Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ QString davUserDisplyNameC()
return "display-name";
}

QString accountAliasC()
{
return "account-alias";
}

QString userUUIDC()
{
return "uuid";
Expand Down Expand Up @@ -108,7 +113,7 @@ bool AccountManager::restore()
for (const auto &accountIndex : childGroups) {
settings->beginGroup(accountIndex);
if (auto acc = loadAccountHelper(*settings)) {
acc->_groupIndex = accountIndex;
acc->setGroupIndex(accountIndex);
if (auto accState = AccountState::loadFromSettings(acc, *settings)) {
addAccountState(accState);
}
Expand All @@ -124,6 +129,7 @@ Account *AccountManager::createAccount(const NewAccountModel &model)
auto account = new Account(QUuid::createUuid(), model.davUser(), model.effectiveUserInfoUrl());

account->setDavDisplayName(model.displayName());
account->setAccountAlias(account->calculateAlias());

Credentials *creds = new Credentials(model.authToken(), model.refreshToken(), account);
account->setCredentials(creds);
Expand Down Expand Up @@ -161,9 +167,10 @@ void AccountManager::saveAccount(Account *account)
auto settings = ConfigFile::settingsWithGroup(accountsC());
settings->beginGroup(account->groupIndex());

settings->setValue(urlC(), account->_url.toString());
settings->setValue(davUserC(), account->_davUser);
settings->setValue(davUserDisplyNameC(), account->_displayName);
settings->setValue(urlC(), account->url().toString());
settings->setValue(davUserC(), account->davUser());
settings->setValue(davUserDisplyNameC(), account->davDisplayName());
settings->setValue(accountAliasC(), account->accountAlias());
settings->setValue(userUUIDC(), account->uuid());
if (account->hasCapabilities()) {
settings->setValue(capabilitesC(), account->capabilities().raw());
Expand Down Expand Up @@ -283,6 +290,10 @@ Account *AccountManager::loadAccountHelper(QSettings &settings)
auto acc = new Account(uid, user, url);

acc->setDavDisplayName(settings.value(davUserDisplyNameC()).toString());
QString alias = settings.value(accountAliasC()).toString();
if (alias.isEmpty())
alias = acc->calculateAlias();
acc->setAccountAlias(alias);
acc->setCapabilities(caps);
acc->setDefaultSyncRoot(settings.value(defaultSyncRootC()).toString());

Expand Down Expand Up @@ -332,7 +343,7 @@ AccountState *AccountManager::addAccount(Account *newAccount)
if (id.isEmpty() || !isAccountIndexAvailable(id)) {
id = generateFreeAccountIndex();
}
newAccount->_groupIndex = id;
newAccount->setGroupIndex(id);


return addAccountState(new AccountState(newAccount));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountsgui/accountsguicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void AccountsGuiController::onAccountAdded(AccountState *state)
// it's really dumb to have "long" text on any toolbar component in the first place. We hope to fix this someday
// by allowing the user to set an account alias which will show as the account name but that needs a major release
// to support the config change
accountAction->setText(account->hostName());
accountAction->setText(account->accountAlias());

accountAction->setToolTip(QString("%1\n%2").arg(account->davDisplayName(), account->url().toDisplayString()));
accountAction->setData(QVariant::fromValue(accountView));
Expand Down
30 changes: 25 additions & 5 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ bool Account::hasAvatar() const
return !_avatarImg.isNull();
}

QString Account::accountAlias() const
{
return _alias;
}

void Account::setAccountAlias(const QString &newAlias)
{
if (_alias != newAlias) {
_alias = newAlias;
emit accountAliasChanged(_alias);
}
}

QString Account::calculateAlias() const
{
QString first = davDisplayName().section(QRegularExpression("\\s"), 0, 0, QString::SectionSkipEmpty);
return first;
}

QString Account::displayNameWithHost() const
{
QString user = davDisplayName();
Expand All @@ -175,11 +194,6 @@ QString Account::initials() const
return out;
}

QGradient::Preset Account::avatarGradient() const
{
return static_cast<QGradient::Preset>(qHash(displayNameWithHost()) % QGradient::NumPresets + 1);
}

QString Account::davDisplayName() const
{
if (_displayName.isEmpty()) {
Expand All @@ -196,6 +210,12 @@ void Account::setDavDisplayName(const QString &newDisplayName)
}
}

void Account::setGroupIndex(const QString &index)
{
if (index != _groupIndex)
_groupIndex = index;
}

QString Account::groupIndex() const
{
return _groupIndex;
Expand Down
41 changes: 24 additions & 17 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*/


#ifndef SERVERCONNECTION_H
#define SERVERCONNECTION_H
#pragma once

#include "owncloudlib.h"

Expand Down Expand Up @@ -60,17 +59,17 @@ class ResourcesCache;
class OWNCLOUDSYNC_EXPORT Account : public QObject
{
Q_OBJECT
Q_PROPERTY(QUuid uid READ uuid CONSTANT)
Q_PROPERTY(QString davUser READ davUser CONSTANT)
Q_PROPERTY(QString davDisplayName READ davDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(QString displayNameWithHost READ displayNameWithHost NOTIFY displayNameChanged)
Q_PROPERTY(QString initials READ initials NOTIFY displayNameChanged)
Q_PROPERTY(QString hostName READ hostName CONSTANT)
Q_PROPERTY(bool hasAvatar READ hasAvatar NOTIFY avatarChanged)
Q_PROPERTY(QGradient::Preset avatarGradient READ avatarGradient NOTIFY displayNameChanged)
Q_PROPERTY(QUrl url READ url CONSTANT)
QML_ELEMENT
QML_UNCREATABLE("Only created in the C++ code")
/* Q_PROPERTY(QUuid uid READ uuid CONSTANT)
Q_PROPERTY(QString davUser READ davUser CONSTANT)
Q_PROPERTY(QString davDisplayName READ davDisplayName NOTIFY displayNameChanged)
Q_PROPERTY(QString displayNameWithHost READ displayNameWithHost NOTIFY displayNameChanged)
Q_PROPERTY(QString initials READ initials NOTIFY displayNameChanged)
Q_PROPERTY(QString hostName READ hostName CONSTANT)
Q_PROPERTY(bool hasAvatar READ hasAvatar NOTIFY avatarChanged)
Q_PROPERTY(QGradient::Preset avatarGradient READ avatarGradient NOTIFY displayNameChanged)
Q_PROPERTY(QUrl url READ url CONSTANT)
QML_ELEMENT
QML_UNCREATABLE("Only created in the C++ code")*/

public:
/**
Expand Down Expand Up @@ -107,6 +106,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
*/
QUrl url() const;


/***
* This is the default folder containing all spaces.
*/
Expand All @@ -131,13 +131,20 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
void setAvatar(const QIcon &img);
bool hasAvatar() const;

// alias for the account which appears in the toolbar button text.
// the user can edit to make each account easily identifiable.
// default value is first section of davDisplayName() (all text appearing before first whitespace)
QString accountAlias() const;
void setAccountAlias(const QString &newAlias);
QString calculateAlias() const;

/// The name of the account as shown in the toolbar
QString displayNameWithHost() const;
QString initials() const;
QGradient::Preset avatarGradient() const;

/// The value used to group the account's setttings
QString groupIndex() const;
void setGroupIndex(const QString &index);

QString hostName() const;

Expand Down Expand Up @@ -236,6 +243,7 @@ public Q_SLOTS:

void avatarChanged();
void displayNameChanged();
void accountAliasChanged(const QString &newAlias);

void unknownConnectionState();

Expand All @@ -250,6 +258,7 @@ public Q_SLOTS:
QUuid _uuid;
QString _davUser;
QString _displayName;
QString _alias;
QString _defaultSyncRoot;
QIcon _avatarImg;

Expand All @@ -270,13 +279,11 @@ public Q_SLOTS:
AppProvider _appProvider;

GraphApi::SpacesManager *_spacesManager = nullptr;
friend class AccountManager;
// friend class AccountManager;
};
}

Q_DECLARE_METATYPE(OCC::Account)


QDebug OWNCLOUDSYNC_EXPORT operator<<(QDebug debug, const OCC::Account *job);

#endif //SERVERCONNECTION_H
Loading