add more spacing
[personal-kdebase.git] / workspace / libs / kephal / kded_kephal / dbus / dbusapi_configurations.cpp
blob1ce9f3b4af7e8226348043b6f8657d895b04983a
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_configurations.h"
22 #include "kephal/configurations.h"
23 #include "configurationsadaptor.h"
24 #include "kephal/outputs.h"
26 #include <QDebug>
27 #include <QObject>
30 using namespace Kephal;
32 DBusAPIConfigurations::DBusAPIConfigurations(QObject * parent)
33 : QObject(parent)
35 new ConfigurationsAdaptor(this);
36 QDBusConnection dbus = QDBusConnection::sessionBus();
38 bool result;
39 result = dbus.registerObject("/Configurations", this);
40 qDebug() << "configurations registered on the bus:" << result;
42 connect(Configurations::self(), SIGNAL(configurationActivated(Kephal::Configuration *)), this, SLOT(configurationActivatedSlot(Kephal::Configuration *)));
43 connect(Configurations::self(), SIGNAL(confirmed()), this, SIGNAL(confirmed()));
44 connect(Configurations::self(), SIGNAL(reverted()), this, SIGNAL(reverted()));
45 connect(Configurations::self(), SIGNAL(confirmTimeout(int)), this, SIGNAL(confirmTimeout(int)));
48 QStringList DBusAPIConfigurations::configurations() {
49 QStringList result;
50 foreach (const QString& name, Configurations::self()->configurations().keys()) {
51 result << name;
53 return result;
56 int DBusAPIConfigurations::numAvailablePositions(QString output) {
57 Output * o = Outputs::self()->output(output);
58 if (o) {
59 m_outputAvailablePositions.insert(output, o->availablePositions());
60 return m_outputAvailablePositions[output].size();
62 return 0;
65 QPoint DBusAPIConfigurations::availablePosition(QString output, int index) {
66 if (m_outputAvailablePositions.contains(output)) {
67 return m_outputAvailablePositions[output][index];
69 return QPoint();
72 QStringList DBusAPIConfigurations::alternateConfigurations() {
73 QStringList result;
74 foreach (Configuration * config, Configurations::self()->alternateConfigurations()) {
75 result << config->name();
77 return result;
80 QString DBusAPIConfigurations::activeConfiguration() {
81 Configuration * config = Configurations::self()->activeConfiguration();
82 if (config) {
83 return config->name();
85 return "";
88 bool DBusAPIConfigurations::move(QString output, QPoint position) {
89 Output * o = Outputs::self()->output(output);
90 if (o) {
91 return Configurations::self()->move(o, position);
93 return false;
96 bool DBusAPIConfigurations::resize(QString output, QSize size) {
97 Output * o = Outputs::self()->output(output);
98 if (o) {
99 return Configurations::self()->resize(o, size);
101 return false;
104 bool DBusAPIConfigurations::rotate(QString output, int rotation) {
105 Output * o = Outputs::self()->output(output);
106 if (o) {
107 return Configurations::self()->rotate(o, (Rotation) rotation);
109 return false;
112 bool DBusAPIConfigurations::changeRate(QString output, qreal rate) {
113 Output * o = Outputs::self()->output(output);
114 if (o) {
115 return Configurations::self()->changeRate(o, rate);
117 return false;
120 bool DBusAPIConfigurations::reflectX(QString output, bool reflect) {
121 Output * o = Outputs::self()->output(output);
122 if (o) {
123 return Configurations::self()->reflectX(o, reflect);
125 return false;
128 bool DBusAPIConfigurations::reflectY(QString output, bool reflect) {
129 Output * o = Outputs::self()->output(output);
130 if (o) {
131 return Configurations::self()->reflectY(o, reflect);
133 return false;
136 bool DBusAPIConfigurations::isModifiable(QString config) {
137 Configuration * c = Configurations::self()->configuration(config);
138 if (c) {
139 return c->isModifiable();
141 return false;
144 bool DBusAPIConfigurations::isActivated(QString config) {
145 Configuration * c = Configurations::self()->configuration(config);
146 if (c) {
147 return c->isActivated();
149 return false;
152 void DBusAPIConfigurations::activate(QString config) {
153 Configuration * c = Configurations::self()->configuration(config);
154 if (c) {
155 c->activate();
159 int DBusAPIConfigurations::primaryScreen(QString config) {
160 Configuration * c = Configurations::self()->configuration(config);
161 if (c) {
162 return c->primaryScreen();
164 return 0;
167 int DBusAPIConfigurations::screen(QString outputId) {
168 Output * output = Outputs::self()->output(outputId);
169 if (output) {
170 return Configurations::self()->screen(output);
172 return -1;
175 void DBusAPIConfigurations::setPolling(bool polling) {
176 Configurations::self()->setPolling(polling);
179 bool DBusAPIConfigurations::polling() {
180 return Configurations::self()->polling();
183 void DBusAPIConfigurations::configurationActivatedSlot(Kephal::Configuration * configuration) {
184 emit configurationActivated(configuration->name());
187 void DBusAPIConfigurations::confirm() {
188 Configurations::self()->confirm();
191 void DBusAPIConfigurations::revert() {
192 Configurations::self()->revert();
195 #ifndef NO_KDE
196 #include "dbusapi_configurations.moc"
197 #endif