1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008-2009 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 UpOkProcess.cpp
22 * @brief Okular process.
23 * @author James Hogan <james@albanarts.com>
26 #include "UpOkProcess.h"
27 #include "UpOkPresentation.h"
28 #include "UpOkBackend.h"
32 #include <QDBusConnection>
33 #include <QDBusInterface>
35 #include <QStringList>
38 * Constructors + destructor
41 /// Primary constructor.
42 UpOkProcess::UpOkProcess(QString serviceName
, UpOkBackend
* parent
)
45 , m_serviceName(serviceName
)
47 // Get the current document
48 QDBusInterface
application(m_serviceName
, "/okular", "org.kde.okular");
49 if (application
.isValid())
51 QString doc
= application
.call("currentDocument").arguments().first().toString();
52 dbusPresentationOpened(doc
);
57 UpOkProcess::~UpOkProcess()
59 foreach (UpOkPresentation
* pres
, m_presentations
)
61 unloadedPresentation(pres
);
70 /// Get the service name.
71 QString
UpOkProcess::serviceName() const
76 /// Get a list of presentations.
77 QList
<UpOkPresentation
*> UpOkProcess::presentations()
79 return m_presentations
.values();
86 /// Indicates that a new presentation has been made available.
87 void UpOkProcess::dbusPresentationOpened(QString docName
)
89 Q_ASSERT(!docName
.isEmpty());
90 StringHashPresentation::iterator it
= m_presentations
.find(docName
);
91 if (likely(m_presentations
.end() == it
))
93 UpOkPresentation
* pres
= new UpOkPresentation(m_serviceName
, m_backend
, this);
94 m_presentations
[docName
] = pres
;
95 loadedPresentation(pres
);
99 /// Indicates that an old presentation is no longer available.
100 void UpOkProcess::dbusPresentationClosed(QString docName
)
102 Q_ASSERT(!docName
.isEmpty());
103 StringHashPresentation::iterator it
= m_presentations
.find(docName
);
104 if (likely(m_presentations
.end() != it
))
106 UpOkPresentation
* presentation
= *it
;
107 m_presentations
.erase(it
);
108 unloadedPresentation(presentation
);