From 0b7bee1e2600ee80554aa85b18d30ca1964535a0 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 6 May 2016 21:31:14 +0900 Subject: Use lambda captures instead of throwing job pointers around --- connection.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index e04de7aa..bf19a16e 100644 --- a/connection.cpp +++ b/connection.cpp @@ -62,7 +62,13 @@ void Connection::resolveServer(QString domain) void Connection::connectToServer(QString user, QString password) { PasswordLogin* loginJob = new PasswordLogin(d->data, user, password); - connect( loginJob, &PasswordLogin::result, d, &ConnectionPrivate::connectDone ); + connect( loginJob, &PasswordLogin::success, [=] () { + qDebug() << "Our user ID: " << d->userId; + connectWithToken(loginJob->id(), loginJob->token()); + }); + connect( loginJob, &PasswordLogin::failure, [=] () { + emit loginError(loginJob->errorString()); + }); loginJob->start(); d->username = user; // to be able to reconnect d->password = password; @@ -79,7 +85,14 @@ void Connection::connectWithToken(QString userId, QString token) void Connection::reconnect() { PasswordLogin* loginJob = new PasswordLogin(d->data, d->username, d->password ); - connect( loginJob, &PasswordLogin::result, d, &ConnectionPrivate::reconnectDone ); + connect( loginJob, &PasswordLogin::success, [=] () { + d->userId = loginJob->id(); + emit reconnected(); + }); + connect( loginJob, &PasswordLogin::failure, [=] () { + emit loginError(loginJob->errorString()); + d->isConnected = false; + }); loginJob->start(); } @@ -89,7 +102,13 @@ SyncJob* Connection::sync(int timeout) SyncJob* syncJob = new SyncJob(d->data, d->data->lastEvent()); syncJob->setFilter(filter); syncJob->setTimeout(timeout); - connect( syncJob, &SyncJob::result, d, &ConnectionPrivate::syncDone ); + connect( syncJob, &SyncJob::success, [=] () { + d->data->setLastEvent(syncJob->nextBatch()); + d->processRooms(syncJob->roomData()); + emit syncDone(); + }); + connect( syncJob, &SyncJob::failure, + [=] () { emit connectionError(syncJob->errorString());}); syncJob->start(); return syncJob; } @@ -110,7 +129,10 @@ PostReceiptJob* Connection::postReceipt(Room* room, Event* event) void Connection::joinRoom(QString roomAlias) { JoinRoomJob* job = new JoinRoomJob(d->data, roomAlias); - connect( job, &JoinRoomJob::result, d, &ConnectionPrivate::gotJoinRoom ); + connect( job, &SyncJob::success, [=] () { + if ( Room* r = d->provideRoom(job->roomId()) ) + emit joinedRoom(r); + }); job->start(); } -- cgit v1.2.3 From 5a0e6080a6245aa2c68f254d7105f19629a5a654 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 7 May 2016 18:13:51 +0900 Subject: Minors: one fix, one cleanup --- connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index bf19a16e..a219f1da 100644 --- a/connection.cpp +++ b/connection.cpp @@ -63,7 +63,7 @@ void Connection::connectToServer(QString user, QString password) { PasswordLogin* loginJob = new PasswordLogin(d->data, user, password); connect( loginJob, &PasswordLogin::success, [=] () { - qDebug() << "Our user ID: " << d->userId; + qDebug() << "Our user ID: " << loginJob->id(); connectWithToken(loginJob->id(), loginJob->token()); }); connect( loginJob, &PasswordLogin::failure, [=] () { -- cgit v1.2.3