Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/.clang-format b/.clang-format
- index 9597d15..8bbf219 100644
- --- a/.clang-format
- +++ b/.clang-format
- @@ -1,6 +1,6 @@
- BasedOnStyle: WebKit
- Language: Cpp
- -BreakConstructorInitializers: BeforeColon
- +BreakConstructorInitializers: AfterColon
- PointerAlignment: Right
- AlignAfterOpenBracket: Align
- AlignConsecutiveAssignments: true
- @@ -8,7 +8,7 @@ AlignConsecutiveDeclarations: true
- AlignTrailingComments: true
- ColumnLimit: 120
- CompactNamespaces: false
- -UseTab: AlignWithSpaces
- +UseTab: Always
- IndentWidth: 8
- TabWidth: 8
- EmptyLineBeforeAccessModifier: LogicalBlock
- diff --git a/libqomp/src/qompplayer.h b/libqomp/src/qompplayer.h
- index 1e15e6a..7de870e 100644
- --- a/libqomp/src/qompplayer.h
- +++ b/libqomp/src/qompplayer.h
- @@ -78,6 +78,9 @@ signals:
- void tuneDataUpdated(Tune*);
- + void shuffleUpdated(bool enabled);
- + void loopAllUpdated(bool enabled);
- +
- protected:
- QompPlayer();
- diff --git a/plugins/mprisplugin/mprisadapter.cpp b/plugins/mprisplugin/mprisadapter.cpp
- index 771d4be..08ffcc3 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,41 +62,39 @@ 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()}});
- + 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());
- }
- @@ -108,46 +103,41 @@ void MprisAdapter::updateProperties()
- 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 {
- @@ -158,31 +148,53 @@ void MprisAdapter::PlayPause()
- 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);
- +}
- +
- +void MprisAdapter::setShuffle(bool shuffle)
- +{
- + if (shuffle_ != shuffle) {
- + shuffle_ = shuffle;
- + updateProperties();
- }
- }
- -qreal MprisAdapter::getVolume()
- +void MprisAdapter::setLoopAll(const QString &loop)
- {
- - return controller_->getVolume();
- + if (loopAll_ != loop) {
- + loopAll_ = loop;
- + updateProperties();
- + }
- }
- -qreal MprisAdapter::getPosition()
- +void MprisAdapter::sendShuffle(bool shuffle)
- {
- - return controller_->getPosition();
- + shuffle_ = shuffle;
- + controller_->emitSignal(SHUFFLE, shuffle);
- }
- +
- +void MprisAdapter::sendLoopStatus(const QString &loop)
- +{
- + if (loop != loopAll_) {
- + bool loopStatus = bool(loop == "Playlist" || loop == "Track");
- + controller_->emitSignal(LOOPALL, loopStatus);
- + }
- +}
- +
- +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..9f6b719 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,8 @@ public:
- void setStatus(const QString &status);
- void setMetadata(const QompMetaData &tune);
- void updateProperties();
- + void setShuffle(bool shuffle);
- + void setLoopAll(const QString &loop);
- private:
- QVariantMap metadata() const;
- @@ -80,6 +84,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 &loop);
- private:
- MprisController *controller_;
- @@ -88,6 +96,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..f432216 100644
- --- a/plugins/mprisplugin/mpriscontroller.cpp
- +++ b/plugins/mprisplugin/mpriscontroller.cpp
- @@ -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
- @@ -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 shuffleChanged();
- + break;
- + case LOOPALL:
- + emit loopAllChanged();
- break;
- }
- }
- @@ -93,12 +93,16 @@ 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::setShuffle(bool shuffle) { mprisAdapter_->setShuffle(shuffle); }
- -void MprisController::setPosition(const qreal &pos)
- +void MprisController::setLoopAll(bool loop)
- {
- - position_ = pos;
- + QString loopName("None");
- + if (loop)
- + loopName = "Playlist";
- + mprisAdapter_->setLoopAll(loopName);
- }
- diff --git a/plugins/mprisplugin/mpriscontroller.h b/plugins/mprisplugin/mpriscontroller.h
- index 2be0430..bc6ccd1 100644
- --- a/plugins/mprisplugin/mpriscontroller.h
- +++ b/plugins/mprisplugin/mpriscontroller.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
- @@ -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,8 @@ public:
- qreal getPosition();
- void setVolume(const qreal &volume);
- void setPosition(const qreal &pos);
- + void setShuffle(bool shuffle);
- + void setLoopAll(bool loop);
- signals:
- void play();
- @@ -63,6 +67,8 @@ signals:
- void updateVolume();
- void updatePosition();
- void positionChanged(const qreal &position);
- + void shuffleChanged();
- + void loopAllChanged();
- private:
- RootAdapter *rootAdapter_;
- diff --git a/plugins/mprisplugin/mprisplugin.cpp b/plugins/mprisplugin/mprisplugin.cpp
- index 9fe8952..e79cd28 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,17 @@
- */
- #include "mprisplugin.h"
- +#include "common.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,47 +41,45 @@
- #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);
- + disconnect(player_, &QompPlayer::shuffleUpdated, this, &MprisPlugin::shuffleUpdated);
- + disconnect(player_, &QompPlayer::loopAllUpdated, this, &MprisPlugin::loopAllUpdated);
- }
- 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);
- + connect(player_, &QompPlayer::shuffleUpdated, this, &MprisPlugin::shuffleUpdated);
- + connect(player_, &QompPlayer::loopAllUpdated, this, &MprisPlugin::loopAllUpdated);
- }
- }
- }
- -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);
- connect(mpris_, &MprisController::play, this, &MprisPlugin::play);
- @@ -95,6 +93,8 @@ 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(mpris_, &MprisController::shuffleChanged, this, &MprisPlugin::updateShuffle);
- + connect(mpris_, &MprisController::loopAllChanged, this, &MprisPlugin::updateLoopAll);
- }
- else {
- disconnect(mpris_);
- @@ -106,32 +106,32 @@ 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();
- }
- }
- @@ -140,11 +140,11 @@ void MprisPlugin::next()
- 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();
- }
- }
- @@ -153,22 +153,19 @@ void MprisPlugin::previous()
- 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();
- }
- }
- @@ -176,61 +173,58 @@ void MprisPlugin::doRaise()
- 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
- + tune_->trackLength = Qomp::durationStringToSeconds(tune->duration) * 1e6; // in microseconds
- if (!tune->file.isEmpty()) {
- tune_->url = (tune->file.startsWith("file://")) ? tune->file : "file://" + tune->file;
- }
- @@ -243,22 +237,24 @@ void MprisPlugin::getMetaData(Tune *tune)
- 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);
- }
- + quint32 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 +270,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);
- }
- @@ -285,16 +281,44 @@ void MprisPlugin::sendMetadata(const QString &status)
- if (status == STOPPED || status == PAUSED) {
- mpris_->sendData(status, QompMetaData());
- }
- - else if (status == PLAYING){
- + else if (status == PLAYING) {
- mpris_->sendData(status, *tune_);
- }
- }
- +void MprisPlugin::shuffleUpdated(bool enabled) { mpris_->setShuffle(enabled); }
- +
- +void MprisPlugin::loopAllUpdated(bool enabled) { mpris_->setLoopAll(enabled); }
- +
- +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();
- + }
- + }
- +}
- +
- 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..7f14bce 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,10 @@ private slots:
- void updatePosition();
- void setPosition(const qreal &position);
- void tuneUpdated(Tune *tune);
- + void shuffleUpdated(bool enabled);
- + void loopAllUpdated(bool enabled);
- + void updateShuffle();
- + void updateLoopAll();
- private:
- void disableMpris();
- diff --git a/plugins/mprisplugin/rootadapter.cpp b/plugins/mprisplugin/rootadapter.cpp
- index f221839..3a43eed 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,21 @@ 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/qompcon.cpp b/src/qompcon.cpp
- index 379c8c9..8cfb62f 100644
- --- a/src/qompcon.cpp
- +++ b/src/qompcon.cpp
- @@ -856,7 +856,6 @@ void QompCon::connectMainWin()
- connect(player_, SIGNAL(mutedChanged(bool)), mainWin_, SLOT(setMuteState(bool)));
- connect(player_, SIGNAL(volumeChanged(qreal)), mainWin_, SLOT(volumeChanged(qreal)));
- connect(player_, SIGNAL(currentTuneTotalTimeChanged(qint64)), mainWin_, SLOT(currentTotalTimeChanged(qint64)));
- -
- connect(mainWin_, SIGNAL(aboutQomp()), SLOT(actAboutQomp()));
- connect(mainWin_, SIGNAL(bugReport()), SLOT(actBugReport()));
- connect(mainWin_, SIGNAL(checkForUpdates()), SLOT(actCheckForUpdates()));
- @@ -877,6 +876,8 @@ void QompCon::connectMainWin()
- connect(mainWin_, SIGNAL(removeTune(Tune*)), SLOT(actRemoveTune(Tune*)));
- connect(mainWin_, SIGNAL(mediaActivated(QModelIndex)), SLOT(actMediaActivated(QModelIndex)));
- connect(mainWin_, SIGNAL(mediaClicked(QModelIndex)), SLOT(actMediaClicked(QModelIndex)));
- + connect(mainWin_, &QompMainWin::shuffleUpdated, player_, &QompPlayer::shuffleUpdated);
- + connect(mainWin_, &QompMainWin::repeatAllUpdated, player_, &QompPlayer::loopAllUpdated);
- #ifndef QOMP_MOBILE
- connect(&watcher_, SIGNAL(commandShow()), mainWin_, SLOT(show()));
- #endif
- diff --git a/src/qompmainwin.cpp b/src/qompmainwin.cpp
- index b8fb878..f3f89d1 100644
- --- a/src/qompmainwin.cpp
- +++ b/src/qompmainwin.cpp
- @@ -134,6 +134,12 @@ QompMainWin::Private::Private(QompMainWin *p) :
- mainWin_->setupFinished();
- connect(ThemeManager::instance(), &ThemeManager::themeChanged, parentWin_, &QompMainWin::updateButtonIcons);
- + connect(ui->tb_repeatAll, &QToolButton::toggled, this, [this](bool enabled){
- + emit parentWin_->repeatAllUpdated(enabled);
- + });
- + connect(ui->tb_shuffle, &QToolButton::toggled, this, [this](bool enabled){
- + emit parentWin_->shuffleUpdated(enabled);
- + });
- ui->tb_repeatAll->setChecked(Options::instance()->getOption(OPTION_REPEAT_ALL).toBool());
- ui->tb_shuffle->setChecked(Options::instance()->getOption(OPTION_SHUFFLE).toBool());
- updateShuffleIcon();
- diff --git a/src/qompmainwin.h b/src/qompmainwin.h
- index b950f10..265bffc 100644
- --- a/src/qompmainwin.h
- +++ b/src/qompmainwin.h
- @@ -79,6 +79,9 @@ signals:
- void mediaActivated(const QModelIndex& index);
- void mediaClicked(const QModelIndex& index);
- + void shuffleUpdated(bool enabled);
- + void repeatAllUpdated(bool enabled);
- +
- protected:
- bool eventFilter(QObject *o, QEvent *e);
Add Comment
Please, Sign In to add comment