|
1 #include <QFileDialog> |
|
2 #include <QMessageBox> |
|
3 #include "librarieseditor.h" |
|
4 #include "ui_librarieseditor.h" |
|
5 |
|
6 LibrariesEditor::LibrariesEditor(QSettings* settings, QWidget* parent) : |
|
7 QWidget{parent}, |
|
8 libraries{settings, this}, |
|
9 ui{*new Ui_LibrariesEditor} |
|
10 { |
|
11 this->ui.setupUi(this); |
|
12 connect( |
|
13 this->ui.newLibrarySearch, |
|
14 &QPushButton::clicked, |
|
15 this, |
|
16 &LibrariesEditor::searchPathForNewLibrary); |
|
17 connect( |
|
18 this->ui.newLibraryAdd, |
|
19 &QPushButton::clicked, |
|
20 this, |
|
21 &LibrariesEditor::addNewLibrary); |
|
22 this->ui.librariesTable->setModel(&this->libraries); |
|
23 } |
|
24 |
|
25 LibrariesEditor::~LibrariesEditor() |
|
26 { |
|
27 delete &this->ui; |
|
28 } |
|
29 |
|
30 void LibrariesEditor::searchPathForNewLibrary() |
|
31 { |
|
32 const QString path = QFileDialog::getExistingDirectory(this, tr("Browse LDraw library")); |
|
33 if (not path.isEmpty()) |
|
34 { |
|
35 this->ui.newLibraryPath->setText(path); |
|
36 } |
|
37 } |
|
38 |
|
39 void LibrariesEditor::addNewLibrary() |
|
40 { |
|
41 const QDir dir{this->ui.newLibraryPath->text()}; |
|
42 if (not dir.exists()) |
|
43 { |
|
44 QMessageBox::critical(this, |
|
45 tr("Library does not exist"), |
|
46 format( |
|
47 tr("The directory %1 does not exist."), |
|
48 quoted(dir.path()))); |
|
49 } |
|
50 else |
|
51 { |
|
52 if (not dir.isReadable()) |
|
53 { |
|
54 QMessageBox::warning(this, |
|
55 tr("Unreadable library"), |
|
56 format( |
|
57 tr("The directory %1 cannot be read."), |
|
58 quoted(dir.path()))); |
|
59 } |
|
60 this->libraries.addLibrary({Library::OfficialLibrary, dir}); |
|
61 this->ui.newLibraryPath->clear(); |
|
62 } |
|
63 } |
|
64 |
|
65 void LibrariesEditor::saveSettings(QSettings* settings) |
|
66 { |
|
67 this->libraries.storeToSettings(settings); |
|
68 } |