Rename Controller.connection to activeConnection
This commit is contained in:
@@ -110,7 +110,7 @@ void Controller::loginWithCredentials(QString serverAddr, QString user, QString
|
||||
qWarning() << "Couldn't save access token";
|
||||
account.sync();
|
||||
addConnection(conn);
|
||||
setConnection(conn);
|
||||
setActiveConnection(conn);
|
||||
});
|
||||
connect(conn, &Connection::networkError, [=](QString error, QString, int, int) {
|
||||
Q_EMIT errorOccured("Network Error", error);
|
||||
@@ -144,7 +144,7 @@ void Controller::loginWithAccessToken(QString serverAddr, QString user, QString
|
||||
qWarning() << "Couldn't save access token";
|
||||
account.sync();
|
||||
addConnection(conn);
|
||||
setConnection(conn);
|
||||
setActiveConnection(conn);
|
||||
});
|
||||
connect(conn, &Connection::networkError, this, [=](QString error, QString, int, int) {
|
||||
Q_EMIT errorOccured("Network Error", error);
|
||||
@@ -179,9 +179,9 @@ void Controller::logout(Connection *conn, bool serverSideLogout)
|
||||
Q_EMIT conn->stateChanged();
|
||||
Q_EMIT conn->loggedOut();
|
||||
if (!m_connections.isEmpty())
|
||||
setConnection(m_connections[0]);
|
||||
setActiveConnection(m_connections[0]);
|
||||
else
|
||||
setConnection(nullptr);
|
||||
setActiveConnection(nullptr);
|
||||
if (!serverSideLogout) {
|
||||
return;
|
||||
}
|
||||
@@ -263,7 +263,7 @@ void Controller::invokeLogin()
|
||||
}
|
||||
|
||||
if (!m_connections.isEmpty()) {
|
||||
setConnection(m_connections[0]);
|
||||
setActiveConnection(m_connections[0]);
|
||||
}
|
||||
|
||||
Q_EMIT initiated();
|
||||
@@ -517,17 +517,17 @@ void Controller::setBusy(bool busy)
|
||||
Q_EMIT busyChanged();
|
||||
}
|
||||
|
||||
Connection *Controller::connection() const
|
||||
Connection *Controller::activeConnection() const
|
||||
{
|
||||
if (m_connection.isNull())
|
||||
return nullptr;
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
void Controller::setConnection(Connection *connection)
|
||||
void Controller::setActiveConnection(Connection *connection)
|
||||
{
|
||||
if (connection == m_connection)
|
||||
return;
|
||||
m_connection = connection;
|
||||
Q_EMIT connectionChanged();
|
||||
Q_EMIT activeConnectionChanged();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Controller : public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int accountCount READ accountCount NOTIFY connectionAdded NOTIFY connectionDropped)
|
||||
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 busy READ busy WRITE setBusy NOTIFY busyChanged)
|
||||
Q_PROPERTY(KAboutData aboutData READ aboutData WRITE setAboutData NOTIFY aboutDataChanged)
|
||||
@@ -38,8 +38,8 @@ public:
|
||||
|
||||
QVector<Connection *> connections() const;
|
||||
|
||||
void setConnection(Connection *conn);
|
||||
Connection *connection() const;
|
||||
void setActiveConnection(Connection *connection);
|
||||
Connection *activeConnection() const;
|
||||
|
||||
void addConnection(Connection *c);
|
||||
void dropConnection(Connection *c);
|
||||
@@ -101,7 +101,7 @@ Q_SIGNALS:
|
||||
void notificationClicked(const QString roomId, const QString eventId);
|
||||
void quitOnLastWindowClosedChanged();
|
||||
void unreadCountChanged();
|
||||
void connectionChanged();
|
||||
void activeConnectionChanged();
|
||||
void isOnlineChanged();
|
||||
void aboutDataChanged();
|
||||
void passwordStatus(Controller::PasswordStatus status);
|
||||
|
||||
@@ -40,21 +40,21 @@ ThumbnailResponse::ThumbnailResponse(QString id, QSize size)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Controller::instance().connection()) {
|
||||
if (!Controller::instance().activeConnection()) {
|
||||
qWarning() << "Current connection is null";
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
void ThumbnailResponse::startRequest()
|
||||
{
|
||||
// Runs in the main thread, not QML thread
|
||||
Q_ASSERT(QThread::currentThread() == Controller::instance().connection()->thread());
|
||||
job = Controller::instance().connection()->getThumbnail(mediaId, requestedSize);
|
||||
Q_ASSERT(QThread::currentThread() == Controller::instance().activeConnection()->thread());
|
||||
job = Controller::instance().activeConnection()->getThumbnail(mediaId, requestedSize);
|
||||
// Connect to any possible outcome including abandonment
|
||||
// to make sure the QML thread is not left stuck forever.
|
||||
connect(job, &BaseJob::finished, this, &ThumbnailResponse::prepareResult);
|
||||
|
||||
Reference in New Issue
Block a user