application.cpp
1 //------------------------------------------------------------------------------
2 // application.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 "application.h"
24 
25 #include "gui/mainwindow.h"
26 #include <cassert>
27 
28 DClass<Application>
29 {
30  public:
31  MainWindow *mainWindow;
32  bool running;
33 };
34 
35 DPointered(Application)
36 
37 Application *Application::staticInstance = NULL;
38 
39 Application::Application(int &argc, char **argv)
40 : QApplication(argc, argv)
41 {
42  d->mainWindow = NULL;
43  d->running = true;
44 }
45 
46 
47 Application::~Application()
48 {
49 }
50 
52 {
53  if (staticInstance != NULL)
54  {
55  staticInstance->destroy();
56  }
57 }
58 
59 void Application::destroy()
60 {
61  d->running = false;
62 }
63 
64 bool Application::isInit()
65 {
66  return staticInstance != NULL;
67 }
68 
69 void Application::init(int &argc, char **argv)
70 {
71  assert(staticInstance == NULL && "Cannot initialize Application twice!");
72  staticInstance = new Application(argc, argv);
73 }
74 
75 Application *Application::instance()
76 {
77  assert(staticInstance != NULL);
78  return staticInstance;
79 }
80 
82 {
83  return d->running;
84 }
85 
87 {
88  return d->mainWindow;
89 }
90 
92 {
93  return d->mainWindow;
94 }
95 
96 void Application::setMainWindow(MainWindow *mainWindow)
97 {
98  d->mainWindow = mainWindow;
99 }
100 
102 {
103  d->running = false;
104 }
void stopRunning()
Makes isRunning() return false.
QWidget * mainWindowAsQWidget() const
Returns MainWindow as a QWidget.
Definition: application.cpp:91
MainWindow * mainWindow() const
MainWindow of the program.
Definition: application.cpp:86
Program central hub of information.
Definition: application.h:44
static void deinit()
Deinitializes the program; executed when program is shutting down.
Definition: application.cpp:51
bool isRunning() const
Plugins and other threads can use this to figure out if program is closing.
Definition: application.cpp:81