MythTV  master
imagetypes.h
Go to the documentation of this file.
1 
4 #ifndef IMAGETYPES_H
5 #define IMAGETYPES_H
6 
7 #include <QStringList>
8 #include <QSharedPointer>
9 #include <QPair>
10 #include <QList>
11 #include <QHash>
12 #include <QMap>
13 #include <QMetaType>
14 
15 #include "mythmetaexp.h"
16 #include "mythchrono.h"
17 
18 // Define this to log/count creation/deletion of ImageItem heap objects.
19 // These are created liberally when processing images and are liable to leak.
20 // At idle there should be precisely 1 ImageItem for every image/dir displayed.
21 //#define MEMORY_DEBUG active
22 #ifdef MEMORY_DEBUG
23 #include <QDebug>
24 #endif
25 
26 // Id of the (virtual) Gallery root node
27 #define GALLERY_DB_ID 0
28 // Id of the Storage Group (Photographs) node
29 #define PHOTO_DB_ID 1
30 
31 
33 // We need to use other names to avoid getting coflicts with the videolist.h file
35  kUnknown = 0,
36  kDevice = 1,
37  kCloneDir = 2,
38  kDirectory = 3,
39  kImageFile = 4,
41 };
42 
43 
56 };
57 
58 
59 // Convenience types
60 using ImageIdList = QList<int>;
61 using StringPair = QPair<QString, QString>;
62 using NameHash = QHash<QString, QString>;
63 using StringMap = QMap<int, QString>;
64 using ThumbPair = QPair<int, QString>;
65 
66 
69 {
70 public:
71  explicit ImageItem(int id = 0)
72  : m_id(id)
73 #ifndef MEMORY_DEBUG
74  {}
75 #else
76  { qDebug() << QString("Created %1 (%2)").arg(m_id).arg(++GetItemCount()); }
77 
78  ~ImageItem()
79  { qDebug() << QString("Deleted %1 (%2)").arg(m_id).arg(--GetItemCount()); }
80 
81  // Embeds a static var in header to avoid the need for a cpp
82  static int& GetItemCount() { static int count; return count; }
83 #endif
84 
85 
89  int m_id;
90 
91  // Db File attributes
92  QString m_baseName;
93  QString m_filePath;
94  QString m_extension;
95  int m_device { 0 };
96  int m_parentId { 0 };
97  int m_type { 0 };
98  std::chrono::seconds m_modTime { 0s };
99  int m_size { 0 };
100  std::chrono::seconds m_date { 0s };
101  int m_orientation { 0 };
102  QString m_comment;
103 
104  // Db User attributes
105  bool m_isHidden { false };
106  int m_userThumbnail { 0 };
107 
108  // Derived attributes
109  QString m_url;
110  QString m_thumbPath;
111  QList<ThumbPair> m_thumbNails;
112  int m_dirCount { 0 };
113  int m_fileCount { 0 };
114 
115  // Convenience functions
116  bool IsDevice() const { return m_type == kDevice; }
117  bool IsDirectory() const { return m_type <= kDirectory; }
118  bool IsFile() const { return m_type > kDirectory; }
119  bool IsLocal() const { return IsLocalId(m_id); }
120 
122  static bool IsLocalId(int id) { return id < GALLERY_DB_ID; }
124  static bool IsLocalParent(int id) { return id <= GALLERY_DB_ID; }
125 
127  static int ToLocalId(int id) { return -id; }
128  static QString ToLocalId(const QString &id) { return "-" + id; }
129 
131  static int ToDbId(int id) { return abs(id); }
132  static QString ToDbId(QString ids) { return ids.remove("-"); }
133 
134 
141  {
142  QStringList local;
143  QStringList remote;
144  for (int id : qAsConst(ids))
145  {
146  if (ImageItem::IsLocalId(id))
147  local << QString::number(id);
148  else
149  remote << QString::number(id);
150  }
151  return qMakePair(local.join(","), remote.join(","));
152  }
153 
154 private:
155  Q_DISABLE_COPY(ImageItem)
156 };
157 
158 // Convenience containers
159 using ImagePtr = QSharedPointer<ImageItem>;
160 using ImageList = QVector<ImagePtr>;
161 using ImageHash = QHash<QString, ImagePtr>;
162 
163 // Read-only images alias
164 using ImageItemK = const ImageItem;
165 using ImagePtrK = QSharedPointer<ImageItemK>;
166 using ImageListK = QList<ImagePtrK>;
167 
169 
170 #endif // IMAGETYPES_H
kSortByNameDesc
@ kSortByNameDesc
Name Z-A.
Definition: imagetypes.h:47
ImagePtrK
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
NameHash
QHash< QString, QString > NameHash
Definition: imagetypes.h:62
ImageNodeType
ImageNodeType
Type of image node.
Definition: imagetypes.h:34
kVideoFile
@ kVideoFile
A video.
Definition: imagetypes.h:40
ImageItem::m_id
int m_id
Uniquely identifies an image (file/dir).
Definition: imagetypes.h:89
kSortByExtDesc
@ kSortByExtDesc
Extension Z-A.
Definition: imagetypes.h:51
ImageItem::m_comment
QString m_comment
User comment, from Exif metadata.
Definition: imagetypes.h:102
ImageItem::ToLocalId
static int ToLocalId(int id)
Converts a DB id (positive) to an id of a local image (negative)
Definition: imagetypes.h:127
ImageItem::IsLocal
bool IsLocal() const
Definition: imagetypes.h:119
kDirectory
@ kDirectory
A device sub directory.
Definition: imagetypes.h:38
ImageItem::ToDbId
static QString ToDbId(QString ids)
Definition: imagetypes.h:132
mythmetaexp.h
ImageItem::m_url
QString m_url
Definition: imagetypes.h:109
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
kSortByDateDesc
@ kSortByDateDesc
Exif date Latest -> Earliest.
Definition: imagetypes.h:55
ImageHash
QHash< QString, ImagePtr > ImageHash
Definition: imagetypes.h:161
ImageItem::ImageItem
ImageItem(int id=0)
Definition: imagetypes.h:71
kSortByNameAsc
@ kSortByNameAsc
Name A-Z.
Definition: imagetypes.h:46
StringMap
QMap< int, QString > StringMap
Definition: imagetypes.h:63
ImageListK
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:166
ImageItem::ToLocalId
static QString ToLocalId(const QString &id)
Definition: imagetypes.h:128
kSortByExtAsc
@ kSortByExtAsc
Extension A-Z.
Definition: imagetypes.h:50
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_baseName
QString m_baseName
File/Dir name with extension (no path)
Definition: imagetypes.h:92
ImageList
QVector< ImagePtr > ImageList
Definition: imagetypes.h:160
ImageItem::IsLocalParent
static bool IsLocalParent(int id)
Parents of locals are locals or root.
Definition: imagetypes.h:124
ImageItem::m_thumbNails
QList< ThumbPair > m_thumbNails
Definition: imagetypes.h:111
kSortByModTimeDesc
@ kSortByModTimeDesc
File modified time Latest -> Earliest.
Definition: imagetypes.h:49
ImageItem::IsFile
bool IsFile() const
Definition: imagetypes.h:118
kImageFile
@ kImageFile
A picture.
Definition: imagetypes.h:39
ImagePtr
QSharedPointer< ImageItem > ImagePtr
Definition: imagetypes.h:159
ImageItem
Represents a picture, video or directory.
Definition: imagetypes.h:68
ImageItem::ToDbId
static int ToDbId(int id)
Converts local image ids (negative) to Db ids (positive)
Definition: imagetypes.h:131
kSortByDateAsc
@ kSortByDateAsc
Exif date Earliest -> Latest.
Definition: imagetypes.h:54
ImageIdList
QList< int > ImageIdList
Definition: imagetypes.h:60
ImageItem::m_thumbPath
QString m_thumbPath
Myth URL of image (abs filepath for locals)
Definition: imagetypes.h:110
ImageSortOrder
ImageSortOrder
Image ordering.
Definition: imagetypes.h:45
StringPair
QPair< QString, QString > StringPair
Definition: imagetypes.h:61
mythchrono.h
ImageItem::IsDirectory
bool IsDirectory() const
Definition: imagetypes.h:117
ThumbPair
QPair< int, QString > ThumbPair
Definition: imagetypes.h:64
ImageItem::IsDevice
bool IsDevice() const
Definition: imagetypes.h:116
kSortByModTimeAsc
@ kSortByModTimeAsc
File modified time Earliest -> Latest.
Definition: imagetypes.h:48
ImageItem::m_extension
QString m_extension
Image file extension.
Definition: imagetypes.h:94
kDevice
@ kDevice
Storage Group and local mounted media.
Definition: imagetypes.h:36
kSortBySizeAsc
@ kSortBySizeAsc
File size Smallest -> Largest.
Definition: imagetypes.h:52
kUnknown
@ kUnknown
Unprocessable file type.
Definition: imagetypes.h:35
META_PUBLIC
#define META_PUBLIC
Definition: mythmetaexp.h:9
kSortBySizeDesc
@ kSortBySizeDesc
File size Largest -> Smallest.
Definition: imagetypes.h:53
kCloneDir
@ kCloneDir
A device sub dir comprised from multiple SG dirs.
Definition: imagetypes.h:37
GALLERY_DB_ID
#define GALLERY_DB_ID
Definition: imagetypes.h:27
ImageItem::m_filePath
QString m_filePath
Absolute for local images. Usually SG-relative for remotes.
Definition: imagetypes.h:93