[vlc-commits] qt: skip invalid history points when going back in history

Pierre Lamot git at videolan.org
Fri Nov 27 14:52:28 CET 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Fri Nov 20 23:17:42 2020 +0530| [23eb27d3574113e77d6c19e8857dfb7f1d98618e] | committer: Pierre Lamot

qt: skip invalid history points when going back in history

  Media tree nodes might no longer valid when going back on them (ie: parent
  changed).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=23eb27d3574113e77d6c19e8857dfb7f1d98618e
---

 modules/gui/qt/network/networkmediamodel.hpp | 10 ++++++
 modules/gui/qt/util/navigation_history.cpp   | 53 ++++++++++++++++++++++++++++
 2 files changed, 63 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..a03ebb3566 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,53 @@ 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() )
+        {
+            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 +120,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);



More information about the vlc-commits mailing list