qt: medialib: implement separate data loaders
[vlc.git] / modules / gui / qt / medialibrary / mlalbumtrackmodel.hpp
blobe494b597cb28dd0eaad7582894580c57b50b5707
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 MLTRACKMODEL_HPP
20 #define MLTRACKMODEL_HPP
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include <QObject>
27 #include "mlbasemodel.hpp"
28 #include "mlalbumtrack.hpp"
31 class MLAlbumTrackModel : public MLSlidingWindowModel<MLAlbumTrack>
33 Q_OBJECT
35 public:
36 enum Roles {
37 TRACK_ID = Qt::UserRole + 1,
38 TRACK_TITLE,
39 TRACK_COVER,
40 TRACK_NUMBER,
41 TRACK_DISC_NUMBER,
42 TRACK_DURATION,
43 TRACK_DURATION_SHORT,
44 TRACK_ALBUM,
45 TRACK_ARTIST,
47 TRACK_TITLE_FIRST_SYMBOL,
48 TRACK_ALBUM_FIRST_SYMBOL,
49 TRACK_ARTIST_FIRST_SYMBOL,
52 public:
53 explicit MLAlbumTrackModel(QObject *parent = nullptr);
55 virtual ~MLAlbumTrackModel() = default;
57 QVariant data(const QModelIndex &index, int role) const override;
58 QHash<int, QByteArray> roleNames() const override;
60 protected:
61 ListCacheLoader<std::unique_ptr<MLAlbumTrack>> *createLoader() const override;
63 private:
64 vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
65 vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const override;
66 QByteArray criteriaToName(vlc_ml_sorting_criteria_t criteria) const override;
67 virtual void onVlcMlEvent( const MLEvent &event ) override;
69 static QHash<QByteArray, vlc_ml_sorting_criteria_t> M_names_to_criteria;
71 struct Loader : public BaseLoader
73 Loader(const MLAlbumTrackModel &model) : BaseLoader(model) {}
74 size_t count() const override;
75 std::vector<std::unique_ptr<MLAlbumTrack>> load(size_t index, size_t count) const override;
78 #endif // MLTRACKMODEL_HPP