From 95ccaa39d0551ca11c874ec274109e0a04aec3ca Mon Sep 17 00:00:00 2001 From: Liran BN Date: Sun, 31 Aug 2014 12:33:27 +0300 Subject: [PATCH] Add calendar option bug fixes, better phrasing, calendar option --- jceGrade.pro | 108 ++-- jceGrade.pro.user | 251 ++++++++++ main/CalendarTab/CalendarManager.cpp | 17 + main/CalendarTab/CalendarManager.h | 24 + main/CourseTab/coursestablemanager.cpp | 251 ++++++++++ main/CourseTab/coursestablemanager.h | 43 ++ main/LoginTab/loginhandler.cpp | 141 ++++++ main/LoginTab/loginhandler.h | 44 ++ main/mainscreen.cpp | 172 ++++--- main/mainscreen.h | 23 +- main/mainscreen.ui | 467 ++++++++---------- src/{data => appDatabase}/savedata.cpp | 400 +++++++-------- src/{data => appDatabase}/savedata.h | 108 ++-- src/grades/Course.cpp | 55 --- src/grades/Page.cpp | 164 ------ src/jce/jcedate.cpp | 34 -- src/jce/jcedate.h | 33 -- .../jcesslclient.cpp | 264 +++++----- .../jcesslclient.h | 78 +-- src/jceData/Calendar/calendarCourse.cpp | 142 ++++++ src/jceData/Calendar/calendarCourse.h | 69 +++ src/jceData/Calendar/calendarPage.cpp | 111 +++++ src/jceData/Calendar/calendarPage.h | 26 + src/jceData/Grades/gradeCourse.cpp | 36 ++ .../Course.h => jceData/Grades/gradeCourse.h} | 117 ++--- .../Grades/gradePage.cpp} | 350 +++++++------ .../Grades/gradePage.h} | 93 ++-- src/{grades => jceData}/Page.h | 81 ++- src/jceData/course.h | 49 ++ src/jceData/page.cpp | 144 ++++++ .../jceLoginHtmlScripts.h | 159 +++--- src/{jce => jceSettings}/jcelogin.cpp | 442 +++++++++-------- src/{jce => jceSettings}/jcelogin.h | 119 ++--- src/{ => jceSettings}/user.cpp | 97 ++-- src/{ => jceSettings}/user.h | 91 ++-- 35 files changed, 2904 insertions(+), 1899 deletions(-) create mode 100644 jceGrade.pro.user create mode 100644 main/CalendarTab/CalendarManager.cpp create mode 100644 main/CalendarTab/CalendarManager.h create mode 100644 main/CourseTab/coursestablemanager.cpp create mode 100644 main/CourseTab/coursestablemanager.h create mode 100644 main/LoginTab/loginhandler.cpp create mode 100644 main/LoginTab/loginhandler.h rename src/{data => appDatabase}/savedata.cpp (96%) rename src/{data => appDatabase}/savedata.h (96%) delete mode 100644 src/grades/Course.cpp delete mode 100644 src/grades/Page.cpp delete mode 100644 src/jce/jcedate.cpp delete mode 100644 src/jce/jcedate.h rename src/{connection => jceConnection}/jcesslclient.cpp (95%) rename src/{connection => jceConnection}/jcesslclient.h (94%) create mode 100644 src/jceData/Calendar/calendarCourse.cpp create mode 100644 src/jceData/Calendar/calendarCourse.h create mode 100644 src/jceData/Calendar/calendarPage.cpp create mode 100644 src/jceData/Calendar/calendarPage.h create mode 100644 src/jceData/Grades/gradeCourse.cpp rename src/{grades/Course.h => jceData/Grades/gradeCourse.h} (53%) rename src/{grades/GradePage.cpp => jceData/Grades/gradePage.cpp} (68%) rename src/{grades/GradePage.h => jceData/Grades/gradePage.h} (62%) rename src/{grades => jceData}/Page.h (77%) create mode 100644 src/jceData/course.h create mode 100644 src/jceData/page.cpp rename src/{jce => jceSettings}/jceLoginHtmlScripts.h (62%) rename src/{jce => jceSettings}/jcelogin.cpp (88%) rename src/{jce => jceSettings}/jcelogin.h (83%) rename src/{ => jceSettings}/user.cpp (74%) rename src/{ => jceSettings}/user.h (72%) diff --git a/jceGrade.pro b/jceGrade.pro index 9e068ba..b341c1b 100644 --- a/jceGrade.pro +++ b/jceGrade.pro @@ -1,53 +1,55 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-05-31T19:49:42 -# -#------------------------------------------------- - -QT += core gui network - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -TARGET = jceGrade -TEMPLATE = app -RC_FILE = appConfigure.rc -CONFIG += c++11 static -SOURCES += main/coursestablemanager.cpp \ - main/loginhandler.cpp \ - main/main.cpp \ - main/mainscreen.cpp \ - src/connection/jcesslclient.cpp \ - src/user.cpp \ - src/grades/Course.cpp \ - src/grades/GradePage.cpp \ - src/grades/Page.cpp \ - src/jce/jcedate.cpp \ - src/jce/jcelogin.cpp \ - src/data/savedata.cpp \ - - - - -HEADERS += main/coursestablemanager.h \ - main/loginhandler.h \ - main/mainscreen.h \ - src/connection/jcesslclient.h \ - src/user.h \ - src/grades/Course.h \ - src/grades/GradePage.h \ - src/grades/Page.h \ - src/jce/jcedate.h \ - src/jce/jcelogin.h \ - src/jce/jceLoginHtmlScripts.h \ - src/data/savedata.h \ - - -TRANSLATIONS = jce_en.ts \ - jce_he.ts - -FORMS += \ - main/mainscreen.ui - -OTHER_FILES += - -RESOURCES += \ - resources/connectionstatus.qrc +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-31T19:49:42 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TARGET = jceGrade +TEMPLATE = app +RC_FILE = appConfigure.rc +CONFIG += c++11 static + +FORMS += \ + main/mainscreen.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 + +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 + diff --git a/jceGrade.pro.user b/jceGrade.pro.user new file mode 100644 index 0000000..c29c631 --- /dev/null +++ b/jceGrade.pro.user @@ -0,0 +1,251 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.3.0 MinGW 32bit + Desktop Qt 5.3.0 MinGW 32bit + qt.53.win32_mingw482_kit + 0 + 0 + 0 + + D:/Dropbox/cpp/jceConQT/build-jceGrade-Desktop_Qt_5_3_0_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Dropbox/cpp/jceConQT/build-jceGrade-Desktop_Qt_5_3_0_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + jceGrade + + Qt4ProjectManager.Qt4RunConfiguration:D:/Dropbox/cpp/jceConQT/jceAverageCalculator/jceGrade.pro + + jceGrade.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {f3f3b933-8225-47b3-aa78-fc5de0bd714b} + + + ProjectExplorer.Project.Updater.FileVersion + 15 + + diff --git a/main/CalendarTab/CalendarManager.cpp b/main/CalendarTab/CalendarManager.cpp new file mode 100644 index 0000000..80dce68 --- /dev/null +++ b/main/CalendarTab/CalendarManager.cpp @@ -0,0 +1,17 @@ +#include "CalendarManager.h" + +CalendarManager::CalendarManager(QPlainTextEdit *ptr) +{ + this->ptr = ptr; +} + +void CalendarManager::setCalendar(std::string html) +{ + cali = new CalendarPage(html); + QString text; + for (calendarCourse *a: *cali->getCourses()) + { + text += QString::fromStdString(a->courseToString()); + } + ptr->setPlainText(text); +} diff --git a/main/CalendarTab/CalendarManager.h b/main/CalendarTab/CalendarManager.h new file mode 100644 index 0000000..dc91bf4 --- /dev/null +++ b/main/CalendarTab/CalendarManager.h @@ -0,0 +1,24 @@ +#ifndef CALENDARMANAGER_H +#define CALENDARMANAGER_H + +#include "./src/jceData/Calendar/calendarPage.h" +#include + +#include + +class CalendarManager +{ +public: + CalendarManager(QPlainTextEdit *ptr); + ~CalendarManager() + { + delete cali; + } + + void setCalendar(std::string html); +private: + QPlainTextEdit * ptr; + CalendarPage * cali; +}; + +#endif // CALENDARMANAGER_H diff --git a/main/CourseTab/coursestablemanager.cpp b/main/CourseTab/coursestablemanager.cpp new file mode 100644 index 0000000..c32a4c2 --- /dev/null +++ b/main/CourseTab/coursestablemanager.cpp @@ -0,0 +1,251 @@ +#include "coursestablemanager.h" + +coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr) +{ + this->gp = NULL; + this->us = usrPtr; + this->courseTBL = ptr; + + /* + * Initilizing Table + */ + courseTBL->setRowCount(0); + courseTBL->setColumnCount(COURSE_FIELDS); + QStringList mz; + mz << QObject::tr("Code") << QObject::tr("Name") << QObject::tr("Type") << QObject::tr("Points") << QObject::tr("Hours") << QObject::tr("Grade") << QObject::tr("Additions"); + courseTBL->setHorizontalHeaderLabels(mz); + courseTBL->verticalHeader()->setVisible(true); + courseTBL->setSelectionMode(QAbstractItemView::SingleSelection); + courseTBL->setShowGrid(true); + courseTBL->setStyleSheet("QTableView {selection-background-color: red;}"); +} + +coursesTableManager::~coursesTableManager() +{ + courseTBL = NULL; + delete gp; + gp = NULL; +} +/** + * @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table + */ +void coursesTableManager::insertJceCoursesIntoTable() +{ + for (gradeCourse *c: *gp->getCourses()) + { + if (us->getInfluenceCourseOnly()) + { + if (isCourseInfluence(c)) + addRow(c); + } + else + addRow(c); + } +} +/** + * @brief coursesTableManager::setCoursesList creating courses list with given html page + * @param html + */ +void coursesTableManager::setCoursesList(std::string &html) +{ + gp = new GradePage(html); +} +/** + * @brief coursesTableManager::changes when user changes the table manually it updates it + * @param change string change + * @param row row index + * @param col col index + * @return if change has been done + */ +bool coursesTableManager::changes(QString change, int row, int col) +{ + + bool isNumFlag = true; + + int serialCourse = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text().toInt(); + for (gradeCourse *c: *gp->getCourses()) + { + if (c->getSerialNum() == serialCourse) + { + switch (col) + { + case (gradeCourse::CourseScheme::NAME): + c->setName(change.toStdString()); + break; + case (gradeCourse::CourseScheme::TYPE): + c->setType(change.toStdString()); + break; + case (gradeCourse::CourseScheme::POINTS): + { + change.toDouble(&isNumFlag); + + if (!isNumFlag) + { + courseTBL->item(row,col)->setText(QString::number(c->getPoints())); + } + else + c->setPoints(change.toDouble()); + break; + } + case (gradeCourse::CourseScheme::HOURS): + { + change.toDouble(&isNumFlag); + + if (!isNumFlag) + { + courseTBL->item(row,col)->setText(QString::number(c->getHours())); + } + else + c->setHours(change.toDouble()); + break; + } + case (gradeCourse::CourseScheme::GRADE): + { + change.toDouble(&isNumFlag); + + if (!isNumFlag) + { + courseTBL->item(row,col)->setText(QString::number(c->getGrade())); + } + else + { + if ((change.toDouble() >= 0) && (change.toDouble() <= 100)) + c->setGrade(change.toDouble()); + else + courseTBL->item(row,col)->setText(QString::number(c->getGrade())); + } + break; + } + case (gradeCourse::CourseScheme::ADDITION): + c->setAdditions(change.toStdString()); + break; + } + break; + } + } + return isNumFlag; + +} +/** + * @brief coursesTableManager::addRow adds row with given information + * @param courseToAdd if exists, add its information to table + */ +void coursesTableManager::addRow(const gradeCourse *courseToAdd) +{ + int i,j; + i = courseTBL->rowCount(); + j = 0; + QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition; + const gradeCourse * c; + if (courseToAdd != NULL) + { + c = courseToAdd; + if (!isCourseAlreadyInserted(c->getSerialNum())) + { + courseTBL->setRowCount(courseTBL->rowCount()+1); + serial = new QTableWidgetItem(QString::number(c->getSerialNum())); + serial->setFlags(serial->flags() & ~Qt::ItemIsEditable); + points = new QTableWidgetItem(QString::number(c->getPoints())); + points->setFlags(serial->flags() & ~Qt::ItemIsEditable); + hours = new QTableWidgetItem(QString::number(c->getHours())); + hours->setFlags(serial->flags() & ~Qt::ItemIsEditable); + grade = new QTableWidgetItem(QString::number(c->getGrade())); + name = new QTableWidgetItem(QString::fromStdString(c->getName())); + name->setFlags(serial->flags() & ~Qt::ItemIsEditable); + type = new QTableWidgetItem(QString::fromStdString(c->getType())); + type->setFlags(serial->flags() & ~Qt::ItemIsEditable); + addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions())); + + courseTBL->setItem(i,j++,serial); + courseTBL->setItem(i,j++,name); + courseTBL->setItem(i,j++,type); + courseTBL->setItem(i,j++,points); + courseTBL->setItem(i,j++,hours); + courseTBL->setItem(i,j++,grade); + courseTBL->setItem(i,j,addition); + + } + } + else + { + } + courseTBL->resizeColumnsToContents(); + +} +double coursesTableManager::getAvg() +{ + if (this->gp != NULL) + return gp->getAvg(); + return 0; +} + + +void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus) +{ + if (ignoreCourseStatus) + { + int i = 0; + while (i < courseTBL->rowCount()) + { + if (courseTBL->item(i,gradeCourse::CourseScheme::POINTS)->text().compare("0") == 0) + courseTBL->removeRow(i--); + i++; + } + } + else + { + for (gradeCourse *c: *gp->getCourses()) + { + if (!(isCourseAlreadyInserted(c->getSerialNum()))) + if (c->getPoints() == 0) + addRow(c); + } + } + +} + +void coursesTableManager::clearTable() +{ + if (courseTBL->rowCount() == 0) + return; + + int i = 0; //starting point + while (courseTBL->rowCount() > i) + { + gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text().toStdString()); + courseTBL->removeRow(i); + } + gp = NULL; + courseTBL->repaint(); +} + +gradeCourse *coursesTableManager::getCourseByRow(int row) +{ + QString courseSerial = courseTBL->item(row,gradeCourse::CourseScheme::SERIAL)->text(); + for (gradeCourse *c: *gp->getCourses()) + { + if (c->getSerialNum() == courseSerial.toDouble()) + return c; + } + return NULL; +} + +bool coursesTableManager::isCourseAlreadyInserted(double courseID) +{ + int i=0; + for (i = 0; i < courseTBL->rowCount(); ++i) + { + QString courseSerial = courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text(); + if (QString::number(courseID) == courseSerial) + return true; + } + return false; +} + +bool coursesTableManager::isCourseInfluence(const gradeCourse *courseToCheck) +{ + if (courseToCheck->getPoints() > 0) + return true; + return false; + +} diff --git a/main/CourseTab/coursestablemanager.h b/main/CourseTab/coursestablemanager.h new file mode 100644 index 0000000..4dabc58 --- /dev/null +++ b/main/CourseTab/coursestablemanager.h @@ -0,0 +1,43 @@ +#ifndef COURSESTABLEMANAGER_H +#define COURSESTABLEMANAGER_H + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "./src/jceData/Grades/gradePage.h" +#include "./src/jceSettings/user.h" + +class coursesTableManager +{ +public: + coursesTableManager(QTableWidget *, user *usrPtr); + ~coursesTableManager(); + void insertJceCoursesIntoTable(); + void setCoursesList(std::string &htmlPage); + bool changes(QString change, int row, int col); + void addRow(const gradeCourse * courseToAdd = 0); + double getAvg(); + + void influnceCourseChanged(bool status); + void clearTable(); + +private: + QTableWidget *courseTBL; + GradePage *gp; + user *us; + + gradeCourse * getCourseByRow(int row); + bool isCourseAlreadyInserted(double courseID); + bool isCourseInfluence(const gradeCourse *courseToCheck); +}; + +#endif // COURSESTABLEMANAGER_H diff --git a/main/LoginTab/loginhandler.cpp b/main/LoginTab/loginhandler.cpp new file mode 100644 index 0000000..5480bd7 --- /dev/null +++ b/main/LoginTab/loginhandler.cpp @@ -0,0 +1,141 @@ +#include "loginhandler.h" + +loginHandler::loginHandler(user *ptr): logggedInFlag(false) +{ + this->jceLog = new jceLogin(ptr); +} +void loginHandler::setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) +{ + + this->statusLabelPtr = statusLabelPtr; + this->pswdEditPtr = pswdEditPtr; + this->usrnmEditPtr = usrnmEditPtr; +} + +bool loginHandler::makeConnection() +{ + if (this->jceLog == NULL) + return false; + + try + { + jceLog->makeConnection(); + } + catch (jceLogin::jceStatus &a) + { + int status = (int)a; + switch (status) + { + case jceLogin::JCE_YOU_ARE_IN: + { + logggedInFlag = true; + return logggedInFlag; + break; + } + case jceLogin::ERROR_ON_VALIDATION: + { + popMessage("Please Check Your Username & Password",false); + + usrnmEditPtr->setDisabled(false); + pswdEditPtr->setDisabled(false); + + pswdEditPtr->selectAll(); + pswdEditPtr->setFocus(); + return false; + } + case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED: + { + popMessage("You have been blocked by JCE, please try in a couple of minutes."); + jceLog->closeAll(); + return false; + } + case jceLogin::ERROR_ON_OPEN_SOCKET: + { + popMessage("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("Recieve Request Time Out."); + jceLog->closeAll(); + return false; + break; + } + case jceLogin::ERROR_ON_SEND_REQUEST: + { + popMessage("Send Request Time Out."); + jceLog->closeAll(); + return false; + break; + } + } + } + return false; +} + + +bool loginHandler::isLoggedInFlag() +{ + return this->logggedInFlag; +} + +void loginHandler::setLoginFlag(bool flag) +{ + this->logggedInFlag = flag; +} + +QString loginHandler::getCurrentPageContect() +{ + QTextEdit phrase; + if (isLoggedInFlag()) + phrase.setText(QString::fromStdString(jceLog->getPage())); + else + throw jceLogin::ERROR_ON_GETTING_INFO; + + 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; +} + +int loginHandler::makeCalendarRequest(int year, int semester) +{ + if (isLoggedInFlag()) + return jceLog->getCalendar(year,semester); + else + return jceLogin::JCE_NOT_CONNECTED; +} +void loginHandler::popMessage(QString message,bool addInfo) +{ + if (addInfo) + message.append("\nIf this message appear without reason, please contact me at liranbg@gmail.com"); + + QMessageBox msgBox; + msgBox.setWindowTitle("Error"); + msgBox.setText(message); + msgBox.exec(); + msgBox.setFocus(); + +} + + diff --git a/main/LoginTab/loginhandler.h b/main/LoginTab/loginhandler.h new file mode 100644 index 0000000..2795d67 --- /dev/null +++ b/main/LoginTab/loginhandler.h @@ -0,0 +1,44 @@ +#ifndef LOGINHANDLER_H +#define LOGINHANDLER_H +#include +#include +#include +#include +#include +#include + +#include "./src/jceSettings/jcelogin.h" +#include "./src/appDatabase/savedata.h" + + +class loginHandler +{ +public: + loginHandler(user *ptr); + void setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); + 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: + + void popMessage(QString message, bool addInfo = true); + + bool logggedInFlag; + jceLogin *jceLog; + + QLabel *statusLabelPtr; + QLineEdit *pswdEditPtr; + QLineEdit *usrnmEditPtr; + + +}; + +#endif // LOGINHANDLER_H diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 20cd284..39a3925 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -6,7 +6,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr { ui->setupUi(this); - this->setFixedSize(this->size()); //main not resizeable + //this->setFixedSize(this->size()); //main not resizeable //Login Tab @@ -21,9 +21,8 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr ui->statusBar->addPermanentWidget(statusLabel,1); setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); - //Course and Setting Tab + //Course, Setting, Calendar Tab ui->CoursesTab->setDisabled(true); - ui->SettingsTab->setDisabled(true); ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); @@ -32,8 +31,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr this->userLoginSetting = new user("",""); this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); this->loginHandel = new loginHandler(userLoginSetting); - - updateDates(); + this->calendar = new CalendarManager(ui->calendartext); //check login File SaveData::init(); @@ -51,7 +49,6 @@ MainScreen::~MainScreen() delete loginHandel; delete ui; } -/*** LOGIN TAB FUNCTIONS ***/ void MainScreen::on_loginButton_clicked() { if (loginHandel->isLoggedInFlag()) @@ -61,26 +58,32 @@ void MainScreen::on_loginButton_clicked() uiSetConnectMode(); } -void MainScreen::on_usrnmLineEdit_editingFinished() +void MainScreen::on_pushButton_clicked() { - ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); -} -void MainScreen::on_keepLogin_clicked() -{ - if (ui->keepLogin->isChecked()) - SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()); + int status = 0; + if (loginHandel->isLoggedInFlag()) + { + if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_GRADE_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->setCalendar(loginHandel->getCurrentPageContect().toStdString()); + } - else - SaveData::deleteData(); + else if (status == jceLogin::JCE_NOT_CONNECTED) + { + QMessageBox::critical(this,tr("Error"),tr("Not Connected")); + } + } } -/*** COURSES TAB FUNCTIONS ***/ + void MainScreen::on_ratesButton_clicked() { std::string pageString; int status = 0; if (loginHandel->isLoggedInFlag()) { - if ((status = loginHandel->makeGradeRequest()) == 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().toStdString(); courseTableMgr->setCoursesList(pageString); @@ -91,7 +94,56 @@ void MainScreen::on_ratesButton_clicked() QMessageBox::critical(this,tr("Error"),tr("Not Connected")); } } + + + } +void MainScreen::on_checkBoxCoursesInfluence_toggled(bool checked) +{ + this->userLoginSetting->setInfluenceCourseOnly(checked); + this->courseTableMgr->influnceCourseChanged(checked); +} +void MainScreen::on_spinBoxCoursesFromYear_editingFinished() +{ + if (ui->spinBoxCoursesFromYear->value() > ui->spinBoxCoursesToYear->value()) + { + ui->spinBoxCoursesFromYear->setValue(ui->spinBoxCoursesToYear->value()); + ui->spinBoxCoursesFromYear->setFocus(); + } + +} +void MainScreen::on_spinBoxCoursesToYear_editingFinished() +{ + if (ui->spinBoxCoursesFromYear->value() > ui->spinBoxCoursesToYear->value()) + { + ui->spinBoxCoursesToYear->setValue(ui->spinBoxCoursesFromYear->value()); + ui->spinBoxCoursesToYear->setFocus(); + + } +} +void MainScreen::on_spinBoxCoursesFromSemester_editingFinished() +{ + if (ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value()) + { + if (ui->spinBoxCoursesFromSemester->value() > ui->spinBoxCoursesToSemester->value()) + { + ui->spinBoxCoursesFromSemester->setValue(ui->spinBoxCoursesToSemester->value()); + ui->spinBoxCoursesFromSemester->setFocus(); + } + } +} +void MainScreen::on_spinBoxCoursesToSemester_editingFinished() +{ + if (ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value()) + { + if (ui->spinBoxCoursesFromSemester->value() > ui->spinBoxCoursesToSemester->value()) + { + ui->spinBoxCoursesToSemester->setValue(ui->spinBoxCoursesFromSemester->value()); + ui->spinBoxCoursesToSemester->setFocus(); + } + } +} + void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) { if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) @@ -99,79 +151,11 @@ void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) else QMessageBox::critical(this,"Error","Missmatching data"); } -void MainScreen::on_clearTableButton_clicked() -{ - courseTableMgr->clearTable(); - ui->avgLCD->display(courseTableMgr->getAvg()); -} - -/*** SETTING TAB FUNCTIONS ***/ -void MainScreen::on_spinBoxFromYear_editingFinished() +void MainScreen::on_usrnmLineEdit_editingFinished() { - if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) - { - ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value()); - ui->spinBoxFromYear->setFocus(); - updateDates(); - } - else - updateDates(); + ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); } -void MainScreen::on_spinBoxToYear_editingFinished() -{ - if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) - { - ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value()); - ui->spinBoxToYear->setFocus(); - updateDates(); - } - else - updateDates(); -} -void MainScreen::on_spinBoxFromSem_editingFinished() -{ - if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) - { - if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) - { - ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value()); - ui->spinBoxFromSem->setFocus(); - } - } - updateDates(); -} -void MainScreen::on_spinBoxToSemester_editingFinished() -{ - if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) - { - if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) - { - ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value()); - ui->spinBoxToSemester->setFocus(); - } - } - updateDates(); -} -void MainScreen::on_checkBox_toggled(bool checked) -{ - this->userLoginSetting->setInfluenceCourseOnly(checked); - this->courseTableMgr->influnceCourseChanged(checked); -} -/* - * ------------------------------ - * -*/ -void MainScreen::updateDates() -{ - std::string fy,ty,fs,ts; - fy = std::to_string(ui->spinBoxFromYear->value()); - ty = std::to_string(ui->spinBoxToYear->value()); - fs = std::to_string(ui->spinBoxFromSem->value()); - ts = std::to_string(ui->spinBoxToSemester->value()); - userLoginSetting->setDate(fy,fs,ty,ts); -} - void MainScreen::uiSetDisconnectMode() { setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); @@ -213,7 +197,6 @@ void MainScreen::uiSetConnectMode() //fix before distrbute ui->loginButton->setText("&Logout"); this->ui->ratesButton->setEnabled(true); ui->CoursesTab->setEnabled(true); - ui->SettingsTab->setEnabled(true); } else @@ -262,6 +245,12 @@ void MainScreen::on_actionCredits_triggered() ""); } +void MainScreen::on_clearTableButton_clicked() +{ + + courseTableMgr->clearTable(); + ui->avgLCD->display(courseTableMgr->getAvg()); +} void MainScreen::on_actionExit_triggered() { @@ -269,7 +258,14 @@ void MainScreen::on_actionExit_triggered() } +void MainScreen::on_keepLogin_clicked() +{ + if (ui->keepLogin->isChecked()) + SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()); + else + SaveData::deleteData(); +} void MainScreen::on_actionHow_To_triggered() { diff --git a/main/mainscreen.h b/main/mainscreen.h index bf4b4a3..ddf79c3 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -10,8 +10,9 @@ #include #include -#include "coursestablemanager.h" -#include "loginhandler.h" +#include "./CourseTab/coursestablemanager.h" +#include "./LoginTab/loginhandler.h" +#include "./CalendarTab/CalendarManager.h" #define StatusIconHeight 35 namespace Ui { @@ -30,18 +31,16 @@ private slots: void on_ratesButton_clicked(); - void on_spinBoxFromYear_editingFinished(); + void on_spinBoxCoursesFromYear_editingFinished(); - void on_spinBoxFromSem_editingFinished(); + void on_spinBoxCoursesFromSemester_editingFinished(); - void on_spinBoxToYear_editingFinished(); + void on_spinBoxCoursesToYear_editingFinished(); - void on_spinBoxToSemester_editingFinished(); + void on_spinBoxCoursesToSemester_editingFinished(); void on_loginButton_clicked(); - void on_checkBox_toggled(bool checked); - void on_usrnmLineEdit_editingFinished(); void on_actionCredits_triggered(); @@ -55,10 +54,13 @@ private slots: void on_keepLogin_clicked(); void on_actionHow_To_triggered(); - + + void on_pushButton_clicked(); + + void on_checkBoxCoursesInfluence_toggled(bool checked); + private: - void updateDates(); void uiSetDisconnectMode(); void uiSetConnectMode(); void setLabelConnectionStatus(jceLogin::jceStatus statusDescription); @@ -67,6 +69,7 @@ private: user *userLoginSetting; + CalendarManager * calendar; coursesTableManager *courseTableMgr; loginHandler *loginHandel; diff --git a/main/mainscreen.ui b/main/mainscreen.ui index 2f62dd3..71993fc 100644 --- a/main/mainscreen.ui +++ b/main/mainscreen.ui @@ -7,7 +7,7 @@ 0 0 855 - 649 + 517 @@ -61,7 +61,7 @@ background: qlineargradient(spread:pad, x1:0.496, y1:0, x2:0.508, y2:1, stop:0 r QTabWidget::Rounded - 1 + 0 false @@ -303,7 +303,7 @@ font-size: 15px; - Courses + GPA @@ -311,7 +311,7 @@ font-size: 15px; 0 - + @@ -330,7 +330,7 @@ font-size: 15px; - + @@ -375,7 +375,7 @@ font-size: 15px; - + Average: @@ -410,260 +410,211 @@ font-size: 15px; - - - - - - - false - - - - 0 - 0 - - - - Settings - - - - - 20 - 20 - 251 - 159 - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 48 - 20 - - - - - - - - - - Semester - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 50 - 20 - - - - - - - - Year - - - - - - - - - - - - - QLayout::SetMinimumSize - - - 0 - - - - - - 0 - 0 - - - - - 40 - 16777215 - - - - From - - - - - - - - 0 - 0 - - - - - 40 - 16777215 - - - - To - - - - - - - - - - - - - 3 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - false - - - false - - - 2009 - - - 2015 - - - 2009 - - - - - - - - - - - 3 - - - 3 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - 2010 - - - 2026 - - - 2015 - - - - - - - - - - - - - + + + + - Only influence Courses + Only Main Courses - - false + + + + + + + 0 + 0 + + + + From + + + + + + + Year: + + + + + + + 2008 + + + 2015 + + + 2011 + + + + + + + Semester: + + + + + + + 1 + + + 3 + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + To + + + + + + + Year: + + + + + + + 2008 + + + 2015 + + + 2014 + + + + + + + Semester + + + + + + + 1 + + + 3 + + + 3 - - - - + + + + + + + + Calendar + + + + + + + + + + + + 2012 + + + 2020 + + + 2014 + + + + + + + 1 + + + 3 + + + 2 + + + + + + + Get Calendar + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::RightToLeft + + + + + + + + @@ -675,7 +626,7 @@ font-size: 15px; 0 0 855 - 29 + 21 @@ -723,15 +674,9 @@ font-size: 15px; usrnmLineEdit pswdLineEdit loginButton - tabWidget ratesButton clearTableButton - checkBox - spinBoxFromSem coursesTable - spinBoxFromYear - spinBoxToSemester - spinBoxToYear diff --git a/src/data/savedata.cpp b/src/appDatabase/savedata.cpp similarity index 96% rename from src/data/savedata.cpp rename to src/appDatabase/savedata.cpp index 4cab10a..89900da 100644 --- a/src/data/savedata.cpp +++ b/src/appDatabase/savedata.cpp @@ -1,200 +1,200 @@ -#include "savedata.h" - - - -/** - * @brief Checks the status tag in the file - * @return boolean the status - */ -bool SaveData::isSaved() -{ - QString status; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - { - status = getValViaTag("status", file); - if(status == "true") - { - file->close(); //close & return - return true; - } - return false; //close & return - file->close(); - } - /* If Faild to open */ - std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl; - return false; -} - - -/** - * @brief This Function will modify the file, and save the data. - * @param username - QString - * @param password - QString - * @return true if saved - false if error - */ -bool SaveData::save(QString username, QString password) -{ - std::cout << "Trying to save data..." << std::endl; - QFile file(FILE_NAME); - if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) - return false; /* IO Error! */ - QTextStream output(&file); - QString hash_pass = hashPassword(password); - output << "[status]true[/]\n[username]"<open(QIODevice::ReadOnly|QIODevice::Text)) - username = getValViaTag("username", file); - file->close(); - return username; - -} - -/** - * @brief getter for password - * @return QString - password - */ -QString SaveData::getPassword() -{ - QString pass = ""; - QFile* file = new QFile(FILE_NAME); - /* Opening file for read */ - if(file->open(QIODevice::ReadOnly|QIODevice::Text)) - pass = getValViaTag("password", file); - file->close(); - pass = deHashPasword(pass); - return pass; - -} - -/** - * @brief This is A functions that will init the tags file. - * if it exist - do nothing - * if there is no file, it will create it and run the deleteData function - * so tags will be set. - */ -void SaveData::init() -{ - QFile file(FILE_NAME); - if(!file.exists()) - { - file.open(QIODevice::ReadWrite | QIODevice::Text); - file.close(); - deleteData(); - } -} - -/** - * @brief This function will return the vale of a given tag name. - * NOTE: valid tag names are : "status", "username", "password" - * if tag is invalid - will return "" - an empty QString! - * @param tag - QString, the tag name - * @param file - a QFile pointer - * @return QString - the value in tag - * NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!) - */ -QString SaveData::getValViaTag(QString tag, QFile* file) -{ - QString val, line , tmpTag; - QTextStream textStream( file); - while((line = textStream.readLine()) != NULL) - { - std::cout << "DEBUG: line => " << line.toStdString() << std::endl; - for(int i = 0 ; i< line.length() ;++i) - { - if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/") - { - i++; - tmpTag = line.mid(i, tag.length()); - if(tmpTag == tag) - { - i+= tag.length()+1; // i is now right after '[' - int j = i; - while(line[j] != '[')// put j at the end of the value - j++; - /* Then... the value is :*/ - val = line.mid(i, j-i); - std::cout << "DEBUG: ["<open(QIODevice::ReadOnly|QIODevice::Text)) + { + status = getValViaTag("status", file); + if(status == "true") + { + file->close(); //close & return + return true; + } + return false; //close & return + file->close(); + } + /* If Faild to open */ + std::cout << "Faild To Accsess file: " << FILE_NAME << std::endl; + return false; +} + + +/** + * @brief This Function will modify the file, and save the data. + * @param username - QString + * @param password - QString + * @return true if saved - false if error + */ +bool SaveData::save(QString username, QString password) +{ + std::cout << "Trying to save data..." << std::endl; + QFile file(FILE_NAME); + if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) + return false; /* IO Error! */ + QTextStream output(&file); + QString hash_pass = hashPassword(password); + output << "[status]true[/]\n[username]"<open(QIODevice::ReadOnly|QIODevice::Text)) + username = getValViaTag("username", file); + file->close(); + return username; + +} + +/** + * @brief getter for password + * @return QString - password + */ +QString SaveData::getPassword() +{ + QString pass = ""; + QFile* file = new QFile(FILE_NAME); + /* Opening file for read */ + if(file->open(QIODevice::ReadOnly|QIODevice::Text)) + pass = getValViaTag("password", file); + file->close(); + pass = deHashPasword(pass); + return pass; + +} + +/** + * @brief This is A functions that will init the tags file. + * if it exist - do nothing + * if there is no file, it will create it and run the deleteData function + * so tags will be set. + */ +void SaveData::init() +{ + QFile file(FILE_NAME); + if(!file.exists()) + { + file.open(QIODevice::ReadWrite | QIODevice::Text); + file.close(); + deleteData(); + } +} + +/** + * @brief This function will return the vale of a given tag name. + * NOTE: valid tag names are : "status", "username", "password" + * if tag is invalid - will return "" - an empty QString! + * @param tag - QString, the tag name + * @param file - a QFile pointer + * @return QString - the value in tag + * NOTE: if NULL value, or an invalid tag name -> return "" (empty QString!) + */ +QString SaveData::getValViaTag(QString tag, QFile* file) +{ + QString val, line , tmpTag; + QTextStream textStream( file); + while((line = textStream.readLine()) != NULL) + { + std::cout << "DEBUG: line => " << line.toStdString() << std::endl; + for(int i = 0 ; i< line.length() ;++i) + { + if(line[i] == '[' && line[i+1] != '/') //get open tag at begining of line and not end of tag ("[/") + { + i++; + tmpTag = line.mid(i, tag.length()); + if(tmpTag == tag) + { + i+= tag.length()+1; // i is now right after '[' + int j = i; + while(line[j] != '[')// put j at the end of the value + j++; + /* Then... the value is :*/ + val = line.mid(i, j-i); + std::cout << "DEBUG: ["< -#include -#include - -/* C/C++ libs */ -#include -#include -#include - -#define FILE_NAME "JAC_DB.dat" -#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]" - -class SaveData -{ -public: - bool static isSaved(); - bool static save(QString username, QString password); - bool static deleteData(); - QString static getUsername(); - QString static getPassword(); - void static init(); -private: - QString static getValViaTag(QString tag, QFile *file); - QString static hashPassword(QString pass); - QString static deHashPasword(QString pass); -}; - -#endif // SAVEDATA_H +#ifndef SAVEDATA_H +#define SAVEDATA_H + +/** + * SaveData Class + * -------------------------------------- + * + * all functions in this class are static! + * no need to create an object! + * + * provides all the needed functions + * for saving user data for JCE login. + * + * the class will enteract with a file formated by tags for storing the valus. + * the file format is as sutch: + * + * [status]Status Value[/] + * [username]usernaem vale[/] + * [password]hashed(not really) password vale[/] + * + * the class will create a file if not exists by calling Save Data::init() function. + * + * for more info about functions - see implantation + */ + +/* QT libs */ +#include +#include +#include + +/* C/C++ libs */ +#include +#include +#include + +#define FILE_NAME "JAC_DB.dat" +#define DEFAULT_DATA_EMPTY "[status]false[/]\n[username][/]\n[password][/]" + +class SaveData +{ +public: + bool static isSaved(); + bool static save(QString username, QString password); + bool static deleteData(); + QString static getUsername(); + QString static getPassword(); + void static init(); +private: + QString static getValViaTag(QString tag, QFile *file); + QString static hashPassword(QString pass); + QString static deHashPasword(QString pass); +}; + +#endif // SAVEDATA_H diff --git a/src/grades/Course.cpp b/src/grades/Course.cpp deleted file mode 100644 index c57a774..0000000 --- a/src/grades/Course.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "Course.h" - -Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions) -{ - this->serialNum = serial; - this->name = name; - this->type = type; - this->points = points; - this->hours = hours; - this->grade = grade; - this->additions = additions; -} - -Course::~Course() -{ - -} -double Course::getGrade() const -{ - double noGrade = NO_GRADE_YET; - if (grade == noGrade) - return 0; - else - return this->grade; -} - -void Course::setName(std::string name) -{ - this->name = name; -} - -void Course::setType(std::string type) -{ - this->type = type; -} - -void Course::setPoints(double points) -{ - this->points=points; -} - -void Course::setHours(double hours) -{ - this->hours = hours; -} - -void Course::setGrade(double grade) -{ - this->grade = grade; -} - -void Course::setAdditions(std::string additions) -{ - this->additions = additions; -} diff --git a/src/grades/Page.cpp b/src/grades/Page.cpp deleted file mode 100644 index f32bc4a..0000000 --- a/src/grades/Page.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include "Page.h" - -Page::Page(std::string& html) -{ - makeText(html); -} -void Page::makeText(std::string& html) -{ - int index = 0; - index = findTitle(html, index); - index = runToActualText(html, index); //set index into the actual place where the data is - manageTableContent(html, index); -} - -int Page::findTitle(std::string& from, int index) -{ - std::string temp; - while(index < (int)from.length()) - { - if(from[index] == '<') - { - //title> - index++; - std::string titleTag = from.substr(index, 5); //legth of title - if(titleTag == "title") //check if the tag is title - { - while(from[index] != '>') - index++; - index++; - while(from[index] != '<') - { - temp += from[index]; - index++; - } - this->title = temp; //sets the title - return index; - } - } - - index++; - } - return -1; -} - -int Page::runToActualText(std::string& from, int index) -{ - while(index < (int)from.length()) - { - if(from[index] == '<') - { - index++; - if(from[index] == '!') - { - //!--FileName - std::string bodyTag = from.substr(index, 11); //!--FileName - - if(bodyTag == "!--FileName") //check if the tag is body tag - { - while(from[index] != '>') - index++; - return index; - } - } - } - index++; - } - return -1; -} - -void Page::manageTableContent(std::string& html, int index) -{ - std::string temp; - for (int i = index; i < (int)html.length(); i++) - { - if(html[i] == '<') - { - // / / - std::string endofTable = ""; - std::string tableTag = html.substr(i, 4); //legth of "tr/td" - if(tableTag == "") - { - temp += "\n"; //new row -> new line - i = stitchText(html, temp, i+4); - if(i == -1) //EOF - break; - } - else if(tableTag == "" || tableTag == "") - { - temp += "\t"; // new cell -> tab between data - i = stitchText(html, temp, i+4); - if (i == -1) //EOF - break; - } - else if(tableTag == "text = temp; -} - -int Page::stitchText(std::string& from, std::string& to, int index) -{ - if (from[index] == '<') - { - std::string bTag = from.substr(index, 3); - if (bTag != "") - return index-1; //go back one step - for the main function to inc i - index += 3; - } - - while (from[index] != '<' && index < (int)from.length()) - { - if (from[index] == '&') - { - //  - std::string nbspChr = from.substr(index, 6); - if (nbspChr == " ") - { - index += 5; - from.at(index) = ' '; - } - - } - - if (endOfString(index,(int) from.length())) - return -1; //EOF - - else if (from[index] == '<') - return index - 1; //go back one step - for the main function to inc i - - if (from[index] != '\n') //check the actuall data before continue - to += from[index]; - index++; - } - - return index-1; -} -bool Page::endOfString(int index, int length) -{ - if(index < length) - return false; - return true; -} - -std::string Page::getString() -{ - return this->text; -} - -std::string Page::getTitle() -{ - return this->title; -} diff --git a/src/jce/jcedate.cpp b/src/jce/jcedate.cpp deleted file mode 100644 index af59cc5..0000000 --- a/src/jce/jcedate.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "jcedate.h" - -jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester) -{ - this->fSemester = fromSemester; - this->fYear = fromYear; - this->tSemester = toSemester; - this->tYear = toYear; -} - -void jceDate::setFYear(std::string fromYear) -{ - this->fYear = fromYear; -} - -void jceDate::setTYear(std::string toYear) -{ - this->tYear = toYear; -} - -void jceDate::setFSemester(std::string fromSemester) -{ - this->fSemester = fromSemester; -} - -void jceDate::setTSemester(std::string toSemester) -{ - this->tSemester = toSemester; -} - -jceDate::~jceDate() -{ - -} diff --git a/src/jce/jcedate.h b/src/jce/jcedate.h deleted file mode 100644 index 9a3fa55..0000000 --- a/src/jce/jcedate.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef JCEDATE_H -#define JCEDATE_H - -#include - -class jceDate -{ - -public: - - jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); - ~jceDate(); - - void setFYear(std::string fromYear); - void setTYear(std::string toYear); - void setFSemester(std::string fromSemester); - void setTSemester(std::string toSemester); - - std::string getFYear() { return this->fYear;} - std::string getTYear() { return this->tYear;} - std::string getFSemester() { return this->fSemester;} - std::string getTSemester() { return this->tSemester;} - -private: - std::string fYear; //from - std::string fSemester; - - std::string tYear; //to - std::string tSemester; - -}; - -#endif // JCEDATE_H diff --git a/src/connection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp similarity index 95% rename from src/connection/jcesslclient.cpp rename to src/jceConnection/jcesslclient.cpp index b1f2ca9..65ddb46 100644 --- a/src/connection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -1,132 +1,132 @@ -#include "jcesslclient.h" - -jceSSLClient::jceSSLClient() : flag(false), packet("") -{ - 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())); - -} - -bool jceSSLClient::makeConnect(std::string server, int port) -{ - QEventLoop loop; - QObject::connect(this, SIGNAL(encrypted()), &loop, SLOT(quit())); - if (isConnected()) - abort(); - if (isOpen()) - abort(); - - connectToHostEncrypted(server.c_str(), port); - loop.exec(); - return isConnected(); - -} -bool jceSSLClient::makeDiconnect() -{ - - abort(); - if (state() == QAbstractSocket::SocketState::ConnectedState) - { - flag = false; - } - else - flag = true; - - return flag; -} - - -bool jceSSLClient::isConnected() -{ - - return flag; -} - -bool jceSSLClient::sendData(std::string str) -{ - if (isConnected()) //if connected - { - write(str.c_str(),str.length()); - while (waitForBytesWritten()); - return true; - } - return false; -} -/** - * @brief jceSSLClient::recieveData - * @param str this variable will store the recieved data - * @param fast true for LOGIN ONLY, false to retrieve all data - * @return true if recieved data bigger than zero - */ -bool jceSSLClient::recieveData(std::string &str, bool fast) -{ - packet = ""; - bool sflag = false; - - if (fast) //fast connection, good for login only!! - { - 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())); - } - else - { - QString p; - while (waitForReadyRead(milisTimeOut)) - { - do - { - p = readAll(); - packet.append(p); - }while (p.size() > 0); - } - } - - str = packet.toStdString(); - if (str.size() > 0) - sflag = true; - - return sflag; - -} -void jceSSLClient::readIt() -{ - QString p; - do - { - p = readAll(); - packet.append(p); - }while (p.size() > 0); - - - -} -void jceSSLClient::setConnected() -{ - waitForEncrypted(); -} - -void jceSSLClient::setEncrypted() -{ - setReadBufferSize(10000); - setSocketOption(QAbstractSocket::KeepAliveOption,1); - flag = true; -} - -void jceSSLClient::setDisconnected() -{ - abort(); - flag = false; -} - - -void jceSSLClient::checkErrors(QAbstractSocket::SocketError) -{ - -} - +#include "jcesslclient.h" + +jceSSLClient::jceSSLClient() : flag(false), packet("") +{ + 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())); + +} + +bool jceSSLClient::makeConnect(std::string server, int port) +{ + QEventLoop loop; + QObject::connect(this, SIGNAL(encrypted()), &loop, SLOT(quit())); + if (isConnected()) + abort(); + if (isOpen()) + abort(); + + connectToHostEncrypted(server.c_str(), port); + loop.exec(); + return isConnected(); + +} +bool jceSSLClient::makeDiconnect() +{ + + abort(); + if (state() == QAbstractSocket::SocketState::ConnectedState) + { + flag = false; + } + else + flag = true; + + return flag; +} + + +bool jceSSLClient::isConnected() +{ + + return flag; +} + +bool jceSSLClient::sendData(std::string str) +{ + if (isConnected()) //if connected + { + write(str.c_str(),str.length()); + while (waitForBytesWritten()); + return true; + } + return false; +} +/** + * @brief jceSSLClient::recieveData + * @param str this variable will store the recieved data + * @param fast true for LOGIN ONLY, false to retrieve all data + * @return true if recieved data bigger than zero + */ +bool jceSSLClient::recieveData(std::string &str, bool fast) +{ + packet = ""; + bool sflag = false; + + if (fast) //fast connection, good for login only!! + { + 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())); + } + else + { + QString p; + while (waitForReadyRead(milisTimeOut)) + { + do + { + p = readAll(); + packet.append(p); + }while (p.size() > 0); + } + } + + str = packet.toStdString(); + if (str.size() > 0) + sflag = true; + + return sflag; + +} +void jceSSLClient::readIt() +{ + QString p; + do + { + p = readAll(); + packet.append(p); + }while (p.size() > 0); + + + +} +void jceSSLClient::setConnected() +{ + waitForEncrypted(); +} + +void jceSSLClient::setEncrypted() +{ + setReadBufferSize(10000); + setSocketOption(QAbstractSocket::KeepAliveOption,1); + flag = true; +} + +void jceSSLClient::setDisconnected() +{ + abort(); + flag = false; +} + + +void jceSSLClient::checkErrors(QAbstractSocket::SocketError) +{ + +} + diff --git a/src/connection/jcesslclient.h b/src/jceConnection/jcesslclient.h similarity index 94% rename from src/connection/jcesslclient.h rename to src/jceConnection/jcesslclient.h index b19ba10..6e73658 100644 --- a/src/connection/jcesslclient.h +++ b/src/jceConnection/jcesslclient.h @@ -1,39 +1,39 @@ -#ifndef JCESSLCLIENT_H -#define JCESSLCLIENT_H - -#include -#include -#include -#include - -#include -#include -#define milisTimeOut 3500 - -class jceSSLClient : QSslSocket -{ - Q_OBJECT -public: - jceSSLClient(); - - bool makeConnect(std::string server,int port); - bool isConnected(); - bool sendData(std::string str); - bool recieveData(std::string &str, bool fast); - bool makeDiconnect(); - -private slots: - void checkErrors(QAbstractSocket::SocketError); - void setConnected(); - void setEncrypted(); - void setDisconnected(); - void readIt(); - -private: - - bool flag; - QString packet; - -}; - -#endif // JCESSLCLIENT_H +#ifndef JCESSLCLIENT_H +#define JCESSLCLIENT_H + +#include +#include +#include +#include + +#include +#include +#define milisTimeOut 3500 + +class jceSSLClient : QSslSocket +{ + Q_OBJECT +public: + jceSSLClient(); + + bool makeConnect(std::string server,int port); + bool isConnected(); + bool sendData(std::string str); + bool recieveData(std::string &str, bool fast); + bool makeDiconnect(); + +private slots: + void checkErrors(QAbstractSocket::SocketError); + void setConnected(); + void setEncrypted(); + void setDisconnected(); + void readIt(); + +private: + + bool flag; + QString packet; + +}; + +#endif // JCESSLCLIENT_H diff --git a/src/jceData/Calendar/calendarCourse.cpp b/src/jceData/Calendar/calendarCourse.cpp new file mode 100644 index 0000000..5927a53 --- /dev/null +++ b/src/jceData/Calendar/calendarCourse.cpp @@ -0,0 +1,142 @@ +#include "calendarCourse.h" + +calendarCourse::calendarCourse(int serial, std::string name, std::string type, std::string lecturer, double points, + double semesterHours, std::string dayAndHour, + std::string room) : Course(serial,name, type,points) +{ + this->lecturer = lecturer; + this->semesterHours = semesterHours; + this->room = room; + setDayAndHour(dayAndHour); + +} +void calendarCourse::setDayAndHour(std::string phrase) +{ + int ctr = 0; + std::string temp = ""; + QTime timetemp; + char *tok; + char* textToTok = strdup(phrase.c_str()); + tok = strtok(textToTok, " -"); + while(tok != NULL) + { + temp = tok; + switch (ctr) + { + case 0: + setDay(temp); + break; + case 1: + timetemp = QTime::fromString(QString::fromStdString(temp),"hh:mm"); + setHourBegin(timetemp.hour()); + setMinutesBegin(timetemp.minute()); + break; + case 2: + timetemp = QTime::fromString(QString::fromStdString(temp),"hh:mm"); + setHourEnd(timetemp.hour()); + setMinutesEnd(timetemp.minute()); + break; + } + + ctr++; + tok = strtok(NULL, " -"); + } +} + +std::string calendarCourse::getLecturer() const +{ + return lecturer; +} + +void calendarCourse::setLecturer(const std::string &value) +{ + lecturer = value; +} +double calendarCourse::getSemesterHours() const +{ + return semesterHours; +} + +void calendarCourse::setSemesterHours(double value) +{ + semesterHours = value; +} +int calendarCourse::getHourBegin() const +{ + return hourBegin; +} + +void calendarCourse::setHourBegin(int value) +{ + hourBegin = value; +} +int calendarCourse::getMinutesBegin() const +{ + return minutesBegin; +} + +void calendarCourse::setMinutesBegin(int value) +{ + minutesBegin = value; +} +int calendarCourse::getHourEnd() const +{ + return hourEnd; +} + +void calendarCourse::setHourEnd(int value) +{ + hourEnd = value; +} +int calendarCourse::getMinutesEnd() const +{ + return minutesEnd; +} + +void calendarCourse::setMinutesEnd(int value) +{ + minutesEnd = value; +} + +std::string calendarCourse::courseToString() +{ + std::string courseText = ""; + courseText += " " + std::to_string(this->getSerialNum()); + courseText += " " + this->getName(); + courseText += " " + this->getType(); + courseText += " " + this->lecturer; + courseText += " " + std::to_string(this->getPoints()); + courseText += " " + std::to_string(this->semesterHours); + courseText += " " + this->day; + courseText += " " + std::to_string(this->hourBegin) + ":" + std::to_string(this->minutesBegin) + "-" + std::to_string(this->hourEnd) + ":" + std::to_string(this->minutesEnd); + courseText += " " + this->room; + courseText += "\n"; + return courseText; + +} +std::string calendarCourse::getDay() const +{ + return day; +} + +void calendarCourse::setDay(const std::string &value) +{ + day = value; +} + +std::string calendarCourse::getRoom() const +{ + return room; +} + +void calendarCourse::setRoom(const std::string &value) +{ + room = value; +} + + + + + + + diff --git a/src/jceData/Calendar/calendarCourse.h b/src/jceData/Calendar/calendarCourse.h new file mode 100644 index 0000000..4ecb18a --- /dev/null +++ b/src/jceData/Calendar/calendarCourse.h @@ -0,0 +1,69 @@ +#ifndef CALENDARCOURSE_H +#define CALENDARCOURSE_H + +#include "../course.h" +#include +#include +#include + +#include + +#define CALENDAR_COURSE_FIELDS 8 + +class calendarCourse : public Course +{ +public: + enum CourseScheme + { + SERIAL, + NAME, + TYPE, + LECTURER, + POINTS, + SEM_HOURS, + DAY_AND_HOURS, + ROOM + }; + + calendarCourse(int serial, std::string name, std::string type, std::string lecturer, + double points, double semesterHours, std::string dayAndHour, std::string room); + ~calendarCourse(){} + + std::string getDay() const; + std::string getLecturer() const; + std::string getRoom() const; + double getSemesterHours() const; + int getHourBegin() const; + int getMinutesBegin() const; + int getHourEnd() const; + int getMinutesEnd() const; + + void setDay(const std::string &value); + void setLecturer(const std::string &value); + void setRoom(const std::string &value); + void setSemesterHours(double value); + void setHourBegin(int value); + void setMinutesBegin(int value); + void setHourEnd(int value); + void setMinutesEnd(int value); + + std::string courseToString(); + + +private: + + void setDayAndHour(std::string phrase); + + std::string lecturer; + double semesterHours; + std::string day; + int hourBegin; + int minutesBegin; + int hourEnd; + int minutesEnd; + std::string room; + +}; + + +#endif // CALENDARCOURSE_H diff --git a/src/jceData/Calendar/calendarPage.cpp b/src/jceData/Calendar/calendarPage.cpp new file mode 100644 index 0000000..917fb8c --- /dev/null +++ b/src/jceData/Calendar/calendarPage.cpp @@ -0,0 +1,111 @@ +#include "calendarPage.h" + +CalendarPage::CalendarPage(std::string html) +{ + courses = new std::list(); + tempHtml = getString(html); + tempHtml = tokenToLines(tempHtml); + std::cout << "last one..." << std::endl; + calendarListInit(tempHtml); +} + +std::string CalendarPage::htmlToString() +{ + return tempHtml; +} + +std::string CalendarPage::tokenToLines(std::string &textToPhrase) +{ + int ctr = 0; + std::string temp = ""; + char *tok; + char* textToTok = strdup(textToPhrase.c_str()); + tok = strtok(textToTok, "\n"); + while(tok != NULL) + { + //amount of data before the actual needed data and no empty lines + if (strcmp(tok," \t ") != 0) + { + temp += tok; + temp += "\n"; + } + ctr++; + tok = strtok(NULL, "\n"); + } + return temp; +} + +void CalendarPage::calendarListInit(std::string &linesTokinzedString) +{ + std::list stringHolder; + std::string temp; + calendarCourse * cTemp = NULL; + char* tok; + char* textToTok = strdup(linesTokinzedString.c_str()); + tok = strtok(textToTok,"\n"); + while (tok != NULL) + { + temp = tok; + stringHolder.push_back(temp); + tok = strtok(NULL, "\n"); + } + for(std::string temp: stringHolder) + { + cTemp = lineToCourse(temp); + if (cTemp != NULL) + courses->push_back(cTemp); + } +} + +calendarCourse *CalendarPage::lineToCourse(std::string line) +{ + + calendarCourse *tempC = NULL; + std::string templinearray[CALENDAR_COURSE_FIELDS];//[serial,name,type,lecturer,points,semesterhours,dayandhours,room] + int serial; + double points,semesterHours; + std::string name,type, lecturer,dayAndHour,room; + std::string tempS = ""; + std::string emptyTab = " "; + int i = 0; + char* tok; + char* cLine = strdup(line.c_str()); + tok = strtok(cLine, "\t"); + while(tok != NULL) + { + + tempS = tok; + if (i>=1) + templinearray[i-1] = tempS; + i++; + if (i > 8) + break; + tok=strtok(NULL, "\t"); + } + if (templinearray[0] == "") //empty phrasing + return NULL; + for (int p = 0; p < 8; ++p) + { + std::cout << "index : " << p << " is: " << templinearray[p] << std::endl; + } + serial = stoi(templinearray[calendarCourse::CourseScheme::SERIAL]); + name = templinearray[calendarCourse::CourseScheme::NAME]; + type = templinearray[calendarCourse::CourseScheme::TYPE]; + lecturer = templinearray[calendarCourse::CourseScheme::LECTURER]; + + if (templinearray[calendarCourse::CourseScheme::POINTS].compare(" ") == 0) + points = stod(templinearray[calendarCourse::CourseScheme::POINTS]); + else + points = 0; + if (templinearray[calendarCourse::CourseScheme::SEM_HOURS].compare(" ") == 0) + semesterHours = stod(templinearray[calendarCourse::CourseScheme::SEM_HOURS]); + else + semesterHours = 0; + dayAndHour = templinearray[calendarCourse::CourseScheme::DAY_AND_HOURS]; + room = templinearray[calendarCourse::CourseScheme::ROOM]; + + + tempC = new calendarCourse(serial,name,type,lecturer,points,semesterHours,dayAndHour,room); + + return tempC; +} diff --git a/src/jceData/Calendar/calendarPage.h b/src/jceData/Calendar/calendarPage.h new file mode 100644 index 0000000..00f5187 --- /dev/null +++ b/src/jceData/Calendar/calendarPage.h @@ -0,0 +1,26 @@ +#ifndef CALENDARPAGE_H +#define CALENDARPAGE_H + +#include "../page.h" +#include "calendarCourse.h" +#include +#include //strlen and strtok to phrase the html file +#include //checks if character is numeric + +class CalendarPage : public Page +{ +public: + CalendarPage(std::string html); + std::string htmlToString(); + std::list* getCourses() { return courses; } + +private: + std::string tokenToLines(std::string& textToPhrase); + void calendarListInit(std::string& linesTokinzedString); + calendarCourse* lineToCourse(std::string line); + + std::string tempHtml; + std::list* courses; +}; + +#endif // CALENDARPAGE_H diff --git a/src/jceData/Grades/gradeCourse.cpp b/src/jceData/Grades/gradeCourse.cpp new file mode 100644 index 0000000..7ce4284 --- /dev/null +++ b/src/jceData/Grades/gradeCourse.cpp @@ -0,0 +1,36 @@ +#include "gradeCourse.h" + +gradeCourse::gradeCourse(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions) : Course(serial,name,type,points) +{ + this->hours = hours; + this->grade = grade; + this->additions = additions; +} + +gradeCourse::~gradeCourse() +{ + +} +double gradeCourse::getGrade() const +{ + double noGrade = NO_GRADE_YET; + if (grade == noGrade) + return 0; + else + return this->grade; +} + +void gradeCourse::setHours(double hours) +{ + this->hours = hours; +} + +void gradeCourse::setGrade(double grade) +{ + this->grade = grade; +} + +void gradeCourse::setAdditions(std::string additions) +{ + this->additions = additions; +} diff --git a/src/grades/Course.h b/src/jceData/Grades/gradeCourse.h similarity index 53% rename from src/grades/Course.h rename to src/jceData/Grades/gradeCourse.h index af15424..48d51dc 100644 --- a/src/grades/Course.h +++ b/src/jceData/Grades/gradeCourse.h @@ -1,64 +1,53 @@ -#ifndef COURSE_H -#define COURSE_H - -/* This Code Made By Sagi Dayan - * SagiDayan@gmail.com - * - * Minor changes has been made by Liran Ben Gida - * LiranBG@gmail.com -*/ - -#include -#include -#include - -#define COURSE_FIELDS 7 -#define NO_GRADE_YET 101; - - -class Course{ - -public: - enum CourseScheme - { - SERIAL, - NAME, - TYPE, - POINTS, - HOURS, - GRADE, - ADDITION - }; - - Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions); - ~Course(); - - int getSerialNum() const {return this->serialNum;} - std::string getName() const {return this->name;} - std::string getType() const {return this->type;} - double getPoints() const {return this->points;} - double getHours() const {return this->hours;} - double getGrade() const ; - std::string getAddidtions() const {return this->additions;} - - void setName(std::string name); - void setType(std::string type); - void setPoints(double points); - void setHours(double hours); - void setGrade(double grade); - void setAdditions(std::string additions); - -private: - - int serialNum; - std::string name; - std::string type; - double points; - double hours; - double grade; - std::string additions; -}; - - - -#endif +#ifndef GRADE_COURSE_H +#define GRADE_COURSE_H + +/* This Code Made By Sagi Dayan + * SagiDayan@gmail.com + * + * Minor changes has been made by Liran Ben Gida + * LiranBG@gmail.com +*/ +#include "../course.h" +#include +#include +#include + +#define COURSE_FIELDS 7 +#define NO_GRADE_YET 101; + + +class gradeCourse : public Course { + +public: + enum CourseScheme + { + SERIAL, + NAME, + TYPE, + POINTS, + HOURS, + GRADE, + ADDITION + }; + + gradeCourse(int serial, std::string name, std::string type, double points,double hours, double grade, std::string additions); + ~gradeCourse(); + + double getHours() const {return this->hours;} + double getGrade() const ; + std::string getAddidtions() const {return this->additions;} + + void setHours(double hours); + void setGrade(double grade); + void setAdditions(std::string additions); + +private: + + double hours; + double grade; + std::string additions; +}; + + + +#endif diff --git a/src/grades/GradePage.cpp b/src/jceData/Grades/gradePage.cpp similarity index 68% rename from src/grades/GradePage.cpp rename to src/jceData/Grades/gradePage.cpp index aef8fc3..14c7234 100644 --- a/src/grades/GradePage.cpp +++ b/src/jceData/Grades/gradePage.cpp @@ -1,178 +1,172 @@ -#include "GradePage.h" - -GradePage::GradePage(std::string html) : Page(html) -{ - courses = new std::list(); - tempHtml = getString(); - genList(); - -} -GradePage::~GradePage() -{ - for(Course* c : *courses) - delete c; - delete courses; -} -void GradePage::genList() -{ - - this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA ); - - coursesListInit(this->tempHtml); - -} -void GradePage::addCourse(Course *a) -{ - GradePage::courses->push_back(a); - return; -} - -void GradePage::removeCourse(std::string courseSerialID) -{ - for(Course* c : *courses) - { - if (c->getSerialNum() == stoi(courseSerialID)) - { - courses->remove(c); - delete c; - return; - } - } - -} -void GradePage::coursesListInit(std::string& linesTokinzedString) -{ - std::list stringHolder; - std::string temp; - Course* cTemp = NULL; - char* tok; - char* textToTok = strdup(linesTokinzedString.c_str()); - tok = strtok(textToTok,"\n"); - while (tok != NULL) - { - temp = tok; - stringHolder.push_back(temp); - tok = strtok(NULL, "\n"); - } - for(std::string temp: stringHolder) - { - cTemp = lineToCourse(temp); - if (cTemp != NULL) - addCourse(cTemp); - } -} - -std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine) -{ - int ctr = 0; - std::string temp = ""; - char *tok; - char* textToTok = strdup(textToPhrase.c_str()); - tok = strtok(textToTok, "\n"); - while(tok != NULL) - { - //amount of data before the actual needed data and no empty lines - if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0)) - { - temp += tok; - temp += "\n"; - } - ctr++; - tok = strtok(NULL, "\n"); - } - return temp; - -} -Course* GradePage::lineToCourse(std::string line) -{ - Course *tempC = NULL; - std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] - int serial; - double points,hours,grade; - std::string name,type, additions; - std::string tempS = ""; - int i = 0; - char* tok; - char* cLine = strdup(line.c_str()); - tok = strtok(cLine, "\t"); - while(tok != NULL) - { - - tempS = tok; - if (i == 1) //skip the tokenizing loop just once - { - tempS = ""; - char *tokTemp; - tokTemp = tok; - - while (!(isdigit((int)*tokTemp))) - tokTemp++; - - while (isdigit((int)*tokTemp)) - { - tempS += *tokTemp; - tokTemp++; - } - templinearray[i-1] = tempS; - templinearray[i] = tokTemp; - - } - else if (i > 1) - templinearray[i] = tempS; - i++; - tok=strtok(NULL, "\t"); - } - if (templinearray[0] == "") //empty phrasing - return NULL; - - serial = stoi(templinearray[Course::CourseScheme::SERIAL]); - - name = templinearray[Course::CourseScheme::NAME]; - type = templinearray[Course::CourseScheme::TYPE]; - - points = stod(templinearray[Course::CourseScheme::POINTS]); - hours = stod(templinearray[Course::CourseScheme::HOURS]); - - if (isGradedYet(templinearray[Course::CourseScheme::GRADE])) - grade = stod(templinearray[Course::CourseScheme::GRADE]); - else - grade = NO_GRADE_YET; - - additions = templinearray[Course::CourseScheme::ADDITION]; - - tempC = new Course(serial,name,type,points,hours,grade,additions); - return tempC; -} - -//checking if one of the chars inside grade is not a number -bool GradePage::isGradedYet(std::string grade) -{ - if (strlen(grade.c_str()) <= 1) - return false; - - for (char c: grade) - { - if (c == '\0') - break; - if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 - return false; - - } - return true; -} -double GradePage::getAvg() -{ - double avg = 0; - double points = 0; - for(Course* c : *courses) - { - if ((c->getGrade() != 0)) - { - avg += c->getGrade() * c->getPoints(); - points += c->getPoints(); - } - } - - avg /= points; - return avg; -} +#include "gradePage.h" + +GradePage::GradePage(std::string html) : Page() +{ + this->courses = new std::list(); + this->tempHtml = getString(html); + this->tempHtml = tokenToLines(this->tempHtml); + coursesListInit(this->tempHtml); + +} +GradePage::~GradePage() +{ + for(Course* c : *courses) + delete c; + delete courses; +} + +void GradePage::addCourse(gradeCourse *a) +{ + GradePage::courses->push_back(a); + return; +} + +void GradePage::removeCourse(std::string courseSerialID) +{ + for(gradeCourse* c : *courses) + { + if (c->getSerialNum() == stoi(courseSerialID)) + { + courses->remove(c); + delete c; + return; + } + } + +} +void GradePage::coursesListInit(std::string& linesTokinzedString) +{ + std::list stringHolder; + std::string temp; + gradeCourse* cTemp = NULL; + char* tok; + char* textToTok = strdup(linesTokinzedString.c_str()); + tok = strtok(textToTok,"\n"); + while (tok != NULL) + { + temp = tok; + stringHolder.push_back(temp); + tok = strtok(NULL, "\n"); + } + for(std::string temp: stringHolder) + { + cTemp = lineToCourse(temp); + if (cTemp != NULL) + addCourse(cTemp); + } +} + +std::string GradePage::tokenToLines(std::string& textToPhrase) +{ + int ctr = 0; + std::string temp = ""; + char *tok; + char* textToTok = strdup(textToPhrase.c_str()); + tok = strtok(textToTok, "\n"); + while(tok != NULL) + { + //amount of data before the actual needed data and no empty lines + if (strcmp(tok," \t ") != 0) + { + temp += tok; + temp += "\n"; + } + ctr++; + tok = strtok(NULL, "\n"); + } + return temp; + +} +gradeCourse* GradePage::lineToCourse(std::string line) +{ + gradeCourse *tempC = NULL; + std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] + int serial; + double points,hours,grade; + std::string name,type, additions; + std::string tempS = ""; + int i = 0; + char* tok; + char* cLine = strdup(line.c_str()); + tok = strtok(cLine, "\t"); + while(tok != NULL) + { + + tempS = tok; + if (i == 1) //skip the tokenizing loop just once + { + tempS = ""; + char *tokTemp; + tokTemp = tok; + + while (!(isdigit((int)*tokTemp))) + tokTemp++; + + while (isdigit((int)*tokTemp)) + { + tempS += *tokTemp; + tokTemp++; + } + templinearray[i-1] = tempS; + templinearray[i] = tokTemp; + + } + else if (i > 1) + templinearray[i] = tempS; + i++; + tok=strtok(NULL, "\t"); + } + if (templinearray[0] == "") //empty phrasing + return NULL; + + serial = stoi(templinearray[gradeCourse::CourseScheme::SERIAL]); + + name = templinearray[gradeCourse::CourseScheme::NAME]; + type = templinearray[gradeCourse::CourseScheme::TYPE]; + + points = stod(templinearray[gradeCourse::CourseScheme::POINTS]); + hours = stod(templinearray[gradeCourse::CourseScheme::HOURS]); + + if (isGradedYet(templinearray[gradeCourse::CourseScheme::GRADE])) + grade = stod(templinearray[gradeCourse::CourseScheme::GRADE]); + else + grade = NO_GRADE_YET; + + additions = templinearray[gradeCourse::CourseScheme::ADDITION]; + + tempC = new gradeCourse(serial,name,type,points,hours,grade,additions); + return tempC; +} + +//checking if one of the chars inside grade is not a number +bool GradePage::isGradedYet(std::string grade) +{ + if (strlen(grade.c_str()) <= 1) + return false; + + for (char c: grade) + { + if (c == '\0') + break; + if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9 + return false; + + } + return true; +} +double GradePage::getAvg() +{ + double avg = 0; + double points = 0; + for(gradeCourse* c : *courses) + { + if ((c->getGrade() != 0)) + { + avg += c->getGrade() * c->getPoints(); + points += c->getPoints(); + } + } + + avg /= points; + return avg; +} diff --git a/src/grades/GradePage.h b/src/jceData/Grades/gradePage.h similarity index 62% rename from src/grades/GradePage.h rename to src/jceData/Grades/gradePage.h index 2a60481..f13cc86 100644 --- a/src/grades/GradePage.h +++ b/src/jceData/Grades/gradePage.h @@ -1,48 +1,45 @@ -#ifndef GRADE_PAGE_H -#define GRADE_PAGE_H - -/* This Code Made By Sagi Dayan - * SagiDayan@gmail.com - * - * Minor changes has been made by Liran Ben Gida - * LiranBG@gmail.com -*/ - -#include "Page.h" -#include "Course.h" - -#include -#include //strlen and strtok to phrase the html file -#include //checks if character is numeric - -#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5 - -class GradePage : public Page -{ - -public: - GradePage(std::string html); - ~GradePage(); - - void addCourse(Course *); - void removeCourse(std::string courseSerialID); - double getAvg(); - - std::list* getCourses() { return courses; } - -private: - - void genList(); - std::string tokenToLines(std::string& textToPhrase,int fromLine = 0); - void coursesListInit(std::string& linesTokinzedString); - Course* lineToCourse(std::string line); - - bool isGradedYet(std::string grade); - - std::list* courses; - std::string tempHtml; - -}; - - -#endif +#ifndef GRADE_PAGE_H +#define GRADE_PAGE_H + +/* This Code Made By Sagi Dayan + * SagiDayan@gmail.com + * + * Minor changes has been made by Liran Ben Gida + * LiranBG@gmail.com +*/ + +#include "../page.h" +#include "../Grades/gradeCourse.h" + +#include +#include //strlen and strtok to phrase the html file +#include //checks if character is numeric + +class GradePage : public Page +{ + +public: + GradePage(std::string html); + ~GradePage(); + + void addCourse(gradeCourse *); + void removeCourse(std::string courseSerialID); + double getAvg(); + + std::list* getCourses() { return courses; } + +private: + + std::string tokenToLines(std::string& textToPhrase); + void coursesListInit(std::string& linesTokinzedString); + gradeCourse* lineToCourse(std::string line); + + bool isGradedYet(std::string grade); + + std::list* courses; + std::string tempHtml; + +}; + + +#endif diff --git a/src/grades/Page.h b/src/jceData/Page.h similarity index 77% rename from src/grades/Page.h rename to src/jceData/Page.h index da6cf2d..db584d0 100644 --- a/src/grades/Page.h +++ b/src/jceData/Page.h @@ -1,42 +1,39 @@ -#ifndef PAGE_H -#define PAGE_H - -/* This Code Made By Sagi Dayan - * SagiDayan@gmail.com - * - * Minor changes has been made by Liran Ben Gida - * LiranBG@gmail.com -*/ - -#include -#include - -class Page -{ - -public: - - ~Page() {} - -protected: - Page(std::string& html); - std::string getString(); - std::string getTitle(); - void makeText(std::string& html); - - -private: - - - int findTitle(std::string& from, int index); - int runToActualText(std::string& from, int index); - void manageTableContent(std::string& html, int index); - int stitchText(std::string& from, std::string& to, int index); - bool endOfString(int index, int length); - - std::string text; - std::string title; - -}; - -#endif +#ifndef PAGE_H +#define PAGE_H + +/* This Code Made By Sagi Dayan + * SagiDayan@gmail.com + * + * Minor changes has been made by Liran Ben Gida + * LiranBG@gmail.com +*/ + +#include +#include + +class Page +{ + +public: + + ~Page() {} + +protected: + Page(); + std::string getString(std::string& htmlToPhrased); + void makeText(std::string& html); + + +private: + + int runToActualText(std::string& from, int index); + void manageTableContent(std::string& html, int index); + int stitchText(std::string& from, std::string& to, int index); + bool endOfString(int index, int length); + + std::string text; + std::string title; + +}; + +#endif diff --git a/src/jceData/course.h b/src/jceData/course.h new file mode 100644 index 0000000..fa949f8 --- /dev/null +++ b/src/jceData/course.h @@ -0,0 +1,49 @@ +#ifndef COURSE_H +#define COURSE_H + +/* This Code Made By Sagi Dayan + * SagiDayan@gmail.com + * + * minor changes by Liran Ben Gida + * LiranBG@gmail.com +*/ + +#include +#include +#include + + +class Course { + +public: + + Course(int serial,std::string name, std::string type, double points) { + this->serialNum = serial; + this->name = name; + this->type = type; + this->points = points; + } + virtual ~Course() { } + + int getSerialNum() const {return this->serialNum;} + virtual std::string getName() const {return this->name;} + virtual std::string getType() const {return this->type;} + virtual double getPoints() const {return this->points;} + + virtual void setName(std::string name) { this->name = name;} + virtual void setType(std::string type){ this->type = type;} + virtual void setPoints(double points){ this->points = points;} + + +private: + + int serialNum; + std::string name; + std::string type; + double points; + +}; + + + +#endif diff --git a/src/jceData/page.cpp b/src/jceData/page.cpp new file mode 100644 index 0000000..1a01ae1 --- /dev/null +++ b/src/jceData/page.cpp @@ -0,0 +1,144 @@ +#include "page.h" + +Page::Page() +{ + +} +std::string Page::getString(std::string& htmlToPhrased) +{ + makeText(htmlToPhrased); + return this->text; +} +void Page::makeText(std::string& html) +{ + int index = 0; + index = runToActualText(html, index); //set index into the actual place where the data is + manageTableContent(html, index); +} + +int Page::runToActualText(std::string& from, int index) +{ + while (index < (int)from.length()) + { + if (from[index] == '<') + { + if (from.substr(index,7) == "") + return index+7; + } + index++; + } +// while(index < (int)from.length()) +// { +// if(from[index] == '<') +// { +// index++; +// if(from[index] == '!') +// { +// //!--FileName +// std::string bodyTag = from.substr(index, 11); //!--FileName + +// if(bodyTag == "!--FileName") //check if the tag is body tag +// { +// while(from[index] != '>') +// index++; +// return index; +// } +// } +// } +// index++; +//} + return -1; +} + +void Page::manageTableContent(std::string& html, int index) +{ + std::string temp; + for (int i = index; i < (int)html.length(); i++) + { + if(html[i] == '<') + { + // / / + std::string endofTable = ""; + std::string tableTag = html.substr(i, 4); //legth of "tr/td" + if(tableTag == "") + { + temp += "\n"; //new row -> new line + i = stitchText(html, temp, i+4); + if(i == -1) //EOF + break; + } + else if(tableTag == "" || tableTag == "") + { + temp += "\t"; // new cell -> tab between data + if (html.substr(i, 6) == "text = temp; +} + +int Page::stitchText(std::string& from, std::string& to, int index) +{ + if (from[index] == '<') + { + std::string bTag = from.substr(index, 3); + if (bTag != "") + return index-1; //go back one step - for the main function to inc i + index += 3; + } + + while (from[index] != '<' && index < (int)from.length()) + { + if (from[index] == '&') + { + //  + std::string nbspChr = from.substr(index, 6); + if (nbspChr == " ") + { + index += 5; + from.at(index) = ' '; + } + + } + + if (endOfString(index,(int) from.length())) + return -1; //EOF + + else if (from[index] == '<') + return index - 1; //go back one step - for the main function to inc i + + if (from[index] != '\n') //check the actuall data before continue + to += from[index]; + index++; + } + + return index-1; +} +bool Page::endOfString(int index, int length) +{ + if(index < length) + return false; + return true; +} diff --git a/src/jce/jceLoginHtmlScripts.h b/src/jceSettings/jceLoginHtmlScripts.h similarity index 62% rename from src/jce/jceLoginHtmlScripts.h rename to src/jceSettings/jceLoginHtmlScripts.h index 8700049..62f44b3 100644 --- a/src/jce/jceLoginHtmlScripts.h +++ b/src/jceSettings/jceLoginHtmlScripts.h @@ -1,72 +1,87 @@ -#ifndef JCELOGINHTMLSCRIPTS_H -#define JCELOGINHTMLSCRIPTS_H - -#include - -#define dst_host "yedion.jce.ac.il" -#define dst_port 443 - -#include "../user.h" - -class jceLoginHtmlScripts -{ - -private: - - jceLoginHtmlScripts(); - -public: - - static std::string makeRequest(std::string parameters) - { - std::string msg; - msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n"; - msg += "Host: " + std::string(dst_host) + "\r\n"; - msg += "Content-Type: application/x-www-form-urlencoded\r\n"; - msg += "Content-Length: " + to_string(parameters.length()) + "\r\n"; - msg += "Proxy-Connection: Keep-Alive\r\n"; - msg += "Accept-Charset: utf-8"; - msg += "Accept: text/plain\r\n"; - msg += "Connection: Keep-Alive\r\n"; - msg += "\r\n"; - msg += parameters; - return msg; - } - - const static std::string getFirstValidationStep(const user &usr) - { - std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N"; - parameters += usr.getUsername(); - parameters += ",-N"; - parameters += usr.getPassword(); - return parameters; - } - - const static std::string getSecondValidationStep(const user &usr) - { - std::string parameters; - parameters = "prgname=LoginValidtion1&Arguments=-N"; - parameters += usr.getUserID(); - parameters += ",-A,-N"; - parameters += usr.getHashedPassword(); - parameters += ",-A,-A"; - return parameters; - } - const static std::string getGradesPath(const user &usr) - { - std::string parameters; - parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&"; - parameters += "TZ=" + usr.getUserID() + "&"; - parameters += "UNIQ=" + usr.getHashedPassword() + "&"; - parameters += "R1C2=" + usr.date->getFYear() + "&"; - parameters += "R1C1=" + usr.date->getTYear() + "&"; - parameters += "R1C3=" + usr.date->getTSemester() + "&"; - parameters += "R1C4=" + usr.date->getFSemester() + "&"; - parameters += "R1C5=0"; - return parameters; - } - - -}; - -#endif // JCELOGINHTMLSCRIPTS_H +#ifndef JCELOGINHTMLSCRIPTS_H +#define JCELOGINHTMLSCRIPTS_H + +#include + +#define dst_host "yedion.jce.ac.il" +#define dst_port 443 + +#include "./src/jceSettings/user.h" + +class jceLoginHtmlScripts +{ + +private: + + jceLoginHtmlScripts(); + +public: + + static std::string makeRequest(std::string parameters) + { + std::string msg; + msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n"; + msg += "Host: " + std::string(dst_host) + "\r\n"; + msg += "Content-Type: application/x-www-form-urlencoded\r\n"; + msg += "Content-Length: " + to_string(parameters.length()) + "\r\n"; + msg += "Proxy-Connection: Keep-Alive\r\n"; + msg += "Accept-Charset: utf-8"; + msg += "Accept: text/plain\r\n"; + msg += "Connection: Keep-Alive\r\n"; + msg += "\r\n"; + msg += parameters; + return msg; + } + + const static std::string getFirstValidationStep(const user &usr) + { + std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N"; + parameters += usr.getUsername(); + parameters += ",-N"; + parameters += usr.getPassword(); + return parameters; + } + + const static std::string getSecondValidationStep(const user &usr) + { + std::string parameters; + parameters = "prgname=LoginValidtion1&Arguments=-N"; + parameters += usr.getUserID(); + parameters += ",-A,-N"; + parameters += usr.getHashedPassword(); + parameters += ",-A,-A"; + return parameters; + } + const static std::string getGradesPath(const user &usr, + int fromYear, + int toYear, + int fromSemester, + int toSemester) + { + std::string parameters; + parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&"; + parameters += "TZ=" + usr.getUserID() + "&"; + parameters += "UNIQ=" + usr.getHashedPassword() + "&"; + parameters += "R1C2=" + std::to_string(fromYear) + "&"; + parameters += "R1C1=" + std::to_string(toYear) + "&"; + parameters += "R1C3=" + std::to_string(toSemester) + "&"; + parameters += "R1C4=" + std::to_string(fromSemester) + "&"; + parameters += "R1C5=0"; + return parameters; + } + const static std::string getCalendar(const user &usr,int year, int semester) + { + std::string parameters; + parameters = "PRGNAME=Bitsua_maarechet_shaot&ARGUMENTS=TZ,UNIQ,MisparSheilta,R1C1,R1C2&"; + parameters += "TZ=" + usr.getUserID() + "&"; + parameters += "UNIQ=" + usr.getHashedPassword() + "&"; + parameters += "MisparSheilta=3&"; + parameters += "R1C1=" + std::to_string(year) + "&"; + parameters += "R1C2=" + std::to_string(semester) + "&"; + return parameters; + } + + +}; + +#endif // JCELOGINHTMLSCRIPTS_H diff --git a/src/jce/jcelogin.cpp b/src/jceSettings/jcelogin.cpp similarity index 88% rename from src/jce/jcelogin.cpp rename to src/jceSettings/jcelogin.cpp index 5828553..161cdea 100644 --- a/src/jce/jcelogin.cpp +++ b/src/jceSettings/jcelogin.cpp @@ -1,213 +1,229 @@ -#include "jcelogin.h" - -jceLogin::jceLogin(user * username) -{ - this->recieverPage = new std::string(); - this->jceA = username; - this->JceConnector = new jceSSLClient(); -} - -jceLogin::~jceLogin() -{ - 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. - * throws error upon the given error from JCE website or Socket error - */ -void jceLogin::makeConnection() throw (jceStatus) -{ - if (this->recieverPage == NULL) - this->recieverPage = new std::string(); - - if (JceConnector->makeConnect(dst_host,dst_port) == false) - throw jceStatus::ERROR_ON_OPEN_SOCKET; - - int returnMode; - jceStatus status = jceStatus::JCE_NOT_CONNECTED; - - returnMode = checkConnection(); - if (returnMode == true) //connected to host - { - 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_VALIDATION_PASSED; - returnMode = makeSecondVisit(); - if (returnMode == true) //siging in the website - { - status = jceStatus::JCE_YOU_ARE_IN; - setLoginFlag(true); - } - else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) - { - status = jceLogin::ERROR_ON_GETTING_INFO; - } - else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) - { - status = jceLogin::ERROR_ON_SEND_REQUEST; - } - else - status = jceStatus::ERROR_ON_VALIDATION; - } - else - status = jceStatus::ERROR_ON_VALIDATION; - - } - else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) - { - status = jceLogin::ERROR_ON_GETTING_INFO; - } - else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) - { - status = jceLogin::ERROR_ON_SEND_REQUEST; - } - else - status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; - - } - else - status = jceStatus::JCE_NOT_CONNECTED; - - //we throw status even if we are IN! - throw status; - -} - -bool jceLogin::checkConnection() -{ - if (JceConnector->isConnected()) - return true; - - return false; -} - -void jceLogin::reConnect() throw (jceStatus) -{ - closeAll(); - if (this->JceConnector != NULL) - delete JceConnector; - this->recieverPage = new std::string(); - this->JceConnector = new jceSSLClient(); - try - { - - makeConnection(); - } - catch (jceLogin::jceStatus &a) - { - throw a; - } -} - -void jceLogin::closeAll() -{ - JceConnector->makeDiconnect(); - delete recieverPage; - recieverPage = NULL; - loginFlag = false; - -} - -int jceLogin::makeFirstVisit() -{ - std::string usr = jceA->getUsername(); - std::string psw = jceA->getPassword(); - if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) - { - if (!JceConnector->recieveData(*recieverPage,true)) - return jceLogin::ERROR_ON_GETTING_INFO; - } - else - return jceLogin::ERROR_ON_SEND_REQUEST; - - return true; -} - -int jceLogin::makeSecondVisit() -{ - std::string usrid=jceA->getUserID(); - std::string pswid=jceA->getHashedPassword(); - if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) - { - if (!(JceConnector->recieveData(*recieverPage,true))) - return jceLogin::ERROR_ON_GETTING_INFO; - - return true; - } - else - return jceLogin::ERROR_ON_SEND_REQUEST; - - return true; -} - -int jceLogin::getGrades() -{ - if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA))))) - { - 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; - - return true; - -} - -void jceLogin::setLoginFlag(bool x) -{ - this->loginFlag = x; -} -bool jceLogin::isLoginFlag() const -{ - return this->loginFlag; -} - -std::string jceLogin::getPage() -{ - return *recieverPage; -} - -/** - * @brief jceLogin::checkValidation Made by Nadav Luzzato - * @return true if second validation step is right - */ -bool jceLogin::checkValidation() -{ - //finds the hashed password - std::size_t hasspass_position1,hasspass_position2; - - if ((hasspass_position1 = recieverPage->find("-A,-N")) == string::npos) - return false; - hasspass_position1 += 5; - if ((hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1)) == string::npos) - return false; - - std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); - jceA->setHashedPassword(hasspass); - - //finds the user id - std::size_t id_position1 = recieverPage->find("value=\"-N", 0); - id_position1 += 9; - std::size_t id_position2 = recieverPage->find(",-A", id_position1); - if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos)) - { - std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1); - jceA->setUserID(hassid); - } - if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty())) - return false; - - return true; -} +#include "jcelogin.h" + +jceLogin::jceLogin(user * username) +{ + this->recieverPage = new std::string(); + this->jceA = username; + this->JceConnector = new jceSSLClient(); +} + +jceLogin::~jceLogin() +{ + 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. + * throws error upon the given error from JCE website or Socket error + */ +void jceLogin::makeConnection() throw (jceStatus) +{ + if (this->recieverPage == NULL) + this->recieverPage = new std::string(); + + if (JceConnector->makeConnect(dst_host,dst_port) == false) + throw jceStatus::ERROR_ON_OPEN_SOCKET; + + int returnMode; + jceStatus status = jceStatus::JCE_NOT_CONNECTED; + + returnMode = checkConnection(); + if (returnMode == true) //connected to host + { + 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_VALIDATION_PASSED; + returnMode = makeSecondVisit(); + if (returnMode == true) //siging in the website + { + status = jceStatus::JCE_YOU_ARE_IN; + setLoginFlag(true); + } + else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) + { + status = jceLogin::ERROR_ON_GETTING_INFO; + } + else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) + { + status = jceLogin::ERROR_ON_SEND_REQUEST; + } + else + status = jceStatus::ERROR_ON_VALIDATION; + } + else + status = jceStatus::ERROR_ON_VALIDATION; + + } + else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) + { + status = jceLogin::ERROR_ON_GETTING_INFO; + } + else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) + { + status = jceLogin::ERROR_ON_SEND_REQUEST; + } + else + status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; + + } + else + status = jceStatus::JCE_NOT_CONNECTED; + + //we throw status even if we are IN! + throw status; + +} + +bool jceLogin::checkConnection() +{ + if (JceConnector->isConnected()) + return true; + + return false; +} + +void jceLogin::reConnect() throw (jceStatus) +{ + closeAll(); + if (this->JceConnector != NULL) + delete JceConnector; + this->recieverPage = new std::string(); + this->JceConnector = new jceSSLClient(); + try + { + + makeConnection(); + } + catch (jceLogin::jceStatus &a) + { + throw a; + } +} + +void jceLogin::closeAll() +{ + JceConnector->makeDiconnect(); + delete recieverPage; + recieverPage = NULL; + loginFlag = false; + +} + +int jceLogin::makeFirstVisit() +{ + std::string usr = jceA->getUsername(); + std::string psw = jceA->getPassword(); + if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) + { + if (!JceConnector->recieveData(*recieverPage,true)) + return jceLogin::ERROR_ON_GETTING_INFO; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; +} + +int jceLogin::makeSecondVisit() +{ + std::string usrid=jceA->getUserID(); + std::string pswid=jceA->getHashedPassword(); + if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) + { + if (!(JceConnector->recieveData(*recieverPage,true))) + return jceLogin::ERROR_ON_GETTING_INFO; + + return true; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; +} + +int jceLogin::getCalendar(int year, int 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; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; + +} +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))) + return jceLogin::ERROR_ON_GETTING_GRADES; + else + return jceLogin::JCE_GRADE_PAGE_PASSED; + } + else + return jceLogin::ERROR_ON_SEND_REQUEST; + + return true; + +} + +void jceLogin::setLoginFlag(bool x) +{ + this->loginFlag = x; +} +bool jceLogin::isLoginFlag() const +{ + return this->loginFlag; +} + +std::string jceLogin::getPage() +{ + return *recieverPage; +} + +/** + * @brief jceLogin::checkValidation Made by Nadav Luzzato + * @return true if second validation step is right + */ +bool jceLogin::checkValidation() +{ + //finds the hashed password + std::size_t hasspass_position1,hasspass_position2; + + if ((hasspass_position1 = recieverPage->find("-A,-N")) == string::npos) + return false; + hasspass_position1 += 5; + if ((hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1)) == string::npos) + return false; + + std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1); + jceA->setHashedPassword(hasspass); + + //finds the user id + std::size_t id_position1 = recieverPage->find("value=\"-N", 0); + id_position1 += 9; + std::size_t id_position2 = recieverPage->find(",-A", id_position1); + if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos)) + { + std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1); + jceA->setUserID(hassid); + } + if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty())) + return false; + + return true; +} diff --git a/src/jce/jcelogin.h b/src/jceSettings/jcelogin.h similarity index 83% rename from src/jce/jcelogin.h rename to src/jceSettings/jcelogin.h index cd805ad..dfcb593 100644 --- a/src/jce/jcelogin.h +++ b/src/jceSettings/jcelogin.h @@ -1,59 +1,60 @@ -#ifndef JCELOGIN_H -#define JCELOGIN_H - -#include -#include - -#include "../connection/jcesslclient.h" -#include "../user.h" -#include "jceLoginHtmlScripts.h" - -class jceLogin -{ -public: - - enum jceStatus { - JCE_NOT_CONNECTED, - ERROR_ON_VALIDATION, - ERROR_ON_VALIDATION_USER_BLOCKED, - ERROR_ON_OPEN_SOCKET, - ERROR_ON_SEND_REQUEST, - ERROR_ON_GETTING_INFO, - ERROR_ON_GETTING_GRADES, - - JCE_START_VALIDATING_PROGRESS, - JCE_VALIDATION_PASSED, - JCE_YOU_ARE_IN, - JCE_GRADE_PAGE_PASSED - }; - - jceLogin(user* username); - ~jceLogin(); - void makeConnection() throw (jceStatus); - bool checkConnection(); - void reConnect() throw (jceStatus); - void closeAll(); - int getGrades(); - bool isLoginFlag() const; - - std::string getPage(); - - - - - -private: - int makeFirstVisit(); - bool checkValidation(); - int makeSecondVisit(); - void setLoginFlag(bool x); - - bool loginFlag; - std::string * recieverPage; - user * jceA; - jceSSLClient * JceConnector; - - -}; - -#endif // JCELOGIN_H +#ifndef JCELOGIN_H +#define JCELOGIN_H + +#include +#include + +#include "./src/jceConnection/jcesslclient.h" +#include "./src/jceSettings/user.h" +#include "jceLoginHtmlScripts.h" + +class jceLogin +{ +public: + + enum jceStatus { + JCE_NOT_CONNECTED, + ERROR_ON_VALIDATION, + ERROR_ON_VALIDATION_USER_BLOCKED, + ERROR_ON_OPEN_SOCKET, + ERROR_ON_SEND_REQUEST, + ERROR_ON_GETTING_INFO, + ERROR_ON_GETTING_GRADES, + + JCE_START_VALIDATING_PROGRESS, + JCE_VALIDATION_PASSED, + JCE_YOU_ARE_IN, + JCE_GRADE_PAGE_PASSED + }; + + jceLogin(user* username); + ~jceLogin(); + void makeConnection() throw (jceStatus); + bool checkConnection(); + void reConnect() throw (jceStatus); + void closeAll(); + int getCalendar(int year, int semester); + int getGrades(int fromYear, int toYear, int fromSemester, int toSemester); + bool isLoginFlag() const; + + std::string getPage(); + + + + + +private: + int makeFirstVisit(); + bool checkValidation(); + int makeSecondVisit(); + void setLoginFlag(bool x); + + bool loginFlag; + std::string * recieverPage; + user * jceA; + jceSSLClient * JceConnector; + + +}; + +#endif // JCELOGIN_H diff --git a/src/user.cpp b/src/jceSettings/user.cpp similarity index 74% rename from src/user.cpp rename to src/jceSettings/user.cpp index 934a9c3..2a046ac 100644 --- a/src/user.cpp +++ b/src/jceSettings/user.cpp @@ -1,52 +1,45 @@ -#include "user.h" - - -user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false) -{ - - this->username = username; - this->password = password; -} -user::~user() -{ - delete date; -} -void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester) -{ - date->setFYear(fromYear); - date->setFSemester(fromSemester); - date->setTYear(toYear); - date->setTSemester(toSemester); -} - -void user::setInfluenceCourseOnly(bool status) -{ - this->influenceCourseOnly = status; -} - -bool user::getInfluenceCourseOnly() const -{ - return this->influenceCourseOnly; -} - -void user::setUsername(string& username) { - this->username=username; -} - -void user::setPassword(string& password) { - this->password=password; -} - -void user::setUserID(string& ID) -{ - this->userID = ID; -} -void user::setHashedPassword(string& hashpass) -{ - this->hashedPassword = hashpass; -} - -string user::getPassword() const { return password; } -string user::getUsername() const { return username; } -string user::getUserID() const { return userID; } -string user::getHashedPassword() const { return hashedPassword; } +#include "user.h" + + +user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false) +{ + + this->username = username; + this->password = password; +} +user::~user() +{ +} + + +void user::setInfluenceCourseOnly(bool status) +{ + this->influenceCourseOnly = status; +} + +bool user::getInfluenceCourseOnly() const +{ + return this->influenceCourseOnly; +} + +void user::setUsername(string& username) { + this->username=username; +} + +void user::setPassword(string& password) { + this->password=password; +} + +void user::setUserID(string& ID) +{ + this->userID = ID; +} +void user::setHashedPassword(string& hashpass) +{ + this->hashedPassword = hashpass; +} + +string user::getPassword() const { return password; } +string user::getUsername() const { return username; } +string user::getUserID() const { return userID; } +string user::getHashedPassword() const { return hashedPassword; } diff --git a/src/user.h b/src/jceSettings/user.h similarity index 72% rename from src/user.h rename to src/jceSettings/user.h index 8895024..dd638fd 100644 --- a/src/user.h +++ b/src/jceSettings/user.h @@ -1,48 +1,43 @@ -#ifndef user_H -#define user_H - -#include -#include -#include "jce/jcedate.h" - -using namespace std; -class user -{ -public: - user(string username,string password); - ~user(); - void setUsername(string& username); - void setPassword(string& password); - - string getPassword() const; - string getUsername() const; - - void setUserID(string& ID); - void setHashedPassword(string& hashpass); - - string getUserID() const; - string getHashedPassword() const; - - void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester); - - void setInfluenceCourseOnly(bool status); - bool getInfluenceCourseOnly() const; - - jceDate * const date = new jceDate("","","",""); //we do not change the pointer - -private: - - string username; - string password; - - string hashedPassword; - string userID; - - bool influenceCourseOnly; - - - -}; -#endif - - +#ifndef user_H +#define user_H + +#include +#include + +using namespace std; +class user +{ +public: + user(string username,string password); + ~user(); + void setUsername(string& username); + void setPassword(string& password); + + string getPassword() const; + string getUsername() const; + + void setUserID(string& ID); + void setHashedPassword(string& hashpass); + + string getUserID() const; + string getHashedPassword() const; + + void setInfluenceCourseOnly(bool status); + bool getInfluenceCourseOnly() const; + +private: + + string username; + string password; + + string hashedPassword; + string userID; + + bool influenceCourseOnly; + + + +}; +#endif + +