summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend
authorzecke <zecke>2002-09-28 13:30:31 (UTC)
committer zecke <zecke>2002-09-28 13:30:31 (UTC)
commit93f90487bf9d2b8937a4933aef2ee472b5cdc89c (patch) (unidiff)
treee9bf4c608df27ab241c4ad293111cd291bd485b8 /libopie2/opiepim/backend
parent8a95ca149ff5eedc9215bb012c8d7d09cdcaf96c (diff)
downloadopie-93f90487bf9d2b8937a4933aef2ee472b5cdc89c.zip
opie-93f90487bf9d2b8937a4933aef2ee472b5cdc89c.tar.gz
opie-93f90487bf9d2b8937a4933aef2ee472b5cdc89c.tar.bz2
remove debug output
move from Opie::XMLElement to custom parser this cuts down loading 10.000 items from 22 seconds to 4 seconds
Diffstat (limited to 'libopie2/opiepim/backend') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp138
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.h3
2 files changed, 89 insertions, 52 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 692483e..31822d4 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -48,32 +48,75 @@ bool OTodoAccessXML::load() {
48 48
49 Opie::XMLElement *root = Opie::XMLElement::load( m_file ); 49 // here the custom XML parser from TT it's GPL
50 int day, year, month; 50 // but we want to push that to TT.....
51 day = year = month = -1; 51 QFile f(m_file );
52 52 if (!f.open(IO_ReadOnly) )
53 /* if opened */
54 if ( root != 0l ) {
55 Opie::XMLElement *element = root->firstChild();
56 if ( element == 0l )
57 return false; 53 return false;
58 54
59 element = element->firstChild(); 55 QByteArray ba = f.readAll();
56 f.close();
57 char* dt = ba.data();
58 int len = ba.size();
59 int i = 0;
60 char *point;
61 const char* collectionString = "<Task ";
62 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
63 i = point -dt;
64 i+= strlen(collectionString);
65 OTodo ev;
66 m_year = m_month = m_day = 0;
67
68 while ( TRUE ) {
69 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
70 ++i;
71 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
72 break;
60 73
61 while ( element ) { 74 // we have another attribute, read it.
62 if ( element->tagName() != QString::fromLatin1("Task") ) { 75 int j = i;
63 element = element->nextChild(); 76 while ( j < len && dt[j] != '=' )
77 ++j;
78 QCString attr( dt+i, j-i+1);
79
80 i = ++j; // skip =
81
82 // find the start of quotes
83 while ( i < len && dt[i] != '"' )
84 ++i;
85 j = ++i;
86
87 bool haveUtf = FALSE;
88 bool haveEnt = FALSE;
89 while ( j < len && dt[j] != '"' ) {
90 if ( ((unsigned char)dt[j]) > 0x7f )
91 haveUtf = TRUE;
92 if ( dt[j] == '&' )
93 haveEnt = TRUE;
94 ++j;
95 }
96 if ( i == j ) {
97 // empty value
98 i = j + 1;
64 continue; 99 continue;
65 } 100 }
66 /* here is the right element for a task */
67 OTodo ev = todo( &dict, element );
68 m_events.insert( ev.uid(), ev );
69 101
70 element = element->nextChild(); 102 QCString value( dt+i, j-i+1 );
103 i = j + 1;
104
105 QString str = (haveUtf ? QString::fromUtf8( value )
106 : QString::fromLatin1( value ) );
107 if ( haveEnt )
108 str = Qtopia::plainString( str );
109
110 /*
111 * add key + value
112 */
113 todo( &dict, ev, attr, str );
114
71 } 115 }
72 }else { 116 /*
73// qWarning("could not parse"); 117 * now add it
74 return false;; 118 */
119 m_events.insert(ev.uid(), ev );
75 } 120 }
76 delete root;
77 121
78// qWarning("Access %d" + m_events.count() );
79 return true; 122 return true;
@@ -222,17 +265,13 @@ QArray<int> OTodoAccessXML::overDue() {
222/* private */ 265/* private */
223OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)const { 266void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
267 const QCString& attr, const QString& val) {
224// qWarning("parse to do from XMLElement" ); 268// qWarning("parse to do from XMLElement" );
225 OTodo ev;
226 QMap<QString, QString> attributes = element->attributes();
227 QMap<QString, QString>::Iterator it;
228 269
229 int *find=0; 270 int *find=0;
230 int day, month, year; 271
231 day = month = year = -1; 272 find = (*dict)[ attr.data() ];
232 for ( it = attributes.begin(); it != attributes.end(); ++it ) {
233 find = (*dict)[ it.key() ];
234 if (!find ) { 273 if (!find ) {
235// qWarning("Unknown option" + it.key() ); 274// qWarning("Unknown option" + it.key() );
236 ev.setCustomField( it.key(), it.data() ); 275 ev.setCustomField( attr, val );
237 continue; 276 return;
238 } 277 }
@@ -241,34 +280,33 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con
241 case OTodo::Uid: 280 case OTodo::Uid:
242 ev.setUid( it.data().toInt() ); 281 ev.setUid( val.toInt() );
243 break; 282 break;
244 case OTodo::Category: 283 case OTodo::Category:
245 ev.setCategories( ev.idsFromString( it.data() ) ); 284 ev.setCategories( ev.idsFromString( val ) );
246 break; 285 break;
247 case OTodo::HasDate: 286 case OTodo::HasDate:
248 ev.setHasDueDate( it.data().toInt() ); 287 ev.setHasDueDate( val.toInt() );
249 break; 288 break;
250 case OTodo::Completed: 289 case OTodo::Completed:
251 ev.setCompleted( it.data().toInt() ); 290 ev.setCompleted( val.toInt() );
252 break; 291 break;
253 case OTodo::Description: 292 case OTodo::Description:
254 ev.setDescription( it.data() ); 293 ev.setDescription( val );
255 break; 294 break;
256 case OTodo::Summary: 295 case OTodo::Summary:
257 ev.setSummary( it.data() ); 296 ev.setSummary( val );
258 break; 297 break;
259 case OTodo::Priority: 298 case OTodo::Priority:
260 qWarning("ParsePriority " + it.data() ); 299 ev.setPriority( val.toInt() );
261 ev.setPriority( it.data().toInt() );
262 break; 300 break;
263 case OTodo::DateDay: 301 case OTodo::DateDay:
264 day = it.data().toInt(); 302 m_day = val.toInt();
265 break; 303 break;
266 case OTodo::DateMonth: 304 case OTodo::DateMonth:
267 month = it.data().toInt(); 305 m_month = val.toInt();
268 break; 306 break;
269 case OTodo::DateYear: 307 case OTodo::DateYear:
270 year = it.data().toInt(); 308 m_year = val.toInt();
271 break; 309 break;
272 case OTodo::Progress: 310 case OTodo::Progress:
273 ev.setProgress( it.data().toInt() ); 311 ev.setProgress( val.toInt() );
274 break; 312 break;
@@ -281,3 +319,3 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con
281 */ 319 */
282 QStringList refs = QStringList::split(';', it.data() ); 320 QStringList refs = QStringList::split(';', val );
283 QStringList::Iterator strIt; 321 QStringList::Iterator strIt;
@@ -292,3 +330,3 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con
292 case OTodo::HasAlarmDateTime: 330 case OTodo::HasAlarmDateTime:
293 ev.setHasAlarmDateTime( it.data().toInt() ); 331 ev.setHasAlarmDateTime( val.toInt() );
294 break; 332 break;
@@ -296,3 +334,3 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con
296 /* this sounds better ;) zecke */ 334 /* this sounds better ;) zecke */
297 ev.setAlarmDateTime( TimeConversion::fromISO8601( it.data().local8Bit() ) ); 335 ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) );
298 break; 336 break;
@@ -302,9 +340,7 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con
302 } 340 }
303 } 341
304 if ( ev.hasDueDate() ) { 342 if ( ev.hasDueDate() ) {
305 QDate date( year, month, day ); 343 QDate date( m_year, m_month, m_day );
306 ev.setDueDate( date ); 344 ev.setDueDate( date );
307 } 345 }
308
309 return ev;
310} 346}
@@ -482,3 +518,3 @@ QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
482 bool bOver = sortFilter & 0 ? true : false; 518 bool bOver = sortFilter & 0 ? true : false;
483 bool bOnly = split & 2 ? true : false; 519 bool bOnly = sortFilter & 2 ? true : false;
484 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 520 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
diff --git a/libopie2/opiepim/backend/otodoaccessxml.h b/libopie2/opiepim/backend/otodoaccessxml.h
index 6886bab..1e7e371 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.h
+++ b/libopie2/opiepim/backend/otodoaccessxml.h
@@ -41,3 +41,3 @@ public:
41private: 41private:
42 OTodo todo( QAsciiDict<int>*, Opie::XMLElement* )const; 42 void todo( QAsciiDict<int>*, OTodo&,const QCString&,const QString& );
43 QString toString( const OTodo& )const; 43 QString toString( const OTodo& )const;
@@ -51,2 +51,3 @@ private:
51 OTodoAccessXMLPrivate* d; 51 OTodoAccessXMLPrivate* d;
52 int m_year, m_month, m_day;
52 53