summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccesssql.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index ebd03bb..3913661 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -102,49 +102,51 @@ namespace {
102 OverDueQuery(); 102 OverDueQuery();
103 ~OverDueQuery(); 103 ~OverDueQuery();
104 QString query()const; 104 QString query()const;
105 }; 105 };
106 class EffQuery : public OSQLQuery { 106 class EffQuery : public OSQLQuery {
107 public: 107 public:
108 EffQuery( const QDate&, const QDate&, bool inc ); 108 EffQuery( const QDate&, const QDate&, bool inc );
109 ~EffQuery(); 109 ~EffQuery();
110 QString query()const; 110 QString query()const;
111 private: 111 private:
112 QString with()const; 112 QString with()const;
113 QString out()const; 113 QString out()const;
114 QDate m_start; 114 QDate m_start;
115 QDate m_end; 115 QDate m_end;
116 bool m_inc :1; 116 bool m_inc :1;
117 }; 117 };
118 118
119 119
120 CreateQuery::CreateQuery() : OSQLQuery() {} 120 CreateQuery::CreateQuery() : OSQLQuery() {}
121 CreateQuery::~CreateQuery() {} 121 CreateQuery::~CreateQuery() {}
122 QString CreateQuery::query()const { 122 QString CreateQuery::query()const {
123 QString qu; 123 QString qu;
124 qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; 124 qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
125 qu += "description, summary, priority, DueDate, progress , state, "; 125 qu += "description, summary, priority, DueDate, progress , state, ";
126 qu += "Recurrence, reminders, alarms, maintainer, startdate, completeddate);"; 126 // This is the recurrance-stuff .. Exceptions are currently not supported (see ORecur.cpp) ! (eilers)
127 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
128 qu += "reminders, alarms, maintainer, startdate, completeddate);";
127 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 129 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
128 return qu; 130 return qu;
129 } 131 }
130 132
131 LoadQuery::LoadQuery() : OSQLQuery() {} 133 LoadQuery::LoadQuery() : OSQLQuery() {}
132 LoadQuery::~LoadQuery() {} 134 LoadQuery::~LoadQuery() {}
133 QString LoadQuery::query()const { 135 QString LoadQuery::query()const {
134 QString qu; 136 QString qu;
135 // We do not need "distinct" here. The primary key is always unique.. 137 // We do not need "distinct" here. The primary key is always unique..
136 //qu += "select distinct uid from todolist"; 138 //qu += "select distinct uid from todolist";
137 qu += "select uid from todolist"; 139 qu += "select uid from todolist";
138 140
139 return qu; 141 return qu;
140 } 142 }
141 143
142 InsertQuery::InsertQuery( const OTodo& todo ) 144 InsertQuery::InsertQuery( const OTodo& todo )
143 : OSQLQuery(), m_todo( todo ) { 145 : OSQLQuery(), m_todo( todo ) {
144 } 146 }
145 InsertQuery::~InsertQuery() { 147 InsertQuery::~InsertQuery() {
146 } 148 }
147 /* 149 /*
148 * converts from a OTodo to a query 150 * converts from a OTodo to a query
149 * we leave out X-Ref + Alarms 151 * we leave out X-Ref + Alarms
150 */ 152 */
@@ -153,61 +155,69 @@ namespace {
153 int year, month, day; 155 int year, month, day;
154 year = month = day = 0; 156 year = month = day = 0;
155 if (m_todo.hasDueDate() ) { 157 if (m_todo.hasDueDate() ) {
156 QDate date = m_todo.dueDate(); 158 QDate date = m_todo.dueDate();
157 year = date.year(); 159 year = date.year();
158 month = date.month(); 160 month = date.month();
159 day = date.day(); 161 day = date.day();
160 } 162 }
161 int sYear = 0, sMonth = 0, sDay = 0; 163 int sYear = 0, sMonth = 0, sDay = 0;
162 if( m_todo.hasStartDate() ){ 164 if( m_todo.hasStartDate() ){
163 QDate sDate = m_todo.startDate(); 165 QDate sDate = m_todo.startDate();
164 sYear = sDate.year(); 166 sYear = sDate.year();
165 sMonth= sDate.month(); 167 sMonth= sDate.month();
166 sDay = sDate.day(); 168 sDay = sDate.day();
167 } 169 }
168 170
169 int eYear = 0, eMonth = 0, eDay = 0; 171 int eYear = 0, eMonth = 0, eDay = 0;
170 if( m_todo.hasCompletedDate() ){ 172 if( m_todo.hasCompletedDate() ){
171 QDate eDate = m_todo.completedDate(); 173 QDate eDate = m_todo.completedDate();
172 eYear = eDate.year(); 174 eYear = eDate.year();
173 eMonth= eDate.month(); 175 eMonth= eDate.month();
174 eDay = eDate.day(); 176 eDay = eDate.day();
175 } 177 }
176 QString qu; 178 QString qu;
179 QMap<int, QString> recMap = m_todo.recurrence().toMap();
177 qu = "insert into todolist VALUES(" 180 qu = "insert into todolist VALUES("
178 + QString::number( m_todo.uid() ) + "," 181 + QString::number( m_todo.uid() ) + ","
179 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," 182 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
180 + QString::number( m_todo.isCompleted() ) + "," 183 + QString::number( m_todo.isCompleted() ) + ","
181 + "'" + m_todo.description() + "'" + "," 184 + "'" + m_todo.description() + "'" + ","
182 + "'" + m_todo.summary() + "'" + "," 185 + "'" + m_todo.summary() + "'" + ","
183 + QString::number(m_todo.priority() ) + "," 186 + QString::number(m_todo.priority() ) + ","
184 + "'" + QString::number(year) + "-" 187 + "'" + QString::number(year) + "-"
185 + QString::number(month) 188 + QString::number(month)
186 + "-" + QString::number( day ) + "'" + "," 189 + "-" + QString::number( day ) + "'" + ","
187 + QString::number( m_todo.progress() ) + "," 190 + QString::number( m_todo.progress() ) + ","
188 + QString::number( m_todo.state().state() ) + "," 191 + QString::number( m_todo.state().state() ) + ","
189 + "'" + m_todo.recurrence().toString() + "'"+ ","; 192 + "'" + recMap[ ORecur::RType ] + "'" + ","
193 + "'" + recMap[ ORecur::RWeekdays ] + "'" + ","
194 + "'" + recMap[ ORecur::RPosition ] + "'" + ","
195 + "'" + recMap[ ORecur::RFreq ] + "'" + ","
196 + "'" + recMap[ ORecur::RHasEndDate ] + "'" + ","
197 + "'" + recMap[ ORecur::EndDate ] + "'" + ","
198 + "'" + recMap[ ORecur::Created ] + "'" + ","
199 + "'" + recMap[ ORecur::Exceptions ] + "'" + ",";
190 200
191 if ( m_todo.hasNotifiers() ) { 201 if ( m_todo.hasNotifiers() ) {
192 OPimNotifyManager manager = m_todo.notifiers(); 202 OPimNotifyManager manager = m_todo.notifiers();
193 qu += "'" + manager.remindersToString() + "'" + "," 203 qu += "'" + manager.remindersToString() + "'" + ","
194 + "'" + manager.alarmsToString() + "'" + ","; 204 + "'" + manager.alarmsToString() + "'" + ",";
195 } 205 }
196 else{ 206 else{
197 qu += QString( "''" ) + "," 207 qu += QString( "''" ) + ","
198 + "''" + ","; 208 + "''" + ",";
199 } 209 }
200 210
201 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 211 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
202 + "'" + QString::number(sYear) + "-" 212 + "'" + QString::number(sYear) + "-"
203 + QString::number(sMonth) 213 + QString::number(sMonth)
204 + "-" + QString::number(sDay) + "'" + "," 214 + "-" + QString::number(sDay) + "'" + ","
205 + "'" + QString::number(eYear) + "-" 215 + "'" + QString::number(eYear) + "-"
206 + QString::number(eMonth) 216 + QString::number(eMonth)
207 + "-"+QString::number(eDay) + "'" 217 + "-"+QString::number(eDay) + "'"
208 + ")"; 218 + ")";
209 219
210 qWarning("add %s", qu.latin1() ); 220 qWarning("add %s", qu.latin1() );
211 return qu; 221 return qu;
212 } 222 }
213 223
@@ -503,78 +513,91 @@ OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
503 if ( res.state() == OSQLResult::Failure ) { 513 if ( res.state() == OSQLResult::Failure ) {
504 OTodo to; 514 OTodo to;
505 return to; 515 return to;
506 } 516 }
507 517
508 OSQLResultItem::ValueList list = res.results(); 518 OSQLResultItem::ValueList list = res.results();
509 OSQLResultItem::ValueList::Iterator it = list.begin(); 519 OSQLResultItem::ValueList::Iterator it = list.begin();
510 qWarning("todo1"); 520 qWarning("todo1");
511 OTodo to = todo( (*it) ); 521 OTodo to = todo( (*it) );
512 cache( to ); 522 cache( to );
513 ++it; 523 ++it;
514 524
515 for ( ; it != list.end(); ++it ) { 525 for ( ; it != list.end(); ++it ) {
516 qWarning("caching"); 526 qWarning("caching");
517 cache( todo( (*it) ) ); 527 cache( todo( (*it) ) );
518 } 528 }
519 return to; 529 return to;
520} 530}
521OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 531OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
522 qWarning("todo"); 532 qWarning("todo");
523 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 533 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
524 hasDueDate = date( dueDate, item.data("DueDate") ); 534 hasDueDate = date( dueDate, item.data("DueDate") );
525 QStringList cats = QStringList::split(";", item.data("categories") ); 535 QStringList cats = QStringList::split(";", item.data("categories") );
526 536
537 qWarning("Item is completed: %d", item.data("completed").toInt() );
538
527 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 539 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
528 cats, item.data("summary"), item.data("description"), 540 cats, item.data("summary"), item.data("description"),
529 item.data("progress").toUShort(), hasDueDate, dueDate, 541 item.data("progress").toUShort(), hasDueDate, dueDate,
530 item.data("uid").toInt() ); 542 item.data("uid").toInt() );
531 543
532 bool isOk; 544 bool isOk;
533 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 545 int prioInt = QString( item.data("priority") ).toInt( &isOk );
534 if ( isOk ) 546 if ( isOk )
535 to.setPriority( prioInt ); 547 to.setPriority( prioInt );
536 548
537 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 549 bool hasStartDate = false; QDate startDate = QDate::currentDate();
538 hasStartDate = date( startDate, item.data("startdate") ); 550 hasStartDate = date( startDate, item.data("startdate") );
539 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); 551 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
540 hasCompletedDate = date( completedDate, item.data("completeddate") ); 552 hasCompletedDate = date( completedDate, item.data("completeddate") );
541 553
542 if ( hasStartDate ) 554 if ( hasStartDate )
543 to.setStartDate( startDate ); 555 to.setStartDate( startDate );
544 if ( hasCompletedDate ) 556 if ( hasCompletedDate )
545 to.setCompletedDate( completedDate ); 557 to.setCompletedDate( completedDate );
546 558
547 OPimNotifyManager& manager = to.notifiers(); 559 OPimNotifyManager& manager = to.notifiers();
548 manager.alarmsFromString( item.data("alarms") ); 560 manager.alarmsFromString( item.data("alarms") );
549 manager.remindersFromString( item.data("reminders") ); 561 manager.remindersFromString( item.data("reminders") );
550 562
551 OPimState pimState; 563 OPimState pimState;
552 pimState.setState( QString( item.data("state") ).toInt() ); 564 pimState.setState( QString( item.data("state") ).toInt() );
553 to.setState( pimState ); 565 to.setState( pimState );
554 566
555 // Recurrence not supported yet 567 QMap<int, QString> recMap;
556 // to.setRecurrence( 568 recMap.insert( ORecur::RType , item.data("RType") );
569 recMap.insert( ORecur::RWeekdays , item.data("RWeekdays") );
570 recMap.insert( ORecur::RPosition , item.data("RPosition") );
571 recMap.insert( ORecur::RFreq , item.data("RFreq") );
572 recMap.insert( ORecur::RHasEndDate, item.data("RHasEndDate") );
573 recMap.insert( ORecur::EndDate , item.data("EndDate") );
574 recMap.insert( ORecur::Created , item.data("Created") );
575 recMap.insert( ORecur::Exceptions , item.data("Exceptions") );
576
577 ORecur recur;
578 recur.fromMap( recMap );
579 to.setRecurrence( recur );
557 580
558 return to; 581 return to;
559} 582}
560OTodo OTodoAccessBackendSQL::todo( int uid )const { 583OTodo OTodoAccessBackendSQL::todo( int uid )const {
561 FindQuery find( uid ); 584 FindQuery find( uid );
562 return todo( m_driver->query(&find) ); 585 return todo( m_driver->query(&find) );
563} 586}
564/* 587/*
565 * update the dict 588 * update the dict
566 */ 589 */
567void OTodoAccessBackendSQL::fillDict() { 590void OTodoAccessBackendSQL::fillDict() {
568 /* initialize dict */ 591 /* initialize dict */
569 /* 592 /*
570 * UPDATE dict if you change anything!!! 593 * UPDATE dict if you change anything!!!
571 * FIXME: Isn't this dict obsolete ? (eilers) 594 * FIXME: Isn't this dict obsolete ? (eilers)
572 */ 595 */
573 m_dict.setAutoDelete( TRUE ); 596 m_dict.setAutoDelete( TRUE );
574 m_dict.insert("Categories" , new int(OTodo::Category) ); 597 m_dict.insert("Categories" , new int(OTodo::Category) );
575 m_dict.insert("Uid" , new int(OTodo::Uid) ); 598 m_dict.insert("Uid" , new int(OTodo::Uid) );
576 m_dict.insert("HasDate" , new int(OTodo::HasDate) ); 599 m_dict.insert("HasDate" , new int(OTodo::HasDate) );
577 m_dict.insert("Completed" , new int(OTodo::Completed) ); 600 m_dict.insert("Completed" , new int(OTodo::Completed) );
578 m_dict.insert("Description" , new int(OTodo::Description) ); 601 m_dict.insert("Description" , new int(OTodo::Description) );
579 m_dict.insert("Summary" , new int(OTodo::Summary) ); 602 m_dict.insert("Summary" , new int(OTodo::Summary) );
580 m_dict.insert("Priority" , new int(OTodo::Priority) ); 603 m_dict.insert("Priority" , new int(OTodo::Priority) );