Diffstat (limited to 'kabc/plugins/qtopia/resourceqtopia.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 101 |
1 files changed, 81 insertions, 20 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index deb218b..b7263bb 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -32,2 +32,3 @@ $Id$ | |||
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qtextstream.h> | ||
33 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
@@ -92,4 +93,2 @@ ResourceQtopia::~ResourceQtopia() | |||
92 | 93 | ||
93 | if(mAccess != 0) | ||
94 | delete mAccess; | ||
95 | } | 94 | } |
@@ -122,9 +121,2 @@ bool ResourceQtopia::doOpen() | |||
122 | 121 | ||
123 | mAccess = new AddressBookAccess(); | ||
124 | |||
125 | if ( !mAccess ) { | ||
126 | qDebug("Unable to load file() %s", fileName().latin1()); | ||
127 | return false; | ||
128 | } | ||
129 | |||
130 | 122 | ||
@@ -138,4 +130,2 @@ bool ResourceQtopia::doOpen() | |||
138 | qDebug(msg); | 130 | qDebug(msg); |
139 | delete mAccess; | ||
140 | mAccess = 0; | ||
141 | return false; | 131 | return false; |
@@ -151,7 +141,3 @@ void ResourceQtopia::doClose() | |||
151 | 141 | ||
152 | if(mAccess) | 142 | |
153 | { | ||
154 | delete mAccess; | ||
155 | mAccess = 0; | ||
156 | } | ||
157 | // it seems so, that deletion of access deletes backend as well | 143 | // it seems so, that deletion of access deletes backend as well |
@@ -164,2 +150,43 @@ bool ResourceQtopia::load() | |||
164 | { | 150 | { |
151 | |||
152 | QFile file( fileName() ); | ||
153 | if ( !file.open(IO_ReadOnly ) ) { | ||
154 | return false; | ||
155 | } | ||
156 | |||
157 | QDomDocument doc("mydocument" ); | ||
158 | if ( !doc.setContent( &file ) ) { | ||
159 | file.close(); | ||
160 | return false; | ||
161 | } | ||
162 | bool res; | ||
163 | QDomElement docElem = doc.documentElement( ); | ||
164 | QDomNode n = docElem.firstChild(); | ||
165 | while ( !n.isNull() ) { | ||
166 | QDomElement e = n.toElement(); | ||
167 | if ( !e.isNull() ) { | ||
168 | if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { // we're looking for them | ||
169 | QDomNode no = e.firstChild(); | ||
170 | while ( !no.isNull() ) { | ||
171 | QDomElement el = no.toElement(); | ||
172 | if ( !el.isNull() ) { | ||
173 | KABC::Addressee addressee; | ||
174 | res = mConverter->qtopiaToAddressee( el, addressee ); | ||
175 | if ( !addressee.isEmpty() && res ) | ||
176 | { | ||
177 | addressee.setResource( this ); | ||
178 | addressBook()->insertAddressee( addressee ); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | no = no.nextSibling(); | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | n = n.nextSibling(); | ||
188 | } | ||
189 | |||
190 | #if 0 | ||
191 | / old code | ||
165 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | 192 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); |
@@ -176,3 +203,3 @@ bool ResourceQtopia::load() | |||
176 | 203 | ||
177 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 204 | //LRres = mConverter->qtopiaToAddressee( (*contact), addressee ); |
178 | 205 | ||
@@ -184,3 +211,3 @@ bool ResourceQtopia::load() | |||
184 | } | 211 | } |
185 | 212 | #endif | |
186 | return true; | 213 | return true; |
@@ -190,2 +217,36 @@ bool ResourceQtopia::save( Ticket *ticket ) | |||
190 | { | 217 | { |
218 | |||
219 | mDirWatch.stopScan(); | ||
220 | KABC::AddressBook::Iterator it; | ||
221 | bool res; | ||
222 | //pending open file for stream | ||
223 | QTextStream *stream;// = tempFile->textStream(); | ||
224 | stream->setEncoding( QTextStream::UnicodeUTF8 ); | ||
225 | *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; | ||
226 | *stream << " <Groups>" << endl; | ||
227 | *stream << " </Groups>" << endl; | ||
228 | *stream << " <Contacts> " << endl; | ||
229 | // for all entries | ||
230 | KABC::Addressee ab; | ||
231 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | ||
232 | KABC::Addressee addressee = (*it); | ||
233 | res = mConverter->addresseeToQtopia( addressee, stream ); | ||
234 | if (!res == true) | ||
235 | { | ||
236 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | |||
241 | *stream << "</Contacts>" << endl; | ||
242 | *stream << "</AddressBook>" << endl; | ||
243 | //pending close file | ||
244 | mDirWatch.startScan(); | ||
245 | |||
246 | delete ticket; | ||
247 | unlock( fileName() ); | ||
248 | |||
249 | |||
250 | #if 0 | ||
251 | //old code | ||
191 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); | 252 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); |
@@ -201,3 +262,3 @@ bool ResourceQtopia::save( Ticket *ticket ) | |||
201 | 262 | ||
202 | res = mConverter->addresseeToQtopia( *it, c ); | 263 | //res = mConverter->addresseeToQtopia( *it, c ); |
203 | if (res == true) | 264 | if (res == true) |
@@ -220,3 +281,3 @@ bool ResourceQtopia::save( Ticket *ticket ) | |||
220 | unlock( fileName() ); | 281 | unlock( fileName() ); |
221 | 282 | #endif | |
222 | return true; | 283 | return true; |