customparamspanel.cpp
1 //------------------------------------------------------------------------------
2 // customparamspanel.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 "customparamspanel.h"
24 #include "ui_customparamspanel.h"
25 
26 #include "ini/ini.h"
27 #include "scanner.h"
28 #include "serverapi/gamecreateparams.h"
29 
30 DClass<CustomParamsPanel> : public Ui::CustomParamsPanel
31 {
32 };
33 
34 DPointered(CustomParamsPanel)
35 
36 CustomParamsPanel::CustomParamsPanel(QWidget *parent)
37  : QWidget(parent)
38 {
39  d->setupUi(this);
40 }
41 
42 CustomParamsPanel::~CustomParamsPanel()
43 {
44 }
45 
46 void CustomParamsPanel::fillInParams(GameCreateParams &params)
47 {
48  QString customParams = d->paramsArea->toPlainText();
49  QByteArray utf8 = customParams.toUtf8();
50  Scanner sc(utf8.constData(), utf8.length());
51  while (sc.nextString())
52  {
53  params.customParameters() << sc->str();
54  }
55 }
56 
57 void CustomParamsPanel::loadConfig(Ini &config)
58 {
59  IniSection misc = config.section("Misc");
60  d->paramsArea->document()->setPlainText(misc["CustomParams"]);
61 }
62 
63 void CustomParamsPanel::saveConfig(Ini &config)
64 {
65  IniSection misc = config.section("Misc");
66  misc["CustomParams"] = d->paramsArea->toPlainText();
67 }