Commit 980cb377 authored by Armin Felder's avatar Armin Felder
Browse files

win64 compat

parent 026a42e1
......@@ -122,7 +122,7 @@ QVariant ChannelModel::data( const QModelIndex &index, int role ) const
auto avatarImg = currentChannel->getAvatarImg();
if ( !avatarImg.isNull() ) {
auto path = QStringLiteral( "file://" ) + avatarImg->getFilePath();
auto path = Utils::getPathPrefix() + avatarImg->getFilePath();
if ( path.endsWith( "svg" ) ) {
return "qrc:res/user-identity.svg";
......
......@@ -170,7 +170,7 @@ QVariant MessagesModel::data( const QModelIndex &index, int role ) const
auto avatarImg = messageAtIndex->getAvatarImg();
if ( !avatarImg.isNull() ) {
auto path = QStringLiteral( "file://" ) + avatarImg->getFilePath();
auto path = Utils::getPathPrefix() + avatarImg->getFilePath();
if ( path.endsWith( "svg" ) ) {
return "qrc:res/user-identity.svg";
......
......@@ -20,13 +20,13 @@
#include "meteorddp.h"
#include "websocket.h"
#include "meteorddp.h"
#include <QString>
#include <QWebSocket>
#include <QTime>
#include <QCryptographicHash>
#include <functional>
#include <QAbstractSocket>
#include "ddpRequests/ddploginrequest.h"
MeteorDDP::MeteorDDP( QObject *parent, const QString &pUri, bool pUnsecure ): QObject( parent ), unsecure( pUnsecure )
......@@ -38,8 +38,6 @@ MeteorDDP::MeteorDDP( QObject *parent, const QString &pUri, bool pUnsecure ): QO
void MeteorDDP::init( const QString &pUri )
{
mWsClient = new Websocket( this );
QString protocol = QStringLiteral( "wss://" );
if ( unsecure ) {
......@@ -51,15 +49,16 @@ void MeteorDDP::init( const QString &pUri )
qDebug() << "meteor init" ;
mWebsocketUri = pUri;
mResponseBinding.reserve( 100 );
connect( mWsClient, &Websocket::textMessageReceived, this, &MeteorDDP::onTextMessageReceived, Qt::UniqueConnection );
connect( mWsClient, &Websocket::connected, this, &MeteorDDP::onConnected, Qt::UniqueConnection );
connect( mWsClient, &Websocket::closed, this, &MeteorDDP::ddpDisconnected );
connect( &mWebsocket, &QWebSocket::textMessageReceived, this, &MeteorDDP::onTextMessageReceived, Qt::UniqueConnection );
connect( &mWebsocket, &QWebSocket::connected, this, &MeteorDDP::onConnected, Qt::UniqueConnection );
connect( &mWebsocket, &QWebSocket::disconnected, this, &MeteorDDP::ddpDisconnected );
connect( this, &MeteorDDP::sendMessageSignal, this, &MeteorDDP::sendJson, Qt::UniqueConnection );
connect( mWsClient, &Websocket::error, this, [ = ]( QString error ) {
qDebug() << "test";
qDebug() << error;
} );
mWsClient->open( wsUri );
connect( &mWebsocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error),
[=](QAbstractSocket::SocketError error){
qDebug()<<mWebsocket.errorString();
});
mWebsocket.open( wsUri );
QDateTime now = QDateTime::currentDateTime();
uint currentTime = now.toTime_t();
mLastPing = currentTime;
......@@ -88,13 +87,6 @@ void MeteorDDP::connectWithServer()
sendJson( msgObj );
}
/*void MeteorDDP::loadLocale(){
QJsonArray params;
params.append("de");
method("loadLocale",params);
}*/
void MeteorDDP::onTextMessageReceived( const QString &pMsg )
{
#if defined(Q_OS_LINUX)|| defined(Q_OS_IOS)
......@@ -190,7 +182,7 @@ void MeteorDDP::sendJson( const QJsonObject &pMsgObj )
QJsonDocument msgJson = QJsonDocument( pMsgObj );
QString msgString = msgJson.toJson( QJsonDocument::Compact );
qDebug() << "message String" << msgString;
mWsClient->sendTextMessage( msgString );
mWebsocket.sendTextMessage( msgString );
}
bool MeteorDDP::getUnsecure() const
......@@ -240,18 +232,17 @@ void MeteorDDP::resume()
{
qDebug() << "resuming ddp";
if ( mWsClient ) {
#if defined(Q_OS_ANDROID) || defined(Q_OS_LINUX)
qDebug() << "websocket valid: " << mWsClient->isValid();
#if defined(Q_OS_ANDROID) || defined(Q_OS_LINUX) ||defined(Q_OS_WIN)
qDebug() << "websocket valid: " << mWebsocket.isValid();
QUrl wsUri = QUrl( QStringLiteral( "wss://" ) + mWebsocketUri + QStringLiteral( "/websocket" ) );
if ( mWsClient->isDisconnected() ) {
mWsClient->open( wsUri );
} else if ( !mWsClient->isConnecting() ) {
if ( mWebsocket.state() == QAbstractSocket::UnconnectedState ) {
mWebsocket.open( wsUri );
} else if ( mWebsocket.state() != QAbstractSocket::ConnectingState ) {
auto const connection = new QMetaObject::Connection;
*connection = connect( mWsClient, &Websocket::closed, [ = ]() {
*connection = connect( &mWebsocket, &QWebSocket::disconnected, [ = ]() {
qDebug() << "websocket closed";
mWsClient->open( wsUri );
mWebsocket.open( wsUri );
QDateTime now = QDateTime::currentDateTime();
uint currentTime = now.toTime_t();
mLastPing = currentTime;
......@@ -261,26 +252,25 @@ void MeteorDDP::resume()
delete connection;
}
} );
mWsClient->close();
mWebsocket.close();
}
if ( mWsClient->isDisconnected() ) {
if ( mWebsocket.state() == QAbstractSocket::UnconnectedState ) {
// connectWithServer();
}
#else
qDebug() << "resuming ddp";
mWsClient->close();
connect( mWsClient, &Websocket::destroyed, [&]() {
mWsClient = new Websocket( this );
qDebug() << "new Websocket Object created";
mWebsocket.close();
connect(&mWebsocket , &QWebSocket::disconnected, [&]() {
qDebug()<<"disconnected";
init( mWebsocketUri );
} );
mWsClient->deleteLater();
mWebsocket.close();
#endif
}
}
void MeteorDDP::unsetResponseBinding( const QString &pId )
......@@ -292,12 +282,7 @@ void MeteorDDP::unsetResponseBinding( const QString &pId )
bool MeteorDDP::websocketIsValid()
{
if ( mWsClient ) {
return mWsClient->isValid();
}
return false;
return mWebsocket.isValid();
}
uint MeteorDDP::diffToLastMessage()
......@@ -311,7 +296,7 @@ uint MeteorDDP::diffToLastMessage()
void MeteorDDP::disconnectFromServer()
{
qDebug() << "disconnect from server";
mWsClient->close();
mWebsocket.close();
}
void MeteorDDP::setResumeToken( const QString &pToken )
......@@ -344,17 +329,3 @@ bool MeteorDDP::getWebsocketConnectionEstablished() const
{
return mWebsocketConnectionEstablished;
}
/*
MeteorDDP::~MeteorDDP()
{
qDebug()<<"destroying wsClient";
disconnect( mWsClient, &Websocket::textMessageReceived, this, &MeteorDDP::onTextMessageReceived );
disconnect( mWsClient, &Websocket::connected, this, &MeteorDDP::onConnected);
disconnect( this, &MeteorDDP::sendMessageSignal, this, &MeteorDDP::sendJson );
mWsClient->close();
mWsClient->deleteLater();
}
*/
......@@ -27,7 +27,6 @@
#include <QUrl>
#include <QHash>
#include <QtWebSockets/QtWebSockets>
#include "websocket/websocket.h"
#include "ddpRequests/ddprequest.h"
#include "messagelistener.h"
......@@ -77,7 +76,7 @@ class MeteorDDP : public QObject
bool unsecure;
int frameCount = 0;
Websocket *mWsClient = nullptr;
QString mServer;
QUrl wsUri;
QString mUid;
......@@ -94,6 +93,8 @@ class MeteorDDP : public QObject
uint mMaxTimeout = 0;
QSet<QString> mReceivedEvents;
QWebSocket mWebsocket;
signals:
void websocketConnected();
......
TEMPLATE = lib
QT += core network websockets sql concurrent
CONFIG += c++17 static
INCLUDEPATH += websocket\
websocket/linuxwebsocket
SOURCES += api/meteorddp.cpp \
api/restapi.cpp \
websocket/websocket.cpp \
websocket/websocketabstract.cpp \
ddpRequests/ddploginrequest.cpp \
ddpRequests/ddprequest.cpp \
ddpRequests/ddpsubscriptionrequest.cpp \
......@@ -111,8 +107,6 @@ SOURCES += api/meteorddp.cpp \
HEADERS += \
api/meteorddp.h \
api/restapi.h \
websocket/websocket.h \
websocket/websocketabstract.h \
ddpRequests/ddploginrequest.h \
ddpRequests/ddpmethodrequest.h \
ddpRequests/ddprequest.h \
......@@ -219,11 +213,8 @@ HEADERS += \
linux{
SOURCES += websocket/linuxwebsocket/websocketlinux.cpp \
segfaulthandler.cpp
HEADERS += websocket/linuxwebsocket/websocketlinux.h \
segfaulthandler.h
SOURCES += segfaulthandler.cpp
HEADERS += segfaulthandler.h
}
......@@ -253,20 +244,21 @@ android{
}
win32{
QMAKE_CXXFLAGS += /MP
}
ios{
QT += gui-private
SOURCES += websocket/linuxwebsocket/websocketlinux.cpp \
notifications/ios/applepushnotifications.cpp \
SOURCES += notifications/ios/applepushnotifications.cpp \
notifications/ios/iosdevicetokenstorage.cpp \
segfaulthandler.cpp \
notifications/ios/iosnotificationreceiver.cpp
HEADERS += websocket/linuxwebsocket/websocketlinux.h \
notifications/ios/applepushnotifications.h \
HEADERS += notifications/ios/applepushnotifications.h \
notifications/ios/iosdevicetokenstorage.h \
notifications/ios/iosnotificationreceiver.h \
notifications/ios/DelegateClass.h
......@@ -293,6 +285,9 @@ CONFIG(release, debug|release) {
CONFIG += ltcg
QMAKE_CXXFLAGS += -Ofast -funroll-loops -fno-signed-zeros -fno-trapping-math
}
win32:{
QMAKE_CXXFLAGS += /O2
}
}
RESOURCES += \
......
/********************************************************************************************
* *
* Copyright (C) 2017 Armin Felder, Dennis Beier *
* This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>. *
* *
* RocketChatMobileEngine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* RocketChatMobileEngine 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************************/
#include <QWebSocket>
#include "websocketlinux.h"
#include "websocketabstract.h"
websocketLinux::websocketLinux( QObject *parent ): WebsocketAbstract( parent ), mWebsocket( "rocket.chat.mobile", QWebSocketProtocol::VersionLatest, this )
{
connect( &mWebsocket, &QWebSocket::connected, this, &websocketLinux::connected, Qt::UniqueConnection );
connect( &mWebsocket, &QWebSocket::textMessageReceived, this, &websocketLinux::received, Qt::UniqueConnection );
connect( &mWebsocket, &QWebSocket::disconnected, this, &websocketLinux::closed, Qt::UniqueConnection );
//connect(&websocket,&QWebSocket::error,this,&websocketLinux::error);
connect( &mWebsocket, &QWebSocket::stateChanged, this, &websocketLinux::onStatusChanged, Qt::UniqueConnection );
}
void websocketLinux::open( const QUrl &url )
{
qDebug() << "open url";
mWebsocket.open( url );
}
void websocketLinux::close()
{
mWebsocket.close();
}
void websocketLinux::sendTextMessage( const QString &pMessage )
{
if ( !mWebsocket.sendTextMessage( pMessage ) ) {
qWarning() << "ddp did not send message: " << pMessage;
}
}
bool websocketLinux::isValid()
{
qDebug() << "state: " << mWebsocket.state();
return mWebsocket.isValid();
}
bool websocketLinux::isDisconnected()
{
return mWebsocket.state() == QAbstractSocket::UnconnectedState;
}
bool websocketLinux::isConnecting()
{
return mWebsocket.state() == QAbstractSocket::ConnectingState;
}
void websocketLinux::received( const QString &pMsg )
{
emit( textMessageReceived( pMsg ) );
}
void websocketLinux::onStatusChanged()
{
// if(mWebsocket.state() == QAbstractSocket::UnconnectedState){
// emit closed();
// }else if(mWebsocket.state() == QAbstractSocket::ConnectedState){
// emit connected();
// }
qDebug() << "state linux websocket: " << mWebsocket.state();
}
/********************************************************************************************
* *
* Copyright (C) 2017 Armin Felder, Dennis Beier *
* This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>. *
* *
* RocketChatMobileEngine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* RocketChatMobileEngine 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************************/
#ifndef WEBSOCKETLINUX_H
#define WEBSOCKETLINUX_H
#include <QtWebSockets/QtWebSockets>
#include <QAbstractSocket>
#include "websocketabstract.h"
class websocketLinux: public WebsocketAbstract
{
public:
explicit websocketLinux( QObject *parent );
virtual void open( const QUrl & ) override;
virtual void close() override;
virtual void sendTextMessage( const QString & ) override;
virtual bool isValid( void ) override;
virtual bool isDisconnected( void ) override;
virtual bool isConnecting( void ) override;
void received( const QString & );
void onStatusChanged();
private:
QWebSocket mWebsocket;
void emitConnected();
};
#endif // WEBSOCKETLINUX_H
/********************************************************************************************
* *
* Copyright (C) 2017 Armin Felder, Dennis Beier *
* This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>. *
* *
* RocketChatMobileEngine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* RocketChatMobileEngine 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************************/
#include <QUrl>
#include <QThread>
#include <QDebug>
#include "websocket.h"
#include "websocketlinux.h"
Websocket::Websocket( QObject *parent ): WebsocketAbstract( parent )
{
qRegisterMetaType<QAbstractSocket::SocketState>( "QAbstractSocket::SocketState" );
mWebsocketInstance = new websocketLinux( this );
connect( mWebsocketInstance, &WebsocketAbstract::connected, this, &Websocket::connected, Qt::UniqueConnection );
connect( mWebsocketInstance, &WebsocketAbstract::textMessageReceived, this, &Websocket::textMessageReceived, Qt::UniqueConnection );
connect( mWebsocketInstance, &WebsocketAbstract::error, this, &Websocket::error, Qt::UniqueConnection );
connect( mWebsocketInstance, &WebsocketAbstract::closed, this, &Websocket::closed, Qt::UniqueConnection );
}
void Websocket::open( const QUrl &pUrl )
{
mWebsocketInstance->open( pUrl );
}
void Websocket::close()
{
mWebsocketInstance->close();
}
void Websocket::sendTextMessage( const QString &pMessage )
{
mWebsocketInstance->sendTextMessage( pMessage );
}
bool Websocket::isValid()
{
return mWebsocketInstance->isValid();
}
bool Websocket::isDisconnected()
{
return mWebsocketInstance->isDisconnected();
}
bool Websocket::isConnecting()
{
return mWebsocketInstance->isConnecting();
}
void Websocket::updateConnectionStatus()
{
qDebug() << "updated connection status";
mConnectionStatus = true;
emit( connected() );
}
/********************************************************************************************
* *
* Copyright (C) 2017 Armin Felder, Dennis Beier *
* This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>. *
* *
* RocketChatMobileEngine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* RocketChatMobileEngine 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************************/
#ifndef WEBSOCKET_H
#define WEBSOCKET_H
#include <QObject>
#include "websocketabstract.h"
class Websocket: public WebsocketAbstract
{
public:
explicit Websocket( QObject *parent );
virtual void open( const QUrl & ) override;
virtual void close( void ) override;
virtual void sendTextMessage( const QString & ) override;
virtual bool isValid( void ) override;
virtual bool isDisconnected( void ) override;
virtual bool isConnecting( void ) override;
//~Websocket();
private:
void updateConnectionStatus();
bool mConnectionStatus = false;
WebsocketAbstract *mWebsocketInstance;
};
#endif // WEBSOCKET_H
/********************************************************************************************
* *
* Copyright (C) 2017 Armin Felder, Dennis Beier *
* This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>. *
* *
* RocketChatMobileEngine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* RocketChatMobileEngine 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************************/
#include "websocketabstract.h"
WebsocketAbstract::WebsocketAbstract( QObject *parent ): QObject( parent )
{
}
void WebsocketAbstract::sendTextMessage( const QString & )
{
}
void WebsocketAbstract::close()
{
}
/********************************************************************************************
* *
* Copyright (C) 2017 Armin Felder, Dennis Beier *
* This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>. *
* *
* RocketChatMobileEngine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* RocketChatMobileEngine 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************************/
#ifndef WEBSOCKETABSTRACT_H
#define WEBSOCKETABSTRACT_H
#include <QObject>
#include <QUrl>
#include <QString>
#include <QAbstractSocket>