fix including hirarchy

This commit is contained in:
liranbg 2014-06-20 05:59:33 +03:00
parent c1d736ce02
commit ee25c1f94b
8 changed files with 89 additions and 61 deletions

View file

@ -13,7 +13,6 @@
#include <list> #include <list>
#include "src/grades/Course.h"
#include "src/grades/GradePage.h" #include "src/grades/GradePage.h"
#include "src/user.h" #include "src/user.h"

View file

@ -1,12 +1,12 @@
#include "loginhandler.h" #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->statusLabelPtr = statusLabelPtr;
this->pswdEditPtr = pswdEditPtr; this->pswdEditPtr = pswdEditPtr;
this->usrnmEditPtr = usrnmEditPtr; this->usrnmEditPtr = usrnmEditPtr;
@ -28,7 +28,8 @@ bool loginHandler::makeConnection()
{ {
case jceLogin::JCE_YOU_ARE_IN: case jceLogin::JCE_YOU_ARE_IN:
{ {
return true; logggedInFlag = true;
return logggedInFlag;
break; break;
} }
case jceLogin::ERROR_ON_VALIDATION: case jceLogin::ERROR_ON_VALIDATION:
@ -80,6 +81,40 @@ bool loginHandler::makeConnection()
} }
return false; 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) void loginHandler::popMessage(QString message,bool addInfo)
{ {
if (addInfo) if (addInfo)

View file

@ -3,6 +3,7 @@
#include <QString> #include <QString>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QTextEdit>
#include <QMessageBox> #include <QMessageBox>
#include <QPixmap> #include <QPixmap>
@ -12,15 +13,22 @@
class loginHandler class loginHandler
{ {
public: public:
loginHandler(); loginHandler(user *ptr);
void setPointers(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); void setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
bool makeConnection(); bool makeConnection();
bool isLoggedInFlag();
void setLoginFlag(bool flag);
QString getCurrentPageContect();
int makeGradeRequest();
void makeDisconnectionRequest();
private: private:
void popMessage(QString message, bool addInfo = true); void popMessage(QString message, bool addInfo = true);
bool logggedInFlag;
jceLogin *jceLog; jceLogin *jceLog;
QLabel *statusLabelPtr; QLabel *statusLabelPtr;

View file

@ -28,10 +28,9 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
//Pointer allocating //Pointer allocating
this->jceLog = NULL;
this->userLoginSetting = new user("",""); this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler(); this->loginHandel = new loginHandler(userLoginSetting);
updateDates(); updateDates();
@ -48,32 +47,29 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
MainScreen::~MainScreen() MainScreen::~MainScreen()
{ {
delete userLoginSetting; delete userLoginSetting;
delete jceLog;
delete loginHandel; delete loginHandel;
delete ui; delete ui;
} }
void MainScreen::on_ratesButton_clicked() void MainScreen::on_ratesButton_clicked()
{ {
QTextEdit phrase;
std::string pageString; 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) pageString = loginHandel->getCurrentPageContect().toStdString();
{
phrase.setText(QString::fromStdString(jceLog->getPage()));
pageString = phrase.toPlainText().toStdString();
courseTableMgr->setCoursesList(pageString); courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable(); courseTableMgr->insertJceCoursesIntoTable();
} }
else else if (status == jceLogin::JCE_NOT_CONNECTED)
{ {
QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
} }
} }
}
} }
@ -134,15 +130,11 @@ void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
void MainScreen::on_loginButton_clicked() void MainScreen::on_loginButton_clicked()
{ {
if (this->jceLog == NULL) if (loginHandel->isLoggedInFlag())
uiSetConnectMode();
else
{
if (jceLog->isLoginFlag() == true)
uiSetDisconnectMode(); uiSetDisconnectMode();
else else
uiSetConnectMode(); uiSetConnectMode();
}
} }
@ -173,8 +165,7 @@ void MainScreen::uiSetDisconnectMode()
ui->usrnmLineEdit->setEnabled(true); ui->usrnmLineEdit->setEnabled(true);
ui->pswdLineEdit->setEnabled(true); ui->pswdLineEdit->setEnabled(true);
delete jceLog; loginHandel->makeDisconnectionRequest();
jceLog = NULL;
ui->loginButton->setText("&Login"); ui->loginButton->setText("&Login");
this->ui->ratesButton->setDisabled(true); this->ui->ratesButton->setDisabled(true);
return; return;
@ -182,11 +173,6 @@ void MainScreen::uiSetDisconnectMode()
void MainScreen::uiSetConnectMode() //fix before distrbute void MainScreen::uiSetConnectMode() //fix before distrbute
{ {
std::string page;
if (this->jceLog != NULL)
delete jceLog;
string username; string username;
string password; string password;
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
@ -205,20 +191,10 @@ void MainScreen::uiSetConnectMode() //fix before distrbute
userLoginSetting->setUsername(username); userLoginSetting->setUsername(username);
userLoginSetting->setPassword(password); userLoginSetting->setPassword(password);
this->repaint(); this->loginHandel->setPointers(statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
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);
if (loginHandel->makeConnection() == true) if (loginHandel->makeConnection() == true)
{ {
page = this->jceLog->getPage();
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN); setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
ui->loginButton->setText("&Logout"); ui->loginButton->setText("&Logout");
this->ui->ratesButton->setEnabled(true); this->ui->ratesButton->setEnabled(true);

View file

@ -10,9 +10,6 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "src/grades/GradePage.h"
#include "src/jce/jcelogin.h"
#include "coursestablemanager.h" #include "coursestablemanager.h"
#include "loginhandler.h" #include "loginhandler.h"
@ -66,7 +63,6 @@ private:
Ui::MainScreen *ui; Ui::MainScreen *ui;
jceLogin *jceLog;
user *userLoginSetting; user *userLoginSetting;
coursesTableManager *courseTableMgr; coursesTableManager *courseTableMgr;

View file

@ -42,11 +42,11 @@ bool qtsslsocket::isCon()
//need to fix the method //need to fix the method
bool qtsslsocket::send(std::string str) bool qtsslsocket::send(std::string str)
{ {
int status; // int status;
bool flag = isCon(); bool flag = isCon();
if (flag) //if connected if (flag) //if connected
{ {
status = socket->write(str.c_str(),str.length()); socket->write(str.c_str(),str.length());
while (socket->waitForBytesWritten()); while (socket->waitForBytesWritten());
} }
return flag; return flag;
@ -64,3 +64,11 @@ bool qtsslsocket::recieve(std::string &str)
return flag; return flag;
} }
bool qtsslsocket::makeDiconnect()
{
this->socket->abort();
if (socket->isOpen())
return false;
return true;
}

View file

@ -21,6 +21,7 @@ public:
bool isCon(); bool isCon();
bool send(std::string str); bool send(std::string str);
bool recieve(std::string &str); bool recieve(std::string &str);
bool makeDiconnect();
private: private:

View file

@ -21,6 +21,9 @@ jceLogin::~jceLogin()
*/ */
void jceLogin::makeConnection() throw (jceStatus) void jceLogin::makeConnection() throw (jceStatus)
{ {
if (this->recieverPage == NULL)
this->recieverPage = new std::string();
if (JceConnector->makeConnect(dst_host,dst_port) == false) if (JceConnector->makeConnect(dst_host,dst_port) == false)
throw jceStatus::ERROR_ON_OPEN_SOCKET; throw jceStatus::ERROR_ON_OPEN_SOCKET;
@ -96,6 +99,7 @@ void jceLogin::reConnect() throw (jceStatus)
this->JceConnector = new qtsslsocket(); this->JceConnector = new qtsslsocket();
try try
{ {
makeConnection(); makeConnection();
} }
catch (jceLogin::jceStatus &a) catch (jceLogin::jceStatus &a)
@ -106,9 +110,10 @@ void jceLogin::reConnect() throw (jceStatus)
void jceLogin::closeAll() void jceLogin::closeAll()
{ {
JceConnector->makeDiconnect();
delete recieverPage; delete recieverPage;
recieverPage = NULL; recieverPage = NULL;
JceConnector = NULL; loginFlag = false;
} }