-rw-r--r-- | libkcal/qtopiaformat.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/libkcal/qtopiaformat.cpp b/libkcal/qtopiaformat.cpp index 0a4a031..2dfe1a4 100644 --- a/libkcal/qtopiaformat.cpp +++ b/libkcal/qtopiaformat.cpp | |||
@@ -1,124 +1,124 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
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 <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qptrlist.h> | 24 | #include <q3ptrlist.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qclipboard.h> | 26 | #include <qclipboard.h> |
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | #include <qtextstream.h> | 28 | #include <q3textstream.h> |
29 | #include <qxml.h> | 29 | #include <qxml.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <klocale.h> | 32 | #include <klocale.h> |
33 | 33 | ||
34 | #include "calendar.h" | 34 | #include "calendar.h" |
35 | #include "calendarlocal.h" | 35 | #include "calendarlocal.h" |
36 | 36 | ||
37 | #include "qtopiaformat.h" | 37 | #include "qtopiaformat.h" |
38 | 38 | ||
39 | using namespace KCal; | 39 | using namespace KCal; |
40 | 40 | ||
41 | class QtopiaParser : public QXmlDefaultHandler | 41 | class QtopiaParser : public QXmlDefaultHandler |
42 | { | 42 | { |
43 | public: | 43 | public: |
44 | QtopiaParser( Calendar *calendar ) : mCalendar( calendar ) { | 44 | QtopiaParser( Calendar *calendar ) : mCalendar( calendar ) { |
45 | oldCategories = 0; | 45 | oldCategories = 0; |
46 | } | 46 | } |
47 | 47 | ||
48 | bool startElement( const QString &, const QString &, const QString & qName, | 48 | bool startElement( const QString &, const QString &, const QString & qName, |
49 | const QXmlAttributes &attributes ) | 49 | const QXmlAttributes &attributes ) |
50 | { | 50 | { |
51 | if ( qName == "event" ) { | 51 | if ( qName == "event" ) { |
52 | Event *event = new Event; | 52 | Event *event = new Event; |
53 | QString uid = "Qtopia" + attributes.value( "uid" ); | 53 | QString uid = "Qtopia" + attributes.value( "uid" ); |
54 | // event->setUid( uid ); | 54 | // event->setUid( uid ); |
55 | 55 | ||
56 | event->setSummary( attributes.value( "description" ) ); | 56 | event->setSummary( attributes.value( "description" ) ); |
57 | event->setLocation( attributes.value( "location" ) ); | 57 | event->setLocation( attributes.value( "location" ) ); |
58 | event->setDescription( attributes.value( "note" ) ); | 58 | event->setDescription( attributes.value( "note" ) ); |
59 | event->setDtStart( toDateTime( attributes.value( "start" ) ) ); | 59 | event->setDtStart( toDateTime( attributes.value( "start" ) ) ); |
60 | event->setDtEnd( toDateTime( attributes.value( "end" ) ) ); | 60 | event->setDtEnd( toDateTime( attributes.value( "end" ) ) ); |
61 | 61 | ||
62 | if ( attributes.value( "type" ) == "AllDay" ) { | 62 | if ( attributes.value( "type" ) == "AllDay" ) { |
63 | event->setFloats( true ); | 63 | event->setFloats( true ); |
64 | } else { | 64 | } else { |
65 | event->setFloats( false ); | 65 | event->setFloats( false ); |
66 | } | 66 | } |
67 | 67 | ||
68 | QString rtype = attributes.value( "rtype" ); | 68 | QString rtype = attributes.value( "rtype" ); |
69 | if ( !rtype.isEmpty() ) { | 69 | if ( !rtype.isEmpty() ) { |
70 | QDate startDate = event->dtStart().date(); | 70 | QDate startDate = event->dtStart().date(); |
71 | 71 | ||
72 | QString freqStr = attributes.value( "rfreq" ); | 72 | QString freqStr = attributes.value( "rfreq" ); |
73 | int freq = freqStr.toInt(); | 73 | int freq = freqStr.toInt(); |
74 | 74 | ||
75 | QString hasEndDateStr = attributes.value( "rhasenddate" ); | 75 | QString hasEndDateStr = attributes.value( "rhasenddate" ); |
76 | bool hasEndDate = hasEndDateStr == "1"; | 76 | bool hasEndDate = hasEndDateStr == "1"; |
77 | 77 | ||
78 | QString endDateStr = attributes.value( "enddt" ); | 78 | QString endDateStr = attributes.value( "enddt" ); |
79 | QDate endDate = toDateTime( endDateStr ).date(); | 79 | QDate endDate = toDateTime( endDateStr ).date(); |
80 | 80 | ||
81 | QString weekDaysStr = attributes.value( "rweekdays" ); | 81 | QString weekDaysStr = attributes.value( "rweekdays" ); |
82 | int weekDaysNum = weekDaysStr.toInt(); | 82 | int weekDaysNum = weekDaysStr.toInt(); |
83 | if ( weekDaysNum == 0 ) | 83 | if ( weekDaysNum == 0 ) |
84 | weekDaysNum = (1 << (event->dtStart().date().dayOfWeek()-1)); | 84 | weekDaysNum = (1 << (event->dtStart().date().dayOfWeek()-1)); |
85 | 85 | ||
86 | QBitArray weekDays( 7 ); | 86 | QBitArray weekDays( 7 ); |
87 | weekDays.fill( false ); | 87 | weekDays.fill( false ); |
88 | int i; | 88 | int i; |
89 | for( i = 0; i < 7; ++i ) { | 89 | for( i = 0; i < 7; ++i ) { |
90 | weekDays.setBit( i , ( 1 << i ) & weekDaysNum ); | 90 | weekDays.setBit( i , ( 1 << i ) & weekDaysNum ); |
91 | qDebug("%d %d %d ",i, weekDaysNum, weekDays.at(i) ); | 91 | qDebug("%d %d %d ",i, weekDaysNum, weekDays.at(i) ); |
92 | } | 92 | } |
93 | 93 | ||
94 | QString posStr = attributes.value( "rposition" ); | 94 | QString posStr = attributes.value( "rposition" ); |
95 | int pos = posStr.toInt(); | 95 | int pos = posStr.toInt(); |
96 | 96 | ||
97 | Recurrence *r = event->recurrence(); | 97 | Recurrence *r = event->recurrence(); |
98 | 98 | ||
99 | if ( rtype == "Daily" ) { | 99 | if ( rtype == "Daily" ) { |
100 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 100 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
101 | else r->setDaily( freq, -1 ); | 101 | else r->setDaily( freq, -1 ); |
102 | } else if ( rtype == "Weekly" ) { | 102 | } else if ( rtype == "Weekly" ) { |
103 | // fix needed here | 103 | // fix needed here |
104 | // rweekdays not set in XML file | 104 | // rweekdays not set in XML file |
105 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 105 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
106 | else r->setWeekly( freq, weekDays, -1 ); | 106 | else r->setWeekly( freq, weekDays, -1 ); |
107 | } else if ( rtype == "MonthlyDate" ) { | 107 | } else if ( rtype == "MonthlyDate" ) { |
108 | if ( hasEndDate ) | 108 | if ( hasEndDate ) |
109 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 109 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
110 | else | 110 | else |
111 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 111 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
112 | r->addMonthlyDay( startDate.day() ); | 112 | r->addMonthlyDay( startDate.day() ); |
113 | } else if ( rtype == "MonthlyDay" ) { | 113 | } else if ( rtype == "MonthlyDay" ) { |
114 | if ( hasEndDate ) | 114 | if ( hasEndDate ) |
115 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 115 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
116 | else | 116 | else |
117 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 117 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
118 | QBitArray days( 7 ); | 118 | QBitArray days( 7 ); |
119 | days.fill( false ); | 119 | days.fill( false ); |
120 | days.setBit( startDate.dayOfWeek() - 1 ); | 120 | days.setBit( startDate.dayOfWeek() - 1 ); |
121 | r->addMonthlyPos( pos, days ); | 121 | r->addMonthlyPos( pos, days ); |
122 | } else if ( rtype == "Yearly" ) { | 122 | } else if ( rtype == "Yearly" ) { |
123 | if ( hasEndDate ) | 123 | if ( hasEndDate ) |
124 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 124 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
@@ -216,118 +216,118 @@ class QtopiaParser : public QXmlDefaultHandler | |||
216 | { | 216 | { |
217 | return "QtopiaParser: Error!"; | 217 | return "QtopiaParser: Error!"; |
218 | } | 218 | } |
219 | void setCategoriesList ( QStringList * c ) | 219 | void setCategoriesList ( QStringList * c ) |
220 | { | 220 | { |
221 | oldCategories = c; | 221 | oldCategories = c; |
222 | } | 222 | } |
223 | 223 | ||
224 | protected: | 224 | protected: |
225 | void printException( const QXmlParseException &exception ) | 225 | void printException( const QXmlParseException &exception ) |
226 | { | 226 | { |
227 | kdError() << "XML Parse Error (line " << exception.lineNumber() | 227 | kdError() << "XML Parse Error (line " << exception.lineNumber() |
228 | << ", col " << exception.columnNumber() << "): " | 228 | << ", col " << exception.columnNumber() << "): " |
229 | << exception.message() << "(public ID: '" | 229 | << exception.message() << "(public ID: '" |
230 | << exception.publicId() << "' system ID: '" | 230 | << exception.publicId() << "' system ID: '" |
231 | << exception.systemId() << "')" << endl; | 231 | << exception.systemId() << "')" << endl; |
232 | } | 232 | } |
233 | 233 | ||
234 | QDateTime toDateTime( const QString &value ) | 234 | QDateTime toDateTime( const QString &value ) |
235 | { | 235 | { |
236 | QDateTime dt; | 236 | QDateTime dt; |
237 | dt.setTime_t( value.toUInt() ); | 237 | dt.setTime_t( value.toUInt() ); |
238 | 238 | ||
239 | return dt; | 239 | return dt; |
240 | } | 240 | } |
241 | 241 | ||
242 | QStringList lookupCategories( const QString &categoryList ) | 242 | QStringList lookupCategories( const QString &categoryList ) |
243 | { | 243 | { |
244 | QStringList categoryIds = QStringList::split( ";", categoryList ); | 244 | QStringList categoryIds = QStringList::split( ";", categoryList ); |
245 | QStringList categories; | 245 | QStringList categories; |
246 | QStringList::ConstIterator it; | 246 | QStringList::ConstIterator it; |
247 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { | 247 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { |
248 | QString cate = category( *it ); | 248 | QString cate = category( *it ); |
249 | if ( oldCategories ) { | 249 | if ( oldCategories ) { |
250 | if ( ! oldCategories->contains( cate ) ) | 250 | if ( ! oldCategories->contains( cate ) ) |
251 | oldCategories->append( cate ); | 251 | oldCategories->append( cate ); |
252 | } | 252 | } |
253 | categories.append(cate ); | 253 | categories.append(cate ); |
254 | } | 254 | } |
255 | return categories; | 255 | return categories; |
256 | } | 256 | } |
257 | 257 | ||
258 | private: | 258 | private: |
259 | Calendar *mCalendar; | 259 | Calendar *mCalendar; |
260 | QStringList * oldCategories; | 260 | QStringList * oldCategories; |
261 | static QString category( const QString &id ) | 261 | static QString category( const QString &id ) |
262 | { | 262 | { |
263 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); | 263 | QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); |
264 | if ( it == mCategoriesMap.end() ) return id; | 264 | if ( it == mCategoriesMap.end() ) return id; |
265 | else return *it; | 265 | else return *it; |
266 | } | 266 | } |
267 | 267 | ||
268 | static void setCategory( const QString &id, const QString &name ) | 268 | static void setCategory( const QString &id, const QString &name ) |
269 | { | 269 | { |
270 | mCategoriesMap.insert( id, name ); | 270 | mCategoriesMap.insert( id, name ); |
271 | } | 271 | } |
272 | 272 | ||
273 | static QMap<QString,QString> mCategoriesMap; | 273 | static QMap<QString,QString> mCategoriesMap; |
274 | }; | 274 | }; |
275 | 275 | ||
276 | QMap<QString,QString> QtopiaParser::mCategoriesMap; | 276 | QMap<QString,QString> QtopiaParser::mCategoriesMap; |
277 | 277 | ||
278 | QtopiaFormat::QtopiaFormat() | 278 | QtopiaFormat::QtopiaFormat() |
279 | { | 279 | { |
280 | mCategories = 0; | 280 | mCategories = 0; |
281 | } | 281 | } |
282 | 282 | ||
283 | QtopiaFormat::~QtopiaFormat() | 283 | QtopiaFormat::~QtopiaFormat() |
284 | { | 284 | { |
285 | } | 285 | } |
286 | #include <qdom.h> | 286 | #include <qdom.h> |
287 | bool QtopiaFormat::load( Calendar *calendar, const QString &fileName ) | 287 | bool QtopiaFormat::load( Calendar *calendar, const QString &fileName ) |
288 | { | 288 | { |
289 | clearException(); | 289 | clearException(); |
290 | // qDebug("load QtopiaFormat: %s ",fileName.latin1() ); | 290 | // qDebug("load QtopiaFormat: %s ",fileName.latin1() ); |
291 | QtopiaParser handler( calendar ); | 291 | QtopiaParser handler( calendar ); |
292 | handler.setCategoriesList( mCategories ); | 292 | handler.setCategoriesList( mCategories ); |
293 | QFile xmlFile( fileName ); | 293 | QFile xmlFile( fileName ); |
294 | QXmlInputSource source( xmlFile ); | 294 | QXmlInputSource source( xmlFile ); |
295 | QXmlSimpleReader reader; | 295 | QXmlSimpleReader reader; |
296 | reader.setContentHandler( &handler ); | 296 | reader.setContentHandler( &handler ); |
297 | return reader.parse( source ); | 297 | return reader.parse( source ); |
298 | } | 298 | } |
299 | 299 | ||
300 | bool QtopiaFormat::save( Calendar *calendar, const QString &fileName ) | 300 | bool QtopiaFormat::save( Calendar *calendar, const QString &fileName ) |
301 | { | 301 | { |
302 | 302 | ||
303 | clearException(); | 303 | clearException(); |
304 | 304 | ||
305 | QString text = toString( calendar ); | 305 | QString text = toString( calendar ); |
306 | 306 | ||
307 | if ( text.isNull() ) return false; | 307 | if ( text.isNull() ) return false; |
308 | 308 | ||
309 | // TODO: write backup file | 309 | // TODO: write backup file |
310 | 310 | ||
311 | QFile file( fileName ); | 311 | QFile file( fileName ); |
312 | if (!file.open( IO_WriteOnly ) ) { | 312 | if (!file.open( QIODevice::WriteOnly ) ) { |
313 | setException(new ErrorFormat(ErrorFormat::SaveError, | 313 | setException(new ErrorFormat(ErrorFormat::SaveError, |
314 | i18n("Could not open file '%1'").arg(fileName))); | 314 | i18n("Could not open file '%1'").arg(fileName))); |
315 | return false; | 315 | return false; |
316 | } | 316 | } |
317 | QTextStream ts( &file ); | 317 | Q3TextStream ts( &file ); |
318 | ts << text; | 318 | ts << text; |
319 | file.close(); | 319 | file.close(); |
320 | 320 | ||
321 | return true; | 321 | return true; |
322 | } | 322 | } |
323 | 323 | ||
324 | bool QtopiaFormat::fromString( Calendar *, const QString & ) | 324 | bool QtopiaFormat::fromString( Calendar *, const QString & ) |
325 | { | 325 | { |
326 | 326 | ||
327 | return false; | 327 | return false; |
328 | } | 328 | } |
329 | 329 | ||
330 | QString QtopiaFormat::toString( Calendar * ) | 330 | QString QtopiaFormat::toString( Calendar * ) |
331 | { | 331 | { |
332 | return QString::null; | 332 | return QString::null; |
333 | } | 333 | } |