1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship 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. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwApplication.cpp
22 * @brief Application global data.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwApplication.h"
28 #include "KwPluginManager.h"
29 #include "KwFilterManager.h"
30 #include "KwKWorshipFilter.h"
31 #include "KwDatabaseSetup.h"
33 #include <KCmdLineArgs>
36 * Static singleton data
39 /// Singleton application.
40 KwApplication
* KwApplication::s_self
= 0;
46 /// Get the singleton application object.
47 KwApplication
* KwApplication::self()
53 * Constructors + destructor
56 /// Primary constructor.
57 KwApplication::KwApplication()
59 , m_mainWindow(0) // soon to be initialised
60 , m_pluginManager(new KwPluginManager())
61 , m_filterManager(new KwFilterManager())
64 // Application must be lone.
65 Q_ASSERT(0 == s_self
);
69 KwDatabaseSetup dbSetup
;
70 bool databaseOk
= dbSetup
.initialiseFromConfig();
73 m_database
= dbSetup
.database();
76 // Set the default load save filter
77 m_filterManager
->addLoadSaveFilter(new KwKWorshipFilter(), true);
79 // Set up the main window
80 kworship
*widget
= new kworship
;
81 m_mainWindow
= widget
;
83 // Set up the plugin manager
84 m_pluginManager
->setMainWindow(m_mainWindow
);
85 m_pluginManager
->loadPlugins();
87 // see if we are starting with session management
88 if (m_app
.isSessionRestored())
95 // no session.. just start up normally
96 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
97 if (args
->count() > 0)
99 KUrl arg
= args
->arg(0);
100 KUrl url
= KCmdLineArgs::cwd();
101 if (arg
.isRelative())
103 url
.addPath(arg
.path());
109 widget
->loadPlaylist(url
);
116 KwApplication::~KwApplication()
118 Q_ASSERT(this == s_self
);
121 delete m_pluginManager
;
122 delete m_filterManager
;
129 /// Execute the application.
130 int KwApplication::exec()
139 /// Get the main window widget.
140 kworship
* KwApplication::mainWindow()
145 /// Get the plugin manager.
146 KwPluginManager
* KwApplication::pluginManager()
148 return m_pluginManager
;
151 /// Get the filter manager.
152 KwFilterManager
* KwApplication::filterManager()
154 return m_filterManager
;
157 /// Get the database object.
158 QSqlDatabase
& KwApplication::database()