2
* Copyright 2008 Aike J Sommer <dev@aikesommer.name>
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.
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 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.
21
#include "dbusoutputs.h"
25
#include "simpleoutput.h"
30
DBusOutputs::DBusOutputs(QObject * parent)
33
m_interface = new org::kde::Kephal::Outputs(
35
"/modules/kephal/Outputs",
36
QDBusConnection::sessionBus(),
39
if (! m_interface->isValid()) {
46
const QStringList ids = m_interface->outputIds();
47
foreach (const QString& id, ids) {
48
QPoint pos = m_interface->position(id);
49
QSize size = m_interface->size(id);
50
bool connected = m_interface->isConnected(id);
51
bool activated = m_interface->isActivated(id);
52
//qDebug() << "adding an output" << id << "with geom: " << pos << size;
54
SimpleOutput * output = new SimpleOutput(this,
61
m_outputs.append(output);
64
output->_setRate(m_interface->rate(id));
65
int rotation = m_interface->rotation(id);
66
output->_setRotation((Rotation) rotation);
67
output->_setReflectX(m_interface->reflectX(id));
68
output->_setReflectY(m_interface->reflectY(id));
70
outputConnectedSlot(id);
74
connect(m_interface, SIGNAL(outputConnected(QString)), this, SLOT(outputConnectedSlot(QString)));
75
connect(m_interface, SIGNAL(outputDisconnected(QString)), this, SLOT(outputDisconnectedSlot(QString)));
76
connect(m_interface, SIGNAL(outputActivated(QString)), this, SLOT(outputActivatedSlot(QString)));
77
connect(m_interface, SIGNAL(outputDeactivated(QString)), this, SLOT(outputDeactivatedSlot(QString)));
78
connect(m_interface, SIGNAL(outputResized(QString)), this, SLOT(outputResizedSlot(QString)));
79
connect(m_interface, SIGNAL(outputMoved(QString)), this, SLOT(outputMovedSlot(QString)));
80
connect(m_interface, SIGNAL(outputRotated(QString)), this, SLOT(outputRotatedSlot(QString)));
81
connect(m_interface, SIGNAL(outputRateChanged(QString)), this, SLOT(outputRateChangedSlot(QString)));
82
connect(m_interface, SIGNAL(outputReflected(QString)), this, SLOT(outputReflectedSlot(QString)));
85
QList<Output *> DBusOutputs::outputs()
87
QList<Output *> result;
88
foreach(SimpleOutput * output, m_outputs) {
89
result.append(output);
94
void DBusOutputs::activateLayout(const QMap<Output *, QRect> & layout)
99
bool DBusOutputs::isValid() {
103
void DBusOutputs::outputConnectedSlot(QString id) {
104
SimpleOutput * o = (SimpleOutput *) output(id);
106
o->_setConnected(true);
108
int numSizes = m_interface->numAvailableSizes(id);
110
for (int i = 0; i < numSizes; ++i) {
111
sizes << m_interface->availableSize(id, i);
113
o->_setAvailableSizes(sizes);
115
int numRates = m_interface->numAvailableRates(id);
117
for (int i = 0; i < numRates; ++i) {
118
rates << m_interface->availableRate(id, i);
120
o->_setAvailableRates(rates);
122
emit outputConnected(o);
126
void DBusOutputs::outputDisconnectedSlot(QString id) {
127
SimpleOutput * o = (SimpleOutput *) output(id);
129
o->_setConnected(false);
130
emit outputDisconnected(o);
134
void DBusOutputs::outputActivatedSlot(QString id) {
135
SimpleOutput * o = (SimpleOutput *) output(id);
137
o->_setActivated(true);
138
o->_setSize(m_interface->size(id));
139
emit outputActivated(o);
143
void DBusOutputs::outputDeactivatedSlot(QString id) {
144
SimpleOutput * o = (SimpleOutput *) output(id);
146
o->_setActivated(false);
147
emit outputDeactivated(o);
151
void DBusOutputs::outputResizedSlot(QString id) {
152
SimpleOutput * o = (SimpleOutput *) output(id);
154
QSize prev = o->size();
155
o->_setSize(m_interface->size(id));
156
emit outputResized(o, prev, o->size());
160
void DBusOutputs::outputMovedSlot(QString id) {
161
SimpleOutput * o = (SimpleOutput *) output(id);
163
QPoint prev = o->position();
164
o->_setPosition(m_interface->position(id));
165
emit outputMoved(o, prev, o->position());
169
void DBusOutputs::outputRotatedSlot(QString id) {
170
SimpleOutput * o = (SimpleOutput *) output(id);
172
Rotation prev = o->rotation();
173
int rotation = m_interface->rotation(id);
174
o->_setRotation((Rotation) rotation);
175
emit outputRotated(o, prev, o->rotation());
179
void DBusOutputs::outputRateChangedSlot(QString id) {
180
SimpleOutput * o = (SimpleOutput *) output(id);
182
float prev = o->rate();
183
o->_setRate(m_interface->rate(id));
184
emit outputRateChanged(o, prev, o->rate());
188
void DBusOutputs::outputReflectedSlot(QString id) {
189
SimpleOutput * o = (SimpleOutput *) output(id);
191
bool prevX = o->reflectX();
192
bool prevY = o->reflectY();
193
o->_setReflectX(m_interface->reflectX(id));
194
o->_setReflectY(m_interface->reflectY(id));
195
emit outputReflected(o, prevX, prevY, o->reflectX(), o->reflectY());