qt: add functions to insert into playlist in network models
[vlc.git] / modules / gui / qt / network / networksourcesmodel.hpp
blob3f0fe9aeb00a41633f89796d2205db58a45884a8
1 /*****************************************************************************
2 * Copyright (C) 2020 VLC authors and VideoLAN
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * ( at your option ) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17 *****************************************************************************/
19 #ifndef MLNetworkSourcesModel_HPP
20 #define MLNetworkSourcesModel_HPP
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include <QAbstractListModel>
28 #include <vlc_media_library.h>
29 #include <vlc_media_source.h>
30 #include <vlc_threads.h>
31 #include <vlc_cxx_helpers.hpp>
33 #include <util/qml_main_context.hpp>
34 #include "networksourcelistener.hpp"
36 #include <memory>
38 class NetworkSourcesModel : public QAbstractListModel
40 Q_OBJECT
42 Q_PROPERTY(QmlMainContext* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged)
43 Q_PROPERTY(int count READ getCount NOTIFY countChanged)
45 public:
46 enum Role {
47 SOURCE_NAME = Qt::UserRole + 1,
48 SOURCE_LONGNAME,
49 SOURCE_TYPE,
50 SOURCE_ARTWORK
52 Q_ENUM(Role);
54 enum ItemType {
55 TYPE_DUMMY = -1, // provided for UI for entry "Add a service"
56 TYPE_SOURCE = 0
58 Q_ENUM(ItemType);
60 NetworkSourcesModel( QObject* parent = nullptr );
62 QVariant data(const QModelIndex& index, int role) const override;
63 QHash<int, QByteArray> roleNames() const override;
64 int rowCount(const QModelIndex& parent = {}) const override;
66 void setCtx(QmlMainContext* ctx);
68 inline QmlMainContext* getCtx() { return m_ctx; }
70 int getCount() const;
72 Q_INVOKABLE QMap<QString, QVariant> getDataAt(int index);
74 signals:
75 void ctxChanged();
76 void countChanged();
78 private:
79 struct Item
81 QString name;
82 QString longName;
83 QUrl artworkUrl;
86 bool initializeMediaSources();
88 private:
89 std::vector<Item> m_items;
90 QmlMainContext* m_ctx = nullptr;
91 vlc_medialibrary_t* m_ml = nullptr;
92 services_discovery_category_e m_sdSource = services_discovery_category_e::SD_CAT_INTERNET;
95 #endif // MLNetworkSourcesModel_HPP