Skip to content

Commit b888f90

Browse files
committed
added the alias editor action
it pops a dialog to enter the new alias.
1 parent db758a5 commit b888f90

5 files changed

Lines changed: 39 additions & 9 deletions

File tree

src/gui/accountsgui/accountsguicontroller.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ void AccountsGuiController::onAccountAdded(AccountState *state)
8989
_actionForAccount.insert(accountId, accountAction);
9090

9191
accountAction->setIcon(account->avatar());
92-
// eventually make this elided
93-
// problem is, the action has no idea what the size of the button should be.
94-
// it's really dumb to have "long" text on any toolbar component in the first place. We hope to fix this someday
95-
// by allowing the user to set an account alias which will show as the account name but that needs a major release
96-
// to support the config change
92+
9793
accountAction->setText(account->accountAlias());
94+
connect(account, &Account::accountAliasChanged, accountAction, [accountAction](const QString &newAlias) { accountAction->setText(newAlias); });
9895

9996
accountAction->setToolTip(QString("%1\n%2").arg(account->davDisplayName(), account->url().toDisplayString()));
10097
accountAction->setData(QVariant::fromValue(accountView));

src/gui/accountsgui/accountviewcontroller.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "libsync/theme.h"
2727

2828
#include <QDesktopServices>
29+
#include <QInputDialog>
2930
#include <QMenu>
3031
#include <QMessageBox>
3132
#include <QPushButton>
@@ -110,6 +111,11 @@ void AccountViewController::buildManageAccountMenu()
110111
connect(_remove, &QAction::triggered, this, &AccountViewController::onDeleteAccount);
111112
actions.push_back(_remove);
112113

114+
_rename = new QAction(tr("Change alias..."));
115+
_rename->setObjectName("changeAliasAction");
116+
connect(_rename, &QAction::triggered, this, &AccountViewController::onChangeAlias);
117+
actions.push_back(_rename);
118+
113119
_view->setAccountMenuActions(actions);
114120
}
115121

@@ -123,6 +129,7 @@ void AccountViewController::refreshAccountActions()
123129
_reconnect->setEnabled(false);
124130
_showInBrowser->setEnabled(false);
125131
_remove->setEnabled(false);
132+
_rename->setEnabled(false);
126133
return;
127134
}
128135

@@ -187,6 +194,28 @@ void AccountViewController::onDeleteAccount()
187194
messageBox->open();
188195
}
189196

197+
void AccountViewController::onChangeAlias()
198+
{
199+
if (!_accountState || !_accountState->account())
200+
return;
201+
202+
203+
// naturally this thing is STUPIDLY TINY by default so using the convenience method is out:
204+
// QString newAlias = QInputDialog::getText(_view, tr("Change alias"), tr("Account alias:"), QLineEdit::Normal, _accountState->account()->accountAlias());
205+
206+
QInputDialog dialog(_view);
207+
dialog.setWindowTitle(tr("Change alias"));
208+
dialog.setInputMode(QInputDialog::TextInput);
209+
dialog.setLabelText(tr("Account alias:"));
210+
dialog.setTextValue(_accountState->account()->accountAlias());
211+
QSize minHint = dialog.minimumSizeHint(); // width is 192?
212+
dialog.resize(minHint.width() * 2, minHint.height());
213+
214+
int res = dialog.exec();
215+
if (res == QDialog::Accepted && !dialog.textValue().isEmpty())
216+
_accountState->account()->setAccountAlias(dialog.textValue());
217+
}
218+
190219
QIcon AccountViewController::lookupStatusIcon(StatusIcon status)
191220
{
192221
QIcon icon;
@@ -208,6 +237,7 @@ QIcon AccountViewController::lookupStatusIcon(StatusIcon status)
208237
}
209238
return icon;
210239
}
240+
211241
void AccountViewController::onAccountStateChanged(AccountState::State state)
212242
{
213243
if (!_accountState || !_accountState->account() || !_view) {

src/gui/accountsgui/accountviewcontroller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AccountViewController : public QObject
4949
void onDeleteAccount();
5050
void onOpenAccountInBrowser();
5151
void onToggleSignInState();
52+
void onChangeAlias();
5253

5354
void onFolderWizardAccepted();
5455

@@ -62,6 +63,7 @@ class AccountViewController : public QObject
6263
QAction *_reconnect = nullptr;
6364
QAction *_showInBrowser = nullptr;
6465
QAction *_remove = nullptr;
66+
QAction *_rename = nullptr;
6567

6668
void buildManageAccountMenu();
6769
void refreshAccountActions();

src/gui/mainwindow/mainwindow.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ void MainWindow::buildWindow()
8686
// which makes the button "edge" clear. Anyway without this fix, the ... button looked really weird
8787
// looked like it was pushed too far to the right with a larger gap on the left side vs the right
8888
// this change helped a lot.
89-
// note setting the margin does nothing because it's not actually in play - the extra gap around the separator
90-
// is due to the widget spacing in the toolbar itself. I think if we want to get rid of this we have to completely hide
91-
// the separator, but leave it in place to allow placing other widgets before or after it.
89+
// leaving this here as we are currently just hiding the separator, if we want to show it again this needs
90+
// to be uncommented too.
9291
// _toolbar->setStyleSheet("QToolBar::Separator { width: 1px; height: 1px; }");
9392
_toolbar->setIconSize(iconsSize);
9493
_toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
@@ -108,7 +107,7 @@ void MainWindow::buildWindow()
108107
_separatorAction = _toolbar->addSeparator();
109108
// I'm hiding the separator as it is too difficult to make the more button look normal as the toolbar widget spacing is used
110109
// on either side of the separator, and this makes the more button look weird/out of place/too far to the right in a subtle way.
111-
// if we want to turn it back on, at minimum the style sheet above should be uncommented else it's *really* bad.
110+
// if we want to turn it back on, at minimum the tooblar::separator style sheet above should be uncommented else it's *really* bad.
112111
_separatorAction->setVisible(false);
113112

114113
QAction *moreAction = new QAction(tr("More"), this);

src/libsync/account.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ void Account::setAccountAlias(const QString &newAlias)
165165
if (_alias != newAlias) {
166166
_alias = newAlias;
167167
emit accountAliasChanged(_alias);
168+
// eh, may as well save it to settings right away
169+
emit wantsAccountSaved(this);
168170
}
169171
}
170172

0 commit comments

Comments
 (0)