-rw-r--r-- | libopie/tododb.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index fe8b8bf..6b10ec2 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -1,41 +1,43 @@ | |||
1 | 1 | ||
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <opie/tododb.h> | 3 | #include <opie/tododb.h> |
4 | #include <opie/xmltree.h> | 4 | #include <opie/xmltree.h> |
5 | #include <opie/todoresource.h> | 5 | #include <opie/todoresource.h> |
6 | #include <qpe/palmtoprecord.h> | 6 | #include <qpe/palmtoprecord.h> |
7 | #include <qpe/global.h> | 7 | #include <qpe/global.h> |
8 | 8 | ||
9 | using namespace Opie; | 9 | using namespace Opie; |
10 | 10 | ||
11 | namespace { | 11 | namespace { |
12 | 12 | ||
13 | class FileToDoResource : public ToDoResource { | 13 | class FileToDoResource : public ToDoResource { |
14 | public: | 14 | public: |
15 | FileToDoResource() {}; | 15 | FileToDoResource() {}; |
16 | // FIXME better parsing | ||
16 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ | 17 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ |
17 | // prepare the XML | 18 | // prepare the XML |
18 | XMLElement *tasks = new XMLElement( ); | 19 | XMLElement *tasks = new XMLElement( ); |
19 | tasks->setTagName("Tasks" ); | 20 | tasks->setTagName("Tasks" ); |
20 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ | 21 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ |
21 | XMLElement::AttributeMap map; | 22 | XMLElement::AttributeMap map; |
22 | XMLElement *task = new XMLElement(); | 23 | XMLElement *task = new XMLElement(); |
23 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); | 24 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); |
24 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); | 25 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); |
25 | map.insert( "Priority", QString::number( (*it).priority() ) ); | 26 | map.insert( "Priority", QString::number( (*it).priority() ) ); |
27 | map.insert( "Summary", (*it).summary() ); | ||
26 | QArray<int> arrat = (*it).categories(); | 28 | QArray<int> arrat = (*it).categories(); |
27 | QString attr; | 29 | QString attr; |
28 | for(uint i=0; i < arrat.count(); i++ ){ | 30 | for(uint i=0; i < arrat.count(); i++ ){ |
29 | attr.append(QString::number(arrat[i])+";" ); | 31 | attr.append(QString::number(arrat[i])+";" ); |
30 | } | 32 | } |
31 | if(!attr.isEmpty() ) // remove the last ; | 33 | if(!attr.isEmpty() ) // remove the last ; |
32 | attr.remove(attr.length()-1, 1 ); | 34 | attr.remove(attr.length()-1, 1 ); |
33 | map.insert( "Categories", attr ); | 35 | map.insert( "Categories", attr ); |
34 | //else | 36 | //else |
35 | //map.insert( "Categories", QString::null ); | 37 | //map.insert( "Categories", QString::null ); |
36 | map.insert( "Description", (*it).description() ); | 38 | map.insert( "Description", (*it).description() ); |
37 | if( (*it).hasDate() ){ | 39 | if( (*it).hasDate() ){ |
38 | map.insert("DateYear", QString::number( (*it).date().year() ) ); | 40 | map.insert("DateYear", QString::number( (*it).date().year() ) ); |
39 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); | 41 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); |
40 | map.insert("DateDay", QString::number( (*it).date().day() ) ); | 42 | map.insert("DateDay", QString::number( (*it).date().day() ) ); |
41 | } | 43 | } |
@@ -98,37 +100,39 @@ public: | |||
98 | dumInt = dummy.toInt(&ok ); | 100 | dumInt = dummy.toInt(&ok ); |
99 | if(ok ) month = dumInt; | 101 | if(ok ) month = dumInt; |
100 | dummy = element->attribute("DateDay" ); | 102 | dummy = element->attribute("DateDay" ); |
101 | dumInt = dummy.toInt(&ok ); | 103 | dumInt = dummy.toInt(&ok ); |
102 | if(ok ) day = dumInt; | 104 | if(ok ) day = dumInt; |
103 | // set the date | 105 | // set the date |
104 | QDate date( year, month, day ); | 106 | QDate date( year, month, day ); |
105 | event.setDate( date); | 107 | event.setDate( date); |
106 | } | 108 | } |
107 | dummy = element->attribute("Priority" ); | 109 | dummy = element->attribute("Priority" ); |
108 | dumInt = dummy.toInt(&ok ); | 110 | dumInt = dummy.toInt(&ok ); |
109 | if(!ok ) dumInt = ToDoEvent::NORMAL; | 111 | if(!ok ) dumInt = ToDoEvent::NORMAL; |
110 | event.setPriority( dumInt ); | 112 | event.setPriority( dumInt ); |
111 | //description | 113 | //description |
112 | dummy = element->attribute("Description" ); | 114 | dummy = element->attribute("Description" ); |
113 | event.setDescription( dummy ); | 115 | event.setDescription( dummy ); |
116 | dummy = element->attribute("Summary" ); | ||
117 | event.setSummary( dummy ); | ||
114 | // category | 118 | // category |
115 | dummy = element->attribute("Categories" ); | 119 | dummy = element->attribute("Categories" ); |
116 | QStringList ids = QStringList::split(";", dummy ); | 120 | QStringList ids = QStringList::split(";", dummy ); |
117 | event.setCategories( ids ); | 121 | event.setCategories( ids ); |
118 | 122 | ||
119 | //uid | 123 | //uid |
120 | dummy = element->attribute("Uid" ); | 124 | dummy = element->attribute("Uid" ); |
121 | dumInt = dummy.toInt(&ok ); | 125 | dumInt = dummy.toInt(&ok ); |
122 | if(ok ) event.setUid( dumInt ); | 126 | if(ok ) event.setUid( dumInt ); |
123 | m_todos.append( event ); | 127 | m_todos.append( event ); |
124 | element = element->nextChild(); // next element | 128 | element = element->nextChild(); // next element |
125 | } | 129 | } |
126 | //} | 130 | //} |
127 | }else { | 131 | }else { |
128 | qWarning("could not load" ); | 132 | qWarning("could not load" ); |
129 | } | 133 | } |
130 | delete root; | 134 | delete root; |
131 | qWarning("returning" ); | 135 | qWarning("returning" ); |
132 | return m_todos; | 136 | return m_todos; |
133 | } | 137 | } |
134 | }; | 138 | }; |
@@ -168,33 +172,33 @@ QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, | |||
168 | if( (*it).date() >= from && (*it).date() <= to ) | 172 | if( (*it).date() >= from && (*it).date() <= to ) |
169 | events.append( (*it) ); | 173 | events.append( (*it) ); |
170 | }else if( all ){ | 174 | }else if( all ){ |
171 | events.append( (*it) ); | 175 | events.append( (*it) ); |
172 | } | 176 | } |
173 | } | 177 | } |
174 | return events; | 178 | return events; |
175 | } | 179 | } |
176 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, | 180 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, |
177 | bool all) | 181 | bool all) |
178 | { | 182 | { |
179 | return effectiveToDos( from, QDate::currentDate(), all ); | 183 | return effectiveToDos( from, QDate::currentDate(), all ); |
180 | } | 184 | } |
181 | QValueList<ToDoEvent> ToDoDB::overDue() | 185 | QValueList<ToDoEvent> ToDoDB::overDue() |
182 | { | 186 | { |
183 | QValueList<ToDoEvent> events; | 187 | QValueList<ToDoEvent> events; |
184 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 188 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
185 | if( (*it).isOverdue() ) | 189 | if( (*it).isOverdue() ) |
186 | events.append((*it) ); | 190 | events.append((*it) ); |
187 | } | 191 | } |
188 | return events; | 192 | return events; |
189 | } | 193 | } |
190 | QValueList<ToDoEvent> ToDoDB::rawToDos() | 194 | QValueList<ToDoEvent> ToDoDB::rawToDos() |
191 | { | 195 | { |
192 | return m_todos; | 196 | return m_todos; |
193 | } | 197 | } |
194 | void ToDoDB::addEvent( const ToDoEvent &event ) | 198 | void ToDoDB::addEvent( const ToDoEvent &event ) |
195 | { | 199 | { |
196 | m_todos.append( event ); | 200 | m_todos.append( event ); |
197 | } | 201 | } |
198 | void ToDoDB::editEvent( const ToDoEvent &event ) | 202 | void ToDoDB::editEvent( const ToDoEvent &event ) |
199 | { | 203 | { |
200 | m_todos.remove( event ); | 204 | m_todos.remove( event ); |
@@ -225,30 +229,30 @@ void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events ) | |||
225 | { | 229 | { |
226 | QValueList<ToDoEvent>::ConstIterator it; | 230 | QValueList<ToDoEvent>::ConstIterator it; |
227 | for( it = events.begin(); it != events.end(); ++it ){ | 231 | for( it = events.begin(); it != events.end(); ++it ){ |
228 | replaceEvent( (*it) ); | 232 | replaceEvent( (*it) ); |
229 | } | 233 | } |
230 | } | 234 | } |
231 | void ToDoDB::setFileName(const QString &file ) | 235 | void ToDoDB::setFileName(const QString &file ) |
232 | { | 236 | { |
233 | m_fileName =file; | 237 | m_fileName =file; |
234 | } | 238 | } |
235 | QString ToDoDB::fileName()const | 239 | QString ToDoDB::fileName()const |
236 | { | 240 | { |
237 | return m_fileName; | 241 | return m_fileName; |
238 | } | 242 | } |
239 | void ToDoDB::load() | 243 | void ToDoDB::load() |
240 | { | 244 | { |
241 | m_todos = m_res->load( m_fileName ); | 245 | m_todos = m_res->load( m_fileName ); |
242 | } | 246 | } |
243 | bool ToDoDB::save() | 247 | bool ToDoDB::save() |
244 | { | 248 | { |
245 | return m_res->save( m_fileName, m_todos ); | 249 | return m_res->save( m_fileName, m_todos ); |
246 | } | 250 | } |
247 | 251 | ||
248 | 252 | ||
249 | 253 | ||
250 | 254 | ||
251 | 255 | ||
252 | 256 | ||
253 | 257 | ||
254 | 258 | ||