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

« back to all changes in this revision

Viewing changes to libs/kephal/client/dbusoutputs.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 "dbusoutputs.h"
 
22
 
 
23
#include <QDebug>
 
24
 
 
25
#include "simpleoutput.h"
 
26
 
 
27
 
 
28
namespace Kephal {
 
29
 
 
30
    DBusOutputs::DBusOutputs(QObject * parent)
 
31
            : Outputs(parent)
 
32
    {
 
33
        m_interface = new org::kde::Kephal::Outputs(
 
34
            "org.kde.Kephal",
 
35
            "/modules/kephal/Outputs",
 
36
            QDBusConnection::sessionBus(),
 
37
            this);
 
38
 
 
39
        if (! m_interface->isValid()) {
 
40
            m_valid = false;
 
41
            return;
 
42
        }
 
43
 
 
44
        m_valid = true;
 
45
 
 
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;
 
53
 
 
54
            SimpleOutput * output = new SimpleOutput(this,
 
55
                    id,
 
56
                    size,
 
57
                    pos,
 
58
                    connected,
 
59
                    activated);
 
60
 
 
61
            m_outputs.append(output);
 
62
 
 
63
            if (connected) {
 
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));
 
69
 
 
70
                outputConnectedSlot(id);
 
71
            }
 
72
        }
 
73
 
 
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)));
 
83
    }
 
84
 
 
85
    QList<Output *> DBusOutputs::outputs()
 
86
    {
 
87
        QList<Output *> result;
 
88
        foreach(SimpleOutput * output, m_outputs) {
 
89
            result.append(output);
 
90
        }
 
91
        return result;
 
92
    }
 
93
 
 
94
    void DBusOutputs::activateLayout(const QMap<Output *, QRect> & layout)
 
95
    {
 
96
        Q_UNUSED(layout)
 
97
    }
 
98
 
 
99
    bool DBusOutputs::isValid() {
 
100
        return m_valid;
 
101
    }
 
102
 
 
103
    void DBusOutputs::outputConnectedSlot(QString id) {
 
104
        SimpleOutput * o = (SimpleOutput *) output(id);
 
105
        if (o) {
 
106
            o->_setConnected(true);
 
107
 
 
108
            int numSizes = m_interface->numAvailableSizes(id);
 
109
            QList<QSize> sizes;
 
110
            for (int i = 0; i < numSizes; ++i) {
 
111
                sizes << m_interface->availableSize(id, i);
 
112
            }
 
113
            o->_setAvailableSizes(sizes);
 
114
 
 
115
            int numRates = m_interface->numAvailableRates(id);
 
116
            QList<float> rates;
 
117
            for (int i = 0; i < numRates; ++i) {
 
118
                rates << m_interface->availableRate(id, i);
 
119
            }
 
120
            o->_setAvailableRates(rates);
 
121
 
 
122
            emit outputConnected(o);
 
123
        }
 
124
    }
 
125
 
 
126
    void DBusOutputs::outputDisconnectedSlot(QString id) {
 
127
        SimpleOutput * o = (SimpleOutput *) output(id);
 
128
        if (o) {
 
129
            o->_setConnected(false);
 
130
            emit outputDisconnected(o);
 
131
        }
 
132
    }
 
133
 
 
134
    void DBusOutputs::outputActivatedSlot(QString id) {
 
135
        SimpleOutput * o = (SimpleOutput *) output(id);
 
136
        if (o) {
 
137
            o->_setActivated(true);
 
138
            o->_setSize(m_interface->size(id));
 
139
            emit outputActivated(o);
 
140
        }
 
141
    }
 
142
 
 
143
    void DBusOutputs::outputDeactivatedSlot(QString id) {
 
144
        SimpleOutput * o = (SimpleOutput *) output(id);
 
145
        if (o) {
 
146
            o->_setActivated(false);
 
147
            emit outputDeactivated(o);
 
148
        }
 
149
    }
 
150
 
 
151
    void DBusOutputs::outputResizedSlot(QString id) {
 
152
        SimpleOutput * o = (SimpleOutput *) output(id);
 
153
        if (o) {
 
154
            QSize prev = o->size();
 
155
            o->_setSize(m_interface->size(id));
 
156
            emit outputResized(o, prev, o->size());
 
157
        }
 
158
    }
 
159
 
 
160
    void DBusOutputs::outputMovedSlot(QString id) {
 
161
        SimpleOutput * o = (SimpleOutput *) output(id);
 
162
        if (o) {
 
163
            QPoint prev = o->position();
 
164
            o->_setPosition(m_interface->position(id));
 
165
            emit outputMoved(o, prev, o->position());
 
166
        }
 
167
    }
 
168
 
 
169
    void DBusOutputs::outputRotatedSlot(QString id) {
 
170
        SimpleOutput * o = (SimpleOutput *) output(id);
 
171
        if (o) {
 
172
            Rotation prev = o->rotation();
 
173
            int rotation = m_interface->rotation(id);
 
174
            o->_setRotation((Rotation) rotation);
 
175
            emit outputRotated(o, prev, o->rotation());
 
176
        }
 
177
    }
 
178
 
 
179
    void DBusOutputs::outputRateChangedSlot(QString id) {
 
180
        SimpleOutput * o = (SimpleOutput *) output(id);
 
181
        if (o) {
 
182
            float prev = o->rate();
 
183
            o->_setRate(m_interface->rate(id));
 
184
            emit outputRateChanged(o, prev, o->rate());
 
185
        }
 
186
    }
 
187
 
 
188
    void DBusOutputs::outputReflectedSlot(QString id) {
 
189
        SimpleOutput * o = (SimpleOutput *) output(id);
 
190
        if (o) {
 
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());
 
196
        }
 
197
    }
 
198
 
 
199
}
 
200