SQLite compatibility and related fixes
[kworship.git] / kworship / kworship.cpp
blob34bd1ea8511b57e713810b0e14c748084afe0421
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->setSelectionMode(QAbstractItemView::ExtendedSelection);
160 m_view->treePlaylist->setExpandsOnDoubleClick(false);
161 m_view->treePlaylist->setDragEnabled(true);
162 m_view->treePlaylist->setAcceptDrops(true);
164 connect(m_view->treePlaylist, SIGNAL(clicked(QModelIndex)), this, SLOT(playlist_clicked(QModelIndex)));
165 connect(m_view->treePlaylist, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(playlist_doubleClicked(QModelIndex)));
167 m_mediaManager = new KwMediaManager();
168 m_mediaManager->linkAudio(new Phonon::AudioOutput(Phonon::MusicCategory));
169 m_displayManager = new KwDisplayManager(&m_displayController, m_mediaManager);
171 m_previewDisplay = new KwLocalDisplayPreview;
172 m_view->layoutPreview->addWidget(m_previewDisplay);
173 m_displayController.attachChild(m_previewDisplay);
175 KwMediaControlWidget* mediaWidget = new KwMediaControlWidget(m_mediaManager, m_view->dockNowPlaying);
176 m_view->layoutNowPlaying->addWidget(mediaWidget);
179 * Presentation
182 // Drop down list of presentations
183 QComboBox* selectPresCombo = m_view->comboPresentations;
184 m_selectPresTree = new QTreeView(this);
185 m_selectPresTree->header()->hide();
186 selectPresCombo->setModel(m_presentationManager->presentationsModel());
187 selectPresCombo->setView(m_selectPresTree);
188 presentationComboReset();
189 connect(m_presentationManager->presentationsModel(), SIGNAL(modelReset()), this, SLOT(presentationComboReset()));
190 connect(selectPresCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(presentationSelected(int)));
192 // Custom slideshow selector
193 m_view->slideshows->setVisible(false);
194 connect(m_view->comboSlideshows, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(changeSlideshowCombo(QString)));
196 QToolBar* customSlideshowsToolBar = new QToolBar(i18n("Custom Slideshows"));
197 customSlideshowsToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
198 m_view->slideshows->layout()->addWidget(customSlideshowsToolBar);
199 // Add slideshow to playlist
200 KActionMenu* addSlideshowToPlaylistAction = new KActionMenu(KIcon("list-add"), i18n("Add Slideshow to Playlist"), customSlideshowsToolBar);
201 addSlideshowToPlaylistAction->setDelayed(false);
202 customSlideshowsToolBar->addAction(addSlideshowToPlaylistAction);
204 KAction* asLinkAction = new KAction(KIcon("insert-link"), i18n("Add Link to Slideshow into Playlist"), customSlideshowsToolBar);
205 connect(asLinkAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowLinkToPlaylist()));
206 addSlideshowToPlaylistAction->addAction(asLinkAction);
209 KAction* asCopyAction = new KAction(KIcon("edit-copy"), i18n("Save Copy of Slideshow into Playlist"), customSlideshowsToolBar);
210 connect(asCopyAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowCopyToPlaylist()));
211 addSlideshowToPlaylistAction->addAction(asCopyAction);
214 // Presentations toolbar
215 QToolBar* presToolBar = new QToolBar("Presentations");
216 m_view->layoutPresentationsToolbar->layout()->addWidget(presToolBar);
218 KActionMenu* openPresAction = new KActionMenu(KIcon("document-open"), "Open Presentation", presToolBar);
219 openPresAction->setDelayed(true);
220 presToolBar->addAction(openPresAction);
222 KAction* refreshPresAction = new KAction(KIcon("view-refresh"), "Refresh Presentation List", presToolBar);
223 presToolBar->addAction(refreshPresAction);
225 KAction* closePresAction = new KAction(KIcon("fileclose"), "Close Presentation", presToolBar);
226 presToolBar->addAction(closePresAction);
228 KToggleAction* fullscreenPresAction = new KToggleAction(KIcon("view-fullscreen"), "Fullscreen Presentation Mode", presToolBar);
229 presToolBar->addAction(fullscreenPresAction);
231 // Slide list
232 connect(m_view->listSlides, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slide_doubleClicked(QModelIndex)));
234 // Slides toolbar
235 QToolBar* slidesToolBar = new QToolBar("Slides");
236 slidesToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
237 slidesToolBar->setIconSize(QSize(32,32));
238 m_view->layoutSlidesToolbar->layout()->addWidget(slidesToolBar);
240 m_slideshowPrevSlideAction = new KAction(KIcon("media-skip-backward"), i18n("Previous Slide"), slidesToolBar);
241 connect(m_slideshowPrevSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousSlide()));
242 slidesToolBar->addAction(m_slideshowPrevSlideAction);
244 m_slideshowPrevStepAction = new KAction(KIcon("media-seek-backward"), i18n("Previous Step"), slidesToolBar);
245 connect(m_slideshowPrevStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousStep()));
246 slidesToolBar->addAction(m_slideshowPrevStepAction);
248 m_slideshowNextStepAction = new KAction(KIcon("media-seek-forward"), i18n("Next Step"), slidesToolBar);
249 connect(m_slideshowNextStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextStep()));
250 slidesToolBar->addAction(m_slideshowNextStepAction);
252 m_slideshowNextSlideAction = new KAction(KIcon("media-skip-forward"), i18n("Next Slide"), slidesToolBar);
253 connect(m_slideshowNextSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextSlide()));
254 slidesToolBar->addAction(m_slideshowNextSlideAction);
256 m_slideshowAction = new KToggleAction(KIcon("view-presentation"), i18n("Start/Stop Slideshow"), slidesToolBar);
257 connect(m_slideshowAction, SIGNAL(toggled(bool)), this, SLOT(presentationToggled(bool)));
258 slidesToolBar->addAction(m_slideshowAction);
260 // Slide notes
261 m_slideNotes = new QTextEdit();
262 m_slideNotes->setReadOnly(true);
263 m_slideNotes->setWindowTitle(i18n("Slide Notes"));
264 m_slideNotes->show();
266 // Ensure the controls are as when slideshow is stopped
267 m_slideshowAction->setEnabled(false);
268 slideshowStopped();
271 * Display startup
274 // Show the display on startup?
275 if (Settings::displayShowStartup())
277 // If there's only one screen, don't bother showing display.
278 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
279 assert(0 != desktop);
280 if (desktop->numScreens() > 1)
282 toggleMainDisplay(true);
283 m_mainDisplayAction->setChecked(true);
288 kworship::~kworship()
290 delete m_slideNotes;
294 * Public interface
297 /// Load a specified playlist.
298 void kworship::loadPlaylist(const KUrl& url)
300 // Find mime type
301 KMimeType::Ptr mimeType = KMimeType::findByUrl(url);
302 QString mime = mimeType->name();
304 // Use the appropriate filter
305 KwLoadSaveFilter* filter = KwApplication::self()->filterManager()->loadFilterFromMimeType(mime);
306 if (filter)
308 KwDocument* newDoc = filter->load(url, mime);
309 if (0 != newDoc)
311 delete m_document;
312 m_document = newDoc;
314 // Playlist will have changed
315 playlistReset();
317 // Wire up signals
318 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
320 else
322 KMessageBox::error(this,
323 i18n("Loading of \"%1\" failed.").arg(url.url()),
324 i18n("KWorship"));
327 else
329 KMessageBox::error(this,
330 i18n("No load filter exists for the mime type \"%1\"").arg(mime),
331 i18n("KWorship"));
336 * Accessors
339 /// Get the main display manager.
340 KwDisplayManager* kworship::displayManager()
342 return m_displayManager;
345 /// Get the current document.
346 KwDocument* kworship::document()
348 return m_document;
351 /// Get the playlist model.
352 KwPlaylistModel* kworship::playlistModel()
354 return m_playlistModel;
357 void kworship::setupActions()
359 // Application
360 KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
361 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
363 // File management
364 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
365 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
366 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
367 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
369 // Display
370 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
372 m_mainDisplayAction = new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
373 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction );
374 connect(m_mainDisplayAction, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
376 KAction* clearDisplayAction = new KAction(KIcon("clear"), i18n("Clear display"), this);
377 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction);
378 connect(clearDisplayAction, SIGNAL(triggered()), this, SLOT(displayClear()));
380 // Playlist actions
381 m_playlistInsertAction = new KAction(KIcon("insert"), i18n("Insert into playlist"), this);
382 actionCollection()->addAction( QLatin1String("playlist_insert"), m_playlistInsertAction);
383 connect(m_playlistInsertAction, SIGNAL(triggered()), this, SLOT(playlistInsert()));
385 m_playlistDeleteAction = new KAction(KIcon("delete"), i18n("Delete from playlist"), this);
386 m_playlistDeleteAction->setEnabled(false);
387 actionCollection()->addAction( QLatin1String("playlist_delete"), m_playlistDeleteAction);
388 connect(m_playlistDeleteAction, SIGNAL(triggered()), this, SLOT(playlistDelete()));
390 m_playlistMoveUpAction = new KAction(KIcon("up"), i18n("Move playlist item up"), this);
391 m_playlistMoveUpAction->setEnabled(false);
392 actionCollection()->addAction( QLatin1String("playlist_move_up"), m_playlistMoveUpAction);
393 connect(m_playlistMoveUpAction, SIGNAL(triggered()), this, SLOT(playlistMoveUp()));
395 m_playlistMoveDownAction = new KAction(KIcon("down"), i18n("Move playlist item down"), this);
396 m_playlistMoveDownAction->setEnabled(false);
397 actionCollection()->addAction( QLatin1String("playlist_move_down"), m_playlistMoveDownAction);
398 connect(m_playlistMoveDownAction, SIGNAL(triggered()), this, SLOT(playlistMoveDown()));
401 void kworship::settingsChanged()
403 // If the main display is on and screen has changed, move it now
404 if (0 != m_mainDisplay && getCorrectDisplayScreen() != getCurrentDisplayScreen())
406 toggleMainDisplay(false);
407 toggleMainDisplay(true);
408 m_mainDisplayAction->setChecked(true);
412 int kworship::getCorrectDisplayScreen()
414 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
415 assert(0 != desktop);
417 int screens = desktop->numScreens();
418 int displayScreen = -1;
419 if (Settings::displayScreenChoose())
421 displayScreen = Settings::displayScreen();
423 if (-1 == displayScreen)
425 int currentScreen;
426 if (m_view->isVisible())
428 currentScreen = desktop->screenNumber(m_view);
430 else
432 currentScreen = desktop->primaryScreen();
434 displayScreen = 0;
435 if (displayScreen == currentScreen && displayScreen < screens-1)
437 ++displayScreen;
441 return displayScreen;
444 int kworship::getCurrentDisplayScreen()
446 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
447 assert(0 != desktop);
449 int previousScreen = desktop->screenNumber(m_mainDisplay);
451 return previousScreen;
454 void kworship::toggleMainDisplay(bool checked)
456 if (checked)
458 // Ensure the display exists
459 if (0 == m_mainDisplay)
461 m_mainDisplay = new KwLocalDisplay;
462 m_mainDisplay->setPrimary(true);
463 m_mainDisplay->setWindowTitle("kworship display");
464 m_displayController.attachChild(m_mainDisplay);
465 connect(m_mainDisplay, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
468 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
469 assert(0 != desktop);
471 int screens = desktop->numScreens();
472 int displayScreen = getCorrectDisplayScreen();
474 if (displayScreen >= 0 && displayScreen < screens)
476 m_mainDisplay->move(desktop->screenGeometry(displayScreen).topLeft());
479 if (!m_slideshowAction->isChecked())
481 m_mainDisplay->showFullScreen();
484 else
486 if (0 != m_mainDisplay)
488 m_mainDisplay->close();
493 void kworship::mainDisplayClosed()
495 m_mainDisplay->deleteLater();
496 m_mainDisplay = 0;
497 m_mainDisplayAction->setChecked(false);
500 void kworship::displayClear()
502 m_displayManager->background.clear();
503 m_displayManager->text.clear();
506 void kworship::toggleFullscreen(bool checked)
508 if (checked)
510 showFullScreen();
512 else
514 showNormal();
518 bool kworship::askToSave()
520 if (m_document->isModified())
522 switch (KMessageBox::questionYesNoCancel(this,
523 i18n("The current playlist has been modified. "
524 "These modifications will be lost if you continue without saving. "
525 "Would you like to save now?"),
526 i18n("Playlist is modified")))
528 case KMessageBox::Yes:
530 fileSave();
531 // If the document is still modified, save must have been cancelled
532 if (m_document->isModified())
534 return false;
537 break;
538 case KMessageBox::No:
539 break;
540 case KMessageBox::Cancel:
541 default:
543 return false;
545 break;
548 return true;
551 void kworship::fileNew()
553 if (askToSave())
555 clearDocument();
559 void kworship::fileOpen()
561 if (askToSave())
563 // Do the open operation
564 QStringList mimes = KwApplication::self()->filterManager()->loadMimeTypes();
566 KUrl defaultUrl("kfiledialog:///playlist");
567 if (m_document->isSaved())
569 defaultUrl = m_document->url();
572 KFileDialog dlg(defaultUrl, QString(), this);
573 dlg.setMimeFilter(mimes);
574 dlg.setOperationMode(KFileDialog::Opening);
575 dlg.setCaption(i18n("Open Playlist"));
576 dlg.setMode(KFile::File | KFile::ExistingOnly);
577 dlg.exec();
579 KUrl url = dlg.selectedUrl();
580 if (!url.isEmpty())
582 loadPlaylist(url);
587 void kworship::fileSave()
589 if (m_document->isSaved())
591 m_document->save();
593 else
595 fileSaveAs();
599 void kworship::fileSaveAs()
601 QStringList mimes = KwApplication::self()->filterManager()->saveMimeTypes();
603 KUrl defaultUrl("kfiledialog:///playlist");
604 if (m_document->isSaved())
606 defaultUrl = m_document->url();
609 QString defaultMime = m_document->mimeType();
610 if (defaultMime.isEmpty())
612 defaultMime = KwApplication::self()->filterManager()->defaultSaveMimeType();
615 KFileDialog dlg(defaultUrl, QString(), this);
616 dlg.setMimeFilter(mimes, defaultMime);
617 dlg.setOperationMode(KFileDialog::Saving);
618 dlg.setConfirmOverwrite(true);
619 dlg.setCaption(i18n("Save Playlist As"));
620 dlg.setMode(KFile::File);
621 dlg.exec();
623 KUrl url = dlg.selectedUrl();
624 if (!url.isEmpty())
626 // Find mime type
627 QString mime = dlg.currentMimeFilter();
629 // Use the appropriate filter
630 KwLoadSaveFilter* filter = KwApplication::self()->filterManager()->saveFilterFromMimeType(mime);
631 if (filter)
633 m_document->saveAs(filter, mime, url);
634 if (m_document->isModified())
636 KMessageBox::error(this,
637 i18n("Saving to \"%1\" failed.").arg(url.url()),
638 i18n("KWorship"));
641 else
643 KMessageBox::error(this,
644 i18n("No save filter exists for the mime type \"%1\"").arg(mime),
645 i18n("KWorship"));
650 void kworship::optionsPreferences()
652 //avoid to have 2 dialogs shown
653 if ( KConfigDialog::showDialog( "settings" ) ) {
654 return;
656 KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
658 QWidget *generalSettingsDlg = new QWidget(dialog);
659 ui_prefs_base.setupUi(generalSettingsDlg);
660 dialog->addPage(generalSettingsDlg, i18n("General"), "preferences-other", i18n("General"));
662 prefsDisplay *displaySettingsDlg = new prefsDisplay(dialog);
663 dialog->addPage(displaySettingsDlg, i18n("Display"), "video-projector", i18n("Display and Screen"));
665 prefsDatabase *songdbSettingsDlg = new prefsDatabase(dialog);
666 dialog->addPage(songdbSettingsDlg, i18n("Database"), "applications-multimedia", i18n("Database"));
668 QWidget *presentationSettingsDlg = new QWidget(dialog);
669 ui_prefsPresentations_base.setupUi(presentationSettingsDlg);
670 dialog->addPage(presentationSettingsDlg, i18n("Presentations"), "view-presentation", i18n("Presentations and Slideshows"));
672 // Let the plugins have their say
673 KwApplication::self()->pluginManager()->setupConfigDialog(dialog);
675 connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
676 connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(settingsChanged()));
677 dialog->setAttribute( Qt::WA_DeleteOnClose );
678 dialog->show();
681 void kworship::playlist_clicked(QModelIndex index)
683 KwPlaylistNode* node = m_playlistModel->itemFromIndex(index);
684 /// @todo Move this code to selection changed vfunc/slot of view so it can handle deselection
685 // A node must be selected and correspond to a playlist item
686 bool selected = (0 != node && 0 != node->playlistItem());
687 m_playlistDeleteAction->setEnabled(selected);
688 m_playlistMoveUpAction->setEnabled(selected);
689 m_playlistMoveDownAction->setEnabled(selected);
692 void kworship::playlist_doubleClicked(QModelIndex index)
694 KwPlaylistNode* node = m_playlistModel->itemFromIndex(index);
695 node->activate(m_displayManager);
698 void kworship::playlistReset()
700 // Connect up the new document
701 m_playlistModel->setRootNode(m_document->playlist()->getNode(0));
704 void kworship::playlistInsert()
706 KUrl defaultUrl("kfiledialog:///playlist_insert");
708 KUrl::List urls = KFileDialog::getOpenUrls(defaultUrl, QString(), this, i18n("Insert Files into Playlist"));
709 foreach (KUrl url, urls)
711 m_playlistModel->addFile(QModelIndex(), url);
715 void kworship::playlistDelete()
717 /// @todo Implement
720 void kworship::playlistMoveUp()
722 /// @todo Implement
725 void kworship::playlistMoveDown()
727 /// @todo Implement
730 #include <iostream>
731 /// Add the new docker to the interface.
732 void kworship::newDocker(QDockWidget* docker)
734 std::cout << docker << std::endl;
735 addDockWidget(Qt::LeftDockWidgetArea, docker);
738 void kworship::presentationDelete()
740 setPresentation(0, true);
741 presentationSelected(0);
744 void kworship::presentationSelected(int)
746 // Find the treeviews current index
747 QModelIndex index = m_selectPresTree->currentIndex();
748 UpPresentationsModel* model = m_presentationManager->presentationsModel();
749 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
750 if (0 != presNode)
752 m_view->listSlides->setModel(model);
753 m_view->listSlides->setRootIndex(index);
754 setPresentation(presNode->getItem());
756 else
758 m_view->listSlides->setModel(0);
759 setPresentation(0);
763 void kworship::presentationToggled(bool checked)
765 // Find the treeviews current index
766 QModelIndex index = m_selectPresTree->currentIndex();
767 UpPresentationsModel* model = m_presentationManager->presentationsModel();
768 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
769 if (0 != presNode)
771 if (checked)
773 presNode->getItem()->startSlideshow();
775 else
777 presNode->getItem()->stopSlideshow();
782 void kworship::presentationPreviousSlide()
784 // Find the treeviews current index
785 QModelIndex index = m_selectPresTree->currentIndex();
786 UpPresentationsModel* model = m_presentationManager->presentationsModel();
787 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
788 if (0 != presNode)
790 presNode->getItem()->previousSlide();
794 void kworship::presentationNextSlide()
796 // Find the treeviews current index
797 QModelIndex index = m_selectPresTree->currentIndex();
798 UpPresentationsModel* model = m_presentationManager->presentationsModel();
799 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
800 if (0 != presNode)
802 presNode->getItem()->nextSlide();
806 void kworship::presentationPreviousStep()
808 // Find the treeviews current index
809 QModelIndex index = m_selectPresTree->currentIndex();
810 UpPresentationsModel* model = m_presentationManager->presentationsModel();
811 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
812 if (0 != presNode)
814 presNode->getItem()->previousStep();
818 void kworship::presentationNextStep()
820 // Find the treeviews current index
821 QModelIndex index = m_selectPresTree->currentIndex();
822 UpPresentationsModel* model = m_presentationManager->presentationsModel();
823 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(index));
824 if (0 != presNode)
826 presNode->getItem()->nextStep();
830 void kworship::slide_doubleClicked(QModelIndex index)
832 // Find the listviews current index
833 UpPresentationsModel* model = m_presentationManager->presentationsModel();
834 QModelIndex parentIndex = model->parent(index);
835 UpPresentationNode* presNode = dynamic_cast<UpPresentationNode*>(model->itemFromIndex(parentIndex));
836 if (0 != presNode)
838 presNode->getItem()->goToSlide(index.row());
842 // Documents
843 void kworship::clearDocument()
845 delete m_document;
846 m_document = new KwDocument(0, QString(), KUrl(), this);
848 // Playlist will have changed
849 playlistReset();
851 // Wire up signals
852 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
855 // Presentations
856 void kworship::setPresentation(UpPresentation* presentation, bool alreadyDestroyed)
858 if (0 != m_currentPresentation)
860 // Stop the slideshow if its running
861 m_view->slideshows->setVisible(false);
862 if (!alreadyDestroyed)
864 m_currentPresentation->stopSlideshow();
865 disconnect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
866 disconnect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
867 disconnect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
868 disconnect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
869 disconnect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
870 disconnect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
871 disconnect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
873 slideshowStopped();
875 m_currentPresentation = presentation;
876 if (0 != m_currentPresentation)
878 connect(m_currentPresentation, SIGNAL(currentSlideshowChanged(QString)), this, SLOT(changeSlideshowExternal(QString)));
879 connect(m_currentPresentation, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
880 connect(m_currentPresentation, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
881 connect(m_currentPresentation, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
882 connect(m_currentPresentation, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
883 connect(m_currentPresentation, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
884 connect(m_currentPresentation, SIGNAL(destroyed(QObject*)), this, SLOT(presentationDelete()));
885 // update slideshows list
886 refreshSlideshows();
887 m_view->slideshows->setVisible(true);
889 if (m_currentPresentation->isSlideshowRunning())
891 slideshowStarted(m_currentPresentation->numSlidesInSlideshow());
892 slideshowSlideChanged(m_currentPresentation->currentSlideshowSlide(), m_currentPresentation->stepsInCurrentSlideshowSlide());
893 slideshowStepChanged(m_currentPresentation->currentSlideshowStep());
896 m_slideshowAction->setEnabled(0 != m_currentPresentation);
899 // Custom slideshows
901 void kworship::presentationComboReset()
903 m_selectPresTree->expandToDepth(0);
904 m_selectPresTree->setItemsExpandable(false);
907 void kworship::changeSlideshowCombo(QString name)
909 Q_ASSERT(0 != m_currentPresentation);
910 m_currentPresentation->setSlideshow(name);
911 refreshSlides();
914 void kworship::changeSlideshowExternal(QString name)
916 if (m_view->comboSlideshows->currentText() != name)
918 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(name));
919 refreshSlides();
923 void kworship::refreshSlideshows()
925 Q_ASSERT(0 != m_currentPresentation);
926 m_view->comboSlideshows->clear();
927 m_view->comboSlideshows->insertItems(0, m_currentPresentation->slideshows());
928 m_view->comboSlideshows->setCurrentIndex(m_view->comboSlideshows->findText(m_currentPresentation->currentSlideshow()));
931 void kworship::refreshSlides()
933 // Clear child cache
934 QModelIndex root = m_view->listSlides->rootIndex();
935 DefaultModelNode* node = m_presentationManager->presentationsModel()->itemFromIndex(root);
936 Q_ASSERT(0 != node);
937 node->clearChildCache();
939 // Force a refresh
940 m_view->listSlides->setRootIndex(root);
943 void kworship::addSlideshowLinkToPlaylist()
945 Q_ASSERT(0 != m_currentPresentation);
946 QUrl url = m_currentPresentation->url();
947 QString slideshow = m_currentPresentation->currentSlideshow();
948 /// @todo Implement me
950 void kworship::addSlideshowCopyToPlaylist()
952 Q_ASSERT(0 != m_currentPresentation);
953 QString slideshow = m_currentPresentation->currentSlideshow();
954 /// @todo Implement me
957 // From current presentation
959 void kworship::slideshowStarted(int numSlides)
961 // Hide the screen
962 if (0 != m_mainDisplay)
964 m_mainDisplay->hide();
967 // Clear the display
968 m_displayManager->background.clear();
969 m_displayManager->text.clear();
971 m_view->slideshows->setEnabled(false);
972 m_view->progressPresSlides->setMaximum(numSlides);
973 m_view->progressPresSlides->setVisible(true);
974 m_slideshowAction->setChecked(true);
977 void kworship::slideshowStopped()
979 m_view->slideshows->setEnabled(true);
980 m_view->progressPresSlides->setVisible(false);
981 m_view->progressPresSteps->setVisible(false);
982 m_slideshowAction->setChecked(false);
983 m_slideshowPrevSlideAction->setEnabled(false);
984 m_slideshowPrevStepAction->setEnabled(false);
985 m_slideshowNextStepAction->setEnabled(false);
986 m_slideshowNextSlideAction->setEnabled(false);
988 // Clear any preview left from the slideshow
989 m_displayManager->background.clear();
990 // Clear slide notes
991 m_slideNotes->document()->clear();
993 // Show the screen again
994 if (0 != m_mainDisplay)
996 m_mainDisplay->showFullScreen();
1000 void kworship::slideshowSlideChanged(int slide, int numSteps)
1002 m_view->progressPresSlides->setValue(slide + 1);
1003 m_view->progressPresSteps->setMaximum(numSteps);
1004 m_view->progressPresSteps->setVisible(numSteps > 1);
1006 m_slideshowPrevSlideAction->setEnabled(slide > 0);
1007 m_slideshowNextSlideAction->setEnabled(slide < m_view->progressPresSlides->maximum()-1);
1009 // live preview and notes
1010 m_slideNotes->document()->clear();
1011 assert(0 != m_currentPresentation);
1012 UpSlide* currentSlide = m_currentPresentation->slide(slide);
1013 if (0 != currentSlide)
1015 // live preview
1016 if (Settings::presLivePreview())
1018 m_displayManager->background.setImage(currentSlide->preview());
1020 // notes
1021 currentSlide->writeNotes(m_slideNotes->document());
1025 void kworship::slideshowStepChanged(int step)
1027 m_view->progressPresSteps->setValue(step + 1);
1029 bool firstSlide = (m_view->progressPresSlides->value() <= 1);
1030 bool lastSlide = (m_view->progressPresSlides->value() >= m_view->progressPresSlides->maximum());
1031 bool firstStep = firstSlide && (step <= 0);
1032 bool lastStep = lastSlide && (step >= m_view->progressPresSteps->maximum() - 1);
1033 m_slideshowPrevStepAction->setEnabled(!firstStep);
1034 m_slideshowNextStepAction->setEnabled(!lastStep);
1038 #include "kworship.moc"