Make bible integration into a dynamically loaded plugin.
[kworship.git] / kworship / kworship.cpp
blobfd998452540f9d0ab156690d89d79ee4e3fc5f8c
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 #include "kworship.h"
21 #include "kworshipview.h"
22 #include "settings.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 "KwSongdb.h"
47 #include "KwSongdbModel.h"
48 #include "KwSongdbFilterNode.h"
49 #include "KwSongdbTree.h"
50 #include "KwSongdbSong.h"
51 #include "KwSongdbSongEditDialog.h"
52 #include "KwSongdbSongBooksEditWidget.h"
54 #include "UpManager.h"
55 #include "UpPresentationsModel.h"
56 #include "UpPresentation.h"
57 #include "UpPresentationNode.h"
58 #include "UpSlide.h"
60 #include <kconfigdialog.h>
61 #include <kstatusbar.h>
62 #include <kaction.h>
63 #include <kactionmenu.h>
64 #include <kmenu.h>
65 #include <ktoggleaction.h>
66 #include <kactioncollection.h>
67 #include <kstandardaction.h>
68 #include <KDE/KLocale>
69 #include <KFileDialog>
70 #include <KMessageBox>
72 #include <phonon/audiooutput.h>
74 #include <QtGui/QDropEvent>
75 #include <QtGui/QPainter>
76 #include <QColor>
77 #include <QDesktopWidget>
78 #include <QToolBar>
79 #include <QToolButton>
80 #include <QComboBox>
81 #include <QSqlDatabase>
82 #include <QHeaderView>
83 #include <QTextEdit>
85 kworship::kworship()
86 : KXmlGuiWindow()
87 , m_view(new kworshipView(this))
88 , m_displayManager(0)
89 , m_document(0)
90 , m_presentationManager(new UpManager(this))
91 , m_currentPresentation(0)
92 , m_printer(0)
94 m_playlistModel = new KwPlaylistModel;
95 setDocument();
97 // set up presentation backends
98 m_presentationManager->loadBackends();
100 m_mainDisplay = 0;
101 m_previewDisplay = 0;
103 // accept dnd
104 setAcceptDrops(true);
106 // tell the KXmlGuiWindow that this is indeed the main widget
107 setCentralWidget(m_view);
109 // then, setup our actions
110 setupActions();
112 // add a status bar
113 statusBar()->show();
115 // a call to KXmlGuiWindow::setupGUI() populates the GUI
116 // with actions, using KXMLGUI.
117 // It also applies the saved mainwindow settings, if any, and ask the
118 // mainwindow to automatically save settings if changed: window size,
119 // toolbar position, icon size, etc.
120 setupGUI();
122 // Setup the dockers
123 addDockWidget(Qt::LeftDockWidgetArea, m_view->dockPresentation);
124 tabifyDockWidget(m_view->dockPresentation, m_view->dockSongs);
125 addDockWidget(Qt::RightDockWidgetArea, m_view->dockPreview);
126 addDockWidget(Qt::RightDockWidgetArea, m_view->dockLyrics);
127 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockThemes);
128 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockNowPlaying);
130 // Setup some stuff in the tree
131 #if 0
132 #define TREE_ITEM(name, string, parent) QTreeWidgetItem* name = new QTreeWidgetItem(parent); name->setText(0, tr(string));
134 TREE_ITEM(song1, "Our God is a great big God", m_view->treeWidget);
135 TREE_ITEM(song1_style, "(style)", song1);
136 TREE_ITEM(song1_style_1, "Mode", song1_style);
137 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);
138 TREE_ITEM(song1_v2, "He's higher than a skyscraper\nAnd he's deeper than a submarine.", song1);
139 TREE_ITEM(song1_v3, "He's wider than the universe\nAnd beyond my wildest dreams.", song1);
141 #undef TREE_ITEM
142 #endif
144 // Setup song db
146 KwDatabaseSetup dbSetup;
147 bool databaseOk = dbSetup.initialiseFromConfig();
148 if (databaseOk)
150 new KwSongdb(dbSetup.database());
153 // Playlist
154 m_document->playlist()->addClass("beachy");
156 KwCssStyleSheet* styleRules = new KwCssStyleSheet;
158 KwCssStyleRule beachyTheme;
159 beachyTheme.setCriteriaClasses(QSet<QString>() << "beachy");
160 beachyTheme.setStyle<QBrush>("background.brush", Qt::black);
161 beachyTheme.setStyle<KwResourceLink>("background.image.src", KUrl("file:///home/james/media/images/projector/misc/love-god-light.jpg"));
162 styleRules->addRule(beachyTheme);
164 KwCssStyleRule bibleTheme;
165 bibleTheme.setCriteriaKeys(KwCssStyleRule::KeyList() << KwCssScopeKey(KwCssScopeKey::registerScopeType("bible")));
166 bibleTheme.setStyle<QBrush>("background.brush", Qt::black);
167 bibleTheme.setStyle<KwResourceLink>("background.image.src", KUrl("file:///home/james/media/images/projector/misc/bible.jpg"));
168 styleRules->addRule(bibleTheme);
170 m_document->playlist()->addStyleSheet(styleRules);
172 m_view->treePlaylist->setModel(m_playlistModel);
173 m_view->treePlaylist->setExpandsOnDoubleClick(false);
174 m_view->treePlaylist->setAcceptDrops(true);
176 connect(m_view->treePlaylist, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(playlist_doubleClicked(QModelIndex)));
178 m_mediaManager = new KwMediaManager();
179 m_mediaManager->linkAudio(new Phonon::AudioOutput(Phonon::MusicCategory));
180 m_displayManager = new KwDisplayManager(&m_displayController, m_mediaManager);
182 m_previewDisplay = new KwLocalDisplayPreview;
183 m_view->layoutPreview->addWidget(m_previewDisplay);
184 m_displayController.attachChild(m_previewDisplay);
186 KwMediaControlWidget* mediaWidget = new KwMediaControlWidget(m_mediaManager, m_view->dockNowPlaying);
187 m_view->layoutNowPlaying->addWidget(mediaWidget);
189 // Small toolbar for group by action
190 QToolBar* songTextToolBar = new QToolBar("Songs");
191 songTextToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
192 songTextToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
193 m_view->layoutSongsToolbar->layout()->addWidget(songTextToolBar);
195 songTextToolBar->addAction(m_groupSongsByAction);
197 // Rest of the toolbar
198 QToolBar* songToolBar = new QToolBar("Songs");
199 songToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
200 m_view->layoutSongsToolbar->layout()->addWidget(songToolBar);
202 songToolBar->addAction(m_addSongAction);
203 songToolBar->addAction(m_editSongAction);
204 songToolBar->addAction(m_editSongBooksAction);
205 KAction* insertIntoPlaylistAction = new KAction(KIcon("player_playlist"), i18n("Insert Into Playlist"), songToolBar);
206 songToolBar->addAction(insertIntoPlaylistAction);
208 KMenu* groupByMenu = new KMenu(songToolBar);
209 m_groupSongsByAction->setMenu(groupByMenu);
211 if (databaseOk)
213 m_songDbTree = new KwSongdbTree(m_view);
214 m_view->layoutSongsTree->addWidget(m_songDbTree);
215 groupByMenu->addActions(m_songDbTree->groupByActions()->actions());
220 * Presentation
223 // Drop down list of presentations
224 QComboBox* selectPresCombo = m_view->comboPresentations;
225 m_selectPresTree = new QTreeView(this);
226 m_selectPresTree->header()->hide();
227 selectPresCombo->setModel(m_presentationManager->presentationsModel());
228 selectPresCombo->setView(m_selectPresTree);
229 presentationComboReset();
230 connect(m_presentationManager->presentationsModel(), SIGNAL(modelReset()), this, SLOT(presentationComboReset()));
231 connect(selectPresCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(presentationSelected(int)));
233 // Custom slideshow selector
234 m_view->slideshows->setVisible(false);
235 connect(m_view->comboSlideshows, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(changeSlideshowCombo(QString)));
237 QToolBar* customSlideshowsToolBar = new QToolBar(i18n("Custom Slideshows"));
238 customSlideshowsToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
239 m_view->slideshows->layout()->addWidget(customSlideshowsToolBar);
240 // Add slideshow to playlist
241 KActionMenu* addSlideshowToPlaylistAction = new KActionMenu(KIcon("list-add"), i18n("Add Slideshow to Playlist"), customSlideshowsToolBar);
242 addSlideshowToPlaylistAction->setDelayed(false);
243 customSlideshowsToolBar->addAction(addSlideshowToPlaylistAction);
245 KAction* asLinkAction = new KAction(KIcon("insert-link"), i18n("Add Link to Slideshow into Playlist"), customSlideshowsToolBar);
246 connect(asLinkAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowLinkToPlaylist()));
247 addSlideshowToPlaylistAction->addAction(asLinkAction);
250 KAction* asCopyAction = new KAction(KIcon("edit-copy"), i18n("Save Copy of Slideshow into Playlist"), customSlideshowsToolBar);
251 connect(asCopyAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowCopyToPlaylist()));
252 addSlideshowToPlaylistAction->addAction(asCopyAction);
255 // Presentations toolbar
256 QToolBar* presToolBar = new QToolBar("Presentations");
257 m_view->layoutPresentationsToolbar->layout()->addWidget(presToolBar);
259 KActionMenu* openPresAction = new KActionMenu(KIcon("document-open"), "Open Presentation", presToolBar);
260 openPresAction->setDelayed(true);
261 presToolBar->addAction(openPresAction);
263 KAction* refreshPresAction = new KAction(KIcon("view-refresh"), "Refresh Presentation List", presToolBar);
264 presToolBar->addAction(refreshPresAction);
266 KAction* closePresAction = new KAction(KIcon("fileclose"), "Close Presentation", presToolBar);
267 presToolBar->addAction(closePresAction);
269 KToggleAction* fullscreenPresAction = new KToggleAction(KIcon("view-fullscreen"), "Fullscreen Presentation Mode", presToolBar);
270 presToolBar->addAction(fullscreenPresAction);
272 // Slide list
273 connect(m_view->listSlides, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slide_doubleClicked(QModelIndex)));
275 // Slides toolbar
276 QToolBar* slidesToolBar = new QToolBar("Slides");
277 slidesToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
278 slidesToolBar->setIconSize(QSize(32,32));
279 m_view->layoutSlidesToolbar->layout()->addWidget(slidesToolBar);
281 m_slideshowPrevSlideAction = new KAction(KIcon("media-skip-backward"), i18n("Previous Slide"), slidesToolBar);
282 connect(m_slideshowPrevSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousSlide()));
283 slidesToolBar->addAction(m_slideshowPrevSlideAction);
285 m_slideshowPrevStepAction = new KAction(KIcon("media-seek-backward"), i18n("Previous Step"), slidesToolBar);
286 connect(m_slideshowPrevStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousStep()));
287 slidesToolBar->addAction(m_slideshowPrevStepAction);
289 m_slideshowNextStepAction = new KAction(KIcon("media-seek-forward"), i18n("Next Step"), slidesToolBar);
290 connect(m_slideshowNextStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextStep()));
291 slidesToolBar->addAction(m_slideshowNextStepAction);
293 m_slideshowNextSlideAction = new KAction(KIcon("media-skip-forward"), i18n("Next Slide"), slidesToolBar);
294 connect(m_slideshowNextSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextSlide()));
295 slidesToolBar->addAction(m_slideshowNextSlideAction);
297 m_slideshowAction = new KToggleAction(KIcon("view-presentation"), i18n("Start/Stop Slideshow"), slidesToolBar);
298 connect(m_slideshowAction, SIGNAL(toggled(bool)), this, SLOT(presentationToggled(bool)));
299 slidesToolBar->addAction(m_slideshowAction);
301 // Slide notes
302 m_slideNotes = new QTextEdit();
303 m_slideNotes->setReadOnly(true);
304 m_slideNotes->setWindowTitle(i18n("Slide Notes"));
305 m_slideNotes->show();
307 // Ensure the controls are as when slideshow is stopped
308 m_slideshowAction->setEnabled(false);
309 slideshowStopped();
312 * Display startup
315 // Show the display on startup?
316 if (Settings::displayShowStartup())
318 // If there's only one screen, don't bother showing display.
319 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
320 assert(0 != desktop);
321 if (desktop->numScreens() > 1)
323 toggleMainDisplay(true);
324 m_mainDisplayAction->setChecked(true);
329 kworship::~kworship()
331 delete KwSongdb::self();
332 delete m_slideNotes;
336 * Public interface
339 /// Load a specified playlist.
340 void kworship::loadPlaylist(const KUrl& url)
342 setDocument(url);
343 m_document->reload();
347 * Accessors
350 /// Get the main display manager.
351 KwDisplayManager* kworship::displayManager()
353 return m_displayManager;
356 /// Get the current document.
357 KwDocument* kworship::document()
359 return m_document;
362 /// Get the playlist model.
363 KwPlaylistModel* kworship::playlistModel()
365 return m_playlistModel;
368 void kworship::setupActions()
370 // Application
371 KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
372 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
374 // File management
375 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
376 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
377 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
378 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
380 // Display
381 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
383 m_mainDisplayAction = new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
384 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction );
385 connect(m_mainDisplayAction, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
387 KAction* clearDisplayAction = new KAction(KIcon("clear"), i18n("Clear display"), this);
388 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction);
389 connect(clearDisplayAction, SIGNAL(triggered()), this, SLOT(displayClear()));
391 // Song database
392 m_unlockSongDbAction = new KAction(KIcon("document-decrypt"), i18n("Unlock Song Database"), this);
393 actionCollection()->addAction( QLatin1String("unlock_song_database"), m_unlockSongDbAction);
394 connect(m_unlockSongDbAction, SIGNAL(triggered(bool)), this, SLOT(songdbUnlock()));
396 m_lockSongDbAction = new KAction(KIcon("document-encrypt"), i18n("Lock Song Database"), this);
397 m_lockSongDbAction->setVisible(false);
398 actionCollection()->addAction( QLatin1String("lock_song_database"), m_lockSongDbAction);
399 connect(m_lockSongDbAction, SIGNAL(triggered(bool)), this, SLOT(songdbLock()));
401 m_groupSongsByAction = new KActionMenu(KIcon("view-filter"), i18n("Group By"), this);
402 m_groupSongsByAction->setDelayed(false);
403 actionCollection()->addAction( QLatin1String("group_songs_by"), m_groupSongsByAction);
405 m_addSongAction = new KAction(KIcon("list-add"), i18n("Add Song"), this);
406 actionCollection()->addAction( QLatin1String("add_song"), m_addSongAction);
407 connect(m_addSongAction, SIGNAL(triggered(bool)), this, SLOT(songdbAdd()));
409 m_editSongAction = new KAction(KIcon("view-media-lyrics"), i18n("Edit Song"), this);
410 actionCollection()->addAction( QLatin1String("edit_song"), m_editSongAction);
411 connect(m_editSongAction, SIGNAL(triggered(bool)), this, SLOT(songdbEdit()));
413 m_editSongBooksAction = new KAction(KIcon("format-list-ordered"), i18n("Edit Song Books"), this);
414 actionCollection()->addAction( QLatin1String("edit_song_books"), m_editSongBooksAction);
415 connect(m_editSongBooksAction, SIGNAL(triggered(bool)), this, SLOT(songdbEditSongBooks()));
418 void kworship::settingsChanged()
420 // If the main display is on and screen has changed, move it now
421 if (0 != m_mainDisplay && getCorrectDisplayScreen() != getCurrentDisplayScreen())
423 toggleMainDisplay(false);
424 toggleMainDisplay(true);
425 m_mainDisplayAction->setChecked(true);
429 int kworship::getCorrectDisplayScreen()
431 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
432 assert(0 != desktop);
434 int screens = desktop->numScreens();
435 int displayScreen = -1;
436 if (Settings::displayScreenChoose())
438 displayScreen = Settings::displayScreen();
440 if (-1 == displayScreen)
442 int currentScreen;
443 if (m_view->isVisible())
445 currentScreen = desktop->screenNumber(m_view);
447 else
449 currentScreen = desktop->primaryScreen();
451 displayScreen = 0;
452 if (displayScreen == currentScreen && displayScreen < screens-1)
454 ++displayScreen;
458 return displayScreen;
461 int kworship::getCurrentDisplayScreen()
463 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
464 assert(0 != desktop);
466 int previousScreen = desktop->screenNumber(m_mainDisplay);
468 return previousScreen;
471 void kworship::toggleMainDisplay(bool checked)
473 if (checked)
475 // Ensure the display exists
476 if (0 == m_mainDisplay)
478 m_mainDisplay = new KwLocalDisplay;
479 m_mainDisplay->setPrimary(true);
480 m_mainDisplay->setWindowTitle("kworship display");
481 m_displayController.attachChild(m_mainDisplay);
482 connect(m_mainDisplay, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
485 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
486 assert(0 != desktop);
488 int screens = desktop->numScreens();
489 int displayScreen = getCorrectDisplayScreen();
491 if (displayScreen >= 0 && displayScreen < screens)
493 m_mainDisplay->move(desktop->screenGeometry(displayScreen).topLeft());
496 if (!m_slideshowAction->isChecked())
498 m_mainDisplay->showFullScreen();
501 else
503 if (0 != m_mainDisplay)
505 m_mainDisplay->close();
510 void kworship::mainDisplayClosed()
512 m_mainDisplay->deleteLater();
513 m_mainDisplay = 0;
514 m_mainDisplayAction->setChecked(false);
517 void kworship::displayClear()
519 m_displayManager->background.clear();
520 m_displayManager->text.clear();
523 void kworship::toggleFullscreen(bool checked)
525 if (checked)
527 showFullScreen();
529 else
531 showNormal();
535 bool kworship::askToSave()
537 if (m_document->isModified())
539 switch (KMessageBox::questionYesNoCancel(this,
540 i18n("The current playlist has been modified. "
541 "These modifications will be lost if you continue without saving. "
542 "Would you like to save now?"),
543 i18n("Playlist is modified")))
545 case KMessageBox::Yes:
547 fileSave();
548 // If the document is still modified, save must have been cancelled
549 if (m_document->isModified())
551 return false;
554 break;
555 case KMessageBox::No:
556 break;
557 case KMessageBox::Cancel:
558 default:
560 return false;
562 break;
565 return true;
568 void kworship::fileNew()
570 if (askToSave())
572 setDocument();
576 void kworship::fileOpen()
578 if (askToSave())
580 // Do the open operation
581 QString filter = "*.kwz *.kw|" + i18n("All KWorship playlists");
582 KUrl defaultUrl("kfiledialog:///playlist");
583 if (m_document->isSaved())
585 defaultUrl = m_document->url();
587 KUrl url = KFileDialog::getOpenUrl(defaultUrl, filter, this);
588 if (!url.isEmpty())
590 loadPlaylist(url);
595 void kworship::fileSave()
597 if (m_document->isSaved())
599 m_document->save();
601 else
603 fileSaveAs();
607 void kworship::fileSaveAs()
609 QString filter = "*.kwz|" + i18n("KWorship playlists") + "\n"
610 "*.kw|" + i18n("KWorship uncompressed playlists");
611 KUrl defaultUrl("kfiledialog:///playlist");
612 if (m_document->isSaved())
614 defaultUrl = m_document->url();
616 KUrl url = KFileDialog::getSaveUrl(defaultUrl, filter, this);
617 if (!url.isEmpty())
619 m_document->saveAs(url);
623 void kworship::optionsPreferences()
625 //avoid to have 2 dialogs shown
626 if ( KConfigDialog::showDialog( "settings" ) ) {
627 return;
629 KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
631 QWidget *generalSettingsDlg = new QWidget(dialog);
632 ui_prefs_base.setupUi(generalSettingsDlg);
633 dialog->addPage(generalSettingsDlg, i18n("General"), "preferences-other", i18n("General"));
635 prefsDisplay *displaySettingsDlg = new prefsDisplay(dialog);
636 dialog->addPage(displaySettingsDlg, i18n("Display"), "video-projector", i18n("Display and Screen"));
638 prefsSongDB *songdbSettingsDlg = new prefsSongDB(dialog);
639 dialog->addPage(songdbSettingsDlg, i18n("Song DB"), "applications-multimedia", i18n("Song Database"));
641 QWidget *presentationSettingsDlg = new QWidget(dialog);
642 ui_prefsPresentations_base.setupUi(presentationSettingsDlg);
643 dialog->addPage(presentationSettingsDlg, i18n("Presentations"), "view-presentation", i18n("Presentations and Slideshows"));
645 connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
646 connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(settingsChanged()));
647 dialog->setAttribute( Qt::WA_DeleteOnClose );
648 dialog->show();
651 void kworship::playlist_doubleClicked(QModelIndex index)
653 KwPlaylistNode* node = m_playlistModel->itemFromIndex(index);
654 node->activate(m_displayManager);
657 void kworship::playlistReset()
659 // Connect up the new document
660 m_playlistModel->setRootNode(m_document->playlist()->getNode(0));
663 #include <iostream>
664 /// Add the new docker to the interface.
665 void kworship::newDocker(QDockWidget* docker)
667 std::cout << docker << std::endl;
668 addDockWidget(Qt::LeftDockWidgetArea, docker);
671 void kworship::presentationDelete()
673 setPresentation(0, true);
674 presentationSelected(0);
677 void kworship::presentationSelected(int)
679 // Find the treeviews current index
680 QModelIndex index = m_selectPresTree->currentIndex();
681 UpPresentationsModel* model = m_presentationManager->presentationsModel();
682 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
683 if (0 != presNode)
685 m_view->listSlides->setModel(model);
686 m_view->listSlides->setRootIndex(index);
687 setPresentation(presNode->getItem());
689 else
691 m_view->listSlides->setModel(0);
692 setPresentation(0);
696 void kworship::presentationToggled(bool checked)
698 // Find the treeviews current index
699 QModelIndex index = m_selectPresTree->currentIndex();
700 UpPresentationsModel* model = m_presentationManager->presentationsModel();
701 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
702 if (0 != presNode)
704 if (checked)
706 presNode->getItem()->startSlideshow();
708 else
710 presNode->getItem()->stopSlideshow();
715 void kworship::presentationPreviousSlide()
717 // Find the treeviews current index
718 QModelIndex index = m_selectPresTree->currentIndex();
719 UpPresentationsModel* model = m_presentationManager->presentationsModel();
720 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
721 if (0 != presNode)
723 presNode->getItem()->previousSlide();
727 void kworship::presentationNextSlide()
729 // Find the treeviews current index
730 QModelIndex index = m_selectPresTree->currentIndex();
731 UpPresentationsModel* model = m_presentationManager->presentationsModel();
732 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
733 if (0 != presNode)
735 presNode->getItem()->nextSlide();
739 void kworship::presentationPreviousStep()
741 // Find the treeviews current index
742 QModelIndex index = m_selectPresTree->currentIndex();
743 UpPresentationsModel* model = m_presentationManager->presentationsModel();
744 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
745 if (0 != presNode)
747 presNode->getItem()->previousStep();
751 void kworship::presentationNextStep()
753 // Find the treeviews current index
754 QModelIndex index = m_selectPresTree->currentIndex();
755 UpPresentationsModel* model = m_presentationManager->presentationsModel();
756 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
757 if (0 != presNode)
759 presNode->getItem()->nextStep();
763 void kworship::slide_doubleClicked(QModelIndex index)
765 // Find the listviews current index
766 UpPresentationsModel* model = m_presentationManager->presentationsModel();
767 QModelIndex parentIndex = model->parent(index);
768 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(parentIndex));
769 if (0 != presNode)
771 presNode->getItem()->goToSlide(index.row());
775 // Documents
776 void kworship::setDocument(KUrl url)
778 delete m_document;
779 m_document = new KwDocument(url, this);
781 // Playlist will have changed
782 playlistReset();
784 // Wire up signals
785 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
788 // Presentations
789 void kworship::setPresentation(UpPresentation* presentation, bool alreadyDestroyed)
791 if (0 != m_currentPresentation)
793 // Stop the slideshow if its running
794 m_view->slideshows->setVisible(false);
795 if (!alreadyDestroyed)
797 m_currentPresentation->stopSlideshow();
798 disconnect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
799 disconnect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
800 disconnect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
801 disconnect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
802 disconnect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
803 disconnect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
804 disconnect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
806 slideshowStopped();
808 m_currentPresentation = presentation;
809 if (0 != m_currentPresentation)
811 connect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
812 connect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
813 connect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
814 connect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
815 connect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
816 connect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
817 connect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
818 // update slideshows list
819 refreshSlideshows();
820 m_view->slideshows->setVisible(true);
822 if (m_currentPresentation->isSlideshowRunning())
824 slideshowStarted(m_currentPresentation->numSlidesInSlideshow());
825 slideshowSlideChanged(m_currentPresentation->currentSlideshowSlide(), m_currentPresentation->stepsInCurrentSlideshowSlide());
826 slideshowStepChanged(m_currentPresentation->currentSlideshowStep());
829 m_slideshowAction->setEnabled(0 != m_currentPresentation);
832 // Custom slideshows
834 void kworship::presentationComboReset()
836 m_selectPresTree->expandToDepth(0);
837 m_selectPresTree->setItemsExpandable(false);
840 void kworship::changeSlideshowCombo(QString name)
842 Q_ASSERT(0 != m_currentPresentation);
843 m_currentPresentation->setSlideshow(name);
844 refreshSlides();
847 void kworship::changeSlideshowExternal(QString name)
849 if (m_view->comboSlideshows->currentText() != name)
851 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(name));
852 refreshSlides();
856 void kworship::refreshSlideshows()
858 Q_ASSERT(0 != m_currentPresentation);
859 m_view->comboSlideshows->clear();
860 m_view->comboSlideshows->insertItems(0, m_currentPresentation->slideshows());
861 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(m_currentPresentation->currentSlideshow()));
864 void kworship::refreshSlides()
866 // Clear child cache
867 QModelIndex root = m_view->listSlides->rootIndex();
868 DefaultModelNode* node = m_presentationManager->presentationsModel()->itemFromIndex(root);
869 Q_ASSERT(0 != node);
870 node->clearChildCache();
872 // Force a refresh
873 m_view->listSlides->setRootIndex(root);
876 void kworship::addSlideshowLinkToPlaylist()
878 Q_ASSERT(0 != m_currentPresentation);
879 QUrl url = m_currentPresentation->url();
880 QString slideshow = m_currentPresentation->currentSlideshow();
881 /// @todo Implement me
883 void kworship::addSlideshowCopyToPlaylist()
885 Q_ASSERT(0 != m_currentPresentation);
886 QString slideshow = m_currentPresentation->currentSlideshow();
887 /// @todo Implement me
890 // From current presentation
892 void kworship::slideshowStarted(int numSlides)
894 // Hide the screen
895 if (0 != m_mainDisplay)
897 m_mainDisplay->hide();
900 // Clear the display
901 m_displayManager->background.clear();
902 m_displayManager->text.clear();
904 m_view->slideshows->setEnabled(false);
905 m_view->progressPresSlides->setMaximum(numSlides);
906 m_view->progressPresSlides->setVisible(true);
907 m_slideshowAction->setChecked(true);
910 void kworship::slideshowStopped()
912 m_view->slideshows->setEnabled(true);
913 m_view->progressPresSlides->setVisible(false);
914 m_view->progressPresSteps->setVisible(false);
915 m_slideshowAction->setChecked(false);
916 m_slideshowPrevSlideAction->setEnabled(false);
917 m_slideshowPrevStepAction->setEnabled(false);
918 m_slideshowNextStepAction->setEnabled(false);
919 m_slideshowNextSlideAction->setEnabled(false);
921 // Clear any preview left from the slideshow
922 m_displayManager->background.clear();
923 // Clear slide notes
924 m_slideNotes->document()->clear();
926 // Show the screen again
927 if (0 != m_mainDisplay)
929 m_mainDisplay->showFullScreen();
933 void kworship::slideshowSlideChanged(int slide, int numSteps)
935 m_view->progressPresSlides->setValue(slide + 1);
936 m_view->progressPresSteps->setMaximum(numSteps);
937 m_view->progressPresSteps->setVisible(numSteps > 1);
939 m_slideshowPrevSlideAction->setEnabled(slide > 0);
940 m_slideshowNextSlideAction->setEnabled(slide < m_view->progressPresSlides->maximum()-1);
942 // live preview and notes
943 m_slideNotes->document()->clear();
944 assert(0 != m_currentPresentation);
945 UpSlide* currentSlide = m_currentPresentation->slide(slide);
946 if (0 != currentSlide)
948 // live preview
949 if (Settings::presLivePreview())
951 m_displayManager->background.setImage(currentSlide->preview());
953 // notes
954 currentSlide->writeNotes(m_slideNotes->document());
958 void kworship::slideshowStepChanged(int step)
960 m_view->progressPresSteps->setValue(step + 1);
962 bool firstSlide = (m_view->progressPresSlides->value() <= 1);
963 bool lastSlide = (m_view->progressPresSlides->value() >= m_view->progressPresSlides->maximum());
964 bool firstStep = firstSlide && (step <= 0);
965 bool lastStep = lastSlide && (step >= m_view->progressPresSteps->maximum() - 1);
966 m_slideshowPrevStepAction->setEnabled(!firstStep);
967 m_slideshowNextStepAction->setEnabled(!lastStep);
970 // Song DB
972 void kworship::songdbUnlock()
974 m_unlockSongDbAction->setVisible(false);
975 m_lockSongDbAction->setVisible(true);
978 void kworship::songdbLock()
980 m_unlockSongDbAction->setVisible(true);
981 m_lockSongDbAction->setVisible(false);
984 void kworship::songdbAdd()
986 KwSongdbSongEditDialog* dialog = new KwSongdbSongEditDialog(0);
987 dialog->setCaption(i18n("Add Song"));
988 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
989 dialog->show();
992 void kworship::songdbEdit()
994 /// @todo Ensure the same song isn't open twice
995 KwSongdbSong* song = m_songDbTree->currentSong();
996 if (0 != song)
998 KwSongdbVersion* version = m_songDbTree->currentSongVersion();
999 // version may be 0
1000 KwSongdbSongEditDialog* dialog = new KwSongdbSongEditDialog(song, version);
1001 dialog->setCaption(i18n("Edit Song - %1", song->name()));
1002 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
1003 dialog->show();
1005 else
1007 KMessageBox::information(this, i18n("Please select a song."));
1011 void kworship::songdbEditSongBooks()
1013 KwSongdbSongBooksEditWidget::showDialog();
1016 #include "kworship.moc"