25#include <tqdatetime.h>
26#include <tqfileinfo.h>
34#include <kstandarddirs.h>
37#include "vcalformat.h"
38#include "icalformat.h"
39#include "exceptions.h"
40#include "calendarlocal.h"
45#include "filestorage.h"
47#include <tderesources/configwidget.h>
49#include "resourcelocaldirconfig.h"
51#include "resourcelocaldir.h"
55ResourceLocalDir::ResourceLocalDir(
const TDEConfig* config )
65ResourceLocalDir::ResourceLocalDir(
const TQString& dirName )
68 mURL = KURL( dirName );
74void ResourceLocalDir::readConfig(
const TDEConfig *config )
76 TQString url = config->readPathEntry(
"CalendarURL" );
80void ResourceLocalDir::writeConfig( TDEConfig *config )
82 kdDebug(5800) <<
"ResourceLocalDir::writeConfig()" << endl;
84 ResourceCalendar::writeConfig( config );
86 config->writePathEntry(
"CalendarURL", mURL.prettyURL() );
89void ResourceLocalDir::init()
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();
109ResourceLocalDir::~ResourceLocalDir()
118 TQFileInfo dirInfo( mURL.path() );
119 return dirInfo.isDir() && dirInfo.isReadable() &&
120 ( dirInfo.isWritable() || readOnly() );
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;
157 CalendarLocal cal( mCalendar.timeZoneId() );
158 if ( !doFileLoad( cal, fileName ) ) {
166bool 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() );
181 Incidence::List list;
184 list = addedIncidences();
185 list += changedIncidences();
187 for ( Incidence::List::iterator it = list.begin(); it != list.end(); ++it )
196 if ( mDeletedIncidences.contains(
incidence ) ) {
201 mDirWatch.stopScan();
203 TQString fileName = mURL.path() +
"/" +
incidence->uid();
204 kdDebug(5800) <<
"writing '" << fileName <<
"'" << endl;
206 CalendarLocal cal( mCalendar.timeZoneId() );
208 const bool ret = cal.
save( fileName );
210 mDirWatch.startScan();
220void ResourceLocalDir::reload(
const TQString &file )
222 kdDebug(5800) <<
"ResourceLocalDir::reload()" << endl;
227 kdDebug(5800) <<
" File: '" << file <<
"'" << endl;
236bool ResourceLocalDir::deleteEvent(
Event *event)
238 kdDebug(5800) <<
"ResourceLocalDir::deleteEvent" << endl;
239 if ( deleteIncidenceFile(
event) ) {
240 if ( mCalendar.deleteEvent(
event ) ) {
241 mDeletedIncidences.append(
event );
252bool ResourceLocalDir::deleteTodo(
Todo *todo)
254 if ( deleteIncidenceFile(
todo) ) {
255 if ( mCalendar.deleteTodo(
todo ) ) {
256 mDeletedIncidences.append(
todo );
267bool ResourceLocalDir::deleteJournal(
Journal *journal )
269 if ( deleteIncidenceFile(
journal ) ) {
270 if ( mCalendar.deleteJournal(
journal ) ) {
271 mDeletedIncidences.append(
journal );
282void ResourceLocalDir::dump()
const
284 ResourceCalendar::dump();
285 kdDebug(5800) <<
" Url: " << mURL.url() << endl;
288bool 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"
This class provides a calendar stored as a local file.
bool load(const TQString &fileName, CalFormat *format=0)
Loads a calendar on disk in vCalendar or iCalendar format into the current calendar.
bool save(const TQString &fileName, CalFormat *format=0)
Writes out the calendar to disk in the specified format.
virtual bool addIncidence(Incidence *incidence)
Insert an Incidence into the Calendar.
virtual Incidence::List rawIncidences()
Return an unfiltered list of all Incidences for this Calendar.
This class provides an Event in the sense of RFC2445.
This class provides the base class common to all calendar components.
virtual Incidence * clone()=0
Return copy of this object.
This class provides a Journal in the sense of RFC2445.
This class provides a calendar resource using a local CalendarLocal object to cache the calendar data...
void setSavePolicy(int policy)
Set save policy.
virtual bool doOpen()
Opens the resource.
Journal * journal(const TQString &uid)
Return Journal with given unique id.
Todo * todo(const TQString &uid)
Searches todolist for an event with this unique string identifier, returns a pointer or null.
Event * event(const TQString &UniqueStr)
Retrieves an event on the basis of the unique string ID.
virtual bool doLoad()=0
Do the actual loading of the resource data.
virtual bool doSave()=0
Do the actual saving of the resource data.
bool load()
Load resource data.
void resourceChanged(ResourceCalendar *)
This signal is emitted when the data in the resource has changed.
virtual TDEABC::Lock * lock()=0
Return object for locking the resource.
Incidence * incidence(const TQString &uid)
Return incidence with given unique id.
This class provides a Todo in the sense of RFC2445.
Namespace KCal is for global classes, objects and/or functions in libkcal.