File indexing completed on 2025-01-05 04:02:12

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018 */
0019 
0020 #ifndef MPRISMEDIAPLAYER2PLAYER_H
0021 #define MPRISMEDIAPLAYER2PLAYER_H
0022 
0023 #include "dbusabstractadaptor.h"
0024 // lib
0025 #include <document/document.h>
0026 
0027 class QDBusObjectPath;
0028 class QAction;
0029 
0030 namespace Gwenview
0031 {
0032 class SlideShow;
0033 class ContextManager;
0034 
0035 // https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
0036 class MprisMediaPlayer2Player : public DBusAbstractAdaptor
0037 {
0038     Q_OBJECT
0039     Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player")
0040 
0041     Q_PROPERTY(QString PlaybackStatus READ playbackStatus)
0042     Q_PROPERTY(double Rate READ rate WRITE setRate)
0043     Q_PROPERTY(QVariantMap Metadata READ metadata)
0044     Q_PROPERTY(double Volume READ volume WRITE setVolume)
0045     Q_PROPERTY(qlonglong Position READ position)
0046     Q_PROPERTY(double MinimumRate READ minimumRate CONSTANT)
0047     Q_PROPERTY(double MaximumRate READ maximumRate CONSTANT)
0048     Q_PROPERTY(bool Shuffle READ isShuffle WRITE setShuffle)
0049 
0050     Q_PROPERTY(bool CanControl READ canControl CONSTANT)
0051     Q_PROPERTY(bool CanPlay READ canPlay)
0052     Q_PROPERTY(bool CanPause READ canPause)
0053     Q_PROPERTY(bool CanGoNext READ canGoNext)
0054     Q_PROPERTY(bool CanGoPrevious READ canGoPrevious)
0055     Q_PROPERTY(bool CanSeek READ canSeek CONSTANT)
0056 
0057 public:
0058     MprisMediaPlayer2Player(const QString &objectDBusPath,
0059                             SlideShow *slideShow,
0060                             ContextManager *contextManager,
0061                             QAction *toggleSlideShowAction,
0062                             QAction *fullScreenAction,
0063                             QAction *previousAction,
0064                             QAction *nextAction,
0065                             QObject *parent);
0066     ~MprisMediaPlayer2Player() override;
0067 
0068 public Q_SLOTS: // D-Bus API
0069     void Next();
0070     void Previous();
0071     void Pause();
0072     void PlayPause();
0073     void Stop();
0074     void Play();
0075     void Seek(qlonglong Offset);
0076     void SetPosition(const QDBusObjectPath &trackId, qlonglong pos);
0077     void OpenUri(const QString &uri);
0078 
0079 Q_SIGNALS: // D-Bus API
0080     void Seeked(qlonglong Position) const;
0081 
0082 private:
0083     QString playbackStatus() const;
0084     double rate() const;
0085     QVariantMap metadata() const;
0086     double volume() const;
0087     qlonglong position() const;
0088     double minimumRate() const;
0089     double maximumRate() const;
0090     bool isShuffle() const;
0091 
0092     bool canGoNext() const;
0093     bool canGoPrevious() const;
0094     bool canPlay() const;
0095     bool canPause() const;
0096     bool canSeek() const;
0097     bool canControl() const;
0098 
0099     void setRate(double newRate);
0100     void setVolume(double volume);
0101     void setShuffle(bool isShuffle);
0102 
0103     bool updatePlaybackStatus();
0104 
0105     void onSlideShowStateChanged();
0106     void onCurrentUrlChanged(const QUrl &url);
0107     void onRandomActionToggled(bool checked);
0108     void onToggleSlideShowActionChanged();
0109     void onPreviousActionChanged();
0110     void onNextActionChanged();
0111     void onMetaInfoUpdated();
0112 
0113 private:
0114     SlideShow *mSlideShow;
0115     ContextManager *mContextManager;
0116     QAction *mToggleSlideShowAction;
0117     QAction *mFullScreenAction;
0118     QAction *mPreviousAction;
0119     QAction *mNextAction;
0120 
0121     bool mSlideShowEnabled;
0122     bool mPreviousEnabled;
0123     bool mNextEnabled;
0124     QString mPlaybackStatus;
0125     QVariantMap mMetaData;
0126     Document::Ptr mCurrentDocument;
0127 };
0128 
0129 }
0130 
0131 #endif