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 "KwDatabaseSetup.h"
31 #include <KCmdLineArgs>
34 * Static singleton data
37 /// Singleton application.
38 KwApplication
* KwApplication::s_self
= 0;
44 /// Get the singleton application object.
45 KwApplication
* KwApplication::self()
51 * Constructors + destructor
54 /// Primary constructor.
55 KwApplication::KwApplication()
57 , m_mainWindow(0) // soon to be initialised
58 , m_pluginManager(new KwPluginManager())
61 // Application must be lone.
62 Q_ASSERT(0 == s_self
);
66 KwDatabaseSetup dbSetup
;
67 bool databaseOk
= dbSetup
.initialiseFromConfig();
70 m_database
= dbSetup
.database();
73 // Set up the main window
74 kworship
*widget
= new kworship
;
75 m_mainWindow
= widget
;
77 // Set up the plugin manager
78 m_pluginManager
->setMainWindow(m_mainWindow
);
79 m_pluginManager
->loadPlugins();
81 // see if we are starting with session management
82 if (m_app
.isSessionRestored())
89 // no session.. just start up normally
90 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
91 if (args
->count() > 0)
93 KUrl arg
= args
->arg(0);
94 KUrl url
= KCmdLineArgs::cwd();
97 url
.addPath(arg
.path());
103 widget
->loadPlaylist(url
);
110 KwApplication::~KwApplication()
112 Q_ASSERT(this == s_self
);
115 delete m_pluginManager
;
122 /// Execute the application.
123 int KwApplication::exec()
132 /// Get the main window widget.
133 kworship
* KwApplication::mainWindow()
138 /// Get the plugin manager.
139 KwPluginManager
* KwApplication::pluginManager()
141 return m_pluginManager
;
144 /// Get the database object.
145 QSqlDatabase
& KwApplication::database()