From bb79a68be0aa1036790647e8f8764d1f066f5cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bara?= Date: Tue, 4 Jan 2011 17:12:29 +0000 Subject: [PATCH] some minor .cue related changes --- src/core/database.cpp | 7 +++- src/core/song.cpp | 53 +++++++++++++++---------------- src/playlistparsers/cueparser.cpp | 5 +-- src/playlistparsers/cueparser.h | 3 ++ 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/core/database.cpp b/src/core/database.cpp index 058d0fb14..9f5981004 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -513,12 +513,17 @@ void Database::ExecFromFile(const QString &filename, QSqlDatabase &db) { void Database::ExecCommands(const QString &schema, QSqlDatabase &db) { // Run each command QStringList commands(schema.split(";\n\n")); + + // We don't want this list to reflect possible DB schema changes + // so we initialize it before executing any statements. + QStringList tables = SongsTables(db); + foreach (const QString& command, commands) { // There are now lots of "songs" tables that need to have the same schema: // songs, magnatune_songs, and device_*_songs. We allow a magic value // in the schema files to update all songs tables at once. if (command.contains(kMagicAllSongsTables)) { - foreach (const QString& table, SongsTables(db)) { + foreach (const QString& table, tables) { qDebug() << "Updating" << table << "for" << kMagicAllSongsTables; QString new_command(command); new_command.replace(kMagicAllSongsTables, table); diff --git a/src/core/song.cpp b/src/core/song.cpp index ffe22c6ca..595e6c567 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -89,11 +89,11 @@ static QStringList Updateify(const QStringList& list) { const QStringList Song::kColumns = QStringList() << "title" << "album" << "artist" << "albumartist" << "composer" << "track" << "disc" << "bpm" << "year" << "genre" << "comment" << "compilation" - << "length" << "bitrate" << "samplerate" << "directory" << "filename" + << "bitrate" << "samplerate" << "directory" << "filename" << "mtime" << "ctime" << "filesize" << "sampler" << "art_automatic" << "art_manual" << "filetype" << "playcount" << "lastplayed" << "rating" << "forced_compilation_on" << "forced_compilation_off" - << "effective_compilation" << "skipcount" << "score" << "beginning"; + << "effective_compilation" << "skipcount" << "score" << "beginning" << "length"; const QString Song::kColumnSpec = Song::kColumns.join(", "); const QString Song::kBindSpec = Prepend(":", Song::kColumns).join(", "); @@ -470,37 +470,38 @@ void Song::InitFromQuery(const SqlRow& q, int col) { d->comment_ = tostr(col + 11); d->compilation_ = q.value(col + 12).toBool(); - d->bitrate_ = toint(col + 14); - d->samplerate_ = toint(col + 15); + d->bitrate_ = toint(col + 13); + d->samplerate_ = toint(col + 14); - d->directory_id_ = toint(col + 16); - d->filename_ = tostr(col + 17); + d->directory_id_ = toint(col + 15); + d->filename_ = tostr(col + 16); d->basefilename_ = QFileInfo(d->filename_).fileName(); - d->mtime_ = toint(col + 18); - d->ctime_ = toint(col + 19); - d->filesize_ = toint(col + 20); + d->mtime_ = toint(col + 17); + d->ctime_ = toint(col + 18); + d->filesize_ = toint(col + 19); - d->sampler_ = q.value(col + 21).toBool(); + d->sampler_ = q.value(col + 20).toBool(); - d->art_automatic_ = q.value(col + 22).toString(); - d->art_manual_ = q.value(col + 23).toString(); + d->art_automatic_ = q.value(col + 21).toString(); + d->art_manual_ = q.value(col + 22).toString(); - d->filetype_ = FileType(q.value(col + 24).toInt()); - d->playcount_ = q.value(col + 25).isNull() ? 0 : q.value(col + 25).toInt(); - d->lastplayed_ = toint(col + 26); - d->rating_ = tofloat(col + 27); + d->filetype_ = FileType(q.value(col + 23).toInt()); + d->playcount_ = q.value(col + 24).isNull() ? 0 : q.value(col + 24).toInt(); + d->lastplayed_ = toint(col + 25); + d->rating_ = tofloat(col + 26); - d->forced_compilation_on_ = q.value(col + 28).toBool(); - d->forced_compilation_off_ = q.value(col + 29).toBool(); + d->forced_compilation_on_ = q.value(col + 27).toBool(); + d->forced_compilation_off_ = q.value(col + 28).toBool(); - // effective_compilation = 30 + // effective_compilation = 29 - d->skipcount_ = q.value(col + 31).isNull() ? 0 : q.value(col + 31).toInt(); - d->score_ = q.value(col + 32).isNull() ? 0 : q.value(col + 32).toInt(); + d->skipcount_ = q.value(col + 30).isNull() ? 0 : q.value(col + 30).toInt(); + d->score_ = q.value(col + 31).isNull() ? 0 : q.value(col + 31).toInt(); - // TODO: 'end' instead of 'length' - d->beginning_ = q.value(col + 33).isNull() ? 0 : q.value(col + 33).toInt(); - set_length(toint(col + 13)); + // do not move those statements - beginning must be initialized before + // length is! + d->beginning_ = q.value(col + 32).isNull() ? 0 : q.value(col + 32).toInt(); + set_length(toint(col + 33)); #undef tostr #undef toint @@ -931,8 +932,6 @@ void Song::BindToQuery(QSqlQuery *query) const { query->bindValue(":comment", strval(d->comment_)); query->bindValue(":compilation", d->compilation_ ? 1 : 0); - // TODO: replace this with 'end' - query->bindValue(":length", intval(length())); query->bindValue(":bitrate", intval(d->bitrate_)); query->bindValue(":samplerate", intval(d->samplerate_)); @@ -960,6 +959,7 @@ void Song::BindToQuery(QSqlQuery *query) const { query->bindValue(":score", d->score_); query->bindValue(":beginning", d->beginning_); + query->bindValue(":length", intval(length())); #undef intval #undef notnullintval @@ -1049,7 +1049,6 @@ bool Song::IsMetadataEqual(const Song& other) const { d->comment_ == other.d->comment_ && d->compilation_ == other.d->compilation_ && d->beginning_ == other.d->beginning_ && - // this should be replaced by 'end' length() == other.length() && d->bitrate_ == other.d->bitrate_ && d->samplerate_ == other.d->samplerate_ && diff --git a/src/playlistparsers/cueparser.cpp b/src/playlistparsers/cueparser.cpp index cebe09ad2..d22f79828 100644 --- a/src/playlistparsers/cueparser.cpp +++ b/src/playlistparsers/cueparser.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -33,8 +34,6 @@ const char* CueParser::kTrack = "track"; const char* CueParser::kIndex = "index"; const char* CueParser::kAudioTrackType = "audio"; -// TODO: utf and regexps (check on Zucchero - there's something wrong) - CueParser::CueParser(LibraryBackendInterface* library, QObject* parent) : ParserBase(library, parent) { @@ -44,6 +43,8 @@ SongList CueParser::Load(QIODevice* device, const QDir& dir) const { SongList ret; QTextStream text_stream(device); + text_stream.setCodec(QTextCodec::codecForUtfText(device->peek(1024), QTextCodec::codecForName("UTF-8"))); + QString dir_path = dir.absolutePath(); QString line; diff --git a/src/playlistparsers/cueparser.h b/src/playlistparsers/cueparser.h index 9569f07ae..d933a8069 100644 --- a/src/playlistparsers/cueparser.h +++ b/src/playlistparsers/cueparser.h @@ -22,6 +22,9 @@ #include +// This parser will try to detect the real encoding of a .cue file but there's +// a great chance it will fail so it's probably best to assume that the parser +// is UTF compatible only. class CueParser : public ParserBase { Q_OBJECT