diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 03d7e0f0b..0aa132a1e 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -129,6 +129,7 @@ set(updater_SRCS IF( APPLE ) list(APPEND client_SRCS cocoainitializer_mac.mm) list(APPEND client_SRCS settingsdialogmac.cpp) + list(REMOVE_ITEM client_SRCS settingsdialog.cpp) list(APPEND client_SRCS socketapisocket_mac.mm) list(APPEND client_SRCS systray.mm) diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index fc50dd120..d4b9c3eda 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -55,6 +55,8 @@ static const float buttonSizeRatio = 1.618; // golden ratio namespace OCC { +#include "settingsdialogcommon.cpp" + static QIcon circleMask(const QImage &avatar) { int dim = avatar.width(); @@ -236,7 +238,7 @@ void SettingsDialog::accountAdded(AccountState *s) if (!brandingSingleAccount) { accountAction->setToolTip(s->account()->displayName()); - accountAction->setIconText(shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio)); + accountAction->setIconText(SettingsDialogCommon::shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio)); } _toolBar->insertAction(_toolBar->actions().at(0), accountAction); auto accountSettings = new AccountSettings(s, this); @@ -278,32 +280,11 @@ void SettingsDialog::slotAccountDisplayNameChanged() QString displayName = account->displayName(); action->setText(displayName); auto height = _toolBar->sizeHint().height(); - action->setIconText(shortDisplayNameForSettings(account, height * buttonSizeRatio)); + action->setIconText(SettingsDialogCommon::shortDisplayNameForSettings(account, height * buttonSizeRatio)); } } } -QString SettingsDialog::shortDisplayNameForSettings(Account* account, int width) const -{ - QString user = account->davDisplayName(); - if (user.isEmpty()) { - user = account->credentials()->user(); - } - QString host = account->url().host(); - int port = account->url().port(); - if (port > 0 && port != 80 && port != 443) { - host.append(QLatin1Char(':')); - host.append(QString::number(port)); - } - if (width > 0) { - QFont f; - QFontMetrics fm(f); - host = fm.elidedText(host, Qt::ElideMiddle, width); - user = fm.elidedText(user, Qt::ElideRight, width); - } - return user + QLatin1String("\n") + host; -} - void SettingsDialog::accountRemoved(AccountState *s) { for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) { diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index 7c2ffcc03..60c72dec7 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -78,11 +78,6 @@ private: QAction *createColorAwareAction(const QString &iconName, const QString &fileName); QAction *createActionWithIcon(const QIcon &icon, const QString &text, const QString &iconPath = QString()); - /** display name with two lines that is displayed in the settings - * If width is bigger than 0, the string will be ellided so it does not exceed that width - */ - QString shortDisplayNameForSettings(Account* account, int width = 0) const; - Ui::SettingsDialog *const _ui; QActionGroup *_actionGroup; diff --git a/src/gui/settingsdialogcommon.cpp b/src/gui/settingsdialogcommon.cpp new file mode 100644 index 000000000..de6f820c8 --- /dev/null +++ b/src/gui/settingsdialogcommon.cpp @@ -0,0 +1,28 @@ +namespace SettingsDialogCommon +{ + +/** display name with two lines that is displayed in the settings + * If width is bigger than 0, the string will be ellided so it does not exceed that width + */ +QString shortDisplayNameForSettings(Account* account, int width) +{ + QString user = account->davDisplayName(); + if (user.isEmpty()) { + user = account->credentials()->user(); + } + QString host = account->url().host(); + int port = account->url().port(); + if (port > 0 && port != 80 && port != 443) { + host.append(QLatin1Char(':')); + host.append(QString::number(port)); + } + if (width > 0) { + QFont f; + QFontMetrics fm(f); + host = fm.elidedText(host, Qt::ElideMiddle, width); + user = fm.elidedText(user, Qt::ElideRight, width); + } + return user + QLatin1String("\n") + host; +} + +} \ No newline at end of file diff --git a/src/gui/settingsdialogmac.cpp b/src/gui/settingsdialogmac.cpp index db4fad95f..9124c8288 100644 --- a/src/gui/settingsdialogmac.cpp +++ b/src/gui/settingsdialogmac.cpp @@ -38,6 +38,9 @@ namespace OCC { +#include "settingsdialogcommon.cpp" + + // Duplicate in settingsdialog.cpp static QIcon circleMask(const QImage &avatar) { @@ -146,7 +149,7 @@ void SettingsDialogMac::accountAdded(AccountState *s) QIcon accountIcon = MacStandardIcon::icon(MacStandardIcon::UserAccounts); auto accountSettings = new AccountSettings(s, this); - QString displayName = Theme::instance()->multiAccount() ? s->shortDisplayNameForSettings() : tr("Account"); + QString displayName = Theme::instance()->multiAccount() ? SettingsDialogCommon::shortDisplayNameForSettings(s->account().data(), 0) : tr("Account"); insertPreferencesPanel(0, accountIcon, displayName, accountSettings);