libkcal
resourcecalendar.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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::addIncidence( Incidence *incidence, const QString &subresource )
00088 {
00089 Incidence::AddSubResourceVisitor<ResourceCalendar> v( this, subresource );
00090 return incidence->accept( v );
00091 }
00092
00093 bool ResourceCalendar::deleteIncidence( Incidence *incidence )
00094 {
00095 Incidence::DeleteVisitor<ResourceCalendar> v( this );
00096 return incidence->accept( v );
00097 }
00098
00099 Incidence::List ResourceCalendar::rawIncidences()
00100 {
00101 return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() );
00102 }
00103
00104 void ResourceCalendar::setSubresourceActive( const QString &, bool )
00105 {
00106 }
00107
00108 bool ResourceCalendar::addSubresource( const QString &, const QString & )
00109 {
00110 return true;
00111 }
00112
00113 bool ResourceCalendar::removeSubresource( const QString & )
00114 {
00115 return true;
00116 }
00117
00118 bool ResourceCalendar::load()
00119 {
00120 kdDebug(5800) << "Loading resource " + resourceName() << endl;
00121
00122 mReceivedLoadError = false;
00123
00124 bool success = true;
00125 if ( !isOpen() )
00126 success = open();
00127 if ( success )
00128 success = doLoad();
00129
00130 if ( !success && !mReceivedLoadError )
00131 loadError();
00132
00133
00134
00135
00136 if ( readOnly() ) {
00137 Incidence::List incidences( rawIncidences() );
00138 Incidence::List::Iterator it;
00139 for ( it = incidences.begin(); it != incidences.end(); ++it ) {
00140 (*it)->setReadOnly( true );
00141 }
00142 }
00143
00144 kdDebug(5800) << "Done loading resource " + resourceName() << endl;
00145
00146 return success;
00147 }
00148
00149 void ResourceCalendar::loadError( const QString &err )
00150 {
00151 kdDebug(5800) << "Error loading resource: " << err << endl;
00152
00153 mReceivedLoadError = true;
00154
00155 QString msg = i18n("Error while loading %1.\n") .arg( resourceName() );
00156 if ( !err.isEmpty() ) {
00157 msg += err;
00158 }
00159 emit resourceLoadError( this, msg );
00160 }
00161
00162 bool ResourceCalendar::save( Incidence *incidence )
00163 {
00164 if ( !readOnly() ) {
00165 kdDebug(5800) << "Save resource " + resourceName() << endl;
00166
00167 mReceivedSaveError = false;
00168
00169 if ( !isOpen() ) return true;
00170 bool success = incidence ? doSave(incidence) : doSave();
00171 if ( !success && !mReceivedSaveError ) saveError();
00172
00173 return success;
00174 } else {
00175
00176 kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl;
00177 return true;
00178 }
00179 }
00180
00181 bool ResourceCalendar::doSave( Incidence * )
00182 {
00183 return doSave();
00184 }
00185
00186 void ResourceCalendar::saveError( const QString &err )
00187 {
00188 kdDebug(5800) << "Error saving resource: " << err << endl;
00189
00190 mReceivedSaveError = true;
00191
00192 QString msg = i18n("Error while saving %1.\n") .arg( resourceName() );
00193 if ( !err.isEmpty() ) {
00194 msg += err;
00195 }
00196 emit resourceSaveError( this, msg );
00197 }
00198
00199 bool ResourceCalendar::setValue( const QString &key, const QString &value )
00200 {
00201 Q_UNUSED( key );
00202 Q_UNUSED( value );
00203 return false;
00204 }
00205
00206 QString ResourceCalendar::subresourceType( const QString &resource )
00207 {
00208 Q_UNUSED( resource );
00209 return QString();
00210 }
00211
00212 bool ResourceCalendar::subresourceWritable( const QString &resource ) const
00213 {
00214 if ( resource.isEmpty() ) {
00215 return !readOnly();
00216 } else {
00217 return false;
00218 }
00219 }
00220
00221 #include "resourcecalendar.moc"
|