Sun, 04 Oct 2015 02:59:38 +0300
And now it should work again too
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #include <QDir> |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | #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
|
3 | #include "mainwindow.h" |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | #include "dialogs/ldrawpathdialog.h" |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | |
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
|
6 | ConfigOption (QString LDrawPath) |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | LDPaths::LDPaths (QObject* parent) : |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 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
|
10 | HierarchyElement (parent), |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | m_dialog (nullptr) {} |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | void LDPaths::checkPaths() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | { |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
15 | 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
|
16 | |
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
|
17 | if (not configurePaths (pathconfig)) |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | { |
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
|
19 | m_dialog = new LDrawPathDialog (pathconfig, false); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | connect (m_dialog, SIGNAL (pathChanged(QString)), this, SLOT (configurePaths (QString))); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | if (not m_dialog->exec()) |
987
91281e39c50c
Removed the exiting hacks
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
23 | exit (1); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | else |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
25 | m_config->setLDrawPath (m_dialog->path()); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
29 | #include <QDebug> |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | bool LDPaths::isValid (const QDir& dir) const |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | { |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
32 | if (dir.exists()) |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | { |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
34 | if (dir.isReadable()) |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
35 | { |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
36 | QStringList mustHave = { "LDConfig.ldr", "parts", "p" }; |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
37 | QStringList contents = dir.entryList (mustHave); |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
38 | |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
39 | if (contents.size() == mustHave.size()) |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
40 | m_error = ""; |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
41 | else |
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
42 | 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
|
43 | } |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | else |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
45 | m_error = "That directory cannot be read."; |
953
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 | else |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
48 | m_error = "That directory does not exist."; |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | return m_error.isEmpty(); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | bool LDPaths::configurePaths (QString path) |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | { |
999
213a7c7a3ce4
And now it should work again too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
987
diff
changeset
|
55 | QDir dir (path); |
953
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | bool ok = isValid (dir); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | if (ok) |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | baseDir() = dir; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | ldConfigPath() = format ("%1" DIRSLASH "LDConfig.ldr", path); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | partsDir() = QDir (path + DIRSLASH "parts"); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | primitivesDir() = QDir (path + DIRSLASH "p"); |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | } |
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 | if (m_dialog) |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | m_dialog->setStatusText (m_error.isEmpty() ? "OK" : m_error, ok); |
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 | return ok; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | } |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | QString& LDPaths::ldConfigPath() |
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 | static QString value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | return value; |
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 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | QDir& LDPaths::primitivesDir() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | static QDir value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | return value; |
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 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | QDir& LDPaths::partsDir() |
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 | static QDir value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | return value; |
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 | |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | QDir& LDPaths::baseDir() |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | { |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | static QDir value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | return value; |
8349552ee5e9
Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | } |