Merge branch 'master' into sagi_dev
This commit is contained in:
commit
b7a91fdbe8
14 changed files with 775 additions and 660 deletions
134
jceGrade.pro
134
jceGrade.pro
|
@ -1,67 +1,67 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-05-31T19:49:42
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network widgets
|
||||
TARGET = jceGrade
|
||||
TEMPLATE = app
|
||||
RC_FILE = appConfigure.rc
|
||||
CONFIG += qt c++11
|
||||
CONFIG += console static
|
||||
|
||||
TRANSLATIONS = jce_en.ts \
|
||||
jce_he.ts
|
||||
|
||||
FORMS += \
|
||||
main/mainscreen.ui \
|
||||
src/jceData/Calendar/calendarDialog.ui
|
||||
|
||||
OTHER_FILES +=
|
||||
|
||||
RESOURCES += \
|
||||
resources/connectionstatus.qrc
|
||||
|
||||
HEADERS += \
|
||||
main/CalendarTab/CalendarManager.h \
|
||||
main/CourseTab/coursestablemanager.h \
|
||||
main/LoginTab/loginhandler.h \
|
||||
main/mainscreen.h \
|
||||
src/appDatabase/savedata.h \
|
||||
src/jceConnection/jcesslclient.h \
|
||||
src/jceData/Calendar/calendarPage.h \
|
||||
src/jceData/Grades/gradeCourse.h \
|
||||
src/jceData/Grades/gradePage.h \
|
||||
src/jceData/course.h \
|
||||
src/jceData/page.h \
|
||||
src/jceSettings/jcelogin.h \
|
||||
src/jceSettings/jceLoginHtmlScripts.h \
|
||||
src/jceSettings/user.h \
|
||||
src/jceData/Calendar/calendarCourse.h \
|
||||
src/jceData/Calendar/calendarSchedule.h \
|
||||
src/jceData/CSV/csv_exporter.h \
|
||||
src/appDatabase/simplecrypt.h \
|
||||
src/jceData/Calendar/calendarDialog.h \
|
||||
src/jce_logger.h
|
||||
|
||||
SOURCES += \
|
||||
main/CalendarTab/CalendarManager.cpp \
|
||||
main/CourseTab/coursestablemanager.cpp \
|
||||
main/LoginTab/loginhandler.cpp \
|
||||
main/main.cpp \
|
||||
main/mainscreen.cpp \
|
||||
src/appDatabase/savedata.cpp \
|
||||
src/jceConnection/jcesslclient.cpp \
|
||||
src/jceData/Calendar/calendarPage.cpp \
|
||||
src/jceData/Grades/gradeCourse.cpp \
|
||||
src/jceData/Grades/gradePage.cpp \
|
||||
src/jceData/page.cpp \
|
||||
src/jceSettings/jcelogin.cpp \
|
||||
src/jceSettings/user.cpp \
|
||||
src/jceData/Calendar/calendarCourse.cpp \
|
||||
src/jceData/Calendar/calendarSchedule.cpp \
|
||||
src/jceData/CSV/csv_exporter.cpp \
|
||||
src/appDatabase/simplecrypt.cpp \
|
||||
src/jceData/Calendar/calendarDialog.cpp \
|
||||
src/jce_logger.cpp
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-05-31T19:49:42
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network widgets
|
||||
TARGET = jceGrade
|
||||
TEMPLATE = app
|
||||
RC_FILE = appConfigure.rc
|
||||
CONFIG += qt c++11
|
||||
CONFIG += console static
|
||||
|
||||
TRANSLATIONS = jce_en.ts \
|
||||
jce_he.ts
|
||||
|
||||
FORMS += \
|
||||
main/mainscreen.ui \
|
||||
src/jceData/Calendar/calendarDialog.ui
|
||||
|
||||
OTHER_FILES +=
|
||||
|
||||
RESOURCES += \
|
||||
resources/connectionstatus.qrc
|
||||
|
||||
HEADERS += \
|
||||
main/CalendarTab/CalendarManager.h \
|
||||
main/CourseTab/coursestablemanager.h \
|
||||
main/LoginTab/loginhandler.h \
|
||||
main/mainscreen.h \
|
||||
src/appDatabase/savedata.h \
|
||||
src/jceConnection/jcesslclient.h \
|
||||
src/jceData/Calendar/calendarPage.h \
|
||||
src/jceData/Grades/gradeCourse.h \
|
||||
src/jceData/Grades/gradePage.h \
|
||||
src/jceData/course.h \
|
||||
src/jceData/page.h \
|
||||
src/jceSettings/jcelogin.h \
|
||||
src/jceSettings/jceLoginHtmlScripts.h \
|
||||
src/jceSettings/user.h \
|
||||
src/jceData/Calendar/calendarCourse.h \
|
||||
src/jceData/Calendar/calendarSchedule.h \
|
||||
src/jceData/CSV/csv_exporter.h \
|
||||
src/appDatabase/simplecrypt.h \
|
||||
src/jceData/Calendar/calendarDialog.h \
|
||||
src/jce_logger.h
|
||||
|
||||
SOURCES += \
|
||||
main/CalendarTab/CalendarManager.cpp \
|
||||
main/CourseTab/coursestablemanager.cpp \
|
||||
main/LoginTab/loginhandler.cpp \
|
||||
main/main.cpp \
|
||||
main/mainscreen.cpp \
|
||||
src/appDatabase/savedata.cpp \
|
||||
src/jceConnection/jcesslclient.cpp \
|
||||
src/jceData/Calendar/calendarPage.cpp \
|
||||
src/jceData/Grades/gradeCourse.cpp \
|
||||
src/jceData/Grades/gradePage.cpp \
|
||||
src/jceData/page.cpp \
|
||||
src/jceSettings/jcelogin.cpp \
|
||||
src/jceSettings/user.cpp \
|
||||
src/jceData/Calendar/calendarCourse.cpp \
|
||||
src/jceData/Calendar/calendarSchedule.cpp \
|
||||
src/jceData/CSV/csv_exporter.cpp \
|
||||
src/appDatabase/simplecrypt.cpp \
|
||||
src/jceData/Calendar/calendarDialog.cpp \
|
||||
src/jce_logger.cpp
|
||||
|
|
|
@ -1,143 +1,181 @@
|
|||
#include "loginhandler.h"
|
||||
|
||||
loginHandler::loginHandler(user *ptr): logggedInFlag(false)
|
||||
loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr): logggedInFlag(false)
|
||||
{
|
||||
this->jceLog = new jceLogin(ptr);
|
||||
this->loginButtonPtr = loginButtonPtr;
|
||||
|
||||
//statusBar
|
||||
statusBar = statusBarPtr;
|
||||
iconButtomStatusLabel = new QLabel();
|
||||
statusBar->addPermanentWidget(iconButtomStatusLabel,0);
|
||||
setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
|
||||
//user settings
|
||||
userPtr = ptr;
|
||||
this->jceLog = new jceLogin(userPtr);
|
||||
QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost()));
|
||||
}
|
||||
void loginHandler::setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
|
||||
bool loginHandler::login(QString username,QString password)
|
||||
{
|
||||
this->statusLabelPtr = statusLabelPtr;
|
||||
this->pswdEditPtr = pswdEditPtr;
|
||||
this->usrnmEditPtr = usrnmEditPtr;
|
||||
qDebug() << Q_FUNC_INFO << "Login with username and password";
|
||||
if (isLoggedInFlag())
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Loging out";
|
||||
logout();
|
||||
return false;
|
||||
}
|
||||
setIconConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
|
||||
|
||||
userPtr->setUsername(username);
|
||||
userPtr->setPassword(password);
|
||||
|
||||
if (makeConnection() == true)
|
||||
{
|
||||
setIconConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
|
||||
loginButtonPtr->setText(QObject::tr("Logout"));
|
||||
return isLoggedInFlag();
|
||||
}
|
||||
else
|
||||
{
|
||||
logout();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void loginHandler::logout()
|
||||
{
|
||||
loginButtonPtr->setText(QObject::tr("Login"));
|
||||
setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
jceLog->closeAll();
|
||||
logggedInFlag = false;
|
||||
}
|
||||
|
||||
bool loginHandler::makeConnection()
|
||||
{
|
||||
if (this->jceLog == NULL)
|
||||
return false;
|
||||
if (this->jceLog == NULL)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
jceLog->makeConnection();
|
||||
}
|
||||
catch (jceLogin::jceStatus &a)
|
||||
{
|
||||
int status = (int)a;
|
||||
int status = (int)jceLog->makeConnection();
|
||||
switch (status)
|
||||
{
|
||||
case jceLogin::JCE_YOU_ARE_IN:
|
||||
{
|
||||
logggedInFlag = true;
|
||||
return logggedInFlag;
|
||||
break;
|
||||
}
|
||||
case jceLogin::ERROR_ON_VALIDATION:
|
||||
{
|
||||
popMessage(QObject::tr("Please Check Your Username & Password"),false);
|
||||
{
|
||||
case jceLogin::JCE_YOU_ARE_IN:
|
||||
{
|
||||
logggedInFlag = true;
|
||||
return logggedInFlag;
|
||||
}
|
||||
case jceLogin::ERROR_ON_VALIDATION:
|
||||
{
|
||||
popMessage(QObject::tr("Please Check Your Username & Password"),false);
|
||||
return false;
|
||||
}
|
||||
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
|
||||
{
|
||||
popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes."));
|
||||
return false;
|
||||
}
|
||||
case jceLogin::ERROR_ON_OPEN_SOCKET:
|
||||
{
|
||||
popMessage(QObject::tr("Please Check Your Internet Connection."));
|
||||
return false;
|
||||
}
|
||||
case jceLogin::JCE_NOT_CONNECTED:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case jceLogin::ERROR_ON_GETTING_INFO:
|
||||
{
|
||||
popMessage(QObject::tr("Receive Request Timeout."));
|
||||
return false;
|
||||
}
|
||||
case jceLogin::ERROR_ON_SEND_REQUEST:
|
||||
{
|
||||
popMessage(QObject::tr("Send Request Timeout."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
usrnmEditPtr->setDisabled(false);
|
||||
pswdEditPtr->setDisabled(false);
|
||||
|
||||
pswdEditPtr->selectAll();
|
||||
pswdEditPtr->setFocus();
|
||||
return false;
|
||||
}
|
||||
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
|
||||
{
|
||||
popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes."));
|
||||
jceLog->closeAll();
|
||||
return false;
|
||||
}
|
||||
case jceLogin::ERROR_ON_OPEN_SOCKET:
|
||||
{
|
||||
popMessage(QObject::tr("Please Check Your Internet Connection."));
|
||||
jceLog->closeAll();
|
||||
return false;
|
||||
}
|
||||
case jceLogin::JCE_NOT_CONNECTED:
|
||||
{
|
||||
jceLog->reConnect();
|
||||
/*
|
||||
* Fix: need to add a prompte window to ask user whether he wants to reconnect or not
|
||||
*/
|
||||
break;
|
||||
}
|
||||
case jceLogin::ERROR_ON_GETTING_INFO:
|
||||
{
|
||||
popMessage(QObject::tr("Receive Request Timeout."));
|
||||
jceLog->closeAll();
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case jceLogin::ERROR_ON_SEND_REQUEST:
|
||||
{
|
||||
popMessage(QObject::tr("Send Request Timeout."));
|
||||
jceLog->closeAll();
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void loginHandler::readyAfterConnectionLost()
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO;
|
||||
setLoginFlag(false);
|
||||
login(userPtr->getUsername(),userPtr->getPassword());
|
||||
|
||||
}
|
||||
bool loginHandler::isLoggedInFlag()
|
||||
{
|
||||
if (jceLog->isLoginFlag()) //checking connection and then if logged in
|
||||
return this->logggedInFlag;
|
||||
else
|
||||
this->setLoginFlag(false);
|
||||
return false;
|
||||
if (jceLog->isLoginFlag()) //checking connection and then if logged in
|
||||
return this->logggedInFlag;
|
||||
else
|
||||
this->setLoginFlag(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
void loginHandler::setLoginFlag(bool flag)
|
||||
{
|
||||
this->logggedInFlag = flag;
|
||||
this->logggedInFlag = flag;
|
||||
}
|
||||
|
||||
QString loginHandler::getCurrentPageContect()
|
||||
{
|
||||
QTextEdit phrase;
|
||||
if (isLoggedInFlag())
|
||||
phrase.setText(jceLog->getPage());
|
||||
else
|
||||
throw jceLogin::ERROR_ON_GETTING_INFO;
|
||||
QTextEdit phrase;
|
||||
if (isLoggedInFlag())
|
||||
phrase.setText(jceLog->getPage());
|
||||
else
|
||||
throw jceLogin::ERROR_ON_GETTING_INFO;
|
||||
|
||||
return phrase.toPlainText();
|
||||
return phrase.toPlainText();
|
||||
}
|
||||
|
||||
void loginHandler::makeDisconnectionRequest()
|
||||
{
|
||||
jceLog->closeAll();
|
||||
this->logggedInFlag = false;
|
||||
}
|
||||
|
||||
int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester)
|
||||
{
|
||||
if (isLoggedInFlag())
|
||||
return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester);
|
||||
else
|
||||
return jceLogin::JCE_NOT_CONNECTED;
|
||||
if (isLoggedInFlag())
|
||||
return jceLog->getGrades(fromYear, toYear, fromSemester, toSemester);
|
||||
else
|
||||
return jceLogin::JCE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
int loginHandler::makeCalendarRequest(int year, int semester)
|
||||
{
|
||||
if (isLoggedInFlag())
|
||||
return jceLog->getCalendar(year,semester);
|
||||
else
|
||||
return jceLogin::JCE_NOT_CONNECTED;
|
||||
if (isLoggedInFlag())
|
||||
return jceLog->getCalendar(year,semester);
|
||||
else
|
||||
return jceLogin::JCE_NOT_CONNECTED;
|
||||
}
|
||||
void loginHandler::setIconConnectionStatus(jceLogin::jceStatus statusDescription)
|
||||
{
|
||||
QPixmap iconPix;
|
||||
switch (statusDescription)
|
||||
{
|
||||
case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS:
|
||||
iconPix.load(":/icons/blueStatusIcon.png");
|
||||
statusBar->showMessage(tr("Connecting..."));
|
||||
break;
|
||||
case jceLogin::jceStatus::JCE_YOU_ARE_IN:
|
||||
iconPix.load(":/icons/greenStatusIcon.png");
|
||||
statusBar->showMessage(tr("Connected"));
|
||||
break;
|
||||
case jceLogin::jceStatus::JCE_NOT_CONNECTED:
|
||||
iconPix.load(":/icons/redStatusIcon.png");
|
||||
statusBar->showMessage(tr("Disconnected"));
|
||||
break;
|
||||
default:
|
||||
iconPix.load(":/icons/redStatusIcon.png");
|
||||
statusBar->showMessage(tr("Ready."));
|
||||
break;
|
||||
}
|
||||
iconButtomStatusLabel->setPixmap(iconPix);
|
||||
|
||||
this->statusBar->repaint();
|
||||
}
|
||||
void loginHandler::popMessage(QString message,bool addInfo)
|
||||
{
|
||||
if (addInfo)
|
||||
message.append(QObject::tr("\nIf this message appear without reason, please contact me at liranbg@gmail.com"));
|
||||
if (addInfo)
|
||||
message.append(QObject::tr("\nIf this message appear without reason, please contact me at liranbg@gmail.com"));
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle(QObject::tr("Error"));
|
||||
msgBox.setText(message);
|
||||
msgBox.exec();
|
||||
msgBox.setFocus();
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle(QObject::tr("Error"));
|
||||
msgBox.setText(message);
|
||||
msgBox.exec();
|
||||
msgBox.setFocus();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,43 +2,55 @@
|
|||
#define LOGINHANDLER_H
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QTextEdit>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
#include <QStatusBar>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "./src/jceSettings/jcelogin.h"
|
||||
#include "./src/appDatabase/savedata.h"
|
||||
|
||||
|
||||
class loginHandler
|
||||
class loginHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
loginHandler(user *ptr);
|
||||
void setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
|
||||
loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr);
|
||||
~loginHandler()
|
||||
{
|
||||
delete iconButtomStatusLabel;
|
||||
delete jceLog;
|
||||
}
|
||||
|
||||
bool login(QString username,QString password);
|
||||
void logout();
|
||||
void setIconConnectionStatus(jceLogin::jceStatus statusDescription);
|
||||
|
||||
bool makeConnection();
|
||||
|
||||
bool isLoggedInFlag();
|
||||
void setLoginFlag(bool flag);
|
||||
|
||||
QString getCurrentPageContect();
|
||||
|
||||
int makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester);
|
||||
int makeCalendarRequest(int year,int semester);
|
||||
|
||||
void makeDisconnectionRequest();
|
||||
private slots:
|
||||
void readyAfterConnectionLost();
|
||||
|
||||
private:
|
||||
|
||||
void popMessage(QString message, bool addInfo = true);
|
||||
|
||||
bool logggedInFlag;
|
||||
jceLogin *jceLog;
|
||||
|
||||
QLabel *statusLabelPtr;
|
||||
QLineEdit *pswdEditPtr;
|
||||
QLineEdit *usrnmEditPtr;
|
||||
jceLogin * jceLog;
|
||||
user * userPtr;
|
||||
|
||||
QStatusBar *statusBar;
|
||||
QLabel *iconButtomStatusLabel;
|
||||
QPushButton *loginButtonPtr;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -8,19 +8,21 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef QT_DEBUG
|
||||
#ifdef QT_DEBUG // Incase QtCreator is in Debug mode all qDebug messages will go to terminal
|
||||
qDebug() << "Running a debug build";
|
||||
#else
|
||||
#else // If QtCreator is on Release mode , qDebug messages will be logged in a log file.
|
||||
qDebug() << "Running a release build";
|
||||
qInstallMessageHandler(jce_logger::customMessageHandler);
|
||||
#endif
|
||||
|
||||
qDebug() << "Start : JCE Manager Launched" << Q_FUNC_INFO;
|
||||
qDebug() << "Start : JCE Manager Launched";
|
||||
|
||||
QApplication a(argc, argv);
|
||||
QTranslator translator;
|
||||
QString loco;
|
||||
SaveData data;
|
||||
loco = data.getLocal();
|
||||
//Loading Local (From Settings file (SaveData.cpp)
|
||||
if(loco == "default")
|
||||
{
|
||||
QString locale = QLocale::system().name();
|
||||
|
@ -33,10 +35,11 @@ int main(int argc, char *argv[])
|
|||
translator.load("jce_en" , a.applicationDirPath());
|
||||
qDebug() << "Local : English Local Loaded";
|
||||
}
|
||||
a.installTranslator(&translator);
|
||||
a.installTranslator(&translator); //Setting local
|
||||
MainScreen w;
|
||||
w.show();
|
||||
|
||||
//Getting the exit code from QApplication. for debug reasons
|
||||
int returnCode = a.exec();
|
||||
if(returnCode == 0)
|
||||
qDebug() << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode;
|
||||
|
|
|
@ -8,7 +8,6 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
|
|||
//this->setFixedSize(this->size()); //main not resizeable
|
||||
|
||||
//Login Tab
|
||||
QPixmap iconPix;
|
||||
iconPix.load(":/icons/iconX.png");
|
||||
ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
|
||||
ui->labelUsrInputStatus->setVisible(false);
|
||||
|
@ -16,16 +15,12 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
|
|||
ui->labelUsrInputStatus->setPixmap(iconPix);
|
||||
ui->labelPswInputStatus->setPixmap(iconPix);
|
||||
|
||||
//Status Bar
|
||||
//StatusBar
|
||||
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
|
||||
ButtomStatusLabel = new QLabel(this);
|
||||
statusLabel = new QLabel(this);
|
||||
ui->statusBar->setMaximumSize(this->geometry().width(),STATUS_ICON_HEIGH);
|
||||
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0);
|
||||
ui->statusBar->addPermanentWidget(statusLabel,1);
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
ui->statusBar->showMessage(tr("Ready"));
|
||||
|
||||
//Course, Setting, Calendar Tab
|
||||
//Course, Calendar Tab
|
||||
calendarSchedule * calendarSchedulePtr = new calendarSchedule();
|
||||
ui->calendarGridLayoutMain->addWidget(calendarSchedulePtr);
|
||||
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
|
||||
|
@ -33,7 +28,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
|
|||
//Pointer allocating
|
||||
this->userLoginSetting = new user("","");
|
||||
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
|
||||
this->loginHandel = new loginHandler(userLoginSetting);
|
||||
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton);
|
||||
this->calendar = new CalendarManager(calendarSchedulePtr);
|
||||
this->data = new SaveData();
|
||||
|
||||
|
@ -45,54 +40,62 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
|
|||
ui->keepLogin->setChecked(true);
|
||||
}
|
||||
|
||||
//Local Check and ui setting.
|
||||
//language
|
||||
checkLocale();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
MainScreen::~MainScreen()
|
||||
{
|
||||
delete ButtomStatusLabel;
|
||||
delete statusLabel;
|
||||
delete calendar;
|
||||
delete courseTableMgr;
|
||||
delete userLoginSetting;
|
||||
delete loginHandel;
|
||||
delete ui;
|
||||
delete data;
|
||||
delete ui;
|
||||
}
|
||||
//EVENTS ON STATUS BAR
|
||||
void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription)
|
||||
{
|
||||
QPixmap iconPix;
|
||||
switch (statusDescription)
|
||||
{
|
||||
case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS:
|
||||
iconPix.load(":/icons/blueStatusIcon.png");
|
||||
statusLabel->setText(tr("Connecting"));
|
||||
break;
|
||||
case jceLogin::jceStatus::JCE_YOU_ARE_IN:
|
||||
iconPix.load(":/icons/greenStatusIcon.png");
|
||||
statusLabel->setText(tr("Connected"));
|
||||
break;
|
||||
default:
|
||||
iconPix.load(":/icons/redStatusIcon.png");
|
||||
statusLabel->setText(tr("Disconnected"));
|
||||
break;
|
||||
}
|
||||
ButtomStatusLabel->setPixmap(iconPix);
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
//EVENTS ON LOGIN TAB
|
||||
void MainScreen::on_loginButton_clicked()
|
||||
{
|
||||
if (loginHandel->isLoggedInFlag())
|
||||
uiSetDisconnectMode();
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
bool isSettingsOk = false;
|
||||
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
|
||||
{
|
||||
if (ui->usrnmLineEdit->text().isEmpty())
|
||||
{
|
||||
ui->labelUsrInputStatus->setVisible(true);
|
||||
qDebug() << Q_FUNC_INFO << "username input is empty";
|
||||
}
|
||||
else
|
||||
ui->labelUsrInputStatus->setVisible(false);
|
||||
if (ui->pswdLineEdit->text().isEmpty())
|
||||
{
|
||||
ui->labelPswInputStatus->setVisible(true);
|
||||
qDebug() << Q_FUNC_INFO << "password input is empty";
|
||||
}
|
||||
else
|
||||
ui->labelPswInputStatus->setVisible(false);
|
||||
return;
|
||||
}
|
||||
else
|
||||
uiSetConnectMode();
|
||||
{
|
||||
isSettingsOk = true;
|
||||
ui->labelUsrInputStatus->setVisible(false);
|
||||
ui->labelPswInputStatus->setVisible(false);
|
||||
}
|
||||
|
||||
if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true)
|
||||
{
|
||||
ui->pswdLineEdit->setDisabled(true);
|
||||
ui->usrnmLineEdit->setDisabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->pswdLineEdit->setDisabled(false);
|
||||
ui->usrnmLineEdit->setDisabled(false);
|
||||
|
||||
}
|
||||
}
|
||||
void MainScreen::on_keepLogin_clicked()
|
||||
{
|
||||
|
@ -108,74 +111,7 @@ void MainScreen::on_usrnmLineEdit_editingFinished()
|
|||
{
|
||||
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
|
||||
}
|
||||
void MainScreen::uiSetDisconnectMode()
|
||||
{
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
|
||||
ui->usrnmLineEdit->setText("");
|
||||
ui->pswdLineEdit->setText("");
|
||||
ui->usrnmLineEdit->setEnabled(true);
|
||||
ui->pswdLineEdit->setEnabled(true);
|
||||
|
||||
loginHandel->makeDisconnectionRequest();
|
||||
ui->loginButton->setText(tr("&Login"));
|
||||
ui->getCalendarBtn->setDisabled(true);
|
||||
ui->exportToCVSBtn->setDisabled(true);
|
||||
ui->ratesButton->setDisabled(true);
|
||||
return;
|
||||
}
|
||||
void MainScreen::uiSetConnectMode()
|
||||
{
|
||||
QString username;
|
||||
QString password;
|
||||
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
|
||||
{
|
||||
if (ui->usrnmLineEdit->text().isEmpty())
|
||||
{
|
||||
ui->labelUsrInputStatus->setVisible(true);
|
||||
qDebug() << "error, username input is empty";
|
||||
}
|
||||
else
|
||||
ui->labelUsrInputStatus->setVisible(false);
|
||||
if (ui->pswdLineEdit->text().isEmpty())
|
||||
{
|
||||
ui->labelPswInputStatus->setVisible(true);
|
||||
qDebug() << "error, password input is empty";
|
||||
}
|
||||
else
|
||||
ui->labelPswInputStatus->setVisible(false);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->labelUsrInputStatus->setVisible(false);
|
||||
ui->labelPswInputStatus->setVisible(false);
|
||||
}
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
|
||||
|
||||
username = ui->usrnmLineEdit->text();
|
||||
password = ui->pswdLineEdit->text();
|
||||
|
||||
ui->usrnmLineEdit->setDisabled(true);
|
||||
ui->pswdLineEdit->setDisabled(true);
|
||||
|
||||
userLoginSetting->setUsername(username);
|
||||
userLoginSetting->setPassword(password);
|
||||
|
||||
this->loginHandel->setPointers(statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
|
||||
if (loginHandel->makeConnection() == true)
|
||||
{
|
||||
setLabelConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
|
||||
ui->loginButton->setText(tr("&Logout"));
|
||||
ui->ratesButton->setEnabled(true);
|
||||
ui->CoursesTab->setEnabled(true);
|
||||
ui->exportToCVSBtn->setEnabled(true);
|
||||
ui->getCalendarBtn->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
uiSetDisconnectMode();
|
||||
}
|
||||
}
|
||||
//EVENTS ON GPA TAB
|
||||
void MainScreen::on_ratesButton_clicked()
|
||||
{
|
||||
|
@ -189,7 +125,9 @@ void MainScreen::on_ratesButton_clicked()
|
|||
int status = 0;
|
||||
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();
|
||||
courseTableMgr->setCoursesList(pageString);
|
||||
|
@ -226,7 +164,6 @@ void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1)
|
|||
{
|
||||
ui->spinBoxCoursesFromYear->setValue(arg1);
|
||||
}
|
||||
|
||||
void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1)
|
||||
{
|
||||
ui->spinBoxCoursesToYear->setValue(arg1);
|
||||
|
@ -280,7 +217,6 @@ void MainScreen::on_exportToCVSBtn_clicked()
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
//EVENTS ON MENU BAR
|
||||
void MainScreen::on_actionCredits_triggered()
|
||||
{
|
||||
|
@ -309,14 +245,8 @@ void MainScreen::on_actionHow_To_triggered()
|
|||
"<br><li>"+tr("HELP3")+"</li>"
|
||||
"<br><li>"+tr("HELP4")+"</li>"
|
||||
"<br><li>"+tr("HELP5")+"</li>"
|
||||
"<br><br>"+tr("HELP6")+
|
||||
"</ul>");
|
||||
|
||||
"</ul>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MainScreen::on_actionHebrew_triggered()
|
||||
{
|
||||
if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked())
|
||||
|
@ -330,7 +260,6 @@ void MainScreen::on_actionHebrew_triggered()
|
|||
else
|
||||
ui->actionHebrew->setChecked(true);
|
||||
}
|
||||
|
||||
void MainScreen::on_actionEnglish_triggered()
|
||||
{
|
||||
if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked())
|
||||
|
@ -344,8 +273,6 @@ void MainScreen::on_actionEnglish_triggered()
|
|||
else
|
||||
ui->actionEnglish->setChecked(true);
|
||||
}
|
||||
|
||||
|
||||
void MainScreen::on_actionOS_Default_triggered()
|
||||
{
|
||||
if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked())
|
||||
|
|
|
@ -70,25 +70,20 @@ private slots:
|
|||
|
||||
private:
|
||||
|
||||
void uiSetDisconnectMode();
|
||||
void uiSetConnectMode();
|
||||
void setLabelConnectionStatus(jceLogin::jceStatus statusDescription);
|
||||
void checkLocale();
|
||||
|
||||
bool checkIfValidDates();
|
||||
|
||||
Ui::MainScreen *ui;
|
||||
|
||||
QLabel *ButtomStatusLabel;
|
||||
QLabel *statusLabel;
|
||||
|
||||
QPixmap iconPix;
|
||||
user *userLoginSetting;
|
||||
SaveData *data;
|
||||
|
||||
CalendarManager * calendar;
|
||||
coursesTableManager *courseTableMgr;
|
||||
loginHandler *loginHandel;
|
||||
|
||||
bool calendarLoaded;
|
||||
loginHandler *loginHandel;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -345,7 +345,7 @@ font-size: 15px;
|
|||
<item>
|
||||
<widget class="QPushButton" name="ratesButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p><span style=" font-weight:600;">Get your grades</span></p></body></html></string>
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
#include "jcesslclient.h"
|
||||
|
||||
/**
|
||||
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
|
||||
*/
|
||||
jceSSLClient::jceSSLClient() : flag(false), packet("")
|
||||
jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf(), reConnection(false)
|
||||
{
|
||||
//setting signals
|
||||
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
|
||||
connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
|
||||
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
|
||||
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
|
||||
connect(&networkConf,SIGNAL(onlineStateChanged(bool)),this,SLOT(setOnlineState(bool)));
|
||||
|
||||
//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()));
|
||||
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
|
||||
connect(this, SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief jceSSLClient::makeConnect connecting to server with given port. using eventloop to assure it wont stuck the application.
|
||||
* @param server - server to connect to
|
||||
|
@ -24,24 +25,33 @@ jceSSLClient::jceSSLClient() : flag(false), packet("")
|
|||
*/
|
||||
bool jceSSLClient::makeConnect(QString server, int port)
|
||||
{
|
||||
qDebug() << "jceSSLClient::makeConnect; Making connection";
|
||||
if (this->networkConf.isOnline() == false)
|
||||
return false;
|
||||
|
||||
if (reConnection) //reset reconnectiong flag
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Making Reconnection";
|
||||
}
|
||||
else
|
||||
qDebug() << Q_FUNC_INFO << "Making Connection";
|
||||
|
||||
if (isConnected())
|
||||
{
|
||||
qWarning() << "jceSSLClient::makeConnect; Was already connected. Aborting.";
|
||||
makeDiconnect();
|
||||
}
|
||||
if (isOpen())
|
||||
{
|
||||
qWarning() << "jceSSLClient::makeConnect; IsO pen. Aborting.";
|
||||
qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()";
|
||||
makeDiconnect();
|
||||
}
|
||||
|
||||
qDebug() << "jceSSLClient::makeConnect; Connection to: " << server << "On Port: " << port;
|
||||
qDebug() << Q_FUNC_INFO << "Connection to: " << server << "On Port: " << port;
|
||||
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();
|
||||
qDebug() << Q_FUNC_INFO << "returning the connection status: " << isConnected();
|
||||
if (reConnection)
|
||||
{
|
||||
reConnection = false;
|
||||
emit serverDisconnectedbyRemote();
|
||||
}
|
||||
return isConnected();
|
||||
|
||||
}
|
||||
|
@ -51,37 +61,16 @@ bool jceSSLClient::makeConnect(QString server, int port)
|
|||
*/
|
||||
bool jceSSLClient::makeDiconnect()
|
||||
{
|
||||
qDebug() << "jceSSLClient::makeDiconnect;";
|
||||
if (loop.isRunning())
|
||||
{
|
||||
qWarning() << "jceSSLClient::makeDiconnect; Killing connection thread";
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "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;
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "jceSSLClient::makeDiconnect; Disconnecting [else] ";
|
||||
abort(); //ensure the disconnection
|
||||
flag = false;
|
||||
}
|
||||
qDebug() << "jceSSLClient::makeDiconnect; disconnect return with " << flag;
|
||||
return flag;
|
||||
qDebug() << Q_FUNC_INFO << "disconnecting from host and emitting disconnected()";
|
||||
this->disconnectFromHost(); //emits disconnected > setDisconnected
|
||||
setSocketState(QAbstractSocket::SocketState::UnconnectedState);
|
||||
return (!isConnected());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,20 +79,30 @@ bool jceSSLClient::makeDiconnect()
|
|||
*/
|
||||
bool jceSSLClient::isConnected()
|
||||
{
|
||||
bool tempFlag;
|
||||
//checking state before returning flag!
|
||||
if (state() == QAbstractSocket::SocketState::UnconnectedState)
|
||||
{
|
||||
flag = false;
|
||||
tempFlag = false;
|
||||
}
|
||||
else if (state() == QAbstractSocket::SocketState::ClosingState)
|
||||
{
|
||||
flag = false;
|
||||
tempFlag = false;
|
||||
}
|
||||
else if (state() == QAbstractSocket::SocketState::ConnectedState)
|
||||
{
|
||||
flag = true;
|
||||
if (this->networkConf.isOnline())
|
||||
tempFlag = true;
|
||||
else
|
||||
{
|
||||
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
|
||||
tempFlag = false;
|
||||
}
|
||||
|
||||
}
|
||||
return flag;
|
||||
if (!this->networkConf.isOnline()) //no link, ethernet\wifi
|
||||
tempFlag = false;
|
||||
return ((flag) && (tempFlag));
|
||||
}
|
||||
/**
|
||||
* @brief jceSSLClient::sendData - given string, send it to server
|
||||
|
@ -119,7 +118,7 @@ bool jceSSLClient::sendData(QString str)
|
|||
if (waitForBytesWritten())
|
||||
sendDataFlag = true;
|
||||
}
|
||||
qDebug() << "jceSSLClient::sendData; Sending Data status is: " << sendDataFlag;
|
||||
qDebug() << Q_FUNC_INFO << "Sending Data status is: " << sendDataFlag;
|
||||
return sendDataFlag;
|
||||
}
|
||||
/**
|
||||
|
@ -130,7 +129,7 @@ bool jceSSLClient::sendData(QString str)
|
|||
*/
|
||||
bool jceSSLClient::recieveData(QString &str, bool fast)
|
||||
{
|
||||
qDebug() << "jceSSLClient::recieveData Data receiving!";
|
||||
qDebug() << Q_FUNC_INFO << "Data receiving!";
|
||||
packet = "";
|
||||
bool sflag = false;
|
||||
|
||||
|
@ -158,10 +157,10 @@ bool jceSSLClient::recieveData(QString &str, bool fast)
|
|||
}
|
||||
}
|
||||
str = packet;
|
||||
qDebug() << "jceSSLClient::recieveData received bytes: " << str.length() ;
|
||||
qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ;
|
||||
if (str.length() > 0)
|
||||
sflag = true;
|
||||
qDebug() << "jceSSLClient::recieveData return with flag: " << sflag;
|
||||
qDebug() << Q_FUNC_INFO << "return with flag: " << sflag;
|
||||
return sflag;
|
||||
|
||||
}
|
||||
|
@ -177,6 +176,24 @@ void jceSSLClient::readIt()
|
|||
packet.append(p);
|
||||
}while (p.size() > 0);
|
||||
|
||||
}
|
||||
|
||||
void jceSSLClient::setOnlineState(bool isOnline)
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "isOnline status change: " << isOnline;
|
||||
if (isOnline) //to be added later
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Online Statue has been changed. we are online";
|
||||
//we can add here auto reconnect if wifi\ethernet link has appear
|
||||
//will be added next version
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "Online State has been changed. emitting NoInternetLink";
|
||||
this->makeDiconnect();
|
||||
emit noInternetLink();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief jceSSLClient::setConnected called when signaled with connected, calling the encryption function
|
||||
|
@ -186,26 +203,34 @@ void jceSSLClient::setConnected()
|
|||
waitForEncrypted();
|
||||
}
|
||||
/**
|
||||
* @brief jceSSLClient::setDisconnected called when signaled with disconnected, setting flag to false
|
||||
* @brief jceSSLClient::setDisconnected closing socket, updating state and setting flag to false
|
||||
*/
|
||||
void jceSSLClient::setDisconnected()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "connection has been DISCONNECTED";
|
||||
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
|
||||
packet.clear();
|
||||
flag = false;
|
||||
if (reConnection)
|
||||
makeConnect();
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief jceSSLClient::setEncrypted called when signaled with encrypted. setting the buffer size and keeping alive.
|
||||
*/
|
||||
void jceSSLClient::setEncrypted()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "connection has been ENCRYPTED";
|
||||
setReadBufferSize(10000);
|
||||
setSocketOption(QAbstractSocket::KeepAliveOption,1);
|
||||
if (state() == QAbstractSocket::SocketState::ConnectedState)
|
||||
flag = true;
|
||||
else
|
||||
setSocketOption(QAbstractSocket::KeepAliveOption,true);
|
||||
flag = true;
|
||||
if (!isConnected())
|
||||
{
|
||||
qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!";
|
||||
qWarning() << Q_FUNC_INFO << "Connection status didnt change! reseting flag to false";
|
||||
flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief jceSSLClient::showIfErrorMsg message box to show the error occured according to socket
|
||||
|
@ -220,94 +245,111 @@ void jceSSLClient::showIfErrorMsg()
|
|||
bool relevantError = false;
|
||||
switch (enumError)
|
||||
{
|
||||
case QAbstractSocket::SocketError::ConnectionRefusedError:
|
||||
case QAbstractSocket::SocketError::ConnectionRefusedError: /**/
|
||||
errorString = QObject::tr("ConnectionRefusedError");
|
||||
//The connection was refused by the peer (or timed out).
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::RemoteHostClosedError:
|
||||
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())
|
||||
//The remote host closed the connection
|
||||
if (networkConf.isOnline()) //we can reconnect
|
||||
{
|
||||
reConnection = true;
|
||||
}
|
||||
else
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::DatagramTooLargeError:
|
||||
errorString = QObject::tr("DatagramTooLargeError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::NetworkError:
|
||||
errorString = QObject::tr("NetworkError");
|
||||
case QAbstractSocket::SocketError::HostNotFoundError: /**/
|
||||
errorString = QObject::tr("HostNotFoundError");
|
||||
//The host address was not found.
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::AddressInUseError:
|
||||
errorString = QObject::tr("AddressInUseError");
|
||||
case QAbstractSocket::SocketError::SocketAccessError: /**/
|
||||
errorString = QObject::tr("SocketAccessError");
|
||||
//The socket operation failed because the application lacked the required privileges.
|
||||
break;
|
||||
case QAbstractSocket::SocketError::SocketAddressNotAvailableError:
|
||||
errorString = QObject::tr("SocketAddressNotAvailableError");
|
||||
case QAbstractSocket::SocketError::SocketTimeoutError: /**/
|
||||
errorString = QObject::tr("SocketTimeoutError");
|
||||
//The socket operation timed out.
|
||||
if (isConnected()); //ignore it if connected.
|
||||
else
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::UnsupportedSocketOperationError:
|
||||
errorString = QObject::tr("UnsupportedSocketOperationError");
|
||||
case QAbstractSocket::SocketError::NetworkError: /**/
|
||||
errorString = QObject::tr("NetworkError");
|
||||
//An error occurred with the network (e.g., the network cable was accidentally plugged out).
|
||||
if (networkConf.isOnline()) //we can reconnect
|
||||
{
|
||||
}
|
||||
else
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError:
|
||||
errorString = QObject::tr("ProxyAuthenticationRequiredError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::SslHandshakeFailedError:
|
||||
case QAbstractSocket::SocketError::SslHandshakeFailedError: /**/
|
||||
errorString = QObject::tr("SslHandshakeFailedError");
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyConnectionRefusedError:
|
||||
errorString = QObject::tr("ProxyConnectionRefusedError");
|
||||
case QAbstractSocket::SocketError::SslInternalError: /**/
|
||||
errorString = QObject::tr("SslInternalError");
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::UnfinishedSocketOperationError:
|
||||
errorString = QObject::tr("UnfinishedSocketOperationError");
|
||||
case QAbstractSocket::SocketError::SslInvalidUserDataError: /**/
|
||||
errorString = QObject::tr("SslInvalidUserDataError");
|
||||
relevantError = true;
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyConnectionClosedError:
|
||||
errorString = QObject::tr("ProxyConnectionClosedError");
|
||||
case QAbstractSocket::SocketError::DatagramTooLargeError: //not relevant to us
|
||||
errorString = QObject::tr("DatagramTooLargeError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyConnectionTimeoutError:
|
||||
errorString = QObject::tr("ProxyConnectionTimeoutError");
|
||||
case QAbstractSocket::SocketError::SocketResourceError: //not relevant to us
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyNotFoundError:
|
||||
errorString = QObject::tr("ProxyNotFoundError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyProtocolError:
|
||||
errorString = QObject::tr("ProxyProtocolError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::OperationError:
|
||||
case QAbstractSocket::SocketError::OperationError: //not relevant, except for debug
|
||||
errorString = QObject::tr("OperationError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::SslInternalError:
|
||||
errorString = QObject::tr("SslInternalError");
|
||||
case QAbstractSocket::SocketError::AddressInUseError: //not relevant to us
|
||||
errorString = QObject::tr("AddressInUseError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::SslInvalidUserDataError:
|
||||
errorString = QObject::tr("SslInvalidUserDataError");
|
||||
case QAbstractSocket::SocketError::SocketAddressNotAvailableError: //not relevant to us
|
||||
errorString = QObject::tr("SocketAddressNotAvailableError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::TemporaryError:
|
||||
case QAbstractSocket::SocketError::UnsupportedSocketOperationError: //for very old computers, not relevant to us
|
||||
errorString = QObject::tr("UnsupportedSocketOperationError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError: //not relevant to us
|
||||
errorString = QObject::tr("ProxyAuthenticationRequiredError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyConnectionRefusedError: //not relevant to us
|
||||
errorString = QObject::tr("ProxyConnectionRefusedError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::UnfinishedSocketOperationError: //not relevant to us
|
||||
errorString = QObject::tr("UnfinishedSocketOperationError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyConnectionClosedError: //not relevant to us
|
||||
errorString = QObject::tr("ProxyConnectionClosedError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyConnectionTimeoutError: //not relevant to us
|
||||
errorString = QObject::tr("ProxyConnectionTimeoutError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyNotFoundError: //not relevant to us
|
||||
errorString = QObject::tr("ProxyNotFoundError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::ProxyProtocolError: //not relevant to us
|
||||
errorString = QObject::tr("ProxyProtocolError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::TemporaryError: //not relevant to us
|
||||
errorString = QObject::tr("TemporaryError");
|
||||
break;
|
||||
case QAbstractSocket::SocketError::UnknownSocketError:
|
||||
case QAbstractSocket::SocketError::UnknownSocketError: //not relevant, except for debug
|
||||
errorString = QObject::tr("UnknownSocketError");
|
||||
relevantError = true;
|
||||
break;
|
||||
}
|
||||
if (relevantError) //informative string to be shown
|
||||
{
|
||||
qDebug() << "jceSSLClient::showIfErrorMsg(); relevant error. msgbox popped";
|
||||
qDebug() << Q_FUNC_INFO << "relevant error.";
|
||||
msgBox.setIcon(QMessageBox::Warning);
|
||||
msgBox.setText(errorString);
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief jceSSLClient::checkErrors this function exctuing when socket error has occured
|
||||
|
@ -315,8 +357,14 @@ void jceSSLClient::showIfErrorMsg()
|
|||
*/
|
||||
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
|
||||
{
|
||||
qWarning() << "jceSSLClient::checkErrors; Var Error: " << a;
|
||||
qWarning() << "jceSSLClient::checkErrors; Error: " << this->errorString();
|
||||
//ignore this stupid error
|
||||
if (!((isConnected()) && (a == QAbstractSocket::SocketError::SocketTimeoutError)))
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "isOnline?: " << this->networkConf.isOnline();
|
||||
qWarning() << Q_FUNC_INFO << "state is: " << state();
|
||||
qWarning() << Q_FUNC_INFO << "Var Error: " << a;
|
||||
qWarning() << Q_FUNC_INFO << "Error: " << errorString();
|
||||
}
|
||||
showIfErrorMsg();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,36 +6,42 @@
|
|||
#include <QThread>
|
||||
#include <QEventLoop>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#define milisTimeOut 3500
|
||||
#define milisTimeOut 4000
|
||||
|
||||
class jceSSLClient : QSslSocket
|
||||
class jceSSLClient : public QSslSocket
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
jceSSLClient();
|
||||
|
||||
bool makeConnect(QString server, int port);
|
||||
bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443);
|
||||
bool makeDiconnect();
|
||||
bool isConnected();
|
||||
bool sendData(QString str);
|
||||
bool recieveData(QString &str, bool fast);
|
||||
bool makeDiconnect();
|
||||
void showIfErrorMsg();
|
||||
|
||||
signals:
|
||||
void serverDisconnectedbyRemote();
|
||||
void noInternetLink();
|
||||
void socketDisconnected();
|
||||
|
||||
private slots:
|
||||
void checkErrors(QAbstractSocket::SocketError a);
|
||||
void setConnected();
|
||||
void setEncrypted();
|
||||
void setDisconnected();
|
||||
void readIt();
|
||||
void setOnlineState(bool isOnline);
|
||||
|
||||
private:
|
||||
|
||||
bool flag;
|
||||
QString packet;
|
||||
QEventLoop loop; //handle the connection as thread
|
||||
QNetworkConfigurationManager networkConf; //checking if online
|
||||
bool reConnection; //used for remote host disconnecting
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,25 @@
|
|||
#include "csv_exporter.h"
|
||||
|
||||
/*
|
||||
*
|
||||
* Class doc can be bound in csv_exporter.h
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
CSV_Exporter::CSV_Exporter()
|
||||
{
|
||||
|
||||
/* EMPTY - NO NEED */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This method will generate the CSV file (Targeting google calendar import)
|
||||
* it will create a full Semester calendar based on the users input (@param cal)
|
||||
* and the @calSched wich holdes all the courses in "this" semester.
|
||||
* @param calSched - Holdes all the Courses and there info
|
||||
* @param cal - The Calendar dialog witch holdes the starting date and the eand date.
|
||||
* @return - True if *all* went well, false if something on the way went wrong.
|
||||
*/
|
||||
bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal)
|
||||
{
|
||||
if ((cal == NULL) || (calSched == NULL)) //pointers checking!
|
||||
|
@ -16,7 +31,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
|
|||
qDebug() << "Getting path for csv file from user...";
|
||||
|
||||
QString filePath = getFileFath();
|
||||
if (filePath == NULL) //User canceled
|
||||
if(filePath == NULL) //User canceled from the file explorer popup
|
||||
{
|
||||
qDebug() << "CSV : User pressed Cancel... returning false";
|
||||
return false;
|
||||
|
@ -25,7 +40,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
|
|||
qDebug() << "CSV : Atempting to export the Schedule...";
|
||||
|
||||
QFile file(filePath);
|
||||
if(!file.open(QIODevice::ReadWrite | QIODevice::Truncate))
|
||||
if(!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) //Incase unable to open the file (binary mode - \n will not be converted on "Windows")
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
|
@ -33,13 +48,16 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
|
|||
msgBox.exec();
|
||||
qCritical() << "unable to open/create the file... maybe permissions error.";
|
||||
return false;
|
||||
}//else
|
||||
//Delete the file
|
||||
QTextStream out(&file);
|
||||
out << CSV_CALENDAR_HEADER << "\n";
|
||||
for (calendarCourse *coursePtr: *(calSched->getCourses()))
|
||||
}
|
||||
|
||||
QTextStream out(&file); //The output streem.
|
||||
out.setCodec("UTF-8"); //Unicode 8
|
||||
|
||||
out << CSV_CALENDAR_HEADER << "\n"; // macro in header file
|
||||
|
||||
for (calendarCourse *coursePtr: *(calSched->getCourses())) //main loop - running though all courses
|
||||
{
|
||||
// Subject,Start Date,Start Time,End Date,End Time,Description,Location
|
||||
// Getting course info - store in vars for easy access
|
||||
int day = coursePtr->getDay();
|
||||
int startH = coursePtr->getHourBegin();
|
||||
int startM = coursePtr->getMinutesBegin();
|
||||
|
@ -50,11 +68,15 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
|
|||
QString name = coursePtr->getName();
|
||||
QString room = coursePtr->getRoom();
|
||||
|
||||
QDate currentDate = cal->getStartDate();
|
||||
QDate currentDate = cal->getStartDate(); // currentDate will iterate throuh the semester
|
||||
|
||||
currentDate = currentDate.addDays(day-1);
|
||||
currentDate = currentDate.addDays(day-1); //selecting the REAL starting day of that course
|
||||
|
||||
for (;currentDate <= cal->getEndDate(); currentDate = currentDate.addDays(7))
|
||||
/*
|
||||
* secondary loop - We have course info and starting day.
|
||||
* evrey loop enterence we add the course and moving one week forward.
|
||||
*/
|
||||
for(;currentDate <= cal->getEndDate(); currentDate = currentDate.addDays(7))
|
||||
{
|
||||
QString line = makeLine(name, ¤tDate, startH, startM, endH, endM, lecturer, room, type);
|
||||
if(line != NULL)
|
||||
|
@ -72,6 +94,10 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the file path according to user via a file explorer dialog
|
||||
* @return - QString: the file path.
|
||||
*/
|
||||
QString CSV_Exporter::getFileFath()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName();
|
||||
|
@ -82,6 +108,20 @@ QString CSV_Exporter::getFileFath()
|
|||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returning a CSV formated ling in QString.
|
||||
* @param name
|
||||
* @param date
|
||||
* @param startH
|
||||
* @param startM
|
||||
* @param endH
|
||||
* @param endM
|
||||
* @param lecturer
|
||||
* @param room
|
||||
* @param type
|
||||
* @return a CSV formated ling in QString.
|
||||
*/
|
||||
QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM, int endH, int endM, QString lecturer, QString room, QString type)
|
||||
{
|
||||
//Creating a CSV text line for Google Calendar/iCal/Outlook
|
||||
|
@ -114,7 +154,7 @@ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM
|
|||
description.append("\n");
|
||||
description.append(" ב");
|
||||
description.append(room);
|
||||
description.append("\"");
|
||||
description.append("\n Created with JCE Manager.\"");
|
||||
|
||||
//Create the Fucking Line
|
||||
//Header: Subject,Start Date,Start Time,End Date,End Time,Description,Location
|
||||
|
|
|
@ -4,90 +4,97 @@
|
|||
* @brief jceLogin::jceLogin
|
||||
* @param username pointer to allocated user settings
|
||||
*/
|
||||
jceLogin::jceLogin(user * username)
|
||||
jceLogin::jceLogin(user* username)
|
||||
{
|
||||
this->recieverPage = new QString();
|
||||
this->jceA = username;
|
||||
this->JceConnector = new jceSSLClient();
|
||||
this->recieverPage = new QString();
|
||||
this->jceA = username;
|
||||
this->JceConnector = new jceSSLClient();
|
||||
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
|
||||
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
|
||||
}
|
||||
|
||||
jceLogin::~jceLogin()
|
||||
{
|
||||
this->jceA = NULL;
|
||||
delete recieverPage;
|
||||
delete JceConnector;
|
||||
JceConnector = NULL;
|
||||
recieverPage = NULL;
|
||||
this->jceA = NULL;
|
||||
delete recieverPage;
|
||||
delete JceConnector;
|
||||
JceConnector = NULL;
|
||||
recieverPage = NULL;
|
||||
}
|
||||
/**
|
||||
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it.
|
||||
* throws error upon the given error from JCE website or Socket error
|
||||
*/
|
||||
void jceLogin::makeConnection() throw (jceStatus)
|
||||
int jceLogin::makeConnection()
|
||||
{
|
||||
qDebug() << "jceLogin::makeConnection(); connection to be make";
|
||||
qDebug() << "jceLogin::makeConnection(); connection to be make";
|
||||
|
||||
if (this->recieverPage == NULL)
|
||||
this->recieverPage = new QString();
|
||||
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;
|
||||
int returnMode; //gets status according to called function of validation step
|
||||
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
|
||||
|
||||
int returnMode; //gets status according to called function of validation step
|
||||
jceStatus status = jceStatus::JCE_NOT_CONNECTED;
|
||||
returnMode = checkConnection(); //checking socket status. is connected?
|
||||
|
||||
returnMode = checkConnection(); //checking socket status. is connected?
|
||||
|
||||
if (returnMode == true) //connected to host
|
||||
if (returnMode == false)
|
||||
{
|
||||
returnMode = makeFirstVisit();
|
||||
if (returnMode == true) //requst and send first validation
|
||||
if (JceConnector->makeConnect(dst_host,dst_port) == false) //couldnt make a connection
|
||||
return jceStatus::ERROR_ON_OPEN_SOCKET;
|
||||
else
|
||||
returnMode = true;
|
||||
}
|
||||
|
||||
if (returnMode == true) //connected to host
|
||||
{
|
||||
returnMode = makeFirstVisit();
|
||||
if (returnMode == true) //requst and send first validation
|
||||
{
|
||||
status = jceStatus::JCE_START_VALIDATING_PROGRESS;
|
||||
returnMode = checkValidation();
|
||||
if (returnMode == true) //check if username and password are matching
|
||||
status = jceStatus::JCE_START_VALIDATING_PROGRESS;
|
||||
returnMode = checkValidation();
|
||||
if (returnMode == true) //check if username and password are matching
|
||||
{
|
||||
status = jceStatus::JCE_VALIDATION_PASSED;
|
||||
returnMode = makeSecondVisit();
|
||||
if (returnMode == true) //siging in the website
|
||||
status = jceStatus::JCE_VALIDATION_PASSED;
|
||||
returnMode = makeSecondVisit();
|
||||
if (returnMode == true) //siging in the website
|
||||
{
|
||||
qDebug() << "jceLogin::makeConnection(); Signed in succeesfully";
|
||||
status = jceStatus::JCE_YOU_ARE_IN;
|
||||
setLoginFlag(true);
|
||||
qDebug() << "jceLogin::makeConnection(); Signed in succeesfully";
|
||||
status = jceStatus::JCE_YOU_ARE_IN;
|
||||
setLoginFlag(true);
|
||||
}
|
||||
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
||||
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
||||
{
|
||||
status = jceLogin::ERROR_ON_GETTING_INFO;
|
||||
status = jceLogin::ERROR_ON_GETTING_INFO;
|
||||
}
|
||||
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
||||
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
||||
{
|
||||
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION;
|
||||
|
||||
}
|
||||
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
||||
else if (returnMode == jceLogin::ERROR_ON_GETTING_INFO)
|
||||
{
|
||||
status = jceLogin::ERROR_ON_GETTING_INFO;
|
||||
status = jceLogin::ERROR_ON_GETTING_INFO;
|
||||
}
|
||||
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
||||
else if (returnMode == jceLogin::ERROR_ON_SEND_REQUEST)
|
||||
{
|
||||
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
status = jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
}
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
||||
else
|
||||
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
|
||||
|
||||
}
|
||||
else
|
||||
status = jceStatus::JCE_NOT_CONNECTED;
|
||||
else
|
||||
status = jceStatus::JCE_NOT_CONNECTED;
|
||||
|
||||
//we throw status even if we are IN!
|
||||
qDebug() << "jceLogin::makeConnection(); throw status: " << status;
|
||||
throw status;
|
||||
//we throw status even if we are IN!
|
||||
qDebug() << "jceLogin::makeConnection(); return status: " << status;
|
||||
return status;
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -96,41 +103,40 @@ void jceLogin::makeConnection() throw (jceStatus)
|
|||
*/
|
||||
bool jceLogin::checkConnection() const
|
||||
{
|
||||
if (JceConnector->isConnected())
|
||||
return true;
|
||||
if (JceConnector->isConnected())
|
||||
return true;
|
||||
|
||||
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)
|
||||
{
|
||||
closeAll();
|
||||
if (this->JceConnector != NULL)
|
||||
delete JceConnector;
|
||||
this->recieverPage = new QString();
|
||||
this->JceConnector = new jceSSLClient();
|
||||
|
||||
try
|
||||
{
|
||||
makeConnection();
|
||||
}
|
||||
catch (jceLogin::jceStatus &a)
|
||||
{
|
||||
throw a;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @brief jceLogin::closeAll
|
||||
*/
|
||||
void jceLogin::closeAll()
|
||||
{
|
||||
JceConnector->makeDiconnect();
|
||||
delete recieverPage;
|
||||
recieverPage = NULL;
|
||||
this->JceConnector->makeDiconnect();
|
||||
if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty()))
|
||||
{
|
||||
delete recieverPage;
|
||||
recieverPage = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief jceLogin::reMakeConnection
|
||||
*/
|
||||
void jceLogin::reMakeConnection()
|
||||
{
|
||||
if (this->JceConnector != NULL)
|
||||
delete JceConnector;
|
||||
if (this->recieverPage != NULL)
|
||||
delete recieverPage;
|
||||
recieverPage = NULL;
|
||||
JceConnector = NULL;
|
||||
this->recieverPage = new QString();
|
||||
this->JceConnector = new jceSSLClient();
|
||||
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
|
||||
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
|
||||
emit connectionReadyAfterDisconnection();
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -139,17 +145,17 @@ void jceLogin::closeAll()
|
|||
*/
|
||||
int jceLogin::makeFirstVisit()
|
||||
{
|
||||
QString usr = jceA->getUsername();
|
||||
QString psw = jceA->getPassword();
|
||||
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
|
||||
QString usr = jceA->getUsername();
|
||||
QString psw = jceA->getPassword();
|
||||
if (JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
|
||||
{
|
||||
if (!JceConnector->recieveData(*recieverPage,true))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
if (!JceConnector->recieveData(*recieverPage,true))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief jceLogin::makeSecondVisit making the second validation step of jce student portal login
|
||||
|
@ -157,19 +163,19 @@ int jceLogin::makeFirstVisit()
|
|||
*/
|
||||
int jceLogin::makeSecondVisit()
|
||||
{
|
||||
QString usrid=jceA->getUserID();
|
||||
QString pswid=jceA->getHashedPassword();
|
||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
|
||||
QString usrid=jceA->getUserID();
|
||||
QString pswid=jceA->getHashedPassword();
|
||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
|
||||
{
|
||||
if (!(JceConnector->recieveData(*recieverPage,true)))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
if (!(JceConnector->recieveData(*recieverPage,true)))
|
||||
return jceLogin::ERROR_ON_GETTING_INFO;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief jceLogin::getCalendar according to parameters, we make an HTML request and send it over socket to server
|
||||
|
@ -179,17 +185,17 @@ int jceLogin::makeSecondVisit()
|
|||
*/
|
||||
int jceLogin::getCalendar(int year, int semester)
|
||||
{
|
||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
|
||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getCalendar(*jceA,year,semester)))))
|
||||
{
|
||||
if (!(JceConnector->recieveData(*recieverPage,false)))
|
||||
return jceLogin::ERROR_ON_GETTING_GRADES;
|
||||
else
|
||||
return jceLogin::JCE_GRADE_PAGE_PASSED;
|
||||
if (!(JceConnector->recieveData(*recieverPage,false)))
|
||||
return jceLogin::ERROR_ON_GETTING_GRADES;
|
||||
else
|
||||
return jceLogin::JCE_GRADE_PAGE_PASSED;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -202,18 +208,17 @@ int jceLogin::getCalendar(int year, int semester)
|
|||
*/
|
||||
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
|
||||
{
|
||||
std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
|
||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
|
||||
if ((JceConnector->sendData(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA,fromYear, toYear, fromSemester, toSemester)))))
|
||||
{
|
||||
if (!(JceConnector->recieveData(*recieverPage,false)))
|
||||
return jceLogin::ERROR_ON_GETTING_GRADES;
|
||||
else
|
||||
return jceLogin::JCE_GRADE_PAGE_PASSED;
|
||||
if (!(JceConnector->recieveData(*recieverPage,false)))
|
||||
return jceLogin::ERROR_ON_GETTING_GRADES;
|
||||
else
|
||||
return jceLogin::JCE_GRADE_PAGE_PASSED;
|
||||
}
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
else
|
||||
return jceLogin::ERROR_ON_SEND_REQUEST;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -223,43 +228,43 @@ int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemest
|
|||
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;
|
||||
//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;
|
||||
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);
|
||||
//setting user information with given data hassid and hasspass
|
||||
jceA->setHashedPassword(hasspass);
|
||||
jceA->setUserID(hassid);
|
||||
|
||||
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
|
||||
qDebug() << "jceLogin::checkValidation(); Found Hashed: " << hasspass << "And ID: " << hassid;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief jceLogin::setLoginFlag
|
||||
|
@ -267,7 +272,7 @@ bool jceLogin::checkValidation()
|
|||
*/
|
||||
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)
|
||||
|
@ -275,9 +280,9 @@ void jceLogin::setLoginFlag(bool x)
|
|||
*/
|
||||
bool jceLogin::isLoginFlag() const
|
||||
{
|
||||
if (checkConnection())
|
||||
return this->loginFlag;
|
||||
return false;
|
||||
if (checkConnection())
|
||||
return this->loginFlag;
|
||||
return false;
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -286,5 +291,26 @@ bool jceLogin::isLoginFlag() const
|
|||
*/
|
||||
QString jceLogin::getPage()
|
||||
{
|
||||
return *recieverPage;
|
||||
return *recieverPage;
|
||||
}
|
||||
|
||||
void jceLogin::reValidation()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Revalidating user";
|
||||
if (makeFirstVisit() == true)
|
||||
{
|
||||
if (checkValidation())
|
||||
{
|
||||
if (makeSecondVisit() == true)
|
||||
qDebug() << Q_FUNC_INFO << "Validated";
|
||||
else
|
||||
qWarning() << Q_FUNC_INFO << "Second visit finished with an error";
|
||||
}
|
||||
else
|
||||
qDebug() << Q_FUNC_INFO << "checking validation ended with an error";
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Couldnt Validate User";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,17 @@
|
|||
#include "./src/jceSettings/user.h"
|
||||
#include "jceLoginHtmlScripts.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class jceLogin
|
||||
|
||||
class jceLogin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
jceLogin() {}
|
||||
jceLogin(user* username);
|
||||
~jceLogin();
|
||||
|
||||
enum jceStatus {
|
||||
JCE_NOT_CONNECTED,
|
||||
|
@ -26,11 +32,7 @@ public:
|
|||
JCE_GRADE_PAGE_PASSED
|
||||
};
|
||||
|
||||
jceLogin(user* username);
|
||||
~jceLogin();
|
||||
|
||||
void makeConnection() throw (jceStatus);
|
||||
void reConnect() throw (jceStatus);
|
||||
int makeConnection();
|
||||
void closeAll();
|
||||
|
||||
bool checkConnection() const;
|
||||
|
@ -41,6 +43,13 @@ public:
|
|||
|
||||
QString getPage();
|
||||
|
||||
private slots:
|
||||
void reValidation();
|
||||
void reMakeConnection();
|
||||
|
||||
signals:
|
||||
void connectionReadyAfterDisconnection();
|
||||
|
||||
private:
|
||||
|
||||
int makeFirstVisit();
|
||||
|
|
|
@ -1,37 +1,46 @@
|
|||
#include "jce_logger.h"
|
||||
|
||||
/*
|
||||
* This Static method will help parsing our debug messages to a readable Log file
|
||||
*
|
||||
* timestamp - Message type - message
|
||||
*/
|
||||
void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
|
||||
QString dt = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss");
|
||||
QString txt = QString("%1\t").arg(dt);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
txt += QString("DEBUG \t\t %1").arg(msg);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
txt += QString("WARNING \t %1").arg(msg);
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
txt += QString("CRITICAL \t %1").arg(msg);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
txt += QString("FATAL \t\t %1").arg(msg);
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
|
||||
QFile outFile("J_M_Log.log");
|
||||
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
||||
|
||||
QTextStream textStream(&outFile);
|
||||
textStream << txt << endl;
|
||||
}
|
||||
#include "jce_logger.h"
|
||||
|
||||
/*
|
||||
* This Static method will help parsing our debug messages to a readable Log file
|
||||
*
|
||||
* timestamp - Message type - message
|
||||
*
|
||||
* Message types cam be:
|
||||
*
|
||||
* - DEBUG
|
||||
* - WARNING
|
||||
* - CRITICAL
|
||||
* - FATAL
|
||||
*
|
||||
* Logs stored in a log file. File name is Stored in the Macro in Header file
|
||||
*/
|
||||
void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
Q_UNUSED(context);
|
||||
|
||||
QString dt = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss");
|
||||
QString txt = QString("%1\t").arg(dt);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
txt += QString("DEBUG \t\t %1").arg(msg);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
txt += QString("WARNING \t %1").arg(msg);
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
txt += QString("CRITICAL \t %1").arg(msg);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
txt += QString("FATAL \t\t %1").arg(msg);
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
|
||||
QFile outFile(LOG_FILE_NAME);
|
||||
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
||||
|
||||
QTextStream textStream(&outFile);
|
||||
textStream << txt << endl;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
#ifndef JCE_LOGGER_H
|
||||
#define JCE_LOGGER_H
|
||||
|
||||
#include <QMessageLogContext>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
class jce_logger
|
||||
{
|
||||
public:
|
||||
static void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
|
||||
};
|
||||
|
||||
#endif // JCE_LOGGER_H
|
||||
#ifndef JCE_LOGGER_H
|
||||
#define JCE_LOGGER_H
|
||||
|
||||
#include <QMessageLogContext>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#define LOG_FILE_NAME "J_M_Log.log"
|
||||
|
||||
class jce_logger
|
||||
{
|
||||
public:
|
||||
static void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
|
||||
};
|
||||
|
||||
#endif // JCE_LOGGER_H
|
||||
|
|
Loading…
Reference in a new issue