~ubuntu-branches/ubuntu/precise/kactivities/precise-proposed

« back to all changes in this revision

Viewing changes to lib/manager_p.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-13 11:53:27 UTC
  • Revision ID: package-import@ubuntu.com-20111213115327-vqhdel92qx65us8y
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.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 "manager_p.h"
 
21
 
 
22
#include <QDBusConnection>
 
23
 
 
24
#include <ktoolinvocation.h>
 
25
#include <kdebug.h>
 
26
 
 
27
namespace KActivities {
 
28
 
 
29
Manager * Manager::s_instance = NULL;
 
30
 
 
31
// #define ACTIVITY_MANAGER_DBUS_PATH   "org.kde.ActivityManager"
 
32
#define ACTIVITY_MANAGER_DBUS_PATH   "org.kde.kactivitymanagerd"
 
33
#define ACTIVITY_MANAGER_DBUS_OBJECT "/ActivityManager"
 
34
 
 
35
Manager::Manager()
 
36
    : org::kde::ActivityManager(
 
37
            ACTIVITY_MANAGER_DBUS_PATH,
 
38
            ACTIVITY_MANAGER_DBUS_OBJECT,
 
39
            QDBusConnection::sessionBus()
 
40
            )
 
41
{
 
42
    connect(&m_watcher, SIGNAL(serviceOwnerChanged(const QString &, const QString &, const QString &)),
 
43
            this, SLOT(serviceOwnerChanged(const QString &, const QString &, const QString &)));
 
44
}
 
45
 
 
46
Manager * Manager::self()
 
47
{
 
48
    if (!s_instance) {
 
49
        // check if the activity manager is already running
 
50
        if (!isActivityServiceRunning()) {
 
51
 
 
52
            // not running, trying to launch it
 
53
            QString error;
 
54
 
 
55
            int ret = KToolInvocation::startServiceByDesktopPath("kactivitymanagerd.desktop", QStringList(), &error);
 
56
            if (ret > 0) {
 
57
                kDebug() << "Activity: Couldn't start kactivitymanagerd: " << error << endl;
 
58
            }
 
59
 
 
60
            if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(ACTIVITY_MANAGER_DBUS_PATH)) {
 
61
                kDebug() << "Activity: The kactivitymanagerd service is still not registered";
 
62
            } else {
 
63
                kDebug() << "Activity: The kactivitymanagerd service has been registered";
 
64
            }
 
65
        }
 
66
 
 
67
        // creating a new instance of the class
 
68
        s_instance = new Manager();
 
69
    }
 
70
 
 
71
    return s_instance;
 
72
}
 
73
 
 
74
bool Manager::isActivityServiceRunning()
 
75
{
 
76
    return QDBusConnection::sessionBus().interface()->isServiceRegistered(ACTIVITY_MANAGER_DBUS_PATH);
 
77
}
 
78
 
 
79
void Manager::serviceOwnerChanged(const QString & serviceName, const QString & oldOwner, const QString & newOwner)
 
80
{
 
81
    Q_UNUSED(oldOwner)
 
82
 
 
83
    if (serviceName == ACTIVITY_MANAGER_DBUS_PATH) {
 
84
        emit presenceChanged(!newOwner.isEmpty());
 
85
    }
 
86
}
 
87
 
 
88
} // namespace KActivities
 
89