2
* Copyright (C) 2011 Ivan Cukic <ivan.cukic(at)kde.org>
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
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
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.
20
#include "resourceinstance.h"
21
#include "manager_p.h"
23
#include <QCoreApplication>
25
namespace Activities {
28
__inline int toInt(WId wid)
30
return (int)((__int64)wid);
34
__inline int toInt(WId wid)
40
class ResourceInstancePrivate {
43
ResourceInstance::AccessReason reason;
61
static void registerResourceEvent(const QString &application, WId wid, const QUrl &uri, Type event, ResourceInstance::AccessReason reason)
63
Manager::self()->RegisterResourceEvent(application, toInt(wid), uri.toString(), uint(event), uint(reason));
67
void ResourceInstancePrivate::closeResource()
69
registerResourceEvent(application, wid, uri, Closed, reason);
72
void ResourceInstancePrivate::openResource()
74
registerResourceEvent(application, wid, uri, Opened, reason);
77
ResourceInstance::ResourceInstance(WId wid, AccessReason reason, const QString &application, QObject *parent)
78
: QObject(parent), d(new ResourceInstancePrivate())
82
d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
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())
92
d->mimetype = mimetype;
94
d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
99
ResourceInstance::~ResourceInstance()
105
void ResourceInstance::notifyModified()
107
d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::Modified, d->reason);
110
void ResourceInstance::notifyFocusedIn()
112
d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedIn, d->reason);
115
void ResourceInstance::notifyFocusedOut()
117
d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedOut, d->reason);
120
void ResourceInstance::setUri(const QUrl &newUri)
122
if (d->uri == newUri)
125
if (!d->uri.isEmpty()) {
134
void ResourceInstance::setMimetype(const QString &mimetype)
136
d->mimetype = mimetype;
137
// TODO: update the service info
138
Manager::self()->RegisterResourceMimeType(d->uri.toString(), mimetype);
141
void ResourceInstance::setTitle(const QString &title)
144
// TODO: update the service info
145
Manager::self()->RegisterResourceTitle(d->uri.toString(), title);
148
QUrl ResourceInstance::uri() const
153
QString ResourceInstance::mimetype() const
158
QString ResourceInstance::title() const
163
WId ResourceInstance::winId() const
168
ResourceInstance::AccessReason ResourceInstance::accessReason() const
173
void ResourceInstance::notifyAccessed(const QUrl &uri, const QString &application)
175
ResourceInstancePrivate::registerResourceEvent(
176
application.isEmpty() ? QCoreApplication::instance()->applicationName() : application,
177
0, uri, ResourceInstancePrivate::Accessed, User);
180
} // namespace Activities