1 /*****************************************************************************
2 * Copyright (C) 2021 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 MLPLAYLISTMODEL_HPP
20 #define MLPLAYLISTMODEL_HPP
22 // MediaLibrary includes
23 #include "mlbasemodel.hpp"
25 class MLPlaylistModel
: public MLBaseModel
32 MEDIA_ID
= Qt::UserRole
+ 1,
45 MEDIA_TITLE_FIRST_SYMBOL
,
49 explicit MLPlaylistModel(QObject
* parent
= nullptr);
52 Q_INVOKABLE
void insert(const QVariantList
& items
, int at
);
54 Q_INVOKABLE
void move(const QModelIndexList
& indexes
, int to
);
56 Q_INVOKABLE
void remove(const QModelIndexList
& indexes
);
58 public: // QAbstractItemModel implementation
59 QHash
<int, QByteArray
> roleNames() const override
;
61 QVariant
data(const QModelIndex
& index
, int role
= Qt::DisplayRole
) const override
;
63 protected: // MLBaseModel implementation
64 vlc_ml_sorting_criteria_t
roleToCriteria(int role
) const override
;
66 vlc_ml_sorting_criteria_t
nameToCriteria(QByteArray name
) const override
;
68 QByteArray
criteriaToName(vlc_ml_sorting_criteria_t criteria
) const override
;
70 ListCacheLoader
<std::unique_ptr
<MLItem
>> * createLoader() const override
;
73 QList
<int> getRows(const QModelIndexList
& indexes
) const;
75 private: // MLBaseModel implementation
76 void onVlcMlEvent(const MLEvent
& event
) override
;
79 struct Loader
: public MLBaseModel::BaseLoader
81 Loader(const MLPlaylistModel
& model
);
83 size_t count() const override
;
85 std::vector
<std::unique_ptr
<MLItem
>> load(size_t index
, size_t count
) const override
;
89 #endif // MLPLAYLISTMODEL_HPP