From 2ef44eff00cf3455203a0fc4457de82147a3a5d2 Mon Sep 17 00:00:00 2001 From: liranbg Date: Sat, 4 Oct 2014 03:47:14 +0300 Subject: [PATCH] added progress bar ; --- main/LoginTab/loginhandler.cpp | 13 +- main/LoginTab/loginhandler.h | 4 +- main/main.cpp | 14 +- main/mainscreen.cpp | 451 ++++++++++++++------------- main/mainscreen.h | 2 + main/mainscreen.ui | 39 +++ src/jceConnection/jcesslclient.cpp | 468 +++++++++++++++-------------- src/jceConnection/jcesslclient.h | 10 +- src/jceSettings/jcelogin.cpp | 8 +- src/jceSettings/jcelogin.h | 6 +- 10 files changed, 558 insertions(+), 457 deletions(-) diff --git a/main/LoginTab/loginhandler.cpp b/main/LoginTab/loginhandler.cpp index 50d75fa..572bcb0 100644 --- a/main/LoginTab/loginhandler.cpp +++ b/main/LoginTab/loginhandler.cpp @@ -1,19 +1,26 @@ #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->progressBar = progressbarPtr; //statusBar 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); + setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); //user settings userPtr = ptr; - this->jceLog = new jceLogin(userPtr); + this->jceLog = new jceLogin(userPtr,progressBar); QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost())); + } bool loginHandler::login(QString username,QString password) { diff --git a/main/LoginTab/loginhandler.h b/main/LoginTab/loginhandler.h index 6debc9a..8512ec1 100644 --- a/main/LoginTab/loginhandler.h +++ b/main/LoginTab/loginhandler.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "./src/jceSettings/jcelogin.h" @@ -17,7 +18,7 @@ class loginHandler : public QObject { Q_OBJECT public: - loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr); + loginHandler(user *ptr, QStatusBar *statusBarPtr, QPushButton *loginButtonPtr, QProgressBar *progressbarPtr); ~loginHandler() { delete iconButtomStatusLabel; @@ -51,6 +52,7 @@ private: QStatusBar *statusBar; QLabel *iconButtomStatusLabel; QPushButton *loginButtonPtr; + QProgressBar *progressBar; }; diff --git a/main/main.cpp b/main/main.cpp index ef2dd6d..84fb2b2 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -9,13 +9,13 @@ int main(int argc, char *argv[]) { #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. // qDebug() << "Running a release build"; qInstallMessageHandler(jce_logger::customMessageHandler); #endif - qDebug() << "Start : JCE Manager Launched"; + qDebug() << Q_FUNC_INFO << "Start : JCE Manager Launched"; QApplication a(argc, argv); QTranslator translator; @@ -27,13 +27,13 @@ int main(int argc, char *argv[]) { QString locale = QLocale::system().name(); translator.load("jce_"+locale , a.applicationDirPath()); - qDebug() << "Local : Default Local Loaded"; + qDebug() << Q_FUNC_INFO << "Local : Default Local Loaded"; }else if(loco == "he"){ translator.load("jce_he" , a.applicationDirPath()); - qDebug() << "Local : Hebrew Local Loaded"; + qDebug() << Q_FUNC_INFO << "Local : Hebrew Local Loaded"; }else{ translator.load("jce_en" , a.applicationDirPath()); - qDebug() << "Local : English Local Loaded"; + qDebug() << Q_FUNC_INFO << "Local : English Local Loaded"; } a.installTranslator(&translator); //Setting local MainScreen w; @@ -42,8 +42,8 @@ int main(int argc, char *argv[]) //Getting the exit code from QApplication. for debug reasons int returnCode = a.exec(); 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 - 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; } diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index fa7d03f..5425d5d 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -2,361 +2,378 @@ #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); - //this->setFixedSize(this->size()); //main not resizeable + ui->setupUi(this); - ui->labelMadeBy->setOpenExternalLinks(true); + ui->labelMadeBy->setOpenExternalLinks(true); - //Login Tab - iconPix.load(":/icons/iconX.png"); - ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); - ui->labelUsrInputStatus->setVisible(false); - ui->labelPswInputStatus->setVisible(false); - ui->labelUsrInputStatus->setPixmap(iconPix); - ui->labelPswInputStatus->setPixmap(iconPix); + //Login Tab + iconPix.load(":/icons/iconX.png"); + ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); + ui->labelUsrInputStatus->setVisible(false); + ui->labelPswInputStatus->setVisible(false); + ui->labelUsrInputStatus->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 - ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); + //StatusBar & progressbar + 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 - 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); - this->calendar = new CalendarManager(ui->calendarGridLayoutMain); - this->data = new SaveData(); + //GPA Tab + ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); - //check login File - if (data->isSaved()) + //Pointer allocating + 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"; - ui->usrnmLineEdit->setText(data->getUsername()); - ui->pswdLineEdit->setText(data->getPassword()); - ui->keepLogin->setChecked(true); + qDebug() << Q_FUNC_INFO << "Loading data from file"; + ui->usrnmLineEdit->setText(data->getUsername()); + ui->pswdLineEdit->setText(data->getPassword()); + ui->keepLogin->setChecked(true); } - //language - qDebug() << Q_FUNC_INFO << "Checking locale"; - checkLocale(); - qDebug() << Q_FUNC_INFO << "Ready."; + //language + qDebug() << Q_FUNC_INFO << "Checking locale"; + checkLocale(); + ui->statusBar->repaint(); + qDebug() << Q_FUNC_INFO << "Ready."; } MainScreen::~MainScreen() { - delete calendar; - delete courseTableMgr; - delete userLoginSetting; - delete loginHandel; - delete data; - delete ui; + delete calendar; + delete courseTableMgr; + delete userLoginSetting; + delete loginHandel; + delete data; + delete ui; } //EVENTS ON LOGIN TAB void MainScreen::on_loginButton_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) + ui->progressBar->setValue(0); + 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); - qDebug() << Q_FUNC_INFO << "username input is empty"; + ui->labelUsrInputStatus->setVisible(true); + 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); - if (ui->pswdLineEdit->text().isEmpty()) - { - ui->labelPswInputStatus->setVisible(true); - qDebug() << Q_FUNC_INFO << "password input is empty"; - } - else 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->labelPswInputStatus->setVisible(false); - } - qDebug() << Q_FUNC_INFO << "login session start"; - QApplication::setOverrideCursor(Qt::WaitCursor); - 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()) + ui->progressBar->setValue(100); + 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"; - data->setUsername(ui->usrnmLineEdit->text()); - data->setPassword(ui->pswdLineEdit->text()); + qDebug() << Q_FUNC_INFO << "saving data"; + data->setUsername(ui->usrnmLineEdit->text()); + data->setPassword(ui->pswdLineEdit->text()); } } - else + else { - qDebug() << Q_FUNC_INFO << "login session end with false"; - ui->pswdLineEdit->setDisabled(false); - ui->usrnmLineEdit->setDisabled(false); + qDebug() << Q_FUNC_INFO << "login session end with false"; + ui->pswdLineEdit->setDisabled(false); + ui->usrnmLineEdit->setDisabled(false); } - QApplication::restoreOverrideCursor(); + QApplication::restoreOverrideCursor(); } void MainScreen::on_keepLogin_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if (ui->keepLogin->isChecked()) + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if (ui->keepLogin->isChecked()) { - qDebug() << Q_FUNC_INFO << "saving data"; - data->setUsername(ui->usrnmLineEdit->text()); - data->setPassword(ui->pswdLineEdit->text()); + qDebug() << Q_FUNC_INFO << "saving data"; + data->setUsername(ui->usrnmLineEdit->text()); + data->setPassword(ui->pswdLineEdit->text()); } - else - data->reset(); + else + data->reset(); } void MainScreen::on_usrnmLineEdit_editingFinished() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); } //EVENTS ON GPA TAB void MainScreen::on_ratesButton_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if (!checkIfValidDates()) + ui->progressBar->setValue(0); + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if (!checkIfValidDates()) { - qWarning() << Q_FUNC_INFO << "Invalid dates! return"; - QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again")); - return; + qWarning() << Q_FUNC_INFO << "Invalid dates! return"; + QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again")); + return; } - QString pageString; - int status = 0; - QApplication::setOverrideCursor(Qt::WaitCursor); - if (loginHandel->isLoggedInFlag()) + QString pageString; + int status = 0; + QApplication::setOverrideCursor(Qt::WaitCursor); + if (loginHandel->isLoggedInFlag() && !busyFlag) { - if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(), - ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(), - ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_PAGE_PASSED) + ui->statusBar->showMessage(tr("Getting grades...")); + if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(), + ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(), + ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_PAGE_PASSED) { - qDebug() << Q_FUNC_INFO << "grade page is ready"; - pageString = loginHandel->getCurrentPageContect(); - courseTableMgr->setCoursesList(pageString); - courseTableMgr->insertJceCoursesIntoTable(); + qDebug() << Q_FUNC_INFO << "grade page is ready"; + ui->statusBar->showMessage(tr("Done. Inserting data into table..."),1000); + pageString = loginHandel->getCurrentPageContect(); + 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"; - QApplication::restoreOverrideCursor(); - QMessageBox::critical(this,tr("Error"),tr("Not Connected")); + qWarning() << Q_FUNC_INFO << "not connected"; + QApplication::restoreOverrideCursor(); + 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 flag = false; - if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value()) + bool flag = false; + if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value()) { - //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()) + //doesnt matter what is the semester, its valid! 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) { - qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked; - this->userLoginSetting->setInfluenceCourseOnly(checked); - this->courseTableMgr->influnceCourseChanged(checked); + qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked; + this->userLoginSetting->setInfluenceCourseOnly(checked); + this->courseTableMgr->influnceCourseChanged(checked); } void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1) { - ui->spinBoxCoursesFromYear->setValue(arg1); + ui->spinBoxCoursesFromYear->setValue(arg1); } void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1) { - ui->spinBoxCoursesToYear->setValue(arg1); + ui->spinBoxCoursesToYear->setValue(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) { - ui->spinBoxCoursesToSemester->setValue(arg1%4); + ui->spinBoxCoursesToSemester->setValue(arg1%4); } void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) { - if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) - ui->avgLCD->display(courseTableMgr->getAvg()); - else + if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) + ui->avgLCD->display(courseTableMgr->getAvg()); + else { - qWarning() << Q_FUNC_INFO << "missmatch data"; - QMessageBox::critical(this,tr("Error"),tr("Missmatching data")); + qWarning() << Q_FUNC_INFO << "missmatch data"; + QMessageBox::critical(this,tr("Error"),tr("Missmatching data")); } } void MainScreen::on_clearTableButton_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - courseTableMgr->clearTable(); - ui->avgLCD->display(courseTableMgr->getAvg()); + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + courseTableMgr->clearTable(); + ui->avgLCD->display(courseTableMgr->getAvg()); } //EVENTS ON CALENDAR TAB void MainScreen::on_getCalendarBtn_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - int status = 0; - QApplication::setOverrideCursor(Qt::WaitCursor); - if (loginHandel->isLoggedInFlag()) + ui->progressBar->setValue(0); + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + int status = 0; + 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()); - calendar->resetTable(); - calendar->setCalendar(loginHandel->getCurrentPageContect()); - qDebug() << Q_FUNC_INFO << "calendar is loaded"; + + //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()); + calendar->resetTable(); + 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"; - QApplication::restoreOverrideCursor(); - QMessageBox::critical(this,tr("Error"),tr("Not Connected")); + qWarning() << Q_FUNC_INFO << "not connected"; + QApplication::restoreOverrideCursor(); + QMessageBox::critical(this,tr("Error"),tr("Not Connected")); } - else - qCritical() << Q_FUNC_INFO << "calendar get ended with" << status; + else + qCritical() << Q_FUNC_INFO << "calendar get ended with" << status; } - QApplication::restoreOverrideCursor(); + QApplication::restoreOverrideCursor(); } void MainScreen::on_exportToCVSBtn_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if (loginHandel->isLoggedInFlag()) + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if (loginHandel->isLoggedInFlag()) { - this->calendar->exportCalendarCSV(); + this->calendar->exportCalendarCSV(); } } //EVENTS ON MENU BAR void MainScreen::on_actionCredits_triggered() { - qDebug() << Q_FUNC_INFO; - QMessageBox::about(this, "About", - "Jce Manager v1.0.0

" - +tr("License:")+ - "
GNU LESSER GENERAL PUBLIC LICENSE V2.1
" - +"
"+ - "JceManager Repository"+ - "

" - +tr("Powered By: ")+ - " Jce Connection

" - +tr("Developed By")+ - ":" - ); + qDebug() << Q_FUNC_INFO; + QMessageBox::about(this, "About", + "Jce Manager v1.0.0

" + +tr("License:")+ + "
GNU LESSER GENERAL PUBLIC LICENSE V2.1
" + +"
"+ + "JceManager Repository"+ + "

" + +tr("Powered By: ")+ + " Jce Connection

" + +tr("Developed By")+ + ":" + ); } void MainScreen::on_actionExit_triggered() { - qDebug() << Q_FUNC_INFO; - exit(0); + qDebug() << Q_FUNC_INFO; + exit(0); } void MainScreen::on_actionHow_To_triggered() { - qDebug() << Q_FUNC_INFO; - QMessageBox::information(this,"How To", - "" - +tr("Help Guide")+ - "
    " - +tr("
  • Login:
    • Type your username and password and click Login.
    • Once you are connected, you will see a green ball in the right buttom panel.
  • ") - +tr("
  • Getting GPA sheet
    • Click on GPA Tab
    • Select your dates and click on Add
  • ") - +tr("
  • Average Changing
    • Change one of your grade and see the average in the buttom panel changing.
  • ") - +tr("
  • Getting Calendar
    • Click on Calendar Tab
    • Select your dates and click on Get Calendar
  • ") - +tr("
  • For exporting your calendar to a .CSV file:
    • Do previous step and continue to next step
    • Click on Export to CSV
    • Select your dates and click OK
    • Once you're Done, go on your calendar and import your csv file
    • ")+ - "

      " - +tr("For more information, please visit us at: Jce Manager site")); + qDebug() << Q_FUNC_INFO; + QMessageBox::information(this,"How To", + "" + +tr("Help Guide")+ + "
        " + +tr("
      • Login:
        • Type your username and password and click Login.
        • Once you are connected, you will see a green ball in the right buttom panel.
      • ") + +tr("
      • Getting GPA sheet
        • Click on GPA Tab
        • Select your dates and click on Add
      • ") + +tr("
      • Average Changing
        • Change one of your grade and see the average in the buttom panel changing.
      • ") + +tr("
      • Getting Calendar
        • Click on Calendar Tab
        • Select your dates and click on Get Calendar
      • ") + +tr("
      • For exporting your calendar to a .CSV file:
        • Do previous step and continue to next step
        • Click on Export to CSV
        • Select your dates and click OK
        • Once you're Done, go on your calendar and import your csv file
        • ")+ + "

          " + +tr("For more information, please visit us at: Jce Manager site")); } void MainScreen::on_actionHebrew_triggered() { - qDebug() << Q_FUNC_INFO; - if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked()) + qDebug() << Q_FUNC_INFO; + if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked()) { - ui->actionEnglish->setChecked(false); - ui->actionOS_Default->setChecked(false); - qDebug() << Q_FUNC_INFO << "Changed Language to hebrew"; - data->setLocal("he"); - QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); + ui->actionEnglish->setChecked(false); + ui->actionOS_Default->setChecked(false); + qDebug() << Q_FUNC_INFO << "Changed Language to hebrew"; + data->setLocal("he"); + QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); } - else - ui->actionHebrew->setChecked(true); + else + ui->actionHebrew->setChecked(true); } void MainScreen::on_actionEnglish_triggered() { - qDebug() << Q_FUNC_INFO; - if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked()) + qDebug() << Q_FUNC_INFO; + if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked()) { - ui->actionHebrew->setChecked(false); - ui->actionOS_Default->setChecked(false); - qDebug() << Q_FUNC_INFO << "Changed Language to English"; - data->setLocal("en"); - QMessageBox::information(this,"Settings",tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); + ui->actionHebrew->setChecked(false); + ui->actionOS_Default->setChecked(false); + qDebug() << Q_FUNC_INFO << "Changed Language to English"; + data->setLocal("en"); + QMessageBox::information(this,"Settings",tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); } - else - ui->actionEnglish->setChecked(true); + else + ui->actionEnglish->setChecked(true); } void MainScreen::on_actionOS_Default_triggered() { - qDebug() << Q_FUNC_INFO; - if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked()) + qDebug() << Q_FUNC_INFO; + if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked()) { - ui->actionHebrew->setChecked(false); - ui->actionEnglish->setChecked(false); - qDebug() << Q_FUNC_INFO << "Changed Language to OS Default"; - data->setLocal("default"); - QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); + ui->actionHebrew->setChecked(false); + ui->actionEnglish->setChecked(false); + qDebug() << Q_FUNC_INFO << "Changed Language to OS Default"; + data->setLocal("default"); + QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok); } - else - ui->actionOS_Default->setChecked(true); + else + ui->actionOS_Default->setChecked(true); } void MainScreen::checkLocale() { - if(data->getLocal() == "en") + if(data->getLocal() == "en") { - ui->actionHebrew->setChecked(false); - ui->actionOS_Default->setChecked(false); - ui->actionEnglish->setChecked(true); + ui->actionHebrew->setChecked(false); + ui->actionOS_Default->setChecked(false); + ui->actionEnglish->setChecked(true); }else if(data->getLocal() == "he"){ - ui->actionHebrew->setChecked(true); - ui->actionOS_Default->setChecked(false); - ui->actionEnglish->setChecked(false); + ui->actionHebrew->setChecked(true); + ui->actionOS_Default->setChecked(false); + ui->actionEnglish->setChecked(false); }else{ - ui->actionHebrew->setChecked(false); - ui->actionOS_Default->setChecked(true); - ui->actionEnglish->setChecked(false); + ui->actionHebrew->setChecked(false); + ui->actionOS_Default->setChecked(true); + ui->actionEnglish->setChecked(false); } } void MainScreen::on_labelMadeBy_linkActivated(const QString &link) { - qDebug() << Q_FUNC_INFO << "link: " << link; + qDebug() << Q_FUNC_INFO << "link: " << link; } diff --git a/main/mainscreen.h b/main/mainscreen.h index 7ab3d42..929ed48 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -83,6 +83,8 @@ private: coursesTableManager *courseTableMgr; loginHandler *loginHandel; + bool busyFlag; + }; #endif // MAINSCREEN_H diff --git a/main/mainscreen.ui b/main/mainscreen.ui index fc522ca..ad37d5b 100644 --- a/main/mainscreen.ui +++ b/main/mainscreen.ui @@ -626,6 +626,45 @@ font-size: 15px; + + + + + 0 + 0 + + + + #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); +} + + + 0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + Qt::Horizontal + + + false + + + QProgressBar::TopToBottom + + + diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index 729447e..c2b5b07 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -3,17 +3,19 @@ /** * @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 - 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())); + this->progressBar = progressbarPtr; + //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())); } /** @@ -24,48 +26,48 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""),networkConf(), reConnecti */ bool jceSSLClient::makeConnect(QString server, int port) { - if (this->supportsSsl() == false) + if (this->supportsSsl() == false) { - qCritical() << Q_FUNC_INFO << "Couldnt load ssl package. ERROR"; - return false; + qCritical() << Q_FUNC_INFO << "Couldnt load ssl package. ERROR"; + return false; } - else - qDebug() << Q_FUNC_INFO << "ssl loaded."; + else + qDebug() << Q_FUNC_INFO << "ssl loaded."; - if (isConnectedToNetwork() == false) + if (isConnectedToNetwork() == false) { - qDebug() << Q_FUNC_INFO << "return false. not online"; - return false; + qDebug() << Q_FUNC_INFO << "return false. not online"; + return false; } - else - qDebug() << Q_FUNC_INFO << "we're online"; + else + 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 - qDebug() << Q_FUNC_INFO << "Making Connection"; + else + qDebug() << Q_FUNC_INFO << "Making Connection"; - if (isConnected()) + if (isConnected()) { - qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()"; - makeDiconnect(); + qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()"; + makeDiconnect(); } - qDebug() << Q_FUNC_INFO << "Connection to: " << server << "On Port: " << port; - connectToHostEncrypted(server.toStdString().c_str(), port); + qDebug() << Q_FUNC_INFO << "Connection to: " << server << "On Port: " << 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(); - if (reConnection) + qDebug() << Q_FUNC_INFO << "returning the connection status: " << isConnected(); + if (reConnection) { - reConnection = false; - emit serverDisconnectedbyRemote(); + reConnection = false; + emit serverDisconnectedbyRemote(); } - return isConnected(); + return isConnected(); } /** @@ -74,15 +76,15 @@ bool jceSSLClient::makeConnect(QString server, int port) */ bool jceSSLClient::makeDiconnect() { - if (loop.isRunning()) + if (loop.isRunning()) { - qWarning() << Q_FUNC_INFO << "Killing connection thread"; - loop.exit(); + qWarning() << Q_FUNC_INFO << "Killing connection thread"; + loop.exit(); } - qDebug() << Q_FUNC_INFO << "disconnecting from host and emitting disconnected()"; - this->disconnectFromHost(); //emits disconnected > setDisconnected - setSocketState(QAbstractSocket::SocketState::UnconnectedState); - return (!isConnected()); + qDebug() << Q_FUNC_INFO << "disconnecting from host and emitting disconnected()"; + this->disconnectFromHost(); //emits disconnected > setDisconnected + setSocketState(QAbstractSocket::SocketState::UnconnectedState); + return (!isConnected()); } @@ -92,30 +94,30 @@ bool jceSSLClient::makeDiconnect() */ bool jceSSLClient::isConnected() { - bool tempFlag = false; - //checking state before returning flag! - if (state() == QAbstractSocket::SocketState::UnconnectedState) + bool tempFlag = false; + //checking state before returning flag! + 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()) - tempFlag = true; - else + if (isConnectedToNetwork()) + tempFlag = true; + else { - this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); - tempFlag = false; + this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); + tempFlag = false; } } - if (!isConnectedToNetwork()) //no link, ethernet\wifi - tempFlag = false; - return ((flag) && (tempFlag)); + if (!isConnectedToNetwork()) //no link, ethernet\wifi + tempFlag = false; + return ((flag) && (tempFlag)); } /** * @brief jceSSLClient::sendData - given string, send it to server @@ -124,16 +126,16 @@ bool jceSSLClient::isConnected() */ 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()); - if (waitForBytesWritten()) - sendDataFlag = true; + write(str.toStdString().c_str(),str.length()); + if (waitForBytesWritten()) + sendDataFlag = true; } - qDebug() << Q_FUNC_INFO << "Sending Data status is: " << sendDataFlag; - return sendDataFlag; + qDebug() << Q_FUNC_INFO << "Sending Data status is: " << sendDataFlag; + return sendDataFlag; } /** * @brief jceSSLClient::recieveData @@ -143,39 +145,41 @@ bool jceSSLClient::sendData(QString str) */ bool jceSSLClient::recieveData(QString &str, bool fast) { - qDebug() << Q_FUNC_INFO << "Data receiving!"; - packet = ""; - bool sflag = false; + qDebug() << Q_FUNC_INFO << "Data receiving!"; + packet = ""; + 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"; - QEventLoop loop; - connect(this, SIGNAL(readyRead()), &loop, SLOT(quit())); - connect(this, SIGNAL(readyRead()), this, SLOT(readIt())); - loop.exec(); - disconnect(this, SIGNAL(readyRead()), &loop, SLOT(quit())); - disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt())); + qDebug() << Q_FUNC_INFO << "login step receiving"; + //loop will exit after first read packet. + //meanwhile packet will gain data. good for small amount of data - fast connection! + connect(this, SIGNAL(readyRead()), &readerLoop, SLOT(quit())); + connect(this, SIGNAL(readyRead()), this, SLOT(readIt())); + readerLoop.exec(); + disconnect(this, SIGNAL(readyRead()), &readerLoop, SLOT(quit())); + disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt())); } - else + else { - qDebug() << "jceSSLClient::recieveData normal receiving"; - QString p; - while (waitForReadyRead(milisTimeOut)) - { - do - { - p = readAll(); - packet.append(p); - }while (p.size() > 0); - } + qDebug() << Q_FUNC_INFO << "normal receiving"; + //loop will exit after timeout \ full data + connect(this, SIGNAL(packetHasData()), &readerLoop, SLOT(quit())); + + timer.setSingleShot(true); + connect(&timer, SIGNAL(timeout()), &readerLoop, SLOT(quit())); + connect(this, SIGNAL(readyRead()), this, SLOT(readItAll())); + timer.start(5000); + readerLoop.exec(); + } - str = packet; - qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ; - if (str.length() > 0) - sflag = true; - qDebug() << Q_FUNC_INFO << "return with flag: " << sflag; - return sflag; + str = packet; + qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ; + if (str.length() > 0) + sflag = true; + qDebug() << Q_FUNC_INFO << "return with flag: " << sflag; + disconnect(this, SIGNAL(readyRead()), this, SLOT(readItAll())); + return sflag; } /** @@ -183,29 +187,47 @@ bool jceSSLClient::recieveData(QString &str, bool fast) */ void jceSSLClient::readIt() { - QString p; - do + QString p; + do { - p = readAll(); - packet.append(p); + p = readAll(); + packet.append(p); + this->progressBar->setValue(this->progressBar->value() + 6); }while (p.size() > 0); } +void jceSSLClient::readItAll() +{ + QString p; + do + { + p = ""; + p = read(bytesAvailable()); + if (p.contains("") == 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) { - qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline; - if (isOnline) //to be added later + qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline; + if (isOnline) //to be added later { - qDebug() << Q_FUNC_INFO << "Online Statue has been changed. we are online"; - //we can add here auto reconnect if wifi\ethernet link has appear - //will be added next version + qDebug() << Q_FUNC_INFO << "Online Statue has been changed. we are online"; + //we can add here auto reconnect if wifi\ethernet link has appear + //will be added next version } - else + else { - qWarning() << Q_FUNC_INFO << "Online State has been changed. emitting NoInternetLink"; - this->makeDiconnect(); - emit noInternetLink(); + qWarning() << Q_FUNC_INFO << "Online State has been changed. emitting NoInternetLink"; + this->makeDiconnect(); + emit noInternetLink(); } } @@ -214,19 +236,19 @@ void jceSSLClient::setOnlineState(bool isOnline) */ void jceSSLClient::setConnected() { - waitForEncrypted(); + waitForEncrypted(); } /** * @brief jceSSLClient::setDisconnected closing socket, updating state and setting flag to false */ void jceSSLClient::setDisconnected() { - qDebug() << Q_FUNC_INFO << "connection has been DISCONNECTED"; - this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); - packet.clear(); - flag = false; - if (reConnection) - makeConnect(); + qDebug() << Q_FUNC_INFO << "connection has been DISCONNECTED"; + this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); + packet.clear(); + flag = false; + if (reConnection) + makeConnect(); } @@ -235,14 +257,14 @@ void jceSSLClient::setDisconnected() */ void jceSSLClient::setEncrypted() { - qDebug() << Q_FUNC_INFO << "connection has been ENCRYPTED"; - setReadBufferSize(10000); - setSocketOption(QAbstractSocket::KeepAliveOption,true); - flag = true; - if (!isConnected()) + qDebug() << Q_FUNC_INFO << "connection has been ENCRYPTED"; + setReadBufferSize(10000); + setSocketOption(QAbstractSocket::KeepAliveOption,true); + flag = true; + if (!isConnected()) { - qWarning() << Q_FUNC_INFO << "Connection status didnt change! reseting flag to false"; - flag = false; + qWarning() << Q_FUNC_INFO << "Connection status didnt change! reseting flag to false"; + flag = false; } } @@ -253,116 +275,116 @@ void jceSSLClient::setEncrypted() */ void jceSSLClient::showIfErrorMsg() { - QMessageBox msgBox; - SocketError enumError = error(); - QString errorString; - bool relevantError = false; - switch (enumError) + QMessageBox msgBox; + SocketError enumError = error(); + QString errorString; + bool relevantError = false; + switch (enumError) { case QAbstractSocket::SocketError::ConnectionRefusedError: /**/ - errorString = QObject::tr("ConnectionRefusedError"); - //The connection was refused by the peer (or timed out). - relevantError = true; - break; + errorString = QObject::tr("ConnectionRefusedError"); + //The connection was refused by the peer (or timed out). + relevantError = true; + break; case QAbstractSocket::SocketError::RemoteHostClosedError: /**/ - errorString = QObject::tr("RemoteHostClosedError"); - //The remote host closed the connection - if (isConnectedToNetwork()) //we can reconnect + errorString = QObject::tr("RemoteHostClosedError"); + //The remote host closed the connection + if (isConnectedToNetwork()) //we can reconnect { - reConnection = true; + reConnection = true; } - else - relevantError = true; - break; + else + relevantError = true; + break; case QAbstractSocket::SocketError::HostNotFoundError: /**/ - errorString = QObject::tr("HostNotFoundError"); - //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 + errorString = QObject::tr("HostNotFoundError"); + //The host address was not found. 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: /**/ - errorString = QObject::tr("NetworkError"); - //An error occurred with the network (e.g., the network cable was accidentally plugged out). - if (isConnectedToNetwork()) //we can reconnect + errorString = QObject::tr("NetworkError"); + //An error occurred with the network (e.g., the network cable was accidentally plugged out). + if (isConnectedToNetwork()) //we can reconnect { } - else - relevantError = true; - break; + else + relevantError = true; + break; case QAbstractSocket::SocketError::SslHandshakeFailedError: /**/ - errorString = QObject::tr("SslHandshakeFailedError"); - relevantError = true; - break; + errorString = QObject::tr("SslHandshakeFailedError"); + relevantError = true; + break; case QAbstractSocket::SocketError::SslInternalError: /**/ - errorString = QObject::tr("SslInternalError"); - relevantError = true; - break; + errorString = QObject::tr("SslInternalError"); + relevantError = true; + break; case QAbstractSocket::SocketError::SslInvalidUserDataError: /**/ - errorString = QObject::tr("SslInvalidUserDataError"); - relevantError = true; - break; + errorString = QObject::tr("SslInvalidUserDataError"); + relevantError = true; + break; case QAbstractSocket::SocketError::DatagramTooLargeError: //not relevant to us - errorString = QObject::tr("DatagramTooLargeError"); - break; + errorString = QObject::tr("DatagramTooLargeError"); + break; case QAbstractSocket::SocketError::SocketResourceError: //not relevant to us - break; + break; case QAbstractSocket::SocketError::OperationError: //not relevant, except for debug - errorString = QObject::tr("OperationError"); - break; + errorString = QObject::tr("OperationError"); + break; case QAbstractSocket::SocketError::AddressInUseError: //not relevant to us - errorString = QObject::tr("AddressInUseError"); - break; + errorString = QObject::tr("AddressInUseError"); + break; case QAbstractSocket::SocketError::SocketAddressNotAvailableError: //not relevant to us - errorString = QObject::tr("SocketAddressNotAvailableError"); - break; + errorString = QObject::tr("SocketAddressNotAvailableError"); + break; case QAbstractSocket::SocketError::UnsupportedSocketOperationError: //for very old computers, not relevant to us - errorString = QObject::tr("UnsupportedSocketOperationError"); - break; + errorString = QObject::tr("UnsupportedSocketOperationError"); + break; case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError: //not relevant to us - errorString = QObject::tr("ProxyAuthenticationRequiredError"); - break; + errorString = QObject::tr("ProxyAuthenticationRequiredError"); + break; case QAbstractSocket::SocketError::ProxyConnectionRefusedError: //not relevant to us - errorString = QObject::tr("ProxyConnectionRefusedError"); - break; + errorString = QObject::tr("ProxyConnectionRefusedError"); + break; case QAbstractSocket::SocketError::UnfinishedSocketOperationError: //not relevant to us - errorString = QObject::tr("UnfinishedSocketOperationError"); - break; + errorString = QObject::tr("UnfinishedSocketOperationError"); + break; case QAbstractSocket::SocketError::ProxyConnectionClosedError: //not relevant to us - errorString = QObject::tr("ProxyConnectionClosedError"); - break; + errorString = QObject::tr("ProxyConnectionClosedError"); + break; case QAbstractSocket::SocketError::ProxyConnectionTimeoutError: //not relevant to us - errorString = QObject::tr("ProxyConnectionTimeoutError"); - break; + errorString = QObject::tr("ProxyConnectionTimeoutError"); + break; case QAbstractSocket::SocketError::ProxyNotFoundError: //not relevant to us - errorString = QObject::tr("ProxyNotFoundError"); - break; + errorString = QObject::tr("ProxyNotFoundError"); + break; case QAbstractSocket::SocketError::ProxyProtocolError: //not relevant to us - errorString = QObject::tr("ProxyProtocolError"); - break; + errorString = QObject::tr("ProxyProtocolError"); + break; case QAbstractSocket::SocketError::TemporaryError: //not relevant to us - errorString = QObject::tr("TemporaryError"); - break; + errorString = QObject::tr("TemporaryError"); + break; case QAbstractSocket::SocketError::UnknownSocketError: //not relevant, except for debug - errorString = QObject::tr("UnknownSocketError"); - relevantError = true; - break; + errorString = QObject::tr("UnknownSocketError"); + relevantError = true; + break; } - if (relevantError) //informative string to be shown + if (relevantError) //informative string to be shown { - qDebug() << Q_FUNC_INFO << "relevant error."; - msgBox.setIcon(QMessageBox::Warning); - msgBox.setText(errorString); - msgBox.exec(); + qDebug() << Q_FUNC_INFO << "relevant error."; + msgBox.setIcon(QMessageBox::Warning); + msgBox.setText(errorString); + msgBox.exec(); } } /** @@ -371,24 +393,24 @@ void jceSSLClient::showIfErrorMsg() */ void jceSSLClient::checkErrors(QAbstractSocket::SocketError a) { - //ignore this stupid error - bool timeout = (a == QAbstractSocket::SocketError::SocketTimeoutError); - if (!((isConnected()) && (timeout))) + //ignore this stupid error + bool timeout = (a == QAbstractSocket::SocketError::SocketTimeoutError); + if (!((isConnected()) && (timeout))) { - qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork(); - qWarning() << Q_FUNC_INFO << "state is: " << state(); - qWarning() << Q_FUNC_INFO << "Var Error: " << a; - qWarning() << Q_FUNC_INFO << "Error: " << errorString(); + qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork(); + qWarning() << Q_FUNC_INFO << "state is: " << state(); + qWarning() << Q_FUNC_INFO << "Var Error: " << a; + qWarning() << Q_FUNC_INFO << "Error: " << errorString(); } - else + else { - qDebug() << Q_FUNC_INFO << "isConnected?: " << isConnected() << "is timeout?" << timeout; - qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork(); - qWarning() << Q_FUNC_INFO << "state is: " << state(); - qWarning() << Q_FUNC_INFO << "Var Error: " << a; - qWarning() << Q_FUNC_INFO << "Error: " << errorString(); + qDebug() << Q_FUNC_INFO << "isConnected?: " << isConnected() << "is timeout?" << timeout; + qWarning() << Q_FUNC_INFO << "isOnline?: " << isConnectedToNetwork(); + qWarning() << Q_FUNC_INFO << "state is: " << state(); + qWarning() << Q_FUNC_INFO << "Var Error: " << a; + qWarning() << Q_FUNC_INFO << "Error: " << errorString(); } - showIfErrorMsg(); + showIfErrorMsg(); } /** written by KARAN BALKAR @@ -397,20 +419,20 @@ void jceSSLClient::checkErrors(QAbstractSocket::SocketError a) */ bool jceSSLClient::isConnectedToNetwork(){ - QList ifaces = QNetworkInterface::allInterfaces(); - bool result = false; + QList ifaces = QNetworkInterface::allInterfaces(); + 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)) - for (int j=0; j < iface.addressEntries().count(); ++j) - // got an interface which is up, and has an ip address - if (result == false) - result = true; + if ( iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack)) + for (int j=0; j < iface.addressEntries().count(); ++j) + // got an interface which is up, and has an ip address + if (result == false) + result = true; } - return result; + return result; } diff --git a/src/jceConnection/jcesslclient.h b/src/jceConnection/jcesslclient.h index d4f95e7..a6edbed 100644 --- a/src/jceConnection/jcesslclient.h +++ b/src/jceConnection/jcesslclient.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #define milisTimeOut 4000 @@ -15,7 +17,7 @@ class jceSSLClient : public QSslSocket { Q_OBJECT public: - jceSSLClient(); + jceSSLClient(QProgressBar *progressbarPtr); bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443); bool makeDiconnect(); @@ -28,6 +30,7 @@ signals: void serverDisconnectedbyRemote(); void noInternetLink(); void socketDisconnected(); + void packetHasData(); private slots: void checkErrors(QAbstractSocket::SocketError a); @@ -35,6 +38,7 @@ private slots: void setEncrypted(); void setDisconnected(); void readIt(); + void readItAll(); void setOnlineState(bool isOnline); private: @@ -42,9 +46,13 @@ private: bool flag; QString packet; QEventLoop loop; //handle the connection as thread + QEventLoop readerLoop; + QTimer timer; QNetworkConfigurationManager networkConf; //checking if online bool reConnection; //used for remote host disconnecting + QProgressBar *progressBar; // + }; #endif // JCESSLCLIENT_H diff --git a/src/jceSettings/jcelogin.cpp b/src/jceSettings/jcelogin.cpp index 5a25587..900ef23 100644 --- a/src/jceSettings/jcelogin.cpp +++ b/src/jceSettings/jcelogin.cpp @@ -4,11 +4,12 @@ * @brief jceLogin::jceLogin * @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->jceA = username; - this->JceConnector = new jceSSLClient(); + this->JceConnector = new jceSSLClient(progressBar); QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection())); } @@ -133,7 +134,7 @@ void jceLogin::reMakeConnection() recieverPage = NULL; JceConnector = NULL; 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(noInternetLink()),this,SLOT(reMakeConnection())); emit connectionReadyAfterDisconnection(); @@ -297,6 +298,7 @@ QString jceLogin::getPage() void jceLogin::reValidation() { qDebug() << Q_FUNC_INFO << "Revalidating user"; + if (makeFirstVisit() == true) { if (checkValidation()) diff --git a/src/jceSettings/jcelogin.h b/src/jceSettings/jcelogin.h index ede8514..912b47b 100644 --- a/src/jceSettings/jcelogin.h +++ b/src/jceSettings/jcelogin.h @@ -6,6 +6,7 @@ #include "jceLoginHtmlScripts.h" #include +#include #include @@ -13,8 +14,8 @@ class jceLogin : public QObject { Q_OBJECT public: - jceLogin() {} - jceLogin(user* username); + + jceLogin(user* username,QProgressBar *progressbarPtr); ~jceLogin(); enum jceStatus { @@ -61,6 +62,7 @@ private: QString * recieverPage; user * jceA; jceSSLClient * JceConnector; + QProgressBar *progressBar; };