libkcal Library API Documentation

resourcecalendar.cpp

00001 /*
00002     This file is part of libkdepim.
00003     Copyright (c) 1998 Preston Brown
00004     Copyright (c) 2001-2004 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library 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 GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020     Boston, MA 02111-1307, USA.
00021 */
00022 
00023 #include <kconfig.h>
00024 #include <kdebug.h>
00025 #include <klocale.h>
00026 
00027 #include "calendar.h"
00028 
00029 #include "resourcecalendar.h"
00030 
00031 using namespace KCal;
00032 
00033 ResourceCalendar::ResourceCalendar( const KConfig *config )
00034     : KRES::Resource( config )
00035 {
00036 }
00037 
00038 ResourceCalendar::~ResourceCalendar()
00039 {
00040 }
00041 
00042 QString ResourceCalendar::infoText() const
00043 {
00044   QString txt;
00045 
00046   txt += "<b>" + resourceName() + "</b>";
00047   txt += "<br>";
00048 
00049   KRES::Factory *factory = KRES::Factory::self( "calendar" );
00050   QString t = factory->typeName( type() );
00051   txt += i18n("Type: %1").arg( t );
00052 
00053   addInfoText( txt );
00054   
00055   return txt;
00056 }
00057 
00058 void ResourceCalendar::writeConfig( KConfig* config )
00059 {
00060 //  kdDebug(5800) << "ResourceCalendar::writeConfig()" << endl;
00061 
00062   KRES::Resource::writeConfig( config );
00063 }
00064 
00065 bool ResourceCalendar::addIncidence( Incidence *incidence )
00066 {
00067   Incidence::AddVisitor<ResourceCalendar> v( this );
00068   return incidence->accept( v );
00069 }
00070 
00071 Incidence::List ResourceCalendar::rawIncidences()
00072 {
00073   return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), journals() );
00074 }
00075 
00076 void ResourceCalendar::setSubresourceActive( const QString &, bool )
00077 {
00078 }
00079 
00080 bool ResourceCalendar::load()
00081 {
00082   kdDebug(5800) << "Loading resource " + resourceName() << endl;
00083 
00084   // FIXME: test if resource is opened and remove this test from concrete
00085   // resources
00086 
00087   mReceivedLoadError = false;
00088 
00089   bool success = true;
00090   if ( !isOpen() ) success = open();
00091   if ( success ) {
00092     success = doLoad();
00093   }
00094   if ( !success && !mReceivedLoadError ) loadError();
00095 
00096   kdDebug(5800) << "Done loading resource " + resourceName() << endl;
00097 
00098   return success;
00099 }
00100 
00101 void ResourceCalendar::loadError( const QString &err )
00102 {
00103   kdDebug(5800) << "Error loading resource: " << err << endl;
00104 
00105   mReceivedLoadError = true;
00106 
00107   QString msg = i18n("Error while loading %1.\n") .arg( resourceName() );
00108   if ( !err.isEmpty() ) {
00109     msg += err;
00110   }
00111   emit resourceLoadError( this, msg );
00112 }
00113 
00114 bool ResourceCalendar::save()
00115 {
00116   if ( !readOnly() ) { 
00117     kdDebug(5800) << "Save resource " + resourceName() << endl; 
00118 
00119     mReceivedSaveError = false;
00120 
00121     bool success = doSave();
00122     if ( !success && !mReceivedSaveError ) saveError();
00123 
00124     return success;
00125   } else { 
00126     // Read-only, just don't save... 
00127     kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl; 
00128     return true; 
00129   } 
00130 }
00131 
00132 void ResourceCalendar::saveError( const QString &err )
00133 {
00134   kdDebug(5800) << "Error saving resource: " << err << endl;
00135 
00136   mReceivedSaveError = true;
00137 
00138   QString msg = i18n("Error while saving %1.\n") .arg( resourceName() );
00139   if ( !err.isEmpty() ) {
00140     msg += err;
00141   }
00142   emit resourceSaveError( this, msg );
00143 }
00144 
00145 
00146 #include "resourcecalendar.moc"
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Apr 4 04:45:02 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003