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 #include "kworshipview.h"
23 #include "prefsDisplay.h"
24 #include "prefsSongDB.h"
25 #include "KwDatabaseSetup.h"
26 #include "KwDocument.h"
28 #include "KwPlaylistNode.h"
29 #include "KwPlaylistList.h"
30 #include "KwPlaylistNote.h"
31 #include "KwPlaylistText.h"
32 #include "KwPlaylistImage.h"
33 #include "KwPlaylistVideo.h"
34 #include "KwPlaylistModel.h"
36 #include "KwCssStyleSheet.h"
37 #include "KwCssStyleRule.h"
39 #include "KwDisplayManager.h"
40 #include "KwLocalDisplay.h"
41 #include "KwLocalDisplayPreview.h"
43 #include "KwMediaManager.h"
44 #include "KwMediaControlWidget.h"
46 #include <KwBibleManager.h>
47 #include <KwBibleManagerSword.h>
48 #include <KwBibleManagerBibleGateway.h>
49 #include <KwBibleModule.h>
52 #include "KwSongdbModel.h"
53 #include "KwSongdbFilterNode.h"
54 #include "KwSongdbTree.h"
55 #include "KwSongdbSong.h"
56 #include "KwSongdbSongEditDialog.h"
57 #include "KwSongdbSongBooksEditWidget.h"
59 #include "UpManager.h"
60 #include "UpPresentationsModel.h"
61 #include "UpPresentation.h"
62 #include "UpPresentationNode.h"
64 #include "UpKpr1Backend.h"
65 #include "UpKpr2Backend.h"
66 #include "UpOoBackend.h"
68 #include <kconfigdialog.h>
69 #include <kstatusbar.h>
71 #include <kactionmenu.h>
73 #include <ktoggleaction.h>
74 #include <kactioncollection.h>
75 #include <kstandardaction.h>
76 #include <KDE/KLocale>
77 #include <KFileDialog>
78 #include <KMessageBox>
80 #include <phonon/audiooutput.h>
82 #include <QtGui/QDropEvent>
83 #include <QtGui/QPainter>
85 #include <QDesktopWidget>
87 #include <QToolButton>
89 #include <QSqlDatabase>
90 #include <QHeaderView>
95 , m_view(new kworshipView(this))
98 , m_presentationManager(new UpManager(this))
99 , m_currentPresentation(0)
102 m_playlistModel
= new KwPlaylistModel
;
105 // set up presentation backends
106 m_presentationManager
->registerBackend
<UpOoBackend
>();
107 m_presentationManager
->registerBackend
<UpKpr2Backend
>();
108 m_presentationManager
->registerBackend
<UpKpr1Backend
>();
111 m_previewDisplay
= 0;
114 setAcceptDrops(true);
116 // tell the KXmlGuiWindow that this is indeed the main widget
117 setCentralWidget(m_view
);
119 // then, setup our actions
125 // a call to KXmlGuiWindow::setupGUI() populates the GUI
126 // with actions, using KXMLGUI.
127 // It also applies the saved mainwindow settings, if any, and ask the
128 // mainwindow to automatically save settings if changed: window size,
129 // toolbar position, icon size, etc.
133 addDockWidget(Qt::LeftDockWidgetArea
, m_view
->dockPresentation
);
134 tabifyDockWidget(m_view
->dockPresentation
, m_view
->dockBible
);
135 tabifyDockWidget(m_view
->dockPresentation
, m_view
->dockSongs
);
136 addDockWidget(Qt::RightDockWidgetArea
, m_view
->dockPreview
);
137 addDockWidget(Qt::RightDockWidgetArea
, m_view
->dockLyrics
);
138 addDockWidget(Qt::BottomDockWidgetArea
, m_view
->dockThemes
);
139 addDockWidget(Qt::BottomDockWidgetArea
, m_view
->dockNowPlaying
);
141 // Setup some stuff in the tree
143 #define TREE_ITEM(name, string, parent) QTreeWidgetItem* name = new QTreeWidgetItem(parent); name->setText(0, tr(string));
145 TREE_ITEM(song1
, "Our God is a great big God", m_view
->treeWidget
);
146 TREE_ITEM(song1_style
, "(style)", song1
);
147 TREE_ITEM(song1_style_1
, "Mode", song1_style
);
148 TREE_ITEM(song1_v1
, "Our God is a great big God,\nOur God is a great big God,\nOur God is a great big God,\nAnd He holds us in his hands.", song1
);
149 TREE_ITEM(song1_v2
, "He's higher than a skyscraper\nAnd he's deeper than a submarine.", song1
);
150 TREE_ITEM(song1_v3
, "He's wider than the universe\nAnd beyond my wildest dreams.", song1
);
157 KwDatabaseSetup dbSetup
;
158 bool databaseOk
= dbSetup
.initialiseFromConfig();
161 new KwSongdb(dbSetup
.database());
165 m_document
->playlist()->addClass("beachy");
167 KwCssStyleSheet
* styleRules
= new KwCssStyleSheet
;
169 KwCssStyleRule beachyTheme
;
170 beachyTheme
.setCriteriaClasses(QSet
<QString
>() << "beachy");
171 beachyTheme
.setStyle
<QBrush
>("background.brush", Qt::black
);
172 beachyTheme
.setStyle
<QPixmap
>("background.image.pixmap", QPixmap("/home/james/media/images/projector/misc/love-god-light.jpg"));
173 styleRules
->addRule(beachyTheme
);
175 m_document
->playlist()->addStyleSheet(styleRules
);
177 m_view
->treePlaylist
->setModel(m_playlistModel
);
178 m_view
->treePlaylist
->setExpandsOnDoubleClick(false);
179 m_view
->treePlaylist
->setAcceptDrops(true);
181 connect(m_view
->treePlaylist
, SIGNAL(doubleClicked(QModelIndex
)), this, SLOT(playlist_doubleClicked(QModelIndex
)));
183 m_mediaManager
= new KwMediaManager();
184 m_mediaManager
->linkAudio(new Phonon::AudioOutput(Phonon::MusicCategory
));
185 m_displayManager
= new KwDisplayManager(&m_displayController
, m_mediaManager
);
187 m_previewDisplay
= new KwLocalDisplayPreview
;
188 m_view
->layoutPreview
->addWidget(m_previewDisplay
);
189 m_displayController
.attachChild(m_previewDisplay
);
191 KwMediaControlWidget
* mediaWidget
= new KwMediaControlWidget(m_mediaManager
, m_view
->dockNowPlaying
);
192 m_view
->layoutNowPlaying
->addWidget(mediaWidget
);
194 // Small toolbar for group by action
195 QToolBar
* songTextToolBar
= new QToolBar("Songs");
196 songTextToolBar
->setToolButtonStyle(Qt::ToolButtonTextBesideIcon
);
197 songTextToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
198 m_view
->layoutSongsToolbar
->layout()->addWidget(songTextToolBar
);
200 songTextToolBar
->addAction(m_groupSongsByAction
);
202 // Rest of the toolbar
203 QToolBar
* songToolBar
= new QToolBar("Songs");
204 songToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
205 m_view
->layoutSongsToolbar
->layout()->addWidget(songToolBar
);
207 songToolBar
->addAction(m_addSongAction
);
208 songToolBar
->addAction(m_editSongAction
);
209 songToolBar
->addAction(m_editSongBooksAction
);
210 KAction
* insertIntoPlaylistAction
= new KAction(KIcon("player_playlist"), i18n("Insert Into Playlist"), songToolBar
);
211 songToolBar
->addAction(insertIntoPlaylistAction
);
213 KMenu
* groupByMenu
= new KMenu(songToolBar
);
214 m_groupSongsByAction
->setMenu(groupByMenu
);
218 m_songDbTree
= new KwSongdbTree(m_view
);
219 m_view
->layoutSongsTree
->addWidget(m_songDbTree
);
220 groupByMenu
->addActions(m_songDbTree
->groupByActions()->actions());
228 // Drop down list of presentations
229 QComboBox
* selectPresCombo
= m_view
->comboPresentations
;
230 m_selectPresTree
= new QTreeView(this);
231 m_selectPresTree
->header()->hide();
232 selectPresCombo
->setModel(m_presentationManager
->presentationsModel());
233 selectPresCombo
->setView(m_selectPresTree
);
234 presentationComboReset();
235 connect(m_presentationManager
->presentationsModel(), SIGNAL(modelReset()), this, SLOT(presentationComboReset()));
236 connect(selectPresCombo
, SIGNAL(currentIndexChanged(int)), this, SLOT(presentationSelected(int)));
238 // Custom slideshow selector
239 m_view
->slideshows
->setVisible(false);
240 connect(m_view
->comboSlideshows
, SIGNAL(currentIndexChanged(const QString
&)), this, SLOT(changeSlideshowCombo(QString
)));
242 QToolBar
* customSlideshowsToolBar
= new QToolBar(i18n("Custom Slideshows"));
243 customSlideshowsToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
));
244 m_view
->slideshows
->layout()->addWidget(customSlideshowsToolBar
);
245 // Add slideshow to playlist
246 KActionMenu
* addSlideshowToPlaylistAction
= new KActionMenu(KIcon("list-add"), i18n("Add Slideshow to Playlist"), customSlideshowsToolBar
);
247 addSlideshowToPlaylistAction
->setDelayed(false);
248 customSlideshowsToolBar
->addAction(addSlideshowToPlaylistAction
);
250 KAction
* asLinkAction
= new KAction(KIcon("insert-link"), i18n("Add Link to Slideshow into Playlist"), customSlideshowsToolBar
);
251 connect(asLinkAction
, SIGNAL(triggered(bool)), this, SLOT(addSlideshowLinkToPlaylist()));
252 addSlideshowToPlaylistAction
->addAction(asLinkAction
);
255 KAction
* asCopyAction
= new KAction(KIcon("edit-copy"), i18n("Save Copy of Slideshow into Playlist"), customSlideshowsToolBar
);
256 connect(asCopyAction
, SIGNAL(triggered(bool)), this, SLOT(addSlideshowCopyToPlaylist()));
257 addSlideshowToPlaylistAction
->addAction(asCopyAction
);
260 // Presentations toolbar
261 QToolBar
* presToolBar
= new QToolBar("Presentations");
262 m_view
->layoutPresentationsToolbar
->layout()->addWidget(presToolBar
);
264 KActionMenu
* openPresAction
= new KActionMenu(KIcon("document-open"), "Open Presentation", presToolBar
);
265 openPresAction
->setDelayed(true);
266 presToolBar
->addAction(openPresAction
);
268 KAction
* refreshPresAction
= new KAction(KIcon("view-refresh"), "Refresh Presentation List", presToolBar
);
269 presToolBar
->addAction(refreshPresAction
);
271 KAction
* closePresAction
= new KAction(KIcon("fileclose"), "Close Presentation", presToolBar
);
272 presToolBar
->addAction(closePresAction
);
274 KToggleAction
* fullscreenPresAction
= new KToggleAction(KIcon("view-fullscreen"), "Fullscreen Presentation Mode", presToolBar
);
275 presToolBar
->addAction(fullscreenPresAction
);
278 connect(m_view
->listSlides
, SIGNAL(doubleClicked(QModelIndex
)), this, SLOT(slide_doubleClicked(QModelIndex
)));
281 QToolBar
* slidesToolBar
= new QToolBar("Slides");
282 slidesToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
283 slidesToolBar
->setIconSize(QSize(32,32));
284 m_view
->layoutSlidesToolbar
->layout()->addWidget(slidesToolBar
);
286 m_slideshowPrevSlideAction
= new KAction(KIcon("media-skip-backward"), i18n("Previous Slide"), slidesToolBar
);
287 connect(m_slideshowPrevSlideAction
, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousSlide()));
288 slidesToolBar
->addAction(m_slideshowPrevSlideAction
);
290 m_slideshowPrevStepAction
= new KAction(KIcon("media-seek-backward"), i18n("Previous Step"), slidesToolBar
);
291 connect(m_slideshowPrevStepAction
, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousStep()));
292 slidesToolBar
->addAction(m_slideshowPrevStepAction
);
294 m_slideshowNextStepAction
= new KAction(KIcon("media-seek-forward"), i18n("Next Step"), slidesToolBar
);
295 connect(m_slideshowNextStepAction
, SIGNAL(triggered(bool)), this, SLOT(presentationNextStep()));
296 slidesToolBar
->addAction(m_slideshowNextStepAction
);
298 m_slideshowNextSlideAction
= new KAction(KIcon("media-skip-forward"), i18n("Next Slide"), slidesToolBar
);
299 connect(m_slideshowNextSlideAction
, SIGNAL(triggered(bool)), this, SLOT(presentationNextSlide()));
300 slidesToolBar
->addAction(m_slideshowNextSlideAction
);
302 m_slideshowAction
= new KToggleAction(KIcon("view-presentation"), i18n("Start/Stop Slideshow"), slidesToolBar
);
303 connect(m_slideshowAction
, SIGNAL(toggled(bool)), this, SLOT(presentationToggled(bool)));
304 slidesToolBar
->addAction(m_slideshowAction
);
307 m_slideNotes
= new QTextEdit();
308 m_slideNotes
->setReadOnly(true);
309 m_slideNotes
->setWindowTitle(i18n("Slide Notes"));
310 m_slideNotes
->show();
312 // Ensure the controls are as when slideshow is stopped
313 m_slideshowAction
->setEnabled(false);
320 // Show the display on startup?
321 if (Settings::displayShowStartup())
323 // If there's only one screen, don't bother showing display.
324 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
325 assert(0 != desktop
);
326 if (desktop
->numScreens() > 1)
328 toggleMainDisplay(true);
329 m_mainDisplayAction
->setChecked(true);
333 // Fill list of bibles
334 QList
<KwBibleManager
*> managers
;
335 managers
.push_back(new KwBibleManagerSword
);
336 managers
.push_back(new KwBibleManagerBibleGateway
);
338 m_bibleTabs
= new QTabWidget();
339 m_bibleTabs
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Preferred
);
340 connect(m_bibleTabs
, SIGNAL(currentChanged(int)),
341 this, SLOT(bibleChanged()));
342 m_view
->layoutBibleTabs
->addWidget(m_bibleTabs
);
344 foreach (KwBibleManager
* manager
, managers
)
346 QString name
= manager
->name();
348 mgr
.manager
= manager
;
350 QWidget
* tabWidget
= new QWidget();
351 QHBoxLayout
* layout
= new QHBoxLayout(tabWidget
);
353 mgr
.comboBibles
= new QComboBox();
354 connect(mgr
.comboBibles
, SIGNAL(currentIndexChanged(int)),
355 this, SLOT(bibleChanged()));
357 // Only fill the module list if the manager is local
358 // Otherwise we should wait until the user requests it
359 if (manager
->isRemote())
361 mgr
.comboBibles
->setEnabled(false);
363 mgr
.toolBar
= new QToolBar();
364 KAction
* connectToBible
= new KAction(KIcon("network-connect"), i18n("Connect to %1", name
), mgr
.toolBar
);
365 connect(connectToBible
, SIGNAL(triggered(bool)),
366 this, SLOT(bibleConnect()));
367 mgr
.toolBar
->addAction(connectToBible
);
368 layout
->addWidget(mgr
.toolBar
);
370 // Toolbar should be as small as possible
373 policy
= mgr
.toolBar
->sizePolicy();
374 policy
.setHorizontalStretch(1);
375 mgr
.toolBar
->setSizePolicy(policy
);
377 policy
= mgr
.comboBibles
->sizePolicy();
378 policy
.setHorizontalStretch(10);
379 mgr
.comboBibles
->setSizePolicy(policy
);
384 QStringList modules
= manager
->moduleNames();
385 foreach (QString module
, modules
)
387 mgr
.comboBibles
->addItem(module
, QVariant(module
));
391 layout
->addWidget(mgr
.comboBibles
);
393 m_bibleTabs
->addTab(tabWidget
, name
);
394 m_bibles
.push_back(mgr
);
396 // Ensure widgets are apropriately modified
397 connect(m_view
->comboBibleBook
, SIGNAL(currentIndexChanged(int)),
398 this, SLOT(bibleBookChanged()));
399 connect(m_view
->comboBibleChapter
, SIGNAL(currentIndexChanged(int)),
400 this, SLOT(bibleChapterChanged()));
404 kworship::~kworship()
406 delete KwSongdb::self();
414 /// Load a specified playlist.
415 void kworship::loadPlaylist(const KUrl
& url
)
418 m_document
->reload();
421 void kworship::setupActions()
424 KStandardAction::quit(qApp
, SLOT(quit()), actionCollection());
425 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
428 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
429 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
430 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
431 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
434 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
436 m_mainDisplayAction
= new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
437 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction
);
438 connect(m_mainDisplayAction
, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
440 KAction
* clearDisplayAction
= new KAction(KIcon("clear"), i18n("Clear display"), this);
441 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction
);
442 connect(clearDisplayAction
, SIGNAL(triggered()), this, SLOT(displayClear()));
445 m_unlockSongDbAction
= new KAction(KIcon("document-decrypt"), i18n("Unlock Song Database"), this);
446 actionCollection()->addAction( QLatin1String("unlock_song_database"), m_unlockSongDbAction
);
447 connect(m_unlockSongDbAction
, SIGNAL(triggered(bool)), this, SLOT(songdbUnlock()));
449 m_lockSongDbAction
= new KAction(KIcon("document-encrypt"), i18n("Lock Song Database"), this);
450 m_lockSongDbAction
->setVisible(false);
451 actionCollection()->addAction( QLatin1String("lock_song_database"), m_lockSongDbAction
);
452 connect(m_lockSongDbAction
, SIGNAL(triggered(bool)), this, SLOT(songdbLock()));
454 m_groupSongsByAction
= new KActionMenu(KIcon("view-filter"), i18n("Group By"), this);
455 m_groupSongsByAction
->setDelayed(false);
456 actionCollection()->addAction( QLatin1String("group_songs_by"), m_groupSongsByAction
);
458 m_addSongAction
= new KAction(KIcon("list-add"), i18n("Add Song"), this);
459 actionCollection()->addAction( QLatin1String("add_song"), m_addSongAction
);
460 connect(m_addSongAction
, SIGNAL(triggered(bool)), this, SLOT(songdbAdd()));
462 m_editSongAction
= new KAction(KIcon("view-media-lyrics"), i18n("Edit Song"), this);
463 actionCollection()->addAction( QLatin1String("edit_song"), m_editSongAction
);
464 connect(m_editSongAction
, SIGNAL(triggered(bool)), this, SLOT(songdbEdit()));
466 m_editSongBooksAction
= new KAction(KIcon("format-list-ordered"), i18n("Edit Song Books"), this);
467 actionCollection()->addAction( QLatin1String("edit_song_books"), m_editSongBooksAction
);
468 connect(m_editSongBooksAction
, SIGNAL(triggered(bool)), this, SLOT(songdbEditSongBooks()));
471 void kworship::settingsChanged()
473 // If the main display is on and screen has changed, move it now
474 if (0 != m_mainDisplay
&& getCorrectDisplayScreen() != getCurrentDisplayScreen())
476 toggleMainDisplay(false);
477 toggleMainDisplay(true);
478 m_mainDisplayAction
->setChecked(true);
482 int kworship::getCorrectDisplayScreen()
484 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
485 assert(0 != desktop
);
487 int screens
= desktop
->numScreens();
488 int displayScreen
= -1;
489 if (Settings::displayScreenChoose())
491 displayScreen
= Settings::displayScreen();
493 if (-1 == displayScreen
)
496 if (m_view
->isVisible())
498 currentScreen
= desktop
->screenNumber(m_view
);
502 currentScreen
= desktop
->primaryScreen();
505 if (displayScreen
== currentScreen
&& displayScreen
< screens
-1)
511 return displayScreen
;
514 int kworship::getCurrentDisplayScreen()
516 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
517 assert(0 != desktop
);
519 int previousScreen
= desktop
->screenNumber(m_mainDisplay
);
521 return previousScreen
;
524 void kworship::toggleMainDisplay(bool checked
)
528 // Ensure the display exists
529 if (0 == m_mainDisplay
)
531 m_mainDisplay
= new KwLocalDisplay
;
532 m_mainDisplay
->setPrimary(true);
533 m_mainDisplay
->setWindowTitle("kworship display");
534 m_displayController
.attachChild(m_mainDisplay
);
535 connect(m_mainDisplay
, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
538 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
539 assert(0 != desktop
);
541 int screens
= desktop
->numScreens();
542 int displayScreen
= getCorrectDisplayScreen();
544 if (displayScreen
>= 0 && displayScreen
< screens
)
546 m_mainDisplay
->move(desktop
->screenGeometry(displayScreen
).topLeft());
549 if (!m_slideshowAction
->isChecked())
551 m_mainDisplay
->showFullScreen();
556 if (0 != m_mainDisplay
)
558 m_mainDisplay
->close();
563 void kworship::mainDisplayClosed()
565 m_mainDisplay
->deleteLater();
567 m_mainDisplayAction
->setChecked(false);
570 void kworship::displayClear()
572 m_displayManager
->background
.clear();
573 m_displayManager
->text
.clear();
576 void kworship::toggleFullscreen(bool checked
)
588 bool kworship::askToSave()
590 if (m_document
->isModified())
592 switch (KMessageBox::questionYesNoCancel(this,
593 i18n("The current playlist has been modified. "
594 "These modifications will be lost if you continue without saving. "
595 "Would you like to save now?"),
596 i18n("Playlist is modified")))
598 case KMessageBox::Yes
:
601 // If the document is still modified, save must have been cancelled
602 if (m_document
->isModified())
608 case KMessageBox::No
:
610 case KMessageBox::Cancel
:
621 void kworship::fileNew()
629 void kworship::fileOpen()
633 // Do the open operation
634 QString filter
= "*.kwz *.kw|" + i18n("All KWorship playlists");
635 KUrl
defaultUrl("kfiledialog:///playlist");
636 if (m_document
->isSaved())
638 defaultUrl
= m_document
->url();
640 KUrl url
= KFileDialog::getOpenUrl(defaultUrl
, filter
, this);
648 void kworship::fileSave()
650 if (m_document
->isSaved())
660 void kworship::fileSaveAs()
662 QString filter
= "*.kwz|" + i18n("KWorship playlists") + "\n"
663 "*.kw|" + i18n("KWorship uncompressed playlists");
664 KUrl
defaultUrl("kfiledialog:///playlist");
665 if (m_document
->isSaved())
667 defaultUrl
= m_document
->url();
669 KUrl url
= KFileDialog::getSaveUrl(defaultUrl
, filter
, this);
672 m_document
->saveAs(url
);
676 void kworship::optionsPreferences()
678 //avoid to have 2 dialogs shown
679 if ( KConfigDialog::showDialog( "settings" ) ) {
682 KConfigDialog
*dialog
= new KConfigDialog(this, "settings", Settings::self());
684 QWidget
*generalSettingsDlg
= new QWidget(dialog
);
685 ui_prefs_base
.setupUi(generalSettingsDlg
);
686 dialog
->addPage(generalSettingsDlg
, i18n("General"), "preferences-other", i18n("General"));
688 prefsDisplay
*displaySettingsDlg
= new prefsDisplay(dialog
);
689 dialog
->addPage(displaySettingsDlg
, i18n("Display"), "video-projector", i18n("Display and Screen"));
691 prefsSongDB
*songdbSettingsDlg
= new prefsSongDB(dialog
);
692 dialog
->addPage(songdbSettingsDlg
, i18n("Song DB"), "applications-multimedia", i18n("Song Database"));
694 QWidget
*presentationSettingsDlg
= new QWidget(dialog
);
695 ui_prefsPresentations_base
.setupUi(presentationSettingsDlg
);
696 dialog
->addPage(presentationSettingsDlg
, i18n("Presentations"), "view-presentation", i18n("Presentations and Slideshows"));
698 connect(dialog
, SIGNAL(settingsChanged(QString
)), m_view
, SLOT(settingsChanged()));
699 connect(dialog
, SIGNAL(settingsChanged(QString
)), this, SLOT(settingsChanged()));
700 dialog
->setAttribute( Qt::WA_DeleteOnClose
);
704 void kworship::playlist_doubleClicked(QModelIndex index
)
706 KwPlaylistNode
* node
= m_playlistModel
->itemFromIndex(index
);
707 node
->activate(m_displayManager
);
710 void kworship::playlistReset()
712 // Connect up the new document
713 m_playlistModel
->setRootNode(m_document
->playlist()->getNode(0));
716 void kworship::presentationDelete()
718 setPresentation(0, true);
719 presentationSelected(0);
722 void kworship::presentationSelected(int)
724 // Find the treeviews current index
725 QModelIndex index
= m_selectPresTree
->currentIndex();
726 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
727 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
730 m_view
->listSlides
->setModel(model
);
731 m_view
->listSlides
->setRootIndex(index
);
732 setPresentation(presNode
->getItem());
736 m_view
->listSlides
->setModel(0);
741 void kworship::presentationToggled(bool checked
)
743 // Find the treeviews current index
744 QModelIndex index
= m_selectPresTree
->currentIndex();
745 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
746 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
751 presNode
->getItem()->startSlideshow();
755 presNode
->getItem()->stopSlideshow();
760 void kworship::presentationPreviousSlide()
762 // Find the treeviews current index
763 QModelIndex index
= m_selectPresTree
->currentIndex();
764 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
765 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
768 presNode
->getItem()->previousSlide();
772 void kworship::presentationNextSlide()
774 // Find the treeviews current index
775 QModelIndex index
= m_selectPresTree
->currentIndex();
776 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
777 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
780 presNode
->getItem()->nextSlide();
784 void kworship::presentationPreviousStep()
786 // Find the treeviews current index
787 QModelIndex index
= m_selectPresTree
->currentIndex();
788 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
789 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
792 presNode
->getItem()->previousStep();
796 void kworship::presentationNextStep()
798 // Find the treeviews current index
799 QModelIndex index
= m_selectPresTree
->currentIndex();
800 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
801 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
804 presNode
->getItem()->nextStep();
808 void kworship::slide_doubleClicked(QModelIndex index
)
810 // Find the listviews current index
811 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
812 QModelIndex parentIndex
= model
->parent(index
);
813 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(parentIndex
));
816 presNode
->getItem()->goToSlide(index
.row());
821 void kworship::setDocument(KUrl url
)
824 m_document
= new KwDocument(url
, this);
826 // Playlist will have changed
830 connect(m_document
, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
834 void kworship::setPresentation(UpPresentation
* presentation
, bool alreadyDestroyed
)
836 if (0 != m_currentPresentation
)
838 // Stop the slideshow if its running
839 m_view
->slideshows
->setVisible(false);
840 if (!alreadyDestroyed
)
842 m_currentPresentation
->stopSlideshow();
843 disconnect(m_currentPresentation
, SIGNAL(currentSlideshowChanged(QString
)), this, SLOT(changeSlideshowExternal(QString
)));
844 disconnect(m_currentPresentation
, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
845 disconnect(m_currentPresentation
, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
846 disconnect(m_currentPresentation
, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
847 disconnect(m_currentPresentation
, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
848 disconnect(m_currentPresentation
, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
849 disconnect(m_currentPresentation
, SIGNAL(destroyed(QObject
*)), this, SLOT(presentationDelete()));
853 m_currentPresentation
= presentation
;
854 if (0 != m_currentPresentation
)
856 connect(m_currentPresentation
, SIGNAL(currentSlideshowChanged(QString
)), this, SLOT(changeSlideshowExternal(QString
)));
857 connect(m_currentPresentation
, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
858 connect(m_currentPresentation
, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
859 connect(m_currentPresentation
, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
860 connect(m_currentPresentation
, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
861 connect(m_currentPresentation
, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
862 connect(m_currentPresentation
, SIGNAL(destroyed(QObject
*)), this, SLOT(presentationDelete()));
863 // update slideshows list
865 m_view
->slideshows
->setVisible(true);
867 if (m_currentPresentation
->isSlideshowRunning())
869 slideshowStarted(m_currentPresentation
->numSlidesInSlideshow());
870 slideshowSlideChanged(m_currentPresentation
->currentSlideshowSlide(), m_currentPresentation
->stepsInCurrentSlideshowSlide());
871 slideshowStepChanged(m_currentPresentation
->currentSlideshowStep());
874 m_slideshowAction
->setEnabled(0 != m_currentPresentation
);
879 void kworship::presentationComboReset()
881 m_selectPresTree
->expandToDepth(0);
882 m_selectPresTree
->setItemsExpandable(false);
885 void kworship::changeSlideshowCombo(QString name
)
887 Q_ASSERT(0 != m_currentPresentation
);
888 m_currentPresentation
->setSlideshow(name
);
892 void kworship::changeSlideshowExternal(QString name
)
894 if (m_view
->comboSlideshows
->currentText() != name
)
896 m_view
->comboSlideshows
->setCurrentIndex(m_view
->comboSlideshows
->findText(name
));
901 void kworship::refreshSlideshows()
903 Q_ASSERT(0 != m_currentPresentation
);
904 m_view
->comboSlideshows
->clear();
905 m_view
->comboSlideshows
->insertItems(0, m_currentPresentation
->slideshows());
906 m_view
->comboSlideshows
->setCurrentIndex(m_view
->comboSlideshows
->findText(m_currentPresentation
->currentSlideshow()));
909 void kworship::refreshSlides()
912 QModelIndex root
= m_view
->listSlides
->rootIndex();
913 DefaultModelNode
* node
= m_presentationManager
->presentationsModel()->itemFromIndex(root
);
915 node
->clearChildCache();
918 m_view
->listSlides
->setRootIndex(root
);
921 void kworship::addSlideshowLinkToPlaylist()
923 Q_ASSERT(0 != m_currentPresentation
);
924 QUrl url
= m_currentPresentation
->url();
925 QString slideshow
= m_currentPresentation
->currentSlideshow();
926 /// @todo Implement me
928 void kworship::addSlideshowCopyToPlaylist()
930 Q_ASSERT(0 != m_currentPresentation
);
931 QString slideshow
= m_currentPresentation
->currentSlideshow();
932 /// @todo Implement me
935 // From current presentation
937 void kworship::slideshowStarted(int numSlides
)
940 if (0 != m_mainDisplay
)
942 m_mainDisplay
->hide();
946 m_displayManager
->background
.clear();
947 m_displayManager
->text
.clear();
949 m_view
->slideshows
->setEnabled(false);
950 m_view
->progressPresSlides
->setMaximum(numSlides
);
951 m_view
->progressPresSlides
->setVisible(true);
952 m_slideshowAction
->setChecked(true);
955 void kworship::slideshowStopped()
957 m_view
->slideshows
->setEnabled(true);
958 m_view
->progressPresSlides
->setVisible(false);
959 m_view
->progressPresSteps
->setVisible(false);
960 m_slideshowAction
->setChecked(false);
961 m_slideshowPrevSlideAction
->setEnabled(false);
962 m_slideshowPrevStepAction
->setEnabled(false);
963 m_slideshowNextStepAction
->setEnabled(false);
964 m_slideshowNextSlideAction
->setEnabled(false);
966 // Clear any preview left from the slideshow
967 m_displayManager
->background
.clear();
969 m_slideNotes
->document()->clear();
971 // Show the screen again
972 if (0 != m_mainDisplay
)
974 m_mainDisplay
->showFullScreen();
978 void kworship::slideshowSlideChanged(int slide
, int numSteps
)
980 m_view
->progressPresSlides
->setValue(slide
+ 1);
981 m_view
->progressPresSteps
->setMaximum(numSteps
);
982 m_view
->progressPresSteps
->setVisible(numSteps
> 1);
984 m_slideshowPrevSlideAction
->setEnabled(slide
> 0);
985 m_slideshowNextSlideAction
->setEnabled(slide
< m_view
->progressPresSlides
->maximum()-1);
987 // live preview and notes
988 m_slideNotes
->document()->clear();
989 assert(0 != m_currentPresentation
);
990 UpSlide
* currentSlide
= m_currentPresentation
->slide(slide
);
991 if (0 != currentSlide
)
994 if (Settings::presLivePreview())
996 m_displayManager
->background
.setImage(currentSlide
->preview());
999 currentSlide
->writeNotes(m_slideNotes
->document());
1003 void kworship::slideshowStepChanged(int step
)
1005 m_view
->progressPresSteps
->setValue(step
+ 1);
1007 bool firstSlide
= (m_view
->progressPresSlides
->value() <= 1);
1008 bool lastSlide
= (m_view
->progressPresSlides
->value() >= m_view
->progressPresSlides
->maximum());
1009 bool firstStep
= firstSlide
&& (step
<= 0);
1010 bool lastStep
= lastSlide
&& (step
>= m_view
->progressPresSteps
->maximum() - 1);
1011 m_slideshowPrevStepAction
->setEnabled(!firstStep
);
1012 m_slideshowNextStepAction
->setEnabled(!lastStep
);
1017 void kworship::songdbUnlock()
1019 m_unlockSongDbAction
->setVisible(false);
1020 m_lockSongDbAction
->setVisible(true);
1023 void kworship::songdbLock()
1025 m_unlockSongDbAction
->setVisible(true);
1026 m_lockSongDbAction
->setVisible(false);
1029 void kworship::songdbAdd()
1031 KwSongdbSongEditDialog
* dialog
= new KwSongdbSongEditDialog(0);
1032 dialog
->setCaption(i18n("Add Song"));
1033 dialog
->setAttribute(Qt::WA_DeleteOnClose
, true);
1037 void kworship::songdbEdit()
1039 /// @todo Ensure the same song isn't open twice
1040 KwSongdbSong
* song
= m_songDbTree
->currentSong();
1043 KwSongdbVersion
* version
= m_songDbTree
->currentSongVersion();
1045 KwSongdbSongEditDialog
* dialog
= new KwSongdbSongEditDialog(song
, version
);
1046 dialog
->setCaption(i18n("Edit Song - %1", song
->name()));
1047 dialog
->setAttribute(Qt::WA_DeleteOnClose
, true);
1052 KMessageBox::information(this, i18n("Please select a song."));
1056 void kworship::songdbEditSongBooks()
1058 KwSongdbSongBooksEditWidget::showDialog();
1063 void kworship::bibleConnect()
1065 // Get the current bible manager
1066 int tab
= m_bibleTabs
->currentIndex();
1067 Q_ASSERT(tab
>= 0 && tab
< m_bibles
.size());
1068 BibleManager
& mgr
= m_bibles
[tab
];
1070 // This will force the connection
1071 QStringList modules
= mgr
.manager
->moduleNames();
1072 mgr
.comboBibles
->clear();
1073 if (modules
.isEmpty())
1075 KMessageBox::information(this, i18n("No bibles found"));
1079 mgr
.comboBibles
->setEnabled(true);
1080 foreach (QString module
, modules
)
1082 mgr
.comboBibles
->addItem(module
, QVariant(module
));
1087 void kworship::bibleChanged()
1089 // Get the current bible manager
1090 int tab
= m_bibleTabs
->currentIndex();
1091 if (tab
>= 0 && tab
< m_bibles
.size())
1093 BibleManager
& mgr
= m_bibles
[tab
];
1094 bool enabled
= mgr
.comboBibles
->isEnabled();
1096 // Is a bible selected?
1097 QString bible
= mgr
.comboBibles
->currentText();
1098 KwBibleModule
* module
= mgr
.manager
->module(bible
);
1100 // Update the list of books
1101 QString book
= m_view
->comboBibleBook
->currentText();
1102 int chapter
= m_view
->comboBibleChapter
->currentIndex();
1103 m_view
->comboBibleBook
->clear();
1106 QStringList bookNames
= module
->books();
1107 for (int i
= 0; i
< bookNames
.size(); ++i
)
1109 const QString
& bookName
= bookNames
[i
];
1110 m_view
->comboBibleBook
->addItem(bookName
, QVariant(i
));
1112 int index
= m_view
->comboBibleBook
->findText(book
);
1113 bool canPreserveBook
= (index
>= 0);
1114 if (!canPreserveBook
&& bookNames
.size() > 0)
1118 m_view
->comboBibleBook
->setCurrentIndex(index
);
1119 if (canPreserveBook
&& chapter
>= 0)
1121 // If we can restore book, also restore chapter
1122 m_view
->comboBibleChapter
->setCurrentIndex(chapter
);
1130 //bibleBookChanged();
1131 m_view
->comboBibleBook
->setEnabled(enabled
);
1132 m_view
->comboBibleChapter
->setEnabled(enabled
);
1133 m_view
->searchBible
->setEnabled(enabled
);
1134 m_view
->textBible
->setEnabled(enabled
);
1136 m_view
->searchBible
->setText(QString());
1141 void kworship::bibleBookChanged()
1143 m_view
->comboBibleChapter
->clear();
1145 // Get the current bible manager
1146 int tab
= m_bibleTabs
->currentIndex();
1147 if (tab
>= 0 && tab
< m_bibles
.size())
1149 BibleManager
& mgr
= m_bibles
[tab
];
1151 // Is a bible selected?
1152 QString bible
= mgr
.comboBibles
->currentText();
1153 KwBibleModule
* module
= mgr
.manager
->module(bible
);
1156 // Is a book selected?
1157 int index
= m_view
->comboBibleBook
->currentIndex();
1160 int bookIndex
= m_view
->comboBibleBook
->itemData(index
).toInt();
1161 int numChapters
= module
->numChapters(bookIndex
);
1162 for (int i
= 0; i
< numChapters
; ++i
)
1164 m_view
->comboBibleChapter
->addItem(QString("%1").arg(i
+1), QVariant(i
));
1171 void kworship::bibleChapterChanged()
1173 // Get the current bible manager
1174 int tab
= m_bibleTabs
->currentIndex();
1175 if (tab
>= 0 && tab
< m_bibles
.size())
1177 BibleManager
& mgr
= m_bibles
[tab
];
1179 // Is a bible selected?
1180 QString bible
= mgr
.comboBibles
->currentText();
1181 KwBibleModule
* module
= mgr
.manager
->module(bible
);
1184 // Is a book selected?
1185 int bookIndex
= m_view
->comboBibleBook
->currentIndex();
1188 // Is a chapter selected?
1189 int chapterIndex
= m_view
->comboBibleChapter
->currentIndex();
1190 if (chapterIndex
>= 0)
1192 KwBibleModule::Key key
= module
->createKey(bookIndex
, chapterIndex
);
1193 m_view
->textBible
->document()->setHtml(module
->renderText(key
));
1199 m_view
->textBible
->document()->setPlainText(QString());
1202 void kworship::bibleSearch()
1205 // Search using the key
1206 int index = m_view->comboSwordBibles->currentIndex();
1209 QString modName = m_view->comboSwordBibles->itemData(index).toString();
1210 KwBibleModule* module = KwBibleManager::self()->module(modName);
1213 KwBibleModule::Key key = module->createKey(m_view->searchBible->text());
1214 m_view->textBible->document()->setHtml(module->renderText(key));
1218 m_view->textBible->document()->setPlainText(QString());
1222 #include "kworship.moc"