vlc | branch: master | Pierre Lamot <[email protected]> | Wed Aug 7 10:33:29 2019 +0200| [d3f1aa5c06f212cd228a12433598c85a5b93764b] | committer: Jean-Baptiste Kempf
qt: expose medialibrary discovery progress as state rather than events this avoids handling the logic in QML > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d3f1aa5c06f212cd228a12433598c85a5b93764b --- .../gui/qt/components/mediacenter/mcmedialib.cpp | 57 +++++++++++++++++++--- .../gui/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 d451a741d2..7c44fd9720 100644 --- a/modules/gui/qt/components/mediacenter/mcmedialib.cpp +++ b/modules/gui/qt/components/mediacenter/mcmedialib.cpp @@ -222,23 +222,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_parsingProgress = percent; + self->emit parsingProgressChanged(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_idle = 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 43df1183b1..db52978bf4 100644 --- a/modules/gui/qt/components/mediacenter/mcmedialib.hpp +++ b/modules/gui/qt/components/mediacenter/mcmedialib.hpp @@ -39,6 +39,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 parsingProgress READ parsingProgress NOTIFY parsingProgressChanged) + Q_PROPERTY(QString discoveryEntryPoint READ discoveryEntryPoint NOTIFY discoveryEntryPointChanged) + Q_PROPERTY(bool idle READ idle NOTIFY idleChanged) public: MCMediaLib(intf_thread_t* _intf, QObject* _parent = nullptr ); @@ -53,17 +57,23 @@ public: Q_INVOKABLE void addAndPlay(const QUrl& mrl); Q_INVOKABLE void addAndPlay(const QVariantList&itemIdList); + inline bool idle() const { return m_idle; } + inline int discoveryPending() const { return m_discoveryPending; } + inline QString discoveryEntryPoint() const { return m_discoveryEntryPoint; } + inline int parsingProgress() const { return m_parsingProgress; } 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 parsingProgressChanged( quint32 percent ); + void discoveryEntryPointChanged( QString entryPoint ); + void discoveryPendingChanged( bool state ); + void idleChanged(); private: bool isGridView() const; @@ -76,6 +86,10 @@ private: intf_thread_t* m_intf; bool m_gridView; + bool m_idle = false; + bool m_discoveryPending = false; + int m_parsingProgress = 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..2e4d2ede37 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.idle - 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.parsingProgress + indeterminate: medialib.discoveryPending Text { id: progressText_id color: VLCStyle.colors.text + text: medialib.discoveryPending ? medialib.discoveryEntryPoint : (medialib.parsingProgress + "%") z: progressBar_id.z + 1 anchors.horizontalCenter: parent.horizontalCenter visible: true _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
