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 ML_RECENTS_MODEL_H
20 #define ML_RECENTS_MODEL_H
26 #include <vlc_common.h>
27 #include <vlc_media_library.h>
29 #include "mlbasemodel.hpp"
30 #include "mlvideo.hpp"
37 MLRecentMedia( const vlc_ml_media_t
*_data
);
39 MLRecentMedia( const MLRecentMedia
& url
);
41 inline QUrl
getUrl() const { return m_url
; }
42 inline QDateTime
getLastPlayedDate() const { return m_lastPlayedDate
; }
43 inline MLParentId
getId() const { return m_id
; }
45 MLRecentMedia
*clone() const;
50 QDateTime m_lastPlayedDate
;
53 class MLRecentsModel
: public MLSlidingWindowModel
<MLRecentMedia
>
56 Q_PROPERTY(int numberOfItemsToShow READ getNumberOfItemsToShow WRITE setNumberOfItemsToShow
)
60 RECENT_MEDIA_ID
= Qt::UserRole
+ 1,
62 RECENT_MEDIA_LAST_PLAYED_DATE
66 explicit MLRecentsModel( QObject
* parent
= nullptr );
67 virtual ~MLRecentsModel() = default;
69 QVariant
data( const QModelIndex
& index
, int role
) const override
;
70 QHash
<int, QByteArray
> roleNames() const override
;
71 int m_numberOfItemsToShow
= -1;
73 Q_INVOKABLE
void clearHistory();
75 void setNumberOfItemsToShow(int);
76 int getNumberOfItemsToShow() const;
79 ListCacheLoader
<std::unique_ptr
<MLRecentMedia
>> *createLoader() const override
;
82 vlc_ml_sorting_criteria_t
roleToCriteria( int /* role */ ) const override
{
83 return VLC_ML_SORTING_DEFAULT
;
85 vlc_ml_sorting_criteria_t
nameToCriteria( QByteArray
/* name */ ) const override
{
86 return VLC_ML_SORTING_DEFAULT
;
88 virtual void onVlcMlEvent( const MLEvent
&event
) override
;
90 struct Loader
: public BaseLoader
92 Loader(const MLRecentsModel
&model
, int numberOfItemsToShow
)
94 , m_numberOfItemsToShow(numberOfItemsToShow
)
98 size_t count() const override
;
99 std::vector
<std::unique_ptr
<MLRecentMedia
>> load(size_t index
, size_t count
) const override
;
102 int m_numberOfItemsToShow
;
106 #endif // ML_RECENTS_MODEL_H