src/ldpaths.cpp

changeset 953
8349552ee5e9
child 970
c8aae45afd85
equal deleted inserted replaced
952:f116b63c4844 953:8349552ee5e9
1 #include <QDir>
2 #include "ldpaths.h"
3 #include "dialogs/ldrawpathdialog.h"
4
5 CFGENTRY (String, LDrawPath, "")
6
7 LDPaths::LDPaths (QObject* parent) :
8 QObject (parent),
9 m_dialog (nullptr) {}
10
11 void LDPaths::checkPaths()
12 {
13 if (not configurePaths (cfg::LDrawPath))
14 {
15 m_dialog = new LDrawPathDialog (cfg::LDrawPath, false);
16 connect (m_dialog, SIGNAL (pathChanged(QString)), this, SLOT (configurePaths (QString)));
17
18 if (not m_dialog->exec())
19 Exit();
20 else
21 cfg::LDrawPath = m_dialog->path();
22 }
23 }
24
25 bool LDPaths::isValid (const QDir& dir) const
26 {
27 if (dir.exists() && dir.isReadable())
28 {
29 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
30 QStringList contents = dir.entryList (mustHave);
31
32 if (contents.size() == mustHave.size())
33 m_error = "";
34 else
35 m_error = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
36 }
37 else
38 m_error = "Directory does not exist or is not readable.";
39
40 return m_error.isEmpty();
41 }
42
43 bool LDPaths::configurePaths (QString path)
44 {
45 QDir dir;
46 dir.cd (path);
47 bool ok = isValid (dir);
48
49 if (ok)
50 {
51 baseDir() = dir;
52 ldConfigPath() = format ("%1" DIRSLASH "LDConfig.ldr", path);
53 partsDir() = QDir (path + DIRSLASH "parts");
54 primitivesDir() = QDir (path + DIRSLASH "p");
55 }
56
57 if (m_dialog)
58 m_dialog->setStatusText (m_error.isEmpty() ? "OK" : m_error, ok);
59
60 return ok;
61 }
62
63 QString& LDPaths::ldConfigPath()
64 {
65 static QString value;
66 return value;
67 }
68
69 QDir& LDPaths::primitivesDir()
70 {
71 static QDir value;
72 return value;
73 }
74
75 QDir& LDPaths::partsDir()
76 {
77 static QDir value;
78 return value;
79 }
80
81 QDir& LDPaths::baseDir()
82 {
83 static QDir value;
84 return value;
85 }

mercurial