#include "mainscreen.h" #include "ui_mainscreen.h" MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen) { ui->setupUi(this); this->setFixedSize(this->size()); //main not resizeable //Login Tab ui->pswdLineEdit->setEchoMode((QLineEdit::Password)); //Status Bar ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };"); ButtomStatusLabel = new QLabel(this); statusLabel = new QLabel(this); ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight); ui->statusBar->addPermanentWidget(ButtomStatusLabel,0); ui->statusBar->addPermanentWidget(statusLabel,1); setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED); //Course and Setting Tab ui->CoursesTab->setDisabled(true); ui->SettingsTab->setDisabled(true); ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue)); //Pointer allocating this->userLoginSetting = new user("",""); this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting); this->loginHandel = new loginHandler(userLoginSetting); updateDates(); //check login File SaveData::init(); if (SaveData::isSaved()) { ui->usrnmLineEdit->setText(SaveData::getUsername()); ui->pswdLineEdit->setText(SaveData::getPassword()); ui->keepLogin->setChecked(true); } } MainScreen::~MainScreen() { delete userLoginSetting; delete loginHandel; delete ui; } /*** LOGIN TAB FUNCTIONS ***/ void MainScreen::on_loginButton_clicked() { if (loginHandel->isLoggedInFlag()) uiSetDisconnectMode(); else uiSetConnectMode(); } void MainScreen::on_usrnmLineEdit_editingFinished() { ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower()); } void MainScreen::on_keepLogin_clicked() { if (ui->keepLogin->isChecked()) SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()); else SaveData::deleteData(); } /*** COURSES TAB FUNCTIONS ***/ void MainScreen::on_ratesButton_clicked() { std::string pageString; int status = 0; if (loginHandel->isLoggedInFlag()) { if ((status = loginHandel->makeGradeRequest()) == jceLogin::JCE_GRADE_PAGE_PASSED) { pageString = loginHandel->getCurrentPageContect().toStdString(); courseTableMgr->setCoursesList(pageString); courseTableMgr->insertJceCoursesIntoTable(); } else if (status == jceLogin::JCE_NOT_CONNECTED) { QMessageBox::critical(this,tr("Error"),tr("Not Connected")); } } } void MainScreen::on_coursesTable_itemChanged(QTableWidgetItem *item) { if (this->courseTableMgr->changes(item->text(),item->row(),item->column())) ui->avgLCD->display(courseTableMgr->getAvg()); else QMessageBox::critical(this,"Error","Missmatching data"); } void MainScreen::on_clearTableButton_clicked() { courseTableMgr->clearTable(); ui->avgLCD->display(courseTableMgr->getAvg()); } /*** SETTING TAB FUNCTIONS ***/ void MainScreen::on_spinBoxFromYear_editingFinished() { if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) { ui->spinBoxFromYear->setValue(ui->spinBoxToYear->value()); ui->spinBoxFromYear->setFocus(); updateDates(); } else updateDates(); } void MainScreen::on_spinBoxToYear_editingFinished() { if (ui->spinBoxFromYear->value() > ui->spinBoxToYear->value()) { ui->spinBoxToYear->setValue(ui->spinBoxFromYear->value()); ui->spinBoxToYear->setFocus(); updateDates(); } else updateDates(); } void MainScreen::on_spinBoxFromSem_editingFinished() { if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) { if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) { ui->spinBoxFromSem->setValue(ui->spinBoxToSemester->value()); ui->spinBoxFromSem->setFocus(); } } updateDates(); } void MainScreen::on_spinBoxToSemester_editingFinished() { if (ui->spinBoxFromYear->value() == ui->spinBoxToYear->value()) { if (ui->spinBoxFromSem->value() > ui->spinBoxToSemester->value()) { ui->spinBoxToSemester->setValue(ui->spinBoxFromSem->value()); ui->spinBoxToSemester->setFocus(); } } updateDates(); } void MainScreen::on_checkBox_toggled(bool checked) { this->userLoginSetting->setInfluenceCourseOnly(checked); this->courseTableMgr->influnceCourseChanged(checked); } /* * ------------------------------ * */ void MainScreen::updateDates() { std::string fy,ty,fs,ts; fy = std::to_string(ui->spinBoxFromYear->value()); ty = std::to_string(ui->spinBoxToYear->value()); fs = std::to_string(ui->spinBoxFromSem->value()); ts = std::to_string(ui->spinBoxToSemester->value()); userLoginSetting->setDate(fy,fs,ty,ts); } 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("&Login"); this->ui->ratesButton->setDisabled(true); return; } void MainScreen::uiSetConnectMode() //fix before distrbute { string username; string password; if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty())) { //add icon near to username and password to mark it return; } setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS); username = ui->usrnmLineEdit->text().toStdString(); password = ui->pswdLineEdit->text().toStdString(); 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("&Logout"); this->ui->ratesButton->setEnabled(true); ui->CoursesTab->setEnabled(true); ui->SettingsTab->setEnabled(true); } else { uiSetDisconnectMode(); } } void MainScreen::setLabelConnectionStatus(jceLogin::jceStatus statusDescription) { QPixmap iconPix; switch (statusDescription) { case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS: iconPix.load(":/icons/blueStatusIcon.png"); statusLabel->setText("Connecting"); break; case jceLogin::jceStatus::JCE_YOU_ARE_IN: iconPix.load(":/icons/greenStatusIcon.png"); statusLabel->setText("Connected"); break; default: iconPix.load(":/icons/redStatusIcon.png"); statusLabel->setText("Disconnected"); break; } ButtomStatusLabel->setPixmap(iconPix); this->repaint(); } void MainScreen::on_actionCredits_triggered() { QMessageBox::about(this, "About", "A tiny Application to calculate your grades average. v1.0

" "This software is licensed under Qt5's
GNU LESSER GENERAL PUBLIC LICENSE V2
" "The source code is available at github:
" "jceAverageCalculator Repository" "

This front end is Powered by Jce Connection

" "Developed by: " "" "Thanks to: " ""); } void MainScreen::on_actionExit_triggered() { exit(0); } void MainScreen::on_actionHow_To_triggered() { QMessageBox::information(this,"How To", "How To.." "" "

הסבר" ""); }