Added Featcher: Export calendar to CSV format for

GoogleCalendar/iCal/Outlook

at the gui - calendar tab - there is now an export to csv button.
clicking it will prompt thr user to save the file on his system hard
drive. the app will add the .csv extention.

the csv file, will export only one week, starting from the begining of
the first semester of 2015 (the one that is coming).

in the future i will add a Held doc for exporting and importimg to the
users calendar.

cheers!
This commit is contained in:
Sagi Dayan 2014-09-07 22:57:01 +03:00
parent 49e38dbc27
commit 11b4101c58
9 changed files with 198 additions and 4 deletions

View file

@ -36,7 +36,8 @@ HEADERS += \
src/jceSettings/jceLoginHtmlScripts.h \ src/jceSettings/jceLoginHtmlScripts.h \
src/jceSettings/user.h \ src/jceSettings/user.h \
src/jceData/Calendar/calendarCourse.h \ src/jceData/Calendar/calendarCourse.h \
src/jceData/Calendar/calendarSchedule.h src/jceData/Calendar/calendarSchedule.h \
src/jceData/CSV/csv_exporter.h
SOURCES += \ SOURCES += \
main/CalendarTab/CalendarManager.cpp \ main/CalendarTab/CalendarManager.cpp \
@ -53,5 +54,6 @@ SOURCES += \
src/jceSettings/jcelogin.cpp \ src/jceSettings/jcelogin.cpp \
src/jceSettings/user.cpp \ src/jceSettings/user.cpp \
src/jceData/Calendar/calendarCourse.cpp \ src/jceData/Calendar/calendarCourse.cpp \
src/jceData/Calendar/calendarSchedule.cpp src/jceData/Calendar/calendarSchedule.cpp \
src/jceData/CSV/csv_exporter.cpp

View file

@ -9,3 +9,8 @@ void CalendarManager::setCalendar(std::string html)
{ {
caliSchedPtr->setPage(html); caliSchedPtr->setPage(html);
} }
calendarSchedule *CalendarManager::getSch()
{
return this->caliSchedPtr;
}

View file

@ -16,6 +16,7 @@ public:
void setCalendar(std::string html); void setCalendar(std::string html);
void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); } void resetTable() { if (caliSchedPtr != NULL) caliSchedPtr->clearTableItems(); }
calendarSchedule* getSch();
private: private:
calendarSchedule * caliSchedPtr; calendarSchedule * caliSchedPtr;
}; };

View file

@ -291,3 +291,8 @@ void MainScreen::on_actionHow_To_triggered()
"</ul>"); "</ul>");
} }
void MainScreen::on_pushButton_2_clicked()
{
CSV_Exporter::exportCalendar(this->calendar->getSch());
}

View file

@ -13,6 +13,7 @@
#include "./CourseTab/coursestablemanager.h" #include "./CourseTab/coursestablemanager.h"
#include "./LoginTab/loginhandler.h" #include "./LoginTab/loginhandler.h"
#include "./CalendarTab/CalendarManager.h" #include "./CalendarTab/CalendarManager.h"
#include "../src/jceData/CSV/csv_exporter.h"
#define StatusIconHeight 35 #define StatusIconHeight 35
namespace Ui { namespace Ui {
@ -59,6 +60,8 @@ private slots:
void on_checkBoxCoursesInfluence_toggled(bool checked); void on_checkBoxCoursesInfluence_toggled(bool checked);
void on_pushButton_2_clicked();
private: private:
void uiSetDisconnectMode(); void uiSetDisconnectMode();

View file

@ -588,6 +588,13 @@ font-size: 15px;
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Export to CSV</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
@ -619,7 +626,7 @@ font-size: 15px;
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>855</width> <width>855</width>
<height>21</height> <height>29</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuA_about"> <widget class="QMenu" name="menuA_about">

View file

@ -0,0 +1,145 @@
#include "csv_exporter.h"
CSV_Exporter::CSV_Exporter()
{
}
bool CSV_Exporter::exportCalendar(calendarSchedule *calSched)
{
qDebug() << "Getting path for csv file from user...";
QString filePath = getFileFath();
if(filePath == NULL) //User canceled
{
qDebug() << "User pressed Cancel... returning false";
return false;
}
qDebug() << "User Chose: " << filePath;
qDebug() << "Atempting to export the Schedule...";
QFile file(filePath);
if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
{
qDebug() << "unable to open/create the file... maybe permissions error.";
return false;
}//else
QTextStream out(&file);
out << CSV_CALENDAR_HEADER << "\n";
for (calendarCourse *coursePtr: *(calSched->getCourses()))
{
// Subject,Start Date,Start Time,End Date,End Time,Description,Location
int day = coursePtr->getDay();
int startH = coursePtr->getHourBegin();
int startM = coursePtr->getMinutesBegin();
int endH = coursePtr->getHourEnd();
int endM = coursePtr->getMinutesEnd();
QString lecturer = QString(coursePtr->getLecturer().c_str()); //WHY YOU USED STD STRING?!
QString type = QString(coursePtr->getType().c_str());
QString name = QString(coursePtr->getName().c_str());
QString room = QString(coursePtr->getRoom().c_str());
QString line = makeLine(name, day, startH, startM, endH, endM, lecturer, room, type);
if(line != NULL)
out << line << char(0x0A);
}
out.flush();
file.close();
qDebug() << "Saved Successfuly! - HazZaA!";
return true;
}
QString CSV_Exporter::getFileFath()
{
QString fileName = QFileDialog::getSaveFileName();
if(fileName == "")
return NULL;
fileName.append(".csv");
return fileName;
}
QString CSV_Exporter::makeLine(QString name, int day, int startH, int startM, int endH, int endM, QString lecturer, QString room, QString type)
{
//Creating a CSV text line for Google Calendar/iCal/Outlook
// First day for semester 10/26/2014
QString CSV_line = "";
QString subject = "\"";
subject.append(name);
subject.append(" - ");
subject.append(type);
subject.append("\"");
QString date;
switch (day) {
case 1:
date = "10/26/2014";
break;
case 2:
date = "10/27/2014";
break;
case 3:
date = "10/28/2014";
break;
case 4:
date = "10/29/2014";
break;
case 5:
date = "10/30/2014";
break;
case 6:
date = "10/31/2014";
break;
default:
return NULL;
break;
}
QString start;
start.append(QString::number(startH));
start.append(":00");
//start.append(QString::number(startM));
start.append(":00");
QString end;
end.append(QString::number(endH));
end.append(":");
end.append(QString::number(endM));
end.append(":00");
QString description = "\"מרצה ";
description.append(lecturer);
description.append("\n");
description.append(" ב");
description.append(room);
description.append("\"");
//Create the Fucking Line
//Header: Subject,Start Date,Start Time,End Date,End Time,Description,Location
CSV_line.append(subject);
CSV_line.append(",");
CSV_line.append(date);
CSV_line.append(",");
CSV_line.append(start);
CSV_line.append(",");
CSV_line.append(date);
CSV_line.append(",");
CSV_line.append(end);
CSV_line.append(",");
CSV_line.append(description);
CSV_line.append(",");
CSV_line.append("\"JCE Jerusalem\"");
return CSV_line;
}

View file

@ -0,0 +1,26 @@
#ifndef CSV_EXPORTER_H
#define CSV_EXPORTER_H
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QString>
#include <QDebug>
#include "../Calendar/calendarSchedule.h"
#define CSV_CALENDAR_HEADER "Subject,Start Date,Start Time,End Date,End Time,Description,Location"
class CSV_Exporter
{
public:
CSV_Exporter();
static bool exportCalendar(calendarSchedule* calSched);
private:
static QString getFileFath();
static QString makeLine(QString name,int day,int startH,int startM,int endH,int endM,QString lecturer,QString room,QString type);
};
#endif // CSV_EXPORTER_H

View file

@ -20,7 +20,7 @@ public:
calendarSchedule(); calendarSchedule();
~calendarSchedule() { clearTableItems(); } ~calendarSchedule() { clearTableItems(); }
void setPage(std::string html); void setPage(std::string html);
void clearTableItems(); void clearTableItems();
signals: signals: