1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
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"
32 #include <QDBusConnection>
33 #include <QDBusInterface>
35 #include <QStringList>
38 * Constructors + destructor
41 /// Primary constructor.
42 UpKpr2Process::UpKpr2Process(QString serviceName
, UpKpr2Backend
* 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");
62 dbusPresentationOpened(doc
);
69 UpKpr2Process::~UpKpr2Process()
71 foreach (UpKpr2Presentation
* pres
, m_presentations
)
73 unloadedPresentation(pres
);
82 /// Get the service name.
83 QString
UpKpr2Process::serviceName() const
88 /// Get a list of presentations.
89 QList
<UpKpr2Presentation
*> UpKpr2Process::presentations()
91 return m_presentations
.values();
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
);