| 19 #include <QDir> |
19 #include <QDir> |
| 20 #include "ldpaths.h" |
20 #include "ldpaths.h" |
| 21 #include "mainwindow.h" |
21 #include "mainwindow.h" |
| 22 #include "dialogs/ldrawpathdialog.h" |
22 #include "dialogs/ldrawpathdialog.h" |
| 23 |
23 |
| 24 LDPaths::LDPaths (Configuration *config, QObject* parent) : |
24 LDPaths::LDPaths(QObject* parent) : |
| 25 QObject(parent), |
25 QObject {parent}, |
| 26 m_config(config), |
26 m_dialog {nullptr} {} |
| 27 m_dialog(nullptr) {} |
|
| 28 |
27 |
| |
28 LDPaths::~LDPaths() |
| |
29 { |
| |
30 delete m_dialog; |
| |
31 } |
| 29 |
32 |
| 30 void LDPaths::checkPaths() |
33 bool LDPaths::checkPaths() |
| 31 { |
34 { |
| 32 QString pathconfig = m_config->lDrawPath(); |
35 QString pathconfig = configuration().lDrawPath(); |
| 33 |
36 |
| 34 if (not configurePaths (pathconfig)) |
37 if (configurePaths (pathconfig)) |
| |
38 { |
| |
39 return true; |
| |
40 } |
| |
41 else |
| 35 { |
42 { |
| 36 m_dialog = new LDrawPathDialog (pathconfig, false); |
43 m_dialog = new LDrawPathDialog (pathconfig, false); |
| 37 connect(m_dialog, &LDrawPathDialog::pathChanged, this, &LDPaths::configurePaths); |
44 connect(m_dialog, &LDrawPathDialog::pathChanged, this, &LDPaths::configurePaths); |
| 38 |
45 |
| 39 if (m_dialog->exec() != QDialog::Accepted) |
46 if (m_dialog->exec() != QDialog::Accepted) |
| 40 exit(1); |
47 return false; |
| 41 else |
48 |
| 42 m_config->setLDrawPath(m_dialog->path()); |
49 configuration().setLDrawPath(m_dialog->path()); |
| |
50 return true; |
| 43 } |
51 } |
| 44 } |
52 } |
| 45 |
53 |
| 46 |
54 |
| 47 bool LDPaths::isValid (const QDir& dir) const |
55 bool LDPaths::isValid (const QDir& dir) const |
| 68 } |
76 } |
| 69 |
77 |
| 70 |
78 |
| 71 bool LDPaths::configurePaths (QString path) |
79 bool LDPaths::configurePaths (QString path) |
| 72 { |
80 { |
| 73 QDir dir (path); |
81 QDir dir {path}; |
| 74 bool ok = isValid (dir); |
82 bool ok = isValid(dir); |
| 75 |
83 |
| 76 if (ok) |
84 if (ok) |
| 77 { |
85 { |
| 78 baseDir() = dir; |
86 baseDir() = dir; |
| 79 ldConfigPath() = format ("%1" DIRSLASH "LDConfig.ldr", path); |
87 ldConfigPath() = format("%1/LDConfig.ldr", path); |
| 80 partsDir() = QDir (path + DIRSLASH "parts"); |
88 partsDir() = path + "/parts"; |
| 81 primitivesDir() = QDir (path + DIRSLASH "p"); |
89 primitivesDir() = path + "/p"; |
| 82 } |
90 } |
| 83 |
91 |
| 84 if (m_dialog) |
92 if (m_dialog) |
| 85 m_dialog->setStatusText (m_error.isEmpty() ? "OK" : m_error, ok); |
93 m_dialog->setStatusText(m_error.isEmpty() ? "OK" : m_error, ok); |
| 86 |
94 |
| 87 return ok; |
95 return ok; |
| 88 } |
96 } |
| 89 |
97 |
| 90 |
98 |