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