Go to the documentation of this file.
12 #define LOC QString("Galleryviews: ")
31 static constexpr qint64
BETA_CLIP { 24LL * 60 * 60 };
35 for (
int newid : newIds)
42 for (
int tmpint : all)
44 for (
int tmpint : qAsConst(*
this))
68 return m_active < 0 || m_active >=
m_sequence.size()
106 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"Modified id %1").arg(
id));
225 for (
const QSharedPointer<ImageItem> & im : qAsConst(files))
232 Cache(im->m_id, im->m_parentId, im->m_url, im->m_thumbNails.at(0).second);
238 for (
const QSharedPointer<ImageItem> & im : qAsConst(files))
242 if (files.size() > 1)
248 std::mt19937(std::random_device()()));
255 int size = files.size();
256 int range = files.size() - 1;
276 std::vector<uint32_t> weights;
277 weights.reserve(cdf.size());
278 for (
int i = 0; i < cdf.size(); i++)
280 weights.emplace_back(lround(cdf[i] / cdf.back() * UINT32_MAX));
284 uint32_t maxWeight = weights.back() - 1;
286 for (
int count = 0; count < files.size(); ++count)
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);
311 double totalWeight = 0;
312 QDateTime now = QDateTime::currentDateTime();
314 for (
int i = 0; i < files.size(); ++i)
319 if (im->m_date == 0s)
324 QDateTime curYearAnniversary =
325 QDateTime(QDate(now.date().year(),
326 timestamp.date().month(),
327 timestamp.date().day()),
330 bool isAnniversaryPast = curYearAnniversary < now;
332 QDateTime adjacentYearAnniversary =
333 QDateTime(QDate(now.date().year() +
334 (isAnniversaryPast ? 1 : -1),
335 timestamp.date().month(),
336 timestamp.date().day()),
339 double range = llabs(curYearAnniversary.secsTo(
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,
354 totalWeight += weight;
355 weights[i] = totalWeight;
379 return !files.isEmpty();
388 LOG(VB_FILE, LOG_DEBUG,
LOC +
"Cleared File cache");
410 if (!
file.m_url.isEmpty())
413 if (!
file.m_thumbUrl.isEmpty())
414 urls <<
file.m_thumbUrl;
416 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"Cleared %1 from file cache (%2)")
417 .arg(
id).arg(urls.join(
",")));
460 for (
const auto & thumb : qAsConst(
m_thumbs))
461 ids << QString::number(thumb.first);
462 return QString(
"Dir %1 (%2, %3) Thumbs %4 (%5) Parent %6")
524 for (
const ImagePtr & im : qAsConst(dirs))
542 for (
const QSharedPointer<ImageItem> & im : qAsConst(images))
543 ids.insert(im->m_id);
548 images.prepend(parent);
552 int activeId = selected ? selected->m_id : 0;
609 for (
const ImagePtr & im : qAsConst(images))
629 else if (userIm->IsFile())
631 thumbFiles.append(userIm);
635 thumbDirs.append(userIm);
639 for (
int i = 0; i < std::min(kMaxFolderThumbnails, static_cast<int>(thumbFiles.size())); ++i)
641 parent.
m_thumbNails.append(thumbFiles.at(i)->m_thumbNails.at(0));
646 if (thumbsNeeded > 0)
652 LOG(VB_GENERAL, LOG_NOTICE,
LOC +
653 "Directory thumbnails are more than 10 levels deep");
658 for (
const ImagePtr & im : qAsConst(thumbDirs))
667 if (!im->m_thumbNails.empty())
673 if (--thumbsNeeded == 0)
683 for (
const QSharedPointer<ImageItem> & im : qAsConst(thumbDirs))
685 if (i < im->m_thumbNails.size())
688 if (--thumbsNeeded == 0)
699 int scanned = (userIm || thumbsNeeded > 0)
704 Cache(parent, scanned);
811 bool hiddenMarked =
false;
812 bool unhiddenMarked =
false;
822 unhiddenMarked =
true;
824 if (hiddenMarked && unhiddenMarked)
830 hiddenMarked, unhiddenMarked};
889 LOG(VB_FILE, LOG_DEBUG,
LOC +
"Cleared Dir cache");
924 LOG(VB_FILE, LOG_DEBUG,
LOC + QString(
"Cleared %1 from dir cache").arg(dirId));
951 return !files.isEmpty();
QSharedPointer< ImageItemK > ImagePtrK
void Add(const ImageIdList &newIds)
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...
int GetImages(const ImageIdList &ids, ImageList &files, ImageList &dirs) const
Returns images (local or remote but not a combination)
ImagePtrK HasNext(int inc) const
Peeks at next image in view but does not advance iterator.
const double LEADING_BETA_SHAPE
Tuning parameter for seasonal weights, between 0 and 1, where lower numbers give greater weight to se...
QString GetPosition() const
Get positional status.
void GetImageTree(int id, ImageList &files) const
Return all files (local or remote) in the sub-trees of a dir.
bool LoadFromDb(int parentId) override
Populate view from database as images of a directory sub-tree. Default order of a tree is depth-first...
QHash< int, ImagePtrK > m_images
Image objects currently displayed.
int m_id
Uniquely identifies an image (file/dir).
QStringList ClearImage(int id, bool remove=false)
Clear file from UI cache and optionally from view.
Records info of displayed image files to enable clean-up of the UI image cache.
int GetDirectory(int id, ImagePtr &parent, ImageList &files, ImageList &dirs) const
Return images (local and/or remote) for a dir and its direct children.
const double DEFAULT_WEIGHT
Photos without an exif timestamp will default to the mode of the beta distribution.
const static int kMaxFolderThumbnails
Number of thumbnails to use for folders.
void Mark(int id, bool mark)
Mark/unmark an image/dir.
QList< ThumbPair > m_thumbs
void Rotate(int id)
Rotate view so that starting image is at front.
virtual bool LoadFromDb(int parentId)
Populate view with database images from a directory.
bool PopulateFromCache(ImageItem &dir, int required)
Retrieve cached dir, if available.
QString ToString(int id) const
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
A datastore of images for display by a screen.
@ kSeasonal
Biased random selection so that images are more likely to appear on anniversaries.
const double TRAILING_BETA_SHAPE
See LEADING_BETA_SHAPE.
void Populate(ImageList &files)
Fills view with Db images, re-ordering them as required.
QString GetPosition() const
Get positional status.
void Cache(ImageItemK &dir, int thumbCount)
Cache displayed dir.
void ClearCache()
Clears UI cache.
QHash< int, DirCacheEntry > m_dirCache
Caches displayed image dirs.
bool Select(int id, int fallback=0)
Selects first occurrence of an image.
ImagePtrK Prev(int inc)
Decrements iterator and returns previous image. Wraps at start.
bool Update(int id)
Updates view with images that have been updated.
void MarkAll()
Mark all images/dirs.
static constexpr qint64 BETA_CLIP
The edges of the distribution get clipped to avoid a singularity.
Records dir info for every displayed dir.
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...
QHash< int, FileCacheEntry > m_fileCache
Caches displayed image files.
DirectoryView(SlideOrderType order)
Constructs a view of images & directories that can be marked.
ImagePtrK HasPrev(int inc) const
Peeks at previous image in view but does not decrement iterator.
@ kShuffle
Each image appears exactly once, but in random order.
ImageListK GetAllNodes() const
Get all images/dirs in view.
void InvertMarked()
Mark all unmarked items, unmark all marked items.
QList< ImagePtrK > ImageListK
ImagePtrK GetSelected() const
Get current selection.
void SetDirectory(int newParent)
Manage markings on tree navigation.
void Clear(bool resetParent=true)
Reset view.
QVector< ImagePtr > ImageList
MarkedFiles m_prevMarked
Marked items in previous dir.
QList< ThumbPair > m_thumbNails
QString ToString(int id) const
int m_dirCount
Id & URLs of thumbnail(s). 1 for a file, 4 for dirs.
ImagePtrK Next(int inc)
Advance iterator and return next image, wrapping if necessary. Regenerates unordered views on wrap.
bool LoadFromDb(int parentId) override
Populate view from database as images/subdirs of a directory. View is ordered: Parent dir,...
MarkedFiles m_marked
Marked items in current dir/view.
Provides view datastores for Gallery screens.
void LoadDirThumbs(ImageItem &parent, int thumbsNeeded, int level=0)
Populate thumbs for a dir.
QSharedPointer< ImageItem > ImagePtr
Represents a picture, video or directory.
ImageIdList m_sequence
The sequence in which to display images.
int m_parentId
Id of parent dir.
MenuSubjects GetMenuSubjects()
Determine current selection, markings & various info to support menu display.
static constexpr int PHOTO_DB_ID
void Invert(const ImageIdList &all)
int GetChildren(int id, ImageList &files, ImageList &dirs) const
Return (local or remote) images that are direct children of a dir.
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,...
SlideOrderType
Order of images in slideshow.
void ClearCache()
Clears UI cache.
void Clear(bool resetParent=true)
Resets view.
QStringList RemoveImage(int id, bool deleted=false)
Clear file/dir and all its ancestors from UI cache so that ancestor thumbnails are recalculated....
QVector< double > WeightList
Seasonal weightings for images in a view.
QPair< int, QString > ThumbPair
int m_userThumbnail
Id of thumbnail to use as cover (dirs only)
@ kOrdered
Ordered as per user setting GallerySortOrder.
void Cache(int id, int parent, const QString &url, const QString &thumb)
Cache image properties to optimize UI.
static constexpr int GALLERY_DB_ID
ImageIdList GetChildren() const
void ClearMarked()
Unmark all items.
@ kRandom
Random selection from view. An image may be absent or appear multiple times.
uint32_t MythRandom()
generate 32 random bits
int m_fileCount
Number of child images (dirs only)
int m_active
Sequence index of current selected image.