MythTV  master
galleryviews.cpp
Go to the documentation of this file.
1 #include "galleryviews.h"
2 
3 #include <algorithm> // std::shuffle, upper_bound
4 #include <cmath> // std::pow
5 #include <cstdint>
6 #include <iterator> // std::distance
7 #include <random>
8 #include <vector>
9 
10 #include "libmythbase/mythrandom.h"
11 
12 #define LOC QString("Galleryviews: ")
13 
15 const static int kMaxFolderThumbnails = 4;
16 
23 const double LEADING_BETA_SHAPE = 0.175;
25 const double TRAILING_BETA_SHAPE = 0.31;
26 
28 const double DEFAULT_WEIGHT = std::pow(0.5, TRAILING_BETA_SHAPE - 1) *
29  std::pow(0.5, LEADING_BETA_SHAPE - 1);
31 static constexpr qint64 BETA_CLIP { 24LL * 60 * 60 };
32 
33 void MarkedFiles::Add(const ImageIdList& newIds)
34 {
35  for (int newid : newIds)
36  insert(newid);
37 }
38 
40 {
41  QSet tmp;
42  for (int tmpint : all)
43  tmp.insert(tmpint);
44  for (int tmpint : std::as_const(*this))
45  tmp.remove(tmpint);
46  swap(tmp);
47 }
48 
54 {
55  ImageListK files;
56  for (int id : std::as_const(m_sequence))
57  files.append(m_images.value(id));
58  return files;
59 }
60 
61 
67 {
68  return m_active < 0 || m_active >= m_sequence.size()
69  ? ImagePtrK() : m_images.value(m_sequence.at(m_active));
70 }
71 
72 
77 QString FlatView::GetPosition() const
78 {
79  return QString("%1/%2").arg(m_active + 1).arg(m_sequence.size());
80 }
81 
82 
88 bool FlatView::Update(int id)
89 {
90  ImagePtrK im = m_images.value(id);
91  if (!im)
92  return false;
93 
94  // Get updated image
95  ImageList files;
96  ImageList dirs;
97  ImageIdList ids = ImageIdList() << id;
98  if (m_mgr.GetImages(ids, files, dirs) != 1 || files.size() != 1)
99  return false;
100 
101  bool active = (im == GetSelected());
102 
103  // Replace image
104  m_images.insert(id, files.at(0));
105 
106  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Modified id %1").arg(id));
107 
108  return active;
109 }
110 
111 
119 bool FlatView::Select(int id, int fallback)
120 {
121  // Select first appearance of image
122  int index = m_sequence.indexOf(id);
123  if (index >= 0)
124  {
125  m_active = index;
126  return true;
127  }
128 
129  if (fallback >= 0)
130  m_active = fallback;
131 
132  return false;
133 }
134 
135 
140 void FlatView::Clear(bool resetParent)
141 {
142  m_images.clear();
143  m_sequence.clear();
144  m_active = -1;
145  if (resetParent)
147 }
148 
149 
155 {
156  return m_sequence.isEmpty() || m_active + inc >= m_sequence.size()
157  ? ImagePtrK() : m_images.value(m_sequence.at(m_active + inc));
158 }
159 
160 
167 {
168  if (m_sequence.isEmpty())
169  return {};
170 
171  // Preserve index as it may be reset when wrapping
172  int next = m_active + inc;
173 
174  // Regenerate unordered views when wrapping
175  if (next >= m_sequence.size() && m_order != kOrdered && !LoadFromDb(m_parentId))
176  // Images have disappeared
177  return {};
178 
179  m_active = next % m_sequence.size();
180  return m_images.value(m_sequence.at(m_active));
181 }
182 
183 
189 {
190  return m_sequence.isEmpty() || m_active < inc
191  ? ImagePtrK() : m_images.value(m_sequence.at(m_active - inc));
192 }
193 
194 
200 {
201  if (m_sequence.isEmpty())
202  return {};
203 
204  // Wrap avoiding modulo of negative uncertainty
205  m_active -= inc % m_sequence.size();
206  if (m_active < 0)
207  m_active += m_sequence.size();
208 
209  return m_images.value(m_sequence.at(m_active));
210 }
211 
212 
218 {
219  // Do not reset parent
220  Clear(false);
221 
222  if (files.isEmpty())
223  return;
224 
225  for (const QSharedPointer<ImageItem> & im : std::as_const(files))
226  {
227  // Add image to view
228  m_images.insert(im->m_id, im);
229 
230  // Cache all displayed images
231  if (im->IsFile())
232  Cache(im->m_id, im->m_parentId, im->m_url, im->m_thumbNails.at(0).second);
233  }
234 
235  if (files.size() == 1 || m_order == kOrdered || m_order == kShuffle)
236  {
237  // Default sequence is ordered
238  for (const QSharedPointer<ImageItem> & im : std::as_const(files))
239  m_sequence.append(im->m_id);
240  }
241 
242  if (files.size() > 1)
243  {
244  // Modify viewing sequence
245  if (m_order == kShuffle)
246  {
247  std::shuffle(m_sequence.begin(), m_sequence.end(),
248  std::mt19937(std::random_device()()));
249  }
250  else if (m_order == kRandom)
251  {
252  // An image is not a valid candidate for its successor
253  // add files.size() elements from files in a random order
254  // to m_sequence allowing non-consecutive repetition
255  int size = files.size();
256  int range = files.size() - 1;
257  int last = size; // outside of the random interval [0, size)
258  int count = 0;
259  while (count < size)
260  {
261  int rand = MythRandom(0, range);
262 
263  // Avoid consecutive repeats
264  if (last == rand)
265  {
266  continue;
267  }
268  last = rand;
269  m_sequence.append(files.at(rand)->m_id);
270  count++;
271  }
272  }
273  else if (m_order == kSeasonal)
274  {
275  WeightList cdf = CalculateSeasonalWeights(files); // not normalized to 1.0
276  std::vector<uint32_t> weights;
277  weights.reserve(cdf.size());
278  for (int i = 0; i < cdf.size(); i++)
279  {
280  weights.emplace_back(lround(cdf[i] / cdf.back() * UINT32_MAX));
281  }
282  // exclude the last value so the past the end iterator is not returned
283  // by std::upper_bound
284  uint32_t maxWeight = weights.back() - 1;
285 
286  for (int count = 0; count < files.size(); ++count)
287  {
288  uint32_t randWeight = MythRandom(0, maxWeight);
289  auto it = std::upper_bound(weights.begin(), weights.end(), randWeight);
290  int index = std::distance(weights.begin(), it);
291  m_sequence.append(files.at(index)->m_id);
292  }
293  }
294  }
295 }
296 
297 
309 {
310  WeightList weights(files.size());
311  double totalWeight = 0;
312  QDateTime now = QDateTime::currentDateTime();
313 
314  for (int i = 0; i < files.size(); ++i)
315  {
316  ImagePtrK im = files.at(i);
317  double weight = 0;
318 
319  if (im->m_date == 0s)
320  weight = DEFAULT_WEIGHT;
321  else
322  {
323  QDateTime timestamp = QDateTime::fromSecsSinceEpoch(im->m_date.count());
324  QDateTime curYearAnniversary =
325  QDateTime(QDate(now.date().year(),
326  timestamp.date().month(),
327  timestamp.date().day()),
328  timestamp.time());
329 
330  bool isAnniversaryPast = curYearAnniversary < now;
331 
332  QDateTime adjacentYearAnniversary =
333  QDateTime(QDate(now.date().year() +
334  (isAnniversaryPast ? 1 : -1),
335  timestamp.date().month(),
336  timestamp.date().day()),
337  timestamp.time());
338 
339  double range = llabs(curYearAnniversary.secsTo(
340  adjacentYearAnniversary)) + BETA_CLIP;
341 
342  // This calculation is not normalized, because that would require the
343  // beta function, which isn't part of the C++98 libraries. Weights
344  // that aren't normalized work just as well relative to each other.
345  QDateTime d1(isAnniversaryPast ? curYearAnniversary
346  : adjacentYearAnniversary);
347  QDateTime d2(isAnniversaryPast ? adjacentYearAnniversary
348  : curYearAnniversary);
349  weight = std::pow(llabs(now.secsTo(d1) + BETA_CLIP) / range,
351  * std::pow(llabs(now.secsTo(d2) + BETA_CLIP) / range,
352  LEADING_BETA_SHAPE - 1);
353  }
354  totalWeight += weight;
355  weights[i] = totalWeight;
356  }
357  return weights;
358 }
359 
360 
367 bool FlatView::LoadFromDb(int parentId)
368 {
369  m_parentId = parentId;
370 
371  // Load child images of the parent
372  ImageList files;
373  ImageList dirs;
374  m_mgr.GetChildren(m_parentId, files, dirs);
375 
376  // Load gallery datastore with current dir
377  Populate(files);
378 
379  return !files.isEmpty();
380 }
381 
382 
387 {
388  LOG(VB_FILE, LOG_DEBUG, LOC + "Cleared File cache");
389  m_fileCache.clear();
390 }
391 
392 
399 QStringList FlatView::ClearImage(int id, bool remove)
400 {
401  if (remove)
402  {
403  m_sequence.removeAll(id);
404  m_images.remove(id);
405  }
406 
407  QStringList urls;
408  FileCacheEntry file = m_fileCache.take(id);
409 
410  if (!file.m_url.isEmpty())
411  urls << file.m_url;
412 
413  if (!file.m_thumbUrl.isEmpty())
414  urls << file.m_thumbUrl;
415 
416  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Cleared %1 from file cache (%2)")
417  .arg(id).arg(urls.join(",")));
418  return urls;
419 }
420 
421 
426 void FlatView::Rotate(int id)
427 {
428  // Rotate sequence so that (first appearance of) specified image is
429  // at offset from front
430  int index = m_sequence.indexOf(id);
431  if (index >= 0)
432  {
433  int first = index % m_sequence.size();
434  if (first > 0)
435  m_sequence = m_sequence.mid(first) + m_sequence.mid(0, first);
436  }
437 }
438 
439 
447 void FlatView::Cache(int id, int parent, const QString &url, const QString &thumb)
448 {
449  // Cache parent dir so that dir thumbs are updated when a child changes.
450  // Also store urls for image cache cleanup
451  FileCacheEntry cached(parent, url, thumb);
452  m_fileCache.insert(id, cached);
453  LOG(VB_FILE, LOG_DEBUG, LOC + "Caching " + cached.ToString(id));
454 }
455 
456 
457 QString DirCacheEntry::ToString(int id) const
458 {
459  QStringList ids;
460  for (const auto & thumb : std::as_const(m_thumbs))
461  ids << QString::number(thumb.first);
462  return QString("Dir %1 (%2, %3) Thumbs %4 (%5) Parent %6")
463  .arg(id).arg(m_fileCount).arg(m_dirCount).arg(ids.join(","))
464  .arg(m_thumbCount).arg(m_parent);
465 }
466 
467 
473  : FlatView(order)
474 {
475  m_marked.Clear();
477 }
478 
479 
485 {
486  return QString("%1/%2").arg(m_active).arg(m_sequence.size() - 1);
487 }
488 
489 
498 bool DirectoryView::LoadFromDb(int parentId)
499 {
500  // Determine parent (defaulting to ancestor) & get initial children
501  ImageList files;
502  ImageList dirs;
503  ImagePtr parent;
504  int count = 0;
505  // Root is guaranteed to return at least 1 item
506  while ((count = m_mgr.GetDirectory(parentId, parent, files, dirs)) == 0)
507  {
508  // Fallback if dir no longer exists
509  // Ascend to Gallery for gallery subdirs, Root for device dirs & Gallery
510  parentId = parentId > PHOTO_DB_ID ? PHOTO_DB_ID : GALLERY_DB_ID;
511  }
512 
513  SetDirectory(parentId);
514  m_parentId = parentId;
515 
516  // No SG & no devices uses special 'empty' screen
517  if (!parent || (parentId == GALLERY_DB_ID && count == 1))
518  {
519  parent.clear();
520  return false;
521  }
522 
523  // Populate all subdirs
524  for (const ImagePtr & im : std::as_const(dirs))
525  {
526  if (im)
527  // Load sufficient thumbs from each dir as subsequent dirs may be empty
529  }
530 
531  // Populate parent
533  PopulateThumbs(*parent, kMaxFolderThumbnails, files, dirs);
534 
535  // Dirs shown before images
536  ImageList images = dirs + files;
537 
538  // Validate marked images
539  if (!m_marked.isEmpty())
540  {
541  QSet<int> ids;
542  for (const QSharedPointer<ImageItem> & im : std::as_const(images))
543  ids.insert(im->m_id);
544  m_marked.intersect(ids);
545  }
546 
547  // Parent is always first (for navigating up).
548  images.prepend(parent);
549 
550  // Preserve current selection before view is destroyed
551  ImagePtrK selected = GetSelected();
552  int activeId = selected ? selected->m_id : 0;
553 
554  // Construct view
555  Populate(images);
556 
557  // Reinstate selection, falling back to parent
558  Select(activeId);
559 
560  return true;
561 }
562 
563 
570 void DirectoryView::LoadDirThumbs(ImageItem &parent, int thumbsNeeded, int level)
571 {
572  // Use cached data, if available
573  if (PopulateFromCache(parent, thumbsNeeded))
574  return;
575 
576  // Load child images & dirs
577  ImageList files;
578  ImageList dirs;
579  m_mgr.GetChildren(parent.m_id, files, dirs);
580 
581  PopulateThumbs(parent, thumbsNeeded, files, dirs, level);
582 }
583 
584 
595 void DirectoryView::PopulateThumbs(ImageItem &parent, int thumbsNeeded,
596  const ImageList &files, const ImageList &dirs,
597  int level)
598 {
599  // Set parent stats
600  parent.m_fileCount = files.size();
601  parent.m_dirCount = dirs.size();
602 
603  // Locate user assigned thumb amongst children, if defined
604  ImagePtr userIm;
605  if (parent.m_userThumbnail != 0)
606  {
607  ImageList images = files + dirs;
608  // ImageItem has been explicitly marked Q_DISABLE_COPY
609  for (const ImagePtr & im : std::as_const(images))
610  {
611  if (im && im->m_id == parent.m_userThumbnail)
612  { // cppcheck-suppress useStlAlgorithm
613  userIm = im;
614  break;
615  }
616  }
617  }
618 
619  // Children to use as thumbnails
620  ImageList thumbFiles;
621  ImageList thumbDirs;
622 
623  if (!userIm)
624  {
625  // Construct multi-thumbnail from all children
626  thumbFiles = files;
627  thumbDirs = dirs;
628  }
629  else if (userIm->IsFile())
630  {
631  thumbFiles.append(userIm);
632  thumbsNeeded = 1;
633  }
634  else
635  thumbDirs.append(userIm);
636 
637  // Fill parent thumbs from child files first
638  // Whilst they're available fill as many as possible for cache
639 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
640  for (int i = 0; i < std::min(kMaxFolderThumbnails, thumbFiles.size()); ++i)
641 #else
642  for (int i = 0; i < std::min(kMaxFolderThumbnails, static_cast<int>(thumbFiles.size())); ++i)
643 #endif
644  {
645  parent.m_thumbNails.append(thumbFiles.at(i)->m_thumbNails.at(0));
646  --thumbsNeeded;
647  }
648 
649  // Only recurse if necessary
650  if (thumbsNeeded > 0)
651  {
652  // Prevent lengthy/infinite recursion due to deep/cyclic folder
653  // structures
654  if (++level > 10)
655  {
656  LOG(VB_GENERAL, LOG_NOTICE, LOC +
657  "Directory thumbnails are more than 10 levels deep");
658  }
659  else
660  {
661  // Recursively load subdir thumbs to try to get 1 thumb from each
662  for (const ImagePtr & im : std::as_const(thumbDirs))
663  {
664  if (!im)
665  continue;
666 
667  // Load sufficient thumbs from each dir as subsequent dirs may
668  // be empty
669  LoadDirThumbs(*im, thumbsNeeded, level);
670 
671  if (!im->m_thumbNails.empty())
672  {
673  // Add first thumbnail to parent thumb
674  parent.m_thumbNails.append(im->m_thumbNails.at(0));
675 
676  // Quit when we have sufficient thumbs
677  if (--thumbsNeeded == 0)
678  break;
679  }
680  }
681 
682  // If insufficient dirs to supply 1 thumb per dir, use other dir
683  // thumbs (indices 1-3) as well
684  int i = 0;
685  while (thumbsNeeded > 0 && ++i < kMaxFolderThumbnails)
686  {
687  for (const QSharedPointer<ImageItem> & im : std::as_const(thumbDirs))
688  {
689  if (i < im->m_thumbNails.size())
690  {
691  parent.m_thumbNails.append(im->m_thumbNails.at(i));
692  if (--thumbsNeeded == 0)
693  break;
694  }
695  }
696  }
697  }
698  }
699 
700  // Flag the cached entry with number of thumbs loaded. If future uses require
701  // more, then the dir must be reloaded.
702  // For user thumbs and dirs with insufficient child images, the cache is always valid
703  int scanned = (userIm || thumbsNeeded > 0)
705  : parent.m_thumbNails.size();
706 
707  // Cache result to optimize navigation
708  Cache(parent, scanned);
709 }
710 
711 
716 void DirectoryView::Clear(bool /*resetParent*/)
717 {
718  ClearMarked();
719  ClearCache();
720  FlatView::Clear();
721 }
722 
723 
728 {
729  // Any marking clears previous marks
732 }
733 
734 
740 void DirectoryView::Mark(int id, bool mark)
741 {
742  if (mark)
743  {
744  // Any marking clears previous marks
746  m_marked.Add(id);
747  }
748  else
749  {
750  m_prevMarked.remove(id);
751  m_marked.remove(id);
752  }
753 }
754 
755 
760 {
761  // Any marking clears previous marks
764 }
765 
766 
771 {
772  m_marked.Clear();
774 }
775 
776 
781 void DirectoryView::SetDirectory(int newParent)
782 {
783  if (m_marked.IsFor(newParent))
784  // Directory hasn't changed
785  return;
786 
787  // Markings are cleared on every dir change
788  // Any current markings become previous markings
789  // Only 1 set of previous markings are preserved
790  if (m_prevMarked.IsFor(newParent))
791  {
792  // Returned to dir of previous markings: reinstate them
795  return;
796  }
797 
798  if (!m_marked.isEmpty())
799  // Preserve current markings
801 
802  // Initialise current markings for new dir
803  m_marked.Initialise(newParent);
804 }
805 
806 
812 {
813  // hiddenMarked is true if 1 or more marked items are hidden
814  // unhiddenMarked is true if 1 or more marked items are not hidden
815  bool hiddenMarked = false;
816  bool unhiddenMarked = false;
817  for (int id : std::as_const(m_marked))
818  {
819  ImagePtrK im = m_images.value(id);
820  if (!im)
821  continue;
822 
823  if (im->m_isHidden)
824  hiddenMarked = true;
825  else
826  unhiddenMarked = true;
827 
828  if (hiddenMarked && unhiddenMarked)
829  break;
830  }
831 
832  return {GetSelected(), m_sequence.size() - 1,
834  hiddenMarked, unhiddenMarked};
835 }
836 
837 
845 {
846  DirCacheEntry cached(m_dirCache.value(dir.m_id));
847  if (cached.m_dirCount == -1 || cached.m_thumbCount < required)
848  return false;
849 
850  dir.m_fileCount = cached.m_fileCount;
851  dir.m_dirCount = cached.m_dirCount;
852  dir.m_thumbNails = cached.m_thumbs;
853 
854  LOG(VB_FILE, LOG_DEBUG, LOC + "Using cached " + cached.ToString(dir.m_id));
855  return true;
856 }
857 
858 
864 void DirectoryView::Cache(ImageItemK &dir, int thumbCount)
865 {
866  // Cache counts & thumbnails for each dir so that we don't need to reload its
867  // children from Db each time it's displayed
868  DirCacheEntry cacheEntry(dir.m_parentId, dir.m_dirCount, dir.m_fileCount,
869  dir.m_thumbNails, thumbCount);
870 
871  m_dirCache.insert(dir.m_id, cacheEntry);
872 
873  // Cache images used by dir thumbnails
874  for (const ThumbPair & thumb : std::as_const(dir.m_thumbNails))
875  {
876  // Do not overwrite any existing image url nor parent.
877  // Image url is cached when image is displayed as a child, but not as a
878  // ancestor dir thumbnail
879  // First cache attempt will be by parent. Subsequent attempts may be
880  // by ancestor dirs.
881  if (!m_fileCache.contains(thumb.first))
882  FlatView::Cache(thumb.first, dir.m_id, "", thumb.second);
883  }
884  LOG(VB_FILE, LOG_DEBUG, LOC + "Caching " + cacheEntry.ToString(dir.m_id));
885 }
886 
887 
892 {
893  LOG(VB_FILE, LOG_DEBUG, LOC + "Cleared Dir cache");
894  m_dirCache.clear();
896 }
897 
898 
906 QStringList DirectoryView::RemoveImage(int id, bool deleted)
907 {
908  QStringList urls;
909  int dirId = id;
910 
911  if (deleted)
912  {
913  m_marked.remove(id);
914  m_prevMarked.remove(id);
915  }
916 
917  // If id is a file then start with its parent
918  if (m_fileCache.contains(id))
919  {
920  // Clear file cache & start from its parent dir
921  dirId = m_fileCache.value(id).m_parent;
922  urls = FlatView::ClearImage(id, deleted);
923  }
924 
925  // Clear ancestor dirs
926  while (m_dirCache.contains(dirId))
927  {
928  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Cleared %1 from dir cache").arg(dirId));
929  DirCacheEntry dir = m_dirCache.take(dirId);
930  dirId = dir.m_parent;
931  }
932  return urls;
933 }
934 
935 
943 bool TreeView::LoadFromDb(int parentId)
944 {
945  m_parentId = parentId;
946 
947  // Load visible subtree of the parent
948  // Ordered images of parent first, then breadth-first recursion of ordered dirs
949  ImageList files;
950  m_mgr.GetImageTree(m_parentId, files);
951 
952  // Load view
953  Populate(files);
954 
955  return !files.isEmpty();
956 }
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
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
ImageDbReader::GetImages
int GetImages(const ImageIdList &ids, ImageList &files, ImageList &dirs) const
Returns images (local or remote but not a combination)
Definition: imagemanager.cpp:1832
FlatView::HasNext
ImagePtrK HasNext(int inc) const
Peeks at next image in view but does not advance iterator.
Definition: galleryviews.cpp:154
LEADING_BETA_SHAPE
const double LEADING_BETA_SHAPE
Tuning parameter for seasonal weights, between 0 and 1, where lower numbers give greater weight to se...
Definition: galleryviews.cpp:23
DirectoryView::GetPosition
QString GetPosition() const
Get positional status.
Definition: galleryviews.cpp:484
ImageDbReader::GetImageTree
void GetImageTree(int id, ImageList &files) const
Return all files (local or remote) in the sub-trees of a dir.
Definition: imagemanager.cpp:1891
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:943
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
ImageItem::m_id
int m_id
Uniquely identifies an image (file/dir).
Definition: imagetypes.h:89
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
mythrandom.h
ImageDbReader::GetDirectory
int GetDirectory(int id, ImagePtr &parent, ImageList &files, ImageList &dirs) const
Return images (local and/or remote) for a dir and its direct children.
Definition: imagemanager.cpp:1800
DEFAULT_WEIGHT
const double DEFAULT_WEIGHT
Photos without an exif timestamp will default to the mode of the beta distribution.
Definition: galleryviews.cpp:28
kMaxFolderThumbnails
const static int kMaxFolderThumbnails
Number of thumbnails to use for folders.
Definition: galleryviews.cpp:15
FlatView::m_order
SlideOrderType m_order
Definition: galleryviews.h:131
DirectoryView::Mark
void Mark(int id, bool mark)
Mark/unmark an image/dir.
Definition: galleryviews.cpp:740
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:844
FlatView::m_mgr
ImageManagerFe & m_mgr
Definition: galleryviews.h:132
FileCacheEntry::ToString
QString ToString(int id) const
Definition: galleryviews.h:84
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
FlatView
A datastore of images for display by a screen.
Definition: galleryviews.h:98
kSeasonal
@ kSeasonal
Biased random selection so that images are more likely to appear on anniversaries.
Definition: galleryviews.h:25
TRAILING_BETA_SHAPE
const double TRAILING_BETA_SHAPE
See LEADING_BETA_SHAPE.
Definition: galleryviews.cpp:25
build_compdb.file
file
Definition: build_compdb.py:55
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::Cache
void Cache(ImageItemK &dir, int thumbCount)
Cache displayed dir.
Definition: galleryviews.cpp:864
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::Clear
void Clear()
Definition: galleryviews.h:39
FlatView::Select
bool Select(int id, int fallback=0)
Selects first occurrence of an image.
Definition: galleryviews.cpp:119
FlatView::Prev
ImagePtrK Prev(int inc)
Decrements iterator and returns previous image. Wraps at start.
Definition: galleryviews.cpp:199
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
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:727
BETA_CLIP
static constexpr qint64 BETA_CLIP
The edges of the distribution get clipped to avoid a singularity.
Definition: galleryviews.cpp:31
DirCacheEntry
Records dir info for every displayed dir.
Definition: galleryviews.h:145
MythDate::fromSecsSinceEpoch
MBASE_PUBLIC QDateTime fromSecsSinceEpoch(int64_t seconds)
This function takes the number of seconds since the start of the epoch and returns a QDateTime with t...
Definition: mythdate.cpp:72
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
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
LOC
#define LOC
Definition: galleryviews.cpp:12
kShuffle
@ kShuffle
Each image appears exactly once, but in random order.
Definition: galleryviews.h:23
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:759
ImageListK
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:166
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:781
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
ImageItem::m_thumbNails
QList< ThumbPair > m_thumbNails
Definition: imagetypes.h:111
DirCacheEntry::ToString
QString ToString(int id) const
Definition: galleryviews.cpp:457
ImageItem::m_dirCount
int m_dirCount
Id & URLs of thumbnail(s). 1 for a file, 4 for dirs.
Definition: imagetypes.h:112
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
galleryviews.h
Provides view datastores for Gallery screens.
DirectoryView::LoadDirThumbs
void LoadDirThumbs(ImageItem &parent, int thumbsNeeded, int level=0)
Populate thumbs for a dir.
Definition: galleryviews.cpp:570
ImagePtr
QSharedPointer< ImageItem > ImagePtr
Definition: imagetypes.h:159
DirCacheEntry::m_thumbCount
int m_thumbCount
Definition: galleryviews.h:157
ImageItem
Represents a picture, video or directory.
Definition: imagetypes.h:68
DirCacheEntry::m_parent
int m_parent
Definition: galleryviews.h:156
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
ImageItem::m_parentId
int m_parentId
Id of parent dir.
Definition: imagetypes.h:96
DirectoryView::GetMenuSubjects
MenuSubjects GetMenuSubjects()
Determine current selection, markings & various info to support menu display.
Definition: galleryviews.cpp:811
PHOTO_DB_ID
static constexpr int PHOTO_DB_ID
Definition: imagetypes.h:29
MarkedFiles::Invert
void Invert(const ImageIdList &all)
Definition: galleryviews.cpp:39
ImageDbReader::GetChildren
int GetChildren(int id, ImageList &files, ImageList &dirs) const
Return (local or remote) images that are direct children of a dir.
Definition: imagemanager.cpp:1853
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
SlideOrderType
SlideOrderType
Order of images in slideshow.
Definition: galleryviews.h:21
DirectoryView::ClearCache
void ClearCache()
Clears UI cache.
Definition: galleryviews.cpp:891
DirectoryView::Clear
void Clear(bool resetParent=true)
Resets view.
Definition: galleryviews.cpp:716
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:906
WeightList
QVector< double > WeightList
Seasonal weightings for images in a view.
Definition: galleryviews.h:30
ThumbPair
QPair< int, QString > ThumbPair
Definition: imagetypes.h:64
ImageItem::m_userThumbnail
int m_userThumbnail
Id of thumbnail to use as cover (dirs only)
Definition: imagetypes.h:106
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
MarkedFiles::IsFor
bool IsFor(int id) const
Definition: galleryviews.h:40
DirectoryView::GetChildren
ImageIdList GetChildren() const
Definition: galleryviews.h:197
DirectoryView::ClearMarked
void ClearMarked()
Unmark all items.
Definition: galleryviews.cpp:770
kRandom
@ kRandom
Random selection from view. An image may be absent or appear multiple times.
Definition: galleryviews.h:24
MythRandomStd::MythRandom
uint32_t MythRandom()
generate 32 random bits
Definition: mythrandom.h:20
DirCacheEntry::m_dirCount
int m_dirCount
Definition: galleryviews.h:158
ImageItem::m_fileCount
int m_fileCount
Number of child images (dirs only)
Definition: imagetypes.h:113
FlatView::m_active
int m_active
Sequence index of current selected image.
Definition: galleryviews.h:135