~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/kworkspace/kactivitymanager_p.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2010 Ivan Cukic <ivan.cukic(at)kde.org>
 
3
 *
 
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
 
7
 *   Software Foundation
 
8
 *
 
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
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#include "kactivitymanager_p.h"
 
21
 
 
22
#include <QDBusConnection>
 
23
 
 
24
#include <KToolInvocation>
 
25
#include <KDebug>
 
26
 
 
27
KActivityManager * KActivityManager::s_instance = NULL;
 
28
 
 
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"
 
32
 
 
33
KActivityManager::KActivityManager()
 
34
    : org::kde::ActivityManager(
 
35
            ACTIVITY_MANAGER_DBUS_PATH,
 
36
            ACTIVITY_MANAGER_DBUS_OBJECT,
 
37
            QDBusConnection::sessionBus()
 
38
            )
 
39
{
 
40
    connect(&m_watcher, SIGNAL(serviceOwnerChanged(const QString &, const QString &, const QString &)),
 
41
            this, SLOT(serviceOwnerChanged(const QString &, const QString &, const QString &)));
 
42
}
 
43
 
 
44
KActivityManager * KActivityManager::self()
 
45
{
 
46
    if (!s_instance) {
 
47
        // check if the activity manager is already running
 
48
        if (!isActivityServiceRunning()) {
 
49
 
 
50
            // not running, trying to launch it
 
51
            QString error;
 
52
 
 
53
            int ret = KToolInvocation::startServiceByDesktopPath("kactivitymanagerd.desktop", QStringList(), &error);
 
54
            if (ret > 0) {
 
55
                kDebug() << "Activity: Couldn't start kactivitymanagerd: " << error << endl;
 
56
            }
 
57
 
 
58
            if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(ACTIVITY_MANAGER_DBUS_PATH)) {
 
59
                kDebug() << "Activity: The kactivitymanagerd service is still not registered";
 
60
            } else {
 
61
                kDebug() << "Activity: The kactivitymanagerd service has been registered";
 
62
            }
 
63
        }
 
64
 
 
65
        // creating a new instance of the class
 
66
        s_instance = new KActivityManager();
 
67
    }
 
68
 
 
69
    return s_instance;
 
70
}
 
71
 
 
72
bool KActivityManager::isActivityServiceRunning()
 
73
{
 
74
    return QDBusConnection::sessionBus().interface()->isServiceRegistered(ACTIVITY_MANAGER_DBUS_PATH);
 
75
}
 
76
 
 
77
void KActivityManager::serviceOwnerChanged(const QString & serviceName, const QString & oldOwner, const QString & newOwner)
 
78
{
 
79
    if (serviceName == ACTIVITY_MANAGER_DBUS_PATH) {
 
80
        emit presenceChanged(!newOwner.isEmpty());
 
81
    }
 
82
}
 
83