author | zecke <zecke> | 2002-10-18 14:09:14 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-18 14:09:14 (UTC) |
commit | 461113126af82cd6343eedab36ecabb4253780ee (patch) (unidiff) | |
tree | 3176b63dd7f99c58138f237805c88db334fd4a38 /libopie | |
parent | a574a09dd7b24091a4d2093c8b046ccd32e78d63 (diff) | |
download | opie-461113126af82cd6343eedab36ecabb4253780ee.zip opie-461113126af82cd6343eedab36ecabb4253780ee.tar.gz opie-461113126af82cd6343eedab36ecabb4253780ee.tar.bz2 |
Add a small quirk mode... for testing
Fix parsing of due Date
We can not rely that HasDate is past the dates..
do the final QDate generation just before adding
the OTodo
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 7a55c67..385fd27 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -71,97 +71,105 @@ bool OTodoAccessXML::load() { | |||
71 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) | 71 | if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) |
72 | break; | 72 | break; |
73 | 73 | ||
74 | // we have another attribute, read it. | 74 | // we have another attribute, read it. |
75 | int j = i; | 75 | int j = i; |
76 | while ( j < len && dt[j] != '=' ) | 76 | while ( j < len && dt[j] != '=' ) |
77 | ++j; | 77 | ++j; |
78 | QCString attr( dt+i, j-i+1); | 78 | QCString attr( dt+i, j-i+1); |
79 | 79 | ||
80 | i = ++j; // skip = | 80 | i = ++j; // skip = |
81 | 81 | ||
82 | // find the start of quotes | 82 | // find the start of quotes |
83 | while ( i < len && dt[i] != '"' ) | 83 | while ( i < len && dt[i] != '"' ) |
84 | ++i; | 84 | ++i; |
85 | j = ++i; | 85 | j = ++i; |
86 | 86 | ||
87 | bool haveUtf = FALSE; | 87 | bool haveUtf = FALSE; |
88 | bool haveEnt = FALSE; | 88 | bool haveEnt = FALSE; |
89 | while ( j < len && dt[j] != '"' ) { | 89 | while ( j < len && dt[j] != '"' ) { |
90 | if ( ((unsigned char)dt[j]) > 0x7f ) | 90 | if ( ((unsigned char)dt[j]) > 0x7f ) |
91 | haveUtf = TRUE; | 91 | haveUtf = TRUE; |
92 | if ( dt[j] == '&' ) | 92 | if ( dt[j] == '&' ) |
93 | haveEnt = TRUE; | 93 | haveEnt = TRUE; |
94 | ++j; | 94 | ++j; |
95 | } | 95 | } |
96 | if ( i == j ) { | 96 | if ( i == j ) { |
97 | // empty value | 97 | // empty value |
98 | i = j + 1; | 98 | i = j + 1; |
99 | continue; | 99 | continue; |
100 | } | 100 | } |
101 | 101 | ||
102 | QCString value( dt+i, j-i+1 ); | 102 | QCString value( dt+i, j-i+1 ); |
103 | i = j + 1; | 103 | i = j + 1; |
104 | 104 | ||
105 | QString str = (haveUtf ? QString::fromUtf8( value ) | 105 | QString str = (haveUtf ? QString::fromUtf8( value ) |
106 | : QString::fromLatin1( value ) ); | 106 | : QString::fromLatin1( value ) ); |
107 | if ( haveEnt ) | 107 | if ( haveEnt ) |
108 | str = Qtopia::plainString( str ); | 108 | str = Qtopia::plainString( str ); |
109 | 109 | ||
110 | /* | 110 | /* |
111 | * add key + value | 111 | * add key + value |
112 | */ | 112 | */ |
113 | todo( &dict, ev, attr, str ); | 113 | todo( &dict, ev, attr, str ); |
114 | 114 | ||
115 | } | 115 | } |
116 | /* | 116 | /* |
117 | * now add it | 117 | * now add it |
118 | */ | 118 | */ |
119 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { | ||
120 | ev.setUid( 1 ); | ||
121 | m_changed = true; | ||
122 | } | ||
123 | if ( ev.hasDueDate() ) { | ||
124 | ev.setDueDate( QDate(m_year, m_month, m_day) ); | ||
125 | } | ||
119 | m_events.insert(ev.uid(), ev ); | 126 | m_events.insert(ev.uid(), ev ); |
127 | m_year = m_month = m_day = -1; | ||
120 | } | 128 | } |
121 | 129 | ||
122 | qWarning("counts %d records loaded!", m_events.count() ); | 130 | qWarning("counts %d records loaded!", m_events.count() ); |
123 | return true; | 131 | return true; |
124 | } | 132 | } |
125 | bool OTodoAccessXML::reload() { | 133 | bool OTodoAccessXML::reload() { |
126 | return load(); | 134 | return load(); |
127 | } | 135 | } |
128 | bool OTodoAccessXML::save() { | 136 | bool OTodoAccessXML::save() { |
129 | // qWarning("saving"); | 137 | // qWarning("saving"); |
130 | if (!m_opened || !m_changed ) { | 138 | if (!m_opened || !m_changed ) { |
131 | // qWarning("not saving"); | 139 | // qWarning("not saving"); |
132 | return true; | 140 | return true; |
133 | } | 141 | } |
134 | QString strNewFile = m_file + ".new"; | 142 | QString strNewFile = m_file + ".new"; |
135 | QFile f( strNewFile ); | 143 | QFile f( strNewFile ); |
136 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 144 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
137 | return false; | 145 | return false; |
138 | 146 | ||
139 | int written; | 147 | int written; |
140 | QString out; | 148 | QString out; |
141 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 149 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
142 | 150 | ||
143 | // for all todos | 151 | // for all todos |
144 | QMap<int, OTodo>::Iterator it; | 152 | QMap<int, OTodo>::Iterator it; |
145 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 153 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
146 | out+= "<Task " + toString( (*it) ) + " />\n"; | 154 | out+= "<Task " + toString( (*it) ) + " />\n"; |
147 | QCString cstr = out.utf8(); | 155 | QCString cstr = out.utf8(); |
148 | written = f.writeBlock( cstr.data(), cstr.length() ); | 156 | written = f.writeBlock( cstr.data(), cstr.length() ); |
149 | 157 | ||
150 | /* less written then we wanted */ | 158 | /* less written then we wanted */ |
151 | if ( written != (int)cstr.length() ) { | 159 | if ( written != (int)cstr.length() ) { |
152 | f.close(); | 160 | f.close(); |
153 | QFile::remove( strNewFile ); | 161 | QFile::remove( strNewFile ); |
154 | return false; | 162 | return false; |
155 | } | 163 | } |
156 | out = QString::null; | 164 | out = QString::null; |
157 | } | 165 | } |
158 | 166 | ||
159 | out += "</Tasks>"; | 167 | out += "</Tasks>"; |
160 | QCString cstr = out.utf8(); | 168 | QCString cstr = out.utf8(); |
161 | written = f.writeBlock( cstr.data(), cstr.length() ); | 169 | written = f.writeBlock( cstr.data(), cstr.length() ); |
162 | 170 | ||
163 | if ( written != (int)cstr.length() ) { | 171 | if ( written != (int)cstr.length() ) { |
164 | f.close(); | 172 | f.close(); |
165 | QFile::remove( strNewFile ); | 173 | QFile::remove( strNewFile ); |
166 | return false; | 174 | return false; |
167 | } | 175 | } |
@@ -294,101 +302,96 @@ void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, | |||
294 | ev.setDescription( val ); | 302 | ev.setDescription( val ); |
295 | break; | 303 | break; |
296 | case OTodo::Summary: | 304 | case OTodo::Summary: |
297 | ev.setSummary( val ); | 305 | ev.setSummary( val ); |
298 | break; | 306 | break; |
299 | case OTodo::Priority: | 307 | case OTodo::Priority: |
300 | ev.setPriority( val.toInt() ); | 308 | ev.setPriority( val.toInt() ); |
301 | break; | 309 | break; |
302 | case OTodo::DateDay: | 310 | case OTodo::DateDay: |
303 | m_day = val.toInt(); | 311 | m_day = val.toInt(); |
304 | break; | 312 | break; |
305 | case OTodo::DateMonth: | 313 | case OTodo::DateMonth: |
306 | m_month = val.toInt(); | 314 | m_month = val.toInt(); |
307 | break; | 315 | break; |
308 | case OTodo::DateYear: | 316 | case OTodo::DateYear: |
309 | m_year = val.toInt(); | 317 | m_year = val.toInt(); |
310 | break; | 318 | break; |
311 | case OTodo::Progress: | 319 | case OTodo::Progress: |
312 | ev.setProgress( val.toInt() ); | 320 | ev.setProgress( val.toInt() ); |
313 | break; | 321 | break; |
314 | case OTodo::CrossReference: | 322 | case OTodo::CrossReference: |
315 | { | 323 | { |
316 | /* | 324 | /* |
317 | * A cross refernce looks like | 325 | * A cross refernce looks like |
318 | * appname,id;appname,id | 326 | * appname,id;appname,id |
319 | * we need to split it up | 327 | * we need to split it up |
320 | */ | 328 | */ |
321 | QStringList refs = QStringList::split(';', val ); | 329 | QStringList refs = QStringList::split(';', val ); |
322 | QStringList::Iterator strIt; | 330 | QStringList::Iterator strIt; |
323 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { | 331 | for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { |
324 | int pos = (*strIt).find(','); | 332 | int pos = (*strIt).find(','); |
325 | if ( pos > -1 ) | 333 | if ( pos > -1 ) |
326 | ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); | 334 | ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); |
327 | 335 | ||
328 | } | 336 | } |
329 | break; | 337 | break; |
330 | } | 338 | } |
331 | case OTodo::HasAlarmDateTime: | 339 | case OTodo::HasAlarmDateTime: |
332 | ev.setHasAlarmDateTime( val.toInt() ); | 340 | ev.setHasAlarmDateTime( val.toInt() ); |
333 | break; | 341 | break; |
334 | case OTodo::AlarmDateTime: { | 342 | case OTodo::AlarmDateTime: { |
335 | /* this sounds better ;) zecke */ | 343 | /* this sounds better ;) zecke */ |
336 | ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) ); | 344 | ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) ); |
337 | break; | 345 | break; |
338 | } | 346 | } |
339 | default: | 347 | default: |
340 | break; | 348 | break; |
341 | } | 349 | } |
342 | |||
343 | if ( ev.hasDueDate() ) { | ||
344 | QDate date( m_year, m_month, m_day ); | ||
345 | ev.setDueDate( date ); | ||
346 | } | ||
347 | } | 350 | } |
348 | QString OTodoAccessXML::toString( const OTodo& ev )const { | 351 | QString OTodoAccessXML::toString( const OTodo& ev )const { |
349 | QString str; | 352 | QString str; |
350 | 353 | ||
351 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; | 354 | str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; |
352 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; | 355 | str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; |
353 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; | 356 | str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; |
354 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; | 357 | str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; |
355 | 358 | ||
356 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; | 359 | str += "Categories=\"" + toString( ev.categories() ) + "\" "; |
357 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; | 360 | str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; |
358 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; | 361 | str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; |
359 | 362 | ||
360 | if ( ev.hasDueDate() ) { | 363 | if ( ev.hasDueDate() ) { |
361 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; | 364 | str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; |
362 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; | 365 | str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; |
363 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; | 366 | str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; |
364 | } | 367 | } |
365 | // qWarning( "Uid %d", ev.uid() ); | 368 | // qWarning( "Uid %d", ev.uid() ); |
366 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; | 369 | str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; |
367 | 370 | ||
368 | // append the extra options | 371 | // append the extra options |
369 | /* FIXME Qtopia::Record this is currently not | 372 | /* FIXME Qtopia::Record this is currently not |
370 | * possible you can set custom fields | 373 | * possible you can set custom fields |
371 | * but don' iterate over the list | 374 | * but don' iterate over the list |
372 | * I may do #define private protected | 375 | * I may do #define private protected |
373 | * for this case - cough --zecke | 376 | * for this case - cough --zecke |
374 | */ | 377 | */ |
375 | /* | 378 | /* |
376 | QMap<QString, QString> extras = ev.extras(); | 379 | QMap<QString, QString> extras = ev.extras(); |
377 | QMap<QString, QString>::Iterator extIt; | 380 | QMap<QString, QString>::Iterator extIt; |
378 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) | 381 | for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) |
379 | str += extIt.key() + "=\"" + extIt.data() + "\" "; | 382 | str += extIt.key() + "=\"" + extIt.data() + "\" "; |
380 | */ | 383 | */ |
381 | // cross refernce | 384 | // cross refernce |
382 | QStringList list = ev.relatedApps(); | 385 | QStringList list = ev.relatedApps(); |
383 | QStringList::Iterator listIt; | 386 | QStringList::Iterator listIt; |
384 | QString refs; | 387 | QString refs; |
385 | str += "CrossReference=\""; | 388 | str += "CrossReference=\""; |
386 | bool added = false; | 389 | bool added = false; |
387 | for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { | 390 | for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { |
388 | added = true; | 391 | added = true; |
389 | QArray<int> ints = ev.relations( (*listIt) ); | 392 | QArray<int> ints = ev.relations( (*listIt) ); |
390 | for ( uint i = 0; i< ints.count(); i++ ) { | 393 | for ( uint i = 0; i< ints.count(); i++ ) { |
391 | str += (*listIt) + "," + QString::number( i ) + ";"; | 394 | str += (*listIt) + "," + QString::number( i ) + ";"; |
392 | } | 395 | } |
393 | } | 396 | } |
394 | if ( added ) | 397 | if ( added ) |