summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-21 07:09:09 (UTC)
committer zautrix <zautrix>2004-09-21 07:09:09 (UTC)
commit1cf4cc6e7bf25ee309852c7c97155de86917289f (patch) (unidiff)
tree721dd83559c3c7635d132b8a95cd6fdc4cdcc351
parent434ddaa08e0a650422ef271332a1d11879028095 (diff)
downloadkdepimpi-1cf4cc6e7bf25ee309852c7c97155de86917289f.zip
kdepimpi-1cf4cc6e7bf25ee309852c7c97155de86917289f.tar.gz
kdepimpi-1cf4cc6e7bf25ee309852c7c97155de86917289f.tar.bz2
qtopia format changes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp135
1 files changed, 26 insertions, 109 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 1f90fcb..f9cabcb 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -43,26 +43,24 @@ $Id$
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncprefwidget.h" 52#include "syncprefwidget.h"
53 53
54#include "resourceqtopia.h" 54#include "resourceqtopia.h"
55#include <libkdepim/ksyncprofile.h>
56#include <qpe/quuid.h>
57 55
58using namespace KABC; 56using namespace KABC;
59extern "C" 57extern "C"
60{ 58{
61 void *init_microkabc_qtopia() 59 void *init_microkabc_qtopia()
62 { 60 {
63 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); 61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>();
64 } 62 }
65} 63}
66 64
67ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable )
68 : Resource( config, syncable ), mConverter (0) 66 : Resource( config, syncable ), mConverter (0)
@@ -182,137 +180,56 @@ bool ResourceQtopia::load()
182 if ( !addressee.isEmpty() && res ) 180 if ( !addressee.isEmpty() && res )
183 { 181 {
184 addressee.setResource( this ); 182 addressee.setResource( this );
185 addressBook()->insertAddressee( addressee ); 183 addressBook()->insertAddressee( addressee );
186 } 184 }
187 } 185 }
188 186
189 return true; 187 return true;
190} 188}
191 189
192bool ResourceQtopia::save( Ticket *ticket ) 190bool ResourceQtopia::save( Ticket *ticket )
193{ 191{
194 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 192 qDebug("ResourceQtopia::save: %s", fileName().latin1());
195
196 mDirWatch.stopScan();
197
198 KABC::AddressBook::Iterator it;
199 bool res;
200 KABC::Addressee::List changedAddressees;
201 QStringList addedUID;
202 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
203 //KABC::Addressee addressee = (*it);
204 // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() );
205 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
206 QUuid uid( (*it).originalExternalUID() );
207 bool ok;
208 PimContact c = mAccess->contactForId( uid, &ok );
209 qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() );
210 res = mConverter->addresseeToQtopia( *it, c );
211 if (res == true) {
212 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
213 qDebug("skipping adding of contact ");
214 continue;
215 PimContact e;
216 AddressBookAccess Access2;
217 Access2.addContact(e);
218 const PimContact* contact;
219 bool res;
220 QString uid2, Ouid;
221 AddressBookIterator itt(Access2);
222 for (contact=itt.toFirst(); itt.current(); ++itt)
223 {
224 contact = itt.current();
225 QString exuid = contact->uid().toString();
226 Ouid =exuid;
227 int ente = exuid.find( "-0000");
228 if ( exuid.left(1) == "{" )
229 exuid = exuid.mid(1);
230 if ( ente > -1 )
231 exuid = exuid.left( ente-1 );
232 uid2 = exuid;
233 qDebug("trying find uid ");
234 if ( !addressBook()->containsExternalUid( uid2 ) ) {
235 qDebug("ab not contains ");
236 if ( !addedUID.contains( uid2 )) {
237 qDebug("list not contains ");
238 break;
239 }
240 }
241
242 }
243 if ( !itt.current()) {
244 qDebug("ERROR uid ");
245 continue;
246 }
247 else
248 qDebug("ADD uid detected ");
249
250
251 QUuid uid3( Ouid);
252 PimContact d = Access2.contactForId( uid3, &ok );
253 if ( ! ok ) {
254 qDebug("ADD: Error getting new uid ");
255 } else {
256 qDebug("NEW UID found ");
257 PimContact g = mAccess->contactForId( c.uid(), &ok );
258 KABC::Addressee addressee;
259 mConverter->qtopiaToAddressee( g, addressee );
260 addressee.setUid((*it).uid() );
261 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
262 changedAddressees.append( addressee );
263 addedUID.append( uid2 );
264 }
265
266
267 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
268 qDebug("Remove contact ");
269 if ( ok )
270 mAccess->removeContact(c);
271 else
272 qDebug("Error remove contact from qtopia ");
273 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
274 if ( ok ) {
275 qDebug("Update contact ");
276 mAccess->updateContact(c);
277 PimContact g = mAccess->contactForId( c.uid(), &ok );
278 KABC::Addressee addressee;
279 mConverter->qtopiaToAddressee( g, addressee );
280 addressee.setUid((*it).uid() );
281 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
282 changedAddressees.append( addressee );
283 }
284 else
285 qDebug("Error update contact from qtopia ");
286
287 }
288
289 } else {
290 qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1());
291 }
292 }
293 }
294 193
295 KABC::Addressee::List::Iterator it2; 194 mDirWatch.stopScan();
296 for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 )
297 addressBook()->insertAddressee((*it2));
298 195
196 KABC::AddressBook::Iterator it;
197 bool res;
299 198
199 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
200 PimContact c;
201 KABC::Addressee addressee = (*it);
300 202
301 mDirWatch.startScan(); 203 res = mConverter->addresseeToQtopia( *it, c );
204 if (res == true)
205 {
206 mAccess->addContact(c);
207// if (res == false)
208// qDebug("Unable to append Contact %s", c.fullName().latin1());
209 }
210 else
211 {
212 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
213 }
214 }
302 215
303 delete ticket; 216// mAccess->addressBookUpdated();
304 unlock( fileName() );
305 217
306 return true; 218 mDirWatch.startScan();
219
220 delete ticket;
221 unlock( fileName() );
222
223 return true;
307} 224}
308 225
309bool ResourceQtopia::lock( const QString &lockfileName ) 226bool ResourceQtopia::lock( const QString &lockfileName )
310{ 227{
311 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 228 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
312 229
313 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 230 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
314 231
315 QString fn = lockfileName; 232 QString fn = lockfileName;
316 233
317 KURL url(fn); 234 KURL url(fn);
318 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 235 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );