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 
00031 #include "options.h"
00032 
00033 #include <qfile.h>
00034 #include <qtextstream.h>
00035 #include <qdatetime.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"), QObject(), fOutfile(0L), fSyncing(false)
00049 {
00050     FUNCTIONSETUP;
00051 }
00052 
00053 
00054 /* DCOP */ ASYNC LogFile::logStartSync()
00055 {
00056     FUNCTIONSETUP;
00057     // If a sync is already running (something went wrong then!), close that old log
00058     if (fSyncing) logEndSync();
00059     
00060     fOutfile = new QFile(KPilotSettings::logFileName());
00061     
00062     if (!fOutfile || !fOutfile->open(IO_WriteOnly)) 
00063     {
00064         DEBUGKPILOT<<"Unable to open log file "<<KPilotSettings::logFileName()<<endl;
00065         kdWarning()<<"Unable to open log file "<<KPilotSettings::logFileName()<<endl;
00066         KPILOT_DELETE( fOutfile );
00067         fSyncing = false;
00068         return;
00069     }
00070     
00071     fSyncing = true;
00072     fLogStream.setDevice(fOutfile);
00073 
00074     fLogStream<<(CSL1("KPilot HotSync log, %1").arg(QDateTime::currentDateTime().toString()))<<endl<<endl<<endl;
00075     fLogStream<<(CSL1("Version: KPilot %1").arg(QString::fromLatin1(KPILOT_VERSION)))<<endl;
00076     fLogStream<<(CSL1("Version: pilot-link %1.%2.%3%4" )
00077         .arg(PILOT_LINK_VERSION).arg(PILOT_LINK_MAJOR).arg(PILOT_LINK_MINOR)
00078 #ifdef PILOT_LINK_PATCH
00079         .arg(QString::fromLatin1(PILOT_LINK_PATCH))
00080 #else
00081         .arg(QString())
00082 #endif
00083         )<<endl;
00084 #ifdef KDE_VERSION_STRING
00085     fLogStream<<(CSL1("Version: KDE %1" ).arg(QString::fromLatin1(KDE_VERSION_STRING)) )<<endl;
00086 #endif
00087 #ifdef QT_VERSION_STR
00088     fLogStream<<(CSL1("Version: Qt %1" ).arg(QString::fromLatin1(QT_VERSION_STR)) )<<endl;
00089 #endif
00090     fLogStream<<endl<<endl;
00091         
00092 }
00093 
00094 /* DCOP */ ASYNC LogFile::logEndSync()
00095 {
00096     if (fSyncing) 
00097     {
00098         logMessage(i18n("HotSync finished."));
00099         fLogStream.unsetDevice();
00100         if (fOutfile) fOutfile->close();
00101         KPILOT_DELETE(fOutfile)
00102         fSyncing=false;
00103     }
00104 }
00105 
00106 /* DCOP */ ASYNC LogFile::logMessage(QString s)
00107 {
00108     addMessage(s);
00109 }
00110 
00111 /* DCOP */ ASYNC LogFile::logError(QString s)
00112 {
00113     addMessage(s);
00114 }
00115 
00116 /* DCOP */ ASYNC LogFile::logProgress(QString, int)
00117 {
00118 }
00119 
00120 
00121 void LogFile::addMessage(const QString & s)
00122 {
00123     FUNCTIONSETUP;
00124     if ( fSyncing && !s.isEmpty() ) 
00125     {
00126         fLogStream<<QTime::currentTime().toString()<<"  "<<s<<endl;
00127     }
00128 }
00129 
KDE Home | KDE Accessibility Home | Description of Access Keys