00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include <stdlib.h>
00022
00023
#include <qdatetime.h>
00024
#include <qstring.h>
00025
#include <qptrlist.h>
00026
00027
#include <kdebug.h>
00028
00029
#include "calendar.h"
00030
#include "vcaldrag.h"
00031
#include "vcalformat.h"
00032
#include "icalformat.h"
00033
00034
#include "filestorage.h"
00035
00036
using namespace KCal;
00037
00038 FileStorage::FileStorage(
Calendar *cal,
const QString &fileName,
00039
CalFormat *format )
00040 :
CalStorage( cal ),
00041 mFileName( fileName ),
00042 mSaveFormat( format )
00043 {
00044 }
00045
00046 FileStorage::~FileStorage()
00047 {
00048
delete mSaveFormat;
00049 }
00050
00051
void FileStorage::setFileName(
const QString &fileName )
00052 {
00053 mFileName = fileName;
00054 }
00055
00056
QString FileStorage::fileName()const
00057 {
00058
return mFileName;
00059 }
00060
00061
00062 void FileStorage::setSaveFormat(
CalFormat *format )
00063 {
00064
delete mSaveFormat;
00065 mSaveFormat = format;
00066 }
00067
00068
CalFormat *FileStorage::saveFormat()const
00069 {
00070
return mSaveFormat;
00071 }
00072
00073
00074
bool FileStorage::open()
00075 {
00076
return true;
00077 }
00078
00079
bool FileStorage::load()
00080 {
00081
00082
00083
00084
00085
if (mFileName.isEmpty())
return false;
00086
00087
00088
00089
ICalFormat iCal;
00090
00091
bool success = iCal.
load( calendar(), mFileName);
00092
00093
if ( !success ) {
00094
if ( iCal.
exception() ) {
00095
00096
if ( iCal.
exception()->
errorCode() == ErrorFormat::CalVersion1 ) {
00097
00098 kdDebug(5800) <<
"FileStorage::load() Fallback to VCalFormat" << endl;
00099
VCalFormat vCal;
00100 success = vCal.
load( calendar(), mFileName );
00101 calendar()->
setLoadedProductId( vCal.
productId() );
00102 }
else {
00103
return false;
00104 }
00105 }
else {
00106 kdDebug(5800) <<
"Warning! There should be set an exception." << endl;
00107
return false;
00108 }
00109 }
else {
00110
00111 calendar()->
setLoadedProductId( iCal.
loadedProductId() );
00112 }
00113
00114 calendar()->
setModified(
false );
00115
00116
return true;
00117 }
00118
00119
bool FileStorage::save()
00120 {
00121
if ( mFileName.isEmpty() )
return false;
00122
00123
CalFormat *format = 0;
00124
if ( mSaveFormat ) format = mSaveFormat;
00125
else format =
new ICalFormat;
00126
00127
bool success = format->
save( calendar(), mFileName );
00128
00129
if ( success ) {
00130 calendar()->
setModified(
false );
00131 }
else {
00132
if ( !format->
exception() ) {
00133 kdDebug(5800) <<
"FileStorage::save(): Error. There should be set an expection."
00134 << endl;
00135 }
else {
00136 kdDebug(5800) <<
"FileStorage::save(): " << format->
exception()->
message()
00137 << endl;
00138 }
00139 }
00140
00141
if ( !mSaveFormat )
delete format;
00142
00143
return success;
00144 }
00145
00146
bool FileStorage::close()
00147 {
00148
return true;
00149 }