qt: medialib: define a super-type for list items
[vlc.git] / modules / gui / qt / medialibrary / mlurlmodel.hpp
blob4a28aa0f3a6ca9b28128131aa9f05d9a14b3b438
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 MLURLMODEL_H
20 #define MLURLMODEL_H
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include <QObject>
27 #include "mlbasemodel.hpp"
29 #include <vlc_media_library.h>
30 #include "mlhelper.hpp"
31 #include "mlqmltypes.hpp"
33 class MLUrl : public MLItem {
34 public:
35 MLUrl( const vlc_ml_media_t *_data );
37 MLUrl( const MLUrl& url );
39 QString getUrl() const;
40 QString getLastPlayedDate() const;
42 MLUrl *clone() const;
44 private:
45 QString m_url;
46 QString m_lastPlayedDate;
49 class MLUrlModel : public MLSlidingWindowModel<MLUrl>
51 Q_OBJECT
53 public:
54 enum Roles {
55 URL_ID = Qt::UserRole + 1,
56 URL_URL,
57 URL_LAST_PLAYED_DATE
59 Q_ENUM(Roles);
61 explicit MLUrlModel(QObject *parent = nullptr);
63 virtual ~MLUrlModel() = default;
65 QVariant data(const QModelIndex &index, int role) const override;
66 QHash<int, QByteArray> roleNames() const override;
68 Q_INVOKABLE void addAndPlay( const QString& url );
70 protected:
71 ListCacheLoader<std::unique_ptr<MLUrl>> *createLoader() const override;
73 private:
74 vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
75 virtual void onVlcMlEvent( const MLEvent &event ) override;
77 struct Loader : public BaseLoader
79 Loader(const MLUrlModel &model) : BaseLoader(model) {}
80 size_t count() const override;
81 std::vector<std::unique_ptr<MLUrl>> load(size_t index, size_t count) const override;
85 #endif // MLURLMODEL_H