Changeset View
Changeset View
Standalone View
Standalone View
src/datatypes.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2016-2017 Matthieu Gallien <matthieu_gallien@yahoo.fr> | ||||
3 | * Copyright 2019 Alexander Stippich <a.stippich@gmx.net> | ||||
4 | * | ||||
5 | * This program is free software: you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Lesser General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 3 of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | * Lesser General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Lesser General Public License | ||||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef DATATYPES_H | ||||
20 | #define DATATYPES_H | ||||
21 | | ||||
22 | #include "elisaLib_export.h" | ||||
23 | | ||||
24 | #include <QObject> | ||||
25 | #include <QString> | ||||
26 | #include <QList> | ||||
27 | #include <QVariant> | ||||
28 | #include <QUrl> | ||||
29 | #include <QDateTime> | ||||
30 | #include <QMap> | ||||
31 | | ||||
32 | class ELISALIB_EXPORT DataTypes : public QObject | ||||
33 | { | ||||
34 | Q_OBJECT | ||||
35 | | ||||
36 | public: | ||||
37 | | ||||
38 | enum ColumnsRoles { | ||||
39 | TitleRole = Qt::UserRole + 1, | ||||
40 | SecondaryTextRole, | ||||
41 | ImageUrlRole, | ||||
42 | ShadowForImageRole, | ||||
43 | ChildModelRole, | ||||
44 | DurationRole, | ||||
45 | StringDurationRole, | ||||
46 | MilliSecondsDurationRole, | ||||
47 | ArtistRole, | ||||
48 | AllArtistsRole, | ||||
49 | HighestTrackRating, | ||||
50 | AlbumRole, | ||||
51 | AlbumArtistRole, | ||||
52 | IsValidAlbumArtistRole, | ||||
53 | TrackNumberRole, | ||||
54 | DiscNumberRole, | ||||
55 | RatingRole, | ||||
56 | GenreRole, | ||||
57 | LyricistRole, | ||||
58 | ComposerRole, | ||||
59 | CommentRole, | ||||
60 | YearRole, | ||||
61 | ChannelsRole, | ||||
62 | BitRateRole, | ||||
63 | SampleRateRole, | ||||
64 | ResourceRole, | ||||
65 | IdRole, | ||||
66 | DatabaseIdRole, | ||||
67 | IsSingleDiscAlbumRole, | ||||
68 | ContainerDataRole, | ||||
69 | IsPartialDataRole, | ||||
70 | AlbumIdRole, | ||||
71 | HasEmbeddedCover, | ||||
72 | FileModificationTime, | ||||
73 | FirstPlayDate, | ||||
74 | LastPlayDate, | ||||
75 | PlayCounter, | ||||
76 | PlayFrequency, | ||||
77 | ElementTypeRole, | ||||
78 | LyricsRole, | ||||
79 | }; | ||||
80 | | ||||
81 | Q_ENUM(ColumnsRoles) | ||||
82 | | ||||
83 | private: | ||||
84 | | ||||
85 | using DataType = QMap<ColumnsRoles, QVariant>; | ||||
86 | | ||||
87 | public: | ||||
88 | | ||||
89 | class TrackDataType : public DataType | ||||
90 | { | ||||
91 | public: | ||||
92 | | ||||
93 | using DataType::DataType; | ||||
94 | | ||||
95 | bool isValid() const | ||||
96 | { | ||||
97 | return !isEmpty(); | ||||
98 | } | ||||
99 | | ||||
100 | qulonglong databaseId() const | ||||
101 | { | ||||
102 | return operator[](key_type::DatabaseIdRole).toULongLong(); | ||||
103 | } | ||||
104 | | ||||
105 | QString title() const | ||||
106 | { | ||||
107 | return operator[](key_type::TitleRole).toString(); | ||||
108 | } | ||||
109 | | ||||
110 | QString artist() const | ||||
111 | { | ||||
112 | return operator[](key_type::ArtistRole).toString(); | ||||
113 | } | ||||
114 | | ||||
115 | qulonglong albumId() const | ||||
116 | { | ||||
117 | return operator[](key_type::AlbumIdRole).toULongLong(); | ||||
118 | } | ||||
119 | | ||||
120 | bool hasAlbum() const | ||||
121 | { | ||||
122 | return find(key_type::AlbumRole) != end(); | ||||
123 | } | ||||
124 | | ||||
125 | QString album() const | ||||
126 | { | ||||
127 | return operator[](key_type::AlbumRole).toString(); | ||||
128 | } | ||||
129 | | ||||
130 | QString albumArtist() const | ||||
131 | { | ||||
132 | return operator[](key_type::AlbumArtistRole).toString(); | ||||
133 | } | ||||
134 | | ||||
135 | bool hasTrackNumber() const | ||||
136 | { | ||||
137 | return find(key_type::TrackNumberRole) != end(); | ||||
138 | } | ||||
139 | | ||||
140 | int trackNumber() const | ||||
141 | { | ||||
142 | return operator[](key_type::TrackNumberRole).toInt(); | ||||
143 | } | ||||
144 | | ||||
145 | bool hasDiscNumber() const | ||||
146 | { | ||||
147 | return find(key_type::DiscNumberRole) != end(); | ||||
148 | } | ||||
149 | | ||||
150 | int discNumber() const | ||||
151 | { | ||||
152 | return operator[](key_type::DiscNumberRole).toInt(); | ||||
153 | } | ||||
154 | | ||||
155 | QTime duration() const | ||||
156 | { | ||||
157 | return operator[](key_type::DurationRole).toTime(); | ||||
158 | } | ||||
159 | | ||||
160 | QUrl resourceURI() const | ||||
161 | { | ||||
162 | return operator[](key_type::ResourceRole).toUrl(); | ||||
163 | } | ||||
164 | | ||||
165 | QUrl albumCover() const | ||||
166 | { | ||||
167 | return operator[](key_type::ImageUrlRole).toUrl(); | ||||
168 | } | ||||
169 | | ||||
170 | bool isSingleDiscAlbum() const | ||||
171 | { | ||||
172 | return operator[](key_type::IsSingleDiscAlbumRole).toBool(); | ||||
173 | } | ||||
174 | | ||||
175 | int rating() const | ||||
176 | { | ||||
177 | return operator[](key_type::RatingRole).toInt(); | ||||
178 | } | ||||
179 | | ||||
180 | QString genre() const | ||||
181 | { | ||||
182 | return operator[](key_type::GenreRole).toString(); | ||||
183 | } | ||||
184 | | ||||
185 | QString composer() const | ||||
186 | { | ||||
187 | return operator[](key_type::ComposerRole).toString(); | ||||
188 | } | ||||
189 | | ||||
190 | QString lyricist() const | ||||
191 | { | ||||
192 | return operator[](key_type::LyricistRole).toString(); | ||||
193 | } | ||||
194 | | ||||
195 | QString lyrics() const | ||||
196 | { | ||||
197 | return operator[](key_type::LyricsRole).toString(); | ||||
198 | } | ||||
199 | | ||||
200 | QString comment() const | ||||
201 | { | ||||
202 | return operator[](key_type::CommentRole).toString(); | ||||
203 | } | ||||
204 | | ||||
205 | int year() const | ||||
206 | { | ||||
207 | return operator[](key_type::YearRole).toInt(); | ||||
208 | } | ||||
209 | | ||||
210 | int channels() const | ||||
211 | { | ||||
212 | return operator[](key_type::ChannelsRole).toInt(); | ||||
213 | } | ||||
214 | | ||||
215 | int bitRate() const | ||||
216 | { | ||||
217 | return operator[](key_type::BitRateRole).toInt(); | ||||
218 | } | ||||
219 | | ||||
220 | int sampleRate() const | ||||
221 | { | ||||
222 | return operator[](key_type::SampleRateRole).toInt(); | ||||
223 | } | ||||
224 | | ||||
225 | bool hasEmbeddedCover() const | ||||
226 | { | ||||
227 | return operator[](key_type::HasEmbeddedCover).toBool(); | ||||
228 | } | ||||
229 | | ||||
230 | QDateTime fileModificationTime() const | ||||
231 | { | ||||
232 | return operator[](key_type::FileModificationTime).toDateTime(); | ||||
233 | } | ||||
234 | }; | ||||
235 | | ||||
236 | using ListTrackDataType = QList<TrackDataType>; | ||||
237 | | ||||
238 | using ListRadioDataType = QList<TrackDataType>; | ||||
239 | | ||||
240 | class AlbumDataType : public DataType | ||||
241 | { | ||||
242 | public: | ||||
243 | | ||||
244 | using DataType::DataType; | ||||
245 | | ||||
246 | qulonglong databaseId() const | ||||
247 | { | ||||
248 | return operator[](key_type::DatabaseIdRole).toULongLong(); | ||||
249 | } | ||||
250 | | ||||
251 | QString title() const | ||||
252 | { | ||||
253 | return operator[](key_type::TitleRole).toString(); | ||||
254 | } | ||||
255 | | ||||
256 | QString artist() const | ||||
257 | { | ||||
258 | return operator[](key_type::ArtistRole).toString(); | ||||
259 | } | ||||
260 | | ||||
261 | bool isValidArtist() const | ||||
262 | { | ||||
263 | const auto &artistData = operator[](key_type::ArtistRole); | ||||
264 | return artistData.isValid() && !artistData.toString().isEmpty(); | ||||
265 | } | ||||
266 | | ||||
267 | QStringList genres() const | ||||
268 | { | ||||
269 | return operator[](key_type::GenreRole).toStringList(); | ||||
270 | } | ||||
271 | | ||||
272 | QUrl albumArtURI() const | ||||
273 | { | ||||
274 | return operator[](key_type::ImageUrlRole).toUrl(); | ||||
275 | } | ||||
276 | | ||||
277 | bool isSingleDiscAlbum() const | ||||
278 | { | ||||
279 | return operator[](key_type::IsSingleDiscAlbumRole).toBool(); | ||||
280 | } | ||||
281 | | ||||
282 | bool isValid() const | ||||
283 | { | ||||
284 | return !isEmpty(); | ||||
285 | } | ||||
286 | | ||||
287 | }; | ||||
288 | | ||||
289 | using ListAlbumDataType = QList<AlbumDataType>; | ||||
290 | | ||||
291 | class ArtistDataType : public DataType | ||||
292 | { | ||||
293 | public: | ||||
294 | | ||||
295 | using DataType::DataType; | ||||
296 | | ||||
297 | qulonglong databaseId() const | ||||
298 | { | ||||
299 | return operator[](key_type::DatabaseIdRole).toULongLong(); | ||||
300 | } | ||||
301 | | ||||
302 | }; | ||||
303 | | ||||
304 | using ListArtistDataType = QList<ArtistDataType>; | ||||
305 | | ||||
306 | class GenreDataType : public DataType | ||||
307 | { | ||||
308 | public: | ||||
309 | | ||||
310 | using DataType::DataType; | ||||
311 | | ||||
312 | qulonglong databaseId() const | ||||
313 | { | ||||
314 | return operator[](key_type::DatabaseIdRole).toULongLong(); | ||||
315 | } | ||||
316 | | ||||
317 | QString title() const | ||||
318 | { | ||||
319 | return operator[](key_type::TitleRole).toString(); | ||||
320 | } | ||||
321 | | ||||
322 | }; | ||||
323 | | ||||
324 | using ListGenreDataType = QList<GenreDataType>; | ||||
325 | | ||||
326 | }; | ||||
327 | | ||||
328 | Q_DECLARE_METATYPE(DataTypes::TrackDataType) | ||||
329 | Q_DECLARE_METATYPE(DataTypes::AlbumDataType) | ||||
330 | Q_DECLARE_METATYPE(DataTypes::ArtistDataType) | ||||
331 | Q_DECLARE_METATYPE(DataTypes::GenreDataType) | ||||
332 | | ||||
333 | Q_DECLARE_METATYPE(DataTypes::ListTrackDataType) | ||||
334 | Q_DECLARE_METATYPE(DataTypes::ListAlbumDataType) | ||||
335 | Q_DECLARE_METATYPE(DataTypes::ListArtistDataType) | ||||
336 | Q_DECLARE_METATYPE(DataTypes::ListGenreDataType) | ||||
337 | | ||||
338 | #endif // DATABASEINTERFACE_H |