libkcal
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 <kconfig.h> 00026 #include <kdebug.h> 00027 #include <klocale.h> 00028 00029 #include "calendar.h" 00030 00031 #include "resourcecalendar.h" 00032 00033 using namespace KCal; 00034 00035 ResourceCalendar::ResourceCalendar( const KConfig *config ) 00036 : KRES::Resource( config ),mResolveConflict( false ) 00037 { 00038 } 00039 00040 ResourceCalendar::~ResourceCalendar() 00041 { 00042 } 00043 00044 void ResourceCalendar::setResolveConflict( bool b) 00045 { 00046 mResolveConflict = b; 00047 } 00048 QString ResourceCalendar::infoText() const 00049 { 00050 QString txt; 00051 00052 txt += "<b>" + resourceName() + "</b>"; 00053 txt += "<br>"; 00054 00055 KRES::Factory *factory = KRES::Factory::self( "calendar" ); 00056 QString t = factory->typeName( type() ); 00057 txt += i18n("Type: %1").arg( t ); 00058 00059 addInfoText( txt ); 00060 00061 return txt; 00062 } 00063 00064 void ResourceCalendar::writeConfig( KConfig* config ) 00065 { 00066 // kdDebug(5800) << "ResourceCalendar::writeConfig()" << endl; 00067 00068 KRES::Resource::writeConfig( config ); 00069 } 00070 00071 Incidence *ResourceCalendar::incidence( const QString &uid ) 00072 { 00073 Incidence *i = event( uid ); 00074 if ( i ) return i; 00075 i = todo( uid ); 00076 if ( i ) return i; 00077 i = journal( uid ); 00078 return i; 00079 } 00080 00081 bool ResourceCalendar::addIncidence( Incidence *incidence ) 00082 { 00083 Incidence::AddVisitor<ResourceCalendar> v( this ); 00084 return incidence->accept( v ); 00085 } 00086 00087 bool ResourceCalendar::deleteIncidence( Incidence *incidence ) 00088 { 00089 Incidence::DeleteVisitor<ResourceCalendar> v( this ); 00090 return incidence->accept( v ); 00091 } 00092 00093 Incidence::List ResourceCalendar::rawIncidences() 00094 { 00095 return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() ); 00096 } 00097 00098 void ResourceCalendar::setSubresourceActive( const QString &, bool ) 00099 { 00100 } 00101 00102 bool ResourceCalendar::load() 00103 { 00104 kdDebug(5800) << "Loading resource " + resourceName() << endl; 00105 00106 mReceivedLoadError = false; 00107 00108 bool success = true; 00109 if ( !isOpen() ) success = open(); 00110 if ( success ) { 00111 success = doLoad(); 00112 } 00113 if ( !success && !mReceivedLoadError ) loadError(); 00114 00115 // If the resource is read-only, we need to set its incidences to read-only, 00116 // too. This can't be done at a lower-level, since the read-only setting 00117 // happens at this level 00118 if ( readOnly() ) { 00119 Incidence::List incidences( rawIncidences() ); 00120 Incidence::List::Iterator it; 00121 for ( it = incidences.begin(); it != incidences.end(); ++it ) { 00122 (*it)->setReadOnly( true ); 00123 } 00124 } 00125 00126 kdDebug(5800) << "Done loading resource " + resourceName() << endl; 00127 00128 return success; 00129 } 00130 00131 void ResourceCalendar::loadError( const QString &err ) 00132 { 00133 kdDebug(5800) << "Error loading resource: " << err << endl; 00134 00135 mReceivedLoadError = true; 00136 00137 QString msg = i18n("Error while loading %1.\n") .arg( resourceName() ); 00138 if ( !err.isEmpty() ) { 00139 msg += err; 00140 } 00141 emit resourceLoadError( this, msg ); 00142 } 00143 00144 bool ResourceCalendar::save( Incidence *incidence ) 00145 { 00146 if ( !readOnly() ) { 00147 kdDebug(5800) << "Save resource " + resourceName() << endl; 00148 00149 mReceivedSaveError = false; 00150 00151 if ( !isOpen() ) return true; 00152 bool success = incidence ? doSave(incidence) : doSave(); 00153 if ( !success && !mReceivedSaveError ) saveError(); 00154 00155 return success; 00156 } else { 00157 // Read-only, just don't save... 00158 kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl; 00159 return true; 00160 } 00161 } 00162 00163 bool ResourceCalendar::doSave( Incidence * ) 00164 { 00165 return doSave(); 00166 } 00167 00168 void ResourceCalendar::saveError( const QString &err ) 00169 { 00170 kdDebug(5800) << "Error saving resource: " << err << endl; 00171 00172 mReceivedSaveError = true; 00173 00174 QString msg = i18n("Error while saving %1.\n") .arg( resourceName() ); 00175 if ( !err.isEmpty() ) { 00176 msg += err; 00177 } 00178 emit resourceSaveError( this, msg ); 00179 } 00180 00181 bool ResourceCalendar::setValue( const QString &key, const QString &value ) 00182 { 00183 return false; 00184 } 00185 00186 00187 #include "resourcecalendar.moc"