Convertion to CSS-like format of style sheets at top level (criteria, not styles)
[kworship.git] / unipresent / kpresenter2 / UpKpr2Presentation.cpp
blob382b225b1d3710821798ec4f4d5076912fd3fc34
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 /**
21 * @file UpKpr2Presentation.cpp
22 * @brief KPresenter 2 presentation.
23 * @author James Hogan <james@albanarts.com>
26 #include "UpKpr2Presentation.h"
27 #include "UpKpr2Slide.h"
28 #include "UpKpr2Backend.h"
30 #include <KLocale>
32 #include <QList>
33 #include <QVariant>
34 #include <QDBusReply>
36 #include <cassert>
39 * Constructors + destructor
42 /// Primary constructor.
43 UpKpr2Presentation::UpKpr2Presentation(QString service, QString path, UpKpr2Backend* backend, QObject* parent)
44 : UpPresentation(backend, parent)
45 , m_dbus(service, path, "org.kde.koffice.document")
46 , m_dbusView(0)
47 , m_url()
48 , m_customSlideshowsDialog(false)
50 if (m_dbus.isValid())
52 m_url = m_dbus.call("url").arguments().first().toString();
53 if ((QDBusReply<int>)m_dbus.call("viewCount") > 0)
55 QString viewPath = "/" + (QDBusReply<QString>)m_dbus.call("view", 0);
56 m_dbusView = new QDBusInterface(service, viewPath, "org.kde.koffice.presentation.view");
58 QDBusConnection::sessionBus().connect(service, viewPath, "org.kde.koffice.presentation.view", "activeCustomSlideShowChanged", this, SLOT(dbusCurrentSlideshowChanged(QString)));
59 QDBusConnection::sessionBus().connect(service, viewPath, "org.kde.koffice.presentation.view", "customSlideShowsModified", this, SIGNAL(customSlideshowsModified()));
61 QDBusConnection::sessionBus().connect(service, viewPath, "org.kde.koffice.presentation.view", "presentationStarted", this, SLOT(dbusScreenStarted(int)));
62 QDBusConnection::sessionBus().connect(service, viewPath, "org.kde.koffice.presentation.view", "presentationStopped", this, SIGNAL(slideshowStopped()));
64 QDBusConnection::sessionBus().connect(service, viewPath, "org.kde.koffice.presentation.view", "presentationPageChanged", this, SIGNAL(slideshowSlideChanged(int, int)));
65 QDBusConnection::sessionBus().connect(service, viewPath, "org.kde.koffice.presentation.view", "presentationStepChanged", this, SIGNAL(slideshowStepChanged(int)));
70 /// Destructor.
71 UpKpr2Presentation::~UpKpr2Presentation()
73 delete m_dbusView;
77 * Main interface
80 void UpKpr2Presentation::close()
84 QUrl UpKpr2Presentation::url() const
86 return m_url;
90 * Custom slideshows
93 QString UpKpr2Presentation::currentSlideshow()
95 if (m_dbusView)
97 QDBusReply<QString> result = m_dbusView->call("activeCustomSlideShow");
98 if (result.isValid())
100 QString slideshow = result;
101 if (!slideshow.isEmpty())
103 return slideshow;
107 return i18n("All slides");
110 QStringList UpKpr2Presentation::slideshows()
112 QStringList results;
113 results << i18n("All slides");
114 if (m_dbusView)
116 QDBusReply<QStringList> reply = m_dbusView->call("customSlideShows");
117 if (reply.isValid())
119 results << reply;
122 return results;
125 void UpKpr2Presentation::setSlideshow(QString slideshow)
127 if (slideshow == i18n("All slides"))
129 slideshow = QString();
131 if (m_dbusView)
133 m_dbusView->call("setActiveCustomSlideShow", slideshow);
137 int UpKpr2Presentation::numSlides()
139 if (m_dbusView)
141 QDBusReply<int> result = m_dbusView->call("numCustomSlideShowSlides");
142 if (result.isValid())
144 return result;
147 return 0;
150 UpSlide* UpKpr2Presentation::slide(int index)
152 return new UpKpr2Slide(this, index);
156 * Slideshow accessors
159 bool UpKpr2Presentation::isSlideshowRunning()
161 if (m_dbusView)
163 QDBusReply<bool> result = m_dbusView->call("isPresentationRunning");
164 if (result.isValid())
166 return result;
169 return false;
172 int UpKpr2Presentation::numSlidesInSlideshow()
174 if (m_dbusView)
176 QDBusReply<int> result = m_dbusView->call("numPresentationPages");
177 if (result.isValid())
179 // There's also the finish slide
180 /// @todo the finish slide is optional, ensure this is correct
181 return result - 1;
184 return 0;
187 int UpKpr2Presentation::currentSlideshowSlide()
189 if (m_dbusView)
191 QDBusReply<int> result = m_dbusView->call("currentPresentationPage");
192 if (result.isValid())
194 return result;
197 return 0;
200 int UpKpr2Presentation::stepsInCurrentSlideshowSlide()
202 if (m_dbusView)
204 QDBusReply<int> result = m_dbusView->call("numStepsInPresentationPage");
205 if (result.isValid())
207 int steps = result;
208 if (steps <= 0)
210 steps = 1;
212 return steps;
215 return 1;
218 int UpKpr2Presentation::currentSlideshowStep()
220 if (m_dbusView)
222 QDBusReply<int> result = m_dbusView->call("currentPresentationStep");
223 if (result.isValid())
225 return result;
228 return 0;
232 * Slideshow control
235 void UpKpr2Presentation::startSlideshow()
237 if (m_dbusView)
239 m_dbusView->call("presentationStart");
243 void UpKpr2Presentation::stopSlideshow()
245 if (m_dbusView)
247 m_dbusView->call("presentationStop");
251 void UpKpr2Presentation::goToSlide(int index)
253 if (m_dbusView)
255 m_dbusView->call("gotoPresentationPage", index);
259 void UpKpr2Presentation::previousSlide()
261 if (m_dbusView)
263 m_dbusView->call("presentationPrevSlide");
267 void UpKpr2Presentation::nextSlide()
269 if (m_dbusView)
271 m_dbusView->call("presentationNextSlide");
275 void UpKpr2Presentation::previousStep()
277 if (m_dbusView)
279 m_dbusView->call("presentationPrev");
283 void UpKpr2Presentation::nextStep()
285 if (m_dbusView)
287 m_dbusView->call("presentationNext");
292 * Backend specific interface.
295 /// Get the dbus interface.
296 QDBusInterface& UpKpr2Presentation::dbus()
298 return m_dbus;
301 /// Get the dbus view interface.
302 QDBusInterface* UpKpr2Presentation::dbusView()
304 return m_dbusView;
308 * DBus slots
311 void UpKpr2Presentation::dbusCurrentSlideshowChanged(QString slideshow)
313 if (slideshow.isEmpty())
315 slideshow = i18n("All slides");
317 currentSlideshowChanged(slideshow);
320 void UpKpr2Presentation::dbusScreenStarted(int pages)
322 /// @todo find whether this incldues the finish page or not
323 slideshowStarted(pages-1);
327 * Callbacks
330 void UpKpr2Presentation::callbackResult()
332 m_customSlideshowsDialog = false;
335 void UpKpr2Presentation::callbackError()
337 m_customSlideshowsDialog = false;
340 #include "UpKpr2Presentation.moc"