From c76c7595c4281100823a18be1f200228ad8f1d51 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Sun, 16 Nov 2008 17:38:08 +0000 Subject: [PATCH] Restructured main with new KwApplication and plugin manager to use it that way plugin manager doesn't have to pass around pointers to the main window which isn't really main enough bible plugin can now add a bible item to the playlist, but it doesn't do anything --- kworship/CMakeLists.txt | 3 +- kworship/{main.cpp => KwApplication.cpp} | 101 +++++++++++++++------ kworship/{KwPluginManager.h => KwApplication.h} | 73 +++++++++------ kworship/KwBiblePlugin.cpp | 13 ++- kworship/KwBiblePlugin.h | 2 +- kworship/KwPlugin.cpp | 4 +- kworship/KwPlugin.h | 5 +- kworship/KwPluginManager.cpp | 9 +- kworship/KwPluginManager.h | 7 +- kworship/bible/CMakeLists.txt | 2 + .../KwBiblePlaylistItem.cpp} | 57 +++++++----- .../KwBiblePlaylistItem.h} | 43 +++++---- .../KwBiblePlaylistItemNode.cpp} | 49 ++++++++++ .../KwBiblePlaylistItemNode.h} | 46 ++++++++++ kworship/kworship.cpp | 30 ++++-- kworship/kworship.h | 17 +++- kworship/main.cpp | 33 +------ kworship/playlist/CMakeLists.txt | 4 +- kworship/playlist/KwPlaylistModel.cpp | 29 ++++-- kworship/playlist/KwPlaylistModel.h | 9 ++ 20 files changed, 368 insertions(+), 168 deletions(-) copy kworship/{main.cpp => KwApplication.cpp} (61%) copy kworship/{KwPluginManager.h => KwApplication.h} (63%) copy kworship/{KwPluginManager.cpp => bible/KwBiblePlaylistItem.cpp} (60%) copy kworship/{playlist/KwPlaylistModel.h => bible/KwBiblePlaylistItem.h} (65%) rename kworship/{playlist/KwPlaylistReading.h => bible/KwBiblePlaylistItemNode.cpp} (62%) rename kworship/{playlist/KwPlaylistReading.cpp => bible/KwBiblePlaylistItemNode.h} (62%) diff --git a/kworship/CMakeLists.txt b/kworship/CMakeLists.txt index 7d31098..20a649d 100644 --- a/kworship/CMakeLists.txt +++ b/kworship/CMakeLists.txt @@ -29,8 +29,9 @@ add_subdirectory (playlist) add_subdirectory (archive) set(kworship_SRCS - kworship.cpp main.cpp + KwApplication.cpp + kworship.cpp kworshipview.cpp prefsDisplay.cpp prefsSongDB.cpp diff --git a/kworship/main.cpp b/kworship/KwApplication.cpp similarity index 61% copy from kworship/main.cpp copy to kworship/KwApplication.cpp index 30cfca3..4b7c2d1 100644 --- a/kworship/main.cpp +++ b/kworship/KwApplication.cpp @@ -17,40 +17,59 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +/** + * @file KwApplication.cpp + * @brief Application global data. + * @author James Hogan + */ + +#include "KwApplication.h" #include "kworship.h" +#include "KwPluginManager.h" +#include "KwBiblePlugin.h" + +#include + +/* + * Static singleton data + */ -#include -#include -#include -#include -#include +/// Singleton application. +KwApplication* KwApplication::s_self = 0; -int main(int argc, char **argv) +/* + * Singletonhood + */ + +/// Get the singleton application object. +KwApplication* KwApplication::self() { - KAboutData about("kworship", 0, - ki18n("KWorship"), "0.1", - ki18n("Free/Open source church worship & presentation software"), - KAboutData::License_GPL_V2, - ki18n("(C) 2008 James Hogan"), - KLocalizedString(), - "http://kworship.org", - "bugs@kworship.org"); - about.addAuthor( ki18n("James Hogan"), KLocalizedString(), "james@albanarts.com" ); - KCmdLineArgs::init(argc, argv, &about); - - KCmdLineOptions options; - options.add("+[URL]", ki18n( "Document to open" )); - KCmdLineArgs::addCmdLineOptions(options); - KApplication app; - - // Screen number can be managed by a DesktopView widget - KConfigDialogManager::changedMap()->insert("DesktopView", SIGNAL(screenChanged(int))); - KConfigDialogManager::propertyMap()->insert("DesktopView", "selectedScreen"); + return s_self; +} + +/* + * Constructors + destructor + */ +/// Primary constructor. +KwApplication::KwApplication() +: m_app() +, m_mainWindow(0) // soon to be initialised +, m_pluginManager(new KwPluginManager()) +{ + // Application must be lone. + Q_ASSERT(0 == s_self); + s_self = this; + + // Set up the main window kworship *widget = new kworship; + m_mainWindow = widget; + + // Set up the plugin manager + m_pluginManager->loadPlugin(new KwBiblePlugin()); // see if we are starting with session management - if (app.isSessionRestored()) + if (m_app.isSessionRestored()) { RESTORE(kworship); } @@ -75,6 +94,34 @@ int main(int argc, char **argv) } args->clear(); } +} - return app.exec(); +/// Destructor. +KwApplication::~KwApplication() +{ + Q_ASSERT(this == s_self); + s_self = 0; + + delete m_pluginManager; +} + +/* + * Main interface + */ + +/// Execute the application. +int KwApplication::exec() +{ + return m_app.exec(); } + +/* + * Accessors + */ + +/// Get the main window widget. +kworship* KwApplication::mainWindow() +{ + return m_mainWindow; +} + diff --git a/kworship/KwPluginManager.h b/kworship/KwApplication.h similarity index 63% copy from kworship/KwPluginManager.h copy to kworship/KwApplication.h index 257be1f..cd33acf 100644 --- a/kworship/KwPluginManager.h +++ b/kworship/KwApplication.h @@ -17,64 +17,81 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _KwPluginManager_h_ -#define _KwPluginManager_h_ +#ifndef _KwApplication_h_ +#define _KwApplication_h_ /** - * @file KwPluginManager.h - * @brief Manages KWorship plugins. + * @file KwApplication.h + * @brief Application global data. * @author James Hogan */ -#include -#include -#include +#include -class KwPlugin; +class KwPluginManager; +class kworship; -class QMainWindow; - -/** Manages KWorship plugins. - * @todo Dynamic loading/unloading of plugins. - */ -class KwPluginManager : public QObject +/// Application global data. +class KwApplication { - Q_OBJECT - public: /* + * Singletonhood + */ + + /// Get the singleton application object. + static KwApplication* self(); + + /* * Constructors + destructor */ /// Primary constructor. - KwPluginManager(QMainWindow* mainWindow); + KwApplication(); /// Destructor. - virtual ~KwPluginManager(); + virtual ~KwApplication(); /* - * Plugin loading and unloading + * Main interface */ - /** Directly load a plugin. - * @param plugin The plugin object. - * @returns True on success, false otherwise. + /// Execute the application. + int exec(); + + /* + * Accessors */ - bool loadPlugin(KwPlugin* plugin); + + /// Get the main window widget. + kworship* mainWindow(); + + /// Get the plugin manager. + KwPluginManager* pluginManager(); private: /* + * Static singleton data + */ + + /// Singleton application. + static KwApplication* s_self; + + /* * Variables */ - /// Main window. - QMainWindow* m_mainWindow; + /// KApplication object. + KApplication m_app; + + /// Main window widget. + kworship* m_mainWindow; - /// Plugins by id. - QMap m_plugins; + /// Plugin manager. + KwPluginManager* m_pluginManager; }; -#endif // _KwPluginManager_h_ +#endif // _KwApplication_h_ diff --git a/kworship/KwBiblePlugin.cpp b/kworship/KwBiblePlugin.cpp index ab5dc8a..22898c1 100644 --- a/kworship/KwBiblePlugin.cpp +++ b/kworship/KwBiblePlugin.cpp @@ -24,11 +24,17 @@ */ #include "KwBiblePlugin.h" +#include "KwApplication.h" +#include "kworship.h" +#include "KwDocument.h" #include #include #include #include +#include + +#include #include #include @@ -251,6 +257,9 @@ void KwBiblePlugin::slotVerseRange() /// Fired by the insert into playlist action. void KwBiblePlugin::slotInsertIntoPlaylist() { + KwBiblePlaylistItem* item = new KwBiblePlaylistItem(); + KwPlaylistModel* model = KwApplication::self()->mainWindow()->playlistModel(); + model->addItem(QModelIndex(), item); } /// Fired by the show now action. @@ -262,7 +271,7 @@ void KwBiblePlugin::slotShowNow() * Loading and unloading virtual interface */ -void KwBiblePlugin::_load(QMainWindow* mainWindow) +void KwBiblePlugin::_load() { // Construct the bible managers. QList managers; @@ -382,7 +391,7 @@ void KwBiblePlugin::_load(QMainWindow* mainWindow) connect(m_editRange, SIGNAL(textChanged(const QString&)), this, SLOT(slotVerseRange())); - mainWindow->addDockWidget(Qt::LeftDockWidgetArea, m_docker); + KwApplication::self()->mainWindow()->addDockWidget(Qt::LeftDockWidgetArea, m_docker); slotBibleChanged(); } diff --git a/kworship/KwBiblePlugin.h b/kworship/KwBiblePlugin.h index 2d41c9f..0590c21 100644 --- a/kworship/KwBiblePlugin.h +++ b/kworship/KwBiblePlugin.h @@ -87,7 +87,7 @@ class KwBiblePlugin : public KwPlugin */ // Reimplemented - virtual void _load(QMainWindow* mainWindow); + virtual void _load(); // Reimplemented virtual void _unload(); diff --git a/kworship/KwPlugin.cpp b/kworship/KwPlugin.cpp index 52ec59d..50d1ea4 100644 --- a/kworship/KwPlugin.cpp +++ b/kworship/KwPlugin.cpp @@ -85,11 +85,11 @@ void KwPlugin::setManager(KwPluginManager* manager) } /// Load the plugin. -void KwPlugin::load(QMainWindow* mainWindow) +void KwPlugin::load() { if (!m_loaded) { - _load(mainWindow); + _load(); } } diff --git a/kworship/KwPlugin.h b/kworship/KwPlugin.h index ed6bc2f..f5f91df 100644 --- a/kworship/KwPlugin.h +++ b/kworship/KwPlugin.h @@ -31,7 +31,6 @@ class KwPluginManager; -class QMainWindow; class QDockWidget; /// An abstract KWorship plugin. @@ -85,7 +84,7 @@ class KwPlugin : public QObject /** Load the plugin. * @pre Manager must have been set. */ - void load(QMainWindow* mainWindow); + void load(); /// Unload the plugin. void unload(); @@ -99,7 +98,7 @@ class KwPlugin : public QObject /** Load the plugin. * @pre !isLoaded() */ - virtual void _load(QMainWindow* mainWindow) = 0; + virtual void _load() = 0; /** Unload the plugin. * @pre isLoaded() diff --git a/kworship/KwPluginManager.cpp b/kworship/KwPluginManager.cpp index 7114305..7918544 100644 --- a/kworship/KwPluginManager.cpp +++ b/kworship/KwPluginManager.cpp @@ -26,16 +26,13 @@ #include "KwPluginManager.h" #include "KwPlugin.h" -#include - /* * Constructors + destructor */ /// Primary constructor. -KwPluginManager::KwPluginManager(QMainWindow* mainWindow) -: m_mainWindow(mainWindow) -, m_plugins() +KwPluginManager::KwPluginManager() +: m_plugins() { } @@ -56,7 +53,7 @@ bool KwPluginManager::loadPlugin(KwPlugin* plugin) if (!m_plugins.contains(id)) { m_plugins[id] = plugin; - plugin->load(m_mainWindow); + plugin->load(); return true; } return false; diff --git a/kworship/KwPluginManager.h b/kworship/KwPluginManager.h index 257be1f..f466b1e 100644 --- a/kworship/KwPluginManager.h +++ b/kworship/KwPluginManager.h @@ -32,8 +32,6 @@ class KwPlugin; -class QMainWindow; - /** Manages KWorship plugins. * @todo Dynamic loading/unloading of plugins. */ @@ -48,7 +46,7 @@ class KwPluginManager : public QObject */ /// Primary constructor. - KwPluginManager(QMainWindow* mainWindow); + KwPluginManager(); /// Destructor. virtual ~KwPluginManager(); @@ -69,9 +67,6 @@ class KwPluginManager : public QObject * Variables */ - /// Main window. - QMainWindow* m_mainWindow; - /// Plugins by id. QMap m_plugins; }; diff --git a/kworship/bible/CMakeLists.txt b/kworship/bible/CMakeLists.txt index 08c95fc..ecdf214 100644 --- a/kworship/bible/CMakeLists.txt +++ b/kworship/bible/CMakeLists.txt @@ -7,6 +7,8 @@ find_package(Sword REQUIRED) set(kworshipbible_SRCS KwBibleManager.cpp KwBibleModule.cpp + KwBiblePlaylistItem.cpp + KwBiblePlaylistItemNode.cpp # SWORD KwBibleManagerSword.cpp KwBibleModuleSword.cpp diff --git a/kworship/KwPluginManager.cpp b/kworship/bible/KwBiblePlaylistItem.cpp similarity index 60% copy from kworship/KwPluginManager.cpp copy to kworship/bible/KwBiblePlaylistItem.cpp index 7114305..47e3789 100644 --- a/kworship/KwPluginManager.cpp +++ b/kworship/bible/KwBiblePlaylistItem.cpp @@ -18,47 +18,58 @@ ***************************************************************************/ /** - * @file KwPluginManager.cpp - * @brief Manages KWorship plugins. + * @file KwBiblePlaylistItem.cpp + * @brief A playlist item for bible passages. * @author James Hogan */ -#include "KwPluginManager.h" -#include "KwPlugin.h" +#include "KwBiblePlaylistItem.h" +#include "KwBiblePlaylistItemNode.h" -#include +KW_REGISTER_PLAYLIST_ITEM(KwBiblePlaylistItem, "bible") /* - * Constructors + destructor + * Constructors + destructor. */ -/// Primary constructor. -KwPluginManager::KwPluginManager(QMainWindow* mainWindow) -: m_mainWindow(mainWindow) -, m_plugins() +/// Default constructor. +KwBiblePlaylistItem::KwBiblePlaylistItem() +: KwPlaylistItem() { } +/// Construct from a DOM element. +KwBiblePlaylistItem::KwBiblePlaylistItem(const QDomElement& element, KwResourceManager* resourceManager) +: KwPlaylistItem() +{ + /// @todo Implement bible passage import. +} + /// Destructor. -KwPluginManager::~KwPluginManager() +KwBiblePlaylistItem::~KwBiblePlaylistItem() +{ +} + +/* + * DOM Translation. + */ + +QString KwBiblePlaylistItem::itemType() const +{ + return "bible"; +} + +void KwBiblePlaylistItem::exportDetailsToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const { + /// @todo Implement bible passage export. } /* - * Plugin loading and unloading + * Main interface */ -/// Directly load a plugin. -bool KwPluginManager::loadPlugin(KwPlugin* plugin) +KwPlaylistNode* KwBiblePlaylistItem::getNode(KwPlaylistNode* parent) { - const QString& id = plugin->id(); - Q_ASSERT(!plugin->isLoaded()); - if (!m_plugins.contains(id)) - { - m_plugins[id] = plugin; - plugin->load(m_mainWindow); - return true; - } - return false; + return new KwBiblePlaylistItemNode(parent, this); } diff --git a/kworship/playlist/KwPlaylistModel.h b/kworship/bible/KwBiblePlaylistItem.h similarity index 65% copy from kworship/playlist/KwPlaylistModel.h copy to kworship/bible/KwBiblePlaylistItem.h index c269c19..adba549 100644 --- a/kworship/playlist/KwPlaylistModel.h +++ b/kworship/bible/KwBiblePlaylistItem.h @@ -17,22 +17,22 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _KwPlaylistModel_h_ -#define _KwPlaylistModel_h_ +#ifndef _KwBiblePlaylistItem_h_ +#define _KwBiblePlaylistItem_h_ /** - * @file KwPlaylistModel.h - * @brief A Qt model for playlist items. + * @file KwBiblePlaylistItem.h + * @brief A playlist item for bible passages. * @author James Hogan */ -#include "KwPlaylistNode.h" +#include -#include "NodeBasedModel.h" - -/// A Qt model for playlist items. -class KwPlaylistModel : public NodeBasedModel +/// A playlist item for bible passages. +class KwBiblePlaylistItem : public KwPlaylistItem { + KW_PLAYLIST_ITEM + public: /* @@ -40,21 +40,30 @@ class KwPlaylistModel : public NodeBasedModel */ /// Default constructor. - KwPlaylistModel(QObject* parent = 0); + KwBiblePlaylistItem(); + + /// Construct from a DOM element. + KwBiblePlaylistItem(const QDomElement& element, KwResourceManager* resourceManager); /// Destructor. - virtual ~KwPlaylistModel(); + virtual ~KwBiblePlaylistItem(); /* - * Drag and drop + * DOM Translation. */ - QStringList mimeTypes() const; - Qt::DropActions supportedDropActions() const; - Qt::ItemFlags flags(const QModelIndex& index) const; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); + // Reimplemented + virtual QString itemType() const; + + // Reimplemented + virtual void exportDetailsToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const; + + /* + * Main interface + */ + virtual KwPlaylistNode* getNode(KwPlaylistNode* parent); }; -#endif // _KwPlaylistModel_h_ +#endif // _KwBiblePlaylistItem_h_ diff --git a/kworship/playlist/KwPlaylistReading.h b/kworship/bible/KwBiblePlaylistItemNode.cpp similarity index 62% rename from kworship/playlist/KwPlaylistReading.h rename to kworship/bible/KwBiblePlaylistItemNode.cpp index 3b2057d..9bfc14e 100644 --- a/kworship/playlist/KwPlaylistReading.h +++ b/kworship/bible/KwBiblePlaylistItemNode.cpp @@ -17,4 +17,53 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +/** + * @file KwBiblePlaylistItemNode.cpp + * @brief A playlist node for a bible passage item. + * @author James Hogan + */ + +#include "KwBiblePlaylistItemNode.h" +#include "KwBiblePlaylistItem.h" + +#include + +/* + * Constructors + destructor. + */ + +/// Primary constructor. +KwBiblePlaylistItemNode::KwBiblePlaylistItemNode(KwPlaylistNode* parent, KwBiblePlaylistItem* item) +: KwPlaylistNode(parent) +, m_item(item) +{ +} + +/// Destructor. +KwBiblePlaylistItemNode::~KwBiblePlaylistItemNode() +{ +} + +/* + * Main interface + */ + +QVariant KwBiblePlaylistItemNode::getData(int role, int column) +{ + if (role == Qt::DisplayRole) + { + if (column == 0) + { + return "Bible Passage"; + } + } + else if (role == Qt::DecorationRole) + { + if (column == 0) + { + return KIcon("bible"); + } + } + return QVariant(); +} diff --git a/kworship/playlist/KwPlaylistReading.cpp b/kworship/bible/KwBiblePlaylistItemNode.h similarity index 62% rename from kworship/playlist/KwPlaylistReading.cpp rename to kworship/bible/KwBiblePlaylistItemNode.h index 3b2057d..ae63bee 100644 --- a/kworship/playlist/KwPlaylistReading.cpp +++ b/kworship/bible/KwBiblePlaylistItemNode.h @@ -17,4 +17,50 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#ifndef _KwBiblePlaylistItemNode_h_ +#define _KwBiblePlaylistItemNode_h_ + +/** + * @file KwBiblePlaylistItemNode.h + * @brief A playlist node for a bible passage item. + * @author James Hogan + */ + +#include "KwPlaylistNode.h" + +class KwBiblePlaylistItem; + +/// A playlist node for a text. +class KwBiblePlaylistItemNode : public KwPlaylistNode +{ + public: + + /* + * Constructors + destructor. + */ + + /// Primary constructor. + KwBiblePlaylistItemNode(KwPlaylistNode* parent, KwBiblePlaylistItem* item); + + /// Destructor. + virtual ~KwBiblePlaylistItemNode(); + + /* + * Main interface + */ + + // Reimplemented + virtual QVariant getData(int role, int column); + + private: + + /* + * Variables + */ + + /// Playlist item. + KwBiblePlaylistItem* m_item; +}; + +#endif // _KwBiblePlaylistItemNode_h_ diff --git a/kworship/kworship.cpp b/kworship/kworship.cpp index 1db5f2b..2d14289 100644 --- a/kworship/kworship.cpp +++ b/kworship/kworship.cpp @@ -43,9 +43,6 @@ #include "KwMediaManager.h" #include "KwMediaControlWidget.h" -#include "KwPluginManager.h" -#include "KwBiblePlugin.h" - #include "KwSongdb.h" #include "KwSongdbModel.h" #include "KwSongdbFilterNode.h" @@ -93,7 +90,6 @@ kworship::kworship() , m_view(new kworshipView(this)) , m_displayManager(0) , m_document(0) -, m_plugins(new KwPluginManager(this)) , m_presentationManager(new UpManager(this)) , m_currentPresentation(0) , m_printer(0) @@ -101,9 +97,6 @@ kworship::kworship() m_playlistModel = new KwPlaylistModel; setDocument(); - // Load plugins - m_plugins->loadPlugin(new KwBiblePlugin()); - // set up presentation backends m_presentationManager->registerBackend(); m_presentationManager->registerBackend(); @@ -336,7 +329,6 @@ kworship::~kworship() { delete KwSongdb::self(); delete m_slideNotes; - delete m_plugins; } /* @@ -350,6 +342,28 @@ void kworship::loadPlaylist(const KUrl& url) m_document->reload(); } +/* + * Accessors + */ + +/// Get the main display manager. +KwDisplayManager* kworship::displayManager() +{ + return m_displayManager; +} + +/// Get the current document. +KwDocument* kworship::document() +{ + return m_document; +} + +/// Get the playlist model. +KwPlaylistModel* kworship::playlistModel() +{ + return m_playlistModel; +} + void kworship::setupActions() { // Application diff --git a/kworship/kworship.h b/kworship/kworship.h index 236e3c3..62be6b3 100644 --- a/kworship/kworship.h +++ b/kworship/kworship.h @@ -38,7 +38,6 @@ class KwPlaylistList; class KwPlaylistModel; class KwMediaManager; class KwDocument; -class KwPluginManager; class KwSongdbModel; class KwSongdbTree; @@ -84,6 +83,19 @@ public: /// Load a specified playlist. void loadPlaylist(const KUrl& url); + /* + * Accessors + */ + + /// Get the main display manager. + KwDisplayManager* displayManager(); + + /// Get the current document. + KwDocument* document(); + + /// Get the playlist model. + KwPlaylistModel* playlistModel(); + private slots: void settingsChanged(); void toggleMainDisplay(bool checked); @@ -157,9 +169,6 @@ private: KwDocument* m_document; KwPlaylistModel* m_playlistModel; - // Plugins - KwPluginManager* m_plugins; - KwSongdbModel* m_songDbModel; KwSongdbTree* m_songDbTree; KAction* m_unlockSongDbAction; diff --git a/kworship/main.cpp b/kworship/main.cpp index 30cfca3..6bf3762 100644 --- a/kworship/main.cpp +++ b/kworship/main.cpp @@ -17,9 +17,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include "kworship.h" +#include "KwApplication.h" -#include #include #include #include @@ -41,40 +40,12 @@ int main(int argc, char **argv) KCmdLineOptions options; options.add("+[URL]", ki18n( "Document to open" )); KCmdLineArgs::addCmdLineOptions(options); - KApplication app; // Screen number can be managed by a DesktopView widget KConfigDialogManager::changedMap()->insert("DesktopView", SIGNAL(screenChanged(int))); KConfigDialogManager::propertyMap()->insert("DesktopView", "selectedScreen"); - kworship *widget = new kworship; - - // see if we are starting with session management - if (app.isSessionRestored()) - { - RESTORE(kworship); - } - else - { - widget->show(); - // no session.. just start up normally - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - if (args->count() > 0) - { - KUrl arg = args->arg(0); - KUrl url = KCmdLineArgs::cwd(); - if (arg.isRelative()) - { - url.addPath(arg.path()); - } - else - { - url = arg; - } - widget->loadPlaylist(url); - } - args->clear(); - } + KwApplication app; return app.exec(); } diff --git a/kworship/playlist/CMakeLists.txt b/kworship/playlist/CMakeLists.txt index 719d236..2d48dd7 100644 --- a/kworship/playlist/CMakeLists.txt +++ b/kworship/playlist/CMakeLists.txt @@ -21,7 +21,6 @@ set(kworshipplaylist_SRCS KwPlaylistNote.cpp KwPlaylistNoteNode.cpp KwPlaylistPresentation.cpp - KwPlaylistReading.cpp KwPlaylistSong.cpp KwPlaylistSongNode.cpp KwPlaylistSongNodeVerse.cpp @@ -31,3 +30,6 @@ set(kworshipplaylist_SRCS kde4_add_library(kworshipplaylist ${kworshipplaylist_SRCS}) +target_link_libraries(kworshipplaylist + kworshiparchive +) diff --git a/kworship/playlist/KwPlaylistModel.cpp b/kworship/playlist/KwPlaylistModel.cpp index 4caeb4d..a2da5f2 100644 --- a/kworship/playlist/KwPlaylistModel.cpp +++ b/kworship/playlist/KwPlaylistModel.cpp @@ -55,6 +55,25 @@ KwPlaylistModel::~KwPlaylistModel() } /* + * Modification interface + */ + +/// Add an item to the list. +void KwPlaylistModel::addItem(const QModelIndex& parent, KwPlaylistItem* item, int position) +{ + KwPlaylistListNode* list = dynamic_cast(itemFromIndex(parent)); + Q_ASSERT(0 != list); + if (position == -1) + { + position = list->getChildCount(); + } + beginInsertRows(parent, position, position); + list->childrenAdded(position, position); + list->getItem()->addItem(item, position); + endInsertRows(); +} + +/* * Drag and drop */ @@ -125,10 +144,7 @@ bool KwPlaylistModel::dropMimeData(const QMimeData* data, Qt::DropAction action, if (ok) { KwPlaylistSong* newSong = new KwPlaylistSong(KwSongdb::self()->songVersionById(versionId)); - beginInsertRows(parent, row, row); - list->childrenAdded(row, row); - list->getItem()->addItem(newSong, row); - endInsertRows(); + addItem(parent, newSong, row); ++row; } } @@ -166,10 +182,7 @@ bool KwPlaylistModel::dropMimeData(const QMimeData* data, Qt::DropAction action, { newItem = new KwPlaylistFile(file); } - beginInsertRows(parent, row, row); - list->childrenAdded(row, row); - list->getItem()->addItem(newItem, row); - endInsertRows(); + addItem(parent, newItem, row); ++row; } diff --git a/kworship/playlist/KwPlaylistModel.h b/kworship/playlist/KwPlaylistModel.h index c269c19..e389c88 100644 --- a/kworship/playlist/KwPlaylistModel.h +++ b/kworship/playlist/KwPlaylistModel.h @@ -30,6 +30,8 @@ #include "NodeBasedModel.h" +class KwPlaylistItem; + /// A Qt model for playlist items. class KwPlaylistModel : public NodeBasedModel { @@ -46,6 +48,13 @@ class KwPlaylistModel : public NodeBasedModel virtual ~KwPlaylistModel(); /* + * Modification interface + */ + + /// Add an item to the list. + void addItem(const QModelIndex& parent, KwPlaylistItem* item, int position = -1); + + /* * Drag and drop */ -- 2.11.4.GIT