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

« back to all changes in this revision

Viewing changes to libs/kworkspace/kactivityconsumer.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 library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License version 2 as published by the Free Software Foundation.
 
7
 *
 
8
 * This library is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Library General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Library General Public License
 
14
 * along with this library; see the file COPYING.LIB.  If not, write to
 
15
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
 * Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "kactivityconsumer.h"
 
20
#include "kactivityconsumer_p.h"
 
21
#include "kactivitymanager_p.h"
 
22
 
 
23
#include <KDebug>
 
24
 
 
25
KActivityConsumer::KActivityConsumer(QObject * parent)
 
26
    : QObject(parent), d(new KActivityConsumerPrivate())
 
27
{
 
28
    connect(
 
29
        KActivityManager::self(), SIGNAL(CurrentActivityChanged(const QString &)),
 
30
        this,       SIGNAL(currentActivityChanged(const QString &))
 
31
    );
 
32
}
 
33
 
 
34
KActivityConsumer::~KActivityConsumer()
 
35
{
 
36
    delete d;
 
37
}
 
38
 
 
39
// macro defines a shorthand for validating and returning a d-bus result
 
40
// @param TYPE type of the result
 
41
// @param METHOD invocation of the d-bus method
 
42
// @param DEFAULT value to be used if the reply was not valid
 
43
#define KACTIVITYCONSUMER_DBUS_RETURN(TYPE, METHOD, DEFAULT)  \
 
44
    QDBusReply < TYPE > dbusReply = METHOD;                   \
 
45
    if (dbusReply.isValid()) {                                \
 
46
        return dbusReply.value();                             \
 
47
    } else {                                                  \
 
48
        kDebug() << "d-bus reply was invalid"                 \
 
49
                 << dbusReply.value()                         \
 
50
                 << dbusReply.error();                        \
 
51
        return DEFAULT;                                       \
 
52
    }
 
53
 
 
54
QString KActivityConsumer::currentActivity() const
 
55
{
 
56
    KACTIVITYCONSUMER_DBUS_RETURN(
 
57
        QString, KActivityManager::self()->CurrentActivity(), QString() );
 
58
}
 
59
 
 
60
QStringList KActivityConsumer::listActivities(KActivityInfo::State state) const
 
61
{
 
62
    KACTIVITYCONSUMER_DBUS_RETURN(
 
63
        QStringList, KActivityManager::self()->ListActivities(state), QStringList() );
 
64
}
 
65
 
 
66
QStringList KActivityConsumer::listActivities() const
 
67
{
 
68
    KACTIVITYCONSUMER_DBUS_RETURN(
 
69
        QStringList, KActivityManager::self()->ListActivities(), QStringList() );
 
70
}
 
71
 
 
72
QStringList KActivityConsumer::activitiesForResource(const KUrl & uri)
 
73
{
 
74
    KACTIVITYCONSUMER_DBUS_RETURN(
 
75
        QStringList, KActivityManager::self()->ActivitiesForResource(uri.url()), QStringList() );
 
76
}
 
77
 
 
78
#undef KACTIVITYCONSUMER_DBUS_RETURN
 
79
 
 
80
void KActivityConsumer::resourceAccessed(const KUrl & uri)
 
81
{
 
82
    KActivityManager::self()->NotifyResourceAccessed(
 
83
        QCoreApplication::instance()->applicationName(),
 
84
        uri.url()
 
85
    );
 
86
}
 
87
 
 
88
void KActivityConsumer::resourceAccessed(WId wid, const KUrl & uri, ResourceAction action)
 
89
{
 
90
    switch (action) {
 
91
        case Opened:
 
92
            KActivityManager::self()->NotifyResourceOpened(
 
93
                    QCoreApplication::instance()->applicationName(),
 
94
                    (uint)wid,
 
95
                    uri.url()
 
96
                );
 
97
            break;
 
98
 
 
99
        case Modified:
 
100
            KActivityManager::self()->NotifyResourceModified(
 
101
                    (uint)wid,
 
102
                    uri.url()
 
103
                );
 
104
            break;
 
105
 
 
106
        case Closed:
 
107
            KActivityManager::self()->NotifyResourceClosed(
 
108
                    (uint)wid,
 
109
                    uri.url()
 
110
                );
 
111
            break;
 
112
    }
 
113
}
 
114
 
 
115
KActivityConsumer::ServiceStatus KActivityConsumer::serviceStatus()
 
116
{
 
117
    if (!KActivityManager::isActivityServiceRunning()) {
 
118
        return NotRunning;
 
119
    }
 
120
 
 
121
    if (!KActivityManager::self()->IsBackstoreAvailable()) {
 
122
        return BareFunctionality;
 
123
    }
 
124
 
 
125
    return FullFunctionality;
 
126
}
 
127