295 lines
10 KiB
C++
295 lines
10 KiB
C++
#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;
|
|
}
|
|
void MainScreen::on_loginButton_clicked()
|
|
{
|
|
if (loginHandel->isLoggedInFlag())
|
|
uiSetDisconnectMode();
|
|
|
|
else
|
|
uiSetConnectMode();
|
|
|
|
}
|
|
|
|
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_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_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_checkBox_toggled(bool checked)
|
|
{
|
|
this->userLoginSetting->setInfluenceCourseOnly(checked);
|
|
this->courseTableMgr->influnceCourseChanged(checked);
|
|
}
|
|
void MainScreen::on_usrnmLineEdit_editingFinished()
|
|
{
|
|
ui->usrnmLineEdit->setText(ui->usrnmLineEdit->text().toLower());
|
|
}
|
|
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(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();
|
|
}
|
|
void MainScreen::on_actionCredits_triggered()
|
|
{
|
|
QMessageBox::about(this, "About", tr("CREDITS-ROOL-UP1") + " v1.0<br><br>"
|
|
+ tr("CREDITS-ROOL-UP2")+"<br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>"
|
|
+ tr("CREDITS-ROOL-UP3")+"<br>"
|
|
"<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>"
|
|
"<br><br>"+tr("CREDITS-ROOL-UP4")+"<a href='https://github.com/liranbg/jceConnection'> Jce Connection</a><br><br>"
|
|
+tr("DevBy")+":"
|
|
"<ul>"
|
|
"<li><a href='mailto:liranbg@gmail.com'>"+tr("Liran")+"</a></li>"
|
|
"<li><a href='mailto:sagidayan@gmail.com'>"+tr("Sagi")+"</a></li>"
|
|
"</ul>"
|
|
+tr("Tnks")+ "... :"
|
|
"<ul>"
|
|
"<li><a href='mailto:nadav2051@gmail.com'>"+tr("Nadav")+"</a></li>"
|
|
"</ul>");
|
|
}
|
|
|
|
void MainScreen::on_clearTableButton_clicked()
|
|
{
|
|
|
|
courseTableMgr->clearTable();
|
|
ui->avgLCD->display(courseTableMgr->getAvg());
|
|
}
|
|
|
|
void MainScreen::on_actionExit_triggered()
|
|
{
|
|
exit(0);
|
|
}
|
|
|
|
|
|
void MainScreen::on_keepLogin_clicked()
|
|
{
|
|
if (ui->keepLogin->isChecked())
|
|
SaveData::save(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text());
|
|
|
|
else
|
|
SaveData::deleteData();
|
|
}
|
|
|
|
void MainScreen::on_actionHow_To_triggered()
|
|
{
|
|
QMessageBox::information(this,"How To",
|
|
"<b>How To..</b>"
|
|
"<ul>"
|
|
"<br><li>Insert your username and password correctly</li>"
|
|
"<br><li>Login and wait for the ball in the status (buttom) bar to become Green</li>"
|
|
"<br><li>Check <b>Settings</b> to select your date Interval</li>"
|
|
"<br><li>Press <b>Courses</b> tab and then press <u>Add</u> button and wait until courses will be loaded into the table</li>"
|
|
"<br><li>Change the once of the grade cell and see your average is changing. </li>"
|
|
"<br><br>Tip: Need to change Date interval? in Courses tab click <u>Clean</u>, then change the date interval then hit <u>Add</u> again! :-)"
|
|
"</ul>"
|
|
"<br><br><b>הסבר</b>"
|
|
"<ul>"
|
|
"<br><li>הכנס את שם המשתמש והסיסמה שלך כנדרש</li>"
|
|
"<br><li>לחץ התחבר והמתן מספר שניות עד להופעת כדור ירוק בתחתית המסך</li>"
|
|
"<br><li>בדוק <b>הגדרות</b> כדי לבדוק את תקופת הזמן אותם תרצה להציג</li>"
|
|
"<br><li> לחץ על <b>Courses</b> ולאחר מכן על כפתור <u>Add</u> והמתן מספר שניות עד להופעת הקורסים בטבלה</li>"
|
|
"<br><li>כעת ניתן לשנות ערכים בתא הציונים ולראות את ממוצע הציונים בהתאם </li>"
|
|
"<br><br>טיפ: רוצה לשנות את תקופת הזמן? לחץ על <u>Clean</u> , ולאחר מכן שנה את תקופת הזמן ולחץ על <u>Add</u> שוב! :-)"
|
|
" </ul>");
|
|
|
|
}
|