need to fix getting calendar lineToCourse

This commit is contained in:
liranbg 2014-10-05 15:33:57 +03:00
parent 026c6b937c
commit fd612169d7
6 changed files with 1205 additions and 41 deletions

View file

@ -125,13 +125,13 @@ void loginHandler::setLoginFlag(bool flag)
}
QString loginHandler::getCurrentPageContect()
{
QTextEdit phrase;
QTextEdit parse;
if (isLoggedInFlag())
phrase.setText(jceLog->getPage());
parse.setText(jceLog->getPage());
else
throw jceLogin::ERROR_ON_GETTING_INFO;
return phrase.toPlainText();
return parse.toPlainText();
}
int loginHandler::makeGradeRequest(int fromYear, int toYear, int fromSemester, int toSemester)
{

View file

@ -233,39 +233,47 @@ void MainScreen::on_graphButton_clicked()
{
courseTableMgr->showGraph();
}
//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)
{
QString page;
calendar->resetTable();
page = ui->plainTextEdit->toPlainText();
calendar->setCalendar(page);
// 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..."));
// 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"));
}
// //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);
else if (status == jceLogin::JCE_NOT_CONNECTED)
{
qWarning() << Q_FUNC_INFO << "not connected";
QApplication::restoreOverrideCursor();
QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
}
else
qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
}
QApplication::restoreOverrideCursor();
// page = loginHandel->getCurrentPageContect();
// calendar->setCalendar(page);
// ui->progressBar->setValue(100);
// qDebug() << Q_FUNC_INFO << "calendar is loaded";
// ui->statusBar->showMessage(tr("Done"));
// }
// else if (status == jceLogin::JCE_NOT_CONNECTED)
// {
// qWarning() << Q_FUNC_INFO << "not connected";
// QApplication::restoreOverrideCursor();
// QMessageBox::critical(this,tr("Error"),tr("Not Connected"));
// }
// else
// qCritical() << Q_FUNC_INFO << "calendar get ended with" << status;
// }
// QApplication::restoreOverrideCursor();
}
void MainScreen::on_exportToCVSBtn_clicked()
{

File diff suppressed because it is too large Load diff

View file

@ -8,10 +8,13 @@ QString CalendarPage::htmlToString()
void CalendarPage::setPage(QString html)
{
qDebug() << "parsing calendar";
courses = new std::list<calendarCourse*>();
tempHtml = getString(html);
tempHtml = tokenToLines(tempHtml);
qDebug() << "creating courses list";
calendarListInit(tempHtml);
qDebug() << "done";
}
@ -114,6 +117,7 @@ calendarCourse *CalendarPage::lineToCourse(QString line)
else
room = ROOM_DEFAULT_STRING;
qDebug() << serial << name << type << lecturer << points << semesterHours << dayAndHour << room;
tempC = new calendarCourse(serial,name,type,lecturer,points,semesterHours,dayAndHour,room);
return tempC;

View file

@ -37,8 +37,8 @@ calendarSchedule::calendarSchedule()
void calendarSchedule::setPage(QString html)
{
CalendarPage::setPage(html);
insertCourseIntoTable();
qDebug() << Q_FUNC_INFO << "inserting into table";
// insertCourseIntoTable();
}
void calendarSchedule::clearTableItems()
@ -57,15 +57,17 @@ void calendarSchedule::insertCourseIntoTable()
QTableWidgetItem *item;
QString courseString;
int currentHour,currentDay,blocksNumer;
int currentHour,currentDay,blocksNumber;
int row,col;
for (calendarCourse *coursePtr: *getCourses())
{
qDebug() << coursePtr->getSerialNum();
courseString = "";
currentHour = coursePtr->getHourBegin();
currentDay = coursePtr->getDay();
blocksNumer = coursePtr->getHourEnd() - coursePtr->getHourBegin(); //every hour is a block to fill!
while (blocksNumer >= 0)
blocksNumber = coursePtr->getHourEnd() - coursePtr->getHourBegin(); //every hour is a block to fill!
qDebug() << blocksNumber;
while (blocksNumber >= 0)
{
row = currentHour - HOURS_BEGIN;
col = currentDay-1;
@ -88,7 +90,7 @@ void calendarSchedule::insertCourseIntoTable()
this->setItem(row,col,item);
currentHour++;
--blocksNumer;
--blocksNumber;
}
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

View file

@ -36,7 +36,8 @@ void Page::manageTableContent(QString &html, int index)
QString tableTag = html.mid(i, 4); //legth of "tr/td"
if (tableTag == "<tr>")
{
temp += dateHeader;
if (!dateHeader.isEmpty())
temp += dateHeader;
i = stitchText(html, temp, i+4);
if (i == -1) //EOF
break;
@ -49,7 +50,8 @@ void Page::manageTableContent(QString &html, int index)
}
else if (tableTag == "<td>" || tableTag == "<th>")
{
temp += "\t"; // new cell -> tab between data
if (!dateHeader.isEmpty())
temp += "\t"; // new cell -> tab between data
if (html.mid(i, 6) == "<td><a") //link to lecturer portal, need to be deleted
{
i += 6;
@ -58,19 +60,28 @@ void Page::manageTableContent(QString &html, int index)
}
else
i = stitchText(html, temp, i+4);
if (dateHeader.isEmpty())
temp += "\t";
if (i == -1) //EOF
break;
}
else if (tableTag == "<td ") // a Year title (in grades table)
{
if (!dateHeader.isEmpty())
if (!temp.isEmpty())
if (temp.lastIndexOf(dateHeader) == temp.length()-dateHeader.length())
{
temp.chop(dateHeader.length()+1);
temp += "\t";
}
while (html.mid(i,3) != "<b>")
while ((html.mid(i,3) != "<b>") && (i < (int)html.length()))
{
if (html.mid(i,5) == "</td>")
break;
i++;
}
i = stitchText(html, temp, i);
}