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 <kstandarddirs.h>
00030 #include <ksimpleconfig.h>
00031 #include <kio/netaccess.h>
00032 #include <kdebug.h>
00033
00034 #include "adcalendarbase.h"
00035
00036 ADCalendarBase::EventsMap ADCalendarBase::eventsHandled_;
00037
00038 ADCalendarBase::ADCalendarBase(const QString& url, const QCString& appname, Type type)
00039 : mUrlString(url),
00040 mAppName(appname),
00041 mActionType(type),
00042 mRcIndex(-1),
00043 mLoaded(false),
00044 mUnregistered(false)
00045 {
00046 if (mAppName == "korgac")
00047 {
00048 KConfig cfg( locate( "config", "korganizerrc" ) );
00049 cfg.setGroup( "Time & Date" );
00050 QString tz = cfg.readEntry( "TimeZoneId", "" );
00051 kdDebug(5900) << "ADCalendarBase(): tz: " << tz << endl;
00052 if( tz.isEmpty() ) {
00053
00054
00055
00056 QString zone;
00057 char zonefilebuf[100];
00058 int len = readlink("/etc/localtime",zonefilebuf,100);
00059 if (len > 0 && len < 100) {
00060 zonefilebuf[len] = '\0';
00061 zone = zonefilebuf;
00062 zone = zone.mid(zone.find("zoneinfo/") + 9);
00063 } else {
00064 tzset();
00065 zone = tzname[0];
00066 }
00067 tz = zone;
00068 }
00069 setTimeZoneId( tz );
00070 }
00071 }
00072
00073
00074
00075
00076 bool ADCalendarBase::loadFile_(const QCString& appName)
00077 {
00078 mLoaded = false;
00079 KURL url(mUrlString);
00080 QString tmpFile;
00081 if (KIO::NetAccess::download(url, tmpFile))
00082 {
00083 kdDebug(5900) << "--- Downloaded to " << tmpFile << endl;
00084 mLoaded = load(tmpFile);
00085 KIO::NetAccess::removeTempFile(tmpFile);
00086 if (!mLoaded)
00087 kdDebug(5900) << "ADCalendarBase::loadFile_(): Error loading calendar file '" << tmpFile << "'\n";
00088 else
00089 {
00090
00091 for (EventsMap::Iterator it = eventsHandled_.begin(); it != eventsHandled_.end(); )
00092 {
00093 if (it.data().calendarURL == mUrlString && !event(it.key()))
00094 {
00095
00096 EventsMap::Iterator i = it;
00097 ++it;
00098 eventsHandled_.remove(i);
00099 }
00100 else
00101 ++it;
00102 }
00103 }
00104 }
00105 else if (!appName.isEmpty()) {
00106 #if TODO_handle_download_error
00107 KMessageBox::error(0L, i18n("Cannot download calendar from\n%1.")
00108 .arg(url.prettyURL()), appName);
00109 #endif
00110 }
00111 return mLoaded;
00112 }
00113
00114 void ADCalendarBase::dump() const
00115 {
00116 kdDebug(5900) << " <calendar>" << endl;
00117 kdDebug(5900) << " <url>" << urlString() << "</url>" << endl;
00118 kdDebug(5900) << " <appname>" << appName() << "</appname>" << endl;
00119 if ( loaded() ) kdDebug(5900) << " <loaded/>" << endl;
00120 kdDebug(5900) << " <actiontype>" << int(actionType()) << "</actiontype>" << endl;
00121 if (enabled() ) kdDebug(5900) << " <enabled/>" << endl;
00122 else kdDebug(5900) << " <disabled/>" << endl;
00123 if (available()) kdDebug(5900) << " <available/>" << endl;
00124 kdDebug(5900) << " </calendar>" << endl;
00125 }
This file is part of the documentation for kdelibs Version 3.1.5.