From 026b9db3a9e5357d7c580b3f5787b784482d23fe Mon Sep 17 00:00:00 2001 From: Benjamin Arnaud Date: Wed, 23 Feb 2022 17:53:57 +0100 Subject: [PATCH] qt: Create control_list_filter --- modules/gui/qt/Makefile.am | 3 + modules/gui/qt/maininterface/mainui.cpp | 2 + modules/gui/qt/player/control_list_filter.cpp | 93 +++++++++++++++++++ modules/gui/qt/player/control_list_filter.hpp | 56 +++++++++++ po/POTFILES.in | 2 + 5 files changed, 156 insertions(+) create mode 100644 modules/gui/qt/player/control_list_filter.cpp create mode 100644 modules/gui/qt/player/control_list_filter.hpp diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am index 01b16daaa0..df2d4e73d1 100644 --- a/modules/gui/qt/Makefile.am +++ b/modules/gui/qt/Makefile.am @@ -228,6 +228,8 @@ libqt_plugin_la_SOURCES = \ gui/qt/player/player_controller.cpp gui/qt/player/player_controller.hpp gui/qt/player/player_controller_p.hpp \ gui/qt/player/player_controlbar_model.cpp gui/qt/player/player_controlbar_model.hpp \ gui/qt/player/control_list_model.cpp gui/qt/player/control_list_model.hpp \ + gui/qt/player/control_list_filter.cpp \ + gui/qt/player/control_list_filter.hpp \ gui/qt/playlist/media.hpp \ gui/qt/playlist/playlist_common.cpp \ gui/qt/playlist/playlist_common.hpp \ @@ -424,6 +426,7 @@ nodist_libqt_plugin_la_SOURCES = \ gui/qt/player/player_controller.moc.cpp \ gui/qt/player/player_controlbar_model.moc.cpp \ gui/qt/player/control_list_model.moc.cpp \ + gui/qt/player/control_list_filter.moc.cpp \ gui/qt/playlist/playlist_common.moc.cpp \ gui/qt/playlist/playlist_controller.moc.cpp \ gui/qt/playlist/playlist_item.moc.cpp \ diff --git a/modules/gui/qt/maininterface/mainui.cpp b/modules/gui/qt/maininterface/mainui.cpp index 21bcc6b843..36b47ebc4c 100644 --- a/modules/gui/qt/maininterface/mainui.cpp +++ b/modules/gui/qt/maininterface/mainui.cpp @@ -22,6 +22,7 @@ #include "player/player_controller.hpp" #include "player/player_controlbar_model.hpp" #include "player/control_list_model.hpp" +#include "player/control_list_filter.hpp" #include "dialogs/toolbar/controlbar_profile_model.hpp" #include "dialogs/toolbar/controlbar_profile.hpp" @@ -255,6 +256,7 @@ void MainUI::registerQMLTypes() qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "ControlbarProfile", ""); qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "PlayerControlbarModel", ""); qmlRegisterUncreatableType( uri, versionMajor, versionMinor, "ControlListModel", "" ); + qmlRegisterType(uri, versionMajor, versionMinor, "ControlListFilter"); qmlRegisterSingletonType(uri, versionMajor, versionMinor, "PlayerListModel", PlayerControlbarModel::getPlaylistIdentifierListModel); qmlRegisterType( uri, versionMajor, versionMinor, "StringListMenu" ); diff --git a/modules/gui/qt/player/control_list_filter.cpp b/modules/gui/qt/player/control_list_filter.cpp new file mode 100644 index 0000000000..a07301dec9 --- /dev/null +++ b/modules/gui/qt/player/control_list_filter.cpp @@ -0,0 +1,93 @@ +/***************************************************************************** + * Copyright (C) 2022 VLC authors and VideoLAN + * + * Authors: Benjamin Arnaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * ( at your option ) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#include "control_list_filter.hpp" + +// Player includes +#include "player_controller.hpp" +#include "control_list_model.hpp" + +// Ctor / dtor + +/* explicit */ ControlListFilter::ControlListFilter(QObject * parent) + : QSortFilterProxyModel(parent) {} + +// QAbstractProxyModel reimplementation + +void ControlListFilter::setSourceModel(QAbstractItemModel * sourceModel) /* override */ +{ + assert(sourceModel->inherits("ControlListModel")); + + QSortFilterProxyModel::setSourceModel(sourceModel); +} + +// Protected QSortFilterProxyModel reimplementation + +bool ControlListFilter::filterAcceptsRow(int source_row, const QModelIndex &) const /* override */ +{ + QAbstractItemModel * model = sourceModel(); + + if (model == nullptr || m_player == nullptr) + return true; + + QVariant variant = model->data(model->index(source_row, 0), ControlListModel::ID_ROLE); + + if (variant.isValid() == false) + return true; + + ControlListModel::ControlType type + = static_cast (variant.toInt()); + + // NOTE: These controls are completely hidden when the current media does not support them. + if (type == ControlListModel::TELETEXT_BUTTONS) + { + return m_player->isTeletextAvailable(); + } + else if (type == ControlListModel::DVD_MENUS_BUTTON) + { + return m_player->hasMenu(); + } + + return true; +} + +// Properties + +PlayerController * ControlListFilter::player() +{ + return m_player; +} + +void ControlListFilter::setPlayer(PlayerController * player) +{ + if (m_player == player) return; + + if (m_player) + disconnect(m_player, nullptr, this, nullptr); + + m_player = player; + + connect(player, &PlayerController::teletextAvailableChanged, this, &ControlListFilter::invalidate); + connect(player, &PlayerController::hasMenuChanged, this, &ControlListFilter::invalidate); + + invalidate(); + + emit playerChanged(); +} diff --git a/modules/gui/qt/player/control_list_filter.hpp b/modules/gui/qt/player/control_list_filter.hpp new file mode 100644 index 0000000000..03cdcb6585 --- /dev/null +++ b/modules/gui/qt/player/control_list_filter.hpp @@ -0,0 +1,56 @@ +/***************************************************************************** + * Copyright (C) 2022 VLC authors and VideoLAN + * + * Authors: Benjamin Arnaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * ( at your option ) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifndef CONTROLLISTFILTER_HPP +#define CONTROLLISTFILTER_HPP + +// Qt includes +#include + +// Forward declarations +class PlayerController; + +class ControlListFilter : public QSortFilterProxyModel +{ + Q_OBJECT + + Q_PROPERTY(PlayerController * player READ player WRITE setPlayer NOTIFY playerChanged) + +public: + explicit ControlListFilter(QObject * parent = nullptr); + +public: // QAbstractProxyModel reimplementation + void setSourceModel(QAbstractItemModel * sourceModel) override; + +protected: // QSortFilterProxyModel reimplementation + bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override; + +signals: + void playerChanged(); + +public: // Properties + PlayerController * player(); + void setPlayer(PlayerController * player); + +private: // Variables + PlayerController * m_player = nullptr; +}; + +#endif // CONTROLLISTFILTER_HPP diff --git a/po/POTFILES.in b/po/POTFILES.in index a6a9899700..ceb6bf2cfc 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -817,6 +817,8 @@ modules/gui/qt/util/validators.cpp modules/gui/qt/util/validators.hpp modules/gui/qt/player/player_controlbar_model.cpp modules/gui/qt/player/player_controlbar_model.hpp +modules/gui/qt/player/control_list_filter.cpp +modules/gui/qt/player/control_list_filter.hpp modules/gui/qt/dialogs/dialogs/qml/CustomDialog.qml modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml modules/gui/qt/dialogs/dialogs/qml/WindowDialog.qml