From af5fb5e0ffec87d59a7b0df778d226efc3132e57 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 11 Apr 2016 10:44:46 +0900 Subject: Minor fixes and cleanup 1. Remove accidental trailing \ 2. Show the contents of NetworkError in logs --- jobs/basejob.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index b7e1b718..bf4ade89 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -81,7 +81,7 @@ void BaseJob::start() QNetworkRequest req = QNetworkRequest(url); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);\ + req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); req.setMaximumRedirectsAllowed(10); #endif QJsonDocument data = QJsonDocument(this->data()); @@ -124,7 +124,7 @@ void BaseJob::gotReply() { if( d->reply->error() != QNetworkReply::NoError ) { - qDebug() << "NetworkError!!!"; + qDebug() << "NetworkError!!!" << d->reply->error(); fail( NetworkError, d->reply->errorString() ); return; } -- cgit v1.2.3 From 1f52b9cc31105d78fc24251fa201d9ae43dd8c33 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 11 Apr 2016 10:45:48 +0900 Subject: Don't put excess whitespaces in log lines before QStrings - Qt inserts them automatically. --- room.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/room.cpp b/room.cpp index 07128844..11faf104 100644 --- a/room.cpp +++ b/room.cpp @@ -71,14 +71,14 @@ Room::Room(Connection* connection, QString id) d->connection = connection; d->joinState = JoinState::Join; d->gettingNewContent = false; - qDebug() << "New Room: " << id; + qDebug() << "New Room:" << id; //connection->getMembers(this); // I don't think we need this anymore in r0.0.1 } Room::~Room() { - qDebug() << "deconstructing room " << this; + qDebug() << "deconstructing room" << this; delete d; } @@ -302,7 +302,7 @@ void Room::processStateEvent(Event* event) if (RoomNameEvent* nameEvent = static_cast(event)) { d->name = nameEvent->name(); - qDebug() << "room name: " << d->name; + qDebug() << "room name:" << d->name; emit namesChanged(this); } else { @@ -314,14 +314,14 @@ void Room::processStateEvent(Event* event) { RoomAliasesEvent* aliasesEvent = static_cast(event); d->aliases = aliasesEvent->aliases(); - qDebug() << "room aliases: " << d->aliases; + qDebug() << "room aliases:" << d->aliases; emit namesChanged(this); } if( event->type() == EventType::RoomCanonicalAlias ) { RoomCanonicalAliasEvent* aliasEvent = static_cast(event); d->canonicalAlias = aliasEvent->alias(); - qDebug() << "room canonical alias: " << d->canonicalAlias; + qDebug() << "room canonical alias:" << d->canonicalAlias; emit namesChanged(this); } if( event->type() == EventType::RoomTopic ) -- cgit v1.2.3 From 48e7e8108a62fe990972256143b8d71180312c8b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 11 Apr 2016 10:46:33 +0900 Subject: Use a more telling log line than !!!! --- events/roomaliasesevent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events/roomaliasesevent.cpp b/events/roomaliasesevent.cpp index 6bbe0aff..54fb5682 100644 --- a/events/roomaliasesevent.cpp +++ b/events/roomaliasesevent.cpp @@ -64,7 +64,7 @@ QStringList RoomAliasesEvent::aliases() const RoomAliasesEvent* RoomAliasesEvent::fromJson(const QJsonObject& obj) { - qDebug() << "!!!!"; + qDebug() << "RoomAliasesEvent::fromJson"; RoomAliasesEvent* e = new RoomAliasesEvent(); e->parseJson(obj); const QJsonObject contents = obj.value("content").toObject(); -- cgit v1.2.3 From 8045e36b6b8597120f46e0d4d42cf87ac790351b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 11 Apr 2016 12:27:56 +0900 Subject: Drop unneeded check and debug message --- room.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/room.cpp b/room.cpp index 11faf104..99d7f810 100644 --- a/room.cpp +++ b/room.cpp @@ -334,7 +334,6 @@ void Room::processStateEvent(Event* event) { RoomMemberEvent* memberEvent = static_cast(event); User* u = d->connection->user(memberEvent->userId()); - if( !u ) qDebug() << "addState: invalid user!" << u << memberEvent->userId(); u->processEvent(event); if( memberEvent->membership() == MembershipType::Join and !d->users.contains(u) ) { -- cgit v1.2.3 From def5a08b4d360f6035ad4c420f0206ad6f96e0bd Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 11 Apr 2016 12:43:32 +0900 Subject: Factor out the code that searches an insertion point in a timeline. This is used once in the library and, I guess, twice more in the Quaternion. Implemented as a template function that is equally suitable for Event and Message, and any container that supports STL-style iterators (QList and other Qt containers do). --- CMakeLists.txt | 1 + events/event.h | 18 ++++++++++++++++++ room.cpp | 10 +--------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb5a47cb..526249e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,7 @@ if ( CMAKE_VERSION VERSION_LESS "3.1" ) else ( CMAKE_VERSION VERSION_LESS "3.1" ) target_compile_features(qmatrixclient PRIVATE cxx_range_for) target_compile_features(qmatrixclient PRIVATE cxx_override) + target_compile_features(qmatrixclient PRIVATE cxx_lambdas) endif ( CMAKE_VERSION VERSION_LESS "3.1" ) target_link_libraries(qmatrixclient Qt5::Core Qt5::Network Qt5::Gui) diff --git a/events/event.h b/events/event.h index b25b1378..6a8d0e89 100644 --- a/events/event.h +++ b/events/event.h @@ -19,6 +19,8 @@ #ifndef QMATRIXCLIENT_EVENT_H #define QMATRIXCLIENT_EVENT_H +#include + #include #include #include @@ -53,6 +55,22 @@ namespace QMatrixClient class Private; Private* d; }; + + /** + * Finds a place in the timeline where a new event/message could be inserted. + * @return an iterator to an item with the earliest timestamp after + * the one of 'item'; or timeline.end(), if all events are earlier + */ + template class ContT> + typename ContT::iterator + findInsertionPos(ContT & timeline, const ItemT *item) + { + return std::lower_bound (timeline.begin(), timeline.end(), item, + [](const ItemT * a, const ItemT * b) { + return a->timestamp() < b->timestamp(); + } + ); + } } #endif // QMATRIXCLIENT_EVENT_H diff --git a/room.cpp b/room.cpp index 99d7f810..c5b674ae 100644 --- a/room.cpp +++ b/room.cpp @@ -284,15 +284,7 @@ Connection* Room::connection() void Room::processMessageEvent(Event* event) { - for( int i=0; imessageEvents.count(); i++ ) - { - if( event->timestamp() < d->messageEvents.at(i)->timestamp() ) - { - d->messageEvents.insert(i, event); - return; - } - } - d->messageEvents.append(event); + d->messageEvents.insert(findInsertionPos(d->messageEvents, event), event); } void Room::processStateEvent(Event* event) -- cgit v1.2.3 From ba8b886e1e027ee1eadfc8fd66346bc0ad4a816b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 11 Apr 2016 14:26:40 +0900 Subject: Add more target_compile_features supported by CMake 3.1 and already used in the code. See https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES for the full list. All the newly added features are already implied by C++11 standard so for older CMakes -std=c++11 should cover all bases anyway. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 526249e4..32792435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,10 @@ if ( CMAKE_VERSION VERSION_LESS "3.1" ) else ( CMAKE_VERSION VERSION_LESS "3.1" ) target_compile_features(qmatrixclient PRIVATE cxx_range_for) target_compile_features(qmatrixclient PRIVATE cxx_override) + target_compile_features(qmatrixclient PRIVATE cxx_strong_enums) target_compile_features(qmatrixclient PRIVATE cxx_lambdas) + target_compile_features(qmatrixclient PRIVATE cxx_auto_type) + target_compile_features(qmatrixclient PRIVATE cxx_generalized_initializers) endif ( CMAKE_VERSION VERSION_LESS "3.1" ) target_link_libraries(qmatrixclient Qt5::Core Qt5::Network Qt5::Gui) -- cgit v1.2.3