BibleGateway: Fix bitrotted scraper, use mobile.*
[kworship.git] / kworship / kworship.cpp
blob64a45fe258781fa2ac52ae414eff8042babdfd0a
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 "prefsPresentations.h"
26 #include "KwDatabaseSetup.h"
27 #include "KwDocument.h"
28 #include "KwApplication.h"
29 #include "KwPluginManager.h"
30 #include "KwFilterManager.h"
31 #include "KwLoadSaveFilter.h"
33 #include "KwPlaylistNode.h"
34 #include "KwPlaylistList.h"
35 #include "KwPlaylistNote.h"
36 #include "KwPlaylistText.h"
37 #include "KwPlaylistImage.h"
38 #include "KwPlaylistVideo.h"
39 #include "KwPlaylistModel.h"
41 #include "KwCssStyleSheet.h"
42 #include "KwCssStyleRule.h"
44 #include "KwDisplayManager.h"
45 #include "KwLocalDisplay.h"
46 #include "KwLocalDisplayPreview.h"
48 #include "KwMediaManager.h"
49 #include "KwMediaControlWidget.h"
51 #include "UpManager.h"
52 #include "UpPresentationsModel.h"
53 #include "UpPresentation.h"
54 #include "UpPresentationNode.h"
55 #include "UpSlide.h"
57 #include <kconfigdialog.h>
58 #include <kstatusbar.h>
59 #include <kaction.h>
60 #include <kactionmenu.h>
61 #include <kmenu.h>
62 #include <ktoggleaction.h>
63 #include <kactioncollection.h>
64 #include <kstandardaction.h>
65 #include <KDE/KLocale>
66 #include <KFileDialog>
67 #include <KMessageBox>
69 #include <phonon/audiooutput.h>
71 #include <QtGui/QDropEvent>
72 #include <QtGui/QPainter>
73 #include <QColor>
74 #include <QDesktopWidget>
75 #include <QToolBar>
76 #include <QToolButton>
77 #include <QComboBox>
78 #include <QSqlDatabase>
79 #include <QHeaderView>
80 #include <QTextEdit>
82 kworship::kworship()
83 : KXmlGuiWindow()
84 , m_view(new kworshipView(this))
85 , m_displayManager(0)
86 , m_document(0)
87 , m_presentationManager(new UpManager(this))
88 , m_currentPresentation(0)
89 , m_printer(0)
91 m_playlistModel = new KwPlaylistModel;
92 clearDocument();
94 // set up presentation backends
95 m_presentationManager->loadBackends();
97 m_mainDisplay = 0;
98 m_previewDisplay = 0;
100 // accept dnd
101 setAcceptDrops(true);
103 // tell the KXmlGuiWindow that this is indeed the main widget
104 setCentralWidget(m_view);
106 // then, setup our actions
107 setupActions();
109 // add a status bar
110 statusBar()->show();
112 // a call to KXmlGuiWindow::setupGUI() populates the GUI
113 // with actions, using KXMLGUI.
114 // It also applies the saved mainwindow settings, if any, and ask the
115 // mainwindow to automatically save settings if changed: window size,
116 // toolbar position, icon size, etc.
117 setupGUI();
119 // Setup the dockers
120 addDockWidget(Qt::LeftDockWidgetArea, m_view->dockPresentation);
121 addDockWidget(Qt::RightDockWidgetArea, m_view->dockPreview);
122 addDockWidget(Qt::RightDockWidgetArea, m_view->dockLyrics);
123 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockThemes);
124 addDockWidget(Qt::BottomDockWidgetArea, m_view->dockNowPlaying);
126 // Setup some stuff in the tree
127 #if 0
128 #define TREE_ITEM(name, string, parent) QTreeWidgetItem* name = new QTreeWidgetItem(parent); name->setText(0, tr(string));
130 TREE_ITEM(song1, "Our God is a great big God", m_view->treeWidget);
131 TREE_ITEM(song1_style, "(style)", song1);
132 TREE_ITEM(song1_style_1, "Mode", song1_style);
133 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);
134 TREE_ITEM(song1_v2, "He's higher than a skyscraper\nAnd he's deeper than a submarine.", song1);
135 TREE_ITEM(song1_v3, "He's wider than the universe\nAnd beyond my wildest dreams.", song1);
137 #undef TREE_ITEM
138 #endif
140 // Playlist
141 m_document->playlist()->addClass("beachy");
143 KwCssStyleSheet* styleRules = new KwCssStyleSheet;
145 KwCssStyleRule beachyTheme;
146 beachyTheme.setCriteriaClasses(QSet<QString>() << "beachy");
147 beachyTheme.setStyle<QBrush>("background.brush", Qt::black);
148 beachyTheme.setStyle<KwResourceLink>("background.image.src", KUrl("file:///home/james/media/images/projector/misc/love-god-light.jpg"));
149 styleRules->addRule(beachyTheme);
151 KwCssStyleRule bibleTheme;
152 bibleTheme.setCriteriaKeys(KwCssStyleRule::KeyList() << KwCssScopeKey(KwCssScopeKey::registerScopeType("bible")));
153 bibleTheme.setStyle<QBrush>("background.brush", Qt::black);
154 bibleTheme.setStyle<KwResourceLink>("background.image.src", KUrl("file:///home/james/media/images/projector/misc/bible.jpg"));
155 styleRules->addRule(bibleTheme);
157 m_document->playlist()->addStyleSheet(styleRules);
159 m_view->treePlaylist->setModel(m_playlistModel);
160 m_view->treePlaylist->setSelectionMode(QAbstractItemView::ExtendedSelection);
161 m_view->treePlaylist->setExpandsOnDoubleClick(false);
162 m_view->treePlaylist->setDragEnabled(true);
163 m_view->treePlaylist->setAcceptDrops(true);
165 connect(m_view->treePlaylist, SIGNAL(clicked(QModelIndex)), this, SLOT(playlist_clicked(QModelIndex)));
166 connect(m_view->treePlaylist, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(playlist_doubleClicked(QModelIndex)));
168 m_mediaManager = new KwMediaManager();
169 m_mediaManager->linkAudio(new Phonon::AudioOutput(Phonon::MusicCategory));
170 m_displayManager = new KwDisplayManager(&m_displayController, m_mediaManager);
172 m_previewDisplay = new KwLocalDisplayPreview;
173 m_view->layoutPreview->addWidget(m_previewDisplay);
174 m_displayController.attachChild(m_previewDisplay);
176 KwMediaControlWidget* mediaWidget = new KwMediaControlWidget(m_mediaManager, m_view->dockNowPlaying);
177 m_view->layoutNowPlaying->addWidget(mediaWidget);
180 * Presentation
183 // Drop down list of presentations
184 QComboBox* selectPresCombo = m_view->comboPresentations;
185 m_selectPresTree = new QTreeView(this);
186 m_selectPresTree->header()->hide();
187 selectPresCombo->setModel(m_presentationManager->presentationsModel());
188 selectPresCombo->setView(m_selectPresTree);
189 presentationComboReset();
190 connect(m_presentationManager->presentationsModel(), SIGNAL(modelReset()), this, SLOT(presentationComboReset()));
191 connect(selectPresCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(presentationSelected(int)));
193 // Custom slideshow selector
194 m_view->slideshows->setVisible(false);
195 connect(m_view->comboSlideshows, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(changeSlideshowCombo(QString)));
197 QToolBar* customSlideshowsToolBar = new QToolBar(i18n("Custom Slideshows"));
198 customSlideshowsToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
199 m_view->slideshows->layout()->addWidget(customSlideshowsToolBar);
200 // Add slideshow to playlist
201 KActionMenu* addSlideshowToPlaylistAction = new KActionMenu(KIcon("list-add"), i18n("Add Slideshow to Playlist"), customSlideshowsToolBar);
202 addSlideshowToPlaylistAction->setDelayed(false);
203 customSlideshowsToolBar->addAction(addSlideshowToPlaylistAction);
205 KAction* asLinkAction = new KAction(KIcon("insert-link"), i18n("Add Link to Slideshow into Playlist"), customSlideshowsToolBar);
206 connect(asLinkAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowLinkToPlaylist()));
207 addSlideshowToPlaylistAction->addAction(asLinkAction);
210 KAction* asCopyAction = new KAction(KIcon("edit-copy"), i18n("Save Copy of Slideshow into Playlist"), customSlideshowsToolBar);
211 connect(asCopyAction, SIGNAL(triggered(bool)), this, SLOT(addSlideshowCopyToPlaylist()));
212 addSlideshowToPlaylistAction->addAction(asCopyAction);
215 // Presentations toolbar
216 QToolBar* presToolBar = new QToolBar("Presentations");
217 m_view->layoutPresentationsToolbar->layout()->addWidget(presToolBar);
219 KActionMenu* openPresAction = new KActionMenu(KIcon("document-open"), "Open Presentation", presToolBar);
220 openPresAction->setDelayed(true);
221 presToolBar->addAction(openPresAction);
223 KAction* refreshPresAction = new KAction(KIcon("view-refresh"), "Refresh Presentation List", presToolBar);
224 presToolBar->addAction(refreshPresAction);
226 KAction* closePresAction = new KAction(KIcon("fileclose"), "Close Presentation", presToolBar);
227 presToolBar->addAction(closePresAction);
229 KToggleAction* fullscreenPresAction = new KToggleAction(KIcon("view-fullscreen"), "Fullscreen Presentation Mode", presToolBar);
230 presToolBar->addAction(fullscreenPresAction);
232 // Slide list
233 connect(m_view->listSlides, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slide_doubleClicked(QModelIndex)));
235 // Slides toolbar
236 QToolBar* slidesToolBar = new QToolBar("Slides");
237 slidesToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
238 slidesToolBar->setIconSize(QSize(32,32));
239 m_view->layoutSlidesToolbar->layout()->addWidget(slidesToolBar);
241 m_slideshowPrevSlideAction = new KAction(KIcon("media-skip-backward"), i18n("Previous Slide"), slidesToolBar);
242 connect(m_slideshowPrevSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousSlide()));
243 slidesToolBar->addAction(m_slideshowPrevSlideAction);
245 m_slideshowPrevStepAction = new KAction(KIcon("media-seek-backward"), i18n("Previous Step"), slidesToolBar);
246 connect(m_slideshowPrevStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousStep()));
247 slidesToolBar->addAction(m_slideshowPrevStepAction);
249 m_slideshowNextStepAction = new KAction(KIcon("media-seek-forward"), i18n("Next Step"), slidesToolBar);
250 connect(m_slideshowNextStepAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextStep()));
251 slidesToolBar->addAction(m_slideshowNextStepAction);
253 m_slideshowNextSlideAction = new KAction(KIcon("media-skip-forward"), i18n("Next Slide"), slidesToolBar);
254 connect(m_slideshowNextSlideAction, SIGNAL(triggered(bool)), this, SLOT(presentationNextSlide()));
255 slidesToolBar->addAction(m_slideshowNextSlideAction);
257 m_slideshowAction = new KToggleAction(KIcon("view-presentation"), i18n("Start/Stop Slideshow"), slidesToolBar);
258 connect(m_slideshowAction, SIGNAL(toggled(bool)), this, SLOT(presentationToggled(bool)));
259 slidesToolBar->addAction(m_slideshowAction);
261 // Slide notes
262 m_slideNotes = new QTextEdit();
263 m_slideNotes->setReadOnly(true);
264 m_slideNotes->setWindowTitle(i18n("Slide Notes"));
265 m_slideNotes->show();
267 // Ensure the controls are as when slideshow is stopped
268 m_slideshowAction->setEnabled(false);
269 slideshowStopped();
272 * Display startup
275 // Show the display on startup?
276 if (Settings::displayShowStartup())
278 // If there's only one screen, don't bother showing display.
279 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
280 assert(0 != desktop);
281 if (desktop->numScreens() > 1)
283 toggleMainDisplay(true);
284 m_mainDisplayAction->setChecked(true);
289 kworship::~kworship()
291 delete m_slideNotes;
295 * Public interface
298 /// Load a specified playlist.
299 void kworship::loadPlaylist(const KUrl& url)
301 // Find mime type
302 KMimeType::Ptr mimeType = KMimeType::findByUrl(url);
303 QString mime = mimeType->name();
305 // Use the appropriate filter
306 KwLoadSaveFilter* filter = KwApplication::self()->filterManager()->loadFilterFromMimeType(mime);
307 if (filter)
309 KwDocument* newDoc = filter->load(url, mime);
310 if (0 != newDoc)
312 delete m_document;
313 m_document = newDoc;
315 // Playlist will have changed
316 playlistReset();
318 // Wire up signals
319 connect(m_document, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
321 else
323 KMessageBox::error(this,
324 i18n("Loading of \"%1\" failed.").arg(url.url()),
325 i18n("KWorship"));
328 else
330 KMessageBox::error(this,
331 i18n("No load filter exists for the mime type \"%1\"").arg(mime),
332 i18n("KWorship"));
337 * Accessors
340 /// Get the main display manager.
341 KwDisplayManager* kworship::displayManager()
343 return m_displayManager;
346 /// Get the current document.
347 KwDocument* kworship::document()
349 return m_document;
352 /// Get the playlist model.
353 KwPlaylistModel* kworship::playlistModel()
355 return m_playlistModel;
358 void kworship::setupActions()
360 // Application
361 KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
362 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
364 // File management
365 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
366 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
367 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
368 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
370 // Display
371 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
373 m_mainDisplayAction = new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
374 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction );
375 connect(m_mainDisplayAction, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
377 KAction* clearDisplayAction = new KAction(KIcon("clear"), i18n("Clear display"), this);
378 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction);
379 connect(clearDisplayAction, SIGNAL(triggered()), this, SLOT(displayClear()));
381 // Playlist actions
382 m_playlistInsertAction = new KAction(KIcon("insert"), i18n("Insert into playlist"), this);
383 actionCollection()->addAction( QLatin1String("playlist_insert"), m_playlistInsertAction);
384 connect(m_playlistInsertAction, SIGNAL(triggered()), this, SLOT(playlistInsert()));
386 m_playlistDeleteAction = new KAction(KIcon("delete"), i18n("Delete from playlist"), this);
387 m_playlistDeleteAction->setEnabled(false);
388 actionCollection()->addAction( QLatin1String("playlist_delete"), m_playlistDeleteAction);
389 connect(m_playlistDeleteAction, SIGNAL(triggered()), this, SLOT(playlistDelete()));
391 m_playlistMoveUpAction = new KAction(KIcon("up"), i18n("Move playlist item up"), this);
392 m_playlistMoveUpAction->setEnabled(false);
393 actionCollection()->addAction( QLatin1String("playlist_move_up"), m_playlistMoveUpAction);
394 connect(m_playlistMoveUpAction, SIGNAL(triggered()), this, SLOT(playlistMoveUp()));
396 m_playlistMoveDownAction = new KAction(KIcon("down"), i18n("Move playlist item down"), this);
397 m_playlistMoveDownAction->setEnabled(false);
398 actionCollection()->addAction( QLatin1String("playlist_move_down"), m_playlistMoveDownAction);
399 connect(m_playlistMoveDownAction, SIGNAL(triggered()), this, SLOT(playlistMoveDown()));
402 void kworship::settingsChanged()
404 // If the main display is on and screen has changed, move it now
405 if (0 != m_mainDisplay && getCorrectDisplayScreen() != getCurrentDisplayScreen())
407 toggleMainDisplay(false);
408 toggleMainDisplay(true);
409 m_mainDisplayAction->setChecked(true);
413 int kworship::getCorrectDisplayScreen()
415 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
416 assert(0 != desktop);
418 int screens = desktop->numScreens();
419 int displayScreen = -1;
420 if (Settings::displayScreenChoose())
422 displayScreen = Settings::displayScreen();
424 if (-1 == displayScreen)
426 int currentScreen;
427 if (m_view->isVisible())
429 currentScreen = desktop->screenNumber(m_view);
431 else
433 currentScreen = desktop->primaryScreen();
435 displayScreen = 0;
436 if (displayScreen == currentScreen && displayScreen < screens-1)
438 ++displayScreen;
442 return displayScreen;
445 int kworship::getCurrentDisplayScreen()
447 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
448 assert(0 != desktop);
450 int previousScreen = desktop->screenNumber(m_mainDisplay);
452 return previousScreen;
455 void kworship::toggleMainDisplay(bool checked)
457 if (checked)
459 // Ensure the display exists
460 if (0 == m_mainDisplay)
462 m_mainDisplay = new KwLocalDisplay;
463 m_mainDisplay->setPrimary(true);
464 m_mainDisplay->setWindowTitle("kworship display");
465 m_displayController.attachChild(m_mainDisplay);
466 connect(m_mainDisplay, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
469 QDesktopWidget* desktop = qobject_cast<QApplication*>(QCoreApplication::instance())->desktop();
470 assert(0 != desktop);
472 int screens = desktop->numScreens();
473 int displayScreen = getCorrectDisplayScreen();
475 if (displayScreen >= 0 && displayScreen < screens)
477 m_mainDisplay->move(desktop->screenGeometry(displayScreen).topLeft());
480 if (!m_slideshowAction->isChecked())
482 m_mainDisplay->showFullScreen();
485 else
487 if (0 != m_mainDisplay)
489 m_mainDisplay->close();
494 void kworship::mainDisplayClosed()
496 m_mainDisplay->deleteLater();
497 m_mainDisplay = 0;
498 m_mainDisplayAction->setChecked(false);
501 void kworship::displayClear()
503 m_displayManager->background.clear();
504 m_displayManager->text.clear();
507 void kworship::toggleFullscreen(bool checked)
509 if (checked)
511 showFullScreen();
513 else
515 showNormal();
519 bool kworship::askToSave()
521 if (m_document->isModified())
523 switch (KMessageBox::questionYesNoCancel(this,
524 i18n("The current playlist has been modified. "
525 "These modifications will be lost if you continue without saving. "
526 "Would you like to save now?"),
527 i18n("Playlist is modified")))
529 case KMessageBox::Yes:
531 fileSave();
532 // If the document is still modified, save must have been cancelled
533 if (m_document->isModified())
535 return false;
538 break;
539 case KMessageBox::No:
540 break;
541 case KMessageBox::Cancel:
542 default:
544 return false;
546 break;
549 return true;
552 void kworship::fileNew()
554 if (askToSave())
556 clearDocument();
560 void kworship::fileOpen()
562 if (askToSave())
564 // Do the open operation
565 QStringList mimes = KwApplication::self()->filterManager()->loadMimeTypes();
567 KUrl defaultUrl("kfiledialog:///playlist");
568 if (m_document->isSaved())
570 defaultUrl = m_document->url();
573 KFileDialog dlg(defaultUrl, QString(), this);
574 dlg.setMimeFilter(mimes);
575 dlg.setOperationMode(KFileDialog::Opening);
576 dlg.setCaption(i18n("Open Playlist"));
577 dlg.setMode(KFile::File | KFile::ExistingOnly);
578 dlg.exec();
580 KUrl url = dlg.selectedUrl();
581 if (!url.isEmpty())
583 loadPlaylist(url);
588 void kworship::fileSave()
590 if (m_document->isSaved())
592 m_document->save();
594 else
596 fileSaveAs();
600 void kworship::fileSaveAs()
602 QStringList mimes = KwApplication::self()->filterManager()->saveMimeTypes();
604 KUrl defaultUrl("kfiledialog:///playlist");
605 if (m_document->isSaved())
607 defaultUrl = m_document->url();
610 QString defaultMime = m_document->mimeType();
611 if (defaultMime.isEmpty())
613 defaultMime = KwApplication::self()->filterManager()->defaultSaveMimeType();
616 KFileDialog dlg(defaultUrl, QString(), this);
617 dlg.setMimeFilter(mimes, defaultMime);
618 dlg.setOperationMode(KFileDialog::Saving);
619 dlg.setConfirmOverwrite(true);
620 dlg.setCaption(i18n("Save Playlist As"));
621 dlg.setMode(KFile::File);
622 dlg.exec();
624 KUrl url = dlg.selectedUrl();
625 if (!url.isEmpty())
627 // Find mime type
628 QString mime = dlg.currentMimeFilter();
630 // Use the appropriate filter
631 KwLoadSaveFilter* filter = KwApplication::self()->filterManager()->saveFilterFromMimeType(mime);
632 if (filter)
634 m_document->saveAs(filter, mime, url);
635 if (m_document->isModified())
637 KMessageBox::error(this,
638 i18n("Saving to \"%1\" failed.").arg(url.url()),
639 i18n("KWorship"));
642 else
644 KMessageBox::error(this,
645 i18n("No save filter exists for the mime type \"%1\"").arg(mime),
646 i18n("KWorship"));
651 void kworship::optionsPreferences()
653 //avoid to have 2 dialogs shown
654 if ( KConfigDialog::showDialog( "settings" ) ) {
655 return;
657 KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
659 QWidget *generalSettingsDlg = new QWidget(dialog);
660 ui_prefs_base.setupUi(generalSettingsDlg);
661 dialog->addPage(generalSettingsDlg, i18n("General"), "preferences-other", i18n("General"));
663 prefsDisplay *displaySettingsDlg = new prefsDisplay(dialog);
664 dialog->addPage(displaySettingsDlg, i18n("Display"), "video-projector", i18n("Display and Screen"));
666 prefsDatabase *songdbSettingsDlg = new prefsDatabase(dialog);
667 dialog->addPage(songdbSettingsDlg, i18n("Database"), "applications-multimedia", i18n("Database"));
669 prefsPresentations *presentationsSettingsDlg = new prefsPresentations(dialog);
670 dialog->addPage(presentationsSettingsDlg, 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"