src/ldpaths.cpp

Mon, 31 Aug 2015 23:36:08 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 31 Aug 2015 23:36:08 +0300
changeset 977
dc3ceb65cda7
parent 971
c00f9665a9f8
child 987
91281e39c50c
permissions
-rw-r--r--

More refactor and removal of g_win uses

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())
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 Exit();
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 bool LDPaths::isValid (const QDir& dir) const
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 if (dir.exists() && dir.isReadable())
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 QStringList mustHave = { "LDConfig.ldr", "parts", "p" };
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 QStringList contents = dir.entryList (mustHave);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 if (contents.size() == mustHave.size())
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 m_error = "";
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 else
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 m_error = "Not an LDraw directory! Must<br />have LDConfig.ldr, parts/ and p/.";
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 }
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 else
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 m_error = "Directory does not exist or is not readable.";
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 return m_error.isEmpty();
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::configurePaths (QString path)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 QDir dir;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 dir.cd (path);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 bool ok = isValid (dir);
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 if (ok)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 baseDir() = dir;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 ldConfigPath() = format ("%1" DIRSLASH "LDConfig.ldr", path);
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 partsDir() = QDir (path + DIRSLASH "parts");
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 primitivesDir() = QDir (path + DIRSLASH "p");
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 if (m_dialog)
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 m_dialog->setStatusText (m_error.isEmpty() ? "OK" : m_error, ok);
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 return ok;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 QString& LDPaths::ldConfigPath()
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 static QString value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 return value;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 QDir& LDPaths::primitivesDir()
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 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 return value;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 QDir& LDPaths::partsDir()
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 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 return value;
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
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 QDir& LDPaths::baseDir()
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 static QDir value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 return value;
8349552ee5e9 Refactor LDrawPathDialog and LDPaths
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 }

mercurial