fixing qt ssl socket

This commit is contained in:
Liran BN 2014-06-20 20:13:21 +03:00
parent ee25c1f94b
commit 57f1481a43
8 changed files with 60 additions and 37 deletions

View file

@ -82,6 +82,7 @@ bool loginHandler::makeConnection()
return false; return false;
} }
bool loginHandler::isLoggedInFlag() bool loginHandler::isLoggedInFlag()
{ {
return this->logggedInFlag; return this->logggedInFlag;

View file

@ -34,6 +34,9 @@ private:
QLabel *statusLabelPtr; QLabel *statusLabelPtr;
QLineEdit *pswdEditPtr; QLineEdit *pswdEditPtr;
QLineEdit *usrnmEditPtr; QLineEdit *usrnmEditPtr;
}; };
#endif // LOGINHANDLER_H #endif // LOGINHANDLER_H

View file

@ -50,9 +50,18 @@ MainScreen::~MainScreen()
delete loginHandel; delete loginHandel;
delete ui; delete ui;
} }
void MainScreen::on_loginButton_clicked()
{
if (loginHandel->isLoggedInFlag())
uiSetDisconnectMode();
else
uiSetConnectMode();
}
void MainScreen::on_ratesButton_clicked() void MainScreen::on_ratesButton_clicked()
{ {
std::string pageString; std::string pageString;
int status = 0; int status = 0;
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
@ -72,7 +81,6 @@ void MainScreen::on_ratesButton_clicked()
} }
void MainScreen::on_spinBoxFromYear_editingFinished() void MainScreen::on_spinBoxFromYear_editingFinished()
{ {
if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value())
@ -128,15 +136,7 @@ void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
QMessageBox::critical(this,"Error","Missmatching data"); QMessageBox::critical(this,"Error","Missmatching data");
} }
void MainScreen::on_loginButton_clicked()
{
if (loginHandel->isLoggedInFlag())
uiSetDisconnectMode();
else
uiSetConnectMode();
}
void MainScreen::on_checkBox_toggled(bool checked) void MainScreen::on_checkBox_toggled(bool checked)
{ {
@ -192,7 +192,6 @@ void MainScreen::uiSetConnectMode() //fix before distrbute
userLoginSetting->setPassword(password); userLoginSetting->setPassword(password);
this->loginHandel->setPointers(statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit); this->loginHandel->setPointers(statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
if (loginHandel->makeConnection() == true) if (loginHandel->makeConnection() == true)
{ {
setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
@ -200,6 +199,7 @@ void MainScreen::uiSetConnectMode() //fix before distrbute
this->ui->ratesButton->setEnabled(true); this->ui->ratesButton->setEnabled(true);
ui->CoursesTab->setEnabled(true); ui->CoursesTab->setEnabled(true);
ui->SettingsTab->setEnabled(true); ui->SettingsTab->setEnabled(true);
} }
else else
{ {

View file

@ -293,9 +293,6 @@ font-size: 15px;
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="CoursesTab"> <widget class="QWidget" name="CoursesTab">
@ -587,9 +584,6 @@ font-size: 15px;
<property name="readOnly"> <property name="readOnly">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
<property name="minimum"> <property name="minimum">
<number>2009</number> <number>2009</number>
</property> </property>
@ -599,6 +593,9 @@ font-size: 15px;
<property name="value"> <property name="value">
<number>2009</number> <number>2009</number>
</property> </property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -655,7 +652,7 @@ font-size: 15px;
<item row="1" column="0"> <item row="1" column="0">
<widget class="QCheckBox" name="checkBox"> <widget class="QCheckBox" name="checkBox">
<property name="text"> <property name="text">
<string>Only influences Courses</string> <string>Only influence Courses</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>false</bool>
@ -678,7 +675,7 @@ font-size: 15px;
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>855</width> <width>855</width>
<height>29</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuA_about"> <widget class="QMenu" name="menuA_about">

View file

@ -3,29 +3,24 @@
bool qtsslsocket::makeConnect(std::string server,int port) bool qtsslsocket::makeConnect(std::string server,int port)
{ {
if (this->socket != NULL) //already connected? if (isCon())
{ socket->abort();
socket->close();
socket = NULL;
}
if (this->socket == NULL) //if was connected, we deleted it and remake it
socket = new QSslSocket();
if (this->socket != NULL) //now we will connect it to host
{
socket->connectToHostEncrypted(server.c_str(), port); socket->connectToHostEncrypted(server.c_str(), port);
if (socket->waitForEncrypted()) //waiting for encryption socket->waitForEncrypted();
flag = true;
}
return isCon(); //return true/false upon isCon function return true; //return true/false upon isCon function
} }
qtsslsocket::qtsslsocket() : flag(false) qtsslsocket::qtsslsocket() : flag(false)
{ {
socket = new QSslSocket(); socket = new QSslSocket();
connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
connect(socket,SIGNAL(connected()),this,SLOT(setConnected()));
connect(socket,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
this->flag = true;
} }
@ -72,3 +67,21 @@ bool qtsslsocket::makeDiconnect()
return false; return false;
return true; return true;
} }
void qtsslsocket::checkErrors(QAbstractSocket::SocketError info)
{
}
void qtsslsocket::setConnected()
{
// socket->waitForEncrypted();
}
void qtsslsocket::setEncrypted()
{
// this->flag = true;
}

View file

@ -7,7 +7,7 @@
#include <QString> #include <QString>
#include <iostream> #include <iostream>
#include <string> #include <string>
#define milisTimeOut 3000 #define milisTimeOut 3500
class qtsslsocket : public QObject class qtsslsocket : public QObject
{ {
@ -24,10 +24,18 @@ public:
bool makeDiconnect(); bool makeDiconnect();
private slots:
void checkErrors(QAbstractSocket::SocketError);
void setConnected();
void setEncrypted();
private: private:
QSslSocket *socket; QSslSocket *socket;
bool flag; bool flag;
}; };
#endif // QTSSLSOCKET_H #endif // QTSSLSOCKET_H

View file

@ -5,6 +5,7 @@ jceLogin::jceLogin(user * username)
this->recieverPage = new std::string(); this->recieverPage = new std::string();
this->jceA = username; this->jceA = username;
this->JceConnector = new qtsslsocket(); this->JceConnector = new qtsslsocket();
} }
jceLogin::~jceLogin() jceLogin::~jceLogin()

View file

@ -9,8 +9,6 @@
#include "jceLoginHtmlScripts.h" #include "jceLoginHtmlScripts.h"
class jceLogin class jceLogin
{ {
public: public:
@ -43,6 +41,8 @@ public:
private: private:
int makeFirstVisit(); int makeFirstVisit();
bool checkValidation(); bool checkValidation();