00001
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 "knoteslegacy.h"
00041
00042
#include "knotes/resourcelocal.h"
00043
#include "knotes/resourcemanager.h"
00044
00045
00046
00047 ResourceLocal::ResourceLocal(
const KConfig* config )
00048 :
ResourceNotes( config )
00049 {
00050
if ( !config )
00051 setType(
"file" );
00052 }
00053
00054 ResourceLocal::~ResourceLocal()
00055 {
00056 }
00057
00058
bool ResourceLocal::load()
00059 {
00060 mCalendar.load( KGlobal::dirs()->saveLocation(
"data" ) +
"knotes/notes.ics" );
00061
00062
00063
00064
00065
00066
00067
00068
if ( KNotesLegacy::convert( &mCalendar ) )
00069 save();
00070
00071 KCal::Journal::List notes = mCalendar.journals();
00072 KCal::Journal::List::ConstIterator it;
00073
for ( it = notes.begin(); it != notes.end(); ++it )
00074 manager()->registerNote(
this, *it );
00075
00076
return true;
00077 }
00078
00079
bool ResourceLocal::save()
00080 {
00081
QString file = KGlobal::dirs()->saveLocation(
"data" ) +
"knotes/notes.ics";
00082
00083
if ( !mCalendar.save( file,
new KCal::ICalFormat() ) )
00084 {
00085 KMessageBox::error( 0,
00086 i18n(
"<qt>Unable to save the notes to <b>%1</b>. "
00087
"Check that there is sufficient disk space."
00088
"<br>There should be a backup in the same directory "
00089
"though.</qt>").arg( file ) );
00090
return false;
00091 }
00092
00093
return true;
00094 }
00095
00096
bool ResourceLocal::addNote( KCal::Journal* journal )
00097 {
00098 mCalendar.addJournal( journal );
00099
return true;
00100 }
00101
00102
bool ResourceLocal::deleteNote( KCal::Journal* journal )
00103 {
00104 mCalendar.deleteJournal( journal );
00105
return true;
00106 }