adcalendarbase.cpp
00001
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 #include <unistd.h>
00027 #include <time.h>
00028
00029 #include <qfile.h>
00030
00031 #include <kstandarddirs.h>
00032 #include <ksimpleconfig.h>
00033 #include <ktempfile.h>
00034 #include <kio/job.h>
00035 #include <kio/jobclasses.h>
00036 #include <kdebug.h>
00037
00038 #include "adcalendarbase.h"
00039 #include "adcalendarbase.moc"
00040
00041 ADCalendarBase::EventsMap ADCalendarBase::mEventsHandled;
00042 QStringList ADCalendarBase::mCalendarUrls;
00043
00044 ADCalendarBase::ADCalendarBase(const QString& url, const QCString& appname, Type type)
00045 : mUrlString(url),
00046 mAppName(appname),
00047 mActionType(type),
00048 mRcIndex(-1),
00049 mLoaded(false),
00050 mLoadedConnected(false),
00051 mUnregistered(false)
00052 {
00053 mUrlIndex = mCalendarUrls.findIndex(url);
00054 if (mUrlIndex < 0)
00055 {
00056 mUrlIndex = static_cast<int>(mCalendarUrls.count());
00057 mCalendarUrls.append(url);
00058 }
00059 if (mAppName == "korgac")
00060 {
00061 KConfig cfg( locate( "config", "korganizerrc" ) );
00062 cfg.setGroup( "Time & Date" );
00063 QString tz = cfg.readEntry( "TimeZoneId" );
00064 kdDebug(5900) << "ADCalendarBase(): tz: " << tz << endl;
00065 if( tz.isEmpty() ) {
00066
00067
00068
00069 QString zone;
00070 char zonefilebuf[100];
00071 int len = readlink("/etc/localtime",zonefilebuf,100);
00072 if (len > 0 && len < 100) {
00073 zonefilebuf[len] = '\0';
00074 zone = zonefilebuf;
00075 zone = zone.mid(zone.find("zoneinfo/") + 9);
00076 } else {
00077 tzset();
00078 zone = tzname[0];
00079 }
00080 tz = zone;
00081 }
00082 setTimeZoneId( tz );
00083 }
00084 }
00085
00086
00087
00088
00089 bool ADCalendarBase::loadFile_()
00090 {
00091 if ( !mTempFileName.isNull() ) {
00092
00093 kdError(5900) << "ADCalendarBase::loadFile_(): already downloading another file\n";
00094 return false;
00095 }
00096 mLoaded = false;
00097 KURL url( mUrlString );
00098 if ( url.isLocalFile() ) {
00099
00100 loadLocalFile( url.path() );
00101 emit loaded( this, mLoaded );
00102 } else {
00103
00104 KTempFile tempFile;
00105 mTempFileName = tempFile.name();
00106 KURL dest;
00107 dest.setPath( mTempFileName );
00108 KIO::FileCopyJob *job = KIO::file_copy( url, dest, -1, true );
00109 connect( job, SIGNAL( result( KIO::Job * ) ),
00110 SLOT( slotDownloadJobResult( KIO::Job * ) ) );
00111 }
00112 return true;
00113 }
00114
00115 void ADCalendarBase::slotDownloadJobResult( KIO::Job *job )
00116 {
00117 if ( job->error() ) {
00118 KURL url( mUrlString );
00119 kdDebug(5900) << "Error downloading calendar from " << url.prettyURL() << endl;
00120 job->showErrorDialog( 0 );
00121 } else {
00122 kdDebug(5900) << "--- Downloaded to " << mTempFileName << endl;
00123 loadLocalFile( mTempFileName );
00124 }
00125 unlink( QFile::encodeName( mTempFileName ) );
00126 mTempFileName = QString::null;
00127 emit loaded( this, mLoaded );
00128 }
00129
00130 void ADCalendarBase::loadLocalFile( const QString& filename )
00131 {
00132 mLoaded = load( filename );
00133 if (!mLoaded)
00134 kdDebug(5900) << "ADCalendarBase::loadLocalFile(): Error loading calendar file '" << filename << "'\n";
00135 else
00136 {
00137
00138 for (EventsMap::Iterator it = mEventsHandled.begin(); it != mEventsHandled.end(); )
00139 {
00140 if (it.key().calendarIndex == mUrlIndex && !event(it.key().eventID))
00141 {
00142
00143 EventsMap::Iterator i = it;
00144 ++it;
00145 mEventsHandled.remove(i);
00146 }
00147 else
00148 ++it;
00149 }
00150 }
00151 }
00152
00153 bool ADCalendarBase::setLoadedConnected()
00154 {
00155 if (mLoadedConnected)
00156 return true;
00157 mLoadedConnected = true;
00158 return false;
00159 }
00160
00161 void ADCalendarBase::dump() const
00162 {
00163 kdDebug(5900) << " <calendar>" << endl;
00164 kdDebug(5900) << " <url>" << urlString() << "</url>" << endl;
00165 kdDebug(5900) << " <appname>" << appName() << "</appname>" << endl;
00166 if ( loaded() ) kdDebug(5900) << " <loaded/>" << endl;
00167 kdDebug(5900) << " <actiontype>" << int(actionType()) << "</actiontype>" << endl;
00168 if (enabled() ) kdDebug(5900) << " <enabled/>" << endl;
00169 else kdDebug(5900) << " <disabled/>" << endl;
00170 if (available()) kdDebug(5900) << " <available/>" << endl;
00171 kdDebug(5900) << " </calendar>" << endl;
00172 }
This file is part of the documentation for kalarmd Library Version 3.3.2.