2 * SomePlayer - An alternate music player for Maemo 5
3 * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
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.
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.
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.
20 #include "dbusadaptor.h"
21 #include <QtCore/QMetaObject>
22 #include <QtCore/QByteArray>
23 #include <QtCore/QList>
24 #include <QtCore/QMap>
25 #include <QtCore/QString>
26 #include <QtCore/QStringList>
27 #include <QtCore/QVariant>
32 * Implementation of adaptor class DBusAdaptop
35 DBusAdaptop::DBusAdaptop(QObject *parent)
36 : QDBusAbstractAdaptor(parent)
39 setAutoRelaySignals(true);
40 // handling signals from bluetooth headset
41 _time = QTime::currentTime();
42 if (!QDBusConnection::systemBus().connect(QString(), QString(),
43 "org.freedesktop.Hal.Device", "Condition", this, SLOT(processBTSignal(QString, QString)))) {
44 qWarning() << "Can not connect to HAL";
48 DBusAdaptop::~DBusAdaptop()
53 QString DBusAdaptop::album()
55 // handle method call ru.somebody.someplayer.album
57 QMetaObject::invokeMethod(parent(), "album", Q_RETURN_ARG(QString, out0));
61 QString DBusAdaptop::artist()
63 // handle method call ru.somebody.someplayer.artist
65 QMetaObject::invokeMethod(parent(), "artist", Q_RETURN_ARG(QString, out0));
69 void DBusAdaptop::next()
71 // handle method call ru.somebody.someplayer.next
72 QMetaObject::invokeMethod(parent(), "next");
75 void DBusAdaptop::prev()
77 // handle method call ru.somebody.someplayer.prev
78 QMetaObject::invokeMethod(parent(), "prev");
81 void DBusAdaptop::stop()
83 // handle method call ru.somebody.someplayer.stop
84 QMetaObject::invokeMethod(parent(), "stop");
87 QString DBusAdaptop::title()
89 // handle method call ru.somebody.someplayer.title
91 QMetaObject::invokeMethod(parent(), "title", Q_RETURN_ARG(QString, out0));
95 void DBusAdaptop::toggle()
97 // handle method call ru.somebody.someplayer.toggle
98 QMetaObject::invokeMethod(parent(), "toggle");
101 void DBusAdaptop::processBTSignal(QString event, QString state) {
102 QTime t = QTime::currentTime();
103 long msec = _time.msecsTo(t);
104 if (msec > _DBUS_ACTION_TIMEOUT_) {
105 if (event == "ButtonPressed") {
106 if (state == "next-song") {
108 } else if (state == "previous-song") {
110 } else if (state == "play-cd" || state == "pause-cd") {
112 } else if (state == "connection") {
113 SomePlayer::Storage::Config config;
114 if (config.getValue("hw/hpautopause").toString() != "yes") {
117 bool present = QDBusInterface ("org.freedesktop.Hal",
118 "/org/freedesktop/Hal/devices/platform_headphone",
119 "org.freedesktop.Hal.Device",
120 QDBusConnection::systemBus()).call ("GetProperty", "button.state.value").arguments().at(0).toBool();
124 QTimer::singleShot(1000, this, SLOT(playIfPaused()));
133 void DBusAdaptop::pause() {
134 QMetaObject::invokeMethod(parent(), "pause");
137 void DBusAdaptop::playIfPaused() {
138 QMetaObject::invokeMethod(parent(), "playIfPaused");