author | zecke <zecke> | 2002-04-25 16:11:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-25 16:11:10 (UTC) |
commit | e944a214e0efeccd2eb9cc479ad8893427c6b81d (patch) (unidiff) | |
tree | 263f754a34d23738dac6c3dea9dbcb0ce8b6bb3e | |
parent | 48dbc8fb69a5d19f466ea757207e42c3861b4dee (diff) | |
download | opie-e944a214e0efeccd2eb9cc479ad8893427c6b81d.zip opie-e944a214e0efeccd2eb9cc479ad8893427c6b81d.tar.gz opie-e944a214e0efeccd2eb9cc479ad8893427c6b81d.tar.bz2 |
This should fix the Umlaut problem
-rw-r--r-- | libopie/tododb.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp index c486723..33fa177 100644 --- a/libopie/tododb.cpp +++ b/libopie/tododb.cpp | |||
@@ -1,251 +1,252 @@ | |||
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 | namespace { | 9 | namespace { |
10 | 10 | ||
11 | class FileToDoResource : public ToDoResource { | 11 | class FileToDoResource : public ToDoResource { |
12 | public: | 12 | public: |
13 | FileToDoResource() {}; | 13 | FileToDoResource() {}; |
14 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ | 14 | bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){ |
15 | // prepare the XML | 15 | // prepare the XML |
16 | XMLElement *tasks = new XMLElement( ); | 16 | XMLElement *tasks = new XMLElement( ); |
17 | tasks->setTagName("Tasks" ); | 17 | tasks->setTagName("Tasks" ); |
18 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ | 18 | for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){ |
19 | XMLElement::AttributeMap map; | 19 | XMLElement::AttributeMap map; |
20 | XMLElement *task = new XMLElement(); | 20 | XMLElement *task = new XMLElement(); |
21 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); | 21 | map.insert( "Completed", QString::number((int)(*it).isCompleted() ) ); |
22 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); | 22 | map.insert( "HasDate", QString::number((int)(*it).hasDate() ) ); |
23 | map.insert( "Priority", QString::number( (*it).priority() ) ); | 23 | map.insert( "Priority", QString::number( (*it).priority() ) ); |
24 | QArray<int> arrat = (*it).categories(); | 24 | QArray<int> arrat = (*it).categories(); |
25 | QString attr; | 25 | QString attr; |
26 | for(uint i=0; i < arrat.count(); i++ ){ | 26 | for(uint i=0; i < arrat.count(); i++ ){ |
27 | attr.append(QString::number(arrat[i])+";" ); | 27 | attr.append(QString::number(arrat[i])+";" ); |
28 | } | 28 | } |
29 | if(!attr.isEmpty() ) // remove the last ; | 29 | if(!attr.isEmpty() ) // remove the last ; |
30 | attr.remove(attr.length()-1, 1 ); | 30 | attr.remove(attr.length()-1, 1 ); |
31 | map.insert( "Categories", attr ); | 31 | map.insert( "Categories", attr ); |
32 | //else | 32 | //else |
33 | //map.insert( "Categories", QString::null ); | 33 | //map.insert( "Categories", QString::null ); |
34 | map.insert( "Description", (*it).description() ); | 34 | map.insert( "Description", (*it).description() ); |
35 | if( (*it).hasDate() ){ | 35 | if( (*it).hasDate() ){ |
36 | map.insert("DateYear", QString::number( (*it).date().year() ) ); | 36 | map.insert("DateYear", QString::number( (*it).date().year() ) ); |
37 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); | 37 | map.insert("DateMonth", QString::number( (*it).date().month() ) ); |
38 | map.insert("DateDay", QString::number( (*it).date().day() ) ); | 38 | map.insert("DateDay", QString::number( (*it).date().day() ) ); |
39 | } | 39 | } |
40 | map.insert("Uid", QString::number( (*it).uid() ) ); | 40 | map.insert("Uid", QString::number( (*it).uid() ) ); |
41 | task->setTagName("Task" ); | 41 | task->setTagName("Task" ); |
42 | task->setAttributes( map ); | 42 | task->setAttributes( map ); |
43 | tasks->appendChild(task); | 43 | tasks->appendChild(task); |
44 | } | 44 | } |
45 | QFile file( name); | 45 | QFile file( name); |
46 | if( file.open(IO_WriteOnly ) ){ | 46 | if( file.open(IO_WriteOnly ) ){ |
47 | QTextStream stream(&file ); | 47 | QTextStream stream(&file ); |
48 | stream.setEncoding( QTextStream::UnicodeUTF8 ); | ||
48 | stream << "<!DOCTYPE Tasks>" << endl; | 49 | stream << "<!DOCTYPE Tasks>" << endl; |
49 | tasks->save(stream ); | 50 | tasks->save(stream ); |
50 | delete tasks; | 51 | delete tasks; |
51 | stream << "</Tasks>" << endl; | 52 | stream << "</Tasks>" << endl; |
52 | file.close(); | 53 | file.close(); |
53 | return true; | 54 | return true; |
54 | } | 55 | } |
55 | return false; | 56 | return false; |
56 | } | 57 | } |
57 | QValueList<ToDoEvent> load( const QString &name ){ | 58 | QValueList<ToDoEvent> load( const QString &name ){ |
58 | qWarning("loading tododb" ); | 59 | qWarning("loading tododb" ); |
59 | QValueList<ToDoEvent> m_todos; | 60 | QValueList<ToDoEvent> m_todos; |
60 | XMLElement *root = XMLElement::load( name ); | 61 | XMLElement *root = XMLElement::load( name ); |
61 | if(root != 0l ){ // start parsing | 62 | if(root != 0l ){ // start parsing |
62 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); | 63 | qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() ); |
63 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start | 64 | //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start |
64 | XMLElement *element = root->firstChild(); | 65 | XMLElement *element = root->firstChild(); |
65 | element = element->firstChild(); | 66 | element = element->firstChild(); |
66 | while( element ){ | 67 | while( element ){ |
67 | if( element->tagName() != QString::fromLatin1("Task") ){ | 68 | if( element->tagName() != QString::fromLatin1("Task") ){ |
68 | element = element->nextChild(); | 69 | element = element->nextChild(); |
69 | continue; | 70 | continue; |
70 | } | 71 | } |
71 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); | 72 | qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() ); |
72 | QString dummy; | 73 | QString dummy; |
73 | ToDoEvent event; | 74 | ToDoEvent event; |
74 | bool ok; | 75 | bool ok; |
75 | int dumInt; | 76 | int dumInt; |
76 | // completed | 77 | // completed |
77 | dummy = element->attribute("Completed" ); | 78 | dummy = element->attribute("Completed" ); |
78 | dumInt = dummy.toInt(&ok ); | 79 | dumInt = dummy.toInt(&ok ); |
79 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); | 80 | if(ok ) event.setCompleted( dumInt == 0 ? false : true ); |
80 | // hasDate | 81 | // hasDate |
81 | dummy = element->attribute("HasDate" ); | 82 | dummy = element->attribute("HasDate" ); |
82 | dumInt = dummy.toInt(&ok ); | 83 | dumInt = dummy.toInt(&ok ); |
83 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); | 84 | if(ok ) event.setHasDate( dumInt == 0 ? false: true ); |
84 | // set the date | 85 | // set the date |
85 | bool hasDa = dumInt; | 86 | bool hasDa = dumInt; |
86 | if ( hasDa ) { //parse the date | 87 | if ( hasDa ) { //parse the date |
87 | int year, day, month = 0; | 88 | int year, day, month = 0; |
88 | year = day = month; | 89 | year = day = month; |
89 | // year | 90 | // year |
90 | dummy = element->attribute("DateYear" ); | 91 | dummy = element->attribute("DateYear" ); |
91 | dumInt = dummy.toInt(&ok ); | 92 | dumInt = dummy.toInt(&ok ); |
92 | if( ok ) year = dumInt; | 93 | if( ok ) year = dumInt; |
93 | // month | 94 | // month |
94 | dummy = element->attribute("DateMonth" ); | 95 | dummy = element->attribute("DateMonth" ); |
95 | dumInt = dummy.toInt(&ok ); | 96 | dumInt = dummy.toInt(&ok ); |
96 | if(ok ) month = dumInt; | 97 | if(ok ) month = dumInt; |
97 | dummy = element->attribute("DateDay" ); | 98 | dummy = element->attribute("DateDay" ); |
98 | dumInt = dummy.toInt(&ok ); | 99 | dumInt = dummy.toInt(&ok ); |
99 | if(ok ) day = dumInt; | 100 | if(ok ) day = dumInt; |
100 | // set the date | 101 | // set the date |
101 | QDate date( year, month, day ); | 102 | QDate date( year, month, day ); |
102 | event.setDate( date); | 103 | event.setDate( date); |
103 | } | 104 | } |
104 | dummy = element->attribute("Priority" ); | 105 | dummy = element->attribute("Priority" ); |
105 | dumInt = dummy.toInt(&ok ); | 106 | dumInt = dummy.toInt(&ok ); |
106 | if(!ok ) dumInt = ToDoEvent::NORMAL; | 107 | if(!ok ) dumInt = ToDoEvent::NORMAL; |
107 | event.setPriority( dumInt ); | 108 | event.setPriority( dumInt ); |
108 | //description | 109 | //description |
109 | dummy = element->attribute("Description" ); | 110 | dummy = element->attribute("Description" ); |
110 | event.setDescription( dummy ); | 111 | event.setDescription( dummy ); |
111 | // category | 112 | // category |
112 | dummy = element->attribute("Categories" ); | 113 | dummy = element->attribute("Categories" ); |
113 | QStringList ids = QStringList::split(";", dummy ); | 114 | QStringList ids = QStringList::split(";", dummy ); |
114 | event.setCategories( ids ); | 115 | event.setCategories( ids ); |
115 | 116 | ||
116 | //uid | 117 | //uid |
117 | dummy = element->attribute("Uid" ); | 118 | dummy = element->attribute("Uid" ); |
118 | dumInt = dummy.toInt(&ok ); | 119 | dumInt = dummy.toInt(&ok ); |
119 | if(ok ) event.setUid( dumInt ); | 120 | if(ok ) event.setUid( dumInt ); |
120 | m_todos.append( event ); | 121 | m_todos.append( event ); |
121 | element = element->nextChild(); // next element | 122 | element = element->nextChild(); // next element |
122 | } | 123 | } |
123 | //} | 124 | //} |
124 | }else { | 125 | }else { |
125 | qWarning("could not load" ); | 126 | qWarning("could not load" ); |
126 | } | 127 | } |
127 | delete root; | 128 | delete root; |
128 | qWarning("returning" ); | 129 | qWarning("returning" ); |
129 | return m_todos; | 130 | return m_todos; |
130 | } | 131 | } |
131 | }; | 132 | }; |
132 | 133 | ||
133 | } | 134 | } |
134 | 135 | ||
135 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ | 136 | ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){ |
136 | m_fileName = fileName; | 137 | m_fileName = fileName; |
137 | if( fileName.isEmpty() && res == 0 ){ | 138 | if( fileName.isEmpty() && res == 0 ){ |
138 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); | 139 | m_fileName = Global::applicationFileName("todolist","todolist.xml"); |
139 | res = new FileToDoResource(); | 140 | res = new FileToDoResource(); |
140 | //qWarning("%s", m_fileName.latin1() ); | 141 | //qWarning("%s", m_fileName.latin1() ); |
141 | }else if(res == 0 ){ // let's create a ToDoResource for xml | 142 | }else if(res == 0 ){ // let's create a ToDoResource for xml |
142 | res = new FileToDoResource(); | 143 | res = new FileToDoResource(); |
143 | } | 144 | } |
144 | m_res = res; | 145 | m_res = res; |
145 | load(); | 146 | load(); |
146 | } | 147 | } |
147 | ToDoResource* ToDoDB::resource(){ | 148 | ToDoResource* ToDoDB::resource(){ |
148 | return m_res; | 149 | return m_res; |
149 | }; | 150 | }; |
150 | void ToDoDB::setResource( ToDoResource *res ) | 151 | void ToDoDB::setResource( ToDoResource *res ) |
151 | { | 152 | { |
152 | delete m_res; | 153 | delete m_res; |
153 | m_res = res; | 154 | m_res = res; |
154 | } | 155 | } |
155 | ToDoDB::~ToDoDB() | 156 | ToDoDB::~ToDoDB() |
156 | { | 157 | { |
157 | delete m_res; | 158 | delete m_res; |
158 | } | 159 | } |
159 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, | 160 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to, |
160 | bool all ) | 161 | bool all ) |
161 | { | 162 | { |
162 | QValueList<ToDoEvent> events; | 163 | QValueList<ToDoEvent> events; |
163 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 164 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
164 | if( (*it).hasDate() ){ | 165 | if( (*it).hasDate() ){ |
165 | if( (*it).date() >= from && (*it).date() <= to ) | 166 | if( (*it).date() >= from && (*it).date() <= to ) |
166 | events.append( (*it) ); | 167 | events.append( (*it) ); |
167 | }else if( all ){ | 168 | }else if( all ){ |
168 | events.append( (*it) ); | 169 | events.append( (*it) ); |
169 | } | 170 | } |
170 | } | 171 | } |
171 | return events; | 172 | return events; |
172 | } | 173 | } |
173 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, | 174 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, |
174 | bool all) | 175 | bool all) |
175 | { | 176 | { |
176 | return effectiveToDos( from, QDate::currentDate(), all ); | 177 | return effectiveToDos( from, QDate::currentDate(), all ); |
177 | } | 178 | } |
178 | QValueList<ToDoEvent> ToDoDB::overDue() | 179 | QValueList<ToDoEvent> ToDoDB::overDue() |
179 | { | 180 | { |
180 | QValueList<ToDoEvent> events; | 181 | QValueList<ToDoEvent> events; |
181 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ | 182 | for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){ |
182 | if( (*it).isOverdue() ) | 183 | if( (*it).isOverdue() ) |
183 | events.append((*it) ); | 184 | events.append((*it) ); |
184 | } | 185 | } |
185 | return events; | 186 | return events; |
186 | } | 187 | } |
187 | QValueList<ToDoEvent> ToDoDB::rawToDos() | 188 | QValueList<ToDoEvent> ToDoDB::rawToDos() |
188 | { | 189 | { |
189 | return m_todos; | 190 | return m_todos; |
190 | } | 191 | } |
191 | void ToDoDB::addEvent( const ToDoEvent &event ) | 192 | void ToDoDB::addEvent( const ToDoEvent &event ) |
192 | { | 193 | { |
193 | m_todos.append( event ); | 194 | m_todos.append( event ); |
194 | } | 195 | } |
195 | void ToDoDB::editEvent( const ToDoEvent &event ) | 196 | void ToDoDB::editEvent( const ToDoEvent &event ) |
196 | { | 197 | { |
197 | m_todos.remove( event ); | 198 | m_todos.remove( event ); |
198 | m_todos.append( event ); | 199 | m_todos.append( event ); |
199 | } | 200 | } |
200 | void ToDoDB::removeEvent( const ToDoEvent &event ) | 201 | void ToDoDB::removeEvent( const ToDoEvent &event ) |
201 | { | 202 | { |
202 | m_todos.remove( event ); | 203 | m_todos.remove( event ); |
203 | } | 204 | } |
204 | void ToDoDB::replaceEvent(const ToDoEvent &event ) | 205 | void ToDoDB::replaceEvent(const ToDoEvent &event ) |
205 | { | 206 | { |
206 | QValueList<ToDoEvent>::Iterator it; | 207 | QValueList<ToDoEvent>::Iterator it; |
207 | int uid = event.uid(); | 208 | int uid = event.uid(); |
208 | // == is not overloaded as we would like :( so let's search for the uid | 209 | // == is not overloaded as we would like :( so let's search for the uid |
209 | for(it = m_todos.begin(); it != m_todos.end(); ++it ){ | 210 | for(it = m_todos.begin(); it != m_todos.end(); ++it ){ |
210 | if( (*it).uid() == uid ){ | 211 | if( (*it).uid() == uid ){ |
211 | m_todos.remove( (*it) ); | 212 | m_todos.remove( (*it) ); |
212 | break; // should save us the iterate is now borked | 213 | break; // should save us the iterate is now borked |
213 | } | 214 | } |
214 | } | 215 | } |
215 | m_todos.append(event); | 216 | m_todos.append(event); |
216 | } | 217 | } |
217 | void ToDoDB::reload() | 218 | void ToDoDB::reload() |
218 | { | 219 | { |
219 | load(); | 220 | load(); |
220 | } | 221 | } |
221 | void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events ) | 222 | void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events ) |
222 | { | 223 | { |
223 | QValueList<ToDoEvent>::ConstIterator it; | 224 | QValueList<ToDoEvent>::ConstIterator it; |
224 | for( it = events.begin(); it != events.end(); ++it ){ | 225 | for( it = events.begin(); it != events.end(); ++it ){ |
225 | replaceEvent( (*it) ); | 226 | replaceEvent( (*it) ); |
226 | } | 227 | } |
227 | } | 228 | } |
228 | void ToDoDB::setFileName(const QString &file ) | 229 | void ToDoDB::setFileName(const QString &file ) |
229 | { | 230 | { |
230 | m_fileName =file; | 231 | m_fileName =file; |
231 | } | 232 | } |
232 | QString ToDoDB::fileName()const | 233 | QString ToDoDB::fileName()const |
233 | { | 234 | { |
234 | return m_fileName; | 235 | return m_fileName; |
235 | } | 236 | } |
236 | void ToDoDB::load() | 237 | void ToDoDB::load() |
237 | { | 238 | { |
238 | m_todos = m_res->load( m_fileName ); | 239 | m_todos = m_res->load( m_fileName ); |
239 | } | 240 | } |
240 | bool ToDoDB::save() | 241 | bool ToDoDB::save() |
241 | { | 242 | { |
242 | return m_res->save( m_fileName, m_todos ); | 243 | return m_res->save( m_fileName, m_todos ); |
243 | } | 244 | } |
244 | 245 | ||
245 | 246 | ||
246 | 247 | ||
247 | 248 | ||
248 | 249 | ||
249 | 250 | ||
250 | 251 | ||
251 | 252 | ||