25 #include <tqdatetime.h> 26 #include <tqfileinfo.h> 28 #include <tqptrlist.h> 31 #include <tdelocale.h> 33 #include <tdeconfig.h> 34 #include <tdestandarddirs.h> 37 #include "vcalformat.h" 38 #include "icalformat.h" 39 #include "exceptions.h" 40 #include "calendarlocal.h" 41 #include "incidence.h" 45 #include "filestorage.h" 47 #include <tderesources/configwidget.h> 49 #include "resourcelocaldirconfig.h" 51 #include "resourcelocaldir.h" 55 ResourceLocalDir::ResourceLocalDir(
const TDEConfig* config )
65 ResourceLocalDir::ResourceLocalDir(
const TQString& dirName )
68 mURL = KURL( dirName );
74 void ResourceLocalDir::readConfig(
const TDEConfig *config )
76 TQString url = config->readPathEntry(
"CalendarURL" );
80 void ResourceLocalDir::writeConfig( TDEConfig *config )
82 kdDebug(5800) <<
"ResourceLocalDir::writeConfig()" << endl;
84 ResourceCalendar::writeConfig( config );
86 config->writePathEntry(
"CalendarURL", mURL.prettyURL() );
89 void ResourceLocalDir::init()
93 setSavePolicy( SaveDelayed );
95 connect( &mDirWatch, TQ_SIGNAL( dirty(
const TQString & ) ),
96 TQ_SLOT( reload(
const TQString & ) ) );
97 connect( &mDirWatch, TQ_SIGNAL( created(
const TQString & ) ),
98 TQ_SLOT( reload(
const TQString & ) ) );
99 connect( &mDirWatch, TQ_SIGNAL( deleted(
const TQString & ) ),
100 TQ_SLOT( reload(
const TQString & ) ) );
102 mLock =
new TDEABC::Lock( mURL.path() );
104 mDirWatch.addDir( mURL.path(), true );
105 mDirWatch.startScan();
109 ResourceLocalDir::~ResourceLocalDir()
116 bool ResourceLocalDir::doOpen()
118 TQFileInfo dirInfo( mURL.path() );
119 return dirInfo.isDir() && dirInfo.isReadable() &&
120 ( dirInfo.isWritable() || readOnly() );
123 bool ResourceLocalDir::doLoad()
125 kdDebug(5800) <<
"ResourceLocalDir::load()" << endl;
128 TQString dirName = mURL.path();
130 if ( !( TDEStandardDirs::exists( dirName ) || TDEStandardDirs::exists( dirName +
"/") ) ) {
131 kdDebug(5800) <<
"ResourceLocalDir::load(): Directory '" << dirName
132 <<
"' doesn't exist yet. Creating it..." << endl;
136 return TDEStandardDirs::makeDir( dirName, 0775 );
140 kdDebug(5800) <<
"ResourceLocalDir::load(): '" << dirName <<
"'" << endl;
141 TQFileInfo dirInfo( dirName );
142 if ( !( dirInfo.isDir() && dirInfo.isReadable() &&
143 ( dirInfo.isWritable() || readOnly() ) ) )
146 TQDir dir( dirName );
147 TQStringList entries = dir.entryList( TQDir::Files | TQDir::Readable );
150 TQStringList::ConstIterator it;
151 for( it = entries.constBegin(); it != entries.constEnd(); ++it ) {
152 if ( (*it).endsWith(
"~" ) )
155 TQString fileName = dirName +
"/" + *it;
156 kdDebug(5800) <<
" read '" << fileName <<
"'" << endl;
158 if ( !doFileLoad( cal, fileName ) ) {
166 bool ResourceLocalDir::doFileLoad(
CalendarLocal &cal,
const TQString &fileName )
168 if ( !cal.
load( fileName ) )
171 Incidence::List::ConstIterator it;
172 for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
174 if ( i ) mCalendar.addIncidence( i->
clone() );
179 bool ResourceLocalDir::doSave()
184 list = addedIncidences();
185 list += changedIncidences();
187 for ( Incidence::List::iterator it = list.begin(); it != list.end(); ++it )
188 if ( !doSave( *it ) )
194 bool ResourceLocalDir::doSave(
Incidence *incidence )
196 if ( mDeletedIncidences.contains( incidence ) ) {
197 mDeletedIncidences.remove( incidence );
201 mDirWatch.stopScan();
203 TQString fileName = mURL.path() +
"/" + incidence->
uid();
204 kdDebug(5800) <<
"writing '" << fileName <<
"'" << endl;
208 const bool ret = cal.
save( fileName );
210 mDirWatch.startScan();
215 TDEABC::Lock *ResourceLocalDir::lock()
220 void ResourceLocalDir::reload(
const TQString &file )
222 kdDebug(5800) <<
"ResourceLocalDir::reload()" << endl;
227 kdDebug(5800) <<
" File: '" << file <<
"'" << endl;
232 emit resourceChanged(
this );
236 bool ResourceLocalDir::deleteEvent(
Event *event)
238 kdDebug(5800) <<
"ResourceLocalDir::deleteEvent" << endl;
239 if ( deleteIncidenceFile(event) ) {
240 if ( mCalendar.deleteEvent( event ) ) {
241 mDeletedIncidences.append( event );
252 bool ResourceLocalDir::deleteTodo(
Todo *todo)
254 if ( deleteIncidenceFile(todo) ) {
255 if ( mCalendar.deleteTodo( todo ) ) {
256 mDeletedIncidences.append( todo );
267 bool ResourceLocalDir::deleteJournal(
Journal *journal )
269 if ( deleteIncidenceFile( journal ) ) {
270 if ( mCalendar.deleteJournal( journal ) ) {
271 mDeletedIncidences.append( journal );
282 void ResourceLocalDir::dump()
const 284 ResourceCalendar::dump();
285 kdDebug(5800) <<
" Url: " << mURL.url() << endl;
288 bool ResourceLocalDir::deleteIncidenceFile(
Incidence *incidence)
290 TQFile file( mURL.path() +
"/" + incidence->
uid() );
291 if ( !file.exists() )
294 mDirWatch.stopScan();
295 bool removed = file.remove();
296 mDirWatch.startScan();
300 #include "resourcelocaldir.moc" bool save(const TQString &fileName, CalFormat *format=0)
Writes out the calendar to disk in the specified format.
bool load(const TQString &fileName, CalFormat *format=0)
Loads a calendar on disk in vCalendar or iCalendar format into the current calendar.
This class provides a Todo in the sense of RFC2445.
This class provides an Event in the sense of RFC2445.
This class provides a calendar stored as a local file.
TQString uid() const
Return the unique id for the event.
This class provides the base class common to all calendar components.
This class provides a Journal in the sense of RFC2445.
Namespace KCal is for global classes, objects and/or functions in libkcal.
virtual bool addIncidence(Incidence *incidence)
Insert an Incidence into the Calendar.
This class provides a calendar resource using a local CalendarLocal object to cache the calendar data...
virtual Incidence::List rawIncidences()
Return an unfiltered list of all Incidences for this Calendar.
virtual Incidence * clone()=0
Return copy of this object.