22 #include "hwform.h" |
22 #include "hwform.h" |
23 #include "pages.h" |
23 #include "pages.h" |
24 #include "hwconsts.h" |
24 #include "hwconsts.h" |
25 #include "fpsedit.h" |
25 #include "fpsedit.h" |
26 |
26 |
27 GameUIConfig::GameUIConfig(HWForm * FormWidgets) |
27 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName) |
28 : QObject() |
28 : QSettings(fileName, QSettings::IniFormat) |
29 { |
29 { |
30 Form = FormWidgets; |
30 Form = FormWidgets; |
31 |
31 |
32 QFile settings(cfgdir->absolutePath() + "/options"); |
32 Form->ui.pageOptions->CBResolution->setCurrentIndex(value("video/resolution").toUInt()); |
33 if (settings.open(QIODevice::ReadOnly)) |
33 Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
34 { |
|
35 QTextStream stream(&settings); |
|
36 stream.setCodec("UTF-8"); |
|
37 QString str; |
|
38 |
34 |
39 while (!stream.atEnd()) |
35 Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool()); |
40 { |
36 |
41 str = stream.readLine(); |
37 Form->ui.pageNet->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString()); |
42 if (str.startsWith(";")) continue; |
38 Form->ui.pageNet->editIP->setText(value("net/ip", "").toString()); |
43 if (str.startsWith("resolution ")) |
39 Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool()); |
44 { |
40 Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt()); |
45 Form->ui.pageOptions->CBResolution->setCurrentIndex(str.mid(11).toLong()); |
|
46 } else |
|
47 if (str.startsWith("fullscreen ")) |
|
48 { |
|
49 Form->ui.pageOptions->CBFullscreen->setChecked(str.mid(11).toLong()); |
|
50 } else |
|
51 if (str.startsWith("sound ")) |
|
52 { |
|
53 Form->ui.pageOptions->CBEnableSound->setChecked(str.mid(6).toLong()); |
|
54 } else |
|
55 if (str.startsWith("nick ")) |
|
56 { |
|
57 Form->ui.pageNet->editNetNick->setText(str.mid(5)); |
|
58 } else |
|
59 if (str.startsWith("ip ")) |
|
60 { |
|
61 Form->ui.pageNet->editIP->setText(str.mid(3)); |
|
62 } else |
|
63 if (str.startsWith("showfps ")) |
|
64 { |
|
65 Form->ui.pageOptions->CBShowFPS->setChecked(str.mid(8).toLong()); |
|
66 } else |
|
67 if (str.startsWith("interval ")) |
|
68 { |
|
69 Form->ui.pageOptions->fpsedit->setValue(str.mid(9).toUInt()); |
|
70 } |
|
71 } |
|
72 settings.close(); |
|
73 } |
|
74 |
41 |
75 QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
42 QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
76 if (themesfile.open(QIODevice::ReadOnly)) { |
43 if (themesfile.open(QIODevice::ReadOnly)) { |
77 QTextStream stream(&themesfile); |
44 QTextStream stream(&themesfile); |
78 QString str; |
45 QString str; |
97 return cleanedList; |
64 return cleanedList; |
98 } |
65 } |
99 |
66 |
100 void GameUIConfig::SaveOptions() |
67 void GameUIConfig::SaveOptions() |
101 { |
68 { |
102 QFile settings(cfgdir->absolutePath() + "/options"); |
69 setValue("video/resolution", vid_Resolution()); |
103 if (!settings.open(QIODevice::WriteOnly)) |
70 setValue("video/fullscreen", vid_Fullscreen()); |
104 { |
71 |
105 QMessageBox::critical(0, |
72 setValue("audio/sound", isSoundEnabled()); |
106 tr("Error"), |
73 |
107 tr("Cannot save options to file %1").arg(settings.fileName()), |
74 setValue("net/nick", Form->ui.pageNet->editNetNick->text()); |
108 tr("Quit")); |
75 setValue("net/ip", Form->ui.pageNet->editIP->text()); |
109 return ; |
76 |
110 } |
77 setValue("fps/show", isShowFPSEnabled()); |
111 QTextStream stream(&settings); |
78 setValue("fps/interval", Form->ui.pageOptions->fpsedit->value()); |
112 stream.setCodec("UTF-8"); |
|
113 stream << "; Generated by Hedgewars, do not modify" << endl; |
|
114 stream << "resolution " << vid_Resolution() << endl; |
|
115 stream << "fullscreen " << vid_Fullscreen() << endl; |
|
116 stream << "sound " << isSoundEnabled() << endl; |
|
117 stream << "nick " << Form->ui.pageNet->editNetNick->text() << endl; |
|
118 stream << "ip " << Form->ui.pageNet->editIP->text() << endl; |
|
119 stream << "showfps " << isShowFPSEnabled() << endl; |
|
120 stream << "interval " << Form->ui.pageOptions->fpsedit->value() << endl; |
|
121 settings.close(); |
|
122 } |
79 } |
123 |
80 |
124 int GameUIConfig::vid_Resolution() |
81 int GameUIConfig::vid_Resolution() |
125 { |
82 { |
126 return Form->ui.pageOptions->CBResolution->currentIndex(); |
83 return Form->ui.pageOptions->CBResolution->currentIndex(); |