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;
60
static void registerResourceEvent(const QString &application, WId wid, const QUrl &uri, Type event, ResourceInstance::AccessReason reason)
62
Manager::self()->RegisterResourceEvent(application, toInt(wid), uri.toString(), uint(event), uint(reason));
66
void ResourceInstancePrivate::closeResource()
68
registerResourceEvent(application, wid, uri, Closed, reason);
71
void ResourceInstancePrivate::openResource()
73
registerResourceEvent(application, wid, uri, Opened, reason);
76
ResourceInstance::ResourceInstance(WId wid, AccessReason reason, const QString &application, QObject *parent)
77
: QObject(parent), d(new ResourceInstancePrivate())
81
d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
85
ResourceInstance::ResourceInstance(WId wid, QUrl resourceUri, const QString &mimetype, AccessReason reason, const QString &application, QObject *parent)
86
: QObject(parent), d(new ResourceInstancePrivate())
91
d->mimetype = mimetype;
92
d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
97
ResourceInstance::~ResourceInstance()
103
void ResourceInstance::notifyModified()
105
d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::Modified, d->reason);
108
void ResourceInstance::notifyFocusedIn()
110
d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedIn, d->reason);
113
void ResourceInstance::notifyFocusedOut()
115
d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedOut, d->reason);
118
void ResourceInstance::setUri(const QUrl &newUri)
120
if (d->uri == newUri)
123
if (!d->uri.isEmpty()) {
132
void ResourceInstance::setMimetype(const QString &mimetype)
134
d->mimetype = mimetype;
135
// TODO: update the service info
136
Manager::self()->RegisterResourceMimeType(d->uri.toString(), mimetype);
139
QUrl ResourceInstance::uri() const
144
QString ResourceInstance::mimetype() const
149
WId ResourceInstance::winId() const
154
ResourceInstance::AccessReason ResourceInstance::accessReason() const
159
void ResourceInstance::notifyAccessed(const QUrl &uri, const QString &application)
161
ResourceInstancePrivate::registerResourceEvent(
162
application.isEmpty() ? QCoreApplication::instance()->applicationName() : application,
163
0, uri, ResourceInstancePrivate::Accessed, User);
166
} // namespace Activities