More definition of bible module structure
[kworship.git] / kworship / kworship.cpp
blobd7b6adc090d19391083ad36a52fc7da1f305f276
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 "KwBibleManager.h"
47 #include "KwBibleModule.h"
49 #include "KwSongdb.h"
50 #include "KwSongdbModel.h"
51 #include "KwSongdbFilterNode.h"
52 #include "KwSongdbTree.h"
53 #include "KwSongdbSong.h"
54 #include "KwSongdbSongEditDialog.h"
55 #include "KwSongdbSongBooksEditWidget.h"
57 #include "UpManager.h"
58 #include "UpPresentationsModel.h"
59 #include "UpPresentation.h"
60 #include "UpPresentationNode.h"
61 #include "UpSlide.h"
62 #include "UpKpr1Backend.h"
63 #include "UpKpr2Backend.h"
64 #include "UpOoBackend.h"
66 #include <kconfigdialog.h>
67 #include <kstatusbar.h>
68 #include <kaction.h>
69 #include <kactionmenu.h>
70 #include <kmenu.h>
71 #include <ktoggleaction.h>
72 #include <kactioncollection.h>
73 #include <kstandardaction.h>
74 #include <KDE/KLocale>
75 #include <KFileDialog>
76 #include <KMessageBox>
78 #include <phonon/audiooutput.h>
80 #include <QtGui/QDropEvent>
81 #include <QtGui/QPainter>
82 #include <QColor>
83 #include <QDesktopWidget>
84 #include <QToolBar>
85 #include <QToolButton>
86 #include <QComboBox>
87 #include <QSqlDatabase>
88 #include <QHeaderView>
89 #include <QTextEdit>
91 kworship::kworship()
92 : KXmlGuiWindow()
93 , m_view(new kworshipView(this))
94 , m_displayManager(0)
95 , m_document(0)
96 , m_presentationManager(new UpManager(this))
97 , m_currentPresentation(0)
98 , m_printer(0)
100 m_playlistModel = new KwPlaylistModel;
101 setDocument();
103 // set up presentation backends
104 m_presentationManager->registerBackend<UpOoBackend>();
105 m_presentationManager->registerBackend<UpKpr2Backend>();
106 m_presentationManager->registerBackend<UpKpr1Backend>();
108 m_mainDisplay = 0;
109 m_previewDisplay = 0;
111 // accept dnd
112 setAcceptDrops(true);
114 // tell the KXmlGuiWindow that this is indeed the main widget
115 setCentralWidget(m_view);
117 // then, setup our actions
118 setupActions();
120 // add a status bar
121 statusBar()->show();
123 // a call to KXmlGuiWindow::setupGUI() populates the GUI
124 // with actions, using KXMLGUI.
125 // It also applies the saved mainwindow settings, if any, and ask the
126 // mainwindow to automatically save settings if changed: window size,
127 // toolbar position, icon size, etc.
128 setupGUI();
130 // Setup the dockers
131 addDockWidget(Qt::LeftDockWidgetArea, m_view->dockPresentation);
132 tabifyDockWidget(m_view->dockPresentation, m_view->dockBible);
133 tabifyDockWidget(m_view->dockPresentation, m_view->dockSongs);
134 addDockWidget(Qt::RightDockWidgetArea, m_view->dockPreview);
135 addDockWidget(Qt::RightDockWidgetArea, m_view->dockLyrics);
136 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockThemes);
137 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockNowPlaying);
139 // Setup some stuff in the tree
140 #if 0
141 #define TREE_ITEM(name, string, parent) QTreeWidgetItem* name = new QTreeWidgetItem(parent); name->setText(0, tr(string));
143 TREE_ITEM(song1, "Our God is a great big God", m_view->treeWidget);
144 TREE_ITEM(song1_style, "(style)", song1);
145 TREE_ITEM(song1_style_1, "Mode", song1_style);
146 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);
147 TREE_ITEM(song1_v2, "He's higher than a skyscraper\nAnd he's deeper than a submarine.", song1);
148 TREE_ITEM(song1_v3, "He's wider than the universe\nAnd beyond my wildest dreams.", song1);
150 #undef TREE_ITEM
151 #endif
153 // Setup song db
155 KwDatabaseSetup dbSetup;
156 bool databaseOk = dbSetup.initialiseFromConfig();
157 if (databaseOk)
159 new KwSongdb(dbSetup.database());
162 // Playlist
163 m_document->playlist()->addClass("beachy");
165 KwCssStyleSheet* styleRules = new KwCssStyleSheet;
167 KwCssStyleRule beachyTheme;
168 beachyTheme.setCriteriaClasses(QSet<QString>() << "beachy");
169 beachyTheme.setStyle<QBrush>("background.brush", Qt::black);
170 beachyTheme.setStyle<QPixmap>("background.image.pixmap", QPixmap("/home/james/media/images/projector/misc/love-god-light.jpg"));
171 styleRules->addRule(beachyTheme);
173 m_document->playlist()->addStyleSheet(styleRules);
175 m_view->treePlaylist->setModel(m_playlistModel);
176 m_view->treePlaylist->setExpandsOnDoubleClick(false);
177 m_view->treePlaylist->setAcceptDrops(true);
179 connect(m_view->treePlaylist, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(playlist_doubleClicked(QModelIndex)));
181 m_mediaManager = new KwMediaManager();
182 m_mediaManager->linkAudio(new Phonon::AudioOutput(Phonon::MusicCategory));
183 m_displayManager = new KwDisplayManager(&m_displayController, m_mediaManager);
185 m_previewDisplay = new KwLocalDisplayPreview;
186 m_view->layoutPreview->addWidget(m_previewDisplay);
187 m_displayController.attachChild(m_previewDisplay);
189 KwMediaControlWidget* mediaWidget = new KwMediaControlWidget(m_mediaManager, m_view->dockNowPlaying);
190 m_view->layoutNowPlaying->addWidget(mediaWidget);
192 // Small toolbar for group by action
193 QToolBar* songTextToolBar = new QToolBar("Songs");
194 songTextToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
195 songTextToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
196 m_view->layoutSongsToolbar->layout()->addWidget(songTextToolBar);
198 songTextToolBar->addAction(m_groupSongsByAction);
200 // Rest of the toolbar
201 QToolBar* songToolBar = new QToolBar("Songs");
202 songToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
203 m_view->layoutSongsToolbar->layout()->addWidget(songToolBar);
205 songToolBar->addAction(m_addSongAction);
206 songToolBar->addAction(m_editSongAction);
207 songToolBar->addAction(m_editSongBooksAction);
208 KAction* insertIntoPlaylistAction = new KAction(KIcon("player_playlist"), i18n("Insert Into Playlist"), songToolBar);
209 songToolBar->addAction(insertIntoPlaylistAction);
211 KMenu* groupByMenu = new KMenu(songToolBar);
212 m_groupSongsByAction->setMenu(groupByMenu);
214 if (databaseOk)
216 m_songDbTree = new KwSongdbTree(m_view);
217 m_view->layoutSongsTree->addWidget(m_songDbTree);
218 groupByMenu->addActions(m_songDbTree->groupByActions()->actions());
223 * Presentation
226 // Drop down list of presentations
227 QComboBox* selectPresCombo = m_view->comboPresentations;
228 m_selectPresTree = new QTreeView(this);
229 m_selectPresTree->header()->hide();
230 selectPresCombo->setModel(m_presentationManager->presentationsModel());
231 selectPresCombo->setView(m_selectPresTree);
232 presentationComboReset();
233 connect(m_presentationManager->presentationsModel(), SIGNAL(modelReset()), this, SLOT(presentationComboReset()));
234 connect(selectPresCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(presentationSelected(int)));
236 // Custom slideshow selector
237 m_view->slideshows->setVisible(false);
238 connect(m_view->comboSlideshows, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(changeSlideshowCombo(QString)));
240 QToolBar* customSlideshowsToolBar = new QToolBar(i18n("Custom Slideshows"));
241 customSlideshowsToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
242 m_view->slideshows->layout()->addWidget(customSlideshowsToolBar);
243 // Add slideshow to playlist
244 KActionMenu* addSlideshowToPlaylistAction = new KActionMenu(KIcon("list-add"), i18n("Add Slideshow to Playlist"), customSlideshowsToolBar);
245 addSlideshowToPlaylistAction->setDelayed(false);
246 customSlideshowsToolBar->addAction(addSlideshowToPlaylistAction);
248 KAction* asLinkAction = new KAction(KIcon("insert-link"), i18n("Add Link to Slideshow into Playlist"), customSlideshowsToolBar);
249 connect(asLinkAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowLinkToPlaylist()));
250 addSlideshowToPlaylistAction->addAction(asLinkAction);
253 KAction* asCopyAction = new KAction(KIcon("edit-copy"), i18n("Save Copy of Slideshow into Playlist"), customSlideshowsToolBar);
254 connect(asCopyAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowCopyToPlaylist()));
255 addSlideshowToPlaylistAction->addAction(asCopyAction);
258 // Presentations toolbar
259 QToolBar* presToolBar = new QToolBar("Presentations");
260 m_view->layoutPresentationsToolbar->layout()->addWidget(presToolBar);
262 KActionMenu* openPresAction = new KActionMenu(KIcon("document-open"), "Open Presentation", presToolBar);
263 openPresAction->setDelayed(true);
264 presToolBar->addAction(openPresAction);
266 KAction* refreshPresAction = new KAction(KIcon("view-refresh"), "Refresh Presentation List", presToolBar);
267 presToolBar->addAction(refreshPresAction);
269 KAction* closePresAction = new KAction(KIcon("fileclose"), "Close Presentation", presToolBar);
270 presToolBar->addAction(closePresAction);
272 KToggleAction* fullscreenPresAction = new KToggleAction(KIcon("view-fullscreen"), "Fullscreen Presentation Mode", presToolBar);
273 presToolBar->addAction(fullscreenPresAction);
275 // Slide list
276 connect(m_view->listSlides, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slide_doubleClicked(QModelIndex)));
278 // Slides toolbar
279 QToolBar* slidesToolBar = new QToolBar("Slides");
280 slidesToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
281 slidesToolBar->setIconSize(QSize(32,32));
282 m_view->layoutSlidesToolbar->layout()->addWidget(slidesToolBar);
284 m_slideshowPrevSlideAction = new KAction(KIcon("media-skip-backward"), i18n("Previous Slide"), slidesToolBar);
285 connect(m_slideshowPrevSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousSlide()));
286 slidesToolBar->addAction(m_slideshowPrevSlideAction);
288 m_slideshowPrevStepAction = new KAction(KIcon("media-seek-backward"), i18n("Previous Step"), slidesToolBar);
289 connect(m_slideshowPrevStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousStep()));
290 slidesToolBar->addAction(m_slideshowPrevStepAction);
292 m_slideshowNextStepAction = new KAction(KIcon("media-seek-forward"), i18n("Next Step"), slidesToolBar);
293 connect(m_slideshowNextStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextStep()));
294 slidesToolBar->addAction(m_slideshowNextStepAction);
296 m_slideshowNextSlideAction = new KAction(KIcon("media-skip-forward"), i18n("Next Slide"), slidesToolBar);
297 connect(m_slideshowNextSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextSlide()));
298 slidesToolBar->addAction(m_slideshowNextSlideAction);
300 m_slideshowAction = new KToggleAction(KIcon("view-presentation"), i18n("Start/Stop Slideshow"), slidesToolBar);
301 connect(m_slideshowAction, SIGNAL(toggled(bool)), this, SLOT(presentationToggled(bool)));
302 slidesToolBar->addAction(m_slideshowAction);
304 // Slide notes
305 m_slideNotes = new QTextEdit();
306 m_slideNotes->setReadOnly(true);
307 m_slideNotes->setWindowTitle(i18n("Slide Notes"));
308 m_slideNotes->show();
310 // Ensure the controls are as when slideshow is stopped
311 m_slideshowAction->setEnabled(false);
312 slideshowStopped();
315 * Display startup
318 // Show the display on startup?
319 if (Settings::displayShowStartup())
321 // If there's only one screen, don't bother showing display.
322 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
323 assert(0 != desktop);
324 if (desktop->numScreens() > 1)
326 toggleMainDisplay(true);
327 m_mainDisplayAction->setChecked(true);
331 // Fill list of bibles
332 KwBibleManager* manager = KwBibleManager::self();
333 QList<KwBibleModule*> modules = manager->modules();
334 foreach (KwBibleModule* module, modules)
336 m_view->comboSwordBibles->addItem(i18n("%1 - %2", module->name(), module->description()), QVariant(module->name()));
339 connect(m_view->comboSwordBibles, SIGNAL(currentIndexChanged(int)),
340 this, SLOT(bibleSearch()));
341 connect(m_view->searchBible, SIGNAL(textEdited(const QString&)),
342 this, SLOT(bibleSearch()));
345 kworship::~kworship()
347 delete KwSongdb::self();
348 delete m_slideNotes;
352 * Public interface
355 /// Load a specified playlist.
356 void kworship::loadPlaylist(const KUrl& url)
358 setDocument(url);
359 m_document->reload();
362 void kworship::setupActions()
364 // Application
365 KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
366 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
368 // File management
369 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
370 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
371 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
372 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
374 // Display
375 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
377 m_mainDisplayAction = new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
378 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction );
379 connect(m_mainDisplayAction, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
381 KAction* clearDisplayAction = new KAction(KIcon("clear"), i18n("Clear display"), this);
382 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction);
383 connect(clearDisplayAction, SIGNAL(triggered()), this, SLOT(displayClear()));
385 // Song database
386 m_unlockSongDbAction = new KAction(KIcon("document-decrypt"), i18n("Unlock Song Database"), this);
387 actionCollection()->addAction( QLatin1String("unlock_song_database"), m_unlockSongDbAction);
388 connect(m_unlockSongDbAction, SIGNAL(triggered(bool)), this, SLOT(songdbUnlock()));
390 m_lockSongDbAction = new KAction(KIcon("document-encrypt"), i18n("Lock Song Database"), this);
391 m_lockSongDbAction->setVisible(false);
392 actionCollection()->addAction( QLatin1String("lock_song_database"), m_lockSongDbAction);
393 connect(m_lockSongDbAction, SIGNAL(triggered(bool)), this, SLOT(songdbLock()));
395 m_groupSongsByAction = new KActionMenu(KIcon("view-filter"), i18n("Group By"), this);
396 m_groupSongsByAction->setDelayed(false);
397 actionCollection()->addAction( QLatin1String("group_songs_by"), m_groupSongsByAction);
399 m_addSongAction = new KAction(KIcon("list-add"), i18n("Add Song"), this);
400 actionCollection()->addAction( QLatin1String("add_song"), m_addSongAction);
401 connect(m_addSongAction, SIGNAL(triggered(bool)), this, SLOT(songdbAdd()));
403 m_editSongAction = new KAction(KIcon("view-media-lyrics"), i18n("Edit Song"), this);
404 actionCollection()->addAction( QLatin1String("edit_song"), m_editSongAction);
405 connect(m_editSongAction, SIGNAL(triggered(bool)), this, SLOT(songdbEdit()));
407 m_editSongBooksAction = new KAction(KIcon("format-list-ordered"), i18n("Edit Song Books"), this);
408 actionCollection()->addAction( QLatin1String("edit_song_books"), m_editSongBooksAction);
409 connect(m_editSongBooksAction, SIGNAL(triggered(bool)), this, SLOT(songdbEditSongBooks()));
412 void kworship::settingsChanged()
414 // If the main display is on and screen has changed, move it now
415 if (0 != m_mainDisplay && getCorrectDisplayScreen() != getCurrentDisplayScreen())
417 toggleMainDisplay(false);
418 toggleMainDisplay(true);
419 m_mainDisplayAction->setChecked(true);
423 int kworship::getCorrectDisplayScreen()
425 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
426 assert(0 != desktop);
428 int screens = desktop->numScreens();
429 int displayScreen = -1;
430 if (Settings::displayScreenChoose())
432 displayScreen = Settings::displayScreen();
434 if (-1 == displayScreen)
436 int currentScreen;
437 if (m_view->isVisible())
439 currentScreen = desktop->screenNumber(m_view);
441 else
443 currentScreen = desktop->primaryScreen();
445 displayScreen = 0;
446 if (displayScreen == currentScreen && displayScreen < screens-1)
448 ++displayScreen;
452 return displayScreen;
455 int kworship::getCurrentDisplayScreen()
457 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
458 assert(0 != desktop);
460 int previousScreen = desktop->screenNumber(m_mainDisplay);
462 return previousScreen;
465 void kworship::toggleMainDisplay(bool checked)
467 if (checked)
469 // Ensure the display exists
470 if (0 == m_mainDisplay)
472 m_mainDisplay = new KwLocalDisplay;
473 m_mainDisplay->setPrimary(true);
474 m_mainDisplay->setWindowTitle("kworship display");
475 m_displayController.attachChild(m_mainDisplay);
476 connect(m_mainDisplay, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
479 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
480 assert(0 != desktop);
482 int screens = desktop->numScreens();
483 int displayScreen = getCorrectDisplayScreen();
485 if (displayScreen >= 0 && displayScreen < screens)
487 m_mainDisplay->move(desktop->screenGeometry(displayScreen).topLeft());
490 if (!m_slideshowAction->isChecked())
492 m_mainDisplay->showFullScreen();
495 else
497 if (0 != m_mainDisplay)
499 m_mainDisplay->close();
504 void kworship::mainDisplayClosed()
506 m_mainDisplay->deleteLater();
507 m_mainDisplay = 0;
508 m_mainDisplayAction->setChecked(false);
511 void kworship::displayClear()
513 m_displayManager->background.clear();
514 m_displayManager->text.clear();
517 void kworship::toggleFullscreen(bool checked)
519 if (checked)
521 showFullScreen();
523 else
525 showNormal();
529 bool kworship::askToSave()
531 if (m_document->isModified())
533 switch (KMessageBox::questionYesNoCancel(this,
534 i18n("The current playlist has been modified. "
535 "These modifications will be lost if you continue without saving. "
536 "Would you like to save now?"),
537 i18n("Playlist is modified")))
539 case KMessageBox::Yes:
541 fileSave();
542 // If the document is still modified, save must have been cancelled
543 if (m_document->isModified())
545 return false;
548 break;
549 case KMessageBox::No:
550 break;
551 case KMessageBox::Cancel:
552 default:
554 return false;
556 break;
559 return true;
562 void kworship::fileNew()
564 if (askToSave())
566 setDocument();
570 void kworship::fileOpen()
572 if (askToSave())
574 // Do the open operation
575 QString filter = "*.kwz *.kw|" + i18n("All KWorship playlists");
576 KUrl defaultUrl("kfiledialog:///playlist");
577 if (m_document->isSaved())
579 defaultUrl = m_document->url();
581 KUrl url = KFileDialog::getOpenUrl(defaultUrl, filter, this);
582 if (!url.isEmpty())
584 loadPlaylist(url);
589 void kworship::fileSave()
591 if (m_document->isSaved())
593 m_document->save();
595 else
597 fileSaveAs();
601 void kworship::fileSaveAs()
603 QString filter = "*.kwz|" + i18n("KWorship playlists") + "\n"
604 "*.kw|" + i18n("KWorship uncompressed playlists");
605 KUrl defaultUrl("kfiledialog:///playlist");
606 if (m_document->isSaved())
608 defaultUrl = m_document->url();
610 KUrl url = KFileDialog::getSaveUrl(defaultUrl, filter, this);
611 if (!url.isEmpty())
613 m_document->saveAs(url);
617 void kworship::optionsPreferences()
619 //avoid to have 2 dialogs shown
620 if ( KConfigDialog::showDialog( "settings" ) ) {
621 return;
623 KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
625 QWidget *generalSettingsDlg = new QWidget(dialog);
626 ui_prefs_base.setupUi(generalSettingsDlg);
627 dialog->addPage(generalSettingsDlg, i18n("General"), "preferences-other", i18n("General"));
629 prefsDisplay *displaySettingsDlg = new prefsDisplay(dialog);
630 dialog->addPage(displaySettingsDlg, i18n("Display"), "video-projector", i18n("Display and Screen"));
632 prefsSongDB *songdbSettingsDlg = new prefsSongDB(dialog);
633 dialog->addPage(songdbSettingsDlg, i18n("Song DB"), "applications-multimedia", i18n("Song Database"));
635 QWidget *presentationSettingsDlg = new QWidget(dialog);
636 ui_prefsPresentations_base.setupUi(presentationSettingsDlg);
637 dialog->addPage(presentationSettingsDlg, i18n("Presentations"), "view-presentation", i18n("Presentations and Slideshows"));
639 connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
640 connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(settingsChanged()));
641 dialog->setAttribute( Qt::WA_DeleteOnClose );
642 dialog->show();
645 void kworship::playlist_doubleClicked(QModelIndex index)
647 KwPlaylistNode* node = m_playlistModel->itemFromIndex(index);
648 node->activate(m_displayManager);
651 void kworship::playlistReset()
653 // Connect up the new document
654 m_playlistModel->setRootNode(m_document->playlist()->getNode(0));
657 void kworship::presentationDelete()
659 setPresentation(0, true);
660 presentationSelected(0);
663 void kworship::presentationSelected(int)
665 // Find the treeviews current index
666 QModelIndex index = m_selectPresTree->currentIndex();
667 UpPresentationsModel* model = m_presentationManager->presentationsModel();
668 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
669 if (0 != presNode)
671 m_view->listSlides->setModel(model);
672 m_view->listSlides->setRootIndex(index);
673 setPresentation(presNode->getItem());
675 else
677 m_view->listSlides->setModel(0);
678 setPresentation(0);
682 void kworship::presentationToggled(bool checked)
684 // Find the treeviews current index
685 QModelIndex index = m_selectPresTree->currentIndex();
686 UpPresentationsModel* model = m_presentationManager->presentationsModel();
687 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
688 if (0 != presNode)
690 if (checked)
692 presNode->getItem()->startSlideshow();
694 else
696 presNode->getItem()->stopSlideshow();
701 void kworship::presentationPreviousSlide()
703 // Find the treeviews current index
704 QModelIndex index = m_selectPresTree->currentIndex();
705 UpPresentationsModel* model = m_presentationManager->presentationsModel();
706 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
707 if (0 != presNode)
709 presNode->getItem()->previousSlide();
713 void kworship::presentationNextSlide()
715 // Find the treeviews current index
716 QModelIndex index = m_selectPresTree->currentIndex();
717 UpPresentationsModel* model = m_presentationManager->presentationsModel();
718 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
719 if (0 != presNode)
721 presNode->getItem()->nextSlide();
725 void kworship::presentationPreviousStep()
727 // Find the treeviews current index
728 QModelIndex index = m_selectPresTree->currentIndex();
729 UpPresentationsModel* model = m_presentationManager->presentationsModel();
730 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
731 if (0 != presNode)
733 presNode->getItem()->previousStep();
737 void kworship::presentationNextStep()
739 // Find the treeviews current index
740 QModelIndex index = m_selectPresTree->currentIndex();
741 UpPresentationsModel* model = m_presentationManager->presentationsModel();
742 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
743 if (0 != presNode)
745 presNode->getItem()->nextStep();
749 void kworship::slide_doubleClicked(QModelIndex index)
751 // Find the listviews current index
752 UpPresentationsModel* model = m_presentationManager->presentationsModel();
753 QModelIndex parentIndex = model->parent(index);
754 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(parentIndex));
755 if (0 != presNode)
757 presNode->getItem()->goToSlide(index.row());
761 // Documents
762 void kworship::setDocument(KUrl url)
764 delete m_document;
765 m_document = new KwDocument(url, this);
767 // Playlist will have changed
768 playlistReset();
770 // Wire up signals
771 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
774 // Presentations
775 void kworship::setPresentation(UpPresentation* presentation, bool alreadyDestroyed)
777 if (0 != m_currentPresentation)
779 // Stop the slideshow if its running
780 m_view->slideshows->setVisible(false);
781 if (!alreadyDestroyed)
783 m_currentPresentation->stopSlideshow();
784 disconnect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
785 disconnect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
786 disconnect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
787 disconnect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
788 disconnect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
789 disconnect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
790 disconnect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
792 slideshowStopped();
794 m_currentPresentation = presentation;
795 if (0 != m_currentPresentation)
797 connect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
798 connect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
799 connect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
800 connect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
801 connect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
802 connect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
803 connect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
804 // update slideshows list
805 refreshSlideshows();
806 m_view->slideshows->setVisible(true);
808 if (m_currentPresentation->isSlideshowRunning())
810 slideshowStarted(m_currentPresentation->numSlidesInSlideshow());
811 slideshowSlideChanged(m_currentPresentation->currentSlideshowSlide(), m_currentPresentation->stepsInCurrentSlideshowSlide());
812 slideshowStepChanged(m_currentPresentation->currentSlideshowStep());
815 m_slideshowAction->setEnabled(0 != m_currentPresentation);
818 // Custom slideshows
820 void kworship::presentationComboReset()
822 m_selectPresTree->expandToDepth(0);
823 m_selectPresTree->setItemsExpandable(false);
826 void kworship::changeSlideshowCombo(QString name)
828 Q_ASSERT(0 != m_currentPresentation);
829 m_currentPresentation->setSlideshow(name);
830 refreshSlides();
833 void kworship::changeSlideshowExternal(QString name)
835 if (m_view->comboSlideshows->currentText() != name)
837 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(name));
838 refreshSlides();
842 void kworship::refreshSlideshows()
844 Q_ASSERT(0 != m_currentPresentation);
845 m_view->comboSlideshows->clear();
846 m_view->comboSlideshows->insertItems(0, m_currentPresentation->slideshows());
847 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(m_currentPresentation->currentSlideshow()));
850 void kworship::refreshSlides()
852 // Clear child cache
853 QModelIndex root = m_view->listSlides->rootIndex();
854 DefaultModelNode* node = m_presentationManager->presentationsModel()->itemFromIndex(root);
855 Q_ASSERT(0 != node);
856 node->clearChildCache();
858 // Force a refresh
859 m_view->listSlides->setRootIndex(root);
862 void kworship::addSlideshowLinkToPlaylist()
864 Q_ASSERT(0 != m_currentPresentation);
865 QUrl url = m_currentPresentation->url();
866 QString slideshow = m_currentPresentation->currentSlideshow();
867 /// @todo Implement me
869 void kworship::addSlideshowCopyToPlaylist()
871 Q_ASSERT(0 != m_currentPresentation);
872 QString slideshow = m_currentPresentation->currentSlideshow();
873 /// @todo Implement me
876 // From current presentation
878 void kworship::slideshowStarted(int numSlides)
880 // Hide the screen
881 if (0 != m_mainDisplay)
883 m_mainDisplay->hide();
886 // Clear the display
887 m_displayManager->background.clear();
888 m_displayManager->text.clear();
890 m_view->slideshows->setEnabled(false);
891 m_view->progressPresSlides->setMaximum(numSlides);
892 m_view->progressPresSlides->setVisible(true);
893 m_slideshowAction->setChecked(true);
896 void kworship::slideshowStopped()
898 m_view->slideshows->setEnabled(true);
899 m_view->progressPresSlides->setVisible(false);
900 m_view->progressPresSteps->setVisible(false);
901 m_slideshowAction->setChecked(false);
902 m_slideshowPrevSlideAction->setEnabled(false);
903 m_slideshowPrevStepAction->setEnabled(false);
904 m_slideshowNextStepAction->setEnabled(false);
905 m_slideshowNextSlideAction->setEnabled(false);
907 // Clear any preview left from the slideshow
908 m_displayManager->background.clear();
909 // Clear slide notes
910 m_slideNotes->document()->clear();
912 // Show the screen again
913 if (0 != m_mainDisplay)
915 m_mainDisplay->showFullScreen();
919 void kworship::slideshowSlideChanged(int slide, int numSteps)
921 m_view->progressPresSlides->setValue(slide + 1);
922 m_view->progressPresSteps->setMaximum(numSteps);
923 m_view->progressPresSteps->setVisible(numSteps > 1);
925 m_slideshowPrevSlideAction->setEnabled(slide > 0);
926 m_slideshowNextSlideAction->setEnabled(slide < m_view->progressPresSlides->maximum()-1);
928 // live preview and notes
929 m_slideNotes->document()->clear();
930 assert(0 != m_currentPresentation);
931 UpSlide* currentSlide = m_currentPresentation->slide(slide);
932 if (0 != currentSlide)
934 // live preview
935 if (Settings::presLivePreview())
937 m_displayManager->background.setImage(currentSlide->preview());
939 // notes
940 currentSlide->writeNotes(m_slideNotes->document());
944 void kworship::slideshowStepChanged(int step)
946 m_view->progressPresSteps->setValue(step + 1);
948 bool firstSlide = (m_view->progressPresSlides->value() <= 1);
949 bool lastSlide = (m_view->progressPresSlides->value() >= m_view->progressPresSlides->maximum());
950 bool firstStep = firstSlide && (step <= 0);
951 bool lastStep = lastSlide && (step >= m_view->progressPresSteps->maximum() - 1);
952 m_slideshowPrevStepAction->setEnabled(!firstStep);
953 m_slideshowNextStepAction->setEnabled(!lastStep);
956 // Song DB
958 void kworship::songdbUnlock()
960 m_unlockSongDbAction->setVisible(false);
961 m_lockSongDbAction->setVisible(true);
964 void kworship::songdbLock()
966 m_unlockSongDbAction->setVisible(true);
967 m_lockSongDbAction->setVisible(false);
970 void kworship::songdbAdd()
972 KwSongdbSongEditDialog* dialog = new KwSongdbSongEditDialog(0);
973 dialog->setCaption(i18n("Add Song"));
974 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
975 dialog->show();
978 void kworship::songdbEdit()
980 /// @todo Ensure the same song isn't open twice
981 KwSongdbSong* song = m_songDbTree->currentSong();
982 if (0 != song)
984 KwSongdbVersion* version = m_songDbTree->currentSongVersion();
985 // version may be 0
986 KwSongdbSongEditDialog* dialog = new KwSongdbSongEditDialog(song, version);
987 dialog->setCaption(i18n("Edit Song - %1", song->name()));
988 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
989 dialog->show();
991 else
993 KMessageBox::information(this, i18n("Please select a song."));
997 void kworship::songdbEditSongBooks()
999 KwSongdbSongBooksEditWidget::showDialog();
1002 // Bibles
1004 void kworship::bibleSearch()
1006 // Search using the key
1007 int index = m_view->comboSwordBibles->currentIndex();
1008 if (index >= 0)
1010 QString modName = m_view->comboSwordBibles->itemData(index).toString();
1011 KwBibleModule* module = KwBibleManager::self()->module(modName);
1012 if (0 != module)
1014 KwBibleModule::Key key = module->createKey(m_view->searchBible->text());
1015 m_view->textBible->document()->setHtml(module->renderText(key));
1016 return;
1019 m_view->textBible->document()->setPlainText(QString());
1022 #include "kworship.moc"