summaryrefslogtreecommitdiffabout
path: root/kabc/addressee.cpp
authorzautrix <zautrix>2004-10-09 16:58:08 (UTC)
committer zautrix <zautrix>2004-10-09 16:58:08 (UTC)
commit59ed933d6c43ecb0ddd3dec53cc289ee8aa68482 (patch) (unidiff)
tree8b1cbcf9c420e7dffd1e1293bcfa69e8e821f3fa /kabc/addressee.cpp
parentb80a099d9432bdc3d4eea778b1813b82b2680ecf (diff)
downloadkdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.zip
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.gz
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.bz2
fixed sync bug
Diffstat (limited to 'kabc/addressee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3f3d5c0..607ae26 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,1935 +1,1947 @@
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 ); 46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern ); 47static bool matchBinaryPatternP( int value, int pattern );
48 48
49struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
50{ 50{
51 QString uid; 51 QString uid;
52 QString name; 52 QString name;
53 QString formattedName; 53 QString formattedName;
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1;
91}; 92};
92 93
93Addressee::Addressee() 94Addressee::Addressee()
94{ 95{
95 mData = new AddresseeData; 96 mData = new AddresseeData;
96 mData->empty = true; 97 mData->empty = true;
97 mData->changed = false; 98 mData->changed = false;
98 mData->resource = 0; 99 mData->resource = 0;
99 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
100 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
101 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
102} 103}
103 104
104Addressee::~Addressee() 105Addressee::~Addressee()
105{ 106{
106} 107}
107 108
108Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
109{ 110{
110 mData = a.mData; 111 mData = a.mData;
111} 112}
112 113
113Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
114{ 115{
115 mData = a.mData; 116 mData = a.mData;
116 return (*this); 117 return (*this);
117} 118}
118 119
119Addressee Addressee::copy() 120Addressee Addressee::copy()
120{ 121{
121 Addressee a; 122 Addressee a;
122 *(a.mData) = *mData; 123 *(a.mData) = *mData;
123 return a; 124 return a;
124} 125}
125 126
126void Addressee::detach() 127void Addressee::detach()
127{ 128{
128 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
129 *this = copy(); 130 *this = copy();
130} 131}
131 132
132bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
133{ 134{
134 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
135 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
136 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
137 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
138 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
139 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
140 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
141 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
142 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
143 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
144 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
145 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
146 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
147 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
148 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
149 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
150 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
151 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
152 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
153 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
154 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
155 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
156 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
157 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
158 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
159 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
160 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
161 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
162 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
163 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
164 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
165 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
166 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
167 168
168 return true; 169 return true;
169} 170}
170 171
171bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
172{ 173{
173 return !( a == *this ); 174 return !( a == *this );
174} 175}
175 176
176bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
177{ 178{
178 return mData->empty; 179 return mData->empty;
179} 180}
180ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
181{ 182{
182 int max = attList.count(); 183 int max = attList.count();
183 ulong cSum = 0; 184 ulong cSum = 0;
184 int j,k,i; 185 int j,k,i;
185 int add; 186 int add;
186 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
187 QString s = attList[i]; 188 QString s = attList[i];
188 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
189 j = s.length(); 190 j = s.length();
190 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
191 int mul = k +1; 192 int mul = k +1;
192 add = s[k].unicode (); 193 add = s[k].unicode ();
193 if ( k < 16 ) 194 if ( k < 16 )
194 mul = mul * mul; 195 mul = mul * mul;
195 int ii = i+1; 196 int ii = i+1;
196 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
197 cSum += add; 198 cSum += add;
198 } 199 }
199 } 200 }
200 201
201 } 202 }
202 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
203 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
204 205
205 return cSum; 206 return cSum;
206 207
207} 208}
208void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
209{ 210{
210 QStringList l; 211 QStringList l;
211 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
212 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
213 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
214 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
215 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
216 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
217 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
218 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
219 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
220 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
221 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
222 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
223 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
224 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
225 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
226 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
227 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
228 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
229 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
230 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
231 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
232 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
233 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
234 //if ( mData->url.isValid() ) l.append( ); 235 //if ( mData->url.isValid() ) l.append( );
235#if 0 236#if 0
236 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); 237 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
237 if ( !mData->addresses.isEmpty() ) l.append( ); 238 if ( !mData->addresses.isEmpty() ) l.append( );
238 //if ( !mData->keys.isEmpty() ) l.append( ); 239 //if ( !mData->keys.isEmpty() ) l.append( );
239 if ( !mData->emails.isEmpty() ) l.append( ); 240 if ( !mData->emails.isEmpty() ) l.append( );
240 if ( !mData->categories .isEmpty() ) l.append( ); 241 if ( !mData->categories .isEmpty() ) l.append( );
241 if ( !mData->custom.isEmpty() ) l.append( ); 242 if ( !mData->custom.isEmpty() ) l.append( );
242#endif 243#endif
243 KABC::PhoneNumber::List phoneNumbers; 244 KABC::PhoneNumber::List phoneNumbers;
244 KABC::PhoneNumber::List::Iterator phoneIter; 245 KABC::PhoneNumber::List::Iterator phoneIter;
245 246
246 QStringList t; 247 QStringList t;
247 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 248 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
248 ++phoneIter ) 249 ++phoneIter )
249 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 250 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
250 t.sort(); 251 t.sort();
251 uint iii; 252 uint iii;
252 for ( iii = 0; iii < t.count(); ++iii) 253 for ( iii = 0; iii < t.count(); ++iii)
253 l.append( t[iii] ); 254 l.append( t[iii] );
254 t = mData->emails; 255 t = mData->emails;
255 t.sort(); 256 t.sort();
256 for ( iii = 0; iii < t.count(); ++iii) 257 for ( iii = 0; iii < t.count(); ++iii)
257 l.append( t[iii] ); 258 l.append( t[iii] );
258 t = mData->categories; 259 t = mData->categories;
259 t.sort(); 260 t.sort();
260 for ( iii = 0; iii < t.count(); ++iii) 261 for ( iii = 0; iii < t.count(); ++iii)
261 l.append( t[iii] ); 262 l.append( t[iii] );
262 t = mData->custom; 263 t = mData->custom;
263 t.sort(); 264 t.sort();
264 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
265 l.append( t[iii] ); 266 l.append( t[iii] );
266 KABC::Address::List::Iterator addressIter; 267 KABC::Address::List::Iterator addressIter;
267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 268 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
268 ++addressIter ) { 269 ++addressIter ) {
269 t = (*addressIter).asList(); 270 t = (*addressIter).asList();
270 t.sort(); 271 t.sort();
271 for ( iii = 0; iii < t.count(); ++iii) 272 for ( iii = 0; iii < t.count(); ++iii)
272 l.append( t[iii] ); 273 l.append( t[iii] );
273 } 274 }
274 uint cs = getCsum4List(l); 275 uint cs = getCsum4List(l);
275 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 276 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
276 setCsum( dev, QString::number (cs )); 277 setCsum( dev, QString::number (cs ));
277} 278}
278 279
279void Addressee::mergeContact( const Addressee& ad ) 280void Addressee::mergeContact( const Addressee& ad )
280{ 281{
281 282
282 detach(); 283 detach();
283 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 284 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
284 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 285 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
285 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 286 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
286 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 287 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
287 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 288 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
288 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 289 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
289 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 290 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
290 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 291 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
291 if ( !mData->birthday.isValid() ) 292 if ( !mData->birthday.isValid() )
292 if ( ad.mData->birthday.isValid()) 293 if ( ad.mData->birthday.isValid())
293 mData->birthday = ad.mData->birthday; 294 mData->birthday = ad.mData->birthday;
294 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 295 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
295 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 296 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
296 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 297 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
297 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 298 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
298 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 299 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
299 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 300 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
300 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 301 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
301 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 302 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
302 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 303 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
303 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 304 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
304 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 305 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
305 306
306 // pending: 307 // pending:
307 // merging phonenumbers 308 // merging phonenumbers
308 // merging addresses 309 // merging addresses
309 // merging emails; 310 // merging emails;
310 // merging categories; 311 // merging categories;
311 // merging custom; 312 // merging custom;
312 // merging keys 313 // merging keys
313 qDebug("merge contact %s ", ad.uid().latin1()); 314 qDebug("merge contact %s ", ad.uid().latin1());
314 setUid( ad.uid() ); 315 setUid( ad.uid() );
315 setRevision( ad.revision() ); 316 setRevision( ad.revision() );
316} 317}
317 318
318bool Addressee::removeVoice() 319bool Addressee::removeVoice()
319{ 320{
320 PhoneNumber::List phoneN = phoneNumbers(); 321 PhoneNumber::List phoneN = phoneNumbers();
321 PhoneNumber::List::Iterator phoneIt; 322 PhoneNumber::List::Iterator phoneIt;
322 bool found = false; 323 bool found = false;
323 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 324 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
324 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 325 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
325 if ((*phoneIt).type() - PhoneNumber::Voice ) { 326 if ((*phoneIt).type() - PhoneNumber::Voice ) {
326 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 327 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
327 insertPhoneNumber( (*phoneIt) ); 328 insertPhoneNumber( (*phoneIt) );
328 found = true; 329 found = true;
329 } 330 }
330 } 331 }
331 332
332 } 333 }
333 return found; 334 return found;
334} 335}
335void Addressee::simplifyAddresses() 336void Addressee::simplifyAddresses()
336{ 337{
337 if ( mData->addresses.count() < 3 ) return ; 338 if ( mData->addresses.count() < 3 ) return ;
338 int count = 0; 339 int count = 0;
339 Address::List list; 340 Address::List list;
340 Address::List::Iterator it; 341 Address::List::Iterator it;
341 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 342 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
342 if ( count > 1 ) 343 if ( count > 1 )
343 list.append( *it ); 344 list.append( *it );
344 ++count; 345 ++count;
345 } 346 }
346 for( it = list.begin(); it != list.end(); ++it ) { 347 for( it = list.begin(); it != list.end(); ++it ) {
347 removeAddress( (*it) ); 348 removeAddress( (*it) );
348 } 349 }
349} 350}
350 351
351// removes all emails but the first 352// removes all emails but the first
352// needed by phone sync 353// needed by phone sync
353void Addressee::simplifyEmails() 354void Addressee::simplifyEmails()
354{ 355{
355 if ( mData->emails.count() == 0 ) return ; 356 if ( mData->emails.count() == 0 ) return ;
356 QString email = mData->emails.first(); 357 QString email = mData->emails.first();
357 detach(); 358 detach();
358 mData->emails.clear(); 359 mData->emails.clear();
359 mData->emails.append( email ); 360 mData->emails.append( email );
360} 361}
361 362
362void Addressee::simplifyPhoneNumbers() 363void Addressee::simplifyPhoneNumbers()
363{ 364{
364 KABC::PhoneNumber::List removeNumbers; 365 KABC::PhoneNumber::List removeNumbers;
365 KABC::PhoneNumber::List::Iterator phoneIter; 366 KABC::PhoneNumber::List::Iterator phoneIter;
366 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 367 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
367 ++phoneIter ) { 368 ++phoneIter ) {
368 if ( ! ( *phoneIter ).simplifyNumber() ) 369 if ( ! ( *phoneIter ).simplifyNumber() )
369 removeNumbers.append( ( *phoneIter ) ); 370 removeNumbers.append( ( *phoneIter ) );
370 } 371 }
371 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 372 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
372 ++phoneIter ) { 373 ++phoneIter ) {
373 removePhoneNumber(( *phoneIter )); 374 removePhoneNumber(( *phoneIter ));
374 } 375 }
375} 376}
376void Addressee::simplifyPhoneNumberTypes() 377void Addressee::simplifyPhoneNumberTypes()
377{ 378{
378 KABC::PhoneNumber::List::Iterator phoneIter; 379 KABC::PhoneNumber::List::Iterator phoneIter;
379 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 380 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
380 ++phoneIter ) 381 ++phoneIter )
381 ( *phoneIter ).simplifyType(); 382 ( *phoneIter ).simplifyType();
382} 383}
383void Addressee::removeID(const QString &prof) 384void Addressee::removeID(const QString &prof)
384{ 385{
385 detach(); 386 detach();
386 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 387 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
387 388
388} 389}
389void Addressee::setID( const QString & prof , const QString & id ) 390void Addressee::setID( const QString & prof , const QString & id )
390{ 391{
391 detach(); 392 detach();
392 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 393 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
393 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 394 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
394} 395}
395void Addressee::setTempSyncStat( int id ) 396void Addressee::setTempSyncStat( int id )
396{ 397{
397 if ( mData->mTempSyncStat == id ) return; 398 if ( mData->mTempSyncStat == id ) return;
398 detach(); 399 detach();
399 mData->mTempSyncStat = id; 400 mData->mTempSyncStat = id;
400} 401}
401int Addressee::tempSyncStat() const 402int Addressee::tempSyncStat() const
402{ 403{
403 return mData->mTempSyncStat; 404 return mData->mTempSyncStat;
404} 405}
405 406
406QString Addressee::getID( const QString & prof) 407QString Addressee::getID( const QString & prof)
407{ 408{
408 return KIdManager::getId ( mData->mExternalId, prof ); 409 return KIdManager::getId ( mData->mExternalId, prof );
409} 410}
410 411
411void Addressee::setCsum( const QString & prof , const QString & id ) 412void Addressee::setCsum( const QString & prof , const QString & id )
412{ 413{
413 detach(); 414 detach();
414 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 415 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
415 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 416 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
416 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 417 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
417} 418}
418 419
419QString Addressee::getCsum( const QString & prof) 420QString Addressee::getCsum( const QString & prof)
420{ 421{
421 return KIdManager::getCsum ( mData->mExternalId, prof ); 422 return KIdManager::getCsum ( mData->mExternalId, prof );
422} 423}
423 424
424void Addressee::setIDStr( const QString & s ) 425void Addressee::setIDStr( const QString & s )
425{ 426{
426 detach(); 427 detach();
427 mData->mExternalId = s; 428 mData->mExternalId = s;
428} 429}
429 430
430QString Addressee::IDStr() const 431QString Addressee::IDStr() const
431{ 432{
432 return mData->mExternalId; 433 return mData->mExternalId;
433} 434}
434 435
435void Addressee::setExternalUID( const QString &id ) 436void Addressee::setExternalUID( const QString &id )
436{ 437{
437 if ( id == mData->externalUID ) return; 438 if ( id == mData->externalUID ) return;
438 detach(); 439 detach();
439 mData->empty = false; 440 mData->empty = false;
440 mData->externalUID = id; 441 mData->externalUID = id;
441} 442}
442 443
443QString Addressee::externalUID() const 444QString Addressee::externalUID() const
444{ 445{
445 return mData->externalUID; 446 return mData->externalUID;
446} 447}
447void Addressee::setOriginalExternalUID( const QString &id ) 448void Addressee::setOriginalExternalUID( const QString &id )
448{ 449{
449 if ( id == mData->originalExternalUID ) return; 450 if ( id == mData->originalExternalUID ) return;
450 detach(); 451 detach();
451 mData->empty = false; 452 mData->empty = false;
452 //qDebug("*******Set orig uid %s ", id.latin1()); 453 //qDebug("*******Set orig uid %s ", id.latin1());
453 mData->originalExternalUID = id; 454 mData->originalExternalUID = id;
454} 455}
455 456
456QString Addressee::originalExternalUID() const 457QString Addressee::originalExternalUID() const
457{ 458{
458 return mData->originalExternalUID; 459 return mData->originalExternalUID;
459} 460}
460 461
461void Addressee::setUid( const QString &id ) 462void Addressee::setUid( const QString &id )
462{ 463{
463 if ( id == mData->uid ) return; 464 if ( id == mData->uid ) return;
464 detach(); 465 detach();
465 //qDebug("****setuid %s ", id.latin1()); 466 //qDebug("****setuid %s ", id.latin1());
466 mData->empty = false; 467 mData->empty = false;
467 mData->uid = id; 468 mData->uid = id;
468} 469}
469 470
470QString Addressee::uid() const 471QString Addressee::uid() const
471{ 472{
472 if ( mData->uid.isEmpty() ) 473 if ( mData->uid.isEmpty() )
473 mData->uid = KApplication::randomString( 10 ); 474 mData->uid = KApplication::randomString( 10 );
474 475
475 return mData->uid; 476 return mData->uid;
476} 477}
477 478
478QString Addressee::uidLabel() 479QString Addressee::uidLabel()
479{ 480{
480 return i18n("Unique Identifier"); 481 return i18n("Unique Identifier");
481} 482}
482 483
483void Addressee::setName( const QString &name ) 484void Addressee::setName( const QString &name )
484{ 485{
485 if ( name == mData->name ) return; 486 if ( name == mData->name ) return;
486 detach(); 487 detach();
487 mData->empty = false; 488 mData->empty = false;
488 mData->name = name; 489 mData->name = name;
489} 490}
490 491
491QString Addressee::name() const 492QString Addressee::name() const
492{ 493{
493 return mData->name; 494 return mData->name;
494} 495}
495 496
496QString Addressee::nameLabel() 497QString Addressee::nameLabel()
497{ 498{
498 return i18n("Name"); 499 return i18n("Name");
499} 500}
500 501
501 502
502void Addressee::setFormattedName( const QString &formattedName ) 503void Addressee::setFormattedName( const QString &formattedName )
503{ 504{
504 if ( formattedName == mData->formattedName ) return; 505 if ( formattedName == mData->formattedName ) return;
505 detach(); 506 detach();
506 mData->empty = false; 507 mData->empty = false;
507 mData->formattedName = formattedName; 508 mData->formattedName = formattedName;
508} 509}
509 510
510QString Addressee::formattedName() const 511QString Addressee::formattedName() const
511{ 512{
512 return mData->formattedName; 513 return mData->formattedName;
513} 514}
514 515
515QString Addressee::formattedNameLabel() 516QString Addressee::formattedNameLabel()
516{ 517{
517 return i18n("Formatted Name"); 518 return i18n("Formatted Name");
518} 519}
519 520
520 521
521void Addressee::setFamilyName( const QString &familyName ) 522void Addressee::setFamilyName( const QString &familyName )
522{ 523{
523 if ( familyName == mData->familyName ) return; 524 if ( familyName == mData->familyName ) return;
524 detach(); 525 detach();
525 mData->empty = false; 526 mData->empty = false;
526 mData->familyName = familyName; 527 mData->familyName = familyName;
527} 528}
528 529
529QString Addressee::familyName() const 530QString Addressee::familyName() const
530{ 531{
531 return mData->familyName; 532 return mData->familyName;
532} 533}
533 534
534QString Addressee::familyNameLabel() 535QString Addressee::familyNameLabel()
535{ 536{
536 return i18n("Family Name"); 537 return i18n("Family Name");
537} 538}
538 539
539 540
540void Addressee::setGivenName( const QString &givenName ) 541void Addressee::setGivenName( const QString &givenName )
541{ 542{
542 if ( givenName == mData->givenName ) return; 543 if ( givenName == mData->givenName ) return;
543 detach(); 544 detach();
544 mData->empty = false; 545 mData->empty = false;
545 mData->givenName = givenName; 546 mData->givenName = givenName;
546} 547}
547 548
548QString Addressee::givenName() const 549QString Addressee::givenName() const
549{ 550{
550 return mData->givenName; 551 return mData->givenName;
551} 552}
552 553
553QString Addressee::givenNameLabel() 554QString Addressee::givenNameLabel()
554{ 555{
555 return i18n("Given Name"); 556 return i18n("Given Name");
556} 557}
557 558
558 559
559void Addressee::setAdditionalName( const QString &additionalName ) 560void Addressee::setAdditionalName( const QString &additionalName )
560{ 561{
561 if ( additionalName == mData->additionalName ) return; 562 if ( additionalName == mData->additionalName ) return;
562 detach(); 563 detach();
563 mData->empty = false; 564 mData->empty = false;
564 mData->additionalName = additionalName; 565 mData->additionalName = additionalName;
565} 566}
566 567
567QString Addressee::additionalName() const 568QString Addressee::additionalName() const
568{ 569{
569 return mData->additionalName; 570 return mData->additionalName;
570} 571}
571 572
572QString Addressee::additionalNameLabel() 573QString Addressee::additionalNameLabel()
573{ 574{
574 return i18n("Additional Names"); 575 return i18n("Additional Names");
575} 576}
576 577
577 578
578void Addressee::setPrefix( const QString &prefix ) 579void Addressee::setPrefix( const QString &prefix )
579{ 580{
580 if ( prefix == mData->prefix ) return; 581 if ( prefix == mData->prefix ) return;
581 detach(); 582 detach();
582 mData->empty = false; 583 mData->empty = false;
583 mData->prefix = prefix; 584 mData->prefix = prefix;
584} 585}
585 586
586QString Addressee::prefix() const 587QString Addressee::prefix() const
587{ 588{
588 return mData->prefix; 589 return mData->prefix;
589} 590}
590 591
591QString Addressee::prefixLabel() 592QString Addressee::prefixLabel()
592{ 593{
593 return i18n("Honorific Prefixes"); 594 return i18n("Honorific Prefixes");
594} 595}
595 596
596 597
597void Addressee::setSuffix( const QString &suffix ) 598void Addressee::setSuffix( const QString &suffix )
598{ 599{
599 if ( suffix == mData->suffix ) return; 600 if ( suffix == mData->suffix ) return;
600 detach(); 601 detach();
601 mData->empty = false; 602 mData->empty = false;
602 mData->suffix = suffix; 603 mData->suffix = suffix;
603} 604}
604 605
605QString Addressee::suffix() const 606QString Addressee::suffix() const
606{ 607{
607 return mData->suffix; 608 return mData->suffix;
608} 609}
609 610
610QString Addressee::suffixLabel() 611QString Addressee::suffixLabel()
611{ 612{
612 return i18n("Honorific Suffixes"); 613 return i18n("Honorific Suffixes");
613} 614}
614 615
615 616
616void Addressee::setNickName( const QString &nickName ) 617void Addressee::setNickName( const QString &nickName )
617{ 618{
618 if ( nickName == mData->nickName ) return; 619 if ( nickName == mData->nickName ) return;
619 detach(); 620 detach();
620 mData->empty = false; 621 mData->empty = false;
621 mData->nickName = nickName; 622 mData->nickName = nickName;
622} 623}
623 624
624QString Addressee::nickName() const 625QString Addressee::nickName() const
625{ 626{
626 return mData->nickName; 627 return mData->nickName;
627} 628}
628 629
629QString Addressee::nickNameLabel() 630QString Addressee::nickNameLabel()
630{ 631{
631 return i18n("Nick Name"); 632 return i18n("Nick Name");
632} 633}
633 634
634 635
635void Addressee::setBirthday( const QDateTime &birthday ) 636void Addressee::setBirthday( const QDateTime &birthday )
636{ 637{
637 if ( birthday == mData->birthday ) return; 638 if ( birthday == mData->birthday ) return;
638 detach(); 639 detach();
639 mData->empty = false; 640 mData->empty = false;
640 mData->birthday = birthday; 641 mData->birthday = birthday;
641} 642}
642 643
643QDateTime Addressee::birthday() const 644QDateTime Addressee::birthday() const
644{ 645{
645 return mData->birthday; 646 return mData->birthday;
646} 647}
647 648
648QString Addressee::birthdayLabel() 649QString Addressee::birthdayLabel()
649{ 650{
650 return i18n("Birthday"); 651 return i18n("Birthday");
651} 652}
652 653
653 654
654QString Addressee::homeAddressStreetLabel() 655QString Addressee::homeAddressStreetLabel()
655{ 656{
656 return i18n("Home Address Street"); 657 return i18n("Home Address Street");
657} 658}
658 659
659 660
660QString Addressee::homeAddressLocalityLabel() 661QString Addressee::homeAddressLocalityLabel()
661{ 662{
662 return i18n("Home Address Locality"); 663 return i18n("Home Address Locality");
663} 664}
664 665
665 666
666QString Addressee::homeAddressRegionLabel() 667QString Addressee::homeAddressRegionLabel()
667{ 668{
668 return i18n("Home Address Region"); 669 return i18n("Home Address Region");
669} 670}
670 671
671 672
672QString Addressee::homeAddressPostalCodeLabel() 673QString Addressee::homeAddressPostalCodeLabel()
673{ 674{
674 return i18n("Home Address Postal Code"); 675 return i18n("Home Address Postal Code");
675} 676}
676 677
677 678
678QString Addressee::homeAddressCountryLabel() 679QString Addressee::homeAddressCountryLabel()
679{ 680{
680 return i18n("Home Address Country"); 681 return i18n("Home Address Country");
681} 682}
682 683
683 684
684QString Addressee::homeAddressLabelLabel() 685QString Addressee::homeAddressLabelLabel()
685{ 686{
686 return i18n("Home Address Label"); 687 return i18n("Home Address Label");
687} 688}
688 689
689 690
690QString Addressee::businessAddressStreetLabel() 691QString Addressee::businessAddressStreetLabel()
691{ 692{
692 return i18n("Business Address Street"); 693 return i18n("Business Address Street");
693} 694}
694 695
695 696
696QString Addressee::businessAddressLocalityLabel() 697QString Addressee::businessAddressLocalityLabel()
697{ 698{
698 return i18n("Business Address Locality"); 699 return i18n("Business Address Locality");
699} 700}
700 701
701 702
702QString Addressee::businessAddressRegionLabel() 703QString Addressee::businessAddressRegionLabel()
703{ 704{
704 return i18n("Business Address Region"); 705 return i18n("Business Address Region");
705} 706}
706 707
707 708
708QString Addressee::businessAddressPostalCodeLabel() 709QString Addressee::businessAddressPostalCodeLabel()
709{ 710{
710 return i18n("Business Address Postal Code"); 711 return i18n("Business Address Postal Code");
711} 712}
712 713
713 714
714QString Addressee::businessAddressCountryLabel() 715QString Addressee::businessAddressCountryLabel()
715{ 716{
716 return i18n("Business Address Country"); 717 return i18n("Business Address Country");
717} 718}
718 719
719 720
720QString Addressee::businessAddressLabelLabel() 721QString Addressee::businessAddressLabelLabel()
721{ 722{
722 return i18n("Business Address Label"); 723 return i18n("Business Address Label");
723} 724}
724 725
725 726
726QString Addressee::homePhoneLabel() 727QString Addressee::homePhoneLabel()
727{ 728{
728 return i18n("Home Phone"); 729 return i18n("Home Phone");
729} 730}
730 731
731 732
732QString Addressee::businessPhoneLabel() 733QString Addressee::businessPhoneLabel()
733{ 734{
734 return i18n("Business Phone"); 735 return i18n("Business Phone");
735} 736}
736 737
737 738
738QString Addressee::mobilePhoneLabel() 739QString Addressee::mobilePhoneLabel()
739{ 740{
740 return i18n("Mobile Phone"); 741 return i18n("Mobile Phone");
741} 742}
742 743
743 744
744QString Addressee::homeFaxLabel() 745QString Addressee::homeFaxLabel()
745{ 746{
746 return i18n("Home Fax"); 747 return i18n("Home Fax");
747} 748}
748 749
749 750
750QString Addressee::businessFaxLabel() 751QString Addressee::businessFaxLabel()
751{ 752{
752 return i18n("Business Fax"); 753 return i18n("Business Fax");
753} 754}
754 755
755 756
756QString Addressee::carPhoneLabel() 757QString Addressee::carPhoneLabel()
757{ 758{
758 return i18n("Car Phone"); 759 return i18n("Car Phone");
759} 760}
760 761
761 762
762QString Addressee::isdnLabel() 763QString Addressee::isdnLabel()
763{ 764{
764 return i18n("ISDN"); 765 return i18n("ISDN");
765} 766}
766 767
767 768
768QString Addressee::pagerLabel() 769QString Addressee::pagerLabel()
769{ 770{
770 return i18n("Pager"); 771 return i18n("Pager");
771} 772}
772 773
773QString Addressee::sipLabel() 774QString Addressee::sipLabel()
774{ 775{
775 return i18n("SIP"); 776 return i18n("SIP");
776} 777}
777 778
778QString Addressee::emailLabel() 779QString Addressee::emailLabel()
779{ 780{
780 return i18n("Email Address"); 781 return i18n("Email Address");
781} 782}
782 783
783 784
784void Addressee::setMailer( const QString &mailer ) 785void Addressee::setMailer( const QString &mailer )
785{ 786{
786 if ( mailer == mData->mailer ) return; 787 if ( mailer == mData->mailer ) return;
787 detach(); 788 detach();
788 mData->empty = false; 789 mData->empty = false;
789 mData->mailer = mailer; 790 mData->mailer = mailer;
790} 791}
791 792
792QString Addressee::mailer() const 793QString Addressee::mailer() const
793{ 794{
794 return mData->mailer; 795 return mData->mailer;
795} 796}
796 797
797QString Addressee::mailerLabel() 798QString Addressee::mailerLabel()
798{ 799{
799 return i18n("Mail Client"); 800 return i18n("Mail Client");
800} 801}
801 802
802 803
803void Addressee::setTimeZone( const TimeZone &timeZone ) 804void Addressee::setTimeZone( const TimeZone &timeZone )
804{ 805{
805 if ( timeZone == mData->timeZone ) return; 806 if ( timeZone == mData->timeZone ) return;
806 detach(); 807 detach();
807 mData->empty = false; 808 mData->empty = false;
808 mData->timeZone = timeZone; 809 mData->timeZone = timeZone;
809} 810}
810 811
811TimeZone Addressee::timeZone() const 812TimeZone Addressee::timeZone() const
812{ 813{
813 return mData->timeZone; 814 return mData->timeZone;
814} 815}
815 816
816QString Addressee::timeZoneLabel() 817QString Addressee::timeZoneLabel()
817{ 818{
818 return i18n("Time Zone"); 819 return i18n("Time Zone");
819} 820}
820 821
821 822
822void Addressee::setGeo( const Geo &geo ) 823void Addressee::setGeo( const Geo &geo )
823{ 824{
824 if ( geo == mData->geo ) return; 825 if ( geo == mData->geo ) return;
825 detach(); 826 detach();
826 mData->empty = false; 827 mData->empty = false;
827 mData->geo = geo; 828 mData->geo = geo;
828} 829}
829 830
830Geo Addressee::geo() const 831Geo Addressee::geo() const
831{ 832{
832 return mData->geo; 833 return mData->geo;
833} 834}
834 835
835QString Addressee::geoLabel() 836QString Addressee::geoLabel()
836{ 837{
837 return i18n("Geographic Position"); 838 return i18n("Geographic Position");
838} 839}
839 840
840 841
841void Addressee::setTitle( const QString &title ) 842void Addressee::setTitle( const QString &title )
842{ 843{
843 if ( title == mData->title ) return; 844 if ( title == mData->title ) return;
844 detach(); 845 detach();
845 mData->empty = false; 846 mData->empty = false;
846 mData->title = title; 847 mData->title = title;
847} 848}
848 849
849QString Addressee::title() const 850QString Addressee::title() const
850{ 851{
851 return mData->title; 852 return mData->title;
852} 853}
853 854
854QString Addressee::titleLabel() 855QString Addressee::titleLabel()
855{ 856{
856 return i18n("Title"); 857 return i18n("Title");
857} 858}
858 859
859 860
860void Addressee::setRole( const QString &role ) 861void Addressee::setRole( const QString &role )
861{ 862{
862 if ( role == mData->role ) return; 863 if ( role == mData->role ) return;
863 detach(); 864 detach();
864 mData->empty = false; 865 mData->empty = false;
865 mData->role = role; 866 mData->role = role;
866} 867}
867 868
868QString Addressee::role() const 869QString Addressee::role() const
869{ 870{
870 return mData->role; 871 return mData->role;
871} 872}
872 873
873QString Addressee::roleLabel() 874QString Addressee::roleLabel()
874{ 875{
875 return i18n("Role"); 876 return i18n("Role");
876} 877}
877 878
878 879
879void Addressee::setOrganization( const QString &organization ) 880void Addressee::setOrganization( const QString &organization )
880{ 881{
881 if ( organization == mData->organization ) return; 882 if ( organization == mData->organization ) return;
882 detach(); 883 detach();
883 mData->empty = false; 884 mData->empty = false;
884 mData->organization = organization; 885 mData->organization = organization;
885} 886}
886 887
887QString Addressee::organization() const 888QString Addressee::organization() const
888{ 889{
889 return mData->organization; 890 return mData->organization;
890} 891}
891 892
892QString Addressee::organizationLabel() 893QString Addressee::organizationLabel()
893{ 894{
894 return i18n("Organization"); 895 return i18n("Organization");
895} 896}
896 897
897 898
898void Addressee::setNote( const QString &note ) 899void Addressee::setNote( const QString &note )
899{ 900{
900 if ( note == mData->note ) return; 901 if ( note == mData->note ) return;
901 detach(); 902 detach();
902 mData->empty = false; 903 mData->empty = false;
903 mData->note = note; 904 mData->note = note;
904} 905}
905 906
906QString Addressee::note() const 907QString Addressee::note() const
907{ 908{
908 return mData->note; 909 return mData->note;
909} 910}
910 911
911QString Addressee::noteLabel() 912QString Addressee::noteLabel()
912{ 913{
913 return i18n("Note"); 914 return i18n("Note");
914} 915}
915 916
916 917
917void Addressee::setProductId( const QString &productId ) 918void Addressee::setProductId( const QString &productId )
918{ 919{
919 if ( productId == mData->productId ) return; 920 if ( productId == mData->productId ) return;
920 detach(); 921 detach();
921 mData->empty = false; 922 mData->empty = false;
922 mData->productId = productId; 923 mData->productId = productId;
923} 924}
924 925
925QString Addressee::productId() const 926QString Addressee::productId() const
926{ 927{
927 return mData->productId; 928 return mData->productId;
928} 929}
929 930
930QString Addressee::productIdLabel() 931QString Addressee::productIdLabel()
931{ 932{
932 return i18n("Product Identifier"); 933 return i18n("Product Identifier");
933} 934}
934 935
935 936
936void Addressee::setRevision( const QDateTime &revision ) 937void Addressee::setRevision( const QDateTime &revision )
937{ 938{
938 if ( revision == mData->revision ) return; 939 if ( revision == mData->revision ) return;
939 detach(); 940 detach();
940 mData->empty = false; 941 mData->empty = false;
941 mData->revision = revision; 942 mData->revision = revision;
942} 943}
943 944
944QDateTime Addressee::revision() const 945QDateTime Addressee::revision() const
945{ 946{
946 return mData->revision; 947 return mData->revision;
947} 948}
948 949
949QString Addressee::revisionLabel() 950QString Addressee::revisionLabel()
950{ 951{
951 return i18n("Revision Date"); 952 return i18n("Revision Date");
952} 953}
953 954
954 955
955void Addressee::setSortString( const QString &sortString ) 956void Addressee::setSortString( const QString &sortString )
956{ 957{
957 if ( sortString == mData->sortString ) return; 958 if ( sortString == mData->sortString ) return;
958 detach(); 959 detach();
959 mData->empty = false; 960 mData->empty = false;
960 mData->sortString = sortString; 961 mData->sortString = sortString;
961} 962}
962 963
963QString Addressee::sortString() const 964QString Addressee::sortString() const
964{ 965{
965 return mData->sortString; 966 return mData->sortString;
966} 967}
967 968
968QString Addressee::sortStringLabel() 969QString Addressee::sortStringLabel()
969{ 970{
970 return i18n("Sort String"); 971 return i18n("Sort String");
971} 972}
972 973
973 974
974void Addressee::setUrl( const KURL &url ) 975void Addressee::setUrl( const KURL &url )
975{ 976{
976 if ( url == mData->url ) return; 977 if ( url == mData->url ) return;
977 detach(); 978 detach();
978 mData->empty = false; 979 mData->empty = false;
979 mData->url = url; 980 mData->url = url;
980} 981}
981 982
982KURL Addressee::url() const 983KURL Addressee::url() const
983{ 984{
984 return mData->url; 985 return mData->url;
985} 986}
986 987
987QString Addressee::urlLabel() 988QString Addressee::urlLabel()
988{ 989{
989 return i18n("URL"); 990 return i18n("URL");
990} 991}
991 992
992 993
993void Addressee::setSecrecy( const Secrecy &secrecy ) 994void Addressee::setSecrecy( const Secrecy &secrecy )
994{ 995{
995 if ( secrecy == mData->secrecy ) return; 996 if ( secrecy == mData->secrecy ) return;
996 detach(); 997 detach();
997 mData->empty = false; 998 mData->empty = false;
998 mData->secrecy = secrecy; 999 mData->secrecy = secrecy;
999} 1000}
1000 1001
1001Secrecy Addressee::secrecy() const 1002Secrecy Addressee::secrecy() const
1002{ 1003{
1003 return mData->secrecy; 1004 return mData->secrecy;
1004} 1005}
1005 1006
1006QString Addressee::secrecyLabel() 1007QString Addressee::secrecyLabel()
1007{ 1008{
1008 return i18n("Security Class"); 1009 return i18n("Security Class");
1009} 1010}
1010 1011
1011 1012
1012void Addressee::setLogo( const Picture &logo ) 1013void Addressee::setLogo( const Picture &logo )
1013{ 1014{
1014 if ( logo == mData->logo ) return; 1015 if ( logo == mData->logo ) return;
1015 detach(); 1016 detach();
1016 mData->empty = false; 1017 mData->empty = false;
1017 mData->logo = logo; 1018 mData->logo = logo;
1018} 1019}
1019 1020
1020Picture Addressee::logo() const 1021Picture Addressee::logo() const
1021{ 1022{
1022 return mData->logo; 1023 return mData->logo;
1023} 1024}
1024 1025
1025QString Addressee::logoLabel() 1026QString Addressee::logoLabel()
1026{ 1027{
1027 return i18n("Logo"); 1028 return i18n("Logo");
1028} 1029}
1029 1030
1030 1031
1031void Addressee::setPhoto( const Picture &photo ) 1032void Addressee::setPhoto( const Picture &photo )
1032{ 1033{
1033 if ( photo == mData->photo ) return; 1034 if ( photo == mData->photo ) return;
1034 detach(); 1035 detach();
1035 mData->empty = false; 1036 mData->empty = false;
1036 mData->photo = photo; 1037 mData->photo = photo;
1037} 1038}
1038 1039
1039Picture Addressee::photo() const 1040Picture Addressee::photo() const
1040{ 1041{
1041 return mData->photo; 1042 return mData->photo;
1042} 1043}
1043 1044
1044QString Addressee::photoLabel() 1045QString Addressee::photoLabel()
1045{ 1046{
1046 return i18n("Photo"); 1047 return i18n("Photo");
1047} 1048}
1048 1049
1049 1050
1050void Addressee::setSound( const Sound &sound ) 1051void Addressee::setSound( const Sound &sound )
1051{ 1052{
1052 if ( sound == mData->sound ) return; 1053 if ( sound == mData->sound ) return;
1053 detach(); 1054 detach();
1054 mData->empty = false; 1055 mData->empty = false;
1055 mData->sound = sound; 1056 mData->sound = sound;
1056} 1057}
1057 1058
1058Sound Addressee::sound() const 1059Sound Addressee::sound() const
1059{ 1060{
1060 return mData->sound; 1061 return mData->sound;
1061} 1062}
1062 1063
1063QString Addressee::soundLabel() 1064QString Addressee::soundLabel()
1064{ 1065{
1065 return i18n("Sound"); 1066 return i18n("Sound");
1066} 1067}
1067 1068
1068 1069
1069void Addressee::setAgent( const Agent &agent ) 1070void Addressee::setAgent( const Agent &agent )
1070{ 1071{
1071 if ( agent == mData->agent ) return; 1072 if ( agent == mData->agent ) return;
1072 detach(); 1073 detach();
1073 mData->empty = false; 1074 mData->empty = false;
1074 mData->agent = agent; 1075 mData->agent = agent;
1075} 1076}
1076 1077
1077Agent Addressee::agent() const 1078Agent Addressee::agent() const
1078{ 1079{
1079 return mData->agent; 1080 return mData->agent;
1080} 1081}
1081 1082
1082QString Addressee::agentLabel() 1083QString Addressee::agentLabel()
1083{ 1084{
1084 return i18n("Agent"); 1085 return i18n("Agent");
1085} 1086}
1086 1087
1087 1088
1088 1089
1089void Addressee::setNameFromString( const QString &str ) 1090void Addressee::setNameFromString( const QString &str )
1090{ 1091{
1091 setFormattedName( str ); 1092 setFormattedName( str );
1092 setName( str ); 1093 setName( str );
1093 1094
1094 static bool first = true; 1095 static bool first = true;
1095 static QStringList titles; 1096 static QStringList titles;
1096 static QStringList suffixes; 1097 static QStringList suffixes;
1097 static QStringList prefixes; 1098 static QStringList prefixes;
1098 1099
1099 if ( first ) { 1100 if ( first ) {
1100 first = false; 1101 first = false;
1101 titles += i18n( "Dr." ); 1102 titles += i18n( "Dr." );
1102 titles += i18n( "Miss" ); 1103 titles += i18n( "Miss" );
1103 titles += i18n( "Mr." ); 1104 titles += i18n( "Mr." );
1104 titles += i18n( "Mrs." ); 1105 titles += i18n( "Mrs." );
1105 titles += i18n( "Ms." ); 1106 titles += i18n( "Ms." );
1106 titles += i18n( "Prof." ); 1107 titles += i18n( "Prof." );
1107 1108
1108 suffixes += i18n( "I" ); 1109 suffixes += i18n( "I" );
1109 suffixes += i18n( "II" ); 1110 suffixes += i18n( "II" );
1110 suffixes += i18n( "III" ); 1111 suffixes += i18n( "III" );
1111 suffixes += i18n( "Jr." ); 1112 suffixes += i18n( "Jr." );
1112 suffixes += i18n( "Sr." ); 1113 suffixes += i18n( "Sr." );
1113 1114
1114 prefixes += "van"; 1115 prefixes += "van";
1115 prefixes += "von"; 1116 prefixes += "von";
1116 prefixes += "de"; 1117 prefixes += "de";
1117 1118
1118 KConfig config( locateLocal( "config", "kabcrc") ); 1119 KConfig config( locateLocal( "config", "kabcrc") );
1119 config.setGroup( "General" ); 1120 config.setGroup( "General" );
1120 titles += config.readListEntry( "Prefixes" ); 1121 titles += config.readListEntry( "Prefixes" );
1121 titles.remove( "" ); 1122 titles.remove( "" );
1122 prefixes += config.readListEntry( "Inclusions" ); 1123 prefixes += config.readListEntry( "Inclusions" );
1123 prefixes.remove( "" ); 1124 prefixes.remove( "" );
1124 suffixes += config.readListEntry( "Suffixes" ); 1125 suffixes += config.readListEntry( "Suffixes" );
1125 suffixes.remove( "" ); 1126 suffixes.remove( "" );
1126 } 1127 }
1127 1128
1128 // clear all name parts 1129 // clear all name parts
1129 setPrefix( "" ); 1130 setPrefix( "" );
1130 setGivenName( "" ); 1131 setGivenName( "" );
1131 setAdditionalName( "" ); 1132 setAdditionalName( "" );
1132 setFamilyName( "" ); 1133 setFamilyName( "" );
1133 setSuffix( "" ); 1134 setSuffix( "" );
1134 1135
1135 if ( str.isEmpty() ) 1136 if ( str.isEmpty() )
1136 return; 1137 return;
1137 1138
1138 int i = str.find(','); 1139 int i = str.find(',');
1139 if( i < 0 ) { 1140 if( i < 0 ) {
1140 QStringList parts = QStringList::split( " ", str ); 1141 QStringList parts = QStringList::split( " ", str );
1141 int leftOffset = 0; 1142 int leftOffset = 0;
1142 int rightOffset = parts.count() - 1; 1143 int rightOffset = parts.count() - 1;
1143 1144
1144 QString suffix; 1145 QString suffix;
1145 while ( rightOffset >= 0 ) { 1146 while ( rightOffset >= 0 ) {
1146 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1147 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1147 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1148 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1148 rightOffset--; 1149 rightOffset--;
1149 } else 1150 } else
1150 break; 1151 break;
1151 } 1152 }
1152 setSuffix( suffix ); 1153 setSuffix( suffix );
1153 1154
1154 if ( rightOffset < 0 ) 1155 if ( rightOffset < 0 )
1155 return; 1156 return;
1156 1157
1157 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1158 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1158 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1159 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1159 rightOffset--; 1160 rightOffset--;
1160 } else 1161 } else
1161 setFamilyName( parts[ rightOffset ] ); 1162 setFamilyName( parts[ rightOffset ] );
1162 1163
1163 QString prefix; 1164 QString prefix;
1164 while ( leftOffset < rightOffset ) { 1165 while ( leftOffset < rightOffset ) {
1165 if ( titles.contains( parts[ leftOffset ] ) ) { 1166 if ( titles.contains( parts[ leftOffset ] ) ) {
1166 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1167 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1167 leftOffset++; 1168 leftOffset++;
1168 } else 1169 } else
1169 break; 1170 break;
1170 } 1171 }
1171 setPrefix( prefix ); 1172 setPrefix( prefix );
1172 1173
1173 if ( leftOffset < rightOffset ) { 1174 if ( leftOffset < rightOffset ) {
1174 setGivenName( parts[ leftOffset ] ); 1175 setGivenName( parts[ leftOffset ] );
1175 leftOffset++; 1176 leftOffset++;
1176 } 1177 }
1177 1178
1178 QString additionalName; 1179 QString additionalName;
1179 while ( leftOffset < rightOffset ) { 1180 while ( leftOffset < rightOffset ) {
1180 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1181 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1181 leftOffset++; 1182 leftOffset++;
1182 } 1183 }
1183 setAdditionalName( additionalName ); 1184 setAdditionalName( additionalName );
1184 } else { 1185 } else {
1185 QString part1 = str.left( i ); 1186 QString part1 = str.left( i );
1186 QString part2 = str.mid( i + 1 ); 1187 QString part2 = str.mid( i + 1 );
1187 1188
1188 QStringList parts = QStringList::split( " ", part1 ); 1189 QStringList parts = QStringList::split( " ", part1 );
1189 int leftOffset = 0; 1190 int leftOffset = 0;
1190 int rightOffset = parts.count() - 1; 1191 int rightOffset = parts.count() - 1;
1191 1192
1192 QString suffix; 1193 QString suffix;
1193 while ( rightOffset >= 0 ) { 1194 while ( rightOffset >= 0 ) {
1194 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1195 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1195 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1196 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1196 rightOffset--; 1197 rightOffset--;
1197 } else 1198 } else
1198 break; 1199 break;
1199 } 1200 }
1200 setSuffix( suffix ); 1201 setSuffix( suffix );
1201 1202
1202 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1203 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1203 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1204 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1204 rightOffset--; 1205 rightOffset--;
1205 } else 1206 } else
1206 setFamilyName( parts[ rightOffset ] ); 1207 setFamilyName( parts[ rightOffset ] );
1207 1208
1208 QString prefix; 1209 QString prefix;
1209 while ( leftOffset < rightOffset ) { 1210 while ( leftOffset < rightOffset ) {
1210 if ( titles.contains( parts[ leftOffset ] ) ) { 1211 if ( titles.contains( parts[ leftOffset ] ) ) {
1211 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1212 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1212 leftOffset++; 1213 leftOffset++;
1213 } else 1214 } else
1214 break; 1215 break;
1215 } 1216 }
1216 1217
1217 parts = QStringList::split( " ", part2 ); 1218 parts = QStringList::split( " ", part2 );
1218 1219
1219 leftOffset = 0; 1220 leftOffset = 0;
1220 rightOffset = parts.count(); 1221 rightOffset = parts.count();
1221 1222
1222 while ( leftOffset < rightOffset ) { 1223 while ( leftOffset < rightOffset ) {
1223 if ( titles.contains( parts[ leftOffset ] ) ) { 1224 if ( titles.contains( parts[ leftOffset ] ) ) {
1224 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1225 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1225 leftOffset++; 1226 leftOffset++;
1226 } else 1227 } else
1227 break; 1228 break;
1228 } 1229 }
1229 setPrefix( prefix ); 1230 setPrefix( prefix );
1230 1231
1231 if ( leftOffset < rightOffset ) { 1232 if ( leftOffset < rightOffset ) {
1232 setGivenName( parts[ leftOffset ] ); 1233 setGivenName( parts[ leftOffset ] );
1233 leftOffset++; 1234 leftOffset++;
1234 } 1235 }
1235 1236
1236 QString additionalName; 1237 QString additionalName;
1237 while ( leftOffset < rightOffset ) { 1238 while ( leftOffset < rightOffset ) {
1238 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1239 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1239 leftOffset++; 1240 leftOffset++;
1240 } 1241 }
1241 setAdditionalName( additionalName ); 1242 setAdditionalName( additionalName );
1242 } 1243 }
1243} 1244}
1244 1245
1245QString Addressee::realName() const 1246QString Addressee::realName() const
1246{ 1247{
1247 if ( !formattedName().isEmpty() ) 1248 if ( !formattedName().isEmpty() )
1248 return formattedName(); 1249 return formattedName();
1249 1250
1250 QString n = assembledName(); 1251 QString n = assembledName();
1251 1252
1252 if ( n.isEmpty() ) 1253 if ( n.isEmpty() )
1253 n = name(); 1254 n = name();
1254 1255
1255 return n; 1256 return n;
1256} 1257}
1257 1258
1258QString Addressee::assembledName() const 1259QString Addressee::assembledName() const
1259{ 1260{
1260 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1261 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1261 familyName() + " " + suffix(); 1262 familyName() + " " + suffix();
1262 1263
1263 return name.simplifyWhiteSpace(); 1264 return name.simplifyWhiteSpace();
1264} 1265}
1265 1266
1266QString Addressee::fullEmail( const QString &email ) const 1267QString Addressee::fullEmail( const QString &email ) const
1267{ 1268{
1268 QString e; 1269 QString e;
1269 if ( email.isNull() ) { 1270 if ( email.isNull() ) {
1270 e = preferredEmail(); 1271 e = preferredEmail();
1271 } else { 1272 } else {
1272 e = email; 1273 e = email;
1273 } 1274 }
1274 if ( e.isEmpty() ) return QString::null; 1275 if ( e.isEmpty() ) return QString::null;
1275 1276
1276 QString text; 1277 QString text;
1277 if ( realName().isEmpty() ) 1278 if ( realName().isEmpty() )
1278 text = e; 1279 text = e;
1279 else 1280 else
1280 text = assembledName() + " <" + e + ">"; 1281 text = assembledName() + " <" + e + ">";
1281 1282
1282 return text; 1283 return text;
1283} 1284}
1284 1285
1285void Addressee::insertEmail( const QString &email, bool preferred ) 1286void Addressee::insertEmail( const QString &email, bool preferred )
1286{ 1287{
1287 detach(); 1288 detach();
1288 1289
1289 QStringList::Iterator it = mData->emails.find( email ); 1290 QStringList::Iterator it = mData->emails.find( email );
1290 1291
1291 if ( it != mData->emails.end() ) { 1292 if ( it != mData->emails.end() ) {
1292 if ( !preferred || it == mData->emails.begin() ) return; 1293 if ( !preferred || it == mData->emails.begin() ) return;
1293 mData->emails.remove( it ); 1294 mData->emails.remove( it );
1294 mData->emails.prepend( email ); 1295 mData->emails.prepend( email );
1295 } else { 1296 } else {
1296 if ( preferred ) { 1297 if ( preferred ) {
1297 mData->emails.prepend( email ); 1298 mData->emails.prepend( email );
1298 } else { 1299 } else {
1299 mData->emails.append( email ); 1300 mData->emails.append( email );
1300 } 1301 }
1301 } 1302 }
1302} 1303}
1303 1304
1304void Addressee::removeEmail( const QString &email ) 1305void Addressee::removeEmail( const QString &email )
1305{ 1306{
1306 detach(); 1307 detach();
1307 1308
1308 QStringList::Iterator it = mData->emails.find( email ); 1309 QStringList::Iterator it = mData->emails.find( email );
1309 if ( it == mData->emails.end() ) return; 1310 if ( it == mData->emails.end() ) return;
1310 1311
1311 mData->emails.remove( it ); 1312 mData->emails.remove( it );
1312} 1313}
1313 1314
1314QString Addressee::preferredEmail() const 1315QString Addressee::preferredEmail() const
1315{ 1316{
1316 if ( mData->emails.count() == 0 ) return QString::null; 1317 if ( mData->emails.count() == 0 ) return QString::null;
1317 else return mData->emails.first(); 1318 else return mData->emails.first();
1318} 1319}
1319 1320
1320QStringList Addressee::emails() const 1321QStringList Addressee::emails() const
1321{ 1322{
1322 return mData->emails; 1323 return mData->emails;
1323} 1324}
1324void Addressee::setEmails( const QStringList& emails ) { 1325void Addressee::setEmails( const QStringList& emails ) {
1325 detach(); 1326 detach();
1326 mData->emails = emails; 1327 mData->emails = emails;
1327} 1328}
1328void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1329void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1329{ 1330{
1330 detach(); 1331 detach();
1331 mData->empty = false; 1332 mData->empty = false;
1332 1333
1333 PhoneNumber::List::Iterator it; 1334 PhoneNumber::List::Iterator it;
1334 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1335 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1335 if ( (*it).id() == phoneNumber.id() ) { 1336 if ( (*it).id() == phoneNumber.id() ) {
1336 *it = phoneNumber; 1337 *it = phoneNumber;
1337 return; 1338 return;
1338 } 1339 }
1339 } 1340 }
1340 mData->phoneNumbers.append( phoneNumber ); 1341 mData->phoneNumbers.append( phoneNumber );
1341} 1342}
1342 1343
1343void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1344void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1344{ 1345{
1345 detach(); 1346 detach();
1346 1347
1347 PhoneNumber::List::Iterator it; 1348 PhoneNumber::List::Iterator it;
1348 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1349 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1349 if ( (*it).id() == phoneNumber.id() ) { 1350 if ( (*it).id() == phoneNumber.id() ) {
1350 mData->phoneNumbers.remove( it ); 1351 mData->phoneNumbers.remove( it );
1351 return; 1352 return;
1352 } 1353 }
1353 } 1354 }
1354} 1355}
1355 1356
1356PhoneNumber Addressee::phoneNumber( int type ) const 1357PhoneNumber Addressee::phoneNumber( int type ) const
1357{ 1358{
1358 PhoneNumber phoneNumber( "", type ); 1359 PhoneNumber phoneNumber( "", type );
1359 PhoneNumber::List::ConstIterator it; 1360 PhoneNumber::List::ConstIterator it;
1360 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1361 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1361 if ( matchBinaryPatternP( (*it).type(), type ) ) { 1362 if ( matchBinaryPatternP( (*it).type(), type ) ) {
1362 if ( (*it).type() & PhoneNumber::Pref ) 1363 if ( (*it).type() & PhoneNumber::Pref )
1363 return (*it); 1364 return (*it);
1364 else if ( phoneNumber.number().isEmpty() ) 1365 else if ( phoneNumber.number().isEmpty() )
1365 phoneNumber = (*it); 1366 phoneNumber = (*it);
1366 } 1367 }
1367 } 1368 }
1368 1369
1369 return phoneNumber; 1370 return phoneNumber;
1370} 1371}
1371 1372
1372PhoneNumber::List Addressee::phoneNumbers() const 1373PhoneNumber::List Addressee::phoneNumbers() const
1373{ 1374{
1374 return mData->phoneNumbers; 1375 return mData->phoneNumbers;
1375} 1376}
1376 1377
1377PhoneNumber::List Addressee::phoneNumbers( int type ) const 1378PhoneNumber::List Addressee::phoneNumbers( int type ) const
1378{ 1379{
1379 PhoneNumber::List list; 1380 PhoneNumber::List list;
1380 1381
1381 PhoneNumber::List::ConstIterator it; 1382 PhoneNumber::List::ConstIterator it;
1382 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1383 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1383 if ( matchBinaryPattern( (*it).type(), type ) ) { 1384 if ( matchBinaryPattern( (*it).type(), type ) ) {
1384 list.append( *it ); 1385 list.append( *it );
1385 } 1386 }
1386 } 1387 }
1387 return list; 1388 return list;
1388} 1389}
1389 1390
1390PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1391PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1391{ 1392{
1392 PhoneNumber::List::ConstIterator it; 1393 PhoneNumber::List::ConstIterator it;
1393 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1394 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1394 if ( (*it).id() == id ) { 1395 if ( (*it).id() == id ) {
1395 return *it; 1396 return *it;
1396 } 1397 }
1397 } 1398 }
1398 return PhoneNumber(); 1399 return PhoneNumber();
1399} 1400}
1400 1401
1401void Addressee::insertKey( const Key &key ) 1402void Addressee::insertKey( const Key &key )
1402{ 1403{
1403 detach(); 1404 detach();
1404 mData->empty = false; 1405 mData->empty = false;
1405 1406
1406 Key::List::Iterator it; 1407 Key::List::Iterator it;
1407 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1408 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1408 if ( (*it).id() == key.id() ) { 1409 if ( (*it).id() == key.id() ) {
1409 *it = key; 1410 *it = key;
1410 return; 1411 return;
1411 } 1412 }
1412 } 1413 }
1413 mData->keys.append( key ); 1414 mData->keys.append( key );
1414} 1415}
1415 1416
1416void Addressee::removeKey( const Key &key ) 1417void Addressee::removeKey( const Key &key )
1417{ 1418{
1418 detach(); 1419 detach();
1419 1420
1420 Key::List::Iterator it; 1421 Key::List::Iterator it;
1421 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1422 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1422 if ( (*it).id() == key.id() ) { 1423 if ( (*it).id() == key.id() ) {
1423 mData->keys.remove( key ); 1424 mData->keys.remove( key );
1424 return; 1425 return;
1425 } 1426 }
1426 } 1427 }
1427} 1428}
1428 1429
1429Key Addressee::key( int type, QString customTypeString ) const 1430Key Addressee::key( int type, QString customTypeString ) const
1430{ 1431{
1431 Key::List::ConstIterator it; 1432 Key::List::ConstIterator it;
1432 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1433 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1433 if ( (*it).type() == type ) { 1434 if ( (*it).type() == type ) {
1434 if ( type == Key::Custom ) { 1435 if ( type == Key::Custom ) {
1435 if ( customTypeString.isEmpty() ) { 1436 if ( customTypeString.isEmpty() ) {
1436 return *it; 1437 return *it;
1437 } else { 1438 } else {
1438 if ( (*it).customTypeString() == customTypeString ) 1439 if ( (*it).customTypeString() == customTypeString )
1439 return (*it); 1440 return (*it);
1440 } 1441 }
1441 } else { 1442 } else {
1442 return *it; 1443 return *it;
1443 } 1444 }
1444 } 1445 }
1445 } 1446 }
1446 return Key( QString(), type ); 1447 return Key( QString(), type );
1447} 1448}
1448void Addressee::setKeys( const Key::List& list ) { 1449void Addressee::setKeys( const Key::List& list ) {
1449 detach(); 1450 detach();
1450 mData->keys = list; 1451 mData->keys = list;
1451} 1452}
1452 1453
1453Key::List Addressee::keys() const 1454Key::List Addressee::keys() const
1454{ 1455{
1455 return mData->keys; 1456 return mData->keys;
1456} 1457}
1457 1458
1458Key::List Addressee::keys( int type, QString customTypeString ) const 1459Key::List Addressee::keys( int type, QString customTypeString ) const
1459{ 1460{
1460 Key::List list; 1461 Key::List list;
1461 1462
1462 Key::List::ConstIterator it; 1463 Key::List::ConstIterator it;
1463 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1464 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1464 if ( (*it).type() == type ) { 1465 if ( (*it).type() == type ) {
1465 if ( type == Key::Custom ) { 1466 if ( type == Key::Custom ) {
1466 if ( customTypeString.isEmpty() ) { 1467 if ( customTypeString.isEmpty() ) {
1467 list.append(*it); 1468 list.append(*it);
1468 } else { 1469 } else {
1469 if ( (*it).customTypeString() == customTypeString ) 1470 if ( (*it).customTypeString() == customTypeString )
1470 list.append(*it); 1471 list.append(*it);
1471 } 1472 }
1472 } else { 1473 } else {
1473 list.append(*it); 1474 list.append(*it);
1474 } 1475 }
1475 } 1476 }
1476 } 1477 }
1477 return list; 1478 return list;
1478} 1479}
1479 1480
1480Key Addressee::findKey( const QString &id ) const 1481Key Addressee::findKey( const QString &id ) const
1481{ 1482{
1482 Key::List::ConstIterator it; 1483 Key::List::ConstIterator it;
1483 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1484 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1484 if ( (*it).id() == id ) { 1485 if ( (*it).id() == id ) {
1485 return *it; 1486 return *it;
1486 } 1487 }
1487 } 1488 }
1488 return Key(); 1489 return Key();
1489} 1490}
1490 1491
1491QString Addressee::asString() const 1492QString Addressee::asString() const
1492{ 1493{
1493 return "Smith, agent Smith..."; 1494 return "Smith, agent Smith...";
1494} 1495}
1495 1496
1496void Addressee::dump() const 1497void Addressee::dump() const
1497{ 1498{
1498 return; 1499 return;
1499 kdDebug(5700) << "Addressee {" << endl; 1500 kdDebug(5700) << "Addressee {" << endl;
1500 1501
1501 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1502 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1502 1503
1503 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1504 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1504 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1505 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1505 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1506 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1506 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1507 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1507 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1508 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1508 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1509 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1509 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1510 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1510 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1511 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1511 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1512 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1512 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1513 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1513 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1514 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1514 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1515 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1515 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1516 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1516 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1517 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1517 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1518 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1518 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1519 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1519 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1520 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1520 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1521 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1521 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1522 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1522 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1523 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1523 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1524 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1524 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1525 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1525 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1526 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1526 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1527 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1527 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1528 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1528 1529
1529 kdDebug(5700) << " Emails {" << endl; 1530 kdDebug(5700) << " Emails {" << endl;
1530 QStringList e = emails(); 1531 QStringList e = emails();
1531 QStringList::ConstIterator it; 1532 QStringList::ConstIterator it;
1532 for( it = e.begin(); it != e.end(); ++it ) { 1533 for( it = e.begin(); it != e.end(); ++it ) {
1533 kdDebug(5700) << " " << (*it) << endl; 1534 kdDebug(5700) << " " << (*it) << endl;
1534 } 1535 }
1535 kdDebug(5700) << " }" << endl; 1536 kdDebug(5700) << " }" << endl;
1536 1537
1537 kdDebug(5700) << " PhoneNumbers {" << endl; 1538 kdDebug(5700) << " PhoneNumbers {" << endl;
1538 PhoneNumber::List p = phoneNumbers(); 1539 PhoneNumber::List p = phoneNumbers();
1539 PhoneNumber::List::ConstIterator it2; 1540 PhoneNumber::List::ConstIterator it2;
1540 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1541 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1541 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1542 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1542 } 1543 }
1543 kdDebug(5700) << " }" << endl; 1544 kdDebug(5700) << " }" << endl;
1544 1545
1545 Address::List a = addresses(); 1546 Address::List a = addresses();
1546 Address::List::ConstIterator it3; 1547 Address::List::ConstIterator it3;
1547 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1548 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1548 (*it3).dump(); 1549 (*it3).dump();
1549 } 1550 }
1550 1551
1551 kdDebug(5700) << " Keys {" << endl; 1552 kdDebug(5700) << " Keys {" << endl;
1552 Key::List k = keys(); 1553 Key::List k = keys();
1553 Key::List::ConstIterator it4; 1554 Key::List::ConstIterator it4;
1554 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1555 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1555 kdDebug(5700) << " Type: " << int((*it4).type()) << 1556 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1556 " Key: " << (*it4).textData() << 1557 " Key: " << (*it4).textData() <<
1557 " CustomString: " << (*it4).customTypeString() << endl; 1558 " CustomString: " << (*it4).customTypeString() << endl;
1558 } 1559 }
1559 kdDebug(5700) << " }" << endl; 1560 kdDebug(5700) << " }" << endl;
1560 1561
1561 kdDebug(5700) << "}" << endl; 1562 kdDebug(5700) << "}" << endl;
1562} 1563}
1563 1564
1564 1565
1565void Addressee::insertAddress( const Address &address ) 1566void Addressee::insertAddress( const Address &address )
1566{ 1567{
1567 detach(); 1568 detach();
1568 mData->empty = false; 1569 mData->empty = false;
1569 1570
1570 Address::List::Iterator it; 1571 Address::List::Iterator it;
1571 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1572 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1572 if ( (*it).id() == address.id() ) { 1573 if ( (*it).id() == address.id() ) {
1573 *it = address; 1574 *it = address;
1574 return; 1575 return;
1575 } 1576 }
1576 } 1577 }
1577 mData->addresses.append( address ); 1578 mData->addresses.append( address );
1578} 1579}
1579 1580
1580void Addressee::removeAddress( const Address &address ) 1581void Addressee::removeAddress( const Address &address )
1581{ 1582{
1582 detach(); 1583 detach();
1583 1584
1584 Address::List::Iterator it; 1585 Address::List::Iterator it;
1585 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1586 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1586 if ( (*it).id() == address.id() ) { 1587 if ( (*it).id() == address.id() ) {
1587 mData->addresses.remove( it ); 1588 mData->addresses.remove( it );
1588 return; 1589 return;
1589 } 1590 }
1590 } 1591 }
1591} 1592}
1592 1593
1593Address Addressee::address( int type ) const 1594Address Addressee::address( int type ) const
1594{ 1595{
1595 Address address( type ); 1596 Address address( type );
1596 Address::List::ConstIterator it; 1597 Address::List::ConstIterator it;
1597 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1598 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1598 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1599 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1599 if ( (*it).type() & Address::Pref ) 1600 if ( (*it).type() & Address::Pref )
1600 return (*it); 1601 return (*it);
1601 else if ( address.isEmpty() ) 1602 else if ( address.isEmpty() )
1602 address = (*it); 1603 address = (*it);
1603 } 1604 }
1604 } 1605 }
1605 1606
1606 return address; 1607 return address;
1607} 1608}
1608 1609
1609Address::List Addressee::addresses() const 1610Address::List Addressee::addresses() const
1610{ 1611{
1611 return mData->addresses; 1612 return mData->addresses;
1612} 1613}
1613 1614
1614Address::List Addressee::addresses( int type ) const 1615Address::List Addressee::addresses( int type ) const
1615{ 1616{
1616 Address::List list; 1617 Address::List list;
1617 1618
1618 Address::List::ConstIterator it; 1619 Address::List::ConstIterator it;
1619 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1620 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1620 if ( matchBinaryPattern( (*it).type(), type ) ) { 1621 if ( matchBinaryPattern( (*it).type(), type ) ) {
1621 list.append( *it ); 1622 list.append( *it );
1622 } 1623 }
1623 } 1624 }
1624 1625
1625 return list; 1626 return list;
1626} 1627}
1627 1628
1628Address Addressee::findAddress( const QString &id ) const 1629Address Addressee::findAddress( const QString &id ) const
1629{ 1630{
1630 Address::List::ConstIterator it; 1631 Address::List::ConstIterator it;
1631 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1632 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1632 if ( (*it).id() == id ) { 1633 if ( (*it).id() == id ) {
1633 return *it; 1634 return *it;
1634 } 1635 }
1635 } 1636 }
1636 return Address(); 1637 return Address();
1637} 1638}
1638 1639
1639void Addressee::insertCategory( const QString &c ) 1640void Addressee::insertCategory( const QString &c )
1640{ 1641{
1641 detach(); 1642 detach();
1642 mData->empty = false; 1643 mData->empty = false;
1643 1644
1644 if ( mData->categories.contains( c ) ) return; 1645 if ( mData->categories.contains( c ) ) return;
1645 1646
1646 mData->categories.append( c ); 1647 mData->categories.append( c );
1647} 1648}
1648 1649
1649void Addressee::removeCategory( const QString &c ) 1650void Addressee::removeCategory( const QString &c )
1650{ 1651{
1651 detach(); 1652 detach();
1652 1653
1653 QStringList::Iterator it = mData->categories.find( c ); 1654 QStringList::Iterator it = mData->categories.find( c );
1654 if ( it == mData->categories.end() ) return; 1655 if ( it == mData->categories.end() ) return;
1655 1656
1656 mData->categories.remove( it ); 1657 mData->categories.remove( it );
1657} 1658}
1658 1659
1659bool Addressee::hasCategory( const QString &c ) const 1660bool Addressee::hasCategory( const QString &c ) const
1660{ 1661{
1661 return ( mData->categories.contains( c ) ); 1662 return ( mData->categories.contains( c ) );
1662} 1663}
1663 1664
1664void Addressee::setCategories( const QStringList &c ) 1665void Addressee::setCategories( const QStringList &c )
1665{ 1666{
1666 detach(); 1667 detach();
1667 mData->empty = false; 1668 mData->empty = false;
1668 1669
1669 mData->categories = c; 1670 mData->categories = c;
1670} 1671}
1671 1672
1672QStringList Addressee::categories() const 1673QStringList Addressee::categories() const
1673{ 1674{
1674 return mData->categories; 1675 return mData->categories;
1675} 1676}
1676 1677
1677void Addressee::insertCustom( const QString &app, const QString &name, 1678void Addressee::insertCustom( const QString &app, const QString &name,
1678 const QString &value ) 1679 const QString &value )
1679{ 1680{
1680 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1681 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1681 1682
1682 detach(); 1683 detach();
1683 mData->empty = false; 1684 mData->empty = false;
1684 1685
1685 QString qualifiedName = app + "-" + name + ":"; 1686 QString qualifiedName = app + "-" + name + ":";
1686 1687
1687 QStringList::Iterator it; 1688 QStringList::Iterator it;
1688 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1689 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1689 if ( (*it).startsWith( qualifiedName ) ) { 1690 if ( (*it).startsWith( qualifiedName ) ) {
1690 (*it) = qualifiedName + value; 1691 (*it) = qualifiedName + value;
1691 return; 1692 return;
1692 } 1693 }
1693 } 1694 }
1694 mData->custom.append( qualifiedName + value ); 1695 mData->custom.append( qualifiedName + value );
1695} 1696}
1696 1697
1697void Addressee::removeCustom( const QString &app, const QString &name) 1698void Addressee::removeCustom( const QString &app, const QString &name)
1698{ 1699{
1699 detach(); 1700 detach();
1700 1701
1701 QString qualifiedName = app + "-" + name + ":"; 1702 QString qualifiedName = app + "-" + name + ":";
1702 1703
1703 QStringList::Iterator it; 1704 QStringList::Iterator it;
1704 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1705 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1705 if ( (*it).startsWith( qualifiedName ) ) { 1706 if ( (*it).startsWith( qualifiedName ) ) {
1706 mData->custom.remove( it ); 1707 mData->custom.remove( it );
1707 return; 1708 return;
1708 } 1709 }
1709 } 1710 }
1710} 1711}
1711 1712
1712QString Addressee::custom( const QString &app, const QString &name ) const 1713QString Addressee::custom( const QString &app, const QString &name ) const
1713{ 1714{
1714 QString qualifiedName = app + "-" + name + ":"; 1715 QString qualifiedName = app + "-" + name + ":";
1715 QString value; 1716 QString value;
1716 1717
1717 QStringList::ConstIterator it; 1718 QStringList::ConstIterator it;
1718 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1719 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1719 if ( (*it).startsWith( qualifiedName ) ) { 1720 if ( (*it).startsWith( qualifiedName ) ) {
1720 value = (*it).mid( (*it).find( ":" ) + 1 ); 1721 value = (*it).mid( (*it).find( ":" ) + 1 );
1721 break; 1722 break;
1722 } 1723 }
1723 } 1724 }
1724 1725
1725 return value; 1726 return value;
1726} 1727}
1727 1728
1728void Addressee::setCustoms( const QStringList &l ) 1729void Addressee::setCustoms( const QStringList &l )
1729{ 1730{
1730 detach(); 1731 detach();
1731 mData->empty = false; 1732 mData->empty = false;
1732 1733
1733 mData->custom = l; 1734 mData->custom = l;
1734} 1735}
1735 1736
1736QStringList Addressee::customs() const 1737QStringList Addressee::customs() const
1737{ 1738{
1738 return mData->custom; 1739 return mData->custom;
1739} 1740}
1740 1741
1741void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1742void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1742 QString &email) 1743 QString &email)
1743{ 1744{
1744 int startPos, endPos, len; 1745 int startPos, endPos, len;
1745 QString partA, partB, result; 1746 QString partA, partB, result;
1746 char endCh = '>'; 1747 char endCh = '>';
1747 1748
1748 startPos = rawEmail.find('<'); 1749 startPos = rawEmail.find('<');
1749 if (startPos < 0) 1750 if (startPos < 0)
1750 { 1751 {
1751 startPos = rawEmail.find('('); 1752 startPos = rawEmail.find('(');
1752 endCh = ')'; 1753 endCh = ')';
1753 } 1754 }
1754 if (startPos < 0) 1755 if (startPos < 0)
1755 { 1756 {
1756 // We couldn't find any separators, so we assume the whole string 1757 // We couldn't find any separators, so we assume the whole string
1757 // is the email address 1758 // is the email address
1758 email = rawEmail; 1759 email = rawEmail;
1759 fullName = ""; 1760 fullName = "";
1760 } 1761 }
1761 else 1762 else
1762 { 1763 {
1763 // We have a start position, try to find an end 1764 // We have a start position, try to find an end
1764 endPos = rawEmail.find(endCh, startPos+1); 1765 endPos = rawEmail.find(endCh, startPos+1);
1765 1766
1766 if (endPos < 0) 1767 if (endPos < 0)
1767 { 1768 {
1768 // We couldn't find the end of the email address. We can only 1769 // We couldn't find the end of the email address. We can only
1769 // assume the entire string is the email address. 1770 // assume the entire string is the email address.
1770 email = rawEmail; 1771 email = rawEmail;
1771 fullName = ""; 1772 fullName = "";
1772 } 1773 }
1773 else 1774 else
1774 { 1775 {
1775 // We have a start and end to the email address 1776 // We have a start and end to the email address
1776 1777
1777 // Grab the name part 1778 // Grab the name part
1778 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1779 fullName = rawEmail.left(startPos).stripWhiteSpace();
1779 1780
1780 // grab the email part 1781 // grab the email part
1781 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1782 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1782 1783
1783 // Check that we do not have any extra characters on the end of the 1784 // Check that we do not have any extra characters on the end of the
1784 // strings 1785 // strings
1785 len = fullName.length(); 1786 len = fullName.length();
1786 if (fullName[0]=='"' && fullName[len-1]=='"') 1787 if (fullName[0]=='"' && fullName[len-1]=='"')
1787 fullName = fullName.mid(1, len-2); 1788 fullName = fullName.mid(1, len-2);
1788 else if (fullName[0]=='<' && fullName[len-1]=='>') 1789 else if (fullName[0]=='<' && fullName[len-1]=='>')
1789 fullName = fullName.mid(1, len-2); 1790 fullName = fullName.mid(1, len-2);
1790 else if (fullName[0]=='(' && fullName[len-1]==')') 1791 else if (fullName[0]=='(' && fullName[len-1]==')')
1791 fullName = fullName.mid(1, len-2); 1792 fullName = fullName.mid(1, len-2);
1792 } 1793 }
1793 } 1794 }
1794} 1795}
1795 1796
1796void Addressee::setResource( Resource *resource ) 1797void Addressee::setResource( Resource *resource )
1797{ 1798{
1798 detach(); 1799 detach();
1799 mData->resource = resource; 1800 mData->resource = resource;
1800} 1801}
1801 1802
1802Resource *Addressee::resource() const 1803Resource *Addressee::resource() const
1803{ 1804{
1804 return mData->resource; 1805 return mData->resource;
1805} 1806}
1806 1807
1807//US 1808//US
1808QString Addressee::resourceLabel() 1809QString Addressee::resourceLabel()
1809{ 1810{
1810 return i18n("Resource"); 1811 return i18n("Resource");
1811} 1812}
1812 1813
1813void Addressee::setChanged( bool value ) 1814void Addressee::setChanged( bool value )
1814{ 1815{
1815 detach(); 1816 detach();
1816 mData->changed = value; 1817 mData->changed = value;
1817} 1818}
1818 1819
1819bool Addressee::changed() const 1820bool Addressee::changed() const
1820{ 1821{
1821 return mData->changed; 1822 return mData->changed;
1822} 1823}
1823 1824
1825void Addressee::setTagged( bool value )
1826{
1827 detach();
1828 mData->tagged = value;
1829}
1830
1831bool Addressee::tagged() const
1832{
1833 return mData->tagged;
1834}
1835
1824QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 1836QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
1825{ 1837{
1826 if (!a.mData) return s; 1838 if (!a.mData) return s;
1827 1839
1828 s << a.uid(); 1840 s << a.uid();
1829 1841
1830 s << a.mData->name; 1842 s << a.mData->name;
1831 s << a.mData->formattedName; 1843 s << a.mData->formattedName;
1832 s << a.mData->familyName; 1844 s << a.mData->familyName;
1833 s << a.mData->givenName; 1845 s << a.mData->givenName;
1834 s << a.mData->additionalName; 1846 s << a.mData->additionalName;
1835 s << a.mData->prefix; 1847 s << a.mData->prefix;
1836 s << a.mData->suffix; 1848 s << a.mData->suffix;
1837 s << a.mData->nickName; 1849 s << a.mData->nickName;
1838 s << a.mData->birthday; 1850 s << a.mData->birthday;
1839 s << a.mData->mailer; 1851 s << a.mData->mailer;
1840 s << a.mData->timeZone; 1852 s << a.mData->timeZone;
1841 s << a.mData->geo; 1853 s << a.mData->geo;
1842 s << a.mData->title; 1854 s << a.mData->title;
1843 s << a.mData->role; 1855 s << a.mData->role;
1844 s << a.mData->organization; 1856 s << a.mData->organization;
1845 s << a.mData->note; 1857 s << a.mData->note;
1846 s << a.mData->productId; 1858 s << a.mData->productId;
1847 s << a.mData->revision; 1859 s << a.mData->revision;
1848 s << a.mData->sortString; 1860 s << a.mData->sortString;
1849 s << a.mData->url; 1861 s << a.mData->url;
1850 s << a.mData->secrecy; 1862 s << a.mData->secrecy;
1851 s << a.mData->logo; 1863 s << a.mData->logo;
1852 s << a.mData->photo; 1864 s << a.mData->photo;
1853 s << a.mData->sound; 1865 s << a.mData->sound;
1854 s << a.mData->agent; 1866 s << a.mData->agent;
1855 s << a.mData->phoneNumbers; 1867 s << a.mData->phoneNumbers;
1856 s << a.mData->addresses; 1868 s << a.mData->addresses;
1857 s << a.mData->emails; 1869 s << a.mData->emails;
1858 s << a.mData->categories; 1870 s << a.mData->categories;
1859 s << a.mData->custom; 1871 s << a.mData->custom;
1860 s << a.mData->keys; 1872 s << a.mData->keys;
1861 return s; 1873 return s;
1862} 1874}
1863 1875
1864QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 1876QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
1865{ 1877{
1866 if (!a.mData) return s; 1878 if (!a.mData) return s;
1867 1879
1868 s >> a.mData->uid; 1880 s >> a.mData->uid;
1869 1881
1870 s >> a.mData->name; 1882 s >> a.mData->name;
1871 s >> a.mData->formattedName; 1883 s >> a.mData->formattedName;
1872 s >> a.mData->familyName; 1884 s >> a.mData->familyName;
1873 s >> a.mData->givenName; 1885 s >> a.mData->givenName;
1874 s >> a.mData->additionalName; 1886 s >> a.mData->additionalName;
1875 s >> a.mData->prefix; 1887 s >> a.mData->prefix;
1876 s >> a.mData->suffix; 1888 s >> a.mData->suffix;
1877 s >> a.mData->nickName; 1889 s >> a.mData->nickName;
1878 s >> a.mData->birthday; 1890 s >> a.mData->birthday;
1879 s >> a.mData->mailer; 1891 s >> a.mData->mailer;
1880 s >> a.mData->timeZone; 1892 s >> a.mData->timeZone;
1881 s >> a.mData->geo; 1893 s >> a.mData->geo;
1882 s >> a.mData->title; 1894 s >> a.mData->title;
1883 s >> a.mData->role; 1895 s >> a.mData->role;
1884 s >> a.mData->organization; 1896 s >> a.mData->organization;
1885 s >> a.mData->note; 1897 s >> a.mData->note;
1886 s >> a.mData->productId; 1898 s >> a.mData->productId;
1887 s >> a.mData->revision; 1899 s >> a.mData->revision;
1888 s >> a.mData->sortString; 1900 s >> a.mData->sortString;
1889 s >> a.mData->url; 1901 s >> a.mData->url;
1890 s >> a.mData->secrecy; 1902 s >> a.mData->secrecy;
1891 s >> a.mData->logo; 1903 s >> a.mData->logo;
1892 s >> a.mData->photo; 1904 s >> a.mData->photo;
1893 s >> a.mData->sound; 1905 s >> a.mData->sound;
1894 s >> a.mData->agent; 1906 s >> a.mData->agent;
1895 s >> a.mData->phoneNumbers; 1907 s >> a.mData->phoneNumbers;
1896 s >> a.mData->addresses; 1908 s >> a.mData->addresses;
1897 s >> a.mData->emails; 1909 s >> a.mData->emails;
1898 s >> a.mData->categories; 1910 s >> a.mData->categories;
1899 s >> a.mData->custom; 1911 s >> a.mData->custom;
1900 s >> a.mData->keys; 1912 s >> a.mData->keys;
1901 1913
1902 a.mData->empty = false; 1914 a.mData->empty = false;
1903 1915
1904 return s; 1916 return s;
1905} 1917}
1906bool matchBinaryPattern( int value, int pattern ) 1918bool matchBinaryPattern( int value, int pattern )
1907{ 1919{
1908 /** 1920 /**
1909 We want to match all telephonnumbers/addresses which have the bits in the 1921 We want to match all telephonnumbers/addresses which have the bits in the
1910 pattern set. More are allowed. 1922 pattern set. More are allowed.
1911 if pattern == 0 we have a special handling, then we want only those with 1923 if pattern == 0 we have a special handling, then we want only those with
1912 exactly no bit set. 1924 exactly no bit set.
1913 */ 1925 */
1914 if ( pattern == 0 ) 1926 if ( pattern == 0 )
1915 return ( value == 0 ); 1927 return ( value == 0 );
1916 else 1928 else
1917 return ( pattern == ( pattern & value ) ); 1929 return ( pattern == ( pattern & value ) );
1918} 1930}
1919 1931
1920bool matchBinaryPatternP( int value, int pattern ) 1932bool matchBinaryPatternP( int value, int pattern )
1921{ 1933{
1922 1934
1923 if ( pattern == 0 ) 1935 if ( pattern == 0 )
1924 return ( value == 0 ); 1936 return ( value == 0 );
1925 else 1937 else
1926 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); 1938 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
1927} 1939}
1928bool matchBinaryPatternA( int value, int pattern ) 1940bool matchBinaryPatternA( int value, int pattern )
1929{ 1941{
1930 1942
1931 if ( pattern == 0 ) 1943 if ( pattern == 0 )
1932 return ( value == 0 ); 1944 return ( value == 0 );
1933 else 1945 else
1934 return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); 1946 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
1935} 1947}