-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 21f93a0..c3416cb 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -119,96 +119,97 @@ bool OTodoAccessXML::load() { | |||
119 | while ( j < len && dt[j] != '"' ) { | 119 | while ( j < len && dt[j] != '"' ) { |
120 | if ( ((unsigned char)dt[j]) > 0x7f ) | 120 | if ( ((unsigned char)dt[j]) > 0x7f ) |
121 | haveUtf = TRUE; | 121 | haveUtf = TRUE; |
122 | if ( dt[j] == '&' ) | 122 | if ( dt[j] == '&' ) |
123 | haveEnt = TRUE; | 123 | haveEnt = TRUE; |
124 | ++j; | 124 | ++j; |
125 | } | 125 | } |
126 | if ( i == j ) { | 126 | if ( i == j ) { |
127 | // empty value | 127 | // empty value |
128 | i = j + 1; | 128 | i = j + 1; |
129 | continue; | 129 | continue; |
130 | } | 130 | } |
131 | 131 | ||
132 | QCString value( dt+i, j-i+1 ); | 132 | QCString value( dt+i, j-i+1 ); |
133 | i = j + 1; | 133 | i = j + 1; |
134 | 134 | ||
135 | QString str = (haveUtf ? QString::fromUtf8( value ) | 135 | QString str = (haveUtf ? QString::fromUtf8( value ) |
136 | : QString::fromLatin1( value ) ); | 136 | : QString::fromLatin1( value ) ); |
137 | if ( haveEnt ) | 137 | if ( haveEnt ) |
138 | str = Qtopia::plainString( str ); | 138 | str = Qtopia::plainString( str ); |
139 | 139 | ||
140 | /* | 140 | /* |
141 | * add key + value | 141 | * add key + value |
142 | */ | 142 | */ |
143 | todo( &dict, ev, attr, str ); | 143 | todo( &dict, ev, attr, str ); |
144 | 144 | ||
145 | } | 145 | } |
146 | /* | 146 | /* |
147 | * now add it | 147 | * now add it |
148 | */ | 148 | */ |
149 | qWarning("End at %d", i ); | 149 | qWarning("End at %d", i ); |
150 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { | 150 | if (m_events.contains( ev.uid() ) || ev.uid() == 0) { |
151 | ev.setUid( 1 ); | 151 | ev.setUid( 1 ); |
152 | m_changed = true; | 152 | m_changed = true; |
153 | } | 153 | } |
154 | if ( ev.hasDueDate() ) { | 154 | if ( ev.hasDueDate() ) { |
155 | ev.setDueDate( QDate(m_year, m_month, m_day) ); | 155 | ev.setDueDate( QDate(m_year, m_month, m_day) ); |
156 | } | 156 | } |
157 | m_events.insert(ev.uid(), ev ); | 157 | m_events.insert(ev.uid(), ev ); |
158 | m_year = m_month = m_day = -1; | 158 | m_year = m_month = m_day = -1; |
159 | } | 159 | } |
160 | 160 | ||
161 | munmap(map_addr, attribut.st_size ); | 161 | munmap(map_addr, attribut.st_size ); |
162 | 162 | ||
163 | qWarning("counts %d records loaded!", m_events.count() ); | 163 | qWarning("counts %d records loaded!", m_events.count() ); |
164 | return true; | 164 | return true; |
165 | } | 165 | } |
166 | bool OTodoAccessXML::reload() { | 166 | bool OTodoAccessXML::reload() { |
167 | m_events.clear(); | ||
167 | return load(); | 168 | return load(); |
168 | } | 169 | } |
169 | bool OTodoAccessXML::save() { | 170 | bool OTodoAccessXML::save() { |
170 | // qWarning("saving"); | 171 | // qWarning("saving"); |
171 | if (!m_opened || !m_changed ) { | 172 | if (!m_opened || !m_changed ) { |
172 | // qWarning("not saving"); | 173 | // qWarning("not saving"); |
173 | return true; | 174 | return true; |
174 | } | 175 | } |
175 | QString strNewFile = m_file + ".new"; | 176 | QString strNewFile = m_file + ".new"; |
176 | QFile f( strNewFile ); | 177 | QFile f( strNewFile ); |
177 | if (!f.open( IO_WriteOnly|IO_Raw ) ) | 178 | if (!f.open( IO_WriteOnly|IO_Raw ) ) |
178 | return false; | 179 | return false; |
179 | 180 | ||
180 | int written; | 181 | int written; |
181 | QString out; | 182 | QString out; |
182 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; | 183 | out = "<!DOCTYPE Tasks>\n<Tasks>\n"; |
183 | 184 | ||
184 | // for all todos | 185 | // for all todos |
185 | QMap<int, OTodo>::Iterator it; | 186 | QMap<int, OTodo>::Iterator it; |
186 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 187 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
187 | out+= "<Task " + toString( (*it) ) + " />\n"; | 188 | out+= "<Task " + toString( (*it) ) + " />\n"; |
188 | QCString cstr = out.utf8(); | 189 | QCString cstr = out.utf8(); |
189 | written = f.writeBlock( cstr.data(), cstr.length() ); | 190 | written = f.writeBlock( cstr.data(), cstr.length() ); |
190 | 191 | ||
191 | /* less written then we wanted */ | 192 | /* less written then we wanted */ |
192 | if ( written != (int)cstr.length() ) { | 193 | if ( written != (int)cstr.length() ) { |
193 | f.close(); | 194 | f.close(); |
194 | QFile::remove( strNewFile ); | 195 | QFile::remove( strNewFile ); |
195 | return false; | 196 | return false; |
196 | } | 197 | } |
197 | out = QString::null; | 198 | out = QString::null; |
198 | } | 199 | } |
199 | 200 | ||
200 | out += "</Tasks>"; | 201 | out += "</Tasks>"; |
201 | QCString cstr = out.utf8(); | 202 | QCString cstr = out.utf8(); |
202 | written = f.writeBlock( cstr.data(), cstr.length() ); | 203 | written = f.writeBlock( cstr.data(), cstr.length() ); |
203 | 204 | ||
204 | if ( written != (int)cstr.length() ) { | 205 | if ( written != (int)cstr.length() ) { |
205 | f.close(); | 206 | f.close(); |
206 | QFile::remove( strNewFile ); | 207 | QFile::remove( strNewFile ); |
207 | return false; | 208 | return false; |
208 | } | 209 | } |
209 | /* flush before renaming */ | 210 | /* flush before renaming */ |
210 | f.close(); | 211 | f.close(); |
211 | 212 | ||
212 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { | 213 | if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { |
213 | // qWarning("error renaming"); | 214 | // qWarning("error renaming"); |
214 | QFile::remove( strNewFile ); | 215 | QFile::remove( strNewFile ); |