2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include <QtXml/QDomDocument>
28 #include <mce/dbus-names.h>
29 #include <mce/mode-names.h>
32 #include "mceprivate.h"
34 const int DISPLAY_STATE_INDEX = 0;
36 static QDBusConnection dBusConnection = QDBusConnection::systemBus();
38 MCEPrivate::MCEPrivate(QObject *parent)
42 qDebug() << __PRETTY_FUNCTION__;
44 m_parent = static_cast<MCE*>(parent);
46 m_dBusInterface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
47 MCE_REQUEST_IF, dBusConnection, this);
49 dBusConnection.connect(MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
50 MCE_DISPLAY_SIG, this, SLOT(displayStateChanged(const QDBusMessage &)));
52 m_dBusInterface->callWithCallback(MCE_DISPLAY_STATUS_GET, QList<QVariant>(), this,
53 SLOT(setDisplayState(QString)),
54 SLOT(displayStateError(QDBusError)));
57 void MCEPrivate::displayStateChanged(const QDBusMessage &message)
59 qDebug() << __PRETTY_FUNCTION__;
61 QString state = message.arguments().at(DISPLAY_STATE_INDEX).toString();
62 setDisplayState(state);
65 void MCEPrivate::displayStateError(const QDBusError &error)
67 qDebug() << __PRETTY_FUNCTION__;
72 bool MCEPrivate::isDisplayOn()
74 qDebug() << __PRETTY_FUNCTION__;
79 void MCEPrivate::setDisplayState(const QString &state)
81 qDebug() << __PRETTY_FUNCTION__;
83 if (!state.isEmpty()) {
84 if (state == MCE_DISPLAY_ON_STRING) {
86 emit m_parent->displayOff(false);
88 else if (state == MCE_DISPLAY_OFF_STRING) {
90 emit m_parent->displayOff(true);
95 bool MCEPrivate::isTouchscreenVibrationEnabled()
98 QFile file("/var/lib/gconf/system/osso/dsm/vibra/\%gconf.xml");
100 if (!file.open(QIODevice::ReadOnly))
102 if (!doc.setContent(&file)) {
109 QDomNodeList domNodeList = doc.elementsByTagName("entry");
111 for (int i = 0; i < domNodeList.count(); ++i) {
113 QDomElement element = domNodeList.at(i).toElement();
115 if ((!element.isNull()) && (element.hasAttribute("name")) &&
116 (element.attribute("name") == "touchscreen_vibra_enabled")) {
118 return QVariant(element.attribute("value", "false")).toBool();
125 void MCEPrivate::stopVibration()
127 qDebug() << __PRETTY_FUNCTION__;
129 m_dBusInterface->call(MCE_ACTIVATE_VIBRATOR_PATTERN, "PatternPowerKeyPress");
132 void MCEPrivate::vibrationFeedback()
134 qDebug() << __PRETTY_FUNCTION__;
136 if (isTouchscreenVibrationEnabled()) {
137 m_dBusInterface->call(MCE_ACTIVATE_VIBRATOR_PATTERN, "PatternPowerKeyPress");
139 const int VIBRATION_TIME = 40; //Vibration time in milliseconds
140 QTimer::singleShot(VIBRATION_TIME, this, SLOT(stopVibration()));