Basic openoffice.org control, and listening for new presentation documents, still...
[kworship.git] / kworship / kworship.cpp
blob2f06932dd77d3869028971a658e74471a5b7f232
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 "prefsDatabase.h"
25 #include "KwDatabaseSetup.h"
26 #include "KwDocument.h"
27 #include "KwApplication.h"
28 #include "KwPluginManager.h"
29 #include "KwFilterManager.h"
30 #include "KwLoadSaveFilter.h"
32 #include "KwPlaylistNode.h"
33 #include "KwPlaylistList.h"
34 #include "KwPlaylistNote.h"
35 #include "KwPlaylistText.h"
36 #include "KwPlaylistImage.h"
37 #include "KwPlaylistVideo.h"
38 #include "KwPlaylistModel.h"
40 #include "KwCssStyleSheet.h"
41 #include "KwCssStyleRule.h"
43 #include "KwDisplayManager.h"
44 #include "KwLocalDisplay.h"
45 #include "KwLocalDisplayPreview.h"
47 #include "KwMediaManager.h"
48 #include "KwMediaControlWidget.h"
50 #include "UpManager.h"
51 #include "UpPresentationsModel.h"
52 #include "UpPresentation.h"
53 #include "UpPresentationNode.h"
54 #include "UpSlide.h"
56 #include <kconfigdialog.h>
57 #include <kstatusbar.h>
58 #include <kaction.h>
59 #include <kactionmenu.h>
60 #include <kmenu.h>
61 #include <ktoggleaction.h>
62 #include <kactioncollection.h>
63 #include <kstandardaction.h>
64 #include <KDE/KLocale>
65 #include <KFileDialog>
66 #include <KMessageBox>
68 #include <phonon/audiooutput.h>
70 #include <QtGui/QDropEvent>
71 #include <QtGui/QPainter>
72 #include <QColor>
73 #include <QDesktopWidget>
74 #include <QToolBar>
75 #include <QToolButton>
76 #include <QComboBox>
77 #include <QSqlDatabase>
78 #include <QHeaderView>
79 #include <QTextEdit>
81 kworship::kworship()
82 : KXmlGuiWindow()
83 , m_view(new kworshipView(this))
84 , m_displayManager(0)
85 , m_document(0)
86 , m_presentationManager(new UpManager(this))
87 , m_currentPresentation(0)
88 , m_printer(0)
90 m_playlistModel = new KwPlaylistModel;
91 clearDocument();
93 // set up presentation backends
94 m_presentationManager->loadBackends();
96 m_mainDisplay = 0;
97 m_previewDisplay = 0;
99 // accept dnd
100 setAcceptDrops(true);
102 // tell the KXmlGuiWindow that this is indeed the main widget
103 setCentralWidget(m_view);
105 // then, setup our actions
106 setupActions();
108 // add a status bar
109 statusBar()->show();
111 // a call to KXmlGuiWindow::setupGUI() populates the GUI
112 // with actions, using KXMLGUI.
113 // It also applies the saved mainwindow settings, if any, and ask the
114 // mainwindow to automatically save settings if changed: window size,
115 // toolbar position, icon size, etc.
116 setupGUI();
118 // Setup the dockers
119 addDockWidget(Qt::LeftDockWidgetArea, m_view->dockPresentation);
120 addDockWidget(Qt::RightDockWidgetArea, m_view->dockPreview);
121 addDockWidget(Qt::RightDockWidgetArea, m_view->dockLyrics);
122 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockThemes);
123 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockNowPlaying);
125 // Setup some stuff in the tree
126 #if 0
127 #define TREE_ITEM(name, string, parent) QTreeWidgetItem* name = new QTreeWidgetItem(parent); name->setText(0, tr(string));
129 TREE_ITEM(song1, "Our God is a great big God", m_view->treeWidget);
130 TREE_ITEM(song1_style, "(style)", song1);
131 TREE_ITEM(song1_style_1, "Mode", song1_style);
132 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);
133 TREE_ITEM(song1_v2, "He's higher than a skyscraper\nAnd he's deeper than a submarine.", song1);
134 TREE_ITEM(song1_v3, "He's wider than the universe\nAnd beyond my wildest dreams.", song1);
136 #undef TREE_ITEM
137 #endif
139 // Playlist
140 m_document->playlist()->addClass("beachy");
142 KwCssStyleSheet* styleRules = new KwCssStyleSheet;
144 KwCssStyleRule beachyTheme;
145 beachyTheme.setCriteriaClasses(QSet<QString>() << "beachy");
146 beachyTheme.setStyle<QBrush>("background.brush", Qt::black);
147 beachyTheme.setStyle<KwResourceLink>("background.image.src", KUrl("file:///home/james/media/images/projector/misc/love-god-light.jpg"));
148 styleRules->addRule(beachyTheme);
150 KwCssStyleRule bibleTheme;
151 bibleTheme.setCriteriaKeys(KwCssStyleRule::KeyList() << KwCssScopeKey(KwCssScopeKey::registerScopeType("bible")));
152 bibleTheme.setStyle<QBrush>("background.brush", Qt::black);
153 bibleTheme.setStyle<KwResourceLink>("background.image.src", KUrl("file:///home/james/media/images/projector/misc/bible.jpg"));
154 styleRules->addRule(bibleTheme);
156 m_document->playlist()->addStyleSheet(styleRules);
158 m_view->treePlaylist->setModel(m_playlistModel);
159 m_view->treePlaylist->setExpandsOnDoubleClick(false);
160 m_view->treePlaylist->setAcceptDrops(true);
162 connect(m_view->treePlaylist, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(playlist_doubleClicked(QModelIndex)));
164 m_mediaManager = new KwMediaManager();
165 m_mediaManager->linkAudio(new Phonon::AudioOutput(Phonon::MusicCategory));
166 m_displayManager = new KwDisplayManager(&m_displayController, m_mediaManager);
168 m_previewDisplay = new KwLocalDisplayPreview;
169 m_view->layoutPreview->addWidget(m_previewDisplay);
170 m_displayController.attachChild(m_previewDisplay);
172 KwMediaControlWidget* mediaWidget = new KwMediaControlWidget(m_mediaManager, m_view->dockNowPlaying);
173 m_view->layoutNowPlaying->addWidget(mediaWidget);
176 * Presentation
179 // Drop down list of presentations
180 QComboBox* selectPresCombo = m_view->comboPresentations;
181 m_selectPresTree = new QTreeView(this);
182 m_selectPresTree->header()->hide();
183 selectPresCombo->setModel(m_presentationManager->presentationsModel());
184 selectPresCombo->setView(m_selectPresTree);
185 presentationComboReset();
186 connect(m_presentationManager->presentationsModel(), SIGNAL(modelReset()), this, SLOT(presentationComboReset()));
187 connect(selectPresCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(presentationSelected(int)));
189 // Custom slideshow selector
190 m_view->slideshows->setVisible(false);
191 connect(m_view->comboSlideshows, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(changeSlideshowCombo(QString)));
193 QToolBar* customSlideshowsToolBar = new QToolBar(i18n("Custom Slideshows"));
194 customSlideshowsToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
195 m_view->slideshows->layout()->addWidget(customSlideshowsToolBar);
196 // Add slideshow to playlist
197 KActionMenu* addSlideshowToPlaylistAction = new KActionMenu(KIcon("list-add"), i18n("Add Slideshow to Playlist"), customSlideshowsToolBar);
198 addSlideshowToPlaylistAction->setDelayed(false);
199 customSlideshowsToolBar->addAction(addSlideshowToPlaylistAction);
201 KAction* asLinkAction = new KAction(KIcon("insert-link"), i18n("Add Link to Slideshow into Playlist"), customSlideshowsToolBar);
202 connect(asLinkAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowLinkToPlaylist()));
203 addSlideshowToPlaylistAction->addAction(asLinkAction);
206 KAction* asCopyAction = new KAction(KIcon("edit-copy"), i18n("Save Copy of Slideshow into Playlist"), customSlideshowsToolBar);
207 connect(asCopyAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowCopyToPlaylist()));
208 addSlideshowToPlaylistAction->addAction(asCopyAction);
211 // Presentations toolbar
212 QToolBar* presToolBar = new QToolBar("Presentations");
213 m_view->layoutPresentationsToolbar->layout()->addWidget(presToolBar);
215 KActionMenu* openPresAction = new KActionMenu(KIcon("document-open"), "Open Presentation", presToolBar);
216 openPresAction->setDelayed(true);
217 presToolBar->addAction(openPresAction);
219 KAction* refreshPresAction = new KAction(KIcon("view-refresh"), "Refresh Presentation List", presToolBar);
220 presToolBar->addAction(refreshPresAction);
222 KAction* closePresAction = new KAction(KIcon("fileclose"), "Close Presentation", presToolBar);
223 presToolBar->addAction(closePresAction);
225 KToggleAction* fullscreenPresAction = new KToggleAction(KIcon("view-fullscreen"), "Fullscreen Presentation Mode", presToolBar);
226 presToolBar->addAction(fullscreenPresAction);
228 // Slide list
229 connect(m_view->listSlides, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slide_doubleClicked(QModelIndex)));
231 // Slides toolbar
232 QToolBar* slidesToolBar = new QToolBar("Slides");
233 slidesToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
234 slidesToolBar->setIconSize(QSize(32,32));
235 m_view->layoutSlidesToolbar->layout()->addWidget(slidesToolBar);
237 m_slideshowPrevSlideAction = new KAction(KIcon("media-skip-backward"), i18n("Previous Slide"), slidesToolBar);
238 connect(m_slideshowPrevSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousSlide()));
239 slidesToolBar->addAction(m_slideshowPrevSlideAction);
241 m_slideshowPrevStepAction = new KAction(KIcon("media-seek-backward"), i18n("Previous Step"), slidesToolBar);
242 connect(m_slideshowPrevStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousStep()));
243 slidesToolBar->addAction(m_slideshowPrevStepAction);
245 m_slideshowNextStepAction = new KAction(KIcon("media-seek-forward"), i18n("Next Step"), slidesToolBar);
246 connect(m_slideshowNextStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextStep()));
247 slidesToolBar->addAction(m_slideshowNextStepAction);
249 m_slideshowNextSlideAction = new KAction(KIcon("media-skip-forward"), i18n("Next Slide"), slidesToolBar);
250 connect(m_slideshowNextSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextSlide()));
251 slidesToolBar->addAction(m_slideshowNextSlideAction);
253 m_slideshowAction = new KToggleAction(KIcon("view-presentation"), i18n("Start/Stop Slideshow"), slidesToolBar);
254 connect(m_slideshowAction, SIGNAL(toggled(bool)), this, SLOT(presentationToggled(bool)));
255 slidesToolBar->addAction(m_slideshowAction);
257 // Slide notes
258 m_slideNotes = new QTextEdit();
259 m_slideNotes->setReadOnly(true);
260 m_slideNotes->setWindowTitle(i18n("Slide Notes"));
261 m_slideNotes->show();
263 // Ensure the controls are as when slideshow is stopped
264 m_slideshowAction->setEnabled(false);
265 slideshowStopped();
268 * Display startup
271 // Show the display on startup?
272 if (Settings::displayShowStartup())
274 // If there's only one screen, don't bother showing display.
275 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
276 assert(0 != desktop);
277 if (desktop->numScreens() > 1)
279 toggleMainDisplay(true);
280 m_mainDisplayAction->setChecked(true);
285 kworship::~kworship()
287 delete m_slideNotes;
291 * Public interface
294 /// Load a specified playlist.
295 void kworship::loadPlaylist(const KUrl& url)
297 // Find mime type
298 KMimeType::Ptr mimeType = KMimeType::findByUrl(url);
299 QString mime = mimeType->name();
301 // Use the appropriate filter
302 KwLoadSaveFilter* filter = KwApplication::self()->filterManager()->loadFilterFromMimeType(mime);
303 if (filter)
305 KwDocument* newDoc = filter->load(url, mime);
306 if (0 != newDoc)
308 delete m_document;
309 m_document = newDoc;
311 // Playlist will have changed
312 playlistReset();
314 // Wire up signals
315 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
317 else
319 KMessageBox::error(this,
320 i18n("Loading of \"%1\" failed.").arg(url.url()),
321 i18n("KWorship"));
324 else
326 KMessageBox::error(this,
327 i18n("No load filter exists for the mime type \"%1\"").arg(mime),
328 i18n("KWorship"));
333 * Accessors
336 /// Get the main display manager.
337 KwDisplayManager* kworship::displayManager()
339 return m_displayManager;
342 /// Get the current document.
343 KwDocument* kworship::document()
345 return m_document;
348 /// Get the playlist model.
349 KwPlaylistModel* kworship::playlistModel()
351 return m_playlistModel;
354 void kworship::setupActions()
356 // Application
357 KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
358 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
360 // File management
361 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
362 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
363 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
364 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
366 // Display
367 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
369 m_mainDisplayAction = new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
370 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction );
371 connect(m_mainDisplayAction, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
373 KAction* clearDisplayAction = new KAction(KIcon("clear"), i18n("Clear display"), this);
374 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction);
375 connect(clearDisplayAction, SIGNAL(triggered()), this, SLOT(displayClear()));
378 void kworship::settingsChanged()
380 // If the main display is on and screen has changed, move it now
381 if (0 != m_mainDisplay && getCorrectDisplayScreen() != getCurrentDisplayScreen())
383 toggleMainDisplay(false);
384 toggleMainDisplay(true);
385 m_mainDisplayAction->setChecked(true);
389 int kworship::getCorrectDisplayScreen()
391 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
392 assert(0 != desktop);
394 int screens = desktop->numScreens();
395 int displayScreen = -1;
396 if (Settings::displayScreenChoose())
398 displayScreen = Settings::displayScreen();
400 if (-1 == displayScreen)
402 int currentScreen;
403 if (m_view->isVisible())
405 currentScreen = desktop->screenNumber(m_view);
407 else
409 currentScreen = desktop->primaryScreen();
411 displayScreen = 0;
412 if (displayScreen == currentScreen && displayScreen < screens-1)
414 ++displayScreen;
418 return displayScreen;
421 int kworship::getCurrentDisplayScreen()
423 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
424 assert(0 != desktop);
426 int previousScreen = desktop->screenNumber(m_mainDisplay);
428 return previousScreen;
431 void kworship::toggleMainDisplay(bool checked)
433 if (checked)
435 // Ensure the display exists
436 if (0 == m_mainDisplay)
438 m_mainDisplay = new KwLocalDisplay;
439 m_mainDisplay->setPrimary(true);
440 m_mainDisplay->setWindowTitle("kworship display");
441 m_displayController.attachChild(m_mainDisplay);
442 connect(m_mainDisplay, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
445 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
446 assert(0 != desktop);
448 int screens = desktop->numScreens();
449 int displayScreen = getCorrectDisplayScreen();
451 if (displayScreen >= 0 && displayScreen < screens)
453 m_mainDisplay->move(desktop->screenGeometry(displayScreen).topLeft());
456 if (!m_slideshowAction->isChecked())
458 m_mainDisplay->showFullScreen();
461 else
463 if (0 != m_mainDisplay)
465 m_mainDisplay->close();
470 void kworship::mainDisplayClosed()
472 m_mainDisplay->deleteLater();
473 m_mainDisplay = 0;
474 m_mainDisplayAction->setChecked(false);
477 void kworship::displayClear()
479 m_displayManager->background.clear();
480 m_displayManager->text.clear();
483 void kworship::toggleFullscreen(bool checked)
485 if (checked)
487 showFullScreen();
489 else
491 showNormal();
495 bool kworship::askToSave()
497 if (m_document->isModified())
499 switch (KMessageBox::questionYesNoCancel(this,
500 i18n("The current playlist has been modified. "
501 "These modifications will be lost if you continue without saving. "
502 "Would you like to save now?"),
503 i18n("Playlist is modified")))
505 case KMessageBox::Yes:
507 fileSave();
508 // If the document is still modified, save must have been cancelled
509 if (m_document->isModified())
511 return false;
514 break;
515 case KMessageBox::No:
516 break;
517 case KMessageBox::Cancel:
518 default:
520 return false;
522 break;
525 return true;
528 void kworship::fileNew()
530 if (askToSave())
532 clearDocument();
536 void kworship::fileOpen()
538 if (askToSave())
540 // Do the open operation
541 QStringList mimes = KwApplication::self()->filterManager()->loadMimeTypes();
543 KUrl defaultUrl("kfiledialog:///playlist");
544 if (m_document->isSaved())
546 defaultUrl = m_document->url();
549 KFileDialog dlg(defaultUrl, QString(), this);
550 dlg.setMimeFilter(mimes);
551 dlg.setOperationMode(KFileDialog::Opening);
552 dlg.setCaption(i18n("Open Playlist"));
553 dlg.setMode(KFile::File | KFile::ExistingOnly);
554 dlg.exec();
556 KUrl url = dlg.selectedUrl();
557 if (!url.isEmpty())
559 loadPlaylist(url);
564 void kworship::fileSave()
566 if (m_document->isSaved())
568 m_document->save();
570 else
572 fileSaveAs();
576 void kworship::fileSaveAs()
578 QStringList mimes = KwApplication::self()->filterManager()->saveMimeTypes();
580 KUrl defaultUrl("kfiledialog:///playlist");
581 if (m_document->isSaved())
583 defaultUrl = m_document->url();
586 QString defaultMime = m_document->mimeType();
587 if (defaultMime.isEmpty())
589 defaultMime = KwApplication::self()->filterManager()->defaultSaveMimeType();
592 KFileDialog dlg(defaultUrl, QString(), this);
593 dlg.setMimeFilter(mimes, defaultMime);
594 dlg.setOperationMode(KFileDialog::Saving);
595 dlg.setConfirmOverwrite(true);
596 dlg.setCaption(i18n("Save Playlist As"));
597 dlg.setMode(KFile::File);
598 dlg.exec();
600 KUrl url = dlg.selectedUrl();
601 if (!url.isEmpty())
603 // Find mime type
604 QString mime = dlg.currentMimeFilter();
606 // Use the appropriate filter
607 KwLoadSaveFilter* filter = KwApplication::self()->filterManager()->saveFilterFromMimeType(mime);
608 if (filter)
610 m_document->saveAs(filter, mime, url);
611 if (m_document->isModified())
613 KMessageBox::error(this,
614 i18n("Saving to \"%1\" failed.").arg(url.url()),
615 i18n("KWorship"));
618 else
620 KMessageBox::error(this,
621 i18n("No save filter exists for the mime type \"%1\"").arg(mime),
622 i18n("KWorship"));
627 void kworship::optionsPreferences()
629 //avoid to have 2 dialogs shown
630 if ( KConfigDialog::showDialog( "settings" ) ) {
631 return;
633 KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
635 QWidget *generalSettingsDlg = new QWidget(dialog);
636 ui_prefs_base.setupUi(generalSettingsDlg);
637 dialog->addPage(generalSettingsDlg, i18n("General"), "preferences-other", i18n("General"));
639 prefsDisplay *displaySettingsDlg = new prefsDisplay(dialog);
640 dialog->addPage(displaySettingsDlg, i18n("Display"), "video-projector", i18n("Display and Screen"));
642 prefsDatabase *songdbSettingsDlg = new prefsDatabase(dialog);
643 dialog->addPage(songdbSettingsDlg, i18n("Database"), "applications-multimedia", i18n("Database"));
645 QWidget *presentationSettingsDlg = new QWidget(dialog);
646 ui_prefsPresentations_base.setupUi(presentationSettingsDlg);
647 dialog->addPage(presentationSettingsDlg, i18n("Presentations"), "view-presentation", i18n("Presentations and Slideshows"));
649 // Let the plugins have their say
650 KwApplication::self()->pluginManager()->setupConfigDialog(dialog);
652 connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
653 connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(settingsChanged()));
654 dialog->setAttribute( Qt::WA_DeleteOnClose );
655 dialog->show();
658 void kworship::playlist_doubleClicked(QModelIndex index)
660 KwPlaylistNode* node = m_playlistModel->itemFromIndex(index);
661 node->activate(m_displayManager);
664 void kworship::playlistReset()
666 // Connect up the new document
667 m_playlistModel->setRootNode(m_document->playlist()->getNode(0));
670 #include <iostream>
671 /// Add the new docker to the interface.
672 void kworship::newDocker(QDockWidget* docker)
674 std::cout << docker << std::endl;
675 addDockWidget(Qt::LeftDockWidgetArea, docker);
678 void kworship::presentationDelete()
680 setPresentation(0, true);
681 presentationSelected(0);
684 void kworship::presentationSelected(int)
686 // Find the treeviews current index
687 QModelIndex index = m_selectPresTree->currentIndex();
688 UpPresentationsModel* model = m_presentationManager->presentationsModel();
689 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
690 if (0 != presNode)
692 m_view->listSlides->setModel(model);
693 m_view->listSlides->setRootIndex(index);
694 setPresentation(presNode->getItem());
696 else
698 m_view->listSlides->setModel(0);
699 setPresentation(0);
703 void kworship::presentationToggled(bool checked)
705 // Find the treeviews current index
706 QModelIndex index = m_selectPresTree->currentIndex();
707 UpPresentationsModel* model = m_presentationManager->presentationsModel();
708 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
709 if (0 != presNode)
711 if (checked)
713 presNode->getItem()->startSlideshow();
715 else
717 presNode->getItem()->stopSlideshow();
722 void kworship::presentationPreviousSlide()
724 // Find the treeviews current index
725 QModelIndex index = m_selectPresTree->currentIndex();
726 UpPresentationsModel* model = m_presentationManager->presentationsModel();
727 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
728 if (0 != presNode)
730 presNode->getItem()->previousSlide();
734 void kworship::presentationNextSlide()
736 // Find the treeviews current index
737 QModelIndex index = m_selectPresTree->currentIndex();
738 UpPresentationsModel* model = m_presentationManager->presentationsModel();
739 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
740 if (0 != presNode)
742 presNode->getItem()->nextSlide();
746 void kworship::presentationPreviousStep()
748 // Find the treeviews current index
749 QModelIndex index = m_selectPresTree->currentIndex();
750 UpPresentationsModel* model = m_presentationManager->presentationsModel();
751 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
752 if (0 != presNode)
754 presNode->getItem()->previousStep();
758 void kworship::presentationNextStep()
760 // Find the treeviews current index
761 QModelIndex index = m_selectPresTree->currentIndex();
762 UpPresentationsModel* model = m_presentationManager->presentationsModel();
763 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
764 if (0 != presNode)
766 presNode->getItem()->nextStep();
770 void kworship::slide_doubleClicked(QModelIndex index)
772 // Find the listviews current index
773 UpPresentationsModel* model = m_presentationManager->presentationsModel();
774 QModelIndex parentIndex = model->parent(index);
775 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(parentIndex));
776 if (0 != presNode)
778 presNode->getItem()->goToSlide(index.row());
782 // Documents
783 void kworship::clearDocument()
785 delete m_document;
786 m_document = new KwDocument(0, QString(), KUrl(), this);
788 // Playlist will have changed
789 playlistReset();
791 // Wire up signals
792 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
795 // Presentations
796 void kworship::setPresentation(UpPresentation* presentation, bool alreadyDestroyed)
798 if (0 != m_currentPresentation)
800 // Stop the slideshow if its running
801 m_view->slideshows->setVisible(false);
802 if (!alreadyDestroyed)
804 m_currentPresentation->stopSlideshow();
805 disconnect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
806 disconnect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
807 disconnect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
808 disconnect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
809 disconnect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
810 disconnect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
811 disconnect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
813 slideshowStopped();
815 m_currentPresentation = presentation;
816 if (0 != m_currentPresentation)
818 connect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
819 connect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
820 connect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
821 connect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
822 connect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
823 connect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
824 connect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
825 // update slideshows list
826 refreshSlideshows();
827 m_view->slideshows->setVisible(true);
829 if (m_currentPresentation->isSlideshowRunning())
831 slideshowStarted(m_currentPresentation->numSlidesInSlideshow());
832 slideshowSlideChanged(m_currentPresentation->currentSlideshowSlide(), m_currentPresentation->stepsInCurrentSlideshowSlide());
833 slideshowStepChanged(m_currentPresentation->currentSlideshowStep());
836 m_slideshowAction->setEnabled(0 != m_currentPresentation);
839 // Custom slideshows
841 void kworship::presentationComboReset()
843 m_selectPresTree->expandToDepth(0);
844 m_selectPresTree->setItemsExpandable(false);
847 void kworship::changeSlideshowCombo(QString name)
849 Q_ASSERT(0 != m_currentPresentation);
850 m_currentPresentation->setSlideshow(name);
851 refreshSlides();
854 void kworship::changeSlideshowExternal(QString name)
856 if (m_view->comboSlideshows->currentText() != name)
858 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(name));
859 refreshSlides();
863 void kworship::refreshSlideshows()
865 Q_ASSERT(0 != m_currentPresentation);
866 m_view->comboSlideshows->clear();
867 m_view->comboSlideshows->insertItems(0, m_currentPresentation->slideshows());
868 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(m_currentPresentation->currentSlideshow()));
871 void kworship::refreshSlides()
873 // Clear child cache
874 QModelIndex root = m_view->listSlides->rootIndex();
875 DefaultModelNode* node = m_presentationManager->presentationsModel()->itemFromIndex(root);
876 Q_ASSERT(0 != node);
877 node->clearChildCache();
879 // Force a refresh
880 m_view->listSlides->setRootIndex(root);
883 void kworship::addSlideshowLinkToPlaylist()
885 Q_ASSERT(0 != m_currentPresentation);
886 QUrl url = m_currentPresentation->url();
887 QString slideshow = m_currentPresentation->currentSlideshow();
888 /// @todo Implement me
890 void kworship::addSlideshowCopyToPlaylist()
892 Q_ASSERT(0 != m_currentPresentation);
893 QString slideshow = m_currentPresentation->currentSlideshow();
894 /// @todo Implement me
897 // From current presentation
899 void kworship::slideshowStarted(int numSlides)
901 // Hide the screen
902 if (0 != m_mainDisplay)
904 m_mainDisplay->hide();
907 // Clear the display
908 m_displayManager->background.clear();
909 m_displayManager->text.clear();
911 m_view->slideshows->setEnabled(false);
912 m_view->progressPresSlides->setMaximum(numSlides);
913 m_view->progressPresSlides->setVisible(true);
914 m_slideshowAction->setChecked(true);
917 void kworship::slideshowStopped()
919 m_view->slideshows->setEnabled(true);
920 m_view->progressPresSlides->setVisible(false);
921 m_view->progressPresSteps->setVisible(false);
922 m_slideshowAction->setChecked(false);
923 m_slideshowPrevSlideAction->setEnabled(false);
924 m_slideshowPrevStepAction->setEnabled(false);
925 m_slideshowNextStepAction->setEnabled(false);
926 m_slideshowNextSlideAction->setEnabled(false);
928 // Clear any preview left from the slideshow
929 m_displayManager->background.clear();
930 // Clear slide notes
931 m_slideNotes->document()->clear();
933 // Show the screen again
934 if (0 != m_mainDisplay)
936 m_mainDisplay->showFullScreen();
940 void kworship::slideshowSlideChanged(int slide, int numSteps)
942 m_view->progressPresSlides->setValue(slide + 1);
943 m_view->progressPresSteps->setMaximum(numSteps);
944 m_view->progressPresSteps->setVisible(numSteps > 1);
946 m_slideshowPrevSlideAction->setEnabled(slide > 0);
947 m_slideshowNextSlideAction->setEnabled(slide < m_view->progressPresSlides->maximum()-1);
949 // live preview and notes
950 m_slideNotes->document()->clear();
951 assert(0 != m_currentPresentation);
952 UpSlide* currentSlide = m_currentPresentation->slide(slide);
953 if (0 != currentSlide)
955 // live preview
956 if (Settings::presLivePreview())
958 m_displayManager->background.setImage(currentSlide->preview());
960 // notes
961 currentSlide->writeNotes(m_slideNotes->document());
965 void kworship::slideshowStepChanged(int step)
967 m_view->progressPresSteps->setValue(step + 1);
969 bool firstSlide = (m_view->progressPresSlides->value() <= 1);
970 bool lastSlide = (m_view->progressPresSlides->value() >= m_view->progressPresSlides->maximum());
971 bool firstStep = firstSlide && (step <= 0);
972 bool lastStep = lastSlide && (step >= m_view->progressPresSteps->maximum() - 1);
973 m_slideshowPrevStepAction->setEnabled(!firstStep);
974 m_slideshowNextStepAction->setEnabled(!lastStep);
978 #include "kworship.moc"