Restoring eq after start, checkable fav button
[someplayer] / src / dbusadaptor.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 "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>
28 #include <QDebug>
29
30 /*
31  * Implementation of adaptor class DBusAdaptop
32  */
33
34 DBusAdaptop::DBusAdaptop(QObject *parent)
35     : QDBusAbstractAdaptor(parent)
36 {
37     // constructor
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";
44     }
45 }
46
47 DBusAdaptop::~DBusAdaptop()
48 {
49     // destructor
50 }
51
52 QString DBusAdaptop::album()
53 {
54     // handle method call ru.somebody.someplayer.album
55     QString out0;
56     QMetaObject::invokeMethod(parent(), "album", Q_RETURN_ARG(QString, out0));
57     return out0;
58 }
59
60 QString DBusAdaptop::artist()
61 {
62     // handle method call ru.somebody.someplayer.artist
63     QString out0;
64     QMetaObject::invokeMethod(parent(), "artist", Q_RETURN_ARG(QString, out0));
65     return out0;
66 }
67
68 void DBusAdaptop::next()
69 {
70     // handle method call ru.somebody.someplayer.next
71     QMetaObject::invokeMethod(parent(), "next");
72 }
73
74 void DBusAdaptop::prev()
75 {
76     // handle method call ru.somebody.someplayer.prev
77     QMetaObject::invokeMethod(parent(), "prev");
78 }
79
80 void DBusAdaptop::stop()
81 {
82     // handle method call ru.somebody.someplayer.stop
83     QMetaObject::invokeMethod(parent(), "stop");
84 }
85
86 QString DBusAdaptop::title()
87 {
88     // handle method call ru.somebody.someplayer.title
89     QString out0;
90     QMetaObject::invokeMethod(parent(), "title", Q_RETURN_ARG(QString, out0));
91     return out0;
92 }
93
94 void DBusAdaptop::toggle()
95 {
96     // handle method call ru.somebody.someplayer.toggle
97     QMetaObject::invokeMethod(parent(), "toggle");
98 }
99
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") {
106                                 next();
107                         } else if (state == "previous-song") {
108                                 prev();
109                         } else if (state == "play-cd" || state == "pause-cd") {
110                                 toggle();
111                         }
112                 }
113         }
114         _time = t;
115 }