summaryrefslogtreecommitdiffabout
path: root/libkcal/filestorage.cpp
Unidiff
Diffstat (limited to 'libkcal/filestorage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/filestorage.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/libkcal/filestorage.cpp b/libkcal/filestorage.cpp
new file mode 100644
index 0000000..00c15d9
--- a/dev/null
+++ b/libkcal/filestorage.cpp
@@ -0,0 +1,140 @@
1/*
2 This file is part of libkcal.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <stdlib.h>
22
23#include <qdatetime.h>
24#include <qstring.h>
25#include <qptrlist.h>
26
27#include <kdebug.h>
28
29#include "calendar.h"
30#include "vcaldrag.h"
31#include "vcalformat.h"
32#include "icalformat.h"
33
34#include "filestorage.h"
35
36using namespace KCal;
37
38FileStorage::FileStorage( Calendar *cal, const QString &fileName,
39 CalFormat *format )
40 : CalStorage( cal ),
41 mFileName( fileName ),
42 mSaveFormat( format )
43{
44}
45
46FileStorage::~FileStorage()
47{
48 delete mSaveFormat;
49}
50
51void FileStorage::setFileName( const QString &fileName )
52{
53 mFileName = fileName;
54}
55
56QString FileStorage::fileName()const
57{
58 return mFileName;
59}
60
61
62void FileStorage::setSaveFormat( CalFormat *format )
63{
64 delete mSaveFormat;
65 mSaveFormat = format;
66}
67
68CalFormat *FileStorage::saveFormat()const
69{
70 return mSaveFormat;
71}
72
73
74bool FileStorage::open()
75{
76 return true;
77}
78
79bool FileStorage::load( bool quick )
80{
81 kdDebug(5800) << "FileStorage::load(): '" << mFileName << "'" << endl;
82
83 // do we want to silently accept this, or make some noise? Dunno...
84 // it is a semantical thing vs. a practical thing.
85 if (mFileName.isEmpty()) return false;
86
87 // Always try to load with iCalendar. It will detect, if it is actually a
88 // vCalendar file.
89 ICalFormat iCal (quick );
90
91 bool success = iCal.load( calendar(), mFileName);
92
93 if ( !success ) {
94 if ( iCal.exception() ) {
95// kdDebug(5800) << "---Error: " << mFormat->exception()->errorCode() << endl;
96 if ( iCal.exception()->errorCode() == ErrorFormat::CalVersion1 ) {
97 // Expected non vCalendar file, but detected vCalendar
98 kdDebug(5800) << "FileStorage::load() Fallback to VCalFormat" << endl;
99 VCalFormat vCal;
100 success = vCal.load( calendar(), mFileName );
101 calendar()->setLoadedProductId( vCal.productId() );
102 } else {
103 return false;
104 }
105 } else {
106 kdDebug(5800) << "Warning! There should be set an exception." << endl;
107 return false;
108 }
109 } else {
110// kdDebug(5800) << "---Success" << endl;
111 calendar()->setLoadedProductId( iCal.loadedProductId() );
112 }
113
114 calendar()->setModified( false );
115
116 return true;
117}
118
119bool FileStorage::save()
120{
121 if ( mFileName.isEmpty() ) return false;
122
123 bool success;
124
125 if ( mSaveFormat ) {
126 success = mSaveFormat->save( calendar(), mFileName);
127 } else {
128 ICalFormat iCal;
129 success = iCal.save( calendar(), mFileName);
130 }
131
132 if ( success ) calendar()->setModified( false );
133
134 return success;
135}
136
137bool FileStorage::close()
138{
139 return true;
140}