File indexing completed on 2024-05-19 05:38:37
0001 0002 /* 0003 SPDX-FileCopyrightText: 2007-2012 Alex Merry <alex.merry@kdemail.net> 0004 SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QBindable> 0012 #include <QObject> 0013 0014 #include "kmpris_export.h" 0015 0016 class Mpris2FilterProxyModel; 0017 class PlayerContainer; 0018 0019 class KMPRIS_EXPORT Multiplexer : public QObject 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 static std::shared_ptr<Multiplexer> self(); 0025 explicit Multiplexer(QObject *parent = nullptr); 0026 ~Multiplexer() override; 0027 0028 /** 0029 * The player that is automatically chosen by the multiplexer. 0030 * When there is no player, the value is -1. 0031 */ 0032 QBindable<int> activePlayerIndex() const; 0033 QBindable<PlayerContainer *> activePlayer() const; 0034 0035 Q_SIGNALS: 0036 void activePlayerIndexChanged(int newIndex); 0037 0038 private Q_SLOTS: 0039 void onRowsInserted(const QModelIndex &parent, int first, int last); 0040 void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last); 0041 void onRowsRemoved(const QModelIndex &parent, int first, int last); 0042 void onPlaybackStatusChanged(); 0043 0044 private: 0045 void updateIndex(); 0046 void evaluatePlayers(); 0047 0048 std::shared_ptr<Mpris2FilterProxyModel> m_filterModel; 0049 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(Multiplexer, PlayerContainer *, m_activePlayer, nullptr) 0050 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(Multiplexer, int, m_activePlayerIndex, -1, &Multiplexer::activePlayerIndexChanged) 0051 };