From d2b7cf40c8cbc048c7e4eda8ee4db93cc9e51936 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Wed, 17 Sep 2014 19:52:21 +0300 Subject: [PATCH 01/12] Documentation --- main/main.cpp | 11 +++--- src/jceData/CSV/csv_exporter.cpp | 62 +++++++++++++++++++++++++------- src/jce_logger.cpp | 11 +++++- src/jce_logger.h | 2 ++ 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index ff037ec..609c15f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -8,19 +8,21 @@ int main(int argc, char *argv[]) { -#ifdef QT_DEBUG +#ifdef QT_DEBUG // Incase QtCreator is in Debug mode all qDebug messages will go to terminal qDebug() << "Running a debug build"; -#else +#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" << Q_FUNC_INFO; + qDebug() << "Start : JCE Manager Launched"; + QApplication a(argc, argv); QTranslator translator; QString loco; SaveData data; loco = data.getLocal(); + //Loading Local (From Settings file (SaveData.cpp) if(loco == "default") { QString locale = QLocale::system().name(); @@ -33,10 +35,11 @@ int main(int argc, char *argv[]) translator.load("jce_en" , a.applicationDirPath()); qDebug() << "Local : English Local Loaded"; } - a.installTranslator(&translator); + a.installTranslator(&translator); //Setting local MainScreen w; w.show(); + //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; diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index 0d96427..b712ad8 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -1,10 +1,25 @@ #include "csv_exporter.h" +/* + * + * Class doc can be bound in csv_exporter.h + * + */ + + CSV_Exporter::CSV_Exporter() { - + /* EMPTY - NO NEED */ } +/** + * @brief This method will generate the CSV file (Targeting google calendar import) + * it will create a full Semester calendar based on the users input (@param cal) + * and the @calSched wich holdes all the courses in "this" semester. + * @param calSched - Holdes all the Courses and there info + * @param cal - The Calendar dialog witch holdes the starting date and the eand date. + * @return - True if *all* went well, false if something on the way went wrong. + */ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal) { if ((cal == NULL) || (calSched == NULL) || (calSched->getCourses() == NULL)) //pointers checking! @@ -14,7 +29,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca } qDebug() << "CSV : Getting path for csv file from user..."; QString filePath = getFileFath(); - if(filePath == NULL) //User canceled + if(filePath == NULL) //User canceled from the file explorer popup { qDebug() << "CSV : User pressed Cancel... returning false"; return false; @@ -23,31 +38,36 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca qDebug() << "CSV : Atempting to export the Schedule..."; QFile file(filePath); - if(!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) + if(!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) //Incase unable to open the file (binary mode - \n will not be converted on "Windows") { qCritical() << "CSV : unable to open/create the file... maybe permissions error."; return false; - }//else - //Delete the file + } + QTextStream out(&file); - out << CSV_CALENDAR_HEADER << "\n"; - for (calendarCourse *coursePtr: *(calSched->getCourses())) + out << CSV_CALENDAR_HEADER << "\n"; // macro in header file + + for (calendarCourse *coursePtr: *(calSched->getCourses())) //main loop - running though all courses { - // Subject,Start Date,Start Time,End Date,End Time,Description,Location + // Getting course info - store in vars for easy access int day = coursePtr->getDay(); int startH = coursePtr->getHourBegin(); int startM = coursePtr->getMinutesBegin(); int endH = coursePtr->getHourEnd(); int endM = coursePtr->getMinutesEnd(); - QString lecturer = QString(coursePtr->getLecturer().c_str()); //WHY YOU USED STD STRING?! + QString lecturer = QString(coursePtr->getLecturer().c_str()); //NOTE: STD String QString type = QString(coursePtr->getType().c_str()); QString name = QString(coursePtr->getName().c_str()); QString room = QString(coursePtr->getRoom().c_str()); - QDate currentDate = cal->getStartDate(); + QDate currentDate = cal->getStartDate(); // currentDate will iterate thou the semester - currentDate = currentDate.addDays(day-1); + currentDate = currentDate.addDays(day-1); //selecting the REAL starting day of that course + /* + * secondary loop - We have course info and starting day. + * evrey loop enterence we add the course and moving one week forward. + */ for(;currentDate <= cal->getEndDate(); currentDate = currentDate.addDays(7)) { QString line = makeLine(name, ¤tDate, startH, startM, endH, endM, lecturer, room, type); @@ -66,6 +86,10 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca } +/** + * @brief Get the file path according to user via a file explorer dialog + * @return - QString: the file path. + */ QString CSV_Exporter::getFileFath() { QString fileName = QFileDialog::getSaveFileName(); @@ -76,6 +100,20 @@ QString CSV_Exporter::getFileFath() return fileName; } + +/** + * @brief Returning a CSV formated ling in QString. + * @param name + * @param date + * @param startH + * @param startM + * @param endH + * @param endM + * @param lecturer + * @param room + * @param type + * @return a CSV formated ling in QString. + */ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM, int endH, int endM, QString lecturer, QString room, QString type) { //Creating a CSV text line for Google Calendar/iCal/Outlook @@ -108,7 +146,7 @@ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM description.append("\n"); description.append(" ב"); description.append(room); - description.append("\""); + description.append("\n Created with JCE Manager. \" "); //Create the Fucking Line //Header: Subject,Start Date,Start Time,End Date,End Time,Description,Location diff --git a/src/jce_logger.cpp b/src/jce_logger.cpp index cbfe6d1..829b5e2 100644 --- a/src/jce_logger.cpp +++ b/src/jce_logger.cpp @@ -4,6 +4,15 @@ * This Static method will help parsing our debug messages to a readable Log file * * timestamp - Message type - message + * + * Message types cam be: + * + * - DEBUG + * - WARNING + * - CRITICAL + * - FATAL + * + * Logs stored in a log file. File name is Stored in the Macro in Header file */ void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { @@ -29,7 +38,7 @@ void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext & break; } - QFile outFile("J_M_Log.log"); + QFile outFile(LOG_FILE_NAME); outFile.open(QIODevice::WriteOnly | QIODevice::Append); QTextStream textStream(&outFile); diff --git a/src/jce_logger.h b/src/jce_logger.h index eabc222..2414c04 100644 --- a/src/jce_logger.h +++ b/src/jce_logger.h @@ -7,6 +7,8 @@ #include #include +#define LOG_FILE_NAME "J_M_Log.log" + class jce_logger { public: From b092ca5ec210f1ac0716db7604024893c34034b6 Mon Sep 17 00:00:00 2001 From: Liran BN Date: Wed, 17 Sep 2014 20:06:36 +0300 Subject: [PATCH 02/12] fixed qstring casting --- src/jceData/CSV/csv_exporter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index 67a6a57..d2149fe 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -61,10 +61,10 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca int startM = coursePtr->getMinutesBegin(); int endH = coursePtr->getHourEnd(); int endM = coursePtr->getMinutesEnd(); - QString lecturer = QString(coursePtr->getLecturer().c_str()); //NOTE: STD String - QString type = QString(coursePtr->getType().c_str()); - QString name = QString(coursePtr->getName().c_str()); - QString room = QString(coursePtr->getRoom().c_str()); + QString lecturer = coursePtr->getLecturer(); + QString type = coursePtr->getType(); + QString name = coursePtr->getName(); + QString room = coursePtr->getRoom(); QDate currentDate = cal->getStartDate(); // currentDate will iterate thou the semester From 090dc28137f6ec492dc91375f02c4498b7005c24 Mon Sep 17 00:00:00 2001 From: liranbg Date: Thu, 18 Sep 2014 01:59:42 +0300 Subject: [PATCH 03/12] icon fix --- jceGrade.pro | 134 +++++++++++++++---------------- main/mainscreen.cpp | 10 +-- main/mainscreen.h | 5 +- src/jceData/CSV/csv_exporter.cpp | 2 +- src/jce_logger.cpp | 92 ++++++++++----------- src/jce_logger.h | 38 ++++----- 6 files changed, 139 insertions(+), 142 deletions(-) diff --git a/jceGrade.pro b/jceGrade.pro index 6491211..011cfa6 100644 --- a/jceGrade.pro +++ b/jceGrade.pro @@ -1,67 +1,67 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-05-31T19:49:42 -# -#------------------------------------------------- - -QT += core gui network widgets -TARGET = jceGrade -TEMPLATE = app -RC_FILE = appConfigure.rc -CONFIG += qt c++11 -CONFIG += console static - -TRANSLATIONS = jce_en.ts \ - jce_he.ts - -FORMS += \ - main/mainscreen.ui \ - src/jceData/Calendar/calendarDialog.ui - -OTHER_FILES += - -RESOURCES += \ - resources/connectionstatus.qrc - -HEADERS += \ - main/CalendarTab/CalendarManager.h \ - main/CourseTab/coursestablemanager.h \ - main/LoginTab/loginhandler.h \ - main/mainscreen.h \ - src/appDatabase/savedata.h \ - src/jceConnection/jcesslclient.h \ - src/jceData/Calendar/calendarPage.h \ - src/jceData/Grades/gradeCourse.h \ - src/jceData/Grades/gradePage.h \ - src/jceData/course.h \ - src/jceData/page.h \ - src/jceSettings/jcelogin.h \ - src/jceSettings/jceLoginHtmlScripts.h \ - src/jceSettings/user.h \ - src/jceData/Calendar/calendarCourse.h \ - src/jceData/Calendar/calendarSchedule.h \ - src/jceData/CSV/csv_exporter.h \ - src/appDatabase/simplecrypt.h \ - src/jceData/Calendar/calendarDialog.h \ - src/jce_logger.h - -SOURCES += \ - main/CalendarTab/CalendarManager.cpp \ - main/CourseTab/coursestablemanager.cpp \ - main/LoginTab/loginhandler.cpp \ - main/main.cpp \ - main/mainscreen.cpp \ - src/appDatabase/savedata.cpp \ - src/jceConnection/jcesslclient.cpp \ - src/jceData/Calendar/calendarPage.cpp \ - src/jceData/Grades/gradeCourse.cpp \ - src/jceData/Grades/gradePage.cpp \ - src/jceData/page.cpp \ - src/jceSettings/jcelogin.cpp \ - src/jceSettings/user.cpp \ - src/jceData/Calendar/calendarCourse.cpp \ - src/jceData/Calendar/calendarSchedule.cpp \ - src/jceData/CSV/csv_exporter.cpp \ - src/appDatabase/simplecrypt.cpp \ - src/jceData/Calendar/calendarDialog.cpp \ - src/jce_logger.cpp +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-31T19:49:42 +# +#------------------------------------------------- + +QT += core gui network widgets +TARGET = jceGrade +TEMPLATE = app +RC_FILE = appConfigure.rc +CONFIG += qt c++11 +CONFIG += console static + +TRANSLATIONS = jce_en.ts \ + jce_he.ts + +FORMS += \ + main/mainscreen.ui \ + src/jceData/Calendar/calendarDialog.ui + +OTHER_FILES += + +RESOURCES += \ + resources/connectionstatus.qrc + +HEADERS += \ + main/CalendarTab/CalendarManager.h \ + main/CourseTab/coursestablemanager.h \ + main/LoginTab/loginhandler.h \ + main/mainscreen.h \ + src/appDatabase/savedata.h \ + src/jceConnection/jcesslclient.h \ + src/jceData/Calendar/calendarPage.h \ + src/jceData/Grades/gradeCourse.h \ + src/jceData/Grades/gradePage.h \ + src/jceData/course.h \ + src/jceData/page.h \ + src/jceSettings/jcelogin.h \ + src/jceSettings/jceLoginHtmlScripts.h \ + src/jceSettings/user.h \ + src/jceData/Calendar/calendarCourse.h \ + src/jceData/Calendar/calendarSchedule.h \ + src/jceData/CSV/csv_exporter.h \ + src/appDatabase/simplecrypt.h \ + src/jceData/Calendar/calendarDialog.h \ + src/jce_logger.h + +SOURCES += \ + main/CalendarTab/CalendarManager.cpp \ + main/CourseTab/coursestablemanager.cpp \ + main/LoginTab/loginhandler.cpp \ + main/main.cpp \ + main/mainscreen.cpp \ + src/appDatabase/savedata.cpp \ + src/jceConnection/jcesslclient.cpp \ + src/jceData/Calendar/calendarPage.cpp \ + src/jceData/Grades/gradeCourse.cpp \ + src/jceData/Grades/gradePage.cpp \ + src/jceData/page.cpp \ + src/jceSettings/jcelogin.cpp \ + src/jceSettings/user.cpp \ + src/jceData/Calendar/calendarCourse.cpp \ + src/jceData/Calendar/calendarSchedule.cpp \ + src/jceData/CSV/csv_exporter.cpp \ + src/appDatabase/simplecrypt.cpp \ + src/jceData/Calendar/calendarDialog.cpp \ + src/jce_logger.cpp diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index c082097..cd0eb14 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -8,7 +8,6 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr //this->setFixedSize(this->size()); //main not resizeable //Login Tab - QPixmap iconPix; iconPix.load(":/icons/iconX.png"); ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); ui->labelUsrInputStatus->setVisible(false); @@ -25,7 +24,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr ui->statusBar->addPermanentWidget(statusLabel,1); setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); - //Course, Setting, Calendar Tab + //Course, Calendar Tab calendarSchedule * calendarSchedulePtr = new calendarSchedule(); ui->calendarGridLayoutMain->addWidget(calendarSchedulePtr); ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); @@ -45,11 +44,9 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr ui->keepLogin->setChecked(true); } - //Local Check and ui setting. + //language checkLocale(); - - } MainScreen::~MainScreen() @@ -60,13 +57,12 @@ MainScreen::~MainScreen() delete courseTableMgr; delete userLoginSetting; delete loginHandel; - delete ui; delete data; + delete ui; } //EVENTS ON STATUS BAR void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription) { - QPixmap iconPix; switch (statusDescription) { case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: diff --git a/main/mainscreen.h b/main/mainscreen.h index 7f15462..02c60ba 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -81,14 +81,15 @@ private: QLabel *ButtomStatusLabel; QLabel *statusLabel; + QPixmap iconPix; user *userLoginSetting; SaveData *data; + CalendarManager * calendar; coursesTableManager *courseTableMgr; - loginHandler *loginHandel; - bool calendarLoaded; + loginHandler *loginHandel; }; diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index d2149fe..2b2bb89 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -152,7 +152,7 @@ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM description.append("\n"); description.append(" ב"); description.append(room); - description.append("\n Created with JCE Manager. \" "); + description.append("\n Created with JCE Manager.\""); //Create the Fucking Line //Header: Subject,Start Date,Start Time,End Date,End Time,Description,Location diff --git a/src/jce_logger.cpp b/src/jce_logger.cpp index 829b5e2..41e3f6a 100644 --- a/src/jce_logger.cpp +++ b/src/jce_logger.cpp @@ -1,46 +1,46 @@ -#include "jce_logger.h" - -/* - * This Static method will help parsing our debug messages to a readable Log file - * - * timestamp - Message type - message - * - * Message types cam be: - * - * - DEBUG - * - WARNING - * - CRITICAL - * - FATAL - * - * Logs stored in a log file. File name is Stored in the Macro in Header file - */ -void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) -{ - Q_UNUSED(context); - - QString dt = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss"); - QString txt = QString("%1\t").arg(dt); - - switch (type) - { - case QtDebugMsg: - txt += QString("DEBUG \t\t %1").arg(msg); - break; - case QtWarningMsg: - txt += QString("WARNING \t %1").arg(msg); - break; - case QtCriticalMsg: - txt += QString("CRITICAL \t %1").arg(msg); - break; - case QtFatalMsg: - txt += QString("FATAL \t\t %1").arg(msg); - abort(); - break; - } - - QFile outFile(LOG_FILE_NAME); - outFile.open(QIODevice::WriteOnly | QIODevice::Append); - - QTextStream textStream(&outFile); - textStream << txt << endl; -} +#include "jce_logger.h" + +/* + * This Static method will help parsing our debug messages to a readable Log file + * + * timestamp - Message type - message + * + * Message types cam be: + * + * - DEBUG + * - WARNING + * - CRITICAL + * - FATAL + * + * Logs stored in a log file. File name is Stored in the Macro in Header file + */ +void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + Q_UNUSED(context); + + QString dt = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss"); + QString txt = QString("%1\t").arg(dt); + + switch (type) + { + case QtDebugMsg: + txt += QString("DEBUG \t\t %1").arg(msg); + break; + case QtWarningMsg: + txt += QString("WARNING \t %1").arg(msg); + break; + case QtCriticalMsg: + txt += QString("CRITICAL \t %1").arg(msg); + break; + case QtFatalMsg: + txt += QString("FATAL \t\t %1").arg(msg); + abort(); + break; + } + + QFile outFile(LOG_FILE_NAME); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + + QTextStream textStream(&outFile); + textStream << txt << endl; +} diff --git a/src/jce_logger.h b/src/jce_logger.h index 2414c04..b13e47d 100644 --- a/src/jce_logger.h +++ b/src/jce_logger.h @@ -1,19 +1,19 @@ -#ifndef JCE_LOGGER_H -#define JCE_LOGGER_H - -#include -#include -#include -#include -#include - -#define LOG_FILE_NAME "J_M_Log.log" - -class jce_logger -{ -public: - static void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); - -}; - -#endif // JCE_LOGGER_H +#ifndef JCE_LOGGER_H +#define JCE_LOGGER_H + +#include +#include +#include +#include +#include + +#define LOG_FILE_NAME "J_M_Log.log" + +class jce_logger +{ +public: + static void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); + +}; + +#endif // JCE_LOGGER_H From e029f9c61536151448dbe2c55b4d8ad6107ecce8 Mon Sep 17 00:00:00 2001 From: liranbg Date: Thu, 18 Sep 2014 03:34:49 +0300 Subject: [PATCH 04/12] add network checking. now we can handle network link errors --- main/mainscreen.cpp | 26 ++++----- src/jceConnection/jcesslclient.cpp | 91 +++++++++++++++++------------- src/jceConnection/jcesslclient.h | 11 ++-- src/jceSettings/jcelogin.cpp | 1 - 4 files changed, 72 insertions(+), 57 deletions(-) diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index cd0eb14..89c73bc 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -185,7 +185,9 @@ void MainScreen::on_ratesButton_clicked() int status = 0; if (loginHandel->isLoggedInFlag()) { - if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED) + if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(), + ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(), + ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED) { pageString = loginHandel->getCurrentPageContect(); courseTableMgr->setCoursesList(pageString); @@ -283,13 +285,13 @@ void MainScreen::on_actionCredits_triggered() QMessageBox::about(this, "About", tr("CREDITS-ROOL-UP1") + " v1.0

" + tr("CREDITS-ROOL-UP2")+"
GNU LESSER GENERAL PUBLIC LICENSE V2
" + tr("CREDITS-ROOL-UP3")+"
" - "jceAverageCalculator Repository" - "

"+tr("CREDITS-ROOL-UP4")+" Jce Connection

" + "jceAverageCalculator Repository" + "

"+tr("CREDITS-ROOL-UP4")+" Jce Connection

" +tr("DevBy")+":" - ""); + ""); } void MainScreen::on_actionExit_triggered() { @@ -301,13 +303,11 @@ void MainScreen::on_actionHow_To_triggered() "How To.." "
    " "
  • "+tr("HELP1")+"
  • " - "
  • "+tr("HELP2")+"
  • " - "
  • "+tr("HELP3")+"
  • " - "
  • "+tr("HELP4")+"
  • " - "
  • "+tr("HELP5")+"
  • " - "

    "+tr("HELP6")+ + "
  • "+tr("HELP2")+"
  • " + "
  • "+tr("HELP3")+"
  • " + "
  • "+tr("HELP4")+"
  • " + "
  • "+tr("HELP5")+"
  • " "
"); - } diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index bc28116..5e54774 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -1,18 +1,21 @@ #include "jcesslclient.h" + /** * @brief jceSSLClient::jceSSLClient Constructer, setting the signals */ -jceSSLClient::jceSSLClient() : flag(false), packet("") +jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf() { //setting signals connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError))); connect(this,SIGNAL(connected()),this,SLOT(setConnected())); connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted())); connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected())); + connect(&networkConf,SIGNAL(onlineStateChanged(bool)),this,SLOT(setOnlineState(bool))); //loop event will connect the server, and when it is connected, it will quit - but connection will be open - connect(this, SIGNAL(encrypted()), &loop, SLOT(quit())); - connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit())); + connect(this, SIGNAL(encrypted()), &loop, SLOT(quit())); + connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit())); + } @@ -51,37 +54,16 @@ bool jceSSLClient::makeConnect(QString server, int port) */ bool jceSSLClient::makeDiconnect() { - qDebug() << "jceSSLClient::makeDiconnect;"; + if (loop.isRunning()) - { - qWarning() << "jceSSLClient::makeDiconnect; Killing connection thread"; + { + qWarning() << Q_FUNC_INFO << "Killing connection thread"; loop.exit(); - } - if (state() == QAbstractSocket::SocketState::UnconnectedState) - { - qDebug() << "jceSSLClient::makeDiconnect; Disconnected with [UnconnectedState]"; - flag = false; } - else if (state() == QAbstractSocket::SocketState::ConnectedState) - { - qWarning() << "jceSSLClient::makeDiconnect; Disconnecting with [ConnectedState] "; - abort(); - if (state() != QAbstractSocket::SocketState::UnconnectedState) - { - qWarning() << "jceSSLClient::makeDiconnect; still open! recursion call to disconnect"; - abort();//still connected? ensure the disconnection - flag = makeDiconnect(); //recursion call! - } - flag = false; - } - else - { - qWarning() << "jceSSLClient::makeDiconnect; Disconnecting [else] "; - abort(); //ensure the disconnection - flag = false; - } - qDebug() << "jceSSLClient::makeDiconnect; disconnect return with " << flag; - return flag; + qDebug() << Q_FUNC_INFO << "emitting disconnected()"; + emit disconnected(); + return isConnected(); + } /** @@ -101,8 +83,17 @@ bool jceSSLClient::isConnected() } else if (state() == QAbstractSocket::SocketState::ConnectedState) { - flag = true; + if (this->networkConf.isOnline()) + flag = true; + else + { + this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); + flag = false; + } + } + if (!this->networkConf.isOnline()) //no link, ethernet\wifi + flag = false; return flag; } /** @@ -177,6 +168,21 @@ void jceSSLClient::readIt() packet.append(p); }while (p.size() > 0); +} + +void jceSSLClient::setOnlineState(bool isOnline) +{ + qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline; + if (isOnline) + { + this->makeConnect(); + + } + else + { + this->makeDiconnect(); + } + } /** * @brief jceSSLClient::setConnected called when signaled with connected, calling the encryption function @@ -186,10 +192,13 @@ void jceSSLClient::setConnected() waitForEncrypted(); } /** - * @brief jceSSLClient::setDisconnected called when signaled with disconnected, setting flag to false + * @brief jceSSLClient::setDisconnected closing socket, updating state and setting flag to false */ void jceSSLClient::setDisconnected() { + qDebug() << Q_FUNC_INFO << "DISCONNECTED"; + this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); + abort(); flag = false; } /** @@ -199,8 +208,7 @@ void jceSSLClient::setEncrypted() { setReadBufferSize(10000); setSocketOption(QAbstractSocket::KeepAliveOption,1); - if (state() == QAbstractSocket::SocketState::ConnectedState) - flag = true; + if (isConnected()); else { qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!"; @@ -226,6 +234,7 @@ void jceSSLClient::showIfErrorMsg() break; case QAbstractSocket::SocketError::RemoteHostClosedError: errorString = QObject::tr("RemoteHostClosedError"); + relevantError = true; break; case QAbstractSocket::SocketError::HostNotFoundError: @@ -240,8 +249,12 @@ void jceSSLClient::showIfErrorMsg() break; case QAbstractSocket::SocketError::SocketTimeoutError: errorString = QObject::tr("SocketTimeoutError"); - if (!isConnected()) + + if (state() == QAbstractSocket::SocketState::UnconnectedState) + { + relevantError = true; + } break; case QAbstractSocket::SocketError::DatagramTooLargeError: errorString = QObject::tr("DatagramTooLargeError"); @@ -315,8 +328,10 @@ void jceSSLClient::showIfErrorMsg() */ void jceSSLClient::checkErrors(QAbstractSocket::SocketError a) { - qWarning() << "jceSSLClient::checkErrors; Var Error: " << a; - qWarning() << "jceSSLClient::checkErrors; Error: " << this->errorString(); + qWarning() << Q_FUNC_INFO << "isOnline?: " << this->networkConf.isOnline(); + qWarning() << Q_FUNC_INFO << "state is: " << state(); + qWarning() << Q_FUNC_INFO << "Var Error: " << a; + qWarning() << Q_FUNC_INFO << "Error: " << errorString(); showIfErrorMsg(); } diff --git a/src/jceConnection/jcesslclient.h b/src/jceConnection/jcesslclient.h index bb8913d..3d61644 100644 --- a/src/jceConnection/jcesslclient.h +++ b/src/jceConnection/jcesslclient.h @@ -6,10 +6,9 @@ #include #include #include +#include -#include -#include -#define milisTimeOut 3500 +#define milisTimeOut 4000 class jceSSLClient : QSslSocket { @@ -17,11 +16,11 @@ class jceSSLClient : QSslSocket public: jceSSLClient(); - bool makeConnect(QString server, int port); + bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443); + bool makeDiconnect(); bool isConnected(); bool sendData(QString str); bool recieveData(QString &str, bool fast); - bool makeDiconnect(); void showIfErrorMsg(); private slots: @@ -30,12 +29,14 @@ private slots: void setEncrypted(); void setDisconnected(); void readIt(); + void setOnlineState(bool isOnline); private: bool flag; QString packet; QEventLoop loop; //handle the connection as thread + QNetworkConfigurationManager networkConf; //checking online }; diff --git a/src/jceSettings/jcelogin.cpp b/src/jceSettings/jcelogin.cpp index 7e5ccf0..76c9cf8 100644 --- a/src/jceSettings/jcelogin.cpp +++ b/src/jceSettings/jcelogin.cpp @@ -202,7 +202,6 @@ int jceLogin::getCalendar(int year, int semester) */ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester) { - std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl; if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester))))) { if (!(JceConnector->recieveData(*recieverPage,false))) From 9be57bfecfe18c6f73773c6491253d1b4c33bffe Mon Sep 17 00:00:00 2001 From: liranbg Date: Thu, 18 Sep 2014 05:18:33 +0300 Subject: [PATCH 05/12] attemp to fix the reconnecting issue. --- src/jceConnection/jcesslclient.cpp | 201 ++++++++++++++++------------- 1 file changed, 111 insertions(+), 90 deletions(-) diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index 5e54774..0e3eee3 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -14,7 +14,7 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf() //loop event will connect the server, and when it is connected, it will quit - but connection will be open connect(this, SIGNAL(encrypted()), &loop, SLOT(quit())); - connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit())); + connect(this, SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit())); } @@ -27,24 +27,18 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf() */ bool jceSSLClient::makeConnect(QString server, int port) { - qDebug() << "jceSSLClient::makeConnect; Making connection"; - if (isConnected()) + qDebug() << Q_FUNC_INFO << "Making connection"; + if (flag) { - qWarning() << "jceSSLClient::makeConnect; Was already connected. Aborting."; + qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()"; makeDiconnect(); } - if (isOpen()) - { - qWarning() << "jceSSLClient::makeConnect; IsO pen. Aborting."; - makeDiconnect(); - } - - qDebug() << "jceSSLClient::makeConnect; Connection to: " << server << "On Port: " << 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 - qDebug() << "jceSSLClient::makeConnect; returning the connection status: " << isConnected(); + qDebug() << Q_FUNC_INFO << "returning the connection status: " << isConnected(); return isConnected(); } @@ -54,7 +48,7 @@ bool jceSSLClient::makeConnect(QString server, int port) */ bool jceSSLClient::makeDiconnect() { - + this->disconnectFromHost(); if (loop.isRunning()) { qWarning() << Q_FUNC_INFO << "Killing connection thread"; @@ -62,7 +56,7 @@ bool jceSSLClient::makeDiconnect() } qDebug() << Q_FUNC_INFO << "emitting disconnected()"; emit disconnected(); - return isConnected(); + return (!isConnected()); } @@ -110,7 +104,7 @@ bool jceSSLClient::sendData(QString str) if (waitForBytesWritten()) sendDataFlag = true; } - qDebug() << "jceSSLClient::sendData; Sending Data status is: " << sendDataFlag; + qDebug() << Q_FUNC_INFO << "Sending Data status is: " << sendDataFlag; return sendDataFlag; } /** @@ -121,7 +115,7 @@ bool jceSSLClient::sendData(QString str) */ bool jceSSLClient::recieveData(QString &str, bool fast) { - qDebug() << "jceSSLClient::recieveData Data receiving!"; + qDebug() << Q_FUNC_INFO << "Data receiving!"; packet = ""; bool sflag = false; @@ -149,10 +143,10 @@ bool jceSSLClient::recieveData(QString &str, bool fast) } } str = packet; - qDebug() << "jceSSLClient::recieveData received bytes: " << str.length() ; + qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ; if (str.length() > 0) sflag = true; - qDebug() << "jceSSLClient::recieveData return with flag: " << sflag; + qDebug() << Q_FUNC_INFO << "return with flag: " << sflag; return sflag; } @@ -175,11 +169,13 @@ void jceSSLClient::setOnlineState(bool isOnline) qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline; if (isOnline) { - this->makeConnect(); + if (this->makeConnect()) + qDebug() << Q_FUNC_INFO << "reconnected"; } else { + setSocketState(QAbstractSocket::SocketState::UnconnectedState); this->makeDiconnect(); } @@ -198,7 +194,6 @@ void jceSSLClient::setDisconnected() { qDebug() << Q_FUNC_INFO << "DISCONNECTED"; this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); - abort(); flag = false; } /** @@ -228,110 +223,136 @@ void jceSSLClient::showIfErrorMsg() bool relevantError = false; switch (enumError) { - case QAbstractSocket::SocketError::ConnectionRefusedError: + case QAbstractSocket::SocketError::ConnectionRefusedError: /**/ errorString = QObject::tr("ConnectionRefusedError"); + //The connection was refused by the peer (or timed out). relevantError = true; break; - case QAbstractSocket::SocketError::RemoteHostClosedError: + case QAbstractSocket::SocketError::RemoteHostClosedError: /**/ errorString = QObject::tr("RemoteHostClosedError"); - - relevantError = true; - break; - case QAbstractSocket::SocketError::HostNotFoundError: - errorString = QObject::tr("HostNotFoundError"); - relevantError = true; - break; - case QAbstractSocket::SocketError::SocketAccessError: - errorString = QObject::tr("SocketAccessError"); - break; - case QAbstractSocket::SocketError::SocketResourceError: - errorString = QObject::tr("SocketResourceError"); - break; - case QAbstractSocket::SocketError::SocketTimeoutError: - errorString = QObject::tr("SocketTimeoutError"); - - if (state() == QAbstractSocket::SocketState::UnconnectedState) + //The remote host closed the connection + if (isConnected()) //we can reconnect { + qDebug() << Q_FUNC_INFO << "trying to reconnect"; + flag = false; + this->disconnectFromHost(); + qDebug() << Q_FUNC_INFO << "we disconnected."; + if (makeConnect()) + qDebug() << Q_FUNC_INFO << "RECONNECTED"; - relevantError = true; } + else + relevantError = true; break; - case QAbstractSocket::SocketError::DatagramTooLargeError: + 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 + 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 (isConnected()) //we can reconnect + { + makeConnect(); + } + else + relevantError = true; + relevantError = true; + break; + case QAbstractSocket::SocketError::SslHandshakeFailedError: /**/ + errorString = QObject::tr("SslHandshakeFailedError"); + relevantError = true; + break; + case QAbstractSocket::SocketError::SslInternalError: /**/ + errorString = QObject::tr("SslInternalError"); + relevantError = true; + break; + case QAbstractSocket::SocketError::SslInvalidUserDataError: /**/ + errorString = QObject::tr("SslInvalidUserDataError"); + relevantError = true; + break; + case QAbstractSocket::SocketError::DatagramTooLargeError: //not relevant to us errorString = QObject::tr("DatagramTooLargeError"); break; - case QAbstractSocket::SocketError::NetworkError: - errorString = QObject::tr("NetworkError"); - relevantError = true; + case QAbstractSocket::SocketError::SocketResourceError: //not relevant to us break; - case QAbstractSocket::SocketError::AddressInUseError: - errorString = QObject::tr("AddressInUseError"); - break; - case QAbstractSocket::SocketError::SocketAddressNotAvailableError: - errorString = QObject::tr("SocketAddressNotAvailableError"); - break; - case QAbstractSocket::SocketError::UnsupportedSocketOperationError: - errorString = QObject::tr("UnsupportedSocketOperationError"); - break; - case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError: - errorString = QObject::tr("ProxyAuthenticationRequiredError"); - break; - case QAbstractSocket::SocketError::SslHandshakeFailedError: - errorString = QObject::tr("SslHandshakeFailedError"); - break; - case QAbstractSocket::SocketError::ProxyConnectionRefusedError: - errorString = QObject::tr("ProxyConnectionRefusedError"); - break; - case QAbstractSocket::SocketError::UnfinishedSocketOperationError: - errorString = QObject::tr("UnfinishedSocketOperationError"); - break; - case QAbstractSocket::SocketError::ProxyConnectionClosedError: - errorString = QObject::tr("ProxyConnectionClosedError"); - break; - case QAbstractSocket::SocketError::ProxyConnectionTimeoutError: - errorString = QObject::tr("ProxyConnectionTimeoutError"); - break; - case QAbstractSocket::SocketError::ProxyNotFoundError: - errorString = QObject::tr("ProxyNotFoundError"); - break; - case QAbstractSocket::SocketError::ProxyProtocolError: - errorString = QObject::tr("ProxyProtocolError"); - break; - case QAbstractSocket::SocketError::OperationError: + case QAbstractSocket::SocketError::OperationError: //not relevant, except for debug errorString = QObject::tr("OperationError"); break; - case QAbstractSocket::SocketError::SslInternalError: - errorString = QObject::tr("SslInternalError"); + case QAbstractSocket::SocketError::AddressInUseError: //not relevant to us + errorString = QObject::tr("AddressInUseError"); break; - case QAbstractSocket::SocketError::SslInvalidUserDataError: - errorString = QObject::tr("SslInvalidUserDataError"); + case QAbstractSocket::SocketError::SocketAddressNotAvailableError: //not relevant to us + errorString = QObject::tr("SocketAddressNotAvailableError"); break; - case QAbstractSocket::SocketError::TemporaryError: + case QAbstractSocket::SocketError::UnsupportedSocketOperationError: //for very old computers, not relevant to us + errorString = QObject::tr("UnsupportedSocketOperationError"); + break; + case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError: //not relevant to us + errorString = QObject::tr("ProxyAuthenticationRequiredError"); + break; + case QAbstractSocket::SocketError::ProxyConnectionRefusedError: //not relevant to us + errorString = QObject::tr("ProxyConnectionRefusedError"); + break; + case QAbstractSocket::SocketError::UnfinishedSocketOperationError: //not relevant to us + errorString = QObject::tr("UnfinishedSocketOperationError"); + break; + case QAbstractSocket::SocketError::ProxyConnectionClosedError: //not relevant to us + errorString = QObject::tr("ProxyConnectionClosedError"); + break; + case QAbstractSocket::SocketError::ProxyConnectionTimeoutError: //not relevant to us + errorString = QObject::tr("ProxyConnectionTimeoutError"); + break; + case QAbstractSocket::SocketError::ProxyNotFoundError: //not relevant to us + errorString = QObject::tr("ProxyNotFoundError"); + break; + case QAbstractSocket::SocketError::ProxyProtocolError: //not relevant to us + errorString = QObject::tr("ProxyProtocolError"); + break; + case QAbstractSocket::SocketError::TemporaryError: //not relevant to us errorString = QObject::tr("TemporaryError"); break; - case QAbstractSocket::SocketError::UnknownSocketError: + case QAbstractSocket::SocketError::UnknownSocketError: //not relevant, except for debug errorString = QObject::tr("UnknownSocketError"); relevantError = true; break; } if (relevantError) //informative string to be shown { - qDebug() << "jceSSLClient::showIfErrorMsg(); relevant error. msgbox popped"; + qDebug() << Q_FUNC_INFO << "relevant error."; msgBox.setIcon(QMessageBox::Warning); msgBox.setText(errorString); msgBox.exec(); } - } + + /** * @brief jceSSLClient::checkErrors this function exctuing when socket error has occured * @param a includes the error enum from QAbstractSocket::SocketError enum list */ void jceSSLClient::checkErrors(QAbstractSocket::SocketError a) { - qWarning() << Q_FUNC_INFO << "isOnline?: " << this->networkConf.isOnline(); - qWarning() << Q_FUNC_INFO << "state is: " << state(); - qWarning() << Q_FUNC_INFO << "Var Error: " << a; - qWarning() << Q_FUNC_INFO << "Error: " << errorString(); + //ignore this stupid error + if (!((isConnected()) && (a == QAbstractSocket::SocketError::SocketTimeoutError))) + { + qWarning() << Q_FUNC_INFO << "isOnline?: " << this->networkConf.isOnline(); + qWarning() << Q_FUNC_INFO << "state is: " << state(); + qWarning() << Q_FUNC_INFO << "Var Error: " << a; + qWarning() << Q_FUNC_INFO << "Error: " << errorString(); + } showIfErrorMsg(); } From ac0973cf1188afa956a0f08178dd8770e6a2e1ac Mon Sep 17 00:00:00 2001 From: liranbg Date: Thu, 18 Sep 2014 06:18:49 +0300 Subject: [PATCH 06/12] reconnected is working! just need to add the validations steps and we are good to go --- src/jceConnection/jcesslclient.cpp | 62 +++++++++++++++--------------- src/jceConnection/jcesslclient.h | 9 ++++- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index 0e3eee3..81d756f 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -3,7 +3,7 @@ /** * @brief jceSSLClient::jceSSLClient Constructer, setting the signals */ -jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf() +jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf(), reConnection(false) { //setting signals connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError))); @@ -16,7 +16,6 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf() connect(this, SIGNAL(encrypted()), &loop, SLOT(quit())); connect(this, SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit())); - } /** @@ -28,7 +27,7 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf() bool jceSSLClient::makeConnect(QString server, int port) { qDebug() << Q_FUNC_INFO << "Making connection"; - if (flag) + if (isConnected()) { qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()"; makeDiconnect(); @@ -48,14 +47,14 @@ bool jceSSLClient::makeConnect(QString server, int port) */ bool jceSSLClient::makeDiconnect() { - this->disconnectFromHost(); if (loop.isRunning()) { qWarning() << Q_FUNC_INFO << "Killing connection thread"; loop.exit(); } - qDebug() << Q_FUNC_INFO << "emitting disconnected()"; - emit disconnected(); + qDebug() << Q_FUNC_INFO << "disconnecting from host and emitting disconnected()"; + this->disconnectFromHost(); //emits disconnected > setDisconnected + setSocketState(QAbstractSocket::SocketState::UnconnectedState); return (!isConnected()); } @@ -66,29 +65,30 @@ bool jceSSLClient::makeDiconnect() */ bool jceSSLClient::isConnected() { + bool tempFlag; //checking state before returning flag! if (state() == QAbstractSocket::SocketState::UnconnectedState) { - flag = false; + tempFlag = false; } else if (state() == QAbstractSocket::SocketState::ClosingState) { - flag = false; + tempFlag = false; } else if (state() == QAbstractSocket::SocketState::ConnectedState) { if (this->networkConf.isOnline()) - flag = true; + tempFlag = true; else { this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); - flag = false; + tempFlag = false; } } if (!this->networkConf.isOnline()) //no link, ethernet\wifi - flag = false; - return flag; + tempFlag = false; + return ((flag) && (tempFlag)); } /** * @brief jceSSLClient::sendData - given string, send it to server @@ -167,16 +167,16 @@ void jceSSLClient::readIt() void jceSSLClient::setOnlineState(bool isOnline) { qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline; - if (isOnline) + if (isOnline) //to be added later { - if (this->makeConnect()) - qDebug() << Q_FUNC_INFO << "reconnected"; - + //we can add here auto reconnect if wifi\ethernet link has appear + //will be added next version } else { - setSocketState(QAbstractSocket::SocketState::UnconnectedState); + //abort() ? this->makeDiconnect(); + emit noInternetLink(); } } @@ -194,21 +194,27 @@ void jceSSLClient::setDisconnected() { qDebug() << Q_FUNC_INFO << "DISCONNECTED"; this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); + packet.clear(); flag = false; + if (reConnection) + makeConnect(); + } /** * @brief jceSSLClient::setEncrypted called when signaled with encrypted. setting the buffer size and keeping alive. */ void jceSSLClient::setEncrypted() { + qDebug() << Q_FUNC_INFO << "ENCRYPTED"; setReadBufferSize(10000); - setSocketOption(QAbstractSocket::KeepAliveOption,1); - if (isConnected()); - else + setSocketOption(QAbstractSocket::KeepAliveOption,true); + flag = true; + if (!isConnected()) { - qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!"; + qWarning() << Q_FUNC_INFO << "Connection status didnt change! reseting flag to false"; flag = false; } + } /** * @brief jceSSLClient::showIfErrorMsg message box to show the error occured according to socket @@ -231,15 +237,9 @@ void jceSSLClient::showIfErrorMsg() case QAbstractSocket::SocketError::RemoteHostClosedError: /**/ errorString = QObject::tr("RemoteHostClosedError"); //The remote host closed the connection - if (isConnected()) //we can reconnect + if (networkConf.isOnline()) //we can reconnect { - qDebug() << Q_FUNC_INFO << "trying to reconnect"; - flag = false; - this->disconnectFromHost(); - qDebug() << Q_FUNC_INFO << "we disconnected."; - if (makeConnect()) - qDebug() << Q_FUNC_INFO << "RECONNECTED"; - + reConnection = true; } else relevantError = true; @@ -263,13 +263,11 @@ void jceSSLClient::showIfErrorMsg() case QAbstractSocket::SocketError::NetworkError: /**/ errorString = QObject::tr("NetworkError"); //An error occurred with the network (e.g., the network cable was accidentally plugged out). - if (isConnected()) //we can reconnect + if (networkConf.isOnline()) //we can reconnect { - makeConnect(); } else relevantError = true; - relevantError = true; break; case QAbstractSocket::SocketError::SslHandshakeFailedError: /**/ errorString = QObject::tr("SslHandshakeFailedError"); diff --git a/src/jceConnection/jcesslclient.h b/src/jceConnection/jcesslclient.h index 3d61644..8b8d0ef 100644 --- a/src/jceConnection/jcesslclient.h +++ b/src/jceConnection/jcesslclient.h @@ -23,6 +23,11 @@ public: bool recieveData(QString &str, bool fast); void showIfErrorMsg(); +signals: + void serverDisconnectedbyRemote(); + void noInternetLink(); + void socketDisconnected(); + private slots: void checkErrors(QAbstractSocket::SocketError a); void setConnected(); @@ -32,11 +37,11 @@ private slots: void setOnlineState(bool isOnline); private: - bool flag; QString packet; QEventLoop loop; //handle the connection as thread - QNetworkConfigurationManager networkConf; //checking online + QNetworkConfigurationManager networkConf; //checking if online + bool reConnection; //used for remote host disconnecting }; From 8fa723a162844face2488d6cfc9c0fcb197c821f Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Thu, 18 Sep 2014 15:24:05 +0300 Subject: [PATCH 07/12] Added UTF-8 codec to csv file. fix #14 --- src/jceData/CSV/csv_exporter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index b712ad8..e466b7e 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -44,7 +44,9 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca return false; } - QTextStream out(&file); + QTextStream out(&file); //The output streem. + out.setCodec("UTF-8"); //Unicode 8 + out << CSV_CALENDAR_HEADER << "\n"; // macro in header file for (calendarCourse *coursePtr: *(calSched->getCourses())) //main loop - running though all courses From bf0c2574def05578585c2f76daea0f9ec80b6c13 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Thu, 18 Sep 2014 15:27:48 +0300 Subject: [PATCH 08/12] Cleaning after merge --- src/jceData/CSV/csv_exporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index 615094b..8bf4a3a 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -68,7 +68,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca QString name = coursePtr->getName(); QString room = coursePtr->getRoom(); - QDate currentDate = cal->getStartDate(); // currentDate will iterate thou the semester + QDate currentDate = cal->getStartDate(); // currentDate will iterate throuh the semester currentDate = currentDate.addDays(day-1); //selecting the REAL starting day of that course From 32e4272f83137e8cad185923fc69f058b897cfad Mon Sep 17 00:00:00 2001 From: liranbg Date: Sun, 21 Sep 2014 13:31:26 +0300 Subject: [PATCH 09/12] server disconnection bug 1 --- src/jceConnection/jcesslclient.cpp | 17 +- src/jceConnection/jcesslclient.h | 2 +- src/jceSettings/jcelogin.cpp | 288 +++++++++++++++-------------- src/jceSettings/jcelogin.h | 14 +- 4 files changed, 178 insertions(+), 143 deletions(-) diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index 81d756f..a4e2ceb 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -26,18 +26,31 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf(), reConnect */ bool jceSSLClient::makeConnect(QString server, int port) { - qDebug() << Q_FUNC_INFO << "Making connection"; + if (reConnection) //reset reconnectiong flag + { + qDebug() << Q_FUNC_INFO << "Making Reconnection"; + } + else + qDebug() << Q_FUNC_INFO << "Making Connection"; + if (isConnected()) { 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); loop.exec(); //starting connection, waiting to encryption and then it ends qDebug() << Q_FUNC_INFO << "returning the connection status: " << isConnected(); + if (reConnection) + { + reConnection = false; + emit serverDisconnectedbyRemote(); + } return isConnected(); } @@ -205,7 +218,7 @@ void jceSSLClient::setDisconnected() */ void jceSSLClient::setEncrypted() { - qDebug() << Q_FUNC_INFO << "ENCRYPTED"; + qDebug() << Q_FUNC_INFO << "ENCRYPTED"; setReadBufferSize(10000); setSocketOption(QAbstractSocket::KeepAliveOption,true); flag = true; diff --git a/src/jceConnection/jcesslclient.h b/src/jceConnection/jcesslclient.h index 8b8d0ef..f67b2ac 100644 --- a/src/jceConnection/jcesslclient.h +++ b/src/jceConnection/jcesslclient.h @@ -10,7 +10,7 @@ #define milisTimeOut 4000 -class jceSSLClient : QSslSocket +class jceSSLClient : public QSslSocket { Q_OBJECT public: diff --git a/src/jceSettings/jcelogin.cpp b/src/jceSettings/jcelogin.cpp index 76c9cf8..255c4a1 100644 --- a/src/jceSettings/jcelogin.cpp +++ b/src/jceSettings/jcelogin.cpp @@ -4,20 +4,21 @@ * @brief jceLogin::jceLogin * @param username pointer to allocated user settings */ -jceLogin::jceLogin(user * username) +jceLogin::jceLogin(user* username) { - this->recieverPage = new QString(); - this->jceA = username; - this->JceConnector = new jceSSLClient(); + this->recieverPage = new QString(); + this->jceA = username; + this->JceConnector = new jceSSLClient(); + JceConnector->connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); } jceLogin::~jceLogin() { - this->jceA = NULL; - delete recieverPage; - delete JceConnector; - JceConnector = NULL; - recieverPage = NULL; + this->jceA = NULL; + delete recieverPage; + delete JceConnector; + JceConnector = NULL; + recieverPage = NULL; } /** * @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it. @@ -25,69 +26,69 @@ jceLogin::~jceLogin() */ void jceLogin::makeConnection() throw (jceStatus) { - qDebug() << "jceLogin::makeConnection(); connection to be make"; + qDebug() << "jceLogin::makeConnection(); connection to be make"; - if (this->recieverPage == NULL) - this->recieverPage = new QString(); + if (this->recieverPage == NULL) + this->recieverPage = new QString(); - if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection - throw jceStatus::ERROR_ON_OPEN_SOCKET; + if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection + throw jceStatus::ERROR_ON_OPEN_SOCKET; - int returnMode; //gets status according to called function of validation step - jceStatus status = jceStatus::JCE_NOT_CONNECTED; + int returnMode; //gets status according to called function of validation step + jceStatus status = jceStatus::JCE_NOT_CONNECTED; - returnMode = checkConnection(); //checking socket status. is connected? + returnMode = checkConnection(); //checking socket status. is connected? - if (returnMode == true) //connected to host + if (returnMode == true) //connected to host { - returnMode = makeFirstVisit(); - if (returnMode == true) //requst and send first validation + returnMode = makeFirstVisit(); + if (returnMode == true) //requst and send first validation { - status = jceStatus::JCE_START_VALIDATING_PROGRESS; - returnMode = checkValidation(); - if (returnMode == true) //check if username and password are matching + status = jceStatus::JCE_START_VALIDATING_PROGRESS; + returnMode = checkValidation(); + if (returnMode == true) //check if username and password are matching { - status = jceStatus::JCE_VALIDATION_PASSED; - returnMode = makeSecondVisit(); - if (returnMode == true) //siging in the website + status = jceStatus::JCE_VALIDATION_PASSED; + returnMode = makeSecondVisit(); + if (returnMode == true) //siging in the website { - qDebug() << "jceLogin::makeConnection(); Signed in succeesfully"; - status = jceStatus::JCE_YOU_ARE_IN; - setLoginFlag(true); + qDebug() << "jceLogin::makeConnection(); Signed in succeesfully"; + status = jceStatus::JCE_YOU_ARE_IN; + setLoginFlag(true); } - else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) + else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) { - status = jceLogin::ERROR_ON_GETTING_INFO; + status = jceLogin::ERROR_ON_GETTING_INFO; } - else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) + else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) { - status = jceLogin::ERROR_ON_SEND_REQUEST; + status = jceLogin::ERROR_ON_SEND_REQUEST; } - else - status = jceStatus::ERROR_ON_VALIDATION; + else + status = jceStatus::ERROR_ON_VALIDATION; } - else - status = jceStatus::ERROR_ON_VALIDATION; + else + status = jceStatus::ERROR_ON_VALIDATION; } - else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) + else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) { - status = jceLogin::ERROR_ON_GETTING_INFO; + status = jceLogin::ERROR_ON_GETTING_INFO; } - else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) + else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) { - status = jceLogin::ERROR_ON_SEND_REQUEST; + status = jceLogin::ERROR_ON_SEND_REQUEST; } - else - status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; + else + status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; } - else - status = jceStatus::JCE_NOT_CONNECTED; + else + status = jceStatus::JCE_NOT_CONNECTED; - //we throw status even if we are IN! - qDebug() << "jceLogin::makeConnection(); throw status: " << status; - throw status; + //we throw status even if we are IN! + qDebug() << "jceLogin::makeConnection(); throw status: " << status; + throw status; } /** @@ -96,10 +97,10 @@ void jceLogin::makeConnection() throw (jceStatus) */ bool jceLogin::checkConnection() const { - if (JceConnector->isConnected()) - return true; + if (JceConnector->isConnected()) + return true; - return false; + return false; } /** * @brief jceLogin::reConnect @@ -108,29 +109,29 @@ bool jceLogin::checkConnection() const */ void jceLogin::reConnect() throw (jceStatus) { - closeAll(); - if (this->JceConnector != NULL) - delete JceConnector; - this->recieverPage = new QString(); - this->JceConnector = new jceSSLClient(); + closeAll(); + if (this->JceConnector != NULL) + delete JceConnector; + this->recieverPage = new QString(); + this->JceConnector = new jceSSLClient(); - try - { - makeConnection(); - } - catch (jceLogin::jceStatus &a) - { - throw a; - } + try + { + makeConnection(); + } + catch (jceLogin::jceStatus &a) + { + throw a; + } } /** * @brief jceLogin::closeAll */ void jceLogin::closeAll() { - JceConnector->makeDiconnect(); - delete recieverPage; - recieverPage = NULL; + JceConnector->makeDiconnect(); + delete recieverPage; + recieverPage = NULL; } /** @@ -139,17 +140,17 @@ void jceLogin::closeAll() */ int jceLogin::makeFirstVisit() { - QString usr = jceA->getUsername(); - QString psw = jceA->getPassword(); - if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) + QString usr = jceA->getUsername(); + QString psw = jceA->getPassword(); + if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) { - if (!JceConnector->recieveData(*recieverPage,true)) - return jceLogin::ERROR_ON_GETTING_INFO; + if (!JceConnector->recieveData(*recieverPage,true)) + return jceLogin::ERROR_ON_GETTING_INFO; } - else - return jceLogin::ERROR_ON_SEND_REQUEST; + else + return jceLogin::ERROR_ON_SEND_REQUEST; - return true; + return true; } /** * @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login @@ -157,19 +158,19 @@ int jceLogin::makeFirstVisit() */ int jceLogin::makeSecondVisit() { - QString usrid=jceA->getUserID(); - QString pswid=jceA->getHashedPassword(); - if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) + QString usrid=jceA->getUserID(); + QString pswid=jceA->getHashedPassword(); + if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) { - if (!(JceConnector->recieveData(*recieverPage,true))) - return jceLogin::ERROR_ON_GETTING_INFO; + if (!(JceConnector->recieveData(*recieverPage,true))) + return jceLogin::ERROR_ON_GETTING_INFO; - return true; + return true; } - else - return jceLogin::ERROR_ON_SEND_REQUEST; + else + return jceLogin::ERROR_ON_SEND_REQUEST; - return true; + return true; } /** * @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server @@ -179,17 +180,17 @@ int jceLogin::makeSecondVisit() */ int jceLogin::getCalendar(int year, int semester) { - if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester))))) + if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester))))) { - if (!(JceConnector->recieveData(*recieverPage,false))) - return jceLogin::ERROR_ON_GETTING_GRADES; - else - return jceLogin::JCE_GRADE_PAGE_PASSED; + if (!(JceConnector->recieveData(*recieverPage,false))) + return jceLogin::ERROR_ON_GETTING_GRADES; + else + return jceLogin::JCE_GRADE_PAGE_PASSED; } - else - return jceLogin::ERROR_ON_SEND_REQUEST; + else + return jceLogin::ERROR_ON_SEND_REQUEST; - return true; + return true; } /** @@ -202,17 +203,17 @@ int jceLogin::getCalendar(int year, int semester) */ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester) { - if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester))))) + if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester))))) { - if (!(JceConnector->recieveData(*recieverPage,false))) - return jceLogin::ERROR_ON_GETTING_GRADES; - else - return jceLogin::JCE_GRADE_PAGE_PASSED; + if (!(JceConnector->recieveData(*recieverPage,false))) + return jceLogin::ERROR_ON_GETTING_GRADES; + else + return jceLogin::JCE_GRADE_PAGE_PASSED; } - else - return jceLogin::ERROR_ON_SEND_REQUEST; + else + return jceLogin::ERROR_ON_SEND_REQUEST; - return true; + return true; } /** @@ -222,43 +223,43 @@ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemest bool jceLogin::checkValidation() { - //finds the hashed password - QString constUserID_TAG = "value=\"-N"; - QString constHassID_TAG = "-A,-N"; - QString hasspass,hassid; - std::size_t hasspass_position1,hasspass_position2; - std::size_t id_position1,id_position2; + //finds the hashed password + QString constUserID_TAG = "value=\"-N"; + QString constHassID_TAG = "-A,-N"; + QString hasspass,hassid; + std::size_t hasspass_position1,hasspass_position2; + std::size_t id_position1,id_position2; - hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index - if (hasspass_position1 == std::string::npos) //didnt find the tag - return false; - else - hasspass_position1 += constHassID_TAG.length(); //skip the index of tag - hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1); - //finds the hass pass - if (hasspass_position2 != std::string::npos) //found the hasspass! storing it - hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1); - else - return false; - //finds the user id - id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index - if (id_position1 == std::string::npos) //didnt find the tag - return false; - else - id_position1 += constUserID_TAG.length(); //skip the index of tag - id_position2 = this->recieverPage->toStdString().find(",-A", id_position1); - if (id_position2 != std::string::npos) //found the hassid! storing it - hassid = recieverPage->mid(id_position1,id_position2-id_position1); - else - return false; + hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index + if (hasspass_position1 == std::string::npos) //didnt find the tag + return false; + else + hasspass_position1 += constHassID_TAG.length(); //skip the index of tag + hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1); + //finds the hass pass + if (hasspass_position2 != std::string::npos) //found the hasspass! storing it + hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1); + else + return false; + //finds the user id + id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index + if (id_position1 == std::string::npos) //didnt find the tag + return false; + else + id_position1 += constUserID_TAG.length(); //skip the index of tag + id_position2 = this->recieverPage->toStdString().find(",-A", id_position1); + if (id_position2 != std::string::npos) //found the hassid! storing it + hassid = recieverPage->mid(id_position1,id_position2-id_position1); + else + return false; - //setting user information with given data hassid and hasspass - jceA->setHashedPassword(hasspass); - jceA->setUserID(hassid); + //setting user information with given data hassid and hasspass + jceA->setHashedPassword(hasspass); + jceA->setUserID(hassid); - qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid; + qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid; - return true; + return true; } /** * @brief jceLogin::setLoginFlag @@ -266,7 +267,7 @@ bool jceLogin::checkValidation() */ void jceLogin::setLoginFlag(bool x) { - this->loginFlag = x; + this->loginFlag = x; } /** * @brief jceLogin::isLoginFlag checking if there is a connection, if true - > return if we signed in. otherwise, return not (not connected dough) @@ -274,9 +275,9 @@ void jceLogin::setLoginFlag(bool x) */ bool jceLogin::isLoginFlag() const { - if (checkConnection()) - return this->loginFlag; - return false; + if (checkConnection()) + return this->loginFlag; + return false; } /** @@ -285,5 +286,16 @@ bool jceLogin::isLoginFlag() const */ QString jceLogin::getPage() { - return *recieverPage; + return *recieverPage; +} + +void jceLogin::reValidation() +{ + qDebug() << Q_FUNC_INFO << "Revalidating user"; + if (makeFirstVisit()) + { + if (makeSecondVisit()) + qDebug() << Q_FUNC_INFO << "Validated"; + } + } diff --git a/src/jceSettings/jcelogin.h b/src/jceSettings/jcelogin.h index dee3572..f55d50e 100644 --- a/src/jceSettings/jcelogin.h +++ b/src/jceSettings/jcelogin.h @@ -5,11 +5,19 @@ #include "./src/jceSettings/user.h" #include "jceLoginHtmlScripts.h" +#include #include + class jceLogin { + + Q_OBJECT + public: + jceLogin() {} + jceLogin(user* username); + ~jceLogin(); enum jceStatus { JCE_NOT_CONNECTED, @@ -26,8 +34,7 @@ public: JCE_GRADE_PAGE_PASSED }; - jceLogin(user* username); - ~jceLogin(); + void makeConnection() throw (jceStatus); void reConnect() throw (jceStatus); @@ -41,6 +48,9 @@ public: QString getPage(); +private slots: + void reValidation(); + private: int makeFirstVisit(); From b4559f51820f811839bbc290088ca56c5891c949 Mon Sep 17 00:00:00 2001 From: liranbg Date: Sun, 21 Sep 2014 14:08:22 +0300 Subject: [PATCH 10/12] compiling error fix --- src/jceSettings/jcelogin.cpp | 2 +- src/jceSettings/jcelogin.h | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/jceSettings/jcelogin.cpp b/src/jceSettings/jcelogin.cpp index 255c4a1..145e926 100644 --- a/src/jceSettings/jcelogin.cpp +++ b/src/jceSettings/jcelogin.cpp @@ -9,7 +9,7 @@ jceLogin::jceLogin(user* username) this->recieverPage = new QString(); this->jceA = username; this->JceConnector = new jceSSLClient(); - JceConnector->connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); + QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); } jceLogin::~jceLogin() diff --git a/src/jceSettings/jcelogin.h b/src/jceSettings/jcelogin.h index f55d50e..df6a61c 100644 --- a/src/jceSettings/jcelogin.h +++ b/src/jceSettings/jcelogin.h @@ -9,11 +9,9 @@ #include -class jceLogin +class jceLogin : public QObject { - Q_OBJECT - public: jceLogin() {} jceLogin(user* username); From 68bd693dd8e2d8f1e7a0a90a339a4b8d45fb3082 Mon Sep 17 00:00:00 2001 From: liranbg Date: Mon, 22 Sep 2014 00:53:28 +0300 Subject: [PATCH 11/12] reconnecting fix --- src/jceConnection/jcesslclient.cpp | 4 ++-- src/jceSettings/jcelogin.cpp | 37 +++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index a4e2ceb..bdcc197 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -205,7 +205,7 @@ void jceSSLClient::setConnected() */ void jceSSLClient::setDisconnected() { - qDebug() << Q_FUNC_INFO << "DISCONNECTED"; + qDebug() << Q_FUNC_INFO << "connection has been DISCONNECTED"; this->setSocketState(QAbstractSocket::SocketState::UnconnectedState); packet.clear(); flag = false; @@ -218,7 +218,7 @@ void jceSSLClient::setDisconnected() */ void jceSSLClient::setEncrypted() { - qDebug() << Q_FUNC_INFO << "ENCRYPTED"; + qDebug() << Q_FUNC_INFO << "connection has been ENCRYPTED"; setReadBufferSize(10000); setSocketOption(QAbstractSocket::KeepAliveOption,true); flag = true; diff --git a/src/jceSettings/jcelogin.cpp b/src/jceSettings/jcelogin.cpp index 145e926..0447cd7 100644 --- a/src/jceSettings/jcelogin.cpp +++ b/src/jceSettings/jcelogin.cpp @@ -31,14 +31,15 @@ void jceLogin::makeConnection() throw (jceStatus) if (this->recieverPage == NULL) this->recieverPage = new QString(); - if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection - throw jceStatus::ERROR_ON_OPEN_SOCKET; - int returnMode; //gets status according to called function of validation step jceStatus status = jceStatus::JCE_NOT_CONNECTED; returnMode = checkConnection(); //checking socket status. is connected? + if (returnMode == false) + if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection + throw jceStatus::ERROR_ON_OPEN_SOCKET; + if (returnMode == true) //connected to host { returnMode = makeFirstVisit(); @@ -292,10 +293,34 @@ QString jceLogin::getPage() void jceLogin::reValidation() { qDebug() << Q_FUNC_INFO << "Revalidating user"; - if (makeFirstVisit()) + if (makeFirstVisit() == true) { - if (makeSecondVisit()) - qDebug() << Q_FUNC_INFO << "Validated"; + if (checkValidation()) + { + if (makeSecondVisit() == true) + qDebug() << Q_FUNC_INFO << "Validated"; + else + qWarning() << Q_FUNC_INFO << "Second visit finished with an error"; + } + else + qDebug() << Q_FUNC_INFO << "checking validation ended with an error"; } + else + { + qDebug() << Q_FUNC_INFO << "Couldnt Validate User"; + } + /* + delete recieverPage; + recieverPage = NULL; + if (this->JceConnector != NULL) + delete JceConnector; + this->recieverPage = new QString(); + this->JceConnector = new jceSSLClient(); + if (makeFirstVisit() == true) + { + if (checkValidation()) + { + if (makeSecondVisit() == true) + */ } From 256b9085a921cd41b7a1cc4ada8d27edda72fc75 Mon Sep 17 00:00:00 2001 From: liranbg Date: Mon, 22 Sep 2014 05:04:38 +0300 Subject: [PATCH 12/12] added relogin, reconnection, changed pointer allocation --- main/LoginTab/loginhandler.cpp | 250 +++++++++++++++++------------ main/LoginTab/loginhandler.h | 36 +++-- main/mainscreen.cpp | 171 ++++++-------------- main/mainscreen.h | 6 - main/mainscreen.ui | 2 +- src/jceConnection/jcesslclient.cpp | 11 +- src/jceSettings/jcelogin.cpp | 74 ++++----- src/jceSettings/jcelogin.h | 9 +- 8 files changed, 263 insertions(+), 296 deletions(-) diff --git a/main/LoginTab/loginhandler.cpp b/main/LoginTab/loginhandler.cpp index e1574f9..9d0d66a 100644 --- a/main/LoginTab/loginhandler.cpp +++ b/main/LoginTab/loginhandler.cpp @@ -1,143 +1,181 @@ #include "loginhandler.h" -loginHandler::loginHandler(user *ptr): logggedInFlag(false) +loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr): logggedInFlag(false) { - this->jceLog = new jceLogin(ptr); + this->loginButtonPtr = loginButtonPtr; + + //statusBar + statusBar = statusBarPtr; + iconButtomStatusLabel = new QLabel(); + statusBar->addPermanentWidget(iconButtomStatusLabel,0); + setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); + + //user settings + userPtr = ptr; + this->jceLog = new jceLogin(userPtr); + QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost())); } -void loginHandler::setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) +bool loginHandler::login(QString username,QString password) { - this->statusLabelPtr = statusLabelPtr; - this->pswdEditPtr = pswdEditPtr; - this->usrnmEditPtr = usrnmEditPtr; + qDebug() << Q_FUNC_INFO << "Login with username and password"; + if (isLoggedInFlag()) + { + qDebug() << Q_FUNC_INFO << "Loging out"; + logout(); + return false; + } + setIconConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); + + userPtr->setUsername(username); + userPtr->setPassword(password); + + if (makeConnection() == true) + { + setIconConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); + loginButtonPtr->setText(QObject::tr("Logout")); + return isLoggedInFlag(); + } + else + { + logout(); + return false; + } +} + +void loginHandler::logout() +{ + loginButtonPtr->setText(QObject::tr("Login")); + setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); + jceLog->closeAll(); + logggedInFlag = false; } bool loginHandler::makeConnection() { - if (this->jceLog == NULL) - return false; + if (this->jceLog == NULL) + return false; - try - { - jceLog->makeConnection(); - } - catch (jceLogin::jceStatus &a) - { - int status = (int)a; + int status = (int)jceLog->makeConnection(); switch (status) - { - case jceLogin::JCE_YOU_ARE_IN: - { - logggedInFlag = true; - return logggedInFlag; - break; - } - case jceLogin::ERROR_ON_VALIDATION: - { - popMessage(QObject::tr("Please Check Your Username & Password"),false); + { + case jceLogin::JCE_YOU_ARE_IN: + { + logggedInFlag = true; + return logggedInFlag; + } + case jceLogin::ERROR_ON_VALIDATION: + { + popMessage(QObject::tr("Please Check Your Username & Password"),false); + return false; + } + case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED: + { + popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes.")); + return false; + } + case jceLogin::ERROR_ON_OPEN_SOCKET: + { + popMessage(QObject::tr("Please Check Your Internet Connection.")); + return false; + } + case jceLogin::JCE_NOT_CONNECTED: + { + break; + } + case jceLogin::ERROR_ON_GETTING_INFO: + { + popMessage(QObject::tr("Receive Request Timeout.")); + return false; + } + case jceLogin::ERROR_ON_SEND_REQUEST: + { + popMessage(QObject::tr("Send Request Timeout.")); + return false; + } + } - usrnmEditPtr->setDisabled(false); - pswdEditPtr->setDisabled(false); - - pswdEditPtr->selectAll(); - pswdEditPtr->setFocus(); - return false; - } - case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED: - { - popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes.")); - jceLog->closeAll(); - return false; - } - case jceLogin::ERROR_ON_OPEN_SOCKET: - { - popMessage(QObject::tr("Please Check Your Internet Connection.")); - jceLog->closeAll(); - return false; - } - case jceLogin::JCE_NOT_CONNECTED: - { - jceLog->reConnect(); - /* - * Fix: need to add a prompte window to ask user whether he wants to reconnect or not - */ - break; - } - case jceLogin::ERROR_ON_GETTING_INFO: - { - popMessage(QObject::tr("Receive Request Timeout.")); - jceLog->closeAll(); - return false; - break; - } - case jceLogin::ERROR_ON_SEND_REQUEST: - { - popMessage(QObject::tr("Send Request Timeout.")); - jceLog->closeAll(); - return false; - break; - } - } - } - return false; + return false; } +void loginHandler::readyAfterConnectionLost() +{ + qWarning() << Q_FUNC_INFO; + setLoginFlag(false); + login(userPtr->getUsername(),userPtr->getPassword()); +} bool loginHandler::isLoggedInFlag() { - if (jceLog->isLoginFlag()) //checking connection and then if logged in - return this->logggedInFlag; - else - this->setLoginFlag(false); - return false; + if (jceLog->isLoginFlag()) //checking connection and then if logged in + return this->logggedInFlag; + else + this->setLoginFlag(false); + return false; } - void loginHandler::setLoginFlag(bool flag) { - this->logggedInFlag = flag; + this->logggedInFlag = flag; } - QString loginHandler::getCurrentPageContect() { - QTextEdit phrase; - if (isLoggedInFlag()) - phrase.setText(jceLog->getPage()); - else - throw jceLogin::ERROR_ON_GETTING_INFO; + QTextEdit phrase; + if (isLoggedInFlag()) + phrase.setText(jceLog->getPage()); + else + throw jceLogin::ERROR_ON_GETTING_INFO; - return phrase.toPlainText(); + return phrase.toPlainText(); } - -void loginHandler::makeDisconnectionRequest() -{ - jceLog->closeAll(); - this->logggedInFlag = false; -} - int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester) { - if (isLoggedInFlag()) - return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester); - else - return jceLogin::JCE_NOT_CONNECTED; + if (isLoggedInFlag()) + return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester); + else + return jceLogin::JCE_NOT_CONNECTED; } - int loginHandler::makeCalendarRequest(int year, int semester) { - if (isLoggedInFlag()) - return jceLog->getCalendar(year,semester); - else - return jceLogin::JCE_NOT_CONNECTED; + if (isLoggedInFlag()) + return jceLog->getCalendar(year,semester); + else + return jceLogin::JCE_NOT_CONNECTED; +} +void loginHandler::setIconConnectionStatus(jceLogin::jceStatus statusDescription) +{ + QPixmap iconPix; + switch (statusDescription) + { + case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: + iconPix.load(":/icons/blueStatusIcon.png"); + statusBar->showMessage(tr("Connecting...")); + break; + case jceLogin::jceStatus::JCE_YOU_ARE_IN: + iconPix.load(":/icons/greenStatusIcon.png"); + statusBar->showMessage(tr("Connected")); + break; + case jceLogin::jceStatus::JCE_NOT_CONNECTED: + iconPix.load(":/icons/redStatusIcon.png"); + statusBar->showMessage(tr("Disconnected")); + break; + default: + iconPix.load(":/icons/redStatusIcon.png"); + statusBar->showMessage(tr("Ready.")); + break; + } + iconButtomStatusLabel->setPixmap(iconPix); + + this->statusBar->repaint(); } void loginHandler::popMessage(QString message,bool addInfo) { - if (addInfo) - message.append(QObject::tr("\nIf this message appear without reason, please contact me at liranbg@gmail.com")); + if (addInfo) + message.append(QObject::tr("\nIf this message appear without reason, please contact me at liranbg@gmail.com")); - QMessageBox msgBox; - msgBox.setWindowTitle(QObject::tr("Error")); - msgBox.setText(message); - msgBox.exec(); - msgBox.setFocus(); + QMessageBox msgBox; + msgBox.setWindowTitle(QObject::tr("Error")); + msgBox.setText(message); + msgBox.exec(); + msgBox.setFocus(); } diff --git a/main/LoginTab/loginhandler.h b/main/LoginTab/loginhandler.h index b855dad..6debc9a 100644 --- a/main/LoginTab/loginhandler.h +++ b/main/LoginTab/loginhandler.h @@ -2,43 +2,55 @@ #define LOGINHANDLER_H #include #include -#include -#include #include +#include #include #include +#include +#include #include "./src/jceSettings/jcelogin.h" #include "./src/appDatabase/savedata.h" -class loginHandler +class loginHandler : public QObject { + Q_OBJECT public: - loginHandler(user *ptr); - void setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); + loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr); + ~loginHandler() + { + delete iconButtomStatusLabel; + delete jceLog; + } + + bool login(QString username,QString password); + void logout(); + void setIconConnectionStatus(jceLogin::jceStatus statusDescription); + bool makeConnection(); + bool isLoggedInFlag(); void setLoginFlag(bool flag); - QString getCurrentPageContect(); int makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester); int makeCalendarRequest(int year,int semester); - void makeDisconnectionRequest(); +private slots: + void readyAfterConnectionLost(); private: void popMessage(QString message, bool addInfo = true); bool logggedInFlag; - jceLogin *jceLog; - - QLabel *statusLabelPtr; - QLineEdit *pswdEditPtr; - QLineEdit *usrnmEditPtr; + jceLogin * jceLog; + user * userPtr; + QStatusBar *statusBar; + QLabel *iconButtomStatusLabel; + QPushButton *loginButtonPtr; }; diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 89c73bc..fb261e3 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -15,14 +15,10 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr ui->labelUsrInputStatus->setPixmap(iconPix); ui->labelPswInputStatus->setPixmap(iconPix); - //Status Bar + //StatusBar ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); - ButtomStatusLabel = new QLabel(this); - statusLabel = new QLabel(this); ui->statusBar->setMaximumSize(this->geometry().width(),STATUS_ICON_HEIGH); - ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); - ui->statusBar->addPermanentWidget(statusLabel,1); - setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); + ui->statusBar->showMessage(tr("Ready")); //Course, Calendar Tab calendarSchedule * calendarSchedulePtr = new calendarSchedule(); @@ -32,7 +28,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr //Pointer allocating this->userLoginSetting = new user("",""); this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); - this->loginHandel = new loginHandler(userLoginSetting); + this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton); this->calendar = new CalendarManager(calendarSchedulePtr); this->data = new SaveData(); @@ -48,11 +44,8 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr checkLocale(); } - MainScreen::~MainScreen() { - delete ButtomStatusLabel; - delete statusLabel; delete calendar; delete courseTableMgr; delete userLoginSetting; @@ -61,34 +54,48 @@ MainScreen::~MainScreen() delete ui; } //EVENTS ON STATUS BAR -void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription) -{ - switch (statusDescription) - { - case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: - iconPix.load(":/icons/blueStatusIcon.png"); - statusLabel->setText(tr("Connecting")); - break; - case jceLogin::jceStatus::JCE_YOU_ARE_IN: - iconPix.load(":/icons/greenStatusIcon.png"); - statusLabel->setText(tr("Connected")); - break; - default: - iconPix.load(":/icons/redStatusIcon.png"); - statusLabel->setText(tr("Disconnected")); - break; - } - ButtomStatusLabel->setPixmap(iconPix); - this->repaint(); -} //EVENTS ON LOGIN TAB void MainScreen::on_loginButton_clicked() { - if (loginHandel->isLoggedInFlag()) - uiSetDisconnectMode(); + qDebug() << Q_FUNC_INFO; + bool isSettingsOk = false; + if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) + { + if (ui->usrnmLineEdit->text().isEmpty()) + { + ui->labelUsrInputStatus->setVisible(true); + qDebug() << Q_FUNC_INFO << "username input is empty"; + } + 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 - uiSetConnectMode(); + { + isSettingsOk = true; + ui->labelUsrInputStatus->setVisible(false); + ui->labelPswInputStatus->setVisible(false); + } + + if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true) + { + ui->pswdLineEdit->setDisabled(true); + ui->usrnmLineEdit->setDisabled(true); + } + else + { + ui->pswdLineEdit->setDisabled(false); + ui->usrnmLineEdit->setDisabled(false); + + } } void MainScreen::on_keepLogin_clicked() { @@ -104,74 +111,7 @@ void MainScreen::on_usrnmLineEdit_editingFinished() { ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); } -void MainScreen::uiSetDisconnectMode() -{ - setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); - ui->usrnmLineEdit->setText(""); - ui->pswdLineEdit->setText(""); - ui->usrnmLineEdit->setEnabled(true); - ui->pswdLineEdit->setEnabled(true); - loginHandel->makeDisconnectionRequest(); - ui->loginButton->setText(tr("&Login")); - ui->getCalendarBtn->setDisabled(true); - ui->exportToCVSBtn->setDisabled(true); - ui->ratesButton->setDisabled(true); - return; -} -void MainScreen::uiSetConnectMode() -{ - QString username; - QString password; - if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) - { - if (ui->usrnmLineEdit->text().isEmpty()) - { - ui->labelUsrInputStatus->setVisible(true); - qDebug() << "error, username input is empty"; - } - else - ui->labelUsrInputStatus->setVisible(false); - if (ui->pswdLineEdit->text().isEmpty()) - { - ui->labelPswInputStatus->setVisible(true); - qDebug() << "error, password input is empty"; - } - else - ui->labelPswInputStatus->setVisible(false); - return; - } - else - { - ui->labelUsrInputStatus->setVisible(false); - ui->labelPswInputStatus->setVisible(false); - } - setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); - - username = ui->usrnmLineEdit->text(); - password = ui->pswdLineEdit->text(); - - ui->usrnmLineEdit->setDisabled(true); - ui->pswdLineEdit->setDisabled(true); - - userLoginSetting->setUsername(username); - userLoginSetting->setPassword(password); - - this->loginHandel->setPointers(statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit); - if (loginHandel->makeConnection() == true) - { - setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); - ui->loginButton->setText(tr("&Logout")); - ui->ratesButton->setEnabled(true); - ui->CoursesTab->setEnabled(true); - ui->exportToCVSBtn->setEnabled(true); - ui->getCalendarBtn->setEnabled(true); - } - else - { - uiSetDisconnectMode(); - } -} //EVENTS ON GPA TAB void MainScreen::on_ratesButton_clicked() { @@ -224,7 +164,6 @@ void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1) { ui->spinBoxCoursesFromYear->setValue(arg1); } - void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1) { ui->spinBoxCoursesToYear->setValue(arg1); @@ -278,20 +217,19 @@ void MainScreen::on_exportToCVSBtn_clicked() } } - //EVENTS ON MENU BAR void MainScreen::on_actionCredits_triggered() { QMessageBox::about(this, "About", tr("CREDITS-ROOL-UP1") + " v1.0

" + tr("CREDITS-ROOL-UP2")+"
GNU LESSER GENERAL PUBLIC LICENSE V2
" + tr("CREDITS-ROOL-UP3")+"
" - "jceAverageCalculator Repository" - "

"+tr("CREDITS-ROOL-UP4")+" Jce Connection

" + "jceAverageCalculator Repository" + "

"+tr("CREDITS-ROOL-UP4")+" Jce Connection

" +tr("DevBy")+":" - ""); + ""); } void MainScreen::on_actionExit_triggered() { @@ -303,16 +241,12 @@ void MainScreen::on_actionHow_To_triggered() "How To.." "
    " "
  • "+tr("HELP1")+"
  • " - "
  • "+tr("HELP2")+"
  • " - "
  • "+tr("HELP3")+"
  • " - "
  • "+tr("HELP4")+"
  • " - "
  • "+tr("HELP5")+"
  • " - "
"); + "
  • "+tr("HELP2")+"
  • " + "
  • "+tr("HELP3")+"
  • " + "
  • "+tr("HELP4")+"
  • " + "
  • "+tr("HELP5")+"
  • " + ""); } - - - - void MainScreen::on_actionHebrew_triggered() { if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked()) @@ -326,7 +260,6 @@ void MainScreen::on_actionHebrew_triggered() else ui->actionHebrew->setChecked(true); } - void MainScreen::on_actionEnglish_triggered() { if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked()) @@ -340,8 +273,6 @@ void MainScreen::on_actionEnglish_triggered() else ui->actionEnglish->setChecked(true); } - - void MainScreen::on_actionOS_Default_triggered() { if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked()) diff --git a/main/mainscreen.h b/main/mainscreen.h index 02c60ba..9c641b6 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -70,19 +70,13 @@ private slots: private: - void uiSetDisconnectMode(); - void uiSetConnectMode(); - void setLabelConnectionStatus(jceLogin::jceStatus statusDescription); void checkLocale(); bool checkIfValidDates(); Ui::MainScreen *ui; - QLabel *ButtomStatusLabel; - QLabel *statusLabel; QPixmap iconPix; - user *userLoginSetting; SaveData *data; diff --git a/main/mainscreen.ui b/main/mainscreen.ui index 0f0a0de..885971b 100644 --- a/main/mainscreen.ui +++ b/main/mainscreen.ui @@ -345,7 +345,7 @@ font-size: 15px; - false + true <html><head/><body><p><span style=" font-weight:600;">Get your grades</span></p></body></html> diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index bdcc197..00818b5 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -17,7 +17,6 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf(), reConnect connect(this, SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit())); } - /** * @brief jceSSLClient::makeConnect connecting to server with given port. using eventloop to assure it wont stuck the application. * @param server - server to connect to @@ -26,6 +25,9 @@ jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf(), reConnect */ bool jceSSLClient::makeConnect(QString server, int port) { + if (this->networkConf.isOnline() == false) + return false; + if (reConnection) //reset reconnectiong flag { qDebug() << Q_FUNC_INFO << "Making Reconnection"; @@ -39,7 +41,6 @@ bool jceSSLClient::makeConnect(QString server, int port) makeDiconnect(); } - qDebug() << Q_FUNC_INFO << "Connection to: " << server << "On Port: " << port; connectToHostEncrypted(server.toStdString().c_str(), port); @@ -182,12 +183,13 @@ void jceSSLClient::setOnlineState(bool isOnline) 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 } else { - //abort() ? + qWarning() << Q_FUNC_INFO << "Online State has been changed. emitting NoInternetLink"; this->makeDiconnect(); emit noInternetLink(); } @@ -212,6 +214,7 @@ void jceSSLClient::setDisconnected() if (reConnection) makeConnect(); + } /** * @brief jceSSLClient::setEncrypted called when signaled with encrypted. setting the buffer size and keeping alive. @@ -348,8 +351,6 @@ void jceSSLClient::showIfErrorMsg() msgBox.exec(); } } - - /** * @brief jceSSLClient::checkErrors this function exctuing when socket error has occured * @param a includes the error enum from QAbstractSocket::SocketError enum list diff --git a/src/jceSettings/jcelogin.cpp b/src/jceSettings/jcelogin.cpp index 0447cd7..b0ec4ae 100644 --- a/src/jceSettings/jcelogin.cpp +++ b/src/jceSettings/jcelogin.cpp @@ -10,6 +10,7 @@ jceLogin::jceLogin(user* username) this->jceA = username; this->JceConnector = new jceSSLClient(); QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); + QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection())); } jceLogin::~jceLogin() @@ -24,7 +25,7 @@ jceLogin::~jceLogin() * @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it. * throws error upon the given error from JCE website or Socket error */ -void jceLogin::makeConnection() throw (jceStatus) +int jceLogin::makeConnection() { qDebug() << "jceLogin::makeConnection(); connection to be make"; @@ -37,8 +38,12 @@ void jceLogin::makeConnection() throw (jceStatus) returnMode = checkConnection(); //checking socket status. is connected? if (returnMode == false) + { if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection - throw jceStatus::ERROR_ON_OPEN_SOCKET; + return jceStatus::ERROR_ON_OPEN_SOCKET; + else + returnMode = true; + } if (returnMode == true) //connected to host { @@ -88,8 +93,8 @@ void jceLogin::makeConnection() throw (jceStatus) status = jceStatus::JCE_NOT_CONNECTED; //we throw status even if we are IN! - qDebug() << "jceLogin::makeConnection(); throw status: " << status; - throw status; + qDebug() << "jceLogin::makeConnection(); return status: " << status; + return status; } /** @@ -103,36 +108,35 @@ bool jceLogin::checkConnection() const return false; } -/** - * @brief jceLogin::reConnect - * closing connection and deleting pointers. - * calling class's makeConnection function and throw the exception of it. - */ -void jceLogin::reConnect() throw (jceStatus) -{ - closeAll(); - if (this->JceConnector != NULL) - delete JceConnector; - this->recieverPage = new QString(); - this->JceConnector = new jceSSLClient(); - - try - { - makeConnection(); - } - catch (jceLogin::jceStatus &a) - { - throw a; - } -} /** * @brief jceLogin::closeAll */ void jceLogin::closeAll() { - JceConnector->makeDiconnect(); - delete recieverPage; + this->JceConnector->makeDiconnect(); + if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty())) + { + delete recieverPage; + recieverPage = NULL; + } + +} +/** + * @brief jceLogin::reMakeConnection + */ +void jceLogin::reMakeConnection() +{ + if (this->JceConnector != NULL) + delete JceConnector; + if (this->recieverPage != NULL) + delete recieverPage; recieverPage = NULL; + JceConnector = NULL; + this->recieverPage = new QString(); + this->JceConnector = new jceSSLClient(); + QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); + QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection())); + emit connectionReadyAfterDisconnection(); } /** @@ -309,18 +313,4 @@ void jceLogin::reValidation() { qDebug() << Q_FUNC_INFO << "Couldnt Validate User"; } - /* - delete recieverPage; - recieverPage = NULL; - if (this->JceConnector != NULL) - delete JceConnector; - this->recieverPage = new QString(); - this->JceConnector = new jceSSLClient(); - if (makeFirstVisit() == true) - { - if (checkValidation()) - { - if (makeSecondVisit() == true) - */ - } diff --git a/src/jceSettings/jcelogin.h b/src/jceSettings/jcelogin.h index df6a61c..622843a 100644 --- a/src/jceSettings/jcelogin.h +++ b/src/jceSettings/jcelogin.h @@ -32,10 +32,7 @@ public: JCE_GRADE_PAGE_PASSED }; - - - void makeConnection() throw (jceStatus); - void reConnect() throw (jceStatus); + int makeConnection(); void closeAll(); bool checkConnection() const; @@ -48,6 +45,10 @@ public: private slots: void reValidation(); + void reMakeConnection(); + +signals: + void connectionReadyAfterDisconnection(); private: