From 873642c0d898f3152b251a783bf4cdef47070d4c Mon Sep 17 00:00:00 2001 From: Alex Borisov Date: Thu, 2 Feb 2012 00:33:44 +0200 Subject: FIX: implement async connection requests --- client/ProxyClientApp.cpp | 22 ++++++++-------------- client/SslClient.cpp | 19 +++++++++++++++++-- client/SslClient.h | 6 ++++++ 3 files changed, 31 insertions(+), 16 deletions(-) (limited to 'client') diff --git a/client/ProxyClientApp.cpp b/client/ProxyClientApp.cpp index f9cbf78..b55c33c 100644 --- a/client/ProxyClientApp.cpp +++ b/client/ProxyClientApp.cpp @@ -1,7 +1,5 @@ -#include -#include -#include +#include #include "client.h" #include "Dialog.h" @@ -70,17 +68,6 @@ ProxyClientApp::ProxyClientApp(int &argc, char *argv[]): QApplication(argc, argv welcomeMsg.setStandardButtons(QMessageBox::Ok); welcomeMsg.setIcon(QMessageBox::Information); welcomeMsg.exec(); - - /* - vector > files; - pair file; - file = make_pair("../main.cpp", "70ba1d68907cc9d3"); - files.push_back(file); - - //QString addr = QString::fromLocal8Bit(); - DownloadClient downloadClient("127.0.0.1"); - downloadClient.Download(files); - */ } void ProxyClientApp::trayActivated(QSystemTrayIcon::ActivationReason reason) @@ -94,8 +81,15 @@ void ProxyClientApp::trayActivated(QSystemTrayIcon::ActivationReason reason) void ProxyClientApp::showProxyDialog() { Logger::Trace("Creating proxy dialog.\n"); + QDesktopWidget* screen = QApplication::desktop(); + QRect availScreenRect = screen->availableGeometry(); + + Logger::Debug("Available screen size WxH = %d x %d\n", availScreenRect.width(), availScreenRect.height()); + ProxyDialog *dialog = new ProxyDialog(); dialog->show(); + dialog->move(availScreenRect.width() - dialog->frameSize().width(), + availScreenRect.height() - dialog->frameSize().height()); } void ProxyClientApp::configUpdated() diff --git a/client/SslClient.cpp b/client/SslClient.cpp index e13a028..3909210 100644 --- a/client/SslClient.cpp +++ b/client/SslClient.cpp @@ -13,6 +13,7 @@ SslClient::SslClient(): port(13666) SslClient::SslClient(QString addr): port(13666) { server = addr; + _currentRequest = Unknown; /* read certificates */ QFile ca_cert_file(":/ca.crt"); @@ -74,8 +75,8 @@ void SslClient::SendRequest(RequestType type) if (sslSocket.state() != QAbstractSocket::ConnectedState) { Logger::Trace("Connecting to server %s:%u\n", server.toLocal8Bit().data(), port); + _currentRequest = type; sslSocket.connectToHostEncrypted(server, port); - sslSocket.waitForEncrypted(-1); } else { @@ -101,6 +102,7 @@ void SslClient::SendRequest(RequestType type) char data[5] = {0x13, 0x13, rcode, 0x14, 0x14}; QByteArray pkt(data); sslSocket.write(pkt); + _currentRequest = Unknown; } void SslClient::SendFileRequest(string filename) @@ -109,8 +111,9 @@ void SslClient::SendFileRequest(string filename) if (sslSocket.state() != QAbstractSocket::ConnectedState) { Logger::Trace("Connecting to server %s:%u\n", server.toLocal8Bit().data(), port); + _currentFile = filename; + _currentRequest = RegularFile; sslSocket.connectToHostEncrypted(server, port); - sslSocket.waitForEncrypted(-1); } else { @@ -128,6 +131,7 @@ void SslClient::SendFileRequest(string filename) data[pkt_size - 1] = data[pkt_size - 2] = 0x14; QByteArray pkt(data); sslSocket.write(pkt); + _currentRequest = Unknown; } @@ -137,6 +141,17 @@ void SslClient::SendFileRequest(string filename) void SslClient::Connected() { Logger::Info("Connected to server %s\n", server.toStdString().c_str()); + if (_currentRequest != Unknown) + { + if (_currentRequest == RegularFile) + { + SendFileRequest(_currentFile); + } + else + { + SendRequest(_currentRequest); + } + } } void SslClient::Disconnected() diff --git a/client/SslClient.h b/client/SslClient.h index 1d3256f..b0528d6 100644 --- a/client/SslClient.h +++ b/client/SslClient.h @@ -47,6 +47,10 @@ public: */ enum RequestType { + /** + * @brief + */ + Unknown = 0x00, /** * @brief Request generic config */ @@ -152,6 +156,8 @@ private: QSslSocket sslSocket; QByteArray pkt; unsigned short port; + RequestType _currentRequest; + string _currentFile; }; #endif \ No newline at end of file -- cgit v1.2.3