QString instead of std::string. added socket error handle, still not completed the handling

This commit is contained in:
liranbg 2014-09-17 04:08:38 +03:00
parent 582a959fb3
commit 03a75ab737
29 changed files with 813 additions and 547 deletions

View file

@ -6,7 +6,7 @@ CalendarManager::CalendarManager(calendarSchedule *ptr)
caliDialog = new CalendarDialog(); caliDialog = new CalendarDialog();
} }
void CalendarManager::setCalendar(std::string html) void CalendarManager::setCalendar(QString html)
{ {
caliSchedPtr->setPage(html); caliSchedPtr->setPage(html);
} }

View file

@ -18,7 +18,7 @@ public:
delete caliDialog; delete caliDialog;
} }
bool exportCalendarCSV(); bool exportCalendarCSV();
void setCalendar(std::string html); void setCalendar(QString html);
void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); } void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); }
private: private:

View file

@ -46,7 +46,7 @@ void coursesTableManager::insertJceCoursesIntoTable()
* @brief coursesTableManager::setCoursesList creating courses list with given html page * @brief coursesTableManager::setCoursesList creating courses list with given html page
* @param html * @param html
*/ */
void coursesTableManager::setCoursesList(std::string &html) void coursesTableManager::setCoursesList(QString &html)
{ {
gp = new GradePage(html); gp = new GradePage(html);
} }
@ -70,10 +70,10 @@ bool coursesTableManager::changes(QString change, int row, int col)
switch (col) switch (col)
{ {
case (gradeCourse::CourseScheme::NAME): case (gradeCourse::CourseScheme::NAME):
c->setName(change.toStdString()); c->setName(change);
break; break;
case (gradeCourse::CourseScheme::TYPE): case (gradeCourse::CourseScheme::TYPE):
c->setType(change.toStdString()); c->setType(change);
break; break;
case (gradeCourse::CourseScheme::POINTS): case (gradeCourse::CourseScheme::POINTS):
{ {
@ -117,7 +117,7 @@ bool coursesTableManager::changes(QString change, int row, int col)
break; break;
} }
case (gradeCourse::CourseScheme::ADDITION): case (gradeCourse::CourseScheme::ADDITION):
c->setAdditions(change.toStdString()); c->setAdditions(change);
break; break;
} }
break; break;
@ -150,11 +150,11 @@ void coursesTableManager::addRow(const gradeCourse *courseToAdd)
hours = new QTableWidgetItem(QString::number(c->getHours())); hours = new QTableWidgetItem(QString::number(c->getHours()));
hours->setFlags(serial->flags() & ~Qt::ItemIsEditable); hours->setFlags(serial->flags() & ~Qt::ItemIsEditable);
grade = new QTableWidgetItem(QString::number(c->getGrade())); grade = new QTableWidgetItem(QString::number(c->getGrade()));
name = new QTableWidgetItem(QString::fromStdString(c->getName())); name = new QTableWidgetItem(c->getName());
name->setFlags(serial->flags() & ~Qt::ItemIsEditable); name->setFlags(serial->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem(QString::fromStdString(c->getType())); type = new QTableWidgetItem(c->getType());
type->setFlags(serial->flags() & ~Qt::ItemIsEditable); type->setFlags(serial->flags() & ~Qt::ItemIsEditable);
addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions())); addition = new QTableWidgetItem(c->getAddidtions());
courseTBL->setItem(i,j++,serial); courseTBL->setItem(i,j++,serial);
courseTBL->setItem(i,j++,name); courseTBL->setItem(i,j++,name);
@ -212,7 +212,7 @@ void coursesTableManager::clearTable()
int i = 0; //starting point int i = 0; //starting point
while (courseTBL->rowCount() > i) while (courseTBL->rowCount() > i)
{ {
gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text().toStdString()); gp->removeCourse(courseTBL->item(i,gradeCourse::CourseScheme::SERIAL)->text());
courseTBL->removeRow(i); courseTBL->removeRow(i);
} }
gp = NULL; gp = NULL;

View file

@ -22,7 +22,7 @@ public:
coursesTableManager(QTableWidget *, user *usrPtr); coursesTableManager(QTableWidget *, user *usrPtr);
~coursesTableManager(); ~coursesTableManager();
void insertJceCoursesIntoTable(); void insertJceCoursesIntoTable();
void setCoursesList(std::string &htmlPage); void setCoursesList(QString &htmlPage);
bool changes(QString change, int row, int col); bool changes(QString change, int row, int col);
void addRow(const gradeCourse * courseToAdd = 0); void addRow(const gradeCourse * courseToAdd = 0);
double getAvg(); double getAvg();

View file

@ -100,7 +100,7 @@ QString loginHandler::getCurrentPageContect()
{ {
QTextEdit phrase; QTextEdit phrase;
if (isLoggedInFlag()) if (isLoggedInFlag())
phrase.setText(QString::fromStdString(jceLog->getPage())); phrase.setText(jceLog->getPage());
else else
throw jceLogin::ERROR_ON_GETTING_INFO; throw jceLogin::ERROR_ON_GETTING_INFO;

View file

@ -20,7 +20,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ButtomStatusLabel = new QLabel(this); ButtomStatusLabel = new QLabel(this);
statusLabel = new QLabel(this); statusLabel = new QLabel(this);
ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight); ui->statusBar->setMaximumSize(this->geometry().width(),STATUS_ICON_HEIGH);
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); ui->statusBar->addPermanentWidget(ButtomStatusLabel,0);
ui->statusBar->addPermanentWidget(statusLabel,1); ui->statusBar->addPermanentWidget(statusLabel,1);
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
@ -50,6 +50,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
checkLocale(); checkLocale();
} }
MainScreen::~MainScreen() MainScreen::~MainScreen()
@ -125,8 +126,8 @@ void MainScreen::uiSetDisconnectMode()
} }
void MainScreen::uiSetConnectMode() void MainScreen::uiSetConnectMode()
{ {
string username; QString username;
string password; QString password;
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
{ {
if (ui->usrnmLineEdit->text().isEmpty()) if (ui->usrnmLineEdit->text().isEmpty())
@ -152,8 +153,8 @@ void MainScreen::uiSetConnectMode()
} }
setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
username = ui->usrnmLineEdit->text().toStdString(); username = ui->usrnmLineEdit->text();
password = ui->pswdLineEdit->text().toStdString(); password = ui->pswdLineEdit->text();
ui->usrnmLineEdit->setDisabled(true); ui->usrnmLineEdit->setDisabled(true);
ui->pswdLineEdit->setDisabled(true); ui->pswdLineEdit->setDisabled(true);
@ -180,13 +181,13 @@ void MainScreen::uiSetConnectMode()
//EVENTS ON GPA TAB //EVENTS ON GPA TAB
void MainScreen::on_ratesButton_clicked() void MainScreen::on_ratesButton_clicked()
{ {
std::string pageString; QString pageString;
int status = 0; int status = 0;
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED) if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED)
{ {
pageString = loginHandel->getCurrentPageContect().toStdString(); pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString); courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable(); courseTableMgr->insertJceCoursesIntoTable();
} }
@ -264,7 +265,7 @@ void MainScreen::on_getCalendarBtn_clicked()
//Use it for debug. add plain text and change the object name to 'plainTextEdit' so you will get the html request //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()); //ui->plainTextEdit->setPlainText(loginHandel->getCurrentPageContect());
calendar->resetTable(); calendar->resetTable();
calendar->setCalendar(loginHandel->getCurrentPageContect().toStdString()); calendar->setCalendar(loginHandel->getCurrentPageContect());
} }
else if (status == jceLogin::JCE_NOT_CONNECTED) else if (status == jceLogin::JCE_NOT_CONNECTED)

View file

@ -15,7 +15,7 @@
#include "./CalendarTab/CalendarManager.h" #include "./CalendarTab/CalendarManager.h"
#define StatusIconHeight 35 #define STATUS_ICON_HEIGH 35
namespace Ui { namespace Ui {
class MainScreen; class MainScreen;
} }

View file

@ -1,58 +1,126 @@
#include "jcesslclient.h" #include "jcesslclient.h"
/**
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
*/
jceSSLClient::jceSSLClient() : flag(false), packet("") jceSSLClient::jceSSLClient() : flag(false), packet("")
{ {
//setting signals
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError))); connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
connect(this,SIGNAL(connected()),this,SLOT(setConnected())); connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted())); connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected())); connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
//loop event will connect the server, and when it is connected, it will quit - but connection will be open
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit()));
} }
bool jceSSLClient::makeConnect(std::string server, int port) /**
* @brief jceSSLClient::makeConnect connecting to server with given port. using eventloop to assure it wont stuck the application.
* @param server - server to connect to
* @param port - the using port
* @return - true if connected, false otherwise
*/
bool jceSSLClient::makeConnect(QString server, int port)
{ {
QEventLoop loop; qDebug() << "jceSSLClient::makeConnect; Making connection";
QObject::connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
if (isConnected()) if (isConnected())
abort(); {
qWarning() << "jceSSLClient::makeConnect; Was already connected. Aborting.";
makeDiconnect();
}
if (isOpen()) if (isOpen())
abort(); {
qWarning() << "jceSSLClient::makeConnect; IsO pen. Aborting.";
makeDiconnect();
}
connectToHostEncrypted(server.c_str(), port); qDebug() << "jceSSLClient::makeConnect; Connection to: " << server << "On Port: " << port;
loop.exec(); connectToHostEncrypted(server.toStdString().c_str(), port);
loop.exec(); //starting connection, waiting to encryption and then it ends
qDebug() << "jceSSLClient::makeConnect; returning the connection status: " << isConnected();
return isConnected(); return isConnected();
} }
/**
* @brief jceSSLClient::makeDiconnect from current server
* @return the flag of connection status
*/
bool jceSSLClient::makeDiconnect() bool jceSSLClient::makeDiconnect()
{ {
qDebug() << "jceSSLClient::makeDiconnect;";
abort(); if (loop.isRunning())
if (state() == QAbstractSocket::SocketState::ConnectedState)
{ {
qWarning() << "jceSSLClient::makeDiconnect; Killing connection thread";
loop.exit();
}
if (state() == QAbstractSocket::SocketState::UnconnectedState)
{
qDebug() << "jceSSLClient::makeDiconnect; Disconnected with [UnconnectedState]";
flag = false;
}
else if (state() == QAbstractSocket::SocketState::ConnectedState)
{
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting with [ConnectedState] ";
abort();
if (state() != QAbstractSocket::SocketState::UnconnectedState)
{
qWarning() << "jceSSLClient::makeDiconnect; still open! recursion call to disconnect";
abort();//still connected? ensure the disconnection
flag = makeDiconnect(); //recursion call!
}
flag = false; flag = false;
} }
else else
flag = true; {
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting [else] ";
abort(); //ensure the disconnection
flag = false;
}
qDebug() << "jceSSLClient::makeDiconnect; disconnect return with " << flag;
return flag; return flag;
} }
/**
* @brief jceSSLClient::isConnected connection checking
* @return regardless to state, it checks if there's a connection
*/
bool jceSSLClient::isConnected() bool jceSSLClient::isConnected()
{ {
//checking state before returning flag!
if (state() == QAbstractSocket::SocketState::UnconnectedState)
{
flag = false;
}
else if (state() == QAbstractSocket::SocketState::ClosingState)
{
flag = false;
}
else if (state() == QAbstractSocket::SocketState::ConnectedState)
{
flag = true;
}
return flag; return flag;
} }
/**
bool jceSSLClient::sendData(std::string str) * @brief jceSSLClient::sendData - given string, send it to server
* @param str - string to send
* @return true if succeed and byte were written
*/
bool jceSSLClient::sendData(QString str)
{ {
bool sendDataFlag = false;
if (isConnected()) //if connected if (isConnected()) //if connected
{ {
write(str.c_str(),str.length()); write(str.toStdString().c_str(),str.length());
while (waitForBytesWritten()); if (waitForBytesWritten())
return true; sendDataFlag = true;
} }
return false; qDebug() << "jceSSLClient::sendData; Sending Data status is: " << sendDataFlag;
return sendDataFlag;
} }
/** /**
* @brief jceSSLClient::recieveData * @brief jceSSLClient::recieveData
@ -60,13 +128,15 @@ bool jceSSLClient::sendData(std::string str)
* @param fast true for LOGIN ONLY, false to retrieve all data * @param fast true for LOGIN ONLY, false to retrieve all data
* @return true if recieved data bigger than zero * @return true if recieved data bigger than zero
*/ */
bool jceSSLClient::recieveData(std::string &str, bool fast) bool jceSSLClient::recieveData(QString &str, bool fast)
{ {
qDebug() << "jceSSLClient::recieveData Data receiving!";
packet = ""; packet = "";
bool sflag = false; bool sflag = false;
if (fast) //fast connection, good for login only!! if (fast) //fast mode connection, good only for login step!!!!
{ {
qDebug() << "jceSSLClient::recieveData login step receiving";
QEventLoop loop; QEventLoop loop;
connect(this, SIGNAL(readyRead()), &loop, SLOT(quit())); connect(this, SIGNAL(readyRead()), &loop, SLOT(quit()));
connect(this, SIGNAL(readyRead()), this, SLOT(readIt())); connect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
@ -76,6 +146,7 @@ bool jceSSLClient::recieveData(std::string &str, bool fast)
} }
else else
{ {
qDebug() << "jceSSLClient::recieveData normal receiving";
QString p; QString p;
while (waitForReadyRead(milisTimeOut)) while (waitForReadyRead(milisTimeOut))
{ {
@ -86,14 +157,17 @@ bool jceSSLClient::recieveData(std::string &str, bool fast)
}while (p.size() > 0); }while (p.size() > 0);
} }
} }
str = packet;
str = packet.toStdString(); qDebug() << "jceSSLClient::recieveData received bytes: " << str.length() ;
if (str.size() > 0) if (str.length() > 0)
sflag = true; sflag = true;
qDebug() << "jceSSLClient::recieveData return with flag: " << sflag;
return sflag; return sflag;
} }
/**
* @brief jceSSLClient::readIt function to read for fast mode in recieved data
*/
void jceSSLClient::readIt() void jceSSLClient::readIt()
{ {
QString p; QString p;
@ -103,30 +177,146 @@ void jceSSLClient::readIt()
packet.append(p); packet.append(p);
}while (p.size() > 0); }while (p.size() > 0);
} }
/**
* @brief jceSSLClient::setConnected called when signaled with connected, calling the encryption function
*/
void jceSSLClient::setConnected() void jceSSLClient::setConnected()
{ {
waitForEncrypted(); waitForEncrypted();
} }
/**
* @brief jceSSLClient::setDisconnected called when signaled with disconnected, setting flag to false
*/
void jceSSLClient::setDisconnected()
{
flag = false;
}
/**
* @brief jceSSLClient::setEncrypted called when signaled with encrypted. setting the buffer size and keeping alive.
*/
void jceSSLClient::setEncrypted() void jceSSLClient::setEncrypted()
{ {
setReadBufferSize(10000); setReadBufferSize(10000);
setSocketOption(QAbstractSocket::KeepAliveOption,1); setSocketOption(QAbstractSocket::KeepAliveOption,1);
if (state() == QAbstractSocket::SocketState::ConnectedState)
flag = true; flag = true;
} else
void jceSSLClient::setDisconnected()
{ {
abort(); qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!";
flag = false; flag = false;
} }
}
/**
void jceSSLClient::checkErrors(QAbstractSocket::SocketError) * @brief jceSSLClient::showIfErrorMsg message box to show the error occured according to socket
* if relevant, we will prompt a message box to informate the user
* otherwise, we will handle the error or ignore it.
*/
void jceSSLClient::showIfErrorMsg()
{ {
QMessageBox msgBox;
SocketError enumError = error();
QString errorString;
bool relevantError = false;
switch (enumError)
{
case QAbstractSocket::SocketError::ConnectionRefusedError:
errorString = QObject::tr("ConnectionRefusedError");
relevantError = true;
break;
case QAbstractSocket::SocketError::RemoteHostClosedError:
errorString = QObject::tr("RemoteHostClosedError");
relevantError = true;
break;
case QAbstractSocket::SocketError::HostNotFoundError:
errorString = QObject::tr("HostNotFoundError");
relevantError = true;
break;
case QAbstractSocket::SocketError::SocketAccessError:
errorString = QObject::tr("SocketAccessError");
break;
case QAbstractSocket::SocketError::SocketResourceError:
errorString = QObject::tr("SocketResourceError");
break;
case QAbstractSocket::SocketError::SocketTimeoutError:
errorString = QObject::tr("SocketTimeoutError");
if (isConnected())
relevantError = true;
break;
case QAbstractSocket::SocketError::DatagramTooLargeError:
errorString = QObject::tr("DatagramTooLargeError");
break;
case QAbstractSocket::SocketError::NetworkError:
errorString = QObject::tr("NetworkError");
relevantError = true;
break;
case QAbstractSocket::SocketError::AddressInUseError:
errorString = QObject::tr("AddressInUseError");
break;
case QAbstractSocket::SocketError::SocketAddressNotAvailableError:
errorString = QObject::tr("SocketAddressNotAvailableError");
break;
case QAbstractSocket::SocketError::UnsupportedSocketOperationError:
errorString = QObject::tr("UnsupportedSocketOperationError");
break;
case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError:
errorString = QObject::tr("ProxyAuthenticationRequiredError");
break;
case QAbstractSocket::SocketError::SslHandshakeFailedError:
errorString = QObject::tr("SslHandshakeFailedError");
break;
case QAbstractSocket::SocketError::ProxyConnectionRefusedError:
errorString = QObject::tr("ProxyConnectionRefusedError");
break;
case QAbstractSocket::SocketError::UnfinishedSocketOperationError:
errorString = QObject::tr("UnfinishedSocketOperationError");
break;
case QAbstractSocket::SocketError::ProxyConnectionClosedError:
errorString = QObject::tr("ProxyConnectionClosedError");
break;
case QAbstractSocket::SocketError::ProxyConnectionTimeoutError:
errorString = QObject::tr("ProxyConnectionTimeoutError");
break;
case QAbstractSocket::SocketError::ProxyNotFoundError:
errorString = QObject::tr("ProxyNotFoundError");
break;
case QAbstractSocket::SocketError::ProxyProtocolError:
errorString = QObject::tr("ProxyProtocolError");
break;
case QAbstractSocket::SocketError::OperationError:
errorString = QObject::tr("OperationError");
break;
case QAbstractSocket::SocketError::SslInternalError:
errorString = QObject::tr("SslInternalError");
break;
case QAbstractSocket::SocketError::SslInvalidUserDataError:
errorString = QObject::tr("SslInvalidUserDataError");
break;
case QAbstractSocket::SocketError::TemporaryError:
errorString = QObject::tr("TemporaryError");
break;
case QAbstractSocket::SocketError::UnknownSocketError:
errorString = QObject::tr("UnknownSocketError");
relevantError = true;
break;
}
if (relevantError) //informative string to be shown
{
qDebug() << "jceSSLClient::showIfErrorMsg(); relevant error. msgbox popped";
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(errorString);
msgBox.exec();
}
}
/**
* @brief jceSSLClient::checkErrors this function exctuing when socket error has occured
* @param a includes the error enum from QAbstractSocket::SocketError enum list
*/
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
{
qWarning() << "jceSSLClient::checkErrors; Var Error: " << a;
qWarning() << "jceSSLClient::checkErrors; Error: " << this->errorString();
showIfErrorMsg();
} }

View file

@ -5,6 +5,7 @@
#include <QSslSocket> #include <QSslSocket>
#include <QThread> #include <QThread>
#include <QEventLoop> #include <QEventLoop>
#include <QMessageBox>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -16,14 +17,15 @@ class jceSSLClient : QSslSocket
public: public:
jceSSLClient(); jceSSLClient();
bool makeConnect(std::string server,int port); bool makeConnect(QString server, int port);
bool isConnected(); bool isConnected();
bool sendData(std::string str); bool sendData(QString str);
bool recieveData(std::string &str, bool fast); bool recieveData(QString &str, bool fast);
bool makeDiconnect(); bool makeDiconnect();
void showIfErrorMsg();
private slots: private slots:
void checkErrors(QAbstractSocket::SocketError); void checkErrors(QAbstractSocket::SocketError a);
void setConnected(); void setConnected();
void setEncrypted(); void setEncrypted();
void setDisconnected(); void setDisconnected();
@ -33,6 +35,7 @@ private:
bool flag; bool flag;
QString packet; QString packet;
QEventLoop loop; //handle the connection as thread
}; };

View file

@ -36,10 +36,10 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
int startM = coursePtr->getMinutesBegin(); int startM = coursePtr->getMinutesBegin();
int endH = coursePtr->getHourEnd(); int endH = coursePtr->getHourEnd();
int endM = coursePtr->getMinutesEnd(); int endM = coursePtr->getMinutesEnd();
QString lecturer = QString(coursePtr->getLecturer().c_str()); //WHY YOU USED STD STRING?! QString lecturer = coursePtr->getLecturer();
QString type = QString(coursePtr->getType().c_str()); QString type = coursePtr->getType();
QString name = QString(coursePtr->getName().c_str()); QString name = coursePtr->getName();
QString room = QString(coursePtr->getRoom().c_str()); QString room = coursePtr->getRoom();
QDate currentDate = cal->getStartDate(); QDate currentDate = cal->getStartDate();

View file

@ -1,8 +1,8 @@
#include "calendarCourse.h" #include "calendarCourse.h"
calendarCourse::calendarCourse(int serial, std::string name, std::string type, std::string lecturer, double points, calendarCourse::calendarCourse(int serial, QString name, QString type, QString lecturer, double points,
double semesterHours, std::string dayAndHour, double semesterHours, QString dayAndHour,
std::string room) : Course(serial,name, type,points) QString room) : Course(serial,name, type,points)
{ {
this->lecturer = lecturer; this->lecturer = lecturer;
this->semesterHours = semesterHours; this->semesterHours = semesterHours;
@ -10,13 +10,13 @@ calendarCourse::calendarCourse(int serial, std::string name, std::string type, s
setDayAndHour(dayAndHour); setDayAndHour(dayAndHour);
} }
void calendarCourse::setDayAndHour(std::string phrase) void calendarCourse::setDayAndHour(QString phrase)
{ {
int ctr = 0; int ctr = 0;
std::string temp = ""; QString temp = "";
QTime timetemp; QTime timetemp;
char *tok; char *tok;
char* textToTok = strdup(phrase.c_str()); char* textToTok = strdup(phrase.toStdString().c_str());
tok = strtok(textToTok, " -"); tok = strtok(textToTok, " -");
while(tok != NULL) while(tok != NULL)
{ {
@ -27,12 +27,12 @@ void calendarCourse::setDayAndHour(std::string phrase)
setDay(temp); setDay(temp);
break; break;
case 1: case 1:
timetemp = QTime::fromString(QString::fromStdString(temp),"hh:mm"); timetemp = QTime::fromString(temp,"hh:mm");
setHourBegin(timetemp.hour()); setHourBegin(timetemp.hour());
setMinutesBegin(timetemp.minute()); setMinutesBegin(timetemp.minute());
break; break;
case 2: case 2:
timetemp = QTime::fromString(QString::fromStdString(temp),"hh:mm"); timetemp = QTime::fromString(temp,"hh:mm");
setHourEnd(timetemp.hour()); setHourEnd(timetemp.hour());
setMinutesEnd(timetemp.minute()); setMinutesEnd(timetemp.minute());
break; break;
@ -43,12 +43,12 @@ void calendarCourse::setDayAndHour(std::string phrase)
} }
} }
std::string calendarCourse::getLecturer() const QString calendarCourse::getLecturer() const
{ {
return lecturer; return lecturer;
} }
void calendarCourse::setLecturer(const std::string &value) void calendarCourse::setLecturer(const QString &value)
{ {
lecturer = value; lecturer = value;
} }
@ -98,17 +98,17 @@ void calendarCourse::setMinutesEnd(int value)
minutesEnd = value; minutesEnd = value;
} }
std::string calendarCourse::courseToString() QString calendarCourse::courseToString()
{ {
std::string courseText = ""; QString courseText = "";
courseText += " " + std::to_string(this->getSerialNum()); courseText += " " + QString::number(this->getSerialNum());
courseText += " " + this->getName(); courseText += " " + this->getName();
courseText += " " + this->getType(); courseText += " " + this->getType();
courseText += " " + this->lecturer; courseText += " " + this->lecturer;
courseText += " " + std::to_string(this->getPoints()); courseText += " " + QString::number(this->getPoints());
courseText += " " + std::to_string(this->semesterHours); courseText += " " + QString::number(this->semesterHours);
courseText += " " + std::to_string(this->day); courseText += " " + QString::number(this->day);
courseText += " " + std::to_string(this->hourBegin) + ":" + std::to_string(this->minutesBegin) + "-" + std::to_string(this->hourEnd) + ":" + std::to_string(this->minutesEnd); courseText += " " + QString::number(this->hourBegin) + ":" + QString::number(this->minutesBegin) + "-" + QString::number(this->hourEnd) + ":" + QString::number(this->minutesEnd);
courseText += " " + this->room; courseText += " " + this->room;
courseText += "\n"; courseText += "\n";
return courseText; return courseText;
@ -119,9 +119,9 @@ int calendarCourse::getDay() const
return day; return day;
} }
void calendarCourse::setDay(const std::string &value) void calendarCourse::setDay(const QString &value)
{ {
std::string dayTemp = value.substr(0,2); std::string dayTemp = value.toStdString().substr(0,2); //recieving two characters respresting days
if (dayTemp.compare("\u05D0") == 0) //alef if (dayTemp.compare("\u05D0") == 0) //alef
day = 1; day = 1;
else if (dayTemp.compare("\u05D1") == 0) //bet else if (dayTemp.compare("\u05D1") == 0) //bet
@ -138,12 +138,12 @@ void calendarCourse::setDay(const std::string &value)
day= -1; day= -1;
} }
std::string calendarCourse::getRoom() const QString calendarCourse::getRoom() const
{ {
return room; return room;
} }
void calendarCourse::setRoom(const std::string &value) void calendarCourse::setRoom(const QString &value)
{ {
room = value; room = value;
} }

View file

@ -24,43 +24,43 @@ public:
DAY_AND_HOURS, DAY_AND_HOURS,
ROOM ROOM
}; };
calendarCourse(int serial, std::string name, std::string type, std::string lecturer, calendarCourse(int serial, QString name, QString type, QString lecturer,
double points, double semesterHours, std::string dayAndHour, std::string room); double points, double semesterHours, QString dayAndHour, QString room);
~calendarCourse(){} ~calendarCourse(){}
int getDay() const; int getDay() const;
std::string getLecturer() const; QString getLecturer() const;
std::string getRoom() const; QString getRoom() const;
double getSemesterHours() const; double getSemesterHours() const;
int getHourBegin() const; int getHourBegin() const;
int getMinutesBegin() const; int getMinutesBegin() const;
int getHourEnd() const; int getHourEnd() const;
int getMinutesEnd() const; int getMinutesEnd() const;
void setDay(const std::string &value); void setDay(const QString &value);
void setLecturer(const std::string &value); void setLecturer(const QString &value);
void setRoom(const std::string &value); void setRoom(const QString &value);
void setSemesterHours(double value); void setSemesterHours(double value);
void setHourBegin(int value); void setHourBegin(int value);
void setMinutesBegin(int value); void setMinutesBegin(int value);
void setHourEnd(int value); void setHourEnd(int value);
void setMinutesEnd(int value); void setMinutesEnd(int value);
std::string courseToString(); QString courseToString();
private: private:
void setDayAndHour(std::string phrase); void setDayAndHour(QString phrase);
std::string lecturer; QString lecturer;
double semesterHours; double semesterHours;
int day; int day;
int hourBegin; int hourBegin;
int minutesBegin; int minutesBegin;
int hourEnd; int hourEnd;
int minutesEnd; int minutesEnd;
std::string room; QString room;
}; };

View file

@ -1,11 +1,11 @@
#include "calendarPage.h" #include "calendarPage.h"
std::string CalendarPage::htmlToString() QString CalendarPage::htmlToString()
{ {
return tempHtml; return tempHtml;
} }
void CalendarPage::setPage(std::string html) void CalendarPage::setPage(QString html)
{ {
courses = new std::list<calendarCourse*>(); courses = new std::list<calendarCourse*>();
@ -15,12 +15,12 @@ void CalendarPage::setPage(std::string html)
} }
std::string CalendarPage::tokenToLines(std::string &textToPhrase) QString CalendarPage::tokenToLines(QString &textToParse)
{ {
int ctr = 0; int ctr = 0;
std::string temp = ""; QString temp = "";
char *tok; char *tok;
char* textToTok = strdup(textToPhrase.c_str()); char* textToTok = strdup(textToParse.toStdString().c_str());
tok = strtok(textToTok, "\n"); tok = strtok(textToTok, "\n");
while(tok != NULL) while(tok != NULL)
{ {
@ -36,13 +36,13 @@ std::string CalendarPage::tokenToLines(std::string &textToPhrase)
return temp; return temp;
} }
void CalendarPage::calendarListInit(std::string &linesTokinzedString) void CalendarPage::calendarListInit(QString &linesTokinzedString)
{ {
std::list<std::string> stringHolder; std::list<QString> stringHolder;
std::string temp; QString temp;
calendarCourse * cTemp = NULL; calendarCourse * cTemp = NULL;
char* tok; char* tok;
char* textToTok = strdup(linesTokinzedString.c_str()); char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
tok = strtok(textToTok,"\n"); tok = strtok(textToTok,"\n");
while (tok != NULL) while (tok != NULL)
{ {
@ -50,7 +50,7 @@ void CalendarPage::calendarListInit(std::string &linesTokinzedString)
stringHolder.push_back(temp); stringHolder.push_back(temp);
tok = strtok(NULL, "\n"); tok = strtok(NULL, "\n");
} }
for(std::string temp: stringHolder) for (QString temp: stringHolder)
{ {
cTemp = lineToCourse(temp); cTemp = lineToCourse(temp);
if (cTemp != NULL) if (cTemp != NULL)
@ -58,24 +58,23 @@ void CalendarPage::calendarListInit(std::string &linesTokinzedString)
} }
} }
calendarCourse *CalendarPage::lineToCourse(std::string line) calendarCourse *CalendarPage::lineToCourse(QString line)
{ {
calendarCourse *tempC = NULL; calendarCourse *tempC = NULL;
std::string 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;
std::string name,type, lecturer,dayAndHour,room; QString name,type, lecturer,dayAndHour,room;
std::string tempS = ""; QString tempS = "";
std::string emptyTab = " ";
int i = 0; int i = 0;
char* tok; char* tok;
char* cLine = strdup(line.c_str()); char* cLine = strdup(line.toStdString().c_str());
tok = strtok(cLine, "\t"); tok = strtok(cLine, "\t");
while(tok != NULL) while(tok != NULL)
{ {
tempS = tok; tempS = QString(tok);
if (i>=1) if (i>=1)
templinearray[i-1] = tempS; templinearray[i-1] = tempS;
i++; i++;
@ -83,19 +82,19 @@ calendarCourse *CalendarPage::lineToCourse(std::string line)
break; break;
tok=strtok(NULL, "\t"); tok=strtok(NULL, "\t");
} }
if (templinearray[0] == "") //empty phrasing if (templinearray[0] == "") //empty parsing
return NULL; return NULL;
serial = stoi(templinearray[calendarCourse::CourseScheme::SERIAL]); 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];
lecturer = templinearray[calendarCourse::CourseScheme::LECTURER]; lecturer = templinearray[calendarCourse::CourseScheme::LECTURER];
if (templinearray[calendarCourse::CourseScheme::POINTS].compare(" ") == 0) if (templinearray[calendarCourse::CourseScheme::POINTS].compare(" ") == 0)
points = stod(templinearray[calendarCourse::CourseScheme::POINTS]); points = templinearray[calendarCourse::CourseScheme::POINTS].toDouble();
else else
points = 0; points = 0;
if (templinearray[calendarCourse::CourseScheme::SEM_HOURS].compare(" ") == 0) if (templinearray[calendarCourse::CourseScheme::SEM_HOURS].compare(" ") == 0)
semesterHours = stod(templinearray[calendarCourse::CourseScheme::SEM_HOURS]); 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];

View file

@ -4,28 +4,28 @@
#include "../page.h" #include "../page.h"
#include "calendarCourse.h" #include "calendarCourse.h"
#include <list> #include <list>
#include <string.h> //strlen and strtok to phrase the html file //#include <string.h> //strlen and strtok to phrase the html file
#include <ctype.h> //checks if character is numeric //#include <ctype.h> //checks if character is numeric
class CalendarPage : public Page class CalendarPage : public Page
{ {
public: public:
std::string htmlToString(); QString htmlToString();
std::list<calendarCourse*>* getCourses() { return courses; } std::list<calendarCourse*>* getCourses() { return courses; }
protected: protected:
virtual void setPage(std::string html); virtual void setPage(QString html);
CalendarPage() { } CalendarPage() { }
private: private:
std::string tokenToLines(std::string& textToPhrase); QString tokenToLines(QString &textToParse);
void calendarListInit(std::string& linesTokinzedString); void calendarListInit(QString &linesTokinzedString);
calendarCourse* lineToCourse(std::string line); calendarCourse* lineToCourse(QString line);
std::string tempHtml; QString tempHtml;
std::list<calendarCourse*>* courses; std::list<calendarCourse*>* courses;

View file

@ -34,7 +34,7 @@ calendarSchedule::calendarSchedule()
} }
void calendarSchedule::setPage(std::string html) void calendarSchedule::setPage(QString html)
{ {
CalendarPage::setPage(html); CalendarPage::setPage(html);
@ -69,7 +69,7 @@ void calendarSchedule::insertCourseIntoTable()
{ {
row = currentHour % HOURS_BEGIN; row = currentHour % HOURS_BEGIN;
col = currentDay-1; col = currentDay-1;
courseString = (QString::fromStdString(coursePtr->getName() + " \n" + coursePtr->getLecturer() + " \n" + coursePtr->getRoom())); courseString = (QString(coursePtr->getName() + " \n" + coursePtr->getLecturer() + " \n" + coursePtr->getRoom()));
item = new QTableWidgetItem(courseString); item = new QTableWidgetItem(courseString);
if (this->takeItem(row,col) != NULL) if (this->takeItem(row,col) != NULL)
delete this->takeItem(row,col); delete this->takeItem(row,col);

View file

@ -19,7 +19,7 @@ class calendarSchedule : public QTableWidget, public CalendarPage
public: public:
calendarSchedule(); calendarSchedule();
~calendarSchedule() { clearTableItems(); } ~calendarSchedule() { clearTableItems(); }
void setPage(std::string html); void setPage(QString html);
void clearTableItems(); void clearTableItems();
signals: signals:

View file

@ -1,6 +1,6 @@
#include "gradeCourse.h" #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) gradeCourse::gradeCourse(int serial, QString name, QString type, double points, double hours, double grade, QString additions) : Course(serial,name,type,points)
{ {
this->hours = hours; this->hours = hours;
this->grade = grade; this->grade = grade;
@ -30,7 +30,7 @@ void gradeCourse::setGrade(double grade)
this->grade = grade; this->grade = grade;
} }
void gradeCourse::setAdditions(std::string additions) void gradeCourse::setAdditions(QString additions)
{ {
this->additions = additions; this->additions = additions;
} }

View file

@ -30,22 +30,22 @@ public:
ADDITION ADDITION
}; };
gradeCourse(int serial, std::string name, std::string type, double points,double hours, double grade, std::string additions); gradeCourse(int serial, QString name, QString type, double points,double hours, double grade, QString additions);
~gradeCourse(); ~gradeCourse();
double getHours() const {return this->hours;} double getHours() const {return this->hours;}
double getGrade() const ; double getGrade() const ;
std::string getAddidtions() const {return this->additions;} QString getAddidtions() const {return this->additions;}
void setHours(double hours); void setHours(double hours);
void setGrade(double grade); void setGrade(double grade);
void setAdditions(std::string additions); void setAdditions(QString additions);
private: private:
double hours; double hours;
double grade; double grade;
std::string additions; QString additions;
}; };

View file

@ -1,11 +1,11 @@
#include "gradePage.h" #include "gradePage.h"
GradePage::GradePage(std::string html) : Page() GradePage::GradePage(QString html) : Page()
{ {
this->courses = new std::list<gradeCourse*>(); courses = new std::list<gradeCourse*>();
this->tempHtml = getString(html); tempHtml = getString(html);
this->tempHtml = tokenToLines(this->tempHtml); tempHtml = tokenToLines(tempHtml);
coursesListInit(this->tempHtml); coursesListInit(tempHtml);
} }
GradePage::~GradePage() GradePage::~GradePage()
@ -15,17 +15,11 @@ GradePage::~GradePage()
delete courses; delete courses;
} }
void GradePage::addCourse(gradeCourse *a) void GradePage::removeCourse(QString courseSerialID)
{
GradePage::courses->push_back(a);
return;
}
void GradePage::removeCourse(std::string courseSerialID)
{ {
for(gradeCourse* c : *courses) for(gradeCourse* c : *courses)
{ {
if (c->getSerialNum() == stoi(courseSerialID)) if (c->getSerialNum() == courseSerialID.toInt())
{ {
courses->remove(c); courses->remove(c);
delete c; delete c;
@ -34,13 +28,13 @@ void GradePage::removeCourse(std::string courseSerialID)
} }
} }
void GradePage::coursesListInit(std::string& linesTokinzedString) void GradePage::coursesListInit(QString &linesTokinzedString)
{ {
std::list<std::string> stringHolder; std::list<QString> stringHolder;
std::string temp; QString temp;
gradeCourse* cTemp = NULL; gradeCourse* cTemp = NULL;
char* tok; char* tok;
char* textToTok = strdup(linesTokinzedString.c_str()); char* textToTok = strdup(linesTokinzedString.toStdString().c_str());
tok = strtok(textToTok,"\n"); tok = strtok(textToTok,"\n");
while (tok != NULL) while (tok != NULL)
{ {
@ -48,20 +42,20 @@ void GradePage::coursesListInit(std::string& linesTokinzedString)
stringHolder.push_back(temp); stringHolder.push_back(temp);
tok = strtok(NULL, "\n"); tok = strtok(NULL, "\n");
} }
for(std::string temp: stringHolder) for(QString temp: stringHolder)
{ {
cTemp = lineToCourse(temp); cTemp = lineToCourse(temp);
if (cTemp != NULL) if (cTemp != NULL)
addCourse(cTemp); courses->push_back(cTemp);
} }
} }
std::string GradePage::tokenToLines(std::string& textToPhrase) QString GradePage::tokenToLines(QString &textToPhrase)
{ {
int ctr = 0; int ctr = 0;
std::string temp = ""; QString temp = "";
char *tok; char *tok;
char* textToTok = strdup(textToPhrase.c_str()); char* textToTok = strdup(textToPhrase.toStdString().c_str());
tok = strtok(textToTok, "\n"); tok = strtok(textToTok, "\n");
while(tok != NULL) while(tok != NULL)
{ {
@ -77,17 +71,17 @@ std::string GradePage::tokenToLines(std::string& textToPhrase)
return temp; return temp;
} }
gradeCourse* GradePage::lineToCourse(std::string line) gradeCourse* GradePage::lineToCourse(QString line)
{ {
gradeCourse *tempC = NULL; gradeCourse *tempC = NULL;
std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions] QString templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
int serial; int serial;
double points,hours,grade; double points,hours,grade;
std::string name,type, additions; QString name,type, additions;
std::string tempS = ""; QString tempS = "";
int i = 0; int i = 0;
char* tok; char* tok;
char* cLine = strdup(line.c_str()); char* cLine = strdup(line.toStdString().c_str());
tok = strtok(cLine, "\t"); tok = strtok(cLine, "\t");
while(tok != NULL) while(tok != NULL)
{ {
@ -98,37 +92,38 @@ gradeCourse* GradePage::lineToCourse(std::string line)
tempS = ""; tempS = "";
char *tokTemp; char *tokTemp;
tokTemp = tok; tokTemp = tok;
while (!(isdigit((int)*tokTemp))) while (!(isdigit((int)*tokTemp)))
tokTemp++; tokTemp++;
while (isdigit((int)*tokTemp)) while (isdigit((int)*tokTemp))
{ {
tempS += *tokTemp; tempS += QString(*tokTemp);
tokTemp++; tokTemp++;
} }
templinearray[i-1] = tempS; templinearray[i-1] = tempS;
templinearray[i] = tokTemp; templinearray[i] = QString(tokTemp);
} }
else if (i > 1) else if (i > 1)
{
templinearray[i] = tempS; templinearray[i] = tempS;
}
i++; i++;
tok=strtok(NULL, "\t"); tok=strtok(NULL, "\t");
} }
if (templinearray[0] == "") //empty phrasing if (templinearray[0] == "") //empty phrasing
return NULL; return NULL;
serial = stoi(templinearray[gradeCourse::CourseScheme::SERIAL]); serial = templinearray[gradeCourse::CourseScheme::SERIAL].toInt();
name = templinearray[gradeCourse::CourseScheme::NAME]; name = templinearray[gradeCourse::CourseScheme::NAME];
type = templinearray[gradeCourse::CourseScheme::TYPE]; type = templinearray[gradeCourse::CourseScheme::TYPE];
points = stod(templinearray[gradeCourse::CourseScheme::POINTS]); points = templinearray[gradeCourse::CourseScheme::POINTS].toDouble();
hours = stod(templinearray[gradeCourse::CourseScheme::HOURS]); hours = templinearray[gradeCourse::CourseScheme::HOURS].toDouble();
if (isGradedYet(templinearray[gradeCourse::CourseScheme::GRADE])) if (isGradedYet(templinearray[gradeCourse::CourseScheme::GRADE]))
grade = stod(templinearray[gradeCourse::CourseScheme::GRADE]); grade = templinearray[gradeCourse::CourseScheme::GRADE].toDouble();
else else
grade = NO_GRADE_YET; grade = NO_GRADE_YET;
@ -139,12 +134,12 @@ gradeCourse* GradePage::lineToCourse(std::string line)
} }
//checking if one of the chars inside grade is not a number //checking if one of the chars inside grade is not a number
bool GradePage::isGradedYet(std::string grade) bool GradePage::isGradedYet(QString grade)
{ {
if (strlen(grade.c_str()) <= 1) if (strlen(grade.toStdString().c_str()) <= 1)
return false; return false;
for (char c: grade) for (char c: grade.toStdString())
{ {
if (c == '\0') if (c == '\0')
break; break;

View file

@ -4,7 +4,7 @@
/* This Code Made By Sagi Dayan /* This Code Made By Sagi Dayan
* SagiDayan@gmail.com * SagiDayan@gmail.com
* *
* Minor changes has been made by Liran Ben Gida * Changes has been made by Liran Ben Gida
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */
@ -12,32 +12,29 @@
#include "../Grades/gradeCourse.h" #include "../Grades/gradeCourse.h"
#include <list> #include <list>
#include <string.h> //strlen and strtok to phrase the html file
#include <ctype.h> //checks if character is numeric
class GradePage : public Page class GradePage : public Page
{ {
public: public:
GradePage(std::string html); GradePage(QString html);
~GradePage(); ~GradePage();
void addCourse(gradeCourse *); void removeCourse(QString courseSerialID);
void removeCourse(std::string courseSerialID);
double getAvg(); double getAvg();
std::list<gradeCourse*>* getCourses() { return courses; } std::list<gradeCourse*>* getCourses() { return courses; }
private: private:
std::string tokenToLines(std::string& textToPhrase); QString tokenToLines(QString &textToPhrase);
void coursesListInit(std::string& linesTokinzedString); void coursesListInit(QString &linesTokinzedString);
gradeCourse* lineToCourse(std::string line); gradeCourse* lineToCourse(QString line);
bool isGradedYet(std::string grade); bool isGradedYet(QString grade);
std::list<gradeCourse*>* courses; std::list<gradeCourse*>* courses;
std::string tempHtml; QString tempHtml;
}; };

View file

@ -8,8 +8,7 @@
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */
#include <string> #include <QString>
#include <iostream>
#include <list> #include <list>
@ -17,7 +16,7 @@ class Course {
public: public:
Course(int serial,std::string name, std::string type, double points) { Course(int serial,QString name, QString type, double points) {
this->serialNum = serial; this->serialNum = serial;
this->name = name; this->name = name;
this->type = type; this->type = type;
@ -26,20 +25,20 @@ public:
virtual ~Course() { } virtual ~Course() { }
int getSerialNum() const {return this->serialNum;} int getSerialNum() const {return this->serialNum;}
virtual std::string getName() const {return this->name;} virtual QString getName() const {return this->name;}
virtual std::string getType() const {return this->type;} virtual QString getType() const {return this->type;}
virtual double getPoints() const {return this->points;} virtual double getPoints() const {return this->points;}
virtual void setName(std::string name) { this->name = name;} virtual void setName(QString name) { this->name = name;}
virtual void setType(std::string type){ this->type = type;} virtual void setType(QString type){ this->type = type;}
virtual void setPoints(double points){ this->points = points;} virtual void setPoints(double points){ this->points = points;}
private: private:
int serialNum; int serialNum;
std::string name; QString name;
std::string type; QString type;
double points; double points;
}; };

View file

@ -1,45 +1,40 @@
#include "page.h" #include "page.h"
Page::Page() Page::Page() {}
/**
* @brief Page::getString
* @param htmlToPhrased
* @return
*/
QString Page::getString(QString &htmlToParse)
{ {
makeText(htmlToParse);
}
std::string Page::getString(std::string& htmlToPhrased)
{
makeText(htmlToPhrased);
return this->text; return this->text;
} }
void Page::makeText(std::string& html) void Page::makeText(QString &html)
{ {
int index = 0; int index = 0;
index = runToActualText(html, index); //set index into the actual 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);
qDebug() << "page after parsing " << text;
} }
/**
int Page::runToActualText(std::string& from, int index) * @brief Page::manageTableContent strip html, make it string
* @param html html to parse
* @param index index to start looking for data
*/
void Page::manageTableContent(QString &html, int index)
{ {
while (index < (int)from.length()) if (index == -1)
return;
QString temp;
for (int i = index; i < html.length(); i++)
{ {
if (from[index] == '<') if(html.at(i) == '<')
{
if (from.substr(index,7) == "<tbody>")
return index+7;
}
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] == '<')
{ {
//<tr> / <td> / <th> //<tr> / <td> / <th>
std::string endofTable = "</tbody>"; QString endofTable = "</tbody>";
std::string tableTag = html.substr(i, 4); //legth of "tr/td" QString tableTag = html.mid(i, 4); //legth of "tr/td"
if (tableTag == "<tr>") if (tableTag == "<tr>")
{ {
temp += "\n"; //new row -> new line temp += "\n"; //new row -> new line
@ -50,7 +45,7 @@ void Page::manageTableContent(std::string& html, int index)
else if (tableTag == "<td>" || tableTag == "<th>") else if (tableTag == "<td>" || tableTag == "<th>")
{ {
temp += "\t"; // new cell -> tab between data temp += "\t"; // new cell -> tab between data
if (html.substr(i, 6) == "<td><a") //link to lecturer portal, need to be deleted if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
{ {
i += 6; i += 6;
while (html.at(++i) != '>'); while (html.at(++i) != '>');
@ -64,11 +59,11 @@ void Page::manageTableContent(std::string& html, int index)
else if(tableTag == "<td ") // a Year title (in grades table) else if(tableTag == "<td ") // a Year title (in grades table)
{ {
temp += "\t"; temp += "\t";
while(html[i] != '>') while(html.at(i) != '>')
i++; i++;
i = stitchText(html, temp, i+1); i = stitchText(html, temp, i+1);
} }
else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table else if (html.mid(i,(endofTable).length()) == endofTable) //is end of table
{ {
break; break;
} }
@ -79,26 +74,26 @@ void Page::manageTableContent(std::string& html, int index)
this->text = temp; this->text = temp;
} }
int Page::stitchText(std::string& from, std::string& to, int index) int Page::stitchText(QString &from, QString &to, int index)
{ {
if (from[index] == '<') if (from.at(index) == '<')
{ {
std::string bTag = from.substr(index, 3); QString bTag = from.mid(index, 3);
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 += 3; index += 3;
} }
while (from[index] != '<' && index < (int)from.length()) while (from.at(index) != '<' && index < (int)from.length())
{ {
if (from[index] == '&') if (from[index] == '&')
{ {
//&nbsp; //&nbsp;
std::string nbspChr = from.substr(index, 6); QString nbspChr = from.mid(index, 6);
if (nbspChr == "&nbsp;") if (nbspChr == "&nbsp;")
{ {
index += 5; index += 5;
from.at(index) = ' '; from.replace(index,1,' ');
} }
} }
@ -106,11 +101,11 @@ int Page::stitchText(std::string& from, std::string& to, int index)
if (endOfString(index,(int) from.length())) if (endOfString(index,(int) from.length()))
return -1; //EOF return -1; //EOF
else if (from[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[index] != '\n') //check the actuall data before continue if (from.at(index) != '\n') //check the actuall data before continue
to += from[index]; to += from.at(index);
index++; index++;
} }

View file

@ -4,35 +4,36 @@
/* This Code Made By Sagi Dayan /* This Code Made By Sagi Dayan
* SagiDayan@gmail.com * SagiDayan@gmail.com
* *
* Minor changes has been made by Liran Ben Gida * Changes has been made by Liran Ben Gida
* LiranBG@gmail.com * LiranBG@gmail.com
*/ */
#include <QDebug>
#include <QString>
#include <iostream> /**
#include <string> * @brief The Page class
* parsing given page - strip and clean html tags
* use only with JCE
*/
class Page class Page
{ {
public: public:
~Page() {} ~Page() {}
protected: protected:
Page(); Page();
std::string getString(std::string& htmlToPhrased); QString getString(QString &htmlToParse);
void makeText(std::string& html); void makeText(QString &html);
private: private:
int runToActualText(std::string& from, int index); void manageTableContent(QString &html, int index);
void manageTableContent(std::string& html, int index); int stitchText(QString &from, QString &to, int index);
int stitchText(std::string& from, std::string& to, int index);
bool endOfString(int index, int length); bool endOfString(int index, int length);
std::string text; QString text;
std::string title; QString title;
}; };

View file

@ -1,12 +1,16 @@
#ifndef JCELOGINHTMLSCRIPTS_H #ifndef JCELOGINHTMLSCRIPTS_H
#define JCELOGINHTMLSCRIPTS_H #define JCELOGINHTMLSCRIPTS_H
#include <string> #include "./src/jceSettings/user.h"
#define dst_host "yedion.jce.ac.il" #define dst_host "yedion.jce.ac.il"
#define dst_port 443 #define dst_port 443
#include "./src/jceSettings/user.h" /**
* @brief The jceLoginHtmlScripts class
* this class gets parameters and making the httml request string to be sent
* the headers of the http request were written according to JCE's student portal login page
*/
class jceLoginHtmlScripts class jceLoginHtmlScripts
{ {
@ -17,13 +21,13 @@ private:
public: public:
static std::string makeRequest(std::string parameters) static QString makeRequest(QString parameters)
{ {
std::string msg; QString msg;
msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n"; msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n";
msg += "Host: " + std::string(dst_host) + "\r\n"; msg += "Host: " + QString(dst_host) + "\r\n";
msg += "Content-Type: application/x-www-form-urlencoded\r\n"; msg += "Content-Type: application/x-www-form-urlencoded\r\n";
msg += "Content-Length: " + to_string(parameters.length()) + "\r\n"; msg += "Content-Length: " + QString::number(parameters.length()) + "\r\n";
msg += "Proxy-Connection: Keep-Alive\r\n"; msg += "Proxy-Connection: Keep-Alive\r\n";
msg += "Accept-Charset: UTF-8"; msg += "Accept-Charset: UTF-8";
msg += "Accept: text/plain\r\n"; msg += "Accept: text/plain\r\n";
@ -33,18 +37,18 @@ public:
return msg; return msg;
} }
const static std::string getFirstValidationStep(const user &usr) const static QString getFirstValidationStep(const user &usr)
{ {
std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N"; QString parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
parameters += usr.getUsername(); parameters += usr.getUsername();
parameters += ",-N"; parameters += ",-N";
parameters += usr.getPassword(); parameters += usr.getPassword();
return parameters; return parameters;
} }
const static std::string getSecondValidationStep(const user &usr) const static QString getSecondValidationStep(const user &usr)
{ {
std::string parameters; QString parameters;
parameters = "prgname=LoginValidtion1&Arguments=-N"; parameters = "prgname=LoginValidtion1&Arguments=-N";
parameters += usr.getUserID(); parameters += usr.getUserID();
parameters += ",-A,-N"; parameters += ",-A,-N";
@ -52,32 +56,32 @@ public:
parameters += ",-A,-A"; parameters += ",-A,-A";
return parameters; return parameters;
} }
const static std::string getGradesPath(const user &usr, const static QString getGradesPath(const user &usr,
int fromYear, int fromYear,
int toYear, int toYear,
int fromSemester, int fromSemester,
int toSemester) int toSemester)
{ {
std::string parameters; QString parameters;
parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&"; parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&";
parameters += "TZ=" + usr.getUserID() + "&"; parameters += "TZ=" + usr.getUserID() + "&";
parameters += "UNIQ=" + usr.getHashedPassword() + "&"; parameters += "UNIQ=" + usr.getHashedPassword() + "&";
parameters += "R1C2=" + std::to_string(fromYear) + "&"; parameters += "R1C2=" + QString::number(fromYear) + "&";
parameters += "R1C1=" + std::to_string(toYear) + "&"; parameters += "R1C1=" + QString::number(toYear) + "&";
parameters += "R1C3=" + std::to_string(toSemester) + "&"; parameters += "R1C3=" + QString::number(toSemester) + "&";
parameters += "R1C4=" + std::to_string(fromSemester) + "&"; parameters += "R1C4=" + QString::number(fromSemester) + "&";
parameters += "R1C5=0"; parameters += "R1C5=0";
return parameters; return parameters;
} }
const static std::string getCalendar(const user &usr,int year, int semester) const static QString getCalendar(const user &usr,int year, int semester)
{ {
std::string parameters; QString parameters;
parameters = "PRGNAME=Bitsua_maarechet_shaot&ARGUMENTS=TZ,UNIQ,MisparSheilta,R1C1,R1C2&"; parameters = "PRGNAME=Bitsua_maarechet_shaot&ARGUMENTS=TZ,UNIQ,MisparSheilta,R1C1,R1C2&";
parameters += "TZ=" + usr.getUserID() + "&"; parameters += "TZ=" + usr.getUserID() + "&";
parameters += "UNIQ=" + usr.getHashedPassword() + "&"; parameters += "UNIQ=" + usr.getHashedPassword() + "&";
parameters += "MisparSheilta=3&"; parameters += "MisparSheilta=3&";
parameters += "R1C1=" + std::to_string(year) + "&"; parameters += "R1C1=" + QString::number(year) + "&";
parameters += "R1C2=" + std::to_string(semester) + "&"; parameters += "R1C2=" + QString::number(semester) + "&";
return parameters; return parameters;
} }

View file

@ -1,8 +1,12 @@
#include "jcelogin.h" #include "jcelogin.h"
/**
* @brief jceLogin::jceLogin
* @param username pointer to allocated user settings
*/
jceLogin::jceLogin(user * username) jceLogin::jceLogin(user * username)
{ {
this->recieverPage = new std::string(); this->recieverPage = new QString();
this->jceA = username; this->jceA = username;
this->JceConnector = new jceSSLClient(); this->JceConnector = new jceSSLClient();
} }
@ -21,16 +25,19 @@ jceLogin::~jceLogin()
*/ */
void jceLogin::makeConnection() throw (jceStatus) void jceLogin::makeConnection() throw (jceStatus)
{ {
if (this->recieverPage == NULL) qDebug() << "jceLogin::makeConnection(); connection to be make";
this->recieverPage = new std::string();
if (JceConnector->makeConnect(dst_host,dst_port) == false) if (this->recieverPage == NULL)
this->recieverPage = new QString();
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
throw jceStatus::ERROR_ON_OPEN_SOCKET; throw jceStatus::ERROR_ON_OPEN_SOCKET;
int returnMode; 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(); returnMode = checkConnection(); //checking socket status. is connected?
if (returnMode == true) //connected to host if (returnMode == true) //connected to host
{ {
returnMode = makeFirstVisit(); returnMode = makeFirstVisit();
@ -44,6 +51,7 @@ void jceLogin::makeConnection() throw (jceStatus)
returnMode = makeSecondVisit(); returnMode = makeSecondVisit();
if (returnMode == true) //siging in the website if (returnMode == true) //siging in the website
{ {
qDebug() << "jceLogin::makeConnection(); Signed in succeesfully";
status = jceStatus::JCE_YOU_ARE_IN; status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true); setLoginFlag(true);
} }
@ -78,10 +86,14 @@ void jceLogin::makeConnection() throw (jceStatus)
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(); throw status: " << status;
throw status; throw status;
} }
/**
* @brief jceLogin::checkConnection
* @return if connected true, otherwise false
*/
bool jceLogin::checkConnection() const bool jceLogin::checkConnection() const
{ {
if (JceConnector->isConnected()) if (JceConnector->isConnected())
@ -89,17 +101,21 @@ bool jceLogin::checkConnection() const
return false; return false;
} }
/**
* @brief jceLogin::reConnect
* closing connection and deleting pointers.
* calling class's makeConnection function and throw the exception of it.
*/
void jceLogin::reConnect() throw (jceStatus) void jceLogin::reConnect() throw (jceStatus)
{ {
closeAll(); closeAll();
if (this->JceConnector != NULL) if (this->JceConnector != NULL)
delete JceConnector; delete JceConnector;
this->recieverPage = new std::string(); this->recieverPage = new QString();
this->JceConnector = new jceSSLClient(); this->JceConnector = new jceSSLClient();
try try
{ {
makeConnection(); makeConnection();
} }
catch (jceLogin::jceStatus &a) catch (jceLogin::jceStatus &a)
@ -107,20 +123,24 @@ void jceLogin::reConnect() throw (jceStatus)
throw a; throw a;
} }
} }
/**
* @brief jceLogin::closeAll
*/
void jceLogin::closeAll() void jceLogin::closeAll()
{ {
JceConnector->makeDiconnect(); JceConnector->makeDiconnect();
delete recieverPage; delete recieverPage;
recieverPage = NULL; recieverPage = NULL;
loginFlag = false;
} }
/**
* @brief jceLogin::makeFirstVisit making the first validation step of jce student portal login
* @return jceLogin enum list on error, true if valid
*/
int jceLogin::makeFirstVisit() int jceLogin::makeFirstVisit()
{ {
std::string usr = jceA->getUsername(); QString usr = jceA->getUsername();
std::string 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))
@ -131,11 +151,14 @@ int jceLogin::makeFirstVisit()
return true; return true;
} }
/**
* @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login
* @return jceLogin enum list on error, true if valid
*/
int jceLogin::makeSecondVisit() int jceLogin::makeSecondVisit()
{ {
std::string usrid=jceA->getUserID(); QString usrid=jceA->getUserID();
std::string 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)))
@ -148,7 +171,12 @@ int jceLogin::makeSecondVisit()
return true; return true;
} }
/**
* @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server
* @param year - selected year
* @param semester - selected semester
* @return true if ok, jceLogin enum on error (recieverPage has html to parse if true)
*/
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)))))
@ -164,6 +192,14 @@ int jceLogin::getCalendar(int year, int semester)
return true; return true;
} }
/**
* @brief jceLogin::getGrades according to parameters, we make an HTML request and send it over socket to server
* @param fromYear - from year
* @param toYear - to year
* @param fromSemester - from semester
* @param toSemester - to semester
* @return true if ok, jceLogin enum on error (recieverPage has html to parse if true)
*/
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester) int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
{ {
std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl; std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
@ -180,11 +216,63 @@ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemest
return true; return true;
} }
/**
* @brief jceLogin::checkValidation Made by Nadav Luzzato
* @return true if second validation step is right
*/
bool jceLogin::checkValidation()
{
//finds the hashed password
QString constUserID_TAG = "value=\"-N";
QString constHassID_TAG = "-A,-N";
QString hasspass,hassid;
std::size_t hasspass_position1,hasspass_position2;
std::size_t id_position1,id_position2;
hasspass_position1 = this->recieverPage->toStdString().find(constHassID_TAG.toStdString()); //looking for hasspass index
if (hasspass_position1 == std::string::npos) //didnt find the tag
return false;
else
hasspass_position1 += constHassID_TAG.length(); //skip the index of tag
hasspass_position2 = this->recieverPage->toStdString().find(",-A,-A", hasspass_position1);
//finds the hass pass
if (hasspass_position2 != std::string::npos) //found the hasspass! storing it
hasspass = recieverPage->mid(hasspass_position1,hasspass_position2-hasspass_position1);
else
return false;
//finds the user id
id_position1 = this->recieverPage->toStdString().find(constUserID_TAG.toStdString(), 0); //looking for hassid index
if (id_position1 == std::string::npos) //didnt find the tag
return false;
else
id_position1 += constUserID_TAG.length(); //skip the index of tag
id_position2 = this->recieverPage->toStdString().find(",-A", id_position1);
if (id_position2 != std::string::npos) //found the hassid! storing it
hassid = recieverPage->mid(id_position1,id_position2-id_position1);
else
return false;
//setting user information with given data hassid and hasspass
jceA->setHashedPassword(hasspass);
jceA->setUserID(hassid);
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
return true;
}
/**
* @brief jceLogin::setLoginFlag
* @param x
*/
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)
* @return
*/
bool jceLogin::isLoginFlag() const bool jceLogin::isLoginFlag() const
{ {
if (checkConnection()) if (checkConnection())
@ -192,41 +280,11 @@ bool jceLogin::isLoginFlag() const
return false; return false;
} }
/**
std::string jceLogin::getPage() * @brief jceLogin::getPage
* @return html page
*/
QString jceLogin::getPage()
{ {
return *recieverPage; 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;
}

View file

@ -1,13 +1,12 @@
#ifndef JCELOGIN_H #ifndef JCELOGIN_H
#define JCELOGIN_H #define JCELOGIN_H
#include <string>
#include <fstream>
#include "./src/jceConnection/jcesslclient.h" #include "./src/jceConnection/jcesslclient.h"
#include "./src/jceSettings/user.h" #include "./src/jceSettings/user.h"
#include "jceLoginHtmlScripts.h" #include "jceLoginHtmlScripts.h"
#include <QString>
class jceLogin class jceLogin
{ {
public: public:
@ -29,28 +28,28 @@ public:
jceLogin(user* username); jceLogin(user* username);
~jceLogin(); ~jceLogin();
void makeConnection() throw (jceStatus); void makeConnection() throw (jceStatus);
bool checkConnection() const;
void reConnect() throw (jceStatus); void reConnect() throw (jceStatus);
void closeAll(); void closeAll();
int getCalendar(int year, int semester);
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester); bool checkConnection() const;
bool isLoginFlag() const; bool isLoginFlag() const;
std::string getPage(); int getCalendar(int year, int semester);
int getGrades(int fromYear, int toYear, int fromSemester, int toSemester);
QString getPage();
private: private:
int makeFirstVisit(); int makeFirstVisit();
bool checkValidation();
int makeSecondVisit(); int makeSecondVisit();
bool checkValidation();
void setLoginFlag(bool x); void setLoginFlag(bool x);
bool loginFlag; bool loginFlag;
std::string * recieverPage; QString * recieverPage;
user * jceA; user * jceA;
jceSSLClient * JceConnector; jceSSLClient * JceConnector;

View file

@ -1,45 +1,73 @@
#include "user.h" #include "user.h"
/**
user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false) * @brief user::user Constructor
* @param username user name
* @param password password
*/
user::user(QString username,QString password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
{ {
this->username = username; this->username = username;
this->password = password; this->password = password;
} }
user::~user() user::~user()
{ {
} }
/**
* @brief user::setInfluenceCourseOnly
* @param status show only courses with influnce?
*/
void user::setInfluenceCourseOnly(bool status) void user::setInfluenceCourseOnly(bool status)
{ {
this->influenceCourseOnly = status; this->influenceCourseOnly = status;
} }
/**
* @brief user::getInfluenceCourseOnly
* @return if user wants to show only influence courses
*/
bool user::getInfluenceCourseOnly() const bool user::getInfluenceCourseOnly() const
{ {
return this->influenceCourseOnly; return this->influenceCourseOnly;
} }
/**
void user::setUsername(string& username) { * @brief user::setUsername
* @param username given username to change to
*/
void user::setUsername(QString& username)
{
this->username = username; this->username = username;
} }
/**
void user::setPassword(string& password) { * @brief user::setPassword
* @param password given password to change to
*/
void user::setPassword(QString& password)
{
this->password = password; this->password = password;
} }
/**
void user::setUserID(string& ID) * @brief user::setUserID
* @param ID given ID from html
*/
void user::setUserID(QString& ID)
{ {
this->userID = ID; this->userID = ID;
} }
void user::setHashedPassword(string& hashpass) /**
* @brief user::setHashedPassword
* @param hashpass given hashed password given from html
*/
void user::setHashedPassword(QString& hashpass)
{ {
this->hashedPassword = hashpass; this->hashedPassword = hashpass;
} }
/**
string user::getPassword() const { return password; } * @brief user::get*
string user::getUsername() const { return username; } * @return getters
string user::getUserID() const { return userID; } */
string user::getHashedPassword() const { return hashedPassword; } QString user::getPassword() const { return password; }
QString user::getUsername() const { return username; }
QString user::getUserID() const { return userID; }
QString user::getHashedPassword() const { return hashedPassword; }

View file

@ -1,42 +1,39 @@
#ifndef user_H #ifndef user_H
#define user_H #define user_H
#include <string> #include <QString>
#include <iostream>
using namespace std;
class user class user
{ {
public: public:
user(string username,string password);
user(QString username,QString password);
~user(); ~user();
void setUsername(string& username); void setUsername(QString& username);
void setPassword(string& password); void setPassword(QString& password);
string getPassword() const; QString getPassword() const;
string getUsername() const; QString getUsername() const;
void setUserID(string& ID); void setUserID(QString& ID);
void setHashedPassword(string& hashpass); void setHashedPassword(QString& hashpass);
string getUserID() const; QString getUserID() const;
string getHashedPassword() const; QString getHashedPassword() const;
void setInfluenceCourseOnly(bool status); void setInfluenceCourseOnly(bool status);
bool getInfluenceCourseOnly() const; bool getInfluenceCourseOnly() const;
private: private:
string username; QString username;
string password; QString password;
string hashedPassword; QString hashedPassword;
string userID; QString userID;
bool influenceCourseOnly; bool influenceCourseOnly;
}; };
#endif #endif