diff --git a/src/controller.cpp b/src/controller.cpp index cc3f0a80f..4c552f9ff 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -101,17 +101,17 @@ Controller::Controller(QObject *parent) } #endif - connect(&Accounts, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged); + connect(&m_accountRegistry, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged); static int oldAccountCount = 0; - connect(&Accounts, &AccountRegistry::accountCountChanged, this, [this]() { - if (Accounts.size() > oldAccountCount) { - auto connection = Accounts.accounts()[Accounts.size() - 1]; + connect(&m_accountRegistry, &AccountRegistry::accountCountChanged, this, [this]() { + if (m_accountRegistry.size() > oldAccountCount) { + auto connection = m_accountRegistry.accounts()[m_accountRegistry.size() - 1]; connect(connection, &Connection::syncDone, this, [connection]() { NotificationsManager::instance().handleNotifications(connection); }); } - oldAccountCount = Accounts.size(); + oldAccountCount = m_accountRegistry.size(); }); QTimer::singleShot(0, this, [this] { @@ -147,10 +147,10 @@ void Controller::logout(Connection *conn, bool serverSideLogout) job.start(); loop.exec(); - if (Accounts.count() > 1) { + if (m_accountRegistry.count() > 1) { // Only set the connection if the the account being logged out is currently active if (conn == activeConnection()) { - setActiveConnection(Accounts.accounts()[0]); + setActiveConnection(m_accountRegistry.accounts()[0]); } } else { setActiveConnection(nullptr); @@ -165,7 +165,7 @@ void Controller::addConnection(Connection *c) { Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection"); - Accounts.add(c); + m_accountRegistry.add(c); c->setLazyLoading(true); @@ -391,7 +391,7 @@ NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, b int Controller::accountCount() const { - return Accounts.count(); + return m_accountRegistry.count(); } void Controller::setQuitOnLastWindowClosed() @@ -625,10 +625,10 @@ void Controller::setApplicationProxy() int Controller::activeConnectionIndex() const { - auto result = std::find_if(Accounts.accounts().begin(), Accounts.accounts().end(), [this](const auto &it) { + auto result = std::find_if(m_accountRegistry.accounts().begin(), m_accountRegistry.accounts().end(), [this](const auto &it) { return it == m_connection; }); - return result - Accounts.accounts().begin(); + return result - m_accountRegistry.accounts().begin(); } int Controller::quotientMinorVersion() const @@ -681,4 +681,9 @@ QVariantList Controller::getSupportedRoomVersions(Quotient::Connection *connecti return supportedRoomVersions; } +AccountRegistry &Controller::accounts() +{ + return m_accountRegistry; +} + #include "moc_controller.cpp" diff --git a/src/controller.h b/src/controller.h index f6cb0f328..e28dc6209 100644 --- a/src/controller.h +++ b/src/controller.h @@ -9,6 +9,7 @@ #include +#include #include #include @@ -229,6 +230,8 @@ public: Q_INVOKABLE QVariantList getSupportedRoomVersions(Quotient::Connection *connection); + Quotient::AccountRegistry &accounts(); + private: explicit Controller(QObject *parent = nullptr); @@ -245,6 +248,7 @@ private: bool hasWindowSystem() const; QPointer m_pushRuleModel; + Quotient::AccountRegistry m_accountRegistry; private Q_SLOTS: void invokeLogin(); diff --git a/src/login.cpp b/src/login.cpp index 32a2ad423..9d4682fd9 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -42,7 +42,7 @@ void Login::init() return; } - m_isLoggedIn = Accounts.isLoggedIn(m_matrixId); + m_isLoggedIn = Controller::instance().accounts().isLoggedIn(m_matrixId); Q_EMIT isLoggedInChanged(); if (m_isLoggedIn) { return; diff --git a/src/main.cpp b/src/main.cpp index 5b33c759e..6a2f8cf81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", &EmojiModel::instance()); - qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::Accounts); + qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Controller::instance().accounts()); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &SpaceHierarchyCache::instance()); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CustomEmojiModel", &CustomEmojiModel::instance()); qmlRegisterType("org.kde.neochat", 1, 0, "ActionsHandler"); diff --git a/src/notificationsmanager.cpp b/src/notificationsmanager.cpp index f0c1613f9..70c14e435 100644 --- a/src/notificationsmanager.cpp +++ b/src/notificationsmanager.cpp @@ -212,7 +212,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room, return; } if (room->localUser()->id() != Controller::instance().activeConnection()->userId()) { - Controller::instance().setActiveConnection(Accounts.get(room->localUser()->id())); + Controller::instance().setActiveConnection(Controller::instance().accounts().get(room->localUser()->id())); } RoomManager::instance().enterRoom(room); }); diff --git a/src/qml/main.qml b/src/qml/main.qml index c3897fc45..dd5e4675c 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -242,6 +242,7 @@ Kirigami.ApplicationWindow { function onInitiated() { if (Controller.accountCount === 0) { + console.warn("9") pageStack.replace("qrc:/WelcomePage.qml", {}); } else if (!roomListLoaded) { pageStack.replace(roomListComponent, {