Version bump
[someplayer] / src / dbusclient.cpp
1 /*
2  * SomePlayer - An alternate music player for Maemo 5
3  * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include "dbusclient.h"
21 #include <QDebug>
22
23 DBusClient::DBusClient(QObject *parent) :
24                 QObject(parent)
25 {
26         _timer.setInterval(60000);
27         _timer.setSingleShot(false);
28         //dbus-send  --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_keypad_off_pause
29         _unpause_keys_message = QDBusMessage::createMethodCall("com.nokia.mce",
30                                                                "/com/nokia/mce/request",
31                                                                "com.nokia.mce.request",
32                                                                "req_keypad_off_pause");
33
34         //signal sender=:1.13 -> dest=(null destination) serial=4373 path=/com/nokia/mce/signal; interface=com.nokia.mce.signal; member=display_status_ind
35         //string "off"
36         QDBusConnection::systemBus().connect(QString(), QString(),
37                                              "com.nokia.mce.signal", "display_status_ind", this, SLOT(_display_handler(QString)));
38         //signal sender=:1.46 -> dest=(null destination) serial=2966 path=/com/nokia/tklock/signal; interface=com.nokia.tklock.signal; member=mm_key_press
39         //uint32 74
40         //uint32 65476
41         QDBusConnection::systemBus().connect(QString(), QString(),
42                                              "com.nokia.tklock.signal", "mm_key_press", this, SLOT(_zoom_keys_handler(quint32,quint32)));
43
44 }
45
46 void DBusClient::enableKeys() {
47         connect(&_timer, SIGNAL(timeout()), this, SLOT(_unpause_keys()));
48         _unpause_keys();
49         _timer.start();
50 }
51
52 void DBusClient::disableKeys() {
53         disconnect(&_timer, SIGNAL(timeout()), this, SLOT(_unpause_keys()));
54         _timer.stop();
55 }
56
57 void DBusClient::_unpause_keys() {
58         QDBusConnection::systemBus().call(_unpause_keys_message);
59 }
60
61 void DBusClient::_display_handler(QString state) {
62         emit displayStateChanged(state == "on");
63 }
64
65 void DBusClient::_zoom_keys_handler(quint32 code, quint32 /*ignored*/) {
66         emit zoomKeyPressed(code);
67 }
68
69 void DBusClient::setVolume(quint32 volume) {
70         QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer",
71                                                           "/com/nokia/mafw/renderer/gstrenderer",
72                                                           "com.nokia.mafw.extension",
73                                                           "set_extension_property");
74         QList<QVariant> args;
75         args << "volume" << QVariant::fromValue(QDBusVariant(volume));
76         msg.setArguments(args);
77         QDBusConnection::sessionBus().send(msg);
78 }
79
80 quint32 DBusClient::getVolume() {
81         QDBusInterface iface("com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer",
82                              "/com/nokia/mafw/renderer/gstrenderer",
83                              "com.nokia.mafw.extension",
84                              QDBusConnection::sessionBus());
85         QDBusMessage reply = iface.call("get_extension_property", "volume");
86         QList<QVariant> values = reply.arguments();
87         QVariant volume = values.takeAt(1);
88         QDBusVariant var = qvariant_cast<QDBusVariant>(volume);
89         volume = var.variant();
90         return volume.toUInt();
91 }
92