fixed bugs. ready to make graph feature

This commit is contained in:
Liran BN 2014-10-06 19:15:24 +03:00
parent fd612169d7
commit 72dfc10778
13 changed files with 411 additions and 1591 deletions

View file

@ -130,7 +130,6 @@ QString loginHandler::getCurrentPageContect()
parse.setText(jceLog->getPage()); parse.setText(jceLog->getPage());
else else
throw jceLogin::ERROR_ON_GETTING_INFO; throw jceLogin::ERROR_ON_GETTING_INFO;
return parse.toPlainText(); return parse.toPlainText();
} }
int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester) int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester)

View file

@ -2,7 +2,7 @@
#include "ui_mainscreen.h" #include "ui_mainscreen.h"
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen), busyFlag() MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -33,7 +33,6 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSc
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar); this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar);
this->calendar = new CalendarManager(ui->calendarGridLayoutMain); this->calendar = new CalendarManager(ui->calendarGridLayoutMain);
this->data = new SaveData(); this->data = new SaveData();
busyFlag = false;
//check login File //check login File
if (data->isSaved()) if (data->isSaved())
@ -145,7 +144,7 @@ void MainScreen::on_ratesButton_clicked()
QString pageString; QString pageString;
int status = 0; int status = 0;
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag() && !busyFlag) if (loginHandel->isLoggedInFlag())
{ {
ui->statusBar->showMessage(tr("Getting grades...")); ui->statusBar->showMessage(tr("Getting grades..."));
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(), if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),
@ -170,7 +169,6 @@ void MainScreen::on_ratesButton_clicked()
{ {
qCritical() << Q_FUNC_INFO << "grade get ended with" << status; qCritical() << Q_FUNC_INFO << "grade get ended with" << status;
} }
busyFlag = true;
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
@ -237,43 +235,34 @@ void MainScreen::on_graphButton_clicked()
//EVENTS ON CALENDAR TAB //EVENTS ON CALENDAR TAB
void MainScreen::on_getCalendarBtn_clicked() void MainScreen::on_getCalendarBtn_clicked()
{ {
QString page; ui->progressBar->setValue(0);
calendar->resetTable(); qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
page = ui->plainTextEdit->toPlainText(); int status = 0;
calendar->setCalendar(page); QString page;
// ui->progressBar->setValue(0); QApplication::setOverrideCursor(Qt::WaitCursor);
// qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); if (loginHandel->isLoggedInFlag())
// int status = 0; {
// QString page; ui->statusBar->showMessage(tr("Getting schedule..."));
// QApplication::setOverrideCursor(Qt::WaitCursor); if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
// if (loginHandel->isLoggedInFlag()) {
// { calendar->resetTable();
// ui->statusBar->showMessage(tr("Getting schedule...")); ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
// if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED) page = loginHandel->getCurrentPageContect();
// { calendar->setCalendar(page);
ui->progressBar->setValue(100);
// //Use it for debug. add plain text and change the object name to 'plainTextEdit' so you will get the html request qDebug() << Q_FUNC_INFO << "calendar is loaded";
// //ui->plainTextEdit->setPlainText(loginHandel->getCurrentPageContect()); ui->statusBar->showMessage(tr("Done"));
// calendar->resetTable(); }
// ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000); else if (status == jceLogin::JCE_NOT_CONNECTED)
{
// page = loginHandel->getCurrentPageContect(); qWarning() << Q_FUNC_INFO << "not connected";
// calendar->setCalendar(page); QApplication::restoreOverrideCursor();
// ui->progressBar->setValue(100); QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
// qDebug() << Q_FUNC_INFO << "calendar is loaded"; }
// ui->statusBar->showMessage(tr("Done")); else
// } qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
}
// else if (status == jceLogin::JCE_NOT_CONNECTED) QApplication::restoreOverrideCursor();
// {
// qWarning() << Q_FUNC_INFO << "not connected";
// QApplication::restoreOverrideCursor();
// QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
// }
// else
// qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
// }
// QApplication::restoreOverrideCursor();
} }
void MainScreen::on_exportToCVSBtn_clicked() void MainScreen::on_exportToCVSBtn_clicked()
{ {

View file

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

File diff suppressed because it is too large Load diff

View file

@ -61,7 +61,7 @@ void CalendarDialog::on_calStart_selectionChanged()
void CalendarDialog::on_buttonBox_accepted() void CalendarDialog::on_buttonBox_accepted()
{ {
if(this->isOK) if(this->isOK)
qDebug() << "CalendarDialog: Valid input"; qDebug() << Q_FUNC_INFO << "CalendarDialog: Valid input";
} }
void CalendarDialog::on_calEnd_selectionChanged() void CalendarDialog::on_calEnd_selectionChanged()

View file

@ -2,123 +2,108 @@
QString CalendarPage::htmlToString() QString CalendarPage::htmlToString()
{ {
return tempHtml; return tempHtml;
} }
void CalendarPage::setPage(QString html) void CalendarPage::setPage(QString html)
{ {
qDebug() << "parsing calendar"; courses = new std::list<calendarCourse*>();
courses = new std::list<calendarCourse*>(); tempHtml = getString(html);
tempHtml = getString(html); calendarListInit(tempHtml);
tempHtml = tokenToLines(tempHtml);
qDebug() << "creating courses list";
calendarListInit(tempHtml);
qDebug() << "done";
} }
QString CalendarPage::tokenToLines(QString &textToParse)
{
int ctr = 0;
QString temp = "";
char *tok;
char* textToTok = strdup(textToParse.toStdString().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(QString &linesTokinzedString) void CalendarPage::calendarListInit(QString &linesTokinzedString)
{ {
std::list<QString> stringHolder; std::list<QString> stringHolder;
QString temp; QString temp;
calendarCourse * cTemp = NULL; calendarCourse * cTemp = NULL;
char* tok; char* tok;
char* textToTok = strdup(linesTokinzedString.toStdString().c_str()); char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
tok = strtok(textToTok,"\n"); tok = strtok(textToTok,"\n");
while (tok != NULL) while (tok != NULL)
{ {
temp = tok; temp = tok;
stringHolder.push_back(temp); stringHolder.push_back(temp);
tok = strtok(NULL, "\n"); tok = strtok(NULL, "\n");
} }
for (QString temp: stringHolder) for (QString temp: stringHolder)
{ {
cTemp = lineToCourse(temp); cTemp = lineToCourse(temp);
if (cTemp != NULL) if (cTemp != NULL)
courses->push_back(cTemp); courses->push_back(cTemp);
} }
} }
calendarCourse *CalendarPage::lineToCourse(QString line) calendarCourse *CalendarPage::lineToCourse(QString line)
{ {
calendarCourse *tempC = NULL; calendarCourse *tempC = NULL;
QString templinearray[CALENDAR_COURSE_FIELDS];//[serial,name,type,lecturer,points,semesterhours,dayandhours,room] QString templinearray[CALENDAR_COURSE_FIELDS];//[serial,name,type,lecturer,points,semesterhours,dayandhours,room]
int serial; int serial;
double points,semesterHours; double points,semesterHours;
QString name,type, lecturer,dayAndHour,room; QString name,type, lecturer,dayAndHour,room;
QString tempS = ""; QString tempS = "";
int i = 0; int i = 0;
char* tok; char* tok;
char* cLine = strdup(line.toStdString().c_str()); char* cLine = strdup(line.toStdString().c_str());
tok = strtok(cLine, "\t"); tok = strtok(cLine, "\t");
while(tok != NULL) while(tok != NULL)
{ {
tempS = QString(tok); tempS = QString(tok);
if (i >= 1) if (i >= 1) //skips on semester character
{ {
templinearray[i-1] = tempS.trimmed(); templinearray[i-1] = tempS.trimmed();
} }
i++; i++;
if (i > 8) if (i > 8)
break; break;
tok=strtok(NULL, "\t"); tok=strtok(NULL, "\t");
} }
if (templinearray[0] == "") //empty parsing if (templinearray[0] == "") //empty parsing
return NULL; return NULL;
serial = templinearray[calendarCourse::CourseScheme::SERIAL].toInt(); serial = templinearray[calendarCourse::CourseScheme::SERIAL].toInt();
name = templinearray[calendarCourse::CourseScheme::NAME]; name = templinearray[calendarCourse::CourseScheme::NAME];
type = templinearray[calendarCourse::CourseScheme::TYPE]; type = templinearray[calendarCourse::CourseScheme::TYPE];
if (!templinearray[calendarCourse::CourseScheme::LECTURER].isEmpty()) if (!templinearray[calendarCourse::CourseScheme::LECTURER].isEmpty())
lecturer = templinearray[calendarCourse::CourseScheme::LECTURER]; lecturer = templinearray[calendarCourse::CourseScheme::LECTURER];
else else
lecturer = LECTURER_DEFAULT_STRING; lecturer = LECTURER_DEFAULT_STRING;
if (!templinearray[calendarCourse::CourseScheme::POINTS].isEmpty()) if (!templinearray[calendarCourse::CourseScheme::POINTS].isEmpty())
points = templinearray[calendarCourse::CourseScheme::POINTS].toDouble(); points = templinearray[calendarCourse::CourseScheme::POINTS].toDouble();
else else
points = 0; points = 0;
if (!templinearray[calendarCourse::CourseScheme::SEM_HOURS].isEmpty()) if (!templinearray[calendarCourse::CourseScheme::SEM_HOURS].isEmpty())
semesterHours = templinearray[calendarCourse::CourseScheme::SEM_HOURS].toDouble(); semesterHours = templinearray[calendarCourse::CourseScheme::SEM_HOURS].toDouble();
else else
semesterHours = 0; semesterHours = 0;
dayAndHour = templinearray[calendarCourse::CourseScheme::DAY_AND_HOURS]; dayAndHour = templinearray[calendarCourse::CourseScheme::DAY_AND_HOURS];
if (!templinearray[calendarCourse::CourseScheme::ROOM].isEmpty()) if (!templinearray[calendarCourse::CourseScheme::ROOM].isEmpty())
room = templinearray[calendarCourse::CourseScheme::ROOM]; room = templinearray[calendarCourse::CourseScheme::ROOM];
else else
room = ROOM_DEFAULT_STRING; room = ROOM_DEFAULT_STRING;
qDebug() << serial << name << type << lecturer << points << semesterHours << dayAndHour << room;
tempC = new calendarCourse(serial,name,type,lecturer,points,semesterHours,dayAndHour,room);
return tempC; tempC = new calendarCourse(serial,name,type,lecturer,points,semesterHours,dayAndHour,room);
// qDebug() << "serial is: " << tempC->getSerialNum();
// qDebug() << tempC->getName();
// qDebug() << tempC->getType();
// qDebug() << tempC->getLecturer();
// qDebug() << tempC->getPoints();
// qDebug() << tempC->getHourBegin() << ":" << tempC->getMinutesBegin();
// qDebug() << tempC->getHourEnd() << ":" << tempC->getMinutesEnd();
// qDebug() << tempC->getDay();
// qDebug() << tempC->getRoom();
return tempC;
} }

View file

@ -22,7 +22,6 @@ protected:
private: private:
QString tokenToLines(QString &textToParse);
void calendarListInit(QString &linesTokinzedString); void calendarListInit(QString &linesTokinzedString);
calendarCourse* lineToCourse(QString line); calendarCourse* lineToCourse(QString line);

View file

@ -38,7 +38,7 @@ void calendarSchedule::setPage(QString html)
{ {
CalendarPage::setPage(html); CalendarPage::setPage(html);
qDebug() << Q_FUNC_INFO << "inserting into table"; qDebug() << Q_FUNC_INFO << "inserting into table";
// insertCourseIntoTable(); insertCourseIntoTable();
} }
void calendarSchedule::clearTableItems() void calendarSchedule::clearTableItems()
@ -61,12 +61,10 @@ void calendarSchedule::insertCourseIntoTable()
int row,col; int row,col;
for (calendarCourse *coursePtr: *getCourses()) for (calendarCourse *coursePtr: *getCourses())
{ {
qDebug() << coursePtr->getSerialNum();
courseString = ""; courseString = "";
currentHour = coursePtr->getHourBegin(); currentHour = coursePtr->getHourBegin();
currentDay = coursePtr->getDay(); currentDay = coursePtr->getDay();
blocksNumber = coursePtr->getHourEnd() - coursePtr->getHourBegin(); //every hour is a block to fill! blocksNumber = coursePtr->getHourEnd() - coursePtr->getHourBegin(); //every hour is a block to fill!
qDebug() << blocksNumber;
while (blocksNumber >= 0) while (blocksNumber >= 0)
{ {
row = currentHour - HOURS_BEGIN; row = currentHour - HOURS_BEGIN;

View file

@ -4,7 +4,6 @@ GradePage::GradePage(QString html) : Page()
{ {
courses = new std::list<gradeCourse*>(); courses = new std::list<gradeCourse*>();
tempHtml = getString(html); tempHtml = getString(html);
tempHtml = tokenToLines(tempHtml);
coursesListInit(tempHtml); coursesListInit(tempHtml);
} }
@ -49,26 +48,6 @@ void GradePage::coursesListInit(QString &linesTokinzedString)
courses->push_back(cTemp); courses->push_back(cTemp);
} }
} }
QString GradePage::tokenToLines(QString &textToPhrase)
{
QString temp = "";
char *tok;
char* textToTok = strdup(textToPhrase.toStdString().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";
}
tok = strtok(NULL, "\n");
}
return temp;
}
gradeCourse* GradePage::lineToCourse(QString line) gradeCourse* GradePage::lineToCourse(QString line)
{ {
gradeCourse *tempC = NULL; gradeCourse *tempC = NULL;

View file

@ -27,7 +27,6 @@ public:
private: private:
QString tokenToLines(QString &textToPhrase);
void coursesListInit(QString &linesTokinzedString); void coursesListInit(QString &linesTokinzedString);
gradeCourse* lineToCourse(QString line); gradeCourse* lineToCourse(QString line);

View file

@ -8,14 +8,14 @@ Page::Page() { dateHeader = "";}
*/ */
QString Page::getString(QString &htmlToParse) QString Page::getString(QString &htmlToParse)
{ {
makeText(htmlToParse); makeText(htmlToParse);
return this->text; return this->text;
} }
void Page::makeText(QString &html) void Page::makeText(QString &html)
{ {
int index = 0; int index = 0;
index = html.indexOf("<tbody>",0); //set index into the place where the data is index = html.indexOf("<tbody>",0); //set index into the place where the data is
manageTableContent(html, index); manageTableContent(html, index);
} }
/** /**
* @brief Page::manageTableContent strip html, make it string * @brief Page::manageTableContent strip html, make it string
@ -24,141 +24,153 @@ void Page::makeText(QString &html)
*/ */
void Page::manageTableContent(QString &html, int index) void Page::manageTableContent(QString &html, int index)
{ {
if (index == -1) if (index == -1)
return; return;
QString temp; QString temp;
for (int i = index; i < html.length(); i++) for (int i = index; i < html.length(); i++)
{ {
if (html.at(i) == '<') if (html.at(i) == '<')
{ {
//<tr> / <td> / <th> //<tr> / <td> / <th>
QString endofTable = "</tbody>"; QString endofTable = "</tbody>";
QString tableTag = html.mid(i, 4); //legth of "tr/td" QString tableTag = html.mid(i, 4); //legth of "tr/td"
if (tableTag == "<tr>") if (tableTag == "<tr>")
{
if (!dateHeader.isEmpty())
temp += dateHeader;
i = stitchText(html, temp, i+4);
if (i == -1) //EOF
break;
}
else if (tableTag == "</tr")
{
temp += "\n"; //end row -> new line
i+=5;
}
else if (tableTag == "<td>" || tableTag == "<th>")
{
if (!dateHeader.isEmpty())
temp += "\t"; // new cell -> tab between data
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
{
i += 6;
while (html.at(++i) != '>');
i = stitchText(html, temp, i+1);
}
else
i = stitchText(html, temp, i+4);
if (dateHeader.isEmpty())
temp += "\t";
if (i == -1) //EOF
break;
}
else if (tableTag == "<td ") // a Year title (in grades table)
{
if (!dateHeader.isEmpty())
if (!temp.isEmpty())
if (temp.lastIndexOf(dateHeader) == temp.length()-dateHeader.length())
{
temp.chop(dateHeader.length()+1);
temp += "\t";
}
while ((html.mid(i,3) != "<b>") && (i < (int)html.length()))
{
if (html.mid(i,5) == "</td>")
break;
i++;
}
i = stitchText(html, temp, i);
}
if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
{ {
if (!dateHeader.isEmpty())
temp += dateHeader;
i = stitchText(html, temp, i+4);
if (i == -1) //EOF
break; break;
}
else if (tableTag == "</tr")
{
temp += "\n"; //end row -> new line
i+=5;
}
else if (tableTag == "<td>" || tableTag == "<th>")
{
if (!dateHeader.isEmpty())
temp += "\t"; // new cell -> tab between data
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
{
i += 6;
while (html.at(++i) != '>');
i = stitchText(html, temp, i+1);
}
else
i = stitchText(html, temp, i+4);
if (dateHeader.isEmpty())
temp += "\t";
if (i == -1) //EOF
break;
}
else if (tableTag == "<td ") // a Year title (in grades table) or Day and Hour (in calendar page)
{
if (!dateHeader.isEmpty())
{
//checking if theres a need to fill a timestamp of course
//if the string is not empty, then we will chop the last date stamp to avoid multiple date stamp in empty rows
if (!temp.isEmpty())
if (temp.lastIndexOf(dateHeader) == temp.length()-dateHeader.length())
{
temp.chop(dateHeader.length()+5);
temp += "\t";
}
}
while ((html.mid(i,5) != "</td>") && (i < (int)html.length()))
{
if (html.mid(i,3) == "<b>") //for gpa. year & semester title
{
break;
}
else if ((html.at(i) == '>') && (html.mid(i+4,3) != "<b>")) //for calendar. day and hours
{
i += 1; //lenght of >
break;
}
i++;
}
i = stitchText(html, temp, i);
temp += "\t";
}
if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
{
break;
} }
} }
} }
this->text = temp; this->text = temp;
} }
int Page::stitchText(QString &from, QString &to, int index) int Page::stitchText(QString &from, QString &to, int index)
{ {
if (from.at(index) == '<') if (from.mid(index,3) == "<b>")
{ {
QString bTag = from.mid(index, 3); QString bTag = from.mid(index, 3);
QString dateline = from.mid(index,from.indexOf("</b>",index+4)-index); QString dateline = from.mid(index,from.indexOf("</b>",index+4)-index);
QString temp; QString temp;
QString date; QString date;
char* tok; char* tok;
int i = 0; int i = 0;
char* textToTok = strdup(dateline.toStdString().c_str()); char* textToTok = strdup(dateline.toStdString().c_str());
tok = strtok(textToTok,"<>&nbsp;:"); tok = strtok(textToTok,"<>&nbsp;:");
while (tok != NULL) while (tok != NULL)
{ {
if (i == 1) if (i == 1)
{ {
temp = tok; temp = tok;
date += temp + "\t"; date += temp + "\t";
} }
else if (i == 3) else if (i == 3)
{ {
temp = tok; temp = tok;
date += temp; date += temp;
} }
i++; i++;
tok = strtok(NULL, "<>&nbsp;:"); tok = strtok(NULL, "<>&nbsp;:");
} }
dateHeader = date; dateHeader = date;
if (bTag != "<b>") if (bTag != "<b>")
return index-1; //go back one step - for the main function to inc i return index-1; //go back one step - for the main function to inc i
index += dateline.length(); index += dateline.length();
} }
while (from.at(index) != '<' && index < (int)from.length()) while (from.at(index) != '<' && index < (int)from.length())
{ {
if (from[index] == '&') if (from[index] == '&')
{ {
//&nbsp; //&nbsp;
QString nbspChr = from.mid(index, 6); QString nbspChr = from.mid(index, 6);
if (nbspChr == "&nbsp;") if (nbspChr == "&nbsp;")
{ {
index += 5; index += 5;
from.replace(index,1,' '); from.replace(index,1,' ');
} }
} }
if (endOfString(index,(int) from.length())) if (endOfString(index,(int) from.length()))
return -1; //EOF return -1; //EOF
else if (from.at(index) == '<') else if (from.at(index) == '<')
return index - 1; //go back one step - for the main function to inc i return index - 1; //go back one step - for the main function to inc i
if ((from.at(index) != '\n') && (from.at(index) != '\t')) //check the actuall data before continue if ((from.at(index) != '\n') && (from.at(index) != '\t')) //check the actuall data before continue
to += from.at(index); to += from.at(index);
index++; index++;
} }
return index-1; return index-1;
} }
bool Page::endOfString(int index, int length) bool Page::endOfString(int index, int length)
{ {
if(index < length) if(index < length)
return false; return false;
return true; return true;
} }

View file

@ -6,21 +6,21 @@
*/ */
jceLogin::jceLogin(user* username, QProgressBar *progressbarPtr) jceLogin::jceLogin(user* username, QProgressBar *progressbarPtr)
{ {
this->progressBar = progressbarPtr; this->progressBar = progressbarPtr;
this->recieverPage = new QString(); this->recieverPage = new QString();
this->jceA = username; this->jceA = username;
this->JceConnector = new jceSSLClient(progressBar); this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection())); QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
} }
jceLogin::~jceLogin() jceLogin::~jceLogin()
{ {
this->jceA = NULL; this->jceA = NULL;
delete recieverPage; delete recieverPage;
delete JceConnector; delete JceConnector;
JceConnector = NULL; JceConnector = NULL;
recieverPage = NULL; recieverPage = NULL;
} }
/** /**
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it. * @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
@ -28,74 +28,74 @@ jceLogin::~jceLogin()
*/ */
int jceLogin::makeConnection() int jceLogin::makeConnection()
{ {
qDebug() << "jceLogin::makeConnection(); connection to be make"; qDebug() << "jceLogin::makeConnection(); connection to be make";
if (this->recieverPage == NULL) if (this->recieverPage == NULL)
this->recieverPage = new QString(); this->recieverPage = new QString();
int returnMode; //gets status according to called function of validation step int returnMode; //gets status according to called function of validation step
jceStatus status = jceStatus::JCE_NOT_CONNECTED; jceStatus status = jceStatus::JCE_NOT_CONNECTED;
returnMode = checkConnection(); //checking socket status. is connected? returnMode = checkConnection(); //checking socket status. is connected?
if (returnMode == false) if (returnMode == false)
{ {
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
return jceStatus::ERROR_ON_OPEN_SOCKET; return jceStatus::ERROR_ON_OPEN_SOCKET;
else else
returnMode = true; returnMode = true;
} }
if (returnMode == true) //connected to host if (returnMode == true) //connected to host
{ {
returnMode = makeFirstVisit(); returnMode = makeFirstVisit();
if (returnMode == true) //requst and send first validation if (returnMode == true) //requst and send first validation
{ {
status = jceStatus::JCE_START_VALIDATING_PROGRESS; status = jceStatus::JCE_START_VALIDATING_PROGRESS;
returnMode = checkValidation(); returnMode = checkValidation();
if (returnMode == true) //check if username and password are matching if (returnMode == true) //check if username and password are matching
{ {
status = jceStatus::JCE_VALIDATION_PASSED; status = jceStatus::JCE_VALIDATION_PASSED;
returnMode = makeSecondVisit(); returnMode = makeSecondVisit();
if (returnMode == true) //siging in the website if (returnMode == true) //siging in the website
{ {
qDebug() << "jceLogin::makeConnection(); Signed in succeesfully"; qDebug() << "jceLogin::makeConnection(); Signed in succeesfully";
status = jceStatus::JCE_YOU_ARE_IN; status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true); setLoginFlag(true);
} }
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
{ {
status = jceLogin::ERROR_ON_GETTING_INFO; status = jceLogin::ERROR_ON_GETTING_INFO;
} }
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
{ {
status = jceLogin::ERROR_ON_SEND_REQUEST; status = jceLogin::ERROR_ON_SEND_REQUEST;
} }
else else
status = jceStatus::ERROR_ON_VALIDATION;
}
else
status = jceStatus::ERROR_ON_VALIDATION; status = jceStatus::ERROR_ON_VALIDATION;
}
else
status = jceStatus::ERROR_ON_VALIDATION;
} }
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO) else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
{ {
status = jceLogin::ERROR_ON_GETTING_INFO; status = jceLogin::ERROR_ON_GETTING_INFO;
} }
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST) else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
{ {
status = jceLogin::ERROR_ON_SEND_REQUEST; status = jceLogin::ERROR_ON_SEND_REQUEST;
} }
else else
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED; status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
} }
else else
status = jceStatus::JCE_NOT_CONNECTED; status = jceStatus::JCE_NOT_CONNECTED;
//we throw status even if we are IN! //we throw status even if we are IN!
qDebug() << "jceLogin::makeConnection(); return status: " << status; qDebug() << "jceLogin::makeConnection(); return status: " << status;
return status; return status;
} }
/** /**
@ -104,21 +104,21 @@ int jceLogin::makeConnection()
*/ */
bool jceLogin::checkConnection() const bool jceLogin::checkConnection() const
{ {
if (JceConnector->isConnected()) if (JceConnector->isConnected())
return true; return true;
return false; return false;
} }
/** /**
* @brief jceLogin::closeAll * @brief jceLogin::closeAll
*/ */
void jceLogin::closeAll() void jceLogin::closeAll()
{ {
this->JceConnector->makeDiconnect(); this->JceConnector->makeDiconnect();
if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty())) if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty()))
{ {
delete recieverPage; delete recieverPage;
recieverPage = NULL; recieverPage = NULL;
} }
} }
@ -127,17 +127,17 @@ void jceLogin::closeAll()
*/ */
void jceLogin::reMakeConnection() void jceLogin::reMakeConnection()
{ {
if (this->JceConnector != NULL) if (this->JceConnector != NULL)
delete JceConnector; delete JceConnector;
if (this->recieverPage != NULL) if (this->recieverPage != NULL)
delete recieverPage; delete recieverPage;
recieverPage = NULL; recieverPage = NULL;
JceConnector = NULL; JceConnector = NULL;
this->recieverPage = new QString(); this->recieverPage = new QString();
this->JceConnector = new jceSSLClient(progressBar); this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation())); QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection())); QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
emit connectionReadyAfterDisconnection(); emit connectionReadyAfterDisconnection();
} }
/** /**
@ -146,17 +146,17 @@ void jceLogin::reMakeConnection()
*/ */
int jceLogin::makeFirstVisit() int jceLogin::makeFirstVisit()
{ {
QString usr = jceA->getUsername(); QString usr = jceA->getUsername();
QString psw = jceA->getPassword(); QString psw = jceA->getPassword();
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA)))) if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
{ {
if (!JceConnector->recieveData(*recieverPage,true)) if (!JceConnector->recieveData(*recieverPage,true))
return jceLogin::ERROR_ON_GETTING_INFO; return jceLogin::ERROR_ON_GETTING_INFO;
} }
else else
return jceLogin::ERROR_ON_SEND_REQUEST; return jceLogin::ERROR_ON_SEND_REQUEST;
return true; return true;
} }
/** /**
* @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login * @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login
@ -164,19 +164,19 @@ int jceLogin::makeFirstVisit()
*/ */
int jceLogin::makeSecondVisit() int jceLogin::makeSecondVisit()
{ {
QString usrid=jceA->getUserID(); QString usrid=jceA->getUserID();
QString pswid=jceA->getHashedPassword(); QString pswid=jceA->getHashedPassword();
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA))))) if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
{ {
if (!(JceConnector->recieveData(*recieverPage,true))) if (!(JceConnector->recieveData(*recieverPage,true)))
return jceLogin::ERROR_ON_GETTING_INFO; return jceLogin::ERROR_ON_GETTING_INFO;
return true; return true;
} }
else else
return jceLogin::ERROR_ON_SEND_REQUEST; return jceLogin::ERROR_ON_SEND_REQUEST;
return true; return true;
} }
/** /**
* @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server * @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server
@ -186,17 +186,17 @@ int jceLogin::makeSecondVisit()
*/ */
int jceLogin::getCalendar(int year, int semester) int jceLogin::getCalendar(int year, int semester)
{ {
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester))))) if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
{ {
if (!(JceConnector->recieveData(*recieverPage,false))) if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_PAGE; return jceLogin::ERROR_ON_GETTING_PAGE;
else else
return jceLogin::JCE_PAGE_PASSED; return jceLogin::JCE_PAGE_PASSED;
} }
else else
return jceLogin::ERROR_ON_SEND_REQUEST; return jceLogin::ERROR_ON_SEND_REQUEST;
return true; return true;
} }
/** /**
@ -209,17 +209,17 @@ int jceLogin::getCalendar(int year, int semester)
*/ */
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester) int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
{ {
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester))))) if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
{ {
if (!(JceConnector->recieveData(*recieverPage,false))) if (!(JceConnector->recieveData(*recieverPage,false)))
return jceLogin::ERROR_ON_GETTING_PAGE; return jceLogin::ERROR_ON_GETTING_PAGE;
else else
return jceLogin::JCE_PAGE_PASSED; return jceLogin::JCE_PAGE_PASSED;
} }
else else
return jceLogin::ERROR_ON_SEND_REQUEST; return jceLogin::ERROR_ON_SEND_REQUEST;
return true; return true;
} }
/** /**
@ -229,43 +229,43 @@ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemest
bool jceLogin::checkValidation() bool jceLogin::checkValidation()
{ {
//finds the hashed password //finds the hashed password
QString constUserID_TAG = "value=\"-N"; QString constUserID_TAG = "value=\"-N";
QString constHassID_TAG = "-A,-N"; QString constHassID_TAG = "-A,-N";
QString hasspass,hassid; QString hasspass,hassid;
std::size_t hasspass_position1,hasspass_position2; std::size_t hasspass_position1,hasspass_position2;
std::size_t id_position1,id_position2; std::size_t id_position1,id_position2;
hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index
if (hasspass_position1 == std::string::npos) //didnt find the tag if (hasspass_position1 == std::string::npos) //didnt find the tag
return false; return false;
else else
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1); hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1);
//finds the hass pass //finds the hass pass
if (hasspass_position2 != std::string::npos) //found the hasspass! storing it if (hasspass_position2 != std::string::npos) //found the hasspass! storing it
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1); hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
else else
return false; return false;
//finds the user id //finds the user id
id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index
if (id_position1 == std::string::npos) //didnt find the tag if (id_position1 == std::string::npos) //didnt find the tag
return false; return false;
else else
id_position1 += constUserID_TAG.length(); //skip the index of tag id_position1 += constUserID_TAG.length(); //skip the index of tag
id_position2 = this->recieverPage->toStdString().find(",-A", id_position1); id_position2 = this->recieverPage->toStdString().find(",-A", id_position1);
if (id_position2 != std::string::npos) //found the hassid! storing it if (id_position2 != std::string::npos) //found the hassid! storing it
hassid = recieverPage->mid(id_position1,id_position2-id_position1); hassid = recieverPage->mid(id_position1,id_position2-id_position1);
else else
return false; return false;
//setting user information with given data hassid and hasspass //setting user information with given data hassid and hasspass
jceA->setHashedPassword(hasspass); jceA->setHashedPassword(hasspass);
jceA->setUserID(hassid); jceA->setUserID(hassid);
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid; qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
return true; return true;
} }
/** /**
* @brief jceLogin::setLoginFlag * @brief jceLogin::setLoginFlag
@ -273,7 +273,7 @@ bool jceLogin::checkValidation()
*/ */
void jceLogin::setLoginFlag(bool x) void jceLogin::setLoginFlag(bool x)
{ {
this->loginFlag = x; this->loginFlag = x;
} }
/** /**
* @brief jceLogin::isLoginFlag checking if there is a connection, if true - > return if we signed in. otherwise, return not (not connected dough) * @brief jceLogin::isLoginFlag checking if there is a connection, if true - > return if we signed in. otherwise, return not (not connected dough)
@ -281,9 +281,9 @@ void jceLogin::setLoginFlag(bool x)
*/ */
bool jceLogin::isLoginFlag() const bool jceLogin::isLoginFlag() const
{ {
if (checkConnection()) if (checkConnection())
return this->loginFlag; return this->loginFlag;
return false; return false;
} }
/** /**
@ -292,27 +292,27 @@ bool jceLogin::isLoginFlag() const
*/ */
QString jceLogin::getPage() QString jceLogin::getPage()
{ {
return *recieverPage; return *recieverPage;
} }
void jceLogin::reValidation() void jceLogin::reValidation()
{ {
qDebug() << Q_FUNC_INFO << "Revalidating user"; qDebug() << Q_FUNC_INFO << "Revalidating user";
if (makeFirstVisit() == true) if (makeFirstVisit() == true)
{ {
if (checkValidation()) if (checkValidation())
{ {
if (makeSecondVisit() == true) if (makeSecondVisit() == true)
qDebug() << Q_FUNC_INFO << "Validated"; qDebug() << Q_FUNC_INFO << "Validated";
else else
qWarning() << Q_FUNC_INFO << "Second visit finished with an error"; qWarning() << Q_FUNC_INFO << "Second visit finished with an error";
} }
else else
qDebug() << Q_FUNC_INFO << "checking validation ended with an error"; qDebug() << Q_FUNC_INFO << "checking validation ended with an error";
} }
else else
{ {
qDebug() << Q_FUNC_INFO << "Couldnt Validate User"; qDebug() << Q_FUNC_INFO << "Couldnt Validate User";
} }
} }

View file

@ -12,57 +12,58 @@
class jceLogin : public QObject class jceLogin : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
jceLogin(user* username,QProgressBar *progressbarPtr); jceLogin(user* username,QProgressBar *progressbarPtr);
~jceLogin(); ~jceLogin();
enum jceStatus { enum jceStatus {
JCE_NOT_CONNECTED, JCE_NOT_CONNECTED,
ERROR_ON_VALIDATION, ERROR_ON_VALIDATION,
ERROR_ON_VALIDATION_USER_BLOCKED, ERROR_ON_VALIDATION_USER_BLOCKED,
ERROR_ON_OPEN_SOCKET, ERROR_ON_OPEN_SOCKET,
ERROR_ON_SEND_REQUEST, ERROR_ON_SEND_REQUEST,
ERROR_ON_GETTING_INFO, ERROR_ON_GETTING_INFO,
ERROR_ON_GETTING_PAGE, ERROR_ON_GETTING_PAGE,
JCE_START_VALIDATING_PROGRESS, JCE_START_VALIDATING_PROGRESS,
JCE_VALIDATION_PASSED, JCE_VALIDATION_PASSED,
JCE_YOU_ARE_IN, JCE_YOU_ARE_IN,
JCE_PAGE_PASSED JCE_PAGE_PASSED
}; };
int makeConnection();
void closeAll();
bool checkConnection() const; int makeConnection();
bool isLoginFlag() const; void closeAll();
int getCalendar(int year, int semester); bool checkConnection() const;
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester); bool isLoginFlag() const;
QString getPage(); int getCalendar(int year, int semester);
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
QString getPage();
private slots: private slots:
void reValidation(); void reValidation();
void reMakeConnection(); void reMakeConnection();
signals: signals:
void connectionReadyAfterDisconnection(); void connectionReadyAfterDisconnection();
private: private:
int makeFirstVisit(); int makeFirstVisit();
int makeSecondVisit(); int makeSecondVisit();
bool checkValidation(); bool checkValidation();
void setLoginFlag(bool x); void setLoginFlag(bool x);
bool loginFlag; bool loginFlag;
QString * recieverPage; QString * recieverPage;
user * jceA; user * jceA;
jceSSLClient * JceConnector; jceSSLClient * JceConnector;
QProgressBar *progressBar; QProgressBar *progressBar;
}; };