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
43 // qt version of input_item_type_e
44 TYPE_UNKNOWN
= ITEM_TYPE_UNKNOWN
,
56 // qt version of input_item_type_e
58 CAT_DEVICES
= SD_CAT_DEVICES
,
66 Q_PROPERTY(QmlMainContext
* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged
)
67 Q_PROPERTY(SDCatType sd_source READ getSdSource WRITE setSdSource NOTIFY sdSourceChanged
)
71 NetworkDeviceModel( QObject
* parent
= nullptr );
73 QVariant
data(const QModelIndex
& index
, int role
) const override
;
74 QHash
<int, QByteArray
> roleNames() const override
;
75 int rowCount(const QModelIndex
& parent
) const override
;
77 void setCtx(QmlMainContext
* ctx
);
78 void setSdSource(SDCatType s
);
80 inline QmlMainContext
* getCtx() { return m_ctx
; }
81 inline SDCatType
getSdSource() { return m_sdSource
; }
83 Q_INVOKABLE
bool addToPlaylist( int index
);
84 Q_INVOKABLE
bool addToPlaylist(const QVariantList
& itemIdList
);
85 Q_INVOKABLE
bool addAndPlay( int index
);
86 Q_INVOKABLE
bool addAndPlay(const QVariantList
& itemIdList
);
90 void sdSourceChanged();
93 using MediaSourcePtr
= vlc_shared_data_ptr_type(vlc_media_source_t
,
94 vlc_media_source_Hold
, vlc_media_source_Release
);
96 using InputItemPtr
= vlc_shared_data_ptr_type(input_item_t
,
104 std::vector
<QUrl
> mrls
;
107 MediaSourcePtr mediaSource
;
108 InputItemPtr inputItem
;
112 bool initializeMediaSources();
113 void onItemCleared( MediaSourcePtr mediaSource
, input_item_node_t
* node
) override
;
114 void onItemAdded( MediaSourcePtr mediaSource
, input_item_node_t
* parent
, input_item_node_t
*const children
[], size_t count
) override
;
115 void onItemRemoved( MediaSourcePtr mediaSource
, input_item_node_t
* node
, input_item_node_t
*const children
[], size_t count
) override
;
116 inline void onItemPreparseEnded( MediaSourcePtr
, input_item_node_t
*, enum input_item_preparse_status
) override
{}
118 void refreshDeviceList(MediaSourcePtr mediaSource
, input_item_node_t
* const children
[], size_t count
, bool clear
);
121 std::vector
<Item
> m_items
;
122 QmlMainContext
* m_ctx
= nullptr;
123 vlc_medialibrary_t
* m_ml
= nullptr;
124 SDCatType m_sdSource
= CAT_UNDEFINED
;
126 std::vector
<std::unique_ptr
<NetworkSourceListener
>> m_listeners
;
129 #endif // MLNETWORKDEVICEMODEL_HPP