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));
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.constEnd() - 1).key() + 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  im->m_date = im->m_filePath.contains(IMPORTDIR)
385  ? fi.lastModified().toSecsSinceEpoch()
386  : QDateTime::currentSecsSinceEpoch();
387  im->m_modTime = im->m_date;
388  im->m_type = kDevice;
389  return im;
390  }
391 
392  im->m_modTime = fi.lastModified().toSecsSinceEpoch();
393 
394  if (fi.isDir())
395  {
396  im->m_type = kDirectory;
397  return im;
398  }
399 
400  im->m_extension = fi.suffix().toLower();
401  im->m_type = GetImageType(im->m_extension);
402 
403  if (im->m_type == kUnknown)
404  {
405  delete im;
406  return nullptr;
407  }
408 
409  im->m_thumbPath = GetAbsThumbPath(ThumbDir(im->m_device), ThumbPath(*im));
410  im->m_size = fi.size();
411 
412  return im;
413 }
414 
415 
421 void ImageAdapterLocal::Notify(const QString &mesg,
422  const QStringList &extra)
423 {
424  QString host(gCoreContext->GetHostName());
425  gCoreContext->SendEvent(MythEvent(QString("%1 %2").arg(mesg, host), extra));
426 }
427 
428 
437 ImageItem *ImageAdapterSg::CreateItem(const QFileInfo &fi, int parentId,
438  int /*devId*/, const QString &base) const
439 {
440  auto *im = new ImageItem();
441 
442  im->m_device = 0;
443  im->m_parentId = parentId;
444 
445  if (parentId == GALLERY_DB_ID)
446  {
447  // All SG dirs map to a single Db dir
448  im->m_filePath = "";
449  im->m_type = kDevice;
450  im->m_date = QDateTime::currentMSecsSinceEpoch() / 1000;
451  im->m_modTime = im->m_date;
452  return im;
453  }
454 
455  // Strip SG path & leading / to leave a relative path
456  im->m_filePath = fi.absoluteFilePath().mid(base.size() + 1);
457  im->m_modTime = fi.lastModified().toSecsSinceEpoch();
458 
459  if (fi.isDir())
460  {
461  im->m_type = kDirectory;
462  return im;
463  }
464 
465  im->m_extension = fi.suffix().toLower();
466  im->m_type = GetImageType(im->m_extension);
467 
468  if (im->m_type == kUnknown)
469  {
470  delete im;
471  return nullptr;
472  }
473 
474  im->m_thumbPath = GetAbsThumbPath(ThumbDir(im->m_device), ThumbPath(*im));
475  im->m_size = fi.size();
476 
477  return im;
478 }
479 
480 
486 void ImageAdapterSg::Notify(const QString &mesg,
487  const QStringList &extra)
488 {
489  gCoreContext->SendEvent(MythEvent(mesg, extra));
490 }
491 
492 
498 {
499  StringMap map;
500  int i = 0;
501  QStringList paths = m_sg.GetDirList();
502  for (const auto& path : qAsConst(paths))
503  map.insert(i++, path);
504  return map;
505 }
506 
507 
515 {
516  if (im->IsDevice())
517  return m_sg.FindNextDirMostFree();
518  return im->m_filePath.startsWith("/") ? im->m_filePath
519  : m_sg.FindFile(im->m_filePath);
520 }
521 
522 
523 // Database fields used by several image queries
524 #define DB_COLUMNS \
525 "file_id, filename, name, dir_id, type, modtime, size, " \
526 "extension, date, hidden, orientation, angle, path, zoom"
527 // Id, filepath, basename, parentId, type, modtime, size,
528 // extension, image date, hidden, orientation, cover id, comment, device id
529 
530 
536 template <class FS>
538 {
539  auto *im = new ImageItem(FS::ImageId(query.value(0).toInt()));
540 
541  // Ordered as per DB_COLUMNS
542  im->m_filePath = query.value(1).toString();
543  im->m_baseName = query.value(2).toString();
544  im->m_parentId = FS::ImageId(query.value(3).toInt());
545  im->m_type = query.value(4).toInt();
546  im->m_modTime = query.value(5).toInt();
547  im->m_size = query.value(6).toInt();
548  im->m_extension = query.value(7).toString();
549  im->m_date = query.value(8).toUInt();
550  im->m_isHidden = query.value(9).toBool();
551  im->m_orientation = query.value(10).toInt();
552  im->m_userThumbnail = FS::ImageId(query.value(11).toInt());
553  im->m_comment = query.value(12).toString();
554  im->m_device = query.value(13).toInt();
555  im->m_url = FS::MakeFileUrl(im->m_filePath);
556 
557  if (im->IsFile())
558  {
559  // Only pics/vids have thumbs
560  QString thumbPath(FS::ThumbPath(*im));
561  QString devPath(FS::ThumbDir(im->m_device));
562  QString url(FS::MakeThumbUrl(devPath, thumbPath));
563 
564  im->m_thumbPath = FS::GetAbsThumbPath(devPath, thumbPath);
565  im->m_thumbNails.append(qMakePair(im->m_id, url));
566  }
567  return im;
568 }
569 
570 
579 template <class FS>
580 int ImageDb<FS>::GetImages(const QString &ids, ImageList &files, ImageList &dirs,
581  const QString &refine) const
582 {
583  if (ids.isEmpty())
584  return 0;
585 
586  QString select = QString("file_id IN (%1) %2").arg(FS::DbIds(ids), refine);
587  return ReadImages(dirs, files, select);
588 }
589 
590 
599 template <class FS>
600 int ImageDb<FS>::GetChildren(const QString &ids, ImageList &files, ImageList &dirs,
601  const QString &refine) const
602 {
603  QString select = QString("dir_id IN (%1) %2").arg(FS::DbIds(ids), refine);
604  return ReadImages(dirs, files, select);
605 }
606 
607 
617 template <class FS>
619  ImageList &files, ImageList &dirs,
620  const QString &refine) const
621 {
623  query.prepare(QString("SELECT " DB_COLUMNS " FROM %1 "
624  "WHERE (dir_id = :ID1 OR file_id = :ID2) "
625  "%2;").arg(m_table, refine));
626 
627  // Qt < 5.4 won't bind multiple occurrences
628  int dbId = FS::DbId(id);
629  query.bindValue(":ID1", dbId);
630  query.bindValue(":ID2", dbId);
631 
632  if (!query.exec())
633  {
635  return -1;
636  }
637  while (query.next())
638  {
639  ImagePtr im(CreateImage(query));
640 
641  if (im->IsFile())
642  files.append(im);
643  else if (im->m_id == id)
644  parent = im;
645  else
646  dirs.append(im);
647  }
648  return query.size();
649 }
650 
651 
659 template <class FS>
660 bool ImageDb<FS>::GetDescendants(const QString &ids,
661  ImageList &files, ImageList &dirs) const
662 {
663  if (ids.isEmpty())
664  return false;
665 
666  if (ReadImages(dirs, files, QString("file_id IN (%1)").arg(FS::DbIds(ids))) < 0)
667  return false;
668 
670  QString sql =
671  QString("SELECT " DB_COLUMNS
672  ", LENGTH(filename) - LENGTH(REPLACE(filename, '/', ''))"
673  " AS depth "
674  "FROM %1 WHERE filename LIKE :PREFIX "
675  "ORDER BY depth;").arg(m_table);
676 
677  for (const auto& im1 : qAsConst(dirs))
678  {
679  query.prepare(sql);
680  query.bindValue(":PREFIX", im1->m_filePath + "/%");
681 
682  if (!query.exec())
683  {
685  return false;
686  }
687 
688  while (query.next())
689  {
690  ImagePtr im2(CreateImage(query));
691  if (im2->IsDirectory())
692  dirs.append(im2);
693  else
694  files.append(im2);
695  }
696  }
697  return true;
698 }
699 
700 
708 template <class FS>
709 bool ImageDb<FS>::GetImageTree(int id, ImageList &files, const QString &refine) const
710 {
711  // Load starting children
712  ImageList dirs;
713  if (GetChildren(QString::number(id), files, dirs, refine) < 0)
714  return false;
715 
716  for (const auto& im : qAsConst(dirs))
717  if (!GetImageTree(im->m_id, files, refine))
718  return false;
719  return true;
720 }
721 
722 
728 template <class FS>
730 {
732  query.prepare(QString("SELECT " DB_COLUMNS " FROM %1").arg(m_table));
733 
734  if (!query.exec())
735  {
737  return false;
738  }
739 
740  while (query.next())
741  {
742  ImagePtr im(CreateImage(query));
743  if (im->IsDirectory())
744  dirs.insert(im->m_filePath, im);
745  else
746  files.insert(im->m_filePath, im);
747  }
748  return true;
749 }
750 
751 
759 template <class FS>
760 void ImageDb<FS>::ClearDb(int devId, const QString &action)
761 {
762  if (action == "DEVICE CLOSE ALL")
763  // Retain Db images when closing UI
764  return;
765 
767 
768  if (action == "DEVICE CLEAR ALL")
769  {
770  // Clear images from all devices. Reset auto-increment
771  query.prepare(QString("TRUNCATE TABLE %1;").arg(m_table));
772 
773  if (!query.exec())
775  }
776  else // Actions DEVICE REMOVE & DEVICE EJECT
777  {
778  // Delete all images of the device
779  query.prepare(QString("DELETE IGNORE FROM %1 WHERE zoom = :FS;").arg(m_table));
780  query.bindValue(":FS", devId);
781 
782  if (!query.exec())
784  }
785 }
786 
787 
795 template <class FS>
796 int ImageDb<FS>::InsertDbImage(ImageItemK &im, bool checkForDuplicate) const
797 {
799 
800  if (checkForDuplicate)
801  {
802  query.prepare(QString("SELECT file_id FROM %1 WHERE filename = :NAME;")
803  .arg(m_table));
804 
805  query.bindValue(":NAME", im.m_filePath);
806 
807  if (!query.exec())
808  {
810  return -1;
811  }
812 
813  if (query.size() > 0)
814  {
815  LOG(VB_FILE, LOG_DEBUG, QString("Image: %1 already exists in Db")
816  .arg(im.m_filePath));
817  return query.value(0).toInt();
818  }
819  }
820 
821  query.prepare(QString("INSERT INTO %1 (" DB_COLUMNS ") VALUES (0, "
822  ":FILEPATH, :NAME, :PARENT, :TYPE, :MODTIME, "
823  ":SIZE, :EXTENSION, :DATE, :HIDDEN, :ORIENT, "
824  ":COVER, :COMMENT, :FS);").arg(m_table));
825 
826  query.bindValue(":FILEPATH", im.m_filePath);
827  query.bindValue(":NAME", FS::BaseNameOf(im.m_filePath));
828  query.bindValue(":FS", im.m_device);
829  query.bindValue(":PARENT", FS::DbId(im.m_parentId));
830  query.bindValue(":TYPE", im.m_type);
831  query.bindValue(":MODTIME", im.m_modTime);
832  query.bindValue(":SIZE", im.m_size);
833  query.bindValue(":EXTENSION", im.m_extension);
834  query.bindValue(":DATE", im.m_date);
835  query.bindValue(":ORIENT", im.m_orientation);
836  query.bindValue(":COMMENT", im.m_comment.isNull() ? "" : im.m_comment);
837  query.bindValue(":HIDDEN", im.m_isHidden);
838  query.bindValue(":COVER", FS::DbId(im.m_userThumbnail));
839 
840  if (query.exec())
841  return FS::ImageId(query.lastInsertId().toInt());
842 
844  return -1;
845 }
846 
847 
853 template <class FS>
855 {
857  query.prepare(QString
858  ("UPDATE %1 SET "
859  "filename = :FILEPATH, name = :NAME, "
860  "dir_id = :PARENT, type = :TYPE, "
861  "modtime = :MODTIME, size = :SIZE, "
862  "extension = :EXTENSION, date = :DATE, zoom = :FS, "
863  "hidden = :HIDDEN, orientation = :ORIENT, "
864  "angle = :COVER, path = :COMMENT "
865  "WHERE file_id = :ID;").arg(m_table));
866 
867  query.bindValue(":ID", FS::DbId(im.m_id));
868  query.bindValue(":FILEPATH", im.m_filePath);
869  query.bindValue(":NAME", FS::BaseNameOf(im.m_filePath));
870  query.bindValue(":PARENT", FS::DbId(im.m_parentId));
871  query.bindValue(":TYPE", im.m_type);
872  query.bindValue(":MODTIME", im.m_modTime);
873  query.bindValue(":SIZE", im.m_size);
874  query.bindValue(":EXTENSION", im.m_extension);
875  query.bindValue(":DATE", im.m_date);
876  query.bindValue(":FS", im.m_device);
877  query.bindValue(":HIDDEN", im.m_isHidden);
878  query.bindValue(":ORIENT", im.m_orientation);
879  query.bindValue(":COVER", FS::DbId(im.m_userThumbnail));
880  query.bindValue(":COMMENT", im.m_comment.isNull() ? "" : im.m_comment);
881 
882  if (query.exec())
883  return true;
884 
886  return false;
887 }
888 
889 
896 template <class FS>
897 QStringList ImageDb<FS>::RemoveFromDB(const ImageList &imList) const
898 {
899  QStringList ids;
900  if (!imList.isEmpty())
901  {
902  for (const auto& im : qAsConst(imList))
903  ids << QString::number(FS::DbId(im->m_id));
904 
905  QString idents = ids.join(",");
907  query.prepare(QString("DELETE IGNORE FROM %1 WHERE file_id IN (%2);")
908  .arg(m_table, idents));
909 
910  if (!query.exec())
911  {
913  return QStringList();
914  }
915  }
916  return ids;
917 }
918 
919 
926 template <class FS>
927 bool ImageDb<FS>::SetHidden(bool hide, const QString &ids) const
928 {
929  if (ids.isEmpty())
930  return false;
931 
933 
934  query.prepare(QString("UPDATE %1 SET "
935  "hidden = :HIDDEN "
936  "WHERE file_id IN (%2);").arg(m_table, FS::DbIds(ids)));
937  query.bindValue(":HIDDEN", hide ? 1 : 0);
938 
939  if (query.exec())
940  return true;
941 
943  return false;
944 }
945 
946 
952 template <class FS>
953 bool ImageDb<FS>::SetCover(int dir, int id) const
954 {
956 
957  query.prepare(QString("UPDATE %1 SET "
958  "angle = :COVER "
959  "WHERE file_id = :DIR").arg(m_table));
960  query.bindValue(":COVER", FS::DbId(id));
961  query.bindValue(":DIR", FS::DbId(dir));
962  \
963  if (query.exec())
964  return true;
965 
967  return false;
968 }
969 
970 
976 template <class FS>
977 bool ImageDb<FS>::SetOrientation(int id, int orientation) const
978 {
980 
981  query.prepare(QString("UPDATE %1 SET ").arg(m_table) +
982  "orientation = :ORIENTATION "
983  "WHERE file_id = :ID");
984  query.bindValue(":ORIENTATION", orientation);
985  query.bindValue(":ID", FS::DbId(id));
986  \
987  if (query.exec())
988  return true;
989 
991  return false;
992 }
993 
994 
1002 template <class FS>
1004  const QString &selector) const
1005 {
1007  query.prepare(QString("SELECT " DB_COLUMNS " FROM %1 WHERE %2")
1008  .arg(m_table, selector));
1009  if (!query.exec())
1010  {
1012  return -1;
1013  }
1014 
1015  while (query.next())
1016  {
1017  ImagePtr im(CreateImage(query));
1018 
1019  if (im->IsFile())
1020  files.append(im);
1021  else
1022  dirs.append(im);
1023  }
1024  return query.size();
1025 }
1026 
1027 
1037 template <class FS>
1038 void ImageDb<FS>::GetDescendantCount(int id, bool all, int &dirs,
1039  int &pics, int &videos, int &sizeKb) const
1040 {
1041  QString whereClause;
1042  if (!all)
1043  {
1044  whereClause = "WHERE filename LIKE "
1045  "( SELECT CONCAT(filename, '/%') "
1046  " FROM %2 WHERE file_id = :ID);";
1047  }
1048 
1050  query.prepare(QString("SELECT SUM(type <= :FLDR) AS Fldr, "
1051  " SUM(type = :PIC) AS Pics, "
1052  " SUM(type = :VID) AS Vids, "
1053  " SUM(size / 1024) "
1054  "FROM %2 %1;").arg(whereClause).arg(m_table));
1055 
1056  query.bindValue(":FLDR", kDirectory);
1057  query.bindValue(":PIC", kImageFile);
1058  query.bindValue(":VID", kVideoFile);
1059  if (!all)
1060  query.bindValue(":ID", FS::DbId(id));
1061 
1062  if (!query.exec())
1063  {
1065  }
1066  else if (query.next())
1067  {
1068  dirs += query.value(0).toInt();
1069  pics += query.value(1).toInt();
1070  videos += query.value(2).toInt();
1071  sizeKb += query.value(3).toInt();
1072  }
1073 }
1074 
1075 
1080 {
1081  // Be has a single SG device
1083 }
1084 
1085 
1090  : ImageDb(QString("`%1_%2`").arg(DB_TABLE, gCoreContext->GetHostName()))
1091 {
1092  // Remove any table leftover from a previous FE crash
1093  DropTable();
1094 }
1095 
1096 
1101 {
1103  query.prepare(QString("DROP TABLE IF EXISTS %1;").arg(m_table));
1104  if (query.exec())
1105  m_dbExists = false;
1106  else
1108 }
1109 
1110 
1115 {
1116  if (m_dbExists)
1117  return true;
1118 
1120 
1121  // Create temporary table
1122  query.prepare(QString("CREATE TABLE %1 LIKE " DB_TABLE ";").arg(m_table));
1123  if (query.exec())
1124  {
1125  // Store it in memory only
1126  query.prepare(QString("ALTER TABLE %1 ENGINE = MEMORY;").arg(m_table));
1127  if (query.exec())
1128  {
1129  m_dbExists = true;
1130  LOG(VB_FILE, LOG_DEBUG, QString("Created Db table %1").arg(m_table));
1131  return true;
1132  }
1133  }
1135 
1136  // Clean up after failure
1137  query.prepare(QString("DROP TABLE IF EXISTS %1;").arg(m_table));
1138  query.exec();
1139  return false;
1140 }
1141 
1142 
1146 class ReadMetaThread : public QRunnable
1147 {
1148 public:
1149  ReadMetaThread(ImagePtrK im, QString path)
1150  : m_im(std::move(im)), m_path(std::move(path)) {}
1151 
1152  void run() override // QRunnable
1153  {
1154  QStringList tags;
1155  QString orientation;
1156  QString size;
1157 
1158  // Read metadata for files only
1159  if (m_im->IsFile())
1160  {
1161  ImageMetaData *metadata = (m_im->m_type == kVideoFile)
1164  tags = metadata->GetAllTags();
1165  orientation = Orientation(m_im->m_orientation).Description();
1166  size = ImageAdapterBase::FormatSize(m_im->m_size / 1024);
1167  delete metadata;
1168  }
1169 
1170  // Add identifier at front
1171  tags.prepend(QString::number(m_im->m_id));
1172 
1173  // Include file info
1174  tags << ImageMetaData::ToString(EXIF_MYTH_HOST, "Host",
1176  tags << ImageMetaData::ToString(EXIF_MYTH_PATH, "Path",
1178  tags << ImageMetaData::ToString(EXIF_MYTH_NAME, "Name",
1180  tags << ImageMetaData::ToString(EXIF_MYTH_SIZE, "Size", size);
1181  tags << ImageMetaData::ToString(EXIF_MYTH_ORIENT, "Orientation",
1182  orientation);
1183 
1184  MythEvent me("IMAGE_METADATA", tags);
1185  gCoreContext->SendEvent(me);
1186  }
1187 
1188 private:
1190  QString m_path;
1191 };
1192 
1193 
1202 template <class DBFS>
1203 QStringList ImageHandler<DBFS>::HandleGetMetadata(const QString &id) const
1204 {
1205  // Find image in DB
1206  ImageList files;
1207  ImageList dirs;
1208  if (DBFS::GetImages(id, files, dirs) != 1)
1209  RESULT_ERR("Image not found", QString("Unknown image %1").arg(id))
1210 
1211  ImagePtr im = files.isEmpty() ? dirs[0] : files[0];
1212 
1213  QString absPath = DBFS::GetAbsFilePath(im);
1214  if (absPath.isEmpty())
1215  RESULT_ERR("Image not found",
1216  QString("File %1 not found").arg(im->m_filePath))
1217 
1218  auto *worker = new ReadMetaThread(im, absPath);
1219 
1220  MThreadPool::globalInstance()->start(worker, "ImageMetaData");
1221 
1222  RESULT_OK(QString("Fetching metadata for %1").arg(id))
1223 }
1224 
1225 
1233 template <class DBFS>
1234 QStringList ImageHandler<DBFS>::HandleRename(const QString &id,
1235  const QString &newBase) const
1236 {
1237  // Sanity check new name
1238  if (newBase.isEmpty() || newBase.contains("/") || newBase.contains("\\"))
1239  RESULT_ERR("Invalid name", QString("Invalid name %1").arg(newBase))
1240 
1241  // Find image in DB
1242  ImageList files;
1243  ImageList dirs;
1244  if (DBFS::GetImages(id, files, dirs) != 1)
1245  RESULT_ERR("Image not found", QString("Image %1 not in Db").arg(id))
1246 
1247  ImagePtr im = files.isEmpty() ? dirs[0] : files[0];
1248 
1249  // Find file
1250  QString oldPath = DBFS::GetAbsFilePath(im);
1251  if (oldPath.isEmpty())
1252  RESULT_ERR("Image not found",
1253  QString("File %1 not found").arg(im->m_filePath))
1254 
1255  // Generate new filename
1256  QFileInfo oldFi = QFileInfo(oldPath);
1257  QString newName = im->IsDirectory()
1258  ? newBase : QString("%1.%2").arg(newBase, oldFi.suffix());
1259 
1260  im->m_filePath = DBFS::ConstructPath(DBFS::PathOf(im->m_filePath), newName);
1261 
1262  // Ensure no SG duplicate files are created. (Creating clone dirs is ok)
1263  if (im->IsFile())
1264  {
1265  QString existPath = DBFS::GetAbsFilePath(im);
1266  if (!existPath.isEmpty())
1267  RESULT_ERR("Filename already used",
1268  QString("Renaming %1 to %2 will create a duplicate of %3")
1269  .arg(oldPath, im->m_filePath, existPath))
1270  }
1271 
1272  // Rename file or directory
1273  QString newPath = oldFi.dir().absoluteFilePath(newName);
1274  if (!QFile::rename(oldPath, newPath))
1275  RESULT_ERR("Rename failed",
1276  QString("Rename of %1 -> %2 failed").arg(oldPath, newPath))
1277 
1278  if (im->IsDirectory())
1279  {
1280  // Dir name change affects path of all sub-dirs & files and their thumbs
1281  HandleScanRequest("START");
1282  }
1283  else // file
1284  {
1285  // Update db
1286  DBFS::UpdateDbImage(*im);
1287 
1288  // Image is modified, not deleted
1289  QStringList mesg("");
1290  mesg << QString::number(im->m_id);
1291 
1292  // Rename thumbnail.
1293  m_thumbGen->MoveThumbnail(im);
1294 
1295  // Notify clients of changed image
1296  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1297  }
1298  RESULT_OK(QString("Renamed %1 -> %2").arg(oldPath, newPath))
1299 }
1300 
1301 
1309 template <class DBFS>
1310 QStringList ImageHandler<DBFS>::HandleDelete(const QString &ids) const
1311 {
1312  // Get subtree of all files
1313  ImageList files;
1314  ImageList dirs;
1315  // Dirs will be in depth-first order, (subdirs after parent)
1316  DBFS::GetDescendants(ids, files, dirs);
1317 
1318  // Remove files from filesystem first
1319  RemoveFiles(files);
1320  // ... then dirs, which should now be empty
1321  RemoveFiles(dirs);
1322 
1323  // Fail if nothing deleted
1324  if (files.isEmpty() && dirs.isEmpty())
1325  RESULT_ERR("Delete failed", QString("Delete of %1 failed").arg(ids))
1326 
1327  // Update Db
1328  DBFS::RemoveFromDB(files + dirs);
1329 
1330  // Clean up thumbnails
1331  QStringList mesg(m_thumbGen->DeleteThumbs(files));
1332 
1333  // Notify clients of deleted ids
1334  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1335 
1336  return QStringList("OK");
1337 }
1338 
1339 
1352 template <class DBFS>
1353 QStringList ImageHandler<DBFS>::HandleDbCreate(QStringList defs) const
1354 {
1355  if (defs.isEmpty())
1356  RESULT_ERR("Copy Failed", "Empty defs")
1357 
1358  // First item is the field seperator
1359  const QString separator = defs.takeFirst();
1360 
1361  // Convert cover ids to their new equivalent. Map<source id, new id>
1362  // Dirs follow their children so new cover ids will be defined before they
1363  // are used
1364  QHash<QString, int> idMap;
1365 
1366  // Create skeleton Db images using copied settings.
1367  // Scanner will update other attributes
1368  ImageItem im;
1369  for (const auto& def : qAsConst(defs))
1370  {
1371  QStringList aDef = def.split(separator);
1372 
1373  // Expects id, type, path, hidden, orientation, cover
1374  if (aDef.size() != 6)
1375  {
1376  // Coding error
1377  LOG(VB_GENERAL, LOG_ERR,
1378  LOC + QString("Bad definition: (%1)").arg(def));
1379  continue;
1380  }
1381 
1382  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Creating %1").arg(aDef.join(",")));
1383 
1384  im.m_type = aDef[1].toInt();
1385  im.m_filePath = aDef[2];
1386  im.m_isHidden = (aDef[3].toInt() != 0);
1387  im.m_orientation = aDef[4].toInt();
1388  im.m_userThumbnail = idMap.value(aDef[5]);
1389 
1390  // Don't insert duplicate filepaths
1391  int newId = DBFS::InsertDbImage(im, true);
1392 
1393  // Record old->new id map in case it's being used as a cover
1394  idMap.insert(aDef[0], newId);
1395  }
1396  HandleScanRequest("START");
1397 
1398  RESULT_OK("Created Db images")
1399 }
1400 
1401 
1411 template <class DBFS>
1412 QStringList ImageHandler<DBFS>::HandleDbMove(const QString &ids,
1413  const QString &srcPath,
1414  QString destPath) const
1415 {
1416  // Sanity check new path
1417  if (destPath.contains(".."))
1418  RESULT_ERR("Invalid path", QString("Invalid path %1").arg(destPath))
1419 
1420  // Get subtrees of renamed files
1421  ImageList images;
1422  ImageList dirs;
1423  ImageList files;
1424  bool ok = DBFS::GetDescendants(ids, files, dirs);
1425  images << dirs << files;
1426 
1427  if (!ok || images.isEmpty())
1428  RESULT_ERR("Image not found", QString("Images %1 not in Db").arg(ids))
1429 
1430  if (!destPath.isEmpty() && !destPath.endsWith(QChar('/')))
1431  destPath.append("/");
1432 
1433  // Update path of images only. Scanner will repair parentId
1434  for (const auto& im : qAsConst(images))
1435  {
1436  QString old = im->m_filePath;
1437 
1438  if (srcPath.isEmpty())
1439  {
1440  // Image in SG root
1441  im->m_filePath.prepend(destPath);
1442  }
1443  else if (im->m_filePath.startsWith(srcPath))
1444  {
1445  // All other images
1446  im->m_filePath.replace(srcPath, destPath);
1447  }
1448  else
1449  {
1450  // Coding error
1451  LOG(VB_GENERAL, LOG_ERR,
1452  LOC + QString("Bad image: (%1 -> %2)").arg(srcPath, destPath));
1453  continue;
1454  }
1455 
1456  LOG(VB_FILE, LOG_DEBUG,
1457  LOC + QString("Db Renaming %1 -> %2").arg(old, im->m_filePath));
1458 
1459  DBFS::UpdateDbImage(*im);
1460 
1461  // Rename thumbnail
1462  if (im->IsFile())
1463  m_thumbGen->MoveThumbnail(im);
1464  }
1465  HandleScanRequest("START");
1466 
1467  RESULT_OK(QString("Moved %1 from %2 -> %3").arg(ids).arg(srcPath, destPath))
1468 }
1469 
1470 
1478 template <class DBFS>
1479 QStringList ImageHandler<DBFS>::HandleHide(bool hide, const QString &ids) const
1480 {
1481  if (!DBFS::SetHidden(hide, ids))
1482  RESULT_ERR("Hide failed", QString("Db hide failed for %1").arg(ids))
1483 
1484  // Send changed ids only (none deleted)
1485  QStringList mesg = QStringList("") << ids;
1486  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1487 
1488  RESULT_OK(QString("Images %1 now %2hidden").arg(ids, hide ? "" : "un"))
1489 }
1490 
1491 
1500 template <class DBFS>
1501 QStringList ImageHandler<DBFS>::HandleTransform(int transform,
1502  const QString &ids) const
1503 {
1504  if (transform < kResetToExif || transform > kFlipVertical)
1505  RESULT_ERR("Transform failed", QString("Bad transform %1").arg(transform))
1506 
1507  ImageList files;
1508  ImageList dirs;
1509  if (DBFS::GetImages(ids, files, dirs) < 1 || files.isEmpty())
1510  RESULT_ERR("Image not found", QString("Images %1 not in Db").arg(ids))
1511 
1512  // Update db
1513  for (const auto& im : qAsConst(files))
1514  {
1515  int old = im->m_orientation;
1516  im->m_orientation = Orientation(im->m_orientation).Transform(transform);
1517 
1518  // Update Db
1519  if (DBFS::SetOrientation(im->m_id, im->m_orientation))
1520  {
1521  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Transformed %1 from %2 to %3")
1522  .arg(im->m_filePath).arg(old).arg(im->m_orientation));
1523  }
1524  }
1525 
1526  // Images are changed, not deleted
1527  QStringList mesg("");
1528 
1529  // Clean up thumbnails
1530  mesg << m_thumbGen->DeleteThumbs(files);
1531 
1532  // Notify clients of changed images
1533  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1534 
1535  return QStringList("OK");
1536 }
1537 
1538 
1547 template <class DBFS>
1548 QStringList ImageHandler<DBFS>::HandleDirs(const QString &destId,
1549  bool rescan,
1550  const QStringList &relPaths) const
1551 {
1552  // Find image in DB
1553  ImageList files;
1554  ImageList dirs;
1555  if (DBFS::GetImages(destId, files, dirs) != 1 || dirs.isEmpty())
1556  RESULT_ERR("Destination not found",
1557  QString("Image %1 not in Db").arg(destId))
1558 
1559  // Find dir. SG device (Photographs) uses most-free filesystem
1560  QString destPath = DBFS::GetAbsFilePath(dirs[0]);
1561  if (destPath.isEmpty())
1562  RESULT_ERR("Destination not found",
1563  QString("Dest dir %1 not found").arg(dirs[0]->m_filePath))
1564 
1565  QDir destDir(destPath);
1566  bool succeeded = false;
1567  for (const auto& relPath : qAsConst(relPaths))
1568  {
1569  // Validate dir name
1570  if (relPath.isEmpty() || relPath.contains("..") || relPath.startsWith(QChar('/')))
1571  continue;
1572 
1573  QString newPath = DBFS::ConstructPath(destDir.absolutePath(), relPath);
1574  if (!destDir.mkpath(relPath))
1575  {
1576  LOG(VB_GENERAL, LOG_ERR,
1577  LOC + QString("Failed to create dir %1").arg(newPath));
1578  continue;
1579  }
1580  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Dir %1 created").arg(newPath));
1581  succeeded = true;
1582  }
1583 
1584  if (!succeeded)
1585  // Failures should only occur due to user input
1586  RESULT_ERR("Invalid Name", QString("Invalid name %1")
1587  .arg(relPaths.join(",")))
1588 
1589  if (rescan)
1590  // Rescan to detect new dir
1591  HandleScanRequest("START");
1592 
1593  return QStringList("OK");
1594 }
1595 
1596 
1603 template <class DBFS>
1604 QStringList ImageHandler<DBFS>::HandleCover(int dir, int cover) const
1605 {
1606  if (!DBFS::SetCover(dir, cover))
1607  RESULT_ERR("Set Cover failed",
1608  QString("Failed to set %1 to cover %2").arg(dir).arg(cover))
1609 
1610  // Image has changed, nothing deleted
1611  QStringList mesg = QStringList("") << QString::number(dir);
1612  DBFS::Notify("IMAGE_DB_CHANGED", mesg);
1613 
1614  RESULT_OK(QString("Cover of %1 is now %2").arg(dir).arg(cover));
1615 }
1616 
1617 
1626 template <class DBFS>
1627 QStringList ImageHandler<DBFS>::HandleIgnore(const QString &exclusions) const
1628 {
1629  // Save new setting. FE will have already saved it but not cleared the cache
1630  gCoreContext->SaveSettingOnHost("GalleryIgnoreFilter", exclusions, nullptr);
1631 
1632  // Rescan
1633  HandleScanRequest("START");
1634 
1635  RESULT_OK(QString("Using exclusions '%1'").arg(exclusions))
1636 }
1637 
1638 
1646 template <class DBFS>
1647 QStringList ImageHandler<DBFS>::HandleScanRequest(const QString &command,
1648  int devId) const
1649 {
1650  if (!m_scanner)
1651  RESULT_ERR("Missing Scanner", "Missing Scanner");
1652 
1653  if (command == "START")
1654  {
1655  // Must be dormant to start a scan
1656  if (m_scanner->IsScanning())
1657  RESULT_ERR("", "Scanner is busy");
1658 
1659  m_scanner->ChangeState(true);
1660  RESULT_OK("Scan requested");
1661  }
1662  else if (command == "STOP")
1663  {
1664  // Must be scanning to interrupt
1665  if (!m_scanner->IsScanning())
1666  RESULT_ERR("Scanner not running", "Scanner not running");
1667 
1668  m_scanner->ChangeState(false);
1669  RESULT_OK("Terminate scan requested");
1670  }
1671  else if (command == "QUERY")
1672  {
1673  return QStringList("OK") << m_scanner->GetProgress();
1674  }
1675  else if (command.startsWith(QString("DEVICE")))
1676  {
1677  m_scanner->EnqueueClear(devId, command);
1678  RESULT_OK(QString("Clearing device %1 %2").arg(command).arg(devId))
1679  }
1680  RESULT_ERR("Unknown command", QString("Unknown command %1").arg(command));
1681 }
1682 
1683 
1691 template <class DBFS>
1693 (const QStringList &message) const
1694 {
1695  if (message.size() != 2)
1696  RESULT_ERR("Unknown Command",
1697  QString("Bad request: %1").arg(message.join("|")))
1698 
1699  int priority = message.at(0).toInt()
1701 
1702  // get specific image details from db
1703  ImageList files;
1704  ImageList dirs;
1705  DBFS::GetImages(message.at(1), files, dirs);
1706 
1707  for (const auto& im : qAsConst(files))
1708  // notify clients when done; highest priority
1709  m_thumbGen->CreateThumbnail(im, priority, true);
1710 
1711  return QStringList("OK");
1712 }
1713 
1714 
1724 template <class DBFS>
1726 {
1727  QMutableVectorIterator<ImagePtr> it(images);
1728  it.toBack();
1729  while (it.hasPrevious())
1730  {
1731  ImagePtrK im = it.previous();
1732 
1733  // Remove file or directory
1734  QString absFilename = DBFS::GetAbsFilePath(im);
1735 
1736  bool success = !absFilename.isEmpty()
1737  && (im->IsFile() ? QFile::remove(absFilename)
1738  : QDir::root().rmdir(absFilename));
1739  if (success)
1740  LOG(VB_FILE, LOG_DEBUG, LOC + QString("Deleted %1").arg(absFilename));
1741  else
1742  {
1743  LOG(VB_GENERAL, LOG_ERR, LOC +
1744  QString("Can't delete %1").arg(absFilename));
1745  // Remove from list
1746  it.remove();
1747  }
1748  }
1749 }
1750 
1751 
1758 {
1759  switch (type)
1760  {
1761  case kPicOnly: return QString("AND type != %1").arg(kVideoFile);
1762  case kVideoOnly: return QString("AND type != %1").arg(kImageFile);
1763  case kPicAndVideo: return "";
1764  }
1765  return "";
1766 }
1767 
1768 
1775 {
1776  m_refineClause = QString("%2 %3 "
1777  "ORDER BY "
1778  "CASE WHEN type <= %1 THEN %4, "
1779  "CASE WHEN type > %1 THEN %5 ")
1780  .arg(kDirectory)
1781  .arg(m_showHidden ? "" : "AND hidden = 0",
1785 }
1786 
1787 
1794 {
1795  // prepare the sorting statement
1796  switch (order)
1797  {
1798  default:
1799  case kSortByNameAsc: return "name END ASC";
1800  case kSortByNameDesc: return "name END DESC";
1801  case kSortByModTimeAsc: return "modtime END ASC";
1802  case kSortByModTimeDesc: return "modtime END DESC";
1803  case kSortByExtAsc: return "extension END ASC, name ASC";
1804  case kSortByExtDesc: return "extension END DESC, name DESC";
1805  case kSortBySizeAsc: return "size END ASC, name ASC";
1806  case kSortBySizeDesc: return "size END DESC, name DESC";
1807  case kSortByDateAsc: return "IF(date=0, modtime, date) END ASC";
1808  case kSortByDateDesc: return "IF(date=0, modtime, date) END DESC";
1809  }
1810 }
1811 
1812 
1822  ImageList &files, ImageList &dirs) const
1823 {
1824  // Only Root node will invoke both Db queries but result set will be small
1825  // For Root the SG is always ordered before local devices
1826  // Root node has no Db entry so the 2 queries will not overwrite the parent.
1827  int count = 0;
1828  if (!ImageItem::IsLocalId(id))
1829  count = m_remote->GetDirectory(id, parent, files, dirs, m_refineClause);
1831  count += ImageHandler::GetDirectory(id, parent, files, dirs, m_refineClause);
1832 
1833  if (id == GALLERY_DB_ID)
1834  {
1835  // Add a Root node
1836  parent = ImagePtr(new ImageItem(GALLERY_DB_ID));
1837  parent->m_parentId = GALLERY_DB_ID;
1838  parent->m_type = kDevice;
1839 
1840  ++count;
1841  }
1842  return count;
1843 }
1844 
1845 
1854  ImageList &files, ImageList &dirs) const
1855 {
1856  // Ids are either all local or all remote. GALLERY_DB_ID not valid
1857  StringPair lists = ImageItem::PartitionIds(ids);
1858 
1859  if (!lists.second.isEmpty())
1860  return m_remote->GetImages(lists.second, files, dirs, m_refineClause);
1861  if (m_dbExists && !lists.first.isEmpty())
1862  return ImageHandler::GetImages(lists.first, files, dirs, m_refineClause);
1863  return 0;
1864 }
1865 
1866 
1874 int ImageDbReader::GetChildren(int id, ImageList &files, ImageList &dirs) const
1875 {
1876  int count = 0;
1877  if (!ImageItem::IsLocalId(id))
1878  count = m_remote->GetChildren(QString::number(id), files, dirs,
1879  m_refineClause);
1881  count += ImageHandler::GetChildren(QString::number(id), files, dirs,
1882  m_refineClause);
1883  return count;
1884 }
1885 
1886 
1894  ImageList &files, ImageList &dirs) const
1895 {
1896  // Ids are either all local or all remote
1897  StringPair lists = ImageItem::PartitionIds(ids);
1898 
1899  if (!lists.second.isEmpty())
1900  m_remote->GetDescendants(lists.second, files, dirs);
1901  if (m_dbExists && !lists.first.isEmpty())
1902  ImageHandler::GetDescendants(lists.first, files, dirs);
1903 }
1904 
1905 
1912 void ImageDbReader::GetImageTree(int id, ImageList &files) const
1913 {
1914  if (!ImageItem::IsLocalId(id))
1915  m_remote->GetImageTree(id, files, m_refineClause);
1917  ImageHandler::GetImageTree(id, files, m_refineClause);
1918 }
1919 
1920 
1929 void ImageDbReader::GetDescendantCount(int id, int &dirs, int &pics,
1930  int &videos, int &sizeKb) const
1931 {
1932  if (id == GALLERY_DB_ID)
1933  {
1934  // Sum both unfiltered tables
1935  m_remote->GetDescendantCount(id, true, dirs, pics, videos, sizeKb);
1936  if (m_dbExists)
1937  ImageHandler::GetDescendantCount(id, true, dirs, pics, videos, sizeKb);
1938  }
1939  else if (!ImageItem::IsLocalId(id))
1940  {
1941  // Don't filter on SG path (it's blank)
1943  dirs, pics, videos, sizeKb);
1944  }
1945  else if (m_dbExists)
1946  {
1947  // Always filter on device/dir
1948  ImageHandler::GetDescendantCount(id, false, dirs, pics, videos, sizeKb);
1949  }
1950 }
1951 
1952 
1957 
1958 
1964 {
1965  if (!s_instance)
1966  s_instance = new ImageManagerBe();
1967  return s_instance;
1968 }
1969 
1970 
1976 {
1977  if (!s_instance)
1978  {
1979  // Use saved settings
1981  (gCoreContext->GetNumSetting("GalleryImageOrder"),
1982  gCoreContext->GetNumSetting("GalleryDirOrder"),
1983  gCoreContext->GetBoolSetting("GalleryShowHidden"),
1984  gCoreContext->GetNumSetting("GalleryShowType"),
1985  gCoreContext->GetSetting("GalleryDateFormat"));
1986  }
1987  return *s_instance;
1988 }
1989 
1990 
1999 void ImageManagerFe::CreateThumbnails(const ImageIdList &ids, bool forFolder)
2000 {
2001  // Split images into <locals, remotes>
2002  StringPair lists = ImageItem::PartitionIds(ids);
2003 
2004  if (!lists.second.isEmpty())
2005  {
2006  LOG(VB_FILE, LOG_DEBUG, LOC +
2007  QString("Sending CREATE_THUMBNAILS %1 (forFolder %2)")
2008  .arg(lists.second).arg(forFolder));
2009 
2010  QStringList message;
2011  message << QString::number(static_cast<int>(forFolder)) << lists.second;
2012  gCoreContext->SendEvent(MythEvent("CREATE_THUMBNAILS", message));
2013  }
2014 
2015  if (!lists.first.isEmpty())
2016  {
2017  LOG(VB_FILE, LOG_DEBUG, LOC +
2018  QString("Creating local thumbnails %1 (forFolder %2)")
2019  .arg(lists.first).arg(forFolder));
2020 
2021  QStringList message;
2022  message << QString::number(static_cast<int>(forFolder)) << lists.first;
2023  HandleCreateThumbnails(message);
2024  }
2025 }
2026 
2027 
2034 QString ImageManagerFe::ScanImagesAction(bool start, bool local)
2035 {
2036  QStringList command;
2037  command << (start ? "START" : "STOP");
2038 
2039  if (!local)
2040  {
2041  command.push_front("IMAGE_SCAN");
2042  bool ok = gCoreContext->SendReceiveStringList(command, true);
2043  return ok ? "" : command[1];
2044  }
2045 
2046  // Create database on first scan
2047  if (!CreateTable())
2048  return "Couldn't create database";
2049 
2050  QStringList err = HandleScanRequest(command[0]);
2051  return err[0] == "OK" ? "" : err[1];
2052 }
2053 
2054 
2061 {
2062  QStringList strList;
2063  strList << "IMAGE_SCAN" << "QUERY";
2064 
2065  if (!gCoreContext->SendReceiveStringList(strList))
2066  {
2067  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Scan query failed : %1")
2068  .arg(strList.join(",")));
2069  }
2070  return strList;
2071 }
2072 
2073 
2080 QString ImageManagerFe::HideFiles(bool hidden, const ImageIdList &ids)
2081 {
2082  // Split images into <locals, remotes>
2083  StringPair lists = ImageItem::PartitionIds(ids);
2084  QString result = "";
2085 
2086  if (!lists.second.isEmpty())
2087  {
2088  QStringList message;
2089  message << "IMAGE_HIDE" << QString::number(static_cast<int>(hidden)) << lists.second;
2090 
2091  if (!gCoreContext->SendReceiveStringList(message, true))
2092  result = message[1];
2093  }
2094 
2095  if (!lists.first.isEmpty())
2096  {
2097  QStringList err = HandleHide(hidden, lists.first);
2098  if (err[0] != "OK")
2099  result = err[1];
2100  }
2101  return result;
2102 }
2103 
2104 
2112  const ImageIdList &ids)
2113 {
2114  // Split images into <locals, remotes>
2115  StringPair lists = ImageItem::PartitionIds(ids);
2116  QString result = "";
2117 
2118  if (!lists.second.isEmpty())
2119  {
2120  QStringList message;
2121  message << "IMAGE_TRANSFORM" << QString::number(transform) << lists.second;
2122 
2123  if (!gCoreContext->SendReceiveStringList(message, true))
2124  result = message[1];
2125  }
2126 
2127  if (!lists.first.isEmpty())
2128  {
2129  QStringList err = HandleTransform(transform, lists.first);
2130  if (err[0] != "OK")
2131  result = err[1];
2132  }
2133  return result;
2134 }
2135 
2136 
2143 QString ImageManagerFe::SetCover(int parent, int cover)
2144 {
2145  if (!ImageItem::IsLocalId(parent))
2146  {
2147  QStringList message;
2148  message << "IMAGE_COVER" << QString::number(parent) << QString::number(cover);
2149 
2150  bool ok = gCoreContext->SendReceiveStringList(message, true);
2151  return ok ? "" : message[1];
2152  }
2153 
2154  QStringList err = HandleCover(parent, cover);
2155  return err[0] == "OK" ? "" : err[1];
2156 }
2157 
2158 
2164 {
2165  if (ImageItem::IsLocalId(id))
2166  HandleGetMetadata(QString::number(id));
2167  else
2168  gCoreContext->SendEvent(MythEvent("IMAGE_GET_METADATA", QString::number(id)));
2169 }
2170 
2171 
2174 {
2175  QStringList message("IMAGE_SCAN");
2176  message << "DEVICE CLEAR ALL";
2177  gCoreContext->SendReceiveStringList(message, true);
2178 }
2179 
2180 
2187 QString ImageManagerFe::IgnoreDirs(const QString &excludes)
2188 {
2189  QStringList message("IMAGE_IGNORE");
2190  message << excludes;
2191  bool ok = gCoreContext->SendReceiveStringList(message, true);
2192  return ok ? "" : message[1];
2193 }
2194 
2195 
2203 QString ImageManagerFe::MakeDir(int parent, const QStringList &names, bool rescan)
2204 {
2205  QString destId = QString::number(parent);
2206 
2207  if (!ImageItem::IsLocalId(parent))
2208  {
2209  QStringList message("IMAGE_CREATE_DIRS");
2210  message << destId << QString::number(static_cast<int>(rescan)) << names;
2211  bool ok = gCoreContext->SendReceiveStringList(message, true);
2212  return ok ? "" : message[1];
2213  }
2214  QStringList err = HandleDirs(destId, rescan, names);
2215  return (err[0] == "OK") ? "" : err[1];
2216 }
2217 
2218 
2225 QString ImageManagerFe::RenameFile(const ImagePtrK& im, const QString &name)
2226 {
2227  if (!im->IsLocal())
2228  {
2229  QStringList message("IMAGE_RENAME");
2230  message << QString::number(im->m_id) << name;
2231  bool ok = gCoreContext->SendReceiveStringList(message, true);
2232  return ok ? "" : message[1];
2233  }
2234  QStringList err = HandleRename(QString::number(im->m_id), name);
2235  return (err[0] == "OK") ? "" : err[1];
2236 }
2237 
2238 
2245 QString ImageManagerFe::CreateImages(int destId, const ImageListK &images)
2246 {
2247  if (images.isEmpty())
2248  return "";
2249 
2250  // Define field seperator & include it in message
2251  const QString seperator("...");
2252  QStringList imageDefs(seperator);
2253  ImageIdList ids;
2254  for (const auto& im : qAsConst(images))
2255  {
2256  ids << im->m_id;
2257 
2258  // Copies preserve hide state, orientation & cover
2259  QStringList aDef;
2260  aDef << QString::number(im->m_id)
2261  << QString::number(im->m_type)
2262  << im->m_filePath
2263  << QString::number(static_cast<int>(im->m_isHidden))
2264  << QString::number(im->m_orientation)
2265  << QString::number(im->m_userThumbnail);
2266 
2267  imageDefs << aDef.join(seperator);
2268  }
2269 
2270  // Images are either all local or all remote
2271  if (ImageItem::IsLocalId(destId))
2272  {
2273  QStringList err = HandleDbCreate(imageDefs);
2274  return (err[0] == "OK") ? "" : err[1];
2275  }
2276  imageDefs.prepend("IMAGE_COPY");
2277  bool ok = gCoreContext->SendReceiveStringList(imageDefs, true);
2278  return ok ? "" : imageDefs[1];
2279 }
2280 
2281 
2289 QString ImageManagerFe::MoveDbImages(const ImagePtrK& destDir, ImageListK &images,
2290  const QString &srcPath)
2291 {
2292  QStringList idents;
2293  for (const auto& im : qAsConst(images))
2294  idents << QString::number(im->m_id);
2295 
2296  // Images are either all local or all remote
2297  if (destDir->IsLocal())
2298  {
2299  QStringList err = HandleDbMove(idents.join(","), srcPath,
2300  destDir->m_filePath);
2301  return (err[0] == "OK") ? "" : err[1];
2302  }
2303 
2304  QStringList message("IMAGE_MOVE");
2305  message << idents.join(",") << srcPath << destDir->m_filePath;
2306  bool ok = gCoreContext->SendReceiveStringList(message, true);
2307  return ok ? "" : message[1];
2308 }
2309 
2310 
2317 {
2318  StringPair lists = ImageItem::PartitionIds(ids);
2319 
2320  QString result = "";
2321  if (!lists.second.isEmpty())
2322  {
2323  QStringList message("IMAGE_DELETE");
2324  message << lists.second;
2325 
2326  bool ok = gCoreContext->SendReceiveStringList(message, true);
2327  if (!ok)
2328  result = message[1];
2329  }
2330  if (!lists.first.isEmpty())
2331  {
2332  QStringList err = HandleDelete(lists.first);
2333  if (err[0] != "OK")
2334  result = err[1];
2335  }
2336  return result;
2337 }
2338 
2339 
2347 {
2348  if (im->m_id == GALLERY_DB_ID)
2349  return "";
2350 
2351  qint64 secs = 0;
2353 
2354  if (im->m_date > 0)
2355  {
2356  secs = im->m_date;
2357  format |= MythDate::kTime;
2358  }
2359  else
2360  secs = im->m_modTime;
2361 
2362  return MythDate::toString(QDateTime::fromSecsSinceEpoch(secs), format);
2363 }
2364 
2365 
2372 QString ImageManagerFe::ShortDateOf(const ImagePtrK& im) const
2373 {
2374  if (im->m_id == GALLERY_DB_ID)
2375  return "";
2376 
2377  qint64 secs(im->m_date > 0 ? im->m_date : im->m_modTime);
2378  return QDateTime::fromSecsSinceEpoch(secs).date().toString(m_dateFormat);
2379 }
2380 
2381 
2388 {
2389  if (im.m_id == GALLERY_DB_ID)
2390  return tr("Gallery");
2391  if (im.m_id == PHOTO_DB_ID)
2392  return tr("Photographs");
2393  return im.IsLocal() ? DeviceName(im.m_device)
2394  : m_remote->DeviceName(im.m_device);
2395 }
2396 
2397 
2405 QString ImageManagerFe::CrumbName(ImageItemK &im, bool getPath) const
2406 {
2407  if (im.IsDevice())
2408  return DeviceCaption(im);
2409 
2410  if (!getPath)
2411  return im.m_baseName;
2412 
2413  QString dev;
2414  QString path(im.m_filePath);
2415 
2416  if (im.IsLocal())
2417  {
2418  // Replace local mount path with device name
2419  path.remove(0, DeviceMount(im.m_device).size());
2420  dev = DeviceName(im.m_device);
2421  }
2422  return dev + path.replace("/", " > ");
2423 }
2424 
2425 
2426 void ImageManagerFe::CloseDevices(int devId, bool eject)
2427 {
2428  QString reason = (devId == DEVICE_INVALID)
2429  ? "DEVICE CLOSE ALL"
2430  : eject ? "DEVICE EJECT" : "DEVICE REMOVE";
2431  HandleScanRequest(reason, devId);
2432 }
2433 
2434 
2440 {
2442  if (!monitor)
2443  return false;
2444 
2445  // Detect all local media
2446  QList<MythMediaDevice*> devices
2448 
2449  for (auto *dev : qAsConst(devices))
2450  {
2451  if (monitor->ValidateAndLock(dev) && dev->isUsable())
2452  OpenDevice(dev->getDeviceModel(), dev->getMountPath(), dev);
2453  else
2454  monitor->Unlock(dev);
2455  }
2456 
2457  if (DeviceCount() > 0)
2458  {
2459  // Close devices that are no longer present
2460  QList absentees = GetAbsentees();
2461  for (int devId : qAsConst(absentees))
2462  CloseDevices(devId);
2463 
2464  // Start local scan
2465  QString err = ScanImagesAction(true, true);
2466  if (!err.isEmpty())
2467  LOG(VB_GENERAL, LOG_ERR, LOC + err);
2468  }
2469  return DeviceCount() > 0;
2470 }
2471 
2472 
2478 {
2480 
2481  if (!event || !monitor)
2482  return;
2483 
2484  MythMediaDevice *dev = event->getDevice();
2485  if (!dev)
2486  return;
2487 
2488  MythMediaType type = dev->getMediaType();
2489  MythMediaStatus status = dev->getStatus();
2490 
2491  LOG(VB_FILE, LOG_DEBUG, LOC +
2492  QString("Media event for %1 (%2) at %3, type %4, status %5 (was %6)")
2493  .arg(dev->getDeviceModel(), dev->getVolumeID(), dev->getMountPath())
2494  .arg(type).arg(status).arg(event->getOldStatus()));
2495 
2497  {
2498  LOG(VB_FILE, LOG_DEBUG, LOC +
2499  QString("Ignoring event - wrong type %1").arg(type));
2500  return;
2501  }
2502 
2503  if (status == MEDIASTAT_USEABLE || status == MEDIASTAT_MOUNTED)
2504  {
2505  // New device. Lock it & scan
2506  if (monitor->ValidateAndLock(dev))
2507  {
2508  OpenDevice(dev->getDeviceModel(), dev->getMountPath(), dev);
2509  ScanImagesAction(true, true);
2510  }
2511  else
2512  monitor->Unlock(dev);
2513  return;
2514  }
2515 
2516  // Device has disappeared
2517  int devId = LocateMount(dev->getMountPath());
2518  if (devId != DEVICE_INVALID)
2519  CloseDevices(devId);
2520 }
2521 
2522 
2524 {
2525  auto *tmp = new QTemporaryDir(QDir::tempPath() % "/" IMPORTDIR "-XXXXXX");
2526  if (!tmp->isValid())
2527  {
2528  delete tmp;
2529  return "";
2530  }
2531 
2532  QString time(QDateTime::currentDateTime().toString("mm:ss"));
2533  OpenDevice("Import " + time, tmp->path(), nullptr, tmp);
2534  return tmp->path();
2535 }
2536 
2537 
2538 // Must define the valid template implementations to generate code for the
2539 // instantiations (as they are defined in the cpp rather than header).
2540 // Otherwise the linker will fail with undefined references...
2541 template class ImageDb<ImageAdapterSg>;
2542 template class ImageDb<ImageAdapterLocal>;
2543 template class ImageHandler<ImageDbSg>;
2544 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:46
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:783
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:164
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
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:1234
ImageDb::SetHidden
bool SetHidden(bool hide, const QString &ids) const
Sets hidden status of an image/dir in database.
Definition: imagemanager.cpp:927
PHOTO_DB_ID
#define PHOTO_DB_ID
Definition: imagetypes.h:28
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:203
ImageDbReader::GetImages
int GetImages(const ImageIdList &ids, ImageList &files, ImageList &dirs) const
Returns images (local or remote but not a combination)
Definition: imagemanager.cpp:1853
DeviceManager::GetDeviceDirs
StringMap GetDeviceDirs() const
Get all known devices.
Definition: imagemanager.cpp:246
root
QDomElement root
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:656
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:1999
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:1912
ImageItem::m_type
int m_type
Type of node: dir, video etc.
Definition: imagetypes.h:96
kVideoFile
@ kVideoFile
A video.
Definition: imagetypes.h:39
MediaMonitor::GetMedias
QList< MythMediaDevice * > GetMedias(unsigned mediatypes)
Ask for available media. Must be locked with ValidateAndLock().
Definition: mythmediamonitor.cpp:614
ReadMetaThread
Task to read all metadata from file.
Definition: imagemanager.cpp:1146
Device::isImport
bool isImport() const
Definition: imagemanager.cpp:105
ImageItem::m_id
int m_id
Uniquely identifies an image (file/dir).
Definition: imagetypes.h:88
ImageDb::UpdateDbImage
bool UpdateDbImage(ImageItemK &im) const
Updates or creates database image or dir.
Definition: imagemanager.cpp:854
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:1380
kSortByExtDesc
@ kSortByExtDesc
Extension Z-A.
Definition: imagetypes.h:50
ImageItem::m_comment
QString m_comment
User comment, from Exif metadata.
Definition: imagetypes.h:101
ImageDbReader::GetDirectory
int GetDirectory(int id, ImagePtr &parent, ImageList &files, ImageList &dirs) const
Return images (local and/or remote) for a dir and its direct children.
Definition: imagemanager.cpp:1821
ImageManagerFe::CreateImages
QString CreateImages(int destId, const ImageListK &images)
Copies database images (but not the files themselves).
Definition: imagemanager.cpp:2245
ImageManagerFe::ScanImagesAction
QString ScanImagesAction(bool start, bool local=false)
Handle scanner start/stop commands.
Definition: imagemanager.cpp:2034
LOC
#define LOC
Definition: imagemanager.cpp:13
ImageHandler::HandleGetMetadata
QStringList HandleGetMetadata(const QString &id) const
Read meta data for an image.
Definition: imagemanager.cpp:1203
MediaMonitor::GetMediaMonitor
static MediaMonitor * GetMediaMonitor(void)
Definition: mythmediamonitor.cpp:83
ImageItem::IsLocal
bool IsLocal() const
Definition: imagetypes.h:118
ImageDbLocal::DropTable
void DropTable()
Remove local image table.
Definition: imagemanager.cpp:1100
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:2203
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:104
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:37
DB_COLUMNS
#define DB_COLUMNS
Definition: imagemanager.cpp:524
MSqlQuery::lastInsertId
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:888
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:2477
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:2187
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:198
arg
arg(title).arg(filename).arg(doDelete))
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:486
DEVICE_INVALID
#define DEVICE_INVALID
Definition: imagemanager.h:71
ImageManagerFe::HideFiles
QString HideFiles(bool hidden, const ImageIdList &ids)
Hide/unhide images.
Definition: imagemanager.cpp:2080
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:580
ImageDb::InsertDbImage
int InsertDbImage(ImageItemK &im, bool checkForDuplicate=false) const
Adds new image to database, optionally checking for existing filepath.
Definition: imagemanager.cpp:796
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:537
ImageHandler::HandleCover
QStringList HandleCover(int dir, int cover) const
Updates/resets cover thumbnail for an image dir.
Definition: imagemanager.cpp:1604
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:1757
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:94
ImageManagerFe::CloseDevices
void CloseDevices(int devId=DEVICE_INVALID, bool eject=false)
Definition: imagemanager.cpp:2426
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:139
true
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
ImageDbSg::ImageDbSg
ImageDbSg()
SG database constructor.
Definition: imagemanager.cpp:1079
ImageManagerFe::ChangeOrientation
QString ChangeOrientation(ImageFileTransform transform, const ImageIdList &ids)
Apply an orientation transform to images.
Definition: imagemanager.cpp:2111
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:1501
dbaccess.h
ImageManagerFe::getInstance
static ImageManagerFe & getInstance()
Get Frontend Gallery.
Definition: imagemanager.cpp:1975
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:2387
kSortByDateDesc
@ kSortByDateDesc
Exif date Latest -> Earliest.
Definition: imagetypes.h:54
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:1353
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:709
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
ImageItem::m_modTime
qint64 m_modTime
Filesystem modified datestamp.
Definition: imagetypes.h:97
ImageHash
QHash< QString, ImagePtr > ImageHash
Definition: imagetypes.h:160
mythdate.h
ImageHandler::HandleDbMove
QStringList HandleDbMove(const QString &ids, const QString &srcPath, QString destPath) const
Updates images that have been renamed.
Definition: imagemanager.cpp:1412
GetConfDir
QString GetConfDir(void)
Definition: mythdirs.cpp:224
kSortByNameAsc
@ kSortByNameAsc
Name A-Z.
Definition: imagetypes.h:45
kPicOnly
@ kPicOnly
Hide videos.
Definition: imagemanager.h:79
ImageManagerFe::ClearStorageGroup
static void ClearStorageGroup()
Clear database & thumbnails of Storage Group images.
Definition: imagemanager.cpp:2173
MythCoreContext::SendEvent
void SendEvent(const MythEvent &event)
Definition: mythcorecontext.cpp:1540
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:62
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:178
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:977
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:1893
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:1793
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:165
clear
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:844
MediaMonitor::Unlock
void Unlock(MythMediaDevice *pMedia)
decrements the MythMediaDevices reference count
Definition: mythmediamonitor.cpp:520
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:2346
RESULT_OK
#define RESULT_OK(MESG)
Definition: imagemanager.cpp:25
kSortByExtAsc
@ kSortByExtAsc
Extension A-Z.
Definition: imagetypes.h:49
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:2143
uint
unsigned int uint
Definition: compat.h:141
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:121
ImageItem::m_orientation
int m_orientation
Image orientation.
Definition: imagetypes.h:100
ImageItem::m_baseName
QString m_baseName
File/Dir name with extension (no path)
Definition: imagetypes.h:91
MediaMonitor
Definition: mythmediamonitor.h:43
ImageList
QVector< ImagePtr > ImageList
Definition: imagetypes.h:159
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:933
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:2523
ImageItem::IsLocalParent
static bool IsLocalParent(int id)
Parents of locals are locals or root.
Definition: imagetypes.h:123
ImageHandler::RemoveFiles
void RemoveFiles(ImageList &images) const
Deletes images and dirs from the filesystem.
Definition: imagemanager.cpp:1725
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:1929
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:927
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:48
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:1647
ImageHandler::HandleDirs
QStringList HandleDirs(const QString &destId, bool rescan, const QStringList &relPaths) const
Creates new image directories.
Definition: imagemanager.cpp:1548
kImageFile
@ kImageFile
A picture.
Definition: imagetypes.h:38
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:2289
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:158
MythDate::kAddYear
@ kAddYear
Add year to string if not included.
Definition: mythdate.h:22
ImageManagerFe
The image manager for use by Frontends.
Definition: imagemanager.h:456
StorageGroup::FindNextDirMostFree
QString FindNextDirMostFree(void)
Definition: storagegroup.cpp:671
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1174
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:67
MEDIATYPE_MGALLERY
@ MEDIATYPE_MGALLERY
Definition: mythmedia.h:33
ImageDbLocal::ImageDbLocal
ImageDbLocal()
Local database constructor.
Definition: imagemanager.cpp:1089
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:864
Device::Device
Device(QString name, QString mount, MythMediaDevice *media=nullptr, QTemporaryDir *import=nullptr)
Definition: imagemanager.cpp:36
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:1627
kSortByDateAsc
@ kSortByDateAsc
Exif date Earliest -> Latest.
Definition: imagetypes.h:53
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:953
ImageIdList
QList< int > ImageIdList
Definition: imagetypes.h:59
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:1003
ImageManagerFe::CrumbName
QString CrumbName(ImageItemK &im, bool getPath=false) const
Return a displayable name (with optional path) for an image.
Definition: imagemanager.cpp:2405
ImageItem::m_parentId
int m_parentId
Id of parent dir.
Definition: imagetypes.h:95
ImageDb::ClearDb
void ClearDb(int devId, const QString &action)
Clear Db for device & remove device.
Definition: imagemanager.cpp:760
StringPair
QPair< QString, QString > StringPair
Definition: imagetypes.h:60
ImageDbReader::GetChildren
int GetChildren(int id, ImageList &files, ImageList &dirs) const
Return (local or remote) images that are direct children of a dir.
Definition: imagemanager.cpp:1874
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:514
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:1963
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:618
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:421
ImageDb::RemoveFromDB
QStringList RemoveFromDB(const ImageList &imList) const
Remove images/dirs from database.
Definition: imagemanager.cpp:897
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:729
ImageDbLocal::CreateTable
bool CreateTable()
Create local database table, if it doesn't exist.
Definition: imagemanager.cpp:1114
MediaMonitor::ValidateAndLock
bool ValidateAndLock(MythMediaDevice *pMedia)
Validates the MythMediaDevice and increments its reference count.
Definition: mythmediamonitor.cpp:503
MythDate::kDateFull
@ kDateFull
Default local time.
Definition: mythdate.h:16
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:1774
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:859
ImageItem::m_userThumbnail
int m_userThumbnail
Id of thumbnail to use as cover (dirs only)
Definition: imagetypes.h:105
ImageHandler::HandleDelete
QStringList HandleDelete(const QString &ids) const
Deletes images/dirs.
Definition: imagemanager.cpp:1310
ImageItem::IsDevice
bool IsDevice() const
Definition: imagetypes.h:115
ImageAdapterSg::GetScanDirs
StringMap GetScanDirs() const
Returns SG dirs.
Definition: imagemanager.cpp:497
MythMediaDevice
Definition: mythmedia.h:48
ImageManagerFe::DeleteFiles
QString DeleteFiles(const ImageIdList &ids)
Delete images.
Definition: imagemanager.cpp:2316
kSortByModTimeAsc
@ kSortByModTimeAsc
File modified time Earliest -> Latest.
Definition: imagetypes.h:47
ReadMetaThread::ReadMetaThread
ReadMetaThread(ImagePtrK im, QString path)
Definition: imagemanager.cpp:1149
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:600
ReadMetaThread::m_path
QString m_path
Definition: imagemanager.cpp:1190
ImageDb
Database API.
Definition: imagemanager.h:274
ImageItem::m_extension
QString m_extension
Image file extension.
Definition: imagetypes.h:93
MythDate::kTime
@ kTime
Default local time.
Definition: mythdate.h:19
kDevice
@ kDevice
Storage Group and local mounted media.
Definition: imagetypes.h:35
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:437
ImageItem::m_date
qint64 m_date
Image creation date, from Exif metadata.
Definition: imagetypes.h:99
ImageManagerBe
The image manager to be used by the Backend.
Definition: imagemanager.h:378
kSortBySizeAsc
@ kSortBySizeAsc
File size Smallest -> Largest.
Definition: imagetypes.h:51
ImageDb::GetDescendants
bool GetDescendants(const QString &ids, ImageList &files, ImageList &dirs) const
Return images and all of their descendants.
Definition: imagemanager.cpp:660
ImageManagerFe::RequestMetaData
void RequestMetaData(int id)
Requests all exif/ffmpeg tags for an image, which returns by event.
Definition: imagemanager.cpp:2163
MThreadPool::globalInstance
static MThreadPool * globalInstance(void)
Definition: mthreadpool.cpp:306
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:1038
ImageAdapterBase::GetImageType
ImageNodeType GetImageType(const QString &ext) const
Determine file type from its extension.
Definition: imagemanager.h:165
query
MSqlQuery query(MSqlQuery::InitCon())
ImageManagerFe::ScanQuery
static QStringList ScanQuery()
Returns storage group scanner status.
Definition: imagemanager.cpp:2060
kUnknown
@ kUnknown
Unprocessable file type.
Definition: imagetypes.h:34
MythCoreContext::SaveSettingOnHost
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
Definition: mythcorecontext.cpp:912
ImageManagerFe::RenameFile
QString RenameFile(const ImagePtrK &im, const QString &name)
Rename an image.
Definition: imagemanager.cpp:2225
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:2372
ImageHandler::HandleCreateThumbnails
QStringList HandleCreateThumbnails(const QStringList &message) const
Creates thumbnails on-demand.
Definition: imagemanager.cpp:1693
ReadMetaThread::m_im
ImagePtrK m_im
Definition: imagemanager.cpp:1189
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:1479
kSortBySizeDesc
@ kSortBySizeDesc
File size Largest -> Smallest.
Definition: imagetypes.h:52
Orientation
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:62
MThreadPool::start
void start(QRunnable *runnable, const QString &debugName, int priority=0)
Definition: mthreadpool.cpp:341
ImageItem::m_size
int m_size
Filesize (files only)
Definition: imagetypes.h:98
MEDIATYPE_DATA
@ MEDIATYPE_DATA
Definition: mythmedia.h:26
GALLERY_DB_ID
#define GALLERY_DB_ID
Definition: imagetypes.h:26
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:919
ImageAdapterBase::SupportedVideos
static QStringList SupportedVideos()
Return recognised video extensions.
Definition: imagemanager.cpp:349
ReadMetaThread::run
void run() override
Definition: imagemanager.cpp:1152
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
ImageItem::m_filePath
QString m_filePath
Absolute for local images. Usually SG-relative for remotes.
Definition: imagetypes.h:92
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:2439