Parent: [5e96b0] (diff)

Child: [27e872] (diff)

Download this file

MetaData.h    320 lines (262 with data), 8.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* Copyright (C) 2011 Lucio Carreras
*
* This file is part of sayonara player
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef METADATA_H_
#define METADATA_H_
#include <vector>
using namespace std;
#include <QString>
#include <QStringList>
#include <QPair>
#include <QDebug>
#include <QVariant>
#include <QMap>
#include "HelperStructs/globals.h"
struct MetaData {
qint32 id;
qint32 album_id;
qint32 artist_id;
QString title;
QString artist;
QString album;
QStringList genres;
qint32 rating;
qint64 length_ms;
qint32 year;
QString filepath;
qint32 track_num;
qint32 bitrate;
qint64 filesize;
QString comment;
int discnumber;
int n_discs;
bool is_extern;
int radio_mode;
bool pl_selected;
bool pl_playing;
bool pl_dragged;
bool is_lib_selected;
bool is_disabled;
QString didl;
inline MetaData () {
id = -1;
artist_id = -1;
album_id = -1;
title = "";
artist = "";
album = "";
rating = 0;
length_ms = 0;
year = 0;
filepath = "";
track_num = 0;
bitrate = 0;
is_extern = false;
radio_mode = RADIO_OFF;
filesize = 0;
comment = "";
discnumber = 0;
n_discs = -1;
pl_selected = false;
pl_playing = false;
pl_dragged = false;
is_lib_selected = false;
is_disabled = false;
didl = "";
}
void print() {
qDebug() << title
<< " by " << artist
<< " from " << album
<< " (" << length_ms << " m_sec) :: " << filepath;
}
QVariant toVariant() const {
QStringList list;
QString tmpTitle = title;
QString tmpArtist = artist;
QString tmpAlbum = album;
if (title.trimmed().size() == 0) tmpTitle = QString("(Unknown title)");
if (artist.trimmed().size() == 0) tmpArtist = QString("");
if (album.trimmed().size() == 0) tmpAlbum = QString("");
list.push_back(tmpTitle);
list.push_back(tmpArtist);
list.push_back(tmpAlbum);
list.push_back(QString::number(rating));
list.push_back(QString::number(length_ms));
list.push_back(QString::number(year));
list.push_back(filepath);
list.push_back(QString::number(track_num));
list.push_back(QString::number(bitrate));
list.push_back(QString::number(id));
list.push_back(QString::number(album_id));
list.push_back(QString::number(artist_id));
list.push_back(QString::number(filesize));
list.push_back(comment);
list.push_back(QString::number(discnumber));
list.push_back(QString::number(n_discs));
list.push_back(genres.join(","));
list.push_back(QString::number( (is_extern) ? 1 : 0 ));
list.push_back( QString::number(radio_mode) );
list.push_back( (pl_playing) ? "1" : "0" );
list.push_back( (pl_selected) ? "1" : "0" );
list.push_back( (pl_dragged) ? "1" : "0" );
list.push_back( (is_lib_selected) ? "1" : "0" );
list.push_back( (is_disabled) ? "1" : "0");
list.push_back(didl);
return list;
}
static bool fromVariant(QVariant v, MetaData& md){
QStringList list = v.toStringList();
if(list.size() < 24) return false;
md.title = list[0];
md.artist = list[1];
md.album = list[2];
md.rating = list[3].toInt();
md.length_ms = list[4].toULongLong();
md.year = list[5].toInt();
md.filepath = list[6];
md.track_num = list[7].toInt();
md.bitrate = list[8].toInt();
md.id = list[9].toInt();
md.album_id = list[10].toInt();
md.artist_id = list[11].toInt();
md.filesize = list[12].toInt();
md.comment = list[13];
md.discnumber = list[14].toInt();
md.n_discs = list[15].toInt();
md.genres = list[16].split(",");
md.is_extern = ( list[17] == "1" );
md.radio_mode = list[18].toInt();
md.pl_playing = (list[19] == "1");
md.pl_selected = (list[20] == "1");
md.pl_dragged = (list[21] == "1");
md.is_lib_selected = (list[22] == "1");
md.is_disabled = (list[23] == "1");
md.didl = list[24];
return true;
}
};
class MetaDataList : public vector<MetaData> {
public:
MetaDataList(){}
~MetaDataList() {
clear();
}
void setCurPlayTrack(int idx) {
for (uint i = 0; i < size(); i++) {
if ((int) i == idx)
at(i).pl_playing = true;
at(i).pl_playing = false;
}
}
bool contains(const MetaData& md, bool cs=false) {
QString filepath;
if(cs) {
filepath = md.filepath.trimmed();
for(uint i = 0; i < size(); i++){
MetaData md = at(i);
QString filepath2 = md.filepath.trimmed();
if(!filepath.compare(filepath2))
return true;
}
} else {
filepath = md.filepath.toLower().trimmed();
for (uint i = 0; i < size(); i++){
MetaData md = vector<MetaData>::at(i);
QString filepath2 = md.filepath.toLower().trimmed();
if(!filepath.compare(filepath2))
return true;
}
}
return false;
}
void insert_mid(const MetaData& md, int pos) {
if(pos < 0)
pos = 0;
if(pos >= (int) size()) {
push_back(md);
return;
}
uint sz = size();
// copy last element
push_back(at(sz - 1));
sz++;
// s
for(uint j= sz-2; j>(uint) pos; j--){
at(j) = at(j-1);
}
// replace
at(pos) = md;
}
};
struct CustomPlaylist{
QString name;
qint32 id;
MetaDataList tracks;
qint32 length;
qint32 num_tracks;
bool is_valid;
CustomPlaylist(){
is_valid = false;
id = -1;
name = "";
length = 0;
num_tracks = 0;
}
};
struct LastTrack{
qint32 id;
QString filepath;
qint32 pos_sec;
bool valid;
LastTrack(){
id = -1;
filepath = "";
pos_sec = -1;
valid = false;
}
void reset(){
id = -1;
filepath = "";
pos_sec = -1;
valid = false;
}
QString toString(){
QString str;
str += QString::number(id) + ",";
str += filepath + ",";
str += QString::number(pos_sec);
return str;
}
static LastTrack fromString(QString str){
QStringList lst = str.split(",");
LastTrack tr;
if(lst.size() < 3) return tr;
tr.id = lst[0].toInt();
tr.filepath = lst[1];
bool ok;
tr.pos_sec = lst[2].toInt(&ok);
if(!ok && lst.size() > 3){
tr.pos_sec = lst[lst.size() - 1].toInt();
tr.filepath.clear();
for(int i=1; i<lst.size() - 1; i++){
tr.filepath += lst[i];
}
}
tr.valid = true;
return tr;
}
};
#endif /* METADATA_H_ */