MythTV master
galleryviews.h
Go to the documentation of this file.
1
11#ifndef GALLERYVIEWS_H
12#define GALLERYVIEWS_H
13
14#include <utility>
15
16#include <QSet>
17#include <QVector>
18
19// MythTV headers
21
22
24enum SlideOrderType : std::uint8_t {
27 kRandom = 2,
28 kSeasonal = 3
29};
30
31
33using WeightList = QVector<double>;
34
35
37class MarkedFiles : public QSet<int>
38{
39public:
40 MarkedFiles() = default;
41 void Initialise(int id) { m_valid = true; m_parent = id; clear();}
42 void Clear() { m_valid = false; clear(); }
43 bool IsFor(int id) const { return m_valid && m_parent == id; }
44 void Add(const ImageIdList& newIds);
45 void Add(int id) { insert(id); }
46 void Invert(const ImageIdList& all);
47
48private:
49 bool m_valid {false};
50 int m_parent {0};
51};
52
53
56{
57public:
58 MenuSubjects() = default;
59 MenuSubjects(const ImagePtrK& selection, ssize_t childCount,
60 MarkedFiles &marked, MarkedFiles &prevMarked,
61 bool hiddenMarked, bool unhiddenMarked)
62 : m_selected(selection),
63 m_selectedMarked(selection && marked.contains(selection->m_id)),
64 m_markedId(marked.values()), m_prevMarkedId(prevMarked.values()),
65 m_childCount(childCount),
66 m_hiddenMarked(hiddenMarked), m_unhiddenMarked(unhiddenMarked)
67 {}
68
70 bool m_selectedMarked {false};
73 ssize_t m_childCount {0};
74 bool m_hiddenMarked {false};
75 bool m_unhiddenMarked {false};
76};
77
80{
81public:
82 // Default constructor for QHash 'undefined entry'
83 FileCacheEntry() = default;
84 FileCacheEntry(int parent, QString url, QString thumbUrl)
85 : m_parent(parent), m_url(std::move(url)), m_thumbUrl(std::move(thumbUrl)) {}
86
87 QString ToString(int id) const
88 { return QString("File %1 Parent %2").arg(id).arg(m_parent); }
89
91 QString m_url;
92 QString m_thumbUrl;
93};
94
95
102{
103public:
104 explicit FlatView(SlideOrderType order)
105 : m_order(order), m_mgr(ImageManagerFe::getInstance()) {}
106 virtual ~FlatView() { Clear(); }
107
108 int GetParentId() const { return m_parentId; }
109 ImageListK GetAllNodes() const;
110 ImagePtrK GetSelected() const;
111 ImagePtrK HasNext(int inc) const;
112 ImagePtrK HasPrev(int inc) const;
113 ImagePtrK Next(int inc);
114 ImagePtrK Prev(int inc);
115 QString GetPosition() const;
116 bool Select(int id, int fallback = 0);
117 virtual bool LoadFromDb(int parentId);
118 QStringList ClearImage(int id, bool remove = false);
119 void ClearCache();
120 bool Update(int id);
121 void Rotate(int id);
122 void Clear(bool resetParent = true);
123
124 QString GetCachedThumbUrl(int id) const
125 { return m_fileCache.value(id).m_thumbUrl; }
126
127protected:
129
130 void Populate(ImageList &files);
131 void Cache(int id, int parent, const QString &url, const QString &thumb);
132
133 int m_parentId {-1};
136 QHash<int, ImagePtrK> m_images;
138 int m_active {0};
139
141 QHash<int, FileCacheEntry> m_fileCache;
142};
143
144
149{
150public:
151 DirCacheEntry() = default;
152 DirCacheEntry(int parentId, int dirs, int files,
153 QList<ThumbPair> thumbs, int thumbCount)
154 : m_parent(parentId), m_thumbCount(thumbCount),
155 m_dirCount(dirs), m_fileCount(files), m_thumbs(std::move(thumbs)) {}
156
157 QString ToString(int id) const;
158
159 int m_parent {0};
161 int m_dirCount {-1};
162 int m_fileCount {-1};
163 QList<ThumbPair> m_thumbs;
164};
165
166
174{
175public:
176 explicit DirectoryView(SlideOrderType order);
177
179 { return m_sequence.isEmpty() ? ImagePtrK() : m_images.value(m_sequence.at(0)); }
180
181 QString GetPosition() const;
182 bool LoadFromDb(int parentId) override; // FlatView
183 void Clear(bool resetParent = true);
185 QStringList RemoveImage(int id, bool deleted = false);
186 void ClearCache();
187 void MarkAll();
188 void Mark(int id, bool mark);
189 void InvertMarked();
190 void ClearMarked();
191 bool IsMarked(int id) const
192 { return m_marked.contains(id) || m_prevMarked.contains(id); }
193
194protected:
195 void SetDirectory(int newParent);
196 void LoadDirThumbs(ImageItem &parent, int thumbsNeeded, int level = 0);
197 void PopulateThumbs(ImageItem &parent, int thumbsNeeded,
198 const ImageList &files, const ImageList &dirs,
199 int level = 0);
200 ImageIdList GetChildren() const { return m_sequence.mid(1); }
201 bool PopulateFromCache(ImageItem &dir, int required);
202 void Cache(ImageItemK &dir, int thumbCount);
203
206
208 QHash<int, DirCacheEntry> m_dirCache;
209};
210
211
217class TreeView : public FlatView
218{
219public:
220 explicit TreeView(SlideOrderType order) : FlatView(order) {}
221
222 bool LoadFromDb(int parentId) override; // FlatView
223};
224
225
226#endif // GALLERYVIEWS_H
Records dir info for every displayed dir.
Definition: galleryviews.h:149
QString ToString(int id) const
DirCacheEntry()=default
DirCacheEntry(int parentId, int dirs, int files, QList< ThumbPair > thumbs, int thumbCount)
Definition: galleryviews.h:152
QList< ThumbPair > m_thumbs
Definition: galleryviews.h:163
A datastore of images for display by a screen. Provides an ordered list of dirs & images from a singl...
Definition: galleryviews.h:174
void LoadDirThumbs(ImageItem &parent, int thumbsNeeded, int level=0)
Populate thumbs for a dir.
ImagePtrK GetParent() const
Definition: galleryviews.h:178
QString GetPosition() const
Get positional status.
void ClearMarked()
Unmark all items.
void Clear(bool resetParent=true)
Resets view.
bool PopulateFromCache(ImageItem &dir, int required)
Retrieve cached dir, if available.
MenuSubjects GetMenuSubjects()
Determine current selection, markings & various info to support menu display.
void PopulateThumbs(ImageItem &parent, int thumbsNeeded, const ImageList &files, const ImageList &dirs, int level=0)
Populate directory stats & thumbnails recursively from database as follows: Use user cover,...
QHash< int, DirCacheEntry > m_dirCache
Caches displayed image dirs.
Definition: galleryviews.h:208
DirectoryView(SlideOrderType order)
Constructs a view of images & directories that can be marked.
bool IsMarked(int id) const
Definition: galleryviews.h:191
void MarkAll()
Mark all images/dirs.
bool LoadFromDb(int parentId) override
Populate view from database as images/subdirs of a directory. View is ordered: Parent dir,...
void ClearCache()
Clears UI cache.
MarkedFiles m_prevMarked
Marked items in previous dir.
Definition: galleryviews.h:205
ImageIdList GetChildren() const
Definition: galleryviews.h:200
QStringList RemoveImage(int id, bool deleted=false)
Clear file/dir and all its ancestors from UI cache so that ancestor thumbnails are recalculated....
void InvertMarked()
Mark all unmarked items, unmark all marked items.
MarkedFiles m_marked
Marked items in current dir/view.
Definition: galleryviews.h:204
void SetDirectory(int newParent)
Manage markings on tree navigation.
void Cache(ImageItemK &dir, int thumbCount)
Cache displayed dir.
void Mark(int id, bool mark)
Mark/unmark an image/dir.
Records info of displayed image files to enable clean-up of the UI image cache.
Definition: galleryviews.h:80
FileCacheEntry(int parent, QString url, QString thumbUrl)
Definition: galleryviews.h:84
QString m_thumbUrl
Definition: galleryviews.h:92
QString ToString(int id) const
Definition: galleryviews.h:87
FileCacheEntry()=default
A datastore of images for display by a screen.
Definition: galleryviews.h:102
void Cache(int id, int parent, const QString &url, const QString &thumb)
Cache image properties to optimize UI.
virtual ~FlatView()
Definition: galleryviews.h:106
bool Update(int id)
Updates view with images that have been updated.
int m_parentId
Definition: galleryviews.h:133
QStringList ClearImage(int id, bool remove=false)
Clear file from UI cache and optionally from view.
SlideOrderType m_order
Definition: galleryviews.h:134
int GetParentId() const
Definition: galleryviews.h:108
void ClearCache()
Clears UI cache.
ImagePtrK Prev(int inc)
Decrements iterator and returns previous image. Wraps at start.
FlatView(SlideOrderType order)
Definition: galleryviews.h:104
bool Select(int id, int fallback=0)
Selects first occurrence of an image.
ImageManagerFe & m_mgr
Definition: galleryviews.h:135
void Populate(ImageList &files)
Fills view with Db images, re-ordering them as required.
ImagePtrK HasNext(int inc) const
Peeks at next image in view but does not advance iterator.
void Clear(bool resetParent=true)
Reset view.
int m_active
Sequence index of current selected image.
Definition: galleryviews.h:138
ImagePtrK Next(int inc)
Advance iterator and return next image, wrapping if necessary. Regenerates unordered views on wrap.
QHash< int, FileCacheEntry > m_fileCache
Caches displayed image files.
Definition: galleryviews.h:141
ImageIdList m_sequence
The sequence in which to display images.
Definition: galleryviews.h:137
QString GetPosition() const
Get positional status.
ImagePtrK GetSelected() const
Get current selection.
virtual bool LoadFromDb(int parentId)
Populate view with database images from a directory.
ImageListK GetAllNodes() const
Get all images/dirs in view.
ImagePtrK HasPrev(int inc) const
Peeks at previous image in view but does not decrement iterator.
QHash< int, ImagePtrK > m_images
Image objects currently displayed.
Definition: galleryviews.h:136
void Rotate(int id)
Rotate view so that starting image is at front.
static WeightList CalculateSeasonalWeights(ImageList &files)
This method calculates a weight for the item based on how closely it was taken to the current time of...
QString GetCachedThumbUrl(int id) const
Definition: galleryviews.h:124
Represents a picture, video or directory.
Definition: imagetypes.h:69
The image manager for use by Frontends.
Definition: imagemanager.h:456
A container of images/dirs that have been marked.
Definition: galleryviews.h:38
void Initialise(int id)
Definition: galleryviews.h:41
bool IsFor(int id) const
Definition: galleryviews.h:43
void Add(const ImageIdList &newIds)
void Invert(const ImageIdList &all)
void Clear()
Definition: galleryviews.h:42
void Add(int id)
Definition: galleryviews.h:45
MarkedFiles()=default
A snapshot of current selection, markings & dir info when menu is invoked.
Definition: galleryviews.h:56
ImageIdList m_prevMarkedId
Ids of marked items in previous dir.
Definition: galleryviews.h:72
MenuSubjects()=default
ImageIdList m_markedId
Ids of all marked items.
Definition: galleryviews.h:71
MenuSubjects(const ImagePtrK &selection, ssize_t childCount, MarkedFiles &marked, MarkedFiles &prevMarked, bool hiddenMarked, bool unhiddenMarked)
Definition: galleryviews.h:59
ssize_t m_childCount
Number of images & dirs excl parent.
Definition: galleryviews.h:73
bool m_hiddenMarked
Is any marked item hidden ?
Definition: galleryviews.h:74
ImagePtrK m_selected
Selected item.
Definition: galleryviews.h:69
bool m_selectedMarked
Is selected item marked ?
Definition: galleryviews.h:70
bool m_unhiddenMarked
Is any marked item unhidden ?
Definition: galleryviews.h:75
A datastore of images for display by a screen. Provides an ordered list of images (no dirs) from a di...
Definition: galleryviews.h:218
TreeView(SlideOrderType order)
Definition: galleryviews.h:220
bool LoadFromDb(int parentId) override
Populate view from database as images of a directory sub-tree. Default order of a tree is depth-first...
SlideOrderType
Order of images in slideshow.
Definition: galleryviews.h:24
@ kSeasonal
Biased random selection so that images are more likely to appear on anniversaries.
Definition: galleryviews.h:28
@ kShuffle
Each image appears exactly once, but in random order.
Definition: galleryviews.h:26
@ kRandom
Random selection from view. An image may be absent or appear multiple times.
Definition: galleryviews.h:27
@ kOrdered
Ordered as per user setting GallerySortOrder.
Definition: galleryviews.h:25
QVector< double > WeightList
Seasonal weightings for images in a view.
Definition: galleryviews.h:33
Manages a collection of images.
QVector< ImagePtr > ImageList
Definition: imagetypes.h:160
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:166
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
static constexpr int GALLERY_DB_ID
Definition: imagetypes.h:27
QList< int > ImageIdList
Definition: imagetypes.h:60
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:949
STL namespace.