cfgwadseekergeneral.cpp
1 //------------------------------------------------------------------------------
2 // cfgwadseekergeneral.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 "cfgwadseekergeneral.h"
24 #include "ui_cfgwadseekergeneral.h"
25 
26 #include "configuration/doomseekerconfig.h"
27 #include "pathfinder/filesearchpath.h"
28 #include <QCompleter>
29 #include <QDebug>
30 #include <QDirModel>
31 #include <QMessageBox>
32 
33 DClass<CFGWadseekerGeneral> : public Ui::CFGWadseekerGeneral
34 {
35 };
36 
37 DPointered(CFGWadseekerGeneral)
38 
40 : ConfigurationBaseBox(parent)
41 {
42  d->setupUi(this);
43 
44  // Settings defined in this widget are ATM unused.
45  d->widgetTimeouts->setVisible(false);
46 
47  d->cbTargetDirectory->setCompleter(new QCompleter(new QDirModel()));
48 }
49 
50 CFGWadseekerGeneral::~CFGWadseekerGeneral()
51 {
52 }
53 
54 void CFGWadseekerGeneral::fillTargetDirectoryComboBox()
55 {
56  d->cbTargetDirectory->clear();
57  d->cbTargetDirectory->addItems(gConfig.doomseeker.wadPathsOnly());
58 }
59 
61 {
62  fillTargetDirectoryComboBox();
63 
64  d->cbTargetDirectory->setEditText(gConfig.wadseeker.targetDirectory);
65  d->spinConnectTimeout->setValue(gConfig.wadseeker.connectTimeoutSeconds);
66  d->spinDownloadTimeout->setValue(gConfig.wadseeker.downloadTimeoutSeconds);
67  d->spinMaxConcurrentSiteSeeks->setValue(gConfig.wadseeker.maxConcurrentSiteDownloads);
68  d->spinMaxConcurrentWadDownloads->setValue(gConfig.wadseeker.maxConcurrentWadDownloads);
69 }
70 
72 {
73  gConfig.wadseeker.targetDirectory = d->cbTargetDirectory->currentText();
74 
75  QFileInfo targetDirectoryInfo(d->cbTargetDirectory->currentText());
76  if(!targetDirectoryInfo.isWritable())
77  {
78  QMessageBox::warning(this, tr("Wadseeker - error"),
79  tr("The target directory you selected for Wadseeker can not be written to."));
80  }
81  else
82  {
83  // If path seems valid:
84  // Also take a look at the file paths configuration. Warn if it is not on the list.
85  bool pathPossible = false;
86 
87  QFileInfo wadseekerTargetDirectoryFileInfo(d->cbTargetDirectory->currentText());
88  foreach (FileSearchPath possiblePath, gConfig.doomseeker.wadPaths)
89  {
90  // Bring paths to QFileInfo before string comparison. Two same paths
91  // may have different string representations.
92  // TODO: Consider recursive paths.
93  QFileInfo possiblePathFileInfo(possiblePath.path());
94 
95  if (possiblePathFileInfo == wadseekerTargetDirectoryFileInfo)
96  {
97  pathPossible = true;
98  break;
99  }
100  }
101 
102  if (!pathPossible)
103  {
104  QMessageBox::warning(this, tr("Wadseeker - error"),
105  tr("The specified target directory for Wadseeker could not be found on the file (WAD) paths list.\n\n"
106  "Doomseeker will automatically add this path to the file search paths."));
107  }
108  }
109 
110  gConfig.wadseeker.connectTimeoutSeconds = d->spinConnectTimeout->value();
111  gConfig.wadseeker.downloadTimeoutSeconds = d->spinDownloadTimeout->value();
112  gConfig.wadseeker.maxConcurrentSiteDownloads = d->spinMaxConcurrentSiteSeeks->value();
113  gConfig.wadseeker.maxConcurrentWadDownloads = d->spinMaxConcurrentWadDownloads->value();
114 }
void saveSettings()
Reimplement this to write settings to config from widgets.
void readSettings()
Reimplement this to read settings from config into widgets.
Base class for configuration pages.