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::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
00116
00117
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
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"
|