cfgwadseekergeneral.cpp
1 //------------------------------------------------------------------------------
2 // cfgwadseekergeneral.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) 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 public:
36  bool completerActive;
37 
38  QString targetDirectory() const
39  {
40  return cbTargetDirectory->currentText().trimmed();
41  }
42 };
43 
44 DPointered(CFGWadseekerGeneral)
45 
47 : ConfigPage(parent)
48 {
49  d->setupUi(this);
50  d->completerActive = false;
51 
52  // Settings defined in this widget are ATM unused.
53  d->widgetTimeouts->setVisible(false);
54  d->lblDirectoryWarning->setPixmap(QPixmap(":/icons/exclamation_16.png"));
55  d->lblDirectoryWarning->hide();
56  d->lblDirectoryWarning->setWordWrap(true);
57 
58  this->connect(d->cbTargetDirectory, SIGNAL(editTextChanged(QString)),
59  SIGNAL(validationRequested()));
60 }
61 
62 CFGWadseekerGeneral::~CFGWadseekerGeneral()
63 {
64 }
65 
66 void CFGWadseekerGeneral::activateCompleter()
67 {
68  // Lazy activation of completer prevents floppy drive clicking
69  // on QComboBox::addItem() if you're on Windows and if you
70  // actually have a floppy drive.
71  //
72  // The floppy drive will still click *one time* when user tries to type
73  // anything, but at least it won't click on readSettings() anymore
74  // (so, essentially, when user opens config box).
75  if (!d->completerActive)
76  {
77  d->cbTargetDirectory->setCompleter(new QCompleter(new QDirModel()));
78  d->completerActive = true;
79  }
80 }
81 
82 void CFGWadseekerGeneral::fillTargetDirectoryComboBox()
83 {
84  d->cbTargetDirectory->clear();
85  d->cbTargetDirectory->addItems(gConfig.doomseeker.wadPathsOnly());
86 }
87 
89 {
90  fillTargetDirectoryComboBox();
91 
92  d->cbTargetDirectory->setEditText(gConfig.wadseeker.targetDirectory);
93  d->spinConnectTimeout->setValue(gConfig.wadseeker.connectTimeoutSeconds);
94  d->spinDownloadTimeout->setValue(gConfig.wadseeker.downloadTimeoutSeconds);
95  d->spinMaxConcurrentSiteSeeks->setValue(gConfig.wadseeker.maxConcurrentSiteDownloads);
96  d->spinMaxConcurrentWadDownloads->setValue(gConfig.wadseeker.maxConcurrentWadDownloads);
97 }
98 
100 {
101  gConfig.wadseeker.targetDirectory = d->targetDirectory();
102  gConfig.wadseeker.connectTimeoutSeconds = d->spinConnectTimeout->value();
103  gConfig.wadseeker.downloadTimeoutSeconds = d->spinDownloadTimeout->value();
104  gConfig.wadseeker.maxConcurrentSiteDownloads = d->spinMaxConcurrentSiteSeeks->value();
105  gConfig.wadseeker.maxConcurrentWadDownloads = d->spinMaxConcurrentWadDownloads->value();
106 }
107 
108 void CFGWadseekerGeneral::showEvent(QShowEvent *event)
109 {
110  activateCompleter();
111  ConfigPage::showEvent(event);
112 }
113 
115 {
116  QString error;
117 
118  QFileInfo targetDirectory = d->targetDirectory();
119  if (error.isEmpty() && d->targetDirectory().isEmpty())
120  {
121  error = tr("No path specified.");
122  }
123 
124  if (error.isEmpty() && !targetDirectory.exists())
125  {
126  error = tr("This path doesn't exist.");
127  }
128 
129  if (error.isEmpty() && !targetDirectory.isDir())
130  {
131  error = tr("This is not a directory.");
132  }
133 
134  if (error.isEmpty() && !targetDirectory.isWritable())
135  {
136  error = tr("This directory cannot be written to.");
137  }
138 
139  // If path seems valid also take a look at the file
140  // paths configuration. Warn if it is not on the list.
141  if (error.isEmpty())
142  {
143  bool pathOnList = false;
144  foreach(FileSearchPath possiblePath, gConfig.doomseeker.wadPaths)
145  {
146  // Bring paths to QFileInfo before string comparison. Two same paths
147  // may have different string representations.
148  // TODO: Consider recursive paths.
149  QFileInfo possiblePathFileInfo(possiblePath.path());
150 
151  if (possiblePathFileInfo == targetDirectory)
152  {
153  pathOnList = true;
154  break;
155  }
156  }
157 
158  if (!pathOnList)
159  {
160  error = tr(
161  "The specified target directory for Wadseeker could not be found on the file (WAD) paths list.\n\n"
162  "Doomseeker will automatically add this path to the file search paths.");
163  }
164  }
165 
166  d->lblDirectoryWarning->setVisible(!error.isEmpty());
167  d->lblDirectoryWarning->setText(error);
168  return error.isEmpty() ? VALIDATION_OK : VALIDATION_ERROR;
169 }
Validation
Result of validate()
Definition: configpage.h:50
void saveSettings()
Reimplement this to write settings to config from widgets.
Validation detected no problems.
Definition: configpage.h:53
Validation validate()
Validate settings on this page.
void readSettings()
Reimplement this to read settings from config into widgets.
Validation detected at least one problem.
Definition: configpage.h:55
Base class for configuration pages.
Definition: configpage.h:44