src/ldpaths.cpp

Sun, 04 Oct 2015 14:08:51 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 04 Oct 2015 14:08:51 +0300
changeset 1006
a6b462051ae0
parent 1000
c064cc048f14
child 1012
413ecd6b9801
permissions
-rw-r--r--

Copyright header fix, some minor stuff

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
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
3 * Copyright (C) 2013 - 2015 Teemu Piippo
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
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
24 ConfigOption (QString LDrawPath)
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LDPaths::LDPaths (QObject* parent) :
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 QObject (parent),
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
28 HierarchyElement (parent),
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 m_dialog (nullptr) {}
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 void LDPaths::checkPaths()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 {
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
33 QString pathconfig = m_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
34
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
35 if (not configurePaths (pathconfig))
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 {
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
37 m_dialog = new LDrawPathDialog (pathconfig, false);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 connect (m_dialog, SIGNAL (pathChanged(QString)), this, SLOT (configurePaths (QString)));
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 if (not m_dialog->exec())
987
91281e39c50c Removed the exiting hacks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
41 exit (1);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 else
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
43 m_config->setLDrawPath (m_dialog->path());
953
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 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 bool LDPaths::isValid (const QDir& dir) const
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
49 if (dir.exists())
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 {
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
51 if (dir.isReadable())
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
52 {
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
53 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
54 QStringList contents = dir.entryList (mustHave);
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
55
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
56 if (contents.size() == mustHave.size())
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
57 m_error = "";
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
58 else
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
59 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
60 }
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 else
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
62 m_error = "That directory cannot be read.";
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 else
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
65 m_error = "That directory does not exist.";
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 return m_error.isEmpty();
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 bool LDPaths::configurePaths (QString path)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 {
999
213a7c7a3ce4 And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 987
diff changeset
72 QDir dir (path);
953
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 bool ok = isValid (dir);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 if (ok)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 baseDir() = dir;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 ldConfigPath() = format ("%1" DIRSLASH "LDConfig.ldr", path);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 partsDir() = QDir (path + DIRSLASH "parts");
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 primitivesDir() = QDir (path + DIRSLASH "p");
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 if (m_dialog)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 m_dialog->setStatusText (m_error.isEmpty() ? "OK" : m_error, ok);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 return ok;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 QString& LDPaths::ldConfigPath()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 static QString value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 return value;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 QDir& LDPaths::primitivesDir()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 return value;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 QDir& LDPaths::partsDir()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 return value;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 QDir& LDPaths::baseDir()
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 return value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }

mercurial