summaryrefslogtreecommitdiffabout
path: root/kabc/addressee.cpp
authorzautrix <zautrix>2004-09-21 07:05:01 (UTC)
committer zautrix <zautrix>2004-09-21 07:05:01 (UTC)
commit434ddaa08e0a650422ef271332a1d11879028095 (patch) (unidiff)
treee4f229120d8bfa9febb7ab123b1311329f0e6aa4 /kabc/addressee.cpp
parented49c55dac215ac2ed9286ebfc36e5a19417f0bb (diff)
downloadkdepimpi-434ddaa08e0a650422ef271332a1d11879028095.zip
kdepimpi-434ddaa08e0a650422ef271332a1d11879028095.tar.gz
kdepimpi-434ddaa08e0a650422ef271332a1d11879028095.tar.bz2
DTM sync fixes
Diffstat (limited to 'kabc/addressee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index e241281..31ce1d6 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,173 +1,175 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern );
46 48
47struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
48{ 50{
49 QString uid; 51 QString uid;
50 QString name; 52 QString name;
51 QString formattedName; 53 QString formattedName;
52 QString familyName; 54 QString familyName;
53 QString givenName; 55 QString givenName;
54 QString additionalName; 56 QString additionalName;
55 QString prefix; 57 QString prefix;
56 QString suffix; 58 QString suffix;
57 QString nickName; 59 QString nickName;
58 QDateTime birthday; 60 QDateTime birthday;
59 QString mailer; 61 QString mailer;
60 TimeZone timeZone; 62 TimeZone timeZone;
61 Geo geo; 63 Geo geo;
62 QString title; 64 QString title;
63 QString role; 65 QString role;
64 QString organization; 66 QString organization;
65 QString note; 67 QString note;
66 QString productId; 68 QString productId;
67 QDateTime revision; 69 QDateTime revision;
68 QString sortString; 70 QString sortString;
69 QString externalUID; 71 QString externalUID;
70 QString originalExternalUID; 72 QString originalExternalUID;
71 KURL url; 73 KURL url;
72 Secrecy secrecy; 74 Secrecy secrecy;
73 Picture logo; 75 Picture logo;
74 Picture photo; 76 Picture photo;
75 Sound sound; 77 Sound sound;
76 Agent agent; 78 Agent agent;
77 QString mExternalId; 79 QString mExternalId;
78 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
79 Address::List addresses; 81 Address::List addresses;
80 Key::List keys; 82 Key::List keys;
81 QStringList emails; 83 QStringList emails;
82 QStringList categories; 84 QStringList categories;
83 QStringList custom; 85 QStringList custom;
84 int mTempSyncStat; 86 int mTempSyncStat;
85 Resource *resource; 87 Resource *resource;
86 88
87 bool empty :1; 89 bool empty :1;
88 bool changed :1; 90 bool changed :1;
89}; 91};
90 92
91Addressee::Addressee() 93Addressee::Addressee()
92{ 94{
93 mData = new AddresseeData; 95 mData = new AddresseeData;
94 mData->empty = true; 96 mData->empty = true;
95 mData->changed = false; 97 mData->changed = false;
96 mData->resource = 0; 98 mData->resource = 0;
97 mData->mExternalId = ":"; 99 mData->mExternalId = ":";
98 mData->revision = QDateTime ( QDate( 2003,1,1)); 100 mData->revision = QDateTime ( QDate( 2003,1,1));
99 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 101 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
100} 102}
101 103
102Addressee::~Addressee() 104Addressee::~Addressee()
103{ 105{
104} 106}
105 107
106Addressee::Addressee( const Addressee &a ) 108Addressee::Addressee( const Addressee &a )
107{ 109{
108 mData = a.mData; 110 mData = a.mData;
109} 111}
110 112
111Addressee &Addressee::operator=( const Addressee &a ) 113Addressee &Addressee::operator=( const Addressee &a )
112{ 114{
113 mData = a.mData; 115 mData = a.mData;
114 return (*this); 116 return (*this);
115} 117}
116 118
117Addressee Addressee::copy() 119Addressee Addressee::copy()
118{ 120{
119 Addressee a; 121 Addressee a;
120 *(a.mData) = *mData; 122 *(a.mData) = *mData;
121 return a; 123 return a;
122} 124}
123 125
124void Addressee::detach() 126void Addressee::detach()
125{ 127{
126 if ( mData.count() == 1 ) return; 128 if ( mData.count() == 1 ) return;
127 *this = copy(); 129 *this = copy();
128} 130}
129 131
130bool Addressee::operator==( const Addressee &a ) const 132bool Addressee::operator==( const Addressee &a ) const
131{ 133{
132 if ( uid() != a.uid() ) return false; 134 if ( uid() != a.uid() ) return false;
133 if ( mData->name != a.mData->name ) return false; 135 if ( mData->name != a.mData->name ) return false;
134 if ( mData->formattedName != a.mData->formattedName ) return false; 136 if ( mData->formattedName != a.mData->formattedName ) return false;
135 if ( mData->familyName != a.mData->familyName ) return false; 137 if ( mData->familyName != a.mData->familyName ) return false;
136 if ( mData->givenName != a.mData->givenName ) return false; 138 if ( mData->givenName != a.mData->givenName ) return false;
137 if ( mData->additionalName != a.mData->additionalName ) return false; 139 if ( mData->additionalName != a.mData->additionalName ) return false;
138 if ( mData->prefix != a.mData->prefix ) return false; 140 if ( mData->prefix != a.mData->prefix ) return false;
139 if ( mData->suffix != a.mData->suffix ) return false; 141 if ( mData->suffix != a.mData->suffix ) return false;
140 if ( mData->nickName != a.mData->nickName ) return false; 142 if ( mData->nickName != a.mData->nickName ) return false;
141 if ( mData->birthday != a.mData->birthday ) return false; 143 if ( mData->birthday != a.mData->birthday ) return false;
142 if ( mData->mailer != a.mData->mailer ) return false; 144 if ( mData->mailer != a.mData->mailer ) return false;
143 if ( mData->timeZone != a.mData->timeZone ) return false; 145 if ( mData->timeZone != a.mData->timeZone ) return false;
144 if ( mData->geo != a.mData->geo ) return false; 146 if ( mData->geo != a.mData->geo ) return false;
145 if ( mData->title != a.mData->title ) return false; 147 if ( mData->title != a.mData->title ) return false;
146 if ( mData->role != a.mData->role ) return false; 148 if ( mData->role != a.mData->role ) return false;
147 if ( mData->organization != a.mData->organization ) return false; 149 if ( mData->organization != a.mData->organization ) return false;
148 if ( mData->note != a.mData->note ) return false; 150 if ( mData->note != a.mData->note ) return false;
149 if ( mData->productId != a.mData->productId ) return false; 151 if ( mData->productId != a.mData->productId ) return false;
150 //if ( mData->revision != a.mData->revision ) return false; 152 //if ( mData->revision != a.mData->revision ) return false;
151 if ( mData->sortString != a.mData->sortString ) return false; 153 if ( mData->sortString != a.mData->sortString ) return false;
152 if ( mData->secrecy != a.mData->secrecy ) return false; 154 if ( mData->secrecy != a.mData->secrecy ) return false;
153 if ( mData->logo != a.mData->logo ) return false; 155 if ( mData->logo != a.mData->logo ) return false;
154 if ( mData->photo != a.mData->photo ) return false; 156 if ( mData->photo != a.mData->photo ) return false;
155 if ( mData->sound != a.mData->sound ) return false; 157 if ( mData->sound != a.mData->sound ) return false;
156 if ( mData->agent != a.mData->agent ) return false; 158 if ( mData->agent != a.mData->agent ) return false;
157 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 159 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
158 ( mData->url != a.mData->url ) ) return false; 160 ( mData->url != a.mData->url ) ) return false;
159 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 161 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
160 if ( mData->addresses != a.mData->addresses ) return false; 162 if ( mData->addresses != a.mData->addresses ) return false;
161 if ( mData->keys != a.mData->keys ) return false; 163 if ( mData->keys != a.mData->keys ) return false;
162 if ( mData->emails != a.mData->emails ) return false; 164 if ( mData->emails != a.mData->emails ) return false;
163 if ( mData->categories != a.mData->categories ) return false; 165 if ( mData->categories != a.mData->categories ) return false;
164 if ( mData->custom != a.mData->custom ) return false; 166 if ( mData->custom != a.mData->custom ) return false;
165 167
166 return true; 168 return true;
167} 169}
168 170
169bool Addressee::operator!=( const Addressee &a ) const 171bool Addressee::operator!=( const Addressee &a ) const
170{ 172{
171 return !( a == *this ); 173 return !( a == *this );
172} 174}
173 175
@@ -256,270 +258,270 @@ void Addressee::computeCsum(const QString &dev)
256 t = mData->categories; 258 t = mData->categories;
257 t.sort(); 259 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 260 for ( iii = 0; iii < t.count(); ++iii)
259 l.append( t[iii] ); 261 l.append( t[iii] );
260 t = mData->custom; 262 t = mData->custom;
261 t.sort(); 263 t.sort();
262 for ( iii = 0; iii < t.count(); ++iii) 264 for ( iii = 0; iii < t.count(); ++iii)
263 l.append( t[iii] ); 265 l.append( t[iii] );
264 KABC::Address::List::Iterator addressIter; 266 KABC::Address::List::Iterator addressIter;
265 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
266 ++addressIter ) { 268 ++addressIter ) {
267 t = (*addressIter).asList(); 269 t = (*addressIter).asList();
268 t.sort(); 270 t.sort();
269 for ( iii = 0; iii < t.count(); ++iii) 271 for ( iii = 0; iii < t.count(); ++iii)
270 l.append( t[iii] ); 272 l.append( t[iii] );
271 } 273 }
272 uint cs = getCsum4List(l); 274 uint cs = getCsum4List(l);
273 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 275 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
274 setCsum( dev, QString::number (cs )); 276 setCsum( dev, QString::number (cs ));
275} 277}
276 278
277void Addressee::mergeContact( const Addressee& ad ) 279void Addressee::mergeContact( const Addressee& ad )
278{ 280{
279 281
280 detach(); 282 detach();
281 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 283 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
282 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 284 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
283 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 285 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
284 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 286 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
285 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 287 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
286 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 288 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
287 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 289 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
288 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 290 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
289 if ( !mData->birthday.isValid() ) 291 if ( !mData->birthday.isValid() )
290 if ( ad.mData->birthday.isValid()) 292 if ( ad.mData->birthday.isValid())
291 mData->birthday = ad.mData->birthday; 293 mData->birthday = ad.mData->birthday;
292 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 294 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
293 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 295 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
294 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 296 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
295 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 297 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
296 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 298 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
297 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 299 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
298 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 300 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
299 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 301 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
300 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 302 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
301 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 303 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
302 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 304 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
303 305
304 // pending: 306 // pending:
305 // merging phonenumbers 307 // merging phonenumbers
306 // merging addresses 308 // merging addresses
307 // merging emails; 309 // merging emails;
308 // merging categories; 310 // merging categories;
309 // merging custom; 311 // merging custom;
310 // merging keys 312 // merging keys
311 qDebug("merge contact %s ", ad.uid().latin1()); 313 qDebug("merge contact %s ", ad.uid().latin1());
312 setUid( ad.uid() ); 314 setUid( ad.uid() );
313} 315}
314 316
315void Addressee::removeID(const QString &prof) 317void Addressee::removeID(const QString &prof)
316{ 318{
317 detach(); 319 detach();
318 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 320 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
319 321
320} 322}
321void Addressee::setID( const QString & prof , const QString & id ) 323void Addressee::setID( const QString & prof , const QString & id )
322{ 324{
323 detach(); 325 detach();
324 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 326 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
325 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 327 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
326} 328}
327void Addressee::setTempSyncStat( int id ) 329void Addressee::setTempSyncStat( int id )
328{ 330{
329 if ( mData->mTempSyncStat == id ) return; 331 if ( mData->mTempSyncStat == id ) return;
330 detach(); 332 detach();
331 mData->mTempSyncStat = id; 333 mData->mTempSyncStat = id;
332} 334}
333int Addressee::tempSyncStat() const 335int Addressee::tempSyncStat() const
334{ 336{
335 return mData->mTempSyncStat; 337 return mData->mTempSyncStat;
336} 338}
337 339
338QString Addressee::getID( const QString & prof) 340QString Addressee::getID( const QString & prof)
339{ 341{
340 return KIdManager::getId ( mData->mExternalId, prof ); 342 return KIdManager::getId ( mData->mExternalId, prof );
341} 343}
342 344
343void Addressee::setCsum( const QString & prof , const QString & id ) 345void Addressee::setCsum( const QString & prof , const QString & id )
344{ 346{
345 detach(); 347 detach();
346 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 348 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
347 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 349 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
348 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 350 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
349} 351}
350 352
351QString Addressee::getCsum( const QString & prof) 353QString Addressee::getCsum( const QString & prof)
352{ 354{
353 return KIdManager::getCsum ( mData->mExternalId, prof ); 355 return KIdManager::getCsum ( mData->mExternalId, prof );
354} 356}
355 357
356void Addressee::setIDStr( const QString & s ) 358void Addressee::setIDStr( const QString & s )
357{ 359{
358 detach(); 360 detach();
359 mData->mExternalId = s; 361 mData->mExternalId = s;
360} 362}
361 363
362QString Addressee::IDStr() const 364QString Addressee::IDStr() const
363{ 365{
364 return mData->mExternalId; 366 return mData->mExternalId;
365} 367}
366 368
367void Addressee::setExternalUID( const QString &id ) 369void Addressee::setExternalUID( const QString &id )
368{ 370{
369 if ( id == mData->externalUID ) return; 371 if ( id == mData->externalUID ) return;
370 detach(); 372 detach();
371 mData->empty = false; 373 mData->empty = false;
372 mData->externalUID = id; 374 mData->externalUID = id;
373} 375}
374 376
375QString Addressee::externalUID() const 377QString Addressee::externalUID() const
376{ 378{
377 return mData->externalUID; 379 return mData->externalUID;
378} 380}
379void Addressee::setOriginalExternalUID( const QString &id ) 381void Addressee::setOriginalExternalUID( const QString &id )
380{ 382{
381 if ( id == mData->originalExternalUID ) return; 383 if ( id == mData->originalExternalUID ) return;
382 detach(); 384 detach();
383 mData->empty = false; 385 mData->empty = false;
384 qDebug("*******Set orig uid %s ", id.latin1()); 386 //qDebug("*******Set orig uid %s ", id.latin1());
385 mData->originalExternalUID = id; 387 mData->originalExternalUID = id;
386} 388}
387 389
388QString Addressee::originalExternalUID() const 390QString Addressee::originalExternalUID() const
389{ 391{
390 return mData->originalExternalUID; 392 return mData->originalExternalUID;
391} 393}
392 394
393void Addressee::setUid( const QString &id ) 395void Addressee::setUid( const QString &id )
394{ 396{
395 if ( id == mData->uid ) return; 397 if ( id == mData->uid ) return;
396 detach(); 398 detach();
397 qDebug("****setuid %s ", id.latin1()); 399 //qDebug("****setuid %s ", id.latin1());
398 mData->empty = false; 400 mData->empty = false;
399 mData->uid = id; 401 mData->uid = id;
400} 402}
401 403
402QString Addressee::uid() const 404QString Addressee::uid() const
403{ 405{
404 if ( mData->uid.isEmpty() ) 406 if ( mData->uid.isEmpty() )
405 mData->uid = KApplication::randomString( 10 ); 407 mData->uid = KApplication::randomString( 10 );
406 408
407 return mData->uid; 409 return mData->uid;
408} 410}
409 411
410QString Addressee::uidLabel() 412QString Addressee::uidLabel()
411{ 413{
412 return i18n("Unique Identifier"); 414 return i18n("Unique Identifier");
413} 415}
414 416
415void Addressee::setName( const QString &name ) 417void Addressee::setName( const QString &name )
416{ 418{
417 if ( name == mData->name ) return; 419 if ( name == mData->name ) return;
418 detach(); 420 detach();
419 mData->empty = false; 421 mData->empty = false;
420 mData->name = name; 422 mData->name = name;
421} 423}
422 424
423QString Addressee::name() const 425QString Addressee::name() const
424{ 426{
425 return mData->name; 427 return mData->name;
426} 428}
427 429
428QString Addressee::nameLabel() 430QString Addressee::nameLabel()
429{ 431{
430 return i18n("Name"); 432 return i18n("Name");
431} 433}
432 434
433 435
434void Addressee::setFormattedName( const QString &formattedName ) 436void Addressee::setFormattedName( const QString &formattedName )
435{ 437{
436 if ( formattedName == mData->formattedName ) return; 438 if ( formattedName == mData->formattedName ) return;
437 detach(); 439 detach();
438 mData->empty = false; 440 mData->empty = false;
439 mData->formattedName = formattedName; 441 mData->formattedName = formattedName;
440} 442}
441 443
442QString Addressee::formattedName() const 444QString Addressee::formattedName() const
443{ 445{
444 return mData->formattedName; 446 return mData->formattedName;
445} 447}
446 448
447QString Addressee::formattedNameLabel() 449QString Addressee::formattedNameLabel()
448{ 450{
449 return i18n("Formatted Name"); 451 return i18n("Formatted Name");
450} 452}
451 453
452 454
453void Addressee::setFamilyName( const QString &familyName ) 455void Addressee::setFamilyName( const QString &familyName )
454{ 456{
455 if ( familyName == mData->familyName ) return; 457 if ( familyName == mData->familyName ) return;
456 detach(); 458 detach();
457 mData->empty = false; 459 mData->empty = false;
458 mData->familyName = familyName; 460 mData->familyName = familyName;
459} 461}
460 462
461QString Addressee::familyName() const 463QString Addressee::familyName() const
462{ 464{
463 return mData->familyName; 465 return mData->familyName;
464} 466}
465 467
466QString Addressee::familyNameLabel() 468QString Addressee::familyNameLabel()
467{ 469{
468 return i18n("Family Name"); 470 return i18n("Family Name");
469} 471}
470 472
471 473
472void Addressee::setGivenName( const QString &givenName ) 474void Addressee::setGivenName( const QString &givenName )
473{ 475{
474 if ( givenName == mData->givenName ) return; 476 if ( givenName == mData->givenName ) return;
475 detach(); 477 detach();
476 mData->empty = false; 478 mData->empty = false;
477 mData->givenName = givenName; 479 mData->givenName = givenName;
478} 480}
479 481
480QString Addressee::givenName() const 482QString Addressee::givenName() const
481{ 483{
482 return mData->givenName; 484 return mData->givenName;
483} 485}
484 486
485QString Addressee::givenNameLabel() 487QString Addressee::givenNameLabel()
486{ 488{
487 return i18n("Given Name"); 489 return i18n("Given Name");
488} 490}
489 491
490 492
491void Addressee::setAdditionalName( const QString &additionalName ) 493void Addressee::setAdditionalName( const QString &additionalName )
492{ 494{
493 if ( additionalName == mData->additionalName ) return; 495 if ( additionalName == mData->additionalName ) return;
494 detach(); 496 detach();
495 mData->empty = false; 497 mData->empty = false;
496 mData->additionalName = additionalName; 498 mData->additionalName = additionalName;
497} 499}
498 500
499QString Addressee::additionalName() const 501QString Addressee::additionalName() const
500{ 502{
501 return mData->additionalName; 503 return mData->additionalName;
502} 504}
503 505
504QString Addressee::additionalNameLabel() 506QString Addressee::additionalNameLabel()
505{ 507{
506 return i18n("Additional Names"); 508 return i18n("Additional Names");
507} 509}
508 510
509 511
510void Addressee::setPrefix( const QString &prefix ) 512void Addressee::setPrefix( const QString &prefix )
511{ 513{
512 if ( prefix == mData->prefix ) return; 514 if ( prefix == mData->prefix ) return;
513 detach(); 515 detach();
514 mData->empty = false; 516 mData->empty = false;
515 mData->prefix = prefix; 517 mData->prefix = prefix;
516} 518}
517 519
518QString Addressee::prefix() const 520QString Addressee::prefix() const
519{ 521{
520 return mData->prefix; 522 return mData->prefix;
521} 523}
522 524
523QString Addressee::prefixLabel() 525QString Addressee::prefixLabel()
524{ 526{
525 return i18n("Honorific Prefixes"); 527 return i18n("Honorific Prefixes");
@@ -1165,494 +1167,494 @@ void Addressee::setNameFromString( const QString &str )
1165 leftOffset++; 1167 leftOffset++;
1166 } 1168 }
1167 1169
1168 QString additionalName; 1170 QString additionalName;
1169 while ( leftOffset < rightOffset ) { 1171 while ( leftOffset < rightOffset ) {
1170 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1172 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1171 leftOffset++; 1173 leftOffset++;
1172 } 1174 }
1173 setAdditionalName( additionalName ); 1175 setAdditionalName( additionalName );
1174 } 1176 }
1175} 1177}
1176 1178
1177QString Addressee::realName() const 1179QString Addressee::realName() const
1178{ 1180{
1179 if ( !formattedName().isEmpty() ) 1181 if ( !formattedName().isEmpty() )
1180 return formattedName(); 1182 return formattedName();
1181 1183
1182 QString n = assembledName(); 1184 QString n = assembledName();
1183 1185
1184 if ( n.isEmpty() ) 1186 if ( n.isEmpty() )
1185 n = name(); 1187 n = name();
1186 1188
1187 return n; 1189 return n;
1188} 1190}
1189 1191
1190QString Addressee::assembledName() const 1192QString Addressee::assembledName() const
1191{ 1193{
1192 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1194 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1193 familyName() + " " + suffix(); 1195 familyName() + " " + suffix();
1194 1196
1195 return name.simplifyWhiteSpace(); 1197 return name.simplifyWhiteSpace();
1196} 1198}
1197 1199
1198QString Addressee::fullEmail( const QString &email ) const 1200QString Addressee::fullEmail( const QString &email ) const
1199{ 1201{
1200 QString e; 1202 QString e;
1201 if ( email.isNull() ) { 1203 if ( email.isNull() ) {
1202 e = preferredEmail(); 1204 e = preferredEmail();
1203 } else { 1205 } else {
1204 e = email; 1206 e = email;
1205 } 1207 }
1206 if ( e.isEmpty() ) return QString::null; 1208 if ( e.isEmpty() ) return QString::null;
1207 1209
1208 QString text; 1210 QString text;
1209 if ( realName().isEmpty() ) 1211 if ( realName().isEmpty() )
1210 text = e; 1212 text = e;
1211 else 1213 else
1212 text = assembledName() + " <" + e + ">"; 1214 text = assembledName() + " <" + e + ">";
1213 1215
1214 return text; 1216 return text;
1215} 1217}
1216 1218
1217void Addressee::insertEmail( const QString &email, bool preferred ) 1219void Addressee::insertEmail( const QString &email, bool preferred )
1218{ 1220{
1219 detach(); 1221 detach();
1220 1222
1221 QStringList::Iterator it = mData->emails.find( email ); 1223 QStringList::Iterator it = mData->emails.find( email );
1222 1224
1223 if ( it != mData->emails.end() ) { 1225 if ( it != mData->emails.end() ) {
1224 if ( !preferred || it == mData->emails.begin() ) return; 1226 if ( !preferred || it == mData->emails.begin() ) return;
1225 mData->emails.remove( it ); 1227 mData->emails.remove( it );
1226 mData->emails.prepend( email ); 1228 mData->emails.prepend( email );
1227 } else { 1229 } else {
1228 if ( preferred ) { 1230 if ( preferred ) {
1229 mData->emails.prepend( email ); 1231 mData->emails.prepend( email );
1230 } else { 1232 } else {
1231 mData->emails.append( email ); 1233 mData->emails.append( email );
1232 } 1234 }
1233 } 1235 }
1234} 1236}
1235 1237
1236void Addressee::removeEmail( const QString &email ) 1238void Addressee::removeEmail( const QString &email )
1237{ 1239{
1238 detach(); 1240 detach();
1239 1241
1240 QStringList::Iterator it = mData->emails.find( email ); 1242 QStringList::Iterator it = mData->emails.find( email );
1241 if ( it == mData->emails.end() ) return; 1243 if ( it == mData->emails.end() ) return;
1242 1244
1243 mData->emails.remove( it ); 1245 mData->emails.remove( it );
1244} 1246}
1245 1247
1246QString Addressee::preferredEmail() const 1248QString Addressee::preferredEmail() const
1247{ 1249{
1248 if ( mData->emails.count() == 0 ) return QString::null; 1250 if ( mData->emails.count() == 0 ) return QString::null;
1249 else return mData->emails.first(); 1251 else return mData->emails.first();
1250} 1252}
1251 1253
1252QStringList Addressee::emails() const 1254QStringList Addressee::emails() const
1253{ 1255{
1254 return mData->emails; 1256 return mData->emails;
1255} 1257}
1256void Addressee::setEmails( const QStringList& emails ) { 1258void Addressee::setEmails( const QStringList& emails ) {
1257 detach(); 1259 detach();
1258 mData->emails = emails; 1260 mData->emails = emails;
1259} 1261}
1260void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1262void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1261{ 1263{
1262 detach(); 1264 detach();
1263 mData->empty = false; 1265 mData->empty = false;
1264 1266
1265 PhoneNumber::List::Iterator it; 1267 PhoneNumber::List::Iterator it;
1266 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1268 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1267 if ( (*it).id() == phoneNumber.id() ) { 1269 if ( (*it).id() == phoneNumber.id() ) {
1268 *it = phoneNumber; 1270 *it = phoneNumber;
1269 return; 1271 return;
1270 } 1272 }
1271 } 1273 }
1272 mData->phoneNumbers.append( phoneNumber ); 1274 mData->phoneNumbers.append( phoneNumber );
1273} 1275}
1274 1276
1275void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1277void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1276{ 1278{
1277 detach(); 1279 detach();
1278 1280
1279 PhoneNumber::List::Iterator it; 1281 PhoneNumber::List::Iterator it;
1280 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1282 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1281 if ( (*it).id() == phoneNumber.id() ) { 1283 if ( (*it).id() == phoneNumber.id() ) {
1282 mData->phoneNumbers.remove( it ); 1284 mData->phoneNumbers.remove( it );
1283 return; 1285 return;
1284 } 1286 }
1285 } 1287 }
1286} 1288}
1287 1289
1288PhoneNumber Addressee::phoneNumber( int type ) const 1290PhoneNumber Addressee::phoneNumber( int type ) const
1289{ 1291{
1290 PhoneNumber phoneNumber( "", type ); 1292 PhoneNumber phoneNumber( "", type );
1291 PhoneNumber::List::ConstIterator it; 1293 PhoneNumber::List::ConstIterator it;
1292 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1294 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1293 if ( matchBinaryPattern( (*it).type(), type ) ) { 1295 if ( matchBinaryPatternP( (*it).type(), type ) ) {
1294 if ( (*it).type() & PhoneNumber::Pref ) 1296 if ( (*it).type() & PhoneNumber::Pref )
1295 return (*it); 1297 return (*it);
1296 else if ( phoneNumber.number().isEmpty() ) 1298 else if ( phoneNumber.number().isEmpty() )
1297 phoneNumber = (*it); 1299 phoneNumber = (*it);
1298 } 1300 }
1299 } 1301 }
1300 1302
1301 return phoneNumber; 1303 return phoneNumber;
1302} 1304}
1303 1305
1304PhoneNumber::List Addressee::phoneNumbers() const 1306PhoneNumber::List Addressee::phoneNumbers() const
1305{ 1307{
1306 return mData->phoneNumbers; 1308 return mData->phoneNumbers;
1307} 1309}
1308 1310
1309PhoneNumber::List Addressee::phoneNumbers( int type ) const 1311PhoneNumber::List Addressee::phoneNumbers( int type ) const
1310{ 1312{
1311 PhoneNumber::List list; 1313 PhoneNumber::List list;
1312 1314
1313 PhoneNumber::List::ConstIterator it; 1315 PhoneNumber::List::ConstIterator it;
1314 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1316 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1315 if ( matchBinaryPattern( (*it).type(), type ) ) { 1317 if ( matchBinaryPattern( (*it).type(), type ) ) {
1316 list.append( *it ); 1318 list.append( *it );
1317 } 1319 }
1318 } 1320 }
1319 return list; 1321 return list;
1320} 1322}
1321 1323
1322PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1324PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1323{ 1325{
1324 PhoneNumber::List::ConstIterator it; 1326 PhoneNumber::List::ConstIterator it;
1325 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1327 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1326 if ( (*it).id() == id ) { 1328 if ( (*it).id() == id ) {
1327 return *it; 1329 return *it;
1328 } 1330 }
1329 } 1331 }
1330 return PhoneNumber(); 1332 return PhoneNumber();
1331} 1333}
1332 1334
1333void Addressee::insertKey( const Key &key ) 1335void Addressee::insertKey( const Key &key )
1334{ 1336{
1335 detach(); 1337 detach();
1336 mData->empty = false; 1338 mData->empty = false;
1337 1339
1338 Key::List::Iterator it; 1340 Key::List::Iterator it;
1339 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1341 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1340 if ( (*it).id() == key.id() ) { 1342 if ( (*it).id() == key.id() ) {
1341 *it = key; 1343 *it = key;
1342 return; 1344 return;
1343 } 1345 }
1344 } 1346 }
1345 mData->keys.append( key ); 1347 mData->keys.append( key );
1346} 1348}
1347 1349
1348void Addressee::removeKey( const Key &key ) 1350void Addressee::removeKey( const Key &key )
1349{ 1351{
1350 detach(); 1352 detach();
1351 1353
1352 Key::List::Iterator it; 1354 Key::List::Iterator it;
1353 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1355 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1354 if ( (*it).id() == key.id() ) { 1356 if ( (*it).id() == key.id() ) {
1355 mData->keys.remove( key ); 1357 mData->keys.remove( key );
1356 return; 1358 return;
1357 } 1359 }
1358 } 1360 }
1359} 1361}
1360 1362
1361Key Addressee::key( int type, QString customTypeString ) const 1363Key Addressee::key( int type, QString customTypeString ) const
1362{ 1364{
1363 Key::List::ConstIterator it; 1365 Key::List::ConstIterator it;
1364 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1366 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1365 if ( (*it).type() == type ) { 1367 if ( (*it).type() == type ) {
1366 if ( type == Key::Custom ) { 1368 if ( type == Key::Custom ) {
1367 if ( customTypeString.isEmpty() ) { 1369 if ( customTypeString.isEmpty() ) {
1368 return *it; 1370 return *it;
1369 } else { 1371 } else {
1370 if ( (*it).customTypeString() == customTypeString ) 1372 if ( (*it).customTypeString() == customTypeString )
1371 return (*it); 1373 return (*it);
1372 } 1374 }
1373 } else { 1375 } else {
1374 return *it; 1376 return *it;
1375 } 1377 }
1376 } 1378 }
1377 } 1379 }
1378 return Key( QString(), type ); 1380 return Key( QString(), type );
1379} 1381}
1380void Addressee::setKeys( const Key::List& list ) { 1382void Addressee::setKeys( const Key::List& list ) {
1381 detach(); 1383 detach();
1382 mData->keys = list; 1384 mData->keys = list;
1383} 1385}
1384 1386
1385Key::List Addressee::keys() const 1387Key::List Addressee::keys() const
1386{ 1388{
1387 return mData->keys; 1389 return mData->keys;
1388} 1390}
1389 1391
1390Key::List Addressee::keys( int type, QString customTypeString ) const 1392Key::List Addressee::keys( int type, QString customTypeString ) const
1391{ 1393{
1392 Key::List list; 1394 Key::List list;
1393 1395
1394 Key::List::ConstIterator it; 1396 Key::List::ConstIterator it;
1395 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1397 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1396 if ( (*it).type() == type ) { 1398 if ( (*it).type() == type ) {
1397 if ( type == Key::Custom ) { 1399 if ( type == Key::Custom ) {
1398 if ( customTypeString.isEmpty() ) { 1400 if ( customTypeString.isEmpty() ) {
1399 list.append(*it); 1401 list.append(*it);
1400 } else { 1402 } else {
1401 if ( (*it).customTypeString() == customTypeString ) 1403 if ( (*it).customTypeString() == customTypeString )
1402 list.append(*it); 1404 list.append(*it);
1403 } 1405 }
1404 } else { 1406 } else {
1405 list.append(*it); 1407 list.append(*it);
1406 } 1408 }
1407 } 1409 }
1408 } 1410 }
1409 return list; 1411 return list;
1410} 1412}
1411 1413
1412Key Addressee::findKey( const QString &id ) const 1414Key Addressee::findKey( const QString &id ) const
1413{ 1415{
1414 Key::List::ConstIterator it; 1416 Key::List::ConstIterator it;
1415 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1417 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1416 if ( (*it).id() == id ) { 1418 if ( (*it).id() == id ) {
1417 return *it; 1419 return *it;
1418 } 1420 }
1419 } 1421 }
1420 return Key(); 1422 return Key();
1421} 1423}
1422 1424
1423QString Addressee::asString() const 1425QString Addressee::asString() const
1424{ 1426{
1425 return "Smith, agent Smith..."; 1427 return "Smith, agent Smith...";
1426} 1428}
1427 1429
1428void Addressee::dump() const 1430void Addressee::dump() const
1429{ 1431{
1430 return; 1432 return;
1431 kdDebug(5700) << "Addressee {" << endl; 1433 kdDebug(5700) << "Addressee {" << endl;
1432 1434
1433 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1435 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1434 1436
1435 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1437 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1436 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1438 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1437 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1439 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1438 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1440 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1439 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1441 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1440 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1442 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1441 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1443 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1442 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1444 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1443 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1445 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1444 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1446 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1445 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1447 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1446 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1448 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1447 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1449 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1448 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1450 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1449 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1451 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1450 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1452 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1451 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1453 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1452 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1454 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1453 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1455 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1454 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1456 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1455 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1457 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1456 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1458 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1457 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1459 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1458 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1460 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1459 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1461 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1460 1462
1461 kdDebug(5700) << " Emails {" << endl; 1463 kdDebug(5700) << " Emails {" << endl;
1462 QStringList e = emails(); 1464 QStringList e = emails();
1463 QStringList::ConstIterator it; 1465 QStringList::ConstIterator it;
1464 for( it = e.begin(); it != e.end(); ++it ) { 1466 for( it = e.begin(); it != e.end(); ++it ) {
1465 kdDebug(5700) << " " << (*it) << endl; 1467 kdDebug(5700) << " " << (*it) << endl;
1466 } 1468 }
1467 kdDebug(5700) << " }" << endl; 1469 kdDebug(5700) << " }" << endl;
1468 1470
1469 kdDebug(5700) << " PhoneNumbers {" << endl; 1471 kdDebug(5700) << " PhoneNumbers {" << endl;
1470 PhoneNumber::List p = phoneNumbers(); 1472 PhoneNumber::List p = phoneNumbers();
1471 PhoneNumber::List::ConstIterator it2; 1473 PhoneNumber::List::ConstIterator it2;
1472 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1474 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1473 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1475 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1474 } 1476 }
1475 kdDebug(5700) << " }" << endl; 1477 kdDebug(5700) << " }" << endl;
1476 1478
1477 Address::List a = addresses(); 1479 Address::List a = addresses();
1478 Address::List::ConstIterator it3; 1480 Address::List::ConstIterator it3;
1479 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1481 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1480 (*it3).dump(); 1482 (*it3).dump();
1481 } 1483 }
1482 1484
1483 kdDebug(5700) << " Keys {" << endl; 1485 kdDebug(5700) << " Keys {" << endl;
1484 Key::List k = keys(); 1486 Key::List k = keys();
1485 Key::List::ConstIterator it4; 1487 Key::List::ConstIterator it4;
1486 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1488 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1487 kdDebug(5700) << " Type: " << int((*it4).type()) << 1489 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1488 " Key: " << (*it4).textData() << 1490 " Key: " << (*it4).textData() <<
1489 " CustomString: " << (*it4).customTypeString() << endl; 1491 " CustomString: " << (*it4).customTypeString() << endl;
1490 } 1492 }
1491 kdDebug(5700) << " }" << endl; 1493 kdDebug(5700) << " }" << endl;
1492 1494
1493 kdDebug(5700) << "}" << endl; 1495 kdDebug(5700) << "}" << endl;
1494} 1496}
1495 1497
1496 1498
1497void Addressee::insertAddress( const Address &address ) 1499void Addressee::insertAddress( const Address &address )
1498{ 1500{
1499 detach(); 1501 detach();
1500 mData->empty = false; 1502 mData->empty = false;
1501 1503
1502 Address::List::Iterator it; 1504 Address::List::Iterator it;
1503 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1505 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1504 if ( (*it).id() == address.id() ) { 1506 if ( (*it).id() == address.id() ) {
1505 *it = address; 1507 *it = address;
1506 return; 1508 return;
1507 } 1509 }
1508 } 1510 }
1509 mData->addresses.append( address ); 1511 mData->addresses.append( address );
1510} 1512}
1511 1513
1512void Addressee::removeAddress( const Address &address ) 1514void Addressee::removeAddress( const Address &address )
1513{ 1515{
1514 detach(); 1516 detach();
1515 1517
1516 Address::List::Iterator it; 1518 Address::List::Iterator it;
1517 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1519 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1518 if ( (*it).id() == address.id() ) { 1520 if ( (*it).id() == address.id() ) {
1519 mData->addresses.remove( it ); 1521 mData->addresses.remove( it );
1520 return; 1522 return;
1521 } 1523 }
1522 } 1524 }
1523} 1525}
1524 1526
1525Address Addressee::address( int type ) const 1527Address Addressee::address( int type ) const
1526{ 1528{
1527 Address address( type ); 1529 Address address( type );
1528 Address::List::ConstIterator it; 1530 Address::List::ConstIterator it;
1529 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1531 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1530 if ( matchBinaryPattern( (*it).type(), type ) ) { 1532 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1531 if ( (*it).type() & Address::Pref ) 1533 if ( (*it).type() & Address::Pref )
1532 return (*it); 1534 return (*it);
1533 else if ( address.isEmpty() ) 1535 else if ( address.isEmpty() )
1534 address = (*it); 1536 address = (*it);
1535 } 1537 }
1536 } 1538 }
1537 1539
1538 return address; 1540 return address;
1539} 1541}
1540 1542
1541Address::List Addressee::addresses() const 1543Address::List Addressee::addresses() const
1542{ 1544{
1543 return mData->addresses; 1545 return mData->addresses;
1544} 1546}
1545 1547
1546Address::List Addressee::addresses( int type ) const 1548Address::List Addressee::addresses( int type ) const
1547{ 1549{
1548 Address::List list; 1550 Address::List list;
1549 1551
1550 Address::List::ConstIterator it; 1552 Address::List::ConstIterator it;
1551 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1553 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1552 if ( matchBinaryPattern( (*it).type(), type ) ) { 1554 if ( matchBinaryPattern( (*it).type(), type ) ) {
1553 list.append( *it ); 1555 list.append( *it );
1554 } 1556 }
1555 } 1557 }
1556 1558
1557 return list; 1559 return list;
1558} 1560}
1559 1561
1560Address Addressee::findAddress( const QString &id ) const 1562Address Addressee::findAddress( const QString &id ) const
1561{ 1563{
1562 Address::List::ConstIterator it; 1564 Address::List::ConstIterator it;
1563 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1565 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1564 if ( (*it).id() == id ) { 1566 if ( (*it).id() == id ) {
1565 return *it; 1567 return *it;
1566 } 1568 }
1567 } 1569 }
1568 return Address(); 1570 return Address();
1569} 1571}
1570 1572
1571void Addressee::insertCategory( const QString &c ) 1573void Addressee::insertCategory( const QString &c )
1572{ 1574{
1573 detach(); 1575 detach();
1574 mData->empty = false; 1576 mData->empty = false;
1575 1577
1576 if ( mData->categories.contains( c ) ) return; 1578 if ( mData->categories.contains( c ) ) return;
1577 1579
1578 mData->categories.append( c ); 1580 mData->categories.append( c );
1579} 1581}
1580 1582
1581void Addressee::removeCategory( const QString &c ) 1583void Addressee::removeCategory( const QString &c )
1582{ 1584{
1583 detach(); 1585 detach();
1584 1586
1585 QStringList::Iterator it = mData->categories.find( c ); 1587 QStringList::Iterator it = mData->categories.find( c );
1586 if ( it == mData->categories.end() ) return; 1588 if ( it == mData->categories.end() ) return;
1587 1589
1588 mData->categories.remove( it ); 1590 mData->categories.remove( it );
1589} 1591}
1590 1592
1591bool Addressee::hasCategory( const QString &c ) const 1593bool Addressee::hasCategory( const QString &c ) const
1592{ 1594{
1593 return ( mData->categories.contains( c ) ); 1595 return ( mData->categories.contains( c ) );
1594} 1596}
1595 1597
1596void Addressee::setCategories( const QStringList &c ) 1598void Addressee::setCategories( const QStringList &c )
1597{ 1599{
1598 detach(); 1600 detach();
1599 mData->empty = false; 1601 mData->empty = false;
1600 1602
1601 mData->categories = c; 1603 mData->categories = c;
1602} 1604}
1603 1605
1604QStringList Addressee::categories() const 1606QStringList Addressee::categories() const
1605{ 1607{
1606 return mData->categories; 1608 return mData->categories;
1607} 1609}
1608 1610
1609void Addressee::insertCustom( const QString &app, const QString &name, 1611void Addressee::insertCustom( const QString &app, const QString &name,
1610 const QString &value ) 1612 const QString &value )
1611{ 1613{
1612 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1614 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1613 1615
1614 detach(); 1616 detach();
1615 mData->empty = false; 1617 mData->empty = false;
1616 1618
1617 QString qualifiedName = app + "-" + name + ":"; 1619 QString qualifiedName = app + "-" + name + ":";
1618 1620
1619 QStringList::Iterator it; 1621 QStringList::Iterator it;
1620 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1622 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1621 if ( (*it).startsWith( qualifiedName ) ) { 1623 if ( (*it).startsWith( qualifiedName ) ) {
1622 (*it) = qualifiedName + value; 1624 (*it) = qualifiedName + value;
1623 return; 1625 return;
1624 } 1626 }
1625 } 1627 }
1626 mData->custom.append( qualifiedName + value ); 1628 mData->custom.append( qualifiedName + value );
1627} 1629}
1628 1630
1629void Addressee::removeCustom( const QString &app, const QString &name) 1631void Addressee::removeCustom( const QString &app, const QString &name)
1630{ 1632{
1631 detach(); 1633 detach();
1632 1634
1633 QString qualifiedName = app + "-" + name + ":"; 1635 QString qualifiedName = app + "-" + name + ":";
1634 1636
1635 QStringList::Iterator it; 1637 QStringList::Iterator it;
1636 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1638 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1637 if ( (*it).startsWith( qualifiedName ) ) { 1639 if ( (*it).startsWith( qualifiedName ) ) {
1638 mData->custom.remove( it ); 1640 mData->custom.remove( it );
1639 return; 1641 return;
1640 } 1642 }
1641 } 1643 }
1642} 1644}
1643 1645
1644QString Addressee::custom( const QString &app, const QString &name ) const 1646QString Addressee::custom( const QString &app, const QString &name ) const
1645{ 1647{
1646 QString qualifiedName = app + "-" + name + ":"; 1648 QString qualifiedName = app + "-" + name + ":";
1647 QString value; 1649 QString value;
1648 1650
1649 QStringList::ConstIterator it; 1651 QStringList::ConstIterator it;
1650 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1652 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1651 if ( (*it).startsWith( qualifiedName ) ) { 1653 if ( (*it).startsWith( qualifiedName ) ) {
1652 value = (*it).mid( (*it).find( ":" ) + 1 ); 1654 value = (*it).mid( (*it).find( ":" ) + 1 );
1653 break; 1655 break;
1654 } 1656 }
1655 } 1657 }
1656 1658
1657 return value; 1659 return value;
1658} 1660}
@@ -1710,142 +1712,158 @@ void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1710 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1712 fullName = rawEmail.left(startPos).stripWhiteSpace();
1711 1713
1712 // grab the email part 1714 // grab the email part
1713 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1715 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1714 1716
1715 // Check that we do not have any extra characters on the end of the 1717 // Check that we do not have any extra characters on the end of the
1716 // strings 1718 // strings
1717 len = fullName.length(); 1719 len = fullName.length();
1718 if (fullName[0]=='"' && fullName[len-1]=='"') 1720 if (fullName[0]=='"' && fullName[len-1]=='"')
1719 fullName = fullName.mid(1, len-2); 1721 fullName = fullName.mid(1, len-2);
1720 else if (fullName[0]=='<' && fullName[len-1]=='>') 1722 else if (fullName[0]=='<' && fullName[len-1]=='>')
1721 fullName = fullName.mid(1, len-2); 1723 fullName = fullName.mid(1, len-2);
1722 else if (fullName[0]=='(' && fullName[len-1]==')') 1724 else if (fullName[0]=='(' && fullName[len-1]==')')
1723 fullName = fullName.mid(1, len-2); 1725 fullName = fullName.mid(1, len-2);
1724 } 1726 }
1725 } 1727 }
1726} 1728}
1727 1729
1728void Addressee::setResource( Resource *resource ) 1730void Addressee::setResource( Resource *resource )
1729{ 1731{
1730 detach(); 1732 detach();
1731 mData->resource = resource; 1733 mData->resource = resource;
1732} 1734}
1733 1735
1734Resource *Addressee::resource() const 1736Resource *Addressee::resource() const
1735{ 1737{
1736 return mData->resource; 1738 return mData->resource;
1737} 1739}
1738 1740
1739//US 1741//US
1740QString Addressee::resourceLabel() 1742QString Addressee::resourceLabel()
1741{ 1743{
1742 return i18n("Resource"); 1744 return i18n("Resource");
1743} 1745}
1744 1746
1745void Addressee::setChanged( bool value ) 1747void Addressee::setChanged( bool value )
1746{ 1748{
1747 detach(); 1749 detach();
1748 mData->changed = value; 1750 mData->changed = value;
1749} 1751}
1750 1752
1751bool Addressee::changed() const 1753bool Addressee::changed() const
1752{ 1754{
1753 return mData->changed; 1755 return mData->changed;
1754} 1756}
1755 1757
1756QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 1758QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
1757{ 1759{
1758 if (!a.mData) return s; 1760 if (!a.mData) return s;
1759 1761
1760 s << a.uid(); 1762 s << a.uid();
1761 1763
1762 s << a.mData->name; 1764 s << a.mData->name;
1763 s << a.mData->formattedName; 1765 s << a.mData->formattedName;
1764 s << a.mData->familyName; 1766 s << a.mData->familyName;
1765 s << a.mData->givenName; 1767 s << a.mData->givenName;
1766 s << a.mData->additionalName; 1768 s << a.mData->additionalName;
1767 s << a.mData->prefix; 1769 s << a.mData->prefix;
1768 s << a.mData->suffix; 1770 s << a.mData->suffix;
1769 s << a.mData->nickName; 1771 s << a.mData->nickName;
1770 s << a.mData->birthday; 1772 s << a.mData->birthday;
1771 s << a.mData->mailer; 1773 s << a.mData->mailer;
1772 s << a.mData->timeZone; 1774 s << a.mData->timeZone;
1773 s << a.mData->geo; 1775 s << a.mData->geo;
1774 s << a.mData->title; 1776 s << a.mData->title;
1775 s << a.mData->role; 1777 s << a.mData->role;
1776 s << a.mData->organization; 1778 s << a.mData->organization;
1777 s << a.mData->note; 1779 s << a.mData->note;
1778 s << a.mData->productId; 1780 s << a.mData->productId;
1779 s << a.mData->revision; 1781 s << a.mData->revision;
1780 s << a.mData->sortString; 1782 s << a.mData->sortString;
1781 s << a.mData->url; 1783 s << a.mData->url;
1782 s << a.mData->secrecy; 1784 s << a.mData->secrecy;
1783 s << a.mData->logo; 1785 s << a.mData->logo;
1784 s << a.mData->photo; 1786 s << a.mData->photo;
1785 s << a.mData->sound; 1787 s << a.mData->sound;
1786 s << a.mData->agent; 1788 s << a.mData->agent;
1787 s << a.mData->phoneNumbers; 1789 s << a.mData->phoneNumbers;
1788 s << a.mData->addresses; 1790 s << a.mData->addresses;
1789 s << a.mData->emails; 1791 s << a.mData->emails;
1790 s << a.mData->categories; 1792 s << a.mData->categories;
1791 s << a.mData->custom; 1793 s << a.mData->custom;
1792 s << a.mData->keys; 1794 s << a.mData->keys;
1793 return s; 1795 return s;
1794} 1796}
1795 1797
1796QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 1798QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
1797{ 1799{
1798 if (!a.mData) return s; 1800 if (!a.mData) return s;
1799 1801
1800 s >> a.mData->uid; 1802 s >> a.mData->uid;
1801 1803
1802 s >> a.mData->name; 1804 s >> a.mData->name;
1803 s >> a.mData->formattedName; 1805 s >> a.mData->formattedName;
1804 s >> a.mData->familyName; 1806 s >> a.mData->familyName;
1805 s >> a.mData->givenName; 1807 s >> a.mData->givenName;
1806 s >> a.mData->additionalName; 1808 s >> a.mData->additionalName;
1807 s >> a.mData->prefix; 1809 s >> a.mData->prefix;
1808 s >> a.mData->suffix; 1810 s >> a.mData->suffix;
1809 s >> a.mData->nickName; 1811 s >> a.mData->nickName;
1810 s >> a.mData->birthday; 1812 s >> a.mData->birthday;
1811 s >> a.mData->mailer; 1813 s >> a.mData->mailer;
1812 s >> a.mData->timeZone; 1814 s >> a.mData->timeZone;
1813 s >> a.mData->geo; 1815 s >> a.mData->geo;
1814 s >> a.mData->title; 1816 s >> a.mData->title;
1815 s >> a.mData->role; 1817 s >> a.mData->role;
1816 s >> a.mData->organization; 1818 s >> a.mData->organization;
1817 s >> a.mData->note; 1819 s >> a.mData->note;
1818 s >> a.mData->productId; 1820 s >> a.mData->productId;
1819 s >> a.mData->revision; 1821 s >> a.mData->revision;
1820 s >> a.mData->sortString; 1822 s >> a.mData->sortString;
1821 s >> a.mData->url; 1823 s >> a.mData->url;
1822 s >> a.mData->secrecy; 1824 s >> a.mData->secrecy;
1823 s >> a.mData->logo; 1825 s >> a.mData->logo;
1824 s >> a.mData->photo; 1826 s >> a.mData->photo;
1825 s >> a.mData->sound; 1827 s >> a.mData->sound;
1826 s >> a.mData->agent; 1828 s >> a.mData->agent;
1827 s >> a.mData->phoneNumbers; 1829 s >> a.mData->phoneNumbers;
1828 s >> a.mData->addresses; 1830 s >> a.mData->addresses;
1829 s >> a.mData->emails; 1831 s >> a.mData->emails;
1830 s >> a.mData->categories; 1832 s >> a.mData->categories;
1831 s >> a.mData->custom; 1833 s >> a.mData->custom;
1832 s >> a.mData->keys; 1834 s >> a.mData->keys;
1833 1835
1834 a.mData->empty = false; 1836 a.mData->empty = false;
1835 1837
1836 return s; 1838 return s;
1837} 1839}
1838
1839bool matchBinaryPattern( int value, int pattern ) 1840bool matchBinaryPattern( int value, int pattern )
1840{ 1841{
1841 /** 1842 /**
1842 We want to match all telephonnumbers/addresses which have the bits in the 1843 We want to match all telephonnumbers/addresses which have the bits in the
1843 pattern set. More are allowed. 1844 pattern set. More are allowed.
1844 if pattern == 0 we have a special handling, then we want only those with 1845 if pattern == 0 we have a special handling, then we want only those with
1845 exactly no bit set. 1846 exactly no bit set.
1846 */ 1847 */
1847 if ( pattern == 0 ) 1848 if ( pattern == 0 )
1848 return ( value == 0 ); 1849 return ( value == 0 );
1849 else 1850 else
1850 return ( pattern == ( pattern & value ) ); 1851 return ( pattern == ( pattern & value ) );
1851} 1852}
1853
1854bool matchBinaryPatternP( int value, int pattern )
1855{
1856
1857 if ( pattern == 0 )
1858 return ( value == 0 );
1859 else
1860 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
1861}
1862bool matchBinaryPatternA( int value, int pattern )
1863{
1864
1865 if ( pattern == 0 )
1866 return ( value == 0 );
1867 else
1868 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
1869}