[vlc-devel] [PATCH 1/2] qt: expose medialibrary discovery progress as state rather than events
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Tue Aug 6 19:02:07 CEST 2019
On Tue, Aug 6, 2019, at 6:43 PM, Pierre Lamot wrote:
> this avoids handling the logic in QML
> ---
> .../qt/components/mediacenter/mcmedialib.cpp | 57 +++++++++++++++++--
> .../qt/components/mediacenter/mcmedialib.hpp | 22 +++++--
> modules/gui/qt/qml/utils/ScanProgressBar.qml | 25 ++------
> 3 files changed, 73 insertions(+), 31 deletions(-)
>
> diff --git a/modules/gui/qt/components/mediacenter/mcmedialib.cpp
> b/modules/gui/qt/components/mediacenter/mcmedialib.cpp
> index 1889537cbe..3edef7b946 100644
> --- a/modules/gui/qt/components/mediacenter/mcmedialib.cpp
> +++ b/modules/gui/qt/components/mediacenter/mcmedialib.cpp
> @@ -224,23 +224,68 @@ void MCMediaLib::onMediaLibraryEvent( void* data,
> const vlc_ml_event_t* event )
> switch ( event->i_type )
> {
> case VLC_ML_EVENT_PARSING_PROGRESS_UPDATED:
> - self->emit progressUpdated(
> event->parsing_progress.i_percent );
> + {
> + int percent = event->parsing_progress.i_percent;
> + QMetaObject::invokeMethod(self, [self, percent]() {
> + self->m_discoveryProgress = percent;
> + self->emit discoveryProgressChanged(percent);
> + });
> break;
> + }
> case VLC_ML_EVENT_DISCOVERY_STARTED:
> - self->emit discoveryStarted();
> + {
> + QMetaObject::invokeMethod(self, [self]() {
> + self->m_discoveryPending = true;
> + self->emit
> discoveryPendingChanged(self->m_discoveryPending);
> + self->emit discoveryStarted();
> + });
> break;
> + }
> case VLC_ML_EVENT_DISCOVERY_PROGRESS:
> - self->emit discoveryProgress(
> event->discovery_progress.psz_entry_point );
> + {
> + QString entryPoint{
> event->discovery_progress.psz_entry_point };
> + QMetaObject::invokeMethod(self, [self, entryPoint]() {
> + self->m_discoveryEntryPoint = entryPoint;
> + self->emit discoveryEntryPointChanged(entryPoint);
> + });
> break;
> + }
> case VLC_ML_EVENT_DISCOVERY_COMPLETED:
> - self->emit discoveryCompleted();
> + {
> + QMetaObject::invokeMethod(self, [self]() {
> + self->m_discoveryPending = false;
> + self->emit
> discoveryPendingChanged(self->m_discoveryPending);
> + self->emit discoveryCompleted();
> + });
> break;
> + }
> case VLC_ML_EVENT_RELOAD_STARTED:
> - self->emit reloadStarted();
> + {
> + QMetaObject::invokeMethod(self, [self]() {
> + self->m_discoveryPending = true;
> + self->emit
> discoveryPendingChanged(self->m_discoveryPending);
> + self->emit reloadStarted();
> + });
> break;
> + }
> case VLC_ML_EVENT_RELOAD_COMPLETED:
> - self->emit reloadCompleted();
> + {
> + QMetaObject::invokeMethod(self, [self]() {
> + self->m_discoveryPending = false;
> + self->emit
> discoveryPendingChanged(self->m_discoveryPending);
> + self->emit reloadCompleted();
> + });
> break;
> + }
> + case VLC_ML_EVENT_BACKGROUND_IDLE_CHANGED:
> + {
> + bool idle = event->background_idle_changed.b_idle;
> + QMetaObject::invokeMethod(self, [self, idle]() {
> + self->m_discoveryIdle = idle;
> + self->emit idleChanged();
> + });
> + break;
> + }
> default:
> break;
> }
> diff --git a/modules/gui/qt/components/mediacenter/mcmedialib.hpp
> b/modules/gui/qt/components/mediacenter/mcmedialib.hpp
> index 61d100c47d..b97fffc2b1 100644
> --- a/modules/gui/qt/components/mediacenter/mcmedialib.hpp
> +++ b/modules/gui/qt/components/mediacenter/mcmedialib.hpp
> @@ -40,6 +40,10 @@ class MCMediaLib : public QObject
> Q_OBJECT
>
> Q_PROPERTY(bool gridView READ isGridView WRITE setGridView NOTIFY
> gridViewChanged)
> + Q_PROPERTY(bool discoveryPending READ discoveryPending NOTIFY
> discoveryPendingChanged)
> + Q_PROPERTY(int discoveryProgress READ discoveryProgress NOTIFY
> discoveryProgressChanged)
> + Q_PROPERTY(QString discoveryEntryPoint READ discoveryEntryPoint
> NOTIFY discoveryEntryPointChanged)
> + Q_PROPERTY(bool discoveryIdle READ discoveryIdle NOTIFY
> idleChanged)
>
> public:
> MCMediaLib(intf_thread_t* _intf, QObject* _parent = nullptr );
> @@ -54,17 +58,23 @@ public:
> Q_INVOKABLE void addAndPlay(const QUrl& mrl);
> Q_INVOKABLE void addAndPlay(const QVariantList&itemIdList);
>
> + inline bool discoveryIdle() const { return m_discoveryIdle; }
> + inline int discoveryPending() const { return m_discoveryPending; }
> + inline QString discoveryEntryPoint() const { return
> m_discoveryEntryPoint; }
> + inline int discoveryProgress() const { return m_discoveryProgress;
> }
>
> vlc_medialibrary_t* vlcMl();
>
> signals:
> void gridViewChanged();
> - void discoveryStarted();
> void reloadStarted();
> - void discoveryProgress( QString entryPoint );
> - void discoveryCompleted();
> void reloadCompleted();
> - void progressUpdated( quint32 percent );
> + void discoveryStarted();
> + void discoveryCompleted();
> + void discoveryProgressChanged( quint32 percent );
> + void discoveryEntryPointChanged( QString entryPoint );
> + void discoveryPendingChanged( bool state );
> + void idleChanged();
>
> private:
> bool isGridView() const;
> @@ -81,6 +91,10 @@ private:
> intf_thread_t* m_intf;
>
> bool m_gridView;
> + bool m_discoveryIdle = false;
> + bool m_discoveryPending = false;
> + int m_discoveryProgress = 0;
> + QString m_discoveryEntryPoint;
>
> /* Medialibrary */
> vlc_medialibrary_t* m_ml;
> diff --git a/modules/gui/qt/qml/utils/ScanProgressBar.qml
> b/modules/gui/qt/qml/utils/ScanProgressBar.qml
> index 7b298110c4..e954c0b7a5 100644
> --- a/modules/gui/qt/qml/utils/ScanProgressBar.qml
> +++ b/modules/gui/qt/qml/utils/ScanProgressBar.qml
> @@ -21,37 +21,20 @@ import QtQuick.Controls 2.4
> import "qrc:///style/"
>
> ProgressBar {
> - property int progressPercent: 0
> - property bool discoveryDone: true
> + visible: !medialib.discoveryIdle
>
> - Connections {
> - target: medialib
> - onProgressUpdated: {
> - progressPercent = percent;
> - if (discoveryDone)
> - progressText_id.text = percent + "%";
> - }
> - onDiscoveryProgress: {
> - progressText_id.text = entryPoint;
> - }
> - onDiscoveryStarted: discoveryDone = false
> - onReloadStarted: discoveryDone = false
> - onDiscoveryCompleted: discoveryDone = true
> - onReloadCompleted: discoveryDone = true
> - }
> -
> - visible: ((progressPercent < 100) && (progressPercent != 0)) ||
> !discoveryDone
> id: progressBar_id
> from: 0
> to: 100
> height: progressText_id.height
> anchors.topMargin: 10
> anchors.bottomMargin: 10
> - value: progressPercent
> - indeterminate: !discoveryDone
> + value: medialib.discoveryProgress
> + indeterminate: medialib.discoveryPending
> Text {
> id: progressText_id
> color: VLCStyle.colors.text
> + text: medialib.discoveryPending ?
> medialib.discoveryEntryPoint : (medialib.discoveryProgress + "%")
> z: progressBar_id.z + 1
> anchors.horizontalCenter: parent.horizontalCenter
> visible: true
> --
> 2.17.1
>
As far as the medialib is concerned, "discovery" is solely about finding media files in the entrypoints/folders, not analyzing those, while the parsing progress (ie. VLC_ML_EVENT_PARSING_PROGRESS_UPDATED) is about this analysis, and is referred to as "parsing", so I'd be in favor of tweaking the naming a little to have a separation between those 2 tasks.
TL;DR: I think the discoveryProgress property should be called parsingProgress (or something similar), and discoveryIdle should be called something like medialibIdle (or something similar²).
Otherwise LGTM
--
Hugo Beauzée-Luyssen
hugo at beauzee.fr
More information about the vlc-devel
mailing list