dtor first
[personal-kdebase.git] / workspace / libs / kephal / screens / dbus / dbusscreens.cpp
blobe3c436863bf2a03a4621afea6cb79ea7796d19ee
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 "dbusscreens.h"
23 #include <QDebug>
25 #include "../simplescreen.h"
26 #include "screens_interface.h"
27 #include "kephal/outputs.h"
30 namespace Kephal {
32 DBusScreens::DBusScreens(QObject * parent)
33 : Screens(parent)
35 m_interface = new org::kde::Kephal::Screens(
36 "org.kde.Kephal",
37 "/Screens",
38 QDBusConnection::sessionBus(),
39 this);
41 if (! m_interface->isValid()) {
42 m_valid = false;
43 return;
46 m_valid = true;
48 int numScreens = m_interface->numScreens();
49 for (int i = 0; i < numScreens; ++i) {
50 int id = m_interface->id(i);
51 QPoint pos = m_interface->position(id);
52 QSize size = m_interface->size(id);
53 //qDebug() << "adding a screen" << id << "with geom: " << pos << size;
55 SimpleScreen * screen = new SimpleScreen(this,
56 id,
57 size,
58 pos,
59 false);
60 m_screens.append(screen);
62 const QStringList outputIds = m_interface->outputs(id);
63 foreach (const QString& outputId, outputIds) {
64 Output * output = Outputs::self()->output(outputId);
65 if (output) {
66 screen->_outputs() << output;
71 connect(m_interface, SIGNAL(screenResized(int)), this, SLOT(screenResizedSlot(int)));
72 connect(m_interface, SIGNAL(screenMoved(int)), this, SLOT(screenMovedSlot(int)));
73 connect(m_interface, SIGNAL(screenAdded(int)), this, SLOT(screenAddedSlot(int)));
74 connect(m_interface, SIGNAL(screenRemoved(int)), this, SLOT(screenRemovedSlot(int)));
77 void DBusScreens::screenResizedSlot(int id) {
78 SimpleScreen * s = (SimpleScreen *) screen(id);
79 if (s) {
80 QSize prev = s->size();
81 s->_setSize(m_interface->size(id));
82 emit screenResized(s, prev, s->size());
86 void DBusScreens::screenMovedSlot(int id) {
87 SimpleScreen * s = (SimpleScreen *) screen(id);
88 if (s) {
89 QPoint prev = s->position();
90 s->_setPosition(m_interface->position(id));
91 emit screenMoved(s, prev, s->position());
95 void DBusScreens::screenAddedSlot(int id) {
96 QPoint pos = m_interface->position(id);
97 QSize size = m_interface->size(id);
98 //qDebug() << "adding a screen" << id << "with geom: " << pos << size;
100 SimpleScreen * screen = new SimpleScreen(this,
102 size,
103 pos,
104 false);
105 m_screens.append(screen);
107 const QStringList outputIds = m_interface->outputs(id);
108 foreach (const QString& outputId, outputIds) {
109 Output * output = Outputs::self()->output(outputId);
110 if (output) {
111 screen->_outputs() << output;
115 emit screenAdded(screen);
118 void DBusScreens::screenRemovedSlot(int id) {
119 SimpleScreen * s = (SimpleScreen *) screen(id);
120 if (s) {
121 m_screens.removeAll(s);
122 delete s;
123 emit screenRemoved(id);
128 DBusScreens::~DBusScreens() {
129 foreach(Screen * screen, m_screens) {
130 delete screen;
132 m_screens.clear();
135 QList<Screen *> DBusScreens::screens()
137 QList<Screen *> result;
138 foreach(SimpleScreen * screen, m_screens) {
139 result.append(screen);
141 return result;
144 bool DBusScreens::isValid() {
145 return m_valid;