added progress bar

;
This commit is contained in:
liranbg 2014-10-04 03:47:14 +03:00
parent 26cbfbd576
commit 2ef44eff00
10 changed files with 558 additions and 457 deletions

View file

@ -1,19 +1,26 @@
#include "loginhandler.h" #include "loginhandler.h"
loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr): logggedInFlag(false) loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr,QProgressBar *progressbarPtr): logggedInFlag(false)
{ {
this->loginButtonPtr = loginButtonPtr; this->loginButtonPtr = loginButtonPtr;
this->progressBar = progressbarPtr;
//statusBar //statusBar
statusBar = statusBarPtr; statusBar = statusBarPtr;
iconButtomStatusLabel = new QLabel(); iconButtomStatusLabel = new QLabel(statusBarPtr);
iconButtomStatusLabel->setAlignment(Qt::AlignHCenter);
//display progressbar and then ball icon.
statusBar->addPermanentWidget(progressBar,0);
statusBar->addPermanentWidget(iconButtomStatusLabel,0); statusBar->addPermanentWidget(iconButtomStatusLabel,0);
setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
//user settings //user settings
userPtr = ptr; userPtr = ptr;
this->jceLog = new jceLogin(userPtr); this->jceLog = new jceLogin(userPtr,progressBar);
QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost())); QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost()));
} }
bool loginHandler::login(QString username,QString password) bool loginHandler::login(QString username,QString password)
{ {

View file

@ -7,6 +7,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPixmap> #include <QPixmap>
#include <QStatusBar> #include <QStatusBar>
#include <QProgressBar>
#include <QPushButton> #include <QPushButton>
#include "./src/jceSettings/jcelogin.h" #include "./src/jceSettings/jcelogin.h"
@ -17,7 +18,7 @@ class loginHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr); loginHandler(user *ptr, QStatusBar *statusBarPtr, QPushButton *loginButtonPtr, QProgressBar *progressbarPtr);
~loginHandler() ~loginHandler()
{ {
delete iconButtomStatusLabel; delete iconButtomStatusLabel;
@ -51,6 +52,7 @@ private:
QStatusBar *statusBar; QStatusBar *statusBar;
QLabel *iconButtomStatusLabel; QLabel *iconButtomStatusLabel;
QPushButton *loginButtonPtr; QPushButton *loginButtonPtr;
QProgressBar *progressBar;
}; };

View file

@ -9,13 +9,13 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef QT_DEBUG // Incase QtCreator is in Debug mode all qDebug messages will go to terminal #ifdef QT_DEBUG // Incase QtCreator is in Debug mode all qDebug messages will go to terminal
qDebug() << "Running a debug build"; qDebug() << Q_FUNC_INFO << "Running a debug build";
#else // If QtCreator is on Release mode , qDebug messages will be logged in a log file. #else // If QtCreator is on Release mode , qDebug messages will be logged in a log file.
// qDebug() << "Running a release build"; // qDebug() << "Running a release build";
qInstallMessageHandler(jce_logger::customMessageHandler); qInstallMessageHandler(jce_logger::customMessageHandler);
#endif #endif
qDebug() << "Start : JCE Manager Launched"; qDebug() << Q_FUNC_INFO << "Start : JCE Manager Launched";
QApplication a(argc, argv); QApplication a(argc, argv);
QTranslator translator; QTranslator translator;
@ -27,13 +27,13 @@ int main(int argc, char *argv[])
{ {
QString locale = QLocale::system().name(); QString locale = QLocale::system().name();
translator.load("jce_"+locale , a.applicationDirPath()); translator.load("jce_"+locale , a.applicationDirPath());
qDebug() << "Local : Default Local Loaded"; qDebug() << Q_FUNC_INFO << "Local : Default Local Loaded";
}else if(loco == "he"){ }else if(loco == "he"){
translator.load("jce_he" , a.applicationDirPath()); translator.load("jce_he" , a.applicationDirPath());
qDebug() << "Local : Hebrew Local Loaded"; qDebug() << Q_FUNC_INFO << "Local : Hebrew Local Loaded";
}else{ }else{
translator.load("jce_en" , a.applicationDirPath()); translator.load("jce_en" , a.applicationDirPath());
qDebug() << "Local : English Local Loaded"; qDebug() << Q_FUNC_INFO << "Local : English Local Loaded";
} }
a.installTranslator(&translator); //Setting local a.installTranslator(&translator); //Setting local
MainScreen w; MainScreen w;
@ -42,8 +42,8 @@ int main(int argc, char *argv[])
//Getting the exit code from QApplication. for debug reasons //Getting the exit code from QApplication. for debug reasons
int returnCode = a.exec(); int returnCode = a.exec();
if(returnCode == 0) if(returnCode == 0)
qDebug() << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode; qDebug() << Q_FUNC_INFO << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode;
else else
qCritical() << "End : JCE Manager Ended Unusccessfully With A Return Code: " << returnCode; qCritical() << Q_FUNC_INFO << "End : JCE Manager Ended Unusccessfully With A Return Code: " << returnCode;
return returnCode; return returnCode;
} }

View file

@ -2,361 +2,378 @@
#include "ui_mainscreen.h" #include "ui_mainscreen.h"
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen) MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen), busyFlag()
{ {
ui->setupUi(this); ui->setupUi(this);
//this->setFixedSize(this->size()); //main not resizeable
ui->labelMadeBy->setOpenExternalLinks(true); ui->labelMadeBy->setOpenExternalLinks(true);
//Login Tab //Login Tab
iconPix.load(":/icons/iconX.png"); iconPix.load(":/icons/iconX.png");
ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
ui->labelUsrInputStatus->setVisible(false); ui->labelUsrInputStatus->setVisible(false);
ui->labelPswInputStatus->setVisible(false); ui->labelPswInputStatus->setVisible(false);
ui->labelUsrInputStatus->setPixmap(iconPix); ui->labelUsrInputStatus->setPixmap(iconPix);
ui->labelPswInputStatus->setPixmap(iconPix); ui->labelPswInputStatus->setPixmap(iconPix);
//StatusBar
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ui->statusBar->setFixedHeight(STATUS_ICON_HEIGH);
ui->statusBar->showMessage(tr("Ready"));
//GPA Tab //StatusBar & progressbar
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); ui->progressBar->setFixedHeight(STATUS_ICON_HEIGH);
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ui->statusBar->setFixedHeight(STATUS_ICON_HEIGH+5);
ui->statusBar->showMessage(tr("Ready"));
//Pointer allocating //GPA Tab
qDebug() << Q_FUNC_INFO << "Allocating pointers"; ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton);
this->calendar = new CalendarManager(ui->calendarGridLayoutMain);
this->data = new SaveData();
//check login File //Pointer allocating
if (data->isSaved()) qDebug() << Q_FUNC_INFO << "Allocating pointers";
this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar);
this->calendar = new CalendarManager(ui->calendarGridLayoutMain);
this->data = new SaveData();
busyFlag = false;
//check login File
if (data->isSaved())
{ {
qDebug() << Q_FUNC_INFO << "Loading data from file"; qDebug() << Q_FUNC_INFO << "Loading data from file";
ui->usrnmLineEdit->setText(data->getUsername()); ui->usrnmLineEdit->setText(data->getUsername());
ui->pswdLineEdit->setText(data->getPassword()); ui->pswdLineEdit->setText(data->getPassword());
ui->keepLogin->setChecked(true); ui->keepLogin->setChecked(true);
} }
//language //language
qDebug() << Q_FUNC_INFO << "Checking locale"; qDebug() << Q_FUNC_INFO << "Checking locale";
checkLocale(); checkLocale();
qDebug() << Q_FUNC_INFO << "Ready."; ui->statusBar->repaint();
qDebug() << Q_FUNC_INFO << "Ready.";
} }
MainScreen::~MainScreen() MainScreen::~MainScreen()
{ {
delete calendar; delete calendar;
delete courseTableMgr; delete courseTableMgr;
delete userLoginSetting; delete userLoginSetting;
delete loginHandel; delete loginHandel;
delete data; delete data;
delete ui; delete ui;
} }
//EVENTS ON LOGIN TAB //EVENTS ON LOGIN TAB
void MainScreen::on_loginButton_clicked() void MainScreen::on_loginButton_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); ui->progressBar->setValue(0);
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
{ {
if (ui->usrnmLineEdit->text().isEmpty()) if (ui->usrnmLineEdit->text().isEmpty())
{ {
ui->labelUsrInputStatus->setVisible(true); ui->labelUsrInputStatus->setVisible(true);
qDebug() << Q_FUNC_INFO << "username input is empty"; qDebug() << Q_FUNC_INFO << "username input is empty";
} }
else else
ui->labelUsrInputStatus->setVisible(false);
if (ui->pswdLineEdit->text().isEmpty())
{
ui->labelPswInputStatus->setVisible(true);
qDebug() << Q_FUNC_INFO << "password input is empty";
}
else
ui->labelPswInputStatus->setVisible(false);
return;
}
else
{
ui->labelUsrInputStatus->setVisible(false); ui->labelUsrInputStatus->setVisible(false);
if (ui->pswdLineEdit->text().isEmpty())
{
ui->labelPswInputStatus->setVisible(true);
qDebug() << Q_FUNC_INFO << "password input is empty";
}
else
ui->labelPswInputStatus->setVisible(false); ui->labelPswInputStatus->setVisible(false);
return;
} }
else qDebug() << Q_FUNC_INFO << "login session start";
QApplication::setOverrideCursor(Qt::WaitCursor);
if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true)
{ {
ui->labelUsrInputStatus->setVisible(false); ui->progressBar->setValue(100);
ui->labelPswInputStatus->setVisible(false); qDebug() << Q_FUNC_INFO << "login session end with true";
} ui->pswdLineEdit->setDisabled(true);
qDebug() << Q_FUNC_INFO << "login session start"; ui->usrnmLineEdit->setDisabled(true);
QApplication::setOverrideCursor(Qt::WaitCursor); if (ui->keepLogin->isChecked())
if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true)
{
qDebug() << Q_FUNC_INFO << "login session end with true";
ui->pswdLineEdit->setDisabled(true);
ui->usrnmLineEdit->setDisabled(true);
if (ui->keepLogin->isChecked())
{ {
qDebug() << Q_FUNC_INFO << "saving data"; qDebug() << Q_FUNC_INFO << "saving data";
data->setUsername(ui->usrnmLineEdit->text()); data->setUsername(ui->usrnmLineEdit->text());
data->setPassword(ui->pswdLineEdit->text()); data->setPassword(ui->pswdLineEdit->text());
} }
} }
else else
{ {
qDebug() << Q_FUNC_INFO << "login session end with false"; qDebug() << Q_FUNC_INFO << "login session end with false";
ui->pswdLineEdit->setDisabled(false); ui->pswdLineEdit->setDisabled(false);
ui->usrnmLineEdit->setDisabled(false); ui->usrnmLineEdit->setDisabled(false);
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
void MainScreen::on_keepLogin_clicked() void MainScreen::on_keepLogin_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (ui->keepLogin->isChecked()) if (ui->keepLogin->isChecked())
{ {
qDebug() << Q_FUNC_INFO << "saving data"; qDebug() << Q_FUNC_INFO << "saving data";
data->setUsername(ui->usrnmLineEdit->text()); data->setUsername(ui->usrnmLineEdit->text());
data->setPassword(ui->pswdLineEdit->text()); data->setPassword(ui->pswdLineEdit->text());
} }
else else
data->reset(); data->reset();
} }
void MainScreen::on_usrnmLineEdit_editingFinished() void MainScreen::on_usrnmLineEdit_editingFinished()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
} }
//EVENTS ON GPA TAB //EVENTS ON GPA TAB
void MainScreen::on_ratesButton_clicked() void MainScreen::on_ratesButton_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); ui->progressBar->setValue(0);
if (!checkIfValidDates()) qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (!checkIfValidDates())
{ {
qWarning() << Q_FUNC_INFO << "Invalid dates! return"; qWarning() << Q_FUNC_INFO << "Invalid dates! return";
QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again")); QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again"));
return; return;
} }
QString pageString; QString pageString;
int status = 0; int status = 0;
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag() && !busyFlag)
{ {
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(), ui->statusBar->showMessage(tr("Getting grades..."));
ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(), if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),
ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_PAGE_PASSED) ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),
ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{ {
qDebug() << Q_FUNC_INFO << "grade page is ready"; qDebug() << Q_FUNC_INFO << "grade page is ready";
pageString = loginHandel->getCurrentPageContect(); ui->statusBar->showMessage(tr("Done. Inserting data into table..."),1000);
courseTableMgr->setCoursesList(pageString); pageString = loginHandel->getCurrentPageContect();
courseTableMgr->insertJceCoursesIntoTable(); courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable();
ui->progressBar->setValue(100);
ui->statusBar->showMessage(tr("Done"));
} }
else if (status == jceLogin::JCE_NOT_CONNECTED) else if (status == jceLogin::JCE_NOT_CONNECTED)
{ {
qWarning() << Q_FUNC_INFO << "not connected"; qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected")); QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
} }
else else
{ {
qCritical() << Q_FUNC_INFO << "grade get ended with" << status; qCritical() << Q_FUNC_INFO << "grade get ended with" << status;
} }
busyFlag = true;
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
bool MainScreen::checkIfValidDates() bool MainScreen::checkIfValidDates()
{ {
bool flag = false; bool flag = false;
if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value()) if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value())
{ {
//doesnt matter what is the semester, its valid! //doesnt matter what is the semester, its valid!
flag = true;
}
else if ((ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value()))
{
//semester from must be equal or less than to semester
if (ui->spinBoxCoursesFromSemester->value() <= ui->spinBoxCoursesToSemester->value())
flag = true; flag = true;
} }
return flag; else if ((ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value()))
{
//semester from must be equal or less than to semester
if (ui->spinBoxCoursesFromSemester->value() <= ui->spinBoxCoursesToSemester->value())
flag = true;
}
return flag;
} }
void MainScreen::on_checkBoxCoursesInfluence_toggled(bool checked) void MainScreen::on_checkBoxCoursesInfluence_toggled(bool checked)
{ {
qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked; qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked;
this->userLoginSetting->setInfluenceCourseOnly(checked); this->userLoginSetting->setInfluenceCourseOnly(checked);
this->courseTableMgr->influnceCourseChanged(checked); this->courseTableMgr->influnceCourseChanged(checked);
} }
void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1)
{ {
ui->spinBoxCoursesFromYear->setValue(arg1); ui->spinBoxCoursesFromYear->setValue(arg1);
} }
void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1)
{ {
ui->spinBoxCoursesToYear->setValue(arg1); ui->spinBoxCoursesToYear->setValue(arg1);
} }
void MainScreen::on_spinBoxCoursesFromSemester_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesFromSemester_valueChanged(int arg1)
{ {
ui->spinBoxCoursesFromSemester->setValue(arg1%4); ui->spinBoxCoursesFromSemester->setValue(arg1%4);
} }
void MainScreen::on_spinBoxCoursesToSemester_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesToSemester_valueChanged(int arg1)
{ {
ui->spinBoxCoursesToSemester->setValue(arg1%4); ui->spinBoxCoursesToSemester->setValue(arg1%4);
} }
void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
{ {
if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) if (this->courseTableMgr->changes(item->text(),item->row(),item->column()))
ui->avgLCD->display(courseTableMgr->getAvg()); ui->avgLCD->display(courseTableMgr->getAvg());
else else
{ {
qWarning() << Q_FUNC_INFO << "missmatch data"; qWarning() << Q_FUNC_INFO << "missmatch data";
QMessageBox::critical(this,tr("Error"),tr("Missmatching data")); QMessageBox::critical(this,tr("Error"),tr("Missmatching data"));
} }
} }
void MainScreen::on_clearTableButton_clicked() void MainScreen::on_clearTableButton_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
courseTableMgr->clearTable(); courseTableMgr->clearTable();
ui->avgLCD->display(courseTableMgr->getAvg()); ui->avgLCD->display(courseTableMgr->getAvg());
} }
//EVENTS ON CALENDAR TAB //EVENTS ON CALENDAR TAB
void MainScreen::on_getCalendarBtn_clicked() void MainScreen::on_getCalendarBtn_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); ui->progressBar->setValue(0);
int status = 0; qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
QApplication::setOverrideCursor(Qt::WaitCursor); int status = 0;
if (loginHandel->isLoggedInFlag()) QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag())
{ {
if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED) ui->statusBar->showMessage(tr("Getting schedule..."));
if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{ {
//Use it for debug. add plain text and change the object name to 'plainTextEdit' so you will get the html request
//ui->plainTextEdit->setPlainText(loginHandel->getCurrentPageContect()); //Use it for debug. add plain text and change the object name to 'plainTextEdit' so you will get the html request
calendar->resetTable(); //ui->plainTextEdit->setPlainText(loginHandel->getCurrentPageContect());
calendar->setCalendar(loginHandel->getCurrentPageContect()); calendar->resetTable();
qDebug() << Q_FUNC_INFO << "calendar is loaded"; ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
calendar->setCalendar(loginHandel->getCurrentPageContect());
ui->progressBar->setValue(100);
qDebug() << Q_FUNC_INFO << "calendar is loaded";
ui->statusBar->showMessage(tr("Done"));
} }
else if (status == jceLogin::JCE_NOT_CONNECTED) else if (status == jceLogin::JCE_NOT_CONNECTED)
{ {
qWarning() << Q_FUNC_INFO << "not connected"; qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected")); QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
} }
else else
qCritical() << Q_FUNC_INFO << "calendar get ended with" << status; qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
void MainScreen::on_exportToCVSBtn_clicked() void MainScreen::on_exportToCVSBtn_clicked()
{ {
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
this->calendar->exportCalendarCSV(); this->calendar->exportCalendarCSV();
} }
} }
//EVENTS ON MENU BAR //EVENTS ON MENU BAR
void MainScreen::on_actionCredits_triggered() void MainScreen::on_actionCredits_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QMessageBox::about(this, "About", QMessageBox::about(this, "About",
"<a href='http://liranbg.github.io/JceManager/'>Jce Manager</a> v1.0.0<br><br>" "<a href='http://liranbg.github.io/JceManager/'>Jce Manager</a> v1.0.0<br><br>"
+tr("License:")+ +tr("License:")+
"<br>GNU LESSER GENERAL PUBLIC LICENSE V2.1<br>" "<br>GNU LESSER GENERAL PUBLIC LICENSE V2.1<br>"
+"<br>"+ +"<br>"+
"<a href='https://github.com/liranbg/JceManager'>JceManager Repository</a>"+ "<a href='https://github.com/liranbg/JceManager'>JceManager Repository</a>"+
"<br><br>" "<br><br>"
+tr("Powered By: ")+ +tr("Powered By: ")+
"<a href='https://github.com/liranbg/jceConnection'> Jce Connection</a><br><br>" "<a href='https://github.com/liranbg/jceConnection'> Jce Connection</a><br><br>"
+tr("Developed By")+ +tr("Developed By")+
":<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></ul>" "<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li></ul>"
); );
} }
void MainScreen::on_actionExit_triggered() void MainScreen::on_actionExit_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
exit(0); exit(0);
} }
void MainScreen::on_actionHow_To_triggered() void MainScreen::on_actionHow_To_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QMessageBox::information(this,"How To", QMessageBox::information(this,"How To",
"<b>" "<b>"
+tr("Help Guide")+ +tr("Help Guide")+
"</b><ul>" "</b><ul>"
+tr("<br><li>Login: <ul><li>Type your username and password and click Login.</li><li>Once you are connected, you will see a green ball in the right buttom panel.</li></ul></li>") +tr("<br><li>Login: <ul><li>Type your username and password and click Login.</li><li>Once you are connected, you will see a green ball in the right buttom panel.</li></ul></li>")
+tr("<br><li>Getting GPA sheet<ul><li>Click on GPA Tab</li><li> Select your dates and click on Add</li></ul></li>") +tr("<br><li>Getting GPA sheet<ul><li>Click on GPA Tab</li><li> Select your dates and click on Add</li></ul></li>")
+tr("<br><li>Average Changing<ul><li>Change one of your grade and see the average in the buttom panel changing.</li></ul></li>") +tr("<br><li>Average Changing<ul><li>Change one of your grade and see the average in the buttom panel changing.</li></ul></li>")
+tr("<br><li>Getting Calendar<ul><li>Click on Calendar Tab</li><li> Select your dates and click on Get Calendar</li></ul></li>") +tr("<br><li>Getting Calendar<ul><li>Click on Calendar Tab</li><li> Select your dates and click on Get Calendar</li></ul></li>")
+tr("<br><li>For exporting your calendar to a .CSV file:<ul><li>Do previous step and continue to next step</li><li> Click on Export to CSV</li><li>Select your dates and click OK</li><li>Once you're Done, go on your calendar and import your csv file</li></li>")+ +tr("<br><li>For exporting your calendar to a .CSV file:<ul><li>Do previous step and continue to next step</li><li> Click on Export to CSV</li><li>Select your dates and click OK</li><li>Once you're Done, go on your calendar and import your csv file</li></li>")+
"<br><br>" "<br><br>"
+tr("<b>For more information, please visit us at: <a href='http://liranbg.github.io/JceManager/'>Jce Manager site</a></b>")); +tr("<b>For more information, please visit us at: <a href='http://liranbg.github.io/JceManager/'>Jce Manager site</a></b>"));
} }
void MainScreen::on_actionHebrew_triggered() void MainScreen::on_actionHebrew_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked()) if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked())
{ {
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
qDebug() << Q_FUNC_INFO << "Changed Language to hebrew"; qDebug() << Q_FUNC_INFO << "Changed Language to hebrew";
data->setLocal("he"); data->setLocal("he");
QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok);
} }
else else
ui->actionHebrew->setChecked(true); ui->actionHebrew->setChecked(true);
} }
void MainScreen::on_actionEnglish_triggered() void MainScreen::on_actionEnglish_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked()) if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked())
{ {
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
qDebug() << Q_FUNC_INFO << "Changed Language to English"; qDebug() << Q_FUNC_INFO << "Changed Language to English";
data->setLocal("en"); data->setLocal("en");
QMessageBox::information(this,"Settings",tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); QMessageBox::information(this,"Settings",tr("Your settings will take effect next time you start the program"),QMessageBox::Ok);
} }
else else
ui->actionEnglish->setChecked(true); ui->actionEnglish->setChecked(true);
} }
void MainScreen::on_actionOS_Default_triggered() void MainScreen::on_actionOS_Default_triggered()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked()) if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked())
{ {
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
qDebug() << Q_FUNC_INFO << "Changed Language to OS Default"; qDebug() << Q_FUNC_INFO << "Changed Language to OS Default";
data->setLocal("default"); data->setLocal("default");
QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok);
} }
else else
ui->actionOS_Default->setChecked(true); ui->actionOS_Default->setChecked(true);
} }
void MainScreen::checkLocale() void MainScreen::checkLocale()
{ {
if(data->getLocal() == "en") if(data->getLocal() == "en")
{ {
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
ui->actionEnglish->setChecked(true); ui->actionEnglish->setChecked(true);
}else if(data->getLocal() == "he"){ }else if(data->getLocal() == "he"){
ui->actionHebrew->setChecked(true); ui->actionHebrew->setChecked(true);
ui->actionOS_Default->setChecked(false); ui->actionOS_Default->setChecked(false);
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
}else{ }else{
ui->actionHebrew->setChecked(false); ui->actionHebrew->setChecked(false);
ui->actionOS_Default->setChecked(true); ui->actionOS_Default->setChecked(true);
ui->actionEnglish->setChecked(false); ui->actionEnglish->setChecked(false);
} }
} }
void MainScreen::on_labelMadeBy_linkActivated(const QString &link) void MainScreen::on_labelMadeBy_linkActivated(const QString &link)
{ {
qDebug() << Q_FUNC_INFO << "link: " << link; qDebug() << Q_FUNC_INFO << "link: " << link;
} }

View file

@ -83,6 +83,8 @@ private:
coursesTableManager *courseTableMgr; coursesTableManager *courseTableMgr;
loginHandler *loginHandel; loginHandler *loginHandel;
bool busyFlag;
}; };
#endif // MAINSCREEN_H #endif // MAINSCREEN_H

View file

@ -626,6 +626,45 @@ font-size: 15px;
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">#progressBar::horizontal {
border: 1px solid gray;
border-radius: 3px;
background: white;
padding: 1px;
}
#progressBar::chunk:horizontal {
background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 green, stop: 1 white);
}</string>
</property>
<property name="value">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="textDirection">
<enum>QProgressBar::TopToBottom</enum>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="labelMadeBy"> <widget class="QLabel" name="labelMadeBy">
<property name="text"> <property name="text">

View file

@ -3,17 +3,19 @@
/** /**
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals * @brief jceSSLClient::jceSSLClient Constructer, setting the signals
*/ */
jceSSLClient::jceSSLClient() : flag(false), packet(""),networkConf(), reConnection(false) jceSSLClient::jceSSLClient(QProgressBar *progressbarPtr) : flag(false), packet(""),networkConf(), reConnection(false)
{ {
//setting signals this->progressBar = progressbarPtr;
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError))); //setting signals
connect(this,SIGNAL(connected()),this,SLOT(setConnected())); connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted())); connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected())); connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
connect(&networkConf,SIGNAL(onlineStateChanged(bool)),this,SLOT(setOnlineState(bool))); connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
//loop event will connect the server, and when it is connected, it will quit - but connection will be open connect(&networkConf,SIGNAL(onlineStateChanged(bool)),this,SLOT(setOnlineState(bool)));
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
connect(this, SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit())); //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()));
} }
/** /**
@ -24,48 +26,48 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""),networkConf(), reConnecti
*/ */
bool jceSSLClient::makeConnect(QString server, int port) bool jceSSLClient::makeConnect(QString server, int port)
{ {
if (this->supportsSsl() == false) if (this->supportsSsl() == false)
{ {
qCritical() << Q_FUNC_INFO << "Couldnt load ssl package. ERROR"; qCritical() << Q_FUNC_INFO << "Couldnt load ssl package. ERROR";
return false; return false;
} }
else else
qDebug() << Q_FUNC_INFO << "ssl loaded."; qDebug() << Q_FUNC_INFO << "ssl loaded.";
if (isConnectedToNetwork() == false) if (isConnectedToNetwork() == false)
{ {
qDebug() << Q_FUNC_INFO << "return false. not online"; qDebug() << Q_FUNC_INFO << "return false. not online";
return false; return false;
} }
else else
qDebug() << Q_FUNC_INFO << "we're online"; qDebug() << Q_FUNC_INFO << "we're online";
if (reConnection) //reset reconnectiong flag if (reConnection) //reset reconnectiong flag
{ {
qDebug() << Q_FUNC_INFO << "Making Reconnection"; qDebug() << Q_FUNC_INFO << "Making Reconnection";
} }
else else
qDebug() << Q_FUNC_INFO << "Making Connection"; qDebug() << Q_FUNC_INFO << "Making Connection";
if (isConnected()) if (isConnected())
{ {
qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()"; qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()";
makeDiconnect(); makeDiconnect();
} }
qDebug() << Q_FUNC_INFO << "Connection to: " << server << "On Port: " << port; qDebug() << Q_FUNC_INFO << "Connection to: " << server << "On Port: " << port;
connectToHostEncrypted(server.toStdString().c_str(), port); connectToHostEncrypted(server.toStdString().c_str(), port);
loop.exec(); //starting connection, waiting to encryption and then it ends loop.exec(); //starting connection, waiting to encryption and then it ends
qDebug() << Q_FUNC_INFO << "returning the connection status: " << isConnected(); qDebug() << Q_FUNC_INFO << "returning the connection status: " << isConnected();
if (reConnection) if (reConnection)
{ {
reConnection = false; reConnection = false;
emit serverDisconnectedbyRemote(); emit serverDisconnectedbyRemote();
} }
return isConnected(); return isConnected();
} }
/** /**
@ -74,15 +76,15 @@ bool jceSSLClient::makeConnect(QString server, int port)
*/ */
bool jceSSLClient::makeDiconnect() bool jceSSLClient::makeDiconnect()
{ {
if (loop.isRunning()) if (loop.isRunning())
{ {
qWarning() << Q_FUNC_INFO << "Killing connection thread"; qWarning() << Q_FUNC_INFO << "Killing connection thread";
loop.exit(); loop.exit();
} }
qDebug() << Q_FUNC_INFO << "disconnecting from host and emitting disconnected()"; qDebug() << Q_FUNC_INFO << "disconnecting from host and emitting disconnected()";
this->disconnectFromHost(); //emits disconnected > setDisconnected this->disconnectFromHost(); //emits disconnected > setDisconnected
setSocketState(QAbstractSocket::SocketState::UnconnectedState); setSocketState(QAbstractSocket::SocketState::UnconnectedState);
return (!isConnected()); return (!isConnected());
} }
@ -92,30 +94,30 @@ bool jceSSLClient::makeDiconnect()
*/ */
bool jceSSLClient::isConnected() bool jceSSLClient::isConnected()
{ {
bool tempFlag = false; bool tempFlag = false;
//checking state before returning flag! //checking state before returning flag!
if (state() == QAbstractSocket::SocketState::UnconnectedState) if (state() == QAbstractSocket::SocketState::UnconnectedState)
{ {
tempFlag = false; tempFlag = false;
} }
else if (state() == QAbstractSocket::SocketState::ClosingState) else if (state() == QAbstractSocket::SocketState::ClosingState)
{ {
tempFlag = false; tempFlag = false;
} }
else if (state() == QAbstractSocket::SocketState::ConnectedState) else if (state() == QAbstractSocket::SocketState::ConnectedState)
{ {
if (isConnectedToNetwork()) if (isConnectedToNetwork())
tempFlag = true; tempFlag = true;
else else
{ {
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
tempFlag = false; tempFlag = false;
} }
} }
if (!isConnectedToNetwork()) //no link, ethernet\wifi if (!isConnectedToNetwork()) //no link, ethernet\wifi
tempFlag = false; tempFlag = false;
return ((flag) && (tempFlag)); return ((flag) && (tempFlag));
} }
/** /**
* @brief jceSSLClient::sendData - given string, send it to server * @brief jceSSLClient::sendData - given string, send it to server
@ -124,16 +126,16 @@ bool jceSSLClient::isConnected()
*/ */
bool jceSSLClient::sendData(QString str) bool jceSSLClient::sendData(QString str)
{ {
bool sendDataFlag = false; bool sendDataFlag = false;
if (isConnected()) //if connected if (isConnected()) //if connected
{ {
write(str.toStdString().c_str(),str.length()); write(str.toStdString().c_str(),str.length());
if (waitForBytesWritten()) if (waitForBytesWritten())
sendDataFlag = true; sendDataFlag = true;
} }
qDebug() << Q_FUNC_INFO << "Sending Data status is: " << sendDataFlag; qDebug() << Q_FUNC_INFO << "Sending Data status is: " << sendDataFlag;
return sendDataFlag; return sendDataFlag;
} }
/** /**
* @brief jceSSLClient::recieveData * @brief jceSSLClient::recieveData
@ -143,39 +145,41 @@ bool jceSSLClient::sendData(QString str)
*/ */
bool jceSSLClient::recieveData(QString &str, bool fast) bool jceSSLClient::recieveData(QString &str, bool fast)
{ {
qDebug() << Q_FUNC_INFO << "Data receiving!"; qDebug() << Q_FUNC_INFO << "Data receiving!";
packet = ""; packet = "";
bool sflag = false; bool sflag = false;
if (fast) //fast mode connection, good only for login step!!!! if (fast) //fast mode connection, good only for login step!!!!
{ {
qDebug() << "jceSSLClient::recieveData login step receiving"; qDebug() << Q_FUNC_INFO << "login step receiving";
QEventLoop loop; //loop will exit after first read packet.
connect(this, SIGNAL(readyRead()), &loop, SLOT(quit())); //meanwhile packet will gain data. good for small amount of data - fast connection!
connect(this, SIGNAL(readyRead()), this, SLOT(readIt())); connect(this, SIGNAL(readyRead()), &readerLoop, SLOT(quit()));
loop.exec(); connect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
disconnect(this, SIGNAL(readyRead()), &loop, SLOT(quit())); readerLoop.exec();
disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt())); disconnect(this, SIGNAL(readyRead()), &readerLoop, SLOT(quit()));
disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
} }
else else
{ {
qDebug() << "jceSSLClient::recieveData normal receiving"; qDebug() << Q_FUNC_INFO << "normal receiving";
QString p; //loop will exit after timeout \ full data
while (waitForReadyRead(milisTimeOut)) connect(this, SIGNAL(packetHasData()), &readerLoop, SLOT(quit()));
{
do timer.setSingleShot(true);
{ connect(&timer, SIGNAL(timeout()), &readerLoop, SLOT(quit()));
p = readAll(); connect(this, SIGNAL(readyRead()), this, SLOT(readItAll()));
packet.append(p); timer.start(5000);
}while (p.size() > 0); readerLoop.exec();
}
} }
str = packet; str = packet;
qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ; qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ;
if (str.length() > 0) if (str.length() > 0)
sflag = true; sflag = true;
qDebug() << Q_FUNC_INFO << "return with flag: " << sflag; qDebug() << Q_FUNC_INFO << "return with flag: " << sflag;
return sflag; disconnect(this, SIGNAL(readyRead()), this, SLOT(readItAll()));
return sflag;
} }
/** /**
@ -183,29 +187,47 @@ bool jceSSLClient::recieveData(QString &str, bool fast)
*/ */
void jceSSLClient::readIt() void jceSSLClient::readIt()
{ {
QString p; QString p;
do do
{ {
p = readAll(); p = readAll();
packet.append(p); packet.append(p);
this->progressBar->setValue(this->progressBar->value() + 6);
}while (p.size() > 0); }while (p.size() > 0);
} }
void jceSSLClient::readItAll()
{
QString p;
do
{
p = "";
p = read(bytesAvailable());
if (p.contains("</tbody>") == true)
{
qDebug() << "we have the end!";
timer.setInterval(1000);
}
this->progressBar->setValue(this->progressBar->value() + 6);
// qDebug() << "p lenght" << p.length();
packet.append(p);
}while (p.size() > 0);
}
void jceSSLClient::setOnlineState(bool isOnline) void jceSSLClient::setOnlineState(bool isOnline)
{ {
qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline; qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline;
if (isOnline) //to be added later if (isOnline) //to be added later
{ {
qDebug() << Q_FUNC_INFO << "Online Statue has been changed. we are online"; qDebug() << Q_FUNC_INFO << "Online Statue has been changed. we are online";
//we can add here auto reconnect if wifi\ethernet link has appear //we can add here auto reconnect if wifi\ethernet link has appear
//will be added next version //will be added next version
} }
else else
{ {
qWarning() << Q_FUNC_INFO << "Online State has been changed. emitting NoInternetLink"; qWarning() << Q_FUNC_INFO << "Online State has been changed. emitting NoInternetLink";
this->makeDiconnect(); this->makeDiconnect();
emit noInternetLink(); emit noInternetLink();
} }
} }
@ -214,19 +236,19 @@ void jceSSLClient::setOnlineState(bool isOnline)
*/ */
void jceSSLClient::setConnected() void jceSSLClient::setConnected()
{ {
waitForEncrypted(); waitForEncrypted();
} }
/** /**
* @brief jceSSLClient::setDisconnected closing socket, updating state and 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 << "connection has been DISCONNECTED"; qDebug() << Q_FUNC_INFO << "connection has been DISCONNECTED";
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
packet.clear(); packet.clear();
flag = false; flag = false;
if (reConnection) if (reConnection)
makeConnect(); makeConnect();
} }
@ -235,14 +257,14 @@ void jceSSLClient::setDisconnected()
*/ */
void jceSSLClient::setEncrypted() void jceSSLClient::setEncrypted()
{ {
qDebug() << Q_FUNC_INFO << "connection has been ENCRYPTED"; qDebug() << Q_FUNC_INFO << "connection has been ENCRYPTED";
setReadBufferSize(10000); setReadBufferSize(10000);
setSocketOption(QAbstractSocket::KeepAliveOption,true); setSocketOption(QAbstractSocket::KeepAliveOption,true);
flag = true; flag = true;
if (!isConnected()) if (!isConnected())
{ {
qWarning() << Q_FUNC_INFO << "Connection status didnt change! reseting flag to false"; qWarning() << Q_FUNC_INFO << "Connection status didnt change! reseting flag to false";
flag = false; flag = false;
} }
} }
@ -253,116 +275,116 @@ void jceSSLClient::setEncrypted()
*/ */
void jceSSLClient::showIfErrorMsg() void jceSSLClient::showIfErrorMsg()
{ {
QMessageBox msgBox; QMessageBox msgBox;
SocketError enumError = error(); SocketError enumError = error();
QString errorString; QString errorString;
bool relevantError = false; bool relevantError = false;
switch (enumError) switch (enumError)
{ {
case QAbstractSocket::SocketError::ConnectionRefusedError: /**/ case QAbstractSocket::SocketError::ConnectionRefusedError: /**/
errorString = QObject::tr("ConnectionRefusedError"); errorString = QObject::tr("ConnectionRefusedError");
//The connection was refused by the peer (or timed out). //The connection was refused by the peer (or timed out).
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::RemoteHostClosedError: /**/ case QAbstractSocket::SocketError::RemoteHostClosedError: /**/
errorString = QObject::tr("RemoteHostClosedError"); errorString = QObject::tr("RemoteHostClosedError");
//The remote host closed the connection //The remote host closed the connection
if (isConnectedToNetwork()) //we can reconnect if (isConnectedToNetwork()) //we can reconnect
{ {
reConnection = true; reConnection = true;
} }
else else
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::HostNotFoundError: /**/ case QAbstractSocket::SocketError::HostNotFoundError: /**/
errorString = QObject::tr("HostNotFoundError"); errorString = QObject::tr("HostNotFoundError");
//The host address was not found. //The host address was not found.
relevantError = true;
break;
case QAbstractSocket::SocketError::SocketAccessError: /**/
errorString = QObject::tr("SocketAccessError");
//The socket operation failed because the application lacked the required privileges.
break;
case QAbstractSocket::SocketError::SocketTimeoutError: /**/
errorString = QObject::tr("SocketTimeoutError");
//The socket operation timed out.
if (isConnected()); //ignore it if connected.
else
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::SocketAccessError: /**/
errorString = QObject::tr("SocketAccessError");
//The socket operation failed because the application lacked the required privileges.
break;
case QAbstractSocket::SocketError::SocketTimeoutError: /**/
errorString = QObject::tr("SocketTimeoutError");
//The socket operation timed out.
if (isConnected()); //ignore it if connected.
else
relevantError = true;
break;
case QAbstractSocket::SocketError::NetworkError: /**/ case QAbstractSocket::SocketError::NetworkError: /**/
errorString = QObject::tr("NetworkError"); errorString = QObject::tr("NetworkError");
//An error occurred with the network (e.g., the network cable was accidentally plugged out). //An error occurred with the network (e.g., the network cable was accidentally plugged out).
if (isConnectedToNetwork()) //we can reconnect if (isConnectedToNetwork()) //we can reconnect
{ {
} }
else else
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::SslHandshakeFailedError: /**/ case QAbstractSocket::SocketError::SslHandshakeFailedError: /**/
errorString = QObject::tr("SslHandshakeFailedError"); errorString = QObject::tr("SslHandshakeFailedError");
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::SslInternalError: /**/ case QAbstractSocket::SocketError::SslInternalError: /**/
errorString = QObject::tr("SslInternalError"); errorString = QObject::tr("SslInternalError");
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::SslInvalidUserDataError: /**/ case QAbstractSocket::SocketError::SslInvalidUserDataError: /**/
errorString = QObject::tr("SslInvalidUserDataError"); errorString = QObject::tr("SslInvalidUserDataError");
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::DatagramTooLargeError: //not relevant to us case QAbstractSocket::SocketError::DatagramTooLargeError: //not relevant to us
errorString = QObject::tr("DatagramTooLargeError"); errorString = QObject::tr("DatagramTooLargeError");
break; break;
case QAbstractSocket::SocketError::SocketResourceError: //not relevant to us case QAbstractSocket::SocketError::SocketResourceError: //not relevant to us
break; break;
case QAbstractSocket::SocketError::OperationError: //not relevant, except for debug case QAbstractSocket::SocketError::OperationError: //not relevant, except for debug
errorString = QObject::tr("OperationError"); errorString = QObject::tr("OperationError");
break; break;
case QAbstractSocket::SocketError::AddressInUseError: //not relevant to us case QAbstractSocket::SocketError::AddressInUseError: //not relevant to us
errorString = QObject::tr("AddressInUseError"); errorString = QObject::tr("AddressInUseError");
break; break;
case QAbstractSocket::SocketError::SocketAddressNotAvailableError: //not relevant to us case QAbstractSocket::SocketError::SocketAddressNotAvailableError: //not relevant to us
errorString = QObject::tr("SocketAddressNotAvailableError"); errorString = QObject::tr("SocketAddressNotAvailableError");
break; break;
case QAbstractSocket::SocketError::UnsupportedSocketOperationError: //for very old computers, not relevant to us case QAbstractSocket::SocketError::UnsupportedSocketOperationError: //for very old computers, not relevant to us
errorString = QObject::tr("UnsupportedSocketOperationError"); errorString = QObject::tr("UnsupportedSocketOperationError");
break; break;
case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError: //not relevant to us case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError: //not relevant to us
errorString = QObject::tr("ProxyAuthenticationRequiredError"); errorString = QObject::tr("ProxyAuthenticationRequiredError");
break; break;
case QAbstractSocket::SocketError::ProxyConnectionRefusedError: //not relevant to us case QAbstractSocket::SocketError::ProxyConnectionRefusedError: //not relevant to us
errorString = QObject::tr("ProxyConnectionRefusedError"); errorString = QObject::tr("ProxyConnectionRefusedError");
break; break;
case QAbstractSocket::SocketError::UnfinishedSocketOperationError: //not relevant to us case QAbstractSocket::SocketError::UnfinishedSocketOperationError: //not relevant to us
errorString = QObject::tr("UnfinishedSocketOperationError"); errorString = QObject::tr("UnfinishedSocketOperationError");
break; break;
case QAbstractSocket::SocketError::ProxyConnectionClosedError: //not relevant to us case QAbstractSocket::SocketError::ProxyConnectionClosedError: //not relevant to us
errorString = QObject::tr("ProxyConnectionClosedError"); errorString = QObject::tr("ProxyConnectionClosedError");
break; break;
case QAbstractSocket::SocketError::ProxyConnectionTimeoutError: //not relevant to us case QAbstractSocket::SocketError::ProxyConnectionTimeoutError: //not relevant to us
errorString = QObject::tr("ProxyConnectionTimeoutError"); errorString = QObject::tr("ProxyConnectionTimeoutError");
break; break;
case QAbstractSocket::SocketError::ProxyNotFoundError: //not relevant to us case QAbstractSocket::SocketError::ProxyNotFoundError: //not relevant to us
errorString = QObject::tr("ProxyNotFoundError"); errorString = QObject::tr("ProxyNotFoundError");
break; break;
case QAbstractSocket::SocketError::ProxyProtocolError: //not relevant to us case QAbstractSocket::SocketError::ProxyProtocolError: //not relevant to us
errorString = QObject::tr("ProxyProtocolError"); errorString = QObject::tr("ProxyProtocolError");
break; break;
case QAbstractSocket::SocketError::TemporaryError: //not relevant to us case QAbstractSocket::SocketError::TemporaryError: //not relevant to us
errorString = QObject::tr("TemporaryError"); errorString = QObject::tr("TemporaryError");
break; break;
case QAbstractSocket::SocketError::UnknownSocketError: //not relevant, except for debug case QAbstractSocket::SocketError::UnknownSocketError: //not relevant, except for debug
errorString = QObject::tr("UnknownSocketError"); errorString = QObject::tr("UnknownSocketError");
relevantError = true; relevantError = true;
break; break;
} }
if (relevantError) //informative string to be shown if (relevantError) //informative string to be shown
{ {
qDebug() << Q_FUNC_INFO << "relevant error."; qDebug() << Q_FUNC_INFO << "relevant error.";
msgBox.setIcon(QMessageBox::Warning); msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(errorString); msgBox.setText(errorString);
msgBox.exec(); msgBox.exec();
} }
} }
/** /**
@ -371,24 +393,24 @@ void jceSSLClient::showIfErrorMsg()
*/ */
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a) void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
{ {
//ignore this stupid error //ignore this stupid error
bool timeout = (a == QAbstractSocket::SocketError::SocketTimeoutError); bool timeout = (a == QAbstractSocket::SocketError::SocketTimeoutError);
if (!((isConnected()) && (timeout))) if (!((isConnected()) && (timeout)))
{ {
qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork(); qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork();
qWarning() << Q_FUNC_INFO << "state is: " << state(); qWarning() << Q_FUNC_INFO << "state is: " << state();
qWarning() << Q_FUNC_INFO << "Var Error: " << a; qWarning() << Q_FUNC_INFO << "Var Error: " << a;
qWarning() << Q_FUNC_INFO << "Error: " << errorString(); qWarning() << Q_FUNC_INFO << "Error: " << errorString();
} }
else else
{ {
qDebug() << Q_FUNC_INFO << "isConnected?: " << isConnected() << "is timeout?" << timeout; qDebug() << Q_FUNC_INFO << "isConnected?: " << isConnected() << "is timeout?" << timeout;
qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork(); qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork();
qWarning() << Q_FUNC_INFO << "state is: " << state(); qWarning() << Q_FUNC_INFO << "state is: " << state();
qWarning() << Q_FUNC_INFO << "Var Error: " << a; qWarning() << Q_FUNC_INFO << "Var Error: " << a;
qWarning() << Q_FUNC_INFO << "Error: " << errorString(); qWarning() << Q_FUNC_INFO << "Error: " << errorString();
} }
showIfErrorMsg(); showIfErrorMsg();
} }
/** written by KARAN BALKAR /** written by KARAN BALKAR
@ -397,20 +419,20 @@ void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
*/ */
bool jceSSLClient::isConnectedToNetwork(){ bool jceSSLClient::isConnectedToNetwork(){
QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces(); QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
bool result = false; bool result = false;
for (int i = 0; i < ifaces.count(); ++i) for (int i = 0; i < ifaces.count(); ++i)
{ {
QNetworkInterface iface = ifaces.at(i); QNetworkInterface iface = ifaces.at(i);
if ( iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) if ( iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
for (int j=0; j < iface.addressEntries().count(); ++j) for (int j=0; j < iface.addressEntries().count(); ++j)
// got an interface which is up, and has an ip address // got an interface which is up, and has an ip address
if (result == false) if (result == false)
result = true; result = true;
} }
return result; return result;
} }

View file

@ -8,6 +8,8 @@
#include <QMessageBox> #include <QMessageBox>
#include <QNetworkConfigurationManager> #include <QNetworkConfigurationManager>
#include <QtNetwork/QNetworkInterface> #include <QtNetwork/QNetworkInterface>
#include <QTimer>
#include <QProgressBar>
#define milisTimeOut 4000 #define milisTimeOut 4000
@ -15,7 +17,7 @@ class jceSSLClient : public QSslSocket
{ {
Q_OBJECT Q_OBJECT
public: public:
jceSSLClient(); jceSSLClient(QProgressBar *progressbarPtr);
bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443); bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443);
bool makeDiconnect(); bool makeDiconnect();
@ -28,6 +30,7 @@ signals:
void serverDisconnectedbyRemote(); void serverDisconnectedbyRemote();
void noInternetLink(); void noInternetLink();
void socketDisconnected(); void socketDisconnected();
void packetHasData();
private slots: private slots:
void checkErrors(QAbstractSocket::SocketError a); void checkErrors(QAbstractSocket::SocketError a);
@ -35,6 +38,7 @@ private slots:
void setEncrypted(); void setEncrypted();
void setDisconnected(); void setDisconnected();
void readIt(); void readIt();
void readItAll();
void setOnlineState(bool isOnline); void setOnlineState(bool isOnline);
private: private:
@ -42,9 +46,13 @@ private:
bool flag; bool flag;
QString packet; QString packet;
QEventLoop loop; //handle the connection as thread QEventLoop loop; //handle the connection as thread
QEventLoop readerLoop;
QTimer timer;
QNetworkConfigurationManager networkConf; //checking if online QNetworkConfigurationManager networkConf; //checking if online
bool reConnection; //used for remote host disconnecting bool reConnection; //used for remote host disconnecting
QProgressBar *progressBar; //
}; };
#endif // JCESSLCLIENT_H #endif // JCESSLCLIENT_H

View file

@ -4,11 +4,12 @@
* @brief jceLogin::jceLogin * @brief jceLogin::jceLogin
* @param username pointer to allocated user settings * @param username pointer to allocated user settings
*/ */
jceLogin::jceLogin(user* username) jceLogin::jceLogin(user* username, QProgressBar *progressbarPtr)
{ {
this->progressBar = progressbarPtr;
this->recieverPage = new QString(); this->recieverPage = new QString();
this->jceA = username; this->jceA = username;
this->JceConnector = new jceSSLClient(); this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection())); QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
} }
@ -133,7 +134,7 @@ void jceLogin::reMakeConnection()
recieverPage = NULL; recieverPage = NULL;
JceConnector = NULL; JceConnector = NULL;
this->recieverPage = new QString(); this->recieverPage = new QString();
this->JceConnector = new jceSSLClient(); this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection())); QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
emit connectionReadyAfterDisconnection(); emit connectionReadyAfterDisconnection();
@ -297,6 +298,7 @@ QString jceLogin::getPage()
void jceLogin::reValidation() void jceLogin::reValidation()
{ {
qDebug() << Q_FUNC_INFO << "Revalidating user"; qDebug() << Q_FUNC_INFO << "Revalidating user";
if (makeFirstVisit() == true) if (makeFirstVisit() == true)
{ {
if (checkValidation()) if (checkValidation())

View file

@ -6,6 +6,7 @@
#include "jceLoginHtmlScripts.h" #include "jceLoginHtmlScripts.h"
#include <QObject> #include <QObject>
#include <QProgressBar>
#include <QString> #include <QString>
@ -13,8 +14,8 @@ class jceLogin : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
jceLogin() {}
jceLogin(user* username); jceLogin(user* username,QProgressBar *progressbarPtr);
~jceLogin(); ~jceLogin();
enum jceStatus { enum jceStatus {
@ -61,6 +62,7 @@ private:
QString * recieverPage; QString * recieverPage;
user * jceA; user * jceA;
jceSSLClient * JceConnector; jceSSLClient * JceConnector;
QProgressBar *progressBar;
}; };