|
4 | 4 | #include <QGridLayout>
|
5 | 5 | #include <QIcon>
|
6 | 6 | #include <QLabel>
|
| 7 | +#include <QMessageBox> |
7 | 8 | #include "core/application.h"
|
8 | 9 | #include "forms/filedialog.h"
|
9 | 10 | #include "models/prefixesmodel.h"
|
10 | 11 | #include "widgets/lineedit.h"
|
11 | 12 |
|
12 | 13 |
|
13 | 14 | PrefixDialog::PrefixDialog(QWidget* parent) :
|
14 |
| - QDialog(parent) |
| 15 | + QDialog(parent), |
| 16 | + item_(nullptr) |
15 | 17 | {
|
16 | 18 | setupUi();
|
17 | 19 | }
|
@@ -77,35 +79,50 @@ void PrefixDialog::browseForWinePrefix()
|
77 | 79 | }
|
78 | 80 |
|
79 | 81 |
|
80 |
| -QString PrefixDialog::name() const |
| 82 | +PrefixItem* PrefixDialog::item() const |
81 | 83 | {
|
82 |
| - return nameEdit_->text(); |
| 84 | + return item_; |
83 | 85 | }
|
84 | 86 |
|
85 | 87 |
|
86 |
| -void PrefixDialog::setName(const QString& name) |
| 88 | +void PrefixDialog::setItem(PrefixItem* item) |
87 | 89 | {
|
88 |
| - nameEdit_->setText(name); |
89 |
| -} |
90 |
| - |
| 90 | + item_ = item; |
91 | 91 |
|
92 |
| -QString PrefixDialog::path() const |
93 |
| -{ |
94 |
| - return pathEdit_->text(); |
95 |
| -} |
96 |
| - |
97 |
| - |
98 |
| -void PrefixDialog::setPath(const QString& path) |
99 |
| -{ |
100 |
| - pathEdit_->setText(path); |
| 92 | + if(item_) { |
| 93 | + nameEdit_->setText(item->name()); |
| 94 | + pathEdit_->setText(item->path()); |
| 95 | + } |
| 96 | + else { |
| 97 | + nameEdit_->clear(); |
| 98 | + pathEdit_->clear(); |
| 99 | + } |
101 | 100 | }
|
102 | 101 |
|
103 | 102 |
|
104 | 103 | void PrefixDialog::accept()
|
105 | 104 | {
|
106 |
| - if(!qApp->prefixes()->createPrefix(nameEdit_->text(), pathEdit_->text())) { |
107 |
| - // TODO messagebox |
108 |
| - return; |
| 105 | + QString name = nameEdit_->text(); |
| 106 | + QString message = QString("The prefix with name '%1' is already exist.").arg(name); |
| 107 | + |
| 108 | + if(!item_) { |
| 109 | + if(!qApp->prefixes()->createPrefix(nameEdit_->text(), pathEdit_->text())) { |
| 110 | + QMessageBox::critical(this, "Error", message); |
| 111 | + return; |
| 112 | + } |
| 113 | + } |
| 114 | + else if(name != item_->name()) { |
| 115 | + Storage::Prefix prefix = qApp->storage()->prefix(name.toStdString()); |
| 116 | + if(!prefix.isNull()) { |
| 117 | + QMessageBox::critical(this, "Error", message); |
| 118 | + return; |
| 119 | + } |
| 120 | + |
| 121 | + item_->setName(nameEdit_->text()); |
| 122 | + item_->setPath(pathEdit_->text()); |
| 123 | + } |
| 124 | + else { |
| 125 | + item_->setPath(pathEdit_->text()); |
109 | 126 | }
|
110 | 127 |
|
111 | 128 | QDialog::accept();
|
|
0 commit comments