remotemgmt_plat/syncml_ds_error_reporting_api/tsrc/QtSyncStatusSpy/qtsyncstatuslog.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 25 b183ec05bd8c
child 27 5cc2995847ea
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
     1 #include <qtextstream.h>
       
     2 #include <qstringlist.h>
       
     3 #include <qdir.h>
       
     4 #include "qtsyncstatuslog.h"
       
     5 
       
     6 const QString LogFilePath = "C:/logs/Sync/";
       
     7 const QString LogFileName = LogFilePath + "QtSyncStatus.txt";
       
     8 
       
     9 QtSyncStatusLog::QtSyncStatusLog() : mLogFile(LogFileName)
       
    10 {
       
    11     open();
       
    12 }
       
    13 
       
    14 QtSyncStatusLog::~QtSyncStatusLog()
       
    15 {
       
    16     mLogFile.close();
       
    17 }
       
    18 
       
    19 void QtSyncStatusLog::clear()
       
    20 {
       
    21     mLogFile.remove();
       
    22     open();    
       
    23 }
       
    24 
       
    25 void QtSyncStatusLog::write(QString& string)
       
    26 {
       
    27     QTextStream stream(&mLogFile);
       
    28     stream << string;
       
    29     stream.flush();
       
    30 }
       
    31 
       
    32 QStringList QtSyncStatusLog::lines()
       
    33 {
       
    34     QStringList list;
       
    35     QTextStream stream(&mLogFile);
       
    36     stream.seek(0);
       
    37     while (!stream.atEnd()) {
       
    38         list.append(stream.readLine());
       
    39     }
       
    40     return list;
       
    41 }
       
    42 
       
    43 void QtSyncStatusLog::open()
       
    44 {
       
    45     QDir dir(LogFilePath);
       
    46     if (!dir.exists()) {
       
    47         dir.mkpath(LogFilePath);
       
    48     }
       
    49     if (!mLogFile.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text)) {
       
    50         qFatal("error opening log file");
       
    51         return;
       
    52     }    
       
    53 }
       
    54 
       
    55