[vlc-devel] [PATCH 09/10] qt: skip invalid history points when going back in history
Prince Gupta
guptaprince8832 at gmail.com
Fri Nov 20 18:29:42 CET 2020
From: Pierre Lamot <pierre at videolabs.io>
Media tree nodes might no longer valid when going back on them (ie: parent
changed).
---
modules/gui/qt/network/networkmediamodel.hpp | 10 ++++
modules/gui/qt/util/navigation_history.cpp | 54 ++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index c12011ec5b..1d36047188 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -65,6 +65,14 @@ public:
return source.get() != nullptr;
}
+ bool isValid() {
+ vlc_media_tree_Lock(source->tree);
+ input_item_node_t* node;
+ bool ret = vlc_media_tree_Find( source->tree, media.get(), &node, nullptr);
+ vlc_media_tree_Unlock(source->tree);
+ return ret;
+ }
+
MediaSourcePtr source;
InputItemPtr media;
};
@@ -231,4 +239,6 @@ private:
QVariantList m_path;
};
+Q_DECLARE_METATYPE(NetworkTreeItem)
+
#endif // MLNETWORKMEDIAMODEL_HPP
diff --git a/modules/gui/qt/util/navigation_history.cpp b/modules/gui/qt/util/navigation_history.cpp
index 9d5e622ea8..4d87ec2874 100644
--- a/modules/gui/qt/util/navigation_history.cpp
+++ b/modules/gui/qt/util/navigation_history.cpp
@@ -1,5 +1,6 @@
#include "navigation_history.hpp"
#include <cassert>
+#include "network/networkmediamodel.hpp"
NavigationHistory::NavigationHistory(QObject *parent)
: QObject(parent)
@@ -44,6 +45,54 @@ static void pushListRec(QVariantMap& itemMap, QVariantList::const_iterator it, Q
}
}
+
+static bool isNodeValid(QVariant& value)
+{
+ if (value.canConvert(QVariant::StringList)
+ || value.canConvert(QVariant::StringList)
+ || value.canConvert(QVariant::String)
+ || value.canConvert(QVariant::UInt)
+ || value.canConvert(QVariant::Int)
+ || value.canConvert(QVariant::Bool)
+ )
+ {
+ return true;
+ }
+ else if ( value.canConvert(QVariant::List) )
+ {
+ QVariantList valueList = value.toList();
+ for (QVariant& v : valueList) {
+ if (!isNodeValid(v))
+ return false;
+ }
+ return true;
+ }
+ else if (value.canConvert<NetworkTreeItem>() )
+ {
+ NetworkTreeItem item = value.value<NetworkTreeItem>();
+ if ( ! item.isValid() )
+ {
+ qDebug( "NetworkTreeItem item is not valid" );
+ return false;
+ }
+ return true;
+ }
+ else if ( value.canConvert(QVariant::Map) )
+ {
+ QVariantMap valueList = value.toMap();
+ for (QVariant& v : valueList.values()) {
+ if (!isNodeValid(v)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ assert(false);
+ return false;
+}
+
+
void NavigationHistory::push(QVariantList itemList, NavigationHistory::PostAction postAction)
{
QVariantMap itemMap;
@@ -72,6 +121,11 @@ void NavigationHistory::previous(PostAction postAction)
return;
m_history.pop_back();
+ while (!isNodeValid(m_history.back())) {
+ m_history.pop_back();
+ if (m_history.count() == 1)
+ break;
+ }
if (m_history.count() == 1)
emit previousEmptyChanged(true);
--
2.25.1
More information about the vlc-devel
mailing list