wadseekershow.cpp
1 //------------------------------------------------------------------------------
2 // wadseekershow.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 "wadseekershow.h"
24 
25 #include "application.h"
26 #include "configuration/doomseekerconfig.h"
27 #include "gui/mainwindow.h"
28 #include "gui/wadseekerinterface.h"
29 #include "serverapi/server.h"
30 #include "templatedpathresolver.h"
31 #include <QDir>
32 #include <QFileInfo>
33 #include <QMap>
34 #include <QMessageBox>
35 
36 DClass<WadseekerShow>
37 {
38 };
39 
40 DPointered(WadseekerShow)
41 
42 WadseekerShow *WadseekerShow::staticInstance = nullptr;
43 
45 {
46 }
47 
48 bool WadseekerShow::checkWadseekerValidity(QWidget *parent)
49 {
50  if (WadseekerInterface::isInstantiated())
51  {
52  QMessageBox::warning(parent, tr("Wadseeker cannot be launched"),
53  tr("Another instance of Wadseeker is already running."), QMessageBox::Ok);
54  return false;
55  }
56 
57  QString targetDirPath = gDoomseekerTemplatedPathResolver().resolve(gConfig.wadseeker.targetDirectory);
58  QDir targetDir(targetDirPath);
59  QFileInfo targetDirFileInfo(targetDirPath);
60 
61  if (targetDirPath.isEmpty() || !targetDir.exists() || !targetDirFileInfo.isWritable())
62  {
63  QString error = tr("Wadseeker will not work correctly:\n\n"
64  "The target directory is either not configured, is invalid or cannot be written to.\n\n"
65  "Please review your Configuration and/or refer to the online help available from "
66  "the Help menu.");
67  QMessageBox::warning(parent, tr("Wadseeker cannot be launched"),
68  error, QMessageBox::Ok);
69  return false;
70  }
71 
72  return true;
73 }
74 
75 WadseekerShow *WadseekerShow::instance()
76 {
77  if (staticInstance == nullptr)
78  staticInstance = new WadseekerShow();
79  return staticInstance;
80 }