mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-24 05:55:59 +03:00
Detect newly added user and rebuild account menu automatically
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
parent
3da982f073
commit
32741162d9
2 changed files with 26 additions and 9 deletions
|
@ -136,17 +136,23 @@ UserModel::UserModel(QObject *parent)
|
|||
{
|
||||
// TODO: Remember selected user from last quit via settings file
|
||||
if (AccountManager::instance()->accounts().size() > 0) {
|
||||
initUserList();
|
||||
buildUserList();
|
||||
}
|
||||
|
||||
connect(AccountManager::instance(), &AccountManager::accountAdded,
|
||||
this, &UserModel::buildUserList);
|
||||
}
|
||||
|
||||
void UserModel::initUserList()
|
||||
void UserModel::buildUserList()
|
||||
{
|
||||
for (int i = 0; i < AccountManager::instance()->accounts().size(); i++) {
|
||||
auto user = AccountManager::instance()->accounts().at(i);
|
||||
addUser(user);
|
||||
}
|
||||
if (_init) {
|
||||
_users.first().setCurrentUser(true);
|
||||
_init = false;
|
||||
}
|
||||
}
|
||||
|
||||
Q_INVOKABLE int UserModel::numUsers()
|
||||
|
@ -186,12 +192,22 @@ Q_INVOKABLE bool UserModel::currentServerHasTalk()
|
|||
|
||||
void UserModel::addUser(AccountStatePtr &user, const bool &isCurrent)
|
||||
{
|
||||
bool containsUser = false;
|
||||
for (int i = 0; i < _users.size(); i++) {
|
||||
if (_users[i] == user) {
|
||||
containsUser = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!containsUser) {
|
||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||
_users << User(user, isCurrent);
|
||||
if (isCurrent) {
|
||||
_currentUserId = _users.indexOf(_users.last());
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
int UserModel::currentUserIndex()
|
||||
|
|
|
@ -95,8 +95,9 @@ private:
|
|||
UserModel(QObject *parent = 0);
|
||||
QList<User> _users;
|
||||
int _currentUserId;
|
||||
bool _init = true;
|
||||
|
||||
void initUserList();
|
||||
void buildUserList();
|
||||
};
|
||||
|
||||
class ImageProvider : public QQuickImageProvider
|
||||
|
|
Loading…
Reference in a new issue