From 646890abb3e3268d806840dc77443d07143ae26e Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 5 Aug 2015 14:49:16 +0200 Subject: [PATCH] SettingsDialog: use the same short display name on Win/Linux than on Mac Issue #3516 --- src/gui/accountstate.cpp | 16 ++++++++++++++++ src/gui/accountstate.h | 3 +++ src/gui/settingsdialog.cpp | 11 +++++++---- src/gui/settingsdialogmac.cpp | 12 +----------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 2483576c5..e7006f38d 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -252,5 +252,21 @@ std::unique_ptr AccountState::settings() return s; } +QString AccountState::shortDisplayNameForSettings() const +{ + QString userWithoutMailHost = account()->credentials()->user(); + if (userWithoutMailHost.contains('@')) { + userWithoutMailHost = userWithoutMailHost.left(userWithoutMailHost.lastIndexOf('@')); + } + QString hostWithoutTld = account()->url().host(); + if (hostWithoutTld.contains('.')) { + hostWithoutTld = hostWithoutTld.left(hostWithoutTld.lastIndexOf('.')); + hostWithoutTld = hostWithoutTld.replace(QLatin1String("www."), QLatin1String("")); + } + + return userWithoutMailHost + QLatin1String("\n") + hostWithoutTld; +} + + } // namespace OCC diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index 36ee4adb7..d5412aa35 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -89,6 +89,9 @@ public: /** Returns a new settings object for this account, already in the right groups. */ std::unique_ptr settings(); + /** display name with two lines that is displayed in the settings */ + QString shortDisplayNameForSettings() const; + private: void setState(State state); diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index d79b57a87..ce57eeb50 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -76,20 +76,22 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) : spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); toolBar->addWidget(spacer); + // Note: all the actions have a '\n' because the account name is in two lines and + // all buttons must have the same size in order to keep a good layout QIcon protocolIcon(QLatin1String(":/client/resources/activity.png")); - _protocolAction = toolBar->addAction(protocolIcon, tr("Activity")); + _protocolAction = toolBar->addAction(protocolIcon, tr("Activity") + QLatin1Char('\n')); _protocolAction->setCheckable(true); ProtocolWidget *protocolWidget = new ProtocolWidget; _ui->stack->addWidget(protocolWidget); QIcon generalIcon(QLatin1String(":/client/resources/settings.png")); - QAction *generalAction = toolBar->addAction(generalIcon, tr("General")); + QAction *generalAction = toolBar->addAction(generalIcon, tr("General") + QLatin1Char('\n')); generalAction->setCheckable(true); GeneralSettings *generalSettings = new GeneralSettings; _ui->stack->addWidget(generalSettings); QIcon networkIcon(QLatin1String(":/client/resources/network.png")); - QAction *networkAction = toolBar->addAction(networkIcon, tr("Network")); + QAction *networkAction = toolBar->addAction(networkIcon, tr("Network") + QLatin1Char('\n')); networkAction->setCheckable(true); NetworkSettings *networkSettings = new NetworkSettings; _ui->stack->addWidget(networkSettings); @@ -163,7 +165,8 @@ void SettingsDialog::accountAdded(AccountState *s) QIcon accountIcon(QLatin1String(":/client/resources/account.png")); auto toolBar = qobject_cast(layout()->menuBar()); Q_ASSERT(toolBar); - auto accountAction = new QAction(accountIcon, s->account()->displayName(), this); + auto accountAction = new QAction(accountIcon, s->shortDisplayNameForSettings(), this); + accountAction->setToolTip(s->account()->displayName()); toolBar->insertAction(toolBar->actions().at(0), accountAction); accountAction->setCheckable(true); auto accountSettings = new AccountSettings(s, this); diff --git a/src/gui/settingsdialogmac.cpp b/src/gui/settingsdialogmac.cpp index 053e5a904..e7b95dcfe 100644 --- a/src/gui/settingsdialogmac.cpp +++ b/src/gui/settingsdialogmac.cpp @@ -114,17 +114,7 @@ void SettingsDialogMac::accountAdded(AccountState *s) QIcon accountIcon = MacStandardIcon::icon(MacStandardIcon::UserAccounts); auto accountSettings = new AccountSettings(s, this); - QString userWithoutMailHost = s->account()->credentials()->user(); - if (userWithoutMailHost.contains('@')) { - userWithoutMailHost = userWithoutMailHost.left(userWithoutMailHost.lastIndexOf('@')); - } - QString hostWithoutTld = s->account()->url().host(); - if (hostWithoutTld.contains('.')) { - hostWithoutTld = hostWithoutTld.left(hostWithoutTld.lastIndexOf('.')); - hostWithoutTld = hostWithoutTld.replace(QLatin1String("www."), QLatin1String("")); - } - - QString displayName = tr("%1\n%2").arg(userWithoutMailHost, hostWithoutTld); + QString displayName = s->shortDisplayNameForSettings(); insertPreferencesPanel(0, accountIcon, displayName, accountSettings);