messagingapp/msgnotifications/msgnotifier/src/main.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 37 518b245aa84c
child 47 5b14749788d7
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
    24 #include "msgnotifier.h"
    24 #include "msgnotifier.h"
    25 #include "debugtraces.h"
    25 #include "debugtraces.h"
    26 
    26 
    27 const QString debugFileName("c:/msgnotifier.txt");
    27 const QString debugFileName("c:/msgnotifier.txt");
    28 
    28 
    29 
       
    30 #ifdef _DEBUG_TRACES_
    29 #ifdef _DEBUG_TRACES_
    31 void debugInit(QtMsgType type, const char *msg)
    30 void debugInit(QtMsgType type, const char *msg)
    32  {
    31 {
    33  
    32 
    34  QFile ofile(debugFileName);
    33     QFile ofile(debugFileName);
    35     if (!ofile.open(QIODevice::Append | QIODevice::Text))
    34     if (!ofile.open(QIODevice::Append | QIODevice::Text)) {
    36     {
       
    37         qFatal("error opening results file");
    35         qFatal("error opening results file");
    38         return;
    36         return;
    39     }
    37     }
    40     QDateTime dt = QDateTime::currentDateTime();
    38     QDateTime dt = QDateTime::currentDateTime();
    41 
    39 
    42     QTextStream out(&ofile);
    40     QTextStream out(&ofile);
    43     switch (type)
    41     switch (type) {
    44     {
    42     case QtDebugMsg:
    45         case QtDebugMsg:
       
    46         out << "\n DEBUG:";
    43         out << "\n DEBUG:";
    47         out << msg;
    44         out << msg;
    48         break;
    45         break;
    49         case QtWarningMsg:
    46     case QtWarningMsg:
    50         out << "\n WARN:";
    47         out << "\n WARN:";
    51         out << msg;
    48         out << msg;
    52         break;
    49         break;
    53         case QtCriticalMsg:
    50     case QtCriticalMsg:
    54         out << "\n ";
    51         out << "\n ";
    55         out << dt.toString("dd/MM/yyyy hh:mm:ss.zzz:ap");
    52         out << dt.toString("dd/MM/yyyy hh:mm:ss.zzz:ap");
    56         out << " CRITICAL:";
    53         out << " CRITICAL:";
    57         out << msg;
    54         out << msg;
    58         break;
    55         break;
    59         case QtFatalMsg:
    56     case QtFatalMsg:
    60         out << "\n FATAL:";
    57         out << "\n FATAL:";
    61         out << msg;
    58         out << msg;
    62         abort();
    59         abort();
    63         break;
    60         break;
    64         default:
    61     default:
    65         out << " No Log Selection Type:";
    62         out << " No Log Selection Type:";
    66         out << msg;
    63         out << msg;
    67         break;
    64         break;
    68 
    65 
    69     }
    66     }
    70  }
    67 }
    71 #endif
    68 #endif
    72 
    69 
    73 int main(int argc,char *argv[])
    70 int main(int argc, char *argv[])
    74 {
    71 {
    75     QCoreApplication app(argc,argv);
    72     QCoreApplication app(argc, argv);
    76     
    73 
    77 #ifdef _DEBUG_TRACES_
    74 #ifdef _DEBUG_TRACES_
    78 	//Debug Logs
    75     //Debug Logs
    79 		QFile ofile;
    76     QFile ofile;
    80     if (ofile.exists(debugFileName)) {
    77     if (ofile.exists(debugFileName)) {
    81     ofile.remove(debugFileName);
    78         ofile.remove(debugFileName);
    82     }
    79     }
    83 	qInstallMsgHandler(debugInit);
    80     qInstallMsgHandler(debugInit);
    84 #endif
    81 #endif
    85 
    82 	  // TODO: Get notifications at startup time.handled later
    86     // create harvester 
    83     QPointer<MsgNotifier> msgNotifier = new MsgNotifier();
    87     QPointer<MsgNotifier> msgNotifier = new MsgNotifier();   
    84     int r = app.exec();
    88     int r = app.exec();    
       
    89     delete msgNotifier;
    85     delete msgNotifier;
    90     return r;
    86     return r;
    91  }
    87 }
    92  
    88