MythTV  master
imagemanager.cpp
Go to the documentation of this file.
1 #include "imagemanager.h"
2 
3 #include <QImageReader>
4 #include <QRunnable>
5 #include <utility>
6 
7 #include "dbaccess.h" // for FileAssociations
8 #include "mthreadpool.h"
9 #include "mythdate.h"
10 #include "mythmediamonitor.h"
11 
12 
13 #define LOC QString("ImageManager: ")
14 #define DBLOC QString("ImageDb(%1): ").arg(m_table)
15 
16 // Must be empty as it's prepended to path
17 #define STORAGE_GROUP_MOUNT ""
18 
19 #define DB_TABLE "gallery_files"
20 
21 #define RESULT_ERR(ERR, MESG) \
22 { LOG(VB_GENERAL, LOG_ERR, LOC + (MESG)); \
23  return QStringList("ERROR") << (ERR); }
24 
25 #define RESULT_OK(MESG) \
26 { LOG(VB_FILE, LOG_DEBUG, LOC + (MESG)); \
27  return QStringList("OK"); }
28 
29 #define IMPORTDIR "Import"
30 
31 
33 class Device
34 {
35 public:
36  Device(QString name, QString mount,
37  MythMediaDevice *media = nullptr, QTemporaryDir *import = nullptr)
38  : m_present(true), m_name(std::move(name)), m_mount(std::move(mount)),
39  m_media(media), m_dir(import)
40  {
41  // Path relative to TEMP storage group
42  m_thumbs = QString("%1/%2").arg(THUMBNAIL_SUBDIR, m_name);
43  }
44 
45 
48  {
49  Close();
50 
51  // Remove imported images
52  delete m_dir;
53 
54  // Clean up non-SG thumbnails
56  RemoveThumbs();
57  }
58 
59 
61  void Close(bool eject = false)
62  {
63  // Imports remain present; others do not
64  m_present = isImport();
65 
66  // Release device
67  if (m_media)
68  {
69  if (eject)
70  {
71  LOG(VB_GENERAL, LOG_INFO, LOC + QString("Ejecting '%1' at '%2'")
72  .arg(m_name, m_mount));
74  }
75  else
76  LOG(VB_MEDIA, LOG_DEBUG, LOC + QString("Unlocked '%1'").arg(m_name));
77 
79  m_media = nullptr;
80  }
81  }
82 
83 
88  static void RemoveDirContents(const QString& path)
89  {
90  QDir(path).removeRecursively();
91  }
92 
93 
95  void RemoveThumbs(void) const
96  {
97  // Remove thumbnails
98  QString dir = QString("%1/" TEMP_SUBDIR "/%2").arg(GetConfDir(), m_thumbs);
99  LOG(VB_FILE, LOG_INFO, LOC + QString("Removing thumbnails in %1").arg(dir));
100  RemoveDirContents(dir);
101  QDir::root().rmpath(dir);
102  }
103 
104 
105  bool isImport() const { return m_dir; }
106  bool isPresent() const { return m_present; }
107  void setPresent(MythMediaDevice *media) { m_present = true; m_media = media; }
108 
110  bool m_present;
111  QString m_name;
112  QString m_mount;
113  QString m_thumbs;
115  QTemporaryDir *m_dir;
116 };
117 
118 
119 static Device kNullDevice = Device("Unknown Device", "<Invalid Path>");
120 
121 
123 {
124  qDeleteAll(m_devices);
125 }
126 
127 
129 QString DeviceManager::DeviceMount(int devId) const
130 {
131  return m_devices.value(devId, &kNullDevice)->m_mount;
132 }
133 
134 
136 QString DeviceManager::DeviceName(int devId) const
137 {
138  return m_devices.value(devId, &kNullDevice)->m_name;
139 }
140 
141 
142 QString DeviceManager::ThumbDir(int fs) const
143 {
144  return m_devices.value(fs, &kNullDevice)->m_thumbs;
145 }
146 
147 
157 int DeviceManager::OpenDevice(const QString &name, const QString &mount,
158  MythMediaDevice *media, QTemporaryDir *dir)
159 {
160  // Handle devices reappearing at same mountpoint.
161  // If a USB is unplugged whilst in use (without unmounting) we get no event
162  // but we do when it's re-inserted
163  QString state("Known");
164  int id = LocateMount(mount);
165 
166  if (id == DEVICE_INVALID)
167  {
168  state = "New";
169  id = m_devices.isEmpty() ? 0 : m_devices.lastKey() + 1;
170  m_devices.insert(id, new Device(name, mount, media, dir));
171  }
172  else if (m_devices.value(id))
173  m_devices.value(id)->setPresent(media);
174 
175  LOG(VB_GENERAL, LOG_INFO, LOC +
176  QString("%1 device %2 mounted at '%3' [Id %4]")
177  .arg(state, name, mount).arg(id));
178 
179  return id;
180 }
181 
182 
189 QStringList DeviceManager::CloseDevices(int devId, const QString &action)
190 {
191  QStringList clear;
192 
193  if (action == "DEVICE CLOSE ALL")
194  {
195  // Close all devices but retain their thumbnails
196  for (auto *dev : qAsConst(m_devices))
197  if (dev)
198  dev->Close();
199  }
200  else if (action == "DEVICE CLEAR ALL")
201  {
202  // Remove all thumbnails but retain devices
203  for (const auto *dev : qAsConst(m_devices)) {
204  if (dev)
205  {
206  clear << dev->m_mount;
207  dev->RemoveThumbs();
208  }
209  }
210  }
211  else
212  {
213  // Remove single device & its thumbnails, optionally ejecting it
214  Device *dev = m_devices.take(devId);
215  if (dev)
216  {
217  if (action == "DEVICE EJECT")
218  dev->Close(true);
219  clear << dev->m_mount;
220  delete dev;
221  }
222  }
223  return clear;
224 }
225 
226 
232 int DeviceManager::LocateMount(const QString &mount) const
233 {
234  DeviceMap::const_iterator it = m_devices.constBegin();
235  while (it != m_devices.constEnd())
236  {
237  if (it.value()->m_mount == mount)
238  return it.key();
239  ++it;
240  }
241  return DEVICE_INVALID;
242 }
243 
244 
247 {
249 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
250  for (int id : m_devices.keys())
251  {
252  Device *dev = m_devices.value(id);
253  if (dev)
254  paths.insert(id, dev->m_mount);
255  }
256 #elif QT_VERSION < QT_VERSION_CHECK(5,15,0)
257  for (auto it = m_devices.constKeyValueBegin();
258  it != m_devices.constKeyValueEnd(); ++it)
259  {
260  if ((*it).second)
261  paths.insert((*it).first, (*it).second->m_mount);
262  }
263 #else
264  for (auto it = m_devices.constKeyValueBegin();
265  it != m_devices.constKeyValueEnd(); ++it)
266  {
267  if (it->second)
268  paths.insert(it->first, it->second->m_mount);
269  }
270 #endif
271  return paths;
272 }
273 
274 
277 {
278  QList<int> absent;
279 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
280  for (int id : m_devices.keys())
281  {
282  Device *dev = m_devices.value(id);
283  if (dev && !dev->isPresent())
284  absent << id;
285  }
286 #elif QT_VERSION < QT_VERSION_CHECK(5,15,0)
287  for (auto it = m_devices.constKeyValueBegin();
288  it != m_devices.constKeyValueEnd(); it++)
289  {
290  Device *dev = (*it).second;
291  if (dev && !dev->isPresent())
292  absent << (*it).first;
293  }
294 #else
295  for (auto it = m_devices.constKeyValueBegin();
296  it != m_devices.constKeyValueEnd(); it++)
297  {
298  Device *dev = it->second;
299  if (dev && !dev->isPresent())
300  absent << it->first;
301  }
302 #endif
303  return absent;
304 }
305 
306 
311  m_imageFileExt(SupportedImages()),
312  m_videoFileExt(SupportedVideos())
313 {
314  // Generate glob list from supported extensions
315  QStringList glob;
316  QStringList allExt = m_imageFileExt + m_videoFileExt;
317  for (const auto& ext : qAsConst(allExt))
318  glob << "*." + ext;
319 
320  // Apply filters to only detect image files
321  m_dirFilter.setNameFilters(glob);
322  m_dirFilter.setFilter(QDir::AllDirs | QDir::Files | QDir::Readable |
323  QDir::NoDotAndDotDot | QDir::NoSymLinks);
324 
325  // Sync files before dirs to improve thumb generation response
326  // Order by time (oldest first) - this determines the order thumbs appear
327  m_dirFilter.setSorting(QDir::DirsLast | QDir::Time | QDir::Reversed);
328 }
329 
335 {
336  // Determine supported picture formats from Qt
337  QStringList formats;
338  QList<QByteArray> supported = QImageReader::supportedImageFormats();
339  for (const auto& ext : qAsConst(supported))
340  formats << QString(ext);
341  return formats;
342 }
343 
344 
350 {
351  // Determine supported video formats from MythVideo
352  QStringList formats;
355  for (const auto & fa : faList)
356  {
357  if (!fa.use_default && fa.playcommand == "Internal")
358  formats << QString(fa.extension);
359  }
360  return formats;
361 }
362 
363 
372 ImageItem *ImageAdapterLocal::CreateItem(const QFileInfo &fi, int parentId,
373  int devId, const QString & /*base*/) const
374 {
375  auto *im = new ImageItem();
376 
377  im->m_parentId = parentId;
378  im->m_device = devId;
379  im->m_filePath = fi.absoluteFilePath();
380 
381  if (parentId == GALLERY_DB_ID)
382  {
383  // Import devices show time of import, other devices show 'last scan time'
384  auto secs = im->m_filePath.contains(IMPORTDIR)
385  ? fi.lastModified().toSecsSinceEpoch()
386  : QDateTime::currentSecsSinceEpoch();
387  im->m_date = std::chrono::seconds(secs);
388  im->m_modTime = im->m_date;
389  im->m_type = kDevice;
390  return im;
391  }
392 
393  im->m_modTime = std::chrono::seconds(fi.lastModified().toSecsSinceEpoch());
394 
395  if (fi.isDir())
396  {
397  im->m_type = kDirectory;
398  return im;
399  }
400 
401  im->m_extension = fi.suffix().toLower();
402  im->m_type = GetImageType(im->m_extension);
403 
404  if (im->m_type == kUnknown)
405  {
406  delete im;
407  return nullptr;
408  }
409 
410  im->m_thumbPath = GetAbsThumbPath(ThumbDir(im->m_device), ThumbPath(*im));
411  im->m_size = fi.size();
412 
413  return im;
414 }
415 
416 
422 void ImageAdapterLocal::Notify(const QString &mesg,
423  const QStringList &extra)
424 {
425  QString host(gCoreContext->GetHostName());
426  gCoreContext->SendEvent(MythEvent(QString("%1 %2").arg(mesg, host), extra));
427 }
428 
429 
438 ImageItem *ImageAdapterSg::CreateItem(const QFileInfo &fi, int parentId,
439  int /*devId*/, const QString &base) const
440 {
441  auto *im = new ImageItem();
442 
443  im->m_device = 0;
444  im->m_parentId = parentId;
445 
446  if (parentId == GALLERY_DB_ID)
447  {
448  // All SG dirs map to a single Db dir
449  im->m_filePath = "";
450  im->m_type = kDevice;
451  im->m_date = std::chrono::seconds(QDateTime::currentSecsSinceEpoch());
452  im->m_modTime = im->m_date;
453  return im;
454  }
455 
456  // Strip SG path & leading / to leave a relative path
457  im->m_filePath = fi.absoluteFilePath().mid(base.size() + 1);
458  im->m_modTime = std::chrono::seconds(fi.lastModified().toSecsSinceEpoch());
459 
460  if (fi.isDir())
461  {
462  im->m_type = kDirectory;
463  return im;
464  }
465 
466  im->m_extension = fi.suffix().toLower();
467  im->m_type = GetImageType(im->m_extension);
468 
469  if (im->m_type == kUnknown)
470  {
471  delete im;
472  return nullptr;
473  }
474 
475  im->m_thumbPath = GetAbsThumbPath(ThumbDir(im->m_device), ThumbPath(*im));
476  im->m_size = fi.size();
477 
478  return im;
479 }
480 
481 
487 void ImageAdapterSg::Notify(const QString &mesg,
488  const QStringList &extra)
489 {
490  gCoreContext->SendEvent(MythEvent(mesg, extra));
491 }
492 
493 
499 {
500  StringMap map;
501  int i = 0;
502  QStringList paths = m_sg.GetDirList();
503  for (const auto& path : qAsConst(paths))
504  map.insert(i++, path);
505  return map;
506 }
507 
508 
516 {
517  if (im->IsDevice())
518  return m_sg.FindNextDirMostFree();
519  return im->m_filePath.startsWith("/") ? im->m_filePath
520  : m_sg.FindFile(im->m_filePath);
521 }
522 
523 
524 // Database fields used by several image queries
525 #define DB_COLUMNS \
526 "file_id, filename, name, dir_id, type, modtime, size, " \
527 "extension, date, hidden, orientation, angle, path, zoom"
528 // Id, filepath, basename, parentId, type, modtime, size,
529 // extension, image date, hidden, orientation, cover id, comment, device id
530 
531 
537 template <class FS>
539 {
540  auto *im = new ImageItem(FS::ImageId(query.value(0).toInt()));
541 
542  // Ordered as per DB_COLUMNS
543  im->m_filePath = query.value(1).toString();
544  im->m_baseName = query.value(2).toString();
545  im->m_parentId = FS::ImageId(query.value(3).toInt());
546  im->m_type = query.value(4).toInt();
547  im->m_modTime = std::chrono::seconds(query.value(5).toInt());
548  im->m_size = query.value(6).toInt();
549  im->m_extension = query.value(7).toString();
550  im->m_date = std::chrono::seconds(query.value(8).toUInt());
551  im->m_isHidden = query.value(9).toBool();
552  im->m_orientation = query.value(10).toInt();
553  im->m_userThumbnail = FS::ImageId(query.value(11).toInt());
554  im->m_comment = query.value(12).toString();
555  im->m_device = query.value(13).toInt();
556  im->m_url = FS::MakeFileUrl(im->m_filePath);
557 
558  if (im->IsFile())
559  {
560  // Only pics/vids have thumbs
561  QString thumbPath(FS::ThumbPath(*im));
562  QString devPath(FS::ThumbDir(im->m_device));
563  QString url(FS::MakeThumbUrl(devPath, thumbPath));
564 
565  im->m_thumbPath = FS::GetAbsThumbPath(devPath, thumbPath);
566  im->m_thumbNails.append(qMakePair(im->m_id, url));
567  }
568  return im;
569 }
570 
571 
580 template <class FS>
581 int ImageDb<FS>::GetImages(const QString &ids, ImageList &files, ImageList &dirs,
582  const QString &refine) const
583 {
584  if (ids.isEmpty())
585  return 0;
586 
587  QString select = QString("file_id IN (%1) %2").arg(FS::DbIds(ids), refine);
588  return ReadImages(dirs, files, select);
589 }
590 
591 
600 template <class FS>
601 int ImageDb<FS>::GetChildren(const QString &ids, ImageList &files, ImageList &dirs,
602  const QString &refine) const
603 {
604  QString select = QString("dir_id IN (%1) %2").arg(FS::DbIds(ids), refine);
605  return ReadImages(dirs, files, select);
606 }
607 
608 
618 template <class FS>
620  ImageList &files, ImageList &dirs,
621  const QString &refine) const
622 {
623  MSqlQuery query(MSqlQuery::InitCon());
624  query.prepare(QString("SELECT " DB_COLUMNS " FROM %1 "
625  "WHERE (dir_id = :ID1 OR file_id = :ID2) "
626  "%2;").arg(m_table, refine));
627 
628  // Qt < 5.4 won't bind multiple occurrences
629  int dbId = FS::DbId(id);
630  query.bindValue(":ID1", dbId);
631  query.bindValue(":ID2", dbId);
632 
633  if (!query.exec())
634  {
635  MythDB::DBError(DBLOC, query);
636  return -1;
637  }
638  while (query.next())
639  {
640  ImagePtr im(CreateImage(query));
641 
642  if (im->IsFile())
643  files.append(im);
644  else if (im->m_id == id)
645  parent = im;
646  else
647  dirs.append(im);
648  }
649  return query.size();
650 }
651 
652 
660 template <class FS>
661 bool ImageDb<FS>::GetDescendants(const QString &ids,
662  ImageList &files, ImageList &dirs) const
663 {
664  if (ids.isEmpty())
665  return false;
666 
667  if (ReadImages(dirs, files, QString("file_id IN (%1)").arg(FS::DbIds(ids))) < 0)
668  return false;
669 
670  MSqlQuery query(MSqlQuery::InitCon());
671  QString sql =
672  QString("SELECT " DB_COLUMNS
673  ", LENGTH(filename) - LENGTH(REPLACE(filename, '/', ''))"
674  " AS depth "
675  "FROM %1 WHERE filename LIKE :PREFIX "
676  "ORDER BY depth;").arg(m_table);
677 
678  for (const auto& im1 : qAsConst(dirs))
679  {
680  query.prepare(sql);
681  query.bindValue(":PREFIX", im1->m_filePath + "/%");
682 
683  if (!query.exec())
684  {
685  MythDB::DBError(DBLOC, query);
686  return false;
687  }
688 
689  while (query.next())
690  {
691  ImagePtr im2(CreateImage(query));
692  if (im2->IsDirectory())
693  dirs.append(im2);
694  else
695  files.append(im2);
696  }
697  }
698  return true;
699 }
700 
701 
709 template <class FS>
710 bool ImageDb<FS>::GetImageTree(int id, ImageList &files, const QString &refine) const
711 {
712  // Load starting children
713  ImageList dirs;
714  if (GetChildren(QString::number(id), files, dirs, refine) < 0)
715  return false;
716 
717  for (const auto& im : qAsConst(dirs))
718  if (!GetImageTree(im->m_id, files, refine))
719  return false;
720  return true;
721 }
722 
723 
729 template <class FS>
731 {
732  MSqlQuery query(MSqlQuery::InitCon());
733  query.prepare(QString("SELECT " DB_COLUMNS " FROM %1").arg(m_table));
734 
735  if (!query.exec())
736  {
737  MythDB::DBError(DBLOC, query);
738  return false;
739  }
740 
741  while (query.next())
742  {
743  ImagePtr im(CreateImage(query));
744  if (im->IsDirectory())
745  dirs.insert(im->m_filePath, im);
746  else
747  files.insert(im->m_filePath, im);
748  }
749  return true;
750 }
751 
752 
760 template <class FS>
761 void ImageDb<FS>::ClearDb(int devId, const QString &action)
762 {
763  if (action == "DEVICE CLOSE ALL")
764  // Retain Db images when closing UI
765  return;
766 
767  MSqlQuery query(MSqlQuery::InitCon());
768 
769  if (action == "DEVICE CLEAR ALL")
770  {
771  // Clear images from all devices. Reset auto-increment
772  query.prepare(QString("TRUNCATE TABLE %1;").arg(m_table));
773 
774  if (!query.exec())
775  MythDB::DBError(DBLOC, query);
776  }
777  else // Actions DEVICE REMOVE & DEVICE EJECT
778  {
779  // Delete all images of the device
780  query.prepare(QString("DELETE IGNORE FROM %1 WHERE zoom = :FS;").arg(m_table));
781  query.bindValue(":FS", devId);
782 
783  if (!query.exec())
784  MythDB::DBError(DBLOC, query);
785  }
786 }
787 
788 
796 template <class FS>
797 int ImageDb<FS>::InsertDbImage(ImageItemK &im, bool checkForDuplicate) const
798 {
799  MSqlQuery query(MSqlQuery::InitCon());
800 
801  if (checkForDuplicate)
802  {
803  query.prepare(QString("SELECT file_id FROM %1 WHERE filename = :NAME;")
804  .arg(m_table));
805 
806  query.bindValue(":NAME", im.m_filePath);
807 
808  if (!query.exec())
809  {
810  MythDB::DBError(DBLOC, query);
811  return -1;
812  }
813 
814  if (query.size() > 0)
815  {
816  LOG(VB_FILE, LOG_DEBUG, QString("Image: %1 already exists in Db")
817  .arg(im.m_filePath));
818  return query.value(0).toInt();
819  }
820  }
821 
822  query.prepare(QString("INSERT INTO %1 (" DB_COLUMNS ") VALUES (0, "
823  ":FILEPATH, :NAME, :PARENT, :TYPE, :MODTIME, "
824  ":SIZE, :EXTENSION, :DATE, :HIDDEN, :ORIENT, "
825  ":COVER, :COMMENT, :FS);").arg(m_table));
826 
827  query.bindValue(":FILEPATH", im.m_filePath);
828  query.bindValue(":NAME", FS::BaseNameOf(im.m_filePath));
829  query.bindValue(":FS", im.m_device);
830  query.bindValue(":PARENT", FS::DbId(im.m_parentId));
831  query.bindValue(":TYPE", im.m_type);
832  query.bindValue(":MODTIME", static_cast<qint64>(im.m_modTime.count()));
833  query.bindValue(":SIZE", im.m_size);
834  query.bindValue(":EXTENSION", im.m_extension);
835  query.bindValue(":DATE", static_cast<qint64>(im.m_date.count()));
836  query.bindValue(":ORIENT", im.m_orientation);
837  query.bindValue(":COMMENT", im.m_comment.isNull() ? "" : im.m_comment);
838  query.bindValue(":HIDDEN", im.m_isHidden);
839  query.bindValue(":COVER", FS::DbId(im.m_userThumbnail));
840 
841  if (query.exec())
842  return FS::ImageId(query.lastInsertId().toInt());
843 
844  MythDB::DBError(DBLOC, query);
845  return -1;
846 }
847 
848 
854 template <class FS>
856 {
857  MSqlQuery query(MSqlQuery::InitCon());
858  query.prepare(QString
859  ("UPDATE %1 SET "
860  "filename = :FILEPATH, name = :NAME, "
861  "dir_id = :PARENT, type = :TYPE, "
862  "modtime = :MODTIME, size = :SIZE, "
863  "extension = :EXTENSION, date = :DATE, zoom = :FS, "
864  "hidden = :HIDDEN, orientation = :ORIENT, "
865  "angle = :COVER, path = :COMMENT "
866  "WHERE file_id = :ID;").arg(m_table));
867 
868  query.bindValue(":ID", FS::DbId(im.m_id));
869  query.bindValue(":FILEPATH", im.m_filePath);
870  query.bindValue(":NAME", FS::BaseNameOf(im.m_filePath));
871  query.bindValue(":PARENT", FS::DbId(im.m_parentId));
872  query.bindValue(":TYPE", im.m_type);
873  query.bindValue(":MODTIME", static_cast<qint64>(im.m_modTime.count()));
874  query.bindValue(":SIZE", im.m_size);
875  query.bindValue(":EXTENSION", im.m_extension);
876  query.bindValue(":DATE", static_cast<qint64>(im.m_date.count()));
877  query.bindValue(":FS", im.m_device);
878  query.bindValue(":HIDDEN", im.m_isHidden);
879  query.bindValue(":ORIENT", im.m_orientation);
880  query.bindValue(":COVER", FS::DbId(im.m_userThumbnail));
881  query.bindValue(":COMMENT", im.m_comment.isNull() ? "" : im.m_comment);
882 
883  if (query.exec())
884  return true;
885 
886  MythDB::DBError(DBLOC, query);
887  return false;
888 }
889 
890 
897 template <class FS>
898 QStringList ImageDb<FS>::RemoveFromDB(const ImageList &imList) const
899 {
900  QStringList ids;
901  if (!imList.isEmpty())
902  {
903  for (const auto& im : qAsConst(imList))
904  ids << QString::number(FS::DbId(im->m_id));
905 
906  QString idents = ids.join(",");
907  MSqlQuery query(MSqlQuery::InitCon());
908  query.prepare(QString("DELETE IGNORE FROM %1 WHERE file_id IN (%2);")
909  .arg(m_table, idents));
910 
911  if (!query.exec())
912  {
913  MythDB::DBError(DBLOC, query);
914  return QStringList();
915  }
916  }
917  return ids;
918 }
919 
920 
927 template <class FS>
928 bool ImageDb<FS>::SetHidden(bool hide, const QString &ids) const
929 {
930  if (ids.isEmpty())
931  return false;
932 
933  MSqlQuery query(MSqlQuery::InitCon());
934 
935  query.prepare(QString("UPDATE %1 SET "
936  "hidden = :HIDDEN "
937  "WHERE file_id IN (%2);").arg(m_table, FS::DbIds(ids)));
938  query.bindValue(":HIDDEN", hide ? 1 : 0);
939 
940  if (query.exec())
941  return true;
942 
943  MythDB::DBError(DBLOC, query);
944  return false;
945 }
946 
947 
953 template <class FS>
954 bool ImageDb<FS>::SetCover(int dir, int id) const
955 {
956  MSqlQuery query(MSqlQuery::InitCon());
957 
958  query.prepare(QString("UPDATE %1 SET "
959  "angle = :COVER "
960  "WHERE file_id = :DIR").arg(m_table));
961  query.bindValue(":COVER", FS::DbId(id));
962  query.bindValue(":DIR", FS::DbId(dir));
963  \
964  if (query.exec())
965  return true;
966 
967  MythDB::DBError(DBLOC, query);
968  return false;
969 }
970 
971 
977 template <class FS>
978 bool ImageDb<FS>::SetOrientation(int id, int orientation) const
979 {
980  MSqlQuery query(MSqlQuery::InitCon());
981 
982  query.prepare(QString("UPDATE %1 SET ").arg(m_table) +
983  "orientation = :ORIENTATION "
984  "WHERE file_id = :ID");
985  query.bindValue(":ORIENTATION", orientation);
986  query.bindValue(":ID", FS::DbId(id));
987  \
988  if (query.exec())
989  return true;
990 
991  MythDB::DBError(DBLOC, query);
992  return false;
993 }
994 
995 
1003 template <class FS>
1005  const QString &selector) const
1006 {
1007  MSqlQuery query(MSqlQuery::InitCon());
1008  query.prepare(QString("SELECT " DB_COLUMNS " FROM %1 WHERE %2")
1009  .arg(m_table, selector));
1010  if (!query.exec())
1011  {
1012  MythDB::DBError(DBLOC, query);
1013  return -1;
1014  }
1015 
1016  while (query.next())
1017  {
1018  ImagePtr im(CreateImage(query));
1019 
1020  if (im->IsFile())
1021  files.append(im);
1022  else
1023  dirs.append(im);
1024  }
1025  return query.size();
1026 }
1027 
1028 
1038 template <class FS>
1039 void ImageDb<FS>::GetDescendantCount(int id, bool all, int &dirs,
1040  int &pics, int &videos, int &sizeKb) const
1041 {
1042  QString whereClause;
1043  if (!all)
1044  {
1045  whereClause = "WHERE filename LIKE "
1046  "( SELECT CONCAT(filename, '/%') "
1047  " FROM %2 WHERE file_id = :ID);";
1048  }
1049 
1050  MSqlQuery query(MSqlQuery::InitCon());
1051  query.prepare(QString("SELECT SUM(type <= :FLDR) AS Fldr, "
1052  " SUM(type = :PIC) AS Pics, "
1053  " SUM(type = :VID) AS Vids, "
1054  " SUM(size / 1024) "
1055  "FROM %2 %1;").arg(whereClause, m_table));
1056 
1057  query.bindValue(":FLDR", kDirectory);
1058  query.bindValue(":PIC", kImageFile);
1059  query.bindValue(":VID", kVideoFile);
1060  if (!all)
1061  query.bindValue(":ID", FS::DbId(id));
1062 
1063  if (!query.exec())
1064  {
1065  MythDB::DBError(DBLOC, query);
1066  }
1067  else if (query.next())
1068  {
1069  dirs += query.value(0).toInt();
1070  pics += query.value(1).toInt();
1071  videos += query.value(2).toInt();
1072  sizeKb += query.value(3).toInt();
1073  }
1074 }
1075 
1076 
1081 {
1082  // Be has a single SG device
1084 }
1085 
1086 
1091  : ImageDb(QString("`%1_%2`").arg(DB_TABLE, gCoreContext->GetHostName()))
1092 {
1093  // Remove any table leftover from a previous FE crash
1094  DropTable();
1095 }
1096 
1097 
1102 {
1103  MSqlQuery query(MSqlQuery::InitCon());
1104  query.prepare(QString("DROP TABLE IF EXISTS %1;").arg(m_table));
1105  if (query.exec())
1106  m_dbExists = false;
1107  else
1108  MythDB::DBError(DBLOC, query);
1109 }
1110 
1111 
1116 {
1117  if (m_dbExists)
1118  return true;
1119 
1120  MSqlQuery query(MSqlQuery::InitCon());
1121 
1122  // Create temporary table
1123  query.prepare(QString("CREATE TABLE %1 LIKE " DB_TABLE ";").arg(m_table));
1124  if (query.exec())
1125  {
1126  // Store it in memory only
1127  query.prepare(QString("ALTER TABLE %1 ENGINE = MEMORY;").arg(m_table));
1128  if (query.exec())
1129  {
1130  m_dbExists = true;
1131  LOG(VB_FILE, LOG_DEBUG, QString("Created Db table %1").arg(m_table));
1132  return true;
1133  }
1134  }
1135  MythDB::DBError(DBLOC, query);
1136 
1137  // Clean up after failure
1138  query.prepare(QString("DROP TABLE IF EXISTS %1;").arg(m_table));
1139  query.exec();
1140  return false;
1141 }
1142 
1143 
1147 class ReadMetaThread : public QRunnable
1148 {
1149 public:
1150  ReadMetaThread(ImagePtrK im, QString path)
1151  : m_im(std::move(im)), m_path(std::move(path)) {}
1152 
1153  void run() override // QRunnable
1154  {
1155  QStringList tags;
1156  QString orientation;
1157  QString size;
1158 
1159  // Read metadata for files only
1160  if (m_im->IsFile())
1161  {
1162  ImageMetaData *metadata = (m_im->m_type == kVideoFile)
1165  tags = metadata->GetAllTags();
1166  orientation = Orientation(m_im->m_orientation).Description();
1167  size = ImageAdapterBase::FormatSize(m_im->m_size / 1024);
1168  delete metadata;
1169  }
1170 
1171  // Add identifier at front
1172  tags.prepend(QString::number(m_im->m_id));
1173 
1174  // Include file info
1175  tags << ImageMetaData::ToString(EXIF_MYTH_HOST, "Host",
1177  tags << ImageMetaData::ToString(EXIF_MYTH_PATH, "Path",
1179  tags << ImageMetaData::ToString(EXIF_MYTH_NAME, "Name",
1181  tags << ImageMetaData::ToString(EXIF_MYTH_SIZE, "Size", size);
1182  tags << ImageMetaData::ToString(EXIF_MYTH_ORIENT, "Orientation",
1183  orientation);
1184 
1185  MythEvent me("IMAGE_METADATA", tags);
1186  gCoreContext->SendEvent(me);
1187  }
1188 
1189 private:
1191  QString m_path;
1192 };
1193 
1194 
1203 template <class DBFS>
1204 QStringList ImageHandler<DBFS>::HandleGetMetadata(const QString &id) const
1205 {
1206  // Find image in DB
1207  ImageList files;
1208  ImageList dirs;
1209  if (DBFS::GetImages(id, files, dirs) != 1)
1210  RESULT_ERR("Image not found", QString("Unknown image %1").arg(id))
1211 
1212  ImagePtr im = files.isEmpty() ? dirs[0] : files[0];
1213 
1214  QString absPath = DBFS::GetAbsFilePath(im);
1215  if (absPath.isEmpty())
1216  RESULT_ERR("Image not found",
1217  QString("File %1 not found").arg(im->m_filePath))
1218 
1219  auto *worker = new ReadMetaThread(im, absPath);
1220 
1221  MThreadPool::globalInstance()->start(worker, "ImageMetaData");
1222 
1223  RESULT_OK(QString("Fetching metadata for %1").arg(id))
1224 }
1225 
1226 
1234 template <class DBFS>
1235 QStringList ImageHandler<DBFS>::HandleRename(const QString &id,
1236  const QString &newBase) const
1237 {
1238  // Sanity check new name
1239  if (newBase.isEmpty() || newBase.contains("/") || newBase.contains("\\"))
1240  RESULT_ERR("Invalid name", QString("Invalid name %1").arg(newBase))
1241 
1242  // Find image in DB
1243  ImageList files;
1244  ImageList dirs;
1245  if (DBFS::GetImages(id, files, dirs) != 1)
1246  RESULT_ERR("Image not found", QString("Image %1 not in Db").arg(id))
1247 
1248  ImagePtr im = files.isEmpty() ? dirs[0] : files[0];
1249 
1250  // Find file
1251  QString oldPath = DBFS::GetAbsFilePath(im);
1252  if (oldPath.isEmpty())
1253  RESULT_ERR("Image not found",
1254  QString("File %1 not found").arg(im->m_filePath))
1255 
1256  // Generate new filename
1257  QFileInfo oldFi = QFileInfo(oldPath);
1258  QString newName = im->IsDirectory()
1259  ? newBase : QString("%1.%2").arg(newBase, oldFi.suffix());
1260 
1261  im->m_filePath = DBFS::ConstructPath(DBFS::PathOf(im->m_filePath), newName);
1262 
1263  // Ensure no SG duplicate files are created. (Creating clone dirs is ok)
1264  if (im->IsFile())
1265  {
1266  QString existPath = DBFS::GetAbsFilePath(im);
1267  if (!existPath.isEmpty())
1268  RESULT_ERR("Filename already used",
1269  QString("Renaming %1 to %2 will create a duplicate of %3")
1270  .arg(oldPath, im->m_filePath, existPath))
1271  }
1272 
1273  // Rename file or directory
1274  QString newPath = oldFi.dir().absoluteFilePath(newName);
1275  if (!QFile::rename(oldPath, newPath))
1276  RESULT_ERR("Rename failed",
1277  QString("Rename of %1 -> %2 failed").arg(oldPath, newPath))
1278 
1279  if (im->IsDirectory())
1280  {
1281  // Dir name change affects path of all sub-dirs & files and their thumbs
1282  HandleScanRequest("START");
1283  }
1284  else // file
1285  {
1286  // Update db
1287  DBFS::UpdateDbImage(*im);
1288 
1289  // Image is modified, not deleted
1290  QStringList mesg("");
1291  mesg << QString::number(im->m_id);
1292 
1293  // Rename thumbnail.
1294  m_thumbGen->MoveThumbnail(im);
1295 
1296  // Notify clients of changed image
1297  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1298  }
1299  RESULT_OK(QString("Renamed %1 -> %2").arg(oldPath, newPath))
1300 }
1301 
1302 
1310 template <class DBFS>
1311 QStringList ImageHandler<DBFS>::HandleDelete(const QString &ids) const
1312 {
1313  // Get subtree of all files
1314  ImageList files;
1315  ImageList dirs;
1316  // Dirs will be in depth-first order, (subdirs after parent)
1317  DBFS::GetDescendants(ids, files, dirs);
1318 
1319  // Remove files from filesystem first
1320  RemoveFiles(files);
1321  // ... then dirs, which should now be empty
1322  RemoveFiles(dirs);
1323 
1324  // Fail if nothing deleted
1325  if (files.isEmpty() && dirs.isEmpty())
1326  RESULT_ERR("Delete failed", QString("Delete of %1 failed").arg(ids))
1327 
1328  // Update Db
1329  DBFS::RemoveFromDB(files + dirs);
1330 
1331  // Clean up thumbnails
1332  QStringList mesg(m_thumbGen->DeleteThumbs(files));
1333 
1334  // Notify clients of deleted ids
1335  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1336 
1337  return QStringList("OK");
1338 }
1339 
1340 
1353 template <class DBFS>
1354 QStringList ImageHandler<DBFS>::HandleDbCreate(QStringList defs) const
1355 {
1356  if (defs.isEmpty())
1357  RESULT_ERR("Copy Failed", "Empty defs")
1358 
1359  // First item is the field seperator
1360  const QString separator = defs.takeFirst();
1361 
1362  // Convert cover ids to their new equivalent. Map<source id, new id>
1363  // Dirs follow their children so new cover ids will be defined before they
1364  // are used
1365  QHash<QString, int> idMap;
1366 
1367  // Create skeleton Db images using copied settings.
1368  // Scanner will update other attributes
1369  ImageItem im;
1370  for (const auto& def : qAsConst(defs))
1371  {
1372  QStringList aDef = def.split(separator);
1373 
1374  // Expects id, type, path, hidden, orientation, cover
1375  if (aDef.size() != 6)
1376  {
1377  // Coding error
1378  LOG(VB_GENERAL, LOG_ERR,
1379  LOC + QString("Bad definition: (%1)").arg(def));
1380  continue;
1381  }
1382 
1383  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Creating %1").arg(aDef.join(",")));
1384 
1385  im.m_type = aDef[1].toInt();
1386  im.m_filePath = aDef[2];
1387  im.m_isHidden = (aDef[3].toInt() != 0);
1388  im.m_orientation = aDef[4].toInt();
1389  im.m_userThumbnail = idMap.value(aDef[5]);
1390 
1391  // Don't insert duplicate filepaths
1392  int newId = DBFS::InsertDbImage(im, true);
1393 
1394  // Record old->new id map in case it's being used as a cover
1395  idMap.insert(aDef[0], newId);
1396  }
1397  HandleScanRequest("START");
1398 
1399  RESULT_OK("Created Db images")
1400 }
1401 
1402 
1412 template <class DBFS>
1413 QStringList ImageHandler<DBFS>::HandleDbMove(const QString &ids,
1414  const QString &srcPath,
1415  QString destPath) const
1416 {
1417  // Sanity check new path
1418  if (destPath.contains(".."))
1419  RESULT_ERR("Invalid path", QString("Invalid path %1").arg(destPath))
1420 
1421  // Get subtrees of renamed files
1422  ImageList images;
1423  ImageList dirs;
1424  ImageList files;
1425  bool ok = DBFS::GetDescendants(ids, files, dirs);
1426  images << dirs << files;
1427 
1428  if (!ok || images.isEmpty())
1429  RESULT_ERR("Image not found", QString("Images %1 not in Db").arg(ids))
1430 
1431  if (!destPath.isEmpty() && !destPath.endsWith(QChar('/')))
1432  destPath.append("/");
1433 
1434  // Update path of images only. Scanner will repair parentId
1435  for (const auto& im : qAsConst(images))
1436  {
1437  QString old = im->m_filePath;
1438 
1439  if (srcPath.isEmpty())
1440  {
1441  // Image in SG root
1442  im->m_filePath.prepend(destPath);
1443  }
1444  else if (im->m_filePath.startsWith(srcPath))
1445  {
1446  // All other images
1447  im->m_filePath.replace(srcPath, destPath);
1448  }
1449  else
1450  {
1451  // Coding error
1452  LOG(VB_GENERAL, LOG_ERR,
1453  LOC + QString("Bad image: (%1 -> %2)").arg(srcPath, destPath));
1454  continue;
1455  }
1456 
1457  LOG(VB_FILE, LOG_DEBUG,
1458  LOC + QString("Db Renaming %1 -> %2").arg(old, im->m_filePath));
1459 
1460  DBFS::UpdateDbImage(*im);
1461 
1462  // Rename thumbnail
1463  if (im->IsFile())
1464  m_thumbGen->MoveThumbnail(im);
1465  }
1466  HandleScanRequest("START");
1467 
1468  RESULT_OK(QString("Moved %1 from %2 -> %3").arg(ids, srcPath, destPath))
1469 }
1470 
1471 
1479 template <class DBFS>
1480 QStringList ImageHandler<DBFS>::HandleHide(bool hide, const QString &ids) const
1481 {
1482  if (!DBFS::SetHidden(hide, ids))
1483  RESULT_ERR("Hide failed", QString("Db hide failed for %1").arg(ids))
1484 
1485  // Send changed ids only (none deleted)
1486  QStringList mesg = QStringList("") << ids;
1487  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1488 
1489  RESULT_OK(QString("Images %1 now %2hidden").arg(ids, hide ? "" : "un"))
1490 }
1491 
1492 
1501 template <class DBFS>
1502 QStringList ImageHandler<DBFS>::HandleTransform(int transform,
1503  const QString &ids) const
1504 {
1505  if (transform < kResetToExif || transform > kFlipVertical)
1506  RESULT_ERR("Transform failed", QString("Bad transform %1").arg(transform))
1507 
1508  ImageList files;
1509  ImageList dirs;
1510  if (DBFS::GetImages(ids, files, dirs) < 1 || files.isEmpty())
1511  RESULT_ERR("Image not found", QString("Images %1 not in Db").arg(ids))
1512 
1513  // Update db
1514  for (const auto& im : qAsConst(files))
1515  {
1516  int old = im->m_orientation;
1517  im->m_orientation = Orientation(im->m_orientation).Transform(transform);
1518 
1519  // Update Db
1520  if (DBFS::SetOrientation(im->m_id, im->m_orientation))
1521  {
1522  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Transformed %1 from %2 to %3")
1523  .arg(im->m_filePath).arg(old).arg(im->m_orientation));
1524  }
1525  }
1526 
1527  // Images are changed, not deleted
1528  QStringList mesg("");
1529 
1530  // Clean up thumbnails
1531  mesg << m_thumbGen->DeleteThumbs(files);
1532 
1533  // Notify clients of changed images
1534  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1535 
1536  return QStringList("OK");
1537 }
1538 
1539 
1548 template <class DBFS>
1549 QStringList ImageHandler<DBFS>::HandleDirs(const QString &destId,
1550  bool rescan,
1551  const QStringList &relPaths) const
1552 {
1553  // Find image in DB
1554  ImageList files;
1555  ImageList dirs;
1556  if (DBFS::GetImages(destId, files, dirs) != 1 || dirs.isEmpty())
1557  RESULT_ERR("Destination not found",
1558  QString("Image %1 not in Db").arg(destId))
1559 
1560  // Find dir. SG device (Photographs) uses most-free filesystem
1561  QString destPath = DBFS::GetAbsFilePath(dirs[0]);
1562  if (destPath.isEmpty())
1563  RESULT_ERR("Destination not found",
1564  QString("Dest dir %1 not found").arg(dirs[0]->m_filePath))
1565 
1566  QDir destDir(destPath);
1567  bool succeeded = false;
1568  for (const auto& relPath : qAsConst(relPaths))
1569  {
1570  // Validate dir name
1571  if (relPath.isEmpty() || relPath.contains("..") || relPath.startsWith(QChar('/')))
1572  continue;
1573 
1574  QString newPath = DBFS::ConstructPath(destDir.absolutePath(), relPath);
1575  if (!destDir.mkpath(relPath))
1576  {
1577  LOG(VB_GENERAL, LOG_ERR,
1578  LOC + QString("Failed to create dir %1").arg(newPath));
1579  continue;
1580  }
1581  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Dir %1 created").arg(newPath));
1582  succeeded = true;
1583  }
1584 
1585  if (!succeeded)
1586  // Failures should only occur due to user input
1587  RESULT_ERR("Invalid Name", QString("Invalid name %1")
1588  .arg(relPaths.join(",")))
1589 
1590  if (rescan)
1591  // Rescan to detect new dir
1592  HandleScanRequest("START");
1593 
1594  return QStringList("OK");
1595 }
1596 
1597 
1604 template <class DBFS>
1605 QStringList ImageHandler<DBFS>::HandleCover(int dir, int cover) const
1606 {
1607  if (!DBFS::SetCover(dir, cover))
1608  RESULT_ERR("Set Cover failed",
1609  QString("Failed to set %1 to cover %2").arg(dir).arg(cover))
1610 
1611  // Image has changed, nothing deleted
1612  QStringList mesg = QStringList("") << QString::number(dir);
1613  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1614 
1615  RESULT_OK(QString("Cover of %1 is now %2").arg(dir).arg(cover));
1616 }
1617 
1618 
1627 template <class DBFS>
1628 QStringList ImageHandler<DBFS>::HandleIgnore(const QString &exclusions) const
1629 {
1630  // Save new setting. FE will have already saved it but not cleared the cache
1631  gCoreContext->SaveSettingOnHost("GalleryIgnoreFilter", exclusions, nullptr);
1632 
1633  // Rescan
1634  HandleScanRequest("START");
1635 
1636  RESULT_OK(QString("Using exclusions '%1'").arg(exclusions))
1637 }
1638 
1639 
1647 template <class DBFS>
1648 QStringList ImageHandler<DBFS>::HandleScanRequest(const QString &command,
1649  int devId) const
1650 {
1651  if (!m_scanner)
1652  RESULT_ERR("Missing Scanner", "Missing Scanner");
1653 
1654  if (command == "START")
1655  {
1656  // Must be dormant to start a scan
1657  if (m_scanner->IsScanning())
1658  RESULT_ERR("", "Scanner is busy");
1659 
1660  m_scanner->ChangeState(true);
1661  RESULT_OK("Scan requested");
1662  }
1663  else if (command == "STOP")
1664  {
1665  // Must be scanning to interrupt
1666  if (!m_scanner->IsScanning())
1667  RESULT_ERR("Scanner not running", "Scanner not running");
1668 
1669  m_scanner->ChangeState(false);
1670  RESULT_OK("Terminate scan requested");
1671  }
1672  else if (command == "QUERY")
1673  {
1674  return QStringList("OK") << m_scanner->GetProgress();
1675  }
1676  else if (command.startsWith(QString("DEVICE")))
1677  {
1678  m_scanner->EnqueueClear(devId, command);
1679  RESULT_OK(QString("Clearing device %1 %2").arg(command).arg(devId))
1680  }
1681  RESULT_ERR("Unknown command", QString("Unknown command %1").arg(command));
1682 }
1683 
1684 
1692 template <class DBFS>
1694 (const QStringList &message) const
1695 {
1696  if (message.size() != 2)
1697  RESULT_ERR("Unknown Command",
1698  QString("Bad request: %1").arg(message.join("|")))
1699 
1700  int priority = message.at(0).toInt()
1702 
1703  // get specific image details from db
1704  ImageList files;
1705  ImageList dirs;
1706  DBFS::GetImages(message.at(1), files, dirs);
1707 
1708  for (const auto& im : qAsConst(files))
1709  // notify clients when done; highest priority
1710  m_thumbGen->CreateThumbnail(im, priority, true);
1711 
1712  return QStringList("OK");
1713 }
1714 
1715 
1725 template <class DBFS>
1727 {
1728 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
1729  QMutableVectorIterator<ImagePtr> it(images);
1730 #else
1731  QMutableListIterator<ImagePtr> it(images);
1732 #endif
1733  it.toBack();
1734  while (it.hasPrevious())
1735  {
1736  ImagePtrK im = it.previous();
1737 
1738  // Remove file or directory
1739  QString absFilename = DBFS::GetAbsFilePath(im);
1740 
1741  bool success = !absFilename.isEmpty()
1742  && (im->IsFile() ? QFile::remove(absFilename)
1743  : QDir::root().rmdir(absFilename));
1744  if (success)
1745  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Deleted %1").arg(absFilename));
1746  else
1747  {
1748  LOG(VB_GENERAL, LOG_ERR, LOC +
1749  QString("Can't delete %1").arg(absFilename));
1750  // Remove from list
1751  it.remove();
1752  }
1753  }
1754 }
1755 
1756 
1763 {
1764  switch (type)
1765  {
1766  case kPicOnly: return QString("AND type != %1").arg(kVideoFile);
1767  case kVideoOnly: return QString("AND type != %1").arg(kImageFile);
1768  case kPicAndVideo: return "";
1769  }
1770  return "";
1771 }
1772 
1773 
1780 {
1781  m_refineClause = QString("%2 %3 "
1782  "ORDER BY "
1783  "CASE WHEN type <= %1 THEN %4, "
1784  "CASE WHEN type > %1 THEN %5 ")
1785  .arg(kDirectory)
1786  .arg(m_showHidden ? "" : "AND hidden = 0",
1790 }
1791 
1792 
1799 {
1800  // prepare the sorting statement
1801  switch (order)
1802  {
1803  default:
1804  case kSortByNameAsc: return "name END ASC";
1805  case kSortByNameDesc: return "name END DESC";
1806  case kSortByModTimeAsc: return "modtime END ASC";
1807  case kSortByModTimeDesc: return "modtime END DESC";
1808  case kSortByExtAsc: return "extension END ASC, name ASC";
1809  case kSortByExtDesc: return "extension END DESC, name DESC";
1810  case kSortBySizeAsc: return "size END ASC, name ASC";
1811  case kSortBySizeDesc: return "size END DESC, name DESC";
1812  case kSortByDateAsc: return "IF(date=0, modtime, date) END ASC";
1813  case kSortByDateDesc: return "IF(date=0, modtime, date) END DESC";
1814  }
1815 }
1816 
1817 
1827  ImageList &files, ImageList &dirs) const
1828 {
1829  // Only Root node will invoke both Db queries but result set will be small
1830  // For Root the SG is always ordered before local devices
1831  // Root node has no Db entry so the 2 queries will not overwrite the parent.
1832  int count = 0;
1833  if (!ImageItem::IsLocalId(id))
1834  count = m_remote->GetDirectory(id, parent, files, dirs, m_refineClause);
1836  count += ImageHandler::GetDirectory(id, parent, files, dirs, m_refineClause);
1837 
1838  if (id == GALLERY_DB_ID)
1839  {
1840  // Add a Root node
1841  parent = ImagePtr(new ImageItem(GALLERY_DB_ID));
1842  parent->m_parentId = GALLERY_DB_ID;
1843  parent->m_type = kDevice;
1844 
1845  ++count;
1846  }
1847  return count;
1848 }
1849 
1850 
1859  ImageList &files, ImageList &dirs) const
1860 {
1861  // Ids are either all local or all remote. GALLERY_DB_ID not valid
1862  StringPair lists = ImageItem::PartitionIds(ids);
1863 
1864  if (!lists.second.isEmpty())
1865  return m_remote->GetImages(lists.second, files, dirs, m_refineClause);
1866  if (m_dbExists && !lists.first.isEmpty())
1867  return ImageHandler::GetImages(lists.first, files, dirs, m_refineClause);
1868  return 0;
1869 }
1870 
1871 
1879 int ImageDbReader::GetChildren(int id, ImageList &files, ImageList &dirs) const
1880 {
1881  int count = 0;
1882  if (!ImageItem::IsLocalId(id))
1883  count = m_remote->GetChildren(QString::number(id), files, dirs,
1884  m_refineClause);
1886  count += ImageHandler::GetChildren(QString::number(id), files, dirs,
1887  m_refineClause);
1888  return count;
1889 }
1890 
1891 
1899  ImageList &files, ImageList &dirs) const
1900 {
1901  // Ids are either all local or all remote
1902  StringPair lists = ImageItem::PartitionIds(ids);
1903 
1904  if (!lists.second.isEmpty())
1905  m_remote->GetDescendants(lists.second, files, dirs);
1906  if (m_dbExists && !lists.first.isEmpty())
1907  ImageHandler::GetDescendants(lists.first, files, dirs);
1908 }
1909 
1910 
1917 void ImageDbReader::GetImageTree(int id, ImageList &files) const
1918 {
1919  if (!ImageItem::IsLocalId(id))
1920  m_remote->GetImageTree(id, files, m_refineClause);
1922  ImageHandler::GetImageTree(id, files, m_refineClause);
1923 }
1924 
1925 
1934 void ImageDbReader::GetDescendantCount(int id, int &dirs, int &pics,
1935  int &videos, int &sizeKb) const
1936 {
1937  if (id == GALLERY_DB_ID)
1938  {
1939  // Sum both unfiltered tables
1940  m_remote->GetDescendantCount(id, true, dirs, pics, videos, sizeKb);
1941  if (m_dbExists)
1942  ImageHandler::GetDescendantCount(id, true, dirs, pics, videos, sizeKb);
1943  }
1944  else if (!ImageItem::IsLocalId(id))
1945  {
1946  // Don't filter on SG path (it's blank)
1948  dirs, pics, videos, sizeKb);
1949  }
1950  else if (m_dbExists)
1951  {
1952  // Always filter on device/dir
1953  ImageHandler::GetDescendantCount(id, false, dirs, pics, videos, sizeKb);
1954  }
1955 }
1956 
1957 
1962 
1963 
1969 {
1970  if (!s_instance)
1971  s_instance = new ImageManagerBe();
1972  return s_instance;
1973 }
1974 
1975 
1981 {
1982  if (!s_instance)
1983  {
1984  // Use saved settings
1986  (gCoreContext->GetNumSetting("GalleryImageOrder"),
1987  gCoreContext->GetNumSetting("GalleryDirOrder"),
1988  gCoreContext->GetBoolSetting("GalleryShowHidden"),
1989  gCoreContext->GetNumSetting("GalleryShowType"),
1990  gCoreContext->GetSetting("GalleryDateFormat"));
1991  }
1992  return *s_instance;
1993 }
1994 
1995 
2004 void ImageManagerFe::CreateThumbnails(const ImageIdList &ids, bool forFolder)
2005 {
2006  // Split images into <locals, remotes>
2007  StringPair lists = ImageItem::PartitionIds(ids);
2008 
2009  if (!lists.second.isEmpty())
2010  {
2011  LOG(VB_FILE, LOG_DEBUG, LOC +
2012  QString("Sending CREATE_THUMBNAILS %1 (forFolder %2)")
2013  .arg(lists.second).arg(forFolder));
2014 
2015  QStringList message;
2016  message << QString::number(static_cast<int>(forFolder)) << lists.second;
2017  gCoreContext->SendEvent(MythEvent("CREATE_THUMBNAILS", message));
2018  }
2019 
2020  if (!lists.first.isEmpty())
2021  {
2022  LOG(VB_FILE, LOG_DEBUG, LOC +
2023  QString("Creating local thumbnails %1 (forFolder %2)")
2024  .arg(lists.first).arg(forFolder));
2025 
2026  QStringList message;
2027  message << QString::number(static_cast<int>(forFolder)) << lists.first;
2028  HandleCreateThumbnails(message);
2029  }
2030 }
2031 
2032 
2039 QString ImageManagerFe::ScanImagesAction(bool start, bool local)
2040 {
2041  QStringList command;
2042  command << (start ? "START" : "STOP");
2043 
2044  if (!local)
2045  {
2046  command.push_front("IMAGE_SCAN");
2047  bool ok = gCoreContext->SendReceiveStringList(command, true);
2048  return ok ? "" : command[1];
2049  }
2050 
2051  // Create database on first scan
2052  if (!CreateTable())
2053  return "Couldn't create database";
2054 
2055  QStringList err = HandleScanRequest(command[0]);
2056  return err[0] == "OK" ? "" : err[1];
2057 }
2058 
2059 
2066 {
2067  QStringList strList;
2068  strList << "IMAGE_SCAN" << "QUERY";
2069 
2070  if (!gCoreContext->SendReceiveStringList(strList))
2071  {
2072  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Scan query failed : %1")
2073  .arg(strList.join(",")));
2074  }
2075  return strList;
2076 }
2077 
2078 
2085 QString ImageManagerFe::HideFiles(bool hidden, const ImageIdList &ids)
2086 {
2087  // Split images into <locals, remotes>
2088  StringPair lists = ImageItem::PartitionIds(ids);
2089  QString result = "";
2090 
2091  if (!lists.second.isEmpty())
2092  {
2093  QStringList message;
2094  message << "IMAGE_HIDE" << QString::number(static_cast<int>(hidden)) << lists.second;
2095 
2096  if (!gCoreContext->SendReceiveStringList(message, true))
2097  result = message[1];
2098  }
2099 
2100  if (!lists.first.isEmpty())
2101  {
2102  QStringList err = HandleHide(hidden, lists.first);
2103  if (err[0] != "OK")
2104  result = err[1];
2105  }
2106  return result;
2107 }
2108 
2109 
2117  const ImageIdList &ids)
2118 {
2119  // Split images into <locals, remotes>
2120  StringPair lists = ImageItem::PartitionIds(ids);
2121  QString result = "";
2122 
2123  if (!lists.second.isEmpty())
2124  {
2125  QStringList message;
2126  message << "IMAGE_TRANSFORM" << QString::number(transform) << lists.second;
2127 
2128  if (!gCoreContext->SendReceiveStringList(message, true))
2129  result = message[1];
2130  }
2131 
2132  if (!lists.first.isEmpty())
2133  {
2134  QStringList err = HandleTransform(transform, lists.first);
2135  if (err[0] != "OK")
2136  result = err[1];
2137  }
2138  return result;
2139 }
2140 
2141 
2148 QString ImageManagerFe::SetCover(int parent, int cover)
2149 {
2150  if (!ImageItem::IsLocalId(parent))
2151  {
2152  QStringList message;
2153  message << "IMAGE_COVER" << QString::number(parent) << QString::number(cover);
2154 
2155  bool ok = gCoreContext->SendReceiveStringList(message, true);
2156  return ok ? "" : message[1];
2157  }
2158 
2159  QStringList err = HandleCover(parent, cover);
2160  return err[0] == "OK" ? "" : err[1];
2161 }
2162 
2163 
2169 {
2170  if (ImageItem::IsLocalId(id))
2171  HandleGetMetadata(QString::number(id));
2172  else
2173  gCoreContext->SendEvent(MythEvent("IMAGE_GET_METADATA", QString::number(id)));
2174 }
2175 
2176 
2179 {
2180  QStringList message("IMAGE_SCAN");
2181  message << "DEVICE CLEAR ALL";
2182  gCoreContext->SendReceiveStringList(message, true);
2183 }
2184 
2185 
2192 QString ImageManagerFe::IgnoreDirs(const QString &excludes)
2193 {
2194  QStringList message("IMAGE_IGNORE");
2195  message << excludes;
2196  bool ok = gCoreContext->SendReceiveStringList(message, true);
2197  return ok ? "" : message[1];
2198 }
2199 
2200 
2208 QString ImageManagerFe::MakeDir(int parent, const QStringList &names, bool rescan)
2209 {
2210  QString destId = QString::number(parent);
2211 
2212  if (!ImageItem::IsLocalId(parent))
2213  {
2214  QStringList message("IMAGE_CREATE_DIRS");
2215  message << destId << QString::number(static_cast<int>(rescan)) << names;
2216  bool ok = gCoreContext->SendReceiveStringList(message, true);
2217  return ok ? "" : message[1];
2218  }
2219  QStringList err = HandleDirs(destId, rescan, names);
2220  return (err[0] == "OK") ? "" : err[1];
2221 }
2222 
2223 
2230 QString ImageManagerFe::RenameFile(const ImagePtrK& im, const QString &name)
2231 {
2232  if (!im->IsLocal())
2233  {
2234  QStringList message("IMAGE_RENAME");
2235  message << QString::number(im->m_id) << name;
2236  bool ok = gCoreContext->SendReceiveStringList(message, true);
2237  return ok ? "" : message[1];
2238  }
2239  QStringList err = HandleRename(QString::number(im->m_id), name);
2240  return (err[0] == "OK") ? "" : err[1];
2241 }
2242 
2243 
2250 QString ImageManagerFe::CreateImages(int destId, const ImageListK &images)
2251 {
2252  if (images.isEmpty())
2253  return "";
2254 
2255  // Define field seperator & include it in message
2256  const QString seperator("...");
2257  QStringList imageDefs(seperator);
2258  ImageIdList ids;
2259  for (const auto& im : qAsConst(images))
2260  {
2261  ids << im->m_id;
2262 
2263  // Copies preserve hide state, orientation & cover
2264  QStringList aDef;
2265  aDef << QString::number(im->m_id)
2266  << QString::number(im->m_type)
2267  << im->m_filePath
2268  << QString::number(static_cast<int>(im->m_isHidden))
2269  << QString::number(im->m_orientation)
2270  << QString::number(im->m_userThumbnail);
2271 
2272  imageDefs << aDef.join(seperator);
2273  }
2274 
2275  // Images are either all local or all remote
2276  if (ImageItem::IsLocalId(destId))
2277  {
2278  QStringList err = HandleDbCreate(imageDefs);
2279  return (err[0] == "OK") ? "" : err[1];
2280  }
2281  imageDefs.prepend("IMAGE_COPY");
2282  bool ok = gCoreContext->SendReceiveStringList(imageDefs, true);
2283  return ok ? "" : imageDefs[1];
2284 }
2285 
2286 
2294 QString ImageManagerFe::MoveDbImages(const ImagePtrK& destDir, ImageListK &images,
2295  const QString &srcPath)
2296 {
2297  QStringList idents;
2298  for (const auto& im : qAsConst(images))
2299  idents << QString::number(im->m_id);
2300 
2301  // Images are either all local or all remote
2302  if (destDir->IsLocal())
2303  {
2304  QStringList err = HandleDbMove(idents.join(","), srcPath,
2305  destDir->m_filePath);
2306  return (err[0] == "OK") ? "" : err[1];
2307  }
2308 
2309  QStringList message("IMAGE_MOVE");
2310  message << idents.join(",") << srcPath << destDir->m_filePath;
2311  bool ok = gCoreContext->SendReceiveStringList(message, true);
2312  return ok ? "" : message[1];
2313 }
2314 
2315 
2322 {
2323  StringPair lists = ImageItem::PartitionIds(ids);
2324 
2325  QString result = "";
2326  if (!lists.second.isEmpty())
2327  {
2328  QStringList message("IMAGE_DELETE");
2329  message << lists.second;
2330 
2331  bool ok = gCoreContext->SendReceiveStringList(message, true);
2332  if (!ok)
2333  result = message[1];
2334  }
2335  if (!lists.first.isEmpty())
2336  {
2337  QStringList err = HandleDelete(lists.first);
2338  if (err[0] != "OK")
2339  result = err[1];
2340  }
2341  return result;
2342 }
2343 
2344 
2352 {
2353  if (im->m_id == GALLERY_DB_ID)
2354  return "";
2355 
2356  std::chrono::seconds secs = 0s;
2358 
2359  if (im->m_date > 0s)
2360  {
2361  secs = im->m_date;
2362  format |= MythDate::kTime;
2363  }
2364  else
2365  secs = im->m_modTime;
2366 
2367  return MythDate::toString(QDateTime::fromSecsSinceEpoch(secs.count()), format);
2368 }
2369 
2370 
2377 QString ImageManagerFe::ShortDateOf(const ImagePtrK& im) const
2378 {
2379  if (im->m_id == GALLERY_DB_ID)
2380  return "";
2381 
2382  std::chrono::seconds secs(im->m_date > 0s ? im->m_date : im->m_modTime);
2383  return QDateTime::fromSecsSinceEpoch(secs.count()).date().toString(m_dateFormat);
2384 }
2385 
2386 
2393 {
2394  if (im.m_id == GALLERY_DB_ID)
2395  return tr("Gallery");
2396  if (im.m_id == PHOTO_DB_ID)
2397  return tr("Photographs");
2398  return im.IsLocal() ? DeviceName(im.m_device)
2399  : m_remote->DeviceName(im.m_device);
2400 }
2401 
2402 
2410 QString ImageManagerFe::CrumbName(ImageItemK &im, bool getPath) const
2411 {
2412  if (im.IsDevice())
2413  return DeviceCaption(im);
2414 
2415  if (!getPath)
2416  return im.m_baseName;
2417 
2418  QString dev;
2419  QString path(im.m_filePath);
2420 
2421  if (im.IsLocal())
2422  {
2423  // Replace local mount path with device name
2424  path.remove(0, DeviceMount(im.m_device).size());
2425  dev = DeviceName(im.m_device);
2426  }
2427  return dev + path.replace("/", " > ");
2428 }
2429 
2430 
2431 void ImageManagerFe::CloseDevices(int devId, bool eject)
2432 {
2433  QString reason = (devId == DEVICE_INVALID)
2434  ? "DEVICE CLOSE ALL"
2435  : eject ? "DEVICE EJECT" : "DEVICE REMOVE";
2436  HandleScanRequest(reason, devId);
2437 }
2438 
2439 
2445 {
2447  if (!monitor)
2448  return false;
2449 
2450  // Detect all local media
2451  QList<MythMediaDevice*> devices
2453 
2454  for (auto *dev : qAsConst(devices))
2455  {
2456  if (monitor->ValidateAndLock(dev) && dev->isUsable())
2457  OpenDevice(dev->getDeviceModel(), dev->getMountPath(), dev);
2458  else
2459  monitor->Unlock(dev);
2460  }
2461 
2462  if (DeviceCount() > 0)
2463  {
2464  // Close devices that are no longer present
2465  QList absentees = GetAbsentees();
2466  for (int devId : qAsConst(absentees))
2467  CloseDevices(devId);
2468 
2469  // Start local scan
2470  QString err = ScanImagesAction(true, true);
2471  if (!err.isEmpty())
2472  LOG(VB_GENERAL, LOG_ERR, LOC + err);
2473  }
2474  return DeviceCount() > 0;
2475 }
2476 
2477 
2483 {
2485 
2486  if (!event || !monitor)
2487  return;
2488 
2489  MythMediaDevice *dev = event->getDevice();
2490  if (!dev)
2491  return;
2492 
2493  MythMediaType type = dev->getMediaType();
2494  MythMediaStatus status = dev->getStatus();
2495 
2496  LOG(VB_FILE, LOG_DEBUG, LOC +
2497  QString("Media event for %1 (%2) at %3, type %4, status %5 (was %6)")
2498  .arg(dev->getDeviceModel(), dev->getVolumeID(), dev->getMountPath())
2499  .arg(type).arg(status).arg(event->getOldStatus()));
2500 
2502  {
2503  LOG(VB_FILE, LOG_DEBUG, LOC +
2504  QString("Ignoring event - wrong type %1").arg(type));
2505  return;
2506  }
2507 
2508  if (status == MEDIASTAT_USEABLE || status == MEDIASTAT_MOUNTED)
2509  {
2510  // New device. Lock it & scan
2511  if (monitor->ValidateAndLock(dev))
2512  {
2513  OpenDevice(dev->getDeviceModel(), dev->getMountPath(), dev);
2514  ScanImagesAction(true, true);
2515  }
2516  else
2517  monitor->Unlock(dev);
2518  return;
2519  }
2520 
2521  // Device has disappeared
2522  int devId = LocateMount(dev->getMountPath());
2523  if (devId != DEVICE_INVALID)
2524  CloseDevices(devId);
2525 }
2526 
2527 
2529 {
2530  auto *tmp = new QTemporaryDir(QDir::tempPath() % "/" IMPORTDIR "-XXXXXX");
2531  if (!tmp->isValid())
2532  {
2533  delete tmp;
2534  return "";
2535  }
2536 
2537  QString time(QDateTime::currentDateTime().toString("mm:ss"));
2538  OpenDevice("Import " + time, tmp->path(), nullptr, tmp);
2539  return tmp->path();
2540 }
2541 
2542 
2543 // Must define the valid template implementations to generate code for the
2544 // instantiations (as they are defined in the cpp rather than header).
2545 // Otherwise the linker will fail with undefined references...
2546 template class ImageDb<ImageAdapterSg>;
2547 template class ImageDb<ImageAdapterLocal>;
2548 template class ImageHandler<ImageDbSg>;
2549 template class ImageHandler<ImageDbLocal>;
MythMediaDevice::getMountPath
const QString & getMountPath() const
Definition: mythmedia.h:58
ImageAdapterBase::ImageAdapterBase
ImageAdapterBase()
Constructor.
Definition: imagemanager.cpp:310
MythMediaEvent::getOldStatus
MythMediaStatus getOldStatus(void) const
Definition: mythmedia.h:190
ImageManagerBe::s_instance
static ImageManagerBe * s_instance
BE Gallery instance.
Definition: imagemanager.h:391
kPicAndVideo
@ kPicAndVideo
Show Pictures & Videos.
Definition: imagemanager.h:78
kSortByNameDesc
@ kSortByNameDesc
Name Z-A.
Definition: imagetypes.h:47
ImageManagerFe::m_dateFormat
QString m_dateFormat
UI format for thumbnail date captions.
Definition: imagemanager.h:514
ImageManagerFe::ImageManagerFe
ImageManagerFe(int order, int dirOrder, bool showAll, int showType, QString dateFormat)
Definition: imagemanager.h:501
MEDIATYPE_MIXED
@ MEDIATYPE_MIXED
Definition: mythmedia.h:27
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:802
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:124
ImageDbReader::m_showType
int m_showType
Type of images to display - pic only/video only/both.
Definition: imagemanager.h:443
ImageHandler::HandleRename
QStringList HandleRename(const QString &id, const QString &newBase) const
Change name of an image/dir.
Definition: imagemanager.cpp:1235
ImageDb::SetHidden
bool SetHidden(bool hide, const QString &ids) const
Sets hidden status of an image/dir in database.
Definition: imagemanager.cpp:928
PHOTO_DB_ID
#define PHOTO_DB_ID
Definition: imagetypes.h:29
Device::m_thumbs
QString m_thumbs
Dir sub-path of device thumbnails.
Definition: imagemanager.cpp:113
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:80
MSqlQuery::size
int size(void) const
Definition: mythdbcon.h:211
ImageDbReader::GetImages
int GetImages(const ImageIdList &ids, ImageList &files, ImageList &dirs) const
Returns images (local or remote but not a combination)
Definition: imagemanager.cpp:1858
DeviceManager::GetDeviceDirs
StringMap GetDeviceDirs() const
Get all known devices.
Definition: imagemanager.cpp:246
ImageAdapterBase::BaseNameOf
static QString BaseNameOf(const QString &path)
Extracts file name (incl extension) from a filepath.
Definition: imagemanager.h:136
ImageManagerFe::CreateThumbnails
void CreateThumbnails(const ImageIdList &ids, bool forFolder)
Create thumbnails or verify that they already exist.
Definition: imagemanager.cpp:2004
ImageDbLocal::m_dbExists
bool m_dbExists
Definition: imagemanager.h:329
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:1917
ImageItem::m_type
int m_type
Type of node: dir, video etc.
Definition: imagetypes.h:97
kVideoFile
@ kVideoFile
A video.
Definition: imagetypes.h:40
MediaMonitor::GetMedias
QList< MythMediaDevice * > GetMedias(unsigned mediatypes)
Ask for available media. Must be locked with ValidateAndLock().
Definition: mythmediamonitor.cpp:613
ReadMetaThread
Task to read all metadata from file.
Definition: imagemanager.cpp:1147
Device::isImport
bool isImport() const
Definition: imagemanager.cpp:105
ImageItem::m_id
int m_id
Uniquely identifies an image (file/dir).
Definition: imagetypes.h:89
ImageDb::UpdateDbImage
bool UpdateDbImage(ImageItemK &im) const
Updates or creates database image or dir.
Definition: imagemanager.cpp:855
MythCoreContext::SendReceiveStringList
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
Definition: mythcorecontext.cpp:1395
kSortByExtDesc
@ kSortByExtDesc
Extension Z-A.
Definition: imagetypes.h:51
ImageItem::m_comment
QString m_comment
User comment, from Exif metadata.
Definition: imagetypes.h:102
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:1826
ImageManagerFe::CreateImages
QString CreateImages(int destId, const ImageListK &images)
Copies database images (but not the files themselves).
Definition: imagemanager.cpp:2250
ImageManagerFe::ScanImagesAction
QString ScanImagesAction(bool start, bool local=false)
Handle scanner start/stop commands.
Definition: imagemanager.cpp:2039
LOC
#define LOC
Definition: imagemanager.cpp:13
ImageHandler::HandleGetMetadata
QStringList HandleGetMetadata(const QString &id) const
Read meta data for an image.
Definition: imagemanager.cpp:1204
MediaMonitor::GetMediaMonitor
static MediaMonitor * GetMediaMonitor(void)
Definition: mythmediamonitor.cpp:83
ImageItem::IsLocal
bool IsLocal() const
Definition: imagetypes.h:119
ImageDbLocal::DropTable
void DropTable()
Remove local image table.
Definition: imagemanager.cpp:1101
ImageMetaData
Abstract class for image metadata.
Definition: imagemetadata.h:99
ImageManagerFe::s_instance
static ImageManagerFe * s_instance
FE Gallery instance.
Definition: imagemanager.h:511
DeviceManager::DeviceName
QString DeviceName(int devId) const
Get model name of the device.
Definition: imagemanager.cpp:136
kNullDevice
static Device kNullDevice
Definition: imagemanager.cpp:119
ImageManagerFe::MakeDir
QString MakeDir(int parent, const QStringList &names, bool rescan=true)
Create directories.
Definition: imagemanager.cpp:2208
ImageDbReader::m_showHidden
bool m_showHidden
Whether hidden images are displayed.
Definition: imagemanager.h:442
ImageItem::m_isHidden
bool m_isHidden
If true, image won't be shown.
Definition: imagetypes.h:105
Device::RemoveDirContents
static void RemoveDirContents(const QString &path)
Clears all files and sub-dirs within a directory.
Definition: imagemanager.cpp:88
StorageGroup::FindFile
QString FindFile(const QString &filename)
Definition: storagegroup.cpp:602
kDirectory
@ kDirectory
A device sub directory.
Definition: imagetypes.h:38
DB_COLUMNS
#define DB_COLUMNS
Definition: imagemanager.cpp:525
MSqlQuery::lastInsertId
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:907
Device::m_mount
QString m_mount
Mountpoint.
Definition: imagemanager.cpp:112
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
ImageManagerFe::DeviceEvent
void DeviceEvent(MythMediaEvent *event)
Manage events for local devices.
Definition: imagemanager.cpp:2482
EXIF_MYTH_SIZE
#define EXIF_MYTH_SIZE
Definition: imagemetadata.h:41
Device::isPresent
bool isPresent() const
Definition: imagemanager.cpp:106
DeviceManager::DeviceCount
int DeviceCount() const
Definition: imagemanager.h:100
ImageManagerFe::IgnoreDirs
static QString IgnoreDirs(const QString &excludes)
Set directories to ignore during scans of the storage group.
Definition: imagemanager.cpp:2192
ImageAdapterBase::m_videoFileExt
QStringList m_videoFileExt
List of file extensions recognised as videos.
Definition: imagemanager.h:179
Device::m_media
MythMediaDevice * m_media
Set for MediaMonitor devices only.
Definition: imagemanager.cpp:114
RESULT_ERR
#define RESULT_ERR(ERR, MESG)
Definition: imagemanager.cpp:21
imagemanager.h
Manages a collection of images.
Device::Close
void Close(bool eject=false)
Releases device.
Definition: imagemanager.cpp:61
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:201
mythmediamonitor.h
MEDIASTAT_USEABLE
@ MEDIASTAT_USEABLE
Definition: mythmedia.h:19
RemoveFromDB
bool RemoveFromDB(Bookmark *site)
Definition: browserdbutil.cpp:158
Device::RemoveThumbs
void RemoveThumbs(void) const
Delete thumbnails associated with device.
Definition: imagemanager.cpp:95
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
MythMediaDevice::getDevicePath
const QString & getDevicePath() const
Definition: mythmedia.h:61
kDirRequestPriority
@ kDirRequestPriority
Client request to display a directory thumbnail.
Definition: imagethumbs.h:35
MythMediaDevice::getStatus
MythMediaStatus getStatus() const
Definition: mythmedia.h:70
ImageAdapterSg::Notify
static void Notify(const QString &mesg, const QStringList &extra)
Send message to all clients about remote ids.
Definition: imagemanager.cpp:487
DEVICE_INVALID
#define DEVICE_INVALID
Definition: imagemanager.h:71
ImageManagerFe::HideFiles
QString HideFiles(bool hidden, const ImageIdList &ids)
Hide/unhide images.
Definition: imagemanager.cpp:2085
IMAGE_STORAGE_GROUP
#define IMAGE_STORAGE_GROUP
Definition: imagemanager.h:63
ImageAdapterSg::m_sg
StorageGroup m_sg
Images storage group.
Definition: imagemanager.h:266
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
FileAssociations::getList
const association_list & getList() const
Definition: dbaccess.cpp:805
STORAGE_GROUP_MOUNT
#define STORAGE_GROUP_MOUNT
Definition: imagemanager.cpp:17
ImageDb::GetImages
int GetImages(const QString &ids, ImageList &files, ImageList &dirs, const QString &refine="") const
Read database images/dirs by id.
Definition: imagemanager.cpp:581
ImageDb::InsertDbImage
int InsertDbImage(ImageItemK &im, bool checkForDuplicate=false) const
Adds new image to database, optionally checking for existing filepath.
Definition: imagemanager.cpp:797
Device
A device containing images (ie. USB stick, CD, storage group etc)
Definition: imagemanager.cpp:33
MEDIASTAT_MOUNTED
@ MEDIASTAT_MOUNTED
Definition: mythmedia.h:21
ImageDb::CreateImage
ImageItem * CreateImage(const MSqlQuery &query) const
Create image from Db query data.
Definition: imagemanager.cpp:538
ImageHandler::HandleCover
QStringList HandleCover(int dir, int cover) const
Updates/resets cover thumbnail for an image dir.
Definition: imagemanager.cpp:1605
DeviceManager::ThumbDir
QString ThumbDir(int fs) const
Definition: imagemanager.cpp:142
ImageManagerBe::ImageManagerBe
ImageManagerBe()
Definition: imagemanager.h:384
ImageDbReader::TypeSelector
static QString TypeSelector(int type)
Generate SQL type filter clause.
Definition: imagemanager.cpp:1762
MythMediaDevice::getDeviceModel
const QString & getDeviceModel() const
Definition: mythmedia.h:67
ImageMetaData::FromVideo
static ImageMetaData * FromVideo(const QString &filePath)
Factory to retrieve metadata from videos.
Definition: imagemetadata.cpp:709
ImageItem::m_device
int m_device
Id of media device. Always 0 (SG) for remotes, 1+ for local devices.
Definition: imagetypes.h:95
ImageManagerFe::CloseDevices
void CloseDevices(int devId=DEVICE_INVALID, bool eject=false)
Definition: imagemanager.cpp:2431
ImageItem::PartitionIds
static StringPair PartitionIds(const ImageIdList &ids)
Separates list of ids into a list of local ids and a list of remote ids.
Definition: imagetypes.h:140
true
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
ImageDbSg::ImageDbSg
ImageDbSg()
SG database constructor.
Definition: imagemanager.cpp:1080
ImageManagerFe::ChangeOrientation
QString ChangeOrientation(ImageFileTransform transform, const ImageIdList &ids)
Apply an orientation transform to images.
Definition: imagemanager.cpp:2116
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
ImageHandler::HandleTransform
QStringList HandleTransform(int transform, const QString &ids) const
Change orientation of pictures by applying a transformation.
Definition: imagemanager.cpp:1502
dbaccess.h
ImageManagerFe::getInstance
static ImageManagerFe & getInstance()
Get Frontend Gallery.
Definition: imagemanager.cpp:1980
ImageAdapterLocal::CreateItem
ImageItem * CreateItem(const QFileInfo &fi, int parentId, int devId, const QString &base) const
Construct a local image from a file.
Definition: imagemanager.cpp:372
ImageManagerFe::DeviceCaption
QString DeviceCaption(ImageItemK &im) const
Return translated device name.
Definition: imagemanager.cpp:2392
kSortByDateDesc
@ kSortByDateDesc
Exif date Latest -> Earliest.
Definition: imagetypes.h:55
Orientation::Transform
int Transform(int transform)
Adjust orientation to apply a transform to an image.
Definition: imagemetadata.cpp:28
ImageHandler::HandleDbCreate
QStringList HandleDbCreate(QStringList defs) const
Creates images for files created by a copy operation.
Definition: imagemanager.cpp:1354
ImageDbReader::m_refineClause
QString m_refineClause
SQL clause for image filtering/ordering.
Definition: imagemanager.h:444
ImageMetaData::ToString
static QString ToString(const QString &name, const QString &label, const QString &value)
Encodes metadata into a string as <tag name><tag label><tag value>
Definition: imagemetadata.h:112
ImageFileTransform
ImageFileTransform
Image transformations.
Definition: imagemetadata.h:46
EXIF_MYTH_ORIENT
#define EXIF_MYTH_ORIENT
Definition: imagemetadata.h:42
ImageDb::GetImageTree
bool GetImageTree(int id, ImageList &files, const QString &refine) const
Returns all files in the sub-tree of a dir.
Definition: imagemanager.cpp:710
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
toString
QString toString(MarkTypes type)
Definition: programtypes.cpp:26
ImageHash
QHash< QString, ImagePtr > ImageHash
Definition: imagetypes.h:161
mythdate.h
ImageHandler::HandleDbMove
QStringList HandleDbMove(const QString &ids, const QString &srcPath, QString destPath) const
Updates images that have been renamed.
Definition: imagemanager.cpp:1413
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:224
kSortByNameAsc
@ kSortByNameAsc
Name A-Z.
Definition: imagetypes.h:46
kPicOnly
@ kPicOnly
Hide videos.
Definition: imagemanager.h:79
ImageManagerFe::ClearStorageGroup
static void ClearStorageGroup()
Clear database & thumbnails of Storage Group images.
Definition: imagemanager.cpp:2178
MythCoreContext::SendEvent
void SendEvent(const MythEvent &event)
Definition: mythcorecontext.cpp:1554
DeviceManager::~DeviceManager
~DeviceManager()
Definition: imagemanager.cpp:122
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
FileAssociations::association_list
std::vector< file_association > association_list
Definition: dbaccess.h:154
StringMap
QMap< int, QString > StringMap
Definition: imagetypes.h:63
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:200
ImageHandler< ImageDbSg >
ImageAdapterBase::FormatSize
static QString FormatSize(int sizeKib)
Definition: imagemanager.h:143
ImageDb::SetOrientation
bool SetOrientation(int id, int orientation) const
Sets image orientation in Db.
Definition: imagemanager.cpp:978
formats
const std::array< const std::string, 8 > formats
Definition: vbilut.cpp:189
MythMediaEvent
Definition: mythmedia.h:183
ImageDbReader::GetDescendants
void GetDescendants(const ImageIdList &ids, ImageList &files, ImageList &dirs) const
Return all (local or remote) images that are direct children of a dir.
Definition: imagemanager.cpp:1898
ImageAdapterBase::SupportedImages
static QStringList SupportedImages()
Return recognised pictures.
Definition: imagemanager.cpp:334
ImageDbReader::OrderSelector
static QString OrderSelector(int order)
Generate SQL ordering clause.
Definition: imagemanager.cpp:1798
ImageItem::m_modTime
std::chrono::seconds m_modTime
Filesystem modified datestamp.
Definition: imagetypes.h:98
DBLOC
#define DBLOC
Definition: imagemanager.cpp:14
ImageAdapterBase::PathOf
static QString PathOf(const QString &path)
Extracts path from a filepath.
Definition: imagemanager.h:140
ImageListK
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:166
clear
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:866
MediaMonitor::Unlock
void Unlock(MythMediaDevice *pMedia)
decrements the MythMediaDevices reference count
Definition: mythmediamonitor.cpp:519
Orientation::Description
QString Description() const
Generate text description of orientation.
Definition: imagemetadata.cpp:228
ImageManagerFe::LongDateOf
static QString LongDateOf(const ImagePtrK &im)
Return a timestamp/datestamp for an image or dir.
Definition: imagemanager.cpp:2351
RESULT_OK
#define RESULT_OK(MESG)
Definition: imagemanager.cpp:25
kSortByExtAsc
@ kSortByExtAsc
Extension A-Z.
Definition: imagetypes.h:50
EXIF_MYTH_PATH
#define EXIF_MYTH_PATH
Definition: imagemetadata.h:39
StorageGroup::GetDirList
QStringList GetDirList(void) const
Definition: storagegroup.h:23
ImageManagerFe::SetCover
QString SetCover(int parent, int cover)
Set image to use as a cover thumbnail(s)
Definition: imagemanager.cpp:2148
uint
unsigned int uint
Definition: compat.h:144
ImageMetaData::FromPicture
static ImageMetaData * FromPicture(const QString &filePath)
Factory to retrieve metadata from pictures.
Definition: imagemetadata.cpp:700
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
ImageItem::IsLocalId
static bool IsLocalId(int id)
Determine image type (local/remote) from its id. Root/Gallery is remote.
Definition: imagetypes.h:122
ImageItem::m_orientation
int m_orientation
Image orientation.
Definition: imagetypes.h:101
ImageItem::m_baseName
QString m_baseName
File/Dir name with extension (no path)
Definition: imagetypes.h:92
MediaMonitor
Definition: mythmediamonitor.h:47
ImageList
QVector< ImagePtr > ImageList
Definition: imagetypes.h:160
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:936
DeviceManager::DeviceMount
QString DeviceMount(int devId) const
Get path at which the device is mounted.
Definition: imagemanager.cpp:129
ImageManagerFe::CreateImport
QString CreateImport()
Definition: imagemanager.cpp:2528
ImageItem::IsLocalParent
static bool IsLocalParent(int id)
Parents of locals are locals or root.
Definition: imagetypes.h:124
ImageHandler::RemoveFiles
void RemoveFiles(ImageList &images) const
Deletes images and dirs from the filesystem.
Definition: imagemanager.cpp:1726
ImageAdapterBase::GetAbsThumbPath
static QString GetAbsThumbPath(const QString &devPath, const QString &path)
Get absolute filepath for thumbnail of an image.
Definition: imagemanager.h:148
ImageMetaData::GetAllTags
virtual QStringList GetAllTags()=0
ImageDbReader::GetDescendantCount
void GetDescendantCount(int id, int &dirs, int &pics, int &videos, int &sizeKb) const
Return counts of dirs, pics and videos in the subtree of a dir. Also dir size.
Definition: imagemanager.cpp:1934
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:930
THUMBNAIL_SUBDIR
#define THUMBNAIL_SUBDIR
Definition: imagemanager.h:69
Device::m_present
bool m_present
True when gallery UI is running & device is useable. Always true for imports.
Definition: imagemanager.cpp:110
FileAssociations::getFileAssociation
static FileAssociations & getFileAssociation()
Definition: dbaccess.cpp:830
kSortByModTimeDesc
@ kSortByModTimeDesc
File modified time Latest -> Earliest.
Definition: imagetypes.h:49
mthreadpool.h
Device::m_dir
QTemporaryDir * m_dir
Dir path of images: import devices only.
Definition: imagemanager.cpp:115
ImageHandler::HandleScanRequest
QStringList HandleScanRequest(const QString &command, int devId=DEVICE_INVALID) const
Process scan requests.
Definition: imagemanager.cpp:1648
ImageHandler::HandleDirs
QStringList HandleDirs(const QString &destId, bool rescan, const QStringList &relPaths) const
Creates new image directories.
Definition: imagemanager.cpp:1549
kImageFile
@ kImageFile
A picture.
Definition: imagetypes.h:39
IMPORTDIR
#define IMPORTDIR
Definition: imagemanager.cpp:29
ImageManagerFe::MoveDbImages
QString MoveDbImages(const ImagePtrK &destDir, ImageListK &images, const QString &srcPath)
Moves database images (but not the files themselves).
Definition: imagemanager.cpp:2294
ImageAdapterBase::m_dirFilter
QDir m_dirFilter
A pre-configured dir for reading image/video files.
Definition: imagemanager.h:175
MythMediaType
MythMediaType
Definition: mythmedia.h:24
kFlipVertical
@ kFlipVertical
Reflect about horizontal axis.
Definition: imagemetadata.h:51
ImagePtr
QSharedPointer< ImageItem > ImagePtr
Definition: imagetypes.h:159
MythDate::kAddYear
@ kAddYear
Add year to string if not included.
Definition: mythdate.h:25
ImageManagerFe
The image manager for use by Frontends.
Definition: imagemanager.h:456
StorageGroup::FindNextDirMostFree
QString FindNextDirMostFree(void)
Definition: storagegroup.cpp:671
ImageDbReader::m_fileOrder
int m_fileOrder
Display ordering of pics/videos.
Definition: imagemanager.h:441
ImageDbReader::m_remote
ImageDbSg * m_remote
Remote database access.
Definition: imagemanager.h:438
ImageItem
Represents a picture, video or directory.
Definition: imagetypes.h:68
MEDIATYPE_MGALLERY
@ MEDIATYPE_MGALLERY
Definition: mythmedia.h:33
ImageDbLocal::ImageDbLocal
ImageDbLocal()
Local database constructor.
Definition: imagemanager.cpp:1090
Device::~Device
~Device()
Delete device, its thumbnails and any imported images.
Definition: imagemanager.cpp:47
MediaMonitor::EjectMedia
void EjectMedia(const QString &path)
Definition: mythmediamonitor.cpp:275
DeviceManager::LocateMount
int LocateMount(const QString &mount) const
Find the id of a device.
Definition: imagemanager.cpp:232
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:878
Device::Device
Device(QString name, QString mount, MythMediaDevice *media=nullptr, QTemporaryDir *import=nullptr)
Definition: imagemanager.cpp:36
std
Definition: mythchrono.h:23
EXIF_MYTH_NAME
#define EXIF_MYTH_NAME
Definition: imagemetadata.h:40
ImageHandler::HandleIgnore
QStringList HandleIgnore(const QString &exclusions) const
Updates exclusion list for images.
Definition: imagemanager.cpp:1628
kSortByDateAsc
@ kSortByDateAsc
Exif date Earliest -> Latest.
Definition: imagetypes.h:54
DeviceManager::OpenDevice
int OpenDevice(const QString &name, const QString &mount, MythMediaDevice *media=nullptr, QTemporaryDir *dir=nullptr)
Define a new device and assign it a unique id. If the device is already known, its existing id is ret...
Definition: imagemanager.cpp:157
ImageDb::SetCover
bool SetCover(int dir, int id) const
Set the thumbnail(s) to be used for a dir.
Definition: imagemanager.cpp:954
ImageIdList
QList< int > ImageIdList
Definition: imagetypes.h:60
ImageAdapterBase::ThumbPath
static QString ThumbPath(const ImageItem &im)
Thumbnails of videos are a JPEG snapshot with jpg suffix appended.
Definition: imagemanager.h:152
ImageDb::ReadImages
int ReadImages(ImageList &dirs, ImageList &files, const QString &selector) const
Read selected database images/dirs.
Definition: imagemanager.cpp:1004
ImageManagerFe::CrumbName
QString CrumbName(ImageItemK &im, bool getPath=false) const
Return a displayable name (with optional path) for an image.
Definition: imagemanager.cpp:2410
ImageItem::m_parentId
int m_parentId
Id of parent dir.
Definition: imagetypes.h:96
ImageDb::ClearDb
void ClearDb(int devId, const QString &action)
Clear Db for device & remove device.
Definition: imagemanager.cpp:761
StringPair
QPair< QString, QString > StringPair
Definition: imagetypes.h:61
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:1879
MythMediaDevice::getMediaType
MythMediaType getMediaType() const
Definition: mythmedia.h:91
ImageAdapterSg::GetAbsFilePath
QString GetAbsFilePath(const ImagePtrK &im) const
Get absolute filepath for a remote image.
Definition: imagemanager.cpp:515
EXIF_MYTH_HOST
#define EXIF_MYTH_HOST
Definition: imagemetadata.h:38
build_compdb.action
action
Definition: build_compdb.py:9
ImageDbReader::m_dirOrder
int m_dirOrder
Display ordering of dirs.
Definition: imagemanager.h:440
ImageManagerBe::getInstance
static ImageManagerBe * getInstance()
Get Backend Gallery.
Definition: imagemanager.cpp:1968
ImageDb::GetDirectory
int GetDirectory(int id, ImagePtr &parent, ImageList &files, ImageList &dirs, const QString &refine) const
Read a dir and its immediate children from Db.
Definition: imagemanager.cpp:619
DeviceManager::CloseDevices
QStringList CloseDevices(int devId, const QString &action)
Remove a device (or all devices)
Definition: imagemanager.cpp:189
DB_TABLE
#define DB_TABLE
Definition: imagemanager.cpp:19
ImageAdapterLocal::Notify
static void Notify(const QString &mesg, const QStringList &extra)
Send local message to UI about local ids.
Definition: imagemanager.cpp:422
ImageDb::RemoveFromDB
QStringList RemoveFromDB(const ImageList &imList) const
Remove images/dirs from database.
Definition: imagemanager.cpp:898
ImageDb::ReadAllImages
bool ReadAllImages(ImageHash &files, ImageHash &dirs) const
Read all database images and dirs as map. No filters or ordering applied.
Definition: imagemanager.cpp:730
ImageDbLocal::CreateTable
bool CreateTable()
Create local database table, if it doesn't exist.
Definition: imagemanager.cpp:1115
MediaMonitor::ValidateAndLock
bool ValidateAndLock(MythMediaDevice *pMedia)
Validates the MythMediaDevice and increments its reference count.
Definition: mythmediamonitor.cpp:502
MythDate::kDateFull
@ kDateFull
Default local time.
Definition: mythdate.h:19
DeviceManager::GetAbsentees
QList< int > GetAbsentees()
Get list of mountpoints for non-import devices.
Definition: imagemanager.cpp:276
ImageDbReader::SetRefinementClause
void SetRefinementClause()
Sets filter/ordering SQL clause used when reading database according to current filter/sort settings.
Definition: imagemanager.cpp:1779
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:862
ImageItem::m_userThumbnail
int m_userThumbnail
Id of thumbnail to use as cover (dirs only)
Definition: imagetypes.h:106
ImageHandler::HandleDelete
QStringList HandleDelete(const QString &ids) const
Deletes images/dirs.
Definition: imagemanager.cpp:1311
ImageItem::IsDevice
bool IsDevice() const
Definition: imagetypes.h:116
ImageAdapterSg::GetScanDirs
StringMap GetScanDirs() const
Returns SG dirs.
Definition: imagemanager.cpp:498
MythMediaDevice
Definition: mythmedia.h:48
ImageItem::m_date
std::chrono::seconds m_date
Image creation date, from Exif metadata.
Definition: imagetypes.h:100
ImageManagerFe::DeleteFiles
QString DeleteFiles(const ImageIdList &ids)
Delete images.
Definition: imagemanager.cpp:2321
kSortByModTimeAsc
@ kSortByModTimeAsc
File modified time Earliest -> Latest.
Definition: imagetypes.h:48
ReadMetaThread::ReadMetaThread
ReadMetaThread(ImagePtrK im, QString path)
Definition: imagemanager.cpp:1150
ImageDb< ImageAdapterLocal >::m_table
QString m_table
Db table name.
Definition: imagemanager.h:310
Device::setPresent
void setPresent(MythMediaDevice *media)
Definition: imagemanager.cpp:107
ImageDb::GetChildren
int GetChildren(const QString &ids, ImageList &files, ImageList &dirs, const QString &refine="") const
Read immediate children of a dir.
Definition: imagemanager.cpp:601
ReadMetaThread::m_path
QString m_path
Definition: imagemanager.cpp:1191
ImageDb
Database API.
Definition: imagemanager.h:274
ImageItem::m_extension
QString m_extension
Image file extension.
Definition: imagetypes.h:94
MythDate::kTime
@ kTime
Default local time.
Definition: mythdate.h:22
kDevice
@ kDevice
Storage Group and local mounted media.
Definition: imagetypes.h:36
ImageAdapterSg::CreateItem
ImageItem * CreateItem(const QFileInfo &fi, int parentId, int devId, const QString &base) const
Construct a remote image from a file.
Definition: imagemanager.cpp:438
ImageManagerBe
The image manager to be used by the Backend.
Definition: imagemanager.h:378
kSortBySizeAsc
@ kSortBySizeAsc
File size Smallest -> Largest.
Definition: imagetypes.h:52
ImageDb::GetDescendants
bool GetDescendants(const QString &ids, ImageList &files, ImageList &dirs) const
Return images and all of their descendants.
Definition: imagemanager.cpp:661
ImageManagerFe::RequestMetaData
void RequestMetaData(int id)
Requests all exif/ffmpeg tags for an image, which returns by event.
Definition: imagemanager.cpp:2168
MThreadPool::globalInstance
static MThreadPool * globalInstance(void)
Definition: mthreadpool.cpp:317
MythMediaStatus
MythMediaStatus
Definition: mythmedia.h:12
DeviceManager::m_devices
DeviceMap m_devices
Device store.
Definition: imagemanager.h:119
ImageDb::GetDescendantCount
void GetDescendantCount(int id, bool all, int &dirs, int &pics, int &videos, int &sizeKb) const
Return counts of dirs, pics, videos and size in the subtree of a dir.
Definition: imagemanager.cpp:1039
ImageAdapterBase::GetImageType
ImageNodeType GetImageType(const QString &ext) const
Determine file type from its extension.
Definition: imagemanager.h:165
ImageManagerFe::ScanQuery
static QStringList ScanQuery()
Returns storage group scanner status.
Definition: imagemanager.cpp:2065
kUnknown
@ kUnknown
Unprocessable file type.
Definition: imagetypes.h:35
MythCoreContext::SaveSettingOnHost
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
Definition: mythcorecontext.cpp:915
ImageManagerFe::RenameFile
QString RenameFile(const ImagePtrK &im, const QString &name)
Rename an image.
Definition: imagemanager.cpp:2230
MythMediaDevice::getVolumeID
const QString & getVolumeID() const
Definition: mythmedia.h:72
Device::m_name
QString m_name
Device model/volume/id.
Definition: imagemanager.cpp:111
ImageManagerFe::ShortDateOf
QString ShortDateOf(const ImagePtrK &im) const
Return a short datestamp for thumbnail captions.
Definition: imagemanager.cpp:2377
ImageHandler::HandleCreateThumbnails
QStringList HandleCreateThumbnails(const QStringList &message) const
Creates thumbnails on-demand.
Definition: imagemanager.cpp:1694
ReadMetaThread::m_im
ImagePtrK m_im
Definition: imagemanager.cpp:1190
ImageAdapterBase::m_imageFileExt
QStringList m_imageFileExt
List of file extensions recognised as pictures.
Definition: imagemanager.h:177
ImageHandler::HandleHide
QStringList HandleHide(bool hide, const QString &ids) const
Hides/unhides images/dirs.
Definition: imagemanager.cpp:1480
kSortBySizeDesc
@ kSortBySizeDesc
File size Largest -> Smallest.
Definition: imagetypes.h:53
Orientation
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:62
MThreadPool::start
void start(QRunnable *runnable, const QString &debugName, int priority=0)
Definition: mthreadpool.cpp:352
ImageItem::m_size
int m_size
Filesize (files only)
Definition: imagetypes.h:99
MEDIATYPE_DATA
@ MEDIATYPE_DATA
Definition: mythmedia.h:26
GALLERY_DB_ID
#define GALLERY_DB_ID
Definition: imagetypes.h:27
kVideoOnly
@ kVideoOnly
Hide pictures.
Definition: imagemanager.h:80
TEMP_SUBDIR
#define TEMP_SUBDIR
Definition: imagemanager.h:67
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:922
ImageAdapterBase::SupportedVideos
static QStringList SupportedVideos()
Return recognised video extensions.
Definition: imagemanager.cpp:349
ReadMetaThread::run
void run() override
Definition: imagemanager.cpp:1153
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:827
ImageItem::m_filePath
QString m_filePath
Absolute for local images. Usually SG-relative for remotes.
Definition: imagetypes.h:93
kPicRequestPriority
@ kPicRequestPriority
Client request to display an image thumbnail.
Definition: imagethumbs.h:34
build_compdb.paths
paths
Definition: build_compdb.py:13
ImageManagerFe::DetectLocalDevices
bool DetectLocalDevices()
Detect and scan local devices.
Definition: imagemanager.cpp:2444