[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: factorize roles across network models

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Aug 10 06:24:11 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
3e2a6bb4 by Pierre Lamot at 2024-08-10T06:02:38+00:00
qt: factorize roles across network models

- - - - -
4b9d4151 by Pierre Lamot at 2024-08-10T06:02:38+00:00
qml: expose artwork fallback as a model property in Network models

the artwork fallback depends on the item type and may be different for each item
we may as well expose it as a model property

- - - - -
140f7700 by Pierre Lamot at 2024-08-10T06:02:38+00:00
qml: use artworkFallback property in network views

Rather than having a type mapping defined in each files

- - - - -


14 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/meson.build
- modules/gui/qt/network/devicesourceprovider.hpp
- + modules/gui/qt/network/networkbasemodel.cpp
- + modules/gui/qt/network/networkbasemodel.hpp
- modules/gui/qt/network/networkdevicemodel.cpp
- modules/gui/qt/network/networkdevicemodel.hpp
- modules/gui/qt/network/networkmediamodel.cpp
- modules/gui/qt/network/networkmediamodel.hpp
- modules/gui/qt/network/qml/BrowseTreeDisplay.qml
- modules/gui/qt/network/qml/NetworkCustomCover.qml
- modules/gui/qt/network/qml/NetworkGridItem.qml
- modules/gui/qt/network/standardpathmodel.cpp
- modules/gui/qt/network/standardpathmodel.hpp


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -246,6 +246,8 @@ libqt_plugin_la_SOURCES = \
 	network/mediatreelistener.hpp \
 	network/devicesourceprovider.cpp \
 	network/devicesourceprovider.hpp \
+	network/networkbasemodel.cpp \
+	network/networkbasemodel.hpp \
 	network/networkdevicemodel.cpp \
 	network/networkdevicemodel.hpp \
 	network/networksourcesmodel.cpp \
@@ -442,6 +444,7 @@ nodist_libqt_plugin_la_SOURCES = \
 	menus/menus.moc.cpp \
 	network/devicesourceprovider.moc.cpp \
 	network/networkdevicemodel.moc.cpp \
+	network/networkbasemodel.moc.cpp \
 	network/networksourcesmodel.moc.cpp \
 	network/networkmediamodel.moc.cpp \
 	network/servicesdiscoverymodel.moc.cpp \


=====================================
modules/gui/qt/meson.build
=====================================
@@ -104,6 +104,7 @@ moc_headers = files(
     'menus/qml_menu_wrapper.hpp',
     'menus/menus.hpp',
     'network/devicesourceprovider.hpp',
+    'network/networkbasemodel.hpp',
     'network/networkdevicemodel.hpp',
     'network/networksourcesmodel.hpp',
     'network/networkmediamodel.hpp',
@@ -374,6 +375,8 @@ some_sources = files(
     'network/mediatreelistener.hpp',
     'network/devicesourceprovider.cpp',
     'network/devicesourceprovider.hpp',
+    'network/networkbasemodel.cpp',
+    'network/networkbasemodel.hpp',
     'network/networkdevicemodel.cpp',
     'network/networkdevicemodel.hpp',
     'network/networksourcesmodel.cpp',


=====================================
modules/gui/qt/network/devicesourceprovider.hpp
=====================================
@@ -32,18 +32,19 @@
 #include "mediatreelistener.hpp"
 
 //represents an entry of the model
-struct NetworkDeviceItem
+struct NetworkDeviceItem : public NetworkBaseItem
 {
-    NetworkDeviceItem(const SharedInputItem& item, const NetworkDeviceModel::MediaSourcePtr& mediaSource)
-        : name(qfu(item->psz_name))
-        , mainMrl(QUrl::fromEncoded(item->psz_uri))
-        , protocol(mainMrl.scheme())
-        , type( static_cast<NetworkDeviceModel::ItemType>(item->i_type))
-        , mediaSource(mediaSource)
-        , inputItem(item)
+    NetworkDeviceItem(const SharedInputItem& item, const NetworkDeviceModel::MediaSourcePtr& source)
     {
+        name = qfu(item->psz_name);
+        mainMrl = QUrl::fromEncoded(item->psz_uri);
+        protocol = mainMrl.scheme();
+        type = static_cast<NetworkDeviceModel::ItemType>(item->i_type);
+        mediaSource = source;
+        inputItem = item;
+
         id = qHash(name) ^ qHash(protocol);
-        mrls.push_back(std::make_pair(mainMrl, mediaSource));
+        mrls.push_back(std::make_pair(mainMrl, source));
 
         char* artworkUrl = input_item_GetArtworkURL(inputItem.get());
         if (artworkUrl)
@@ -54,15 +55,10 @@ struct NetworkDeviceItem
     }
 
     uint id;
-    QString name;
-    QUrl mainMrl;
     std::vector<std::pair<QUrl, NetworkDeviceModel::MediaSourcePtr>> mrls;
-    QString protocol;
-    NetworkDeviceModel::ItemType type;
     NetworkDeviceModel::MediaSourcePtr mediaSource;
     SharedInputItem inputItem;
-    QString artwork;
-};
+ };
 
 using NetworkDeviceItemPtr =std::shared_ptr<NetworkDeviceItem>;
 


=====================================
modules/gui/qt/network/networkbasemodel.cpp
=====================================
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * 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 "networkbasemodel.hpp"
+
+QVariant NetworkBaseModel::basedata(const NetworkBaseItem& item, int role) const
+{
+    switch (role)
+    {
+    case NETWORK_BASE_NAME:
+        return item.name;
+    case NETWORK_BASE_MRL:
+        return item.mainMrl;
+    case NETWORK_BASE_TYPE:
+        return item.type;
+    case NETWORK_BASE_PROTOCOL:
+        return item.protocol;
+    case NETWORK_BASE_ARTWORK:
+        return item.artwork;
+    case NETWORK_BASE_ARTWORK_FALLBACK:
+        return artworkFallbackForType(item.type);
+    default:
+        return {};
+    };
+}
+
+QString NetworkBaseModel::artworkFallbackForType(const ItemType type) const
+{
+    switch (type) {
+    case TYPE_DISC:
+        return "qrc:///sd/disc.svg";
+    case TYPE_CARD:
+        return "qrc:///sd/capture-card.svg";
+    case TYPE_STREAM:
+        return "qrc:///sd/stream.svg";
+    case TYPE_PLAYLIST:
+        return "qrc:///sd/playlist.svg";
+    case TYPE_FILE:
+        return "qrc:///sd/file.svg";
+    default:
+        return "qrc:///sd/directory.svg";
+    }
+}
+
+QHash<int, QByteArray> NetworkBaseModel::roleNames() const
+{
+    return {
+        { NETWORK_BASE_NAME, "name" },
+        { NETWORK_BASE_MRL, "mrl" },
+        { NETWORK_BASE_TYPE, "type" },
+        { NETWORK_BASE_PROTOCOL, "protocol" },
+        { NETWORK_BASE_ARTWORK, "artwork" },
+        { NETWORK_BASE_ARTWORK_FALLBACK, "artworkFallback" },
+    };
+}


=====================================
modules/gui/qt/network/networkbasemodel.hpp
=====================================
@@ -0,0 +1,80 @@
+/*****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * 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 NETWORKBASEMODEL_HPP
+#define NETWORKBASEMODEL_HPP
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "util/base_model.hpp"
+#include <vlc_media_source.h>
+
+#include <QString>
+#include <QUrl>
+
+struct NetworkBaseItem;
+class NetworkBaseModel: public BaseModel
+{
+    Q_OBJECT
+
+public:
+    enum Role {
+        NETWORK_BASE_NAME = Qt::UserRole + 1,
+        NETWORK_BASE_MRL,
+        NETWORK_BASE_TYPE,
+        NETWORK_BASE_PROTOCOL,
+        NETWORK_BASE_ARTWORK,
+        NETWORK_BASE_ARTWORK_FALLBACK,
+        NETWORK_BASE_MAX
+    };
+
+    enum ItemType{
+        // qt version of input_item_type_e
+        TYPE_UNKNOWN = ITEM_TYPE_UNKNOWN,
+        TYPE_FILE,
+        TYPE_DIRECTORY,
+        TYPE_DISC,
+        TYPE_CARD,
+        TYPE_STREAM,
+        TYPE_PLAYLIST,
+        TYPE_NODE,
+    };
+    Q_ENUM( ItemType )
+
+    using BaseModel::BaseModel;
+
+    QHash<int, QByteArray> roleNames() const override;
+
+    Q_INVOKABLE QString artworkFallbackForType(const ItemType type) const;
+
+protected:
+    QVariant basedata(const NetworkBaseItem& item, int role) const;
+};
+
+struct NetworkBaseItem
+{
+    QString name;
+    QUrl mainMrl;
+    QString protocol;
+    NetworkBaseModel::ItemType type;
+    QString artwork;
+};
+
+#endif /* NETWORKBASEMODEL_HPP */


=====================================
modules/gui/qt/network/networkdevicemodel.cpp
=====================================
@@ -221,7 +221,7 @@ NetworkDeviceModel::NetworkDeviceModel( QObject* parent )
 }
 
 NetworkDeviceModel::NetworkDeviceModel( NetworkDeviceModelPrivate* priv, QObject* parent)
-    : BaseModel(priv, parent)
+    : NetworkBaseModel(priv, parent)
 {
 }
 
@@ -237,36 +237,21 @@ QVariant NetworkDeviceModel::data( const QModelIndex& index, int role ) const
 
     switch ( role )
     {
-        case NETWORK_NAME:
-            return item->name;
-        case NETWORK_MRL:
-            return item->mainMrl;
-        case NETWORK_TYPE:
-            return item->type;
-        case NETWORK_PROTOCOL:
-            return item->protocol;
         case NETWORK_SOURCE:
             return item->mediaSource->description;
         case NETWORK_TREE:
             return QVariant::fromValue( NetworkTreeItem(MediaTreePtr{ item->mediaSource->tree }, item->inputItem.get()) );
-        case NETWORK_ARTWORK:
-            return item->artwork;
         default:
-            return {};
+            return NetworkBaseModel::basedata(*item, role);
     }
 }
 
 QHash<int, QByteArray> NetworkDeviceModel::roleNames() const
 {
-    return {
-        { NETWORK_NAME, "name" },
-        { NETWORK_MRL, "mrl" },
-        { NETWORK_TYPE, "type" },
-        { NETWORK_PROTOCOL, "protocol" },
-        { NETWORK_SOURCE, "source" },
-        { NETWORK_TREE, "tree" },
-        { NETWORK_ARTWORK, "artwork" },
-    };
+    QHash<int, QByteArray> roles = NetworkBaseModel::roleNames();
+    roles[NETWORK_SOURCE] = "source";
+    roles[NETWORK_TREE] = "tree";
+    return roles;
 }
 
 void NetworkDeviceModel::setCtx(MainCtx* ctx)


=====================================
modules/gui/qt/network/networkdevicemodel.hpp
=====================================
@@ -28,7 +28,7 @@
 
 #include <vlc_media_source.h>
 
-#include "util/base_model.hpp"
+#include "networkbasemodel.hpp"
 #include "util/shared_input_item.hpp"
 
 #include <memory>
@@ -38,7 +38,7 @@ Q_MOC_INCLUDE("maininterface/mainctx.hpp")
 class MainCtx;
 
 class NetworkDeviceModelPrivate;
-class NetworkDeviceModel : public BaseModel
+class NetworkDeviceModel : public NetworkBaseModel
 {
     Q_OBJECT
 
@@ -49,28 +49,10 @@ class NetworkDeviceModel : public BaseModel
 
 public: // Enums
     enum Role {
-        NETWORK_NAME = Qt::UserRole + 1,
-        NETWORK_MRL,
-        NETWORK_TYPE,
-        NETWORK_PROTOCOL,
-        NETWORK_SOURCE,
+        NETWORK_SOURCE = NetworkBaseModel::NETWORK_BASE_MAX,
         NETWORK_TREE,
-        NETWORK_ARTWORK,
     };
 
-    enum ItemType{
-        // qt version of input_item_type_e
-        TYPE_UNKNOWN = ITEM_TYPE_UNKNOWN,
-        TYPE_FILE,
-        TYPE_DIRECTORY,
-        TYPE_DISC,
-        TYPE_CARD,
-        TYPE_STREAM,
-        TYPE_PLAYLIST,
-        TYPE_NODE,
-    };
-    Q_ENUM( ItemType )
-
     enum SDCatType{
         // qt version of input_item_type_e
         CAT_UNDEFINED = 0,


=====================================
modules/gui/qt/network/networkmediamodel.cpp
=====================================
@@ -40,17 +40,12 @@ namespace {
 //use the same queue as in mlfoldermodel
 static const char* const ML_FOLDER_ADD_QUEUE = "ML_FOLDER_ADD_QUEUE";
 
-struct NetworkMediaItem
+struct NetworkMediaItem : public NetworkBaseItem
 {
-    QString name;
     QString uri;
-    QUrl mainMrl;
-    QString protocol;
     bool indexed;
-    NetworkMediaModel::ItemType type;
     bool canBeIndexed;
     NetworkTreeItem tree;
-    QString artwork;
     qint64 fileSize;
     QDateTime fileModified;
     MLMedia media;
@@ -487,7 +482,7 @@ struct NetworkMediaModel::ListenerCb : public MediaTreeListener::MediaTreeListen
 // NetworkMediaModel implementation
 
 NetworkMediaModel::NetworkMediaModel( QObject* parent )
-    : BaseModel( new  NetworkMediaModelPrivate(this), parent )
+    : NetworkBaseModel( new  NetworkMediaModelPrivate(this), parent )
 {
 }
 
@@ -515,21 +510,13 @@ QVariant NetworkMediaModel::data( const QModelIndex& index, int role ) const
 
     switch ( role )
     {
-        case NETWORK_NAME:
-            return item->name;
-        case NETWORK_MRL:
-            return item->mainMrl;
         case NETWORK_INDEXED:
             return item->indexed;
         case NETWORK_CANINDEX:
             return item->canBeIndexed;
-        case NETWORK_TYPE:
-            return item->type;
-        case NETWORK_PROTOCOL:
-            return item->protocol;
         case NETWORK_TREE:
             return QVariant::fromValue( item->tree );
-        case NETWORK_ARTWORK:
+        case NETWORK_BASE_ARTWORK:
         {
             if (!item->artwork.isEmpty())
                 return item->artwork;
@@ -570,27 +557,24 @@ QVariant NetworkMediaModel::data( const QModelIndex& index, int role ) const
             return {};
         }
         default:
-            return {};
+            return basedata(*item, role);
     }
 }
 
 QHash<int, QByteArray> NetworkMediaModel::roleNames() const
 {
-    return {
-        { NETWORK_NAME, "name" },
-        { NETWORK_MRL, "mrl" },
-        { NETWORK_INDEXED, "indexed" },
-        { NETWORK_CANINDEX, "can_index" },
-        { NETWORK_TYPE, "type" },
-        { NETWORK_PROTOCOL, "protocol" },
-        { NETWORK_TREE, "tree" },
-        { NETWORK_ARTWORK, "artwork" },
-        { NETWORK_FILE_SIZE, "fileSizeRaw64" },
-        { NETWORK_FILE_MODIFIED, "fileModified" },
-        { NETWORK_MEDIA, "media" },
-        { NETWORK_MEDIA_PROGRESS, "progress" },
-        { NETWORK_MEDIA_DURATION, "duration" }
-    };
+    auto roles = NetworkBaseModel::roleNames();
+
+    roles[NETWORK_INDEXED] = "indexed";
+    roles[NETWORK_CANINDEX] = "can_index";
+    roles[NETWORK_TREE] = "tree";
+    roles[NETWORK_FILE_SIZE] = "fileSizeRaw64";
+    roles[NETWORK_FILE_MODIFIED] = "fileModified";
+    roles[NETWORK_MEDIA] = "media";
+    roles[NETWORK_MEDIA_PROGRESS] = "progress";
+    roles[NETWORK_MEDIA_DURATION] = "duration";
+
+    return roles;
 }
 
 Qt::ItemFlags NetworkMediaModel::flags( const QModelIndex& idx ) const


=====================================
modules/gui/qt/network/networkmediamodel.hpp
=====================================
@@ -30,7 +30,7 @@
 #include <vlc_cxx_helpers.hpp>
 
 #include "util/shared_input_item.hpp"
-#include "util/base_model.hpp"
+#include "networkbasemodel.hpp"
 
 #include <memory>
 
@@ -101,20 +101,15 @@ private:
 };
 
 class NetworkMediaModelPrivate;
-class NetworkMediaModel : public BaseModel
+class NetworkMediaModel : public NetworkBaseModel
 {
     Q_OBJECT
 
 public:
     enum Role {
-        NETWORK_NAME = Qt::UserRole + 1,
-        NETWORK_MRL,
-        NETWORK_INDEXED,
+        NETWORK_INDEXED = NETWORK_BASE_MAX,
         NETWORK_CANINDEX,
-        NETWORK_TYPE,
-        NETWORK_PROTOCOL,
         NETWORK_TREE,
-        NETWORK_ARTWORK,
         NETWORK_FILE_SIZE,
         NETWORK_FILE_MODIFIED,
         NETWORK_MEDIA,
@@ -122,19 +117,6 @@ public:
         NETWORK_MEDIA_DURATION,
     };
 
-    enum ItemType{
-        // qt version of input_item_type_e
-        TYPE_UNKNOWN = ITEM_TYPE_UNKNOWN,
-        TYPE_FILE,
-        TYPE_DIRECTORY,
-        TYPE_DISC,
-        TYPE_CARD,
-        TYPE_STREAM,
-        TYPE_PLAYLIST,
-        TYPE_NODE,
-    };
-    Q_ENUM( ItemType )
-
     Q_PROPERTY(MainCtx* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged)
     Q_PROPERTY(QVariant tree READ getTree WRITE setTree NOTIFY treeChanged)
     Q_PROPERTY(QVariantList path READ getPath NOTIFY pathChanged)


=====================================
modules/gui/qt/network/qml/BrowseTreeDisplay.qml
=====================================
@@ -94,24 +94,7 @@ MainViewLoader {
         defaultText:  qsTr("Unknown Share")
 
         coverProvider: function(index, data) {
-            function _baseUri(type) {
-                switch (type) {
-                case NetworkMediaModel.TYPE_DISC:
-                    return "qrc:///sd/disc.svg"
-                case NetworkMediaModel.TYPE_CARD:
-                    return "qrc:///sd/capture-card.svg"
-                case NetworkMediaModel.TYPE_STREAM:
-                    return "qrc:///sd/stream.svg"
-                case NetworkMediaModel.TYPE_PLAYLIST:
-                    return "qrc:///sd/playlist.svg"
-                case NetworkMediaModel.TYPE_FILE:
-                    return "qrc:///sd/file.svg"
-                default:
-                    return "qrc:///sd/directory.svg"
-                }
-            }
-
-            const fallbackImage = SVGColorImage.colorize(_baseUri(data.type))
+            const fallbackImage = SVGColorImage.colorize(data.artworkFallback)
                 .background(networkDragItem.colorContext.bg.secondary)
                 .color1(networkDragItem.colorContext.fg.primary)
                 .accent(networkDragItem.colorContext.accent)


=====================================
modules/gui/qt/network/qml/NetworkCustomCover.qml
=====================================
@@ -45,25 +45,6 @@ Item {
     // currently shown image
     property var _image: typeImage.visible ? typeImage : artwork
 
-
-    function _baseUri(type) {
-        switch (type) {
-        case NetworkMediaModel.TYPE_DISC:
-            return "qrc:///sd/disc.svg"
-        case NetworkMediaModel.TYPE_CARD:
-            return "qrc:///sd/capture-card.svg"
-        case NetworkMediaModel.TYPE_STREAM:
-            return "qrc:///sd/stream.svg"
-        case NetworkMediaModel.TYPE_PLAYLIST:
-            return "qrc:///sd/playlist.svg"
-        case NetworkMediaModel.TYPE_FILE:
-            return "qrc:///sd/file.svg"
-        default:
-            return "qrc:///sd/directory.svg"
-        }
-    }
-
-
     Widgets.ScaledImage {
         // failsafe cover, we show this while loading artwork or if loading fails
 
@@ -83,7 +64,7 @@ Item {
             if (!networkModel || !visible)
                 return ""
 
-            const img = SVGColorImage.colorize(_baseUri(networkModel.type))
+            const img = SVGColorImage.colorize(networkModel.artworkFallback)
                 .color1(root.color1)
                 .accent(root.accent)
 


=====================================
modules/gui/qt/network/qml/NetworkGridItem.qml
=====================================
@@ -49,24 +49,7 @@ Widgets.GridItem {
     cacheImage: true // we may have network thumbnail
 
     fallbackImage: {
-        const f = function(type) {
-            switch (type) {
-            case NetworkMediaModel.TYPE_DISC:
-                return "qrc:///sd/disc.svg"
-            case NetworkMediaModel.TYPE_CARD:
-                return "qrc:///sd/capture-card.svg"
-            case NetworkMediaModel.TYPE_STREAM:
-                return "qrc:///sd/stream.svg"
-            case NetworkMediaModel.TYPE_PLAYLIST:
-                return "qrc:///sd/playlist.svg"
-            case NetworkMediaModel.TYPE_FILE:
-                return "qrc:///sd/file.svg"
-            default:
-                return "qrc:///sd/directory.svg"
-            }
-        }
-
-        return SVGColorImage.colorize(f(model.type))
+        return SVGColorImage.colorize(model.artworkFallback)
                             .color1(root.colorContext.fg.primary)
                             .accent(root.colorContext.accent)
                             .uri()


=====================================
modules/gui/qt/network/standardpathmodel.cpp
=====================================
@@ -38,19 +38,10 @@ using MediaTreePtr = vlc_shared_data_ptr_type(vlc_media_tree_t,
                                               vlc_media_tree_Hold,
                                               vlc_media_tree_Release);
 
-struct StandardPathItem
+struct StandardPathItem : public NetworkBaseItem
 {
-    QString name;
-    QUrl    mrl;
-
-    QString protocol;
-
-    NetworkDeviceModel::ItemType type;
-
     SharedInputItem inputItem;
     MediaTreePtr tree;
-
-    QUrl artwork;
 };
 
 using StandardPathItemPtr =  std::shared_ptr<StandardPathItem>;
@@ -79,7 +70,7 @@ bool ascendingName(const StandardPathItemPtr& a,
 bool ascendingMrl(const StandardPathItemPtr& a,
                    const StandardPathItemPtr& b)
 {
-    return (QString::compare(a->mrl.toString(), b->mrl.toString(), Qt::CaseInsensitive) <= 0);
+    return (QString::compare(a->mainMrl.toString(), b->mainMrl.toString(), Qt::CaseInsensitive) <= 0);
 }
 
 bool descendingName(const StandardPathItemPtr& a,
@@ -91,7 +82,7 @@ bool descendingName(const StandardPathItemPtr& a,
 bool descendingMrl(const StandardPathItemPtr& a,
                    const StandardPathItemPtr& b)
 {
-    return (QString::compare(a->mrl.toString(), b->mrl.toString(), Qt::CaseInsensitive) >= 0);
+    return (QString::compare(a->mainMrl.toString(), b->mainMrl.toString(), Qt::CaseInsensitive) >= 0);
 }
 
 }
@@ -130,13 +121,13 @@ public:
         Q_Q(StandardPathModel);
         assert(m_qmlInitializing == false);
 #ifdef Q_OS_UNIX
-        addItem(QVLCUserDir(VLC_HOME_DIR), qtr("Home"), QUrl());
+        addItem(QVLCUserDir(VLC_HOME_DIR), qtr("Home"), {});
 #endif
-        addItem(QVLCUserDir(VLC_DESKTOP_DIR), qtr("Desktop"), QUrl());
-        addItem(QVLCUserDir(VLC_DOCUMENTS_DIR), qtr("Documents"), QUrl());
-        addItem(QVLCUserDir(VLC_MUSIC_DIR), qtr("Music"), QUrl());
-        addItem(QVLCUserDir(VLC_VIDEOS_DIR), qtr("Videos"), QUrl());
-        addItem(QVLCUserDir(VLC_DOWNLOAD_DIR), qtr("Download"), QUrl());
+        addItem(QVLCUserDir(VLC_DESKTOP_DIR), qtr("Desktop"), {});
+        addItem(QVLCUserDir(VLC_DOCUMENTS_DIR), qtr("Documents"), {});
+        addItem(QVLCUserDir(VLC_MUSIC_DIR), qtr("Music"), {});
+        addItem(QVLCUserDir(VLC_VIDEOS_DIR), qtr("Videos"), {});
+        addItem(QVLCUserDir(VLC_DOWNLOAD_DIR), qtr("Download"), {});
         //model is never updated, but this is still needed to fit the LocalListBaseModelPrivate requirements
         ++m_revision;
         m_loading = false;
@@ -152,14 +143,14 @@ public:
         return nullptr;
     }
 
-    void addItem(const QString & path, const QString & name, const QUrl & artwork)
+    void addItem(const QString & path, const QString & name, const QString& artwork)
     {
         QUrl url = QUrl::fromLocalFile(path);
 
         auto item = std::make_shared<StandardPathItem>();
 
         item->name = name;
-        item->mrl  = url;
+        item->mainMrl  = url;
         item->protocol = url.scheme();
         item->type = NetworkDeviceModel::TYPE_DIRECTORY;
 
@@ -200,7 +191,7 @@ public:
 // Ctor / dtor
 
 StandardPathModel::StandardPathModel(QObject * parent)
-    : BaseModel(new StandardPathModelPrivate(this), parent)
+    : NetworkBaseModel(new StandardPathModelPrivate(this), parent)
 {
 }
 
@@ -208,16 +199,10 @@ StandardPathModel::StandardPathModel(QObject * parent)
 
 QHash<int, QByteArray> StandardPathModel::roleNames() const /* override */
 {
-    return
-    {
-        { PATH_NAME, "name" },
-        { PATH_MRL, "mrl" },
-        { PATH_PROTOCOL, "protocol" },
-        { PATH_TYPE, "type" },
-        { PATH_SOURCE, "source" },
-        { PATH_TREE, "tree" },
-        { PATH_ARTWORK, "artwork" }
-    };
+    auto roles = NetworkBaseModel::roleNames();
+    roles[PATH_SOURCE] = "source";
+    roles[PATH_TREE] = "tree";
+    return roles;
 }
 
 QVariant StandardPathModel::data(const QModelIndex & index, int role) const /* override */
@@ -230,19 +215,9 @@ QVariant StandardPathModel::data(const QModelIndex & index, int role) const /* o
 
     switch (role)
     {
-        case PATH_NAME:
-            return item->name;
-        case PATH_MRL:
-            return item->mrl;
-        case PATH_PROTOCOL:
-            return item->protocol;
-        case PATH_TYPE:
-            return item->type;
         case PATH_TREE:
             return QVariant::fromValue(NetworkTreeItem(item->tree, item->inputItem.get()));
-        case PATH_ARTWORK:
-            return item->artwork;
         default:
-            return QVariant();
+            return NetworkBaseModel::basedata(*item, role);
     }
 }


=====================================
modules/gui/qt/network/standardpathmodel.hpp
=====================================
@@ -26,10 +26,10 @@
 #endif
 
 // VLC includes
-#include "util/base_model.hpp"
+#include "networkbasemodel.hpp"
 
 class StandardPathModelPrivate;
-class StandardPathModel : public BaseModel
+class StandardPathModel : public NetworkBaseModel
 {
     Q_OBJECT
 
@@ -37,11 +37,7 @@ public: // Enums
     // NOTE: Roles should be aligned with the NetworkDeviceModel.
     enum Role
     {
-        PATH_NAME = Qt::UserRole + 1,
-        PATH_MRL,
-        PATH_TYPE,
-        PATH_PROTOCOL,
-        PATH_SOURCE,
+        PATH_SOURCE = NetworkBaseModel::NETWORK_BASE_MAX,
         PATH_TREE,
         PATH_ARTWORK
     };



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/afa6e6c244252d12e66b792f82d4fb60d5f13439...140f7700e3b96da446e271e49a8fb6f984dfb763

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/afa6e6c244252d12e66b792f82d4fb60d5f13439...140f7700e3b96da446e271e49a8fb6f984dfb763
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list