MythTV master
imagetypes.h
Go to the documentation of this file.
1
3
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
16#include "mythmetaexp.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
27static constexpr int GALLERY_DB_ID { 0 };
28// Id of the Storage Group (Photographs) node
29static constexpr int PHOTO_DB_ID { 1 };
30
31
33// We need to use other names to avoid getting coflicts with the videolist.h file
34enum ImageNodeType : std::uint8_t {
36 kDevice = 1,
40 kVideoFile = 5
41};
42
43
45enum ImageSortOrder : std::uint8_t {
55 kSortByDateDesc = 10
56};
57
58
59// Convenience types
60using ImageIdList = QList<int>;
61using StringPair = QPair<QString, QString>;
62using NameHash = QHash<QString, QString>;
63using StringMap = QMap<int, QString>;
64using ThumbPair = QPair<int, QString>;
65
66
69{
70public:
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
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 : std::as_const(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
154private:
155 Q_DISABLE_COPY(ImageItem)
156};
157
158// Convenience containers
159using ImagePtr = QSharedPointer<ImageItem>;
160using ImageList = QVector<ImagePtr>;
161using ImageHash = QHash<QString, ImagePtr>;
162
163// Read-only images alias
164using ImageItemK = const ImageItem;
165using ImagePtrK = QSharedPointer<ImageItemK>;
166using ImageListK = QList<ImagePtrK>;
167
169
170#endif // IMAGETYPES_H
Represents a picture, video or directory.
Definition: imagetypes.h:69
static bool IsLocalParent(int id)
Parents of locals are locals or root.
Definition: imagetypes.h:124
int m_id
Uniquely identifies an image (file/dir).
Definition: imagetypes.h:89
QString m_extension
Image file extension.
Definition: imagetypes.h:94
bool IsLocal() const
Definition: imagetypes.h:119
QList< ThumbPair > m_thumbNails
Definition: imagetypes.h:111
bool IsFile() const
Definition: imagetypes.h:118
static bool IsLocalId(int id)
Determine image type (local/remote) from its id. Root/Gallery is remote.
Definition: imagetypes.h:122
QString m_comment
User comment, from Exif metadata.
Definition: imagetypes.h:102
QString m_url
Definition: imagetypes.h:109
static int ToDbId(int id)
Converts local image ids (negative) to Db ids (positive)
Definition: imagetypes.h:131
QString m_baseName
File/Dir name with extension (no path)
Definition: imagetypes.h:92
QString m_thumbPath
Myth URL of image (abs filepath for locals)
Definition: imagetypes.h:110
static QString ToDbId(QString ids)
Definition: imagetypes.h:132
bool IsDirectory() const
Definition: imagetypes.h:117
ImageItem(int id=0)
Definition: imagetypes.h:71
bool IsDevice() const
Definition: imagetypes.h:116
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
QString m_filePath
Absolute for local images. Usually SG-relative for remotes.
Definition: imagetypes.h:93
static int ToLocalId(int id)
Converts a DB id (positive) to an id of a local image (negative)
Definition: imagetypes.h:127
static QString ToLocalId(const QString &id)
Definition: imagetypes.h:128
QHash< QString, ImagePtr > ImageHash
Definition: imagetypes.h:161
QVector< ImagePtr > ImageList
Definition: imagetypes.h:160
ImageSortOrder
Image ordering.
Definition: imagetypes.h:45
@ kSortBySizeAsc
File size Smallest -> Largest.
Definition: imagetypes.h:52
@ kSortByNameAsc
Name A-Z.
Definition: imagetypes.h:46
@ kSortByDateAsc
Exif date Earliest -> Latest.
Definition: imagetypes.h:54
@ kSortByExtAsc
Extension A-Z.
Definition: imagetypes.h:50
@ kSortByExtDesc
Extension Z-A.
Definition: imagetypes.h:51
@ kSortByNameDesc
Name Z-A.
Definition: imagetypes.h:47
@ kSortBySizeDesc
File size Largest -> Smallest.
Definition: imagetypes.h:53
@ kSortByModTimeAsc
File modified time Earliest -> Latest.
Definition: imagetypes.h:48
@ kSortByModTimeDesc
File modified time Latest -> Earliest.
Definition: imagetypes.h:49
@ kSortByDateDesc
Exif date Latest -> Earliest.
Definition: imagetypes.h:55
QList< ImagePtrK > ImageListK
Definition: imagetypes.h:166
QSharedPointer< ImageItemK > ImagePtrK
Definition: imagetypes.h:165
QPair< int, QString > ThumbPair
Definition: imagetypes.h:64
QMap< int, QString > StringMap
Definition: imagetypes.h:63
static constexpr int GALLERY_DB_ID
Definition: imagetypes.h:27
static constexpr int PHOTO_DB_ID
Definition: imagetypes.h:29
ImageNodeType
Type of image node.
Definition: imagetypes.h:34
@ kDevice
Storage Group and local mounted media.
Definition: imagetypes.h:36
@ kCloneDir
A device sub dir comprised from multiple SG dirs.
Definition: imagetypes.h:37
@ kDirectory
A device sub directory.
Definition: imagetypes.h:38
@ kImageFile
A picture.
Definition: imagetypes.h:39
@ kUnknown
Unprocessable file type.
Definition: imagetypes.h:35
@ kVideoFile
A video.
Definition: imagetypes.h:40
QSharedPointer< ImageItem > ImagePtr
Definition: imagetypes.h:159
QHash< QString, QString > NameHash
Definition: imagetypes.h:62
QPair< QString, QString > StringPair
Definition: imagetypes.h:61
QList< int > ImageIdList
Definition: imagetypes.h:60
Q_DECLARE_METATYPE(std::chrono::seconds)
#define META_PUBLIC
Definition: mythmetaexp.h:9