doomseekerconfigurationdialog.cpp
1 //------------------------------------------------------------------------------
2 // doomseekerconfigurationdialog.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; 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) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "doomseekerconfigurationdialog.h"
24 #include "configuration/doomseekerconfig.h"
25 #include "gui/configuration/cfgappearance.h"
26 #include "gui/configuration/cfgautoupdates.h"
27 #include "gui/configuration/cfgcustomservers.h"
28 #include "gui/configuration/cfgfilepaths.h"
29 #include "gui/configuration/cfgquery.h"
30 #include "gui/configuration/cfgserverpasswords.h"
31 #include "gui/configuration/cfgwadalias.h"
32 #include "gui/configuration/cfgwadseekerappearance.h"
33 #include "gui/configuration/cfgwadseekergeneral.h"
34 #include "gui/configuration/cfgwadseekeridgames.h"
35 #include "gui/configuration/cfgwadseekersites.h"
36 #include "gui/configuration/engineconfigpage.h"
37 #include "gui/mainwindow.h"
38 #include "plugins/engineplugin.h"
39 #include "plugins/pluginloader.h"
40 #include "updater/updatechannel.h"
41 #include "application.h"
42 #include "log.h"
43 #include "qtmetapointer.h"
44 #include <QStandardItem>
45 #include <QTreeView>
46 
47 DoomseekerConfigurationDialog::DoomseekerConfigurationDialog(QWidget* parent)
48 : ConfigurationDialog(parent)
49 {
50  this->bAppearanceChanged = false;
51  this->bCustomServersChanged = false;
52 }
53 
54 QStandardItem* DoomseekerConfigurationDialog::addConfigPage(QStandardItem* rootItem, ConfigPage* configPage, int position)
55 {
56  QStandardItem* pItem = ConfigurationDialog::addConfigPage(rootItem, configPage, position);
57 
58  if (pItem != NULL)
59  {
60  connect(configPage, SIGNAL( appearanceChanged() ),
61  SLOT( appearanceChangedSlot() ) );
62  }
63 
64  return pItem;
65 }
66 
67 bool DoomseekerConfigurationDialog::addEngineConfiguration(ConfigPage* configPage)
68 {
69  if (enginesRoot != NULL)
70  {
71  return addConfigPage(enginesRoot, configPage);
72  }
73  return false;
74 }
75 
76 void DoomseekerConfigurationDialog::appearanceChangedSlot()
77 {
78  this->bAppearanceChanged = true;
79 }
80 
81 void DoomseekerConfigurationDialog::appendFilePathsConfigurationBoxes()
82 {
83  QStandardItem *itemFilePaths = addConfigPage(NULL, new CFGFilePaths(this));
84  addConfigPage(itemFilePaths, new CFGWadAlias(this));
85 }
86 
87 void DoomseekerConfigurationDialog::appendWadseekerConfigurationBoxes()
88 {
89  QStandardItem* wadseekerRoot = addLabel(NULL, tr("Wadseeker"));
90  wadseekerRoot->setIcon(QIcon(":/icons/get-wad.png"));
91 
92  ConfigPage* configPage = NULL;
93 
94  configPage = new CFGWadseekerAppearance(this);
95  addConfigPage(wadseekerRoot, configPage);
96 
97  configPage = new CFGWadseekerGeneral(this);
98  addConfigPage(wadseekerRoot, configPage);
99 
100  configPage = new CFGWadseekerSites(this);
101  addConfigPage(wadseekerRoot, configPage);
102 
103  configPage = new CFGWadseekerIdgames(this);
104  addConfigPage(wadseekerRoot, configPage);
105 }
106 
107 void DoomseekerConfigurationDialog::doSaveSettings()
108 {
109  bCustomServersChanged = customServersCfgBox->allowSave();
110  if (gConfig.saveToFile())
111  {
112  gLog << tr("Settings saved!");
113  }
114  else
115  {
116  gLog << tr("Settings save failed!");
117  }
118 }
119 
120 void DoomseekerConfigurationDialog::initOptionsList()
121 {
122  enginesRoot = addLabel(NULL, tr("Engines"));
123  enginesRoot->setIcon(QIcon(":/icons/joystick.png"));
124 
125  ConfigPage* configPage = NULL;
126 
127  configPage = new CFGAppearance(this);
128  addConfigPage(NULL, configPage);
129 
130  configPage = new CFGAutoUpdates(this);
131  addConfigPage(NULL, configPage);
132 
133  configPage = new CFGCustomServers(this);
134  addConfigPage(NULL, configPage);
135  customServersCfgBox = configPage;
136 
137  configPage = new CFGServerPasswords(this);
138  addConfigPage(NULL, configPage);
139 
140  configPage = new CFGQuery(this);
141  addConfigPage(NULL, configPage);
142 
143  appendFilePathsConfigurationBoxes();
144  appendWadseekerConfigurationBoxes();
145 
146  optionsTree()->expandAll();
147 }
148 
149 void DoomseekerConfigurationDialog::openConfiguration(const EnginePlugin *openPlugin)
150 {
151  MainWindow *mw = gApp->mainWindow();
152 
153  DoomseekerConfigurationDialog configDialog(mw);
154  configDialog.initOptionsList();
155 
156  for(unsigned i = 0; i < gPlugins->numPlugins(); ++i)
157  {
158  EnginePlugin* pPluginInfo = gPlugins->info(i);
159 
160  // Create the config box.
161  ConfigPage* configPage = pPluginInfo->configuration(&configDialog);
162  configDialog.addEngineConfiguration(configPage);
163  }
164 
165  bool bLookupHostsSettingBefore = gConfig.doomseeker.bLookupHosts;
166  DoomseekerConfig::AutoUpdates::UpdateMode updateModeBefore = gConfig.autoUpdates.updateMode;
167  UpdateChannel updateChannelBefore = UpdateChannel::fromName(gConfig.autoUpdates.updateChannelName);
168  // Stop the auto refresh timer during configuration.
169  mw->stopAutoRefreshTimer();
170 
171  if(openPlugin)
172  configDialog.showPluginConfiguration(openPlugin);
173 
174  configDialog.exec();
175 
176  // Do some cleanups after config box finishes.
177  mw->initAutoRefreshTimer();
178 
179  // If update channel or update mode changed then we should discard the
180  // current updates.
181  UpdateChannel updateChannelAfter = UpdateChannel::fromName(gConfig.autoUpdates.updateChannelName);
182  if (updateChannelBefore != updateChannelAfter
183  || updateModeBefore != gConfig.autoUpdates.updateMode)
184  {
185  mw->abortAutoUpdater();
186  gConfig.autoUpdates.bPerformUpdateOnNextRun = false;
187  gConfig.saveToFile();
188  }
189 
190  mw->finishConfiguration(configDialog, !bLookupHostsSettingBefore && gConfig.doomseeker.bLookupHosts);
191 }
192 
193 void DoomseekerConfigurationDialog::showPluginConfiguration(const EnginePlugin *plugin)
194 {
195  // Find plugin page and make it the active page
196  for(int i = 0;i < enginesRoot->rowCount();++i)
197  {
198  QStandardItem *page = enginesRoot->child(i);
199  QtMetaPointer metaPointer = page->data(Qt::UserRole).value<QtMetaPointer>();
200  void* pointer = metaPointer;
201  EngineConfigPage *engineConfig = (EngineConfigPage*)pointer;
202 
203  if(engineConfig->plugin() == plugin)
204  {
205  showConfigPage(engineConfig);
206  }
207  }
208 }
virtual ConfigPage * configuration(QWidget *parent)
Engine&#39;s configuration widget.
QTreeView * optionsTree()
Returns pointer to the tree widget that contains configuration sections list.
static UpdateChannel fromName(const QString &name)
Creates object from its internal name.
void finishConfiguration(DoomseekerConfigurationDialog &, bool)
Definition: mainwindow.cpp:672
virtual QStandardItem * addConfigPage(QStandardItem *rootItem, ConfigPage *configPage, int position=-1)
Adds a new configuration page to the options tree view.
QStandardItem * addConfigPage(QStandardItem *rootItem, ConfigPage *configPage, int position=-1)
Adds a new configuration page to the options tree view.
QStandardItem * addLabel(QStandardItem *rootItem, const QString &label, int position=-1)
Adds a label node to the options tree view.
const EnginePlugin * plugin() const
Parent plugin handled by this page.
Base for configuration pages for plugins; provides some default behavior.
Base class for configuration pages.
Definition: configpage.h:43
void showConfigPage(ConfigPage *widget)
void initAutoRefreshTimer()
Definition: mainwindow.cpp:785