From 1920540a3298be217bf96dcdb951c4a28e35b7bf Mon Sep 17 00:00:00 2001 From: Nikolay Tischenko Date: Tue, 5 Oct 2010 00:56:24 +0700 Subject: [PATCH] Added D-Bus support Service description in resources/ru.somebody.someplayer.xml --- resources/ru.somebody.someplayer.xml | 47 +++++++++++++++++ someplayer.pro | 8 +-- src/dbusadaptor.cpp | 92 ++++++++++++++++++++++++++++++++++ src/dbusadaptor.h | 80 +++++++++++++++++++++++++++++ src/libraryform.cpp | 1 + src/main.cpp | 2 +- src/mainwindow.cpp | 1 + src/player/player.cpp | 18 +++++++ src/player/player.h | 3 ++ src/playerform.cpp | 7 +++ src/playerform.h | 2 + src/someplayer.h | 4 +- src/ui/settingsdialog.ui | 49 ++---------------- 13 files changed, 263 insertions(+), 51 deletions(-) create mode 100644 resources/ru.somebody.someplayer.xml create mode 100644 src/dbusadaptor.cpp create mode 100644 src/dbusadaptor.h diff --git a/resources/ru.somebody.someplayer.xml b/resources/ru.somebody.someplayer.xml new file mode 100644 index 0000000..06a7b50 --- /dev/null +++ b/resources/ru.somebody.someplayer.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/someplayer.pro b/someplayer.pro index c446198..2aae545 100644 --- a/someplayer.pro +++ b/someplayer.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui phonon sql +QT += core gui phonon sql dbus TARGET = someplayer TEMPLATE = app @@ -120,7 +120,8 @@ SOURCES += src/main.cpp\ src/timerdialog.cpp \ src/equalizerdialog.cpp \ src/saveplaylistdialog.cpp \ - src/settingsdialog.cpp + src/settingsdialog.cpp \ + src/dbusadaptor.cpp HEADERS += src/mainwindow.h \ src/player/player.h \ @@ -219,7 +220,8 @@ HEADERS += src/mainwindow.h \ src/equalizerdialog.h \ src/saveplaylistdialog.h \ src/settingsdialog.h \ - src/abstractitemrenderer.h + src/abstractitemrenderer.h \ + src/dbusadaptor.h FORMS += src/ui/mainwindow.ui \ src/ui/playerform.ui \ diff --git a/src/dbusadaptor.cpp b/src/dbusadaptor.cpp new file mode 100644 index 0000000..25b90e0 --- /dev/null +++ b/src/dbusadaptor.cpp @@ -0,0 +1,92 @@ +/* + * SomePlayer - An alternate music player for Maemo 5 + * Copyright (C) 2010 Nikolay (somebody) Tischenko + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "dbusadaptor.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class DBusAdaptop + */ + +DBusAdaptop::DBusAdaptop(QObject *parent) + : QDBusAbstractAdaptor(parent) +{ + // constructor + setAutoRelaySignals(true); +} + +DBusAdaptop::~DBusAdaptop() +{ + // destructor +} + +QString DBusAdaptop::album() +{ + // handle method call ru.somebody.someplayer.album + QString out0; + QMetaObject::invokeMethod(parent(), "album", Q_RETURN_ARG(QString, out0)); + return out0; +} + +QString DBusAdaptop::artist() +{ + // handle method call ru.somebody.someplayer.artist + QString out0; + QMetaObject::invokeMethod(parent(), "artist", Q_RETURN_ARG(QString, out0)); + return out0; +} + +void DBusAdaptop::next() +{ + // handle method call ru.somebody.someplayer.next + QMetaObject::invokeMethod(parent(), "next"); +} + +void DBusAdaptop::prev() +{ + // handle method call ru.somebody.someplayer.prev + QMetaObject::invokeMethod(parent(), "prev"); +} + +void DBusAdaptop::stop() +{ + // handle method call ru.somebody.someplayer.stop + QMetaObject::invokeMethod(parent(), "stop"); +} + +QString DBusAdaptop::title() +{ + // handle method call ru.somebody.someplayer.title + QString out0; + QMetaObject::invokeMethod(parent(), "title", Q_RETURN_ARG(QString, out0)); + return out0; +} + +void DBusAdaptop::toggle() +{ + // handle method call ru.somebody.someplayer.toggle + QMetaObject::invokeMethod(parent(), "toggle"); +} + diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h new file mode 100644 index 0000000..30ebd0b --- /dev/null +++ b/src/dbusadaptor.h @@ -0,0 +1,80 @@ +/* + * SomePlayer - An alternate music player for Maemo 5 + * Copyright (C) 2010 Nikolay (somebody) Tischenko + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef DBUSADAPTOR +#define DBUSADAPTOR + +#include +#include +class QByteArray; +template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; + +/* + * Adaptor class for interface ru.somebody.someplayer + */ +class DBusAdaptop: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "ru.somebody.someplayer") + Q_CLASSINFO("D-Bus Introspection", "" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + DBusAdaptop(QObject *parent); + virtual ~DBusAdaptop(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + QString album(); + QString artist(); + Q_NOREPLY void next(); + Q_NOREPLY void prev(); + Q_NOREPLY void stop(); + QString title(); + Q_NOREPLY void toggle(); +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/src/libraryform.cpp b/src/libraryform.cpp index 756baba..bb190f1 100644 --- a/src/libraryform.cpp +++ b/src/libraryform.cpp @@ -87,6 +87,7 @@ LibraryForm::LibraryForm(Library *lib, QWidget *parent) : Config config; _icons_theme = config.getValue("ui/iconstheme").toString(); _current_playlist_changed = true; + setAttribute(Qt::WA_Maemo5StackedWindow); } LibraryForm::~LibraryForm() diff --git a/src/main.cpp b/src/main.cpp index 1fca7d9..84fb50f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - a.setApplicationName("someplayer"); + a.setApplicationName("ru.somebody.someplayer"); MainWindow w; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8fe95e9..f704c25 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -91,6 +91,7 @@ MainWindow::MainWindow(QWidget *parent) : _library_form->updateIcons(); _player_form->updateIcons(); hideSearchPanel(); + _player_form->reload(true); library(); } diff --git a/src/player/player.cpp b/src/player/player.cpp index 6aa78d6..80fc64e 100644 --- a/src/player/player.cpp +++ b/src/player/player.cpp @@ -302,3 +302,21 @@ void Player::setEqualizerValue(int band, double value) { Config config; config.setValue(QString("equalizer/band%1").arg(band), value); } + +QString Player::artist() { + if (_current < 0) + return ""; + return _playlist.tracks().at(_current).metadata().artist(); +} + +QString Player::album() { + if (_current < 0) + return ""; + return _playlist.tracks().at(_current).metadata().album(); +} + +QString Player::title() { + if (_current < 0) + return ""; + return _playlist.tracks().at(_current).metadata().title(); +} diff --git a/src/player/player.h b/src/player/player.h index ee520da..562aad4 100644 --- a/src/player/player.h +++ b/src/player/player.h @@ -93,6 +93,9 @@ namespace SomePlayer { void disableEqualizer(); void setEqualizerValue(int band, double value); void equalizerValue(int band, double *); + QString artist(); + QString album(); + QString title(); private slots: void _stateChanged(Phonon::State, Phonon::State); void _tick(qint64); diff --git a/src/playerform.cpp b/src/playerform.cpp index 20118df..3bf359c 100644 --- a/src/playerform.cpp +++ b/src/playerform.cpp @@ -116,6 +116,13 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) : connect(_tag_resolver, SIGNAL(decoded(Track)), this, SLOT(_track_decoded(Track))); connect(ui->volumeButton, SIGNAL(clicked()), this, SLOT(_toggle_volume())); ui->topWidget->setVisible(false); + setAttribute(Qt::WA_Maemo5StackedWindow); + + // dbus + _dbusadaptor = new DBusAdaptop(_player); + QDBusConnection connection = QDBusConnection::sessionBus(); + bool ret = connection.registerService(_SERVICE_NAME_); + ret = connection.registerObject("/", _player); } PlayerForm::~PlayerForm() diff --git a/src/playerform.h b/src/playerform.h index 7d5e3db..59a3299 100644 --- a/src/playerform.h +++ b/src/playerform.h @@ -30,6 +30,7 @@ #include #include "trackrenderer.h" #include "tagresolver.h" +#include "dbusadaptor.h" namespace Ui { class PlayerForm; @@ -110,6 +111,7 @@ private: int _search_current_id; QString _icons_theme; + DBusAdaptop *_dbusadaptor; }; #endif // PLAYERFORM_H diff --git a/src/someplayer.h b/src/someplayer.h index 8cb4600..159797a 100644 --- a/src/someplayer.h +++ b/src/someplayer.h @@ -47,7 +47,9 @@ namespace SomePlayer { #include "config.h" #define _DYNAMIC_PLAYLIST_MAX_COUNT_ 50 -#define _SOMEPLAYER_VERSION_ "1.3.2" +#define _SOMEPLAYER_VERSION_ "1.3.3" #define NDEBUG +#define _SERVICE_NAME_ "ru.somebody.someplayer" + #endif diff --git a/src/ui/settingsdialog.ui b/src/ui/settingsdialog.ui index 5208f75..8368d57 100644 --- a/src/ui/settingsdialog.ui +++ b/src/ui/settingsdialog.ui @@ -25,8 +25,8 @@ 0 - -88 - 760 + 0 + 776 296 @@ -187,53 +187,10 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - buttonBox - accepted() - SettingsDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - SettingsDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + -- 1.7.9.5