From d4d2cf179f101e1418a6acf5fe13fe111e335720 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 20 Dec 2020 18:08:08 +0000 Subject: library: fixed warning git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9598 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/library/library.cpp | 60 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/General/library/library.cpp b/src/plugins/General/library/library.cpp index 14ff9ac7a..b1730e5f7 100644 --- a/src/plugins/General/library/library.cpp +++ b/src/plugins/General/library/library.cpp @@ -42,25 +42,19 @@ Library::Library(QObject *parent) : QObject(parent) { - QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", CONNECTION_NAME); - if(db.isValid() && !db.isOpen()) { - db.setDatabaseName(Qmmp::configDir() + "/" + "library.sqlite"); - db.open(); - if(createTables()) - { - QSqlQuery query(db); - query.exec("PRAGMA journal_mode = WAL"); - query.exec("PRAGMA synchronous = NORMAL"); - qDebug("Library: database initialization finished"); - } - else + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", CONNECTION_NAME); + if(db.isValid() && !db.isOpen()) { - qWarning("Library: plugin is disabled"); + db.setDatabaseName(Qmmp::configDir() + "/" + "library.sqlite"); + db.open(); + if(createTables()) + qDebug("Library: database initialization finished"); + else + qWarning("Library: plugin is disabled"); } - db.close(); - QSqlDatabase::removeDatabase(CONNECTION_NAME); } + QSqlDatabase::removeDatabase(CONNECTION_NAME); QSettings settings(Qmmp::configFile(), QSettings::IniFormat); m_dirs = settings.value("Library/dirs").toStringList(); @@ -103,7 +97,6 @@ void Library::startDirectoryScanning() m_filters = MetaDataManager::instance()->nameFilters(); m_future = QtConcurrent::run(this, &Library::scanDirectories, m_dirs); - } bool Library::createTables() @@ -123,8 +116,6 @@ bool Library::createTables() if(!ok) qWarning("Library: unable to create table, error: %s", qPrintable(query.lastError().text())); - removeInvalid(); - return ok; } @@ -207,21 +198,30 @@ bool Library::scanDirectories(const QStringList &paths) qDebug() << Q_FUNC_INFO << paths; m_stopped = false; - QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", CONNECTION_NAME); - db.setDatabaseName(Qmmp::configDir() + "/" + "library.sqlite"); - db.open(); - QSqlQuery query(db); - query.exec("PRAGMA journal_mode = WAL"); - query.exec("PRAGMA synchronous = NORMAL"); - - for(const QString &path : qAsConst(paths)) { - addDirectory(path); - if(m_stopped) - return false; + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", CONNECTION_NAME); + db.setDatabaseName(Qmmp::configDir() + "/" + "library.sqlite"); + db.open(); + + QSqlQuery query(db); + query.exec("PRAGMA journal_mode = WAL"); + query.exec("PRAGMA synchronous = NORMAL"); + + for(const QString &path : qAsConst(paths)) + { + addDirectory(path); + if(m_stopped) + { + db.close(); + QSqlDatabase::removeDatabase(CONNECTION_NAME); + return false; + } + } + + removeInvalid(); } - removeInvalid(); + QSqlDatabase::removeDatabase(CONNECTION_NAME); qDebug("Library: directory scan finished"); return true; -- cgit v1.2.3-13-gbd6f