diff options
Diffstat (limited to 'src/plugins/General/mpris')
| -rw-r--r-- | src/plugins/General/mpris/CMakeLists.txt | 63 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris.cpp | 56 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris.h | 57 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris.pro | 46 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mprisfactory.cpp | 61 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mprisfactory.h | 45 | ||||
| -rw-r--r-- | src/plugins/General/mpris/playerobject.cpp | 117 | ||||
| -rw-r--r-- | src/plugins/General/mpris/playerobject.h | 77 | ||||
| -rw-r--r-- | src/plugins/General/mpris/rootobject.cpp | 49 | ||||
| -rw-r--r-- | src/plugins/General/mpris/rootobject.h | 52 |
10 files changed, 623 insertions, 0 deletions
diff --git a/src/plugins/General/mpris/CMakeLists.txt b/src/plugins/General/mpris/CMakeLists.txt new file mode 100644 index 000000000..d82bd30f3 --- /dev/null +++ b/src/plugins/General/mpris/CMakeLists.txt @@ -0,0 +1,63 @@ +project(libmpris) + +cmake_minimum_required(VERSION 2.4.8 FATAL_ERROR) + +SET (QT_USE_QTDBUS TRUE) + +INCLUDE(FindQt4) + +include(${QT_USE_FILE}) + +if(COMMAND cmake_policy) +cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + + + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +# libqmmpui & libqmmp +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) + +SET(libmpris_SRCS + mpris.cpp + mprisfactory.cpp + rootobject.cpp + playerobject.cpp +) + +SET(libmpris_MOC_HDRS + mprisfactory.h + mpris.h + rootobject.h + playerobject.h +) + +SET(libmpris_RCCS translations/translations.qrc) + +QT4_ADD_RESOURCES(libmpris_RCC_SRCS ${libmpris_RCCS}) + +QT4_WRAP_CPP(libmpris_MOC_SRCS ${libmpris_MOC_HDRS}) + +# user interface + + +# QT4_WRAP_UI(libmpris_UIS_H ${libmpris_UIS}) +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_LIBRARY(mpris SHARED ${libmpris_SRCS} ${libmpris_MOC_SRCS} ${libmpris_RCC_SRCS}) +add_dependencies(mpris qmmpui libqmmp) +target_link_libraries(mpris ${QT_LIBRARIES} -lqmmpui -lqmmp) +install(TARGETS mpris DESTINATION ${LIB_DIR}/qmmp/General) diff --git a/src/plugins/General/mpris/mpris.cpp b/src/plugins/General/mpris/mpris.cpp new file mode 100644 index 000000000..e2a6612ee --- /dev/null +++ b/src/plugins/General/mpris/mpris.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QtDBus> + +#include "playerobject.h" +#include "rootobject.h" +#include "mpris.h" + +MPRIS::MPRIS(QObject *parent) + : General(parent) +{ + PlayerObject *player = new PlayerObject(this); + RootObject *root = new RootObject(this); + QDBusConnection connection = QDBusConnection::sessionBus(); + connection.registerObject("/Player", player, QDBusConnection::ExportAllContents); + connection.registerObject("/", root, QDBusConnection::ExportAllContents); + connection.registerService("org.mpris.qmmp"); + m_left = 0; + m_right = 0; + m_time = 0; + //m_state = General::Stopped; +} + + +MPRIS::~MPRIS() +{ +} + +int MPRIS::leftVolume() +{ + return m_left; +} + +int MPRIS::rightVolume() +{ + return m_right; +} + diff --git a/src/plugins/General/mpris/mpris.h b/src/plugins/General/mpris/mpris.h new file mode 100644 index 000000000..8b90d2881 --- /dev/null +++ b/src/plugins/General/mpris/mpris.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef MPRIS_H +#define MPRIS_H + + +#include <qmmpui/general.h> + +class DBUSAdaptor; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ + +class MPRIS : public General +{ +Q_OBJECT +public: + MPRIS(QObject *parent = 0); + + ~MPRIS(); + +signals: + void stateChanged(); + void timeChanged(); + void volumeChanged(); + void songChanged(); + +public slots: + int leftVolume(); + int rightVolume(); + +private: + DBUSAdaptor *m_adaptor; + int m_left, m_right; + uint m_state; + int m_time; +}; + +#endif diff --git a/src/plugins/General/mpris/mpris.pro b/src/plugins/General/mpris/mpris.pro new file mode 100644 index 000000000..af6fec72a --- /dev/null +++ b/src/plugins/General/mpris/mpris.pro @@ -0,0 +1,46 @@ +include(../../plugins.pri) + +CONFIG += release \ +warn_on \ +plugin \ + lib \ + qdbus + +TARGET =$$PLUGINS_PREFIX/General/mpris +QMAKE_CLEAN =$$PLUGINS_PREFIX/General/libmpris.so + +TEMPLATE = lib +QMAKE_LIBDIR += ../../../../lib + +TRANSLATIONS = translations/mpris_plugin_cs.ts \ + translations/mpris_plugin_de.ts \ + translations/mpris_plugin_zh_CN.ts \ + translations/mpris_plugin_zh_TW.ts \ + translations/mpris_plugin_ru.ts \ + translations/mpris_plugin_uk_UA.ts +RESOURCES = translations/translations.qrc + +isEmpty(LIB_DIR){ + LIB_DIR = /lib +} +target.path = $$LIB_DIR/qmmp/General +INSTALLS += target +#FORMS += settingsdialog.ui + +#RESOURCES += images/images.qrc + + +HEADERS += mprisfactory.h \ + mpris.h \ + playerobject.h \ + rootobject.h + +SOURCES += mprisfactory.cpp \ + mpris.cpp \ + playerobject.cpp \ + rootobject.cpp + +INCLUDEPATH += ../../../../src + +LIBS += -lqmmpui -lqmmp + diff --git a/src/plugins/General/mpris/mprisfactory.cpp b/src/plugins/General/mpris/mprisfactory.cpp new file mode 100644 index 000000000..c7011486d --- /dev/null +++ b/src/plugins/General/mpris/mprisfactory.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QtGui> + +#include "mpris.h" +#include "mprisfactory.h" + +const GeneralProperties MPRISFactory::properties() const +{ + GeneralProperties properties; + properties.name = tr("MPRIS Plugin"); + properties.hasAbout = TRUE; + properties.hasSettings = FALSE; + properties.visibilityControl = FALSE; + return properties; +} + +General *MPRISFactory::create(QObject *parent) +{ + return new MPRIS(parent); +} + +QDialog *MPRISFactory::createConfigDialog(QWidget *) +{ + return 0; +} + +void MPRISFactory::showAbout(QWidget *parent) +{ + QMessageBox::about (parent, tr("About MPRIS Plugin"), + tr("Qmmp MPRIS Plugin")+"\n"+ + tr("Writen by: Ilya Kotov <forkotov02@hotmail.ru>")); +} + +QTranslator *MPRISFactory::createTranslator(QObject *parent) +{ + QTranslator *translator = new QTranslator(parent); + QString locale = QLocale::system().name(); + translator->load(QString(":/mpris_plugin_") + locale); + return translator; +} + +Q_EXPORT_PLUGIN(MPRISFactory) diff --git a/src/plugins/General/mpris/mprisfactory.h b/src/plugins/General/mpris/mprisfactory.h new file mode 100644 index 000000000..27708dd6e --- /dev/null +++ b/src/plugins/General/mpris/mprisfactory.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef MPRISFACTORY_H +#define MPRISFACTORY_H + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +#include <QObject> +#include <QTranslator> + +#include <qmmpui/general.h> +#include <qmmpui/generalfactory.h> + +class MPRISFactory : public QObject, public GeneralFactory +{ +Q_OBJECT +Q_INTERFACES(GeneralFactory); +public: + const GeneralProperties properties() const; + General *create(QObject *parent); + QDialog *createConfigDialog(QWidget *parent); + void showAbout(QWidget *parent); + QTranslator *createTranslator(QObject *parent); + +}; + +#endif diff --git a/src/plugins/General/mpris/playerobject.cpp b/src/plugins/General/mpris/playerobject.cpp new file mode 100644 index 000000000..21c296dec --- /dev/null +++ b/src/plugins/General/mpris/playerobject.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QFile> +#include <qmmp/soundcore.h> + +#include "playerobject.h" + +PlayerObject::PlayerObject(QObject *parent) + : QDBusAbstractAdaptor(parent) +{ + setAutoRelaySignals(TRUE); + m_core = SoundCore::instance(); +} + +PlayerObject::~PlayerObject() +{} + +void PlayerObject::Next() +{ + +} + +void PlayerObject::Prev() +{ + +} + +void PlayerObject::Pause() +{ + m_core->pause(); +} + +void PlayerObject::Stop() +{ + m_core->stop(); +} + +void PlayerObject::Play() +{ + //m_core->play(); +} + +PlayerStatus PlayerObject::GetStatus() +{ + PlayerStatus st; + st.state = 2; + if (m_core->state() == Qmmp::Playing) + st.state = 0; + else if (m_core->state() == Qmmp::Paused) + st.state = 1; + st.random = 0; //TODO playlist support + st.repeat = 0; + st.repeatPlayList = 0; + return st; +} + +QVariantMap PlayerObject::GetMetadata() +{ + QVariantMap map; + + if (QFile::exists(m_core->metaData(Qmmp::URL))) + map.insert("location", "file://" +m_core->metaData(Qmmp::URL)); + else + map.insert("location", m_core->metaData(Qmmp::URL)); + map.insert("title", m_core->metaData(Qmmp::TITLE)); + map.insert("artist", m_core->metaData(Qmmp::ARTIST)); + map.insert("album", m_core->metaData(Qmmp::ALBUM)); + map.insert("tracknumber", m_core->metaData(Qmmp::TRACK)); + map.insert("time", m_core->length()); + map.insert("mtime", m_core->length() * 1000); + map.insert("genre", m_core->metaData(Qmmp::GENRE)); + map.insert("comment", m_core->metaData(Qmmp::COMMENT)); + map.insert("audio-bitrate", m_core->bitrate()); + map.insert("audio-samplerate", m_core->frequency()); + map.insert("year", m_core->metaData(Qmmp::YEAR)); + return map; +} + +void PlayerObject::VolumeSet(int volume) +{ + int balance = (m_core->rightVolume() - m_core->leftVolume()) * 100/VolumeGet(); + m_core->setVolume(volume - qMax(balance,0)*volume/100, + volume + qMin(balance,0)*volume/100); +} + +int PlayerObject::VolumeGet() +{ + return qMax(m_core->leftVolume(), m_core->rightVolume()); +} + +void PlayerObject::PositionSet(int pos) +{ + m_core->seek(pos / 1000); +} + +qint64 PlayerObject::PositionGet() +{ + return m_core->elapsed() * 1000; +} diff --git a/src/plugins/General/mpris/playerobject.h b/src/plugins/General/mpris/playerobject.h new file mode 100644 index 000000000..09f112728 --- /dev/null +++ b/src/plugins/General/mpris/playerobject.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PLAYEROBJECT_H +#define PLAYEROBJECT_H + +#include <QtDBus> +#include <QString> +#include <QVariant> + +class SoundCore; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ + +struct PlayerStatus +{ + int state; // 0 = Playing, 1 = Paused, 2 = Stopped. + int random; // 0 = Playing linearly, 1 = Playing randomly. + int repeat; // 0 = Go to the next element once the current has finished playing, 1 = Repeat the current element + int repeatPlayList; // 0 = Stop playing once the last element has been played, 1 = Never give up playing +}; + + +class PlayerObject : public QDBusAbstractAdaptor +{ +Q_OBJECT +Q_CLASSINFO("D-Bus Interface", "org.freedesktop.MediaPlayer") + +public: + PlayerObject(QObject *parent = 0); + + ~PlayerObject(); + +public slots: + void Next(); + void Prev(); + void Pause(); + void Stop(); + void Play(); + //void Repeat(); + PlayerStatus GetStatus(); + QVariantMap GetMetadata(); + //GetCaps + void VolumeSet(int in0); + int VolumeGet(); + void PositionSet(int in0); + qint64 PositionGet(); + +signals: + //TrackChange + //StatusChange + //CapsChange + +private: + SoundCore *m_core; + +}; + +#endif diff --git a/src/plugins/General/mpris/rootobject.cpp b/src/plugins/General/mpris/rootobject.cpp new file mode 100644 index 000000000..4869fd862 --- /dev/null +++ b/src/plugins/General/mpris/rootobject.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "rootobject.h" + +RootObject::RootObject(QObject *parent) + : QDBusAbstractAdaptor(parent) +{ +} + + +RootObject::~RootObject() +{ +} + +QString RootObject::Identity() +{ + QString name = "Qmmp 0.3.0-svn"; + return name; +} + +Version RootObject::MprisVersion() +{ + struct Version v; + v.major = 1; + v.minor = 0; + return v; +} + +void RootObject::Quit() +{ + QMetaObject::invokeMethod(parent(), "exit"); +} diff --git a/src/plugins/General/mpris/rootobject.h b/src/plugins/General/mpris/rootobject.h new file mode 100644 index 000000000..1bae78e4c --- /dev/null +++ b/src/plugins/General/mpris/rootobject.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef ROOTOBJECT_H +#define ROOTOBJECT_H + +#include <QDBusAbstractAdaptor> +#include <QString> + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ + + +struct Version +{ + quint16 major; + quint16 minor; +}; + +class RootObject : public QDBusAbstractAdaptor +{ +Q_OBJECT +Q_CLASSINFO("D-Bus Interface", "org.freedesktop.MediaPlayer") +public: + RootObject(QObject *parent = 0); + + ~RootObject(); + +public slots: + QString Identity(); + Version MprisVersion(); + void Quit(); +}; + +#endif |
