From 0770f6e6b5099602def4966174ece8789996a78c Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Tue, 11 Apr 2017 02:35:09 +0300 Subject: [PATCH] Make the timer single shot --- include/ChatPage.h | 1 + include/MatrixClient.h | 1 + src/ChatPage.cc | 32 +++++++++++++++++++++----------- src/MatrixClient.cc | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/include/ChatPage.h b/include/ChatPage.h index d53d1a7f..4ee7441b 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -57,6 +57,7 @@ public slots: void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url); void initialSyncCompleted(const SyncResponse &response); void syncCompleted(const SyncResponse &response); + void syncFailed(const QString &msg); void changeTopRoomInfo(const RoomInfo &info); void sendTextMessage(const QString &msg); void messageSent(const QString event_id, int txn_id); diff --git a/include/MatrixClient.h b/include/MatrixClient.h index ae67af3a..decd14ff 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -67,6 +67,7 @@ signals: void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name); void initialSyncCompleted(const SyncResponse &response); void syncCompleted(const SyncResponse &response); + void syncFailed(const QString &msg); void messageSent(const QString &event_id, const int txn_id); private slots: diff --git a/src/ChatPage.cc b/src/ChatPage.cc index a5e86f1f..87aa8680 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -38,6 +38,7 @@ ChatPage::ChatPage(QWidget *parent) content_downloader_ = new QNetworkAccessManager(parent); room_list_ = new RoomList(this); + ui->sideBarMainLayout->addWidget(room_list_); top_bar_ = new TopRoomBar(this); ui->topBarLayout->addWidget(top_bar_); @@ -49,8 +50,10 @@ ChatPage::ChatPage(QWidget *parent) ui->contentLayout->addWidget(text_input_); user_info_widget_ = new UserInfoWidget(ui->sideBarTopWidget); + ui->sideBarTopUserInfoLayout->addWidget(user_info_widget_); sync_timer_ = new QTimer(this); + sync_timer_->setSingleShot(true); connect(sync_timer_, SIGNAL(timeout()), this, SLOT(startSync())); connect(user_info_widget_, SIGNAL(logout()), matrix_client_, SLOT(logout())); @@ -60,12 +63,10 @@ ChatPage::ChatPage(QWidget *parent) SIGNAL(roomChanged(const RoomInfo &)), this, SLOT(changeTopRoomInfo(const RoomInfo &))); - connect(room_list_, SIGNAL(roomChanged(const RoomInfo &)), view_manager_, SLOT(setHistoryView(const RoomInfo &))); - connect(room_list_, SIGNAL(fetchRoomAvatar(const QString &, const QUrl &)), this, @@ -76,21 +77,22 @@ ChatPage::ChatPage(QWidget *parent) this, SLOT(sendTextMessage(const QString &))); - ui->sideBarTopUserInfoLayout->addWidget(user_info_widget_); - ui->sideBarMainLayout->addWidget(room_list_); - connect(matrix_client_, - SIGNAL(initialSyncCompleted(SyncResponse)), + SIGNAL(initialSyncCompleted(const SyncResponse &)), this, - SLOT(initialSyncCompleted(SyncResponse))); + SLOT(initialSyncCompleted(const SyncResponse &))); connect(matrix_client_, - SIGNAL(syncCompleted(SyncResponse)), + SIGNAL(syncCompleted(const SyncResponse &)), this, - SLOT(syncCompleted(SyncResponse))); + SLOT(syncCompleted(const SyncResponse &))); connect(matrix_client_, - SIGNAL(getOwnProfileResponse(QUrl, QString)), + SIGNAL(syncFailed(const QString &)), this, - SLOT(updateOwnProfileInfo(QUrl, QString))); + SLOT(syncFailed(const QString &))); + connect(matrix_client_, + SIGNAL(getOwnProfileResponse(const QUrl &, const QString &)), + this, + SLOT(updateOwnProfileInfo(const QUrl &, const QString &))); connect(matrix_client_, SIGNAL(messageSent(QString, int)), this, @@ -160,12 +162,20 @@ void ChatPage::setOwnAvatar(const QByteArray &img) user_info_widget_->setAvatar(pixmap.toImage()); } +void ChatPage::syncFailed(const QString &msg) +{ + qWarning() << "Sync error:" << msg; + sync_timer_->start(sync_interval_ * 5); +} + void ChatPage::syncCompleted(const SyncResponse &response) { matrix_client_->setNextBatchToken(response.nextBatch()); /* room_list_->sync(response.rooms()); */ view_manager_->sync(response.rooms()); + + sync_timer_->start(sync_interval_); } void ChatPage::initialSyncCompleted(const SyncResponse &response) diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 86aeb179..fb7857c9 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -206,7 +206,7 @@ void MatrixClient::onSyncResponse(QNetworkReply *reply) int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (status == 0 || status >= 400) { - qWarning() << reply->errorString(); + emit syncFailed(reply->errorString()); return; }