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