kpilot/kpilot

logFile.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 ** Copyright (C) 2004 by Reinhold Kainhofer
00005 **
00006 ** This file defines the log file class, which logs
00007 ** sync-messages during a HotSync to a file.
00008 */
00009 
00010 /*
00011 ** This program is free software; you can redistribute it and/or modify
00012 ** it under the terms of the GNU General Public License as published by
00013 ** the Free Software Foundation; either version 2 of the License, or
00014 ** (at your option) any later version.
00015 **
00016 ** This program is distributed in the hope that it will be useful,
00017 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 ** GNU General Public License for more details.
00020 **
00021 ** You should have received a copy of the GNU General Public License
00022 ** along with this program in a file called COPYING; if not, write to
00023 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 ** MA 02110-1301, USA.
00025 */
00026 
00027 /*
00028 ** Bug reports and questions can be sent to kde-pim@kde.org.
00029 */
00030 static const char *logf_id =
00031     "$Id: logFile.cc 437980 2005-07-23 19:53:57Z kainhofe $";
00032 
00033 #include "options.h"
00034 
00035 #include <qfile.h>
00036 #include <qtextstream.h>
00037 #include <qdatetime.h>
00038 
00039 #include <pi-version.h>
00040 
00041 #ifndef PILOT_LINK_PATCH
00042 #define PILOT_LINK_PATCH "unknown"
00043 #endif
00044 #include "logFile.h"
00045 #include "kpilotConfig.h"
00046 
00047 #include "logFile.moc"
00048 
00049 
00050 LogFile::LogFile() : DCOPObject("LogIface"), QObject(), fOutfile(0L), fSyncing(false)
00051 {
00052     FUNCTIONSETUP;
00053     (void) logf_id;
00054 }
00055 
00056 
00057 /* DCOP */ ASYNC LogFile::logStartSync()
00058 {
00059     FUNCTIONSETUP;
00060     // If a sync is already running (something went wrong then!), close that old log
00061     if (fSyncing) logEndSync();
00062     
00063     fOutfile = new QFile(KPilotSettings::logFileName());
00064     
00065     if (!fOutfile || !fOutfile->open(IO_WriteOnly)) 
00066     {
00067         DEBUGKPILOT<<"Unable to open log file "<<KPilotSettings::logFileName()<<endl;
00068         kdWarning()<<"Unable to open log file "<<KPilotSettings::logFileName()<<endl;
00069         KPILOT_DELETE( fOutfile );
00070         fSyncing = false;
00071         return;
00072     }
00073     
00074     fSyncing = true;
00075     fLogStream.setDevice(fOutfile);
00076 
00077     fLogStream<<(CSL1("KPilot HotSync log, %1").arg(QDateTime::currentDateTime().toString()))<<endl<<endl<<endl;
00078     fLogStream<<(CSL1("Version: KPilot %1").arg(QString::fromLatin1(KPILOT_VERSION)))<<endl;
00079     fLogStream<<(CSL1("Version: pilot-link %1.%2.%3%4" )
00080         .arg(PILOT_LINK_VERSION).arg(PILOT_LINK_MAJOR).arg(PILOT_LINK_MINOR)
00081 #ifdef PILOT_LINK_PATCH
00082         .arg(QString::fromLatin1(PILOT_LINK_PATCH))
00083 #else
00084         .arg(QString())
00085 #endif
00086         )<<endl;
00087 #ifdef KDE_VERSION_STRING
00088     fLogStream<<(CSL1("Version: KDE %1" ).arg(QString::fromLatin1(KDE_VERSION_STRING)) )<<endl;
00089 #endif
00090 #ifdef QT_VERSION_STR
00091     fLogStream<<(CSL1("Version: Qt %1" ).arg(QString::fromLatin1(QT_VERSION_STR)) )<<endl;
00092 #endif
00093     fLogStream<<endl<<endl;
00094         
00095 }
00096 
00097 /* DCOP */ ASYNC LogFile::logEndSync()
00098 {
00099     if (fSyncing) 
00100     {
00101         logMessage(i18n("HotSync finished."));
00102         fLogStream.unsetDevice();
00103         if (fOutfile) fOutfile->close();
00104         KPILOT_DELETE(fOutfile)
00105         fSyncing=false;
00106     }
00107 }
00108 
00109 /* DCOP */ ASYNC LogFile::logMessage(QString s)
00110 {
00111     addMessage(s);
00112 }
00113 
00114 /* DCOP */ ASYNC LogFile::logError(QString s)
00115 {
00116     addMessage(s);
00117 }
00118 
00119 /* DCOP */ ASYNC LogFile::logProgress(QString, int)
00120 {
00121 }
00122 
00123 
00124 void LogFile::addMessage(const QString & s)
00125 {
00126     FUNCTIONSETUP;
00127     if ( fSyncing && !s.isEmpty() ) 
00128     {
00129         fLogStream<<QTime::currentTime().toString()<<"  "<<s<<endl;
00130     }
00131 }
00132 
KDE Home | KDE Accessibility Home | Description of Access Keys