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::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::addSubresource( const QString &, const QString & )
00103 {
00104 return true;
00105 }
00106
00107 bool ResourceCalendar::removeSubresource( const QString & )
00108 {
00109 return true;
00110 }
00111
00112 bool ResourceCalendar::load()
00113 {
00114 kdDebug(5800) << "Loading resource " + resourceName() << endl;
00115
00116 mReceivedLoadError = false;
00117
00118 bool success = true;
00119 if ( !isOpen() )
00120 success = open();
00121 if ( success )
00122 success = doLoad();
00123
00124 if ( !success && !mReceivedLoadError )
00125 loadError();
00126
00127
00128
00129
00130 if ( readOnly() ) {
00131 Incidence::List incidences( rawIncidences() );
00132 Incidence::List::Iterator it;
00133 for ( it = incidences.begin(); it != incidences.end(); ++it ) {
00134 (*it)->setReadOnly( true );
00135 }
00136 }
00137
00138 kdDebug(5800) << "Done loading resource " + resourceName() << endl;
00139
00140 return success;
00141 }
00142
00143 void ResourceCalendar::loadError( const QString &err )
00144 {
00145 kdDebug(5800) << "Error loading resource: " << err << endl;
00146
00147 mReceivedLoadError = true;
00148
00149 QString msg = i18n("Error while loading %1.\n") .arg( resourceName() );
00150 if ( !err.isEmpty() ) {
00151 msg += err;
00152 }
00153 emit resourceLoadError( this, msg );
00154 }
00155
00156 bool ResourceCalendar::save( Incidence *incidence )
00157 {
00158 if ( !readOnly() ) {
00159 kdDebug(5800) << "Save resource " + resourceName() << endl;
00160
00161 mReceivedSaveError = false;
00162
00163 if ( !isOpen() ) return true;
00164 bool success = incidence ? doSave(incidence) : doSave();
00165 if ( !success && !mReceivedSaveError ) saveError();
00166
00167 return success;
00168 } else {
00169
00170 kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl;
00171 return true;
00172 }
00173 }
00174
00175 bool ResourceCalendar::doSave( Incidence * )
00176 {
00177 return doSave();
00178 }
00179
00180 void ResourceCalendar::saveError( const QString &err )
00181 {
00182 kdDebug(5800) << "Error saving resource: " << err << endl;
00183
00184 mReceivedSaveError = true;
00185
00186 QString msg = i18n("Error while saving %1.\n") .arg( resourceName() );
00187 if ( !err.isEmpty() ) {
00188 msg += err;
00189 }
00190 emit resourceSaveError( this, msg );
00191 }
00192
00193 bool ResourceCalendar::setValue( const QString &key, const QString &value )
00194 {
00195 return false;
00196 }
00197
00198 QString ResourceCalendar::subresourceType( const QString &resource )
00199 {
00200 Q_UNUSED( resource );
00201 return QString();
00202 }
00203
00204
00205 #include "resourcecalendar.moc"
|