fixed the null pointer error on csv exportion

This commit is contained in:
liranbg 2014-09-17 05:47:12 +03:00
parent 13eef8a2ed
commit c3345399f4
10 changed files with 116 additions and 116 deletions

View file

@ -16,7 +16,7 @@ TRANSLATIONS = jce_en.ts \
FORMS += \ FORMS += \
main/mainscreen.ui \ main/mainscreen.ui \
src/jceData/Calendar/calendardialog.ui src/jceData/Calendar/calendarDialog.ui
OTHER_FILES += OTHER_FILES +=
@ -42,7 +42,7 @@ HEADERS += \
src/jceData/Calendar/calendarSchedule.h \ src/jceData/Calendar/calendarSchedule.h \
src/jceData/CSV/csv_exporter.h \ src/jceData/CSV/csv_exporter.h \
src/appDatabase/simplecrypt.h \ src/appDatabase/simplecrypt.h \
src/jceData/Calendar/calendardialog.h src/jceData/Calendar/calendarDialog.h
SOURCES += \ SOURCES += \
main/CalendarTab/CalendarManager.cpp \ main/CalendarTab/CalendarManager.cpp \
@ -62,6 +62,6 @@ SOURCES += \
src/jceData/Calendar/calendarSchedule.cpp \ src/jceData/Calendar/calendarSchedule.cpp \
src/jceData/CSV/csv_exporter.cpp \ src/jceData/CSV/csv_exporter.cpp \
src/appDatabase/simplecrypt.cpp \ src/appDatabase/simplecrypt.cpp \
src/jceData/Calendar/calendardialog.cpp src/jceData/Calendar/calendarDialog.cpp

View file

@ -10,37 +10,30 @@ void CalendarManager::setCalendar(QString html)
{ {
caliSchedPtr->setPage(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()) qDebug() << this->caliSchedPtr->getCourses();
return false; if (this->caliSchedPtr->getCourses() == NULL)
return;
QMessageBox msgBox; QMessageBox msgBox;
int buttonClicked = caliDialog->exec(); int buttonClicked = caliDialog->exec();
if (buttonClicked == 0) //cancel? if (buttonClicked == 0) //cancel?
return false; return;
//calDialog.getStartDate(),calDialog.getEndDate() //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.setIcon(QMessageBox::Information);
msgBox.setText(QObject::tr("Exported Successfuly!")); 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 else
{ {
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText(QObject::tr("Dates not valid")); msgBox.setText(QObject::tr("Dates not valid"));
msgBox.exec();
} }
return false; msgBox.exec();
} }

View file

@ -17,7 +17,7 @@ public:
delete caliSchedPtr; delete caliSchedPtr;
delete caliDialog; delete caliDialog;
} }
bool exportCalendarCSV(); void exportCalendarCSV();
void setCalendar(QString html); void setCalendar(QString html);
void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); } void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); }

View file

@ -170,7 +170,6 @@ void MainScreen::uiSetConnectMode()
ui->CoursesTab->setEnabled(true); ui->CoursesTab->setEnabled(true);
ui->exportToCVSBtn->setEnabled(true); ui->exportToCVSBtn->setEnabled(true);
ui->getCalendarBtn->setEnabled(true); ui->getCalendarBtn->setEnabled(true);
} }
else else
{ {
@ -277,10 +276,8 @@ void MainScreen::on_exportToCVSBtn_clicked()
{ {
if (loginHandel->isLoggedInFlag()) if (loginHandel->isLoggedInFlag())
{ {
if(!this->calendar->exportCalendarCSV()) this->calendar->exportCalendarCSV();
{
QMessageBox::critical(this,tr("Error"),"No Calendar was loaded."); //Need Translation
}
} }
} }

View file

@ -240,7 +240,7 @@ void jceSSLClient::showIfErrorMsg()
break; break;
case QAbstractSocket::SocketError::SocketTimeoutError: case QAbstractSocket::SocketError::SocketTimeoutError:
errorString = QObject::tr("SocketTimeoutError"); errorString = QObject::tr("SocketTimeoutError");
if (isConnected()) if (!isConnected())
relevantError = true; relevantError = true;
break; break;
case QAbstractSocket::SocketError::DatagramTooLargeError: case QAbstractSocket::SocketError::DatagramTooLargeError:

View file

@ -7,11 +7,15 @@ CSV_Exporter::CSV_Exporter()
bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal) 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; return false;
if (calSched->getCourses() == NULL)
{
return false;
}
qDebug() << "Getting path for csv file from user..."; qDebug() << "Getting path for csv file from user...";
QString filePath = getFileFath(); QString filePath = getFileFath();
if(filePath == NULL) //User canceled if (filePath == NULL) //User canceled
{ {
qDebug() << "User pressed Cancel... returning false"; qDebug() << "User pressed Cancel... returning false";
return false; return false;
@ -20,7 +24,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
qDebug() << "Atempting to export the Schedule..."; qDebug() << "Atempting to export the Schedule...";
QFile file(filePath); 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."; qDebug() << "unable to open/create the file... maybe permissions error.";
return false; return false;
@ -45,7 +49,7 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
currentDate = currentDate.addDays(day-1); 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, &currentDate, startH, startM, endH, endM, lecturer, room, type); QString line = makeLine(name, &currentDate, startH, startM, endH, endM, lecturer, room, type);
#ifdef Q_OS_LINUX || Q_OS_UNIX #ifdef Q_OS_LINUX || Q_OS_UNIX
@ -74,9 +78,9 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca
QString CSV_Exporter::getFileFath() QString CSV_Exporter::getFileFath()
{ {
QString fileName = QFileDialog::getSaveFileName(); QString fileName = QFileDialog::getSaveFileName();
if(fileName == "") if (fileName == "")
return NULL; return NULL;
if(!fileName.contains(".csv", Qt::CaseInsensitive)) if (!fileName.contains(".csv", Qt::CaseInsensitive))
fileName.append(".csv"); fileName.append(".csv");
return fileName; return fileName;
} }

View file

@ -8,30 +8,34 @@ calendarCourse::calendarCourse(int serial, QString name, QString type, QString l
this->semesterHours = semesterHours; this->semesterHours = semesterHours;
this->room = room; this->room = room;
setDayAndHour(dayAndHour); 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; int ctr = 0;
QString temp = ""; QString temp = "";
QTime timetemp; QTime timetemp;
char *tok; char *tok;
char* textToTok = strdup(phrase.toStdString().c_str()); char* textToTok = strdup(parse.toStdString().c_str());
tok = strtok(textToTok, " -"); tok = strtok(textToTok, " -");
while(tok != NULL) while(tok != NULL)
{ {
temp = tok; temp = tok;
switch (ctr) switch (ctr)
{ {
case 0: case 0: //day
setDay(temp); setDay(temp);
break; break;
case 1: case 1: //hour it begins
timetemp = QTime::fromString(temp,"hh:mm"); timetemp = QTime::fromString(temp,"hh:mm");
setHourBegin(timetemp.hour()); setHourBegin(timetemp.hour());
setMinutesBegin(timetemp.minute()); setMinutesBegin(timetemp.minute());
break; break;
case 2: case 2: //hour it ends
timetemp = QTime::fromString(temp,"hh:mm"); timetemp = QTime::fromString(temp,"hh:mm");
setHourEnd(timetemp.hour()); setHourEnd(timetemp.hour());
setMinutesEnd(timetemp.minute()); setMinutesEnd(timetemp.minute());
@ -97,7 +101,10 @@ void calendarCourse::setMinutesEnd(int value)
{ {
minutesEnd = value; minutesEnd = value;
} }
/**
* @brief calendarCourse::courseToString
* @return prints the course into string pattern
*/
QString calendarCourse::courseToString() QString calendarCourse::courseToString()
{ {
QString courseText = ""; QString courseText = "";
@ -118,7 +125,11 @@ int calendarCourse::getDay() const
{ {
return day; 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) void calendarCourse::setDay(const QString &value)
{ {
std::string dayTemp = value.toStdString().substr(0,2); //recieving two characters respresting days std::string dayTemp = value.toStdString().substr(0,2); //recieving two characters respresting days
@ -137,7 +148,6 @@ void calendarCourse::setDay(const QString &value)
else else
day= -1; day= -1;
} }
QString calendarCourse::getRoom() const QString calendarCourse::getRoom() const
{ {
return room; return room;

View file

@ -2,10 +2,6 @@
#define CALENDARCOURSE_H #define CALENDARCOURSE_H
#include "../course.h" #include "../course.h"
#include <string>
#include <iostream>
#include <list>
#include <QTime> #include <QTime>
#define CALENDAR_COURSE_FIELDS 8 #define CALENDAR_COURSE_FIELDS 8
@ -51,7 +47,7 @@ public:
private: private:
void setDayAndHour(QString phrase); void setDayAndHour(QString parse);
QString lecturer; QString lecturer;
double semesterHours; double semesterHours;

View file

@ -17,7 +17,7 @@ public:
protected: protected:
virtual void setPage(QString html); virtual void setPage(QString html);
CalendarPage() { } CalendarPage() { courses = NULL; }
private: private:

View file

@ -1,5 +1,5 @@
#include "calendardialog.h" #include "calendarDialog.h"
#include "ui_calendardialog.h" #include "ui_calenDardialog.h"
CalendarDialog::CalendarDialog(QWidget *parent) : CalendarDialog::CalendarDialog(QWidget *parent) :
@ -35,7 +35,7 @@ void CalendarDialog::on_calStart_selectionChanged()
if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate()) if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate())
{ {
changeLabeStatusIcon(false); 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; this->isOK = false;
} }
else else
@ -49,7 +49,7 @@ void CalendarDialog::on_calStart_selectionChanged()
void CalendarDialog::on_buttonBox_accepted() void CalendarDialog::on_buttonBox_accepted()
{ {
if(ui->calStart->selectedDate() > ui->calEnd->selectedDate()) if(ui->calStart->selectedDate() > ui->calEnd->selectedDate())
qDebug() << "start bigger than end!"; qDebug() << "start is bigger than end!";
} }
void CalendarDialog::on_calEnd_selectionChanged() void CalendarDialog::on_calEnd_selectionChanged()
@ -57,7 +57,7 @@ void CalendarDialog::on_calEnd_selectionChanged()
if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate()) if(ui->calStart->selectedDate() >= ui->calEnd->selectedDate())
{ {
changeLabeStatusIcon(false); 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; this->isOK = false;
} }
else else