42 , QNetworkProxy::Socks5Proxy |
42 , QNetworkProxy::Socks5Proxy |
43 , QNetworkProxy::HttpProxy}; |
43 , QNetworkProxy::HttpProxy}; |
44 |
44 |
45 |
45 |
46 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName) |
46 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName) |
47 : QSettings(fileName, QSettings::IniFormat) |
47 : QSettings(fileName, QSettings::IniFormat, FormWidgets) |
48 { |
48 { |
49 Form = FormWidgets; |
49 Form = FormWidgets; |
50 |
50 |
51 connect(Form->ui.pageOptions->CBEnableFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool))); |
51 setIniCodec("UTF-8"); |
|
52 |
|
53 connect(Form->ui.pageOptions->CBFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool))); |
52 |
54 |
53 //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt()); |
55 //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt()); |
54 resizeToConfigValues(); |
56 resizeToConfigValues(); |
55 |
57 |
56 reloadValues(); |
58 reloadValues(); |
|
59 #ifdef VIDEOREC |
57 reloadVideosValues(); |
60 reloadVideosValues(); |
|
61 #endif |
58 } |
62 } |
59 |
63 |
60 void GameUIConfig::reloadValues(void) |
64 void GameUIConfig::reloadValues(void) |
61 { |
65 { |
62 Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool()); |
66 Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool()); |
75 bool ffscr=value("frontend/fullscreen", false).toBool(); |
79 bool ffscr=value("frontend/fullscreen", false).toBool(); |
76 Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr); |
80 Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr); |
77 |
81 |
78 Form->ui.pageOptions->SLQuality->setValue(value("video/quality", 5).toUInt()); |
82 Form->ui.pageOptions->SLQuality->setValue(value("video/quality", 5).toUInt()); |
79 Form->ui.pageOptions->CBStereoMode->setCurrentIndex(value("video/stereo", 0).toUInt()); |
83 Form->ui.pageOptions->CBStereoMode->setCurrentIndex(value("video/stereo", 0).toUInt()); |
80 Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/effects", true).toBool()); |
84 Form->ui.pageOptions->CBFrontendEffects->setChecked(value("frontend/effects", true).toBool()); |
81 Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool()); |
85 Form->ui.pageOptions->CBSound->setChecked(value("audio/sound", true).toBool()); |
82 Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/sound", true).toBool()); |
86 Form->ui.pageOptions->CBFrontendSound->setChecked(value("frontend/sound", true).toBool()); |
83 Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool()); |
87 Form->ui.pageOptions->CBMusic->setChecked(value("audio/music", true).toBool()); |
84 Form->ui.pageOptions->CBEnableFrontendMusic->setChecked(value("frontend/music", true).toBool()); |
88 Form->ui.pageOptions->CBFrontendMusic->setChecked(value("frontend/music", true).toBool()); |
85 Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt()); |
89 Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt()); |
86 |
90 |
87 QString netNick = value("net/nick", "").toString(); |
91 QString netNick = value("net/nick", "").toString(); |
88 Form->ui.pageOptions->editNetNick->setText(netNick); |
92 Form->ui.pageOptions->editNetNick->setText(netNick); |
89 bool savePwd = value("net/savepassword",true).toBool(); |
93 bool savePwd = value("net/savepassword",true).toBool(); |
90 Form->ui.pageOptions->CBSavePassword->setChecked(savePwd); |
94 Form->ui.pageOptions->CBSavePassword->setChecked(savePwd); |
91 |
95 |
92 Form->ui.pageOptions->editNetPassword->installEventFilter(this); |
96 Form->ui.pageOptions->editNetPassword->installEventFilter(this); |
93 |
97 |
94 int passLength = value("net/passwordlength", 0).toInt(); |
98 int passLength = value("net/passwordlength", 0).toInt(); |
95 setNetPasswordLength(passLength); |
99 if (!savePwd) { |
96 if (savePwd == false) { |
100 Form->ui.pageOptions->editNetPassword->setEnabled(false); |
97 Form->ui.pageOptions->editNetPassword->setEnabled(savePwd); |
|
98 Form->ui.pageOptions->editNetPassword->setText(""); |
101 Form->ui.pageOptions->editNetPassword->setText(""); |
99 setNetPasswordLength(0); |
102 setNetPasswordLength(0); |
|
103 } else |
|
104 { |
|
105 setNetPasswordLength(passLength); |
100 } |
106 } |
101 |
107 |
102 delete netHost; |
108 delete netHost; |
103 netHost = new QString(value("net/ip", "").toString()); |
109 netHost = new QString(value("net/ip", "").toString()); |
104 netPort = value("net/port", 46631).toUInt(); |
110 netPort = value("net/port", 46631).toUInt(); |
122 Form->ui.pageOptions->leProxy->setText(value("proxy/host", "").toString()); |
128 Form->ui.pageOptions->leProxy->setText(value("proxy/host", "").toString()); |
123 Form->ui.pageOptions->sbProxyPort->setValue(value("proxy/port", "8080").toInt()); |
129 Form->ui.pageOptions->sbProxyPort->setValue(value("proxy/port", "8080").toInt()); |
124 Form->ui.pageOptions->leProxyLogin->setText(value("proxy/login", "").toString()); |
130 Form->ui.pageOptions->leProxyLogin->setText(value("proxy/login", "").toString()); |
125 Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString()); |
131 Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString()); |
126 |
132 |
127 depth = HWApplication::desktop()->depth(); |
|
128 if (depth < 16) depth = 16; |
|
129 else if (depth > 16) depth = 32; |
|
130 |
|
131 { // load colors |
133 { // load colors |
132 QStandardItemModel * model = DataManager::instance().colorsModel(); |
134 QStandardItemModel * model = DataManager::instance().colorsModel(); |
133 for(int i = model->rowCount() - 1; i >= 0; --i) |
135 for(int i = model->rowCount() - 1; i >= 0; --i) |
134 model->item(i)->setData(QColor(value(QString("colors/color%1").arg(i), model->item(i)->data().value<QColor>()).value<QColor>())); |
136 model->item(i)->setData(QColor(value(QString("colors/color%1").arg(i), model->item(i)->data().value<QColor>()).value<QColor>())); |
135 } |
137 } |
136 } |
138 } |
137 |
139 |
138 void GameUIConfig::reloadVideosValues(void) |
140 void GameUIConfig::reloadVideosValues(void) |
139 { |
141 { |
140 Form->ui.pageVideos->framerateBox->setValue(value("videorec/fps",25).toUInt()); |
142 // one pass with default values |
141 Form->ui.pageVideos->bitrateBox->setValue(value("videorec/bitrate",400).toUInt()); |
143 Form->ui.pageOptions->setDefaultOptions(); |
142 bool useGameRes = value("videorec/usegameres",true).toBool(); |
144 |
|
145 // then load user configuration |
|
146 Form->ui.pageOptions->framerateBox->setCurrentIndex( |
|
147 Form->ui.pageOptions->framerateBox->findData( |
|
148 value("videorec/framerate", rec_Framerate()).toString() + " fps", |
|
149 Qt::MatchExactly) ); |
|
150 Form->ui.pageOptions->bitrateBox->setValue(value("videorec/bitrate", rec_Bitrate()).toUInt()); |
|
151 bool useGameRes = value("videorec/usegameres",Form->ui.pageOptions->checkUseGameRes->isChecked()).toBool(); |
143 if (useGameRes) |
152 if (useGameRes) |
144 { |
153 { |
145 QRect res = vid_Resolution(); |
154 QRect res = vid_Resolution(); |
146 Form->ui.pageVideos->widthEdit->setText(QString::number(res.width())); |
155 Form->ui.pageOptions->widthEdit->setText(QString::number(res.width())); |
147 Form->ui.pageVideos->heightEdit->setText(QString::number(res.height())); |
156 Form->ui.pageOptions->heightEdit->setText(QString::number(res.height())); |
148 } |
157 } |
149 else |
158 else |
150 { |
159 { |
151 Form->ui.pageVideos->widthEdit->setText(value("videorec/width","800").toString()); |
160 Form->ui.pageOptions->widthEdit->setText(value("videorec/width","800").toString()); |
152 Form->ui.pageVideos->heightEdit->setText(value("videorec/height","600").toString()); |
161 Form->ui.pageOptions->heightEdit->setText(value("videorec/height","600").toString()); |
153 } |
162 } |
154 Form->ui.pageVideos->checkUseGameRes->setChecked(useGameRes); |
163 Form->ui.pageOptions->checkUseGameRes->setChecked(useGameRes); |
155 Form->ui.pageVideos->checkRecordAudio->setChecked(value("videorec/audio",true).toBool()); |
164 Form->ui.pageOptions->checkRecordAudio->setChecked( |
156 if (!Form->ui.pageVideos->tryCodecs(value("videorec/format","no").toString(), |
165 value("videorec/audio",Form->ui.pageOptions->checkRecordAudio->isChecked()).toBool() ); |
|
166 if (!Form->ui.pageOptions->tryCodecs(value("videorec/format","no").toString(), |
157 value("videorec/videocodec","no").toString(), |
167 value("videorec/videocodec","no").toString(), |
158 value("videorec/audiocodec","no").toString())) |
168 value("videorec/audiocodec","no").toString())) |
159 Form->ui.pageVideos->setDefaultCodecs(); |
169 Form->ui.pageOptions->setDefaultCodecs(); |
160 } |
170 } |
161 |
171 |
162 QStringList GameUIConfig::GetTeamsList() |
172 QStringList GameUIConfig::GetTeamsList() |
163 { |
173 { |
164 QDir teamdir; |
174 QDir teamdir; |
173 return cleanedList; |
183 return cleanedList; |
174 } |
184 } |
175 |
185 |
176 void GameUIConfig::resizeToConfigValues() |
186 void GameUIConfig::resizeToConfigValues() |
177 { |
187 { |
178 Form->resize(value("frontend/width", 800).toUInt(), value("frontend/height", 600).toUInt()); |
188 // fill 2/3 of the screen desktop |
|
189 const QRect deskSize = QApplication::desktop()->screenGeometry(-1); |
|
190 Form->resize(value("frontend/width", qMin(qMax(deskSize.width()*2/3,800),deskSize.width())).toUInt(), |
|
191 value("frontend/height", qMin(qMax(deskSize.height()*2/3,600),deskSize.height())).toUInt()); |
|
192 |
|
193 // move the window to the center of the screen |
|
194 QPoint center = QApplication::desktop()->availableGeometry(-1).center(); |
|
195 center.setX(center.x() - (Form->width()/2)); |
|
196 center.setY(center.y() - (Form->height()/2)); |
|
197 Form->move(center); |
179 } |
198 } |
180 |
199 |
181 void GameUIConfig::SaveOptions() |
200 void GameUIConfig::SaveOptions() |
182 { |
201 { |
183 setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
202 setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
208 setValue("audio/music", isMusicEnabled()); |
227 setValue("audio/music", isMusicEnabled()); |
209 setValue("frontend/music", isFrontendMusicEnabled()); |
228 setValue("frontend/music", isFrontendMusicEnabled()); |
210 setValue("audio/volume", Form->ui.pageOptions->volumeBox->value()); |
229 setValue("audio/volume", Form->ui.pageOptions->volumeBox->value()); |
211 |
230 |
212 setValue("net/nick", netNick()); |
231 setValue("net/nick", netNick()); |
213 if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) |
232 if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) { |
214 { |
233 setPasswordHash(netPasswordHash()); |
215 setValue("net/passwordhash", netPasswordHash()); |
234 } |
216 setValue("net/passwordlength", netPasswordLength()); |
235 else if(!Form->ui.pageOptions->CBSavePassword->isChecked()) { |
217 } |
236 clearPasswordHash(); |
|
237 } |
|
238 |
218 setValue("net/savepassword", Form->ui.pageOptions->CBSavePassword->isChecked()); |
239 setValue("net/savepassword", Form->ui.pageOptions->CBSavePassword->isChecked()); |
219 setValue("net/ip", *netHost); |
240 setValue("net/ip", *netHost); |
220 setValue("net/port", netPort); |
241 setValue("net/port", netPort); |
221 setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); |
242 setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); |
222 setValue("net/serverport", Form->ui.pageNetServer->sbPort->value()); |
243 setValue("net/serverport", Form->ui.pageNetServer->sbPort->value()); |
266 QStandardItemModel * model = DataManager::instance().colorsModel(); |
287 QStandardItemModel * model = DataManager::instance().colorsModel(); |
267 for(int i = model->rowCount() - 1; i >= 0; --i) |
288 for(int i = model->rowCount() - 1; i >= 0; --i) |
268 setValue(QString("colors/color%1").arg(i), model->item(i)->data()); |
289 setValue(QString("colors/color%1").arg(i), model->item(i)->data()); |
269 } |
290 } |
270 |
291 |
271 Form->gameSettings->sync(); |
292 sync(); |
272 } |
293 } |
273 |
294 |
274 void GameUIConfig::SaveVideosOptions() |
295 void GameUIConfig::SaveVideosOptions() |
275 { |
296 { |
276 QRect res = rec_Resolution(); |
297 QRect res = rec_Resolution(); |
277 setValue("videorec/format", AVFormat()); |
298 setValue("videorec/format", AVFormat()); |
278 setValue("videorec/videocodec", videoCodec()); |
299 setValue("videorec/videocodec", videoCodec()); |
279 setValue("videorec/audiocodec", audioCodec()); |
300 setValue("videorec/audiocodec", audioCodec()); |
280 setValue("videorec/fps", rec_Framerate()); |
301 setValue("videorec/framerate", rec_Framerate()); |
281 setValue("videorec/bitrate", rec_Bitrate()); |
302 setValue("videorec/bitrate", rec_Bitrate()); |
282 setValue("videorec/width", res.width()); |
303 setValue("videorec/width", res.width()); |
283 setValue("videorec/height", res.height()); |
304 setValue("videorec/height", res.height()); |
284 setValue("videorec/usegameres", Form->ui.pageVideos->checkUseGameRes->isChecked()); |
305 setValue("videorec/usegameres", Form->ui.pageOptions->checkUseGameRes->isChecked()); |
285 setValue("videorec/audio", recordAudio()); |
306 setValue("videorec/audio", recordAudio()); |
286 |
307 |
287 Form->gameSettings->sync(); |
308 sync(); |
|
309 } |
|
310 |
|
311 void GameUIConfig::setValue(const QString &key, const QVariant &value) |
|
312 { |
|
313 //qDebug() << "[settings]" << key << value; |
|
314 QSettings::setValue(key, value); |
288 } |
315 } |
289 |
316 |
290 QString GameUIConfig::language() |
317 QString GameUIConfig::language() |
291 { |
318 { |
292 return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString(); |
319 return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString(); |
368 return Form->ui.pageOptions->CBFrontendFullscreen->isChecked(); |
395 return Form->ui.pageOptions->CBFrontendFullscreen->isChecked(); |
369 } |
396 } |
370 |
397 |
371 bool GameUIConfig::isSoundEnabled() |
398 bool GameUIConfig::isSoundEnabled() |
372 { |
399 { |
373 return Form->ui.pageOptions->CBEnableSound->isChecked(); |
400 return Form->ui.pageOptions->CBSound->isChecked(); |
374 } |
401 } |
375 bool GameUIConfig::isFrontendSoundEnabled() |
402 bool GameUIConfig::isFrontendSoundEnabled() |
376 { |
403 { |
377 return Form->ui.pageOptions->CBEnableFrontendSound->isChecked(); |
404 return Form->ui.pageOptions->CBFrontendSound->isChecked(); |
378 } |
405 } |
379 |
406 |
380 bool GameUIConfig::isMusicEnabled() |
407 bool GameUIConfig::isMusicEnabled() |
381 { |
408 { |
382 return Form->ui.pageOptions->CBEnableMusic->isChecked(); |
409 return Form->ui.pageOptions->CBMusic->isChecked(); |
383 } |
410 } |
384 bool GameUIConfig::isFrontendMusicEnabled() |
411 bool GameUIConfig::isFrontendMusicEnabled() |
385 { |
412 { |
386 return Form->ui.pageOptions->CBEnableFrontendMusic->isChecked(); |
413 return Form->ui.pageOptions->CBFrontendMusic->isChecked(); |
387 } |
414 } |
388 |
415 |
389 bool GameUIConfig::isShowFPSEnabled() |
416 bool GameUIConfig::isShowFPSEnabled() |
390 { |
417 { |
391 return Form->ui.pageOptions->CBShowFPS->isChecked(); |
418 return Form->ui.pageOptions->CBShowFPS->isChecked(); |
443 return Form->ui.pageOptions->editNetPassword->text().size(); |
465 return Form->ui.pageOptions->editNetPassword->text().size(); |
444 } |
466 } |
445 |
467 |
446 bool GameUIConfig::netPasswordIsValid() |
468 bool GameUIConfig::netPasswordIsValid() |
447 { |
469 { |
448 return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0')); |
470 return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '*')); |
|
471 } |
|
472 |
|
473 void GameUIConfig::clearPasswordHash() |
|
474 { |
|
475 setValue("net/passwordhash", QString()); |
|
476 setValue("net/passwordlength", 0); |
|
477 setValue("net/savepassword", false); //changes the savepassword value to false in order to not let the user save an empty password in PAGE_SETUP |
|
478 reloadValues(); //reloads the values of PAGE_SETUP |
|
479 } |
|
480 |
|
481 void GameUIConfig::setPasswordHash(const QString & passwordhash) |
|
482 { |
|
483 setValue("net/passwordhash", passwordhash); |
|
484 setValue("net/passwordlength", passwordhash.size()/4); |
|
485 setNetPasswordLength(passwordhash.size()/4); //the hash.size() is divided by 4 let PAGE_SETUP use a reasonable number of stars to display the PW |
|
486 } |
|
487 |
|
488 QString GameUIConfig::passwordHash() |
|
489 { |
|
490 return value("net/passwordhash").toString(); |
|
491 } |
|
492 |
|
493 void GameUIConfig::clearTempHash() |
|
494 { |
|
495 setTempHash(QString()); |
|
496 } |
|
497 |
|
498 void GameUIConfig::setTempHash(const QString & temphash) |
|
499 { |
|
500 this->temphash = temphash; |
|
501 } |
|
502 |
|
503 QString GameUIConfig::tempHash() { |
|
504 return this->temphash; |
449 } |
505 } |
450 |
506 |
451 // When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field |
507 // When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field |
452 bool GameUIConfig::eventFilter(QObject *object, QEvent *event) |
508 bool GameUIConfig::eventFilter(QObject *object, QEvent *event) |
453 { |
509 { |
483 return Form->ui.pageOptions->volumeBox->value() * 128 / 100; |
539 return Form->ui.pageOptions->volumeBox->value() * 128 / 100; |
484 } |
540 } |
485 |
541 |
486 QString GameUIConfig::AVFormat() |
542 QString GameUIConfig::AVFormat() |
487 { |
543 { |
488 return Form->ui.pageVideos->format(); |
544 return Form->ui.pageOptions->format(); |
489 } |
545 } |
490 |
546 |
491 QString GameUIConfig::videoCodec() |
547 QString GameUIConfig::videoCodec() |
492 { |
548 { |
493 return Form->ui.pageVideos->videoCodec(); |
549 return Form->ui.pageOptions->videoCodec(); |
494 } |
550 } |
495 |
551 |
496 QString GameUIConfig::audioCodec() |
552 QString GameUIConfig::audioCodec() |
497 { |
553 { |
498 return Form->ui.pageVideos->audioCodec(); |
554 return Form->ui.pageOptions->audioCodec(); |
499 } |
555 } |
500 |
556 |
501 QRect GameUIConfig::rec_Resolution() |
557 QRect GameUIConfig::rec_Resolution() |
502 { |
558 { |
503 if (Form->ui.pageVideos->checkUseGameRes->isChecked()) |
559 if (Form->ui.pageOptions->checkUseGameRes->isChecked()) |
504 return vid_Resolution(); |
560 return vid_Resolution(); |
505 QRect res(0,0,0,0); |
561 QRect res(0,0,0,0); |
506 res.setWidth(Form->ui.pageVideos->widthEdit->text().toUInt()); |
562 res.setWidth(Form->ui.pageOptions->widthEdit->text().toUInt()); |
507 res.setHeight(Form->ui.pageVideos->heightEdit->text().toUInt()); |
563 res.setHeight(Form->ui.pageOptions->heightEdit->text().toUInt()); |
508 return res; |
564 return res; |
509 } |
565 } |
510 |
566 |
511 int GameUIConfig::rec_Framerate() |
567 int GameUIConfig::rec_Framerate() |
512 { |
568 { |
513 return Form->ui.pageVideos->framerateBox->value(); |
569 // remove the "fps" label |
|
570 QString fpsText = Form->ui.pageOptions->framerateBox->currentText(); |
|
571 QStringList fpsList = fpsText.split(" "); |
|
572 return fpsList.first().toInt(); |
514 } |
573 } |
515 |
574 |
516 int GameUIConfig::rec_Bitrate() |
575 int GameUIConfig::rec_Bitrate() |
517 { |
576 { |
518 return Form->ui.pageVideos->bitrateBox->value(); |
577 return Form->ui.pageOptions->bitrateBox->value(); |
519 } |
578 } |
520 |
579 |
521 bool GameUIConfig::recordAudio() |
580 bool GameUIConfig::recordAudio() |
522 { |
581 { |
523 return Form->ui.pageVideos->checkRecordAudio->isChecked(); |
582 return Form->ui.pageOptions->checkRecordAudio->isChecked(); |
524 } |
583 } |