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

« back to all changes in this revision

Viewing changes to libs/kworkspace/kactivityinfo.h

  • 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
#ifndef ACTIVITY_INFO_H
 
20
#define ACTIVITY_INFO_H
 
21
 
 
22
#include <QObject>
 
23
#include <QWidget>
 
24
#include <QString>
 
25
#include <QStringList>
 
26
 
 
27
#include <KUrl>
 
28
#include <kdemacros.h>
 
29
 
 
30
/**
 
31
 * This class provides info about an activity. Most methods in it
 
32
 * require a Nepomuk backend running.
 
33
 *
 
34
 * @see KActivityConsumer for info about activities
 
35
 *
 
36
 * @since 4.5
 
37
 */
 
38
class KDE_EXPORT KActivityInfo: public QObject
 
39
{
 
40
    Q_OBJECT
 
41
 
 
42
    Q_PROPERTY(KUrl uri READ uri)
 
43
    Q_PROPERTY(KUrl resourceUri READ resourceUri)
 
44
    Q_PROPERTY(QString id READ id)
 
45
    Q_PROPERTY(QString name READ name)
 
46
 
 
47
public:
 
48
    explicit KActivityInfo(const QString & activityId, QObject *parent=0);
 
49
    ~KActivityInfo();
 
50
 
 
51
    /**
 
52
     * @return true if the activity represented by this object exists and is valid
 
53
     */
 
54
    bool isValid() const;
 
55
 
 
56
    /**
 
57
     * Set of predefined resource types provided for convenience
 
58
     */
 
59
    enum ResourceType {
 
60
        UnspecifiedResource = 0,
 
61
        DocumentResource    = 1, ///< @see nfo:Document
 
62
        FolderResource      = 2, ///< @see nfo:Folder
 
63
        ApplicationResource = 3, ///< @see nfo:Application
 
64
        ContactResource     = 4, ///< @see nco:Contact
 
65
        LocationResource    = 5  ///< @see pimo:Location
 
66
 
 
67
    };
 
68
 
 
69
    /**
 
70
     * Specifies which parts of this class are functional
 
71
     */
 
72
    enum Availability {
 
73
        Nothing = 0,             ///< No activity info provided (isValid is false)
 
74
        BasicInfo = 1,           ///< Basic info is provided
 
75
        Everything = 2           ///< Everything is available
 
76
    };
 
77
 
 
78
    /**
 
79
     * State of the activity
 
80
     */
 
81
    enum State {
 
82
        Invalid  = 0,
 
83
        Running  = 2,
 
84
        Starting = 3,
 
85
        Stopped  = 4,
 
86
        Stopping = 5
 
87
    };
 
88
 
 
89
    /**
 
90
     * @returns what info is provided by this instance of KActivityInfo
 
91
     */
 
92
    Availability availability() const;
 
93
 
 
94
    /**
 
95
     * Associates the resource with the activity represented by this
 
96
     * KActivityInfo object.
 
97
     * @param resourceUrl url of the resource
 
98
     * @param resourceType type of the resource
 
99
     * @note Functional only when availability is Everything
 
100
     */
 
101
    void associateResource(const KUrl & resourceUrl, ResourceType resourceType = UnspecifiedResource);
 
102
 
 
103
    /**
 
104
     * Associates the resource with the activity represented by this
 
105
     * KActivityInfo object.
 
106
     * @param resourceUrl url of the resource
 
107
     * @param resourceType type of the resource
 
108
     * @note Functional only when availability is Everything
 
109
     */
 
110
    void associateResource(const KUrl & resourceUrl, const KUrl & resourceType);
 
111
 
 
112
    /**
 
113
     * Removes the association of this activity and the specified
 
114
     * resource.
 
115
     * @param resourceUrl url of the resource
 
116
     * @note Functional only when availability is Everything
 
117
     */
 
118
    void disassociateResource(const KUrl & resourceUrl);
 
119
 
 
120
    /**
 
121
     * @param resourceType type of the resource
 
122
     * @returns a list of resources of the specified type that are
 
123
     * associated with this activity. If the type is not specified,
 
124
     * all associated resources are returned,
 
125
     * @note Functional only when availability is Everything
 
126
     */
 
127
    QList < KUrl > associatedResources(ResourceType resourceType = UnspecifiedResource) const;
 
128
 
 
129
    /**
 
130
     * @param resourceType type of the resource
 
131
     * @returns a list of resources of the specified type that are
 
132
     * associated with this activity. If the type is not specified,
 
133
     * all associated resources are returned,
 
134
     * @note Functional only when availability is Everything
 
135
     */
 
136
    QList < KUrl > associatedResources(const KUrl & resourceType) const;
 
137
 
 
138
    /**
 
139
     * @returns the URI of this activity. The same URI is used by
 
140
     * activities KIO slave.
 
141
     * @note Functional only when availability is Everything
 
142
     */
 
143
    KUrl uri() const;
 
144
 
 
145
    /**
 
146
     * @returns the Nepomuk resource URI of this activity
 
147
     * @note Functional only when availability is Everything
 
148
     */
 
149
    KUrl resourceUri() const;
 
150
 
 
151
    /**
 
152
     * @returns the id of the activity
 
153
     */
 
154
    QString id() const;
 
155
 
 
156
    /**
 
157
     * @returns the name of the activity
 
158
     * @note Functional when availability is BasicInfo or Everything
 
159
     */
 
160
    QString name() const;
 
161
 
 
162
    /**
 
163
     * @returns the icon of the activity. Icon can be a
 
164
     * freedesktop.org name or a file path. Or empty if
 
165
     * no icon is set.
 
166
     * @note Functional only when availability is Everything
 
167
     */
 
168
    QString icon() const;
 
169
 
 
170
    /**
 
171
     * @returns the state of the activity
 
172
     */
 
173
    State state() const;
 
174
 
 
175
    /**
 
176
     * This function is provided for convenience.
 
177
     * @returns the name of the specified activity
 
178
     * @param id id of the activity
 
179
     */
 
180
    static QString name(const QString & id);
 
181
 
 
182
Q_SIGNALS:
 
183
    /**
 
184
     * Emitted when the activity's name, icon or description is changed
 
185
     */
 
186
    void infoChanged();
 
187
 
 
188
    /**
 
189
     * Emitted when the activity is added
 
190
     */
 
191
    void added();
 
192
 
 
193
    /**
 
194
     * Emitted when the activity is removed
 
195
     */
 
196
    void removed();
 
197
 
 
198
    /**
 
199
     * Emitted when the activity is started
 
200
     */
 
201
    void started();
 
202
 
 
203
    /**
 
204
     * Emitted when the activity is stopped
 
205
     */
 
206
    void stopped();
 
207
 
 
208
    /**
 
209
     * Emitted when the activity changes state
 
210
     * @param state new state of the activity
 
211
     */
 
212
    void stateChanged(KActivityInfo::State state);
 
213
 
 
214
private:
 
215
    class Private;
 
216
    Private * const d;
 
217
 
 
218
    Q_PRIVATE_SLOT(d, void activityStateChanged(const QString &, int))
 
219
    Q_PRIVATE_SLOT(d, void added(const QString &))
 
220
    Q_PRIVATE_SLOT(d, void removed(const QString &))
 
221
    Q_PRIVATE_SLOT(d, void started(const QString &))
 
222
    Q_PRIVATE_SLOT(d, void stopped(const QString &))
 
223
    Q_PRIVATE_SLOT(d, void infoChanged(const QString &))
 
224
};
 
225
 
 
226
#endif // ACTIVITY_INFO_H