1 /* |
|
2 * ZCinema: Zandronum demo launcher |
|
3 * Copyright (C) 2013 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #include "versionEditor.h" |
|
20 #include "ui_versionEditor.h" |
|
21 #include "ui_addversion.h" |
|
22 #include "config.h" |
|
23 #include "misc.h" |
|
24 |
|
25 EXTERN_CONFIG (Map, binaryPaths) |
|
26 EXTERN_CONFIG (List, devBuildNames) |
|
27 EXTERN_CONFIG (List, releaseNames) |
|
28 |
|
29 // ============================================================================= |
|
30 // ----------------------------------------------------------------------------- |
|
31 VersionEditor::VersionEditor (QWidget* parent, Qt::WindowFlags f) : |
|
32 QDialog (parent, f), |
|
33 m_ui (new Ui_VersionEditor) |
|
34 { |
|
35 m_ui->setupUi (this); |
|
36 |
|
37 connect (m_ui->m_versions, SIGNAL (currentCellChanged (int, int, int, int)), |
|
38 this, SLOT (selectionChanged (int))); |
|
39 |
|
40 connect (m_ui->m_add, SIGNAL (clicked (bool)), this, SLOT (add())); |
|
41 connect (m_ui->m_edit, SIGNAL (clicked (bool)), this, SLOT (edit())); |
|
42 connect (m_ui->m_remove, SIGNAL (clicked (bool)), this, SLOT (remove())); |
|
43 connect (m_ui->m_clear, SIGNAL (clicked (bool)), this, SLOT (clear())); |
|
44 |
|
45 initVersions(); |
|
46 } |
|
47 |
|
48 // ============================================================================= |
|
49 // ----------------------------------------------------------------------------- |
|
50 VersionEditor::~VersionEditor() { |
|
51 delete m_ui; |
|
52 } |
|
53 |
|
54 // ============================================================================= |
|
55 // ----------------------------------------------------------------------------- |
|
56 void VersionEditor::initVersions() { |
|
57 int i = 0; |
|
58 |
|
59 for (const QVariant& ver : (cfg::releaseNames + cfg::devBuildNames)) { |
|
60 bool isRelease = (i < cfg::releaseNames.size()); |
|
61 addVersion (ver.toString(), cfg::binaryPaths[ver.toString()].toString(), isRelease); |
|
62 |
|
63 ++i; |
|
64 } |
|
65 } |
|
66 |
|
67 // ============================================================================= |
|
68 // ----------------------------------------------------------------------------- |
|
69 void VersionEditor::add() { |
|
70 AddVersionPrompt* dlg = new AddVersionPrompt (this); |
|
71 if (!dlg->exec()) |
|
72 return; |
|
73 |
|
74 addVersion (dlg->name(), dlg->path(), dlg->release()); |
|
75 } |
|
76 |
|
77 // ============================================================================= |
|
78 // ----------------------------------------------------------------------------- |
|
79 void VersionEditor::edit() { |
|
80 QTableWidget* const vers = m_ui->m_versions; |
|
81 int row = vers->currentRow(); |
|
82 |
|
83 if (row < 0) |
|
84 return; |
|
85 |
|
86 AddVersionPrompt* dlg = new AddVersionPrompt (this); |
|
87 dlg->setName (vers->item (row, NameColumn)->text()); |
|
88 dlg->setPath (vers->item (row, PathColumn)->text()); |
|
89 dlg->setRelease (getReleaseCheckbox(row)->isChecked()); |
|
90 |
|
91 if (!dlg->exec()) |
|
92 return; |
|
93 |
|
94 addVersion (dlg->name(), dlg->path(), dlg->release()); |
|
95 } |
|
96 |
|
97 // ============================================================================= |
|
98 // ----------------------------------------------------------------------------- |
|
99 void VersionEditor::remove() { |
|
100 QTableWidget* const vers = m_ui->m_versions; |
|
101 |
|
102 str name = vers->item (vers->currentRow(), NameColumn)->text(); |
|
103 vers->removeRow (vers->currentRow()); |
|
104 } |
|
105 |
|
106 // ============================================================================= |
|
107 // ----------------------------------------------------------------------------- |
|
108 void VersionEditor::clear() { |
|
109 if (!confirm (tr ("Really remove all versions?"))) |
|
110 return; |
|
111 |
|
112 for (int i = m_ui->m_versions->rowCount() - 1; i >= 0; --i) |
|
113 m_ui->m_versions->removeRow (i); |
|
114 } |
|
115 |
|
116 // ============================================================================= |
|
117 // ----------------------------------------------------------------------------- |
|
118 void VersionEditor::addVersion (str name, str path, bool isRelease) { |
|
119 QTableWidget* const vers = m_ui->m_versions; |
|
120 |
|
121 int row = vers->rowCount(); |
|
122 vers->insertRow (row); |
|
123 vers->setItem (row, NameColumn, new QTableWidgetItem); |
|
124 vers->setItem (row, PathColumn, new QTableWidgetItem); |
|
125 vers->item (row, NameColumn)->setText (name); |
|
126 vers->item (row, PathColumn)->setText (path); |
|
127 |
|
128 QCheckBox* cb = new QCheckBox; |
|
129 cb->setChecked (isRelease); |
|
130 vers->setCellWidget (row, ReleaseColumn, cb); |
|
131 } |
|
132 |
|
133 // ============================================================================= |
|
134 // ----------------------------------------------------------------------------- |
|
135 void VersionEditor::saveChanges() { |
|
136 QTableWidget* const vers = m_ui->m_versions; |
|
137 |
|
138 cfg::devBuildNames.clear(); |
|
139 cfg::releaseNames.clear(); |
|
140 cfg::binaryPaths.clear(); |
|
141 |
|
142 for (int i = 0; i < vers->rowCount(); ++i) { |
|
143 const QCheckBox* cb = getReleaseCheckbox (i); |
|
144 bool isRelease = cb->isChecked(); |
|
145 const str name = vers->item (i, NameColumn)->text(), |
|
146 path = vers->item (i, PathColumn)->text(); |
|
147 |
|
148 if (isRelease) |
|
149 cfg::releaseNames << QVariant (name); |
|
150 else |
|
151 cfg::devBuildNames << QVariant (name); |
|
152 |
|
153 cfg::binaryPaths[name] = path; |
|
154 } |
|
155 } |
|
156 |
|
157 // ============================================================================= |
|
158 // ----------------------------------------------------------------------------- |
|
159 void VersionEditor::selectionChanged (int row) { |
|
160 bool ok = (row != -1); |
|
161 m_ui->m_edit->setEnabled (ok); |
|
162 m_ui->m_remove->setEnabled (ok); |
|
163 } |
|
164 |
|
165 // ============================================================================= |
|
166 // ----------------------------------------------------------------------------- |
|
167 QCheckBox* VersionEditor::getReleaseCheckbox (int i) { |
|
168 return static_cast<QCheckBox*> (m_ui->m_versions->cellWidget (i, ReleaseColumn)); |
|
169 } |
|
170 |
|
171 // ============================================================================= |
|
172 // ----------------------------------------------------------------------------- |
|
173 AddVersionPrompt::AddVersionPrompt (QWidget* parent, Qt::WindowFlags f) : |
|
174 QDialog (parent, f), |
|
175 m_ui (new Ui_AddVersion) |
|
176 { |
|
177 m_ui->setupUi (this); |
|
178 connect (m_ui->m_binaryName, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged())); |
|
179 connect (m_ui->m_binaryPath, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged())); |
|
180 connect (m_ui->m_findBinary, SIGNAL (clicked (bool)), this, SLOT (findPath())); |
|
181 } |
|
182 |
|
183 // ============================================================================= |
|
184 // ----------------------------------------------------------------------------- |
|
185 AddVersionPrompt::~AddVersionPrompt() { |
|
186 delete m_ui; |
|
187 } |
|
188 |
|
189 // ============================================================================= |
|
190 // ----------------------------------------------------------------------------- |
|
191 void AddVersionPrompt::findPath() { |
|
192 str path = ConfigBox::getBinaryPath (this); |
|
193 if (!path.isEmpty()) |
|
194 m_ui->m_binaryPath->setText (path); |
|
195 } |
|
196 |
|
197 // ============================================================================= |
|
198 // ----------------------------------------------------------------------------- |
|
199 str AddVersionPrompt::name() { |
|
200 return m_ui->m_binaryName->text(); |
|
201 } |
|
202 |
|
203 // ============================================================================= |
|
204 // ----------------------------------------------------------------------------- |
|
205 str AddVersionPrompt::path() { |
|
206 return m_ui->m_binaryPath->text(); |
|
207 } |
|
208 |
|
209 // ============================================================================= |
|
210 // ----------------------------------------------------------------------------- |
|
211 bool AddVersionPrompt::release() { |
|
212 return m_ui->m_release->isChecked(); |
|
213 } |
|
214 |
|
215 // ============================================================================= |
|
216 // ----------------------------------------------------------------------------- |
|
217 void AddVersionPrompt::setName (const str& a) { |
|
218 m_ui->m_binaryName->setText (a); |
|
219 } |
|
220 |
|
221 // ============================================================================= |
|
222 // ----------------------------------------------------------------------------- |
|
223 void AddVersionPrompt::setPath (const str& a) { |
|
224 m_ui->m_binaryPath->setText (a); |
|
225 } |
|
226 |
|
227 // ============================================================================= |
|
228 // ----------------------------------------------------------------------------- |
|
229 void AddVersionPrompt::setRelease (bool a) { |
|
230 m_ui->m_release->setChecked (a); |
|
231 } |
|
232 |
|
233 // ============================================================================= |
|
234 // ----------------------------------------------------------------------------- |
|
235 void AddVersionPrompt::fieldsChanged() { |
|
236 bool ok = (!m_ui->m_binaryName->text().isEmpty()) && (!m_ui->m_binaryPath->text().isEmpty()); |
|
237 m_ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (ok); |
|
238 } |
|