Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/plugins/mprisplugin/mprisadapter.cpp b/plugins/mprisplugin/mprisadapter.cpp
- index 771d4be..759f76e 100644
- --- a/plugins/mprisplugin/mprisadapter.cpp
- +++ b/plugins/mprisplugin/mprisadapter.cpp
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2013-2019 Khryukin Evgeny, Vitaly Tonkacheyev
- + * Copyright (C) 2013-2022 Khryukin Evgeny, Vitaly Tonkacheyev
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- @@ -18,13 +18,13 @@
- */
- #include "mprisadapter.h"
- -#include "tune.h"
- #include "mpriscontroller.h"
- +#include "tune.h"
- +#include <QStringList>
- #include <QtDBus/QDBusConnection>
- #include <QtDBus/QDBusMessage>
- #include <QtDBus/QDBusObjectPath>
- -#include <QStringList>
- #ifdef DEBUG_OUTPUT
- #include <QDebug>
- #endif
- @@ -33,18 +33,15 @@
- #endif
- MprisAdapter::MprisAdapter(MprisController *p) :
- - QDBusAbstractAdaptor(p),
- - controller_(p),
- - playerStatus_("Stopped"),
- - statusChanged_(false),
- - metadataChanged_(false)
- + QDBusAbstractAdaptor(p), controller_(p), playerStatus_("Stopped"), statusChanged_(false), metadataChanged_(false),
- + shuffle_(false), loopAll_(QStringLiteral("None"))
- {
- }
- void MprisAdapter::setStatus(const QString &status)
- {
- if (!status.isEmpty() && (status != playerStatus_)) {
- - playerStatus_ = status;
- + playerStatus_ = status;
- statusChanged_ = true;
- }
- else {
- @@ -65,124 +62,123 @@ void MprisAdapter::setMetadata(const QompMetaData &tune)
- metaDataMap_["xesam:album"] = tune.album;
- }
- if (!tune.artist.isEmpty()) {
- - metaDataMap_["xesam:artist"] = QStringList({tune.artist});
- + metaDataMap_["xesam:artist"] = QStringList({ tune.artist });
- }
- - metaDataMap_["xesam:url"] = tune.url;
- + metaDataMap_["xesam:url"] = tune.url;
- metaDataMap_["xesam:trackNumber"] = tune.trackNumber;
- - metaDataMap_["mpris:length"] = tune.trackLength;
- + metaDataMap_["mpris:length"] = tune.trackLength;
- + quint32 argument = 0;
- #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
- - trackId_ = QDBusObjectPath(QString("/org/qomp/MediaPlayer2/Track/%1").arg(qrand()));
- + argument = qrand();
- #else
- - trackId_ = QDBusObjectPath(QString("/org/qomp/MediaPlayer2/Track/%1").arg(QRandomGenerator::global()->generate()));
- + argument = QRandomGenerator::global()->generate();
- #endif
- + trackId_ = QDBusObjectPath(QString("/org/qomp/MediaPlayer2/Track/%1").arg(argument));
- metaDataMap_["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>(trackId_);
- - if(!tune.cover.isEmpty()) {
- + if (!tune.cover.isEmpty())
- metaDataMap_["mpris:artUrl"] = tune.cover.startsWith("http") ? tune.cover : "file://" + tune.cover;
- - }
- metadataChanged_ = true;
- }
- -QVariantMap MprisAdapter::metadata() const
- -{
- - return metaDataMap_;
- -}
- +QVariantMap MprisAdapter::metadata() const { return metaDataMap_; }
- -QString MprisAdapter::playbackStatus() const
- -{
- - return playerStatus_;
- -}
- +QString MprisAdapter::playbackStatus() const { return playerStatus_; }
- void MprisAdapter::updateProperties()
- {
- - QVariantMap map({{"CanGoNext", canGoNext()},
- - {"CanGoPrevious", canGoPrevious()},
- - {"CanPlay", canPlay()},
- - {"CanPause", canPause()},
- - {"CanSeek", canSeek()},
- - {"Volume", getVolume()}});
- - if (!playerStatus_.isEmpty() && statusChanged_) {
- + QVariantMap map({ { "CanGoNext", canGoNext() },
- + { "CanGoPrevious", canGoPrevious() },
- + { "CanPlay", canPlay() },
- + { "CanPause", canPause() },
- + { "CanSeek", canSeek() },
- + { "Volume", getVolume() },
- + { "Shuffle", shuffle() },
- + { "LoopStatus", loopAll() } });
- + if (!playerStatus_.isEmpty() && statusChanged_)
- map.insert("PlaybackStatus", playbackStatus());
- - }
- +
- if (!metadata().isEmpty() && metadataChanged_) {
- map.insert("Metadata", metadata());
- metadataChanged_ = false;
- }
- - QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2",
- - "org.freedesktop.DBus.Properties",
- + QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties",
- "PropertiesChanged");
- msg << "org.mpris.MediaPlayer2.Player" << map << QStringList();
- QDBusConnection::sessionBus().send(msg);
- }
- -
- void MprisAdapter::Play()
- {
- - if(canPlay()) {
- + if (canPlay())
- controller_->emitSignal(PLAY);
- - }
- }
- void MprisAdapter::Pause()
- {
- - if(canPause()) {
- + if (canPause())
- controller_->emitSignal(PAUSE);
- - }
- }
- void MprisAdapter::Next()
- {
- - if(canGoNext()) {
- + if (canGoNext())
- controller_->emitSignal(NEXT);
- - }
- }
- void MprisAdapter::Previous()
- {
- - if(canGoPrevious()) {
- + if (canGoPrevious())
- controller_->emitSignal(PREVIOUS);
- - }
- }
- void MprisAdapter::PlayPause()
- {
- - if(canPlay() && canPause()) {
- - if(playerStatus_ == "Playing") {
- + if (canPlay() && canPause()) {
- + if (playerStatus_ == "Playing")
- controller_->emitSignal(PAUSE);
- - }
- - else {
- + else
- controller_->emitSignal(PLAY);
- - }
- }
- }
- void MprisAdapter::Stop()
- {
- - if(canControl()) {
- + if (canControl())
- controller_->emitSignal(STOP);
- - }
- }
- void MprisAdapter::setVolume(const qreal &volume)
- {
- - if( volume >= 0.0 ) {
- + if (volume >= 0.0)
- controller_->emitSignal(VOLUME, volume);
- - }
- }
- void MprisAdapter::SetPosition(const QDBusObjectPath &TrackId, qlonglong Position)
- {
- - if (trackId_ == TrackId && Position > 0.0) {
- + if (trackId_ == TrackId && Position > 0.0)
- controller_->emitSignal(POSITION, Position);
- - }
- }
- -qreal MprisAdapter::getVolume()
- +void MprisAdapter::setLoopAndShuffle(bool loop, bool shuffle)
- +{
- + shuffle_ = shuffle;
- + loopAll_ = (loop) ? QStringLiteral("Playlist") : QStringLiteral("None");
- + updateProperties();
- +}
- +
- +void MprisAdapter::sendShuffle(bool shuffle)
- {
- - return controller_->getVolume();
- + shuffle_ = shuffle;
- + controller_->emitSignal(SHUFFLE);
- }
- -qreal MprisAdapter::getPosition()
- +void MprisAdapter::sendLoopStatus(const QString &status)
- {
- - return controller_->getPosition();
- + loopAll_ = status;
- + controller_->emitSignal(LOOPALL);
- }
- +
- +qreal MprisAdapter::getVolume() { return controller_->getVolume(); }
- +
- +qreal MprisAdapter::getPosition() { return controller_->getPosition(); }
- diff --git a/plugins/mprisplugin/mprisadapter.h b/plugins/mprisplugin/mprisadapter.h
- index d1a6ad4..174c835 100644
- --- a/plugins/mprisplugin/mprisadapter.h
- +++ b/plugins/mprisplugin/mprisadapter.h
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2013 Khryukin Evgeny, Vitaly Tonkacheyev
- + * Copyright (C) 2013-2022 Khryukin Evgeny, Vitaly Tonkacheyev
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- @@ -50,6 +50,8 @@ class MprisAdapter : public QDBusAbstractAdaptor
- Q_PROPERTY(bool CanControl READ canControl)
- Q_PROPERTY(qreal Volume READ getVolume WRITE setVolume)
- Q_PROPERTY(qlonglong Position READ getPosition)
- + Q_PROPERTY(bool Shuffle READ shuffle WRITE sendShuffle)
- + Q_PROPERTY(QString LoopStatus READ loopAll WRITE sendLoopStatus)
- public:
- explicit MprisAdapter(MprisController *p);
- @@ -67,6 +69,7 @@ public:
- void setStatus(const QString &status);
- void setMetadata(const QompMetaData &tune);
- void updateProperties();
- + void setLoopAndShuffle(bool loop, bool shuffle);
- private:
- QVariantMap metadata() const;
- @@ -80,6 +83,10 @@ private:
- void setVolume(const qreal &volume);
- qreal getVolume();
- qreal getPosition();
- + bool shuffle() const {return shuffle_;};
- + QString loopAll() const {return loopAll_;};
- + void sendShuffle(bool shuffle);
- + void sendLoopStatus(const QString &status);
- private:
- MprisController *controller_;
- @@ -88,6 +95,8 @@ private:
- bool statusChanged_;
- bool metadataChanged_;
- QDBusObjectPath trackId_;
- + bool shuffle_;
- + QString loopAll_;
- };
- #endif // MPRISADAPTER_H
- diff --git a/plugins/mprisplugin/mpriscontroller.cpp b/plugins/mprisplugin/mpriscontroller.cpp
- index 2986e7e..7e33ada 100644
- --- a/plugins/mprisplugin/mpriscontroller.cpp
- +++ b/plugins/mprisplugin/mpriscontroller.cpp
- @@ -22,12 +22,9 @@
- #include <QtDBus/QDBusConnection>
- -MprisController::MprisController(QObject *parent)
- -: QObject(parent),
- - rootAdapter_(new RootAdapter(this)),
- - mprisAdapter_(new MprisAdapter(this)),
- - volume_(0.0),
- - position_(0.0)
- +MprisController::MprisController(QObject *parent) :
- + QObject(parent), rootAdapter_(new RootAdapter(this)), mprisAdapter_(new MprisAdapter(this)), volume_(0.0),
- + position_(0.0)
- {
- QDBusConnection qompConnection = QDBusConnection::sessionBus();
- qompConnection.registerObject("/org/mpris/MediaPlayer2", this);
- @@ -35,10 +32,7 @@ MprisController::MprisController(QObject *parent)
- rootAdapter_->setData();
- }
- -MprisController::~MprisController()
- -{
- - QDBusConnection::sessionBus().unregisterService("org.mpris.MediaPlayer2.qomp");
- -}
- +MprisController::~MprisController() { QDBusConnection::sessionBus().unregisterService("org.mpris.MediaPlayer2.qomp"); }
- void MprisController::sendData(const QString &status, const QompMetaData &tune)
- {
- @@ -50,7 +44,7 @@ void MprisController::sendData(const QString &status, const QompMetaData &tune)
- void MprisController::emitSignal(SignalType type, const qreal &userValue)
- {
- - switch(type) {
- + switch (type) {
- case PLAY:
- emit play();
- break;
- @@ -76,7 +70,13 @@ void MprisController::emitSignal(SignalType type, const qreal &userValue)
- emit volumeChanged(userValue);
- break;
- case POSITION:
- - emit positionChanged(userValue/1000.0);
- + emit positionChanged(userValue / 1000.0);
- + break;
- + case SHUFFLE:
- + emit shuffleUpdated();
- + break;
- + case LOOPALL:
- + emit loopStatusUpdated();
- break;
- }
- }
- @@ -93,12 +93,6 @@ qreal MprisController::getPosition()
- return position_;
- }
- -void MprisController::setVolume(const qreal &volume)
- -{
- - volume_ = volume;
- -}
- +void MprisController::setVolume(const qreal &volume) { volume_ = volume; }
- -void MprisController::setPosition(const qreal &pos)
- -{
- - position_ = pos;
- -}
- +void MprisController::setPosition(const qreal &pos) { position_ = pos; }
- diff --git a/plugins/mprisplugin/mpriscontroller.h b/plugins/mprisplugin/mpriscontroller.h
- index 2be0430..c544ff5 100644
- --- a/plugins/mprisplugin/mpriscontroller.h
- +++ b/plugins/mprisplugin/mpriscontroller.h
- @@ -34,7 +34,9 @@ enum SignalType {
- VOLUME = 5,
- QUIT = 6,
- RAISE = 7,
- - POSITION = 8
- + POSITION = 8,
- + SHUFFLE = 9,
- + LOOPALL = 10
- };
- class MprisController : public QObject
- @@ -50,6 +52,7 @@ public:
- qreal getPosition();
- void setVolume(const qreal &volume);
- void setPosition(const qreal &pos);
- + void setLoopAndShuffle(bool loop, bool shuffle) { mprisAdapter_->setLoopAndShuffle(loop, shuffle); };
- signals:
- void play();
- @@ -63,6 +66,8 @@ signals:
- void updateVolume();
- void updatePosition();
- void positionChanged(const qreal &position);
- + void shuffleUpdated();
- + void loopStatusUpdated();
- private:
- RootAdapter *rootAdapter_;
- diff --git a/plugins/mprisplugin/mprisplugin.cpp b/plugins/mprisplugin/mprisplugin.cpp
- index 9fe8952..54724b5 100644
- --- a/plugins/mprisplugin/mprisplugin.cpp
- +++ b/plugins/mprisplugin/mprisplugin.cpp
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2013 Khryukin Evgeny
- + * Copyright (C) 2013-2022 Khryukin Evgeny
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- @@ -18,17 +18,19 @@
- */
- #include "mprisplugin.h"
- +#include "common.h"
- +#include "defines.h"
- +#include "options.h"
- #include "qompplayer.h"
- #include "tune.h"
- -#include "common.h"
- -#include <QTimer>
- -#include <QtPlugin>
- #include <QApplication>
- #include <QMainWindow>
- -#include <QToolButton>
- #include <QStandardPaths>
- #include <QTemporaryFile>
- +#include <QTimer>
- +#include <QToolButton>
- +#include <QtPlugin>
- #ifdef DEBUG_OUTPUT
- #include <QDebug>
- #endif
- @@ -41,49 +43,47 @@
- #define PLAYING "Playing"
- #define nextButtonName "tb_next"
- #define prevButtonName "tb_prev"
- +#define shuffleButtonName "tb_shuffle"
- +#define loopAllButtonName "tb_repeatAll"
- -static const QSize maxArtSize(510,510);
- +static const QSize maxArtSize(510, 510);
- MprisPlugin::MprisPlugin() :
- - player_(nullptr),
- - enabled_(true),
- - mpris_(nullptr),
- - tune_(nullptr),
- - lastTune_(nullptr),
- - artFile_(nullptr)
- + player_(nullptr), enabled_(true), mpris_(nullptr), tune_(nullptr), lastTune_(nullptr), artFile_(nullptr)
- {
- }
- void MprisPlugin::qompPlayerChanged(QompPlayer *player)
- {
- - if(player_ != player) {
- - if(player_) {
- + if (player_ != player) {
- + if (player_) {
- disconnect(player_, &QompPlayer::stateChanged, this, &MprisPlugin::playerStatusChanged);
- disconnect(player_, &QompPlayer::tuneDataUpdated, this, &MprisPlugin::tuneUpdated);
- }
- player_ = player;
- - if(player_) {
- + if (player_) {
- connect(player_, &QompPlayer::stateChanged, this, &MprisPlugin::playerStatusChanged);
- - //needed to update albumArt for online files
- + // needed to update albumArt for online files
- connect(player_, &QompPlayer::tuneDataUpdated, this, &MprisPlugin::tuneUpdated);
- }
- }
- }
- -void MprisPlugin::playerControlChanged(QompPlayerControl *control)
- -{
- - Q_UNUSED(control)
- -}
- +void MprisPlugin::playerControlChanged(QompPlayerControl *control) { Q_UNUSED(control) }
- void MprisPlugin::setEnabled(bool enabled)
- {
- enabled_ = enabled;
- - if(enabled_) {
- - mpris_ = new MprisController(this);
- - tune_ = new QompMetaData();
- + if (enabled_) {
- + mpris_ = new MprisController(this);
- + tune_ = new QompMetaData();
- artFile_ = new QTemporaryFile(this);
- artFile_->setAutoRemove(true);
- + auto options = Options::instance();
- + bool shuffle = options->getOption(OPTION_SHUFFLE).toBool();
- + bool loopAll = options->getOption(OPTION_REPEAT_ALL).toBool();
- + mpris_->setLoopAndShuffle(loopAll, shuffle);
- connect(mpris_, &MprisController::play, this, &MprisPlugin::play);
- connect(mpris_, &MprisController::pause, this, &MprisPlugin::pause);
- connect(mpris_, &MprisController::stop, this, &MprisPlugin::stop);
- @@ -95,6 +95,9 @@ void MprisPlugin::setEnabled(bool enabled)
- connect(mpris_, &MprisController::updateVolume, this, &MprisPlugin::updateVolume);
- connect(mpris_, &MprisController::updatePosition, this, &MprisPlugin::updatePosition);
- connect(mpris_, &MprisController::positionChanged, this, &MprisPlugin::setPosition);
- + connect(options, &Options::updateOptions, this, &MprisPlugin::optionsUpdated);
- + connect(mpris_, &MprisController::shuffleUpdated, this, &MprisPlugin::updateShuffle);
- + connect(mpris_, &MprisController::loopStatusUpdated, this, &MprisPlugin::updateLoopAll);
- }
- else {
- disconnect(mpris_);
- @@ -106,159 +109,144 @@ void MprisPlugin::setEnabled(bool enabled)
- void MprisPlugin::play()
- {
- - if(player_) {
- + if (player_) {
- player_->play();
- }
- }
- void MprisPlugin::pause()
- {
- - if(player_) {
- + if (player_)
- player_->pause();
- - }
- }
- void MprisPlugin::stop()
- {
- - if(player_) {
- + if (player_)
- player_->stop();
- - }
- }
- void MprisPlugin::next()
- {
- - if(player_) {
- + if (player_) {
- QMainWindow *mainWin = Qomp::getMainWindow();
- if (mainWin) {
- QToolButton *nextBtn = mainWin->findChild<QToolButton *>(nextButtonName);
- - if(nextBtn) {
- + if (nextBtn)
- emit nextBtn->clicked();
- - }
- }
- }
- }
- void MprisPlugin::previous()
- {
- - if(player_) {
- + if (player_) {
- QMainWindow *mainWin = Qomp::getMainWindow();
- if (mainWin) {
- QToolButton *prevBtn = mainWin->findChild<QToolButton *>(prevButtonName);
- - if(prevBtn) {
- + if (prevBtn)
- emit prevBtn->clicked();
- - }
- }
- }
- }
- void MprisPlugin::setVolume(const qreal &volume)
- {
- - if(player_) {
- + if (player_) {
- player_->setVolume(volume);
- - emit player_->volumeChanged(volume); //Temporary hack, FIXME
- + emit player_->volumeChanged(volume); // Temporary hack, FIXME
- }
- }
- -void MprisPlugin::doQuit()
- -{
- - qApp->quit();
- -}
- +void MprisPlugin::doQuit() { qApp->quit(); }
- void MprisPlugin::doRaise()
- {
- QMainWindow *mainWin = Qomp::getMainWindow();
- - if(mainWin) {
- - if(mainWin->isHidden()) {
- + if (mainWin)
- + if (mainWin->isHidden())
- mainWin->show();
- - }
- - }
- }
- void MprisPlugin::updateVolume()
- {
- - if(player_) {
- + if (player_)
- mpris_->setVolume(player_->volume());
- - }
- }
- void MprisPlugin::updatePosition()
- {
- - if(player_) {
- - mpris_->setPosition(player_->position()*1000); //microseconds
- - }
- + if (player_)
- + mpris_->setPosition(player_->position() * 1000); // microseconds
- }
- void MprisPlugin::setPosition(const qreal &position)
- {
- - if(player_) {
- - player_->setPosition(position); //miliseconds
- - }
- + if (player_)
- + player_->setPosition(position); // miliseconds
- }
- -void MprisPlugin::unload()
- -{
- - disableMpris();
- -}
- +void MprisPlugin::unload() { disableMpris(); }
- void MprisPlugin::playerStatusChanged(Qomp::State state)
- {
- - if(!enabled_ || !mpris_ || !player_)
- + if (!enabled_ || !mpris_ || !player_)
- return;
- - switch(state) {
- - case Qomp::StatePlaying:
- - getMetaData(player_->currentTune());
- - sendMetadata(PLAYING);
- - break;
- - case Qomp::StateStopped:
- - sendMetadata(STOPPED);
- - break;
- - case Qomp::StatePaused:
- - sendMetadata(PAUSED);
- - break;
- - default:
- - break;
- + switch (state) {
- + case Qomp::StatePlaying:
- + getMetaData(player_->currentTune());
- + sendMetadata(PLAYING);
- + break;
- + case Qomp::StateStopped:
- + sendMetadata(STOPPED);
- + break;
- + case Qomp::StatePaused:
- + sendMetadata(PAUSED);
- + break;
- + default:
- + break;
- }
- }
- void MprisPlugin::getMetaData(Tune *tune)
- {
- if (tune && lastTune_ != tune) {
- - lastTune_ = tune;
- - const int num = tune->trackNumber.isEmpty() ? 0 : tune->trackNumber.toInt();
- - tune_->artist = tune->artist;
- - tune_->title= tune->title;
- - tune_->album = tune->album;
- + lastTune_ = tune;
- + const int num = tune->trackNumber.isEmpty() ? 0 : tune->trackNumber.toInt();
- + tune_->artist = tune->artist;
- + tune_->title = tune->title;
- + tune_->album = tune->album;
- tune_->trackNumber = num;
- - tune_->trackLength = Qomp::durationStringToSeconds(tune->duration)*1e6; //in microseconds
- - if (!tune->file.isEmpty()) {
- + tune_->trackLength = Qomp::durationStringToSeconds(tune->duration) * 1e6; // in microseconds
- + if (!tune->file.isEmpty())
- tune_->url = (tune->file.startsWith("file://")) ? tune->file : "file://" + tune->file;
- - }
- - else {
- + else
- tune_->url = QString();
- - }
- tune_->cover = getAlbumArtFile(tune->cover());
- }
- }
- QString MprisPlugin::getAlbumArtFile(const QImage &art)
- {
- - if(!art.isNull()) {
- - if(artFile_->exists()) {
- + if (!art.isNull()) {
- + if (artFile_->exists())
- artFile_->remove();
- - }
- +
- const QString tmpPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
- - if(!tmpPath.isEmpty()) {
- + if (!tmpPath.isEmpty()) {
- QImage scaledArt = art;
- - if((scaledArt.size().width() > maxArtSize.width())
- - || (scaledArt.size().height() > maxArtSize.height())) {
- + if ((scaledArt.size().width() > maxArtSize.width())
- + || (scaledArt.size().height() > maxArtSize.height()))
- scaledArt = scaledArt.scaled(maxArtSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- - }
- +
- + qint32 index = 0;
- #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
- - artFile_->setFileName(tmpPath + "/qomp_" + QString::number(qrand()) + "_cover.png");
- + index = qrand();
- #else
- - artFile_->setFileName(tmpPath + "/qomp_" + QString::number(QRandomGenerator::global()->generate()) + "_cover.png");
- + index = QRandomGenerator::global()->generate();
- #endif
- + artFile_->setFileName(tmpPath + "/qomp_" + QString::number(index) + "_cover.png");
- if (artFile_->open()) {
- if (!scaledArt.save(artFile_, "PNG")) {
- artFile_->close();
- @@ -274,7 +262,7 @@ QString MprisPlugin::getAlbumArtFile(const QImage &art)
- void MprisPlugin::tuneUpdated(Tune *tune)
- {
- - if(player_->state() == Qomp::StatePlaying) {
- + if (player_->state() == Qomp::StatePlaying) {
- getMetaData(tune);
- sendMetadata(PLAYING);
- }
- @@ -282,11 +270,41 @@ void MprisPlugin::tuneUpdated(Tune *tune)
- void MprisPlugin::sendMetadata(const QString &status)
- {
- - if (status == STOPPED || status == PAUSED) {
- + if (status == STOPPED || status == PAUSED)
- mpris_->sendData(status, QompMetaData());
- - }
- - else if (status == PLAYING){
- + else if (status == PLAYING)
- mpris_->sendData(status, *tune_);
- +}
- +
- +void MprisPlugin::optionsUpdated()
- +{
- + auto options = Options::instance();
- + bool shuffle = options->getOption(OPTION_SHUFFLE).toBool();
- + bool loopAll = options->getOption(OPTION_REPEAT_ALL).toBool();
- + mpris_->setLoopAndShuffle(loopAll, shuffle);
- +}
- +
- +void MprisPlugin::updateShuffle()
- +{
- + if (player_) {
- + QMainWindow *mainWin = Qomp::getMainWindow();
- + if (mainWin) {
- + QToolButton *shuffleBtn = mainWin->findChild<QToolButton *>(shuffleButtonName);
- + if (shuffleBtn)
- + shuffleBtn->click();
- + }
- + }
- +}
- +
- +void MprisPlugin::updateLoopAll()
- +{
- + if (player_) {
- + QMainWindow *mainWin = Qomp::getMainWindow();
- + if (mainWin) {
- + QToolButton *loopBtn = mainWin->findChild<QToolButton *>(loopAllButtonName);
- + if (loopBtn)
- + loopBtn->click();
- + }
- }
- }
- @@ -295,6 +313,6 @@ void MprisPlugin::disableMpris()
- delete mpris_;
- mpris_ = 0;
- delete tune_;
- - tune_ = 0;
- + tune_ = 0;
- lastTune_ = 0;
- }
- diff --git a/plugins/mprisplugin/mprisplugin.h b/plugins/mprisplugin/mprisplugin.h
- index de78312..825a843 100644
- --- a/plugins/mprisplugin/mprisplugin.h
- +++ b/plugins/mprisplugin/mprisplugin.h
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2013 Khryukin Evgeny
- + * Copyright (C) 2013-2022 Khryukin Evgeny
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- @@ -58,6 +58,9 @@ private slots:
- void updatePosition();
- void setPosition(const qreal &position);
- void tuneUpdated(Tune *tune);
- + void optionsUpdated();
- + void updateShuffle();
- + void updateLoopAll();
- private:
- void disableMpris();
- diff --git a/plugins/mprisplugin/rootadapter.cpp b/plugins/mprisplugin/rootadapter.cpp
- index f221839..525557e 100644
- --- a/plugins/mprisplugin/rootadapter.cpp
- +++ b/plugins/mprisplugin/rootadapter.cpp
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2016-2019 Khryukin Evgeny, Vitaly Tonkacheyev
- + * Copyright (C) 2016-2022 Khryukin Evgeny, Vitaly Tonkacheyev
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- @@ -23,23 +23,18 @@
- #include <QDBusConnection>
- #include <QDBusMessage>
- -RootAdapter::RootAdapter(MprisController *p)
- - :QDBusAbstractAdaptor(p),
- - controller_(p)
- -{
- -}
- +RootAdapter::RootAdapter(MprisController *p) : QDBusAbstractAdaptor(p), controller_(p) { }
- void RootAdapter::setData()
- {
- - QVariantMap map({{"SupportedMimeTypes", getMimeTypes()},
- - {"Identity", getIdentity()},
- - {"CanQuit", canQuit()},
- - {"CanRaise", canRaise()},
- - {"CanSetFullscreen", canSetFullscreen()},
- - {"SupportedUriSchemes", QStringList()},
- - {"HasTrackList", hasTrackList()}});
- - QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2",
- - "org.freedesktop.DBus.Properties",
- + QVariantMap map({ { "SupportedMimeTypes", getMimeTypes() },
- + { "Identity", getIdentity() },
- + { "CanQuit", canQuit() },
- + { "CanRaise", canRaise() },
- + { "CanSetFullscreen", canSetFullscreen() },
- + { "SupportedUriSchemes", QStringList() },
- + { "HasTrackList", hasTrackList() } });
- + QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties",
- "PropertiesChanged");
- msg << "org.mpris.MediaPlayer2" << map << QStringList();
- QDBusConnection::sessionBus().send(msg);
- @@ -47,25 +42,19 @@ void RootAdapter::setData()
- void RootAdapter::Quit()
- {
- - if(canQuit()) {
- + if (canQuit())
- controller_->emitSignal(QUIT);
- - }
- }
- void RootAdapter::Raise()
- {
- - if(canRaise()) {
- + if (canRaise())
- controller_->emitSignal(RAISE);
- - }
- }
- QStringList RootAdapter::getMimeTypes() const
- {
- - return QStringList({"audio/aac", "audio/x-flac",
- - "audio/flac", "audio/mp3",
- - "audio/mpeg", "application/ogg",
- - "audio/x-vorbis+ogg", "audio/x-ms-wma",
- - "audio/mp4", "audio/MP4A-LATM",
- - "audio/mpeg4-generic", "audio/m4a",
- - "audio/ac3"});
- + return QStringList({ "audio/aac", "audio/x-flac", "audio/flac", "audio/mp3", "audio/mpeg", "application/ogg",
- + "audio/x-vorbis+ogg", "audio/x-ms-wma", "audio/mp4", "audio/MP4A-LATM",
- + "audio/mpeg4-generic", "audio/m4a", "audio/ac3" });
- }
- diff --git a/plugins/mprisplugin/rootadapter.h b/plugins/mprisplugin/rootadapter.h
- index f995066..fdbf9e4 100644
- --- a/plugins/mprisplugin/rootadapter.h
- +++ b/plugins/mprisplugin/rootadapter.h
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2016 Khryukin Evgeny, Vitaly Tonkacheyev
- + * Copyright (C) 2016-2022 Khryukin Evgeny, Vitaly Tonkacheyev
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- @@ -43,7 +43,7 @@ public:
- private:
- QStringList getMimeTypes() const;
- - QStringList getUriSchemes() const {return QStringList();}
- + QStringList getUriSchemes() const {return QStringList();}
- QString getIdentity() const {return "Qomp";}
- QString getDesktopEntry() const {return "qomp";}
- bool canQuit() const {return true;}
- diff --git a/src/qompmainwin.cpp b/src/qompmainwin.cpp
- index b8fb878..4ae6ef0 100644
- --- a/src/qompmainwin.cpp
- +++ b/src/qompmainwin.cpp
- @@ -508,6 +508,7 @@ void QompMainWin::Private::updateOptions()
- {
- Options::instance()->setOption(OPTION_REPEAT_ALL, ui->tb_repeatAll->isChecked());
- Options::instance()->setOption(OPTION_SHUFFLE, ui->tb_shuffle->isChecked());
- + emit Options::instance()->updateOptions();
- }
- void QompMainWin::Private::removeSelectedIndexes()
Add Comment
Please, Sign In to add comment