1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 20:09:50 +01:00

Fix style, hide the new columns by default, and move the new columns to the end of the enum

This commit is contained in:
David Sansome 2013-03-10 17:58:09 +11:00
parent a6d3b48231
commit d89954ae31
6 changed files with 46 additions and 28 deletions

View File

@ -55,7 +55,10 @@ CREATE TABLE device_%deviceid_songs (
unavailable INTEGER DEFAULT 0,
effective_albumartist TEXT,
etag TEXT
etag TEXT,
performer TEXT,
grouping TEXT
);
CREATE INDEX idx_device_%deviceid_songs_album ON device_%deviceid_songs (album);
@ -63,7 +66,7 @@ CREATE INDEX idx_device_%deviceid_songs_album ON device_%deviceid_songs (album);
CREATE INDEX idx_device_%deviceid_songs_comp_artist ON device_%deviceid_songs (effective_compilation, artist);
CREATE VIRTUAL TABLE device_%deviceid_fts USING fts3(
ftstitle, ftsalbum, ftsartist, ftsalbumartist, ftscomposer, ftsgenre, ftscomment,
ftstitle, ftsalbum, ftsartist, ftsalbumartist, ftscomposer, ftsperformer, ftsgrouping, ftsgenre, ftscomment,
tokenize=unicode
);

View File

@ -500,8 +500,8 @@ void Database::UpdateDatabaseSchema(int version, QSqlDatabase &db) {
}
}
qLog(Debug) << "Applying database schema update" << version
<< "from" << filename;
ExecSchemaCommandsFromFile(db, filename, version - 1, &t);
<< "from" << filename;
ExecSchemaCommandsFromFile(db, filename, version - 1, true);
t.Commit();
} else {
qLog(Debug) << "Applying database schema update" << version
@ -533,22 +533,25 @@ void Database::UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db) {
}
void Database::ExecSchemaCommandsFromFile(QSqlDatabase& db,
QString const& filename,
const QString& filename,
int schema_version,
ScopedTransaction const* outerTransaction) {
bool in_transaction) {
// Open and read the database schema
QFile schema_file(filename);
if (!schema_file.open(QIODevice::ReadOnly))
qFatal("Couldn't open schema file %s", filename.toUtf8().constData());
ExecSchemaCommands(db, QString::fromUtf8(schema_file.readAll()), schema_version, outerTransaction);
ExecSchemaCommands(db,
QString::fromUtf8(schema_file.readAll()),
schema_version,
in_transaction);
}
void Database::ExecSchemaCommands(QSqlDatabase& db,
QString const& schema,
const QString& schema,
int schema_version,
ScopedTransaction const* outerTransaction) {
bool in_transaction) {
// Run each command
QStringList const schemaCommands(schema.split(";\n\n"));
const 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.
@ -556,26 +559,26 @@ void Database::ExecSchemaCommands(QSqlDatabase& db,
// be queried before beginning an inner transaction! Otherwise
// DROP TABLE commands on song tables may fail due to database
// locks.
QStringList const songTables(SongsTables(db, schema_version));
const QStringList song_tables(SongsTables(db, schema_version));
if (0 == outerTransaction) {
ScopedTransaction innerTransaction(&db);
ExecSongTablesCommands(db, songTables, schemaCommands);
innerTransaction.Commit();
if (!in_transaction) {
ScopedTransaction inner_transaction(&db);
ExecSongTablesCommands(db, song_tables, commands);
inner_transaction.Commit();
} else {
ExecSongTablesCommands(db, songTables, schemaCommands);
ExecSongTablesCommands(db, song_tables, commands);
}
}
void Database::ExecSongTablesCommands(QSqlDatabase& db,
QStringList const& songTables,
QStringList const& commands) {
foreach (QString const& command, commands) {
const QStringList& song_tables,
const QStringList& commands) {
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 (QString const& table, songTables) {
foreach (const QString& table, song_tables) {
qLog(Info) << "Updating" << table << "for" << kMagicAllSongsTables;
QString new_command(command);
new_command.replace(kMagicAllSongsTables, table);

View File

@ -38,7 +38,6 @@ struct sqlite3_tokenizer_module;
}
class Application;
class ScopedTransaction;
class Database : public QObject {
Q_OBJECT
@ -56,7 +55,10 @@ class Database : public QObject {
QMutex* Mutex() { return &mutex_; }
void RecreateAttachedDb(const QString& database_name);
void ExecSchemaCommands(QSqlDatabase &db, QString const& schema, int schema_version, ScopedTransaction const* outerTransaction = 0);
void ExecSchemaCommands(QSqlDatabase& db,
const QString& schema,
int schema_version,
bool in_transaction = false);
int startup_schema_version() const { return startup_schema_version_; }
int current_schema_version() const { return kSchemaVersion; }
@ -70,8 +72,13 @@ class Database : public QObject {
private:
void UpdateMainSchema(QSqlDatabase* db);
void ExecSchemaCommandsFromFile(QSqlDatabase &db, QString const& filename, int schema_version, ScopedTransaction const* outerTransaction = 0);
void ExecSongTablesCommands(QSqlDatabase &db, QStringList const& songTables, QStringList const& commands);
void ExecSchemaCommandsFromFile(QSqlDatabase& db,
const QString& filename,
int schema_version,
bool in_transaction = false);
void ExecSongTablesCommands(QSqlDatabase& db,
const QStringList& song_tables,
const QStringList& commands);
void UpdateDatabaseSchema(int version, QSqlDatabase& db);
void UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db);

View File

@ -90,7 +90,7 @@ int DeviceDatabaseBackend::AddDevice(const Device& device) {
QString schema = QString::fromUtf8(schema_file.readAll());
schema.replace("%deviceid", QString::number(id));
db_->ExecSchemaCommands(db, schema, 0, &t);
db_->ExecSchemaCommands(db, schema, 0, true);
t.Commit();
return id;

View File

@ -90,8 +90,6 @@ class Playlist : public QAbstractListModel {
Column_Album,
Column_AlbumArtist,
Column_Composer,
Column_Performer,
Column_Grouping,
Column_Length,
Column_Track,
Column_Disc,
@ -119,6 +117,9 @@ class Playlist : public QAbstractListModel {
Column_Source,
Column_Mood,
Column_Performer,
Column_Grouping,
ColumnCount
};

View File

@ -46,7 +46,7 @@
# include "moodbar/moodbaritemdelegate.h"
#endif
const int PlaylistView::kStateVersion = 5;
const int PlaylistView::kStateVersion = 6;
const int PlaylistView::kGlowIntensitySteps = 24;
const int PlaylistView::kAutoscrollGraceTimeout = 30; // seconds
const int PlaylistView::kDropIndicatorWidth = 2;
@ -324,6 +324,10 @@ void PlaylistView::LoadGeometry() {
if (state_version < 5) {
header_->HideSection(Playlist::Column_Mood);
}
if (state_version < 6) {
header_->HideSection(Playlist::Column_Performer);
header_->HideSection(Playlist::Column_Grouping);
}
// Make sure at least one column is visible
bool all_hidden = true;