add network checking. now we can handle network link errors
This commit is contained in:
parent
090dc28137
commit
e029f9c615
4 changed files with 72 additions and 57 deletions
|
@ -185,7 +185,9 @@ void MainScreen::on_ratesButton_clicked()
|
||||||
int status = 0;
|
int status = 0;
|
||||||
if (loginHandel->isLoggedInFlag())
|
if (loginHandel->isLoggedInFlag())
|
||||||
{
|
{
|
||||||
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED)
|
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),
|
||||||
|
ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),
|
||||||
|
ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED)
|
||||||
{
|
{
|
||||||
pageString = loginHandel->getCurrentPageContect();
|
pageString = loginHandel->getCurrentPageContect();
|
||||||
courseTableMgr->setCoursesList(pageString);
|
courseTableMgr->setCoursesList(pageString);
|
||||||
|
@ -283,13 +285,13 @@ void MainScreen::on_actionCredits_triggered()
|
||||||
QMessageBox::about(this, "About", tr("CREDITS-ROOL-UP1") + " v1.0<br><br>"
|
QMessageBox::about(this, "About", tr("CREDITS-ROOL-UP1") + " v1.0<br><br>"
|
||||||
+ tr("CREDITS-ROOL-UP2")+"<br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>"
|
+ tr("CREDITS-ROOL-UP2")+"<br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>"
|
||||||
+ tr("CREDITS-ROOL-UP3")+"<br>"
|
+ tr("CREDITS-ROOL-UP3")+"<br>"
|
||||||
"<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>"
|
"<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>"
|
||||||
"<br><br>"+tr("CREDITS-ROOL-UP4")+"<a href='https://github.com/liranbg/jceConnection'> Jce Connection</a><br><br>"
|
"<br><br>"+tr("CREDITS-ROOL-UP4")+"<a href='https://github.com/liranbg/jceConnection'> Jce Connection</a><br><br>"
|
||||||
+tr("DevBy")+":"
|
+tr("DevBy")+":"
|
||||||
"<ul>"
|
"<ul>"
|
||||||
"<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran")+"</a></li>"
|
"<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran")+"</a></li>"
|
||||||
"<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li>"
|
"<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li>"
|
||||||
"</ul>");
|
"</ul>");
|
||||||
}
|
}
|
||||||
void MainScreen::on_actionExit_triggered()
|
void MainScreen::on_actionExit_triggered()
|
||||||
{
|
{
|
||||||
|
@ -301,13 +303,11 @@ void MainScreen::on_actionHow_To_triggered()
|
||||||
"<b>How To..</b>"
|
"<b>How To..</b>"
|
||||||
"<ul>"
|
"<ul>"
|
||||||
"<br><li>"+tr("HELP1")+"</li>"
|
"<br><li>"+tr("HELP1")+"</li>"
|
||||||
"<br><li>"+tr("HELP2")+"</li>"
|
"<br><li>"+tr("HELP2")+"</li>"
|
||||||
"<br><li>"+tr("HELP3")+"</li>"
|
"<br><li>"+tr("HELP3")+"</li>"
|
||||||
"<br><li>"+tr("HELP4")+"</li>"
|
"<br><li>"+tr("HELP4")+"</li>"
|
||||||
"<br><li>"+tr("HELP5")+"</li>"
|
"<br><li>"+tr("HELP5")+"</li>"
|
||||||
"<br><br>"+tr("HELP6")+
|
|
||||||
"</ul>");
|
"</ul>");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
#include "jcesslclient.h"
|
#include "jcesslclient.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
|
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
|
||||||
*/
|
*/
|
||||||
jceSSLClient::jceSSLClient() : flag(false), packet("")
|
jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf()
|
||||||
{
|
{
|
||||||
//setting signals
|
//setting signals
|
||||||
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
|
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
|
||||||
connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
|
connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
|
||||||
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
|
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
|
||||||
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
|
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
|
||||||
|
connect(&networkConf,SIGNAL(onlineStateChanged(bool)),this,SLOT(setOnlineState(bool)));
|
||||||
|
|
||||||
//loop event will connect the server, and when it is connected, it will quit - but connection will be open
|
//loop event will connect the server, and when it is connected, it will quit - but connection will be open
|
||||||
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
|
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
|
||||||
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit()));
|
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit()));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,37 +54,16 @@ bool jceSSLClient::makeConnect(QString server, int port)
|
||||||
*/
|
*/
|
||||||
bool jceSSLClient::makeDiconnect()
|
bool jceSSLClient::makeDiconnect()
|
||||||
{
|
{
|
||||||
qDebug() << "jceSSLClient::makeDiconnect;";
|
|
||||||
if (loop.isRunning())
|
if (loop.isRunning())
|
||||||
{
|
{
|
||||||
qWarning() << "jceSSLClient::makeDiconnect; Killing connection thread";
|
qWarning() << Q_FUNC_INFO << "Killing connection thread";
|
||||||
loop.exit();
|
loop.exit();
|
||||||
}
|
|
||||||
if (state() == QAbstractSocket::SocketState::UnconnectedState)
|
|
||||||
{
|
|
||||||
qDebug() << "jceSSLClient::makeDiconnect; Disconnected with [UnconnectedState]";
|
|
||||||
flag = false;
|
|
||||||
}
|
}
|
||||||
else if (state() == QAbstractSocket::SocketState::ConnectedState)
|
qDebug() << Q_FUNC_INFO << "emitting disconnected()";
|
||||||
{
|
emit disconnected();
|
||||||
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting with [ConnectedState] ";
|
return isConnected();
|
||||||
abort();
|
|
||||||
if (state() != QAbstractSocket::SocketState::UnconnectedState)
|
|
||||||
{
|
|
||||||
qWarning() << "jceSSLClient::makeDiconnect; still open! recursion call to disconnect";
|
|
||||||
abort();//still connected? ensure the disconnection
|
|
||||||
flag = makeDiconnect(); //recursion call!
|
|
||||||
}
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting [else] ";
|
|
||||||
abort(); //ensure the disconnection
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
qDebug() << "jceSSLClient::makeDiconnect; disconnect return with " << flag;
|
|
||||||
return flag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,8 +83,17 @@ bool jceSSLClient::isConnected()
|
||||||
}
|
}
|
||||||
else if (state() == QAbstractSocket::SocketState::ConnectedState)
|
else if (state() == QAbstractSocket::SocketState::ConnectedState)
|
||||||
{
|
{
|
||||||
flag = true;
|
if (this->networkConf.isOnline())
|
||||||
|
flag = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (!this->networkConf.isOnline()) //no link, ethernet\wifi
|
||||||
|
flag = false;
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -177,6 +168,21 @@ void jceSSLClient::readIt()
|
||||||
packet.append(p);
|
packet.append(p);
|
||||||
}while (p.size() > 0);
|
}while (p.size() > 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void jceSSLClient::setOnlineState(bool isOnline)
|
||||||
|
{
|
||||||
|
qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline;
|
||||||
|
if (isOnline)
|
||||||
|
{
|
||||||
|
this->makeConnect();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->makeDiconnect();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceSSLClient::setConnected called when signaled with connected, calling the encryption function
|
* @brief jceSSLClient::setConnected called when signaled with connected, calling the encryption function
|
||||||
|
@ -186,10 +192,13 @@ void jceSSLClient::setConnected()
|
||||||
waitForEncrypted();
|
waitForEncrypted();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief jceSSLClient::setDisconnected called when signaled with disconnected, setting flag to false
|
* @brief jceSSLClient::setDisconnected closing socket, updating state and setting flag to false
|
||||||
*/
|
*/
|
||||||
void jceSSLClient::setDisconnected()
|
void jceSSLClient::setDisconnected()
|
||||||
{
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << "DISCONNECTED";
|
||||||
|
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
|
||||||
|
abort();
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -199,8 +208,7 @@ void jceSSLClient::setEncrypted()
|
||||||
{
|
{
|
||||||
setReadBufferSize(10000);
|
setReadBufferSize(10000);
|
||||||
setSocketOption(QAbstractSocket::KeepAliveOption,1);
|
setSocketOption(QAbstractSocket::KeepAliveOption,1);
|
||||||
if (state() == QAbstractSocket::SocketState::ConnectedState)
|
if (isConnected());
|
||||||
flag = true;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!";
|
qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!";
|
||||||
|
@ -226,6 +234,7 @@ void jceSSLClient::showIfErrorMsg()
|
||||||
break;
|
break;
|
||||||
case QAbstractSocket::SocketError::RemoteHostClosedError:
|
case QAbstractSocket::SocketError::RemoteHostClosedError:
|
||||||
errorString = QObject::tr("RemoteHostClosedError");
|
errorString = QObject::tr("RemoteHostClosedError");
|
||||||
|
|
||||||
relevantError = true;
|
relevantError = true;
|
||||||
break;
|
break;
|
||||||
case QAbstractSocket::SocketError::HostNotFoundError:
|
case QAbstractSocket::SocketError::HostNotFoundError:
|
||||||
|
@ -240,8 +249,12 @@ void jceSSLClient::showIfErrorMsg()
|
||||||
break;
|
break;
|
||||||
case QAbstractSocket::SocketError::SocketTimeoutError:
|
case QAbstractSocket::SocketError::SocketTimeoutError:
|
||||||
errorString = QObject::tr("SocketTimeoutError");
|
errorString = QObject::tr("SocketTimeoutError");
|
||||||
if (!isConnected())
|
|
||||||
|
if (state() == QAbstractSocket::SocketState::UnconnectedState)
|
||||||
|
{
|
||||||
|
|
||||||
relevantError = true;
|
relevantError = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case QAbstractSocket::SocketError::DatagramTooLargeError:
|
case QAbstractSocket::SocketError::DatagramTooLargeError:
|
||||||
errorString = QObject::tr("DatagramTooLargeError");
|
errorString = QObject::tr("DatagramTooLargeError");
|
||||||
|
@ -315,8 +328,10 @@ void jceSSLClient::showIfErrorMsg()
|
||||||
*/
|
*/
|
||||||
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
|
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
|
||||||
{
|
{
|
||||||
qWarning() << "jceSSLClient::checkErrors; Var Error: " << a;
|
qWarning() << Q_FUNC_INFO << "isOnline?: " << this->networkConf.isOnline();
|
||||||
qWarning() << "jceSSLClient::checkErrors; Error: " << this->errorString();
|
qWarning() << Q_FUNC_INFO << "state is: " << state();
|
||||||
|
qWarning() << Q_FUNC_INFO << "Var Error: " << a;
|
||||||
|
qWarning() << Q_FUNC_INFO << "Error: " << errorString();
|
||||||
showIfErrorMsg();
|
showIfErrorMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,9 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QNetworkConfigurationManager>
|
||||||
|
|
||||||
#include <iostream>
|
#define milisTimeOut 4000
|
||||||
#include <string>
|
|
||||||
#define milisTimeOut 3500
|
|
||||||
|
|
||||||
class jceSSLClient : QSslSocket
|
class jceSSLClient : QSslSocket
|
||||||
{
|
{
|
||||||
|
@ -17,11 +16,11 @@ class jceSSLClient : QSslSocket
|
||||||
public:
|
public:
|
||||||
jceSSLClient();
|
jceSSLClient();
|
||||||
|
|
||||||
bool makeConnect(QString server, int port);
|
bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443);
|
||||||
|
bool makeDiconnect();
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
bool sendData(QString str);
|
bool sendData(QString str);
|
||||||
bool recieveData(QString &str, bool fast);
|
bool recieveData(QString &str, bool fast);
|
||||||
bool makeDiconnect();
|
|
||||||
void showIfErrorMsg();
|
void showIfErrorMsg();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -30,12 +29,14 @@ private slots:
|
||||||
void setEncrypted();
|
void setEncrypted();
|
||||||
void setDisconnected();
|
void setDisconnected();
|
||||||
void readIt();
|
void readIt();
|
||||||
|
void setOnlineState(bool isOnline);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool flag;
|
bool flag;
|
||||||
QString packet;
|
QString packet;
|
||||||
QEventLoop loop; //handle the connection as thread
|
QEventLoop loop; //handle the connection as thread
|
||||||
|
QNetworkConfigurationManager networkConf; //checking online
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,6 @@ int jceLogin::getCalendar(int year, int semester)
|
||||||
*/
|
*/
|
||||||
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
|
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
|
||||||
{
|
{
|
||||||
std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
|
|
||||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
|
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
|
||||||
{
|
{
|
||||||
if (!(JceConnector->recieveData(*recieverPage,false)))
|
if (!(JceConnector->recieveData(*recieverPage,false)))
|
||||||
|
|
Loading…
Reference in a new issue