MythTV  master
Go to the documentation of this file.
14 #include "imagemanager.h"
19  kOrdered = 0,
20  kShuffle = 1,
21  kRandom = 2,
22  kSeasonal = 3
23 };
27 using WeightList = QVector<double>;
31 class MarkedFiles : public QSet<int>
32 {
33 public:
34  MarkedFiles() : QSet() {}
35  void Initialise(int id) { m_valid = true; m_parent = id; clear();}
36  void Clear() { m_valid = false; clear(); }
37  bool IsFor(int id) { return m_valid && m_parent == id; }
38  void Add(ImageIdList newIds) { unite(newIds.toSet()); }
39  void Add(int id) { insert(id); }
40  void Invert(ImageIdList all) { QSet tmp(all.toSet() - *this); swap(tmp); }
42 private:
43  bool m_valid {false};
44  int m_parent {0};
45 };
50 {
51 public:
52  MenuSubjects() = default;
53  MenuSubjects(ImagePtrK selection, int childCount,
54  MarkedFiles &marked, MarkedFiles &prevMarked,
55  bool hiddenMarked, bool unhiddenMarked)
56  : m_selected(selection),
57  m_selectedMarked(selection && marked.contains(selection->m_id)),
58  m_markedId(marked.toList()), m_prevMarkedId(prevMarked.toList()),
59  m_childCount(childCount),
60  m_hiddenMarked(hiddenMarked), m_unhiddenMarked(unhiddenMarked)
61  {}
63  ImagePtrK m_selected {nullptr};
64  bool m_selectedMarked {false};
67  int m_childCount {0};
68  bool m_hiddenMarked {false};
69  bool m_unhiddenMarked {false};
70 };
74 {
75 public:
76  // Default constructor for QHash 'undefined entry'
77  FileCacheEntry() = default;
78  FileCacheEntry(int parent, const QString &url, const QString &thumbUrl)
79  : m_parent(parent), m_url(url), m_thumbUrl(thumbUrl) {}
81  QString ToString(int id)
82  { return QString("File %1 Parent %2").arg(id).arg(m_parent); }
85  QString m_url;
86  QString m_thumbUrl;
87 };
95 class FlatView
96 {
97 public:
98  explicit FlatView(SlideOrderType order)
99  : m_order(order), m_mgr(ImageManagerFe::getInstance()) {}
100  virtual ~FlatView() { Clear(); }
102  int GetParentId() const { return m_parentId; }
103  ImageListK GetAllNodes() const;
104  ImagePtrK GetSelected() const;
105  ImagePtrK HasNext(int inc) const;
106  ImagePtrK HasPrev(int inc) const;
107  ImagePtrK Next(int inc);
108  ImagePtrK Prev(int inc);
109  QString GetPosition() const;
110  bool Select(int id, int fallback = 0);
111  virtual bool LoadFromDb(int parentId);
112  QStringList ClearImage(int id, bool remove = false);
113  void ClearCache();
114  bool Update(int id);
115  void Rotate(int id);
116  void Clear(bool resetParent = true);
118  QString GetCachedThumbUrl(int id) const
119  { return m_fileCache.value(id).m_thumbUrl; }
121 protected:
124  void Populate(ImageList &files);
125  void Cache(int id, int parent, const QString &url, const QString &thumb);
127  int m_parentId {-1};
130  QHash<int, ImagePtrK> m_images;
132  int m_active {0};
135  QHash<int, FileCacheEntry> m_fileCache;
136 };
143 {
144 public:
145  DirCacheEntry() = default;
146  DirCacheEntry(int parentId, int dirs, int files,
147  const QList<ThumbPair> &thumbs, int thumbCount)
148  : m_parent(parentId), m_thumbCount(thumbCount),
149  m_dirCount(dirs), m_fileCount(files), m_thumbs(thumbs) {}
151  QString ToString(int id) const;
153  int m_parent {0};
154  int m_thumbCount {0};
155  int m_dirCount {-1};
156  int m_fileCount {-1};
157  QList<ThumbPair> m_thumbs;
158 };
167 class DirectoryView : public FlatView
168 {
169 public:
170  explicit DirectoryView(SlideOrderType);
173  { return m_sequence.isEmpty() ? ImagePtrK() : m_images.value(; }
175  QString GetPosition() const;
176  bool LoadFromDb(int parentId) override; // FlatView
177  void Clear(bool resetParent = true);
179  QStringList RemoveImage(int id, bool deleted = false);
180  void ClearCache();
181  void MarkAll();
182  void Mark(int, bool);
183  void InvertMarked();
184  void ClearMarked();
185  bool IsMarked(int id) const
186  { return m_marked.contains(id) || m_prevMarked.contains(id); }
188 protected:
189  void SetDirectory(int);
190  void LoadDirThumbs(ImageItem &, int thumbsNeeded, int level = 0);
191  void PopulateThumbs(ImageItem &, int thumbsNeeded,
192  const ImageList &files, const ImageList &dirs,
193  int level = 0);
194  ImageIdList GetChildren() const { return m_sequence.mid(1); }
195  bool PopulateFromCache(ImageItem &, int required);
196  void Cache(ImageItemK &, int thumbCount);
202  QHash<int, DirCacheEntry> m_dirCache;
203 };
211 class TreeView : public FlatView
212 {
213 public:
214  explicit TreeView(SlideOrderType order) : FlatView(order) {}
216  bool LoadFromDb(int parentId) override; // FlatView
217 };
220 #endif // GALLERYVIEWS_H
ImageIdList m_markedId
Ids of all marked items.
Definition: galleryviews.h:65
ImagePtrK m_selected
Selected item.
Definition: galleryviews.h:63
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:131
A datastore of images for display by a screen.
Definition: galleryviews.h:95
QHash< int, FileCacheEntry > m_fileCache
Caches displayed image files.
Definition: galleryviews.h:135
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:20
void ClearCache()
Clears UI cache.
QString GetPosition() const
Get positional status.
bool IsFor(int id)
Definition: galleryviews.h:37
QString ToString(int id) const
The image manager for use by Frontends.
Definition: imagemanager.h:452
QString m_thumbUrl
Definition: galleryviews.h:86
void PopulateThumbs(ImageItem &, int thumbsNeeded, const ImageList &files, const ImageList &dirs, int level=0)
Populate directory stats & thumbnails recursively from database as follows: Use user cover,...
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:27
Manages a collection of images.
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:35
ImagePtrK HasPrev(int inc) const
Peeks at previous image in view but does not decrement iterator.
bool Update(int id)
Updates view with images that have been updated.
MarkedFiles m_prevMarked
Marked items in previous dir.
Definition: galleryviews.h:199
Constructs a view of images & directories that can be marked.
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:22
void Add(int id)
Definition: galleryviews.h:39
static guint32 * tmp
Definition: goom_core.c:35
bool IsMarked(int id) const
Definition: galleryviews.h:185
QString GetCachedThumbUrl(int id) const
Definition: galleryviews.h:118
Random selection from view. An image may be absent or appear multiple times.
Definition: galleryviews.h:21
void Invert(ImageIdList all)
Definition: galleryviews.h:40
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:179
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:18
A datastore of images for display by a screen. Provides an ordered list of dirs & images from a singl...
Definition: galleryviews.h:167
QString GetPosition() const
Get positional status.
void Cache(ImageItemK &, int thumbCount)
Cache displayed dir.
void MarkAll()
Mark all images/dirs.
void Mark(int, bool)
Mark/unmark an image/dir.
void LoadDirThumbs(ImageItem &, int thumbsNeeded, int level=0)
Populate thumbs for a dir.
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:830
void Clear()
Definition: galleryviews.h:36
QList< ThumbPair > m_thumbs
Definition: galleryviews.h:157
void Rotate(int id)
Rotate view so that starting image is at front.
QString ToString(int id)
Definition: galleryviews.h:81
ImagePtrK GetSelected() const
Get current selection.
void Clear(bool resetParent=true)
Resets view.
MenuSubjects(ImagePtrK selection, int childCount, MarkedFiles &marked, MarkedFiles &prevMarked, bool hiddenMarked, bool unhiddenMarked)
Definition: galleryviews.h:53
void ClearMarked()
Unmark all items.
ImageIdList m_prevMarkedId
Ids of marked items in previous dir.
Definition: galleryviews.h:66
Records info of displayed image files to enable clean-up of the UI image cache.
Definition: galleryviews.h:73
A datastore of images for display by a screen. Provides an ordered list of images (no dirs) from a di...
Definition: galleryviews.h:211
int GetParentId() const
Definition: galleryviews.h:102
TreeView(SlideOrderType order)
Definition: galleryviews.h:214
void ClearCache()
Clears UI cache.
bool m_selectedMarked
Is selected item marked ?
Definition: galleryviews.h:64
QList< ImagePtr > ImageList
Definition: imagetypes.h:174
FlatView(SlideOrderType order)
Definition: galleryviews.h:98
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:132
FileCacheEntry(int parent, const QString &url, const QString &thumbUrl)
Definition: galleryviews.h:78
void SetDirectory(int)
Manage markings on tree navigation.
QList< int > ImageIdList
Definition: imagetypes.h:59
DirCacheEntry(int parentId, int dirs, int files, const QList< ThumbPair > &thumbs, int thumbCount)
Definition: galleryviews.h:146
ImagePtrK GetParent() const
Definition: galleryviews.h:172
virtual ~FlatView()
Definition: galleryviews.h:100
bool PopulateFromCache(ImageItem &, int required)
Retrieve cached dir, if available.
bool m_unhiddenMarked
Is any marked item unhidden ?
Definition: galleryviews.h:69
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:127
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...
void Add(ImageIdList newIds)
Definition: galleryviews.h:38
MarkedFiles m_marked
Marked items in current dir/view.
Definition: galleryviews.h:198
Records dir info for every displayed dir.
Definition: galleryviews.h:142
ImageManagerFe & m_mgr
Definition: galleryviews.h:129
QHash< int, ImagePtrK > m_images
Image objects currently displayed.
Definition: galleryviews.h:130
bool m_hiddenMarked
Is any marked item hidden ?
Definition: galleryviews.h:68
A container of images/dirs that have been marked.
Definition: galleryviews.h:31
Definition: imagetypes.h:26
SlideOrderType m_order
Definition: galleryviews.h:128
ImageIdList GetChildren() const
Definition: galleryviews.h:194
QHash< int, DirCacheEntry > m_dirCache
Caches displayed image dirs.
Definition: galleryviews.h:202
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:19
int m_childCount
Number of images & dirs excl parent.
Definition: galleryviews.h:67
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:180
A snapshot of current selection, markings & dir info when menu is invoked.
Definition: galleryviews.h:49