Basic openoffice.org control, and listening for new presentation documents, still...
[kworship.git] / kworship / KwApplication.cpp
blob3e3aef5934f7a8d908f46514dca1d92e82a13595
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 "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;
43 * Singletonhood
46 /// Get the singleton application object.
47 KwApplication* KwApplication::self()
49 return s_self;
53 * Constructors + destructor
56 /// Primary constructor.
57 KwApplication::KwApplication()
58 : m_app()
59 , m_mainWindow(0) // soon to be initialised
60 , m_pluginManager(new KwPluginManager())
61 , m_filterManager(new KwFilterManager())
62 , m_database()
64 // Application must be lone.
65 Q_ASSERT(0 == s_self);
66 s_self = this;
68 // Setup database
69 KwDatabaseSetup dbSetup;
70 bool databaseOk = dbSetup.initialiseFromConfig();
71 if (databaseOk)
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())
90 RESTORE(kworship);
92 else
94 widget->show();
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());
105 else
107 url = arg;
109 widget->loadPlaylist(url);
111 args->clear();
115 /// Destructor.
116 KwApplication::~KwApplication()
118 Q_ASSERT(this == s_self);
119 s_self = 0;
121 delete m_pluginManager;
122 delete m_filterManager;
126 * Main interface
129 /// Execute the application.
130 int KwApplication::exec()
132 return m_app.exec();
136 * Accessors
139 /// Get the main window widget.
140 kworship* KwApplication::mainWindow()
142 return m_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()
160 return m_database;