jce-manager/main/mainscreen.cpp

414 lines
15 KiB
C++
Raw Normal View History

2014-06-18 23:44:46 +00:00
#include "mainscreen.h"
#include "ui_mainscreen.h"
2014-10-16 08:15:23 +00:00
#define VERSION "1.1.0"
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen)
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
ui->setupUi(this);
this->isBlocked = false;
//Login Tab
iconPix.load(":/icons/iconX.png");
ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
ui->labelUsrInputStatus->setVisible(false);
ui->labelPswInputStatus->setVisible(false);
ui->labelUsrInputStatus->setPixmap(iconPix);
ui->labelPswInputStatus->setPixmap(iconPix);
2014-10-12 13:48:42 +00:00
2014-10-12 22:43:08 +00:00
//StatusBar
statusBar = new jceStatusBar(this);
this->setStatusBar(statusBar);
2014-10-12 13:48:42 +00:00
2014-10-12 22:43:08 +00:00
//GPA Tab
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
2014-10-12 13:48:42 +00:00
2014-10-12 22:43:08 +00:00
//Pointer allocating
qDebug() << Q_FUNC_INFO << "Allocating pointers";
this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler(userLoginSetting, ui->loginButton, statusBar);
this->calendar = new CalendarManager(this,ui->calendarGridLayoutMain);
this->data = new SaveData();
2014-10-12 13:48:42 +00:00
2014-10-12 22:43:08 +00:00
//check login File
if (data->isSaved())
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "Loading data from file";
ui->usrnmLineEdit->setText(data->getUsername());
ui->pswdLineEdit->setText(data->getPassword());
ui->keepLogin->setChecked(true);
2014-06-18 23:44:46 +00:00
}
2014-10-12 22:43:08 +00:00
//language
qDebug() << Q_FUNC_INFO << "Checking locale";
checkLocale();
qDebug() << Q_FUNC_INFO << "Ready.";
2014-06-18 23:44:46 +00:00
}
MainScreen::~MainScreen()
{
2014-10-13 23:45:11 +00:00
delete statusBar;
2014-10-12 22:43:08 +00:00
delete calendar;
delete courseTableMgr;
delete userLoginSetting;
delete loginHandel;
delete data;
delete ui;
2014-06-18 23:44:46 +00:00
}
2014-09-09 08:20:58 +00:00
//EVENTS ON LOGIN TAB
2014-06-20 17:13:21 +00:00
void MainScreen::on_loginButton_clicked()
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
if (!isBusy())
{
2014-10-12 22:43:08 +00:00
lock();
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
{
2014-10-12 22:43:08 +00:00
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);
2014-10-14 15:01:45 +00:00
unlock();
2014-10-12 22:43:08 +00:00
return;
}
2014-10-12 22:43:08 +00:00
else
{
2014-10-12 22:43:08 +00:00
ui->labelUsrInputStatus->setVisible(false);
ui->labelPswInputStatus->setVisible(false);
}
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "login session start";
if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true)
{
qDebug() << Q_FUNC_INFO << "login session end with true";
ui->pswdLineEdit->setDisabled(true);
ui->usrnmLineEdit->setDisabled(true);
if (ui->keepLogin->isChecked())
{
qDebug() << Q_FUNC_INFO << "saving data";
data->setUsername(ui->usrnmLineEdit->text());
data->setPassword(ui->pswdLineEdit->text());
}
}
else
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "login session end with false";
ui->pswdLineEdit->setDisabled(false);
ui->usrnmLineEdit->setDisabled(false);
}
2014-10-12 22:43:08 +00:00
unlock();
2014-09-09 08:20:58 +00:00
}
2014-10-12 22:43:08 +00:00
}
void MainScreen::on_keepLogin_clicked()
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (ui->keepLogin->isChecked())
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "saving data";
data->setUsername(ui->usrnmLineEdit->text());
data->setPassword(ui->pswdLineEdit->text());
2014-09-09 08:20:58 +00:00
}
2014-10-12 22:43:08 +00:00
else
data->reset();
2014-09-09 08:20:58 +00:00
}
void MainScreen::on_usrnmLineEdit_editingFinished()
{
2014-10-12 22:43:08 +00:00
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
}
2014-09-09 08:20:58 +00:00
//EVENTS ON GPA TAB
2014-06-20 17:13:21 +00:00
void MainScreen::on_ratesButton_clicked()
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (!isBusy())
{
2014-10-12 22:43:08 +00:00
lock();
if (!checkIfValidDates())
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
qWarning() << Q_FUNC_INFO << "Invalid dates! return";
QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again"));
return;
2014-06-20 02:59:33 +00:00
}
2014-10-12 22:43:08 +00:00
QString pageString;
int status = 0;
if (loginHandel->isLoggedInFlag())
2014-06-20 02:59:33 +00:00
{
2014-10-12 22:43:08 +00:00
statusBar->setIconConnectionStatus(jceStatusBar::Ready);
if ((status = loginHandel->makeGradeRequest(ui->spinBoxCoursesFromYear->value(),
ui->spinBoxCoursesToYear->value(),ui->spinBoxCoursesFromSemester->value(),
ui->spinBoxCoursesToSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{
qDebug() << Q_FUNC_INFO << "grade page is ready";
statusBar->setIconConnectionStatus(jceStatusBar::Inserting);
pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString);
statusBar->setIconConnectionStatus(jceStatusBar::Done);
}
else if (status == jceLogin::JCE_NOT_CONNECTED)
{
qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
}
else
{
2014-10-13 13:00:58 +00:00
statusBar->setIconConnectionStatus(jceStatusBar::Error);
2014-10-12 22:43:08 +00:00
qCritical() << Q_FUNC_INFO << "grade get ended with" << status;
}
}
2014-10-12 22:43:08 +00:00
unlock();
2014-06-18 23:44:46 +00:00
}
2014-08-27 10:49:15 +00:00
}
bool MainScreen::checkIfValidDates()
{
2014-10-12 22:43:08 +00:00
bool flag = false;
if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value())
{
2014-10-12 22:43:08 +00:00
//doesnt matter what is the semester, its valid!
flag = true;
}
2014-10-12 22:43:08 +00:00
else if ((ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value()))
{
2014-10-12 22:43:08 +00:00
//semester from must be equal or less than to semester
if (ui->spinBoxCoursesFromSemester->value() <= ui->spinBoxCoursesToSemester->value())
flag = true;
}
2014-10-12 22:43:08 +00:00
return flag;
}
2014-10-07 14:26:11 +00:00
void MainScreen::on_checkBoxCoursesInfluence_toggled(bool checked)
2014-08-27 10:49:15 +00:00
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked;
this->userLoginSetting->setInfluenceCourseOnly(checked);
this->courseTableMgr->influnceCourseChanged(checked);
2014-06-18 23:44:46 +00:00
}
void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1)
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
ui->spinBoxCoursesFromYear->setValue(arg1);
2014-06-18 23:44:46 +00:00
}
void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1)
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
ui->spinBoxCoursesToYear->setValue(arg1);
2014-06-18 23:44:46 +00:00
}
void MainScreen::on_spinBoxCoursesFromSemester_valueChanged(int arg1)
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
ui->spinBoxCoursesFromSemester->setValue(arg1%4);
2014-06-18 23:44:46 +00:00
}
void MainScreen::on_spinBoxCoursesToSemester_valueChanged(int arg1)
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
ui->spinBoxCoursesToSemester->setValue(arg1%4);
2014-06-18 23:44:46 +00:00
}
void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item)
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
if (this->courseTableMgr->changes(item->text(),item->row(),item->column()))
ui->avgLCD->display(courseTableMgr->getAvg());
else
{
2014-10-12 22:43:08 +00:00
qWarning() << Q_FUNC_INFO << "missmatch data";
QMessageBox::critical(this,tr("Error"),tr("Missmatching data"));
}
2014-06-18 23:44:46 +00:00
}
2014-09-09 08:20:58 +00:00
void MainScreen::on_clearTableButton_clicked()
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
courseTableMgr->clearTable();
ui->avgLCD->display(courseTableMgr->getAvg());
2014-06-18 23:44:46 +00:00
}
2014-10-07 14:26:11 +00:00
2014-10-05 11:16:01 +00:00
void MainScreen::on_graphButton_clicked()
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO;
if (!courseTableMgr->showGraph())
QMessageBox::critical(this,tr("Error"),tr("You must to load GPA first\nClick on 'Get GPA'"));
2014-10-05 11:16:01 +00:00
}
2014-10-13 02:12:00 +00:00
void MainScreen::on_revertBtn_clicked()
{
qDebug() << Q_FUNC_INFO;
if (!isBusy())
{
lock();
courseTableMgr->revertChanges();
unlock();
}
}
2014-09-09 08:20:58 +00:00
//EVENTS ON CALENDAR TAB
void MainScreen::on_examsBtn_clicked()
2014-10-12 02:52:07 +00:00
{
2014-10-12 22:43:08 +00:00
calendar->showExamDialog();
2014-10-12 02:52:07 +00:00
}
void MainScreen::on_getCalendarBtn_clicked()
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (!isBusy())
{
2014-10-12 22:43:08 +00:00
lock();
int status = 0;
QString page;
if (loginHandel->isLoggedInFlag())
{
statusBar->setIconConnectionStatus(jceStatusBar::Ready);
2014-10-12 22:43:08 +00:00
if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{
statusBar->setIconConnectionStatus(jceStatusBar::Inserting);
calendar->resetTable();
page = loginHandel->getCurrentPageContect();
calendar->setCalendar(page);
2014-10-12 02:52:07 +00:00
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "calendar is loaded";
2014-10-12 02:52:07 +00:00
2014-10-12 22:43:08 +00:00
//auto getting exam
if (loginHandel->isLoggedInFlag())
2014-10-12 02:52:07 +00:00
{
2014-10-12 22:43:08 +00:00
if ((status = loginHandel->makeExamsScheduleRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{
page = loginHandel->getCurrentPageContect();
calendar->setExamsSchedule(page);
qDebug() << Q_FUNC_INFO << "exams schedule is loaded";
statusBar->setIconConnectionStatus(jceStatusBar::Done);
}
else if (status == jceLogin::JCE_NOT_CONNECTED)
{
qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
}
else
qCritical() << Q_FUNC_INFO << "exams request get ended with" << status;
2014-10-12 02:52:07 +00:00
}
2014-10-12 22:43:08 +00:00
else if (status == jceLogin::JCE_NOT_CONNECTED)
2014-10-12 02:52:07 +00:00
{
2014-10-12 22:43:08 +00:00
qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
2014-10-12 02:52:07 +00:00
}
2014-10-12 22:43:08 +00:00
else
qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
}
}
2014-10-12 22:43:08 +00:00
unlock();
2014-10-12 02:52:07 +00:00
}
2014-06-18 23:44:46 +00:00
}
2014-09-09 08:20:58 +00:00
void MainScreen::on_exportToCVSBtn_clicked()
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (loginHandel->isLoggedInFlag())
{
2014-10-12 22:43:08 +00:00
this->calendar->exportCalendarCSV();
}
2014-06-18 23:44:46 +00:00
}
2014-10-13 23:45:11 +00:00
//MAIN SCREEN
void MainScreen::on_labelMadeBy_linkActivated(const QString &link)
{
qDebug() << Q_FUNC_INFO << "link: " << link;
}
/**
* @brief MainScreen::lock
* turn isblocked into true to avoid multiple requests and to cause errors
*/
void MainScreen::lock()
{
QApplication::setOverrideCursor(Qt::WaitCursor);
this->isBlocked = true;
}
void MainScreen::unlock()
{
QApplication::restoreOverrideCursor();
this->isBlocked = false;
}
bool MainScreen::isBusy()
{
return this->isBlocked;
}
void MainScreen::on_langButton_clicked()
{
qDebug() << Q_FUNC_INFO;
if (data->getLocale() == "en")
{
qDebug() << Q_FUNC_INFO << "Changed lang to he";
data->setLocale("he");
}else if(data->getLocale() == "he"){
qDebug() << Q_FUNC_INFO << "Changed lang to en";
data->setLocale("en");
}else{
qCritical() << Q_FUNC_INFO << "currupted data. reset to en";
data->reset();
data->setLocale("en");
}
checkLocale();
QMessageBox::information(this,tr("Settings"),tr("Your settings will take effect next time you start the program"),QMessageBox::Ok);
}
void MainScreen::on_creditButton_clicked()
2014-06-18 23:44:46 +00:00
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO;
QMessageBox::about(this, "About",
2014-10-16 08:15:23 +00:00
"<a href='http://liranbg.github.io/JceManager/'>Jce Manager</a> "
+ QString("Version: " + QString(VERSION)) +"<br><br>"
+tr("License: ")+ "LGPL v2.1<br>"
"<br><a href='https://github.com/liranbg/JceManager'>JceManager Repository</a>"
+"<br><br>" + tr("Developed By: ")+
"<ul>"+
"<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran Ben Gida")+"</a></li>"+
"<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi Dayan")+"</a></li></ul>"
2014-10-12 22:43:08 +00:00
);
2014-06-18 23:44:46 +00:00
}
2014-10-13 23:45:11 +00:00
void MainScreen::on_howtoButton_clicked()
2014-06-22 12:43:31 +00:00
{
2014-10-12 22:43:08 +00:00
qDebug() << Q_FUNC_INFO;
QMessageBox::information(this,"How To",
"<b>"
+tr("Help Guide")+
"</b><ul>"
+tr("<br><li>Login: <ul><li>Type your username and password and click Login.</li><li>Once you are connected, you will see a green ball in the right buttom panel.</li></ul></li>")
+tr("<br><li>Getting GPA sheet<ul><li>Click on GPA Tab</li><li> Select your dates and click on Add</li></ul></li>")
+tr("<br><li>Average Changing<ul><li>Change one of your grade and see the average in the buttom panel changing.</li></ul></li>")
+tr("<br><li>Getting Calendar<ul><li>Click on Calendar Tab</li><li> Select your dates and click on Get Calendar</li></ul></li>")
+tr("<br><li>For exporting your calendar to a .CSV file:<ul><li>Do previous step and continue to next step</li><li> Click on Export to CSV</li><li>Select your dates and click OK</li><li>Once you're Done, go on your calendar and import your csv file</li></li>")+
"<br><br>"
+tr("<b>For more information, please visit us at: <a href='http://liranbg.github.io/JceManager/'>Jce Manager site</a></b>"));
2014-06-22 12:43:31 +00:00
}
2014-10-13 23:45:11 +00:00
2014-09-09 08:20:58 +00:00
void MainScreen::checkLocale()
{
2014-10-13 23:45:11 +00:00
qDebug() << Q_FUNC_INFO;
if (data->getLocale() == "en")
2014-09-09 08:20:58 +00:00
{
2014-10-13 23:45:11 +00:00
ui->langButton->setIcon(QIcon(":/icons/us.png"));
}else if(data->getLocale() == "he"){
ui->langButton->setIcon(QIcon(":/icons/il.png"));
2014-09-09 08:20:58 +00:00
}else{
2014-10-13 23:45:11 +00:00
qCritical() << Q_FUNC_INFO << "currupted data. reset eng";
data->reset();
ui->langButton->setIcon(QIcon(":/icons/us.png"));
2014-10-13 23:45:11 +00:00
}
}