Default to sqlite backend in core creation wizard
authorBen Rosser <rosser.bjr@gmail.com>
Mon, 19 Sep 2016 04:41:21 +0000 (00:41 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 13 Oct 2016 20:02:16 +0000 (22:02 +0200)
This introduces the notion of a "default" storage backend into
the core by adding a function (Core::isStorageBackendDefault),
which returns true if a given Storage object is 'default' and
false if not. This information is then added to the BackendInfo
dictionary passed through the protocol to the user interface,
which ensures the backend that is default will always be the
one displayed by default.

This change was prompted by conversation in IRC with [Saint]
and @digitalcircuit about making core creation slightly more
intuitive.

This allows us to, potentially, change the default storage
backend shown at core creation time should at some point
another backend be introduced, without having to modify
the interface.

It is a little weird having "isDefault" be an attribute of
*each* storage backend, but this was the simplest way to do
it without modifying the handshake. (Whichever is the last
storage backend to claim to be the default will win).

(As an aside, should this be merged and should #170 be merged
I'll implement something similar for authenticators in a
separate PR).

Resolves GH-250.

src/core/core.cpp
src/core/core.h
src/qtui/coreconfigwizard.cpp

index 0faf769..11db682 100644 (file)
@@ -669,6 +669,7 @@ QVariantList Core::backendInfo()
         v["Description"] = backend->description();
         v["SetupKeys"] = backend->setupKeys();
         v["SetupDefaults"] = backend->setupDefaults();
+        v["IsDefault"] = isStorageBackendDefault(backend);
         backends.append(v);
     }
     return backends;
index 2015f70..88b398a 100644 (file)
@@ -504,6 +504,19 @@ public:
 
     static QVariantList backendInfo();
 
+    /**
+     * Checks if a storage backend is the default storage backend. This
+     * hardcodes this information into the core (not the client).
+     *
+     * \param backend    The backend to check.
+     *
+     * @return True if storage backend is default, false otherwise.
+     */
+    static inline bool isStorageBackendDefault(const Storage *backend)
+    {
+        return (backend->displayName() == "SQLite") ? true : false;
+    }
+
     static QString setup(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData);
 
     static inline QTimer &syncTimer() { return instance()->_storageSyncTimer; }
index 63ac400..6873528 100644 (file)
@@ -201,10 +201,16 @@ StorageSelectionPage::StorageSelectionPage(const QHash<QString, QVariant> &backe
 
     registerField("storage.backend", ui.backendList);
 
+    int defaultIndex = 0;
     foreach(QString key, _backends.keys()) {
         ui.backendList->addItem(_backends[key].toMap()["DisplayName"].toString(), key);
+        if (_backends[key].toMap()["IsDefault"].toBool()) {
+            defaultIndex = ui.backendList->count() - 1;
+        }
     }
 
+    ui.backendList->setCurrentIndex(defaultIndex);
+
     on_backendList_currentIndexChanged();
 }