kalarmd Library API Documentation

adcalendarbase.cpp

00001 /*
00002     Calendar access for KDE Alarm Daemon.
00003 
00004     This file is part of the KDE alarm daemon.
00005     Copyright (c) 2001 David Jarvie <software@astrojar.org.uk>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
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       // Set a reasonable default timezone is none
00054       // was found in the config file
00055       // see koprefs.cpp in korganizer
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  * Load the calendar file.
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       // Remove all now non-existent events from the handled list
00091       for (EventsMap::Iterator it = eventsHandled_.begin();  it != eventsHandled_.end();  )
00092       {
00093         if (it.data().calendarURL == mUrlString  &&  !event(it.key()))
00094         {
00095           // Event belonged to this calendar, but can't find it any more
00096           EventsMap::Iterator i = it;
00097           ++it;                      // prevent iterator becoming invalid with remove()
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 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:55 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001