Tidy up some of songdb actions and put in menus
[kworship.git] / kworship / kworship.cpp
blobce6883e4f4604f6347d3165d7f10eed282a33f9d
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"
59 #include "UpKpr1Backend.h"
60 #include "UpKpr2Backend.h"
61 #include "UpOoBackend.h"
63 #include <kconfigdialog.h>
64 #include <kstatusbar.h>
65 #include <kaction.h>
66 #include <kactionmenu.h>
67 #include <kmenu.h>
68 #include <ktoggleaction.h>
69 #include <kactioncollection.h>
70 #include <kstandardaction.h>
71 #include <KDE/KLocale>
72 #include <KFileDialog>
73 #include <KMessageBox>
75 #include <phonon/audiooutput.h>
77 #include <QtGui/QDropEvent>
78 #include <QtGui/QPainter>
79 #include <QColor>
80 #include <QDesktopWidget>
81 #include <QToolBar>
82 #include <QToolButton>
83 #include <QComboBox>
84 #include <QSqlDatabase>
85 #include <QHeaderView>
86 #include <QTextEdit>
88 kworship::kworship()
89 : KXmlGuiWindow()
90 , m_view(new kworshipView(this))
91 , m_displayManager(0)
92 , m_document(0)
93 , m_presentationManager(new UpManager(this))
94 , m_currentPresentation(0)
95 , m_printer(0)
97 m_playlistModel = new KwPlaylistModel;
98 setDocument();
100 // set up presentation backends
101 m_presentationManager->registerBackend<UpOoBackend>();
102 m_presentationManager->registerBackend<UpKpr2Backend>();
103 m_presentationManager->registerBackend<UpKpr1Backend>();
105 m_mainDisplay = 0;
106 m_previewDisplay = 0;
108 // accept dnd
109 setAcceptDrops(true);
111 // tell the KXmlGuiWindow that this is indeed the main widget
112 setCentralWidget(m_view);
114 // then, setup our actions
115 setupActions();
117 // add a status bar
118 statusBar()->show();
120 // a call to KXmlGuiWindow::setupGUI() populates the GUI
121 // with actions, using KXMLGUI.
122 // It also applies the saved mainwindow settings, if any, and ask the
123 // mainwindow to automatically save settings if changed: window size,
124 // toolbar position, icon size, etc.
125 setupGUI();
127 // Setup the dockers
128 addDockWidget(Qt::LeftDockWidgetArea, m_view->dockPresentation);
129 tabifyDockWidget(m_view->dockPresentation, m_view->dockBible);
130 tabifyDockWidget(m_view->dockPresentation, m_view->dockSongs);
131 addDockWidget(Qt::RightDockWidgetArea, m_view->dockPreview);
132 addDockWidget(Qt::RightDockWidgetArea, m_view->dockLyrics);
133 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockThemes);
134 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockNowPlaying);
136 // Setup some stuff in the tree
137 #if 0
138 #define TREE_ITEM(name, string, parent) QTreeWidgetItem* name = new QTreeWidgetItem(parent); name->setText(0, tr(string));
140 TREE_ITEM(song1, "Our God is a great big God", m_view->treeWidget);
141 TREE_ITEM(song1_style, "(style)", song1);
142 TREE_ITEM(song1_style_1, "Mode", song1_style);
143 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);
144 TREE_ITEM(song1_v2, "He's higher than a skyscraper\nAnd he's deeper than a submarine.", song1);
145 TREE_ITEM(song1_v3, "He's wider than the universe\nAnd beyond my wildest dreams.", song1);
147 #undef TREE_ITEM
148 #endif
150 // Setup song db
152 KwDatabaseSetup dbSetup;
153 bool databaseOk = dbSetup.initialiseFromConfig();
154 if (databaseOk)
156 new KwSongdb(dbSetup.database());
159 // Playlist
160 m_document->playlist()->addClass("beachy");
162 KwCssStyleSheet* styleRules = new KwCssStyleSheet;
164 KwCssStyleRule beachyTheme;
165 beachyTheme.setCriteriaClasses(QSet<QString>() << "beachy");
166 beachyTheme.setStyle<QBrush>("background.brush", Qt::black);
167 beachyTheme.setStyle<QPixmap>("background.image.pixmap", QPixmap("/home/james/media/images/projector/misc/love-god-light.jpg"));
168 styleRules->addRule(beachyTheme);
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();
346 void kworship::setupActions()
348 // Application
349 KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
350 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
352 // File management
353 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
354 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
355 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
356 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
358 // Display
359 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
361 m_mainDisplayAction = new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
362 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction );
363 connect(m_mainDisplayAction, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
365 KAction* clearDisplayAction = new KAction(KIcon("clear"), i18n("Clear display"), this);
366 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction);
367 connect(clearDisplayAction, SIGNAL(triggered()), this, SLOT(displayClear()));
369 // Song database
370 m_unlockSongDbAction = new KAction(KIcon("document-decrypt"), i18n("Unlock Song Database"), this);
371 actionCollection()->addAction( QLatin1String("unlock_song_database"), m_unlockSongDbAction);
372 connect(m_unlockSongDbAction, SIGNAL(triggered(bool)), this, SLOT(songdbUnlock()));
374 m_lockSongDbAction = new KAction(KIcon("document-encrypt"), i18n("Lock Song Database"), this);
375 m_lockSongDbAction->setVisible(false);
376 actionCollection()->addAction( QLatin1String("lock_song_database"), m_lockSongDbAction);
377 connect(m_lockSongDbAction, SIGNAL(triggered(bool)), this, SLOT(songdbLock()));
379 m_groupSongsByAction = new KActionMenu(KIcon("view-filter"), i18n("Group By"), this);
380 m_groupSongsByAction->setDelayed(false);
381 actionCollection()->addAction( QLatin1String("group_songs_by"), m_groupSongsByAction);
383 m_addSongAction = new KAction(KIcon("list-add"), i18n("Add Song"), this);
384 actionCollection()->addAction( QLatin1String("add_song"), m_addSongAction);
385 connect(m_addSongAction, SIGNAL(triggered(bool)), this, SLOT(songdbAdd()));
387 m_editSongAction = new KAction(KIcon("view-media-lyrics"), i18n("Edit Song"), this);
388 actionCollection()->addAction( QLatin1String("edit_song"), m_editSongAction);
389 connect(m_editSongAction, SIGNAL(triggered(bool)), this, SLOT(songdbEdit()));
391 m_editSongBooksAction = new KAction(KIcon("format-list-ordered"), i18n("Edit Song Books"), this);
392 actionCollection()->addAction( QLatin1String("edit_song_books"), m_editSongBooksAction);
393 connect(m_editSongBooksAction, SIGNAL(triggered(bool)), this, SLOT(songdbEditSongBooks()));
396 void kworship::settingsChanged()
398 // If the main display is on and screen has changed, move it now
399 if (0 != m_mainDisplay && getCorrectDisplayScreen() != getCurrentDisplayScreen())
401 toggleMainDisplay(false);
402 toggleMainDisplay(true);
403 m_mainDisplayAction->setChecked(true);
407 int kworship::getCorrectDisplayScreen()
409 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
410 assert(0 != desktop);
412 int screens = desktop->numScreens();
413 int displayScreen = -1;
414 if (Settings::displayScreenChoose())
416 displayScreen = Settings::displayScreen();
418 if (-1 == displayScreen)
420 int currentScreen;
421 if (m_view->isVisible())
423 currentScreen = desktop->screenNumber(m_view);
425 else
427 currentScreen = desktop->primaryScreen();
429 displayScreen = 0;
430 if (displayScreen == currentScreen && displayScreen < screens-1)
432 ++displayScreen;
436 return displayScreen;
439 int kworship::getCurrentDisplayScreen()
441 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
442 assert(0 != desktop);
444 int previousScreen = desktop->screenNumber(m_mainDisplay);
446 return previousScreen;
449 void kworship::toggleMainDisplay(bool checked)
451 if (checked)
453 // Ensure the display exists
454 if (0 == m_mainDisplay)
456 m_mainDisplay = new KwLocalDisplay;
457 m_mainDisplay->setPrimary(true);
458 m_mainDisplay->setWindowTitle("kworship display");
459 m_displayController.attachChild(m_mainDisplay);
460 connect(m_mainDisplay, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
463 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
464 assert(0 != desktop);
466 int screens = desktop->numScreens();
467 int displayScreen = getCorrectDisplayScreen();
469 if (displayScreen >= 0 && displayScreen < screens)
471 m_mainDisplay->move(desktop->screenGeometry(displayScreen).topLeft());
474 if (!m_slideshowAction->isChecked())
476 m_mainDisplay->showFullScreen();
479 else
481 if (0 != m_mainDisplay)
483 m_mainDisplay->close();
488 void kworship::mainDisplayClosed()
490 m_mainDisplay->deleteLater();
491 m_mainDisplay = 0;
492 m_mainDisplayAction->setChecked(false);
495 void kworship::displayClear()
497 m_displayManager->background.clear();
498 m_displayManager->text.clear();
501 void kworship::toggleFullscreen(bool checked)
503 if (checked)
505 showFullScreen();
507 else
509 showNormal();
513 bool kworship::askToSave()
515 if (m_document->isModified())
517 switch (KMessageBox::questionYesNoCancel(this,
518 i18n("The current playlist has been modified. "
519 "These modifications will be lost if you continue without saving. "
520 "Would you like to save now?"),
521 i18n("Playlist is modified")))
523 case KMessageBox::Yes:
525 fileSave();
526 // If the document is still modified, save must have been cancelled
527 if (m_document->isModified())
529 return false;
532 break;
533 case KMessageBox::No:
534 break;
535 case KMessageBox::Cancel:
536 default:
538 return false;
540 break;
543 return true;
546 void kworship::fileNew()
548 if (askToSave())
550 setDocument();
554 void kworship::fileOpen()
556 if (askToSave())
558 // Do the open operation
559 QString filter = "*.kwz *.kw|" + i18n("All KWorship playlists");
560 KUrl defaultUrl("kfiledialog:///playlist");
561 if (m_document->isSaved())
563 defaultUrl = m_document->url();
565 KUrl url = KFileDialog::getOpenUrl(defaultUrl, filter, this);
566 if (!url.isEmpty())
568 loadPlaylist(url);
573 void kworship::fileSave()
575 if (m_document->isSaved())
577 m_document->save();
579 else
581 fileSaveAs();
585 void kworship::fileSaveAs()
587 QString filter = "*.kwz|" + i18n("KWorship playlists") + "\n"
588 "*.kw|" + i18n("KWorship uncompressed playlists");
589 KUrl defaultUrl("kfiledialog:///playlist");
590 if (m_document->isSaved())
592 defaultUrl = m_document->url();
594 KUrl url = KFileDialog::getSaveUrl(defaultUrl, filter, this);
595 if (!url.isEmpty())
597 m_document->saveAs(url);
601 void kworship::optionsPreferences()
603 //avoid to have 2 dialogs shown
604 if ( KConfigDialog::showDialog( "settings" ) ) {
605 return;
607 KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
609 QWidget *generalSettingsDlg = new QWidget(dialog);
610 ui_prefs_base.setupUi(generalSettingsDlg);
611 dialog->addPage(generalSettingsDlg, i18n("General"), "preferences-other", i18n("General"));
613 prefsDisplay *displaySettingsDlg = new prefsDisplay(dialog);
614 dialog->addPage(displaySettingsDlg, i18n("Display"), "video-projector", i18n("Display and Screen"));
616 prefsSongDB *songdbSettingsDlg = new prefsSongDB(dialog);
617 dialog->addPage(songdbSettingsDlg, i18n("Song DB"), "applications-multimedia", i18n("Song Database"));
619 QWidget *presentationSettingsDlg = new QWidget(dialog);
620 ui_prefsPresentations_base.setupUi(presentationSettingsDlg);
621 dialog->addPage(presentationSettingsDlg, i18n("Presentations"), "view-presentation", i18n("Presentations and Slideshows"));
623 connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
624 connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(settingsChanged()));
625 dialog->setAttribute( Qt::WA_DeleteOnClose );
626 dialog->show();
629 void kworship::playlist_doubleClicked(QModelIndex index)
631 KwPlaylistNode* node = m_playlistModel->itemFromIndex(index);
632 node->activate(m_displayManager);
635 void kworship::playlistReset()
637 // Connect up the new document
638 m_playlistModel->setRootNode(m_document->playlist()->getNode(0));
641 void kworship::presentationDelete()
643 setPresentation(0, true);
644 presentationSelected(0);
647 void kworship::presentationSelected(int)
649 // Find the treeviews current index
650 QModelIndex index = m_selectPresTree->currentIndex();
651 UpPresentationsModel* model = m_presentationManager->presentationsModel();
652 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
653 if (0 != presNode)
655 m_view->listSlides->setModel(model);
656 m_view->listSlides->setRootIndex(index);
657 setPresentation(presNode->getItem());
659 else
661 m_view->listSlides->setModel(0);
662 setPresentation(0);
666 void kworship::presentationToggled(bool checked)
668 // Find the treeviews current index
669 QModelIndex index = m_selectPresTree->currentIndex();
670 UpPresentationsModel* model = m_presentationManager->presentationsModel();
671 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
672 if (0 != presNode)
674 if (checked)
676 presNode->getItem()->startSlideshow();
678 else
680 presNode->getItem()->stopSlideshow();
685 void kworship::presentationPreviousSlide()
687 // Find the treeviews current index
688 QModelIndex index = m_selectPresTree->currentIndex();
689 UpPresentationsModel* model = m_presentationManager->presentationsModel();
690 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
691 if (0 != presNode)
693 presNode->getItem()->previousSlide();
697 void kworship::presentationNextSlide()
699 // Find the treeviews current index
700 QModelIndex index = m_selectPresTree->currentIndex();
701 UpPresentationsModel* model = m_presentationManager->presentationsModel();
702 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
703 if (0 != presNode)
705 presNode->getItem()->nextSlide();
709 void kworship::presentationPreviousStep()
711 // Find the treeviews current index
712 QModelIndex index = m_selectPresTree->currentIndex();
713 UpPresentationsModel* model = m_presentationManager->presentationsModel();
714 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
715 if (0 != presNode)
717 presNode->getItem()->previousStep();
721 void kworship::presentationNextStep()
723 // Find the treeviews current index
724 QModelIndex index = m_selectPresTree->currentIndex();
725 UpPresentationsModel* model = m_presentationManager->presentationsModel();
726 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
727 if (0 != presNode)
729 presNode->getItem()->nextStep();
733 void kworship::slide_doubleClicked(QModelIndex index)
735 // Find the listviews current index
736 UpPresentationsModel* model = m_presentationManager->presentationsModel();
737 QModelIndex parentIndex = model->parent(index);
738 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(parentIndex));
739 if (0 != presNode)
741 presNode->getItem()->goToSlide(index.row());
745 // Documents
746 void kworship::setDocument(KUrl url)
748 delete m_document;
749 m_document = new KwDocument(url, this);
751 // Playlist will have changed
752 playlistReset();
754 // Wire up signals
755 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
758 // Presentations
759 void kworship::setPresentation(UpPresentation* presentation, bool alreadyDestroyed)
761 if (0 != m_currentPresentation)
763 // Stop the slideshow if its running
764 m_view->slideshows->setVisible(false);
765 if (!alreadyDestroyed)
767 m_currentPresentation->stopSlideshow();
768 disconnect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
769 disconnect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
770 disconnect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
771 disconnect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
772 disconnect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
773 disconnect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
774 disconnect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
776 slideshowStopped();
778 m_currentPresentation = presentation;
779 if (0 != m_currentPresentation)
781 connect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
782 connect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
783 connect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
784 connect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
785 connect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
786 connect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
787 connect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
788 // update slideshows list
789 refreshSlideshows();
790 m_view->slideshows->setVisible(true);
792 if (m_currentPresentation->isSlideshowRunning())
794 slideshowStarted(m_currentPresentation->numSlidesInSlideshow());
795 slideshowSlideChanged(m_currentPresentation->currentSlideshowSlide(), m_currentPresentation->stepsInCurrentSlideshowSlide());
796 slideshowStepChanged(m_currentPresentation->currentSlideshowStep());
799 m_slideshowAction->setEnabled(0 != m_currentPresentation);
802 // Custom slideshows
804 void kworship::presentationComboReset()
806 m_selectPresTree->expandToDepth(0);
807 m_selectPresTree->setItemsExpandable(false);
810 void kworship::changeSlideshowCombo(QString name)
812 Q_ASSERT(0 != m_currentPresentation);
813 m_currentPresentation->setSlideshow(name);
814 refreshSlides();
817 void kworship::changeSlideshowExternal(QString name)
819 if (m_view->comboSlideshows->currentText() != name)
821 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(name));
822 refreshSlides();
826 void kworship::refreshSlideshows()
828 Q_ASSERT(0 != m_currentPresentation);
829 m_view->comboSlideshows->clear();
830 m_view->comboSlideshows->insertItems(0, m_currentPresentation->slideshows());
831 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(m_currentPresentation->currentSlideshow()));
834 void kworship::refreshSlides()
836 // Clear child cache
837 QModelIndex root = m_view->listSlides->rootIndex();
838 DefaultModelNode* node = m_presentationManager->presentationsModel()->itemFromIndex(root);
839 Q_ASSERT(0 != node);
840 node->clearChildCache();
842 // Force a refresh
843 m_view->listSlides->setRootIndex(root);
846 void kworship::addSlideshowLinkToPlaylist()
848 Q_ASSERT(0 != m_currentPresentation);
849 QUrl url = m_currentPresentation->url();
850 QString slideshow = m_currentPresentation->currentSlideshow();
851 /// @todo Implement me
853 void kworship::addSlideshowCopyToPlaylist()
855 Q_ASSERT(0 != m_currentPresentation);
856 QString slideshow = m_currentPresentation->currentSlideshow();
857 /// @todo Implement me
860 // From current presentation
862 void kworship::slideshowStarted(int numSlides)
864 // Hide the screen
865 if (0 != m_mainDisplay)
867 m_mainDisplay->hide();
870 // Clear the display
871 m_displayManager->background.clear();
872 m_displayManager->text.clear();
874 m_view->slideshows->setEnabled(false);
875 m_view->progressPresSlides->setMaximum(numSlides);
876 m_view->progressPresSlides->setVisible(true);
877 m_slideshowAction->setChecked(true);
880 void kworship::slideshowStopped()
882 m_view->slideshows->setEnabled(true);
883 m_view->progressPresSlides->setVisible(false);
884 m_view->progressPresSteps->setVisible(false);
885 m_slideshowAction->setChecked(false);
886 m_slideshowPrevSlideAction->setEnabled(false);
887 m_slideshowPrevStepAction->setEnabled(false);
888 m_slideshowNextStepAction->setEnabled(false);
889 m_slideshowNextSlideAction->setEnabled(false);
891 // Clear any preview left from the slideshow
892 m_displayManager->background.clear();
893 // Clear slide notes
894 m_slideNotes->document()->clear();
896 // Show the screen again
897 if (0 != m_mainDisplay)
899 m_mainDisplay->showFullScreen();
903 void kworship::slideshowSlideChanged(int slide, int numSteps)
905 m_view->progressPresSlides->setValue(slide + 1);
906 m_view->progressPresSteps->setMaximum(numSteps);
907 m_view->progressPresSteps->setVisible(numSteps > 1);
909 m_slideshowPrevSlideAction->setEnabled(slide > 0);
910 m_slideshowNextSlideAction->setEnabled(slide < m_view->progressPresSlides->maximum()-1);
912 // live preview and notes
913 m_slideNotes->document()->clear();
914 assert(0 != m_currentPresentation);
915 UpSlide* currentSlide = m_currentPresentation->slide(slide);
916 if (0 != currentSlide)
918 // live preview
919 if (Settings::presLivePreview())
921 m_displayManager->background.setImage(currentSlide->preview());
923 // notes
924 currentSlide->writeNotes(m_slideNotes->document());
928 void kworship::slideshowStepChanged(int step)
930 m_view->progressPresSteps->setValue(step + 1);
932 bool firstSlide = (m_view->progressPresSlides->value() <= 1);
933 bool lastSlide = (m_view->progressPresSlides->value() >= m_view->progressPresSlides->maximum());
934 bool firstStep = firstSlide && (step <= 0);
935 bool lastStep = lastSlide && (step >= m_view->progressPresSteps->maximum() - 1);
936 m_slideshowPrevStepAction->setEnabled(!firstStep);
937 m_slideshowNextStepAction->setEnabled(!lastStep);
940 // Song DB
942 void kworship::songdbUnlock()
944 m_unlockSongDbAction->setVisible(false);
945 m_lockSongDbAction->setVisible(true);
948 void kworship::songdbLock()
950 m_unlockSongDbAction->setVisible(true);
951 m_lockSongDbAction->setVisible(false);
954 void kworship::songdbAdd()
956 KwSongdbSongEditDialog* dialog = new KwSongdbSongEditDialog(0);
957 dialog->setCaption(i18n("Add Song"));
958 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
959 dialog->show();
962 void kworship::songdbEdit()
964 /// @todo Ensure the same song isn't open twice
965 KwSongdbSong* song = m_songDbTree->currentSong();
966 if (0 != song)
968 KwSongdbVersion* version = m_songDbTree->currentSongVersion();
969 // version may be 0
970 KwSongdbSongEditDialog* dialog = new KwSongdbSongEditDialog(song, version);
971 dialog->setCaption(i18n("Edit Song - %1", song->name()));
972 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
973 dialog->show();
975 else
977 KMessageBox::information(this, i18n("Please select a song."));
981 void kworship::songdbEditSongBooks()
983 KwSongdbSongBooksEditWidget::showDialog();
986 #include "kworship.moc"