summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp13
-rw-r--r--kabc/address.h1
-rw-r--r--kabc/addressbook.cpp133
-rw-r--r--kabc/addressbook.h4
-rw-r--r--kabc/addressee.cpp99
-rw-r--r--kabc/addressee.h2
-rw-r--r--kaddressbook/kabcore.cpp36
7 files changed, 245 insertions, 43 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index c820a6c..5ffe511 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -1,651 +1,664 @@
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()
92{
93 QStringList result;
94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox);
95 if ( ! mExtended.isEmpty())result.append(mExtended);
96 if ( ! mStreet.isEmpty())result.append(mStreet);
97 if ( ! mLocality.isEmpty() )result.append(mLocality);
98 if ( ! mRegion.isEmpty())result.append(mRegion);
99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode);
100 if ( ! mCountry.isEmpty())result.append(mCountry);
101 if ( ! mLabel.isEmpty() )result.append(mLabel);
102 return result;
103}
91void Address::clear() 104void Address::clear()
92{ 105{
93 *this = Address(); 106 *this = Address();
94} 107}
95 108
96void Address::setId( const QString &id ) 109void Address::setId( const QString &id )
97{ 110{
98 mEmpty = false; 111 mEmpty = false;
99 112
100 mId = id; 113 mId = id;
101} 114}
102 115
103QString Address::id() const 116QString Address::id() const
104{ 117{
105 return mId; 118 return mId;
106} 119}
107 120
108void Address::setType( int type ) 121void Address::setType( int type )
109{ 122{
110 mEmpty = false; 123 mEmpty = false;
111 124
112 mType = type; 125 mType = type;
113} 126}
114 127
115int Address::type() const 128int Address::type() const
116{ 129{
117 return mType; 130 return mType;
118} 131}
119 132
120QString Address::typeLabel() const 133QString Address::typeLabel() const
121{ 134{
122 QString label; 135 QString label;
123 bool first = true; 136 bool first = true;
124 137
125 TypeList list = typeList(); 138 TypeList list = typeList();
126 139
127 TypeList::Iterator it; 140 TypeList::Iterator it;
128 for ( it = list.begin(); it != list.end(); ++it ) { 141 for ( it = list.begin(); it != list.end(); ++it ) {
129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 142 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 143 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
131 if ( first ) 144 if ( first )
132 first = false; 145 first = false;
133 } 146 }
134 } 147 }
135 148
136 return label; 149 return label;
137} 150}
138 151
139void Address::setPostOfficeBox( const QString &s ) 152void Address::setPostOfficeBox( const QString &s )
140{ 153{
141 mEmpty = false; 154 mEmpty = false;
142 155
143 mPostOfficeBox = s; 156 mPostOfficeBox = s;
144} 157}
145 158
146QString Address::postOfficeBox() const 159QString Address::postOfficeBox() const
147{ 160{
148 return mPostOfficeBox; 161 return mPostOfficeBox;
149} 162}
150 163
151QString Address::postOfficeBoxLabel() 164QString Address::postOfficeBoxLabel()
152{ 165{
153 return i18n("Post Office Box"); 166 return i18n("Post Office Box");
154} 167}
155 168
156 169
157void Address::setExtended( const QString &s ) 170void Address::setExtended( const QString &s )
158{ 171{
159 mEmpty = false; 172 mEmpty = false;
160 173
161 mExtended = s; 174 mExtended = s;
162} 175}
163 176
164QString Address::extended() const 177QString Address::extended() const
165{ 178{
166 return mExtended; 179 return mExtended;
167} 180}
168 181
169QString Address::extendedLabel() 182QString Address::extendedLabel()
170{ 183{
171 return i18n("Extended Address Information"); 184 return i18n("Extended Address Information");
172} 185}
173 186
174 187
175void Address::setStreet( const QString &s ) 188void Address::setStreet( const QString &s )
176{ 189{
177 mEmpty = false; 190 mEmpty = false;
178 191
179 mStreet = s; 192 mStreet = s;
180} 193}
181 194
182QString Address::street() const 195QString Address::street() const
183{ 196{
184 return mStreet; 197 return mStreet;
185} 198}
186 199
187QString Address::streetLabel() 200QString Address::streetLabel()
188{ 201{
189 return i18n("Street"); 202 return i18n("Street");
190} 203}
191 204
192 205
193void Address::setLocality( const QString &s ) 206void Address::setLocality( const QString &s )
194{ 207{
195 mEmpty = false; 208 mEmpty = false;
196 209
197 mLocality = s; 210 mLocality = s;
198} 211}
199 212
200QString Address::locality() const 213QString Address::locality() const
201{ 214{
202 return mLocality; 215 return mLocality;
203} 216}
204 217
205QString Address::localityLabel() 218QString Address::localityLabel()
206{ 219{
207 return i18n("Locality"); 220 return i18n("Locality");
208} 221}
209 222
210 223
211void Address::setRegion( const QString &s ) 224void Address::setRegion( const QString &s )
212{ 225{
213 mEmpty = false; 226 mEmpty = false;
214 227
215 mRegion = s; 228 mRegion = s;
216} 229}
217 230
218QString Address::region() const 231QString Address::region() const
219{ 232{
220 return mRegion; 233 return mRegion;
221} 234}
222 235
223QString Address::regionLabel() 236QString Address::regionLabel()
224{ 237{
225 return i18n("Region"); 238 return i18n("Region");
226} 239}
227 240
228 241
229void Address::setPostalCode( const QString &s ) 242void Address::setPostalCode( const QString &s )
230{ 243{
231 mEmpty = false; 244 mEmpty = false;
232 245
233 mPostalCode = s; 246 mPostalCode = s;
234} 247}
235 248
236QString Address::postalCode() const 249QString Address::postalCode() const
237{ 250{
238 return mPostalCode; 251 return mPostalCode;
239} 252}
240 253
241QString Address::postalCodeLabel() 254QString Address::postalCodeLabel()
242{ 255{
243 return i18n("Postal Code"); 256 return i18n("Postal Code");
244} 257}
245 258
246 259
247void Address::setCountry( const QString &s ) 260void Address::setCountry( const QString &s )
248{ 261{
249 mEmpty = false; 262 mEmpty = false;
250 263
251 mCountry = s; 264 mCountry = s;
252} 265}
253 266
254QString Address::country() const 267QString Address::country() const
255{ 268{
256 return mCountry; 269 return mCountry;
257} 270}
258 271
259QString Address::countryLabel() 272QString Address::countryLabel()
260{ 273{
261 return i18n("Country"); 274 return i18n("Country");
262} 275}
263 276
264 277
265void Address::setLabel( const QString &s ) 278void Address::setLabel( const QString &s )
266{ 279{
267 mEmpty = false; 280 mEmpty = false;
268 281
269 mLabel = s; 282 mLabel = s;
270} 283}
271 284
272QString Address::label() const 285QString Address::label() const
273{ 286{
274 return mLabel; 287 return mLabel;
275} 288}
276 289
277QString Address::labelLabel() 290QString Address::labelLabel()
278{ 291{
279 return i18n("Delivery Label"); 292 return i18n("Delivery Label");
280} 293}
281 294
282Address::TypeList Address::typeList() 295Address::TypeList Address::typeList()
283{ 296{
284 TypeList list; 297 TypeList list;
285 298
286 list << Dom << Intl << Postal << Parcel << Home << Work << Pref; 299 list << Dom << Intl << Postal << Parcel << Home << Work << Pref;
287 300
288 return list; 301 return list;
289} 302}
290 303
291QString Address::typeLabel( int type ) 304QString Address::typeLabel( int type )
292{ 305{
293 QString label; 306 QString label;
294 if ( type & Dom ) 307 if ( type & Dom )
295 label += i18n("Domestic")+" "; 308 label += i18n("Domestic")+" ";
296 if ( type & Intl ) 309 if ( type & Intl )
297 label += i18n("International")+" "; 310 label += i18n("International")+" ";
298 if ( type & Postal ) 311 if ( type & Postal )
299 label += i18n("Postal")+" "; 312 label += i18n("Postal")+" ";
300 if ( type & Parcel ) 313 if ( type & Parcel )
301 label += i18n("Parcel")+" "; 314 label += i18n("Parcel")+" ";
302 if ( type & Work ) 315 if ( type & Work )
303 label += i18n("Work Address", "Work")+" "; 316 label += i18n("Work Address", "Work")+" ";
304 if ( type & Home ) 317 if ( type & Home )
305 label += i18n("Home Address", "Home") +" "; 318 label += i18n("Home Address", "Home") +" ";
306 if ( type & Pref ) 319 if ( type & Pref )
307 label += i18n("Preferred Address", "(p)"); 320 label += i18n("Preferred Address", "(p)");
308 if ( label.isEmpty() ) 321 if ( label.isEmpty() )
309 label = i18n("Other"); 322 label = i18n("Other");
310 return label; 323 return label;
311 324
312#if 0 325#if 0
313 switch ( type ) { 326 switch ( type ) {
314 case Dom: 327 case Dom:
315 return i18n("Domestic"); 328 return i18n("Domestic");
316 break; 329 break;
317 case Intl: 330 case Intl:
318 return i18n("International"); 331 return i18n("International");
319 break; 332 break;
320 case Postal: 333 case Postal:
321 return i18n("Postal"); 334 return i18n("Postal");
322 break; 335 break;
323 case Parcel: 336 case Parcel:
324 return i18n("Parcel"); 337 return i18n("Parcel");
325 break; 338 break;
326 case Home: 339 case Home:
327 return i18n("Home Address", "Home"); 340 return i18n("Home Address", "Home");
328 break; 341 break;
329 case Work: 342 case Work:
330 return i18n("Work Address", "Work"); 343 return i18n("Work Address", "Work");
331 break; 344 break;
332 case Pref: 345 case Pref:
333 return i18n("Preferred Address"); 346 return i18n("Preferred Address");
334 break; 347 break;
335 default: 348 default:
336 return i18n("Other"); 349 return i18n("Other");
337 break; 350 break;
338 } 351 }
339#endif 352#endif
340} 353}
341 354
342void Address::dump() const 355void Address::dump() const
343{ 356{
344 qDebug("Address::dump() +++++++++++++++++ "); 357 qDebug("Address::dump() +++++++++++++++++ ");
345#if 0 358#if 0
346 kdDebug(5700) << " Address {" << endl; 359 kdDebug(5700) << " Address {" << endl;
347 kdDebug(5700) << " Id: " << id() << endl; 360 kdDebug(5700) << " Id: " << id() << endl;
348 kdDebug(5700) << " Extended: " << extended() << endl; 361 kdDebug(5700) << " Extended: " << extended() << endl;
349 kdDebug(5700) << " Street: " << street() << endl; 362 kdDebug(5700) << " Street: " << street() << endl;
350 kdDebug(5700) << " Postal Code: " << postalCode() << endl; 363 kdDebug(5700) << " Postal Code: " << postalCode() << endl;
351 kdDebug(5700) << " Locality: " << locality() << endl; 364 kdDebug(5700) << " Locality: " << locality() << endl;
352 kdDebug(5700) << " }" << endl; 365 kdDebug(5700) << " }" << endl;
353#endif 366#endif
354} 367}
355 368
356 369
357QString Address::formattedAddress( const QString &realName 370QString Address::formattedAddress( const QString &realName
358 , const QString &orgaName ) const 371 , const QString &orgaName ) const
359{ 372{
360 QString ciso; 373 QString ciso;
361 QString addrTemplate; 374 QString addrTemplate;
362 QString ret; 375 QString ret;
363 376
364 // ************************************************************** 377 // **************************************************************
365 // LR: currently we have no iso handling - we will format the address manually here 378 // LR: currently we have no iso handling - we will format the address manually here
366 379
367 QString text; 380 QString text;
368 if ( !street().isEmpty() ) 381 if ( !street().isEmpty() )
369 text += street() + "\n"; 382 text += street() + "\n";
370 383
371 if ( !postOfficeBox().isEmpty() ) 384 if ( !postOfficeBox().isEmpty() )
372 text += postOfficeBox() + "\n"; 385 text += postOfficeBox() + "\n";
373 386
374 text += locality() + QString(" ") + region(); 387 text += locality() + QString(" ") + region();
375 388
376 if ( !postalCode().isEmpty() ) 389 if ( !postalCode().isEmpty() )
377 text += QString(", ") + postalCode(); 390 text += QString(", ") + postalCode();
378 391
379 text += "\n"; 392 text += "\n";
380 393
381 if ( !country().isEmpty() ) 394 if ( !country().isEmpty() )
382 text += country() + "\n"; 395 text += country() + "\n";
383 396
384 text += extended(); 397 text += extended();
385 398
386 399
387 return text; 400 return text;
388 // ************************************************************** 401 // **************************************************************
389 402
390 // FIXME: first check for iso-country-field and prefer that one 403 // FIXME: first check for iso-country-field and prefer that one
391 if ( !country().isEmpty() ) { 404 if ( !country().isEmpty() ) {
392 ciso = countryToISO( country() ); 405 ciso = countryToISO( country() );
393 } else { 406 } else {
394 // fall back to our own country 407 // fall back to our own country
395 ciso = KGlobal::locale()->country(); 408 ciso = KGlobal::locale()->country();
396 } 409 }
397 //qDebug("ciso %s ",ciso.latin1() ); 410 //qDebug("ciso %s ",ciso.latin1() );
398 KSimpleConfig entry( locate( "locale", 411 KSimpleConfig entry( locate( "locale",
399 QString( "l10n/" ) + ciso + QString( "/entry.desktop" ) ) ); 412 QString( "l10n/" ) + ciso + QString( "/entry.desktop" ) ) );
400 entry.setGroup( "KCM Locale" ); 413 entry.setGroup( "KCM Locale" );
401 414
402 // decide whether this needs special business address formatting 415 // decide whether this needs special business address formatting
403 if ( orgaName.isNull() ) { 416 if ( orgaName.isNull() ) {
404 addrTemplate = entry.readEntry( "AddressFormat" ); 417 addrTemplate = entry.readEntry( "AddressFormat" );
405 } else { 418 } else {
406 addrTemplate = entry.readEntry( "BusinessAddressFormat" ); 419 addrTemplate = entry.readEntry( "BusinessAddressFormat" );
407 if ( addrTemplate.isEmpty() ) 420 if ( addrTemplate.isEmpty() )
408 addrTemplate = entry.readEntry( "AddressFormat" ); 421 addrTemplate = entry.readEntry( "AddressFormat" );
409 } 422 }
410 423
411 // in the case there's no format found at all, default to what we've always 424 // in the case there's no format found at all, default to what we've always
412 // used: 425 // used:
413 if ( addrTemplate.isEmpty() ) { 426 if ( addrTemplate.isEmpty() ) {
414 qDebug("address format database incomplete****************** "); 427 qDebug("address format database incomplete****************** ");
415 kdWarning(5700) << "address format database incomplete " 428 kdWarning(5700) << "address format database incomplete "
416 << "(no format for locale " << ciso 429 << "(no format for locale " << ciso
417 << " found). Using default address formatting." << endl; 430 << " found). Using default address formatting." << endl;
418 addrTemplate = "%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z"; 431 addrTemplate = "%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z";
419 } 432 }
420 433
421 // scan 434 // scan
422 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName ); 435 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName );
423 436
424 // now add the country line if needed (formatting this time according to 437 // now add the country line if needed (formatting this time according to
425 // the rules of our own system country ) 438 // the rules of our own system country )
426 if ( !country().isEmpty() ) { 439 if ( !country().isEmpty() ) {
427 KSimpleConfig entry( locate( "locale", QString( "l10n/" ) 440 KSimpleConfig entry( locate( "locale", QString( "l10n/" )
428 + KGlobal::locale()->country() + QString( "/entry.desktop" ) ) ); 441 + KGlobal::locale()->country() + QString( "/entry.desktop" ) ) );
429 entry.setGroup( "KCM Locale" ); 442 entry.setGroup( "KCM Locale" );
430 QString cpos = entry.readEntry( "AddressCountryPosition" ); 443 QString cpos = entry.readEntry( "AddressCountryPosition" );
431 if ( "BELOW" == cpos || cpos.isEmpty() ) { 444 if ( "BELOW" == cpos || cpos.isEmpty() ) {
432 ret = ret + "\n\n" + country().upper(); 445 ret = ret + "\n\n" + country().upper();
433 } else if ( "below" == cpos ) { 446 } else if ( "below" == cpos ) {
434 ret = ret + "\n\n" + country(); 447 ret = ret + "\n\n" + country();
435 } else if ( "ABOVE" == cpos ) { 448 } else if ( "ABOVE" == cpos ) {
436 ret = country().upper() + "\n\n" + ret; 449 ret = country().upper() + "\n\n" + ret;
437 } else if ( "above" == cpos ) { 450 } else if ( "above" == cpos ) {
438 ret = country() + "\n\n" + ret; 451 ret = country() + "\n\n" + ret;
439 } 452 }
440 } 453 }
441 454
442 return ret; 455 return ret;
443} 456}
444 457
445bool Address::parseAddressTemplateSection( const QString &tsection, 458bool Address::parseAddressTemplateSection( const QString &tsection,
446 QString &result, const QString &realName, const QString &orgaName ) const 459 QString &result, const QString &realName, const QString &orgaName ) const
447{ 460{
448 // This method first parses and substitutes any bracketed sections and 461 // This method first parses and substitutes any bracketed sections and
449 // after that replaces any tags with their values. If a bracketed section 462 // after that replaces any tags with their values. If a bracketed section
450 // or a tag evaluate to zero, they are not just removed but replaced 463 // or a tag evaluate to zero, they are not just removed but replaced
451 // with a placeholder. This is because in the last step conditionals are 464 // with a placeholder. This is because in the last step conditionals are
452 // resolved which depend on information about zero-evaluations. 465 // resolved which depend on information about zero-evaluations.
453 result = tsection; 466 result = tsection;
454 int stpos = 0; 467 int stpos = 0;
455 bool ret = false; 468 bool ret = false;
456 469
457 // first check for brackets that have to be evaluated first 470 // first check for brackets that have to be evaluated first
458 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos ); 471 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
459 while ( -1 != fpos ) { 472 while ( -1 != fpos ) {
460 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length(); 473 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length();
461 int bpos2; 474 int bpos2;
462 // expect opening bracket and find next balanced closing bracket. If 475 // expect opening bracket and find next balanced closing bracket. If
463 // next char is no opening bracket, continue parsing (no valid tag) 476 // next char is no opening bracket, continue parsing (no valid tag)
464 if ( '(' == result[bpos1] ) { 477 if ( '(' == result[bpos1] ) {
465 bpos2 = findBalancedBracket( result, bpos1 ); 478 bpos2 = findBalancedBracket( result, bpos1 );
466 if ( -1 != bpos2 ) { 479 if ( -1 != bpos2 ) {
467 // we have balanced brackets, recursively parse: 480 // we have balanced brackets, recursively parse:
468 QString rplstr; 481 QString rplstr;
469 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1, 482 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1,
470 bpos2-bpos1-1 ), rplstr, 483 bpos2-bpos1-1 ), rplstr,
471 realName, orgaName ); 484 realName, orgaName );
472 if ( purge ) { 485 if ( purge ) {
473 // purge -> remove all 486 // purge -> remove all
474 // replace with !_P_!, so conditional tags work later 487 // replace with !_P_!, so conditional tags work later
475 result.replace( fpos, bpos2 - fpos + 1, "!_P_!" ); 488 result.replace( fpos, bpos2 - fpos + 1, "!_P_!" );
476 // leave stpos as it is 489 // leave stpos as it is
477 } else { 490 } else {
478 // no purge -> replace with recursively parsed string 491 // no purge -> replace with recursively parsed string
479 result.replace( fpos, bpos2 - fpos + 1, rplstr ); 492 result.replace( fpos, bpos2 - fpos + 1, rplstr );
480 ret = true; 493 ret = true;
481 stpos = fpos + rplstr.length(); 494 stpos = fpos + rplstr.length();
482 } 495 }
483 } else { 496 } else {
484 // unbalanced brackets: keep on parsing (should not happen 497 // unbalanced brackets: keep on parsing (should not happen
485 // and will result in bad formatting) 498 // and will result in bad formatting)
486 stpos = bpos1; 499 stpos = bpos1;
487 } 500 }
488 } 501 }
489 fpos = result.find( KABC_FMTTAG_purgeempty, stpos ); 502 fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
490 } 503 }
491 504
492 // after sorting out all purge tags, we just search'n'replace the rest, 505 // after sorting out all purge tags, we just search'n'replace the rest,
493 // keeping track of whether at least one tag evaluates to something. 506 // keeping track of whether at least one tag evaluates to something.
494 // The following macro needs QString for R_FIELD 507 // The following macro needs QString for R_FIELD
495 // It substitutes !_P_! for empty fields so conditional tags work later 508 // It substitutes !_P_! for empty fields so conditional tags work later
496#define REPLTAG(R_TAG,R_FIELD) \ 509#define REPLTAG(R_TAG,R_FIELD) \
497 if ( result.contains(R_TAG, false) ) { \ 510 if ( result.contains(R_TAG, false) ) { \
498 QString rpl = R_FIELD.isEmpty() ? QString("!_P_!") : R_FIELD; \ 511 QString rpl = R_FIELD.isEmpty() ? QString("!_P_!") : R_FIELD; \
499 result.replace( R_TAG, rpl ); \ 512 result.replace( R_TAG, rpl ); \
500 if ( !R_FIELD.isEmpty() ) { \ 513 if ( !R_FIELD.isEmpty() ) { \
501 ret = true; \ 514 ret = true; \
502 } \ 515 } \
503 } 516 }
504 REPLTAG( KABC_FMTTAG_realname, realName ); 517 REPLTAG( KABC_FMTTAG_realname, realName );
505 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() ); 518 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() );
506 REPLTAG( KABC_FMTTAG_company, orgaName ); 519 REPLTAG( KABC_FMTTAG_company, orgaName );
507 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() ); 520 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() );
508 REPLTAG( KABC_FMTTAG_pobox, postOfficeBox() ); 521 REPLTAG( KABC_FMTTAG_pobox, postOfficeBox() );
509 REPLTAG( KABC_FMTTAG_street, street() ); 522 REPLTAG( KABC_FMTTAG_street, street() );
510 REPLTAG( KABC_FMTTAG_STREET, street().upper() ); 523 REPLTAG( KABC_FMTTAG_STREET, street().upper() );
511 REPLTAG( KABC_FMTTAG_zipcode, postalCode() ); 524 REPLTAG( KABC_FMTTAG_zipcode, postalCode() );
512 REPLTAG( KABC_FMTTAG_location, locality() ); 525 REPLTAG( KABC_FMTTAG_location, locality() );
513 REPLTAG( KABC_FMTTAG_LOCATION, locality().upper() ); 526 REPLTAG( KABC_FMTTAG_LOCATION, locality().upper() );
514 REPLTAG( KABC_FMTTAG_region, region() ); 527 REPLTAG( KABC_FMTTAG_region, region() );
515 REPLTAG( KABC_FMTTAG_REGION, region().upper() ); 528 REPLTAG( KABC_FMTTAG_REGION, region().upper() );
516 result.replace( KABC_FMTTAG_newline, "\n" ); 529 result.replace( KABC_FMTTAG_newline, "\n" );
517#undef REPLTAG 530#undef REPLTAG
518 531
519 // conditional comma 532 // conditional comma
520 fpos = result.find( KABC_FMTTAG_condcomma, 0 ); 533 fpos = result.find( KABC_FMTTAG_condcomma, 0 );
521 while ( -1 != fpos ) { 534 while ( -1 != fpos ) {
522 QString str1 = result.mid( fpos - 5, 5 ); 535 QString str1 = result.mid( fpos - 5, 5 );
523 QString str2 = result.mid( fpos + 2, 5 ); 536 QString str2 = result.mid( fpos + 2, 5 );
524 if ( str1 != "!_P_!" && str2 != "!_P_!" ) { 537 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
525 result.replace( fpos, 2, ", " ); 538 result.replace( fpos, 2, ", " );
526 } else { 539 } else {
527 result.remove( fpos, 2 ); 540 result.remove( fpos, 2 );
528 } 541 }
529 fpos = result.find( KABC_FMTTAG_condcomma, fpos ); 542 fpos = result.find( KABC_FMTTAG_condcomma, fpos );
530 } 543 }
531 // conditional whitespace 544 // conditional whitespace
532 fpos = result.find( KABC_FMTTAG_condwhite, 0 ); 545 fpos = result.find( KABC_FMTTAG_condwhite, 0 );
533 while ( -1 != fpos ) { 546 while ( -1 != fpos ) {
534 QString str1 = result.mid( fpos - 5, 5 ); 547 QString str1 = result.mid( fpos - 5, 5 );
535 QString str2 = result.mid( fpos + 2, 5 ); 548 QString str2 = result.mid( fpos + 2, 5 );
536 if ( str1 != "!_P_!" && str2 != "!_P_!" ) { 549 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
537 result.replace( fpos, 2, " " ); 550 result.replace( fpos, 2, " " );
538 } else { 551 } else {
539 result.remove( fpos, 2 ); 552 result.remove( fpos, 2 );
540 } 553 }
541 fpos = result.find( KABC_FMTTAG_condwhite, fpos ); 554 fpos = result.find( KABC_FMTTAG_condwhite, fpos );
542 } 555 }
543 556
544 // remove purged: 557 // remove purged:
545//US my QT version does not support remove. So lets do it the old fashioned way. 558//US my QT version does not support remove. So lets do it the old fashioned way.
546//US result.remove( "!_P_!" ); 559//US result.remove( "!_P_!" );
547 int n = result.find("!_P_!"); 560 int n = result.find("!_P_!");
548 if (n >= 0) 561 if (n >= 0)
549 result.remove( n, 5 ); 562 result.remove( n, 5 );
550 563
551 return ret; 564 return ret;
552} 565}
553 566
554int Address::findBalancedBracket( const QString &tsection, int pos ) const 567int Address::findBalancedBracket( const QString &tsection, int pos ) const
555{ 568{
556 int balancecounter = 0; 569 int balancecounter = 0;
557 for( unsigned int i = pos + 1; i < tsection.length(); i++ ) { 570 for( unsigned int i = pos + 1; i < tsection.length(); i++ ) {
558 if ( ')' == tsection.at(i) && 0 == balancecounter ) { 571 if ( ')' == tsection.at(i) && 0 == balancecounter ) {
559 // found end of brackets 572 // found end of brackets
560 return i; 573 return i;
561 } else 574 } else
562 if ( '(' == tsection.at(i) ) { 575 if ( '(' == tsection.at(i) ) {
563 // nested brackets 576 // nested brackets
564 balancecounter++; 577 balancecounter++;
565 } 578 }
566 } 579 }
567 return -1; 580 return -1;
568} 581}
569 582
570QString Address::countryToISO( const QString &cname ) 583QString Address::countryToISO( const QString &cname )
571{ 584{
572 // we search a map file for translations from country names to 585 // we search a map file for translations from country names to
573 // iso codes, storing caching things in a QMap for faster future 586 // iso codes, storing caching things in a QMap for faster future
574 // access. 587 // access.
575/*US 588/*US
576 589
577 QString isoCode = mISOMap[ cname ]; 590 QString isoCode = mISOMap[ cname ];
578 if ( !isoCode.isEmpty() ) 591 if ( !isoCode.isEmpty() )
579 return isoCode; 592 return isoCode;
580 593
581 QString mapfile = KGlobal::dirs()->findResource( "data", 594 QString mapfile = KGlobal::dirs()->findResource( "data",
582 QString::fromLatin1( "kabc/countrytransl.map" ) ); 595 QString::fromLatin1( "kabc/countrytransl.map" ) );
583 596
584 QFile file( mapfile ); 597 QFile file( mapfile );
585 if ( file.open( IO_ReadOnly ) ) { 598 if ( file.open( IO_ReadOnly ) ) {
586 QTextStream s( &file ); 599 QTextStream s( &file );
587 QString strbuf = s.readLine(); 600 QString strbuf = s.readLine();
588 while( !strbuf.isNull() ) { 601 while( !strbuf.isNull() ) {
589 if ( strbuf.startsWith( cname ) ) { 602 if ( strbuf.startsWith( cname ) ) {
590 int index = strbuf.findRev('\t'); 603 int index = strbuf.findRev('\t');
591 strbuf = strbuf.mid(index+1, 2); 604 strbuf = strbuf.mid(index+1, 2);
592 file.close(); 605 file.close();
593 mISOMap[ cname ] = strbuf; 606 mISOMap[ cname ] = strbuf;
594 return strbuf; 607 return strbuf;
595 } 608 }
596 strbuf = s.readLine(); 609 strbuf = s.readLine();
597 } 610 }
598 file.close(); 611 file.close();
599 } 612 }
600*/ 613*/
601 // fall back to system country 614 // fall back to system country
602 mISOMap[ cname ] = KGlobal::locale()->country(); 615 mISOMap[ cname ] = KGlobal::locale()->country();
603 return KGlobal::locale()->country(); 616 return KGlobal::locale()->country();
604} 617}
605 618
606QString Address::ISOtoCountry( const QString &ISOname ) 619QString Address::ISOtoCountry( const QString &ISOname )
607{ 620{
608/*US 621/*US
609 // get country name from ISO country code (e.g. "no" -> i18n("Norway")) 622 // get country name from ISO country code (e.g. "no" -> i18n("Norway"))
610 QString mapfile = KGlobal::dirs()->findResource( "data", 623 QString mapfile = KGlobal::dirs()->findResource( "data",
611 QString::fromLatin1( "kabc/countrytransl.map" ) ); 624 QString::fromLatin1( "kabc/countrytransl.map" ) );
612 625
613kdWarning() << "MAPFILE : " << mapfile << endl; 626kdWarning() << "MAPFILE : " << mapfile << endl;
614 QFile file( mapfile ); 627 QFile file( mapfile );
615 if ( file.open( IO_ReadOnly ) ) { 628 if ( file.open( IO_ReadOnly ) ) {
616 QTextStream s( &file ); 629 QTextStream s( &file );
617 QString searchStr = "\t" + ISOname.simplifyWhiteSpace().lower(); 630 QString searchStr = "\t" + ISOname.simplifyWhiteSpace().lower();
618kdWarning() << "Suche : " << searchStr << endl; 631kdWarning() << "Suche : " << searchStr << endl;
619 QString strbuf = s.readLine(); 632 QString strbuf = s.readLine();
620 int pos; 633 int pos;
621 while( !strbuf.isNull() ) { 634 while( !strbuf.isNull() ) {
622 if ( (pos=strbuf.find( searchStr )) != -1 ) { 635 if ( (pos=strbuf.find( searchStr )) != -1 ) {
623 file.close(); 636 file.close();
624 return i18n(strbuf.left(pos).utf8()); 637 return i18n(strbuf.left(pos).utf8());
625 } 638 }
626 strbuf = s.readLine(); 639 strbuf = s.readLine();
627 } 640 }
628 file.close(); 641 file.close();
629 } 642 }
630*/ 643*/
631 return ISOname; 644 return ISOname;
632} 645}
633 646
634QDataStream &KABC::operator<<( QDataStream &s, const Address &addr ) 647QDataStream &KABC::operator<<( QDataStream &s, const Address &addr )
635{ 648{
636 return s << addr.mId << addr.mType << addr.mPostOfficeBox << 649 return s << addr.mId << addr.mType << addr.mPostOfficeBox <<
637 addr.mExtended << addr.mStreet << addr.mLocality << 650 addr.mExtended << addr.mStreet << addr.mLocality <<
638 addr.mRegion << addr.mPostalCode << addr.mCountry << 651 addr.mRegion << addr.mPostalCode << addr.mCountry <<
639 addr.mLabel; 652 addr.mLabel;
640} 653}
641 654
642QDataStream &KABC::operator>>( QDataStream &s, Address &addr ) 655QDataStream &KABC::operator>>( QDataStream &s, Address &addr )
643{ 656{
644 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >> 657 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >>
645 addr.mStreet >> addr.mLocality >> addr.mRegion >> 658 addr.mStreet >> addr.mLocality >> addr.mRegion >>
646 addr.mPostalCode >> addr.mCountry >> addr.mLabel; 659 addr.mPostalCode >> addr.mCountry >> addr.mLabel;
647 660
648 addr.mEmpty = false; 661 addr.mEmpty = false;
649 662
650 return s; 663 return s;
651} 664}
diff --git a/kabc/address.h b/kabc/address.h
index ad132a7..6b53c7e 100644
--- a/kabc/address.h
+++ b/kabc/address.h
@@ -1,346 +1,347 @@
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 <qvaluelist.h> 33#include <qvaluelist.h>
34 34
35// template tags for address formatting localization 35// template tags for address formatting localization
36#define KABC_FMTTAG_realname QString("%n") 36#define KABC_FMTTAG_realname QString("%n")
37#define KABC_FMTTAG_REALNAME QString("%N") 37#define KABC_FMTTAG_REALNAME QString("%N")
38#define KABC_FMTTAG_company QString("%cm") 38#define KABC_FMTTAG_company QString("%cm")
39#define KABC_FMTTAG_COMPANY QString("%CM") 39#define KABC_FMTTAG_COMPANY QString("%CM")
40#define KABC_FMTTAG_pobox QString("%p") 40#define KABC_FMTTAG_pobox QString("%p")
41#define KABC_FMTTAG_street QString("%s") 41#define KABC_FMTTAG_street QString("%s")
42#define KABC_FMTTAG_STREET QString("%S") 42#define KABC_FMTTAG_STREET QString("%S")
43#define KABC_FMTTAG_zipcode QString("%z") 43#define KABC_FMTTAG_zipcode QString("%z")
44#define KABC_FMTTAG_location QString("%l") 44#define KABC_FMTTAG_location QString("%l")
45#define KABC_FMTTAG_LOCATION QString("%L") 45#define KABC_FMTTAG_LOCATION QString("%L")
46#define KABC_FMTTAG_region QString("%r") 46#define KABC_FMTTAG_region QString("%r")
47#define KABC_FMTTAG_REGION QString("%R") 47#define KABC_FMTTAG_REGION QString("%R")
48#define KABC_FMTTAG_newline QString("\\n") 48#define KABC_FMTTAG_newline QString("\\n")
49#define KABC_FMTTAG_condcomma QString("%,") 49#define KABC_FMTTAG_condcomma QString("%,")
50#define KABC_FMTTAG_condwhite QString("%w") 50#define KABC_FMTTAG_condwhite QString("%w")
51#define KABC_FMTTAG_purgeempty QString("%0") 51#define KABC_FMTTAG_purgeempty QString("%0")
52 52
53namespace KABC { 53namespace KABC {
54 54
55/** 55/**
56 @short Postal address information. 56 @short Postal address information.
57 57
58 This class represents information about a postal address. 58 This class represents information about a postal address.
59*/ 59*/
60class Address 60class Address
61{ 61{
62 friend QDataStream &operator<<( QDataStream &, const Address & ); 62 friend QDataStream &operator<<( QDataStream &, const Address & );
63 friend QDataStream &operator>>( QDataStream &, Address & ); 63 friend QDataStream &operator>>( QDataStream &, Address & );
64 64
65 public: 65 public:
66 /** 66 /**
67 List of addresses. 67 List of addresses.
68 */ 68 */
69 typedef QValueList<Address> List; 69 typedef QValueList<Address> List;
70 typedef QValueList<int> TypeList; 70 typedef QValueList<int> TypeList;
71 71
72 /** 72 /**
73 Address types: 73 Address types:
74 74
75 @li @p Dom - domestic 75 @li @p Dom - domestic
76 @li @p Intl - international 76 @li @p Intl - international
77 @li @p Postal - postal 77 @li @p Postal - postal
78 @li @p Parcel - parcel 78 @li @p Parcel - parcel
79 @li @p Home - home address 79 @li @p Home - home address
80 @li @p Work - address at work 80 @li @p Work - address at work
81 @li @p Pref - preferred address 81 @li @p Pref - preferred address
82 */ 82 */
83 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32, 83 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32,
84 Pref = 64 }; 84 Pref = 64 };
85 85
86 /** 86 /**
87 Constructor that creates an empty Address, which is initialized 87 Constructor that creates an empty Address, which is initialized
88 with a unique id (see @ref id()). 88 with a unique id (see @ref id()).
89 */ 89 */
90 Address(); 90 Address();
91 91
92 /** 92 /**
93 This is like @ref Address() just above, with the difference 93 This is like @ref Address() just above, with the difference
94 that you can specify the type. 94 that you can specify the type.
95 */ 95 */
96 Address( int ); 96 Address( int );
97 97
98 bool operator==( const Address & ) const; 98 bool operator==( const Address & ) const;
99 bool operator!=( const Address & ) const; 99 bool operator!=( const Address & ) const;
100 100
101 /** 101 /**
102 Returns true, if the address is empty. 102 Returns true, if the address is empty.
103 */ 103 */
104 bool isEmpty() const; 104 bool isEmpty() const;
105 105
106 /** 106 /**
107 Clears all entries of the address. 107 Clears all entries of the address.
108 */ 108 */
109 void clear(); 109 void clear();
110 QStringList asList();
110 111
111 /** 112 /**
112 Sets the unique id. 113 Sets the unique id.
113 */ 114 */
114 void setId( const QString & ); 115 void setId( const QString & );
115 116
116 /* 117 /*
117 Returns the unique id. 118 Returns the unique id.
118 */ 119 */
119 QString id() const; 120 QString id() const;
120 121
121 /** 122 /**
122 Sets the type of address. See enum for definiton of types. 123 Sets the type of address. See enum for definiton of types.
123 124
124 @param type type, can be a bitwise or of multiple types. 125 @param type type, can be a bitwise or of multiple types.
125 */ 126 */
126 void setType( int type ); 127 void setType( int type );
127 128
128 /** 129 /**
129 Returns the type of address. Can be a bitwise or of multiple types. 130 Returns the type of address. Can be a bitwise or of multiple types.
130 */ 131 */
131 int type() const; 132 int type() const;
132 133
133 /** 134 /**
134 Returns a translated string of all types the address has. 135 Returns a translated string of all types the address has.
135 */ 136 */
136 QString typeLabel() const; 137 QString typeLabel() const;
137 138
138 /** 139 /**
139 Sets the post office box. 140 Sets the post office box.
140 */ 141 */
141 void setPostOfficeBox( const QString & ); 142 void setPostOfficeBox( const QString & );
142 143
143 /** 144 /**
144 Returns the post office box. 145 Returns the post office box.
145 */ 146 */
146 QString postOfficeBox() const; 147 QString postOfficeBox() const;
147 148
148 /** 149 /**
149 Returns the translated label for post office box field. 150 Returns the translated label for post office box field.
150 */ 151 */
151 static QString postOfficeBoxLabel(); 152 static QString postOfficeBoxLabel();
152 153
153 /** 154 /**
154 Sets the extended address information. 155 Sets the extended address information.
155 */ 156 */
156 void setExtended( const QString & ); 157 void setExtended( const QString & );
157 158
158 /** 159 /**
159 Returns the extended address information. 160 Returns the extended address information.
160 */ 161 */
161 QString extended() const; 162 QString extended() const;
162 163
163 /** 164 /**
164 Returns the translated label for extended field. 165 Returns the translated label for extended field.
165 */ 166 */
166 static QString extendedLabel(); 167 static QString extendedLabel();
167 168
168 /** 169 /**
169 Sets the street (including number). 170 Sets the street (including number).
170 */ 171 */
171 void setStreet( const QString & ); 172 void setStreet( const QString & );
172 173
173 /** 174 /**
174 Returns the street. 175 Returns the street.
175 */ 176 */
176 QString street() const; 177 QString street() const;
177 178
178 /** 179 /**
179 Returns the translated label for street field. 180 Returns the translated label for street field.
180 */ 181 */
181 static QString streetLabel(); 182 static QString streetLabel();
182 183
183 /** 184 /**
184 Sets the locality, e.g. city. 185 Sets the locality, e.g. city.
185 */ 186 */
186 void setLocality( const QString & ); 187 void setLocality( const QString & );
187 188
188 /** 189 /**
189 Returns the locality. 190 Returns the locality.
190 */ 191 */
191 QString locality() const; 192 QString locality() const;
192 193
193 /** 194 /**
194 Returns the translated label for locality field. 195 Returns the translated label for locality field.
195 */ 196 */
196 static QString localityLabel(); 197 static QString localityLabel();
197 198
198 /** 199 /**
199 Sets the region, e.g. state. 200 Sets the region, e.g. state.
200 */ 201 */
201 void setRegion( const QString & ); 202 void setRegion( const QString & );
202 203
203 /** 204 /**
204 Returns the region. 205 Returns the region.
205 */ 206 */
206 QString region() const; 207 QString region() const;
207 208
208 /** 209 /**
209 Returns the translated label for region field. 210 Returns the translated label for region field.
210 */ 211 */
211 static QString regionLabel(); 212 static QString regionLabel();
212 213
213 /** 214 /**
214 Sets the postal code. 215 Sets the postal code.
215 */ 216 */
216 void setPostalCode( const QString & ); 217 void setPostalCode( const QString & );
217 218
218 /** 219 /**
219 Returns the postal code. 220 Returns the postal code.
220 */ 221 */
221 QString postalCode() const; 222 QString postalCode() const;
222 223
223 /** 224 /**
224 Returns the translated label for postal code field. 225 Returns the translated label for postal code field.
225 */ 226 */
226 static QString postalCodeLabel(); 227 static QString postalCodeLabel();
227 228
228 /** 229 /**
229 Sets the country. 230 Sets the country.
230 */ 231 */
231 void setCountry( const QString & ); 232 void setCountry( const QString & );
232 233
233 /** 234 /**
234 Returns the country. 235 Returns the country.
235 */ 236 */
236 QString country() const; 237 QString country() const;
237 238
238 /** 239 /**
239 Returns the translated label for country field. 240 Returns the translated label for country field.
240 */ 241 */
241 static QString countryLabel(); 242 static QString countryLabel();
242 243
243 /** 244 /**
244 Sets the delivery label. This is the literal text to be used as label. 245 Sets the delivery label. This is the literal text to be used as label.
245 */ 246 */
246 void setLabel( const QString & ); 247 void setLabel( const QString & );
247 248
248 /** 249 /**
249 Returns the delivery label. 250 Returns the delivery label.
250 */ 251 */
251 QString label() const; 252 QString label() const;
252 253
253 /** 254 /**
254 Returns the translated label for delivery label field. 255 Returns the translated label for delivery label field.
255 */ 256 */
256 static QString labelLabel(); 257 static QString labelLabel();
257 258
258 /** 259 /**
259 Returns the list of available types. 260 Returns the list of available types.
260 */ 261 */
261 static TypeList typeList(); 262 static TypeList typeList();
262 263
263 /** 264 /**
264 Returns the translated label for a special type. 265 Returns the translated label for a special type.
265 */ 266 */
266 static QString typeLabel( int type ); 267 static QString typeLabel( int type );
267 268
268 /** 269 /**
269 Used for debug output. 270 Used for debug output.
270 */ 271 */
271 void dump() const; 272 void dump() const;
272 273
273 /** 274 /**
274 Returns this address formatted according to the country-specific 275 Returns this address formatted according to the country-specific
275 address formatting rules. The formatting rules applied depend on 276 address formatting rules. The formatting rules applied depend on
276 either the addresses {@link #country country} field, or (if the 277 either the addresses {@link #country country} field, or (if the
277 latter is empty) on the system country setting. If companyName is 278 latter is empty) on the system country setting. If companyName is
278 provided, an available business address format will be preferred. 279 provided, an available business address format will be preferred.
279 280
280 @param realName the formatted name of the contact 281 @param realName the formatted name of the contact
281 @param orgaName the name of the organization or company 282 @param orgaName the name of the organization or company
282 @return the formatted address (containing newline characters) 283 @return the formatted address (containing newline characters)
283 */ 284 */
284 QString formattedAddress( const QString &realName=QString::null 285 QString formattedAddress( const QString &realName=QString::null
285 , const QString &orgaName=QString::null ) const; 286 , const QString &orgaName=QString::null ) const;
286 287
287 /** 288 /**
288 Returns ISO code for a localized country name. Only localized country 289 Returns ISO code for a localized country name. Only localized country
289 names will be understood. This might be replaced by a KLocale method in 290 names will be understood. This might be replaced by a KLocale method in
290 the future. 291 the future.
291 @param cname name of the country 292 @param cname name of the country
292 @return two digit ISO code 293 @return two digit ISO code
293 */ 294 */
294 static QString countryToISO( const QString &cname ); 295 static QString countryToISO( const QString &cname );
295 296
296 /** 297 /**
297 Returns a localized country name for a ISO code. 298 Returns a localized country name for a ISO code.
298 This might be replaced by a KLocale method in the future. 299 This might be replaced by a KLocale method in the future.
299 @param ISOname two digit ISO code 300 @param ISOname two digit ISO code
300 @return localized name of the country 301 @return localized name of the country
301 @since 3.2 302 @since 3.2
302 */ 303 */
303 static QString ISOtoCountry( const QString &ISOname ); 304 static QString ISOtoCountry( const QString &ISOname );
304 305
305 private: 306 private:
306 /** 307 /**
307 Parses a snippet of an address template 308 Parses a snippet of an address template
308 @param tsection the template string to be parsed 309 @param tsection the template string to be parsed
309 @param result QString reference in which the result will be stored 310 @param result QString reference in which the result will be stored
310 @return true if at least one tag evaluated positively, else false 311 @return true if at least one tag evaluated positively, else false
311 */ 312 */
312 bool parseAddressTemplateSection( const QString &tsection 313 bool parseAddressTemplateSection( const QString &tsection
313 , QString &result 314 , QString &result
314 , const QString &realName 315 , const QString &realName
315 , const QString &orgaName ) const; 316 , const QString &orgaName ) const;
316 317
317 /** 318 /**
318 Finds the balanced closing bracket starting from the opening bracket at 319 Finds the balanced closing bracket starting from the opening bracket at
319 pos in tsection. 320 pos in tsection.
320 @return position of closing bracket, -1 for unbalanced brackets 321 @return position of closing bracket, -1 for unbalanced brackets
321 */ 322 */
322 int findBalancedBracket( const QString &tsection, int pos ) const; 323 int findBalancedBracket( const QString &tsection, int pos ) const;
323 324
324 bool mEmpty; 325 bool mEmpty;
325 326
326 QString mId; 327 QString mId;
327 int mType; 328 int mType;
328 329
329 QString mPostOfficeBox; 330 QString mPostOfficeBox;
330 QString mExtended; 331 QString mExtended;
331 QString mStreet; 332 QString mStreet;
332 QString mLocality; 333 QString mLocality;
333 QString mRegion; 334 QString mRegion;
334 QString mPostalCode; 335 QString mPostalCode;
335 QString mCountry; 336 QString mCountry;
336 QString mLabel; 337 QString mLabel;
337 338
338 static QMap<QString, QString> mISOMap; 339 static QMap<QString, QString> mISOMap;
339}; 340};
340 341
341QDataStream &operator<<( QDataStream &, const Address & ); 342QDataStream &operator<<( QDataStream &, const Address & );
342QDataStream &operator>>( QDataStream &, Address & ); 343QDataStream &operator>>( QDataStream &, Address & );
343 344
344} 345}
345 346
346#endif 347#endif
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16e1653..ec9f893 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,788 +1,849 @@
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 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41 41
42#include <kglobal.h> 42#include <kglobal.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kdebug.h> 44#include <kdebug.h>
45#include <libkcal/syncdefines.h> 45#include <libkcal/syncdefines.h>
46#include "addressbook.h" 46#include "addressbook.h"
47#include "resource.h" 47#include "resource.h"
48 48
49//US #include "addressbook.moc" 49//US #include "addressbook.moc"
50 50
51using namespace KABC; 51using namespace KABC;
52 52
53struct AddressBook::AddressBookData 53struct AddressBook::AddressBookData
54{ 54{
55 Addressee::List mAddressees; 55 Addressee::List mAddressees;
56 Addressee::List mRemovedAddressees; 56 Addressee::List mRemovedAddressees;
57 Field::List mAllFields; 57 Field::List mAllFields;
58 KConfig *mConfig; 58 KConfig *mConfig;
59 KRES::Manager<Resource> *mManager; 59 KRES::Manager<Resource> *mManager;
60//US ErrorHandler *mErrorHandler; 60//US ErrorHandler *mErrorHandler;
61}; 61};
62 62
63struct AddressBook::Iterator::IteratorData 63struct AddressBook::Iterator::IteratorData
64{ 64{
65 Addressee::List::Iterator mIt; 65 Addressee::List::Iterator mIt;
66}; 66};
67 67
68struct AddressBook::ConstIterator::ConstIteratorData 68struct AddressBook::ConstIterator::ConstIteratorData
69{ 69{
70 Addressee::List::ConstIterator mIt; 70 Addressee::List::ConstIterator mIt;
71}; 71};
72 72
73AddressBook::Iterator::Iterator() 73AddressBook::Iterator::Iterator()
74{ 74{
75 d = new IteratorData; 75 d = new IteratorData;
76} 76}
77 77
78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
79{ 79{
80 d = new IteratorData; 80 d = new IteratorData;
81 d->mIt = i.d->mIt; 81 d->mIt = i.d->mIt;
82} 82}
83 83
84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
85{ 85{
86 if( this == &i ) return *this; // guard against self assignment 86 if( this == &i ) return *this; // guard against self assignment
87 delete d; // delete the old data the Iterator was completely constructed before 87 delete d; // delete the old data the Iterator was completely constructed before
88 d = new IteratorData; 88 d = new IteratorData;
89 d->mIt = i.d->mIt; 89 d->mIt = i.d->mIt;
90 return *this; 90 return *this;
91} 91}
92 92
93AddressBook::Iterator::~Iterator() 93AddressBook::Iterator::~Iterator()
94{ 94{
95 delete d; 95 delete d;
96} 96}
97 97
98const Addressee &AddressBook::Iterator::operator*() const 98const Addressee &AddressBook::Iterator::operator*() const
99{ 99{
100 return *(d->mIt); 100 return *(d->mIt);
101} 101}
102 102
103Addressee &AddressBook::Iterator::operator*() 103Addressee &AddressBook::Iterator::operator*()
104{ 104{
105 return *(d->mIt); 105 return *(d->mIt);
106} 106}
107 107
108Addressee *AddressBook::Iterator::operator->() 108Addressee *AddressBook::Iterator::operator->()
109{ 109{
110 return &(*(d->mIt)); 110 return &(*(d->mIt));
111} 111}
112 112
113AddressBook::Iterator &AddressBook::Iterator::operator++() 113AddressBook::Iterator &AddressBook::Iterator::operator++()
114{ 114{
115 (d->mIt)++; 115 (d->mIt)++;
116 return *this; 116 return *this;
117} 117}
118 118
119AddressBook::Iterator &AddressBook::Iterator::operator++(int) 119AddressBook::Iterator &AddressBook::Iterator::operator++(int)
120{ 120{
121 (d->mIt)++; 121 (d->mIt)++;
122 return *this; 122 return *this;
123} 123}
124 124
125AddressBook::Iterator &AddressBook::Iterator::operator--() 125AddressBook::Iterator &AddressBook::Iterator::operator--()
126{ 126{
127 (d->mIt)--; 127 (d->mIt)--;
128 return *this; 128 return *this;
129} 129}
130 130
131AddressBook::Iterator &AddressBook::Iterator::operator--(int) 131AddressBook::Iterator &AddressBook::Iterator::operator--(int)
132{ 132{
133 (d->mIt)--; 133 (d->mIt)--;
134 return *this; 134 return *this;
135} 135}
136 136
137bool AddressBook::Iterator::operator==( const Iterator &it ) 137bool AddressBook::Iterator::operator==( const Iterator &it )
138{ 138{
139 return ( d->mIt == it.d->mIt ); 139 return ( d->mIt == it.d->mIt );
140} 140}
141 141
142bool AddressBook::Iterator::operator!=( const Iterator &it ) 142bool AddressBook::Iterator::operator!=( const Iterator &it )
143{ 143{
144 return ( d->mIt != it.d->mIt ); 144 return ( d->mIt != it.d->mIt );
145} 145}
146 146
147 147
148AddressBook::ConstIterator::ConstIterator() 148AddressBook::ConstIterator::ConstIterator()
149{ 149{
150 d = new ConstIteratorData; 150 d = new ConstIteratorData;
151} 151}
152 152
153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
154{ 154{
155 d = new ConstIteratorData; 155 d = new ConstIteratorData;
156 d->mIt = i.d->mIt; 156 d->mIt = i.d->mIt;
157} 157}
158 158
159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
160{ 160{
161 if( this == &i ) return *this; // guard for self assignment 161 if( this == &i ) return *this; // guard for self assignment
162 delete d; // delete the old data because the Iterator was really constructed before 162 delete d; // delete the old data because the Iterator was really constructed before
163 d = new ConstIteratorData; 163 d = new ConstIteratorData;
164 d->mIt = i.d->mIt; 164 d->mIt = i.d->mIt;
165 return *this; 165 return *this;
166} 166}
167 167
168AddressBook::ConstIterator::~ConstIterator() 168AddressBook::ConstIterator::~ConstIterator()
169{ 169{
170 delete d; 170 delete d;
171} 171}
172 172
173const Addressee &AddressBook::ConstIterator::operator*() const 173const Addressee &AddressBook::ConstIterator::operator*() const
174{ 174{
175 return *(d->mIt); 175 return *(d->mIt);
176} 176}
177 177
178const Addressee* AddressBook::ConstIterator::operator->() const 178const Addressee* AddressBook::ConstIterator::operator->() const
179{ 179{
180 return &(*(d->mIt)); 180 return &(*(d->mIt));
181} 181}
182 182
183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
184{ 184{
185 (d->mIt)++; 185 (d->mIt)++;
186 return *this; 186 return *this;
187} 187}
188 188
189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
190{ 190{
191 (d->mIt)++; 191 (d->mIt)++;
192 return *this; 192 return *this;
193} 193}
194 194
195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
196{ 196{
197 (d->mIt)--; 197 (d->mIt)--;
198 return *this; 198 return *this;
199} 199}
200 200
201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
202{ 202{
203 (d->mIt)--; 203 (d->mIt)--;
204 return *this; 204 return *this;
205} 205}
206 206
207bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 207bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
208{ 208{
209 return ( d->mIt == it.d->mIt ); 209 return ( d->mIt == it.d->mIt );
210} 210}
211 211
212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
213{ 213{
214 return ( d->mIt != it.d->mIt ); 214 return ( d->mIt != it.d->mIt );
215} 215}
216 216
217 217
218AddressBook::AddressBook() 218AddressBook::AddressBook()
219{ 219{
220 init(0, "contact"); 220 init(0, "contact");
221} 221}
222 222
223AddressBook::AddressBook( const QString &config ) 223AddressBook::AddressBook( const QString &config )
224{ 224{
225 init(config, "contact"); 225 init(config, "contact");
226} 226}
227 227
228AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
229{ 229{
230 init(config, family); 230 init(config, family);
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false;
237 d = new AddressBookData; 238 d = new AddressBookData;
238 QString fami = family; 239 QString fami = family;
239 qDebug("new ab "); 240 qDebug("new ab ");
240 if (config != 0) { 241 if (config != 0) {
241 qDebug("config != 0 "); 242 qDebug("config != 0 ");
242 if ( family == "syncContact" ) { 243 if ( family == "syncContact" ) {
243 qDebug("creating sync config "); 244 qDebug("creating sync config ");
244 fami = "contact"; 245 fami = "contact";
245 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
246 con->setGroup( "General" ); 247 con->setGroup( "General" );
247 con->writeEntry( "ResourceKeys", QString("sync") ); 248 con->writeEntry( "ResourceKeys", QString("sync") );
248 con->writeEntry( "Standard", QString("sync") ); 249 con->writeEntry( "Standard", QString("sync") );
249 con->setGroup( "Resource_sync" ); 250 con->setGroup( "Resource_sync" );
250 con->writeEntry( "FileFormat", QString("vcard") ); 251 con->writeEntry( "FileFormat", QString("vcard") );
251 con->writeEntry( "FileName", config ); 252 con->writeEntry( "FileName", config );
252 con->writeEntry( "ResourceIdentifier", QString("sync") ); 253 con->writeEntry( "ResourceIdentifier", QString("sync") );
253 con->writeEntry( "ResourceName", QString("sync_res") ); 254 con->writeEntry( "ResourceName", QString("sync_res") );
254 con->writeEntry( "ResourceType", QString("file") ); 255 con->writeEntry( "ResourceType", QString("file") );
255 //con->sync(); 256 //con->sync();
256 d->mConfig = con; 257 d->mConfig = con;
257 } 258 }
258 else 259 else
259 d->mConfig = new KConfig( locateLocal("config", config) ); 260 d->mConfig = new KConfig( locateLocal("config", config) );
260// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 261// qDebug("AddressBook::init 1 config=%s",config.latin1() );
261 } 262 }
262 else { 263 else {
263 d->mConfig = 0; 264 d->mConfig = 0;
264// qDebug("AddressBook::init 1 config=0"); 265// qDebug("AddressBook::init 1 config=0");
265 } 266 }
266 267
267//US d->mErrorHandler = 0; 268//US d->mErrorHandler = 0;
268 d->mManager = new KRES::Manager<Resource>( fami, false ); 269 d->mManager = new KRES::Manager<Resource>( fami, false );
269 d->mManager->readConfig( d->mConfig ); 270 d->mManager->readConfig( d->mConfig );
270 if ( family == "syncContact" ) { 271 if ( family == "syncContact" ) {
271 KRES::Manager<Resource> *manager = d->mManager; 272 KRES::Manager<Resource> *manager = d->mManager;
272 KRES::Manager<Resource>::ActiveIterator it; 273 KRES::Manager<Resource>::ActiveIterator it;
273 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 274 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
274 (*it)->setAddressBook( this ); 275 (*it)->setAddressBook( this );
275 if ( !(*it)->open() ) 276 if ( !(*it)->open() )
276 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 277 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
277 } 278 }
278 Resource *res = standardResource(); 279 Resource *res = standardResource();
279 if ( !res ) { 280 if ( !res ) {
280 qDebug("ERROR: no standard resource"); 281 qDebug("ERROR: no standard resource");
281 res = manager->createResource( "file" ); 282 res = manager->createResource( "file" );
282 if ( res ) 283 if ( res )
283 { 284 {
284 addResource( res ); 285 addResource( res );
285 } 286 }
286 else 287 else
287 qDebug(" No resource available!!!"); 288 qDebug(" No resource available!!!");
288 } 289 }
289 setStandardResource( res ); 290 setStandardResource( res );
290 manager->writeConfig(); 291 manager->writeConfig();
291 } 292 }
292 addCustomField( i18n( "Department" ), KABC::Field::Organization, 293 addCustomField( i18n( "Department" ), KABC::Field::Organization,
293 "X-Department", "KADDRESSBOOK" ); 294 "X-Department", "KADDRESSBOOK" );
294 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 295 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
295 "X-Profession", "KADDRESSBOOK" ); 296 "X-Profession", "KADDRESSBOOK" );
296 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 297 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
297 "X-AssistantsName", "KADDRESSBOOK" ); 298 "X-AssistantsName", "KADDRESSBOOK" );
298 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 299 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
299 "X-ManagersName", "KADDRESSBOOK" ); 300 "X-ManagersName", "KADDRESSBOOK" );
300 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 301 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
301 "X-SpousesName", "KADDRESSBOOK" ); 302 "X-SpousesName", "KADDRESSBOOK" );
302 addCustomField( i18n( "Office" ), KABC::Field::Personal, 303 addCustomField( i18n( "Office" ), KABC::Field::Personal,
303 "X-Office", "KADDRESSBOOK" ); 304 "X-Office", "KADDRESSBOOK" );
304 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 305 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
305 "X-IMAddress", "KADDRESSBOOK" ); 306 "X-IMAddress", "KADDRESSBOOK" );
306 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 307 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
307 "X-Anniversary", "KADDRESSBOOK" ); 308 "X-Anniversary", "KADDRESSBOOK" );
308 309
309 //US added this field to become compatible with Opie/qtopia addressbook 310 //US added this field to become compatible with Opie/qtopia addressbook
310 // values can be "female" or "male" or "". An empty field represents undefined. 311 // values can be "female" or "male" or "". An empty field represents undefined.
311 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 312 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
312 "X-Gender", "KADDRESSBOOK" ); 313 "X-Gender", "KADDRESSBOOK" );
313 addCustomField( i18n( "Children" ), KABC::Field::Personal, 314 addCustomField( i18n( "Children" ), KABC::Field::Personal,
314 "X-Children", "KADDRESSBOOK" ); 315 "X-Children", "KADDRESSBOOK" );
315 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 316 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
316 "X-FreeBusyUrl", "KADDRESSBOOK" ); 317 "X-FreeBusyUrl", "KADDRESSBOOK" );
317 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 318 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
318 "X-ExternalID", "KADDRESSBOOK" ); 319 "X-ExternalID", "KADDRESSBOOK" );
319} 320}
320 321
321AddressBook::~AddressBook() 322AddressBook::~AddressBook()
322{ 323{
323 delete d->mConfig; d->mConfig = 0; 324 delete d->mConfig; d->mConfig = 0;
324 delete d->mManager; d->mManager = 0; 325 delete d->mManager; d->mManager = 0;
325//US delete d->mErrorHandler; d->mErrorHandler = 0; 326//US delete d->mErrorHandler; d->mErrorHandler = 0;
326 delete d; d = 0; 327 delete d; d = 0;
327} 328}
328 329
329bool AddressBook::load() 330bool AddressBook::load()
330{ 331{
331 332
332 333
333 clear(); 334 clear();
334 335
335 KRES::Manager<Resource>::ActiveIterator it; 336 KRES::Manager<Resource>::ActiveIterator it;
336 bool ok = true; 337 bool ok = true;
337 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
338 if ( !(*it)->load() ) { 339 if ( !(*it)->load() ) {
339 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 340 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
340 ok = false; 341 ok = false;
341 } 342 }
342 343
343 // mark all addressees as unchanged 344 // mark all addressees as unchanged
344 Addressee::List::Iterator addrIt; 345 Addressee::List::Iterator addrIt;
345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
346 (*addrIt).setChanged( false ); 347 (*addrIt).setChanged( false );
347 348
349 blockLSEchange = true;
348 return ok; 350 return ok;
349} 351}
350 352
351bool AddressBook::save( Ticket *ticket ) 353bool AddressBook::save( Ticket *ticket )
352{ 354{
353 kdDebug(5700) << "AddressBook::save()"<< endl; 355 kdDebug(5700) << "AddressBook::save()"<< endl;
354 356
355 if ( ticket->resource() ) { 357 if ( ticket->resource() ) {
356 deleteRemovedAddressees(); 358 deleteRemovedAddressees();
357 return ticket->resource()->save( ticket ); 359 return ticket->resource()->save( ticket );
358 } 360 }
359 361
360 return false; 362 return false;
361} 363}
362bool AddressBook::saveAB() 364bool AddressBook::saveAB()
363{ 365{
364 bool ok = true; 366 bool ok = true;
365 367
366 deleteRemovedAddressees(); 368 deleteRemovedAddressees();
367 369
368 KRES::Manager<Resource>::ActiveIterator it; 370 KRES::Manager<Resource>::ActiveIterator it;
369 KRES::Manager<Resource> *manager = d->mManager; 371 KRES::Manager<Resource> *manager = d->mManager;
370 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 372 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
371 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 373 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
372 Ticket *ticket = requestSaveTicket( *it ); 374 Ticket *ticket = requestSaveTicket( *it );
373// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 375// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
374 if ( !ticket ) { 376 if ( !ticket ) {
375 error( i18n( "Unable to save to resource '%1'. It is locked." ) 377 error( i18n( "Unable to save to resource '%1'. It is locked." )
376 .arg( (*it)->resourceName() ) ); 378 .arg( (*it)->resourceName() ) );
377 return false; 379 return false;
378 } 380 }
379 381
380 //if ( !save( ticket ) ) 382 //if ( !save( ticket ) )
381 if ( ticket->resource() ) { 383 if ( ticket->resource() ) {
382 if ( ! ticket->resource()->save( ticket ) ) 384 if ( ! ticket->resource()->save( ticket ) )
383 ok = false; 385 ok = false;
384 } else 386 } else
385 ok = false; 387 ok = false;
386 388
387 } 389 }
388 } 390 }
389 return ok; 391 return ok;
390} 392}
391 393
392AddressBook::Iterator AddressBook::begin() 394AddressBook::Iterator AddressBook::begin()
393{ 395{
394 Iterator it = Iterator(); 396 Iterator it = Iterator();
395 it.d->mIt = d->mAddressees.begin(); 397 it.d->mIt = d->mAddressees.begin();
396 return it; 398 return it;
397} 399}
398 400
399AddressBook::ConstIterator AddressBook::begin() const 401AddressBook::ConstIterator AddressBook::begin() const
400{ 402{
401 ConstIterator it = ConstIterator(); 403 ConstIterator it = ConstIterator();
402 it.d->mIt = d->mAddressees.begin(); 404 it.d->mIt = d->mAddressees.begin();
403 return it; 405 return it;
404} 406}
405 407
406AddressBook::Iterator AddressBook::end() 408AddressBook::Iterator AddressBook::end()
407{ 409{
408 Iterator it = Iterator(); 410 Iterator it = Iterator();
409 it.d->mIt = d->mAddressees.end(); 411 it.d->mIt = d->mAddressees.end();
410 return it; 412 return it;
411} 413}
412 414
413AddressBook::ConstIterator AddressBook::end() const 415AddressBook::ConstIterator AddressBook::end() const
414{ 416{
415 ConstIterator it = ConstIterator(); 417 ConstIterator it = ConstIterator();
416 it.d->mIt = d->mAddressees.end(); 418 it.d->mIt = d->mAddressees.end();
417 return it; 419 return it;
418} 420}
419 421
420void AddressBook::clear() 422void AddressBook::clear()
421{ 423{
422 d->mAddressees.clear(); 424 d->mAddressees.clear();
423} 425}
424 426
425Ticket *AddressBook::requestSaveTicket( Resource *resource ) 427Ticket *AddressBook::requestSaveTicket( Resource *resource )
426{ 428{
427 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 429 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
428 430
429 if ( !resource ) 431 if ( !resource )
430 { 432 {
431 qDebug("AddressBook::requestSaveTicket no resource" ); 433 qDebug("AddressBook::requestSaveTicket no resource" );
432 resource = standardResource(); 434 resource = standardResource();
433 } 435 }
434 436
435 KRES::Manager<Resource>::ActiveIterator it; 437 KRES::Manager<Resource>::ActiveIterator it;
436 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 438 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
437 if ( (*it) == resource ) { 439 if ( (*it) == resource ) {
438 if ( (*it)->readOnly() || !(*it)->isOpen() ) 440 if ( (*it)->readOnly() || !(*it)->isOpen() )
439 return 0; 441 return 0;
440 else 442 else
441 return (*it)->requestSaveTicket(); 443 return (*it)->requestSaveTicket();
442 } 444 }
443 } 445 }
444 446
445 return 0; 447 return 0;
446} 448}
447 449
448void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 450void AddressBook::insertAddressee( const Addressee &a, bool setRev )
449{ 451{
450 Addressee::List::Iterator it; 452 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 453 return;
452 if ( a.uid() == (*it).uid() ) { 454 }
453 if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 455 bool found = false;
454 return; 456 Addressee::List::Iterator it;
455 } 457 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
456 bool changed = false; 458 if ( a.uid() == (*it).uid() ) {
457 Addressee addr = a; 459
458 if ( addr != (*it) ) 460 bool changed = false;
459 changed = true; 461 Addressee addr = a;
460 462 if ( addr != (*it) )
461 (*it) = a; 463 changed = true;
462 if ( (*it).resource() == 0 ) 464
463 (*it).setResource( standardResource() ); 465 (*it) = a;
464 466 if ( (*it).resource() == 0 )
465 if ( changed ) { 467 (*it).setResource( standardResource() );
466 if ( setRev ) { 468
469 if ( changed ) {
470 if ( setRev ) {
467 471
468 // get rid of micro seconds 472 // get rid of micro seconds
469 QDateTime dt = QDateTime::currentDateTime(); 473 QDateTime dt = QDateTime::currentDateTime();
470 QTime t = dt.time(); 474 QTime t = dt.time();
471 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 475 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
472 (*it).setRevision( dt ); 476 (*it).setRevision( dt );
473 } 477 }
474 (*it).setChanged( true ); 478 (*it).setChanged( true );
475 } 479 }
476 480
477 return; 481 found = true;
482 } else {
483 if ( (*it).uid() == QString("last-syncAddressee-") ) {
484 QString name = (*it).uid().mid( 19 );
485 Addressee b = a;
486 QString id = b.getID( name );
487 if ( ! id.isEmpty() ) {
488 QString des = (*it).note();
489 int startN;
490 if( (startN = des.find( id ) ) >= 0 ) {
491 int endN = des.find( ",", startN+1 );
492 des = des.left( startN ) + des.mid( endN+1 );
493 (*it).setNote( des );
494 }
495 }
496 }
497 }
478 } 498 }
479 } 499 if ( found )
480 d->mAddressees.append( a ); 500 return;
481 Addressee& addr = d->mAddressees.last(); 501 d->mAddressees.append( a );
482 if ( addr.resource() == 0 ) 502 Addressee& addr = d->mAddressees.last();
483 addr.setResource( standardResource() ); 503 if ( addr.resource() == 0 )
504 addr.setResource( standardResource() );
484 505
485 addr.setChanged( true ); 506 addr.setChanged( true );
486} 507}
487 508
488void AddressBook::removeAddressee( const Addressee &a ) 509void AddressBook::removeAddressee( const Addressee &a )
489{ 510{
490 Iterator it; 511 Iterator it;
512 Iterator it2;
513 bool found = false;
491 for ( it = begin(); it != end(); ++it ) { 514 for ( it = begin(); it != end(); ++it ) {
492 if ( a.uid() == (*it).uid() ) { 515 if ( a.uid() == (*it).uid() ) {
493 removeAddressee( it ); 516 found = true;
494 return; 517 it2 = it;
518 } else {
519 if ( (*it).uid() == QString("last-syncAddressee-") ) {
520 QString name = (*it).uid().mid( 19 );
521 Addressee b = a;
522 QString id = b.getID( name );
523 if ( ! id.isEmpty() ) {
524 QString des = (*it).note();
525 if( des.find( id ) < 0 ) {
526 des += id + ",";
527 (*it).setNote( des );
528 }
529 }
530 }
531
495 } 532 }
496 } 533 }
534
535 if ( found )
536 removeAddressee( it2 );
537
538}
539
540void AddressBook::removeDeletedAddressees()
541{
542 deleteRemovedAddressees();
543 Iterator it = begin();
544 Iterator it2 ;
545 QDateTime dt ( QDate( 2004,1,1) );
546 while ( it != end() ) {
547 (*it).setRevision( dt );
548 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
549 it2 = it;
550 ++it;
551 removeAddressee( it2 );
552 } else
553 ++it;
554 }
555 deleteRemovedAddressees();
497} 556}
498 557
499void AddressBook::removeAddressee( const Iterator &it ) 558void AddressBook::removeAddressee( const Iterator &it )
500{ 559{
501 d->mRemovedAddressees.append( (*it) ); 560 d->mRemovedAddressees.append( (*it) );
502 d->mAddressees.remove( it.d->mIt ); 561 d->mAddressees.remove( it.d->mIt );
503} 562}
504 563
505AddressBook::Iterator AddressBook::find( const Addressee &a ) 564AddressBook::Iterator AddressBook::find( const Addressee &a )
506{ 565{
507 Iterator it; 566 Iterator it;
508 for ( it = begin(); it != end(); ++it ) { 567 for ( it = begin(); it != end(); ++it ) {
509 if ( a.uid() == (*it).uid() ) { 568 if ( a.uid() == (*it).uid() ) {
510 return it; 569 return it;
511 } 570 }
512 } 571 }
513 return end(); 572 return end();
514} 573}
515 574
516Addressee AddressBook::findByUid( const QString &uid ) 575Addressee AddressBook::findByUid( const QString &uid )
517{ 576{
518 Iterator it; 577 Iterator it;
519 for ( it = begin(); it != end(); ++it ) { 578 for ( it = begin(); it != end(); ++it ) {
520 if ( uid == (*it).uid() ) { 579 if ( uid == (*it).uid() ) {
521 return *it; 580 return *it;
522 } 581 }
523 } 582 }
524 return Addressee(); 583 return Addressee();
525} 584}
585#if 0
526Addressee::List AddressBook::getExternLastSyncAddressees() 586Addressee::List AddressBook::getExternLastSyncAddressees()
527{ 587{
528 Addressee::List results; 588 Addressee::List results;
529 589
530 Iterator it; 590 Iterator it;
531 for ( it = begin(); it != end(); ++it ) { 591 for ( it = begin(); it != end(); ++it ) {
532 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 592 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
533 if ( (*it).familyName().left(3) == "E: " ) 593 if ( (*it).familyName().left(4) == "!E: " )
534 results.append( *it ); 594 results.append( *it );
535 } 595 }
536 } 596 }
537 597
538 return results; 598 return results;
539} 599}
600#endif
540void AddressBook::resetTempSyncStat() 601void AddressBook::resetTempSyncStat()
541{ 602{
542 Iterator it; 603 Iterator it;
543 for ( it = begin(); it != end(); ++it ) { 604 for ( it = begin(); it != end(); ++it ) {
544 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 605 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
545 } 606 }
546 607
547} 608}
548 609
549QStringList AddressBook:: uidList() 610QStringList AddressBook:: uidList()
550{ 611{
551 QStringList results; 612 QStringList results;
552 Iterator it; 613 Iterator it;
553 for ( it = begin(); it != end(); ++it ) { 614 for ( it = begin(); it != end(); ++it ) {
554 results.append( (*it).uid() ); 615 results.append( (*it).uid() );
555 } 616 }
556 return results; 617 return results;
557} 618}
558 619
559 620
560Addressee::List AddressBook::allAddressees() 621Addressee::List AddressBook::allAddressees()
561{ 622{
562 return d->mAddressees; 623 return d->mAddressees;
563 624
564} 625}
565 626
566Addressee::List AddressBook::findByName( const QString &name ) 627Addressee::List AddressBook::findByName( const QString &name )
567{ 628{
568 Addressee::List results; 629 Addressee::List results;
569 630
570 Iterator it; 631 Iterator it;
571 for ( it = begin(); it != end(); ++it ) { 632 for ( it = begin(); it != end(); ++it ) {
572 if ( name == (*it).realName() ) { 633 if ( name == (*it).realName() ) {
573 results.append( *it ); 634 results.append( *it );
574 } 635 }
575 } 636 }
576 637
577 return results; 638 return results;
578} 639}
579 640
580Addressee::List AddressBook::findByEmail( const QString &email ) 641Addressee::List AddressBook::findByEmail( const QString &email )
581{ 642{
582 Addressee::List results; 643 Addressee::List results;
583 QStringList mailList; 644 QStringList mailList;
584 645
585 Iterator it; 646 Iterator it;
586 for ( it = begin(); it != end(); ++it ) { 647 for ( it = begin(); it != end(); ++it ) {
587 mailList = (*it).emails(); 648 mailList = (*it).emails();
588 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 649 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
589 if ( email == (*ite) ) { 650 if ( email == (*ite) ) {
590 results.append( *it ); 651 results.append( *it );
591 } 652 }
592 } 653 }
593 } 654 }
594 655
595 return results; 656 return results;
596} 657}
597 658
598Addressee::List AddressBook::findByCategory( const QString &category ) 659Addressee::List AddressBook::findByCategory( const QString &category )
599{ 660{
600 Addressee::List results; 661 Addressee::List results;
601 662
602 Iterator it; 663 Iterator it;
603 for ( it = begin(); it != end(); ++it ) { 664 for ( it = begin(); it != end(); ++it ) {
604 if ( (*it).hasCategory( category) ) { 665 if ( (*it).hasCategory( category) ) {
605 results.append( *it ); 666 results.append( *it );
606 } 667 }
607 } 668 }
608 669
609 return results; 670 return results;
610} 671}
611 672
612void AddressBook::dump() const 673void AddressBook::dump() const
613{ 674{
614 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 675 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
615 676
616 ConstIterator it; 677 ConstIterator it;
617 for( it = begin(); it != end(); ++it ) { 678 for( it = begin(); it != end(); ++it ) {
618 (*it).dump(); 679 (*it).dump();
619 } 680 }
620 681
621 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 682 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
622} 683}
623 684
624QString AddressBook::identifier() 685QString AddressBook::identifier()
625{ 686{
626 QStringList identifier; 687 QStringList identifier;
627 688
628 689
629 KRES::Manager<Resource>::ActiveIterator it; 690 KRES::Manager<Resource>::ActiveIterator it;
630 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 691 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
631 if ( !(*it)->identifier().isEmpty() ) 692 if ( !(*it)->identifier().isEmpty() )
632 identifier.append( (*it)->identifier() ); 693 identifier.append( (*it)->identifier() );
633 } 694 }
634 695
635 return identifier.join( ":" ); 696 return identifier.join( ":" );
636} 697}
637 698
638Field::List AddressBook::fields( int category ) 699Field::List AddressBook::fields( int category )
639{ 700{
640 if ( d->mAllFields.isEmpty() ) { 701 if ( d->mAllFields.isEmpty() ) {
641 d->mAllFields = Field::allFields(); 702 d->mAllFields = Field::allFields();
642 } 703 }
643 704
644 if ( category == Field::All ) return d->mAllFields; 705 if ( category == Field::All ) return d->mAllFields;
645 706
646 Field::List result; 707 Field::List result;
647 Field::List::ConstIterator it; 708 Field::List::ConstIterator it;
648 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 709 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
649 if ( (*it)->category() & category ) result.append( *it ); 710 if ( (*it)->category() & category ) result.append( *it );
650 } 711 }
651 712
652 return result; 713 return result;
653} 714}
654 715
655bool AddressBook::addCustomField( const QString &label, int category, 716bool AddressBook::addCustomField( const QString &label, int category,
656 const QString &key, const QString &app ) 717 const QString &key, const QString &app )
657{ 718{
658 if ( d->mAllFields.isEmpty() ) { 719 if ( d->mAllFields.isEmpty() ) {
659 d->mAllFields = Field::allFields(); 720 d->mAllFields = Field::allFields();
660 } 721 }
661//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 722//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
662 QString a = app.isNull() ? KGlobal::getAppName() : app; 723 QString a = app.isNull() ? KGlobal::getAppName() : app;
663 724
664 QString k = key.isNull() ? label : key; 725 QString k = key.isNull() ? label : key;
665 726
666 Field *field = Field::createCustomField( label, category, k, a ); 727 Field *field = Field::createCustomField( label, category, k, a );
667 728
668 if ( !field ) return false; 729 if ( !field ) return false;
669 730
670 d->mAllFields.append( field ); 731 d->mAllFields.append( field );
671 732
672 return true; 733 return true;
673} 734}
674 735
675QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 736QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
676{ 737{
677 if (!ab.d) return s; 738 if (!ab.d) return s;
678 739
679 return s << ab.d->mAddressees; 740 return s << ab.d->mAddressees;
680} 741}
681 742
682QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 743QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
683{ 744{
684 if (!ab.d) return s; 745 if (!ab.d) return s;
685 746
686 s >> ab.d->mAddressees; 747 s >> ab.d->mAddressees;
687 748
688 return s; 749 return s;
689} 750}
690 751
691bool AddressBook::addResource( Resource *resource ) 752bool AddressBook::addResource( Resource *resource )
692{ 753{
693 if ( !resource->open() ) { 754 if ( !resource->open() ) {
694 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 755 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
695 return false; 756 return false;
696 } 757 }
697 758
698 resource->setAddressBook( this ); 759 resource->setAddressBook( this );
699 760
700 d->mManager->add( resource ); 761 d->mManager->add( resource );
701 return true; 762 return true;
702} 763}
703 764
704bool AddressBook::removeResource( Resource *resource ) 765bool AddressBook::removeResource( Resource *resource )
705{ 766{
706 resource->close(); 767 resource->close();
707 768
708 if ( resource == standardResource() ) 769 if ( resource == standardResource() )
709 d->mManager->setStandardResource( 0 ); 770 d->mManager->setStandardResource( 0 );
710 771
711 resource->setAddressBook( 0 ); 772 resource->setAddressBook( 0 );
712 773
713 d->mManager->remove( resource ); 774 d->mManager->remove( resource );
714 return true; 775 return true;
715} 776}
716 777
717QPtrList<Resource> AddressBook::resources() 778QPtrList<Resource> AddressBook::resources()
718{ 779{
719 QPtrList<Resource> list; 780 QPtrList<Resource> list;
720 781
721// qDebug("AddressBook::resources() 1"); 782// qDebug("AddressBook::resources() 1");
722 783
723 KRES::Manager<Resource>::ActiveIterator it; 784 KRES::Manager<Resource>::ActiveIterator it;
724 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 785 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
725 list.append( *it ); 786 list.append( *it );
726 787
727 return list; 788 return list;
728} 789}
729 790
730/*US 791/*US
731void AddressBook::setErrorHandler( ErrorHandler *handler ) 792void AddressBook::setErrorHandler( ErrorHandler *handler )
732{ 793{
733 delete d->mErrorHandler; 794 delete d->mErrorHandler;
734 d->mErrorHandler = handler; 795 d->mErrorHandler = handler;
735} 796}
736*/ 797*/
737 798
738void AddressBook::error( const QString& msg ) 799void AddressBook::error( const QString& msg )
739{ 800{
740/*US 801/*US
741 if ( !d->mErrorHandler ) // create default error handler 802 if ( !d->mErrorHandler ) // create default error handler
742 d->mErrorHandler = new ConsoleErrorHandler; 803 d->mErrorHandler = new ConsoleErrorHandler;
743 804
744 if ( d->mErrorHandler ) 805 if ( d->mErrorHandler )
745 d->mErrorHandler->error( msg ); 806 d->mErrorHandler->error( msg );
746 else 807 else
747 kdError(5700) << "no error handler defined" << endl; 808 kdError(5700) << "no error handler defined" << endl;
748*/ 809*/
749 kdDebug(5700) << "msg" << endl; 810 kdDebug(5700) << "msg" << endl;
750 qDebug(msg); 811 qDebug(msg);
751} 812}
752 813
753void AddressBook::deleteRemovedAddressees() 814void AddressBook::deleteRemovedAddressees()
754{ 815{
755 Addressee::List::Iterator it; 816 Addressee::List::Iterator it;
756 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 817 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
757 Resource *resource = (*it).resource(); 818 Resource *resource = (*it).resource();
758 if ( resource && !resource->readOnly() && resource->isOpen() ) 819 if ( resource && !resource->readOnly() && resource->isOpen() )
759 resource->removeAddressee( *it ); 820 resource->removeAddressee( *it );
760 } 821 }
761 822
762 d->mRemovedAddressees.clear(); 823 d->mRemovedAddressees.clear();
763} 824}
764 825
765void AddressBook::setStandardResource( Resource *resource ) 826void AddressBook::setStandardResource( Resource *resource )
766{ 827{
767// qDebug("AddressBook::setStandardResource 1"); 828// qDebug("AddressBook::setStandardResource 1");
768 d->mManager->setStandardResource( resource ); 829 d->mManager->setStandardResource( resource );
769} 830}
770 831
771Resource *AddressBook::standardResource() 832Resource *AddressBook::standardResource()
772{ 833{
773 return d->mManager->standardResource(); 834 return d->mManager->standardResource();
774} 835}
775 836
776KRES::Manager<Resource> *AddressBook::resourceManager() 837KRES::Manager<Resource> *AddressBook::resourceManager()
777{ 838{
778 return d->mManager; 839 return d->mManager;
779} 840}
780 841
781void AddressBook::cleanUp() 842void AddressBook::cleanUp()
782{ 843{
783 KRES::Manager<Resource>::ActiveIterator it; 844 KRES::Manager<Resource>::ActiveIterator it;
784 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 845 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
785 if ( !(*it)->readOnly() && (*it)->isOpen() ) 846 if ( !(*it)->readOnly() && (*it)->isOpen() )
786 (*it)->cleanUp(); 847 (*it)->cleanUp();
787 } 848 }
788} 849}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 253de68..2f2678b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,334 +1,336 @@
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_ADDRESSBOOK_H 28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H 29#define KABC_ADDRESSBOOK_H
30 30
31#include <qobject.h> 31#include <qobject.h>
32 32
33#include <kresources/manager.h> 33#include <kresources/manager.h>
34#include <qptrlist.h> 34#include <qptrlist.h>
35 35
36#include "addressee.h" 36#include "addressee.h"
37#include "field.h" 37#include "field.h"
38 38
39namespace KABC { 39namespace KABC {
40 40
41class ErrorHandler; 41class ErrorHandler;
42class Resource; 42class Resource;
43class Ticket; 43class Ticket;
44 44
45/** 45/**
46 @short Address Book 46 @short Address Book
47 47
48 This class provides access to a collection of address book entries. 48 This class provides access to a collection of address book entries.
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 145
146 /** 146 /**
147 Returns a iterator for first entry of address book. 147 Returns a iterator for first entry of address book.
148 */ 148 */
149 Iterator begin(); 149 Iterator begin();
150 150
151 /** 151 /**
152 Returns a const iterator for first entry of address book. 152 Returns a const iterator for first entry of address book.
153 */ 153 */
154 ConstIterator begin() const; 154 ConstIterator begin() const;
155 155
156 /** 156 /**
157 Returns a iterator for first entry of address book. 157 Returns a iterator for first entry of address book.
158 */ 158 */
159 Iterator end(); 159 Iterator end();
160 160
161 /** 161 /**
162 Returns a const iterator for first entry of address book. 162 Returns a const iterator for first entry of address book.
163 */ 163 */
164 ConstIterator end() const; 164 ConstIterator end() const;
165 165
166 /** 166 /**
167 Removes all entries from address book. 167 Removes all entries from address book.
168 */ 168 */
169 void clear(); 169 void clear();
170 170
171 /** 171 /**
172 Insert an Addressee object into address book. If an object with the same 172 Insert an Addressee object into address book. If an object with the same
173 unique id already exists in the address book it it replaced by the new 173 unique id already exists in the address book it it replaced by the new
174 one. If not the new object is appended to the address book. 174 one. If not the new object is appended to the address book.
175 */ 175 */
176 void insertAddressee( const Addressee &, bool setRev = true ); 176 void insertAddressee( const Addressee &, bool setRev = true );
177 177
178 /** 178 /**
179 Removes entry from the address book. 179 Removes entry from the address book.
180 */ 180 */
181 void removeAddressee( const Addressee & ); 181 void removeAddressee( const Addressee & );
182 182
183 /** 183 /**
184 This is like @ref removeAddressee() just above, with the difference that 184 This is like @ref removeAddressee() just above, with the difference that
185 the first element is a iterator, returned by @ref begin(). 185 the first element is a iterator, returned by @ref begin().
186 */ 186 */
187 void removeAddressee( const Iterator & ); 187 void removeAddressee( const Iterator & );
188 188
189 /** 189 /**
190 Find the specified entry in address book. Returns end(), if the entry 190 Find the specified entry in address book. Returns end(), if the entry
191 couldn't be found. 191 couldn't be found.
192 */ 192 */
193 Iterator find( const Addressee & ); 193 Iterator find( const Addressee & );
194 194
195 /** 195 /**
196 Find the entry specified by an unique id. Returns an empty Addressee 196 Find the entry specified by an unique id. Returns an empty Addressee
197 object, if the address book does not contain an entry with this id. 197 object, if the address book does not contain an entry with this id.
198 */ 198 */
199 Addressee findByUid( const QString & ); 199 Addressee findByUid( const QString & );
200 200
201 201
202 /** 202 /**
203 Returns a list of all addressees in the address book. This list can 203 Returns a list of all addressees in the address book. This list can
204 be sorted with @ref KABC::AddresseeList for example. 204 be sorted with @ref KABC::AddresseeList for example.
205 */ 205 */
206 Addressee::List allAddressees(); 206 Addressee::List allAddressees();
207 207
208 /** 208 /**
209 Find all entries with the specified name in the address book. Returns 209 Find all entries with the specified name in the address book. Returns
210 an empty list, if no entries could be found. 210 an empty list, if no entries could be found.
211 */ 211 */
212 Addressee::List findByName( const QString & ); 212 Addressee::List findByName( const QString & );
213 213
214 /** 214 /**
215 Find all entries with the specified email address in the address book. 215 Find all entries with the specified email address in the address book.
216 Returns an empty list, if no entries could be found. 216 Returns an empty list, if no entries could be found.
217 */ 217 */
218 Addressee::List findByEmail( const QString & ); 218 Addressee::List findByEmail( const QString & );
219 219
220 /** 220 /**
221 Find all entries wich have the specified category in the address book. 221 Find all entries wich have the specified category in the address book.
222 Returns an empty list, if no entries could be found. 222 Returns an empty list, if no entries could be found.
223 */ 223 */
224 Addressee::List findByCategory( const QString & ); 224 Addressee::List findByCategory( const QString & );
225 225
226 /** 226 /**
227 Return a string identifying this addressbook. 227 Return a string identifying this addressbook.
228 */ 228 */
229 virtual QString identifier(); 229 virtual QString identifier();
230 230
231 /** 231 /**
232 Used for debug output. 232 Used for debug output.
233 */ 233 */
234 void dump() const; 234 void dump() const;
235 235
236 void emitAddressBookLocked() { emit addressBookLocked( this ); } 236 void emitAddressBookLocked() { emit addressBookLocked( this ); }
237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
238 void emitAddressBookChanged() { emit addressBookChanged( this ); } 238 void emitAddressBookChanged() { emit addressBookChanged( this ); }
239 239
240 /** 240 /**
241 Return list of all Fields known to the address book which are associated 241 Return list of all Fields known to the address book which are associated
242 with the given field category. 242 with the given field category.
243 */ 243 */
244 Field::List fields( int category = Field::All ); 244 Field::List fields( int category = Field::All );
245 245
246 /** 246 /**
247 Add custom field to address book. 247 Add custom field to address book.
248 248
249 @param label User visible label of the field. 249 @param label User visible label of the field.
250 @param category Ored list of field categories. 250 @param category Ored list of field categories.
251 @param key Identifier used as key for reading and writing the field. 251 @param key Identifier used as key for reading and writing the field.
252 @param app String used as application key for reading and writing 252 @param app String used as application key for reading and writing
253 the field. 253 the field.
254 */ 254 */
255 bool addCustomField( const QString &label, int category = Field::All, 255 bool addCustomField( const QString &label, int category = Field::All,
256 const QString &key = QString::null, 256 const QString &key = QString::null,
257 const QString &app = QString::null ); 257 const QString &app = QString::null );
258 258
259 259
260 /** 260 /**
261 Add address book resource. 261 Add address book resource.
262 */ 262 */
263 bool addResource( Resource * ); 263 bool addResource( Resource * );
264 264
265 /** 265 /**
266 Remove address book resource. 266 Remove address book resource.
267 */ 267 */
268 bool removeResource( Resource * ); 268 bool removeResource( Resource * );
269 269
270 /** 270 /**
271 Return pointer list of all resources. 271 Return pointer list of all resources.
272 */ 272 */
273 QPtrList<Resource> resources(); 273 QPtrList<Resource> resources();
274 274
275 /** 275 /**
276 Set the @p ErrorHandler, that is used by @ref error() to 276 Set the @p ErrorHandler, that is used by @ref error() to
277 provide gui-independend error messages. 277 provide gui-independend error messages.
278 */ 278 */
279 void setErrorHandler( ErrorHandler * ); 279 void setErrorHandler( ErrorHandler * );
280 280
281 /** 281 /**
282 Shows gui independend error messages. 282 Shows gui independend error messages.
283 */ 283 */
284 void error( const QString& ); 284 void error( const QString& );
285 285
286 /** 286 /**
287 Query all resources to clean up their lock files 287 Query all resources to clean up their lock files
288 */ 288 */
289 void cleanUp(); 289 void cleanUp();
290 290
291 // sync stuff 291 // sync stuff
292 Addressee::List getExternLastSyncAddressees(); 292 //Addressee::List getExternLastSyncAddressees();
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList(); 294 QStringList uidList();
295 void removeDeletedAddressees();
295 296
296 297
297 signals: 298 signals:
298 /** 299 /**
299 Emitted, when the address book has changed on disk. 300 Emitted, when the address book has changed on disk.
300 */ 301 */
301 void addressBookChanged( AddressBook * ); 302 void addressBookChanged( AddressBook * );
302 303
303 /** 304 /**
304 Emitted, when the address book has been locked for writing. 305 Emitted, when the address book has been locked for writing.
305 */ 306 */
306 void addressBookLocked( AddressBook * ); 307 void addressBookLocked( AddressBook * );
307 308
308 /** 309 /**
309 Emitted, when the address book has been unlocked. 310 Emitted, when the address book has been unlocked.
310 */ 311 */
311 void addressBookUnlocked( AddressBook * ); 312 void addressBookUnlocked( AddressBook * );
312 313
313 protected: 314 protected:
314 void deleteRemovedAddressees(); 315 void deleteRemovedAddressees();
315 void setStandardResource( Resource * ); 316 void setStandardResource( Resource * );
316 Resource *standardResource(); 317 Resource *standardResource();
317 KRES::Manager<Resource> *resourceManager(); 318 KRES::Manager<Resource> *resourceManager();
318 319
319 void init(const QString &config, const QString &family); 320 void init(const QString &config, const QString &family);
320 321
321 private: 322 private:
322//US QPtrList<Resource> mDummy; // Remove in KDE 4 323//US QPtrList<Resource> mDummy; // Remove in KDE 4
323 324
324 325
325 struct AddressBookData; 326 struct AddressBookData;
326 AddressBookData *d; 327 AddressBookData *d;
328 bool blockLSEchange;
327}; 329};
328 330
329QDataStream &operator<<( QDataStream &, const AddressBook & ); 331QDataStream &operator<<( QDataStream &, const AddressBook & );
330QDataStream &operator>>( QDataStream &, AddressBook & ); 332QDataStream &operator>>( QDataStream &, AddressBook & );
331 333
332} 334}
333 335
334#endif 336#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 7f04d8f..0f5d605 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,1683 +1,1778 @@
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 );
46 46
47struct Addressee::AddresseeData : public KShared 47struct Addressee::AddresseeData : public KShared
48{ 48{
49 QString uid; 49 QString uid;
50 QString name; 50 QString name;
51 QString formattedName; 51 QString formattedName;
52 QString familyName; 52 QString familyName;
53 QString givenName; 53 QString givenName;
54 QString additionalName; 54 QString additionalName;
55 QString prefix; 55 QString prefix;
56 QString suffix; 56 QString suffix;
57 QString nickName; 57 QString nickName;
58 QDateTime birthday; 58 QDateTime birthday;
59 QString mailer; 59 QString mailer;
60 TimeZone timeZone; 60 TimeZone timeZone;
61 Geo geo; 61 Geo geo;
62 QString title; 62 QString title;
63 QString role; 63 QString role;
64 QString organization; 64 QString organization;
65 QString note; 65 QString note;
66 QString productId; 66 QString productId;
67 QDateTime revision; 67 QDateTime revision;
68 QString sortString; 68 QString sortString;
69 KURL url; 69 KURL url;
70 Secrecy secrecy; 70 Secrecy secrecy;
71 Picture logo; 71 Picture logo;
72 Picture photo; 72 Picture photo;
73 Sound sound; 73 Sound sound;
74 Agent agent; 74 Agent agent;
75 QString mExternalId; 75 QString mExternalId;
76 PhoneNumber::List phoneNumbers; 76 PhoneNumber::List phoneNumbers;
77 Address::List addresses; 77 Address::List addresses;
78 Key::List keys; 78 Key::List keys;
79 QStringList emails; 79 QStringList emails;
80 QStringList categories; 80 QStringList categories;
81 QStringList custom; 81 QStringList custom;
82 82
83 Resource *resource; 83 Resource *resource;
84 84
85 bool empty :1; 85 bool empty :1;
86 bool changed :1; 86 bool changed :1;
87}; 87};
88 88
89Addressee::Addressee() 89Addressee::Addressee()
90{ 90{
91 mData = new AddresseeData; 91 mData = new AddresseeData;
92 mData->empty = true; 92 mData->empty = true;
93 mData->changed = false; 93 mData->changed = false;
94 mData->resource = 0; 94 mData->resource = 0;
95 mData->mExternalId = ":"; 95 mData->mExternalId = ":";
96 mData->revision = QDateTime ( QDate( 2004,1,1)); 96 mData->revision = QDateTime ( QDate( 2004,1,1));
97 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 97 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
98} 98}
99 99
100Addressee::~Addressee() 100Addressee::~Addressee()
101{ 101{
102} 102}
103 103
104Addressee::Addressee( const Addressee &a ) 104Addressee::Addressee( const Addressee &a )
105{ 105{
106 mData = a.mData; 106 mData = a.mData;
107 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 107 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
108} 108}
109 109
110Addressee &Addressee::operator=( const Addressee &a ) 110Addressee &Addressee::operator=( const Addressee &a )
111{ 111{
112 mData = a.mData; 112 mData = a.mData;
113 return (*this); 113 return (*this);
114} 114}
115 115
116Addressee Addressee::copy() 116Addressee Addressee::copy()
117{ 117{
118 Addressee a; 118 Addressee a;
119 *(a.mData) = *mData; 119 *(a.mData) = *mData;
120 return a; 120 return a;
121} 121}
122 122
123void Addressee::detach() 123void Addressee::detach()
124{ 124{
125 if ( mData.count() == 1 ) return; 125 if ( mData.count() == 1 ) return;
126 *this = copy(); 126 *this = copy();
127} 127}
128 128
129bool Addressee::operator==( const Addressee &a ) const 129bool Addressee::operator==( const Addressee &a ) const
130{ 130{
131 if ( uid() != a.uid() ) return false; 131 if ( uid() != a.uid() ) return false;
132 if ( mData->name != a.mData->name ) return false; 132 if ( mData->name != a.mData->name ) return false;
133 if ( mData->formattedName != a.mData->formattedName ) return false; 133 if ( mData->formattedName != a.mData->formattedName ) return false;
134 if ( mData->familyName != a.mData->familyName ) return false; 134 if ( mData->familyName != a.mData->familyName ) return false;
135 if ( mData->givenName != a.mData->givenName ) return false; 135 if ( mData->givenName != a.mData->givenName ) return false;
136 if ( mData->additionalName != a.mData->additionalName ) return false; 136 if ( mData->additionalName != a.mData->additionalName ) return false;
137 if ( mData->prefix != a.mData->prefix ) return false; 137 if ( mData->prefix != a.mData->prefix ) return false;
138 if ( mData->suffix != a.mData->suffix ) return false; 138 if ( mData->suffix != a.mData->suffix ) return false;
139 if ( mData->nickName != a.mData->nickName ) return false; 139 if ( mData->nickName != a.mData->nickName ) return false;
140 if ( mData->birthday != a.mData->birthday ) return false; 140 if ( mData->birthday != a.mData->birthday ) return false;
141 if ( mData->mailer != a.mData->mailer ) return false; 141 if ( mData->mailer != a.mData->mailer ) return false;
142 if ( mData->timeZone != a.mData->timeZone ) return false; 142 if ( mData->timeZone != a.mData->timeZone ) return false;
143 if ( mData->geo != a.mData->geo ) return false; 143 if ( mData->geo != a.mData->geo ) return false;
144 if ( mData->title != a.mData->title ) return false; 144 if ( mData->title != a.mData->title ) return false;
145 if ( mData->role != a.mData->role ) return false; 145 if ( mData->role != a.mData->role ) return false;
146 if ( mData->organization != a.mData->organization ) return false; 146 if ( mData->organization != a.mData->organization ) return false;
147 if ( mData->note != a.mData->note ) return false; 147 if ( mData->note != a.mData->note ) return false;
148 if ( mData->productId != a.mData->productId ) return false; 148 if ( mData->productId != a.mData->productId ) return false;
149 if ( mData->revision != a.mData->revision ) return false; 149 if ( mData->revision != a.mData->revision ) return false;
150 if ( mData->sortString != a.mData->sortString ) return false; 150 if ( mData->sortString != a.mData->sortString ) return false;
151 if ( mData->secrecy != a.mData->secrecy ) return false; 151 if ( mData->secrecy != a.mData->secrecy ) return false;
152 if ( mData->logo != a.mData->logo ) return false; 152 if ( mData->logo != a.mData->logo ) return false;
153 if ( mData->photo != a.mData->photo ) return false; 153 if ( mData->photo != a.mData->photo ) return false;
154 if ( mData->sound != a.mData->sound ) return false; 154 if ( mData->sound != a.mData->sound ) return false;
155 if ( mData->agent != a.mData->agent ) return false; 155 if ( mData->agent != a.mData->agent ) return false;
156 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 156 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
157 ( mData->url != a.mData->url ) ) return false; 157 ( mData->url != a.mData->url ) ) return false;
158 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 158 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
159 if ( mData->addresses != a.mData->addresses ) return false; 159 if ( mData->addresses != a.mData->addresses ) return false;
160 if ( mData->keys != a.mData->keys ) return false; 160 if ( mData->keys != a.mData->keys ) return false;
161 if ( mData->emails != a.mData->emails ) return false; 161 if ( mData->emails != a.mData->emails ) return false;
162 if ( mData->categories != a.mData->categories ) return false; 162 if ( mData->categories != a.mData->categories ) return false;
163 if ( mData->custom != a.mData->custom ) return false; 163 if ( mData->custom != a.mData->custom ) return false;
164 164
165 return true; 165 return true;
166} 166}
167 167
168bool Addressee::operator!=( const Addressee &a ) const 168bool Addressee::operator!=( const Addressee &a ) const
169{ 169{
170 return !( a == *this ); 170 return !( a == *this );
171} 171}
172 172
173bool Addressee::isEmpty() const 173bool Addressee::isEmpty() const
174{ 174{
175 return mData->empty; 175 return mData->empty;
176} 176}
177ulong Addressee::getCsum4List( const QStringList & attList)
178{
179 int max = attList.count();
180 ulong cSum = 0;
181 int j,k,i;
182 int add;
183 for ( i = 0; i < max ; ++i ) {
184 QString s = attList[i];
185 if ( ! s.isEmpty() ){
186 j = s.length();
187 for ( k = 0; k < j; ++k ) {
188 int mul = k +1;
189 add = s[k].unicode ();
190 if ( k < 16 )
191 mul = mul * mul;
192 int ii = i+1;
193 add = add * mul *ii*ii*ii;
194 cSum += add;
195 }
196 }
197
198 }
199 //QString dump = attList.join(",");
200 //qDebug("csum: %d %s", cSum,dump.latin1());
201
202 return cSum;
203
204}
205void Addressee::computeCsum(const QString &dev)
206{
207 QStringList l;
208 if ( !mData->name.isEmpty() ) l.append(mData->name);
209 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
210 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
211 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
212 if ( !mData->additionalName ) l.append( mData->additionalName );
213 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
214 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
215 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
216 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
217 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
218 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
219 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
220 if ( !mData->title .isEmpty() ) l.append( mData->title );
221 if ( !mData->role.isEmpty() ) l.append( mData->role );
222 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
223 if ( !mData->note.isEmpty() ) l.append( mData->note );
224 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
225 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
226 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
227 // if ( !mData->logo.isEmpty() ) l.append( );
228 //if ( !mData->photo.isEmpty() ) l.append( );
229 //if ( !mData->sound.isEmpty() ) l.append( );
230 //if ( !mData->agent.isEmpty() ) l.append( );
231 //if ( mData->url.isValid() ) l.append( );
232#if 0
233 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
234 if ( !mData->addresses.isEmpty() ) l.append( );
235 //if ( !mData->keys.isEmpty() ) l.append( );
236 if ( !mData->emails.isEmpty() ) l.append( );
237 if ( !mData->categories .isEmpty() ) l.append( );
238 if ( !mData->custom.isEmpty() ) l.append( );
239#endif
240 KABC::PhoneNumber::List phoneNumbers;
241 KABC::PhoneNumber::List::Iterator phoneIter;
242
243 QStringList t;
244 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
245 ++phoneIter )
246 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
247 t.sort();
248 uint iii;
249 for ( iii = 0; iii < t.count(); ++iii)
250 l.append( t[iii] );
251 t = mData->emails;
252 t.sort();
253 for ( iii = 0; iii < t.count(); ++iii)
254 l.append( t[iii] );
255 t = mData->categories;
256 t.sort();
257 for ( iii = 0; iii < t.count(); ++iii)
258 l.append( t[iii] );
259 t = mData->custom;
260 t.sort();
261 for ( iii = 0; iii < t.count(); ++iii)
262 l.append( t[iii] );
263 KABC::Address::List::Iterator addressIter;
264 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
265 ++addressIter ) {
266 t = (*addressIter).asList();
267 t.sort();
268 for ( iii = 0; iii < t.count(); ++iii)
269 l.append( t[iii] );
270 }
271 setCsum( dev, QString::number (getCsum4List(l)) );
272}
177void Addressee::removeID(const QString &prof) 273void Addressee::removeID(const QString &prof)
178{ 274{
179 detach(); 275 detach();
180 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 276 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
181 277
182} 278}
183void Addressee::setID( const QString & prof , const QString & id ) 279void Addressee::setID( const QString & prof , const QString & id )
184{ 280{
185 detach(); 281 detach();
186 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 282 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
187} 283}
188void Addressee::setTempSyncStat( int id ) 284void Addressee::setTempSyncStat( int id )
189{ 285{
190 mTempSyncStat = id; 286 mTempSyncStat = id;
191} 287}
192int Addressee::tempSyncStat() const 288int Addressee::tempSyncStat() const
193{ 289{
194 return mTempSyncStat; 290 return mTempSyncStat;
195} 291}
196 292
197QString Addressee::getID( const QString & prof) 293QString Addressee::getID( const QString & prof)
198{ 294{
199 return KIdManager::getId ( mData->mExternalId, prof ); 295 return KIdManager::getId ( mData->mExternalId, prof );
200} 296}
201 297
202void Addressee::setCsum( const QString & prof , const QString & id ) 298void Addressee::setCsum( const QString & prof , const QString & id )
203{ 299{
204 detach(); 300 detach();
205 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 301 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
206} 302}
207 303
208QString Addressee::getCsum( const QString & prof) 304QString Addressee::getCsum( const QString & prof)
209{ 305{
210 return KIdManager::getCsum ( mData->mExternalId, prof ); 306 return KIdManager::getCsum ( mData->mExternalId, prof );
211} 307}
212 308
213void Addressee::setIDStr( const QString & s ) 309void Addressee::setIDStr( const QString & s )
214{ 310{
215 detach(); 311 detach();
216 mData->mExternalId = s; 312 mData->mExternalId = s;
217} 313}
218 314
219QString Addressee::IDStr() const 315QString Addressee::IDStr() const
220{ 316{
221 return mData->mExternalId; 317 return mData->mExternalId;
222} 318}
223 319
224 320
225void Addressee::setUid( const QString &id ) 321void Addressee::setUid( const QString &id )
226{ 322{
227 if ( id == mData->uid ) return; 323 if ( id == mData->uid ) return;
228 detach(); 324 detach();
229 mData->empty = false; 325 mData->empty = false;
230 mData->uid = id; 326 mData->uid = id;
231} 327}
232 328
233QString Addressee::uid() const 329QString Addressee::uid() const
234{ 330{
235 if ( mData->uid.isEmpty() ) 331 if ( mData->uid.isEmpty() )
236 mData->uid = KApplication::randomString( 10 ); 332 mData->uid = KApplication::randomString( 10 );
237 333
238 return mData->uid; 334 return mData->uid;
239} 335}
240 336
241QString Addressee::uidLabel() 337QString Addressee::uidLabel()
242{ 338{
243 return i18n("Unique Identifier"); 339 return i18n("Unique Identifier");
244} 340}
245 341
246void Addressee::setName( const QString &name ) 342void Addressee::setName( const QString &name )
247{ 343{
248 if ( name == mData->name ) return; 344 if ( name == mData->name ) return;
249 detach(); 345 detach();
250 mData->empty = false; 346 mData->empty = false;
251 mData->name = name; 347 mData->name = name;
252} 348}
253 349
254QString Addressee::name() const 350QString Addressee::name() const
255{ 351{
256 return mData->name; 352 return mData->name;
257} 353}
258 354
259QString Addressee::nameLabel() 355QString Addressee::nameLabel()
260{ 356{
261 return i18n("Name"); 357 return i18n("Name");
262} 358}
263 359
264 360
265void Addressee::setFormattedName( const QString &formattedName ) 361void Addressee::setFormattedName( const QString &formattedName )
266{ 362{
267 if ( formattedName == mData->formattedName ) return; 363 if ( formattedName == mData->formattedName ) return;
268 detach(); 364 detach();
269 mData->empty = false; 365 mData->empty = false;
270 mData->formattedName = formattedName; 366 mData->formattedName = formattedName;
271} 367}
272 368
273QString Addressee::formattedName() const 369QString Addressee::formattedName() const
274{ 370{
275 return mData->formattedName; 371 return mData->formattedName;
276} 372}
277 373
278QString Addressee::formattedNameLabel() 374QString Addressee::formattedNameLabel()
279{ 375{
280 return i18n("Formatted Name"); 376 return i18n("Formatted Name");
281} 377}
282 378
283 379
284void Addressee::setFamilyName( const QString &familyName ) 380void Addressee::setFamilyName( const QString &familyName )
285{ 381{
286 if ( familyName == mData->familyName ) return; 382 if ( familyName == mData->familyName ) return;
287 detach(); 383 detach();
288 mData->empty = false; 384 mData->empty = false;
289 mData->familyName = familyName; 385 mData->familyName = familyName;
290} 386}
291 387
292QString Addressee::familyName() const 388QString Addressee::familyName() const
293{ 389{
294 return mData->familyName; 390 return mData->familyName;
295} 391}
296 392
297QString Addressee::familyNameLabel() 393QString Addressee::familyNameLabel()
298{ 394{
299 return i18n("Family Name"); 395 return i18n("Family Name");
300} 396}
301 397
302 398
303void Addressee::setGivenName( const QString &givenName ) 399void Addressee::setGivenName( const QString &givenName )
304{ 400{
305 if ( givenName == mData->givenName ) return; 401 if ( givenName == mData->givenName ) return;
306 detach(); 402 detach();
307 mData->empty = false; 403 mData->empty = false;
308 mData->givenName = givenName; 404 mData->givenName = givenName;
309} 405}
310 406
311QString Addressee::givenName() const 407QString Addressee::givenName() const
312{ 408{
313 return mData->givenName; 409 return mData->givenName;
314} 410}
315 411
316QString Addressee::givenNameLabel() 412QString Addressee::givenNameLabel()
317{ 413{
318 return i18n("Given Name"); 414 return i18n("Given Name");
319} 415}
320 416
321 417
322void Addressee::setAdditionalName( const QString &additionalName ) 418void Addressee::setAdditionalName( const QString &additionalName )
323{ 419{
324 if ( additionalName == mData->additionalName ) return; 420 if ( additionalName == mData->additionalName ) return;
325 detach(); 421 detach();
326 mData->empty = false; 422 mData->empty = false;
327 mData->additionalName = additionalName; 423 mData->additionalName = additionalName;
328} 424}
329 425
330QString Addressee::additionalName() const 426QString Addressee::additionalName() const
331{ 427{
332 return mData->additionalName; 428 return mData->additionalName;
333} 429}
334 430
335QString Addressee::additionalNameLabel() 431QString Addressee::additionalNameLabel()
336{ 432{
337 return i18n("Additional Names"); 433 return i18n("Additional Names");
338} 434}
339 435
340 436
341void Addressee::setPrefix( const QString &prefix ) 437void Addressee::setPrefix( const QString &prefix )
342{ 438{
343 if ( prefix == mData->prefix ) return; 439 if ( prefix == mData->prefix ) return;
344 detach(); 440 detach();
345 mData->empty = false; 441 mData->empty = false;
346 mData->prefix = prefix; 442 mData->prefix = prefix;
347} 443}
348 444
349QString Addressee::prefix() const 445QString Addressee::prefix() const
350{ 446{
351 return mData->prefix; 447 return mData->prefix;
352} 448}
353 449
354QString Addressee::prefixLabel() 450QString Addressee::prefixLabel()
355{ 451{
356 return i18n("Honorific Prefixes"); 452 return i18n("Honorific Prefixes");
357} 453}
358 454
359 455
360void Addressee::setSuffix( const QString &suffix ) 456void Addressee::setSuffix( const QString &suffix )
361{ 457{
362 if ( suffix == mData->suffix ) return; 458 if ( suffix == mData->suffix ) return;
363 detach(); 459 detach();
364 mData->empty = false; 460 mData->empty = false;
365 mData->suffix = suffix; 461 mData->suffix = suffix;
366} 462}
367 463
368QString Addressee::suffix() const 464QString Addressee::suffix() const
369{ 465{
370 return mData->suffix; 466 return mData->suffix;
371} 467}
372 468
373QString Addressee::suffixLabel() 469QString Addressee::suffixLabel()
374{ 470{
375 return i18n("Honorific Suffixes"); 471 return i18n("Honorific Suffixes");
376} 472}
377 473
378 474
379void Addressee::setNickName( const QString &nickName ) 475void Addressee::setNickName( const QString &nickName )
380{ 476{
381 if ( nickName == mData->nickName ) return; 477 if ( nickName == mData->nickName ) return;
382 detach(); 478 detach();
383 mData->empty = false; 479 mData->empty = false;
384 mData->nickName = nickName; 480 mData->nickName = nickName;
385} 481}
386 482
387QString Addressee::nickName() const 483QString Addressee::nickName() const
388{ 484{
389 return mData->nickName; 485 return mData->nickName;
390} 486}
391 487
392QString Addressee::nickNameLabel() 488QString Addressee::nickNameLabel()
393{ 489{
394 return i18n("Nick Name"); 490 return i18n("Nick Name");
395} 491}
396 492
397 493
398void Addressee::setBirthday( const QDateTime &birthday ) 494void Addressee::setBirthday( const QDateTime &birthday )
399{ 495{
400 if ( birthday == mData->birthday ) return; 496 if ( birthday == mData->birthday ) return;
401 detach(); 497 detach();
402 mData->empty = false; 498 mData->empty = false;
403 mData->birthday = birthday; 499 mData->birthday = birthday;
404} 500}
405 501
406QDateTime Addressee::birthday() const 502QDateTime Addressee::birthday() const
407{ 503{
408 return mData->birthday; 504 return mData->birthday;
409} 505}
410 506
411QString Addressee::birthdayLabel() 507QString Addressee::birthdayLabel()
412{ 508{
413 return i18n("Birthday"); 509 return i18n("Birthday");
414} 510}
415 511
416 512
417QString Addressee::homeAddressStreetLabel() 513QString Addressee::homeAddressStreetLabel()
418{ 514{
419 return i18n("Home Address Street"); 515 return i18n("Home Address Street");
420} 516}
421 517
422 518
423QString Addressee::homeAddressLocalityLabel() 519QString Addressee::homeAddressLocalityLabel()
424{ 520{
425 return i18n("Home Address Locality"); 521 return i18n("Home Address Locality");
426} 522}
427 523
428 524
429QString Addressee::homeAddressRegionLabel() 525QString Addressee::homeAddressRegionLabel()
430{ 526{
431 return i18n("Home Address Region"); 527 return i18n("Home Address Region");
432} 528}
433 529
434 530
435QString Addressee::homeAddressPostalCodeLabel() 531QString Addressee::homeAddressPostalCodeLabel()
436{ 532{
437 return i18n("Home Address Postal Code"); 533 return i18n("Home Address Postal Code");
438} 534}
439 535
440 536
441QString Addressee::homeAddressCountryLabel() 537QString Addressee::homeAddressCountryLabel()
442{ 538{
443 return i18n("Home Address Country"); 539 return i18n("Home Address Country");
444} 540}
445 541
446 542
447QString Addressee::homeAddressLabelLabel() 543QString Addressee::homeAddressLabelLabel()
448{ 544{
449 return i18n("Home Address Label"); 545 return i18n("Home Address Label");
450} 546}
451 547
452 548
453QString Addressee::businessAddressStreetLabel() 549QString Addressee::businessAddressStreetLabel()
454{ 550{
455 return i18n("Business Address Street"); 551 return i18n("Business Address Street");
456} 552}
457 553
458 554
459QString Addressee::businessAddressLocalityLabel() 555QString Addressee::businessAddressLocalityLabel()
460{ 556{
461 return i18n("Business Address Locality"); 557 return i18n("Business Address Locality");
462} 558}
463 559
464 560
465QString Addressee::businessAddressRegionLabel() 561QString Addressee::businessAddressRegionLabel()
466{ 562{
467 return i18n("Business Address Region"); 563 return i18n("Business Address Region");
468} 564}
469 565
470 566
471QString Addressee::businessAddressPostalCodeLabel() 567QString Addressee::businessAddressPostalCodeLabel()
472{ 568{
473 return i18n("Business Address Postal Code"); 569 return i18n("Business Address Postal Code");
474} 570}
475 571
476 572
477QString Addressee::businessAddressCountryLabel() 573QString Addressee::businessAddressCountryLabel()
478{ 574{
479 return i18n("Business Address Country"); 575 return i18n("Business Address Country");
480} 576}
481 577
482 578
483QString Addressee::businessAddressLabelLabel() 579QString Addressee::businessAddressLabelLabel()
484{ 580{
485 return i18n("Business Address Label"); 581 return i18n("Business Address Label");
486} 582}
487 583
488 584
489QString Addressee::homePhoneLabel() 585QString Addressee::homePhoneLabel()
490{ 586{
491 return i18n("Home Phone"); 587 return i18n("Home Phone");
492} 588}
493 589
494 590
495QString Addressee::businessPhoneLabel() 591QString Addressee::businessPhoneLabel()
496{ 592{
497 return i18n("Business Phone"); 593 return i18n("Business Phone");
498} 594}
499 595
500 596
501QString Addressee::mobilePhoneLabel() 597QString Addressee::mobilePhoneLabel()
502{ 598{
503 return i18n("Mobile Phone"); 599 return i18n("Mobile Phone");
504} 600}
505 601
506 602
507QString Addressee::homeFaxLabel() 603QString Addressee::homeFaxLabel()
508{ 604{
509 return i18n("Home Fax"); 605 return i18n("Home Fax");
510} 606}
511 607
512 608
513QString Addressee::businessFaxLabel() 609QString Addressee::businessFaxLabel()
514{ 610{
515 return i18n("Business Fax"); 611 return i18n("Business Fax");
516} 612}
517 613
518 614
519QString Addressee::carPhoneLabel() 615QString Addressee::carPhoneLabel()
520{ 616{
521 return i18n("Car Phone"); 617 return i18n("Car Phone");
522} 618}
523 619
524 620
525QString Addressee::isdnLabel() 621QString Addressee::isdnLabel()
526{ 622{
527 return i18n("ISDN"); 623 return i18n("ISDN");
528} 624}
529 625
530 626
531QString Addressee::pagerLabel() 627QString Addressee::pagerLabel()
532{ 628{
533 return i18n("Pager"); 629 return i18n("Pager");
534} 630}
535 631
536QString Addressee::sipLabel() 632QString Addressee::sipLabel()
537{ 633{
538 return i18n("SIP"); 634 return i18n("SIP");
539} 635}
540 636
541QString Addressee::emailLabel() 637QString Addressee::emailLabel()
542{ 638{
543 return i18n("Email Address"); 639 return i18n("Email Address");
544} 640}
545 641
546 642
547void Addressee::setMailer( const QString &mailer ) 643void Addressee::setMailer( const QString &mailer )
548{ 644{
549 if ( mailer == mData->mailer ) return; 645 if ( mailer == mData->mailer ) return;
550 detach(); 646 detach();
551 mData->empty = false; 647 mData->empty = false;
552 mData->mailer = mailer; 648 mData->mailer = mailer;
553} 649}
554 650
555QString Addressee::mailer() const 651QString Addressee::mailer() const
556{ 652{
557 return mData->mailer; 653 return mData->mailer;
558} 654}
559 655
560QString Addressee::mailerLabel() 656QString Addressee::mailerLabel()
561{ 657{
562 return i18n("Mail Client"); 658 return i18n("Mail Client");
563} 659}
564 660
565 661
566void Addressee::setTimeZone( const TimeZone &timeZone ) 662void Addressee::setTimeZone( const TimeZone &timeZone )
567{ 663{
568 if ( timeZone == mData->timeZone ) return; 664 if ( timeZone == mData->timeZone ) return;
569 detach(); 665 detach();
570 mData->empty = false; 666 mData->empty = false;
571 mData->timeZone = timeZone; 667 mData->timeZone = timeZone;
572} 668}
573 669
574TimeZone Addressee::timeZone() const 670TimeZone Addressee::timeZone() const
575{ 671{
576 return mData->timeZone; 672 return mData->timeZone;
577} 673}
578 674
579QString Addressee::timeZoneLabel() 675QString Addressee::timeZoneLabel()
580{ 676{
581 return i18n("Time Zone"); 677 return i18n("Time Zone");
582} 678}
583 679
584 680
585void Addressee::setGeo( const Geo &geo ) 681void Addressee::setGeo( const Geo &geo )
586{ 682{
587 if ( geo == mData->geo ) return; 683 if ( geo == mData->geo ) return;
588 detach(); 684 detach();
589 mData->empty = false; 685 mData->empty = false;
590 mData->geo = geo; 686 mData->geo = geo;
591} 687}
592 688
593Geo Addressee::geo() const 689Geo Addressee::geo() const
594{ 690{
595 return mData->geo; 691 return mData->geo;
596} 692}
597 693
598QString Addressee::geoLabel() 694QString Addressee::geoLabel()
599{ 695{
600 return i18n("Geographic Position"); 696 return i18n("Geographic Position");
601} 697}
602 698
603 699
604void Addressee::setTitle( const QString &title ) 700void Addressee::setTitle( const QString &title )
605{ 701{
606 if ( title == mData->title ) return; 702 if ( title == mData->title ) return;
607 detach(); 703 detach();
608 mData->empty = false; 704 mData->empty = false;
609 mData->title = title; 705 mData->title = title;
610} 706}
611 707
612QString Addressee::title() const 708QString Addressee::title() const
613{ 709{
614 return mData->title; 710 return mData->title;
615} 711}
616 712
617QString Addressee::titleLabel() 713QString Addressee::titleLabel()
618{ 714{
619 return i18n("Title"); 715 return i18n("Title");
620} 716}
621 717
622 718
623void Addressee::setRole( const QString &role ) 719void Addressee::setRole( const QString &role )
624{ 720{
625 if ( role == mData->role ) return; 721 if ( role == mData->role ) return;
626 detach(); 722 detach();
627 mData->empty = false; 723 mData->empty = false;
628 mData->role = role; 724 mData->role = role;
629} 725}
630 726
631QString Addressee::role() const 727QString Addressee::role() const
632{ 728{
633 return mData->role; 729 return mData->role;
634} 730}
635 731
636QString Addressee::roleLabel() 732QString Addressee::roleLabel()
637{ 733{
638 return i18n("Role"); 734 return i18n("Role");
639} 735}
640 736
641 737
642void Addressee::setOrganization( const QString &organization ) 738void Addressee::setOrganization( const QString &organization )
643{ 739{
644 if ( organization == mData->organization ) return; 740 if ( organization == mData->organization ) return;
645 detach(); 741 detach();
646 mData->empty = false; 742 mData->empty = false;
647 mData->organization = organization; 743 mData->organization = organization;
648} 744}
649 745
650QString Addressee::organization() const 746QString Addressee::organization() const
651{ 747{
652 return mData->organization; 748 return mData->organization;
653} 749}
654 750
655QString Addressee::organizationLabel() 751QString Addressee::organizationLabel()
656{ 752{
657 return i18n("Organization"); 753 return i18n("Organization");
658} 754}
659 755
660 756
661void Addressee::setNote( const QString &note ) 757void Addressee::setNote( const QString &note )
662{ 758{
663 if ( note == mData->note ) return; 759 if ( note == mData->note ) return;
664 detach(); 760 detach();
665 mData->empty = false; 761 mData->empty = false;
666 mData->note = note; 762 mData->note = note;
667} 763}
668 764
669QString Addressee::note() const 765QString Addressee::note() const
670{ 766{
671 return mData->note; 767 return mData->note;
672} 768}
673 769
674QString Addressee::noteLabel() 770QString Addressee::noteLabel()
675{ 771{
676 return i18n("Note"); 772 return i18n("Note");
677} 773}
678 774
679 775
680void Addressee::setProductId( const QString &productId ) 776void Addressee::setProductId( const QString &productId )
681{ 777{
682 if ( productId == mData->productId ) return; 778 if ( productId == mData->productId ) return;
683 detach(); 779 detach();
684 mData->empty = false; 780 mData->empty = false;
685 mData->productId = productId; 781 mData->productId = productId;
686} 782}
687 783
688QString Addressee::productId() const 784QString Addressee::productId() const
689{ 785{
690 return mData->productId; 786 return mData->productId;
691} 787}
692 788
693QString Addressee::productIdLabel() 789QString Addressee::productIdLabel()
694{ 790{
695 return i18n("Product Identifier"); 791 return i18n("Product Identifier");
696} 792}
697 793
698 794
699void Addressee::setRevision( const QDateTime &revision ) 795void Addressee::setRevision( const QDateTime &revision )
700{ 796{
701 if ( revision == mData->revision ) return; 797 if ( revision == mData->revision ) return;
702 detach(); 798 detach();
703 mData->empty = false; 799 mData->empty = false;
704 mData->revision = revision; 800 mData->revision = revision;
705} 801}
706 802
707QDateTime Addressee::revision() const 803QDateTime Addressee::revision() const
708{ 804{
709 return mData->revision; 805 return mData->revision;
710} 806}
711 807
712QString Addressee::revisionLabel() 808QString Addressee::revisionLabel()
713{ 809{
714 return i18n("Revision Date"); 810 return i18n("Revision Date");
715} 811}
716 812
717 813
718void Addressee::setSortString( const QString &sortString ) 814void Addressee::setSortString( const QString &sortString )
719{ 815{
720 if ( sortString == mData->sortString ) return; 816 if ( sortString == mData->sortString ) return;
721 detach(); 817 detach();
722 mData->empty = false; 818 mData->empty = false;
723 mData->sortString = sortString; 819 mData->sortString = sortString;
724} 820}
725 821
726QString Addressee::sortString() const 822QString Addressee::sortString() const
727{ 823{
728 return mData->sortString; 824 return mData->sortString;
729} 825}
730 826
731QString Addressee::sortStringLabel() 827QString Addressee::sortStringLabel()
732{ 828{
733 return i18n("Sort String"); 829 return i18n("Sort String");
734} 830}
735 831
736 832
737void Addressee::setUrl( const KURL &url ) 833void Addressee::setUrl( const KURL &url )
738{ 834{
739 if ( url == mData->url ) return; 835 if ( url == mData->url ) return;
740 detach(); 836 detach();
741 mData->empty = false; 837 mData->empty = false;
742 mData->url = url; 838 mData->url = url;
743} 839}
744 840
745KURL Addressee::url() const 841KURL Addressee::url() const
746{ 842{
747 return mData->url; 843 return mData->url;
748} 844}
749 845
750QString Addressee::urlLabel() 846QString Addressee::urlLabel()
751{ 847{
752 return i18n("URL"); 848 return i18n("URL");
753} 849}
754 850
755 851
756void Addressee::setSecrecy( const Secrecy &secrecy ) 852void Addressee::setSecrecy( const Secrecy &secrecy )
757{ 853{
758 if ( secrecy == mData->secrecy ) return; 854 if ( secrecy == mData->secrecy ) return;
759 detach(); 855 detach();
760 mData->empty = false; 856 mData->empty = false;
761 mData->secrecy = secrecy; 857 mData->secrecy = secrecy;
762} 858}
763 859
764Secrecy Addressee::secrecy() const 860Secrecy Addressee::secrecy() const
765{ 861{
766 return mData->secrecy; 862 return mData->secrecy;
767} 863}
768 864
769QString Addressee::secrecyLabel() 865QString Addressee::secrecyLabel()
770{ 866{
771 return i18n("Security Class"); 867 return i18n("Security Class");
772} 868}
773 869
774 870
775void Addressee::setLogo( const Picture &logo ) 871void Addressee::setLogo( const Picture &logo )
776{ 872{
777 if ( logo == mData->logo ) return; 873 if ( logo == mData->logo ) return;
778 detach(); 874 detach();
779 mData->empty = false; 875 mData->empty = false;
780 mData->logo = logo; 876 mData->logo = logo;
781} 877}
782 878
783Picture Addressee::logo() const 879Picture Addressee::logo() const
784{ 880{
785 return mData->logo; 881 return mData->logo;
786} 882}
787 883
788QString Addressee::logoLabel() 884QString Addressee::logoLabel()
789{ 885{
790 return i18n("Logo"); 886 return i18n("Logo");
791} 887}
792 888
793 889
794void Addressee::setPhoto( const Picture &photo ) 890void Addressee::setPhoto( const Picture &photo )
795{ 891{
796 if ( photo == mData->photo ) return; 892 if ( photo == mData->photo ) return;
797 detach(); 893 detach();
798 mData->empty = false; 894 mData->empty = false;
799 mData->photo = photo; 895 mData->photo = photo;
800} 896}
801 897
802Picture Addressee::photo() const 898Picture Addressee::photo() const
803{ 899{
804 return mData->photo; 900 return mData->photo;
805} 901}
806 902
807QString Addressee::photoLabel() 903QString Addressee::photoLabel()
808{ 904{
809 return i18n("Photo"); 905 return i18n("Photo");
810} 906}
811 907
812 908
813void Addressee::setSound( const Sound &sound ) 909void Addressee::setSound( const Sound &sound )
814{ 910{
815 if ( sound == mData->sound ) return; 911 if ( sound == mData->sound ) return;
816 detach(); 912 detach();
817 mData->empty = false; 913 mData->empty = false;
818 mData->sound = sound; 914 mData->sound = sound;
819} 915}
820 916
821Sound Addressee::sound() const 917Sound Addressee::sound() const
822{ 918{
823 return mData->sound; 919 return mData->sound;
824} 920}
825 921
826QString Addressee::soundLabel() 922QString Addressee::soundLabel()
827{ 923{
828 return i18n("Sound"); 924 return i18n("Sound");
829} 925}
830 926
831 927
832void Addressee::setAgent( const Agent &agent ) 928void Addressee::setAgent( const Agent &agent )
833{ 929{
834 if ( agent == mData->agent ) return; 930 if ( agent == mData->agent ) return;
835 detach(); 931 detach();
836 mData->empty = false; 932 mData->empty = false;
837 mData->agent = agent; 933 mData->agent = agent;
838} 934}
839 935
840Agent Addressee::agent() const 936Agent Addressee::agent() const
841{ 937{
842 return mData->agent; 938 return mData->agent;
843} 939}
844 940
845QString Addressee::agentLabel() 941QString Addressee::agentLabel()
846{ 942{
847 return i18n("Agent"); 943 return i18n("Agent");
848} 944}
849 945
850 946
851 947
852void Addressee::setNameFromString( const QString &str ) 948void Addressee::setNameFromString( const QString &str )
853{ 949{
854 setFormattedName( str ); 950 setFormattedName( str );
855 setName( str ); 951 setName( str );
856 952
857 static bool first = true; 953 static bool first = true;
858 static QStringList titles; 954 static QStringList titles;
859 static QStringList suffixes; 955 static QStringList suffixes;
860 static QStringList prefixes; 956 static QStringList prefixes;
861 957
862 if ( first ) { 958 if ( first ) {
863 first = false; 959 first = false;
864 titles += i18n( "Dr." ); 960 titles += i18n( "Dr." );
865 titles += i18n( "Miss" ); 961 titles += i18n( "Miss" );
866 titles += i18n( "Mr." ); 962 titles += i18n( "Mr." );
867 titles += i18n( "Mrs." ); 963 titles += i18n( "Mrs." );
868 titles += i18n( "Ms." ); 964 titles += i18n( "Ms." );
869 titles += i18n( "Prof." ); 965 titles += i18n( "Prof." );
870 966
871 suffixes += i18n( "I" ); 967 suffixes += i18n( "I" );
872 suffixes += i18n( "II" ); 968 suffixes += i18n( "II" );
873 suffixes += i18n( "III" ); 969 suffixes += i18n( "III" );
874 suffixes += i18n( "Jr." ); 970 suffixes += i18n( "Jr." );
875 suffixes += i18n( "Sr." ); 971 suffixes += i18n( "Sr." );
876 972
877 prefixes += "van"; 973 prefixes += "van";
878 prefixes += "von"; 974 prefixes += "von";
879 prefixes += "de"; 975 prefixes += "de";
880 976
881 KConfig config( locateLocal( "config", "kabcrc") ); 977 KConfig config( locateLocal( "config", "kabcrc") );
882 config.setGroup( "General" ); 978 config.setGroup( "General" );
883 titles += config.readListEntry( "Prefixes" ); 979 titles += config.readListEntry( "Prefixes" );
884 titles.remove( "" ); 980 titles.remove( "" );
885 prefixes += config.readListEntry( "Inclusions" ); 981 prefixes += config.readListEntry( "Inclusions" );
886 prefixes.remove( "" ); 982 prefixes.remove( "" );
887 suffixes += config.readListEntry( "Suffixes" ); 983 suffixes += config.readListEntry( "Suffixes" );
888 suffixes.remove( "" ); 984 suffixes.remove( "" );
889 } 985 }
890 986
891 // clear all name parts 987 // clear all name parts
892 setPrefix( "" ); 988 setPrefix( "" );
893 setGivenName( "" ); 989 setGivenName( "" );
894 setAdditionalName( "" ); 990 setAdditionalName( "" );
895 setFamilyName( "" ); 991 setFamilyName( "" );
896 setSuffix( "" ); 992 setSuffix( "" );
897 993
898 if ( str.isEmpty() ) 994 if ( str.isEmpty() )
899 return; 995 return;
900 996
901 int i = str.find(','); 997 int i = str.find(',');
902 if( i < 0 ) { 998 if( i < 0 ) {
903 QStringList parts = QStringList::split( " ", str ); 999 QStringList parts = QStringList::split( " ", str );
904 int leftOffset = 0; 1000 int leftOffset = 0;
905 int rightOffset = parts.count() - 1; 1001 int rightOffset = parts.count() - 1;
906 1002
907 QString suffix; 1003 QString suffix;
908 while ( rightOffset >= 0 ) { 1004 while ( rightOffset >= 0 ) {
909 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1005 if ( suffixes.contains( parts[ rightOffset ] ) ) {
910 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1006 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
911 rightOffset--; 1007 rightOffset--;
912 } else 1008 } else
913 break; 1009 break;
914 } 1010 }
915 setSuffix( suffix ); 1011 setSuffix( suffix );
916 1012
917 if ( rightOffset < 0 ) 1013 if ( rightOffset < 0 )
918 return; 1014 return;
919 1015
920 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1016 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
921 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1017 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
922 rightOffset--; 1018 rightOffset--;
923 } else 1019 } else
924 setFamilyName( parts[ rightOffset ] ); 1020 setFamilyName( parts[ rightOffset ] );
925 1021
926 QString prefix; 1022 QString prefix;
927 while ( leftOffset < rightOffset ) { 1023 while ( leftOffset < rightOffset ) {
928 if ( titles.contains( parts[ leftOffset ] ) ) { 1024 if ( titles.contains( parts[ leftOffset ] ) ) {
929 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1025 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
930 leftOffset++; 1026 leftOffset++;
931 } else 1027 } else
932 break; 1028 break;
933 } 1029 }
934 setPrefix( prefix ); 1030 setPrefix( prefix );
935 1031
936 if ( leftOffset < rightOffset ) { 1032 if ( leftOffset < rightOffset ) {
937 setGivenName( parts[ leftOffset ] ); 1033 setGivenName( parts[ leftOffset ] );
938 leftOffset++; 1034 leftOffset++;
939 } 1035 }
940 1036
941 QString additionalName; 1037 QString additionalName;
942 while ( leftOffset < rightOffset ) { 1038 while ( leftOffset < rightOffset ) {
943 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1039 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
944 leftOffset++; 1040 leftOffset++;
945 } 1041 }
946 setAdditionalName( additionalName ); 1042 setAdditionalName( additionalName );
947 } else { 1043 } else {
948 QString part1 = str.left( i ); 1044 QString part1 = str.left( i );
949 QString part2 = str.mid( i + 1 ); 1045 QString part2 = str.mid( i + 1 );
950 1046
951 QStringList parts = QStringList::split( " ", part1 ); 1047 QStringList parts = QStringList::split( " ", part1 );
952 int leftOffset = 0; 1048 int leftOffset = 0;
953 int rightOffset = parts.count() - 1; 1049 int rightOffset = parts.count() - 1;
954 1050
955 QString suffix; 1051 QString suffix;
956 while ( rightOffset >= 0 ) { 1052 while ( rightOffset >= 0 ) {
957 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1053 if ( suffixes.contains( parts[ rightOffset ] ) ) {
958 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1054 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
959 rightOffset--; 1055 rightOffset--;
960 } else 1056 } else
961 break; 1057 break;
962 } 1058 }
963 setSuffix( suffix ); 1059 setSuffix( suffix );
964 1060
965 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1061 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
966 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1062 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
967 rightOffset--; 1063 rightOffset--;
968 } else 1064 } else
969 setFamilyName( parts[ rightOffset ] ); 1065 setFamilyName( parts[ rightOffset ] );
970 1066
971 QString prefix; 1067 QString prefix;
972 while ( leftOffset < rightOffset ) { 1068 while ( leftOffset < rightOffset ) {
973 if ( titles.contains( parts[ leftOffset ] ) ) { 1069 if ( titles.contains( parts[ leftOffset ] ) ) {
974 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1070 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
975 leftOffset++; 1071 leftOffset++;
976 } else 1072 } else
977 break; 1073 break;
978 } 1074 }
979 1075
980 parts = QStringList::split( " ", part2 ); 1076 parts = QStringList::split( " ", part2 );
981 1077
982 leftOffset = 0; 1078 leftOffset = 0;
983 rightOffset = parts.count(); 1079 rightOffset = parts.count();
984 1080
985 while ( leftOffset < rightOffset ) { 1081 while ( leftOffset < rightOffset ) {
986 if ( titles.contains( parts[ leftOffset ] ) ) { 1082 if ( titles.contains( parts[ leftOffset ] ) ) {
987 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1083 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
988 leftOffset++; 1084 leftOffset++;
989 } else 1085 } else
990 break; 1086 break;
991 } 1087 }
992 setPrefix( prefix ); 1088 setPrefix( prefix );
993 1089
994 if ( leftOffset < rightOffset ) { 1090 if ( leftOffset < rightOffset ) {
995 setGivenName( parts[ leftOffset ] ); 1091 setGivenName( parts[ leftOffset ] );
996 leftOffset++; 1092 leftOffset++;
997 } 1093 }
998 1094
999 QString additionalName; 1095 QString additionalName;
1000 while ( leftOffset < rightOffset ) { 1096 while ( leftOffset < rightOffset ) {
1001 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1097 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1002 leftOffset++; 1098 leftOffset++;
1003 } 1099 }
1004 setAdditionalName( additionalName ); 1100 setAdditionalName( additionalName );
1005 } 1101 }
1006} 1102}
1007 1103
1008QString Addressee::realName() const 1104QString Addressee::realName() const
1009{ 1105{
1010 if ( !formattedName().isEmpty() ) 1106 if ( !formattedName().isEmpty() )
1011 return formattedName(); 1107 return formattedName();
1012 1108
1013 QString n = assembledName(); 1109 QString n = assembledName();
1014 1110
1015 if ( n.isEmpty() ) 1111 if ( n.isEmpty() )
1016 n = name(); 1112 n = name();
1017 1113
1018 return n; 1114 return n;
1019} 1115}
1020 1116
1021QString Addressee::assembledName() const 1117QString Addressee::assembledName() const
1022{ 1118{
1023 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1119 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1024 familyName() + " " + suffix(); 1120 familyName() + " " + suffix();
1025 1121
1026 return name.simplifyWhiteSpace(); 1122 return name.simplifyWhiteSpace();
1027} 1123}
1028 1124
1029QString Addressee::fullEmail( const QString &email ) const 1125QString Addressee::fullEmail( const QString &email ) const
1030{ 1126{
1031 QString e; 1127 QString e;
1032 if ( email.isNull() ) { 1128 if ( email.isNull() ) {
1033 e = preferredEmail(); 1129 e = preferredEmail();
1034 } else { 1130 } else {
1035 e = email; 1131 e = email;
1036 } 1132 }
1037 if ( e.isEmpty() ) return QString::null; 1133 if ( e.isEmpty() ) return QString::null;
1038 1134
1039 QString text; 1135 QString text;
1040 if ( realName().isEmpty() ) 1136 if ( realName().isEmpty() )
1041 text = e; 1137 text = e;
1042 else 1138 else
1043 text = assembledName() + " <" + e + ">"; 1139 text = assembledName() + " <" + e + ">";
1044 1140
1045 return text; 1141 return text;
1046} 1142}
1047 1143
1048void Addressee::insertEmail( const QString &email, bool preferred ) 1144void Addressee::insertEmail( const QString &email, bool preferred )
1049{ 1145{
1050 detach(); 1146 detach();
1051 1147
1052 QStringList::Iterator it = mData->emails.find( email ); 1148 QStringList::Iterator it = mData->emails.find( email );
1053 1149
1054 if ( it != mData->emails.end() ) { 1150 if ( it != mData->emails.end() ) {
1055 if ( !preferred || it == mData->emails.begin() ) return; 1151 if ( !preferred || it == mData->emails.begin() ) return;
1056 mData->emails.remove( it ); 1152 mData->emails.remove( it );
1057 mData->emails.prepend( email ); 1153 mData->emails.prepend( email );
1058 } else { 1154 } else {
1059 if ( preferred ) { 1155 if ( preferred ) {
1060 mData->emails.prepend( email ); 1156 mData->emails.prepend( email );
1061 } else { 1157 } else {
1062 mData->emails.append( email ); 1158 mData->emails.append( email );
1063 } 1159 }
1064 } 1160 }
1065} 1161}
1066 1162
1067void Addressee::removeEmail( const QString &email ) 1163void Addressee::removeEmail( const QString &email )
1068{ 1164{
1069 detach(); 1165 detach();
1070 1166
1071 QStringList::Iterator it = mData->emails.find( email ); 1167 QStringList::Iterator it = mData->emails.find( email );
1072 if ( it == mData->emails.end() ) return; 1168 if ( it == mData->emails.end() ) return;
1073 1169
1074 mData->emails.remove( it ); 1170 mData->emails.remove( it );
1075} 1171}
1076 1172
1077QString Addressee::preferredEmail() const 1173QString Addressee::preferredEmail() const
1078{ 1174{
1079 if ( mData->emails.count() == 0 ) return QString::null; 1175 if ( mData->emails.count() == 0 ) return QString::null;
1080 else return mData->emails.first(); 1176 else return mData->emails.first();
1081} 1177}
1082 1178
1083QStringList Addressee::emails() const 1179QStringList Addressee::emails() const
1084{ 1180{
1085 return mData->emails; 1181 return mData->emails;
1086} 1182}
1087void Addressee::setEmails( const QStringList& emails ) { 1183void Addressee::setEmails( const QStringList& emails ) {
1088 detach(); 1184 detach();
1089 mData->emails = emails; 1185 mData->emails = emails;
1090} 1186}
1091void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1187void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1092{ 1188{
1093 detach(); 1189 detach();
1094 mData->empty = false; 1190 mData->empty = false;
1095 1191
1096 PhoneNumber::List::Iterator it; 1192 PhoneNumber::List::Iterator it;
1097 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1193 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1098 if ( (*it).id() == phoneNumber.id() ) { 1194 if ( (*it).id() == phoneNumber.id() ) {
1099 *it = phoneNumber; 1195 *it = phoneNumber;
1100 return; 1196 return;
1101 } 1197 }
1102 } 1198 }
1103 mData->phoneNumbers.append( phoneNumber ); 1199 mData->phoneNumbers.append( phoneNumber );
1104} 1200}
1105 1201
1106void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1202void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1107{ 1203{
1108 detach(); 1204 detach();
1109 1205
1110 PhoneNumber::List::Iterator it; 1206 PhoneNumber::List::Iterator it;
1111 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1207 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1112 if ( (*it).id() == phoneNumber.id() ) { 1208 if ( (*it).id() == phoneNumber.id() ) {
1113 mData->phoneNumbers.remove( it ); 1209 mData->phoneNumbers.remove( it );
1114 return; 1210 return;
1115 } 1211 }
1116 } 1212 }
1117} 1213}
1118 1214
1119PhoneNumber Addressee::phoneNumber( int type ) const 1215PhoneNumber Addressee::phoneNumber( int type ) const
1120{ 1216{
1121 PhoneNumber phoneNumber( "", type ); 1217 PhoneNumber phoneNumber( "", type );
1122 PhoneNumber::List::ConstIterator it; 1218 PhoneNumber::List::ConstIterator it;
1123 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1219 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1124 if ( matchBinaryPattern( (*it).type(), type ) ) { 1220 if ( matchBinaryPattern( (*it).type(), type ) ) {
1125 if ( (*it).type() & PhoneNumber::Pref ) 1221 if ( (*it).type() & PhoneNumber::Pref )
1126 return (*it); 1222 return (*it);
1127 else if ( phoneNumber.number().isEmpty() ) 1223 else if ( phoneNumber.number().isEmpty() )
1128 phoneNumber = (*it); 1224 phoneNumber = (*it);
1129 } 1225 }
1130 } 1226 }
1131 1227
1132 return phoneNumber; 1228 return phoneNumber;
1133} 1229}
1134 1230
1135PhoneNumber::List Addressee::phoneNumbers() const 1231PhoneNumber::List Addressee::phoneNumbers() const
1136{ 1232{
1137 return mData->phoneNumbers; 1233 return mData->phoneNumbers;
1138} 1234}
1139 1235
1140PhoneNumber::List Addressee::phoneNumbers( int type ) const 1236PhoneNumber::List Addressee::phoneNumbers( int type ) const
1141{ 1237{
1142 PhoneNumber::List list; 1238 PhoneNumber::List list;
1143 1239
1144 PhoneNumber::List::ConstIterator it; 1240 PhoneNumber::List::ConstIterator it;
1145 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1241 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1146 if ( matchBinaryPattern( (*it).type(), type ) ) { 1242 if ( matchBinaryPattern( (*it).type(), type ) ) {
1147 list.append( *it ); 1243 list.append( *it );
1148 } 1244 }
1149 } 1245 }
1150 return list; 1246 return list;
1151} 1247}
1152 1248
1153PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1249PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1154{ 1250{
1155 PhoneNumber::List::ConstIterator it; 1251 PhoneNumber::List::ConstIterator it;
1156 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1252 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1157 if ( (*it).id() == id ) { 1253 if ( (*it).id() == id ) {
1158 return *it; 1254 return *it;
1159 } 1255 }
1160 } 1256 }
1161 return PhoneNumber(); 1257 return PhoneNumber();
1162} 1258}
1163 1259
1164void Addressee::insertKey( const Key &key ) 1260void Addressee::insertKey( const Key &key )
1165{ 1261{
1166 detach(); 1262 detach();
1167 mData->empty = false; 1263 mData->empty = false;
1168 1264
1169 Key::List::Iterator it; 1265 Key::List::Iterator it;
1170 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1266 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1171 if ( (*it).id() == key.id() ) { 1267 if ( (*it).id() == key.id() ) {
1172 *it = key; 1268 *it = key;
1173 return; 1269 return;
1174 } 1270 }
1175 } 1271 }
1176 mData->keys.append( key ); 1272 mData->keys.append( key );
1177} 1273}
1178 1274
1179void Addressee::removeKey( const Key &key ) 1275void Addressee::removeKey( const Key &key )
1180{ 1276{
1181 detach(); 1277 detach();
1182 1278
1183 Key::List::Iterator it; 1279 Key::List::Iterator it;
1184 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1280 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1185 if ( (*it).id() == key.id() ) { 1281 if ( (*it).id() == key.id() ) {
1186 mData->keys.remove( key ); 1282 mData->keys.remove( key );
1187 return; 1283 return;
1188 } 1284 }
1189 } 1285 }
1190} 1286}
1191 1287
1192Key Addressee::key( int type, QString customTypeString ) const 1288Key Addressee::key( int type, QString customTypeString ) const
1193{ 1289{
1194 Key::List::ConstIterator it; 1290 Key::List::ConstIterator it;
1195 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1291 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1196 if ( (*it).type() == type ) { 1292 if ( (*it).type() == type ) {
1197 if ( type == Key::Custom ) { 1293 if ( type == Key::Custom ) {
1198 if ( customTypeString.isEmpty() ) { 1294 if ( customTypeString.isEmpty() ) {
1199 return *it; 1295 return *it;
1200 } else { 1296 } else {
1201 if ( (*it).customTypeString() == customTypeString ) 1297 if ( (*it).customTypeString() == customTypeString )
1202 return (*it); 1298 return (*it);
1203 } 1299 }
1204 } else { 1300 } else {
1205 return *it; 1301 return *it;
1206 } 1302 }
1207 } 1303 }
1208 } 1304 }
1209 return Key( QString(), type ); 1305 return Key( QString(), type );
1210} 1306}
1211void Addressee::setKeys( const Key::List& list ) { 1307void Addressee::setKeys( const Key::List& list ) {
1212 detach(); 1308 detach();
1213 mData->keys = list; 1309 mData->keys = list;
1214} 1310}
1215 1311
1216Key::List Addressee::keys() const 1312Key::List Addressee::keys() const
1217{ 1313{
1218 return mData->keys; 1314 return mData->keys;
1219} 1315}
1220 1316
1221Key::List Addressee::keys( int type, QString customTypeString ) const 1317Key::List Addressee::keys( int type, QString customTypeString ) const
1222{ 1318{
1223 Key::List list; 1319 Key::List list;
1224 1320
1225 Key::List::ConstIterator it; 1321 Key::List::ConstIterator it;
1226 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1322 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1227 if ( (*it).type() == type ) { 1323 if ( (*it).type() == type ) {
1228 if ( type == Key::Custom ) { 1324 if ( type == Key::Custom ) {
1229 if ( customTypeString.isEmpty() ) { 1325 if ( customTypeString.isEmpty() ) {
1230 list.append(*it); 1326 list.append(*it);
1231 } else { 1327 } else {
1232 if ( (*it).customTypeString() == customTypeString ) 1328 if ( (*it).customTypeString() == customTypeString )
1233 list.append(*it); 1329 list.append(*it);
1234 } 1330 }
1235 } else { 1331 } else {
1236 list.append(*it); 1332 list.append(*it);
1237 } 1333 }
1238 } 1334 }
1239 } 1335 }
1240 return list; 1336 return list;
1241} 1337}
1242 1338
1243Key Addressee::findKey( const QString &id ) const 1339Key Addressee::findKey( const QString &id ) const
1244{ 1340{
1245 Key::List::ConstIterator it; 1341 Key::List::ConstIterator it;
1246 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1342 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1247 if ( (*it).id() == id ) { 1343 if ( (*it).id() == id ) {
1248 return *it; 1344 return *it;
1249 } 1345 }
1250 } 1346 }
1251 return Key(); 1347 return Key();
1252} 1348}
1253 1349
1254QString Addressee::asString() const 1350QString Addressee::asString() const
1255{ 1351{
1256 return "Smith, agent Smith..."; 1352 return "Smith, agent Smith...";
1257} 1353}
1258 1354
1259void Addressee::dump() const 1355void Addressee::dump() const
1260{ 1356{
1261 return; 1357 return;
1262 kdDebug(5700) << "Addressee {" << endl; 1358 kdDebug(5700) << "Addressee {" << endl;
1263 1359
1264 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1360 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1265 1361
1266 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1362 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1267 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1363 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1268 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1364 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1269 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1365 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1270 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1366 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1271 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1367 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1272 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1368 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1273 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1369 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1274 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1370 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1275 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1371 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1276 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1372 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1277 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1373 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1278 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1374 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1279 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1375 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1280 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1376 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1281 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1377 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1282 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1378 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1283 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1379 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1284 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1380 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1285 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1381 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1286 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1382 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1287 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1383 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1288 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1384 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1289 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1385 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1290 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1386 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1291 1387
1292 kdDebug(5700) << " Emails {" << endl; 1388 kdDebug(5700) << " Emails {" << endl;
1293 QStringList e = emails(); 1389 QStringList e = emails();
1294 QStringList::ConstIterator it; 1390 QStringList::ConstIterator it;
1295 for( it = e.begin(); it != e.end(); ++it ) { 1391 for( it = e.begin(); it != e.end(); ++it ) {
1296 kdDebug(5700) << " " << (*it) << endl; 1392 kdDebug(5700) << " " << (*it) << endl;
1297 } 1393 }
1298 kdDebug(5700) << " }" << endl; 1394 kdDebug(5700) << " }" << endl;
1299 1395
1300 kdDebug(5700) << " PhoneNumbers {" << endl; 1396 kdDebug(5700) << " PhoneNumbers {" << endl;
1301 PhoneNumber::List p = phoneNumbers(); 1397 PhoneNumber::List p = phoneNumbers();
1302 PhoneNumber::List::ConstIterator it2; 1398 PhoneNumber::List::ConstIterator it2;
1303 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1399 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1304 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1400 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1305 } 1401 }
1306 kdDebug(5700) << " }" << endl; 1402 kdDebug(5700) << " }" << endl;
1307 1403
1308 Address::List a = addresses(); 1404 Address::List a = addresses();
1309 Address::List::ConstIterator it3; 1405 Address::List::ConstIterator it3;
1310 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1406 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1311 (*it3).dump(); 1407 (*it3).dump();
1312 } 1408 }
1313 1409
1314 kdDebug(5700) << " Keys {" << endl; 1410 kdDebug(5700) << " Keys {" << endl;
1315 Key::List k = keys(); 1411 Key::List k = keys();
1316 Key::List::ConstIterator it4; 1412 Key::List::ConstIterator it4;
1317 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1413 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1318 kdDebug(5700) << " Type: " << int((*it4).type()) << 1414 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1319 " Key: " << (*it4).textData() << 1415 " Key: " << (*it4).textData() <<
1320 " CustomString: " << (*it4).customTypeString() << endl; 1416 " CustomString: " << (*it4).customTypeString() << endl;
1321 } 1417 }
1322 kdDebug(5700) << " }" << endl; 1418 kdDebug(5700) << " }" << endl;
1323 1419
1324 kdDebug(5700) << "}" << endl; 1420 kdDebug(5700) << "}" << endl;
1325} 1421}
1326 1422
1327 1423
1328void Addressee::insertAddress( const Address &address ) 1424void Addressee::insertAddress( const Address &address )
1329{ 1425{
1330 detach(); 1426 detach();
1331 mData->empty = false; 1427 mData->empty = false;
1332 1428
1333 Address::List::Iterator it; 1429 Address::List::Iterator it;
1334 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1430 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1335 if ( (*it).id() == address.id() ) { 1431 if ( (*it).id() == address.id() ) {
1336 *it = address; 1432 *it = address;
1337 return; 1433 return;
1338 } 1434 }
1339 } 1435 }
1340 mData->addresses.append( address ); 1436 mData->addresses.append( address );
1341} 1437}
1342 1438
1343void Addressee::removeAddress( const Address &address ) 1439void Addressee::removeAddress( const Address &address )
1344{ 1440{
1345 detach(); 1441 detach();
1346 1442
1347 Address::List::Iterator it; 1443 Address::List::Iterator it;
1348 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1444 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1349 if ( (*it).id() == address.id() ) { 1445 if ( (*it).id() == address.id() ) {
1350 mData->addresses.remove( it ); 1446 mData->addresses.remove( it );
1351 return; 1447 return;
1352 } 1448 }
1353 } 1449 }
1354} 1450}
1355 1451
1356Address Addressee::address( int type ) const 1452Address Addressee::address( int type ) const
1357{ 1453{
1358 Address address( type ); 1454 Address address( type );
1359 Address::List::ConstIterator it; 1455 Address::List::ConstIterator it;
1360 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1361 if ( matchBinaryPattern( (*it).type(), type ) ) { 1457 if ( matchBinaryPattern( (*it).type(), type ) ) {
1362 if ( (*it).type() & Address::Pref ) 1458 if ( (*it).type() & Address::Pref )
1363 return (*it); 1459 return (*it);
1364 else if ( address.isEmpty() ) 1460 else if ( address.isEmpty() )
1365 address = (*it); 1461 address = (*it);
1366 } 1462 }
1367 } 1463 }
1368 1464
1369 return address; 1465 return address;
1370} 1466}
1371 1467
1372Address::List Addressee::addresses() const 1468Address::List Addressee::addresses() const
1373{ 1469{
1374 return mData->addresses; 1470 return mData->addresses;
1375} 1471}
1376 1472
1377Address::List Addressee::addresses( int type ) const 1473Address::List Addressee::addresses( int type ) const
1378{ 1474{
1379 Address::List list; 1475 Address::List list;
1380 1476
1381 Address::List::ConstIterator it; 1477 Address::List::ConstIterator it;
1382 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1478 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1383 if ( matchBinaryPattern( (*it).type(), type ) ) { 1479 if ( matchBinaryPattern( (*it).type(), type ) ) {
1384 list.append( *it ); 1480 list.append( *it );
1385 } 1481 }
1386 } 1482 }
1387 1483
1388 return list; 1484 return list;
1389} 1485}
1390 1486
1391Address Addressee::findAddress( const QString &id ) const 1487Address Addressee::findAddress( const QString &id ) const
1392{ 1488{
1393 Address::List::ConstIterator it; 1489 Address::List::ConstIterator it;
1394 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1490 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1395 if ( (*it).id() == id ) { 1491 if ( (*it).id() == id ) {
1396 return *it; 1492 return *it;
1397 } 1493 }
1398 } 1494 }
1399 return Address(); 1495 return Address();
1400} 1496}
1401 1497
1402void Addressee::insertCategory( const QString &c ) 1498void Addressee::insertCategory( const QString &c )
1403{ 1499{
1404 detach(); 1500 detach();
1405 mData->empty = false; 1501 mData->empty = false;
1406 1502
1407 if ( mData->categories.contains( c ) ) return; 1503 if ( mData->categories.contains( c ) ) return;
1408 1504
1409 mData->categories.append( c ); 1505 mData->categories.append( c );
1410} 1506}
1411 1507
1412void Addressee::removeCategory( const QString &c ) 1508void Addressee::removeCategory( const QString &c )
1413{ 1509{
1414 detach(); 1510 detach();
1415 1511
1416 QStringList::Iterator it = mData->categories.find( c ); 1512 QStringList::Iterator it = mData->categories.find( c );
1417 if ( it == mData->categories.end() ) return; 1513 if ( it == mData->categories.end() ) return;
1418 1514
1419 mData->categories.remove( it ); 1515 mData->categories.remove( it );
1420} 1516}
1421 1517
1422bool Addressee::hasCategory( const QString &c ) const 1518bool Addressee::hasCategory( const QString &c ) const
1423{ 1519{
1424 return ( mData->categories.contains( c ) ); 1520 return ( mData->categories.contains( c ) );
1425} 1521}
1426 1522
1427void Addressee::setCategories( const QStringList &c ) 1523void Addressee::setCategories( const QStringList &c )
1428{ 1524{
1429 detach(); 1525 detach();
1430 mData->empty = false; 1526 mData->empty = false;
1431 1527
1432 mData->categories = c; 1528 mData->categories = c;
1433} 1529}
1434 1530
1435QStringList Addressee::categories() const 1531QStringList Addressee::categories() const
1436{ 1532{
1437 return mData->categories; 1533 return mData->categories;
1438} 1534}
1439 1535
1440void Addressee::insertCustom( const QString &app, const QString &name, 1536void Addressee::insertCustom( const QString &app, const QString &name,
1441 const QString &value ) 1537 const QString &value )
1442{ 1538{
1443 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1539 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1444 1540
1445 detach(); 1541 detach();
1446 mData->empty = false; 1542 mData->empty = false;
1447 1543
1448 QString qualifiedName = app + "-" + name + ":"; 1544 QString qualifiedName = app + "-" + name + ":";
1449 1545
1450 QStringList::Iterator it; 1546 QStringList::Iterator it;
1451 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1547 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1452 if ( (*it).startsWith( qualifiedName ) ) { 1548 if ( (*it).startsWith( qualifiedName ) ) {
1453 (*it) = qualifiedName + value; 1549 (*it) = qualifiedName + value;
1454 return; 1550 return;
1455 } 1551 }
1456 } 1552 }
1457
1458 mData->custom.append( qualifiedName + value ); 1553 mData->custom.append( qualifiedName + value );
1459} 1554}
1460 1555
1461void Addressee::removeCustom( const QString &app, const QString &name) 1556void Addressee::removeCustom( const QString &app, const QString &name)
1462{ 1557{
1463 detach(); 1558 detach();
1464 1559
1465 QString qualifiedName = app + "-" + name + ":"; 1560 QString qualifiedName = app + "-" + name + ":";
1466 1561
1467 QStringList::Iterator it; 1562 QStringList::Iterator it;
1468 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1563 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1469 if ( (*it).startsWith( qualifiedName ) ) { 1564 if ( (*it).startsWith( qualifiedName ) ) {
1470 mData->custom.remove( it ); 1565 mData->custom.remove( it );
1471 return; 1566 return;
1472 } 1567 }
1473 } 1568 }
1474} 1569}
1475 1570
1476QString Addressee::custom( const QString &app, const QString &name ) const 1571QString Addressee::custom( const QString &app, const QString &name ) const
1477{ 1572{
1478 QString qualifiedName = app + "-" + name + ":"; 1573 QString qualifiedName = app + "-" + name + ":";
1479 QString value; 1574 QString value;
1480 1575
1481 QStringList::ConstIterator it; 1576 QStringList::ConstIterator it;
1482 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1577 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1483 if ( (*it).startsWith( qualifiedName ) ) { 1578 if ( (*it).startsWith( qualifiedName ) ) {
1484 value = (*it).mid( (*it).find( ":" ) + 1 ); 1579 value = (*it).mid( (*it).find( ":" ) + 1 );
1485 break; 1580 break;
1486 } 1581 }
1487 } 1582 }
1488 1583
1489 return value; 1584 return value;
1490} 1585}
1491 1586
1492void Addressee::setCustoms( const QStringList &l ) 1587void Addressee::setCustoms( const QStringList &l )
1493{ 1588{
1494 detach(); 1589 detach();
1495 mData->empty = false; 1590 mData->empty = false;
1496 1591
1497 mData->custom = l; 1592 mData->custom = l;
1498} 1593}
1499 1594
1500QStringList Addressee::customs() const 1595QStringList Addressee::customs() const
1501{ 1596{
1502 return mData->custom; 1597 return mData->custom;
1503} 1598}
1504 1599
1505void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1600void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1506 QString &email) 1601 QString &email)
1507{ 1602{
1508 int startPos, endPos, len; 1603 int startPos, endPos, len;
1509 QString partA, partB, result; 1604 QString partA, partB, result;
1510 char endCh = '>'; 1605 char endCh = '>';
1511 1606
1512 startPos = rawEmail.find('<'); 1607 startPos = rawEmail.find('<');
1513 if (startPos < 0) 1608 if (startPos < 0)
1514 { 1609 {
1515 startPos = rawEmail.find('('); 1610 startPos = rawEmail.find('(');
1516 endCh = ')'; 1611 endCh = ')';
1517 } 1612 }
1518 if (startPos < 0) 1613 if (startPos < 0)
1519 { 1614 {
1520 // We couldn't find any separators, so we assume the whole string 1615 // We couldn't find any separators, so we assume the whole string
1521 // is the email address 1616 // is the email address
1522 email = rawEmail; 1617 email = rawEmail;
1523 fullName = ""; 1618 fullName = "";
1524 } 1619 }
1525 else 1620 else
1526 { 1621 {
1527 // We have a start position, try to find an end 1622 // We have a start position, try to find an end
1528 endPos = rawEmail.find(endCh, startPos+1); 1623 endPos = rawEmail.find(endCh, startPos+1);
1529 1624
1530 if (endPos < 0) 1625 if (endPos < 0)
1531 { 1626 {
1532 // We couldn't find the end of the email address. We can only 1627 // We couldn't find the end of the email address. We can only
1533 // assume the entire string is the email address. 1628 // assume the entire string is the email address.
1534 email = rawEmail; 1629 email = rawEmail;
1535 fullName = ""; 1630 fullName = "";
1536 } 1631 }
1537 else 1632 else
1538 { 1633 {
1539 // We have a start and end to the email address 1634 // We have a start and end to the email address
1540 1635
1541 // Grab the name part 1636 // Grab the name part
1542 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1637 fullName = rawEmail.left(startPos).stripWhiteSpace();
1543 1638
1544 // grab the email part 1639 // grab the email part
1545 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1640 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1546 1641
1547 // Check that we do not have any extra characters on the end of the 1642 // Check that we do not have any extra characters on the end of the
1548 // strings 1643 // strings
1549 len = fullName.length(); 1644 len = fullName.length();
1550 if (fullName[0]=='"' && fullName[len-1]=='"') 1645 if (fullName[0]=='"' && fullName[len-1]=='"')
1551 fullName = fullName.mid(1, len-2); 1646 fullName = fullName.mid(1, len-2);
1552 else if (fullName[0]=='<' && fullName[len-1]=='>') 1647 else if (fullName[0]=='<' && fullName[len-1]=='>')
1553 fullName = fullName.mid(1, len-2); 1648 fullName = fullName.mid(1, len-2);
1554 else if (fullName[0]=='(' && fullName[len-1]==')') 1649 else if (fullName[0]=='(' && fullName[len-1]==')')
1555 fullName = fullName.mid(1, len-2); 1650 fullName = fullName.mid(1, len-2);
1556 } 1651 }
1557 } 1652 }
1558} 1653}
1559 1654
1560void Addressee::setResource( Resource *resource ) 1655void Addressee::setResource( Resource *resource )
1561{ 1656{
1562 detach(); 1657 detach();
1563 mData->resource = resource; 1658 mData->resource = resource;
1564} 1659}
1565 1660
1566Resource *Addressee::resource() const 1661Resource *Addressee::resource() const
1567{ 1662{
1568 return mData->resource; 1663 return mData->resource;
1569} 1664}
1570 1665
1571//US 1666//US
1572QString Addressee::resourceLabel() 1667QString Addressee::resourceLabel()
1573{ 1668{
1574 return i18n("Resource"); 1669 return i18n("Resource");
1575} 1670}
1576 1671
1577void Addressee::setChanged( bool value ) 1672void Addressee::setChanged( bool value )
1578{ 1673{
1579 detach(); 1674 detach();
1580 mData->changed = value; 1675 mData->changed = value;
1581} 1676}
1582 1677
1583bool Addressee::changed() const 1678bool Addressee::changed() const
1584{ 1679{
1585 return mData->changed; 1680 return mData->changed;
1586} 1681}
1587 1682
1588QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 1683QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
1589{ 1684{
1590 if (!a.mData) return s; 1685 if (!a.mData) return s;
1591 1686
1592 s << a.uid(); 1687 s << a.uid();
1593 1688
1594 s << a.mData->name; 1689 s << a.mData->name;
1595 s << a.mData->formattedName; 1690 s << a.mData->formattedName;
1596 s << a.mData->familyName; 1691 s << a.mData->familyName;
1597 s << a.mData->givenName; 1692 s << a.mData->givenName;
1598 s << a.mData->additionalName; 1693 s << a.mData->additionalName;
1599 s << a.mData->prefix; 1694 s << a.mData->prefix;
1600 s << a.mData->suffix; 1695 s << a.mData->suffix;
1601 s << a.mData->nickName; 1696 s << a.mData->nickName;
1602 s << a.mData->birthday; 1697 s << a.mData->birthday;
1603 s << a.mData->mailer; 1698 s << a.mData->mailer;
1604 s << a.mData->timeZone; 1699 s << a.mData->timeZone;
1605 s << a.mData->geo; 1700 s << a.mData->geo;
1606 s << a.mData->title; 1701 s << a.mData->title;
1607 s << a.mData->role; 1702 s << a.mData->role;
1608 s << a.mData->organization; 1703 s << a.mData->organization;
1609 s << a.mData->note; 1704 s << a.mData->note;
1610 s << a.mData->productId; 1705 s << a.mData->productId;
1611 s << a.mData->revision; 1706 s << a.mData->revision;
1612 s << a.mData->sortString; 1707 s << a.mData->sortString;
1613 s << a.mData->url; 1708 s << a.mData->url;
1614 s << a.mData->secrecy; 1709 s << a.mData->secrecy;
1615 s << a.mData->logo; 1710 s << a.mData->logo;
1616 s << a.mData->photo; 1711 s << a.mData->photo;
1617 s << a.mData->sound; 1712 s << a.mData->sound;
1618 s << a.mData->agent; 1713 s << a.mData->agent;
1619 s << a.mData->phoneNumbers; 1714 s << a.mData->phoneNumbers;
1620 s << a.mData->addresses; 1715 s << a.mData->addresses;
1621 s << a.mData->emails; 1716 s << a.mData->emails;
1622 s << a.mData->categories; 1717 s << a.mData->categories;
1623 s << a.mData->custom; 1718 s << a.mData->custom;
1624 s << a.mData->keys; 1719 s << a.mData->keys;
1625 return s; 1720 return s;
1626} 1721}
1627 1722
1628QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 1723QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
1629{ 1724{
1630 if (!a.mData) return s; 1725 if (!a.mData) return s;
1631 1726
1632 s >> a.mData->uid; 1727 s >> a.mData->uid;
1633 1728
1634 s >> a.mData->name; 1729 s >> a.mData->name;
1635 s >> a.mData->formattedName; 1730 s >> a.mData->formattedName;
1636 s >> a.mData->familyName; 1731 s >> a.mData->familyName;
1637 s >> a.mData->givenName; 1732 s >> a.mData->givenName;
1638 s >> a.mData->additionalName; 1733 s >> a.mData->additionalName;
1639 s >> a.mData->prefix; 1734 s >> a.mData->prefix;
1640 s >> a.mData->suffix; 1735 s >> a.mData->suffix;
1641 s >> a.mData->nickName; 1736 s >> a.mData->nickName;
1642 s >> a.mData->birthday; 1737 s >> a.mData->birthday;
1643 s >> a.mData->mailer; 1738 s >> a.mData->mailer;
1644 s >> a.mData->timeZone; 1739 s >> a.mData->timeZone;
1645 s >> a.mData->geo; 1740 s >> a.mData->geo;
1646 s >> a.mData->title; 1741 s >> a.mData->title;
1647 s >> a.mData->role; 1742 s >> a.mData->role;
1648 s >> a.mData->organization; 1743 s >> a.mData->organization;
1649 s >> a.mData->note; 1744 s >> a.mData->note;
1650 s >> a.mData->productId; 1745 s >> a.mData->productId;
1651 s >> a.mData->revision; 1746 s >> a.mData->revision;
1652 s >> a.mData->sortString; 1747 s >> a.mData->sortString;
1653 s >> a.mData->url; 1748 s >> a.mData->url;
1654 s >> a.mData->secrecy; 1749 s >> a.mData->secrecy;
1655 s >> a.mData->logo; 1750 s >> a.mData->logo;
1656 s >> a.mData->photo; 1751 s >> a.mData->photo;
1657 s >> a.mData->sound; 1752 s >> a.mData->sound;
1658 s >> a.mData->agent; 1753 s >> a.mData->agent;
1659 s >> a.mData->phoneNumbers; 1754 s >> a.mData->phoneNumbers;
1660 s >> a.mData->addresses; 1755 s >> a.mData->addresses;
1661 s >> a.mData->emails; 1756 s >> a.mData->emails;
1662 s >> a.mData->categories; 1757 s >> a.mData->categories;
1663 s >> a.mData->custom; 1758 s >> a.mData->custom;
1664 s >> a.mData->keys; 1759 s >> a.mData->keys;
1665 1760
1666 a.mData->empty = false; 1761 a.mData->empty = false;
1667 1762
1668 return s; 1763 return s;
1669} 1764}
1670 1765
1671bool matchBinaryPattern( int value, int pattern ) 1766bool matchBinaryPattern( int value, int pattern )
1672{ 1767{
1673 /** 1768 /**
1674 We want to match all telephonnumbers/addresses which have the bits in the 1769 We want to match all telephonnumbers/addresses which have the bits in the
1675 pattern set. More are allowed. 1770 pattern set. More are allowed.
1676 if pattern == 0 we have a special handling, then we want only those with 1771 if pattern == 0 we have a special handling, then we want only those with
1677 exactly no bit set. 1772 exactly no bit set.
1678 */ 1773 */
1679 if ( pattern == 0 ) 1774 if ( pattern == 0 )
1680 return ( value == 0 ); 1775 return ( value == 0 );
1681 else 1776 else
1682 return ( pattern == ( pattern & value ) ); 1777 return ( pattern == ( pattern & value ) );
1683} 1778}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index f098371..0805458 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -1,838 +1,840 @@
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 <qstringlist.h> 34#include <qstringlist.h>
35#include <qvaluelist.h> 35#include <qvaluelist.h>
36 36
37#include <ksharedptr.h> 37#include <ksharedptr.h>
38#include <kurl.h> 38#include <kurl.h>
39 39
40#include "address.h" 40#include "address.h"
41#include "agent.h" 41#include "agent.h"
42#include "geo.h" 42#include "geo.h"
43#include "key.h" 43#include "key.h"
44#include "phonenumber.h" 44#include "phonenumber.h"
45#include "picture.h" 45#include "picture.h"
46#include "secrecy.h" 46#include "secrecy.h"
47#include "sound.h" 47#include "sound.h"
48#include "timezone.h" 48#include "timezone.h"
49 49
50namespace KABC { 50namespace KABC {
51 51
52class Resource; 52class Resource;
53 53
54/** 54/**
55 @short address book entry 55 @short address book entry
56 56
57 This class represents an entry in the address book. 57 This class represents an entry in the address book.
58 58
59 The data of this class is implicitly shared. You can pass this class by value. 59 The data of this class is implicitly shared. You can pass this class by value.
60 60
61 If you need the name of a field for presenting it to the user you should use 61 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 62 the functions ending in Label(). They return a translated string which can be
63 used as label for the corresponding field. 63 used as label for the corresponding field.
64 64
65 About the name fields: 65 About the name fields:
66 66
67 givenName() is the first name and familyName() the last name. In some 67 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 68 countries the family name comes first, that's the reason for the
69 naming. formattedName() is the full name with the correct formatting. 69 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 70 It is used as an override, when the correct formatting can't be generated
71 from the other name fields automatically. 71 from the other name fields automatically.
72 72
73 realName() returns a fully formatted name(). It uses formattedName, if set, 73 realName() returns a fully formatted name(). It uses formattedName, if set,
74 otherwise it constucts the name from the name fields. As fallback, if 74 otherwise it constucts the name from the name fields. As fallback, if
75 nothing else is set it uses name(). 75 nothing else is set it uses name().
76 76
77 name() is the NAME type of RFC2426. It can be used as internal name for the 77 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. 78 data enty, but shouldn't be used for displaying the data to the user.
79 */ 79 */
80class Addressee 80class Addressee
81{ 81{
82 friend QDataStream &operator<<( QDataStream &, const Addressee & ); 82 friend QDataStream &operator<<( QDataStream &, const Addressee & );
83 friend QDataStream &operator>>( QDataStream &, Addressee & ); 83 friend QDataStream &operator>>( QDataStream &, Addressee & );
84 84
85 public: 85 public:
86 typedef QValueList<Addressee> List; 86 typedef QValueList<Addressee> List;
87 87
88 /** 88 /**
89 Construct an empty address book entry. 89 Construct an empty address book entry.
90 */ 90 */
91 Addressee(); 91 Addressee();
92 ~Addressee(); 92 ~Addressee();
93 93
94 Addressee( const Addressee & ); 94 Addressee( const Addressee & );
95 Addressee &operator=( const Addressee & ); 95 Addressee &operator=( const Addressee & );
96 96
97 bool operator==( const Addressee & ) const; 97 bool operator==( const Addressee & ) const;
98 bool operator!=( const Addressee & ) const; 98 bool operator!=( const Addressee & ) const;
99 // sync stuff 99 // sync stuff
100 void setTempSyncStat(int id); 100 void setTempSyncStat(int id);
101 int tempSyncStat() const; 101 int tempSyncStat() const;
102 void setIDStr( const QString & ); 102 void setIDStr( const QString & );
103 QString IDStr() const; 103 QString IDStr() const;
104 void setID( const QString &, const QString & ); 104 void setID( const QString &, const QString & );
105 QString getID( const QString & ); 105 QString getID( const QString & );
106 void setCsum( const QString &, const QString & ); 106 void setCsum( const QString &, const QString & );
107 QString getCsum( const QString & ); 107 QString getCsum( const QString & );
108 void removeID(const QString &); 108 void removeID(const QString &);
109 void computeCsum(const QString &dev);
110 ulong getCsum4List( const QStringList & attList);
109 /** 111 /**
110 Return, if the address book entry is empty. 112 Return, if the address book entry is empty.
111 */ 113 */
112 bool isEmpty() const; 114 bool isEmpty() const;
113 115
114 /** 116 /**
115 Set unique identifier. 117 Set unique identifier.
116 */ 118 */
117 void setUid( const QString &uid ); 119 void setUid( const QString &uid );
118 /** 120 /**
119 Return unique identifier. 121 Return unique identifier.
120 */ 122 */
121 QString uid() const; 123 QString uid() const;
122 /** 124 /**
123 Return translated label for uid field. 125 Return translated label for uid field.
124 */ 126 */
125 static QString uidLabel(); 127 static QString uidLabel();
126 128
127 /** 129 /**
128 Set name. 130 Set name.
129 */ 131 */
130 void setName( const QString &name ); 132 void setName( const QString &name );
131 /** 133 /**
132 Return name. 134 Return name.
133 */ 135 */
134 QString name() const; 136 QString name() const;
135 /** 137 /**
136 Return translated label for name field. 138 Return translated label for name field.
137 */ 139 */
138 static QString nameLabel(); 140 static QString nameLabel();
139 141
140 /** 142 /**
141 Set formatted name. 143 Set formatted name.
142 */ 144 */
143 void setFormattedName( const QString &formattedName ); 145 void setFormattedName( const QString &formattedName );
144 /** 146 /**
145 Return formatted name. 147 Return formatted name.
146 */ 148 */
147 QString formattedName() const; 149 QString formattedName() const;
148 /** 150 /**
149 Return translated label for formattedName field. 151 Return translated label for formattedName field.
150 */ 152 */
151 static QString formattedNameLabel(); 153 static QString formattedNameLabel();
152 154
153 /** 155 /**
154 Set family name. 156 Set family name.
155 */ 157 */
156 void setFamilyName( const QString &familyName ); 158 void setFamilyName( const QString &familyName );
157 /** 159 /**
158 Return family name. 160 Return family name.
159 */ 161 */
160 QString familyName() const; 162 QString familyName() const;
161 /** 163 /**
162 Return translated label for familyName field. 164 Return translated label for familyName field.
163 */ 165 */
164 static QString familyNameLabel(); 166 static QString familyNameLabel();
165 167
166 /** 168 /**
167 Set given name. 169 Set given name.
168 */ 170 */
169 void setGivenName( const QString &givenName ); 171 void setGivenName( const QString &givenName );
170 /** 172 /**
171 Return given name. 173 Return given name.
172 */ 174 */
173 QString givenName() const; 175 QString givenName() const;
174 /** 176 /**
175 Return translated label for givenName field. 177 Return translated label for givenName field.
176 */ 178 */
177 static QString givenNameLabel(); 179 static QString givenNameLabel();
178 180
179 /** 181 /**
180 Set additional names. 182 Set additional names.
181 */ 183 */
182 void setAdditionalName( const QString &additionalName ); 184 void setAdditionalName( const QString &additionalName );
183 /** 185 /**
184 Return additional names. 186 Return additional names.
185 */ 187 */
186 QString additionalName() const; 188 QString additionalName() const;
187 /** 189 /**
188 Return translated label for additionalName field. 190 Return translated label for additionalName field.
189 */ 191 */
190 static QString additionalNameLabel(); 192 static QString additionalNameLabel();
191 193
192 /** 194 /**
193 Set honorific prefixes. 195 Set honorific prefixes.
194 */ 196 */
195 void setPrefix( const QString &prefix ); 197 void setPrefix( const QString &prefix );
196 /** 198 /**
197 Return honorific prefixes. 199 Return honorific prefixes.
198 */ 200 */
199 QString prefix() const; 201 QString prefix() const;
200 /** 202 /**
201 Return translated label for prefix field. 203 Return translated label for prefix field.
202 */ 204 */
203 static QString prefixLabel(); 205 static QString prefixLabel();
204 206
205 /** 207 /**
206 Set honorific suffixes. 208 Set honorific suffixes.
207 */ 209 */
208 void setSuffix( const QString &suffix ); 210 void setSuffix( const QString &suffix );
209 /** 211 /**
210 Return honorific suffixes. 212 Return honorific suffixes.
211 */ 213 */
212 QString suffix() const; 214 QString suffix() const;
213 /** 215 /**
214 Return translated label for suffix field. 216 Return translated label for suffix field.
215 */ 217 */
216 static QString suffixLabel(); 218 static QString suffixLabel();
217 219
218 /** 220 /**
219 Set nick name. 221 Set nick name.
220 */ 222 */
221 void setNickName( const QString &nickName ); 223 void setNickName( const QString &nickName );
222 /** 224 /**
223 Return nick name. 225 Return nick name.
224 */ 226 */
225 QString nickName() const; 227 QString nickName() const;
226 /** 228 /**
227 Return translated label for nickName field. 229 Return translated label for nickName field.
228 */ 230 */
229 static QString nickNameLabel(); 231 static QString nickNameLabel();
230 232
231 /** 233 /**
232 Set birthday. 234 Set birthday.
233 */ 235 */
234 void setBirthday( const QDateTime &birthday ); 236 void setBirthday( const QDateTime &birthday );
235 /** 237 /**
236 Return birthday. 238 Return birthday.
237 */ 239 */
238 QDateTime birthday() const; 240 QDateTime birthday() const;
239 /** 241 /**
240 Return translated label for birthday field. 242 Return translated label for birthday field.
241 */ 243 */
242 static QString birthdayLabel(); 244 static QString birthdayLabel();
243 245
244 /** 246 /**
245 Return translated label for homeAddressStreet field. 247 Return translated label for homeAddressStreet field.
246 */ 248 */
247 static QString homeAddressStreetLabel(); 249 static QString homeAddressStreetLabel();
248 250
249 /** 251 /**
250 Return translated label for homeAddressLocality field. 252 Return translated label for homeAddressLocality field.
251 */ 253 */
252 static QString homeAddressLocalityLabel(); 254 static QString homeAddressLocalityLabel();
253 255
254 /** 256 /**
255 Return translated label for homeAddressRegion field. 257 Return translated label for homeAddressRegion field.
256 */ 258 */
257 static QString homeAddressRegionLabel(); 259 static QString homeAddressRegionLabel();
258 260
259 /** 261 /**
260 Return translated label for homeAddressPostalCode field. 262 Return translated label for homeAddressPostalCode field.
261 */ 263 */
262 static QString homeAddressPostalCodeLabel(); 264 static QString homeAddressPostalCodeLabel();
263 265
264 /** 266 /**
265 Return translated label for homeAddressCountry field. 267 Return translated label for homeAddressCountry field.
266 */ 268 */
267 static QString homeAddressCountryLabel(); 269 static QString homeAddressCountryLabel();
268 270
269 /** 271 /**
270 Return translated label for homeAddressLabel field. 272 Return translated label for homeAddressLabel field.
271 */ 273 */
272 static QString homeAddressLabelLabel(); 274 static QString homeAddressLabelLabel();
273 275
274 /** 276 /**
275 Return translated label for businessAddressStreet field. 277 Return translated label for businessAddressStreet field.
276 */ 278 */
277 static QString businessAddressStreetLabel(); 279 static QString businessAddressStreetLabel();
278 280
279 /** 281 /**
280 Return translated label for businessAddressLocality field. 282 Return translated label for businessAddressLocality field.
281 */ 283 */
282 static QString businessAddressLocalityLabel(); 284 static QString businessAddressLocalityLabel();
283 285
284 /** 286 /**
285 Return translated label for businessAddressRegion field. 287 Return translated label for businessAddressRegion field.
286 */ 288 */
287 static QString businessAddressRegionLabel(); 289 static QString businessAddressRegionLabel();
288 290
289 /** 291 /**
290 Return translated label for businessAddressPostalCode field. 292 Return translated label for businessAddressPostalCode field.
291 */ 293 */
292 static QString businessAddressPostalCodeLabel(); 294 static QString businessAddressPostalCodeLabel();
293 295
294 /** 296 /**
295 Return translated label for businessAddressCountry field. 297 Return translated label for businessAddressCountry field.
296 */ 298 */
297 static QString businessAddressCountryLabel(); 299 static QString businessAddressCountryLabel();
298 300
299 /** 301 /**
300 Return translated label for businessAddressLabel field. 302 Return translated label for businessAddressLabel field.
301 */ 303 */
302 static QString businessAddressLabelLabel(); 304 static QString businessAddressLabelLabel();
303 305
304 /** 306 /**
305 Return translated label for homePhone field. 307 Return translated label for homePhone field.
306 */ 308 */
307 static QString homePhoneLabel(); 309 static QString homePhoneLabel();
308 310
309 /** 311 /**
310 Return translated label for businessPhone field. 312 Return translated label for businessPhone field.
311 */ 313 */
312 static QString businessPhoneLabel(); 314 static QString businessPhoneLabel();
313 315
314 /** 316 /**
315 Return translated label for mobilePhone field. 317 Return translated label for mobilePhone field.
316 */ 318 */
317 static QString mobilePhoneLabel(); 319 static QString mobilePhoneLabel();
318 320
319 /** 321 /**
320 Return translated label for homeFax field. 322 Return translated label for homeFax field.
321 */ 323 */
322 static QString homeFaxLabel(); 324 static QString homeFaxLabel();
323 325
324 /** 326 /**
325 Return translated label for businessFax field. 327 Return translated label for businessFax field.
326 */ 328 */
327 static QString businessFaxLabel(); 329 static QString businessFaxLabel();
328 330
329 /** 331 /**
330 Return translated label for carPhone field. 332 Return translated label for carPhone field.
331 */ 333 */
332 static QString carPhoneLabel(); 334 static QString carPhoneLabel();
333 335
334 /** 336 /**
335 Return translated label for isdn field. 337 Return translated label for isdn field.
336 */ 338 */
337 static QString isdnLabel(); 339 static QString isdnLabel();
338 340
339 /** 341 /**
340 Return translated label for pager field. 342 Return translated label for pager field.
341 */ 343 */
342 static QString pagerLabel(); 344 static QString pagerLabel();
343 345
344 /** 346 /**
345 Return translated label for sip field. 347 Return translated label for sip field.
346 */ 348 */
347 static QString sipLabel(); 349 static QString sipLabel();
348 350
349 /** 351 /**
350 Return translated label for email field. 352 Return translated label for email field.
351 */ 353 */
352 static QString emailLabel(); 354 static QString emailLabel();
353 355
354 /** 356 /**
355 Set mail client. 357 Set mail client.
356 */ 358 */
357 void setMailer( const QString &mailer ); 359 void setMailer( const QString &mailer );
358 /** 360 /**
359 Return mail client. 361 Return mail client.
360 */ 362 */
361 QString mailer() const; 363 QString mailer() const;
362 /** 364 /**
363 Return translated label for mailer field. 365 Return translated label for mailer field.
364 */ 366 */
365 static QString mailerLabel(); 367 static QString mailerLabel();
366 368
367 /** 369 /**
368 Set time zone. 370 Set time zone.
369 */ 371 */
370 void setTimeZone( const TimeZone &timeZone ); 372 void setTimeZone( const TimeZone &timeZone );
371 /** 373 /**
372 Return time zone. 374 Return time zone.
373 */ 375 */
374 TimeZone timeZone() const; 376 TimeZone timeZone() const;
375 /** 377 /**
376 Return translated label for timeZone field. 378 Return translated label for timeZone field.
377 */ 379 */
378 static QString timeZoneLabel(); 380 static QString timeZoneLabel();
379 381
380 /** 382 /**
381 Set geographic position. 383 Set geographic position.
382 */ 384 */
383 void setGeo( const Geo &geo ); 385 void setGeo( const Geo &geo );
384 /** 386 /**
385 Return geographic position. 387 Return geographic position.
386 */ 388 */
387 Geo geo() const; 389 Geo geo() const;
388 /** 390 /**
389 Return translated label for geo field. 391 Return translated label for geo field.
390 */ 392 */
391 static QString geoLabel(); 393 static QString geoLabel();
392 394
393 /** 395 /**
394 Set title. 396 Set title.
395 */ 397 */
396 void setTitle( const QString &title ); 398 void setTitle( const QString &title );
397 /** 399 /**
398 Return title. 400 Return title.
399 */ 401 */
400 QString title() const; 402 QString title() const;
401 /** 403 /**
402 Return translated label for title field. 404 Return translated label for title field.
403 */ 405 */
404 static QString titleLabel(); 406 static QString titleLabel();
405 407
406 /** 408 /**
407 Set role. 409 Set role.
408 */ 410 */
409 void setRole( const QString &role ); 411 void setRole( const QString &role );
410 /** 412 /**
411 Return role. 413 Return role.
412 */ 414 */
413 QString role() const; 415 QString role() const;
414 /** 416 /**
415 Return translated label for role field. 417 Return translated label for role field.
416 */ 418 */
417 static QString roleLabel(); 419 static QString roleLabel();
418 420
419 /** 421 /**
420 Set organization. 422 Set organization.
421 */ 423 */
422 void setOrganization( const QString &organization ); 424 void setOrganization( const QString &organization );
423 /** 425 /**
424 Return organization. 426 Return organization.
425 */ 427 */
426 QString organization() const; 428 QString organization() const;
427 /** 429 /**
428 Return translated label for organization field. 430 Return translated label for organization field.
429 */ 431 */
430 static QString organizationLabel(); 432 static QString organizationLabel();
431 433
432 /** 434 /**
433 Set note. 435 Set note.
434 */ 436 */
435 void setNote( const QString &note ); 437 void setNote( const QString &note );
436 /** 438 /**
437 Return note. 439 Return note.
438 */ 440 */
439 QString note() const; 441 QString note() const;
440 /** 442 /**
441 Return translated label for note field. 443 Return translated label for note field.
442 */ 444 */
443 static QString noteLabel(); 445 static QString noteLabel();
444 446
445 /** 447 /**
446 Set product identifier. 448 Set product identifier.
447 */ 449 */
448 void setProductId( const QString &productId ); 450 void setProductId( const QString &productId );
449 /** 451 /**
450 Return product identifier. 452 Return product identifier.
451 */ 453 */
452 QString productId() const; 454 QString productId() const;
453 /** 455 /**
454 Return translated label for productId field. 456 Return translated label for productId field.
455 */ 457 */
456 static QString productIdLabel(); 458 static QString productIdLabel();
457 459
458 /** 460 /**
459 Set revision date. 461 Set revision date.
460 */ 462 */
461 void setRevision( const QDateTime &revision ); 463 void setRevision( const QDateTime &revision );
462 /** 464 /**
463 Return revision date. 465 Return revision date.
464 */ 466 */
465 QDateTime revision() const; 467 QDateTime revision() const;
466 /** 468 /**
467 Return translated label for revision field. 469 Return translated label for revision field.
468 */ 470 */
469 static QString revisionLabel(); 471 static QString revisionLabel();
470 472
471 /** 473 /**
472 Set sort string. 474 Set sort string.
473 */ 475 */
474 void setSortString( const QString &sortString ); 476 void setSortString( const QString &sortString );
475 /** 477 /**
476 Return sort string. 478 Return sort string.
477 */ 479 */
478 QString sortString() const; 480 QString sortString() const;
479 /** 481 /**
480 Return translated label for sortString field. 482 Return translated label for sortString field.
481 */ 483 */
482 static QString sortStringLabel(); 484 static QString sortStringLabel();
483 485
484 /** 486 /**
485 Set URL. 487 Set URL.
486 */ 488 */
487 void setUrl( const KURL &url ); 489 void setUrl( const KURL &url );
488 /** 490 /**
489 Return URL. 491 Return URL.
490 */ 492 */
491 KURL url() const; 493 KURL url() const;
492 /** 494 /**
493 Return translated label for url field. 495 Return translated label for url field.
494 */ 496 */
495 static QString urlLabel(); 497 static QString urlLabel();
496 498
497 /** 499 /**
498 Set security class. 500 Set security class.
499 */ 501 */
500 void setSecrecy( const Secrecy &secrecy ); 502 void setSecrecy( const Secrecy &secrecy );
501 /** 503 /**
502 Return security class. 504 Return security class.
503 */ 505 */
504 Secrecy secrecy() const; 506 Secrecy secrecy() const;
505 /** 507 /**
506 Return translated label for secrecy field. 508 Return translated label for secrecy field.
507 */ 509 */
508 static QString secrecyLabel(); 510 static QString secrecyLabel();
509 511
510 /** 512 /**
511 Set logo. 513 Set logo.
512 */ 514 */
513 void setLogo( const Picture &logo ); 515 void setLogo( const Picture &logo );
514 /** 516 /**
515 Return logo. 517 Return logo.
516 */ 518 */
517 Picture logo() const; 519 Picture logo() const;
518 /** 520 /**
519 Return translated label for logo field. 521 Return translated label for logo field.
520 */ 522 */
521 static QString logoLabel(); 523 static QString logoLabel();
522 524
523 /** 525 /**
524 Set photo. 526 Set photo.
525 */ 527 */
526 void setPhoto( const Picture &photo ); 528 void setPhoto( const Picture &photo );
527 /** 529 /**
528 Return photo. 530 Return photo.
529 */ 531 */
530 Picture photo() const; 532 Picture photo() const;
531 /** 533 /**
532 Return translated label for photo field. 534 Return translated label for photo field.
533 */ 535 */
534 static QString photoLabel(); 536 static QString photoLabel();
535 537
536 /** 538 /**
537 Set sound. 539 Set sound.
538 */ 540 */
539 void setSound( const Sound &sound ); 541 void setSound( const Sound &sound );
540 /** 542 /**
541 Return sound. 543 Return sound.
542 */ 544 */
543 Sound sound() const; 545 Sound sound() const;
544 /** 546 /**
545 Return translated label for sound field. 547 Return translated label for sound field.
546 */ 548 */
547 static QString soundLabel(); 549 static QString soundLabel();
548 550
549 /** 551 /**
550 Set agent. 552 Set agent.
551 */ 553 */
552 void setAgent( const Agent &agent ); 554 void setAgent( const Agent &agent );
553 /** 555 /**
554 Return agent. 556 Return agent.
555 */ 557 */
556 Agent agent() const; 558 Agent agent() const;
557 /** 559 /**
558 Return translated label for agent field. 560 Return translated label for agent field.
559 */ 561 */
560 static QString agentLabel(); 562 static QString agentLabel();
561 563
562 /** 564 /**
563 Set name fields by parsing the given string and trying to associate the 565 Set name fields by parsing the given string and trying to associate the
564 parts of the string with according fields. This function should probably 566 parts of the string with according fields. This function should probably
565 be a bit more clever. 567 be a bit more clever.
566 */ 568 */
567 void setNameFromString( const QString & ); 569 void setNameFromString( const QString & );
568 570
569 /** 571 /**
570 Return the name of the addressee. This is calculated from all the name 572 Return the name of the addressee. This is calculated from all the name
571 fields. 573 fields.
572 */ 574 */
573 QString realName() const; 575 QString realName() const;
574 576
575 /** 577 /**
576 Return the name that consists of all name parts. 578 Return the name that consists of all name parts.
577 */ 579 */
578 QString assembledName() const; 580 QString assembledName() const;
579 581
580 /** 582 /**
581 Return email address including real name. 583 Return email address including real name.
582 584
583 @param email Email address to be used to construct the full email string. 585 @param email Email address to be used to construct the full email string.
584 If this is QString::null the preferred email address is used. 586 If this is QString::null the preferred email address is used.
585 */ 587 */
586 QString fullEmail( const QString &email=QString::null ) const; 588 QString fullEmail( const QString &email=QString::null ) const;
587 589
588 /** 590 /**
589 Insert an email address. If the email address already exists in this 591 Insert an email address. If the email address already exists in this
590 addressee it is not duplicated. 592 addressee it is not duplicated.
591 593
592 @param email Email address 594 @param email Email address
593 @param preferred Set to true, if this is the preferred email address of 595 @param preferred Set to true, if this is the preferred email address of
594 the addressee. 596 the addressee.
595 */ 597 */
596 void insertEmail( const QString &email, bool preferred=false ); 598 void insertEmail( const QString &email, bool preferred=false );
597 599
598 /** 600 /**
599 Remove email address. If the email address doesn't exist, nothing happens. 601 Remove email address. If the email address doesn't exist, nothing happens.
600 */ 602 */
601 void removeEmail( const QString &email ); 603 void removeEmail( const QString &email );
602 604
603 /** 605 /**
604 Return preferred email address. This is the first email address or the 606 Return preferred email address. This is the first email address or the
605 last one added with @ref insertEmail() with a set preferred parameter. 607 last one added with @ref insertEmail() with a set preferred parameter.
606 */ 608 */
607 QString preferredEmail() const; 609 QString preferredEmail() const;
608 610
609 /** 611 /**
610 Return list of all email addresses. 612 Return list of all email addresses.
611 */ 613 */
612 QStringList emails() const; 614 QStringList emails() const;
613 615
614 /** 616 /**
615 Set the emails to @param. 617 Set the emails to @param.
616 The first email address gets the preferred one! 618 The first email address gets the preferred one!
617 @param list The list of email addresses. 619 @param list The list of email addresses.
618 */ 620 */
619 void setEmails( const QStringList& list); 621 void setEmails( const QStringList& list);
620 622
621 /** 623 /**
622 Insert a phone number. If a phone number with the same id already exists 624 Insert a phone number. If a phone number with the same id already exists
623 in this addressee it is not duplicated. 625 in this addressee it is not duplicated.
624 */ 626 */
625 void insertPhoneNumber( const PhoneNumber &phoneNumber ); 627 void insertPhoneNumber( const PhoneNumber &phoneNumber );
626 628
627 /** 629 /**
628 Remove phone number. If no phone number with the given id exists for this 630 Remove phone number. If no phone number with the given id exists for this
629 addresse nothing happens. 631 addresse nothing happens.
630 */ 632 */
631 void removePhoneNumber( const PhoneNumber &phoneNumber ); 633 void removePhoneNumber( const PhoneNumber &phoneNumber );
632 634
633 /** 635 /**
634 Return phone number, which matches the given type. 636 Return phone number, which matches the given type.
635 */ 637 */
636 PhoneNumber phoneNumber( int type ) const; 638 PhoneNumber phoneNumber( int type ) const;
637 639
638 /** 640 /**
639 Return list of all phone numbers. 641 Return list of all phone numbers.
640 */ 642 */
641 PhoneNumber::List phoneNumbers() const; 643 PhoneNumber::List phoneNumbers() const;
642 644
643 /** 645 /**
644 Return list of phone numbers with a special type. 646 Return list of phone numbers with a special type.
645 */ 647 */
646 PhoneNumber::List phoneNumbers( int type ) const; 648 PhoneNumber::List phoneNumbers( int type ) const;
647 649
648 /** 650 /**
649 Return phone number with the given id. 651 Return phone number with the given id.
650 */ 652 */
651 PhoneNumber findPhoneNumber( const QString &id ) const; 653 PhoneNumber findPhoneNumber( const QString &id ) const;
652 654
653 /** 655 /**
654 Insert a key. If a key with the same id already exists 656 Insert a key. If a key with the same id already exists
655 in this addressee it is not duplicated. 657 in this addressee it is not duplicated.
656 */ 658 */
657 void insertKey( const Key &key ); 659 void insertKey( const Key &key );
658 660
659 /** 661 /**
660 Remove a key. If no key with the given id exists for this 662 Remove a key. If no key with the given id exists for this
661 addresse nothing happens. 663 addresse nothing happens.
662 */ 664 */
663 void removeKey( const Key &key ); 665 void removeKey( const Key &key );
664 666
665 /** 667 /**
666 Return key, which matches the given type. 668 Return key, which matches the given type.
667 If @p type == Key::Custom you can specify a string 669 If @p type == Key::Custom you can specify a string
668 that should match. If you leave the string empty, the first 670 that should match. If you leave the string empty, the first
669 key with a custom value is returned. 671 key with a custom value is returned.
670 */ 672 */
671 Key key( int type, QString customTypeString = QString::null ) const; 673 Key key( int type, QString customTypeString = QString::null ) const;
672 674
673 /** 675 /**
674 Return list of all keys. 676 Return list of all keys.
675 */ 677 */
676 Key::List keys() const; 678 Key::List keys() const;
677 679
678 /** 680 /**
679 Set the list of keys 681 Set the list of keys
680 @param keys The keys to be set. 682 @param keys The keys to be set.
681 */ 683 */
682 void setKeys( const Key::List& keys); 684 void setKeys( const Key::List& keys);
683 685
684 /** 686 /**
685 Return list of keys with a special type. 687 Return list of keys with a special type.
686 If @p type == Key::Custom you can specify a string 688 If @p type == Key::Custom you can specify a string
687 that should match. If you leave the string empty, all custom 689 that should match. If you leave the string empty, all custom
688 keys will be returned. 690 keys will be returned.
689 */ 691 */
690 Key::List keys( int type, QString customTypeString = QString::null ) const; 692 Key::List keys( int type, QString customTypeString = QString::null ) const;
691 693
692 /** 694 /**
693 Return key with the given id. 695 Return key with the given id.
694 */ 696 */
695 Key findKey( const QString &id ) const; 697 Key findKey( const QString &id ) const;
696 698
697 /** 699 /**
698 Insert an address. If an address with the same id already exists 700 Insert an address. If an address with the same id already exists
699 in this addressee it is not duplicated. 701 in this addressee it is not duplicated.
700 */ 702 */
701 void insertAddress( const Address &address ); 703 void insertAddress( const Address &address );
702 704
703 /** 705 /**
704 Remove address. If no address with the given id exists for this 706 Remove address. If no address with the given id exists for this
705 addresse nothing happens. 707 addresse nothing happens.
706 */ 708 */
707 void removeAddress( const Address &address ); 709 void removeAddress( const Address &address );
708 710
709 /** 711 /**
710 Return address, which matches the given type. 712 Return address, which matches the given type.
711 */ 713 */
712 Address address( int type ) const; 714 Address address( int type ) const;
713 715
714 /** 716 /**
715 Return list of all addresses. 717 Return list of all addresses.
716 */ 718 */
717 Address::List addresses() const; 719 Address::List addresses() const;
718 720
719 /** 721 /**
720 Return list of addresses with a special type. 722 Return list of addresses with a special type.
721 */ 723 */
722 Address::List addresses( int type ) const; 724 Address::List addresses( int type ) const;
723 725
724 /** 726 /**
725 Return address with the given id. 727 Return address with the given id.
726 */ 728 */
727 Address findAddress( const QString &id ) const; 729 Address findAddress( const QString &id ) const;
728 730
729 /** 731 /**
730 Insert category. If the category already exists it is not duplicated. 732 Insert category. If the category already exists it is not duplicated.
731 */ 733 */
732 void insertCategory( const QString & ); 734 void insertCategory( const QString & );
733 735
734 /** 736 /**
735 Remove category. 737 Remove category.
736 */ 738 */
737 void removeCategory( const QString & ); 739 void removeCategory( const QString & );
738 740
739 /** 741 /**
740 Return, if addressee has the given category. 742 Return, if addressee has the given category.
741 */ 743 */
742 bool hasCategory( const QString & ) const; 744 bool hasCategory( const QString & ) const;
743 745
744 /** 746 /**
745 Set categories to given value. 747 Set categories to given value.
746 */ 748 */
747 void setCategories( const QStringList & ); 749 void setCategories( const QStringList & );
748 750
749 /** 751 /**
750 Return list of all set categories. 752 Return list of all set categories.
751 */ 753 */
752 QStringList categories() const; 754 QStringList categories() const;
753 755
754 /** 756 /**
755 Insert custom entry. The entry is identified by the name of the inserting 757 Insert custom entry. The entry is identified by the name of the inserting
756 application and a unique name. If an entry with the given app and name 758 application and a unique name. If an entry with the given app and name
757 already exists its value is replaced with the new given value. 759 already exists its value is replaced with the new given value.
758 */ 760 */
759 void insertCustom( const QString &app, const QString &name, 761 void insertCustom( const QString &app, const QString &name,
760 const QString &value ); 762 const QString &value );
761 763
762 /** 764 /**
763 Remove custom entry. 765 Remove custom entry.
764 */ 766 */
765 void removeCustom( const QString &app, const QString &name ); 767 void removeCustom( const QString &app, const QString &name );
766 768
767 /** 769 /**
768 Return value of custom entry, identified by app and entry name. 770 Return value of custom entry, identified by app and entry name.
769 */ 771 */
770 QString custom( const QString &app, const QString &name ) const; 772 QString custom( const QString &app, const QString &name ) const;
771 773
772 /** 774 /**
773 Set all custom entries. 775 Set all custom entries.
774 */ 776 */
775 void setCustoms( const QStringList & ); 777 void setCustoms( const QStringList & );
776 778
777 /** 779 /**
778 Return list of all custom entries. 780 Return list of all custom entries.
779 */ 781 */
780 QStringList customs() const; 782 QStringList customs() const;
781 783
782 /** 784 /**
783 Parse full email address. The result is given back in fullName and email. 785 Parse full email address. The result is given back in fullName and email.
784 */ 786 */
785 static void parseEmailAddress( const QString &rawEmail, QString &fullName, 787 static void parseEmailAddress( const QString &rawEmail, QString &fullName,
786 QString &email ); 788 QString &email );
787 789
788 /** 790 /**
789 Debug output. 791 Debug output.
790 */ 792 */
791 void dump() const; 793 void dump() const;
792 794
793 /** 795 /**
794 Returns string representation of the addressee. 796 Returns string representation of the addressee.
795 */ 797 */
796 QString asString() const; 798 QString asString() const;
797 799
798 /** 800 /**
799 Set resource where the addressee is from. 801 Set resource where the addressee is from.
800 */ 802 */
801 void setResource( Resource *resource ); 803 void setResource( Resource *resource );
802 804
803 /** 805 /**
804 Return pointer to resource. 806 Return pointer to resource.
805 */ 807 */
806 Resource *resource() const; 808 Resource *resource() const;
807 809
808 /** 810 /**
809 Return resourcelabel. 811 Return resourcelabel.
810 */ 812 */
811 //US 813 //US
812 static QString resourceLabel(); 814 static QString resourceLabel();
813 815
814 /** 816 /**
815 Mark addressee as changed. 817 Mark addressee as changed.
816 */ 818 */
817 void setChanged( bool value ); 819 void setChanged( bool value );
818 820
819 /** 821 /**
820 Return whether the addressee is changed. 822 Return whether the addressee is changed.
821 */ 823 */
822 bool changed() const; 824 bool changed() const;
823 825
824 private: 826 private:
825 Addressee copy(); 827 Addressee copy();
826 void detach(); 828 void detach();
827 int mTempSyncStat; 829 int mTempSyncStat;
828 830
829 struct AddresseeData; 831 struct AddresseeData;
830 mutable KSharedPtr<AddresseeData> mData; 832 mutable KSharedPtr<AddresseeData> mData;
831}; 833};
832 834
833QDataStream &operator<<( QDataStream &, const Addressee & ); 835QDataStream &operator<<( QDataStream &, const Addressee & );
834QDataStream &operator>>( QDataStream &, Addressee & ); 836QDataStream &operator>>( QDataStream &, Addressee & );
835 837
836} 838}
837 839
838#endif 840#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index cc8eb52..8776b53 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,2993 +1,3021 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
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/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include "kabcore.h" 31#include "kabcore.h"
32 32
33#include <stdaddressbook.h> 33#include <stdaddressbook.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kfiledialog.h> 35#include <kfiledialog.h>
36#include <qprogressbar.h> 36#include <qprogressbar.h>
37 37
38#ifndef KAB_EMBEDDED 38#ifndef KAB_EMBEDDED
39#include <qclipboard.h> 39#include <qclipboard.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qfile.h> 41#include <qfile.h>
42#include <qapplicaton.h> 42#include <qapplicaton.h>
43#include <qprogressbar.h> 43#include <qprogressbar.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qvbox.h> 46#include <qvbox.h>
47#include <kabc/addresseelist.h> 47#include <kabc/addresseelist.h>
48#include <kabc/errorhandler.h> 48#include <kabc/errorhandler.h>
49#include <kabc/resource.h> 49#include <kabc/resource.h>
50#include <kabc/vcardconverter.h> 50#include <kabc/vcardconverter.h>
51#include <kapplication.h> 51#include <kapplication.h>
52#include <kactionclasses.h> 52#include <kactionclasses.h>
53#include <kcmultidialog.h> 53#include <kcmultidialog.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kdeversion.h> 55#include <kdeversion.h>
56#include <kkeydialog.h> 56#include <kkeydialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <kprinter.h> 58#include <kprinter.h>
59#include <kprotocolinfo.h> 59#include <kprotocolinfo.h>
60#include <kresources/selectdialog.h> 60#include <kresources/selectdialog.h>
61#include <kstandarddirs.h> 61#include <kstandarddirs.h>
62#include <ktempfile.h> 62#include <ktempfile.h>
63#include <kxmlguiclient.h> 63#include <kxmlguiclient.h>
64#include <kaboutdata.h> 64#include <kaboutdata.h>
65#include <libkdepim/categoryselectdialog.h> 65#include <libkdepim/categoryselectdialog.h>
66 66
67#include "addresseeutil.h" 67#include "addresseeutil.h"
68#include "addresseeeditordialog.h" 68#include "addresseeeditordialog.h"
69#include "extensionmanager.h" 69#include "extensionmanager.h"
70#include "kstdaction.h" 70#include "kstdaction.h"
71#include "kaddressbookservice.h" 71#include "kaddressbookservice.h"
72#include "ldapsearchdialog.h" 72#include "ldapsearchdialog.h"
73#include "printing/printingwizard.h" 73#include "printing/printingwizard.h"
74#else // KAB_EMBEDDED 74#else // KAB_EMBEDDED
75 75
76#include <kapplication.h> 76#include <kapplication.h>
77#include "KDGanttMinimizeSplitter.h" 77#include "KDGanttMinimizeSplitter.h"
78#include "kaddressbookmain.h" 78#include "kaddressbookmain.h"
79#include "kactioncollection.h" 79#include "kactioncollection.h"
80#include "addresseedialog.h" 80#include "addresseedialog.h"
81//US 81//US
82#include <addresseeview.h> 82#include <addresseeview.h>
83 83
84#include <qapp.h> 84#include <qapp.h>
85#include <qmenubar.h> 85#include <qmenubar.h>
86//#include <qtoolbar.h> 86//#include <qtoolbar.h>
87#include <qmessagebox.h> 87#include <qmessagebox.h>
88#include <kdebug.h> 88#include <kdebug.h>
89#include <kiconloader.h> // needed for SmallIcon 89#include <kiconloader.h> // needed for SmallIcon
90#include <kresources/kcmkresources.h> 90#include <kresources/kcmkresources.h>
91#include <ktoolbar.h> 91#include <ktoolbar.h>
92 92
93 93
94//#include <qlabel.h> 94//#include <qlabel.h>
95 95
96 96
97#ifndef DESKTOP_VERSION 97#ifndef DESKTOP_VERSION
98#include <qpe/ir.h> 98#include <qpe/ir.h>
99#include <qpe/qpemenubar.h> 99#include <qpe/qpemenubar.h>
100#include <qtopia/qcopenvelope_qws.h> 100#include <qtopia/qcopenvelope_qws.h>
101#else 101#else
102 102
103#include <qmenubar.h> 103#include <qmenubar.h>
104#endif 104#endif
105 105
106#endif // KAB_EMBEDDED 106#endif // KAB_EMBEDDED
107#include "kcmconfigs/kcmkabconfig.h" 107#include "kcmconfigs/kcmkabconfig.h"
108#include "kcmconfigs/kcmkdepimconfig.h" 108#include "kcmconfigs/kcmkdepimconfig.h"
109#include "kpimglobalprefs.h" 109#include "kpimglobalprefs.h"
110#include "externalapphandler.h" 110#include "externalapphandler.h"
111 111
112 112
113#include <kresources/selectdialog.h> 113#include <kresources/selectdialog.h>
114#include <kmessagebox.h> 114#include <kmessagebox.h>
115 115
116#include <picture.h> 116#include <picture.h>
117#include <resource.h> 117#include <resource.h>
118 118
119//US#include <qsplitter.h> 119//US#include <qsplitter.h>
120#include <qmap.h> 120#include <qmap.h>
121#include <qdir.h> 121#include <qdir.h>
122#include <qfile.h> 122#include <qfile.h>
123#include <qvbox.h> 123#include <qvbox.h>
124#include <qlayout.h> 124#include <qlayout.h>
125#include <qclipboard.h> 125#include <qclipboard.h>
126#include <qtextstream.h> 126#include <qtextstream.h>
127 127
128#include <libkdepim/categoryselectdialog.h> 128#include <libkdepim/categoryselectdialog.h>
129#include <kabc/vcardconverter.h> 129#include <kabc/vcardconverter.h>
130 130
131 131
132#include "addresseeutil.h" 132#include "addresseeutil.h"
133#include "undocmds.h" 133#include "undocmds.h"
134#include "addresseeeditordialog.h" 134#include "addresseeeditordialog.h"
135#include "viewmanager.h" 135#include "viewmanager.h"
136#include "details/detailsviewcontainer.h" 136#include "details/detailsviewcontainer.h"
137#include "kabprefs.h" 137#include "kabprefs.h"
138#include "xxportmanager.h" 138#include "xxportmanager.h"
139#include "incsearchwidget.h" 139#include "incsearchwidget.h"
140#include "jumpbuttonbar.h" 140#include "jumpbuttonbar.h"
141#include "extensionmanager.h" 141#include "extensionmanager.h"
142#include "addresseeconfig.h" 142#include "addresseeconfig.h"
143#include <kcmultidialog.h> 143#include <kcmultidialog.h>
144 144
145#ifdef _WIN32_ 145#ifdef _WIN32_
146 146
147#include "kaimportoldialog.h" 147#include "kaimportoldialog.h"
148#else 148#else
149#include <unistd.h> 149#include <unistd.h>
150#endif 150#endif
151// sync includes 151// sync includes
152#include <libkdepim/ksyncprofile.h> 152#include <libkdepim/ksyncprofile.h>
153#include <libkdepim/ksyncprefsdialog.h> 153#include <libkdepim/ksyncprefsdialog.h>
154 154
155 155
156bool pasteWithNewUid = true; 156bool pasteWithNewUid = true;
157 157
158#ifdef KAB_EMBEDDED 158#ifdef KAB_EMBEDDED
159KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 159KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
160 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 160 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
161 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 161 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
162 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 162 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
163#else //KAB_EMBEDDED 163#else //KAB_EMBEDDED
164KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 164KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
165 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 165 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
166 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 166 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
167 mReadWrite( readWrite ), mModified( false ) 167 mReadWrite( readWrite ), mModified( false )
168#endif //KAB_EMBEDDED 168#endif //KAB_EMBEDDED
169{ 169{
170 170
171 mBlockSaveFlag = false; 171 mBlockSaveFlag = false;
172 mExtensionBarSplitter = 0; 172 mExtensionBarSplitter = 0;
173 mIsPart = !parent->inherits( "KAddressBookMain" ); 173 mIsPart = !parent->inherits( "KAddressBookMain" );
174 174
175 mAddressBook = KABC::StdAddressBook::self(); 175 mAddressBook = KABC::StdAddressBook::self();
176 KABC::StdAddressBook::setAutomaticSave( false ); 176 KABC::StdAddressBook::setAutomaticSave( false );
177 177
178#ifndef KAB_EMBEDDED 178#ifndef KAB_EMBEDDED
179 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 179 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
180#endif //KAB_EMBEDDED 180#endif //KAB_EMBEDDED
181 181
182 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 182 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
183 SLOT( addressBookChanged() ) ); 183 SLOT( addressBookChanged() ) );
184 184
185#if 0 185#if 0
186 // LP moved to addressbook init method 186 // LP moved to addressbook init method
187 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 187 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
188 "X-Department", "KADDRESSBOOK" ); 188 "X-Department", "KADDRESSBOOK" );
189 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 189 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
190 "X-Profession", "KADDRESSBOOK" ); 190 "X-Profession", "KADDRESSBOOK" );
191 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 191 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
192 "X-AssistantsName", "KADDRESSBOOK" ); 192 "X-AssistantsName", "KADDRESSBOOK" );
193 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 193 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
194 "X-ManagersName", "KADDRESSBOOK" ); 194 "X-ManagersName", "KADDRESSBOOK" );
195 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 195 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
196 "X-SpousesName", "KADDRESSBOOK" ); 196 "X-SpousesName", "KADDRESSBOOK" );
197 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 197 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
198 "X-Office", "KADDRESSBOOK" ); 198 "X-Office", "KADDRESSBOOK" );
199 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 199 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
200 "X-IMAddress", "KADDRESSBOOK" ); 200 "X-IMAddress", "KADDRESSBOOK" );
201 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 201 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
202 "X-Anniversary", "KADDRESSBOOK" ); 202 "X-Anniversary", "KADDRESSBOOK" );
203 203
204 //US added this field to become compatible with Opie/qtopia addressbook 204 //US added this field to become compatible with Opie/qtopia addressbook
205 // values can be "female" or "male" or "". An empty field represents undefined. 205 // values can be "female" or "male" or "". An empty field represents undefined.
206 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 206 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
207 "X-Gender", "KADDRESSBOOK" ); 207 "X-Gender", "KADDRESSBOOK" );
208 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 208 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
209 "X-Children", "KADDRESSBOOK" ); 209 "X-Children", "KADDRESSBOOK" );
210 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 210 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
211 "X-FreeBusyUrl", "KADDRESSBOOK" ); 211 "X-FreeBusyUrl", "KADDRESSBOOK" );
212#endif 212#endif
213 initGUI(); 213 initGUI();
214 214
215 mIncSearchWidget->setFocus(); 215 mIncSearchWidget->setFocus();
216 216
217 217
218 connect( mViewManager, SIGNAL( selected( const QString& ) ), 218 connect( mViewManager, SIGNAL( selected( const QString& ) ),
219 SLOT( setContactSelected( const QString& ) ) ); 219 SLOT( setContactSelected( const QString& ) ) );
220 connect( mViewManager, SIGNAL( executed( const QString& ) ), 220 connect( mViewManager, SIGNAL( executed( const QString& ) ),
221 SLOT( executeContact( const QString& ) ) ); 221 SLOT( executeContact( const QString& ) ) );
222 222
223 connect( mViewManager, SIGNAL( deleteRequest( ) ), 223 connect( mViewManager, SIGNAL( deleteRequest( ) ),
224 SLOT( deleteContacts( ) ) ); 224 SLOT( deleteContacts( ) ) );
225 connect( mViewManager, SIGNAL( modified() ), 225 connect( mViewManager, SIGNAL( modified() ),
226 SLOT( setModified() ) ); 226 SLOT( setModified() ) );
227 227
228 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 228 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
229 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 229 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
230 230
231 connect( mXXPortManager, SIGNAL( modified() ), 231 connect( mXXPortManager, SIGNAL( modified() ),
232 SLOT( setModified() ) ); 232 SLOT( setModified() ) );
233 233
234 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 234 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
235 SLOT( incrementalSearch( const QString& ) ) ); 235 SLOT( incrementalSearch( const QString& ) ) );
236 connect( mIncSearchWidget, SIGNAL( fieldChanged() ), 236 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
237 mJumpButtonBar, SLOT( recreateButtons() ) ); 237 mJumpButtonBar, SLOT( recreateButtons() ) );
238 238
239 connect( mDetails, SIGNAL( sendEmail( const QString& ) ), 239 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
240 SLOT( sendMail( const QString& ) ) ); 240 SLOT( sendMail( const QString& ) ) );
241 241
242 242
243 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 243 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
244 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); 244 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)));
245 245
246 246
247#ifndef KAB_EMBEDDED 247#ifndef KAB_EMBEDDED
248 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 248 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
249 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 249 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
250 250
251 connect( mDetails, SIGNAL( browse( const QString& ) ), 251 connect( mDetails, SIGNAL( browse( const QString& ) ),
252 SLOT( browse( const QString& ) ) ); 252 SLOT( browse( const QString& ) ) );
253 253
254 254
255 mAddressBookService = new KAddressBookService( this ); 255 mAddressBookService = new KAddressBookService( this );
256 256
257#endif //KAB_EMBEDDED 257#endif //KAB_EMBEDDED
258 mEditorDialog = 0; 258 mEditorDialog = 0;
259 createAddresseeEditorDialog( this ); 259 createAddresseeEditorDialog( this );
260 setModified( false ); 260 setModified( false );
261} 261}
262 262
263KABCore::~KABCore() 263KABCore::~KABCore()
264{ 264{
265 // save(); 265 // save();
266 //saveSettings(); 266 //saveSettings();
267 //KABPrefs::instance()->writeConfig(); 267 //KABPrefs::instance()->writeConfig();
268 delete AddresseeConfig::instance(); 268 delete AddresseeConfig::instance();
269 mAddressBook = 0; 269 mAddressBook = 0;
270 KABC::StdAddressBook::close(); 270 KABC::StdAddressBook::close();
271} 271}
272 272
273void KABCore::restoreSettings() 273void KABCore::restoreSettings()
274{ 274{
275 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 275 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
276 276
277 bool state; 277 bool state;
278 278
279 if (mMultipleViewsAtOnce) 279 if (mMultipleViewsAtOnce)
280 state = KABPrefs::instance()->mDetailsPageVisible; 280 state = KABPrefs::instance()->mDetailsPageVisible;
281 else 281 else
282 state = false; 282 state = false;
283 283
284 mActionDetails->setChecked( state ); 284 mActionDetails->setChecked( state );
285 setDetailsVisible( state ); 285 setDetailsVisible( state );
286 286
287 state = KABPrefs::instance()->mJumpButtonBarVisible; 287 state = KABPrefs::instance()->mJumpButtonBarVisible;
288 288
289 mActionJumpBar->setChecked( state ); 289 mActionJumpBar->setChecked( state );
290 setJumpButtonBarVisible( state ); 290 setJumpButtonBarVisible( state );
291/*US 291/*US
292 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 292 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
293 if ( splitterSize.count() == 0 ) { 293 if ( splitterSize.count() == 0 ) {
294 splitterSize.append( width() / 2 ); 294 splitterSize.append( width() / 2 );
295 splitterSize.append( width() / 2 ); 295 splitterSize.append( width() / 2 );
296 } 296 }
297 mMiniSplitter->setSizes( splitterSize ); 297 mMiniSplitter->setSizes( splitterSize );
298 if ( mExtensionBarSplitter ) { 298 if ( mExtensionBarSplitter ) {
299 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 299 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
300 if ( splitterSize.count() == 0 ) { 300 if ( splitterSize.count() == 0 ) {
301 splitterSize.append( width() / 2 ); 301 splitterSize.append( width() / 2 );
302 splitterSize.append( width() / 2 ); 302 splitterSize.append( width() / 2 );
303 } 303 }
304 mExtensionBarSplitter->setSizes( splitterSize ); 304 mExtensionBarSplitter->setSizes( splitterSize );
305 305
306 } 306 }
307*/ 307*/
308 mViewManager->restoreSettings(); 308 mViewManager->restoreSettings();
309 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 309 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
310 mExtensionManager->restoreSettings(); 310 mExtensionManager->restoreSettings();
311#ifdef DESKTOP_VERSION 311#ifdef DESKTOP_VERSION
312 int wid = width(); 312 int wid = width();
313 if ( wid < 10 ) 313 if ( wid < 10 )
314 wid = 400; 314 wid = 400;
315#else 315#else
316 int wid = QApplication::desktop()->width(); 316 int wid = QApplication::desktop()->width();
317 if ( wid < 640 ) 317 if ( wid < 640 )
318 wid = QApplication::desktop()->height(); 318 wid = QApplication::desktop()->height();
319#endif 319#endif
320 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 320 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
321 if ( true /*splitterSize.count() == 0*/ ) { 321 if ( true /*splitterSize.count() == 0*/ ) {
322 splitterSize.append( wid / 2 ); 322 splitterSize.append( wid / 2 );
323 splitterSize.append( wid / 2 ); 323 splitterSize.append( wid / 2 );
324 } 324 }
325 mMiniSplitter->setSizes( splitterSize ); 325 mMiniSplitter->setSizes( splitterSize );
326 if ( mExtensionBarSplitter ) { 326 if ( mExtensionBarSplitter ) {
327 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 327 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
328 if ( true /*splitterSize.count() == 0*/ ) { 328 if ( true /*splitterSize.count() == 0*/ ) {
329 splitterSize.append( wid / 2 ); 329 splitterSize.append( wid / 2 );
330 splitterSize.append( wid / 2 ); 330 splitterSize.append( wid / 2 );
331 } 331 }
332 mExtensionBarSplitter->setSizes( splitterSize ); 332 mExtensionBarSplitter->setSizes( splitterSize );
333 333
334 } 334 }
335 335
336 336
337} 337}
338 338
339void KABCore::saveSettings() 339void KABCore::saveSettings()
340{ 340{
341 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 341 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
342 if ( mExtensionBarSplitter ) 342 if ( mExtensionBarSplitter )
343 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 343 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
344 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 344 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
345 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 345 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
346#ifndef KAB_EMBEDDED 346#ifndef KAB_EMBEDDED
347 347
348 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 348 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
349 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 349 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
350#endif //KAB_EMBEDDED 350#endif //KAB_EMBEDDED
351 mExtensionManager->saveSettings(); 351 mExtensionManager->saveSettings();
352 mViewManager->saveSettings(); 352 mViewManager->saveSettings();
353 353
354 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 354 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
355} 355}
356 356
357KABC::AddressBook *KABCore::addressBook() const 357KABC::AddressBook *KABCore::addressBook() const
358{ 358{
359 return mAddressBook; 359 return mAddressBook;
360} 360}
361 361
362KConfig *KABCore::config() 362KConfig *KABCore::config()
363{ 363{
364#ifndef KAB_EMBEDDED 364#ifndef KAB_EMBEDDED
365 return KABPrefs::instance()->config(); 365 return KABPrefs::instance()->config();
366#else //KAB_EMBEDDED 366#else //KAB_EMBEDDED
367 return KABPrefs::instance()->getConfig(); 367 return KABPrefs::instance()->getConfig();
368#endif //KAB_EMBEDDED 368#endif //KAB_EMBEDDED
369} 369}
370 370
371KActionCollection *KABCore::actionCollection() const 371KActionCollection *KABCore::actionCollection() const
372{ 372{
373 return mGUIClient->actionCollection(); 373 return mGUIClient->actionCollection();
374} 374}
375 375
376KABC::Field *KABCore::currentSearchField() const 376KABC::Field *KABCore::currentSearchField() const
377{ 377{
378 if (mIncSearchWidget) 378 if (mIncSearchWidget)
379 return mIncSearchWidget->currentField(); 379 return mIncSearchWidget->currentField();
380 else 380 else
381 return 0; 381 return 0;
382} 382}
383 383
384QStringList KABCore::selectedUIDs() const 384QStringList KABCore::selectedUIDs() const
385{ 385{
386 return mViewManager->selectedUids(); 386 return mViewManager->selectedUids();
387} 387}
388 388
389KABC::Resource *KABCore::requestResource( QWidget *parent ) 389KABC::Resource *KABCore::requestResource( QWidget *parent )
390{ 390{
391 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 391 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
392 392
393 QPtrList<KRES::Resource> kresResources; 393 QPtrList<KRES::Resource> kresResources;
394 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 394 QPtrListIterator<KABC::Resource> resIt( kabcResources );
395 KABC::Resource *resource; 395 KABC::Resource *resource;
396 while ( ( resource = resIt.current() ) != 0 ) { 396 while ( ( resource = resIt.current() ) != 0 ) {
397 ++resIt; 397 ++resIt;
398 if ( !resource->readOnly() ) { 398 if ( !resource->readOnly() ) {
399 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 399 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
400 if ( res ) 400 if ( res )
401 kresResources.append( res ); 401 kresResources.append( res );
402 } 402 }
403 } 403 }
404 404
405 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 405 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
406 return static_cast<KABC::Resource*>( res ); 406 return static_cast<KABC::Resource*>( res );
407} 407}
408 408
409#ifndef KAB_EMBEDDED 409#ifndef KAB_EMBEDDED
410KAboutData *KABCore::createAboutData() 410KAboutData *KABCore::createAboutData()
411#else //KAB_EMBEDDED 411#else //KAB_EMBEDDED
412void KABCore::createAboutData() 412void KABCore::createAboutData()
413#endif //KAB_EMBEDDED 413#endif //KAB_EMBEDDED
414{ 414{
415#ifndef KAB_EMBEDDED 415#ifndef KAB_EMBEDDED
416 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 416 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
417 "3.1", I18N_NOOP( "The KDE Address Book" ), 417 "3.1", I18N_NOOP( "The KDE Address Book" ),
418 KAboutData::License_GPL_V2, 418 KAboutData::License_GPL_V2,
419 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 419 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
420 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 420 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
421 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 421 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
422 about->addAuthor( "Cornelius Schumacher", 422 about->addAuthor( "Cornelius Schumacher",
423 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 423 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
424 "schumacher@kde.org" ); 424 "schumacher@kde.org" );
425 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 425 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
426 "mpilone@slac.com" ); 426 "mpilone@slac.com" );
427 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 427 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
428 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 428 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
429 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 429 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
430 "michel@klaralvdalens-datakonsult.se" ); 430 "michel@klaralvdalens-datakonsult.se" );
431 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 431 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
432 "hansen@kde.org" ); 432 "hansen@kde.org" );
433 433
434 return about; 434 return about;
435#endif //KAB_EMBEDDED 435#endif //KAB_EMBEDDED
436 436
437 QString version; 437 QString version;
438#include <../version> 438#include <../version>
439 QMessageBox::about( this, "About KAddressbook/Pi", 439 QMessageBox::about( this, "About KAddressbook/Pi",
440 "KAddressbook/Platform-independent\n" 440 "KAddressbook/Platform-independent\n"
441 "(KA/Pi) " +version + " - " + 441 "(KA/Pi) " +version + " - " +
442#ifdef DESKTOP_VERSION 442#ifdef DESKTOP_VERSION
443 "Desktop Edition\n" 443 "Desktop Edition\n"
444#else 444#else
445 "PDA-Edition\n" 445 "PDA-Edition\n"
446 "for: Zaurus 5500 / 7x0 / 8x0\n" 446 "for: Zaurus 5500 / 7x0 / 8x0\n"
447#endif 447#endif
448 448
449 "(c) 2004 Ulf Schenk\n" 449 "(c) 2004 Ulf Schenk\n"
450 "(c) 2004 Lutz Rogowski\n" 450 "(c) 2004 Lutz Rogowski\n"
451 "(c) 1997-2003, The KDE PIM Team\n" 451 "(c) 1997-2003, The KDE PIM Team\n"
452 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 452 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
453 "Don Sanders Original author\n" 453 "Don Sanders Original author\n"
454 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 454 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
455 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 455 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
456 "Greg Stern DCOP interface\n" 456 "Greg Stern DCOP interface\n"
457 "Mark Westcot Contact pinning\n" 457 "Mark Westcot Contact pinning\n"
458 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 458 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
459 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 459 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
460#ifdef _WIN32_ 460#ifdef _WIN32_
461 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 461 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
462#endif 462#endif
463 ); 463 );
464} 464}
465 465
466void KABCore::setContactSelected( const QString &uid ) 466void KABCore::setContactSelected( const QString &uid )
467{ 467{
468 KABC::Addressee addr = mAddressBook->findByUid( uid ); 468 KABC::Addressee addr = mAddressBook->findByUid( uid );
469 if ( !mDetails->isHidden() ) 469 if ( !mDetails->isHidden() )
470 mDetails->setAddressee( addr ); 470 mDetails->setAddressee( addr );
471 471
472 if ( !addr.isEmpty() ) { 472 if ( !addr.isEmpty() ) {
473 emit contactSelected( addr.formattedName() ); 473 emit contactSelected( addr.formattedName() );
474 KABC::Picture pic = addr.photo(); 474 KABC::Picture pic = addr.photo();
475 if ( pic.isIntern() ) { 475 if ( pic.isIntern() ) {
476//US emit contactSelected( pic.data() ); 476//US emit contactSelected( pic.data() );
477//US instead use: 477//US instead use:
478 QPixmap px; 478 QPixmap px;
479 if (pic.data().isNull() != true) 479 if (pic.data().isNull() != true)
480 { 480 {
481 px.convertFromImage(pic.data()); 481 px.convertFromImage(pic.data());
482 } 482 }
483 483
484 emit contactSelected( px ); 484 emit contactSelected( px );
485 } 485 }
486 } 486 }
487 487
488 488
489 mExtensionManager->setSelectionChanged(); 489 mExtensionManager->setSelectionChanged();
490 490
491 // update the actions 491 // update the actions
492 bool selected = !uid.isEmpty(); 492 bool selected = !uid.isEmpty();
493 493
494 if ( mReadWrite ) { 494 if ( mReadWrite ) {
495 mActionCut->setEnabled( selected ); 495 mActionCut->setEnabled( selected );
496 mActionPaste->setEnabled( selected ); 496 mActionPaste->setEnabled( selected );
497 } 497 }
498 498
499 mActionCopy->setEnabled( selected ); 499 mActionCopy->setEnabled( selected );
500 mActionDelete->setEnabled( selected ); 500 mActionDelete->setEnabled( selected );
501 mActionEditAddressee->setEnabled( selected ); 501 mActionEditAddressee->setEnabled( selected );
502 mActionMail->setEnabled( selected ); 502 mActionMail->setEnabled( selected );
503 mActionMailVCard->setEnabled( selected ); 503 mActionMailVCard->setEnabled( selected );
504 //if (mActionBeam) 504 //if (mActionBeam)
505 //mActionBeam->setEnabled( selected ); 505 //mActionBeam->setEnabled( selected );
506 506
507 if (mActionBeamVCard) 507 if (mActionBeamVCard)
508 mActionBeamVCard->setEnabled( selected ); 508 mActionBeamVCard->setEnabled( selected );
509 509
510 mActionWhoAmI->setEnabled( selected ); 510 mActionWhoAmI->setEnabled( selected );
511 mActionCategories->setEnabled( selected ); 511 mActionCategories->setEnabled( selected );
512} 512}
513 513
514void KABCore::sendMail() 514void KABCore::sendMail()
515{ 515{
516 sendMail( mViewManager->selectedEmails().join( ", " ) ); 516 sendMail( mViewManager->selectedEmails().join( ", " ) );
517} 517}
518 518
519void KABCore::sendMail( const QString& emaillist ) 519void KABCore::sendMail( const QString& emaillist )
520{ 520{
521 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 521 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
522 if (emaillist.contains(",") > 0) 522 if (emaillist.contains(",") > 0)
523 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 523 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
524 else 524 else
525 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 525 ExternalAppHandler::instance()->mailToOneContact( emaillist );
526} 526}
527 527
528 528
529 529
530void KABCore::mailVCard() 530void KABCore::mailVCard()
531{ 531{
532 QStringList uids = mViewManager->selectedUids(); 532 QStringList uids = mViewManager->selectedUids();
533 if ( !uids.isEmpty() ) 533 if ( !uids.isEmpty() )
534 mailVCard( uids ); 534 mailVCard( uids );
535} 535}
536 536
537void KABCore::mailVCard( const QStringList& uids ) 537void KABCore::mailVCard( const QStringList& uids )
538{ 538{
539 QStringList urls; 539 QStringList urls;
540 540
541// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 541// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
542 542
543 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 543 QString dirName = "/tmp/" + KApplication::randomString( 8 );
544 544
545 545
546 546
547 QDir().mkdir( dirName, true ); 547 QDir().mkdir( dirName, true );
548 548
549 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 549 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
550 KABC::Addressee a = mAddressBook->findByUid( *it ); 550 KABC::Addressee a = mAddressBook->findByUid( *it );
551 551
552 if ( a.isEmpty() ) 552 if ( a.isEmpty() )
553 continue; 553 continue;
554 554
555 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 555 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
556 556
557 QString fileName = dirName + "/" + name; 557 QString fileName = dirName + "/" + name;
558 558
559 QFile outFile(fileName); 559 QFile outFile(fileName);
560 560
561 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 561 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
562 KABC::VCardConverter converter; 562 KABC::VCardConverter converter;
563 QString vcard; 563 QString vcard;
564 564
565 converter.addresseeToVCard( a, vcard ); 565 converter.addresseeToVCard( a, vcard );
566 566
567 QTextStream t( &outFile ); // use a text stream 567 QTextStream t( &outFile ); // use a text stream
568 t.setEncoding( QTextStream::UnicodeUTF8 ); 568 t.setEncoding( QTextStream::UnicodeUTF8 );
569 t << vcard; 569 t << vcard;
570 570
571 outFile.close(); 571 outFile.close();
572 572
573 urls.append( fileName ); 573 urls.append( fileName );
574 } 574 }
575 } 575 }
576 576
577 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 577 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
578 578
579 579
580/*US 580/*US
581 kapp->invokeMailer( QString::null, QString::null, QString::null, 581 kapp->invokeMailer( QString::null, QString::null, QString::null,
582 QString::null, // subject 582 QString::null, // subject
583 QString::null, // body 583 QString::null, // body
584 QString::null, 584 QString::null,
585 urls ); // attachments 585 urls ); // attachments
586*/ 586*/
587 587
588} 588}
589 589
590/** 590/**
591 Beams the "WhoAmI contact. 591 Beams the "WhoAmI contact.
592*/ 592*/
593void KABCore::beamMySelf() 593void KABCore::beamMySelf()
594{ 594{
595 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 595 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
596 if (!a.isEmpty()) 596 if (!a.isEmpty())
597 { 597 {
598 QStringList uids; 598 QStringList uids;
599 uids << a.uid(); 599 uids << a.uid();
600 600
601 beamVCard(uids); 601 beamVCard(uids);
602 } else { 602 } else {
603 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 603 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
604 604
605 605
606 } 606 }
607} 607}
608 608
609void KABCore::beamVCard() 609void KABCore::beamVCard()
610{ 610{
611 QStringList uids = mViewManager->selectedUids(); 611 QStringList uids = mViewManager->selectedUids();
612 if ( !uids.isEmpty() ) 612 if ( !uids.isEmpty() )
613 beamVCard( uids ); 613 beamVCard( uids );
614} 614}
615 615
616 616
617void KABCore::beamVCard(const QStringList& uids) 617void KABCore::beamVCard(const QStringList& uids)
618{ 618{
619/*US 619/*US
620 QString beamFilename; 620 QString beamFilename;
621 Opie::OPimContact c; 621 Opie::OPimContact c;
622 if ( actionPersonal->isOn() ) { 622 if ( actionPersonal->isOn() ) {
623 beamFilename = addressbookPersonalVCardName(); 623 beamFilename = addressbookPersonalVCardName();
624 if ( !QFile::exists( beamFilename ) ) 624 if ( !QFile::exists( beamFilename ) )
625 return; // can't beam a non-existent file 625 return; // can't beam a non-existent file
626 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 626 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
627 beamFilename ); 627 beamFilename );
628 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 628 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
629 Opie::OPimContactAccess::List allList = access->allRecords(); 629 Opie::OPimContactAccess::List allList = access->allRecords();
630 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 630 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
631 c = *it; 631 c = *it;
632 632
633 delete access; 633 delete access;
634 } else { 634 } else {
635 unlink( beamfile ); // delete if exists 635 unlink( beamfile ); // delete if exists
636 mkdir("/tmp/obex/", 0755); 636 mkdir("/tmp/obex/", 0755);
637 c = m_abView -> currentEntry(); 637 c = m_abView -> currentEntry();
638 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 638 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
639 beamfile ); 639 beamfile );
640 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 640 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
641 access->add( c ); 641 access->add( c );
642 access->save(); 642 access->save();
643 delete access; 643 delete access;
644 644
645 beamFilename = beamfile; 645 beamFilename = beamfile;
646 } 646 }
647 647
648 owarn << "Beaming: " << beamFilename << oendl; 648 owarn << "Beaming: " << beamFilename << oendl;
649*/ 649*/
650 650
651#if 0 651#if 0
652 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 652 QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
653 653
654 QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); 654 QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
655 655
656 QString name = "contact.vcf"; 656 QString name = "contact.vcf";
657 657
658 QString fileName = dirName + "/" + name; 658 QString fileName = dirName + "/" + name;
659#endif 659#endif
660 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory 660 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
661 // 661 //
662 QString fileName = "/tmp/kapibeamfile.vcf"; 662 QString fileName = "/tmp/kapibeamfile.vcf";
663 663
664 664
665 //QDir().mkdir( dirName, true ); 665 //QDir().mkdir( dirName, true );
666 666
667 667
668 KABC::VCardConverter converter; 668 KABC::VCardConverter converter;
669 QString description; 669 QString description;
670 QString datastream; 670 QString datastream;
671 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 671 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
672 KABC::Addressee a = mAddressBook->findByUid( *it ); 672 KABC::Addressee a = mAddressBook->findByUid( *it );
673 673
674 if ( a.isEmpty() ) 674 if ( a.isEmpty() )
675 continue; 675 continue;
676 676
677 if (description.isEmpty()) 677 if (description.isEmpty())
678 description = a.formattedName(); 678 description = a.formattedName();
679 679
680 QString vcard; 680 QString vcard;
681 converter.addresseeToVCard( a, vcard ); 681 converter.addresseeToVCard( a, vcard );
682 int start = 0; 682 int start = 0;
683 int next; 683 int next;
684 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 684 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
685 int semi = vcard.find(";", next); 685 int semi = vcard.find(";", next);
686 int dopp = vcard.find(":", next); 686 int dopp = vcard.find(":", next);
687 int sep; 687 int sep;
688 if ( semi < dopp && semi >= 0 ) 688 if ( semi < dopp && semi >= 0 )
689 sep = semi ; 689 sep = semi ;
690 else 690 else
691 sep = dopp; 691 sep = dopp;
692 datastream +=vcard.mid( start, next - start); 692 datastream +=vcard.mid( start, next - start);
693 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 693 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
694 start = sep; 694 start = sep;
695 } 695 }
696 datastream += vcard.mid( start,vcard.length() ); 696 datastream += vcard.mid( start,vcard.length() );
697 } 697 }
698#ifndef DESKTOP_VERSION 698#ifndef DESKTOP_VERSION
699 QFile outFile(fileName); 699 QFile outFile(fileName);
700 if ( outFile.open(IO_WriteOnly) ) { 700 if ( outFile.open(IO_WriteOnly) ) {
701 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 701 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
702 QTextStream t( &outFile ); // use a text stream 702 QTextStream t( &outFile ); // use a text stream
703 t.setEncoding( QTextStream::UnicodeUTF8 ); 703 t.setEncoding( QTextStream::UnicodeUTF8 );
704 t <<datastream; 704 t <<datastream;
705 outFile.close(); 705 outFile.close();
706 Ir *ir = new Ir( this ); 706 Ir *ir = new Ir( this );
707 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 707 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
708 ir->send( fileName, description, "text/x-vCard" ); 708 ir->send( fileName, description, "text/x-vCard" );
709 } else { 709 } else {
710 qDebug("Error open temp beam file "); 710 qDebug("Error open temp beam file ");
711 return; 711 return;
712 } 712 }
713#endif 713#endif
714 714
715} 715}
716 716
717void KABCore::beamDone( Ir *ir ) 717void KABCore::beamDone( Ir *ir )
718{ 718{
719#ifndef DESKTOP_VERSION 719#ifndef DESKTOP_VERSION
720 delete ir; 720 delete ir;
721#endif 721#endif
722} 722}
723 723
724 724
725void KABCore::browse( const QString& url ) 725void KABCore::browse( const QString& url )
726{ 726{
727#ifndef KAB_EMBEDDED 727#ifndef KAB_EMBEDDED
728 kapp->invokeBrowser( url ); 728 kapp->invokeBrowser( url );
729#else //KAB_EMBEDDED 729#else //KAB_EMBEDDED
730 qDebug("KABCore::browse must be fixed"); 730 qDebug("KABCore::browse must be fixed");
731#endif //KAB_EMBEDDED 731#endif //KAB_EMBEDDED
732} 732}
733 733
734void KABCore::selectAllContacts() 734void KABCore::selectAllContacts()
735{ 735{
736 mViewManager->setSelected( QString::null, true ); 736 mViewManager->setSelected( QString::null, true );
737} 737}
738 738
739void KABCore::deleteContacts() 739void KABCore::deleteContacts()
740{ 740{
741 QStringList uidList = mViewManager->selectedUids(); 741 QStringList uidList = mViewManager->selectedUids();
742 deleteContacts( uidList ); 742 deleteContacts( uidList );
743} 743}
744 744
745void KABCore::deleteContacts( const QStringList &uids ) 745void KABCore::deleteContacts( const QStringList &uids )
746{ 746{
747 if ( uids.count() > 0 ) { 747 if ( uids.count() > 0 ) {
748 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 748 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
749 UndoStack::instance()->push( command ); 749 UndoStack::instance()->push( command );
750 RedoStack::instance()->clear(); 750 RedoStack::instance()->clear();
751 751
752 // now if we deleted anything, refresh 752 // now if we deleted anything, refresh
753 setContactSelected( QString::null ); 753 setContactSelected( QString::null );
754 setModified( true ); 754 setModified( true );
755 } 755 }
756} 756}
757 757
758void KABCore::copyContacts() 758void KABCore::copyContacts()
759{ 759{
760 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 760 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
761 761
762 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 762 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
763 763
764 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 764 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
765 765
766 QClipboard *cb = QApplication::clipboard(); 766 QClipboard *cb = QApplication::clipboard();
767 cb->setText( clipText ); 767 cb->setText( clipText );
768} 768}
769 769
770void KABCore::cutContacts() 770void KABCore::cutContacts()
771{ 771{
772 QStringList uidList = mViewManager->selectedUids(); 772 QStringList uidList = mViewManager->selectedUids();
773 773
774//US if ( uidList.size() > 0 ) { 774//US if ( uidList.size() > 0 ) {
775 if ( uidList.count() > 0 ) { 775 if ( uidList.count() > 0 ) {
776 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 776 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
777 UndoStack::instance()->push( command ); 777 UndoStack::instance()->push( command );
778 RedoStack::instance()->clear(); 778 RedoStack::instance()->clear();
779 779
780 setModified( true ); 780 setModified( true );
781 } 781 }
782} 782}
783 783
784void KABCore::pasteContacts() 784void KABCore::pasteContacts()
785{ 785{
786 QClipboard *cb = QApplication::clipboard(); 786 QClipboard *cb = QApplication::clipboard();
787 787
788 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 788 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
789 789
790 pasteContacts( list ); 790 pasteContacts( list );
791} 791}
792 792
793void KABCore::pasteContacts( KABC::Addressee::List &list ) 793void KABCore::pasteContacts( KABC::Addressee::List &list )
794{ 794{
795 KABC::Resource *resource = requestResource( this ); 795 KABC::Resource *resource = requestResource( this );
796 KABC::Addressee::List::Iterator it; 796 KABC::Addressee::List::Iterator it;
797 for ( it = list.begin(); it != list.end(); ++it ) 797 for ( it = list.begin(); it != list.end(); ++it )
798 (*it).setResource( resource ); 798 (*it).setResource( resource );
799 799
800 PwPasteCommand *command = new PwPasteCommand( this, list ); 800 PwPasteCommand *command = new PwPasteCommand( this, list );
801 UndoStack::instance()->push( command ); 801 UndoStack::instance()->push( command );
802 RedoStack::instance()->clear(); 802 RedoStack::instance()->clear();
803 803
804 setModified( true ); 804 setModified( true );
805} 805}
806 806
807void KABCore::setWhoAmI() 807void KABCore::setWhoAmI()
808{ 808{
809 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 809 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
810 810
811 if ( addrList.count() > 1 ) { 811 if ( addrList.count() > 1 ) {
812 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 812 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
813 return; 813 return;
814 } 814 }
815 815
816 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 816 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
817 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 817 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
818 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 818 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
819} 819}
820 820
821void KABCore::setCategories() 821void KABCore::setCategories()
822{ 822{
823 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 823 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
824 if ( !dlg.exec() ) 824 if ( !dlg.exec() )
825 return; 825 return;
826 826
827 bool merge = false; 827 bool merge = false;
828 QString msg = i18n( "Merge with existing categories?" ); 828 QString msg = i18n( "Merge with existing categories?" );
829 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 829 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
830 merge = true; 830 merge = true;
831 831
832 QStringList categories = dlg.selectedCategories(); 832 QStringList categories = dlg.selectedCategories();
833 833
834 QStringList uids = mViewManager->selectedUids(); 834 QStringList uids = mViewManager->selectedUids();
835 QStringList::Iterator it; 835 QStringList::Iterator it;
836 for ( it = uids.begin(); it != uids.end(); ++it ) { 836 for ( it = uids.begin(); it != uids.end(); ++it ) {
837 KABC::Addressee addr = mAddressBook->findByUid( *it ); 837 KABC::Addressee addr = mAddressBook->findByUid( *it );
838 if ( !addr.isEmpty() ) { 838 if ( !addr.isEmpty() ) {
839 if ( !merge ) 839 if ( !merge )
840 addr.setCategories( categories ); 840 addr.setCategories( categories );
841 else { 841 else {
842 QStringList addrCategories = addr.categories(); 842 QStringList addrCategories = addr.categories();
843 QStringList::Iterator catIt; 843 QStringList::Iterator catIt;
844 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 844 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
845 if ( !addrCategories.contains( *catIt ) ) 845 if ( !addrCategories.contains( *catIt ) )
846 addrCategories.append( *catIt ); 846 addrCategories.append( *catIt );
847 } 847 }
848 addr.setCategories( addrCategories ); 848 addr.setCategories( addrCategories );
849 } 849 }
850 850
851 mAddressBook->insertAddressee( addr ); 851 mAddressBook->insertAddressee( addr );
852 } 852 }
853 } 853 }
854 854
855 if ( uids.count() > 0 ) 855 if ( uids.count() > 0 )
856 setModified( true ); 856 setModified( true );
857} 857}
858 858
859void KABCore::setSearchFields( const KABC::Field::List &fields ) 859void KABCore::setSearchFields( const KABC::Field::List &fields )
860{ 860{
861 mIncSearchWidget->setFields( fields ); 861 mIncSearchWidget->setFields( fields );
862} 862}
863 863
864void KABCore::incrementalSearch( const QString& text ) 864void KABCore::incrementalSearch( const QString& text )
865{ 865{
866 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 866 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
867} 867}
868 868
869void KABCore::setModified() 869void KABCore::setModified()
870{ 870{
871 setModified( true ); 871 setModified( true );
872} 872}
873 873
874void KABCore::setModifiedWOrefresh() 874void KABCore::setModifiedWOrefresh()
875{ 875{
876 // qDebug("KABCore::setModifiedWOrefresh() "); 876 // qDebug("KABCore::setModifiedWOrefresh() ");
877 mModified = true; 877 mModified = true;
878 mActionSave->setEnabled( mModified ); 878 mActionSave->setEnabled( mModified );
879#ifdef DESKTOP_VERSION 879#ifdef DESKTOP_VERSION
880 mDetails->refreshView(); 880 mDetails->refreshView();
881#endif 881#endif
882 882
883} 883}
884void KABCore::setModified( bool modified ) 884void KABCore::setModified( bool modified )
885{ 885{
886 mModified = modified; 886 mModified = modified;
887 mActionSave->setEnabled( mModified ); 887 mActionSave->setEnabled( mModified );
888 888
889 if ( modified ) 889 if ( modified )
890 mJumpButtonBar->recreateButtons(); 890 mJumpButtonBar->recreateButtons();
891 891
892 mViewManager->refreshView(); 892 mViewManager->refreshView();
893 mDetails->refreshView(); 893 mDetails->refreshView();
894 894
895} 895}
896 896
897bool KABCore::modified() const 897bool KABCore::modified() const
898{ 898{
899 return mModified; 899 return mModified;
900} 900}
901 901
902void KABCore::contactModified( const KABC::Addressee &addr ) 902void KABCore::contactModified( const KABC::Addressee &addr )
903{ 903{
904 904
905 Command *command = 0; 905 Command *command = 0;
906 QString uid; 906 QString uid;
907 907
908 // check if it exists already 908 // check if it exists already
909 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 909 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
910 if ( origAddr.isEmpty() ) 910 if ( origAddr.isEmpty() )
911 command = new PwNewCommand( mAddressBook, addr ); 911 command = new PwNewCommand( mAddressBook, addr );
912 else { 912 else {
913 command = new PwEditCommand( mAddressBook, origAddr, addr ); 913 command = new PwEditCommand( mAddressBook, origAddr, addr );
914 uid = addr.uid(); 914 uid = addr.uid();
915 } 915 }
916 916
917 UndoStack::instance()->push( command ); 917 UndoStack::instance()->push( command );
918 RedoStack::instance()->clear(); 918 RedoStack::instance()->clear();
919 919
920 setModified( true ); 920 setModified( true );
921} 921}
922 922
923void KABCore::newContact() 923void KABCore::newContact()
924{ 924{
925 925
926 926
927 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 927 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
928 928
929 QPtrList<KRES::Resource> kresResources; 929 QPtrList<KRES::Resource> kresResources;
930 QPtrListIterator<KABC::Resource> it( kabcResources ); 930 QPtrListIterator<KABC::Resource> it( kabcResources );
931 KABC::Resource *resource; 931 KABC::Resource *resource;
932 while ( ( resource = it.current() ) != 0 ) { 932 while ( ( resource = it.current() ) != 0 ) {
933 ++it; 933 ++it;
934 if ( !resource->readOnly() ) { 934 if ( !resource->readOnly() ) {
935 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 935 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
936 if ( res ) 936 if ( res )
937 kresResources.append( res ); 937 kresResources.append( res );
938 } 938 }
939 } 939 }
940 940
941 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 941 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
942 resource = static_cast<KABC::Resource*>( res ); 942 resource = static_cast<KABC::Resource*>( res );
943 943
944 if ( resource ) { 944 if ( resource ) {
945 KABC::Addressee addr; 945 KABC::Addressee addr;
946 addr.setResource( resource ); 946 addr.setResource( resource );
947 mEditorDialog->setAddressee( addr ); 947 mEditorDialog->setAddressee( addr );
948 KApplication::execDialog ( mEditorDialog ); 948 KApplication::execDialog ( mEditorDialog );
949 949
950 } else 950 } else
951 return; 951 return;
952 952
953 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 953 // mEditorDict.insert( dialog->addressee().uid(), dialog );
954 954
955 955
956} 956}
957 957
958void KABCore::addEmail( QString aStr ) 958void KABCore::addEmail( QString aStr )
959{ 959{
960#ifndef KAB_EMBEDDED 960#ifndef KAB_EMBEDDED
961 QString fullName, email; 961 QString fullName, email;
962 962
963 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 963 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
964 964
965 // Try to lookup the addressee matching the email address 965 // Try to lookup the addressee matching the email address
966 bool found = false; 966 bool found = false;
967 QStringList emailList; 967 QStringList emailList;
968 KABC::AddressBook::Iterator it; 968 KABC::AddressBook::Iterator it;
969 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 969 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
970 emailList = (*it).emails(); 970 emailList = (*it).emails();
971 if ( emailList.contains( email ) > 0 ) { 971 if ( emailList.contains( email ) > 0 ) {
972 found = true; 972 found = true;
973 (*it).setNameFromString( fullName ); 973 (*it).setNameFromString( fullName );
974 editContact( (*it).uid() ); 974 editContact( (*it).uid() );
975 } 975 }
976 } 976 }
977 977
978 if ( !found ) { 978 if ( !found ) {
979 KABC::Addressee addr; 979 KABC::Addressee addr;
980 addr.setNameFromString( fullName ); 980 addr.setNameFromString( fullName );
981 addr.insertEmail( email, true ); 981 addr.insertEmail( email, true );
982 982
983 mAddressBook->insertAddressee( addr ); 983 mAddressBook->insertAddressee( addr );
984 mViewManager->refreshView( addr.uid() ); 984 mViewManager->refreshView( addr.uid() );
985 editContact( addr.uid() ); 985 editContact( addr.uid() );
986 } 986 }
987#else //KAB_EMBEDDED 987#else //KAB_EMBEDDED
988 qDebug("KABCore::addEmail finsih method"); 988 qDebug("KABCore::addEmail finsih method");
989#endif //KAB_EMBEDDED 989#endif //KAB_EMBEDDED
990} 990}
991 991
992void KABCore::importVCard( const KURL &url, bool showPreview ) 992void KABCore::importVCard( const KURL &url, bool showPreview )
993{ 993{
994 mXXPortManager->importVCard( url, showPreview ); 994 mXXPortManager->importVCard( url, showPreview );
995} 995}
996void KABCore::importFromOL() 996void KABCore::importFromOL()
997{ 997{
998#ifdef _WIN32_ 998#ifdef _WIN32_
999 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 999 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
1000 idgl->exec(); 1000 idgl->exec();
1001 KABC::Addressee::List list = idgl->getAddressList(); 1001 KABC::Addressee::List list = idgl->getAddressList();
1002 if ( list.count() > 0 ) { 1002 if ( list.count() > 0 ) {
1003 KABC::Addressee::List listNew; 1003 KABC::Addressee::List listNew;
1004 KABC::Addressee::List listExisting; 1004 KABC::Addressee::List listExisting;
1005 KABC::Addressee::List::Iterator it; 1005 KABC::Addressee::List::Iterator it;
1006 KABC::AddressBook::Iterator iter; 1006 KABC::AddressBook::Iterator iter;
1007 for ( it = list.begin(); it != list.end(); ++it ) { 1007 for ( it = list.begin(); it != list.end(); ++it ) {
1008 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1008 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1009 listNew.append( (*it) ); 1009 listNew.append( (*it) );
1010 else 1010 else
1011 listExisting.append( (*it) ); 1011 listExisting.append( (*it) );
1012 } 1012 }
1013 if ( listExisting.count() > 0 ) 1013 if ( listExisting.count() > 0 )
1014 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1014 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1015 if ( listNew.count() > 0 ) { 1015 if ( listNew.count() > 0 ) {
1016 pasteWithNewUid = false; 1016 pasteWithNewUid = false;
1017 pasteContacts( listNew ); 1017 pasteContacts( listNew );
1018 pasteWithNewUid = true; 1018 pasteWithNewUid = true;
1019 } 1019 }
1020 } 1020 }
1021 delete idgl; 1021 delete idgl;
1022#endif 1022#endif
1023} 1023}
1024 1024
1025void KABCore::importVCard( const QString &vCard, bool showPreview ) 1025void KABCore::importVCard( const QString &vCard, bool showPreview )
1026{ 1026{
1027 mXXPortManager->importVCard( vCard, showPreview ); 1027 mXXPortManager->importVCard( vCard, showPreview );
1028} 1028}
1029 1029
1030//US added a second method without defaultparameter 1030//US added a second method without defaultparameter
1031void KABCore::editContact2() { 1031void KABCore::editContact2() {
1032 editContact( QString::null ); 1032 editContact( QString::null );
1033} 1033}
1034 1034
1035void KABCore::editContact( const QString &uid ) 1035void KABCore::editContact( const QString &uid )
1036{ 1036{
1037 1037
1038 if ( mExtensionManager->isQuickEditVisible() ) 1038 if ( mExtensionManager->isQuickEditVisible() )
1039 return; 1039 return;
1040 1040
1041 // First, locate the contact entry 1041 // First, locate the contact entry
1042 QString localUID = uid; 1042 QString localUID = uid;
1043 if ( localUID.isNull() ) { 1043 if ( localUID.isNull() ) {
1044 QStringList uidList = mViewManager->selectedUids(); 1044 QStringList uidList = mViewManager->selectedUids();
1045 if ( uidList.count() > 0 ) 1045 if ( uidList.count() > 0 )
1046 localUID = *( uidList.at( 0 ) ); 1046 localUID = *( uidList.at( 0 ) );
1047 } 1047 }
1048 1048
1049 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1049 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1050 if ( !addr.isEmpty() ) { 1050 if ( !addr.isEmpty() ) {
1051 mEditorDialog->setAddressee( addr ); 1051 mEditorDialog->setAddressee( addr );
1052 KApplication::execDialog ( mEditorDialog ); 1052 KApplication::execDialog ( mEditorDialog );
1053 } 1053 }
1054} 1054}
1055 1055
1056/** 1056/**
1057 Shows or edits the detail view for the given uid. If the uid is QString::null, 1057 Shows or edits the detail view for the given uid. If the uid is QString::null,
1058 the method will try to find a selected addressee in the view. 1058 the method will try to find a selected addressee in the view.
1059 */ 1059 */
1060void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1060void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1061{ 1061{
1062 if ( mMultipleViewsAtOnce ) 1062 if ( mMultipleViewsAtOnce )
1063 { 1063 {
1064 editContact( uid ); 1064 editContact( uid );
1065 } 1065 }
1066 else 1066 else
1067 { 1067 {
1068 setDetailsVisible( true ); 1068 setDetailsVisible( true );
1069 mActionDetails->setChecked(true); 1069 mActionDetails->setChecked(true);
1070 } 1070 }
1071 1071
1072} 1072}
1073 1073
1074void KABCore::save() 1074void KABCore::save()
1075{ 1075{
1076 if (mBlockSaveFlag) 1076 if (mBlockSaveFlag)
1077 return; 1077 return;
1078 mBlockSaveFlag = true; 1078 mBlockSaveFlag = true;
1079 if ( !mModified ) 1079 if ( !mModified )
1080 return; 1080 return;
1081 QString text = i18n( "There was an error while attempting to save\n the " 1081 QString text = i18n( "There was an error while attempting to save\n the "
1082 "address book. Please check that some \nother application is " 1082 "address book. Please check that some \nother application is "
1083 "not using it. " ); 1083 "not using it. " );
1084 statusMessage(i18n("Saving addressbook ... ")); 1084 statusMessage(i18n("Saving addressbook ... "));
1085#ifndef KAB_EMBEDDED 1085#ifndef KAB_EMBEDDED
1086 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1086 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1087 if ( !b || !b->save() ) { 1087 if ( !b || !b->save() ) {
1088 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1088 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1089 } 1089 }
1090#else //KAB_EMBEDDED 1090#else //KAB_EMBEDDED
1091 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1091 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1092 if ( !b || !b->save() ) { 1092 if ( !b || !b->save() ) {
1093 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1093 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1094 } 1094 }
1095#endif //KAB_EMBEDDED 1095#endif //KAB_EMBEDDED
1096 1096
1097 statusMessage(i18n("Addressbook saved!")); 1097 statusMessage(i18n("Addressbook saved!"));
1098 setModified( false ); 1098 setModified( false );
1099 mBlockSaveFlag = false; 1099 mBlockSaveFlag = false;
1100} 1100}
1101 1101
1102void KABCore::statusMessage(QString mess , int time ) 1102void KABCore::statusMessage(QString mess , int time )
1103{ 1103{
1104 //topLevelWidget()->setCaption( mess ); 1104 //topLevelWidget()->setCaption( mess );
1105 // pending setting timer to revome message 1105 // pending setting timer to revome message
1106} 1106}
1107void KABCore::undo() 1107void KABCore::undo()
1108{ 1108{
1109 UndoStack::instance()->undo(); 1109 UndoStack::instance()->undo();
1110 1110
1111 // Refresh the view 1111 // Refresh the view
1112 mViewManager->refreshView(); 1112 mViewManager->refreshView();
1113} 1113}
1114 1114
1115void KABCore::redo() 1115void KABCore::redo()
1116{ 1116{
1117 RedoStack::instance()->redo(); 1117 RedoStack::instance()->redo();
1118 1118
1119 // Refresh the view 1119 // Refresh the view
1120 mViewManager->refreshView(); 1120 mViewManager->refreshView();
1121} 1121}
1122 1122
1123void KABCore::setJumpButtonBarVisible( bool visible ) 1123void KABCore::setJumpButtonBarVisible( bool visible )
1124{ 1124{
1125 if (mMultipleViewsAtOnce) 1125 if (mMultipleViewsAtOnce)
1126 { 1126 {
1127 if ( visible ) 1127 if ( visible )
1128 mJumpButtonBar->show(); 1128 mJumpButtonBar->show();
1129 else 1129 else
1130 mJumpButtonBar->hide(); 1130 mJumpButtonBar->hide();
1131 } 1131 }
1132 else 1132 else
1133 { 1133 {
1134 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1134 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1135 if (mViewManager->isVisible()) 1135 if (mViewManager->isVisible())
1136 { 1136 {
1137 if ( visible ) 1137 if ( visible )
1138 mJumpButtonBar->show(); 1138 mJumpButtonBar->show();
1139 else 1139 else
1140 mJumpButtonBar->hide(); 1140 mJumpButtonBar->hide();
1141 } 1141 }
1142 else 1142 else
1143 { 1143 {
1144 mJumpButtonBar->hide(); 1144 mJumpButtonBar->hide();
1145 } 1145 }
1146 } 1146 }
1147} 1147}
1148 1148
1149 1149
1150void KABCore::setDetailsToState() 1150void KABCore::setDetailsToState()
1151{ 1151{
1152 setDetailsVisible( mActionDetails->isChecked() ); 1152 setDetailsVisible( mActionDetails->isChecked() );
1153} 1153}
1154 1154
1155 1155
1156 1156
1157void KABCore::setDetailsVisible( bool visible ) 1157void KABCore::setDetailsVisible( bool visible )
1158{ 1158{
1159 if (visible && mDetails->isHidden()) 1159 if (visible && mDetails->isHidden())
1160 { 1160 {
1161 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1161 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1162 if ( addrList.count() > 0 ) 1162 if ( addrList.count() > 0 )
1163 mDetails->setAddressee( addrList[ 0 ] ); 1163 mDetails->setAddressee( addrList[ 0 ] );
1164 } 1164 }
1165 1165
1166 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1166 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1167 // the listview and the detailview. We do that by changing the splitbar size. 1167 // the listview and the detailview. We do that by changing the splitbar size.
1168 if (mMultipleViewsAtOnce) 1168 if (mMultipleViewsAtOnce)
1169 { 1169 {
1170 if ( visible ) 1170 if ( visible )
1171 mDetails->show(); 1171 mDetails->show();
1172 else 1172 else
1173 mDetails->hide(); 1173 mDetails->hide();
1174 } 1174 }
1175 else 1175 else
1176 { 1176 {
1177 if ( visible ) { 1177 if ( visible ) {
1178 mViewManager->hide(); 1178 mViewManager->hide();
1179 mDetails->show(); 1179 mDetails->show();
1180 } 1180 }
1181 else { 1181 else {
1182 mViewManager->show(); 1182 mViewManager->show();
1183 mDetails->hide(); 1183 mDetails->hide();
1184 } 1184 }
1185 setJumpButtonBarVisible( !visible ); 1185 setJumpButtonBarVisible( !visible );
1186 } 1186 }
1187 1187
1188} 1188}
1189 1189
1190void KABCore::extensionChanged( int id ) 1190void KABCore::extensionChanged( int id )
1191{ 1191{
1192 //change the details view only for non desktop systems 1192 //change the details view only for non desktop systems
1193#ifndef DESKTOP_VERSION 1193#ifndef DESKTOP_VERSION
1194 1194
1195 if (id == 0) 1195 if (id == 0)
1196 { 1196 {
1197 //the user disabled the extension. 1197 //the user disabled the extension.
1198 1198
1199 if (mMultipleViewsAtOnce) 1199 if (mMultipleViewsAtOnce)
1200 { // enable detailsview again 1200 { // enable detailsview again
1201 setDetailsVisible( true ); 1201 setDetailsVisible( true );
1202 mActionDetails->setChecked( true ); 1202 mActionDetails->setChecked( true );
1203 } 1203 }
1204 else 1204 else
1205 { //go back to the listview 1205 { //go back to the listview
1206 setDetailsVisible( false ); 1206 setDetailsVisible( false );
1207 mActionDetails->setChecked( false ); 1207 mActionDetails->setChecked( false );
1208 mActionDetails->setEnabled(true); 1208 mActionDetails->setEnabled(true);
1209 } 1209 }
1210 1210
1211 } 1211 }
1212 else 1212 else
1213 { 1213 {
1214 //the user enabled the extension. 1214 //the user enabled the extension.
1215 setDetailsVisible( false ); 1215 setDetailsVisible( false );
1216 mActionDetails->setChecked( false ); 1216 mActionDetails->setChecked( false );
1217 1217
1218 if (!mMultipleViewsAtOnce) 1218 if (!mMultipleViewsAtOnce)
1219 { 1219 {
1220 mActionDetails->setEnabled(false); 1220 mActionDetails->setEnabled(false);
1221 } 1221 }
1222 1222
1223 mExtensionManager->setSelectionChanged(); 1223 mExtensionManager->setSelectionChanged();
1224 1224
1225 } 1225 }
1226 1226
1227#endif// DESKTOP_VERSION 1227#endif// DESKTOP_VERSION
1228 1228
1229} 1229}
1230 1230
1231 1231
1232void KABCore::extensionModified( const KABC::Addressee::List &list ) 1232void KABCore::extensionModified( const KABC::Addressee::List &list )
1233{ 1233{
1234 1234
1235 if ( list.count() != 0 ) { 1235 if ( list.count() != 0 ) {
1236 KABC::Addressee::List::ConstIterator it; 1236 KABC::Addressee::List::ConstIterator it;
1237 for ( it = list.begin(); it != list.end(); ++it ) 1237 for ( it = list.begin(); it != list.end(); ++it )
1238 mAddressBook->insertAddressee( *it ); 1238 mAddressBook->insertAddressee( *it );
1239 if ( list.count() > 1 ) 1239 if ( list.count() > 1 )
1240 setModified(); 1240 setModified();
1241 else 1241 else
1242 setModifiedWOrefresh(); 1242 setModifiedWOrefresh();
1243 } 1243 }
1244 if ( list.count() == 0 ) 1244 if ( list.count() == 0 )
1245 mViewManager->refreshView(); 1245 mViewManager->refreshView();
1246 else 1246 else
1247 mViewManager->refreshView( list[ 0 ].uid() ); 1247 mViewManager->refreshView( list[ 0 ].uid() );
1248 1248
1249 1249
1250 1250
1251} 1251}
1252 1252
1253QString KABCore::getNameByPhone( const QString &phone ) 1253QString KABCore::getNameByPhone( const QString &phone )
1254{ 1254{
1255#ifndef KAB_EMBEDDED 1255#ifndef KAB_EMBEDDED
1256 QRegExp r( "[/*/-/ ]" ); 1256 QRegExp r( "[/*/-/ ]" );
1257 QString localPhone( phone ); 1257 QString localPhone( phone );
1258 1258
1259 bool found = false; 1259 bool found = false;
1260 QString ownerName = ""; 1260 QString ownerName = "";
1261 KABC::AddressBook::Iterator iter; 1261 KABC::AddressBook::Iterator iter;
1262 KABC::PhoneNumber::List::Iterator phoneIter; 1262 KABC::PhoneNumber::List::Iterator phoneIter;
1263 KABC::PhoneNumber::List phoneList; 1263 KABC::PhoneNumber::List phoneList;
1264 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1264 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1265 phoneList = (*iter).phoneNumbers(); 1265 phoneList = (*iter).phoneNumbers();
1266 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1266 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1267 ++phoneIter) { 1267 ++phoneIter) {
1268 // Get rid of separator chars so just the numbers are compared. 1268 // Get rid of separator chars so just the numbers are compared.
1269 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1269 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1270 ownerName = (*iter).formattedName(); 1270 ownerName = (*iter).formattedName();
1271 found = true; 1271 found = true;
1272 } 1272 }
1273 } 1273 }
1274 } 1274 }
1275 1275
1276 return ownerName; 1276 return ownerName;
1277#else //KAB_EMBEDDED 1277#else //KAB_EMBEDDED
1278 qDebug("KABCore::getNameByPhone finsih method"); 1278 qDebug("KABCore::getNameByPhone finsih method");
1279 return ""; 1279 return "";
1280#endif //KAB_EMBEDDED 1280#endif //KAB_EMBEDDED
1281 1281
1282} 1282}
1283 1283
1284void KABCore::openConfigDialog() 1284void KABCore::openConfigDialog()
1285{ 1285{
1286 KABPrefs* kab_prefs = KABPrefs::instance(); 1286 KABPrefs* kab_prefs = KABPrefs::instance();
1287 KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance(); 1287 KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance();
1288 1288
1289 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1289 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1290 KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1290 KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1291 ConfigureDialog->addModule(kabcfg ); 1291 ConfigureDialog->addModule(kabcfg );
1292 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1292 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1293 ConfigureDialog->addModule(kdelibcfg ); 1293 ConfigureDialog->addModule(kdelibcfg );
1294 1294
1295 1295
1296 1296
1297 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1297 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1298 this, SLOT( configurationChanged() ) ); 1298 this, SLOT( configurationChanged() ) );
1299 connect( ConfigureDialog, SIGNAL( okClicked() ), 1299 connect( ConfigureDialog, SIGNAL( okClicked() ),
1300 this, SLOT( configurationChanged() ) ); 1300 this, SLOT( configurationChanged() ) );
1301 saveSettings(); 1301 saveSettings();
1302#ifndef DESKTOP_VERSION 1302#ifndef DESKTOP_VERSION
1303 ConfigureDialog->showMaximized(); 1303 ConfigureDialog->showMaximized();
1304#endif 1304#endif
1305 if ( ConfigureDialog->exec() ) 1305 if ( ConfigureDialog->exec() )
1306 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1306 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1307 delete ConfigureDialog; 1307 delete ConfigureDialog;
1308} 1308}
1309 1309
1310void KABCore::openLDAPDialog() 1310void KABCore::openLDAPDialog()
1311{ 1311{
1312#ifndef KAB_EMBEDDED 1312#ifndef KAB_EMBEDDED
1313 if ( !mLdapSearchDialog ) { 1313 if ( !mLdapSearchDialog ) {
1314 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1314 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1315 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1315 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1316 SLOT( refreshView() ) ); 1316 SLOT( refreshView() ) );
1317 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1317 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1318 SLOT( setModified() ) ); 1318 SLOT( setModified() ) );
1319 } else 1319 } else
1320 mLdapSearchDialog->restoreSettings(); 1320 mLdapSearchDialog->restoreSettings();
1321 1321
1322 if ( mLdapSearchDialog->isOK() ) 1322 if ( mLdapSearchDialog->isOK() )
1323 mLdapSearchDialog->exec(); 1323 mLdapSearchDialog->exec();
1324#else //KAB_EMBEDDED 1324#else //KAB_EMBEDDED
1325 qDebug("KABCore::openLDAPDialog() finsih method"); 1325 qDebug("KABCore::openLDAPDialog() finsih method");
1326#endif //KAB_EMBEDDED 1326#endif //KAB_EMBEDDED
1327} 1327}
1328 1328
1329void KABCore::print() 1329void KABCore::print()
1330{ 1330{
1331#ifndef KAB_EMBEDDED 1331#ifndef KAB_EMBEDDED
1332 KPrinter printer; 1332 KPrinter printer;
1333 if ( !printer.setup( this ) ) 1333 if ( !printer.setup( this ) )
1334 return; 1334 return;
1335 1335
1336 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1336 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1337 mViewManager->selectedUids(), this ); 1337 mViewManager->selectedUids(), this );
1338 1338
1339 wizard.exec(); 1339 wizard.exec();
1340#else //KAB_EMBEDDED 1340#else //KAB_EMBEDDED
1341 qDebug("KABCore::print() finsih method"); 1341 qDebug("KABCore::print() finsih method");
1342#endif //KAB_EMBEDDED 1342#endif //KAB_EMBEDDED
1343 1343
1344} 1344}
1345 1345
1346 1346
1347void KABCore::addGUIClient( KXMLGUIClient *client ) 1347void KABCore::addGUIClient( KXMLGUIClient *client )
1348{ 1348{
1349 if ( mGUIClient ) 1349 if ( mGUIClient )
1350 mGUIClient->insertChildClient( client ); 1350 mGUIClient->insertChildClient( client );
1351 else 1351 else
1352 KMessageBox::error( this, "no KXMLGUICLient"); 1352 KMessageBox::error( this, "no KXMLGUICLient");
1353} 1353}
1354 1354
1355 1355
1356void KABCore::configurationChanged() 1356void KABCore::configurationChanged()
1357{ 1357{
1358 mExtensionManager->reconfigure(); 1358 mExtensionManager->reconfigure();
1359} 1359}
1360 1360
1361void KABCore::addressBookChanged() 1361void KABCore::addressBookChanged()
1362{ 1362{
1363/*US 1363/*US
1364 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1364 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1365 while ( it.current() ) { 1365 while ( it.current() ) {
1366 if ( it.current()->dirty() ) { 1366 if ( it.current()->dirty() ) {
1367 QString text = i18n( "Data has been changed externally. Unsaved " 1367 QString text = i18n( "Data has been changed externally. Unsaved "
1368 "changes will be lost." ); 1368 "changes will be lost." );
1369 KMessageBox::information( this, text ); 1369 KMessageBox::information( this, text );
1370 } 1370 }
1371 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1371 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1372 ++it; 1372 ++it;
1373 } 1373 }
1374*/ 1374*/
1375 if (mEditorDialog) 1375 if (mEditorDialog)
1376 { 1376 {
1377 if (mEditorDialog->dirty()) 1377 if (mEditorDialog->dirty())
1378 { 1378 {
1379 QString text = i18n( "Data has been changed externally. Unsaved " 1379 QString text = i18n( "Data has been changed externally. Unsaved "
1380 "changes will be lost." ); 1380 "changes will be lost." );
1381 KMessageBox::information( this, text ); 1381 KMessageBox::information( this, text );
1382 } 1382 }
1383 QString currentuid = mEditorDialog->addressee().uid(); 1383 QString currentuid = mEditorDialog->addressee().uid();
1384 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1384 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1385 } 1385 }
1386 mViewManager->refreshView(); 1386 mViewManager->refreshView();
1387// mDetails->refreshView(); 1387// mDetails->refreshView();
1388 1388
1389 1389
1390} 1390}
1391 1391
1392AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1392AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1393 const char *name ) 1393 const char *name )
1394{ 1394{
1395 1395
1396 if ( mEditorDialog == 0 ) { 1396 if ( mEditorDialog == 0 ) {
1397 mEditorDialog = new AddresseeEditorDialog( this, parent, 1397 mEditorDialog = new AddresseeEditorDialog( this, parent,
1398 name ? name : "editorDialog" ); 1398 name ? name : "editorDialog" );
1399 1399
1400 1400
1401 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1401 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1402 SLOT( contactModified( const KABC::Addressee& ) ) ); 1402 SLOT( contactModified( const KABC::Addressee& ) ) );
1403 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1403 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1404 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1404 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1405 } 1405 }
1406 1406
1407 return mEditorDialog; 1407 return mEditorDialog;
1408} 1408}
1409 1409
1410void KABCore::slotEditorDestroyed( const QString &uid ) 1410void KABCore::slotEditorDestroyed( const QString &uid )
1411{ 1411{
1412 //mEditorDict.remove( uid ); 1412 //mEditorDict.remove( uid );
1413} 1413}
1414 1414
1415void KABCore::initGUI() 1415void KABCore::initGUI()
1416{ 1416{
1417#ifndef KAB_EMBEDDED 1417#ifndef KAB_EMBEDDED
1418 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1418 QHBoxLayout *topLayout = new QHBoxLayout( this );
1419 topLayout->setSpacing( KDialogBase::spacingHint() ); 1419 topLayout->setSpacing( KDialogBase::spacingHint() );
1420 1420
1421 mExtensionBarSplitter = new QSplitter( this ); 1421 mExtensionBarSplitter = new QSplitter( this );
1422 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1422 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1423 1423
1424 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1424 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1425 1425
1426 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1426 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1427 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1427 mIncSearchWidget = new IncSearchWidget( viewSpace );
1428 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1428 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1429 SLOT( incrementalSearch( const QString& ) ) ); 1429 SLOT( incrementalSearch( const QString& ) ) );
1430 1430
1431 mViewManager = new ViewManager( this, viewSpace ); 1431 mViewManager = new ViewManager( this, viewSpace );
1432 viewSpace->setStretchFactor( mViewManager, 1 ); 1432 viewSpace->setStretchFactor( mViewManager, 1 );
1433 1433
1434 mDetails = new ViewContainer( mDetailsSplitter ); 1434 mDetails = new ViewContainer( mDetailsSplitter );
1435 1435
1436 mJumpButtonBar = new JumpButtonBar( this, this ); 1436 mJumpButtonBar = new JumpButtonBar( this, this );
1437 1437
1438 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1438 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1439 1439
1440 topLayout->addWidget( mExtensionBarSplitter ); 1440 topLayout->addWidget( mExtensionBarSplitter );
1441 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1441 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1442 topLayout->addWidget( mJumpButtonBar ); 1442 topLayout->addWidget( mJumpButtonBar );
1443 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1443 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1444 1444
1445 mXXPortManager = new XXPortManager( this, this ); 1445 mXXPortManager = new XXPortManager( this, this );
1446 1446
1447#else //KAB_EMBEDDED 1447#else //KAB_EMBEDDED
1448 //US initialize viewMenu before settingup viewmanager. 1448 //US initialize viewMenu before settingup viewmanager.
1449 // Viewmanager needs this menu to plugin submenues. 1449 // Viewmanager needs this menu to plugin submenues.
1450 viewMenu = new QPopupMenu( this ); 1450 viewMenu = new QPopupMenu( this );
1451 settingsMenu = new QPopupMenu( this ); 1451 settingsMenu = new QPopupMenu( this );
1452 //filterMenu = new QPopupMenu( this ); 1452 //filterMenu = new QPopupMenu( this );
1453 ImportMenu = new QPopupMenu( this ); 1453 ImportMenu = new QPopupMenu( this );
1454 ExportMenu = new QPopupMenu( this ); 1454 ExportMenu = new QPopupMenu( this );
1455 syncMenu = new QPopupMenu( this ); 1455 syncMenu = new QPopupMenu( this );
1456 changeMenu= new QPopupMenu( this ); 1456 changeMenu= new QPopupMenu( this );
1457 1457
1458//US since we have no splitter for the embedded system, setup 1458//US since we have no splitter for the embedded system, setup
1459// a layout with two frames. One left and one right. 1459// a layout with two frames. One left and one right.
1460 1460
1461 QBoxLayout *topLayout; 1461 QBoxLayout *topLayout;
1462 1462
1463 // = new QHBoxLayout( this ); 1463 // = new QHBoxLayout( this );
1464// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1464// QBoxLayout *topLayout = (QBoxLayout*)layout();
1465 1465
1466// QWidget *mainBox = new QWidget( this ); 1466// QWidget *mainBox = new QWidget( this );
1467// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1467// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1468 1468
1469#ifdef DESKTOP_VERSION 1469#ifdef DESKTOP_VERSION
1470 topLayout = new QHBoxLayout( this ); 1470 topLayout = new QHBoxLayout( this );
1471 1471
1472 1472
1473 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1473 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1474 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1474 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1475 1475
1476 topLayout->addWidget(mMiniSplitter ); 1476 topLayout->addWidget(mMiniSplitter );
1477 1477
1478 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1478 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1479 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1479 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1480 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1480 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1481 mDetails = new ViewContainer( mMiniSplitter ); 1481 mDetails = new ViewContainer( mMiniSplitter );
1482 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1482 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1483#else 1483#else
1484 if ( QApplication::desktop()->width() > 480 ) { 1484 if ( QApplication::desktop()->width() > 480 ) {
1485 topLayout = new QHBoxLayout( this ); 1485 topLayout = new QHBoxLayout( this );
1486 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1486 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1487 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1487 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1488 } else { 1488 } else {
1489 1489
1490 topLayout = new QHBoxLayout( this ); 1490 topLayout = new QHBoxLayout( this );
1491 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1491 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1492 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1492 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1493 } 1493 }
1494 1494
1495 topLayout->addWidget(mMiniSplitter ); 1495 topLayout->addWidget(mMiniSplitter );
1496 mViewManager = new ViewManager( this, mMiniSplitter ); 1496 mViewManager = new ViewManager( this, mMiniSplitter );
1497 mDetails = new ViewContainer( mMiniSplitter ); 1497 mDetails = new ViewContainer( mMiniSplitter );
1498 1498
1499 1499
1500 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1500 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1501#endif 1501#endif
1502 //eh->hide(); 1502 //eh->hide();
1503 // topLayout->addWidget(mExtensionManager ); 1503 // topLayout->addWidget(mExtensionManager );
1504 1504
1505 1505
1506/*US 1506/*US
1507#ifndef KAB_NOSPLITTER 1507#ifndef KAB_NOSPLITTER
1508 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1508 QHBoxLayout *topLayout = new QHBoxLayout( this );
1509//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1509//US topLayout->setSpacing( KDialogBase::spacingHint() );
1510 topLayout->setSpacing( 10 ); 1510 topLayout->setSpacing( 10 );
1511 1511
1512 mDetailsSplitter = new QSplitter( this ); 1512 mDetailsSplitter = new QSplitter( this );
1513 1513
1514 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1514 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1515 1515
1516 mViewManager = new ViewManager( this, viewSpace ); 1516 mViewManager = new ViewManager( this, viewSpace );
1517 viewSpace->setStretchFactor( mViewManager, 1 ); 1517 viewSpace->setStretchFactor( mViewManager, 1 );
1518 1518
1519 mDetails = new ViewContainer( mDetailsSplitter ); 1519 mDetails = new ViewContainer( mDetailsSplitter );
1520 1520
1521 topLayout->addWidget( mDetailsSplitter ); 1521 topLayout->addWidget( mDetailsSplitter );
1522 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1522 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1523#else //KAB_NOSPLITTER 1523#else //KAB_NOSPLITTER
1524 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1524 QHBoxLayout *topLayout = new QHBoxLayout( this );
1525//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1525//US topLayout->setSpacing( KDialogBase::spacingHint() );
1526 topLayout->setSpacing( 10 ); 1526 topLayout->setSpacing( 10 );
1527 1527
1528// mDetailsSplitter = new QSplitter( this ); 1528// mDetailsSplitter = new QSplitter( this );
1529 1529
1530 QVBox *viewSpace = new QVBox( this ); 1530 QVBox *viewSpace = new QVBox( this );
1531 1531
1532 mViewManager = new ViewManager( this, viewSpace ); 1532 mViewManager = new ViewManager( this, viewSpace );
1533 viewSpace->setStretchFactor( mViewManager, 1 ); 1533 viewSpace->setStretchFactor( mViewManager, 1 );
1534 1534
1535 mDetails = new ViewContainer( this ); 1535 mDetails = new ViewContainer( this );
1536 1536
1537 topLayout->addWidget( viewSpace ); 1537 topLayout->addWidget( viewSpace );
1538// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1538// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1539 topLayout->addWidget( mDetails ); 1539 topLayout->addWidget( mDetails );
1540#endif //KAB_NOSPLITTER 1540#endif //KAB_NOSPLITTER
1541*/ 1541*/
1542 1542
1543 1543
1544#endif //KAB_EMBEDDED 1544#endif //KAB_EMBEDDED
1545 initActions(); 1545 initActions();
1546 1546
1547#ifdef KAB_EMBEDDED 1547#ifdef KAB_EMBEDDED
1548 addActionsManually(); 1548 addActionsManually();
1549 //US make sure the export and import menues are initialized before creating the xxPortManager. 1549 //US make sure the export and import menues are initialized before creating the xxPortManager.
1550 mXXPortManager = new XXPortManager( this, this ); 1550 mXXPortManager = new XXPortManager( this, this );
1551 1551
1552 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1552 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1553 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1553 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1554 // mActionQuit->plug ( mMainWindow->toolBar()); 1554 // mActionQuit->plug ( mMainWindow->toolBar());
1555 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1555 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1556 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1556 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1557 // mIncSearchWidget->hide(); 1557 // mIncSearchWidget->hide();
1558 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1558 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1559 SLOT( incrementalSearch( const QString& ) ) ); 1559 SLOT( incrementalSearch( const QString& ) ) );
1560 1560
1561 1561
1562 mJumpButtonBar = new JumpButtonBar( this, this ); 1562 mJumpButtonBar = new JumpButtonBar( this, this );
1563 1563
1564 topLayout->addWidget( mJumpButtonBar ); 1564 topLayout->addWidget( mJumpButtonBar );
1565//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1565//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1566 1566
1567// mMainWindow->getIconToolBar()->raise(); 1567// mMainWindow->getIconToolBar()->raise();
1568 1568
1569#endif //KAB_EMBEDDED 1569#endif //KAB_EMBEDDED
1570 1570
1571} 1571}
1572void KABCore::initActions() 1572void KABCore::initActions()
1573{ 1573{
1574//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1574//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1575 1575
1576#ifndef KAB_EMBEDDED 1576#ifndef KAB_EMBEDDED
1577 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1577 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1578 SLOT( clipboardDataChanged() ) ); 1578 SLOT( clipboardDataChanged() ) );
1579#endif //KAB_EMBEDDED 1579#endif //KAB_EMBEDDED
1580 1580
1581 // file menu 1581 // file menu
1582 if ( mIsPart ) { 1582 if ( mIsPart ) {
1583 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1583 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1584 SLOT( sendMail() ), actionCollection(), 1584 SLOT( sendMail() ), actionCollection(),
1585 "kaddressbook_mail" ); 1585 "kaddressbook_mail" );
1586 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1586 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1587 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1587 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1588 1588
1589 } else { 1589 } else {
1590 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1590 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1591 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1591 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1592 } 1592 }
1593 1593
1594 1594
1595 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1595 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1596 SLOT( save() ), actionCollection(), "file_sync" ); 1596 SLOT( save() ), actionCollection(), "file_sync" );
1597 1597
1598 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1598 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1599 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1599 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1600 1600
1601 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1601 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1602 this, SLOT( mailVCard() ), 1602 this, SLOT( mailVCard() ),
1603 actionCollection(), "file_mail_vcard"); 1603 actionCollection(), "file_mail_vcard");
1604 1604
1605 mActionBeamVCard = 0; 1605 mActionBeamVCard = 0;
1606 mActionBeam = 0; 1606 mActionBeam = 0;
1607 1607
1608#ifndef DESKTOP_VERSION 1608#ifndef DESKTOP_VERSION
1609 if ( Ir::supported() ) { 1609 if ( Ir::supported() ) {
1610 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1610 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1611 SLOT( beamVCard() ), actionCollection(), 1611 SLOT( beamVCard() ), actionCollection(),
1612 "kaddressbook_beam_vcard" ); 1612 "kaddressbook_beam_vcard" );
1613 1613
1614 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1614 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1615 SLOT( beamMySelf() ), actionCollection(), 1615 SLOT( beamMySelf() ), actionCollection(),
1616 "kaddressbook_beam_myself" ); 1616 "kaddressbook_beam_myself" );
1617 } 1617 }
1618#endif 1618#endif
1619 1619
1620 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1620 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1621 this, SLOT( editContact2() ), 1621 this, SLOT( editContact2() ),
1622 actionCollection(), "file_properties" ); 1622 actionCollection(), "file_properties" );
1623 1623
1624#ifdef KAB_EMBEDDED 1624#ifdef KAB_EMBEDDED
1625 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1625 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1626 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1626 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1627 mMainWindow, SLOT( exit() ), 1627 mMainWindow, SLOT( exit() ),
1628 actionCollection(), "quit" ); 1628 actionCollection(), "quit" );
1629#endif //KAB_EMBEDDED 1629#endif //KAB_EMBEDDED
1630 1630
1631 // edit menu 1631 // edit menu
1632 if ( mIsPart ) { 1632 if ( mIsPart ) {
1633 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1633 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1634 SLOT( copyContacts() ), actionCollection(), 1634 SLOT( copyContacts() ), actionCollection(),
1635 "kaddressbook_copy" ); 1635 "kaddressbook_copy" );
1636 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1636 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1637 SLOT( cutContacts() ), actionCollection(), 1637 SLOT( cutContacts() ), actionCollection(),
1638 "kaddressbook_cut" ); 1638 "kaddressbook_cut" );
1639 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1639 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1640 SLOT( pasteContacts() ), actionCollection(), 1640 SLOT( pasteContacts() ), actionCollection(),
1641 "kaddressbook_paste" ); 1641 "kaddressbook_paste" );
1642 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1642 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1643 SLOT( selectAllContacts() ), actionCollection(), 1643 SLOT( selectAllContacts() ), actionCollection(),
1644 "kaddressbook_select_all" ); 1644 "kaddressbook_select_all" );
1645 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1645 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1646 SLOT( undo() ), actionCollection(), 1646 SLOT( undo() ), actionCollection(),
1647 "kaddressbook_undo" ); 1647 "kaddressbook_undo" );
1648 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1648 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1649 this, SLOT( redo() ), actionCollection(), 1649 this, SLOT( redo() ), actionCollection(),
1650 "kaddressbook_redo" ); 1650 "kaddressbook_redo" );
1651 } else { 1651 } else {
1652 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1652 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1653 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1653 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1654 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1654 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1655 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1655 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1656 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1656 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1657 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1657 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1658 } 1658 }
1659 1659
1660 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1660 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1661 Key_Delete, this, SLOT( deleteContacts() ), 1661 Key_Delete, this, SLOT( deleteContacts() ),
1662 actionCollection(), "edit_delete" ); 1662 actionCollection(), "edit_delete" );
1663 1663
1664 mActionUndo->setEnabled( false ); 1664 mActionUndo->setEnabled( false );
1665 mActionRedo->setEnabled( false ); 1665 mActionRedo->setEnabled( false );
1666 1666
1667 // settings menu 1667 // settings menu
1668#ifdef KAB_EMBEDDED 1668#ifdef KAB_EMBEDDED
1669//US special menuentry to configure the addressbook resources. On KDE 1669//US special menuentry to configure the addressbook resources. On KDE
1670// you do that through the control center !!! 1670// you do that through the control center !!!
1671 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1671 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1672 SLOT( configureResources() ), actionCollection(), 1672 SLOT( configureResources() ), actionCollection(),
1673 "kaddressbook_configure_resources" ); 1673 "kaddressbook_configure_resources" );
1674#endif //KAB_EMBEDDED 1674#endif //KAB_EMBEDDED
1675 1675
1676 if ( mIsPart ) { 1676 if ( mIsPart ) {
1677 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1677 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1678 SLOT( openConfigDialog() ), actionCollection(), 1678 SLOT( openConfigDialog() ), actionCollection(),
1679 "kaddressbook_configure" ); 1679 "kaddressbook_configure" );
1680 1680
1681 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1681 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1682 this, SLOT( configureKeyBindings() ), actionCollection(), 1682 this, SLOT( configureKeyBindings() ), actionCollection(),
1683 "kaddressbook_configure_shortcuts" ); 1683 "kaddressbook_configure_shortcuts" );
1684#ifdef KAB_EMBEDDED 1684#ifdef KAB_EMBEDDED
1685 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1685 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1686 mActionConfigureToolbars->setEnabled( false ); 1686 mActionConfigureToolbars->setEnabled( false );
1687#endif //KAB_EMBEDDED 1687#endif //KAB_EMBEDDED
1688 1688
1689 } else { 1689 } else {
1690 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1690 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1691 1691
1692 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1692 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1693 } 1693 }
1694 1694
1695 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1695 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1696 actionCollection(), "options_show_jump_bar" ); 1696 actionCollection(), "options_show_jump_bar" );
1697 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1697 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1698 1698
1699 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1699 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1700 actionCollection(), "options_show_details" ); 1700 actionCollection(), "options_show_details" );
1701 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1701 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1702 1702
1703 // misc 1703 // misc
1704 // only enable LDAP lookup if we can handle the protocol 1704 // only enable LDAP lookup if we can handle the protocol
1705#ifndef KAB_EMBEDDED 1705#ifndef KAB_EMBEDDED
1706 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1706 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1707 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1707 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1708 this, SLOT( openLDAPDialog() ), actionCollection(), 1708 this, SLOT( openLDAPDialog() ), actionCollection(),
1709 "ldap_lookup" ); 1709 "ldap_lookup" );
1710 } 1710 }
1711#else //KAB_EMBEDDED 1711#else //KAB_EMBEDDED
1712 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1712 //qDebug("KABCore::initActions() LDAP has to be implemented");
1713#endif //KAB_EMBEDDED 1713#endif //KAB_EMBEDDED
1714 1714
1715 1715
1716 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1716 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1717 SLOT( setWhoAmI() ), actionCollection(), 1717 SLOT( setWhoAmI() ), actionCollection(),
1718 "set_personal" ); 1718 "set_personal" );
1719 1719
1720 1720
1721 1721
1722 1722
1723 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1723 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1724 SLOT( setCategories() ), actionCollection(), 1724 SLOT( setCategories() ), actionCollection(),
1725 "edit_set_categories" ); 1725 "edit_set_categories" );
1726 1726
1727 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1727 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1728 SLOT( removeVoice() ), actionCollection(), 1728 SLOT( removeVoice() ), actionCollection(),
1729 "remove_voice" ); 1729 "remove_voice" );
1730 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1730 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1731 SLOT( importFromOL() ), actionCollection(), 1731 SLOT( importFromOL() ), actionCollection(),
1732 "import_OL" ); 1732 "import_OL" );
1733#ifdef KAB_EMBEDDED 1733#ifdef KAB_EMBEDDED
1734 mActionLicence = new KAction( i18n( "Licence" ), 0, 1734 mActionLicence = new KAction( i18n( "Licence" ), 0,
1735 this, SLOT( showLicence() ), actionCollection(), 1735 this, SLOT( showLicence() ), actionCollection(),
1736 "licence_about_data" ); 1736 "licence_about_data" );
1737 mActionFaq = new KAction( i18n( "Faq" ), 0, 1737 mActionFaq = new KAction( i18n( "Faq" ), 0,
1738 this, SLOT( faq() ), actionCollection(), 1738 this, SLOT( faq() ), actionCollection(),
1739 "faq_about_data" ); 1739 "faq_about_data" );
1740 1740
1741 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1741 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1742 this, SLOT( createAboutData() ), actionCollection(), 1742 this, SLOT( createAboutData() ), actionCollection(),
1743 "kaddressbook_about_data" ); 1743 "kaddressbook_about_data" );
1744#endif //KAB_EMBEDDED 1744#endif //KAB_EMBEDDED
1745 1745
1746 clipboardDataChanged(); 1746 clipboardDataChanged();
1747 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1747 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1748 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1748 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1749} 1749}
1750 1750
1751//US we need this function, to plug all actions into the correct menues. 1751//US we need this function, to plug all actions into the correct menues.
1752// KDE uses a XML format to plug the actions, but we work her without this overhead. 1752// KDE uses a XML format to plug the actions, but we work her without this overhead.
1753void KABCore::addActionsManually() 1753void KABCore::addActionsManually()
1754{ 1754{
1755//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1755//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1756 1756
1757#ifdef KAB_EMBEDDED 1757#ifdef KAB_EMBEDDED
1758 QPopupMenu *fileMenu = new QPopupMenu( this ); 1758 QPopupMenu *fileMenu = new QPopupMenu( this );
1759 QPopupMenu *editMenu = new QPopupMenu( this ); 1759 QPopupMenu *editMenu = new QPopupMenu( this );
1760 QPopupMenu *helpMenu = new QPopupMenu( this ); 1760 QPopupMenu *helpMenu = new QPopupMenu( this );
1761 1761
1762 KToolBar* tb = mMainWindow->toolBar(); 1762 KToolBar* tb = mMainWindow->toolBar();
1763 1763
1764#ifdef DESKTOP_VERSION 1764#ifdef DESKTOP_VERSION
1765 QMenuBar* mb = mMainWindow->menuBar(); 1765 QMenuBar* mb = mMainWindow->menuBar();
1766 1766
1767 //US setup menubar. 1767 //US setup menubar.
1768 //Disable the following block if you do not want to have a menubar. 1768 //Disable the following block if you do not want to have a menubar.
1769 mb->insertItem( "&File", fileMenu ); 1769 mb->insertItem( "&File", fileMenu );
1770 mb->insertItem( "&Edit", editMenu ); 1770 mb->insertItem( "&Edit", editMenu );
1771 mb->insertItem( "&View", viewMenu ); 1771 mb->insertItem( "&View", viewMenu );
1772 mb->insertItem( "&Settings", settingsMenu ); 1772 mb->insertItem( "&Settings", settingsMenu );
1773 mb->insertItem( i18n("Synchronize"), syncMenu ); 1773 mb->insertItem( i18n("Synchronize"), syncMenu );
1774 mb->insertItem( "&Change selected", changeMenu ); 1774 mb->insertItem( "&Change selected", changeMenu );
1775 mb->insertItem( "&Help", helpMenu ); 1775 mb->insertItem( "&Help", helpMenu );
1776 mIncSearchWidget = new IncSearchWidget( tb ); 1776 mIncSearchWidget = new IncSearchWidget( tb );
1777 // tb->insertWidget(-1, 0, mIncSearchWidget); 1777 // tb->insertWidget(-1, 0, mIncSearchWidget);
1778 1778
1779#else 1779#else
1780 //US setup toolbar 1780 //US setup toolbar
1781 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1781 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1782 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1782 QPopupMenu *popupBarTB = new QPopupMenu( this );
1783 menuBarTB->insertItem( "ME", popupBarTB); 1783 menuBarTB->insertItem( "ME", popupBarTB);
1784 tb->insertWidget(-1, 0, menuBarTB); 1784 tb->insertWidget(-1, 0, menuBarTB);
1785 mIncSearchWidget = new IncSearchWidget( tb ); 1785 mIncSearchWidget = new IncSearchWidget( tb );
1786 1786
1787 tb->enableMoving(false); 1787 tb->enableMoving(false);
1788 popupBarTB->insertItem( "&File", fileMenu ); 1788 popupBarTB->insertItem( "&File", fileMenu );
1789 popupBarTB->insertItem( "&Edit", editMenu ); 1789 popupBarTB->insertItem( "&Edit", editMenu );
1790 popupBarTB->insertItem( "&View", viewMenu ); 1790 popupBarTB->insertItem( "&View", viewMenu );
1791 popupBarTB->insertItem( "&Settings", settingsMenu ); 1791 popupBarTB->insertItem( "&Settings", settingsMenu );
1792 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1792 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1793 mViewManager->getFilterAction()->plug ( popupBarTB); 1793 mViewManager->getFilterAction()->plug ( popupBarTB);
1794 popupBarTB->insertItem( "&Change selected", changeMenu ); 1794 popupBarTB->insertItem( "&Change selected", changeMenu );
1795 popupBarTB->insertItem( "&Help", helpMenu ); 1795 popupBarTB->insertItem( "&Help", helpMenu );
1796 if (QApplication::desktop()->width() > 320 ) { 1796 if (QApplication::desktop()->width() > 320 ) {
1797 // mViewManager->getFilterAction()->plug ( tb); 1797 // mViewManager->getFilterAction()->plug ( tb);
1798 } 1798 }
1799#endif 1799#endif
1800 // mActionQuit->plug ( mMainWindow->toolBar()); 1800 // mActionQuit->plug ( mMainWindow->toolBar());
1801 1801
1802 1802
1803 1803
1804 //US Now connect the actions with the menue entries. 1804 //US Now connect the actions with the menue entries.
1805 mActionPrint->plug( fileMenu ); 1805 mActionPrint->plug( fileMenu );
1806 mActionMail->plug( fileMenu ); 1806 mActionMail->plug( fileMenu );
1807 fileMenu->insertSeparator(); 1807 fileMenu->insertSeparator();
1808 1808
1809 mActionNewContact->plug( fileMenu ); 1809 mActionNewContact->plug( fileMenu );
1810 mActionNewContact->plug( tb ); 1810 mActionNewContact->plug( tb );
1811 1811
1812 mActionEditAddressee->plug( fileMenu ); 1812 mActionEditAddressee->plug( fileMenu );
1813 if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1813 if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1814 (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1814 (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1815 mActionEditAddressee->plug( tb ); 1815 mActionEditAddressee->plug( tb );
1816 1816
1817 fileMenu->insertSeparator(); 1817 fileMenu->insertSeparator();
1818 mActionSave->plug( fileMenu ); 1818 mActionSave->plug( fileMenu );
1819 fileMenu->insertItem( "&Import", ImportMenu ); 1819 fileMenu->insertItem( "&Import", ImportMenu );
1820 fileMenu->insertItem( "&Export", ExportMenu ); 1820 fileMenu->insertItem( "&Export", ExportMenu );
1821 fileMenu->insertSeparator(); 1821 fileMenu->insertSeparator();
1822 mActionMailVCard->plug( fileMenu ); 1822 mActionMailVCard->plug( fileMenu );
1823#ifndef DESKTOP_VERSION 1823#ifndef DESKTOP_VERSION
1824 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1824 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
1825 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 1825 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
1826#endif 1826#endif
1827 fileMenu->insertSeparator(); 1827 fileMenu->insertSeparator();
1828 mActionQuit->plug( fileMenu ); 1828 mActionQuit->plug( fileMenu );
1829#ifdef _WIN32_ 1829#ifdef _WIN32_
1830 mActionImportOL->plug( ImportMenu ); 1830 mActionImportOL->plug( ImportMenu );
1831#endif 1831#endif
1832 // edit menu 1832 // edit menu
1833 mActionUndo->plug( editMenu ); 1833 mActionUndo->plug( editMenu );
1834 mActionRedo->plug( editMenu ); 1834 mActionRedo->plug( editMenu );
1835 editMenu->insertSeparator(); 1835 editMenu->insertSeparator();
1836 mActionCut->plug( editMenu ); 1836 mActionCut->plug( editMenu );
1837 mActionCopy->plug( editMenu ); 1837 mActionCopy->plug( editMenu );
1838 mActionPaste->plug( editMenu ); 1838 mActionPaste->plug( editMenu );
1839 mActionDelete->plug( editMenu ); 1839 mActionDelete->plug( editMenu );
1840 editMenu->insertSeparator(); 1840 editMenu->insertSeparator();
1841 mActionSelectAll->plug( editMenu ); 1841 mActionSelectAll->plug( editMenu );
1842 1842
1843 mActionRemoveVoice->plug( changeMenu ); 1843 mActionRemoveVoice->plug( changeMenu );
1844 // settings menu 1844 // settings menu
1845//US special menuentry to configure the addressbook resources. On KDE 1845//US special menuentry to configure the addressbook resources. On KDE
1846// you do that through the control center !!! 1846// you do that through the control center !!!
1847 mActionConfigResources->plug( settingsMenu ); 1847 mActionConfigResources->plug( settingsMenu );
1848 settingsMenu->insertSeparator(); 1848 settingsMenu->insertSeparator();
1849 1849
1850 mActionConfigKAddressbook->plug( settingsMenu ); 1850 mActionConfigKAddressbook->plug( settingsMenu );
1851 1851
1852 if ( mIsPart ) { 1852 if ( mIsPart ) {
1853 mActionConfigShortcuts->plug( settingsMenu ); 1853 mActionConfigShortcuts->plug( settingsMenu );
1854 mActionConfigureToolbars->plug( settingsMenu ); 1854 mActionConfigureToolbars->plug( settingsMenu );
1855 1855
1856 } else { 1856 } else {
1857 mActionKeyBindings->plug( settingsMenu ); 1857 mActionKeyBindings->plug( settingsMenu );
1858 } 1858 }
1859 1859
1860 settingsMenu->insertSeparator(); 1860 settingsMenu->insertSeparator();
1861 1861
1862 mActionJumpBar->plug( settingsMenu ); 1862 mActionJumpBar->plug( settingsMenu );
1863 mActionDetails->plug( settingsMenu ); 1863 mActionDetails->plug( settingsMenu );
1864 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 1864 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
1865 mActionDetails->plug( tb ); 1865 mActionDetails->plug( tb );
1866 settingsMenu->insertSeparator(); 1866 settingsMenu->insertSeparator();
1867 1867
1868 mActionWhoAmI->plug( settingsMenu ); 1868 mActionWhoAmI->plug( settingsMenu );
1869 mActionCategories->plug( settingsMenu ); 1869 mActionCategories->plug( settingsMenu );
1870 1870
1871 mActionLicence->plug( helpMenu ); 1871 mActionLicence->plug( helpMenu );
1872 mActionFaq->plug( helpMenu ); 1872 mActionFaq->plug( helpMenu );
1873 mActionAboutKAddressbook->plug( helpMenu ); 1873 mActionAboutKAddressbook->plug( helpMenu );
1874 1874
1875 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 1875 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
1876 1876
1877 mActionSave->plug( tb ); 1877 mActionSave->plug( tb );
1878 mViewManager->getFilterAction()->plug ( tb); 1878 mViewManager->getFilterAction()->plug ( tb);
1879 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 1879 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
1880 mActionUndo->plug( tb ); 1880 mActionUndo->plug( tb );
1881 mActionDelete->plug( tb ); 1881 mActionDelete->plug( tb );
1882 mActionRedo->plug( tb ); 1882 mActionRedo->plug( tb );
1883 } 1883 }
1884 } 1884 }
1885 //mActionQuit->plug ( tb ); 1885 //mActionQuit->plug ( tb );
1886 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 1886 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
1887 1887
1888 //US link the searchwidget first to this. 1888 //US link the searchwidget first to this.
1889 // The real linkage to the toolbar happens later. 1889 // The real linkage to the toolbar happens later.
1890//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 1890//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
1891//US tb->insertItem( mIncSearchWidget ); 1891//US tb->insertItem( mIncSearchWidget );
1892/*US 1892/*US
1893 mIncSearchWidget = new IncSearchWidget( tb ); 1893 mIncSearchWidget = new IncSearchWidget( tb );
1894 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1894 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1895 SLOT( incrementalSearch( const QString& ) ) ); 1895 SLOT( incrementalSearch( const QString& ) ) );
1896 1896
1897 mJumpButtonBar = new JumpButtonBar( this, this ); 1897 mJumpButtonBar = new JumpButtonBar( this, this );
1898 1898
1899//US topLayout->addWidget( mJumpButtonBar ); 1899//US topLayout->addWidget( mJumpButtonBar );
1900 this->layout()->add( mJumpButtonBar ); 1900 this->layout()->add( mJumpButtonBar );
1901*/ 1901*/
1902 1902
1903#endif //KAB_EMBEDDED 1903#endif //KAB_EMBEDDED
1904 1904
1905 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); 1905 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) );
1906 fillSyncMenu(); 1906 fillSyncMenu();
1907 1907
1908} 1908}
1909void KABCore::showLicence() 1909void KABCore::showLicence()
1910{ 1910{
1911 KApplication::showLicence(); 1911 KApplication::showLicence();
1912} 1912}
1913void KABCore::removeVoice() 1913void KABCore::removeVoice()
1914{ 1914{
1915 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) 1915 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No )
1916 return; 1916 return;
1917 KABC::Addressee::List list = mViewManager->selectedAddressees(); 1917 KABC::Addressee::List list = mViewManager->selectedAddressees();
1918 KABC::Addressee::List::Iterator it; 1918 KABC::Addressee::List::Iterator it;
1919 for ( it = list.begin(); it != list.end(); ++it ) { 1919 for ( it = list.begin(); it != list.end(); ++it ) {
1920 PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); 1920 PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
1921 PhoneNumber::List::Iterator phoneIt; 1921 PhoneNumber::List::Iterator phoneIt;
1922 bool found = false; 1922 bool found = false;
1923 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { 1923 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
1924 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 1924 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
1925 if ((*phoneIt).type() - PhoneNumber::Voice ) { 1925 if ((*phoneIt).type() - PhoneNumber::Voice ) {
1926 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 1926 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
1927 (*it).insertPhoneNumber( (*phoneIt) ); 1927 (*it).insertPhoneNumber( (*phoneIt) );
1928 found = true; 1928 found = true;
1929 } 1929 }
1930 } 1930 }
1931 1931
1932 } 1932 }
1933 if ( found ) 1933 if ( found )
1934 contactModified((*it) ); 1934 contactModified((*it) );
1935 } 1935 }
1936} 1936}
1937 1937
1938 1938
1939 1939
1940void KABCore::clipboardDataChanged() 1940void KABCore::clipboardDataChanged()
1941{ 1941{
1942 1942
1943 if ( mReadWrite ) 1943 if ( mReadWrite )
1944 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 1944 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
1945 1945
1946} 1946}
1947 1947
1948void KABCore::updateActionMenu() 1948void KABCore::updateActionMenu()
1949{ 1949{
1950 UndoStack *undo = UndoStack::instance(); 1950 UndoStack *undo = UndoStack::instance();
1951 RedoStack *redo = RedoStack::instance(); 1951 RedoStack *redo = RedoStack::instance();
1952 1952
1953 if ( undo->isEmpty() ) 1953 if ( undo->isEmpty() )
1954 mActionUndo->setText( i18n( "Undo" ) ); 1954 mActionUndo->setText( i18n( "Undo" ) );
1955 else 1955 else
1956 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 1956 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
1957 1957
1958 mActionUndo->setEnabled( !undo->isEmpty() ); 1958 mActionUndo->setEnabled( !undo->isEmpty() );
1959 1959
1960 if ( !redo->top() ) 1960 if ( !redo->top() )
1961 mActionRedo->setText( i18n( "Redo" ) ); 1961 mActionRedo->setText( i18n( "Redo" ) );
1962 else 1962 else
1963 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 1963 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
1964 1964
1965 mActionRedo->setEnabled( !redo->isEmpty() ); 1965 mActionRedo->setEnabled( !redo->isEmpty() );
1966} 1966}
1967 1967
1968void KABCore::configureKeyBindings() 1968void KABCore::configureKeyBindings()
1969{ 1969{
1970#ifndef KAB_EMBEDDED 1970#ifndef KAB_EMBEDDED
1971 KKeyDialog::configure( actionCollection(), true ); 1971 KKeyDialog::configure( actionCollection(), true );
1972#else //KAB_EMBEDDED 1972#else //KAB_EMBEDDED
1973 qDebug("KABCore::configureKeyBindings() not implemented"); 1973 qDebug("KABCore::configureKeyBindings() not implemented");
1974#endif //KAB_EMBEDDED 1974#endif //KAB_EMBEDDED
1975} 1975}
1976 1976
1977#ifdef KAB_EMBEDDED 1977#ifdef KAB_EMBEDDED
1978void KABCore::configureResources() 1978void KABCore::configureResources()
1979{ 1979{
1980 KRES::KCMKResources dlg( this, "" , 0 ); 1980 KRES::KCMKResources dlg( this, "" , 0 );
1981 1981
1982 if ( !dlg.exec() ) 1982 if ( !dlg.exec() )
1983 return; 1983 return;
1984 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 1984 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
1985} 1985}
1986#endif //KAB_EMBEDDED 1986#endif //KAB_EMBEDDED
1987 1987
1988 1988
1989/* this method will be called through the QCop interface from Ko/Pi to select addresses 1989/* this method will be called through the QCop interface from Ko/Pi to select addresses
1990 * for the attendees list of an event. 1990 * for the attendees list of an event.
1991 */ 1991 */
1992void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 1992void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
1993{ 1993{
1994 QStringList nameList; 1994 QStringList nameList;
1995 QStringList emailList; 1995 QStringList emailList;
1996 QStringList uidList; 1996 QStringList uidList;
1997 1997
1998 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 1998 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
1999 uint i=0; 1999 uint i=0;
2000 for (i=0; i < list.count(); i++) 2000 for (i=0; i < list.count(); i++)
2001 { 2001 {
2002 nameList.append(list[i].realName()); 2002 nameList.append(list[i].realName());
2003 emailList.append(list[i].preferredEmail()); 2003 emailList.append(list[i].preferredEmail());
2004 uidList.append(list[i].uid()); 2004 uidList.append(list[i].uid());
2005 } 2005 }
2006 2006
2007 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2007 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2008 2008
2009} 2009}
2010 2010
2011/* this method will be called through the QCop interface from other apps to show details of a contact. 2011/* this method will be called through the QCop interface from other apps to show details of a contact.
2012 */ 2012 */
2013void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2013void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2014{ 2014{
2015 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2015 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2016 2016
2017 QString foundUid = QString::null; 2017 QString foundUid = QString::null;
2018 if ( ! uid.isEmpty() ) { 2018 if ( ! uid.isEmpty() ) {
2019 Addressee adrr = mAddressBook->findByUid( uid ); 2019 Addressee adrr = mAddressBook->findByUid( uid );
2020 if ( !adrr.isEmpty() ) { 2020 if ( !adrr.isEmpty() ) {
2021 foundUid = uid; 2021 foundUid = uid;
2022 } 2022 }
2023 if ( email == "sendbacklist" ) { 2023 if ( email == "sendbacklist" ) {
2024 //qDebug("ssssssssssssssssssssssend "); 2024 //qDebug("ssssssssssssssssssssssend ");
2025 QStringList nameList; 2025 QStringList nameList;
2026 QStringList emailList; 2026 QStringList emailList;
2027 QStringList uidList; 2027 QStringList uidList;
2028 nameList.append(adrr.realName()); 2028 nameList.append(adrr.realName());
2029 emailList = adrr.emails(); 2029 emailList = adrr.emails();
2030 uidList.append( adrr.preferredEmail()); 2030 uidList.append( adrr.preferredEmail());
2031 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2031 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2032 return; 2032 return;
2033 } 2033 }
2034 2034
2035 } 2035 }
2036 2036
2037 if ( email == "sendbacklist" ) 2037 if ( email == "sendbacklist" )
2038 return; 2038 return;
2039 if (foundUid.isEmpty()) 2039 if (foundUid.isEmpty())
2040 { 2040 {
2041 //find the uid of the person first 2041 //find the uid of the person first
2042 Addressee::List namelist; 2042 Addressee::List namelist;
2043 Addressee::List emaillist; 2043 Addressee::List emaillist;
2044 2044
2045 if (!name.isEmpty()) 2045 if (!name.isEmpty())
2046 namelist = mAddressBook->findByName( name ); 2046 namelist = mAddressBook->findByName( name );
2047 2047
2048 if (!email.isEmpty()) 2048 if (!email.isEmpty())
2049 emaillist = mAddressBook->findByEmail( email ); 2049 emaillist = mAddressBook->findByEmail( email );
2050 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2050 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2051 //check if we have a match in Namelist and Emaillist 2051 //check if we have a match in Namelist and Emaillist
2052 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2052 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2053 foundUid = emaillist[0].uid(); 2053 foundUid = emaillist[0].uid();
2054 } 2054 }
2055 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2055 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2056 foundUid = namelist[0].uid(); 2056 foundUid = namelist[0].uid();
2057 else 2057 else
2058 { 2058 {
2059 for (int i = 0; i < namelist.count(); i++) 2059 for (int i = 0; i < namelist.count(); i++)
2060 { 2060 {
2061 for (int j = 0; j < emaillist.count(); j++) 2061 for (int j = 0; j < emaillist.count(); j++)
2062 { 2062 {
2063 if (namelist[i] == emaillist[j]) 2063 if (namelist[i] == emaillist[j])
2064 { 2064 {
2065 foundUid = namelist[i].uid(); 2065 foundUid = namelist[i].uid();
2066 } 2066 }
2067 } 2067 }
2068 } 2068 }
2069 } 2069 }
2070 } 2070 }
2071 else 2071 else
2072 { 2072 {
2073 foundUid = uid; 2073 foundUid = uid;
2074 } 2074 }
2075 2075
2076 if (!foundUid.isEmpty()) 2076 if (!foundUid.isEmpty())
2077 { 2077 {
2078 2078
2079 // raise Ka/Pi if it is in the background 2079 // raise Ka/Pi if it is in the background
2080#ifndef DESKTOP_VERSION 2080#ifndef DESKTOP_VERSION
2081#ifndef KORG_NODCOP 2081#ifndef KORG_NODCOP
2082 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2082 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2083#endif 2083#endif
2084#endif 2084#endif
2085 2085
2086 mMainWindow->showMaximized(); 2086 mMainWindow->showMaximized();
2087 mMainWindow-> raise(); 2087 mMainWindow-> raise();
2088 2088
2089 mViewManager->setSelected( "", false); 2089 mViewManager->setSelected( "", false);
2090 mViewManager->refreshView( "" ); 2090 mViewManager->refreshView( "" );
2091 mViewManager->setSelected( foundUid, true ); 2091 mViewManager->setSelected( foundUid, true );
2092 mViewManager->refreshView( foundUid ); 2092 mViewManager->refreshView( foundUid );
2093 2093
2094 if ( !mMultipleViewsAtOnce ) 2094 if ( !mMultipleViewsAtOnce )
2095 { 2095 {
2096 setDetailsVisible( true ); 2096 setDetailsVisible( true );
2097 mActionDetails->setChecked(true); 2097 mActionDetails->setChecked(true);
2098 } 2098 }
2099 } 2099 }
2100} 2100}
2101 2101
2102 2102
2103void KABCore::faq() 2103void KABCore::faq()
2104{ 2104{
2105 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2105 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2106} 2106}
2107 2107
2108 2108
2109void KABCore::fillSyncMenu() 2109void KABCore::fillSyncMenu()
2110{ 2110{
2111 if ( syncMenu->count() ) 2111 if ( syncMenu->count() )
2112 syncMenu->clear(); 2112 syncMenu->clear();
2113 syncMenu->insertItem( i18n("Configure..."), 0 ); 2113 syncMenu->insertItem( i18n("Configure..."), 0 );
2114 syncMenu->insertSeparator(); 2114 syncMenu->insertSeparator();
2115 syncMenu->insertItem( i18n("Multiple sync"), 1 ); 2115 syncMenu->insertItem( i18n("Multiple sync"), 1 );
2116 syncMenu->insertSeparator(); 2116 syncMenu->insertSeparator();
2117 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2117 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2118 config.setGroup("General"); 2118 config.setGroup("General");
2119 QStringList prof = config.readListEntry("SyncProfileNames"); 2119 QStringList prof = config.readListEntry("SyncProfileNames");
2120 KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 2120 KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
2121 if ( prof.count() < 3 ) { 2121 if ( prof.count() < 3 ) {
2122 prof.clear(); 2122 prof.clear();
2123 prof << i18n("Sharp_DTM"); 2123 prof << i18n("Sharp_DTM");
2124 prof << i18n("Local_file"); 2124 prof << i18n("Local_file");
2125 prof << i18n("Last_file"); 2125 prof << i18n("Last_file");
2126 KSyncProfile* temp = new KSyncProfile (); 2126 KSyncProfile* temp = new KSyncProfile ();
2127 temp->setName( prof[0] ); 2127 temp->setName( prof[0] );
2128 temp->writeConfig(&config); 2128 temp->writeConfig(&config);
2129 temp->setName( prof[1] ); 2129 temp->setName( prof[1] );
2130 temp->writeConfig(&config); 2130 temp->writeConfig(&config);
2131 temp->setName( prof[2] ); 2131 temp->setName( prof[2] );
2132 temp->writeConfig(&config); 2132 temp->writeConfig(&config);
2133 config.setGroup("General"); 2133 config.setGroup("General");
2134 config.writeEntry("SyncProfileNames",prof); 2134 config.writeEntry("SyncProfileNames",prof);
2135 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 2135 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
2136 config.sync(); 2136 config.sync();
2137 delete temp; 2137 delete temp;
2138 } 2138 }
2139 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 2139 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
2140 KABPrefs::instance()->mSyncProfileNames = prof; 2140 KABPrefs::instance()->mSyncProfileNames = prof;
2141 int i; 2141 int i;
2142 for ( i = 0; i < prof.count(); ++i ) { 2142 for ( i = 0; i < prof.count(); ++i ) {
2143 2143
2144 syncMenu->insertItem( prof[i], 1000+i ); 2144 syncMenu->insertItem( prof[i], 1000+i );
2145 if ( i == 2 ) 2145 if ( i == 2 )
2146 syncMenu->insertSeparator(); 2146 syncMenu->insertSeparator();
2147 } 2147 }
2148 QDir app_dir; 2148 QDir app_dir;
2149 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 2149 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
2150 syncMenu->setItemEnabled( false , 1000 ); 2150 syncMenu->setItemEnabled( false , 1000 );
2151 } 2151 }
2152 //probaly useless 2152 //probaly useless
2153 //mView->setupExternSyncProfiles(); 2153 //mView->setupExternSyncProfiles();
2154} 2154}
2155void KABCore::slotSyncMenu( int action ) 2155void KABCore::slotSyncMenu( int action )
2156{ 2156{
2157 //qDebug("syncaction %d ", action); 2157 //qDebug("syncaction %d ", action);
2158 if ( action == 0 ) { 2158 if ( action == 0 ) {
2159 2159
2160 // seems to be a Qt2 event handling bug 2160 // seems to be a Qt2 event handling bug
2161 // syncmenu.clear causes a segfault at first time 2161 // syncmenu.clear causes a segfault at first time
2162 // when we call it after the main event loop, it is ok 2162 // when we call it after the main event loop, it is ok
2163 // same behaviour when calling OM/Pi via QCOP for the first time 2163 // same behaviour when calling OM/Pi via QCOP for the first time
2164 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 2164 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
2165 //confSync(); 2165 //confSync();
2166 2166
2167 return; 2167 return;
2168 } 2168 }
2169 if ( action == 1 ) { 2169 if ( action == 1 ) {
2170 multiSync( true ); 2170 multiSync( true );
2171 return; 2171 return;
2172 } 2172 }
2173 2173
2174 if (mBlockSaveFlag) 2174 if (mBlockSaveFlag)
2175 return; 2175 return;
2176 mBlockSaveFlag = true; 2176 mBlockSaveFlag = true;
2177 mCurrentSyncProfile = action - 1000 ; 2177 mCurrentSyncProfile = action - 1000 ;
2178 mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; 2178 mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ;
2179 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; 2179 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ;
2180 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2180 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2181 KSyncProfile* temp = new KSyncProfile (); 2181 KSyncProfile* temp = new KSyncProfile ();
2182 temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2182 temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2183 temp->readConfig(&config); 2183 temp->readConfig(&config);
2184 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2184 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2185 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2185 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2186 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2186 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2187 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2187 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2188 KABPrefs::instance()->mWriteBackInFuture = 0; 2188 KABPrefs::instance()->mWriteBackInFuture = 0;
2189 if ( temp->getWriteBackFuture() ) 2189 if ( temp->getWriteBackFuture() )
2190 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2190 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2191 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2191 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2192 if ( action == 1000 ) { 2192 if ( action == 1000 ) {
2193 syncSharp(); 2193 syncSharp();
2194 2194
2195 } else if ( action == 1001 ) { 2195 } else if ( action == 1001 ) {
2196 syncLocalFile(); 2196 syncLocalFile();
2197 2197
2198 } else if ( action == 1002 ) { 2198 } else if ( action == 1002 ) {
2199 quickSyncLocalFile(); 2199 quickSyncLocalFile();
2200 2200
2201 } else if ( action >= 1003 ) { 2201 } else if ( action >= 1003 ) {
2202 if ( temp->getIsLocalFileSync() ) { 2202 if ( temp->getIsLocalFileSync() ) {
2203 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 2203 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
2204 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 2204 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
2205 } else { 2205 } else {
2206 if ( temp->getIsPhoneSync() ) { 2206 if ( temp->getIsPhoneSync() ) {
2207 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 2207 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2208 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 2208 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2209 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 2209 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2210 syncPhone(); 2210 syncPhone();
2211 } else 2211 } else
2212 syncRemote( temp ); 2212 syncRemote( temp );
2213 2213
2214 } 2214 }
2215 } 2215 }
2216 delete temp; 2216 delete temp;
2217 mBlockSaveFlag = false; 2217 mBlockSaveFlag = false;
2218} 2218}
2219 2219
2220void KABCore::syncLocalFile() 2220void KABCore::syncLocalFile()
2221{ 2221{
2222 2222
2223 QString fn =KABPrefs::instance()->mLastSyncedLocalFile; 2223 QString fn =KABPrefs::instance()->mLastSyncedLocalFile;
2224 2224
2225 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2225 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2226 if ( fn == "" ) 2226 if ( fn == "" )
2227 return; 2227 return;
2228 if ( syncWithFile( fn, false ) ) { 2228 if ( syncWithFile( fn, false ) ) {
2229 qDebug("syncLocalFile() successful "); 2229 qDebug("syncLocalFile() successful ");
2230 } 2230 }
2231 2231
2232} 2232}
2233bool KABCore::syncWithFile( QString fn , bool quick ) 2233bool KABCore::syncWithFile( QString fn , bool quick )
2234{ 2234{
2235 bool ret = false; 2235 bool ret = false;
2236 QFileInfo info; 2236 QFileInfo info;
2237 info.setFile( fn ); 2237 info.setFile( fn );
2238 QString mess; 2238 QString mess;
2239 bool loadbup = true; 2239 bool loadbup = true;
2240 if ( !info. exists() ) { 2240 if ( !info. exists() ) {
2241 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 2241 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2242 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2242 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2243 mess ); 2243 mess );
2244 return ret; 2244 return ret;
2245 } 2245 }
2246 int result = 0; 2246 int result = 0;
2247 if ( !quick ) { 2247 if ( !quick ) {
2248 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2248 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2249 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2249 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2250 mess, 2250 mess,
2251 i18n("Sync"), i18n("Cancel"), 0, 2251 i18n("Sync"), i18n("Cancel"), 0,
2252 0, 1 ); 2252 0, 1 );
2253 if ( result ) 2253 if ( result )
2254 return false; 2254 return false;
2255 } 2255 }
2256 if ( KABPrefs::instance()->mAskForPreferences ) 2256 if ( KABPrefs::instance()->mAskForPreferences )
2257 edit_sync_options(); 2257 edit_sync_options();
2258 if ( result == 0 ) { 2258 if ( result == 0 ) {
2259 //qDebug("Now sycing ... "); 2259 //qDebug("Now sycing ... ");
2260 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) 2260 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) )
2261 setCaption( i18n("Synchronization successful") ); 2261 setCaption( i18n("Synchronization successful") );
2262 else 2262 else
2263 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 2263 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2264 if ( ! quick ) 2264 if ( ! quick )
2265 KABPrefs::instance()->mLastSyncedLocalFile = fn; 2265 KABPrefs::instance()->mLastSyncedLocalFile = fn;
2266 setModified(); 2266 setModified();
2267 } 2267 }
2268 return ret; 2268 return ret;
2269} 2269}
2270void KABCore::quickSyncLocalFile() 2270void KABCore::quickSyncLocalFile()
2271{ 2271{
2272 2272
2273 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { 2273 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2274 qDebug("quick syncLocalFile() successful "); 2274 qDebug("quick syncLocalFile() successful ");
2275 2275
2276 } 2276 }
2277} 2277}
2278void KABCore::multiSync( bool askforPrefs ) 2278void KABCore::multiSync( bool askforPrefs )
2279{ 2279{
2280 if (mBlockSaveFlag) 2280 if (mBlockSaveFlag)
2281 return; 2281 return;
2282 mBlockSaveFlag = true; 2282 mBlockSaveFlag = true;
2283 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 2283 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
2284 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2284 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2285 question, 2285 question,
2286 i18n("Yes"), i18n("No"), 2286 i18n("Yes"), i18n("No"),
2287 0, 0 ) != 0 ) { 2287 0, 0 ) != 0 ) {
2288 mBlockSaveFlag = false; 2288 mBlockSaveFlag = false;
2289 setCaption(i18n("Aborted! Nothing synced!")); 2289 setCaption(i18n("Aborted! Nothing synced!"));
2290 return; 2290 return;
2291 } 2291 }
2292 mCurrentSyncDevice = i18n("Multiple profiles") ; 2292 mCurrentSyncDevice = i18n("Multiple profiles") ;
2293 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; 2293 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs;
2294 if ( askforPrefs ) { 2294 if ( askforPrefs ) {
2295 edit_sync_options(); 2295 edit_sync_options();
2296 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; 2296 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs;
2297 } 2297 }
2298 setCaption(i18n("Multiple sync started.") ); 2298 setCaption(i18n("Multiple sync started.") );
2299 qApp->processEvents(); 2299 qApp->processEvents();
2300 int num = ringSync() ; 2300 int num = ringSync() ;
2301 if ( num > 1 ) 2301 if ( num > 1 )
2302 ringSync(); 2302 ringSync();
2303 mBlockSaveFlag = false; 2303 mBlockSaveFlag = false;
2304 if ( num ) 2304 if ( num )
2305 save(); 2305 save();
2306 if ( num ) 2306 if ( num )
2307 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 2307 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
2308 else 2308 else
2309 setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 2309 setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
2310 return; 2310 return;
2311} 2311}
2312int KABCore::ringSync() 2312int KABCore::ringSync()
2313{ 2313{
2314 int syncedProfiles = 0; 2314 int syncedProfiles = 0;
2315 int i; 2315 int i;
2316 QTime timer; 2316 QTime timer;
2317 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2317 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2318 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; 2318 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames;
2319 KSyncProfile* temp = new KSyncProfile (); 2319 KSyncProfile* temp = new KSyncProfile ();
2320 KABPrefs::instance()->mAskForPreferences = false; 2320 KABPrefs::instance()->mAskForPreferences = false;
2321 for ( i = 0; i < syncProfileNames.count(); ++i ) { 2321 for ( i = 0; i < syncProfileNames.count(); ++i ) {
2322 mCurrentSyncProfile = i; 2322 mCurrentSyncProfile = i;
2323 temp->setName(syncProfileNames[mCurrentSyncProfile]); 2323 temp->setName(syncProfileNames[mCurrentSyncProfile]);
2324 temp->readConfig(&config); 2324 temp->readConfig(&config);
2325 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { 2325 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) {
2326 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 2326 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
2327 ++syncedProfiles; 2327 ++syncedProfiles;
2328 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2328 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2329 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2329 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2330 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2330 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2331 KABPrefs::instance()->mWriteBackInFuture = 0; 2331 KABPrefs::instance()->mWriteBackInFuture = 0;
2332 if ( temp->getWriteBackFuture() ) 2332 if ( temp->getWriteBackFuture() )
2333 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2333 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2334 KABPrefs::instance()->mShowSyncSummary = false; 2334 KABPrefs::instance()->mShowSyncSummary = false;
2335 mCurrentSyncDevice = syncProfileNames[i] ; 2335 mCurrentSyncDevice = syncProfileNames[i] ;
2336 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; 2336 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName;
2337 if ( i == 0 ) { 2337 if ( i == 0 ) {
2338 syncSharp(); 2338 syncSharp();
2339 } else { 2339 } else {
2340 if ( temp->getIsLocalFileSync() ) { 2340 if ( temp->getIsLocalFileSync() ) {
2341 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) 2341 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) )
2342 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 2342 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
2343 } else { 2343 } else {
2344 if ( temp->getIsPhoneSync() ) { 2344 if ( temp->getIsPhoneSync() ) {
2345 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 2345 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2346 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 2346 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2347 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 2347 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2348 syncPhone(); 2348 syncPhone();
2349 } else 2349 } else
2350 syncRemote( temp, false ); 2350 syncRemote( temp, false );
2351 2351
2352 } 2352 }
2353 } 2353 }
2354 timer.start(); 2354 timer.start();
2355 setCaption(i18n("Multiple sync in progress ... please wait!") ); 2355 setCaption(i18n("Multiple sync in progress ... please wait!") );
2356 while ( timer.elapsed () < 2000 ) { 2356 while ( timer.elapsed () < 2000 ) {
2357 qApp->processEvents(); 2357 qApp->processEvents();
2358#ifndef _WIN32_ 2358#ifndef _WIN32_
2359 sleep (1); 2359 sleep (1);
2360#endif 2360#endif
2361 } 2361 }
2362 2362
2363 } 2363 }
2364 2364
2365 } 2365 }
2366 delete temp; 2366 delete temp;
2367 return syncedProfiles; 2367 return syncedProfiles;
2368} 2368}
2369 2369
2370void KABCore::syncRemote( KSyncProfile* prof, bool ask) 2370void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2371{ 2371{
2372 QString question; 2372 QString question;
2373 if ( ask ) { 2373 if ( ask ) {
2374 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 2374 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2375 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2375 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2376 question, 2376 question,
2377 i18n("Yes"), i18n("No"), 2377 i18n("Yes"), i18n("No"),
2378 0, 0 ) != 0 ) 2378 0, 0 ) != 0 )
2379 return; 2379 return;
2380 } 2380 }
2381 QString command = prof->getPreSyncCommandAB(); 2381 QString command = prof->getPreSyncCommandAB();
2382 int fi; 2382 int fi;
2383 if ( (fi = command.find("$PWD$")) > 0 ) { 2383 if ( (fi = command.find("$PWD$")) > 0 ) {
2384 QString pwd = getPassword(); 2384 QString pwd = getPassword();
2385 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2385 command = command.left( fi )+ pwd + command.mid( fi+5 );
2386 2386
2387 } 2387 }
2388 int maxlen = 30; 2388 int maxlen = 30;
2389 if ( QApplication::desktop()->width() > 320 ) 2389 if ( QApplication::desktop()->width() > 320 )
2390 maxlen += 25; 2390 maxlen += 25;
2391 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2391 setCaption ( i18n( "Copy remote file to local machine..." ) );
2392 int fileSize = 0; 2392 int fileSize = 0;
2393 int result = system ( command ); 2393 int result = system ( command );
2394 // 0 : okay 2394 // 0 : okay
2395 // 256: no such file or dir 2395 // 256: no such file or dir
2396 // 2396 //
2397 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2397 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2398 if ( result != 0 ) { 2398 if ( result != 0 ) {
2399 int len = maxlen; 2399 int len = maxlen;
2400 while ( len < command.length() ) { 2400 while ( len < command.length() ) {
2401 command.insert( len , "\n" ); 2401 command.insert( len , "\n" );
2402 len += maxlen +2; 2402 len += maxlen +2;
2403 } 2403 }
2404 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2404 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2405 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2405 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2406 question, 2406 question,
2407 i18n("Okay!")) ; 2407 i18n("Okay!")) ;
2408 setCaption ("KO/Pi"); 2408 setCaption ("KO/Pi");
2409 return; 2409 return;
2410 } 2410 }
2411 setCaption ( i18n( "Copying succeed." ) ); 2411 setCaption ( i18n( "Copying succeed." ) );
2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
2414// Event* e = mView->getLastSyncEvent(); 2414// Event* e = mView->getLastSyncEvent();
2415// e->setReadOnly( false ); 2415// e->setReadOnly( false );
2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2417// e->setReadOnly( true ); 2417// e->setReadOnly( true );
2418 if ( KABPrefs::instance()->mWriteBackFile ) { 2418 if ( KABPrefs::instance()->mWriteBackFile ) {
2419 command = prof->getPostSyncCommandAB(); 2419 command = prof->getPostSyncCommandAB();
2420 int fi; 2420 int fi;
2421 if ( (fi = command.find("$PWD$")) > 0 ) { 2421 if ( (fi = command.find("$PWD$")) > 0 ) {
2422 QString pwd = getPassword(); 2422 QString pwd = getPassword();
2423 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2423 command = command.left( fi )+ pwd + command.mid( fi+5 );
2424 2424
2425 } 2425 }
2426 setCaption ( i18n( "Writing back file ..." ) ); 2426 setCaption ( i18n( "Writing back file ..." ) );
2427 result = system ( command ); 2427 result = system ( command );
2428 qDebug("KO: Writing back file result: %d ", result); 2428 qDebug("KO: Writing back file result: %d ", result);
2429 if ( result != 0 ) { 2429 if ( result != 0 ) {
2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2431 return; 2431 return;
2432 } else { 2432 } else {
2433 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2433 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2434 } 2434 }
2435 } 2435 }
2436 } 2436 }
2437 return; 2437 return;
2438} 2438}
2439#include <qpushbutton.h> 2439#include <qpushbutton.h>
2440#include <qradiobutton.h> 2440#include <qradiobutton.h>
2441#include <qbuttongroup.h> 2441#include <qbuttongroup.h>
2442void KABCore::edit_sync_options() 2442void KABCore::edit_sync_options()
2443{ 2443{
2444 //mDialogManager->showSyncOptions(); 2444 //mDialogManager->showSyncOptions();
2445 //KABPrefs::instance()->mSyncAlgoPrefs 2445 //KABPrefs::instance()->mSyncAlgoPrefs
2446 QDialog dia( this, "dia", true ); 2446 QDialog dia( this, "dia", true );
2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2449 QVBoxLayout lay ( &dia ); 2449 QVBoxLayout lay ( &dia );
2450 lay.setSpacing( 2 ); 2450 lay.setSpacing( 2 );
2451 lay.setMargin( 3 ); 2451 lay.setMargin( 3 );
2452 lay.addWidget(&gr); 2452 lay.addWidget(&gr);
2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2459 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2459 //QRadioButton both( i18n("Take both on conflict"), &gr );
2460 QPushButton pb ( "OK", &dia); 2460 QPushButton pb ( "OK", &dia);
2461 lay.addWidget( &pb ); 2461 lay.addWidget( &pb );
2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2464 case 0: 2464 case 0:
2465 loc.setChecked( true); 2465 loc.setChecked( true);
2466 break; 2466 break;
2467 case 1: 2467 case 1:
2468 rem.setChecked( true ); 2468 rem.setChecked( true );
2469 break; 2469 break;
2470 case 2: 2470 case 2:
2471 newest.setChecked( true); 2471 newest.setChecked( true);
2472 break; 2472 break;
2473 case 3: 2473 case 3:
2474 ask.setChecked( true); 2474 ask.setChecked( true);
2475 break; 2475 break;
2476 case 4: 2476 case 4:
2477 f_loc.setChecked( true); 2477 f_loc.setChecked( true);
2478 break; 2478 break;
2479 case 5: 2479 case 5:
2480 f_rem.setChecked( true); 2480 f_rem.setChecked( true);
2481 break; 2481 break;
2482 case 6: 2482 case 6:
2483 // both.setChecked( true); 2483 // both.setChecked( true);
2484 break; 2484 break;
2485 default: 2485 default:
2486 break; 2486 break;
2487 } 2487 }
2488 if ( dia.exec() ) { 2488 if ( dia.exec() ) {
2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2490 } 2490 }
2491 2491
2492 2492
2493} 2493}
2494QString KABCore::getPassword( ) 2494QString KABCore::getPassword( )
2495{ 2495{
2496 QString retfile = ""; 2496 QString retfile = "";
2497 QDialog dia ( this, "input-dialog", true ); 2497 QDialog dia ( this, "input-dialog", true );
2498 QLineEdit lab ( &dia ); 2498 QLineEdit lab ( &dia );
2499 lab.setEchoMode( QLineEdit::Password ); 2499 lab.setEchoMode( QLineEdit::Password );
2500 QVBoxLayout lay( &dia ); 2500 QVBoxLayout lay( &dia );
2501 lay.setMargin(7); 2501 lay.setMargin(7);
2502 lay.setSpacing(7); 2502 lay.setSpacing(7);
2503 lay.addWidget( &lab); 2503 lay.addWidget( &lab);
2504 dia.setFixedSize( 230,50 ); 2504 dia.setFixedSize( 230,50 );
2505 dia.setCaption( i18n("Enter password") ); 2505 dia.setCaption( i18n("Enter password") );
2506 QPushButton pb ( "OK", &dia); 2506 QPushButton pb ( "OK", &dia);
2507 lay.addWidget( &pb ); 2507 lay.addWidget( &pb );
2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2509 dia.show(); 2509 dia.show();
2510 int res = dia.exec(); 2510 int res = dia.exec();
2511 if ( res ) 2511 if ( res )
2512 retfile = lab.text(); 2512 retfile = lab.text();
2513 dia.hide(); 2513 dia.hide();
2514 qApp->processEvents(); 2514 qApp->processEvents();
2515 return retfile; 2515 return retfile;
2516 2516
2517} 2517}
2518#include <libkcal/syncdefines.h> 2518#include <libkcal/syncdefines.h>
2519 2519
2520KABC::Addressee KABCore::getLastSyncAddressee() 2520KABC::Addressee KABCore::getLastSyncAddressee()
2521{ 2521{
2522 Addressee lse; 2522 Addressee lse;
2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2525 if (lse.isEmpty()) { 2525 if (lse.isEmpty()) {
2526 qDebug("Creating new last-syncAddressee "); 2526 qDebug("Creating new last-syncAddressee ");
2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2527 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2528 QString sum = ""; 2528 QString sum = "";
2529 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 2529 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
2530 sum = "E: "; 2530 sum = "E: ";
2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2531 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2532 lse.setRevision( mLastAddressbookSync ); 2532 lse.setRevision( mLastAddressbookSync );
2533 lse.setCategories( i18n("SyncEvent") ); 2533 lse.setCategories( i18n("SyncEvent") );
2534 mAddressBook->insertAddressee( lse ); 2534 mAddressBook->insertAddressee( lse );
2535 } 2535 }
2536 return lse; 2536 return lse;
2537} 2537}
2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2538int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2539{ 2539{
2540 2540
2541 //void setZaurusId(int id); 2541 //void setZaurusId(int id);
2542 // int zaurusId() const; 2542 // int zaurusId() const;
2543 // void setZaurusUid(int id); 2543 // void setZaurusUid(int id);
2544 // int zaurusUid() const; 2544 // int zaurusUid() const;
2545 // void setZaurusStat(int id); 2545 // void setZaurusStat(int id);
2546 // int zaurusStat() const; 2546 // int zaurusStat() const;
2547 // 0 equal 2547 // 0 equal
2548 // 1 take local 2548 // 1 take local
2549 // 2 take remote 2549 // 2 take remote
2550 // 3 cancel 2550 // 3 cancel
2551 QDateTime lastSync = mLastAddressbookSync; 2551 QDateTime lastSync = mLastAddressbookSync;
2552 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2552 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2553 bool remCh, locCh; 2553 bool remCh, locCh;
2554 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2554 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2555 //if ( remCh ) 2555 //if ( remCh )
2556 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2556 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2557 locCh = ( local->revision() > mLastAddressbookSync ); 2557 locCh = ( local->revision() > mLastAddressbookSync );
2558 if ( !remCh && ! locCh ) { 2558 if ( !remCh && ! locCh ) {
2559 //qDebug("both not changed "); 2559 //qDebug("both not changed ");
2560 lastSync = local->revision().addDays(1); 2560 lastSync = local->revision().addDays(1);
2561 } else { 2561 } else {
2562 if ( locCh ) { 2562 if ( locCh ) {
2563 //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); 2563 //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1());
2564 lastSync = local->revision().addDays( -1 ); 2564 lastSync = local->revision().addDays( -1 );
2565 if ( !remCh ) 2565 if ( !remCh )
2566 remote->setRevision( lastSync.addDays( -1 ) ); 2566 remote->setRevision( lastSync.addDays( -1 ) );
2567 } else { 2567 } else {
2568 //qDebug(" not loc changed "); 2568 //qDebug(" not loc changed ");
2569 lastSync = local->revision().addDays( 1 ); 2569 lastSync = local->revision().addDays( 1 );
2570 if ( remCh ) 2570 if ( remCh )
2571 remote->setRevision( lastSync.addDays( 1 ) ); 2571 remote->setRevision( lastSync.addDays( 1 ) );
2572 2572
2573 } 2573 }
2574 } 2574 }
2575 full = true; 2575 full = true;
2576 if ( mode < SYNC_PREF_ASK ) 2576 if ( mode < SYNC_PREF_ASK )
2577 mode = SYNC_PREF_ASK; 2577 mode = SYNC_PREF_ASK;
2578 } else { 2578 } else {
2579 if ( local->revision() == remote->revision() ) 2579 if ( local->revision() == remote->revision() )
2580 return 0; 2580 return 0;
2581 2581
2582 } 2582 }
2583 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2583 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2584 2584
2585 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); 2585 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
2586 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2586 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2587 //full = true; //debug only 2587 //full = true; //debug only
2588 if ( full ) { 2588 if ( full ) {
2589 bool equ = ( (*local) == (*remote) ); 2589 bool equ = ( (*local) == (*remote) );
2590 if ( equ ) { 2590 if ( equ ) {
2591 //qDebug("equal "); 2591 //qDebug("equal ");
2592 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2592 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2593 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2593 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2594 } 2594 }
2595 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2595 if ( mode < SYNC_PREF_FORCE_LOCAL )
2596 return 0; 2596 return 0;
2597 2597
2598 }//else //debug only 2598 }//else //debug only
2599 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2599 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2600 } 2600 }
2601 int result; 2601 int result;
2602 bool localIsNew; 2602 bool localIsNew;
2603 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2603 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2604 2604
2605 if ( full && mode < SYNC_PREF_NEWEST ) 2605 if ( full && mode < SYNC_PREF_NEWEST )
2606 mode = SYNC_PREF_ASK; 2606 mode = SYNC_PREF_ASK;
2607 2607
2608 switch( mode ) { 2608 switch( mode ) {
2609 case SYNC_PREF_LOCAL: 2609 case SYNC_PREF_LOCAL:
2610 if ( lastSync > remote->revision() ) 2610 if ( lastSync > remote->revision() )
2611 return 1; 2611 return 1;
2612 if ( lastSync > local->revision() ) 2612 if ( lastSync > local->revision() )
2613 return 2; 2613 return 2;
2614 return 1; 2614 return 1;
2615 break; 2615 break;
2616 case SYNC_PREF_REMOTE: 2616 case SYNC_PREF_REMOTE:
2617 if ( lastSync > remote->revision() ) 2617 if ( lastSync > remote->revision() )
2618 return 1; 2618 return 1;
2619 if ( lastSync > local->revision() ) 2619 if ( lastSync > local->revision() )
2620 return 2; 2620 return 2;
2621 return 2; 2621 return 2;
2622 break; 2622 break;
2623 case SYNC_PREF_NEWEST: 2623 case SYNC_PREF_NEWEST:
2624 if ( local->revision() > remote->revision() ) 2624 if ( local->revision() > remote->revision() )
2625 return 1; 2625 return 1;
2626 else 2626 else
2627 return 2; 2627 return 2;
2628 break; 2628 break;
2629 case SYNC_PREF_ASK: 2629 case SYNC_PREF_ASK:
2630 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); 2630 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() );
2631 if ( lastSync > remote->revision() ) 2631 if ( lastSync > remote->revision() )
2632 return 1; 2632 return 1;
2633 if ( lastSync > local->revision() ) 2633 if ( lastSync > local->revision() )
2634 return 2; 2634 return 2;
2635 localIsNew = local->revision() >= remote->revision(); 2635 localIsNew = local->revision() >= remote->revision();
2636 //qDebug("conflict! ************************************** "); 2636 //qDebug("conflict! ************************************** ");
2637 { 2637 {
2638 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2638 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2639 result = acd.executeD(localIsNew); 2639 result = acd.executeD(localIsNew);
2640 return result; 2640 return result;
2641 } 2641 }
2642 break; 2642 break;
2643 case SYNC_PREF_FORCE_LOCAL: 2643 case SYNC_PREF_FORCE_LOCAL:
2644 return 1; 2644 return 1;
2645 break; 2645 break;
2646 case SYNC_PREF_FORCE_REMOTE: 2646 case SYNC_PREF_FORCE_REMOTE:
2647 return 2; 2647 return 2;
2648 break; 2648 break;
2649 2649
2650 default: 2650 default:
2651 // SYNC_PREF_TAKE_BOTH not implemented 2651 // SYNC_PREF_TAKE_BOTH not implemented
2652 break; 2652 break;
2653 } 2653 }
2654 return 0; 2654 return 0;
2655} 2655}
2656bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2656bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2657{ 2657{
2658 bool syncOK = true; 2658 bool syncOK = true;
2659 int addedAddressee = 0; 2659 int addedAddressee = 0;
2660 int addedAddresseeR = 0; 2660 int addedAddresseeR = 0;
2661 int deletedAddresseeR = 0; 2661 int deletedAddresseeR = 0;
2662 int deletedAddresseeL = 0; 2662 int deletedAddresseeL = 0;
2663 int changedLocal = 0; 2663 int changedLocal = 0;
2664 int changedRemote = 0; 2664 int changedRemote = 0;
2665 //QPtrList<Addressee> el = local->rawAddressees(); 2665 //QPtrList<Addressee> el = local->rawAddressees();
2666 Addressee addresseeR; 2666 Addressee addresseeR;
2667 QString uid; 2667 QString uid;
2668 int take; 2668 int take;
2669 Addressee addresseeL; 2669 Addressee addresseeL;
2670 Addressee addresseeRSync; 2670 Addressee addresseeRSync;
2671 Addressee addresseeLSync; 2671 Addressee addresseeLSync;
2672 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2672 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2673 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2673 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2674 bool fullDateRange = false; 2674 bool fullDateRange = false;
2675 local->resetTempSyncStat(); 2675 local->resetTempSyncStat();
2676 mLastAddressbookSync = QDateTime::currentDateTime(); 2676 mLastAddressbookSync = QDateTime::currentDateTime();
2677 QDateTime modifiedCalendar = mLastAddressbookSync;; 2677 QDateTime modifiedCalendar = mLastAddressbookSync;;
2678 addresseeLSync = getLastSyncAddressee(); 2678 addresseeLSync = getLastSyncAddressee();
2679 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2679 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2680 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2680 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2681 if ( !addresseeR.isEmpty() ) { 2681 if ( !addresseeR.isEmpty() ) {
2682 addresseeRSync = addresseeR; 2682 addresseeRSync = addresseeR;
2683 remote->removeAddressee(addresseeR ); 2683 remote->removeAddressee(addresseeR );
2684 2684
2685 } else { 2685 } else {
2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2686 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2687 addresseeRSync = addresseeLSync ; 2687 addresseeRSync = addresseeLSync ;
2688 } else { 2688 } else {
2689 qDebug("FULLDATE 1"); 2689 qDebug("FULLDATE 1");
2690 fullDateRange = true; 2690 fullDateRange = true;
2691 Addressee newAdd; 2691 Addressee newAdd;
2692 addresseeRSync = newAdd; 2692 addresseeRSync = newAdd;
2693 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2693 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2694 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2694 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2695 addresseeRSync.setRevision( mLastAddressbookSync ); 2695 addresseeRSync.setRevision( mLastAddressbookSync );
2696 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2696 addresseeRSync.setCategories( i18n("SyncAddressee") );
2697 } 2697 }
2698 } 2698 }
2699 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2699 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2700 qDebug("FULLDATE 2"); 2700 qDebug("FULLDATE 2");
2701 fullDateRange = true; 2701 fullDateRange = true;
2702 } 2702 }
2703 if ( ! fullDateRange ) { 2703 if ( ! fullDateRange ) {
2704 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2704 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2705 2705
2706 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2706 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2707 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2707 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2708 fullDateRange = true; 2708 fullDateRange = true;
2709 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2709 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2710 } 2710 }
2711 } 2711 }
2712 fullDateRange = true; // debug only! 2712 // fullDateRange = true; // debug only!
2713 if ( fullDateRange ) 2713 if ( fullDateRange )
2714 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2714 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2715 else 2715 else
2716 mLastAddressbookSync = addresseeLSync.revision(); 2716 mLastAddressbookSync = addresseeLSync.revision();
2717 // for resyncing if own file has changed 2717 // for resyncing if own file has changed
2718 // PENDING fixme later when implemented 2718 // PENDING fixme later when implemented
2719#if 0 2719#if 0
2720 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2720 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2721 mLastAddressbookSync = loadedFileVersion; 2721 mLastAddressbookSync = loadedFileVersion;
2722 qDebug("setting mLastAddressbookSync "); 2722 qDebug("setting mLastAddressbookSync ");
2723 } 2723 }
2724#endif 2724#endif
2725 2725
2726 //qDebug("*************************** "); 2726 //qDebug("*************************** ");
2727 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2727 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2728 QStringList er = remote->uidList(); 2728 QStringList er = remote->uidList();
2729 Addressee inR ;//= er.first(); 2729 Addressee inR ;//= er.first();
2730 Addressee inL; 2730 Addressee inL;
2731 QProgressBar bar( er.count(),0 ); 2731 QProgressBar bar( er.count(),0 );
2732 bar.setCaption (i18n("Syncing - close to abort!") ); 2732 bar.setCaption (i18n("Syncing - close to abort!") );
2733 2733
2734 int w = 300; 2734 int w = 300;
2735 if ( QApplication::desktop()->width() < 320 ) 2735 if ( QApplication::desktop()->width() < 320 )
2736 w = 220; 2736 w = 220;
2737 int h = bar.sizeHint().height() ; 2737 int h = bar.sizeHint().height() ;
2738 int dw = QApplication::desktop()->width(); 2738 int dw = QApplication::desktop()->width();
2739 int dh = QApplication::desktop()->height(); 2739 int dh = QApplication::desktop()->height();
2740 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2740 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2741 bar.show(); 2741 bar.show();
2742 int modulo = (er.count()/10)+1; 2742 int modulo = (er.count()/10)+1;
2743 int incCounter = 0; 2743 int incCounter = 0;
2744 while ( incCounter < er.count()) { 2744 while ( incCounter < er.count()) {
2745 if ( ! bar.isVisible() ) 2745 if ( ! bar.isVisible() )
2746 return false; 2746 return false;
2747 if ( incCounter % modulo == 0 ) 2747 if ( incCounter % modulo == 0 )
2748 bar.setProgress( incCounter ); 2748 bar.setProgress( incCounter );
2749 uid = er[ incCounter ]; 2749 uid = er[ incCounter ];
2750 bool skipIncidence = false; 2750 bool skipIncidence = false;
2751 if ( uid.left(19) == QString("last-syncAddressee-") ) 2751 if ( uid.left(19) == QString("last-syncAddressee-") )
2752 skipIncidence = true; 2752 skipIncidence = true;
2753 QString idS; 2753 QString idS;
2754 qApp->processEvents(); 2754 qApp->processEvents();
2755 if ( !skipIncidence ) { 2755 if ( !skipIncidence ) {
2756 inL = local->findByUid( uid ); 2756 inL = local->findByUid( uid );
2757 inR = remote->findByUid( uid ); 2757 inR = remote->findByUid( uid );
2758 //inL.setResource( 0 ); 2758 //inL.setResource( 0 );
2759 //inR.setResource( 0 ); 2759 //inR.setResource( 0 );
2760 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2760 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2761 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2761 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2762 //qDebug("take %d %s ", take, inL.summary().latin1()); 2762 //qDebug("take %d %s ", take, inL.summary().latin1());
2763 if ( take == 3 ) 2763 if ( take == 3 )
2764 return false; 2764 return false;
2765 if ( take == 1 ) {// take local 2765 if ( take == 1 ) {// take local
2766 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2766 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2767 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2767 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2768 local->insertAddressee( inL, false ); 2768 local->insertAddressee( inL, false );
2769 } 2769 }
2770 else 2770 else
2771 idS = inR.IDStr(); 2771 idS = inR.IDStr();
2772 remote->removeAddressee( inR ); 2772 remote->removeAddressee( inR );
2773 inR = inL; 2773 inR = inL;
2774 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2774 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2775 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 2775 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
2776 inR.setIDStr( idS ); 2776 inR.setIDStr( idS );
2777 inR.setResource( 0 ); 2777 inR.setResource( 0 );
2778 remote->insertAddressee( inR , false); 2778 remote->insertAddressee( inR , false);
2779 ++changedRemote; 2779 ++changedRemote;
2780 } else { 2780 } else {
2781 idS = inL.IDStr(); 2781 idS = inL.IDStr();
2782 local->removeAddressee( inL ); 2782 local->removeAddressee( inL );
2783 inL = inR; 2783 inL = inR;
2784 inL.setIDStr( idS ); 2784 inL.setIDStr( idS );
2785 inL.setResource( 0 ); 2785 inL.setResource( 0 );
2786 local->insertAddressee( inL , false ); 2786 local->insertAddressee( inL , false );
2787 ++changedLocal; 2787 ++changedLocal;
2788 } 2788 }
2789 } 2789 }
2790 } else { // no conflict 2790 } else { // no conflict
2791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2791 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2792 QString des = addresseeLSync.note(); 2792 QString des = addresseeLSync.note();
2793 QString pref = "a"; 2793 QString pref = "a";
2794 if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2794 if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2795 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2795 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2796 ++deletedAddresseeR; 2796 ++deletedAddresseeR;
2797 } else { 2797 } else {
2798 inR.setRevision( modifiedCalendar ); 2798 inR.setRevision( modifiedCalendar );
2799 remote->insertAddressee( inR, false ); 2799 remote->insertAddressee( inR, false );
2800 inL = inR; 2800 inL = inR;
2801 inL.setResource( 0 ); 2801 inL.setResource( 0 );
2802 local->insertAddressee( inL , false); 2802 local->insertAddressee( inL , false);
2803 ++addedAddressee; 2803 ++addedAddressee;
2804 } 2804 }
2805 } else { 2805 } else {
2806 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2806 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2807 inR.setRevision( modifiedCalendar ); 2807 inR.setRevision( modifiedCalendar );
2808 remote->insertAddressee( inR, false ); 2808 remote->insertAddressee( inR, false );
2809 inR.setResource( 0 ); 2809 inR.setResource( 0 );
2810 local->insertAddressee( inR, false ); 2810 local->insertAddressee( inR, false );
2811 ++addedAddressee; 2811 ++addedAddressee;
2812 } else { 2812 } else {
2813 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2813 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2814 remote->removeAddressee( inR ); 2814 remote->removeAddressee( inR );
2815 ++deletedAddresseeR; 2815 ++deletedAddresseeR;
2816 } 2816 }
2817 } 2817 }
2818 } 2818 }
2819 } 2819 }
2820 ++incCounter; 2820 ++incCounter;
2821 } 2821 }
2822 er.clear(); 2822 er.clear();
2823 QStringList el = remote->uidList(); 2823 QStringList el = remote->uidList();
2824 modulo = (el.count()/10)+1; 2824 modulo = (el.count()/10)+1;
2825 bar.setCaption (i18n("Add / remove addressees") ); 2825 bar.setCaption (i18n("Add / remove addressees") );
2826 bar.setTotalSteps ( el.count() ) ; 2826 bar.setTotalSteps ( el.count() ) ;
2827 bar.show(); 2827 bar.show();
2828 incCounter = 0; 2828 incCounter = 0;
2829 while ( incCounter < el.count()) { 2829 while ( incCounter < el.count()) {
2830 2830
2831 qApp->processEvents(); 2831 qApp->processEvents();
2832 if ( ! bar.isVisible() ) 2832 if ( ! bar.isVisible() )
2833 return false; 2833 return false;
2834 if ( incCounter % modulo == 0 ) 2834 if ( incCounter % modulo == 0 )
2835 bar.setProgress( incCounter ); 2835 bar.setProgress( incCounter );
2836 uid = el[ incCounter ]; 2836 uid = el[ incCounter ];
2837 bool skipIncidence = false; 2837 bool skipIncidence = false;
2838 if ( uid.left(19) == QString("last-syncAddressee-") ) 2838 if ( uid.left(19) == QString("last-syncAddressee-") )
2839 skipIncidence = true; 2839 skipIncidence = true;
2840 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2840 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2841 skipIncidence = true; 2841 skipIncidence = true;
2842 if ( !skipIncidence ) { 2842 if ( !skipIncidence ) {
2843 inL = local->findByUid( uid ); 2843 inL = local->findByUid( uid );
2844 inR = remote->findByUid( uid ); 2844 inR = remote->findByUid( uid );
2845 if ( inR.isEmpty() ) { 2845 if ( inR.isEmpty() ) {
2846 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2846 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2847 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2847 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2848 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2848 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2849 local->removeAddressee( inL ); 2849 local->removeAddressee( inL );
2850 ++deletedAddresseeL; 2850 ++deletedAddresseeL;
2851 } else { 2851 } else {
2852 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2852 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2853 inL.removeID(mCurrentSyncDevice ); 2853 inL.removeID(mCurrentSyncDevice );
2854 ++addedAddresseeR; 2854 ++addedAddresseeR;
2855 //qDebug("remote added Incidence %s ", inL.summary().latin1()); 2855 //qDebug("remote added Incidence %s ", inL.summary().latin1());
2856 inL.setRevision( modifiedCalendar ); 2856 inL.setRevision( modifiedCalendar );
2857 local->insertAddressee( inL, false ); 2857 local->insertAddressee( inL, false );
2858 inR = inL; 2858 inR = inL;
2859 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2859 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2860 inR.setResource( 0 ); 2860 inR.setResource( 0 );
2861 remote->insertAddressee( inR, false ); 2861 remote->insertAddressee( inR, false );
2862 } 2862 }
2863 } 2863 }
2864 } else { 2864 } else {
2865 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2865 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2866 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2866 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2867 local->removeAddressee( inL ); 2867 local->removeAddressee( inL );
2868 ++deletedAddresseeL; 2868 ++deletedAddresseeL;
2869 } else { 2869 } else {
2870 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { 2870 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2871 ++addedAddresseeR; 2871 ++addedAddresseeR;
2872 inL.setRevision( modifiedCalendar ); 2872 inL.setRevision( modifiedCalendar );
2873 local->insertAddressee( inL, false ); 2873 local->insertAddressee( inL, false );
2874 inR = inL; 2874 inR = inL;
2875 inR.setResource( 0 ); 2875 inR.setResource( 0 );
2876 remote->insertAddressee( inR, false ); 2876 remote->insertAddressee( inR, false );
2877 } 2877 }
2878 } 2878 }
2879 } 2879 }
2880 } 2880 }
2881 } 2881 }
2882 ++incCounter; 2882 ++incCounter;
2883 } 2883 }
2884 el.clear(); 2884 el.clear();
2885 bar.hide(); 2885 bar.hide();
2886 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2886 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2887 // get rid of micro seconds 2887 // get rid of micro seconds
2888 QTime t = mLastAddressbookSync.time(); 2888 QTime t = mLastAddressbookSync.time();
2889 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2889 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2890 addresseeLSync.setRevision( mLastAddressbookSync ); 2890 addresseeLSync.setRevision( mLastAddressbookSync );
2891 addresseeRSync.setRevision( mLastAddressbookSync ); 2891 addresseeRSync.setRevision( mLastAddressbookSync );
2892 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2892 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2893 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2893 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2894 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2894 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2895 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2895 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2896 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2896 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2897 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2897 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2898 2898
2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2899 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2900 remote->insertAddressee( addresseeRSync, false ); 2900 remote->insertAddressee( addresseeRSync, false );
2901 local->insertAddressee( addresseeLSync, false ); 2901 local->insertAddressee( addresseeLSync, false );
2902 QString mes; 2902 QString mes;
2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2903 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2904 if ( KABPrefs::instance()->mShowSyncSummary ) { 2904 if ( KABPrefs::instance()->mShowSyncSummary ) {
2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2905 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2906 } 2906 }
2907 qDebug( mes ); 2907 qDebug( mes );
2908 return syncOK; 2908 return syncOK;
2909} 2909}
2910 2910
2911bool KABCore::syncAB(QString filename, int mode) 2911bool KABCore::syncAB(QString filename, int mode)
2912{ 2912{
2913 2913
2914 //pending prepare addresseeview for output 2914 //pending prepare addresseeview for output
2915 //pending detect, if remote file has REV field. if not switch to external sync 2915 //pending detect, if remote file has REV field. if not switch to external sync
2916 mGlobalSyncMode = SYNC_MODE_NORMAL; 2916 mGlobalSyncMode = SYNC_MODE_NORMAL;
2917 AddressBook abLocal(filename,"syncContact"); 2917 AddressBook abLocal(filename,"syncContact");
2918 bool syncOK = false; 2918 bool syncOK = false;
2919 if ( abLocal.load() ) { 2919 if ( abLocal.load() ) {
2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2920 qDebug("AB loaded %s mode %d",filename.latin1(), mode );
2921 AddressBook::Iterator it; 2921 bool external = false;
2922 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2923 if ( ! lse.isEmpty() ) {
2924 if ( lse.familyName().left(4) == "!E: " )
2925 external = true;
2926 } else {
2927 bool found = false;
2928 QDateTime dt( QDate( 2004,1,1));
2929 AddressBook::Iterator it;
2930 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2931 if ( (*it).revision() != dt ) {
2932 found = true;
2933 break;
2934 }
2935 }
2936 external = ! found;
2937 }
2938
2939 if ( external ) {
2940 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2941 AddressBook::Iterator it;
2942 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2943 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2944 (*it).computeCsum( mCurrentSyncDevice );
2945 }
2946 }
2947 //AddressBook::Iterator it;
2922 //QStringList vcards; 2948 //QStringList vcards;
2923 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2949 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2924 // qDebug("Name %s ", (*it).familyName().latin1()); 2950 // qDebug("Name %s ", (*it).familyName().latin1());
2925 //} 2951 //}
2926 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2952 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2927 if ( syncOK ) { 2953 if ( syncOK ) {
2928 if ( KABPrefs::instance()->mWriteBackFile ) 2954 if ( KABPrefs::instance()->mWriteBackFile )
2929 { 2955 {
2956 if ( external )
2957 abLocal.removeDeletedAddressees();
2930 qDebug("saving remote AB "); 2958 qDebug("saving remote AB ");
2931 abLocal.saveAB(); 2959 abLocal.saveAB();
2932 } 2960 }
2933 } 2961 }
2934 setModified(); 2962 setModified();
2935 2963
2936 } 2964 }
2937 if ( syncOK ) 2965 if ( syncOK )
2938 mViewManager->refreshView(); 2966 mViewManager->refreshView();
2939 return syncOK; 2967 return syncOK;
2940#if 0 2968#if 0
2941 2969
2942 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2970 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2943 getEventViewerDialog()->setSyncMode( true ); 2971 getEventViewerDialog()->setSyncMode( true );
2944 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2972 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2945 getEventViewerDialog()->setSyncMode( false ); 2973 getEventViewerDialog()->setSyncMode( false );
2946 if ( syncOK ) { 2974 if ( syncOK ) {
2947 if ( KOPrefs::instance()->mWriteBackFile ) 2975 if ( KOPrefs::instance()->mWriteBackFile )
2948 { 2976 {
2949 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2977 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2950 storage->save(); 2978 storage->save();
2951 } 2979 }
2952 } 2980 }
2953 setModified(); 2981 setModified();
2954 } 2982 }
2955 2983
2956#endif 2984#endif
2957} 2985}
2958 2986
2959void KABCore::confSync() 2987void KABCore::confSync()
2960{ 2988{
2961 static KSyncPrefsDialog* sp = 0; 2989 static KSyncPrefsDialog* sp = 0;
2962 if ( ! sp ) { 2990 if ( ! sp ) {
2963 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 2991 sp = new KSyncPrefsDialog( this, "syncprefs", true );
2964 } 2992 }
2965 sp->usrReadConfig(); 2993 sp->usrReadConfig();
2966#ifndef DESKTOP_VERSION 2994#ifndef DESKTOP_VERSION
2967 sp->showMaximized(); 2995 sp->showMaximized();
2968#else 2996#else
2969 sp->show(); 2997 sp->show();
2970#endif 2998#endif
2971 sp->exec(); 2999 sp->exec();
2972 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 3000 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
2973 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 3001 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
2974 fillSyncMenu(); 3002 fillSyncMenu();
2975} 3003}
2976void KABCore::syncSharp() 3004void KABCore::syncSharp()
2977{ 3005{
2978 if ( mModified ) 3006 if ( mModified )
2979 save(); 3007 save();
2980 qDebug("pending syncSharp() "); 3008 qDebug("pending syncSharp() ");
2981 //mView->syncSharp(); 3009 //mView->syncSharp();
2982 setModified(); 3010 setModified();
2983 3011
2984} 3012}
2985void KABCore::syncPhone() 3013void KABCore::syncPhone()
2986{ 3014{
2987 if ( mModified ) 3015 if ( mModified )
2988 save(); 3016 save();
2989 qDebug("pending syncPhone(); "); 3017 qDebug("pending syncPhone(); ");
2990 //mView->syncPhone(); 3018 //mView->syncPhone();
2991 setModified(); 3019 setModified();
2992 3020
2993} 3021}