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 "src/grades/Course.h"
#include "src/grades/GradePage.h"
#include "src/user.h"

View file

@ -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)

View file

@ -3,6 +3,7 @@
#include <QString>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QMessageBox>
#include <QPixmap>
@ -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;

View file

@ -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);

View file

@ -10,9 +10,6 @@
#include <string>
#include <iostream>
#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;

View file

@ -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;
}

View file

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

View file

@ -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;
}