KPresenter 1.6 backend: interval polling of document list
[kworship.git] / unipresent / kpresenter1 / UpKpr1Backend.cpp
blob051ae1d743515a578de659dc54e330c189115e6b
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 UpKpr1Backend.cpp
22 * @brief KPresenter 1 presentation manager.
23 * @author James Hogan <james@albanarts.com>
26 #include "UpKpr1Backend.h"
27 #include "UpKpr1AppsDcop.h"
28 #include "UpKpr1KpresenterDcop.h"
29 #include "UpKpr1PresentationDcop.h"
30 #include "UpKpr1Presentation.h"
32 #include <KLocale>
34 #include <QTimer>
37 * Constructors + destructor
40 /// Primary constructor.
41 UpKpr1Backend::UpKpr1Backend(QObject* parent)
42 : UpBackend(parent)
43 , m_presentations()
44 , m_refreshTimer(new QTimer(this))
46 connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
47 m_refreshTimer->start(15000);
48 activate();
51 /// Destructor.
52 UpKpr1Backend::~UpKpr1Backend()
57 * General meta information
60 QString UpKpr1Backend::id() const
62 return "KOffice1/KPresenter";
65 QString UpKpr1Backend::UpKpr1Backend::name() const
67 return i18n("KPresenter 1");
70 QString UpKpr1Backend::description() const
72 return i18n("Controls a running KPresenter 1 presentation");
75 QStringList UpKpr1Backend::mimeTypes() const
77 /// @todo Find mime types from kpresenter if possible
78 return QStringList()
79 << "application/x-kpresenter"
80 << "application/vnd.oasis.opendocument.presentation"
84 QIcon UpKpr1Backend::icon() const
86 return QIcon();
90 * Activation
93 bool UpKpr1Backend::isActive()
95 /// @todo Gently try again
96 return !m_presentations.empty();
99 bool UpKpr1Backend::activate()
101 refresh();
102 return true;
105 void UpKpr1Backend::deactivate()
110 * Presentation management
113 QList<UpPresentation*> UpKpr1Backend::presentations()
115 return m_presentations;
118 bool UpKpr1Backend::openPresentation(const QUrl& url)
120 return false;
124 * Private slots
127 /// Hit at intervals to refresh presentation list.
128 void UpKpr1Backend::refresh()
130 QList<UpPresentation*> lostPresentations = m_presentations;
132 UpKpr1AppsDcop apps;
133 QList<UpKpr1KpresenterDcop> kprs = apps.kpresenters();
134 foreach(UpKpr1KpresenterDcop kpr, kprs)
136 QList<UpKpr1PresentationDcop> docs = kpr.documents();
137 foreach (UpKpr1PresentationDcop doc, docs)
139 // Must have a view to be useful
140 UpKpr1ViewDcop view = doc.view();
141 if (view.isValid())
143 UpPresentation* presentation = presentationByDcop(doc.reference());
144 if (0 != presentation)
146 // Already exists, remove from lost list
147 lostPresentations.removeOne(presentation);
149 else
151 // New, create
152 presentation = new UpKpr1Presentation(doc, view, this);
153 m_presentations << presentation;
154 loadedPresentation(presentation);
160 // Anything left in lost list needs removing
161 foreach (UpPresentation* presentation, lostPresentations)
163 unloadedPresentation(presentation);
164 delete presentation;
165 m_presentations.removeOne(presentation);
170 * Private functions
173 /// Find a presentation identified by a dcop reference.
174 UpPresentation* UpKpr1Backend::presentationByDcop(const QStringList& dcopRef) const
176 foreach (UpPresentation* presentation, m_presentations)
178 if (static_cast<UpKpr1Presentation*>(presentation)->dcop().reference() == dcopRef)
180 return presentation;
183 return 0;