mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-29 12:19:03 +03:00
Use properties to get user details
Convert imperative QML code to declarative code using property bindings Signed-off-by: Nicolas Fella <nicolas.fella@gmx.de>
This commit is contained in:
parent
a12205f322
commit
07bede8a56
3 changed files with 34 additions and 26 deletions
|
@ -42,6 +42,9 @@ User::User(AccountStatePtr &account, const bool &isCurrent, QObject *parent)
|
|||
[=]() { if (isConnected()) {slotRefresh();} });
|
||||
connect(_account.data(), &AccountState::hasFetchedNavigationApps,
|
||||
this, &User::slotRebuildNavigationAppList);
|
||||
connect(_account->account().data(), &Account::accountChangedDisplayName, this, &User::nameChanged);
|
||||
|
||||
connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &User::hasLocalFolderChanged);
|
||||
}
|
||||
|
||||
void User::slotBuildNotificationDisplay(const ActivityList &list)
|
||||
|
@ -149,6 +152,7 @@ void User::slotRefreshNotifications()
|
|||
|
||||
void User::slotRebuildNavigationAppList()
|
||||
{
|
||||
emit serverHasTalkChanged();
|
||||
// Rebuild App list
|
||||
UserAppsModel::instance()->buildAppList();
|
||||
}
|
||||
|
@ -399,7 +403,7 @@ void User::setCurrentUser(const bool &isCurrent)
|
|||
_isCurrentUser = isCurrent;
|
||||
}
|
||||
|
||||
Folder *User::getFolder()
|
||||
Folder *User::getFolder() const
|
||||
{
|
||||
foreach (Folder *folder, FolderMan::instance()->map()) {
|
||||
if (folder->accountState() == _account.data()) {
|
||||
|
@ -472,6 +476,11 @@ QImage User::avatar(bool whiteBg) const
|
|||
}
|
||||
}
|
||||
|
||||
bool User::hasLocalFolder() const
|
||||
{
|
||||
return getFolder() != nullptr;
|
||||
}
|
||||
|
||||
bool User::serverHasTalk() const
|
||||
{
|
||||
return _account->hasTalk();
|
||||
|
@ -544,7 +553,7 @@ Q_INVOKABLE int UserModel::numUsers()
|
|||
return _users.size();
|
||||
}
|
||||
|
||||
Q_INVOKABLE int UserModel::currentUserId()
|
||||
Q_INVOKABLE int UserModel::currentUserId() const
|
||||
{
|
||||
return _currentUserId;
|
||||
}
|
||||
|
@ -579,15 +588,6 @@ QImage UserModel::avatarById(const int &id)
|
|||
return _users[id]->avatar(true);
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString UserModel::currentUserName()
|
||||
{
|
||||
if (_users.count() >= 1) {
|
||||
return _users[_currentUserId]->name();
|
||||
} else {
|
||||
return QString("No users");
|
||||
}
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString UserModel::currentUserServer()
|
||||
{
|
||||
if (_users.count() >= 1) {
|
||||
|
@ -782,6 +782,11 @@ AccountAppList UserModel::appList() const
|
|||
}
|
||||
}
|
||||
|
||||
User *UserModel::currentUser() const
|
||||
{
|
||||
return _users[currentUserId()];
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
|
||||
ImageProvider::ImageProvider()
|
||||
|
|
|
@ -17,6 +17,10 @@ namespace OCC {
|
|||
class User : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||
Q_PROPERTY(QString server READ server CONSTANT)
|
||||
Q_PROPERTY(bool hasLocalFolder READ hasLocalFolder NOTIFY hasLocalFolderChanged)
|
||||
Q_PROPERTY(bool serverHasTalk READ serverHasTalk NOTIFY serverHasTalkChanged)
|
||||
public:
|
||||
User(AccountStatePtr &account, const bool &isCurrent = false, QObject* parent = 0);
|
||||
|
||||
|
@ -25,11 +29,12 @@ public:
|
|||
bool isConnected() const;
|
||||
bool isCurrentUser() const;
|
||||
void setCurrentUser(const bool &isCurrent);
|
||||
Folder *getFolder();
|
||||
Folder *getFolder() const;
|
||||
ActivityListModel *getActivityModel();
|
||||
void openLocalFolder();
|
||||
QString name() const;
|
||||
QString server(bool shortened = true) const;
|
||||
bool hasLocalFolder() const;
|
||||
bool serverHasTalk() const;
|
||||
bool hasActivities() const;
|
||||
AccountAppList appList() const;
|
||||
|
@ -41,6 +46,9 @@ public:
|
|||
|
||||
signals:
|
||||
void guiLog(const QString &, const QString &);
|
||||
void nameChanged();
|
||||
void hasLocalFolderChanged();
|
||||
void serverHasTalkChanged();
|
||||
|
||||
public slots:
|
||||
void slotItemCompleted(const QString &folder, const SyncFileItemPtr &item);
|
||||
|
@ -79,6 +87,7 @@ private:
|
|||
class UserModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(User* currentUser READ currentUser NOTIFY newUserSelected)
|
||||
public:
|
||||
static UserModel *instance();
|
||||
virtual ~UserModel() {};
|
||||
|
@ -92,18 +101,19 @@ public:
|
|||
|
||||
QImage avatarById(const int &id);
|
||||
|
||||
User *currentUser() const;
|
||||
|
||||
Q_INVOKABLE void fetchCurrentActivityModel();
|
||||
Q_INVOKABLE void openCurrentAccountLocalFolder();
|
||||
Q_INVOKABLE void openCurrentAccountTalk();
|
||||
Q_INVOKABLE void openCurrentAccountServer();
|
||||
Q_INVOKABLE QImage currentUserAvatar();
|
||||
Q_INVOKABLE int numUsers();
|
||||
Q_INVOKABLE QString currentUserName();
|
||||
Q_INVOKABLE QString currentUserServer();
|
||||
Q_INVOKABLE bool currentUserHasActivities();
|
||||
Q_INVOKABLE bool currentUserHasLocalFolder();
|
||||
Q_INVOKABLE bool currentServerHasTalk();
|
||||
Q_INVOKABLE int currentUserId();
|
||||
Q_INVOKABLE int currentUserId() const;
|
||||
Q_INVOKABLE bool isUserConnected(const int &id);
|
||||
Q_INVOKABLE void switchCurrentUser(const int &id);
|
||||
Q_INVOKABLE void login(const int &id);
|
||||
|
|
|
@ -30,10 +30,6 @@ Window {
|
|||
onVisibleChanged: {
|
||||
currentAccountAvatar.source = ""
|
||||
currentAccountAvatar.source = "image://avatars/currentUser"
|
||||
currentAccountUser.text = UserModel.currentUserName();
|
||||
currentAccountServer.text = UserModel.currentUserServer();
|
||||
openLocalFolderButton.visible = UserModel.currentUserHasLocalFolder();
|
||||
trayWindowTalkButton.visible = UserModel.currentServerHasTalk();
|
||||
currentAccountStateIndicator.source = ""
|
||||
currentAccountStateIndicator.source = UserModel.isUserConnected(UserModel.currentUserId()) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"
|
||||
|
||||
|
@ -48,15 +44,11 @@ Window {
|
|||
onRefreshCurrentUserGui: {
|
||||
currentAccountAvatar.source = ""
|
||||
currentAccountAvatar.source = "image://avatars/currentUser"
|
||||
currentAccountUser.text = UserModel.currentUserName();
|
||||
currentAccountServer.text = UserModel.currentUserServer();
|
||||
currentAccountStateIndicator.source = ""
|
||||
currentAccountStateIndicator.source = UserModel.isUserConnected(UserModel.currentUserId()) ? "qrc:///client/theme/colored/state-ok.svg" : "qrc:///client/theme/colored/state-offline.svg"
|
||||
}
|
||||
onNewUserSelected: {
|
||||
accountMenu.close();
|
||||
openLocalFolderButton.visible = UserModel.currentUserHasLocalFolder();
|
||||
trayWindowTalkButton.visible = UserModel.currentServerHasTalk();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -327,8 +319,9 @@ Window {
|
|||
Layout.leftMargin: 6
|
||||
Label {
|
||||
id: currentAccountUser
|
||||
|
||||
width: Style.currentAccountLabelWidth
|
||||
text: UserModel.currentUserName()
|
||||
text: UserModel.currentUser.name
|
||||
elide: Text.ElideRight
|
||||
color: "white"
|
||||
font.pixelSize: Style.topLinePixelSize
|
||||
|
@ -337,7 +330,7 @@ Window {
|
|||
Label {
|
||||
id: currentAccountServer
|
||||
width: Style.currentAccountLabelWidth
|
||||
text: UserModel.currentUserServer()
|
||||
text: UserModel.currentUser.server
|
||||
elide: Text.ElideRight
|
||||
color: "white"
|
||||
font.pixelSize: Style.subLinePixelSize
|
||||
|
@ -364,7 +357,7 @@ Window {
|
|||
HeaderButton {
|
||||
id: openLocalFolderButton
|
||||
|
||||
visible: UserModel.currentUserHasLocalFolder()
|
||||
visible: UserModel.currentUser.hasLocalFolder
|
||||
icon.source: "qrc:///client/theme/white/folder.svg"
|
||||
onClicked: UserModel.openCurrentAccountLocalFolder()
|
||||
}
|
||||
|
@ -372,7 +365,7 @@ Window {
|
|||
HeaderButton {
|
||||
id: trayWindowTalkButton
|
||||
|
||||
visible: UserModel.currentServerHasTalk()
|
||||
visible: UserModel.currentUser.serverHasTalk
|
||||
icon.source: "qrc:///client/theme/white/talk-app.svg"
|
||||
onClicked: UserModel.openCurrentAccountTalk()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue