From: Ben Rosser Date: Mon, 19 Sep 2016 04:41:21 +0000 (-0400) Subject: Default to sqlite backend in core creation wizard X-Git-Tag: travis-deploy-test~347 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=3867471c05de4c463373c6c4d1c414871c14cdc8 Default to sqlite backend in core creation wizard 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. --- diff --git a/src/core/core.cpp b/src/core/core.cpp index 0faf7693..11db6827 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -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; diff --git a/src/core/core.h b/src/core/core.h index 2015f70a..88b398a2 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -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; } diff --git a/src/qtui/coreconfigwizard.cpp b/src/qtui/coreconfigwizard.cpp index 63ac4003..68735287 100644 --- a/src/qtui/coreconfigwizard.cpp +++ b/src/qtui/coreconfigwizard.cpp @@ -201,10 +201,16 @@ StorageSelectionPage::StorageSelectionPage(const QHash &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(); }