Use const refs for the deserialized data

This commit is contained in:
Konstantinos Sideris 2017-04-06 19:56:33 +03:00
parent 5bcaaa3aa3
commit 73e73f46ea
19 changed files with 198 additions and 196 deletions

View file

@ -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();

View file

@ -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_);

View file

@ -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 = "";

View file

@ -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");

View file

@ -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_);

View file

@ -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");

View file

@ -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");