-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The 2 year constipation. (mpris plugin)
Probably buggy as hell.
- Loading branch information
1 parent
382d85b
commit 60989e5
Showing
19 changed files
with
1,050 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
set(qmpmpris_SOURCES | ||
qmpmpris.hpp | ||
qmprisdbusinterface.hpp | ||
qmpriswrapper.hpp | ||
qmpmprisimpl.hpp | ||
qmpmpris.cpp | ||
qmprisdbusinterface.cpp | ||
qmpriswrapper.cpp | ||
qmpmprisimpl.cpp | ||
) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
set(CMAKE_AUTOUIC ON) | ||
|
||
find_package(Qt5 REQUIRED COMPONENTS DBus) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}/include/) | ||
|
||
add_library(qmpmpris MODULE | ||
${qmpmpris_SOURCES} | ||
) | ||
|
||
target_link_libraries(qmpmpris | ||
Qt5::Core | ||
Qt5::Widgets | ||
Qt5::DBus | ||
) | ||
|
||
install(TARGETS qmpmpris LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/qmidiplayer/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <cstdio> | ||
#include "qmpmpris.hpp" | ||
#include "qmpriswrapper.hpp" | ||
#include "qmpmprisimpl.hpp" | ||
|
||
qmpMPrisPlugin::qmpMPrisPlugin(qmpPluginAPI *_api) | ||
{ | ||
api = _api; | ||
} | ||
qmpMPrisPlugin::~qmpMPrisPlugin() | ||
{ | ||
api = nullptr; | ||
} | ||
void qmpMPrisPlugin::init() | ||
{ | ||
mw = QMPrisWrapper::create<QMPPlayer, QMPMediaPlayer2, QMPTrackList>("qmidiplayer", api); | ||
} | ||
void qmpMPrisPlugin::deinit() | ||
{ | ||
delete mw; | ||
} | ||
const char *qmpMPrisPlugin::pluginGetName() | ||
{ | ||
return "QMidiPlayer MPris Support"; | ||
} | ||
const char *qmpMPrisPlugin::pluginGetVersion() | ||
{ | ||
return "0.8.8"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef QMPMPRIS_HPP | ||
#define QMPMPRIS_HPP | ||
|
||
#include "../include/qmpcorepublic.hpp" | ||
|
||
class QMPrisWrapper; | ||
class qmpMPrisPlugin: public qmpPluginIntf | ||
{ | ||
private: | ||
qmpPluginAPI *api; | ||
QMPrisWrapper *mw = nullptr; | ||
public: | ||
qmpMPrisPlugin(qmpPluginAPI *_api); | ||
~qmpMPrisPlugin(); | ||
void init(); | ||
void deinit(); | ||
const char *pluginGetName(); | ||
const char *pluginGetVersion(); | ||
}; | ||
|
||
extern "C" { | ||
EXPORTSYM qmpPluginIntf *qmpPluginGetInterface(qmpPluginAPI *api) | ||
{ | ||
return new qmpMPrisPlugin(api); | ||
} | ||
EXPORTSYM const char *qmpPluginGetAPIRev() | ||
{ | ||
return QMP_PLUGIN_API_REV; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
#include <QMetaEnum> | ||
|
||
#include "../include/qmpcorepublic.hpp" | ||
#include "../qmidiplayer-desktop/qmpmainwindow.hpp" | ||
#include "qmpmprisimpl.hpp" | ||
|
||
inline QVariantMap get_metadata(qmpPluginAPI *api) | ||
{ | ||
::PlaybackStatus ps = api->getPlaybackStatus(); | ||
return { | ||
{"mpris:trackid", QDBusObjectPath("/org/chrisoft/qmidiplayer/dummylist/0")}, | ||
{"xesam:url", QString::fromStdWString(api->getWFilePath())}, | ||
{"xesam:title", QString::fromStdWString(api->getWTitle())}, | ||
{"mpris:length", qlonglong(ps.maxtime_ms * 1000)} | ||
}; | ||
} | ||
|
||
QMPPlayer::QMPPlayer(qmpPluginAPI *_api, QObject *parent) : | ||
api(_api), | ||
QMPrisPlayer(parent) | ||
{ | ||
qmw = static_cast<qmpMainWindow*>(api->getMainWindow()); | ||
} | ||
|
||
QString QMPPlayer::getPlaybackStatus() | ||
{ | ||
::PlaybackStatus ps = api->getPlaybackStatus(); | ||
QMPrisPlayer::PlaybackStatus r = QMPrisPlayer::PlaybackStatus::Stopped; | ||
if (!ps.stopped) | ||
r = ps.paused ? QMPrisPlayer::PlaybackStatus::Paused : QMPrisPlayer::PlaybackStatus::Playing; | ||
return QMetaEnum::fromType<QMPrisPlayer::PlaybackStatus>().key(r); | ||
} | ||
|
||
QString QMPPlayer::getLoopStatus() | ||
{ | ||
return QMetaEnum::fromType<QMPrisPlayer::LoopStatus>().key(QMPrisPlayer::LoopStatus::None); | ||
} | ||
|
||
double QMPPlayer::getRate() | ||
{ | ||
return 1; | ||
} | ||
|
||
bool QMPPlayer::getShuffle() | ||
{ | ||
return false; | ||
} | ||
|
||
QVariantMap QMPPlayer::getMetadata() | ||
{ | ||
::PlaybackStatus ps = api->getPlaybackStatus(); | ||
if (ps.stopped) return {}; | ||
return get_metadata(api); | ||
} | ||
|
||
qlonglong QMPPlayer::getPosition() | ||
{ | ||
::PlaybackStatus ps = api->getPlaybackStatus(); | ||
fprintf(stderr, "%lu\n", ps.curtime_ms); | ||
return ps.curtime_ms * 1000; | ||
} | ||
|
||
bool QMPPlayer::getCanGoNext() | ||
{ | ||
return getCanPlay(); | ||
} | ||
|
||
bool QMPPlayer::getCanGoPrevious() | ||
{ | ||
return getCanPlay(); | ||
} | ||
|
||
bool QMPPlayer::getCanPlay() | ||
{ | ||
::PlaybackStatus ps = api->getPlaybackStatus(); | ||
return !ps.stopped; | ||
} | ||
|
||
bool QMPPlayer::getCanPause() | ||
{ | ||
::PlaybackStatus ps = api->getPlaybackStatus(); | ||
return !ps.stopped && !ps.paused; | ||
} | ||
|
||
bool QMPPlayer::getCanSeek() | ||
{ | ||
return getCanPlay(); | ||
} | ||
|
||
bool QMPPlayer::getCanControl() | ||
{ | ||
return true; | ||
} | ||
|
||
void QMPPlayer::Pause() | ||
{ | ||
api->playbackControl(PlaybackControlCommand::Pause, nullptr); | ||
} | ||
|
||
void QMPPlayer::PlayPause() | ||
{ | ||
api->playbackControl(PlaybackControlCommand::TogglePause, nullptr); | ||
} | ||
|
||
void QMPPlayer::Stop() | ||
{ | ||
api->playbackControl(PlaybackControlCommand::Stop, nullptr); | ||
} | ||
|
||
void QMPPlayer::Play() | ||
{ | ||
api->playbackControl(PlaybackControlCommand::Play, nullptr); | ||
} | ||
|
||
void QMPPlayer::Next() | ||
{ | ||
api->playbackControl(PlaybackControlCommand::NextTrack, nullptr); | ||
} | ||
|
||
void QMPPlayer::Previous() | ||
{ | ||
api->playbackControl(PlaybackControlCommand::PrevTrack, nullptr); | ||
} | ||
|
||
void QMPPlayer::Seek(qlonglong t) | ||
{ | ||
double td = t / 1e6; | ||
api->playbackControl(PlaybackControlCommand::SeekAbs, &td); | ||
} | ||
|
||
void QMPPlayer::SetPosition(QDBusObjectPath o, qlonglong t) | ||
{ | ||
if (o.path() == QString("/org/chrisoft/qmidiplayer/dummylist/0")) | ||
{ | ||
double td = t / 1e6; | ||
api->playbackControl(PlaybackControlCommand::SeekAbs, &td); | ||
} | ||
} | ||
|
||
QMPMediaPlayer2::QMPMediaPlayer2(qmpPluginAPI *_api, QObject *parent) : | ||
api(_api), | ||
QMPrisMediaPlayer2(parent) | ||
{ | ||
qmw = static_cast<qmpMainWindow*>(api->getMainWindow()); | ||
} | ||
|
||
void QMPMediaPlayer2::Raise() | ||
{ | ||
qmw->raise(); | ||
} | ||
|
||
void QMPMediaPlayer2::Quit() | ||
{ | ||
qmw->close(); | ||
} | ||
|
||
bool QMPMediaPlayer2::getCanQuit() | ||
{ | ||
return true; | ||
} | ||
|
||
bool QMPMediaPlayer2::getCanRaise() | ||
{ | ||
return true; | ||
} | ||
|
||
QString QMPMediaPlayer2::getIdentity() | ||
{ | ||
return QString("QMidiPlayer"); | ||
} | ||
|
||
QString QMPMediaPlayer2::getDesktopEntry() | ||
{ | ||
return QString("qmidiplayer"); | ||
} | ||
|
||
bool QMPMediaPlayer2::getHasTrackList() | ||
{ | ||
return true; | ||
} | ||
|
||
QMPTrackList::QMPTrackList(qmpPluginAPI *_api, QObject *parent) : | ||
api(_api), | ||
QMPrisTrackList(parent) | ||
{ | ||
} | ||
|
||
QList<QVariantMap> QMPTrackList::GetTracksMetaData(QList<QDBusObjectPath> trackIds) | ||
{ | ||
QList<QVariantMap> ret; | ||
for (auto &i : trackIds) | ||
{ | ||
if (i.path() == QString("/org/chrisoft/qmidiplayer/dummylist/0")) | ||
ret.push_back(get_metadata(api)); | ||
else ret.push_back({}); | ||
} | ||
return ret; | ||
} | ||
|
||
QList<QDBusObjectPath> QMPTrackList::getTracks() | ||
{ | ||
::PlaybackStatus ps = api->getPlaybackStatus(); | ||
if (ps.stopped) | ||
return {}; | ||
return {QDBusObjectPath("/org/chrisoft/qmidiplayer/dummylist/0")}; | ||
} |
Oops, something went wrong.