diff options
Diffstat (limited to 'src/plugins/General/mpris/mpris1')
| -rw-r--r-- | src/plugins/General/mpris/mpris1/playerobject.cpp | 199 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris1/playerobject.h | 101 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris1/rootobject.cpp | 75 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris1/rootobject.h | 54 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris1/tracklistobject.cpp | 144 | ||||
| -rw-r--r-- | src/plugins/General/mpris/mpris1/tracklistobject.h | 70 |
6 files changed, 643 insertions, 0 deletions
diff --git a/src/plugins/General/mpris/mpris1/playerobject.cpp b/src/plugins/General/mpris/mpris1/playerobject.cpp new file mode 100644 index 000000000..e5d4af632 --- /dev/null +++ b/src/plugins/General/mpris/mpris1/playerobject.cpp @@ -0,0 +1,199 @@ +/*************************************************************************** + * Copyright (C) 2008-2009 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 <QDBusMetaType> +#include <QDBusArgument> +#include <qmmp/soundcore.h> +#include <qmmp/metadatamanager.h> +#include <qmmpui/mediaplayer.h> +#include <qmmpui/playlistmanager.h> + +#include "playerobject.h" + + +//register << operator +QDBusArgument &operator << (QDBusArgument &arg, const PlayerStatus &status) +{ + arg.beginStructure(); + arg << status.state; + arg << status.random; + arg << status.repeat; + arg << status.repeatPlayList; + arg.endStructure(); + return arg; +} + +//register >> operator +const QDBusArgument &operator >> (const QDBusArgument &arg, PlayerStatus &status) +{ + arg.beginStructure(); + arg >> status.state; + arg >> status.random; + arg >> status.repeat; + arg >> status.repeatPlayList; + arg.endStructure(); + return arg; +} + +PlayerObject::PlayerObject(QObject *parent) : QObject(parent) +{ + qDBusRegisterMetaType<PlayerStatus>(); + m_core = SoundCore::instance(); + m_player = MediaPlayer::instance(); + m_pl_manager = m_player->playListManager(); + connect(m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(updateCaps())); + connect(m_core, SIGNAL(metaDataChanged ()), SLOT(updateTrack())); + connect(m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(updateStatus())); + connect(m_pl_manager, SIGNAL(repeatableListChanged(bool)), SLOT(updateStatus())); + connect(m_pl_manager, SIGNAL(shuffleChanged(bool)), SLOT(updateStatus())); + connect(m_player, SIGNAL(repeatableChanged(bool)), SLOT(updateStatus())); +} + +PlayerObject::~PlayerObject() +{} + +void PlayerObject::Next() +{ + m_player->next(); +} + +void PlayerObject::Prev() +{ + m_player->previous(); +} + +void PlayerObject::Pause() +{ + m_core->pause(); +} + +void PlayerObject::Stop() +{ + m_player->stop(); +} + +void PlayerObject::Play() +{ + m_player->play(); +} + +void PlayerObject::Repeat(bool in0) +{ + m_player->setRepeatable(in0); +} + +PlayerStatus PlayerObject::GetStatus() +{ + PlayerStatus st; + switch (m_core->state()) + { + case Qmmp::Stopped: + case Qmmp::NormalError: + case Qmmp::FatalError: + st.state = 2; + break; + case Qmmp::Playing: + case Qmmp::Buffering: + st.state = 0; + break; + case Qmmp::Paused: + st.state = 1; + }; + st.random = int(m_pl_manager->isShuffle()); + st.repeat = int(m_player->isRepeatable()); + st.repeatPlayList = int(m_pl_manager->isRepeatableList()); + return st; +} + +QVariantMap PlayerObject::GetMetadata() +{ + QVariantMap map; + + if (m_core->metaData(Qmmp::URL).contains("://")) + map.insert("location", m_core->metaData(Qmmp::URL)); + else + map.insert("location", "file://" + m_core->metaData(Qmmp::URL)); + map.insert("arturl", MetaDataManager::instance()->getCoverPath(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", (quint32)m_core->totalTime()/1000); + map.insert("mtime", (quint32)m_core->totalTime()); + map.insert("genre", m_core->metaData(Qmmp::GENRE)); + map.insert("comment", m_core->metaData(Qmmp::COMMENT)); + map.insert("audio-bitrate", (quint32)m_core->bitrate()); + map.insert("audio-samplerate", (quint32)m_core->frequency()); + map.insert("year", m_core->metaData(Qmmp::YEAR).toUInt()); + return map; +} + +int PlayerObject::GetCaps() +{ + int caps = NONE; + if (GetStatus().state == 0) + caps |= CAN_PAUSE; + else + caps |= CAN_PLAY; + if ((GetStatus().state < 2) && (m_core->totalTime() > 0)) + caps |= CAN_SEEK; + caps |= CAN_GO_NEXT; + caps |= CAN_GO_PREV; + caps |= CAN_PROVIDE_METADATA; + return caps; +} + +void PlayerObject::VolumeSet(int volume) +{ + int balance = (VolumeGet() > 0) ? (m_core->rightVolume() - m_core->leftVolume()) * 100/VolumeGet() : 0; + 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); +} + +int PlayerObject::PositionGet() +{ + return m_core->elapsed(); +} + +void PlayerObject::updateCaps() +{ + emit CapsChange(GetCaps()); +} + +void PlayerObject::updateTrack() +{ + emit TrackChange(GetMetadata()); +} + +void PlayerObject::updateStatus() +{ + emit StatusChange(GetStatus()); +} diff --git a/src/plugins/General/mpris/mpris1/playerobject.h b/src/plugins/General/mpris/mpris1/playerobject.h new file mode 100644 index 000000000..709357387 --- /dev/null +++ b/src/plugins/General/mpris/mpris1/playerobject.h @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright (C) 2008-2009 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 <QObject> +#include <QVariantMap> + +class SoundCore; +class MediaPlayer; +class PlayListManager; + +/** + @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 +}; + +Q_DECLARE_METATYPE(PlayerStatus); + +class PlayerObject : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.MediaPlayer") + +public: + PlayerObject(QObject *parent = 0); + + ~PlayerObject(); + + + enum PlayerCaps + { + + NONE = 0, + CAN_GO_NEXT = 1 << 0, + CAN_GO_PREV = 1 << 1, + CAN_PAUSE = 1 << 2, + CAN_PLAY = 1 << 3, + CAN_SEEK = 1 << 4, + CAN_PROVIDE_METADATA = 1 << 5, + CAN_HAS_TRACKLIST = 1 << 6 + }; + + +public slots: + void Next(); + void Prev(); + void Pause(); + void Stop(); + void Play(); + void Repeat(bool in0); + PlayerStatus GetStatus(); + QVariantMap GetMetadata(); + int GetCaps(); + void VolumeSet(int in0); + int VolumeGet(); + void PositionSet(int in0); + int PositionGet(); + +signals: + void CapsChange(int); + void TrackChange(QVariantMap); + void StatusChange(PlayerStatus); + +private slots: + void updateCaps(); + void updateTrack(); + void updateStatus(); + +private: + SoundCore *m_core; + MediaPlayer *m_player; + PlayListManager *m_pl_manager; + +}; + +#endif diff --git a/src/plugins/General/mpris/mpris1/rootobject.cpp b/src/plugins/General/mpris/mpris1/rootobject.cpp new file mode 100644 index 000000000..7c4267d08 --- /dev/null +++ b/src/plugins/General/mpris/mpris1/rootobject.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + * 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 <QDBusMetaType> +#include <QDBusArgument> + +#include <qmmp/qmmp.h> +#include "rootobject.h" + +//register << operator +QDBusArgument &operator << (QDBusArgument &arg, const Version &v) +{ + arg.beginStructure(); + arg << v.major; + arg << v.minor; + arg.endStructure(); + return arg; +} + +//register >> operator +const QDBusArgument &operator >> (const QDBusArgument &arg, Version &v) +{ + arg.beginStructure(); + arg >> v.major; + arg >> v.minor; + arg.endStructure(); + return arg; +} + +RootObject::RootObject(QObject *parent) + : QObject(parent) +{ + qDBusRegisterMetaType<Version>(); +} + + +RootObject::~RootObject() +{ +} + +QString RootObject::Identity() +{ + QString name = "Qmmp " + Qmmp::strVersion(); + 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/mpris1/rootobject.h b/src/plugins/General/mpris/mpris1/rootobject.h new file mode 100644 index 000000000..378d9f51a --- /dev/null +++ b/src/plugins/General/mpris/mpris1/rootobject.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * 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 <QObject> +#include <QVariantMap> + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ + + +struct Version +{ + quint16 major; + quint16 minor; +}; + +Q_DECLARE_METATYPE(Version); + +class RootObject : public QObject +{ +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 diff --git a/src/plugins/General/mpris/mpris1/tracklistobject.cpp b/src/plugins/General/mpris/mpris1/tracklistobject.cpp new file mode 100644 index 000000000..63e4dfe89 --- /dev/null +++ b/src/plugins/General/mpris/mpris1/tracklistobject.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + * 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 <QUrl> + +#include <qmmpui/playlistmanager.h> +#include <qmmpui/mediaplayer.h> +#include <qmmpui/playlistitem.h> + +#include "tracklistobject.h" + +TrackListObject::TrackListObject(QObject *parent) : QObject(parent) +{ + m_player = MediaPlayer::instance(); + m_pl_manager = m_player->playListManager(); + m_model = m_pl_manager->currentPlayList(); + connect (m_model, SIGNAL(listChanged()), SLOT(updateTrackList())); + connect (m_pl_manager, SIGNAL(currentPlayListChanged(PlayListModel*,PlayListModel*)), + SLOT(switchPlayList(PlayListModel*,PlayListModel*))); + m_prev_count = 0; +} + + +TrackListObject::~TrackListObject() +{ +} + +int TrackListObject::AddTrack(const QString &in0, bool in1) +{ + QString path = in0; + if(in0.startsWith("file://")) + { + path = QUrl(in0).toLocalFile (); + if(!QFile::exists(path)) + return 1; //error + } + if(in1) + { + m_pl_manager->selectPlayList(m_model); + m_player->stop(); + m_prev_count = m_model->count(); + connect(m_model, SIGNAL(listChanged()), this, SLOT(checkNewItem())); + connect(m_model, SIGNAL(loaderFinished()), this, SLOT(disconnectPl())); + } + m_model->add(path); + return 0; +} + +void TrackListObject::DelTrack(int in0) +{ + m_model->removeAt(in0); +} + +int TrackListObject::GetCurrentTrack() +{ + return m_model->currentRow(); +} + +int TrackListObject::GetLength() +{ + return m_model->count(); +} + +QVariantMap TrackListObject::GetMetadata(int in0) +{ + QVariantMap map; + PlayListItem *item = m_model->item(in0); + if (item) + { + if (QFile::exists(item->url())) + map.insert("location", "file://" + item->url()); + else + map.insert("location", item->url()); + map.insert("title", item->value(Qmmp::TITLE)); + map.insert("artist", item->value(Qmmp::ARTIST)); + map.insert("album", item->value(Qmmp::ALBUM)); + map.insert("tracknumber", item->value(Qmmp::TRACK)); + map.insert("time", (quint32)item->length()); + map.insert("mtime", (quint32)item->length() * 1000); + map.insert("genre", item->value(Qmmp::GENRE)); + map.insert("comment", item->value(Qmmp::COMMENT)); + map.insert("year", item->value(Qmmp::YEAR).toUInt()); + } + return map; +} + +void TrackListObject::SetLoop(bool in0) +{ + m_pl_manager->setRepeatableList(in0); +} + +void TrackListObject::SetRandom(bool in0) +{ + m_pl_manager->setShuffle(in0); +} + +void TrackListObject::disconnectPl() +{ + disconnect(m_model, SIGNAL(listChanged()), this, SLOT(checkNewItem())); + disconnect(m_model, SIGNAL(loaderFinished()), this, SLOT(disconnectPl())); +} + +void TrackListObject::checkNewItem() //checks for new item in playlist +{ + if(m_model->count() > m_prev_count) + { + disconnectPl(); //disconnect playlist; + m_model->setCurrent(m_prev_count); // activate first added item + m_player->play(); // ... and play it + } +} + +void TrackListObject::updateTrackList() +{ + emit TrackListChange(m_model->count()); +} + +void TrackListObject::switchPlayList(PlayListModel *cur, PlayListModel *prev) +{ + disconnectPl(); + m_model = cur; + connect (m_model, SIGNAL(listChanged()), SLOT(updateTrackList())); + if(prev) + disconnect(prev,0,this,0); + updateTrackList(); +} diff --git a/src/plugins/General/mpris/mpris1/tracklistobject.h b/src/plugins/General/mpris/mpris1/tracklistobject.h new file mode 100644 index 000000000..eec9eda3c --- /dev/null +++ b/src/plugins/General/mpris/mpris1/tracklistobject.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2008-2009 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 TRACKLISTOBJECT_H +#define TRACKLISTOBJECT_H + +#include <QObject> +#include <QString> +#include <QVariantMap> + +class PlayListModel; +class PlayListManager; +class MediaPlayer; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class TrackListObject : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.MediaPlayer") + +public: + TrackListObject(QObject *parent = 0); + + ~TrackListObject(); + +public slots: + int AddTrack(const QString &in0, bool in1); + void DelTrack(int in0); + int GetCurrentTrack(); + int GetLength(); + QVariantMap GetMetadata(int in0); + void SetLoop(bool in0); + void SetRandom(bool in0); + +signals: + void TrackListChange(int in0); + +private slots: + void disconnectPl(); + void checkNewItem(); + void updateTrackList(); + void switchPlayList(PlayListModel *cur, PlayListModel *prev); + +private: + PlayListModel *m_model; + PlayListManager *m_pl_manager; + MediaPlayer *m_player; + int m_prev_count; + +}; + +#endif |
