Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 173 |
1 files changed, 142 insertions, 31 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index d218090..b4170fc 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -1,9 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | 3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) |
4 | Copyright (C) Holger Freyther (zecke@handhelds.org) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 5 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 6 | .=l. |
6 | .>+-= | 7 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
@@ -25,12 +26,14 @@ | |||
25 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
28 | */ | 29 | */ |
29 | 30 | ||
30 | #include <qdatetime.h> | 31 | #include <qdatetime.h> |
32 | #include <qmap.h> | ||
33 | #include <qstring.h> | ||
31 | 34 | ||
32 | #include <qpe/global.h> | 35 | #include <qpe/global.h> |
33 | 36 | ||
34 | #include <opie2/osqldriver.h> | 37 | #include <opie2/osqldriver.h> |
35 | #include <opie2/osqlresult.h> | 38 | #include <opie2/osqlresult.h> |
36 | #include <opie2/osqlmanager.h> | 39 | #include <opie2/osqlmanager.h> |
@@ -145,22 +148,40 @@ namespace { | |||
145 | QDate m_start; | 148 | QDate m_start; |
146 | QDate m_end; | 149 | QDate m_end; |
147 | bool m_inc :1; | 150 | bool m_inc :1; |
148 | }; | 151 | }; |
149 | 152 | ||
150 | 153 | ||
154 | /** | ||
155 | * a find query for custom elements | ||
156 | */ | ||
157 | class FindCustomQuery : public OSQLQuery { | ||
158 | public: | ||
159 | FindCustomQuery(int uid); | ||
160 | FindCustomQuery(const QArray<int>& ); | ||
161 | ~FindCustomQuery(); | ||
162 | QString query()const; | ||
163 | private: | ||
164 | QString single()const; | ||
165 | QString multi()const; | ||
166 | QArray<int> m_uids; | ||
167 | int m_uid; | ||
168 | }; | ||
169 | |||
170 | |||
171 | |||
151 | CreateQuery::CreateQuery() : OSQLQuery() {} | 172 | CreateQuery::CreateQuery() : OSQLQuery() {} |
152 | CreateQuery::~CreateQuery() {} | 173 | CreateQuery::~CreateQuery() {} |
153 | QString CreateQuery::query()const { | 174 | QString CreateQuery::query()const { |
154 | QString qu; | 175 | QString qu; |
155 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; | 176 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
156 | qu += "description, summary, priority, DueDate, progress , state, "; | 177 | qu += "description, summary, priority, DueDate, progress , state, "; |
157 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) | 178 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) |
158 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; | 179 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; |
159 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; | 180 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; |
160 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 181 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
161 | return qu; | 182 | return qu; |
162 | } | 183 | } |
163 | 184 | ||
164 | LoadQuery::LoadQuery() : OSQLQuery() {} | 185 | LoadQuery::LoadQuery() : OSQLQuery() {} |
165 | LoadQuery::~LoadQuery() {} | 186 | LoadQuery::~LoadQuery() {} |
166 | QString LoadQuery::query()const { | 187 | QString LoadQuery::query()const { |
@@ -176,13 +197,15 @@ namespace { | |||
176 | : OSQLQuery(), m_todo( todo ) { | 197 | : OSQLQuery(), m_todo( todo ) { |
177 | } | 198 | } |
178 | InsertQuery::~InsertQuery() { | 199 | InsertQuery::~InsertQuery() { |
179 | } | 200 | } |
180 | /* | 201 | /* |
181 | * converts from a OPimTodo to a query | 202 | * converts from a OPimTodo to a query |
182 | * we leave out X-Ref + Alarms | 203 | * we leave out X-Ref + Maintainer |
204 | * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding | ||
205 | * decoding stuff there.. (eilers) | ||
183 | */ | 206 | */ |
184 | QString InsertQuery::query()const{ | 207 | QString InsertQuery::query()const{ |
185 | 208 | ||
186 | int year, month, day; | 209 | int year, month, day; |
187 | year = month = day = 0; | 210 | year = month = day = 0; |
188 | if (m_todo.hasDueDate() ) { | 211 | if (m_todo.hasDueDate() ) { |
@@ -212,15 +235,15 @@ namespace { | |||
212 | + QString::number( m_todo.uid() ) + "," | 235 | + QString::number( m_todo.uid() ) + "," |
213 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," | 236 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
214 | + QString::number( m_todo.isCompleted() ) + "," | 237 | + QString::number( m_todo.isCompleted() ) + "," |
215 | + "'" + m_todo.description() + "'" + "," | 238 | + "'" + m_todo.description() + "'" + "," |
216 | + "'" + m_todo.summary() + "'" + "," | 239 | + "'" + m_todo.summary() + "'" + "," |
217 | + QString::number(m_todo.priority() ) + "," | 240 | + QString::number(m_todo.priority() ) + "," |
218 | + "'" + QString::number(year) + "-" | 241 | + "'" + QString::number(year).rightJustify( 4, '0' ) + "-" |
219 | + QString::number(month) | 242 | + QString::number(month).rightJustify( 2, '0' ) |
220 | + "-" + QString::number( day ) + "'" + "," | 243 | + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + "," |
221 | + QString::number( m_todo.progress() ) + "," | 244 | + QString::number( m_todo.progress() ) + "," |
222 | + QString::number( m_todo.state().state() ) + "," | 245 | + QString::number( m_todo.state().state() ) + "," |
223 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," | 246 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," |
224 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," | 247 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," |
225 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," | 248 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," |
226 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," | 249 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," |
@@ -237,21 +260,41 @@ namespace { | |||
237 | else{ | 260 | else{ |
238 | qu += QString( "''" ) + "," | 261 | qu += QString( "''" ) + "," |
239 | + "''" + ","; | 262 | + "''" + ","; |
240 | } | 263 | } |
241 | 264 | ||
242 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) | 265 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) |
243 | + "'" + QString::number(sYear) + "-" | 266 | + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-" |
244 | + QString::number(sMonth) | 267 | + QString::number(sMonth).rightJustify( 2, '0' ) |
245 | + "-" + QString::number(sDay) + "'" + "," | 268 | + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + "," |
246 | + "'" + QString::number(eYear) + "-" | 269 | + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-" |
247 | + QString::number(eMonth) | 270 | + QString::number(eMonth).rightJustify( 2, '0' ) |
248 | + "-"+QString::number(eDay) + "'" | 271 | + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'" |
249 | + ")"; | 272 | + ")"; |
250 | 273 | ||
251 | qWarning("add %s", qu.latin1() ); | 274 | // Save custom Entries: |
275 | int id = 0; | ||
276 | id = 0; | ||
277 | QMap<QString, QString> customMap = m_todo.toExtraMap(); | ||
278 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | ||
279 | it != customMap.end(); ++it ){ | ||
280 | qu += "insert into custom_data VALUES(" | ||
281 | + QString::number( m_todo.uid() ) | ||
282 | + "," | ||
283 | + QString::number( id++ ) | ||
284 | + ",'" | ||
285 | + it.key() | ||
286 | + "'," | ||
287 | + "0" // Priority for future enhancements | ||
288 | + ",'" | ||
289 | + it.data() | ||
290 | + "');"; | ||
291 | } | ||
292 | |||
293 | |||
294 | qDebug("add %s", qu.latin1() ); | ||
252 | return qu; | 295 | return qu; |
253 | } | 296 | } |
254 | 297 | ||
255 | RemoveQuery::RemoveQuery(int uid ) | 298 | RemoveQuery::RemoveQuery(int uid ) |
256 | : OSQLQuery(), m_uid( uid ) {} | 299 | : OSQLQuery(), m_uid( uid ) {} |
257 | RemoveQuery::~RemoveQuery() {} | 300 | RemoveQuery::~RemoveQuery() {} |
@@ -297,13 +340,16 @@ namespace { | |||
297 | 340 | ||
298 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 341 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
299 | OverDueQuery::~OverDueQuery() {} | 342 | OverDueQuery::~OverDueQuery() {} |
300 | QString OverDueQuery::query()const { | 343 | QString OverDueQuery::query()const { |
301 | QDate date = QDate::currentDate(); | 344 | QDate date = QDate::currentDate(); |
302 | QString str; | 345 | QString str; |
303 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); | 346 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'") |
347 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | ||
348 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | ||
349 | .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) ); | ||
304 | 350 | ||
305 | return str; | 351 | return str; |
306 | } | 352 | } |
307 | 353 | ||
308 | 354 | ||
309 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 355 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
@@ -312,30 +358,56 @@ namespace { | |||
312 | QString EffQuery::query()const { | 358 | QString EffQuery::query()const { |
313 | return m_inc ? with() : out(); | 359 | return m_inc ? with() : out(); |
314 | } | 360 | } |
315 | QString EffQuery::with()const { | 361 | QString EffQuery::with()const { |
316 | QString str; | 362 | QString str; |
317 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 363 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
318 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) | 364 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
319 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); | 365 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
366 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | ||
367 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | ||
368 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | ||
369 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | ||
320 | return str; | 370 | return str; |
321 | } | 371 | } |
322 | QString EffQuery::out()const { | 372 | QString EffQuery::out()const { |
323 | QString str; | 373 | QString str; |
324 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 374 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
325 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 375 | .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) ) |
326 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 376 | .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) ) |
377 | .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) ) | ||
378 | .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) ) | ||
379 | .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) ) | ||
380 | .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) ); | ||
327 | 381 | ||
328 | return str; | 382 | return str; |
329 | } | 383 | } |
384 | |||
385 | FindCustomQuery::FindCustomQuery(int uid) | ||
386 | : OSQLQuery(), m_uid( uid ) { | ||
387 | } | ||
388 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) | ||
389 | : OSQLQuery(), m_uids( ints ){ | ||
390 | } | ||
391 | FindCustomQuery::~FindCustomQuery() { | ||
392 | } | ||
393 | QString FindCustomQuery::query()const{ | ||
394 | return single(); // Multiple requests not supported ! | ||
395 | } | ||
396 | QString FindCustomQuery::single()const{ | ||
397 | QString qu = "select uid, type, value from custom_data where uid = "; | ||
398 | qu += QString::number(m_uid); | ||
399 | return qu; | ||
400 | } | ||
401 | |||
330 | }; | 402 | }; |
331 | 403 | ||
332 | 404 | ||
333 | namespace Opie { | 405 | namespace Opie { |
334 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) | 406 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) |
335 | : OPimTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) | 407 | : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true) |
336 | { | 408 | { |
337 | QString fi = file; | 409 | QString fi = file; |
338 | if ( fi.isEmpty() ) | 410 | if ( fi.isEmpty() ) |
339 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 411 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
340 | OSQLManager man; | 412 | OSQLManager man; |
341 | m_driver = man.standard(); | 413 | m_driver = man.standard(); |
@@ -380,23 +452,23 @@ OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ | |||
380 | return todo( m_driver->query(&query) ); | 452 | return todo( m_driver->query(&query) ); |
381 | 453 | ||
382 | } | 454 | } |
383 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 455 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
384 | uint cur, Frontend::CacheDirection dir ) const{ | 456 | uint cur, Frontend::CacheDirection dir ) const{ |
385 | uint CACHE = readAhead(); | 457 | uint CACHE = readAhead(); |
386 | qWarning("searching for %d", uid ); | 458 | qDebug("searching for %d", uid ); |
387 | QArray<int> search( CACHE ); | 459 | QArray<int> search( CACHE ); |
388 | uint size =0; | 460 | uint size =0; |
389 | OPimTodo to; | 461 | OPimTodo to; |
390 | 462 | ||
391 | // we try to cache CACHE items | 463 | // we try to cache CACHE items |
392 | switch( dir ) { | 464 | switch( dir ) { |
393 | /* forward */ | 465 | /* forward */ |
394 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) | 466 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) |
395 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 467 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
396 | qWarning("size %d %d", size, ints[i] ); | 468 | qDebug("size %d %d", size, ints[i] ); |
397 | search[size] = ints[i]; | 469 | search[size] = ints[i]; |
398 | size++; | 470 | size++; |
399 | } | 471 | } |
400 | break; | 472 | break; |
401 | /* reverse */ | 473 | /* reverse */ |
402 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) | 474 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) |
@@ -465,13 +537,13 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, | |||
465 | } | 537 | } |
466 | /* | 538 | /* |
467 | * | 539 | * |
468 | */ | 540 | */ |
469 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 541 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
470 | int sortFilter, int cat ) { | 542 | int sortFilter, int cat ) { |
471 | qWarning("sorted %d, %d", asc, sortOrder ); | 543 | qDebug("sorted %d, %d", asc, sortOrder ); |
472 | QString query; | 544 | QString query; |
473 | query = "select uid from todolist WHERE "; | 545 | query = "select uid from todolist WHERE "; |
474 | 546 | ||
475 | /* | 547 | /* |
476 | * Sort Filter stuff | 548 | * Sort Filter stuff |
477 | * not that straight forward | 549 | * not that straight forward |
@@ -486,22 +558,25 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
486 | } | 558 | } |
487 | /* Show only overdue */ | 559 | /* Show only overdue */ |
488 | if ( sortFilter & 2 ) { | 560 | if ( sortFilter & 2 ) { |
489 | QDate date = QDate::currentDate(); | 561 | QDate date = QDate::currentDate(); |
490 | QString due; | 562 | QString due; |
491 | QString base; | 563 | QString base; |
492 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | 564 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0") |
565 | .arg( QString::number( date.year() ).rightJustify( 4, '0' ) ) | ||
566 | .arg( QString::number( date.month() ).rightJustify( 2, '0' ) ) | ||
567 | .arg( QString::number( date.day() ).rightJustify( 2, '0' ) ); | ||
493 | query += " " + base + " AND"; | 568 | query += " " + base + " AND"; |
494 | } | 569 | } |
495 | /* not show completed */ | 570 | /* not show completed */ |
496 | if ( sortFilter & 4 ) { | 571 | if ( sortFilter & 4 ) { |
497 | query += " completed = 0 AND"; | 572 | query += " completed = 0 AND"; |
498 | }else{ | 573 | }else{ |
499 | query += " ( completed = 1 OR completed = 0) AND"; | 574 | query += " ( completed = 1 OR completed = 0) AND"; |
500 | } | 575 | } |
501 | /* srtip the end */ | 576 | /* strip the end */ |
502 | query = query.remove( query.length()-3, 3 ); | 577 | query = query.remove( query.length()-3, 3 ); |
503 | 578 | ||
504 | 579 | ||
505 | /* | 580 | /* |
506 | * sort order stuff | 581 | * sort order stuff |
507 | * quite straight forward | 582 | * quite straight forward |
@@ -521,17 +596,17 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
521 | case 3: | 596 | case 3: |
522 | query += "DueDate"; | 597 | query += "DueDate"; |
523 | break; | 598 | break; |
524 | } | 599 | } |
525 | 600 | ||
526 | if ( !asc ) { | 601 | if ( !asc ) { |
527 | qWarning("not ascending!"); | 602 | qDebug("not ascending!"); |
528 | query += " DESC"; | 603 | query += " DESC"; |
529 | } | 604 | } |
530 | 605 | ||
531 | qWarning( query ); | 606 | qDebug( query ); |
532 | OSQLRawQuery raw(query ); | 607 | OSQLRawQuery raw(query ); |
533 | return uids( m_driver->query(&raw) ); | 608 | return uids( m_driver->query(&raw) ); |
534 | } | 609 | } |
535 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 610 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
536 | if ( str == "0-0-0" ) | 611 | if ( str == "0-0-0" ) |
537 | return false; | 612 | return false; |
@@ -542,38 +617,41 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | |||
542 | month = list[1].toInt(); | 617 | month = list[1].toInt(); |
543 | day = list[2].toInt(); | 618 | day = list[2].toInt(); |
544 | da.setYMD( year, month, day ); | 619 | da.setYMD( year, month, day ); |
545 | return true; | 620 | return true; |
546 | } | 621 | } |
547 | } | 622 | } |
548 | OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 623 | OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ |
549 | if ( res.state() == OSQLResult::Failure ) { | 624 | if ( res.state() == OSQLResult::Failure ) { |
550 | OPimTodo to; | 625 | OPimTodo to; |
551 | return to; | 626 | return to; |
552 | } | 627 | } |
553 | 628 | ||
554 | OSQLResultItem::ValueList list = res.results(); | 629 | OSQLResultItem::ValueList list = res.results(); |
555 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 630 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
556 | qWarning("todo1"); | 631 | qDebug("todo1"); |
557 | OPimTodo to = todo( (*it) ); | 632 | OPimTodo to = todo( (*it) ); |
558 | cache( to ); | 633 | cache( to ); |
559 | ++it; | 634 | ++it; |
560 | 635 | ||
561 | for ( ; it != list.end(); ++it ) { | 636 | for ( ; it != list.end(); ++it ) { |
562 | qWarning("caching"); | 637 | qDebug("caching"); |
563 | cache( todo( (*it) ) ); | 638 | cache( todo( (*it) ) ); |
564 | } | 639 | } |
565 | return to; | 640 | return to; |
566 | } | 641 | } |
567 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 642 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
568 | qWarning("todo"); | 643 | qDebug("todo(ResultItem)"); |
644 | |||
645 | // Request information from addressbook table and create the OPimTodo-object. | ||
646 | |||
569 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 647 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
570 | hasDueDate = date( dueDate, item.data("DueDate") ); | 648 | hasDueDate = date( dueDate, item.data("DueDate") ); |
571 | QStringList cats = QStringList::split(";", item.data("categories") ); | 649 | QStringList cats = QStringList::split(";", item.data("categories") ); |
572 | 650 | ||
573 | qWarning("Item is completed: %d", item.data("completed").toInt() ); | 651 | qDebug("Item is completed: %d", item.data("completed").toInt() ); |
574 | 652 | ||
575 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 653 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
576 | cats, item.data("summary"), item.data("description"), | 654 | cats, item.data("summary"), item.data("description"), |
577 | item.data("progress").toUShort(), hasDueDate, dueDate, | 655 | item.data("progress").toUShort(), hasDueDate, dueDate, |
578 | item.data("uid").toInt() ); | 656 | item.data("uid").toInt() ); |
579 | 657 | ||
@@ -611,22 +689,27 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
611 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); | 689 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); |
612 | 690 | ||
613 | OPimRecurrence recur; | 691 | OPimRecurrence recur; |
614 | recur.fromMap( recMap ); | 692 | recur.fromMap( recMap ); |
615 | to.setRecurrence( recur ); | 693 | to.setRecurrence( recur ); |
616 | 694 | ||
695 | // Finally load the custom-entries for this UID and put it into the created object | ||
696 | to.setExtraMap( requestCustom( to.uid() ) ); | ||
697 | |||
617 | return to; | 698 | return to; |
618 | } | 699 | } |
619 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { | 700 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { |
620 | FindQuery find( uid ); | 701 | FindQuery find( uid ); |
621 | return todo( m_driver->query(&find) ); | 702 | return todo( m_driver->query(&find) ); |
622 | } | 703 | } |
623 | /* | 704 | /* |
624 | * update the dict | 705 | * update the dict |
625 | */ | 706 | */ |
626 | void OPimTodoAccessBackendSQL::fillDict() { | 707 | void OPimTodoAccessBackendSQL::fillDict() { |
708 | |||
709 | #if 0 | ||
627 | /* initialize dict */ | 710 | /* initialize dict */ |
628 | /* | 711 | /* |
629 | * UPDATE dict if you change anything!!! | 712 | * UPDATE dict if you change anything!!! |
630 | * FIXME: Isn't this dict obsolete ? (eilers) | 713 | * FIXME: Isn't this dict obsolete ? (eilers) |
631 | */ | 714 | */ |
632 | m_dict.setAutoDelete( TRUE ); | 715 | m_dict.setAutoDelete( TRUE ); |
@@ -642,12 +725,14 @@ void OPimTodoAccessBackendSQL::fillDict() { | |||
642 | m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); | 725 | m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); |
643 | m_dict.insert("Progress" , new int(OPimTodo::Progress) ); | 726 | m_dict.insert("Progress" , new int(OPimTodo::Progress) ); |
644 | m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) | 727 | m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) |
645 | m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); | 728 | m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); |
646 | // m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) | 729 | // m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) |
647 | // m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) | 730 | // m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) |
731 | |||
732 | #endif | ||
648 | } | 733 | } |
649 | /* | 734 | /* |
650 | * need to be const so let's fool the | 735 | * need to be const so let's fool the |
651 | * compiler :( | 736 | * compiler :( |
652 | */ | 737 | */ |
653 | void OPimTodoAccessBackendSQL::update()const { | 738 | void OPimTodoAccessBackendSQL::update()const { |
@@ -661,13 +746,13 @@ void OPimTodoAccessBackendSQL::update()const { | |||
661 | } | 746 | } |
662 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 747 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
663 | 748 | ||
664 | OSQLResultItem::ValueList list = res.results(); | 749 | OSQLResultItem::ValueList list = res.results(); |
665 | OSQLResultItem::ValueList::Iterator it; | 750 | OSQLResultItem::ValueList::Iterator it; |
666 | QArray<int> ints(list.count() ); | 751 | QArray<int> ints(list.count() ); |
667 | qWarning(" count = %d", list.count() ); | 752 | qDebug(" count = %d", list.count() ); |
668 | 753 | ||
669 | int i = 0; | 754 | int i = 0; |
670 | for (it = list.begin(); it != list.end(); ++it ) { | 755 | for (it = list.begin(); it != list.end(); ++it ) { |
671 | ints[i] = (*it).data("uid").toInt(); | 756 | ints[i] = (*it).data("uid").toInt(); |
672 | i++; | 757 | i++; |
673 | } | 758 | } |
@@ -722,7 +807,33 @@ QBitArray OPimTodoAccessBackendSQL::sup() const{ | |||
722 | 807 | ||
723 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ | 808 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
724 | #warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !! | 809 | #warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !! |
725 | 810 | ||
726 | } | 811 | } |
727 | 812 | ||
813 | |||
814 | QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const | ||
815 | { | ||
816 | QMap<QString, QString> customMap; | ||
817 | |||
818 | FindCustomQuery query( uid ); | ||
819 | OSQLResult res_custom = m_driver->query( &query ); | ||
820 | |||
821 | if ( res_custom.state() == OSQLResult::Failure ) { | ||
822 | qWarning("OSQLResult::Failure in find query !!"); | ||
823 | QMap<QString, QString> empty; | ||
824 | return empty; | ||
825 | } | ||
826 | |||
827 | OSQLResultItem::ValueList list = res_custom.results(); | ||
828 | OSQLResultItem::ValueList::Iterator it = list.begin(); | ||
829 | for ( ; it != list.end(); ++it ) { | ||
830 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | ||
831 | } | ||
832 | |||
833 | return customMap; | ||
834 | } | ||
835 | |||
836 | |||
837 | |||
838 | |||
728 | } | 839 | } |