From 3a0ccf3697e1d97b646768a08c20883b3c54daf4 Mon Sep 17 00:00:00 2001 From: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> Date: Wed, 4 Dec 2019 13:00:26 +0100 Subject: [PATCH] connected UserModel login/logout signals, minor fixes Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com> --- src/gui/accountmanager.h | 7 +++---- src/gui/owncloudgui.cpp | 6 ++++++ src/gui/systray.cpp | 2 +- src/gui/tray/UserModel.cpp | 24 ++++++++++-------------- src/gui/tray/UserModel.h | 12 +++++++++--- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h index fabc6ca5b..4719b8109 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -89,6 +89,9 @@ private: // Adds an account to the tracked list, emitting accountAdded() void addAccountState(AccountState *accountState); + AccountManager() {} + QList _accounts; + public slots: /// Saves account data, not including the credentials void saveAccount(Account *a); @@ -104,9 +107,5 @@ Q_SIGNALS: void accountAdded(AccountState *account); void accountRemoved(AccountState *account); void removeAccountFolders(AccountState *account); - -private: - AccountManager() {} - QList _accounts; }; } diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 3a4c8651b..3d328403c 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -113,6 +113,12 @@ ownCloudGui::ownCloudGui(Application *parent) this, &ownCloudGui::slotShowOptionalTrayMessage); connect(Logger::instance(), &Logger::guiMessage, this, &ownCloudGui::slotShowGuiMessage); + + + connect(UserModel::instance(), &UserModel::login, + this, &ownCloudGui::slotLogin); + connect(UserModel::instance(), &UserModel::logout, + this, &ownCloudGui::slotLogout); } #ifdef WITH_LIBCLOUDPROVIDERS diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index d34f300bf..74bc1347e 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -43,7 +43,7 @@ Systray::Systray() // TODO: make singleton, provide ::instance() QQmlComponent systray(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/init.qml"))); _trayContext = engine->contextForObject(systray.create()); - _accountMenuModel = new UserModel(); + _accountMenuModel = UserModel::instance(); systray.engine()->rootContext()->setContextProperty("systrayBackend", _accountMenuModel); // TODO: hack to pass the icon to QML diff --git a/src/gui/tray/UserModel.cpp b/src/gui/tray/UserModel.cpp index 4544f3ee4..aec5287c4 100644 --- a/src/gui/tray/UserModel.cpp +++ b/src/gui/tray/UserModel.cpp @@ -68,6 +68,16 @@ void User::logout() /*-------------------------------------------------------------------------------------*/ +UserModel* UserModel::_instance = nullptr; + +UserModel *UserModel::instance() +{ + if (_instance == nullptr) { + _instance = new UserModel(); + } + return _instance; +} + UserModel::UserModel(QObject *parent) : QAbstractListModel() , _currentUser(nullptr) @@ -88,20 +98,6 @@ UserModel::UserModel(QObject *parent) } } -UserModel::~UserModel() -{ -} - -Q_INVOKABLE void UserModel::login() -{ - _currentUser->login(); -} - -Q_INVOKABLE void UserModel::logout() -{ - _currentUser->logout(); -} - Q_INVOKABLE int UserModel::numUsers() { auto test = _users.size(); diff --git a/src/gui/tray/UserModel.h b/src/gui/tray/UserModel.h index 3e115c39c..f2fb8f16d 100644 --- a/src/gui/tray/UserModel.h +++ b/src/gui/tray/UserModel.h @@ -30,8 +30,8 @@ class UserModel : public QAbstractListModel Q_OBJECT public: - UserModel(QObject *parent = 0); - virtual ~UserModel(); + static UserModel *instance(); + virtual ~UserModel() {}; void addUser(const User &user); void addCurrentUser(const User &user); @@ -40,7 +40,7 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - Q_INVOKABLE void login(); + Q_INVOKABLE void logout(); Q_INVOKABLE int numUsers(); @@ -55,10 +55,16 @@ public: AvatarRole }; +signals: + Q_INVOKABLE void login(); + Q_INVOKABLE void logout(); + protected: QHash roleNames() const; private: + static UserModel *_instance; + UserModel(QObject *parent = 0); QList _users; User *_currentUser; };