summaryrefslogtreecommitdiffabout
path: root/libkcal/vcalformat.cpp
Unidiff
Diffstat (limited to 'libkcal/vcalformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/vcalformat.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 1167e58..076cd3f 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -24,48 +24,49 @@
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qclipboard.h> 27#include <qclipboard.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qfile.h> 29#include <qfile.h>
30 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kmessagebox.h> 32#include <kmessagebox.h>
33#include <kiconloader.h> 33#include <kiconloader.h>
34#include <klocale.h> 34#include <klocale.h>
35 35
36#include "vcc.h" 36#include "vcc.h"
37#include "vobject.h" 37#include "vobject.h"
38 38
39#include "vcaldrag.h" 39#include "vcaldrag.h"
40#include "calendar.h" 40#include "calendar.h"
41 41
42#include "vcalformat.h" 42#include "vcalformat.h"
43 43
44using namespace KCal; 44using namespace KCal;
45 45
46VCalFormat::VCalFormat() 46VCalFormat::VCalFormat()
47{ 47{
48 mCalendar = 0;
48} 49}
49 50
50VCalFormat::~VCalFormat() 51VCalFormat::~VCalFormat()
51{ 52{
52} 53}
53 54
54bool VCalFormat::load(Calendar *calendar, const QString &fileName) 55bool VCalFormat::load(Calendar *calendar, const QString &fileName)
55{ 56{
56 mCalendar = calendar; 57 mCalendar = calendar;
57 58
58 clearException(); 59 clearException();
59 60
60 kdDebug(5800) << "VCalFormat::load() " << fileName << endl; 61 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
61 62
62 VObject *vcal = 0; 63 VObject *vcal = 0;
63 64
64 // this is not necessarily only 1 vcal. Could be many vcals, or include 65 // this is not necessarily only 1 vcal. Could be many vcals, or include
65 // a vcard... 66 // a vcard...
66 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 67 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
67 68
68 if (!vcal) { 69 if (!vcal) {
69 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 70 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
70 return FALSE; 71 return FALSE;
71 } 72 }
@@ -144,60 +145,62 @@ bool VCalFormat::fromString( Calendar *calendar, const QString &text )
144 VObjectIterator i; 145 VObjectIterator i;
145 VObject *curvo; 146 VObject *curvo;
146 initPropIterator( &i, vcal ); 147 initPropIterator( &i, vcal );
147 148
148 // we only take the first object. TODO: parse all incidences. 149 // we only take the first object. TODO: parse all incidences.
149 do { 150 do {
150 curvo = nextVObject( &i ); 151 curvo = nextVObject( &i );
151 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 152 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
152 strcmp( vObjectName( curvo ), VCTodoProp ) ); 153 strcmp( vObjectName( curvo ), VCTodoProp ) );
153 154
154 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 155 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
155 Event *event = VEventToEvent( curvo ); 156 Event *event = VEventToEvent( curvo );
156 calendar->addEvent( event ); 157 calendar->addEvent( event );
157 } else { 158 } else {
158 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 159 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
159 deleteVObject( vcal ); 160 deleteVObject( vcal );
160 return false; 161 return false;
161 } 162 }
162 163
163 deleteVObject( vcal ); 164 deleteVObject( vcal );
164 165
165 return true; 166 return true;
166} 167}
167 168
168QString VCalFormat::eventToString( Event * event) 169QString VCalFormat::eventToString( Event * event, Calendar *calendar)
169{ 170{
170 if ( !event ) return QString::null; 171 if ( !event ) return QString::null;
172 mCalendar = calendar;
171 VObject *vevent = eventToVEvent( event ); 173 VObject *vevent = eventToVEvent( event );
172 char *buf = writeMemVObject( 0, 0, vevent ); 174 char *buf = writeMemVObject( 0, 0, vevent );
173 QString result( buf ); 175 QString result( buf );
174 cleanVObject( vevent ); 176 cleanVObject( vevent );
175 return result; 177 return result;
176} 178}
177QString VCalFormat::todoToString( Todo * todo ) 179QString VCalFormat::todoToString( Todo * todo, Calendar *calendar )
178{ 180{
179 if ( !todo ) return QString::null; 181 if ( !todo ) return QString::null;
182 mCalendar = calendar;
180 VObject *vevent = eventToVTodo( todo ); 183 VObject *vevent = eventToVTodo( todo );
181 char *buf = writeMemVObject( 0, 0, vevent ); 184 char *buf = writeMemVObject( 0, 0, vevent );
182 QString result( buf ); 185 QString result( buf );
183 cleanVObject( vevent ); 186 cleanVObject( vevent );
184 return result; 187 return result;
185} 188}
186 189
187QString VCalFormat::toString( Calendar *calendar ) 190QString VCalFormat::toString( Calendar *calendar )
188{ 191{
189 // TODO: Factor out VCalFormat::asString() 192 // TODO: Factor out VCalFormat::asString()
190 193
191 VObject *vcal = newVObject(VCCalProp); 194 VObject *vcal = newVObject(VCCalProp);
192 195
193 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 196 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
194 QString tmpStr = mCalendar->getTimeZoneStr(); 197 QString tmpStr = mCalendar->getTimeZoneStr();
195 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 198 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
196 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 199 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
197 200
198 // TODO: Use all data. 201 // TODO: Use all data.
199 QPtrList<Event> events = calendar->events(); 202 QPtrList<Event> events = calendar->events();
200 Event *event = events.first(); 203 Event *event = events.first();
201 if ( !event ) return QString::null; 204 if ( !event ) return QString::null;
202 205
203 VObject *vevent = eventToVEvent( event ); 206 VObject *vevent = eventToVEvent( event );