~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/kephal/service/dbus/dbusapi_screens.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2008 Aike J Sommer <dev@aikesommer.name>
 
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 as
 
6
 *   published by the Free Software Foundation; either version 2,
 
7
 *   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 Library 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
 
 
21
#include "dbusapi_screens.h"
 
22
#include "screens.h"
 
23
#include "outputs.h"
 
24
#include "screensadaptor.h"
 
25
 
 
26
#include <KDebug>
 
27
 
 
28
 
 
29
 
 
30
using namespace Kephal;
 
31
 
 
32
DBusAPIScreens::DBusAPIScreens(QObject * parent)
 
33
        : QObject(parent)
 
34
{
 
35
    new ScreensAdaptor(this);
 
36
    QDBusConnection dbus = QDBusConnection::sessionBus();
 
37
 
 
38
    const bool result = dbus.registerObject("/modules/kephal/Screens", this);
 
39
    kDebug() << "screens registered on the bus:" << result;
 
40
 
 
41
    connect(Screens::self(), SIGNAL(screenResized(Kephal::Screen *, QSize, QSize)), this, SLOT(screenResized(Kephal::Screen *, QSize, QSize)));
 
42
    connect(Screens::self(), SIGNAL(screenMoved(Kephal::Screen *, QPoint, QPoint)), this, SLOT(screenMoved(Kephal::Screen *, QPoint, QPoint)));
 
43
    connect(Screens::self(), SIGNAL(screenAdded(Kephal::Screen *)), this, SLOT(screenAdded(Kephal::Screen *)));
 
44
    connect(Screens::self(), SIGNAL(screenRemoved(int)), this, SLOT(screenRemovedSlot(int)));
 
45
}
 
46
 
 
47
void DBusAPIScreens::screenResized(Kephal::Screen * s, QSize oldSize, QSize newSize) {
 
48
    Q_UNUSED(oldSize)
 
49
    Q_UNUSED(newSize)
 
50
    emit screenResized(s->id());
 
51
}
 
52
 
 
53
void DBusAPIScreens::screenMoved(Kephal::Screen * s, QPoint oldPosition, QPoint newPosition) {
 
54
    Q_UNUSED(oldPosition)
 
55
    Q_UNUSED(newPosition)
 
56
    emit screenMoved(s->id());
 
57
}
 
58
 
 
59
void DBusAPIScreens::screenAdded(Kephal::Screen * s) {
 
60
    emit screenAdded(s->id());
 
61
}
 
62
 
 
63
void DBusAPIScreens::screenRemovedSlot(int id) {
 
64
    emit screenRemoved(id);
 
65
}
 
66
 
 
67
QSize DBusAPIScreens::size(int id)
 
68
{
 
69
    Screen * s = Screens::self()->screen(id);
 
70
    return s ? s->size() : QSize(0,0);
 
71
}
 
72
 
 
73
QPoint DBusAPIScreens::position(int id)
 
74
{
 
75
    Screen * s = Screens::self()->screen(id);
 
76
    return s ? s->position() : QPoint(0,0);
 
77
}
 
78
 
 
79
int DBusAPIScreens::numScreens()
 
80
{
 
81
    QList<Screen *> screens = Screens::self()->screens();
 
82
    return screens.size();
 
83
}
 
84
 
 
85
int DBusAPIScreens::id(int index)
 
86
{
 
87
    QList<Screen *> screens = Screens::self()->screens();
 
88
    if (index < screens.size()) {
 
89
        return screens[index]->id();
 
90
    }
 
91
    return -1;
 
92
}
 
93
 
 
94
int DBusAPIScreens::primaryScreen()
 
95
{
 
96
    Screen * s = Screens::self()->primaryScreen();
 
97
    return s ? s->id() : 0;
 
98
}
 
99
 
 
100
QStringList DBusAPIScreens::outputs(int id) {
 
101
    Screen * s = Screens::self()->screen(id);
 
102
    QStringList result;
 
103
    if (s) {
 
104
        foreach (Output * output, s->outputs()) {
 
105
            result << output->id();
 
106
        }
 
107
    }
 
108
    return result;
 
109
}
 
110
 
 
111
#ifndef NO_KDE
 
112
#include "dbusapi_screens.moc"
 
113
#endif
 
114