knotes
resourcelocal.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
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <klocale.h>
00035 #include <kmessagebox.h>
00036 #include <kstandarddirs.h>
00037
00038 #include <libkcal/icalformat.h>
00039
00040 #include "knotes/resourcelocal.h"
00041 #include "knotes/resourcelocalconfig.h"
00042 #include "knotes/resourcemanager.h"
00043 #include "knotes/resourcenotes.h"
00044
00045
00046
00047 ResourceLocal::ResourceLocal( const KConfig *config )
00048 : ResourceNotes( config ), mCalendar( TQString::fromLatin1( "UTC" ) )
00049 {
00050 kdDebug(5500) << "ResourceLocal::ResourceLocal()" << endl;
00051 setType( "file" );
00052 mURL = KGlobal::dirs()->saveLocation( "data", "knotes/" ) + "notes.ics";
00053
00054 if ( config )
00055 {
00056 KURL u = config->readPathEntry( "NotesURL" );
00057 if ( !u.isEmpty() )
00058 mURL = u;
00059 }
00060 }
00061
00062 ResourceLocal::~ResourceLocal()
00063 {
00064 }
00065
00066 void ResourceLocal::writeConfig( KConfig *config )
00067 {
00068 KRES::Resource::writeConfig( config );
00069 config->writePathEntry( "NotesURL", mURL.prettyURL() );
00070 }
00071
00072 bool ResourceLocal::load()
00073 {
00074 mCalendar.load( mURL.path() );
00075
00076 KCal::Journal::List notes = mCalendar.journals();
00077 KCal::Journal::List::ConstIterator it;
00078 for ( it = notes.constBegin(); it != notes.constEnd(); ++it )
00079 manager()->registerNote( this, *it );
00080
00081 return true;
00082 }
00083
00084 bool ResourceLocal::save()
00085 {
00086 if ( !mCalendar.save( mURL.path(), new KCal::ICalFormat() ) )
00087 {
00088 KMessageBox::error( 0,
00089 i18n("<qt>Unable to save the notes to <b>%1</b>. "
00090 "Check that there is sufficient disk space."
00091 "<br>There should be a backup in the same directory "
00092 "though.</qt>").arg( mURL.path() ) );
00093 return false;
00094 }
00095
00096 return true;
00097 }
00098
00099 bool ResourceLocal::addNote( KCal::Journal *journal )
00100 {
00101 return mCalendar.addJournal( journal );
00102 }
00103
00104 bool ResourceLocal::deleteNote( KCal::Journal *journal )
00105 {
00106 return mCalendar.deleteJournal( journal );
00107 }
00108
00109 KCal::Alarm::List ResourceLocal::alarms( const TQDateTime& from, const TQDateTime& to )
00110 {
00111 KCal::Alarm::List alarms;
00112 KCal::Journal::List notes = mCalendar.journals();
00113 KCal::Journal::List::ConstIterator note;
00114 for ( note = notes.constBegin(); note != notes.constEnd(); ++note )
00115 {
00116 TQDateTime preTime = from.addSecs( -1 );
00117 KCal::Alarm::List::ConstIterator it;
00118 for( it = (*note)->alarms().constBegin(); it != (*note)->alarms().constEnd(); ++it )
00119 {
00120 if ( (*it)->enabled() )
00121 {
00122 TQDateTime dt = (*it)->nextRepetition( preTime );
00123 if ( dt.isValid() && dt <= to )
00124 alarms.append( *it );
00125 }
00126 }
00127 }
00128
00129 return alarms;
00130 }
|