libkcal Library API Documentation

filestorage.cpp

00001 /* 00002 This file is part of libkcal. 00003 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 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 // kdDebug(5800) << "FileStorage::load(): '" << mFileName << "'" << endl; 00082 00083 // do we want to silently accept this, or make some noise? Dunno... 00084 // it is a semantical thing vs. a practical thing. 00085 if (mFileName.isEmpty()) return false; 00086 00087 // Always try to load with iCalendar. It will detect, if it is actually a 00088 // vCalendar file. 00089 ICalFormat iCal; 00090 00091 bool success = iCal.load( calendar(), mFileName); 00092 00093 if ( !success ) { 00094 if ( iCal.exception() ) { 00095 // kdDebug(5800) << "---Error: " << mFormat->exception()->errorCode() << endl; 00096 if ( iCal.exception()->errorCode() == ErrorFormat::CalVersion1 ) { 00097 // Expected non vCalendar file, but detected vCalendar 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 // kdDebug(5800) << "---Success" << endl; 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 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:49:08 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003