~ubuntu-branches/ubuntu/utopic/kde4libs/utopic

« back to all changes in this revision

Viewing changes to .pc/kubuntu-mobile-01-Ported-the-new-libkactivities.diff/experimental/libkactivities/kactivitymanager_p.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:53:22 UTC
  • mfrom: (1.14.11)
  • Revision ID: package-import@ubuntu.com-20111216135322-joct6gdco90t3koc
Tags: 4:4.7.90-0ubuntu1
* New upstream beta release
* Remove kubuntu_mobile patches, kactivities is split out now and they 
  will be out of date, keep 
  kubuntu-mobile-07-serviceAvailabilityChanged-bool-signal.diff
  for binary compatibility reasons

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.h>
25
 
#include <kdebug.h>
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