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

« back to all changes in this revision

Viewing changes to experimental/libkactivities/resourceinstance.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) 2011 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 "resourceinstance.h"
21
 
#include "manager_p.h"
22
 
 
23
 
#include <QCoreApplication>
24
 
 
25
 
namespace Activities {
26
 
 
27
 
#ifdef Q_OS_WIN64
28
 
__inline int toInt(WId wid)
29
 
{
30
 
        return (int)((__int64)wid);
31
 
}
32
 
 
33
 
#else
34
 
__inline int toInt(WId wid)
35
 
{
36
 
        return (int)wid;
37
 
}
38
 
#endif
39
 
 
40
 
class ResourceInstancePrivate {
41
 
public:
42
 
    WId wid;
43
 
    ResourceInstance::AccessReason reason;
44
 
    QUrl uri;
45
 
    QString mimetype;
46
 
    QString title;
47
 
    QString application;
48
 
 
49
 
    void closeResource();
50
 
    void openResource();
51
 
 
52
 
    enum Type {
53
 
        Accessed = 0,
54
 
        Opened = 1,
55
 
        Modified = 2,
56
 
        Closed = 3,
57
 
        FocusedIn = 4,
58
 
        FocusedOut = 5
59
 
    };
60
 
 
61
 
    static void registerResourceEvent(const QString &application, WId wid, const QUrl &uri, Type event, ResourceInstance::AccessReason reason)
62
 
    {
63
 
        Manager::self()->RegisterResourceEvent(application, toInt(wid), uri.toString(), uint(event), uint(reason));
64
 
    }
65
 
};
66
 
 
67
 
void ResourceInstancePrivate::closeResource()
68
 
{
69
 
    registerResourceEvent(application, wid, uri, Closed, reason);
70
 
}
71
 
 
72
 
void ResourceInstancePrivate::openResource()
73
 
{
74
 
    registerResourceEvent(application, wid, uri, Opened, reason);
75
 
}
76
 
 
77
 
ResourceInstance::ResourceInstance(WId wid, AccessReason reason, const QString &application, QObject *parent)
78
 
    : QObject(parent), d(new ResourceInstancePrivate())
79
 
{
80
 
    d->wid = wid;
81
 
    d->reason = reason;
82
 
    d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
83
 
 
84
 
}
85
 
 
86
 
ResourceInstance::ResourceInstance(WId wid, QUrl resourceUri, const QString &mimetype, const QString &title, AccessReason reason, const QString &application, QObject *parent)
87
 
    : QObject(parent), d(new ResourceInstancePrivate())
88
 
{
89
 
    d->wid = wid;
90
 
    d->reason = reason;
91
 
    d->uri = resourceUri;
92
 
    d->mimetype = mimetype;
93
 
    d->title = title;
94
 
    d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
95
 
 
96
 
    d->openResource();
97
 
}
98
 
 
99
 
ResourceInstance::~ResourceInstance()
100
 
{
101
 
    d->closeResource();
102
 
    delete d;
103
 
}
104
 
 
105
 
void ResourceInstance::notifyModified()
106
 
{
107
 
    d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::Modified, d->reason);
108
 
}
109
 
 
110
 
void ResourceInstance::notifyFocusedIn()
111
 
{
112
 
    d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedIn, d->reason);
113
 
}
114
 
 
115
 
void ResourceInstance::notifyFocusedOut()
116
 
{
117
 
    d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedOut, d->reason);
118
 
}
119
 
 
120
 
void ResourceInstance::setUri(const QUrl &newUri)
121
 
{
122
 
    if (d->uri == newUri)
123
 
        return;
124
 
 
125
 
    if (!d->uri.isEmpty()) {
126
 
        d->closeResource();
127
 
    }
128
 
 
129
 
    d->uri = newUri;
130
 
 
131
 
    d->openResource();
132
 
}
133
 
 
134
 
void ResourceInstance::setMimetype(const QString &mimetype)
135
 
{
136
 
    d->mimetype = mimetype;
137
 
    // TODO: update the service info
138
 
    Manager::self()->RegisterResourceMimeType(d->uri.toString(), mimetype);
139
 
}
140
 
 
141
 
void ResourceInstance::setTitle(const QString &title)
142
 
{
143
 
    d->title = title;
144
 
    // TODO: update the service info
145
 
    Manager::self()->RegisterResourceTitle(d->uri.toString(), title);
146
 
}
147
 
 
148
 
QUrl ResourceInstance::uri() const
149
 
{
150
 
    return d->uri;
151
 
}
152
 
 
153
 
QString ResourceInstance::mimetype() const
154
 
{
155
 
    return d->mimetype;
156
 
}
157
 
 
158
 
QString ResourceInstance::title() const
159
 
{
160
 
    return d->title;
161
 
}
162
 
 
163
 
WId ResourceInstance::winId() const
164
 
{
165
 
    return d->wid;
166
 
}
167
 
 
168
 
ResourceInstance::AccessReason ResourceInstance::accessReason() const
169
 
{
170
 
    return d->reason;
171
 
}
172
 
 
173
 
void ResourceInstance::notifyAccessed(const QUrl &uri, const QString &application)
174
 
{
175
 
    ResourceInstancePrivate::registerResourceEvent(
176
 
            application.isEmpty() ? QCoreApplication::instance()->applicationName() : application,
177
 
            0, uri, ResourceInstancePrivate::Accessed, User);
178
 
}
179
 
 
180
 
} // namespace Activities