34 #include <tdelocale.h>
35 #include <tdemessagebox.h>
36 #include <kstandarddirs.h>
38 #include <libkcal/icalformat.h>
40 #include "knotes/resourcelocal.h"
41 #include "knotes/resourcelocalconfig.h"
42 #include "knotes/resourcemanager.h"
43 #include "knotes/resourcenotes.h"
47 ResourceLocal::ResourceLocal(
const TDEConfig *config )
48 :
ResourceNotes( config ), mCalendar( TQString::fromLatin1(
"UTC" ) )
50 kdDebug(5500) <<
"ResourceLocal::ResourceLocal()" << endl;
52 mURL = TDEGlobal::dirs()->saveLocation(
"data",
"knotes/" ) +
"notes.ics";
56 KURL u = config->readPathEntry(
"NotesURL" );
62 ResourceLocal::~ResourceLocal()
66 void ResourceLocal::writeConfig( TDEConfig *config )
68 KRES::Resource::writeConfig( config );
69 config->writePathEntry(
"NotesURL", mURL.prettyURL() );
72 bool ResourceLocal::load()
74 mCalendar.load( mURL.path() );
76 KCal::Journal::List notes = mCalendar.journals();
77 KCal::Journal::List::ConstIterator it;
78 for ( it = notes.constBegin(); it != notes.constEnd(); ++it )
79 manager()->registerNote(
this, *it );
84 bool ResourceLocal::save()
86 if ( !mCalendar.save( mURL.path(),
new KCal::ICalFormat() ) )
88 KMessageBox::error( 0,
89 i18n(
"<qt>Unable to save the notes to <b>%1</b>. "
90 "Check that there is sufficient disk space."
91 "<br>There should be a backup in the same directory "
92 "though.</qt>").arg( mURL.path() ) );
99 bool ResourceLocal::addNote( KCal::Journal *journal )
101 return mCalendar.addJournal( journal );
104 bool ResourceLocal::deleteNote( KCal::Journal *journal )
106 return mCalendar.deleteJournal( journal );
109 KCal::Alarm::List ResourceLocal::alarms(
const TQDateTime& from,
const TQDateTime& to )
111 KCal::Alarm::List alarms;
112 KCal::Journal::List notes = mCalendar.journals();
113 KCal::Journal::List::ConstIterator note;
114 for ( note = notes.constBegin(); note != notes.constEnd(); ++note )
116 TQDateTime preTime = from.addSecs( -1 );
117 KCal::Alarm::List::ConstIterator it;
118 for( it = (*note)->alarms().constBegin(); it != (*note)->alarms().constEnd(); ++it )
120 if ( (*it)->enabled() )
122 TQDateTime dt = (*it)->nextRepetition( preTime );
123 if ( dt.isValid() && dt <= to )
124 alarms.append( *it );
This class provides the interfaces for a KNotes resource.