added progress bar

;
This commit is contained in:
liranbg 2014-10-04 03:47:14 +03:00
parent 26cbfbd576
commit 2ef44eff00
10 changed files with 558 additions and 457 deletions

View file

@ -1,19 +1,26 @@
#include "loginhandler.h"
loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr): logggedInFlag(false)
loginHandler::loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr,QProgressBar *progressbarPtr): logggedInFlag(false)
{
this->loginButtonPtr = loginButtonPtr;
this->progressBar = progressbarPtr;
//statusBar
statusBar = statusBarPtr;
iconButtomStatusLabel = new QLabel();
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);
//user settings
userPtr = ptr;
this->jceLog = new jceLogin(userPtr);
this->jceLog = new jceLogin(userPtr,progressBar);
QObject::connect(this->jceLog,SIGNAL(connectionReadyAfterDisconnection()),this,SLOT(readyAfterConnectionLost()));
}
bool loginHandler::login(QString username,QString password)
{

View file

@ -7,6 +7,7 @@
#include <QMessageBox>
#include <QPixmap>
#include <QStatusBar>
#include <QProgressBar>
#include <QPushButton>
#include "./src/jceSettings/jcelogin.h"
@ -17,7 +18,7 @@ class loginHandler : public QObject
{
Q_OBJECT
public:
loginHandler(user *ptr, QStatusBar *statusBarPtr,QPushButton *loginButtonPtr);
loginHandler(user *ptr, QStatusBar *statusBarPtr, QPushButton *loginButtonPtr, QProgressBar *progressbarPtr);
~loginHandler()
{
delete iconButtomStatusLabel;
@ -51,6 +52,7 @@ private:
QStatusBar *statusBar;
QLabel *iconButtomStatusLabel;
QPushButton *loginButtonPtr;
QProgressBar *progressBar;
};

View file

@ -9,13 +9,13 @@
int main(int argc, char *argv[])
{
#ifdef QT_DEBUG // Incase QtCreator is in Debug mode all qDebug messages will go to terminal
qDebug() << "Running a debug build";
qDebug() << Q_FUNC_INFO << "Running a debug build";
#else // If QtCreator is on Release mode , qDebug messages will be logged in a log file.
// qDebug() << "Running a release build";
qInstallMessageHandler(jce_logger::customMessageHandler);
#endif
qDebug() << "Start : JCE Manager Launched";
qDebug() << Q_FUNC_INFO << "Start : JCE Manager Launched";
QApplication a(argc, argv);
QTranslator translator;
@ -27,13 +27,13 @@ int main(int argc, char *argv[])
{
QString locale = QLocale::system().name();
translator.load("jce_"+locale , a.applicationDirPath());
qDebug() << "Local : Default Local Loaded";
qDebug() << Q_FUNC_INFO << "Local : Default Local Loaded";
}else if(loco == "he"){
translator.load("jce_he" , a.applicationDirPath());
qDebug() << "Local : Hebrew Local Loaded";
qDebug() << Q_FUNC_INFO << "Local : Hebrew Local Loaded";
}else{
translator.load("jce_en" , a.applicationDirPath());
qDebug() << "Local : English Local Loaded";
qDebug() << Q_FUNC_INFO << "Local : English Local Loaded";
}
a.installTranslator(&translator); //Setting local
MainScreen w;
@ -42,8 +42,8 @@ int main(int argc, char *argv[])
//Getting the exit code from QApplication. for debug reasons
int returnCode = a.exec();
if(returnCode == 0)
qDebug() << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode;
qDebug() << Q_FUNC_INFO << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode;
else
qCritical() << "End : JCE Manager Ended Unusccessfully With A Return Code: " << returnCode;
qCritical() << Q_FUNC_INFO << "End : JCE Manager Ended Unusccessfully With A Return Code: " << returnCode;
return returnCode;
}

View file

@ -2,10 +2,9 @@
#include "ui_mainscreen.h"
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen)
MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainScreen), busyFlag()
{
ui->setupUi(this);
//this->setFixedSize(this->size()); //main not resizeable
ui->labelMadeBy->setOpenExternalLinks(true);
@ -17,9 +16,11 @@ MainScreen::MainScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainSc
ui->labelUsrInputStatus->setPixmap(iconPix);
ui->labelPswInputStatus->setPixmap(iconPix);
//StatusBar
//StatusBar & progressbar
ui->progressBar->setFixedHeight(STATUS_ICON_HEIGH);
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ui->statusBar->setFixedHeight(STATUS_ICON_HEIGH);
ui->statusBar->setFixedHeight(STATUS_ICON_HEIGH+5);
ui->statusBar->showMessage(tr("Ready"));
//GPA Tab
@ -29,9 +30,10 @@ 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);
this->loginHandel = new loginHandler(userLoginSetting,ui->statusBar,ui->loginButton,ui->progressBar);
this->calendar = new CalendarManager(ui->calendarGridLayoutMain);
this->data = new SaveData();
busyFlag = false;
//check login File
if (data->isSaved())
@ -45,6 +47,7 @@ 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.";
}
@ -61,6 +64,7 @@ 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()))
{
@ -89,6 +93,7 @@ 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);
@ -129,6 +134,7 @@ void MainScreen::on_usrnmLineEdit_editingFinished()
//EVENTS ON GPA TAB
void MainScreen::on_ratesButton_clicked()
{
ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
if (!checkIfValidDates())
{
@ -139,16 +145,20 @@ void MainScreen::on_ratesButton_clicked()
QString pageString;
int status = 0;
QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag())
if (loginHandel->isLoggedInFlag() && !busyFlag)
{
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);
pageString = loginHandel->getCurrentPageContect();
courseTableMgr->setCoursesList(pageString);
courseTableMgr->insertJceCoursesIntoTable();
ui->progressBar->setValue(100);
ui->statusBar->showMessage(tr("Done"));
}
else if (status == jceLogin::JCE_NOT_CONNECTED)
{
@ -160,6 +170,7 @@ void MainScreen::on_ratesButton_clicked()
{
qCritical() << Q_FUNC_INFO << "grade get ended with" << status;
}
busyFlag = true;
}
QApplication::restoreOverrideCursor();
}
@ -221,18 +232,24 @@ void MainScreen::on_clearTableButton_clicked()
//EVENTS ON CALENDAR TAB
void MainScreen::on_getCalendarBtn_clicked()
{
ui->progressBar->setValue(0);
qDebug() << Q_FUNC_INFO << "in: " << ui->tabWidget->currentWidget()->objectName();
int status = 0;
QApplication::setOverrideCursor(Qt::WaitCursor);
if (loginHandel->isLoggedInFlag())
{
ui->statusBar->showMessage(tr("Getting schedule..."));
if ((status = loginHandel->makeCalendarRequest(ui->spinBoxYear->value(),ui->spinBoxSemester->value())) == jceLogin::JCE_PAGE_PASSED)
{
//Use it for debug. add plain text and change the object name to 'plainTextEdit' so you will get the html request
//ui->plainTextEdit->setPlainText(loginHandel->getCurrentPageContect());
calendar->resetTable();
ui->statusBar->showMessage(tr("Done. Inserting schdule into table..."),1000);
calendar->setCalendar(loginHandel->getCurrentPageContect());
ui->progressBar->setValue(100);
qDebug() << Q_FUNC_INFO << "calendar is loaded";
ui->statusBar->showMessage(tr("Done"));
}
else if (status == jceLogin::JCE_NOT_CONNECTED)

View file

@ -83,6 +83,8 @@ private:
coursesTableManager *courseTableMgr;
loginHandler *loginHandel;
bool busyFlag;
};
#endif // MAINSCREEN_H

View file

@ -626,6 +626,45 @@ font-size: 15px;
</widget>
</widget>
</item>
<item>
<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: white;
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::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</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>
<widget class="QLabel" name="labelMadeBy">
<property name="text">

View file

@ -3,14 +3,16 @@
/**
* @brief jceSSLClient::jceSSLClient Constructer, setting the signals
*/
jceSSLClient::jceSSLClient() : flag(false), packet(""),networkConf(), reConnection(false)
jceSSLClient::jceSSLClient(QProgressBar *progressbarPtr) : flag(false), packet(""),networkConf(), reConnection(false)
{
this->progressBar = progressbarPtr;
//setting signals
connect(this,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(checkErrors(QAbstractSocket::SocketError)));
connect(this,SIGNAL(connected()),this,SLOT(setConnected()));
connect(this,SIGNAL(encrypted()),this,SLOT(setEncrypted()));
connect(this,SIGNAL(disconnected()),this,SLOT(setDisconnected()));
connect(&networkConf,SIGNAL(onlineStateChanged(bool)),this,SLOT(setOnlineState(bool)));
//loop event will connect the server, and when it is connected, it will quit - but connection will be open
connect(this, SIGNAL(encrypted()), &loop, SLOT(quit()));
connect(this, SIGNAL(error(QAbstractSocket::SocketError)),&loop,SLOT(quit()));
@ -149,32 +151,34 @@ bool jceSSLClient::recieveData(QString &str, bool fast)
if (fast) //fast mode connection, good only for login step!!!!
{
qDebug() << "jceSSLClient::recieveData login step receiving";
QEventLoop loop;
connect(this, SIGNAL(readyRead()), &loop, SLOT(quit()));
qDebug() << Q_FUNC_INFO << "login step receiving";
//loop will exit after first read packet.
//meanwhile packet will gain data. good for small amount of data - fast connection!
connect(this, SIGNAL(readyRead()), &readerLoop, SLOT(quit()));
connect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
loop.exec();
disconnect(this, SIGNAL(readyRead()), &loop, SLOT(quit()));
readerLoop.exec();
disconnect(this, SIGNAL(readyRead()), &readerLoop, SLOT(quit()));
disconnect(this, SIGNAL(readyRead()), this, SLOT(readIt()));
}
else
{
qDebug() << "jceSSLClient::recieveData normal receiving";
QString p;
while (waitForReadyRead(milisTimeOut))
{
do
{
p = readAll();
packet.append(p);
}while (p.size() > 0);
}
qDebug() << Q_FUNC_INFO << "normal receiving";
//loop will exit after timeout \ full data
connect(this, SIGNAL(packetHasData()), &readerLoop, SLOT(quit()));
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()), &readerLoop, SLOT(quit()));
connect(this, SIGNAL(readyRead()), this, SLOT(readItAll()));
timer.start(5000);
readerLoop.exec();
}
str = packet;
qDebug() << Q_FUNC_INFO << "received bytes: " << str.length() ;
if (str.length() > 0)
sflag = true;
qDebug() << Q_FUNC_INFO << "return with flag: " << sflag;
disconnect(this, SIGNAL(readyRead()), this, SLOT(readItAll()));
return sflag;
}
@ -188,9 +192,27 @@ void jceSSLClient::readIt()
{
p = readAll();
packet.append(p);
this->progressBar->setValue(this->progressBar->value() + 6);
}while (p.size() > 0);
}
void jceSSLClient::readItAll()
{
QString p;
do
{
p = "";
p = read(bytesAvailable());
if (p.contains("</tbody>") == true)
{
qDebug() << "we have the end!";
timer.setInterval(1000);
}
this->progressBar->setValue(this->progressBar->value() + 6);
// qDebug() << "p lenght" << p.length();
packet.append(p);
}while (p.size() > 0);
}
void jceSSLClient::setOnlineState(bool isOnline)
{

View file

@ -8,6 +8,8 @@
#include <QMessageBox>
#include <QNetworkConfigurationManager>
#include <QtNetwork/QNetworkInterface>
#include <QTimer>
#include <QProgressBar>
#define milisTimeOut 4000
@ -15,7 +17,7 @@ class jceSSLClient : public QSslSocket
{
Q_OBJECT
public:
jceSSLClient();
jceSSLClient(QProgressBar *progressbarPtr);
bool makeConnect(QString server = "yedion.jce.ac.il", int port = 443);
bool makeDiconnect();
@ -28,6 +30,7 @@ signals:
void serverDisconnectedbyRemote();
void noInternetLink();
void socketDisconnected();
void packetHasData();
private slots:
void checkErrors(QAbstractSocket::SocketError a);
@ -35,6 +38,7 @@ private slots:
void setEncrypted();
void setDisconnected();
void readIt();
void readItAll();
void setOnlineState(bool isOnline);
private:
@ -42,9 +46,13 @@ private:
bool flag;
QString packet;
QEventLoop loop; //handle the connection as thread
QEventLoop readerLoop;
QTimer timer;
QNetworkConfigurationManager networkConf; //checking if online
bool reConnection; //used for remote host disconnecting
QProgressBar *progressBar; //
};
#endif // JCESSLCLIENT_H

View file

@ -4,11 +4,12 @@
* @brief jceLogin::jceLogin
* @param username pointer to allocated user settings
*/
jceLogin::jceLogin(user* username)
jceLogin::jceLogin(user* username, QProgressBar *progressbarPtr)
{
this->progressBar = progressbarPtr;
this->recieverPage = new QString();
this->jceA = username;
this->JceConnector = new jceSSLClient();
this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
}
@ -133,7 +134,7 @@ void jceLogin::reMakeConnection()
recieverPage = NULL;
JceConnector = NULL;
this->recieverPage = new QString();
this->JceConnector = new jceSSLClient();
this->JceConnector = new jceSSLClient(progressBar);
QObject::connect(JceConnector,SIGNAL(serverDisconnectedbyRemote()),this,SLOT(reValidation()));
QObject::connect(JceConnector,SIGNAL(noInternetLink()),this,SLOT(reMakeConnection()));
emit connectionReadyAfterDisconnection();
@ -297,6 +298,7 @@ QString jceLogin::getPage()
void jceLogin::reValidation()
{
qDebug() << Q_FUNC_INFO << "Revalidating user";
if (makeFirstVisit() == true)
{
if (checkValidation())

View file

@ -6,6 +6,7 @@
#include "jceLoginHtmlScripts.h"
#include <QObject>
#include <QProgressBar>
#include <QString>
@ -13,8 +14,8 @@ class jceLogin : public QObject
{
Q_OBJECT
public:
jceLogin() {}
jceLogin(user* username);
jceLogin(user* username,QProgressBar *progressbarPtr);
~jceLogin();
enum jceStatus {
@ -61,6 +62,7 @@ private:
QString * recieverPage;
user * jceA;
jceSSLClient * JceConnector;
QProgressBar *progressBar;
};