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