summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Borisov <b0ric.alex@gmail.com>2012-02-02 00:33:44 +0200
committerAlex Borisov <b0ric.alex@gmail.com>2012-02-02 00:33:44 +0200
commit873642c0d898f3152b251a783bf4cdef47070d4c (patch)
treef271bf4f62122f21dd32c27fb62d80f60bc0c54c
parentf381a83786d233ca183f3d45f892c4f064a77a58 (diff)
FIX: implement async connection requests
-rw-r--r--client/ProxyClientApp.cpp22
-rw-r--r--client/SslClient.cpp19
-rw-r--r--client/SslClient.h6
3 files changed, 31 insertions, 16 deletions
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 <QMenu>
-#include <QMessageBox>
-#include <QFileInfo>
+#include <QtGui>
#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<pair<string, string> > files;
- pair<string, string> 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
@@ -48,6 +48,10 @@ public:
enum RequestType
{
/**
+ * @brief
+ */
+ Unknown = 0x00,
+ /**
* @brief Request generic config
*/
Config = 0x01,
@@ -152,6 +156,8 @@ private:
QSslSocket sslSocket;
QByteArray pkt;
unsigned short port;
+ RequestType _currentRequest;
+ string _currentFile;
};
#endif \ No newline at end of file