Stop using the AccountRegistry Singleton
This commit is contained in:
@@ -101,17 +101,17 @@ Controller::Controller(QObject *parent)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(&Accounts, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged);
|
connect(&m_accountRegistry, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged);
|
||||||
|
|
||||||
static int oldAccountCount = 0;
|
static int oldAccountCount = 0;
|
||||||
connect(&Accounts, &AccountRegistry::accountCountChanged, this, [this]() {
|
connect(&m_accountRegistry, &AccountRegistry::accountCountChanged, this, [this]() {
|
||||||
if (Accounts.size() > oldAccountCount) {
|
if (m_accountRegistry.size() > oldAccountCount) {
|
||||||
auto connection = Accounts.accounts()[Accounts.size() - 1];
|
auto connection = m_accountRegistry.accounts()[m_accountRegistry.size() - 1];
|
||||||
connect(connection, &Connection::syncDone, this, [connection]() {
|
connect(connection, &Connection::syncDone, this, [connection]() {
|
||||||
NotificationsManager::instance().handleNotifications(connection);
|
NotificationsManager::instance().handleNotifications(connection);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
oldAccountCount = Accounts.size();
|
oldAccountCount = m_accountRegistry.size();
|
||||||
});
|
});
|
||||||
|
|
||||||
QTimer::singleShot(0, this, [this] {
|
QTimer::singleShot(0, this, [this] {
|
||||||
@@ -147,10 +147,10 @@ void Controller::logout(Connection *conn, bool serverSideLogout)
|
|||||||
job.start();
|
job.start();
|
||||||
loop.exec();
|
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
|
// Only set the connection if the the account being logged out is currently active
|
||||||
if (conn == activeConnection()) {
|
if (conn == activeConnection()) {
|
||||||
setActiveConnection(Accounts.accounts()[0]);
|
setActiveConnection(m_accountRegistry.accounts()[0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setActiveConnection(nullptr);
|
setActiveConnection(nullptr);
|
||||||
@@ -165,7 +165,7 @@ void Controller::addConnection(Connection *c)
|
|||||||
{
|
{
|
||||||
Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection");
|
Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection");
|
||||||
|
|
||||||
Accounts.add(c);
|
m_accountRegistry.add(c);
|
||||||
|
|
||||||
c->setLazyLoading(true);
|
c->setLazyLoading(true);
|
||||||
|
|
||||||
@@ -391,7 +391,7 @@ NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, b
|
|||||||
|
|
||||||
int Controller::accountCount() const
|
int Controller::accountCount() const
|
||||||
{
|
{
|
||||||
return Accounts.count();
|
return m_accountRegistry.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::setQuitOnLastWindowClosed()
|
void Controller::setQuitOnLastWindowClosed()
|
||||||
@@ -625,10 +625,10 @@ void Controller::setApplicationProxy()
|
|||||||
|
|
||||||
int Controller::activeConnectionIndex() const
|
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 it == m_connection;
|
||||||
});
|
});
|
||||||
return result - Accounts.accounts().begin();
|
return result - m_accountRegistry.accounts().begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Controller::quotientMinorVersion() const
|
int Controller::quotientMinorVersion() const
|
||||||
@@ -681,4 +681,9 @@ QVariantList Controller::getSupportedRoomVersions(Quotient::Connection *connecti
|
|||||||
return supportedRoomVersions;
|
return supportedRoomVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AccountRegistry &Controller::accounts()
|
||||||
|
{
|
||||||
|
return m_accountRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_controller.cpp"
|
#include "moc_controller.cpp"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <KFormat>
|
#include <KFormat>
|
||||||
|
|
||||||
|
#include <Quotient/accountregistry.h>
|
||||||
#include <Quotient/jobs/basejob.h>
|
#include <Quotient/jobs/basejob.h>
|
||||||
#include <Quotient/settings.h>
|
#include <Quotient/settings.h>
|
||||||
|
|
||||||
@@ -229,6 +230,8 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE QVariantList getSupportedRoomVersions(Quotient::Connection *connection);
|
Q_INVOKABLE QVariantList getSupportedRoomVersions(Quotient::Connection *connection);
|
||||||
|
|
||||||
|
Quotient::AccountRegistry &accounts();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Controller(QObject *parent = nullptr);
|
explicit Controller(QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -245,6 +248,7 @@ private:
|
|||||||
bool hasWindowSystem() const;
|
bool hasWindowSystem() const;
|
||||||
|
|
||||||
QPointer<PushRuleModel> m_pushRuleModel;
|
QPointer<PushRuleModel> m_pushRuleModel;
|
||||||
|
Quotient::AccountRegistry m_accountRegistry;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void invokeLogin();
|
void invokeLogin();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void Login::init()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isLoggedIn = Accounts.isLoggedIn(m_matrixId);
|
m_isLoggedIn = Controller::instance().accounts().isLoggedIn(m_matrixId);
|
||||||
Q_EMIT isLoggedInChanged();
|
Q_EMIT isLoggedInChanged();
|
||||||
if (m_isLoggedIn) {
|
if (m_isLoggedIn) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login);
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login);
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper);
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper);
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", &EmojiModel::instance());
|
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, "SpaceHierarchyCache", &SpaceHierarchyCache::instance());
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CustomEmojiModel", &CustomEmojiModel::instance());
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CustomEmojiModel", &CustomEmojiModel::instance());
|
||||||
qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler");
|
qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler");
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (room->localUser()->id() != Controller::instance().activeConnection()->userId()) {
|
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);
|
RoomManager::instance().enterRoom(room);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -242,6 +242,7 @@ Kirigami.ApplicationWindow {
|
|||||||
|
|
||||||
function onInitiated() {
|
function onInitiated() {
|
||||||
if (Controller.accountCount === 0) {
|
if (Controller.accountCount === 0) {
|
||||||
|
console.warn("9")
|
||||||
pageStack.replace("qrc:/WelcomePage.qml", {});
|
pageStack.replace("qrc:/WelcomePage.qml", {});
|
||||||
} else if (!roomListLoaded) {
|
} else if (!roomListLoaded) {
|
||||||
pageStack.replace(roomListComponent, {
|
pageStack.replace(roomListComponent, {
|
||||||
|
|||||||
Reference in New Issue
Block a user