jcestatusbar widget

This commit is contained in:
Liran BN 2014-10-12 22:19:43 +03:00
parent 7980382db7
commit 1032c32013
12 changed files with 217 additions and 150 deletions

View file

@ -58,7 +58,8 @@ HEADERS += \
src/jceData/Calendar/coursesSchedule/calendarDialog.h \
src/jceData/Calendar/coursesSchedule/calendarPage.h \
src/jceData/Calendar/coursesSchedule/calendarPageCourse.h \
src/jceData/Calendar/coursesSchedule/calendarSchedule.h
src/jceData/Calendar/coursesSchedule/calendarSchedule.h \
main/jceWidgets/jcestatusbar.h
SOURCES += \
main/CalendarTab/CalendarManager.cpp \
@ -84,4 +85,5 @@ SOURCES += \
src/jceData/Calendar/coursesSchedule/calendarDialog.cpp \
src/jceData/Calendar/coursesSchedule/calendarPage.cpp \
src/jceData/Calendar/coursesSchedule/calendarPageCourse.cpp \
src/jceData/Calendar/coursesSchedule/calendarSchedule.cpp
src/jceData/Calendar/coursesSchedule/calendarSchedule.cpp \
main/jceWidgets/jcestatusbar.cpp

View file

@ -1,24 +1,17 @@
#include "loginhandler.h"
loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr,QProgressBar *progressbarPtr): logggedInFlag(false)
loginHandler::loginHandler(user *ptr, QPushButton *loginButtonPtr, jceStatusBar *progressbarPtr): logggedInFlag(false)
{
this->loginButtonPtr = loginButtonPtr;
this->progressBar = progressbarPtr;
this->statusBar = progressbarPtr;
//statusBar
statusBar = statusBarPtr;
iconButtomStatusLabel = new QLabel(statusBarPtr);
iconButtomStatusLabel->setAlignment(Qt::AlignHCenter);
//display progressbar and then ball icon.
statusBar->addPermanentWidget(progressBar,0);
statusBar->addPermanentWidget(iconButtomStatusLabel,0);
setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
//user settings
userPtr = ptr;
this->jceLog = new jceLogin(userPtr,progressBar);
this->jceLog = new jceLogin(userPtr,statusBar);
QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost()));
}
@ -31,14 +24,14 @@ bool loginHandler::login(QString username,QString password)
logout();
return false;
}
setIconConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
statusBar->setIconConnectionStatus(jceStatusBar::Connecting);
userPtr->setUsername(username);
userPtr->setPassword(password);
if (makeConnection() == true)
{
setIconConnectionStatus(jceLogin::jceStatus::JCE_YOU_ARE_IN);
statusBar->setIconConnectionStatus(jceStatusBar::LoggedIn);
loginButtonPtr->setText(QObject::tr("Logout"));
return isLoggedInFlag();
}
@ -52,7 +45,7 @@ bool loginHandler::login(QString username,QString password)
void loginHandler::logout()
{
loginButtonPtr->setText(QObject::tr("Login"));
setIconConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
statusBar->setIconConnectionStatus(jceStatusBar::Disconnected);
jceLog->closeAll();
logggedInFlag = false;
}
@ -154,32 +147,7 @@ int loginHandler::makeExamsScheduleRequest(int year, int semester)
else
return jceLogin::JCE_NOT_CONNECTED;
}
void loginHandler::setIconConnectionStatus(jceLogin::jceStatus statusDescription)
{
QPixmap iconPix;
switch (statusDescription)
{
case jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS:
iconPix.load(":/icons/blueStatusIcon.png");
statusBar->showMessage(tr("Connecting..."));
break;
case jceLogin::jceStatus::JCE_YOU_ARE_IN:
iconPix.load(":/icons/greenStatusIcon.png");
statusBar->showMessage(tr("Connected"));
break;
case jceLogin::jceStatus::JCE_NOT_CONNECTED:
iconPix.load(":/icons/redStatusIcon.png");
statusBar->showMessage(tr("Disconnected"));
break;
default:
iconPix.load(":/icons/redStatusIcon.png");
statusBar->showMessage(tr("Ready."));
break;
}
iconButtomStatusLabel->setPixmap(iconPix);
this->statusBar->repaint();
}
void loginHandler::popMessage(QString message,bool addInfo)
{
if (addInfo)

View file

@ -6,28 +6,25 @@
#include <QLabel>
#include <QMessageBox>
#include <QPixmap>
#include <QStatusBar>
#include <QProgressBar>
#include <QPushButton>
#include "./src/jceSettings/jcelogin.h"
#include "./src/appDatabase/savedata.h"
#include "./main/jceWidgets/jcestatusbar.h"
class loginHandler : public QObject
{
Q_OBJECT
public:
loginHandler(user *ptr, QStatusBar *statusBarPtr, QPushButton *loginButtonPtr, QProgressBar *progressbarPtr);
loginHandler(user *ptr, QPushButton *loginButtonPtr, jceStatusBar *progressbarPtr);
~loginHandler()
{
delete iconButtomStatusLabel;
delete jceLog;
}
bool login(QString username,QString password);
void logout();
void setIconConnectionStatus(jceLogin::jceStatus statusDescription);
bool makeConnection();
@ -50,10 +47,9 @@ private:
jceLogin * jceLog;
user * userPtr;
QStatusBar *statusBar;
QLabel *iconButtomStatusLabel;
jceStatusBar *statusBar;
QPushButton *loginButtonPtr;
QProgressBar *progressBar;
};

View file

@ -0,0 +1,118 @@
#include "jcestatusbar.h"
jceStatusBar::jceStatusBar(QWidget *parent) :
QStatusBar(parent)
{
this->setStyleSheet("QStatusBar::item { border: 0px solid black };");
this->setFixedHeight(STATUS_ICON_HEIGH+5);
this->showMessage(tr("Ready"));
//Icon
iconButtomStatusLabel = new QLabel(this);
iconButtomStatusLabel->setAlignment(Qt::AlignHCenter);
//ProgressBar
progressBar = new QProgressBar(this);
connect(progressBar,SIGNAL(valueChanged(int)),this,SLOT(setProgressValue(int)));
connect(this,SIGNAL(progressHasPacket(int)),this,SLOT(addValueToProgressBar(int)));
progressBar->setFixedWidth(120);
progressBar->setFixedHeight(STATUS_ICON_HEIGH);
progressBar->setStyleSheet("#progressBar::horizontal {"
"border: 1px solid gray;"
"border-radius: 3px;"
"background: transparent;"
"padding: 1px;"
"}"
"#progressBar::chunk:horizontal {"
"background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 green, stop: 1 white);"
"}");
progressBar->setRange(0,100);
progressBar->setValue(0);
progressBar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
progressBar->setTextVisible(true);
progressBar->setFormat("%p%");
addPermanentWidget(progressBar,0);
addPermanentWidget(iconButtomStatusLabel,0);
}
void jceStatusBar::setIconConnectionStatus(jceProgressStatus update)
{
QPixmap iconPix;
switch (update)
{
case jceProgressStatus::Disconnected:
iconPix.load(":/icons/redStatusIcon.png");
showMessage(tr("Disconnected"));
break;
case jceProgressStatus::Ready:
iconPix.load(":/icons/redStatusIcon.png");
showMessage(tr("Ready."));
break;
case jceProgressStatus::Connecting:
iconPix.load(":/icons/blueStatusIcon.png");
showMessage(tr("Connecting..."));
break;
case jceProgressStatus::Sending:
iconPix.load(":/icons/blueStatusIcon.png");
showMessage(tr("Sending."));
break;
case jceProgressStatus::Recieving:
iconPix.load(":/icons/blueStatusIcon.png");
showMessage(tr("Recieving."));
break;
case jceProgressStatus::Inserting:
iconPix.load(":/icons/blueStatusIcon.png");
showMessage(tr("Inserting."));
break;
case jceProgressStatus::LoggedIn:
setProgressValue(100);
iconPix.load(":/icons/greenStatusIcon.png");
showMessage(tr("LoggedIn."));
break;
case jceProgressStatus::Done:
setProgressValue(100);
iconPix.load(":/icons/greenStatusIcon.png");
showMessage(tr("Done."));
break;
case jceProgressStatus::Connected:
setProgressValue(100);
iconPix.load(":/icons/greenStatusIcon.png");
showMessage(tr("Connected"));
break;
}
iconButtomStatusLabel->setPixmap(iconPix);
repaint();
}
/**
* @brief Every time the value changes this method will be called
* @param value = the value of the progress Bar
*/
void jceStatusBar::setProgressValue(int value)
{
if (value == 0)
{
progressBar->setVisible(false);
progressBar->setValue(0);
}
else
{
progressBar->setValue(value);
progressBar->setVisible(true);
}
}
void jceStatusBar::addValueToProgressBar(int value)
{
progressBar->setValue(progressBar->value() + value);
}

View file

@ -0,0 +1,51 @@
#ifndef JCESTATUSBAR_H
#define JCESTATUSBAR_H
#include <QStatusBar>
#include <QProgressBar>
#include <QLabel>
#define STATUS_ICON_HEIGH 35
class jceStatusBar : public QStatusBar
{
Q_OBJECT
public:
enum jceProgressStatus
{
Ready,
Disconnected,
Connecting,
Connected,
LoggedIn,
Sending,
Recieving,
Inserting,
Done
};
jceStatusBar(QWidget *parent = 0);
void setIconConnectionStatus(jceProgressStatus update);
signals:
void progressHasPacket(int num);
public slots:
void setProgressValue(int val);
private slots:
void addValueToProgressBar(int value);
private:
QProgressBar * progressBar;
QLabel *iconButtomStatusLabel;
};
#endif // JCESTATUSBAR_H

View file

@ -6,6 +6,8 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSc
{
ui->setupUi(this);
ui->labelMadeBy->setOpenExternalLinks(true);
//Login Tab
@ -16,12 +18,9 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSc
ui->labelUsrInputStatus->setPixmap(iconPix);
ui->labelPswInputStatus->setPixmap(iconPix);
//StatusBar & progressbar
ui->progressBar->setFixedHeight(STATUS_ICON_HEIGH);
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ui->statusBar->setFixedHeight(STATUS_ICON_HEIGH+5);
ui->statusBar->showMessage(tr("Ready"));
//StatusBar
statusBar = new jceStatusBar(this);
this->setStatusBar(statusBar);
//GPA Tab
ui->avgLCD->setPalette(QPalette(QPalette::WindowText,Qt::blue));
@ -30,7 +29,7 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSc
qDebug() << Q_FUNC_INFO << "Allocating pointers";
this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar);
this->loginHandel = new loginHandler(userLoginSetting, ui->loginButton, statusBar);
this->calendar = new CalendarManager(this,ui->calendarGridLayoutMain);
this->data = new SaveData();
@ -46,12 +45,8 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSc
//language
qDebug() << Q_FUNC_INFO << "Checking locale";
checkLocale();
ui->statusBar->repaint();
qDebug() << Q_FUNC_INFO << "Ready.";
//set the progress bar to be invisible (It will show only if value !=0 or !=100)
ui->progressBar->setVisible(false);
}
MainScreen::~MainScreen()
{
@ -66,7 +61,6 @@ MainScreen::~MainScreen()
//EVENTS ON LOGIN TAB
void MainScreen::on_loginButton_clicked()
{
ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
{
@ -95,7 +89,6 @@ void MainScreen::on_loginButton_clicked()
QApplication::setOverrideCursor(Qt::WaitCursor);
if (this->loginHandel->login(ui->usrnmLineEdit->text(),ui->pswdLineEdit->text()) == true)
{
ui->progressBar->setValue(100);
qDebug() << Q_FUNC_INFO << "login session end with true";
ui->pswdLineEdit->setDisabled(true);
ui->usrnmLineEdit->setDisabled(true);
@ -137,7 +130,7 @@ void MainScreen::on_usrnmLineEdit_editingFinished()
void MainScreen::on_ratesButton_clicked()
{
ui->progressBar->setValue(0);
// ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (!checkIfValidDates())
{
@ -150,18 +143,18 @@ void MainScreen::on_ratesButton_clicked()
QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag())
{
ui->statusBar->showMessage(tr("Getting grades..."));
// ui->statusBar->showMessage(tr("Getting grades..."));
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";
ui->statusBar->showMessage(tr("Done. Inserting data into table..."),1000);
// ui->statusBar->showMessage(tr("Done. Inserting data into table..."),1000);
pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable();
ui->progressBar->setValue(100);
ui->statusBar->showMessage(tr("Done"));
// ui->progressBar->setValue(100);
// ui->statusBar->showMessage(tr("Done"));
}
else if (status == jceLogin::JCE_NOT_CONNECTED)
{
@ -248,18 +241,18 @@ void MainScreen::on_examsBtn_clicked()
}
void MainScreen::on_getCalendarBtn_clicked()
{
ui->progressBar->setValue(0);
// ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
int status = 0;
QString page;
QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag())
{
ui->statusBar->showMessage(tr("Getting schedule..."));
// ui->statusBar->showMessage(tr("Getting schedule..."));
if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{
calendar->resetTable();
ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
// ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
page = loginHandel->getCurrentPageContect();
calendar->setCalendar(page);
@ -268,10 +261,10 @@ void MainScreen::on_getCalendarBtn_clicked()
//auto getting exam
if (loginHandel->isLoggedInFlag())
{
ui->statusBar->showMessage(tr("Getting exams..."));
// ui->statusBar->showMessage(tr("Getting exams..."));
if ((status = loginHandel->makeExamsScheduleRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{
ui->statusBar->showMessage(tr("Done."),1000);
// ui->statusBar->showMessage(tr("Done."),1000);
page = loginHandel->getCurrentPageContect();
calendar->setExamsSchedule(page);
qDebug() << Q_FUNC_INFO << "exams schedule is loaded";
@ -286,8 +279,8 @@ void MainScreen::on_getCalendarBtn_clicked()
qCritical() << Q_FUNC_INFO << "exams request get ended with" << status;
ui->progressBar->setValue(100);
ui->statusBar->showMessage(tr("Done"));
// ui->progressBar->setValue(100);
// ui->statusBar->showMessage(tr("Done"));
}
else if (status == jceLogin::JCE_NOT_CONNECTED)
{
@ -416,16 +409,4 @@ void MainScreen::on_labelMadeBy_linkActivated(const QString &link)
}
/**
* @brief Every time the value changes this method will be called
* @param value = the value of the progress Bar
*/
void MainScreen::on_progressBar_valueChanged(int value)
{
if(value == 0 || value == 100)
ui->progressBar->setVisible(false);
else
ui->progressBar->setVisible(true);
}

View file

@ -10,9 +10,10 @@
#include "./CourseTab/coursestablemanager.h"
#include "./LoginTab/loginhandler.h"
#include "./CalendarTab/CalendarManager.h"
#include "./jceWidgets/jceStatusBar.h"
#define STATUS_ICON_HEIGH 35
namespace Ui {
class MainScreen;
}
@ -58,7 +59,7 @@ private slots:
void on_spinBoxCoursesToYear_valueChanged(int arg1);
void on_spinBoxCoursesToSemester_valueChanged(int arg1);
void on_labelMadeBy_linkActivated(const QString &link);
void on_progressBar_valueChanged(int value);
// void on_progressBar_valueChanged(int value);
private:
@ -75,6 +76,8 @@ private:
coursesTableManager *courseTableMgr;
loginHandler *loginHandel;
jceStatusBar *statusBar;
};
#endif // MAINSCREEN_H

View file

@ -899,45 +899,6 @@ font-size: 15px;
</widget>
</widget>
</item>
<item row="2" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">#progressBar::horizontal {
border: 1px solid gray;
border-radius: 3px;
background: transparent;
padding: 1px;
}
#progressBar::chunk:horizontal {
background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 green, stop: 1 white);
}</string>
</property>
<property name="value">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="textDirection">
<enum>QProgressBar::TopToBottom</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelMadeBy">
<property name="text">
@ -975,20 +936,6 @@ background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 green, stop:
</widget>
<addaction name="menuA_about"/>
</widget>
<widget class="QStatusBar" name="statusBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>50</height>
</size>
</property>
</widget>
<action name="actionCredits">
<property name="text">
<string>Credits</string>

View file

@ -3,7 +3,7 @@
/**
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
*/
jceSSLClient::jceSSLClient(QProgressBar *progressbarPtr) : loggedIAndConnectedFlag(false), readingFlag(false),
jceSSLClient::jceSSLClient(jceStatusBar *progressbarPtr) : loggedIAndConnectedFlag(false), readingFlag(false),
reConnectionFlag(false), networkConf(), packet(""), recieveLastPacket(false), packetSizeRecieved(0)
{
this->progressBar = progressbarPtr;
@ -208,7 +208,7 @@ void jceSSLClient::readIt()
packet.append("\0");
readerAppendingLocker.unlock();
progressBar->setValue(this->progressBar->value() + 6);
emit progressBar->progressHasPacket(6);
if (tempPacket.contains("Go_To_system_After_Login.htm") || tempPacket.contains("</html>"))
{

View file

@ -11,7 +11,7 @@
#include <QNetworkConfigurationManager>
#include <QtNetwork/QNetworkInterface>
#include <QProgressBar>
#include "./main/jceWidgets/jcestatusbar.h"
#define packetSize 4096 //4k
#define milisTimeOut 5000 //4 seconds
@ -20,7 +20,7 @@ class jceSSLClient : public QSslSocket
{
Q_OBJECT
public:
jceSSLClient(QProgressBar *progressbarPtr);
jceSSLClient(jceStatusBar *progressbarPtr);
bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443);
bool makeDiconnect();
@ -64,7 +64,7 @@ private:
QProgressBar *progressBar; //progressbar pointer
jceStatusBar *progressBar; //progressbar pointer
};

View file

@ -4,7 +4,7 @@
* @brief jceLogin::jceLogin
* @param username pointer to allocated user settings
*/
jceLogin::jceLogin(user* username, QProgressBar *progressbarPtr)
jceLogin::jceLogin(user* username, jceStatusBar *progressbarPtr)
{
this->progressBar = progressbarPtr;
this->recieverPage = new QString();

View file

@ -1,12 +1,13 @@
#ifndef JCELOGIN_H
#define JCELOGIN_H
#include "./src/jceConnection/jcesslclient.h"
#include "./src/jceSettings/user.h"
#include "jceLoginHtmlScripts.h"
#include <QObject>
#include <QProgressBar>
#include <QString>
@ -15,7 +16,7 @@ class jceLogin : public QObject
Q_OBJECT
public:
jceLogin(user* username,QProgressBar *progressbarPtr);
jceLogin(user* username,jceStatusBar *progressbarPtr);
~jceLogin();
enum jceStatus {
@ -64,7 +65,7 @@ private:
QString * recieverPage;
user * jceA;
jceSSLClient * JceConnector;
QProgressBar *progressBar;
jceStatusBar *progressBar;
};