|
1 #include "versionEditor.h" |
|
2 #include "ui_versionEditor.h" |
|
3 #include "ui_addversion.h" |
|
4 #include "config.h" |
|
5 #include "misc.h" |
|
6 #include "build/moc_versionEditor.cpp" |
|
7 |
|
8 EXTERN_CONFIG (Map, binaryPaths) |
|
9 EXTERN_CONFIG (List, devBuildNames) |
|
10 EXTERN_CONFIG (List, releaseNames) |
|
11 |
|
12 // ============================================================================= |
|
13 // ----------------------------------------------------------------------------- |
|
14 VersionEditor::VersionEditor (QWidget* parent, Qt::WindowFlags f) : |
|
15 QDialog (parent, f), |
|
16 m_ui (new Ui_VersionEditor) |
|
17 { |
|
18 m_ui->setupUi (this); |
|
19 |
|
20 connect (m_ui->m_versions, SIGNAL (currentCellChanged (int, int, int, int)), |
|
21 this, SLOT (selectionChanged (int))); |
|
22 |
|
23 connect (m_ui->m_add, SIGNAL (clicked (bool)), this, SLOT (add())); |
|
24 connect (m_ui->m_edit, SIGNAL (clicked (bool)), this, SLOT (edit())); |
|
25 connect (m_ui->m_remove, SIGNAL (clicked (bool)), this, SLOT (remove())); |
|
26 connect (m_ui->m_clear, SIGNAL (clicked (bool)), this, SLOT (clear())); |
|
27 |
|
28 initVersions(); |
|
29 } |
|
30 |
|
31 // ============================================================================= |
|
32 // ----------------------------------------------------------------------------- |
|
33 VersionEditor::~VersionEditor() { |
|
34 delete m_ui; |
|
35 } |
|
36 |
|
37 // ============================================================================= |
|
38 // ----------------------------------------------------------------------------- |
|
39 void VersionEditor::initVersions() { |
|
40 int i = 0; |
|
41 |
|
42 for (const QVariant& ver : (cfg::releaseNames + cfg::devBuildNames)) { |
|
43 bool isRelease = (i < cfg::releaseNames.size()); |
|
44 addVersion (ver.toString(), cfg::binaryPaths[ver.toString()].toString(), isRelease); |
|
45 |
|
46 ++i; |
|
47 } |
|
48 } |
|
49 |
|
50 // ============================================================================= |
|
51 // ----------------------------------------------------------------------------- |
|
52 void VersionEditor::add() { |
|
53 AddVersionPrompt* dlg = new AddVersionPrompt (this); |
|
54 if (!dlg->exec()) |
|
55 return; |
|
56 |
|
57 addVersion (dlg->name(), dlg->path(), dlg->release()); |
|
58 } |
|
59 |
|
60 // ============================================================================= |
|
61 // ----------------------------------------------------------------------------- |
|
62 void VersionEditor::edit() { |
|
63 QTableWidget* const vers = m_ui->m_versions; |
|
64 int row = vers->currentRow(); |
|
65 |
|
66 if (row < 0) |
|
67 return; |
|
68 |
|
69 AddVersionPrompt* dlg = new AddVersionPrompt (this); |
|
70 dlg->setName (vers->item (row, NameColumn)->text()); |
|
71 dlg->setPath (vers->item (row, PathColumn)->text()); |
|
72 dlg->setRelease (getReleaseCheckbox(row)->isChecked()); |
|
73 |
|
74 if (!dlg->exec()) |
|
75 return; |
|
76 |
|
77 addVersion (dlg->name(), dlg->path(), dlg->release()); |
|
78 } |
|
79 |
|
80 // ============================================================================= |
|
81 // ----------------------------------------------------------------------------- |
|
82 void VersionEditor::remove() { |
|
83 QTableWidget* const vers = m_ui->m_versions; |
|
84 |
|
85 str name = vers->item (vers->currentRow(), NameColumn)->text(); |
|
86 if (!confirm (fmt (tr ("Really remove version %1?"), name))) |
|
87 return; |
|
88 |
|
89 vers->removeRow (vers->currentRow()); |
|
90 } |
|
91 |
|
92 // ============================================================================= |
|
93 // ----------------------------------------------------------------------------- |
|
94 void VersionEditor::clear() { |
|
95 if (!confirm (tr ("Really remove all versions?"))) |
|
96 return; |
|
97 |
|
98 m_ui->m_versions->clear(); |
|
99 } |
|
100 |
|
101 // ============================================================================= |
|
102 // ----------------------------------------------------------------------------- |
|
103 void VersionEditor::addVersion (str name, str path, bool isRelease) { |
|
104 QTableWidget* const vers = m_ui->m_versions; |
|
105 |
|
106 int row = vers->rowCount(); |
|
107 vers->insertRow (row); |
|
108 vers->setItem (row, NameColumn, new QTableWidgetItem); |
|
109 vers->setItem (row, PathColumn, new QTableWidgetItem); |
|
110 vers->item (row, NameColumn)->setText (name); |
|
111 vers->item (row, PathColumn)->setText (path); |
|
112 |
|
113 QCheckBox* cb = new QCheckBox; |
|
114 cb->setChecked (isRelease); |
|
115 vers->setCellWidget (row, ReleaseColumn, cb); |
|
116 } |
|
117 |
|
118 // ============================================================================= |
|
119 // ----------------------------------------------------------------------------- |
|
120 void VersionEditor::saveChanges() { |
|
121 QTableWidget* const vers = m_ui->m_versions; |
|
122 |
|
123 cfg::devBuildNames.clear(); |
|
124 cfg::releaseNames.clear(); |
|
125 cfg::binaryPaths.clear(); |
|
126 |
|
127 for (int i = 0; i < vers->rowCount(); ++i) { |
|
128 const QCheckBox* cb = getReleaseCheckbox (i); |
|
129 bool isRelease = cb->isChecked(); |
|
130 const str name = vers->item (i, NameColumn)->text(), |
|
131 path = vers->item (i, PathColumn)->text(); |
|
132 |
|
133 if (isRelease) |
|
134 cfg::releaseNames << QVariant (name); |
|
135 else |
|
136 cfg::devBuildNames << QVariant (name); |
|
137 |
|
138 cfg::binaryPaths[name] = path; |
|
139 } |
|
140 |
|
141 cfg::save(); |
|
142 } |
|
143 |
|
144 // ============================================================================= |
|
145 // ----------------------------------------------------------------------------- |
|
146 void VersionEditor::selectionChanged (int row) { |
|
147 bool ok = (row != -1); |
|
148 m_ui->m_edit->setEnabled (ok); |
|
149 m_ui->m_remove->setEnabled (ok); |
|
150 } |
|
151 |
|
152 // ============================================================================= |
|
153 // ----------------------------------------------------------------------------- |
|
154 QCheckBox* VersionEditor::getReleaseCheckbox (int i) { |
|
155 return static_cast<QCheckBox*> (m_ui->m_versions->cellWidget (i, ReleaseColumn)); |
|
156 } |
|
157 |
|
158 // ============================================================================= |
|
159 // ----------------------------------------------------------------------------- |
|
160 AddVersionPrompt::AddVersionPrompt (QWidget* parent, Qt::WindowFlags f) : |
|
161 QDialog (parent, f), |
|
162 m_ui (new Ui_AddVersion) |
|
163 { |
|
164 m_ui->setupUi (this); |
|
165 connect (m_ui->m_binaryName, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged())); |
|
166 connect (m_ui->m_binaryPath, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged())); |
|
167 connect (m_ui->m_findBinary, SIGNAL (clicked (bool)), this, SLOT (findPath())); |
|
168 } |
|
169 |
|
170 // ============================================================================= |
|
171 // ----------------------------------------------------------------------------- |
|
172 AddVersionPrompt::~AddVersionPrompt() { |
|
173 delete m_ui; |
|
174 } |
|
175 |
|
176 // ============================================================================= |
|
177 // ----------------------------------------------------------------------------- |
|
178 void AddVersionPrompt::findPath() { |
|
179 str path = ConfigBox::getBinaryPath (this); |
|
180 if (!path.isEmpty()) |
|
181 m_ui->m_binaryPath->setText (path); |
|
182 } |
|
183 |
|
184 // ============================================================================= |
|
185 // ----------------------------------------------------------------------------- |
|
186 str AddVersionPrompt::name() { |
|
187 return m_ui->m_binaryName->text(); |
|
188 } |
|
189 |
|
190 // ============================================================================= |
|
191 // ----------------------------------------------------------------------------- |
|
192 str AddVersionPrompt::path() { |
|
193 return m_ui->m_binaryPath->text(); |
|
194 } |
|
195 |
|
196 // ============================================================================= |
|
197 // ----------------------------------------------------------------------------- |
|
198 bool AddVersionPrompt::release() { |
|
199 return m_ui->m_release->isChecked(); |
|
200 } |
|
201 |
|
202 // ============================================================================= |
|
203 // ----------------------------------------------------------------------------- |
|
204 void AddVersionPrompt::setName (const str& a) { |
|
205 m_ui->m_binaryName->setText (a); |
|
206 } |
|
207 |
|
208 // ============================================================================= |
|
209 // ----------------------------------------------------------------------------- |
|
210 void AddVersionPrompt::setPath (const str& a) { |
|
211 m_ui->m_binaryPath->setText (a); |
|
212 } |
|
213 |
|
214 // ============================================================================= |
|
215 // ----------------------------------------------------------------------------- |
|
216 void AddVersionPrompt::setRelease (bool a) { |
|
217 m_ui->m_release->setChecked (a); |
|
218 } |
|
219 |
|
220 // ============================================================================= |
|
221 // ----------------------------------------------------------------------------- |
|
222 void AddVersionPrompt::fieldsChanged() { |
|
223 bool ok = (!m_ui->m_binaryName->text().isEmpty()) && (!m_ui->m_binaryPath->text().isEmpty()); |
|
224 m_ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (ok); |
|
225 } |