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

« back to all changes in this revision

Viewing changes to libs/kephal/service/dbus/dbusapi_configurations.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_configurations.h"
 
22
#include "configurations.h"
 
23
#include "configurationsadaptor.h"
 
24
#include "outputs.h"
 
25
 
 
26
#include <KDebug>
 
27
#include <QObject>
 
28
 
 
29
 
 
30
using namespace Kephal;
 
31
 
 
32
DBusAPIConfigurations::DBusAPIConfigurations(QObject * parent)
 
33
    : QObject(parent)
 
34
{
 
35
    new ConfigurationsAdaptor(this);
 
36
    QDBusConnection dbus = QDBusConnection::sessionBus();
 
37
 
 
38
    const bool result = dbus.registerObject("/modules/kephal/Configurations", this);
 
39
    kDebug() << "configurations registered on the bus:" << result;
 
40
 
 
41
    connect(Configurations::self(), SIGNAL(configurationActivated(Kephal::Configuration *)), this, SLOT(configurationActivatedSlot(Kephal::Configuration *)));
 
42
    connect(Configurations::self(), SIGNAL(confirmed()), this, SIGNAL(confirmed()));
 
43
    connect(Configurations::self(), SIGNAL(reverted()), this, SIGNAL(reverted()));
 
44
    connect(Configurations::self(), SIGNAL(confirmTimeout(int)), this, SIGNAL(confirmTimeout(int)));
 
45
}
 
46
 
 
47
QStringList DBusAPIConfigurations::configurations() {
 
48
    QStringList result;
 
49
    foreach (const QString& name, Configurations::self()->configurations().keys()) {
 
50
        result << name;
 
51
    }
 
52
    return result;
 
53
}
 
54
 
 
55
int DBusAPIConfigurations::numAvailablePositions(QString output) {
 
56
    Output * o = Outputs::self()->output(output);
 
57
    if (o) {
 
58
        m_outputAvailablePositions.insert(output, o->availablePositions());
 
59
        return m_outputAvailablePositions[output].size();
 
60
    }
 
61
    return 0;
 
62
}
 
63
 
 
64
QPoint DBusAPIConfigurations::availablePosition(QString output, int index) {
 
65
    if (m_outputAvailablePositions.contains(output)) {
 
66
        return m_outputAvailablePositions[output][index];
 
67
    }
 
68
    return QPoint();
 
69
}
 
70
 
 
71
QStringList DBusAPIConfigurations::alternateConfigurations() {
 
72
    QStringList result;
 
73
    foreach (Configuration * config, Configurations::self()->alternateConfigurations()) {
 
74
        result << config->name();
 
75
    }
 
76
    return result;
 
77
}
 
78
 
 
79
QString DBusAPIConfigurations::activeConfiguration() {
 
80
    Configuration * config = Configurations::self()->activeConfiguration();
 
81
    if (config) {
 
82
        return config->name();
 
83
    }
 
84
    return "";
 
85
}
 
86
 
 
87
// Not needed. If Configurations provides access to configurations, it should not also provide ways
 
88
// to temporarily modify the current configuration.  This should be done by a config UI.
 
89
#if 0
 
90
bool DBusAPIConfigurations::move(QString output, QPoint position) {
 
91
    Output * o = Outputs::self()->output(output);
 
92
    if (o) {
 
93
        return Configurations::self()->move(o, position);
 
94
    }
 
95
    return false;
 
96
}
 
97
 
 
98
bool DBusAPIConfigurations::resize(QString output, QSize size) {
 
99
    Output * o = Outputs::self()->output(output);
 
100
    if (o) {
 
101
        return Configurations::self()->resize(o, size);
 
102
    }
 
103
    return false;
 
104
}
 
105
 
 
106
bool DBusAPIConfigurations::rotate(QString output, int rotation) {
 
107
    Output * o = Outputs::self()->output(output);
 
108
    if (o) {
 
109
        return Configurations::self()->rotate(o, (Rotation) rotation);
 
110
    }
 
111
    return false;
 
112
}
 
113
 
 
114
bool DBusAPIConfigurations::changeRate(QString output, double rate) {
 
115
    Output * o = Outputs::self()->output(output);
 
116
    if (o) {
 
117
        return Configurations::self()->changeRate(o, static_cast<float>(rate));
 
118
    }
 
119
    return false;
 
120
}
 
121
 
 
122
bool DBusAPIConfigurations::reflectX(QString output, bool reflect) {
 
123
    Output * o = Outputs::self()->output(output);
 
124
    if (o) {
 
125
        return Configurations::self()->reflectX(o, reflect);
 
126
    }
 
127
    return false;
 
128
}
 
129
 
 
130
bool DBusAPIConfigurations::reflectY(QString output, bool reflect) {
 
131
    Output * o = Outputs::self()->output(output);
 
132
    if (o) {
 
133
        return Configurations::self()->reflectY(o, reflect);
 
134
    }
 
135
    return false;
 
136
}
 
137
#endif
 
138
bool DBusAPIConfigurations::isModifiable(QString config) {
 
139
    Configuration * c = Configurations::self()->configuration(config);
 
140
    if (c) {
 
141
        return c->isModifiable();
 
142
    }
 
143
    return false;
 
144
}
 
145
 
 
146
bool DBusAPIConfigurations::isActivated(QString config) {
 
147
    Configuration * c = Configurations::self()->configuration(config);
 
148
    if (c) {
 
149
        return c->isActivated();
 
150
    }
 
151
    return false;
 
152
}
 
153
 
 
154
void DBusAPIConfigurations::activate(QString config) {
 
155
    Configuration * c = Configurations::self()->configuration(config);
 
156
    if (c) {
 
157
        c->activate();
 
158
    }
 
159
}
 
160
 
 
161
int DBusAPIConfigurations::primaryScreen(QString config) {
 
162
    Configuration * c = Configurations::self()->configuration(config);
 
163
    if (c) {
 
164
        return c->primaryScreen();
 
165
    }
 
166
    return 0;
 
167
}
 
168
 
 
169
int DBusAPIConfigurations::screen(QString outputId) {
 
170
    Output * output = Outputs::self()->output(outputId);
 
171
    if (output) {
 
172
        return Configurations::self()->screen(output);
 
173
    }
 
174
    return -1;
 
175
}
 
176
 
 
177
void DBusAPIConfigurations::setPolling(bool polling) {
 
178
    Configurations::self()->setPolling(polling);
 
179
}
 
180
 
 
181
bool DBusAPIConfigurations::polling() {
 
182
    return Configurations::self()->polling();
 
183
}
 
184
 
 
185
void DBusAPIConfigurations::configurationActivatedSlot(Kephal::Configuration * configuration) {
 
186
    emit configurationActivated(configuration->name());
 
187
}
 
188
 
 
189
void DBusAPIConfigurations::confirm() {
 
190
    Configurations::self()->confirm();
 
191
}
 
192
 
 
193
void DBusAPIConfigurations::revert() {
 
194
    Configurations::self()->revert();
 
195
}
 
196
 
 
197
#ifndef NO_KDE
 
198
#include "dbusapi_configurations.moc"
 
199
#endif
 
200