diff -r f5b689a4f7a2 -r e0c1916b8ddc remotemgmt_plat/syncml_ds_error_reporting_api/tsrc/QtSyncStatusSpy/qtsyncstatuslog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/remotemgmt_plat/syncml_ds_error_reporting_api/tsrc/QtSyncStatusSpy/qtsyncstatuslog.cpp Thu Sep 02 21:22:11 2010 +0300 @@ -0,0 +1,55 @@ +#include +#include +#include +#include "qtsyncstatuslog.h" + +const QString LogFilePath = "C:/logs/Sync/"; +const QString LogFileName = LogFilePath + "QtSyncStatus.txt"; + +QtSyncStatusLog::QtSyncStatusLog() : mLogFile(LogFileName) +{ + open(); +} + +QtSyncStatusLog::~QtSyncStatusLog() +{ + mLogFile.close(); +} + +void QtSyncStatusLog::clear() +{ + mLogFile.remove(); + open(); +} + +void QtSyncStatusLog::write(QString& string) +{ + QTextStream stream(&mLogFile); + stream << string; + stream.flush(); +} + +QStringList QtSyncStatusLog::lines() +{ + QStringList list; + QTextStream stream(&mLogFile); + stream.seek(0); + while (!stream.atEnd()) { + list.append(stream.readLine()); + } + return list; +} + +void QtSyncStatusLog::open() +{ + QDir dir(LogFilePath); + if (!dir.exists()) { + dir.mkpath(LogFilePath); + } + if (!mLogFile.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text)) { + qFatal("error opening log file"); + return; + } +} + +