diff --git a/jceGrade.pro b/jceGrade.pro index 82b1ae5..161308d 100644 --- a/jceGrade.pro +++ b/jceGrade.pro @@ -42,7 +42,8 @@ HEADERS += \ src/jceData/Calendar/calendarSchedule.h \ src/jceData/CSV/csv_exporter.h \ src/appDatabase/simplecrypt.h \ - src/jceData/Calendar/calendardialog.h + src/jceData/Calendar/calendardialog.h \ + src/jce_logger.h SOURCES += \ main/CalendarTab/CalendarManager.cpp \ @@ -62,6 +63,7 @@ SOURCES += \ src/jceData/Calendar/calendarSchedule.cpp \ src/jceData/CSV/csv_exporter.cpp \ src/appDatabase/simplecrypt.cpp \ - src/jceData/Calendar/calendardialog.cpp + src/jceData/Calendar/calendardialog.cpp \ + src/jce_logger.cpp diff --git a/main/main.cpp b/main/main.cpp index 93c9496..ada4f6e 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -3,10 +3,13 @@ #include #include #include "../src/appDatabase/savedata.h" +#include "../src/jce_logger.h" int main(int argc, char *argv[]) { + qInstallMessageHandler(jce_logger::customMessageHandler); + qDebug() << "Start : JCE Manager Launched" << Q_FUNC_INFO; QApplication a(argc, argv); QTranslator translator; QString loco; @@ -16,13 +19,22 @@ int main(int argc, char *argv[]) { QString locale = QLocale::system().name(); translator.load("jce_"+locale , a.applicationDirPath()); - }else if(loco == "he") + qDebug() << "Local : Default Local Loaded"; + }else if(loco == "he"){ translator.load("jce_he" , a.applicationDirPath()); - else + qDebug() << "Local : Hebrew Local Loaded"; + }else{ translator.load("jce_en" , a.applicationDirPath()); + qDebug() << "Local : English Local Loaded"; + } a.installTranslator(&translator); MainScreen w; w.show(); - return a.exec(); + int returnCode = a.exec(); + if(returnCode == 0) + qDebug() << "End : JCE Manager Ended Successfully With A Return Code: " << returnCode; + else + qCritical() << "End : JCE Manager Ended Unusccessfully With A Return Code: " << returnCode; + return returnCode; } diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index e40cc49..0d96427 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -8,21 +8,24 @@ CSV_Exporter::CSV_Exporter() bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *cal) { if ((cal == NULL) || (calSched == NULL) || (calSched->getCourses() == NULL)) //pointers checking! + { + qWarning() << "CSV : User trying to export to csv but no calendar was loaded. aborting."; return false; - qDebug() << "Getting path for csv file from user..."; + } + qDebug() << "CSV : Getting path for csv file from user..."; QString filePath = getFileFath(); if(filePath == NULL) //User canceled { - qDebug() << "User pressed Cancel... returning false"; + qDebug() << "CSV : User pressed Cancel... returning false"; return false; } - qDebug() << "User Chose: " << filePath; - qDebug() << "Atempting to export the Schedule..."; + qDebug() << "CSV : User Chose: " << filePath; + qDebug() << "CSV : Atempting to export the Schedule..."; QFile file(filePath); - if(!file.open(QIODevice::ReadWrite | QIODevice::Text |QIODevice::Truncate)) + if(!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) { - qDebug() << "unable to open/create the file... maybe permissions error."; + qCritical() << "CSV : unable to open/create the file... maybe permissions error."; return false; }//else //Delete the file @@ -48,25 +51,17 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca 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 if(line != NULL) out << line << char(0x0A); -#endif -#ifdef Q_OS_OSX - if(line != NULL) - out << line << char(0x0A); -#endif -#ifdef Q_OS_WIN - if(line != NULL) - out << line << char(0x0D) << char(0x0A); -#endif + else + qWarning() << "CSV : Got A NULL in Line! in function: " << Q_FUNC_INFO; } out.flush(); } file.close(); - qDebug() << "Saved Successfuly! - HazZaA!"; + qDebug() << "CSV : Exported Successfully"; return true; } diff --git a/src/jce_logger.cpp b/src/jce_logger.cpp new file mode 100644 index 0000000..cbfe6d1 --- /dev/null +++ b/src/jce_logger.cpp @@ -0,0 +1,37 @@ +#include "jce_logger.h" + +/* + * This Static method will help parsing our debug messages to a readable Log file + * + * timestamp - Message type - message + */ +void jce_logger::customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + Q_UNUSED(context); + + QString dt = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss"); + QString txt = QString("%1\t").arg(dt); + + switch (type) + { + case QtDebugMsg: + txt += QString("DEBUG \t\t %1").arg(msg); + break; + case QtWarningMsg: + txt += QString("WARNING \t %1").arg(msg); + break; + case QtCriticalMsg: + txt += QString("CRITICAL \t %1").arg(msg); + break; + case QtFatalMsg: + txt += QString("FATAL \t\t %1").arg(msg); + abort(); + break; + } + + QFile outFile("J_M_Log.log"); + outFile.open(QIODevice::WriteOnly | QIODevice::Append); + + QTextStream textStream(&outFile); + textStream << txt << endl; +} diff --git a/src/jce_logger.h b/src/jce_logger.h new file mode 100644 index 0000000..eabc222 --- /dev/null +++ b/src/jce_logger.h @@ -0,0 +1,17 @@ +#ifndef JCE_LOGGER_H +#define JCE_LOGGER_H + +#include +#include +#include +#include +#include + +class jce_logger +{ +public: + static void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); + +}; + +#endif // JCE_LOGGER_H