summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp27
-rw-r--r--kabc/address.h2
-rw-r--r--kabc/addressee.cpp25
-rw-r--r--kabc/addressee.h4
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp22
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp39
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp16
7 files changed, 128 insertions, 7 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index 5ffe511..6151f9e 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -1,664 +1,691 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28//US added kglobal.h 28//US added kglobal.h
29#include <kglobal.h> 29#include <kglobal.h>
30 30
31#include <kapplication.h> 31#include <kapplication.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <ksimpleconfig.h> 34#include <ksimpleconfig.h>
35#include <kstandarddirs.h> 35#include <kstandarddirs.h>
36 36
37#include <qfile.h> 37#include <qfile.h>
38 38
39#include "address.h" 39#include "address.h"
40 40
41using namespace KABC; 41using namespace KABC;
42 42
43QMap<QString, QString> Address::mISOMap; 43QMap<QString, QString> Address::mISOMap;
44 44
45Address::Address() : 45Address::Address() :
46 mEmpty( true ), mType( 0 ) 46 mEmpty( true ), mType( 0 )
47{ 47{
48 mId = KApplication::randomString( 10 ); 48 mId = KApplication::randomString( 10 );
49} 49}
50 50
51Address::Address( int type ) : 51Address::Address( int type ) :
52 mEmpty( true ), mType( type ) 52 mEmpty( true ), mType( type )
53{ 53{
54 mId = KApplication::randomString( 10 ); 54 mId = KApplication::randomString( 10 );
55} 55}
56 56
57bool Address::operator==( const Address &a ) const 57bool Address::operator==( const Address &a ) const
58{ 58{
59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false; 59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false;
60 if ( mExtended != a.mExtended ) return false; 60 if ( mExtended != a.mExtended ) return false;
61 if ( mStreet != a.mStreet ) return false; 61 if ( mStreet != a.mStreet ) return false;
62 if ( mLocality != a.mLocality ) return false; 62 if ( mLocality != a.mLocality ) return false;
63 if ( mRegion != a.mRegion ) return false; 63 if ( mRegion != a.mRegion ) return false;
64 if ( mPostalCode != a.mPostalCode ) return false; 64 if ( mPostalCode != a.mPostalCode ) return false;
65 if ( mCountry != a.mCountry ) return false; 65 if ( mCountry != a.mCountry ) return false;
66 if ( mLabel != a.mLabel ) return false; 66 if ( mLabel != a.mLabel ) return false;
67 67
68 return true; 68 return true;
69} 69}
70 70
71bool Address::operator!=( const Address &a ) const 71bool Address::operator!=( const Address &a ) const
72{ 72{
73 return !( a == *this ); 73 return !( a == *this );
74} 74}
75 75
76bool Address::isEmpty() const 76bool Address::isEmpty() const
77{ 77{
78 if ( mPostOfficeBox.isEmpty() && 78 if ( mPostOfficeBox.isEmpty() &&
79 mExtended.isEmpty() && 79 mExtended.isEmpty() &&
80 mStreet.isEmpty() && 80 mStreet.isEmpty() &&
81 mLocality.isEmpty() && 81 mLocality.isEmpty() &&
82 mRegion.isEmpty() && 82 mRegion.isEmpty() &&
83 mPostalCode.isEmpty() && 83 mPostalCode.isEmpty() &&
84 mCountry.isEmpty() && 84 mCountry.isEmpty() &&
85 mLabel.isEmpty() ) { 85 mLabel.isEmpty() ) {
86 return true; 86 return true;
87 } 87 }
88 return false; 88 return false;
89} 89}
90 90
91QStringList Address::asList() 91QStringList Address::asList()
92{ 92{
93 QStringList result; 93 QStringList result;
94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox); 94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox);
95 if ( ! mExtended.isEmpty())result.append(mExtended); 95 if ( ! mExtended.isEmpty())result.append(mExtended);
96 if ( ! mStreet.isEmpty())result.append(mStreet); 96 if ( ! mStreet.isEmpty())result.append(mStreet);
97 if ( ! mLocality.isEmpty() )result.append(mLocality); 97 if ( ! mLocality.isEmpty() )result.append(mLocality);
98 if ( ! mRegion.isEmpty())result.append(mRegion); 98 if ( ! mRegion.isEmpty())result.append(mRegion);
99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode); 99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode);
100 if ( ! mCountry.isEmpty())result.append(mCountry); 100 if ( ! mCountry.isEmpty())result.append(mCountry);
101 if ( ! mLabel.isEmpty() )result.append(mLabel); 101 if ( ! mLabel.isEmpty() )result.append(mLabel);
102 return result; 102 return result;
103} 103}
104
105bool Address::matchAddress( QRegExp* re ) const
106{
107
108#if QT_VERSION >= 0x030000
109 if (re->search( mPostOfficeBox ) == 0) return true;
110 if (re->search( mExtended ) == 0) return true;
111 if (re->search( mStreet ) == 0) return true;
112 if (re->search( mLocality ) == 0) return true;
113 if (re->search( mRegion ) == 0) return true;
114 if (re->search( mPostalCode ) == 0) return true;
115 if (re->search( mCountry ) == 0) return true;
116 if (re->search( mLabel ) == 0) return true;
117#else
118 if (re->match( mPostOfficeBox ) == 0) return true;
119 if (re->match( mExtended ) == 0) return true;
120 if (re->match( mStreet ) == 0) return true;
121 if (re->match( mLocality ) == 0) return true;
122 if (re->match( mRegion ) == 0) return true;
123 if (re->match( mPostalCode ) == 0) return true;
124 if (re->match( mCountry ) == 0) return true;
125 if (re->match( mLabel ) == 0) return true;
126#endif
127
128 return false;
129}
130
104void Address::clear() 131void Address::clear()
105{ 132{
106 *this = Address(); 133 *this = Address();
107} 134}
108 135
109void Address::setId( const QString &id ) 136void Address::setId( const QString &id )
110{ 137{
111 mEmpty = false; 138 mEmpty = false;
112 139
113 mId = id; 140 mId = id;
114} 141}
115 142
116QString Address::id() const 143QString Address::id() const
117{ 144{
118 return mId; 145 return mId;
119} 146}
120 147
121void Address::setType( int type ) 148void Address::setType( int type )
122{ 149{
123 mEmpty = false; 150 mEmpty = false;
124 151
125 mType = type; 152 mType = type;
126} 153}
127 154
128int Address::type() const 155int Address::type() const
129{ 156{
130 return mType; 157 return mType;
131} 158}
132 159
133QString Address::typeLabel() const 160QString Address::typeLabel() const
134{ 161{
135 QString label; 162 QString label;
136 bool first = true; 163 bool first = true;
137 164
138 TypeList list = typeList(); 165 TypeList list = typeList();
139 166
140 TypeList::Iterator it; 167 TypeList::Iterator it;
141 for ( it = list.begin(); it != list.end(); ++it ) { 168 for ( it = list.begin(); it != list.end(); ++it ) {
142 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 169 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
143 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 170 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
144 if ( first ) 171 if ( first )
145 first = false; 172 first = false;
146 } 173 }
147 } 174 }
148 175
149 return label; 176 return label;
150} 177}
151 178
152void Address::setPostOfficeBox( const QString &s ) 179void Address::setPostOfficeBox( const QString &s )
153{ 180{
154 mEmpty = false; 181 mEmpty = false;
155 182
156 mPostOfficeBox = s; 183 mPostOfficeBox = s;
157} 184}
158 185
159QString Address::postOfficeBox() const 186QString Address::postOfficeBox() const
160{ 187{
161 return mPostOfficeBox; 188 return mPostOfficeBox;
162} 189}
163 190
164QString Address::postOfficeBoxLabel() 191QString Address::postOfficeBoxLabel()
165{ 192{
166 return i18n("Post Office Box"); 193 return i18n("Post Office Box");
167} 194}
168 195
169 196
170void Address::setExtended( const QString &s ) 197void Address::setExtended( const QString &s )
171{ 198{
172 mEmpty = false; 199 mEmpty = false;
173 200
174 mExtended = s; 201 mExtended = s;
175} 202}
176 203
177QString Address::extended() const 204QString Address::extended() const
178{ 205{
179 return mExtended; 206 return mExtended;
180} 207}
181 208
182QString Address::extendedLabel() 209QString Address::extendedLabel()
183{ 210{
184 return i18n("Extended Address Information"); 211 return i18n("Extended Address Information");
185} 212}
186 213
187 214
188void Address::setStreet( const QString &s ) 215void Address::setStreet( const QString &s )
189{ 216{
190 mEmpty = false; 217 mEmpty = false;
191 218
192 mStreet = s; 219 mStreet = s;
193} 220}
194 221
195QString Address::street() const 222QString Address::street() const
196{ 223{
197 return mStreet; 224 return mStreet;
198} 225}
199 226
200QString Address::streetLabel() 227QString Address::streetLabel()
201{ 228{
202 return i18n("Street"); 229 return i18n("Street");
203} 230}
204 231
205 232
206void Address::setLocality( const QString &s ) 233void Address::setLocality( const QString &s )
207{ 234{
208 mEmpty = false; 235 mEmpty = false;
209 236
210 mLocality = s; 237 mLocality = s;
211} 238}
212 239
213QString Address::locality() const 240QString Address::locality() const
214{ 241{
215 return mLocality; 242 return mLocality;
216} 243}
217 244
218QString Address::localityLabel() 245QString Address::localityLabel()
219{ 246{
220 return i18n("Locality"); 247 return i18n("Locality");
221} 248}
222 249
223 250
224void Address::setRegion( const QString &s ) 251void Address::setRegion( const QString &s )
225{ 252{
226 mEmpty = false; 253 mEmpty = false;
227 254
228 mRegion = s; 255 mRegion = s;
229} 256}
230 257
231QString Address::region() const 258QString Address::region() const
232{ 259{
233 return mRegion; 260 return mRegion;
234} 261}
235 262
236QString Address::regionLabel() 263QString Address::regionLabel()
237{ 264{
238 return i18n("Region"); 265 return i18n("Region");
239} 266}
240 267
241 268
242void Address::setPostalCode( const QString &s ) 269void Address::setPostalCode( const QString &s )
243{ 270{
244 mEmpty = false; 271 mEmpty = false;
245 272
246 mPostalCode = s; 273 mPostalCode = s;
247} 274}
248 275
249QString Address::postalCode() const 276QString Address::postalCode() const
250{ 277{
251 return mPostalCode; 278 return mPostalCode;
252} 279}
253 280
254QString Address::postalCodeLabel() 281QString Address::postalCodeLabel()
255{ 282{
256 return i18n("Postal Code"); 283 return i18n("Postal Code");
257} 284}
258 285
259 286
260void Address::setCountry( const QString &s ) 287void Address::setCountry( const QString &s )
261{ 288{
262 mEmpty = false; 289 mEmpty = false;
263 290
264 mCountry = s; 291 mCountry = s;
265} 292}
266 293
267QString Address::country() const 294QString Address::country() const
268{ 295{
269 return mCountry; 296 return mCountry;
270} 297}
271 298
272QString Address::countryLabel() 299QString Address::countryLabel()
273{ 300{
274 return i18n("Country"); 301 return i18n("Country");
275} 302}
276 303
277 304
278void Address::setLabel( const QString &s ) 305void Address::setLabel( const QString &s )
279{ 306{
280 mEmpty = false; 307 mEmpty = false;
281 308
282 mLabel = s; 309 mLabel = s;
283} 310}
284 311
285QString Address::label() const 312QString Address::label() const
286{ 313{
287 return mLabel; 314 return mLabel;
288} 315}
289 316
290QString Address::labelLabel() 317QString Address::labelLabel()
291{ 318{
292 return i18n("Delivery Label"); 319 return i18n("Delivery Label");
293} 320}
294 321
295Address::TypeList Address::typeList() 322Address::TypeList Address::typeList()
296{ 323{
297 TypeList list; 324 TypeList list;
298 325
299 list << Dom << Intl << Postal << Parcel << Home << Work << Pref; 326 list << Dom << Intl << Postal << Parcel << Home << Work << Pref;
300 327
301 return list; 328 return list;
302} 329}
303 330
304QString Address::typeLabel( int type ) 331QString Address::typeLabel( int type )
305{ 332{
306 QString label; 333 QString label;
307 if ( type & Dom ) 334 if ( type & Dom )
308 label += i18n("Domestic")+" "; 335 label += i18n("Domestic")+" ";
309 if ( type & Intl ) 336 if ( type & Intl )
310 label += i18n("International")+" "; 337 label += i18n("International")+" ";
311 if ( type & Postal ) 338 if ( type & Postal )
312 label += i18n("Postal")+" "; 339 label += i18n("Postal")+" ";
313 if ( type & Parcel ) 340 if ( type & Parcel )
314 label += i18n("Parcel")+" "; 341 label += i18n("Parcel")+" ";
315 if ( type & Work ) 342 if ( type & Work )
316 label += i18n("Work Address", "Work")+" "; 343 label += i18n("Work Address", "Work")+" ";
317 if ( type & Home ) 344 if ( type & Home )
318 label += i18n("Home Address", "Home") +" "; 345 label += i18n("Home Address", "Home") +" ";
319 if ( type & Pref ) 346 if ( type & Pref )
320 label += i18n("Preferred Address", "(p)"); 347 label += i18n("Preferred Address", "(p)");
321 if ( label.isEmpty() ) 348 if ( label.isEmpty() )
322 label = i18n("Other"); 349 label = i18n("Other");
323 return label; 350 return label;
324 351
325#if 0 352#if 0
326 switch ( type ) { 353 switch ( type ) {
327 case Dom: 354 case Dom:
328 return i18n("Domestic"); 355 return i18n("Domestic");
329 break; 356 break;
330 case Intl: 357 case Intl:
331 return i18n("International"); 358 return i18n("International");
332 break; 359 break;
333 case Postal: 360 case Postal:
334 return i18n("Postal"); 361 return i18n("Postal");
335 break; 362 break;
336 case Parcel: 363 case Parcel:
337 return i18n("Parcel"); 364 return i18n("Parcel");
338 break; 365 break;
339 case Home: 366 case Home:
340 return i18n("Home Address", "Home"); 367 return i18n("Home Address", "Home");
341 break; 368 break;
342 case Work: 369 case Work:
343 return i18n("Work Address", "Work"); 370 return i18n("Work Address", "Work");
344 break; 371 break;
345 case Pref: 372 case Pref:
346 return i18n("Preferred Address"); 373 return i18n("Preferred Address");
347 break; 374 break;
348 default: 375 default:
349 return i18n("Other"); 376 return i18n("Other");
350 break; 377 break;
351 } 378 }
352#endif 379#endif
353} 380}
354 381
355void Address::dump() const 382void Address::dump() const
356{ 383{
357 qDebug("Address::dump() +++++++++++++++++ "); 384 qDebug("Address::dump() +++++++++++++++++ ");
358#if 0 385#if 0
359 kdDebug(5700) << " Address {" << endl; 386 kdDebug(5700) << " Address {" << endl;
360 kdDebug(5700) << " Id: " << id() << endl; 387 kdDebug(5700) << " Id: " << id() << endl;
361 kdDebug(5700) << " Extended: " << extended() << endl; 388 kdDebug(5700) << " Extended: " << extended() << endl;
362 kdDebug(5700) << " Street: " << street() << endl; 389 kdDebug(5700) << " Street: " << street() << endl;
363 kdDebug(5700) << " Postal Code: " << postalCode() << endl; 390 kdDebug(5700) << " Postal Code: " << postalCode() << endl;
364 kdDebug(5700) << " Locality: " << locality() << endl; 391 kdDebug(5700) << " Locality: " << locality() << endl;
365 kdDebug(5700) << " }" << endl; 392 kdDebug(5700) << " }" << endl;
366#endif 393#endif
367} 394}
368 395
369 396
370QString Address::formattedAddress( const QString &realName 397QString Address::formattedAddress( const QString &realName
371 , const QString &orgaName ) const 398 , const QString &orgaName ) const
372{ 399{
373 QString ciso; 400 QString ciso;
374 QString addrTemplate; 401 QString addrTemplate;
375 QString ret; 402 QString ret;
376 403
377 // ************************************************************** 404 // **************************************************************
378 // LR: currently we have no iso handling - we will format the address manually here 405 // LR: currently we have no iso handling - we will format the address manually here
379 406
380 QString text; 407 QString text;
381 if ( !street().isEmpty() ) 408 if ( !street().isEmpty() )
382 text += street() + "\n"; 409 text += street() + "\n";
383 410
384 if ( !postOfficeBox().isEmpty() ) 411 if ( !postOfficeBox().isEmpty() )
385 text += postOfficeBox() + "\n"; 412 text += postOfficeBox() + "\n";
386 413
387 text += locality() + QString(" ") + region(); 414 text += locality() + QString(" ") + region();
388 415
389 if ( !postalCode().isEmpty() ) 416 if ( !postalCode().isEmpty() )
390 text += QString(", ") + postalCode(); 417 text += QString(", ") + postalCode();
391 418
392 text += "\n"; 419 text += "\n";
393 420
394 if ( !country().isEmpty() ) 421 if ( !country().isEmpty() )
395 text += country() + "\n"; 422 text += country() + "\n";
396 423
397 text += extended(); 424 text += extended();
398 425
399 426
400 return text; 427 return text;
401 // ************************************************************** 428 // **************************************************************
402 429
403 // FIXME: first check for iso-country-field and prefer that one 430 // FIXME: first check for iso-country-field and prefer that one
404 if ( !country().isEmpty() ) { 431 if ( !country().isEmpty() ) {
405 ciso = countryToISO( country() ); 432 ciso = countryToISO( country() );
406 } else { 433 } else {
407 // fall back to our own country 434 // fall back to our own country
408 ciso = KGlobal::locale()->country(); 435 ciso = KGlobal::locale()->country();
409 } 436 }
410 //qDebug("ciso %s ",ciso.latin1() ); 437 //qDebug("ciso %s ",ciso.latin1() );
411 KSimpleConfig entry( locate( "locale", 438 KSimpleConfig entry( locate( "locale",
412 QString( "l10n/" ) + ciso + QString( "/entry.desktop" ) ) ); 439 QString( "l10n/" ) + ciso + QString( "/entry.desktop" ) ) );
413 entry.setGroup( "KCM Locale" ); 440 entry.setGroup( "KCM Locale" );
414 441
415 // decide whether this needs special business address formatting 442 // decide whether this needs special business address formatting
416 if ( orgaName.isNull() ) { 443 if ( orgaName.isNull() ) {
417 addrTemplate = entry.readEntry( "AddressFormat" ); 444 addrTemplate = entry.readEntry( "AddressFormat" );
418 } else { 445 } else {
419 addrTemplate = entry.readEntry( "BusinessAddressFormat" ); 446 addrTemplate = entry.readEntry( "BusinessAddressFormat" );
420 if ( addrTemplate.isEmpty() ) 447 if ( addrTemplate.isEmpty() )
421 addrTemplate = entry.readEntry( "AddressFormat" ); 448 addrTemplate = entry.readEntry( "AddressFormat" );
422 } 449 }
423 450
424 // in the case there's no format found at all, default to what we've always 451 // in the case there's no format found at all, default to what we've always
425 // used: 452 // used:
426 if ( addrTemplate.isEmpty() ) { 453 if ( addrTemplate.isEmpty() ) {
427 qDebug("address format database incomplete****************** "); 454 qDebug("address format database incomplete****************** ");
428 kdWarning(5700) << "address format database incomplete " 455 kdWarning(5700) << "address format database incomplete "
429 << "(no format for locale " << ciso 456 << "(no format for locale " << ciso
430 << " found). Using default address formatting." << endl; 457 << " found). Using default address formatting." << endl;
431 addrTemplate = "%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z"; 458 addrTemplate = "%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z";
432 } 459 }
433 460
434 // scan 461 // scan
435 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName ); 462 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName );
436 463
437 // now add the country line if needed (formatting this time according to 464 // now add the country line if needed (formatting this time according to
438 // the rules of our own system country ) 465 // the rules of our own system country )
439 if ( !country().isEmpty() ) { 466 if ( !country().isEmpty() ) {
440 KSimpleConfig entry( locate( "locale", QString( "l10n/" ) 467 KSimpleConfig entry( locate( "locale", QString( "l10n/" )
441 + KGlobal::locale()->country() + QString( "/entry.desktop" ) ) ); 468 + KGlobal::locale()->country() + QString( "/entry.desktop" ) ) );
442 entry.setGroup( "KCM Locale" ); 469 entry.setGroup( "KCM Locale" );
443 QString cpos = entry.readEntry( "AddressCountryPosition" ); 470 QString cpos = entry.readEntry( "AddressCountryPosition" );
444 if ( "BELOW" == cpos || cpos.isEmpty() ) { 471 if ( "BELOW" == cpos || cpos.isEmpty() ) {
445 ret = ret + "\n\n" + country().upper(); 472 ret = ret + "\n\n" + country().upper();
446 } else if ( "below" == cpos ) { 473 } else if ( "below" == cpos ) {
447 ret = ret + "\n\n" + country(); 474 ret = ret + "\n\n" + country();
448 } else if ( "ABOVE" == cpos ) { 475 } else if ( "ABOVE" == cpos ) {
449 ret = country().upper() + "\n\n" + ret; 476 ret = country().upper() + "\n\n" + ret;
450 } else if ( "above" == cpos ) { 477 } else if ( "above" == cpos ) {
451 ret = country() + "\n\n" + ret; 478 ret = country() + "\n\n" + ret;
452 } 479 }
453 } 480 }
454 481
455 return ret; 482 return ret;
456} 483}
457 484
458bool Address::parseAddressTemplateSection( const QString &tsection, 485bool Address::parseAddressTemplateSection( const QString &tsection,
459 QString &result, const QString &realName, const QString &orgaName ) const 486 QString &result, const QString &realName, const QString &orgaName ) const
460{ 487{
461 // This method first parses and substitutes any bracketed sections and 488 // This method first parses and substitutes any bracketed sections and
462 // after that replaces any tags with their values. If a bracketed section 489 // after that replaces any tags with their values. If a bracketed section
463 // or a tag evaluate to zero, they are not just removed but replaced 490 // or a tag evaluate to zero, they are not just removed but replaced
464 // with a placeholder. This is because in the last step conditionals are 491 // with a placeholder. This is because in the last step conditionals are
465 // resolved which depend on information about zero-evaluations. 492 // resolved which depend on information about zero-evaluations.
466 result = tsection; 493 result = tsection;
467 int stpos = 0; 494 int stpos = 0;
468 bool ret = false; 495 bool ret = false;
469 496
470 // first check for brackets that have to be evaluated first 497 // first check for brackets that have to be evaluated first
471 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos ); 498 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
472 while ( -1 != fpos ) { 499 while ( -1 != fpos ) {
473 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length(); 500 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length();
474 int bpos2; 501 int bpos2;
475 // expect opening bracket and find next balanced closing bracket. If 502 // expect opening bracket and find next balanced closing bracket. If
476 // next char is no opening bracket, continue parsing (no valid tag) 503 // next char is no opening bracket, continue parsing (no valid tag)
477 if ( '(' == result[bpos1] ) { 504 if ( '(' == result[bpos1] ) {
478 bpos2 = findBalancedBracket( result, bpos1 ); 505 bpos2 = findBalancedBracket( result, bpos1 );
479 if ( -1 != bpos2 ) { 506 if ( -1 != bpos2 ) {
480 // we have balanced brackets, recursively parse: 507 // we have balanced brackets, recursively parse:
481 QString rplstr; 508 QString rplstr;
482 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1, 509 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1,
483 bpos2-bpos1-1 ), rplstr, 510 bpos2-bpos1-1 ), rplstr,
484 realName, orgaName ); 511 realName, orgaName );
485 if ( purge ) { 512 if ( purge ) {
486 // purge -> remove all 513 // purge -> remove all
487 // replace with !_P_!, so conditional tags work later 514 // replace with !_P_!, so conditional tags work later
488 result.replace( fpos, bpos2 - fpos + 1, "!_P_!" ); 515 result.replace( fpos, bpos2 - fpos + 1, "!_P_!" );
489 // leave stpos as it is 516 // leave stpos as it is
490 } else { 517 } else {
491 // no purge -> replace with recursively parsed string 518 // no purge -> replace with recursively parsed string
492 result.replace( fpos, bpos2 - fpos + 1, rplstr ); 519 result.replace( fpos, bpos2 - fpos + 1, rplstr );
493 ret = true; 520 ret = true;
494 stpos = fpos + rplstr.length(); 521 stpos = fpos + rplstr.length();
495 } 522 }
496 } else { 523 } else {
497 // unbalanced brackets: keep on parsing (should not happen 524 // unbalanced brackets: keep on parsing (should not happen
498 // and will result in bad formatting) 525 // and will result in bad formatting)
499 stpos = bpos1; 526 stpos = bpos1;
500 } 527 }
501 } 528 }
502 fpos = result.find( KABC_FMTTAG_purgeempty, stpos ); 529 fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
503 } 530 }
504 531
505 // after sorting out all purge tags, we just search'n'replace the rest, 532 // after sorting out all purge tags, we just search'n'replace the rest,
506 // keeping track of whether at least one tag evaluates to something. 533 // keeping track of whether at least one tag evaluates to something.
507 // The following macro needs QString for R_FIELD 534 // The following macro needs QString for R_FIELD
508 // It substitutes !_P_! for empty fields so conditional tags work later 535 // It substitutes !_P_! for empty fields so conditional tags work later
509#define REPLTAG(R_TAG,R_FIELD) \ 536#define REPLTAG(R_TAG,R_FIELD) \
510 if ( result.contains(R_TAG, false) ) { \ 537 if ( result.contains(R_TAG, false) ) { \
511 QString rpl = R_FIELD.isEmpty() ? QString("!_P_!") : R_FIELD; \ 538 QString rpl = R_FIELD.isEmpty() ? QString("!_P_!") : R_FIELD; \
512 result.replace( R_TAG, rpl ); \ 539 result.replace( R_TAG, rpl ); \
513 if ( !R_FIELD.isEmpty() ) { \ 540 if ( !R_FIELD.isEmpty() ) { \
514 ret = true; \ 541 ret = true; \
515 } \ 542 } \
516 } 543 }
517 REPLTAG( KABC_FMTTAG_realname, realName ); 544 REPLTAG( KABC_FMTTAG_realname, realName );
518 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() ); 545 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() );
519 REPLTAG( KABC_FMTTAG_company, orgaName ); 546 REPLTAG( KABC_FMTTAG_company, orgaName );
520 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() ); 547 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() );
521 REPLTAG( KABC_FMTTAG_pobox, postOfficeBox() ); 548 REPLTAG( KABC_FMTTAG_pobox, postOfficeBox() );
522 REPLTAG( KABC_FMTTAG_street, street() ); 549 REPLTAG( KABC_FMTTAG_street, street() );
523 REPLTAG( KABC_FMTTAG_STREET, street().upper() ); 550 REPLTAG( KABC_FMTTAG_STREET, street().upper() );
524 REPLTAG( KABC_FMTTAG_zipcode, postalCode() ); 551 REPLTAG( KABC_FMTTAG_zipcode, postalCode() );
525 REPLTAG( KABC_FMTTAG_location, locality() ); 552 REPLTAG( KABC_FMTTAG_location, locality() );
526 REPLTAG( KABC_FMTTAG_LOCATION, locality().upper() ); 553 REPLTAG( KABC_FMTTAG_LOCATION, locality().upper() );
527 REPLTAG( KABC_FMTTAG_region, region() ); 554 REPLTAG( KABC_FMTTAG_region, region() );
528 REPLTAG( KABC_FMTTAG_REGION, region().upper() ); 555 REPLTAG( KABC_FMTTAG_REGION, region().upper() );
529 result.replace( KABC_FMTTAG_newline, "\n" ); 556 result.replace( KABC_FMTTAG_newline, "\n" );
530#undef REPLTAG 557#undef REPLTAG
531 558
532 // conditional comma 559 // conditional comma
533 fpos = result.find( KABC_FMTTAG_condcomma, 0 ); 560 fpos = result.find( KABC_FMTTAG_condcomma, 0 );
534 while ( -1 != fpos ) { 561 while ( -1 != fpos ) {
535 QString str1 = result.mid( fpos - 5, 5 ); 562 QString str1 = result.mid( fpos - 5, 5 );
536 QString str2 = result.mid( fpos + 2, 5 ); 563 QString str2 = result.mid( fpos + 2, 5 );
537 if ( str1 != "!_P_!" && str2 != "!_P_!" ) { 564 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
538 result.replace( fpos, 2, ", " ); 565 result.replace( fpos, 2, ", " );
539 } else { 566 } else {
540 result.remove( fpos, 2 ); 567 result.remove( fpos, 2 );
541 } 568 }
542 fpos = result.find( KABC_FMTTAG_condcomma, fpos ); 569 fpos = result.find( KABC_FMTTAG_condcomma, fpos );
543 } 570 }
544 // conditional whitespace 571 // conditional whitespace
545 fpos = result.find( KABC_FMTTAG_condwhite, 0 ); 572 fpos = result.find( KABC_FMTTAG_condwhite, 0 );
546 while ( -1 != fpos ) { 573 while ( -1 != fpos ) {
547 QString str1 = result.mid( fpos - 5, 5 ); 574 QString str1 = result.mid( fpos - 5, 5 );
548 QString str2 = result.mid( fpos + 2, 5 ); 575 QString str2 = result.mid( fpos + 2, 5 );
549 if ( str1 != "!_P_!" && str2 != "!_P_!" ) { 576 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
550 result.replace( fpos, 2, " " ); 577 result.replace( fpos, 2, " " );
551 } else { 578 } else {
552 result.remove( fpos, 2 ); 579 result.remove( fpos, 2 );
553 } 580 }
554 fpos = result.find( KABC_FMTTAG_condwhite, fpos ); 581 fpos = result.find( KABC_FMTTAG_condwhite, fpos );
555 } 582 }
556 583
557 // remove purged: 584 // remove purged:
558//US my QT version does not support remove. So lets do it the old fashioned way. 585//US my QT version does not support remove. So lets do it the old fashioned way.
559//US result.remove( "!_P_!" ); 586//US result.remove( "!_P_!" );
560 int n = result.find("!_P_!"); 587 int n = result.find("!_P_!");
561 if (n >= 0) 588 if (n >= 0)
562 result.remove( n, 5 ); 589 result.remove( n, 5 );
563 590
564 return ret; 591 return ret;
565} 592}
566 593
567int Address::findBalancedBracket( const QString &tsection, int pos ) const 594int Address::findBalancedBracket( const QString &tsection, int pos ) const
568{ 595{
569 int balancecounter = 0; 596 int balancecounter = 0;
570 for( unsigned int i = pos + 1; i < tsection.length(); i++ ) { 597 for( unsigned int i = pos + 1; i < tsection.length(); i++ ) {
571 if ( ')' == tsection.at(i) && 0 == balancecounter ) { 598 if ( ')' == tsection.at(i) && 0 == balancecounter ) {
572 // found end of brackets 599 // found end of brackets
573 return i; 600 return i;
574 } else 601 } else
575 if ( '(' == tsection.at(i) ) { 602 if ( '(' == tsection.at(i) ) {
576 // nested brackets 603 // nested brackets
577 balancecounter++; 604 balancecounter++;
578 } 605 }
579 } 606 }
580 return -1; 607 return -1;
581} 608}
582 609
583QString Address::countryToISO( const QString &cname ) 610QString Address::countryToISO( const QString &cname )
584{ 611{
585 // we search a map file for translations from country names to 612 // we search a map file for translations from country names to
586 // iso codes, storing caching things in a QMap for faster future 613 // iso codes, storing caching things in a QMap for faster future
587 // access. 614 // access.
588/*US 615/*US
589 616
590 QString isoCode = mISOMap[ cname ]; 617 QString isoCode = mISOMap[ cname ];
591 if ( !isoCode.isEmpty() ) 618 if ( !isoCode.isEmpty() )
592 return isoCode; 619 return isoCode;
593 620
594 QString mapfile = KGlobal::dirs()->findResource( "data", 621 QString mapfile = KGlobal::dirs()->findResource( "data",
595 QString::fromLatin1( "kabc/countrytransl.map" ) ); 622 QString::fromLatin1( "kabc/countrytransl.map" ) );
596 623
597 QFile file( mapfile ); 624 QFile file( mapfile );
598 if ( file.open( IO_ReadOnly ) ) { 625 if ( file.open( IO_ReadOnly ) ) {
599 QTextStream s( &file ); 626 QTextStream s( &file );
600 QString strbuf = s.readLine(); 627 QString strbuf = s.readLine();
601 while( !strbuf.isNull() ) { 628 while( !strbuf.isNull() ) {
602 if ( strbuf.startsWith( cname ) ) { 629 if ( strbuf.startsWith( cname ) ) {
603 int index = strbuf.findRev('\t'); 630 int index = strbuf.findRev('\t');
604 strbuf = strbuf.mid(index+1, 2); 631 strbuf = strbuf.mid(index+1, 2);
605 file.close(); 632 file.close();
606 mISOMap[ cname ] = strbuf; 633 mISOMap[ cname ] = strbuf;
607 return strbuf; 634 return strbuf;
608 } 635 }
609 strbuf = s.readLine(); 636 strbuf = s.readLine();
610 } 637 }
611 file.close(); 638 file.close();
612 } 639 }
613*/ 640*/
614 // fall back to system country 641 // fall back to system country
615 mISOMap[ cname ] = KGlobal::locale()->country(); 642 mISOMap[ cname ] = KGlobal::locale()->country();
616 return KGlobal::locale()->country(); 643 return KGlobal::locale()->country();
617} 644}
618 645
619QString Address::ISOtoCountry( const QString &ISOname ) 646QString Address::ISOtoCountry( const QString &ISOname )
620{ 647{
621/*US 648/*US
622 // get country name from ISO country code (e.g. "no" -> i18n("Norway")) 649 // get country name from ISO country code (e.g. "no" -> i18n("Norway"))
623 QString mapfile = KGlobal::dirs()->findResource( "data", 650 QString mapfile = KGlobal::dirs()->findResource( "data",
624 QString::fromLatin1( "kabc/countrytransl.map" ) ); 651 QString::fromLatin1( "kabc/countrytransl.map" ) );
625 652
626kdWarning() << "MAPFILE : " << mapfile << endl; 653kdWarning() << "MAPFILE : " << mapfile << endl;
627 QFile file( mapfile ); 654 QFile file( mapfile );
628 if ( file.open( IO_ReadOnly ) ) { 655 if ( file.open( IO_ReadOnly ) ) {
629 QTextStream s( &file ); 656 QTextStream s( &file );
630 QString searchStr = "\t" + ISOname.simplifyWhiteSpace().lower(); 657 QString searchStr = "\t" + ISOname.simplifyWhiteSpace().lower();
631kdWarning() << "Suche : " << searchStr << endl; 658kdWarning() << "Suche : " << searchStr << endl;
632 QString strbuf = s.readLine(); 659 QString strbuf = s.readLine();
633 int pos; 660 int pos;
634 while( !strbuf.isNull() ) { 661 while( !strbuf.isNull() ) {
635 if ( (pos=strbuf.find( searchStr )) != -1 ) { 662 if ( (pos=strbuf.find( searchStr )) != -1 ) {
636 file.close(); 663 file.close();
637 return i18n(strbuf.left(pos).utf8()); 664 return i18n(strbuf.left(pos).utf8());
638 } 665 }
639 strbuf = s.readLine(); 666 strbuf = s.readLine();
640 } 667 }
641 file.close(); 668 file.close();
642 } 669 }
643*/ 670*/
644 return ISOname; 671 return ISOname;
645} 672}
646 673
647QDataStream &KABC::operator<<( QDataStream &s, const Address &addr ) 674QDataStream &KABC::operator<<( QDataStream &s, const Address &addr )
648{ 675{
649 return s << addr.mId << addr.mType << addr.mPostOfficeBox << 676 return s << addr.mId << addr.mType << addr.mPostOfficeBox <<
650 addr.mExtended << addr.mStreet << addr.mLocality << 677 addr.mExtended << addr.mStreet << addr.mLocality <<
651 addr.mRegion << addr.mPostalCode << addr.mCountry << 678 addr.mRegion << addr.mPostalCode << addr.mCountry <<
652 addr.mLabel; 679 addr.mLabel;
653} 680}
654 681
655QDataStream &KABC::operator>>( QDataStream &s, Address &addr ) 682QDataStream &KABC::operator>>( QDataStream &s, Address &addr )
656{ 683{
657 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >> 684 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >>
658 addr.mStreet >> addr.mLocality >> addr.mRegion >> 685 addr.mStreet >> addr.mLocality >> addr.mRegion >>
659 addr.mPostalCode >> addr.mCountry >> addr.mLabel; 686 addr.mPostalCode >> addr.mCountry >> addr.mLabel;
660 687
661 addr.mEmpty = false; 688 addr.mEmpty = false;
662 689
663 return s; 690 return s;
664} 691}
diff --git a/kabc/address.h b/kabc/address.h
index 37dd851..38ad20b 100644
--- a/kabc/address.h
+++ b/kabc/address.h
@@ -1,348 +1,350 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_ADDRESS_H 28#ifndef KABC_ADDRESS_H
29#define KABC_ADDRESS_H 29#define KABC_ADDRESS_H
30 30
31#include <qmap.h> 31#include <qmap.h>
32#include <qstring.h> 32#include <qstring.h>
33#include <qregexp.h>
33#include <qstringlist.h> 34#include <qstringlist.h>
34#include <qvaluelist.h> 35#include <qvaluelist.h>
35 36
36// template tags for address formatting localization 37// template tags for address formatting localization
37#define KABC_FMTTAG_realname QString("%n") 38#define KABC_FMTTAG_realname QString("%n")
38#define KABC_FMTTAG_REALNAME QString("%N") 39#define KABC_FMTTAG_REALNAME QString("%N")
39#define KABC_FMTTAG_company QString("%cm") 40#define KABC_FMTTAG_company QString("%cm")
40#define KABC_FMTTAG_COMPANY QString("%CM") 41#define KABC_FMTTAG_COMPANY QString("%CM")
41#define KABC_FMTTAG_pobox QString("%p") 42#define KABC_FMTTAG_pobox QString("%p")
42#define KABC_FMTTAG_street QString("%s") 43#define KABC_FMTTAG_street QString("%s")
43#define KABC_FMTTAG_STREET QString("%S") 44#define KABC_FMTTAG_STREET QString("%S")
44#define KABC_FMTTAG_zipcode QString("%z") 45#define KABC_FMTTAG_zipcode QString("%z")
45#define KABC_FMTTAG_location QString("%l") 46#define KABC_FMTTAG_location QString("%l")
46#define KABC_FMTTAG_LOCATION QString("%L") 47#define KABC_FMTTAG_LOCATION QString("%L")
47#define KABC_FMTTAG_region QString("%r") 48#define KABC_FMTTAG_region QString("%r")
48#define KABC_FMTTAG_REGION QString("%R") 49#define KABC_FMTTAG_REGION QString("%R")
49#define KABC_FMTTAG_newline QString("\\n") 50#define KABC_FMTTAG_newline QString("\\n")
50#define KABC_FMTTAG_condcomma QString("%,") 51#define KABC_FMTTAG_condcomma QString("%,")
51#define KABC_FMTTAG_condwhite QString("%w") 52#define KABC_FMTTAG_condwhite QString("%w")
52#define KABC_FMTTAG_purgeempty QString("%0") 53#define KABC_FMTTAG_purgeempty QString("%0")
53 54
54namespace KABC { 55namespace KABC {
55 56
56/** 57/**
57 @short Postal address information. 58 @short Postal address information.
58 59
59 This class represents information about a postal address. 60 This class represents information about a postal address.
60*/ 61*/
61class Address 62class Address
62{ 63{
63 friend QDataStream &operator<<( QDataStream &, const Address & ); 64 friend QDataStream &operator<<( QDataStream &, const Address & );
64 friend QDataStream &operator>>( QDataStream &, Address & ); 65 friend QDataStream &operator>>( QDataStream &, Address & );
65 66
66 public: 67 public:
67 /** 68 /**
68 List of addresses. 69 List of addresses.
69 */ 70 */
70 typedef QValueList<Address> List; 71 typedef QValueList<Address> List;
71 typedef QValueList<int> TypeList; 72 typedef QValueList<int> TypeList;
72 73
73 /** 74 /**
74 Address types: 75 Address types:
75 76
76 @li @p Dom - domestic 77 @li @p Dom - domestic
77 @li @p Intl - international 78 @li @p Intl - international
78 @li @p Postal - postal 79 @li @p Postal - postal
79 @li @p Parcel - parcel 80 @li @p Parcel - parcel
80 @li @p Home - home address 81 @li @p Home - home address
81 @li @p Work - address at work 82 @li @p Work - address at work
82 @li @p Pref - preferred address 83 @li @p Pref - preferred address
83 */ 84 */
84 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32, 85 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32,
85 Pref = 64 }; 86 Pref = 64 };
86 87
87 /** 88 /**
88 Constructor that creates an empty Address, which is initialized 89 Constructor that creates an empty Address, which is initialized
89 with a unique id (see @ref id()). 90 with a unique id (see @ref id()).
90 */ 91 */
91 Address(); 92 Address();
92 93
93 /** 94 /**
94 This is like @ref Address() just above, with the difference 95 This is like @ref Address() just above, with the difference
95 that you can specify the type. 96 that you can specify the type.
96 */ 97 */
97 Address( int ); 98 Address( int );
99 bool matchAddress( QRegExp* searchExp ) const;
98 100
99 bool operator==( const Address & ) const; 101 bool operator==( const Address & ) const;
100 bool operator!=( const Address & ) const; 102 bool operator!=( const Address & ) const;
101 103
102 /** 104 /**
103 Returns true, if the address is empty. 105 Returns true, if the address is empty.
104 */ 106 */
105 bool isEmpty() const; 107 bool isEmpty() const;
106 108
107 /** 109 /**
108 Clears all entries of the address. 110 Clears all entries of the address.
109 */ 111 */
110 void clear(); 112 void clear();
111 QStringList asList(); 113 QStringList asList();
112 114
113 /** 115 /**
114 Sets the unique id. 116 Sets the unique id.
115 */ 117 */
116 void setId( const QString & ); 118 void setId( const QString & );
117 119
118 /* 120 /*
119 Returns the unique id. 121 Returns the unique id.
120 */ 122 */
121 QString id() const; 123 QString id() const;
122 124
123 /** 125 /**
124 Sets the type of address. See enum for definiton of types. 126 Sets the type of address. See enum for definiton of types.
125 127
126 @param type type, can be a bitwise or of multiple types. 128 @param type type, can be a bitwise or of multiple types.
127 */ 129 */
128 void setType( int type ); 130 void setType( int type );
129 131
130 /** 132 /**
131 Returns the type of address. Can be a bitwise or of multiple types. 133 Returns the type of address. Can be a bitwise or of multiple types.
132 */ 134 */
133 int type() const; 135 int type() const;
134 136
135 /** 137 /**
136 Returns a translated string of all types the address has. 138 Returns a translated string of all types the address has.
137 */ 139 */
138 QString typeLabel() const; 140 QString typeLabel() const;
139 141
140 /** 142 /**
141 Sets the post office box. 143 Sets the post office box.
142 */ 144 */
143 void setPostOfficeBox( const QString & ); 145 void setPostOfficeBox( const QString & );
144 146
145 /** 147 /**
146 Returns the post office box. 148 Returns the post office box.
147 */ 149 */
148 QString postOfficeBox() const; 150 QString postOfficeBox() const;
149 151
150 /** 152 /**
151 Returns the translated label for post office box field. 153 Returns the translated label for post office box field.
152 */ 154 */
153 static QString postOfficeBoxLabel(); 155 static QString postOfficeBoxLabel();
154 156
155 /** 157 /**
156 Sets the extended address information. 158 Sets the extended address information.
157 */ 159 */
158 void setExtended( const QString & ); 160 void setExtended( const QString & );
159 161
160 /** 162 /**
161 Returns the extended address information. 163 Returns the extended address information.
162 */ 164 */
163 QString extended() const; 165 QString extended() const;
164 166
165 /** 167 /**
166 Returns the translated label for extended field. 168 Returns the translated label for extended field.
167 */ 169 */
168 static QString extendedLabel(); 170 static QString extendedLabel();
169 171
170 /** 172 /**
171 Sets the street (including number). 173 Sets the street (including number).
172 */ 174 */
173 void setStreet( const QString & ); 175 void setStreet( const QString & );
174 176
175 /** 177 /**
176 Returns the street. 178 Returns the street.
177 */ 179 */
178 QString street() const; 180 QString street() const;
179 181
180 /** 182 /**
181 Returns the translated label for street field. 183 Returns the translated label for street field.
182 */ 184 */
183 static QString streetLabel(); 185 static QString streetLabel();
184 186
185 /** 187 /**
186 Sets the locality, e.g. city. 188 Sets the locality, e.g. city.
187 */ 189 */
188 void setLocality( const QString & ); 190 void setLocality( const QString & );
189 191
190 /** 192 /**
191 Returns the locality. 193 Returns the locality.
192 */ 194 */
193 QString locality() const; 195 QString locality() const;
194 196
195 /** 197 /**
196 Returns the translated label for locality field. 198 Returns the translated label for locality field.
197 */ 199 */
198 static QString localityLabel(); 200 static QString localityLabel();
199 201
200 /** 202 /**
201 Sets the region, e.g. state. 203 Sets the region, e.g. state.
202 */ 204 */
203 void setRegion( const QString & ); 205 void setRegion( const QString & );
204 206
205 /** 207 /**
206 Returns the region. 208 Returns the region.
207 */ 209 */
208 QString region() const; 210 QString region() const;
209 211
210 /** 212 /**
211 Returns the translated label for region field. 213 Returns the translated label for region field.
212 */ 214 */
213 static QString regionLabel(); 215 static QString regionLabel();
214 216
215 /** 217 /**
216 Sets the postal code. 218 Sets the postal code.
217 */ 219 */
218 void setPostalCode( const QString & ); 220 void setPostalCode( const QString & );
219 221
220 /** 222 /**
221 Returns the postal code. 223 Returns the postal code.
222 */ 224 */
223 QString postalCode() const; 225 QString postalCode() const;
224 226
225 /** 227 /**
226 Returns the translated label for postal code field. 228 Returns the translated label for postal code field.
227 */ 229 */
228 static QString postalCodeLabel(); 230 static QString postalCodeLabel();
229 231
230 /** 232 /**
231 Sets the country. 233 Sets the country.
232 */ 234 */
233 void setCountry( const QString & ); 235 void setCountry( const QString & );
234 236
235 /** 237 /**
236 Returns the country. 238 Returns the country.
237 */ 239 */
238 QString country() const; 240 QString country() const;
239 241
240 /** 242 /**
241 Returns the translated label for country field. 243 Returns the translated label for country field.
242 */ 244 */
243 static QString countryLabel(); 245 static QString countryLabel();
244 246
245 /** 247 /**
246 Sets the delivery label. This is the literal text to be used as label. 248 Sets the delivery label. This is the literal text to be used as label.
247 */ 249 */
248 void setLabel( const QString & ); 250 void setLabel( const QString & );
249 251
250 /** 252 /**
251 Returns the delivery label. 253 Returns the delivery label.
252 */ 254 */
253 QString label() const; 255 QString label() const;
254 256
255 /** 257 /**
256 Returns the translated label for delivery label field. 258 Returns the translated label for delivery label field.
257 */ 259 */
258 static QString labelLabel(); 260 static QString labelLabel();
259 261
260 /** 262 /**
261 Returns the list of available types. 263 Returns the list of available types.
262 */ 264 */
263 static TypeList typeList(); 265 static TypeList typeList();
264 266
265 /** 267 /**
266 Returns the translated label for a special type. 268 Returns the translated label for a special type.
267 */ 269 */
268 static QString typeLabel( int type ); 270 static QString typeLabel( int type );
269 271
270 /** 272 /**
271 Used for debug output. 273 Used for debug output.
272 */ 274 */
273 void dump() const; 275 void dump() const;
274 276
275 /** 277 /**
276 Returns this address formatted according to the country-specific 278 Returns this address formatted according to the country-specific
277 address formatting rules. The formatting rules applied depend on 279 address formatting rules. The formatting rules applied depend on
278 either the addresses {@link #country country} field, or (if the 280 either the addresses {@link #country country} field, or (if the
279 latter is empty) on the system country setting. If companyName is 281 latter is empty) on the system country setting. If companyName is
280 provided, an available business address format will be preferred. 282 provided, an available business address format will be preferred.
281 283
282 @param realName the formatted name of the contact 284 @param realName the formatted name of the contact
283 @param orgaName the name of the organization or company 285 @param orgaName the name of the organization or company
284 @return the formatted address (containing newline characters) 286 @return the formatted address (containing newline characters)
285 */ 287 */
286 QString formattedAddress( const QString &realName=QString::null 288 QString formattedAddress( const QString &realName=QString::null
287 , const QString &orgaName=QString::null ) const; 289 , const QString &orgaName=QString::null ) const;
288 290
289 /** 291 /**
290 Returns ISO code for a localized country name. Only localized country 292 Returns ISO code for a localized country name. Only localized country
291 names will be understood. This might be replaced by a KLocale method in 293 names will be understood. This might be replaced by a KLocale method in
292 the future. 294 the future.
293 @param cname name of the country 295 @param cname name of the country
294 @return two digit ISO code 296 @return two digit ISO code
295 */ 297 */
296 static QString countryToISO( const QString &cname ); 298 static QString countryToISO( const QString &cname );
297 299
298 /** 300 /**
299 Returns a localized country name for a ISO code. 301 Returns a localized country name for a ISO code.
300 This might be replaced by a KLocale method in the future. 302 This might be replaced by a KLocale method in the future.
301 @param ISOname two digit ISO code 303 @param ISOname two digit ISO code
302 @return localized name of the country 304 @return localized name of the country
303 @since 3.2 305 @since 3.2
304 */ 306 */
305 static QString ISOtoCountry( const QString &ISOname ); 307 static QString ISOtoCountry( const QString &ISOname );
306 308
307 private: 309 private:
308 /** 310 /**
309 Parses a snippet of an address template 311 Parses a snippet of an address template
310 @param tsection the template string to be parsed 312 @param tsection the template string to be parsed
311 @param result QString reference in which the result will be stored 313 @param result QString reference in which the result will be stored
312 @return true if at least one tag evaluated positively, else false 314 @return true if at least one tag evaluated positively, else false
313 */ 315 */
314 bool parseAddressTemplateSection( const QString &tsection 316 bool parseAddressTemplateSection( const QString &tsection
315 , QString &result 317 , QString &result
316 , const QString &realName 318 , const QString &realName
317 , const QString &orgaName ) const; 319 , const QString &orgaName ) const;
318 320
319 /** 321 /**
320 Finds the balanced closing bracket starting from the opening bracket at 322 Finds the balanced closing bracket starting from the opening bracket at
321 pos in tsection. 323 pos in tsection.
322 @return position of closing bracket, -1 for unbalanced brackets 324 @return position of closing bracket, -1 for unbalanced brackets
323 */ 325 */
324 int findBalancedBracket( const QString &tsection, int pos ) const; 326 int findBalancedBracket( const QString &tsection, int pos ) const;
325 327
326 bool mEmpty; 328 bool mEmpty;
327 329
328 QString mId; 330 QString mId;
329 int mType; 331 int mType;
330 332
331 QString mPostOfficeBox; 333 QString mPostOfficeBox;
332 QString mExtended; 334 QString mExtended;
333 QString mStreet; 335 QString mStreet;
334 QString mLocality; 336 QString mLocality;
335 QString mRegion; 337 QString mRegion;
336 QString mPostalCode; 338 QString mPostalCode;
337 QString mCountry; 339 QString mCountry;
338 QString mLabel; 340 QString mLabel;
339 341
340 static QMap<QString, QString> mISOMap; 342 static QMap<QString, QString> mISOMap;
341}; 343};
342 344
343QDataStream &operator<<( QDataStream &, const Address & ); 345QDataStream &operator<<( QDataStream &, const Address & );
344QDataStream &operator>>( QDataStream &, Address & ); 346QDataStream &operator>>( QDataStream &, Address & );
345 347
346} 348}
347 349
348#endif 350#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 155ce24..7e1e414 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,2205 +1,2230 @@
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
310{
311 KABC::Address::List::Iterator addressIter;
312 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
313 ++addressIter ) {
314 if ( (*addressIter).matchAddress( re ) )
315 return true;
316 }
317 return false;
318}
319bool Addressee::matchPhoneNumber( QRegExp* re ) const
320{
321 KABC::PhoneNumber::List::Iterator phoneIter;
322
323 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) {
324#if QT_VERSION >= 0x030000
325 if (re->search( (*phoneIter).number() ) == 0)
326#else
327 if (re->match( (*phoneIter).number() ) == 0)
328#endif
329 return true;
309 330
331 }
332 return false;
333
334}
310void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 335void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
311{ 336{
312 // merge all standard non-outlook fields. 337 // merge all standard non-outlook fields.
313 //if isSubSet (e.g. mobile phone sync) merge all fields 338 //if isSubSet (e.g. mobile phone sync) merge all fields
314 339
315 detach(); 340 detach();
316 if ( isSubSet ) { 341 if ( isSubSet ) {
317 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 342 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
318 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 343 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
319 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 344 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
320 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 345 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
321 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 346 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
322 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 347 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
323 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 348 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
324 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 349 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
325 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 350 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
326 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 351 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
327 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 352 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
328 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 353 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
329 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 354 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
330 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 ;
331 if ( !mData->birthday.isValid() ) 356 if ( !mData->birthday.isValid() )
332 if ( ad.mData->birthday.isValid()) 357 if ( ad.mData->birthday.isValid())
333 mData->birthday = ad.mData->birthday; 358 mData->birthday = ad.mData->birthday;
334 359
335 } 360 }
336 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 361 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
337 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 362 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
338 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 363 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
339 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 364 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
340 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 365 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
341 QStringList t; 366 QStringList t;
342 QStringList tAD; 367 QStringList tAD;
343 uint iii; 368 uint iii;
344 369
345 // ********** phone numbers 370 // ********** phone numbers
346 if ( isSubSet ) { 371 if ( isSubSet ) {
347 PhoneNumber::List phoneAD = ad.phoneNumbers(); 372 PhoneNumber::List phoneAD = ad.phoneNumbers();
348 PhoneNumber::List::Iterator phoneItAD; 373 PhoneNumber::List::Iterator phoneItAD;
349 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 374 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
350 bool found = false; 375 bool found = false;
351 PhoneNumber::List::Iterator it; 376 PhoneNumber::List::Iterator it;
352 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 377 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
353 if ( ( *phoneItAD ).contains( (*it) ) ) { 378 if ( ( *phoneItAD ).contains( (*it) ) ) {
354 found = true; 379 found = true;
355 (*it).setType( ( *phoneItAD ).type() ); 380 (*it).setType( ( *phoneItAD ).type() );
356 (*it).setNumber( ( *phoneItAD ).number() ); 381 (*it).setNumber( ( *phoneItAD ).number() );
357 break; 382 break;
358 } 383 }
359 } 384 }
360 // if ( isSubSet && ! found ) 385 // if ( isSubSet && ! found )
361 if ( ! found ) // LR try this one... 386 if ( ! found ) // LR try this one...
362 mData->phoneNumbers.append( *phoneItAD ); 387 mData->phoneNumbers.append( *phoneItAD );
363 } 388 }
364 } else { 389 } else {
365 PhoneNumber::List phoneAD = ad.phoneNumbers(); 390 PhoneNumber::List phoneAD = ad.phoneNumbers();
366 PhoneNumber::List::Iterator phoneItAD; 391 PhoneNumber::List::Iterator phoneItAD;
367 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 392 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
368 bool found = false; 393 bool found = false;
369 PhoneNumber::List::Iterator it; 394 PhoneNumber::List::Iterator it;
370 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 395 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
371 if ( ( *phoneItAD ).contains( (*it) ) ) { 396 if ( ( *phoneItAD ).contains( (*it) ) ) {
372 found = true; 397 found = true;
373 (*it).setType( ( *phoneItAD ).type() ); 398 (*it).setType( ( *phoneItAD ).type() );
374 (*it).setNumber( ( *phoneItAD ).number() ); 399 (*it).setNumber( ( *phoneItAD ).number() );
375 break; 400 break;
376 } 401 }
377 } 402 }
378 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
379 if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) ) 404 if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) )
380 mData->phoneNumbers.append( *phoneItAD ); 405 mData->phoneNumbers.append( *phoneItAD );
381 } 406 }
382 } 407 }
383 } 408 }
384 if ( isSubSet ) { 409 if ( isSubSet ) {
385 // ************* emails; 410 // ************* emails;
386 t = mData->emails; 411 t = mData->emails;
387 tAD = ad.mData->emails; 412 tAD = ad.mData->emails;
388 for ( iii = 0; iii < tAD.count(); ++iii) 413 for ( iii = 0; iii < tAD.count(); ++iii)
389 if ( !t.contains(tAD[iii] ) ) 414 if ( !t.contains(tAD[iii] ) )
390 mData->emails.append( tAD[iii] ); 415 mData->emails.append( tAD[iii] );
391 } 416 }
392 417
393 // ************* categories; 418 // ************* categories;
394 if ( isSubSet ) { 419 if ( isSubSet ) {
395 t = mData->categories; 420 t = mData->categories;
396 tAD = ad.mData->categories; 421 tAD = ad.mData->categories;
397 for ( iii = 0; iii < tAD.count(); ++iii) 422 for ( iii = 0; iii < tAD.count(); ++iii)
398 if ( !t.contains(tAD[iii] ) ) 423 if ( !t.contains(tAD[iii] ) )
399 mData->categories.append( tAD[iii] ); 424 mData->categories.append( tAD[iii] );
400 } 425 }
401 QStringList::ConstIterator it; 426 QStringList::ConstIterator it;
402 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 ) {
403 QString qualifiedName = (*it).left( (*it).find( ":" )); 428 QString qualifiedName = (*it).left( (*it).find( ":" ));
404 bool found = false; 429 bool found = false;
405 QStringList::ConstIterator itL; 430 QStringList::ConstIterator itL;
406 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 431 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
407 if ( (*itL).startsWith( qualifiedName ) ) { 432 if ( (*itL).startsWith( qualifiedName ) ) {
408 found = true; 433 found = true;
409 break; 434 break;
410 } 435 }
411 } 436 }
412 if ( ! found ) { 437 if ( ! found ) {
413 mData->custom.append( *it ); 438 mData->custom.append( *it );
414 } 439 }
415 } 440 }
416 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;
417 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;
418 if ( !mData->sound.isIntern() ) { 443 if ( !mData->sound.isIntern() ) {
419 if ( mData->sound.url().isEmpty() ) { 444 if ( mData->sound.url().isEmpty() ) {
420 mData->sound = ad.mData->sound; 445 mData->sound = ad.mData->sound;
421 } 446 }
422 } 447 }
423 if ( !mData->agent.isIntern() ) { 448 if ( !mData->agent.isIntern() ) {
424 if ( mData->agent.url().isEmpty() ) { 449 if ( mData->agent.url().isEmpty() ) {
425 mData->agent = ad.mData->agent; 450 mData->agent = ad.mData->agent;
426 } 451 }
427 } 452 }
428 { 453 {
429 Key::List::Iterator itA; 454 Key::List::Iterator itA;
430 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 ) {
431 bool found = false; 456 bool found = false;
432 Key::List::Iterator it; 457 Key::List::Iterator it;
433 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 458 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
434 if ( (*it) == (*itA)) { 459 if ( (*it) == (*itA)) {
435 found = true; 460 found = true;
436 break; 461 break;
437 462
438 } 463 }
439 } 464 }
440 if ( ! found ) { 465 if ( ! found ) {
441 mData->keys.append( *itA ); 466 mData->keys.append( *itA );
442 } 467 }
443 } 468 }
444 } 469 }
445 if ( isSubSet ) { 470 if ( isSubSet ) {
446 KABC::Address::List::Iterator addressIterA; 471 KABC::Address::List::Iterator addressIterA;
447 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 ) {
448 bool found = false; 473 bool found = false;
449 KABC::Address::List::Iterator addressIter; 474 KABC::Address::List::Iterator addressIter;
450 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 475 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
451 ++addressIter ) { 476 ++addressIter ) {
452 if ( (*addressIter) == (*addressIterA)) { 477 if ( (*addressIter) == (*addressIterA)) {
453 found = true; 478 found = true;
454 (*addressIter).setType( (*addressIterA).type() ); 479 (*addressIter).setType( (*addressIterA).type() );
455 break; 480 break;
456 } 481 }
457 482
458 } 483 }
459 if ( isSubSet && ! found ) { 484 if ( isSubSet && ! found ) {
460 mData->addresses.append( *addressIterA ); 485 mData->addresses.append( *addressIterA );
461 } 486 }
462 } 487 }
463 } 488 }
464 //qDebug("merge contact %s ", ad.uid().latin1()); 489 //qDebug("merge contact %s ", ad.uid().latin1());
465 setUid( ad.uid() ); 490 setUid( ad.uid() );
466 setRevision( ad.revision() ); 491 setRevision( ad.revision() );
467} 492}
468 493
469bool Addressee::removeVoice() 494bool Addressee::removeVoice()
470{ 495{
471 PhoneNumber::List phoneN = phoneNumbers(); 496 PhoneNumber::List phoneN = phoneNumbers();
472 PhoneNumber::List::Iterator phoneIt; 497 PhoneNumber::List::Iterator phoneIt;
473 bool found = false; 498 bool found = false;
474 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 499 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
475 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 500 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
476 if ((*phoneIt).type() - PhoneNumber::Voice ) { 501 if ((*phoneIt).type() - PhoneNumber::Voice ) {
477 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 502 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
478 insertPhoneNumber( (*phoneIt) ); 503 insertPhoneNumber( (*phoneIt) );
479 found = true; 504 found = true;
480 } 505 }
481 } 506 }
482 507
483 } 508 }
484 return found; 509 return found;
485} 510}
486 511
487bool Addressee::containsAdr(const Addressee& ad ) 512bool Addressee::containsAdr(const Addressee& ad )
488{ 513{
489 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;
490 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;
491 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 ;
492 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 ;
493 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 ;
494 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 ;
495 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 ;
496 521
497 // compare phone numbers 522 // compare phone numbers
498 PhoneNumber::List phoneN = ad.phoneNumbers(); 523 PhoneNumber::List phoneN = ad.phoneNumbers();
499 PhoneNumber::List::Iterator phoneIt; 524 PhoneNumber::List::Iterator phoneIt;
500 bool found = false; 525 bool found = false;
501 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 526 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
502 bool found = false; 527 bool found = false;
503 PhoneNumber::List phoneL = ad.phoneNumbers(); 528 PhoneNumber::List phoneL = ad.phoneNumbers();
504 PhoneNumber::List::Iterator phoneItL; 529 PhoneNumber::List::Iterator phoneItL;
505 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 530 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
506 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 531 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
507 found = true; 532 found = true;
508 break; 533 break;
509 } 534 }
510 } 535 }
511 if ( ! found ) 536 if ( ! found )
512 return false; 537 return false;
513 } 538 }
514 return true; 539 return true;
515 540
516} 541}
517void Addressee::simplifyAddresses() 542void Addressee::simplifyAddresses()
518{ 543{
519 544
520 545
521 Address::List list; 546 Address::List list;
522 Address::List::Iterator it; 547 Address::List::Iterator it;
523 Address::List::Iterator it2; 548 Address::List::Iterator it2;
524 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 549 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
525 it2 = it; 550 it2 = it;
526 ++it2; 551 ++it2;
527 for( ; it2 != mData->addresses.end(); ++it2 ) { 552 for( ; it2 != mData->addresses.end(); ++it2 ) {
528 if ( (*it) == (*it2) ) { 553 if ( (*it) == (*it2) ) {
529 list.append( *it ); 554 list.append( *it );
530 break; 555 break;
531 } 556 }
532 } 557 }
533 } 558 }
534 for( it = list.begin(); it != list.end(); ++it ) { 559 for( it = list.begin(); it != list.end(); ++it ) {
535 removeAddress( (*it) ); 560 removeAddress( (*it) );
536 } 561 }
537 562
538 list.clear(); 563 list.clear();
539 int max = 2; 564 int max = 2;
540 if ( mData->url.isValid() ) 565 if ( mData->url.isValid() )
541 max = 1; 566 max = 1;
542 if ( mData->addresses.count() <= max ) return ; 567 if ( mData->addresses.count() <= max ) return ;
543 int count = 0; 568 int count = 0;
544 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 569 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
545 if ( count >= max ) 570 if ( count >= max )
546 list.append( *it ); 571 list.append( *it );
547 ++count; 572 ++count;
548 } 573 }
549 for( it = list.begin(); it != list.end(); ++it ) { 574 for( it = list.begin(); it != list.end(); ++it ) {
550 removeAddress( (*it) ); 575 removeAddress( (*it) );
551 } 576 }
552} 577}
553 578
554// removes all emails but the first 579// removes all emails but the first
555// needed by phone sync 580// needed by phone sync
556void Addressee::simplifyEmails() 581void Addressee::simplifyEmails()
557{ 582{
558 if ( mData->emails.count() == 0 ) return ; 583 if ( mData->emails.count() == 0 ) return ;
559 QString email = mData->emails.first(); 584 QString email = mData->emails.first();
560 detach(); 585 detach();
561 mData->emails.clear(); 586 mData->emails.clear();
562 mData->emails.append( email ); 587 mData->emails.append( email );
563} 588}
564 589
565void Addressee::simplifyPhoneNumbers() 590void Addressee::simplifyPhoneNumbers()
566{ 591{
567 int max = 4; 592 int max = 4;
568 int inList = mData->phoneNumbers.count(); 593 int inList = mData->phoneNumbers.count();
569 KABC::PhoneNumber::List removeNumbers; 594 KABC::PhoneNumber::List removeNumbers;
570 KABC::PhoneNumber::List::Iterator phoneIter; 595 KABC::PhoneNumber::List::Iterator phoneIter;
571 if ( inList > max ) { 596 if ( inList > max ) {
572 // delete non-preferred numbers 597 // delete non-preferred numbers
573 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 598 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
574 ++phoneIter ) { 599 ++phoneIter ) {
575 if ( inList > max ) { 600 if ( inList > max ) {
576 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { 601 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
577 removeNumbers.append( ( *phoneIter ) ); 602 removeNumbers.append( ( *phoneIter ) );
578 --inList; 603 --inList;
579 } 604 }
580 } else 605 } else
581 break; 606 break;
582 } 607 }
583 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 608 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
584 ++phoneIter ) { 609 ++phoneIter ) {
585 removePhoneNumber(( *phoneIter )); 610 removePhoneNumber(( *phoneIter ));
586 } 611 }
587 // delete preferred numbers 612 // delete preferred numbers
588 if ( inList > max ) { 613 if ( inList > max ) {
589 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 614 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
590 ++phoneIter ) { 615 ++phoneIter ) {
591 if ( inList > max ) { 616 if ( inList > max ) {
592 removeNumbers.append( ( *phoneIter ) ); 617 removeNumbers.append( ( *phoneIter ) );
593 --inList; 618 --inList;
594 } else 619 } else
595 break; 620 break;
596 } 621 }
597 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 622 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
598 ++phoneIter ) { 623 ++phoneIter ) {
599 removePhoneNumber(( *phoneIter )); 624 removePhoneNumber(( *phoneIter ));
600 } 625 }
601 } 626 }
602 } 627 }
603 // remove non-numeric characters 628 // remove non-numeric characters
604 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 629 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
605 ++phoneIter ) { 630 ++phoneIter ) {
606 if ( ! ( *phoneIter ).simplifyNumber() ) 631 if ( ! ( *phoneIter ).simplifyNumber() )
607 removeNumbers.append( ( *phoneIter ) ); 632 removeNumbers.append( ( *phoneIter ) );
608 } 633 }
609 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 634 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
610 ++phoneIter ) { 635 ++phoneIter ) {
611 removePhoneNumber(( *phoneIter )); 636 removePhoneNumber(( *phoneIter ));
612 } 637 }
613} 638}
614void Addressee::simplifyPhoneNumberTypes() 639void Addressee::simplifyPhoneNumberTypes()
615{ 640{
616 KABC::PhoneNumber::List::Iterator phoneIter; 641 KABC::PhoneNumber::List::Iterator phoneIter;
617 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 642 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
618 ++phoneIter ) 643 ++phoneIter )
619 ( *phoneIter ).simplifyType(); 644 ( *phoneIter ).simplifyType();
620} 645}
621void Addressee::removeID(const QString &prof) 646void Addressee::removeID(const QString &prof)
622{ 647{
623 detach(); 648 detach();
624 if ( prof.isEmpty() ) 649 if ( prof.isEmpty() )
625 mData->mExternalId = ":"; 650 mData->mExternalId = ":";
626 else 651 else
627 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 652 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
628 653
629} 654}
630void Addressee::setID( const QString & prof , const QString & id ) 655void Addressee::setID( const QString & prof , const QString & id )
631{ 656{
632 detach(); 657 detach();
633 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 658 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
634 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 659 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
635} 660}
636void Addressee::setTempSyncStat( int id ) 661void Addressee::setTempSyncStat( int id )
637{ 662{
638 if ( mData->mTempSyncStat == id ) return; 663 if ( mData->mTempSyncStat == id ) return;
639 detach(); 664 detach();
640 mData->mTempSyncStat = id; 665 mData->mTempSyncStat = id;
641} 666}
642int Addressee::tempSyncStat() const 667int Addressee::tempSyncStat() const
643{ 668{
644 return mData->mTempSyncStat; 669 return mData->mTempSyncStat;
645} 670}
646 671
647const QString Addressee::getID( const QString & prof) const 672const QString Addressee::getID( const QString & prof) const
648{ 673{
649 return KIdManager::getId ( mData->mExternalId, prof ); 674 return KIdManager::getId ( mData->mExternalId, prof );
650} 675}
651 676
652void Addressee::setCsum( const QString & prof , const QString & id ) 677void Addressee::setCsum( const QString & prof , const QString & id )
653{ 678{
654 detach(); 679 detach();
655 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 680 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
656 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 681 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
657 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 682 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
658} 683}
659 684
660const QString Addressee::getCsum( const QString & prof) const 685const QString Addressee::getCsum( const QString & prof) const
661{ 686{
662 return KIdManager::getCsum ( mData->mExternalId, prof ); 687 return KIdManager::getCsum ( mData->mExternalId, prof );
663} 688}
664 689
665void Addressee::setIDStr( const QString & s ) 690void Addressee::setIDStr( const QString & s )
666{ 691{
667 detach(); 692 detach();
668 mData->mExternalId = s; 693 mData->mExternalId = s;
669} 694}
670 695
671const QString Addressee::IDStr() const 696const QString Addressee::IDStr() const
672{ 697{
673 return mData->mExternalId; 698 return mData->mExternalId;
674} 699}
675 700
676void Addressee::setExternalUID( const QString &id ) 701void Addressee::setExternalUID( const QString &id )
677{ 702{
678 if ( id == mData->externalUID ) return; 703 if ( id == mData->externalUID ) return;
679 detach(); 704 detach();
680 mData->empty = false; 705 mData->empty = false;
681 mData->externalUID = id; 706 mData->externalUID = id;
682} 707}
683 708
684const QString Addressee::externalUID() const 709const QString Addressee::externalUID() const
685{ 710{
686 return mData->externalUID; 711 return mData->externalUID;
687} 712}
688void Addressee::setOriginalExternalUID( const QString &id ) 713void Addressee::setOriginalExternalUID( const QString &id )
689{ 714{
690 if ( id == mData->originalExternalUID ) return; 715 if ( id == mData->originalExternalUID ) return;
691 detach(); 716 detach();
692 mData->empty = false; 717 mData->empty = false;
693 //qDebug("*******Set orig uid %s ", id.latin1()); 718 //qDebug("*******Set orig uid %s ", id.latin1());
694 mData->originalExternalUID = id; 719 mData->originalExternalUID = id;
695} 720}
696 721
697QString Addressee::originalExternalUID() const 722QString Addressee::originalExternalUID() const
698{ 723{
699 return mData->originalExternalUID; 724 return mData->originalExternalUID;
700} 725}
701 726
702void Addressee::setUid( const QString &id ) 727void Addressee::setUid( const QString &id )
703{ 728{
704 if ( id == mData->uid ) return; 729 if ( id == mData->uid ) return;
705 detach(); 730 detach();
706 //qDebug("****setuid %s ", id.latin1()); 731 //qDebug("****setuid %s ", id.latin1());
707 mData->empty = false; 732 mData->empty = false;
708 mData->uid = id; 733 mData->uid = id;
709} 734}
710 735
711const QString Addressee::uid() const 736const QString Addressee::uid() const
712{ 737{
713 if ( mData->uid.isEmpty() ) 738 if ( mData->uid.isEmpty() )
714 mData->uid = KApplication::randomString( 10 ); 739 mData->uid = KApplication::randomString( 10 );
715 740
716 return mData->uid; 741 return mData->uid;
717} 742}
718 743
719QString Addressee::uidLabel() 744QString Addressee::uidLabel()
720{ 745{
721 return i18n("Unique Identifier"); 746 return i18n("Unique Identifier");
722} 747}
723 748
724void Addressee::setName( const QString &name ) 749void Addressee::setName( const QString &name )
725{ 750{
726 if ( name == mData->name ) return; 751 if ( name == mData->name ) return;
727 detach(); 752 detach();
728 mData->empty = false; 753 mData->empty = false;
729 mData->name = name; 754 mData->name = name;
730} 755}
731 756
732QString Addressee::name() const 757QString Addressee::name() const
733{ 758{
734 return mData->name; 759 return mData->name;
735} 760}
736 761
737QString Addressee::nameLabel() 762QString Addressee::nameLabel()
738{ 763{
739 return i18n("Name"); 764 return i18n("Name");
740} 765}
741 766
742 767
743void Addressee::setFormattedName( const QString &formattedName ) 768void Addressee::setFormattedName( const QString &formattedName )
744{ 769{
745 if ( formattedName == mData->formattedName ) return; 770 if ( formattedName == mData->formattedName ) return;
746 detach(); 771 detach();
747 mData->empty = false; 772 mData->empty = false;
748 mData->formattedName = formattedName; 773 mData->formattedName = formattedName;
749} 774}
750 775
751QString Addressee::formattedName() const 776QString Addressee::formattedName() const
752{ 777{
753 return mData->formattedName; 778 return mData->formattedName;
754} 779}
755 780
756QString Addressee::formattedNameLabel() 781QString Addressee::formattedNameLabel()
757{ 782{
758 return i18n("Formatted Name"); 783 return i18n("Formatted Name");
759} 784}
760 785
761 786
762void Addressee::setFamilyName( const QString &familyName ) 787void Addressee::setFamilyName( const QString &familyName )
763{ 788{
764 if ( familyName == mData->familyName ) return; 789 if ( familyName == mData->familyName ) return;
765 detach(); 790 detach();
766 mData->empty = false; 791 mData->empty = false;
767 mData->familyName = familyName; 792 mData->familyName = familyName;
768} 793}
769 794
770QString Addressee::familyName() const 795QString Addressee::familyName() const
771{ 796{
772 return mData->familyName; 797 return mData->familyName;
773} 798}
774 799
775QString Addressee::familyNameLabel() 800QString Addressee::familyNameLabel()
776{ 801{
777 return i18n("Family Name"); 802 return i18n("Family Name");
778} 803}
779 804
780 805
781void Addressee::setGivenName( const QString &givenName ) 806void Addressee::setGivenName( const QString &givenName )
782{ 807{
783 if ( givenName == mData->givenName ) return; 808 if ( givenName == mData->givenName ) return;
784 detach(); 809 detach();
785 mData->empty = false; 810 mData->empty = false;
786 mData->givenName = givenName; 811 mData->givenName = givenName;
787} 812}
788 813
789QString Addressee::givenName() const 814QString Addressee::givenName() const
790{ 815{
791 return mData->givenName; 816 return mData->givenName;
792} 817}
793 818
794QString Addressee::givenNameLabel() 819QString Addressee::givenNameLabel()
795{ 820{
796 return i18n("Given Name"); 821 return i18n("Given Name");
797} 822}
798 823
799 824
800void Addressee::setAdditionalName( const QString &additionalName ) 825void Addressee::setAdditionalName( const QString &additionalName )
801{ 826{
802 if ( additionalName == mData->additionalName ) return; 827 if ( additionalName == mData->additionalName ) return;
803 detach(); 828 detach();
804 mData->empty = false; 829 mData->empty = false;
805 mData->additionalName = additionalName; 830 mData->additionalName = additionalName;
806} 831}
807 832
808QString Addressee::additionalName() const 833QString Addressee::additionalName() const
809{ 834{
810 return mData->additionalName; 835 return mData->additionalName;
811} 836}
812 837
813QString Addressee::additionalNameLabel() 838QString Addressee::additionalNameLabel()
814{ 839{
815 return i18n("Additional Names"); 840 return i18n("Additional Names");
816} 841}
817 842
818 843
819void Addressee::setPrefix( const QString &prefix ) 844void Addressee::setPrefix( const QString &prefix )
820{ 845{
821 if ( prefix == mData->prefix ) return; 846 if ( prefix == mData->prefix ) return;
822 detach(); 847 detach();
823 mData->empty = false; 848 mData->empty = false;
824 mData->prefix = prefix; 849 mData->prefix = prefix;
825} 850}
826 851
827QString Addressee::prefix() const 852QString Addressee::prefix() const
828{ 853{
829 return mData->prefix; 854 return mData->prefix;
830} 855}
831 856
832QString Addressee::prefixLabel() 857QString Addressee::prefixLabel()
833{ 858{
834 return i18n("Honorific Prefixes"); 859 return i18n("Honorific Prefixes");
835} 860}
836 861
837 862
838void Addressee::setSuffix( const QString &suffix ) 863void Addressee::setSuffix( const QString &suffix )
839{ 864{
840 if ( suffix == mData->suffix ) return; 865 if ( suffix == mData->suffix ) return;
841 detach(); 866 detach();
842 mData->empty = false; 867 mData->empty = false;
843 mData->suffix = suffix; 868 mData->suffix = suffix;
844} 869}
845 870
846QString Addressee::suffix() const 871QString Addressee::suffix() const
847{ 872{
848 return mData->suffix; 873 return mData->suffix;
849} 874}
850 875
851QString Addressee::suffixLabel() 876QString Addressee::suffixLabel()
852{ 877{
853 return i18n("Honorific Suffixes"); 878 return i18n("Honorific Suffixes");
854} 879}
855 880
856 881
857void Addressee::setNickName( const QString &nickName ) 882void Addressee::setNickName( const QString &nickName )
858{ 883{
859 if ( nickName == mData->nickName ) return; 884 if ( nickName == mData->nickName ) return;
860 detach(); 885 detach();
861 mData->empty = false; 886 mData->empty = false;
862 mData->nickName = nickName; 887 mData->nickName = nickName;
863} 888}
864 889
865QString Addressee::nickName() const 890QString Addressee::nickName() const
866{ 891{
867 return mData->nickName; 892 return mData->nickName;
868} 893}
869 894
870QString Addressee::nickNameLabel() 895QString Addressee::nickNameLabel()
871{ 896{
872 return i18n("Nick Name"); 897 return i18n("Nick Name");
873} 898}
874 899
875 900
876void Addressee::setBirthday( const QDateTime &birthday ) 901void Addressee::setBirthday( const QDateTime &birthday )
877{ 902{
878 if ( birthday == mData->birthday ) return; 903 if ( birthday == mData->birthday ) return;
879 detach(); 904 detach();
880 mData->empty = false; 905 mData->empty = false;
881 mData->birthday = birthday; 906 mData->birthday = birthday;
882} 907}
883 908
884QDateTime Addressee::birthday() const 909QDateTime Addressee::birthday() const
885{ 910{
886 return mData->birthday; 911 return mData->birthday;
887} 912}
888 913
889QString Addressee::birthdayLabel() 914QString Addressee::birthdayLabel()
890{ 915{
891 return i18n("Birthday"); 916 return i18n("Birthday");
892} 917}
893 918
894 919
895QString Addressee::homeAddressStreetLabel() 920QString Addressee::homeAddressStreetLabel()
896{ 921{
897 return i18n("Home Address Street"); 922 return i18n("Home Address Street");
898} 923}
899 924
900 925
901QString Addressee::homeAddressLocalityLabel() 926QString Addressee::homeAddressLocalityLabel()
902{ 927{
903 return i18n("Home Address Locality"); 928 return i18n("Home Address Locality");
904} 929}
905 930
906 931
907QString Addressee::homeAddressRegionLabel() 932QString Addressee::homeAddressRegionLabel()
908{ 933{
909 return i18n("Home Address Region"); 934 return i18n("Home Address Region");
910} 935}
911 936
912 937
913QString Addressee::homeAddressPostalCodeLabel() 938QString Addressee::homeAddressPostalCodeLabel()
914{ 939{
915 return i18n("Home Address Postal Code"); 940 return i18n("Home Address Postal Code");
916} 941}
917 942
918 943
919QString Addressee::homeAddressCountryLabel() 944QString Addressee::homeAddressCountryLabel()
920{ 945{
921 return i18n("Home Address Country"); 946 return i18n("Home Address Country");
922} 947}
923 948
924 949
925QString Addressee::homeAddressLabelLabel() 950QString Addressee::homeAddressLabelLabel()
926{ 951{
927 return i18n("Home Address Label"); 952 return i18n("Home Address Label");
928} 953}
929 954
930 955
931QString Addressee::businessAddressStreetLabel() 956QString Addressee::businessAddressStreetLabel()
932{ 957{
933 return i18n("Business Address Street"); 958 return i18n("Business Address Street");
934} 959}
935 960
936 961
937QString Addressee::businessAddressLocalityLabel() 962QString Addressee::businessAddressLocalityLabel()
938{ 963{
939 return i18n("Business Address Locality"); 964 return i18n("Business Address Locality");
940} 965}
941 966
942 967
943QString Addressee::businessAddressRegionLabel() 968QString Addressee::businessAddressRegionLabel()
944{ 969{
945 return i18n("Business Address Region"); 970 return i18n("Business Address Region");
946} 971}
947 972
948 973
949QString Addressee::businessAddressPostalCodeLabel() 974QString Addressee::businessAddressPostalCodeLabel()
950{ 975{
951 return i18n("Business Address Postal Code"); 976 return i18n("Business Address Postal Code");
952} 977}
953 978
954 979
955QString Addressee::businessAddressCountryLabel() 980QString Addressee::businessAddressCountryLabel()
956{ 981{
957 return i18n("Business Address Country"); 982 return i18n("Business Address Country");
958} 983}
959 984
960 985
961QString Addressee::businessAddressLabelLabel() 986QString Addressee::businessAddressLabelLabel()
962{ 987{
963 return i18n("Business Address Label"); 988 return i18n("Business Address Label");
964} 989}
965 990
966 991
967QString Addressee::homePhoneLabel() 992QString Addressee::homePhoneLabel()
968{ 993{
969 return i18n("Home Phone"); 994 return i18n("Home Phone");
970} 995}
971 996
972 997
973QString Addressee::businessPhoneLabel() 998QString Addressee::businessPhoneLabel()
974{ 999{
975 return i18n("Business Phone"); 1000 return i18n("Business Phone");
976} 1001}
977 1002
978 1003
979QString Addressee::mobilePhoneLabel() 1004QString Addressee::mobilePhoneLabel()
980{ 1005{
981 return i18n("Mobile Phone"); 1006 return i18n("Mobile Phone");
982} 1007}
983QString Addressee::mobileWorkPhoneLabel() 1008QString Addressee::mobileWorkPhoneLabel()
984{ 1009{
985 return i18n("Mobile (work)"); 1010 return i18n("Mobile (work)");
986} 1011}
987QString Addressee::mobileHomePhoneLabel() 1012QString Addressee::mobileHomePhoneLabel()
988{ 1013{
989 return i18n("Mobile (home)"); 1014 return i18n("Mobile (home)");
990} 1015}
991 1016
992 1017
993QString Addressee::homeFaxLabel() 1018QString Addressee::homeFaxLabel()
994{ 1019{
995 return i18n("Home Fax"); 1020 return i18n("Home Fax");
996} 1021}
997 1022
998 1023
999QString Addressee::businessFaxLabel() 1024QString Addressee::businessFaxLabel()
1000{ 1025{
1001 return i18n("Business Fax"); 1026 return i18n("Business Fax");
1002} 1027}
1003 1028
1004 1029
1005QString Addressee::carPhoneLabel() 1030QString Addressee::carPhoneLabel()
1006{ 1031{
1007 return i18n("Car Phone"); 1032 return i18n("Car Phone");
1008} 1033}
1009 1034
1010 1035
1011QString Addressee::isdnLabel() 1036QString Addressee::isdnLabel()
1012{ 1037{
1013 return i18n("ISDN"); 1038 return i18n("ISDN");
1014} 1039}
1015 1040
1016 1041
1017QString Addressee::pagerLabel() 1042QString Addressee::pagerLabel()
1018{ 1043{
1019 return i18n("Pager"); 1044 return i18n("Pager");
1020} 1045}
1021 1046
1022QString Addressee::sipLabel() 1047QString Addressee::sipLabel()
1023{ 1048{
1024 return i18n("SIP"); 1049 return i18n("SIP");
1025} 1050}
1026 1051
1027QString Addressee::emailLabel() 1052QString Addressee::emailLabel()
1028{ 1053{
1029 return i18n("Email Address"); 1054 return i18n("Email Address");
1030} 1055}
1031 1056
1032 1057
1033void Addressee::setMailer( const QString &mailer ) 1058void Addressee::setMailer( const QString &mailer )
1034{ 1059{
1035 if ( mailer == mData->mailer ) return; 1060 if ( mailer == mData->mailer ) return;
1036 detach(); 1061 detach();
1037 mData->empty = false; 1062 mData->empty = false;
1038 mData->mailer = mailer; 1063 mData->mailer = mailer;
1039} 1064}
1040 1065
1041QString Addressee::mailer() const 1066QString Addressee::mailer() const
1042{ 1067{
1043 return mData->mailer; 1068 return mData->mailer;
1044} 1069}
1045 1070
1046QString Addressee::mailerLabel() 1071QString Addressee::mailerLabel()
1047{ 1072{
1048 return i18n("Mail Client"); 1073 return i18n("Mail Client");
1049} 1074}
1050 1075
1051 1076
1052void Addressee::setTimeZone( const TimeZone &timeZone ) 1077void Addressee::setTimeZone( const TimeZone &timeZone )
1053{ 1078{
1054 if ( timeZone == mData->timeZone ) return; 1079 if ( timeZone == mData->timeZone ) return;
1055 detach(); 1080 detach();
1056 mData->empty = false; 1081 mData->empty = false;
1057 mData->timeZone = timeZone; 1082 mData->timeZone = timeZone;
1058} 1083}
1059 1084
1060TimeZone Addressee::timeZone() const 1085TimeZone Addressee::timeZone() const
1061{ 1086{
1062 return mData->timeZone; 1087 return mData->timeZone;
1063} 1088}
1064 1089
1065QString Addressee::timeZoneLabel() 1090QString Addressee::timeZoneLabel()
1066{ 1091{
1067 return i18n("Time Zone"); 1092 return i18n("Time Zone");
1068} 1093}
1069 1094
1070 1095
1071void Addressee::setGeo( const Geo &geo ) 1096void Addressee::setGeo( const Geo &geo )
1072{ 1097{
1073 if ( geo == mData->geo ) return; 1098 if ( geo == mData->geo ) return;
1074 detach(); 1099 detach();
1075 mData->empty = false; 1100 mData->empty = false;
1076 mData->geo = geo; 1101 mData->geo = geo;
1077} 1102}
1078 1103
1079Geo Addressee::geo() const 1104Geo Addressee::geo() const
1080{ 1105{
1081 return mData->geo; 1106 return mData->geo;
1082} 1107}
1083 1108
1084QString Addressee::geoLabel() 1109QString Addressee::geoLabel()
1085{ 1110{
1086 return i18n("Geographic Position"); 1111 return i18n("Geographic Position");
1087} 1112}
1088 1113
1089 1114
1090void Addressee::setTitle( const QString &title ) 1115void Addressee::setTitle( const QString &title )
1091{ 1116{
1092 if ( title == mData->title ) return; 1117 if ( title == mData->title ) return;
1093 detach(); 1118 detach();
1094 mData->empty = false; 1119 mData->empty = false;
1095 mData->title = title; 1120 mData->title = title;
1096} 1121}
1097 1122
1098QString Addressee::title() const 1123QString Addressee::title() const
1099{ 1124{
1100 return mData->title; 1125 return mData->title;
1101} 1126}
1102 1127
1103QString Addressee::titleLabel() 1128QString Addressee::titleLabel()
1104{ 1129{
1105 return i18n("Title"); 1130 return i18n("Title");
1106} 1131}
1107 1132
1108 1133
1109void Addressee::setRole( const QString &role ) 1134void Addressee::setRole( const QString &role )
1110{ 1135{
1111 if ( role == mData->role ) return; 1136 if ( role == mData->role ) return;
1112 detach(); 1137 detach();
1113 mData->empty = false; 1138 mData->empty = false;
1114 mData->role = role; 1139 mData->role = role;
1115} 1140}
1116 1141
1117QString Addressee::role() const 1142QString Addressee::role() const
1118{ 1143{
1119 return mData->role; 1144 return mData->role;
1120} 1145}
1121 1146
1122QString Addressee::roleLabel() 1147QString Addressee::roleLabel()
1123{ 1148{
1124 return i18n("Role"); 1149 return i18n("Role");
1125} 1150}
1126 1151
1127 1152
1128void Addressee::setOrganization( const QString &organization ) 1153void Addressee::setOrganization( const QString &organization )
1129{ 1154{
1130 if ( organization == mData->organization ) return; 1155 if ( organization == mData->organization ) return;
1131 detach(); 1156 detach();
1132 mData->empty = false; 1157 mData->empty = false;
1133 mData->organization = organization; 1158 mData->organization = organization;
1134} 1159}
1135 1160
1136QString Addressee::organization() const 1161QString Addressee::organization() const
1137{ 1162{
1138 return mData->organization; 1163 return mData->organization;
1139} 1164}
1140 1165
1141QString Addressee::organizationLabel() 1166QString Addressee::organizationLabel()
1142{ 1167{
1143 return i18n("Organization"); 1168 return i18n("Organization");
1144} 1169}
1145 1170
1146 1171
1147void Addressee::setNote( const QString &note ) 1172void Addressee::setNote( const QString &note )
1148{ 1173{
1149 if ( note == mData->note ) return; 1174 if ( note == mData->note ) return;
1150 detach(); 1175 detach();
1151 mData->empty = false; 1176 mData->empty = false;
1152 mData->note = note; 1177 mData->note = note;
1153} 1178}
1154 1179
1155QString Addressee::note() const 1180QString Addressee::note() const
1156{ 1181{
1157 return mData->note; 1182 return mData->note;
1158} 1183}
1159 1184
1160QString Addressee::noteLabel() 1185QString Addressee::noteLabel()
1161{ 1186{
1162 return i18n("Note"); 1187 return i18n("Note");
1163} 1188}
1164 1189
1165 1190
1166void Addressee::setProductId( const QString &productId ) 1191void Addressee::setProductId( const QString &productId )
1167{ 1192{
1168 if ( productId == mData->productId ) return; 1193 if ( productId == mData->productId ) return;
1169 detach(); 1194 detach();
1170 mData->empty = false; 1195 mData->empty = false;
1171 mData->productId = productId; 1196 mData->productId = productId;
1172} 1197}
1173 1198
1174QString Addressee::productId() const 1199QString Addressee::productId() const
1175{ 1200{
1176 return mData->productId; 1201 return mData->productId;
1177} 1202}
1178 1203
1179QString Addressee::productIdLabel() 1204QString Addressee::productIdLabel()
1180{ 1205{
1181 return i18n("Product Identifier"); 1206 return i18n("Product Identifier");
1182} 1207}
1183 1208
1184 1209
1185void Addressee::setRevision( const QDateTime &revision ) 1210void Addressee::setRevision( const QDateTime &revision )
1186{ 1211{
1187 if ( revision == mData->revision ) return; 1212 if ( revision == mData->revision ) return;
1188 detach(); 1213 detach();
1189 mData->empty = false; 1214 mData->empty = false;
1190 mData->revision = QDateTime( revision.date(), 1215 mData->revision = QDateTime( revision.date(),
1191 QTime (revision.time().hour(), 1216 QTime (revision.time().hour(),
1192 revision.time().minute(), 1217 revision.time().minute(),
1193 revision.time().second())); 1218 revision.time().second()));
1194} 1219}
1195 1220
1196QDateTime Addressee::revision() const 1221QDateTime Addressee::revision() const
1197{ 1222{
1198 return mData->revision; 1223 return mData->revision;
1199} 1224}
1200 1225
1201QString Addressee::revisionLabel() 1226QString Addressee::revisionLabel()
1202{ 1227{
1203 return i18n("Revision Date"); 1228 return i18n("Revision Date");
1204} 1229}
1205 1230
1206 1231
1207void Addressee::setSortString( const QString &sortString ) 1232void Addressee::setSortString( const QString &sortString )
1208{ 1233{
1209 if ( sortString == mData->sortString ) return; 1234 if ( sortString == mData->sortString ) return;
1210 detach(); 1235 detach();
1211 mData->empty = false; 1236 mData->empty = false;
1212 mData->sortString = sortString; 1237 mData->sortString = sortString;
1213} 1238}
1214 1239
1215QString Addressee::sortString() const 1240QString Addressee::sortString() const
1216{ 1241{
1217 return mData->sortString; 1242 return mData->sortString;
1218} 1243}
1219 1244
1220QString Addressee::sortStringLabel() 1245QString Addressee::sortStringLabel()
1221{ 1246{
1222 return i18n("Sort String"); 1247 return i18n("Sort String");
1223} 1248}
1224 1249
1225 1250
1226void Addressee::setUrl( const KURL &url ) 1251void Addressee::setUrl( const KURL &url )
1227{ 1252{
1228 if ( url == mData->url ) return; 1253 if ( url == mData->url ) return;
1229 detach(); 1254 detach();
1230 mData->empty = false; 1255 mData->empty = false;
1231 mData->url = url; 1256 mData->url = url;
1232} 1257}
1233 1258
1234KURL Addressee::url() const 1259KURL Addressee::url() const
1235{ 1260{
1236 return mData->url; 1261 return mData->url;
1237} 1262}
1238 1263
1239QString Addressee::urlLabel() 1264QString Addressee::urlLabel()
1240{ 1265{
1241 return i18n("URL"); 1266 return i18n("URL");
1242} 1267}
1243 1268
1244 1269
1245void Addressee::setSecrecy( const Secrecy &secrecy ) 1270void Addressee::setSecrecy( const Secrecy &secrecy )
1246{ 1271{
1247 if ( secrecy == mData->secrecy ) return; 1272 if ( secrecy == mData->secrecy ) return;
1248 detach(); 1273 detach();
1249 mData->empty = false; 1274 mData->empty = false;
1250 mData->secrecy = secrecy; 1275 mData->secrecy = secrecy;
1251} 1276}
1252 1277
1253Secrecy Addressee::secrecy() const 1278Secrecy Addressee::secrecy() const
1254{ 1279{
1255 return mData->secrecy; 1280 return mData->secrecy;
1256} 1281}
1257 1282
1258QString Addressee::secrecyLabel() 1283QString Addressee::secrecyLabel()
1259{ 1284{
1260 return i18n("Security Class"); 1285 return i18n("Security Class");
1261} 1286}
1262 1287
1263 1288
1264void Addressee::setLogo( const Picture &logo ) 1289void Addressee::setLogo( const Picture &logo )
1265{ 1290{
1266 if ( logo == mData->logo ) return; 1291 if ( logo == mData->logo ) return;
1267 detach(); 1292 detach();
1268 mData->empty = false; 1293 mData->empty = false;
1269 mData->logo = logo; 1294 mData->logo = logo;
1270} 1295}
1271 1296
1272Picture Addressee::logo() const 1297Picture Addressee::logo() const
1273{ 1298{
1274 return mData->logo; 1299 return mData->logo;
1275} 1300}
1276 1301
1277QString Addressee::logoLabel() 1302QString Addressee::logoLabel()
1278{ 1303{
1279 return i18n("Logo"); 1304 return i18n("Logo");
1280} 1305}
1281 1306
1282 1307
1283void Addressee::setPhoto( const Picture &photo ) 1308void Addressee::setPhoto( const Picture &photo )
1284{ 1309{
1285 if ( photo == mData->photo ) return; 1310 if ( photo == mData->photo ) return;
1286 detach(); 1311 detach();
1287 mData->empty = false; 1312 mData->empty = false;
1288 mData->photo = photo; 1313 mData->photo = photo;
1289} 1314}
1290 1315
1291Picture Addressee::photo() const 1316Picture Addressee::photo() const
1292{ 1317{
1293 return mData->photo; 1318 return mData->photo;
1294} 1319}
1295 1320
1296QString Addressee::photoLabel() 1321QString Addressee::photoLabel()
1297{ 1322{
1298 return i18n("Photo"); 1323 return i18n("Photo");
1299} 1324}
1300 1325
1301 1326
1302void Addressee::setSound( const Sound &sound ) 1327void Addressee::setSound( const Sound &sound )
1303{ 1328{
1304 if ( sound == mData->sound ) return; 1329 if ( sound == mData->sound ) return;
1305 detach(); 1330 detach();
1306 mData->empty = false; 1331 mData->empty = false;
1307 mData->sound = sound; 1332 mData->sound = sound;
1308} 1333}
1309 1334
1310Sound Addressee::sound() const 1335Sound Addressee::sound() const
1311{ 1336{
1312 return mData->sound; 1337 return mData->sound;
1313} 1338}
1314 1339
1315QString Addressee::soundLabel() 1340QString Addressee::soundLabel()
1316{ 1341{
1317 return i18n("Sound"); 1342 return i18n("Sound");
1318} 1343}
1319 1344
1320 1345
1321void Addressee::setAgent( const Agent &agent ) 1346void Addressee::setAgent( const Agent &agent )
1322{ 1347{
1323 if ( agent == mData->agent ) return; 1348 if ( agent == mData->agent ) return;
1324 detach(); 1349 detach();
1325 mData->empty = false; 1350 mData->empty = false;
1326 mData->agent = agent; 1351 mData->agent = agent;
1327} 1352}
1328 1353
1329Agent Addressee::agent() const 1354Agent Addressee::agent() const
1330{ 1355{
1331 return mData->agent; 1356 return mData->agent;
1332} 1357}
1333 1358
1334QString Addressee::agentLabel() 1359QString Addressee::agentLabel()
1335{ 1360{
1336 return i18n("Agent"); 1361 return i18n("Agent");
1337} 1362}
1338 1363
1339 1364
1340 1365
1341void Addressee::setNameFromString( const QString &str ) 1366void Addressee::setNameFromString( const QString &str )
1342{ 1367{
1343 setFormattedName( str ); 1368 setFormattedName( str );
1344 setName( str ); 1369 setName( str );
1345 1370
1346 static bool first = true; 1371 static bool first = true;
1347 static QStringList titles; 1372 static QStringList titles;
1348 static QStringList suffixes; 1373 static QStringList suffixes;
1349 static QStringList prefixes; 1374 static QStringList prefixes;
1350 1375
1351 if ( first ) { 1376 if ( first ) {
1352 first = false; 1377 first = false;
1353 titles += i18n( "Dr." ); 1378 titles += i18n( "Dr." );
1354 titles += i18n( "Miss" ); 1379 titles += i18n( "Miss" );
1355 titles += i18n( "Mr." ); 1380 titles += i18n( "Mr." );
1356 titles += i18n( "Mrs." ); 1381 titles += i18n( "Mrs." );
1357 titles += i18n( "Ms." ); 1382 titles += i18n( "Ms." );
1358 titles += i18n( "Prof." ); 1383 titles += i18n( "Prof." );
1359 1384
1360 suffixes += i18n( "I" ); 1385 suffixes += i18n( "I" );
1361 suffixes += i18n( "II" ); 1386 suffixes += i18n( "II" );
1362 suffixes += i18n( "III" ); 1387 suffixes += i18n( "III" );
1363 suffixes += i18n( "Jr." ); 1388 suffixes += i18n( "Jr." );
1364 suffixes += i18n( "Sr." ); 1389 suffixes += i18n( "Sr." );
1365 1390
1366 prefixes += "van"; 1391 prefixes += "van";
1367 prefixes += "von"; 1392 prefixes += "von";
1368 prefixes += "de"; 1393 prefixes += "de";
1369 1394
1370 KConfig config( locateLocal( "config", "kabcrc") ); 1395 KConfig config( locateLocal( "config", "kabcrc") );
1371 config.setGroup( "General" ); 1396 config.setGroup( "General" );
1372 titles += config.readListEntry( "Prefixes" ); 1397 titles += config.readListEntry( "Prefixes" );
1373 titles.remove( "" ); 1398 titles.remove( "" );
1374 prefixes += config.readListEntry( "Inclusions" ); 1399 prefixes += config.readListEntry( "Inclusions" );
1375 prefixes.remove( "" ); 1400 prefixes.remove( "" );
1376 suffixes += config.readListEntry( "Suffixes" ); 1401 suffixes += config.readListEntry( "Suffixes" );
1377 suffixes.remove( "" ); 1402 suffixes.remove( "" );
1378 } 1403 }
1379 1404
1380 // clear all name parts 1405 // clear all name parts
1381 setPrefix( "" ); 1406 setPrefix( "" );
1382 setGivenName( "" ); 1407 setGivenName( "" );
1383 setAdditionalName( "" ); 1408 setAdditionalName( "" );
1384 setFamilyName( "" ); 1409 setFamilyName( "" );
1385 setSuffix( "" ); 1410 setSuffix( "" );
1386 1411
1387 if ( str.isEmpty() ) 1412 if ( str.isEmpty() )
1388 return; 1413 return;
1389 1414
1390 int i = str.find(','); 1415 int i = str.find(',');
1391 if( i < 0 ) { 1416 if( i < 0 ) {
1392 QStringList parts = QStringList::split( " ", str ); 1417 QStringList parts = QStringList::split( " ", str );
1393 int leftOffset = 0; 1418 int leftOffset = 0;
1394 int rightOffset = parts.count() - 1; 1419 int rightOffset = parts.count() - 1;
1395 1420
1396 QString suffix; 1421 QString suffix;
1397 while ( rightOffset >= 0 ) { 1422 while ( rightOffset >= 0 ) {
1398 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1423 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1399 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1424 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1400 rightOffset--; 1425 rightOffset--;
1401 } else 1426 } else
1402 break; 1427 break;
1403 } 1428 }
1404 setSuffix( suffix ); 1429 setSuffix( suffix );
1405 1430
1406 if ( rightOffset < 0 ) 1431 if ( rightOffset < 0 )
1407 return; 1432 return;
1408 1433
1409 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1434 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1410 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1435 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1411 rightOffset--; 1436 rightOffset--;
1412 } else 1437 } else
1413 setFamilyName( parts[ rightOffset ] ); 1438 setFamilyName( parts[ rightOffset ] );
1414 1439
1415 QString prefix; 1440 QString prefix;
1416 while ( leftOffset < rightOffset ) { 1441 while ( leftOffset < rightOffset ) {
1417 if ( titles.contains( parts[ leftOffset ] ) ) { 1442 if ( titles.contains( parts[ leftOffset ] ) ) {
1418 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1443 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1419 leftOffset++; 1444 leftOffset++;
1420 } else 1445 } else
1421 break; 1446 break;
1422 } 1447 }
1423 setPrefix( prefix ); 1448 setPrefix( prefix );
1424 1449
1425 if ( leftOffset < rightOffset ) { 1450 if ( leftOffset < rightOffset ) {
1426 setGivenName( parts[ leftOffset ] ); 1451 setGivenName( parts[ leftOffset ] );
1427 leftOffset++; 1452 leftOffset++;
1428 } 1453 }
1429 1454
1430 QString additionalName; 1455 QString additionalName;
1431 while ( leftOffset < rightOffset ) { 1456 while ( leftOffset < rightOffset ) {
1432 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1457 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1433 leftOffset++; 1458 leftOffset++;
1434 } 1459 }
1435 setAdditionalName( additionalName ); 1460 setAdditionalName( additionalName );
1436 } else { 1461 } else {
1437 QString part1 = str.left( i ); 1462 QString part1 = str.left( i );
1438 QString part2 = str.mid( i + 1 ); 1463 QString part2 = str.mid( i + 1 );
1439 1464
1440 QStringList parts = QStringList::split( " ", part1 ); 1465 QStringList parts = QStringList::split( " ", part1 );
1441 int leftOffset = 0; 1466 int leftOffset = 0;
1442 int rightOffset = parts.count() - 1; 1467 int rightOffset = parts.count() - 1;
1443 1468
1444 QString suffix; 1469 QString suffix;
1445 while ( rightOffset >= 0 ) { 1470 while ( rightOffset >= 0 ) {
1446 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1471 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1447 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1472 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1448 rightOffset--; 1473 rightOffset--;
1449 } else 1474 } else
1450 break; 1475 break;
1451 } 1476 }
1452 setSuffix( suffix ); 1477 setSuffix( suffix );
1453 1478
1454 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1479 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1455 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1480 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1456 rightOffset--; 1481 rightOffset--;
1457 } else 1482 } else
1458 setFamilyName( parts[ rightOffset ] ); 1483 setFamilyName( parts[ rightOffset ] );
1459 1484
1460 QString prefix; 1485 QString prefix;
1461 while ( leftOffset < rightOffset ) { 1486 while ( leftOffset < rightOffset ) {
1462 if ( titles.contains( parts[ leftOffset ] ) ) { 1487 if ( titles.contains( parts[ leftOffset ] ) ) {
1463 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1488 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1464 leftOffset++; 1489 leftOffset++;
1465 } else 1490 } else
1466 break; 1491 break;
1467 } 1492 }
1468 1493
1469 parts = QStringList::split( " ", part2 ); 1494 parts = QStringList::split( " ", part2 );
1470 1495
1471 leftOffset = 0; 1496 leftOffset = 0;
1472 rightOffset = parts.count(); 1497 rightOffset = parts.count();
1473 1498
1474 while ( leftOffset < rightOffset ) { 1499 while ( leftOffset < rightOffset ) {
1475 if ( titles.contains( parts[ leftOffset ] ) ) { 1500 if ( titles.contains( parts[ leftOffset ] ) ) {
1476 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1501 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1477 leftOffset++; 1502 leftOffset++;
1478 } else 1503 } else
1479 break; 1504 break;
1480 } 1505 }
1481 setPrefix( prefix ); 1506 setPrefix( prefix );
1482 1507
1483 if ( leftOffset < rightOffset ) { 1508 if ( leftOffset < rightOffset ) {
1484 setGivenName( parts[ leftOffset ] ); 1509 setGivenName( parts[ leftOffset ] );
1485 leftOffset++; 1510 leftOffset++;
1486 } 1511 }
1487 1512
1488 QString additionalName; 1513 QString additionalName;
1489 while ( leftOffset < rightOffset ) { 1514 while ( leftOffset < rightOffset ) {
1490 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1515 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1491 leftOffset++; 1516 leftOffset++;
1492 } 1517 }
1493 setAdditionalName( additionalName ); 1518 setAdditionalName( additionalName );
1494 } 1519 }
1495} 1520}
1496 1521
1497QString Addressee::realName() const 1522QString Addressee::realName() const
1498{ 1523{
1499 if ( !formattedName().isEmpty() ) 1524 if ( !formattedName().isEmpty() )
1500 return formattedName(); 1525 return formattedName();
1501 1526
1502 QString n = assembledName(); 1527 QString n = assembledName();
1503 1528
1504 if ( n.isEmpty() ) 1529 if ( n.isEmpty() )
1505 n = name(); 1530 n = name();
1506 if ( n.isEmpty() ) 1531 if ( n.isEmpty() )
1507 n = organization(); 1532 n = organization();
1508 return n; 1533 return n;
1509} 1534}
1510 1535
1511QString Addressee::assembledName() const 1536QString Addressee::assembledName() const
1512{ 1537{
1513 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1538 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1514 familyName() + " " + suffix(); 1539 familyName() + " " + suffix();
1515 1540
1516 return name.simplifyWhiteSpace(); 1541 return name.simplifyWhiteSpace();
1517} 1542}
1518 1543
1519QString Addressee::fullEmail( const QString &email ) const 1544QString Addressee::fullEmail( const QString &email ) const
1520{ 1545{
1521 QString e; 1546 QString e;
1522 if ( email.isNull() ) { 1547 if ( email.isNull() ) {
1523 e = preferredEmail(); 1548 e = preferredEmail();
1524 } else { 1549 } else {
1525 e = email; 1550 e = email;
1526 } 1551 }
1527 if ( e.isEmpty() ) return QString::null; 1552 if ( e.isEmpty() ) return QString::null;
1528 1553
1529 QString text; 1554 QString text;
1530 if ( realName().isEmpty() ) 1555 if ( realName().isEmpty() )
1531 text = e; 1556 text = e;
1532 else 1557 else
1533 text = assembledName() + " <" + e + ">"; 1558 text = assembledName() + " <" + e + ">";
1534 1559
1535 return text; 1560 return text;
1536} 1561}
1537 1562
1538void Addressee::insertEmail( const QString &email, bool preferred ) 1563void Addressee::insertEmail( const QString &email, bool preferred )
1539{ 1564{
1540 detach(); 1565 detach();
1541 1566
1542 QStringList::Iterator it = mData->emails.find( email ); 1567 QStringList::Iterator it = mData->emails.find( email );
1543 1568
1544 if ( it != mData->emails.end() ) { 1569 if ( it != mData->emails.end() ) {
1545 if ( !preferred || it == mData->emails.begin() ) return; 1570 if ( !preferred || it == mData->emails.begin() ) return;
1546 mData->emails.remove( it ); 1571 mData->emails.remove( it );
1547 mData->emails.prepend( email ); 1572 mData->emails.prepend( email );
1548 } else { 1573 } else {
1549 if ( preferred ) { 1574 if ( preferred ) {
1550 mData->emails.prepend( email ); 1575 mData->emails.prepend( email );
1551 } else { 1576 } else {
1552 mData->emails.append( email ); 1577 mData->emails.append( email );
1553 } 1578 }
1554 } 1579 }
1555} 1580}
1556 1581
1557void Addressee::removeEmail( const QString &email ) 1582void Addressee::removeEmail( const QString &email )
1558{ 1583{
1559 detach(); 1584 detach();
1560 1585
1561 QStringList::Iterator it = mData->emails.find( email ); 1586 QStringList::Iterator it = mData->emails.find( email );
1562 if ( it == mData->emails.end() ) return; 1587 if ( it == mData->emails.end() ) return;
1563 1588
1564 mData->emails.remove( it ); 1589 mData->emails.remove( it );
1565} 1590}
1566 1591
1567QString Addressee::preferredEmail() const 1592QString Addressee::preferredEmail() const
1568{ 1593{
1569 if ( mData->emails.count() == 0 ) return QString::null; 1594 if ( mData->emails.count() == 0 ) return QString::null;
1570 else return mData->emails.first(); 1595 else return mData->emails.first();
1571} 1596}
1572 1597
1573QStringList Addressee::emails() const 1598QStringList Addressee::emails() const
1574{ 1599{
1575 return mData->emails; 1600 return mData->emails;
1576} 1601}
1577void Addressee::setEmails( const QStringList& emails ) { 1602void Addressee::setEmails( const QStringList& emails ) {
1578 detach(); 1603 detach();
1579 mData->emails = emails; 1604 mData->emails = emails;
1580} 1605}
1581void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1606void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1582{ 1607{
1583 detach(); 1608 detach();
1584 mData->empty = false; 1609 mData->empty = false;
1585 1610
1586 PhoneNumber::List::Iterator it; 1611 PhoneNumber::List::Iterator it;
1587 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1612 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1588 if ( (*it).id() == phoneNumber.id() ) { 1613 if ( (*it).id() == phoneNumber.id() ) {
1589 *it = phoneNumber; 1614 *it = phoneNumber;
1590 return; 1615 return;
1591 } 1616 }
1592 } 1617 }
1593 mData->phoneNumbers.append( phoneNumber ); 1618 mData->phoneNumbers.append( phoneNumber );
1594} 1619}
1595 1620
1596void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1621void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1597{ 1622{
1598 detach(); 1623 detach();
1599 1624
1600 PhoneNumber::List::Iterator it; 1625 PhoneNumber::List::Iterator it;
1601 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1626 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1602 if ( (*it).id() == phoneNumber.id() ) { 1627 if ( (*it).id() == phoneNumber.id() ) {
1603 mData->phoneNumbers.remove( it ); 1628 mData->phoneNumbers.remove( it );
1604 return; 1629 return;
1605 } 1630 }
1606 } 1631 }
1607} 1632}
1608 1633
1609PhoneNumber Addressee::phoneNumber( int type ) const 1634PhoneNumber Addressee::phoneNumber( int type ) const
1610{ 1635{
1611 PhoneNumber phoneNumber( "", type ); 1636 PhoneNumber phoneNumber( "", type );
1612 PhoneNumber::List::ConstIterator it; 1637 PhoneNumber::List::ConstIterator it;
1613 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1638 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1614 if ( matchBinaryPatternP( (*it).type(), type ) ) { 1639 if ( matchBinaryPatternP( (*it).type(), type ) ) {
1615 if ( (*it).type() & PhoneNumber::Pref ) 1640 if ( (*it).type() & PhoneNumber::Pref )
1616 return (*it); 1641 return (*it);
1617 else if ( phoneNumber.number().isEmpty() ) 1642 else if ( phoneNumber.number().isEmpty() )
1618 phoneNumber = (*it); 1643 phoneNumber = (*it);
1619 } 1644 }
1620 } 1645 }
1621 1646
1622 return phoneNumber; 1647 return phoneNumber;
1623} 1648}
1624 1649
1625PhoneNumber::List Addressee::phoneNumbers() const 1650PhoneNumber::List Addressee::phoneNumbers() const
1626{ 1651{
1627 return mData->phoneNumbers; 1652 return mData->phoneNumbers;
1628} 1653}
1629 1654
1630PhoneNumber::List Addressee::phoneNumbers( int type ) const 1655PhoneNumber::List Addressee::phoneNumbers( int type ) const
1631{ 1656{
1632 PhoneNumber::List list; 1657 PhoneNumber::List list;
1633 1658
1634 PhoneNumber::List::ConstIterator it; 1659 PhoneNumber::List::ConstIterator it;
1635 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1660 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1636 if ( matchBinaryPattern( (*it).type(), type ) ) { 1661 if ( matchBinaryPattern( (*it).type(), type ) ) {
1637 list.append( *it ); 1662 list.append( *it );
1638 } 1663 }
1639 } 1664 }
1640 return list; 1665 return list;
1641} 1666}
1642 1667
1643PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1668PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1644{ 1669{
1645 PhoneNumber::List::ConstIterator it; 1670 PhoneNumber::List::ConstIterator it;
1646 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1671 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1647 if ( (*it).id() == id ) { 1672 if ( (*it).id() == id ) {
1648 return *it; 1673 return *it;
1649 } 1674 }
1650 } 1675 }
1651 return PhoneNumber(); 1676 return PhoneNumber();
1652} 1677}
1653 1678
1654void Addressee::insertKey( const Key &key ) 1679void Addressee::insertKey( const Key &key )
1655{ 1680{
1656 detach(); 1681 detach();
1657 mData->empty = false; 1682 mData->empty = false;
1658 1683
1659 Key::List::Iterator it; 1684 Key::List::Iterator it;
1660 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1685 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1661 if ( (*it).id() == key.id() ) { 1686 if ( (*it).id() == key.id() ) {
1662 *it = key; 1687 *it = key;
1663 return; 1688 return;
1664 } 1689 }
1665 } 1690 }
1666 mData->keys.append( key ); 1691 mData->keys.append( key );
1667} 1692}
1668 1693
1669void Addressee::removeKey( const Key &key ) 1694void Addressee::removeKey( const Key &key )
1670{ 1695{
1671 detach(); 1696 detach();
1672 1697
1673 Key::List::Iterator it; 1698 Key::List::Iterator it;
1674 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1699 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1675 if ( (*it).id() == key.id() ) { 1700 if ( (*it).id() == key.id() ) {
1676 mData->keys.remove( key ); 1701 mData->keys.remove( key );
1677 return; 1702 return;
1678 } 1703 }
1679 } 1704 }
1680} 1705}
1681 1706
1682Key Addressee::key( int type, QString customTypeString ) const 1707Key Addressee::key( int type, QString customTypeString ) const
1683{ 1708{
1684 Key::List::ConstIterator it; 1709 Key::List::ConstIterator it;
1685 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1710 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1686 if ( (*it).type() == type ) { 1711 if ( (*it).type() == type ) {
1687 if ( type == Key::Custom ) { 1712 if ( type == Key::Custom ) {
1688 if ( customTypeString.isEmpty() ) { 1713 if ( customTypeString.isEmpty() ) {
1689 return *it; 1714 return *it;
1690 } else { 1715 } else {
1691 if ( (*it).customTypeString() == customTypeString ) 1716 if ( (*it).customTypeString() == customTypeString )
1692 return (*it); 1717 return (*it);
1693 } 1718 }
1694 } else { 1719 } else {
1695 return *it; 1720 return *it;
1696 } 1721 }
1697 } 1722 }
1698 } 1723 }
1699 return Key( QString(), type ); 1724 return Key( QString(), type );
1700} 1725}
1701void Addressee::setKeys( const Key::List& list ) { 1726void Addressee::setKeys( const Key::List& list ) {
1702 detach(); 1727 detach();
1703 mData->keys = list; 1728 mData->keys = list;
1704} 1729}
1705 1730
1706Key::List Addressee::keys() const 1731Key::List Addressee::keys() const
1707{ 1732{
1708 return mData->keys; 1733 return mData->keys;
1709} 1734}
1710 1735
1711Key::List Addressee::keys( int type, QString customTypeString ) const 1736Key::List Addressee::keys( int type, QString customTypeString ) const
1712{ 1737{
1713 Key::List list; 1738 Key::List list;
1714 1739
1715 Key::List::ConstIterator it; 1740 Key::List::ConstIterator it;
1716 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1741 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1717 if ( (*it).type() == type ) { 1742 if ( (*it).type() == type ) {
1718 if ( type == Key::Custom ) { 1743 if ( type == Key::Custom ) {
1719 if ( customTypeString.isEmpty() ) { 1744 if ( customTypeString.isEmpty() ) {
1720 list.append(*it); 1745 list.append(*it);
1721 } else { 1746 } else {
1722 if ( (*it).customTypeString() == customTypeString ) 1747 if ( (*it).customTypeString() == customTypeString )
1723 list.append(*it); 1748 list.append(*it);
1724 } 1749 }
1725 } else { 1750 } else {
1726 list.append(*it); 1751 list.append(*it);
1727 } 1752 }
1728 } 1753 }
1729 } 1754 }
1730 return list; 1755 return list;
1731} 1756}
1732 1757
1733Key Addressee::findKey( const QString &id ) const 1758Key Addressee::findKey( const QString &id ) const
1734{ 1759{
1735 Key::List::ConstIterator it; 1760 Key::List::ConstIterator it;
1736 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1761 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1737 if ( (*it).id() == id ) { 1762 if ( (*it).id() == id ) {
1738 return *it; 1763 return *it;
1739 } 1764 }
1740 } 1765 }
1741 return Key(); 1766 return Key();
1742} 1767}
1743 1768
1744QString Addressee::asString() const 1769QString Addressee::asString() const
1745{ 1770{
1746 return "Smith, agent Smith..."; 1771 return "Smith, agent Smith...";
1747} 1772}
1748 1773
1749void Addressee::dump() const 1774void Addressee::dump() const
1750{ 1775{
1751 return; 1776 return;
1752#if 0 1777#if 0
1753 kdDebug(5700) << "Addressee {" << endl; 1778 kdDebug(5700) << "Addressee {" << endl;
1754 1779
1755 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1780 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1756 1781
1757 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1782 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1758 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1783 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1759 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1784 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1760 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1785 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1761 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1786 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1762 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1787 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1763 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1788 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1764 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1789 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1765 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1790 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1766 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1791 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1767 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1792 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1768 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1793 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1769 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1794 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1770 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1795 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1771 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1796 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1772 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1797 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1773 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1798 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1774 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1799 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1775 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1800 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1776 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1801 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1777 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1802 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1778 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1803 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1779 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1804 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1780 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1805 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1781 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1806 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1782 1807
1783 kdDebug(5700) << " Emails {" << endl; 1808 kdDebug(5700) << " Emails {" << endl;
1784 QStringList e = emails(); 1809 QStringList e = emails();
1785 QStringList::ConstIterator it; 1810 QStringList::ConstIterator it;
1786 for( it = e.begin(); it != e.end(); ++it ) { 1811 for( it = e.begin(); it != e.end(); ++it ) {
1787 kdDebug(5700) << " " << (*it) << endl; 1812 kdDebug(5700) << " " << (*it) << endl;
1788 } 1813 }
1789 kdDebug(5700) << " }" << endl; 1814 kdDebug(5700) << " }" << endl;
1790 1815
1791 kdDebug(5700) << " PhoneNumbers {" << endl; 1816 kdDebug(5700) << " PhoneNumbers {" << endl;
1792 PhoneNumber::List p = phoneNumbers(); 1817 PhoneNumber::List p = phoneNumbers();
1793 PhoneNumber::List::ConstIterator it2; 1818 PhoneNumber::List::ConstIterator it2;
1794 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1819 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1795 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1820 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1796 } 1821 }
1797 kdDebug(5700) << " }" << endl; 1822 kdDebug(5700) << " }" << endl;
1798 1823
1799 Address::List a = addresses(); 1824 Address::List a = addresses();
1800 Address::List::ConstIterator it3; 1825 Address::List::ConstIterator it3;
1801 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1826 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1802 (*it3).dump(); 1827 (*it3).dump();
1803 } 1828 }
1804 1829
1805 kdDebug(5700) << " Keys {" << endl; 1830 kdDebug(5700) << " Keys {" << endl;
1806 Key::List k = keys(); 1831 Key::List k = keys();
1807 Key::List::ConstIterator it4; 1832 Key::List::ConstIterator it4;
1808 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1833 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1809 kdDebug(5700) << " Type: " << int((*it4).type()) << 1834 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1810 " Key: " << (*it4).textData() << 1835 " Key: " << (*it4).textData() <<
1811 " CustomString: " << (*it4).customTypeString() << endl; 1836 " CustomString: " << (*it4).customTypeString() << endl;
1812 } 1837 }
1813 kdDebug(5700) << " }" << endl; 1838 kdDebug(5700) << " }" << endl;
1814 1839
1815 kdDebug(5700) << "}" << endl; 1840 kdDebug(5700) << "}" << endl;
1816#endif 1841#endif
1817} 1842}
1818 1843
1819 1844
1820void Addressee::insertAddress( const Address &address ) 1845void Addressee::insertAddress( const Address &address )
1821{ 1846{
1822 detach(); 1847 detach();
1823 mData->empty = false; 1848 mData->empty = false;
1824 1849
1825 Address::List::Iterator it; 1850 Address::List::Iterator it;
1826 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1851 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1827 if ( (*it).id() == address.id() ) { 1852 if ( (*it).id() == address.id() ) {
1828 *it = address; 1853 *it = address;
1829 return; 1854 return;
1830 } 1855 }
1831 } 1856 }
1832 mData->addresses.append( address ); 1857 mData->addresses.append( address );
1833} 1858}
1834 1859
1835void Addressee::removeAddress( const Address &address ) 1860void Addressee::removeAddress( const Address &address )
1836{ 1861{
1837 detach(); 1862 detach();
1838 1863
1839 Address::List::Iterator it; 1864 Address::List::Iterator it;
1840 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1865 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1841 if ( (*it).id() == address.id() ) { 1866 if ( (*it).id() == address.id() ) {
1842 mData->addresses.remove( it ); 1867 mData->addresses.remove( it );
1843 return; 1868 return;
1844 } 1869 }
1845 } 1870 }
1846} 1871}
1847 1872
1848Address Addressee::address( int type ) const 1873Address Addressee::address( int type ) const
1849{ 1874{
1850 Address address( type ); 1875 Address address( type );
1851 Address::List::ConstIterator it; 1876 Address::List::ConstIterator it;
1852 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1877 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1853 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1878 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1854 if ( (*it).type() & Address::Pref ) 1879 if ( (*it).type() & Address::Pref )
1855 return (*it); 1880 return (*it);
1856 else if ( address.isEmpty() ) 1881 else if ( address.isEmpty() )
1857 address = (*it); 1882 address = (*it);
1858 } 1883 }
1859 } 1884 }
1860 1885
1861 return address; 1886 return address;
1862} 1887}
1863 1888
1864Address::List Addressee::addresses() const 1889Address::List Addressee::addresses() const
1865{ 1890{
1866 return mData->addresses; 1891 return mData->addresses;
1867} 1892}
1868 1893
1869Address::List Addressee::addresses( int type ) const 1894Address::List Addressee::addresses( int type ) const
1870{ 1895{
1871 Address::List list; 1896 Address::List list;
1872 1897
1873 Address::List::ConstIterator it; 1898 Address::List::ConstIterator it;
1874 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1899 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1875 if ( matchBinaryPattern( (*it).type(), type ) ) { 1900 if ( matchBinaryPattern( (*it).type(), type ) ) {
1876 list.append( *it ); 1901 list.append( *it );
1877 } 1902 }
1878 } 1903 }
1879 1904
1880 return list; 1905 return list;
1881} 1906}
1882 1907
1883Address Addressee::findAddress( const QString &id ) const 1908Address Addressee::findAddress( const QString &id ) const
1884{ 1909{
1885 Address::List::ConstIterator it; 1910 Address::List::ConstIterator it;
1886 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1911 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1887 if ( (*it).id() == id ) { 1912 if ( (*it).id() == id ) {
1888 return *it; 1913 return *it;
1889 } 1914 }
1890 } 1915 }
1891 return Address(); 1916 return Address();
1892} 1917}
1893 1918
1894void Addressee::insertCategory( const QString &c ) 1919void Addressee::insertCategory( const QString &c )
1895{ 1920{
1896 detach(); 1921 detach();
1897 mData->empty = false; 1922 mData->empty = false;
1898 1923
1899 if ( mData->categories.contains( c ) ) return; 1924 if ( mData->categories.contains( c ) ) return;
1900 1925
1901 mData->categories.append( c ); 1926 mData->categories.append( c );
1902} 1927}
1903 1928
1904void Addressee::removeCategory( const QString &c ) 1929void Addressee::removeCategory( const QString &c )
1905{ 1930{
1906 detach(); 1931 detach();
1907 1932
1908 QStringList::Iterator it = mData->categories.find( c ); 1933 QStringList::Iterator it = mData->categories.find( c );
1909 if ( it == mData->categories.end() ) return; 1934 if ( it == mData->categories.end() ) return;
1910 1935
1911 mData->categories.remove( it ); 1936 mData->categories.remove( it );
1912} 1937}
1913 1938
1914bool Addressee::hasCategory( const QString &c ) const 1939bool Addressee::hasCategory( const QString &c ) const
1915{ 1940{
1916 return ( mData->categories.contains( c ) ); 1941 return ( mData->categories.contains( c ) );
1917} 1942}
1918 1943
1919void Addressee::setCategories( const QStringList &c ) 1944void Addressee::setCategories( const QStringList &c )
1920{ 1945{
1921 detach(); 1946 detach();
1922 mData->empty = false; 1947 mData->empty = false;
1923 1948
1924 mData->categories = c; 1949 mData->categories = c;
1925} 1950}
1926 1951
1927QStringList Addressee::categories() const 1952QStringList Addressee::categories() const
1928{ 1953{
1929 return mData->categories; 1954 return mData->categories;
1930} 1955}
1931 1956
1932void Addressee::insertCustom( const QString &app, const QString &name, 1957void Addressee::insertCustom( const QString &app, const QString &name,
1933 const QString &value ) 1958 const QString &value )
1934{ 1959{
1935 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1960 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1936 1961
1937 detach(); 1962 detach();
1938 mData->empty = false; 1963 mData->empty = false;
1939 1964
1940 QString qualifiedName = app + "-" + name + ":"; 1965 QString qualifiedName = app + "-" + name + ":";
1941 1966
1942 QStringList::Iterator it; 1967 QStringList::Iterator it;
1943 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1968 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1944 if ( (*it).startsWith( qualifiedName ) ) { 1969 if ( (*it).startsWith( qualifiedName ) ) {
1945 (*it) = qualifiedName + value; 1970 (*it) = qualifiedName + value;
1946 return; 1971 return;
1947 } 1972 }
1948 } 1973 }
1949 mData->custom.append( qualifiedName + value ); 1974 mData->custom.append( qualifiedName + value );
1950} 1975}
1951 1976
1952void Addressee::removeCustom( const QString &app, const QString &name) 1977void Addressee::removeCustom( const QString &app, const QString &name)
1953{ 1978{
1954 detach(); 1979 detach();
1955 1980
1956 QString qualifiedName = app + "-" + name + ":"; 1981 QString qualifiedName = app + "-" + name + ":";
1957 1982
1958 QStringList::Iterator it; 1983 QStringList::Iterator it;
1959 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1984 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1960 if ( (*it).startsWith( qualifiedName ) ) { 1985 if ( (*it).startsWith( qualifiedName ) ) {
1961 mData->custom.remove( it ); 1986 mData->custom.remove( it );
1962 return; 1987 return;
1963 } 1988 }
1964 } 1989 }
1965} 1990}
1966 1991
1967QString Addressee::custom( const QString &app, const QString &name ) const 1992QString Addressee::custom( const QString &app, const QString &name ) const
1968{ 1993{
1969 QString qualifiedName = app + "-" + name + ":"; 1994 QString qualifiedName = app + "-" + name + ":";
1970 QString value; 1995 QString value;
1971 1996
1972 QStringList::ConstIterator it; 1997 QStringList::ConstIterator it;
1973 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1998 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1974 if ( (*it).startsWith( qualifiedName ) ) { 1999 if ( (*it).startsWith( qualifiedName ) ) {
1975 value = (*it).mid( (*it).find( ":" ) + 1 ); 2000 value = (*it).mid( (*it).find( ":" ) + 1 );
1976 break; 2001 break;
1977 } 2002 }
1978 } 2003 }
1979 2004
1980 return value; 2005 return value;
1981} 2006}
1982 2007
1983void Addressee::setCustoms( const QStringList &l ) 2008void Addressee::setCustoms( const QStringList &l )
1984{ 2009{
1985 detach(); 2010 detach();
1986 mData->empty = false; 2011 mData->empty = false;
1987 2012
1988 mData->custom = l; 2013 mData->custom = l;
1989} 2014}
1990 2015
1991QStringList Addressee::customs() const 2016QStringList Addressee::customs() const
1992{ 2017{
1993 return mData->custom; 2018 return mData->custom;
1994} 2019}
1995 2020
1996void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 2021void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1997 QString &email) 2022 QString &email)
1998{ 2023{
1999 int startPos, endPos, len; 2024 int startPos, endPos, len;
2000 QString partA, partB, result; 2025 QString partA, partB, result;
2001 char endCh = '>'; 2026 char endCh = '>';
2002 2027
2003 startPos = rawEmail.find('<'); 2028 startPos = rawEmail.find('<');
2004 if (startPos < 0) 2029 if (startPos < 0)
2005 { 2030 {
2006 startPos = rawEmail.find('('); 2031 startPos = rawEmail.find('(');
2007 endCh = ')'; 2032 endCh = ')';
2008 } 2033 }
2009 if (startPos < 0) 2034 if (startPos < 0)
2010 { 2035 {
2011 // We couldn't find any separators, so we assume the whole string 2036 // We couldn't find any separators, so we assume the whole string
2012 // is the email address 2037 // is the email address
2013 email = rawEmail; 2038 email = rawEmail;
2014 fullName = ""; 2039 fullName = "";
2015 } 2040 }
2016 else 2041 else
2017 { 2042 {
2018 // We have a start position, try to find an end 2043 // We have a start position, try to find an end
2019 endPos = rawEmail.find(endCh, startPos+1); 2044 endPos = rawEmail.find(endCh, startPos+1);
2020 2045
2021 if (endPos < 0) 2046 if (endPos < 0)
2022 { 2047 {
2023 // We couldn't find the end of the email address. We can only 2048 // We couldn't find the end of the email address. We can only
2024 // assume the entire string is the email address. 2049 // assume the entire string is the email address.
2025 email = rawEmail; 2050 email = rawEmail;
2026 fullName = ""; 2051 fullName = "";
2027 } 2052 }
2028 else 2053 else
2029 { 2054 {
2030 // We have a start and end to the email address 2055 // We have a start and end to the email address
2031 2056
2032 // Grab the name part 2057 // Grab the name part
2033 fullName = rawEmail.left(startPos).stripWhiteSpace(); 2058 fullName = rawEmail.left(startPos).stripWhiteSpace();
2034 2059
2035 // grab the email part 2060 // grab the email part
2036 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 2061 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
2037 2062
2038 // Check that we do not have any extra characters on the end of the 2063 // Check that we do not have any extra characters on the end of the
2039 // strings 2064 // strings
2040 len = fullName.length(); 2065 len = fullName.length();
2041 if (fullName[0]=='"' && fullName[len-1]=='"') 2066 if (fullName[0]=='"' && fullName[len-1]=='"')
2042 fullName = fullName.mid(1, len-2); 2067 fullName = fullName.mid(1, len-2);
2043 else if (fullName[0]=='<' && fullName[len-1]=='>') 2068 else if (fullName[0]=='<' && fullName[len-1]=='>')
2044 fullName = fullName.mid(1, len-2); 2069 fullName = fullName.mid(1, len-2);
2045 else if (fullName[0]=='(' && fullName[len-1]==')') 2070 else if (fullName[0]=='(' && fullName[len-1]==')')
2046 fullName = fullName.mid(1, len-2); 2071 fullName = fullName.mid(1, len-2);
2047 } 2072 }
2048 } 2073 }
2049} 2074}
2050 2075
2051void Addressee::setResource( Resource *resource ) 2076void Addressee::setResource( Resource *resource )
2052{ 2077{
2053 detach(); 2078 detach();
2054 mData->resource = resource; 2079 mData->resource = resource;
2055} 2080}
2056 2081
2057Resource *Addressee::resource() const 2082Resource *Addressee::resource() const
2058{ 2083{
2059 return mData->resource; 2084 return mData->resource;
2060} 2085}
2061 2086
2062//US 2087//US
2063QString Addressee::resourceLabel() 2088QString Addressee::resourceLabel()
2064{ 2089{
2065 return i18n("Resource"); 2090 return i18n("Resource");
2066} 2091}
2067QString Addressee::categoryLabel() 2092QString Addressee::categoryLabel()
2068{ 2093{
2069 return i18n("Category"); 2094 return i18n("Category");
2070} 2095}
2071 2096
2072void Addressee::setChanged( bool value ) 2097void Addressee::setChanged( bool value )
2073{ 2098{
2074 detach(); 2099 detach();
2075 mData->changed = value; 2100 mData->changed = value;
2076} 2101}
2077 2102
2078bool Addressee::changed() const 2103bool Addressee::changed() const
2079{ 2104{
2080 return mData->changed; 2105 return mData->changed;
2081} 2106}
2082 2107
2083void Addressee::setTagged( bool value ) 2108void Addressee::setTagged( bool value )
2084{ 2109{
2085 detach(); 2110 detach();
2086 mData->tagged = value; 2111 mData->tagged = value;
2087} 2112}
2088 2113
2089bool Addressee::tagged() const 2114bool Addressee::tagged() const
2090{ 2115{
2091 return mData->tagged; 2116 return mData->tagged;
2092} 2117}
2093 2118
2094QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 2119QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
2095{ 2120{
2096 if (!a.mData) return s; 2121 if (!a.mData) return s;
2097 2122
2098 s << a.uid(); 2123 s << a.uid();
2099 2124
2100 s << a.mData->name; 2125 s << a.mData->name;
2101 s << a.mData->formattedName; 2126 s << a.mData->formattedName;
2102 s << a.mData->familyName; 2127 s << a.mData->familyName;
2103 s << a.mData->givenName; 2128 s << a.mData->givenName;
2104 s << a.mData->additionalName; 2129 s << a.mData->additionalName;
2105 s << a.mData->prefix; 2130 s << a.mData->prefix;
2106 s << a.mData->suffix; 2131 s << a.mData->suffix;
2107 s << a.mData->nickName; 2132 s << a.mData->nickName;
2108 s << a.mData->birthday; 2133 s << a.mData->birthday;
2109 s << a.mData->mailer; 2134 s << a.mData->mailer;
2110 s << a.mData->timeZone; 2135 s << a.mData->timeZone;
2111 s << a.mData->geo; 2136 s << a.mData->geo;
2112 s << a.mData->title; 2137 s << a.mData->title;
2113 s << a.mData->role; 2138 s << a.mData->role;
2114 s << a.mData->organization; 2139 s << a.mData->organization;
2115 s << a.mData->note; 2140 s << a.mData->note;
2116 s << a.mData->productId; 2141 s << a.mData->productId;
2117 s << a.mData->revision; 2142 s << a.mData->revision;
2118 s << a.mData->sortString; 2143 s << a.mData->sortString;
2119 s << a.mData->url; 2144 s << a.mData->url;
2120 s << a.mData->secrecy; 2145 s << a.mData->secrecy;
2121 s << a.mData->logo; 2146 s << a.mData->logo;
2122 s << a.mData->photo; 2147 s << a.mData->photo;
2123 s << a.mData->sound; 2148 s << a.mData->sound;
2124 s << a.mData->agent; 2149 s << a.mData->agent;
2125 s << a.mData->phoneNumbers; 2150 s << a.mData->phoneNumbers;
2126 s << a.mData->addresses; 2151 s << a.mData->addresses;
2127 s << a.mData->emails; 2152 s << a.mData->emails;
2128 s << a.mData->categories; 2153 s << a.mData->categories;
2129 s << a.mData->custom; 2154 s << a.mData->custom;
2130 s << a.mData->keys; 2155 s << a.mData->keys;
2131 return s; 2156 return s;
2132} 2157}
2133 2158
2134QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 2159QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
2135{ 2160{
2136 if (!a.mData) return s; 2161 if (!a.mData) return s;
2137 2162
2138 s >> a.mData->uid; 2163 s >> a.mData->uid;
2139 2164
2140 s >> a.mData->name; 2165 s >> a.mData->name;
2141 s >> a.mData->formattedName; 2166 s >> a.mData->formattedName;
2142 s >> a.mData->familyName; 2167 s >> a.mData->familyName;
2143 s >> a.mData->givenName; 2168 s >> a.mData->givenName;
2144 s >> a.mData->additionalName; 2169 s >> a.mData->additionalName;
2145 s >> a.mData->prefix; 2170 s >> a.mData->prefix;
2146 s >> a.mData->suffix; 2171 s >> a.mData->suffix;
2147 s >> a.mData->nickName; 2172 s >> a.mData->nickName;
2148 s >> a.mData->birthday; 2173 s >> a.mData->birthday;
2149 s >> a.mData->mailer; 2174 s >> a.mData->mailer;
2150 s >> a.mData->timeZone; 2175 s >> a.mData->timeZone;
2151 s >> a.mData->geo; 2176 s >> a.mData->geo;
2152 s >> a.mData->title; 2177 s >> a.mData->title;
2153 s >> a.mData->role; 2178 s >> a.mData->role;
2154 s >> a.mData->organization; 2179 s >> a.mData->organization;
2155 s >> a.mData->note; 2180 s >> a.mData->note;
2156 s >> a.mData->productId; 2181 s >> a.mData->productId;
2157 s >> a.mData->revision; 2182 s >> a.mData->revision;
2158 s >> a.mData->sortString; 2183 s >> a.mData->sortString;
2159 s >> a.mData->url; 2184 s >> a.mData->url;
2160 s >> a.mData->secrecy; 2185 s >> a.mData->secrecy;
2161 s >> a.mData->logo; 2186 s >> a.mData->logo;
2162 s >> a.mData->photo; 2187 s >> a.mData->photo;
2163 s >> a.mData->sound; 2188 s >> a.mData->sound;
2164 s >> a.mData->agent; 2189 s >> a.mData->agent;
2165 s >> a.mData->phoneNumbers; 2190 s >> a.mData->phoneNumbers;
2166 s >> a.mData->addresses; 2191 s >> a.mData->addresses;
2167 s >> a.mData->emails; 2192 s >> a.mData->emails;
2168 s >> a.mData->categories; 2193 s >> a.mData->categories;
2169 s >> a.mData->custom; 2194 s >> a.mData->custom;
2170 s >> a.mData->keys; 2195 s >> a.mData->keys;
2171 2196
2172 a.mData->empty = false; 2197 a.mData->empty = false;
2173 2198
2174 return s; 2199 return s;
2175} 2200}
2176bool matchBinaryPattern( int value, int pattern ) 2201bool matchBinaryPattern( int value, int pattern )
2177{ 2202{
2178 /** 2203 /**
2179 We want to match all telephonnumbers/addresses which have the bits in the 2204 We want to match all telephonnumbers/addresses which have the bits in the
2180 pattern set. More are allowed. 2205 pattern set. More are allowed.
2181 if pattern == 0 we have a special handling, then we want only those with 2206 if pattern == 0 we have a special handling, then we want only those with
2182 exactly no bit set. 2207 exactly no bit set.
2183 */ 2208 */
2184 if ( pattern == 0 ) 2209 if ( pattern == 0 )
2185 return ( value == 0 ); 2210 return ( value == 0 );
2186 else 2211 else
2187 return ( pattern == ( pattern & value ) ); 2212 return ( pattern == ( pattern & value ) );
2188} 2213}
2189 2214
2190bool matchBinaryPatternP( int value, int pattern ) 2215bool matchBinaryPatternP( int value, int pattern )
2191{ 2216{
2192 2217
2193 if ( pattern == 0 ) 2218 if ( pattern == 0 )
2194 return ( value == 0 ); 2219 return ( value == 0 );
2195 else 2220 else
2196 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); 2221 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
2197} 2222}
2198bool matchBinaryPatternA( int value, int pattern ) 2223bool matchBinaryPatternA( int value, int pattern )
2199{ 2224{
2200 2225
2201 if ( pattern == 0 ) 2226 if ( pattern == 0 )
2202 return ( value == 0 ); 2227 return ( value == 0 );
2203 else 2228 else
2204 return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); 2229 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
2205} 2230}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index a2fbcf5..d1c07cb 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -1,855 +1,859 @@
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#ifndef KABC_ADDRESSEE_H 29#ifndef KABC_ADDRESSEE_H
30#define KABC_ADDRESSEE_H 30#define KABC_ADDRESSEE_H
31 31
32#include <qdatetime.h> 32#include <qdatetime.h>
33#include <qstring.h> 33#include <qstring.h>
34#include <qregexp.h>
34#include <qstringlist.h> 35#include <qstringlist.h>
35#include <qvaluelist.h> 36#include <qvaluelist.h>
36 37
37#include <ksharedptr.h> 38#include <ksharedptr.h>
38#include <kurl.h> 39#include <kurl.h>
39 40
40#include "address.h" 41#include "address.h"
41#include "agent.h" 42#include "agent.h"
42#include "geo.h" 43#include "geo.h"
43#include "key.h" 44#include "key.h"
44#include "phonenumber.h" 45#include "phonenumber.h"
45#include "picture.h" 46#include "picture.h"
46#include "secrecy.h" 47#include "secrecy.h"
47#include "sound.h" 48#include "sound.h"
48#include "timezone.h" 49#include "timezone.h"
49 50
50namespace KABC { 51namespace KABC {
51 52
52class Resource; 53class Resource;
53 54
54/** 55/**
55 @short address book entry 56 @short address book entry
56 57
57 This class represents an entry in the address book. 58 This class represents an entry in the address book.
58 59
59 The data of this class is implicitly shared. You can pass this class by value. 60 The data of this class is implicitly shared. You can pass this class by value.
60 61
61 If you need the name of a field for presenting it to the user you should use 62 If you need the name of a field for presenting it to the user you should use
62 the functions ending in Label(). They return a translated string which can be 63 the functions ending in Label(). They return a translated string which can be
63 used as label for the corresponding field. 64 used as label for the corresponding field.
64 65
65 About the name fields: 66 About the name fields:
66 67
67 givenName() is the first name and familyName() the last name. In some 68 givenName() is the first name and familyName() the last name. In some
68 countries the family name comes first, that's the reason for the 69 countries the family name comes first, that's the reason for the
69 naming. formattedName() is the full name with the correct formatting. 70 naming. formattedName() is the full name with the correct formatting.
70 It is used as an override, when the correct formatting can't be generated 71 It is used as an override, when the correct formatting can't be generated
71 from the other name fields automatically. 72 from the other name fields automatically.
72 73
73 realName() returns a fully formatted name(). It uses formattedName, if set, 74 realName() returns a fully formatted name(). It uses formattedName, if set,
74 otherwise it constucts the name from the name fields. As fallback, if 75 otherwise it constucts the name from the name fields. As fallback, if
75 nothing else is set it uses name(). 76 nothing else is set it uses name().
76 77
77 name() is the NAME type of RFC2426. It can be used as internal name for the 78 name() is the NAME type of RFC2426. It can be used as internal name for the
78 data enty, but shouldn't be used for displaying the data to the user. 79 data enty, but shouldn't be used for displaying the data to the user.
79 */ 80 */
80class Addressee 81class Addressee
81{ 82{
82 friend QDataStream &operator<<( QDataStream &, const Addressee & ); 83 friend QDataStream &operator<<( QDataStream &, const Addressee & );
83 friend QDataStream &operator>>( QDataStream &, Addressee & ); 84 friend QDataStream &operator>>( QDataStream &, Addressee & );
84 85
85 public: 86 public:
86 typedef QValueList<Addressee> List; 87 typedef QValueList<Addressee> List;
87 88
88 /** 89 /**
89 Construct an empty address book entry. 90 Construct an empty address book entry.
90 */ 91 */
91 Addressee(); 92 Addressee();
92 ~Addressee(); 93 ~Addressee();
93 94
94 Addressee( const Addressee & ); 95 Addressee( const Addressee & );
95 Addressee &operator=( const Addressee & ); 96 Addressee &operator=( const Addressee & );
96 97
97 bool operator==( const Addressee & ) const; 98 bool operator==( const Addressee & ) const;
98 bool operator!=( const Addressee & ) const; 99 bool operator!=( const Addressee & ) const;
99 // sync stuff 100 // sync stuff
100 void setTempSyncStat(int id); 101 void setTempSyncStat(int id);
101 int tempSyncStat() const; 102 int tempSyncStat() const;
102 void setIDStr( const QString & ); 103 void setIDStr( const QString & );
103 const QString IDStr() const; 104 const QString IDStr() const;
104 void setID( const QString &, const QString & ); 105 void setID( const QString &, const QString & );
105 const QString getID( const QString & ) const; 106 const QString getID( const QString & ) const;
106 void setCsum( const QString &, const QString & ); 107 void setCsum( const QString &, const QString & );
107 const QString getCsum( const QString & ) const ; 108 const QString getCsum( const QString & ) const ;
108 void removeID(const QString &); 109 void removeID(const QString &);
109 void computeCsum(const QString &dev); 110 void computeCsum(const QString &dev);
110 ulong getCsum4List( const QStringList & attList); 111 ulong getCsum4List( const QStringList & attList);
111 /** 112 /**
112 Return, if the address book entry is empty. 113 Return, if the address book entry is empty.
113 */ 114 */
114 bool isEmpty() const; 115 bool isEmpty() const;
115 void setExternalUID( const QString &id ); 116 void setExternalUID( const QString &id );
116 const QString externalUID() const; 117 const QString externalUID() const;
117 void setOriginalExternalUID( const QString &id ); 118 void setOriginalExternalUID( const QString &id );
118 QString originalExternalUID() const; 119 QString originalExternalUID() const;
119 void mergeContact( const Addressee& ad, bool isSubSet ); 120 void mergeContact( const Addressee& ad, bool isSubSet );
120 void simplifyEmails(); 121 void simplifyEmails();
121 void simplifyAddresses(); 122 void simplifyAddresses();
122 void simplifyPhoneNumbers(); 123 void simplifyPhoneNumbers();
123 void simplifyPhoneNumberTypes(); 124 void simplifyPhoneNumberTypes();
124 bool removeVoice(); 125 bool removeVoice();
125 bool containsAdr(const Addressee& addr ); 126 bool containsAdr(const Addressee& addr );
126 127
127 /** 128 /**
128 Set unique identifier. 129 Set unique identifier.
129 */ 130 */
130 void setUid( const QString &uid ); 131 void setUid( const QString &uid );
131 /** 132 /**
132 Return unique identifier. 133 Return unique identifier.
133 */ 134 */
134 const QString uid() const; 135 const QString uid() const;
135 /** 136 /**
136 Return translated label for uid field. 137 Return translated label for uid field.
137 */ 138 */
138 static QString uidLabel(); 139 static QString uidLabel();
139 140
140 /** 141 /**
141 Set name. 142 Set name.
142 */ 143 */
143 void setName( const QString &name ); 144 void setName( const QString &name );
144 /** 145 /**
145 Return name. 146 Return name.
146 */ 147 */
147 QString name() const; 148 QString name() const;
148 /** 149 /**
149 Return translated label for name field. 150 Return translated label for name field.
150 */ 151 */
151 static QString nameLabel(); 152 static QString nameLabel();
152 153
153 /** 154 /**
154 Set formatted name. 155 Set formatted name.
155 */ 156 */
156 void setFormattedName( const QString &formattedName ); 157 void setFormattedName( const QString &formattedName );
157 /** 158 /**
158 Return formatted name. 159 Return formatted name.
159 */ 160 */
160 QString formattedName() const; 161 QString formattedName() const;
161 /** 162 /**
162 Return translated label for formattedName field. 163 Return translated label for formattedName field.
163 */ 164 */
164 static QString formattedNameLabel(); 165 static QString formattedNameLabel();
165 166
166 /** 167 /**
167 Set family name. 168 Set family name.
168 */ 169 */
169 void setFamilyName( const QString &familyName ); 170 void setFamilyName( const QString &familyName );
170 /** 171 /**
171 Return family name. 172 Return family name.
172 */ 173 */
173 QString familyName() const; 174 QString familyName() const;
174 /** 175 /**
175 Return translated label for familyName field. 176 Return translated label for familyName field.
176 */ 177 */
177 static QString familyNameLabel(); 178 static QString familyNameLabel();
178 179
179 /** 180 /**
180 Set given name. 181 Set given name.
181 */ 182 */
182 void setGivenName( const QString &givenName ); 183 void setGivenName( const QString &givenName );
183 /** 184 /**
184 Return given name. 185 Return given name.
185 */ 186 */
186 QString givenName() const; 187 QString givenName() const;
187 /** 188 /**
188 Return translated label for givenName field. 189 Return translated label for givenName field.
189 */ 190 */
190 static QString givenNameLabel(); 191 static QString givenNameLabel();
191 192
192 /** 193 /**
193 Set additional names. 194 Set additional names.
194 */ 195 */
195 void setAdditionalName( const QString &additionalName ); 196 void setAdditionalName( const QString &additionalName );
196 /** 197 /**
197 Return additional names. 198 Return additional names.
198 */ 199 */
199 QString additionalName() const; 200 QString additionalName() const;
200 /** 201 /**
201 Return translated label for additionalName field. 202 Return translated label for additionalName field.
202 */ 203 */
203 static QString additionalNameLabel(); 204 static QString additionalNameLabel();
204 205
205 /** 206 /**
206 Set honorific prefixes. 207 Set honorific prefixes.
207 */ 208 */
208 void setPrefix( const QString &prefix ); 209 void setPrefix( const QString &prefix );
209 /** 210 /**
210 Return honorific prefixes. 211 Return honorific prefixes.
211 */ 212 */
212 QString prefix() const; 213 QString prefix() const;
213 /** 214 /**
214 Return translated label for prefix field. 215 Return translated label for prefix field.
215 */ 216 */
216 static QString prefixLabel(); 217 static QString prefixLabel();
217 218
218 /** 219 /**
219 Set honorific suffixes. 220 Set honorific suffixes.
220 */ 221 */
221 void setSuffix( const QString &suffix ); 222 void setSuffix( const QString &suffix );
222 /** 223 /**
223 Return honorific suffixes. 224 Return honorific suffixes.
224 */ 225 */
225 QString suffix() const; 226 QString suffix() const;
226 /** 227 /**
227 Return translated label for suffix field. 228 Return translated label for suffix field.
228 */ 229 */
229 static QString suffixLabel(); 230 static QString suffixLabel();
230 231
231 /** 232 /**
232 Set nick name. 233 Set nick name.
233 */ 234 */
234 void setNickName( const QString &nickName ); 235 void setNickName( const QString &nickName );
235 /** 236 /**
236 Return nick name. 237 Return nick name.
237 */ 238 */
238 QString nickName() const; 239 QString nickName() const;
239 /** 240 /**
240 Return translated label for nickName field. 241 Return translated label for nickName field.
241 */ 242 */
242 static QString nickNameLabel(); 243 static QString nickNameLabel();
243 244
244 /** 245 /**
245 Set birthday. 246 Set birthday.
246 */ 247 */
247 void setBirthday( const QDateTime &birthday ); 248 void setBirthday( const QDateTime &birthday );
248 /** 249 /**
249 Return birthday. 250 Return birthday.
250 */ 251 */
251 QDateTime birthday() const; 252 QDateTime birthday() const;
252 /** 253 /**
253 Return translated label for birthday field. 254 Return translated label for birthday field.
254 */ 255 */
255 static QString birthdayLabel(); 256 static QString birthdayLabel();
256 257
257 /** 258 /**
258 Return translated label for homeAddressStreet field. 259 Return translated label for homeAddressStreet field.
259 */ 260 */
260 static QString homeAddressStreetLabel(); 261 static QString homeAddressStreetLabel();
261 262
262 /** 263 /**
263 Return translated label for homeAddressLocality field. 264 Return translated label for homeAddressLocality field.
264 */ 265 */
265 static QString homeAddressLocalityLabel(); 266 static QString homeAddressLocalityLabel();
266 267
267 /** 268 /**
268 Return translated label for homeAddressRegion field. 269 Return translated label for homeAddressRegion field.
269 */ 270 */
270 static QString homeAddressRegionLabel(); 271 static QString homeAddressRegionLabel();
271 272
272 /** 273 /**
273 Return translated label for homeAddressPostalCode field. 274 Return translated label for homeAddressPostalCode field.
274 */ 275 */
275 static QString homeAddressPostalCodeLabel(); 276 static QString homeAddressPostalCodeLabel();
276 277
277 /** 278 /**
278 Return translated label for homeAddressCountry field. 279 Return translated label for homeAddressCountry field.
279 */ 280 */
280 static QString homeAddressCountryLabel(); 281 static QString homeAddressCountryLabel();
281 282
282 /** 283 /**
283 Return translated label for homeAddressLabel field. 284 Return translated label for homeAddressLabel field.
284 */ 285 */
285 static QString homeAddressLabelLabel(); 286 static QString homeAddressLabelLabel();
286 287
287 /** 288 /**
288 Return translated label for businessAddressStreet field. 289 Return translated label for businessAddressStreet field.
289 */ 290 */
290 static QString businessAddressStreetLabel(); 291 static QString businessAddressStreetLabel();
291 292
292 /** 293 /**
293 Return translated label for businessAddressLocality field. 294 Return translated label for businessAddressLocality field.
294 */ 295 */
295 static QString businessAddressLocalityLabel(); 296 static QString businessAddressLocalityLabel();
296 297
297 /** 298 /**
298 Return translated label for businessAddressRegion field. 299 Return translated label for businessAddressRegion field.
299 */ 300 */
300 static QString businessAddressRegionLabel(); 301 static QString businessAddressRegionLabel();
301 302
302 /** 303 /**
303 Return translated label for businessAddressPostalCode field. 304 Return translated label for businessAddressPostalCode field.
304 */ 305 */
305 static QString businessAddressPostalCodeLabel(); 306 static QString businessAddressPostalCodeLabel();
306 307
307 /** 308 /**
308 Return translated label for businessAddressCountry field. 309 Return translated label for businessAddressCountry field.
309 */ 310 */
310 static QString businessAddressCountryLabel(); 311 static QString businessAddressCountryLabel();
311 312
312 /** 313 /**
313 Return translated label for businessAddressLabel field. 314 Return translated label for businessAddressLabel field.
314 */ 315 */
315 static QString businessAddressLabelLabel(); 316 static QString businessAddressLabelLabel();
316 317
317 /** 318 /**
318 Return translated label for homePhone field. 319 Return translated label for homePhone field.
319 */ 320 */
320 static QString homePhoneLabel(); 321 static QString homePhoneLabel();
321 322
322 /** 323 /**
323 Return translated label for businessPhone field. 324 Return translated label for businessPhone field.
324 */ 325 */
325 static QString businessPhoneLabel(); 326 static QString businessPhoneLabel();
326 327
327 /** 328 /**
328 Return translated label for mobilePhone field. 329 Return translated label for mobilePhone field.
329 */ 330 */
330 static QString mobilePhoneLabel(); 331 static QString mobilePhoneLabel();
331 static QString mobileWorkPhoneLabel(); 332 static QString mobileWorkPhoneLabel();
332 static QString mobileHomePhoneLabel(); 333 static QString mobileHomePhoneLabel();
333 334
334 /** 335 /**
335 Return translated label for homeFax field. 336 Return translated label for homeFax field.
336 */ 337 */
337 static QString homeFaxLabel(); 338 static QString homeFaxLabel();
338 339
339 /** 340 /**
340 Return translated label for businessFax field. 341 Return translated label for businessFax field.
341 */ 342 */
342 static QString businessFaxLabel(); 343 static QString businessFaxLabel();
343 344
344 /** 345 /**
345 Return translated label for carPhone field. 346 Return translated label for carPhone field.
346 */ 347 */
347 static QString carPhoneLabel(); 348 static QString carPhoneLabel();
348 349
349 /** 350 /**
350 Return translated label for isdn field. 351 Return translated label for isdn field.
351 */ 352 */
352 static QString isdnLabel(); 353 static QString isdnLabel();
353 354
354 /** 355 /**
355 Return translated label for pager field. 356 Return translated label for pager field.
356 */ 357 */
357 static QString pagerLabel(); 358 static QString pagerLabel();
358 359
359 /** 360 /**
360 Return translated label for sip field. 361 Return translated label for sip field.
361 */ 362 */
362 static QString sipLabel(); 363 static QString sipLabel();
363 364
364 /** 365 /**
365 Return translated label for email field. 366 Return translated label for email field.
366 */ 367 */
367 static QString emailLabel(); 368 static QString emailLabel();
368 369
369 /** 370 /**
370 Set mail client. 371 Set mail client.
371 */ 372 */
372 void setMailer( const QString &mailer ); 373 void setMailer( const QString &mailer );
373 /** 374 /**
374 Return mail client. 375 Return mail client.
375 */ 376 */
376 QString mailer() const; 377 QString mailer() const;
377 /** 378 /**
378 Return translated label for mailer field. 379 Return translated label for mailer field.
379 */ 380 */
380 static QString mailerLabel(); 381 static QString mailerLabel();
381 382
382 /** 383 /**
383 Set time zone. 384 Set time zone.
384 */ 385 */
385 void setTimeZone( const TimeZone &timeZone ); 386 void setTimeZone( const TimeZone &timeZone );
386 /** 387 /**
387 Return time zone. 388 Return time zone.
388 */ 389 */
389 TimeZone timeZone() const; 390 TimeZone timeZone() const;
390 /** 391 /**
391 Return translated label for timeZone field. 392 Return translated label for timeZone field.
392 */ 393 */
393 static QString timeZoneLabel(); 394 static QString timeZoneLabel();
394 395
395 /** 396 /**
396 Set geographic position. 397 Set geographic position.
397 */ 398 */
398 void setGeo( const Geo &geo ); 399 void setGeo( const Geo &geo );
399 /** 400 /**
400 Return geographic position. 401 Return geographic position.
401 */ 402 */
402 Geo geo() const; 403 Geo geo() const;
403 /** 404 /**
404 Return translated label for geo field. 405 Return translated label for geo field.
405 */ 406 */
406 static QString geoLabel(); 407 static QString geoLabel();
407 408
408 /** 409 /**
409 Set title. 410 Set title.
410 */ 411 */
411 void setTitle( const QString &title ); 412 void setTitle( const QString &title );
412 /** 413 /**
413 Return title. 414 Return title.
414 */ 415 */
415 QString title() const; 416 QString title() const;
416 /** 417 /**
417 Return translated label for title field. 418 Return translated label for title field.
418 */ 419 */
419 static QString titleLabel(); 420 static QString titleLabel();
420 421
421 /** 422 /**
422 Set role. 423 Set role.
423 */ 424 */
424 void setRole( const QString &role ); 425 void setRole( const QString &role );
425 /** 426 /**
426 Return role. 427 Return role.
427 */ 428 */
428 QString role() const; 429 QString role() const;
429 /** 430 /**
430 Return translated label for role field. 431 Return translated label for role field.
431 */ 432 */
432 static QString roleLabel(); 433 static QString roleLabel();
433 434
434 /** 435 /**
435 Set organization. 436 Set organization.
436 */ 437 */
437 void setOrganization( const QString &organization ); 438 void setOrganization( const QString &organization );
438 /** 439 /**
439 Return organization. 440 Return organization.
440 */ 441 */
441 QString organization() const; 442 QString organization() const;
442 /** 443 /**
443 Return translated label for organization field. 444 Return translated label for organization field.
444 */ 445 */
445 static QString organizationLabel(); 446 static QString organizationLabel();
446 447
447 /** 448 /**
448 Set note. 449 Set note.
449 */ 450 */
450 void setNote( const QString &note ); 451 void setNote( const QString &note );
451 /** 452 /**
452 Return note. 453 Return note.
453 */ 454 */
454 QString note() const; 455 QString note() const;
455 /** 456 /**
456 Return translated label for note field. 457 Return translated label for note field.
457 */ 458 */
458 static QString noteLabel(); 459 static QString noteLabel();
459 460
460 /** 461 /**
461 Set product identifier. 462 Set product identifier.
462 */ 463 */
463 void setProductId( const QString &productId ); 464 void setProductId( const QString &productId );
464 /** 465 /**
465 Return product identifier. 466 Return product identifier.
466 */ 467 */
467 QString productId() const; 468 QString productId() const;
468 /** 469 /**
469 Return translated label for productId field. 470 Return translated label for productId field.
470 */ 471 */
471 static QString productIdLabel(); 472 static QString productIdLabel();
472 473
473 /** 474 /**
474 Set revision date. 475 Set revision date.
475 */ 476 */
476 void setRevision( const QDateTime &revision ); 477 void setRevision( const QDateTime &revision );
477 /** 478 /**
478 Return revision date. 479 Return revision date.
479 */ 480 */
480 QDateTime revision() const; 481 QDateTime revision() const;
481 /** 482 /**
482 Return translated label for revision field. 483 Return translated label for revision field.
483 */ 484 */
484 static QString revisionLabel(); 485 static QString revisionLabel();
485 486
486 /** 487 /**
487 Set sort string. 488 Set sort string.
488 */ 489 */
489 void setSortString( const QString &sortString ); 490 void setSortString( const QString &sortString );
490 /** 491 /**
491 Return sort string. 492 Return sort string.
492 */ 493 */
493 QString sortString() const; 494 QString sortString() const;
494 /** 495 /**
495 Return translated label for sortString field. 496 Return translated label for sortString field.
496 */ 497 */
497 static QString sortStringLabel(); 498 static QString sortStringLabel();
498 499
499 /** 500 /**
500 Set URL. 501 Set URL.
501 */ 502 */
502 void setUrl( const KURL &url ); 503 void setUrl( const KURL &url );
503 /** 504 /**
504 Return URL. 505 Return URL.
505 */ 506 */
506 KURL url() const; 507 KURL url() const;
507 /** 508 /**
508 Return translated label for url field. 509 Return translated label for url field.
509 */ 510 */
510 static QString urlLabel(); 511 static QString urlLabel();
511 512
512 /** 513 /**
513 Set security class. 514 Set security class.
514 */ 515 */
515 void setSecrecy( const Secrecy &secrecy ); 516 void setSecrecy( const Secrecy &secrecy );
516 /** 517 /**
517 Return security class. 518 Return security class.
518 */ 519 */
519 Secrecy secrecy() const; 520 Secrecy secrecy() const;
520 /** 521 /**
521 Return translated label for secrecy field. 522 Return translated label for secrecy field.
522 */ 523 */
523 static QString secrecyLabel(); 524 static QString secrecyLabel();
524 525
525 /** 526 /**
526 Set logo. 527 Set logo.
527 */ 528 */
528 void setLogo( const Picture &logo ); 529 void setLogo( const Picture &logo );
529 /** 530 /**
530 Return logo. 531 Return logo.
531 */ 532 */
532 Picture logo() const; 533 Picture logo() const;
533 /** 534 /**
534 Return translated label for logo field. 535 Return translated label for logo field.
535 */ 536 */
536 static QString logoLabel(); 537 static QString logoLabel();
537 538
538 /** 539 /**
539 Set photo. 540 Set photo.
540 */ 541 */
541 void setPhoto( const Picture &photo ); 542 void setPhoto( const Picture &photo );
542 /** 543 /**
543 Return photo. 544 Return photo.
544 */ 545 */
545 Picture photo() const; 546 Picture photo() const;
546 /** 547 /**
547 Return translated label for photo field. 548 Return translated label for photo field.
548 */ 549 */
549 static QString photoLabel(); 550 static QString photoLabel();
550 551
551 /** 552 /**
552 Set sound. 553 Set sound.
553 */ 554 */
554 void setSound( const Sound &sound ); 555 void setSound( const Sound &sound );
555 /** 556 /**
556 Return sound. 557 Return sound.
557 */ 558 */
558 Sound sound() const; 559 Sound sound() const;
559 /** 560 /**
560 Return translated label for sound field. 561 Return translated label for sound field.
561 */ 562 */
562 static QString soundLabel(); 563 static QString soundLabel();
563 564
564 /** 565 /**
565 Set agent. 566 Set agent.
566 */ 567 */
567 void setAgent( const Agent &agent ); 568 void setAgent( const Agent &agent );
568 /** 569 /**
569 Return agent. 570 Return agent.
570 */ 571 */
571 Agent agent() const; 572 Agent agent() const;
572 /** 573 /**
573 Return translated label for agent field. 574 Return translated label for agent field.
574 */ 575 */
575 static QString agentLabel(); 576 static QString agentLabel();
576 577
577 /** 578 /**
578 Set name fields by parsing the given string and trying to associate the 579 Set name fields by parsing the given string and trying to associate the
579 parts of the string with according fields. This function should probably 580 parts of the string with according fields. This function should probably
580 be a bit more clever. 581 be a bit more clever.
581 */ 582 */
582 void setNameFromString( const QString & ); 583 void setNameFromString( const QString & );
583 584
584 /** 585 /**
585 Return the name of the addressee. This is calculated from all the name 586 Return the name of the addressee. This is calculated from all the name
586 fields. 587 fields.
587 */ 588 */
588 QString realName() const; 589 QString realName() const;
589 590
590 /** 591 /**
591 Return the name that consists of all name parts. 592 Return the name that consists of all name parts.
592 */ 593 */
593 QString assembledName() const; 594 QString assembledName() const;
594 595
595 /** 596 /**
596 Return email address including real name. 597 Return email address including real name.
597 598
598 @param email Email address to be used to construct the full email string. 599 @param email Email address to be used to construct the full email string.
599 If this is QString::null the preferred email address is used. 600 If this is QString::null the preferred email address is used.
600 */ 601 */
601 QString fullEmail( const QString &email=QString::null ) const; 602 QString fullEmail( const QString &email=QString::null ) const;
602 603
603 /** 604 /**
604 Insert an email address. If the email address already exists in this 605 Insert an email address. If the email address already exists in this
605 addressee it is not duplicated. 606 addressee it is not duplicated.
606 607
607 @param email Email address 608 @param email Email address
608 @param preferred Set to true, if this is the preferred email address of 609 @param preferred Set to true, if this is the preferred email address of
609 the addressee. 610 the addressee.
610 */ 611 */
611 void insertEmail( const QString &email, bool preferred=false ); 612 void insertEmail( const QString &email, bool preferred=false );
612 613
613 /** 614 /**
614 Remove email address. If the email address doesn't exist, nothing happens. 615 Remove email address. If the email address doesn't exist, nothing happens.
615 */ 616 */
616 void removeEmail( const QString &email ); 617 void removeEmail( const QString &email );
617 618
618 /** 619 /**
619 Return preferred email address. This is the first email address or the 620 Return preferred email address. This is the first email address or the
620 last one added with @ref insertEmail() with a set preferred parameter. 621 last one added with @ref insertEmail() with a set preferred parameter.
621 */ 622 */
622 QString preferredEmail() const; 623 QString preferredEmail() const;
623 624
624 /** 625 /**
625 Return list of all email addresses. 626 Return list of all email addresses.
626 */ 627 */
627 QStringList emails() const; 628 QStringList emails() const;
628 629
629 /** 630 /**
630 Set the emails to @param. 631 Set the emails to @param.
631 The first email address gets the preferred one! 632 The first email address gets the preferred one!
632 @param list The list of email addresses. 633 @param list The list of email addresses.
633 */ 634 */
634 void setEmails( const QStringList& list); 635 void setEmails( const QStringList& list);
635 636
636 /** 637 /**
637 Insert a phone number. If a phone number with the same id already exists 638 Insert a phone number. If a phone number with the same id already exists
638 in this addressee it is not duplicated. 639 in this addressee it is not duplicated.
639 */ 640 */
640 void insertPhoneNumber( const PhoneNumber &phoneNumber ); 641 void insertPhoneNumber( const PhoneNumber &phoneNumber );
641 642
642 /** 643 /**
643 Remove phone number. If no phone number with the given id exists for this 644 Remove phone number. If no phone number with the given id exists for this
644 addresse nothing happens. 645 addresse nothing happens.
645 */ 646 */
646 void removePhoneNumber( const PhoneNumber &phoneNumber ); 647 void removePhoneNumber( const PhoneNumber &phoneNumber );
647 648
648 /** 649 /**
649 Return phone number, which matches the given type. 650 Return phone number, which matches the given type.
650 */ 651 */
651 PhoneNumber phoneNumber( int type ) const; 652 PhoneNumber phoneNumber( int type ) const;
652 653
654 bool matchPhoneNumber( QRegExp* searchExp ) const;
655 bool matchAddress( QRegExp* searchExp ) const;
656
653 /** 657 /**
654 Return list of all phone numbers. 658 Return list of all phone numbers.
655 */ 659 */
656 PhoneNumber::List phoneNumbers() const; 660 PhoneNumber::List phoneNumbers() const;
657 661
658 /** 662 /**
659 Return list of phone numbers with a special type. 663 Return list of phone numbers with a special type.
660 */ 664 */
661 PhoneNumber::List phoneNumbers( int type ) const; 665 PhoneNumber::List phoneNumbers( int type ) const;
662 666
663 /** 667 /**
664 Return phone number with the given id. 668 Return phone number with the given id.
665 */ 669 */
666 PhoneNumber findPhoneNumber( const QString &id ) const; 670 PhoneNumber findPhoneNumber( const QString &id ) const;
667 671
668 /** 672 /**
669 Insert a key. If a key with the same id already exists 673 Insert a key. If a key with the same id already exists
670 in this addressee it is not duplicated. 674 in this addressee it is not duplicated.
671 */ 675 */
672 void insertKey( const Key &key ); 676 void insertKey( const Key &key );
673 677
674 /** 678 /**
675 Remove a key. If no key with the given id exists for this 679 Remove a key. If no key with the given id exists for this
676 addresse nothing happens. 680 addresse nothing happens.
677 */ 681 */
678 void removeKey( const Key &key ); 682 void removeKey( const Key &key );
679 683
680 /** 684 /**
681 Return key, which matches the given type. 685 Return key, which matches the given type.
682 If @p type == Key::Custom you can specify a string 686 If @p type == Key::Custom you can specify a string
683 that should match. If you leave the string empty, the first 687 that should match. If you leave the string empty, the first
684 key with a custom value is returned. 688 key with a custom value is returned.
685 */ 689 */
686 Key key( int type, QString customTypeString = QString::null ) const; 690 Key key( int type, QString customTypeString = QString::null ) const;
687 691
688 /** 692 /**
689 Return list of all keys. 693 Return list of all keys.
690 */ 694 */
691 Key::List keys() const; 695 Key::List keys() const;
692 696
693 /** 697 /**
694 Set the list of keys 698 Set the list of keys
695 @param keys The keys to be set. 699 @param keys The keys to be set.
696 */ 700 */
697 void setKeys( const Key::List& keys); 701 void setKeys( const Key::List& keys);
698 702
699 /** 703 /**
700 Return list of keys with a special type. 704 Return list of keys with a special type.
701 If @p type == Key::Custom you can specify a string 705 If @p type == Key::Custom you can specify a string
702 that should match. If you leave the string empty, all custom 706 that should match. If you leave the string empty, all custom
703 keys will be returned. 707 keys will be returned.
704 */ 708 */
705 Key::List keys( int type, QString customTypeString = QString::null ) const; 709 Key::List keys( int type, QString customTypeString = QString::null ) const;
706 710
707 /** 711 /**
708 Return key with the given id. 712 Return key with the given id.
709 */ 713 */
710 Key findKey( const QString &id ) const; 714 Key findKey( const QString &id ) const;
711 715
712 /** 716 /**
713 Insert an address. If an address with the same id already exists 717 Insert an address. If an address with the same id already exists
714 in this addressee it is not duplicated. 718 in this addressee it is not duplicated.
715 */ 719 */
716 void insertAddress( const Address &address ); 720 void insertAddress( const Address &address );
717 721
718 /** 722 /**
719 Remove address. If no address with the given id exists for this 723 Remove address. If no address with the given id exists for this
720 addresse nothing happens. 724 addresse nothing happens.
721 */ 725 */
722 void removeAddress( const Address &address ); 726 void removeAddress( const Address &address );
723 727
724 /** 728 /**
725 Return address, which matches the given type. 729 Return address, which matches the given type.
726 */ 730 */
727 Address address( int type ) const; 731 Address address( int type ) const;
728 732
729 /** 733 /**
730 Return list of all addresses. 734 Return list of all addresses.
731 */ 735 */
732 Address::List addresses() const; 736 Address::List addresses() const;
733 737
734 /** 738 /**
735 Return list of addresses with a special type. 739 Return list of addresses with a special type.
736 */ 740 */
737 Address::List addresses( int type ) const; 741 Address::List addresses( int type ) const;
738 742
739 /** 743 /**
740 Return address with the given id. 744 Return address with the given id.
741 */ 745 */
742 Address findAddress( const QString &id ) const; 746 Address findAddress( const QString &id ) const;
743 747
744 /** 748 /**
745 Insert category. If the category already exists it is not duplicated. 749 Insert category. If the category already exists it is not duplicated.
746 */ 750 */
747 void insertCategory( const QString & ); 751 void insertCategory( const QString & );
748 752
749 /** 753 /**
750 Remove category. 754 Remove category.
751 */ 755 */
752 void removeCategory( const QString & ); 756 void removeCategory( const QString & );
753 757
754 /** 758 /**
755 Return, if addressee has the given category. 759 Return, if addressee has the given category.
756 */ 760 */
757 bool hasCategory( const QString & ) const; 761 bool hasCategory( const QString & ) const;
758 762
759 /** 763 /**
760 Set categories to given value. 764 Set categories to given value.
761 */ 765 */
762 void setCategories( const QStringList & ); 766 void setCategories( const QStringList & );
763 767
764 /** 768 /**
765 Return list of all set categories. 769 Return list of all set categories.
766 */ 770 */
767 QStringList categories() const; 771 QStringList categories() const;
768 772
769 /** 773 /**
770 Insert custom entry. The entry is identified by the name of the inserting 774 Insert custom entry. The entry is identified by the name of the inserting
771 application and a unique name. If an entry with the given app and name 775 application and a unique name. If an entry with the given app and name
772 already exists its value is replaced with the new given value. 776 already exists its value is replaced with the new given value.
773 */ 777 */
774 void insertCustom( const QString &app, const QString &name, 778 void insertCustom( const QString &app, const QString &name,
775 const QString &value ); 779 const QString &value );
776 780
777 /** 781 /**
778 Remove custom entry. 782 Remove custom entry.
779 */ 783 */
780 void removeCustom( const QString &app, const QString &name ); 784 void removeCustom( const QString &app, const QString &name );
781 785
782 /** 786 /**
783 Return value of custom entry, identified by app and entry name. 787 Return value of custom entry, identified by app and entry name.
784 */ 788 */
785 QString custom( const QString &app, const QString &name ) const; 789 QString custom( const QString &app, const QString &name ) const;
786 790
787 /** 791 /**
788 Set all custom entries. 792 Set all custom entries.
789 */ 793 */
790 void setCustoms( const QStringList & ); 794 void setCustoms( const QStringList & );
791 795
792 /** 796 /**
793 Return list of all custom entries. 797 Return list of all custom entries.
794 */ 798 */
795 QStringList customs() const; 799 QStringList customs() const;
796 800
797 /** 801 /**
798 Parse full email address. The result is given back in fullName and email. 802 Parse full email address. The result is given back in fullName and email.
799 */ 803 */
800 static void parseEmailAddress( const QString &rawEmail, QString &fullName, 804 static void parseEmailAddress( const QString &rawEmail, QString &fullName,
801 QString &email ); 805 QString &email );
802 806
803 /** 807 /**
804 Debug output. 808 Debug output.
805 */ 809 */
806 void dump() const; 810 void dump() const;
807 811
808 /** 812 /**
809 Returns string representation of the addressee. 813 Returns string representation of the addressee.
810 */ 814 */
811 QString asString() const; 815 QString asString() const;
812 816
813 /** 817 /**
814 Set resource where the addressee is from. 818 Set resource where the addressee is from.
815 */ 819 */
816 void setResource( Resource *resource ); 820 void setResource( Resource *resource );
817 821
818 /** 822 /**
819 Return pointer to resource. 823 Return pointer to resource.
820 */ 824 */
821 Resource *resource() const; 825 Resource *resource() const;
822 826
823 /** 827 /**
824 Return resourcelabel. 828 Return resourcelabel.
825 */ 829 */
826 //US 830 //US
827 static QString resourceLabel(); 831 static QString resourceLabel();
828 static QString categoryLabel(); 832 static QString categoryLabel();
829 /** 833 /**
830 Mark addressee as changed. 834 Mark addressee as changed.
831 */ 835 */
832 void setChanged( bool value ); 836 void setChanged( bool value );
833 837
834 /** 838 /**
835 Return whether the addressee is changed. 839 Return whether the addressee is changed.
836 */ 840 */
837 bool changed() const; 841 bool changed() const;
838 842
839 void setTagged( bool value ); 843 void setTagged( bool value );
840 bool tagged() const; 844 bool tagged() const;
841 845
842 private: 846 private:
843 Addressee copy(); 847 Addressee copy();
844 void detach(); 848 void detach();
845 849
846 struct AddresseeData; 850 struct AddresseeData;
847 mutable KSharedPtr<AddresseeData> mData; 851 mutable KSharedPtr<AddresseeData> mData;
848}; 852};
849 853
850QDataStream &operator<<( QDataStream &, const Addressee & ); 854QDataStream &operator<<( QDataStream &, const Addressee & );
851QDataStream &operator>>( QDataStream &, Addressee & ); 855QDataStream &operator>>( QDataStream &, Addressee & );
852 856
853} 857}
854 858
855#endif 859#endif
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index ca21016..b503652 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -1,507 +1,525 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qdragobject.h> 24#include <qdragobject.h>
25#include <qevent.h> 25#include <qevent.h>
26#include <qiconview.h> 26#include <qiconview.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qstringlist.h> 28#include <qstringlist.h>
29#include <qregexp.h> 29#include <qregexp.h>
30#include <qapplication.h> 30#include <qapplication.h>
31 31
32#include <kabc/addressbook.h> 32#include <kabc/addressbook.h>
33#include <kabc/addressee.h> 33#include <kabc/addressee.h>
34#include <kconfig.h> 34#include <kconfig.h>
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37 37
38#include "kabprefs.h" 38#include "kabprefs.h"
39#include "viewmanager.h" 39#include "viewmanager.h"
40 40
41 41
42#include "kaddressbookcardview.h" 42#include "kaddressbookcardview.h"
43 43
44#ifndef KAB_EMBEDDED 44#ifndef KAB_EMBEDDED
45extern "C" { 45extern "C" {
46 void *init_libkaddrbk_cardview() 46 void *init_libkaddrbk_cardview()
47 { 47 {
48 return ( new CardViewFactory ); 48 return ( new CardViewFactory );
49 } 49 }
50} 50}
51#endif //KAB_EMBEDDED 51#endif //KAB_EMBEDDED
52 52
53//////////////////////////////// 53////////////////////////////////
54// AddresseeCardViewItem (internal class) 54// AddresseeCardViewItem (internal class)
55class AddresseeCardViewItem : public CardViewItem 55class AddresseeCardViewItem : public CardViewItem
56{ 56{
57 public: 57 public:
58 AddresseeCardViewItem(const KABC::Field::List &fields, 58 AddresseeCardViewItem(const KABC::Field::List &fields,
59 bool showEmptyFields, 59 bool showEmptyFields,
60 KABC::AddressBook *doc, const KABC::Addressee &a, 60 KABC::AddressBook *doc, const KABC::Addressee &a,
61 CardView *parent) 61 CardView *parent)
62 : CardViewItem(parent, a.realName() ), 62 : CardViewItem(parent, a.realName() ),
63 mFields( fields ), mShowEmptyFields(showEmptyFields), 63 mFields( fields ), mShowEmptyFields(showEmptyFields),
64 mDocument(doc), mAddressee(a) 64 mDocument(doc), mAddressee(a)
65 { 65 {
66 if ( mFields.isEmpty() ) { 66 if ( mFields.isEmpty() ) {
67 mFields = KABC::Field::defaultFields(); 67 mFields = KABC::Field::defaultFields();
68 } 68 }
69 refresh(); 69 refresh();
70 } 70 }
71 71
72 const KABC::Addressee &addressee() const { return mAddressee; } 72 const KABC::Addressee &addressee() const { return mAddressee; }
73 73
74 void refresh() 74 void refresh()
75 { 75 {
76 // Update our addressee, since it may have changed elsewhere 76 // Update our addressee, since it may have changed elsewhere
77 mAddressee = mDocument->findByUid(mAddressee.uid()); 77 mAddressee = mDocument->findByUid(mAddressee.uid());
78 78
79 if (!mAddressee.isEmpty()) 79 if (!mAddressee.isEmpty())
80 { 80 {
81 clearFields(); 81 clearFields();
82 82
83 // Try all the selected fields until we find one with text. 83 // Try all the selected fields until we find one with text.
84 // This will limit the number of unlabeled icons in the view 84 // This will limit the number of unlabeled icons in the view
85 KABC::Field::List::Iterator iter; 85 KABC::Field::List::Iterator iter;
86 for (iter = mFields.begin(); iter != mFields.end(); ++iter) 86 for (iter = mFields.begin(); iter != mFields.end(); ++iter)
87 { 87 {
88 // insert empty fields or not? not doing so saves a bit of memory and CPU 88 // insert empty fields or not? not doing so saves a bit of memory and CPU
89 // (during geometry calculations), but prevents having equally 89 // (during geometry calculations), but prevents having equally
90 // wide label columns in all cards, unless CardViewItem/CardView search 90 // wide label columns in all cards, unless CardViewItem/CardView search
91 // globally for the widest label. (anders) 91 // globally for the widest label. (anders)
92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) 92 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
93 insertField((*iter)->label(), (*iter)->value( mAddressee )); 93 insertField((*iter)->label(), (*iter)->value( mAddressee ));
94 } 94 }
95 95
96 // We might want to make this the first field. hmm... -mpilone 96 // We might want to make this the first field. hmm... -mpilone
97 setCaption( mAddressee.realName() ); 97 setCaption( mAddressee.realName() );
98 } 98 }
99 } 99 }
100 100
101 private: 101 private:
102 KABC::Field::List mFields; 102 KABC::Field::List mFields;
103 bool mShowEmptyFields; 103 bool mShowEmptyFields;
104 KABC::AddressBook *mDocument; 104 KABC::AddressBook *mDocument;
105 KABC::Addressee mAddressee; 105 KABC::Addressee mAddressee;
106}; 106};
107 107
108/////////////////////////////// 108///////////////////////////////
109// AddresseeCardView 109// AddresseeCardView
110 110
111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) 111AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
112 : CardView(parent, name) 112 : CardView(parent, name)
113{ 113{
114 setAcceptDrops(true); 114 setAcceptDrops(true);
115} 115}
116 116
117AddresseeCardView::~AddresseeCardView() 117AddresseeCardView::~AddresseeCardView()
118{ 118{
119} 119}
120void AddresseeCardView::printMe() 120void AddresseeCardView::printMe()
121{ 121{
122#ifdef DESKTOP_VERSION 122#ifdef DESKTOP_VERSION
123 QPrinter printer; 123 QPrinter printer;
124 if (!printer.setup() ) 124 if (!printer.setup() )
125 return; 125 return;
126 QPainter p; 126 QPainter p;
127 p.begin ( &printer ); 127 p.begin ( &printer );
128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); 128 QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
129 float dx, dy; 129 float dx, dy;
130 int wid = (m.width() * 9)/10; 130 int wid = (m.width() * 9)/10;
131 dx = (float) wid/(float)contentsWidth (); 131 dx = (float) wid/(float)contentsWidth ();
132 dy = (float)(m.height()) / (float)contentsHeight (); 132 dy = (float)(m.height()) / (float)contentsHeight ();
133 float scale; 133 float scale;
134 // scale to fit the width or height of the paper 134 // scale to fit the width or height of the paper
135 if ( dx < dy ) 135 if ( dx < dy )
136 scale = dx; 136 scale = dx;
137 else 137 else
138 scale = dy; 138 scale = dy;
139 p.translate( m.width()/10,0 ); 139 p.translate( m.width()/10,0 );
140 p.scale( scale, scale ); 140 p.scale( scale, scale );
141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); 141 drawContents ( &p, 0,0, contentsWidth (), contentsHeight () );
142 p.end(); 142 p.end();
143 repaint(); 143 repaint();
144#endif 144#endif
145} 145}
146 146
147 147
148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) 148void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
149{ 149{
150#ifndef KAB_EMBEDDED 150#ifndef KAB_EMBEDDED
151 if (QTextDrag::canDecode(e)) 151 if (QTextDrag::canDecode(e))
152 e->accept(); 152 e->accept();
153#else //KAB_EMBEDDED 153#else //KAB_EMBEDDED
154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); 154qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
155#endif //KAB_EMBEDDED 155#endif //KAB_EMBEDDED
156} 156}
157 157
158void AddresseeCardView::dropEvent(QDropEvent *e) 158void AddresseeCardView::dropEvent(QDropEvent *e)
159{ 159{
160 emit addresseeDropped(e); 160 emit addresseeDropped(e);
161} 161}
162 162
163void AddresseeCardView::startDrag() 163void AddresseeCardView::startDrag()
164{ 164{
165 emit startAddresseeDrag(); 165 emit startAddresseeDrag();
166} 166}
167 167
168 168
169/////////////////////////////// 169///////////////////////////////
170// KAddressBookCardView 170// KAddressBookCardView
171 171
172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, 172KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
173 QWidget *parent, const char *name ) 173 QWidget *parent, const char *name )
174 : KAddressBookView( ab, parent, name ) 174 : KAddressBookView( ab, parent, name )
175{ 175{
176 mShowEmptyFields = false; 176 mShowEmptyFields = false;
177 177
178 // Init the GUI 178 // Init the GUI
179 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 179 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
180 180
181 mCardView = new AddresseeCardView(viewWidget(), "mCardView"); 181 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
182 mCardView->setSelectionMode(CardView::Extended); 182 mCardView->setSelectionMode(CardView::Extended);
183 layout->addWidget(mCardView); 183 layout->addWidget(mCardView);
184 184
185 // Connect up the signals 185 // Connect up the signals
186 connect(mCardView, SIGNAL(executed(CardViewItem *)), 186 connect(mCardView, SIGNAL(executed(CardViewItem *)),
187 this, SLOT(addresseeExecuted(CardViewItem *))); 187 this, SLOT(addresseeExecuted(CardViewItem *)));
188 connect(mCardView, SIGNAL(selectionChanged()), 188 connect(mCardView, SIGNAL(selectionChanged()),
189 this, SLOT(addresseeSelected())); 189 this, SLOT(addresseeSelected()));
190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), 190 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
191 this, SIGNAL(dropped(QDropEvent*))); 191 this, SIGNAL(dropped(QDropEvent*)));
192 connect(mCardView, SIGNAL(startAddresseeDrag()), 192 connect(mCardView, SIGNAL(startAddresseeDrag()),
193 this, SIGNAL(startDrag())); 193 this, SIGNAL(startDrag()));
194 connect(this, SIGNAL(printView()), 194 connect(this, SIGNAL(printView()),
195 mCardView , SLOT(printMe())); 195 mCardView , SLOT(printMe()));
196} 196}
197 197
198KAddressBookCardView::~KAddressBookCardView() 198KAddressBookCardView::~KAddressBookCardView()
199{ 199{
200} 200}
201void KAddressBookCardView::setFocusAV() 201void KAddressBookCardView::setFocusAV()
202{ 202{
203 if ( mCardView ) 203 if ( mCardView )
204 mCardView->setFocus(); 204 mCardView->setFocus();
205 205
206} 206}
207void KAddressBookCardView::scrollUP() 207void KAddressBookCardView::scrollUP()
208{ 208{
209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 209 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
210 QApplication::postEvent( mCardView, ev ); 210 QApplication::postEvent( mCardView, ev );
211 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 ); 211 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 );
212 QApplication::postEvent( mCardView, ev ); 212 QApplication::postEvent( mCardView, ev );
213 213
214} 214}
215void KAddressBookCardView::scrollDOWN() 215void KAddressBookCardView::scrollDOWN()
216{ 216{
217 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 217 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
218 QApplication::postEvent( mCardView, ev ); 218 QApplication::postEvent( mCardView, ev );
219 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 ); 219 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 );
220 QApplication::postEvent( mCardView, ev ); 220 QApplication::postEvent( mCardView, ev );
221} 221}
222void KAddressBookCardView::readConfig(KConfig *config) 222void KAddressBookCardView::readConfig(KConfig *config)
223{ 223{
224 KAddressBookView::readConfig(config); 224 KAddressBookView::readConfig(config);
225 225
226 // costum colors? 226 // costum colors?
227 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 227 if ( config->readBoolEntry( "EnableCustomColors", false ) )
228 { 228 {
229 QPalette p( mCardView->palette() ); 229 QPalette p( mCardView->palette() );
230 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 230 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
231 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 231 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
232 c = p.color(QPalette::Normal, QColorGroup::Text ); 232 c = p.color(QPalette::Normal, QColorGroup::Text );
233 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 233 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
234 c = p.color(QPalette::Normal, QColorGroup::Button ); 234 c = p.color(QPalette::Normal, QColorGroup::Button );
235 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 235 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
236 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 236 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
237 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 237 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
238 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 238 c = p.color(QPalette::Normal, QColorGroup::Highlight );
239 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 239 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
240 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 240 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
241 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 241 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
242 mCardView->viewport()->setPalette( p ); 242 mCardView->viewport()->setPalette( p );
243 } 243 }
244 else 244 else
245 { 245 {
246 // needed if turned off during a session. 246 // needed if turned off during a session.
247 mCardView->viewport()->setPalette( mCardView->palette() ); 247 mCardView->viewport()->setPalette( mCardView->palette() );
248 } 248 }
249 249
250 //custom fonts? 250 //custom fonts?
251 QFont f( font() ); 251 QFont f( font() );
252 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 252 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
253 { 253 {
254 mCardView->setFont( config->readFontEntry( "TextFont", &f) ); 254 mCardView->setFont( config->readFontEntry( "TextFont", &f) );
255 f.setBold( true ); 255 f.setBold( true );
256 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 256 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
257 } 257 }
258 else 258 else
259 { 259 {
260 mCardView->setFont( f ); 260 mCardView->setFont( f );
261 f.setBold( true ); 261 f.setBold( true );
262 mCardView->setHeaderFont( f ); 262 mCardView->setHeaderFont( f );
263 } 263 }
264 264
265 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); 265 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
266 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", 266 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
267 true)); 267 true));
268 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); 268 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
269 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); 269 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
270 270
271 mCardView->setShowEmptyFields( mShowEmptyFields ); 271 mCardView->setShowEmptyFields( mShowEmptyFields );
272 272
273 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); 273 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
274 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); 274 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
275 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); 275 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
276 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); 276 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
277 277
278#if 0 278#if 0
279 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven 279 // LR KABPrefs::instance()->mHonorSingleClick is handled and fixed in cardviews contentsMouseDoubleClickEven
280 disconnect(mCardView, SIGNAL(executed(CardViewItem *)), 280 disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
281 this, SLOT(addresseeExecuted(CardViewItem *))); 281 this, SLOT(addresseeExecuted(CardViewItem *)));
282 282
283 if (KABPrefs::instance()->mHonorSingleClick) 283 if (KABPrefs::instance()->mHonorSingleClick)
284 connect(mCardView, SIGNAL(executed(CardViewItem *)), 284 connect(mCardView, SIGNAL(executed(CardViewItem *)),
285 this, SLOT(addresseeExecuted(CardViewItem *))); 285 this, SLOT(addresseeExecuted(CardViewItem *)));
286 else 286 else
287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 287 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
288 this, SLOT(addresseeExecuted(CardViewItem *))); 288 this, SLOT(addresseeExecuted(CardViewItem *)));
289#endif 289#endif
290 290
291 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), 291 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
292 this, SLOT(addresseeExecuted(CardViewItem *))); 292 this, SLOT(addresseeExecuted(CardViewItem *)));
293} 293}
294 294
295void KAddressBookCardView::writeConfig( KConfig *config ) 295void KAddressBookCardView::writeConfig( KConfig *config )
296{ 296{
297 config->writeEntry( "ItemWidth", mCardView->itemWidth() ); 297 config->writeEntry( "ItemWidth", mCardView->itemWidth() );
298 KAddressBookView::writeConfig( config ); 298 KAddressBookView::writeConfig( config );
299} 299}
300void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field ) 300void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
301{ 301{
302 mCardView->clear(); 302 mCardView->clear();
303 if ( s.isEmpty() || s == "*" ) { 303 if ( s.isEmpty() || s == "*" ) {
304 refresh(); 304 refresh();
305 return; 305 return;
306 } 306 }
307 QRegExp re = getRegExp( s ); 307 QRegExp re = getRegExp( s );
308 if (!re.isValid()) 308 if (!re.isValid())
309 return; 309 return;
310 mCardView->viewport()->setUpdatesEnabled( false ); 310 mCardView->viewport()->setUpdatesEnabled( false );
311 KABC::Addressee::List addresseeList = addressees(); 311 KABC::Addressee::List addresseeList = addressees();
312 KABC::Addressee::List::Iterator it; 312 KABC::Addressee::List::Iterator it;
313 if ( field ) { 313 if ( field ) {
314 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 314 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
315 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 315 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
316 continue; 316 continue;
317#if QT_VERSION >= 0x030000 317#if QT_VERSION >= 0x030000
318 if (re.search(field->value( *it ).lower()) == 0) 318 if (re.search(field->value( *it ).lower()) == 0)
319#else 319#else
320 if (re.match(field->value( *it ).lower()) == 0) 320 if (re.match(field->value( *it ).lower()) == 0)
321#endif 321#endif
322 new AddresseeCardViewItem(fields(), mShowEmptyFields, 322 new AddresseeCardViewItem(fields(), mShowEmptyFields,
323 addressBook(), *it, mCardView); 323 addressBook(), *it, mCardView);
324 324
325 } 325 }
326 } else { 326 } else {
327 KABC::Field::List fieldList = allFields(); 327 KABC::Field::List fieldList = allFields();
328 KABC::Field::List::ConstIterator fieldIt; 328 KABC::Field::List::ConstIterator fieldIt;
329 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 329 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
330 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 330 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
331 continue; 331 continue;
332 bool match = false;
332 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 333 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
333#if QT_VERSION >= 0x030000 334#if QT_VERSION >= 0x030000
334 if (re.search((*fieldIt)->value( *it ).lower()) == 0) 335 if (re.search((*fieldIt)->value( *it ).lower()) == 0)
335#else 336#else
336 if (re.match((*fieldIt)->value( *it ).lower()) == 0) 337 if (re.match((*fieldIt)->value( *it ).lower()) == 0)
337#endif 338#endif
338 { 339 {
339 new AddresseeCardViewItem(fields(), mShowEmptyFields, 340 new AddresseeCardViewItem(fields(), mShowEmptyFields,
340 addressBook(), *it, mCardView); 341 addressBook(), *it, mCardView);
342 match = true;
341 break; 343 break;
342 } 344 }
343 } 345 }
346 if ( ! match ) {
347 if ( (*it).matchPhoneNumber( &re ) ) {
348 new AddresseeCardViewItem(fields(), mShowEmptyFields,
349 addressBook(), *it, mCardView);
350 match = true;
351 break;
352 }
353 }
354 if ( ! match ) {
355 if ( (*it).matchAddress( &re ) ) {
356 new AddresseeCardViewItem(fields(), mShowEmptyFields,
357 addressBook(), *it, mCardView);
358 match = true;
359 break;
360 }
361 }
344 } 362 }
345 } 363 }
346 mCardView->viewport()->setUpdatesEnabled( true ); 364 mCardView->viewport()->setUpdatesEnabled( true );
347 mCardView->viewport()->update(); 365 mCardView->viewport()->update();
348 if ( mCardView->firstItem() ) { 366 if ( mCardView->firstItem() ) {
349 mCardView->setCurrentItem ( mCardView->firstItem() ); 367 mCardView->setCurrentItem ( mCardView->firstItem() );
350 mCardView->setSelected ( mCardView->firstItem() , true ); 368 mCardView->setSelected ( mCardView->firstItem() , true );
351 } 369 }
352 else 370 else
353 emit selected(QString::null); 371 emit selected(QString::null);
354} 372}
355QStringList KAddressBookCardView::selectedUids() 373QStringList KAddressBookCardView::selectedUids()
356{ 374{
357 QStringList uidList; 375 QStringList uidList;
358 CardViewItem *item; 376 CardViewItem *item;
359 AddresseeCardViewItem *aItem; 377 AddresseeCardViewItem *aItem;
360 378
361 for (item = mCardView->firstItem(); item; item = item->nextItem()) 379 for (item = mCardView->firstItem(); item; item = item->nextItem())
362 { 380 {
363 if (item->isSelected()) 381 if (item->isSelected())
364 { 382 {
365#ifndef KAB_EMBEDDED 383#ifndef KAB_EMBEDDED
366 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 384 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
367#else //KAB_EMBEDDED 385#else //KAB_EMBEDDED
368 aItem = (AddresseeCardViewItem*)(item); 386 aItem = (AddresseeCardViewItem*)(item);
369#endif //KAB_EMBEDDED 387#endif //KAB_EMBEDDED
370 if (aItem) 388 if (aItem)
371 uidList << aItem->addressee().uid(); 389 uidList << aItem->addressee().uid();
372 } 390 }
373 } 391 }
374 392
375 return uidList; 393 return uidList;
376} 394}
377 395
378void KAddressBookCardView::refresh(QString uid) 396void KAddressBookCardView::refresh(QString uid)
379{ 397{
380 CardViewItem *item; 398 CardViewItem *item;
381 AddresseeCardViewItem *aItem; 399 AddresseeCardViewItem *aItem;
382 400
383 if (uid.isNull()) 401 if (uid.isNull())
384 { 402 {
385 // Rebuild the view 403 // Rebuild the view
386 mCardView->viewport()->setUpdatesEnabled( false ); 404 mCardView->viewport()->setUpdatesEnabled( false );
387 mCardView->clear(); 405 mCardView->clear();
388 406
389 KABC::Addressee::List addresseeList = addressees(); 407 KABC::Addressee::List addresseeList = addressees();
390 KABC::Addressee::List::Iterator iter; 408 KABC::Addressee::List::Iterator iter;
391 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) 409 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
392 { 410 {
393 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) 411 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
394 continue; 412 continue;
395 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, 413 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
396 addressBook(), *iter, mCardView); 414 addressBook(), *iter, mCardView);
397 } 415 }
398 mCardView->viewport()->setUpdatesEnabled( true ); 416 mCardView->viewport()->setUpdatesEnabled( true );
399 mCardView->viewport()->update(); 417 mCardView->viewport()->update();
400 418
401 // by default nothing is selected 419 // by default nothing is selected
402 emit selected(QString::null); 420 emit selected(QString::null);
403 } 421 }
404 else 422 else
405 { 423 {
406 // Try to find the one to refresh 424 // Try to find the one to refresh
407 bool found = false; 425 bool found = false;
408 for (item = mCardView->firstItem(); item && !found; 426 for (item = mCardView->firstItem(); item && !found;
409 item = item->nextItem()) 427 item = item->nextItem())
410 { 428 {
411#ifndef KAB_EMBEDDED 429#ifndef KAB_EMBEDDED
412 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 430 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
413#else //KAB_EMBEDDED 431#else //KAB_EMBEDDED
414 aItem = (AddresseeCardViewItem*)(item); 432 aItem = (AddresseeCardViewItem*)(item);
415#endif //KAB_EMBEDDED 433#endif //KAB_EMBEDDED
416 434
417 if ((aItem) && (aItem->addressee().uid() == uid)) 435 if ((aItem) && (aItem->addressee().uid() == uid))
418 { 436 {
419 aItem->refresh(); 437 aItem->refresh();
420 found = true; 438 found = true;
421 } 439 }
422 } 440 }
423 } 441 }
424} 442}
425 443
426void KAddressBookCardView::setSelected(QString uid, bool selected) 444void KAddressBookCardView::setSelected(QString uid, bool selected)
427{ 445{
428 CardViewItem *item; 446 CardViewItem *item;
429 AddresseeCardViewItem *aItem; 447 AddresseeCardViewItem *aItem;
430 448
431 if (uid.isNull()) 449 if (uid.isNull())
432 { 450 {
433 mCardView->selectAll(selected); 451 mCardView->selectAll(selected);
434 } 452 }
435 else 453 else
436 { 454 {
437 bool found = false; 455 bool found = false;
438 for (item = mCardView->firstItem(); item && !found; 456 for (item = mCardView->firstItem(); item && !found;
439 item = item->nextItem()) 457 item = item->nextItem())
440 { 458 {
441#ifndef KAB_EMBEDDED 459#ifndef KAB_EMBEDDED
442 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 460 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
443#else //KAB_EMBEDDED 461#else //KAB_EMBEDDED
444 aItem = (AddresseeCardViewItem*)(item); 462 aItem = (AddresseeCardViewItem*)(item);
445#endif //KAB_EMBEDDED 463#endif //KAB_EMBEDDED
446 464
447 if ((aItem) && (aItem->addressee().uid() == uid)) 465 if ((aItem) && (aItem->addressee().uid() == uid))
448 { 466 {
449 mCardView->setSelected(aItem, selected); 467 mCardView->setSelected(aItem, selected);
450 mCardView->ensureItemVisible(item); 468 mCardView->ensureItemVisible(item);
451 found = true; 469 found = true;
452 } 470 }
453 } 471 }
454 } 472 }
455} 473}
456 474
457//US added an additional method without parameter 475//US added an additional method without parameter
458void KAddressBookCardView::setSelected() 476void KAddressBookCardView::setSelected()
459{ 477{
460 setSelected(QString::null, true); 478 setSelected(QString::null, true);
461} 479}
462 480
463void KAddressBookCardView::addresseeExecuted(CardViewItem *item) 481void KAddressBookCardView::addresseeExecuted(CardViewItem *item)
464{ 482{
465#ifndef KAB_EMBEDDED 483#ifndef KAB_EMBEDDED
466 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); 484 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item);
467#else //KAB_EMBEDDED 485#else //KAB_EMBEDDED
468 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); 486 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item);
469#endif //KAB_EMBEDDED 487#endif //KAB_EMBEDDED
470 if (aItem) 488 if (aItem)
471 { 489 {
472 //kdDebug()<<"... even has a valid item:)"<<endl; 490 //kdDebug()<<"... even has a valid item:)"<<endl;
473 emit executed(aItem->addressee().uid()); 491 emit executed(aItem->addressee().uid());
474 } 492 }
475} 493}
476 494
477void KAddressBookCardView::addresseeSelected() 495void KAddressBookCardView::addresseeSelected()
478{ 496{
479 CardViewItem *item; 497 CardViewItem *item;
480 AddresseeCardViewItem *aItem; 498 AddresseeCardViewItem *aItem;
481 499
482 bool found = false; 500 bool found = false;
483 for (item = mCardView->firstItem(); item && !found; 501 for (item = mCardView->firstItem(); item && !found;
484 item = item->nextItem()) 502 item = item->nextItem())
485 { 503 {
486 if (item->isSelected()) 504 if (item->isSelected())
487 { 505 {
488#ifndef KAB_EMBEDDED 506#ifndef KAB_EMBEDDED
489 aItem = dynamic_cast<AddresseeCardViewItem*>(item); 507 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
490#else //KAB_EMBEDDED 508#else //KAB_EMBEDDED
491 aItem = (AddresseeCardViewItem*)(item); 509 aItem = (AddresseeCardViewItem*)(item);
492#endif //KAB_EMBEDDED 510#endif //KAB_EMBEDDED
493 if ( aItem ) 511 if ( aItem )
494 { 512 {
495 emit selected(aItem->addressee().uid()); 513 emit selected(aItem->addressee().uid());
496 found = true; 514 found = true;
497 } 515 }
498 } 516 }
499 } 517 }
500 518
501 if (!found) 519 if (!found)
502 emit selected(QString::null); 520 emit selected(QString::null);
503 521
504} 522}
505#ifndef KAB_EMBEDDED 523#ifndef KAB_EMBEDDED
506#include "kaddressbookcardview.moc" 524#include "kaddressbookcardview.moc"
507#endif //KAB_EMBEDDED 525#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp
index 4bbdf1d..d6ddec3 100644
--- a/kaddressbook/views/kaddressbookiconview.cpp
+++ b/kaddressbook/views/kaddressbookiconview.cpp
@@ -1,452 +1,481 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef KAB_EMBEDDED 24#ifndef KAB_EMBEDDED
25#include <qiconview.h> 25#include <qiconview.h>
26#include <qstringlist.h> 26#include <qstringlist.h>
27 27
28#include <kabc/addressee.h> 28#include <kabc/addressee.h>
29#include <kconfig.h> 29#include <kconfig.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kiconloader.h> 32#include <kiconloader.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#else //KAB_EMBEDDED 35#else //KAB_EMBEDDED
36#endif //KAB_EMBEDDED 36#endif //KAB_EMBEDDED
37 37
38#include <kabc/addressbook.h> 38#include <kabc/addressbook.h>
39#include "kabprefs.h" 39#include "kabprefs.h"
40#include "viewmanager.h" 40#include "viewmanager.h"
41#include "kaddressbookiconview.h" 41#include "kaddressbookiconview.h"
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qapplication.h> 44#include <qapplication.h>
45#include <kglobal.h> 45#include <kglobal.h>
46/*US transfered to the headerfile 46/*US transfered to the headerfile
47class IconViewFactory : public ViewFactory 47class IconViewFactory : public ViewFactory
48{ 48{
49 public: 49 public:
50 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) 50 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
51 { 51 {
52 return new KAddressBookIconView( ab, parent, name ); 52 return new KAddressBookIconView( ab, parent, name );
53 } 53 }
54 54
55 QString type() const { return "Icon"; } 55 QString type() const { return "Icon"; }
56 56
57 QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } 57 QString description() const { return i18n( "Icons represent contacts. Very simple view." ); }
58}; 58};
59 59
60*/ 60*/
61 61
62extern "C" { 62extern "C" {
63 void *init_libkaddrbk_iconview() 63 void *init_libkaddrbk_iconview()
64 { 64 {
65 return ( new IconViewFactory ); 65 return ( new IconViewFactory );
66 } 66 }
67} 67}
68 68
69//////////////////////////////// 69////////////////////////////////
70// AddresseeIconView (internal class) 70// AddresseeIconView (internal class)
71#ifndef KAB_EMBEDDED 71#ifndef KAB_EMBEDDED
72AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) 72AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
73 : KIconView(parent, name) 73 : KIconView(parent, name)
74#else //KAB_EMBEDDED 74#else //KAB_EMBEDDED
75AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) 75AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
76 : QIconView(parent, name) 76 : QIconView(parent, name)
77#endif //KAB_EMBEDDED 77#endif //KAB_EMBEDDED
78 78
79{ 79{
80 setSelectionMode( QIconView::Extended ); 80 setSelectionMode( QIconView::Extended );
81 setResizeMode( QIconView::Adjust ); 81 setResizeMode( QIconView::Adjust );
82 setWordWrapIconText( true ); 82 setWordWrapIconText( true );
83 setGridX( 100 ); 83 setGridX( 100 );
84 setItemsMovable(false); 84 setItemsMovable(false);
85 setSorting(true, true); 85 setSorting(true, true);
86 86
87 87
88//US ??? setMode( KIconView::Select ); 88//US ??? setMode( KIconView::Select );
89 89
90#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
91 91
92 connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)), 92 connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)),
93 this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&))); 93 this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&)));
94#endif //KAB_EMBEDDED 94#endif //KAB_EMBEDDED
95} 95}
96 96
97AddresseeIconView::~AddresseeIconView() 97AddresseeIconView::~AddresseeIconView()
98{ 98{
99} 99}
100 100
101 101
102void AddresseeIconView::itemDropped(QDropEvent *e, 102void AddresseeIconView::itemDropped(QDropEvent *e,
103 const QValueList<QIconDragItem> &) 103 const QValueList<QIconDragItem> &)
104{ 104{
105 emit addresseeDropped(e); 105 emit addresseeDropped(e);
106} 106}
107 107
108QDragObject *AddresseeIconView::dragObject() 108QDragObject *AddresseeIconView::dragObject()
109{ 109{
110 emit startAddresseeDrag(); 110 emit startAddresseeDrag();
111 111
112 // We never want IconView to start the drag 112 // We never want IconView to start the drag
113 return 0; 113 return 0;
114} 114}
115//////////////////////////////// 115////////////////////////////////
116// AddresseeIconViewItem (internal class) 116// AddresseeIconViewItem (internal class)
117#ifndef KAB_EMBEDDED 117#ifndef KAB_EMBEDDED
118class AddresseeIconViewItem : public KIconViewItem 118class AddresseeIconViewItem : public KIconViewItem
119#else //KAB_EMBEDDED 119#else //KAB_EMBEDDED
120class AddresseeIconViewItem : public QIconViewItem 120class AddresseeIconViewItem : public QIconViewItem
121#endif //KAB_EMBEDDED 121#endif //KAB_EMBEDDED
122{ 122{
123 public: 123 public:
124#ifndef KAB_EMBEDDED 124#ifndef KAB_EMBEDDED
125 AddresseeIconViewItem(const KABC::Field::List &fields, 125 AddresseeIconViewItem(const KABC::Field::List &fields,
126 KABC::AddressBook *doc, const KABC::Addressee &a, 126 KABC::AddressBook *doc, const KABC::Addressee &a,
127 QIconView *parent) 127 QIconView *parent)
128 : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) 128 : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
129#else //KAB_EMBEDDED 129#else //KAB_EMBEDDED
130 AddresseeIconViewItem(const KABC::Field::List &fields, 130 AddresseeIconViewItem(const KABC::Field::List &fields,
131 KABC::AddressBook *doc, const KABC::Addressee &a, 131 KABC::AddressBook *doc, const KABC::Addressee &a,
132 QIconView *parent) 132 QIconView *parent)
133 : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) 133 : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
134#endif //KAB_EMBEDDED 134#endif //KAB_EMBEDDED
135 { 135 {
136 if ( mFields.isEmpty() ) { 136 if ( mFields.isEmpty() ) {
137 mFields = KABC::Field::defaultFields(); 137 mFields = KABC::Field::defaultFields();
138 } 138 }
139 refresh(); 139 refresh();
140 } 140 }
141 141
142 const KABC::Addressee &addressee() const { return mAddressee; } 142 const KABC::Addressee &addressee() const { return mAddressee; }
143 143
144 void refresh() 144 void refresh()
145 { 145 {
146 // Update our addressee, since it may have changed elsewhere 146 // Update our addressee, since it may have changed elsewhere
147 mAddressee = mDocument->findByUid(mAddressee.uid()); 147 mAddressee = mDocument->findByUid(mAddressee.uid());
148 148
149 if (!mAddressee.isEmpty()) 149 if (!mAddressee.isEmpty())
150 setText( mAddressee.givenName() + " " + mAddressee.familyName() ); 150 setText( mAddressee.givenName() + " " + mAddressee.familyName() );
151 151
152 QPixmap icon; 152 QPixmap icon;
153 QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) ); 153
154 KABC::Picture pic = mAddressee.photo(); 154 KABC::Picture pic = mAddressee.photo();
155 if ( pic.data().isNull() ) 155 if ( pic.data().isNull() )
156 pic = mAddressee.logo(); 156 pic = mAddressee.logo();
157 157
158 if ( pic.isIntern() && !pic.data().isNull() ) { 158 if ( pic.isIntern() && !pic.data().isNull() ) {
159 QImage img = pic.data(); 159 QImage img = pic.data();
160#ifndef KAB_EMBEDDED 160#ifndef KAB_EMBEDDED
161 if ( img.width() > img.height() ) 161 if ( img.width() > img.height() )
162 icon = img.scaleWidth( 32 ); 162 icon = img.scaleWidth( 32 );
163 else 163 else
164 icon = img.scaleHeight( 32 ); 164 icon = img.scaleHeight( 32 );
165#else //KAB_EMBEDDED 165#else //KAB_EMBEDDED
166
167 int wid = pic.data().width();
168 int hei = pic.data().height();
169 int max = 48;
170 if ( wid > max || hei > max ) {
171 if ( wid > hei ) {
172 hei = (hei*max)/wid;
173 wid = max;
174 } else {
175 wid = (wid*max)/hei;
176 hei = max;
177 }
178 }
166 qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor"); 179 qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor");
167 icon.convertFromImage(img.smoothScale(32, 32)); 180 icon.convertFromImage(img.smoothScale(wid, hei));
168#endif //KAB_EMBEDDED 181#endif //KAB_EMBEDDED
169 182
170 } else 183 } else {
171 icon = defaultIcon; 184 icon = KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 );
172 185 }
173 setPixmap( icon ); 186 setPixmap( icon );
174 } 187 }
175 188
176 private: 189 private:
177 KABC::Field::List mFields; 190 KABC::Field::List mFields;
178 KABC::AddressBook *mDocument; 191 KABC::AddressBook *mDocument;
179 KABC::Addressee mAddressee; 192 KABC::Addressee mAddressee;
180}; 193};
181 194
182/////////////////////////////// 195///////////////////////////////
183// KAddressBookView 196// KAddressBookView
184 197
185KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab, 198KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
186 QWidget *parent, const char *name) 199 QWidget *parent, const char *name)
187 : KAddressBookView( ab, parent, name ) 200 : KAddressBookView( ab, parent, name )
188{ 201{
189 // Init the GUI 202 // Init the GUI
190 QVBoxLayout *layout = new QVBoxLayout(viewWidget()); 203 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
191 204
192 mIconView = new AddresseeIconView(viewWidget(), "mIconView"); 205 mIconView = new AddresseeIconView(viewWidget(), "mIconView");
193 layout->addWidget(mIconView); 206 layout->addWidget(mIconView);
194 207
195 // Connect up the signals 208 // Connect up the signals
196 209
197//US method executed is part of KIconView 210//US method executed is part of KIconView
198//US connect(mIconView, SIGNAL(executed(QIconViewItem *)), 211//US connect(mIconView, SIGNAL(executed(QIconViewItem *)),
199//US this, SLOT(addresseeExecuted(QIconViewItem *))); 212//US this, SLOT(addresseeExecuted(QIconViewItem *)));
200 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 213 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
201 this, SLOT(addresseeExecuted(QIconViewItem *))); 214 this, SLOT(addresseeExecuted(QIconViewItem *)));
202 215
203 connect(mIconView, SIGNAL(selectionChanged()), 216 connect(mIconView, SIGNAL(selectionChanged()),
204 this, SLOT(addresseeSelected())); 217 this, SLOT(addresseeSelected()));
205 connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)), 218 connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)),
206 this, SIGNAL(dropped(QDropEvent*))); 219 this, SIGNAL(dropped(QDropEvent*)));
207 connect(mIconView, SIGNAL(startAddresseeDrag()), 220 connect(mIconView, SIGNAL(startAddresseeDrag()),
208 this, SIGNAL(startDrag())); 221 this, SIGNAL(startDrag()));
209} 222}
210 223
211KAddressBookIconView::~KAddressBookIconView() 224KAddressBookIconView::~KAddressBookIconView()
212{ 225{
213} 226}
214void KAddressBookIconView::setFocusAV() 227void KAddressBookIconView::setFocusAV()
215{ 228{
216 if ( mIconView ) 229 if ( mIconView )
217 mIconView->setFocus(); 230 mIconView->setFocus();
218} 231}
219 232
220 233
221void KAddressBookIconView::scrollUP() 234void KAddressBookIconView::scrollUP()
222{ 235{
223 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 236 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
224 QApplication::postEvent( mIconView, ev ); 237 QApplication::postEvent( mIconView, ev );
225} 238}
226void KAddressBookIconView::scrollDOWN() 239void KAddressBookIconView::scrollDOWN()
227{ 240{
228 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 241 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
229 QApplication::postEvent( mIconView, ev ); 242 QApplication::postEvent( mIconView, ev );
230} 243}
231void KAddressBookIconView::readConfig(KConfig *config) 244void KAddressBookIconView::readConfig(KConfig *config)
232{ 245{
233 KAddressBookView::readConfig(config); 246 KAddressBookView::readConfig(config);
234 247
235//US method executed is part of KIconView 248//US method executed is part of KIconView
236//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), 249//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)),
237//US this, SLOT(addresseeExecuted(QIconViewItem *))); 250//US this, SLOT(addresseeExecuted(QIconViewItem *)));
238 disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 251 disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
239 this, SLOT(addresseeExecuted(QIconViewItem *))); 252 this, SLOT(addresseeExecuted(QIconViewItem *)));
240 253
241//US method executed is part of KIconView. Use selectionChanged instead 254//US method executed is part of KIconView. Use selectionChanged instead
242/*US 255/*US
243 if (KABPrefs::instance()->mHonorSingleClick) 256 if (KABPrefs::instance()->mHonorSingleClick)
244 connect(mIconView, SIGNAL(executed(QIconViewItem *)), 257 connect(mIconView, SIGNAL(executed(QIconViewItem *)),
245 this, SLOT(addresseeExecuted(QIconViewItem *))); 258 this, SLOT(addresseeExecuted(QIconViewItem *)));
246 else 259 else
247 connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), 260 connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)),
248 this, SLOT(addresseeExecuted(QIconViewItem *))); 261 this, SLOT(addresseeExecuted(QIconViewItem *)));
249*/ 262*/
250 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), 263 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
251 this, SLOT(addresseeExecuted(QIconViewItem *))); 264 this, SLOT(addresseeExecuted(QIconViewItem *)));
252 265
253} 266}
254void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field ) 267void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
255{ 268{
256 mIconView->clear(); 269 mIconView->clear();
257 mIconList.clear(); 270 mIconList.clear();
258 if ( s.isEmpty() || s == "*" ) { 271 if ( s.isEmpty() || s == "*" ) {
259 refresh(); 272 refresh();
260 return; 273 return;
261 } 274 }
262 QRegExp re = getRegExp( s ); 275 QRegExp re = getRegExp( s );
263 if (!re.isValid()) 276 if (!re.isValid())
264 return; 277 return;
265 KABC::Addressee::List addresseeList = addressees(); 278 KABC::Addressee::List addresseeList = addressees();
266 KABC::Addressee::List::Iterator it; 279 KABC::Addressee::List::Iterator it;
267 if ( field ) { 280 if ( field ) {
268 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 281 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
269 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 282 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
270 continue; 283 continue;
271#if QT_VERSION >= 0x030000 284#if QT_VERSION >= 0x030000
272 if (re.search(field->value( *it ).lower()) == 0) 285 if (re.search(field->value( *it ).lower()) == 0)
273#else 286#else
274 if (re.match(field->value( *it ).lower()) == 0) 287 if (re.match(field->value( *it ).lower()) == 0)
275#endif 288#endif
276 mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); 289 mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
277 290
278 291
279 } 292 }
280 } else { 293 } else {
281 KABC::Field::List fieldList = allFields(); 294 KABC::Field::List fieldList = allFields();
282 KABC::Field::List::ConstIterator fieldIt; 295 KABC::Field::List::ConstIterator fieldIt;
283 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 296 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
284 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 297 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
285 continue; 298 continue;
299 bool match = false;
286 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 300 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
287#if QT_VERSION >= 0x030000 301#if QT_VERSION >= 0x030000
288 if (re.search((*fieldIt)->value( *it ).lower()) == 0) 302 if (re.search((*fieldIt)->value( *it ).lower()) == 0)
289#else 303#else
290 if (re.match((*fieldIt)->value( *it ).lower()) == 0) 304 if (re.match((*fieldIt)->value( *it ).lower()) == 0)
291#endif 305#endif
292 { 306 {
293 mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView )); 307 mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
308 match = true;
294 break; 309 break;
295 } 310 }
311 }
312 if ( ! match ) {
313 if ( (*it).matchPhoneNumber( &re ) ) {
314 mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
315 match = true;
316 break;
317 }
318 }
319 if ( ! match ) {
320 if ( (*it).matchAddress( &re ) ) {
321 mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
322 match = true;
323 break;
324 }
296 } 325 }
297 } 326 }
298 } 327 }
299 mIconView->arrangeItemsInGrid( true ); 328 mIconView->arrangeItemsInGrid( true );
300 if ( mIconView->firstItem() ) { 329 if ( mIconView->firstItem() ) {
301 mIconView->setCurrentItem ( mIconView->firstItem() ); 330 mIconView->setCurrentItem ( mIconView->firstItem() );
302 mIconView->setSelected ( mIconView->firstItem() , true ); 331 mIconView->setSelected ( mIconView->firstItem() , true );
303 } 332 }
304 else 333 else
305 emit selected(QString::null); 334 emit selected(QString::null);
306} 335}
307QStringList KAddressBookIconView::selectedUids() 336QStringList KAddressBookIconView::selectedUids()
308{ 337{
309 QStringList uidList; 338 QStringList uidList;
310 QIconViewItem *item; 339 QIconViewItem *item;
311 AddresseeIconViewItem *aItem; 340 AddresseeIconViewItem *aItem;
312 341
313 for (item = mIconView->firstItem(); item; item = item->nextItem()) 342 for (item = mIconView->firstItem(); item; item = item->nextItem())
314 { 343 {
315 if (item->isSelected()) 344 if (item->isSelected())
316 { 345 {
317#ifndef KAB_EMBEDDED 346#ifndef KAB_EMBEDDED
318 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 347 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
319#else //KAB_EMBEDDED 348#else //KAB_EMBEDDED
320 aItem = (AddresseeIconViewItem*)(item); 349 aItem = (AddresseeIconViewItem*)(item);
321#endif //KAB_EMBEDDED 350#endif //KAB_EMBEDDED
322 if (aItem) 351 if (aItem)
323 uidList << aItem->addressee().uid(); 352 uidList << aItem->addressee().uid();
324 } 353 }
325 } 354 }
326 355
327 return uidList; 356 return uidList;
328} 357}
329 358
330void KAddressBookIconView::refresh(QString uid) 359void KAddressBookIconView::refresh(QString uid)
331{ 360{
332 QIconViewItem *item; 361 QIconViewItem *item;
333 AddresseeIconViewItem *aItem; 362 AddresseeIconViewItem *aItem;
334 363
335 if ( uid.isNull() ) { 364 if ( uid.isNull() ) {
336 // Rebuild the view 365 // Rebuild the view
337 mIconView->clear(); 366 mIconView->clear();
338 mIconList.clear(); 367 mIconList.clear();
339 368
340 KABC::Addressee::List addresseeList = addressees(); 369 KABC::Addressee::List addresseeList = addressees();
341 KABC::Addressee::List::Iterator iter; 370 KABC::Addressee::List::Iterator iter;
342 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) { 371 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) {
343 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) 372 if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") )
344 continue; 373 continue;
345 aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView ); 374 aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView );
346 } 375 }
347 376
348 mIconView->arrangeItemsInGrid( true ); 377 mIconView->arrangeItemsInGrid( true );
349 378
350 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) 379 for ( item = mIconView->firstItem(); item; item = item->nextItem() )
351 { 380 {
352#ifndef KAB_EMBEDDED 381#ifndef KAB_EMBEDDED
353 AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item ); 382 AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item );
354#else //KAB_EMBEDDED 383#else //KAB_EMBEDDED
355 AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item ); 384 AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item );
356#endif //KAB_EMBEDDED 385#endif //KAB_EMBEDDED
357 mIconList.append( aivi ); 386 mIconList.append( aivi );
358 } 387 }
359 388
360 } else { 389 } else {
361 // Try to find the one to refresh 390 // Try to find the one to refresh
362 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { 391 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) {
363#ifndef KAB_EMBEDDED 392#ifndef KAB_EMBEDDED
364 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 393 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
365#else //KAB_EMBEDDED 394#else //KAB_EMBEDDED
366 aItem = (AddresseeIconViewItem*)(item); 395 aItem = (AddresseeIconViewItem*)(item);
367#endif //KAB_EMBEDDED 396#endif //KAB_EMBEDDED
368 if ((aItem) && (aItem->addressee().uid() == uid)) { 397 if ((aItem) && (aItem->addressee().uid() == uid)) {
369 aItem->refresh(); 398 aItem->refresh();
370 mIconView->arrangeItemsInGrid( true ); 399 mIconView->arrangeItemsInGrid( true );
371 return; 400 return;
372 } 401 }
373 } 402 }
374 refresh( QString::null ); 403 refresh( QString::null );
375 } 404 }
376} 405}
377 406
378void KAddressBookIconView::setSelected(QString uid, bool selected) 407void KAddressBookIconView::setSelected(QString uid, bool selected)
379{ 408{
380 QIconViewItem *item; 409 QIconViewItem *item;
381 AddresseeIconViewItem *aItem; 410 AddresseeIconViewItem *aItem;
382 411
383 if (uid.isNull()) 412 if (uid.isNull())
384 { 413 {
385 mIconView->selectAll(selected); 414 mIconView->selectAll(selected);
386 } 415 }
387 else 416 else
388 { 417 {
389 bool found = false; 418 bool found = false;
390 for (item = mIconView->firstItem(); item && !found; 419 for (item = mIconView->firstItem(); item && !found;
391 item = item->nextItem()) 420 item = item->nextItem())
392 { 421 {
393#ifndef KAB_EMBEDDED 422#ifndef KAB_EMBEDDED
394 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 423 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
395#else //KAB_EMBEDDED 424#else //KAB_EMBEDDED
396 aItem = (AddresseeIconViewItem*)(item); 425 aItem = (AddresseeIconViewItem*)(item);
397#endif //KAB_EMBEDDED 426#endif //KAB_EMBEDDED
398 427
399 if ((aItem) && (aItem->addressee().uid() == uid)) 428 if ((aItem) && (aItem->addressee().uid() == uid))
400 { 429 {
401 mIconView->setSelected(aItem, selected); 430 mIconView->setSelected(aItem, selected);
402 mIconView->ensureItemVisible( aItem ); 431 mIconView->ensureItemVisible( aItem );
403 found = true; 432 found = true;
404 } 433 }
405 } 434 }
406 } 435 }
407} 436}
408 437
409void KAddressBookIconView::addresseeExecuted(QIconViewItem *item) 438void KAddressBookIconView::addresseeExecuted(QIconViewItem *item)
410{ 439{
411#ifndef KAB_EMBEDDED 440#ifndef KAB_EMBEDDED
412 AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item); 441 AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item);
413#else //KAB_EMBEDDED 442#else //KAB_EMBEDDED
414 AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item); 443 AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item);
415#endif //KAB_EMBEDDED 444#endif //KAB_EMBEDDED
416 445
417 if (aItem) { 446 if (aItem) {
418 emit executed(aItem->addressee().uid()); 447 emit executed(aItem->addressee().uid());
419 } 448 }
420} 449}
421 450
422void KAddressBookIconView::addresseeSelected() 451void KAddressBookIconView::addresseeSelected()
423{ 452{
424 QIconViewItem *item; 453 QIconViewItem *item;
425 AddresseeIconViewItem *aItem; 454 AddresseeIconViewItem *aItem;
426 455
427 bool found = false; 456 bool found = false;
428 for (item = mIconView->firstItem(); item && !found; 457 for (item = mIconView->firstItem(); item && !found;
429 item = item->nextItem()) 458 item = item->nextItem())
430 { 459 {
431 if (item->isSelected()) 460 if (item->isSelected())
432 { 461 {
433#ifndef KAB_EMBEDDED 462#ifndef KAB_EMBEDDED
434 aItem = dynamic_cast<AddresseeIconViewItem*>(item); 463 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
435#else //KAB_EMBEDDED 464#else //KAB_EMBEDDED
436 aItem = (AddresseeIconViewItem*)(item); 465 aItem = (AddresseeIconViewItem*)(item);
437#endif //KAB_EMBEDDED 466#endif //KAB_EMBEDDED
438 if (aItem) 467 if (aItem)
439 { 468 {
440 emit selected(aItem->addressee().uid()); 469 emit selected(aItem->addressee().uid());
441 found = true; 470 found = true;
442 } 471 }
443 } 472 }
444 } 473 }
445 474
446 if (!found) 475 if (!found)
447 emit selected(QString::null); 476 emit selected(QString::null);
448} 477}
449 478
450#ifndef KAB_EMBEDDED 479#ifndef KAB_EMBEDDED
451#include "kaddressbookiconview.moc" 480#include "kaddressbookiconview.moc"
452#endif //KAB_EMBEDDED 481#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
index 348f491..02fc40a 100644
--- a/kaddressbook/views/kaddressbooktableview.cpp
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -1,474 +1,490 @@
1// $Id$ 1// $Id$
2 2
3#include <qvbox.h> 3#include <qvbox.h>
4#include <qlistbox.h> 4#include <qlistbox.h>
5#include <qwidget.h> 5#include <qwidget.h>
6#include <qfile.h> 6#include <qfile.h>
7#include <qimage.h> 7#include <qimage.h>
8#include <qcombobox.h> 8#include <qcombobox.h>
9#include <qapplication.h> 9#include <qapplication.h>
10#include <qdragobject.h> 10#include <qdragobject.h>
11#include <qevent.h> 11#include <qevent.h>
12#include <qurl.h> 12#include <qurl.h>
13#include <qpixmap.h> 13#include <qpixmap.h>
14 14
15#include <kabc/addressbook.h> 15#include <kabc/addressbook.h>
16#include <kapplication.h> 16#include <kapplication.h>
17#include <kconfig.h> 17#include <kconfig.h>
18#include <kcolorbutton.h> 18#include <kcolorbutton.h>
19#include <kdebug.h> 19#include <kdebug.h>
20#include <kglobal.h> 20#include <kglobal.h>
21#include <kiconloader.h> 21#include <kiconloader.h>
22#include <klineedit.h> 22#include <klineedit.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kmessagebox.h> 24#include <kmessagebox.h>
25#include <kurl.h> 25#include <kurl.h>
26#include <kurlrequester.h> 26#include <kurlrequester.h>
27 27
28//US#include "configuretableviewdialog.h" 28//US#include "configuretableviewdialog.h"
29#include "contactlistview.h" 29#include "contactlistview.h"
30#include "kabprefs.h" 30#include "kabprefs.h"
31#include "undocmds.h" 31#include "undocmds.h"
32#include "viewmanager.h" 32#include "viewmanager.h"
33 33
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qheader.h> 35#include <qheader.h>
36#include <qregexp.h> 36#include <qregexp.h>
37 37
38#include "kaddressbooktableview.h" 38#include "kaddressbooktableview.h"
39 39
40 40
41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, 41KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
42 QWidget *parent, const char *name ) 42 QWidget *parent, const char *name )
43 : KAddressBookView( ab, parent, name ) 43 : KAddressBookView( ab, parent, name )
44{ 44{
45 mainLayout = new QVBoxLayout( viewWidget(), 2 ); 45 mainLayout = new QVBoxLayout( viewWidget(), 2 );
46 46
47 // The list view will be created when the config is read. 47 // The list view will be created when the config is read.
48 mListView = 0; 48 mListView = 0;
49} 49}
50 50
51KAddressBookTableView::~KAddressBookTableView() 51KAddressBookTableView::~KAddressBookTableView()
52{ 52{
53} 53}
54void KAddressBookTableView::setFocusAV() 54void KAddressBookTableView::setFocusAV()
55{ 55{
56 if ( mListView ) 56 if ( mListView )
57 mListView->setFocus(); 57 mListView->setFocus();
58 58
59} 59}
60void KAddressBookTableView::scrollUP() 60void KAddressBookTableView::scrollUP()
61{ 61{
62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); 62 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 );
63 QApplication::postEvent( mListView, ev ); 63 QApplication::postEvent( mListView, ev );
64 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 ); 64 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 );
65 QApplication::postEvent( mListView, ev ); 65 QApplication::postEvent( mListView, ev );
66} 66}
67void KAddressBookTableView::scrollDOWN() 67void KAddressBookTableView::scrollDOWN()
68{ 68{
69 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); 69 QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 );
70 QApplication::postEvent( mListView, ev ); 70 QApplication::postEvent( mListView, ev );
71 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 ); 71 ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 );
72 QApplication::postEvent( mListView, ev ); 72 QApplication::postEvent( mListView, ev );
73} 73}
74void KAddressBookTableView::reconstructListView() 74void KAddressBookTableView::reconstructListView()
75{ 75{
76 if (mListView) 76 if (mListView)
77 { 77 {
78 disconnect(mListView, SIGNAL(selectionChanged()), 78 disconnect(mListView, SIGNAL(selectionChanged()),
79 this, SLOT(addresseeSelected())); 79 this, SLOT(addresseeSelected()));
80 disconnect(mListView, SIGNAL(executed(QListViewItem*)), 80 disconnect(mListView, SIGNAL(executed(QListViewItem*)),
81 this, SLOT(addresseeExecuted(QListViewItem*))); 81 this, SLOT(addresseeExecuted(QListViewItem*)));
82 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 82 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
83 this, SLOT(addresseeExecuted(QListViewItem*))); 83 this, SLOT(addresseeExecuted(QListViewItem*)));
84 disconnect(mListView, SIGNAL(startAddresseeDrag()), this, 84 disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
85 SIGNAL(startDrag())); 85 SIGNAL(startDrag()));
86 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), 86 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
87 this, SLOT(addresseeExecuted(QListViewItem*))); 87 this, SLOT(addresseeExecuted(QListViewItem*)));
88 88
89 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 89 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
90 SIGNAL(dropped(QDropEvent*))); 90 SIGNAL(dropped(QDropEvent*)));
91 delete mListView; 91 delete mListView;
92 } 92 }
93 93
94 mListView = new ContactListView( this, addressBook(), viewWidget() ); 94 mListView = new ContactListView( this, addressBook(), viewWidget() );
95 95
96 connect(this, SIGNAL(printView()), 96 connect(this, SIGNAL(printView()),
97 mListView , SLOT(printMe())); 97 mListView , SLOT(printMe()));
98 //US set singleClick manually, because it is no global configparameter in embedded space 98 //US set singleClick manually, because it is no global configparameter in embedded space
99 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick); 99 mListView->setSingleClick(KABPrefs::instance()->mHonorSingleClick);
100 100
101 // Add the columns 101 // Add the columns
102 KABC::Field::List fieldList = fields(); 102 KABC::Field::List fieldList = fields();
103 KABC::Field::List::ConstIterator it; 103 KABC::Field::List::ConstIterator it;
104 104
105 int c = 0; 105 int c = 0;
106 for( it = fieldList.begin(); it != fieldList.end(); ++it ) { 106 for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
107 mListView->addColumn( (*it)->label() ); 107 mListView->addColumn( (*it)->label() );
108 mListView->setColumnWidthMode(c++, QListView::Manual); 108 mListView->setColumnWidthMode(c++, QListView::Manual);
109//US 109//US
110 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); 110 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
111 } 111 }
112 112
113 connect(mListView, SIGNAL(selectionChanged()), 113 connect(mListView, SIGNAL(selectionChanged()),
114 this, SLOT(addresseeSelected())); 114 this, SLOT(addresseeSelected()));
115 connect(mListView, SIGNAL(startAddresseeDrag()), this, 115 connect(mListView, SIGNAL(startAddresseeDrag()), this,
116 SIGNAL(startDrag())); 116 SIGNAL(startDrag()));
117 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, 117 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
118 SIGNAL(dropped(QDropEvent*))); 118 SIGNAL(dropped(QDropEvent*)));
119 119
120 if (KABPrefs::instance()->mHonorSingleClick) { 120 if (KABPrefs::instance()->mHonorSingleClick) {
121 // qDebug("KAddressBookTableView::reconstructListView single"); 121 // qDebug("KAddressBookTableView::reconstructListView single");
122 connect(mListView, SIGNAL(executed(QListViewItem*)), 122 connect(mListView, SIGNAL(executed(QListViewItem*)),
123 this, SLOT(addresseeExecuted(QListViewItem*))); 123 this, SLOT(addresseeExecuted(QListViewItem*)));
124 } else { 124 } else {
125 // qDebug("KAddressBookTableView::reconstructListView double"); 125 // qDebug("KAddressBookTableView::reconstructListView double");
126 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), 126 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
127 this, SLOT(addresseeExecuted(QListViewItem*))); 127 this, SLOT(addresseeExecuted(QListViewItem*)));
128 } 128 }
129 connect(mListView, SIGNAL(returnPressed(QListViewItem*)), 129 connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
130 this, SLOT(addresseeExecuted(QListViewItem*))); 130 this, SLOT(addresseeExecuted(QListViewItem*)));
131 connect(mListView, SIGNAL(signalDelete()), 131 connect(mListView, SIGNAL(signalDelete()),
132 this, SLOT(addresseeDeleted())); 132 this, SLOT(addresseeDeleted()));
133 133
134//US performceimprovement. Refresh is done from the outside 134//US performceimprovement. Refresh is done from the outside
135//US refresh(); 135//US refresh();
136 136
137 mListView->setSorting( 0, true ); 137 mListView->setSorting( 0, true );
138 mainLayout->addWidget( mListView ); 138 mainLayout->addWidget( mListView );
139 mainLayout->activate(); 139 mainLayout->activate();
140 mListView->show(); 140 mListView->show();
141} 141}
142 142
143void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) 143void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field )
144{ 144{
145 mListView->clear(); 145 mListView->clear();
146 if ( s.isEmpty() || s == "*" ) { 146 if ( s.isEmpty() || s == "*" ) {
147 refresh(); 147 refresh();
148 return; 148 return;
149 } 149 }
150 QRegExp re = getRegExp( s ); 150 QRegExp re = getRegExp( s );
151 if (!re.isValid()) 151 if (!re.isValid())
152 return; 152 return;
153 KABC::Addressee::List addresseeList = addressees(); 153 KABC::Addressee::List addresseeList = addressees();
154 KABC::Addressee::List::Iterator it; 154 KABC::Addressee::List::Iterator it;
155 if ( field ) { 155 if ( field ) {
156 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 156 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
157 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 157 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
158 continue; 158 continue;
159#if QT_VERSION >= 0x030000 159#if QT_VERSION >= 0x030000
160 if (re.search(field->value( *it ).lower()) == 0) 160 if (re.search(field->value( *it ).lower()) == 0)
161#else 161#else
162 if (re.match(field->value( *it ).lower()) == 0) 162 if (re.match(field->value( *it ).lower()) == 0)
163#endif 163#endif
164 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 164 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
165 165
166 } 166 }
167 } else { 167 } else {
168 KABC::Field::List fieldList = allFields(); 168 KABC::Field::List fieldList = allFields();
169 KABC::Field::List::ConstIterator fieldIt; 169 KABC::Field::List::ConstIterator fieldIt;
170 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 170 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
171 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 171 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
172 continue; 172 continue;
173 bool match = false;
173 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 174 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
174#if QT_VERSION >= 0x030000 175#if QT_VERSION >= 0x030000
175 if (re.search((*fieldIt)->value( *it ).lower()) == 0) 176 if (re.search((*fieldIt)->value( *it ).lower()) == 0)
176#else 177#else
177 if (re.match((*fieldIt)->value( *it ).lower()) == 0) 178 if (re.match((*fieldIt)->value( *it ).lower()) == 0)
178#endif 179#endif
179 { 180 {
180 //qDebug("match %s %s %s", pattern.latin1(), (*fieldIt)->value( *it ).latin1(), (*fieldIt)->label().latin1() ); 181 //qDebug("match %s %s %s", pattern.latin1(), (*fieldIt)->value( *it ).latin1(), (*fieldIt)->label().latin1() );
181 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 182 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
183 match = true;
182 break; 184 break;
183 } 185 }
184 } 186 }
187 if ( ! match ) {
188 if ( (*it).matchPhoneNumber( &re ) ) {
189 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
190 match = true;
191 break;
192 }
193 }
194 if ( ! match ) {
195 if ( (*it).matchAddress( &re ) ) {
196 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
197 match = true;
198 break;
199 }
200 }
185 } 201 }
186 } 202 }
187 // Sometimes the background pixmap gets messed up when we add lots 203 // Sometimes the background pixmap gets messed up when we add lots
188 // of items. 204 // of items.
189 //mListView->repaint(); 205 //mListView->repaint();
190 if ( mListView->firstChild() ) { 206 if ( mListView->firstChild() ) {
191 mListView->setCurrentItem ( mListView->firstChild() ); 207 mListView->setCurrentItem ( mListView->firstChild() );
192 mListView->setSelected ( mListView->firstChild(), true ); 208 mListView->setSelected ( mListView->firstChild(), true );
193 } 209 }
194 else 210 else
195 emit selected(QString::null); 211 emit selected(QString::null);
196 212
197} 213}
198void KAddressBookTableView::writeConfig(KConfig *config) 214void KAddressBookTableView::writeConfig(KConfig *config)
199{ 215{
200 KAddressBookView::writeConfig(config); 216 KAddressBookView::writeConfig(config);
201 217
202 mListView->saveLayout(config, config->group()); 218 mListView->saveLayout(config, config->group());
203} 219}
204 220
205void KAddressBookTableView::readConfig(KConfig *config) 221void KAddressBookTableView::readConfig(KConfig *config)
206{ 222{
207 KAddressBookView::readConfig( config ); 223 KAddressBookView::readConfig( config );
208 // The config could have changed the fields, so we need to reconstruct 224 // The config could have changed the fields, so we need to reconstruct
209 // the listview. 225 // the listview.
210 reconstructListView(); 226 reconstructListView();
211 227
212 // costum colors? 228 // costum colors?
213 if ( config->readBoolEntry( "EnableCustomColors", false ) ) 229 if ( config->readBoolEntry( "EnableCustomColors", false ) )
214 { 230 {
215 QPalette p( mListView->palette() ); 231 QPalette p( mListView->palette() );
216 QColor c = p.color(QPalette::Normal, QColorGroup::Base ); 232 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
217 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); 233 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
218 c = p.color(QPalette::Normal, QColorGroup::Text ); 234 c = p.color(QPalette::Normal, QColorGroup::Text );
219 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); 235 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
220 c = p.color(QPalette::Normal, QColorGroup::Button ); 236 c = p.color(QPalette::Normal, QColorGroup::Button );
221 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 237 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
222 c = p.color(QPalette::Normal, QColorGroup::ButtonText ); 238 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
223 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); 239 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
224 c = p.color(QPalette::Normal, QColorGroup::Highlight ); 240 c = p.color(QPalette::Normal, QColorGroup::Highlight );
225 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); 241 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
226 c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); 242 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
227 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); 243 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
228#ifndef KAB_EMBEDDED 244#ifndef KAB_EMBEDDED
229 c = KGlobalSettings::alternateBackgroundColor(); 245 c = KGlobalSettings::alternateBackgroundColor();
230#else //KAB_EMBEDDED 246#else //KAB_EMBEDDED
231 c = QColor(240, 240, 240); 247 c = QColor(240, 240, 240);
232#endif //KAB_EMBEDDED 248#endif //KAB_EMBEDDED
233 c = config->readColorEntry ("AlternatingBackgroundColor", &c); 249 c = config->readColorEntry ("AlternatingBackgroundColor", &c);
234 mListView->setAlternateColor(c); 250 mListView->setAlternateColor(c);
235 251
236 252
237 //US mListView->viewport()->setPalette( p ); 253 //US mListView->viewport()->setPalette( p );
238 mListView->setPalette( p ); 254 mListView->setPalette( p );
239 } 255 }
240 else 256 else
241 { 257 {
242 // needed if turned off during a session. 258 // needed if turned off during a session.
243 //US mListView->viewport()->setPalette( mListView->palette() ); 259 //US mListView->viewport()->setPalette( mListView->palette() );
244 mListView->setPalette( mListView->palette() ); 260 mListView->setPalette( mListView->palette() );
245 } 261 }
246 262
247 //custom fonts? 263 //custom fonts?
248 QFont f( font() ); 264 QFont f( font() );
249 if ( config->readBoolEntry( "EnableCustomFonts", false ) ) 265 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
250 { 266 {
251 mListView->setFont( config->readFontEntry( "TextFont", &f) ); 267 mListView->setFont( config->readFontEntry( "TextFont", &f) );
252 f.setBold( true ); 268 f.setBold( true );
253 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); 269 //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
254 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); 270 mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) );
255 } 271 }
256 else 272 else
257 { 273 {
258 mListView->setFont( f ); 274 mListView->setFont( f );
259 f.setBold( true ); 275 f.setBold( true );
260 //US mListView->setHeaderFont( f ); 276 //US mListView->setHeaderFont( f );
261 mListView->header()->setFont( f ); 277 mListView->header()->setFont( f );
262 } 278 }
263 279
264 // Set the list view options 280 // Set the list view options
265 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", 281 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
266 true)); 282 true));
267 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); 283 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
268 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); 284 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
269 285
270 if (config->readBoolEntry("Background", false)) 286 if (config->readBoolEntry("Background", false))
271 mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); 287 mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
272 288
273 // Restore the layout of the listview 289 // Restore the layout of the listview
274 mListView->restoreLayout(config, config->group()); 290 mListView->restoreLayout(config, config->group());
275} 291}
276 292
277void KAddressBookTableView::refresh(QString uid) 293void KAddressBookTableView::refresh(QString uid)
278{ 294{
279 // For now just repopulate. In reality this method should 295 // For now just repopulate. In reality this method should
280 // check the value of uid, and if valid iterate through 296 // check the value of uid, and if valid iterate through
281 // the listview to find the entry, then tell it to refresh. 297 // the listview to find the entry, then tell it to refresh.
282 298
283 if (uid.isNull()) { 299 if (uid.isNull()) {
284 // Clear the list view 300 // Clear the list view
285 QString currentUID, nextUID; 301 QString currentUID, nextUID;
286#ifndef KAB_EMBEDDED 302#ifndef KAB_EMBEDDED
287 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); 303 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
288#else //KAB_EMBEDDED 304#else //KAB_EMBEDDED
289 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); 305 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
290#endif //KAB_EMBEDDED 306#endif //KAB_EMBEDDED
291 307
292 if ( currentItem ) { 308 if ( currentItem ) {
293#ifndef KAB_EMBEDDED 309#ifndef KAB_EMBEDDED
294 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); 310 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
295#else //KAB_EMBEDDED 311#else //KAB_EMBEDDED
296 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); 312 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
297#endif //KAB_EMBEDDED 313#endif //KAB_EMBEDDED
298 if ( nextItem ) 314 if ( nextItem )
299 nextUID = nextItem->addressee().uid(); 315 nextUID = nextItem->addressee().uid();
300 currentUID = currentItem->addressee().uid(); 316 currentUID = currentItem->addressee().uid();
301 } 317 }
302 318
303 mListView->clear(); 319 mListView->clear();
304 320
305 currentItem = 0; 321 currentItem = 0;
306 KABC::Addressee::List addresseeList = addressees(); 322 KABC::Addressee::List addresseeList = addressees();
307 KABC::Addressee::List::Iterator it; 323 KABC::Addressee::List::Iterator it;
308 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { 324 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
309 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 325 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
310 continue; 326 continue;
311 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); 327 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
312 if ( (*it).uid() == currentUID ) 328 if ( (*it).uid() == currentUID )
313 currentItem = item; 329 currentItem = item;
314 else if ( (*it).uid() == nextUID && !currentItem ) 330 else if ( (*it).uid() == nextUID && !currentItem )
315 currentItem = item; 331 currentItem = item;
316 } 332 }
317 333
318 // Sometimes the background pixmap gets messed up when we add lots 334 // Sometimes the background pixmap gets messed up when we add lots
319 // of items. 335 // of items.
320 mListView->repaint(); 336 mListView->repaint();
321 337
322 if ( currentItem ) { 338 if ( currentItem ) {
323 mListView->setCurrentItem( currentItem ); 339 mListView->setCurrentItem( currentItem );
324 mListView->ensureItemVisible( currentItem ); 340 mListView->ensureItemVisible( currentItem );
325 } 341 }
326 } else { 342 } else {
327 // Only need to update on entry. Iterate through and try to find it 343 // Only need to update on entry. Iterate through and try to find it
328 ContactListViewItem *ceItem; 344 ContactListViewItem *ceItem;
329 QListViewItemIterator it( mListView ); 345 QListViewItemIterator it( mListView );
330 while ( it.current() ) { 346 while ( it.current() ) {
331#ifndef KAB_EMBEDDED 347#ifndef KAB_EMBEDDED
332 ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); 348 ceItem = dynamic_cast<ContactListViewItem*>( it.current() );
333#else //KAB_EMBEDDED 349#else //KAB_EMBEDDED
334 ceItem = (ContactListViewItem*)( it.current() ); 350 ceItem = (ContactListViewItem*)( it.current() );
335#endif //KAB_EMBEDDED 351#endif //KAB_EMBEDDED
336 352
337 if ( ceItem && ceItem->addressee().uid() == uid ) { 353 if ( ceItem && ceItem->addressee().uid() == uid ) {
338 ceItem->refresh(); 354 ceItem->refresh();
339 return; 355 return;
340 } 356 }
341 ++it; 357 ++it;
342 } 358 }
343 359
344 refresh( QString::null ); 360 refresh( QString::null );
345 } 361 }
346} 362}
347 363
348QStringList KAddressBookTableView::selectedUids() 364QStringList KAddressBookTableView::selectedUids()
349{ 365{
350 QStringList uidList; 366 QStringList uidList;
351 QListViewItem *item; 367 QListViewItem *item;
352 ContactListViewItem *ceItem; 368 ContactListViewItem *ceItem;
353 369
354 for(item = mListView->firstChild(); item; item = item->itemBelow()) 370 for(item = mListView->firstChild(); item; item = item->itemBelow())
355 { 371 {
356 if (mListView->isSelected( item )) 372 if (mListView->isSelected( item ))
357 { 373 {
358#ifndef KAB_EMBEDDED 374#ifndef KAB_EMBEDDED
359 ceItem = dynamic_cast<ContactListViewItem*>(item); 375 ceItem = dynamic_cast<ContactListViewItem*>(item);
360#else //KAB_EMBEDDED 376#else //KAB_EMBEDDED
361 ceItem = (ContactListViewItem*)(item); 377 ceItem = (ContactListViewItem*)(item);
362#endif //KAB_EMBEDDED 378#endif //KAB_EMBEDDED
363 379
364 if (ceItem != 0L) 380 if (ceItem != 0L)
365 uidList << ceItem->addressee().uid(); 381 uidList << ceItem->addressee().uid();
366 } 382 }
367 } 383 }
368 if ( uidList.count() == 0 ) 384 if ( uidList.count() == 0 )
369 if ( mListView->currentItem() ) { 385 if ( mListView->currentItem() ) {
370 ceItem = (ContactListViewItem*)(mListView->currentItem()) ; 386 ceItem = (ContactListViewItem*)(mListView->currentItem()) ;
371 uidList << ceItem->addressee().uid(); 387 uidList << ceItem->addressee().uid();
372 } 388 }
373 389
374 return uidList; 390 return uidList;
375} 391}
376 392
377void KAddressBookTableView::setSelected(QString uid, bool selected) 393void KAddressBookTableView::setSelected(QString uid, bool selected)
378{ 394{
379 QListViewItem *item; 395 QListViewItem *item;
380 ContactListViewItem *ceItem; 396 ContactListViewItem *ceItem;
381 397
382 if (uid.isNull()) 398 if (uid.isNull())
383 { 399 {
384 mListView->selectAll(selected); 400 mListView->selectAll(selected);
385 } 401 }
386 else 402 else
387 { 403 {
388 for(item = mListView->firstChild(); item; item = item->itemBelow()) 404 for(item = mListView->firstChild(); item; item = item->itemBelow())
389 { 405 {
390#ifndef KAB_EMBEDDED 406#ifndef KAB_EMBEDDED
391 ceItem = dynamic_cast<ContactListViewItem*>(item); 407 ceItem = dynamic_cast<ContactListViewItem*>(item);
392#else //KAB_EMBEDDED 408#else //KAB_EMBEDDED
393 ceItem = (ContactListViewItem*)(item); 409 ceItem = (ContactListViewItem*)(item);
394#endif //KAB_EMBEDDED 410#endif //KAB_EMBEDDED
395 411
396 412
397 if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) 413 if ((ceItem != 0L) && (ceItem->addressee().uid() == uid))
398 { 414 {
399 mListView->setSelected(item, selected); 415 mListView->setSelected(item, selected);
400 416
401 if (selected) 417 if (selected)
402 mListView->ensureItemVisible(item); 418 mListView->ensureItemVisible(item);
403 } 419 }
404 } 420 }
405 } 421 }
406} 422}
407 423
408void KAddressBookTableView::addresseeSelected() 424void KAddressBookTableView::addresseeSelected()
409{ 425{
410 // We need to try to find the first selected item. This might not be the 426 // We need to try to find the first selected item. This might not be the
411 // last selected item, but when QListView is in multiselection mode, 427 // last selected item, but when QListView is in multiselection mode,
412 // there is no way to figure out which one was 428 // there is no way to figure out which one was
413 // selected last. 429 // selected last.
414 QListViewItem *item; 430 QListViewItem *item;
415 bool found =false; 431 bool found =false;
416 for (item = mListView->firstChild(); item && !found; 432 for (item = mListView->firstChild(); item && !found;
417 item = item->nextSibling()) 433 item = item->nextSibling())
418 { 434 {
419 if (item->isSelected()) 435 if (item->isSelected())
420 { 436 {
421 found = true; 437 found = true;
422#ifndef KAB_EMBEDDED 438#ifndef KAB_EMBEDDED
423 ContactListViewItem *ceItem 439 ContactListViewItem *ceItem
424 = dynamic_cast<ContactListViewItem*>(item); 440 = dynamic_cast<ContactListViewItem*>(item);
425#else //KAB_EMBEDDED 441#else //KAB_EMBEDDED
426 ContactListViewItem *ceItem 442 ContactListViewItem *ceItem
427 = (ContactListViewItem*)(item); 443 = (ContactListViewItem*)(item);
428#endif //KAB_EMBEDDED 444#endif //KAB_EMBEDDED
429 445
430 if ( ceItem ) emit selected(ceItem->addressee().uid()); 446 if ( ceItem ) emit selected(ceItem->addressee().uid());
431 } 447 }
432 } 448 }
433 449
434 if (!found) 450 if (!found)
435 emit selected(QString::null); 451 emit selected(QString::null);
436} 452}
437 453
438void KAddressBookTableView::addresseeExecuted(QListViewItem *item) 454void KAddressBookTableView::addresseeExecuted(QListViewItem *item)
439{ 455{
440 if (item) 456 if (item)
441 { 457 {
442#ifndef KAB_EMBEDDED 458#ifndef KAB_EMBEDDED
443 ContactListViewItem *ceItem 459 ContactListViewItem *ceItem
444 = dynamic_cast<ContactListViewItem*>(item); 460 = dynamic_cast<ContactListViewItem*>(item);
445#else //KAB_EMBEDDED 461#else //KAB_EMBEDDED
446 ContactListViewItem *ceItem 462 ContactListViewItem *ceItem
447 = (ContactListViewItem*)(item); 463 = (ContactListViewItem*)(item);
448#endif //KAB_EMBEDDED 464#endif //KAB_EMBEDDED
449 465
450 if (ceItem) 466 if (ceItem)
451 { 467 {
452 emit executed(ceItem->addressee().uid()); 468 emit executed(ceItem->addressee().uid());
453 } 469 }
454 } 470 }
455 else 471 else
456 { 472 {
457 emit executed(QString::null); 473 emit executed(QString::null);
458 } 474 }
459} 475}
460 476
461void KAddressBookTableView::addresseeDeleted() 477void KAddressBookTableView::addresseeDeleted()
462{ 478{
463 479
464 emit deleteRequest(); 480 emit deleteRequest();
465 481
466} 482}
467 483
468 484
469 485
470 486
471 487
472#ifndef KAB_EMBEDDED 488#ifndef KAB_EMBEDDED
473#include "kaddressbooktableview.moc" 489#include "kaddressbooktableview.moc"
474#endif //KAB_EMBEDDED 490#endif //KAB_EMBEDDED