mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-16 10:41:34 +03:00
SettingsDialog: Display the user avatar as action icon if available.
The avatar image is fetched from the server async, thus connect a signal from the account if the avatar changes. Server feature https://github.com/owncloud/core/pull/26872 is needed.
This commit is contained in:
parent
e05d6bfcdc
commit
d466a05915
2 changed files with 49 additions and 6 deletions
|
@ -196,8 +196,17 @@ void SettingsDialog::accountAdded(AccountState *s)
|
|||
|
||||
bool brandingSingleAccount = !Theme::instance()->multiAccount();
|
||||
|
||||
auto accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
|
||||
brandingSingleAccount ? tr("Account") : s->account()->displayName());
|
||||
QAction *accountAction;
|
||||
QPixmap avatar = s->account()->avatar();
|
||||
const QString actionText = brandingSingleAccount ? tr("Account") : s->account()->displayName();
|
||||
if(avatar.isNull()) {
|
||||
accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
|
||||
actionText);
|
||||
} else {
|
||||
QIcon icon(avatar);
|
||||
accountAction = createActionWithIcon(icon, actionText);
|
||||
}
|
||||
|
||||
if (!brandingSingleAccount) {
|
||||
accountAction->setToolTip(s->account()->displayName());
|
||||
accountAction->setIconText(s->shortDisplayNameForSettings(height * buttonSizeRatio));
|
||||
|
@ -207,14 +216,30 @@ void SettingsDialog::accountAdded(AccountState *s)
|
|||
_ui->stack->insertWidget(0 , accountSettings);
|
||||
_actionGroup->addAction(accountAction);
|
||||
_actionGroupWidgets.insert(accountAction, accountSettings);
|
||||
_actionForAccount.insert(s->account().data(), accountAction);
|
||||
|
||||
connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged()));
|
||||
connect( accountSettings, SIGNAL(openFolderAlias(const QString&)),
|
||||
_gui, SLOT(slotFolderOpenAction(QString)));
|
||||
connect(s->account().data(), SIGNAL(accountChangedAvatar()), SLOT(slotAccountAvatarChanged()));
|
||||
|
||||
slotRefreshActivity(s);
|
||||
}
|
||||
|
||||
void SettingsDialog::slotAccountAvatarChanged()
|
||||
{
|
||||
Account *account = static_cast<Account*>(sender());
|
||||
if( account && _actionForAccount.contains(account)) {
|
||||
QAction *action = _actionForAccount[account];
|
||||
if( action ) {
|
||||
QPixmap pix = account->avatar();
|
||||
if( !pix.isNull() ) {
|
||||
action->setIcon( QIcon(pix) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::accountRemoved(AccountState *s)
|
||||
{
|
||||
for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) {
|
||||
|
@ -236,6 +261,9 @@ void SettingsDialog::accountRemoved(AccountState *s)
|
|||
}
|
||||
}
|
||||
|
||||
if( _actionForAccount.contains(s->account().data()) ) {
|
||||
_actionForAccount.remove(s->account().data());
|
||||
}
|
||||
_activitySettings->slotRemoveAccount(s);
|
||||
|
||||
// Hide when the last account is deleted. We want to enter the same
|
||||
|
@ -306,14 +334,22 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
QAction *SettingsDialog::createActionWithIcon(const QIcon& icon, const QString& text, const QString& iconPath)
|
||||
{
|
||||
QAction *action = new ToolButtonAction(icon, text, this);
|
||||
action->setCheckable(true);
|
||||
if(!iconPath.isEmpty()) {
|
||||
action->setProperty("iconPath", iconPath);
|
||||
}
|
||||
return action;
|
||||
|
||||
}
|
||||
|
||||
QAction *SettingsDialog::createColorAwareAction(const QString &iconPath, const QString &text)
|
||||
{
|
||||
// all buttons must have the same size in order to keep a good layout
|
||||
QIcon coloredIcon = createColorAwareIcon(iconPath);
|
||||
QAction *action = new ToolButtonAction(coloredIcon, text, this);
|
||||
action->setCheckable(true);
|
||||
action->setProperty("iconPath", iconPath);
|
||||
return action;
|
||||
return createActionWithIcon(coloredIcon, text, iconPath);
|
||||
}
|
||||
|
||||
void SettingsDialog::slotRefreshActivity( AccountState* accountState )
|
||||
|
|
|
@ -58,6 +58,7 @@ public slots:
|
|||
void showActivityPage();
|
||||
void slotSwitchPage(QAction *action);
|
||||
void slotRefreshActivity(AccountState *accountState );
|
||||
void slotAccountAvatarChanged();
|
||||
|
||||
protected:
|
||||
void reject() Q_DECL_OVERRIDE;
|
||||
|
@ -73,12 +74,18 @@ private:
|
|||
|
||||
QIcon createColorAwareIcon(const QString &name);
|
||||
QAction *createColorAwareAction(const QString &iconName, const QString &fileName);
|
||||
QAction *createActionWithIcon(const QIcon& icon, const QString& text, const QString& iconPath = QString());
|
||||
|
||||
Ui::SettingsDialog * const _ui;
|
||||
|
||||
QActionGroup* _actionGroup;
|
||||
// Maps the actions from the action group to the corresponding widgets
|
||||
QHash<QAction*, QWidget*> _actionGroupWidgets;
|
||||
|
||||
// Maps the action in the dialog to their according account. Needed in
|
||||
// case the account avatar changes
|
||||
QHash<Account*, QAction*> _actionForAccount;
|
||||
|
||||
QToolBar* _toolBar;
|
||||
|
||||
ActivitySettings *_activitySettings;
|
||||
|
|
Loading…
Reference in a new issue