~ubuntu-branches/ubuntu/saucy/kactivities/saucy-proposed

« back to all changes in this revision

Viewing changes to service/plugins/slc/slc.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Scott Kitterman
  • Date: 2012-11-20 13:47:27 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121120134727-vqzk04slqjoay3de
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Scott Kitterman ]
* Add new libkactivities-models1 library package (debian/control, .install,
  and .symbols)
* Add nepomuk-core-dev to build-depends
* Wildcard libkactivities6.install so that soversion changes don't cause
  build failures
* Update libkactivities6.symbols
* Update libkactivities-dev.install for new files for libkactivies-models
* Add new files to libkactivities-bin.install, including Activities kcm

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
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.
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 License
15
 
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
 
18
 
#include "slc.h"
19
 
#include "slcadaptor.h"
20
 
 
21
 
#include <QDBusConnection>
22
 
#include <KDebug>
23
 
#include <KWindowSystem>
24
 
#include <KUrl>
25
 
 
26
 
SlcPlugin::SlcPlugin(QObject * parent, const QVariantList & args)
27
 
    : Plugin(parent), focussedWindow(0)
28
 
{
29
 
    Q_UNUSED(args)
30
 
    // kDebug() << "We are in the SlcPlugin";
31
 
 
32
 
    QDBusConnection dbus = QDBusConnection::sessionBus();
33
 
    new SLCAdaptor(this);
34
 
    dbus.registerObject("/SLC", this);
35
 
 
36
 
    connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)),
37
 
            this, SLOT(activeWindowChanged(WId)));
38
 
}
39
 
 
40
 
SlcPlugin::~SlcPlugin()
41
 
{
42
 
}
43
 
 
44
 
void SlcPlugin::addEvents(const EventList & events)
45
 
{
46
 
    foreach (const Event & event, events) {
47
 
        switch (event.type) {
48
 
            case Event::FocussedIn:
49
 
            case Event::Opened:
50
 
                // kDebug() << "Event::FocussedIn" << focussedWindow << event.wid << event.uri;
51
 
 
52
 
                lastFocussedResource[event.wid] = event.uri;
53
 
 
54
 
                if (event.wid == focussedWindow) {
55
 
                    updateFocus(focussedWindow);
56
 
                }
57
 
 
58
 
                break;
59
 
 
60
 
            case Event::FocussedOut:
61
 
            case Event::Closed:
62
 
                // kDebug() << "Event::FocussedOut" << focussedWindow << event.wid << event.uri;
63
 
 
64
 
                if (lastFocussedResource[event.wid] == event.uri) {
65
 
                    lastFocussedResource[event.wid] = KUrl();
66
 
                }
67
 
 
68
 
                if (event.wid == focussedWindow) {
69
 
                    updateFocus();
70
 
                }
71
 
 
72
 
                break;
73
 
 
74
 
            default:
75
 
                // nothing
76
 
                break;
77
 
        }
78
 
    }
79
 
}
80
 
 
81
 
KUrl SlcPlugin::_focussedResourceURI()
82
 
{
83
 
    KUrl kuri;
84
 
 
85
 
    if (lastFocussedResource.contains(focussedWindow)) {
86
 
        kuri = lastFocussedResource[focussedWindow];
87
 
    } else {
88
 
        foreach (const KUrl & uri, sharedInfo()->windows()[focussedWindow].resources) {
89
 
            kuri = uri;
90
 
            break;
91
 
        }
92
 
    }
93
 
 
94
 
    return kuri;
95
 
}
96
 
 
97
 
QString SlcPlugin::focussedResourceURI()
98
 
{
99
 
    return _focussedResourceURI().url();
100
 
}
101
 
 
102
 
QString SlcPlugin::focussedResourceMimetype()
103
 
{
104
 
    return sharedInfo()->resources().contains(_focussedResourceURI()) ?
105
 
        sharedInfo()->resources()[_focussedResourceURI()].mimetype : QString();
106
 
}
107
 
 
108
 
QString SlcPlugin::focussedResourceTitle()
109
 
{
110
 
    return sharedInfo()->resources().contains(_focussedResourceURI()) ?
111
 
        sharedInfo()->resources()[_focussedResourceURI()].title : QString();
112
 
}
113
 
 
114
 
void SlcPlugin::activeWindowChanged(WId wid)
115
 
{
116
 
    if (wid == focussedWindow) return;
117
 
 
118
 
    focussedWindow = wid;
119
 
 
120
 
    updateFocus(wid);
121
 
}
122
 
 
123
 
void SlcPlugin::updateFocus(WId wid)
124
 
{
125
 
    // kDebug() << "SHARED INFO" << (void*) sharedInfo();
126
 
 
127
 
    if (wid == 0 || !sharedInfo()->windows().contains(wid)) {
128
 
        // kDebug() << "Clearing focus" << wid;
129
 
        emit focusChanged(QString(), QString(), QString());
130
 
 
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);
135
 
 
136
 
    }
137
 
}
138
 
 
139
 
KAMD_EXPORT_PLUGIN(SlcPlugin, "activitymanger_plugin_slc")