summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-11-06 14:30:14 (UTC)
committer zautrix <zautrix>2004-11-06 14:30:14 (UTC)
commitf8841c92d5251f713eb7a025af8fdee52de45b3d (patch) (unidiff)
tree29c3c48e5da5b5ce05126da46475de1a0a845428 /libkcal
parent71eeea80d9c449bd1983c1a9207c7123e919b55f (diff)
downloadkdepimpi-f8841c92d5251f713eb7a025af8fdee52de45b3d.zip
kdepimpi-f8841c92d5251f713eb7a025af8fdee52de45b3d.tar.gz
kdepimpi-f8841c92d5251f713eb7a025af8fdee52de45b3d.tar.bz2
category utf8 fixes
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/sharpformat.cpp45
-rw-r--r--libkcal/sharpformat.h2
2 files changed, 4 insertions, 43 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index b88e729..24b8349 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -55,25 +55,24 @@ using namespace KCal;
55// 13 RPOS pos = 4. monday in month 55// 13 RPOS pos = 4. monday in month
56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun 56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
57// 15 REND 0 = no end/ 1 = end 57// 15 REND 0 = no end/ 1 = end
58// 16 REDT rec end dt 58// 16 REDT rec end dt
59//ALSD 59//ALSD
60//ALED 60//ALED
61//MDAY 61//MDAY
62 62
63class SharpParser : public QObject 63class SharpParser : public QObject
64{ 64{
65 public: 65 public:
66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) { 66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) {
67 oldCategories = 0;
68 } 67 }
69 68
70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
71 { 70 {
72 int i = 1; 71 int i = 1;
73 bool skip = true; 72 bool skip = true;
74 int max = attList.count() -2; 73 int max = attList.count() -2;
75 while ( i < max ) { 74 while ( i < max ) {
76 if ( !attList[i].isEmpty() ) { 75 if ( !attList[i].isEmpty() ) {
77 skip = false; 76 skip = false;
78 break; 77 break;
79 } 78 }
@@ -161,25 +160,25 @@ class SharpParser : public QObject
161 } else if ( rtype == "4" ) { 160 } else if ( rtype == "4" ) {
162 if ( hasEndDate ) 161 if ( hasEndDate )
163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 162 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
164 else 163 else
165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 164 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
166 r->addYearlyNum( startDate.month() ); 165 r->addYearlyNum( startDate.month() );
167 } 166 }
168 } else { 167 } else {
169 event->recurrence()->unsetRecurs(); 168 event->recurrence()->unsetRecurs();
170 } 169 }
171 170
172 QString categoryList = attList[1] ; 171 QString categoryList = attList[1] ;
173 event->setCategories( lookupCategories( categoryList ) ); 172 event->setCategories( categoryList );
174 173
175 // strange 0 semms to mean: alarm enabled 174 // strange 0 semms to mean: alarm enabled
176 if ( attList[8] == "0" ) { 175 if ( attList[8] == "0" ) {
177 Alarm *alarm; 176 Alarm *alarm;
178 if ( event->alarms().count() > 0 ) 177 if ( event->alarms().count() > 0 )
179 alarm = event->alarms().first(); 178 alarm = event->alarms().first();
180 else { 179 else {
181 alarm = new Alarm( event ); 180 alarm = new Alarm( event );
182 event->addAlarm( alarm ); 181 event->addAlarm( alarm );
183 alarm->setType( Alarm::Audio ); 182 alarm->setType( Alarm::Audio );
184 } 183 }
185 //alarm->setType( Alarm::Audio ); 184 //alarm->setType( Alarm::Audio );
@@ -215,25 +214,25 @@ class SharpParser : public QObject
215 todo->setID( "Sharp_DTM", attList[0]); 214 todo->setID( "Sharp_DTM", attList[0]);
216 todo->setCsum( "Sharp_DTM", QString::number( cSum )); 215 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
217 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 216 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
218 217
219 todo->setSummary( attList[7] ); 218 todo->setSummary( attList[7] );
220 todo->setDescription( attList[8]); 219 todo->setDescription( attList[8]);
221 220
222 int priority = attList[6].toInt(); 221 int priority = attList[6].toInt();
223 if ( priority == 0 ) priority = 3; 222 if ( priority == 0 ) priority = 3;
224 todo->setPriority( priority ); 223 todo->setPriority( priority );
225 224
226 QString categoryList = attList[1]; 225 QString categoryList = attList[1];
227 todo->setCategories( lookupCategories( categoryList ) ); 226 todo->setCategories( categoryList );
228 227
229 228
230 229
231 QString hasDateStr = attList[3]; // due 230 QString hasDateStr = attList[3]; // due
232 if ( !hasDateStr.isEmpty() ) { 231 if ( !hasDateStr.isEmpty() ) {
233 if ( hasDateStr.right(6) == "000000" ) { 232 if ( hasDateStr.right(6) == "000000" ) {
234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 233 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
235 todo->setFloats( true ); 234 todo->setFloats( true );
236 } 235 }
237 else { 236 else {
238 todo->setDtDue( fromString( hasDateStr ) ); 237 todo->setDtDue( fromString( hasDateStr ) );
239 todo->setFloats( false ); 238 todo->setFloats( false );
@@ -262,29 +261,24 @@ class SharpParser : public QObject
262 } else if ( qName == "Category" ) { 261 } else if ( qName == "Category" ) {
263 /* 262 /*
264 QString id = attributes.value( "id" ); 263 QString id = attributes.value( "id" );
265 QString name = attributes.value( "name" ); 264 QString name = attributes.value( "name" );
266 setCategory( id, name ); 265 setCategory( id, name );
267 */ 266 */
268 } 267 }
269 //qDebug("end "); 268 //qDebug("end ");
270 return true; 269 return true;
271 } 270 }
272 271
273 272
274 void setCategoriesList ( QStringList * c )
275 {
276 oldCategories = c;
277 }
278
279 QDateTime fromString ( QString s, bool useTz = true ) { 273 QDateTime fromString ( QString s, bool useTz = true ) {
280 QDateTime dt; 274 QDateTime dt;
281 int y,m,t,h,min,sec; 275 int y,m,t,h,min,sec;
282 y = s.mid(0,4).toInt(); 276 y = s.mid(0,4).toInt();
283 m = s.mid(4,2).toInt(); 277 m = s.mid(4,2).toInt();
284 t = s.mid(6,2).toInt(); 278 t = s.mid(6,2).toInt();
285 h = s.mid(9,2).toInt(); 279 h = s.mid(9,2).toInt();
286 min = s.mid(11,2).toInt(); 280 min = s.mid(11,2).toInt();
287 sec = s.mid(13,2).toInt(); 281 sec = s.mid(13,2).toInt();
288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 282 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
289 int offset = KGlobal::locale()->localTimeOffset( dt ); 283 int offset = KGlobal::locale()->localTimeOffset( dt );
290 if ( useTz ) 284 if ( useTz )
@@ -292,63 +286,32 @@ class SharpParser : public QObject
292 return dt; 286 return dt;
293 287
294 } 288 }
295 protected: 289 protected:
296 QDateTime toDateTime( const QString &value ) 290 QDateTime toDateTime( const QString &value )
297 { 291 {
298 QDateTime dt; 292 QDateTime dt;
299 dt.setTime_t( value.toUInt() ); 293 dt.setTime_t( value.toUInt() );
300 294
301 return dt; 295 return dt;
302 } 296 }
303 297
304 QStringList lookupCategories( const QString &categoryList )
305 {
306 QStringList categoryIds = QStringList::split( ";", categoryList );
307 QStringList categories;
308 QStringList::ConstIterator it;
309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
310 QString cate = category( *it );
311 if ( oldCategories ) {
312 if ( ! oldCategories->contains( cate ) )
313 oldCategories->append( cate );
314 }
315 categories.append(cate );
316 }
317 return categories;
318 }
319
320 private: 298 private:
321 Calendar *mCalendar; 299 Calendar *mCalendar;
322 QStringList * oldCategories;
323 static QString category( const QString &id )
324 {
325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
326 if ( it == mCategoriesMap.end() ) return id;
327 else return *it;
328 }
329
330 static void setCategory( const QString &id, const QString &name )
331 {
332 mCategoriesMap.insert( id, name );
333 }
334
335 static QMap<QString,QString> mCategoriesMap;
336}; 300};
337 301
338QMap<QString,QString> SharpParser::mCategoriesMap;
339 302
340SharpFormat::SharpFormat() 303SharpFormat::SharpFormat()
341{ 304{
342 mCategories = 0; 305
343} 306}
344 307
345SharpFormat::~SharpFormat() 308SharpFormat::~SharpFormat()
346{ 309{
347} 310}
348ulong SharpFormat::getCsum( const QStringList & attList) 311ulong SharpFormat::getCsum( const QStringList & attList)
349{ 312{
350 int max = attList.count() -1; 313 int max = attList.count() -1;
351 ulong cSum = 0; 314 ulong cSum = 0;
352 int j,k,i; 315 int j,k,i;
353 int add; 316 int add;
354 for ( i = 1; i < max ; ++i ) { 317 for ( i = 1; i < max ; ++i ) {
@@ -1009,25 +972,25 @@ bool SharpFormat::fromString( Calendar *calendar, const QString & text)
1009} 972}
1010bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) 973bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type)
1011{ 974{
1012 // qDebug("test %s ", text.latin1()); 975 // qDebug("test %s ", text.latin1());
1013 QStringList templist; 976 QStringList templist;
1014 QString tempString; 977 QString tempString;
1015 int start = 0; 978 int start = 0;
1016 int len = text.length(); 979 int len = text.length();
1017 int end = text.find ("\n",start)+1; 980 int end = text.find ("\n",start)+1;
1018 bool ok = true; 981 bool ok = true;
1019 start = end; 982 start = end;
1020 SharpParser handler( calendar ); 983 SharpParser handler( calendar );
1021 handler.setCategoriesList( mCategories ); 984 // handler.setCategoriesList( mCategories );
1022 while ( start > 0 ) { 985 while ( start > 0 ) {
1023 templist.clear(); 986 templist.clear();
1024 ok = true; 987 ok = true;
1025 while ( ok ) { 988 while ( ok ) {
1026 tempString = getPart( text, ok, start ); 989 tempString = getPart( text, ok, start );
1027 if ( start >= len || start == 0 ) { 990 if ( start >= len || start == 0 ) {
1028 start = 0; 991 start = 0;
1029 ok = false; 992 ok = false;
1030 } 993 }
1031 if ( tempString.right(1) =="\n" ) 994 if ( tempString.right(1) =="\n" )
1032 tempString = tempString.left( tempString.length()-1); 995 tempString = tempString.left( tempString.length()-1);
1033 //if ( ok ) 996 //if ( ok )
diff --git a/libkcal/sharpformat.h b/libkcal/sharpformat.h
index 0b13862..a71177d 100644
--- a/libkcal/sharpformat.h
+++ b/libkcal/sharpformat.h
@@ -31,31 +31,29 @@ namespace KCal {
31 31
32/** 32/**
33 This class implements the calendar format used by Sharp. 33 This class implements the calendar format used by Sharp.
34*/ 34*/
35class SharpFormat : public QObject { 35class SharpFormat : public QObject {
36 public: 36 public:
37 /** Create new iCalendar format. */ 37 /** Create new iCalendar format. */
38 SharpFormat(); 38 SharpFormat();
39 virtual ~SharpFormat(); 39 virtual ~SharpFormat();
40 40
41 bool load( Calendar * ,Calendar *); 41 bool load( Calendar * ,Calendar *);
42 bool save( Calendar * ); 42 bool save( Calendar * );
43 void setCategoriesList ( QStringList * cat ){ mCategories = cat; }
44 bool fromString2Cal( Calendar *, Calendar *, const QString & , const QString & ); 43 bool fromString2Cal( Calendar *, Calendar *, const QString & , const QString & );
45 bool fromString( Calendar *, const QString & ); 44 bool fromString( Calendar *, const QString & );
46 QString toString( Calendar * ); 45 QString toString( Calendar * );
47 static ulong getCsum( const QStringList & ); 46 static ulong getCsum( const QStringList & );
48 47
49 private: 48 private:
50 QString getEventString( Event* ); 49 QString getEventString( Event* );
51 QString getTodoString( Todo* ); 50 QString getTodoString( Todo* );
52 QString dtToString( const QDateTime& dt, bool useTZ = true ); 51 QString dtToString( const QDateTime& dt, bool useTZ = true );
53 52
54 QStringList *mCategories;
55 int getNumFromRecord( QString answer,Incidence* inc ) ; 53 int getNumFromRecord( QString answer,Incidence* inc ) ;
56 QString getPart( const QString & text, bool &ok, int &start ); 54 QString getPart( const QString & text, bool &ok, int &start );
57}; 55};
58 56
59} 57}
60 58
61#endif 59#endif