diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 925669321..76314128a 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -18,6 +18,7 @@ #include #include +#include namespace OCC { @@ -252,24 +253,17 @@ std::unique_ptr AccountState::settings() return s; } -QString AccountState::shortDisplayNameForSettings() const +QString AccountState::shortDisplayNameForSettings(int width) const { - QString userWithoutMailHost = account()->credentials()->user(); - if (userWithoutMailHost.contains('@')) { - userWithoutMailHost = userWithoutMailHost.left(userWithoutMailHost.lastIndexOf('@')); + QString user = account()->credentials()->user(); + QString host = account()->url().host(); + if (width > 0) { + QFont f; + QFontMetrics fm(f); + host = fm.elidedText(host, Qt::ElideRight, width); + user = fm.elidedText(user, Qt::ElideRight, width); } - QString hostWithoutTld = account()->url().host(); - if (hostWithoutTld.contains('.') && !hostWithoutTld.at(0).isDigit()) { - hostWithoutTld = hostWithoutTld.left(hostWithoutTld.lastIndexOf('.')); - hostWithoutTld = hostWithoutTld.replace(QLatin1String("www."), QLatin1String("")); - hostWithoutTld = hostWithoutTld.replace(QLatin1String("cloud."), QLatin1String("")); - hostWithoutTld = hostWithoutTld.replace(QLatin1String("sync."), QLatin1String("")); - hostWithoutTld = hostWithoutTld.replace(QLatin1String("drive."), QLatin1String("")); - hostWithoutTld = hostWithoutTld.replace(QLatin1String("share."), QLatin1String("")); - hostWithoutTld = hostWithoutTld.replace(QLatin1String("web."), QLatin1String("")); - } - - return userWithoutMailHost + QLatin1String("\n") + hostWithoutTld; + return user + QLatin1String("\n") + host; } diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h index d5412aa35..f56364e10 100644 --- a/src/gui/accountstate.h +++ b/src/gui/accountstate.h @@ -89,8 +89,10 @@ 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; + /** 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(int width = 0) const; private: void setState(State state); diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index a87e3b538..d798bd8a4 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -42,7 +42,7 @@ namespace { const char TOOLBAR_CSS[] = "QToolBar { background: %1; margin: 0; padding: 0; border: none; border-bottom: 1px solid %2; spacing: 0; } " - "QToolBar QToolButton { background: %1; border: none; border-bottom: 1px solid %2; margin: 0; padding: 0; } " + "QToolBar QToolButton { background: %1; border: none; border-bottom: 1px solid %2; margin: 0; padding: 5px; } " "QToolBar QToolButton:checked { background: %3; color: %4; }"; } @@ -69,12 +69,9 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) : connect(closeWindowAction, SIGNAL(triggered()), SLOT(accept())); addAction(closeWindowAction); - setObjectName("Settings"); // required as group for saveGeometry call setWindowTitle(Theme::instance()->appNameGUI()); - // Add a spacer so config buttons are right aligned and account buttons will be left aligned - _seperatorAction = _toolBar->addSeparator(); _actionGroup = new QActionGroup(this); _actionGroup->setExclusive(true); @@ -191,14 +188,16 @@ void SettingsDialog::showActivityPage() void SettingsDialog::accountAdded(AccountState *s) { + auto height = _toolBar->sizeHint().height(); auto accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"), - s->shortDisplayNameForSettings()); + s->shortDisplayNameForSettings(height * 1.618)); // Golden ratio accountAction->setToolTip(s->account()->displayName()); QToolButton* accountButton = new QToolButton; - accountButton->setDefaultAction(accountAction); accountButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + accountButton->setDefaultAction(accountAction); accountButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + accountButton->setMinimumWidth(height * 1.3); QAction* toolbarAction = _toolBar->insertWidget(_toolBar->actions().at(0), accountButton); _toolbarAccountActions.insert(accountAction, toolbarAction); @@ -211,8 +210,6 @@ void SettingsDialog::accountAdded(AccountState *s) connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged())); connect( accountSettings, SIGNAL(openFolderAlias(const QString&)), _gui, SLOT(slotFolderOpenAction(QString))); - - _seperatorAction->setVisible(!_toolbarAccountActions.isEmpty()); } void SettingsDialog::accountRemoved(AccountState *s) @@ -232,8 +229,6 @@ void SettingsDialog::accountRemoved(AccountState *s) break; } } - - _seperatorAction->setVisible(!_toolbarAccountActions.isEmpty()); } void SettingsDialog::customizeStyle() @@ -284,6 +279,7 @@ void SettingsDialog::addActionToToolBar(QAction *action) { btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); _toolBar->addWidget(btn); + btn->setMinimumWidth(_toolBar->sizeHint().height() * 1.3); } } // namespace OCC diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index f6a219826..3b8e0c651 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -79,7 +79,6 @@ private: // Maps the actions from the action group to the toolbar actions QHash _toolbarAccountActions; - QAction * _seperatorAction; QAction * _protocolAction; ownCloudGui *_gui; };