mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 06:25:56 +03:00
Settings Dialog: Fix display name compilation for macOS #6078
This commit is contained in:
parent
315e38e814
commit
cd07865da6
5 changed files with 37 additions and 29 deletions
|
@ -129,6 +129,7 @@ set(updater_SRCS
|
||||||
IF( APPLE )
|
IF( APPLE )
|
||||||
list(APPEND client_SRCS cocoainitializer_mac.mm)
|
list(APPEND client_SRCS cocoainitializer_mac.mm)
|
||||||
list(APPEND client_SRCS settingsdialogmac.cpp)
|
list(APPEND client_SRCS settingsdialogmac.cpp)
|
||||||
|
list(REMOVE_ITEM client_SRCS settingsdialog.cpp)
|
||||||
list(APPEND client_SRCS socketapisocket_mac.mm)
|
list(APPEND client_SRCS socketapisocket_mac.mm)
|
||||||
list(APPEND client_SRCS systray.mm)
|
list(APPEND client_SRCS systray.mm)
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,8 @@ static const float buttonSizeRatio = 1.618; // golden ratio
|
||||||
|
|
||||||
namespace OCC {
|
namespace OCC {
|
||||||
|
|
||||||
|
#include "settingsdialogcommon.cpp"
|
||||||
|
|
||||||
static QIcon circleMask(const QImage &avatar)
|
static QIcon circleMask(const QImage &avatar)
|
||||||
{
|
{
|
||||||
int dim = avatar.width();
|
int dim = avatar.width();
|
||||||
|
@ -236,7 +238,7 @@ void SettingsDialog::accountAdded(AccountState *s)
|
||||||
|
|
||||||
if (!brandingSingleAccount) {
|
if (!brandingSingleAccount) {
|
||||||
accountAction->setToolTip(s->account()->displayName());
|
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);
|
_toolBar->insertAction(_toolBar->actions().at(0), accountAction);
|
||||||
auto accountSettings = new AccountSettings(s, this);
|
auto accountSettings = new AccountSettings(s, this);
|
||||||
|
@ -278,32 +280,11 @@ void SettingsDialog::slotAccountDisplayNameChanged()
|
||||||
QString displayName = account->displayName();
|
QString displayName = account->displayName();
|
||||||
action->setText(displayName);
|
action->setText(displayName);
|
||||||
auto height = _toolBar->sizeHint().height();
|
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)
|
void SettingsDialog::accountRemoved(AccountState *s)
|
||||||
{
|
{
|
||||||
for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) {
|
for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) {
|
||||||
|
|
|
@ -78,11 +78,6 @@ private:
|
||||||
QAction *createColorAwareAction(const QString &iconName, const QString &fileName);
|
QAction *createColorAwareAction(const QString &iconName, const QString &fileName);
|
||||||
QAction *createActionWithIcon(const QIcon &icon, const QString &text, const QString &iconPath = QString());
|
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;
|
Ui::SettingsDialog *const _ui;
|
||||||
|
|
||||||
QActionGroup *_actionGroup;
|
QActionGroup *_actionGroup;
|
||||||
|
|
28
src/gui/settingsdialogcommon.cpp
Normal file
28
src/gui/settingsdialogcommon.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -38,6 +38,9 @@
|
||||||
|
|
||||||
namespace OCC {
|
namespace OCC {
|
||||||
|
|
||||||
|
#include "settingsdialogcommon.cpp"
|
||||||
|
|
||||||
|
|
||||||
// Duplicate in settingsdialog.cpp
|
// Duplicate in settingsdialog.cpp
|
||||||
static QIcon circleMask(const QImage &avatar)
|
static QIcon circleMask(const QImage &avatar)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +149,7 @@ void SettingsDialogMac::accountAdded(AccountState *s)
|
||||||
QIcon accountIcon = MacStandardIcon::icon(MacStandardIcon::UserAccounts);
|
QIcon accountIcon = MacStandardIcon::icon(MacStandardIcon::UserAccounts);
|
||||||
auto accountSettings = new AccountSettings(s, this);
|
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);
|
insertPreferencesPanel(0, accountIcon, displayName, accountSettings);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue