1 #include <QLabel> |
1 #include <QLabel> |
2 #include <QFileDialog> |
2 #include <QFileDialog> |
3 #include <QFormLayout> |
3 #include <QFormLayout> |
|
4 #include <QProgressBar> |
|
5 #include <QMessageBox> |
|
6 #include <QUrl> |
|
7 #include <QNetworkAccessManager> |
|
8 #include <QNetworkRequest> |
|
9 #include <QNetworkReply> |
4 #include "config.h" |
10 #include "config.h" |
5 #include "ui_configbox.h" |
11 #include "ui_configbox.h" |
6 #include "misc.h" |
12 #include "misc.h" |
|
13 #include "demo.h" |
|
14 #include "build/moc_config.cpp" |
7 |
15 |
8 // ============================================================================= |
16 // ============================================================================= |
9 // ----------------------------------------------------------------------------- |
17 // ----------------------------------------------------------------------------- |
10 class FindPathButton : public QPushButton { |
18 class FindPathButton : public QPushButton { |
11 public: |
19 public: |
12 explicit FindPathButton( QWidget* parent = null ) : QPushButton( parent ) { |
20 explicit FindPathButton (QWidget* parent = null) : QPushButton (parent) { |
13 setText( "..." ); |
21 setText ("..."); |
14 } |
22 } |
15 |
23 |
16 QLineEdit* editWidget() const { return m_editWidget; } |
24 QLineEdit* editWidget() const { |
17 void setEditWidget( QLineEdit* edit ) { m_editWidget = edit; } |
25 return m_editWidget; |
18 |
26 } |
|
27 void setEditWidget (QLineEdit* edit) { |
|
28 m_editWidget = edit; |
|
29 } |
|
30 |
19 private: |
31 private: |
20 QLineEdit* m_editWidget; |
32 QLineEdit* m_editWidget; |
21 }; |
33 }; |
22 |
34 |
23 // ============================================================================= |
35 // ============================================================================= |
24 // ----------------------------------------------------------------------------- |
36 // ----------------------------------------------------------------------------- |
25 ConfigBox::ConfigBox( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) { |
37 ConfigBox::ConfigBox (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f), |
|
38 m_nam (new QNetworkAccessManager (this)) { |
26 ui = new Ui_ConfigBox; |
39 ui = new Ui_ConfigBox; |
27 ui->setupUi( this ); |
40 ui->setupUi (this); |
28 QFormLayout* layout = new QFormLayout( ui->zandronumVersions ); |
41 ui->updateProgress->hide(); |
29 |
42 ui->updateLabel->hide(); |
30 for( str ver : g_zanVersions ) { |
43 |
31 QLabel* lb = new QLabel( ver + ":" ); |
44 initVersions(); |
|
45 initFromSettings(); |
|
46 |
|
47 connect (ui->wad_add, SIGNAL (clicked()), this, SLOT (addPath())); |
|
48 connect (ui->wad_pathEntry, SIGNAL (returnPressed()), this, SLOT (addPath())); |
|
49 connect (ui->wad_findPath, SIGNAL (clicked()), this, SLOT (findPath())); |
|
50 connect (ui->wad_del, SIGNAL (clicked()), this, SLOT (delPath())); |
|
51 connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), this, |
|
52 SLOT (buttonPressed (QAbstractButton*))); |
|
53 setWindowTitle (fmt (APPNAME " %1", versionString())); |
|
54 } |
|
55 |
|
56 // ============================================================================= |
|
57 // ----------------------------------------------------------------------------- |
|
58 ConfigBox::~ConfigBox() { |
|
59 delete ui; |
|
60 } |
|
61 |
|
62 // ============================================================================= |
|
63 // ----------------------------------------------------------------------------- |
|
64 void ConfigBox::initVersions() { |
|
65 QFormLayout* releaseLayout = new QFormLayout (ui->zandronumVersions), |
|
66 *testLayout = new QFormLayout (ui->betaVersions); |
|
67 list<var> versions = getVersionsList(), |
|
68 releases = getReleasesList(); |
|
69 |
|
70 for (const var& ver : versions) { |
|
71 str verstring = ver.toString(); |
|
72 |
|
73 bool isRelease = false; |
|
74 for (const var& rel : releases) { |
|
75 if (rel.toString() == verstring) { |
|
76 isRelease = true; |
|
77 break; |
|
78 } |
|
79 } |
|
80 |
|
81 QLabel* lb = new QLabel (verstring + ":"); |
32 QLineEdit* ledit = new QLineEdit; |
82 QLineEdit* ledit = new QLineEdit; |
33 FindPathButton* btn = new FindPathButton; |
83 FindPathButton* btn = new FindPathButton; |
34 btn->setEditWidget( ledit ); |
84 btn->setEditWidget (ledit); |
35 |
85 |
36 QWidget* wdg = new QWidget; |
86 QWidget* wdg = new QWidget; |
37 QHBoxLayout* leditLayout = new QHBoxLayout( wdg ); |
87 QHBoxLayout* leditLayout = new QHBoxLayout (wdg); |
38 leditLayout->addWidget( ledit ); |
88 leditLayout->addWidget (ledit); |
39 leditLayout->addWidget( btn ); |
89 leditLayout->addWidget (btn); |
40 |
90 |
41 m_zanBinaries << ledit; |
91 m_zanBinaries << ledit; |
42 layout->addRow( lb, wdg ); |
92 connect (btn, SIGNAL (clicked()), this, SLOT (findZanBinary())); |
43 connect( btn, SIGNAL( clicked() ), this, SLOT( findZanBinary() )); |
93 |
44 } |
94 if (isRelease) |
45 |
95 releaseLayout->addRow (lb, wdg); |
46 initFromSettings(); |
96 else |
47 |
97 testLayout->addRow (lb, wdg); |
48 connect( ui->wad_add, SIGNAL( clicked() ), this, SLOT( addPath() )); |
98 } |
49 connect( ui->wad_pathEntry, SIGNAL( returnPressed() ), this, SLOT( addPath() )); |
|
50 connect( ui->wad_findPath, SIGNAL( clicked() ), this, SLOT( findPath() )); |
|
51 connect( ui->wad_del, SIGNAL( clicked() ), this, SLOT( delPath() )); |
|
52 connect( ui->buttonBox, SIGNAL( accepted() ), this, SLOT( okPressed() )); |
|
53 connect( ui->buttonBox, SIGNAL( rejected() ), this, SLOT( cancelPressed() )); |
|
54 setWindowTitle( fmt( APPNAME " %1", versionString())); |
|
55 } |
|
56 |
|
57 // ============================================================================= |
|
58 // ----------------------------------------------------------------------------- |
|
59 ConfigBox::~ConfigBox() { |
|
60 delete ui; |
|
61 } |
99 } |
62 |
100 |
63 // ============================================================================= |
101 // ============================================================================= |
64 // ----------------------------------------------------------------------------- |
102 // ----------------------------------------------------------------------------- |
65 void ConfigBox::initFromSettings() { |
103 void ConfigBox::initFromSettings() { |
66 QSettings cfg; |
104 QSettings cfg; |
67 |
|
68 ui->wad_pathsList->clear(); |
105 ui->wad_pathsList->clear(); |
69 |
106 list<var> paths = cfg.value ("wads/paths", list<var>()).toList(); |
70 list<var> paths = cfg.value( "wads/paths", list<var>() ).toList(); |
107 |
71 for( const var& it : paths ) |
108 for (const var & it : paths) |
72 addPath( it.toString() ); |
109 addPath (it.toString()); |
73 |
110 |
74 int i = 0; |
111 int i = 0; |
75 for( str ver : g_zanVersions ) |
112 |
76 m_zanBinaries[i++]->setText( cfg.value( binaryConfigName( ver ), "" ).toString() ); |
113 list<var> versions = getVersionsList(); |
77 |
114 for (const var& ver : versions) |
78 ui->noDemoPrompt->setChecked( cfg.value( "nodemoprompt", false ).toBool() ); |
115 m_zanBinaries[i++]->setText (cfg.value (binaryConfigName (ver.toString()), "").toString()); |
|
116 |
|
117 ui->noDemoPrompt->setChecked (cfg.value ("nodemoprompt", false).toBool()); |
|
118 } |
|
119 |
|
120 // ============================================================================= |
|
121 // ----------------------------------------------------------------------------- |
|
122 void ConfigBox::saveSettings() { |
|
123 QSettings cfg; |
|
124 list<var> wadPathList; |
|
125 |
|
126 for (int i = 0; i < ui->wad_pathsList->count(); ++i) |
|
127 wadPathList << ui->wad_pathsList->item (i)->text(); |
|
128 |
|
129 cfg.setValue ("wads/paths", wadPathList); |
|
130 cfg.setValue ("nodemoprompt", ui->noDemoPrompt->isChecked()); |
|
131 |
|
132 int i = 0; |
|
133 list<var> versions = getVersionsList(); |
|
134 for (const var& ver : versions) |
|
135 cfg.setValue (binaryConfigName (ver.toString()), m_zanBinaries[i++]->text()); |
79 } |
136 } |
80 |
137 |
81 // ============================================================================= |
138 // ============================================================================= |
82 // ----------------------------------------------------------------------------- |
139 // ----------------------------------------------------------------------------- |
83 void ConfigBox::addPath() { |
140 void ConfigBox::addPath() { |
84 addPath( ui->wad_pathEntry->text() ); |
141 addPath (ui->wad_pathEntry->text()); |
85 ui->wad_pathEntry->clear(); |
142 ui->wad_pathEntry->clear(); |
86 } |
143 } |
87 |
144 |
88 // ============================================================================= |
145 // ============================================================================= |
89 // ----------------------------------------------------------------------------- |
146 // ----------------------------------------------------------------------------- |
90 void ConfigBox::addPath( str path ) { |
147 void ConfigBox::addPath (str path) { |
91 ui->wad_pathsList->addItem( path ); |
148 ui->wad_pathsList->addItem (path); |
92 QListWidgetItem* item = ui->wad_pathsList->item( ui->wad_pathsList->count() - 1 ); |
149 QListWidgetItem* item = ui->wad_pathsList->item (ui->wad_pathsList->count() - 1); |
93 item->setFlags( item->flags() | Qt::ItemIsEditable ); |
150 item->setFlags (item->flags() | Qt::ItemIsEditable); |
94 } |
151 } |
95 |
152 |
96 // ============================================================================= |
153 // ============================================================================= |
97 // ----------------------------------------------------------------------------- |
154 // ----------------------------------------------------------------------------- |
98 void ConfigBox::findPath() { |
155 void ConfigBox::findPath() { |
99 str path = QFileDialog::getExistingDirectory( this ); |
156 str path = QFileDialog::getExistingDirectory (this); |
100 if( path.isEmpty() ) |
157 |
|
158 if (path.isEmpty()) |
101 return; |
159 return; |
102 |
160 |
103 ui->wad_pathEntry->setText( path ); |
161 ui->wad_pathEntry->setText (path); |
104 } |
162 } |
105 |
163 |
106 // ============================================================================= |
164 // ============================================================================= |
107 // ----------------------------------------------------------------------------- |
165 // ----------------------------------------------------------------------------- |
108 void ConfigBox::delPath() { |
166 void ConfigBox::delPath() { |
110 } |
168 } |
111 |
169 |
112 // ============================================================================= |
170 // ============================================================================= |
113 // ----------------------------------------------------------------------------- |
171 // ----------------------------------------------------------------------------- |
114 void ConfigBox::findZanBinary() { |
172 void ConfigBox::findZanBinary() { |
115 FindPathButton* btn = dynamic_cast<FindPathButton*>( sender() ); |
173 FindPathButton* btn = dynamic_cast<FindPathButton*> (sender()); |
|
174 |
|
175 if (!btn) |
|
176 return; |
|
177 |
|
178 str path = getBinaryPath (this); |
|
179 if (path.isEmpty()) |
|
180 return; |
|
181 |
|
182 btn->editWidget()->setText (path); |
|
183 } |
|
184 |
|
185 // ============================================================================= |
|
186 // ----------------------------------------------------------------------------- |
|
187 str ConfigBox::getBinaryPath (QWidget* parent) { |
116 str path; |
188 str path; |
117 |
189 const str filter = |
118 if( !btn ) |
|
119 return; |
|
120 |
|
121 str filter; |
|
122 #ifdef _WIN32 |
190 #ifdef _WIN32 |
123 filter = "Zandronum Binaries (zandronum.exe)(zandronum.exe);;All files (*.*)(*.*)"; |
191 "Zandronum Binaries (zandronum.exe)(zandronum.exe);;All files (*.*)(*.*)"; |
124 #else |
192 #else |
125 filter = "Zandronum Binaries (zandronum)(zandronum);;All files (*.*)(*.*)"; |
193 "Zandronum Binaries (zandronum)(zandronum);;All files (*.*)(*.*)"; |
126 #endif |
194 #endif |
127 |
195 |
128 if(( path = QFileDialog::getOpenFileName( this, QString(), QString(), filter )).isEmpty() ) |
196 return QFileDialog::getOpenFileName (parent, QString(), QString(), filter); |
129 return; |
197 } |
130 |
198 |
131 btn->editWidget()->setText( path ); |
199 // ============================================================================= |
132 } |
200 // ----------------------------------------------------------------------------- |
133 |
201 void ConfigBox::buttonPressed (QAbstractButton* btn) { |
134 // ============================================================================= |
202 if (btn == ui->buttonBox->button (QDialogButtonBox::Ok)) { |
135 // ----------------------------------------------------------------------------- |
203 saveSettings(); |
136 void ConfigBox::okPressed() { |
204 accept(); |
137 QSettings cfg; |
205 } elif (btn == ui->buttonBox->button (QDialogButtonBox::Cancel)) |
138 list<var> wadPathList; |
206 reject(); |
139 |
207 elif (btn == ui->buttonBox->button (QDialogButtonBox::Apply)) |
140 for( int i = 0; i < ui->wad_pathsList->count(); ++i ) |
208 saveSettings(); |
141 wadPathList << ui->wad_pathsList->item( i )->text(); |
209 } |
142 |
|
143 cfg.setValue( "wads/paths", wadPathList ); |
|
144 cfg.setValue( "nodemoprompt", ui->noDemoPrompt->isChecked() ); |
|
145 |
|
146 int i = 0; |
|
147 for( str ver : g_zanVersions ) |
|
148 cfg.setValue( binaryConfigName( ver ), m_zanBinaries[i++]->text() ); |
|
149 |
|
150 accept(); |
|
151 } |
|
152 |
|
153 // ============================================================================= |
|
154 // ----------------------------------------------------------------------------- |
|
155 void ConfigBox::cancelPressed() { |
|
156 reject(); |
|
157 } |
|