From 9a1afe11b844174bd0fd4ce80d89e909fb25f638 Mon Sep 17 00:00:00 2001 From: David A Roberts Date: Mon, 11 Apr 2016 18:39:56 +1000 Subject: Add QMake project include file. --- package.pri | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 package.pri diff --git a/package.pri b/package.pri new file mode 100644 index 00000000..1290aa19 --- /dev/null +++ b/package.pri @@ -0,0 +1,72 @@ +QT += network +CONFIG += c++11 + +INCLUDEPATH += $$PWD $$PWD/kcoreaddons/src/lib/jobs + +HEADERS += \ + $$PWD/connectiondata.h \ + $$PWD/connection.h \ + $$PWD/connectionprivate.h \ + $$PWD/room.h \ + $$PWD/user.h \ + $$PWD/logmessage.h \ + $$PWD/state.h \ + $$PWD/events/event.h \ + $$PWD/events/roommessageevent.h \ + $$PWD/events/roomnameevent.h \ + $$PWD/events/roomaliasesevent.h \ + $$PWD/events/roomcanonicalaliasevent.h \ + $$PWD/events/roommemberevent.h \ + $$PWD/events/roomtopicevent.h \ + $$PWD/events/typingevent.h \ + $$PWD/events/receiptevent.h \ + $$PWD/events/unknownevent.h \ + $$PWD/jobs/basejob.h \ + $$PWD/jobs/checkauthmethods.h \ + $$PWD/jobs/passwordlogin.h \ + $$PWD/jobs/postmessagejob.h \ + $$PWD/jobs/postreceiptjob.h \ + $$PWD/jobs/joinroomjob.h \ + $$PWD/jobs/leaveroomjob.h \ + $$PWD/jobs/roommembersjob.h \ + $$PWD/jobs/roommessagesjob.h \ + $$PWD/jobs/syncjob.h \ + $$PWD/jobs/mediathumbnailjob.h \ + $$PWD/kcoreaddons/src/lib/jobs/kjob.h \ + $$PWD/kcoreaddons/src/lib/jobs/kcompositejob.h \ + $$PWD/kcoreaddons/src/lib/jobs/kjobtrackerinterface.h \ + $$PWD/kcoreaddons/src/lib/jobs/kjobuidelegate.h + +SOURCES += \ + $$PWD/connectiondata.cpp \ + $$PWD/connection.cpp \ + $$PWD/connectionprivate.cpp \ + $$PWD/room.cpp \ + $$PWD/user.cpp \ + $$PWD/logmessage.cpp \ + $$PWD/state.cpp \ + $$PWD/events/event.cpp \ + $$PWD/events/roommessageevent.cpp \ + $$PWD/events/roomnameevent.cpp \ + $$PWD/events/roomaliasesevent.cpp \ + $$PWD/events/roomcanonicalaliasevent.cpp \ + $$PWD/events/roommemberevent.cpp \ + $$PWD/events/roomtopicevent.cpp \ + $$PWD/events/typingevent.cpp \ + $$PWD/events/receiptevent.cpp \ + $$PWD/events/unknownevent.cpp \ + $$PWD/jobs/basejob.cpp \ + $$PWD/jobs/checkauthmethods.cpp \ + $$PWD/jobs/passwordlogin.cpp \ + $$PWD/jobs/postmessagejob.cpp \ + $$PWD/jobs/postreceiptjob.cpp \ + $$PWD/jobs/joinroomjob.cpp \ + $$PWD/jobs/leaveroomjob.cpp \ + $$PWD/jobs/roommembersjob.cpp \ + $$PWD/jobs/roommessagesjob.cpp \ + $$PWD/jobs/syncjob.cpp \ + $$PWD/jobs/mediathumbnailjob.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kjob.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kcompositejob.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kjobtrackerinterface.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kjobuidelegate.cpp -- cgit v1.2.3 From b5c8ca7b8b3ce4bcd8ddb45580d00876cc2b1c77 Mon Sep 17 00:00:00 2001 From: David A Roberts Date: Mon, 11 Apr 2016 19:40:44 +1000 Subject: Rename package.pri --- libqmatrixclient.pri | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.pri | 72 ---------------------------------------------------- 2 files changed, 72 insertions(+), 72 deletions(-) create mode 100644 libqmatrixclient.pri delete mode 100644 package.pri diff --git a/libqmatrixclient.pri b/libqmatrixclient.pri new file mode 100644 index 00000000..1290aa19 --- /dev/null +++ b/libqmatrixclient.pri @@ -0,0 +1,72 @@ +QT += network +CONFIG += c++11 + +INCLUDEPATH += $$PWD $$PWD/kcoreaddons/src/lib/jobs + +HEADERS += \ + $$PWD/connectiondata.h \ + $$PWD/connection.h \ + $$PWD/connectionprivate.h \ + $$PWD/room.h \ + $$PWD/user.h \ + $$PWD/logmessage.h \ + $$PWD/state.h \ + $$PWD/events/event.h \ + $$PWD/events/roommessageevent.h \ + $$PWD/events/roomnameevent.h \ + $$PWD/events/roomaliasesevent.h \ + $$PWD/events/roomcanonicalaliasevent.h \ + $$PWD/events/roommemberevent.h \ + $$PWD/events/roomtopicevent.h \ + $$PWD/events/typingevent.h \ + $$PWD/events/receiptevent.h \ + $$PWD/events/unknownevent.h \ + $$PWD/jobs/basejob.h \ + $$PWD/jobs/checkauthmethods.h \ + $$PWD/jobs/passwordlogin.h \ + $$PWD/jobs/postmessagejob.h \ + $$PWD/jobs/postreceiptjob.h \ + $$PWD/jobs/joinroomjob.h \ + $$PWD/jobs/leaveroomjob.h \ + $$PWD/jobs/roommembersjob.h \ + $$PWD/jobs/roommessagesjob.h \ + $$PWD/jobs/syncjob.h \ + $$PWD/jobs/mediathumbnailjob.h \ + $$PWD/kcoreaddons/src/lib/jobs/kjob.h \ + $$PWD/kcoreaddons/src/lib/jobs/kcompositejob.h \ + $$PWD/kcoreaddons/src/lib/jobs/kjobtrackerinterface.h \ + $$PWD/kcoreaddons/src/lib/jobs/kjobuidelegate.h + +SOURCES += \ + $$PWD/connectiondata.cpp \ + $$PWD/connection.cpp \ + $$PWD/connectionprivate.cpp \ + $$PWD/room.cpp \ + $$PWD/user.cpp \ + $$PWD/logmessage.cpp \ + $$PWD/state.cpp \ + $$PWD/events/event.cpp \ + $$PWD/events/roommessageevent.cpp \ + $$PWD/events/roomnameevent.cpp \ + $$PWD/events/roomaliasesevent.cpp \ + $$PWD/events/roomcanonicalaliasevent.cpp \ + $$PWD/events/roommemberevent.cpp \ + $$PWD/events/roomtopicevent.cpp \ + $$PWD/events/typingevent.cpp \ + $$PWD/events/receiptevent.cpp \ + $$PWD/events/unknownevent.cpp \ + $$PWD/jobs/basejob.cpp \ + $$PWD/jobs/checkauthmethods.cpp \ + $$PWD/jobs/passwordlogin.cpp \ + $$PWD/jobs/postmessagejob.cpp \ + $$PWD/jobs/postreceiptjob.cpp \ + $$PWD/jobs/joinroomjob.cpp \ + $$PWD/jobs/leaveroomjob.cpp \ + $$PWD/jobs/roommembersjob.cpp \ + $$PWD/jobs/roommessagesjob.cpp \ + $$PWD/jobs/syncjob.cpp \ + $$PWD/jobs/mediathumbnailjob.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kjob.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kcompositejob.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kjobtrackerinterface.cpp \ + $$PWD/kcoreaddons/src/lib/jobs/kjobuidelegate.cpp diff --git a/package.pri b/package.pri deleted file mode 100644 index 1290aa19..00000000 --- a/package.pri +++ /dev/null @@ -1,72 +0,0 @@ -QT += network -CONFIG += c++11 - -INCLUDEPATH += $$PWD $$PWD/kcoreaddons/src/lib/jobs - -HEADERS += \ - $$PWD/connectiondata.h \ - $$PWD/connection.h \ - $$PWD/connectionprivate.h \ - $$PWD/room.h \ - $$PWD/user.h \ - $$PWD/logmessage.h \ - $$PWD/state.h \ - $$PWD/events/event.h \ - $$PWD/events/roommessageevent.h \ - $$PWD/events/roomnameevent.h \ - $$PWD/events/roomaliasesevent.h \ - $$PWD/events/roomcanonicalaliasevent.h \ - $$PWD/events/roommemberevent.h \ - $$PWD/events/roomtopicevent.h \ - $$PWD/events/typingevent.h \ - $$PWD/events/receiptevent.h \ - $$PWD/events/unknownevent.h \ - $$PWD/jobs/basejob.h \ - $$PWD/jobs/checkauthmethods.h \ - $$PWD/jobs/passwordlogin.h \ - $$PWD/jobs/postmessagejob.h \ - $$PWD/jobs/postreceiptjob.h \ - $$PWD/jobs/joinroomjob.h \ - $$PWD/jobs/leaveroomjob.h \ - $$PWD/jobs/roommembersjob.h \ - $$PWD/jobs/roommessagesjob.h \ - $$PWD/jobs/syncjob.h \ - $$PWD/jobs/mediathumbnailjob.h \ - $$PWD/kcoreaddons/src/lib/jobs/kjob.h \ - $$PWD/kcoreaddons/src/lib/jobs/kcompositejob.h \ - $$PWD/kcoreaddons/src/lib/jobs/kjobtrackerinterface.h \ - $$PWD/kcoreaddons/src/lib/jobs/kjobuidelegate.h - -SOURCES += \ - $$PWD/connectiondata.cpp \ - $$PWD/connection.cpp \ - $$PWD/connectionprivate.cpp \ - $$PWD/room.cpp \ - $$PWD/user.cpp \ - $$PWD/logmessage.cpp \ - $$PWD/state.cpp \ - $$PWD/events/event.cpp \ - $$PWD/events/roommessageevent.cpp \ - $$PWD/events/roomnameevent.cpp \ - $$PWD/events/roomaliasesevent.cpp \ - $$PWD/events/roomcanonicalaliasevent.cpp \ - $$PWD/events/roommemberevent.cpp \ - $$PWD/events/roomtopicevent.cpp \ - $$PWD/events/typingevent.cpp \ - $$PWD/events/receiptevent.cpp \ - $$PWD/events/unknownevent.cpp \ - $$PWD/jobs/basejob.cpp \ - $$PWD/jobs/checkauthmethods.cpp \ - $$PWD/jobs/passwordlogin.cpp \ - $$PWD/jobs/postmessagejob.cpp \ - $$PWD/jobs/postreceiptjob.cpp \ - $$PWD/jobs/joinroomjob.cpp \ - $$PWD/jobs/leaveroomjob.cpp \ - $$PWD/jobs/roommembersjob.cpp \ - $$PWD/jobs/roommessagesjob.cpp \ - $$PWD/jobs/syncjob.cpp \ - $$PWD/jobs/mediathumbnailjob.cpp \ - $$PWD/kcoreaddons/src/lib/jobs/kjob.cpp \ - $$PWD/kcoreaddons/src/lib/jobs/kcompositejob.cpp \ - $$PWD/kcoreaddons/src/lib/jobs/kjobtrackerinterface.cpp \ - $$PWD/kcoreaddons/src/lib/jobs/kjobuidelegate.cpp -- cgit v1.2.3 From 0f6cb38896443cf104aa470eb1822bd2e49143f1 Mon Sep 17 00:00:00 2001 From: David A Roberts Date: Tue, 12 Apr 2016 20:05:17 +1000 Subject: Resolve Matrix SRV records. --- connection.cpp | 5 +++++ connection.h | 3 +++ connectiondata.cpp | 14 +++++++++++++- connectiondata.h | 6 ++++-- connectionprivate.cpp | 29 ++++++++++++++++++++++++++++- connectionprivate.h | 4 +++- jobs/basejob.cpp | 11 ++++++++++- jobs/basejob.h | 1 + 8 files changed, 67 insertions(+), 6 deletions(-) diff --git a/connection.cpp b/connection.cpp index 5127dea8..d9802f5f 100644 --- a/connection.cpp +++ b/connection.cpp @@ -54,6 +54,11 @@ Connection::~Connection() delete d; } +void Connection::resolveServer(QString domain) +{ + d->resolveServer( domain ); +} + void Connection::connectToServer(QString user, QString password) { PasswordLogin* loginJob = new PasswordLogin(d->data, user, password); diff --git a/connection.h b/connection.h index 64d3d077..dc056fd8 100644 --- a/connection.h +++ b/connection.h @@ -44,6 +44,7 @@ namespace QMatrixClient QHash roomMap() const; Q_INVOKABLE virtual bool isConnected(); + Q_INVOKABLE virtual void resolveServer( QString domain ); Q_INVOKABLE virtual void connectToServer( QString user, QString password ); Q_INVOKABLE virtual void reconnect(); Q_INVOKABLE virtual SyncJob* sync(int timeout=-1); @@ -61,12 +62,14 @@ namespace QMatrixClient signals: void connected(); void reconnected(); + void resolved(); void syncDone(); void newRoom(Room* room); void joinedRoom(Room* room); void loginError(QString error); void connectionError(QString error); + void resolveError(QString error); //void jobError(BaseJob* job); protected: diff --git a/connectiondata.cpp b/connectiondata.cpp index 374484b0..4a3bd47f 100644 --- a/connectiondata.cpp +++ b/connectiondata.cpp @@ -72,6 +72,18 @@ void ConnectionData::setToken(QString token) d->token = token; } +void ConnectionData::setHost(QString host) +{ + d->baseUrl.setHost(host); + qDebug() << "updated baseUrl to" << d->baseUrl; +} + +void ConnectionData::setPort(int port) +{ + d->baseUrl.setPort(port); + qDebug() << "updated baseUrl to" << d->baseUrl; +} + QString ConnectionData::lastEvent() const { return d->lastEvent; @@ -80,4 +92,4 @@ QString ConnectionData::lastEvent() const void ConnectionData::setLastEvent(QString identifier) { d->lastEvent = identifier; -} \ No newline at end of file +} diff --git a/connectiondata.h b/connectiondata.h index e11f54b5..6407780c 100644 --- a/connectiondata.h +++ b/connectiondata.h @@ -34,9 +34,11 @@ namespace QMatrixClient //bool isConnected() const; QString token() const; QUrl baseUrl() const; - + QNetworkAccessManager* nam() const; void setToken( QString token ); + void setHost( QString host ); + void setPort( int port ); QString lastEvent() const; void setLastEvent( QString identifier ); @@ -47,4 +49,4 @@ namespace QMatrixClient }; } -#endif // QMATRIXCLIENT_CONNECTIONDATA_H \ No newline at end of file +#endif // QMATRIXCLIENT_CONNECTIONDATA_H diff --git a/connectionprivate.cpp b/connectionprivate.cpp index 90733ed0..50fd1b0c 100644 --- a/connectionprivate.cpp +++ b/connectionprivate.cpp @@ -31,6 +31,7 @@ #include "events/roommemberevent.h" #include +#include using namespace QMatrixClient; @@ -46,6 +47,32 @@ ConnectionPrivate::~ConnectionPrivate() delete data; } +void ConnectionPrivate::resolveServer(QString domain) +{ + // Find the Matrix server for the given domain. + QDnsLookup* dns = new QDnsLookup(); + dns->setType(QDnsLookup::SRV); + dns->setName("_matrix._tcp." + domain); + + connect(dns, &QDnsLookup::finished, [this,dns]() { + // Check the lookup succeeded. + if (dns->error() != QDnsLookup::NoError || + dns->serviceRecords().isEmpty()) { + emit q->resolveError("DNS lookup failed"); + dns->deleteLater(); + return; + } + + // Handle the results. + QDnsServiceRecord record = dns->serviceRecords().first(); + data->setHost(record.target()); + data->setPort(record.port()); + emit q->resolved(); + dns->deleteLater(); + }); + dns->lookup(); +} + void ConnectionPrivate::processState(State* state) { QString roomId = state->event()->roomId(); @@ -175,4 +202,4 @@ void ConnectionPrivate::gotRoomMembers(KJob* job) if( membersJob->error() == BaseJob::NetworkError ) emit q->connectionError( membersJob->errorString() ); } -} \ No newline at end of file +} diff --git a/connectionprivate.h b/connectionprivate.h index 2aeeaf0b..1fccc759 100644 --- a/connectionprivate.h +++ b/connectionprivate.h @@ -43,6 +43,8 @@ namespace QMatrixClient ConnectionPrivate(Connection* parent); ~ConnectionPrivate(); + void resolveServer( QString domain ); + void processState( State* state ); void processRooms( const QList& data ); @@ -64,4 +66,4 @@ namespace QMatrixClient }; } -#endif // QMATRIXCLIENT_CONNECTIONPRIVATE_H \ No newline at end of file +#endif // QMATRIXCLIENT_CONNECTIONPRIVATE_H diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index b7e1b718..86109feb 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -97,6 +97,7 @@ void BaseJob::start() d->reply = d->connection->nam()->put(req, data.toJson()); break; } + connect( d->reply, &QNetworkReply::sslErrors, this, &BaseJob::sslErrors ); connect( d->reply, &QNetworkReply::finished, this, &BaseJob::gotReply ); QTimer::singleShot( 120*1000, this, SLOT(timeout()) ); // connect( d->reply, static_cast(&QNetworkReply::error), @@ -124,7 +125,7 @@ void BaseJob::gotReply() { if( d->reply->error() != QNetworkReply::NoError ) { - qDebug() << "NetworkError!!!"; + qDebug() << "NetworkError:" << d->reply->errorString(); fail( NetworkError, d->reply->errorString() ); return; } @@ -144,3 +145,11 @@ void BaseJob::timeout() if( d->reply->isRunning() ) d->reply->abort(); } + +void BaseJob::sslErrors(const QList& errors) +{ + foreach (const QSslError &error, errors) { + qWarning() << "SSL ERROR" << error.errorString(); + } + d->reply->ignoreSslErrors(); // TODO: insecure! should prompt user first +} diff --git a/jobs/basejob.h b/jobs/basejob.h index 88911ca1..95cf4232 100644 --- a/jobs/basejob.h +++ b/jobs/basejob.h @@ -63,6 +63,7 @@ namespace QMatrixClient protected slots: virtual void gotReply(); void timeout(); + void sslErrors(const QList& errors); //void networkError(QNetworkReply::NetworkError code); -- cgit v1.2.3 From deda947801d536dba9b59370867f205fe8aabaa8 Mon Sep 17 00:00:00 2001 From: David A Roberts Date: Fri, 22 Apr 2016 12:44:19 +1000 Subject: Allow login with token. --- connection.cpp | 18 ++++++++++++++++++ connection.h | 3 +++ user.cpp | 4 ++-- user.h | 6 +++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/connection.cpp b/connection.cpp index d9802f5f..e04de7aa 100644 --- a/connection.cpp +++ b/connection.cpp @@ -68,6 +68,14 @@ void Connection::connectToServer(QString user, QString password) d->password = password; } +void Connection::connectWithToken(QString userId, QString token) +{ + d->isConnected = true; + d->userId = userId; + d->data->setToken(token); + emit connected(); +} + void Connection::reconnect() { PasswordLogin* loginJob = new PasswordLogin(d->data, d->username, d->password ); @@ -149,6 +157,16 @@ User *Connection::user() return user(d->userId); } +QString Connection::userId() +{ + return d->userId; +} + +QString Connection::token() +{ + return d->data->token(); +} + QHash< QString, Room* > Connection::roomMap() const { return d->roomMap; diff --git a/connection.h b/connection.h index dc056fd8..9f3d23f3 100644 --- a/connection.h +++ b/connection.h @@ -46,6 +46,7 @@ namespace QMatrixClient Q_INVOKABLE virtual void resolveServer( QString domain ); Q_INVOKABLE virtual void connectToServer( QString user, QString password ); + Q_INVOKABLE virtual void connectWithToken( QString userId, QString token ); Q_INVOKABLE virtual void reconnect(); Q_INVOKABLE virtual SyncJob* sync(int timeout=-1); Q_INVOKABLE virtual void postMessage( Room* room, QString type, QString message ); @@ -58,6 +59,8 @@ namespace QMatrixClient Q_INVOKABLE virtual User* user(QString userId); Q_INVOKABLE virtual User* user(); + Q_INVOKABLE virtual QString userId(); + Q_INVOKABLE virtual QString token(); signals: void connected(); diff --git a/user.cpp b/user.cpp index 1b232ab8..2cc81fd9 100644 --- a/user.cpp +++ b/user.cpp @@ -50,7 +50,7 @@ class User::Private: public QObject }; User::User(QString userId, Connection* connection) - : d(new Private) + : QObject(connection), d(new Private) { d->q = this; d->connection = connection; @@ -147,4 +147,4 @@ void User::Private::gotAvatar(KJob* job) Qt::KeepAspectRatio, Qt::SmoothTransformation); scaledMap.clear(); emit q->avatarChanged(q); -} \ No newline at end of file +} diff --git a/user.h b/user.h index a34bd285..d0965ef3 100644 --- a/user.h +++ b/user.h @@ -36,17 +36,17 @@ namespace QMatrixClient /** * Returns the id of the user */ - QString id() const; + Q_INVOKABLE QString id() const; /** * Returns the name chosen by the user */ - QString name() const; + Q_INVOKABLE QString name() const; /** * Returns the name that should be used to display the user. */ - QString displayname() const; + Q_INVOKABLE QString displayname() const; QPixmap avatar(int requestedWidth, int requestedHeight); -- cgit v1.2.3 From aa8b077499653b6ebf2d78136c75c801e6f99c29 Mon Sep 17 00:00:00 2001 From: David A Roberts Date: Sat, 23 Apr 2016 12:54:21 +1000 Subject: Room: Q_INVOKABLE --- room.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/room.h b/room.h index e5e357ee..c4993f7a 100644 --- a/room.h +++ b/room.h @@ -40,30 +40,30 @@ namespace QMatrixClient Room(Connection* connection, QString id); virtual ~Room(); - QString id() const; - QList messageEvents() const; - QString name() const; - QStringList aliases() const; - QString canonicalAlias() const; - QString displayName() const; - QString topic() const; - JoinState joinState() const; - QList usersTyping() const; + Q_INVOKABLE QString id() const; + Q_INVOKABLE QList messageEvents() const; + Q_INVOKABLE QString name() const; + Q_INVOKABLE QStringList aliases() const; + Q_INVOKABLE QString canonicalAlias() const; + Q_INVOKABLE QString displayName() const; + Q_INVOKABLE QString topic() const; + Q_INVOKABLE JoinState joinState() const; + Q_INVOKABLE QList usersTyping() const; - QList users() const; + Q_INVOKABLE QList users() const; - void addMessage( Event* event ); - void addInitialState( State* state ); - void updateData( const SyncRoomData& data ); - void setJoinState( JoinState state ); + Q_INVOKABLE void addMessage( Event* event ); + Q_INVOKABLE void addInitialState( State* state ); + Q_INVOKABLE void updateData( const SyncRoomData& data ); + Q_INVOKABLE void setJoinState( JoinState state ); - void markMessageAsRead( Event* event ); - QString lastReadEvent(User* user); + Q_INVOKABLE void markMessageAsRead( Event* event ); + Q_INVOKABLE QString lastReadEvent(User* user); - int notificationCount() const; - void resetNotificationCount(); - int highlightCount() const; - void resetHighlightCount(); + Q_INVOKABLE int notificationCount() const; + Q_INVOKABLE void resetNotificationCount(); + Q_INVOKABLE int highlightCount() const; + Q_INVOKABLE void resetHighlightCount(); public slots: void getPreviousContent(); -- cgit v1.2.3