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 KwSongdbPlugin.cpp
22 * @brief Song database plugin.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwSongdbPlugin.h"
27 #include "KwSongdbTree.h"
29 #include "KwSongdbSongEditDialog.h"
30 #include "KwSongdbSong.h"
31 #include "KwSongdbSongBooksEditWidget.h"
32 #include <KwApplication.h>
36 #include <KActionMenu>
37 #include <KActionCollection>
38 #include <KGenericFactory>
40 #include <KMessageBox>
43 #include <QDockWidget>
44 #include <QVBoxLayout>
47 K_EXPORT_COMPONENT_FACTORY( kworship_songdb
, KGenericFactory
<KwSongdbPlugin
>("kworship_songdb") )
50 * Constructors + destructor
53 /// Default constructor.
54 KwSongdbPlugin::KwSongdbPlugin(QObject
* parent
, const QStringList
& params
)
55 : KwPlugin(parent
, "songdb",
57 i18n("The song database plugin allows for the management and display of song lyrics."))
59 , m_unlockSongDbAction(0)
60 , m_lockSongDbAction(0)
61 , m_groupSongsByAction(0)
64 , m_editSongBooksAction(0)
66 setXMLFile("songdb/kworship_songdbui.rc");
70 m_unlockSongDbAction
= new KAction(KIcon("document-decrypt"), i18n("Unlock Song Database"), this);
71 actionCollection()->addAction( QLatin1String("unlock_song_database"), m_unlockSongDbAction
);
72 connect(m_unlockSongDbAction
, SIGNAL(triggered(bool)), this, SLOT(songdbUnlock()));
74 m_lockSongDbAction
= new KAction(KIcon("document-encrypt"), i18n("Lock Song Database"), this);
75 m_lockSongDbAction
->setVisible(false);
76 actionCollection()->addAction( QLatin1String("lock_song_database"), m_lockSongDbAction
);
77 connect(m_lockSongDbAction
, SIGNAL(triggered(bool)), this, SLOT(songdbLock()));
79 m_groupSongsByAction
= new KActionMenu(KIcon("view-filter"), i18n("Group By"), this);
80 m_groupSongsByAction
->setDelayed(false);
81 actionCollection()->addAction( QLatin1String("group_songs_by"), m_groupSongsByAction
);
83 m_addSongAction
= new KAction(KIcon("list-add"), i18n("Add Song"), this);
84 actionCollection()->addAction( QLatin1String("add_song"), m_addSongAction
);
85 connect(m_addSongAction
, SIGNAL(triggered(bool)), this, SLOT(songdbAdd()));
87 m_editSongAction
= new KAction(KIcon("view-media-lyrics"), i18n("Edit Song"), this);
88 actionCollection()->addAction( QLatin1String("edit_song"), m_editSongAction
);
89 connect(m_editSongAction
, SIGNAL(triggered(bool)), this, SLOT(songdbEdit()));
91 m_editSongBooksAction
= new KAction(KIcon("format-list-ordered"), i18n("Edit Song Books"), this);
92 actionCollection()->addAction( QLatin1String("edit_song_books"), m_editSongBooksAction
);
93 connect(m_editSongBooksAction
, SIGNAL(triggered(bool)), this, SLOT(songdbEditSongBooks()));
96 m_docker
= new QDockWidget(i18n("Song DB"));
97 m_docker
->setObjectName("dockSongdb");
98 QWidget
* mainDockWidget
= new QWidget(/*m_docker*/);
99 QVBoxLayout
* dockLayout
= new QVBoxLayout(mainDockWidget
);
100 m_docker
->setWidget(mainDockWidget
);
102 // Ensure database is connected
103 KwApplication
* app
= KwApplication::self();
104 if (app
->database().isOpen())
106 new KwSongdb(app
->database());
109 QWidget
* toolbarWidget
= new QWidget(mainDockWidget
);
110 dockLayout
->addWidget(toolbarWidget
);
111 QHBoxLayout
* toolbarLayout
= new QHBoxLayout(toolbarWidget
);
113 // Small toolbar for group by action
114 QToolBar
* songTextToolBar
= new QToolBar("Songs");
115 songTextToolBar
->setToolButtonStyle(Qt::ToolButtonTextBesideIcon
);
116 songTextToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
117 toolbarLayout
->addWidget(songTextToolBar
);
119 songTextToolBar
->addAction(m_groupSongsByAction
);
121 // Rest of the toolbar
122 QToolBar
* songToolBar
= new QToolBar("Songs");
123 songToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
124 toolbarLayout
->addWidget(songToolBar
);
126 songToolBar
->addAction(m_addSongAction
);
127 songToolBar
->addAction(m_editSongAction
);
128 songToolBar
->addAction(m_editSongBooksAction
);
129 KAction
* insertIntoPlaylistAction
= new KAction(KIcon("player_playlist"), i18n("Insert Into Playlist"), songToolBar
);
130 songToolBar
->addAction(insertIntoPlaylistAction
);
132 KMenu
* groupByMenu
= new KMenu(songToolBar
);
133 m_groupSongsByAction
->setMenu(groupByMenu
);
135 m_songDbTree
= new KwSongdbTree(mainDockWidget
);
136 dockLayout
->addWidget(m_songDbTree
);
137 groupByMenu
->addActions(m_songDbTree
->groupByActions()->actions());
141 QLabel
* labelNoDb
= new QLabel(i18n("Song database not connected: %1", app
->database().lastError().text()), mainDockWidget
);
142 dockLayout
->addWidget(labelNoDb
);
145 app
->mainWindow()->addDockWidget(Qt::LeftDockWidgetArea
, m_docker
);
149 KwSongdbPlugin::~KwSongdbPlugin()
151 delete KwSongdb::self();
158 void KwSongdbPlugin::songdbUnlock()
160 m_unlockSongDbAction
->setVisible(false);
161 m_lockSongDbAction
->setVisible(true);
164 void KwSongdbPlugin::songdbLock()
166 m_unlockSongDbAction
->setVisible(true);
167 m_lockSongDbAction
->setVisible(false);
170 void KwSongdbPlugin::songdbAdd()
172 KwSongdbSongEditDialog
* dialog
= new KwSongdbSongEditDialog(0);
173 dialog
->setCaption(i18n("Add Song"));
174 dialog
->setAttribute(Qt::WA_DeleteOnClose
, true);
178 void KwSongdbPlugin::songdbEdit()
180 /// @todo Ensure the same song isn't open twice
181 KwSongdbSong
* song
= m_songDbTree
->currentSong();
184 KwSongdbVersion
* version
= m_songDbTree
->currentSongVersion();
186 KwSongdbSongEditDialog
* dialog
= new KwSongdbSongEditDialog(song
, version
);
187 dialog
->setCaption(i18n("Edit Song - %1", song
->name()));
188 dialog
->setAttribute(Qt::WA_DeleteOnClose
, true);
193 KMessageBox::information(KwApplication::self()->mainWindow(), i18n("Please select a song."));
197 void KwSongdbPlugin::songdbEditSongBooks()
199 KwSongdbSongBooksEditWidget::showDialog();
203 * Loading and unloading virtual interface
206 void KwSongdbPlugin::_load()
210 void KwSongdbPlugin::_unload()