miscserversetuppanel.cpp
1 //------------------------------------------------------------------------------
2 // miscserversetuppanel.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "miscserversetuppanel.h"
24 #include "ui_miscserversetuppanel.h"
25 
26 #include "configuration/doomseekerconfig.h"
27 #include "ini/ini.h"
28 #include "plugins/engineplugin.h"
29 #include "serverapi/gamecreateparams.h"
30 
31 DClass<MiscServerSetupPanel> : public Ui::MiscServerSetupPanel
32 {
33 public:
34  bool anythingAvailable;
35 };
36 
37 DPointered(MiscServerSetupPanel)
38 
40 : QWidget(parent)
41 {
42  d->setupUi(this);
43  d->anythingAvailable = false;
44 
45  d->cbHidePasswords->setChecked(gConfig.doomseeker.bHidePasswords);
46 }
47 
48 MiscServerSetupPanel::~MiscServerSetupPanel()
49 {
50 }
51 
52 void MiscServerSetupPanel::fillInParams(GameCreateParams &params)
53 {
54  params.setEmail(d->leEmail->text());
55  params.setMotd(d->pteMOTD->toPlainText());
56  params.setConnectPassword(d->leConnectPassword->text());
57  params.setIngamePassword(d->leJoinPassword->text());
58  params.setRconPassword(d->leRConPassword->text());
59  params.setUrl(d->leURL->text());
60 }
61 
62 bool MiscServerSetupPanel::isAnythingAvailable() const
63 {
64  return d->anythingAvailable;
65 }
66 
67 void MiscServerSetupPanel::loadConfig(Ini &config)
68 {
69  IniSection misc = config.section("Misc");
70  d->leURL->setText(misc["URL"]);
71  d->leEmail->setText(misc["eMail"]);
72  d->leConnectPassword->setText(misc["connectPassword"]);
73  d->leJoinPassword->setText(misc["joinPassword"]);
74  d->leRConPassword->setText(misc["RConPassword"]);
75  d->pteMOTD->document()->setPlainText(misc["MOTD"]);
76 }
77 
78 void MiscServerSetupPanel::saveConfig(Ini &config)
79 {
80  IniSection misc = config.section("Misc");
81  misc["URL"] = d->leURL->text();
82  misc["eMail"] = d->leEmail->text();
83  misc["connectPassword"] = d->leConnectPassword->text();
84  misc["joinPassword"] = d->leJoinPassword->text();
85  misc["RConPassword"] = d->leRConPassword->text();
86  misc["MOTD"] = d->pteMOTD->toPlainText();
87 }
88 
89 void MiscServerSetupPanel::setupForEngine(const EnginePlugin *engine)
90 {
91  d->anythingAvailable = false;
92  bool visible = false;
93 
94  visible = engine->data()->allowsConnectPassword;
95  d->labelConnectPassword->setVisible(visible);
96  d->leConnectPassword->setVisible(visible);
97  d->anythingAvailable = visible || d->anythingAvailable;
98 
99  visible = engine->data()->allowsEmail;
100  d->labelEmail->setVisible(visible);
101  d->leEmail->setVisible(visible);
102  d->anythingAvailable = visible || d->anythingAvailable;
103 
104  visible = engine->data()->allowsJoinPassword;
105  d->labelJoinPassword->setVisible(visible);
106  d->leJoinPassword->setVisible(visible);
107  d->anythingAvailable = visible || d->anythingAvailable;
108 
109  visible = engine->data()->allowsMOTD;
110  d->labelMOTD->setVisible(visible);
111  d->pteMOTD->setVisible(visible);
112  d->anythingAvailable = visible || d->anythingAvailable;
113 
114  visible = engine->data()->allowsRConPassword;
115  d->labelRConPassword->setVisible(visible);
116  d->leRConPassword->setVisible(visible);
117  d->anythingAvailable = visible || d->anythingAvailable;
118 
119  visible = engine->data()->allowsURL;
120  d->labelURL->setVisible(visible);
121  d->leURL->setVisible(visible);
122  d->anythingAvailable = visible || d->anythingAvailable;
123 }
124 
125 void MiscServerSetupPanel::setHidePasswords(bool hide)
126 {
127  QLineEdit::EchoMode echoMode = hide ? QLineEdit::Password : QLineEdit::Normal;
128  d->leConnectPassword->setEchoMode(echoMode);
129  d->leJoinPassword->setEchoMode(echoMode);
130  d->leRConPassword->setEchoMode(echoMode);
131 }
Game parametrization data used when creating new games.
Configuration handler.
Definition: ini.h:69
INI section representation.
Definition: inisection.h:40
IniSection section(const QString &name)
Access configuration file section.
Definition: ini.cpp:95