src/ldpaths.cpp

Wed, 10 Jan 2018 22:54:09 +0200

author
Santeri Piippo
date
Wed, 10 Jan 2018 22:54:09 +0200
changeset 1226
d1199d965235
parent 1224
5a31b6d4bf81
permissions
-rw-r--r--

drop Qt4 support

1006
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
1 /*
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
2 * LDForge: LDraw parts authoring CAD
1222
34def2630300 happy new year 2018
Santeri Piippo
parents: 1217
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
1006
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
4 *
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
5 * This program is free software: you can redistribute it and/or modify
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
6 * it under the terms of the GNU General Public License as published by
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
8 * (at your option) any later version.
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
9 *
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
10 * This program is distributed in the hope that it will be useful,
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
13 * GNU General Public License for more details.
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
14 *
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
15 * You should have received a copy of the GNU General Public License
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
17 */
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
18
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QDir>
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "ldpaths.h"
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
21 #include "mainwindow.h"
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "dialogs/ldrawpathdialog.h"
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
24 ConfigOption(QString LDrawPath)
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
26 LDPaths::LDPaths(QObject* parent) :
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
27 QObject(parent),
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
28 m_dialog(nullptr) {}
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 void LDPaths::checkPaths()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 {
1224
5a31b6d4bf81 undo config change
Santeri Piippo
parents: 1222
diff changeset
32 QString pathconfig = config->lDrawPath();
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 953
diff changeset
33
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
34 if (not configurePaths(pathconfig))
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
36 m_dialog = new LDrawPathDialog(pathconfig, false);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
37 connect(m_dialog, SIGNAL(pathChanged(QString)), this, SLOT(configurePaths(QString)));
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 if (not m_dialog->exec())
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
40 exit(1);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 else
1224
5a31b6d4bf81 undo config change
Santeri Piippo
parents: 1222
diff changeset
42 config->setLDrawPath(m_dialog->path());
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
46 bool LDPaths::isValid(const QDir& dir) const
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 {
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
48 if (dir.exists())
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 {
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
50 if (dir.isReadable())
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
51 {
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
52 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
53 QStringList contents = dir.entryList(mustHave);
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
54
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
55 if (contents.size() == mustHave.size())
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
56 m_error = "";
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
57 else
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
58 m_error = "That is not an LDraw directory! It must<br />have LDConfig.ldr, parts/ and p/.";
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
59 }
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 else
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
61 m_error = "That directory cannot be read.";
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 else
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
64 m_error = "That directory does not exist.";
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 return m_error.isEmpty();
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
69 bool LDPaths::configurePaths(QString path)
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
71 QDir dir(path);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
72 bool ok = isValid(dir);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 if (ok)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 baseDir() = dir;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
77 ldConfigPath() = format("%1" DIRSLASH "LDConfig.ldr", path);
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
78 partsDir() = QDir(path + DIRSLASH "parts");
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
79 primitivesDir() = QDir(path + DIRSLASH "p");
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 if (m_dialog)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
83 m_dialog->setStatusText(m_error.isEmpty() ? "OK" : m_error, ok);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 return ok;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 QString& LDPaths::ldConfigPath()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 static QString value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 return value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 QDir& LDPaths::primitivesDir()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 return value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 QDir& LDPaths::partsDir()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 return value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 QDir& LDPaths::baseDir()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 return value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 }

mercurial