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