jce-manager/main/mainscreen.cpp

269 lines
7.8 KiB
C++
Raw Normal View History

2014-06-14 17:02:50 +00:00
#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
2014-06-14 17:02:50 +00:00
ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
//Status Bar
2014-06-14 17:02:50 +00:00
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));
2014-06-14 17:02:50 +00:00
//Pointer allocating
2014-06-14 17:02:50 +00:00
this->jceLog = NULL;
this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
2014-06-14 17:02:50 +00:00
updateDates();
}
MainScreen::~MainScreen()
{
delete userLoginSetting;
delete jceLog;
delete ui;
}
void MainScreen::on_ratesButton_clicked()
{
QTextEdit phrase;
std::string pageString;
if (this->jceLog != NULL)
{
if (jceLog->getGrades())
{
phrase.setText(QString::fromStdString(jceLog->getPage()));
pageString = phrase.toPlainText().toStdString();
courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable();
}
}
}
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");
2014-06-14 17:02:50 +00:00
}
void MainScreen::on_loginButton_clicked()
{
if (this->jceLog == NULL)
uiSetConnectMode();
else
{
if (jceLog->isLoginFlag() == true)
uiSetDisconnectMode();
else
uiSetConnectMode();
}
}
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);
delete jceLog;
jceLog = NULL;
ui->loginButton->setText("&Login");
this->ui->ratesButton->setDisabled(true);
return;
}
void MainScreen::uiSetConnectMode()
{
2014-06-18 18:42:46 +00:00
std::string page;
2014-06-17 14:09:51 +00:00
if (this->jceLog != NULL)
delete jceLog;
2014-06-14 17:02:50 +00:00
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);
2014-06-14 17:02:50 +00:00
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->repaint();
2014-06-18 18:42:46 +00:00
page = "connecting with username ";
page = username;
page += "and password: ";
page += password;
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
2014-06-14 17:02:50 +00:00
jceLog = new jceLogin(userLoginSetting);
this->loginHandel = new loginHandler(jceLog,statusLabel,ui->pswdLineEdit,ui->usrnmLineEdit);
if (loginHandel->makeConnection() == true)
{
2014-06-18 18:42:46 +00:00
page = this->jceLog->getPage();
ui->textEdit->setText(ui->textEdit->toPlainText() + QString::fromStdString(page));
2014-06-14 17:02:50 +00:00
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()
{
2014-06-15 16:53:20 +00:00
QMessageBox::about(this, "About", "A tiny application to calculate your grades average. <br><br>"
"This software is licensed under Qt5's <br>GNU LESSER GENERAL PUBLIC LICENSE V2<br>"
"The source code is available at github:<br>"
"<a href='https://github.com/liranbg/jceAverageCalculator'>jceAverageCalculator Repository</a>"
"<br><br>This front end is Powered by <a href='https://github.com/liranbg/jceConnection'>Jce Connection</a><br><br>"
"Made by:"
"<ul>"
"<li><a href='mailto:liranbg@gmail.com'>Liran Ben Gida</a></li>"
"</ul>"
"Thanks to: "
"<ul>"
"<li><a href='mailto:sagidayan@gmail.com'>Sagi Dayan</a></li>"
"<li><a href='mailto:nadav2051@gmail.com'>Nadav Luzzato</a></li>"
"</ul>");
2014-06-14 17:02:50 +00:00
}
void MainScreen::on_clearTableButton_clicked()
{
courseTableMgr->clearTable();
ui->avgLCD->display(courseTableMgr->getAvg());
}
void MainScreen::on_actionExit_triggered()
{
exit(0);
}