From c3345399f4acb3dbdc8134922cde383890f83576 Mon Sep 17 00:00:00 2001 From: liranbg Date: Wed, 17 Sep 2014 05:47:12 +0300 Subject: [PATCH] fixed the null pointer error on csv exportion --- jceGrade.pro | 134 ++++++++++++------------ main/CalendarTab/CalendarManager.cpp | 25 ++--- main/CalendarTab/CalendarManager.h | 2 +- main/mainscreen.cpp | 7 +- src/jceConnection/jcesslclient.cpp | 2 +- src/jceData/CSV/csv_exporter.cpp | 16 +-- src/jceData/Calendar/calendarCourse.cpp | 28 +++-- src/jceData/Calendar/calendarCourse.h | 6 +- src/jceData/Calendar/calendarPage.h | 2 +- src/jceData/Calendar/calendardialog.cpp | 10 +- 10 files changed, 116 insertions(+), 116 deletions(-) diff --git a/jceGrade.pro b/jceGrade.pro index 00ecad1..5bdecb2 100644 --- a/jceGrade.pro +++ b/jceGrade.pro @@ -1,67 +1,67 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-05-31T19:49:42 -# -#------------------------------------------------- - -QT += core gui network widgets -TARGET = jceGrade -TEMPLATE = app -RC_FILE = appConfigure.rc -CONFIG += qt c++11 -CONFIG += console static - -TRANSLATIONS = jce_en.ts \ - jce_he.ts - -FORMS += \ - main/mainscreen.ui \ - src/jceData/Calendar/calendardialog.ui - -OTHER_FILES += - -RESOURCES += \ - resources/connectionstatus.qrc - -HEADERS += \ - main/CalendarTab/CalendarManager.h \ - main/CourseTab/coursestablemanager.h \ - main/LoginTab/loginhandler.h \ - main/mainscreen.h \ - src/appDatabase/savedata.h \ - src/jceConnection/jcesslclient.h \ - src/jceData/Calendar/calendarPage.h \ - src/jceData/Grades/gradeCourse.h \ - src/jceData/Grades/gradePage.h \ - src/jceData/course.h \ - src/jceData/page.h \ - src/jceSettings/jcelogin.h \ - src/jceSettings/jceLoginHtmlScripts.h \ - src/jceSettings/user.h \ - src/jceData/Calendar/calendarCourse.h \ - src/jceData/Calendar/calendarSchedule.h \ - src/jceData/CSV/csv_exporter.h \ - src/appDatabase/simplecrypt.h \ - src/jceData/Calendar/calendardialog.h - -SOURCES += \ - main/CalendarTab/CalendarManager.cpp \ - main/CourseTab/coursestablemanager.cpp \ - main/LoginTab/loginhandler.cpp \ - main/main.cpp \ - main/mainscreen.cpp \ - src/appDatabase/savedata.cpp \ - src/jceConnection/jcesslclient.cpp \ - src/jceData/Calendar/calendarPage.cpp \ - src/jceData/Grades/gradeCourse.cpp \ - src/jceData/Grades/gradePage.cpp \ - src/jceData/page.cpp \ - src/jceSettings/jcelogin.cpp \ - src/jceSettings/user.cpp \ - src/jceData/Calendar/calendarCourse.cpp \ - src/jceData/Calendar/calendarSchedule.cpp \ - src/jceData/CSV/csv_exporter.cpp \ - src/appDatabase/simplecrypt.cpp \ - src/jceData/Calendar/calendardialog.cpp - - +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-31T19:49:42 +# +#------------------------------------------------- + +QT += core gui network widgets +TARGET = jceGrade +TEMPLATE = app +RC_FILE = appConfigure.rc +CONFIG += qt c++11 +CONFIG += console static + +TRANSLATIONS = jce_en.ts \ + jce_he.ts + +FORMS += \ + main/mainscreen.ui \ + src/jceData/Calendar/calendarDialog.ui + +OTHER_FILES += + +RESOURCES += \ + resources/connectionstatus.qrc + +HEADERS += \ + main/CalendarTab/CalendarManager.h \ + main/CourseTab/coursestablemanager.h \ + main/LoginTab/loginhandler.h \ + main/mainscreen.h \ + src/appDatabase/savedata.h \ + src/jceConnection/jcesslclient.h \ + src/jceData/Calendar/calendarPage.h \ + src/jceData/Grades/gradeCourse.h \ + src/jceData/Grades/gradePage.h \ + src/jceData/course.h \ + src/jceData/page.h \ + src/jceSettings/jcelogin.h \ + src/jceSettings/jceLoginHtmlScripts.h \ + src/jceSettings/user.h \ + src/jceData/Calendar/calendarCourse.h \ + src/jceData/Calendar/calendarSchedule.h \ + src/jceData/CSV/csv_exporter.h \ + src/appDatabase/simplecrypt.h \ + src/jceData/Calendar/calendarDialog.h + +SOURCES += \ + main/CalendarTab/CalendarManager.cpp \ + main/CourseTab/coursestablemanager.cpp \ + main/LoginTab/loginhandler.cpp \ + main/main.cpp \ + main/mainscreen.cpp \ + src/appDatabase/savedata.cpp \ + src/jceConnection/jcesslclient.cpp \ + src/jceData/Calendar/calendarPage.cpp \ + src/jceData/Grades/gradeCourse.cpp \ + src/jceData/Grades/gradePage.cpp \ + src/jceData/page.cpp \ + src/jceSettings/jcelogin.cpp \ + src/jceSettings/user.cpp \ + src/jceData/Calendar/calendarCourse.cpp \ + src/jceData/Calendar/calendarSchedule.cpp \ + src/jceData/CSV/csv_exporter.cpp \ + src/appDatabase/simplecrypt.cpp \ + src/jceData/Calendar/calendarDialog.cpp + + diff --git a/main/CalendarTab/CalendarManager.cpp b/main/CalendarTab/CalendarManager.cpp index 0dec0b4..e141332 100644 --- a/main/CalendarTab/CalendarManager.cpp +++ b/main/CalendarTab/CalendarManager.cpp @@ -10,37 +10,30 @@ void CalendarManager::setCalendar(QString html) { caliSchedPtr->setPage(html); } -bool CalendarManager::exportCalendarCSV() //need to add fix to the null pointer bug +void CalendarManager::exportCalendarCSV() //need to add fix to the null pointer bug { - if (this->caliSchedPtr->getCourses()->empty()) - return false; + qDebug() << this->caliSchedPtr->getCourses(); + if (this->caliSchedPtr->getCourses() == NULL) + return; QMessageBox msgBox; int buttonClicked = caliDialog->exec(); if (buttonClicked == 0) //cancel? - return false; + return; //calDialog.getStartDate(),calDialog.getEndDate() - if(caliDialog->ok()) + if (caliDialog->ok()) { - if(CSV_Exporter::exportCalendar(caliSchedPtr, caliDialog)) + if (CSV_Exporter::exportCalendar(caliSchedPtr, caliDialog)) { msgBox.setIcon(QMessageBox::Information); msgBox.setText(QObject::tr("Exported Successfuly!")); - msgBox.exec(); - return true; - }else - { - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText(QObject::tr("Error on exporting.")); - msgBox.exec(); } } else { msgBox.setIcon(QMessageBox::Critical); - msgBox.setText(QObject::tr("Dates not valid")); - msgBox.exec(); + msgBox.setText(QObject::tr("Dates not valid")); } - return false; + msgBox.exec(); } diff --git a/main/CalendarTab/CalendarManager.h b/main/CalendarTab/CalendarManager.h index b3e4ef5..766fff3 100644 --- a/main/CalendarTab/CalendarManager.h +++ b/main/CalendarTab/CalendarManager.h @@ -17,7 +17,7 @@ public: delete caliSchedPtr; delete caliDialog; } - bool exportCalendarCSV(); + void exportCalendarCSV(); void setCalendar(QString html); void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); } diff --git a/main/mainscreen.cpp b/main/mainscreen.cpp index 25e005b..c082097 100644 --- a/main/mainscreen.cpp +++ b/main/mainscreen.cpp @@ -170,7 +170,6 @@ void MainScreen::uiSetConnectMode() ui->CoursesTab->setEnabled(true); ui->exportToCVSBtn->setEnabled(true); ui->getCalendarBtn->setEnabled(true); - } else { @@ -277,10 +276,8 @@ void MainScreen::on_exportToCVSBtn_clicked() { if (loginHandel->isLoggedInFlag()) { - if(!this->calendar->exportCalendarCSV()) - { - QMessageBox::critical(this,tr("Error"),"No Calendar was loaded."); //Need Translation - } + this->calendar->exportCalendarCSV(); + } } diff --git a/src/jceConnection/jcesslclient.cpp b/src/jceConnection/jcesslclient.cpp index e0fe79b..bc28116 100644 --- a/src/jceConnection/jcesslclient.cpp +++ b/src/jceConnection/jcesslclient.cpp @@ -240,7 +240,7 @@ void jceSSLClient::showIfErrorMsg() break; case QAbstractSocket::SocketError::SocketTimeoutError: errorString = QObject::tr("SocketTimeoutError"); - if (isConnected()) + if (!isConnected()) relevantError = true; break; case QAbstractSocket::SocketError::DatagramTooLargeError: diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index 0168c9e..385949a 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -7,11 +7,15 @@ CSV_Exporter::CSV_Exporter() bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal) { - if ((cal == NULL) || (calSched == NULL) || (calSched->getCourses() == NULL)) //pointers checking! + if ((cal == NULL) || (calSched == NULL)) //pointers checking! return false; + if (calSched->getCourses() == NULL) + { + return false; + } qDebug() << "Getting path for csv file from user..."; QString filePath = getFileFath(); - if(filePath == NULL) //User canceled + if (filePath == NULL) //User canceled { qDebug() << "User pressed Cancel... returning false"; return false; @@ -20,7 +24,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca qDebug() << "Atempting to export the Schedule..."; QFile file(filePath); - if(!file.open(QIODevice::ReadWrite | QIODevice::Text |QIODevice::Truncate)) + if (!file.open(QIODevice::ReadWrite | QIODevice::Text |QIODevice::Truncate)) { qDebug() << "unable to open/create the file... maybe permissions error."; return false; @@ -45,7 +49,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca currentDate = currentDate.addDays(day-1); - for(;currentDate <= cal->getEndDate(); currentDate = currentDate.addDays(7)) + for (;currentDate <= cal->getEndDate(); currentDate = currentDate.addDays(7)) { QString line = makeLine(name, ¤tDate, startH, startM, endH, endM, lecturer, room, type); #ifdef Q_OS_LINUX || Q_OS_UNIX @@ -74,9 +78,9 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca QString CSV_Exporter::getFileFath() { QString fileName = QFileDialog::getSaveFileName(); - if(fileName == "") + if (fileName == "") return NULL; - if(!fileName.contains(".csv", Qt::CaseInsensitive)) + if (!fileName.contains(".csv", Qt::CaseInsensitive)) fileName.append(".csv"); return fileName; } diff --git a/src/jceData/Calendar/calendarCourse.cpp b/src/jceData/Calendar/calendarCourse.cpp index 88e9502..5fec893 100644 --- a/src/jceData/Calendar/calendarCourse.cpp +++ b/src/jceData/Calendar/calendarCourse.cpp @@ -8,30 +8,34 @@ calendarCourse::calendarCourse(int serial, QString name, QString type, QString l this->semesterHours = semesterHours; this->room = room; setDayAndHour(dayAndHour); - } -void calendarCourse::setDayAndHour(QString phrase) +/** + * @brief calendarCourse::setDayAndHour + * given a string of time and day - parsing it into day, hour it begins and hour it ends seperated + * @param parse - + */ +void calendarCourse::setDayAndHour(QString parse) { int ctr = 0; QString temp = ""; QTime timetemp; char *tok; - char* textToTok = strdup(phrase.toStdString().c_str()); + char* textToTok = strdup(parse.toStdString().c_str()); tok = strtok(textToTok, " -"); while(tok != NULL) { temp = tok; switch (ctr) { - case 0: + case 0: //day setDay(temp); break; - case 1: + case 1: //hour it begins timetemp = QTime::fromString(temp,"hh:mm"); setHourBegin(timetemp.hour()); setMinutesBegin(timetemp.minute()); break; - case 2: + case 2: //hour it ends timetemp = QTime::fromString(temp,"hh:mm"); setHourEnd(timetemp.hour()); setMinutesEnd(timetemp.minute()); @@ -97,7 +101,10 @@ void calendarCourse::setMinutesEnd(int value) { minutesEnd = value; } - +/** + * @brief calendarCourse::courseToString + * @return prints the course into string pattern + */ QString calendarCourse::courseToString() { QString courseText = ""; @@ -118,7 +125,11 @@ int calendarCourse::getDay() const { return day; } - +/** + * @brief calendarCourse::setDay + * translating a day that written with hebrew unicode character to an integer + * @param value - contains the day in unicode + */ void calendarCourse::setDay(const QString &value) { std::string dayTemp = value.toStdString().substr(0,2); //recieving two characters respresting days @@ -137,7 +148,6 @@ void calendarCourse::setDay(const QString &value) else day= -1; } - QString calendarCourse::getRoom() const { return room; diff --git a/src/jceData/Calendar/calendarCourse.h b/src/jceData/Calendar/calendarCourse.h index 121c646..9659d69 100644 --- a/src/jceData/Calendar/calendarCourse.h +++ b/src/jceData/Calendar/calendarCourse.h @@ -2,10 +2,6 @@ #define CALENDARCOURSE_H #include "../course.h" -#include -#include -#include - #include #define CALENDAR_COURSE_FIELDS 8 @@ -51,7 +47,7 @@ public: private: - void setDayAndHour(QString phrase); + void setDayAndHour(QString parse); QString lecturer; double semesterHours; diff --git a/src/jceData/Calendar/calendarPage.h b/src/jceData/Calendar/calendarPage.h index 74dfbe9..5ee4721 100644 --- a/src/jceData/Calendar/calendarPage.h +++ b/src/jceData/Calendar/calendarPage.h @@ -17,7 +17,7 @@ public: protected: virtual void setPage(QString html); - CalendarPage() { } + CalendarPage() { courses = NULL; } private: diff --git a/src/jceData/Calendar/calendardialog.cpp b/src/jceData/Calendar/calendardialog.cpp index 4ca3c93..fb17d3a 100644 --- a/src/jceData/Calendar/calendardialog.cpp +++ b/src/jceData/Calendar/calendardialog.cpp @@ -1,5 +1,5 @@ -#include "calendardialog.h" -#include "ui_calendardialog.h" +#include "calendarDialog.h" +#include "ui_calenDardialog.h" CalendarDialog::CalendarDialog(QWidget *parent) : @@ -35,7 +35,7 @@ void CalendarDialog::on_calStart_selectionChanged() if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate()) { changeLabeStatusIcon(false); - ui->lbl_status->setText(tr("The End of the semester can NOT be equal or before semester begins.")); + ui->lbl_status->setText(tr("The end of the semester can NOT be equal or before the semester begin.")); this->isOK = false; } else @@ -49,7 +49,7 @@ void CalendarDialog::on_calStart_selectionChanged() void CalendarDialog::on_buttonBox_accepted() { if(ui->calStart->selectedDate() > ui->calEnd->selectedDate()) - qDebug() << "start bigger than end!"; + qDebug() << "start is bigger than end!"; } void CalendarDialog::on_calEnd_selectionChanged() @@ -57,7 +57,7 @@ void CalendarDialog::on_calEnd_selectionChanged() if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate()) { changeLabeStatusIcon(false); - ui->lbl_status->setText(tr("The End of the semester can NOT be equal or before semester begins.")); + ui->lbl_status->setText(tr("The end of the semester can NOT be equal or before semester begins.")); this->isOK = false; } else