2
* Copyright (C) 2011 Ivan Cukic ivan.cukic(at)kde.org
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of
7
* the License, or (at your option) any later version.
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 License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "slcadaptor.h"
21
#include <QDBusConnection>
23
#include <KWindowSystem>
26
SlcPlugin::SlcPlugin(QObject * parent, const QVariantList & args)
27
: Plugin(parent), focussedWindow(0)
30
// kDebug() << "We are in the SlcPlugin";
32
QDBusConnection dbus = QDBusConnection::sessionBus();
34
dbus.registerObject("/SLC", this);
36
connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)),
37
this, SLOT(activeWindowChanged(WId)));
40
SlcPlugin::~SlcPlugin()
44
void SlcPlugin::addEvents(const EventList & events)
46
foreach (const Event & event, events) {
48
case Event::FocussedIn:
50
// kDebug() << "Event::FocussedIn" << focussedWindow << event.wid << event.uri;
52
lastFocussedResource[event.wid] = event.uri;
54
if (event.wid == focussedWindow) {
55
updateFocus(focussedWindow);
60
case Event::FocussedOut:
62
// kDebug() << "Event::FocussedOut" << focussedWindow << event.wid << event.uri;
64
if (lastFocussedResource[event.wid] == event.uri) {
65
lastFocussedResource[event.wid] = KUrl();
68
if (event.wid == focussedWindow) {
81
KUrl SlcPlugin::_focussedResourceURI()
85
if (lastFocussedResource.contains(focussedWindow)) {
86
kuri = lastFocussedResource[focussedWindow];
88
foreach (const KUrl & uri, sharedInfo()->windows()[focussedWindow].resources) {
97
QString SlcPlugin::focussedResourceURI()
99
return _focussedResourceURI().url();
102
QString SlcPlugin::focussedResourceMimetype()
104
return sharedInfo()->resources().contains(_focussedResourceURI()) ?
105
sharedInfo()->resources()[_focussedResourceURI()].mimetype : QString();
108
QString SlcPlugin::focussedResourceTitle()
110
return sharedInfo()->resources().contains(_focussedResourceURI()) ?
111
sharedInfo()->resources()[_focussedResourceURI()].title : QString();
114
void SlcPlugin::activeWindowChanged(WId wid)
116
if (wid == focussedWindow) return;
118
focussedWindow = wid;
123
void SlcPlugin::updateFocus(WId wid)
125
// kDebug() << "SHARED INFO" << (void*) sharedInfo();
127
if (wid == 0 || !sharedInfo()->windows().contains(wid)) {
128
// kDebug() << "Clearing focus" << wid;
129
emit focusChanged(QString(), QString(), QString());
131
} else if (wid == focussedWindow) {
132
// kDebug() << "It is the currently focused window" << wid;
133
SharedInfo::ResourceData resourceData = sharedInfo()->resources()[_focussedResourceURI()];
134
emit focusChanged(focussedResourceURI(), resourceData.mimetype, resourceData.title);
139
KAMD_EXPORT_PLUGIN(SlcPlugin, "activitymanger_plugin_slc")