aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp4
-rw-r--r--connection.h2
-rw-r--r--connectionprivate.cpp2
-rw-r--r--events/event.cpp37
-rw-r--r--events/roomaliasesevent.cpp3
-rw-r--r--events/roommessageevent.cpp2
-rw-r--r--events/typingevent.cpp2
-rw-r--r--events/unknownevent.cpp7
-rw-r--r--jobs/basejob.cpp12
-rw-r--r--jobs/basejob.h9
-rw-r--r--jobs/checkauthmethods.cpp6
-rw-r--r--jobs/checkauthmethods.h6
-rw-r--r--jobs/joinroomjob.cpp4
-rw-r--r--jobs/joinroomjob.h6
-rw-r--r--jobs/leaveroomjob.cpp4
-rw-r--r--jobs/leaveroomjob.h4
-rw-r--r--jobs/mediathumbnailjob.cpp6
-rw-r--r--jobs/mediathumbnailjob.h6
-rw-r--r--jobs/passwordlogin.cpp8
-rw-r--r--jobs/passwordlogin.h8
-rw-r--r--jobs/postmessagejob.cpp8
-rw-r--r--jobs/postmessagejob.h8
-rw-r--r--jobs/postreceiptjob.cpp4
-rw-r--r--jobs/postreceiptjob.h2
-rw-r--r--jobs/roommembersjob.cpp6
-rw-r--r--jobs/roommembersjob.h6
-rw-r--r--jobs/roommessagesjob.cpp6
-rw-r--r--jobs/roommessagesjob.h8
-rw-r--r--jobs/syncjob.cpp6
-rw-r--r--jobs/syncjob.h6
-rw-r--r--logging_util.h63
-rw-r--r--state.cpp2
-rw-r--r--user.cpp2
33 files changed, 169 insertions, 96 deletions
diff --git a/connection.cpp b/connection.cpp
index a219f1da..8d916280 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -79,6 +79,8 @@ void Connection::connectWithToken(QString userId, QString token)
d->isConnected = true;
d->userId = userId;
d->data->setToken(token);
+ qDebug() << "Connected with token:";
+ qDebug() << token;
emit connected();
}
@@ -175,7 +177,7 @@ User* Connection::user(QString userId)
User *Connection::user()
{
if( d->userId.isEmpty() )
- return 0;
+ return nullptr;
return user(d->userId);
}
diff --git a/connection.h b/connection.h
index 9f3d23f3..452db198 100644
--- a/connection.h
+++ b/connection.h
@@ -37,7 +37,7 @@ namespace QMatrixClient
class Connection: public QObject {
Q_OBJECT
public:
- Connection(QUrl server, QObject* parent=0);
+ Connection(QUrl server, QObject* parent = nullptr);
Connection();
virtual ~Connection();
diff --git a/connectionprivate.cpp b/connectionprivate.cpp
index bcca8744..62840473 100644
--- a/connectionprivate.cpp
+++ b/connectionprivate.cpp
@@ -39,7 +39,7 @@ ConnectionPrivate::ConnectionPrivate(Connection* parent)
: q(parent)
{
isConnected = false;
- data = 0;
+ data = nullptr;
}
ConnectionPrivate::~ConnectionPrivate()
diff --git a/events/event.cpp b/events/event.cpp
index 9a48108c..d05d666f 100644
--- a/events/event.cpp
+++ b/events/event.cpp
@@ -23,6 +23,7 @@
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
+#include "../logging_util.h"
#include "roommessageevent.h"
#include "roomnameevent.h"
#include "roomaliasesevent.h"
@@ -110,36 +111,38 @@ Event* Event::fromJson(const QJsonObject& obj)
}
if( obj.value("type").toString() == "m.typing" )
{
- qDebug() << "m.typing...";
return TypingEvent::fromJson(obj);
}
if( obj.value("type").toString() == "m.receipt" )
{
return ReceiptEvent::fromJson(obj);
}
- //qDebug() << "Unknown event";
return UnknownEvent::fromJson(obj);
}
bool Event::parseJson(const QJsonObject& obj)
{
d->originalJson = QString::fromUtf8(QJsonDocument(obj).toJson());
- bool correct = true;
- if( obj.contains("event_id") )
+ bool correct = (d->type != EventType::Unknown);
+ if ( d->type != EventType::Unknown && d->type != EventType::Typing )
{
- d->id = obj.value("event_id").toString();
- } else {
- correct = false;
- qDebug() << "Event: can't find event_id";
- }
- if( obj.contains("origin_server_ts") )
- {
- d->timestamp = QDateTime::fromMSecsSinceEpoch(
- static_cast<qint64>(obj.value("origin_server_ts").toDouble()), Qt::UTC );
- } else {
- correct = false;
- qDebug() << "Event: can't find ts";
- //qDebug() << obj;
+ if( obj.contains("event_id") )
+ {
+ d->id = obj.value("event_id").toString();
+ } else {
+ correct = false;
+ qDebug() << "Event: can't find event_id";
+ qDebug() << formatJson << obj;
+ }
+ if( obj.contains("origin_server_ts") )
+ {
+ d->timestamp = QDateTime::fromMSecsSinceEpoch(
+ static_cast<qint64>(obj.value("origin_server_ts").toDouble()), Qt::UTC );
+ } else {
+ correct = false;
+ qDebug() << "Event: can't find ts";
+ qDebug() << formatJson << obj;
+ }
}
if( obj.contains("room_id") )
{
diff --git a/events/roomaliasesevent.cpp b/events/roomaliasesevent.cpp
index 54fb5682..15b4c54e 100644
--- a/events/roomaliasesevent.cpp
+++ b/events/roomaliasesevent.cpp
@@ -64,7 +64,6 @@ QStringList RoomAliasesEvent::aliases() const
RoomAliasesEvent* RoomAliasesEvent::fromJson(const QJsonObject& obj)
{
- qDebug() << "RoomAliasesEvent::fromJson";
RoomAliasesEvent* e = new RoomAliasesEvent();
e->parseJson(obj);
const QJsonObject contents = obj.value("content").toObject();
@@ -73,6 +72,6 @@ RoomAliasesEvent* RoomAliasesEvent::fromJson(const QJsonObject& obj)
{
e->d->aliases << alias.toString();
}
- qDebug() << e->d->aliases;
+ qDebug() << "RoomAliasesEvent:" << e->d->aliases;
return e;
}
diff --git a/events/roommessageevent.cpp b/events/roommessageevent.cpp
index 99d17e5c..b7459054 100644
--- a/events/roommessageevent.cpp
+++ b/events/roommessageevent.cpp
@@ -39,7 +39,7 @@ RoomMessageEvent::RoomMessageEvent()
: Event(EventType::RoomMessage)
, d(new Private)
{
- d->content = 0;
+ d->content = nullptr;
}
RoomMessageEvent::~RoomMessageEvent()
diff --git a/events/typingevent.cpp b/events/typingevent.cpp
index 242094e1..36a7e693 100644
--- a/events/typingevent.cpp
+++ b/events/typingevent.cpp
@@ -19,6 +19,7 @@
#include "typingevent.h"
#include <QtCore/QJsonArray>
+#include <QtCore/QDebug>
using namespace QMatrixClient;
@@ -53,5 +54,6 @@ TypingEvent* TypingEvent::fromJson(const QJsonObject& obj)
{
e->d->users << user.toString();
}
+ qDebug() << "Typing:" << e->d->users;
return e;
}
diff --git a/events/unknownevent.cpp b/events/unknownevent.cpp
index 758d0ec8..90551409 100644
--- a/events/unknownevent.cpp
+++ b/events/unknownevent.cpp
@@ -19,6 +19,9 @@
#include "unknownevent.h"
#include <QtCore/QJsonDocument>
+#include <QtCore/QDebug>
+
+#include "../logging_util.h"
using namespace QMatrixClient;
@@ -56,5 +59,7 @@ UnknownEvent* UnknownEvent::fromJson(const QJsonObject& obj)
e->parseJson(obj);
e->d->type = obj.value("type").toString();
e->d->content = QString::fromUtf8(QJsonDocument(obj).toJson());
+ qDebug() << "UnknownEvent, JSON follows:";
+ qDebug() << formatJson << obj;
return e;
-} \ No newline at end of file
+}
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index cfdf8a28..50c85048 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -31,7 +31,7 @@ class BaseJob::Private
{
public:
Private(ConnectionData* c, JobHttpType t, bool nt)
- : connection(c), reply(0), type(t), needsToken(nt) {}
+ : connection(c), reply(nullptr), type(t), needsToken(nt) {}
ConnectionData* connection;
QNetworkReply* reply;
@@ -39,7 +39,7 @@ class BaseJob::Private
bool needsToken;
};
-BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, bool needsToken)
+BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, QString name, bool needsToken)
: d(new Private(connection, type, needsToken))
{
// Work around KJob inability to separate success and failure signals
@@ -49,6 +49,7 @@ BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, bool needsToken)
else
emit failure(this);
});
+ setObjectName(name);
}
BaseJob::~BaseJob()
@@ -67,12 +68,12 @@ ConnectionData* BaseJob::connection() const
return d->connection;
}
-QJsonObject BaseJob::data()
+QJsonObject BaseJob::data() const
{
return QJsonObject();
}
-QUrlQuery BaseJob::query()
+QUrlQuery BaseJob::query() const
{
return QUrlQuery();
}
@@ -121,7 +122,7 @@ void BaseJob::fail(int errorCode, QString errorString)
setErrorText( errorString );
if( d->reply->isRunning() )
d->reply->abort();
- qWarning() << this << "failed:" << errorString;
+ qWarning() << "Job" << objectName() << "failed:" << errorString;
emitResult();
}
@@ -155,7 +156,6 @@ void BaseJob::gotReply()
void BaseJob::timeout()
{
- qDebug() << "Timeout!";
fail( TimeoutError, "The job has timed out" );
}
diff --git a/jobs/basejob.h b/jobs/basejob.h
index f1ad66d1..98b7358b 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -40,7 +40,8 @@ namespace QMatrixClient
{
Q_OBJECT
public:
- BaseJob(ConnectionData* connection, JobHttpType type, bool needsToken=true);
+ BaseJob(ConnectionData* connection, JobHttpType type,
+ QString name, bool needsToken=true);
virtual ~BaseJob();
void start() override;
@@ -63,9 +64,9 @@ namespace QMatrixClient
ConnectionData* connection() const;
// to implement
- virtual QString apiPath()=0;
- virtual QUrlQuery query();
- virtual QJsonObject data();
+ virtual QString apiPath() const = 0;
+ virtual QUrlQuery query() const;
+ virtual QJsonObject data() const;
virtual void parseJson(const QJsonDocument& data);
void fail( int errorCode, QString errorString );
diff --git a/jobs/checkauthmethods.cpp b/jobs/checkauthmethods.cpp
index 18b5f9a5..55d8632a 100644
--- a/jobs/checkauthmethods.cpp
+++ b/jobs/checkauthmethods.cpp
@@ -37,7 +37,7 @@ class CheckAuthMethods::Private
};
CheckAuthMethods::CheckAuthMethods(ConnectionData* connection)
- : BaseJob(connection, JobHttpType::GetJob, false)
+ : BaseJob(connection, JobHttpType::GetJob, "CheckAuthMethods", false)
, d(new Private)
{
}
@@ -52,7 +52,7 @@ QString CheckAuthMethods::session()
return d->session;
}
-QString CheckAuthMethods::apiPath()
+QString CheckAuthMethods::apiPath() const
{
return "_matrix/client/r0/login";
}
@@ -60,4 +60,4 @@ QString CheckAuthMethods::apiPath()
void CheckAuthMethods::parseJson(const QJsonDocument& data)
{
// TODO
-} \ No newline at end of file
+}
diff --git a/jobs/checkauthmethods.h b/jobs/checkauthmethods.h
index 2c9ab61a..197f7aa7 100644
--- a/jobs/checkauthmethods.h
+++ b/jobs/checkauthmethods.h
@@ -35,8 +35,8 @@ namespace QMatrixClient
QString session();
protected:
- QString apiPath();
- void parseJson(const QJsonDocument& data);
+ QString apiPath() const override;
+ void parseJson(const QJsonDocument& data) override;
private:
class Private;
@@ -44,4 +44,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_CHECKAUTHMETHODS_H \ No newline at end of file
+#endif // QMATRIXCLIENT_CHECKAUTHMETHODS_H
diff --git a/jobs/joinroomjob.cpp b/jobs/joinroomjob.cpp
index 85a331fa..799d4926 100644
--- a/jobs/joinroomjob.cpp
+++ b/jobs/joinroomjob.cpp
@@ -33,7 +33,7 @@ class JoinRoomJob::Private
};
JoinRoomJob::JoinRoomJob(ConnectionData* data, QString roomAlias)
- : BaseJob(data, JobHttpType::PostJob)
+ : BaseJob(data, JobHttpType::PostJob, "JoinRoomJob")
, d(new Private)
{
d->roomAlias = roomAlias;
@@ -49,7 +49,7 @@ QString JoinRoomJob::roomId()
return d->roomId;
}
-QString JoinRoomJob::apiPath()
+QString JoinRoomJob::apiPath() const
{
return QString("_matrix/client/r0/join/%1").arg(d->roomAlias);
}
diff --git a/jobs/joinroomjob.h b/jobs/joinroomjob.h
index 8f4059f2..1329ca56 100644
--- a/jobs/joinroomjob.h
+++ b/jobs/joinroomjob.h
@@ -34,8 +34,8 @@ namespace QMatrixClient
QString roomId();
protected:
- QString apiPath();
- void parseJson(const QJsonDocument& data);
+ QString apiPath() const override;
+ void parseJson(const QJsonDocument& data) override;
private:
class Private;
@@ -43,4 +43,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_JOINROOMJOB_H \ No newline at end of file
+#endif // QMATRIXCLIENT_JOINROOMJOB_H
diff --git a/jobs/leaveroomjob.cpp b/jobs/leaveroomjob.cpp
index 1adab31f..b29c80ed 100644
--- a/jobs/leaveroomjob.cpp
+++ b/jobs/leaveroomjob.cpp
@@ -34,7 +34,7 @@ class LeaveRoomJob::Private
};
LeaveRoomJob::LeaveRoomJob(ConnectionData* data, Room* room)
- : BaseJob(data, JobHttpType::PostJob)
+ : BaseJob(data, JobHttpType::PostJob, "LeaveRoomJob")
, d(new Private(room))
{
}
@@ -44,7 +44,7 @@ LeaveRoomJob::~LeaveRoomJob()
delete d;
}
-QString LeaveRoomJob::apiPath()
+QString LeaveRoomJob::apiPath() const
{
return QString("_matrix/client/r0/rooms/%1/leave").arg(d->room->id());
}
diff --git a/jobs/leaveroomjob.h b/jobs/leaveroomjob.h
index 535c44b8..9ce9bf4a 100644
--- a/jobs/leaveroomjob.h
+++ b/jobs/leaveroomjob.h
@@ -33,7 +33,7 @@ namespace QMatrixClient
virtual ~LeaveRoomJob();
protected:
- QString apiPath();
+ QString apiPath() const override;
private:
class Private;
@@ -41,4 +41,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_LEAVEROOMJOB_H \ No newline at end of file
+#endif // QMATRIXCLIENT_LEAVEROOMJOB_H
diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp
index 02d9bbd9..48ed0ffb 100644
--- a/jobs/mediathumbnailjob.cpp
+++ b/jobs/mediathumbnailjob.cpp
@@ -34,7 +34,7 @@ class MediaThumbnailJob::Private
MediaThumbnailJob::MediaThumbnailJob(ConnectionData* data, QUrl url, int requestedWidth, int requestedHeight,
ThumbnailType thumbnailType)
- : BaseJob(data, JobHttpType::GetJob)
+ : BaseJob(data, JobHttpType::GetJob, "MediaThumbnailJob")
, d(new Private)
{
d->url = url;
@@ -53,12 +53,12 @@ QPixmap MediaThumbnailJob::thumbnail()
return d->thumbnail;
}
-QString MediaThumbnailJob::apiPath()
+QString MediaThumbnailJob::apiPath() const
{
return QString("/_matrix/media/v1/thumbnail/%1/%2").arg(d->url.host()).arg(d->url.path());
}
-QUrlQuery MediaThumbnailJob::query()
+QUrlQuery MediaThumbnailJob::query() const
{
QUrlQuery query;
query.addQueryItem("width", QString::number(d->requestedWidth));
diff --git a/jobs/mediathumbnailjob.h b/jobs/mediathumbnailjob.h
index 85dc8251..df7c1832 100644
--- a/jobs/mediathumbnailjob.h
+++ b/jobs/mediathumbnailjob.h
@@ -38,8 +38,8 @@ namespace QMatrixClient
QPixmap thumbnail();
protected:
- QString apiPath() override;
- QUrlQuery query() override;
+ QString apiPath() const override;
+ QUrlQuery query() const override;
protected slots:
void gotReply() override;
@@ -50,4 +50,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_MEDIATHUMBNAILJOB_H \ No newline at end of file
+#endif // QMATRIXCLIENT_MEDIATHUMBNAILJOB_H
diff --git a/jobs/passwordlogin.cpp b/jobs/passwordlogin.cpp
index d989815f..9f0cb2e1 100644
--- a/jobs/passwordlogin.cpp
+++ b/jobs/passwordlogin.cpp
@@ -39,7 +39,7 @@ class PasswordLogin::Private
};
PasswordLogin::PasswordLogin(ConnectionData* connection, QString user, QString password)
- : BaseJob(connection, JobHttpType::PostJob, false)
+ : BaseJob(connection, JobHttpType::PostJob, "PasswordLogin", false)
, d(new Private)
{
d->user = user;
@@ -66,12 +66,12 @@ QString PasswordLogin::server()
return d->returned_server;
}
-QString PasswordLogin::apiPath()
+QString PasswordLogin::apiPath() const
{
return "_matrix/client/r0/login";
}
-QJsonObject PasswordLogin::data()
+QJsonObject PasswordLogin::data() const
{
QJsonObject json;
json.insert("type", "m.login.password");
@@ -88,9 +88,7 @@ void PasswordLogin::parseJson(const QJsonDocument& data)
fail( BaseJob::UserDefinedError, "Unexpected data" );
}
d->returned_token = json.value("access_token").toString();
- qDebug() << d->returned_token;
d->returned_server = json.value("home_server").toString();
d->returned_id = json.value("user_id").toString();
- connection()->setToken(d->returned_token);
emitResult();
}
diff --git a/jobs/passwordlogin.h b/jobs/passwordlogin.h
index 19df118e..5e93e74e 100644
--- a/jobs/passwordlogin.h
+++ b/jobs/passwordlogin.h
@@ -37,9 +37,9 @@ namespace QMatrixClient
QString server();
protected:
- QString apiPath();
- QJsonObject data();
- void parseJson(const QJsonDocument& data);
+ QString apiPath() const override;
+ QJsonObject data() const override;
+ void parseJson(const QJsonDocument& data) override;
private:
class Private;
@@ -47,4 +47,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_PASSWORDLOGIN_H \ No newline at end of file
+#endif // QMATRIXCLIENT_PASSWORDLOGIN_H
diff --git a/jobs/postmessagejob.cpp b/jobs/postmessagejob.cpp
index 67c79669..cf9b94fd 100644
--- a/jobs/postmessagejob.cpp
+++ b/jobs/postmessagejob.cpp
@@ -35,7 +35,7 @@ class PostMessageJob::Private
};
PostMessageJob::PostMessageJob(ConnectionData* connection, Room* room, QString type, QString message)
- : BaseJob(connection, JobHttpType::PostJob)
+ : BaseJob(connection, JobHttpType::PostJob, "PostMessageJob")
, d(new Private)
{
d->type = type;
@@ -48,12 +48,12 @@ PostMessageJob::~PostMessageJob()
delete d;
}
-QString PostMessageJob::apiPath()
+QString PostMessageJob::apiPath() const
{
return QString("_matrix/client/r0/rooms/%1/send/m.room.message").arg(d->room->id());
}
-QJsonObject PostMessageJob::data()
+QJsonObject PostMessageJob::data() const
{
QJsonObject json;
json.insert("msgtype", d->type);
@@ -71,4 +71,4 @@ void PostMessageJob::parseJson(const QJsonDocument& data)
return;
}
emitResult();
-} \ No newline at end of file
+}
diff --git a/jobs/postmessagejob.h b/jobs/postmessagejob.h
index 7f40534e..1917ef25 100644
--- a/jobs/postmessagejob.h
+++ b/jobs/postmessagejob.h
@@ -34,9 +34,9 @@ namespace QMatrixClient
//bool success();
protected:
- QString apiPath();
- QJsonObject data();
- void parseJson(const QJsonDocument& data);
+ QString apiPath() const override;
+ QJsonObject data() const override;
+ void parseJson(const QJsonDocument& data) override;
private:
class Private;
@@ -44,4 +44,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_POSTMESSAGEJOB_H \ No newline at end of file
+#endif // QMATRIXCLIENT_POSTMESSAGEJOB_H
diff --git a/jobs/postreceiptjob.cpp b/jobs/postreceiptjob.cpp
index c26186e8..f99b6869 100644
--- a/jobs/postreceiptjob.cpp
+++ b/jobs/postreceiptjob.cpp
@@ -34,7 +34,7 @@ class PostReceiptJob::Private
};
PostReceiptJob::PostReceiptJob(ConnectionData* connection, QString roomId, QString eventId)
- : BaseJob(connection, JobHttpType::PostJob)
+ : BaseJob(connection, JobHttpType::PostJob, "PostReceiptJob")
, d(new Private)
{
d->roomId = roomId;
@@ -46,7 +46,7 @@ PostReceiptJob::~PostReceiptJob()
delete d;
}
-QString PostReceiptJob::apiPath()
+QString PostReceiptJob::apiPath() const
{
return QString("/_matrix/client/r0/rooms/%1/receipt/m.read/%2").arg(d->roomId).arg(d->eventId);
}
diff --git a/jobs/postreceiptjob.h b/jobs/postreceiptjob.h
index 2767fa9a..c5224af5 100644
--- a/jobs/postreceiptjob.h
+++ b/jobs/postreceiptjob.h
@@ -32,7 +32,7 @@ namespace QMatrixClient
virtual ~PostReceiptJob();
protected:
- QString apiPath();
+ QString apiPath() const override;
private:
class Private;
diff --git a/jobs/roommembersjob.cpp b/jobs/roommembersjob.cpp
index e12bc6c4..c16ba481 100644
--- a/jobs/roommembersjob.cpp
+++ b/jobs/roommembersjob.cpp
@@ -34,7 +34,7 @@ class RoomMembersJob::Private
};
RoomMembersJob::RoomMembersJob(ConnectionData* data, Room* room)
- : BaseJob(data, JobHttpType::GetJob)
+ : BaseJob(data, JobHttpType::GetJob, "RoomMembersJob")
, d(new Private)
{
d->room = room;
@@ -50,7 +50,7 @@ QList< State* > RoomMembersJob::states()
return d->states;
}
-QString RoomMembersJob::apiPath()
+QString RoomMembersJob::apiPath() const
{
return QString("_matrix/client/r0/rooms/%1/members").arg(d->room->id());
}
@@ -67,4 +67,4 @@ void RoomMembersJob::parseJson(const QJsonDocument& data)
}
qDebug() << "States: " << d->states.count();
emitResult();
-} \ No newline at end of file
+}
diff --git a/jobs/roommembersjob.h b/jobs/roommembersjob.h
index 0349aa02..ffae4309 100644
--- a/jobs/roommembersjob.h
+++ b/jobs/roommembersjob.h
@@ -35,8 +35,8 @@ namespace QMatrixClient
QList<State*> states();
protected:
- virtual QString apiPath();
- virtual void parseJson(const QJsonDocument& data);
+ virtual QString apiPath() const override;
+ virtual void parseJson(const QJsonDocument& data) override;
private:
class Private;
@@ -44,4 +44,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_ROOMMEMBERSJOB_H \ No newline at end of file
+#endif // QMATRIXCLIENT_ROOMMEMBERSJOB_H
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp
index 5a97cc23..f1943d2c 100644
--- a/jobs/roommessagesjob.cpp
+++ b/jobs/roommessagesjob.cpp
@@ -40,7 +40,7 @@ class RoomMessagesJob::Private
};
RoomMessagesJob::RoomMessagesJob(ConnectionData* data, Room* room, QString from, FetchDirectory dir, int limit)
- : BaseJob(data, JobHttpType::GetJob)
+ : BaseJob(data, JobHttpType::GetJob, "RoomMessagesJob")
{
d = new Private();
d->room = room;
@@ -64,12 +64,12 @@ QString RoomMessagesJob::end()
return d->end;
}
-QString RoomMessagesJob::apiPath()
+QString RoomMessagesJob::apiPath() const
{
return QString("/_matrix/client/r0/rooms/%1/messages").arg(d->room->id());
}
-QUrlQuery RoomMessagesJob::query()
+QUrlQuery RoomMessagesJob::query() const
{
QUrlQuery query;
query.addQueryItem("from", d->from);
diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h
index 2a12ac08..6160dc57 100644
--- a/jobs/roommessagesjob.h
+++ b/jobs/roommessagesjob.h
@@ -39,9 +39,9 @@ namespace QMatrixClient
QString end();
protected:
- QString apiPath();
- QUrlQuery query();
- void parseJson(const QJsonDocument& data);
+ QString apiPath() const override;
+ QUrlQuery query() const override;
+ void parseJson(const QJsonDocument& data) override;
private:
class Private;
@@ -49,4 +49,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_ROOMMESSAGESJOB_H \ No newline at end of file
+#endif // QMATRIXCLIENT_ROOMMESSAGESJOB_H
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
index 6b8ec510..37f79298 100644
--- a/jobs/syncjob.cpp
+++ b/jobs/syncjob.cpp
@@ -44,7 +44,7 @@ class SyncJob::Private
};
SyncJob::SyncJob(ConnectionData* connection, QString since)
- : BaseJob(connection, JobHttpType::GetJob)
+ : BaseJob(connection, JobHttpType::GetJob, "SyncJob")
, d(new Private)
{
d->since = since;
@@ -87,12 +87,12 @@ QList<SyncRoomData> SyncJob::roomData() const
return d->roomData;
}
-QString SyncJob::apiPath()
+QString SyncJob::apiPath() const
{
return "_matrix/client/r0/sync";
}
-QUrlQuery SyncJob::query()
+QUrlQuery SyncJob::query() const
{
QUrlQuery query;
if( !d->filter.isEmpty() )
diff --git a/jobs/syncjob.h b/jobs/syncjob.h
index abbef23a..19dd4646 100644
--- a/jobs/syncjob.h
+++ b/jobs/syncjob.h
@@ -72,9 +72,9 @@ namespace QMatrixClient
QString nextBatch() const;
protected:
- QString apiPath();
- QUrlQuery query();
- void parseJson(const QJsonDocument& data);
+ QString apiPath() const override;
+ QUrlQuery query() const override;
+ void parseJson(const QJsonDocument& data) override;
private:
class Private;
diff --git a/logging_util.h b/logging_util.h
new file mode 100644
index 00000000..47b2e062
--- /dev/null
+++ b/logging_util.h
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * Copyright (C) 2016 Kitsune Ral <kitsune-ral@users.sf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file logging_util.h - a collection of utilities to facilitate debug logging.
+ */
+
+#pragma once
+
+#include <QtCore/QDebug>
+
+namespace QMatrixClient {
+
+// QDebug manipulators
+
+using QDebugManip = QDebug (*)(QDebug);
+
+/**
+ * @brief QDebug manipulator to setup the stream for JSON output.
+ *
+ * Originally made to encapsulate the change in QDebug behavior in Qt 5.4
+ * and the respective addition of QDebug::noquote().
+ * Together with the operator<<() helper, the proposed usage is
+ * (similar to std:: I/O manipulators):
+ *
+ * @example qDebug() << formatJson << json_object; // (QJsonObject, or QJsonValue, etc.)
+ */
+static QDebugManip formatJson = [](QDebug debug_object) {
+#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
+ return debug_object;
+#else
+ return debug_object.noquote();
+#endif
+ };
+
+/**
+ * @brief A helper operator to facilitate using formatJson (and possibly other manipulators)
+ *
+ * @param debug_object to output the json to
+ * @param qdm a QDebug manipulator
+ * @return a copy of debug_object that has its mode altered by qdm
+ */
+inline QDebug operator<< (QDebug debug_object, QDebugManip qdm) {
+ return qdm(debug_object);
+}
+
+}
+
diff --git a/state.cpp b/state.cpp
index ed57bea4..59a3b007 100644
--- a/state.cpp
+++ b/state.cpp
@@ -61,7 +61,7 @@ State* State::fromJson(const QJsonObject& obj)
{
Event* event = Event::fromJson(obj);
if( !event )
- return 0;
+ return nullptr;
State* state = new State(event);
state->d->stateKey = obj.value("state_key").toString();
state->d->replacesState = obj.value("replaces_state").toString();
diff --git a/user.cpp b/user.cpp
index 5018fe83..6bef0de1 100644
--- a/user.cpp
+++ b/user.cpp
@@ -87,7 +87,7 @@ QPixmap User::avatar(int width, int height)
{
if( !d->avatarOngoingRequest && d->avatarUrl.isValid() )
{
- qDebug() << "Get avatar...";
+ qDebug() << "Getting avatar for" << id();
d->requestedWidth = width;
d->requestedHeight = height;
d->avatarOngoingRequest = true;