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 typedef QList<int> ImageIdList;
60 typedef QPair<QString, QString> StringPair;
61 typedef QHash<QString, QString> NameHash;
62 typedef QMap<int, QString> StringMap;
63 typedef QPair<int, QString> ThumbPair;
64 
65 
68 {
69 public:
70  explicit ImageItem(int id = 0)
71  : m_id(id),
72  m_baseName(""), m_filePath(""), m_extension(""),
73  m_device(0), m_parentId(0),
74  m_type(0),
75  m_modTime(0), m_size(0),
76  m_date(0), m_orientation(0), m_comment(""),
77  m_isHidden(false), m_userThumbnail(0),
78  m_url(""), m_thumbPath(""),
79  m_dirCount(0), m_fileCount(0)
80 #ifndef MEMORY_DEBUG
81  {}
82 #else
83  { qDebug() << QString("Created %1 (%2)").arg(m_id).arg(++GetItemCount()); }
84 
85  ~ImageItem()
86  { qDebug() << QString("Deleted %1 (%2)").arg(m_id).arg(--GetItemCount()); }
87 
88  // Embeds a static var in header to avoid the need for a cpp
89  static int& GetItemCount() { static int count; return count; }
90 #endif
91 
92 
96  int m_id;
97 
98  // Db File attributes
99  QString m_baseName;
100  QString m_filePath;
101  QString m_extension;
102  int m_device;
104  int m_type;
105 #if QT_VERSION < QT_VERSION_CHECK(5,8,0)
106  uint m_modTime;
107 #else
108  qint64 m_modTime;
109 #endif
110  int m_size;
111 #if QT_VERSION < QT_VERSION_CHECK(5,8,0)
112  uint m_date;
113 #else
114  qint64 m_date;
115 #endif
117  QString m_comment;
118 
119  // Db User attributes
120  bool m_isHidden;
122 
123  // Derived attributes
124  QString m_url;
125  QString m_thumbPath;
126  QList<ThumbPair> m_thumbNails;
129 
130  // Convenience functions
131  bool IsDevice() const { return m_type == kDevice; }
132  bool IsDirectory() const { return m_type <= kDirectory; }
133  bool IsFile() const { return m_type > kDirectory; }
134  bool IsLocal() const { return IsLocalId(m_id); }
135 
137  static bool IsLocalId(int id) { return id < GALLERY_DB_ID; }
139  static bool IsLocalParent(int id) { return id <= GALLERY_DB_ID; }
140 
142  static int ToLocalId(int id) { return -id; }
143  static QString ToLocalId(const QString &id) { return "-" + id; }
144 
146  static int ToDbId(int id) { return abs(id); }
147  static QString ToDbId(QString ids) { return ids.remove("-"); }
148 
149 
156  {
157  QStringList local, remote;
158  foreach(int id, ids)
159  {
160  if (ImageItem::IsLocalId(id))
161  local << QString::number(id);
162  else
163  remote << QString::number(id);
164  }
165  return qMakePair(local.join(","), remote.join(","));
166  }
167 
168 private:
169  Q_DISABLE_COPY(ImageItem)
170 };
171 
172 // Convenience containers
173 typedef QSharedPointer<ImageItem> ImagePtr;
174 typedef QList<ImagePtr> ImageList;
175 typedef QHash<QString, ImagePtr> ImageHash;
176 
177 // Read-only images alias
178 typedef const ImageItem ImageItemK;
179 typedef QSharedPointer<ImageItemK> ImagePtrK;
180 typedef QList<ImagePtrK> ImageListK;
181 
183 
184 #endif // IMAGETYPES_H
File size Largest -> Smallest.
Definition: imagetypes.h:52
A video.
Definition: imagetypes.h:39
static QString ToDbId(QString ids)
Definition: imagetypes.h:147
Name Z-A.
Definition: imagetypes.h:46
QString m_thumbPath
Myth URL of image (abs filepath for locals)
Definition: imagetypes.h:125
QHash< QString, QString > NameHash
Definition: imagetypes.h:61
QList< ThumbPair > m_thumbNails
Definition: imagetypes.h:126
QPair< int, QString > ThumbPair
Definition: imagetypes.h:63
QString m_url
Definition: imagetypes.h:124
QHash< QString, ImagePtr > ImageHash
Definition: imagetypes.h:175
A device sub directory.
Definition: imagetypes.h:37
static int ToLocalId(int id)
Converts a DB id (positive) to an id of a local image (negative)
Definition: imagetypes.h:142
Extension Z-A.
Definition: imagetypes.h:50
qint64 m_date
Image creation date, from Exif metadata.
Definition: imagetypes.h:114
QString m_filePath
Absolute for local images. Usually SG-relative for remotes.
Definition: imagetypes.h:100
static int ToDbId(int id)
Converts local image ids (negative) to Db ids (positive)
Definition: imagetypes.h:146
ImageItem(int id=0)
Definition: imagetypes.h:70
int m_fileCount
Number of child images (dirs only)
Definition: imagetypes.h:128
int m_parentId
Id of parent dir.
Definition: imagetypes.h:103
unsigned int uint
Definition: compat.h:140
Q_DECLARE_METATYPE(GrabberScript *)
bool IsDevice() const
Definition: imagetypes.h:131
QMap< int, QString > StringMap
Definition: imagetypes.h:62
bool IsLocal() const
Definition: imagetypes.h:134
Exif date Latest -> Earliest.
Definition: imagetypes.h:54
QString m_extension
Image file extension.
Definition: imagetypes.h:101
int m_userThumbnail
Id of thumbnail to use as cover (dirs only)
Definition: imagetypes.h:121
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
static bool IsLocalParent(int id)
Parents of locals are locals or root.
Definition: imagetypes.h:139
#define META_PUBLIC
Definition: mythmetaexp.h:9
Name A-Z.
Definition: imagetypes.h:45
Extension A-Z.
Definition: imagetypes.h:49
qint64 m_modTime
Filesystem modified datestamp.
Definition: imagetypes.h:108
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:155
File modified time Latest -> Earliest.
Definition: imagetypes.h:48
static bool IsLocalId(int id)
Determine image type (local/remote) from its id. Root/Gallery is remote.
Definition: imagetypes.h:137
int m_orientation
Image orientation.
Definition: imagetypes.h:116
QString m_baseName
File/Dir name with extension (no path)
Definition: imagetypes.h:99
QPair< QString, QString > StringPair
Definition: imagetypes.h:60
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:179
QList< ImagePtr > ImageList
Definition: imagetypes.h:174
bool IsDirectory() const
Definition: imagetypes.h:132
int m_dirCount
Id & URLs of thumbnail(s). 1 for a file, 4 for dirs.
Definition: imagetypes.h:127
A picture.
Definition: imagetypes.h:38
bool IsFile() const
Definition: imagetypes.h:133
Exif date Earliest -> Latest.
Definition: imagetypes.h:53
ImageSortOrder
Image ordering.
Definition: imagetypes.h:44
static QString ToLocalId(const QString &id)
Definition: imagetypes.h:143
QSharedPointer< ImageItem > ImagePtr
Definition: imagetypes.h:173
int m_device
Id of media device. Always 0 (SG) for remotes, 1+ for local devices.
Definition: imagetypes.h:102
Represents a picture, video or directory.
Definition: imagetypes.h:67
int m_type
Type of node: dir, video etc.
Definition: imagetypes.h:104
Storage Group and local mounted media.
Definition: imagetypes.h:35
File modified time Earliest -> Latest.
Definition: imagetypes.h:47
QList< int > ImageIdList
Definition: imagetypes.h:59
Unprocessable file type.
Definition: imagetypes.h:34
const ImageItem ImageItemK
Definition: imagetypes.h:178
ImageNodeType
Type of image node.
Definition: imagetypes.h:33
int m_id
Uniquely identifies an image (file/dir).
Definition: imagetypes.h:96
QString m_comment
User comment, from Exif metadata.
Definition: imagetypes.h:117
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:180
int m_size
Filesize (files only)
Definition: imagetypes.h:110
#define GALLERY_DB_ID
Definition: imagetypes.h:26
File size Smallest -> Largest.
Definition: imagetypes.h:51
bool m_isHidden
If true, image won't be shown.
Definition: imagetypes.h:120
A device sub dir comprised from multiple SG dirs.
Definition: imagetypes.h:36