File indexing completed on 2023-05-30 11:40:29

0001 /*
0002     Now playing
0003     Copyright (C) 2017  James D. Smith <smithjd15@gmail.com>
0004     Copyright (C) 2011  Martin Klapetek <martin.klapetek@gmail.com>
0005 
0006     This library is free software; you can redistribute it and/or
0007     modify it under the terms of the GNU Lesser General Public
0008     License as published by the Free Software Foundation; either
0009     version 2.1 of the License, or (at your option) any later version.
0010 
0011     This library is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014     Lesser General Public License for more details.
0015 
0016     You should have received a copy of the GNU Lesser General Public
0017     License along with this library; if not, write to the Free Software
0018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019 */
0020 
0021 #ifndef TELEPATHY_MPRIS_H
0022 #define TELEPATHY_MPRIS_H
0023 
0024 #include <KTp/types.h>
0025 
0026 #include <QTimer>
0027 
0028 class TelepathyMPRIS : public QObject, protected QDBusContext
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     TelepathyMPRIS(QObject *parent = 0);
0034     ~TelepathyMPRIS();
0035 
0036     enum Service {
0037         Unknown,
0038         Stopped,
0039         Paused,
0040         Playing
0041     };
0042     Q_ENUM(Service)
0043 
0044     struct Player {
0045         Service playState = TelepathyMPRIS::Unknown;
0046         QVariantMap metadata;
0047     };
0048 
0049     void enable(bool enable);
0050 
0051     Player* player() {return m_activePlayer;}
0052 
0053 Q_SIGNALS:
0054     void playerChange();
0055 
0056 private Q_SLOTS:
0057     void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
0058     void onPlayerSignalReceived(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
0059 
0060 private:
0061     void requestPlaybackStatus(const QString &serviceName, const QString &owner);
0062     void sortPlayerReply(const QVariantMap &serviceInfo, const QString &serviceName);
0063 
0064     QMetaObject::Connection m_timerConnection;
0065     QTimer *m_activationTimer;
0066     QEventLoop m_initLoop;
0067     QHash<QString, Player*> m_players;
0068     QHash<QString, QString> m_serviceNameByOwner;
0069     Player* m_activePlayer;
0070 };
0071 
0072 #endif // TELEPATHY_MPRIS_H