AccountSettings: Use switch, case to ensure we handle all cases
authorHannah von Reth <hannah.vonreth@owncloud.com>
Tue, 20 Aug 2019 15:28:19 +0000 (17:28 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:55 +0000 (10:58 +0100)
src/gui/accountsettings.cpp

index d553f45e12472ecfc40b5d252da7a00f7a34fe91..6618e9593963f4e385c047050233d560a947418f 100644 (file)
@@ -931,8 +931,8 @@ void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)
 
 void AccountSettings::slotAccountStateChanged()
 {
-    int state = _accountState ? _accountState->state() : AccountState::Disconnected;
-    if (_accountState) {
+    const AccountState::State state = _accountState ? _accountState->state() : AccountState::Disconnected;
+    if (state != AccountState::Disconnected) {
         _ui->sslButton->updateAccountState(_accountState);
         AccountPtr account = _accountState->account();
         QUrl safeUrl(account->url());
@@ -942,9 +942,9 @@ void AccountSettings::slotAccountStateChanged()
             _model->slotUpdateFolderState(folder);
         }
 
-        QString server = QString::fromLatin1("<a href=\"%1\">%2</a>")
-                             .arg(Utility::escape(account->url().toString()),
-                                 Utility::escape(safeUrl.toString()));
+        const QString server = QString::fromLatin1("<a href=\"%1\">%2</a>")
+                                   .arg(Utility::escape(account->url().toString()),
+                                       Utility::escape(safeUrl.toString()));
         QString serverWithUser = server;
         if (AbstractCredentials *cred = account->credentials()) {
             QString user = account->davDisplayName();
@@ -954,19 +954,25 @@ void AccountSettings::slotAccountStateChanged()
             serverWithUser = tr("%1 as <i>%2</i>").arg(server, Utility::escape(user));
         }
 
-        if (state == AccountState::Connected) {
+        switch (state) {
+        case AccountState::Connected: {
             QStringList errors;
             if (account->serverVersionUnsupported()) {
                 errors << tr("The server version %1 is unsupported! Proceed at your own risk.").arg(account->serverVersion());
             }
             showConnectionLabel(tr("Connected to %1.").arg(serverWithUser), errors);
-        } else if (state == AccountState::ServiceUnavailable) {
+            break;
+        }
+        case AccountState::ServiceUnavailable:
             showConnectionLabel(tr("Server %1 is temporarily unavailable.").arg(server));
-        } else if (state == AccountState::MaintenanceMode) {
+            break;
+        case AccountState::MaintenanceMode:
             showConnectionLabel(tr("Server %1 is currently in maintenance mode.").arg(server));
-        } else if (state == AccountState::SignedOut) {
+            break;
+        case AccountState::SignedOut:
             showConnectionLabel(tr("Signed out from %1.").arg(serverWithUser));
-        } else if (state == AccountState::AskingCredentials) {
+            break;
+        case AccountState::AskingCredentials: {
             QUrl url;
             if (auto cred = qobject_cast<HttpCredentialsGui *>(account->credentials())) {
                 connect(cred, &HttpCredentialsGui::authorisationLinkChanged,
@@ -980,10 +986,22 @@ void AccountSettings::slotAccountStateChanged()
             } else {
                 showConnectionLabel(tr("Connecting to %1 …").arg(serverWithUser));
             }
-        } else {
+            break;
+        }
+        case AccountState::NetworkError:
             showConnectionLabel(tr("No connection to %1 at %2.")
                                     .arg(Utility::escape(Theme::instance()->appNameGUI()), server),
                 _accountState->connectionErrors());
+            break;
+        case AccountState::ConfigurationError:
+            showConnectionLabel(tr("Server configuration error: %1 at %2.")
+                                    .arg(Utility::escape(Theme::instance()->appNameGUI()), server),
+                _accountState->connectionErrors());
+            break;
+        case AccountState::Disconnected:
+            // we can't end up here as the whole block is ifdeffed
+            Q_UNREACHABLE();
+            break;
         }
     } else {
         // ownCloud is not yet configured.