diff --git a/main/coursestablemanager.h b/main/coursestablemanager.h index 21262a1..c136866 100644 --- a/main/coursestablemanager.h +++ b/main/coursestablemanager.h @@ -13,7 +13,6 @@ #include -#include "src/grades/Course.h" #include "src/grades/GradePage.h" #include "src/user.h" diff --git a/main/loginhandler.cpp b/main/loginhandler.cpp index f2108c3..6c73ecb 100644 --- a/main/loginhandler.cpp +++ b/main/loginhandler.cpp @@ -1,12 +1,12 @@ #include "loginhandler.h" -loginHandler::loginHandler() +loginHandler::loginHandler(user *ptr): logggedInFlag(false) +{ + this->jceLog = new jceLogin(ptr); +} +void loginHandler::setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) { -} -void loginHandler::setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr) -{ - this->jceLog = ptr; this->statusLabelPtr = statusLabelPtr; this->pswdEditPtr = pswdEditPtr; this->usrnmEditPtr = usrnmEditPtr; @@ -28,7 +28,8 @@ bool loginHandler::makeConnection() { case jceLogin::JCE_YOU_ARE_IN: { - return true; + logggedInFlag = true; + return logggedInFlag; break; } case jceLogin::ERROR_ON_VALIDATION: @@ -80,6 +81,40 @@ bool loginHandler::makeConnection() } return false; } + +bool loginHandler::isLoggedInFlag() +{ + return this->logggedInFlag; +} + +void loginHandler::setLoginFlag(bool flag) +{ + this->logggedInFlag = flag; +} + +QString loginHandler::getCurrentPageContect() +{ + QTextEdit phrase; + if (isLoggedInFlag()) + phrase.setText(QString::fromStdString(jceLog->getPage())); + else + throw jceLogin::ERROR_ON_GETTING_INFO; + + return phrase.toPlainText(); +} + +void loginHandler::makeDisconnectionRequest() +{ + jceLog->closeAll(); +} + +int loginHandler::makeGradeRequest() +{ + if (isLoggedInFlag()) + return jceLog->getGrades(); + else + return jceLogin::JCE_NOT_CONNECTED; +} void loginHandler::popMessage(QString message,bool addInfo) { if (addInfo) diff --git a/main/loginhandler.h b/main/loginhandler.h index ba32f13..1f5c08f 100644 --- a/main/loginhandler.h +++ b/main/loginhandler.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -12,15 +13,22 @@ class loginHandler { public: - loginHandler(); - void setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); + loginHandler(user *ptr); + void setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); bool makeConnection(); + bool isLoggedInFlag(); + void setLoginFlag(bool flag); + + QString getCurrentPageContect(); + int makeGradeRequest(); + + void makeDisconnectionRequest(); private: void popMessage(QString message, bool addInfo = true); - + bool logggedInFlag; jceLogin *jceLog; QLabel *statusLabelPtr; diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 91c12f5..d1027b9 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -28,10 +28,9 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr //Pointer allocating - this->jceLog = NULL; this->userLoginSetting = new user("",""); this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); - this->loginHandel = new loginHandler(); + this->loginHandel = new loginHandler(userLoginSetting); updateDates(); @@ -48,33 +47,30 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr MainScreen::~MainScreen() { delete userLoginSetting; - delete jceLog; delete loginHandel; delete ui; } void MainScreen::on_ratesButton_clicked() { - QTextEdit phrase; + std::string pageString; - if (this->jceLog != NULL) + int status = 0; + if (loginHandel->isLoggedInFlag()) { - if (jceLog->isLoginFlag() == true) + if ((status = loginHandel->makeGradeRequest()) == jceLogin::JCE_GRADE_PAGE_PASSED) { - if (jceLog->getGrades() == jceLogin::JCE_GRADE_PAGE_PASSED) - { - phrase.setText(QString::fromStdString(jceLog->getPage())); - pageString = phrase.toPlainText().toStdString(); - courseTableMgr->setCoursesList(pageString); - courseTableMgr->insertJceCoursesIntoTable(); - } - else - { - - } + pageString = loginHandel->getCurrentPageContect().toStdString(); + courseTableMgr->setCoursesList(pageString); + courseTableMgr->insertJceCoursesIntoTable(); + } + else if (status == jceLogin::JCE_NOT_CONNECTED) + { + QMessageBox::critical(this,tr("Error"),tr("Not Connected")); } - } + + } void MainScreen::on_spinBoxFromYear_editingFinished() @@ -134,15 +130,11 @@ void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) void MainScreen::on_loginButton_clicked() { - if (this->jceLog == NULL) - uiSetConnectMode(); + if (loginHandel->isLoggedInFlag()) + uiSetDisconnectMode(); + else - { - if (jceLog->isLoginFlag() == true) - uiSetDisconnectMode(); - else - uiSetConnectMode(); - } + uiSetConnectMode(); } @@ -173,8 +165,7 @@ void MainScreen::uiSetDisconnectMode() ui->usrnmLineEdit->setEnabled(true); ui->pswdLineEdit->setEnabled(true); - delete jceLog; - jceLog = NULL; + loginHandel->makeDisconnectionRequest(); ui->loginButton->setText("&Login"); this->ui->ratesButton->setDisabled(true); return; @@ -182,11 +173,6 @@ void MainScreen::uiSetDisconnectMode() void MainScreen::uiSetConnectMode() //fix before distrbute { - std::string page; - - if (this->jceLog != NULL) - delete jceLog; - string username; string password; if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) @@ -205,20 +191,10 @@ void MainScreen::uiSetConnectMode() //fix before distrbute userLoginSetting->setUsername(username); userLoginSetting->setPassword(password); - this->repaint(); - page = "connecting with username "; - page = username; - page += "and password: "; - page += password; - ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page)); - - jceLog = new jceLogin(userLoginSetting); - this->loginHandel->setPointers(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit); + this->loginHandel->setPointers(statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit); if (loginHandel->makeConnection() == true) { - page = this->jceLog->getPage(); - ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page)); setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); ui->loginButton->setText("&Logout"); this->ui->ratesButton->setEnabled(true); diff --git a/main/mainscreen.h b/main/mainscreen.h index cb4368f..18f5c8f 100644 --- a/main/mainscreen.h +++ b/main/mainscreen.h @@ -10,9 +10,6 @@ #include #include - -#include "src/grades/GradePage.h" -#include "src/jce/jcelogin.h" #include "coursestablemanager.h" #include "loginhandler.h" @@ -66,7 +63,6 @@ private: Ui::MainScreen *ui; - jceLogin *jceLog; user *userLoginSetting; coursesTableManager *courseTableMgr; diff --git a/src/connection/qtsslsocket.cpp b/src/connection/qtsslsocket.cpp index e936bd8..26698d4 100644 --- a/src/connection/qtsslsocket.cpp +++ b/src/connection/qtsslsocket.cpp @@ -42,11 +42,11 @@ bool qtsslsocket::isCon() //need to fix the method bool qtsslsocket::send(std::string str) { - int status; + // int status; bool flag = isCon(); if (flag) //if connected { - status = socket->write(str.c_str(),str.length()); + socket->write(str.c_str(),str.length()); while (socket->waitForBytesWritten()); } return flag; @@ -64,3 +64,11 @@ bool qtsslsocket::recieve(std::string &str) return flag; } + +bool qtsslsocket::makeDiconnect() +{ + this->socket->abort(); + if (socket->isOpen()) + return false; + return true; +} diff --git a/src/connection/qtsslsocket.h b/src/connection/qtsslsocket.h index 8953bbc..d469fdc 100644 --- a/src/connection/qtsslsocket.h +++ b/src/connection/qtsslsocket.h @@ -21,6 +21,7 @@ public: bool isCon(); bool send(std::string str); bool recieve(std::string &str); + bool makeDiconnect(); private: diff --git a/src/jce/jcelogin.cpp b/src/jce/jcelogin.cpp index 53cfb2b..9bf92f2 100644 --- a/src/jce/jcelogin.cpp +++ b/src/jce/jcelogin.cpp @@ -21,6 +21,9 @@ jceLogin::~jceLogin() */ void jceLogin::makeConnection() throw (jceStatus) { + if (this->recieverPage == NULL) + this->recieverPage = new std::string(); + if (JceConnector->makeConnect(dst_host,dst_port) == false) throw jceStatus::ERROR_ON_OPEN_SOCKET; @@ -96,6 +99,7 @@ void jceLogin::reConnect() throw (jceStatus) this->JceConnector = new qtsslsocket(); try { + makeConnection(); } catch (jceLogin::jceStatus &a) @@ -106,9 +110,10 @@ void jceLogin::reConnect() throw (jceStatus) void jceLogin::closeAll() { + JceConnector->makeDiconnect(); delete recieverPage; recieverPage = NULL; - JceConnector = NULL; + loginFlag = false; }