add more spacing
[personal-kdebase.git] / workspace / libs / kephal / kded_kephal / dbus / dbusapi_outputs.cpp
bloba6ef0b3b6d42ad40319db6a12a0ffa90e7296e31
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 "dbusapi_outputs.h"
22 #include "kephal/outputs.h"
23 #include "outputsadaptor.h"
25 #include <QDebug>
28 using namespace Kephal;
30 DBusAPIOutputs::DBusAPIOutputs(QObject * parent)
31 : QObject(parent)
33 new OutputsAdaptor(this);
34 QDBusConnection dbus = QDBusConnection::sessionBus();
36 bool result;
37 result = dbus.registerObject("/Outputs", this);
38 qDebug() << "outputs registered on the bus:" << result;
40 connect(Outputs::self(), SIGNAL(outputConnected(Kephal::Output *)), this, SLOT(outputConnectedSlot(Kephal::Output *)));
41 connect(Outputs::self(), SIGNAL(outputDisconnected(Kephal::Output *)), this, SLOT(outputDisconnectedSlot(Kephal::Output *)));
42 connect(Outputs::self(), SIGNAL(outputActivated(Kephal::Output *)), this, SLOT(outputActivatedSlot(Kephal::Output *)));
43 connect(Outputs::self(), SIGNAL(outputDeactivated(Kephal::Output *)), this, SLOT(outputDeactivatedSlot(Kephal::Output *)));
44 connect(Outputs::self(), SIGNAL(outputResized(Kephal::Output *, QSize, QSize)), this, SLOT(outputResizedSlot(Kephal::Output *, QSize, QSize)));
45 connect(Outputs::self(), SIGNAL(outputMoved(Kephal::Output *, QPoint, QPoint)), this, SLOT(outputMovedSlot(Kephal::Output *, QPoint, QPoint)));
46 connect(Outputs::self(), SIGNAL(outputRotated(Kephal::Output *, Kephal::Rotation, Kephal::Rotation)), this, SLOT(outputRotatedSlot(Kephal::Output *, Kephal::Rotation, Kephal::Rotation)));
47 connect(Outputs::self(), SIGNAL(outputRateChanged(Kephal::Output *, float, float)), this, SLOT(outputRateChangedSlot(Kephal::Output *, float, float)));
48 connect(Outputs::self(), SIGNAL(outputReflected(Kephal::Output *, bool, bool, bool, bool)), this, SLOT(outputReflectedSlot(Kephal::Output *, bool, bool, bool, bool)));
51 QSize DBusAPIOutputs::size(QString id)
53 Output * output = Outputs::self()->output(id);
54 if (output && output->isActivated()) {
55 return output->size();
57 return QSize(0,0);
60 int DBusAPIOutputs::numAvailableSizes(QString id)
62 Output * output = Outputs::self()->output(id);
63 if (output && output->isActivated()) {
64 m_sizes.insert(id, output->availableSizes());
65 return m_sizes[id].size();
67 return 0;
70 QSize DBusAPIOutputs::availableSize(QString id, int i)
72 if (! m_sizes.contains(id)) {
73 numAvailableSizes(id);
75 if (m_sizes.contains(id) && (m_sizes[id].size() > i)) {
76 return m_sizes[id][i];
78 return QSize(-1, -1);
81 QPoint DBusAPIOutputs::position(QString id)
83 Output * output = Outputs::self()->output(id);
84 if (output && output->isActivated()) {
85 return output->position();
87 return QPoint(0,0);
90 QStringList DBusAPIOutputs::outputIds()
92 QList<Output *> outputs = Outputs::self()->outputs();
93 QStringList result;
94 //qDebug() << "output-ids requested!!";
95 foreach (Output * output, outputs) {
96 //qDebug() << "appending output-id:" << output->id();
97 result.append(output->id());
99 return result;
102 bool DBusAPIOutputs::isConnected(QString id)
104 Output * output = Outputs::self()->output(id);
105 if (output && output->isConnected()) {
106 return true;
108 return false;
111 bool DBusAPIOutputs::isActivated(QString id)
113 Output * output = Outputs::self()->output(id);
114 if (output && output->isActivated()) {
115 return true;
117 return false;
120 int DBusAPIOutputs::numAvailableRates(QString id)
122 Output * output = Outputs::self()->output(id);
123 if (output && output->isActivated()) {
124 m_rates.insert(id, output->availableRates());
125 return m_rates[id].size();
127 return 0;
130 qreal DBusAPIOutputs::availableRate(QString id, int i)
132 if (! m_rates.contains(id)) {
133 numAvailableRates(id);
135 if (m_rates.contains(id) && (m_rates[id].size() > i)) {
136 return m_rates[id][i];
138 return 0;
141 int DBusAPIOutputs::rotation(QString id) {
142 Output * output = Outputs::self()->output(id);
143 if (output && output->isActivated()) {
144 return output->rotation();
146 return RotateNormal;
149 qreal DBusAPIOutputs::rate(QString id) {
150 Output * output = Outputs::self()->output(id);
151 if (output && output->isActivated()) {
152 return output->rate();
154 return 0;
157 bool DBusAPIOutputs::reflectX(QString id) {
158 Output * output = Outputs::self()->output(id);
159 if (output && output->isActivated()) {
160 return output->reflectX();
162 return false;
165 bool DBusAPIOutputs::reflectY(QString id) {
166 Output * output = Outputs::self()->output(id);
167 if (output && output->isActivated()) {
168 return output->reflectY();
170 return false;
173 void DBusAPIOutputs::outputConnectedSlot(Kephal::Output * o) {
174 emit outputConnected(o->id());
177 void DBusAPIOutputs::outputDisconnectedSlot(Kephal::Output * o) {
178 emit outputDisconnected(o->id());
181 void DBusAPIOutputs::outputActivatedSlot(Kephal::Output * o) {
182 emit outputActivated(o->id());
185 void DBusAPIOutputs::outputDeactivatedSlot(Kephal::Output * o) {
186 emit outputDeactivated(o->id());
189 void DBusAPIOutputs::outputResizedSlot(Kephal::Output * o, QSize oldSize, QSize newSize) {
190 Q_UNUSED(oldSize)
191 Q_UNUSED(newSize)
192 emit outputResized(o->id());
195 void DBusAPIOutputs::outputMovedSlot(Kephal::Output * o, QPoint oldPosition, QPoint newPosition) {
196 Q_UNUSED(oldPosition)
197 Q_UNUSED(newPosition)
198 emit outputMoved(o->id());
201 void DBusAPIOutputs::outputRateChangedSlot(Kephal::Output * o, float oldRate, float newRate) {
202 Q_UNUSED(oldRate)
203 Q_UNUSED(newRate)
204 emit outputRateChanged(o->id());
207 void DBusAPIOutputs::outputRotatedSlot(Kephal::Output * o, Rotation oldRotation, Rotation newRotation) {
208 Q_UNUSED(oldRotation)
209 Q_UNUSED(newRotation)
210 emit outputRotated(o->id());
213 void DBusAPIOutputs::outputReflectedSlot(Kephal::Output * o, bool oldX, bool oldY, bool newX, bool newY) {
214 Q_UNUSED(oldX)
215 Q_UNUSED(oldY)
216 Q_UNUSED(newX)
217 Q_UNUSED(newY)
218 emit outputReflected(o->id());
221 #ifndef NO_KDE
222 #include "dbusapi_outputs.moc"
223 #endif