summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-06 19:56:33 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-06 19:56:33 +0300
commit73e73f46eaff4f2236b31ed5858738c6b5e26ea3 (patch)
tree3af375ca4be03bacb34aa72b173dd22a9f792380 /src
parentInitialize sync timer (diff)
downloadnheko-73e73f46eaff4f2236b31ed5858738c6b5e26ea3.tar.xz
Use const refs for the deserialized data
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cc8
-rw-r--r--src/HistoryView.cc4
-rw-r--r--src/HistoryViewItem.cc2
-rw-r--r--src/Login.cc27
-rw-r--r--src/MatrixClient.cc6
-rw-r--r--src/Profile.cc12
-rw-r--r--src/Sync.cc92
7 files changed, 16 insertions, 135 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc

index 732e3651..b5707cb9 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc
@@ -124,7 +124,7 @@ void ChatPage::startSync() matrix_client_->sync(); } -void ChatPage::setOwnAvatar(QByteArray img) +void ChatPage::setOwnAvatar(const QByteArray &img) { if (img.size() == 0) return; @@ -134,7 +134,7 @@ void ChatPage::setOwnAvatar(QByteArray img) user_info_widget_->setAvatar(pixmap.toImage()); } -void ChatPage::syncCompleted(SyncResponse response) +void ChatPage::syncCompleted(const SyncResponse &response) { matrix_client_->setNextBatchToken(response.nextBatch()); @@ -142,7 +142,7 @@ void ChatPage::syncCompleted(SyncResponse response) view_manager_->sync(response.rooms()); } -void ChatPage::initialSyncCompleted(SyncResponse response) +void ChatPage::initialSyncCompleted(const SyncResponse &response) { if (!response.nextBatch().isEmpty()) matrix_client_->setNextBatchToken(response.nextBatch()); @@ -210,7 +210,7 @@ void ChatPage::fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url) }); } -void ChatPage::updateOwnProfileInfo(QUrl avatar_url, QString display_name) +void ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name) { QSettings settings; auto userid = settings.value("auth/user_id").toString(); diff --git a/src/HistoryView.cc b/src/HistoryView.cc
index 0949d17c..3775db9a 100644 --- a/src/HistoryView.cc +++ b/src/HistoryView.cc
@@ -50,7 +50,7 @@ const QList<QString> HistoryView::COLORS({"#FFF46E", "#a2b636", "#4BBE2E"}); -HistoryView::HistoryView(QList<Event> events, QWidget *parent) +HistoryView::HistoryView(const QList<Event> &events, QWidget *parent) : QWidget(parent) { init(); @@ -133,7 +133,7 @@ void HistoryView::init() SLOT(sliderRangeChanged(int, int))); } -void HistoryView::addHistoryItem(Event event, QString color, bool with_sender) +void HistoryView::addHistoryItem(const Event &event, const QString &color, bool with_sender) { // TODO: Probably create another function instead of passing the flag. HistoryViewItem *item = new HistoryViewItem(event, with_sender, color, scroll_widget_); diff --git a/src/HistoryViewItem.cc b/src/HistoryViewItem.cc
index 04c42f45..84890185 100644 --- a/src/HistoryViewItem.cc +++ b/src/HistoryViewItem.cc
@@ -20,7 +20,7 @@ #include "HistoryViewItem.h" -HistoryViewItem::HistoryViewItem(Event event, bool with_sender, QString color, QWidget *parent) +HistoryViewItem::HistoryViewItem(const Event &event, bool with_sender, const QString &color, QWidget *parent) : QWidget(parent) { QString sender = ""; diff --git a/src/Login.cc b/src/Login.cc
index f3b8e2f4..0ce05a80 100644 --- a/src/Login.cc +++ b/src/Login.cc
@@ -42,32 +42,7 @@ QByteArray LoginRequest::serialize() return QJsonDocument(body).toJson(QJsonDocument::Compact); } -void LoginRequest::setPassword(QString password) -{ - password_ = password; -} - -void LoginRequest::setUser(QString username) -{ - user_ = username; -} - -QString LoginResponse::getAccessToken() -{ - return access_token_; -} - -QString LoginResponse::getHomeServer() -{ - return home_server_; -} - -QString LoginResponse::getUserId() -{ - return user_id_; -} - -void LoginResponse::deserialize(QJsonDocument data) throw(DeserializationException) +void LoginResponse::deserialize(const QJsonDocument &data) throw(DeserializationException) { if (!data.isObject()) throw DeserializationException("Login response is not a JSON object"); diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc
index 5510b6d9..725aede6 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc
@@ -42,10 +42,6 @@ MatrixClient::MatrixClient(QString server, QObject *parent) connect(this, SIGNAL(finished(QNetworkReply *)), this, SLOT(onResponse(QNetworkReply *))); } -MatrixClient::~MatrixClient() -{ -} - void MatrixClient::onVersionsResponse(QNetworkReply *reply) { reply->deleteLater(); @@ -289,7 +285,7 @@ void MatrixClient::sync() reply->setProperty("endpoint", Endpoint::Sync); } -void MatrixClient::sendTextMessage(QString roomid, QString msg) +void MatrixClient::sendTextMessage(const QString &roomid, const QString &msg) { QUrlQuery query; query.addQueryItem("access_token", token_); diff --git a/src/Profile.cc b/src/Profile.cc
index aa556370..2322834a 100644 --- a/src/Profile.cc +++ b/src/Profile.cc
@@ -22,17 +22,7 @@ #include "Deserializable.h" #include "Profile.h" -QUrl ProfileResponse::getAvatarUrl() -{ - return avatar_url_; -} - -QString ProfileResponse::getDisplayName() -{ - return display_name_; -} - -void ProfileResponse::deserialize(QJsonDocument data) throw(DeserializationException) +void ProfileResponse::deserialize(const QJsonDocument &data) throw(DeserializationException) { if (!data.isObject()) throw DeserializationException("Profile response is not a JSON object"); diff --git a/src/Sync.cc b/src/Sync.cc
index 3ba6d220..b51ecff7 100644 --- a/src/Sync.cc +++ b/src/Sync.cc
@@ -24,12 +24,7 @@ #include "Deserializable.h" #include "Sync.h" -QString SyncResponse::nextBatch() const -{ - return next_batch_; -} - -void SyncResponse::deserialize(QJsonDocument data) throw(DeserializationException) +void SyncResponse::deserialize(const QJsonDocument &data) throw(DeserializationException) { if (!data.isObject()) throw DeserializationException("Sync response is not a JSON object"); @@ -46,17 +41,7 @@ void SyncResponse::deserialize(QJsonDocument data) throw(DeserializationExceptio next_batch_ = object.value("next_batch").toString(); } -Rooms SyncResponse::rooms() const -{ - return rooms_; -} - -QMap<QString, JoinedRoom> Rooms::join() const -{ - return join_; -} - -void Rooms::deserialize(QJsonValue data) throw(DeserializationException) +void Rooms::deserialize(const QJsonValue &data) throw(DeserializationException) { if (!data.isObject()) throw DeserializationException("Rooms value is not a JSON object"); @@ -96,17 +81,7 @@ void Rooms::deserialize(QJsonValue data) throw(DeserializationException) } } -State JoinedRoom::state() const -{ - return state_; -} - -Timeline JoinedRoom::timeline() const -{ - return timeline_; -} - -void JoinedRoom::deserialize(QJsonValue data) throw(DeserializationException) +void JoinedRoom::deserialize(const QJsonValue &data) throw(DeserializationException) { if (!data.isObject()) throw DeserializationException("JoinedRoom is not a JSON object"); @@ -137,42 +112,7 @@ void JoinedRoom::deserialize(QJsonValue data) throw(DeserializationException) timeline_.deserialize(object.value("timeline")); } -QJsonObject Event::content() const -{ - return content_; -} - -QJsonObject Event::unsigned_content() const -{ - return unsigned_; -} - -QString Event::sender() const -{ - return sender_; -} - -QString Event::state_key() const -{ - return state_key_; -} - -QString Event::type() const -{ - return type_; -} - -QString Event::eventId() const -{ - return event_id_; -} - -uint64_t Event::timestamp() const -{ - return origin_server_ts_; -} - -void Event::deserialize(QJsonValue data) throw(DeserializationException) +void Event::deserialize(const QJsonValue &data) throw(DeserializationException) { if (!data.isObject()) throw DeserializationException("Event is not a JSON object"); @@ -212,12 +152,7 @@ void Event::deserialize(QJsonValue data) throw(DeserializationException) origin_server_ts_ = object.value("origin_server_ts").toDouble(); } -QList<Event> State::events() const -{ - return events_; -} - -void State::deserialize(QJsonValue data) throw(DeserializationException) +void State::deserialize(const QJsonValue &data) throw(DeserializationException) { if (!data.isArray()) throw DeserializationException("State is not a JSON array"); @@ -237,22 +172,7 @@ void State::deserialize(QJsonValue data) throw(DeserializationException) } } -QList<Event> Timeline::events() const -{ - return events_; -} - -QString Timeline::previousBatch() const -{ - return prev_batch_; -} - -bool Timeline::limited() const -{ - return limited_; -} - -void Timeline::deserialize(QJsonValue data) throw(DeserializationException) +void Timeline::deserialize(const QJsonValue &data) throw(DeserializationException) { if (!data.isObject()) throw DeserializationException("Timeline is not a JSON object");