MythTV  master
galleryviews.cpp
Go to the documentation of this file.
1 #include "galleryviews.h"
2 
3 #include <cmath> // for qsrand
4 #include <random>
5 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
6 #include <QRandomGenerator>
7 #endif
8 
9 #define LOC QString("Galleryviews: ")
10 
12 const static int kMaxFolderThumbnails = 4;
13 
20 const double LEADING_BETA_SHAPE = 0.175;
22 const double TRAILING_BETA_SHAPE = 0.31;
23 
25 const double DEFAULT_WEIGHT = std::pow(0.5, TRAILING_BETA_SHAPE - 1) *
26  std::pow(0.5, LEADING_BETA_SHAPE - 1);
28 const qint64 BETA_CLIP = 60 * 60 * 24;
29 
30 void MarkedFiles::Add(const ImageIdList& newIds)
31 {
32  for (int newid : newIds)
33  insert(newid);
34 }
35 
37 {
38  QSet tmp;
39  for (int tmpint : all)
40  tmp.insert(tmpint);
41  for (int tmpint : qAsConst(*this))
42  tmp.remove(tmpint);
43  swap(tmp);
44 }
45 
51 {
52  ImageListK files;
53  for (int id : qAsConst(m_sequence))
54  files.append(m_images.value(id));
55  return files;
56 }
57 
58 
64 {
65  return m_active < 0 || m_active >= m_sequence.size()
66  ? ImagePtrK() : m_images.value(m_sequence.at(m_active));
67 }
68 
69 
74 QString FlatView::GetPosition() const
75 {
76  return QString("%1/%2").arg(m_active + 1).arg(m_sequence.size());
77 }
78 
79 
85 bool FlatView::Update(int id)
86 {
87  ImagePtrK im = m_images.value(id);
88  if (!im)
89  return false;
90 
91  // Get updated image
92  ImageList files;
93  ImageList dirs;
94  ImageIdList ids = ImageIdList() << id;
95  if (m_mgr.GetImages(ids, files, dirs) != 1 || files.size() != 1)
96  return false;
97 
98  bool active = (im == GetSelected());
99 
100  // Replace image
101  m_images.insert(id, files.at(0));
102 
103  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Modified id %1").arg(id));
104 
105  return active;
106 }
107 
108 
116 bool FlatView::Select(int id, int fallback)
117 {
118  // Select first appearance of image
119  int index = m_sequence.indexOf(id);
120  if (index >= 0)
121  {
122  m_active = index;
123  return true;
124  }
125 
126  if (fallback >= 0)
127  m_active = fallback;
128 
129  return false;
130 }
131 
132 
137 void FlatView::Clear(bool resetParent)
138 {
139  m_images.clear();
140  m_sequence.clear();
141  m_active = -1;
142  if (resetParent)
144 }
145 
146 
152 {
153  return m_sequence.isEmpty() || m_active + inc >= m_sequence.size()
154  ? ImagePtrK() : m_images.value(m_sequence.at(m_active + inc));
155 }
156 
157 
164 {
165  if (m_sequence.isEmpty())
166  return ImagePtrK();
167 
168  // Preserve index as it may be reset when wrapping
169  int next = m_active + inc;
170 
171  // Regenerate unordered views when wrapping
172  if (next >= m_sequence.size() && m_order != kOrdered && !LoadFromDb(m_parentId))
173  // Images have disappeared
174  return ImagePtrK();
175 
176  m_active = next % m_sequence.size();
177  return m_images.value(m_sequence.at(m_active));
178 }
179 
180 
186 {
187  return m_sequence.isEmpty() || m_active < inc
188  ? ImagePtrK() : m_images.value(m_sequence.at(m_active - inc));
189 }
190 
191 
197 {
198  if (m_sequence.isEmpty())
199  return ImagePtrK();
200 
201  // Wrap avoiding modulo of negative uncertainty
202  m_active -= inc % m_sequence.size();
203  if (m_active < 0)
204  m_active += m_sequence.size();
205 
206  return m_images.value(m_sequence.at(m_active));
207 }
208 
209 
215 {
216  // Do not reset parent
217  Clear(false);
218 
219  if (files.isEmpty())
220  return;
221 
222  for (const QSharedPointer<ImageItem> & im : qAsConst(files))
223  {
224  // Add image to view
225  m_images.insert(im->m_id, im);
226 
227  // Cache all displayed images
228  if (im->IsFile())
229  Cache(im->m_id, im->m_parentId, im->m_url, im->m_thumbNails.at(0).second);
230  }
231 
232  if (files.size() == 1 || m_order == kOrdered || m_order == kShuffle)
233  {
234  // Default sequence is ordered
235  for (const QSharedPointer<ImageItem> & im : qAsConst(files))
236  m_sequence.append(im->m_id);
237  }
238 
239  if (files.size() > 1)
240  {
241  // Modify viewing sequence
242  if (m_order == kShuffle)
243  {
244  std::shuffle(m_sequence.begin(), m_sequence.end(),
245  std::mt19937(std::random_device()()));
246  }
247  else if (m_order == kRandom)
248  {
249 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
250  QVector<quint32> rands;
251  rands.resize(files.size());
252  QRandomGenerator::global()->fillRange(rands.data(), rands.size());
253 #else
254  // cppcheck-suppress qsrandCalled
255  qsrand(QTime::currentTime().msec());
256 #endif
257  // An image is not a valid candidate for its successor
258  int range = files.size() - 1;
259  int index = range;
260  for (int count = 0; count < files.size(); ++count)
261  {
262 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
263  int rand = rands[count] % range;
264 #else
265  // cppcheck-suppress qrandCalled
266  int rand = qrand() % range;
267 #endif
268  // Avoid consecutive repeats
269  index = (rand < index) ? rand : rand + 1;
270  m_sequence.append(files.at(index)->m_id);
271  }
272  }
273  else if (m_order == kSeasonal)
274  {
275  WeightList weights = CalculateSeasonalWeights(files);
276  double maxWeight = weights.last();
277 
278 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
279  auto *randgen = QRandomGenerator::global();
280 #else
281  // cppcheck-suppress qsrandCalled
282  qsrand(QTime::currentTime().msec());
283 #endif
284  for (int count = 0; count < files.size(); ++count)
285  {
286 #if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
287  // generateDouble() returns in the range [0, 1)
288  double randWeight = randgen->generateDouble() * maxWeight;
289 #else
290  // cppcheck-suppress qrandCalled
291  double randWeight = qrand() * maxWeight / RAND_MAX;
292 #endif
293  WeightList::iterator it =
294  std::upper_bound(weights.begin(), weights.end(), randWeight);
295  int index = std::distance(weights.begin(), it);
296  m_sequence.append(files.at(index)->m_id);
297  }
298  }
299  }
300 }
301 
302 
314 {
315  WeightList weights(files.size());
316  double totalWeight = 0;
317  QDateTime now = QDateTime::currentDateTime();
318 
319  for (int i = 0; i < files.size(); ++i)
320  {
321  ImagePtrK im = files.at(i);
322  double weight = 0;
323 
324  if (im->m_date == 0)
325  weight = DEFAULT_WEIGHT;
326  else
327  {
328  QDateTime timestamp = QDateTime::fromSecsSinceEpoch(im->m_date);
329  QDateTime curYearAnniversary =
330  QDateTime(QDate(now.date().year(),
331  timestamp.date().month(),
332  timestamp.date().day()),
333  timestamp.time());
334 
335  bool isAnniversaryPast = curYearAnniversary < now;
336 
337  QDateTime adjacentYearAnniversary =
338  QDateTime(QDate(now.date().year() +
339  (isAnniversaryPast ? 1 : -1),
340  timestamp.date().month(),
341  timestamp.date().day()),
342  timestamp.time());
343 
344  double range = llabs(curYearAnniversary.secsTo(
345  adjacentYearAnniversary)) + BETA_CLIP;
346 
347  // This calculation is not normalized, because that would require the
348  // beta function, which isn't part of the C++98 libraries. Weights
349  // that aren't normalized work just as well relative to each other.
350  QDateTime d1(isAnniversaryPast ? curYearAnniversary
351  : adjacentYearAnniversary);
352  QDateTime d2(isAnniversaryPast ? adjacentYearAnniversary
353  : curYearAnniversary);
354  weight = std::pow(llabs(now.secsTo(d1) + BETA_CLIP) / range,
356  * std::pow(llabs(now.secsTo(d2) + BETA_CLIP) / range,
357  LEADING_BETA_SHAPE - 1);
358  }
359  totalWeight += weight;
360  weights[i] = totalWeight;
361  }
362  return weights;
363 }
364 
365 
372 bool FlatView::LoadFromDb(int parentId)
373 {
374  m_parentId = parentId;
375 
376  // Load child images of the parent
377  ImageList files;
378  ImageList dirs;
379  m_mgr.GetChildren(m_parentId, files, dirs);
380 
381  // Load gallery datastore with current dir
382  Populate(files);
383 
384  return !files.isEmpty();
385 }
386 
387 
392 {
393  LOG(VB_FILE, LOG_DEBUG, LOC + "Cleared File cache");
394  m_fileCache.clear();
395 }
396 
397 
404 QStringList FlatView::ClearImage(int id, bool remove)
405 {
406  if (remove)
407  {
408  m_sequence.removeAll(id);
409  m_images.remove(id);
410  }
411 
412  QStringList urls;
413  FileCacheEntry file = m_fileCache.take(id);
414 
415  if (!file.m_url.isEmpty())
416  urls << file.m_url;
417 
418  if (!file.m_thumbUrl.isEmpty())
419  urls << file.m_thumbUrl;
420 
421  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Cleared %1 from file cache (%2)")
422  .arg(id).arg(urls.join(",")));
423  return urls;
424 }
425 
426 
431 void FlatView::Rotate(int id)
432 {
433  // Rotate sequence so that (first appearance of) specified image is
434  // at offset from front
435  int index = m_sequence.indexOf(id);
436  if (index >= 0)
437  {
438  int first = index % m_sequence.size();
439  if (first > 0)
440  m_sequence = m_sequence.mid(first) + m_sequence.mid(0, first);
441  }
442 }
443 
444 
452 void FlatView::Cache(int id, int parent, const QString &url, const QString &thumb)
453 {
454  // Cache parent dir so that dir thumbs are updated when a child changes.
455  // Also store urls for image cache cleanup
456  FileCacheEntry cached(parent, url, thumb);
457  m_fileCache.insert(id, cached);
458  LOG(VB_FILE, LOG_DEBUG, LOC + "Caching " + cached.ToString(id));
459 }
460 
461 
462 QString DirCacheEntry::ToString(int id) const
463 {
464  QStringList ids;
465  for (const auto & thumb : qAsConst(m_thumbs))
466  ids << QString::number(thumb.first);
467  return QString("Dir %1 (%2, %3) Thumbs %4 (%5) Parent %6")
468  .arg(id).arg(m_fileCount).arg(m_dirCount).arg(ids.join(","))
469  .arg(m_thumbCount).arg(m_parent);
470 }
471 
472 
478  : FlatView(order)
479 {
480  m_marked.Clear();
482 }
483 
484 
490 {
491  return QString("%1/%2").arg(m_active).arg(m_sequence.size() - 1);
492 }
493 
494 
503 bool DirectoryView::LoadFromDb(int parentId)
504 {
505  // Determine parent (defaulting to ancestor) & get initial children
506  ImageList files;
507  ImageList dirs;
508  ImagePtr parent;
509  int count = 0;
510  // Root is guaranteed to return at least 1 item
511  while ((count = m_mgr.GetDirectory(parentId, parent, files, dirs)) == 0)
512  {
513  // Fallback if dir no longer exists
514  // Ascend to Gallery for gallery subdirs, Root for device dirs & Gallery
515  parentId = parentId > PHOTO_DB_ID ? PHOTO_DB_ID : GALLERY_DB_ID;
516  }
517 
518  SetDirectory(parentId);
519  m_parentId = parentId;
520 
521  // No SG & no devices uses special 'empty' screen
522  if (!parent || (parentId == GALLERY_DB_ID && count == 1))
523  {
524  parent.clear();
525  return false;
526  }
527 
528  // Populate all subdirs
529  for (const ImagePtr & im : qAsConst(dirs))
530  {
531  if (im)
532  // Load sufficient thumbs from each dir as subsequent dirs may be empty
534  }
535 
536  // Populate parent
538  PopulateThumbs(*parent, kMaxFolderThumbnails, files, dirs);
539 
540  // Dirs shown before images
541  ImageList images = dirs + files;
542 
543  // Validate marked images
544  if (!m_marked.isEmpty())
545  {
546  QSet<int> ids;
547  for (const QSharedPointer<ImageItem> & im : qAsConst(images))
548  ids.insert(im->m_id);
549  m_marked.intersect(ids);
550  }
551 
552  // Parent is always first (for navigating up).
553  images.prepend(parent);
554 
555  // Preserve current selection before view is destroyed
556  ImagePtrK selected = GetSelected();
557  int activeId = selected ? selected->m_id : 0;
558 
559  // Construct view
560  Populate(images);
561 
562  // Reinstate selection, falling back to parent
563  Select(activeId);
564 
565  return true;
566 }
567 
568 
575 void DirectoryView::LoadDirThumbs(ImageItem &parent, int thumbsNeeded, int level)
576 {
577  // Use cached data, if available
578  if (PopulateFromCache(parent, thumbsNeeded))
579  return;
580 
581  // Load child images & dirs
582  ImageList files;
583  ImageList dirs;
584  m_mgr.GetChildren(parent.m_id, files, dirs);
585 
586  PopulateThumbs(parent, thumbsNeeded, files, dirs, level);
587 }
588 
589 
600 void DirectoryView::PopulateThumbs(ImageItem &parent, int thumbsNeeded,
601  const ImageList &files, const ImageList &dirs,
602  int level)
603 {
604  // Set parent stats
605  parent.m_fileCount = files.size();
606  parent.m_dirCount = dirs.size();
607 
608  // Locate user assigned thumb amongst children, if defined
609  ImagePtr userIm;
610  if (parent.m_userThumbnail != 0)
611  {
612  ImageList images = files + dirs;
613  // ImageItem has been explicitly marked Q_DISABLE_COPY
614  for (const ImagePtr & im : qAsConst(images))
615  {
616  if (im && im->m_id == parent.m_userThumbnail)
617  { // cppcheck-suppress useStlAlgorithm
618  userIm = im;
619  break;
620  }
621  }
622  }
623 
624  // Children to use as thumbnails
625  ImageList thumbFiles;
626  ImageList thumbDirs;
627 
628  if (!userIm)
629  {
630  // Construct multi-thumbnail from all children
631  thumbFiles = files;
632  thumbDirs = dirs;
633  }
634  else if (userIm->IsFile())
635  {
636  thumbFiles.append(userIm);
637  thumbsNeeded = 1;
638  }
639  else
640  thumbDirs.append(userIm);
641 
642  // Fill parent thumbs from child files first
643  // Whilst they're available fill as many as possible for cache
644  for (int i = 0; i < qMin(kMaxFolderThumbnails, thumbFiles.size()); ++i)
645  {
646  parent.m_thumbNails.append(thumbFiles.at(i)->m_thumbNails.at(0));
647  --thumbsNeeded;
648  }
649 
650  // Only recurse if necessary
651  if (thumbsNeeded > 0)
652  {
653  // Prevent lengthy/infinite recursion due to deep/cyclic folder
654  // structures
655  if (++level > 10)
656  {
657  LOG(VB_GENERAL, LOG_NOTICE, LOC +
658  "Directory thumbnails are more than 10 levels deep");
659  }
660  else
661  {
662  // Recursively load subdir thumbs to try to get 1 thumb from each
663  for (const ImagePtr & im : qAsConst(thumbDirs))
664  {
665  if (!im)
666  continue;
667 
668  // Load sufficient thumbs from each dir as subsequent dirs may
669  // be empty
670  LoadDirThumbs(*im, thumbsNeeded, level);
671 
672  if (!im->m_thumbNails.empty())
673  {
674  // Add first thumbnail to parent thumb
675  parent.m_thumbNails.append(im->m_thumbNails.at(0));
676 
677  // Quit when we have sufficient thumbs
678  if (--thumbsNeeded == 0)
679  break;
680  }
681  }
682 
683  // If insufficient dirs to supply 1 thumb per dir, use other dir
684  // thumbs (indices 1-3) as well
685  int i = 0;
686  while (thumbsNeeded > 0 && ++i < kMaxFolderThumbnails)
687  {
688  for (const QSharedPointer<ImageItem> & im : qAsConst(thumbDirs))
689  {
690  if (i < im->m_thumbNails.size())
691  {
692  parent.m_thumbNails.append(im->m_thumbNails.at(i));
693  if (--thumbsNeeded == 0)
694  break;
695  }
696  }
697  }
698  }
699  }
700 
701  // Flag the cached entry with number of thumbs loaded. If future uses require
702  // more, then the dir must be reloaded.
703  // For user thumbs and dirs with insufficient child images, the cache is always valid
704  int scanned = (userIm || thumbsNeeded > 0)
706  : parent.m_thumbNails.size();
707 
708  // Cache result to optimize navigation
709  Cache(parent, scanned);
710 }
711 
712 
717 void DirectoryView::Clear(bool /*resetParent*/)
718 {
719  ClearMarked();
720  ClearCache();
721  FlatView::Clear();
722 }
723 
724 
729 {
730  // Any marking clears previous marks
733 }
734 
735 
741 void DirectoryView::Mark(int id, bool mark)
742 {
743  if (mark)
744  {
745  // Any marking clears previous marks
747  m_marked.Add(id);
748  }
749  else
750  {
751  m_prevMarked.remove(id);
752  m_marked.remove(id);
753  }
754 }
755 
756 
761 {
762  // Any marking clears previous marks
765 }
766 
767 
772 {
773  m_marked.Clear();
775 }
776 
777 
782 void DirectoryView::SetDirectory(int newParent)
783 {
784  if (m_marked.IsFor(newParent))
785  // Directory hasn't changed
786  return;
787 
788  // Markings are cleared on every dir change
789  // Any current markings become previous markings
790  // Only 1 set of previous markings are preserved
791  if (m_prevMarked.IsFor(newParent))
792  {
793  // Returned to dir of previous markings: reinstate them
796  return;
797  }
798 
799  if (!m_marked.isEmpty())
800  // Preserve current markings
802 
803  // Initialise current markings for new dir
804  m_marked.Initialise(newParent);
805 }
806 
807 
813 {
814  // hiddenMarked is true if 1 or more marked items are hidden
815  // unhiddenMarked is true if 1 or more marked items are not hidden
816  bool hiddenMarked = false;
817  bool unhiddenMarked = false;
818  for (int id : qAsConst(m_marked))
819  {
820  ImagePtrK im = m_images.value(id);
821  if (!im)
822  continue;
823 
824  if (im->m_isHidden)
825  hiddenMarked = true;
826  else
827  unhiddenMarked = true;
828 
829  if (hiddenMarked && unhiddenMarked)
830  break;
831  }
832 
833  return MenuSubjects(GetSelected(), m_sequence.size() - 1,
835  hiddenMarked, unhiddenMarked);
836 }
837 
838 
846 {
847  DirCacheEntry cached(m_dirCache.value(dir.m_id));
848  if (cached.m_dirCount == -1 || cached.m_thumbCount < required)
849  return false;
850 
851  dir.m_fileCount = cached.m_fileCount;
852  dir.m_dirCount = cached.m_dirCount;
853  dir.m_thumbNails = cached.m_thumbs;
854 
855  LOG(VB_FILE, LOG_DEBUG, LOC + "Using cached " + cached.ToString(dir.m_id));
856  return true;
857 }
858 
859 
865 void DirectoryView::Cache(ImageItemK &dir, int thumbCount)
866 {
867  // Cache counts & thumbnails for each dir so that we don't need to reload its
868  // children from Db each time it's displayed
869  DirCacheEntry cacheEntry(dir.m_parentId, dir.m_dirCount, dir.m_fileCount,
870  dir.m_thumbNails, thumbCount);
871 
872  m_dirCache.insert(dir.m_id, cacheEntry);
873 
874  // Cache images used by dir thumbnails
875  for (const ThumbPair & thumb : qAsConst(dir.m_thumbNails))
876  {
877  // Do not overwrite any existing image url nor parent.
878  // Image url is cached when image is displayed as a child, but not as a
879  // ancestor dir thumbnail
880  // First cache attempt will be by parent. Subsequent attempts may be
881  // by ancestor dirs.
882  if (!m_fileCache.contains(thumb.first))
883  FlatView::Cache(thumb.first, dir.m_id, "", thumb.second);
884  }
885  LOG(VB_FILE, LOG_DEBUG, LOC + "Caching " + cacheEntry.ToString(dir.m_id));
886 }
887 
888 
893 {
894  LOG(VB_FILE, LOG_DEBUG, LOC + "Cleared Dir cache");
895  m_dirCache.clear();
897 }
898 
899 
907 QStringList DirectoryView::RemoveImage(int id, bool deleted)
908 {
909  QStringList urls;
910  int dirId = id;
911 
912  if (deleted)
913  {
914  m_marked.remove(id);
915  m_prevMarked.remove(id);
916  }
917 
918  // If id is a file then start with its parent
919  if (m_fileCache.contains(id))
920  {
921  // Clear file cache & start from its parent dir
922  dirId = m_fileCache.value(id).m_parent;
923  urls = FlatView::ClearImage(id, deleted);
924  }
925 
926  // Clear ancestor dirs
927  while (m_dirCache.contains(dirId))
928  {
929  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Cleared %1 from dir cache").arg(dirId));
930  DirCacheEntry dir = m_dirCache.take(dirId);
931  dirId = dir.m_parent;
932  }
933  return urls;
934 }
935 
936 
944 bool TreeView::LoadFromDb(int parentId)
945 {
946  m_parentId = parentId;
947 
948  // Load visible subtree of the parent
949  // Ordered images of parent first, then breadth-first recursion of ordered dirs
950  ImageList files;
951  m_mgr.GetImageTree(m_parentId, files);
952 
953  // Load view
954  Populate(files);
955 
956  return !files.isEmpty();
957 }
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:164
MarkedFiles::Add
void Add(const ImageIdList &newIds)
Definition: galleryviews.cpp:30
PHOTO_DB_ID
#define PHOTO_DB_ID
Definition: imagetypes.h:28
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:313
ImageDbReader::GetImages
int GetImages(const ImageIdList &ids, ImageList &files, ImageList &dirs) const
Returns images (local or remote but not a combination)
Definition: imagemanager.cpp:1853
FlatView::HasNext
ImagePtrK HasNext(int inc) const
Peeks at next image in view but does not advance iterator.
Definition: galleryviews.cpp:151
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:20
DirectoryView::GetPosition
QString GetPosition() const
Get positional status.
Definition: galleryviews.cpp:489
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:1912
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:944
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:88
FlatView::ClearImage
QStringList ClearImage(int id, bool remove=false)
Clear file from UI cache and optionally from view.
Definition: galleryviews.cpp:404
FileCacheEntry
Records info of displayed image files to enable clean-up of the UI image cache.
Definition: galleryviews.h:77
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:1821
DEFAULT_WEIGHT
const double DEFAULT_WEIGHT
Photos without an exif timestamp will default to the mode of the beta distribution.
Definition: galleryviews.cpp:25
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:741
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:431
FlatView::LoadFromDb
virtual bool LoadFromDb(int parentId)
Populate view with database images from a directory.
Definition: galleryviews.cpp:372
DirectoryView::PopulateFromCache
bool PopulateFromCache(ImageItem &dir, int required)
Retrieve cached dir, if available.
Definition: galleryviews.cpp:845
arg
arg(title).arg(filename).arg(doDelete))
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:23
FlatView
A datastore of images for display by a screen.
Definition: galleryviews.h:99
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:22
kMaxFolderThumbnails
static const int kMaxFolderThumbnails
Number of thumbnails to use for folders.
Definition: galleryviews.cpp:12
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:214
FlatView::GetPosition
QString GetPosition() const
Get positional status.
Definition: galleryviews.cpp:74
DirectoryView::Cache
void Cache(ImageItemK &dir, int thumbCount)
Cache displayed dir.
Definition: galleryviews.cpp:865
FlatView::ClearCache
void ClearCache()
Clears UI cache.
Definition: galleryviews.cpp:391
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:116
FlatView::Prev
ImagePtrK Prev(int inc)
Decrements iterator and returns previous image. Wraps at start.
Definition: galleryviews.cpp:196
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
FlatView::Update
bool Update(int id)
Updates view with images that have been updated.
Definition: galleryviews.cpp:85
DirectoryView::MarkAll
void MarkAll()
Mark all images/dirs.
Definition: galleryviews.cpp:728
MythDate::fromSecsSinceEpoch
MBASE_PUBLIC QDateTime fromSecsSinceEpoch(uint seconds)
This function takes the number of seconds since the start of the epoch and returns a QDateTime with t...
Definition: mythdate.cpp:68
DirCacheEntry
Records dir info for every displayed dir.
Definition: galleryviews.h:146
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:477
mark
Definition: lang.cpp:21
FlatView::HasPrev
ImagePtrK HasPrev(int inc) const
Peeks at previous image in view but does not decrement iterator.
Definition: galleryviews.cpp:185
LOC
#define LOC
Definition: galleryviews.cpp:9
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:50
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:53
DirectoryView::InvertMarked
void InvertMarked()
Mark all unmarked items, unmark all marked items.
Definition: galleryviews.cpp:760
ImageListK
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:165
FlatView::GetSelected
ImagePtrK GetSelected() const
Get current selection.
Definition: galleryviews.cpp:63
DirectoryView::SetDirectory
void SetDirectory(int newParent)
Manage markings on tree navigation.
Definition: galleryviews.cpp:782
DirCacheEntry::m_fileCount
int m_fileCount
Definition: galleryviews.h:159
FlatView::Clear
void Clear(bool resetParent=true)
Reset view.
Definition: galleryviews.cpp:137
ImageList
QVector< ImagePtr > ImageList
Definition: imagetypes.h:159
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:110
DirCacheEntry::ToString
QString ToString(int id) const
Definition: galleryviews.cpp:462
ImageItem::m_dirCount
int m_dirCount
Id & URLs of thumbnail(s). 1 for a file, 4 for dirs.
Definition: imagetypes.h:111
FlatView::Next
ImagePtrK Next(int inc)
Advance iterator and return next image, wrapping if necessary. Regenerates unordered views on wrap.
Definition: galleryviews.cpp:163
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:503
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:575
ImagePtr
QSharedPointer< ImageItem > ImagePtr
Definition: imagetypes.h:158
DirCacheEntry::m_thumbCount
int m_thumbCount
Definition: galleryviews.h:157
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1174
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:59
DirectoryView::GetMenuSubjects
MenuSubjects GetMenuSubjects()
Determine current selection, markings & various info to support menu display.
Definition: galleryviews.cpp:812
MarkedFiles::Invert
void Invert(const ImageIdList &all)
Definition: galleryviews.cpp:36
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:1874
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:600
SlideOrderType
SlideOrderType
Order of images in slideshow.
Definition: galleryviews.h:21
DirectoryView::ClearCache
void ClearCache()
Clears UI cache.
Definition: galleryviews.cpp:892
DirectoryView::Clear
void Clear(bool resetParent=true)
Resets view.
Definition: galleryviews.cpp:717
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:907
WeightList
QVector< double > WeightList
Seasonal weightings for images in a view.
Definition: galleryviews.h:30
ThumbPair
QPair< int, QString > ThumbPair
Definition: imagetypes.h:63
ImageItem::m_userThumbnail
int m_userThumbnail
Id of thumbnail to use as cover (dirs only)
Definition: imagetypes.h:105
kOrdered
@ kOrdered
Ordered as per user setting GallerySortOrder.
Definition: galleryviews.h:22
BETA_CLIP
const qint64 BETA_CLIP
The edges of the distribution get clipped to avoid a singularity.
Definition: galleryviews.cpp:28
FlatView::Cache
void Cache(int id, int parent, const QString &url, const QString &thumb)
Cache image properties to optimize UI.
Definition: galleryviews.cpp:452
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:771
kRandom
@ kRandom
Random selection from view. An image may be absent or appear multiple times.
Definition: galleryviews.h:24
DirCacheEntry::m_dirCount
int m_dirCount
Definition: galleryviews.h:158
GALLERY_DB_ID
#define GALLERY_DB_ID
Definition: imagetypes.h:26
ImageItem::m_fileCount
int m_fileCount
Number of child images (dirs only)
Definition: imagetypes.h:112
FlatView::m_active
int m_active
Sequence index of current selected image.
Definition: galleryviews.h:135