resourcecalendar.cpp
00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 1998 Preston Brown <pbrown@kde.org> 00005 Copyright (c) 2001-2004 Cornelius Schumacher <schumacher@kde.org> 00006 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 00007 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Library General Public 00011 License as published by the Free Software Foundation; either 00012 version 2 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Library General Public License for more details. 00018 00019 You should have received a copy of the GNU Library General Public License 00020 along with this library; see the file COPYING.LIB. If not, write to 00021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00022 Boston, MA 02110-1301, USA. 00023 */ 00024 00025 #include <tdeconfig.h> 00026 #include <kdebug.h> 00027 #include <tdelocale.h> 00028 00029 #include "calendar.h" 00030 00031 #include "resourcecalendar.h" 00032 00033 using namespace KCal; 00034 00035 ResourceCalendar::ResourceCalendar( const TDEConfig *config ) 00036 : KRES::Resource( config ), mResolveConflict( false ) 00037 { 00038 mException = 0; 00039 } 00040 00041 ResourceCalendar::~ResourceCalendar() 00042 { 00043 delete mException; 00044 } 00045 00046 void ResourceCalendar::clearException() 00047 { 00048 delete mException; 00049 mException = 0; 00050 } 00051 00052 void ResourceCalendar::setException( ErrorFormat *exception ) 00053 { 00054 delete mException; 00055 mException = exception; 00056 } 00057 00058 ErrorFormat *ResourceCalendar::exception() 00059 { 00060 return mException; 00061 } 00062 00063 void ResourceCalendar::setResolveConflict( bool b) 00064 { 00065 mResolveConflict = b; 00066 } 00067 00068 TQString ResourceCalendar::infoText() const 00069 { 00070 TQString txt; 00071 00072 txt += "<b>" + resourceName() + "</b>"; 00073 txt += "<br>"; 00074 00075 KRES::Factory *factory = KRES::Factory::self( "calendar" ); 00076 TQString t = factory->typeName( type() ); 00077 txt += i18n("Type: %1").arg( t ); 00078 00079 addInfoText( txt ); 00080 00081 return txt; 00082 } 00083 00084 void ResourceCalendar::writeConfig( TDEConfig* config ) 00085 { 00086 // kdDebug(5800) << "ResourceCalendar::writeConfig()" << endl; 00087 00088 KRES::Resource::writeConfig( config ); 00089 } 00090 00091 Incidence *ResourceCalendar::incidence( const TQString &uid ) 00092 { 00093 Incidence *i = event( uid ); 00094 if ( i ) return i; 00095 i = todo( uid ); 00096 if ( i ) return i; 00097 i = journal( uid ); 00098 return i; 00099 } 00100 00101 bool ResourceCalendar::addIncidence( Incidence *incidence ) 00102 { 00103 Incidence::AddVisitor<ResourceCalendar> v( this ); 00104 return incidence->accept( v ); 00105 } 00106 00107 bool ResourceCalendar::addIncidence( Incidence *incidence, const TQString &subresource ) 00108 { 00109 Incidence::AddSubResourceVisitor<ResourceCalendar> v( this, subresource ); 00110 return incidence->accept( v ); 00111 } 00112 00113 bool ResourceCalendar::deleteIncidence( Incidence *incidence ) 00114 { 00115 Incidence::DeleteVisitor<ResourceCalendar> v( this ); 00116 return incidence->accept( v ); 00117 } 00118 00119 Incidence::List ResourceCalendar::rawIncidences() 00120 { 00121 return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() ); 00122 } 00123 00124 void ResourceCalendar::setSubresourceActive( const TQString &, bool ) 00125 { 00126 } 00127 00128 bool ResourceCalendar::addSubresource( const TQString &, const TQString & ) 00129 { 00130 return true; 00131 } 00132 00133 bool ResourceCalendar::removeSubresource( const TQString & ) 00134 { 00135 return true; 00136 } 00137 00138 bool ResourceCalendar::load() 00139 { 00140 kdDebug(5800) << "Loading resource " + resourceName() << endl; 00141 00142 mReceivedLoadError = false; 00143 00144 bool success = true; 00145 if ( !isOpen() ) 00146 success = open(); 00147 if ( success ) 00148 success = doLoad(); 00149 00150 if ( !success && !mReceivedLoadError ) 00151 loadError(); 00152 00153 // If the resource is read-only, we need to set its incidences to read-only, 00154 // too. This can't be done at a lower-level, since the read-only setting 00155 // happens at this level 00156 if ( readOnly() ) { 00157 Incidence::List incidences( rawIncidences() ); 00158 Incidence::List::Iterator it; 00159 for ( it = incidences.begin(); it != incidences.end(); ++it ) { 00160 (*it)->setReadOnly( true ); 00161 } 00162 } 00163 00164 kdDebug(5800) << "Done loading resource " + resourceName() << endl; 00165 00166 return success; 00167 } 00168 00169 void ResourceCalendar::loadError( const TQString &err ) 00170 { 00171 kdDebug(5800) << "Error loading resource: " << err << endl; 00172 00173 mReceivedLoadError = true; 00174 00175 TQString msg = i18n("Error while loading %1.\n") .arg( resourceName() ); 00176 if ( !err.isEmpty() ) { 00177 msg += err; 00178 } 00179 emit resourceLoadError( this, msg ); 00180 } 00181 00182 bool ResourceCalendar::save( Incidence *incidence ) 00183 { 00184 if ( !readOnly() ) { 00185 kdDebug(5800) << "Save resource " + resourceName() << endl; 00186 00187 mReceivedSaveError = false; 00188 00189 if ( !isOpen() ) return true; 00190 bool success = incidence ? doSave(incidence) : doSave(); 00191 if ( !success && !mReceivedSaveError ) saveError(); 00192 00193 return success; 00194 } else { 00195 // Read-only, just don't save... 00196 kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl; 00197 return true; 00198 } 00199 } 00200 00201 bool ResourceCalendar::doSave( Incidence * ) 00202 { 00203 return doSave(); 00204 } 00205 00206 void ResourceCalendar::saveError( const TQString &err ) 00207 { 00208 kdDebug(5800) << "Error saving resource: " << err << endl; 00209 00210 mReceivedSaveError = true; 00211 00212 TQString msg = i18n("Error while saving %1.\n") .arg( resourceName() ); 00213 if ( !err.isEmpty() ) { 00214 msg += err; 00215 } 00216 emit resourceSaveError( this, msg ); 00217 } 00218 00219 bool ResourceCalendar::setValue( const TQString &key, const TQString &value ) 00220 { 00221 Q_UNUSED( key ); 00222 Q_UNUSED( value ); 00223 return false; 00224 } 00225 00226 TQString ResourceCalendar::subresourceType( const TQString &resource ) 00227 { 00228 Q_UNUSED( resource ); 00229 return TQString(); 00230 } 00231 00232 bool ResourceCalendar::subresourceWritable( const TQString &resource ) const 00233 { 00234 if ( resource.isEmpty() ) { 00235 return !readOnly(); 00236 } else { 00237 return false; 00238 } 00239 } 00240 00241 void ResourceCalendar::beginAddingIncidences() 00242 { 00243 } 00244 00245 void ResourceCalendar::endAddingIncidences() 00246 { 00247 } 00248 00249 #include "resourcecalendar.moc"