2
* Copyright (C) 2010 Ivan Cukic <ivan.cukic(at)kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2,
6
* or (at your option) any later version, as published by the Free
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details
14
* You should have received a copy of the GNU General Public
15
* License along with this program; if not, write to the
16
* Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "kactivitymanager_p.h"
22
#include <QDBusConnection>
24
#include <KToolInvocation>
27
KActivityManager * KActivityManager::s_instance = NULL;
29
// #define ACTIVITY_MANAGER_DBUS_PATH "org.kde.ActivityManager"
30
#define ACTIVITY_MANAGER_DBUS_PATH "org.kde.kactivitymanagerd"
31
#define ACTIVITY_MANAGER_DBUS_OBJECT "/ActivityManager"
33
KActivityManager::KActivityManager()
34
: org::kde::ActivityManager(
35
ACTIVITY_MANAGER_DBUS_PATH,
36
ACTIVITY_MANAGER_DBUS_OBJECT,
37
QDBusConnection::sessionBus()
40
connect(&m_watcher, SIGNAL(serviceOwnerChanged(const QString &, const QString &, const QString &)),
41
this, SLOT(serviceOwnerChanged(const QString &, const QString &, const QString &)));
44
KActivityManager * KActivityManager::self()
47
// check if the activity manager is already running
48
if (!isActivityServiceRunning()) {
50
// not running, trying to launch it
53
int ret = KToolInvocation::startServiceByDesktopPath("kactivitymanagerd.desktop", QStringList(), &error);
55
kDebug() << "Activity: Couldn't start kactivitymanagerd: " << error << endl;
58
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(ACTIVITY_MANAGER_DBUS_PATH)) {
59
kDebug() << "Activity: The kactivitymanagerd service is still not registered";
61
kDebug() << "Activity: The kactivitymanagerd service has been registered";
65
// creating a new instance of the class
66
s_instance = new KActivityManager();
72
bool KActivityManager::isActivityServiceRunning()
74
return QDBusConnection::sessionBus().interface()->isServiceRegistered(ACTIVITY_MANAGER_DBUS_PATH);
77
void KActivityManager::serviceOwnerChanged(const QString & serviceName, const QString & oldOwner, const QString & newOwner)
79
if (serviceName == ACTIVITY_MANAGER_DBUS_PATH) {
80
emit presenceChanged(!newOwner.isEmpty());