--- a/HelperStructs/MetaData.h
+++ b/HelperStructs/MetaData.h
@@ -15,106 +15,60 @@
* 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 <QDebug>
#include <QVariant>
#include <QFile>
#include <QDataStream>
-#include "HelperStructs/globals.h"
-
-
struct MetaData {
- qint32 id;
- qint32 album_id;
- qint32 artist_id;
+ qint32 id{-1};
+ qint32 album_id{-1};
+ qint32 artist_id{-1};
QString title;
QString artist;
QString album;
QStringList genres;
- qint32 rating;
- qint64 length_ms;
- qint32 year;
+ qint32 rating{0};
+ qint64 length_ms{0};
+ qint32 year{0};
QString filepath;
- qint32 track_num;
- qint32 bitrate;
- qint64 filesize;
+ qint32 track_num{0};
+ qint32 bitrate{0};
+ qint64 filesize{0};
QString comment;
- int discnumber;
- int n_discs;
-
- bool is_extern;
-
- bool pl_selected;
- bool pl_playing;
- bool pl_dragged;
-
- bool unused1;
- bool is_disabled;
+ int discnumber{0};
+ int n_discs{-1};
+
+ bool is_extern{false};
+
+ bool pl_selected{false};
+ bool pl_playing{false};
+ bool pl_dragged{false};
+
+ bool unused1{false};
+ bool is_disabled{false};
QString didl;
QString albumArtURI;
///// The following are not saved on disk as part of a saved playlist.///
// While playing in avt + shuffle mode: remember what we already played
- bool shuffle_played;
-
- 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;
- filesize = 0;
- comment = "";
- discnumber = 0;
- n_discs = -1;
-
- pl_selected = false;
- pl_playing = false;
- pl_dragged = false;
-
- unused1 = false;
- is_disabled = false;
-
- didl = "";
-
- shuffle_played = false;
- }
-
- void print() const {
-
- qDebug() << title
- << " by " << artist
- << " from " << album
- << " (" << length_ms << " m_sec) :: " << filepath;
- }
+ bool shuffle_played{false};
+
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("");
@@ -148,7 +102,7 @@
return list;
}
- static bool fromVariant(QVariant v, MetaData& md){
+ static bool fromVariant(QVariant v, MetaData& md) {
QStringList list = v.toStringList();
@@ -182,7 +136,7 @@
return true;
}
- bool compare(const MetaData& other) {
+ bool compare(const MetaData& other) const {
bool same = title == other.title &&
artist == other.artist &&
album == other.album &&
@@ -204,14 +158,13 @@
pl_playing == other.pl_playing &&
pl_selected == other.pl_selected &&
pl_dragged == other.pl_dragged &&
- unused1 == other.unused1 &&
is_disabled == other.is_disabled &&
didl == other.didl &&
albumArtURI == other.albumArtURI;
return !same;
}
- bool serialize(QDataStream& strm) {
+ bool serialize(QDataStream& strm) const {
strm <<
title <<
artist <<
@@ -240,6 +193,7 @@
albumArtURI;
return true;
}
+
bool unSerialize(QDataStream& strm) {
strm >>
title >>
@@ -269,49 +223,28 @@
albumArtURI;
return strm.status() == QDataStream::Ok;
}
-
};
-class MetaDataList : public vector<MetaData> {
-
+class MetaDataList : public std::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;
- else
- at(i).pl_playing = false;
+ for (unsigned int i = 0; i < size(); i++) {
+ at(i).pl_playing = false;
}
+ if (idx >= 0 && idx < int(size()))
+ at(idx).pl_playing = true;
}
bool contains(const MetaData& md, bool cs=false, MetaData **found = 0) {
- if(cs) {
- QString filepath = md.filepath.trimmed();
-
- for(uint i = 0; i < size(); i++){
- QString filepath2 = at(i).filepath.trimmed();
- if(!filepath.compare(filepath2)) {
- if (found)
- *found = &(at(i));
- return true;
- }
- }
- } else {
- QString filepath = md.filepath.toLower().trimmed();
-
- for (uint i = 0; i < size(); i++){
- QString filepath2 = at(i).filepath.toLower().trimmed();
- if(!filepath.compare(filepath2)) {
- if (found)
- *found = &(at(i));
- return true;
- }
+ QString filepath = cs ? md.filepath.trimmed() :
+ md.filepath.toLower().trimmed();
+ for(unsigned int i = 0; i < size(); i++) {
+ QString filepath2 = cs ? at(i).filepath.trimmed() :
+ at(i).filepath.toLower().trimmed();
+ if(!filepath.compare(filepath2)) {
+ if (found)
+ *found = &(at(i));
+ return true;
}
}
return false;