Basic openoffice.org control, and listening for new presentation documents, still...
[kworship.git] / unipresent / kpresenter2 / UpKpr2Process.cpp
blob50bde5b32a9a78a62e638a44ab7e350a437c3861
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 UpKpr2Process.cpp
22 * @brief KPresenter 2 process.
23 * @author James Hogan <james@albanarts.com>
26 #include "UpKpr2Process.h"
27 #include "UpKpr2Presentation.h"
28 #include "UpKpr2Backend.h"
30 #include "compiler.h"
32 #include <QDBusConnection>
33 #include <QDBusInterface>
34 #include <QDBusReply>
35 #include <QStringList>
38 * Constructors + destructor
41 /// Primary constructor.
42 UpKpr2Process::UpKpr2Process(QString serviceName, UpKpr2Backend* parent)
43 : QObject(parent)
44 , m_backend(parent)
45 , m_serviceName(serviceName)
47 // Set up document event signals so we know when to create/remove documents
48 QDBusConnection::sessionBus().connect(serviceName, "/application", "org.kde.koffice.application", "documentOpened", this, SLOT(dbusPresentationOpened(QString)));
49 QDBusConnection::sessionBus().connect(serviceName, "/application", "org.kde.koffice.application", "documentClosed", this, SLOT(dbusPresentationClosed(QString)));
51 // Get the current list of documents
52 QDBusInterface application(m_serviceName, "/application", "org.kde.koffice.application");
53 if (application.isValid())
55 QStringList docs = application.call("getDocuments").arguments().first().toStringList();
56 foreach (QString doc, docs)
58 QDBusInterface application(m_serviceName, doc, "org.kde.koffice.document");
59 int views = (QDBusReply<int>)application.call("viewCount");
60 if (views > 0)
62 dbusPresentationOpened(doc);
68 /// Destructor.
69 UpKpr2Process::~UpKpr2Process()
71 foreach (UpKpr2Presentation* pres, m_presentations)
73 unloadedPresentation(pres);
74 delete pres;
79 * Basic accessors
82 /// Get the service name.
83 QString UpKpr2Process::serviceName() const
85 return m_serviceName;
88 /// Get a list of presentations.
89 QList<UpKpr2Presentation*> UpKpr2Process::presentations()
91 return m_presentations.values();
95 * Private slots
98 /// Indicates that a new presentation has been made available.
99 void UpKpr2Process::dbusPresentationOpened(QString docName)
101 Q_ASSERT(!docName.isEmpty());
102 StringHashPresentation::iterator it = m_presentations.find(docName);
103 if (likely(m_presentations.end() == it))
105 UpKpr2Presentation* pres = new UpKpr2Presentation(m_serviceName, docName, m_backend, this);
106 m_presentations[docName] = pres;
107 loadedPresentation(pres);
111 /// Indicates that an old presentation is no longer available.
112 void UpKpr2Process::dbusPresentationClosed(QString docName)
114 Q_ASSERT(!docName.isEmpty());
115 StringHashPresentation::iterator it = m_presentations.find(docName);
116 if (likely(m_presentations.end() != it))
118 UpKpr2Presentation* presentation = *it;
119 m_presentations.erase(it);
120 unloadedPresentation(presentation);
121 delete presentation;