summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-27 19:44:10 (UTC)
committer zautrix <zautrix>2004-10-27 19:44:10 (UTC)
commitbb82cac85cc196b3f60921ab27e84204036b54b8 (patch) (unidiff)
tree518629480b983b6b85a4cf1e5542f94fe1687e41
parent85a0e0d9b1d60805cb4947be1c296c18e73c82b8 (diff)
downloadkdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.zip
kdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.tar.gz
kdepimpi-bb82cac85cc196b3f60921ab27e84204036b54b8.tar.bz2
sync fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp19
-rw-r--r--kabc/addressbook.h2
-rw-r--r--kabc/addressee.cpp2
-rw-r--r--kaddressbook/kabcore.cpp16
4 files changed, 26 insertions, 13 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 9b196b5..5774c36 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1243 +1,1254 @@
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#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h> 50#include <libkdepim/phoneaccess.h>
51#include "addressbook.h" 51#include "addressbook.h"
52#include "resource.h" 52#include "resource.h"
53#include "vcardconverter.h" 53#include "vcardconverter.h"
54#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
55 55
56//US #include "addressbook.moc" 56//US #include "addressbook.moc"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
61{ 61{
62 Addressee::List mAddressees; 62 Addressee::List mAddressees;
63 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
64 Field::List mAllFields; 64 Field::List mAllFields;
65 KConfig *mConfig; 65 KConfig *mConfig;
66 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
67//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
68}; 68};
69 69
70struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
71{ 71{
72 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
73}; 73};
74 74
75struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
76{ 76{
77 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
78}; 78};
79 79
80AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
81{ 81{
82 d = new IteratorData; 82 d = new IteratorData;
83} 83}
84 84
85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
86{ 86{
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89} 89}
90 90
91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
92{ 92{
93 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
94 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
95 d = new IteratorData; 95 d = new IteratorData;
96 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
97 return *this; 97 return *this;
98} 98}
99 99
100AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
101{ 101{
102 delete d; 102 delete d;
103} 103}
104 104
105const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
106{ 106{
107 return *(d->mIt); 107 return *(d->mIt);
108} 108}
109 109
110Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
111{ 111{
112 return *(d->mIt); 112 return *(d->mIt);
113} 113}
114 114
115Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
116{ 116{
117 return &(*(d->mIt)); 117 return &(*(d->mIt));
118} 118}
119 119
120AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
121{ 121{
122 (d->mIt)++; 122 (d->mIt)++;
123 return *this; 123 return *this;
124} 124}
125 125
126AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
127{ 127{
128 (d->mIt)++; 128 (d->mIt)++;
129 return *this; 129 return *this;
130} 130}
131 131
132AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
133{ 133{
134 (d->mIt)--; 134 (d->mIt)--;
135 return *this; 135 return *this;
136} 136}
137 137
138AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
139{ 139{
140 (d->mIt)--; 140 (d->mIt)--;
141 return *this; 141 return *this;
142} 142}
143 143
144bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
145{ 145{
146 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
147} 147}
148 148
149bool AddressBook::Iterator::operator!=( const Iterator &it ) 149bool AddressBook::Iterator::operator!=( const Iterator &it )
150{ 150{
151 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
152} 152}
153 153
154 154
155AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
156{ 156{
157 d = new ConstIteratorData; 157 d = new ConstIteratorData;
158} 158}
159 159
160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
161{ 161{
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164} 164}
165 165
166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
167{ 167{
168 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
169 delete d; // delete the old data because the Iterator was really constructed before 169 delete d; // delete the old data because the Iterator was really constructed before
170 d = new ConstIteratorData; 170 d = new ConstIteratorData;
171 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
172 return *this; 172 return *this;
173} 173}
174 174
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
215{ 215{
216 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
217} 217}
218 218
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
220{ 220{
221 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
222} 222}
223 223
224 224
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
236{ 236{
237 init(config, family); 237 init(config, family);
238 238
239} 239}
240 240
241// the default family is "contact" 241// the default family is "contact"
242void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
243{ 243{
244 blockLSEchange = false; 244 blockLSEchange = false;
245 d = new AddressBookData; 245 d = new AddressBookData;
246 QString fami = family; 246 QString fami = family;
247 if (config != 0) { 247 if (config != 0) {
248 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
249 qDebug("creating sync config "); 249 qDebug("creating sync config ");
250 fami = "contact"; 250 fami = "contact";
251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
252 con->setGroup( "General" ); 252 con->setGroup( "General" );
253 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
254 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
255 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
256 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
257 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
258 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
259 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
260 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
261 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
262 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
263 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
264 } else { 264 } else {
265 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
266 } 266 }
267 //con->sync(); 267 //con->sync();
268 d->mConfig = con; 268 d->mConfig = con;
269 } 269 }
270 else 270 else
271 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
272// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
273 } 273 }
274 else { 274 else {
275 d->mConfig = 0; 275 d->mConfig = 0;
276// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
277 } 277 }
278 278
279//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
280 d->mManager = new KRES::Manager<Resource>( fami ); 280 d->mManager = new KRES::Manager<Resource>( fami );
281 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
282 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
283 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
284 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
286 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
287 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
294 if ( res ) 294 if ( res )
295 { 295 {
296 addResource( res ); 296 addResource( res );
297 } 297 }
298 else 298 else
299 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
300 } 300 }
301 setStandardResource( res ); 301 setStandardResource( res );
302 manager->writeConfig(); 302 manager->writeConfig();
303 } 303 }
304 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
305 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
306 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
307 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344 clear(); 344 clear();
345 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 346 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 350 ok = false;
351 } else { 351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); 352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379// exports all Addressees, which are syncable 379// exports all Addressees, which are syncable
380void AddressBook::export2File( QString fileName ) 380void AddressBook::export2File( QString fileName )
381{ 381{
382 382
383 QFile outFile( fileName ); 383 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( IO_WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 387 return ;
388 } 388 }
389 QTextStream t( &outFile ); 389 QTextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( QTextStream::UnicodeUTF8 );
391 Iterator it; 391 Iterator it;
392 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
395 if ( (*it).resource() && (*it).resource()->includeInSync() ) { 395 if ( (*it).resource() && (*it).resource()->includeInSync() ) {
396 if ( !(*it).IDStr().isEmpty() ) { 396 if ( !(*it).IDStr().isEmpty() ) {
397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
398 } 398 }
399 KABC::VCardConverter converter; 399 KABC::VCardConverter converter;
400 QString vcard; 400 QString vcard;
401 //Resource *resource() const; 401 //Resource *resource() const;
402 converter.addresseeToVCard( *it, vcard, version ); 402 converter.addresseeToVCard( *it, vcard, version );
403 t << vcard << "\r\n"; 403 t << vcard << "\r\n";
404 } 404 }
405 } 405 }
406 t << "\r\n\r\n"; 406 t << "\r\n\r\n";
407 outFile.close(); 407 outFile.close();
408} 408}
409// if QStringList uids is empty, all are exported 409// if QStringList uids is empty, all are exported
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
411{ 411{
412 KABC::VCardConverter converter; 412 KABC::VCardConverter converter;
413 QString datastream; 413 QString datastream;
414 Iterator it; 414 Iterator it;
415 bool all = uids.isEmpty(); 415 bool all = uids.isEmpty();
416 for ( it = begin(); it != end(); ++it ) { 416 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 418 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 419 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 420 continue;
421 } 421 }
422 KABC::Addressee a = ( *it ); 422 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 423 if ( a.isEmpty() )
424 continue; 424 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 425 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 426 continue;
427 a.simplifyEmails(); 427 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 428 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 429 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 430 a.simplifyAddresses();
431 431
432 QString vcard; 432 QString vcard;
433 QString vcardnew; 433 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 434 converter.addresseeToVCard( a, vcard );
435 int start = 0; 435 int start = 0;
436 int next; 436 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 438 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 439 int dopp = vcard.find(":", next);
440 int sep; 440 int sep;
441 if ( semi < dopp && semi >= 0 ) 441 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 442 sep = semi ;
443 else 443 else
444 sep = dopp; 444 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 445 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 447 start = sep;
448 } 448 }
449 vcardnew += vcard.mid( start,vcard.length() ); 449 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 450 vcard = "";
451 start = 0; 451 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 453 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 454 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 455 start = sep;
456 } 456 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 457 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 458 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 459 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 460 datastream += vcard;
461 461
462 } 462 }
463 463
464 QFile outFile(fileName); 464 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 465 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 467 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 468 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 469 t <<datastream;
470 t << "\r\n\r\n"; 470 t << "\r\n\r\n";
471 outFile.close(); 471 outFile.close();
472 472
473 } else { 473 } else {
474 qDebug("Error open temp file "); 474 qDebug("Error open temp file ");
475 return false; 475 return false;
476 } 476 }
477 return true; 477 return true;
478 478
479} 479}
480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513 return list.count(); 513 return list.count();
514} 514}
515void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
516{ 516{
517 Iterator ait; 517 Iterator ait;
518 for ( ait = begin(); ait != end(); ++ait ) { 518 for ( ait = begin(); ait != end(); ++ait ) {
519 if ( setNonSyncTagged ) { 519 if ( setNonSyncTagged ) {
520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
521 (*ait).setTagged( true ); 521 (*ait).setTagged( true );
522 } else 522 } else
523 (*ait).setTagged( false ); 523 (*ait).setTagged( false );
524 } else 524 } else
525 (*ait).setTagged( false ); 525 (*ait).setTagged( false );
526 } 526 }
527} 527}
528void AddressBook::removeUntagged() 528void AddressBook::removeUntagged()
529{ 529{
530 Iterator ait; 530 Iterator ait;
531 bool todelete = false; 531 bool todelete = false;
532 Iterator todel; 532 Iterator todel;
533 for ( ait = begin(); ait != end(); ++ait ) { 533 for ( ait = begin(); ait != end(); ++ait ) {
534 if ( todelete ) 534 if ( todelete )
535 removeAddressee( todel ); 535 removeAddressee( todel );
536 if (!(*ait).tagged()) { 536 if (!(*ait).tagged()) {
537 todelete = true; 537 todelete = true;
538 todel = ait; 538 todel = ait;
539 } else 539 } else
540 todelete = false; 540 todelete = false;
541 } 541 }
542 if ( todelete ) 542 if ( todelete )
543 removeAddressee( todel ); 543 removeAddressee( todel );
544 deleteRemovedAddressees(); 544 deleteRemovedAddressees();
545} 545}
546void AddressBook::smplifyAddressees() 546void AddressBook::smplifyAddressees()
547{ 547{
548 Iterator ait; 548 Iterator ait;
549 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
550 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
551 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
552 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
553 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
554 } 554 }
555} 555}
556void AddressBook::removeSyncInfo( QString syncProfile) 556void AddressBook::removeSyncInfo( QString syncProfile)
557{ 557{
558 Iterator ait; 558 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) { 559 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile ); 560 (*ait).removeID( syncProfile );
561 } 561 }
562 if ( syncProfile.isEmpty() ) { 562 if ( syncProfile.isEmpty() ) {
563 Iterator it = begin(); 563 Iterator it = begin();
564 Iterator it2 ; 564 Iterator it2 ;
565 QDateTime dt ( QDate( 2004,1,1) ); 565 QDateTime dt ( QDate( 2004,1,1) );
566 while ( it != end() ) { 566 while ( it != end() ) {
567 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 567 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
568 it2 = it; 568 it2 = it;
569 //qDebug("removing %s ",(*it).uid().latin1() ); 569 //qDebug("removing %s ",(*it).uid().latin1() );
570 ++it; 570 ++it;
571 removeAddressee( it2 ); 571 removeAddressee( it2 );
572 } else { 572 } else {
573 //qDebug("skipping %s ",(*it).uid().latin1() ); 573 //qDebug("skipping %s ",(*it).uid().latin1() );
574 ++it; 574 ++it;
575 } 575 }
576 } 576 }
577 } else { 577 } else {
578 Addressee lse; 578 Addressee lse;
579 lse = findByUid( "last-syncAddressee-"+ syncProfile ); 579 lse = findByUid( "last-syncAddressee-"+ syncProfile );
580 if ( ! lse.isEmpty() ) 580 if ( ! lse.isEmpty() )
581 removeAddressee( lse ); 581 removeAddressee( lse );
582 } 582 }
583 583
584} 584}
585void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 585void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
586{ 586{
587 Iterator ait; 587 Iterator ait;
588 for ( ait = begin(); ait != end(); ++ait ) { 588 for ( ait = begin(); ait != end(); ++ait ) {
589 QString id = (*ait).IDStr(); 589 QString id = (*ait).IDStr();
590 (*ait).setIDStr( ":"); 590 (*ait).setIDStr( ":");
591 (*ait).setExternalUID( id ); 591 (*ait).setExternalUID( id );
592 (*ait).setOriginalExternalUID( id ); 592 (*ait).setOriginalExternalUID( id );
593 if ( isPreSync ) 593 if ( isPreSync )
594 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 594 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
595 else { 595 else {
596 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 596 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
597 (*ait).setID( currentSyncDevice,id ); 597 (*ait).setID( currentSyncDevice,id );
598 598
599 } 599 }
600 } 600 }
601} 601}
602void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 602void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
603{ 603{
604 604
605 setUntagged(); 605 setUntagged();
606 KABC::Addressee::List list; 606 KABC::Addressee::List list;
607 QFile file( fileName ); 607 QFile file( fileName );
608 file.open( IO_ReadOnly ); 608 file.open( IO_ReadOnly );
609 QByteArray rawData = file.readAll(); 609 QByteArray rawData = file.readAll();
610 file.close(); 610 file.close();
611 QString data; 611 QString data;
612 612
613 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 613 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
614 KABC::VCardTool tool; 614 KABC::VCardTool tool;
615 list = tool.parseVCards( data ); 615 list = tool.parseVCards( data );
616 KABC::Addressee::List::Iterator it; 616 KABC::Addressee::List::Iterator it;
617 for ( it = list.begin(); it != list.end(); ++it ) { 617 for ( it = list.begin(); it != list.end(); ++it ) {
618 Iterator ait; 618 Iterator ait;
619 for ( ait = begin(); ait != end(); ++ait ) { 619 for ( ait = begin(); ait != end(); ++ait ) {
620 if ( !(*ait).tagged() ) { 620 if ( !(*ait).tagged() ) {
621 if ( (*ait).containsAdr(*it)) { 621 if ( (*ait).containsAdr(*it)) {
622 (*ait).setTagged(true); 622 (*ait).setTagged(true);
623 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 623 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
624 (*it).setIDStr( ":"); 624 (*it).setIDStr( ":");
625 (*it).setID( currentSyncDevice,id ); 625 (*it).setID( currentSyncDevice,id );
626 (*it).setExternalUID( id ); 626 (*it).setExternalUID( id );
627 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 627 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
628 (*it).setUid( ( (*ait).uid() )); 628 (*it).setUid( ( (*ait).uid() ));
629 break; 629 break;
630 } 630 }
631 } 631 }
632 632
633 } 633 }
634 if ( ait == end() ) 634 if ( ait == end() )
635 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 635 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
636 } 636 }
637 clear(); 637 clear();
638 for ( it = list.begin(); it != list.end(); ++it ) { 638 for ( it = list.begin(); it != list.end(); ++it ) {
639 insertAddressee( (*it) ); 639 insertAddressee( (*it) );
640 } 640 }
641} 641}
642 642
643bool AddressBook::saveABphone( QString fileName ) 643bool AddressBook::saveABphone( QString fileName )
644{ 644{
645 //smplifyAddressees(); 645 //smplifyAddressees();
646 qDebug("saveABphone:: saving AB... "); 646 qDebug("saveABphone:: saving AB... ");
647 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 647 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
648 return false; 648 return false;
649 qDebug("saveABphone:: writing to phone... "); 649 qDebug("saveABphone:: writing to phone... ");
650 if ( !PhoneAccess::writeToPhone( fileName) ) { 650 if ( !PhoneAccess::writeToPhone( fileName) ) {
651 return false; 651 return false;
652 } 652 }
653 qDebug("saveABphone:: re-reading from phone... "); 653 qDebug("saveABphone:: re-reading from phone... ");
654 if ( !PhoneAccess::readFromPhone( fileName) ) { 654 if ( !PhoneAccess::readFromPhone( fileName) ) {
655 return false; 655 return false;
656 } 656 }
657 return true; 657 return true;
658} 658}
659bool AddressBook::saveAB() 659bool AddressBook::saveAB()
660{ 660{
661 bool ok = true; 661 bool ok = true;
662 662
663 deleteRemovedAddressees(); 663 deleteRemovedAddressees();
664 Iterator ait; 664 Iterator ait;
665 for ( ait = begin(); ait != end(); ++ait ) { 665 for ( ait = begin(); ait != end(); ++ait ) {
666 if ( !(*ait).IDStr().isEmpty() ) { 666 if ( !(*ait).IDStr().isEmpty() ) {
667 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 667 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
668 } 668 }
669 } 669 }
670 KRES::Manager<Resource>::ActiveIterator it; 670 KRES::Manager<Resource>::ActiveIterator it;
671 KRES::Manager<Resource> *manager = d->mManager; 671 KRES::Manager<Resource> *manager = d->mManager;
672 qDebug("SaveAB::saving..." ); 672 qDebug("SaveAB::saving..." );
673 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 673 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
674 qDebug("SaveAB::checking resource..." ); 674 qDebug("SaveAB::checking resource..." );
675 if ( (*it)->readOnly() ) 675 if ( (*it)->readOnly() )
676 qDebug("resource is readonly." ); 676 qDebug("resource is readonly." );
677 if ( (*it)->isOpen() ) 677 if ( (*it)->isOpen() )
678 qDebug("resource is open" ); 678 qDebug("resource is open" );
679 679
680 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 680 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
681 Ticket *ticket = requestSaveTicket( *it ); 681 Ticket *ticket = requestSaveTicket( *it );
682 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 682 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
683 if ( !ticket ) { 683 if ( !ticket ) {
684 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 684 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
685 .arg( (*it)->resourceName() ) ); 685 .arg( (*it)->resourceName() ) );
686 return false; 686 return false;
687 } 687 }
688 688
689 //if ( !save( ticket ) ) 689 //if ( !save( ticket ) )
690 if ( ticket->resource() ) { 690 if ( ticket->resource() ) {
691 QString name = ticket->resource()->resourceName(); 691 QString name = ticket->resource()->resourceName();
692 if ( ! ticket->resource()->save( ticket ) ) 692 if ( ! ticket->resource()->save( ticket ) )
693 ok = false; 693 ok = false;
694 else 694 else
695 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 695 qDebug("StdAddressBook::resource saved '%s'", name.latin1() );
696 696
697 } else 697 } else
698 ok = false; 698 ok = false;
699 699
700 } 700 }
701 } 701 }
702 return ok; 702 return ok;
703} 703}
704 704
705AddressBook::Iterator AddressBook::begin() 705AddressBook::Iterator AddressBook::begin()
706{ 706{
707 Iterator it = Iterator(); 707 Iterator it = Iterator();
708 it.d->mIt = d->mAddressees.begin(); 708 it.d->mIt = d->mAddressees.begin();
709 return it; 709 return it;
710} 710}
711 711
712AddressBook::ConstIterator AddressBook::begin() const 712AddressBook::ConstIterator AddressBook::begin() const
713{ 713{
714 ConstIterator it = ConstIterator(); 714 ConstIterator it = ConstIterator();
715 it.d->mIt = d->mAddressees.begin(); 715 it.d->mIt = d->mAddressees.begin();
716 return it; 716 return it;
717} 717}
718 718
719AddressBook::Iterator AddressBook::end() 719AddressBook::Iterator AddressBook::end()
720{ 720{
721 Iterator it = Iterator(); 721 Iterator it = Iterator();
722 it.d->mIt = d->mAddressees.end(); 722 it.d->mIt = d->mAddressees.end();
723 return it; 723 return it;
724} 724}
725 725
726AddressBook::ConstIterator AddressBook::end() const 726AddressBook::ConstIterator AddressBook::end() const
727{ 727{
728 ConstIterator it = ConstIterator(); 728 ConstIterator it = ConstIterator();
729 it.d->mIt = d->mAddressees.end(); 729 it.d->mIt = d->mAddressees.end();
730 return it; 730 return it;
731} 731}
732 732
733void AddressBook::clear() 733void AddressBook::clear()
734{ 734{
735 d->mAddressees.clear(); 735 d->mAddressees.clear();
736} 736}
737 737
738Ticket *AddressBook::requestSaveTicket( Resource *resource ) 738Ticket *AddressBook::requestSaveTicket( Resource *resource )
739{ 739{
740 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 740 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
741 741
742 if ( !resource ) 742 if ( !resource )
743 { 743 {
744 qDebug("AddressBook::requestSaveTicket no resource" ); 744 qDebug("AddressBook::requestSaveTicket no resource" );
745 resource = standardResource(); 745 resource = standardResource();
746 } 746 }
747 747
748 KRES::Manager<Resource>::ActiveIterator it; 748 KRES::Manager<Resource>::ActiveIterator it;
749 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 749 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
750 if ( (*it) == resource ) { 750 if ( (*it) == resource ) {
751 if ( (*it)->readOnly() || !(*it)->isOpen() ) 751 if ( (*it)->readOnly() || !(*it)->isOpen() )
752 return 0; 752 return 0;
753 else 753 else
754 return (*it)->requestSaveTicket(); 754 return (*it)->requestSaveTicket();
755 } 755 }
756 } 756 }
757 757
758 return 0; 758 return 0;
759} 759}
760//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 760//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
761void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 761void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
762{ 762{
763 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 763 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
764 //qDebug("block insert "); 764 //qDebug("block insert ");
765 return; 765 return;
766 } 766 }
767 //qDebug("inserting.... %s ",a.uid().latin1() ); 767 //qDebug("inserting.... %s ",a.uid().latin1() );
768 bool found = false; 768 bool found = false;
769 Addressee::List::Iterator it; 769 Addressee::List::Iterator it;
770 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 770 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
771 if ( a.uid() == (*it).uid() ) { 771 if ( a.uid() == (*it).uid() ) {
772 772
773 bool changed = false; 773 bool changed = false;
774 Addressee addr = a; 774 Addressee addr = a;
775 if ( addr != (*it) ) 775 if ( addr != (*it) )
776 changed = true; 776 changed = true;
777 777
778 if ( takeResource ) { 778 if ( takeResource ) {
779 Resource * res = (*it).resource(); 779 Resource * res = (*it).resource();
780 (*it) = a; 780 (*it) = a;
781 (*it).setResource( res ); 781 (*it).setResource( res );
782 } else { 782 } else {
783 (*it) = a; 783 (*it) = a;
784 if ( (*it).resource() == 0 ) 784 if ( (*it).resource() == 0 )
785 (*it).setResource( standardResource() ); 785 (*it).setResource( standardResource() );
786 } 786 }
787 if ( changed ) { 787 if ( changed ) {
788 if ( setRev ) { 788 if ( setRev ) {
789 789
790 // get rid of micro seconds 790 // get rid of micro seconds
791 QDateTime dt = QDateTime::currentDateTime(); 791 QDateTime dt = QDateTime::currentDateTime();
792 QTime t = dt.time(); 792 QTime t = dt.time();
793 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 793 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
794 (*it).setRevision( dt ); 794 (*it).setRevision( dt );
795 } 795 }
796 (*it).setChanged( true ); 796 (*it).setChanged( true );
797 } 797 }
798 798
799 found = true; 799 found = true;
800 } else { 800 } else {
801 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 801 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
802 QString name = (*it).uid().mid( 19 ); 802 QString name = (*it).uid().mid( 19 );
803 Addressee b = a; 803 Addressee b = a;
804 QString id = b.getID( name ); 804 QString id = b.getID( name );
805 if ( ! id.isEmpty() ) { 805 if ( ! id.isEmpty() ) {
806 QString des = (*it).note(); 806 QString des = (*it).note();
807 int startN; 807 int startN;
808 if( (startN = des.find( id ) ) >= 0 ) { 808 if( (startN = des.find( id ) ) >= 0 ) {
809 int endN = des.find( ",", startN+1 ); 809 int endN = des.find( ",", startN+1 );
810 des = des.left( startN ) + des.mid( endN+1 ); 810 des = des.left( startN ) + des.mid( endN+1 );
811 (*it).setNote( des ); 811 (*it).setNote( des );
812 } 812 }
813 } 813 }
814 } 814 }
815 } 815 }
816 } 816 }
817 if ( found ) 817 if ( found )
818 return; 818 return;
819 d->mAddressees.append( a ); 819 d->mAddressees.append( a );
820 Addressee& addr = d->mAddressees.last(); 820 Addressee& addr = d->mAddressees.last();
821 if ( addr.resource() == 0 ) 821 if ( addr.resource() == 0 )
822 addr.setResource( standardResource() ); 822 addr.setResource( standardResource() );
823 823
824 addr.setChanged( true ); 824 addr.setChanged( true );
825} 825}
826 826
827void AddressBook::removeAddressee( const Addressee &a ) 827void AddressBook::removeAddressee( const Addressee &a )
828{ 828{
829 Iterator it; 829 Iterator it;
830 Iterator it2; 830 Iterator it2;
831 bool found = false; 831 bool found = false;
832 for ( it = begin(); it != end(); ++it ) { 832 for ( it = begin(); it != end(); ++it ) {
833 if ( a.uid() == (*it).uid() ) { 833 if ( a.uid() == (*it).uid() ) {
834 found = true; 834 found = true;
835 it2 = it; 835 it2 = it;
836 } else { 836 } else {
837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
838 QString name = (*it).uid().mid( 19 ); 838 QString name = (*it).uid().mid( 19 );
839 Addressee b = a; 839 Addressee b = a;
840 QString id = b.getID( name ); 840 QString id = b.getID( name );
841 if ( ! id.isEmpty() ) { 841 if ( ! id.isEmpty() ) {
842 QString des = (*it).note(); 842 QString des = (*it).note();
843 if( des.find( id ) < 0 ) { 843 if( des.find( id ) < 0 ) {
844 des += id + ","; 844 des += id + ",";
845 (*it).setNote( des ); 845 (*it).setNote( des );
846 } 846 }
847 } 847 }
848 } 848 }
849 849
850 } 850 }
851 } 851 }
852 852
853 if ( found ) 853 if ( found )
854 removeAddressee( it2 ); 854 removeAddressee( it2 );
855 855
856} 856}
857 857
858void AddressBook::removeSyncAddressees( bool removeDeleted ) 858void AddressBook::removeSyncAddressees( bool removeDeleted )
859{ 859{
860 Iterator it = begin(); 860 Iterator it = begin();
861 Iterator it2 ; 861 Iterator it2 ;
862 QDateTime dt ( QDate( 2004,1,1) ); 862 QDateTime dt ( QDate( 2004,1,1) );
863 while ( it != end() ) { 863 while ( it != end() ) {
864 (*it).setRevision( dt ); 864 (*it).setRevision( dt );
865 if (( *it).IDStr() != "changed" ) { 865 if (( *it).IDStr() != "changed" ) {
866 // "changed" is used for tagging changed addressees when syncing with KDE or OL 866 // "changed" is used for tagging changed addressees when syncing with KDE or OL
867 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 867 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
868 (*it).setIDStr(""); 868 (*it).setIDStr("");
869 } 869 }
870 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 870 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
871 it2 = it; 871 it2 = it;
872 //qDebug("removing %s ",(*it).uid().latin1() ); 872 //qDebug("removing %s ",(*it).uid().latin1() );
873 ++it; 873 ++it;
874 removeAddressee( it2 ); 874 removeAddressee( it2 );
875 } else { 875 } else {
876 //qDebug("skipping %s ",(*it).uid().latin1() ); 876 //qDebug("skipping %s ",(*it).uid().latin1() );
877 if ( removeDeleted ) {
878 // we have no postprocessing in the resource, we have to do it here
879 // we have to compute csum for all, because it could be the first sync
880 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
881
882
883 }
877 ++it; 884 ++it;
878 } 885 }
879 } 886 }
880 deleteRemovedAddressees(); 887 deleteRemovedAddressees();
881} 888}
882 889
883void AddressBook::removeAddressee( const Iterator &it ) 890void AddressBook::removeAddressee( const Iterator &it )
884{ 891{
885 d->mRemovedAddressees.append( (*it) ); 892 d->mRemovedAddressees.append( (*it) );
886 d->mAddressees.remove( it.d->mIt ); 893 d->mAddressees.remove( it.d->mIt );
887} 894}
888 895
889AddressBook::Iterator AddressBook::find( const Addressee &a ) 896AddressBook::Iterator AddressBook::find( const Addressee &a )
890{ 897{
891 Iterator it; 898 Iterator it;
892 for ( it = begin(); it != end(); ++it ) { 899 for ( it = begin(); it != end(); ++it ) {
893 if ( a.uid() == (*it).uid() ) { 900 if ( a.uid() == (*it).uid() ) {
894 return it; 901 return it;
895 } 902 }
896 } 903 }
897 return end(); 904 return end();
898} 905}
899 906
900Addressee AddressBook::findByUid( const QString &uid ) 907Addressee AddressBook::findByUid( const QString &uid )
901{ 908{
902 Iterator it; 909 Iterator it;
903 for ( it = begin(); it != end(); ++it ) { 910 for ( it = begin(); it != end(); ++it ) {
904 if ( uid == (*it).uid() ) { 911 if ( uid == (*it).uid() ) {
905 return *it; 912 return *it;
906 } 913 }
907 } 914 }
908 return Addressee(); 915 return Addressee();
909} 916}
910void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 917void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
911{ 918{
912 //qDebug("AddressBook::preExternSync "); 919 //qDebug("AddressBook::preExternSync ");
913 AddressBook::Iterator it; 920 AddressBook::Iterator it;
914 for ( it = begin(); it != end(); ++it ) { 921 for ( it = begin(); it != end(); ++it ) {
915 (*it).setID( csd, (*it).externalUID() ); 922 (*it).setID( csd, (*it).externalUID() );
916 (*it).computeCsum( csd ); 923 (*it).computeCsum( csd );
917 } 924 }
918 mergeAB( aBook ,csd, isSubset ); 925 mergeAB( aBook ,csd, isSubset );
919} 926}
920void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 927void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID)
921{ 928{
922 //qDebug("AddressBook::postExternSync "); 929 //qDebug("AddressBook::postExternSync ");
923 AddressBook::Iterator it; 930 AddressBook::Iterator it;
924 for ( it = begin(); it != end(); ++it ) { 931 for ( it = begin(); it != end(); ++it ) {
925 // qDebug("check uid %s ", (*it).uid().latin1() ); 932 //qDebug("check uid %s ", (*it).uid().latin1() );
926 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 933 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
927 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 934 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
928 Addressee ad = aBook->findByUid( ( (*it).uid() )); 935 Addressee ad = aBook->findByUid( ( (*it).uid() ));
929 if ( ad.isEmpty() ) { 936 if ( ad.isEmpty() ) {
930 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 937 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
931 } else { 938 } else {
939 (*it).setIDStr(":");
932 (*it).computeCsum( csd ); 940 (*it).computeCsum( csd );
933 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 941 if ( setID ) {
934 ad.setID( csd, (*it).externalUID() ); 942 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
943 ad.setID( csd, (*it).externalUID() );
944 } else
945 ad.setID( csd, "_" );
935 ad.setCsum( csd, (*it).getCsum( csd ) ); 946 ad.setCsum( csd, (*it).getCsum( csd ) );
936 aBook->insertAddressee( ad ); 947 aBook->insertAddressee( ad );
937 } 948 }
938 } 949 }
939 } 950 }
940} 951}
941 952
942bool AddressBook::containsExternalUid( const QString& uid ) 953bool AddressBook::containsExternalUid( const QString& uid )
943{ 954{
944 Iterator it; 955 Iterator it;
945 for ( it = begin(); it != end(); ++it ) { 956 for ( it = begin(); it != end(); ++it ) {
946 if ( uid == (*it).externalUID( ) ) 957 if ( uid == (*it).externalUID( ) )
947 return true; 958 return true;
948 } 959 }
949 return false; 960 return false;
950} 961}
951Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 962Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
952{ 963{
953 Iterator it; 964 Iterator it;
954 for ( it = begin(); it != end(); ++it ) { 965 for ( it = begin(); it != end(); ++it ) {
955 if ( uid == (*it).getID( profile ) ) 966 if ( uid == (*it).getID( profile ) )
956 return (*it); 967 return (*it);
957 } 968 }
958 return Addressee(); 969 return Addressee();
959} 970}
960void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 971void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
961{ 972{
962 Iterator it; 973 Iterator it;
963 Addressee ad; 974 Addressee ad;
964 for ( it = begin(); it != end(); ++it ) { 975 for ( it = begin(); it != end(); ++it ) {
965 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 976 ad = aBook->findByExternUid( (*it).externalUID(), profile );
966 if ( !ad.isEmpty() ) { 977 if ( !ad.isEmpty() ) {
967 (*it).mergeContact( ad ,isSubset); 978 (*it).mergeContact( ad ,isSubset);
968 } 979 }
969 } 980 }
970#if 0 981#if 0
971 // test only 982 // test only
972 for ( it = begin(); it != end(); ++it ) { 983 for ( it = begin(); it != end(); ++it ) {
973 984
974 qDebug("uid %s ", (*it).uid().latin1()); 985 qDebug("uid %s ", (*it).uid().latin1());
975 } 986 }
976#endif 987#endif
977} 988}
978 989
979#if 0 990#if 0
980Addressee::List AddressBook::getExternLastSyncAddressees() 991Addressee::List AddressBook::getExternLastSyncAddressees()
981{ 992{
982 Addressee::List results; 993 Addressee::List results;
983 994
984 Iterator it; 995 Iterator it;
985 for ( it = begin(); it != end(); ++it ) { 996 for ( it = begin(); it != end(); ++it ) {
986 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 997 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
987 if ( (*it).familyName().left(4) == "!E: " ) 998 if ( (*it).familyName().left(4) == "!E: " )
988 results.append( *it ); 999 results.append( *it );
989 } 1000 }
990 } 1001 }
991 1002
992 return results; 1003 return results;
993} 1004}
994#endif 1005#endif
995void AddressBook::resetTempSyncStat() 1006void AddressBook::resetTempSyncStat()
996{ 1007{
997 Iterator it; 1008 Iterator it;
998 for ( it = begin(); it != end(); ++it ) { 1009 for ( it = begin(); it != end(); ++it ) {
999 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 1010 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
1000 } 1011 }
1001 1012
1002} 1013}
1003 1014
1004QStringList AddressBook:: uidList() 1015QStringList AddressBook:: uidList()
1005{ 1016{
1006 QStringList results; 1017 QStringList results;
1007 Iterator it; 1018 Iterator it;
1008 for ( it = begin(); it != end(); ++it ) { 1019 for ( it = begin(); it != end(); ++it ) {
1009 results.append( (*it).uid() ); 1020 results.append( (*it).uid() );
1010 } 1021 }
1011 return results; 1022 return results;
1012} 1023}
1013 1024
1014 1025
1015Addressee::List AddressBook::allAddressees() 1026Addressee::List AddressBook::allAddressees()
1016{ 1027{
1017 return d->mAddressees; 1028 return d->mAddressees;
1018 1029
1019} 1030}
1020 1031
1021Addressee::List AddressBook::findByName( const QString &name ) 1032Addressee::List AddressBook::findByName( const QString &name )
1022{ 1033{
1023 Addressee::List results; 1034 Addressee::List results;
1024 1035
1025 Iterator it; 1036 Iterator it;
1026 for ( it = begin(); it != end(); ++it ) { 1037 for ( it = begin(); it != end(); ++it ) {
1027 if ( name == (*it).realName() ) { 1038 if ( name == (*it).realName() ) {
1028 results.append( *it ); 1039 results.append( *it );
1029 } 1040 }
1030 } 1041 }
1031 1042
1032 return results; 1043 return results;
1033} 1044}
1034 1045
1035Addressee::List AddressBook::findByEmail( const QString &email ) 1046Addressee::List AddressBook::findByEmail( const QString &email )
1036{ 1047{
1037 Addressee::List results; 1048 Addressee::List results;
1038 QStringList mailList; 1049 QStringList mailList;
1039 1050
1040 Iterator it; 1051 Iterator it;
1041 for ( it = begin(); it != end(); ++it ) { 1052 for ( it = begin(); it != end(); ++it ) {
1042 mailList = (*it).emails(); 1053 mailList = (*it).emails();
1043 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1054 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1044 if ( email == (*ite) ) { 1055 if ( email == (*ite) ) {
1045 results.append( *it ); 1056 results.append( *it );
1046 } 1057 }
1047 } 1058 }
1048 } 1059 }
1049 1060
1050 return results; 1061 return results;
1051} 1062}
1052 1063
1053Addressee::List AddressBook::findByCategory( const QString &category ) 1064Addressee::List AddressBook::findByCategory( const QString &category )
1054{ 1065{
1055 Addressee::List results; 1066 Addressee::List results;
1056 1067
1057 Iterator it; 1068 Iterator it;
1058 for ( it = begin(); it != end(); ++it ) { 1069 for ( it = begin(); it != end(); ++it ) {
1059 if ( (*it).hasCategory( category) ) { 1070 if ( (*it).hasCategory( category) ) {
1060 results.append( *it ); 1071 results.append( *it );
1061 } 1072 }
1062 } 1073 }
1063 1074
1064 return results; 1075 return results;
1065} 1076}
1066 1077
1067void AddressBook::dump() const 1078void AddressBook::dump() const
1068{ 1079{
1069 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1080 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1070 1081
1071 ConstIterator it; 1082 ConstIterator it;
1072 for( it = begin(); it != end(); ++it ) { 1083 for( it = begin(); it != end(); ++it ) {
1073 (*it).dump(); 1084 (*it).dump();
1074 } 1085 }
1075 1086
1076 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1087 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1077} 1088}
1078 1089
1079QString AddressBook::identifier() 1090QString AddressBook::identifier()
1080{ 1091{
1081 QStringList identifier; 1092 QStringList identifier;
1082 1093
1083 1094
1084 KRES::Manager<Resource>::ActiveIterator it; 1095 KRES::Manager<Resource>::ActiveIterator it;
1085 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1096 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1086 if ( !(*it)->identifier().isEmpty() ) 1097 if ( !(*it)->identifier().isEmpty() )
1087 identifier.append( (*it)->identifier() ); 1098 identifier.append( (*it)->identifier() );
1088 } 1099 }
1089 1100
1090 return identifier.join( ":" ); 1101 return identifier.join( ":" );
1091} 1102}
1092 1103
1093Field::List AddressBook::fields( int category ) 1104Field::List AddressBook::fields( int category )
1094{ 1105{
1095 if ( d->mAllFields.isEmpty() ) { 1106 if ( d->mAllFields.isEmpty() ) {
1096 d->mAllFields = Field::allFields(); 1107 d->mAllFields = Field::allFields();
1097 } 1108 }
1098 1109
1099 if ( category == Field::All ) return d->mAllFields; 1110 if ( category == Field::All ) return d->mAllFields;
1100 1111
1101 Field::List result; 1112 Field::List result;
1102 Field::List::ConstIterator it; 1113 Field::List::ConstIterator it;
1103 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1114 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1104 if ( (*it)->category() & category ) result.append( *it ); 1115 if ( (*it)->category() & category ) result.append( *it );
1105 } 1116 }
1106 1117
1107 return result; 1118 return result;
1108} 1119}
1109 1120
1110bool AddressBook::addCustomField( const QString &label, int category, 1121bool AddressBook::addCustomField( const QString &label, int category,
1111 const QString &key, const QString &app ) 1122 const QString &key, const QString &app )
1112{ 1123{
1113 if ( d->mAllFields.isEmpty() ) { 1124 if ( d->mAllFields.isEmpty() ) {
1114 d->mAllFields = Field::allFields(); 1125 d->mAllFields = Field::allFields();
1115 } 1126 }
1116//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1127//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1117 QString a = app.isNull() ? KGlobal::getAppName() : app; 1128 QString a = app.isNull() ? KGlobal::getAppName() : app;
1118 1129
1119 QString k = key.isNull() ? label : key; 1130 QString k = key.isNull() ? label : key;
1120 1131
1121 Field *field = Field::createCustomField( label, category, k, a ); 1132 Field *field = Field::createCustomField( label, category, k, a );
1122 1133
1123 if ( !field ) return false; 1134 if ( !field ) return false;
1124 1135
1125 d->mAllFields.append( field ); 1136 d->mAllFields.append( field );
1126 1137
1127 return true; 1138 return true;
1128} 1139}
1129 1140
1130QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1141QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1131{ 1142{
1132 if (!ab.d) return s; 1143 if (!ab.d) return s;
1133 1144
1134 return s << ab.d->mAddressees; 1145 return s << ab.d->mAddressees;
1135} 1146}
1136 1147
1137QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1148QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1138{ 1149{
1139 if (!ab.d) return s; 1150 if (!ab.d) return s;
1140 1151
1141 s >> ab.d->mAddressees; 1152 s >> ab.d->mAddressees;
1142 1153
1143 return s; 1154 return s;
1144} 1155}
1145 1156
1146bool AddressBook::addResource( Resource *resource ) 1157bool AddressBook::addResource( Resource *resource )
1147{ 1158{
1148 if ( !resource->open() ) { 1159 if ( !resource->open() ) {
1149 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1160 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1150 return false; 1161 return false;
1151 } 1162 }
1152 1163
1153 resource->setAddressBook( this ); 1164 resource->setAddressBook( this );
1154 1165
1155 d->mManager->add( resource ); 1166 d->mManager->add( resource );
1156 return true; 1167 return true;
1157} 1168}
1158 1169
1159bool AddressBook::removeResource( Resource *resource ) 1170bool AddressBook::removeResource( Resource *resource )
1160{ 1171{
1161 resource->close(); 1172 resource->close();
1162 1173
1163 if ( resource == standardResource() ) 1174 if ( resource == standardResource() )
1164 d->mManager->setStandardResource( 0 ); 1175 d->mManager->setStandardResource( 0 );
1165 1176
1166 resource->setAddressBook( 0 ); 1177 resource->setAddressBook( 0 );
1167 1178
1168 d->mManager->remove( resource ); 1179 d->mManager->remove( resource );
1169 return true; 1180 return true;
1170} 1181}
1171 1182
1172QPtrList<Resource> AddressBook::resources() 1183QPtrList<Resource> AddressBook::resources()
1173{ 1184{
1174 QPtrList<Resource> list; 1185 QPtrList<Resource> list;
1175 1186
1176// qDebug("AddressBook::resources() 1"); 1187// qDebug("AddressBook::resources() 1");
1177 1188
1178 KRES::Manager<Resource>::ActiveIterator it; 1189 KRES::Manager<Resource>::ActiveIterator it;
1179 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1190 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1180 list.append( *it ); 1191 list.append( *it );
1181 1192
1182 return list; 1193 return list;
1183} 1194}
1184 1195
1185/*US 1196/*US
1186void AddressBook::setErrorHandler( ErrorHandler *handler ) 1197void AddressBook::setErrorHandler( ErrorHandler *handler )
1187{ 1198{
1188 delete d->mErrorHandler; 1199 delete d->mErrorHandler;
1189 d->mErrorHandler = handler; 1200 d->mErrorHandler = handler;
1190} 1201}
1191*/ 1202*/
1192 1203
1193void AddressBook::error( const QString& msg ) 1204void AddressBook::error( const QString& msg )
1194{ 1205{
1195/*US 1206/*US
1196 if ( !d->mErrorHandler ) // create default error handler 1207 if ( !d->mErrorHandler ) // create default error handler
1197 d->mErrorHandler = new ConsoleErrorHandler; 1208 d->mErrorHandler = new ConsoleErrorHandler;
1198 1209
1199 if ( d->mErrorHandler ) 1210 if ( d->mErrorHandler )
1200 d->mErrorHandler->error( msg ); 1211 d->mErrorHandler->error( msg );
1201 else 1212 else
1202 kdError(5700) << "no error handler defined" << endl; 1213 kdError(5700) << "no error handler defined" << endl;
1203*/ 1214*/
1204 kdDebug(5700) << "msg" << endl; 1215 kdDebug(5700) << "msg" << endl;
1205 qDebug(msg); 1216 qDebug(msg);
1206} 1217}
1207 1218
1208void AddressBook::deleteRemovedAddressees() 1219void AddressBook::deleteRemovedAddressees()
1209{ 1220{
1210 Addressee::List::Iterator it; 1221 Addressee::List::Iterator it;
1211 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1222 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1212 Resource *resource = (*it).resource(); 1223 Resource *resource = (*it).resource();
1213 if ( resource && !resource->readOnly() && resource->isOpen() ) 1224 if ( resource && !resource->readOnly() && resource->isOpen() )
1214 resource->removeAddressee( *it ); 1225 resource->removeAddressee( *it );
1215 } 1226 }
1216 1227
1217 d->mRemovedAddressees.clear(); 1228 d->mRemovedAddressees.clear();
1218} 1229}
1219 1230
1220void AddressBook::setStandardResource( Resource *resource ) 1231void AddressBook::setStandardResource( Resource *resource )
1221{ 1232{
1222// qDebug("AddressBook::setStandardResource 1"); 1233// qDebug("AddressBook::setStandardResource 1");
1223 d->mManager->setStandardResource( resource ); 1234 d->mManager->setStandardResource( resource );
1224} 1235}
1225 1236
1226Resource *AddressBook::standardResource() 1237Resource *AddressBook::standardResource()
1227{ 1238{
1228 return d->mManager->standardResource(); 1239 return d->mManager->standardResource();
1229} 1240}
1230 1241
1231KRES::Manager<Resource> *AddressBook::resourceManager() 1242KRES::Manager<Resource> *AddressBook::resourceManager()
1232{ 1243{
1233 return d->mManager; 1244 return d->mManager;
1234} 1245}
1235 1246
1236void AddressBook::cleanUp() 1247void AddressBook::cleanUp()
1237{ 1248{
1238 KRES::Manager<Resource>::ActiveIterator it; 1249 KRES::Manager<Resource>::ActiveIterator it;
1239 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1250 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1240 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1251 if ( !(*it)->readOnly() && (*it)->isOpen() )
1241 (*it)->cleanUp(); 1252 (*it)->cleanUp();
1242 } 1253 }
1243} 1254}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index f124dc9..75f8b51 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,349 +1,349 @@
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 bool saveABphone( QString fileName ); 145 bool saveABphone( QString fileName );
146 void smplifyAddressees(); 146 void smplifyAddressees();
147 void removeSyncInfo( QString syncProfile); 147 void removeSyncInfo( QString syncProfile);
148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); 148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
149 void export2File( QString fileName ); 149 void export2File( QString fileName );
150 bool export2PhoneFormat( QStringList uids ,QString fileName ); 150 bool export2PhoneFormat( QStringList uids ,QString fileName );
151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
152 void setUntagged( bool setNonSyncTagged = false ); 152 void setUntagged( bool setNonSyncTagged = false );
153 void removeUntagged(); 153 void removeUntagged();
154 void findNewExtIds( QString fileName, QString currentSyncDevice ); 154 void findNewExtIds( QString fileName, QString currentSyncDevice );
155 /** 155 /**
156 Returns a iterator for first entry of address book. 156 Returns a iterator for first entry of address book.
157 */ 157 */
158 Iterator begin(); 158 Iterator begin();
159 159
160 /** 160 /**
161 Returns a const iterator for first entry of address book. 161 Returns a const iterator for first entry of address book.
162 */ 162 */
163 ConstIterator begin() const; 163 ConstIterator begin() const;
164 164
165 /** 165 /**
166 Returns a iterator for first entry of address book. 166 Returns a iterator for first entry of address book.
167 */ 167 */
168 Iterator end(); 168 Iterator end();
169 169
170 /** 170 /**
171 Returns a const iterator for first entry of address book. 171 Returns a const iterator for first entry of address book.
172 */ 172 */
173 ConstIterator end() const; 173 ConstIterator end() const;
174 174
175 /** 175 /**
176 Removes all entries from address book. 176 Removes all entries from address book.
177 */ 177 */
178 void clear(); 178 void clear();
179 179
180 /** 180 /**
181 Insert an Addressee object into address book. If an object with the same 181 Insert an Addressee object into address book. If an object with the same
182 unique id already exists in the address book it it replaced by the new 182 unique id already exists in the address book it it replaced by the new
183 one. If not the new object is appended to the address book. 183 one. If not the new object is appended to the address book.
184 */ 184 */
185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
186 186
187 /** 187 /**
188 Removes entry from the address book. 188 Removes entry from the address book.
189 */ 189 */
190 void removeAddressee( const Addressee & ); 190 void removeAddressee( const Addressee & );
191 191
192 /** 192 /**
193 This is like @ref removeAddressee() just above, with the difference that 193 This is like @ref removeAddressee() just above, with the difference that
194 the first element is a iterator, returned by @ref begin(). 194 the first element is a iterator, returned by @ref begin().
195 */ 195 */
196 void removeAddressee( const Iterator & ); 196 void removeAddressee( const Iterator & );
197 197
198 /** 198 /**
199 Find the specified entry in address book. Returns end(), if the entry 199 Find the specified entry in address book. Returns end(), if the entry
200 couldn't be found. 200 couldn't be found.
201 */ 201 */
202 Iterator find( const Addressee & ); 202 Iterator find( const Addressee & );
203 203
204 /** 204 /**
205 Find the entry specified by an unique id. Returns an empty Addressee 205 Find the entry specified by an unique id. Returns an empty Addressee
206 object, if the address book does not contain an entry with this id. 206 object, if the address book does not contain an entry with this id.
207 */ 207 */
208 Addressee findByUid( const QString & ); 208 Addressee findByUid( const QString & );
209 209
210 210
211 /** 211 /**
212 Returns a list of all addressees in the address book. This list can 212 Returns a list of all addressees in the address book. This list can
213 be sorted with @ref KABC::AddresseeList for example. 213 be sorted with @ref KABC::AddresseeList for example.
214 */ 214 */
215 Addressee::List allAddressees(); 215 Addressee::List allAddressees();
216 216
217 /** 217 /**
218 Find all entries with the specified name in the address book. Returns 218 Find all entries with the specified name in the address book. Returns
219 an empty list, if no entries could be found. 219 an empty list, if no entries could be found.
220 */ 220 */
221 Addressee::List findByName( const QString & ); 221 Addressee::List findByName( const QString & );
222 222
223 /** 223 /**
224 Find all entries with the specified email address in the address book. 224 Find all entries with the specified email address in the address book.
225 Returns an empty list, if no entries could be found. 225 Returns an empty list, if no entries could be found.
226 */ 226 */
227 Addressee::List findByEmail( const QString & ); 227 Addressee::List findByEmail( const QString & );
228 228
229 /** 229 /**
230 Find all entries wich have the specified category in the address book. 230 Find all entries wich have the specified category in the address book.
231 Returns an empty list, if no entries could be found. 231 Returns an empty list, if no entries could be found.
232 */ 232 */
233 Addressee::List findByCategory( const QString & ); 233 Addressee::List findByCategory( const QString & );
234 234
235 /** 235 /**
236 Return a string identifying this addressbook. 236 Return a string identifying this addressbook.
237 */ 237 */
238 virtual QString identifier(); 238 virtual QString identifier();
239 239
240 /** 240 /**
241 Used for debug output. 241 Used for debug output.
242 */ 242 */
243 void dump() const; 243 void dump() const;
244 244
245 void emitAddressBookLocked() { emit addressBookLocked( this ); } 245 void emitAddressBookLocked() { emit addressBookLocked( this ); }
246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
247 void emitAddressBookChanged() { emit addressBookChanged( this ); } 247 void emitAddressBookChanged() { emit addressBookChanged( this ); }
248 248
249 /** 249 /**
250 Return list of all Fields known to the address book which are associated 250 Return list of all Fields known to the address book which are associated
251 with the given field category. 251 with the given field category.
252 */ 252 */
253 Field::List fields( int category = Field::All ); 253 Field::List fields( int category = Field::All );
254 254
255 /** 255 /**
256 Add custom field to address book. 256 Add custom field to address book.
257 257
258 @param label User visible label of the field. 258 @param label User visible label of the field.
259 @param category Ored list of field categories. 259 @param category Ored list of field categories.
260 @param key Identifier used as key for reading and writing the field. 260 @param key Identifier used as key for reading and writing the field.
261 @param app String used as application key for reading and writing 261 @param app String used as application key for reading and writing
262 the field. 262 the field.
263 */ 263 */
264 bool addCustomField( const QString &label, int category = Field::All, 264 bool addCustomField( const QString &label, int category = Field::All,
265 const QString &key = QString::null, 265 const QString &key = QString::null,
266 const QString &app = QString::null ); 266 const QString &app = QString::null );
267 267
268 268
269 /** 269 /**
270 Add address book resource. 270 Add address book resource.
271 */ 271 */
272 bool addResource( Resource * ); 272 bool addResource( Resource * );
273 273
274 /** 274 /**
275 Remove address book resource. 275 Remove address book resource.
276 */ 276 */
277 bool removeResource( Resource * ); 277 bool removeResource( Resource * );
278 278
279 /** 279 /**
280 Return pointer list of all resources. 280 Return pointer list of all resources.
281 */ 281 */
282 QPtrList<Resource> resources(); 282 QPtrList<Resource> resources();
283 283
284 /** 284 /**
285 Set the @p ErrorHandler, that is used by @ref error() to 285 Set the @p ErrorHandler, that is used by @ref error() to
286 provide gui-independend error messages. 286 provide gui-independend error messages.
287 */ 287 */
288 void setErrorHandler( ErrorHandler * ); 288 void setErrorHandler( ErrorHandler * );
289 289
290 /** 290 /**
291 Shows gui independend error messages. 291 Shows gui independend error messages.
292 */ 292 */
293 void error( const QString& ); 293 void error( const QString& );
294 294
295 /** 295 /**
296 Query all resources to clean up their lock files 296 Query all resources to clean up their lock files
297 */ 297 */
298 void cleanUp(); 298 void cleanUp();
299 299
300 // sync stuff 300 // sync stuff
301 //Addressee::List getExternLastSyncAddressees(); 301 //Addressee::List getExternLastSyncAddressees();
302 void resetTempSyncStat(); 302 void resetTempSyncStat();
303 QStringList uidList(); 303 QStringList uidList();
304 void removeSyncAddressees( bool removeDeleted = false ); 304 void removeSyncAddressees( bool removeDeleted = false );
305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); 305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
306 Addressee findByExternUid( const QString& uid , const QString& profile ); 306 Addressee findByExternUid( const QString& uid , const QString& profile );
307 bool containsExternalUid( const QString& uid ); 307 bool containsExternalUid( const QString& uid );
308 308
309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); 309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
310 void postExternSync( AddressBook* aBook, const QString& csd ); 310 void postExternSync( AddressBook* aBook, const QString& csd , bool setID );
311 signals: 311 signals:
312 /** 312 /**
313 Emitted, when the address book has changed on disk. 313 Emitted, when the address book has changed on disk.
314 */ 314 */
315 void addressBookChanged( AddressBook * ); 315 void addressBookChanged( AddressBook * );
316 316
317 /** 317 /**
318 Emitted, when the address book has been locked for writing. 318 Emitted, when the address book has been locked for writing.
319 */ 319 */
320 void addressBookLocked( AddressBook * ); 320 void addressBookLocked( AddressBook * );
321 321
322 /** 322 /**
323 Emitted, when the address book has been unlocked. 323 Emitted, when the address book has been unlocked.
324 */ 324 */
325 void addressBookUnlocked( AddressBook * ); 325 void addressBookUnlocked( AddressBook * );
326 326
327 protected: 327 protected:
328 void deleteRemovedAddressees(); 328 void deleteRemovedAddressees();
329 void setStandardResource( Resource * ); 329 void setStandardResource( Resource * );
330 Resource *standardResource(); 330 Resource *standardResource();
331 KRES::Manager<Resource> *resourceManager(); 331 KRES::Manager<Resource> *resourceManager();
332 332
333 void init(const QString &config, const QString &family); 333 void init(const QString &config, const QString &family);
334 334
335 private: 335 private:
336//US QPtrList<Resource> mDummy; // Remove in KDE 4 336//US QPtrList<Resource> mDummy; // Remove in KDE 4
337 337
338 338
339 struct AddressBookData; 339 struct AddressBookData;
340 AddressBookData *d; 340 AddressBookData *d;
341 bool blockLSEchange; 341 bool blockLSEchange;
342}; 342};
343 343
344QDataStream &operator<<( QDataStream &, const AddressBook & ); 344QDataStream &operator<<( QDataStream &, const AddressBook & );
345QDataStream &operator>>( QDataStream &, AddressBook & ); 345QDataStream &operator>>( QDataStream &, AddressBook & );
346 346
347} 347}
348 348
349#endif 349#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index a660a9d..d5a110a 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,2119 +1,2119 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46static bool matchBinaryPatternA( int value, int pattern ); 46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern ); 47static bool matchBinaryPatternP( int value, int pattern );
48 48
49struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
50{ 50{
51 QString uid; 51 QString uid;
52 QString name; 52 QString name;
53 QString formattedName; 53 QString formattedName;
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1; 91 bool tagged :1;
92}; 92};
93 93
94Addressee::Addressee() 94Addressee::Addressee()
95{ 95{
96 mData = new AddresseeData; 96 mData = new AddresseeData;
97 mData->empty = true; 97 mData->empty = true;
98 mData->changed = false; 98 mData->changed = false;
99 mData->resource = 0; 99 mData->resource = 0;
100 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
101 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
103} 103}
104 104
105Addressee::~Addressee() 105Addressee::~Addressee()
106{ 106{
107} 107}
108 108
109Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
110{ 110{
111 mData = a.mData; 111 mData = a.mData;
112} 112}
113 113
114Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
115{ 115{
116 mData = a.mData; 116 mData = a.mData;
117 return (*this); 117 return (*this);
118} 118}
119 119
120Addressee Addressee::copy() 120Addressee Addressee::copy()
121{ 121{
122 Addressee a; 122 Addressee a;
123 *(a.mData) = *mData; 123 *(a.mData) = *mData;
124 return a; 124 return a;
125} 125}
126 126
127void Addressee::detach() 127void Addressee::detach()
128{ 128{
129 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
130 *this = copy(); 130 *this = copy();
131} 131}
132 132
133bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
134{ 134{
135 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
136 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
137 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
138 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
139 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
140 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
141 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
142 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
143 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
144 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
145 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
146 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
147 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
148 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
149 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
150 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
151 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
152 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
153 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
154 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
155 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
156 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
157 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
158 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
159 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
161 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
163 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
164 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
165 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
166 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
167 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
168 168
169 return true; 169 return true;
170} 170}
171 171
172bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
173{ 173{
174 return !( a == *this ); 174 return !( a == *this );
175} 175}
176 176
177bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
178{ 178{
179 return mData->empty; 179 return mData->empty;
180} 180}
181ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
182{ 182{
183 int max = attList.count(); 183 int max = attList.count();
184 ulong cSum = 0; 184 ulong cSum = 0;
185 int j,k,i; 185 int j,k,i;
186 int add; 186 int add;
187 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
188 QString s = attList[i]; 188 QString s = attList[i];
189 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
190 j = s.length(); 190 j = s.length();
191 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
192 int mul = k +1; 192 int mul = k +1;
193 add = s[k].unicode (); 193 add = s[k].unicode ();
194 if ( k < 16 ) 194 if ( k < 16 )
195 mul = mul * mul; 195 mul = mul * mul;
196 int ii = i+1; 196 int ii = i+1;
197 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
198 cSum += add; 198 cSum += add;
199 } 199 }
200 } 200 }
201 201
202 } 202 }
203 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
204 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
205 205
206 return cSum; 206 return cSum;
207 207
208} 208}
209void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
210{ 210{
211 QStringList l; 211 QStringList l;
212 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
216 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
224 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
225 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
226 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
227 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
228 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
231 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
232 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
233 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
234 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
235 if ( mData->url.isValid() ) 235 if ( mData->url.isValid() )
236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
237 KABC::PhoneNumber::List phoneNumbers; 237 KABC::PhoneNumber::List phoneNumbers;
238 KABC::PhoneNumber::List::Iterator phoneIter; 238 KABC::PhoneNumber::List::Iterator phoneIter;
239 239
240 QStringList t; 240 QStringList t;
241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
242 ++phoneIter ) 242 ++phoneIter )
243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
244 t.sort(); 244 t.sort();
245 uint iii; 245 uint iii;
246 for ( iii = 0; iii < t.count(); ++iii) 246 for ( iii = 0; iii < t.count(); ++iii)
247 l.append( t[iii] ); 247 l.append( t[iii] );
248 t = mData->emails; 248 t = mData->emails;
249 t.sort(); 249 t.sort();
250 for ( iii = 0; iii < t.count(); ++iii) 250 for ( iii = 0; iii < t.count(); ++iii)
251 l.append( t[iii] ); 251 l.append( t[iii] );
252 t = mData->categories; 252 t = mData->categories;
253 t.sort(); 253 t.sort();
254 for ( iii = 0; iii < t.count(); ++iii) 254 for ( iii = 0; iii < t.count(); ++iii)
255 l.append( t[iii] ); 255 l.append( t[iii] );
256 t = mData->custom; 256 t = mData->custom;
257 t.sort(); 257 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 258 for ( iii = 0; iii < t.count(); ++iii)
259 l.append( t[iii] ); 259 l.append( t[iii] );
260 KABC::Address::List::Iterator addressIter; 260 KABC::Address::List::Iterator addressIter;
261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
262 ++addressIter ) { 262 ++addressIter ) {
263 t = (*addressIter).asList(); 263 t = (*addressIter).asList();
264 t.sort(); 264 t.sort();
265 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
266 l.append( t[iii] ); 266 l.append( t[iii] );
267 } 267 }
268 uint cs = getCsum4List(l); 268 uint cs = getCsum4List(l);
269 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 269 //qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
270 setCsum( dev, QString::number (cs )); 270 setCsum( dev, QString::number (cs ));
271} 271}
272 272
273void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 273void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
274{ 274{
275 275
276 detach(); 276 detach();
277 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 277 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
278 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 278 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
279 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 279 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
280 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 280 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
281 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 281 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
282 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 282 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
283 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 283 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
284 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 284 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
285 if ( !mData->birthday.isValid() ) 285 if ( !mData->birthday.isValid() )
286 if ( ad.mData->birthday.isValid()) 286 if ( ad.mData->birthday.isValid())
287 mData->birthday = ad.mData->birthday; 287 mData->birthday = ad.mData->birthday;
288 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 288 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
289 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 289 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
290 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 290 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
291 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 291 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
292 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 292 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
293 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 293 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
294 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 294 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
295 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 295 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
296 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 296 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
297 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 297 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
298 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 298 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
299 QStringList t; 299 QStringList t;
300 QStringList tAD; 300 QStringList tAD;
301 uint iii; 301 uint iii;
302 302
303 // ********** phone numbers 303 // ********** phone numbers
304 PhoneNumber::List phoneAD = ad.phoneNumbers(); 304 PhoneNumber::List phoneAD = ad.phoneNumbers();
305 PhoneNumber::List::Iterator phoneItAD; 305 PhoneNumber::List::Iterator phoneItAD;
306 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 306 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
307 bool found = false; 307 bool found = false;
308 PhoneNumber::List::Iterator it; 308 PhoneNumber::List::Iterator it;
309 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 309 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
310 if ( ( *phoneItAD ).contains( (*it) ) ) { 310 if ( ( *phoneItAD ).contains( (*it) ) ) {
311 found = true; 311 found = true;
312 (*it).setType( ( *phoneItAD ).type() ); 312 (*it).setType( ( *phoneItAD ).type() );
313 (*it).setNumber( ( *phoneItAD ).number() ); 313 (*it).setNumber( ( *phoneItAD ).number() );
314 break; 314 break;
315 } 315 }
316 } 316 }
317 if ( isSubSet && ! found ) 317 if ( isSubSet && ! found )
318 mData->phoneNumbers.append( *phoneItAD ); 318 mData->phoneNumbers.append( *phoneItAD );
319 } 319 }
320 if ( isSubSet ) { 320 if ( isSubSet ) {
321 // ************* emails; 321 // ************* emails;
322 t = mData->emails; 322 t = mData->emails;
323 tAD = ad.mData->emails; 323 tAD = ad.mData->emails;
324 for ( iii = 0; iii < tAD.count(); ++iii) 324 for ( iii = 0; iii < tAD.count(); ++iii)
325 if ( !t.contains(tAD[iii] ) ) 325 if ( !t.contains(tAD[iii] ) )
326 mData->emails.append( tAD[iii] ); 326 mData->emails.append( tAD[iii] );
327 } 327 }
328 328
329 // ************* categories; 329 // ************* categories;
330 t = mData->categories; 330 t = mData->categories;
331 tAD = ad.mData->categories; 331 tAD = ad.mData->categories;
332 for ( iii = 0; iii < tAD.count(); ++iii) 332 for ( iii = 0; iii < tAD.count(); ++iii)
333 if ( !t.contains(tAD[iii] ) ) 333 if ( !t.contains(tAD[iii] ) )
334 mData->categories.append( tAD[iii] ); 334 mData->categories.append( tAD[iii] );
335 QStringList::ConstIterator it; 335 QStringList::ConstIterator it;
336 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { 336 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
337 QString qualifiedName = (*it).left( (*it).find( ":" )); 337 QString qualifiedName = (*it).left( (*it).find( ":" ));
338 bool found = false; 338 bool found = false;
339 QStringList::ConstIterator itL; 339 QStringList::ConstIterator itL;
340 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 340 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
341 if ( (*itL).startsWith( qualifiedName ) ) { 341 if ( (*itL).startsWith( qualifiedName ) ) {
342 found = true; 342 found = true;
343 break; 343 break;
344 } 344 }
345 } 345 }
346 if ( ! found ) { 346 if ( ! found ) {
347 mData->custom.append( *it ); 347 mData->custom.append( *it );
348 } 348 }
349 } 349 }
350 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 350 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
351 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 351 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
352 if ( !mData->sound.isIntern() ) { 352 if ( !mData->sound.isIntern() ) {
353 if ( mData->sound.url().isEmpty() ) { 353 if ( mData->sound.url().isEmpty() ) {
354 mData->sound = ad.mData->sound; 354 mData->sound = ad.mData->sound;
355 } 355 }
356 } 356 }
357 if ( !mData->agent.isIntern() ) { 357 if ( !mData->agent.isIntern() ) {
358 if ( mData->agent.url().isEmpty() ) { 358 if ( mData->agent.url().isEmpty() ) {
359 mData->agent = ad.mData->agent; 359 mData->agent = ad.mData->agent;
360 } 360 }
361 } 361 }
362 { 362 {
363 Key::List::Iterator itA; 363 Key::List::Iterator itA;
364 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 364 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
365 bool found = false; 365 bool found = false;
366 Key::List::Iterator it; 366 Key::List::Iterator it;
367 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 367 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
368 if ( (*it) == (*itA)) { 368 if ( (*it) == (*itA)) {
369 found = true; 369 found = true;
370 break; 370 break;
371 371
372 } 372 }
373 } 373 }
374 if ( ! found ) { 374 if ( ! found ) {
375 mData->keys.append( *itA ); 375 mData->keys.append( *itA );
376 } 376 }
377 } 377 }
378 } 378 }
379 KABC::Address::List::Iterator addressIterA; 379 KABC::Address::List::Iterator addressIterA;
380 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { 380 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
381 bool found = false; 381 bool found = false;
382 KABC::Address::List::Iterator addressIter; 382 KABC::Address::List::Iterator addressIter;
383 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 383 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
384 ++addressIter ) { 384 ++addressIter ) {
385 if ( (*addressIter) == (*addressIterA)) { 385 if ( (*addressIter) == (*addressIterA)) {
386 found = true; 386 found = true;
387 (*addressIter).setType( (*addressIterA).type() ); 387 (*addressIter).setType( (*addressIterA).type() );
388 break; 388 break;
389 } 389 }
390 390
391 } 391 }
392 if ( isSubSet && ! found ) { 392 if ( isSubSet && ! found ) {
393 mData->addresses.append( *addressIterA ); 393 mData->addresses.append( *addressIterA );
394 } 394 }
395 } 395 }
396 //qDebug("merge contact %s ", ad.uid().latin1()); 396 //qDebug("merge contact %s ", ad.uid().latin1());
397 setUid( ad.uid() ); 397 setUid( ad.uid() );
398 setRevision( ad.revision() ); 398 setRevision( ad.revision() );
399} 399}
400 400
401bool Addressee::removeVoice() 401bool Addressee::removeVoice()
402{ 402{
403 PhoneNumber::List phoneN = phoneNumbers(); 403 PhoneNumber::List phoneN = phoneNumbers();
404 PhoneNumber::List::Iterator phoneIt; 404 PhoneNumber::List::Iterator phoneIt;
405 bool found = false; 405 bool found = false;
406 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 406 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
407 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 407 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
408 if ((*phoneIt).type() - PhoneNumber::Voice ) { 408 if ((*phoneIt).type() - PhoneNumber::Voice ) {
409 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 409 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
410 insertPhoneNumber( (*phoneIt) ); 410 insertPhoneNumber( (*phoneIt) );
411 found = true; 411 found = true;
412 } 412 }
413 } 413 }
414 414
415 } 415 }
416 return found; 416 return found;
417} 417}
418 418
419bool Addressee::containsAdr(const Addressee& ad ) 419bool Addressee::containsAdr(const Addressee& ad )
420{ 420{
421 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; 421 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
422 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; 422 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
423 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; 423 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
424 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; 424 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
425 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; 425 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
426 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; 426 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
427 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; 427 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
428 428
429 // compare phone numbers 429 // compare phone numbers
430 PhoneNumber::List phoneN = ad.phoneNumbers(); 430 PhoneNumber::List phoneN = ad.phoneNumbers();
431 PhoneNumber::List::Iterator phoneIt; 431 PhoneNumber::List::Iterator phoneIt;
432 bool found = false; 432 bool found = false;
433 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 433 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
434 bool found = false; 434 bool found = false;
435 PhoneNumber::List phoneL = ad.phoneNumbers(); 435 PhoneNumber::List phoneL = ad.phoneNumbers();
436 PhoneNumber::List::Iterator phoneItL; 436 PhoneNumber::List::Iterator phoneItL;
437 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 437 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
438 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 438 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
439 found = true; 439 found = true;
440 break; 440 break;
441 } 441 }
442 } 442 }
443 if ( ! found ) 443 if ( ! found )
444 return false; 444 return false;
445 } 445 }
446 return true; 446 return true;
447 447
448} 448}
449void Addressee::simplifyAddresses() 449void Addressee::simplifyAddresses()
450{ 450{
451 451
452 452
453 Address::List list; 453 Address::List list;
454 Address::List::Iterator it; 454 Address::List::Iterator it;
455 Address::List::Iterator it2; 455 Address::List::Iterator it2;
456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
457 it2 = it; 457 it2 = it;
458 ++it2; 458 ++it2;
459 for( ; it2 != mData->addresses.end(); ++it2 ) { 459 for( ; it2 != mData->addresses.end(); ++it2 ) {
460 if ( (*it) == (*it2) ) { 460 if ( (*it) == (*it2) ) {
461 list.append( *it ); 461 list.append( *it );
462 break; 462 break;
463 } 463 }
464 } 464 }
465 } 465 }
466 for( it = list.begin(); it != list.end(); ++it ) { 466 for( it = list.begin(); it != list.end(); ++it ) {
467 removeAddress( (*it) ); 467 removeAddress( (*it) );
468 } 468 }
469 469
470 list.clear(); 470 list.clear();
471 int max = 2; 471 int max = 2;
472 if ( mData->url.isValid() ) 472 if ( mData->url.isValid() )
473 max = 1; 473 max = 1;
474 if ( mData->addresses.count() <= max ) return ; 474 if ( mData->addresses.count() <= max ) return ;
475 int count = 0; 475 int count = 0;
476 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 476 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
477 if ( count >= max ) 477 if ( count >= max )
478 list.append( *it ); 478 list.append( *it );
479 ++count; 479 ++count;
480 } 480 }
481 for( it = list.begin(); it != list.end(); ++it ) { 481 for( it = list.begin(); it != list.end(); ++it ) {
482 removeAddress( (*it) ); 482 removeAddress( (*it) );
483 } 483 }
484} 484}
485 485
486// removes all emails but the first 486// removes all emails but the first
487// needed by phone sync 487// needed by phone sync
488void Addressee::simplifyEmails() 488void Addressee::simplifyEmails()
489{ 489{
490 if ( mData->emails.count() == 0 ) return ; 490 if ( mData->emails.count() == 0 ) return ;
491 QString email = mData->emails.first(); 491 QString email = mData->emails.first();
492 detach(); 492 detach();
493 mData->emails.clear(); 493 mData->emails.clear();
494 mData->emails.append( email ); 494 mData->emails.append( email );
495} 495}
496 496
497void Addressee::simplifyPhoneNumbers() 497void Addressee::simplifyPhoneNumbers()
498{ 498{
499 int max = 4; 499 int max = 4;
500 int inList = mData->phoneNumbers.count(); 500 int inList = mData->phoneNumbers.count();
501 KABC::PhoneNumber::List removeNumbers; 501 KABC::PhoneNumber::List removeNumbers;
502 KABC::PhoneNumber::List::Iterator phoneIter; 502 KABC::PhoneNumber::List::Iterator phoneIter;
503 if ( inList > max ) { 503 if ( inList > max ) {
504 // delete non-preferred numbers 504 // delete non-preferred numbers
505 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 505 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
506 ++phoneIter ) { 506 ++phoneIter ) {
507 if ( inList > max ) { 507 if ( inList > max ) {
508 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { 508 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
509 removeNumbers.append( ( *phoneIter ) ); 509 removeNumbers.append( ( *phoneIter ) );
510 --inList; 510 --inList;
511 } 511 }
512 } else 512 } else
513 break; 513 break;
514 } 514 }
515 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 515 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
516 ++phoneIter ) { 516 ++phoneIter ) {
517 removePhoneNumber(( *phoneIter )); 517 removePhoneNumber(( *phoneIter ));
518 } 518 }
519 // delete preferred numbers 519 // delete preferred numbers
520 if ( inList > max ) { 520 if ( inList > max ) {
521 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 521 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
522 ++phoneIter ) { 522 ++phoneIter ) {
523 if ( inList > max ) { 523 if ( inList > max ) {
524 removeNumbers.append( ( *phoneIter ) ); 524 removeNumbers.append( ( *phoneIter ) );
525 --inList; 525 --inList;
526 } else 526 } else
527 break; 527 break;
528 } 528 }
529 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 529 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
530 ++phoneIter ) { 530 ++phoneIter ) {
531 removePhoneNumber(( *phoneIter )); 531 removePhoneNumber(( *phoneIter ));
532 } 532 }
533 } 533 }
534 } 534 }
535 // remove non-numeric characters 535 // remove non-numeric characters
536 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 536 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
537 ++phoneIter ) { 537 ++phoneIter ) {
538 if ( ! ( *phoneIter ).simplifyNumber() ) 538 if ( ! ( *phoneIter ).simplifyNumber() )
539 removeNumbers.append( ( *phoneIter ) ); 539 removeNumbers.append( ( *phoneIter ) );
540 } 540 }
541 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 541 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
542 ++phoneIter ) { 542 ++phoneIter ) {
543 removePhoneNumber(( *phoneIter )); 543 removePhoneNumber(( *phoneIter ));
544 } 544 }
545} 545}
546void Addressee::simplifyPhoneNumberTypes() 546void Addressee::simplifyPhoneNumberTypes()
547{ 547{
548 KABC::PhoneNumber::List::Iterator phoneIter; 548 KABC::PhoneNumber::List::Iterator phoneIter;
549 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 549 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
550 ++phoneIter ) 550 ++phoneIter )
551 ( *phoneIter ).simplifyType(); 551 ( *phoneIter ).simplifyType();
552} 552}
553void Addressee::removeID(const QString &prof) 553void Addressee::removeID(const QString &prof)
554{ 554{
555 detach(); 555 detach();
556 if ( prof.isEmpty() ) 556 if ( prof.isEmpty() )
557 mData->mExternalId = ":"; 557 mData->mExternalId = ":";
558 else 558 else
559 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 559 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
560 560
561} 561}
562void Addressee::setID( const QString & prof , const QString & id ) 562void Addressee::setID( const QString & prof , const QString & id )
563{ 563{
564 detach(); 564 detach();
565 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 565 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
566 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 566 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
567} 567}
568void Addressee::setTempSyncStat( int id ) 568void Addressee::setTempSyncStat( int id )
569{ 569{
570 if ( mData->mTempSyncStat == id ) return; 570 if ( mData->mTempSyncStat == id ) return;
571 detach(); 571 detach();
572 mData->mTempSyncStat = id; 572 mData->mTempSyncStat = id;
573} 573}
574int Addressee::tempSyncStat() const 574int Addressee::tempSyncStat() const
575{ 575{
576 return mData->mTempSyncStat; 576 return mData->mTempSyncStat;
577} 577}
578 578
579QString Addressee::getID( const QString & prof) 579QString Addressee::getID( const QString & prof)
580{ 580{
581 return KIdManager::getId ( mData->mExternalId, prof ); 581 return KIdManager::getId ( mData->mExternalId, prof );
582} 582}
583 583
584void Addressee::setCsum( const QString & prof , const QString & id ) 584void Addressee::setCsum( const QString & prof , const QString & id )
585{ 585{
586 detach(); 586 detach();
587 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 587 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
588 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 588 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
589 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 589 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
590} 590}
591 591
592QString Addressee::getCsum( const QString & prof) 592QString Addressee::getCsum( const QString & prof)
593{ 593{
594 return KIdManager::getCsum ( mData->mExternalId, prof ); 594 return KIdManager::getCsum ( mData->mExternalId, prof );
595} 595}
596 596
597void Addressee::setIDStr( const QString & s ) 597void Addressee::setIDStr( const QString & s )
598{ 598{
599 detach(); 599 detach();
600 mData->mExternalId = s; 600 mData->mExternalId = s;
601} 601}
602 602
603QString Addressee::IDStr() const 603QString Addressee::IDStr() const
604{ 604{
605 return mData->mExternalId; 605 return mData->mExternalId;
606} 606}
607 607
608void Addressee::setExternalUID( const QString &id ) 608void Addressee::setExternalUID( const QString &id )
609{ 609{
610 if ( id == mData->externalUID ) return; 610 if ( id == mData->externalUID ) return;
611 detach(); 611 detach();
612 mData->empty = false; 612 mData->empty = false;
613 mData->externalUID = id; 613 mData->externalUID = id;
614} 614}
615 615
616QString Addressee::externalUID() const 616QString Addressee::externalUID() const
617{ 617{
618 return mData->externalUID; 618 return mData->externalUID;
619} 619}
620void Addressee::setOriginalExternalUID( const QString &id ) 620void Addressee::setOriginalExternalUID( const QString &id )
621{ 621{
622 if ( id == mData->originalExternalUID ) return; 622 if ( id == mData->originalExternalUID ) return;
623 detach(); 623 detach();
624 mData->empty = false; 624 mData->empty = false;
625 //qDebug("*******Set orig uid %s ", id.latin1()); 625 //qDebug("*******Set orig uid %s ", id.latin1());
626 mData->originalExternalUID = id; 626 mData->originalExternalUID = id;
627} 627}
628 628
629QString Addressee::originalExternalUID() const 629QString Addressee::originalExternalUID() const
630{ 630{
631 return mData->originalExternalUID; 631 return mData->originalExternalUID;
632} 632}
633 633
634void Addressee::setUid( const QString &id ) 634void Addressee::setUid( const QString &id )
635{ 635{
636 if ( id == mData->uid ) return; 636 if ( id == mData->uid ) return;
637 detach(); 637 detach();
638 //qDebug("****setuid %s ", id.latin1()); 638 //qDebug("****setuid %s ", id.latin1());
639 mData->empty = false; 639 mData->empty = false;
640 mData->uid = id; 640 mData->uid = id;
641} 641}
642 642
643QString Addressee::uid() const 643QString Addressee::uid() const
644{ 644{
645 if ( mData->uid.isEmpty() ) 645 if ( mData->uid.isEmpty() )
646 mData->uid = KApplication::randomString( 10 ); 646 mData->uid = KApplication::randomString( 10 );
647 647
648 return mData->uid; 648 return mData->uid;
649} 649}
650 650
651QString Addressee::uidLabel() 651QString Addressee::uidLabel()
652{ 652{
653 return i18n("Unique Identifier"); 653 return i18n("Unique Identifier");
654} 654}
655 655
656void Addressee::setName( const QString &name ) 656void Addressee::setName( const QString &name )
657{ 657{
658 if ( name == mData->name ) return; 658 if ( name == mData->name ) return;
659 detach(); 659 detach();
660 mData->empty = false; 660 mData->empty = false;
661 mData->name = name; 661 mData->name = name;
662} 662}
663 663
664QString Addressee::name() const 664QString Addressee::name() const
665{ 665{
666 return mData->name; 666 return mData->name;
667} 667}
668 668
669QString Addressee::nameLabel() 669QString Addressee::nameLabel()
670{ 670{
671 return i18n("Name"); 671 return i18n("Name");
672} 672}
673 673
674 674
675void Addressee::setFormattedName( const QString &formattedName ) 675void Addressee::setFormattedName( const QString &formattedName )
676{ 676{
677 if ( formattedName == mData->formattedName ) return; 677 if ( formattedName == mData->formattedName ) return;
678 detach(); 678 detach();
679 mData->empty = false; 679 mData->empty = false;
680 mData->formattedName = formattedName; 680 mData->formattedName = formattedName;
681} 681}
682 682
683QString Addressee::formattedName() const 683QString Addressee::formattedName() const
684{ 684{
685 return mData->formattedName; 685 return mData->formattedName;
686} 686}
687 687
688QString Addressee::formattedNameLabel() 688QString Addressee::formattedNameLabel()
689{ 689{
690 return i18n("Formatted Name"); 690 return i18n("Formatted Name");
691} 691}
692 692
693 693
694void Addressee::setFamilyName( const QString &familyName ) 694void Addressee::setFamilyName( const QString &familyName )
695{ 695{
696 if ( familyName == mData->familyName ) return; 696 if ( familyName == mData->familyName ) return;
697 detach(); 697 detach();
698 mData->empty = false; 698 mData->empty = false;
699 mData->familyName = familyName; 699 mData->familyName = familyName;
700} 700}
701 701
702QString Addressee::familyName() const 702QString Addressee::familyName() const
703{ 703{
704 return mData->familyName; 704 return mData->familyName;
705} 705}
706 706
707QString Addressee::familyNameLabel() 707QString Addressee::familyNameLabel()
708{ 708{
709 return i18n("Family Name"); 709 return i18n("Family Name");
710} 710}
711 711
712 712
713void Addressee::setGivenName( const QString &givenName ) 713void Addressee::setGivenName( const QString &givenName )
714{ 714{
715 if ( givenName == mData->givenName ) return; 715 if ( givenName == mData->givenName ) return;
716 detach(); 716 detach();
717 mData->empty = false; 717 mData->empty = false;
718 mData->givenName = givenName; 718 mData->givenName = givenName;
719} 719}
720 720
721QString Addressee::givenName() const 721QString Addressee::givenName() const
722{ 722{
723 return mData->givenName; 723 return mData->givenName;
724} 724}
725 725
726QString Addressee::givenNameLabel() 726QString Addressee::givenNameLabel()
727{ 727{
728 return i18n("Given Name"); 728 return i18n("Given Name");
729} 729}
730 730
731 731
732void Addressee::setAdditionalName( const QString &additionalName ) 732void Addressee::setAdditionalName( const QString &additionalName )
733{ 733{
734 if ( additionalName == mData->additionalName ) return; 734 if ( additionalName == mData->additionalName ) return;
735 detach(); 735 detach();
736 mData->empty = false; 736 mData->empty = false;
737 mData->additionalName = additionalName; 737 mData->additionalName = additionalName;
738} 738}
739 739
740QString Addressee::additionalName() const 740QString Addressee::additionalName() const
741{ 741{
742 return mData->additionalName; 742 return mData->additionalName;
743} 743}
744 744
745QString Addressee::additionalNameLabel() 745QString Addressee::additionalNameLabel()
746{ 746{
747 return i18n("Additional Names"); 747 return i18n("Additional Names");
748} 748}
749 749
750 750
751void Addressee::setPrefix( const QString &prefix ) 751void Addressee::setPrefix( const QString &prefix )
752{ 752{
753 if ( prefix == mData->prefix ) return; 753 if ( prefix == mData->prefix ) return;
754 detach(); 754 detach();
755 mData->empty = false; 755 mData->empty = false;
756 mData->prefix = prefix; 756 mData->prefix = prefix;
757} 757}
758 758
759QString Addressee::prefix() const 759QString Addressee::prefix() const
760{ 760{
761 return mData->prefix; 761 return mData->prefix;
762} 762}
763 763
764QString Addressee::prefixLabel() 764QString Addressee::prefixLabel()
765{ 765{
766 return i18n("Honorific Prefixes"); 766 return i18n("Honorific Prefixes");
767} 767}
768 768
769 769
770void Addressee::setSuffix( const QString &suffix ) 770void Addressee::setSuffix( const QString &suffix )
771{ 771{
772 if ( suffix == mData->suffix ) return; 772 if ( suffix == mData->suffix ) return;
773 detach(); 773 detach();
774 mData->empty = false; 774 mData->empty = false;
775 mData->suffix = suffix; 775 mData->suffix = suffix;
776} 776}
777 777
778QString Addressee::suffix() const 778QString Addressee::suffix() const
779{ 779{
780 return mData->suffix; 780 return mData->suffix;
781} 781}
782 782
783QString Addressee::suffixLabel() 783QString Addressee::suffixLabel()
784{ 784{
785 return i18n("Honorific Suffixes"); 785 return i18n("Honorific Suffixes");
786} 786}
787 787
788 788
789void Addressee::setNickName( const QString &nickName ) 789void Addressee::setNickName( const QString &nickName )
790{ 790{
791 if ( nickName == mData->nickName ) return; 791 if ( nickName == mData->nickName ) return;
792 detach(); 792 detach();
793 mData->empty = false; 793 mData->empty = false;
794 mData->nickName = nickName; 794 mData->nickName = nickName;
795} 795}
796 796
797QString Addressee::nickName() const 797QString Addressee::nickName() const
798{ 798{
799 return mData->nickName; 799 return mData->nickName;
800} 800}
801 801
802QString Addressee::nickNameLabel() 802QString Addressee::nickNameLabel()
803{ 803{
804 return i18n("Nick Name"); 804 return i18n("Nick Name");
805} 805}
806 806
807 807
808void Addressee::setBirthday( const QDateTime &birthday ) 808void Addressee::setBirthday( const QDateTime &birthday )
809{ 809{
810 if ( birthday == mData->birthday ) return; 810 if ( birthday == mData->birthday ) return;
811 detach(); 811 detach();
812 mData->empty = false; 812 mData->empty = false;
813 mData->birthday = birthday; 813 mData->birthday = birthday;
814} 814}
815 815
816QDateTime Addressee::birthday() const 816QDateTime Addressee::birthday() const
817{ 817{
818 return mData->birthday; 818 return mData->birthday;
819} 819}
820 820
821QString Addressee::birthdayLabel() 821QString Addressee::birthdayLabel()
822{ 822{
823 return i18n("Birthday"); 823 return i18n("Birthday");
824} 824}
825 825
826 826
827QString Addressee::homeAddressStreetLabel() 827QString Addressee::homeAddressStreetLabel()
828{ 828{
829 return i18n("Home Address Street"); 829 return i18n("Home Address Street");
830} 830}
831 831
832 832
833QString Addressee::homeAddressLocalityLabel() 833QString Addressee::homeAddressLocalityLabel()
834{ 834{
835 return i18n("Home Address Locality"); 835 return i18n("Home Address Locality");
836} 836}
837 837
838 838
839QString Addressee::homeAddressRegionLabel() 839QString Addressee::homeAddressRegionLabel()
840{ 840{
841 return i18n("Home Address Region"); 841 return i18n("Home Address Region");
842} 842}
843 843
844 844
845QString Addressee::homeAddressPostalCodeLabel() 845QString Addressee::homeAddressPostalCodeLabel()
846{ 846{
847 return i18n("Home Address Postal Code"); 847 return i18n("Home Address Postal Code");
848} 848}
849 849
850 850
851QString Addressee::homeAddressCountryLabel() 851QString Addressee::homeAddressCountryLabel()
852{ 852{
853 return i18n("Home Address Country"); 853 return i18n("Home Address Country");
854} 854}
855 855
856 856
857QString Addressee::homeAddressLabelLabel() 857QString Addressee::homeAddressLabelLabel()
858{ 858{
859 return i18n("Home Address Label"); 859 return i18n("Home Address Label");
860} 860}
861 861
862 862
863QString Addressee::businessAddressStreetLabel() 863QString Addressee::businessAddressStreetLabel()
864{ 864{
865 return i18n("Business Address Street"); 865 return i18n("Business Address Street");
866} 866}
867 867
868 868
869QString Addressee::businessAddressLocalityLabel() 869QString Addressee::businessAddressLocalityLabel()
870{ 870{
871 return i18n("Business Address Locality"); 871 return i18n("Business Address Locality");
872} 872}
873 873
874 874
875QString Addressee::businessAddressRegionLabel() 875QString Addressee::businessAddressRegionLabel()
876{ 876{
877 return i18n("Business Address Region"); 877 return i18n("Business Address Region");
878} 878}
879 879
880 880
881QString Addressee::businessAddressPostalCodeLabel() 881QString Addressee::businessAddressPostalCodeLabel()
882{ 882{
883 return i18n("Business Address Postal Code"); 883 return i18n("Business Address Postal Code");
884} 884}
885 885
886 886
887QString Addressee::businessAddressCountryLabel() 887QString Addressee::businessAddressCountryLabel()
888{ 888{
889 return i18n("Business Address Country"); 889 return i18n("Business Address Country");
890} 890}
891 891
892 892
893QString Addressee::businessAddressLabelLabel() 893QString Addressee::businessAddressLabelLabel()
894{ 894{
895 return i18n("Business Address Label"); 895 return i18n("Business Address Label");
896} 896}
897 897
898 898
899QString Addressee::homePhoneLabel() 899QString Addressee::homePhoneLabel()
900{ 900{
901 return i18n("Home Phone"); 901 return i18n("Home Phone");
902} 902}
903 903
904 904
905QString Addressee::businessPhoneLabel() 905QString Addressee::businessPhoneLabel()
906{ 906{
907 return i18n("Business Phone"); 907 return i18n("Business Phone");
908} 908}
909 909
910 910
911QString Addressee::mobilePhoneLabel() 911QString Addressee::mobilePhoneLabel()
912{ 912{
913 return i18n("Mobile Phone"); 913 return i18n("Mobile Phone");
914} 914}
915 915
916 916
917QString Addressee::homeFaxLabel() 917QString Addressee::homeFaxLabel()
918{ 918{
919 return i18n("Home Fax"); 919 return i18n("Home Fax");
920} 920}
921 921
922 922
923QString Addressee::businessFaxLabel() 923QString Addressee::businessFaxLabel()
924{ 924{
925 return i18n("Business Fax"); 925 return i18n("Business Fax");
926} 926}
927 927
928 928
929QString Addressee::carPhoneLabel() 929QString Addressee::carPhoneLabel()
930{ 930{
931 return i18n("Car Phone"); 931 return i18n("Car Phone");
932} 932}
933 933
934 934
935QString Addressee::isdnLabel() 935QString Addressee::isdnLabel()
936{ 936{
937 return i18n("ISDN"); 937 return i18n("ISDN");
938} 938}
939 939
940 940
941QString Addressee::pagerLabel() 941QString Addressee::pagerLabel()
942{ 942{
943 return i18n("Pager"); 943 return i18n("Pager");
944} 944}
945 945
946QString Addressee::sipLabel() 946QString Addressee::sipLabel()
947{ 947{
948 return i18n("SIP"); 948 return i18n("SIP");
949} 949}
950 950
951QString Addressee::emailLabel() 951QString Addressee::emailLabel()
952{ 952{
953 return i18n("Email Address"); 953 return i18n("Email Address");
954} 954}
955 955
956 956
957void Addressee::setMailer( const QString &mailer ) 957void Addressee::setMailer( const QString &mailer )
958{ 958{
959 if ( mailer == mData->mailer ) return; 959 if ( mailer == mData->mailer ) return;
960 detach(); 960 detach();
961 mData->empty = false; 961 mData->empty = false;
962 mData->mailer = mailer; 962 mData->mailer = mailer;
963} 963}
964 964
965QString Addressee::mailer() const 965QString Addressee::mailer() const
966{ 966{
967 return mData->mailer; 967 return mData->mailer;
968} 968}
969 969
970QString Addressee::mailerLabel() 970QString Addressee::mailerLabel()
971{ 971{
972 return i18n("Mail Client"); 972 return i18n("Mail Client");
973} 973}
974 974
975 975
976void Addressee::setTimeZone( const TimeZone &timeZone ) 976void Addressee::setTimeZone( const TimeZone &timeZone )
977{ 977{
978 if ( timeZone == mData->timeZone ) return; 978 if ( timeZone == mData->timeZone ) return;
979 detach(); 979 detach();
980 mData->empty = false; 980 mData->empty = false;
981 mData->timeZone = timeZone; 981 mData->timeZone = timeZone;
982} 982}
983 983
984TimeZone Addressee::timeZone() const 984TimeZone Addressee::timeZone() const
985{ 985{
986 return mData->timeZone; 986 return mData->timeZone;
987} 987}
988 988
989QString Addressee::timeZoneLabel() 989QString Addressee::timeZoneLabel()
990{ 990{
991 return i18n("Time Zone"); 991 return i18n("Time Zone");
992} 992}
993 993
994 994
995void Addressee::setGeo( const Geo &geo ) 995void Addressee::setGeo( const Geo &geo )
996{ 996{
997 if ( geo == mData->geo ) return; 997 if ( geo == mData->geo ) return;
998 detach(); 998 detach();
999 mData->empty = false; 999 mData->empty = false;
1000 mData->geo = geo; 1000 mData->geo = geo;
1001} 1001}
1002 1002
1003Geo Addressee::geo() const 1003Geo Addressee::geo() const
1004{ 1004{
1005 return mData->geo; 1005 return mData->geo;
1006} 1006}
1007 1007
1008QString Addressee::geoLabel() 1008QString Addressee::geoLabel()
1009{ 1009{
1010 return i18n("Geographic Position"); 1010 return i18n("Geographic Position");
1011} 1011}
1012 1012
1013 1013
1014void Addressee::setTitle( const QString &title ) 1014void Addressee::setTitle( const QString &title )
1015{ 1015{
1016 if ( title == mData->title ) return; 1016 if ( title == mData->title ) return;
1017 detach(); 1017 detach();
1018 mData->empty = false; 1018 mData->empty = false;
1019 mData->title = title; 1019 mData->title = title;
1020} 1020}
1021 1021
1022QString Addressee::title() const 1022QString Addressee::title() const
1023{ 1023{
1024 return mData->title; 1024 return mData->title;
1025} 1025}
1026 1026
1027QString Addressee::titleLabel() 1027QString Addressee::titleLabel()
1028{ 1028{
1029 return i18n("Title"); 1029 return i18n("Title");
1030} 1030}
1031 1031
1032 1032
1033void Addressee::setRole( const QString &role ) 1033void Addressee::setRole( const QString &role )
1034{ 1034{
1035 if ( role == mData->role ) return; 1035 if ( role == mData->role ) return;
1036 detach(); 1036 detach();
1037 mData->empty = false; 1037 mData->empty = false;
1038 mData->role = role; 1038 mData->role = role;
1039} 1039}
1040 1040
1041QString Addressee::role() const 1041QString Addressee::role() const
1042{ 1042{
1043 return mData->role; 1043 return mData->role;
1044} 1044}
1045 1045
1046QString Addressee::roleLabel() 1046QString Addressee::roleLabel()
1047{ 1047{
1048 return i18n("Role"); 1048 return i18n("Role");
1049} 1049}
1050 1050
1051 1051
1052void Addressee::setOrganization( const QString &organization ) 1052void Addressee::setOrganization( const QString &organization )
1053{ 1053{
1054 if ( organization == mData->organization ) return; 1054 if ( organization == mData->organization ) return;
1055 detach(); 1055 detach();
1056 mData->empty = false; 1056 mData->empty = false;
1057 mData->organization = organization; 1057 mData->organization = organization;
1058} 1058}
1059 1059
1060QString Addressee::organization() const 1060QString Addressee::organization() const
1061{ 1061{
1062 return mData->organization; 1062 return mData->organization;
1063} 1063}
1064 1064
1065QString Addressee::organizationLabel() 1065QString Addressee::organizationLabel()
1066{ 1066{
1067 return i18n("Organization"); 1067 return i18n("Organization");
1068} 1068}
1069 1069
1070 1070
1071void Addressee::setNote( const QString &note ) 1071void Addressee::setNote( const QString &note )
1072{ 1072{
1073 if ( note == mData->note ) return; 1073 if ( note == mData->note ) return;
1074 detach(); 1074 detach();
1075 mData->empty = false; 1075 mData->empty = false;
1076 mData->note = note; 1076 mData->note = note;
1077} 1077}
1078 1078
1079QString Addressee::note() const 1079QString Addressee::note() const
1080{ 1080{
1081 return mData->note; 1081 return mData->note;
1082} 1082}
1083 1083
1084QString Addressee::noteLabel() 1084QString Addressee::noteLabel()
1085{ 1085{
1086 return i18n("Note"); 1086 return i18n("Note");
1087} 1087}
1088 1088
1089 1089
1090void Addressee::setProductId( const QString &productId ) 1090void Addressee::setProductId( const QString &productId )
1091{ 1091{
1092 if ( productId == mData->productId ) return; 1092 if ( productId == mData->productId ) return;
1093 detach(); 1093 detach();
1094 mData->empty = false; 1094 mData->empty = false;
1095 mData->productId = productId; 1095 mData->productId = productId;
1096} 1096}
1097 1097
1098QString Addressee::productId() const 1098QString Addressee::productId() const
1099{ 1099{
1100 return mData->productId; 1100 return mData->productId;
1101} 1101}
1102 1102
1103QString Addressee::productIdLabel() 1103QString Addressee::productIdLabel()
1104{ 1104{
1105 return i18n("Product Identifier"); 1105 return i18n("Product Identifier");
1106} 1106}
1107 1107
1108 1108
1109void Addressee::setRevision( const QDateTime &revision ) 1109void Addressee::setRevision( const QDateTime &revision )
1110{ 1110{
1111 if ( revision == mData->revision ) return; 1111 if ( revision == mData->revision ) return;
1112 detach(); 1112 detach();
1113 mData->empty = false; 1113 mData->empty = false;
1114 mData->revision = revision; 1114 mData->revision = revision;
1115} 1115}
1116 1116
1117QDateTime Addressee::revision() const 1117QDateTime Addressee::revision() const
1118{ 1118{
1119 return mData->revision; 1119 return mData->revision;
1120} 1120}
1121 1121
1122QString Addressee::revisionLabel() 1122QString Addressee::revisionLabel()
1123{ 1123{
1124 return i18n("Revision Date"); 1124 return i18n("Revision Date");
1125} 1125}
1126 1126
1127 1127
1128void Addressee::setSortString( const QString &sortString ) 1128void Addressee::setSortString( const QString &sortString )
1129{ 1129{
1130 if ( sortString == mData->sortString ) return; 1130 if ( sortString == mData->sortString ) return;
1131 detach(); 1131 detach();
1132 mData->empty = false; 1132 mData->empty = false;
1133 mData->sortString = sortString; 1133 mData->sortString = sortString;
1134} 1134}
1135 1135
1136QString Addressee::sortString() const 1136QString Addressee::sortString() const
1137{ 1137{
1138 return mData->sortString; 1138 return mData->sortString;
1139} 1139}
1140 1140
1141QString Addressee::sortStringLabel() 1141QString Addressee::sortStringLabel()
1142{ 1142{
1143 return i18n("Sort String"); 1143 return i18n("Sort String");
1144} 1144}
1145 1145
1146 1146
1147void Addressee::setUrl( const KURL &url ) 1147void Addressee::setUrl( const KURL &url )
1148{ 1148{
1149 if ( url == mData->url ) return; 1149 if ( url == mData->url ) return;
1150 detach(); 1150 detach();
1151 mData->empty = false; 1151 mData->empty = false;
1152 mData->url = url; 1152 mData->url = url;
1153} 1153}
1154 1154
1155KURL Addressee::url() const 1155KURL Addressee::url() const
1156{ 1156{
1157 return mData->url; 1157 return mData->url;
1158} 1158}
1159 1159
1160QString Addressee::urlLabel() 1160QString Addressee::urlLabel()
1161{ 1161{
1162 return i18n("URL"); 1162 return i18n("URL");
1163} 1163}
1164 1164
1165 1165
1166void Addressee::setSecrecy( const Secrecy &secrecy ) 1166void Addressee::setSecrecy( const Secrecy &secrecy )
1167{ 1167{
1168 if ( secrecy == mData->secrecy ) return; 1168 if ( secrecy == mData->secrecy ) return;
1169 detach(); 1169 detach();
1170 mData->empty = false; 1170 mData->empty = false;
1171 mData->secrecy = secrecy; 1171 mData->secrecy = secrecy;
1172} 1172}
1173 1173
1174Secrecy Addressee::secrecy() const 1174Secrecy Addressee::secrecy() const
1175{ 1175{
1176 return mData->secrecy; 1176 return mData->secrecy;
1177} 1177}
1178 1178
1179QString Addressee::secrecyLabel() 1179QString Addressee::secrecyLabel()
1180{ 1180{
1181 return i18n("Security Class"); 1181 return i18n("Security Class");
1182} 1182}
1183 1183
1184 1184
1185void Addressee::setLogo( const Picture &logo ) 1185void Addressee::setLogo( const Picture &logo )
1186{ 1186{
1187 if ( logo == mData->logo ) return; 1187 if ( logo == mData->logo ) return;
1188 detach(); 1188 detach();
1189 mData->empty = false; 1189 mData->empty = false;
1190 mData->logo = logo; 1190 mData->logo = logo;
1191} 1191}
1192 1192
1193Picture Addressee::logo() const 1193Picture Addressee::logo() const
1194{ 1194{
1195 return mData->logo; 1195 return mData->logo;
1196} 1196}
1197 1197
1198QString Addressee::logoLabel() 1198QString Addressee::logoLabel()
1199{ 1199{
1200 return i18n("Logo"); 1200 return i18n("Logo");
1201} 1201}
1202 1202
1203 1203
1204void Addressee::setPhoto( const Picture &photo ) 1204void Addressee::setPhoto( const Picture &photo )
1205{ 1205{
1206 if ( photo == mData->photo ) return; 1206 if ( photo == mData->photo ) return;
1207 detach(); 1207 detach();
1208 mData->empty = false; 1208 mData->empty = false;
1209 mData->photo = photo; 1209 mData->photo = photo;
1210} 1210}
1211 1211
1212Picture Addressee::photo() const 1212Picture Addressee::photo() const
1213{ 1213{
1214 return mData->photo; 1214 return mData->photo;
1215} 1215}
1216 1216
1217QString Addressee::photoLabel() 1217QString Addressee::photoLabel()
1218{ 1218{
1219 return i18n("Photo"); 1219 return i18n("Photo");
1220} 1220}
1221 1221
1222 1222
1223void Addressee::setSound( const Sound &sound ) 1223void Addressee::setSound( const Sound &sound )
1224{ 1224{
1225 if ( sound == mData->sound ) return; 1225 if ( sound == mData->sound ) return;
1226 detach(); 1226 detach();
1227 mData->empty = false; 1227 mData->empty = false;
1228 mData->sound = sound; 1228 mData->sound = sound;
1229} 1229}
1230 1230
1231Sound Addressee::sound() const 1231Sound Addressee::sound() const
1232{ 1232{
1233 return mData->sound; 1233 return mData->sound;
1234} 1234}
1235 1235
1236QString Addressee::soundLabel() 1236QString Addressee::soundLabel()
1237{ 1237{
1238 return i18n("Sound"); 1238 return i18n("Sound");
1239} 1239}
1240 1240
1241 1241
1242void Addressee::setAgent( const Agent &agent ) 1242void Addressee::setAgent( const Agent &agent )
1243{ 1243{
1244 if ( agent == mData->agent ) return; 1244 if ( agent == mData->agent ) return;
1245 detach(); 1245 detach();
1246 mData->empty = false; 1246 mData->empty = false;
1247 mData->agent = agent; 1247 mData->agent = agent;
1248} 1248}
1249 1249
1250Agent Addressee::agent() const 1250Agent Addressee::agent() const
1251{ 1251{
1252 return mData->agent; 1252 return mData->agent;
1253} 1253}
1254 1254
1255QString Addressee::agentLabel() 1255QString Addressee::agentLabel()
1256{ 1256{
1257 return i18n("Agent"); 1257 return i18n("Agent");
1258} 1258}
1259 1259
1260 1260
1261 1261
1262void Addressee::setNameFromString( const QString &str ) 1262void Addressee::setNameFromString( const QString &str )
1263{ 1263{
1264 setFormattedName( str ); 1264 setFormattedName( str );
1265 setName( str ); 1265 setName( str );
1266 1266
1267 static bool first = true; 1267 static bool first = true;
1268 static QStringList titles; 1268 static QStringList titles;
1269 static QStringList suffixes; 1269 static QStringList suffixes;
1270 static QStringList prefixes; 1270 static QStringList prefixes;
1271 1271
1272 if ( first ) { 1272 if ( first ) {
1273 first = false; 1273 first = false;
1274 titles += i18n( "Dr." ); 1274 titles += i18n( "Dr." );
1275 titles += i18n( "Miss" ); 1275 titles += i18n( "Miss" );
1276 titles += i18n( "Mr." ); 1276 titles += i18n( "Mr." );
1277 titles += i18n( "Mrs." ); 1277 titles += i18n( "Mrs." );
1278 titles += i18n( "Ms." ); 1278 titles += i18n( "Ms." );
1279 titles += i18n( "Prof." ); 1279 titles += i18n( "Prof." );
1280 1280
1281 suffixes += i18n( "I" ); 1281 suffixes += i18n( "I" );
1282 suffixes += i18n( "II" ); 1282 suffixes += i18n( "II" );
1283 suffixes += i18n( "III" ); 1283 suffixes += i18n( "III" );
1284 suffixes += i18n( "Jr." ); 1284 suffixes += i18n( "Jr." );
1285 suffixes += i18n( "Sr." ); 1285 suffixes += i18n( "Sr." );
1286 1286
1287 prefixes += "van"; 1287 prefixes += "van";
1288 prefixes += "von"; 1288 prefixes += "von";
1289 prefixes += "de"; 1289 prefixes += "de";
1290 1290
1291 KConfig config( locateLocal( "config", "kabcrc") ); 1291 KConfig config( locateLocal( "config", "kabcrc") );
1292 config.setGroup( "General" ); 1292 config.setGroup( "General" );
1293 titles += config.readListEntry( "Prefixes" ); 1293 titles += config.readListEntry( "Prefixes" );
1294 titles.remove( "" ); 1294 titles.remove( "" );
1295 prefixes += config.readListEntry( "Inclusions" ); 1295 prefixes += config.readListEntry( "Inclusions" );
1296 prefixes.remove( "" ); 1296 prefixes.remove( "" );
1297 suffixes += config.readListEntry( "Suffixes" ); 1297 suffixes += config.readListEntry( "Suffixes" );
1298 suffixes.remove( "" ); 1298 suffixes.remove( "" );
1299 } 1299 }
1300 1300
1301 // clear all name parts 1301 // clear all name parts
1302 setPrefix( "" ); 1302 setPrefix( "" );
1303 setGivenName( "" ); 1303 setGivenName( "" );
1304 setAdditionalName( "" ); 1304 setAdditionalName( "" );
1305 setFamilyName( "" ); 1305 setFamilyName( "" );
1306 setSuffix( "" ); 1306 setSuffix( "" );
1307 1307
1308 if ( str.isEmpty() ) 1308 if ( str.isEmpty() )
1309 return; 1309 return;
1310 1310
1311 int i = str.find(','); 1311 int i = str.find(',');
1312 if( i < 0 ) { 1312 if( i < 0 ) {
1313 QStringList parts = QStringList::split( " ", str ); 1313 QStringList parts = QStringList::split( " ", str );
1314 int leftOffset = 0; 1314 int leftOffset = 0;
1315 int rightOffset = parts.count() - 1; 1315 int rightOffset = parts.count() - 1;
1316 1316
1317 QString suffix; 1317 QString suffix;
1318 while ( rightOffset >= 0 ) { 1318 while ( rightOffset >= 0 ) {
1319 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1319 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1320 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1320 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1321 rightOffset--; 1321 rightOffset--;
1322 } else 1322 } else
1323 break; 1323 break;
1324 } 1324 }
1325 setSuffix( suffix ); 1325 setSuffix( suffix );
1326 1326
1327 if ( rightOffset < 0 ) 1327 if ( rightOffset < 0 )
1328 return; 1328 return;
1329 1329
1330 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1330 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1331 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1331 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1332 rightOffset--; 1332 rightOffset--;
1333 } else 1333 } else
1334 setFamilyName( parts[ rightOffset ] ); 1334 setFamilyName( parts[ rightOffset ] );
1335 1335
1336 QString prefix; 1336 QString prefix;
1337 while ( leftOffset < rightOffset ) { 1337 while ( leftOffset < rightOffset ) {
1338 if ( titles.contains( parts[ leftOffset ] ) ) { 1338 if ( titles.contains( parts[ leftOffset ] ) ) {
1339 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1339 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1340 leftOffset++; 1340 leftOffset++;
1341 } else 1341 } else
1342 break; 1342 break;
1343 } 1343 }
1344 setPrefix( prefix ); 1344 setPrefix( prefix );
1345 1345
1346 if ( leftOffset < rightOffset ) { 1346 if ( leftOffset < rightOffset ) {
1347 setGivenName( parts[ leftOffset ] ); 1347 setGivenName( parts[ leftOffset ] );
1348 leftOffset++; 1348 leftOffset++;
1349 } 1349 }
1350 1350
1351 QString additionalName; 1351 QString additionalName;
1352 while ( leftOffset < rightOffset ) { 1352 while ( leftOffset < rightOffset ) {
1353 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1353 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1354 leftOffset++; 1354 leftOffset++;
1355 } 1355 }
1356 setAdditionalName( additionalName ); 1356 setAdditionalName( additionalName );
1357 } else { 1357 } else {
1358 QString part1 = str.left( i ); 1358 QString part1 = str.left( i );
1359 QString part2 = str.mid( i + 1 ); 1359 QString part2 = str.mid( i + 1 );
1360 1360
1361 QStringList parts = QStringList::split( " ", part1 ); 1361 QStringList parts = QStringList::split( " ", part1 );
1362 int leftOffset = 0; 1362 int leftOffset = 0;
1363 int rightOffset = parts.count() - 1; 1363 int rightOffset = parts.count() - 1;
1364 1364
1365 QString suffix; 1365 QString suffix;
1366 while ( rightOffset >= 0 ) { 1366 while ( rightOffset >= 0 ) {
1367 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1367 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1368 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1368 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1369 rightOffset--; 1369 rightOffset--;
1370 } else 1370 } else
1371 break; 1371 break;
1372 } 1372 }
1373 setSuffix( suffix ); 1373 setSuffix( suffix );
1374 1374
1375 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1375 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1376 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1376 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1377 rightOffset--; 1377 rightOffset--;
1378 } else 1378 } else
1379 setFamilyName( parts[ rightOffset ] ); 1379 setFamilyName( parts[ rightOffset ] );
1380 1380
1381 QString prefix; 1381 QString prefix;
1382 while ( leftOffset < rightOffset ) { 1382 while ( leftOffset < rightOffset ) {
1383 if ( titles.contains( parts[ leftOffset ] ) ) { 1383 if ( titles.contains( parts[ leftOffset ] ) ) {
1384 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1384 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1385 leftOffset++; 1385 leftOffset++;
1386 } else 1386 } else
1387 break; 1387 break;
1388 } 1388 }
1389 1389
1390 parts = QStringList::split( " ", part2 ); 1390 parts = QStringList::split( " ", part2 );
1391 1391
1392 leftOffset = 0; 1392 leftOffset = 0;
1393 rightOffset = parts.count(); 1393 rightOffset = parts.count();
1394 1394
1395 while ( leftOffset < rightOffset ) { 1395 while ( leftOffset < rightOffset ) {
1396 if ( titles.contains( parts[ leftOffset ] ) ) { 1396 if ( titles.contains( parts[ leftOffset ] ) ) {
1397 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1397 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1398 leftOffset++; 1398 leftOffset++;
1399 } else 1399 } else
1400 break; 1400 break;
1401 } 1401 }
1402 setPrefix( prefix ); 1402 setPrefix( prefix );
1403 1403
1404 if ( leftOffset < rightOffset ) { 1404 if ( leftOffset < rightOffset ) {
1405 setGivenName( parts[ leftOffset ] ); 1405 setGivenName( parts[ leftOffset ] );
1406 leftOffset++; 1406 leftOffset++;
1407 } 1407 }
1408 1408
1409 QString additionalName; 1409 QString additionalName;
1410 while ( leftOffset < rightOffset ) { 1410 while ( leftOffset < rightOffset ) {
1411 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1411 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1412 leftOffset++; 1412 leftOffset++;
1413 } 1413 }
1414 setAdditionalName( additionalName ); 1414 setAdditionalName( additionalName );
1415 } 1415 }
1416} 1416}
1417 1417
1418QString Addressee::realName() const 1418QString Addressee::realName() const
1419{ 1419{
1420 if ( !formattedName().isEmpty() ) 1420 if ( !formattedName().isEmpty() )
1421 return formattedName(); 1421 return formattedName();
1422 1422
1423 QString n = assembledName(); 1423 QString n = assembledName();
1424 1424
1425 if ( n.isEmpty() ) 1425 if ( n.isEmpty() )
1426 n = name(); 1426 n = name();
1427 1427
1428 return n; 1428 return n;
1429} 1429}
1430 1430
1431QString Addressee::assembledName() const 1431QString Addressee::assembledName() const
1432{ 1432{
1433 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1433 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1434 familyName() + " " + suffix(); 1434 familyName() + " " + suffix();
1435 1435
1436 return name.simplifyWhiteSpace(); 1436 return name.simplifyWhiteSpace();
1437} 1437}
1438 1438
1439QString Addressee::fullEmail( const QString &email ) const 1439QString Addressee::fullEmail( const QString &email ) const
1440{ 1440{
1441 QString e; 1441 QString e;
1442 if ( email.isNull() ) { 1442 if ( email.isNull() ) {
1443 e = preferredEmail(); 1443 e = preferredEmail();
1444 } else { 1444 } else {
1445 e = email; 1445 e = email;
1446 } 1446 }
1447 if ( e.isEmpty() ) return QString::null; 1447 if ( e.isEmpty() ) return QString::null;
1448 1448
1449 QString text; 1449 QString text;
1450 if ( realName().isEmpty() ) 1450 if ( realName().isEmpty() )
1451 text = e; 1451 text = e;
1452 else 1452 else
1453 text = assembledName() + " <" + e + ">"; 1453 text = assembledName() + " <" + e + ">";
1454 1454
1455 return text; 1455 return text;
1456} 1456}
1457 1457
1458void Addressee::insertEmail( const QString &email, bool preferred ) 1458void Addressee::insertEmail( const QString &email, bool preferred )
1459{ 1459{
1460 detach(); 1460 detach();
1461 1461
1462 QStringList::Iterator it = mData->emails.find( email ); 1462 QStringList::Iterator it = mData->emails.find( email );
1463 1463
1464 if ( it != mData->emails.end() ) { 1464 if ( it != mData->emails.end() ) {
1465 if ( !preferred || it == mData->emails.begin() ) return; 1465 if ( !preferred || it == mData->emails.begin() ) return;
1466 mData->emails.remove( it ); 1466 mData->emails.remove( it );
1467 mData->emails.prepend( email ); 1467 mData->emails.prepend( email );
1468 } else { 1468 } else {
1469 if ( preferred ) { 1469 if ( preferred ) {
1470 mData->emails.prepend( email ); 1470 mData->emails.prepend( email );
1471 } else { 1471 } else {
1472 mData->emails.append( email ); 1472 mData->emails.append( email );
1473 } 1473 }
1474 } 1474 }
1475} 1475}
1476 1476
1477void Addressee::removeEmail( const QString &email ) 1477void Addressee::removeEmail( const QString &email )
1478{ 1478{
1479 detach(); 1479 detach();
1480 1480
1481 QStringList::Iterator it = mData->emails.find( email ); 1481 QStringList::Iterator it = mData->emails.find( email );
1482 if ( it == mData->emails.end() ) return; 1482 if ( it == mData->emails.end() ) return;
1483 1483
1484 mData->emails.remove( it ); 1484 mData->emails.remove( it );
1485} 1485}
1486 1486
1487QString Addressee::preferredEmail() const 1487QString Addressee::preferredEmail() const
1488{ 1488{
1489 if ( mData->emails.count() == 0 ) return QString::null; 1489 if ( mData->emails.count() == 0 ) return QString::null;
1490 else return mData->emails.first(); 1490 else return mData->emails.first();
1491} 1491}
1492 1492
1493QStringList Addressee::emails() const 1493QStringList Addressee::emails() const
1494{ 1494{
1495 return mData->emails; 1495 return mData->emails;
1496} 1496}
1497void Addressee::setEmails( const QStringList& emails ) { 1497void Addressee::setEmails( const QStringList& emails ) {
1498 detach(); 1498 detach();
1499 mData->emails = emails; 1499 mData->emails = emails;
1500} 1500}
1501void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1501void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1502{ 1502{
1503 detach(); 1503 detach();
1504 mData->empty = false; 1504 mData->empty = false;
1505 1505
1506 PhoneNumber::List::Iterator it; 1506 PhoneNumber::List::Iterator it;
1507 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1507 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1508 if ( (*it).id() == phoneNumber.id() ) { 1508 if ( (*it).id() == phoneNumber.id() ) {
1509 *it = phoneNumber; 1509 *it = phoneNumber;
1510 return; 1510 return;
1511 } 1511 }
1512 } 1512 }
1513 mData->phoneNumbers.append( phoneNumber ); 1513 mData->phoneNumbers.append( phoneNumber );
1514} 1514}
1515 1515
1516void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1516void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1517{ 1517{
1518 detach(); 1518 detach();
1519 1519
1520 PhoneNumber::List::Iterator it; 1520 PhoneNumber::List::Iterator it;
1521 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1521 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1522 if ( (*it).id() == phoneNumber.id() ) { 1522 if ( (*it).id() == phoneNumber.id() ) {
1523 mData->phoneNumbers.remove( it ); 1523 mData->phoneNumbers.remove( it );
1524 return; 1524 return;
1525 } 1525 }
1526 } 1526 }
1527} 1527}
1528 1528
1529PhoneNumber Addressee::phoneNumber( int type ) const 1529PhoneNumber Addressee::phoneNumber( int type ) const
1530{ 1530{
1531 PhoneNumber phoneNumber( "", type ); 1531 PhoneNumber phoneNumber( "", type );
1532 PhoneNumber::List::ConstIterator it; 1532 PhoneNumber::List::ConstIterator it;
1533 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1533 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1534 if ( matchBinaryPatternP( (*it).type(), type ) ) { 1534 if ( matchBinaryPatternP( (*it).type(), type ) ) {
1535 if ( (*it).type() & PhoneNumber::Pref ) 1535 if ( (*it).type() & PhoneNumber::Pref )
1536 return (*it); 1536 return (*it);
1537 else if ( phoneNumber.number().isEmpty() ) 1537 else if ( phoneNumber.number().isEmpty() )
1538 phoneNumber = (*it); 1538 phoneNumber = (*it);
1539 } 1539 }
1540 } 1540 }
1541 1541
1542 return phoneNumber; 1542 return phoneNumber;
1543} 1543}
1544 1544
1545PhoneNumber::List Addressee::phoneNumbers() const 1545PhoneNumber::List Addressee::phoneNumbers() const
1546{ 1546{
1547 return mData->phoneNumbers; 1547 return mData->phoneNumbers;
1548} 1548}
1549 1549
1550PhoneNumber::List Addressee::phoneNumbers( int type ) const 1550PhoneNumber::List Addressee::phoneNumbers( int type ) const
1551{ 1551{
1552 PhoneNumber::List list; 1552 PhoneNumber::List list;
1553 1553
1554 PhoneNumber::List::ConstIterator it; 1554 PhoneNumber::List::ConstIterator it;
1555 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1555 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1556 if ( matchBinaryPattern( (*it).type(), type ) ) { 1556 if ( matchBinaryPattern( (*it).type(), type ) ) {
1557 list.append( *it ); 1557 list.append( *it );
1558 } 1558 }
1559 } 1559 }
1560 return list; 1560 return list;
1561} 1561}
1562 1562
1563PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1563PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1564{ 1564{
1565 PhoneNumber::List::ConstIterator it; 1565 PhoneNumber::List::ConstIterator it;
1566 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1566 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1567 if ( (*it).id() == id ) { 1567 if ( (*it).id() == id ) {
1568 return *it; 1568 return *it;
1569 } 1569 }
1570 } 1570 }
1571 return PhoneNumber(); 1571 return PhoneNumber();
1572} 1572}
1573 1573
1574void Addressee::insertKey( const Key &key ) 1574void Addressee::insertKey( const Key &key )
1575{ 1575{
1576 detach(); 1576 detach();
1577 mData->empty = false; 1577 mData->empty = false;
1578 1578
1579 Key::List::Iterator it; 1579 Key::List::Iterator it;
1580 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1580 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1581 if ( (*it).id() == key.id() ) { 1581 if ( (*it).id() == key.id() ) {
1582 *it = key; 1582 *it = key;
1583 return; 1583 return;
1584 } 1584 }
1585 } 1585 }
1586 mData->keys.append( key ); 1586 mData->keys.append( key );
1587} 1587}
1588 1588
1589void Addressee::removeKey( const Key &key ) 1589void Addressee::removeKey( const Key &key )
1590{ 1590{
1591 detach(); 1591 detach();
1592 1592
1593 Key::List::Iterator it; 1593 Key::List::Iterator it;
1594 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1594 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1595 if ( (*it).id() == key.id() ) { 1595 if ( (*it).id() == key.id() ) {
1596 mData->keys.remove( key ); 1596 mData->keys.remove( key );
1597 return; 1597 return;
1598 } 1598 }
1599 } 1599 }
1600} 1600}
1601 1601
1602Key Addressee::key( int type, QString customTypeString ) const 1602Key Addressee::key( int type, QString customTypeString ) const
1603{ 1603{
1604 Key::List::ConstIterator it; 1604 Key::List::ConstIterator it;
1605 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1605 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1606 if ( (*it).type() == type ) { 1606 if ( (*it).type() == type ) {
1607 if ( type == Key::Custom ) { 1607 if ( type == Key::Custom ) {
1608 if ( customTypeString.isEmpty() ) { 1608 if ( customTypeString.isEmpty() ) {
1609 return *it; 1609 return *it;
1610 } else { 1610 } else {
1611 if ( (*it).customTypeString() == customTypeString ) 1611 if ( (*it).customTypeString() == customTypeString )
1612 return (*it); 1612 return (*it);
1613 } 1613 }
1614 } else { 1614 } else {
1615 return *it; 1615 return *it;
1616 } 1616 }
1617 } 1617 }
1618 } 1618 }
1619 return Key( QString(), type ); 1619 return Key( QString(), type );
1620} 1620}
1621void Addressee::setKeys( const Key::List& list ) { 1621void Addressee::setKeys( const Key::List& list ) {
1622 detach(); 1622 detach();
1623 mData->keys = list; 1623 mData->keys = list;
1624} 1624}
1625 1625
1626Key::List Addressee::keys() const 1626Key::List Addressee::keys() const
1627{ 1627{
1628 return mData->keys; 1628 return mData->keys;
1629} 1629}
1630 1630
1631Key::List Addressee::keys( int type, QString customTypeString ) const 1631Key::List Addressee::keys( int type, QString customTypeString ) const
1632{ 1632{
1633 Key::List list; 1633 Key::List list;
1634 1634
1635 Key::List::ConstIterator it; 1635 Key::List::ConstIterator it;
1636 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1636 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1637 if ( (*it).type() == type ) { 1637 if ( (*it).type() == type ) {
1638 if ( type == Key::Custom ) { 1638 if ( type == Key::Custom ) {
1639 if ( customTypeString.isEmpty() ) { 1639 if ( customTypeString.isEmpty() ) {
1640 list.append(*it); 1640 list.append(*it);
1641 } else { 1641 } else {
1642 if ( (*it).customTypeString() == customTypeString ) 1642 if ( (*it).customTypeString() == customTypeString )
1643 list.append(*it); 1643 list.append(*it);
1644 } 1644 }
1645 } else { 1645 } else {
1646 list.append(*it); 1646 list.append(*it);
1647 } 1647 }
1648 } 1648 }
1649 } 1649 }
1650 return list; 1650 return list;
1651} 1651}
1652 1652
1653Key Addressee::findKey( const QString &id ) const 1653Key Addressee::findKey( const QString &id ) const
1654{ 1654{
1655 Key::List::ConstIterator it; 1655 Key::List::ConstIterator it;
1656 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1656 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1657 if ( (*it).id() == id ) { 1657 if ( (*it).id() == id ) {
1658 return *it; 1658 return *it;
1659 } 1659 }
1660 } 1660 }
1661 return Key(); 1661 return Key();
1662} 1662}
1663 1663
1664QString Addressee::asString() const 1664QString Addressee::asString() const
1665{ 1665{
1666 return "Smith, agent Smith..."; 1666 return "Smith, agent Smith...";
1667} 1667}
1668 1668
1669void Addressee::dump() const 1669void Addressee::dump() const
1670{ 1670{
1671 return; 1671 return;
1672 kdDebug(5700) << "Addressee {" << endl; 1672 kdDebug(5700) << "Addressee {" << endl;
1673 1673
1674 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1674 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1675 1675
1676 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1676 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1677 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1677 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1678 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1678 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1679 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1679 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1680 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1680 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1681 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1681 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1682 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1682 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1683 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1683 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1684 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1684 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1685 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1685 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1686 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1686 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1687 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1687 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1688 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1688 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1689 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1689 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1690 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1690 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1691 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1691 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1692 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1692 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1693 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1693 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1694 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1694 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1695 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1695 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1696 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1696 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1697 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1697 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1698 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1698 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1699 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1699 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1700 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1700 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1701 1701
1702 kdDebug(5700) << " Emails {" << endl; 1702 kdDebug(5700) << " Emails {" << endl;
1703 QStringList e = emails(); 1703 QStringList e = emails();
1704 QStringList::ConstIterator it; 1704 QStringList::ConstIterator it;
1705 for( it = e.begin(); it != e.end(); ++it ) { 1705 for( it = e.begin(); it != e.end(); ++it ) {
1706 kdDebug(5700) << " " << (*it) << endl; 1706 kdDebug(5700) << " " << (*it) << endl;
1707 } 1707 }
1708 kdDebug(5700) << " }" << endl; 1708 kdDebug(5700) << " }" << endl;
1709 1709
1710 kdDebug(5700) << " PhoneNumbers {" << endl; 1710 kdDebug(5700) << " PhoneNumbers {" << endl;
1711 PhoneNumber::List p = phoneNumbers(); 1711 PhoneNumber::List p = phoneNumbers();
1712 PhoneNumber::List::ConstIterator it2; 1712 PhoneNumber::List::ConstIterator it2;
1713 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1713 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1714 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1714 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1715 } 1715 }
1716 kdDebug(5700) << " }" << endl; 1716 kdDebug(5700) << " }" << endl;
1717 1717
1718 Address::List a = addresses(); 1718 Address::List a = addresses();
1719 Address::List::ConstIterator it3; 1719 Address::List::ConstIterator it3;
1720 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1720 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1721 (*it3).dump(); 1721 (*it3).dump();
1722 } 1722 }
1723 1723
1724 kdDebug(5700) << " Keys {" << endl; 1724 kdDebug(5700) << " Keys {" << endl;
1725 Key::List k = keys(); 1725 Key::List k = keys();
1726 Key::List::ConstIterator it4; 1726 Key::List::ConstIterator it4;
1727 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1727 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1728 kdDebug(5700) << " Type: " << int((*it4).type()) << 1728 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1729 " Key: " << (*it4).textData() << 1729 " Key: " << (*it4).textData() <<
1730 " CustomString: " << (*it4).customTypeString() << endl; 1730 " CustomString: " << (*it4).customTypeString() << endl;
1731 } 1731 }
1732 kdDebug(5700) << " }" << endl; 1732 kdDebug(5700) << " }" << endl;
1733 1733
1734 kdDebug(5700) << "}" << endl; 1734 kdDebug(5700) << "}" << endl;
1735} 1735}
1736 1736
1737 1737
1738void Addressee::insertAddress( const Address &address ) 1738void Addressee::insertAddress( const Address &address )
1739{ 1739{
1740 detach(); 1740 detach();
1741 mData->empty = false; 1741 mData->empty = false;
1742 1742
1743 Address::List::Iterator it; 1743 Address::List::Iterator it;
1744 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1744 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1745 if ( (*it).id() == address.id() ) { 1745 if ( (*it).id() == address.id() ) {
1746 *it = address; 1746 *it = address;
1747 return; 1747 return;
1748 } 1748 }
1749 } 1749 }
1750 mData->addresses.append( address ); 1750 mData->addresses.append( address );
1751} 1751}
1752 1752
1753void Addressee::removeAddress( const Address &address ) 1753void Addressee::removeAddress( const Address &address )
1754{ 1754{
1755 detach(); 1755 detach();
1756 1756
1757 Address::List::Iterator it; 1757 Address::List::Iterator it;
1758 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1758 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1759 if ( (*it).id() == address.id() ) { 1759 if ( (*it).id() == address.id() ) {
1760 mData->addresses.remove( it ); 1760 mData->addresses.remove( it );
1761 return; 1761 return;
1762 } 1762 }
1763 } 1763 }
1764} 1764}
1765 1765
1766Address Addressee::address( int type ) const 1766Address Addressee::address( int type ) const
1767{ 1767{
1768 Address address( type ); 1768 Address address( type );
1769 Address::List::ConstIterator it; 1769 Address::List::ConstIterator it;
1770 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1770 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1771 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1771 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1772 if ( (*it).type() & Address::Pref ) 1772 if ( (*it).type() & Address::Pref )
1773 return (*it); 1773 return (*it);
1774 else if ( address.isEmpty() ) 1774 else if ( address.isEmpty() )
1775 address = (*it); 1775 address = (*it);
1776 } 1776 }
1777 } 1777 }
1778 1778
1779 return address; 1779 return address;
1780} 1780}
1781 1781
1782Address::List Addressee::addresses() const 1782Address::List Addressee::addresses() const
1783{ 1783{
1784 return mData->addresses; 1784 return mData->addresses;
1785} 1785}
1786 1786
1787Address::List Addressee::addresses( int type ) const 1787Address::List Addressee::addresses( int type ) const
1788{ 1788{
1789 Address::List list; 1789 Address::List list;
1790 1790
1791 Address::List::ConstIterator it; 1791 Address::List::ConstIterator it;
1792 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1792 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1793 if ( matchBinaryPattern( (*it).type(), type ) ) { 1793 if ( matchBinaryPattern( (*it).type(), type ) ) {
1794 list.append( *it ); 1794 list.append( *it );
1795 } 1795 }
1796 } 1796 }
1797 1797
1798 return list; 1798 return list;
1799} 1799}
1800 1800
1801Address Addressee::findAddress( const QString &id ) const 1801Address Addressee::findAddress( const QString &id ) const
1802{ 1802{
1803 Address::List::ConstIterator it; 1803 Address::List::ConstIterator it;
1804 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1804 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1805 if ( (*it).id() == id ) { 1805 if ( (*it).id() == id ) {
1806 return *it; 1806 return *it;
1807 } 1807 }
1808 } 1808 }
1809 return Address(); 1809 return Address();
1810} 1810}
1811 1811
1812void Addressee::insertCategory( const QString &c ) 1812void Addressee::insertCategory( const QString &c )
1813{ 1813{
1814 detach(); 1814 detach();
1815 mData->empty = false; 1815 mData->empty = false;
1816 1816
1817 if ( mData->categories.contains( c ) ) return; 1817 if ( mData->categories.contains( c ) ) return;
1818 1818
1819 mData->categories.append( c ); 1819 mData->categories.append( c );
1820} 1820}
1821 1821
1822void Addressee::removeCategory( const QString &c ) 1822void Addressee::removeCategory( const QString &c )
1823{ 1823{
1824 detach(); 1824 detach();
1825 1825
1826 QStringList::Iterator it = mData->categories.find( c ); 1826 QStringList::Iterator it = mData->categories.find( c );
1827 if ( it == mData->categories.end() ) return; 1827 if ( it == mData->categories.end() ) return;
1828 1828
1829 mData->categories.remove( it ); 1829 mData->categories.remove( it );
1830} 1830}
1831 1831
1832bool Addressee::hasCategory( const QString &c ) const 1832bool Addressee::hasCategory( const QString &c ) const
1833{ 1833{
1834 return ( mData->categories.contains( c ) ); 1834 return ( mData->categories.contains( c ) );
1835} 1835}
1836 1836
1837void Addressee::setCategories( const QStringList &c ) 1837void Addressee::setCategories( const QStringList &c )
1838{ 1838{
1839 detach(); 1839 detach();
1840 mData->empty = false; 1840 mData->empty = false;
1841 1841
1842 mData->categories = c; 1842 mData->categories = c;
1843} 1843}
1844 1844
1845QStringList Addressee::categories() const 1845QStringList Addressee::categories() const
1846{ 1846{
1847 return mData->categories; 1847 return mData->categories;
1848} 1848}
1849 1849
1850void Addressee::insertCustom( const QString &app, const QString &name, 1850void Addressee::insertCustom( const QString &app, const QString &name,
1851 const QString &value ) 1851 const QString &value )
1852{ 1852{
1853 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1853 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1854 1854
1855 detach(); 1855 detach();
1856 mData->empty = false; 1856 mData->empty = false;
1857 1857
1858 QString qualifiedName = app + "-" + name + ":"; 1858 QString qualifiedName = app + "-" + name + ":";
1859 1859
1860 QStringList::Iterator it; 1860 QStringList::Iterator it;
1861 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1861 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1862 if ( (*it).startsWith( qualifiedName ) ) { 1862 if ( (*it).startsWith( qualifiedName ) ) {
1863 (*it) = qualifiedName + value; 1863 (*it) = qualifiedName + value;
1864 return; 1864 return;
1865 } 1865 }
1866 } 1866 }
1867 mData->custom.append( qualifiedName + value ); 1867 mData->custom.append( qualifiedName + value );
1868} 1868}
1869 1869
1870void Addressee::removeCustom( const QString &app, const QString &name) 1870void Addressee::removeCustom( const QString &app, const QString &name)
1871{ 1871{
1872 detach(); 1872 detach();
1873 1873
1874 QString qualifiedName = app + "-" + name + ":"; 1874 QString qualifiedName = app + "-" + name + ":";
1875 1875
1876 QStringList::Iterator it; 1876 QStringList::Iterator it;
1877 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1877 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1878 if ( (*it).startsWith( qualifiedName ) ) { 1878 if ( (*it).startsWith( qualifiedName ) ) {
1879 mData->custom.remove( it ); 1879 mData->custom.remove( it );
1880 return; 1880 return;
1881 } 1881 }
1882 } 1882 }
1883} 1883}
1884 1884
1885QString Addressee::custom( const QString &app, const QString &name ) const 1885QString Addressee::custom( const QString &app, const QString &name ) const
1886{ 1886{
1887 QString qualifiedName = app + "-" + name + ":"; 1887 QString qualifiedName = app + "-" + name + ":";
1888 QString value; 1888 QString value;
1889 1889
1890 QStringList::ConstIterator it; 1890 QStringList::ConstIterator it;
1891 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1891 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1892 if ( (*it).startsWith( qualifiedName ) ) { 1892 if ( (*it).startsWith( qualifiedName ) ) {
1893 value = (*it).mid( (*it).find( ":" ) + 1 ); 1893 value = (*it).mid( (*it).find( ":" ) + 1 );
1894 break; 1894 break;
1895 } 1895 }
1896 } 1896 }
1897 1897
1898 return value; 1898 return value;
1899} 1899}
1900 1900
1901void Addressee::setCustoms( const QStringList &l ) 1901void Addressee::setCustoms( const QStringList &l )
1902{ 1902{
1903 detach(); 1903 detach();
1904 mData->empty = false; 1904 mData->empty = false;
1905 1905
1906 mData->custom = l; 1906 mData->custom = l;
1907} 1907}
1908 1908
1909QStringList Addressee::customs() const 1909QStringList Addressee::customs() const
1910{ 1910{
1911 return mData->custom; 1911 return mData->custom;
1912} 1912}
1913 1913
1914void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1914void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1915 QString &email) 1915 QString &email)
1916{ 1916{
1917 int startPos, endPos, len; 1917 int startPos, endPos, len;
1918 QString partA, partB, result; 1918 QString partA, partB, result;
1919 char endCh = '>'; 1919 char endCh = '>';
1920 1920
1921 startPos = rawEmail.find('<'); 1921 startPos = rawEmail.find('<');
1922 if (startPos < 0) 1922 if (startPos < 0)
1923 { 1923 {
1924 startPos = rawEmail.find('('); 1924 startPos = rawEmail.find('(');
1925 endCh = ')'; 1925 endCh = ')';
1926 } 1926 }
1927 if (startPos < 0) 1927 if (startPos < 0)
1928 { 1928 {
1929 // We couldn't find any separators, so we assume the whole string 1929 // We couldn't find any separators, so we assume the whole string
1930 // is the email address 1930 // is the email address
1931 email = rawEmail; 1931 email = rawEmail;
1932 fullName = ""; 1932 fullName = "";
1933 } 1933 }
1934 else 1934 else
1935 { 1935 {
1936 // We have a start position, try to find an end 1936 // We have a start position, try to find an end
1937 endPos = rawEmail.find(endCh, startPos+1); 1937 endPos = rawEmail.find(endCh, startPos+1);
1938 1938
1939 if (endPos < 0) 1939 if (endPos < 0)
1940 { 1940 {
1941 // We couldn't find the end of the email address. We can only 1941 // We couldn't find the end of the email address. We can only
1942 // assume the entire string is the email address. 1942 // assume the entire string is the email address.
1943 email = rawEmail; 1943 email = rawEmail;
1944 fullName = ""; 1944 fullName = "";
1945 } 1945 }
1946 else 1946 else
1947 { 1947 {
1948 // We have a start and end to the email address 1948 // We have a start and end to the email address
1949 1949
1950 // Grab the name part 1950 // Grab the name part
1951 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1951 fullName = rawEmail.left(startPos).stripWhiteSpace();
1952 1952
1953 // grab the email part 1953 // grab the email part
1954 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1954 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1955 1955
1956 // Check that we do not have any extra characters on the end of the 1956 // Check that we do not have any extra characters on the end of the
1957 // strings 1957 // strings
1958 len = fullName.length(); 1958 len = fullName.length();
1959 if (fullName[0]=='"' && fullName[len-1]=='"') 1959 if (fullName[0]=='"' && fullName[len-1]=='"')
1960 fullName = fullName.mid(1, len-2); 1960 fullName = fullName.mid(1, len-2);
1961 else if (fullName[0]=='<' && fullName[len-1]=='>') 1961 else if (fullName[0]=='<' && fullName[len-1]=='>')
1962 fullName = fullName.mid(1, len-2); 1962 fullName = fullName.mid(1, len-2);
1963 else if (fullName[0]=='(' && fullName[len-1]==')') 1963 else if (fullName[0]=='(' && fullName[len-1]==')')
1964 fullName = fullName.mid(1, len-2); 1964 fullName = fullName.mid(1, len-2);
1965 } 1965 }
1966 } 1966 }
1967} 1967}
1968 1968
1969void Addressee::setResource( Resource *resource ) 1969void Addressee::setResource( Resource *resource )
1970{ 1970{
1971 detach(); 1971 detach();
1972 mData->resource = resource; 1972 mData->resource = resource;
1973} 1973}
1974 1974
1975Resource *Addressee::resource() const 1975Resource *Addressee::resource() const
1976{ 1976{
1977 return mData->resource; 1977 return mData->resource;
1978} 1978}
1979 1979
1980//US 1980//US
1981QString Addressee::resourceLabel() 1981QString Addressee::resourceLabel()
1982{ 1982{
1983 return i18n("Resource"); 1983 return i18n("Resource");
1984} 1984}
1985 1985
1986void Addressee::setChanged( bool value ) 1986void Addressee::setChanged( bool value )
1987{ 1987{
1988 detach(); 1988 detach();
1989 mData->changed = value; 1989 mData->changed = value;
1990} 1990}
1991 1991
1992bool Addressee::changed() const 1992bool Addressee::changed() const
1993{ 1993{
1994 return mData->changed; 1994 return mData->changed;
1995} 1995}
1996 1996
1997void Addressee::setTagged( bool value ) 1997void Addressee::setTagged( bool value )
1998{ 1998{
1999 detach(); 1999 detach();
2000 mData->tagged = value; 2000 mData->tagged = value;
2001} 2001}
2002 2002
2003bool Addressee::tagged() const 2003bool Addressee::tagged() const
2004{ 2004{
2005 return mData->tagged; 2005 return mData->tagged;
2006} 2006}
2007 2007
2008QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 2008QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
2009{ 2009{
2010 if (!a.mData) return s; 2010 if (!a.mData) return s;
2011 2011
2012 s << a.uid(); 2012 s << a.uid();
2013 2013
2014 s << a.mData->name; 2014 s << a.mData->name;
2015 s << a.mData->formattedName; 2015 s << a.mData->formattedName;
2016 s << a.mData->familyName; 2016 s << a.mData->familyName;
2017 s << a.mData->givenName; 2017 s << a.mData->givenName;
2018 s << a.mData->additionalName; 2018 s << a.mData->additionalName;
2019 s << a.mData->prefix; 2019 s << a.mData->prefix;
2020 s << a.mData->suffix; 2020 s << a.mData->suffix;
2021 s << a.mData->nickName; 2021 s << a.mData->nickName;
2022 s << a.mData->birthday; 2022 s << a.mData->birthday;
2023 s << a.mData->mailer; 2023 s << a.mData->mailer;
2024 s << a.mData->timeZone; 2024 s << a.mData->timeZone;
2025 s << a.mData->geo; 2025 s << a.mData->geo;
2026 s << a.mData->title; 2026 s << a.mData->title;
2027 s << a.mData->role; 2027 s << a.mData->role;
2028 s << a.mData->organization; 2028 s << a.mData->organization;
2029 s << a.mData->note; 2029 s << a.mData->note;
2030 s << a.mData->productId; 2030 s << a.mData->productId;
2031 s << a.mData->revision; 2031 s << a.mData->revision;
2032 s << a.mData->sortString; 2032 s << a.mData->sortString;
2033 s << a.mData->url; 2033 s << a.mData->url;
2034 s << a.mData->secrecy; 2034 s << a.mData->secrecy;
2035 s << a.mData->logo; 2035 s << a.mData->logo;
2036 s << a.mData->photo; 2036 s << a.mData->photo;
2037 s << a.mData->sound; 2037 s << a.mData->sound;
2038 s << a.mData->agent; 2038 s << a.mData->agent;
2039 s << a.mData->phoneNumbers; 2039 s << a.mData->phoneNumbers;
2040 s << a.mData->addresses; 2040 s << a.mData->addresses;
2041 s << a.mData->emails; 2041 s << a.mData->emails;
2042 s << a.mData->categories; 2042 s << a.mData->categories;
2043 s << a.mData->custom; 2043 s << a.mData->custom;
2044 s << a.mData->keys; 2044 s << a.mData->keys;
2045 return s; 2045 return s;
2046} 2046}
2047 2047
2048QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 2048QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
2049{ 2049{
2050 if (!a.mData) return s; 2050 if (!a.mData) return s;
2051 2051
2052 s >> a.mData->uid; 2052 s >> a.mData->uid;
2053 2053
2054 s >> a.mData->name; 2054 s >> a.mData->name;
2055 s >> a.mData->formattedName; 2055 s >> a.mData->formattedName;
2056 s >> a.mData->familyName; 2056 s >> a.mData->familyName;
2057 s >> a.mData->givenName; 2057 s >> a.mData->givenName;
2058 s >> a.mData->additionalName; 2058 s >> a.mData->additionalName;
2059 s >> a.mData->prefix; 2059 s >> a.mData->prefix;
2060 s >> a.mData->suffix; 2060 s >> a.mData->suffix;
2061 s >> a.mData->nickName; 2061 s >> a.mData->nickName;
2062 s >> a.mData->birthday; 2062 s >> a.mData->birthday;
2063 s >> a.mData->mailer; 2063 s >> a.mData->mailer;
2064 s >> a.mData->timeZone; 2064 s >> a.mData->timeZone;
2065 s >> a.mData->geo; 2065 s >> a.mData->geo;
2066 s >> a.mData->title; 2066 s >> a.mData->title;
2067 s >> a.mData->role; 2067 s >> a.mData->role;
2068 s >> a.mData->organization; 2068 s >> a.mData->organization;
2069 s >> a.mData->note; 2069 s >> a.mData->note;
2070 s >> a.mData->productId; 2070 s >> a.mData->productId;
2071 s >> a.mData->revision; 2071 s >> a.mData->revision;
2072 s >> a.mData->sortString; 2072 s >> a.mData->sortString;
2073 s >> a.mData->url; 2073 s >> a.mData->url;
2074 s >> a.mData->secrecy; 2074 s >> a.mData->secrecy;
2075 s >> a.mData->logo; 2075 s >> a.mData->logo;
2076 s >> a.mData->photo; 2076 s >> a.mData->photo;
2077 s >> a.mData->sound; 2077 s >> a.mData->sound;
2078 s >> a.mData->agent; 2078 s >> a.mData->agent;
2079 s >> a.mData->phoneNumbers; 2079 s >> a.mData->phoneNumbers;
2080 s >> a.mData->addresses; 2080 s >> a.mData->addresses;
2081 s >> a.mData->emails; 2081 s >> a.mData->emails;
2082 s >> a.mData->categories; 2082 s >> a.mData->categories;
2083 s >> a.mData->custom; 2083 s >> a.mData->custom;
2084 s >> a.mData->keys; 2084 s >> a.mData->keys;
2085 2085
2086 a.mData->empty = false; 2086 a.mData->empty = false;
2087 2087
2088 return s; 2088 return s;
2089} 2089}
2090bool matchBinaryPattern( int value, int pattern ) 2090bool matchBinaryPattern( int value, int pattern )
2091{ 2091{
2092 /** 2092 /**
2093 We want to match all telephonnumbers/addresses which have the bits in the 2093 We want to match all telephonnumbers/addresses which have the bits in the
2094 pattern set. More are allowed. 2094 pattern set. More are allowed.
2095 if pattern == 0 we have a special handling, then we want only those with 2095 if pattern == 0 we have a special handling, then we want only those with
2096 exactly no bit set. 2096 exactly no bit set.
2097 */ 2097 */
2098 if ( pattern == 0 ) 2098 if ( pattern == 0 )
2099 return ( value == 0 ); 2099 return ( value == 0 );
2100 else 2100 else
2101 return ( pattern == ( pattern & value ) ); 2101 return ( pattern == ( pattern & value ) );
2102} 2102}
2103 2103
2104bool matchBinaryPatternP( int value, int pattern ) 2104bool matchBinaryPatternP( int value, int pattern )
2105{ 2105{
2106 2106
2107 if ( pattern == 0 ) 2107 if ( pattern == 0 )
2108 return ( value == 0 ); 2108 return ( value == 0 );
2109 else 2109 else
2110 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); 2110 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
2111} 2111}
2112bool matchBinaryPatternA( int value, int pattern ) 2112bool matchBinaryPatternA( int value, int pattern )
2113{ 2113{
2114 2114
2115 if ( pattern == 0 ) 2115 if ( pattern == 0 )
2116 return ( value == 0 ); 2116 return ( value == 0 );
2117 else 2117 else
2118 return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); 2118 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
2119} 2119}
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index ea87929..b0cb986 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,2935 +1,2937 @@
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/*s 24/*s
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 <qtimer.h> 36#include <qtimer.h>
37#include <qlabel.h> 37#include <qlabel.h>
38#include <qregexp.h> 38#include <qregexp.h>
39#include <qlineedit.h> 39#include <qlineedit.h>
40#include <qcheckbox.h> 40#include <qcheckbox.h>
41#include <qpushbutton.h> 41#include <qpushbutton.h>
42#include <qprogressbar.h> 42#include <qprogressbar.h>
43#include <libkdepim/phoneaccess.h> 43#include <libkdepim/phoneaccess.h>
44 44
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46#include <qclipboard.h> 46#include <qclipboard.h>
47#include <qdir.h> 47#include <qdir.h>
48#include <qfile.h> 48#include <qfile.h>
49#include <qapplicaton.h> 49#include <qapplicaton.h>
50#include <qprogressbar.h> 50#include <qprogressbar.h>
51#include <qlayout.h> 51#include <qlayout.h>
52#include <qregexp.h> 52#include <qregexp.h>
53#include <qvbox.h> 53#include <qvbox.h>
54#include <kabc/addresseelist.h> 54#include <kabc/addresseelist.h>
55#include <kabc/errorhandler.h> 55#include <kabc/errorhandler.h>
56#include <kabc/resource.h> 56#include <kabc/resource.h>
57#include <kabc/vcardconverter.h> 57#include <kabc/vcardconverter.h>
58#include <kapplication.h> 58#include <kapplication.h>
59#include <kactionclasses.h> 59#include <kactionclasses.h>
60#include <kcmultidialog.h> 60#include <kcmultidialog.h>
61#include <kdebug.h> 61#include <kdebug.h>
62#include <kdeversion.h> 62#include <kdeversion.h>
63#include <kkeydialog.h> 63#include <kkeydialog.h>
64#include <kmessagebox.h> 64#include <kmessagebox.h>
65#include <kprinter.h> 65#include <kprinter.h>
66#include <kprotocolinfo.h> 66#include <kprotocolinfo.h>
67#include <kresources/selectdialog.h> 67#include <kresources/selectdialog.h>
68#include <kstandarddirs.h> 68#include <kstandarddirs.h>
69#include <ktempfile.h> 69#include <ktempfile.h>
70#include <kxmlguiclient.h> 70#include <kxmlguiclient.h>
71#include <kaboutdata.h> 71#include <kaboutdata.h>
72#include <libkdepim/categoryselectdialog.h> 72#include <libkdepim/categoryselectdialog.h>
73 73
74#include "addresseeutil.h" 74#include "addresseeutil.h"
75#include "addresseeeditordialog.h" 75#include "addresseeeditordialog.h"
76#include "extensionmanager.h" 76#include "extensionmanager.h"
77#include "kstdaction.h" 77#include "kstdaction.h"
78#include "kaddressbookservice.h" 78#include "kaddressbookservice.h"
79#include "ldapsearchdialog.h" 79#include "ldapsearchdialog.h"
80#include "printing/printingwizard.h" 80#include "printing/printingwizard.h"
81#else // KAB_EMBEDDED 81#else // KAB_EMBEDDED
82 82
83#include <kapplication.h> 83#include <kapplication.h>
84#include "KDGanttMinimizeSplitter.h" 84#include "KDGanttMinimizeSplitter.h"
85#include "kaddressbookmain.h" 85#include "kaddressbookmain.h"
86#include "kactioncollection.h" 86#include "kactioncollection.h"
87#include "addresseedialog.h" 87#include "addresseedialog.h"
88//US 88//US
89#include <addresseeview.h> 89#include <addresseeview.h>
90 90
91#include <qapp.h> 91#include <qapp.h>
92#include <qmenubar.h> 92#include <qmenubar.h>
93//#include <qtoolbar.h> 93//#include <qtoolbar.h>
94#include <qmessagebox.h> 94#include <qmessagebox.h>
95#include <kdebug.h> 95#include <kdebug.h>
96#include <kiconloader.h> // needed for SmallIcon 96#include <kiconloader.h> // needed for SmallIcon
97#include <kresources/kcmkresources.h> 97#include <kresources/kcmkresources.h>
98#include <ktoolbar.h> 98#include <ktoolbar.h>
99 99
100 100
101//#include <qlabel.h> 101//#include <qlabel.h>
102 102
103 103
104#ifndef DESKTOP_VERSION 104#ifndef DESKTOP_VERSION
105#include <qpe/ir.h> 105#include <qpe/ir.h>
106#include <qpe/qpemenubar.h> 106#include <qpe/qpemenubar.h>
107#include <qtopia/qcopenvelope_qws.h> 107#include <qtopia/qcopenvelope_qws.h>
108#else 108#else
109 109
110#include <qmenubar.h> 110#include <qmenubar.h>
111#endif 111#endif
112 112
113#endif // KAB_EMBEDDED 113#endif // KAB_EMBEDDED
114#include "kcmconfigs/kcmkabconfig.h" 114#include "kcmconfigs/kcmkabconfig.h"
115#include "kcmconfigs/kcmkdepimconfig.h" 115#include "kcmconfigs/kcmkdepimconfig.h"
116#include "kpimglobalprefs.h" 116#include "kpimglobalprefs.h"
117#include "externalapphandler.h" 117#include "externalapphandler.h"
118 118
119 119
120#include <kresources/selectdialog.h> 120#include <kresources/selectdialog.h>
121#include <kmessagebox.h> 121#include <kmessagebox.h>
122 122
123#include <picture.h> 123#include <picture.h>
124#include <resource.h> 124#include <resource.h>
125 125
126//US#include <qsplitter.h> 126//US#include <qsplitter.h>
127#include <qmap.h> 127#include <qmap.h>
128#include <qdir.h> 128#include <qdir.h>
129#include <qfile.h> 129#include <qfile.h>
130#include <qvbox.h> 130#include <qvbox.h>
131#include <qlayout.h> 131#include <qlayout.h>
132#include <qclipboard.h> 132#include <qclipboard.h>
133#include <qtextstream.h> 133#include <qtextstream.h>
134 134
135#include <libkdepim/categoryselectdialog.h> 135#include <libkdepim/categoryselectdialog.h>
136#include <kabc/vcardconverter.h> 136#include <kabc/vcardconverter.h>
137 137
138 138
139#include "addresseeutil.h" 139#include "addresseeutil.h"
140#include "undocmds.h" 140#include "undocmds.h"
141#include "addresseeeditordialog.h" 141#include "addresseeeditordialog.h"
142#include "viewmanager.h" 142#include "viewmanager.h"
143#include "details/detailsviewcontainer.h" 143#include "details/detailsviewcontainer.h"
144#include "kabprefs.h" 144#include "kabprefs.h"
145#include "xxportmanager.h" 145#include "xxportmanager.h"
146#include "incsearchwidget.h" 146#include "incsearchwidget.h"
147#include "jumpbuttonbar.h" 147#include "jumpbuttonbar.h"
148#include "extensionmanager.h" 148#include "extensionmanager.h"
149#include "addresseeconfig.h" 149#include "addresseeconfig.h"
150#include <kcmultidialog.h> 150#include <kcmultidialog.h>
151 151
152#ifdef _WIN32_ 152#ifdef _WIN32_
153 153
154#include "kaimportoldialog.h" 154#include "kaimportoldialog.h"
155#else 155#else
156#include <unistd.h> 156#include <unistd.h>
157#endif 157#endif
158// sync includes 158// sync includes
159#include <libkdepim/ksyncprofile.h> 159#include <libkdepim/ksyncprofile.h>
160#include <libkdepim/ksyncprefsdialog.h> 160#include <libkdepim/ksyncprefsdialog.h>
161 161
162class KAex2phonePrefs : public QDialog 162class KAex2phonePrefs : public QDialog
163{ 163{
164 public: 164 public:
165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
166 QDialog( parent, name, true ) 166 QDialog( parent, name, true )
167 { 167 {
168 setCaption( i18n("Export to phone options") ); 168 setCaption( i18n("Export to phone options") );
169 QVBoxLayout* lay = new QVBoxLayout( this ); 169 QVBoxLayout* lay = new QVBoxLayout( this );
170 lay->setSpacing( 3 ); 170 lay->setSpacing( 3 );
171 lay->setMargin( 3 ); 171 lay->setMargin( 3 );
172 QLabel *lab; 172 QLabel *lab;
173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
174 lab->setAlignment (AlignHCenter ); 174 lab->setAlignment (AlignHCenter );
175 QHBox* temphb; 175 QHBox* temphb;
176 temphb = new QHBox( this ); 176 temphb = new QHBox( this );
177 new QLabel( i18n("I/O device: "), temphb ); 177 new QLabel( i18n("I/O device: "), temphb );
178 mPhoneDevice = new QLineEdit( temphb); 178 mPhoneDevice = new QLineEdit( temphb);
179 lay->addWidget( temphb ); 179 lay->addWidget( temphb );
180 temphb = new QHBox( this ); 180 temphb = new QHBox( this );
181 new QLabel( i18n("Connection: "), temphb ); 181 new QLabel( i18n("Connection: "), temphb );
182 mPhoneConnection = new QLineEdit( temphb); 182 mPhoneConnection = new QLineEdit( temphb);
183 lay->addWidget( temphb ); 183 lay->addWidget( temphb );
184 temphb = new QHBox( this ); 184 temphb = new QHBox( this );
185 new QLabel( i18n("Model(opt.): "), temphb ); 185 new QLabel( i18n("Model(opt.): "), temphb );
186 mPhoneModel = new QLineEdit( temphb); 186 mPhoneModel = new QLineEdit( temphb);
187 lay->addWidget( temphb ); 187 lay->addWidget( temphb );
188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); 188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
189 // lay->addWidget( mWriteToSim ); 189 // lay->addWidget( mWriteToSim );
190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); 190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
191 lab->setAlignment (AlignHCenter ); 191 lab->setAlignment (AlignHCenter );
192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
193 lay->addWidget( ok ); 193 lay->addWidget( ok );
194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
195 lay->addWidget( cancel ); 195 lay->addWidget( cancel );
196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
198 resize( 220, 240 ); 198 resize( 220, 240 );
199 199
200 } 200 }
201 201
202public: 202public:
203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
204 QCheckBox* mWriteToSim; 204 QCheckBox* mWriteToSim;
205}; 205};
206 206
207 207
208bool pasteWithNewUid = true; 208bool pasteWithNewUid = true;
209 209
210#ifdef KAB_EMBEDDED 210#ifdef KAB_EMBEDDED
211KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 211KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
212 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 212 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
213 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 213 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
214 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 214 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
215#else //KAB_EMBEDDED 215#else //KAB_EMBEDDED
216KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 216KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
217 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 217 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
218 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 218 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
219 mReadWrite( readWrite ), mModified( false ) 219 mReadWrite( readWrite ), mModified( false )
220#endif //KAB_EMBEDDED 220#endif //KAB_EMBEDDED
221{ 221{
222 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 222 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
223 // syncManager->setBlockSave(false); 223 // syncManager->setBlockSave(false);
224 mExtensionBarSplitter = 0; 224 mExtensionBarSplitter = 0;
225 mIsPart = !parent->inherits( "KAddressBookMain" ); 225 mIsPart = !parent->inherits( "KAddressBookMain" );
226 mAddressBook = KABC::StdAddressBook::self(); 226 mAddressBook = KABC::StdAddressBook::self();
227 KABC::StdAddressBook::setAutomaticSave( false ); 227 KABC::StdAddressBook::setAutomaticSave( false );
228 228
229#ifndef KAB_EMBEDDED 229#ifndef KAB_EMBEDDED
230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
231#endif //KAB_EMBEDDED 231#endif //KAB_EMBEDDED
232 232
233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
234 SLOT( addressBookChanged() ) ); 234 SLOT( addressBookChanged() ) );
235 235
236#if 0 236#if 0
237 // LP moved to addressbook init method 237 // LP moved to addressbook init method
238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
239 "X-Department", "KADDRESSBOOK" ); 239 "X-Department", "KADDRESSBOOK" );
240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
241 "X-Profession", "KADDRESSBOOK" ); 241 "X-Profession", "KADDRESSBOOK" );
242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
243 "X-AssistantsName", "KADDRESSBOOK" ); 243 "X-AssistantsName", "KADDRESSBOOK" );
244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
245 "X-ManagersName", "KADDRESSBOOK" ); 245 "X-ManagersName", "KADDRESSBOOK" );
246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
247 "X-SpousesName", "KADDRESSBOOK" ); 247 "X-SpousesName", "KADDRESSBOOK" );
248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
249 "X-Office", "KADDRESSBOOK" ); 249 "X-Office", "KADDRESSBOOK" );
250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
251 "X-IMAddress", "KADDRESSBOOK" ); 251 "X-IMAddress", "KADDRESSBOOK" );
252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
253 "X-Anniversary", "KADDRESSBOOK" ); 253 "X-Anniversary", "KADDRESSBOOK" );
254 254
255 //US added this field to become compatible with Opie/qtopia addressbook 255 //US added this field to become compatible with Opie/qtopia addressbook
256 // values can be "female" or "male" or "". An empty field represents undefined. 256 // values can be "female" or "male" or "". An empty field represents undefined.
257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
258 "X-Gender", "KADDRESSBOOK" ); 258 "X-Gender", "KADDRESSBOOK" );
259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
260 "X-Children", "KADDRESSBOOK" ); 260 "X-Children", "KADDRESSBOOK" );
261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
262 "X-FreeBusyUrl", "KADDRESSBOOK" ); 262 "X-FreeBusyUrl", "KADDRESSBOOK" );
263#endif 263#endif
264 initGUI(); 264 initGUI();
265 265
266 mIncSearchWidget->setFocus(); 266 mIncSearchWidget->setFocus();
267 267
268 268
269 connect( mViewManager, SIGNAL( selected( const QString& ) ), 269 connect( mViewManager, SIGNAL( selected( const QString& ) ),
270 SLOT( setContactSelected( const QString& ) ) ); 270 SLOT( setContactSelected( const QString& ) ) );
271 connect( mViewManager, SIGNAL( executed( const QString& ) ), 271 connect( mViewManager, SIGNAL( executed( const QString& ) ),
272 SLOT( executeContact( const QString& ) ) ); 272 SLOT( executeContact( const QString& ) ) );
273 273
274 connect( mViewManager, SIGNAL( deleteRequest( ) ), 274 connect( mViewManager, SIGNAL( deleteRequest( ) ),
275 SLOT( deleteContacts( ) ) ); 275 SLOT( deleteContacts( ) ) );
276 connect( mViewManager, SIGNAL( modified() ), 276 connect( mViewManager, SIGNAL( modified() ),
277 SLOT( setModified() ) ); 277 SLOT( setModified() ) );
278 278
279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
281 281
282 connect( mXXPortManager, SIGNAL( modified() ), 282 connect( mXXPortManager, SIGNAL( modified() ),
283 SLOT( setModified() ) ); 283 SLOT( setModified() ) );
284 284
285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
286 SLOT( incrementalSearch( const QString& ) ) ); 286 SLOT( incrementalSearch( const QString& ) ) );
287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ), 287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
288 mJumpButtonBar, SLOT( recreateButtons() ) ); 288 mJumpButtonBar, SLOT( recreateButtons() ) );
289 289
290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ), 290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
291 SLOT( sendMail( const QString& ) ) ); 291 SLOT( sendMail( const QString& ) ) );
292 292
293 293
294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
295 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&))); 295 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&)));
296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); 296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&)));
297 297
298 298
299#ifndef KAB_EMBEDDED 299#ifndef KAB_EMBEDDED
300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
301 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 301 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
302 302
303 connect( mDetails, SIGNAL( browse( const QString& ) ), 303 connect( mDetails, SIGNAL( browse( const QString& ) ),
304 SLOT( browse( const QString& ) ) ); 304 SLOT( browse( const QString& ) ) );
305 305
306 306
307 mAddressBookService = new KAddressBookService( this ); 307 mAddressBookService = new KAddressBookService( this );
308 308
309#endif //KAB_EMBEDDED 309#endif //KAB_EMBEDDED
310 310
311 mMessageTimer = new QTimer( this ); 311 mMessageTimer = new QTimer( this );
312 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); 312 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) );
313 mEditorDialog = 0; 313 mEditorDialog = 0;
314 createAddresseeEditorDialog( this ); 314 createAddresseeEditorDialog( this );
315 setModified( false ); 315 setModified( false );
316 mBRdisabled = false; 316 mBRdisabled = false;
317#ifndef DESKTOP_VERSION 317#ifndef DESKTOP_VERSION
318 infrared = 0; 318 infrared = 0;
319#endif 319#endif
320 //toggleBeamReceive( ); 320 //toggleBeamReceive( );
321} 321}
322 322
323KABCore::~KABCore() 323KABCore::~KABCore()
324{ 324{
325 // save(); 325 // save();
326 //saveSettings(); 326 //saveSettings();
327 //KABPrefs::instance()->writeConfig(); 327 //KABPrefs::instance()->writeConfig();
328 delete AddresseeConfig::instance(); 328 delete AddresseeConfig::instance();
329 mAddressBook = 0; 329 mAddressBook = 0;
330 KABC::StdAddressBook::close(); 330 KABC::StdAddressBook::close();
331 331
332 delete syncManager; 332 delete syncManager;
333#ifndef DESKTOP_VERSION 333#ifndef DESKTOP_VERSION
334 if ( infrared ) 334 if ( infrared )
335 delete infrared; 335 delete infrared;
336#endif 336#endif
337} 337}
338void KABCore::receive( const QCString& cmsg, const QByteArray& data ) 338void KABCore::receive( const QCString& cmsg, const QByteArray& data )
339{ 339{
340 qDebug("KA: QCOP message received: %s ", cmsg.data() ); 340 qDebug("KA: QCOP message received: %s ", cmsg.data() );
341 if ( cmsg == "setDocument(QString)" ) { 341 if ( cmsg == "setDocument(QString)" ) {
342 QDataStream stream( data, IO_ReadOnly ); 342 QDataStream stream( data, IO_ReadOnly );
343 QString fileName; 343 QString fileName;
344 stream >> fileName; 344 stream >> fileName;
345 recieve( fileName ); 345 recieve( fileName );
346 return; 346 return;
347 } 347 }
348} 348}
349void KABCore::toggleBeamReceive( ) 349void KABCore::toggleBeamReceive( )
350{ 350{
351 if ( mBRdisabled ) 351 if ( mBRdisabled )
352 return; 352 return;
353#ifndef DESKTOP_VERSION 353#ifndef DESKTOP_VERSION
354 if ( infrared ) { 354 if ( infrared ) {
355 qDebug("AB disable BeamReceive "); 355 qDebug("AB disable BeamReceive ");
356 delete infrared; 356 delete infrared;
357 infrared = 0; 357 infrared = 0;
358 mActionBR->setChecked(false); 358 mActionBR->setChecked(false);
359 return; 359 return;
360 } 360 }
361 qDebug("AB enable BeamReceive "); 361 qDebug("AB enable BeamReceive ");
362 mActionBR->setChecked(true); 362 mActionBR->setChecked(true);
363 363
364 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; 364 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ;
365 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); 365 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& )));
366#endif 366#endif
367} 367}
368 368
369 369
370void KABCore::disableBR(bool b) 370void KABCore::disableBR(bool b)
371{ 371{
372#ifndef DESKTOP_VERSION 372#ifndef DESKTOP_VERSION
373 if ( b ) { 373 if ( b ) {
374 if ( infrared ) { 374 if ( infrared ) {
375 toggleBeamReceive( ); 375 toggleBeamReceive( );
376 } 376 }
377 mBRdisabled = true; 377 mBRdisabled = true;
378 } else { 378 } else {
379 if ( mBRdisabled ) { 379 if ( mBRdisabled ) {
380 mBRdisabled = false; 380 mBRdisabled = false;
381 //toggleBeamReceive( ); 381 //toggleBeamReceive( );
382 } 382 }
383 } 383 }
384#endif 384#endif
385 385
386} 386}
387void KABCore::recieve( QString fn ) 387void KABCore::recieve( QString fn )
388{ 388{
389 //qDebug("KABCore::recieve "); 389 //qDebug("KABCore::recieve ");
390 int count = mAddressBook->importFromFile( fn, true ); 390 int count = mAddressBook->importFromFile( fn, true );
391 if ( count ) 391 if ( count )
392 setModified( true ); 392 setModified( true );
393 mViewManager->refreshView(); 393 mViewManager->refreshView();
394 message(i18n("%1 contact(s) received!").arg( count )); 394 message(i18n("%1 contact(s) received!").arg( count ));
395 topLevelWidget()->showMaximized(); 395 topLevelWidget()->showMaximized();
396 topLevelWidget()->raise(); 396 topLevelWidget()->raise();
397} 397}
398void KABCore::restoreSettings() 398void KABCore::restoreSettings()
399{ 399{
400 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 400 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
401 401
402 bool state; 402 bool state;
403 403
404 if (mMultipleViewsAtOnce) 404 if (mMultipleViewsAtOnce)
405 state = KABPrefs::instance()->mDetailsPageVisible; 405 state = KABPrefs::instance()->mDetailsPageVisible;
406 else 406 else
407 state = false; 407 state = false;
408 408
409 mActionDetails->setChecked( state ); 409 mActionDetails->setChecked( state );
410 setDetailsVisible( state ); 410 setDetailsVisible( state );
411 411
412 state = KABPrefs::instance()->mJumpButtonBarVisible; 412 state = KABPrefs::instance()->mJumpButtonBarVisible;
413 413
414 mActionJumpBar->setChecked( state ); 414 mActionJumpBar->setChecked( state );
415 setJumpButtonBarVisible( state ); 415 setJumpButtonBarVisible( state );
416/*US 416/*US
417 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 417 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
418 if ( splitterSize.count() == 0 ) { 418 if ( splitterSize.count() == 0 ) {
419 splitterSize.append( width() / 2 ); 419 splitterSize.append( width() / 2 );
420 splitterSize.append( width() / 2 ); 420 splitterSize.append( width() / 2 );
421 } 421 }
422 mMiniSplitter->setSizes( splitterSize ); 422 mMiniSplitter->setSizes( splitterSize );
423 if ( mExtensionBarSplitter ) { 423 if ( mExtensionBarSplitter ) {
424 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 424 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
425 if ( splitterSize.count() == 0 ) { 425 if ( splitterSize.count() == 0 ) {
426 splitterSize.append( width() / 2 ); 426 splitterSize.append( width() / 2 );
427 splitterSize.append( width() / 2 ); 427 splitterSize.append( width() / 2 );
428 } 428 }
429 mExtensionBarSplitter->setSizes( splitterSize ); 429 mExtensionBarSplitter->setSizes( splitterSize );
430 430
431 } 431 }
432*/ 432*/
433 mViewManager->restoreSettings(); 433 mViewManager->restoreSettings();
434 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 434 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
435 mExtensionManager->restoreSettings(); 435 mExtensionManager->restoreSettings();
436#ifdef DESKTOP_VERSION 436#ifdef DESKTOP_VERSION
437 int wid = width(); 437 int wid = width();
438 if ( wid < 10 ) 438 if ( wid < 10 )
439 wid = 400; 439 wid = 400;
440#else 440#else
441 int wid = QApplication::desktop()->width(); 441 int wid = QApplication::desktop()->width();
442 if ( wid < 640 ) 442 if ( wid < 640 )
443 wid = QApplication::desktop()->height(); 443 wid = QApplication::desktop()->height();
444#endif 444#endif
445 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 445 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
446 if ( true /*splitterSize.count() == 0*/ ) { 446 if ( true /*splitterSize.count() == 0*/ ) {
447 splitterSize.append( wid / 2 ); 447 splitterSize.append( wid / 2 );
448 splitterSize.append( wid / 2 ); 448 splitterSize.append( wid / 2 );
449 } 449 }
450 mMiniSplitter->setSizes( splitterSize ); 450 mMiniSplitter->setSizes( splitterSize );
451 if ( mExtensionBarSplitter ) { 451 if ( mExtensionBarSplitter ) {
452 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 452 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
453 if ( true /*splitterSize.count() == 0*/ ) { 453 if ( true /*splitterSize.count() == 0*/ ) {
454 splitterSize.append( wid / 2 ); 454 splitterSize.append( wid / 2 );
455 splitterSize.append( wid / 2 ); 455 splitterSize.append( wid / 2 );
456 } 456 }
457 mExtensionBarSplitter->setSizes( splitterSize ); 457 mExtensionBarSplitter->setSizes( splitterSize );
458 458
459 } 459 }
460 460
461 461
462} 462}
463 463
464void KABCore::saveSettings() 464void KABCore::saveSettings()
465{ 465{
466 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 466 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
467 if ( mExtensionBarSplitter ) 467 if ( mExtensionBarSplitter )
468 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 468 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
469 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 469 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
470 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 470 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
471#ifndef KAB_EMBEDDED 471#ifndef KAB_EMBEDDED
472 472
473 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 473 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
474 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 474 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
475#endif //KAB_EMBEDDED 475#endif //KAB_EMBEDDED
476 mExtensionManager->saveSettings(); 476 mExtensionManager->saveSettings();
477 mViewManager->saveSettings(); 477 mViewManager->saveSettings();
478 478
479 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 479 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
480} 480}
481 481
482KABC::AddressBook *KABCore::addressBook() const 482KABC::AddressBook *KABCore::addressBook() const
483{ 483{
484 return mAddressBook; 484 return mAddressBook;
485} 485}
486 486
487KConfig *KABCore::config() 487KConfig *KABCore::config()
488{ 488{
489#ifndef KAB_EMBEDDED 489#ifndef KAB_EMBEDDED
490 return KABPrefs::instance()->config(); 490 return KABPrefs::instance()->config();
491#else //KAB_EMBEDDED 491#else //KAB_EMBEDDED
492 return KABPrefs::instance()->getConfig(); 492 return KABPrefs::instance()->getConfig();
493#endif //KAB_EMBEDDED 493#endif //KAB_EMBEDDED
494} 494}
495 495
496KActionCollection *KABCore::actionCollection() const 496KActionCollection *KABCore::actionCollection() const
497{ 497{
498 return mGUIClient->actionCollection(); 498 return mGUIClient->actionCollection();
499} 499}
500 500
501KABC::Field *KABCore::currentSearchField() const 501KABC::Field *KABCore::currentSearchField() const
502{ 502{
503 if (mIncSearchWidget) 503 if (mIncSearchWidget)
504 return mIncSearchWidget->currentField(); 504 return mIncSearchWidget->currentField();
505 else 505 else
506 return 0; 506 return 0;
507} 507}
508 508
509QStringList KABCore::selectedUIDs() const 509QStringList KABCore::selectedUIDs() const
510{ 510{
511 return mViewManager->selectedUids(); 511 return mViewManager->selectedUids();
512} 512}
513 513
514KABC::Resource *KABCore::requestResource( QWidget *parent ) 514KABC::Resource *KABCore::requestResource( QWidget *parent )
515{ 515{
516 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 516 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
517 517
518 QPtrList<KRES::Resource> kresResources; 518 QPtrList<KRES::Resource> kresResources;
519 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 519 QPtrListIterator<KABC::Resource> resIt( kabcResources );
520 KABC::Resource *resource; 520 KABC::Resource *resource;
521 while ( ( resource = resIt.current() ) != 0 ) { 521 while ( ( resource = resIt.current() ) != 0 ) {
522 ++resIt; 522 ++resIt;
523 if ( !resource->readOnly() ) { 523 if ( !resource->readOnly() ) {
524 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 524 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
525 if ( res ) 525 if ( res )
526 kresResources.append( res ); 526 kresResources.append( res );
527 } 527 }
528 } 528 }
529 529
530 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 530 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
531 return static_cast<KABC::Resource*>( res ); 531 return static_cast<KABC::Resource*>( res );
532} 532}
533 533
534#ifndef KAB_EMBEDDED 534#ifndef KAB_EMBEDDED
535KAboutData *KABCore::createAboutData() 535KAboutData *KABCore::createAboutData()
536#else //KAB_EMBEDDED 536#else //KAB_EMBEDDED
537void KABCore::createAboutData() 537void KABCore::createAboutData()
538#endif //KAB_EMBEDDED 538#endif //KAB_EMBEDDED
539{ 539{
540#ifndef KAB_EMBEDDED 540#ifndef KAB_EMBEDDED
541 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 541 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
542 "3.1", I18N_NOOP( "The KDE Address Book" ), 542 "3.1", I18N_NOOP( "The KDE Address Book" ),
543 KAboutData::License_GPL_V2, 543 KAboutData::License_GPL_V2,
544 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 544 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
545 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 545 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
546 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 546 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
547 about->addAuthor( "Cornelius Schumacher", 547 about->addAuthor( "Cornelius Schumacher",
548 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 548 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
549 "schumacher@kde.org" ); 549 "schumacher@kde.org" );
550 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 550 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
551 "mpilone@slac.com" ); 551 "mpilone@slac.com" );
552 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 552 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
553 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 553 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
554 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 554 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
555 "michel@klaralvdalens-datakonsult.se" ); 555 "michel@klaralvdalens-datakonsult.se" );
556 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 556 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
557 "hansen@kde.org" ); 557 "hansen@kde.org" );
558 558
559 return about; 559 return about;
560#endif //KAB_EMBEDDED 560#endif //KAB_EMBEDDED
561 561
562 QString version; 562 QString version;
563#include <../version> 563#include <../version>
564 QMessageBox::about( this, "About KAddressbook/Pi", 564 QMessageBox::about( this, "About KAddressbook/Pi",
565 "KAddressbook/Platform-independent\n" 565 "KAddressbook/Platform-independent\n"
566 "(KA/Pi) " +version + " - " + 566 "(KA/Pi) " +version + " - " +
567#ifdef DESKTOP_VERSION 567#ifdef DESKTOP_VERSION
568 "Desktop Edition\n" 568 "Desktop Edition\n"
569#else 569#else
570 "PDA-Edition\n" 570 "PDA-Edition\n"
571 "for: Zaurus 5500 / 7x0 / 8x0\n" 571 "for: Zaurus 5500 / 7x0 / 8x0\n"
572#endif 572#endif
573 573
574 "(c) 2004 Ulf Schenk\n" 574 "(c) 2004 Ulf Schenk\n"
575 "(c) 2004 Lutz Rogowski\n" 575 "(c) 2004 Lutz Rogowski\n"
576 "(c) 1997-2003, The KDE PIM Team\n" 576 "(c) 1997-2003, The KDE PIM Team\n"
577 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 577 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
578 "Don Sanders Original author\n" 578 "Don Sanders Original author\n"
579 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 579 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
580 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 580 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
581 "Greg Stern DCOP interface\n" 581 "Greg Stern DCOP interface\n"
582 "Mark Westcot Contact pinning\n" 582 "Mark Westcot Contact pinning\n"
583 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 583 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
584 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 584 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
585#ifdef _WIN32_ 585#ifdef _WIN32_
586 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 586 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
587#endif 587#endif
588 ); 588 );
589} 589}
590 590
591void KABCore::setContactSelected( const QString &uid ) 591void KABCore::setContactSelected( const QString &uid )
592{ 592{
593 KABC::Addressee addr = mAddressBook->findByUid( uid ); 593 KABC::Addressee addr = mAddressBook->findByUid( uid );
594 if ( !mDetails->isHidden() ) 594 if ( !mDetails->isHidden() )
595 mDetails->setAddressee( addr ); 595 mDetails->setAddressee( addr );
596 596
597 if ( !addr.isEmpty() ) { 597 if ( !addr.isEmpty() ) {
598 emit contactSelected( addr.formattedName() ); 598 emit contactSelected( addr.formattedName() );
599 KABC::Picture pic = addr.photo(); 599 KABC::Picture pic = addr.photo();
600 if ( pic.isIntern() ) { 600 if ( pic.isIntern() ) {
601//US emit contactSelected( pic.data() ); 601//US emit contactSelected( pic.data() );
602//US instead use: 602//US instead use:
603 QPixmap px; 603 QPixmap px;
604 if (pic.data().isNull() != true) 604 if (pic.data().isNull() != true)
605 { 605 {
606 px.convertFromImage(pic.data()); 606 px.convertFromImage(pic.data());
607 } 607 }
608 608
609 emit contactSelected( px ); 609 emit contactSelected( px );
610 } 610 }
611 } 611 }
612 612
613 613
614 mExtensionManager->setSelectionChanged(); 614 mExtensionManager->setSelectionChanged();
615 615
616 // update the actions 616 // update the actions
617 bool selected = !uid.isEmpty(); 617 bool selected = !uid.isEmpty();
618 618
619 if ( mReadWrite ) { 619 if ( mReadWrite ) {
620 mActionCut->setEnabled( selected ); 620 mActionCut->setEnabled( selected );
621 mActionPaste->setEnabled( selected ); 621 mActionPaste->setEnabled( selected );
622 } 622 }
623 623
624 mActionCopy->setEnabled( selected ); 624 mActionCopy->setEnabled( selected );
625 mActionDelete->setEnabled( selected ); 625 mActionDelete->setEnabled( selected );
626 mActionEditAddressee->setEnabled( selected ); 626 mActionEditAddressee->setEnabled( selected );
627 mActionMail->setEnabled( selected ); 627 mActionMail->setEnabled( selected );
628 mActionMailVCard->setEnabled( selected ); 628 mActionMailVCard->setEnabled( selected );
629 //if (mActionBeam) 629 //if (mActionBeam)
630 //mActionBeam->setEnabled( selected ); 630 //mActionBeam->setEnabled( selected );
631 631
632 if (mActionBeamVCard) 632 if (mActionBeamVCard)
633 mActionBeamVCard->setEnabled( selected ); 633 mActionBeamVCard->setEnabled( selected );
634 634
635 mActionExport2phone->setEnabled( selected ); 635 mActionExport2phone->setEnabled( selected );
636 mActionWhoAmI->setEnabled( selected ); 636 mActionWhoAmI->setEnabled( selected );
637 mActionCategories->setEnabled( selected ); 637 mActionCategories->setEnabled( selected );
638} 638}
639 639
640void KABCore::sendMail() 640void KABCore::sendMail()
641{ 641{
642 sendMail( mViewManager->selectedEmails().join( ", " ) ); 642 sendMail( mViewManager->selectedEmails().join( ", " ) );
643} 643}
644 644
645void KABCore::sendMail( const QString& emaillist ) 645void KABCore::sendMail( const QString& emaillist )
646{ 646{
647 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 647 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
648 if (emaillist.contains(",") > 0) 648 if (emaillist.contains(",") > 0)
649 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 649 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
650 else 650 else
651 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 651 ExternalAppHandler::instance()->mailToOneContact( emaillist );
652} 652}
653 653
654 654
655 655
656void KABCore::mailVCard() 656void KABCore::mailVCard()
657{ 657{
658 QStringList uids = mViewManager->selectedUids(); 658 QStringList uids = mViewManager->selectedUids();
659 if ( !uids.isEmpty() ) 659 if ( !uids.isEmpty() )
660 mailVCard( uids ); 660 mailVCard( uids );
661} 661}
662 662
663void KABCore::mailVCard( const QStringList& uids ) 663void KABCore::mailVCard( const QStringList& uids )
664{ 664{
665 QStringList urls; 665 QStringList urls;
666 666
667// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 667// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
668 668
669 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 669 QString dirName = "/tmp/" + KApplication::randomString( 8 );
670 670
671 671
672 672
673 QDir().mkdir( dirName, true ); 673 QDir().mkdir( dirName, true );
674 674
675 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 675 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
676 KABC::Addressee a = mAddressBook->findByUid( *it ); 676 KABC::Addressee a = mAddressBook->findByUid( *it );
677 677
678 if ( a.isEmpty() ) 678 if ( a.isEmpty() )
679 continue; 679 continue;
680 680
681 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 681 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
682 682
683 QString fileName = dirName + "/" + name; 683 QString fileName = dirName + "/" + name;
684 684
685 QFile outFile(fileName); 685 QFile outFile(fileName);
686 686
687 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 687 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
688 KABC::VCardConverter converter; 688 KABC::VCardConverter converter;
689 QString vcard; 689 QString vcard;
690 690
691 converter.addresseeToVCard( a, vcard ); 691 converter.addresseeToVCard( a, vcard );
692 692
693 QTextStream t( &outFile ); // use a text stream 693 QTextStream t( &outFile ); // use a text stream
694 t.setEncoding( QTextStream::UnicodeUTF8 ); 694 t.setEncoding( QTextStream::UnicodeUTF8 );
695 t << vcard; 695 t << vcard;
696 696
697 outFile.close(); 697 outFile.close();
698 698
699 urls.append( fileName ); 699 urls.append( fileName );
700 } 700 }
701 } 701 }
702 702
703 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 703 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
704 704
705 705
706/*US 706/*US
707 kapp->invokeMailer( QString::null, QString::null, QString::null, 707 kapp->invokeMailer( QString::null, QString::null, QString::null,
708 QString::null, // subject 708 QString::null, // subject
709 QString::null, // body 709 QString::null, // body
710 QString::null, 710 QString::null,
711 urls ); // attachments 711 urls ); // attachments
712*/ 712*/
713 713
714} 714}
715 715
716/** 716/**
717 Beams the "WhoAmI contact. 717 Beams the "WhoAmI contact.
718*/ 718*/
719void KABCore::beamMySelf() 719void KABCore::beamMySelf()
720{ 720{
721 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 721 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
722 if (!a.isEmpty()) 722 if (!a.isEmpty())
723 { 723 {
724 QStringList uids; 724 QStringList uids;
725 uids << a.uid(); 725 uids << a.uid();
726 726
727 beamVCard(uids); 727 beamVCard(uids);
728 } else { 728 } else {
729 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 729 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
730 730
731 731
732 } 732 }
733} 733}
734 734
735void KABCore::export2phone() 735void KABCore::export2phone()
736{ 736{
737 737
738 KAex2phonePrefs ex2phone; 738 KAex2phonePrefs ex2phone;
739 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 739 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
740 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 740 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
741 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 741 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
742 742
743 if ( !ex2phone.exec() ) { 743 if ( !ex2phone.exec() ) {
744 return; 744 return;
745 } 745 }
746 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 746 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
747 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 747 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
748 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 748 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
749 749
750 750
751 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 751 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
752 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 752 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
753 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 753 KPimGlobalPrefs::instance()->mEx2PhoneModel );
754 754
755 QStringList uids = mViewManager->selectedUids(); 755 QStringList uids = mViewManager->selectedUids();
756 if ( uids.isEmpty() ) 756 if ( uids.isEmpty() )
757 return; 757 return;
758 758
759 QString fileName = getPhoneFile(); 759 QString fileName = getPhoneFile();
760 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) 760 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
761 return; 761 return;
762 762
763 message(i18n("Exporting to phone...")); 763 message(i18n("Exporting to phone..."));
764 QTimer::singleShot( 1, this , SLOT ( writeToPhone())); 764 QTimer::singleShot( 1, this , SLOT ( writeToPhone()));
765 765
766} 766}
767QString KABCore::getPhoneFile() 767QString KABCore::getPhoneFile()
768{ 768{
769#ifdef DESKTOP_VERSION 769#ifdef DESKTOP_VERSION
770 return locateLocal("tmp", "phonefile.vcf"); 770 return locateLocal("tmp", "phonefile.vcf");
771#else 771#else
772 return "/tmp/phonefile.vcf"; 772 return "/tmp/phonefile.vcf";
773#endif 773#endif
774 774
775} 775}
776void KABCore::writeToPhone( ) 776void KABCore::writeToPhone( )
777{ 777{
778 if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) 778 if ( PhoneAccess::writeToPhone( getPhoneFile() ) )
779 message(i18n("Export to phone finished!")); 779 message(i18n("Export to phone finished!"));
780 else 780 else
781 qDebug(i18n("Error exporting to phone")); 781 qDebug(i18n("Error exporting to phone"));
782} 782}
783void KABCore::beamVCard() 783void KABCore::beamVCard()
784{ 784{
785 QStringList uids = mViewManager->selectedUids(); 785 QStringList uids = mViewManager->selectedUids();
786 if ( !uids.isEmpty() ) 786 if ( !uids.isEmpty() )
787 beamVCard( uids ); 787 beamVCard( uids );
788} 788}
789 789
790 790
791void KABCore::beamVCard(const QStringList& uids) 791void KABCore::beamVCard(const QStringList& uids)
792{ 792{
793 793
794 // LR: we should use the /tmp dir on the Zaurus, 794 // LR: we should use the /tmp dir on the Zaurus,
795 // because: /tmp = RAM, (HOME)/kdepim = flash memory 795 // because: /tmp = RAM, (HOME)/kdepim = flash memory
796 796
797#ifdef DESKTOP_VERSION 797#ifdef DESKTOP_VERSION
798 QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); 798 QString fileName = locateLocal("tmp", "kapibeamfile.vcf");
799#else 799#else
800 QString fileName = "/tmp/kapibeamfile.vcf"; 800 QString fileName = "/tmp/kapibeamfile.vcf";
801#endif 801#endif
802 802
803 KABC::VCardConverter converter; 803 KABC::VCardConverter converter;
804 QString description; 804 QString description;
805 QString datastream; 805 QString datastream;
806 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 806 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
807 KABC::Addressee a = mAddressBook->findByUid( *it ); 807 KABC::Addressee a = mAddressBook->findByUid( *it );
808 808
809 if ( a.isEmpty() ) 809 if ( a.isEmpty() )
810 continue; 810 continue;
811 811
812 if (description.isEmpty()) 812 if (description.isEmpty())
813 description = a.formattedName(); 813 description = a.formattedName();
814 814
815 QString vcard; 815 QString vcard;
816 converter.addresseeToVCard( a, vcard ); 816 converter.addresseeToVCard( a, vcard );
817 int start = 0; 817 int start = 0;
818 int next; 818 int next;
819 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 819 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
820 int semi = vcard.find(";", next); 820 int semi = vcard.find(";", next);
821 int dopp = vcard.find(":", next); 821 int dopp = vcard.find(":", next);
822 int sep; 822 int sep;
823 if ( semi < dopp && semi >= 0 ) 823 if ( semi < dopp && semi >= 0 )
824 sep = semi ; 824 sep = semi ;
825 else 825 else
826 sep = dopp; 826 sep = dopp;
827 datastream +=vcard.mid( start, next - start); 827 datastream +=vcard.mid( start, next - start);
828 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 828 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
829 start = sep; 829 start = sep;
830 } 830 }
831 datastream += vcard.mid( start,vcard.length() ); 831 datastream += vcard.mid( start,vcard.length() );
832 } 832 }
833#ifndef DESKTOP_VERSION 833#ifndef DESKTOP_VERSION
834 QFile outFile(fileName); 834 QFile outFile(fileName);
835 if ( outFile.open(IO_WriteOnly) ) { 835 if ( outFile.open(IO_WriteOnly) ) {
836 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 836 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
837 QTextStream t( &outFile ); // use a text stream 837 QTextStream t( &outFile ); // use a text stream
838 //t.setEncoding( QTextStream::UnicodeUTF8 ); 838 //t.setEncoding( QTextStream::UnicodeUTF8 );
839 t.setEncoding( QTextStream::Latin1 ); 839 t.setEncoding( QTextStream::Latin1 );
840 t <<datastream.latin1(); 840 t <<datastream.latin1();
841 outFile.close(); 841 outFile.close();
842 Ir *ir = new Ir( this ); 842 Ir *ir = new Ir( this );
843 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 843 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
844 ir->send( fileName, description, "text/x-vCard" ); 844 ir->send( fileName, description, "text/x-vCard" );
845 } else { 845 } else {
846 qDebug("Error open temp beam file "); 846 qDebug("Error open temp beam file ");
847 return; 847 return;
848 } 848 }
849#endif 849#endif
850 850
851} 851}
852 852
853void KABCore::beamDone( Ir *ir ) 853void KABCore::beamDone( Ir *ir )
854{ 854{
855#ifndef DESKTOP_VERSION 855#ifndef DESKTOP_VERSION
856 delete ir; 856 delete ir;
857#endif 857#endif
858 topLevelWidget()->raise(); 858 topLevelWidget()->raise();
859 message( i18n("Beaming finished!") ); 859 message( i18n("Beaming finished!") );
860} 860}
861 861
862 862
863void KABCore::browse( const QString& url ) 863void KABCore::browse( const QString& url )
864{ 864{
865#ifndef KAB_EMBEDDED 865#ifndef KAB_EMBEDDED
866 kapp->invokeBrowser( url ); 866 kapp->invokeBrowser( url );
867#else //KAB_EMBEDDED 867#else //KAB_EMBEDDED
868 qDebug("KABCore::browse must be fixed"); 868 qDebug("KABCore::browse must be fixed");
869#endif //KAB_EMBEDDED 869#endif //KAB_EMBEDDED
870} 870}
871 871
872void KABCore::selectAllContacts() 872void KABCore::selectAllContacts()
873{ 873{
874 mViewManager->setSelected( QString::null, true ); 874 mViewManager->setSelected( QString::null, true );
875} 875}
876 876
877void KABCore::deleteContacts() 877void KABCore::deleteContacts()
878{ 878{
879 QStringList uidList = mViewManager->selectedUids(); 879 QStringList uidList = mViewManager->selectedUids();
880 deleteContacts( uidList ); 880 deleteContacts( uidList );
881} 881}
882 882
883void KABCore::deleteContacts( const QStringList &uids ) 883void KABCore::deleteContacts( const QStringList &uids )
884{ 884{
885 if ( uids.count() > 0 ) { 885 if ( uids.count() > 0 ) {
886 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 886 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
887 UndoStack::instance()->push( command ); 887 UndoStack::instance()->push( command );
888 RedoStack::instance()->clear(); 888 RedoStack::instance()->clear();
889 889
890 // now if we deleted anything, refresh 890 // now if we deleted anything, refresh
891 setContactSelected( QString::null ); 891 setContactSelected( QString::null );
892 setModified( true ); 892 setModified( true );
893 } 893 }
894} 894}
895 895
896void KABCore::copyContacts() 896void KABCore::copyContacts()
897{ 897{
898 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 898 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
899 899
900 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 900 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
901 901
902 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 902 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
903 903
904 QClipboard *cb = QApplication::clipboard(); 904 QClipboard *cb = QApplication::clipboard();
905 cb->setText( clipText ); 905 cb->setText( clipText );
906} 906}
907 907
908void KABCore::cutContacts() 908void KABCore::cutContacts()
909{ 909{
910 QStringList uidList = mViewManager->selectedUids(); 910 QStringList uidList = mViewManager->selectedUids();
911 911
912//US if ( uidList.size() > 0 ) { 912//US if ( uidList.size() > 0 ) {
913 if ( uidList.count() > 0 ) { 913 if ( uidList.count() > 0 ) {
914 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 914 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
915 UndoStack::instance()->push( command ); 915 UndoStack::instance()->push( command );
916 RedoStack::instance()->clear(); 916 RedoStack::instance()->clear();
917 917
918 setModified( true ); 918 setModified( true );
919 } 919 }
920} 920}
921 921
922void KABCore::pasteContacts() 922void KABCore::pasteContacts()
923{ 923{
924 QClipboard *cb = QApplication::clipboard(); 924 QClipboard *cb = QApplication::clipboard();
925 925
926 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 926 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
927 927
928 pasteContacts( list ); 928 pasteContacts( list );
929} 929}
930 930
931void KABCore::pasteContacts( KABC::Addressee::List &list ) 931void KABCore::pasteContacts( KABC::Addressee::List &list )
932{ 932{
933 KABC::Resource *resource = requestResource( this ); 933 KABC::Resource *resource = requestResource( this );
934 KABC::Addressee::List::Iterator it; 934 KABC::Addressee::List::Iterator it;
935 for ( it = list.begin(); it != list.end(); ++it ) 935 for ( it = list.begin(); it != list.end(); ++it )
936 (*it).setResource( resource ); 936 (*it).setResource( resource );
937 937
938 PwPasteCommand *command = new PwPasteCommand( this, list ); 938 PwPasteCommand *command = new PwPasteCommand( this, list );
939 UndoStack::instance()->push( command ); 939 UndoStack::instance()->push( command );
940 RedoStack::instance()->clear(); 940 RedoStack::instance()->clear();
941 941
942 setModified( true ); 942 setModified( true );
943} 943}
944 944
945void KABCore::setWhoAmI() 945void KABCore::setWhoAmI()
946{ 946{
947 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 947 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
948 948
949 if ( addrList.count() > 1 ) { 949 if ( addrList.count() > 1 ) {
950 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 950 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
951 return; 951 return;
952 } 952 }
953 953
954 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 954 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
955 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 955 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
956 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 956 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
957} 957}
958 958
959void KABCore::setCategories() 959void KABCore::setCategories()
960{ 960{
961 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 961 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
962 if ( !dlg.exec() ) 962 if ( !dlg.exec() )
963 return; 963 return;
964 964
965 bool merge = false; 965 bool merge = false;
966 QString msg = i18n( "Merge with existing categories?" ); 966 QString msg = i18n( "Merge with existing categories?" );
967 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 967 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
968 merge = true; 968 merge = true;
969 969
970 QStringList categories = dlg.selectedCategories(); 970 QStringList categories = dlg.selectedCategories();
971 971
972 QStringList uids = mViewManager->selectedUids(); 972 QStringList uids = mViewManager->selectedUids();
973 QStringList::Iterator it; 973 QStringList::Iterator it;
974 for ( it = uids.begin(); it != uids.end(); ++it ) { 974 for ( it = uids.begin(); it != uids.end(); ++it ) {
975 KABC::Addressee addr = mAddressBook->findByUid( *it ); 975 KABC::Addressee addr = mAddressBook->findByUid( *it );
976 if ( !addr.isEmpty() ) { 976 if ( !addr.isEmpty() ) {
977 if ( !merge ) 977 if ( !merge )
978 addr.setCategories( categories ); 978 addr.setCategories( categories );
979 else { 979 else {
980 QStringList addrCategories = addr.categories(); 980 QStringList addrCategories = addr.categories();
981 QStringList::Iterator catIt; 981 QStringList::Iterator catIt;
982 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 982 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
983 if ( !addrCategories.contains( *catIt ) ) 983 if ( !addrCategories.contains( *catIt ) )
984 addrCategories.append( *catIt ); 984 addrCategories.append( *catIt );
985 } 985 }
986 addr.setCategories( addrCategories ); 986 addr.setCategories( addrCategories );
987 } 987 }
988 988
989 mAddressBook->insertAddressee( addr ); 989 mAddressBook->insertAddressee( addr );
990 } 990 }
991 } 991 }
992 992
993 if ( uids.count() > 0 ) 993 if ( uids.count() > 0 )
994 setModified( true ); 994 setModified( true );
995} 995}
996 996
997void KABCore::setSearchFields( const KABC::Field::List &fields ) 997void KABCore::setSearchFields( const KABC::Field::List &fields )
998{ 998{
999 mIncSearchWidget->setFields( fields ); 999 mIncSearchWidget->setFields( fields );
1000} 1000}
1001 1001
1002void KABCore::incrementalSearch( const QString& text ) 1002void KABCore::incrementalSearch( const QString& text )
1003{ 1003{
1004 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 1004 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
1005} 1005}
1006 1006
1007void KABCore::setModified() 1007void KABCore::setModified()
1008{ 1008{
1009 setModified( true ); 1009 setModified( true );
1010} 1010}
1011 1011
1012void KABCore::setModifiedWOrefresh() 1012void KABCore::setModifiedWOrefresh()
1013{ 1013{
1014 // qDebug("KABCore::setModifiedWOrefresh() "); 1014 // qDebug("KABCore::setModifiedWOrefresh() ");
1015 mModified = true; 1015 mModified = true;
1016 mActionSave->setEnabled( mModified ); 1016 mActionSave->setEnabled( mModified );
1017#ifdef DESKTOP_VERSION 1017#ifdef DESKTOP_VERSION
1018 mDetails->refreshView(); 1018 mDetails->refreshView();
1019#endif 1019#endif
1020 1020
1021} 1021}
1022void KABCore::setModified( bool modified ) 1022void KABCore::setModified( bool modified )
1023{ 1023{
1024 mModified = modified; 1024 mModified = modified;
1025 mActionSave->setEnabled( mModified ); 1025 mActionSave->setEnabled( mModified );
1026 1026
1027 if ( modified ) 1027 if ( modified )
1028 mJumpButtonBar->recreateButtons(); 1028 mJumpButtonBar->recreateButtons();
1029 1029
1030 mViewManager->refreshView(); 1030 mViewManager->refreshView();
1031 mDetails->refreshView(); 1031 mDetails->refreshView();
1032 1032
1033} 1033}
1034 1034
1035bool KABCore::modified() const 1035bool KABCore::modified() const
1036{ 1036{
1037 return mModified; 1037 return mModified;
1038} 1038}
1039 1039
1040void KABCore::contactModified( const KABC::Addressee &addr ) 1040void KABCore::contactModified( const KABC::Addressee &addr )
1041{ 1041{
1042 1042
1043 Command *command = 0; 1043 Command *command = 0;
1044 QString uid; 1044 QString uid;
1045 1045
1046 // check if it exists already 1046 // check if it exists already
1047 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 1047 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
1048 if ( origAddr.isEmpty() ) 1048 if ( origAddr.isEmpty() )
1049 command = new PwNewCommand( mAddressBook, addr ); 1049 command = new PwNewCommand( mAddressBook, addr );
1050 else { 1050 else {
1051 command = new PwEditCommand( mAddressBook, origAddr, addr ); 1051 command = new PwEditCommand( mAddressBook, origAddr, addr );
1052 uid = addr.uid(); 1052 uid = addr.uid();
1053 } 1053 }
1054 1054
1055 UndoStack::instance()->push( command ); 1055 UndoStack::instance()->push( command );
1056 RedoStack::instance()->clear(); 1056 RedoStack::instance()->clear();
1057 1057
1058 setModified( true ); 1058 setModified( true );
1059} 1059}
1060 1060
1061void KABCore::newContact() 1061void KABCore::newContact()
1062{ 1062{
1063 1063
1064 1064
1065 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 1065 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
1066 1066
1067 QPtrList<KRES::Resource> kresResources; 1067 QPtrList<KRES::Resource> kresResources;
1068 QPtrListIterator<KABC::Resource> it( kabcResources ); 1068 QPtrListIterator<KABC::Resource> it( kabcResources );
1069 KABC::Resource *resource; 1069 KABC::Resource *resource;
1070 while ( ( resource = it.current() ) != 0 ) { 1070 while ( ( resource = it.current() ) != 0 ) {
1071 ++it; 1071 ++it;
1072 if ( !resource->readOnly() ) { 1072 if ( !resource->readOnly() ) {
1073 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 1073 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
1074 if ( res ) 1074 if ( res )
1075 kresResources.append( res ); 1075 kresResources.append( res );
1076 } 1076 }
1077 } 1077 }
1078 1078
1079 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 1079 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
1080 resource = static_cast<KABC::Resource*>( res ); 1080 resource = static_cast<KABC::Resource*>( res );
1081 1081
1082 if ( resource ) { 1082 if ( resource ) {
1083 KABC::Addressee addr; 1083 KABC::Addressee addr;
1084 addr.setResource( resource ); 1084 addr.setResource( resource );
1085 mEditorDialog->setAddressee( addr ); 1085 mEditorDialog->setAddressee( addr );
1086 KApplication::execDialog ( mEditorDialog ); 1086 KApplication::execDialog ( mEditorDialog );
1087 1087
1088 } else 1088 } else
1089 return; 1089 return;
1090 1090
1091 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 1091 // mEditorDict.insert( dialog->addressee().uid(), dialog );
1092 1092
1093 1093
1094} 1094}
1095 1095
1096void KABCore::addEmail( QString aStr ) 1096void KABCore::addEmail( QString aStr )
1097{ 1097{
1098#ifndef KAB_EMBEDDED 1098#ifndef KAB_EMBEDDED
1099 QString fullName, email; 1099 QString fullName, email;
1100 1100
1101 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 1101 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
1102 1102
1103 // Try to lookup the addressee matching the email address 1103 // Try to lookup the addressee matching the email address
1104 bool found = false; 1104 bool found = false;
1105 QStringList emailList; 1105 QStringList emailList;
1106 KABC::AddressBook::Iterator it; 1106 KABC::AddressBook::Iterator it;
1107 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 1107 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
1108 emailList = (*it).emails(); 1108 emailList = (*it).emails();
1109 if ( emailList.contains( email ) > 0 ) { 1109 if ( emailList.contains( email ) > 0 ) {
1110 found = true; 1110 found = true;
1111 (*it).setNameFromString( fullName ); 1111 (*it).setNameFromString( fullName );
1112 editContact( (*it).uid() ); 1112 editContact( (*it).uid() );
1113 } 1113 }
1114 } 1114 }
1115 1115
1116 if ( !found ) { 1116 if ( !found ) {
1117 KABC::Addressee addr; 1117 KABC::Addressee addr;
1118 addr.setNameFromString( fullName ); 1118 addr.setNameFromString( fullName );
1119 addr.insertEmail( email, true ); 1119 addr.insertEmail( email, true );
1120 1120
1121 mAddressBook->insertAddressee( addr ); 1121 mAddressBook->insertAddressee( addr );
1122 mViewManager->refreshView( addr.uid() ); 1122 mViewManager->refreshView( addr.uid() );
1123 editContact( addr.uid() ); 1123 editContact( addr.uid() );
1124 } 1124 }
1125#else //KAB_EMBEDDED 1125#else //KAB_EMBEDDED
1126 qDebug("KABCore::addEmail finsih method"); 1126 qDebug("KABCore::addEmail finsih method");
1127#endif //KAB_EMBEDDED 1127#endif //KAB_EMBEDDED
1128} 1128}
1129 1129
1130void KABCore::importVCard( const KURL &url, bool showPreview ) 1130void KABCore::importVCard( const KURL &url, bool showPreview )
1131{ 1131{
1132 mXXPortManager->importVCard( url, showPreview ); 1132 mXXPortManager->importVCard( url, showPreview );
1133} 1133}
1134void KABCore::importFromOL() 1134void KABCore::importFromOL()
1135{ 1135{
1136#ifdef _WIN32_ 1136#ifdef _WIN32_
1137 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 1137 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
1138 idgl->exec(); 1138 idgl->exec();
1139 KABC::Addressee::List list = idgl->getAddressList(); 1139 KABC::Addressee::List list = idgl->getAddressList();
1140 if ( list.count() > 0 ) { 1140 if ( list.count() > 0 ) {
1141 KABC::Addressee::List listNew; 1141 KABC::Addressee::List listNew;
1142 KABC::Addressee::List listExisting; 1142 KABC::Addressee::List listExisting;
1143 KABC::Addressee::List::Iterator it; 1143 KABC::Addressee::List::Iterator it;
1144 KABC::AddressBook::Iterator iter; 1144 KABC::AddressBook::Iterator iter;
1145 for ( it = list.begin(); it != list.end(); ++it ) { 1145 for ( it = list.begin(); it != list.end(); ++it ) {
1146 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1146 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1147 listNew.append( (*it) ); 1147 listNew.append( (*it) );
1148 else 1148 else
1149 listExisting.append( (*it) ); 1149 listExisting.append( (*it) );
1150 } 1150 }
1151 if ( listExisting.count() > 0 ) 1151 if ( listExisting.count() > 0 )
1152 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1152 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1153 if ( listNew.count() > 0 ) { 1153 if ( listNew.count() > 0 ) {
1154 pasteWithNewUid = false; 1154 pasteWithNewUid = false;
1155 pasteContacts( listNew ); 1155 pasteContacts( listNew );
1156 pasteWithNewUid = true; 1156 pasteWithNewUid = true;
1157 } 1157 }
1158 } 1158 }
1159 delete idgl; 1159 delete idgl;
1160#endif 1160#endif
1161} 1161}
1162 1162
1163void KABCore::importVCard( const QString &vCard, bool showPreview ) 1163void KABCore::importVCard( const QString &vCard, bool showPreview )
1164{ 1164{
1165 mXXPortManager->importVCard( vCard, showPreview ); 1165 mXXPortManager->importVCard( vCard, showPreview );
1166} 1166}
1167 1167
1168//US added a second method without defaultparameter 1168//US added a second method without defaultparameter
1169void KABCore::editContact2() { 1169void KABCore::editContact2() {
1170 editContact( QString::null ); 1170 editContact( QString::null );
1171} 1171}
1172 1172
1173void KABCore::editContact( const QString &uid ) 1173void KABCore::editContact( const QString &uid )
1174{ 1174{
1175 1175
1176 if ( mExtensionManager->isQuickEditVisible() ) 1176 if ( mExtensionManager->isQuickEditVisible() )
1177 return; 1177 return;
1178 1178
1179 // First, locate the contact entry 1179 // First, locate the contact entry
1180 QString localUID = uid; 1180 QString localUID = uid;
1181 if ( localUID.isNull() ) { 1181 if ( localUID.isNull() ) {
1182 QStringList uidList = mViewManager->selectedUids(); 1182 QStringList uidList = mViewManager->selectedUids();
1183 if ( uidList.count() > 0 ) 1183 if ( uidList.count() > 0 )
1184 localUID = *( uidList.at( 0 ) ); 1184 localUID = *( uidList.at( 0 ) );
1185 } 1185 }
1186 1186
1187 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1187 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1188 if ( !addr.isEmpty() ) { 1188 if ( !addr.isEmpty() ) {
1189 mEditorDialog->setAddressee( addr ); 1189 mEditorDialog->setAddressee( addr );
1190 KApplication::execDialog ( mEditorDialog ); 1190 KApplication::execDialog ( mEditorDialog );
1191 } 1191 }
1192} 1192}
1193 1193
1194/** 1194/**
1195 Shows or edits the detail view for the given uid. If the uid is QString::null, 1195 Shows or edits the detail view for the given uid. If the uid is QString::null,
1196 the method will try to find a selected addressee in the view. 1196 the method will try to find a selected addressee in the view.
1197 */ 1197 */
1198void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1198void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1199{ 1199{
1200 if ( mMultipleViewsAtOnce ) 1200 if ( mMultipleViewsAtOnce )
1201 { 1201 {
1202 editContact( uid ); 1202 editContact( uid );
1203 } 1203 }
1204 else 1204 else
1205 { 1205 {
1206 setDetailsVisible( true ); 1206 setDetailsVisible( true );
1207 mActionDetails->setChecked(true); 1207 mActionDetails->setChecked(true);
1208 } 1208 }
1209 1209
1210} 1210}
1211 1211
1212void KABCore::save() 1212void KABCore::save()
1213{ 1213{
1214 if (syncManager->blockSave()) 1214 if (syncManager->blockSave())
1215 return; 1215 return;
1216 if ( !mModified ) 1216 if ( !mModified )
1217 return; 1217 return;
1218 1218
1219 syncManager->setBlockSave(true); 1219 syncManager->setBlockSave(true);
1220 QString text = i18n( "There was an error while attempting to save\n the " 1220 QString text = i18n( "There was an error while attempting to save\n the "
1221 "address book. Please check that some \nother application is " 1221 "address book. Please check that some \nother application is "
1222 "not using it. " ); 1222 "not using it. " );
1223 message(i18n("Saving addressbook ... ")); 1223 message(i18n("Saving addressbook ... "));
1224#ifndef KAB_EMBEDDED 1224#ifndef KAB_EMBEDDED
1225 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1225 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1226 if ( !b || !b->save() ) { 1226 if ( !b || !b->save() ) {
1227 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1227 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1228 } 1228 }
1229#else //KAB_EMBEDDED 1229#else //KAB_EMBEDDED
1230 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1230 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1231 if ( !b || !b->save() ) { 1231 if ( !b || !b->save() ) {
1232 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1232 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1233 } 1233 }
1234#endif //KAB_EMBEDDED 1234#endif //KAB_EMBEDDED
1235 1235
1236 message(i18n("Addressbook saved!")); 1236 message(i18n("Addressbook saved!"));
1237 setModified( false ); 1237 setModified( false );
1238 syncManager->setBlockSave(false); 1238 syncManager->setBlockSave(false);
1239} 1239}
1240 1240
1241 1241
1242void KABCore::undo() 1242void KABCore::undo()
1243{ 1243{
1244 UndoStack::instance()->undo(); 1244 UndoStack::instance()->undo();
1245 1245
1246 // Refresh the view 1246 // Refresh the view
1247 mViewManager->refreshView(); 1247 mViewManager->refreshView();
1248} 1248}
1249 1249
1250void KABCore::redo() 1250void KABCore::redo()
1251{ 1251{
1252 RedoStack::instance()->redo(); 1252 RedoStack::instance()->redo();
1253 1253
1254 // Refresh the view 1254 // Refresh the view
1255 mViewManager->refreshView(); 1255 mViewManager->refreshView();
1256} 1256}
1257 1257
1258void KABCore::setJumpButtonBarVisible( bool visible ) 1258void KABCore::setJumpButtonBarVisible( bool visible )
1259{ 1259{
1260 if (mMultipleViewsAtOnce) 1260 if (mMultipleViewsAtOnce)
1261 { 1261 {
1262 if ( visible ) 1262 if ( visible )
1263 mJumpButtonBar->show(); 1263 mJumpButtonBar->show();
1264 else 1264 else
1265 mJumpButtonBar->hide(); 1265 mJumpButtonBar->hide();
1266 } 1266 }
1267 else 1267 else
1268 { 1268 {
1269 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1269 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1270 if (mViewManager->isVisible()) 1270 if (mViewManager->isVisible())
1271 { 1271 {
1272 if ( visible ) 1272 if ( visible )
1273 mJumpButtonBar->show(); 1273 mJumpButtonBar->show();
1274 else 1274 else
1275 mJumpButtonBar->hide(); 1275 mJumpButtonBar->hide();
1276 } 1276 }
1277 else 1277 else
1278 { 1278 {
1279 mJumpButtonBar->hide(); 1279 mJumpButtonBar->hide();
1280 } 1280 }
1281 } 1281 }
1282} 1282}
1283 1283
1284 1284
1285void KABCore::setDetailsToState() 1285void KABCore::setDetailsToState()
1286{ 1286{
1287 setDetailsVisible( mActionDetails->isChecked() ); 1287 setDetailsVisible( mActionDetails->isChecked() );
1288} 1288}
1289 1289
1290 1290
1291 1291
1292void KABCore::setDetailsVisible( bool visible ) 1292void KABCore::setDetailsVisible( bool visible )
1293{ 1293{
1294 if (visible && mDetails->isHidden()) 1294 if (visible && mDetails->isHidden())
1295 { 1295 {
1296 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1296 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1297 if ( addrList.count() > 0 ) 1297 if ( addrList.count() > 0 )
1298 mDetails->setAddressee( addrList[ 0 ] ); 1298 mDetails->setAddressee( addrList[ 0 ] );
1299 } 1299 }
1300 1300
1301 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1301 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1302 // the listview and the detailview. We do that by changing the splitbar size. 1302 // the listview and the detailview. We do that by changing the splitbar size.
1303 if (mMultipleViewsAtOnce) 1303 if (mMultipleViewsAtOnce)
1304 { 1304 {
1305 if ( visible ) 1305 if ( visible )
1306 mDetails->show(); 1306 mDetails->show();
1307 else 1307 else
1308 mDetails->hide(); 1308 mDetails->hide();
1309 } 1309 }
1310 else 1310 else
1311 { 1311 {
1312 if ( visible ) { 1312 if ( visible ) {
1313 mViewManager->hide(); 1313 mViewManager->hide();
1314 mDetails->show(); 1314 mDetails->show();
1315 mIncSearchWidget->setFocus(); 1315 mIncSearchWidget->setFocus();
1316 } 1316 }
1317 else { 1317 else {
1318 mViewManager->show(); 1318 mViewManager->show();
1319 mDetails->hide(); 1319 mDetails->hide();
1320 mViewManager->setFocusAV(); 1320 mViewManager->setFocusAV();
1321 } 1321 }
1322 setJumpButtonBarVisible( !visible ); 1322 setJumpButtonBarVisible( !visible );
1323 } 1323 }
1324 1324
1325} 1325}
1326 1326
1327void KABCore::extensionChanged( int id ) 1327void KABCore::extensionChanged( int id )
1328{ 1328{
1329 //change the details view only for non desktop systems 1329 //change the details view only for non desktop systems
1330#ifndef DESKTOP_VERSION 1330#ifndef DESKTOP_VERSION
1331 1331
1332 if (id == 0) 1332 if (id == 0)
1333 { 1333 {
1334 //the user disabled the extension. 1334 //the user disabled the extension.
1335 1335
1336 if (mMultipleViewsAtOnce) 1336 if (mMultipleViewsAtOnce)
1337 { // enable detailsview again 1337 { // enable detailsview again
1338 setDetailsVisible( true ); 1338 setDetailsVisible( true );
1339 mActionDetails->setChecked( true ); 1339 mActionDetails->setChecked( true );
1340 } 1340 }
1341 else 1341 else
1342 { //go back to the listview 1342 { //go back to the listview
1343 setDetailsVisible( false ); 1343 setDetailsVisible( false );
1344 mActionDetails->setChecked( false ); 1344 mActionDetails->setChecked( false );
1345 mActionDetails->setEnabled(true); 1345 mActionDetails->setEnabled(true);
1346 } 1346 }
1347 1347
1348 } 1348 }
1349 else 1349 else
1350 { 1350 {
1351 //the user enabled the extension. 1351 //the user enabled the extension.
1352 setDetailsVisible( false ); 1352 setDetailsVisible( false );
1353 mActionDetails->setChecked( false ); 1353 mActionDetails->setChecked( false );
1354 1354
1355 if (!mMultipleViewsAtOnce) 1355 if (!mMultipleViewsAtOnce)
1356 { 1356 {
1357 mActionDetails->setEnabled(false); 1357 mActionDetails->setEnabled(false);
1358 } 1358 }
1359 1359
1360 mExtensionManager->setSelectionChanged(); 1360 mExtensionManager->setSelectionChanged();
1361 1361
1362 } 1362 }
1363 1363
1364#endif// DESKTOP_VERSION 1364#endif// DESKTOP_VERSION
1365 1365
1366} 1366}
1367 1367
1368 1368
1369void KABCore::extensionModified( const KABC::Addressee::List &list ) 1369void KABCore::extensionModified( const KABC::Addressee::List &list )
1370{ 1370{
1371 1371
1372 if ( list.count() != 0 ) { 1372 if ( list.count() != 0 ) {
1373 KABC::Addressee::List::ConstIterator it; 1373 KABC::Addressee::List::ConstIterator it;
1374 for ( it = list.begin(); it != list.end(); ++it ) 1374 for ( it = list.begin(); it != list.end(); ++it )
1375 mAddressBook->insertAddressee( *it ); 1375 mAddressBook->insertAddressee( *it );
1376 if ( list.count() > 1 ) 1376 if ( list.count() > 1 )
1377 setModified(); 1377 setModified();
1378 else 1378 else
1379 setModifiedWOrefresh(); 1379 setModifiedWOrefresh();
1380 } 1380 }
1381 if ( list.count() == 0 ) 1381 if ( list.count() == 0 )
1382 mViewManager->refreshView(); 1382 mViewManager->refreshView();
1383 else 1383 else
1384 mViewManager->refreshView( list[ 0 ].uid() ); 1384 mViewManager->refreshView( list[ 0 ].uid() );
1385 1385
1386 1386
1387 1387
1388} 1388}
1389 1389
1390QString KABCore::getNameByPhone( const QString &phone ) 1390QString KABCore::getNameByPhone( const QString &phone )
1391{ 1391{
1392#ifndef KAB_EMBEDDED 1392#ifndef KAB_EMBEDDED
1393 QRegExp r( "[/*/-/ ]" ); 1393 QRegExp r( "[/*/-/ ]" );
1394 QString localPhone( phone ); 1394 QString localPhone( phone );
1395 1395
1396 bool found = false; 1396 bool found = false;
1397 QString ownerName = ""; 1397 QString ownerName = "";
1398 KABC::AddressBook::Iterator iter; 1398 KABC::AddressBook::Iterator iter;
1399 KABC::PhoneNumber::List::Iterator phoneIter; 1399 KABC::PhoneNumber::List::Iterator phoneIter;
1400 KABC::PhoneNumber::List phoneList; 1400 KABC::PhoneNumber::List phoneList;
1401 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1401 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1402 phoneList = (*iter).phoneNumbers(); 1402 phoneList = (*iter).phoneNumbers();
1403 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1403 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1404 ++phoneIter) { 1404 ++phoneIter) {
1405 // Get rid of separator chars so just the numbers are compared. 1405 // Get rid of separator chars so just the numbers are compared.
1406 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1406 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1407 ownerName = (*iter).formattedName(); 1407 ownerName = (*iter).formattedName();
1408 found = true; 1408 found = true;
1409 } 1409 }
1410 } 1410 }
1411 } 1411 }
1412 1412
1413 return ownerName; 1413 return ownerName;
1414#else //KAB_EMBEDDED 1414#else //KAB_EMBEDDED
1415 qDebug("KABCore::getNameByPhone finsih method"); 1415 qDebug("KABCore::getNameByPhone finsih method");
1416 return ""; 1416 return "";
1417#endif //KAB_EMBEDDED 1417#endif //KAB_EMBEDDED
1418 1418
1419} 1419}
1420 1420
1421void KABCore::openConfigDialog() 1421void KABCore::openConfigDialog()
1422{ 1422{
1423 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1423 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1424 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1424 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1425 ConfigureDialog->addModule(kabcfg ); 1425 ConfigureDialog->addModule(kabcfg );
1426 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1426 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1427 ConfigureDialog->addModule(kdelibcfg ); 1427 ConfigureDialog->addModule(kdelibcfg );
1428 1428
1429 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1429 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1430 this, SLOT( configurationChanged() ) ); 1430 this, SLOT( configurationChanged() ) );
1431 connect( ConfigureDialog, SIGNAL( okClicked() ), 1431 connect( ConfigureDialog, SIGNAL( okClicked() ),
1432 this, SLOT( configurationChanged() ) ); 1432 this, SLOT( configurationChanged() ) );
1433 saveSettings(); 1433 saveSettings();
1434#ifndef DESKTOP_VERSION 1434#ifndef DESKTOP_VERSION
1435 ConfigureDialog->showMaximized(); 1435 ConfigureDialog->showMaximized();
1436#endif 1436#endif
1437 if ( ConfigureDialog->exec() ) 1437 if ( ConfigureDialog->exec() )
1438 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1438 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1439 delete ConfigureDialog; 1439 delete ConfigureDialog;
1440} 1440}
1441 1441
1442void KABCore::openLDAPDialog() 1442void KABCore::openLDAPDialog()
1443{ 1443{
1444#ifndef KAB_EMBEDDED 1444#ifndef KAB_EMBEDDED
1445 if ( !mLdapSearchDialog ) { 1445 if ( !mLdapSearchDialog ) {
1446 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1446 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1447 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1447 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1448 SLOT( refreshView() ) ); 1448 SLOT( refreshView() ) );
1449 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1449 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1450 SLOT( setModified() ) ); 1450 SLOT( setModified() ) );
1451 } else 1451 } else
1452 mLdapSearchDialog->restoreSettings(); 1452 mLdapSearchDialog->restoreSettings();
1453 1453
1454 if ( mLdapSearchDialog->isOK() ) 1454 if ( mLdapSearchDialog->isOK() )
1455 mLdapSearchDialog->exec(); 1455 mLdapSearchDialog->exec();
1456#else //KAB_EMBEDDED 1456#else //KAB_EMBEDDED
1457 qDebug("KABCore::openLDAPDialog() finsih method"); 1457 qDebug("KABCore::openLDAPDialog() finsih method");
1458#endif //KAB_EMBEDDED 1458#endif //KAB_EMBEDDED
1459} 1459}
1460 1460
1461void KABCore::print() 1461void KABCore::print()
1462{ 1462{
1463#ifndef KAB_EMBEDDED 1463#ifndef KAB_EMBEDDED
1464 KPrinter printer; 1464 KPrinter printer;
1465 if ( !printer.setup( this ) ) 1465 if ( !printer.setup( this ) )
1466 return; 1466 return;
1467 1467
1468 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1468 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1469 mViewManager->selectedUids(), this ); 1469 mViewManager->selectedUids(), this );
1470 1470
1471 wizard.exec(); 1471 wizard.exec();
1472#else //KAB_EMBEDDED 1472#else //KAB_EMBEDDED
1473 qDebug("KABCore::print() finsih method"); 1473 qDebug("KABCore::print() finsih method");
1474#endif //KAB_EMBEDDED 1474#endif //KAB_EMBEDDED
1475 1475
1476} 1476}
1477 1477
1478 1478
1479void KABCore::addGUIClient( KXMLGUIClient *client ) 1479void KABCore::addGUIClient( KXMLGUIClient *client )
1480{ 1480{
1481 if ( mGUIClient ) 1481 if ( mGUIClient )
1482 mGUIClient->insertChildClient( client ); 1482 mGUIClient->insertChildClient( client );
1483 else 1483 else
1484 KMessageBox::error( this, "no KXMLGUICLient"); 1484 KMessageBox::error( this, "no KXMLGUICLient");
1485} 1485}
1486 1486
1487 1487
1488void KABCore::configurationChanged() 1488void KABCore::configurationChanged()
1489{ 1489{
1490 mExtensionManager->reconfigure(); 1490 mExtensionManager->reconfigure();
1491} 1491}
1492 1492
1493void KABCore::addressBookChanged() 1493void KABCore::addressBookChanged()
1494{ 1494{
1495/*US 1495/*US
1496 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1496 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1497 while ( it.current() ) { 1497 while ( it.current() ) {
1498 if ( it.current()->dirty() ) { 1498 if ( it.current()->dirty() ) {
1499 QString text = i18n( "Data has been changed externally. Unsaved " 1499 QString text = i18n( "Data has been changed externally. Unsaved "
1500 "changes will be lost." ); 1500 "changes will be lost." );
1501 KMessageBox::information( this, text ); 1501 KMessageBox::information( this, text );
1502 } 1502 }
1503 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1503 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1504 ++it; 1504 ++it;
1505 } 1505 }
1506*/ 1506*/
1507 if (mEditorDialog) 1507 if (mEditorDialog)
1508 { 1508 {
1509 if (mEditorDialog->dirty()) 1509 if (mEditorDialog->dirty())
1510 { 1510 {
1511 QString text = i18n( "Data has been changed externally. Unsaved " 1511 QString text = i18n( "Data has been changed externally. Unsaved "
1512 "changes will be lost." ); 1512 "changes will be lost." );
1513 KMessageBox::information( this, text ); 1513 KMessageBox::information( this, text );
1514 } 1514 }
1515 QString currentuid = mEditorDialog->addressee().uid(); 1515 QString currentuid = mEditorDialog->addressee().uid();
1516 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1516 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1517 } 1517 }
1518 mViewManager->refreshView(); 1518 mViewManager->refreshView();
1519// mDetails->refreshView(); 1519// mDetails->refreshView();
1520 1520
1521 1521
1522} 1522}
1523 1523
1524AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1524AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1525 const char *name ) 1525 const char *name )
1526{ 1526{
1527 1527
1528 if ( mEditorDialog == 0 ) { 1528 if ( mEditorDialog == 0 ) {
1529 mEditorDialog = new AddresseeEditorDialog( this, parent, 1529 mEditorDialog = new AddresseeEditorDialog( this, parent,
1530 name ? name : "editorDialog" ); 1530 name ? name : "editorDialog" );
1531 1531
1532 1532
1533 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1533 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1534 SLOT( contactModified( const KABC::Addressee& ) ) ); 1534 SLOT( contactModified( const KABC::Addressee& ) ) );
1535 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1535 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1536 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1536 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1537 } 1537 }
1538 1538
1539 return mEditorDialog; 1539 return mEditorDialog;
1540} 1540}
1541 1541
1542void KABCore::slotEditorDestroyed( const QString &uid ) 1542void KABCore::slotEditorDestroyed( const QString &uid )
1543{ 1543{
1544 //mEditorDict.remove( uid ); 1544 //mEditorDict.remove( uid );
1545} 1545}
1546 1546
1547void KABCore::initGUI() 1547void KABCore::initGUI()
1548{ 1548{
1549#ifndef KAB_EMBEDDED 1549#ifndef KAB_EMBEDDED
1550 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1550 QHBoxLayout *topLayout = new QHBoxLayout( this );
1551 topLayout->setSpacing( KDialogBase::spacingHint() ); 1551 topLayout->setSpacing( KDialogBase::spacingHint() );
1552 1552
1553 mExtensionBarSplitter = new QSplitter( this ); 1553 mExtensionBarSplitter = new QSplitter( this );
1554 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1554 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1555 1555
1556 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1556 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1557 1557
1558 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1558 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1559 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1559 mIncSearchWidget = new IncSearchWidget( viewSpace );
1560 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1560 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1561 SLOT( incrementalSearch( const QString& ) ) ); 1561 SLOT( incrementalSearch( const QString& ) ) );
1562 1562
1563 mViewManager = new ViewManager( this, viewSpace ); 1563 mViewManager = new ViewManager( this, viewSpace );
1564 viewSpace->setStretchFactor( mViewManager, 1 ); 1564 viewSpace->setStretchFactor( mViewManager, 1 );
1565 1565
1566 mDetails = new ViewContainer( mDetailsSplitter ); 1566 mDetails = new ViewContainer( mDetailsSplitter );
1567 1567
1568 mJumpButtonBar = new JumpButtonBar( this, this ); 1568 mJumpButtonBar = new JumpButtonBar( this, this );
1569 1569
1570 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1570 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1571 1571
1572 topLayout->addWidget( mExtensionBarSplitter ); 1572 topLayout->addWidget( mExtensionBarSplitter );
1573 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1573 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1574 topLayout->addWidget( mJumpButtonBar ); 1574 topLayout->addWidget( mJumpButtonBar );
1575 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1575 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1576 1576
1577 mXXPortManager = new XXPortManager( this, this ); 1577 mXXPortManager = new XXPortManager( this, this );
1578 1578
1579#else //KAB_EMBEDDED 1579#else //KAB_EMBEDDED
1580 //US initialize viewMenu before settingup viewmanager. 1580 //US initialize viewMenu before settingup viewmanager.
1581 // Viewmanager needs this menu to plugin submenues. 1581 // Viewmanager needs this menu to plugin submenues.
1582 viewMenu = new QPopupMenu( this ); 1582 viewMenu = new QPopupMenu( this );
1583 settingsMenu = new QPopupMenu( this ); 1583 settingsMenu = new QPopupMenu( this );
1584 //filterMenu = new QPopupMenu( this ); 1584 //filterMenu = new QPopupMenu( this );
1585 ImportMenu = new QPopupMenu( this ); 1585 ImportMenu = new QPopupMenu( this );
1586 ExportMenu = new QPopupMenu( this ); 1586 ExportMenu = new QPopupMenu( this );
1587 syncMenu = new QPopupMenu( this ); 1587 syncMenu = new QPopupMenu( this );
1588 changeMenu= new QPopupMenu( this ); 1588 changeMenu= new QPopupMenu( this );
1589 1589
1590//US since we have no splitter for the embedded system, setup 1590//US since we have no splitter for the embedded system, setup
1591// a layout with two frames. One left and one right. 1591// a layout with two frames. One left and one right.
1592 1592
1593 QBoxLayout *topLayout; 1593 QBoxLayout *topLayout;
1594 1594
1595 // = new QHBoxLayout( this ); 1595 // = new QHBoxLayout( this );
1596// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1596// QBoxLayout *topLayout = (QBoxLayout*)layout();
1597 1597
1598// QWidget *mainBox = new QWidget( this ); 1598// QWidget *mainBox = new QWidget( this );
1599// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1599// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1600 1600
1601#ifdef DESKTOP_VERSION 1601#ifdef DESKTOP_VERSION
1602 topLayout = new QHBoxLayout( this ); 1602 topLayout = new QHBoxLayout( this );
1603 1603
1604 1604
1605 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1605 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1606 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1606 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1607 1607
1608 topLayout->addWidget(mMiniSplitter ); 1608 topLayout->addWidget(mMiniSplitter );
1609 1609
1610 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1610 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1611 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1611 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1612 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1612 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1613 mDetails = new ViewContainer( mMiniSplitter ); 1613 mDetails = new ViewContainer( mMiniSplitter );
1614 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1614 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1615#else 1615#else
1616 if ( QApplication::desktop()->width() > 480 ) { 1616 if ( QApplication::desktop()->width() > 480 ) {
1617 topLayout = new QHBoxLayout( this ); 1617 topLayout = new QHBoxLayout( this );
1618 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1618 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1619 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1619 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1620 } else { 1620 } else {
1621 1621
1622 topLayout = new QHBoxLayout( this ); 1622 topLayout = new QHBoxLayout( this );
1623 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1623 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1624 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1624 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1625 } 1625 }
1626 1626
1627 topLayout->addWidget(mMiniSplitter ); 1627 topLayout->addWidget(mMiniSplitter );
1628 mViewManager = new ViewManager( this, mMiniSplitter ); 1628 mViewManager = new ViewManager( this, mMiniSplitter );
1629 mDetails = new ViewContainer( mMiniSplitter ); 1629 mDetails = new ViewContainer( mMiniSplitter );
1630 1630
1631 1631
1632 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1632 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1633#endif 1633#endif
1634 //eh->hide(); 1634 //eh->hide();
1635 // topLayout->addWidget(mExtensionManager ); 1635 // topLayout->addWidget(mExtensionManager );
1636 1636
1637 1637
1638/*US 1638/*US
1639#ifndef KAB_NOSPLITTER 1639#ifndef KAB_NOSPLITTER
1640 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1640 QHBoxLayout *topLayout = new QHBoxLayout( this );
1641//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1641//US topLayout->setSpacing( KDialogBase::spacingHint() );
1642 topLayout->setSpacing( 10 ); 1642 topLayout->setSpacing( 10 );
1643 1643
1644 mDetailsSplitter = new QSplitter( this ); 1644 mDetailsSplitter = new QSplitter( this );
1645 1645
1646 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1646 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1647 1647
1648 mViewManager = new ViewManager( this, viewSpace ); 1648 mViewManager = new ViewManager( this, viewSpace );
1649 viewSpace->setStretchFactor( mViewManager, 1 ); 1649 viewSpace->setStretchFactor( mViewManager, 1 );
1650 1650
1651 mDetails = new ViewContainer( mDetailsSplitter ); 1651 mDetails = new ViewContainer( mDetailsSplitter );
1652 1652
1653 topLayout->addWidget( mDetailsSplitter ); 1653 topLayout->addWidget( mDetailsSplitter );
1654 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1654 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1655#else //KAB_NOSPLITTER 1655#else //KAB_NOSPLITTER
1656 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1656 QHBoxLayout *topLayout = new QHBoxLayout( this );
1657//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1657//US topLayout->setSpacing( KDialogBase::spacingHint() );
1658 topLayout->setSpacing( 10 ); 1658 topLayout->setSpacing( 10 );
1659 1659
1660// mDetailsSplitter = new QSplitter( this ); 1660// mDetailsSplitter = new QSplitter( this );
1661 1661
1662 QVBox *viewSpace = new QVBox( this ); 1662 QVBox *viewSpace = new QVBox( this );
1663 1663
1664 mViewManager = new ViewManager( this, viewSpace ); 1664 mViewManager = new ViewManager( this, viewSpace );
1665 viewSpace->setStretchFactor( mViewManager, 1 ); 1665 viewSpace->setStretchFactor( mViewManager, 1 );
1666 1666
1667 mDetails = new ViewContainer( this ); 1667 mDetails = new ViewContainer( this );
1668 1668
1669 topLayout->addWidget( viewSpace ); 1669 topLayout->addWidget( viewSpace );
1670// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1670// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1671 topLayout->addWidget( mDetails ); 1671 topLayout->addWidget( mDetails );
1672#endif //KAB_NOSPLITTER 1672#endif //KAB_NOSPLITTER
1673*/ 1673*/
1674 1674
1675 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 1675 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
1676 syncManager->setBlockSave(false); 1676 syncManager->setBlockSave(false);
1677 1677
1678 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); 1678 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
1679 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); 1679 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
1680 syncManager->setDefaultFileName( sentSyncFile()); 1680 syncManager->setDefaultFileName( sentSyncFile());
1681 //connect(syncManager , SIGNAL( ), this, SLOT( ) ); 1681 //connect(syncManager , SIGNAL( ), this, SLOT( ) );
1682 1682
1683#endif //KAB_EMBEDDED 1683#endif //KAB_EMBEDDED
1684 initActions(); 1684 initActions();
1685 1685
1686#ifdef KAB_EMBEDDED 1686#ifdef KAB_EMBEDDED
1687 addActionsManually(); 1687 addActionsManually();
1688 //US make sure the export and import menues are initialized before creating the xxPortManager. 1688 //US make sure the export and import menues are initialized before creating the xxPortManager.
1689 mXXPortManager = new XXPortManager( this, this ); 1689 mXXPortManager = new XXPortManager( this, this );
1690 1690
1691 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1691 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1692 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1692 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1693 // mActionQuit->plug ( mMainWindow->toolBar()); 1693 // mActionQuit->plug ( mMainWindow->toolBar());
1694 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1694 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1695 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1695 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1696 // mIncSearchWidget->hide(); 1696 // mIncSearchWidget->hide();
1697 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1697 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1698 SLOT( incrementalSearch( const QString& ) ) ); 1698 SLOT( incrementalSearch( const QString& ) ) );
1699 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); 1699 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) );
1700 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); 1700 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) );
1701 1701
1702 mJumpButtonBar = new JumpButtonBar( this, this ); 1702 mJumpButtonBar = new JumpButtonBar( this, this );
1703 1703
1704 topLayout->addWidget( mJumpButtonBar ); 1704 topLayout->addWidget( mJumpButtonBar );
1705//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1705//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1706 1706
1707// mMainWindow->getIconToolBar()->raise(); 1707// mMainWindow->getIconToolBar()->raise();
1708 1708
1709#endif //KAB_EMBEDDED 1709#endif //KAB_EMBEDDED
1710 1710
1711} 1711}
1712void KABCore::initActions() 1712void KABCore::initActions()
1713{ 1713{
1714//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1714//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1715 1715
1716#ifndef KAB_EMBEDDED 1716#ifndef KAB_EMBEDDED
1717 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1717 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1718 SLOT( clipboardDataChanged() ) ); 1718 SLOT( clipboardDataChanged() ) );
1719#endif //KAB_EMBEDDED 1719#endif //KAB_EMBEDDED
1720 1720
1721 // file menu 1721 // file menu
1722 if ( mIsPart ) { 1722 if ( mIsPart ) {
1723 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1723 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1724 SLOT( sendMail() ), actionCollection(), 1724 SLOT( sendMail() ), actionCollection(),
1725 "kaddressbook_mail" ); 1725 "kaddressbook_mail" );
1726 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1726 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1727 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1727 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1728 1728
1729 } else { 1729 } else {
1730 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1730 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1731 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1731 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1732 } 1732 }
1733 1733
1734 1734
1735 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1735 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1736 SLOT( save() ), actionCollection(), "file_sync" ); 1736 SLOT( save() ), actionCollection(), "file_sync" );
1737 1737
1738 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1738 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1739 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1739 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1740 1740
1741 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1741 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1742 this, SLOT( mailVCard() ), 1742 this, SLOT( mailVCard() ),
1743 actionCollection(), "file_mail_vcard"); 1743 actionCollection(), "file_mail_vcard");
1744 1744
1745 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, 1745 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this,
1746 SLOT( export2phone() ), actionCollection(), 1746 SLOT( export2phone() ), actionCollection(),
1747 "kaddressbook_ex2phone" ); 1747 "kaddressbook_ex2phone" );
1748 1748
1749 mActionBeamVCard = 0; 1749 mActionBeamVCard = 0;
1750 mActionBeam = 0; 1750 mActionBeam = 0;
1751 1751
1752#ifndef DESKTOP_VERSION 1752#ifndef DESKTOP_VERSION
1753 if ( Ir::supported() ) { 1753 if ( Ir::supported() ) {
1754 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1754 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1755 SLOT( beamVCard() ), actionCollection(), 1755 SLOT( beamVCard() ), actionCollection(),
1756 "kaddressbook_beam_vcard" ); 1756 "kaddressbook_beam_vcard" );
1757 1757
1758 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1758 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1759 SLOT( beamMySelf() ), actionCollection(), 1759 SLOT( beamMySelf() ), actionCollection(),
1760 "kaddressbook_beam_myself" ); 1760 "kaddressbook_beam_myself" );
1761 } 1761 }
1762#endif 1762#endif
1763 1763
1764 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1764 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1765 this, SLOT( editContact2() ), 1765 this, SLOT( editContact2() ),
1766 actionCollection(), "file_properties" ); 1766 actionCollection(), "file_properties" );
1767 1767
1768#ifdef KAB_EMBEDDED 1768#ifdef KAB_EMBEDDED
1769 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1769 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1770 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1770 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1771 mMainWindow, SLOT( exit() ), 1771 mMainWindow, SLOT( exit() ),
1772 actionCollection(), "quit" ); 1772 actionCollection(), "quit" );
1773#endif //KAB_EMBEDDED 1773#endif //KAB_EMBEDDED
1774 1774
1775 // edit menu 1775 // edit menu
1776 if ( mIsPart ) { 1776 if ( mIsPart ) {
1777 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1777 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1778 SLOT( copyContacts() ), actionCollection(), 1778 SLOT( copyContacts() ), actionCollection(),
1779 "kaddressbook_copy" ); 1779 "kaddressbook_copy" );
1780 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1780 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1781 SLOT( cutContacts() ), actionCollection(), 1781 SLOT( cutContacts() ), actionCollection(),
1782 "kaddressbook_cut" ); 1782 "kaddressbook_cut" );
1783 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1783 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1784 SLOT( pasteContacts() ), actionCollection(), 1784 SLOT( pasteContacts() ), actionCollection(),
1785 "kaddressbook_paste" ); 1785 "kaddressbook_paste" );
1786 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1786 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1787 SLOT( selectAllContacts() ), actionCollection(), 1787 SLOT( selectAllContacts() ), actionCollection(),
1788 "kaddressbook_select_all" ); 1788 "kaddressbook_select_all" );
1789 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1789 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1790 SLOT( undo() ), actionCollection(), 1790 SLOT( undo() ), actionCollection(),
1791 "kaddressbook_undo" ); 1791 "kaddressbook_undo" );
1792 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1792 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1793 this, SLOT( redo() ), actionCollection(), 1793 this, SLOT( redo() ), actionCollection(),
1794 "kaddressbook_redo" ); 1794 "kaddressbook_redo" );
1795 } else { 1795 } else {
1796 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1796 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1797 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1797 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1798 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1798 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1799 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1799 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1800 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1800 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1801 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1801 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1802 } 1802 }
1803 1803
1804 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1804 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1805 Key_Delete, this, SLOT( deleteContacts() ), 1805 Key_Delete, this, SLOT( deleteContacts() ),
1806 actionCollection(), "edit_delete" ); 1806 actionCollection(), "edit_delete" );
1807 1807
1808 mActionUndo->setEnabled( false ); 1808 mActionUndo->setEnabled( false );
1809 mActionRedo->setEnabled( false ); 1809 mActionRedo->setEnabled( false );
1810 1810
1811 // settings menu 1811 // settings menu
1812#ifdef KAB_EMBEDDED 1812#ifdef KAB_EMBEDDED
1813//US special menuentry to configure the addressbook resources. On KDE 1813//US special menuentry to configure the addressbook resources. On KDE
1814// you do that through the control center !!! 1814// you do that through the control center !!!
1815 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1815 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1816 SLOT( configureResources() ), actionCollection(), 1816 SLOT( configureResources() ), actionCollection(),
1817 "kaddressbook_configure_resources" ); 1817 "kaddressbook_configure_resources" );
1818#endif //KAB_EMBEDDED 1818#endif //KAB_EMBEDDED
1819 1819
1820 if ( mIsPart ) { 1820 if ( mIsPart ) {
1821 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1821 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1822 SLOT( openConfigDialog() ), actionCollection(), 1822 SLOT( openConfigDialog() ), actionCollection(),
1823 "kaddressbook_configure" ); 1823 "kaddressbook_configure" );
1824 1824
1825 //US not implemented yet 1825 //US not implemented yet
1826 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1826 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1827 // this, SLOT( configureKeyBindings() ), actionCollection(), 1827 // this, SLOT( configureKeyBindings() ), actionCollection(),
1828 // "kaddressbook_configure_shortcuts" ); 1828 // "kaddressbook_configure_shortcuts" );
1829#ifdef KAB_EMBEDDED 1829#ifdef KAB_EMBEDDED
1830 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1830 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1831 mActionConfigureToolbars->setEnabled( false ); 1831 mActionConfigureToolbars->setEnabled( false );
1832#endif //KAB_EMBEDDED 1832#endif //KAB_EMBEDDED
1833 1833
1834 } else { 1834 } else {
1835 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1835 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1836 1836
1837 //US not implemented yet 1837 //US not implemented yet
1838 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1838 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1839 } 1839 }
1840 1840
1841 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1841 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1842 actionCollection(), "options_show_jump_bar" ); 1842 actionCollection(), "options_show_jump_bar" );
1843 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1843 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1844 1844
1845 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1845 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1846 actionCollection(), "options_show_details" ); 1846 actionCollection(), "options_show_details" );
1847 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1847 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1848 1848
1849 1849
1850 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, 1850 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this,
1851 SLOT( toggleBeamReceive() ), actionCollection(), 1851 SLOT( toggleBeamReceive() ), actionCollection(),
1852 "kaddressbook_beam_rec" ); 1852 "kaddressbook_beam_rec" );
1853 1853
1854 1854
1855 // misc 1855 // misc
1856 // only enable LDAP lookup if we can handle the protocol 1856 // only enable LDAP lookup if we can handle the protocol
1857#ifndef KAB_EMBEDDED 1857#ifndef KAB_EMBEDDED
1858 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1858 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1859 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1859 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1860 this, SLOT( openLDAPDialog() ), actionCollection(), 1860 this, SLOT( openLDAPDialog() ), actionCollection(),
1861 "ldap_lookup" ); 1861 "ldap_lookup" );
1862 } 1862 }
1863#else //KAB_EMBEDDED 1863#else //KAB_EMBEDDED
1864 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1864 //qDebug("KABCore::initActions() LDAP has to be implemented");
1865#endif //KAB_EMBEDDED 1865#endif //KAB_EMBEDDED
1866 1866
1867 1867
1868 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1868 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1869 SLOT( setWhoAmI() ), actionCollection(), 1869 SLOT( setWhoAmI() ), actionCollection(),
1870 "set_personal" ); 1870 "set_personal" );
1871 1871
1872 1872
1873 1873
1874 1874
1875 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1875 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1876 SLOT( setCategories() ), actionCollection(), 1876 SLOT( setCategories() ), actionCollection(),
1877 "edit_set_categories" ); 1877 "edit_set_categories" );
1878 1878
1879 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1879 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1880 SLOT( removeVoice() ), actionCollection(), 1880 SLOT( removeVoice() ), actionCollection(),
1881 "remove_voice" ); 1881 "remove_voice" );
1882 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1882 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1883 SLOT( importFromOL() ), actionCollection(), 1883 SLOT( importFromOL() ), actionCollection(),
1884 "import_OL" ); 1884 "import_OL" );
1885#ifdef KAB_EMBEDDED 1885#ifdef KAB_EMBEDDED
1886 mActionLicence = new KAction( i18n( "Licence" ), 0, 1886 mActionLicence = new KAction( i18n( "Licence" ), 0,
1887 this, SLOT( showLicence() ), actionCollection(), 1887 this, SLOT( showLicence() ), actionCollection(),
1888 "licence_about_data" ); 1888 "licence_about_data" );
1889 mActionFaq = new KAction( i18n( "Faq" ), 0, 1889 mActionFaq = new KAction( i18n( "Faq" ), 0,
1890 this, SLOT( faq() ), actionCollection(), 1890 this, SLOT( faq() ), actionCollection(),
1891 "faq_about_data" ); 1891 "faq_about_data" );
1892 mActionWN = new KAction( i18n( "What's New?" ), 0, 1892 mActionWN = new KAction( i18n( "What's New?" ), 0,
1893 this, SLOT( whatsnew() ), actionCollection(), 1893 this, SLOT( whatsnew() ), actionCollection(),
1894 "wn" ); 1894 "wn" );
1895 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, 1895 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0,
1896 this, SLOT( synchowto() ), actionCollection(), 1896 this, SLOT( synchowto() ), actionCollection(),
1897 "sync" ); 1897 "sync" );
1898 1898
1899 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1899 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1900 this, SLOT( createAboutData() ), actionCollection(), 1900 this, SLOT( createAboutData() ), actionCollection(),
1901 "kaddressbook_about_data" ); 1901 "kaddressbook_about_data" );
1902#endif //KAB_EMBEDDED 1902#endif //KAB_EMBEDDED
1903 1903
1904 clipboardDataChanged(); 1904 clipboardDataChanged();
1905 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1905 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1906 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1906 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1907} 1907}
1908 1908
1909//US we need this function, to plug all actions into the correct menues. 1909//US we need this function, to plug all actions into the correct menues.
1910// KDE uses a XML format to plug the actions, but we work her without this overhead. 1910// KDE uses a XML format to plug the actions, but we work her without this overhead.
1911void KABCore::addActionsManually() 1911void KABCore::addActionsManually()
1912{ 1912{
1913//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1913//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1914 1914
1915#ifdef KAB_EMBEDDED 1915#ifdef KAB_EMBEDDED
1916 QPopupMenu *fileMenu = new QPopupMenu( this ); 1916 QPopupMenu *fileMenu = new QPopupMenu( this );
1917 QPopupMenu *editMenu = new QPopupMenu( this ); 1917 QPopupMenu *editMenu = new QPopupMenu( this );
1918 QPopupMenu *helpMenu = new QPopupMenu( this ); 1918 QPopupMenu *helpMenu = new QPopupMenu( this );
1919 1919
1920 KToolBar* tb = mMainWindow->toolBar(); 1920 KToolBar* tb = mMainWindow->toolBar();
1921 1921
1922#ifdef DESKTOP_VERSION 1922#ifdef DESKTOP_VERSION
1923 QMenuBar* mb = mMainWindow->menuBar(); 1923 QMenuBar* mb = mMainWindow->menuBar();
1924 1924
1925 //US setup menubar. 1925 //US setup menubar.
1926 //Disable the following block if you do not want to have a menubar. 1926 //Disable the following block if you do not want to have a menubar.
1927 mb->insertItem( "&File", fileMenu ); 1927 mb->insertItem( "&File", fileMenu );
1928 mb->insertItem( "&Edit", editMenu ); 1928 mb->insertItem( "&Edit", editMenu );
1929 mb->insertItem( "&View", viewMenu ); 1929 mb->insertItem( "&View", viewMenu );
1930 mb->insertItem( "&Settings", settingsMenu ); 1930 mb->insertItem( "&Settings", settingsMenu );
1931 mb->insertItem( i18n("Synchronize"), syncMenu ); 1931 mb->insertItem( i18n("Synchronize"), syncMenu );
1932 mb->insertItem( "&Change selected", changeMenu ); 1932 mb->insertItem( "&Change selected", changeMenu );
1933 mb->insertItem( "&Help", helpMenu ); 1933 mb->insertItem( "&Help", helpMenu );
1934 mIncSearchWidget = new IncSearchWidget( tb ); 1934 mIncSearchWidget = new IncSearchWidget( tb );
1935 // tb->insertWidget(-1, 0, mIncSearchWidget); 1935 // tb->insertWidget(-1, 0, mIncSearchWidget);
1936 1936
1937#else 1937#else
1938 //US setup toolbar 1938 //US setup toolbar
1939 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1939 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1940 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1940 QPopupMenu *popupBarTB = new QPopupMenu( this );
1941 menuBarTB->insertItem( "ME", popupBarTB); 1941 menuBarTB->insertItem( "ME", popupBarTB);
1942 tb->insertWidget(-1, 0, menuBarTB); 1942 tb->insertWidget(-1, 0, menuBarTB);
1943 mIncSearchWidget = new IncSearchWidget( tb ); 1943 mIncSearchWidget = new IncSearchWidget( tb );
1944 1944
1945 tb->enableMoving(false); 1945 tb->enableMoving(false);
1946 popupBarTB->insertItem( "&File", fileMenu ); 1946 popupBarTB->insertItem( "&File", fileMenu );
1947 popupBarTB->insertItem( "&Edit", editMenu ); 1947 popupBarTB->insertItem( "&Edit", editMenu );
1948 popupBarTB->insertItem( "&View", viewMenu ); 1948 popupBarTB->insertItem( "&View", viewMenu );
1949 popupBarTB->insertItem( "&Settings", settingsMenu ); 1949 popupBarTB->insertItem( "&Settings", settingsMenu );
1950 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1950 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1951 mViewManager->getFilterAction()->plug ( popupBarTB); 1951 mViewManager->getFilterAction()->plug ( popupBarTB);
1952 popupBarTB->insertItem( "&Change selected", changeMenu ); 1952 popupBarTB->insertItem( "&Change selected", changeMenu );
1953 popupBarTB->insertItem( "&Help", helpMenu ); 1953 popupBarTB->insertItem( "&Help", helpMenu );
1954 if (QApplication::desktop()->width() > 320 ) { 1954 if (QApplication::desktop()->width() > 320 ) {
1955 // mViewManager->getFilterAction()->plug ( tb); 1955 // mViewManager->getFilterAction()->plug ( tb);
1956 } 1956 }
1957#endif 1957#endif
1958 // mActionQuit->plug ( mMainWindow->toolBar()); 1958 // mActionQuit->plug ( mMainWindow->toolBar());
1959 1959
1960 1960
1961 1961
1962 //US Now connect the actions with the menue entries. 1962 //US Now connect the actions with the menue entries.
1963 mActionPrint->plug( fileMenu ); 1963 mActionPrint->plug( fileMenu );
1964 mActionMail->plug( fileMenu ); 1964 mActionMail->plug( fileMenu );
1965 fileMenu->insertSeparator(); 1965 fileMenu->insertSeparator();
1966 1966
1967 mActionNewContact->plug( fileMenu ); 1967 mActionNewContact->plug( fileMenu );
1968 mActionNewContact->plug( tb ); 1968 mActionNewContact->plug( tb );
1969 1969
1970 mActionEditAddressee->plug( fileMenu ); 1970 mActionEditAddressee->plug( fileMenu );
1971 if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1971 if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1972 (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1972 (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1973 mActionEditAddressee->plug( tb ); 1973 mActionEditAddressee->plug( tb );
1974 1974
1975 fileMenu->insertSeparator(); 1975 fileMenu->insertSeparator();
1976 mActionSave->plug( fileMenu ); 1976 mActionSave->plug( fileMenu );
1977 fileMenu->insertItem( "&Import", ImportMenu ); 1977 fileMenu->insertItem( "&Import", ImportMenu );
1978 fileMenu->insertItem( "&Export", ExportMenu ); 1978 fileMenu->insertItem( "&Export", ExportMenu );
1979 fileMenu->insertSeparator(); 1979 fileMenu->insertSeparator();
1980 mActionMailVCard->plug( fileMenu ); 1980 mActionMailVCard->plug( fileMenu );
1981#ifndef DESKTOP_VERSION 1981#ifndef DESKTOP_VERSION
1982 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1982 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
1983 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 1983 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
1984#endif 1984#endif
1985 fileMenu->insertSeparator(); 1985 fileMenu->insertSeparator();
1986 mActionQuit->plug( fileMenu ); 1986 mActionQuit->plug( fileMenu );
1987#ifdef _WIN32_ 1987#ifdef _WIN32_
1988 mActionImportOL->plug( ImportMenu ); 1988 mActionImportOL->plug( ImportMenu );
1989#endif 1989#endif
1990 // edit menu 1990 // edit menu
1991 mActionUndo->plug( editMenu ); 1991 mActionUndo->plug( editMenu );
1992 mActionRedo->plug( editMenu ); 1992 mActionRedo->plug( editMenu );
1993 editMenu->insertSeparator(); 1993 editMenu->insertSeparator();
1994 mActionCut->plug( editMenu ); 1994 mActionCut->plug( editMenu );
1995 mActionCopy->plug( editMenu ); 1995 mActionCopy->plug( editMenu );
1996 mActionPaste->plug( editMenu ); 1996 mActionPaste->plug( editMenu );
1997 mActionDelete->plug( editMenu ); 1997 mActionDelete->plug( editMenu );
1998 editMenu->insertSeparator(); 1998 editMenu->insertSeparator();
1999 mActionSelectAll->plug( editMenu ); 1999 mActionSelectAll->plug( editMenu );
2000 2000
2001 mActionRemoveVoice->plug( changeMenu ); 2001 mActionRemoveVoice->plug( changeMenu );
2002 // settings menu 2002 // settings menu
2003//US special menuentry to configure the addressbook resources. On KDE 2003//US special menuentry to configure the addressbook resources. On KDE
2004// you do that through the control center !!! 2004// you do that through the control center !!!
2005 mActionConfigResources->plug( settingsMenu ); 2005 mActionConfigResources->plug( settingsMenu );
2006 settingsMenu->insertSeparator(); 2006 settingsMenu->insertSeparator();
2007 2007
2008 mActionConfigKAddressbook->plug( settingsMenu ); 2008 mActionConfigKAddressbook->plug( settingsMenu );
2009 2009
2010 if ( mIsPart ) { 2010 if ( mIsPart ) {
2011 //US not implemented yet 2011 //US not implemented yet
2012 //mActionConfigShortcuts->plug( settingsMenu ); 2012 //mActionConfigShortcuts->plug( settingsMenu );
2013 //mActionConfigureToolbars->plug( settingsMenu ); 2013 //mActionConfigureToolbars->plug( settingsMenu );
2014 2014
2015 } else { 2015 } else {
2016 //US not implemented yet 2016 //US not implemented yet
2017 //mActionKeyBindings->plug( settingsMenu ); 2017 //mActionKeyBindings->plug( settingsMenu );
2018 } 2018 }
2019 2019
2020 settingsMenu->insertSeparator(); 2020 settingsMenu->insertSeparator();
2021 2021
2022 mActionJumpBar->plug( settingsMenu ); 2022 mActionJumpBar->plug( settingsMenu );
2023 mActionDetails->plug( settingsMenu ); 2023 mActionDetails->plug( settingsMenu );
2024 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 2024 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
2025 mActionDetails->plug( tb ); 2025 mActionDetails->plug( tb );
2026 settingsMenu->insertSeparator(); 2026 settingsMenu->insertSeparator();
2027 mActionBR->plug(settingsMenu ); 2027 mActionBR->plug(settingsMenu );
2028 settingsMenu->insertSeparator(); 2028 settingsMenu->insertSeparator();
2029 2029
2030 mActionWhoAmI->plug( settingsMenu ); 2030 mActionWhoAmI->plug( settingsMenu );
2031 mActionCategories->plug( settingsMenu ); 2031 mActionCategories->plug( settingsMenu );
2032 2032
2033 2033
2034 mActionWN->plug( helpMenu ); 2034 mActionWN->plug( helpMenu );
2035 mActionSyncHowto->plug( helpMenu ); 2035 mActionSyncHowto->plug( helpMenu );
2036 mActionLicence->plug( helpMenu ); 2036 mActionLicence->plug( helpMenu );
2037 mActionFaq->plug( helpMenu ); 2037 mActionFaq->plug( helpMenu );
2038 mActionAboutKAddressbook->plug( helpMenu ); 2038 mActionAboutKAddressbook->plug( helpMenu );
2039 2039
2040 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 2040 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
2041 2041
2042 mActionSave->plug( tb ); 2042 mActionSave->plug( tb );
2043 mViewManager->getFilterAction()->plug ( tb); 2043 mViewManager->getFilterAction()->plug ( tb);
2044 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 2044 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
2045 mActionUndo->plug( tb ); 2045 mActionUndo->plug( tb );
2046 mActionDelete->plug( tb ); 2046 mActionDelete->plug( tb );
2047 mActionRedo->plug( tb ); 2047 mActionRedo->plug( tb );
2048 } 2048 }
2049 } else { 2049 } else {
2050 if (KABPrefs::instance()->mMultipleViewsAtOnce ) 2050 if (KABPrefs::instance()->mMultipleViewsAtOnce )
2051 mActionSave->plug( tb ); 2051 mActionSave->plug( tb );
2052 } 2052 }
2053 //mActionQuit->plug ( tb ); 2053 //mActionQuit->plug ( tb );
2054 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 2054 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
2055 2055
2056 //US link the searchwidget first to this. 2056 //US link the searchwidget first to this.
2057 // The real linkage to the toolbar happens later. 2057 // The real linkage to the toolbar happens later.
2058//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 2058//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
2059//US tb->insertItem( mIncSearchWidget ); 2059//US tb->insertItem( mIncSearchWidget );
2060/*US 2060/*US
2061 mIncSearchWidget = new IncSearchWidget( tb ); 2061 mIncSearchWidget = new IncSearchWidget( tb );
2062 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 2062 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
2063 SLOT( incrementalSearch( const QString& ) ) ); 2063 SLOT( incrementalSearch( const QString& ) ) );
2064 2064
2065 mJumpButtonBar = new JumpButtonBar( this, this ); 2065 mJumpButtonBar = new JumpButtonBar( this, this );
2066 2066
2067//US topLayout->addWidget( mJumpButtonBar ); 2067//US topLayout->addWidget( mJumpButtonBar );
2068 this->layout()->add( mJumpButtonBar ); 2068 this->layout()->add( mJumpButtonBar );
2069*/ 2069*/
2070 2070
2071#endif //KAB_EMBEDDED 2071#endif //KAB_EMBEDDED
2072 2072
2073 mActionExport2phone->plug( ExportMenu ); 2073 mActionExport2phone->plug( ExportMenu );
2074 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 2074 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
2075 syncManager->fillSyncMenu(); 2075 syncManager->fillSyncMenu();
2076 2076
2077} 2077}
2078void KABCore::showLicence() 2078void KABCore::showLicence()
2079{ 2079{
2080 KApplication::showLicence(); 2080 KApplication::showLicence();
2081} 2081}
2082void KABCore::removeVoice() 2082void KABCore::removeVoice()
2083{ 2083{
2084 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 ) 2084 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 )
2085 return; 2085 return;
2086 KABC::Addressee::List list = mViewManager->selectedAddressees(); 2086 KABC::Addressee::List list = mViewManager->selectedAddressees();
2087 KABC::Addressee::List::Iterator it; 2087 KABC::Addressee::List::Iterator it;
2088 for ( it = list.begin(); it != list.end(); ++it ) { 2088 for ( it = list.begin(); it != list.end(); ++it ) {
2089 2089
2090 if ( (*it).removeVoice() ) 2090 if ( (*it).removeVoice() )
2091 contactModified((*it) ); 2091 contactModified((*it) );
2092 } 2092 }
2093} 2093}
2094 2094
2095 2095
2096 2096
2097void KABCore::clipboardDataChanged() 2097void KABCore::clipboardDataChanged()
2098{ 2098{
2099 2099
2100 if ( mReadWrite ) 2100 if ( mReadWrite )
2101 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2101 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2102 2102
2103} 2103}
2104 2104
2105void KABCore::updateActionMenu() 2105void KABCore::updateActionMenu()
2106{ 2106{
2107 UndoStack *undo = UndoStack::instance(); 2107 UndoStack *undo = UndoStack::instance();
2108 RedoStack *redo = RedoStack::instance(); 2108 RedoStack *redo = RedoStack::instance();
2109 2109
2110 if ( undo->isEmpty() ) 2110 if ( undo->isEmpty() )
2111 mActionUndo->setText( i18n( "Undo" ) ); 2111 mActionUndo->setText( i18n( "Undo" ) );
2112 else 2112 else
2113 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2113 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2114 2114
2115 mActionUndo->setEnabled( !undo->isEmpty() ); 2115 mActionUndo->setEnabled( !undo->isEmpty() );
2116 2116
2117 if ( !redo->top() ) 2117 if ( !redo->top() )
2118 mActionRedo->setText( i18n( "Redo" ) ); 2118 mActionRedo->setText( i18n( "Redo" ) );
2119 else 2119 else
2120 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 2120 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
2121 2121
2122 mActionRedo->setEnabled( !redo->isEmpty() ); 2122 mActionRedo->setEnabled( !redo->isEmpty() );
2123} 2123}
2124 2124
2125void KABCore::configureKeyBindings() 2125void KABCore::configureKeyBindings()
2126{ 2126{
2127#ifndef KAB_EMBEDDED 2127#ifndef KAB_EMBEDDED
2128 KKeyDialog::configure( actionCollection(), true ); 2128 KKeyDialog::configure( actionCollection(), true );
2129#else //KAB_EMBEDDED 2129#else //KAB_EMBEDDED
2130 qDebug("KABCore::configureKeyBindings() not implemented"); 2130 qDebug("KABCore::configureKeyBindings() not implemented");
2131#endif //KAB_EMBEDDED 2131#endif //KAB_EMBEDDED
2132} 2132}
2133 2133
2134#ifdef KAB_EMBEDDED 2134#ifdef KAB_EMBEDDED
2135void KABCore::configureResources() 2135void KABCore::configureResources()
2136{ 2136{
2137 KRES::KCMKResources dlg( this, "" , 0 ); 2137 KRES::KCMKResources dlg( this, "" , 0 );
2138 2138
2139 if ( !dlg.exec() ) 2139 if ( !dlg.exec() )
2140 return; 2140 return;
2141 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 2141 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
2142} 2142}
2143#endif //KAB_EMBEDDED 2143#endif //KAB_EMBEDDED
2144 2144
2145 2145
2146/* this method will be called through the QCop interface from Ko/Pi to select addresses 2146/* this method will be called through the QCop interface from Ko/Pi to select addresses
2147 * for the attendees list of an event. 2147 * for the attendees list of an event.
2148 */ 2148 */
2149void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 2149void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
2150{ 2150{
2151 QStringList nameList; 2151 QStringList nameList;
2152 QStringList emailList; 2152 QStringList emailList;
2153 QStringList uidList; 2153 QStringList uidList;
2154 2154
2155 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 2155 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
2156 uint i=0; 2156 uint i=0;
2157 for (i=0; i < list.count(); i++) 2157 for (i=0; i < list.count(); i++)
2158 { 2158 {
2159 nameList.append(list[i].realName()); 2159 nameList.append(list[i].realName());
2160 emailList.append(list[i].preferredEmail()); 2160 emailList.append(list[i].preferredEmail());
2161 uidList.append(list[i].uid()); 2161 uidList.append(list[i].uid());
2162 } 2162 }
2163 2163
2164 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2164 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2165 2165
2166} 2166}
2167 2167
2168/* this method will be called through the QCop interface from Ko/Pi to select birthdays 2168/* this method will be called through the QCop interface from Ko/Pi to select birthdays
2169 * to put them into the calendar. 2169 * to put them into the calendar.
2170 */ 2170 */
2171void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) 2171void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
2172{ 2172{
2173 // qDebug("KABCore::requestForBirthdayList"); 2173 // qDebug("KABCore::requestForBirthdayList");
2174 QStringList birthdayList; 2174 QStringList birthdayList;
2175 QStringList anniversaryList; 2175 QStringList anniversaryList;
2176 QStringList realNameList; 2176 QStringList realNameList;
2177 QStringList preferredEmailList; 2177 QStringList preferredEmailList;
2178 QStringList assembledNameList; 2178 QStringList assembledNameList;
2179 QStringList uidList; 2179 QStringList uidList;
2180 2180
2181 KABC::AddressBook::Iterator it; 2181 KABC::AddressBook::Iterator it;
2182 2182
2183 int count = 0; 2183 int count = 0;
2184 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 2184 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2185 ++count; 2185 ++count;
2186 } 2186 }
2187 QProgressBar bar(count,0 ); 2187 QProgressBar bar(count,0 );
2188 int w = 300; 2188 int w = 300;
2189 if ( QApplication::desktop()->width() < 320 ) 2189 if ( QApplication::desktop()->width() < 320 )
2190 w = 220; 2190 w = 220;
2191 int h = bar.sizeHint().height() ; 2191 int h = bar.sizeHint().height() ;
2192 int dw = QApplication::desktop()->width(); 2192 int dw = QApplication::desktop()->width();
2193 int dh = QApplication::desktop()->height(); 2193 int dh = QApplication::desktop()->height();
2194 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2194 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2195 bar.show(); 2195 bar.show();
2196 bar.setCaption (i18n("Collecting birthdays - close to abort!") ); 2196 bar.setCaption (i18n("Collecting birthdays - close to abort!") );
2197 qApp->processEvents(); 2197 qApp->processEvents();
2198 2198
2199 QDate bday; 2199 QDate bday;
2200 QString anni; 2200 QString anni;
2201 QString formattedbday; 2201 QString formattedbday;
2202 2202
2203 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) 2203 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
2204 { 2204 {
2205 if ( ! bar.isVisible() ) 2205 if ( ! bar.isVisible() )
2206 return; 2206 return;
2207 bar.setProgress( count++ ); 2207 bar.setProgress( count++ );
2208 qApp->processEvents(); 2208 qApp->processEvents();
2209 bday = (*it).birthday().date(); 2209 bday = (*it).birthday().date();
2210 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); 2210 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
2211 2211
2212 if ( bday.isValid() || !anni.isEmpty()) 2212 if ( bday.isValid() || !anni.isEmpty())
2213 { 2213 {
2214 if (bday.isValid()) 2214 if (bday.isValid())
2215 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); 2215 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
2216 else 2216 else
2217 formattedbday = "NOTVALID"; 2217 formattedbday = "NOTVALID";
2218 if (anni.isEmpty()) 2218 if (anni.isEmpty())
2219 anni = "INVALID"; 2219 anni = "INVALID";
2220 2220
2221 birthdayList.append(formattedbday); 2221 birthdayList.append(formattedbday);
2222 anniversaryList.append(anni); //should be ISODate 2222 anniversaryList.append(anni); //should be ISODate
2223 realNameList.append((*it).realName()); 2223 realNameList.append((*it).realName());
2224 preferredEmailList.append((*it).preferredEmail()); 2224 preferredEmailList.append((*it).preferredEmail());
2225 assembledNameList.append((*it).assembledName()); 2225 assembledNameList.append((*it).assembledName());
2226 uidList.append((*it).uid()); 2226 uidList.append((*it).uid());
2227 2227
2228 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); 2228 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
2229 } 2229 }
2230 } 2230 }
2231 2231
2232 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); 2232 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
2233 2233
2234} 2234}
2235 2235
2236/* this method will be called through the QCop interface from other apps to show details of a contact. 2236/* this method will be called through the QCop interface from other apps to show details of a contact.
2237 */ 2237 */
2238void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2238void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2239{ 2239{
2240 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2240 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2241 2241
2242 QString foundUid = QString::null; 2242 QString foundUid = QString::null;
2243 if ( ! uid.isEmpty() ) { 2243 if ( ! uid.isEmpty() ) {
2244 Addressee adrr = mAddressBook->findByUid( uid ); 2244 Addressee adrr = mAddressBook->findByUid( uid );
2245 if ( !adrr.isEmpty() ) { 2245 if ( !adrr.isEmpty() ) {
2246 foundUid = uid; 2246 foundUid = uid;
2247 } 2247 }
2248 if ( email == "sendbacklist" ) { 2248 if ( email == "sendbacklist" ) {
2249 //qDebug("ssssssssssssssssssssssend "); 2249 //qDebug("ssssssssssssssssssssssend ");
2250 QStringList nameList; 2250 QStringList nameList;
2251 QStringList emailList; 2251 QStringList emailList;
2252 QStringList uidList; 2252 QStringList uidList;
2253 nameList.append(adrr.realName()); 2253 nameList.append(adrr.realName());
2254 emailList = adrr.emails(); 2254 emailList = adrr.emails();
2255 uidList.append( adrr.preferredEmail()); 2255 uidList.append( adrr.preferredEmail());
2256 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2256 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2257 return; 2257 return;
2258 } 2258 }
2259 2259
2260 } 2260 }
2261 2261
2262 if ( email == "sendbacklist" ) 2262 if ( email == "sendbacklist" )
2263 return; 2263 return;
2264 if (foundUid.isEmpty()) 2264 if (foundUid.isEmpty())
2265 { 2265 {
2266 //find the uid of the person first 2266 //find the uid of the person first
2267 Addressee::List namelist; 2267 Addressee::List namelist;
2268 Addressee::List emaillist; 2268 Addressee::List emaillist;
2269 2269
2270 if (!name.isEmpty()) 2270 if (!name.isEmpty())
2271 namelist = mAddressBook->findByName( name ); 2271 namelist = mAddressBook->findByName( name );
2272 2272
2273 if (!email.isEmpty()) 2273 if (!email.isEmpty())
2274 emaillist = mAddressBook->findByEmail( email ); 2274 emaillist = mAddressBook->findByEmail( email );
2275 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2275 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2276 //check if we have a match in Namelist and Emaillist 2276 //check if we have a match in Namelist and Emaillist
2277 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2277 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2278 foundUid = emaillist[0].uid(); 2278 foundUid = emaillist[0].uid();
2279 } 2279 }
2280 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2280 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2281 foundUid = namelist[0].uid(); 2281 foundUid = namelist[0].uid();
2282 else 2282 else
2283 { 2283 {
2284 for (int i = 0; i < namelist.count(); i++) 2284 for (int i = 0; i < namelist.count(); i++)
2285 { 2285 {
2286 for (int j = 0; j < emaillist.count(); j++) 2286 for (int j = 0; j < emaillist.count(); j++)
2287 { 2287 {
2288 if (namelist[i] == emaillist[j]) 2288 if (namelist[i] == emaillist[j])
2289 { 2289 {
2290 foundUid = namelist[i].uid(); 2290 foundUid = namelist[i].uid();
2291 } 2291 }
2292 } 2292 }
2293 } 2293 }
2294 } 2294 }
2295 } 2295 }
2296 else 2296 else
2297 { 2297 {
2298 foundUid = uid; 2298 foundUid = uid;
2299 } 2299 }
2300 2300
2301 if (!foundUid.isEmpty()) 2301 if (!foundUid.isEmpty())
2302 { 2302 {
2303 2303
2304 // raise Ka/Pi if it is in the background 2304 // raise Ka/Pi if it is in the background
2305#ifndef DESKTOP_VERSION 2305#ifndef DESKTOP_VERSION
2306#ifndef KORG_NODCOP 2306#ifndef KORG_NODCOP
2307 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2307 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2308#endif 2308#endif
2309#endif 2309#endif
2310 2310
2311 mMainWindow->showMaximized(); 2311 mMainWindow->showMaximized();
2312 mMainWindow-> raise(); 2312 mMainWindow-> raise();
2313 2313
2314 mViewManager->setSelected( "", false); 2314 mViewManager->setSelected( "", false);
2315 mViewManager->refreshView( "" ); 2315 mViewManager->refreshView( "" );
2316 mViewManager->setSelected( foundUid, true ); 2316 mViewManager->setSelected( foundUid, true );
2317 mViewManager->refreshView( foundUid ); 2317 mViewManager->refreshView( foundUid );
2318 2318
2319 if ( !mMultipleViewsAtOnce ) 2319 if ( !mMultipleViewsAtOnce )
2320 { 2320 {
2321 setDetailsVisible( true ); 2321 setDetailsVisible( true );
2322 mActionDetails->setChecked(true); 2322 mActionDetails->setChecked(true);
2323 } 2323 }
2324 } 2324 }
2325} 2325}
2326 2326
2327void KABCore::whatsnew() 2327void KABCore::whatsnew()
2328{ 2328{
2329 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 2329 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
2330} 2330}
2331void KABCore::synchowto() 2331void KABCore::synchowto()
2332{ 2332{
2333 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 2333 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
2334} 2334}
2335 2335
2336void KABCore::faq() 2336void KABCore::faq()
2337{ 2337{
2338 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2338 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2339} 2339}
2340 2340
2341#include <libkcal/syncdefines.h> 2341#include <libkcal/syncdefines.h>
2342 2342
2343KABC::Addressee KABCore::getLastSyncAddressee() 2343KABC::Addressee KABCore::getLastSyncAddressee()
2344{ 2344{
2345 Addressee lse; 2345 Addressee lse;
2346 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2346 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2347 2347
2348 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2348 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2349 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2349 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2350 if (lse.isEmpty()) { 2350 if (lse.isEmpty()) {
2351 qDebug("Creating new last-syncAddressee "); 2351 qDebug("Creating new last-syncAddressee ");
2352 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2352 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2353 QString sum = ""; 2353 QString sum = "";
2354 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2354 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2355 sum = "E: "; 2355 sum = "E: ";
2356 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2356 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2357 lse.setRevision( mLastAddressbookSync ); 2357 lse.setRevision( mLastAddressbookSync );
2358 lse.setCategories( i18n("SyncEvent") ); 2358 lse.setCategories( i18n("SyncEvent") );
2359 mAddressBook->insertAddressee( lse ); 2359 mAddressBook->insertAddressee( lse );
2360 } 2360 }
2361 return lse; 2361 return lse;
2362} 2362}
2363int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2363int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2364{ 2364{
2365 2365
2366 //void setZaurusId(int id); 2366 //void setZaurusId(int id);
2367 // int zaurusId() const; 2367 // int zaurusId() const;
2368 // void setZaurusUid(int id); 2368 // void setZaurusUid(int id);
2369 // int zaurusUid() const; 2369 // int zaurusUid() const;
2370 // void setZaurusStat(int id); 2370 // void setZaurusStat(int id);
2371 // int zaurusStat() const; 2371 // int zaurusStat() const;
2372 // 0 equal 2372 // 0 equal
2373 // 1 take local 2373 // 1 take local
2374 // 2 take remote 2374 // 2 take remote
2375 // 3 cancel 2375 // 3 cancel
2376 QDateTime lastSync = mLastAddressbookSync; 2376 QDateTime lastSync = mLastAddressbookSync;
2377 QDateTime localMod = local->revision(); 2377 QDateTime localMod = local->revision();
2378 QDateTime remoteMod = remote->revision(); 2378 QDateTime remoteMod = remote->revision();
2379 2379
2380 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2380 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2381 2381
2382 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2382 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2383 bool remCh, locCh; 2383 bool remCh, locCh;
2384 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2384 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2385 2385
2386 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2386 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2387 locCh = ( localMod > mLastAddressbookSync ); 2387 locCh = ( localMod > mLastAddressbookSync );
2388 if ( !remCh && ! locCh ) { 2388 if ( !remCh && ! locCh ) {
2389 //qDebug("both not changed "); 2389 //qDebug("both not changed ");
2390 lastSync = localMod.addDays(1); 2390 lastSync = localMod.addDays(1);
2391 if ( mode <= SYNC_PREF_ASK ) 2391 if ( mode <= SYNC_PREF_ASK )
2392 return 0; 2392 return 0;
2393 } else { 2393 } else {
2394 if ( locCh ) { 2394 if ( locCh ) {
2395 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2395 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2396 lastSync = localMod.addDays( -1 ); 2396 lastSync = localMod.addDays( -1 );
2397 if ( !remCh ) 2397 if ( !remCh )
2398 remoteMod =( lastSync.addDays( -1 ) ); 2398 remoteMod =( lastSync.addDays( -1 ) );
2399 } else { 2399 } else {
2400 //qDebug(" not loc changed "); 2400 //qDebug(" not loc changed ");
2401 lastSync = localMod.addDays( 1 ); 2401 lastSync = localMod.addDays( 1 );
2402 if ( remCh ) 2402 if ( remCh )
2403 remoteMod =( lastSync.addDays( 1 ) ); 2403 remoteMod =( lastSync.addDays( 1 ) );
2404 2404
2405 } 2405 }
2406 } 2406 }
2407 full = true; 2407 full = true;
2408 if ( mode < SYNC_PREF_ASK ) 2408 if ( mode < SYNC_PREF_ASK )
2409 mode = SYNC_PREF_ASK; 2409 mode = SYNC_PREF_ASK;
2410 } else { 2410 } else {
2411 if ( localMod == remoteMod ) 2411 if ( localMod == remoteMod )
2412 return 0; 2412 return 0;
2413 2413
2414 } 2414 }
2415 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2415 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2416 2416
2417 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2417 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2418 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2418 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2419 //full = true; //debug only 2419 //full = true; //debug only
2420 if ( full ) { 2420 if ( full ) {
2421 bool equ = ( (*local) == (*remote) ); 2421 bool equ = ( (*local) == (*remote) );
2422 if ( equ ) { 2422 if ( equ ) {
2423 //qDebug("equal "); 2423 //qDebug("equal ");
2424 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2424 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2425 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2425 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2426 } 2426 }
2427 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2427 if ( mode < SYNC_PREF_FORCE_LOCAL )
2428 return 0; 2428 return 0;
2429 2429
2430 }//else //debug only 2430 }//else //debug only
2431 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2431 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2432 } 2432 }
2433 int result; 2433 int result;
2434 bool localIsNew; 2434 bool localIsNew;
2435 //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() ); 2435 //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() );
2436 2436
2437 if ( full && mode < SYNC_PREF_NEWEST ) 2437 if ( full && mode < SYNC_PREF_NEWEST )
2438 mode = SYNC_PREF_ASK; 2438 mode = SYNC_PREF_ASK;
2439 2439
2440 switch( mode ) { 2440 switch( mode ) {
2441 case SYNC_PREF_LOCAL: 2441 case SYNC_PREF_LOCAL:
2442 if ( lastSync > remoteMod ) 2442 if ( lastSync > remoteMod )
2443 return 1; 2443 return 1;
2444 if ( lastSync > localMod ) 2444 if ( lastSync > localMod )
2445 return 2; 2445 return 2;
2446 return 1; 2446 return 1;
2447 break; 2447 break;
2448 case SYNC_PREF_REMOTE: 2448 case SYNC_PREF_REMOTE:
2449 if ( lastSync > remoteMod ) 2449 if ( lastSync > remoteMod )
2450 return 1; 2450 return 1;
2451 if ( lastSync > localMod ) 2451 if ( lastSync > localMod )
2452 return 2; 2452 return 2;
2453 return 2; 2453 return 2;
2454 break; 2454 break;
2455 case SYNC_PREF_NEWEST: 2455 case SYNC_PREF_NEWEST:
2456 if ( localMod > remoteMod ) 2456 if ( localMod > remoteMod )
2457 return 1; 2457 return 1;
2458 else 2458 else
2459 return 2; 2459 return 2;
2460 break; 2460 break;
2461 case SYNC_PREF_ASK: 2461 case SYNC_PREF_ASK:
2462 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2462 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2463 if ( lastSync > remoteMod ) 2463 if ( lastSync > remoteMod )
2464 return 1; 2464 return 1;
2465 if ( lastSync > localMod ) 2465 if ( lastSync > localMod )
2466 return 2; 2466 return 2;
2467 localIsNew = localMod >= remoteMod; 2467 localIsNew = localMod >= remoteMod;
2468 //qDebug("conflict! ************************************** "); 2468 //qDebug("conflict! ************************************** ");
2469 { 2469 {
2470 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2470 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2471 result = acd.executeD(localIsNew); 2471 result = acd.executeD(localIsNew);
2472 return result; 2472 return result;
2473 } 2473 }
2474 break; 2474 break;
2475 case SYNC_PREF_FORCE_LOCAL: 2475 case SYNC_PREF_FORCE_LOCAL:
2476 return 1; 2476 return 1;
2477 break; 2477 break;
2478 case SYNC_PREF_FORCE_REMOTE: 2478 case SYNC_PREF_FORCE_REMOTE:
2479 return 2; 2479 return 2;
2480 break; 2480 break;
2481 2481
2482 default: 2482 default:
2483 // SYNC_PREF_TAKE_BOTH not implemented 2483 // SYNC_PREF_TAKE_BOTH not implemented
2484 break; 2484 break;
2485 } 2485 }
2486 return 0; 2486 return 0;
2487} 2487}
2488 2488
2489 2489
2490bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2490bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2491{ 2491{
2492 bool syncOK = true; 2492 bool syncOK = true;
2493 int addedAddressee = 0; 2493 int addedAddressee = 0;
2494 int addedAddresseeR = 0; 2494 int addedAddresseeR = 0;
2495 int deletedAddresseeR = 0; 2495 int deletedAddresseeR = 0;
2496 int deletedAddresseeL = 0; 2496 int deletedAddresseeL = 0;
2497 int changedLocal = 0; 2497 int changedLocal = 0;
2498 int changedRemote = 0; 2498 int changedRemote = 0;
2499 2499
2500 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2500 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2501 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2501 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2502 2502
2503 //QPtrList<Addressee> el = local->rawAddressees(); 2503 //QPtrList<Addressee> el = local->rawAddressees();
2504 Addressee addresseeR; 2504 Addressee addresseeR;
2505 QString uid; 2505 QString uid;
2506 int take; 2506 int take;
2507 Addressee addresseeL; 2507 Addressee addresseeL;
2508 Addressee addresseeRSync; 2508 Addressee addresseeRSync;
2509 Addressee addresseeLSync; 2509 Addressee addresseeLSync;
2510 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2510 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2511 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2511 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2512 bool fullDateRange = false; 2512 bool fullDateRange = false;
2513 local->resetTempSyncStat(); 2513 local->resetTempSyncStat();
2514 mLastAddressbookSync = QDateTime::currentDateTime(); 2514 mLastAddressbookSync = QDateTime::currentDateTime();
2515 if ( syncManager->syncWithDesktop() ) { 2515 if ( syncManager->syncWithDesktop() ) {
2516 remote->removeSyncInfo( QString());//remove all info 2516 // remote->removeSyncInfo( QString());//remove all info
2517 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 2517 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2518 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; 2518 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2519 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); 2519 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2520 } else { 2520 } else {
2521 qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime "); 2521 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
2522 } 2522 }
2523 } 2523 }
2524 QDateTime modifiedCalendar = mLastAddressbookSync; 2524 QDateTime modifiedCalendar = mLastAddressbookSync;
2525 addresseeLSync = getLastSyncAddressee(); 2525 addresseeLSync = getLastSyncAddressee();
2526 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2526 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2527 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2527 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2528 if ( !addresseeR.isEmpty() ) { 2528 if ( !addresseeR.isEmpty() ) {
2529 addresseeRSync = addresseeR; 2529 addresseeRSync = addresseeR;
2530 remote->removeAddressee(addresseeR ); 2530 remote->removeAddressee(addresseeR );
2531 2531
2532 } else { 2532 } else {
2533 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2533 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2534 addresseeRSync = addresseeLSync ; 2534 addresseeRSync = addresseeLSync ;
2535 } else { 2535 } else {
2536 qDebug("FULLDATE 1"); 2536 qDebug("FULLDATE 1");
2537 fullDateRange = true; 2537 fullDateRange = true;
2538 Addressee newAdd; 2538 Addressee newAdd;
2539 addresseeRSync = newAdd; 2539 addresseeRSync = newAdd;
2540 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2540 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2541 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2541 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2542 addresseeRSync.setRevision( mLastAddressbookSync ); 2542 addresseeRSync.setRevision( mLastAddressbookSync );
2543 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2543 addresseeRSync.setCategories( i18n("SyncAddressee") );
2544 } 2544 }
2545 } 2545 }
2546 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2546 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2547 qDebug("FULLDATE 2"); 2547 qDebug("FULLDATE 2");
2548 fullDateRange = true; 2548 fullDateRange = true;
2549 } 2549 }
2550 if ( ! fullDateRange ) { 2550 if ( ! fullDateRange ) {
2551 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2551 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2552 2552
2553 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2553 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2554 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2554 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2555 fullDateRange = true; 2555 fullDateRange = true;
2556 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2556 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2557 } 2557 }
2558 } 2558 }
2559 // fullDateRange = true; // debug only! 2559 // fullDateRange = true; // debug only!
2560 if ( fullDateRange ) 2560 if ( fullDateRange )
2561 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2561 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2562 else 2562 else
2563 mLastAddressbookSync = addresseeLSync.revision(); 2563 mLastAddressbookSync = addresseeLSync.revision();
2564 // for resyncing if own file has changed 2564 // for resyncing if own file has changed
2565 // PENDING fixme later when implemented 2565 // PENDING fixme later when implemented
2566#if 0 2566#if 0
2567 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2567 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2568 mLastAddressbookSync = loadedFileVersion; 2568 mLastAddressbookSync = loadedFileVersion;
2569 qDebug("setting mLastAddressbookSync "); 2569 qDebug("setting mLastAddressbookSync ");
2570 } 2570 }
2571#endif 2571#endif
2572 2572
2573 //qDebug("*************************** "); 2573 //qDebug("*************************** ");
2574 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2574 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2575 QStringList er = remote->uidList(); 2575 QStringList er = remote->uidList();
2576 Addressee inR ;//= er.first(); 2576 Addressee inR ;//= er.first();
2577 Addressee inL; 2577 Addressee inL;
2578 2578
2579 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2579 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2580 2580
2581 int modulo = (er.count()/10)+1; 2581 int modulo = (er.count()/10)+1;
2582 int incCounter = 0; 2582 int incCounter = 0;
2583 while ( incCounter < er.count()) { 2583 while ( incCounter < er.count()) {
2584 if (syncManager->isProgressBarCanceled()) 2584 if (syncManager->isProgressBarCanceled())
2585 return false; 2585 return false;
2586 if ( incCounter % modulo == 0 ) 2586 if ( incCounter % modulo == 0 )
2587 syncManager->showProgressBar(incCounter); 2587 syncManager->showProgressBar(incCounter);
2588 2588
2589 uid = er[ incCounter ]; 2589 uid = er[ incCounter ];
2590 bool skipIncidence = false; 2590 bool skipIncidence = false;
2591 if ( uid.left(19) == QString("last-syncAddressee-") ) 2591 if ( uid.left(19) == QString("last-syncAddressee-") )
2592 skipIncidence = true; 2592 skipIncidence = true;
2593 QString idS,OidS; 2593 QString idS,OidS;
2594 qApp->processEvents(); 2594 qApp->processEvents();
2595 if ( !skipIncidence ) { 2595 if ( !skipIncidence ) {
2596 inL = local->findByUid( uid ); 2596 inL = local->findByUid( uid );
2597 inR = remote->findByUid( uid ); 2597 inR = remote->findByUid( uid );
2598 //inL.setResource( 0 ); 2598 //inL.setResource( 0 );
2599 //inR.setResource( 0 ); 2599 //inR.setResource( 0 );
2600 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2600 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2601 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2601 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2602 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2602 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2603 //qDebug("take %d %s ", take, inL.summary().latin1()); 2603 //qDebug("take %d %s ", take, inL.summary().latin1());
2604 if ( take == 3 ) 2604 if ( take == 3 )
2605 return false; 2605 return false;
2606 if ( take == 1 ) {// take local 2606 if ( take == 1 ) {// take local
2607 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2607 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2608 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2608 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2609 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2609 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2610 local->insertAddressee( inL, false ); 2610 local->insertAddressee( inL, false );
2611 idS = inR.externalUID(); 2611 idS = inR.externalUID();
2612 OidS = inR.originalExternalUID(); 2612 OidS = inR.originalExternalUID();
2613 } 2613 }
2614 else 2614 else
2615 idS = inR.IDStr(); 2615 idS = inR.IDStr();
2616 remote->removeAddressee( inR ); 2616 remote->removeAddressee( inR );
2617 inR = inL; 2617 inR = inL;
2618 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2618 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2619 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2619 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2620 inR.setOriginalExternalUID( OidS ); 2620 inR.setOriginalExternalUID( OidS );
2621 inR.setExternalUID( idS ); 2621 inR.setExternalUID( idS );
2622 if ( syncManager->syncWithDesktop() ) 2622 if ( syncManager->syncWithDesktop() )
2623 inR.setIDStr( "changed" ); 2623 inR.setIDStr("changed" );
2624 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" );
2624 } else { 2625 } else {
2625 inR.setIDStr( idS ); 2626 inR.setIDStr( idS );
2626 } 2627 }
2627 inR.setResource( 0 ); 2628 inR.setResource( 0 );
2628 remote->insertAddressee( inR , false); 2629 remote->insertAddressee( inR , false);
2629 ++changedRemote; 2630 ++changedRemote;
2630 } else { // take == 2 take remote 2631 } else { // take == 2 take remote
2631 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2632 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2632 if ( inR.revision().date().year() < 2004 ) 2633 if ( inR.revision().date().year() < 2004 )
2633 inR.setRevision( modifiedCalendar ); 2634 inR.setRevision( modifiedCalendar );
2634 } 2635 }
2635 idS = inL.IDStr(); 2636 idS = inL.IDStr();
2636 local->removeAddressee( inL ); 2637 local->removeAddressee( inL );
2637 inL = inR; 2638 inL = inR;
2638 inL.setIDStr( idS ); 2639 inL.setIDStr( idS );
2639 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2640 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2640 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2641 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2641 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2642 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2642 } 2643 }
2643 inL.setResource( 0 ); 2644 inL.setResource( 0 );
2644 local->insertAddressee( inL , false ); 2645 local->insertAddressee( inL , false );
2645 ++changedLocal; 2646 ++changedLocal;
2646 } 2647 }
2647 } 2648 }
2648 } 2649 }
2649 } else { // no conflict 2650 } else { // no conflict
2650 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2651 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2651 QString des = addresseeLSync.note(); 2652 QString des = addresseeLSync.note();
2652 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2653 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2653 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2654 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2654 remote->insertAddressee( inR, false ); 2655 remote->insertAddressee( inR, false );
2655 ++deletedAddresseeR; 2656 ++deletedAddresseeR;
2656 } else { 2657 } else {
2657 inR.setRevision( modifiedCalendar ); 2658 inR.setRevision( modifiedCalendar );
2658 remote->insertAddressee( inR, false ); 2659 remote->insertAddressee( inR, false );
2659 inL = inR; 2660 inL = inR;
2660 inL.setResource( 0 ); 2661 inL.setResource( 0 );
2661 local->insertAddressee( inL , false); 2662 local->insertAddressee( inL , false);
2662 ++addedAddressee; 2663 ++addedAddressee;
2663 } 2664 }
2664 } else { 2665 } else {
2665 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2666 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2666 inR.setRevision( modifiedCalendar ); 2667 inR.setRevision( modifiedCalendar );
2667 remote->insertAddressee( inR, false ); 2668 remote->insertAddressee( inR, false );
2668 inR.setResource( 0 ); 2669 inR.setResource( 0 );
2669 local->insertAddressee( inR, false ); 2670 local->insertAddressee( inR, false );
2670 ++addedAddressee; 2671 ++addedAddressee;
2671 } else { 2672 } else {
2672 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2673 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2673 remote->removeAddressee( inR ); 2674 remote->removeAddressee( inR );
2674 ++deletedAddresseeR; 2675 ++deletedAddresseeR;
2675 } 2676 }
2676 } 2677 }
2677 } 2678 }
2678 } 2679 }
2679 ++incCounter; 2680 ++incCounter;
2680 } 2681 }
2681 er.clear(); 2682 er.clear();
2682 QStringList el = local->uidList(); 2683 QStringList el = local->uidList();
2683 modulo = (el.count()/10)+1; 2684 modulo = (el.count()/10)+1;
2684 2685
2685 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2686 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2686 incCounter = 0; 2687 incCounter = 0;
2687 while ( incCounter < el.count()) { 2688 while ( incCounter < el.count()) {
2688 qApp->processEvents(); 2689 qApp->processEvents();
2689 if (syncManager->isProgressBarCanceled()) 2690 if (syncManager->isProgressBarCanceled())
2690 return false; 2691 return false;
2691 if ( incCounter % modulo == 0 ) 2692 if ( incCounter % modulo == 0 )
2692 syncManager->showProgressBar(incCounter); 2693 syncManager->showProgressBar(incCounter);
2693 uid = el[ incCounter ]; 2694 uid = el[ incCounter ];
2694 bool skipIncidence = false; 2695 bool skipIncidence = false;
2695 if ( uid.left(19) == QString("last-syncAddressee-") ) 2696 if ( uid.left(19) == QString("last-syncAddressee-") )
2696 skipIncidence = true; 2697 skipIncidence = true;
2697 if ( !skipIncidence ) { 2698 if ( !skipIncidence ) {
2698 inL = local->findByUid( uid ); 2699 inL = local->findByUid( uid );
2699 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2700 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2700 inR = remote->findByUid( uid ); 2701 inR = remote->findByUid( uid );
2701 if ( inR.isEmpty() ) { 2702 if ( inR.isEmpty() ) {
2702 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2703 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2703 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2704 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2704 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2705 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2705 local->removeAddressee( inL ); 2706 local->removeAddressee( inL );
2706 ++deletedAddresseeL; 2707 ++deletedAddresseeL;
2707 } else { 2708 } else {
2708 if ( ! syncManager->mWriteBackExistingOnly ) { 2709 if ( ! syncManager->mWriteBackExistingOnly ) {
2709 inL.removeID(mCurrentSyncDevice ); 2710 inL.removeID(mCurrentSyncDevice );
2710 ++addedAddresseeR; 2711 ++addedAddresseeR;
2711 inL.setRevision( modifiedCalendar ); 2712 inL.setRevision( modifiedCalendar );
2712 local->insertAddressee( inL, false ); 2713 local->insertAddressee( inL, false );
2713 inR = inL; 2714 inR = inL;
2714 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2715 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2715 inR.setResource( 0 ); 2716 inR.setResource( 0 );
2716 remote->insertAddressee( inR, false ); 2717 remote->insertAddressee( inR, false );
2717 } 2718 }
2718 } 2719 }
2719 } else { 2720 } else {
2720 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2721 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2721 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2722 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2722 local->removeAddressee( inL ); 2723 local->removeAddressee( inL );
2723 ++deletedAddresseeL; 2724 ++deletedAddresseeL;
2724 } else { 2725 } else {
2725 if ( ! syncManager->mWriteBackExistingOnly ) { 2726 if ( ! syncManager->mWriteBackExistingOnly ) {
2726 ++addedAddresseeR; 2727 ++addedAddresseeR;
2727 inL.setRevision( modifiedCalendar ); 2728 inL.setRevision( modifiedCalendar );
2728 local->insertAddressee( inL, false ); 2729 local->insertAddressee( inL, false );
2729 inR = inL; 2730 inR = inL;
2730 inR.setResource( 0 ); 2731 inR.setResource( 0 );
2731 remote->insertAddressee( inR, false ); 2732 remote->insertAddressee( inR, false );
2732 } 2733 }
2733 } 2734 }
2734 } 2735 }
2735 } 2736 }
2736 } 2737 }
2737 } 2738 }
2738 ++incCounter; 2739 ++incCounter;
2739 } 2740 }
2740 el.clear(); 2741 el.clear();
2741 syncManager->hideProgressBar(); 2742 syncManager->hideProgressBar();
2742 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2743 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2743 // get rid of micro seconds 2744 // get rid of micro seconds
2744 QTime t = mLastAddressbookSync.time(); 2745 QTime t = mLastAddressbookSync.time();
2745 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2746 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2746 addresseeLSync.setRevision( mLastAddressbookSync ); 2747 addresseeLSync.setRevision( mLastAddressbookSync );
2747 addresseeRSync.setRevision( mLastAddressbookSync ); 2748 addresseeRSync.setRevision( mLastAddressbookSync );
2748 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2749 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2749 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2750 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2750 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2751 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2751 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2752 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2752 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2753 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2753 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2754 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2754 addresseeRSync.setNote( "" ) ; 2755 addresseeRSync.setNote( "" ) ;
2755 addresseeLSync.setNote( "" ); 2756 addresseeLSync.setNote( "" );
2756 2757
2757 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2758 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2758 remote->insertAddressee( addresseeRSync, false ); 2759 remote->insertAddressee( addresseeRSync, false );
2759 local->insertAddressee( addresseeLSync, false ); 2760 local->insertAddressee( addresseeLSync, false );
2760 QString mes; 2761 QString mes;
2761 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 ); 2762 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 );
2762 if ( syncManager->mShowSyncSummary ) { 2763 if ( syncManager->mShowSyncSummary ) {
2763 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2764 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2764 } 2765 }
2765 qDebug( mes ); 2766 qDebug( mes );
2766 return syncOK; 2767 return syncOK;
2767} 2768}
2768 2769
2769 2770
2770//this is a overwritten callbackmethods from the syncinterface 2771//this is a overwritten callbackmethods from the syncinterface
2771bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2772bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2772{ 2773{
2773 2774
2774 //pending prepare addresseeview for output 2775 //pending prepare addresseeview for output
2775 //pending detect, if remote file has REV field. if not switch to external sync 2776 //pending detect, if remote file has REV field. if not switch to external sync
2776 mGlobalSyncMode = SYNC_MODE_NORMAL; 2777 mGlobalSyncMode = SYNC_MODE_NORMAL;
2777 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2778 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2778 2779
2779 AddressBook abLocal(filename,"syncContact"); 2780 AddressBook abLocal(filename,"syncContact");
2780 bool syncOK = false; 2781 bool syncOK = false;
2781 if ( abLocal.load() ) { 2782 if ( abLocal.load() ) {
2782 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2783 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2783 bool external = false; 2784 bool external = false;
2784 bool isXML = false; 2785 bool isXML = false;
2785 if ( filename.right(4) == ".xml") { 2786 if ( filename.right(4) == ".xml") {
2786 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2787 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2787 isXML = true; 2788 isXML = true;
2788 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2789 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2789 } else { 2790 } else {
2790 external = !manager->mIsKapiFile; 2791 external = !manager->mIsKapiFile;
2791 if ( external ) { 2792 if ( external ) {
2792 qDebug("Setting vcf mode to external "); 2793 qDebug("Setting vcf mode to external ");
2793 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2794 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2794 AddressBook::Iterator it; 2795 AddressBook::Iterator it;
2795 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2796 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2796 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2797 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2797 (*it).computeCsum( mCurrentSyncDevice ); 2798 (*it).computeCsum( mCurrentSyncDevice );
2798 } 2799 }
2799 } 2800 }
2800 } 2801 }
2801 //AddressBook::Iterator it; 2802 //AddressBook::Iterator it;
2802 //QStringList vcards; 2803 //QStringList vcards;
2803 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2804 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2804 // qDebug("Name %s ", (*it).familyName().latin1()); 2805 // qDebug("Name %s ", (*it).familyName().latin1());
2805 //} 2806 //}
2806 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2807 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2807 if ( syncOK ) { 2808 if ( syncOK ) {
2808 if ( syncManager->mWriteBackFile ) 2809 if ( syncManager->mWriteBackFile )
2809 { 2810 {
2810 if ( external ) 2811 if ( external )
2811 abLocal.removeSyncAddressees( !isXML); 2812 abLocal.removeSyncAddressees( !isXML);
2812 qDebug("Saving remote AB "); 2813 qDebug("Saving remote AB ");
2813 if ( ! abLocal.saveAB()) 2814 if ( ! abLocal.saveAB())
2814 qDebug("Error writing back AB to file "); 2815 qDebug("Error writing back AB to file ");
2815 if ( isXML ) { 2816 if ( external ) {
2816 // afterwrite processing 2817 // afterwrite processing
2817 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2818 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML);
2818 } 2819 }
2819 } 2820 }
2820 } 2821 }
2821 setModified(); 2822 setModified();
2822 2823
2823 } 2824 }
2824 if ( syncOK ) 2825 if ( syncOK )
2825 mViewManager->refreshView(); 2826 mViewManager->refreshView();
2826 return syncOK; 2827 return syncOK;
2827 2828
2828} 2829}
2829void KABCore::removeSyncInfo( QString syncProfile) 2830void KABCore::removeSyncInfo( QString syncProfile)
2830{ 2831{
2831 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); 2832 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
2832 mAddressBook->removeSyncInfo( syncProfile ); 2833 mAddressBook->removeSyncInfo( syncProfile );
2834 setModified();
2833} 2835}
2834 2836
2835 2837
2836//this is a overwritten callbackmethods from the syncinterface 2838//this is a overwritten callbackmethods from the syncinterface
2837bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2839bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2838{ 2840{
2839 if ( resource == "phone" ) 2841 if ( resource == "phone" )
2840 return syncPhone(); 2842 return syncPhone();
2841 disableBR( true ); 2843 disableBR( true );
2842 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2844 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2843 2845
2844 AddressBook abLocal( resource,"syncContact"); 2846 AddressBook abLocal( resource,"syncContact");
2845 bool syncOK = false; 2847 bool syncOK = false;
2846 if ( abLocal.load() ) { 2848 if ( abLocal.load() ) {
2847 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2849 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2848 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2850 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2849 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2851 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2850 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2852 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2851 if ( syncOK ) { 2853 if ( syncOK ) {
2852 if ( syncManager->mWriteBackFile ) { 2854 if ( syncManager->mWriteBackFile ) {
2853 abLocal.removeSyncAddressees( false ); 2855 abLocal.removeSyncAddressees( false );
2854 abLocal.saveAB(); 2856 abLocal.saveAB();
2855 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2857 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2856 } 2858 }
2857 } 2859 }
2858 setModified(); 2860 setModified();
2859 } 2861 }
2860 if ( syncOK ) 2862 if ( syncOK )
2861 mViewManager->refreshView(); 2863 mViewManager->refreshView();
2862 disableBR( false ); 2864 disableBR( false );
2863 return syncOK; 2865 return syncOK;
2864 2866
2865} 2867}
2866void KABCore::message( QString m ) 2868void KABCore::message( QString m )
2867{ 2869{
2868 topLevelWidget()->setCaption( m ); 2870 topLevelWidget()->setCaption( m );
2869 mMessageTimer->start( 15000, true ); 2871 mMessageTimer->start( 15000, true );
2870} 2872}
2871bool KABCore::syncPhone() 2873bool KABCore::syncPhone()
2872{ 2874{
2873 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2875 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2874 QString fileName = getPhoneFile(); 2876 QString fileName = getPhoneFile();
2875 if ( !PhoneAccess::readFromPhone( fileName) ) { 2877 if ( !PhoneAccess::readFromPhone( fileName) ) {
2876 message(i18n("Phone access failed!")); 2878 message(i18n("Phone access failed!"));
2877 return false; 2879 return false;
2878 } 2880 }
2879 AddressBook abLocal( fileName,"syncContact"); 2881 AddressBook abLocal( fileName,"syncContact");
2880 bool syncOK = false; 2882 bool syncOK = false;
2881 { 2883 {
2882 abLocal.importFromFile( fileName ); 2884 abLocal.importFromFile( fileName );
2883 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2885 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2884 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2886 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2885 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2887 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2886 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2887 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2889 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2888 if ( syncOK ) { 2890 if ( syncOK ) {
2889 if ( syncManager->mWriteBackFile ) { 2891 if ( syncManager->mWriteBackFile ) {
2890 abLocal.removeSyncAddressees( true ); 2892 abLocal.removeSyncAddressees( true );
2891 abLocal.saveABphone( fileName ); 2893 abLocal.saveABphone( fileName );
2892 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2894 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2893 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2895 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2894 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2896 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2895 } 2897 }
2896 } 2898 }
2897 setModified(); 2899 setModified();
2898 } 2900 }
2899 if ( syncOK ) 2901 if ( syncOK )
2900 mViewManager->refreshView(); 2902 mViewManager->refreshView();
2901 return syncOK; 2903 return syncOK;
2902} 2904}
2903void KABCore::getFile( bool success ) 2905void KABCore::getFile( bool success )
2904{ 2906{
2905 if ( ! success ) { 2907 if ( ! success ) {
2906 message( i18n("Error receiving file. Nothing changed!") ); 2908 message( i18n("Error receiving file. Nothing changed!") );
2907 return; 2909 return;
2908 } 2910 }
2909 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2911 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2910 if ( count ) 2912 if ( count )
2911 setModified( true ); 2913 setModified( true );
2912 message( i18n("Pi-Sync successful!") ); 2914 message( i18n("Pi-Sync successful!") );
2913 mViewManager->refreshView(); 2915 mViewManager->refreshView();
2914} 2916}
2915void KABCore::syncFileRequest() 2917void KABCore::syncFileRequest()
2916{ 2918{
2917 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { 2919 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) {
2918 syncManager->slotSyncMenu( 999 ); 2920 syncManager->slotSyncMenu( 999 );
2919 } 2921 }
2920 mAddressBook->export2File( sentSyncFile() ); 2922 mAddressBook->export2File( sentSyncFile() );
2921} 2923}
2922QString KABCore::sentSyncFile() 2924QString KABCore::sentSyncFile()
2923{ 2925{
2924#ifdef DESKTOP_VERSION 2926#ifdef DESKTOP_VERSION
2925 return locateLocal( "tmp", "copysyncab.vcf" ); 2927 return locateLocal( "tmp", "copysyncab.vcf" );
2926#else 2928#else
2927 return QString( "/tmp/copysyncab.vcf" ); 2929 return QString( "/tmp/copysyncab.vcf" );
2928#endif 2930#endif
2929} 2931}
2930 2932
2931void KABCore::setCaptionBack() 2933void KABCore::setCaptionBack()
2932{ 2934{
2933 mMessageTimer->stop(); 2935 mMessageTimer->stop();
2934 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2936 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2935} 2937}