summaryrefslogtreecommitdiffabout
path: root/kabc/addressee.cpp
authorzautrix <zautrix>2004-10-09 16:58:08 (UTC)
committer zautrix <zautrix>2004-10-09 16:58:08 (UTC)
commit59ed933d6c43ecb0ddd3dec53cc289ee8aa68482 (patch) (unidiff)
tree8b1cbcf9c420e7dffd1e1293bcfa69e8e821f3fa /kabc/addressee.cpp
parentb80a099d9432bdc3d4eea778b1813b82b2680ecf (diff)
downloadkdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.zip
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.gz
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.bz2
fixed sync bug
Diffstat (limited to 'kabc/addressee.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3f3d5c0..607ae26 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,474 +1,475 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46static bool matchBinaryPatternA( int value, int pattern ); 46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern ); 47static bool matchBinaryPatternP( int value, int pattern );
48 48
49struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
50{ 50{
51 QString uid; 51 QString uid;
52 QString name; 52 QString name;
53 QString formattedName; 53 QString formattedName;
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1;
91}; 92};
92 93
93Addressee::Addressee() 94Addressee::Addressee()
94{ 95{
95 mData = new AddresseeData; 96 mData = new AddresseeData;
96 mData->empty = true; 97 mData->empty = true;
97 mData->changed = false; 98 mData->changed = false;
98 mData->resource = 0; 99 mData->resource = 0;
99 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
100 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
101 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
102} 103}
103 104
104Addressee::~Addressee() 105Addressee::~Addressee()
105{ 106{
106} 107}
107 108
108Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
109{ 110{
110 mData = a.mData; 111 mData = a.mData;
111} 112}
112 113
113Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
114{ 115{
115 mData = a.mData; 116 mData = a.mData;
116 return (*this); 117 return (*this);
117} 118}
118 119
119Addressee Addressee::copy() 120Addressee Addressee::copy()
120{ 121{
121 Addressee a; 122 Addressee a;
122 *(a.mData) = *mData; 123 *(a.mData) = *mData;
123 return a; 124 return a;
124} 125}
125 126
126void Addressee::detach() 127void Addressee::detach()
127{ 128{
128 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
129 *this = copy(); 130 *this = copy();
130} 131}
131 132
132bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
133{ 134{
134 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
135 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
136 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
137 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
138 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
139 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
140 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
141 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
142 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
143 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
144 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
145 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
146 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
147 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
148 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
149 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
150 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
151 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
152 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
153 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
154 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
155 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
156 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
157 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
158 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
159 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
160 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
161 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
162 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
163 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
164 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
165 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
166 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
167 168
168 return true; 169 return true;
169} 170}
170 171
171bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
172{ 173{
173 return !( a == *this ); 174 return !( a == *this );
174} 175}
175 176
176bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
177{ 178{
178 return mData->empty; 179 return mData->empty;
179} 180}
180ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
181{ 182{
182 int max = attList.count(); 183 int max = attList.count();
183 ulong cSum = 0; 184 ulong cSum = 0;
184 int j,k,i; 185 int j,k,i;
185 int add; 186 int add;
186 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
187 QString s = attList[i]; 188 QString s = attList[i];
188 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
189 j = s.length(); 190 j = s.length();
190 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
191 int mul = k +1; 192 int mul = k +1;
192 add = s[k].unicode (); 193 add = s[k].unicode ();
193 if ( k < 16 ) 194 if ( k < 16 )
194 mul = mul * mul; 195 mul = mul * mul;
195 int ii = i+1; 196 int ii = i+1;
196 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
197 cSum += add; 198 cSum += add;
198 } 199 }
199 } 200 }
200 201
201 } 202 }
202 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
203 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
204 205
205 return cSum; 206 return cSum;
206 207
207} 208}
208void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
209{ 210{
210 QStringList l; 211 QStringList l;
211 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
212 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
213 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
214 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
215 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
216 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
217 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
218 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
219 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
220 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
221 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
222 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
223 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
224 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
225 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
226 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
227 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
228 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
229 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
230 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
231 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
232 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
233 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
234 //if ( mData->url.isValid() ) l.append( ); 235 //if ( mData->url.isValid() ) l.append( );
235#if 0 236#if 0
236 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); 237 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
237 if ( !mData->addresses.isEmpty() ) l.append( ); 238 if ( !mData->addresses.isEmpty() ) l.append( );
238 //if ( !mData->keys.isEmpty() ) l.append( ); 239 //if ( !mData->keys.isEmpty() ) l.append( );
239 if ( !mData->emails.isEmpty() ) l.append( ); 240 if ( !mData->emails.isEmpty() ) l.append( );
240 if ( !mData->categories .isEmpty() ) l.append( ); 241 if ( !mData->categories .isEmpty() ) l.append( );
241 if ( !mData->custom.isEmpty() ) l.append( ); 242 if ( !mData->custom.isEmpty() ) l.append( );
242#endif 243#endif
243 KABC::PhoneNumber::List phoneNumbers; 244 KABC::PhoneNumber::List phoneNumbers;
244 KABC::PhoneNumber::List::Iterator phoneIter; 245 KABC::PhoneNumber::List::Iterator phoneIter;
245 246
246 QStringList t; 247 QStringList t;
247 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 248 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
248 ++phoneIter ) 249 ++phoneIter )
249 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 250 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
250 t.sort(); 251 t.sort();
251 uint iii; 252 uint iii;
252 for ( iii = 0; iii < t.count(); ++iii) 253 for ( iii = 0; iii < t.count(); ++iii)
253 l.append( t[iii] ); 254 l.append( t[iii] );
254 t = mData->emails; 255 t = mData->emails;
255 t.sort(); 256 t.sort();
256 for ( iii = 0; iii < t.count(); ++iii) 257 for ( iii = 0; iii < t.count(); ++iii)
257 l.append( t[iii] ); 258 l.append( t[iii] );
258 t = mData->categories; 259 t = mData->categories;
259 t.sort(); 260 t.sort();
260 for ( iii = 0; iii < t.count(); ++iii) 261 for ( iii = 0; iii < t.count(); ++iii)
261 l.append( t[iii] ); 262 l.append( t[iii] );
262 t = mData->custom; 263 t = mData->custom;
263 t.sort(); 264 t.sort();
264 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
265 l.append( t[iii] ); 266 l.append( t[iii] );
266 KABC::Address::List::Iterator addressIter; 267 KABC::Address::List::Iterator addressIter;
267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 268 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
268 ++addressIter ) { 269 ++addressIter ) {
269 t = (*addressIter).asList(); 270 t = (*addressIter).asList();
270 t.sort(); 271 t.sort();
271 for ( iii = 0; iii < t.count(); ++iii) 272 for ( iii = 0; iii < t.count(); ++iii)
272 l.append( t[iii] ); 273 l.append( t[iii] );
273 } 274 }
274 uint cs = getCsum4List(l); 275 uint cs = getCsum4List(l);
275 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 276 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
276 setCsum( dev, QString::number (cs )); 277 setCsum( dev, QString::number (cs ));
277} 278}
278 279
279void Addressee::mergeContact( const Addressee& ad ) 280void Addressee::mergeContact( const Addressee& ad )
280{ 281{
281 282
282 detach(); 283 detach();
283 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 284 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
284 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 285 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
285 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 286 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
286 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 287 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
287 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 288 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
288 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 289 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
289 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 290 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
290 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 291 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
291 if ( !mData->birthday.isValid() ) 292 if ( !mData->birthday.isValid() )
292 if ( ad.mData->birthday.isValid()) 293 if ( ad.mData->birthday.isValid())
293 mData->birthday = ad.mData->birthday; 294 mData->birthday = ad.mData->birthday;
294 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 295 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
295 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 296 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
296 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 297 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
297 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 298 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
298 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 299 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
299 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 300 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
300 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 301 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
301 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 302 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
302 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 303 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
303 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 304 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
304 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 305 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
305 306
306 // pending: 307 // pending:
307 // merging phonenumbers 308 // merging phonenumbers
308 // merging addresses 309 // merging addresses
309 // merging emails; 310 // merging emails;
310 // merging categories; 311 // merging categories;
311 // merging custom; 312 // merging custom;
312 // merging keys 313 // merging keys
313 qDebug("merge contact %s ", ad.uid().latin1()); 314 qDebug("merge contact %s ", ad.uid().latin1());
314 setUid( ad.uid() ); 315 setUid( ad.uid() );
315 setRevision( ad.revision() ); 316 setRevision( ad.revision() );
316} 317}
317 318
318bool Addressee::removeVoice() 319bool Addressee::removeVoice()
319{ 320{
320 PhoneNumber::List phoneN = phoneNumbers(); 321 PhoneNumber::List phoneN = phoneNumbers();
321 PhoneNumber::List::Iterator phoneIt; 322 PhoneNumber::List::Iterator phoneIt;
322 bool found = false; 323 bool found = false;
323 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 324 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
324 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 325 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
325 if ((*phoneIt).type() - PhoneNumber::Voice ) { 326 if ((*phoneIt).type() - PhoneNumber::Voice ) {
326 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 327 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
327 insertPhoneNumber( (*phoneIt) ); 328 insertPhoneNumber( (*phoneIt) );
328 found = true; 329 found = true;
329 } 330 }
330 } 331 }
331 332
332 } 333 }
333 return found; 334 return found;
334} 335}
335void Addressee::simplifyAddresses() 336void Addressee::simplifyAddresses()
336{ 337{
337 if ( mData->addresses.count() < 3 ) return ; 338 if ( mData->addresses.count() < 3 ) return ;
338 int count = 0; 339 int count = 0;
339 Address::List list; 340 Address::List list;
340 Address::List::Iterator it; 341 Address::List::Iterator it;
341 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 342 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
342 if ( count > 1 ) 343 if ( count > 1 )
343 list.append( *it ); 344 list.append( *it );
344 ++count; 345 ++count;
345 } 346 }
346 for( it = list.begin(); it != list.end(); ++it ) { 347 for( it = list.begin(); it != list.end(); ++it ) {
347 removeAddress( (*it) ); 348 removeAddress( (*it) );
348 } 349 }
349} 350}
350 351
351// removes all emails but the first 352// removes all emails but the first
352// needed by phone sync 353// needed by phone sync
353void Addressee::simplifyEmails() 354void Addressee::simplifyEmails()
354{ 355{
355 if ( mData->emails.count() == 0 ) return ; 356 if ( mData->emails.count() == 0 ) return ;
356 QString email = mData->emails.first(); 357 QString email = mData->emails.first();
357 detach(); 358 detach();
358 mData->emails.clear(); 359 mData->emails.clear();
359 mData->emails.append( email ); 360 mData->emails.append( email );
360} 361}
361 362
362void Addressee::simplifyPhoneNumbers() 363void Addressee::simplifyPhoneNumbers()
363{ 364{
364 KABC::PhoneNumber::List removeNumbers; 365 KABC::PhoneNumber::List removeNumbers;
365 KABC::PhoneNumber::List::Iterator phoneIter; 366 KABC::PhoneNumber::List::Iterator phoneIter;
366 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 367 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
367 ++phoneIter ) { 368 ++phoneIter ) {
368 if ( ! ( *phoneIter ).simplifyNumber() ) 369 if ( ! ( *phoneIter ).simplifyNumber() )
369 removeNumbers.append( ( *phoneIter ) ); 370 removeNumbers.append( ( *phoneIter ) );
370 } 371 }
371 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 372 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
372 ++phoneIter ) { 373 ++phoneIter ) {
373 removePhoneNumber(( *phoneIter )); 374 removePhoneNumber(( *phoneIter ));
374 } 375 }
375} 376}
376void Addressee::simplifyPhoneNumberTypes() 377void Addressee::simplifyPhoneNumberTypes()
377{ 378{
378 KABC::PhoneNumber::List::Iterator phoneIter; 379 KABC::PhoneNumber::List::Iterator phoneIter;
379 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 380 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
380 ++phoneIter ) 381 ++phoneIter )
381 ( *phoneIter ).simplifyType(); 382 ( *phoneIter ).simplifyType();
382} 383}
383void Addressee::removeID(const QString &prof) 384void Addressee::removeID(const QString &prof)
384{ 385{
385 detach(); 386 detach();
386 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 387 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
387 388
388} 389}
389void Addressee::setID( const QString & prof , const QString & id ) 390void Addressee::setID( const QString & prof , const QString & id )
390{ 391{
391 detach(); 392 detach();
392 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 393 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
393 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 394 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
394} 395}
395void Addressee::setTempSyncStat( int id ) 396void Addressee::setTempSyncStat( int id )
396{ 397{
397 if ( mData->mTempSyncStat == id ) return; 398 if ( mData->mTempSyncStat == id ) return;
398 detach(); 399 detach();
399 mData->mTempSyncStat = id; 400 mData->mTempSyncStat = id;
400} 401}
401int Addressee::tempSyncStat() const 402int Addressee::tempSyncStat() const
402{ 403{
403 return mData->mTempSyncStat; 404 return mData->mTempSyncStat;
404} 405}
405 406
406QString Addressee::getID( const QString & prof) 407QString Addressee::getID( const QString & prof)
407{ 408{
408 return KIdManager::getId ( mData->mExternalId, prof ); 409 return KIdManager::getId ( mData->mExternalId, prof );
409} 410}
410 411
411void Addressee::setCsum( const QString & prof , const QString & id ) 412void Addressee::setCsum( const QString & prof , const QString & id )
412{ 413{
413 detach(); 414 detach();
414 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 415 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
415 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 416 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
416 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 417 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
417} 418}
418 419
419QString Addressee::getCsum( const QString & prof) 420QString Addressee::getCsum( const QString & prof)
420{ 421{
421 return KIdManager::getCsum ( mData->mExternalId, prof ); 422 return KIdManager::getCsum ( mData->mExternalId, prof );
422} 423}
423 424
424void Addressee::setIDStr( const QString & s ) 425void Addressee::setIDStr( const QString & s )
425{ 426{
426 detach(); 427 detach();
427 mData->mExternalId = s; 428 mData->mExternalId = s;
428} 429}
429 430
430QString Addressee::IDStr() const 431QString Addressee::IDStr() const
431{ 432{
432 return mData->mExternalId; 433 return mData->mExternalId;
433} 434}
434 435
435void Addressee::setExternalUID( const QString &id ) 436void Addressee::setExternalUID( const QString &id )
436{ 437{
437 if ( id == mData->externalUID ) return; 438 if ( id == mData->externalUID ) return;
438 detach(); 439 detach();
439 mData->empty = false; 440 mData->empty = false;
440 mData->externalUID = id; 441 mData->externalUID = id;
441} 442}
442 443
443QString Addressee::externalUID() const 444QString Addressee::externalUID() const
444{ 445{
445 return mData->externalUID; 446 return mData->externalUID;
446} 447}
447void Addressee::setOriginalExternalUID( const QString &id ) 448void Addressee::setOriginalExternalUID( const QString &id )
448{ 449{
449 if ( id == mData->originalExternalUID ) return; 450 if ( id == mData->originalExternalUID ) return;
450 detach(); 451 detach();
451 mData->empty = false; 452 mData->empty = false;
452 //qDebug("*******Set orig uid %s ", id.latin1()); 453 //qDebug("*******Set orig uid %s ", id.latin1());
453 mData->originalExternalUID = id; 454 mData->originalExternalUID = id;
454} 455}
455 456
456QString Addressee::originalExternalUID() const 457QString Addressee::originalExternalUID() const
457{ 458{
458 return mData->originalExternalUID; 459 return mData->originalExternalUID;
459} 460}
460 461
461void Addressee::setUid( const QString &id ) 462void Addressee::setUid( const QString &id )
462{ 463{
463 if ( id == mData->uid ) return; 464 if ( id == mData->uid ) return;
464 detach(); 465 detach();
465 //qDebug("****setuid %s ", id.latin1()); 466 //qDebug("****setuid %s ", id.latin1());
466 mData->empty = false; 467 mData->empty = false;
467 mData->uid = id; 468 mData->uid = id;
468} 469}
469 470
470QString Addressee::uid() const 471QString Addressee::uid() const
471{ 472{
472 if ( mData->uid.isEmpty() ) 473 if ( mData->uid.isEmpty() )
473 mData->uid = KApplication::randomString( 10 ); 474 mData->uid = KApplication::randomString( 10 );
474 475
@@ -1440,496 +1441,507 @@ Key Addressee::key( int type, QString customTypeString ) const
1440 } 1441 }
1441 } else { 1442 } else {
1442 return *it; 1443 return *it;
1443 } 1444 }
1444 } 1445 }
1445 } 1446 }
1446 return Key( QString(), type ); 1447 return Key( QString(), type );
1447} 1448}
1448void Addressee::setKeys( const Key::List& list ) { 1449void Addressee::setKeys( const Key::List& list ) {
1449 detach(); 1450 detach();
1450 mData->keys = list; 1451 mData->keys = list;
1451} 1452}
1452 1453
1453Key::List Addressee::keys() const 1454Key::List Addressee::keys() const
1454{ 1455{
1455 return mData->keys; 1456 return mData->keys;
1456} 1457}
1457 1458
1458Key::List Addressee::keys( int type, QString customTypeString ) const 1459Key::List Addressee::keys( int type, QString customTypeString ) const
1459{ 1460{
1460 Key::List list; 1461 Key::List list;
1461 1462
1462 Key::List::ConstIterator it; 1463 Key::List::ConstIterator it;
1463 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1464 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1464 if ( (*it).type() == type ) { 1465 if ( (*it).type() == type ) {
1465 if ( type == Key::Custom ) { 1466 if ( type == Key::Custom ) {
1466 if ( customTypeString.isEmpty() ) { 1467 if ( customTypeString.isEmpty() ) {
1467 list.append(*it); 1468 list.append(*it);
1468 } else { 1469 } else {
1469 if ( (*it).customTypeString() == customTypeString ) 1470 if ( (*it).customTypeString() == customTypeString )
1470 list.append(*it); 1471 list.append(*it);
1471 } 1472 }
1472 } else { 1473 } else {
1473 list.append(*it); 1474 list.append(*it);
1474 } 1475 }
1475 } 1476 }
1476 } 1477 }
1477 return list; 1478 return list;
1478} 1479}
1479 1480
1480Key Addressee::findKey( const QString &id ) const 1481Key Addressee::findKey( const QString &id ) const
1481{ 1482{
1482 Key::List::ConstIterator it; 1483 Key::List::ConstIterator it;
1483 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1484 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1484 if ( (*it).id() == id ) { 1485 if ( (*it).id() == id ) {
1485 return *it; 1486 return *it;
1486 } 1487 }
1487 } 1488 }
1488 return Key(); 1489 return Key();
1489} 1490}
1490 1491
1491QString Addressee::asString() const 1492QString Addressee::asString() const
1492{ 1493{
1493 return "Smith, agent Smith..."; 1494 return "Smith, agent Smith...";
1494} 1495}
1495 1496
1496void Addressee::dump() const 1497void Addressee::dump() const
1497{ 1498{
1498 return; 1499 return;
1499 kdDebug(5700) << "Addressee {" << endl; 1500 kdDebug(5700) << "Addressee {" << endl;
1500 1501
1501 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1502 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1502 1503
1503 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1504 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1504 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1505 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1505 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1506 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1506 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1507 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1507 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1508 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1508 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1509 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1509 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1510 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1510 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1511 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1511 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1512 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1512 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1513 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1513 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1514 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1514 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1515 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1515 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1516 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1516 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1517 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1517 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1518 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1518 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1519 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1519 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1520 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1520 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1521 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1521 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1522 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1522 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1523 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1523 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1524 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1524 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1525 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1525 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1526 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1526 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1527 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1527 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1528 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1528 1529
1529 kdDebug(5700) << " Emails {" << endl; 1530 kdDebug(5700) << " Emails {" << endl;
1530 QStringList e = emails(); 1531 QStringList e = emails();
1531 QStringList::ConstIterator it; 1532 QStringList::ConstIterator it;
1532 for( it = e.begin(); it != e.end(); ++it ) { 1533 for( it = e.begin(); it != e.end(); ++it ) {
1533 kdDebug(5700) << " " << (*it) << endl; 1534 kdDebug(5700) << " " << (*it) << endl;
1534 } 1535 }
1535 kdDebug(5700) << " }" << endl; 1536 kdDebug(5700) << " }" << endl;
1536 1537
1537 kdDebug(5700) << " PhoneNumbers {" << endl; 1538 kdDebug(5700) << " PhoneNumbers {" << endl;
1538 PhoneNumber::List p = phoneNumbers(); 1539 PhoneNumber::List p = phoneNumbers();
1539 PhoneNumber::List::ConstIterator it2; 1540 PhoneNumber::List::ConstIterator it2;
1540 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1541 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1541 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1542 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1542 } 1543 }
1543 kdDebug(5700) << " }" << endl; 1544 kdDebug(5700) << " }" << endl;
1544 1545
1545 Address::List a = addresses(); 1546 Address::List a = addresses();
1546 Address::List::ConstIterator it3; 1547 Address::List::ConstIterator it3;
1547 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1548 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1548 (*it3).dump(); 1549 (*it3).dump();
1549 } 1550 }
1550 1551
1551 kdDebug(5700) << " Keys {" << endl; 1552 kdDebug(5700) << " Keys {" << endl;
1552 Key::List k = keys(); 1553 Key::List k = keys();
1553 Key::List::ConstIterator it4; 1554 Key::List::ConstIterator it4;
1554 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1555 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1555 kdDebug(5700) << " Type: " << int((*it4).type()) << 1556 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1556 " Key: " << (*it4).textData() << 1557 " Key: " << (*it4).textData() <<
1557 " CustomString: " << (*it4).customTypeString() << endl; 1558 " CustomString: " << (*it4).customTypeString() << endl;
1558 } 1559 }
1559 kdDebug(5700) << " }" << endl; 1560 kdDebug(5700) << " }" << endl;
1560 1561
1561 kdDebug(5700) << "}" << endl; 1562 kdDebug(5700) << "}" << endl;
1562} 1563}
1563 1564
1564 1565
1565void Addressee::insertAddress( const Address &address ) 1566void Addressee::insertAddress( const Address &address )
1566{ 1567{
1567 detach(); 1568 detach();
1568 mData->empty = false; 1569 mData->empty = false;
1569 1570
1570 Address::List::Iterator it; 1571 Address::List::Iterator it;
1571 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1572 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1572 if ( (*it).id() == address.id() ) { 1573 if ( (*it).id() == address.id() ) {
1573 *it = address; 1574 *it = address;
1574 return; 1575 return;
1575 } 1576 }
1576 } 1577 }
1577 mData->addresses.append( address ); 1578 mData->addresses.append( address );
1578} 1579}
1579 1580
1580void Addressee::removeAddress( const Address &address ) 1581void Addressee::removeAddress( const Address &address )
1581{ 1582{
1582 detach(); 1583 detach();
1583 1584
1584 Address::List::Iterator it; 1585 Address::List::Iterator it;
1585 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1586 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1586 if ( (*it).id() == address.id() ) { 1587 if ( (*it).id() == address.id() ) {
1587 mData->addresses.remove( it ); 1588 mData->addresses.remove( it );
1588 return; 1589 return;
1589 } 1590 }
1590 } 1591 }
1591} 1592}
1592 1593
1593Address Addressee::address( int type ) const 1594Address Addressee::address( int type ) const
1594{ 1595{
1595 Address address( type ); 1596 Address address( type );
1596 Address::List::ConstIterator it; 1597 Address::List::ConstIterator it;
1597 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1598 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1598 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1599 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1599 if ( (*it).type() & Address::Pref ) 1600 if ( (*it).type() & Address::Pref )
1600 return (*it); 1601 return (*it);
1601 else if ( address.isEmpty() ) 1602 else if ( address.isEmpty() )
1602 address = (*it); 1603 address = (*it);
1603 } 1604 }
1604 } 1605 }
1605 1606
1606 return address; 1607 return address;
1607} 1608}
1608 1609
1609Address::List Addressee::addresses() const 1610Address::List Addressee::addresses() const
1610{ 1611{
1611 return mData->addresses; 1612 return mData->addresses;
1612} 1613}
1613 1614
1614Address::List Addressee::addresses( int type ) const 1615Address::List Addressee::addresses( int type ) const
1615{ 1616{
1616 Address::List list; 1617 Address::List list;
1617 1618
1618 Address::List::ConstIterator it; 1619 Address::List::ConstIterator it;
1619 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1620 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1620 if ( matchBinaryPattern( (*it).type(), type ) ) { 1621 if ( matchBinaryPattern( (*it).type(), type ) ) {
1621 list.append( *it ); 1622 list.append( *it );
1622 } 1623 }
1623 } 1624 }
1624 1625
1625 return list; 1626 return list;
1626} 1627}
1627 1628
1628Address Addressee::findAddress( const QString &id ) const 1629Address Addressee::findAddress( const QString &id ) const
1629{ 1630{
1630 Address::List::ConstIterator it; 1631 Address::List::ConstIterator it;
1631 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1632 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1632 if ( (*it).id() == id ) { 1633 if ( (*it).id() == id ) {
1633 return *it; 1634 return *it;
1634 } 1635 }
1635 } 1636 }
1636 return Address(); 1637 return Address();
1637} 1638}
1638 1639
1639void Addressee::insertCategory( const QString &c ) 1640void Addressee::insertCategory( const QString &c )
1640{ 1641{
1641 detach(); 1642 detach();
1642 mData->empty = false; 1643 mData->empty = false;
1643 1644
1644 if ( mData->categories.contains( c ) ) return; 1645 if ( mData->categories.contains( c ) ) return;
1645 1646
1646 mData->categories.append( c ); 1647 mData->categories.append( c );
1647} 1648}
1648 1649
1649void Addressee::removeCategory( const QString &c ) 1650void Addressee::removeCategory( const QString &c )
1650{ 1651{
1651 detach(); 1652 detach();
1652 1653
1653 QStringList::Iterator it = mData->categories.find( c ); 1654 QStringList::Iterator it = mData->categories.find( c );
1654 if ( it == mData->categories.end() ) return; 1655 if ( it == mData->categories.end() ) return;
1655 1656
1656 mData->categories.remove( it ); 1657 mData->categories.remove( it );
1657} 1658}
1658 1659
1659bool Addressee::hasCategory( const QString &c ) const 1660bool Addressee::hasCategory( const QString &c ) const
1660{ 1661{
1661 return ( mData->categories.contains( c ) ); 1662 return ( mData->categories.contains( c ) );
1662} 1663}
1663 1664
1664void Addressee::setCategories( const QStringList &c ) 1665void Addressee::setCategories( const QStringList &c )
1665{ 1666{
1666 detach(); 1667 detach();
1667 mData->empty = false; 1668 mData->empty = false;
1668 1669
1669 mData->categories = c; 1670 mData->categories = c;
1670} 1671}
1671 1672
1672QStringList Addressee::categories() const 1673QStringList Addressee::categories() const
1673{ 1674{
1674 return mData->categories; 1675 return mData->categories;
1675} 1676}
1676 1677
1677void Addressee::insertCustom( const QString &app, const QString &name, 1678void Addressee::insertCustom( const QString &app, const QString &name,
1678 const QString &value ) 1679 const QString &value )
1679{ 1680{
1680 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1681 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1681 1682
1682 detach(); 1683 detach();
1683 mData->empty = false; 1684 mData->empty = false;
1684 1685
1685 QString qualifiedName = app + "-" + name + ":"; 1686 QString qualifiedName = app + "-" + name + ":";
1686 1687
1687 QStringList::Iterator it; 1688 QStringList::Iterator it;
1688 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1689 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1689 if ( (*it).startsWith( qualifiedName ) ) { 1690 if ( (*it).startsWith( qualifiedName ) ) {
1690 (*it) = qualifiedName + value; 1691 (*it) = qualifiedName + value;
1691 return; 1692 return;
1692 } 1693 }
1693 } 1694 }
1694 mData->custom.append( qualifiedName + value ); 1695 mData->custom.append( qualifiedName + value );
1695} 1696}
1696 1697
1697void Addressee::removeCustom( const QString &app, const QString &name) 1698void Addressee::removeCustom( const QString &app, const QString &name)
1698{ 1699{
1699 detach(); 1700 detach();
1700 1701
1701 QString qualifiedName = app + "-" + name + ":"; 1702 QString qualifiedName = app + "-" + name + ":";
1702 1703
1703 QStringList::Iterator it; 1704 QStringList::Iterator it;
1704 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1705 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1705 if ( (*it).startsWith( qualifiedName ) ) { 1706 if ( (*it).startsWith( qualifiedName ) ) {
1706 mData->custom.remove( it ); 1707 mData->custom.remove( it );
1707 return; 1708 return;
1708 } 1709 }
1709 } 1710 }
1710} 1711}
1711 1712
1712QString Addressee::custom( const QString &app, const QString &name ) const 1713QString Addressee::custom( const QString &app, const QString &name ) const
1713{ 1714{
1714 QString qualifiedName = app + "-" + name + ":"; 1715 QString qualifiedName = app + "-" + name + ":";
1715 QString value; 1716 QString value;
1716 1717
1717 QStringList::ConstIterator it; 1718 QStringList::ConstIterator it;
1718 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1719 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1719 if ( (*it).startsWith( qualifiedName ) ) { 1720 if ( (*it).startsWith( qualifiedName ) ) {
1720 value = (*it).mid( (*it).find( ":" ) + 1 ); 1721 value = (*it).mid( (*it).find( ":" ) + 1 );
1721 break; 1722 break;
1722 } 1723 }
1723 } 1724 }
1724 1725
1725 return value; 1726 return value;
1726} 1727}
1727 1728
1728void Addressee::setCustoms( const QStringList &l ) 1729void Addressee::setCustoms( const QStringList &l )
1729{ 1730{
1730 detach(); 1731 detach();
1731 mData->empty = false; 1732 mData->empty = false;
1732 1733
1733 mData->custom = l; 1734 mData->custom = l;
1734} 1735}
1735 1736
1736QStringList Addressee::customs() const 1737QStringList Addressee::customs() const
1737{ 1738{
1738 return mData->custom; 1739 return mData->custom;
1739} 1740}
1740 1741
1741void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1742void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1742 QString &email) 1743 QString &email)
1743{ 1744{
1744 int startPos, endPos, len; 1745 int startPos, endPos, len;
1745 QString partA, partB, result; 1746 QString partA, partB, result;
1746 char endCh = '>'; 1747 char endCh = '>';
1747 1748
1748 startPos = rawEmail.find('<'); 1749 startPos = rawEmail.find('<');
1749 if (startPos < 0) 1750 if (startPos < 0)
1750 { 1751 {
1751 startPos = rawEmail.find('('); 1752 startPos = rawEmail.find('(');
1752 endCh = ')'; 1753 endCh = ')';
1753 } 1754 }
1754 if (startPos < 0) 1755 if (startPos < 0)
1755 { 1756 {
1756 // We couldn't find any separators, so we assume the whole string 1757 // We couldn't find any separators, so we assume the whole string
1757 // is the email address 1758 // is the email address
1758 email = rawEmail; 1759 email = rawEmail;
1759 fullName = ""; 1760 fullName = "";
1760 } 1761 }
1761 else 1762 else
1762 { 1763 {
1763 // We have a start position, try to find an end 1764 // We have a start position, try to find an end
1764 endPos = rawEmail.find(endCh, startPos+1); 1765 endPos = rawEmail.find(endCh, startPos+1);
1765 1766
1766 if (endPos < 0) 1767 if (endPos < 0)
1767 { 1768 {
1768 // We couldn't find the end of the email address. We can only 1769 // We couldn't find the end of the email address. We can only
1769 // assume the entire string is the email address. 1770 // assume the entire string is the email address.
1770 email = rawEmail; 1771 email = rawEmail;
1771 fullName = ""; 1772 fullName = "";
1772 } 1773 }
1773 else 1774 else
1774 { 1775 {
1775 // We have a start and end to the email address 1776 // We have a start and end to the email address
1776 1777
1777 // Grab the name part 1778 // Grab the name part
1778 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1779 fullName = rawEmail.left(startPos).stripWhiteSpace();
1779 1780
1780 // grab the email part 1781 // grab the email part
1781 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1782 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1782 1783
1783 // Check that we do not have any extra characters on the end of the 1784 // Check that we do not have any extra characters on the end of the
1784 // strings 1785 // strings
1785 len = fullName.length(); 1786 len = fullName.length();
1786 if (fullName[0]=='"' && fullName[len-1]=='"') 1787 if (fullName[0]=='"' && fullName[len-1]=='"')
1787 fullName = fullName.mid(1, len-2); 1788 fullName = fullName.mid(1, len-2);
1788 else if (fullName[0]=='<' && fullName[len-1]=='>') 1789 else if (fullName[0]=='<' && fullName[len-1]=='>')
1789 fullName = fullName.mid(1, len-2); 1790 fullName = fullName.mid(1, len-2);
1790 else if (fullName[0]=='(' && fullName[len-1]==')') 1791 else if (fullName[0]=='(' && fullName[len-1]==')')
1791 fullName = fullName.mid(1, len-2); 1792 fullName = fullName.mid(1, len-2);
1792 } 1793 }
1793 } 1794 }
1794} 1795}
1795 1796
1796void Addressee::setResource( Resource *resource ) 1797void Addressee::setResource( Resource *resource )
1797{ 1798{
1798 detach(); 1799 detach();
1799 mData->resource = resource; 1800 mData->resource = resource;
1800} 1801}
1801 1802
1802Resource *Addressee::resource() const 1803Resource *Addressee::resource() const
1803{ 1804{
1804 return mData->resource; 1805 return mData->resource;
1805} 1806}
1806 1807
1807//US 1808//US
1808QString Addressee::resourceLabel() 1809QString Addressee::resourceLabel()
1809{ 1810{
1810 return i18n("Resource"); 1811 return i18n("Resource");
1811} 1812}
1812 1813
1813void Addressee::setChanged( bool value ) 1814void Addressee::setChanged( bool value )
1814{ 1815{
1815 detach(); 1816 detach();
1816 mData->changed = value; 1817 mData->changed = value;
1817} 1818}
1818 1819
1819bool Addressee::changed() const 1820bool Addressee::changed() const
1820{ 1821{
1821 return mData->changed; 1822 return mData->changed;
1822} 1823}
1823 1824
1825void Addressee::setTagged( bool value )
1826{
1827 detach();
1828 mData->tagged = value;
1829}
1830
1831bool Addressee::tagged() const
1832{
1833 return mData->tagged;
1834}
1835
1824QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 1836QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
1825{ 1837{
1826 if (!a.mData) return s; 1838 if (!a.mData) return s;
1827 1839
1828 s << a.uid(); 1840 s << a.uid();
1829 1841
1830 s << a.mData->name; 1842 s << a.mData->name;
1831 s << a.mData->formattedName; 1843 s << a.mData->formattedName;
1832 s << a.mData->familyName; 1844 s << a.mData->familyName;
1833 s << a.mData->givenName; 1845 s << a.mData->givenName;
1834 s << a.mData->additionalName; 1846 s << a.mData->additionalName;
1835 s << a.mData->prefix; 1847 s << a.mData->prefix;
1836 s << a.mData->suffix; 1848 s << a.mData->suffix;
1837 s << a.mData->nickName; 1849 s << a.mData->nickName;
1838 s << a.mData->birthday; 1850 s << a.mData->birthday;
1839 s << a.mData->mailer; 1851 s << a.mData->mailer;
1840 s << a.mData->timeZone; 1852 s << a.mData->timeZone;
1841 s << a.mData->geo; 1853 s << a.mData->geo;
1842 s << a.mData->title; 1854 s << a.mData->title;
1843 s << a.mData->role; 1855 s << a.mData->role;
1844 s << a.mData->organization; 1856 s << a.mData->organization;
1845 s << a.mData->note; 1857 s << a.mData->note;
1846 s << a.mData->productId; 1858 s << a.mData->productId;
1847 s << a.mData->revision; 1859 s << a.mData->revision;
1848 s << a.mData->sortString; 1860 s << a.mData->sortString;
1849 s << a.mData->url; 1861 s << a.mData->url;
1850 s << a.mData->secrecy; 1862 s << a.mData->secrecy;
1851 s << a.mData->logo; 1863 s << a.mData->logo;
1852 s << a.mData->photo; 1864 s << a.mData->photo;
1853 s << a.mData->sound; 1865 s << a.mData->sound;
1854 s << a.mData->agent; 1866 s << a.mData->agent;
1855 s << a.mData->phoneNumbers; 1867 s << a.mData->phoneNumbers;
1856 s << a.mData->addresses; 1868 s << a.mData->addresses;
1857 s << a.mData->emails; 1869 s << a.mData->emails;
1858 s << a.mData->categories; 1870 s << a.mData->categories;
1859 s << a.mData->custom; 1871 s << a.mData->custom;
1860 s << a.mData->keys; 1872 s << a.mData->keys;
1861 return s; 1873 return s;
1862} 1874}
1863 1875
1864QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 1876QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
1865{ 1877{
1866 if (!a.mData) return s; 1878 if (!a.mData) return s;
1867 1879
1868 s >> a.mData->uid; 1880 s >> a.mData->uid;
1869 1881
1870 s >> a.mData->name; 1882 s >> a.mData->name;
1871 s >> a.mData->formattedName; 1883 s >> a.mData->formattedName;
1872 s >> a.mData->familyName; 1884 s >> a.mData->familyName;
1873 s >> a.mData->givenName; 1885 s >> a.mData->givenName;
1874 s >> a.mData->additionalName; 1886 s >> a.mData->additionalName;
1875 s >> a.mData->prefix; 1887 s >> a.mData->prefix;
1876 s >> a.mData->suffix; 1888 s >> a.mData->suffix;
1877 s >> a.mData->nickName; 1889 s >> a.mData->nickName;
1878 s >> a.mData->birthday; 1890 s >> a.mData->birthday;
1879 s >> a.mData->mailer; 1891 s >> a.mData->mailer;
1880 s >> a.mData->timeZone; 1892 s >> a.mData->timeZone;
1881 s >> a.mData->geo; 1893 s >> a.mData->geo;
1882 s >> a.mData->title; 1894 s >> a.mData->title;
1883 s >> a.mData->role; 1895 s >> a.mData->role;
1884 s >> a.mData->organization; 1896 s >> a.mData->organization;
1885 s >> a.mData->note; 1897 s >> a.mData->note;
1886 s >> a.mData->productId; 1898 s >> a.mData->productId;
1887 s >> a.mData->revision; 1899 s >> a.mData->revision;
1888 s >> a.mData->sortString; 1900 s >> a.mData->sortString;
1889 s >> a.mData->url; 1901 s >> a.mData->url;
1890 s >> a.mData->secrecy; 1902 s >> a.mData->secrecy;
1891 s >> a.mData->logo; 1903 s >> a.mData->logo;
1892 s >> a.mData->photo; 1904 s >> a.mData->photo;
1893 s >> a.mData->sound; 1905 s >> a.mData->sound;
1894 s >> a.mData->agent; 1906 s >> a.mData->agent;
1895 s >> a.mData->phoneNumbers; 1907 s >> a.mData->phoneNumbers;
1896 s >> a.mData->addresses; 1908 s >> a.mData->addresses;
1897 s >> a.mData->emails; 1909 s >> a.mData->emails;
1898 s >> a.mData->categories; 1910 s >> a.mData->categories;
1899 s >> a.mData->custom; 1911 s >> a.mData->custom;
1900 s >> a.mData->keys; 1912 s >> a.mData->keys;
1901 1913
1902 a.mData->empty = false; 1914 a.mData->empty = false;
1903 1915
1904 return s; 1916 return s;
1905} 1917}
1906bool matchBinaryPattern( int value, int pattern ) 1918bool matchBinaryPattern( int value, int pattern )
1907{ 1919{
1908 /** 1920 /**
1909 We want to match all telephonnumbers/addresses which have the bits in the 1921 We want to match all telephonnumbers/addresses which have the bits in the
1910 pattern set. More are allowed. 1922 pattern set. More are allowed.
1911 if pattern == 0 we have a special handling, then we want only those with 1923 if pattern == 0 we have a special handling, then we want only those with
1912 exactly no bit set. 1924 exactly no bit set.
1913 */ 1925 */
1914 if ( pattern == 0 ) 1926 if ( pattern == 0 )
1915 return ( value == 0 ); 1927 return ( value == 0 );
1916 else 1928 else
1917 return ( pattern == ( pattern & value ) ); 1929 return ( pattern == ( pattern & value ) );
1918} 1930}
1919 1931
1920bool matchBinaryPatternP( int value, int pattern ) 1932bool matchBinaryPatternP( int value, int pattern )
1921{ 1933{
1922 1934
1923 if ( pattern == 0 ) 1935 if ( pattern == 0 )
1924 return ( value == 0 ); 1936 return ( value == 0 );
1925 else 1937 else
1926 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); 1938 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
1927} 1939}
1928bool matchBinaryPatternA( int value, int pattern ) 1940bool matchBinaryPatternA( int value, int pattern )
1929{ 1941{
1930 1942
1931 if ( pattern == 0 ) 1943 if ( pattern == 0 )
1932 return ( value == 0 ); 1944 return ( value == 0 );
1933 else 1945 else
1934 return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); 1946 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
1935} 1947}