modernize: Prefer default member init over ctor init
[quassel.git] / src / core / abstractsqlstorage.cpp
index fce1bb1..10c0f50 100644 (file)
@@ -19,9 +19,6 @@
  ***************************************************************************/
 
 #include "abstractsqlstorage.h"
-#include "quassel.h"
-
-#include "logger.h"
 
 #include <QMutexLocker>
 #include <QSqlDriver>
 #include <QSqlField>
 #include <QSqlQuery>
 
+#include "logmessage.h"
+#include "quassel.h"
+
 int AbstractSqlStorage::_nextConnectionId = 0;
 AbstractSqlStorage::AbstractSqlStorage(QObject *parent)
-    : Storage(parent),
-    _schemaVersion(0)
+    : Storage(parent)
 {
 }
 
@@ -43,7 +42,7 @@ AbstractSqlStorage::~AbstractSqlStorage()
     QHash<QThread *, Connection *>::iterator conIter;
     for (conIter = _connectionPool.begin(); conIter != _connectionPool.end(); ++conIter) {
         QSqlDatabase::removeDatabase(conIter.value()->name());
-        disconnect(conIter.value(), 0, this, 0);
+        disconnect(conIter.value(), nullptr, this, nullptr);
     }
 }
 
@@ -139,20 +138,19 @@ Storage::State AbstractSqlStorage::init(const QVariantMap &settings,
     }
 
     if (installedSchemaVersion() < schemaVersion()) {
-        qWarning() << qPrintable(tr("Installed Schema (version %1) is not up to date. Upgrading to "
-                                    "version %2...  This may take a while for major upgrades."
-                                    ).arg(installedSchemaVersion()).arg(schemaVersion()));
-        // TODO: The monolithic client won't show this message unless one looks into the debug log.
-        // This should be made more friendly, e.g. a popup message in the GUI.
-        if (!upgradeDb()) {
+        quInfo() << qPrintable(tr("Installed database schema (version %1) is not up to date. Upgrading to "
+                                  "version %2...  This may take a while for major upgrades."
+                                 ).arg(installedSchemaVersion()).arg(schemaVersion()));
+        emit dbUpgradeInProgress(true);
+        auto upgradeResult = upgradeDb();
+        emit dbUpgradeInProgress(false);
+        if (!upgradeResult) {
             qWarning() << qPrintable(tr("Upgrade failed..."));
             return NotAvailable;
         }
-        // Warning messages are also sent to the console, while Info messages aren't.  Add a message
-        // when migration succeeds to avoid confusing folks by implying the schema upgrade failed if
+        // Add a message when migration succeeds to avoid confusing folks by implying the schema upgrade failed if
         // later functionality does not work.
-        qWarning() << qPrintable(tr("Installed Schema successfully upgraded to version %1."
-                                    ).arg(schemaVersion()));
+        quInfo() << qPrintable(tr("Installed database schema successfully upgraded to version %1.").arg(schemaVersion()));
     }
 
     quInfo() << qPrintable(displayName()) << "storage backend is ready. Schema version:" << installedSchemaVersion();
@@ -403,7 +401,6 @@ AbstractSqlStorage::Connection::~Connection()
 //  AbstractSqlMigrator
 // ========================================
 AbstractSqlMigrator::AbstractSqlMigrator()
-    : _query(0)
 {
 }
 
@@ -419,7 +416,7 @@ void AbstractSqlMigrator::newQuery(const QString &query, QSqlDatabase db)
 void AbstractSqlMigrator::resetQuery()
 {
     delete _query;
-    _query = 0;
+    _query = nullptr;
 }
 
 
@@ -490,8 +487,7 @@ void AbstractSqlMigrator::dumpStatus()
 //  AbstractSqlMigrationReader
 // ========================================
 AbstractSqlMigrationReader::AbstractSqlMigrationReader()
-    : AbstractSqlMigrator(),
-    _writer(0)
+    : AbstractSqlMigrator()
 {
 }
 
@@ -575,7 +571,7 @@ void AbstractSqlMigrationReader::abortMigration(const QString &errorMsg)
 
     rollback();
     _writer->rollback();
-    _writer = 0;
+    _writer = nullptr;
 }
 
 
@@ -586,10 +582,10 @@ bool AbstractSqlMigrationReader::finalizeMigration()
 
     commit();
     if (!_writer->commit()) {
-        _writer = 0;
+        _writer = nullptr;
         return false;
     }
-    _writer = 0;
+    _writer = nullptr;
     return true;
 }