checkwadsdlg.cpp
1 //------------------------------------------------------------------------------
2 // checkwadsdlg.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) 2019 Pol Marcet Sardà <polmarcetsarda@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "checkwadsdlg.h"
24 #include "configuration/doomseekerconfig.h"
25 #include "gui/commongui.h"
26 #include "pathfinder/pathfinder.h"
27 #include "pathfinder/wadpathfinder.h"
29 #include <cassert>
30 #include <QScopedPointer>
31 #include <QTimer>
32 
33 DClass<CheckWadsDlg> : public Ui::CheckWadsDlg
34 {
35 public:
36  QList<PWad> wads;
37  const PathFinder *pathFinder;
38  CheckResult wadsChecked;
39  QScopedPointer<QTimer> checkWadTimer;
40  QScopedPointer<QTimer> showWindow;
41  bool checkIncompatibility;
42 };
43 
44 DPointeredNoCopy(CheckWadsDlg)
45 
46 CheckWadsDlg::CheckWadsDlg(const PathFinder *pathFinder, QWidget *parent) : QDialog(parent)
47 {
48  assert(pathFinder != nullptr);
49  d->pathFinder = pathFinder;
50  d->checkIncompatibility = gConfig.doomseeker.bCheckTheIntegrityOfWads;
51  d->checkWadTimer.reset(new QTimer);
52  d->showWindow.reset(new QTimer);
53 
54  d->setupUi(this);
56  connect(d->checkWadTimer.data(), SIGNAL(timeout()), this, SLOT(performCheckStep()));
57  connect(d->showWindow.data(), SIGNAL(timeout()), this, SLOT(openWindow()));
58  connect(d->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(abortCheck()));
59 }
60 
61 CheckWadsDlg::~CheckWadsDlg()
62 {
63 }
64 
65 void CheckWadsDlg::addWads(const QList<PWad> &wads)
66 {
67  d->wads << wads;
68  d->progressBar->setMaximum(d->progressBar->value() + wads.size());
69 }
70 
72 {
73  d->showWindow->setSingleShot(true);
74  d->showWindow->start(500);
75  d->checkWadTimer->start(0);
76 
77  // we'll wait for the checking to finish.
78  QEventLoop loop;
79  connect(this, SIGNAL(finishedChecking()), &loop, SLOT(quit()));
80  loop.exec();
81 
82  d->showWindow->stop();
83  close();
84  return d->wadsChecked;
85 }
86 
87 void CheckWadsDlg::openWindow()
88 {
89  open();
90 }
91 
92 void CheckWadsDlg::performCheckStep()
93 {
94  if (d->wads.isEmpty())
95  {
96  d->checkWadTimer->stop();
97  emit finishedChecking();
98  return;
99  }
100 
101  const PWad wad = d->wads.first();
102  d->wads.removeFirst();
103  WadPathFinder wadFinder(*d->pathFinder);
104  WadFindResult findResult = wadFinder.find(wad.name());
105 
106  if (!findResult.isValid())
107  d->wadsChecked.missingWads << wad;
108  else if (d->checkIncompatibility && !wad.validFile(findResult.path()))
109  d->wadsChecked.incompatibleWads << wad;
110  else
111  d->wadsChecked.foundWads << wad;
112 
113  d->progressBar->setValue(d->progressBar->value() + 1);
114 }
115 
116 void CheckWadsDlg::abortCheck()
117 {
118  d->checkIncompatibility = false;
119 }