Initial commit

This commit is contained in:
liranbg 2014-06-14 20:02:50 +03:00
parent 73d8cb8f8e
commit e8e8bc4b06
29 changed files with 2584 additions and 0 deletions

49
jceGrade.pro Normal file
View file

@ -0,0 +1,49 @@
#-------------------------------------------------
#
# Project created by QtCreator 2014-05-31T19:49:42
#
#-------------------------------------------------
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = jceGrade
TEMPLATE = app
CONFIG += c++11
SOURCES += main/coursestablemanager.cpp \
main/loginhandler.cpp \
main/main.cpp \
main/mainscreen.cpp \
src/connection/qtsslsocket.cpp \
src/user.cpp \
src/grades/Course.cpp \
src/grades/GradePage.cpp \
src/grades/Page.cpp \
src/jce/jcedate.cpp \
src/jce/jcelogin.cpp
HEADERS += main/coursestablemanager.h \
main/loginhandler.h \
main/mainscreen.h \
src/connection/qtsslsocket.h \
src/user.h \
src/grades/Course.h \
src/grades/GradePage.h \
src/grades/Page.h \
src/jce/jcedate.h \
src/jce/jcelogin.h \
src/jce/jceLoginHtmlScripts.h \
FORMS += \
main/mainscreen.ui
OTHER_FILES +=
RESOURCES += \
resources/connectionstatus.qrc

View file

@ -0,0 +1,215 @@
#include "coursestablemanager.h"
coursesTableManager::coursesTableManager(QTableWidget *ptr, user *usrPtr)
{
this->gp = NULL;
this->us = usrPtr;
this->courseTBL = ptr;
/*
* Initilizing Table
*/
courseTBL->setRowCount(0);
courseTBL->setColumnCount(COURSE_FIELDS);
QStringList mz;
mz << "Serial" << "Name" << "Type" << "Points" << "Hours" << "Grade" << "Additions";
courseTBL->setHorizontalHeaderLabels(mz);
courseTBL->verticalHeader()->setVisible(true);
courseTBL->setSelectionMode(QAbstractItemView::SingleSelection);
courseTBL->setShowGrid(true);
courseTBL->setStyleSheet("QTableView {selection-background-color: red;}");
}
coursesTableManager::~coursesTableManager()
{
courseTBL = NULL;
delete gp;
gp=NULL;
}
/**
* @brief coursesTableManager::insertJceCoursesIntoTable phrasing the course list to rows in table
*/
void coursesTableManager::insertJceCoursesIntoTable()
{
for (Course *c: *gp->getCourses())
{
if (us->getInfluenceCourseOnly())
{
if (isCourseInfluence(c))
addRow(c);
}
else
addRow(c);
}
}
/**
* @brief coursesTableManager::setCoursesList creating courses list with given html page
* @param html
*/
void coursesTableManager::setCoursesList(std::string &html)
{
gp = new GradePage(html);
}
/**
* @brief coursesTableManager::changes when user changes the table manually it updates it
* @param change string change
* @param row row index
* @param col col index
*/
void coursesTableManager::changes(std::string change, int row, int col)
{
int serialCourse = courseTBL->item(row,Course::CourseScheme::SERIAL)->text().toInt();
for (Course *c: *gp->getCourses())
{
if (c->getSerialNum() == serialCourse)
{
switch (col)
{
case (Course::CourseScheme::NAME):
c->setName(change);
break;
case (Course::CourseScheme::TYPE):
c->setType(change);
break;
case (Course::CourseScheme::POINTS):
c->setPoints(stod(change));
break;
case (Course::CourseScheme::HOURS):
c->setHours(stod(change));
break;
case (Course::CourseScheme::GRADE):
c->setGrade(stod(change));
break;
case (Course::CourseScheme::ADDITION):
c->setAdditions(change);
break;
}
break;
}
}
}
/**
* @brief coursesTableManager::addRow adds row with given information
* @param courseToAdd if exists, add its information to table
*/
void coursesTableManager::addRow(const Course *courseToAdd)
{
int i,j;
i = courseTBL->rowCount();
j = 0;
QTableWidgetItem *serial,*name,*type,*points,*hours,*grade,*addition;
const Course * c;
if (courseToAdd != NULL)
{
c = courseToAdd;
if (!isCourseAlreadyInserted(c->getSerialNum()))
{
courseTBL->setRowCount(courseTBL->rowCount()+1);
serial = new QTableWidgetItem(QString::number(c->getSerialNum()));
serial->setFlags(serial->flags() & ~Qt::ItemIsEditable);
points = new QTableWidgetItem(QString::number(c->getPoints()));
points->setFlags(serial->flags() & ~Qt::ItemIsEditable);
hours = new QTableWidgetItem(QString::number(c->getHours()));
hours->setFlags(serial->flags() & ~Qt::ItemIsEditable);
grade = new QTableWidgetItem(QString::number(c->getGrade()));
name = new QTableWidgetItem(QString::fromStdString(c->getName()));
name->setFlags(serial->flags() & ~Qt::ItemIsEditable);
type = new QTableWidgetItem(QString::fromStdString(c->getType()));
type->setFlags(serial->flags() & ~Qt::ItemIsEditable);
addition = new QTableWidgetItem(QString::fromStdString(c->getAddidtions()));
courseTBL->setItem(i,j++,serial);
courseTBL->setItem(i,j++,name);
courseTBL->setItem(i,j++,type);
courseTBL->setItem(i,j++,points);
courseTBL->setItem(i,j++,hours);
courseTBL->setItem(i,j++,grade);
courseTBL->setItem(i,j,addition);
}
}
else
{
}
courseTBL->resizeColumnsToContents();
}
double coursesTableManager::getAvg()
{
if (this->gp != NULL)
return gp->getAvg();
return 0;
}
void coursesTableManager::influnceCourseChanged(bool ignoreCourseStatus)
{
if (ignoreCourseStatus)
{
int i = 0;
while (i < courseTBL->rowCount())
{
if (courseTBL->item(i,Course::CourseScheme::POINTS)->text().compare("0") == 0)
courseTBL->removeRow(i--);
i++;
}
}
else
{
for (Course *c: *gp->getCourses())
{
if (!(isCourseAlreadyInserted(c->getSerialNum())))
if (c->getPoints() == 0)
addRow(c);
}
}
}
void coursesTableManager::clearTable()
{
if (courseTBL->rowCount() == 0)
return;
int i = 0; //starting point
while (courseTBL->rowCount() > i)
{
gp->removeCourse(courseTBL->item(i,Course::CourseScheme::SERIAL)->text().toStdString());
courseTBL->removeRow(i);
}
gp = NULL;
courseTBL->repaint();
}
Course *coursesTableManager::getCourseByRow(int row)
{
QString courseSerial = courseTBL->item(row,Course::CourseScheme::SERIAL)->text();
for (Course *c: *gp->getCourses())
{
if (c->getSerialNum() == courseSerial.toDouble())
return c;
}
return NULL;
}
bool coursesTableManager::isCourseAlreadyInserted(double courseID)
{
int i=0;
for (i = 0; i < courseTBL->rowCount(); ++i)
{
QString courseSerial = courseTBL->item(i,Course::CourseScheme::SERIAL)->text();
if (QString::number(courseID) == courseSerial)
return true;
}
return false;
}
bool coursesTableManager::isCourseInfluence(const Course *courseToCheck)
{
if (courseToCheck->getPoints() > 0)
return true;
return false;
}

View file

@ -0,0 +1,43 @@
#ifndef COURSESTABLEMANAGER_H
#define COURSESTABLEMANAGER_H
#include <QApplication>
#include <QDesktopWidget>
#include <QtCore/QCoreApplication>
#include <QHeaderView>
#include <QMessageBox>
#include <QTableWidget>
#include <QProgressBar>
#include <list>
#include "src/grades/Course.h"
#include "src/grades/GradePage.h"
#include "src/user.h"
class coursesTableManager
{
public:
coursesTableManager(QTableWidget *, user *usrPtr);
~coursesTableManager();
void insertJceCoursesIntoTable();
void setCoursesList(std::string &htmlPage);
void changes(std::string change, int row, int col);
void addRow(const Course * courseToAdd = 0);
double getAvg();
void influnceCourseChanged(bool status);
void clearTable();
private:
QTableWidget *courseTBL;
GradePage *gp;
user *us;
Course * getCourseByRow(int row);
bool isCourseAlreadyInserted(double courseID);
bool isCourseInfluence(const Course *courseToCheck);
};
#endif // COURSESTABLEMANAGER_H

66
main/loginhandler.cpp Normal file
View file

@ -0,0 +1,66 @@
#include "loginhandler.h"
loginHandler::loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr)
{
this->jceLog = ptr;
this->statusLabelPtr = statusLabelPtr;
this->pswdEditPtr = pswdEditPtr;
this->usrnmEditPtr = usrnmEditPtr;
}
bool loginHandler::makeConnection()
{
if (this->jceLog == NULL)
{
return false;
}
try
{
jceLog->makeConnection();
}
catch (jceLogin::jceStatus &a)
{
if (a == jceLogin::JCE_YOU_ARE_IN)
{
return true;
}
else if (a == jceLogin::ERROR_ON_VALIDATION)
{
popMessage("check your password");
usrnmEditPtr->setDisabled(false);
pswdEditPtr->setDisabled(false);
pswdEditPtr->selectAll();
pswdEditPtr->setFocus();
return false;
}
else if (a == jceLogin::ERROR_ON_OPEN_SOCKET)
{
popMessage("Please check your internet status");
jceLog->closeAll();
return false;
}
else if (a == jceLogin::ERROR_ON_VALIDATION_USER_BLOCKED)
{
popMessage("You were blocked, please wait couple of minutes or contact JCE");
jceLog->closeAll();
return false;
}
}
return false;
}
void loginHandler::popMessage(QString message)
{
QMessageBox msgBox;
msgBox.setWindowTitle("Error");
msgBox.setText(message);
msgBox.exec();
msgBox.setFocus();
}

29
main/loginhandler.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef LOGINHANDLER_H
#define LOGINHANDLER_H
#include <QString>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QPixmap>
#include "src/jce/jcelogin.h"
class loginHandler
{
public:
loginHandler(jceLogin *ptr,QLabel *statusLabelPtr,QLineEdit *pswdEditPtr,QLineEdit *usrnmEditPtr);
bool makeConnection();
private:
void popMessage(QString message);
jceLogin *jceLog;
QLabel *statusLabelPtr;
QLineEdit *pswdEditPtr;
QLineEdit *usrnmEditPtr;
};
#endif // LOGINHANDLER_H

13
main/main.cpp Normal file
View file

@ -0,0 +1,13 @@
#include "mainscreen.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainScreen w;
w.show();
return a.exec();
}

237
main/mainscreen.cpp Normal file
View file

@ -0,0 +1,237 @@
#include "mainscreen.h"
#include "ui_mainscreen.h"
MainScreen::MainScreen(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainScreen)
{
ui->setupUi(this);
// this->setWindowFlags(this->windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
this->setFixedSize(this->size()); //main not resizeable
ui->pswdLineEdit->setEchoMode((QLineEdit::Password));
ui->statusBar->setStyleSheet("QStatusBar::item { border: 0px solid black };");
ButtomStatusLabel = new QLabel(this);
statusLabel = new QLabel(this);
ui->CoursesTab->setDisabled(true);
ui->SettingsTab->setDisabled(true);
ui->statusBar->setMaximumSize(this->geometry().width(),StatusIconHeight);
ui->statusBar->addPermanentWidget(ButtomStatusLabel,0);
ui->statusBar->addPermanentWidget(statusLabel,1);
this->jceLog = NULL;
this->userLoginSetting = new user("","");
this->courseTableMgr = new coursesTableManager(ui->coursesTable,userLoginSetting);
updateDates();
setLabelConnectionStatus(jceLogin::jceStatus::JCE_NOT_CONNECTED);
}
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)
{
this->courseTableMgr->changes(item->text().toStdString(),item->row(),item->column());
ui->avgLCD->display(courseTableMgr->getAvg());
}
void MainScreen::on_loginButton_clicked()
{
setLabelConnectionStatus(jceLogin::jceStatus::JCE_START_VALIDATING_PROGRESS);
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()
{
string username;
string password;
if ((ui->usrnmLineEdit->text().isEmpty()) || (ui->pswdLineEdit->text().isEmpty()))
{
//add icon near to username and password to mark it
return;
}
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();
jceLog = new jceLogin(userLoginSetting);
this->loginHandel = new loginHandler(jceLog,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 credits;
credits.setText(" A tiny application to calculate your grades average. \n Made by Liran Ben Gida \n Thanks to: Sagi Dayan, Nadav Luzzato");
credits.exec();
}
void MainScreen::on_clearTableButton_clicked()
{
courseTableMgr->clearTable();
ui->avgLCD->display(courseTableMgr->getAvg());
}
void MainScreen::on_actionExit_triggered()
{
exit(0);
}

78
main/mainscreen.h Normal file
View file

@ -0,0 +1,78 @@
#ifndef MAINSCREEN_H
#define MAINSCREEN_H
#include <QMainWindow>
#include <QApplication>
#include <QString>
#include <QMessageBox>
#include <QTextEdit>
#include <string>
#include <iostream>
#include "src/grades/GradePage.h"
#include "src/jce/jcelogin.h"
#include "coursestablemanager.h"
#include "loginhandler.h"
#define StatusIconHeight 35
namespace Ui {
class MainScreen;
}
class MainScreen : public QMainWindow
{
Q_OBJECT
public:
MainScreen(QWidget *parent = 0);
~MainScreen();
private slots:
void on_ratesButton_clicked();
void on_spinBoxFromYear_editingFinished();
void on_spinBoxFromSem_editingFinished();
void on_spinBoxToYear_editingFinished();
void on_spinBoxToSemester_editingFinished();
void on_coursesTable_itemChanged(QTableWidgetItem *item);
void on_loginButton_clicked();
void on_checkBox_toggled(bool checked);
void on_usrnmLineEdit_editingFinished();
void on_actionCredits_triggered();
void on_clearTableButton_clicked();
void on_actionExit_triggered();
private:
void updateDates();
void uiSetDisconnectMode();
void uiSetConnectMode();
void setLabelConnectionStatus(jceLogin::jceStatus statusDescription);
Ui::MainScreen *ui;
jceLogin *jceLog;
user *userLoginSetting;
coursesTableManager *courseTableMgr;
loginHandler *loginHandel;
QLabel *ButtomStatusLabel;
QLabel *statusLabel;
};
#endif // MAINSCREEN_H

691
main/mainscreen.ui Normal file
View file

@ -0,0 +1,691 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainScreen</class>
<widget class="QMainWindow" name="MainScreen">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>737</width>
<height>500</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>JCE Avg Calculator</string>
</property>
<property name="windowIcon">
<iconset resource="../resources/connectionstatus.qrc">
<normaloff>:/icons/icon.png</normaloff>:/icons/icon.png</iconset>
</property>
<property name="styleSheet">
<string notr="true">#centralWidget
{
background: qlineargradient(spread:pad, x1:0.496, y1:0, x2:0.508, y2:1, stop:0 rgba(195, 231, 224, 218), stop:1 rgba(255, 255, 255, 255));
}</string>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="documentMode">
<bool>false</bool>
</property>
<property name="dockNestingEnabled">
<bool>false</bool>
</property>
<widget class="QWidget" name="centralWidget">
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="true">#CoursesTab {
background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf);
border: none;
}
#LoginTab {
background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf);
border: none;
}
#SettingsTab {
background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf);
border: none;
}
#DebugTab {
background: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #eef, stop: 1 #ccf);
border: none;
}</string>
</property>
<property name="tabPosition">
<enum>QTabWidget::North</enum>
</property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="documentMode">
<bool>false</bool>
</property>
<property name="tabsClosable">
<bool>false</bool>
</property>
<property name="movable">
<bool>false</bool>
</property>
<widget class="QWidget" name="LoginTab">
<property name="styleSheet">
<string notr="true"/>
</property>
<attribute name="title">
<string>Login</string>
</attribute>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="leftMargin">
<number>200</number>
</property>
<property name="topMargin">
<number>80</number>
</property>
<property name="rightMargin">
<number>200</number>
</property>
<property name="bottomMargin">
<number>80</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QFrame" name="LoginFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">#LoginFrame {
border: 3px solid rgb(160, 165, 170);
border-radius: 40px;
}
#loginButton {
color: white;
background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #77c, stop: 0.5 #66b, stop: 1 #77c);
border-width: 1px;
border-color: #339;
border-style: solid;
border-radius: 7;
padding: 3px;
font-size: 12px;
padding-left: 5px;
padding-right: 5px;
min-width: 60px;
max-width: 60px;
min-height: 20px;
max-height: 20px;
}
#loginButton:pressed {
background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #88d, stop: 0.1 #99e, stop: 0.49 #88c, stop: 0.5 #77b, stop: 1 #88c);
}
#pswdLabel {
font-weight: bold;
font-size: 15px;
}
#usrnmLabel {
font-weight: bold;
font-size: 15px;
}</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>20</number>
</property>
<property name="topMargin">
<number>15</number>
</property>
<property name="rightMargin">
<number>20</number>
</property>
<property name="bottomMargin">
<number>15</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="usrnmHorizontalLayout" stretch="0,0">
<property name="spacing">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="usrnmLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="usrnmLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="inputMethodHints">
<set>Qt::ImhLatinOnly|Qt::ImhNoPredictiveText</set>
</property>
<property name="maxLength">
<number>20</number>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="pswdHorizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="pswdLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="pswdLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="inputMethodHints">
<set>Qt::ImhHiddenText|Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhSensitiveData</set>
</property>
<property name="maxLength">
<number>20</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="loginButtonHorizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="loginButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="CoursesTab">
<property name="enabled">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<attribute name="title">
<string>Courses</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>2</x>
<y>5</y>
<width>711</width>
<height>371</height>
</rect>
</property>
<layout class="QGridLayout" name="courseGrid">
<property name="leftMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTableWidget" name="coursesTable">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="coursesTableControlHorizontalLayout">
<item>
<layout class="QHBoxLayout" name="coursesButtonLayout">
<item>
<widget class="QPushButton" name="ratesButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearTableButton">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="coursesAvgSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>378</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="AvghorizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Average:</string>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="avgLCD"/>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="SettingsTab">
<property name="enabled">
<bool>false</bool>
</property>
<attribute name="title">
<string>Settings</string>
</attribute>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<width>201</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>Only influences Courses</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<widget class="QFrame" name="frame">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>231</width>
<height>121</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>48</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="semNyearHorizontalLayout">
<item>
<widget class="QLabel" name="SemLabel">
<property name="text">
<string>Semester</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="YearLabel">
<property name="text">
<string>Year</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="fromNtoLabel">
<item>
<widget class="QLabel" name="FromLabel">
<property name="text">
<string>From</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ToLabel">
<property name="text">
<string>To</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="SpinBoxeshorizontalLayout1">
<item>
<widget class="QSpinBox" name="spinBoxFromSem">
<property name="maximum">
<number>3</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="spinBoxFromYear">
<property name="readOnly">
<bool>false</bool>
</property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
<property name="minimum">
<number>2009</number>
</property>
<property name="maximum">
<number>2015</number>
</property>
<property name="value">
<number>2009</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="SpinBoxeshorizontalLayout2">
<item>
<widget class="QSpinBox" name="spinBoxToSemester">
<property name="maximum">
<number>3</number>
</property>
<property name="value">
<number>3</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="spinBoxToYear">
<property name="minimum">
<number>2010</number>
</property>
<property name="maximum">
<number>2026</number>
</property>
<property name="value">
<number>2015</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
<zorder></zorder>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>737</width>
<height>29</height>
</rect>
</property>
<widget class="QMenu" name="menuA_about">
<property name="title">
<string>&amp;About</string>
</property>
<addaction name="actionCredits"/>
<addaction name="actionExit"/>
</widget>
<addaction name="menuA_about"/>
</widget>
<widget class="QStatusBar" name="statusBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<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>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>Exit</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="../resources/connectionstatus.qrc"/>
</resources>
<connections/>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/icons">
<file>blueStatusIcon.png</file>
<file>greenStatusIcon.png</file>
<file>redStatusIcon.png</file>
<file>icon.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
resources/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
resources/redStatusIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -0,0 +1,56 @@
#include "qtsslsocket.h"
qtsslsocket::qtsslsocket(std::string server,int port) : flag(false)
{
socket = new QSslSocket();
socket->connectToHostEncrypted(server.c_str(), port);
if (socket->waitForEncrypted())
flag = true;
}
bool qtsslsocket::isCon()
{
return flag;
}
bool qtsslsocket::send(std::string str)
{
bool flag = true;
this->socket->write(str.c_str());
return flag;
}
bool qtsslsocket::recieve(std::string &str)
{
bool flag = false;
QString s = "";
while (socket->waitForReadyRead(milisTimeOut))
s.append((socket->readAll().data()));
str = s.toStdString();
if (s.size() > 0)
flag = true;
return flag;
}
void qtsslsocket::setProgressBar(QProgressBar *ptr)
{
if (ptr != NULL)
{
this->pb=ptr;
connect(this->socket,SIGNAL(encryptedBytesWritten(qint64)),this,SLOT(on_read()));
//connect(this->socket,SIGNAL(readChannelFinished()),this,SLOT(on_read()));
}
}
void qtsslsocket::on_read()
{
if (this->pb != NULL)
{
if (pb->value() <= 90)
pb->setValue(pb->value() + 10);
}
}

View file

@ -0,0 +1,40 @@
#ifndef QTSSLSOCKET_H
#define QTSSLSOCKET_H
#include <QObject>
#include <QSslSocket>
#include <QtNetwork/QSslCipher>
#include <QString>
#include <QProgressBar>
#include <iostream>
#include <string>
#define milisTimeOut 3000
class qtsslsocket : public QObject
{
Q_OBJECT
public:
qtsslsocket(std::string server,int port);
~qtsslsocket() {
disconnect(this->socket,SIGNAL(encryptedBytesWritten(qint64)),this,SLOT(on_read()));
socket->close();
socket = NULL;
pb = NULL;
}
bool isCon();
bool send(std::string str);
bool recieve(std::string &str);
void setProgressBar(QProgressBar *ptr);
private slots:
void on_read();
private:
QSslSocket *socket;
QProgressBar *pb;
bool flag;
};
#endif // QTSSLSOCKET_H

75
src/grades/Course.cpp Normal file
View file

@ -0,0 +1,75 @@
#include "Course.h"
Course::Course(int serial, std::string name, std::string type, double points, double hours, double grade, std::string additions)
{
this->serialNum = serial;
this->name = name;
this->type = type;
this->points = points;
this->hours = hours;
this->grade = grade;
this->additions = additions;
}
Course::~Course()
{
}
void Course::printCourse()
{
double noGrade = NO_GRADE_YET;
std::cout << "===== Course =====" << std::endl;
std::cout << "serial: " << this->serialNum << std::endl;
std::cout << "name: " << this->name << std::endl;
std::cout << "type: " << this->type << std::endl;
std::cout << "points: " << this->points << std::endl;
std::cout << "hours: " << this->hours << std::endl;
if (this->grade != noGrade)
std::cout << "grade: " << this->grade << std::endl;
else
std::cout << "grade: " << "No Grade" << std::endl;
std::cout << "additions: " << this->additions << std::endl;
}
double Course::getGrade() const
{
double noGrade = NO_GRADE_YET;
if (grade == noGrade)
return 0;
else
return this->grade;
}
void Course::setName(std::string name)
{
this->name = name;
}
void Course::setType(std::string type)
{
this->type = type;
}
void Course::setPoints(double points)
{
this->points=points;
}
void Course::setHours(double hours)
{
this->hours = hours;
}
void Course::setGrade(double grade)
{
this->grade = grade;
}
void Course::setAdditions(std::string additions)
{
this->additions = additions;
}

60
src/grades/Course.h Normal file
View file

@ -0,0 +1,60 @@
#ifndef COURSE_H
#define COURSE_H
#include <string>
#include <iostream>
#include <list>
#define COURSE_FIELDS 7
#define NO_GRADE_YET 101;
class Course{
public:
enum CourseScheme
{
SERIAL,
NAME,
TYPE,
POINTS,
HOURS,
GRADE,
ADDITION
};
Course(int serial,std::string name, std::string type, double points, double hours, double grade, std::string additions);
~Course();
void printCourse();
int getSerialNum() const {return this->serialNum;}
std::string getName() const {return this->name;}
std::string getType() const {return this->type;}
double getPoints() const {return this->points;}
double getHours() const {return this->hours;}
double getGrade() const ;
std::string getAddidtions() const {return this->additions;}
void setName(std::string name);
void setType(std::string type);
void setPoints(double points);
void setHours(double hours);
void setGrade(double grade);
void setAdditions(std::string additions);
private:
int serialNum;
std::string name;
std::string type;
double points;
double hours;
double grade;
std::string additions;
};
#endif

184
src/grades/GradePage.cpp Normal file
View file

@ -0,0 +1,184 @@
#include "GradePage.h"
GradePage::GradePage(std::string html) : Page(html)
{
courses = new std::list<Course*>();
tempHtml = getString();
genList();
}
GradePage::~GradePage()
{
for(Course* c : *courses)
delete c;
delete courses;
}
void GradePage::genList()
{
this->tempHtml = tokenToLines( this->tempHtml , INFO_DATA_LINES_BEFORE_GRADES_DATA );
coursesListInit(this->tempHtml);
}
void GradePage::addCourse(Course *a)
{
GradePage::courses->push_back(a);
return;
}
void GradePage::removeCourse(std::string courseSerialID)
{
for(Course* c : *courses)
{
if (c->getSerialNum() == stoi(courseSerialID))
{
courses->remove(c);
delete c;
return;
}
}
}
void GradePage::coursesListInit(std::string& linesTokinzedString)
{
std::list<std::string> stringHolder;
std::string temp;
Course* cTemp = NULL;
char* tok;
char* textToTok = strdup(linesTokinzedString.c_str());
tok = strtok(textToTok,"\n");
while (tok != NULL)
{
temp = tok;
stringHolder.push_back(temp);
tok = strtok(NULL, "\n");
}
for(std::string temp: stringHolder)
{
cTemp = lineToCourse(temp);
if (cTemp != NULL)
addCourse(cTemp);
}
}
std::string GradePage::tokenToLines(std::string& textToPhrase,int fromLine)
{
int ctr = 0;
std::string temp = "";
char *tok;
char* textToTok = strdup(textToPhrase.c_str());
tok = strtok(textToTok, "\n");
while(tok != NULL)
{
//amount of data before the actual needed data and no empty lines
if ((ctr >= fromLine) && (strcmp(tok," \t ") != 0))
{
temp += tok;
temp += "\n";
}
ctr++;
tok = strtok(NULL, "\n");
}
return temp;
}
Course* GradePage::lineToCourse(std::string line)
{
Course *tempC = NULL;
std::string templinearray[COURSE_FIELDS];//[serial,name,type,points,hours,grade,additions]
int serial;
double points,hours,grade;
std::string name,type, additions;
std::string tempS = "";
int i = 0;
char* tok;
char* cLine = strdup(line.c_str());
tok = strtok(cLine, "\t");
while(tok != NULL)
{
tempS = tok;
if (i == 1) //skip the tokenizing loop just once
{
tempS = "";
char *tokTemp;
tokTemp = tok;
while (!(isdigit((int)*tokTemp)))
tokTemp++;
while (isdigit((int)*tokTemp))
{
tempS += *tokTemp;
tokTemp++;
}
templinearray[i-1] = tempS;
templinearray[i] = tokTemp;
}
else if (i > 1)
templinearray[i] = tempS;
i++;
tok=strtok(NULL, "\t");
}
if (templinearray[0] == "") //empty phrasing
return NULL;
serial = stoi(templinearray[Course::CourseScheme::SERIAL]);
name = templinearray[Course::CourseScheme::NAME];
type = templinearray[Course::CourseScheme::TYPE];
points = stod(templinearray[Course::CourseScheme::POINTS]);
hours = stod(templinearray[Course::CourseScheme::HOURS]);
if (isGradedYet(templinearray[Course::CourseScheme::GRADE]))
grade = stod(templinearray[Course::CourseScheme::GRADE]);
else
grade = NO_GRADE_YET;
additions = templinearray[Course::CourseScheme::ADDITION];
tempC = new Course(serial,name,type,points,hours,grade,additions);
return tempC;
}
//checking if one of the chars inside grade is not a number
bool GradePage::isGradedYet(std::string grade)
{
if (strlen(grade.c_str()) <= 1)
return false;
for (char c: grade)
{
if (c == '\0')
break;
if (((!isdigit((int)c)) && (!isspace((int)c)))) //48 = 0, 57 = 9
return false;
}
return true;
}
void GradePage::printCourses()
{
for(Course* c : *courses)
c->printCourse();
}
double GradePage::getAvg()
{
double avg = 0;
double points = 0;
for(Course* c : *courses)
{
if ((c->getGrade() != 0))
{
avg += c->getGrade() * c->getPoints();
points += c->getPoints();
}
}
avg /= points;
return avg;
}

42
src/grades/GradePage.h Normal file
View file

@ -0,0 +1,42 @@
#ifndef GRADE_PAGE_H
#define GRADE_PAGE_H
#include "Page.h"
#include "Course.h"
#include <list>
#include <string.h> //strlen and strtok to phrase the html file
#include <ctype.h> //checks if character is numeric
#define INFO_DATA_LINES_BEFORE_GRADES_DATA 5
class GradePage : public Page
{
public:
GradePage(std::string html);
void printCourses();
~GradePage();
void addCourse(Course *);
void removeCourse(std::string courseSerialID);
double getAvg();
std::list<Course*>* getCourses() { return courses; }
private:
void genList();
std::string tokenToLines(std::string& textToPhrase,int fromLine = 0);
void coursesListInit(std::string& linesTokinzedString);
Course* lineToCourse(std::string line);
bool isGradedYet(std::string grade);
std::list<Course*>* courses;
std::string tempHtml;
};
#endif

164
src/grades/Page.cpp Normal file
View file

@ -0,0 +1,164 @@
#include "Page.h"
Page::Page(std::string& html)
{
makeText(html);
}
void Page::makeText(std::string& html)
{
int index = 0;
index = findTitle(html, index);
index = runToActualText(html, index); //set index into the actual place where the data is
manageTableContent(html, index);
}
int Page::findTitle(std::string& from, int index)
{
std::string temp;
while(index < (int)from.length())
{
if(from[index] == '<')
{
//title>
index++;
std::string titleTag = from.substr(index, 5); //legth of title
if(titleTag == "title") //check if the tag is title
{
while(from[index] != '>')
index++;
index++;
while(from[index] != '<')
{
temp += from[index];
index++;
}
this->title = temp; //sets the title
return index;
}
}
index++;
}
return -1;
}
int Page::runToActualText(std::string& from, int index)
{
while(index < (int)from.length())
{
if(from[index] == '<')
{
index++;
if(from[index] == '!')
{
//!--FileName
std::string bodyTag = from.substr(index, 11); //!--FileName
if(bodyTag == "!--FileName") //check if the tag is body tag
{
while(from[index] != '>')
index++;
return index;
}
}
}
index++;
}
return -1;
}
void Page::manageTableContent(std::string& html, int index)
{
std::string temp;
for (int i = index; i < (int)html.length(); i++)
{
if(html[i] == '<')
{
//<tr> / <td> / <th>
std::string endofTable = "</tbody>";
std::string tableTag = html.substr(i, 4); //legth of "tr/td"
if(tableTag == "<tr>")
{
temp += "\n"; //new row -> new line
i = stitchText(html, temp, i+4);
if(i == -1) //EOF
break;
}
else if(tableTag == "<td>" || tableTag == "<th>")
{
temp += "\t"; // new cell -> tab between data
i = stitchText(html, temp, i+4);
if (i == -1) //EOF
break;
}
else if(tableTag == "<td ") // a Year title (in grades table)
{
temp += "\t";
while(html[i] != '>')
i++;
i = stitchText(html, temp, i+1);
}
else if (html.substr(i,(endofTable).length()) == endofTable) //is end of table
{
break;
}
}
}
this->text = temp;
}
int Page::stitchText(std::string& from, std::string& to, int index)
{
if (from[index] == '<')
{
std::string bTag = from.substr(index, 3);
if (bTag != "<b>")
return index-1; //go back one step - for the main function to inc i
index += 3;
}
while (from[index] != '<' && index < (int)from.length())
{
if (from[index] == '&')
{
//&nbsp;
std::string nbspChr = from.substr(index, 6);
if (nbspChr == "&nbsp;")
{
index += 5;
from.at(index) = ' ';
}
}
if (endOfString(index,(int) from.length()))
return -1; //EOF
else if (from[index] == '<')
return index - 1; //go back one step - for the main function to inc i
if (from[index] != '\n') //check the actuall data before continue
to += from[index];
index++;
}
return index-1;
}
bool Page::endOfString(int index, int length)
{
if(index < length)
return false;
return true;
}
std::string Page::getString()
{
return this->text;
}
std::string Page::getTitle()
{
return this->title;
}

37
src/grades/Page.h Normal file
View file

@ -0,0 +1,37 @@
#ifndef PAGE_H
#define PAGE_H
#include <iostream>
#include <string>
class Page
{
public:
~Page() {}
protected:
Page(std::string& html);
std::string getString();
std::string getTitle();
void makeText(std::string& html);
private:
int findTitle(std::string& from, int index);
int runToActualText(std::string& from, int index);
void manageTableContent(std::string& html, int index);
int stitchText(std::string& from, std::string& to, int index);
bool endOfString(int index, int length);
std::string text;
std::string title;
};
#endif

View file

@ -0,0 +1,72 @@
#ifndef JCELOGINHTMLSCRIPTS_H
#define JCELOGINHTMLSCRIPTS_H
#include <string>
#define dst_host "yedion.jce.ac.il"
#define dst_port 443
#include "../user.h"
class jceLoginHtmlScripts
{
private:
jceLoginHtmlScripts();
public:
static std::string makeRequest(std::string parameters)
{
std::string msg;
msg = "POST /yedion/fireflyweb.aspx HTTP/1.1\r\n";
msg += "Host: " + std::string(dst_host) + "\r\n";
msg += "Content-Type: application/x-www-form-urlencoded\r\n";
msg += "Content-Length: " + to_string(parameters.length()) + "\r\n";
msg += "Proxy-Connection: Keep-Alive\r\n";
msg += "Accept-Charset: utf-8";
msg += "Accept: text/plain\r\n";
msg += "Connection: Keep-Alive\r\n";
msg += "\r\n";
msg += parameters;
return msg;
}
const static std::string getFirstValidationStep(const user &usr)
{
std::string parameters = "?appname=BSHITA&prgname=LoginValidation&arguments=-N";
parameters += usr.getUsername();
parameters += ",-N";
parameters += usr.getPassword();
return parameters;
}
const static std::string getSecondValidationStep(const user &usr)
{
std::string parameters;
parameters = "prgname=LoginValidtion1&Arguments=-N";
parameters += usr.getUserID();
parameters += ",-A,-N";
parameters += usr.getHashedPassword();
parameters += ",-A,-A";
return parameters;
}
const static std::string getGradesPath(const user &usr)
{
std::string parameters;
parameters = "PRGNAME=HADPASAT_MISMAHIM_LETALMID&ARGUMENTS=TZ,-N4,R1C2,R1C4,R1C1,R1C3,-A,-A,R1C5,-A,UNIQ&";
parameters += "TZ=" + usr.getUserID() + "&";
parameters += "UNIQ=" + usr.getHashedPassword() + "&";
parameters += "R1C2=" + usr.date->getFYear() + "&";
parameters += "R1C1=" + usr.date->getTYear() + "&";
parameters += "R1C3=" + usr.date->getTSemester() + "&";
parameters += "R1C4=" + usr.date->getFSemester() + "&";
parameters += "R1C5=0";
return parameters;
}
};
#endif // JCELOGINHTMLSCRIPTS_H

34
src/jce/jcedate.cpp Normal file
View file

@ -0,0 +1,34 @@
#include "jcedate.h"
jceDate::jceDate(std::string fromYear,std::string fromSemester,std::string toYear,std::string toSemester)
{
this->fSemester = fromSemester;
this->fYear = fromYear;
this->tSemester = toSemester;
this->tYear = toYear;
}
void jceDate::setFYear(std::string fromYear)
{
this->fYear = fromYear;
}
void jceDate::setTYear(std::string toYear)
{
this->tYear = toYear;
}
void jceDate::setFSemester(std::string fromSemester)
{
this->fSemester = fromSemester;
}
void jceDate::setTSemester(std::string toSemester)
{
this->tSemester = toSemester;
}
jceDate::~jceDate()
{
}

33
src/jce/jcedate.h Normal file
View file

@ -0,0 +1,33 @@
#ifndef JCEDATE_H
#define JCEDATE_H
#include <iostream>
class jceDate
{
public:
jceDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
~jceDate();
void setFYear(std::string fromYear);
void setTYear(std::string toYear);
void setFSemester(std::string fromSemester);
void setTSemester(std::string toSemester);
std::string getFYear() { return this->fYear;}
std::string getTYear() { return this->tYear;}
std::string getFSemester() { return this->fSemester;}
std::string getTSemester() { return this->tSemester;}
private:
std::string fYear; //from
std::string fSemester;
std::string tYear; //to
std::string tSemester;
};
#endif // JCEDATE_H

194
src/jce/jcelogin.cpp Normal file
View file

@ -0,0 +1,194 @@
#include "jcelogin.h"
jceLogin::jceLogin(user * username)
{
this->recieverPage = new std::string();
this->jceA = username;
this->JceConnector = new qtsslsocket(dst_host, dst_port);
}
jceLogin::~jceLogin()
{
this->jceA = NULL;
delete recieverPage;
delete JceConnector;
JceConnector = NULL;
recieverPage = NULL;
}
void jceLogin::makeConnection() throw (jceStatus)
{
jceStatus status;
cout << "Connecting with username: " << jceA->getUsername() << std::endl;
if (checkConnection() == true)
{
cout << "first visiting..." << endl;
if (makeFirstVisit() == true)
{
status = jceStatus::JCE_FIRST_VALIDATION_PASSED;
cout << "validating..." << endl;
if (checkValidation() == true)
{
cout << "singing in" << endl;
status = jceStatus::JCE_SECOND_VALIDATION_PASSED;
if (makeSecondVisit() == true)
{
status = jceStatus::JCE_YOU_ARE_IN;
setLoginFlag(true);
}
else
{
status = jceStatus::ERROR_ON_VALIDATION;
cout << "not in evantually. error!" << std::endl;
}
}
else
{
status = jceStatus::ERROR_ON_VALIDATION;
cout<< "error on validation" << std::endl;
}
}
else
{
cout << "error on first visit" << std::endl;
status = jceStatus::ERROR_ON_VALIDATION_USER_BLOCKED;
}
}
else
{
cout << "error on creating socket" << std::endl;
status = jceStatus::ERROR_ON_OPEN_SOCKET;
}
throw status;
}
bool jceLogin::checkConnection()
{
if (JceConnector->isCon())
return true;
return false;
}
void jceLogin::reConnect() throw (jceStatus)
{
closeAll();
this->recieverPage = new std::string();
this->JceConnector = new qtsslsocket(dst_host, dst_port);
try
{
makeConnection();
}
catch (jceLogin::jceStatus &a)
{
throw a;
}
}
void jceLogin::closeAll()
{
delete recieverPage;
recieverPage = NULL;
JceConnector = NULL;
}
int jceLogin::makeFirstVisit()
{
std::string usr = jceA->getUsername();
std::string psw = jceA->getPassword();
if (JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getFirstValidationStep(*jceA))))
{
if (!JceConnector->recieve(*recieverPage))
return jceLogin::ERROR_ON_GETTING_INFO;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
}
int jceLogin::makeSecondVisit()
{
std::string usrid=jceA->getUserID();
std::string pswid=jceA->getHashedPassword();
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getSecondValidationStep(*jceA)))))
{
if (!(JceConnector->recieve(*recieverPage)))
return jceLogin::ERROR_ON_GETTING_INFO;
return true;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
}
int jceLogin::getGrades()
{
if ((JceConnector->send(jceLoginHtmlScripts::makeRequest(jceLoginHtmlScripts::getGradesPath(*jceA)))))
{
if (!(JceConnector->recieve(*recieverPage)))
return jceLogin::ERROR_ON_GETTING_GRADES;
return true;
}
else
return jceLogin::ERROR_ON_SEND_REQUEST;
return true;
}
void jceLogin::setLoginFlag(bool x)
{
this->loginFlag = x;
}
void jceLogin::setProgressBar(QProgressBar *ptr)
{
this->JceConnector->setProgressBar(ptr);
}
bool jceLogin::isLoginFlag() const
{
return this->loginFlag;
}
std::string jceLogin::getPage()
{
return *recieverPage;
}
bool jceLogin::checkValidation()
{
//finds the hashed password
std::size_t hasspass_position1 = recieverPage->find("-A,-N");
hasspass_position1 += 5;
std::size_t hasspass_position2 = recieverPage->find(",-A,-A", hasspass_position1);
if ((hasspass_position2 != std::string::npos) && (hasspass_position1 != std::string::npos))
{
std::string hasspass = recieverPage->substr(hasspass_position1,hasspass_position2-hasspass_position1);
jceA->setHashedPassword(hasspass);
}
//finds the user id
std::size_t id_position1 = recieverPage->find("value=\"-N", 0);
id_position1 += 9;
std::size_t id_position2 = recieverPage->find(",-A", id_position1);
if ((id_position2 != std::string::npos) && (id_position1 != std::string::npos))
{
std::string hassid = recieverPage->substr(id_position1,id_position2-id_position1);
jceA->setUserID(hassid);
}
if (((jceA->getUserID()).empty()) || ((jceA->getHashedPassword()).empty()))
return false;
return true;
}

64
src/jce/jcelogin.h Normal file
View file

@ -0,0 +1,64 @@
#ifndef JCELOGIN_H
#define JCELOGIN_H
#include <string>
#include <fstream>
#include "../connection/qtsslsocket.h"
#include "../user.h"
#include "jceLoginHtmlScripts.h"
class jceLogin
{
public:
enum jceStatus {
JCE_NOT_CONNECTED,
ERROR_ON_VALIDATION,
ERROR_ON_VALIDATION_USER_BLOCKED,
ERROR_ON_INPUT,
ERROR_ON_CONNECTING,
ERROR_ON_OPEN_SOCKET,
ERROR_ON_GETTING_INFO,
ERROR_ON_GETTING_GRADES,
ERROR_ON_SEND_REQUEST,
JCE_START_VALIDATING_PROGRESS,
JCE_FIRST_VALIDATION_PASSED,
JCE_SECOND_VALIDATION_PASSED,
JCE_YOU_ARE_IN,
JCE_GRADE_PAGE_PASSED
};
jceLogin(user* username);
~jceLogin();
void makeConnection() throw (jceStatus);
bool checkConnection();
void reConnect() throw (jceStatus);
void closeAll();
int getGrades();
bool isLoginFlag() const;
void setProgressBar(QProgressBar *);
std::string getPage();
private:
int makeFirstVisit();
bool checkValidation();
int makeSecondVisit();
void setLoginFlag(bool x);
bool loginFlag;
std::string * recieverPage;
user * jceA;
qtsslsocket * JceConnector;
};
#endif // JCELOGIN_H

52
src/user.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "user.h"
user::user(string username,string password) : hashedPassword(""),userID(""), influenceCourseOnly(false)
{
this->username = username;
this->password = password;
}
user::~user()
{
delete date;
}
void user::setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester)
{
date->setFYear(fromYear);
date->setFSemester(fromSemester);
date->setTYear(toYear);
date->setTSemester(toSemester);
}
void user::setInfluenceCourseOnly(bool status)
{
this->influenceCourseOnly = status;
}
bool user::getInfluenceCourseOnly() const
{
return this->influenceCourseOnly;
}
void user::setUsername(string& username) {
this->username=username;
}
void user::setPassword(string& password) {
this->password=password;
}
void user::setUserID(string& ID)
{
this->userID = ID;
}
void user::setHashedPassword(string& hashpass)
{
this->hashedPassword = hashpass;
}
string user::getPassword() const { return password; }
string user::getUsername() const { return username; }
string user::getUserID() const { return userID; }
string user::getHashedPassword() const { return hashedPassword; }

48
src/user.h Normal file
View file

@ -0,0 +1,48 @@
#ifndef user_H
#define user_H
#include <string>
#include <iostream>
#include "jce/jcedate.h"
using namespace std;
class user
{
public:
user(string username,string password);
~user();
void setUsername(string& username);
void setPassword(string& password);
string getPassword() const;
string getUsername() const;
void setUserID(string& ID);
void setHashedPassword(string& hashpass);
string getUserID() const;
string getHashedPassword() const;
void setDate(std::string fromYear, std::string fromSemester, std::string toYear, std::string toSemester);
void setInfluenceCourseOnly(bool status);
bool getInfluenceCourseOnly() const;
jceDate * const date = new jceDate("","","",""); //we do not change the pointer
private:
string username;
string password;
string hashedPassword;
string userID;
bool influenceCourseOnly;
};
#endif