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( QString::fromLatin1( "UTC" ) )
00049 {
00050 kdDebug(5500) << "ResourceLocal::ResourceLocal()" << endl;
00051 setType( "file" );
00052 if ( !config )
00053 {
00054 kdDebug(5500) << "No config, setting default notes.ics" << endl;
00055 mURL = KGlobal::dirs()->saveLocation( "data" ) + "knotes/notes.ics";
00056 }
00057 else
00058 {
00059 mURL = config->readPathEntry( "NotesURL" );
00060 if (mURL.isEmpty())
00061 mURL = KGlobal::dirs()->saveLocation( "data" ) + "knotes/notes.ics";
00062 }
00063 }
00064
00065 ResourceLocal::~ResourceLocal()
00066 {
00067 }
00068
00069 void ResourceLocal::writeConfig( KConfig* config )
00070 {
00071 KRES::Resource::writeConfig( config );
00072 config->writePathEntry( "NotesURL", mURL.prettyURL() );
00073 }
00074
00075 bool ResourceLocal::load()
00076 {
00077 mCalendar.load( mURL.path() );
00078
00079 KCal::Journal::List notes = mCalendar.journals();
00080 KCal::Journal::List::ConstIterator it;
00081 for ( it = notes.begin(); it != notes.end(); ++it )
00082 manager()->registerNote( this, *it );
00083
00084 return true;
00085 }
00086
00087 bool ResourceLocal::save()
00088 {
00089 if ( !mCalendar.save( mURL.path(), new KCal::ICalFormat() ) )
00090 {
00091 KMessageBox::error( 0,
00092 i18n("<qt>Unable to save the notes to <b>%1</b>. "
00093 "Check that there is sufficient disk space."
00094 "<br>There should be a backup in the same directory "
00095 "though.</qt>").arg( mURL.path() ) );
00096 return false;
00097 }
00098
00099 return true;
00100 }
00101
00102 bool ResourceLocal::addNote( KCal::Journal* journal )
00103 {
00104 mCalendar.addJournal( journal );
00105 return true;
00106 }
00107
00108 bool ResourceLocal::deleteNote( KCal::Journal* journal )
00109 {
00110 mCalendar.deleteJournal( journal );
00111 return true;
00112 }
00113
00114 KCal::Alarm::List ResourceLocal::alarms( const QDateTime& from, const QDateTime& to )
00115 {
00116 KCal::Alarm::List alarms;
00117 KCal::Journal::List notes = mCalendar.journals();
00118 KCal::Journal::List::ConstIterator note;
00119 for ( note = notes.begin(); note != notes.end(); ++note )
00120 {
00121 QDateTime preTime = from.addSecs( -1 );
00122 KCal::Alarm::List::ConstIterator it;
00123 for( it = (*note)->alarms().begin(); it != (*note)->alarms().end(); ++it )
00124 {
00125 if ( (*it)->enabled() )
00126 {
00127 QDateTime dt = (*it)->nextRepetition( preTime );
00128 if ( dt.isValid() && dt <= to )
00129 alarms.append( *it );
00130 }
00131 }
00132 }
00133
00134 return alarms;
00135 }
|