summaryrefslogtreecommitdiffabout
path: root/libkcal/vcalformat.cpp
Unidiff
Diffstat (limited to 'libkcal/vcalformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/vcalformat.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 9307f12..0ebd7d1 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -8,65 +8,67 @@
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qdatetime.h> 23#include <qdatetime.h>
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 <kglobal.h>
32#include <kmessagebox.h> 33#include <kmessagebox.h>
33#include <kiconloader.h> 34#include <kiconloader.h>
34#include <klocale.h> 35#include <klocale.h>
35 36
36#include "vcc.h" 37#include "vcc.h"
37#include "vobject.h" 38#include "vobject.h"
38 39
39#include "vcaldrag.h" 40#include "vcaldrag.h"
40#include "calendar.h" 41#include "calendar.h"
41 42
42#include "vcalformat.h" 43#include "vcalformat.h"
43 44
44using namespace KCal; 45using namespace KCal;
45 46
46VCalFormat::VCalFormat() 47VCalFormat::VCalFormat()
47{ 48{
48 mCalendar = 0; 49 mCalendar = 0;
50 useLocalTime = false;
49} 51}
50 52
51VCalFormat::~VCalFormat() 53VCalFormat::~VCalFormat()
52{ 54{
53} 55}
54 56
55bool VCalFormat::load(Calendar *calendar, const QString &fileName) 57bool VCalFormat::load(Calendar *calendar, const QString &fileName)
56{ 58{
57 mCalendar = calendar; 59 mCalendar = calendar;
58 60
59 clearException(); 61 clearException();
60 62
61 kdDebug(5800) << "VCalFormat::load() " << fileName << endl; 63 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
62 64
63 VObject *vcal = 0; 65 VObject *vcal = 0;
64 66
65 // this is not necessarily only 1 vcal. Could be many vcals, or include 67 // this is not necessarily only 1 vcal. Could be many vcals, or include
66 // a vcard... 68 // a vcard...
67 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 69 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
68 70
69 if (!vcal) { 71 if (!vcal) {
70 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 72 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
71 return FALSE; 73 return FALSE;
72 } 74 }
@@ -145,66 +147,74 @@ bool VCalFormat::fromString( Calendar *calendar, const QString &text )
145 VObjectIterator i; 147 VObjectIterator i;
146 VObject *curvo; 148 VObject *curvo;
147 initPropIterator( &i, vcal ); 149 initPropIterator( &i, vcal );
148 150
149 // we only take the first object. TODO: parse all incidences. 151 // we only take the first object. TODO: parse all incidences.
150 do { 152 do {
151 curvo = nextVObject( &i ); 153 curvo = nextVObject( &i );
152 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 154 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
153 strcmp( vObjectName( curvo ), VCTodoProp ) ); 155 strcmp( vObjectName( curvo ), VCTodoProp ) );
154 156
155 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 157 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
156 Event *event = VEventToEvent( curvo ); 158 Event *event = VEventToEvent( curvo );
157 calendar->addEvent( event ); 159 calendar->addEvent( event );
158 } else { 160 } else {
159 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 161 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
160 deleteVObject( vcal ); 162 deleteVObject( vcal );
161 return false; 163 return false;
162 } 164 }
163 165
164 deleteVObject( vcal ); 166 deleteVObject( vcal );
165 167
166 return true; 168 return true;
167} 169}
168 170
169QString VCalFormat::eventToString( Event * event, Calendar *calendar) 171QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal)
170{ 172{
173
171 if ( !event ) return QString::null; 174 if ( !event ) return QString::null;
175 bool useL = useLocalTime;
176 useLocalTime = useLocal;
172 mCalendar = calendar; 177 mCalendar = calendar;
173 VObject *vevent = eventToVEvent( event ); 178 VObject *vevent = eventToVEvent( event );
174 char *buf = writeMemVObject( 0, 0, vevent ); 179 char *buf = writeMemVObject( 0, 0, vevent );
175 QString result( buf ); 180 QString result( buf );
176 cleanVObject( vevent ); 181 cleanVObject( vevent );
182 useLocalTime = useL;
177 return result; 183 return result;
178} 184}
179QString VCalFormat::todoToString( Todo * todo, Calendar *calendar ) 185QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal )
180{ 186{
187
181 if ( !todo ) return QString::null; 188 if ( !todo ) return QString::null;
189 bool useL = useLocalTime;
190 useLocalTime = useLocal;
182 mCalendar = calendar; 191 mCalendar = calendar;
183 VObject *vevent = eventToVTodo( todo ); 192 VObject *vevent = eventToVTodo( todo );
184 char *buf = writeMemVObject( 0, 0, vevent ); 193 char *buf = writeMemVObject( 0, 0, vevent );
185 QString result( buf ); 194 QString result( buf );
186 cleanVObject( vevent ); 195 cleanVObject( vevent );
196 useLocalTime = useL;
187 return result; 197 return result;
188} 198}
189 199
190QString VCalFormat::toString( Calendar *calendar ) 200QString VCalFormat::toString( Calendar *calendar )
191{ 201{
192 // TODO: Factor out VCalFormat::asString() 202 // TODO: Factor out VCalFormat::asString()
193 203
194 VObject *vcal = newVObject(VCCalProp); 204 VObject *vcal = newVObject(VCCalProp);
195 205
196 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 206 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
197 QString tmpStr = mCalendar->getTimeZoneStr(); 207 QString tmpStr = mCalendar->getTimeZoneStr();
198 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 208 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
199 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 209 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
200 210
201 // TODO: Use all data. 211 // TODO: Use all data.
202 QPtrList<Event> events = calendar->events(); 212 QPtrList<Event> events = calendar->events();
203 Event *event = events.first(); 213 Event *event = events.first();
204 if ( !event ) return QString::null; 214 if ( !event ) return QString::null;
205 215
206 VObject *vevent = eventToVEvent( event ); 216 VObject *vevent = eventToVEvent( event );
207 217
208 addVObjectProp( vcal, vevent ); 218 addVObjectProp( vcal, vevent );
209 219
210 char *buf = writeMemVObject( 0, 0, vcal ); 220 char *buf = writeMemVObject( 0, 0, vcal );
@@ -1413,51 +1423,50 @@ Event* VCalFormat::VEventToEvent(VObject *vevent)
1413 anEvent->setSyncStatus(Event::SYNCMOD); 1423 anEvent->setSyncStatus(Event::SYNCMOD);
1414 1424
1415 return anEvent; 1425 return anEvent;
1416} 1426}
1417 1427
1418 1428
1419QString VCalFormat::qDateToISO(const QDate &qd) 1429QString VCalFormat::qDateToISO(const QDate &qd)
1420{ 1430{
1421 QString tmpStr; 1431 QString tmpStr;
1422 1432
1423 ASSERT(qd.isValid()); 1433 ASSERT(qd.isValid());
1424 1434
1425 tmpStr.sprintf("%.2d%.2d%.2d", 1435 tmpStr.sprintf("%.2d%.2d%.2d",
1426 qd.year(), qd.month(), qd.day()); 1436 qd.year(), qd.month(), qd.day());
1427 return tmpStr; 1437 return tmpStr;
1428 1438
1429} 1439}
1430 1440
1431QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) 1441QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu)
1432{ 1442{
1433 QString tmpStr; 1443 QString tmpStr;
1434 1444
1435 ASSERT(qdt.date().isValid()); 1445 ASSERT(qdt.date().isValid());
1436 ASSERT(qdt.time().isValid()); 1446 ASSERT(qdt.time().isValid());
1437 if (zulu) { 1447 if (zulu && !useLocalTime ) {
1438 QDateTime tmpDT(qdt); 1448 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60);
1439 tmpDT = tmpDT.addSecs(60*(-mCalendar->getTimeZone())); // correct to GMT.
1440 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", 1449 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1441 tmpDT.date().year(), tmpDT.date().month(), 1450 tmpDT.date().year(), tmpDT.date().month(),
1442 tmpDT.date().day(), tmpDT.time().hour(), 1451 tmpDT.date().day(), tmpDT.time().hour(),
1443 tmpDT.time().minute(), tmpDT.time().second()); 1452 tmpDT.time().minute(), tmpDT.time().second());
1444 } else { 1453 } else {
1445 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", 1454 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d",
1446 qdt.date().year(), qdt.date().month(), 1455 qdt.date().year(), qdt.date().month(),
1447 qdt.date().day(), qdt.time().hour(), 1456 qdt.date().day(), qdt.time().hour(),
1448 qdt.time().minute(), qdt.time().second()); 1457 qdt.time().minute(), qdt.time().second());
1449 } 1458 }
1450 return tmpStr; 1459 return tmpStr;
1451} 1460}
1452 1461
1453QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) 1462QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr)
1454{ 1463{
1455 QDate tmpDate; 1464 QDate tmpDate;
1456 QTime tmpTime; 1465 QTime tmpTime;
1457 QString tmpStr; 1466 QString tmpStr;
1458 int year, month, day, hour, minute, second; 1467 int year, month, day, hour, minute, second;
1459 1468
1460 tmpStr = dtStr; 1469 tmpStr = dtStr;
1461 year = tmpStr.left(4).toInt(); 1470 year = tmpStr.left(4).toInt();
1462 month = tmpStr.mid(4,2).toInt(); 1471 month = tmpStr.mid(4,2).toInt();
1463 day = tmpStr.mid(6,2).toInt(); 1472 day = tmpStr.mid(6,2).toInt();