KukuRuzo

qomp mpris

Jun 10th, 2022 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 29.55 KB | None | 0 0
  1. diff --git a/.clang-format b/.clang-format
  2. index 9597d15..8bbf219 100644
  3. --- a/.clang-format
  4. +++ b/.clang-format
  5. @@ -1,6 +1,6 @@
  6.  BasedOnStyle: WebKit
  7.  Language: Cpp
  8. -BreakConstructorInitializers: BeforeColon
  9. +BreakConstructorInitializers: AfterColon
  10.  PointerAlignment: Right
  11.  AlignAfterOpenBracket: Align
  12.  AlignConsecutiveAssignments: true
  13. @@ -8,7 +8,7 @@ AlignConsecutiveDeclarations: true
  14.  AlignTrailingComments: true
  15.  ColumnLimit: 120
  16.  CompactNamespaces: false
  17. -UseTab: AlignWithSpaces
  18. +UseTab: Always
  19.  IndentWidth: 8
  20.  TabWidth: 8
  21.  EmptyLineBeforeAccessModifier: LogicalBlock
  22. diff --git a/libqomp/src/qompplayer.h b/libqomp/src/qompplayer.h
  23. index 1e15e6a..7de870e 100644
  24. --- a/libqomp/src/qompplayer.h
  25. +++ b/libqomp/src/qompplayer.h
  26. @@ -78,6 +78,9 @@ signals:
  27.  
  28.     void tuneDataUpdated(Tune*);
  29.  
  30. +   void shuffleUpdated(bool enabled);
  31. +   void loopAllUpdated(bool enabled);
  32. +
  33.  protected:
  34.     QompPlayer();
  35.  
  36. diff --git a/plugins/mprisplugin/mprisadapter.cpp b/plugins/mprisplugin/mprisadapter.cpp
  37. index 771d4be..08ffcc3 100644
  38. --- a/plugins/mprisplugin/mprisadapter.cpp
  39. +++ b/plugins/mprisplugin/mprisadapter.cpp
  40. @@ -1,5 +1,5 @@
  41.  /*
  42. - * Copyright (C) 2013-2019  Khryukin Evgeny, Vitaly Tonkacheyev
  43. + * Copyright (C) 2013-2022  Khryukin Evgeny, Vitaly Tonkacheyev
  44.   *
  45.   * This program is free software; you can redistribute it and/or
  46.   * modify it under the terms of the GNU General Public License
  47. @@ -18,13 +18,13 @@
  48.   */
  49.  
  50.  #include "mprisadapter.h"
  51. -#include "tune.h"
  52.  #include "mpriscontroller.h"
  53. +#include "tune.h"
  54.  
  55. +#include <QStringList>
  56.  #include <QtDBus/QDBusConnection>
  57.  #include <QtDBus/QDBusMessage>
  58.  #include <QtDBus/QDBusObjectPath>
  59. -#include <QStringList>
  60.  #ifdef DEBUG_OUTPUT
  61.  #include <QDebug>
  62.  #endif
  63. @@ -33,18 +33,15 @@
  64.  #endif
  65.  
  66.  MprisAdapter::MprisAdapter(MprisController *p) :
  67. -   QDBusAbstractAdaptor(p),
  68. -   controller_(p),
  69. -   playerStatus_("Stopped"),
  70. -   statusChanged_(false),
  71. -   metadataChanged_(false)
  72. +    QDBusAbstractAdaptor(p), controller_(p), playerStatus_("Stopped"), statusChanged_(false), metadataChanged_(false),
  73. +    shuffle_(false), loopAll_(QStringLiteral("None"))
  74.  {
  75.  }
  76.  
  77.  void MprisAdapter::setStatus(const QString &status)
  78.  {
  79.     if (!status.isEmpty() && (status != playerStatus_)) {
  80. -       playerStatus_ = status;
  81. +       playerStatus_  = status;
  82.         statusChanged_ = true;
  83.     }
  84.     else {
  85. @@ -65,41 +62,39 @@ void MprisAdapter::setMetadata(const QompMetaData &tune)
  86.         metaDataMap_["xesam:album"] = tune.album;
  87.     }
  88.     if (!tune.artist.isEmpty()) {
  89. -       metaDataMap_["xesam:artist"] = QStringList({tune.artist});
  90. +       metaDataMap_["xesam:artist"] = QStringList({ tune.artist });
  91.     }
  92. -   metaDataMap_["xesam:url"] = tune.url;
  93. +   metaDataMap_["xesam:url"]     = tune.url;
  94.     metaDataMap_["xesam:trackNumber"] = tune.trackNumber;
  95. -   metaDataMap_["mpris:length"] = tune.trackLength;
  96. +   metaDataMap_["mpris:length"]      = tune.trackLength;
  97. +   quint32 argument          = 0;
  98.  #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
  99. -   trackId_ = QDBusObjectPath(QString("/org/qomp/MediaPlayer2/Track/%1").arg(qrand()));
  100. +   argument = qrand();
  101.  #else
  102. -   trackId_ = QDBusObjectPath(QString("/org/qomp/MediaPlayer2/Track/%1").arg(QRandomGenerator::global()->generate()));
  103. +   argument = QRandomGenerator::global()->generate();
  104.  #endif
  105. +   trackId_              = QDBusObjectPath(QString("/org/qomp/MediaPlayer2/Track/%1").arg(argument));
  106.     metaDataMap_["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>(trackId_);
  107. -   if(!tune.cover.isEmpty()) {
  108. +   if (!tune.cover.isEmpty()) {
  109.         metaDataMap_["mpris:artUrl"] = tune.cover.startsWith("http") ? tune.cover : "file://" + tune.cover;
  110.     }
  111.     metadataChanged_ = true;
  112.  }
  113.  
  114. -QVariantMap MprisAdapter::metadata() const
  115. -{
  116. -   return metaDataMap_;
  117. -}
  118. +QVariantMap MprisAdapter::metadata() const { return metaDataMap_; }
  119.  
  120. -QString MprisAdapter::playbackStatus() const
  121. -{
  122. -   return playerStatus_;
  123. -}
  124. +QString MprisAdapter::playbackStatus() const { return playerStatus_; }
  125.  
  126.  void MprisAdapter::updateProperties()
  127.  {
  128. -   QVariantMap map({{"CanGoNext", canGoNext()},
  129. -            {"CanGoPrevious", canGoPrevious()},
  130. -            {"CanPlay", canPlay()},
  131. -            {"CanPause", canPause()},
  132. -            {"CanSeek", canSeek()},
  133. -            {"Volume", getVolume()}});
  134. +   QVariantMap map({ { "CanGoNext", canGoNext() },
  135. +             { "CanGoPrevious", canGoPrevious() },
  136. +             { "CanPlay", canPlay() },
  137. +             { "CanPause", canPause() },
  138. +             { "CanSeek", canSeek() },
  139. +             { "Volume", getVolume() },
  140. +             { "Shuffle", shuffle() },
  141. +             { "LoopStatus", loopAll() } });
  142.     if (!playerStatus_.isEmpty() && statusChanged_) {
  143.         map.insert("PlaybackStatus", playbackStatus());
  144.     }
  145. @@ -108,46 +103,41 @@ void MprisAdapter::updateProperties()
  146.         metadataChanged_ = false;
  147.     }
  148.  
  149. -   QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2",
  150. -                             "org.freedesktop.DBus.Properties",
  151. +   QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties",
  152.                               "PropertiesChanged");
  153.     msg << "org.mpris.MediaPlayer2.Player" << map << QStringList();
  154.     QDBusConnection::sessionBus().send(msg);
  155.  }
  156.  
  157. -
  158.  void MprisAdapter::Play()
  159.  {
  160. -   if(canPlay()) {
  161. +   if (canPlay())
  162.         controller_->emitSignal(PLAY);
  163. -   }
  164.  }
  165.  
  166.  void MprisAdapter::Pause()
  167.  {
  168. -   if(canPause()) {
  169. +   if (canPause())
  170.         controller_->emitSignal(PAUSE);
  171. -   }
  172.  }
  173.  
  174.  void MprisAdapter::Next()
  175.  {
  176. -   if(canGoNext()) {
  177. +   if (canGoNext()) {
  178.         controller_->emitSignal(NEXT);
  179.     }
  180.  }
  181.  
  182.  void MprisAdapter::Previous()
  183.  {
  184. -   if(canGoPrevious()) {
  185. +   if (canGoPrevious())
  186.         controller_->emitSignal(PREVIOUS);
  187. -   }
  188.  }
  189.  
  190.  void MprisAdapter::PlayPause()
  191.  {
  192. -   if(canPlay() && canPause()) {
  193. -       if(playerStatus_ == "Playing") {
  194. +   if (canPlay() && canPause()) {
  195. +       if (playerStatus_ == "Playing") {
  196.             controller_->emitSignal(PAUSE);
  197.         }
  198.         else {
  199. @@ -158,31 +148,53 @@ void MprisAdapter::PlayPause()
  200.  
  201.  void MprisAdapter::Stop()
  202.  {
  203. -   if(canControl()) {
  204. +   if (canControl()) {
  205.         controller_->emitSignal(STOP);
  206.     }
  207.  }
  208.  
  209.  void MprisAdapter::setVolume(const qreal &volume)
  210.  {
  211. -   if( volume >= 0.0 ) {
  212. +   if (volume >= 0.0)
  213.         controller_->emitSignal(VOLUME, volume);
  214. -   }
  215.  }
  216.  
  217.  void MprisAdapter::SetPosition(const QDBusObjectPath &TrackId, qlonglong Position)
  218.  {
  219. -   if (trackId_ == TrackId && Position > 0.0) {
  220. +   if (trackId_ == TrackId && Position > 0.0)
  221.         controller_->emitSignal(POSITION, Position);
  222. +}
  223. +
  224. +void MprisAdapter::setShuffle(bool shuffle)
  225. +{
  226. +   if (shuffle_ != shuffle) {
  227. +       shuffle_ = shuffle;
  228. +       updateProperties();
  229.     }
  230.  }
  231.  
  232. -qreal MprisAdapter::getVolume()
  233. +void MprisAdapter::setLoopAll(const QString &loop)
  234.  {
  235. -   return controller_->getVolume();
  236. +   if (loopAll_ != loop) {
  237. +       loopAll_ = loop;
  238. +       updateProperties();
  239. +   }
  240.  }
  241.  
  242. -qreal MprisAdapter::getPosition()
  243. +void MprisAdapter::sendShuffle(bool shuffle)
  244.  {
  245. -   return controller_->getPosition();
  246. +   shuffle_ = shuffle;
  247. +   controller_->emitSignal(SHUFFLE, shuffle);
  248.  }
  249. +
  250. +void MprisAdapter::sendLoopStatus(const QString &loop)
  251. +{
  252. +   if (loop != loopAll_) {
  253. +       bool loopStatus = bool(loop == "Playlist" || loop == "Track");
  254. +       controller_->emitSignal(LOOPALL, loopStatus);
  255. +   }
  256. +}
  257. +
  258. +qreal MprisAdapter::getVolume() { return controller_->getVolume(); }
  259. +
  260. +qreal MprisAdapter::getPosition() { return controller_->getPosition(); }
  261. diff --git a/plugins/mprisplugin/mprisadapter.h b/plugins/mprisplugin/mprisadapter.h
  262. index d1a6ad4..9f6b719 100644
  263. --- a/plugins/mprisplugin/mprisadapter.h
  264. +++ b/plugins/mprisplugin/mprisadapter.h
  265. @@ -1,5 +1,5 @@
  266.  /*
  267. - * Copyright (C) 2013  Khryukin Evgeny, Vitaly Tonkacheyev
  268. + * Copyright (C) 2013-2022  Khryukin Evgeny, Vitaly Tonkacheyev
  269.   *
  270.   * This program is free software; you can redistribute it and/or
  271.   * modify it under the terms of the GNU General Public License
  272. @@ -50,6 +50,8 @@ class MprisAdapter : public QDBusAbstractAdaptor
  273.     Q_PROPERTY(bool CanControl READ canControl)
  274.     Q_PROPERTY(qreal Volume READ getVolume WRITE setVolume)
  275.     Q_PROPERTY(qlonglong Position READ getPosition)
  276. +   Q_PROPERTY(bool Shuffle READ shuffle WRITE sendShuffle)
  277. +   Q_PROPERTY(QString LoopStatus READ loopAll WRITE sendLoopStatus)
  278.  
  279.  public:
  280.     explicit MprisAdapter(MprisController *p);
  281. @@ -67,6 +69,8 @@ public:
  282.     void setStatus(const QString &status);
  283.     void setMetadata(const QompMetaData &tune);
  284.     void updateProperties();
  285. +   void setShuffle(bool shuffle);
  286. +   void setLoopAll(const QString &loop);
  287.  
  288.  private:
  289.     QVariantMap metadata() const;
  290. @@ -80,6 +84,10 @@ private:
  291.     void setVolume(const qreal &volume);
  292.     qreal getVolume();
  293.     qreal getPosition();
  294. +   bool shuffle() const { return shuffle_; };
  295. +   QString loopAll() const { return loopAll_; };
  296. +   void sendShuffle(bool shuffle);
  297. +   void sendLoopStatus(const QString &loop);
  298.  
  299.  private:
  300.     MprisController *controller_;
  301. @@ -88,6 +96,8 @@ private:
  302.     bool statusChanged_;
  303.     bool metadataChanged_;
  304.     QDBusObjectPath trackId_;
  305. +   bool shuffle_;
  306. +   QString loopAll_;
  307.  };
  308.  
  309.  #endif // MPRISADAPTER_H
  310. diff --git a/plugins/mprisplugin/mpriscontroller.cpp b/plugins/mprisplugin/mpriscontroller.cpp
  311. index 2986e7e..f432216 100644
  312. --- a/plugins/mprisplugin/mpriscontroller.cpp
  313. +++ b/plugins/mprisplugin/mpriscontroller.cpp
  314. @@ -1,5 +1,5 @@
  315.  /*
  316. - * Copyright (C) 2013  Khryukin Evgeny, Vitaly Tonkacheyev
  317. + * Copyright (C) 2013-2022  Khryukin Evgeny, Vitaly Tonkacheyev
  318.   *
  319.   * This program is free software; you can redistribute it and/or
  320.   * modify it under the terms of the GNU General Public License
  321. @@ -22,12 +22,9 @@
  322.  
  323.  #include <QtDBus/QDBusConnection>
  324.  
  325. -MprisController::MprisController(QObject *parent)
  326. -: QObject(parent),
  327. -  rootAdapter_(new RootAdapter(this)),
  328. -  mprisAdapter_(new MprisAdapter(this)),
  329. -  volume_(0.0),
  330. -  position_(0.0)
  331. +MprisController::MprisController(QObject *parent) :
  332. +    QObject(parent), rootAdapter_(new RootAdapter(this)), mprisAdapter_(new MprisAdapter(this)), volume_(0.0),
  333. +    position_(0.0)
  334.  {
  335.     QDBusConnection qompConnection = QDBusConnection::sessionBus();
  336.     qompConnection.registerObject("/org/mpris/MediaPlayer2", this);
  337. @@ -35,10 +32,7 @@ MprisController::MprisController(QObject *parent)
  338.     rootAdapter_->setData();
  339.  }
  340.  
  341. -MprisController::~MprisController()
  342. -{
  343. -   QDBusConnection::sessionBus().unregisterService("org.mpris.MediaPlayer2.qomp");
  344. -}
  345. +MprisController::~MprisController() { QDBusConnection::sessionBus().unregisterService("org.mpris.MediaPlayer2.qomp"); }
  346.  
  347.  void MprisController::sendData(const QString &status, const QompMetaData &tune)
  348.  {
  349. @@ -50,7 +44,7 @@ void MprisController::sendData(const QString &status, const QompMetaData &tune)
  350.  
  351.  void MprisController::emitSignal(SignalType type, const qreal &userValue)
  352.  {
  353. -   switch(type) {
  354. +   switch (type) {
  355.     case PLAY:
  356.         emit play();
  357.         break;
  358. @@ -76,7 +70,13 @@ void MprisController::emitSignal(SignalType type, const qreal &userValue)
  359.         emit volumeChanged(userValue);
  360.         break;
  361.     case POSITION:
  362. -       emit positionChanged(userValue/1000.0);
  363. +       emit positionChanged(userValue / 1000.0);
  364. +       break;
  365. +   case SHUFFLE:
  366. +       emit shuffleChanged();
  367. +       break;
  368. +   case LOOPALL:
  369. +       emit loopAllChanged();
  370.         break;
  371.     }
  372.  }
  373. @@ -93,12 +93,16 @@ qreal MprisController::getPosition()
  374.     return position_;
  375.  }
  376.  
  377. -void MprisController::setVolume(const qreal &volume)
  378. -{
  379. -   volume_ = volume;
  380. -}
  381. +void MprisController::setVolume(const qreal &volume) { volume_ = volume; }
  382. +
  383. +void MprisController::setPosition(const qreal &pos) { position_ = pos; }
  384. +
  385. +void MprisController::setShuffle(bool shuffle) { mprisAdapter_->setShuffle(shuffle); }
  386.  
  387. -void MprisController::setPosition(const qreal &pos)
  388. +void MprisController::setLoopAll(bool loop)
  389.  {
  390. -   position_ = pos;
  391. +   QString loopName("None");
  392. +   if (loop)
  393. +       loopName = "Playlist";
  394. +   mprisAdapter_->setLoopAll(loopName);
  395.  }
  396. diff --git a/plugins/mprisplugin/mpriscontroller.h b/plugins/mprisplugin/mpriscontroller.h
  397. index 2be0430..bc6ccd1 100644
  398. --- a/plugins/mprisplugin/mpriscontroller.h
  399. +++ b/plugins/mprisplugin/mpriscontroller.h
  400. @@ -1,5 +1,5 @@
  401.  /*
  402. - * Copyright (C) 2013  Khryukin Evgeny, Vitaly Tonkacheyev
  403. + * Copyright (C) 2013-2022  Khryukin Evgeny, Vitaly Tonkacheyev
  404.   *
  405.   * This program is free software; you can redistribute it and/or
  406.   * modify it under the terms of the GNU General Public License
  407. @@ -34,7 +34,9 @@ enum SignalType {
  408.     VOLUME = 5,
  409.     QUIT = 6,
  410.     RAISE = 7,
  411. -   POSITION = 8
  412. +   POSITION = 8,
  413. +   SHUFFLE = 9,
  414. +   LOOPALL = 10
  415.  };
  416.  
  417.  class MprisController : public QObject
  418. @@ -50,6 +52,8 @@ public:
  419.     qreal getPosition();
  420.     void setVolume(const qreal &volume);
  421.     void setPosition(const qreal &pos);
  422. +   void setShuffle(bool shuffle);
  423. +   void setLoopAll(bool loop);
  424.  
  425.  signals:
  426.     void play();
  427. @@ -63,6 +67,8 @@ signals:
  428.     void updateVolume();
  429.     void updatePosition();
  430.     void positionChanged(const qreal &position);
  431. +   void shuffleChanged();
  432. +   void loopAllChanged();
  433.  
  434.  private:
  435.     RootAdapter *rootAdapter_;
  436. diff --git a/plugins/mprisplugin/mprisplugin.cpp b/plugins/mprisplugin/mprisplugin.cpp
  437. index 9fe8952..e79cd28 100644
  438. --- a/plugins/mprisplugin/mprisplugin.cpp
  439. +++ b/plugins/mprisplugin/mprisplugin.cpp
  440. @@ -1,5 +1,5 @@
  441.  /*
  442. - * Copyright (C) 2013  Khryukin Evgeny
  443. + * Copyright (C) 2013-2022  Khryukin Evgeny
  444.   *
  445.   * This program is free software; you can redistribute it and/or
  446.   * modify it under the terms of the GNU General Public License
  447. @@ -18,17 +18,17 @@
  448.   */
  449.  
  450.  #include "mprisplugin.h"
  451. +#include "common.h"
  452.  #include "qompplayer.h"
  453.  #include "tune.h"
  454. -#include "common.h"
  455.  
  456. -#include <QTimer>
  457. -#include <QtPlugin>
  458.  #include <QApplication>
  459.  #include <QMainWindow>
  460. -#include <QToolButton>
  461.  #include <QStandardPaths>
  462.  #include <QTemporaryFile>
  463. +#include <QTimer>
  464. +#include <QToolButton>
  465. +#include <QtPlugin>
  466.  #ifdef DEBUG_OUTPUT
  467.  #include <QDebug>
  468.  #endif
  469. @@ -41,47 +41,45 @@
  470.  #define PLAYING "Playing"
  471.  #define nextButtonName "tb_next"
  472.  #define prevButtonName "tb_prev"
  473. +#define shuffleButtonName "tb_shuffle"
  474. +#define loopAllButtonName "tb_repeatAll"
  475.  
  476. -static const QSize maxArtSize(510,510);
  477. +static const QSize maxArtSize(510, 510);
  478.  
  479.  MprisPlugin::MprisPlugin() :
  480. -   player_(nullptr),
  481. -   enabled_(true),
  482. -   mpris_(nullptr),
  483. -   tune_(nullptr),
  484. -   lastTune_(nullptr),
  485. -   artFile_(nullptr)
  486. +    player_(nullptr), enabled_(true), mpris_(nullptr), tune_(nullptr), lastTune_(nullptr), artFile_(nullptr)
  487.  {
  488.  }
  489.  
  490.  void MprisPlugin::qompPlayerChanged(QompPlayer *player)
  491.  {
  492. -   if(player_ != player) {
  493. -       if(player_) {
  494. +   if (player_ != player) {
  495. +       if (player_) {
  496.             disconnect(player_, &QompPlayer::stateChanged, this, &MprisPlugin::playerStatusChanged);
  497.             disconnect(player_, &QompPlayer::tuneDataUpdated, this, &MprisPlugin::tuneUpdated);
  498. +           disconnect(player_, &QompPlayer::shuffleUpdated, this, &MprisPlugin::shuffleUpdated);
  499. +           disconnect(player_, &QompPlayer::loopAllUpdated, this, &MprisPlugin::loopAllUpdated);
  500.         }
  501.  
  502.         player_ = player;
  503. -       if(player_) {
  504. +       if (player_) {
  505.             connect(player_, &QompPlayer::stateChanged, this, &MprisPlugin::playerStatusChanged);
  506. -           //needed to update albumArt for online files
  507. +           // needed to update albumArt for online files
  508.             connect(player_, &QompPlayer::tuneDataUpdated, this, &MprisPlugin::tuneUpdated);
  509. +           connect(player_, &QompPlayer::shuffleUpdated, this, &MprisPlugin::shuffleUpdated);
  510. +           connect(player_, &QompPlayer::loopAllUpdated, this, &MprisPlugin::loopAllUpdated);
  511.         }
  512.     }
  513.  }
  514.  
  515. -void MprisPlugin::playerControlChanged(QompPlayerControl *control)
  516. -{
  517. -   Q_UNUSED(control)
  518. -}
  519. +void MprisPlugin::playerControlChanged(QompPlayerControl *control) { Q_UNUSED(control) }
  520.  
  521.  void MprisPlugin::setEnabled(bool enabled)
  522.  {
  523.     enabled_ = enabled;
  524. -   if(enabled_) {
  525. -       mpris_ = new MprisController(this);
  526. -       tune_ = new QompMetaData();
  527. +   if (enabled_) {
  528. +       mpris_   = new MprisController(this);
  529. +       tune_    = new QompMetaData();
  530.         artFile_ = new QTemporaryFile(this);
  531.         artFile_->setAutoRemove(true);
  532.         connect(mpris_, &MprisController::play, this, &MprisPlugin::play);
  533. @@ -95,6 +93,8 @@ void MprisPlugin::setEnabled(bool enabled)
  534.         connect(mpris_, &MprisController::updateVolume, this, &MprisPlugin::updateVolume);
  535.         connect(mpris_, &MprisController::updatePosition, this, &MprisPlugin::updatePosition);
  536.         connect(mpris_, &MprisController::positionChanged, this, &MprisPlugin::setPosition);
  537. +       connect(mpris_, &MprisController::shuffleChanged, this, &MprisPlugin::updateShuffle);
  538. +       connect(mpris_, &MprisController::loopAllChanged, this, &MprisPlugin::updateLoopAll);
  539.     }
  540.     else {
  541.         disconnect(mpris_);
  542. @@ -106,32 +106,32 @@ void MprisPlugin::setEnabled(bool enabled)
  543.  
  544.  void MprisPlugin::play()
  545.  {
  546. -   if(player_) {
  547. +   if (player_) {
  548.         player_->play();
  549.     }
  550.  }
  551.  
  552.  void MprisPlugin::pause()
  553.  {
  554. -   if(player_) {
  555. +   if (player_) {
  556.         player_->pause();
  557.     }
  558.  }
  559.  
  560.  void MprisPlugin::stop()
  561.  {
  562. -   if(player_) {
  563. +   if (player_) {
  564.         player_->stop();
  565.     }
  566.  }
  567.  
  568.  void MprisPlugin::next()
  569.  {
  570. -   if(player_) {
  571. +   if (player_) {
  572.         QMainWindow *mainWin = Qomp::getMainWindow();
  573.         if (mainWin) {
  574.             QToolButton *nextBtn = mainWin->findChild<QToolButton *>(nextButtonName);
  575. -           if(nextBtn) {
  576. +           if (nextBtn) {
  577.                 emit nextBtn->clicked();
  578.             }
  579.         }
  580. @@ -140,11 +140,11 @@ void MprisPlugin::next()
  581.  
  582.  void MprisPlugin::previous()
  583.  {
  584. -   if(player_) {
  585. +   if (player_) {
  586.         QMainWindow *mainWin = Qomp::getMainWindow();
  587.         if (mainWin) {
  588.             QToolButton *prevBtn = mainWin->findChild<QToolButton *>(prevButtonName);
  589. -           if(prevBtn) {
  590. +           if (prevBtn) {
  591.                 emit prevBtn->clicked();
  592.             }
  593.         }
  594. @@ -153,22 +153,19 @@ void MprisPlugin::previous()
  595.  
  596.  void MprisPlugin::setVolume(const qreal &volume)
  597.  {
  598. -   if(player_) {
  599. +   if (player_) {
  600.         player_->setVolume(volume);
  601. -       emit player_->volumeChanged(volume); //Temporary hack, FIXME
  602. +       emit player_->volumeChanged(volume); // Temporary hack, FIXME
  603.     }
  604.  }
  605.  
  606. -void MprisPlugin::doQuit()
  607. -{
  608. -   qApp->quit();
  609. -}
  610. +void MprisPlugin::doQuit() { qApp->quit(); }
  611.  
  612.  void MprisPlugin::doRaise()
  613.  {
  614.     QMainWindow *mainWin = Qomp::getMainWindow();
  615. -   if(mainWin) {
  616. -       if(mainWin->isHidden()) {
  617. +   if (mainWin) {
  618. +       if (mainWin->isHidden()) {
  619.             mainWin->show();
  620.         }
  621.     }
  622. @@ -176,61 +173,58 @@ void MprisPlugin::doRaise()
  623.  
  624.  void MprisPlugin::updateVolume()
  625.  {
  626. -   if(player_) {
  627. +   if (player_) {
  628.         mpris_->setVolume(player_->volume());
  629.     }
  630.  }
  631.  
  632.  void MprisPlugin::updatePosition()
  633.  {
  634. -   if(player_) {
  635. -       mpris_->setPosition(player_->position()*1000); //microseconds
  636. +   if (player_) {
  637. +       mpris_->setPosition(player_->position() * 1000); // microseconds
  638.     }
  639.  }
  640.  
  641.  void MprisPlugin::setPosition(const qreal &position)
  642.  {
  643. -   if(player_) {
  644. -       player_->setPosition(position); //miliseconds
  645. +   if (player_) {
  646. +       player_->setPosition(position); // miliseconds
  647.     }
  648.  }
  649.  
  650. -void MprisPlugin::unload()
  651. -{
  652. -   disableMpris();
  653. -}
  654. +void MprisPlugin::unload() { disableMpris(); }
  655.  
  656.  void MprisPlugin::playerStatusChanged(Qomp::State state)
  657.  {
  658. -   if(!enabled_ || !mpris_ || !player_)
  659. +   if (!enabled_ || !mpris_ || !player_)
  660.         return;
  661.  
  662. -   switch(state) {
  663. -       case Qomp::StatePlaying:
  664. -           getMetaData(player_->currentTune());
  665. -           sendMetadata(PLAYING);
  666. -           break;
  667. -       case Qomp::StateStopped:
  668. -           sendMetadata(STOPPED);
  669. -           break;
  670. -       case Qomp::StatePaused:
  671. -           sendMetadata(PAUSED);
  672. -           break;
  673. -       default:
  674. -           break;
  675. +   switch (state) {
  676. +   case Qomp::StatePlaying:
  677. +       getMetaData(player_->currentTune());
  678. +       sendMetadata(PLAYING);
  679. +       break;
  680. +   case Qomp::StateStopped:
  681. +       sendMetadata(STOPPED);
  682. +       break;
  683. +   case Qomp::StatePaused:
  684. +       sendMetadata(PAUSED);
  685. +       break;
  686. +   default:
  687. +       break;
  688.     }
  689.  }
  690.  
  691.  void MprisPlugin::getMetaData(Tune *tune)
  692.  {
  693.     if (tune && lastTune_ != tune) {
  694. -       lastTune_ = tune;
  695. -       const int num = tune->trackNumber.isEmpty() ? 0 : tune->trackNumber.toInt();
  696. -       tune_->artist = tune->artist;
  697. -       tune_->title= tune->title;
  698. -       tune_->album = tune->album;
  699. +       lastTune_      = tune;
  700. +       const int num      = tune->trackNumber.isEmpty() ? 0 : tune->trackNumber.toInt();
  701. +       tune_->artist      = tune->artist;
  702. +       tune_->title       = tune->title;
  703. +       tune_->album       = tune->album;
  704.         tune_->trackNumber = num;
  705. -       tune_->trackLength = Qomp::durationStringToSeconds(tune->duration)*1e6; //in microseconds
  706. +       tune_->trackLength = Qomp::durationStringToSeconds(tune->duration) * 1e6; // in microseconds
  707.         if (!tune->file.isEmpty()) {
  708.             tune_->url = (tune->file.startsWith("file://")) ? tune->file : "file://" + tune->file;
  709.         }
  710. @@ -243,22 +237,24 @@ void MprisPlugin::getMetaData(Tune *tune)
  711.  
  712.  QString MprisPlugin::getAlbumArtFile(const QImage &art)
  713.  {
  714. -   if(!art.isNull()) {
  715. -       if(artFile_->exists()) {
  716. +   if (!art.isNull()) {
  717. +       if (artFile_->exists()) {
  718.             artFile_->remove();
  719.         }
  720.         const QString tmpPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
  721. -       if(!tmpPath.isEmpty()) {
  722. +       if (!tmpPath.isEmpty()) {
  723.             QImage scaledArt = art;
  724. -           if((scaledArt.size().width() > maxArtSize.width())
  725. -              || (scaledArt.size().height() > maxArtSize.height())) {
  726. +           if ((scaledArt.size().width() > maxArtSize.width())
  727. +               || (scaledArt.size().height() > maxArtSize.height())) {
  728.                 scaledArt = scaledArt.scaled(maxArtSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  729.             }
  730. +           quint32 index = 0;
  731.  #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
  732. -           artFile_->setFileName(tmpPath + "/qomp_" + QString::number(qrand()) + "_cover.png");
  733. +           index = qrand();
  734.  #else
  735. -           artFile_->setFileName(tmpPath + "/qomp_" + QString::number(QRandomGenerator::global()->generate()) + "_cover.png");
  736. +           index = QRandomGenerator::global()->generate();
  737.  #endif
  738. +           artFile_->setFileName(tmpPath + "/qomp_" + QString::number(index) + "_cover.png");
  739.             if (artFile_->open()) {
  740.                 if (!scaledArt.save(artFile_, "PNG")) {
  741.                     artFile_->close();
  742. @@ -274,7 +270,7 @@ QString MprisPlugin::getAlbumArtFile(const QImage &art)
  743.  
  744.  void MprisPlugin::tuneUpdated(Tune *tune)
  745.  {
  746. -   if(player_->state() == Qomp::StatePlaying) {
  747. +   if (player_->state() == Qomp::StatePlaying) {
  748.         getMetaData(tune);
  749.         sendMetadata(PLAYING);
  750.     }
  751. @@ -285,16 +281,44 @@ void MprisPlugin::sendMetadata(const QString &status)
  752.     if (status == STOPPED || status == PAUSED) {
  753.         mpris_->sendData(status, QompMetaData());
  754.     }
  755. -   else if (status == PLAYING){
  756. +   else if (status == PLAYING) {
  757.         mpris_->sendData(status, *tune_);
  758.     }
  759.  }
  760.  
  761. +void MprisPlugin::shuffleUpdated(bool enabled) { mpris_->setShuffle(enabled); }
  762. +
  763. +void MprisPlugin::loopAllUpdated(bool enabled) { mpris_->setLoopAll(enabled); }
  764. +
  765. +void MprisPlugin::updateShuffle()
  766. +{
  767. +   if (player_) {
  768. +       QMainWindow *mainWin = Qomp::getMainWindow();
  769. +       if (mainWin) {
  770. +           QToolButton *shuffleBtn = mainWin->findChild<QToolButton *>(shuffleButtonName);
  771. +           if (shuffleBtn)
  772. +               shuffleBtn->click();
  773. +       }
  774. +   }
  775. +}
  776. +
  777. +void MprisPlugin::updateLoopAll()
  778. +{
  779. +   if (player_) {
  780. +       QMainWindow *mainWin = Qomp::getMainWindow();
  781. +       if (mainWin) {
  782. +           QToolButton *loopBtn = mainWin->findChild<QToolButton *>(loopAllButtonName);
  783. +           if (loopBtn)
  784. +               loopBtn->click();
  785. +       }
  786. +   }
  787. +}
  788. +
  789.  void MprisPlugin::disableMpris()
  790.  {
  791.     delete mpris_;
  792.     mpris_ = 0;
  793.     delete tune_;
  794. -   tune_ = 0;
  795. +   tune_     = 0;
  796.     lastTune_ = 0;
  797.  }
  798. diff --git a/plugins/mprisplugin/mprisplugin.h b/plugins/mprisplugin/mprisplugin.h
  799. index de78312..7f14bce 100644
  800. --- a/plugins/mprisplugin/mprisplugin.h
  801. +++ b/plugins/mprisplugin/mprisplugin.h
  802. @@ -1,5 +1,5 @@
  803.  /*
  804. - * Copyright (C) 2013  Khryukin Evgeny
  805. + * Copyright (C) 2013-2022  Khryukin Evgeny
  806.   *
  807.   * This program is free software; you can redistribute it and/or
  808.   * modify it under the terms of the GNU General Public License
  809. @@ -58,6 +58,10 @@ private slots:
  810.     void updatePosition();
  811.     void setPosition(const qreal &position);
  812.     void tuneUpdated(Tune *tune);
  813. +   void shuffleUpdated(bool enabled);
  814. +   void loopAllUpdated(bool enabled);
  815. +   void updateShuffle();
  816. +   void updateLoopAll();
  817.  
  818.  private:
  819.     void disableMpris();
  820. diff --git a/plugins/mprisplugin/rootadapter.cpp b/plugins/mprisplugin/rootadapter.cpp
  821. index f221839..3a43eed 100644
  822. --- a/plugins/mprisplugin/rootadapter.cpp
  823. +++ b/plugins/mprisplugin/rootadapter.cpp
  824. @@ -1,5 +1,5 @@
  825.  /*
  826. - * Copyright (C) 2016-2019  Khryukin Evgeny, Vitaly Tonkacheyev
  827. + * Copyright (C) 2016-2022  Khryukin Evgeny, Vitaly Tonkacheyev
  828.   *
  829.   * This program is free software; you can redistribute it and/or
  830.   * modify it under the terms of the GNU General Public License
  831. @@ -23,23 +23,18 @@
  832.  #include <QDBusConnection>
  833.  #include <QDBusMessage>
  834.  
  835. -RootAdapter::RootAdapter(MprisController *p)
  836. - :QDBusAbstractAdaptor(p),
  837. -  controller_(p)
  838. -{
  839. -}
  840. +RootAdapter::RootAdapter(MprisController *p) : QDBusAbstractAdaptor(p), controller_(p) { }
  841.  
  842.  void RootAdapter::setData()
  843.  {
  844. -   QVariantMap map({{"SupportedMimeTypes", getMimeTypes()},
  845. -            {"Identity", getIdentity()},
  846. -            {"CanQuit", canQuit()},
  847. -            {"CanRaise", canRaise()},
  848. -            {"CanSetFullscreen", canSetFullscreen()},
  849. -            {"SupportedUriSchemes", QStringList()},
  850. -            {"HasTrackList", hasTrackList()}});
  851. -   QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2",
  852. -                             "org.freedesktop.DBus.Properties",
  853. +   QVariantMap  map({ { "SupportedMimeTypes", getMimeTypes() },
  854. +              { "Identity", getIdentity() },
  855. +              { "CanQuit", canQuit() },
  856. +              { "CanRaise", canRaise() },
  857. +              { "CanSetFullscreen", canSetFullscreen() },
  858. +              { "SupportedUriSchemes", QStringList() },
  859. +              { "HasTrackList", hasTrackList() } });
  860. +   QDBusMessage msg = QDBusMessage::createSignal("/org/mpris/MediaPlayer2", "org.freedesktop.DBus.Properties",
  861.                               "PropertiesChanged");
  862.     msg << "org.mpris.MediaPlayer2" << map << QStringList();
  863.     QDBusConnection::sessionBus().send(msg);
  864. @@ -47,25 +42,21 @@ void RootAdapter::setData()
  865.  
  866.  void RootAdapter::Quit()
  867.  {
  868. -   if(canQuit()) {
  869. +   if (canQuit()) {
  870.         controller_->emitSignal(QUIT);
  871.     }
  872.  }
  873.  
  874.  void RootAdapter::Raise()
  875.  {
  876. -   if(canRaise()) {
  877. +   if (canRaise()) {
  878.         controller_->emitSignal(RAISE);
  879.     }
  880.  }
  881.  
  882.  QStringList RootAdapter::getMimeTypes() const
  883.  {
  884. -   return QStringList({"audio/aac", "audio/x-flac",
  885. -                "audio/flac", "audio/mp3",
  886. -                "audio/mpeg", "application/ogg",
  887. -                "audio/x-vorbis+ogg", "audio/x-ms-wma",
  888. -                "audio/mp4", "audio/MP4A-LATM",
  889. -                "audio/mpeg4-generic", "audio/m4a",
  890. -                "audio/ac3"});
  891. +   return QStringList({ "audio/aac", "audio/x-flac", "audio/flac", "audio/mp3", "audio/mpeg", "application/ogg",
  892. +                "audio/x-vorbis+ogg", "audio/x-ms-wma", "audio/mp4", "audio/MP4A-LATM",
  893. +                "audio/mpeg4-generic", "audio/m4a", "audio/ac3" });
  894.  }
  895. diff --git a/plugins/mprisplugin/rootadapter.h b/plugins/mprisplugin/rootadapter.h
  896. index f995066..fdbf9e4 100644
  897. --- a/plugins/mprisplugin/rootadapter.h
  898. +++ b/plugins/mprisplugin/rootadapter.h
  899. @@ -1,5 +1,5 @@
  900.  /*
  901. - * Copyright (C) 2016  Khryukin Evgeny, Vitaly Tonkacheyev
  902. + * Copyright (C) 2016-2022  Khryukin Evgeny, Vitaly Tonkacheyev
  903.   *
  904.   * This program is free software; you can redistribute it and/or
  905.   * modify it under the terms of the GNU General Public License
  906. @@ -43,7 +43,7 @@ public:
  907.  
  908.  private:
  909.     QStringList getMimeTypes() const;
  910. -    QStringList getUriSchemes() const {return QStringList();}
  911. +   QStringList getUriSchemes() const {return QStringList();}
  912.     QString getIdentity() const {return "Qomp";}
  913.     QString getDesktopEntry() const {return "qomp";}
  914.     bool canQuit() const {return true;}
  915. diff --git a/src/qompcon.cpp b/src/qompcon.cpp
  916. index 379c8c9..8cfb62f 100644
  917. --- a/src/qompcon.cpp
  918. +++ b/src/qompcon.cpp
  919. @@ -856,7 +856,6 @@ void QompCon::connectMainWin()
  920.     connect(player_, SIGNAL(mutedChanged(bool)),            mainWin_, SLOT(setMuteState(bool)));
  921.     connect(player_, SIGNAL(volumeChanged(qreal)),          mainWin_, SLOT(volumeChanged(qreal)));
  922.     connect(player_, SIGNAL(currentTuneTotalTimeChanged(qint64)),   mainWin_, SLOT(currentTotalTimeChanged(qint64)));
  923. -
  924.     connect(mainWin_, SIGNAL(aboutQomp()),              SLOT(actAboutQomp()));
  925.     connect(mainWin_, SIGNAL(bugReport()),              SLOT(actBugReport()));
  926.     connect(mainWin_, SIGNAL(checkForUpdates()),            SLOT(actCheckForUpdates()));
  927. @@ -877,6 +876,8 @@ void QompCon::connectMainWin()
  928.     connect(mainWin_, SIGNAL(removeTune(Tune*)),            SLOT(actRemoveTune(Tune*)));
  929.     connect(mainWin_, SIGNAL(mediaActivated(QModelIndex)),      SLOT(actMediaActivated(QModelIndex)));
  930.     connect(mainWin_, SIGNAL(mediaClicked(QModelIndex)),        SLOT(actMediaClicked(QModelIndex)));
  931. +   connect(mainWin_, &QompMainWin::shuffleUpdated, player_, &QompPlayer::shuffleUpdated);
  932. +   connect(mainWin_, &QompMainWin::repeatAllUpdated, player_, &QompPlayer::loopAllUpdated);
  933.  #ifndef QOMP_MOBILE
  934.     connect(&watcher_, SIGNAL(commandShow()), mainWin_, SLOT(show()));
  935.  #endif
  936. diff --git a/src/qompmainwin.cpp b/src/qompmainwin.cpp
  937. index b8fb878..f3f89d1 100644
  938. --- a/src/qompmainwin.cpp
  939. +++ b/src/qompmainwin.cpp
  940. @@ -134,6 +134,12 @@ QompMainWin::Private::Private(QompMainWin *p) :
  941.     mainWin_->setupFinished();
  942.     connect(ThemeManager::instance(), &ThemeManager::themeChanged, parentWin_, &QompMainWin::updateButtonIcons);
  943.  
  944. +   connect(ui->tb_repeatAll, &QToolButton::toggled, this, [this](bool enabled){
  945. +       emit parentWin_->repeatAllUpdated(enabled);
  946. +   });
  947. +   connect(ui->tb_shuffle, &QToolButton::toggled, this, [this](bool enabled){
  948. +       emit parentWin_->shuffleUpdated(enabled);
  949. +   });
  950.     ui->tb_repeatAll->setChecked(Options::instance()->getOption(OPTION_REPEAT_ALL).toBool());
  951.     ui->tb_shuffle->setChecked(Options::instance()->getOption(OPTION_SHUFFLE).toBool());
  952.     updateShuffleIcon();
  953. diff --git a/src/qompmainwin.h b/src/qompmainwin.h
  954. index b950f10..265bffc 100644
  955. --- a/src/qompmainwin.h
  956. +++ b/src/qompmainwin.h
  957. @@ -79,6 +79,9 @@ signals:
  958.     void mediaActivated(const QModelIndex& index);
  959.     void mediaClicked(const QModelIndex& index);
  960.  
  961. +   void shuffleUpdated(bool enabled);
  962. +   void repeatAllUpdated(bool enabled);
  963. +
  964.  protected:
  965.     bool eventFilter(QObject *o, QEvent *e);
  966.    
  967.  
Add Comment
Please, Sign In to add comment