26 #include <tqdatetime.h>
28 #include <tqptrlist.h>
31 #include <tdelocale.h>
33 #include <kstandarddirs.h>
36 #include "vcalformat.h"
37 #include "icalformat.h"
38 #include "exceptions.h"
39 #include "incidence.h"
43 #include "filestorage.h"
45 #include <tderesources/configwidget.h>
47 #include "resourcelocalconfig.h"
49 #include "resourcelocal.h"
53 class ResourceLocal::Private
56 TQDateTime mLastModified;
63 TQString url = config->readPathEntry(
"CalendarURL" );
66 TQString format = config->readEntry(
"Format" );
67 if ( format ==
"ical" )
69 else if ( format ==
"vcal" )
84 mURL = KURL( fileName );
90 void ResourceLocal::writeConfig( TDEConfig* config )
92 kdDebug(5800) <<
"ResourceLocal::writeConfig()" << endl;
94 ResourceCalendar::writeConfig( config );
95 config->writePathEntry(
"CalendarURL", mURL.prettyURL() );
96 TQString typeID =
typeid( *mFormat ).name();
98 if (
typeid( *mFormat ) ==
typeid(
ICalFormat ) )
99 config->writeEntry(
"Format",
"ical" );
100 else if (
typeid( *mFormat ) ==
typeid(
VCalFormat ) )
101 config->writeEntry(
"Format",
"vcal" );
103 kdDebug(5800) <<
"ERROR: Unknown format type" << endl;
106 void ResourceLocal::init()
108 d =
new ResourceLocal::Private;
114 connect( &mDirWatch, TQ_SIGNAL( dirty(
const TQString & ) ),
115 TQ_SLOT( reload() ) );
116 connect( &mDirWatch, TQ_SIGNAL( created(
const TQString & ) ),
117 TQ_SLOT( reload() ) );
118 connect( &mDirWatch, TQ_SIGNAL( deleted(
const TQString & ) ),
119 TQ_SLOT( reload() ) );
121 mLock =
new TDEABC::Lock( mURL.path() );
123 mDirWatch.addFile( mURL.path() );
124 mDirWatch.startScan();
128 ResourceLocal::~ResourceLocal()
130 mDirWatch.stopScan();
139 TQDateTime ResourceLocal::readLastModified()
141 TQFileInfo fi( mURL.path() );
142 return fi.lastModified();
149 if ( !TDEStandardDirs::exists( mURL.path() ) ) {
150 kdDebug(5800) <<
"ResourceLocal::load(): File doesn't exist yet." << endl;
154 success = mCalendar.
load( mURL.path() );
155 if ( success ) d->mLastModified = readLastModified();
163 bool success = mCalendar.
save( mURL.path() );
164 d->mLastModified = readLastModified();
176 kdDebug(5800) <<
"ResourceLocal::doReload()" << endl;
178 if ( !isOpen() )
return false;
180 if ( d->mLastModified == readLastModified() ) {
181 kdDebug(5800) <<
"ResourceLocal::reload(): file not modified since last read."
187 mCalendar.
load( mURL.path() );
191 void ResourceLocal::reload()
197 void ResourceLocal::dump()
const
199 ResourceCalendar::dump();
200 kdDebug(5800) <<
" Url: " << mURL.url() << endl;
203 TQString ResourceLocal::fileName()
const
208 bool ResourceLocal::setFileName(
const TQString &fileName )
210 bool open = isOpen();
213 mDirWatch.stopScan();
214 mDirWatch.removeFile( mURL.path() );
215 mURL = KURL( fileName );
216 mLock =
new TDEABC::Lock( mURL.path() );
217 mDirWatch.addFile( mURL.path() );
218 mDirWatch.startScan();
224 if ( key ==
"File" ) {
225 return setFileName( value );
231 #include "resourcelocal.moc"
void close()
Clears out the current calendar, freeing all used memory etc.
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.
This class provides a calendar resource using a local CalendarLocal object to cache the calendar data...
void setSavePolicy(int policy)
Set save policy.
void resourceChanged(ResourceCalendar *)
This signal is emitted when the data in the resource has changed.
virtual bool doReload()
Called by reload() to reload the resource, if it is already open.
virtual bool doSave()
Do the actual saving of the resource data.
bool setValue(const TQString &key, const TQString &value)
Sets a particular value of the resource's configuration.
ResourceLocal(const TDEConfig *)
Create resource from configuration information stored in a TDEConfig object.
virtual bool doLoad()
Do the actual loading of the resource data.
TDEABC::Lock * lock()
Return object for locking the resource.
Namespace KCal is for global classes, objects and/or functions in libkcal.