1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
/*
This file is part of kdepim.
Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
Copyright (c) 2005 Volker Krause <volker.krause@rwth-aachen.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tqapplication.h>
#include <kabc/picture.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmdcodec.h>
#include <kstandarddirs.h>
#include <kstringhandler.h>
#include <libkdepim/kpimprefs.h>
#include <libkdepim/progressmanager.h>
#include <kio/davjob.h>
#include "webdavhandler.h"
#include "sloxaccounts.h"
#include "kabcsloxprefs.h"
#include "kabcresourceslox.h"
using namespace KABC;
ResourceSlox::ResourceSlox( const KConfig *config )
: ResourceCached( config ), SloxBase( this )
{
init();
mPrefs->addGroupPrefix( identifier() );
if ( config ) {
readConfig( config );
}
}
ResourceSlox::ResourceSlox( const KURL &url,
const TQString &user, const TQString &password )
: ResourceCached( 0 ), SloxBase( this )
{
init();
mPrefs->addGroupPrefix( identifier() );
mPrefs->setUrl( url.url() );
mPrefs->setUser( user );
mPrefs->setPassword( password );
}
void ResourceSlox::init()
{
mPrefs = new SloxPrefs;
mWebdavHandler.setResource( this );
mDownloadJob = 0;
mUploadJob = 0;
mDownloadProgress = 0;
mUploadProgress = 0;
// phone number mapping for SLOX
mPhoneNumberSloxMap[PhoneNumber::Work] << "phone" << "phone2";
mPhoneNumberSloxMap[PhoneNumber::Home] << "privatephone" << "privatephone2";
mPhoneNumberSloxMap[PhoneNumber::Cell | PhoneNumber::Work] << "mobile" << "mobile2";
mPhoneNumberSloxMap[PhoneNumber::Cell | PhoneNumber::Home] << "privatemobile" << "privatemobile2";
mPhoneNumberSloxMap[PhoneNumber::Fax | PhoneNumber::Work] << "fax" << "fax2";
mPhoneNumberSloxMap[PhoneNumber::Fax | PhoneNumber::Home] << "privatefax" << "privatefax2";
// phone number mapping for OX (mapping partly taken from Kolab)
mPhoneNumberOxMap[PhoneNumber::Work] << "phone_business" << "phone_business2";
mPhoneNumberOxMap[PhoneNumber::Home] << "phone_home" << "phone_home2";
mPhoneNumberOxMap[PhoneNumber::Cell] << "mobile1"<< "mobile2";
mPhoneNumberOxMap[PhoneNumber::Fax | PhoneNumber::Work] << "fax_business";
mPhoneNumberOxMap[PhoneNumber::Fax | PhoneNumber::Home] << "fax_home";
mPhoneNumberOxMap[PhoneNumber::Fax] << "fax_other";
mPhoneNumberOxMap[PhoneNumber::Car] << "phone_car";
mPhoneNumberOxMap[PhoneNumber::Isdn] << "isdn";
mPhoneNumberOxMap[PhoneNumber::Pager] << "pager";
mPhoneNumberOxMap[PhoneNumber::Pref] << "primary";
mPhoneNumberOxMap[PhoneNumber::Voice] << "callback";
mPhoneNumberOxMap[PhoneNumber::Video] << "radio";
mPhoneNumberOxMap[PhoneNumber::Bbs] << "tty_tdd";
mPhoneNumberOxMap[PhoneNumber::Modem] << "telex";
mPhoneNumberOxMap[PhoneNumber::Pcs] << "phone_assistant";
mPhoneNumberOxMap[PhoneNumber::Msg] << "phone_company";
}
ResourceSlox::~ResourceSlox()
{
kdDebug() << "KABC::~ResourceSlox()" << endl;
if ( mDownloadJob ) mDownloadJob->kill();
delete mPrefs;
kdDebug() << "KABC::~ResourceSlox() done" << endl;
}
void ResourceSlox::readConfig( const KConfig * )
{
mPrefs->readConfig();
}
void ResourceSlox::writeConfig( KConfig *config )
{
kdDebug() << "ResourceSlox::writeConfig() " << endl;
kdDebug() << mPrefs->url() << endl;
Resource::writeConfig( config );
mPrefs->writeConfig();
}
Ticket *ResourceSlox::requestSaveTicket()
{
if ( !addressBook() ) {
kdDebug(5700) << "no addressbook" << endl;
return 0;
}
return createTicket( this );
}
void ResourceSlox::releaseSaveTicket( Ticket *ticket )
{
delete ticket;
}
bool ResourceSlox::doOpen()
{
return true;
}
void ResourceSlox::doClose()
{
cancelDownload();
cancelUpload();
}
bool ResourceSlox::load()
{
kdDebug() << "KABC::ResourceSlox::load()" << endl;
#if 0
return asyncLoad();
#else
kdDebug() << "KABC::ResourceSlox::load() is a nop." << endl;
return true;
#endif
}
bool ResourceSlox::asyncLoad()
{
kdDebug() << "KABC::ResourceSlox::asyncLoad()" << endl;
if ( mDownloadJob ) {
kdDebug() << "KABC::ResourceSlox::asyncLoad(): Loading still in progress."
<< endl;
return true;
}
loadCache();
clearChanges();
KURL url = mPrefs->url();
url.setPath( "/servlet/webdav.contacts/" );
url.setUser( mPrefs->user() );
url.setPass( mPrefs->password() );
TQString lastsync = "0";
if ( mPrefs->useLastSync() ) {
TQDateTime dt = mPrefs->lastSync();
if ( dt.isValid() )
lastsync = WebdavHandler::qDateTimeToSlox( dt.addDays( -1 ) );
}
TQDomDocument doc;
TQDomElement root = WebdavHandler::addDavElement( doc, doc, "propfind" );
TQDomElement prop = WebdavHandler::addDavElement( doc, root, "prop" );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( LastSync ), lastsync );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() );
if ( type() == "ox" ) {
WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "NEW_AND_MODIFIED" );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "DELETED" );
} else
WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "all" );
kdDebug() << "REQUEST CONTACTS: \n" << doc.toString( 2 ) << endl;
mDownloadJob = KIO::davPropFind( url, doc, "0", false );
connect( mDownloadJob, TQT_SIGNAL( result( KIO::Job * ) ),
TQT_SLOT( slotResult( KIO::Job * ) ) );
connect( mDownloadJob, TQT_SIGNAL( percent( KIO::Job *, unsigned long ) ),
TQT_SLOT( slotProgress( KIO::Job *, unsigned long ) ) );
mDownloadProgress = KPIM::ProgressManager::instance()->createProgressItem(
KPIM::ProgressManager::getUniqueID(), i18n("Downloading contacts") );
connect( mDownloadProgress,
TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ),
TQT_SLOT( cancelDownload() ) );
mPrefs->setLastSync( TQDateTime::currentDateTime() );
return true;
}
void ResourceSlox::slotResult( KIO::Job *job )
{
kdDebug() << "ResourceSlox::slotResult()" << endl;
if ( job->error() ) {
job->showErrorDialog( 0 );
} else {
kdDebug() << "ResourceSlox::slotResult() success" << endl;
TQDomDocument doc = mDownloadJob->response();
mWebdavHandler.log( doc.toString( 2 ) );
TQValueList<SloxItem> items = WebdavHandler::getSloxItems( this, doc );
bool changed = false;
TQValueList<SloxItem>::ConstIterator it;
for( it = items.begin(); it != items.end(); ++it ) {
SloxItem item = *it;
TQString uid = "kresources_slox_kabc_" + item.sloxId;
if ( item.status == SloxItem::Delete ) {
TQMap<TQString,Addressee>::Iterator it;
it = mAddrMap.find( uid );
if ( it != mAddrMap.end() ) {
mAddrMap.remove( it );
changed = true;
}
} else if ( item.status == SloxItem::Create ) {
Addressee a;
a.setUid( uid );
mWebdavHandler.clearSloxAttributeStatus();
TQDomNode n;
for( n = item.domNode.firstChild(); !n.isNull(); n = n.nextSibling() ) {
TQDomElement e = n.toElement();
mWebdavHandler.parseSloxAttribute( e );
parseContactAttribute( e, a );
}
mWebdavHandler.setSloxAttributes( a );
a.setResource( this );
a.setChanged( false );
mAddrMap.replace( a.uid(), a );
// TODO: Do we need to try to associate addressees with slox accounts?
changed = true;
}
}
clearChanges();
saveCache();
}
mDownloadJob = 0;
mDownloadProgress->setComplete();
mDownloadProgress = 0;
emit loadingFinished( this );
}
void ResourceSlox::slotUploadResult( KIO::Job *job )
{
kdDebug() << "ResourceSlox::slotUploadResult()" << endl;
if ( job->error() ) {
job->showErrorDialog( 0 );
} else {
kdDebug() << "ResourceSlox::slotUploadResult() success" << endl;
TQDomDocument doc = mUploadJob->response();
kdDebug() << k_funcinfo << "Upload result: " << endl;
kdDebug() << doc.toString() << endl;
TQValueList<SloxItem> items = WebdavHandler::getSloxItems( this, doc );
TQValueList<SloxItem>::ConstIterator it;
for( it = items.begin(); it != items.end(); ++it ) {
SloxItem item = *it;
if ( !item.response.contains( "200" ) ) {
savingError( this, item.response + "\n" + item.responseDescription );
continue;
}
if ( item.status == SloxItem::New ) {
TQMap<TQString,Addressee>::Iterator search_res;
search_res = mAddrMap.find( item.clientId );
if ( search_res != mAddrMap.end() ) {
// use the id provided by the server
Addressee a = *search_res;
mAddrMap.remove( search_res );
a.setUid( "kresources_slox_kabc_" + item.sloxId );
a.setResource( this );
a.setChanged( false );
mAddrMap.replace( a.uid(), a );
saveCache();
}
}
}
}
clearChange( mUploadAddressee );
mUploadJob = 0;
mUploadProgress->setComplete();
mUploadProgress = 0;
uploadContacts();
}
void ResourceSlox::parseContactAttribute( const TQDomElement &e, Addressee &a )
{
TQString text = decodeText( e.text() );
if ( text.isEmpty() ) return;
TQString tag = e.tagName();
int pnType = 0;
if ( tag == fieldName( Birthday ) ) {
TQDateTime dt = WebdavHandler::sloxToQDateTime( text );
a.setBirthday( dt.date() );
} else if ( tag == fieldName( Role ) ) {
a.setRole( text );
} else if ( tag == "salutation" ) { // what's this in OX?
a.setPrefix( text );
} else if ( tag == fieldName( Title ) ) {
a.setTitle( text );
} else if ( tag == fieldName( Organization ) ) {
a.setOrganization( text );
} else if ( tag == fieldName( Department ) ) {
a.insertCustom( "KADDRESSBOOK", "X-Department", text );
} else if ( tag == fieldName( FamilyName ) ) {
a.setFamilyName( text );
} else if ( tag == fieldName( GivenName) ) {
a.setGivenName( text );
} else if ( tag == fieldName( SecondName ) ) {
a.setAdditionalName( text );
} else if ( tag == fieldName( DisplayName ) ) {
a.setFormattedName( text );
} else if ( tag == fieldName( Suffix ) ) {
a.setSuffix( text );
} else if ( tag == fieldName( PrimaryEmail ) ) {
a.insertEmail( text, true );
} else if ( (pnType = phoneNumberType( tag )) ) {
a.insertPhoneNumber( PhoneNumber( text, pnType ) );
} else if ( tag == fieldName( Comment ) ) {
a.setNote( text );
} else if ( tag == fieldName( SecondaryEmail1 ) || tag == fieldName( SecondaryEmail2 ) ||
tag == fieldName( SecondaryEmail3 ) ) {
a.insertEmail( text );
} else if ( tag == fieldName( Url ) ) {
a.setUrl( text );
} else if ( tag == fieldName( Image ) ) {
TQByteArray decodedPicture;
KCodecs::base64Decode( text.utf8(), decodedPicture );
a.setPhoto( Picture( TQImage( decodedPicture ) ) );
} else if ( tag == fieldName( NickName ) ) {
a.setNickName( text );
} else if ( tag == fieldName( InstantMsg ) ) {
a.insertCustom( "KADDRESSBOOK", "X-IMAddress", text );
} else if ( tag == fieldName( Office ) ) {
a.insertCustom( "KADDRESSBOOK", "X-Office", text );
} else if ( tag == fieldName( Profession ) ) {
a.insertCustom( "KADDRESSBOOK", "X-Profession", text );
} else if ( tag == fieldName( ManagersName ) ) {
a.insertCustom( "KADDRESSBOOK", "X-ManagersName", text );
} else if ( tag == fieldName( AssistantsName ) ) {
a.insertCustom( "KADDRESSBOOK", "X-AssistantsName", text );
} else if ( tag == fieldName( SpousesName ) ) {
a.insertCustom( "KADDRESSBOOK", "X-SpousesName", text );
} else if ( tag == fieldName( Anniversary ) ) {
TQDateTime dt = WebdavHandler::sloxToQDateTime( text );
a.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt.toString( Qt::ISODate ) );
} else if ( tag == fieldName( Categories ) ) {
a.setCategories( TQStringList::split( TQRegExp(",\\s*"), text ) );
} else if ( type() == "ox" ) { // FIXME: Address reading is missing for SLOX
// read addresses
Address addr;
if ( tag.startsWith( fieldName( BusinessPrefix ) ) ) {
addr = a.address( KABC::Address::Work );
} else if ( tag.startsWith( fieldName( OtherPrefix ) ) ) {
addr = a.address( 0 );
} else {
addr = a.address( KABC::Address::Home );
}
if ( tag.endsWith( fieldName( Street ) ) ) {
addr.setStreet( text );
} else if ( tag.endsWith( fieldName( PostalCode ) ) ) {
addr.setPostalCode( text );
} else if ( tag.endsWith( fieldName( City ) ) ) {
addr.setLocality( text );
} else if ( tag.endsWith( fieldName( State ) ) ) {
addr.setRegion( text );
} else if ( tag.endsWith( fieldName( Country ) ) ) {
addr.setCountry( text );
}
a.insertAddress( addr );
}
}
int ResourceSlox::phoneNumberType( const TQString &fieldName ) const
{
TQMap<int, TQStringList> pnmap;
if ( type() == "ox" )
pnmap = mPhoneNumberOxMap;
else
pnmap = mPhoneNumberSloxMap;
TQMap<int, TQStringList>::ConstIterator it;
for ( it = pnmap.begin(); it != pnmap.end(); ++it ) {
TQStringList l = it.data();
TQStringList::ConstIterator it2;
for ( it2 = l.begin(); it2 != l.end(); ++it2 )
if ( (*it2) == fieldName )
return it.key();
}
return 0;
}
bool ResourceSlox::save( Ticket* )
{
kdDebug() << k_funcinfo << endl;
if ( readOnly() || !hasChanges() || type() != "ox" ) {
emit savingFinished( this );
return true;
}
if ( mDownloadJob ) {
kdWarning() << k_funcinfo << "download still in progress" << endl;
return false;
}
if ( mUploadJob ) {
kdWarning() << k_funcinfo << "upload still in progress" << endl;
return false;
}
saveCache();
uploadContacts();
return true;
}
bool ResourceSlox::asyncSave( Ticket* )
{
return false; // readonly
}
void ResourceSlox::uploadContacts()
{
TQDomDocument doc;
TQDomElement root = WebdavHandler::addDavElement( doc, doc, "propertyupdate" );
TQDomElement set = WebdavHandler::addDavElement( doc, root, "set" );
TQDomElement prop = WebdavHandler::addDavElement( doc, set, "prop" );
bool isDelete = false;
KABC::Addressee::List addedAddr = addedAddressees();
KABC::Addressee::List changedAddr = changedAddressees();
KABC::Addressee::List deletedAddr = deletedAddressees();
if ( !addedAddr.isEmpty() ) {
mUploadAddressee = addedAddr.first();
WebdavHandler::addSloxElement( this, doc, prop, fieldName( ClientId ), mUploadAddressee.uid() );
} else if ( !changedAddr.isEmpty() ) {
mUploadAddressee = changedAddr.first();
WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ),
mUploadAddressee.uid().remove( 0, sizeof("kresources_slox_kabc_") - 1) );
} else if ( !deletedAddr.isEmpty() ) {
mUploadAddressee = deletedAddr.first();
isDelete = true;
} else {
kdDebug() << k_funcinfo << "Upload finished." << endl;
emit savingFinished( this );
return;
}
if ( !isDelete ) {
createAddresseeFields( doc, prop, mUploadAddressee );
} else {
TQString tmp_uid = mUploadAddressee.uid().remove( 0, sizeof("kresources_slox_kabc_") - 1); // remove prefix from uid
WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), tmp_uid );
WebdavHandler::addSloxElement( this, doc, prop, "method", "DELETE" );
}
kdDebug() << k_funcinfo << doc.toString() << endl;
KURL url = mPrefs->url();
url.setPath( "/servlet/webdav.contacts/" );
url.setUser( mPrefs->user() );
url.setPass( mPrefs->password() );
mUploadJob = KIO::davPropPatch( url, doc, false );
connect( mUploadJob, TQT_SIGNAL( result( KIO::Job * ) ),
TQT_SLOT( slotUploadResult( KIO::Job * ) ) );
connect( mUploadJob, TQT_SIGNAL( percent( KIO::Job *, unsigned long ) ),
TQT_SLOT( slotProgress( KIO::Job *, unsigned long ) ) );
mUploadProgress = KPIM::ProgressManager::instance()->createProgressItem(
KPIM::ProgressManager::getUniqueID(), i18n("Uploading contacts") );
connect( mUploadProgress,
TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ),
TQT_SLOT( cancelUpload() ) );
}
void ResourceSlox::createAddresseeFields( TQDomDocument &doc, TQDomElement &prop,
const Addressee &a )
{
// choose addressbook
WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() );
// person
WebdavHandler::addSloxElement( this, doc, prop, fieldName( GivenName ), a.givenName() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( FamilyName ), a.familyName() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Title ), a.title() );
if ( !a.birthday().isNull() )
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ),
WebdavHandler::qDateTimeToSlox( a.birthday() ) );
else
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Birthday ) );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Role ), a.role() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Department ),
a.custom( "KADDRESSBOOK", "X-Department" ) );
if ( type() == "ox" ) { // OX only fields
WebdavHandler::addSloxElement( this, doc, prop, fieldName( DisplayName ), a.formattedName() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondName ), a.additionalName() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Suffix ), a.suffix() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Organization ), a.organization() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( NickName ), a.nickName() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( InstantMsg ),
a.custom( "KADDRESSBOOK", "X-IMAddress" ) );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Office ),
a.custom( "KADDRESSBOOK", "X-Office" ) );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Profession ),
a.custom( "KADDRESSBOOK", "X-Profession" ) );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( ManagersName ),
a.custom( "KADDRESSBOOK", "X-ManagersName" ) );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( AssistantsName ),
a.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( SpousesName ),
a.custom( "KADDRESSBOOK", "X-SpousesName" ) );
TQString anniversary = a.custom( "KADDRESSBOOK", "X-Anniversary" );
if ( !anniversary.isEmpty() )
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ),
WebdavHandler::qDateTimeToSlox( TQDateTime::fromString( anniversary, Qt::ISODate ).date() ) );
else
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Anniversary ) );
}
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Url ), a.url().url() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Comment ), a.note() );
WebdavHandler::addSloxElement( this, doc, prop, fieldName( Categories ), a.categories().join( ", " ) );
// emails
TQStringList email_list = a.emails();
TQStringList::const_iterator emails_it = email_list.begin();
if ( emails_it != email_list.end() )
WebdavHandler::addSloxElement( this, doc, prop, fieldName( PrimaryEmail ), *(emails_it++) );
if ( emails_it != email_list.end() )
WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail1 ), *(emails_it++) );
if ( emails_it != email_list.end() )
WebdavHandler::addSloxElement( this, doc, prop, fieldName( SecondaryEmail2 ), *(emails_it++) );
// phone numbers
PhoneNumber::List pnlist = a.phoneNumbers();
TQMap<int, TQStringList> pnSaveMap;
if ( type() == "ox" )
pnSaveMap = mPhoneNumberOxMap;
else
pnSaveMap = mPhoneNumberSloxMap;
for ( PhoneNumber::List::ConstIterator it = pnlist.begin() ; it != pnlist.end(); ++it ) {
if ( pnSaveMap.contains( (*it).type() ) ) {
TQStringList l = pnSaveMap[(*it).type()];
TQString fn = l.first();
l.remove( l.begin() );
if ( !l.isEmpty() )
pnSaveMap[(*it).type()] = l;
else
pnSaveMap.remove( (*it).type() );
WebdavHandler::addSloxElement( this, doc, prop, fn, (*it).number() );
} else
kdDebug() << k_funcinfo << "Can't save phone number " << (*it).number() << " of type " << (*it).type() << endl;
}
// send empty fields for the remaining ohone number fields
// it's not possible to delete phone numbers otherwise
for ( TQMap<int, TQStringList>::ConstIterator it = pnSaveMap.begin(); it != pnSaveMap.end(); ++it ) {
TQStringList l = it.data();
for ( TQStringList::ConstIterator it2 = l.begin(); it2 != l.end(); ++it2 )
WebdavHandler::addSloxElement( this, doc, prop, (*it2) );
}
// write addresses
createAddressFields( doc, prop, fieldName( HomePrefix ), a.address( KABC::Address::Home ) );
if ( type() == "ox" ) {
createAddressFields( doc, prop, fieldName( BusinessPrefix ), a.address( KABC::Address::Work ) );
createAddressFields( doc, prop, fieldName( OtherPrefix ), a.address( 0 ) );
}
}
void KABC::ResourceSlox::createAddressFields( TQDomDocument &doc, TQDomElement &parent,
const TQString &prefix, const KABC::Address &addr )
{
WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Street ), addr.street() );
WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( PostalCode ), addr.postalCode() );
WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( City ), addr.locality() );
WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( State ), addr.region() );
WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Country ), addr.country() );
}
void ResourceSlox::slotProgress( KIO::Job *job, unsigned long percent )
{
if ( mDownloadProgress && job == mDownloadJob )
mDownloadProgress->setProgress( percent );
else if ( mUploadProgress && job == mUploadJob )
mUploadProgress->setProgress( percent );
}
void ResourceSlox::cancelDownload()
{
if ( mDownloadJob ) mDownloadJob->kill();
mDownloadJob = 0;
if ( mDownloadProgress ) mDownloadProgress->setComplete();
mDownloadProgress = 0;
}
void ResourceSlox::cancelUpload()
{
if ( mUploadJob ) mUploadJob->kill();
mUploadJob = 0;
if ( mUploadProgress ) mUploadProgress->setComplete();
mUploadProgress = 0;
}
void ResourceSlox::setReadOnly( bool b )
{
if ( type() == "ox" )
KABC::Resource::setReadOnly( b );
else
KABC::Resource::setReadOnly( true );
}
bool ResourceSlox::readOnly() const
{
if ( type() == "ox" )
return KABC::Resource::readOnly();
else
return true;
}
#include "kabcresourceslox.moc"
|