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

« back to all changes in this revision

Viewing changes to .pc/kubuntu-mobile-08-Add-title-to-activity-resources.diff/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 application;
47
 
 
48
 
    void closeResource();
49
 
    void openResource();
50
 
 
51
 
    enum Type {
52
 
        Accessed = 0,
53
 
        Opened = 1,
54
 
        Modified = 2,
55
 
        Closed = 3,
56
 
        FocusedIn = 4,
57
 
        FocusedOut = 5
58
 
    };
59
 
 
60
 
    static void registerResourceEvent(const QString &application, WId wid, const QUrl &uri, Type event, ResourceInstance::AccessReason reason)
61
 
    {
62
 
        Manager::self()->RegisterResourceEvent(application, toInt(wid), uri.toString(), uint(event), uint(reason));
63
 
    }
64
 
};
65
 
 
66
 
void ResourceInstancePrivate::closeResource()
67
 
{
68
 
    registerResourceEvent(application, wid, uri, Closed, reason);
69
 
}
70
 
 
71
 
void ResourceInstancePrivate::openResource()
72
 
{
73
 
    registerResourceEvent(application, wid, uri, Opened, reason);
74
 
}
75
 
 
76
 
ResourceInstance::ResourceInstance(WId wid, AccessReason reason, const QString &application, QObject *parent)
77
 
    : QObject(parent), d(new ResourceInstancePrivate())
78
 
{
79
 
    d->wid = wid;
80
 
    d->reason = reason;
81
 
    d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
82
 
 
83
 
}
84
 
 
85
 
ResourceInstance::ResourceInstance(WId wid, QUrl resourceUri, const QString &mimetype, AccessReason reason, const QString &application, QObject *parent)
86
 
    : QObject(parent), d(new ResourceInstancePrivate())
87
 
{
88
 
    d->wid = wid;
89
 
    d->reason = reason;
90
 
    d->uri = resourceUri;
91
 
    d->mimetype = mimetype;
92
 
    d->application = application.isEmpty() ? QCoreApplication::instance()->applicationName() : application;
93
 
 
94
 
    d->openResource();
95
 
}
96
 
 
97
 
ResourceInstance::~ResourceInstance()
98
 
{
99
 
    d->closeResource();
100
 
    delete d;
101
 
}
102
 
 
103
 
void ResourceInstance::notifyModified()
104
 
{
105
 
    d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::Modified, d->reason);
106
 
}
107
 
 
108
 
void ResourceInstance::notifyFocusedIn()
109
 
{
110
 
    d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedIn, d->reason);
111
 
}
112
 
 
113
 
void ResourceInstance::notifyFocusedOut()
114
 
{
115
 
    d->registerResourceEvent(d->application, d->wid, d->uri, ResourceInstancePrivate::FocusedOut, d->reason);
116
 
}
117
 
 
118
 
void ResourceInstance::setUri(const QUrl &newUri)
119
 
{
120
 
    if (d->uri == newUri)
121
 
        return;
122
 
 
123
 
    if (!d->uri.isEmpty()) {
124
 
        d->closeResource();
125
 
    }
126
 
 
127
 
    d->uri = newUri;
128
 
 
129
 
    d->openResource();
130
 
}
131
 
 
132
 
void ResourceInstance::setMimetype(const QString &mimetype)
133
 
{
134
 
    d->mimetype = mimetype;
135
 
    // TODO: update the service info
136
 
    Manager::self()->RegisterResourceMimeType(d->uri.toString(), mimetype);
137
 
}
138
 
 
139
 
QUrl ResourceInstance::uri() const
140
 
{
141
 
    return d->uri;
142
 
}
143
 
 
144
 
QString ResourceInstance::mimetype() const
145
 
{
146
 
    return d->mimetype;
147
 
}
148
 
 
149
 
WId ResourceInstance::winId() const
150
 
{
151
 
    return d->wid;
152
 
}
153
 
 
154
 
ResourceInstance::AccessReason ResourceInstance::accessReason() const
155
 
{
156
 
    return d->reason;
157
 
}
158
 
 
159
 
void ResourceInstance::notifyAccessed(const QUrl &uri, const QString &application)
160
 
{
161
 
    ResourceInstancePrivate::registerResourceEvent(
162
 
            application.isEmpty() ? QCoreApplication::instance()->applicationName() : application,
163
 
            0, uri, ResourceInstancePrivate::Accessed, User);
164
 
}
165
 
 
166
 
} // namespace Activities