X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fcpp%2Flogutility.h;h=b7626161df105fbcd9265b0dad86c2000b7d8c29;hb=526c6066678d5eaa6ca355ee7c2073b83eab7e81;hp=530ba9679749bbcc53b3205d73972ed5c5cb7076;hpb=e372f6ea9613e5f38d1ecd667ca3783935ded76c;p=marketstoday diff --git a/src/cpp/logutility.h b/src/cpp/logutility.h index 530ba96..b762616 100644 --- a/src/cpp/logutility.h +++ b/src/cpp/logutility.h @@ -1,5 +1,5 @@ /* -@version: 0.1 +@version: 0.4 @author: Sudheer K. @license: GNU General Public License */ @@ -10,17 +10,36 @@ #include #include #include +#include class LogUtility : public QObject { Q_OBJECT +private: + QFile * logFile; + public: LogUtility(QObject *parent = 0) : QObject(parent){ + QString strPath; +#if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) + //For maemo fremantle or harmattan use a common path + strPath = QDir().homePath() + "/.marketstoday/marketstoday.log"; +#else + strPath = "marketstoday.log"; +#endif + logFile = new QFile(strPath,this); + + if (!logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { + qDebug() << "MT: Error opening logfile for writing"; + } } + ~LogUtility(){ + if (logFile->isOpen()) + logFile->close(); qDebug() << "Markets Today: In LogUtility object destructor.."; } @@ -28,21 +47,13 @@ public slots: void logMessage(QString strMessage) { QString strTimeNow = QDateTime::currentDateTime().toString("dd-MMM-yyyy HH:mm:ss"); - qDebug() << QString("Markets Today: [%1] - %2").arg(strTimeNow,strMessage); - -#ifdef Q_WS_MAEMO_5 - //For maemo use a common path - QFile logFile("/home/user/.marketstoday/marketstoday.log"); -#else - QFile logFile("marketstoday.log"); -#endif - - if (!logFile.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text)) { return; } + qDebug() << QString("MT: [%1] - %2").arg(strTimeNow,strMessage); - QTextStream logStream(&logFile); - logStream << QString("Markets Today: [%1] - %2").arg(strTimeNow,strMessage) << endl; + if (logFile->isOpen() && logFile->isWritable()) { + QTextStream logStream(logFile); + logStream << QString("[%1] - %2").arg(strTimeNow,strMessage) << endl; + } } }; #endif // LOGUTILITY_H -;