|
1 /* |
|
2 * ZCinema: Zandronum demo launcher |
|
3 * Copyright (C) 2013-2015 Teemu 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 <QFileDialog> |
|
20 #include <commonlib/misc.h> |
|
21 #include <commonlib/version.h> |
|
22 #include <commonlib/config.h> |
|
23 #include "prompts.h" |
|
24 #include "ui_unknownversion.h" |
|
25 #include "ui_findfile.h" |
|
26 |
|
27 // |
|
28 // ------------------------------------------------------------------------------------------------- |
|
29 // |
|
30 |
|
31 UnknownVersionPrompt::UnknownVersionPrompt ( |
|
32 QString fileName, |
|
33 QString binaryName, |
|
34 bool isRelease, |
|
35 QWidget* parent, |
|
36 Qt::WindowFlags f |
|
37 ) : |
|
38 QDialog (parent, f), |
|
39 m_binaryString (binaryName), |
|
40 m_isRelease (isRelease) |
|
41 { |
|
42 ui = new Ui_UnknownVersion; |
|
43 ui->setupUi (this); |
|
44 |
|
45 // Replace the placeholders |
|
46 QString text = ui->m_description->text(); |
|
47 text.replace ("<DEMO>", basename (fileName)); |
|
48 text.replace ("<VERSION>", binaryName); |
|
49 ui->m_description->setText (text); |
|
50 |
|
51 connect (ui->m_addVersion, SIGNAL (clicked (bool)), this, SLOT (addBinary())); |
|
52 connect (ui->m_findBinary, SIGNAL (clicked (bool)), this, SLOT (findBinary())); |
|
53 setWindowTitle (versionSignature()); |
|
54 } |
|
55 |
|
56 // |
|
57 // ------------------------------------------------------------------------------------------------- |
|
58 // |
|
59 |
|
60 UnknownVersionPrompt::~UnknownVersionPrompt() |
|
61 { |
|
62 delete ui; |
|
63 } |
|
64 |
|
65 // |
|
66 // ------------------------------------------------------------------------------------------------- |
|
67 // |
|
68 |
|
69 void UnknownVersionPrompt::addBinary() |
|
70 { |
|
71 ZandronumVersion version (m_binaryString, m_isRelease, ui->m_binaryPath->text()); |
|
72 QList<QVariant> versions = Config::get ("versions").toList(); |
|
73 QVariant var; |
|
74 var.setValue (version); |
|
75 versions.append (var); |
|
76 Config::set ("versions", versions); |
|
77 accept(); |
|
78 } |
|
79 |
|
80 // |
|
81 // ------------------------------------------------------------------------------------------------- |
|
82 // |
|
83 |
|
84 void UnknownVersionPrompt::findBinary() |
|
85 { |
|
86 QString path = getBinaryPath (this); |
|
87 |
|
88 if (path.isEmpty()) |
|
89 return; |
|
90 |
|
91 ui->m_binaryPath->setText (path); |
|
92 } |
|
93 |
|
94 // |
|
95 // ------------------------------------------------------------------------------------------------- |
|
96 // |
|
97 |
|
98 FindFilePrompt::FindFilePrompt (QWidget* parent, Qt::WindowFlags f) : |
|
99 QDialog (parent, f), |
|
100 m_ui (new Ui_FindFile) |
|
101 { |
|
102 m_ui->setupUi (this); |
|
103 connect (m_ui->m_find, SIGNAL (clicked()), this, SLOT (findDemo())); |
|
104 |
|
105 setWindowTitle (versionSignature()); |
|
106 } |
|
107 |
|
108 // |
|
109 // ------------------------------------------------------------------------------------------------- |
|
110 // |
|
111 |
|
112 FindFilePrompt::~FindFilePrompt() |
|
113 { |
|
114 delete m_ui; |
|
115 } |
|
116 |
|
117 // |
|
118 // ------------------------------------------------------------------------------------------------- |
|
119 // |
|
120 |
|
121 void FindFilePrompt::findDemo() |
|
122 { |
|
123 QString path = QFileDialog::getOpenFileName (this, tr ("Open Demo File"), |
|
124 QDir::homePath(), tr ("Demo files (*.cld);;All files (*.*)")); |
|
125 |
|
126 if (not path.isEmpty()) |
|
127 m_ui->m_path->setText (path); |
|
128 } |
|
129 |
|
130 // |
|
131 // ------------------------------------------------------------------------------------------------- |
|
132 // |
|
133 |
|
134 QString FindFilePrompt::path() const |
|
135 { |
|
136 return m_ui->m_path->text(); |
|
137 } |