add more spacing
[personal-kdebase.git] / workspace / libs / kephal / outputs / dbus / dbusoutputs.cpp
blob984aef0a27ef79f44a93e125935bf21ad5b35634
1 /*
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"
23 #include <QDebug>
24 #include <QVariant>
26 #include "../simpleoutput.h"
27 #include "outputs_interface.h"
30 namespace Kephal {
32 DBusOutputs::DBusOutputs(QObject * parent)
33 : Outputs(parent)
35 m_interface = new org::kde::Kephal::Outputs(
36 "org.kde.Kephal",
37 "/Outputs",
38 QDBusConnection::sessionBus(),
39 this);
41 if (! m_interface->isValid()) {
42 m_valid = false;
43 return;
46 m_valid = true;
48 const QStringList ids = m_interface->outputIds();
49 foreach (const QString& id, ids) {
50 QPoint pos = m_interface->position(id);
51 QSize size = m_interface->size(id);
52 bool connected = m_interface->isConnected(id);
53 bool activated = m_interface->isActivated(id);
54 //qDebug() << "adding an output" << id << "with geom: " << pos << size;
56 SimpleOutput * output = new SimpleOutput(this,
57 id,
58 size,
59 pos,
60 connected,
61 activated);
63 m_outputs << output;
65 if (connected) {
66 output->_setRate(m_interface->rate(id));
67 int rotation = m_interface->rotation(id);
68 output->_setRotation((Rotation) rotation);
69 output->_setReflectX(m_interface->reflectX(id));
70 output->_setReflectY(m_interface->reflectY(id));
72 outputConnectedSlot(id);
76 connect(m_interface, SIGNAL(outputConnected(QString)), this, SLOT(outputConnectedSlot(QString)));
77 connect(m_interface, SIGNAL(outputDisconnected(QString)), this, SLOT(outputDisconnectedSlot(QString)));
78 connect(m_interface, SIGNAL(outputActivated(QString)), this, SLOT(outputActivatedSlot(QString)));
79 connect(m_interface, SIGNAL(outputDeactivated(QString)), this, SLOT(outputDeactivatedSlot(QString)));
80 connect(m_interface, SIGNAL(outputResized(QString)), this, SLOT(outputResizedSlot(QString)));
81 connect(m_interface, SIGNAL(outputMoved(QString)), this, SLOT(outputMovedSlot(QString)));
82 connect(m_interface, SIGNAL(outputRotated(QString)), this, SLOT(outputRotatedSlot(QString)));
83 connect(m_interface, SIGNAL(outputRateChanged(QString)), this, SLOT(outputRateChangedSlot(QString)));
84 connect(m_interface, SIGNAL(outputReflected(QString)), this, SLOT(outputReflectedSlot(QString)));
87 QList<Output *> DBusOutputs::outputs()
89 QList<Output *> result;
90 foreach(SimpleOutput * output, m_outputs) {
91 result.append(output);
93 return result;
96 void DBusOutputs::activateLayout(const QMap<Output *, QRect> & layout)
98 Q_UNUSED(layout)
101 bool DBusOutputs::isValid() {
102 return m_valid;
105 void DBusOutputs::outputConnectedSlot(QString id) {
106 SimpleOutput * o = (SimpleOutput *) output(id);
107 if (o) {
108 o->_setConnected(true);
110 int numSizes = m_interface->numAvailableSizes(id);
111 QList<QSize> sizes;
112 for (int i = 0; i < numSizes; ++i) {
113 sizes << m_interface->availableSize(id, i);
115 o->_setAvailableSizes(sizes);
117 int numRates = m_interface->numAvailableRates(id);
118 QList<float> rates;
119 for (int i = 0; i < numRates; ++i) {
120 rates << m_interface->availableRate(id, i);
122 o->_setAvailableRates(rates);
124 emit outputConnected(o);
128 void DBusOutputs::outputDisconnectedSlot(QString id) {
129 SimpleOutput * o = (SimpleOutput *) output(id);
130 if (o) {
131 o->_setConnected(false);
132 emit outputDisconnected(o);
136 void DBusOutputs::outputActivatedSlot(QString id) {
137 SimpleOutput * o = (SimpleOutput *) output(id);
138 if (o) {
139 o->_setActivated(true);
140 o->_setSize(m_interface->size(id));
141 emit outputActivated(o);
145 void DBusOutputs::outputDeactivatedSlot(QString id) {
146 SimpleOutput * o = (SimpleOutput *) output(id);
147 if (o) {
148 o->_setActivated(false);
149 emit outputDeactivated(o);
153 void DBusOutputs::outputResizedSlot(QString id) {
154 SimpleOutput * o = (SimpleOutput *) output(id);
155 if (o) {
156 QSize prev = o->size();
157 o->_setSize(m_interface->size(id));
158 emit outputResized(o, prev, o->size());
162 void DBusOutputs::outputMovedSlot(QString id) {
163 SimpleOutput * o = (SimpleOutput *) output(id);
164 if (o) {
165 QPoint prev = o->position();
166 o->_setPosition(m_interface->position(id));
167 emit outputMoved(o, prev, o->position());
171 void DBusOutputs::outputRotatedSlot(QString id) {
172 SimpleOutput * o = (SimpleOutput *) output(id);
173 if (o) {
174 Rotation prev = o->rotation();
175 int rotation = m_interface->rotation(id);
176 o->_setRotation((Rotation) rotation);
177 emit outputRotated(o, prev, o->rotation());
181 void DBusOutputs::outputRateChangedSlot(QString id) {
182 SimpleOutput * o = (SimpleOutput *) output(id);
183 if (o) {
184 float prev = o->rate();
185 o->_setRate(m_interface->rate(id));
186 emit outputRateChanged(o, prev, o->rate());
190 void DBusOutputs::outputReflectedSlot(QString id) {
191 SimpleOutput * o = (SimpleOutput *) output(id);
192 if (o) {
193 bool prevX = o->reflectX();
194 bool prevY = o->reflectY();
195 o->_setReflectX(m_interface->reflectX(id));
196 o->_setReflectY(m_interface->reflectY(id));
197 emit outputReflected(o, prevX, prevY, o->reflectX(), o->reflectY());