diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 05cbe62..8529604 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -4,397 +4,424 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen) { - ui->setupUi(this); + 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); - //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); + //StatusBar + statusBar = new jceStatusBar(this); + this->setStatusBar(statusBar); - //StatusBar - statusBar = new jceStatusBar(this); - this->setStatusBar(statusBar); + //GPA Tab + ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); - //GPA Tab - ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); + //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(); - //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(); - - //check login File - if (data->isSaved()) + //check login File + if (data->isSaved()) { - qDebug() << Q_FUNC_INFO << "Loading data from file"; - ui->usrnmLineEdit->setText(data->getUsername()); - ui->pswdLineEdit->setText(data->getPassword()); - ui->keepLogin->setChecked(true); + qDebug() << Q_FUNC_INFO << "Loading data from file"; + ui->usrnmLineEdit->setText(data->getUsername()); + ui->pswdLineEdit->setText(data->getPassword()); + ui->keepLogin->setChecked(true); } - //language - qDebug() << Q_FUNC_INFO << "Checking locale"; - checkLocale(); - qDebug() << Q_FUNC_INFO << "Ready."; + //language + qDebug() << Q_FUNC_INFO << "Checking locale"; + checkLocale(); + qDebug() << Q_FUNC_INFO << "Ready."; } MainScreen::~MainScreen() { - delete calendar; - delete courseTableMgr; - delete userLoginSetting; - delete loginHandel; - delete data; - delete ui; + delete calendar; + delete courseTableMgr; + delete userLoginSetting; + delete loginHandel; + delete data; + delete ui; } //EVENTS ON LOGIN TAB void MainScreen::on_loginButton_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) + if (!isBusy()) { - if (ui->usrnmLineEdit->text().isEmpty()) + lock(); + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) { - ui->labelUsrInputStatus->setVisible(true); - qDebug() << Q_FUNC_INFO << "username input is empty"; + 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 - ui->labelUsrInputStatus->setVisible(false); - if (ui->pswdLineEdit->text().isEmpty()) + else { - ui->labelPswInputStatus->setVisible(true); - qDebug() << Q_FUNC_INFO << "password input is empty"; + ui->labelUsrInputStatus->setVisible(false); + ui->labelPswInputStatus->setVisible(false); } - else - ui->labelPswInputStatus->setVisible(false); - return; - } - else - { - ui->labelUsrInputStatus->setVisible(false); - ui->labelPswInputStatus->setVisible(false); - } - qDebug() << Q_FUNC_INFO << "login session start"; - QApplication::setOverrideCursor(Qt::WaitCursor); - 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 << "login session start"; + if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true) { - qDebug() << Q_FUNC_INFO << "saving data"; - data->setUsername(ui->usrnmLineEdit->text()); - data->setPassword(ui->pswdLineEdit->text()); + 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 - { - qDebug() << Q_FUNC_INFO << "login session end with false"; - ui->pswdLineEdit->setDisabled(false); - ui->usrnmLineEdit->setDisabled(false); + else + { + qDebug() << Q_FUNC_INFO << "login session end with false"; + ui->pswdLineEdit->setDisabled(false); + ui->usrnmLineEdit->setDisabled(false); + } + unlock(); } - QApplication::restoreOverrideCursor(); + + } void MainScreen::on_keepLogin_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if (ui->keepLogin->isChecked()) + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if (ui->keepLogin->isChecked()) { - qDebug() << Q_FUNC_INFO << "saving data"; - data->setUsername(ui->usrnmLineEdit->text()); - data->setPassword(ui->pswdLineEdit->text()); + qDebug() << Q_FUNC_INFO << "saving data"; + data->setUsername(ui->usrnmLineEdit->text()); + data->setPassword(ui->pswdLineEdit->text()); } - else - data->reset(); + else + data->reset(); } void MainScreen::on_usrnmLineEdit_editingFinished() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); } //EVENTS ON GPA TAB void MainScreen::on_ratesButton_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if (!checkIfValidDates()) + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if (!isBusy()) { - qWarning() << Q_FUNC_INFO << "Invalid dates! return"; - QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again")); - return; + lock(); + if (!checkIfValidDates()) + { + qWarning() << Q_FUNC_INFO << "Invalid dates! return"; + QMessageBox::critical(this,tr("Error"),tr("Invalid Dates.\nMake Sure everything is correct and try again")); + return; + } + QString pageString; + int status = 0; + if (loginHandel->isLoggedInFlag()) + { + 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); + courseTableMgr->insertJceCoursesIntoTable(); + 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 + { + statusBar->setIconConnectionStatus(jceStatusBar::ERROR); + qCritical() << Q_FUNC_INFO << "grade get ended with" << status; + } + } + unlock(); } - QString pageString; - int status = 0; - QApplication::setOverrideCursor(Qt::WaitCursor); - if (loginHandel->isLoggedInFlag()) - { - 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); - courseTableMgr->insertJceCoursesIntoTable(); - 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 - { - statusBar->setIconConnectionStatus(jceStatusBar::ERROR); - qCritical() << Q_FUNC_INFO << "grade get ended with" << status; - } - } - QApplication::restoreOverrideCursor(); } bool MainScreen::checkIfValidDates() { - bool flag = false; - if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value()) + bool flag = false; + if (ui->spinBoxCoursesFromYear->value() < ui->spinBoxCoursesToYear->value()) { - //doesnt matter what is the semester, its valid! - flag = true; - } - else if ((ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value())) - { - //semester from must be equal or less than to semester - if (ui->spinBoxCoursesFromSemester->value() <= ui->spinBoxCoursesToSemester->value()) + //doesnt matter what is the semester, its valid! flag = true; } - return flag; + else if ((ui->spinBoxCoursesFromYear->value() == ui->spinBoxCoursesToYear->value())) + { + //semester from must be equal or less than to semester + if (ui->spinBoxCoursesFromSemester->value() <= ui->spinBoxCoursesToSemester->value()) + flag = true; + } + return flag; } void MainScreen::on_checkBoxCoursesInfluence_toggled(bool checked) { - qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked; - this->userLoginSetting->setInfluenceCourseOnly(checked); - this->courseTableMgr->influnceCourseChanged(checked); + qDebug() << Q_FUNC_INFO << "only main courses toggeled" << checked; + this->userLoginSetting->setInfluenceCourseOnly(checked); + this->courseTableMgr->influnceCourseChanged(checked); } void MainScreen::on_spinBoxCoursesFromYear_valueChanged(int arg1) { - ui->spinBoxCoursesFromYear->setValue(arg1); + ui->spinBoxCoursesFromYear->setValue(arg1); } void MainScreen::on_spinBoxCoursesToYear_valueChanged(int arg1) { - ui->spinBoxCoursesToYear->setValue(arg1); + ui->spinBoxCoursesToYear->setValue(arg1); } void MainScreen::on_spinBoxCoursesFromSemester_valueChanged(int arg1) { - ui->spinBoxCoursesFromSemester->setValue(arg1%4); + ui->spinBoxCoursesFromSemester->setValue(arg1%4); } void MainScreen::on_spinBoxCoursesToSemester_valueChanged(int arg1) { - ui->spinBoxCoursesToSemester->setValue(arg1%4); + ui->spinBoxCoursesToSemester->setValue(arg1%4); } void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) { - if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) - ui->avgLCD->display(courseTableMgr->getAvg()); - else + if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) + ui->avgLCD->display(courseTableMgr->getAvg()); + else { - qWarning() << Q_FUNC_INFO << "missmatch data"; - QMessageBox::critical(this,tr("Error"),tr("Missmatching data")); + qWarning() << Q_FUNC_INFO << "missmatch data"; + QMessageBox::critical(this,tr("Error"),tr("Missmatching data")); } } void MainScreen::on_clearTableButton_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - courseTableMgr->clearTable(); - ui->avgLCD->display(courseTableMgr->getAvg()); + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + courseTableMgr->clearTable(); + ui->avgLCD->display(courseTableMgr->getAvg()); } void MainScreen::on_graphButton_clicked() { - qDebug() << Q_FUNC_INFO; - courseTableMgr->showGraph(); + qDebug() << Q_FUNC_INFO; + courseTableMgr->showGraph(); } //EVENTS ON CALENDAR TAB void MainScreen::on_examsBtn_clicked() { - calendar->showExamDialog(); - + calendar->showExamDialog(); } void MainScreen::on_getCalendarBtn_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - int status = 0; - QString page; - QApplication::setOverrideCursor(Qt::WaitCursor); - if (loginHandel->isLoggedInFlag()) + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if (!isBusy()) { - if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED) + lock(); + int status = 0; + QString page; + if (loginHandel->isLoggedInFlag()) { - statusBar->setIconConnectionStatus(jceStatusBar::Inserting); - calendar->resetTable(); - page = loginHandel->getCurrentPageContect(); - calendar->setCalendar(page); - - qDebug() << Q_FUNC_INFO << "calendar is loaded"; - - //auto getting exam - if (loginHandel->isLoggedInFlag()) + if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED) { - if ((status = loginHandel->makeExamsScheduleRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED) + statusBar->setIconConnectionStatus(jceStatusBar::Inserting); + calendar->resetTable(); + page = loginHandel->getCurrentPageContect(); + calendar->setCalendar(page); + + qDebug() << Q_FUNC_INFO << "calendar is loaded"; + + //auto getting exam + if (loginHandel->isLoggedInFlag()) { - page = loginHandel->getCurrentPageContect(); - calendar->setExamsSchedule(page); - qDebug() << Q_FUNC_INFO << "exams schedule is loaded"; - statusBar->setIconConnectionStatus(jceStatusBar::Done); + 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; } - else if (status == jceLogin::JCE_NOT_CONNECTED) + 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); + 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; + else + qCritical() << Q_FUNC_INFO << "calendar get ended with" << status; } - 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 << "calendar get ended with" << status; } + unlock(); } - QApplication::restoreOverrideCursor(); } void MainScreen::on_exportToCVSBtn_clicked() { - qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); - if (loginHandel->isLoggedInFlag()) + qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName(); + if (loginHandel->isLoggedInFlag()) { - this->calendar->exportCalendarCSV(); + this->calendar->exportCalendarCSV(); } } //EVENTS ON MENU BAR void MainScreen::on_actionCredits_triggered() { - qDebug() << Q_FUNC_INFO; - QMessageBox::about(this, "About", - "Jce Manager v1.0.0

" - +tr("License:")+ - "
GNU LESSER GENERAL PUBLIC LICENSE V2.1
" - +"
"+ - "JceManager Repository"+ - "

" - +tr("Powered By: ")+ - " Jce Connection

" - +tr("Developed By")+ - ":" - ); + qDebug() << Q_FUNC_INFO; + QMessageBox::about(this, "About", + "Jce Manager v1.0.0

" + +tr("License:")+ + "
GNU LESSER GENERAL PUBLIC LICENSE V2.1
" + +"
"+ + "JceManager Repository"+ + "

" + +tr("Powered By: ")+ + " Jce Connection

" + +tr("Developed By")+ + ":" + ); } void MainScreen::on_actionExit_triggered() { - qDebug() << Q_FUNC_INFO; - exit(0); + qDebug() << Q_FUNC_INFO; + exit(0); } void MainScreen::on_actionHow_To_triggered() { - qDebug() << Q_FUNC_INFO; - QMessageBox::information(this,"How To", - "" - +tr("Help Guide")+ - "