kpilot/kpilot
logFile.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "options.h"
00032
00033 #include <tqfile.h>
00034 #include <tqtextstream.h>
00035 #include <tqdatetime.h>
00036
00037 #include <pi-version.h>
00038
00039 #ifndef PILOT_LINK_PATCH
00040 #define PILOT_LINK_PATCH "unknown"
00041 #endif
00042 #include "logFile.h"
00043 #include "kpilotConfig.h"
00044
00045 #include "logFile.moc"
00046
00047
00048 LogFile::LogFile() : DCOPObject("LogIface"), TQObject(), fOutfile(0L), fSyncing(false)
00049 {
00050 FUNCTIONSETUP;
00051 }
00052
00053
00054 ASYNC LogFile::logStartSync()
00055 {
00056 FUNCTIONSETUP;
00057
00058 if (fSyncing) logEndSync();
00059
00060 fOutfile = new TQFile(KPilotSettings::logFileName());
00061
00062 if (!fOutfile || !fOutfile->open(IO_WriteOnly))
00063 {
00064 WARNINGKPILOT << "Unable to open log file " << KPilotSettings::logFileName() << endl;
00065 KPILOT_DELETE( fOutfile );
00066 fSyncing = false;
00067 return;
00068 }
00069
00070 fSyncing = true;
00071 fLogStream.setDevice(fOutfile);
00072
00073 fLogStream<<(CSL1("KPilot HotSync log, %1").arg(TQDateTime::currentDateTime().toString()))<<endl<<endl<<endl;
00074 fLogStream<<(CSL1("Version: KPilot %1").arg(TQString::fromLatin1(KPILOT_VERSION)))<<endl;
00075 fLogStream<<(CSL1("Version: pilot-link %1.%2.%3%4" )
00076 .arg(PILOT_LINK_VERSION).arg(PILOT_LINK_MAJOR).arg(PILOT_LINK_MINOR)
00077 #ifdef PILOT_LINK_PATCH
00078 .arg(TQString::fromLatin1(PILOT_LINK_PATCH))
00079 #else
00080 .arg(TQString())
00081 #endif
00082 )<<endl;
00083 #ifdef KDE_VERSION_STRING
00084 fLogStream<<(CSL1("Version: KDE %1" ).arg(TQString::fromLatin1(KDE_VERSION_STRING)) )<<endl;
00085 #endif
00086 #ifdef QT_VERSION_STR
00087 fLogStream<<(CSL1("Version: Qt %1" ).arg(TQString::fromLatin1(QT_VERSION_STR)) )<<endl;
00088 #endif
00089 fLogStream<<endl<<endl;
00090
00091 }
00092
00093 ASYNC LogFile::logEndSync()
00094 {
00095 if (fSyncing)
00096 {
00097 logMessage(i18n("HotSync finished."));
00098 fLogStream.unsetDevice();
00099 if (fOutfile) fOutfile->close();
00100 KPILOT_DELETE(fOutfile)
00101 fSyncing=false;
00102 }
00103 }
00104
00105 ASYNC LogFile::logMessage(TQString s)
00106 {
00107 addMessage(s);
00108 }
00109
00110 ASYNC LogFile::logError(TQString s)
00111 {
00112 addMessage(s);
00113 }
00114
00115 ASYNC LogFile::logProgress(TQString, int)
00116 {
00117 }
00118
00119
00120 void LogFile::addMessage(const TQString & s)
00121 {
00122 FUNCTIONSETUP;
00123 if ( fSyncing && !s.isEmpty() )
00124 {
00125 fLogStream<<TQTime::currentTime().toString()<<" "<<s<<endl;
00126 }
00127 }
00128
|