Turn songdb into a plugin, lots of tweaks, drag'n'drop of songs temporarily broken
[kworship.git] / kworship / KwApplication.cpp
blob28ed93f28ca97f1cde44a2084f1d0603651ffd96
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 /**
21 * @file KwApplication.cpp
22 * @brief Application global data.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwApplication.h"
27 #include "kworship.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;
41 * Singletonhood
44 /// Get the singleton application object.
45 KwApplication* KwApplication::self()
47 return s_self;
51 * Constructors + destructor
54 /// Primary constructor.
55 KwApplication::KwApplication()
56 : m_app()
57 , m_mainWindow(0) // soon to be initialised
58 , m_pluginManager(new KwPluginManager())
59 , m_database()
61 // Application must be lone.
62 Q_ASSERT(0 == s_self);
63 s_self = this;
65 // Setup database
66 KwDatabaseSetup dbSetup;
67 bool databaseOk = dbSetup.initialiseFromConfig();
68 if (databaseOk)
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())
84 RESTORE(kworship);
86 else
88 widget->show();
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();
95 if (arg.isRelative())
97 url.addPath(arg.path());
99 else
101 url = arg;
103 widget->loadPlaylist(url);
105 args->clear();
109 /// Destructor.
110 KwApplication::~KwApplication()
112 Q_ASSERT(this == s_self);
113 s_self = 0;
115 delete m_pluginManager;
119 * Main interface
122 /// Execute the application.
123 int KwApplication::exec()
125 return m_app.exec();
129 * Accessors
132 /// Get the main window widget.
133 kworship* KwApplication::mainWindow()
135 return m_mainWindow;
138 /// Get the plugin manager.
139 KwPluginManager* KwApplication::pluginManager()
141 return m_pluginManager;
144 /// Get the database object.
145 QSqlDatabase& KwApplication::database()
147 return m_database;