MythTV  master
Go to the documentation of this file.
14 #include <utility>
16 // MythTV headers
17 #include "imagemanager.h"
22  kOrdered = 0,
23  kShuffle = 1,
24  kRandom = 2,
25  kSeasonal = 3
26 };
30 using WeightList = QVector<double>;
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) { return m_valid && m_parent == id; }
41  void Add(const ImageIdList& newIds) { unite(newIds.toSet()); }
42  void Add(int id) { insert(id); }
43  void Invert(const ImageIdList& all) { QSet tmp(all.toSet() - *this); swap(tmp); }
45 private:
46  bool m_valid {false};
47  int m_parent {0};
48 };
53 {
54 public:
55  MenuSubjects() = default;
56  MenuSubjects(const ImagePtrK& selection, int 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  {}
66  ImagePtrK m_selected {nullptr};
67  bool m_selectedMarked {false};
70  int m_childCount {0};
71  bool m_hiddenMarked {false};
72  bool m_unhiddenMarked {false};
73 };
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)) {}
84  QString ToString(int id)
85  { return QString("File %1 Parent %2").arg(id).arg(m_parent); }
88  QString m_url;
89  QString m_thumbUrl;
90 };
98 class FlatView
99 {
100 public:
101  explicit FlatView(SlideOrderType order)
102  : m_order(order), m_mgr(ImageManagerFe::getInstance()) {}
103  virtual ~FlatView() { Clear(); }
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);
121  QString GetCachedThumbUrl(int id) const
122  { return m_fileCache.value(id).m_thumbUrl; }
124 protected:
127  void Populate(ImageList &files);
128  void Cache(int id, int parent, const QString &url, const QString &thumb);
130  int m_parentId {-1};
133  QHash<int, ImagePtrK> m_images;
135  int m_active {0};
138  QHash<int, FileCacheEntry> m_fileCache;
139 };
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)) {}
154  QString ToString(int id) const;
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 };
170 class DirectoryView : public FlatView
171 {
172 public:
173  explicit DirectoryView(SlideOrderType order);
176  { return m_sequence.isEmpty() ? ImagePtrK() : m_images.value(; }
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); }
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);
205  QHash<int, DirCacheEntry> m_dirCache;
206 };
214 class TreeView : public FlatView
215 {
216 public:
217  explicit TreeView(SlideOrderType order) : FlatView(order) {}
219  bool LoadFromDb(int parentId) override; // FlatView
220 };
223 #endif // GALLERYVIEWS_H
ImageIdList m_markedId
Ids of all marked items.
Definition: galleryviews.h:68
ImagePtrK m_selected
Selected item.
Definition: galleryviews.h:66
DirectoryView(SlideOrderType order)
Constructs a view of images & directories that can be marked.
void Invert(const ImageIdList &all)
Definition: galleryviews.h:43
void Cache(int id, int parent, const QString &url, const QString &thumb)
Cache image properties to optimize UI.
ImageIdList m_sequence
The sequence in which to display images.
Definition: galleryviews.h:134
A datastore of images for display by a screen.
Definition: galleryviews.h:98
QHash< int, FileCacheEntry > m_fileCache
Caches displayed image files.
Definition: galleryviews.h:138
MenuSubjects(const ImagePtrK &selection, int childCount, MarkedFiles &marked, MarkedFiles &prevMarked, bool hiddenMarked, bool unhiddenMarked)
Definition: galleryviews.h:56
bool Select(int id, int fallback=0)
Selects first occurrence of an image.
Each image appears exactly once, but in random order.
Definition: galleryviews.h:23
void ClearCache()
Clears UI cache.
QString GetPosition() const
Get positional status.
bool IsFor(int id)
Definition: galleryviews.h:40
FileCacheEntry(int parent, QString url, QString thumbUrl)
Definition: galleryviews.h:81
QString ToString(int id) const
The image manager for use by Frontends.
Definition: imagemanager.h:456
QString m_thumbUrl
Definition: galleryviews.h:89
QStringList ClearImage(int id, bool remove=false)
Clear file from UI cache and optionally from view.
QVector< double > WeightList
Seasonal weightings for images in a view.
Definition: galleryviews.h:30
void Add(const ImageIdList &newIds)
Definition: galleryviews.h:41
Manages a collection of images.
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,...
bool LoadFromDb(int parentId) override
Populate view from database as images/subdirs of a directory. View is ordered: Parent dir,...
void Initialise(int id)
Definition: galleryviews.h:38
ImagePtrK HasPrev(int inc) const
Peeks at previous image in view but does not decrement iterator.
void Cache(ImageItemK &dir, int thumbCount)
Cache displayed dir.
Definition: lang.c:20
bool Update(int id)
Updates view with images that have been updated.
MarkedFiles m_prevMarked
Marked items in previous dir.
Definition: galleryviews.h:202
void Clear(bool resetParent=true)
Reset view.
ImageListK GetAllNodes() const
Get all images/dirs in view.
Biased random selection so that images are more likely to appear on anniversaries.
Definition: galleryviews.h:25
void Add(int id)
Definition: galleryviews.h:42
static guint32 * tmp
Definition: goom_core.c:35
bool IsMarked(int id) const
Definition: galleryviews.h:188
QString GetCachedThumbUrl(int id) const
Definition: galleryviews.h:121
Random selection from view. An image may be absent or appear multiple times.
Definition: galleryviews.h:24
bool PopulateFromCache(ImageItem &dir, int required)
Retrieve cached dir, if available.
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:172
bool LoadFromDb(int parentId) override
Populate view from database as images of a directory sub-tree. Default order of a tree is depth-first...
Order of images in slideshow.
Definition: galleryviews.h:21
A datastore of images for display by a screen. Provides an ordered list of dirs & images from a singl...
Definition: galleryviews.h:170
QString GetPosition() const
Get positional status.
void MarkAll()
Mark all images/dirs.
void Populate(ImageList &files)
Fills view with Db images, re-ordering them as required.
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:846
void Clear()
Definition: galleryviews.h:39
QList< ThumbPair > m_thumbs
Definition: galleryviews.h:160
void Rotate(int id)
Rotate view so that starting image is at front.
QString ToString(int id)
Definition: galleryviews.h:84
ImagePtrK GetSelected() const
Get current selection.
void Clear(bool resetParent=true)
Resets view.
void ClearMarked()
Unmark all items.
void Mark(int id, bool mark)
Mark/unmark an image/dir.
ImageIdList m_prevMarkedId
Ids of marked items in previous dir.
Definition: galleryviews.h:69
Records info of displayed image files to enable clean-up of the UI image cache.
Definition: galleryviews.h:76
A datastore of images for display by a screen. Provides an ordered list of images (no dirs) from a di...
Definition: galleryviews.h:214
int GetParentId() const
Definition: galleryviews.h:105
TreeView(SlideOrderType order)
Definition: galleryviews.h:217
void ClearCache()
Clears UI cache.
bool m_selectedMarked
Is selected item marked ?
Definition: galleryviews.h:67
QList< ImagePtr > ImageList
Definition: imagetypes.h:167
void SetDirectory(int newParent)
Manage markings on tree navigation.
FlatView(SlideOrderType order)
Definition: galleryviews.h:101
ImagePtrK Prev(int inc)
Decrements iterator and returns previous image. Wraps at start.
int m_active
Sequence index of current selected image.
Definition: galleryviews.h:135
void LoadDirThumbs(ImageItem &parent, int thumbsNeeded, int level=0)
Populate thumbs for a dir.
QList< int > ImageIdList
Definition: imagetypes.h:59
ImagePtrK GetParent() const
Definition: galleryviews.h:175
virtual ~FlatView()
Definition: galleryviews.h:103
bool m_unhiddenMarked
Is any marked item unhidden ?
Definition: galleryviews.h:72
Represents a picture, video or directory.
Definition: imagetypes.h:67
ImagePtrK Next(int inc)
Advance iterator and return next image, wrapping if necessary. Regenerates unordered views on wrap.
QStringList RemoveImage(int id, bool deleted=false)
Clear file/dir and all its ancestors from UI cache so that ancestor thumbnails are recalculated....
MenuSubjects GetMenuSubjects()
Determine current selection, markings & various info to support menu display.
int m_parentId
Definition: galleryviews.h:130
void InvertMarked()
Mark all unmarked items, unmark all marked items.
virtual bool LoadFromDb(int parentId)
Populate view with database images from a directory.
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...
MarkedFiles m_marked
Marked items in current dir/view.
Definition: galleryviews.h:201
Records dir info for every displayed dir.
Definition: galleryviews.h:145
ImageManagerFe & m_mgr
Definition: galleryviews.h:132
QHash< int, ImagePtrK > m_images
Image objects currently displayed.
Definition: galleryviews.h:133
bool m_hiddenMarked
Is any marked item hidden ?
Definition: galleryviews.h:71
A container of images/dirs that have been marked.
Definition: galleryviews.h:34
DirCacheEntry(int parentId, int dirs, int files, QList< ThumbPair > thumbs, int thumbCount)
Definition: galleryviews.h:149
Definition: imagetypes.h:26
SlideOrderType m_order
Definition: galleryviews.h:131
ImageIdList GetChildren() const
Definition: galleryviews.h:197
QHash< int, DirCacheEntry > m_dirCache
Caches displayed image dirs.
Definition: galleryviews.h:205
ImagePtrK HasNext(int inc) const
Peeks at next image in view but does not advance iterator.
Ordered as per user setting GallerySortOrder.
Definition: galleryviews.h:22
int m_childCount
Number of images & dirs excl parent.
Definition: galleryviews.h:70
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:173
A snapshot of current selection, markings & dir info when menu is invoked.
Definition: galleryviews.h:52