Merge branch 'master' into sagi_dev

This commit is contained in:
Sagi Dayan 2014-09-22 18:38:25 +03:00
commit b7a91fdbe8
14 changed files with 775 additions and 660 deletions

View file

@ -1,14 +1,53 @@
#include "loginhandler.h" #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; qDebug() << Q_FUNC_INFO << "Login with username and password";
this->pswdEditPtr = pswdEditPtr; if (isLoggedInFlag())
this->usrnmEditPtr = usrnmEditPtr; {
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() bool loginHandler::makeConnection()
@ -16,72 +55,55 @@ bool loginHandler::makeConnection()
if (this->jceLog == NULL) if (this->jceLog == NULL)
return false; return false;
try int status = (int)jceLog->makeConnection();
{
jceLog->makeConnection();
}
catch (jceLogin::jceStatus &a)
{
int status = (int)a;
switch (status) switch (status)
{ {
case jceLogin::JCE_YOU_ARE_IN: case jceLogin::JCE_YOU_ARE_IN:
{ {
logggedInFlag = true; logggedInFlag = true;
return logggedInFlag; return logggedInFlag;
break;
} }
case jceLogin::ERROR_ON_VALIDATION: case jceLogin::ERROR_ON_VALIDATION:
{ {
popMessage(QObject::tr("Please Check Your Username & Password"),false); popMessage(QObject::tr("Please Check Your Username & Password"),false);
usrnmEditPtr->setDisabled(false);
pswdEditPtr->setDisabled(false);
pswdEditPtr->selectAll();
pswdEditPtr->setFocus();
return false; return false;
} }
case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED: case jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED:
{ {
popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes.")); popMessage(QObject::tr("You have been blocked by JCE, please try in a couple of minutes."));
jceLog->closeAll();
return false; return false;
} }
case jceLogin::ERROR_ON_OPEN_SOCKET: case jceLogin::ERROR_ON_OPEN_SOCKET:
{ {
popMessage(QObject::tr("Please Check Your Internet Connection.")); popMessage(QObject::tr("Please Check Your Internet Connection."));
jceLog->closeAll();
return false; return false;
} }
case jceLogin::JCE_NOT_CONNECTED: 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; break;
} }
case jceLogin::ERROR_ON_GETTING_INFO: case jceLogin::ERROR_ON_GETTING_INFO:
{ {
popMessage(QObject::tr("Receive Request Timeout.")); popMessage(QObject::tr("Receive Request Timeout."));
jceLog->closeAll();
return false; return false;
break;
} }
case jceLogin::ERROR_ON_SEND_REQUEST: case jceLogin::ERROR_ON_SEND_REQUEST:
{ {
popMessage(QObject::tr("Send Request Timeout.")); popMessage(QObject::tr("Send Request Timeout."));
jceLog->closeAll();
return false; return false;
break;
}
} }
} }
return false; return false;
} }
void loginHandler::readyAfterConnectionLost()
{
qWarning() << Q_FUNC_INFO;
setLoginFlag(false);
login(userPtr->getUsername(),userPtr->getPassword());
}
bool loginHandler::isLoggedInFlag() bool loginHandler::isLoggedInFlag()
{ {
if (jceLog->isLoginFlag()) //checking connection and then if logged in if (jceLog->isLoginFlag()) //checking connection and then if logged in
@ -90,12 +112,10 @@ bool loginHandler::isLoggedInFlag()
this->setLoginFlag(false); this->setLoginFlag(false);
return false; return false;
} }
void loginHandler::setLoginFlag(bool flag) void loginHandler::setLoginFlag(bool flag)
{ {
this->logggedInFlag = flag; this->logggedInFlag = flag;
} }
QString loginHandler::getCurrentPageContect() QString loginHandler::getCurrentPageContect()
{ {
QTextEdit phrase; QTextEdit phrase;
@ -106,13 +126,6 @@ QString loginHandler::getCurrentPageContect()
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) int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester)
{ {
if (isLoggedInFlag()) if (isLoggedInFlag())
@ -120,7 +133,6 @@ int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, i
else else
return jceLogin::JCE_NOT_CONNECTED; return jceLogin::JCE_NOT_CONNECTED;
} }
int loginHandler::makeCalendarRequest(int year, int semester) int loginHandler::makeCalendarRequest(int year, int semester)
{ {
if (isLoggedInFlag()) if (isLoggedInFlag())
@ -128,6 +140,32 @@ int loginHandler::makeCalendarRequest(int year, int semester)
else else
return jceLogin::JCE_NOT_CONNECTED; 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) void loginHandler::popMessage(QString message,bool addInfo)
{ {
if (addInfo) if (addInfo)

View file

@ -2,43 +2,55 @@
#define LOGINHANDLER_H #define LOGINHANDLER_H
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit> #include <QTextEdit>
#include <QLabel>
#include <QMessageBox> #include <QMessageBox>
#include <QPixmap> #include <QPixmap>
#include <QStatusBar>
#include <QPushButton>
#include "./src/jceSettings/jcelogin.h" #include "./src/jceSettings/jcelogin.h"
#include "./src/appDatabase/savedata.h" #include "./src/appDatabase/savedata.h"
class loginHandler class loginHandler : public QObject
{ {
Q_OBJECT
public: public:
loginHandler(user *ptr); loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr);
void setPointers(QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr); ~loginHandler()
{
delete iconButtomStatusLabel;
delete jceLog;
}
bool login(QString username,QString password);
void logout();
void setIconConnectionStatus(jceLogin::jceStatus statusDescription);
bool makeConnection(); bool makeConnection();
bool isLoggedInFlag(); bool isLoggedInFlag();
void setLoginFlag(bool flag); void setLoginFlag(bool flag);
QString getCurrentPageContect(); QString getCurrentPageContect();
int makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester); int makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester);
int makeCalendarRequest(int year,int semester); int makeCalendarRequest(int year,int semester);
void makeDisconnectionRequest(); private slots:
void readyAfterConnectionLost();
private: private:
void popMessage(QString message, bool addInfo = true); void popMessage(QString message, bool addInfo = true);
bool logggedInFlag; bool logggedInFlag;
jceLogin *jceLog; jceLogin * jceLog;
user * userPtr;
QLabel *statusLabelPtr;
QLineEdit *pswdEditPtr;
QLineEdit *usrnmEditPtr;
QStatusBar *statusBar;
QLabel *iconButtomStatusLabel;
QPushButton *loginButtonPtr;
}; };

View file

@ -8,19 +8,21 @@
int main(int argc, char *argv[]) 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"; 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"; qDebug() << "Running a release build";
qInstallMessageHandler(jce_logger::customMessageHandler); qInstallMessageHandler(jce_logger::customMessageHandler);
#endif #endif
qDebug() << "Start : JCE Manager Launched" << Q_FUNC_INFO; qDebug() << "Start : JCE Manager Launched";
QApplication a(argc, argv); QApplication a(argc, argv);
QTranslator translator; QTranslator translator;
QString loco; QString loco;
SaveData data; SaveData data;
loco = data.getLocal(); loco = data.getLocal();
//Loading Local (From Settings file (SaveData.cpp)
if(loco == "default") if(loco == "default")
{ {
QString locale = QLocale::system().name(); QString locale = QLocale::system().name();
@ -33,10 +35,11 @@ int main(int argc, char *argv[])
translator.load("jce_en" , a.applicationDirPath()); translator.load("jce_en" , a.applicationDirPath());
qDebug() << "Local : English Local Loaded"; qDebug() << "Local : English Local Loaded";
} }
a.installTranslator(&translator); a.installTranslator(&translator); //Setting local
MainScreen w; MainScreen w;
w.show(); w.show();
//Getting the exit code from QApplication. for debug reasons
int returnCode = a.exec(); int returnCode = a.exec();
if(returnCode == 0) if(returnCode == 0)
qDebug() << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode; qDebug() << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode;

View file

@ -8,7 +8,6 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
//this->setFixedSize(this->size()); //main not resizeable //this->setFixedSize(this->size()); //main not resizeable
//Login Tab //Login Tab
QPixmap iconPix;
iconPix.load(":/icons/iconX.png"); iconPix.load(":/icons/iconX.png");
ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
ui->labelUsrInputStatus->setVisible(false); ui->labelUsrInputStatus->setVisible(false);
@ -16,16 +15,12 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
ui->labelUsrInputStatus->setPixmap(iconPix); ui->labelUsrInputStatus->setPixmap(iconPix);
ui->labelPswInputStatus->setPixmap(iconPix); ui->labelPswInputStatus->setPixmap(iconPix);
//Status Bar //StatusBar
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); 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->setMaximumSize(this->geometry().width(),STATUS_ICON_HEIGH);
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); ui->statusBar->showMessage(tr("Ready"));
ui->statusBar->addPermanentWidget(statusLabel,1);
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
//Course, Setting, Calendar Tab //Course, Calendar Tab
calendarSchedule * calendarSchedulePtr = new calendarSchedule(); calendarSchedule * calendarSchedulePtr = new calendarSchedule();
ui->calendarGridLayoutMain->addWidget(calendarSchedulePtr); ui->calendarGridLayoutMain->addWidget(calendarSchedulePtr);
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
@ -33,7 +28,7 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
//Pointer allocating //Pointer allocating
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(userLoginSetting); this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton);
this->calendar = new CalendarManager(calendarSchedulePtr); this->calendar = new CalendarManager(calendarSchedulePtr);
this->data = new SaveData(); this->data = new SaveData();
@ -45,54 +40,62 @@ MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScr
ui->keepLogin->setChecked(true); ui->keepLogin->setChecked(true);
} }
//Local Check and ui setting. //language
checkLocale(); checkLocale();
} }
MainScreen::~MainScreen() MainScreen::~MainScreen()
{ {
delete ButtomStatusLabel;
delete statusLabel;
delete calendar; delete calendar;
delete courseTableMgr; delete courseTableMgr;
delete userLoginSetting; delete userLoginSetting;
delete loginHandel; delete loginHandel;
delete ui;
delete data; delete data;
delete ui;
} }
//EVENTS ON STATUS BAR //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 //EVENTS ON LOGIN TAB
void MainScreen::on_loginButton_clicked() void MainScreen::on_loginButton_clicked()
{ {
if (loginHandel->isLoggedInFlag()) qDebug() << Q_FUNC_INFO;
uiSetDisconnectMode(); 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 else
uiSetConnectMode(); 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
{
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() void MainScreen::on_keepLogin_clicked()
{ {
@ -108,74 +111,7 @@ void MainScreen::on_usrnmLineEdit_editingFinished()
{ {
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); 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 //EVENTS ON GPA TAB
void MainScreen::on_ratesButton_clicked() void MainScreen::on_ratesButton_clicked()
{ {
@ -189,7 +125,9 @@ void MainScreen::on_ratesButton_clicked()
int status = 0; int status = 0;
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED) if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),
ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),
ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_GRADE_PAGE_PASSED)
{ {
pageString = loginHandel->getCurrentPageContect(); pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString); courseTableMgr->setCoursesList(pageString);
@ -226,7 +164,6 @@ void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1)
{ {
ui->spinBoxCoursesFromYear->setValue(arg1); ui->spinBoxCoursesFromYear->setValue(arg1);
} }
void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1) void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1)
{ {
ui->spinBoxCoursesToYear->setValue(arg1); ui->spinBoxCoursesToYear->setValue(arg1);
@ -280,7 +217,6 @@ void MainScreen::on_exportToCVSBtn_clicked()
} }
} }
//EVENTS ON MENU BAR //EVENTS ON MENU BAR
void MainScreen::on_actionCredits_triggered() void MainScreen::on_actionCredits_triggered()
{ {
@ -309,14 +245,8 @@ void MainScreen::on_actionHow_To_triggered()
"<br><li>"+tr("HELP3")+"</li>" "<br><li>"+tr("HELP3")+"</li>"
"<br><li>"+tr("HELP4")+"</li>" "<br><li>"+tr("HELP4")+"</li>"
"<br><li>"+tr("HELP5")+"</li>" "<br><li>"+tr("HELP5")+"</li>"
"<br><br>"+tr("HELP6")+
"</ul>"); "</ul>");
} }
void MainScreen::on_actionHebrew_triggered() void MainScreen::on_actionHebrew_triggered()
{ {
if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked()) if (ui->actionEnglish->isChecked() || ui->actionOS_Default->isChecked())
@ -330,7 +260,6 @@ void MainScreen::on_actionHebrew_triggered()
else else
ui->actionHebrew->setChecked(true); ui->actionHebrew->setChecked(true);
} }
void MainScreen::on_actionEnglish_triggered() void MainScreen::on_actionEnglish_triggered()
{ {
if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked()) if (ui->actionHebrew->isChecked() || ui->actionOS_Default->isChecked())
@ -344,8 +273,6 @@ void MainScreen::on_actionEnglish_triggered()
else else
ui->actionEnglish->setChecked(true); ui->actionEnglish->setChecked(true);
} }
void MainScreen::on_actionOS_Default_triggered() void MainScreen::on_actionOS_Default_triggered()
{ {
if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked()) if (ui->actionHebrew->isChecked() || ui->actionEnglish->isChecked())

View file

@ -70,25 +70,20 @@ private slots:
private: private:
void uiSetDisconnectMode();
void uiSetConnectMode();
void setLabelConnectionStatus(jceLogin::jceStatus statusDescription);
void checkLocale(); void checkLocale();
bool checkIfValidDates(); bool checkIfValidDates();
Ui::MainScreen *ui; Ui::MainScreen *ui;
QLabel *ButtomStatusLabel; QPixmap iconPix;
QLabel *statusLabel;
user *userLoginSetting; user *userLoginSetting;
SaveData *data; SaveData *data;
CalendarManager * calendar; CalendarManager * calendar;
coursesTableManager *courseTableMgr; coursesTableManager *courseTableMgr;
loginHandler *loginHandel;
bool calendarLoaded; loginHandler *loginHandel;
}; };

View file

@ -345,7 +345,7 @@ font-size: 15px;
<item> <item>
<widget class="QPushButton" name="ratesButton"> <widget class="QPushButton" name="ratesButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="whatsThis"> <property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Get your grades&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Get your grades&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>

View file

@ -1,21 +1,22 @@
#include "jcesslclient.h" #include "jcesslclient.h"
/** /**
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals * @brief jceSSLClient::jceSSLClient Constructer, setting the signals
*/ */
jceSSLClient::jceSSLClient() : flag(false), packet("") jceSSLClient::jceSSLClient() : flag(false), packet(""), networkConf(), reConnection(false)
{ {
//setting signals //setting signals
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError))); connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
connect(this,SIGNAL(connected()),this,SLOT(setConnected())); connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted())); connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected())); connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
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 //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(encrypted()), &loop, SLOT(quit()));
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),&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. * @brief jceSSLClient::makeConnect connecting to server with given port. using eventloop to assure it wont stuck the application.
* @param server - server to connect to * @param server - server to connect to
@ -24,24 +25,33 @@ jceSSLClient::jceSSLClient() : flag(false), packet("")
*/ */
bool jceSSLClient::makeConnect(QString server, int port) 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()) if (isConnected())
{ {
qWarning() << "jceSSLClient::makeConnect; Was already connected. Aborting."; qDebug() << Q_FUNC_INFO << "flag=true, calling makeDisconnect()";
makeDiconnect();
}
if (isOpen())
{
qWarning() << "jceSSLClient::makeConnect; IsO pen. Aborting.";
makeDiconnect(); 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); connectToHostEncrypted(server.toStdString().c_str(), port);
loop.exec(); //starting connection, waiting to encryption and then it ends 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(); return isConnected();
} }
@ -51,37 +61,16 @@ bool jceSSLClient::makeConnect(QString server, int port)
*/ */
bool jceSSLClient::makeDiconnect() bool jceSSLClient::makeDiconnect()
{ {
qDebug() << "jceSSLClient::makeDiconnect;";
if (loop.isRunning()) if (loop.isRunning())
{ {
qWarning() << "jceSSLClient::makeDiconnect; Killing connection thread"; qWarning() << Q_FUNC_INFO << "Killing connection thread";
loop.exit(); loop.exit();
} }
if (state() == QAbstractSocket::SocketState::UnconnectedState) qDebug() << Q_FUNC_INFO << "disconnecting from host and emitting disconnected()";
{ this->disconnectFromHost(); //emits disconnected > setDisconnected
qDebug() << "jceSSLClient::makeDiconnect; Disconnected with [UnconnectedState]"; setSocketState(QAbstractSocket::SocketState::UnconnectedState);
flag = false; return (!isConnected());
}
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;
} }
/** /**
@ -90,20 +79,30 @@ bool jceSSLClient::makeDiconnect()
*/ */
bool jceSSLClient::isConnected() bool jceSSLClient::isConnected()
{ {
bool tempFlag;
//checking state before returning flag! //checking state before returning flag!
if (state() == QAbstractSocket::SocketState::UnconnectedState) if (state() == QAbstractSocket::SocketState::UnconnectedState)
{ {
flag = false; tempFlag = false;
} }
else if (state() == QAbstractSocket::SocketState::ClosingState) else if (state() == QAbstractSocket::SocketState::ClosingState)
{ {
flag = false; tempFlag = false;
} }
else if (state() == QAbstractSocket::SocketState::ConnectedState) 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 * @brief jceSSLClient::sendData - given string, send it to server
@ -119,7 +118,7 @@ bool jceSSLClient::sendData(QString str)
if (waitForBytesWritten()) if (waitForBytesWritten())
sendDataFlag = true; sendDataFlag = true;
} }
qDebug() << "jceSSLClient::sendData; Sending Data status is: " << sendDataFlag; qDebug() << Q_FUNC_INFO << "Sending Data status is: " << sendDataFlag;
return sendDataFlag; return sendDataFlag;
} }
/** /**
@ -130,7 +129,7 @@ bool jceSSLClient::sendData(QString str)
*/ */
bool jceSSLClient::recieveData(QString &str, bool fast) bool jceSSLClient::recieveData(QString &str, bool fast)
{ {
qDebug() << "jceSSLClient::recieveData Data receiving!"; qDebug() << Q_FUNC_INFO << "Data receiving!";
packet = ""; packet = "";
bool sflag = false; bool sflag = false;
@ -158,10 +157,10 @@ bool jceSSLClient::recieveData(QString &str, bool fast)
} }
} }
str = packet; str = packet;
qDebug() << "jceSSLClient::recieveData received bytes: " << str.length() ; qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ;
if (str.length() > 0) if (str.length() > 0)
sflag = true; sflag = true;
qDebug() << "jceSSLClient::recieveData return with flag: " << sflag; qDebug() << Q_FUNC_INFO << "return with flag: " << sflag;
return sflag; return sflag;
} }
@ -177,6 +176,24 @@ void jceSSLClient::readIt()
packet.append(p); packet.append(p);
}while (p.size() > 0); }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 * @brief jceSSLClient::setConnected called when signaled with connected, calling the encryption function
@ -186,26 +203,34 @@ void jceSSLClient::setConnected()
waitForEncrypted(); 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() void jceSSLClient::setDisconnected()
{ {
qDebug() << Q_FUNC_INFO << "connection has been DISCONNECTED";
this->setSocketState(QAbstractSocket::SocketState::UnconnectedState);
packet.clear();
flag = false; flag = false;
if (reConnection)
makeConnect();
} }
/** /**
* @brief jceSSLClient::setEncrypted called when signaled with encrypted. setting the buffer size and keeping alive. * @brief jceSSLClient::setEncrypted called when signaled with encrypted. setting the buffer size and keeping alive.
*/ */
void jceSSLClient::setEncrypted() void jceSSLClient::setEncrypted()
{ {
qDebug() << Q_FUNC_INFO << "connection has been ENCRYPTED";
setReadBufferSize(10000); setReadBufferSize(10000);
setSocketOption(QAbstractSocket::KeepAliveOption,1); setSocketOption(QAbstractSocket::KeepAliveOption,true);
if (state() == QAbstractSocket::SocketState::ConnectedState)
flag = true; flag = true;
else if (!isConnected())
{ {
qWarning() << "jceSSLClient::setEncrypted(); Connection status didnt change!"; qWarning() << Q_FUNC_INFO << "Connection status didnt change! reseting flag to false";
flag = false; flag = false;
} }
} }
/** /**
* @brief jceSSLClient::showIfErrorMsg message box to show the error occured according to socket * @brief jceSSLClient::showIfErrorMsg message box to show the error occured according to socket
@ -220,94 +245,111 @@ void jceSSLClient::showIfErrorMsg()
bool relevantError = false; bool relevantError = false;
switch (enumError) switch (enumError)
{ {
case QAbstractSocket::SocketError::ConnectionRefusedError: case QAbstractSocket::SocketError::ConnectionRefusedError: /**/
errorString = QObject::tr("ConnectionRefusedError"); errorString = QObject::tr("ConnectionRefusedError");
//The connection was refused by the peer (or timed out).
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::RemoteHostClosedError: case QAbstractSocket::SocketError::RemoteHostClosedError: /**/
errorString = QObject::tr("RemoteHostClosedError"); errorString = QObject::tr("RemoteHostClosedError");
//The remote host closed the connection
if (networkConf.isOnline()) //we can reconnect
{
reConnection = true;
}
else
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::HostNotFoundError: case QAbstractSocket::SocketError::HostNotFoundError: /**/
errorString = QObject::tr("HostNotFoundError"); errorString = QObject::tr("HostNotFoundError");
//The host address was not found.
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::SocketAccessError: case QAbstractSocket::SocketError::SocketAccessError: /**/
errorString = QObject::tr("SocketAccessError"); errorString = QObject::tr("SocketAccessError");
//The socket operation failed because the application lacked the required privileges.
break; break;
case QAbstractSocket::SocketError::SocketResourceError: case QAbstractSocket::SocketError::SocketTimeoutError: /**/
errorString = QObject::tr("SocketResourceError");
break;
case QAbstractSocket::SocketError::SocketTimeoutError:
errorString = QObject::tr("SocketTimeoutError"); errorString = QObject::tr("SocketTimeoutError");
if (!isConnected()) //The socket operation timed out.
if (isConnected()); //ignore it if connected.
else
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::DatagramTooLargeError: 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::SslHandshakeFailedError: /**/
errorString = QObject::tr("SslHandshakeFailedError");
relevantError = true;
break;
case QAbstractSocket::SocketError::SslInternalError: /**/
errorString = QObject::tr("SslInternalError");
relevantError = true;
break;
case QAbstractSocket::SocketError::SslInvalidUserDataError: /**/
errorString = QObject::tr("SslInvalidUserDataError");
relevantError = true;
break;
case QAbstractSocket::SocketError::DatagramTooLargeError: //not relevant to us
errorString = QObject::tr("DatagramTooLargeError"); errorString = QObject::tr("DatagramTooLargeError");
break; break;
case QAbstractSocket::SocketError::NetworkError: case QAbstractSocket::SocketError::SocketResourceError: //not relevant to us
errorString = QObject::tr("NetworkError");
relevantError = true;
break; break;
case QAbstractSocket::SocketError::AddressInUseError: case QAbstractSocket::SocketError::OperationError: //not relevant, except for debug
errorString = QObject::tr("AddressInUseError");
break;
case QAbstractSocket::SocketError::SocketAddressNotAvailableError:
errorString = QObject::tr("SocketAddressNotAvailableError");
break;
case QAbstractSocket::SocketError::UnsupportedSocketOperationError:
errorString = QObject::tr("UnsupportedSocketOperationError");
break;
case QAbstractSocket::SocketError::ProxyAuthenticationRequiredError:
errorString = QObject::tr("ProxyAuthenticationRequiredError");
break;
case QAbstractSocket::SocketError::SslHandshakeFailedError:
errorString = QObject::tr("SslHandshakeFailedError");
break;
case QAbstractSocket::SocketError::ProxyConnectionRefusedError:
errorString = QObject::tr("ProxyConnectionRefusedError");
break;
case QAbstractSocket::SocketError::UnfinishedSocketOperationError:
errorString = QObject::tr("UnfinishedSocketOperationError");
break;
case QAbstractSocket::SocketError::ProxyConnectionClosedError:
errorString = QObject::tr("ProxyConnectionClosedError");
break;
case QAbstractSocket::SocketError::ProxyConnectionTimeoutError:
errorString = QObject::tr("ProxyConnectionTimeoutError");
break;
case QAbstractSocket::SocketError::ProxyNotFoundError:
errorString = QObject::tr("ProxyNotFoundError");
break;
case QAbstractSocket::SocketError::ProxyProtocolError:
errorString = QObject::tr("ProxyProtocolError");
break;
case QAbstractSocket::SocketError::OperationError:
errorString = QObject::tr("OperationError"); errorString = QObject::tr("OperationError");
break; break;
case QAbstractSocket::SocketError::SslInternalError: case QAbstractSocket::SocketError::AddressInUseError: //not relevant to us
errorString = QObject::tr("SslInternalError"); errorString = QObject::tr("AddressInUseError");
break; break;
case QAbstractSocket::SocketError::SslInvalidUserDataError: case QAbstractSocket::SocketError::SocketAddressNotAvailableError: //not relevant to us
errorString = QObject::tr("SslInvalidUserDataError"); errorString = QObject::tr("SocketAddressNotAvailableError");
break; 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"); errorString = QObject::tr("TemporaryError");
break; break;
case QAbstractSocket::SocketError::UnknownSocketError: case QAbstractSocket::SocketError::UnknownSocketError: //not relevant, except for debug
errorString = QObject::tr("UnknownSocketError"); errorString = QObject::tr("UnknownSocketError");
relevantError = true; relevantError = true;
break; break;
} }
if (relevantError) //informative string to be shown 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.setIcon(QMessageBox::Warning);
msgBox.setText(errorString); msgBox.setText(errorString);
msgBox.exec(); msgBox.exec();
} }
} }
/** /**
* @brief jceSSLClient::checkErrors this function exctuing when socket error has occured * @brief jceSSLClient::checkErrors this function exctuing when socket error has occured
@ -315,8 +357,14 @@ void jceSSLClient::showIfErrorMsg()
*/ */
void jceSSLClient::checkErrors(QAbstractSocket::SocketError a) void jceSSLClient::checkErrors(QAbstractSocket::SocketError a)
{ {
qWarning() << "jceSSLClient::checkErrors; Var Error: " << a; //ignore this stupid error
qWarning() << "jceSSLClient::checkErrors; Error: " << this->errorString(); 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(); showIfErrorMsg();
} }

View file

@ -6,36 +6,42 @@
#include <QThread> #include <QThread>
#include <QEventLoop> #include <QEventLoop>
#include <QMessageBox> #include <QMessageBox>
#include <QNetworkConfigurationManager>
#include <iostream> #define milisTimeOut 4000
#include <string>
#define milisTimeOut 3500
class jceSSLClient : QSslSocket class jceSSLClient : public QSslSocket
{ {
Q_OBJECT Q_OBJECT
public: public:
jceSSLClient(); jceSSLClient();
bool makeConnect(QString server, int port); bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443);
bool makeDiconnect();
bool isConnected(); bool isConnected();
bool sendData(QString str); bool sendData(QString str);
bool recieveData(QString &str, bool fast); bool recieveData(QString &str, bool fast);
bool makeDiconnect();
void showIfErrorMsg(); void showIfErrorMsg();
signals:
void serverDisconnectedbyRemote();
void noInternetLink();
void socketDisconnected();
private slots: private slots:
void checkErrors(QAbstractSocket::SocketError a); void checkErrors(QAbstractSocket::SocketError a);
void setConnected(); void setConnected();
void setEncrypted(); void setEncrypted();
void setDisconnected(); void setDisconnected();
void readIt(); void readIt();
void setOnlineState(bool isOnline);
private: private:
bool flag; bool flag;
QString packet; QString packet;
QEventLoop loop; //handle the connection as thread QEventLoop loop; //handle the connection as thread
QNetworkConfigurationManager networkConf; //checking if online
bool reConnection; //used for remote host disconnecting
}; };

View file

@ -1,10 +1,25 @@
#include "csv_exporter.h" #include "csv_exporter.h"
/*
*
* Class doc can be bound in csv_exporter.h
*
*/
CSV_Exporter::CSV_Exporter() 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) bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal)
{ {
if ((cal == NULL) || (calSched == NULL)) //pointers checking! 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..."; qDebug() << "Getting path for csv file from user...";
QString filePath = getFileFath(); 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"; qDebug() << "CSV : User pressed Cancel... returning false";
return false; return false;
@ -25,7 +40,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
qDebug() << "CSV : Atempting to export the Schedule..."; qDebug() << "CSV : Atempting to export the Schedule...";
QFile file(filePath); 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; QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
@ -33,13 +48,16 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
msgBox.exec(); msgBox.exec();
qCritical() << "unable to open/create the file... maybe permissions error."; qCritical() << "unable to open/create the file... maybe permissions error.";
return false; return false;
}//else }
//Delete the file
QTextStream out(&file); QTextStream out(&file); //The output streem.
out << CSV_CALENDAR_HEADER << "\n"; out.setCodec("UTF-8"); //Unicode 8
for (calendarCourse *coursePtr: *(calSched->getCourses()))
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 day = coursePtr->getDay();
int startH = coursePtr->getHourBegin(); int startH = coursePtr->getHourBegin();
int startM = coursePtr->getMinutesBegin(); int startM = coursePtr->getMinutesBegin();
@ -50,11 +68,15 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
QString name = coursePtr->getName(); QString name = coursePtr->getName();
QString room = coursePtr->getRoom(); 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, &currentDate, startH, startM, endH, endM, lecturer, room, type); QString line = makeLine(name, &currentDate, startH, startM, endH, endM, lecturer, room, type);
if(line != NULL) 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 CSV_Exporter::getFileFath()
{ {
QString fileName = QFileDialog::getSaveFileName(); QString fileName = QFileDialog::getSaveFileName();
@ -82,6 +108,20 @@ QString CSV_Exporter::getFileFath()
return fileName; 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) 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 //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("\n");
description.append(" ב"); description.append(" ב");
description.append(room); description.append(room);
description.append("\""); description.append("\n Created with JCE Manager.\"");
//Create the Fucking Line //Create the Fucking Line
//Header: Subject,Start Date,Start Time,End Date,End Time,Description,Location //Header: Subject,Start Date,Start Time,End Date,End Time,Description,Location

View file

@ -4,11 +4,13 @@
* @brief jceLogin::jceLogin * @brief jceLogin::jceLogin
* @param username pointer to allocated user settings * @param username pointer to allocated user settings
*/ */
jceLogin::jceLogin(user * username) jceLogin::jceLogin(user* username)
{ {
this->recieverPage = new QString(); this->recieverPage = new QString();
this->jceA = username; this->jceA = username;
this->JceConnector = new jceSSLClient(); this->JceConnector = new jceSSLClient();
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
} }
jceLogin::~jceLogin() jceLogin::~jceLogin()
@ -23,21 +25,26 @@ jceLogin::~jceLogin()
* @brief jceLogin::makeConnection Connecting to JCE student web site with JceA (username object) and validate it. * @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 * 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) if (this->recieverPage == NULL)
this->recieverPage = new QString(); 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 int returnMode; //gets status according to called function of validation step
jceStatus status = jceStatus::JCE_NOT_CONNECTED; jceStatus status = jceStatus::JCE_NOT_CONNECTED;
returnMode = checkConnection(); //checking socket status. is connected? returnMode = checkConnection(); //checking socket status. is connected?
if (returnMode == false)
{
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 if (returnMode == true) //connected to host
{ {
returnMode = makeFirstVisit(); returnMode = makeFirstVisit();
@ -86,8 +93,8 @@ void jceLogin::makeConnection() throw (jceStatus)
status = jceStatus::JCE_NOT_CONNECTED; status = jceStatus::JCE_NOT_CONNECTED;
//we throw status even if we are IN! //we throw status even if we are IN!
qDebug() << "jceLogin::makeConnection(); throw status: " << status; qDebug() << "jceLogin::makeConnection(); return status: " << status;
throw status; return status;
} }
/** /**
@ -101,36 +108,35 @@ bool jceLogin::checkConnection() const
return false; return false;
} }
/**
* @brief jceLogin::reConnect
* closing connection and deleting pointers.
* calling class's makeConnection function and throw the exception of it.
*/
void jceLogin::reConnect() throw (jceStatus)
{
closeAll();
if (this->JceConnector != NULL)
delete JceConnector;
this->recieverPage = new QString();
this->JceConnector = new jceSSLClient();
try
{
makeConnection();
}
catch (jceLogin::jceStatus &a)
{
throw a;
}
}
/** /**
* @brief jceLogin::closeAll * @brief jceLogin::closeAll
*/ */
void jceLogin::closeAll() void jceLogin::closeAll()
{ {
JceConnector->makeDiconnect(); this->JceConnector->makeDiconnect();
if ((this->recieverPage != NULL) && (!this->recieverPage->isEmpty()))
{
delete recieverPage; delete recieverPage;
recieverPage = NULL; 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();
} }
/** /**
@ -202,7 +208,6 @@ int jceLogin::getCalendar(int year, int semester)
*/ */
int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester) int jceLogin::getGrades(int fromYear, int toYear, int fromSemester, int toSemester)
{ {
std::cout << fromYear << " " << toYear << " " << fromSemester << " " << toSemester << std::endl;
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))) if (!(JceConnector->recieveData(*recieverPage,false)))
@ -288,3 +293,24 @@ 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";
}
}

View file

@ -5,11 +5,17 @@
#include "./src/jceSettings/user.h" #include "./src/jceSettings/user.h"
#include "jceLoginHtmlScripts.h" #include "jceLoginHtmlScripts.h"
#include <QObject>
#include <QString> #include <QString>
class jceLogin
class jceLogin : public QObject
{ {
Q_OBJECT
public: public:
jceLogin() {}
jceLogin(user* username);
~jceLogin();
enum jceStatus { enum jceStatus {
JCE_NOT_CONNECTED, JCE_NOT_CONNECTED,
@ -26,11 +32,7 @@ public:
JCE_GRADE_PAGE_PASSED JCE_GRADE_PAGE_PASSED
}; };
jceLogin(user* username); int makeConnection();
~jceLogin();
void makeConnection() throw (jceStatus);
void reConnect() throw (jceStatus);
void closeAll(); void closeAll();
bool checkConnection() const; bool checkConnection() const;
@ -41,6 +43,13 @@ public:
QString getPage(); QString getPage();
private slots:
void reValidation();
void reMakeConnection();
signals:
void connectionReadyAfterDisconnection();
private: private:
int makeFirstVisit(); int makeFirstVisit();

View file

@ -4,6 +4,15 @@
* This Static method will help parsing our debug messages to a readable Log file * This Static method will help parsing our debug messages to a readable Log file
* *
* timestamp - Message type - message * 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) void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{ {
@ -29,7 +38,7 @@ void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &
break; break;
} }
QFile outFile("J_M_Log.log"); QFile outFile(LOG_FILE_NAME);
outFile.open(QIODevice::WriteOnly | QIODevice::Append); outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream textStream(&outFile); QTextStream textStream(&outFile);

View file

@ -7,6 +7,8 @@
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#define LOG_FILE_NAME "J_M_Log.log"
class jce_logger class jce_logger
{ {
public: public: