File indexing completed on 2024-05-19 05:38:36

0001 
0002 
0003 /*
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 <QConcatenateTablesProxyModel>
0012 
0013 #include <qqmlregistration.h>
0014 
0015 #include "kmpris_export.h"
0016 
0017 class Mpris2FilterProxyModel;
0018 class MultiplexerModel;
0019 class PlayerContainer;
0020 
0021 /**
0022  * A model that concatenates the multiplexer and players
0023  */
0024 class KMPRIS_EXPORT Mpris2Model : public QConcatenateTablesProxyModel
0025 {
0026     Q_OBJECT
0027     QML_ELEMENT
0028 
0029     Q_PROPERTY(unsigned currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
0030     Q_PROPERTY(PlayerContainer *currentPlayer READ currentPlayer NOTIFY currentPlayerChanged)
0031 
0032 public:
0033     explicit Mpris2Model(QObject *parent = nullptr);
0034     ~Mpris2Model() override;
0035 
0036     QHash<int, QByteArray> roleNames() const override;
0037 
0038     unsigned currentIndex() const;
0039     void setCurrentIndex(unsigned index);
0040     PlayerContainer *currentPlayer() const;
0041 
0042     Q_INVOKABLE PlayerContainer *playerForLauncherUrl(const QUrl &launcherUrl, unsigned pid) const;
0043 
0044 Q_SIGNALS:
0045     void currentIndexChanged();
0046     void currentPlayerChanged();
0047 
0048 private Q_SLOTS:
0049     void onRowsInserted(const QModelIndex &parent, int first, int last);
0050     void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
0051     void onRowsRemoved(const QModelIndex &parent, int first, int last);
0052     void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles);
0053 
0054 private:
0055     std::shared_ptr<MultiplexerModel> m_multiplexerModel;
0056     std::shared_ptr<Mpris2FilterProxyModel> m_mprisModel;
0057     PlayerContainer *m_currentPlayer = nullptr;
0058     unsigned m_currentIndex = 0;
0059 };