Skip to content

Commit

Permalink
Show icon next to the status label in Account Settings page
Browse files Browse the repository at this point in the history
Fixes: #11811
  • Loading branch information
erikjv authored and TheOneRing committed Sep 23, 2024
1 parent 5adf731 commit 15ee2b7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
48 changes: 36 additions & 12 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void AccountSettings::slotDisableVfsCurrentFolder(Folder *folder)
msgBox->open();
}

void AccountSettings::showConnectionLabel(const QString &message, QStringList errors)
void AccountSettings::showConnectionLabel(const QString &message, StatusIcon statusIcon, QStringList errors)
{
if (errors.isEmpty()) {
ui->connectionStatusLabel->setText(message);
Expand All @@ -360,7 +360,29 @@ void AccountSettings::showConnectionLabel(const QString &message, QStringList er
ui->connectionStatusLabel->setToolTip(QString());
}
ui->accountStatus->setVisible(!message.isEmpty());
ui->warningLabel->setVisible(!errors.isEmpty());

QIcon icon;
switch (statusIcon) {
case StatusIcon::None:
break;
case StatusIcon::Connected:
icon = Resources::getCoreIcon(QStringLiteral("states/ok"));
break;
case StatusIcon::Disconnected:
icon = Resources::getCoreIcon(QStringLiteral("states/offline"));
break;
case StatusIcon::Info:
icon = Resources::getCoreIcon(QStringLiteral("states/information"));
break;
case StatusIcon::Warning:
icon = Resources::getCoreIcon(QStringLiteral("states/warning"));
break;
}

if (!icon.isNull()) {
ui->warningLabel->setPixmap(icon.pixmap(ui->warningLabel->size()));
}
ui->warningLabel->setVisible(statusIcon != StatusIcon::None);
}

void AccountSettings::slotEnableCurrentFolder(Folder *folder, bool terminate)
Expand Down Expand Up @@ -460,42 +482,44 @@ void AccountSettings::slotAccountStateChanged()
switch (state) {
case AccountState::Connected: {
QStringList errors;
StatusIcon icon = StatusIcon::Connected;
if (account->serverSupportLevel() != Account::ServerSupportLevel::Supported) {
errors << tr("The server version %1 is unsupported! Proceed at your own risk.").arg(account->capabilities().status().versionString());
icon = StatusIcon::Warning;
}
showConnectionLabel(tr("Connected"), errors);
showConnectionLabel(tr("Connected"), icon, errors);
break;
}
case AccountState::ServiceUnavailable:
showConnectionLabel(tr("Server is temporarily unavailable"));
showConnectionLabel(tr("Server is temporarily unavailable"), StatusIcon::Disconnected);
break;
case AccountState::MaintenanceMode:
showConnectionLabel(tr("Server is currently in maintenance mode"));
showConnectionLabel(tr("Server is currently in maintenance mode"), StatusIcon::Disconnected);
break;
case AccountState::SignedOut:
showConnectionLabel(tr("Signed out"));
showConnectionLabel(tr("Signed out"), StatusIcon::Disconnected);
break;
case AccountState::AskingCredentials: {
showConnectionLabel(tr("Updating credentials..."));
showConnectionLabel(tr("Updating credentials..."), StatusIcon::Info);
break;
}
case AccountState::Connecting:
if (NetworkInformation::instance()->isBehindCaptivePortal()) {
showConnectionLabel(tr("Captive portal prevents connections to the server."));
showConnectionLabel(tr("Captive portal prevents connections to the server."), StatusIcon::Disconnected);
} else if (NetworkInformation::instance()->isMetered() && ConfigFile().pauseSyncWhenMetered()) {
showConnectionLabel(tr("Sync is paused due to metered internet connection"));
showConnectionLabel(tr("Sync is paused due to metered internet connection"), StatusIcon::Disconnected);
} else {
showConnectionLabel(tr("Connecting..."));
showConnectionLabel(tr("Connecting..."), StatusIcon::Info);
}
break;
case AccountState::ConfigurationError:
showConnectionLabel(tr("Server configuration error"), _accountState->connectionErrors());
showConnectionLabel(tr("Server configuration error"), StatusIcon::Warning, _accountState->connectionErrors());
break;
case AccountState::NetworkError:
// don't display the error to the user, https://github.com/owncloud/client/issues/9790
[[fallthrough]];
case AccountState::Disconnected:
showConnectionLabel(tr("Disconnected"));
showConnectionLabel(tr("Disconnected"), StatusIcon::Disconnected);
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ protected Q_SLOTS:

private:
void showSelectiveSyncDialog(Folder *folder);
void showConnectionLabel(const QString &message,
QStringList errors = QStringList());

enum class StatusIcon { None, Connected, Disconnected, Info, Warning };
void showConnectionLabel(const QString &message, StatusIcon statusIcon, QStringList errors = QStringList());

bool event(QEvent *) override;
void doForceSyncCurrentFolder(Folder *selectedFolder);
Expand Down
18 changes: 8 additions & 10 deletions src/gui/accountsettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="pixmap">
<pixmap resource="../resources/client.qrc">:/client/resources/light/warning.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
Expand All @@ -66,7 +60,7 @@
<string notr="true">Connection Status</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
<enum>Qt::TextFormat::PlainText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down Expand Up @@ -98,6 +92,9 @@
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
Expand All @@ -122,6 +119,9 @@
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
Expand Down Expand Up @@ -155,8 +155,6 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/client.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

0 comments on commit 15ee2b7

Please sign in to comment.