diff --git a/WinRt/keypadhelper.cpp b/WinRt/keypadhelper.cpp deleted file mode 100755 index 688580ff6f24f92d270b8bb311278118b65e7658..0000000000000000000000000000000000000000 --- a/WinRt/keypadhelper.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "keypadhelper.h" - -#include <vccorlib.h> -#include <collection.h> -#include <ppltasks.h> -#include <windows.networking.h> -#include <windows.networking.sockets.h> -#include <windows.storage.streams.h> -#include <windows.foundation.h> -#include <windows.ui.core.h> -#include <windows.ui.viewmanagement.h> - -#include <iostream> - -using namespace Windows::Networking::Sockets; -using namespace Windows::Storage::Streams; -using namespace Windows::Foundation; -using namespace Platform; -using namespace Windows::Web; -using namespace Windows::UI::Core; -using namespace concurrency; - - -KeypadHelper::KeypadHelper(QObject *parent) : QObject(parent) -{ - -} - -void KeypadHelper::showKeypad() { - if(ip){ - ip->TryShow(); - } - -} - -void KeypadHelper::hideKeypad() { - ip->TryHide(); -} \ No newline at end of file diff --git a/WinRt/keypadhelper.h b/WinRt/keypadhelper.h deleted file mode 100755 index c0e7c93742f691d01b05ab878bb83ae7e5e522ba..0000000000000000000000000000000000000000 --- a/WinRt/keypadhelper.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef KEYPADHELPER_H -#define KEYPADHELPER_H - -#include <QObject> -#include <windows.ui.viewmanagement.h> -#include <vccorlib.h> - -#include "WinRt/winrtfix.h" - - -class KeypadHelper : public QObject -{ - Q_OBJECT -public: - explicit KeypadHelper(QObject *parent = 0); - void showKeypad(); - void hideKeypad(); -private: - Windows::UI::ViewManagement::InputPane^ ip = Windows::UI::ViewManagement::InputPane::GetForCurrentView(); - -signals: - -}; - -#endif // KEYPADHELPER_H diff --git a/WinRt/winrtfix.h b/WinRt/winrtfix.h deleted file mode 100755 index 500e4b96adc2490983e1f5f8ff45e2e34263332b..0000000000000000000000000000000000000000 --- a/WinRt/winrtfix.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WINRTFIX_H -#define WINRTFIX_H - -#include <vccorlib.h> - -using namespace Platform; - -HRESULT __stdcall GetActivationFactoryByPCWSTR(void*, Guid&, void**); -namespace __winRT -{ - HRESULT __stdcall __getActivationFactoryByPCWSTR(const void* str, ::Platform::Guid& pGuid, void** ppActivationFactory) - { - return GetActivationFactoryByPCWSTR(const_cast<void*>(str), pGuid, ppActivationFactory); - } -} - -#endif // WINRTFIX_H diff --git a/api/meteorddp.cpp b/api/meteorddp.cpp index 4505a53ec2ec70ff1fda287a752cd20dc365fa2e..ced3ea025b5027822ef572f2072483852737672e 100755 --- a/api/meteorddp.cpp +++ b/api/meteorddp.cpp @@ -29,17 +29,24 @@ #include <functional> #include "ddpRequests/ddploginrequest.h" -MeteorDDP::MeteorDDP( QObject *parent, const QString &pUri ): QObject( parent ) +MeteorDDP::MeteorDDP( QObject *parent, const QString &pUri, bool pUnsecure ): QObject( parent ) { mError = new QJsonParseError; - init( pUri ); + init( pUri, pUnsecure ); } -void MeteorDDP::init( const QString &pUri ) +void MeteorDDP::init( const QString &pUri, bool pUnsecure ) { mWsClient = new Websocket( this ); - QUrl wsUri = QUrl( QStringLiteral( "wss://" ) + pUri + QStringLiteral( "/websocket" ) ); + + QString protocol = QStringLiteral( "wss://" ); + + if ( pUnsecure ) { + protocol = QStringLiteral( "ws://" ); + } + + QUrl wsUri = QUrl( protocol + pUri + QStringLiteral( "/websocket" ) ); qDebug() << wsUri; qDebug( "meteor init" ); mWebsocketUri = pUri; diff --git a/api/meteorddp.h b/api/meteorddp.h index 5d22aaeaf28a1d3bda6d8a32c1fdd54bbf23964b..a5f10fe191d90a5cc60beef5971f0605d13f23ab 100755 --- a/api/meteorddp.h +++ b/api/meteorddp.h @@ -41,7 +41,7 @@ class MeteorDDP : public QObject { Q_OBJECT public: - MeteorDDP( QObject *parent, const QString &pUri ); + MeteorDDP( QObject *parent, const QString &pUri, bool pUnsecure = false ); void connectWithServer(); // ~MeteorDDP(); QString getToken() const; @@ -59,9 +59,9 @@ class MeteorDDP : public QObject void setResumeToken( const QString &pToken ); void setUserId( const QString &pUserId ); - void init( const QString &pServer ); - void registerMessageHandler(MessageListener &); void registerMessageHandler(MessageListener *); + void init( const QString &pServer, bool pUnsecure = false ); + private: QJsonParseError *mError; diff --git a/api/restapi.cpp b/api/restapi.cpp index aa8aa57470c7a1b661f0d2ace98e9d0029319591..352033e9f610f018127ad3dcb7d7397ea7a2115f 100755 --- a/api/restapi.cpp +++ b/api/restapi.cpp @@ -21,14 +21,14 @@ #include "restapi.h" -RestApi::RestApi( QObject *parent, const QString &pBaseUrl, const QString &pApiUri ) : QObject( parent ), mApiUri( pApiUri ), mBaseUrl( pBaseUrl ) +RestApi::RestApi( QObject *parent, const QString &pBaseUrl ) : QObject( parent ), mApiUrl( pBaseUrl + mApiPath ), mBaseUrl( pBaseUrl ) { qRegisterMetaType<RestApiRequest>( "RestApiRequest" ); } void RestApi::init() { - mNam = new QNetworkAccessManager(this); + mNam = new QNetworkAccessManager( this ); mApiLogin = QStringLiteral( "/login" ); mApiLogoff = QStringLiteral( "/logout" ); mCookieJar = new QNetworkCookieJar; @@ -48,7 +48,7 @@ void RestApi::init() void RestApi::login( const QString &pUsername, const QString &pPassword ) { if ( pUsername.length() && pPassword.length() ) { - QUrl url = QString( mApiUri + mApiLogin ); + QUrl url = QString( mApiUrl + mApiLogin ); QByteArray data; data.append( "user=" + pUsername + "&" ); data.append( "password=" + pPassword ); @@ -59,7 +59,7 @@ void RestApi::login( const QString &pUsername, const QString &pPassword ) QNetworkRequest request; request.setHeader( QNetworkRequest::ContentTypeHeader, QString( QStringLiteral( "application/x-www-form-urlencoded" ) ) ); request.setUrl( url ); - qDebug() << "send rest api login to " + mApiUri + mApiLogin; + qDebug() << "send rest api login to " + mApiUrl + mApiLogin; mNetworkReplies[mNam->post( request, data )] = methods::LOGIN; } else { mLoginErrorString = QStringLiteral( "no username or password provided" ); @@ -72,7 +72,7 @@ void RestApi::login( const QString &pUsername, const QString &pPassword ) void RestApi::logout() { - QUrl url = QString( mApiUri + mApiLogoff ); + QUrl url = QString( mApiUrl + mApiLogoff ); QNetworkRequest request; request.setUrl( url ); request.setRawHeader( QByteArray( QByteArrayLiteral( "X-Auth-Token" ) ), QByteArray( mToken.toLocal8Bit() ) ); @@ -343,7 +343,7 @@ void RestApi::sendRequestSlot( const RestApiRequest &pRequest ) QString path; if ( !pRequest->getAbsolutePath() ) { - path = mApiUri + pRequest->getPath(); + path = mApiUrl + pRequest->getPath(); } else { path = pRequest->getPath(); } diff --git a/api/restapi.h b/api/restapi.h index e2f82f7a2c255f73d1ec69d61e324506172d488e..18a4e19c557edfbca3b31f6ece7bbcdddeb843cb 100755 --- a/api/restapi.h +++ b/api/restapi.h @@ -55,7 +55,7 @@ class RestApi: public QObject Q_OBJECT public: - RestApi( QObject *parent, const QString &pBaseUrl, const QString &pApiUri ); + RestApi( QObject *parent, const QString &pBaseUrl ); void login( const QString &pUsername, const QString &pPassword ); void logout(); QString getName() const; @@ -94,7 +94,8 @@ class RestApi: public QObject QString mToken = ""; QString mUserId = ""; - QString mApiUri = ""; + QString mApiPath = QStringLiteral( "/api/v1" ); + QString mApiUrl = ""; QString mBaseUrl = ""; QString mApiLogin = ""; QString mApiLogoff = ""; diff --git a/ddpRequests/rocketchatupdatepushtokenrequest.cpp b/ddpRequests/rocketchatupdatepushtokenrequest.cpp index 605feba38d6cdfff3d910d2d19980ea1bf156f9d..f3a396b6377fa30c51d5b006cd60c99338b3e675 100755 --- a/ddpRequests/rocketchatupdatepushtokenrequest.cpp +++ b/ddpRequests/rocketchatupdatepushtokenrequest.cpp @@ -37,9 +37,6 @@ RocketChatUpdatePushTokenRequest::RocketChatUpdatePushTokenRequest( const QStrin #ifdef Q_OS_IOS tokenObject["apn"] = pToken; #endif -#ifdef Q_OS_WINRT - //TODO: implement -#endif if ( tokenObject.size() ) { options[QStringLiteral( "userId" )] = pUserId; diff --git a/engine.pro b/engine.pro index 11f2c172ddffce6cf045d2d509cbc62c6acaf0a6..c2192bd2ae1d0e2db74291b0bd44f20787590046 100644 --- a/engine.pro +++ b/engine.pro @@ -2,7 +2,6 @@ TEMPLATE = lib QT += core network websockets sql concurrent CONFIG += c++11 static INCLUDEPATH += websocket\ - websocket/winrtwebsocket\ websocket/linuxwebsocket SOURCES += api/meteorddp.cpp \ diff --git a/notifications/notifications.cpp b/notifications/notifications.cpp index e9404f89736a5ea9b474b02cc0d91aedfacba18b..9be6626d38fb5e6142a578f4570f96508e3afa84 100755 --- a/notifications/notifications.cpp +++ b/notifications/notifications.cpp @@ -36,9 +36,6 @@ Notifications::Notifications() #endif #ifdef Q_OS_IOS mNotificationInstance = new ApplePushNotifications; -#endif -#ifdef Q_OS_WINRT - #endif if ( mNotificationInstance != nullptr ) { diff --git a/rocketchat.cpp b/rocketchat.cpp index 8890a0271c67e97b39d3d1ea565102b8d9d64fae..73175528760b3d8ccd653cd8fedf9e9fa2d22319 100755 --- a/rocketchat.cpp +++ b/rocketchat.cpp @@ -37,10 +37,6 @@ #include "android/androidcheckpermissions.h" #include "android/androidbadges.h" #endif -#ifdef Q_OS_WINRT -#include "WinRt/keypadhelper.h" -#include <QInputMethod> -#endif #include <QCoreApplication> /** @@ -60,12 +56,6 @@ RocketChat::RocketChat( QGuiApplication *app ) connect( app, &QGuiApplication::applicationStateChanged, this, &RocketChat::onApplicationStateChanged, Qt::UniqueConnection ); this->mStorage = PersistanceLayer::instance(); -#ifdef Q_OS_WINRT - //KeypadHelper *helper = new KeypadHelper(); - //helper->showKeypad(); - mInputMethod = QGuiApplication::inputMethod(); - connect( mInputMethod, &QInputMethod::visibleChanged, this, &RocketChat::onKeyboardVisiblityChanged ); -#endif #ifdef Q_OS_ANDROID mAndroidStatusBarColor = new AndroidStatusBarColor; #endif @@ -276,7 +266,7 @@ void RocketChat::searchRoomByType( const QString &pTerm, const QString &pType ) QMetaObject::invokeMethod( mServerMap.first(), "searchRoom", Q_ARG( QString, pTerm ), Q_ARG( QString, pType ) ); } -bool RocketChat::newServerByDomain( const QString &domain ) +bool RocketChat::newServerByDomain( const QString &domain, bool pUnsecure = false ) { newServerMutex.lock(); mDdpConnectionEstablished = false; @@ -288,14 +278,19 @@ bool RocketChat::newServerByDomain( const QString &domain ) mServerMap.remove( firstServer->getServerId() ); auto self = this; - connect( firstServer, &RocketChatServerData::destroyed, [ &, self, domain]() { + connect( firstServer, &RocketChatServerData::destroyed, [ &, self, domain, pUnsecure]() { qDebug() << "domain: " << domain; - QString baseUrl = domain; - QString apiUri = QStringLiteral( "https://" ) + domain + QStringLiteral( "/api/v1" ); + QString protocol = QStringLiteral( "https://" ); + + if ( pUnsecure ) { + protocol = QStringLiteral( "http://" ); + } + + QString apiUri = protocol + domain + QStringLiteral( "/api/v1" ); Models::resetModels(); - RocketChatServerData *server = new RocketChatServerData( domain, baseUrl, apiUri ); + RocketChatServerData *server = new RocketChatServerData( domain, domain, pUnsecure ); registerServer( server ); newServerMutex.unlock(); @@ -303,12 +298,15 @@ bool RocketChat::newServerByDomain( const QString &domain ) QMetaObject::invokeMethod( firstServer, "deleteLater" ); } else { - QString baseUrl = domain; - QString apiUri = QStringLiteral( "https://" ) + domain + QStringLiteral( "/api/v1" ); + QString protocol = QStringLiteral( "https://" ); + + if ( pUnsecure ) { + protocol = QStringLiteral( "http://" ); + } Models::resetModels(); - RocketChatServerData *server = new RocketChatServerData( domain, baseUrl, apiUri ); + RocketChatServerData *server = new RocketChatServerData( domain, domain, pUnsecure ); registerServer( server ); newServerMutex.unlock(); @@ -834,14 +832,6 @@ void RocketChat::openFileNameReady( const QString &pFile ) } } -void RocketChat::onKeyboardVisiblityChanged() -{ - QRectF keyBoardRect = mInputMethod->keyboardRectangle(); - float height = floor( keyBoardRect.height() / 2 ) - 5; - bool visible = mInputMethod->isVisible(); - emit keyboardVisibilityChanged( visible, height ); -} - void RocketChat::onEmojisReady( const QVariantList &pEmojiList ) { mEmojisReady = true; diff --git a/rocketchat.h b/rocketchat.h index 4da56e824cb19ff950c6d52a03f7bcc313ad983e..54c3136e3fc755b08e9ca6c1137e173ff9afcf6d 100755 --- a/rocketchat.h +++ b/rocketchat.h @@ -50,7 +50,7 @@ class RocketChat : public QObject //TODO: check for depricated methods Q_INVOKABLE void uploadFile( const QString &pChannelId, const QString &pPath ); Q_INVOKABLE void uploadVideo( const QString &pChannelId, const QString &pPath ); - Q_INVOKABLE bool newServerByDomain( const QString &pChannelId ); + Q_INVOKABLE bool newServerByDomain( const QString &pChannelId, bool pUnsecure ); Q_INVOKABLE bool getDdpConnectionEstablished() const; Q_INVOKABLE void getFileRessource( const QString &pUrl ); @@ -253,7 +253,6 @@ class RocketChat : public QObject void openShareDialog(); void serverReady(); void storageReady(); - void keyboardVisibilityChanged( bool visible, float height ); void emojisReady( QVariantList emojis ); void allChannelsReceived( QVariantList channels ); //TODO: use QVariant... diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index b3cd69e2b65e2e1eb0f781810e6f878a23f5f9ca..cb9b88586165b51ce4d647cf76ad1ae106b8c652 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -23,12 +23,21 @@ #include "CustomModels/models.h" -RocketChatServerData::RocketChatServerData( const QString &pId, QString pBaseUrl, - QString pApiUri ): mBaseUrl( pBaseUrl ), mApiUri( pApiUri ), mServerId( pId ), userModel( Models::getUsersModel() ), loginMethodsModel( Models::getLoginMethodsModel() ), channelsModel( Models::getPublicGroupsModel() ), +RocketChatServerData::RocketChatServerData( const QString &pId, QString pBaseUrl, bool pUnsecure ): mBaseUrl( pBaseUrl ), mServerId( pId ), userModel( Models::getUsersModel() ), loginMethodsModel( Models::getLoginMethodsModel() ), channelsModel( Models::getPublicGroupsModel() ), directModel( Models::getDirectChannelsModel() ), groupsModel( Models::getPublicGroupsModel() ) { qRegisterMetaType<User>( "User" ); + mUnsecureConnection = pUnsecure; + + QString protocol = QStringLiteral( "https://" ); + + if ( pUnsecure ) { + protocol = QStringLiteral( "http://" ); + } + + mApiUri = QStringLiteral( "/api/v1" ); + mStorage = PersistanceLayer::instance(); mEmojiRepo = new EmojiRepo; @@ -53,12 +62,17 @@ RocketChatServerData::RocketChatServerData( const QString &pId, QString pBaseUrl }; mFileService = new FileService( this ); mEmojiService = new EmojiService( this, mFileService, mStorage ); - setRestApi( new RestApi( this, QStringLiteral( "https://" ) + mBaseUrl, mApiUri ) ); + setRestApi( new RestApi( this, protocol + mBaseUrl ) ); } void RocketChatServerData::init() { - mDdpApi = new MeteorDDP( this, mBaseUrl ); + if ( mUnsecureConnection ) { + mDdpApi = new MeteorDDP( this, mBaseUrl, true ); + + } else { + mDdpApi = new MeteorDDP( this, mBaseUrl ); + } mRestApi->moveToThread( QThread::currentThread() ); mDdpApi->moveToThread( QThread::currentThread() ); diff --git a/rocketchatserver.h b/rocketchatserver.h index 5ef26b17012df025b38dbf78b091a42758056b43..a7bd8fd03ab0cd12bf9be7709c7678964e7301db 100755 --- a/rocketchatserver.h +++ b/rocketchatserver.h @@ -114,7 +114,7 @@ class RocketChatServerData : public MessageListener Q_OBJECT public: RocketChatServerData( const QString &pId, QString pBaseUrl, - QString pApiUri ); + bool pUnsecure = false ); void setServerId( const QString &pValue ); @@ -259,6 +259,7 @@ class RocketChatServerData : public MessageListener QString mServerId = ""; uint mTokenExpire = 0; QString mResumeToken; + bool mUnsecureConnection = false; MeteorDDP *mDdpApi = nullptr; RestApi *mRestApi = nullptr; diff --git a/services/rocketchatchannelservice.cpp b/services/rocketchatchannelservice.cpp index cf6f3858dea2a1a0bed584a073462084b2e99cfc..202a60ad32344d7dce30a3466470a8e2d6b7e4fc 100755 --- a/services/rocketchatchannelservice.cpp +++ b/services/rocketchatchannelservice.cpp @@ -531,16 +531,17 @@ void RocketChatChannelService::searchRoom( const QString &pTerm, const QString & channelVector RocketChatChannelService::searchRoomLocal( const QString &pTerm, const QHash<QString, bool> &pFilter, const QString &pType, const QHash<QString, bool> &pNames ) { channelVector list; + QString term = pTerm.toLower(); for ( auto channel : mChannels->getElements() ) { QString id = channel->getRoomId(); QString type = channel->getType(); - QString name = channel->getName(); - QString username = channel->getUsername(); + QString name = channel->getName().toLower(); + QString username = channel->getUsername().toLower(); - if ( !pFilter.contains( id ) && !pNames.contains( name ) && pNames.contains( username ) && ( pType.isEmpty() || pType == type ) ) { + if ( !pFilter.contains( id ) && !pNames.contains( name ) && !pNames.contains( username ) && ( pType.isEmpty() || pType == type ) ) { - if ( name.indexOf( pTerm, Qt::CaseInsensitive ) != -1 || username.indexOf( pTerm, Qt::CaseInsensitive ) != -1 ) { + if ( name.indexOf( term, Qt::CaseInsensitive ) != -1 || username.indexOf( term, Qt::CaseInsensitive ) != -1 ) { list.append( channel ); } } @@ -568,6 +569,8 @@ void RocketChatChannelService::openPrivateChannelWith( QString pUsername ) //TODO: fix if ( !mChannels->contains( rid ) ) { DdpCallback success = [ = ]( QJsonObject pResponse, MeteorDDP * pDdp ) { + Q_UNUSED( pDdp ) + if ( pResponse.contains( "result" ) ) { QString name = pResponse["fname"].toString(); QString username = pResponse["name"].toString(); diff --git a/utils.h b/utils.h index ecde00d0c73f2f366c80a38f452dd5107412ddcc..fffe29758b7e9de9ae18f75ada4e3714e2156cfb 100755 --- a/utils.h +++ b/utils.h @@ -32,19 +32,6 @@ class Utils { public: Utils( const Utils & ) {} -#ifdef Q_OS_WINRT - static Platform::String ^QStringToPlatformString( QString string ) - { - std::wstring wstring = string.toStdWString(); - return ref new Platform::String( wstring.c_str() ); - } - static QString PlatformStringToQString( Platform::String ^string ) - { - std::wstring wString = string->Data(); - QString returnString( QString::fromWCharArray( wString.c_str() ) ); - return returnString.length() ? returnString : ""; - } -#endif static QString removeUtf8Emojis( const QString &pText ); static QString linkiFy( const QString &pText ); static QString emojiFy( const QString &pText, EmojiRepo *pEmojiRepo ); diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index f4f2a5ded5e39a0d2499200e2010ab57f2ffca50..df19655dcd67ed816cd37628a9a1ddcc730939ab 100755 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -25,21 +25,12 @@ #include <QDebug> #include "websocket.h" -#ifdef Q_OS_WINRT -#include "websocket/winrtwebsocket/websocketwinrt.h" -#else #include "websocketlinux.h" -#endif Websocket::Websocket( QObject *parent ): WebsocketAbstract( parent ) { qRegisterMetaType<QAbstractSocket::SocketState>( "QAbstractSocket::SocketState" ); -#ifdef Q_OS_WINRT - qDebug() << "Windows RT websocket instantiated"; - mWebsocketInstance = new WinRTWebsocket; -#else mWebsocketInstance = new websocketLinux( this ); -#endif 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 ); diff --git a/websocket/winrtwebsocket/websocketwinrt.cpp b/websocket/winrtwebsocket/websocketwinrt.cpp deleted file mode 100755 index d6b44019aad5d75a98fc93b76d5780982f16a647..0000000000000000000000000000000000000000 --- a/websocket/winrtwebsocket/websocketwinrt.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include "websocketwinrt.h" - -#include <QDebug> -#include <QString> -#include <QUrl> -#include <QObject> -#include <QThread> -#include <QTimer> - -#include <vccorlib.h> -#include <collection.h> -#include <ppltasks.h> -#include <windows.networking.h> -#include <windows.networking.sockets.h> -#include <windows.storage.streams.h> -#include <windows.foundation.h> -#include <windows.ui.core.h> - -#include <iostream> - -using namespace Windows::Networking::Sockets; -using namespace Windows::Storage::Streams; -using namespace Windows::Foundation; -using namespace Platform; -using namespace Windows::Web; -using namespace Windows::UI::Core; -using namespace concurrency; -/* -HRESULT __stdcall GetActivationFactoryByPCWSTR(void*,Guid&, void**); -namespace __winRT -{ - HRESULT __stdcall __getActivationFactoryByPCWSTR(const void* str, ::Platform::Guid& pGuid, void** ppActivationFactory) - { - return GetActivationFactoryByPCWSTR(const_cast<void*>(str), pGuid, ppActivationFactory); - } -}*/ - -WinRTQTSignalHelperClass* WinRTQTSignalHelperClass::helper = NULL; - -WinRTQTSignalHelperClass* WinRTQTSignalHelperClass::instance(){ - if(!helper){ - helper = new WinRTQTSignalHelperClass; - } - return helper; -} - - - -WinRTWebsocket::WinRTWebsocket() -{ - helper = WinRTQTSignalHelperClass::instance(); - connect(helper,&WinRTQTSignalHelperClass::onMessageReceived,this,&WinRTWebsocket::textMessageReceived, Qt::UniqueConnection ); - connect(helper,&WinRTQTSignalHelperClass::onClosed,this,&WinRTWebsocket::closed, Qt::UniqueConnection ); - connect(helper, &WinRTQTSignalHelperClass::onConnected, this, &WinRTWebsocket::connected, Qt::UniqueConnection ); -} - - -void WinRTWebsocket::open(QUrl url){ - QString urlString = url.toString(); - std::wstring urlWString = urlString.toStdWString(); - Platform::String^ refUrl = ref new Platform::String(urlWString.c_str()); - Uri^ server = ref new Uri(refUrl); - serverAdrr = server; - m_context = ref new ReceiveContext; - m_context->init(server); - -} - -void WinRTWebsocket::checkForConnection(){ - if(connectionOpen){ - timer->stop(); - disconnect(timer,&QTimer::timeout,this,&WinRTWebsocket::checkForConnection); - emit(connected()); - } - else{ - //init(serverAdrr); - } -} - -void WinRTWebsocket::close(){ - m_context->close(); -} - -void WinRTWebsocket::sendTextMessage(QString message){ - - m_context->SendMessage(WinRTWebsocket::QStringToPlatformString(message)); - -} - -bool WinRTWebsocket::isValid() -{ - //todo: fix it! - return true; -} - -void WinRTWebsocket::emitOnMessageReceived(QString message) -{ - //emit(MessageReceived(message)); -} - -void WinRTWebsocket::emitOnClosed(){ - close(); - emit(closed()); -} - -void WinRTQTSignalHelperClass::emitOnMessageReceived(QString message) -{ - emit(onMessageReceived(message)); -} - -void WinRTQTSignalHelperClass::emitOnClosed(){ - emit(onClosed()); -} - -void WinRTQTSignalHelperClass::emitOnConnected() { - emit(onConnected()); -} - -WinRTWebsocket::~WinRTWebsocket(){ - close(); - disconnect(helper, &WinRTQTSignalHelperClass::onMessageReceived, this, &WinRTWebsocket::textMessageReceived); - disconnect(helper, &WinRTQTSignalHelperClass::onClosed, this, &WinRTWebsocket::closed); - disconnect(helper, &WinRTQTSignalHelperClass::onConnected, this, &WinRTWebsocket::connected); - // delete helper; - timer->deleteLater(); -} - - -ReceiveContext::ReceiveContext(){ - helper = WinRTQTSignalHelperClass::instance(); -} - -void ReceiveContext::init(Uri^ server){ - qDebug()<<"WinRT init connection"; - - webSocket = ref new MessageWebSocket(); - - webSocket->Control->MessageType = SocketMessageType::Utf8; - webSocket->MessageReceived += ref new TypedEventHandler<MessageWebSocket^, MessageWebSocketMessageReceivedEventArgs^>(this, &ReceiveContext::OnReceive); - webSocket->Closed += ref new TypedEventHandler<IWebSocket^, WebSocketClosedEventArgs^>(this, &ReceiveContext::Closed); - qDebug()<<"start connection task"; - webSocket->ConnectAsync(server); - qDebug()<<"started connection task"; -} - -void ReceiveContext::SendMessage(Platform::String ^message){ - - if(messageWriter){ - messageWriter->WriteString(message); - - messageWriter->StoreAsync(); - } -} - -void ReceiveContext::HandleException(Exception^ exception){ - qDebug()<<"exception"; - WebErrorStatus status = WebSocketError::GetStatus(exception->HResult); - Platform::String^ error = status.ToString(); - qDebug()<<QString::fromStdWString(error->Data()); -} - -void ReceiveContext::OnReceive(MessageWebSocket^ sender, MessageWebSocketMessageReceivedEventArgs^ args){ - if (!connected) { - connected = true; - helper->emitOnConnected(); - } - if(messageWriter == nullptr){ - messageWebSocket = webSocket; - messageWriter = ref new DataWriter(webSocket->OutputStream); - } - - DataReader^ reader = args->GetDataReader(); - reader->UnicodeEncoding = UnicodeEncoding::Utf8; - String^ read = reader->ReadString(reader->UnconsumedBufferLength); - helper->emitOnMessageReceived(WinRTWebsocket::PlatformStringToQString(read)); -} - -void ReceiveContext::Closed(IWebSocket^ sender, WebSocketClosedEventArgs^ args){ - qDebug()<<"closing"; - - helper->emitOnClosed(); -} - -void setupWriter() -{ - -} - -void ReceiveContext::checkMessage(Platform::String^ message) -{ -// if(MessageWebSocket == nullptr){ -// messageWebSocket -// } -} - -void ReceiveContext::close() -{ - try - { - if (messageWebSocket != nullptr) - { - qDebug()<<"closing connection"; - messageWebSocket->Close(1000, "Closed due to user request."); - messageWebSocket = nullptr; - } - else - { - qDebug()<<"connection allready closed"; - } - } - catch (Exception^ exception) - { - HandleException(exception); - } -} diff --git a/websocket/winrtwebsocket/websocketwinrt.h b/websocket/winrtwebsocket/websocketwinrt.h deleted file mode 100755 index 5d40dba6ca28e009ec62f1dbf786458efb074e86..0000000000000000000000000000000000000000 --- a/websocket/winrtwebsocket/websocketwinrt.h +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef WINRTWEBSOCKET_H -#define WINRTWEBSOCKET_H - -#include <QObject> -#include <QTimer> -#include <QVector> -#include <vccorlib.h> -#include <collection.h> -#include <ppltasks.h> -#include <windows.networking.h> -#include <windows.networking.sockets.h> -#include <windows.storage.streams.h> -#include <windows.foundation.h> -#include <windows.ui.core.h> -#include <codecvt> - -#include "websocketabstract.h" -#include "WinRt/winrtfix.h" - - -using namespace Windows::Networking::Sockets; -using namespace Windows::Storage::Streams; -using namespace Windows::Foundation; -using namespace Platform; -using namespace Windows::Web; -using namespace Windows::UI::Core; -using namespace concurrency; - - -//singelton to communicate between ref class an QT -class WinRTQTSignalHelperClass:public QObject{ - Q_OBJECT -public: - WinRTQTSignalHelperClass(){}; - WinRTQTSignalHelperClass(const WinRTQTSignalHelperClass&){}; - - ~WinRTQTSignalHelperClass(){}; - - static WinRTQTSignalHelperClass *helper; - static WinRTQTSignalHelperClass* instance(); - void emitOnClosed(); - void emitOnMessageReceived(QString); - void emitOnConnected(); - -signals: - - void onMessageReceived(QString); - void onClosed(); - void onConnected(); -}; - - -//class to handle responses -ref class ReceiveContext sealed{ -private: - //ugly hack because of Microsoft... - WinRTQTSignalHelperClass* helper; - - MessageWebSocket^ messageWebSocket; - MessageWebSocket^ webSocket; - - bool connected = false; - - DataWriter^ messageWriter; - void HandleException(Exception^ exception); - void checkMessage(Platform::String^); - - -public: - friend class WinRTWebsocket; - ReceiveContext(); - void SendMessage(Platform::String^); - void init( Uri^); - void close(); - void OnReceive(MessageWebSocket^ sender, MessageWebSocketMessageReceivedEventArgs^ args); - void Closed(IWebSocket^ sender, WebSocketClosedEventArgs^ args); - -}; - -class WinRTWebsocket:public WebsocketAbstract -{ - Q_OBJECT -public: - WinRTWebsocket(); - - virtual void open(QUrl) override; - virtual void close() override; - virtual void sendTextMessage(QString) override; - virtual bool isValid(); - - static Platform::String^ QStringToPlatformString(QString string){ - std::string stdString = string.toStdString(); - std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; - std::wstring wstdString = converter.from_bytes(stdString); - return ref new Platform::String(wstdString.c_str()); - } - static QString PlatformStringToQString(Platform::String ^string){ - std::wstring wString = string->Data(); - - using convert_type = std::codecvt_utf8<wchar_t>; - std::wstring_convert<convert_type, wchar_t> converter; - std::string stdString = converter.to_bytes(wString); - - QString retString = QString::fromStdString(stdString); - - return retString.length()?retString:""; - } - - ~WinRTWebsocket(); - -private: - QTimer *timer; - bool connectionOpen=false; - - Uri^ serverAdrr; - int newMessage=0; - WinRTQTSignalHelperClass* helper; - - ReceiveContext^ m_context; - - void checkForConnection(); -signals: - void MessageReceived(QString); - -private slots: - void emitOnMessageReceived(QString); - void emitOnClosed(); -}; - - - -#endif // WINRTWEBSOCKET_H