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>
31 * Implementation of adaptor class DBusAdaptop
34 DBusAdaptop::DBusAdaptop(QObject *parent)
35 : QDBusAbstractAdaptor(parent)
38 setAutoRelaySignals(true);
39 // handling signals from bluetooth headset
40 _time = QTime::currentTime();
41 if (!QDBusConnection::systemBus().connect(QString(), QString(),
42 "org.freedesktop.Hal.Device", "Condition", this, SLOT(processBTSignal(QString, QString)))) {
43 qWarning() << "Can not connect to HAL";
47 DBusAdaptop::~DBusAdaptop()
52 QString DBusAdaptop::album()
54 // handle method call ru.somebody.someplayer.album
56 QMetaObject::invokeMethod(parent(), "album", Q_RETURN_ARG(QString, out0));
60 QString DBusAdaptop::artist()
62 // handle method call ru.somebody.someplayer.artist
64 QMetaObject::invokeMethod(parent(), "artist", Q_RETURN_ARG(QString, out0));
68 void DBusAdaptop::next()
70 // handle method call ru.somebody.someplayer.next
71 QMetaObject::invokeMethod(parent(), "next");
74 void DBusAdaptop::prev()
76 // handle method call ru.somebody.someplayer.prev
77 QMetaObject::invokeMethod(parent(), "prev");
80 void DBusAdaptop::stop()
82 // handle method call ru.somebody.someplayer.stop
83 QMetaObject::invokeMethod(parent(), "stop");
86 QString DBusAdaptop::title()
88 // handle method call ru.somebody.someplayer.title
90 QMetaObject::invokeMethod(parent(), "title", Q_RETURN_ARG(QString, out0));
94 void DBusAdaptop::toggle()
96 // handle method call ru.somebody.someplayer.toggle
97 QMetaObject::invokeMethod(parent(), "toggle");
100 void DBusAdaptop::processBTSignal(QString event, QString state) {
101 QTime t = QTime::currentTime();
102 long msec = _time.msecsTo(t);
103 if (msec > _DBUS_ACTION_TIMEOUT_) {
104 if (event == "ButtonPressed") {
105 if (state == "next-song") {
107 } else if (state == "previous-song") {
109 } else if (state == "play-cd" || state == "pause-cd") {