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;
|
||||
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();
|
||||
courseTableMgr->setCoursesList(pageString);
|
||||
|
@ -283,13 +285,13 @@ void MainScreen::on_actionCredits_triggered()
|
|||
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-UP3")+"<br>"
|
||||
"<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>"
|
||||
"<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>"
|
||||
+tr("DevBy")+":"
|
||||
"<ul>"
|
||||
"<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran")+"</a></li>"
|
||||
"<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li>"
|
||||
"</ul>");
|
||||
"<ul>"
|
||||
"<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran")+"</a></li>"
|
||||
"<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li>"
|
||||
"</ul>");
|
||||
}
|
||||
void MainScreen::on_actionExit_triggered()
|
||||
{
|
||||
|
@ -301,13 +303,11 @@ void MainScreen::on_actionHow_To_triggered()
|
|||
"<b>How To..</b>"
|
||||
"<ul>"
|
||||
"<br><li>"+tr("HELP1")+"</li>"
|
||||
"<br><li>"+tr("HELP2")+"</li>"
|
||||
"<br><li>"+tr("HELP3")+"</li>"
|
||||
"<br><li>"+tr("HELP4")+"</li>"
|
||||
"<br><li>"+tr("HELP5")+"</li>"
|
||||
"<br><br>"+tr("HELP6")+
|
||||
"<br><li>"+tr("HELP2")+"</li>"
|
||||
"<br><li>"+tr("HELP3")+"</li>"
|
||||
"<br><li>"+tr("HELP4")+"</li>"
|
||||
"<br><li>"+tr("HELP5")+"</li>"
|
||||
"</ul>");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
#include "jcesslclient.h"
|
||||
|
||||
/**
|
||||
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
|
||||
*/
|
||||
jceSSLClient::jceSSLClient() : flag(false), packet("")
|
||||
jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf()
|
||||
{
|
||||
//setting signals
|
||||
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
|
||||
connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
|
||||
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
|
||||
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
|
||||
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
|
||||
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit()));
|
||||
connect(this, SIGNAL(encrypted()), &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()
|
||||
{
|
||||
qDebug() << "jceSSLClient::makeDiconnect;";
|
||||
|
||||
if (loop.isRunning())
|
||||
{
|
||||
qWarning() << "jceSSLClient::makeDiconnect; Killing connection thread";
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "Killing connection thread";
|
||||
loop.exit();
|
||||
}
|
||||
if (state() == QAbstractSocket::SocketState::UnconnectedState)
|
||||
{
|
||||
qDebug() << "jceSSLClient::makeDiconnect; Disconnected with [UnconnectedState]";
|
||||
flag = false;
|
||||
}
|
||||
else if (state() == QAbstractSocket::SocketState::ConnectedState)
|
||||
{
|
||||
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting with [ConnectedState] ";
|
||||
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;
|
||||
qDebug() << Q_FUNC_INFO << "emitting disconnected()";
|
||||
emit disconnected();
|
||||
return isConnected();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,8 +83,17 @@ bool jceSSLClient::isConnected()
|
|||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
|
@ -177,6 +168,21 @@ void jceSSLClient::readIt()
|
|||
packet.append(p);
|
||||
}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
|
||||
|
@ -186,10 +192,13 @@ void jceSSLClient::setConnected()
|
|||
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()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "DISCONNECTED";
|
||||
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
|
||||
abort();
|
||||
flag = false;
|
||||
}
|
||||
/**
|
||||
|
@ -199,8 +208,7 @@ void jceSSLClient::setEncrypted()
|
|||
{
|
||||
setReadBufferSize(10000);
|
||||
setSocketOption(QAbstractSocket::KeepAliveOption,1);
|
||||
if (state() == QAbstractSocket::SocketState::ConnectedState)
|
||||
flag = true;
|
||||
if (isConnected());
|
||||
else
|
||||
{
|
||||
qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!";
|
||||
|
@ -226,6 +234,7 @@ void jceSSLClient::showIfErrorMsg()
|
|||
break;
|
||||
case QAbstractSocket::SocketError::RemoteHostClosedError:
|
||||
errorString = QObject::tr("RemoteHostClosedError");
|
||||
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::HostNotFoundError:
|
||||
|
@ -240,8 +249,12 @@ void jceSSLClient::showIfErrorMsg()
|
|||
break;
|
||||
case QAbstractSocket::SocketError::SocketTimeoutError:
|
||||
errorString = QObject::tr("SocketTimeoutError");
|
||||
if (!isConnected())
|
||||
|
||||
if (state() == QAbstractSocket::SocketState::UnconnectedState)
|
||||
{
|
||||
|
||||
relevantError = true;
|
||||
}
|
||||
break;
|
||||
case QAbstractSocket::SocketError::DatagramTooLargeError:
|
||||
errorString = QObject::tr("DatagramTooLargeError");
|
||||
|
@ -315,8 +328,10 @@ void jceSSLClient::showIfErrorMsg()
|
|||
*/
|
||||
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
|
||||
{
|
||||
qWarning() << "jceSSLClient::checkErrors; Var Error: " << a;
|
||||
qWarning() << "jceSSLClient::checkErrors; Error: " << this->errorString();
|
||||
qWarning() << Q_FUNC_INFO << "isOnline?: " << this->networkConf.isOnline();
|
||||
qWarning() << Q_FUNC_INFO << "state is: " << state();
|
||||
qWarning() << Q_FUNC_INFO << "Var Error: " << a;
|
||||
qWarning() << Q_FUNC_INFO << "Error: " << errorString();
|
||||
showIfErrorMsg();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
#include <QThread>
|
||||
#include <QEventLoop>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#define milisTimeOut 3500
|
||||
#define milisTimeOut 4000
|
||||
|
||||
class jceSSLClient : QSslSocket
|
||||
{
|
||||
|
@ -17,11 +16,11 @@ class jceSSLClient : QSslSocket
|
|||
public:
|
||||
jceSSLClient();
|
||||
|
||||
bool makeConnect(QString server, int port);
|
||||
bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443);
|
||||
bool makeDiconnect();
|
||||
bool isConnected();
|
||||
bool sendData(QString str);
|
||||
bool recieveData(QString &str, bool fast);
|
||||
bool makeDiconnect();
|
||||
void showIfErrorMsg();
|
||||
|
||||
private slots:
|
||||
|
@ -30,12 +29,14 @@ private slots:
|
|||
void setEncrypted();
|
||||
void setDisconnected();
|
||||
void readIt();
|
||||
void setOnlineState(bool isOnline);
|
||||
|
||||
private:
|
||||
|
||||
bool flag;
|
||||
QString packet;
|
||||
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)
|
||||
{
|
||||
std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
|
||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
|
||||
{
|
||||
if (!(JceConnector->recieveData(*recieverPage,false)))
|
||||
|
|
Loading…
Reference in a new issue