Rename Controller.connection to activeConnection
This commit is contained in:
@@ -39,7 +39,7 @@ Dialog {
|
|||||||
|
|
||||||
standardButtons: Dialog.Ok | Dialog.Cancel
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
|
||||||
onAccepted: Controller.createRoom(Controller.connection, roomNameField.text, roomTopicField.text)
|
onAccepted: Controller.createRoom(Controller.activeConnection, roomNameField.text, roomTopicField.text)
|
||||||
|
|
||||||
onClosed: destroy()
|
onClosed: destroy()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ Dialog {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
roomListForm.enteredRoom = Controller.connection.room(room.predecessorId)
|
roomListForm.enteredRoom = Controller.activeConnection.room(room.predecessorId)
|
||||||
root.close()
|
root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ Dialog {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
roomListForm.enteredRoom = Controller.connection.room(room.successorId)
|
roomListForm.enteredRoom = Controller.activeConnection.room(room.successorId)
|
||||||
root.close()
|
root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ Kirigami.ScrollablePage {
|
|||||||
icon: model.connection.user.avatarMediaId ? "image://mxc/" + model.connection.user.avatarMediaId : "im-user"
|
icon: model.connection.user.avatarMediaId ? "image://mxc/" + model.connection.user.avatarMediaId : "im-user"
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Controller.connection = model.connection
|
Controller.activeConnection = model.connection
|
||||||
pageStack.layers.pop()
|
pageStack.layers.pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ Kirigami.ApplicationWindow {
|
|||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
text: i18n("Explore rooms")
|
text: i18n("Explore rooms")
|
||||||
iconName: "compass"
|
iconName: "compass"
|
||||||
onTriggered: pageStack.layers.push("qrc:/imports/NeoChat/Page/JoinRoomPage.qml", {"connection": Controller.connection})
|
onTriggered: pageStack.layers.push("qrc:/imports/NeoChat/Page/JoinRoomPage.qml", {"connection": Controller.activeConnection})
|
||||||
enabled: pageStack.layers.currentItem.title !== i18n("Explore Rooms")
|
enabled: pageStack.layers.currentItem.title !== i18n("Explore Rooms")
|
||||||
},
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
@@ -100,6 +100,6 @@ Kirigami.ApplicationWindow {
|
|||||||
RoomListModel {
|
RoomListModel {
|
||||||
id: spectralRoomListModel
|
id: spectralRoomListModel
|
||||||
|
|
||||||
connection: Controller.connection
|
connection: Controller.activeConnection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ void Controller::loginWithCredentials(QString serverAddr, QString user, QString
|
|||||||
qWarning() << "Couldn't save access token";
|
qWarning() << "Couldn't save access token";
|
||||||
account.sync();
|
account.sync();
|
||||||
addConnection(conn);
|
addConnection(conn);
|
||||||
setConnection(conn);
|
setActiveConnection(conn);
|
||||||
});
|
});
|
||||||
connect(conn, &Connection::networkError, [=](QString error, QString, int, int) {
|
connect(conn, &Connection::networkError, [=](QString error, QString, int, int) {
|
||||||
Q_EMIT errorOccured("Network Error", error);
|
Q_EMIT errorOccured("Network Error", error);
|
||||||
@@ -144,7 +144,7 @@ void Controller::loginWithAccessToken(QString serverAddr, QString user, QString
|
|||||||
qWarning() << "Couldn't save access token";
|
qWarning() << "Couldn't save access token";
|
||||||
account.sync();
|
account.sync();
|
||||||
addConnection(conn);
|
addConnection(conn);
|
||||||
setConnection(conn);
|
setActiveConnection(conn);
|
||||||
});
|
});
|
||||||
connect(conn, &Connection::networkError, this, [=](QString error, QString, int, int) {
|
connect(conn, &Connection::networkError, this, [=](QString error, QString, int, int) {
|
||||||
Q_EMIT errorOccured("Network Error", error);
|
Q_EMIT errorOccured("Network Error", error);
|
||||||
@@ -179,9 +179,9 @@ void Controller::logout(Connection *conn, bool serverSideLogout)
|
|||||||
Q_EMIT conn->stateChanged();
|
Q_EMIT conn->stateChanged();
|
||||||
Q_EMIT conn->loggedOut();
|
Q_EMIT conn->loggedOut();
|
||||||
if (!m_connections.isEmpty())
|
if (!m_connections.isEmpty())
|
||||||
setConnection(m_connections[0]);
|
setActiveConnection(m_connections[0]);
|
||||||
else
|
else
|
||||||
setConnection(nullptr);
|
setActiveConnection(nullptr);
|
||||||
if (!serverSideLogout) {
|
if (!serverSideLogout) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ void Controller::invokeLogin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_connections.isEmpty()) {
|
if (!m_connections.isEmpty()) {
|
||||||
setConnection(m_connections[0]);
|
setActiveConnection(m_connections[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT initiated();
|
Q_EMIT initiated();
|
||||||
@@ -517,17 +517,17 @@ void Controller::setBusy(bool busy)
|
|||||||
Q_EMIT busyChanged();
|
Q_EMIT busyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection *Controller::connection() const
|
Connection *Controller::activeConnection() const
|
||||||
{
|
{
|
||||||
if (m_connection.isNull())
|
if (m_connection.isNull())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return m_connection;
|
return m_connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::setConnection(Connection *connection)
|
void Controller::setActiveConnection(Connection *connection)
|
||||||
{
|
{
|
||||||
if (connection == m_connection)
|
if (connection == m_connection)
|
||||||
return;
|
return;
|
||||||
m_connection = connection;
|
m_connection = connection;
|
||||||
Q_EMIT connectionChanged();
|
Q_EMIT activeConnectionChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class Controller : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int accountCount READ accountCount NOTIFY connectionAdded NOTIFY connectionDropped)
|
Q_PROPERTY(int accountCount READ accountCount NOTIFY connectionAdded NOTIFY connectionDropped)
|
||||||
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
|
Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed NOTIFY quitOnLastWindowClosedChanged)
|
||||||
Q_PROPERTY(Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
|
Q_PROPERTY(Connection *activeConnection READ activeConnection WRITE setActiveConnection NOTIFY activeConnectionChanged)
|
||||||
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged)
|
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged)
|
||||||
Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged)
|
Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged)
|
||||||
Q_PROPERTY(KAboutData aboutData READ aboutData WRITE setAboutData NOTIFY aboutDataChanged)
|
Q_PROPERTY(KAboutData aboutData READ aboutData WRITE setAboutData NOTIFY aboutDataChanged)
|
||||||
@@ -38,8 +38,8 @@ public:
|
|||||||
|
|
||||||
QVector<Connection *> connections() const;
|
QVector<Connection *> connections() const;
|
||||||
|
|
||||||
void setConnection(Connection *conn);
|
void setActiveConnection(Connection *connection);
|
||||||
Connection *connection() const;
|
Connection *activeConnection() const;
|
||||||
|
|
||||||
void addConnection(Connection *c);
|
void addConnection(Connection *c);
|
||||||
void dropConnection(Connection *c);
|
void dropConnection(Connection *c);
|
||||||
@@ -101,7 +101,7 @@ Q_SIGNALS:
|
|||||||
void notificationClicked(const QString roomId, const QString eventId);
|
void notificationClicked(const QString roomId, const QString eventId);
|
||||||
void quitOnLastWindowClosedChanged();
|
void quitOnLastWindowClosedChanged();
|
||||||
void unreadCountChanged();
|
void unreadCountChanged();
|
||||||
void connectionChanged();
|
void activeConnectionChanged();
|
||||||
void isOnlineChanged();
|
void isOnlineChanged();
|
||||||
void aboutDataChanged();
|
void aboutDataChanged();
|
||||||
void passwordStatus(Controller::PasswordStatus status);
|
void passwordStatus(Controller::PasswordStatus status);
|
||||||
|
|||||||
@@ -40,21 +40,21 @@ ThumbnailResponse::ThumbnailResponse(QString id, QSize size)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Controller::instance().connection()) {
|
if (!Controller::instance().activeConnection()) {
|
||||||
qWarning() << "Current connection is null";
|
qWarning() << "Current connection is null";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute a request on the main thread asynchronously
|
// Execute a request on the main thread asynchronously
|
||||||
moveToThread(Controller::instance().connection()->thread());
|
moveToThread(Controller::instance().activeConnection()->thread());
|
||||||
QMetaObject::invokeMethod(this, &ThumbnailResponse::startRequest, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, &ThumbnailResponse::startRequest, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThumbnailResponse::startRequest()
|
void ThumbnailResponse::startRequest()
|
||||||
{
|
{
|
||||||
// Runs in the main thread, not QML thread
|
// Runs in the main thread, not QML thread
|
||||||
Q_ASSERT(QThread::currentThread() == Controller::instance().connection()->thread());
|
Q_ASSERT(QThread::currentThread() == Controller::instance().activeConnection()->thread());
|
||||||
job = Controller::instance().connection()->getThumbnail(mediaId, requestedSize);
|
job = Controller::instance().activeConnection()->getThumbnail(mediaId, requestedSize);
|
||||||
// Connect to any possible outcome including abandonment
|
// Connect to any possible outcome including abandonment
|
||||||
// to make sure the QML thread is not left stuck forever.
|
// to make sure the QML thread is not left stuck forever.
|
||||||
connect(job, &BaseJob::finished, this, &ThumbnailResponse::prepareResult);
|
connect(job, &BaseJob::finished, this, &ThumbnailResponse::prepareResult);
|
||||||
|
|||||||
Reference in New Issue
Block a user