1 /*****************************************************************************
2 * Copyright (C) 2019 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 MLNETWORKDEVICEMODEL_HPP
20 #define MLNETWORKDEVICEMODEL_HPP
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"
38 class NetworkDeviceModel
: public QAbstractListModel
, public NetworkSourceListener::SourceListenerCb
44 NETWORK_NAME
= Qt::UserRole
+ 1,
54 // qt version of input_item_type_e
55 TYPE_UNKNOWN
= ITEM_TYPE_UNKNOWN
,
67 // qt version of input_item_type_e
69 CAT_DEVICES
= SD_CAT_DEVICES
,
77 Q_PROPERTY(QmlMainContext
* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged
)
78 Q_PROPERTY(SDCatType sd_source READ getSdSource WRITE setSdSource NOTIFY sdSourceChanged
)
79 Q_PROPERTY(QString name READ getName NOTIFY nameChanged
)
80 Q_PROPERTY(QString source_name READ getSourceName WRITE setSourceName NOTIFY sourceNameChanged
)
81 Q_PROPERTY(int count READ getCount NOTIFY countChanged
)
84 NetworkDeviceModel( QObject
* parent
= nullptr );
86 QVariant
data(const QModelIndex
& index
, int role
) const override
;
87 QHash
<int, QByteArray
> roleNames() const override
;
88 int rowCount(const QModelIndex
& parent
= {}) const override
;
90 void setCtx(QmlMainContext
* ctx
);
91 void setSdSource(SDCatType s
);
92 void setSourceName(const QString
& sourceName
);
94 inline QmlMainContext
* getCtx() { return m_ctx
; }
95 inline SDCatType
getSdSource() { return m_sdSource
; }
96 inline QString
getName() { return m_name
; }
97 inline QString
getSourceName() { return m_sourceName
; }
101 Q_INVOKABLE
bool insertIntoPlaylist( const QModelIndexList
& itemIdList
, ssize_t playlistIndex
);
102 Q_INVOKABLE
bool addToPlaylist( int index
);
103 Q_INVOKABLE
bool addToPlaylist(const QVariantList
& itemIdList
);
104 Q_INVOKABLE
bool addToPlaylist(const QModelIndexList
& itemIdList
);
105 Q_INVOKABLE
bool addAndPlay( int index
);
106 Q_INVOKABLE
bool addAndPlay(const QVariantList
& itemIdList
);
107 Q_INVOKABLE
bool addAndPlay(const QModelIndexList
& itemIdList
);
109 Q_INVOKABLE QMap
<QString
, QVariant
> getDataAt(int index
);
113 void sdSourceChanged();
114 void sourceNameChanged();
119 using MediaSourcePtr
= vlc_shared_data_ptr_type(vlc_media_source_t
,
120 vlc_media_source_Hold
, vlc_media_source_Release
);
122 using InputItemPtr
= vlc_shared_data_ptr_type(input_item_t
,
130 std::vector
<QUrl
> mrls
;
133 MediaSourcePtr mediaSource
;
134 InputItemPtr inputItem
;
138 bool initializeMediaSources();
139 void onItemCleared( MediaSourcePtr mediaSource
, input_item_node_t
* node
) override
;
140 void onItemAdded( MediaSourcePtr mediaSource
, input_item_node_t
* parent
, input_item_node_t
*const children
[], size_t count
) override
;
141 void onItemRemoved( MediaSourcePtr mediaSource
, input_item_node_t
* node
, input_item_node_t
*const children
[], size_t count
) override
;
142 inline void onItemPreparseEnded( MediaSourcePtr
, input_item_node_t
*, enum input_item_preparse_status
) override
{}
144 void refreshDeviceList(MediaSourcePtr mediaSource
, input_item_node_t
* const children
[], size_t count
, bool clear
);
147 std::vector
<Item
> m_items
;
148 QmlMainContext
* m_ctx
= nullptr;
149 vlc_medialibrary_t
* m_ml
= nullptr;
150 SDCatType m_sdSource
= CAT_UNDEFINED
;
151 QString m_sourceName
; // '*' -> all sources
152 QString m_name
; // source long name
154 std::vector
<std::unique_ptr
<NetworkSourceListener
>> m_listeners
;
157 #endif // MLNETWORKDEVICEMODEL_HPP