summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-18 14:22:10 (UTC)
committer zautrix <zautrix>2004-09-18 14:22:10 (UTC)
commitca8fcf3fd4dc068747d8f31e2189145b22853d55 (patch) (unidiff)
tree29417ffd55d1c4186922a64ed0cdf1c6a1cc69a3
parentbb16660f29fc709791aa0ee4cb63a40710a994a8 (diff)
downloadkdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.zip
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.gz
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.bz2
more AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp15
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kaddressbook/kabcore.cpp206
3 files changed, 105 insertions, 119 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 9332e21..6e8d027 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,770 +1,777 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41 41
42#include <kglobal.h> 42#include <kglobal.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kdebug.h> 44#include <kdebug.h>
45#include <libkcal/syncdefines.h> 45#include <libkcal/syncdefines.h>
46#include "addressbook.h" 46#include "addressbook.h"
47#include "resource.h" 47#include "resource.h"
48 48
49//US #include "addressbook.moc" 49//US #include "addressbook.moc"
50 50
51using namespace KABC; 51using namespace KABC;
52 52
53struct AddressBook::AddressBookData 53struct AddressBook::AddressBookData
54{ 54{
55 Addressee::List mAddressees; 55 Addressee::List mAddressees;
56 Addressee::List mRemovedAddressees; 56 Addressee::List mRemovedAddressees;
57 Field::List mAllFields; 57 Field::List mAllFields;
58 KConfig *mConfig; 58 KConfig *mConfig;
59 KRES::Manager<Resource> *mManager; 59 KRES::Manager<Resource> *mManager;
60//US ErrorHandler *mErrorHandler; 60//US ErrorHandler *mErrorHandler;
61}; 61};
62 62
63struct AddressBook::Iterator::IteratorData 63struct AddressBook::Iterator::IteratorData
64{ 64{
65 Addressee::List::Iterator mIt; 65 Addressee::List::Iterator mIt;
66}; 66};
67 67
68struct AddressBook::ConstIterator::ConstIteratorData 68struct AddressBook::ConstIterator::ConstIteratorData
69{ 69{
70 Addressee::List::ConstIterator mIt; 70 Addressee::List::ConstIterator mIt;
71}; 71};
72 72
73AddressBook::Iterator::Iterator() 73AddressBook::Iterator::Iterator()
74{ 74{
75 d = new IteratorData; 75 d = new IteratorData;
76} 76}
77 77
78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
79{ 79{
80 d = new IteratorData; 80 d = new IteratorData;
81 d->mIt = i.d->mIt; 81 d->mIt = i.d->mIt;
82} 82}
83 83
84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
85{ 85{
86 if( this == &i ) return *this; // guard against self assignment 86 if( this == &i ) return *this; // guard against self assignment
87 delete d; // delete the old data the Iterator was completely constructed before 87 delete d; // delete the old data the Iterator was completely constructed before
88 d = new IteratorData; 88 d = new IteratorData;
89 d->mIt = i.d->mIt; 89 d->mIt = i.d->mIt;
90 return *this; 90 return *this;
91} 91}
92 92
93AddressBook::Iterator::~Iterator() 93AddressBook::Iterator::~Iterator()
94{ 94{
95 delete d; 95 delete d;
96} 96}
97 97
98const Addressee &AddressBook::Iterator::operator*() const 98const Addressee &AddressBook::Iterator::operator*() const
99{ 99{
100 return *(d->mIt); 100 return *(d->mIt);
101} 101}
102 102
103Addressee &AddressBook::Iterator::operator*() 103Addressee &AddressBook::Iterator::operator*()
104{ 104{
105 return *(d->mIt); 105 return *(d->mIt);
106} 106}
107 107
108Addressee *AddressBook::Iterator::operator->() 108Addressee *AddressBook::Iterator::operator->()
109{ 109{
110 return &(*(d->mIt)); 110 return &(*(d->mIt));
111} 111}
112 112
113AddressBook::Iterator &AddressBook::Iterator::operator++() 113AddressBook::Iterator &AddressBook::Iterator::operator++()
114{ 114{
115 (d->mIt)++; 115 (d->mIt)++;
116 return *this; 116 return *this;
117} 117}
118 118
119AddressBook::Iterator &AddressBook::Iterator::operator++(int) 119AddressBook::Iterator &AddressBook::Iterator::operator++(int)
120{ 120{
121 (d->mIt)++; 121 (d->mIt)++;
122 return *this; 122 return *this;
123} 123}
124 124
125AddressBook::Iterator &AddressBook::Iterator::operator--() 125AddressBook::Iterator &AddressBook::Iterator::operator--()
126{ 126{
127 (d->mIt)--; 127 (d->mIt)--;
128 return *this; 128 return *this;
129} 129}
130 130
131AddressBook::Iterator &AddressBook::Iterator::operator--(int) 131AddressBook::Iterator &AddressBook::Iterator::operator--(int)
132{ 132{
133 (d->mIt)--; 133 (d->mIt)--;
134 return *this; 134 return *this;
135} 135}
136 136
137bool AddressBook::Iterator::operator==( const Iterator &it ) 137bool AddressBook::Iterator::operator==( const Iterator &it )
138{ 138{
139 return ( d->mIt == it.d->mIt ); 139 return ( d->mIt == it.d->mIt );
140} 140}
141 141
142bool AddressBook::Iterator::operator!=( const Iterator &it ) 142bool AddressBook::Iterator::operator!=( const Iterator &it )
143{ 143{
144 return ( d->mIt != it.d->mIt ); 144 return ( d->mIt != it.d->mIt );
145} 145}
146 146
147 147
148AddressBook::ConstIterator::ConstIterator() 148AddressBook::ConstIterator::ConstIterator()
149{ 149{
150 d = new ConstIteratorData; 150 d = new ConstIteratorData;
151} 151}
152 152
153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
154{ 154{
155 d = new ConstIteratorData; 155 d = new ConstIteratorData;
156 d->mIt = i.d->mIt; 156 d->mIt = i.d->mIt;
157} 157}
158 158
159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
160{ 160{
161 if( this == &i ) return *this; // guard for self assignment 161 if( this == &i ) return *this; // guard for self assignment
162 delete d; // delete the old data because the Iterator was really constructed before 162 delete d; // delete the old data because the Iterator was really constructed before
163 d = new ConstIteratorData; 163 d = new ConstIteratorData;
164 d->mIt = i.d->mIt; 164 d->mIt = i.d->mIt;
165 return *this; 165 return *this;
166} 166}
167 167
168AddressBook::ConstIterator::~ConstIterator() 168AddressBook::ConstIterator::~ConstIterator()
169{ 169{
170 delete d; 170 delete d;
171} 171}
172 172
173const Addressee &AddressBook::ConstIterator::operator*() const 173const Addressee &AddressBook::ConstIterator::operator*() const
174{ 174{
175 return *(d->mIt); 175 return *(d->mIt);
176} 176}
177 177
178const Addressee* AddressBook::ConstIterator::operator->() const 178const Addressee* AddressBook::ConstIterator::operator->() const
179{ 179{
180 return &(*(d->mIt)); 180 return &(*(d->mIt));
181} 181}
182 182
183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
184{ 184{
185 (d->mIt)++; 185 (d->mIt)++;
186 return *this; 186 return *this;
187} 187}
188 188
189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
190{ 190{
191 (d->mIt)++; 191 (d->mIt)++;
192 return *this; 192 return *this;
193} 193}
194 194
195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
196{ 196{
197 (d->mIt)--; 197 (d->mIt)--;
198 return *this; 198 return *this;
199} 199}
200 200
201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
202{ 202{
203 (d->mIt)--; 203 (d->mIt)--;
204 return *this; 204 return *this;
205} 205}
206 206
207bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 207bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
208{ 208{
209 return ( d->mIt == it.d->mIt ); 209 return ( d->mIt == it.d->mIt );
210} 210}
211 211
212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
213{ 213{
214 return ( d->mIt != it.d->mIt ); 214 return ( d->mIt != it.d->mIt );
215} 215}
216 216
217 217
218AddressBook::AddressBook() 218AddressBook::AddressBook()
219{ 219{
220 init(0, "contact"); 220 init(0, "contact");
221} 221}
222 222
223AddressBook::AddressBook( const QString &config ) 223AddressBook::AddressBook( const QString &config )
224{ 224{
225 init(config, "contact"); 225 init(config, "contact");
226} 226}
227 227
228AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
229{ 229{
230 init(config, family); 230 init(config, family);
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 d = new AddressBookData; 237 d = new AddressBookData;
238 QString fami = family; 238 QString fami = family;
239 qDebug("new ab "); 239 qDebug("new ab ");
240 if (config != 0) { 240 if (config != 0) {
241 qDebug("config != 0 "); 241 qDebug("config != 0 ");
242 if ( family == "syncContact" ) { 242 if ( family == "syncContact" ) {
243 qDebug("creating sync config "); 243 qDebug("creating sync config ");
244 fami = "contact"; 244 fami = "contact";
245 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 245 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
246 con->setGroup( "General" ); 246 con->setGroup( "General" );
247 con->writeEntry( "ResourceKeys", QString("sync") ); 247 con->writeEntry( "ResourceKeys", QString("sync") );
248 con->writeEntry( "Standard", QString("sync") ); 248 con->writeEntry( "Standard", QString("sync") );
249 con->setGroup( "Resource_sync" ); 249 con->setGroup( "Resource_sync" );
250 con->writeEntry( "FileFormat", QString("vcard") ); 250 con->writeEntry( "FileFormat", QString("vcard") );
251 con->writeEntry( "FileName", config ); 251 con->writeEntry( "FileName", config );
252 con->writeEntry( "ResourceIdentifier", QString("sync") ); 252 con->writeEntry( "ResourceIdentifier", QString("sync") );
253 con->writeEntry( "ResourceName", QString("sync_res") ); 253 con->writeEntry( "ResourceName", QString("sync_res") );
254 con->writeEntry( "ResourceType", QString("file") ); 254 con->writeEntry( "ResourceType", QString("file") );
255 //con->sync(); 255 //con->sync();
256 d->mConfig = con; 256 d->mConfig = con;
257 } 257 }
258 else 258 else
259 d->mConfig = new KConfig( locateLocal("config", config) ); 259 d->mConfig = new KConfig( locateLocal("config", config) );
260// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 260// qDebug("AddressBook::init 1 config=%s",config.latin1() );
261 } 261 }
262 else { 262 else {
263 d->mConfig = 0; 263 d->mConfig = 0;
264// qDebug("AddressBook::init 1 config=0"); 264// qDebug("AddressBook::init 1 config=0");
265 } 265 }
266 266
267//US d->mErrorHandler = 0; 267//US d->mErrorHandler = 0;
268 d->mManager = new KRES::Manager<Resource>( fami, false ); 268 d->mManager = new KRES::Manager<Resource>( fami, false );
269 d->mManager->readConfig( d->mConfig ); 269 d->mManager->readConfig( d->mConfig );
270 if ( family == "syncContact" ) { 270 if ( family == "syncContact" ) {
271 KRES::Manager<Resource> *manager = d->mManager; 271 KRES::Manager<Resource> *manager = d->mManager;
272 KRES::Manager<Resource>::ActiveIterator it; 272 KRES::Manager<Resource>::ActiveIterator it;
273 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 273 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
274 (*it)->setAddressBook( this ); 274 (*it)->setAddressBook( this );
275 if ( !(*it)->open() ) 275 if ( !(*it)->open() )
276 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 276 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
277 } 277 }
278 Resource *res = standardResource(); 278 Resource *res = standardResource();
279 if ( !res ) { 279 if ( !res ) {
280 qDebug("ERROR: no standard resource"); 280 qDebug("ERROR: no standard resource");
281 res = manager->createResource( "file" ); 281 res = manager->createResource( "file" );
282 if ( res ) 282 if ( res )
283 { 283 {
284 addResource( res ); 284 addResource( res );
285 } 285 }
286 else 286 else
287 qDebug(" No resource available!!!"); 287 qDebug(" No resource available!!!");
288 } 288 }
289 setStandardResource( res ); 289 setStandardResource( res );
290 manager->writeConfig(); 290 manager->writeConfig();
291 } 291 }
292 addCustomField( i18n( "Department" ), KABC::Field::Organization, 292 addCustomField( i18n( "Department" ), KABC::Field::Organization,
293 "X-Department", "KADDRESSBOOK" ); 293 "X-Department", "KADDRESSBOOK" );
294 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 294 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
295 "X-Profession", "KADDRESSBOOK" ); 295 "X-Profession", "KADDRESSBOOK" );
296 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 296 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
297 "X-AssistantsName", "KADDRESSBOOK" ); 297 "X-AssistantsName", "KADDRESSBOOK" );
298 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 298 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
299 "X-ManagersName", "KADDRESSBOOK" ); 299 "X-ManagersName", "KADDRESSBOOK" );
300 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 300 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
301 "X-SpousesName", "KADDRESSBOOK" ); 301 "X-SpousesName", "KADDRESSBOOK" );
302 addCustomField( i18n( "Office" ), KABC::Field::Personal, 302 addCustomField( i18n( "Office" ), KABC::Field::Personal,
303 "X-Office", "KADDRESSBOOK" ); 303 "X-Office", "KADDRESSBOOK" );
304 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 304 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
305 "X-IMAddress", "KADDRESSBOOK" ); 305 "X-IMAddress", "KADDRESSBOOK" );
306 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 306 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
307 "X-Anniversary", "KADDRESSBOOK" ); 307 "X-Anniversary", "KADDRESSBOOK" );
308 308
309 //US added this field to become compatible with Opie/qtopia addressbook 309 //US added this field to become compatible with Opie/qtopia addressbook
310 // values can be "female" or "male" or "". An empty field represents undefined. 310 // values can be "female" or "male" or "". An empty field represents undefined.
311 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 311 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
312 "X-Gender", "KADDRESSBOOK" ); 312 "X-Gender", "KADDRESSBOOK" );
313 addCustomField( i18n( "Children" ), KABC::Field::Personal, 313 addCustomField( i18n( "Children" ), KABC::Field::Personal,
314 "X-Children", "KADDRESSBOOK" ); 314 "X-Children", "KADDRESSBOOK" );
315 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 315 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
316 "X-FreeBusyUrl", "KADDRESSBOOK" ); 316 "X-FreeBusyUrl", "KADDRESSBOOK" );
317 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 317 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
318 "X-ExternalID", "KADDRESSBOOK" ); 318 "X-ExternalID", "KADDRESSBOOK" );
319} 319}
320 320
321AddressBook::~AddressBook() 321AddressBook::~AddressBook()
322{ 322{
323 delete d->mConfig; d->mConfig = 0; 323 delete d->mConfig; d->mConfig = 0;
324 delete d->mManager; d->mManager = 0; 324 delete d->mManager; d->mManager = 0;
325//US delete d->mErrorHandler; d->mErrorHandler = 0; 325//US delete d->mErrorHandler; d->mErrorHandler = 0;
326 delete d; d = 0; 326 delete d; d = 0;
327} 327}
328 328
329bool AddressBook::load() 329bool AddressBook::load()
330{ 330{
331 331
332 332
333 clear(); 333 clear();
334 334
335 KRES::Manager<Resource>::ActiveIterator it; 335 KRES::Manager<Resource>::ActiveIterator it;
336 bool ok = true; 336 bool ok = true;
337 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 337 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
338 if ( !(*it)->load() ) { 338 if ( !(*it)->load() ) {
339 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 339 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
340 ok = false; 340 ok = false;
341 } 341 }
342 342
343 // mark all addressees as unchanged 343 // mark all addressees as unchanged
344 Addressee::List::Iterator addrIt; 344 Addressee::List::Iterator addrIt;
345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 345 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
346 (*addrIt).setChanged( false ); 346 (*addrIt).setChanged( false );
347 347
348 return ok; 348 return ok;
349} 349}
350 350
351bool AddressBook::save( Ticket *ticket ) 351bool AddressBook::save( Ticket *ticket )
352{ 352{
353 kdDebug(5700) << "AddressBook::save()"<< endl; 353 kdDebug(5700) << "AddressBook::save()"<< endl;
354 354
355 if ( ticket->resource() ) { 355 if ( ticket->resource() ) {
356 deleteRemovedAddressees(); 356 deleteRemovedAddressees();
357 return ticket->resource()->save( ticket ); 357 return ticket->resource()->save( ticket );
358 } 358 }
359 359
360 return false; 360 return false;
361} 361}
362bool AddressBook::saveAB() 362bool AddressBook::saveAB()
363{ 363{
364 bool ok = true; 364 bool ok = true;
365 365
366 deleteRemovedAddressees(); 366 deleteRemovedAddressees();
367 367
368 KRES::Manager<Resource>::ActiveIterator it; 368 KRES::Manager<Resource>::ActiveIterator it;
369 KRES::Manager<Resource> *manager = d->mManager; 369 KRES::Manager<Resource> *manager = d->mManager;
370 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 370 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
371 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 371 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
372 Ticket *ticket = requestSaveTicket( *it ); 372 Ticket *ticket = requestSaveTicket( *it );
373// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 373// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
374 if ( !ticket ) { 374 if ( !ticket ) {
375 error( i18n( "Unable to save to resource '%1'. It is locked." ) 375 error( i18n( "Unable to save to resource '%1'. It is locked." )
376 .arg( (*it)->resourceName() ) ); 376 .arg( (*it)->resourceName() ) );
377 return false; 377 return false;
378 } 378 }
379 379
380 //if ( !save( ticket ) ) 380 //if ( !save( ticket ) )
381 if ( ticket->resource() ) { 381 if ( ticket->resource() ) {
382 if ( ! ticket->resource()->save( ticket ) ) 382 if ( ! ticket->resource()->save( ticket ) )
383 ok = false; 383 ok = false;
384 } else 384 } else
385 ok = false; 385 ok = false;
386 386
387 } 387 }
388 } 388 }
389 return ok; 389 return ok;
390} 390}
391 391
392AddressBook::Iterator AddressBook::begin() 392AddressBook::Iterator AddressBook::begin()
393{ 393{
394 Iterator it = Iterator(); 394 Iterator it = Iterator();
395 it.d->mIt = d->mAddressees.begin(); 395 it.d->mIt = d->mAddressees.begin();
396 return it; 396 return it;
397} 397}
398 398
399AddressBook::ConstIterator AddressBook::begin() const 399AddressBook::ConstIterator AddressBook::begin() const
400{ 400{
401 ConstIterator it = ConstIterator(); 401 ConstIterator it = ConstIterator();
402 it.d->mIt = d->mAddressees.begin(); 402 it.d->mIt = d->mAddressees.begin();
403 return it; 403 return it;
404} 404}
405 405
406AddressBook::Iterator AddressBook::end() 406AddressBook::Iterator AddressBook::end()
407{ 407{
408 Iterator it = Iterator(); 408 Iterator it = Iterator();
409 it.d->mIt = d->mAddressees.end(); 409 it.d->mIt = d->mAddressees.end();
410 return it; 410 return it;
411} 411}
412 412
413AddressBook::ConstIterator AddressBook::end() const 413AddressBook::ConstIterator AddressBook::end() const
414{ 414{
415 ConstIterator it = ConstIterator(); 415 ConstIterator it = ConstIterator();
416 it.d->mIt = d->mAddressees.end(); 416 it.d->mIt = d->mAddressees.end();
417 return it; 417 return it;
418} 418}
419 419
420void AddressBook::clear() 420void AddressBook::clear()
421{ 421{
422 d->mAddressees.clear(); 422 d->mAddressees.clear();
423} 423}
424 424
425Ticket *AddressBook::requestSaveTicket( Resource *resource ) 425Ticket *AddressBook::requestSaveTicket( Resource *resource )
426{ 426{
427 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 427 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
428 428
429 if ( !resource ) 429 if ( !resource )
430 { 430 {
431 qDebug("AddressBook::requestSaveTicket no resource" ); 431 qDebug("AddressBook::requestSaveTicket no resource" );
432 resource = standardResource(); 432 resource = standardResource();
433 } 433 }
434 434
435 KRES::Manager<Resource>::ActiveIterator it; 435 KRES::Manager<Resource>::ActiveIterator it;
436 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 436 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
437 if ( (*it) == resource ) { 437 if ( (*it) == resource ) {
438 if ( (*it)->readOnly() || !(*it)->isOpen() ) 438 if ( (*it)->readOnly() || !(*it)->isOpen() )
439 return 0; 439 return 0;
440 else 440 else
441 return (*it)->requestSaveTicket(); 441 return (*it)->requestSaveTicket();
442 } 442 }
443 } 443 }
444 444
445 return 0; 445 return 0;
446} 446}
447 447
448void AddressBook::insertAddressee( const Addressee &a ) 448void AddressBook::insertAddressee( const Addressee &a )
449{ 449{
450 Addressee::List::Iterator it; 450 Addressee::List::Iterator it;
451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
452 if ( a.uid() == (*it).uid() ) { 452 if ( a.uid() == (*it).uid() ) {
453 bool changed = false; 453 bool changed = false;
454 Addressee addr = a; 454 Addressee addr = a;
455 if ( addr != (*it) ) 455 if ( addr != (*it) )
456 changed = true; 456 changed = true;
457 457
458 (*it) = a; 458 (*it) = a;
459 if ( (*it).resource() == 0 ) 459 if ( (*it).resource() == 0 )
460 (*it).setResource( standardResource() ); 460 (*it).setResource( standardResource() );
461 461
462 if ( changed ) { 462 if ( changed ) {
463 (*it).setRevision( QDateTime::currentDateTime() ); 463 (*it).setRevision( QDateTime::currentDateTime() );
464 (*it).setChanged( true ); 464 (*it).setChanged( true );
465 } 465 }
466 466
467 return; 467 return;
468 } 468 }
469 } 469 }
470 d->mAddressees.append( a ); 470 d->mAddressees.append( a );
471 Addressee& addr = d->mAddressees.last(); 471 Addressee& addr = d->mAddressees.last();
472 if ( addr.resource() == 0 ) 472 if ( addr.resource() == 0 )
473 addr.setResource( standardResource() ); 473 addr.setResource( standardResource() );
474 474
475 addr.setChanged( true ); 475 addr.setChanged( true );
476} 476}
477 477
478void AddressBook::removeAddressee( const Addressee &a ) 478void AddressBook::removeAddressee( const Addressee &a )
479{ 479{
480 Iterator it; 480 Iterator it;
481 for ( it = begin(); it != end(); ++it ) { 481 for ( it = begin(); it != end(); ++it ) {
482 if ( a.uid() == (*it).uid() ) { 482 if ( a.uid() == (*it).uid() ) {
483 removeAddressee( it ); 483 removeAddressee( it );
484 return; 484 return;
485 } 485 }
486 } 486 }
487} 487}
488 488
489void AddressBook::removeAddressee( const Iterator &it ) 489void AddressBook::removeAddressee( const Iterator &it )
490{ 490{
491 d->mRemovedAddressees.append( (*it) ); 491 d->mRemovedAddressees.append( (*it) );
492 d->mAddressees.remove( it.d->mIt ); 492 d->mAddressees.remove( it.d->mIt );
493} 493}
494 494
495AddressBook::Iterator AddressBook::find( const Addressee &a ) 495AddressBook::Iterator AddressBook::find( const Addressee &a )
496{ 496{
497 Iterator it; 497 Iterator it;
498 for ( it = begin(); it != end(); ++it ) { 498 for ( it = begin(); it != end(); ++it ) {
499 if ( a.uid() == (*it).uid() ) { 499 if ( a.uid() == (*it).uid() ) {
500 return it; 500 return it;
501 } 501 }
502 } 502 }
503 return end(); 503 return end();
504} 504}
505 505
506Addressee AddressBook::findByUid( const QString &uid ) 506Addressee AddressBook::findByUid( const QString &uid )
507{ 507{
508 Iterator it; 508 Iterator it;
509 for ( it = begin(); it != end(); ++it ) { 509 for ( it = begin(); it != end(); ++it ) {
510 if ( uid == (*it).uid() ) { 510 if ( uid == (*it).uid() ) {
511 return *it; 511 return *it;
512 } 512 }
513 } 513 }
514 return Addressee(); 514 return Addressee();
515} 515}
516Addressee::List AddressBook::getExternLastSyncAddressees() 516Addressee::List AddressBook::getExternLastSyncAddressees()
517{ 517{
518 Addressee::List results; 518 Addressee::List results;
519 519
520 Iterator it; 520 Iterator it;
521 for ( it = begin(); it != end(); ++it ) { 521 for ( it = begin(); it != end(); ++it ) {
522 if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) { 522 if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) {
523 if ( (*it).familyName().left(3) == "E: " ) 523 if ( (*it).familyName().left(3) == "E: " )
524 results.append( *it ); 524 results.append( *it );
525 } 525 }
526 } 526 }
527 527
528 return results; 528 return results;
529} 529}
530void AddressBook::resetTempSyncStat() 530void AddressBook::resetTempSyncStat()
531{ 531{
532 532 Iterator it;
533
534 Iterator it;
535 for ( it = begin(); it != end(); ++it ) { 533 for ( it = begin(); it != end(); ++it ) {
536 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 534 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
537 } 535 }
538 536
539} 537}
540 538
539QStringList AddressBook:: uidList()
540{
541 QStringList results;
542 Iterator it;
543 for ( it = begin(); it != end(); ++it ) {
544 results.append( (*it).uid() );
545 }
546 return results;
547}
541 548
542 549
543Addressee::List AddressBook::allAddressees() 550Addressee::List AddressBook::allAddressees()
544{ 551{
545 return d->mAddressees; 552 return d->mAddressees;
546} 553}
547 554
548Addressee::List AddressBook::findByName( const QString &name ) 555Addressee::List AddressBook::findByName( const QString &name )
549{ 556{
550 Addressee::List results; 557 Addressee::List results;
551 558
552 Iterator it; 559 Iterator it;
553 for ( it = begin(); it != end(); ++it ) { 560 for ( it = begin(); it != end(); ++it ) {
554 if ( name == (*it).realName() ) { 561 if ( name == (*it).realName() ) {
555 results.append( *it ); 562 results.append( *it );
556 } 563 }
557 } 564 }
558 565
559 return results; 566 return results;
560} 567}
561 568
562Addressee::List AddressBook::findByEmail( const QString &email ) 569Addressee::List AddressBook::findByEmail( const QString &email )
563{ 570{
564 Addressee::List results; 571 Addressee::List results;
565 QStringList mailList; 572 QStringList mailList;
566 573
567 Iterator it; 574 Iterator it;
568 for ( it = begin(); it != end(); ++it ) { 575 for ( it = begin(); it != end(); ++it ) {
569 mailList = (*it).emails(); 576 mailList = (*it).emails();
570 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 577 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
571 if ( email == (*ite) ) { 578 if ( email == (*ite) ) {
572 results.append( *it ); 579 results.append( *it );
573 } 580 }
574 } 581 }
575 } 582 }
576 583
577 return results; 584 return results;
578} 585}
579 586
580Addressee::List AddressBook::findByCategory( const QString &category ) 587Addressee::List AddressBook::findByCategory( const QString &category )
581{ 588{
582 Addressee::List results; 589 Addressee::List results;
583 590
584 Iterator it; 591 Iterator it;
585 for ( it = begin(); it != end(); ++it ) { 592 for ( it = begin(); it != end(); ++it ) {
586 if ( (*it).hasCategory( category) ) { 593 if ( (*it).hasCategory( category) ) {
587 results.append( *it ); 594 results.append( *it );
588 } 595 }
589 } 596 }
590 597
591 return results; 598 return results;
592} 599}
593 600
594void AddressBook::dump() const 601void AddressBook::dump() const
595{ 602{
596 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 603 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
597 604
598 ConstIterator it; 605 ConstIterator it;
599 for( it = begin(); it != end(); ++it ) { 606 for( it = begin(); it != end(); ++it ) {
600 (*it).dump(); 607 (*it).dump();
601 } 608 }
602 609
603 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 610 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
604} 611}
605 612
606QString AddressBook::identifier() 613QString AddressBook::identifier()
607{ 614{
608 QStringList identifier; 615 QStringList identifier;
609 616
610 617
611 KRES::Manager<Resource>::ActiveIterator it; 618 KRES::Manager<Resource>::ActiveIterator it;
612 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 619 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
613 if ( !(*it)->identifier().isEmpty() ) 620 if ( !(*it)->identifier().isEmpty() )
614 identifier.append( (*it)->identifier() ); 621 identifier.append( (*it)->identifier() );
615 } 622 }
616 623
617 return identifier.join( ":" ); 624 return identifier.join( ":" );
618} 625}
619 626
620Field::List AddressBook::fields( int category ) 627Field::List AddressBook::fields( int category )
621{ 628{
622 if ( d->mAllFields.isEmpty() ) { 629 if ( d->mAllFields.isEmpty() ) {
623 d->mAllFields = Field::allFields(); 630 d->mAllFields = Field::allFields();
624 } 631 }
625 632
626 if ( category == Field::All ) return d->mAllFields; 633 if ( category == Field::All ) return d->mAllFields;
627 634
628 Field::List result; 635 Field::List result;
629 Field::List::ConstIterator it; 636 Field::List::ConstIterator it;
630 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 637 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
631 if ( (*it)->category() & category ) result.append( *it ); 638 if ( (*it)->category() & category ) result.append( *it );
632 } 639 }
633 640
634 return result; 641 return result;
635} 642}
636 643
637bool AddressBook::addCustomField( const QString &label, int category, 644bool AddressBook::addCustomField( const QString &label, int category,
638 const QString &key, const QString &app ) 645 const QString &key, const QString &app )
639{ 646{
640 if ( d->mAllFields.isEmpty() ) { 647 if ( d->mAllFields.isEmpty() ) {
641 d->mAllFields = Field::allFields(); 648 d->mAllFields = Field::allFields();
642 } 649 }
643//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 650//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
644 QString a = app.isNull() ? KGlobal::getAppName() : app; 651 QString a = app.isNull() ? KGlobal::getAppName() : app;
645 652
646 QString k = key.isNull() ? label : key; 653 QString k = key.isNull() ? label : key;
647 654
648 Field *field = Field::createCustomField( label, category, k, a ); 655 Field *field = Field::createCustomField( label, category, k, a );
649 656
650 if ( !field ) return false; 657 if ( !field ) return false;
651 658
652 d->mAllFields.append( field ); 659 d->mAllFields.append( field );
653 660
654 return true; 661 return true;
655} 662}
656 663
657QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 664QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
658{ 665{
659 if (!ab.d) return s; 666 if (!ab.d) return s;
660 667
661 return s << ab.d->mAddressees; 668 return s << ab.d->mAddressees;
662} 669}
663 670
664QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 671QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
665{ 672{
666 if (!ab.d) return s; 673 if (!ab.d) return s;
667 674
668 s >> ab.d->mAddressees; 675 s >> ab.d->mAddressees;
669 676
670 return s; 677 return s;
671} 678}
672 679
673bool AddressBook::addResource( Resource *resource ) 680bool AddressBook::addResource( Resource *resource )
674{ 681{
675 if ( !resource->open() ) { 682 if ( !resource->open() ) {
676 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 683 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
677 return false; 684 return false;
678 } 685 }
679 686
680 resource->setAddressBook( this ); 687 resource->setAddressBook( this );
681 688
682 d->mManager->add( resource ); 689 d->mManager->add( resource );
683 return true; 690 return true;
684} 691}
685 692
686bool AddressBook::removeResource( Resource *resource ) 693bool AddressBook::removeResource( Resource *resource )
687{ 694{
688 resource->close(); 695 resource->close();
689 696
690 if ( resource == standardResource() ) 697 if ( resource == standardResource() )
691 d->mManager->setStandardResource( 0 ); 698 d->mManager->setStandardResource( 0 );
692 699
693 resource->setAddressBook( 0 ); 700 resource->setAddressBook( 0 );
694 701
695 d->mManager->remove( resource ); 702 d->mManager->remove( resource );
696 return true; 703 return true;
697} 704}
698 705
699QPtrList<Resource> AddressBook::resources() 706QPtrList<Resource> AddressBook::resources()
700{ 707{
701 QPtrList<Resource> list; 708 QPtrList<Resource> list;
702 709
703// qDebug("AddressBook::resources() 1"); 710// qDebug("AddressBook::resources() 1");
704 711
705 KRES::Manager<Resource>::ActiveIterator it; 712 KRES::Manager<Resource>::ActiveIterator it;
706 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 713 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
707 list.append( *it ); 714 list.append( *it );
708 715
709 return list; 716 return list;
710} 717}
711 718
712/*US 719/*US
713void AddressBook::setErrorHandler( ErrorHandler *handler ) 720void AddressBook::setErrorHandler( ErrorHandler *handler )
714{ 721{
715 delete d->mErrorHandler; 722 delete d->mErrorHandler;
716 d->mErrorHandler = handler; 723 d->mErrorHandler = handler;
717} 724}
718*/ 725*/
719 726
720void AddressBook::error( const QString& msg ) 727void AddressBook::error( const QString& msg )
721{ 728{
722/*US 729/*US
723 if ( !d->mErrorHandler ) // create default error handler 730 if ( !d->mErrorHandler ) // create default error handler
724 d->mErrorHandler = new ConsoleErrorHandler; 731 d->mErrorHandler = new ConsoleErrorHandler;
725 732
726 if ( d->mErrorHandler ) 733 if ( d->mErrorHandler )
727 d->mErrorHandler->error( msg ); 734 d->mErrorHandler->error( msg );
728 else 735 else
729 kdError(5700) << "no error handler defined" << endl; 736 kdError(5700) << "no error handler defined" << endl;
730*/ 737*/
731 kdDebug(5700) << "msg" << endl; 738 kdDebug(5700) << "msg" << endl;
732 qDebug(msg); 739 qDebug(msg);
733} 740}
734 741
735void AddressBook::deleteRemovedAddressees() 742void AddressBook::deleteRemovedAddressees()
736{ 743{
737 Addressee::List::Iterator it; 744 Addressee::List::Iterator it;
738 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 745 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
739 Resource *resource = (*it).resource(); 746 Resource *resource = (*it).resource();
740 if ( resource && !resource->readOnly() && resource->isOpen() ) 747 if ( resource && !resource->readOnly() && resource->isOpen() )
741 resource->removeAddressee( *it ); 748 resource->removeAddressee( *it );
742 } 749 }
743 750
744 d->mRemovedAddressees.clear(); 751 d->mRemovedAddressees.clear();
745} 752}
746 753
747void AddressBook::setStandardResource( Resource *resource ) 754void AddressBook::setStandardResource( Resource *resource )
748{ 755{
749// qDebug("AddressBook::setStandardResource 1"); 756// qDebug("AddressBook::setStandardResource 1");
750 d->mManager->setStandardResource( resource ); 757 d->mManager->setStandardResource( resource );
751} 758}
752 759
753Resource *AddressBook::standardResource() 760Resource *AddressBook::standardResource()
754{ 761{
755 return d->mManager->standardResource(); 762 return d->mManager->standardResource();
756} 763}
757 764
758KRES::Manager<Resource> *AddressBook::resourceManager() 765KRES::Manager<Resource> *AddressBook::resourceManager()
759{ 766{
760 return d->mManager; 767 return d->mManager;
761} 768}
762 769
763void AddressBook::cleanUp() 770void AddressBook::cleanUp()
764{ 771{
765 KRES::Manager<Resource>::ActiveIterator it; 772 KRES::Manager<Resource>::ActiveIterator it;
766 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 773 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
767 if ( !(*it)->readOnly() && (*it)->isOpen() ) 774 if ( !(*it)->readOnly() && (*it)->isOpen() )
768 (*it)->cleanUp(); 775 (*it)->cleanUp();
769 } 776 }
770} 777}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 05225f9..650a638 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,333 +1,334 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_ADDRESSBOOK_H 28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H 29#define KABC_ADDRESSBOOK_H
30 30
31#include <qobject.h> 31#include <qobject.h>
32 32
33#include <kresources/manager.h> 33#include <kresources/manager.h>
34#include <qptrlist.h> 34#include <qptrlist.h>
35 35
36#include "addressee.h" 36#include "addressee.h"
37#include "field.h" 37#include "field.h"
38 38
39namespace KABC { 39namespace KABC {
40 40
41class ErrorHandler; 41class ErrorHandler;
42class Resource; 42class Resource;
43class Ticket; 43class Ticket;
44 44
45/** 45/**
46 @short Address Book 46 @short Address Book
47 47
48 This class provides access to a collection of address book entries. 48 This class provides access to a collection of address book entries.
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 145
146 /** 146 /**
147 Returns a iterator for first entry of address book. 147 Returns a iterator for first entry of address book.
148 */ 148 */
149 Iterator begin(); 149 Iterator begin();
150 150
151 /** 151 /**
152 Returns a const iterator for first entry of address book. 152 Returns a const iterator for first entry of address book.
153 */ 153 */
154 ConstIterator begin() const; 154 ConstIterator begin() const;
155 155
156 /** 156 /**
157 Returns a iterator for first entry of address book. 157 Returns a iterator for first entry of address book.
158 */ 158 */
159 Iterator end(); 159 Iterator end();
160 160
161 /** 161 /**
162 Returns a const iterator for first entry of address book. 162 Returns a const iterator for first entry of address book.
163 */ 163 */
164 ConstIterator end() const; 164 ConstIterator end() const;
165 165
166 /** 166 /**
167 Removes all entries from address book. 167 Removes all entries from address book.
168 */ 168 */
169 void clear(); 169 void clear();
170 170
171 /** 171 /**
172 Insert an Addressee object into address book. If an object with the same 172 Insert an Addressee object into address book. If an object with the same
173 unique id already exists in the address book it it replaced by the new 173 unique id already exists in the address book it it replaced by the new
174 one. If not the new object is appended to the address book. 174 one. If not the new object is appended to the address book.
175 */ 175 */
176 void insertAddressee( const Addressee & ); 176 void insertAddressee( const Addressee & );
177 177
178 /** 178 /**
179 Removes entry from the address book. 179 Removes entry from the address book.
180 */ 180 */
181 void removeAddressee( const Addressee & ); 181 void removeAddressee( const Addressee & );
182 182
183 /** 183 /**
184 This is like @ref removeAddressee() just above, with the difference that 184 This is like @ref removeAddressee() just above, with the difference that
185 the first element is a iterator, returned by @ref begin(). 185 the first element is a iterator, returned by @ref begin().
186 */ 186 */
187 void removeAddressee( const Iterator & ); 187 void removeAddressee( const Iterator & );
188 188
189 /** 189 /**
190 Find the specified entry in address book. Returns end(), if the entry 190 Find the specified entry in address book. Returns end(), if the entry
191 couldn't be found. 191 couldn't be found.
192 */ 192 */
193 Iterator find( const Addressee & ); 193 Iterator find( const Addressee & );
194 194
195 /** 195 /**
196 Find the entry specified by an unique id. Returns an empty Addressee 196 Find the entry specified by an unique id. Returns an empty Addressee
197 object, if the address book does not contain an entry with this id. 197 object, if the address book does not contain an entry with this id.
198 */ 198 */
199 Addressee findByUid( const QString & ); 199 Addressee findByUid( const QString & );
200 200
201 201
202 /** 202 /**
203 Returns a list of all addressees in the address book. This list can 203 Returns a list of all addressees in the address book. This list can
204 be sorted with @ref KABC::AddresseeList for example. 204 be sorted with @ref KABC::AddresseeList for example.
205 */ 205 */
206 Addressee::List allAddressees(); 206 Addressee::List allAddressees();
207 207
208 /** 208 /**
209 Find all entries with the specified name in the address book. Returns 209 Find all entries with the specified name in the address book. Returns
210 an empty list, if no entries could be found. 210 an empty list, if no entries could be found.
211 */ 211 */
212 Addressee::List findByName( const QString & ); 212 Addressee::List findByName( const QString & );
213 213
214 /** 214 /**
215 Find all entries with the specified email address in the address book. 215 Find all entries with the specified email address in the address book.
216 Returns an empty list, if no entries could be found. 216 Returns an empty list, if no entries could be found.
217 */ 217 */
218 Addressee::List findByEmail( const QString & ); 218 Addressee::List findByEmail( const QString & );
219 219
220 /** 220 /**
221 Find all entries wich have the specified category in the address book. 221 Find all entries wich have the specified category in the address book.
222 Returns an empty list, if no entries could be found. 222 Returns an empty list, if no entries could be found.
223 */ 223 */
224 Addressee::List findByCategory( const QString & ); 224 Addressee::List findByCategory( const QString & );
225 225
226 /** 226 /**
227 Return a string identifying this addressbook. 227 Return a string identifying this addressbook.
228 */ 228 */
229 virtual QString identifier(); 229 virtual QString identifier();
230 230
231 /** 231 /**
232 Used for debug output. 232 Used for debug output.
233 */ 233 */
234 void dump() const; 234 void dump() const;
235 235
236 void emitAddressBookLocked() { emit addressBookLocked( this ); } 236 void emitAddressBookLocked() { emit addressBookLocked( this ); }
237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 237 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
238 void emitAddressBookChanged() { emit addressBookChanged( this ); } 238 void emitAddressBookChanged() { emit addressBookChanged( this ); }
239 239
240 /** 240 /**
241 Return list of all Fields known to the address book which are associated 241 Return list of all Fields known to the address book which are associated
242 with the given field category. 242 with the given field category.
243 */ 243 */
244 Field::List fields( int category = Field::All ); 244 Field::List fields( int category = Field::All );
245 245
246 /** 246 /**
247 Add custom field to address book. 247 Add custom field to address book.
248 248
249 @param label User visible label of the field. 249 @param label User visible label of the field.
250 @param category Ored list of field categories. 250 @param category Ored list of field categories.
251 @param key Identifier used as key for reading and writing the field. 251 @param key Identifier used as key for reading and writing the field.
252 @param app String used as application key for reading and writing 252 @param app String used as application key for reading and writing
253 the field. 253 the field.
254 */ 254 */
255 bool addCustomField( const QString &label, int category = Field::All, 255 bool addCustomField( const QString &label, int category = Field::All,
256 const QString &key = QString::null, 256 const QString &key = QString::null,
257 const QString &app = QString::null ); 257 const QString &app = QString::null );
258 258
259 259
260 /** 260 /**
261 Add address book resource. 261 Add address book resource.
262 */ 262 */
263 bool addResource( Resource * ); 263 bool addResource( Resource * );
264 264
265 /** 265 /**
266 Remove address book resource. 266 Remove address book resource.
267 */ 267 */
268 bool removeResource( Resource * ); 268 bool removeResource( Resource * );
269 269
270 /** 270 /**
271 Return pointer list of all resources. 271 Return pointer list of all resources.
272 */ 272 */
273 QPtrList<Resource> resources(); 273 QPtrList<Resource> resources();
274 274
275 /** 275 /**
276 Set the @p ErrorHandler, that is used by @ref error() to 276 Set the @p ErrorHandler, that is used by @ref error() to
277 provide gui-independend error messages. 277 provide gui-independend error messages.
278 */ 278 */
279 void setErrorHandler( ErrorHandler * ); 279 void setErrorHandler( ErrorHandler * );
280 280
281 /** 281 /**
282 Shows gui independend error messages. 282 Shows gui independend error messages.
283 */ 283 */
284 void error( const QString& ); 284 void error( const QString& );
285 285
286 /** 286 /**
287 Query all resources to clean up their lock files 287 Query all resources to clean up their lock files
288 */ 288 */
289 void cleanUp(); 289 void cleanUp();
290 290
291 // sync stuff 291 // sync stuff
292 Addressee::List getExternLastSyncAddressees(); 292 Addressee::List getExternLastSyncAddressees();
293 void resetTempSyncStat(); 293 void resetTempSyncStat();
294 QStringList uidList();
294 295
295 296
296 signals: 297 signals:
297 /** 298 /**
298 Emitted, when the address book has changed on disk. 299 Emitted, when the address book has changed on disk.
299 */ 300 */
300 void addressBookChanged( AddressBook * ); 301 void addressBookChanged( AddressBook * );
301 302
302 /** 303 /**
303 Emitted, when the address book has been locked for writing. 304 Emitted, when the address book has been locked for writing.
304 */ 305 */
305 void addressBookLocked( AddressBook * ); 306 void addressBookLocked( AddressBook * );
306 307
307 /** 308 /**
308 Emitted, when the address book has been unlocked. 309 Emitted, when the address book has been unlocked.
309 */ 310 */
310 void addressBookUnlocked( AddressBook * ); 311 void addressBookUnlocked( AddressBook * );
311 312
312 protected: 313 protected:
313 void deleteRemovedAddressees(); 314 void deleteRemovedAddressees();
314 void setStandardResource( Resource * ); 315 void setStandardResource( Resource * );
315 Resource *standardResource(); 316 Resource *standardResource();
316 KRES::Manager<Resource> *resourceManager(); 317 KRES::Manager<Resource> *resourceManager();
317 318
318 void init(const QString &config, const QString &family); 319 void init(const QString &config, const QString &family);
319 320
320 private: 321 private:
321//US QPtrList<Resource> mDummy; // Remove in KDE 4 322//US QPtrList<Resource> mDummy; // Remove in KDE 4
322 323
323 324
324 struct AddressBookData; 325 struct AddressBookData;
325 AddressBookData *d; 326 AddressBookData *d;
326}; 327};
327 328
328QDataStream &operator<<( QDataStream &, const AddressBook & ); 329QDataStream &operator<<( QDataStream &, const AddressBook & );
329QDataStream &operator>>( QDataStream &, AddressBook & ); 330QDataStream &operator>>( QDataStream &, AddressBook & );
330 331
331} 332}
332 333
333#endif 334#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 53c63ff..f497541 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,2896 +1,2874 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include "kabcore.h" 31#include "kabcore.h"
32 32
33#include <stdaddressbook.h> 33#include <stdaddressbook.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kfiledialog.h> 35#include <kfiledialog.h>
36#include <qprogressbar.h>
36 37
37#ifndef KAB_EMBEDDED 38#ifndef KAB_EMBEDDED
38#include <qclipboard.h> 39#include <qclipboard.h>
39#include <qdir.h> 40#include <qdir.h>
40#include <qfile.h> 41#include <qfile.h>
41#include <qapplicaton.h> 42#include <qapplicaton.h>
43#include <qprogressbar.h>
42#include <qlayout.h> 44#include <qlayout.h>
43#include <qregexp.h> 45#include <qregexp.h>
44#include <qvbox.h> 46#include <qvbox.h>
45#include <kabc/addresseelist.h> 47#include <kabc/addresseelist.h>
46#include <kabc/errorhandler.h> 48#include <kabc/errorhandler.h>
47#include <kabc/resource.h> 49#include <kabc/resource.h>
48#include <kabc/vcardconverter.h> 50#include <kabc/vcardconverter.h>
49#include <kapplication.h> 51#include <kapplication.h>
50#include <kactionclasses.h> 52#include <kactionclasses.h>
51#include <kcmultidialog.h> 53#include <kcmultidialog.h>
52#include <kdebug.h> 54#include <kdebug.h>
53#include <kdeversion.h> 55#include <kdeversion.h>
54#include <kkeydialog.h> 56#include <kkeydialog.h>
55#include <kmessagebox.h> 57#include <kmessagebox.h>
56#include <kprinter.h> 58#include <kprinter.h>
57#include <kprotocolinfo.h> 59#include <kprotocolinfo.h>
58#include <kresources/selectdialog.h> 60#include <kresources/selectdialog.h>
59#include <kstandarddirs.h> 61#include <kstandarddirs.h>
60#include <ktempfile.h> 62#include <ktempfile.h>
61#include <kxmlguiclient.h> 63#include <kxmlguiclient.h>
62#include <kaboutdata.h> 64#include <kaboutdata.h>
63#include <libkdepim/categoryselectdialog.h> 65#include <libkdepim/categoryselectdialog.h>
64 66
65#include "addresseeutil.h" 67#include "addresseeutil.h"
66#include "addresseeeditordialog.h" 68#include "addresseeeditordialog.h"
67#include "extensionmanager.h" 69#include "extensionmanager.h"
68#include "kstdaction.h" 70#include "kstdaction.h"
69#include "kaddressbookservice.h" 71#include "kaddressbookservice.h"
70#include "ldapsearchdialog.h" 72#include "ldapsearchdialog.h"
71#include "printing/printingwizard.h" 73#include "printing/printingwizard.h"
72#else // KAB_EMBEDDED 74#else // KAB_EMBEDDED
73 75
74#include <kapplication.h> 76#include <kapplication.h>
75#include "KDGanttMinimizeSplitter.h" 77#include "KDGanttMinimizeSplitter.h"
76#include "kaddressbookmain.h" 78#include "kaddressbookmain.h"
77#include "kactioncollection.h" 79#include "kactioncollection.h"
78#include "addresseedialog.h" 80#include "addresseedialog.h"
79//US 81//US
80#include <addresseeview.h> 82#include <addresseeview.h>
81 83
82#include <qapp.h> 84#include <qapp.h>
83#include <qmenubar.h> 85#include <qmenubar.h>
84//#include <qtoolbar.h> 86//#include <qtoolbar.h>
85#include <qmessagebox.h> 87#include <qmessagebox.h>
86#include <kdebug.h> 88#include <kdebug.h>
87#include <kiconloader.h> // needed for SmallIcon 89#include <kiconloader.h> // needed for SmallIcon
88#include <kresources/kcmkresources.h> 90#include <kresources/kcmkresources.h>
89#include <ktoolbar.h> 91#include <ktoolbar.h>
90 92
91 93
92//#include <qlabel.h> 94//#include <qlabel.h>
93 95
94 96
95#ifndef DESKTOP_VERSION 97#ifndef DESKTOP_VERSION
96#include <qpe/ir.h> 98#include <qpe/ir.h>
97#include <qpe/qpemenubar.h> 99#include <qpe/qpemenubar.h>
98#include <qtopia/qcopenvelope_qws.h> 100#include <qtopia/qcopenvelope_qws.h>
99#else 101#else
100 102
101#include <qmenubar.h> 103#include <qmenubar.h>
102#endif 104#endif
103 105
104#endif // KAB_EMBEDDED 106#endif // KAB_EMBEDDED
105#include "kcmconfigs/kcmkabconfig.h" 107#include "kcmconfigs/kcmkabconfig.h"
106#include "kcmconfigs/kcmkdepimconfig.h" 108#include "kcmconfigs/kcmkdepimconfig.h"
107#include "kpimglobalprefs.h" 109#include "kpimglobalprefs.h"
108#include "externalapphandler.h" 110#include "externalapphandler.h"
109 111
110 112
111#include <kresources/selectdialog.h> 113#include <kresources/selectdialog.h>
112#include <kmessagebox.h> 114#include <kmessagebox.h>
113 115
114#include <picture.h> 116#include <picture.h>
115#include <resource.h> 117#include <resource.h>
116 118
117//US#include <qsplitter.h> 119//US#include <qsplitter.h>
118#include <qmap.h> 120#include <qmap.h>
119#include <qdir.h> 121#include <qdir.h>
120#include <qfile.h> 122#include <qfile.h>
121#include <qvbox.h> 123#include <qvbox.h>
122#include <qlayout.h> 124#include <qlayout.h>
123#include <qclipboard.h> 125#include <qclipboard.h>
124#include <qtextstream.h> 126#include <qtextstream.h>
125 127
126#include <libkdepim/categoryselectdialog.h> 128#include <libkdepim/categoryselectdialog.h>
127#include <kabc/vcardconverter.h> 129#include <kabc/vcardconverter.h>
128 130
129 131
130#include "addresseeutil.h" 132#include "addresseeutil.h"
131#include "undocmds.h" 133#include "undocmds.h"
132#include "addresseeeditordialog.h" 134#include "addresseeeditordialog.h"
133#include "viewmanager.h" 135#include "viewmanager.h"
134#include "details/detailsviewcontainer.h" 136#include "details/detailsviewcontainer.h"
135#include "kabprefs.h" 137#include "kabprefs.h"
136#include "xxportmanager.h" 138#include "xxportmanager.h"
137#include "incsearchwidget.h" 139#include "incsearchwidget.h"
138#include "jumpbuttonbar.h" 140#include "jumpbuttonbar.h"
139#include "extensionmanager.h" 141#include "extensionmanager.h"
140#include "addresseeconfig.h" 142#include "addresseeconfig.h"
141#include <kcmultidialog.h> 143#include <kcmultidialog.h>
142 144
143#ifdef _WIN32_ 145#ifdef _WIN32_
144 146
145#include "kaimportoldialog.h" 147#include "kaimportoldialog.h"
146#else 148#else
147#include <unistd.h> 149#include <unistd.h>
148#endif 150#endif
149// sync includes 151// sync includes
150#include <libkdepim/ksyncprofile.h> 152#include <libkdepim/ksyncprofile.h>
151#include <libkdepim/ksyncprefsdialog.h> 153#include <libkdepim/ksyncprefsdialog.h>
152 154
153 155
154bool pasteWithNewUid = true; 156bool pasteWithNewUid = true;
155 157
156#ifdef KAB_EMBEDDED 158#ifdef KAB_EMBEDDED
157KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 159KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
158 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 160 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
159 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 161 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
160 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 162 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
161#else //KAB_EMBEDDED 163#else //KAB_EMBEDDED
162KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 164KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
163 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), 165 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
164 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 166 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
165 mReadWrite( readWrite ), mModified( false ) 167 mReadWrite( readWrite ), mModified( false )
166#endif //KAB_EMBEDDED 168#endif //KAB_EMBEDDED
167{ 169{
168 170
169 mBlockSaveFlag = false; 171 mBlockSaveFlag = false;
170 mExtensionBarSplitter = 0; 172 mExtensionBarSplitter = 0;
171 mIsPart = !parent->inherits( "KAddressBookMain" ); 173 mIsPart = !parent->inherits( "KAddressBookMain" );
172 174
173 mAddressBook = KABC::StdAddressBook::self(); 175 mAddressBook = KABC::StdAddressBook::self();
174 KABC::StdAddressBook::setAutomaticSave( false ); 176 KABC::StdAddressBook::setAutomaticSave( false );
175 177
176#ifndef KAB_EMBEDDED 178#ifndef KAB_EMBEDDED
177 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 179 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
178#endif //KAB_EMBEDDED 180#endif //KAB_EMBEDDED
179 181
180 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 182 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
181 SLOT( addressBookChanged() ) ); 183 SLOT( addressBookChanged() ) );
182 184
183#if 0 185#if 0
184 // LP moved to addressbook init method 186 // LP moved to addressbook init method
185 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 187 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
186 "X-Department", "KADDRESSBOOK" ); 188 "X-Department", "KADDRESSBOOK" );
187 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 189 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
188 "X-Profession", "KADDRESSBOOK" ); 190 "X-Profession", "KADDRESSBOOK" );
189 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 191 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
190 "X-AssistantsName", "KADDRESSBOOK" ); 192 "X-AssistantsName", "KADDRESSBOOK" );
191 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 193 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
192 "X-ManagersName", "KADDRESSBOOK" ); 194 "X-ManagersName", "KADDRESSBOOK" );
193 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 195 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
194 "X-SpousesName", "KADDRESSBOOK" ); 196 "X-SpousesName", "KADDRESSBOOK" );
195 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 197 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
196 "X-Office", "KADDRESSBOOK" ); 198 "X-Office", "KADDRESSBOOK" );
197 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 199 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
198 "X-IMAddress", "KADDRESSBOOK" ); 200 "X-IMAddress", "KADDRESSBOOK" );
199 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 201 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
200 "X-Anniversary", "KADDRESSBOOK" ); 202 "X-Anniversary", "KADDRESSBOOK" );
201 203
202 //US added this field to become compatible with Opie/qtopia addressbook 204 //US added this field to become compatible with Opie/qtopia addressbook
203 // values can be "female" or "male" or "". An empty field represents undefined. 205 // values can be "female" or "male" or "". An empty field represents undefined.
204 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 206 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
205 "X-Gender", "KADDRESSBOOK" ); 207 "X-Gender", "KADDRESSBOOK" );
206 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 208 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
207 "X-Children", "KADDRESSBOOK" ); 209 "X-Children", "KADDRESSBOOK" );
208 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 210 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
209 "X-FreeBusyUrl", "KADDRESSBOOK" ); 211 "X-FreeBusyUrl", "KADDRESSBOOK" );
210#endif 212#endif
211 initGUI(); 213 initGUI();
212 214
213 mIncSearchWidget->setFocus(); 215 mIncSearchWidget->setFocus();
214 216
215 217
216 connect( mViewManager, SIGNAL( selected( const QString& ) ), 218 connect( mViewManager, SIGNAL( selected( const QString& ) ),
217 SLOT( setContactSelected( const QString& ) ) ); 219 SLOT( setContactSelected( const QString& ) ) );
218 connect( mViewManager, SIGNAL( executed( const QString& ) ), 220 connect( mViewManager, SIGNAL( executed( const QString& ) ),
219 SLOT( executeContact( const QString& ) ) ); 221 SLOT( executeContact( const QString& ) ) );
220 222
221 connect( mViewManager, SIGNAL( deleteRequest( ) ), 223 connect( mViewManager, SIGNAL( deleteRequest( ) ),
222 SLOT( deleteContacts( ) ) ); 224 SLOT( deleteContacts( ) ) );
223 connect( mViewManager, SIGNAL( modified() ), 225 connect( mViewManager, SIGNAL( modified() ),
224 SLOT( setModified() ) ); 226 SLOT( setModified() ) );
225 227
226 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 228 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
227 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 229 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
228 230
229 connect( mXXPortManager, SIGNAL( modified() ), 231 connect( mXXPortManager, SIGNAL( modified() ),
230 SLOT( setModified() ) ); 232 SLOT( setModified() ) );
231 233
232 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 234 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
233 SLOT( incrementalSearch( const QString& ) ) ); 235 SLOT( incrementalSearch( const QString& ) ) );
234 connect( mIncSearchWidget, SIGNAL( fieldChanged() ), 236 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
235 mJumpButtonBar, SLOT( recreateButtons() ) ); 237 mJumpButtonBar, SLOT( recreateButtons() ) );
236 238
237 connect( mDetails, SIGNAL( sendEmail( const QString& ) ), 239 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
238 SLOT( sendMail( const QString& ) ) ); 240 SLOT( sendMail( const QString& ) ) );
239 241
240 242
241 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 243 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
242 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); 244 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)));
243 245
244 246
245#ifndef KAB_EMBEDDED 247#ifndef KAB_EMBEDDED
246 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 248 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
247 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 249 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
248 250
249 connect( mDetails, SIGNAL( browse( const QString& ) ), 251 connect( mDetails, SIGNAL( browse( const QString& ) ),
250 SLOT( browse( const QString& ) ) ); 252 SLOT( browse( const QString& ) ) );
251 253
252 254
253 mAddressBookService = new KAddressBookService( this ); 255 mAddressBookService = new KAddressBookService( this );
254 256
255#endif //KAB_EMBEDDED 257#endif //KAB_EMBEDDED
256 mEditorDialog = 0; 258 mEditorDialog = 0;
257 createAddresseeEditorDialog( this ); 259 createAddresseeEditorDialog( this );
258 setModified( false ); 260 setModified( false );
259} 261}
260 262
261KABCore::~KABCore() 263KABCore::~KABCore()
262{ 264{
263 // save(); 265 // save();
264 //saveSettings(); 266 //saveSettings();
265 //KABPrefs::instance()->writeConfig(); 267 //KABPrefs::instance()->writeConfig();
266 delete AddresseeConfig::instance(); 268 delete AddresseeConfig::instance();
267 mAddressBook = 0; 269 mAddressBook = 0;
268 KABC::StdAddressBook::close(); 270 KABC::StdAddressBook::close();
269} 271}
270 272
271void KABCore::restoreSettings() 273void KABCore::restoreSettings()
272{ 274{
273 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 275 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
274 276
275 bool state; 277 bool state;
276 278
277 if (mMultipleViewsAtOnce) 279 if (mMultipleViewsAtOnce)
278 state = KABPrefs::instance()->mDetailsPageVisible; 280 state = KABPrefs::instance()->mDetailsPageVisible;
279 else 281 else
280 state = false; 282 state = false;
281 283
282 mActionDetails->setChecked( state ); 284 mActionDetails->setChecked( state );
283 setDetailsVisible( state ); 285 setDetailsVisible( state );
284 286
285 state = KABPrefs::instance()->mJumpButtonBarVisible; 287 state = KABPrefs::instance()->mJumpButtonBarVisible;
286 288
287 mActionJumpBar->setChecked( state ); 289 mActionJumpBar->setChecked( state );
288 setJumpButtonBarVisible( state ); 290 setJumpButtonBarVisible( state );
289/*US 291/*US
290 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 292 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
291 if ( splitterSize.count() == 0 ) { 293 if ( splitterSize.count() == 0 ) {
292 splitterSize.append( width() / 2 ); 294 splitterSize.append( width() / 2 );
293 splitterSize.append( width() / 2 ); 295 splitterSize.append( width() / 2 );
294 } 296 }
295 mMiniSplitter->setSizes( splitterSize ); 297 mMiniSplitter->setSizes( splitterSize );
296 if ( mExtensionBarSplitter ) { 298 if ( mExtensionBarSplitter ) {
297 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 299 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
298 if ( splitterSize.count() == 0 ) { 300 if ( splitterSize.count() == 0 ) {
299 splitterSize.append( width() / 2 ); 301 splitterSize.append( width() / 2 );
300 splitterSize.append( width() / 2 ); 302 splitterSize.append( width() / 2 );
301 } 303 }
302 mExtensionBarSplitter->setSizes( splitterSize ); 304 mExtensionBarSplitter->setSizes( splitterSize );
303 305
304 } 306 }
305*/ 307*/
306 mViewManager->restoreSettings(); 308 mViewManager->restoreSettings();
307 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 309 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
308 mExtensionManager->restoreSettings(); 310 mExtensionManager->restoreSettings();
309#ifdef DESKTOP_VERSION 311#ifdef DESKTOP_VERSION
310 int wid = width(); 312 int wid = width();
311 if ( wid < 10 ) 313 if ( wid < 10 )
312 wid = 400; 314 wid = 400;
313#else 315#else
314 int wid = QApplication::desktop()->width(); 316 int wid = QApplication::desktop()->width();
315 if ( wid < 640 ) 317 if ( wid < 640 )
316 wid = QApplication::desktop()->height(); 318 wid = QApplication::desktop()->height();
317#endif 319#endif
318 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 320 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
319 if ( true /*splitterSize.count() == 0*/ ) { 321 if ( true /*splitterSize.count() == 0*/ ) {
320 splitterSize.append( wid / 2 ); 322 splitterSize.append( wid / 2 );
321 splitterSize.append( wid / 2 ); 323 splitterSize.append( wid / 2 );
322 } 324 }
323 mMiniSplitter->setSizes( splitterSize ); 325 mMiniSplitter->setSizes( splitterSize );
324 if ( mExtensionBarSplitter ) { 326 if ( mExtensionBarSplitter ) {
325 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 327 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
326 if ( true /*splitterSize.count() == 0*/ ) { 328 if ( true /*splitterSize.count() == 0*/ ) {
327 splitterSize.append( wid / 2 ); 329 splitterSize.append( wid / 2 );
328 splitterSize.append( wid / 2 ); 330 splitterSize.append( wid / 2 );
329 } 331 }
330 mExtensionBarSplitter->setSizes( splitterSize ); 332 mExtensionBarSplitter->setSizes( splitterSize );
331 333
332 } 334 }
333 335
334 336
335} 337}
336 338
337void KABCore::saveSettings() 339void KABCore::saveSettings()
338{ 340{
339 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 341 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
340 if ( mExtensionBarSplitter ) 342 if ( mExtensionBarSplitter )
341 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 343 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
342 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 344 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
343 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 345 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
344#ifndef KAB_EMBEDDED 346#ifndef KAB_EMBEDDED
345 347
346 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 348 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
347 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 349 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
348#endif //KAB_EMBEDDED 350#endif //KAB_EMBEDDED
349 mExtensionManager->saveSettings(); 351 mExtensionManager->saveSettings();
350 mViewManager->saveSettings(); 352 mViewManager->saveSettings();
351 353
352 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 354 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
353} 355}
354 356
355KABC::AddressBook *KABCore::addressBook() const 357KABC::AddressBook *KABCore::addressBook() const
356{ 358{
357 return mAddressBook; 359 return mAddressBook;
358} 360}
359 361
360KConfig *KABCore::config() 362KConfig *KABCore::config()
361{ 363{
362#ifndef KAB_EMBEDDED 364#ifndef KAB_EMBEDDED
363 return KABPrefs::instance()->config(); 365 return KABPrefs::instance()->config();
364#else //KAB_EMBEDDED 366#else //KAB_EMBEDDED
365 return KABPrefs::instance()->getConfig(); 367 return KABPrefs::instance()->getConfig();
366#endif //KAB_EMBEDDED 368#endif //KAB_EMBEDDED
367} 369}
368 370
369KActionCollection *KABCore::actionCollection() const 371KActionCollection *KABCore::actionCollection() const
370{ 372{
371 return mGUIClient->actionCollection(); 373 return mGUIClient->actionCollection();
372} 374}
373 375
374KABC::Field *KABCore::currentSearchField() const 376KABC::Field *KABCore::currentSearchField() const
375{ 377{
376 if (mIncSearchWidget) 378 if (mIncSearchWidget)
377 return mIncSearchWidget->currentField(); 379 return mIncSearchWidget->currentField();
378 else 380 else
379 return 0; 381 return 0;
380} 382}
381 383
382QStringList KABCore::selectedUIDs() const 384QStringList KABCore::selectedUIDs() const
383{ 385{
384 return mViewManager->selectedUids(); 386 return mViewManager->selectedUids();
385} 387}
386 388
387KABC::Resource *KABCore::requestResource( QWidget *parent ) 389KABC::Resource *KABCore::requestResource( QWidget *parent )
388{ 390{
389 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 391 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
390 392
391 QPtrList<KRES::Resource> kresResources; 393 QPtrList<KRES::Resource> kresResources;
392 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 394 QPtrListIterator<KABC::Resource> resIt( kabcResources );
393 KABC::Resource *resource; 395 KABC::Resource *resource;
394 while ( ( resource = resIt.current() ) != 0 ) { 396 while ( ( resource = resIt.current() ) != 0 ) {
395 ++resIt; 397 ++resIt;
396 if ( !resource->readOnly() ) { 398 if ( !resource->readOnly() ) {
397 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 399 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
398 if ( res ) 400 if ( res )
399 kresResources.append( res ); 401 kresResources.append( res );
400 } 402 }
401 } 403 }
402 404
403 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 405 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
404 return static_cast<KABC::Resource*>( res ); 406 return static_cast<KABC::Resource*>( res );
405} 407}
406 408
407#ifndef KAB_EMBEDDED 409#ifndef KAB_EMBEDDED
408KAboutData *KABCore::createAboutData() 410KAboutData *KABCore::createAboutData()
409#else //KAB_EMBEDDED 411#else //KAB_EMBEDDED
410void KABCore::createAboutData() 412void KABCore::createAboutData()
411#endif //KAB_EMBEDDED 413#endif //KAB_EMBEDDED
412{ 414{
413#ifndef KAB_EMBEDDED 415#ifndef KAB_EMBEDDED
414 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 416 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
415 "3.1", I18N_NOOP( "The KDE Address Book" ), 417 "3.1", I18N_NOOP( "The KDE Address Book" ),
416 KAboutData::License_GPL_V2, 418 KAboutData::License_GPL_V2,
417 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 419 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
418 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 420 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
419 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 421 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
420 about->addAuthor( "Cornelius Schumacher", 422 about->addAuthor( "Cornelius Schumacher",
421 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 423 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
422 "schumacher@kde.org" ); 424 "schumacher@kde.org" );
423 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 425 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
424 "mpilone@slac.com" ); 426 "mpilone@slac.com" );
425 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 427 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
426 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 428 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
427 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 429 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
428 "michel@klaralvdalens-datakonsult.se" ); 430 "michel@klaralvdalens-datakonsult.se" );
429 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 431 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
430 "hansen@kde.org" ); 432 "hansen@kde.org" );
431 433
432 return about; 434 return about;
433#endif //KAB_EMBEDDED 435#endif //KAB_EMBEDDED
434 436
435 QString version; 437 QString version;
436#include <../version> 438#include <../version>
437 QMessageBox::about( this, "About KAddressbook/Pi", 439 QMessageBox::about( this, "About KAddressbook/Pi",
438 "KAddressbook/Platform-independent\n" 440 "KAddressbook/Platform-independent\n"
439 "(KA/Pi) " +version + " - " + 441 "(KA/Pi) " +version + " - " +
440#ifdef DESKTOP_VERSION 442#ifdef DESKTOP_VERSION
441 "Desktop Edition\n" 443 "Desktop Edition\n"
442#else 444#else
443 "PDA-Edition\n" 445 "PDA-Edition\n"
444 "for: Zaurus 5500 / 7x0 / 8x0\n" 446 "for: Zaurus 5500 / 7x0 / 8x0\n"
445#endif 447#endif
446 448
447 "(c) 2004 Ulf Schenk\n" 449 "(c) 2004 Ulf Schenk\n"
448 "(c) 2004 Lutz Rogowski\n" 450 "(c) 2004 Lutz Rogowski\n"
449 "(c) 1997-2003, The KDE PIM Team\n" 451 "(c) 1997-2003, The KDE PIM Team\n"
450 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 452 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
451 "Don Sanders Original author\n" 453 "Don Sanders Original author\n"
452 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 454 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
453 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 455 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
454 "Greg Stern DCOP interface\n" 456 "Greg Stern DCOP interface\n"
455 "Mark Westcot Contact pinning\n" 457 "Mark Westcot Contact pinning\n"
456 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 458 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
457 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 459 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
458#ifdef _WIN32_ 460#ifdef _WIN32_
459 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 461 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
460#endif 462#endif
461 ); 463 );
462} 464}
463 465
464void KABCore::setContactSelected( const QString &uid ) 466void KABCore::setContactSelected( const QString &uid )
465{ 467{
466 KABC::Addressee addr = mAddressBook->findByUid( uid ); 468 KABC::Addressee addr = mAddressBook->findByUid( uid );
467 if ( !mDetails->isHidden() ) 469 if ( !mDetails->isHidden() )
468 mDetails->setAddressee( addr ); 470 mDetails->setAddressee( addr );
469 471
470 if ( !addr.isEmpty() ) { 472 if ( !addr.isEmpty() ) {
471 emit contactSelected( addr.formattedName() ); 473 emit contactSelected( addr.formattedName() );
472 KABC::Picture pic = addr.photo(); 474 KABC::Picture pic = addr.photo();
473 if ( pic.isIntern() ) { 475 if ( pic.isIntern() ) {
474//US emit contactSelected( pic.data() ); 476//US emit contactSelected( pic.data() );
475//US instead use: 477//US instead use:
476 QPixmap px; 478 QPixmap px;
477 if (pic.data().isNull() != true) 479 if (pic.data().isNull() != true)
478 { 480 {
479 px.convertFromImage(pic.data()); 481 px.convertFromImage(pic.data());
480 } 482 }
481 483
482 emit contactSelected( px ); 484 emit contactSelected( px );
483 } 485 }
484 } 486 }
485 487
486 488
487 mExtensionManager->setSelectionChanged(); 489 mExtensionManager->setSelectionChanged();
488 490
489 // update the actions 491 // update the actions
490 bool selected = !uid.isEmpty(); 492 bool selected = !uid.isEmpty();
491 493
492 if ( mReadWrite ) { 494 if ( mReadWrite ) {
493 mActionCut->setEnabled( selected ); 495 mActionCut->setEnabled( selected );
494 mActionPaste->setEnabled( selected ); 496 mActionPaste->setEnabled( selected );
495 } 497 }
496 498
497 mActionCopy->setEnabled( selected ); 499 mActionCopy->setEnabled( selected );
498 mActionDelete->setEnabled( selected ); 500 mActionDelete->setEnabled( selected );
499 mActionEditAddressee->setEnabled( selected ); 501 mActionEditAddressee->setEnabled( selected );
500 mActionMail->setEnabled( selected ); 502 mActionMail->setEnabled( selected );
501 mActionMailVCard->setEnabled( selected ); 503 mActionMailVCard->setEnabled( selected );
502 //if (mActionBeam) 504 //if (mActionBeam)
503 //mActionBeam->setEnabled( selected ); 505 //mActionBeam->setEnabled( selected );
504 506
505 if (mActionBeamVCard) 507 if (mActionBeamVCard)
506 mActionBeamVCard->setEnabled( selected ); 508 mActionBeamVCard->setEnabled( selected );
507 509
508 mActionWhoAmI->setEnabled( selected ); 510 mActionWhoAmI->setEnabled( selected );
509 mActionCategories->setEnabled( selected ); 511 mActionCategories->setEnabled( selected );
510} 512}
511 513
512void KABCore::sendMail() 514void KABCore::sendMail()
513{ 515{
514 sendMail( mViewManager->selectedEmails().join( ", " ) ); 516 sendMail( mViewManager->selectedEmails().join( ", " ) );
515} 517}
516 518
517void KABCore::sendMail( const QString& emaillist ) 519void KABCore::sendMail( const QString& emaillist )
518{ 520{
519 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 521 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
520 if (emaillist.contains(",") > 0) 522 if (emaillist.contains(",") > 0)
521 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 523 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
522 else 524 else
523 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 525 ExternalAppHandler::instance()->mailToOneContact( emaillist );
524} 526}
525 527
526 528
527 529
528void KABCore::mailVCard() 530void KABCore::mailVCard()
529{ 531{
530 QStringList uids = mViewManager->selectedUids(); 532 QStringList uids = mViewManager->selectedUids();
531 if ( !uids.isEmpty() ) 533 if ( !uids.isEmpty() )
532 mailVCard( uids ); 534 mailVCard( uids );
533} 535}
534 536
535void KABCore::mailVCard( const QStringList& uids ) 537void KABCore::mailVCard( const QStringList& uids )
536{ 538{
537 QStringList urls; 539 QStringList urls;
538 540
539// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 541// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
540 542
541 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 543 QString dirName = "/tmp/" + KApplication::randomString( 8 );
542 544
543 545
544 546
545 QDir().mkdir( dirName, true ); 547 QDir().mkdir( dirName, true );
546 548
547 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 549 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
548 KABC::Addressee a = mAddressBook->findByUid( *it ); 550 KABC::Addressee a = mAddressBook->findByUid( *it );
549 551
550 if ( a.isEmpty() ) 552 if ( a.isEmpty() )
551 continue; 553 continue;
552 554
553 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 555 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
554 556
555 QString fileName = dirName + "/" + name; 557 QString fileName = dirName + "/" + name;
556 558
557 QFile outFile(fileName); 559 QFile outFile(fileName);
558 560
559 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 561 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
560 KABC::VCardConverter converter; 562 KABC::VCardConverter converter;
561 QString vcard; 563 QString vcard;
562 564
563 converter.addresseeToVCard( a, vcard ); 565 converter.addresseeToVCard( a, vcard );
564 566
565 QTextStream t( &outFile ); // use a text stream 567 QTextStream t( &outFile ); // use a text stream
566 t.setEncoding( QTextStream::UnicodeUTF8 ); 568 t.setEncoding( QTextStream::UnicodeUTF8 );
567 t << vcard; 569 t << vcard;
568 570
569 outFile.close(); 571 outFile.close();
570 572
571 urls.append( fileName ); 573 urls.append( fileName );
572 } 574 }
573 } 575 }
574 576
575 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 577 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
576 578
577 579
578/*US 580/*US
579 kapp->invokeMailer( QString::null, QString::null, QString::null, 581 kapp->invokeMailer( QString::null, QString::null, QString::null,
580 QString::null, // subject 582 QString::null, // subject
581 QString::null, // body 583 QString::null, // body
582 QString::null, 584 QString::null,
583 urls ); // attachments 585 urls ); // attachments
584*/ 586*/
585 587
586} 588}
587 589
588/** 590/**
589 Beams the "WhoAmI contact. 591 Beams the "WhoAmI contact.
590*/ 592*/
591void KABCore::beamMySelf() 593void KABCore::beamMySelf()
592{ 594{
593 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 595 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
594 if (!a.isEmpty()) 596 if (!a.isEmpty())
595 { 597 {
596 QStringList uids; 598 QStringList uids;
597 uids << a.uid(); 599 uids << a.uid();
598 600
599 beamVCard(uids); 601 beamVCard(uids);
600 } else { 602 } else {
601 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 603 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
602 604
603 605
604 } 606 }
605} 607}
606 608
607void KABCore::beamVCard() 609void KABCore::beamVCard()
608{ 610{
609 QStringList uids = mViewManager->selectedUids(); 611 QStringList uids = mViewManager->selectedUids();
610 if ( !uids.isEmpty() ) 612 if ( !uids.isEmpty() )
611 beamVCard( uids ); 613 beamVCard( uids );
612} 614}
613 615
614 616
615void KABCore::beamVCard(const QStringList& uids) 617void KABCore::beamVCard(const QStringList& uids)
616{ 618{
617/*US 619/*US
618 QString beamFilename; 620 QString beamFilename;
619 Opie::OPimContact c; 621 Opie::OPimContact c;
620 if ( actionPersonal->isOn() ) { 622 if ( actionPersonal->isOn() ) {
621 beamFilename = addressbookPersonalVCardName(); 623 beamFilename = addressbookPersonalVCardName();
622 if ( !QFile::exists( beamFilename ) ) 624 if ( !QFile::exists( beamFilename ) )
623 return; // can't beam a non-existent file 625 return; // can't beam a non-existent file
624 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 626 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
625 beamFilename ); 627 beamFilename );
626 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 628 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
627 Opie::OPimContactAccess::List allList = access->allRecords(); 629 Opie::OPimContactAccess::List allList = access->allRecords();
628 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 630 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
629 c = *it; 631 c = *it;
630 632
631 delete access; 633 delete access;
632 } else { 634 } else {
633 unlink( beamfile ); // delete if exists 635 unlink( beamfile ); // delete if exists
634 mkdir("/tmp/obex/", 0755); 636 mkdir("/tmp/obex/", 0755);
635 c = m_abView -> currentEntry(); 637 c = m_abView -> currentEntry();
636 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 638 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
637 beamfile ); 639 beamfile );
638 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 640 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
639 access->add( c ); 641 access->add( c );
640 access->save(); 642 access->save();
641 delete access; 643 delete access;
642 644
643 beamFilename = beamfile; 645 beamFilename = beamfile;
644 } 646 }
645 647
646 owarn << "Beaming: " << beamFilename << oendl; 648 owarn << "Beaming: " << beamFilename << oendl;
647*/ 649*/
648 650
649#if 0 651#if 0
650 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 652 QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
651 653
652 QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); 654 QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
653 655
654 QString name = "contact.vcf"; 656 QString name = "contact.vcf";
655 657
656 QString fileName = dirName + "/" + name; 658 QString fileName = dirName + "/" + name;
657#endif 659#endif
658 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory 660 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
659 // 661 //
660 QString fileName = "/tmp/kapibeamfile.vcf"; 662 QString fileName = "/tmp/kapibeamfile.vcf";
661 663
662 664
663 //QDir().mkdir( dirName, true ); 665 //QDir().mkdir( dirName, true );
664 666
665 667
666 KABC::VCardConverter converter; 668 KABC::VCardConverter converter;
667 QString description; 669 QString description;
668 QString datastream; 670 QString datastream;
669 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 671 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
670 KABC::Addressee a = mAddressBook->findByUid( *it ); 672 KABC::Addressee a = mAddressBook->findByUid( *it );
671 673
672 if ( a.isEmpty() ) 674 if ( a.isEmpty() )
673 continue; 675 continue;
674 676
675 if (description.isEmpty()) 677 if (description.isEmpty())
676 description = a.formattedName(); 678 description = a.formattedName();
677 679
678 QString vcard; 680 QString vcard;
679 converter.addresseeToVCard( a, vcard ); 681 converter.addresseeToVCard( a, vcard );
680 int start = 0; 682 int start = 0;
681 int next; 683 int next;
682 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 684 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
683 int semi = vcard.find(";", next); 685 int semi = vcard.find(";", next);
684 int dopp = vcard.find(":", next); 686 int dopp = vcard.find(":", next);
685 int sep; 687 int sep;
686 if ( semi < dopp && semi >= 0 ) 688 if ( semi < dopp && semi >= 0 )
687 sep = semi ; 689 sep = semi ;
688 else 690 else
689 sep = dopp; 691 sep = dopp;
690 datastream +=vcard.mid( start, next - start); 692 datastream +=vcard.mid( start, next - start);
691 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 693 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
692 start = sep; 694 start = sep;
693 } 695 }
694 datastream += vcard.mid( start,vcard.length() ); 696 datastream += vcard.mid( start,vcard.length() );
695 } 697 }
696#ifndef DESKTOP_VERSION 698#ifndef DESKTOP_VERSION
697 QFile outFile(fileName); 699 QFile outFile(fileName);
698 if ( outFile.open(IO_WriteOnly) ) { 700 if ( outFile.open(IO_WriteOnly) ) {
699 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 701 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
700 QTextStream t( &outFile ); // use a text stream 702 QTextStream t( &outFile ); // use a text stream
701 t.setEncoding( QTextStream::UnicodeUTF8 ); 703 t.setEncoding( QTextStream::UnicodeUTF8 );
702 t <<datastream; 704 t <<datastream;
703 outFile.close(); 705 outFile.close();
704 Ir *ir = new Ir( this ); 706 Ir *ir = new Ir( this );
705 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 707 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
706 ir->send( fileName, description, "text/x-vCard" ); 708 ir->send( fileName, description, "text/x-vCard" );
707 } else { 709 } else {
708 qDebug("Error open temp beam file "); 710 qDebug("Error open temp beam file ");
709 return; 711 return;
710 } 712 }
711#endif 713#endif
712 714
713} 715}
714 716
715void KABCore::beamDone( Ir *ir ) 717void KABCore::beamDone( Ir *ir )
716{ 718{
717#ifndef DESKTOP_VERSION 719#ifndef DESKTOP_VERSION
718 delete ir; 720 delete ir;
719#endif 721#endif
720} 722}
721 723
722 724
723void KABCore::browse( const QString& url ) 725void KABCore::browse( const QString& url )
724{ 726{
725#ifndef KAB_EMBEDDED 727#ifndef KAB_EMBEDDED
726 kapp->invokeBrowser( url ); 728 kapp->invokeBrowser( url );
727#else //KAB_EMBEDDED 729#else //KAB_EMBEDDED
728 qDebug("KABCore::browse must be fixed"); 730 qDebug("KABCore::browse must be fixed");
729#endif //KAB_EMBEDDED 731#endif //KAB_EMBEDDED
730} 732}
731 733
732void KABCore::selectAllContacts() 734void KABCore::selectAllContacts()
733{ 735{
734 mViewManager->setSelected( QString::null, true ); 736 mViewManager->setSelected( QString::null, true );
735} 737}
736 738
737void KABCore::deleteContacts() 739void KABCore::deleteContacts()
738{ 740{
739 QStringList uidList = mViewManager->selectedUids(); 741 QStringList uidList = mViewManager->selectedUids();
740 deleteContacts( uidList ); 742 deleteContacts( uidList );
741} 743}
742 744
743void KABCore::deleteContacts( const QStringList &uids ) 745void KABCore::deleteContacts( const QStringList &uids )
744{ 746{
745 if ( uids.count() > 0 ) { 747 if ( uids.count() > 0 ) {
746 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 748 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
747 UndoStack::instance()->push( command ); 749 UndoStack::instance()->push( command );
748 RedoStack::instance()->clear(); 750 RedoStack::instance()->clear();
749 751
750 // now if we deleted anything, refresh 752 // now if we deleted anything, refresh
751 setContactSelected( QString::null ); 753 setContactSelected( QString::null );
752 setModified( true ); 754 setModified( true );
753 } 755 }
754} 756}
755 757
756void KABCore::copyContacts() 758void KABCore::copyContacts()
757{ 759{
758 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 760 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
759 761
760 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 762 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
761 763
762 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 764 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
763 765
764 QClipboard *cb = QApplication::clipboard(); 766 QClipboard *cb = QApplication::clipboard();
765 cb->setText( clipText ); 767 cb->setText( clipText );
766} 768}
767 769
768void KABCore::cutContacts() 770void KABCore::cutContacts()
769{ 771{
770 QStringList uidList = mViewManager->selectedUids(); 772 QStringList uidList = mViewManager->selectedUids();
771 773
772//US if ( uidList.size() > 0 ) { 774//US if ( uidList.size() > 0 ) {
773 if ( uidList.count() > 0 ) { 775 if ( uidList.count() > 0 ) {
774 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 776 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
775 UndoStack::instance()->push( command ); 777 UndoStack::instance()->push( command );
776 RedoStack::instance()->clear(); 778 RedoStack::instance()->clear();
777 779
778 setModified( true ); 780 setModified( true );
779 } 781 }
780} 782}
781 783
782void KABCore::pasteContacts() 784void KABCore::pasteContacts()
783{ 785{
784 QClipboard *cb = QApplication::clipboard(); 786 QClipboard *cb = QApplication::clipboard();
785 787
786 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 788 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
787 789
788 pasteContacts( list ); 790 pasteContacts( list );
789} 791}
790 792
791void KABCore::pasteContacts( KABC::Addressee::List &list ) 793void KABCore::pasteContacts( KABC::Addressee::List &list )
792{ 794{
793 KABC::Resource *resource = requestResource( this ); 795 KABC::Resource *resource = requestResource( this );
794 KABC::Addressee::List::Iterator it; 796 KABC::Addressee::List::Iterator it;
795 for ( it = list.begin(); it != list.end(); ++it ) 797 for ( it = list.begin(); it != list.end(); ++it )
796 (*it).setResource( resource ); 798 (*it).setResource( resource );
797 799
798 PwPasteCommand *command = new PwPasteCommand( this, list ); 800 PwPasteCommand *command = new PwPasteCommand( this, list );
799 UndoStack::instance()->push( command ); 801 UndoStack::instance()->push( command );
800 RedoStack::instance()->clear(); 802 RedoStack::instance()->clear();
801 803
802 setModified( true ); 804 setModified( true );
803} 805}
804 806
805void KABCore::setWhoAmI() 807void KABCore::setWhoAmI()
806{ 808{
807 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 809 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
808 810
809 if ( addrList.count() > 1 ) { 811 if ( addrList.count() > 1 ) {
810 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 812 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
811 return; 813 return;
812 } 814 }
813 815
814 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 816 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
815 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 817 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
816 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 818 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
817} 819}
818 820
819void KABCore::setCategories() 821void KABCore::setCategories()
820{ 822{
821 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 823 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
822 if ( !dlg.exec() ) 824 if ( !dlg.exec() )
823 return; 825 return;
824 826
825 bool merge = false; 827 bool merge = false;
826 QString msg = i18n( "Merge with existing categories?" ); 828 QString msg = i18n( "Merge with existing categories?" );
827 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 829 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
828 merge = true; 830 merge = true;
829 831
830 QStringList categories = dlg.selectedCategories(); 832 QStringList categories = dlg.selectedCategories();
831 833
832 QStringList uids = mViewManager->selectedUids(); 834 QStringList uids = mViewManager->selectedUids();
833 QStringList::Iterator it; 835 QStringList::Iterator it;
834 for ( it = uids.begin(); it != uids.end(); ++it ) { 836 for ( it = uids.begin(); it != uids.end(); ++it ) {
835 KABC::Addressee addr = mAddressBook->findByUid( *it ); 837 KABC::Addressee addr = mAddressBook->findByUid( *it );
836 if ( !addr.isEmpty() ) { 838 if ( !addr.isEmpty() ) {
837 if ( !merge ) 839 if ( !merge )
838 addr.setCategories( categories ); 840 addr.setCategories( categories );
839 else { 841 else {
840 QStringList addrCategories = addr.categories(); 842 QStringList addrCategories = addr.categories();
841 QStringList::Iterator catIt; 843 QStringList::Iterator catIt;
842 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 844 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
843 if ( !addrCategories.contains( *catIt ) ) 845 if ( !addrCategories.contains( *catIt ) )
844 addrCategories.append( *catIt ); 846 addrCategories.append( *catIt );
845 } 847 }
846 addr.setCategories( addrCategories ); 848 addr.setCategories( addrCategories );
847 } 849 }
848 850
849 mAddressBook->insertAddressee( addr ); 851 mAddressBook->insertAddressee( addr );
850 } 852 }
851 } 853 }
852 854
853 if ( uids.count() > 0 ) 855 if ( uids.count() > 0 )
854 setModified( true ); 856 setModified( true );
855} 857}
856 858
857void KABCore::setSearchFields( const KABC::Field::List &fields ) 859void KABCore::setSearchFields( const KABC::Field::List &fields )
858{ 860{
859 mIncSearchWidget->setFields( fields ); 861 mIncSearchWidget->setFields( fields );
860} 862}
861 863
862void KABCore::incrementalSearch( const QString& text ) 864void KABCore::incrementalSearch( const QString& text )
863{ 865{
864 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 866 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
865} 867}
866 868
867void KABCore::setModified() 869void KABCore::setModified()
868{ 870{
869 setModified( true ); 871 setModified( true );
870} 872}
871 873
872void KABCore::setModifiedWOrefresh() 874void KABCore::setModifiedWOrefresh()
873{ 875{
874 // qDebug("KABCore::setModifiedWOrefresh() "); 876 // qDebug("KABCore::setModifiedWOrefresh() ");
875 mModified = true; 877 mModified = true;
876 mActionSave->setEnabled( mModified ); 878 mActionSave->setEnabled( mModified );
877#ifdef DESKTOP_VERSION 879#ifdef DESKTOP_VERSION
878 mDetails->refreshView(); 880 mDetails->refreshView();
879#endif 881#endif
880 882
881} 883}
882void KABCore::setModified( bool modified ) 884void KABCore::setModified( bool modified )
883{ 885{
884 mModified = modified; 886 mModified = modified;
885 mActionSave->setEnabled( mModified ); 887 mActionSave->setEnabled( mModified );
886 888
887 if ( modified ) 889 if ( modified )
888 mJumpButtonBar->recreateButtons(); 890 mJumpButtonBar->recreateButtons();
889 891
890 mViewManager->refreshView(); 892 mViewManager->refreshView();
891 mDetails->refreshView(); 893 mDetails->refreshView();
892 894
893} 895}
894 896
895bool KABCore::modified() const 897bool KABCore::modified() const
896{ 898{
897 return mModified; 899 return mModified;
898} 900}
899 901
900void KABCore::contactModified( const KABC::Addressee &addr ) 902void KABCore::contactModified( const KABC::Addressee &addr )
901{ 903{
902 904
903 Command *command = 0; 905 Command *command = 0;
904 QString uid; 906 QString uid;
905 907
906 // check if it exists already 908 // check if it exists already
907 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 909 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
908 if ( origAddr.isEmpty() ) 910 if ( origAddr.isEmpty() )
909 command = new PwNewCommand( mAddressBook, addr ); 911 command = new PwNewCommand( mAddressBook, addr );
910 else { 912 else {
911 command = new PwEditCommand( mAddressBook, origAddr, addr ); 913 command = new PwEditCommand( mAddressBook, origAddr, addr );
912 uid = addr.uid(); 914 uid = addr.uid();
913 } 915 }
914 916
915 UndoStack::instance()->push( command ); 917 UndoStack::instance()->push( command );
916 RedoStack::instance()->clear(); 918 RedoStack::instance()->clear();
917 919
918 setModified( true ); 920 setModified( true );
919} 921}
920 922
921void KABCore::newContact() 923void KABCore::newContact()
922{ 924{
923 925
924 926
925 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 927 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
926 928
927 QPtrList<KRES::Resource> kresResources; 929 QPtrList<KRES::Resource> kresResources;
928 QPtrListIterator<KABC::Resource> it( kabcResources ); 930 QPtrListIterator<KABC::Resource> it( kabcResources );
929 KABC::Resource *resource; 931 KABC::Resource *resource;
930 while ( ( resource = it.current() ) != 0 ) { 932 while ( ( resource = it.current() ) != 0 ) {
931 ++it; 933 ++it;
932 if ( !resource->readOnly() ) { 934 if ( !resource->readOnly() ) {
933 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 935 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
934 if ( res ) 936 if ( res )
935 kresResources.append( res ); 937 kresResources.append( res );
936 } 938 }
937 } 939 }
938 940
939 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 941 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
940 resource = static_cast<KABC::Resource*>( res ); 942 resource = static_cast<KABC::Resource*>( res );
941 943
942 if ( resource ) { 944 if ( resource ) {
943 KABC::Addressee addr; 945 KABC::Addressee addr;
944 addr.setResource( resource ); 946 addr.setResource( resource );
945 mEditorDialog->setAddressee( addr ); 947 mEditorDialog->setAddressee( addr );
946 KApplication::execDialog ( mEditorDialog ); 948 KApplication::execDialog ( mEditorDialog );
947 949
948 } else 950 } else
949 return; 951 return;
950 952
951 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 953 // mEditorDict.insert( dialog->addressee().uid(), dialog );
952 954
953 955
954} 956}
955 957
956void KABCore::addEmail( QString aStr ) 958void KABCore::addEmail( QString aStr )
957{ 959{
958#ifndef KAB_EMBEDDED 960#ifndef KAB_EMBEDDED
959 QString fullName, email; 961 QString fullName, email;
960 962
961 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 963 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
962 964
963 // Try to lookup the addressee matching the email address 965 // Try to lookup the addressee matching the email address
964 bool found = false; 966 bool found = false;
965 QStringList emailList; 967 QStringList emailList;
966 KABC::AddressBook::Iterator it; 968 KABC::AddressBook::Iterator it;
967 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 969 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
968 emailList = (*it).emails(); 970 emailList = (*it).emails();
969 if ( emailList.contains( email ) > 0 ) { 971 if ( emailList.contains( email ) > 0 ) {
970 found = true; 972 found = true;
971 (*it).setNameFromString( fullName ); 973 (*it).setNameFromString( fullName );
972 editContact( (*it).uid() ); 974 editContact( (*it).uid() );
973 } 975 }
974 } 976 }
975 977
976 if ( !found ) { 978 if ( !found ) {
977 KABC::Addressee addr; 979 KABC::Addressee addr;
978 addr.setNameFromString( fullName ); 980 addr.setNameFromString( fullName );
979 addr.insertEmail( email, true ); 981 addr.insertEmail( email, true );
980 982
981 mAddressBook->insertAddressee( addr ); 983 mAddressBook->insertAddressee( addr );
982 mViewManager->refreshView( addr.uid() ); 984 mViewManager->refreshView( addr.uid() );
983 editContact( addr.uid() ); 985 editContact( addr.uid() );
984 } 986 }
985#else //KAB_EMBEDDED 987#else //KAB_EMBEDDED
986 qDebug("KABCore::addEmail finsih method"); 988 qDebug("KABCore::addEmail finsih method");
987#endif //KAB_EMBEDDED 989#endif //KAB_EMBEDDED
988} 990}
989 991
990void KABCore::importVCard( const KURL &url, bool showPreview ) 992void KABCore::importVCard( const KURL &url, bool showPreview )
991{ 993{
992 mXXPortManager->importVCard( url, showPreview ); 994 mXXPortManager->importVCard( url, showPreview );
993} 995}
994void KABCore::importFromOL() 996void KABCore::importFromOL()
995{ 997{
996#ifdef _WIN32_ 998#ifdef _WIN32_
997 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 999 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
998 idgl->exec(); 1000 idgl->exec();
999 KABC::Addressee::List list = idgl->getAddressList(); 1001 KABC::Addressee::List list = idgl->getAddressList();
1000 if ( list.count() > 0 ) { 1002 if ( list.count() > 0 ) {
1001 KABC::Addressee::List listNew; 1003 KABC::Addressee::List listNew;
1002 KABC::Addressee::List listExisting; 1004 KABC::Addressee::List listExisting;
1003 KABC::Addressee::List::Iterator it; 1005 KABC::Addressee::List::Iterator it;
1004 KABC::AddressBook::Iterator iter; 1006 KABC::AddressBook::Iterator iter;
1005 for ( it = list.begin(); it != list.end(); ++it ) { 1007 for ( it = list.begin(); it != list.end(); ++it ) {
1006 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1008 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1007 listNew.append( (*it) ); 1009 listNew.append( (*it) );
1008 else 1010 else
1009 listExisting.append( (*it) ); 1011 listExisting.append( (*it) );
1010 } 1012 }
1011 if ( listExisting.count() > 0 ) 1013 if ( listExisting.count() > 0 )
1012 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1014 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1013 if ( listNew.count() > 0 ) { 1015 if ( listNew.count() > 0 ) {
1014 pasteWithNewUid = false; 1016 pasteWithNewUid = false;
1015 pasteContacts( listNew ); 1017 pasteContacts( listNew );
1016 pasteWithNewUid = true; 1018 pasteWithNewUid = true;
1017 } 1019 }
1018 } 1020 }
1019 delete idgl; 1021 delete idgl;
1020#endif 1022#endif
1021} 1023}
1022 1024
1023void KABCore::importVCard( const QString &vCard, bool showPreview ) 1025void KABCore::importVCard( const QString &vCard, bool showPreview )
1024{ 1026{
1025 mXXPortManager->importVCard( vCard, showPreview ); 1027 mXXPortManager->importVCard( vCard, showPreview );
1026} 1028}
1027 1029
1028//US added a second method without defaultparameter 1030//US added a second method without defaultparameter
1029void KABCore::editContact2() { 1031void KABCore::editContact2() {
1030 editContact( QString::null ); 1032 editContact( QString::null );
1031} 1033}
1032 1034
1033void KABCore::editContact( const QString &uid ) 1035void KABCore::editContact( const QString &uid )
1034{ 1036{
1035 1037
1036 if ( mExtensionManager->isQuickEditVisible() ) 1038 if ( mExtensionManager->isQuickEditVisible() )
1037 return; 1039 return;
1038 1040
1039 // First, locate the contact entry 1041 // First, locate the contact entry
1040 QString localUID = uid; 1042 QString localUID = uid;
1041 if ( localUID.isNull() ) { 1043 if ( localUID.isNull() ) {
1042 QStringList uidList = mViewManager->selectedUids(); 1044 QStringList uidList = mViewManager->selectedUids();
1043 if ( uidList.count() > 0 ) 1045 if ( uidList.count() > 0 )
1044 localUID = *( uidList.at( 0 ) ); 1046 localUID = *( uidList.at( 0 ) );
1045 } 1047 }
1046 1048
1047 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1049 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1048 if ( !addr.isEmpty() ) { 1050 if ( !addr.isEmpty() ) {
1049 mEditorDialog->setAddressee( addr ); 1051 mEditorDialog->setAddressee( addr );
1050 KApplication::execDialog ( mEditorDialog ); 1052 KApplication::execDialog ( mEditorDialog );
1051 } 1053 }
1052} 1054}
1053 1055
1054/** 1056/**
1055 Shows or edits the detail view for the given uid. If the uid is QString::null, 1057 Shows or edits the detail view for the given uid. If the uid is QString::null,
1056 the method will try to find a selected addressee in the view. 1058 the method will try to find a selected addressee in the view.
1057 */ 1059 */
1058void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1060void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1059{ 1061{
1060 if ( mMultipleViewsAtOnce ) 1062 if ( mMultipleViewsAtOnce )
1061 { 1063 {
1062 editContact( uid ); 1064 editContact( uid );
1063 } 1065 }
1064 else 1066 else
1065 { 1067 {
1066 setDetailsVisible( true ); 1068 setDetailsVisible( true );
1067 mActionDetails->setChecked(true); 1069 mActionDetails->setChecked(true);
1068 } 1070 }
1069 1071
1070} 1072}
1071 1073
1072void KABCore::save() 1074void KABCore::save()
1073{ 1075{
1074 if (mBlockSaveFlag) 1076 if (mBlockSaveFlag)
1075 return; 1077 return;
1076 mBlockSaveFlag = true; 1078 mBlockSaveFlag = true;
1077 if ( !mModified ) 1079 if ( !mModified )
1078 return; 1080 return;
1079 QString text = i18n( "There was an error while attempting to save\n the " 1081 QString text = i18n( "There was an error while attempting to save\n the "
1080 "address book. Please check that some \nother application is " 1082 "address book. Please check that some \nother application is "
1081 "not using it. " ); 1083 "not using it. " );
1082 statusMessage(i18n("Saving addressbook ... ")); 1084 statusMessage(i18n("Saving addressbook ... "));
1083#ifndef KAB_EMBEDDED 1085#ifndef KAB_EMBEDDED
1084 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1086 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1085 if ( !b || !b->save() ) { 1087 if ( !b || !b->save() ) {
1086 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1088 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1087 } 1089 }
1088#else //KAB_EMBEDDED 1090#else //KAB_EMBEDDED
1089 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1091 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1090 if ( !b || !b->save() ) { 1092 if ( !b || !b->save() ) {
1091 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1093 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1092 } 1094 }
1093#endif //KAB_EMBEDDED 1095#endif //KAB_EMBEDDED
1094 1096
1095 statusMessage(i18n("Addressbook saved!")); 1097 statusMessage(i18n("Addressbook saved!"));
1096 setModified( false ); 1098 setModified( false );
1097 mBlockSaveFlag = false; 1099 mBlockSaveFlag = false;
1098} 1100}
1099 1101
1100void KABCore::statusMessage(QString mess , int time ) 1102void KABCore::statusMessage(QString mess , int time )
1101{ 1103{
1102 //topLevelWidget()->setCaption( mess ); 1104 //topLevelWidget()->setCaption( mess );
1103 // pending setting timer to revome message 1105 // pending setting timer to revome message
1104} 1106}
1105void KABCore::undo() 1107void KABCore::undo()
1106{ 1108{
1107 UndoStack::instance()->undo(); 1109 UndoStack::instance()->undo();
1108 1110
1109 // Refresh the view 1111 // Refresh the view
1110 mViewManager->refreshView(); 1112 mViewManager->refreshView();
1111} 1113}
1112 1114
1113void KABCore::redo() 1115void KABCore::redo()
1114{ 1116{
1115 RedoStack::instance()->redo(); 1117 RedoStack::instance()->redo();
1116 1118
1117 // Refresh the view 1119 // Refresh the view
1118 mViewManager->refreshView(); 1120 mViewManager->refreshView();
1119} 1121}
1120 1122
1121void KABCore::setJumpButtonBarVisible( bool visible ) 1123void KABCore::setJumpButtonBarVisible( bool visible )
1122{ 1124{
1123 if (mMultipleViewsAtOnce) 1125 if (mMultipleViewsAtOnce)
1124 { 1126 {
1125 if ( visible ) 1127 if ( visible )
1126 mJumpButtonBar->show(); 1128 mJumpButtonBar->show();
1127 else 1129 else
1128 mJumpButtonBar->hide(); 1130 mJumpButtonBar->hide();
1129 } 1131 }
1130 else 1132 else
1131 { 1133 {
1132 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1134 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1133 if (mViewManager->isVisible()) 1135 if (mViewManager->isVisible())
1134 { 1136 {
1135 if ( visible ) 1137 if ( visible )
1136 mJumpButtonBar->show(); 1138 mJumpButtonBar->show();
1137 else 1139 else
1138 mJumpButtonBar->hide(); 1140 mJumpButtonBar->hide();
1139 } 1141 }
1140 else 1142 else
1141 { 1143 {
1142 mJumpButtonBar->hide(); 1144 mJumpButtonBar->hide();
1143 } 1145 }
1144 } 1146 }
1145} 1147}
1146 1148
1147 1149
1148void KABCore::setDetailsToState() 1150void KABCore::setDetailsToState()
1149{ 1151{
1150 setDetailsVisible( mActionDetails->isChecked() ); 1152 setDetailsVisible( mActionDetails->isChecked() );
1151} 1153}
1152 1154
1153 1155
1154 1156
1155void KABCore::setDetailsVisible( bool visible ) 1157void KABCore::setDetailsVisible( bool visible )
1156{ 1158{
1157 if (visible && mDetails->isHidden()) 1159 if (visible && mDetails->isHidden())
1158 { 1160 {
1159 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1161 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1160 if ( addrList.count() > 0 ) 1162 if ( addrList.count() > 0 )
1161 mDetails->setAddressee( addrList[ 0 ] ); 1163 mDetails->setAddressee( addrList[ 0 ] );
1162 } 1164 }
1163 1165
1164 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1166 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1165 // the listview and the detailview. We do that by changing the splitbar size. 1167 // the listview and the detailview. We do that by changing the splitbar size.
1166 if (mMultipleViewsAtOnce) 1168 if (mMultipleViewsAtOnce)
1167 { 1169 {
1168 if ( visible ) 1170 if ( visible )
1169 mDetails->show(); 1171 mDetails->show();
1170 else 1172 else
1171 mDetails->hide(); 1173 mDetails->hide();
1172 } 1174 }
1173 else 1175 else
1174 { 1176 {
1175 if ( visible ) { 1177 if ( visible ) {
1176 mViewManager->hide(); 1178 mViewManager->hide();
1177 mDetails->show(); 1179 mDetails->show();
1178 } 1180 }
1179 else { 1181 else {
1180 mViewManager->show(); 1182 mViewManager->show();
1181 mDetails->hide(); 1183 mDetails->hide();
1182 } 1184 }
1183 setJumpButtonBarVisible( !visible ); 1185 setJumpButtonBarVisible( !visible );
1184 } 1186 }
1185 1187
1186} 1188}
1187 1189
1188void KABCore::extensionChanged( int id ) 1190void KABCore::extensionChanged( int id )
1189{ 1191{
1190 //change the details view only for non desktop systems 1192 //change the details view only for non desktop systems
1191#ifndef DESKTOP_VERSION 1193#ifndef DESKTOP_VERSION
1192 1194
1193 if (id == 0) 1195 if (id == 0)
1194 { 1196 {
1195 //the user disabled the extension. 1197 //the user disabled the extension.
1196 1198
1197 if (mMultipleViewsAtOnce) 1199 if (mMultipleViewsAtOnce)
1198 { // enable detailsview again 1200 { // enable detailsview again
1199 setDetailsVisible( true ); 1201 setDetailsVisible( true );
1200 mActionDetails->setChecked( true ); 1202 mActionDetails->setChecked( true );
1201 } 1203 }
1202 else 1204 else
1203 { //go back to the listview 1205 { //go back to the listview
1204 setDetailsVisible( false ); 1206 setDetailsVisible( false );
1205 mActionDetails->setChecked( false ); 1207 mActionDetails->setChecked( false );
1206 mActionDetails->setEnabled(true); 1208 mActionDetails->setEnabled(true);
1207 } 1209 }
1208 1210
1209 } 1211 }
1210 else 1212 else
1211 { 1213 {
1212 //the user enabled the extension. 1214 //the user enabled the extension.
1213 setDetailsVisible( false ); 1215 setDetailsVisible( false );
1214 mActionDetails->setChecked( false ); 1216 mActionDetails->setChecked( false );
1215 1217
1216 if (!mMultipleViewsAtOnce) 1218 if (!mMultipleViewsAtOnce)
1217 { 1219 {
1218 mActionDetails->setEnabled(false); 1220 mActionDetails->setEnabled(false);
1219 } 1221 }
1220 1222
1221 mExtensionManager->setSelectionChanged(); 1223 mExtensionManager->setSelectionChanged();
1222 1224
1223 } 1225 }
1224 1226
1225#endif// DESKTOP_VERSION 1227#endif// DESKTOP_VERSION
1226 1228
1227} 1229}
1228 1230
1229 1231
1230void KABCore::extensionModified( const KABC::Addressee::List &list ) 1232void KABCore::extensionModified( const KABC::Addressee::List &list )
1231{ 1233{
1232 1234
1233 if ( list.count() != 0 ) { 1235 if ( list.count() != 0 ) {
1234 KABC::Addressee::List::ConstIterator it; 1236 KABC::Addressee::List::ConstIterator it;
1235 for ( it = list.begin(); it != list.end(); ++it ) 1237 for ( it = list.begin(); it != list.end(); ++it )
1236 mAddressBook->insertAddressee( *it ); 1238 mAddressBook->insertAddressee( *it );
1237 if ( list.count() > 1 ) 1239 if ( list.count() > 1 )
1238 setModified(); 1240 setModified();
1239 else 1241 else
1240 setModifiedWOrefresh(); 1242 setModifiedWOrefresh();
1241 } 1243 }
1242 if ( list.count() == 0 ) 1244 if ( list.count() == 0 )
1243 mViewManager->refreshView(); 1245 mViewManager->refreshView();
1244 else 1246 else
1245 mViewManager->refreshView( list[ 0 ].uid() ); 1247 mViewManager->refreshView( list[ 0 ].uid() );
1246 1248
1247 1249
1248 1250
1249} 1251}
1250 1252
1251QString KABCore::getNameByPhone( const QString &phone ) 1253QString KABCore::getNameByPhone( const QString &phone )
1252{ 1254{
1253#ifndef KAB_EMBEDDED 1255#ifndef KAB_EMBEDDED
1254 QRegExp r( "[/*/-/ ]" ); 1256 QRegExp r( "[/*/-/ ]" );
1255 QString localPhone( phone ); 1257 QString localPhone( phone );
1256 1258
1257 bool found = false; 1259 bool found = false;
1258 QString ownerName = ""; 1260 QString ownerName = "";
1259 KABC::AddressBook::Iterator iter; 1261 KABC::AddressBook::Iterator iter;
1260 KABC::PhoneNumber::List::Iterator phoneIter; 1262 KABC::PhoneNumber::List::Iterator phoneIter;
1261 KABC::PhoneNumber::List phoneList; 1263 KABC::PhoneNumber::List phoneList;
1262 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1264 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1263 phoneList = (*iter).phoneNumbers(); 1265 phoneList = (*iter).phoneNumbers();
1264 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1266 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1265 ++phoneIter) { 1267 ++phoneIter) {
1266 // Get rid of separator chars so just the numbers are compared. 1268 // Get rid of separator chars so just the numbers are compared.
1267 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1269 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1268 ownerName = (*iter).formattedName(); 1270 ownerName = (*iter).formattedName();
1269 found = true; 1271 found = true;
1270 } 1272 }
1271 } 1273 }
1272 } 1274 }
1273 1275
1274 return ownerName; 1276 return ownerName;
1275#else //KAB_EMBEDDED 1277#else //KAB_EMBEDDED
1276 qDebug("KABCore::getNameByPhone finsih method"); 1278 qDebug("KABCore::getNameByPhone finsih method");
1277 return ""; 1279 return "";
1278#endif //KAB_EMBEDDED 1280#endif //KAB_EMBEDDED
1279 1281
1280} 1282}
1281 1283
1282void KABCore::openConfigDialog() 1284void KABCore::openConfigDialog()
1283{ 1285{
1284 KABPrefs* kab_prefs = KABPrefs::instance(); 1286 KABPrefs* kab_prefs = KABPrefs::instance();
1285 KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance(); 1287 KPimGlobalPrefs* kpim_prefs = KPimGlobalPrefs::instance();
1286 1288
1287 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1289 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1288 KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1290 KCMKabConfig* kabcfg = new KCMKabConfig( kab_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1289 ConfigureDialog->addModule(kabcfg ); 1291 ConfigureDialog->addModule(kabcfg );
1290 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1292 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( kpim_prefs, ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1291 ConfigureDialog->addModule(kdelibcfg ); 1293 ConfigureDialog->addModule(kdelibcfg );
1292 1294
1293 1295
1294 1296
1295 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1297 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1296 this, SLOT( configurationChanged() ) ); 1298 this, SLOT( configurationChanged() ) );
1297 connect( ConfigureDialog, SIGNAL( okClicked() ), 1299 connect( ConfigureDialog, SIGNAL( okClicked() ),
1298 this, SLOT( configurationChanged() ) ); 1300 this, SLOT( configurationChanged() ) );
1299 saveSettings(); 1301 saveSettings();
1300#ifndef DESKTOP_VERSION 1302#ifndef DESKTOP_VERSION
1301 ConfigureDialog->showMaximized(); 1303 ConfigureDialog->showMaximized();
1302#endif 1304#endif
1303 if ( ConfigureDialog->exec() ) 1305 if ( ConfigureDialog->exec() )
1304 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1306 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1305 delete ConfigureDialog; 1307 delete ConfigureDialog;
1306} 1308}
1307 1309
1308void KABCore::openLDAPDialog() 1310void KABCore::openLDAPDialog()
1309{ 1311{
1310#ifndef KAB_EMBEDDED 1312#ifndef KAB_EMBEDDED
1311 if ( !mLdapSearchDialog ) { 1313 if ( !mLdapSearchDialog ) {
1312 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1314 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1313 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1315 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1314 SLOT( refreshView() ) ); 1316 SLOT( refreshView() ) );
1315 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1317 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1316 SLOT( setModified() ) ); 1318 SLOT( setModified() ) );
1317 } else 1319 } else
1318 mLdapSearchDialog->restoreSettings(); 1320 mLdapSearchDialog->restoreSettings();
1319 1321
1320 if ( mLdapSearchDialog->isOK() ) 1322 if ( mLdapSearchDialog->isOK() )
1321 mLdapSearchDialog->exec(); 1323 mLdapSearchDialog->exec();
1322#else //KAB_EMBEDDED 1324#else //KAB_EMBEDDED
1323 qDebug("KABCore::openLDAPDialog() finsih method"); 1325 qDebug("KABCore::openLDAPDialog() finsih method");
1324#endif //KAB_EMBEDDED 1326#endif //KAB_EMBEDDED
1325} 1327}
1326 1328
1327void KABCore::print() 1329void KABCore::print()
1328{ 1330{
1329#ifndef KAB_EMBEDDED 1331#ifndef KAB_EMBEDDED
1330 KPrinter printer; 1332 KPrinter printer;
1331 if ( !printer.setup( this ) ) 1333 if ( !printer.setup( this ) )
1332 return; 1334 return;
1333 1335
1334 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1336 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1335 mViewManager->selectedUids(), this ); 1337 mViewManager->selectedUids(), this );
1336 1338
1337 wizard.exec(); 1339 wizard.exec();
1338#else //KAB_EMBEDDED 1340#else //KAB_EMBEDDED
1339 qDebug("KABCore::print() finsih method"); 1341 qDebug("KABCore::print() finsih method");
1340#endif //KAB_EMBEDDED 1342#endif //KAB_EMBEDDED
1341 1343
1342} 1344}
1343 1345
1344 1346
1345void KABCore::addGUIClient( KXMLGUIClient *client ) 1347void KABCore::addGUIClient( KXMLGUIClient *client )
1346{ 1348{
1347 if ( mGUIClient ) 1349 if ( mGUIClient )
1348 mGUIClient->insertChildClient( client ); 1350 mGUIClient->insertChildClient( client );
1349 else 1351 else
1350 KMessageBox::error( this, "no KXMLGUICLient"); 1352 KMessageBox::error( this, "no KXMLGUICLient");
1351} 1353}
1352 1354
1353 1355
1354void KABCore::configurationChanged() 1356void KABCore::configurationChanged()
1355{ 1357{
1356 mExtensionManager->reconfigure(); 1358 mExtensionManager->reconfigure();
1357} 1359}
1358 1360
1359void KABCore::addressBookChanged() 1361void KABCore::addressBookChanged()
1360{ 1362{
1361/*US 1363/*US
1362 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1364 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1363 while ( it.current() ) { 1365 while ( it.current() ) {
1364 if ( it.current()->dirty() ) { 1366 if ( it.current()->dirty() ) {
1365 QString text = i18n( "Data has been changed externally. Unsaved " 1367 QString text = i18n( "Data has been changed externally. Unsaved "
1366 "changes will be lost." ); 1368 "changes will be lost." );
1367 KMessageBox::information( this, text ); 1369 KMessageBox::information( this, text );
1368 } 1370 }
1369 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1371 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1370 ++it; 1372 ++it;
1371 } 1373 }
1372*/ 1374*/
1373 if (mEditorDialog) 1375 if (mEditorDialog)
1374 { 1376 {
1375 if (mEditorDialog->dirty()) 1377 if (mEditorDialog->dirty())
1376 { 1378 {
1377 QString text = i18n( "Data has been changed externally. Unsaved " 1379 QString text = i18n( "Data has been changed externally. Unsaved "
1378 "changes will be lost." ); 1380 "changes will be lost." );
1379 KMessageBox::information( this, text ); 1381 KMessageBox::information( this, text );
1380 } 1382 }
1381 QString currentuid = mEditorDialog->addressee().uid(); 1383 QString currentuid = mEditorDialog->addressee().uid();
1382 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1384 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1383 } 1385 }
1384 mViewManager->refreshView(); 1386 mViewManager->refreshView();
1385// mDetails->refreshView(); 1387// mDetails->refreshView();
1386 1388
1387 1389
1388} 1390}
1389 1391
1390AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1392AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1391 const char *name ) 1393 const char *name )
1392{ 1394{
1393 1395
1394 if ( mEditorDialog == 0 ) { 1396 if ( mEditorDialog == 0 ) {
1395 mEditorDialog = new AddresseeEditorDialog( this, parent, 1397 mEditorDialog = new AddresseeEditorDialog( this, parent,
1396 name ? name : "editorDialog" ); 1398 name ? name : "editorDialog" );
1397 1399
1398 1400
1399 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1401 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1400 SLOT( contactModified( const KABC::Addressee& ) ) ); 1402 SLOT( contactModified( const KABC::Addressee& ) ) );
1401 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1403 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1402 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1404 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1403 } 1405 }
1404 1406
1405 return mEditorDialog; 1407 return mEditorDialog;
1406} 1408}
1407 1409
1408void KABCore::slotEditorDestroyed( const QString &uid ) 1410void KABCore::slotEditorDestroyed( const QString &uid )
1409{ 1411{
1410 //mEditorDict.remove( uid ); 1412 //mEditorDict.remove( uid );
1411} 1413}
1412 1414
1413void KABCore::initGUI() 1415void KABCore::initGUI()
1414{ 1416{
1415#ifndef KAB_EMBEDDED 1417#ifndef KAB_EMBEDDED
1416 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1418 QHBoxLayout *topLayout = new QHBoxLayout( this );
1417 topLayout->setSpacing( KDialogBase::spacingHint() ); 1419 topLayout->setSpacing( KDialogBase::spacingHint() );
1418 1420
1419 mExtensionBarSplitter = new QSplitter( this ); 1421 mExtensionBarSplitter = new QSplitter( this );
1420 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1422 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1421 1423
1422 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1424 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1423 1425
1424 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1426 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1425 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1427 mIncSearchWidget = new IncSearchWidget( viewSpace );
1426 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1428 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1427 SLOT( incrementalSearch( const QString& ) ) ); 1429 SLOT( incrementalSearch( const QString& ) ) );
1428 1430
1429 mViewManager = new ViewManager( this, viewSpace ); 1431 mViewManager = new ViewManager( this, viewSpace );
1430 viewSpace->setStretchFactor( mViewManager, 1 ); 1432 viewSpace->setStretchFactor( mViewManager, 1 );
1431 1433
1432 mDetails = new ViewContainer( mDetailsSplitter ); 1434 mDetails = new ViewContainer( mDetailsSplitter );
1433 1435
1434 mJumpButtonBar = new JumpButtonBar( this, this ); 1436 mJumpButtonBar = new JumpButtonBar( this, this );
1435 1437
1436 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1438 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1437 1439
1438 topLayout->addWidget( mExtensionBarSplitter ); 1440 topLayout->addWidget( mExtensionBarSplitter );
1439 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1441 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1440 topLayout->addWidget( mJumpButtonBar ); 1442 topLayout->addWidget( mJumpButtonBar );
1441 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1443 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1442 1444
1443 mXXPortManager = new XXPortManager( this, this ); 1445 mXXPortManager = new XXPortManager( this, this );
1444 1446
1445#else //KAB_EMBEDDED 1447#else //KAB_EMBEDDED
1446 //US initialize viewMenu before settingup viewmanager. 1448 //US initialize viewMenu before settingup viewmanager.
1447 // Viewmanager needs this menu to plugin submenues. 1449 // Viewmanager needs this menu to plugin submenues.
1448 viewMenu = new QPopupMenu( this ); 1450 viewMenu = new QPopupMenu( this );
1449 settingsMenu = new QPopupMenu( this ); 1451 settingsMenu = new QPopupMenu( this );
1450 //filterMenu = new QPopupMenu( this ); 1452 //filterMenu = new QPopupMenu( this );
1451 ImportMenu = new QPopupMenu( this ); 1453 ImportMenu = new QPopupMenu( this );
1452 ExportMenu = new QPopupMenu( this ); 1454 ExportMenu = new QPopupMenu( this );
1453 syncMenu = new QPopupMenu( this ); 1455 syncMenu = new QPopupMenu( this );
1454 changeMenu= new QPopupMenu( this ); 1456 changeMenu= new QPopupMenu( this );
1455 1457
1456//US since we have no splitter for the embedded system, setup 1458//US since we have no splitter for the embedded system, setup
1457// a layout with two frames. One left and one right. 1459// a layout with two frames. One left and one right.
1458 1460
1459 QBoxLayout *topLayout; 1461 QBoxLayout *topLayout;
1460 1462
1461 // = new QHBoxLayout( this ); 1463 // = new QHBoxLayout( this );
1462// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1464// QBoxLayout *topLayout = (QBoxLayout*)layout();
1463 1465
1464// QWidget *mainBox = new QWidget( this ); 1466// QWidget *mainBox = new QWidget( this );
1465// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1467// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1466 1468
1467#ifdef DESKTOP_VERSION 1469#ifdef DESKTOP_VERSION
1468 topLayout = new QHBoxLayout( this ); 1470 topLayout = new QHBoxLayout( this );
1469 1471
1470 1472
1471 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1473 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1472 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1474 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1473 1475
1474 topLayout->addWidget(mMiniSplitter ); 1476 topLayout->addWidget(mMiniSplitter );
1475 1477
1476 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1478 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1477 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1479 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1478 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1480 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1479 mDetails = new ViewContainer( mMiniSplitter ); 1481 mDetails = new ViewContainer( mMiniSplitter );
1480 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1482 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1481#else 1483#else
1482 if ( QApplication::desktop()->width() > 480 ) { 1484 if ( QApplication::desktop()->width() > 480 ) {
1483 topLayout = new QHBoxLayout( this ); 1485 topLayout = new QHBoxLayout( this );
1484 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1486 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1485 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1487 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1486 } else { 1488 } else {
1487 1489
1488 topLayout = new QHBoxLayout( this ); 1490 topLayout = new QHBoxLayout( this );
1489 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1491 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1490 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1492 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1491 } 1493 }
1492 1494
1493 topLayout->addWidget(mMiniSplitter ); 1495 topLayout->addWidget(mMiniSplitter );
1494 mViewManager = new ViewManager( this, mMiniSplitter ); 1496 mViewManager = new ViewManager( this, mMiniSplitter );
1495 mDetails = new ViewContainer( mMiniSplitter ); 1497 mDetails = new ViewContainer( mMiniSplitter );
1496 1498
1497 1499
1498 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1500 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1499#endif 1501#endif
1500 //eh->hide(); 1502 //eh->hide();
1501 // topLayout->addWidget(mExtensionManager ); 1503 // topLayout->addWidget(mExtensionManager );
1502 1504
1503 1505
1504/*US 1506/*US
1505#ifndef KAB_NOSPLITTER 1507#ifndef KAB_NOSPLITTER
1506 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1508 QHBoxLayout *topLayout = new QHBoxLayout( this );
1507//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1509//US topLayout->setSpacing( KDialogBase::spacingHint() );
1508 topLayout->setSpacing( 10 ); 1510 topLayout->setSpacing( 10 );
1509 1511
1510 mDetailsSplitter = new QSplitter( this ); 1512 mDetailsSplitter = new QSplitter( this );
1511 1513
1512 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1514 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1513 1515
1514 mViewManager = new ViewManager( this, viewSpace ); 1516 mViewManager = new ViewManager( this, viewSpace );
1515 viewSpace->setStretchFactor( mViewManager, 1 ); 1517 viewSpace->setStretchFactor( mViewManager, 1 );
1516 1518
1517 mDetails = new ViewContainer( mDetailsSplitter ); 1519 mDetails = new ViewContainer( mDetailsSplitter );
1518 1520
1519 topLayout->addWidget( mDetailsSplitter ); 1521 topLayout->addWidget( mDetailsSplitter );
1520 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1522 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1521#else //KAB_NOSPLITTER 1523#else //KAB_NOSPLITTER
1522 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1524 QHBoxLayout *topLayout = new QHBoxLayout( this );
1523//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1525//US topLayout->setSpacing( KDialogBase::spacingHint() );
1524 topLayout->setSpacing( 10 ); 1526 topLayout->setSpacing( 10 );
1525 1527
1526// mDetailsSplitter = new QSplitter( this ); 1528// mDetailsSplitter = new QSplitter( this );
1527 1529
1528 QVBox *viewSpace = new QVBox( this ); 1530 QVBox *viewSpace = new QVBox( this );
1529 1531
1530 mViewManager = new ViewManager( this, viewSpace ); 1532 mViewManager = new ViewManager( this, viewSpace );
1531 viewSpace->setStretchFactor( mViewManager, 1 ); 1533 viewSpace->setStretchFactor( mViewManager, 1 );
1532 1534
1533 mDetails = new ViewContainer( this ); 1535 mDetails = new ViewContainer( this );
1534 1536
1535 topLayout->addWidget( viewSpace ); 1537 topLayout->addWidget( viewSpace );
1536// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1538// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1537 topLayout->addWidget( mDetails ); 1539 topLayout->addWidget( mDetails );
1538#endif //KAB_NOSPLITTER 1540#endif //KAB_NOSPLITTER
1539*/ 1541*/
1540 1542
1541 1543
1542#endif //KAB_EMBEDDED 1544#endif //KAB_EMBEDDED
1543 initActions(); 1545 initActions();
1544 1546
1545#ifdef KAB_EMBEDDED 1547#ifdef KAB_EMBEDDED
1546 addActionsManually(); 1548 addActionsManually();
1547 //US make sure the export and import menues are initialized before creating the xxPortManager. 1549 //US make sure the export and import menues are initialized before creating the xxPortManager.
1548 mXXPortManager = new XXPortManager( this, this ); 1550 mXXPortManager = new XXPortManager( this, this );
1549 1551
1550 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1552 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1551 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1553 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1552 // mActionQuit->plug ( mMainWindow->toolBar()); 1554 // mActionQuit->plug ( mMainWindow->toolBar());
1553 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1555 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1554 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1556 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1555 // mIncSearchWidget->hide(); 1557 // mIncSearchWidget->hide();
1556 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1558 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1557 SLOT( incrementalSearch( const QString& ) ) ); 1559 SLOT( incrementalSearch( const QString& ) ) );
1558 1560
1559 1561
1560 mJumpButtonBar = new JumpButtonBar( this, this ); 1562 mJumpButtonBar = new JumpButtonBar( this, this );
1561 1563
1562 topLayout->addWidget( mJumpButtonBar ); 1564 topLayout->addWidget( mJumpButtonBar );
1563//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1565//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1564 1566
1565// mMainWindow->getIconToolBar()->raise(); 1567// mMainWindow->getIconToolBar()->raise();
1566 1568
1567#endif //KAB_EMBEDDED 1569#endif //KAB_EMBEDDED
1568 1570
1569} 1571}
1570void KABCore::initActions() 1572void KABCore::initActions()
1571{ 1573{
1572//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1574//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1573 1575
1574#ifndef KAB_EMBEDDED 1576#ifndef KAB_EMBEDDED
1575 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1577 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1576 SLOT( clipboardDataChanged() ) ); 1578 SLOT( clipboardDataChanged() ) );
1577#endif //KAB_EMBEDDED 1579#endif //KAB_EMBEDDED
1578 1580
1579 // file menu 1581 // file menu
1580 if ( mIsPart ) { 1582 if ( mIsPart ) {
1581 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1583 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1582 SLOT( sendMail() ), actionCollection(), 1584 SLOT( sendMail() ), actionCollection(),
1583 "kaddressbook_mail" ); 1585 "kaddressbook_mail" );
1584 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1586 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1585 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1587 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1586 1588
1587 } else { 1589 } else {
1588 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1590 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1589 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1591 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1590 } 1592 }
1591 1593
1592 1594
1593 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1595 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1594 SLOT( save() ), actionCollection(), "file_sync" ); 1596 SLOT( save() ), actionCollection(), "file_sync" );
1595 1597
1596 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1598 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1597 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1599 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1598 1600
1599 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1601 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1600 this, SLOT( mailVCard() ), 1602 this, SLOT( mailVCard() ),
1601 actionCollection(), "file_mail_vcard"); 1603 actionCollection(), "file_mail_vcard");
1602 1604
1603 mActionBeamVCard = 0; 1605 mActionBeamVCard = 0;
1604 mActionBeam = 0; 1606 mActionBeam = 0;
1605 1607
1606#ifndef DESKTOP_VERSION 1608#ifndef DESKTOP_VERSION
1607 if ( Ir::supported() ) { 1609 if ( Ir::supported() ) {
1608 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1610 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1609 SLOT( beamVCard() ), actionCollection(), 1611 SLOT( beamVCard() ), actionCollection(),
1610 "kaddressbook_beam_vcard" ); 1612 "kaddressbook_beam_vcard" );
1611 1613
1612 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1614 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1613 SLOT( beamMySelf() ), actionCollection(), 1615 SLOT( beamMySelf() ), actionCollection(),
1614 "kaddressbook_beam_myself" ); 1616 "kaddressbook_beam_myself" );
1615 } 1617 }
1616#endif 1618#endif
1617 1619
1618 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1620 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1619 this, SLOT( editContact2() ), 1621 this, SLOT( editContact2() ),
1620 actionCollection(), "file_properties" ); 1622 actionCollection(), "file_properties" );
1621 1623
1622#ifdef KAB_EMBEDDED 1624#ifdef KAB_EMBEDDED
1623 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1625 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1624 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1626 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1625 mMainWindow, SLOT( exit() ), 1627 mMainWindow, SLOT( exit() ),
1626 actionCollection(), "quit" ); 1628 actionCollection(), "quit" );
1627#endif //KAB_EMBEDDED 1629#endif //KAB_EMBEDDED
1628 1630
1629 // edit menu 1631 // edit menu
1630 if ( mIsPart ) { 1632 if ( mIsPart ) {
1631 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1633 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1632 SLOT( copyContacts() ), actionCollection(), 1634 SLOT( copyContacts() ), actionCollection(),
1633 "kaddressbook_copy" ); 1635 "kaddressbook_copy" );
1634 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1636 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1635 SLOT( cutContacts() ), actionCollection(), 1637 SLOT( cutContacts() ), actionCollection(),
1636 "kaddressbook_cut" ); 1638 "kaddressbook_cut" );
1637 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1639 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1638 SLOT( pasteContacts() ), actionCollection(), 1640 SLOT( pasteContacts() ), actionCollection(),
1639 "kaddressbook_paste" ); 1641 "kaddressbook_paste" );
1640 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1642 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1641 SLOT( selectAllContacts() ), actionCollection(), 1643 SLOT( selectAllContacts() ), actionCollection(),
1642 "kaddressbook_select_all" ); 1644 "kaddressbook_select_all" );
1643 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1645 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1644 SLOT( undo() ), actionCollection(), 1646 SLOT( undo() ), actionCollection(),
1645 "kaddressbook_undo" ); 1647 "kaddressbook_undo" );
1646 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1648 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1647 this, SLOT( redo() ), actionCollection(), 1649 this, SLOT( redo() ), actionCollection(),
1648 "kaddressbook_redo" ); 1650 "kaddressbook_redo" );
1649 } else { 1651 } else {
1650 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1652 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1651 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1653 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1652 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1654 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1653 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1655 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1654 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1656 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1655 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1657 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1656 } 1658 }
1657 1659
1658 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1660 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1659 Key_Delete, this, SLOT( deleteContacts() ), 1661 Key_Delete, this, SLOT( deleteContacts() ),
1660 actionCollection(), "edit_delete" ); 1662 actionCollection(), "edit_delete" );
1661 1663
1662 mActionUndo->setEnabled( false ); 1664 mActionUndo->setEnabled( false );
1663 mActionRedo->setEnabled( false ); 1665 mActionRedo->setEnabled( false );
1664 1666
1665 // settings menu 1667 // settings menu
1666#ifdef KAB_EMBEDDED 1668#ifdef KAB_EMBEDDED
1667//US special menuentry to configure the addressbook resources. On KDE 1669//US special menuentry to configure the addressbook resources. On KDE
1668// you do that through the control center !!! 1670// you do that through the control center !!!
1669 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1671 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1670 SLOT( configureResources() ), actionCollection(), 1672 SLOT( configureResources() ), actionCollection(),
1671 "kaddressbook_configure_resources" ); 1673 "kaddressbook_configure_resources" );
1672#endif //KAB_EMBEDDED 1674#endif //KAB_EMBEDDED
1673 1675
1674 if ( mIsPart ) { 1676 if ( mIsPart ) {
1675 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1677 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1676 SLOT( openConfigDialog() ), actionCollection(), 1678 SLOT( openConfigDialog() ), actionCollection(),
1677 "kaddressbook_configure" ); 1679 "kaddressbook_configure" );
1678 1680
1679 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1681 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1680 this, SLOT( configureKeyBindings() ), actionCollection(), 1682 this, SLOT( configureKeyBindings() ), actionCollection(),
1681 "kaddressbook_configure_shortcuts" ); 1683 "kaddressbook_configure_shortcuts" );
1682#ifdef KAB_EMBEDDED 1684#ifdef KAB_EMBEDDED
1683 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1685 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1684 mActionConfigureToolbars->setEnabled( false ); 1686 mActionConfigureToolbars->setEnabled( false );
1685#endif //KAB_EMBEDDED 1687#endif //KAB_EMBEDDED
1686 1688
1687 } else { 1689 } else {
1688 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1690 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1689 1691
1690 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1692 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1691 } 1693 }
1692 1694
1693 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1695 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1694 actionCollection(), "options_show_jump_bar" ); 1696 actionCollection(), "options_show_jump_bar" );
1695 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1697 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1696 1698
1697 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1699 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1698 actionCollection(), "options_show_details" ); 1700 actionCollection(), "options_show_details" );
1699 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1701 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1700 1702
1701 // misc 1703 // misc
1702 // only enable LDAP lookup if we can handle the protocol 1704 // only enable LDAP lookup if we can handle the protocol
1703#ifndef KAB_EMBEDDED 1705#ifndef KAB_EMBEDDED
1704 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1706 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1705 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1707 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1706 this, SLOT( openLDAPDialog() ), actionCollection(), 1708 this, SLOT( openLDAPDialog() ), actionCollection(),
1707 "ldap_lookup" ); 1709 "ldap_lookup" );
1708 } 1710 }
1709#else //KAB_EMBEDDED 1711#else //KAB_EMBEDDED
1710 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1712 //qDebug("KABCore::initActions() LDAP has to be implemented");
1711#endif //KAB_EMBEDDED 1713#endif //KAB_EMBEDDED
1712 1714
1713 1715
1714 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1716 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1715 SLOT( setWhoAmI() ), actionCollection(), 1717 SLOT( setWhoAmI() ), actionCollection(),
1716 "set_personal" ); 1718 "set_personal" );
1717 1719
1718 1720
1719 1721
1720 1722
1721 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1723 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1722 SLOT( setCategories() ), actionCollection(), 1724 SLOT( setCategories() ), actionCollection(),
1723 "edit_set_categories" ); 1725 "edit_set_categories" );
1724 1726
1725 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1727 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1726 SLOT( removeVoice() ), actionCollection(), 1728 SLOT( removeVoice() ), actionCollection(),
1727 "remove_voice" ); 1729 "remove_voice" );
1728 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1730 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1729 SLOT( importFromOL() ), actionCollection(), 1731 SLOT( importFromOL() ), actionCollection(),
1730 "import_OL" ); 1732 "import_OL" );
1731#ifdef KAB_EMBEDDED 1733#ifdef KAB_EMBEDDED
1732 mActionLicence = new KAction( i18n( "Licence" ), 0, 1734 mActionLicence = new KAction( i18n( "Licence" ), 0,
1733 this, SLOT( showLicence() ), actionCollection(), 1735 this, SLOT( showLicence() ), actionCollection(),
1734 "licence_about_data" ); 1736 "licence_about_data" );
1735 mActionFaq = new KAction( i18n( "Faq" ), 0, 1737 mActionFaq = new KAction( i18n( "Faq" ), 0,
1736 this, SLOT( faq() ), actionCollection(), 1738 this, SLOT( faq() ), actionCollection(),
1737 "faq_about_data" ); 1739 "faq_about_data" );
1738 1740
1739 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1741 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1740 this, SLOT( createAboutData() ), actionCollection(), 1742 this, SLOT( createAboutData() ), actionCollection(),
1741 "kaddressbook_about_data" ); 1743 "kaddressbook_about_data" );
1742#endif //KAB_EMBEDDED 1744#endif //KAB_EMBEDDED
1743 1745
1744 clipboardDataChanged(); 1746 clipboardDataChanged();
1745 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1747 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1746 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1748 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1747} 1749}
1748 1750
1749//US we need this function, to plug all actions into the correct menues. 1751//US we need this function, to plug all actions into the correct menues.
1750// KDE uses a XML format to plug the actions, but we work her without this overhead. 1752// KDE uses a XML format to plug the actions, but we work her without this overhead.
1751void KABCore::addActionsManually() 1753void KABCore::addActionsManually()
1752{ 1754{
1753//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1755//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1754 1756
1755#ifdef KAB_EMBEDDED 1757#ifdef KAB_EMBEDDED
1756 QPopupMenu *fileMenu = new QPopupMenu( this ); 1758 QPopupMenu *fileMenu = new QPopupMenu( this );
1757 QPopupMenu *editMenu = new QPopupMenu( this ); 1759 QPopupMenu *editMenu = new QPopupMenu( this );
1758 QPopupMenu *helpMenu = new QPopupMenu( this ); 1760 QPopupMenu *helpMenu = new QPopupMenu( this );
1759 1761
1760 KToolBar* tb = mMainWindow->toolBar(); 1762 KToolBar* tb = mMainWindow->toolBar();
1761 1763
1762#ifdef DESKTOP_VERSION 1764#ifdef DESKTOP_VERSION
1763 QMenuBar* mb = mMainWindow->menuBar(); 1765 QMenuBar* mb = mMainWindow->menuBar();
1764 1766
1765 //US setup menubar. 1767 //US setup menubar.
1766 //Disable the following block if you do not want to have a menubar. 1768 //Disable the following block if you do not want to have a menubar.
1767 mb->insertItem( "&File", fileMenu ); 1769 mb->insertItem( "&File", fileMenu );
1768 mb->insertItem( "&Edit", editMenu ); 1770 mb->insertItem( "&Edit", editMenu );
1769 mb->insertItem( "&View", viewMenu ); 1771 mb->insertItem( "&View", viewMenu );
1770 mb->insertItem( "&Settings", settingsMenu ); 1772 mb->insertItem( "&Settings", settingsMenu );
1771 mb->insertItem( i18n("Synchronize"), syncMenu ); 1773 mb->insertItem( i18n("Synchronize"), syncMenu );
1772 mb->insertItem( "&Change selected", changeMenu ); 1774 mb->insertItem( "&Change selected", changeMenu );
1773 mb->insertItem( "&Help", helpMenu ); 1775 mb->insertItem( "&Help", helpMenu );
1774 mIncSearchWidget = new IncSearchWidget( tb ); 1776 mIncSearchWidget = new IncSearchWidget( tb );
1775 // tb->insertWidget(-1, 0, mIncSearchWidget); 1777 // tb->insertWidget(-1, 0, mIncSearchWidget);
1776 1778
1777#else 1779#else
1778 //US setup toolbar 1780 //US setup toolbar
1779 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1781 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1780 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1782 QPopupMenu *popupBarTB = new QPopupMenu( this );
1781 menuBarTB->insertItem( "ME", popupBarTB); 1783 menuBarTB->insertItem( "ME", popupBarTB);
1782 tb->insertWidget(-1, 0, menuBarTB); 1784 tb->insertWidget(-1, 0, menuBarTB);
1783 mIncSearchWidget = new IncSearchWidget( tb ); 1785 mIncSearchWidget = new IncSearchWidget( tb );
1784 1786
1785 tb->enableMoving(false); 1787 tb->enableMoving(false);
1786 popupBarTB->insertItem( "&File", fileMenu ); 1788 popupBarTB->insertItem( "&File", fileMenu );
1787 popupBarTB->insertItem( "&Edit", editMenu ); 1789 popupBarTB->insertItem( "&Edit", editMenu );
1788 popupBarTB->insertItem( "&View", viewMenu ); 1790 popupBarTB->insertItem( "&View", viewMenu );
1789 popupBarTB->insertItem( "&Settings", settingsMenu ); 1791 popupBarTB->insertItem( "&Settings", settingsMenu );
1790 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1792 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1791 mViewManager->getFilterAction()->plug ( popupBarTB); 1793 mViewManager->getFilterAction()->plug ( popupBarTB);
1792 popupBarTB->insertItem( "&Change selected", changeMenu ); 1794 popupBarTB->insertItem( "&Change selected", changeMenu );
1793 popupBarTB->insertItem( "&Help", helpMenu ); 1795 popupBarTB->insertItem( "&Help", helpMenu );
1794 if (QApplication::desktop()->width() > 320 ) { 1796 if (QApplication::desktop()->width() > 320 ) {
1795 // mViewManager->getFilterAction()->plug ( tb); 1797 // mViewManager->getFilterAction()->plug ( tb);
1796 } 1798 }
1797#endif 1799#endif
1798 // mActionQuit->plug ( mMainWindow->toolBar()); 1800 // mActionQuit->plug ( mMainWindow->toolBar());
1799 1801
1800 1802
1801 1803
1802 //US Now connect the actions with the menue entries. 1804 //US Now connect the actions with the menue entries.
1803 mActionPrint->plug( fileMenu ); 1805 mActionPrint->plug( fileMenu );
1804 mActionMail->plug( fileMenu ); 1806 mActionMail->plug( fileMenu );
1805 fileMenu->insertSeparator(); 1807 fileMenu->insertSeparator();
1806 1808
1807 mActionNewContact->plug( fileMenu ); 1809 mActionNewContact->plug( fileMenu );
1808 mActionNewContact->plug( tb ); 1810 mActionNewContact->plug( tb );
1809 1811
1810 mActionEditAddressee->plug( fileMenu ); 1812 mActionEditAddressee->plug( fileMenu );
1811 if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1813 if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1812 (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1814 (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1813 mActionEditAddressee->plug( tb ); 1815 mActionEditAddressee->plug( tb );
1814 1816
1815 fileMenu->insertSeparator(); 1817 fileMenu->insertSeparator();
1816 mActionSave->plug( fileMenu ); 1818 mActionSave->plug( fileMenu );
1817 fileMenu->insertItem( "&Import", ImportMenu ); 1819 fileMenu->insertItem( "&Import", ImportMenu );
1818 fileMenu->insertItem( "&Export", ExportMenu ); 1820 fileMenu->insertItem( "&Export", ExportMenu );
1819 fileMenu->insertSeparator(); 1821 fileMenu->insertSeparator();
1820 mActionMailVCard->plug( fileMenu ); 1822 mActionMailVCard->plug( fileMenu );
1821#ifndef DESKTOP_VERSION 1823#ifndef DESKTOP_VERSION
1822 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1824 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
1823 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 1825 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
1824#endif 1826#endif
1825 fileMenu->insertSeparator(); 1827 fileMenu->insertSeparator();
1826 mActionQuit->plug( fileMenu ); 1828 mActionQuit->plug( fileMenu );
1827#ifdef _WIN32_ 1829#ifdef _WIN32_
1828 mActionImportOL->plug( ImportMenu ); 1830 mActionImportOL->plug( ImportMenu );
1829#endif 1831#endif
1830 // edit menu 1832 // edit menu
1831 mActionUndo->plug( editMenu ); 1833 mActionUndo->plug( editMenu );
1832 mActionRedo->plug( editMenu ); 1834 mActionRedo->plug( editMenu );
1833 editMenu->insertSeparator(); 1835 editMenu->insertSeparator();
1834 mActionCut->plug( editMenu ); 1836 mActionCut->plug( editMenu );
1835 mActionCopy->plug( editMenu ); 1837 mActionCopy->plug( editMenu );
1836 mActionPaste->plug( editMenu ); 1838 mActionPaste->plug( editMenu );
1837 mActionDelete->plug( editMenu ); 1839 mActionDelete->plug( editMenu );
1838 editMenu->insertSeparator(); 1840 editMenu->insertSeparator();
1839 mActionSelectAll->plug( editMenu ); 1841 mActionSelectAll->plug( editMenu );
1840 1842
1841 mActionRemoveVoice->plug( changeMenu ); 1843 mActionRemoveVoice->plug( changeMenu );
1842 // settings menu 1844 // settings menu
1843//US special menuentry to configure the addressbook resources. On KDE 1845//US special menuentry to configure the addressbook resources. On KDE
1844// you do that through the control center !!! 1846// you do that through the control center !!!
1845 mActionConfigResources->plug( settingsMenu ); 1847 mActionConfigResources->plug( settingsMenu );
1846 settingsMenu->insertSeparator(); 1848 settingsMenu->insertSeparator();
1847 1849
1848 mActionConfigKAddressbook->plug( settingsMenu ); 1850 mActionConfigKAddressbook->plug( settingsMenu );
1849 1851
1850 if ( mIsPart ) { 1852 if ( mIsPart ) {
1851 mActionConfigShortcuts->plug( settingsMenu ); 1853 mActionConfigShortcuts->plug( settingsMenu );
1852 mActionConfigureToolbars->plug( settingsMenu ); 1854 mActionConfigureToolbars->plug( settingsMenu );
1853 1855
1854 } else { 1856 } else {
1855 mActionKeyBindings->plug( settingsMenu ); 1857 mActionKeyBindings->plug( settingsMenu );
1856 } 1858 }
1857 1859
1858 settingsMenu->insertSeparator(); 1860 settingsMenu->insertSeparator();
1859 1861
1860 mActionJumpBar->plug( settingsMenu ); 1862 mActionJumpBar->plug( settingsMenu );
1861 mActionDetails->plug( settingsMenu ); 1863 mActionDetails->plug( settingsMenu );
1862 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 1864 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
1863 mActionDetails->plug( tb ); 1865 mActionDetails->plug( tb );
1864 settingsMenu->insertSeparator(); 1866 settingsMenu->insertSeparator();
1865 1867
1866 mActionWhoAmI->plug( settingsMenu ); 1868 mActionWhoAmI->plug( settingsMenu );
1867 mActionCategories->plug( settingsMenu ); 1869 mActionCategories->plug( settingsMenu );
1868 1870
1869 mActionLicence->plug( helpMenu ); 1871 mActionLicence->plug( helpMenu );
1870 mActionFaq->plug( helpMenu ); 1872 mActionFaq->plug( helpMenu );
1871 mActionAboutKAddressbook->plug( helpMenu ); 1873 mActionAboutKAddressbook->plug( helpMenu );
1872 1874
1873 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 1875 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
1874 1876
1875 mActionSave->plug( tb ); 1877 mActionSave->plug( tb );
1876 mViewManager->getFilterAction()->plug ( tb); 1878 mViewManager->getFilterAction()->plug ( tb);
1877 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 1879 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
1878 mActionUndo->plug( tb ); 1880 mActionUndo->plug( tb );
1879 mActionDelete->plug( tb ); 1881 mActionDelete->plug( tb );
1880 mActionRedo->plug( tb ); 1882 mActionRedo->plug( tb );
1881 } 1883 }
1882 } 1884 }
1883 //mActionQuit->plug ( tb ); 1885 //mActionQuit->plug ( tb );
1884 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 1886 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
1885 1887
1886 //US link the searchwidget first to this. 1888 //US link the searchwidget first to this.
1887 // The real linkage to the toolbar happens later. 1889 // The real linkage to the toolbar happens later.
1888//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 1890//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
1889//US tb->insertItem( mIncSearchWidget ); 1891//US tb->insertItem( mIncSearchWidget );
1890/*US 1892/*US
1891 mIncSearchWidget = new IncSearchWidget( tb ); 1893 mIncSearchWidget = new IncSearchWidget( tb );
1892 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1894 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1893 SLOT( incrementalSearch( const QString& ) ) ); 1895 SLOT( incrementalSearch( const QString& ) ) );
1894 1896
1895 mJumpButtonBar = new JumpButtonBar( this, this ); 1897 mJumpButtonBar = new JumpButtonBar( this, this );
1896 1898
1897//US topLayout->addWidget( mJumpButtonBar ); 1899//US topLayout->addWidget( mJumpButtonBar );
1898 this->layout()->add( mJumpButtonBar ); 1900 this->layout()->add( mJumpButtonBar );
1899*/ 1901*/
1900 1902
1901#endif //KAB_EMBEDDED 1903#endif //KAB_EMBEDDED
1902 1904
1903 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) ); 1905 connect ( syncMenu, SIGNAL( activated ( int ) ), this, SLOT (slotSyncMenu( int ) ) );
1904 fillSyncMenu(); 1906 fillSyncMenu();
1905 1907
1906} 1908}
1907void KABCore::showLicence() 1909void KABCore::showLicence()
1908{ 1910{
1909 KApplication::showLicence(); 1911 KApplication::showLicence();
1910} 1912}
1911void KABCore::removeVoice() 1913void KABCore::removeVoice()
1912{ 1914{
1913 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) 1915 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No )
1914 return; 1916 return;
1915 KABC::Addressee::List list = mViewManager->selectedAddressees(); 1917 KABC::Addressee::List list = mViewManager->selectedAddressees();
1916 KABC::Addressee::List::Iterator it; 1918 KABC::Addressee::List::Iterator it;
1917 for ( it = list.begin(); it != list.end(); ++it ) { 1919 for ( it = list.begin(); it != list.end(); ++it ) {
1918 PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); 1920 PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
1919 PhoneNumber::List::Iterator phoneIt; 1921 PhoneNumber::List::Iterator phoneIt;
1920 bool found = false; 1922 bool found = false;
1921 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { 1923 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
1922 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 1924 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
1923 if ((*phoneIt).type() - PhoneNumber::Voice ) { 1925 if ((*phoneIt).type() - PhoneNumber::Voice ) {
1924 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 1926 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
1925 (*it).insertPhoneNumber( (*phoneIt) ); 1927 (*it).insertPhoneNumber( (*phoneIt) );
1926 found = true; 1928 found = true;
1927 } 1929 }
1928 } 1930 }
1929 1931
1930 } 1932 }
1931 if ( found ) 1933 if ( found )
1932 contactModified((*it) ); 1934 contactModified((*it) );
1933 } 1935 }
1934} 1936}
1935 1937
1936 1938
1937 1939
1938void KABCore::clipboardDataChanged() 1940void KABCore::clipboardDataChanged()
1939{ 1941{
1940 1942
1941 if ( mReadWrite ) 1943 if ( mReadWrite )
1942 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 1944 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
1943 1945
1944} 1946}
1945 1947
1946void KABCore::updateActionMenu() 1948void KABCore::updateActionMenu()
1947{ 1949{
1948 UndoStack *undo = UndoStack::instance(); 1950 UndoStack *undo = UndoStack::instance();
1949 RedoStack *redo = RedoStack::instance(); 1951 RedoStack *redo = RedoStack::instance();
1950 1952
1951 if ( undo->isEmpty() ) 1953 if ( undo->isEmpty() )
1952 mActionUndo->setText( i18n( "Undo" ) ); 1954 mActionUndo->setText( i18n( "Undo" ) );
1953 else 1955 else
1954 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 1956 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
1955 1957
1956 mActionUndo->setEnabled( !undo->isEmpty() ); 1958 mActionUndo->setEnabled( !undo->isEmpty() );
1957 1959
1958 if ( !redo->top() ) 1960 if ( !redo->top() )
1959 mActionRedo->setText( i18n( "Redo" ) ); 1961 mActionRedo->setText( i18n( "Redo" ) );
1960 else 1962 else
1961 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 1963 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
1962 1964
1963 mActionRedo->setEnabled( !redo->isEmpty() ); 1965 mActionRedo->setEnabled( !redo->isEmpty() );
1964} 1966}
1965 1967
1966void KABCore::configureKeyBindings() 1968void KABCore::configureKeyBindings()
1967{ 1969{
1968#ifndef KAB_EMBEDDED 1970#ifndef KAB_EMBEDDED
1969 KKeyDialog::configure( actionCollection(), true ); 1971 KKeyDialog::configure( actionCollection(), true );
1970#else //KAB_EMBEDDED 1972#else //KAB_EMBEDDED
1971 qDebug("KABCore::configureKeyBindings() not implemented"); 1973 qDebug("KABCore::configureKeyBindings() not implemented");
1972#endif //KAB_EMBEDDED 1974#endif //KAB_EMBEDDED
1973} 1975}
1974 1976
1975#ifdef KAB_EMBEDDED 1977#ifdef KAB_EMBEDDED
1976void KABCore::configureResources() 1978void KABCore::configureResources()
1977{ 1979{
1978 KRES::KCMKResources dlg( this, "" , 0 ); 1980 KRES::KCMKResources dlg( this, "" , 0 );
1979 1981
1980 if ( !dlg.exec() ) 1982 if ( !dlg.exec() )
1981 return; 1983 return;
1982 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 1984 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
1983} 1985}
1984#endif //KAB_EMBEDDED 1986#endif //KAB_EMBEDDED
1985 1987
1986 1988
1987/* this method will be called through the QCop interface from Ko/Pi to select addresses 1989/* this method will be called through the QCop interface from Ko/Pi to select addresses
1988 * for the attendees list of an event. 1990 * for the attendees list of an event.
1989 */ 1991 */
1990void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 1992void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
1991{ 1993{
1992 QStringList nameList; 1994 QStringList nameList;
1993 QStringList emailList; 1995 QStringList emailList;
1994 QStringList uidList; 1996 QStringList uidList;
1995 1997
1996 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 1998 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
1997 uint i=0; 1999 uint i=0;
1998 for (i=0; i < list.count(); i++) 2000 for (i=0; i < list.count(); i++)
1999 { 2001 {
2000 nameList.append(list[i].realName()); 2002 nameList.append(list[i].realName());
2001 emailList.append(list[i].preferredEmail()); 2003 emailList.append(list[i].preferredEmail());
2002 uidList.append(list[i].uid()); 2004 uidList.append(list[i].uid());
2003 } 2005 }
2004 2006
2005 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2007 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2006 2008
2007} 2009}
2008 2010
2009/* this method will be called through the QCop interface from other apps to show details of a contact. 2011/* this method will be called through the QCop interface from other apps to show details of a contact.
2010 */ 2012 */
2011void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2013void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2012{ 2014{
2013 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2015 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2014 2016
2015 QString foundUid = QString::null; 2017 QString foundUid = QString::null;
2016 if ( ! uid.isEmpty() ) { 2018 if ( ! uid.isEmpty() ) {
2017 Addressee adrr = mAddressBook->findByUid( uid ); 2019 Addressee adrr = mAddressBook->findByUid( uid );
2018 if ( !adrr.isEmpty() ) { 2020 if ( !adrr.isEmpty() ) {
2019 foundUid = uid; 2021 foundUid = uid;
2020 } 2022 }
2021 if ( email == "sendbacklist" ) { 2023 if ( email == "sendbacklist" ) {
2022 //qDebug("ssssssssssssssssssssssend "); 2024 //qDebug("ssssssssssssssssssssssend ");
2023 QStringList nameList; 2025 QStringList nameList;
2024 QStringList emailList; 2026 QStringList emailList;
2025 QStringList uidList; 2027 QStringList uidList;
2026 nameList.append(adrr.realName()); 2028 nameList.append(adrr.realName());
2027 emailList = adrr.emails(); 2029 emailList = adrr.emails();
2028 uidList.append( adrr.preferredEmail()); 2030 uidList.append( adrr.preferredEmail());
2029 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2031 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2030 return; 2032 return;
2031 } 2033 }
2032 2034
2033 } 2035 }
2034 2036
2035 if ( email == "sendbacklist" ) 2037 if ( email == "sendbacklist" )
2036 return; 2038 return;
2037 if (foundUid.isEmpty()) 2039 if (foundUid.isEmpty())
2038 { 2040 {
2039 //find the uid of the person first 2041 //find the uid of the person first
2040 Addressee::List namelist; 2042 Addressee::List namelist;
2041 Addressee::List emaillist; 2043 Addressee::List emaillist;
2042 2044
2043 if (!name.isEmpty()) 2045 if (!name.isEmpty())
2044 namelist = mAddressBook->findByName( name ); 2046 namelist = mAddressBook->findByName( name );
2045 2047
2046 if (!email.isEmpty()) 2048 if (!email.isEmpty())
2047 emaillist = mAddressBook->findByEmail( email ); 2049 emaillist = mAddressBook->findByEmail( email );
2048 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2050 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2049 //check if we have a match in Namelist and Emaillist 2051 //check if we have a match in Namelist and Emaillist
2050 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2052 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2051 foundUid = emaillist[0].uid(); 2053 foundUid = emaillist[0].uid();
2052 } 2054 }
2053 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2055 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2054 foundUid = namelist[0].uid(); 2056 foundUid = namelist[0].uid();
2055 else 2057 else
2056 { 2058 {
2057 for (int i = 0; i < namelist.count(); i++) 2059 for (int i = 0; i < namelist.count(); i++)
2058 { 2060 {
2059 for (int j = 0; j < emaillist.count(); j++) 2061 for (int j = 0; j < emaillist.count(); j++)
2060 { 2062 {
2061 if (namelist[i] == emaillist[j]) 2063 if (namelist[i] == emaillist[j])
2062 { 2064 {
2063 foundUid = namelist[i].uid(); 2065 foundUid = namelist[i].uid();
2064 } 2066 }
2065 } 2067 }
2066 } 2068 }
2067 } 2069 }
2068 } 2070 }
2069 else 2071 else
2070 { 2072 {
2071 foundUid = uid; 2073 foundUid = uid;
2072 } 2074 }
2073 2075
2074 if (!foundUid.isEmpty()) 2076 if (!foundUid.isEmpty())
2075 { 2077 {
2076 2078
2077 // raise Ka/Pi if it is in the background 2079 // raise Ka/Pi if it is in the background
2078#ifndef DESKTOP_VERSION 2080#ifndef DESKTOP_VERSION
2079#ifndef KORG_NODCOP 2081#ifndef KORG_NODCOP
2080 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2082 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2081#endif 2083#endif
2082#endif 2084#endif
2083 2085
2084 mMainWindow->showMaximized(); 2086 mMainWindow->showMaximized();
2085 mMainWindow-> raise(); 2087 mMainWindow-> raise();
2086 2088
2087 mViewManager->setSelected( "", false); 2089 mViewManager->setSelected( "", false);
2088 mViewManager->refreshView( "" ); 2090 mViewManager->refreshView( "" );
2089 mViewManager->setSelected( foundUid, true ); 2091 mViewManager->setSelected( foundUid, true );
2090 mViewManager->refreshView( foundUid ); 2092 mViewManager->refreshView( foundUid );
2091 2093
2092 if ( !mMultipleViewsAtOnce ) 2094 if ( !mMultipleViewsAtOnce )
2093 { 2095 {
2094 setDetailsVisible( true ); 2096 setDetailsVisible( true );
2095 mActionDetails->setChecked(true); 2097 mActionDetails->setChecked(true);
2096 } 2098 }
2097 } 2099 }
2098} 2100}
2099 2101
2100 2102
2101void KABCore::faq() 2103void KABCore::faq()
2102{ 2104{
2103 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2105 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2104} 2106}
2105 2107
2106 2108
2107void KABCore::fillSyncMenu() 2109void KABCore::fillSyncMenu()
2108{ 2110{
2109 if ( syncMenu->count() ) 2111 if ( syncMenu->count() )
2110 syncMenu->clear(); 2112 syncMenu->clear();
2111 syncMenu->insertItem( i18n("Configure..."), 0 ); 2113 syncMenu->insertItem( i18n("Configure..."), 0 );
2112 syncMenu->insertSeparator(); 2114 syncMenu->insertSeparator();
2113 syncMenu->insertItem( i18n("Multiple sync"), 1 ); 2115 syncMenu->insertItem( i18n("Multiple sync"), 1 );
2114 syncMenu->insertSeparator(); 2116 syncMenu->insertSeparator();
2115 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2117 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2116 config.setGroup("General"); 2118 config.setGroup("General");
2117 QStringList prof = config.readListEntry("SyncProfileNames"); 2119 QStringList prof = config.readListEntry("SyncProfileNames");
2118 KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 2120 KABPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined");
2119 if ( prof.count() < 3 ) { 2121 if ( prof.count() < 3 ) {
2120 prof.clear(); 2122 prof.clear();
2121 prof << i18n("Sharp_DTM"); 2123 prof << i18n("Sharp_DTM");
2122 prof << i18n("Local_file"); 2124 prof << i18n("Local_file");
2123 prof << i18n("Last_file"); 2125 prof << i18n("Last_file");
2124 KSyncProfile* temp = new KSyncProfile (); 2126 KSyncProfile* temp = new KSyncProfile ();
2125 temp->setName( prof[0] ); 2127 temp->setName( prof[0] );
2126 temp->writeConfig(&config); 2128 temp->writeConfig(&config);
2127 temp->setName( prof[1] ); 2129 temp->setName( prof[1] );
2128 temp->writeConfig(&config); 2130 temp->writeConfig(&config);
2129 temp->setName( prof[2] ); 2131 temp->setName( prof[2] );
2130 temp->writeConfig(&config); 2132 temp->writeConfig(&config);
2131 config.setGroup("General"); 2133 config.setGroup("General");
2132 config.writeEntry("SyncProfileNames",prof); 2134 config.writeEntry("SyncProfileNames",prof);
2133 config.writeEntry("ExternSyncProfiles","Sharp_DTM"); 2135 config.writeEntry("ExternSyncProfiles","Sharp_DTM");
2134 config.sync(); 2136 config.sync();
2135 delete temp; 2137 delete temp;
2136 } 2138 }
2137 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 2139 KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
2138 KABPrefs::instance()->mSyncProfileNames = prof; 2140 KABPrefs::instance()->mSyncProfileNames = prof;
2139 int i; 2141 int i;
2140 for ( i = 0; i < prof.count(); ++i ) { 2142 for ( i = 0; i < prof.count(); ++i ) {
2141 2143
2142 syncMenu->insertItem( prof[i], 1000+i ); 2144 syncMenu->insertItem( prof[i], 1000+i );
2143 if ( i == 2 ) 2145 if ( i == 2 )
2144 syncMenu->insertSeparator(); 2146 syncMenu->insertSeparator();
2145 } 2147 }
2146 QDir app_dir; 2148 QDir app_dir;
2147 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 2149 if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
2148 syncMenu->setItemEnabled( false , 1000 ); 2150 syncMenu->setItemEnabled( false , 1000 );
2149 } 2151 }
2150 //probaly useless 2152 //probaly useless
2151 //mView->setupExternSyncProfiles(); 2153 //mView->setupExternSyncProfiles();
2152} 2154}
2153void KABCore::slotSyncMenu( int action ) 2155void KABCore::slotSyncMenu( int action )
2154{ 2156{
2155 //qDebug("syncaction %d ", action); 2157 //qDebug("syncaction %d ", action);
2156 if ( action == 0 ) { 2158 if ( action == 0 ) {
2157 2159
2158 // seems to be a Qt2 event handling bug 2160 // seems to be a Qt2 event handling bug
2159 // syncmenu.clear causes a segfault at first time 2161 // syncmenu.clear causes a segfault at first time
2160 // when we call it after the main event loop, it is ok 2162 // when we call it after the main event loop, it is ok
2161 // same behaviour when calling OM/Pi via QCOP for the first time 2163 // same behaviour when calling OM/Pi via QCOP for the first time
2162 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 2164 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
2163 //confSync(); 2165 //confSync();
2164 2166
2165 return; 2167 return;
2166 } 2168 }
2167 if ( action == 1 ) { 2169 if ( action == 1 ) {
2168 multiSync( true ); 2170 multiSync( true );
2169 return; 2171 return;
2170 } 2172 }
2171 2173
2172 if (mBlockSaveFlag) 2174 if (mBlockSaveFlag)
2173 return; 2175 return;
2174 mBlockSaveFlag = true; 2176 mBlockSaveFlag = true;
2175 mCurrentSyncProfile = action - 1000 ; 2177 mCurrentSyncProfile = action - 1000 ;
2176 mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; 2178 mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ;
2177 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; 2179 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ;
2178 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2180 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2179 KSyncProfile* temp = new KSyncProfile (); 2181 KSyncProfile* temp = new KSyncProfile ();
2180 temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2182 temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2181 temp->readConfig(&config); 2183 temp->readConfig(&config);
2182 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2184 KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2183 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2185 KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
2184 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2186 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2185 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2187 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2186 KABPrefs::instance()->mWriteBackInFuture = 0; 2188 KABPrefs::instance()->mWriteBackInFuture = 0;
2187 if ( temp->getWriteBackFuture() ) 2189 if ( temp->getWriteBackFuture() )
2188 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2190 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2189 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2191 KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2190 if ( action == 1000 ) { 2192 if ( action == 1000 ) {
2191 syncSharp(); 2193 syncSharp();
2192 2194
2193 } else if ( action == 1001 ) { 2195 } else if ( action == 1001 ) {
2194 syncLocalFile(); 2196 syncLocalFile();
2195 2197
2196 } else if ( action == 1002 ) { 2198 } else if ( action == 1002 ) {
2197 quickSyncLocalFile(); 2199 quickSyncLocalFile();
2198 2200
2199 } else if ( action >= 1003 ) { 2201 } else if ( action >= 1003 ) {
2200 if ( temp->getIsLocalFileSync() ) { 2202 if ( temp->getIsLocalFileSync() ) {
2201 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 2203 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
2202 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 2204 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
2203 } else { 2205 } else {
2204 if ( temp->getIsPhoneSync() ) { 2206 if ( temp->getIsPhoneSync() ) {
2205 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 2207 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2206 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 2208 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2207 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 2209 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2208 syncPhone(); 2210 syncPhone();
2209 } else 2211 } else
2210 syncRemote( temp ); 2212 syncRemote( temp );
2211 2213
2212 } 2214 }
2213 } 2215 }
2214 delete temp; 2216 delete temp;
2215 mBlockSaveFlag = false; 2217 mBlockSaveFlag = false;
2216} 2218}
2217 2219
2218void KABCore::syncLocalFile() 2220void KABCore::syncLocalFile()
2219{ 2221{
2220 2222
2221 QString fn =KABPrefs::instance()->mLastSyncedLocalFile; 2223 QString fn =KABPrefs::instance()->mLastSyncedLocalFile;
2222 2224
2223 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2225 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2224 if ( fn == "" ) 2226 if ( fn == "" )
2225 return; 2227 return;
2226 if ( syncWithFile( fn, false ) ) { 2228 if ( syncWithFile( fn, false ) ) {
2227 qDebug("syncLocalFile() successful "); 2229 qDebug("syncLocalFile() successful ");
2228 } 2230 }
2229 2231
2230} 2232}
2231bool KABCore::syncWithFile( QString fn , bool quick ) 2233bool KABCore::syncWithFile( QString fn , bool quick )
2232{ 2234{
2233 bool ret = false; 2235 bool ret = false;
2234 QFileInfo info; 2236 QFileInfo info;
2235 info.setFile( fn ); 2237 info.setFile( fn );
2236 QString mess; 2238 QString mess;
2237 bool loadbup = true; 2239 bool loadbup = true;
2238 if ( !info. exists() ) { 2240 if ( !info. exists() ) {
2239 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 2241 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
2240 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2242 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2241 mess ); 2243 mess );
2242 return ret; 2244 return ret;
2243 } 2245 }
2244 int result = 0; 2246 int result = 0;
2245 if ( !quick ) { 2247 if ( !quick ) {
2246 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2248 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2247 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2249 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2248 mess, 2250 mess,
2249 i18n("Sync"), i18n("Cancel"), 0, 2251 i18n("Sync"), i18n("Cancel"), 0,
2250 0, 1 ); 2252 0, 1 );
2251 if ( result ) 2253 if ( result )
2252 return false; 2254 return false;
2253 } 2255 }
2254 if ( KABPrefs::instance()->mAskForPreferences ) 2256 if ( KABPrefs::instance()->mAskForPreferences )
2255 edit_sync_options(); 2257 edit_sync_options();
2256 if ( result == 0 ) { 2258 if ( result == 0 ) {
2257 //qDebug("Now sycing ... "); 2259 //qDebug("Now sycing ... ");
2258 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) 2260 if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) )
2259 setCaption( i18n("Synchronization successful") ); 2261 setCaption( i18n("Synchronization successful") );
2260 else 2262 else
2261 setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 2263 setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
2262 if ( ! quick ) 2264 if ( ! quick )
2263 KABPrefs::instance()->mLastSyncedLocalFile = fn; 2265 KABPrefs::instance()->mLastSyncedLocalFile = fn;
2264 setModified(); 2266 setModified();
2265 } 2267 }
2266 return ret; 2268 return ret;
2267} 2269}
2268void KABCore::quickSyncLocalFile() 2270void KABCore::quickSyncLocalFile()
2269{ 2271{
2270 2272
2271 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { 2273 if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) {
2272 qDebug("quick syncLocalFile() successful "); 2274 qDebug("quick syncLocalFile() successful ");
2273 2275
2274 } 2276 }
2275} 2277}
2276void KABCore::multiSync( bool askforPrefs ) 2278void KABCore::multiSync( bool askforPrefs )
2277{ 2279{
2278 if (mBlockSaveFlag) 2280 if (mBlockSaveFlag)
2279 return; 2281 return;
2280 mBlockSaveFlag = true; 2282 mBlockSaveFlag = true;
2281 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 2283 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
2282 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2284 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2283 question, 2285 question,
2284 i18n("Yes"), i18n("No"), 2286 i18n("Yes"), i18n("No"),
2285 0, 0 ) != 0 ) { 2287 0, 0 ) != 0 ) {
2286 mBlockSaveFlag = false; 2288 mBlockSaveFlag = false;
2287 setCaption(i18n("Aborted! Nothing synced!")); 2289 setCaption(i18n("Aborted! Nothing synced!"));
2288 return; 2290 return;
2289 } 2291 }
2290 mCurrentSyncDevice = i18n("Multiple profiles") ; 2292 mCurrentSyncDevice = i18n("Multiple profiles") ;
2291 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; 2293 KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs;
2292 if ( askforPrefs ) { 2294 if ( askforPrefs ) {
2293 edit_sync_options(); 2295 edit_sync_options();
2294 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; 2296 KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs;
2295 } 2297 }
2296 setCaption(i18n("Multiple sync started.") ); 2298 setCaption(i18n("Multiple sync started.") );
2297 qApp->processEvents(); 2299 qApp->processEvents();
2298 int num = ringSync() ; 2300 int num = ringSync() ;
2299 if ( num > 1 ) 2301 if ( num > 1 )
2300 ringSync(); 2302 ringSync();
2301 mBlockSaveFlag = false; 2303 mBlockSaveFlag = false;
2302 if ( num ) 2304 if ( num )
2303 save(); 2305 save();
2304 if ( num ) 2306 if ( num )
2305 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 2307 setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
2306 else 2308 else
2307 setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 2309 setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
2308 return; 2310 return;
2309} 2311}
2310int KABCore::ringSync() 2312int KABCore::ringSync()
2311{ 2313{
2312 int syncedProfiles = 0; 2314 int syncedProfiles = 0;
2313 int i; 2315 int i;
2314 QTime timer; 2316 QTime timer;
2315 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2317 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2316 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; 2318 QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames;
2317 KSyncProfile* temp = new KSyncProfile (); 2319 KSyncProfile* temp = new KSyncProfile ();
2318 KABPrefs::instance()->mAskForPreferences = false; 2320 KABPrefs::instance()->mAskForPreferences = false;
2319 for ( i = 0; i < syncProfileNames.count(); ++i ) { 2321 for ( i = 0; i < syncProfileNames.count(); ++i ) {
2320 mCurrentSyncProfile = i; 2322 mCurrentSyncProfile = i;
2321 temp->setName(syncProfileNames[mCurrentSyncProfile]); 2323 temp->setName(syncProfileNames[mCurrentSyncProfile]);
2322 temp->readConfig(&config); 2324 temp->readConfig(&config);
2323 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { 2325 if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) {
2324 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); 2326 setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... "));
2325 ++syncedProfiles; 2327 ++syncedProfiles;
2326 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2328 // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2327 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); 2329 KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
2328 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); 2330 KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
2329 KABPrefs::instance()->mWriteBackInFuture = 0; 2331 KABPrefs::instance()->mWriteBackInFuture = 0;
2330 if ( temp->getWriteBackFuture() ) 2332 if ( temp->getWriteBackFuture() )
2331 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 2333 KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
2332 KABPrefs::instance()->mShowSyncSummary = false; 2334 KABPrefs::instance()->mShowSyncSummary = false;
2333 mCurrentSyncDevice = syncProfileNames[i] ; 2335 mCurrentSyncDevice = syncProfileNames[i] ;
2334 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; 2336 mCurrentSyncName = KABPrefs::instance()->mLocalMachineName;
2335 if ( i == 0 ) { 2337 if ( i == 0 ) {
2336 syncSharp(); 2338 syncSharp();
2337 } else { 2339 } else {
2338 if ( temp->getIsLocalFileSync() ) { 2340 if ( temp->getIsLocalFileSync() ) {
2339 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) 2341 if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) )
2340 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 2342 KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB();
2341 } else { 2343 } else {
2342 if ( temp->getIsPhoneSync() ) { 2344 if ( temp->getIsPhoneSync() ) {
2343 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; 2345 KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ;
2344 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); 2346 KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( );
2345 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); 2347 KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( );
2346 syncPhone(); 2348 syncPhone();
2347 } else 2349 } else
2348 syncRemote( temp, false ); 2350 syncRemote( temp, false );
2349 2351
2350 } 2352 }
2351 } 2353 }
2352 timer.start(); 2354 timer.start();
2353 setCaption(i18n("Multiple sync in progress ... please wait!") ); 2355 setCaption(i18n("Multiple sync in progress ... please wait!") );
2354 while ( timer.elapsed () < 2000 ) { 2356 while ( timer.elapsed () < 2000 ) {
2355 qApp->processEvents(); 2357 qApp->processEvents();
2356#ifndef _WIN32_ 2358#ifndef _WIN32_
2357 sleep (1); 2359 sleep (1);
2358#endif 2360#endif
2359 } 2361 }
2360 2362
2361 } 2363 }
2362 2364
2363 } 2365 }
2364 delete temp; 2366 delete temp;
2365 return syncedProfiles; 2367 return syncedProfiles;
2366} 2368}
2367 2369
2368void KABCore::syncRemote( KSyncProfile* prof, bool ask) 2370void KABCore::syncRemote( KSyncProfile* prof, bool ask)
2369{ 2371{
2370 QString question; 2372 QString question;
2371 if ( ask ) { 2373 if ( ask ) {
2372 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; 2374 question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
2373 if ( QMessageBox::information( this, i18n("KO/Pi Sync"), 2375 if ( QMessageBox::information( this, i18n("KO/Pi Sync"),
2374 question, 2376 question,
2375 i18n("Yes"), i18n("No"), 2377 i18n("Yes"), i18n("No"),
2376 0, 0 ) != 0 ) 2378 0, 0 ) != 0 )
2377 return; 2379 return;
2378 } 2380 }
2379 QString command = prof->getPreSyncCommandAB(); 2381 QString command = prof->getPreSyncCommandAB();
2380 int fi; 2382 int fi;
2381 if ( (fi = command.find("$PWD$")) > 0 ) { 2383 if ( (fi = command.find("$PWD$")) > 0 ) {
2382 QString pwd = getPassword(); 2384 QString pwd = getPassword();
2383 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2385 command = command.left( fi )+ pwd + command.mid( fi+5 );
2384 2386
2385 } 2387 }
2386 int maxlen = 30; 2388 int maxlen = 30;
2387 if ( QApplication::desktop()->width() > 320 ) 2389 if ( QApplication::desktop()->width() > 320 )
2388 maxlen += 25; 2390 maxlen += 25;
2389 setCaption ( i18n( "Copy remote file to local machine..." ) ); 2391 setCaption ( i18n( "Copy remote file to local machine..." ) );
2390 int fileSize = 0; 2392 int fileSize = 0;
2391 int result = system ( command ); 2393 int result = system ( command );
2392 // 0 : okay 2394 // 0 : okay
2393 // 256: no such file or dir 2395 // 256: no such file or dir
2394 // 2396 //
2395 qDebug("KO: Remote copy result(0 = okay): %d ",result ); 2397 qDebug("KO: Remote copy result(0 = okay): %d ",result );
2396 if ( result != 0 ) { 2398 if ( result != 0 ) {
2397 int len = maxlen; 2399 int len = maxlen;
2398 while ( len < command.length() ) { 2400 while ( len < command.length() ) {
2399 command.insert( len , "\n" ); 2401 command.insert( len , "\n" );
2400 len += maxlen +2; 2402 len += maxlen +2;
2401 } 2403 }
2402 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; 2404 question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ;
2403 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), 2405 QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"),
2404 question, 2406 question,
2405 i18n("Okay!")) ; 2407 i18n("Okay!")) ;
2406 setCaption ("KO/Pi"); 2408 setCaption ("KO/Pi");
2407 return; 2409 return;
2408 } 2410 }
2409 setCaption ( i18n( "Copying succeed." ) ); 2411 setCaption ( i18n( "Copying succeed." ) );
2410 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); 2412 //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() );
2411 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { 2413 if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) {
2412// Event* e = mView->getLastSyncEvent(); 2414// Event* e = mView->getLastSyncEvent();
2413// e->setReadOnly( false ); 2415// e->setReadOnly( false );
2414// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2416// e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2415// e->setReadOnly( true ); 2417// e->setReadOnly( true );
2416 if ( KABPrefs::instance()->mWriteBackFile ) { 2418 if ( KABPrefs::instance()->mWriteBackFile ) {
2417 command = prof->getPostSyncCommandAB(); 2419 command = prof->getPostSyncCommandAB();
2418 int fi; 2420 int fi;
2419 if ( (fi = command.find("$PWD$")) > 0 ) { 2421 if ( (fi = command.find("$PWD$")) > 0 ) {
2420 QString pwd = getPassword(); 2422 QString pwd = getPassword();
2421 command = command.left( fi )+ pwd + command.mid( fi+5 ); 2423 command = command.left( fi )+ pwd + command.mid( fi+5 );
2422 2424
2423 } 2425 }
2424 setCaption ( i18n( "Writing back file ..." ) ); 2426 setCaption ( i18n( "Writing back file ..." ) );
2425 result = system ( command ); 2427 result = system ( command );
2426 qDebug("KO: Writing back file result: %d ", result); 2428 qDebug("KO: Writing back file result: %d ", result);
2427 if ( result != 0 ) { 2429 if ( result != 0 ) {
2428 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); 2430 setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
2429 return; 2431 return;
2430 } else { 2432 } else {
2431 setCaption ( i18n( "Syncronization sucessfully completed" ) ); 2433 setCaption ( i18n( "Syncronization sucessfully completed" ) );
2432 } 2434 }
2433 } 2435 }
2434 } 2436 }
2435 return; 2437 return;
2436} 2438}
2437#include <qpushbutton.h> 2439#include <qpushbutton.h>
2438#include <qradiobutton.h> 2440#include <qradiobutton.h>
2439#include <qbuttongroup.h> 2441#include <qbuttongroup.h>
2440void KABCore::edit_sync_options() 2442void KABCore::edit_sync_options()
2441{ 2443{
2442 //mDialogManager->showSyncOptions(); 2444 //mDialogManager->showSyncOptions();
2443 //KABPrefs::instance()->mSyncAlgoPrefs 2445 //KABPrefs::instance()->mSyncAlgoPrefs
2444 QDialog dia( this, "dia", true ); 2446 QDialog dia( this, "dia", true );
2445 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); 2447 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2446 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); 2448 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2447 QVBoxLayout lay ( &dia ); 2449 QVBoxLayout lay ( &dia );
2448 lay.setSpacing( 2 ); 2450 lay.setSpacing( 2 );
2449 lay.setMargin( 3 ); 2451 lay.setMargin( 3 );
2450 lay.addWidget(&gr); 2452 lay.addWidget(&gr);
2451 QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); 2453 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2452 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); 2454 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2453 QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); 2455 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2454 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); 2456 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2455 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); 2457 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2456 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); 2458 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2457 //QRadioButton both( i18n("Take both on conflict"), &gr ); 2459 //QRadioButton both( i18n("Take both on conflict"), &gr );
2458 QPushButton pb ( "OK", &dia); 2460 QPushButton pb ( "OK", &dia);
2459 lay.addWidget( &pb ); 2461 lay.addWidget( &pb );
2460 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2462 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2461 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { 2463 switch ( KABPrefs::instance()->mSyncAlgoPrefs ) {
2462 case 0: 2464 case 0:
2463 loc.setChecked( true); 2465 loc.setChecked( true);
2464 break; 2466 break;
2465 case 1: 2467 case 1:
2466 rem.setChecked( true ); 2468 rem.setChecked( true );
2467 break; 2469 break;
2468 case 2: 2470 case 2:
2469 newest.setChecked( true); 2471 newest.setChecked( true);
2470 break; 2472 break;
2471 case 3: 2473 case 3:
2472 ask.setChecked( true); 2474 ask.setChecked( true);
2473 break; 2475 break;
2474 case 4: 2476 case 4:
2475 f_loc.setChecked( true); 2477 f_loc.setChecked( true);
2476 break; 2478 break;
2477 case 5: 2479 case 5:
2478 f_rem.setChecked( true); 2480 f_rem.setChecked( true);
2479 break; 2481 break;
2480 case 6: 2482 case 6:
2481 // both.setChecked( true); 2483 // both.setChecked( true);
2482 break; 2484 break;
2483 default: 2485 default:
2484 break; 2486 break;
2485 } 2487 }
2486 if ( dia.exec() ) { 2488 if ( dia.exec() ) {
2487 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; 2489 KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2488 } 2490 }
2489 2491
2490 2492
2491} 2493}
2492QString KABCore::getPassword( ) 2494QString KABCore::getPassword( )
2493{ 2495{
2494 QString retfile = ""; 2496 QString retfile = "";
2495 QDialog dia ( this, "input-dialog", true ); 2497 QDialog dia ( this, "input-dialog", true );
2496 QLineEdit lab ( &dia ); 2498 QLineEdit lab ( &dia );
2497 lab.setEchoMode( QLineEdit::Password ); 2499 lab.setEchoMode( QLineEdit::Password );
2498 QVBoxLayout lay( &dia ); 2500 QVBoxLayout lay( &dia );
2499 lay.setMargin(7); 2501 lay.setMargin(7);
2500 lay.setSpacing(7); 2502 lay.setSpacing(7);
2501 lay.addWidget( &lab); 2503 lay.addWidget( &lab);
2502 dia.setFixedSize( 230,50 ); 2504 dia.setFixedSize( 230,50 );
2503 dia.setCaption( i18n("Enter password") ); 2505 dia.setCaption( i18n("Enter password") );
2504 QPushButton pb ( "OK", &dia); 2506 QPushButton pb ( "OK", &dia);
2505 lay.addWidget( &pb ); 2507 lay.addWidget( &pb );
2506 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2508 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2507 dia.show(); 2509 dia.show();
2508 int res = dia.exec(); 2510 int res = dia.exec();
2509 if ( res ) 2511 if ( res )
2510 retfile = lab.text(); 2512 retfile = lab.text();
2511 dia.hide(); 2513 dia.hide();
2512 qApp->processEvents(); 2514 qApp->processEvents();
2513 return retfile; 2515 return retfile;
2514 2516
2515} 2517}
2516#include <libkcal/syncdefines.h> 2518#include <libkcal/syncdefines.h>
2517 2519
2518KABC::Addressee KABCore::getLastSyncAddressee() 2520KABC::Addressee KABCore::getLastSyncAddressee()
2519{ 2521{
2520 Addressee lse; 2522 Addressee lse;
2521 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2523 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2522 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2524 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2523 if (lse.isEmpty()) { 2525 if (lse.isEmpty()) {
2524 lse.setUid( "last-syncEvent-"+mCurrentSyncDevice ); 2526 lse.setUid( "last-syncEvent-"+mCurrentSyncDevice );
2525 QString sum = ""; 2527 QString sum = "";
2526 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 2528 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
2527 sum = "E: "; 2529 sum = "E: ";
2528 lse.setFamilyName(sum+mCurrentSyncDevice + i18n(" - sync event")); 2530 lse.setFamilyName(sum+mCurrentSyncDevice + i18n(" - sync event"));
2529 lse.setRevision( mLastAddressbookSync ); 2531 lse.setRevision( mLastAddressbookSync );
2530 lse.setCategories( i18n("SyncEvent") ); 2532 lse.setCategories( i18n("SyncEvent") );
2531 mAddressBook->insertAddressee( lse ); 2533 mAddressBook->insertAddressee( lse );
2532 } 2534 }
2533 return lse; 2535 return lse;
2534} 2536}
2535 2537
2536bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2538bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2537{ 2539{
2538 bool syncOK = true; 2540 bool syncOK = true;
2539 int addedAddressee = 0; 2541 int addedAddressee = 0;
2540 int addedAddresseeR = 0; 2542 int addedAddresseeR = 0;
2541 int deletedAddresseeR = 0; 2543 int deletedAddresseeR = 0;
2542 int deletedAddresseeL = 0; 2544 int deletedAddresseeL = 0;
2543 int changedLocal = 0; 2545 int changedLocal = 0;
2544 int changedRemote = 0; 2546 int changedRemote = 0;
2545 //QPtrList<Addressee> el = local->rawAddressees(); 2547 //QPtrList<Addressee> el = local->rawAddressees();
2546 Addressee addresseeR; 2548 Addressee addresseeR;
2547 QString uid; 2549 QString uid;
2548 int take; 2550 int take;
2549 Addressee addresseeL; 2551 Addressee addresseeL;
2550 Addressee addresseeRSync; 2552 Addressee addresseeRSync;
2551 Addressee addresseeLSync; 2553 Addressee addresseeLSync;
2552 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2554 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2553 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2555 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2554 bool fullDateRange = false; 2556 bool fullDateRange = false;
2555 local->resetTempSyncStat(); 2557 local->resetTempSyncStat();
2556 mLastAddressbookSync = QDateTime::currentDateTime(); 2558 mLastAddressbookSync = QDateTime::currentDateTime();
2557 QDateTime modifiedCalendar = mLastAddressbookSync;; 2559 QDateTime modifiedCalendar = mLastAddressbookSync;;
2558 addresseeLSync = getLastSyncAddressee(); 2560 addresseeLSync = getLastSyncAddressee();
2559 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2561 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2560 if ( !addresseeR.isEmpty() ) { 2562 if ( !addresseeR.isEmpty() ) {
2561 addresseeRSync = addresseeR; 2563 addresseeRSync = addresseeR;
2562 remote->removeAddressee(addresseeR ); 2564 remote->removeAddressee(addresseeR );
2563 2565
2564 } else { 2566 } else {
2565 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2567 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2566 addresseeRSync = addresseeLSync ; 2568 addresseeRSync = addresseeLSync ;
2567 } else { 2569 } else {
2568 fullDateRange = true; 2570 fullDateRange = true;
2569 Addressee newAdd; 2571 Addressee newAdd;
2570 addresseeRSync = newAdd; 2572 addresseeRSync = newAdd;
2571 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2573 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2572 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2574 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2573 addresseeRSync.setRevision( mLastAddressbookSync ); 2575 addresseeRSync.setRevision( mLastAddressbookSync );
2574 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2576 addresseeRSync.setCategories( i18n("SyncAddressee") );
2575 } 2577 }
2576 } 2578 }
2577 if ( addresseeLSync.revision() == mLastAddressbookSync ) 2579 if ( addresseeLSync.revision() == mLastAddressbookSync )
2578 fullDateRange = true; 2580 fullDateRange = true;
2579 if ( ! fullDateRange ) { 2581 if ( ! fullDateRange ) {
2580 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2582 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2581 2583
2582 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2584 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2583 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2585 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2584 fullDateRange = true; 2586 fullDateRange = true;
2585 } 2587 }
2586 } 2588 }
2587 if ( fullDateRange ) 2589 if ( fullDateRange )
2588 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2590 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2589 else 2591 else
2590 mLastAddressbookSync = addresseeLSync.revision(); 2592 mLastAddressbookSync = addresseeLSync.revision();
2591 // for resyncing if own file has changed 2593 // for resyncing if own file has changed
2592 // PENDING fixme later when implemented 2594 // PENDING fixme later when implemented
2593#if 0 2595#if 0
2594 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2596 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2595 mLastAddressbookSync = loadedFileVersion; 2597 mLastAddressbookSync = loadedFileVersion;
2596 qDebug("setting mLastAddressbookSync "); 2598 qDebug("setting mLastAddressbookSync ");
2597 } 2599 }
2598#endif 2600#endif
2599 2601
2600 #if 0
2601 //qDebug("*************************** "); 2602 //qDebug("*************************** ");
2602 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2603 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2603 QPtrList<Incidence> er = remote->rawIncidences(); 2604 QStringList er = remote->uidList();
2604 Incidence* inR = er.first(); 2605 Addressee inR ;//= er.first();
2605 Incidence* inL; 2606 Addressee inL;
2606 QProgressBar bar( er.count(),0 ); 2607 QProgressBar bar( er.count(),0 );
2607 bar.setCaption (i18n("Syncing - close to abort!") ); 2608 bar.setCaption (i18n("Syncing - close to abort!") );
2608 2609
2609 int w = 300; 2610 int w = 300;
2610 if ( QApplication::desktop()->width() < 320 ) 2611 if ( QApplication::desktop()->width() < 320 )
2611 w = 220; 2612 w = 220;
2612 int h = bar.sizeHint().height() ; 2613 int h = bar.sizeHint().height() ;
2613 int dw = QApplication::desktop()->width(); 2614 int dw = QApplication::desktop()->width();
2614 int dh = QApplication::desktop()->height(); 2615 int dh = QApplication::desktop()->height();
2615 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2616 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2616 bar.show(); 2617 bar.show();
2617 int modulo = (er.count()/10)+1; 2618 int modulo = (er.count()/10)+1;
2618 int incCounter = 0; 2619 int incCounter = 0;
2619 while ( inR ) { 2620 while ( incCounter < er.count()) {
2620 if ( ! bar.isVisible() ) 2621 if ( ! bar.isVisible() )
2621 return false; 2622 return false;
2622 if ( incCounter % modulo == 0 ) 2623 if ( incCounter % modulo == 0 )
2623 bar.setProgress( incCounter ); 2624 bar.setProgress( incCounter );
2624 ++incCounter; 2625 uid = er[ incCounter ];
2625 uid = inR->uid();
2626 bool skipIncidence = false; 2626 bool skipIncidence = false;
2627 if ( uid.left(15) == QString("last-syncAddressee-") ) 2627 if ( uid.left(20) == QString("last-syncAddressee-") )
2628 skipIncidence = true; 2628 skipIncidence = true;
2629 QString idS; 2629 QString idS;
2630 qApp->processAddressees(); 2630 qApp->processEvents();
2631 if ( !skipIncidence ) { 2631 if ( !skipIncidence ) {
2632 inL = local->incidence( uid ); 2632 inL = local->findByUid( uid );
2633 if ( inL ) { // maybe conflict - same uid in both calendars 2633 inR = remote->findByUid( uid );
2634 int maxrev = inL->revision(); 2634 //inL.setResource( 0 );
2635 if ( maxrev < inR->revision() ) 2635 //inR.setResource( 0 );
2636 maxrev = inR->revision(); 2636 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2637 if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { 2637 // pending if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) {
2638 //qDebug("take %d %s ", take, inL->summary().latin1()); 2638 if ( true ) {
2639 //qDebug("take %d %s ", take, inL.summary().latin1());
2639 if ( take == 3 ) 2640 if ( take == 3 )
2640 return false; 2641 return false;
2641 if ( take == 1 ) {// take local 2642 if ( take == 1 ) {// take local
2642 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2643 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2643 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 2644 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2645 local->insertAddressee( inL );
2646 }
2644 else 2647 else
2645 idS = inR->IDStr(); 2648 idS = inR.IDStr();
2646 remote->deleteIncidence( inR ); 2649 remote->removeAddressee( inR );
2647 if ( inL->revision() < maxrev ) 2650 inR = inL;
2648 inL->setRevision( maxrev ); 2651 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2649 inR = inL->clone();
2650 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2651 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 2652 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
2652 inR->setIDStr( idS ); 2653 inR.setIDStr( idS );
2653 remote->addIncidence( inR ); 2654 inR.setResource( 0 );
2655 remote->insertAddressee( inR );
2654 ++changedRemote; 2656 ++changedRemote;
2655 } else { 2657 } else {
2656 if ( inR->revision() < maxrev ) 2658 idS = inL.IDStr();
2657 inR->setRevision( maxrev ); 2659 local->removeAddressee( inL );
2658 idS = inL->IDStr(); 2660 inL = inR;
2659 local->deleteIncidence( inL ); 2661 inL.setIDStr( idS );
2660 inL = inR->clone(); 2662 inL.setResource( 0 );
2661 inL->setIDStr( idS ); 2663 local->insertAddressee( inL );
2662 local->addIncidence( inL );
2663 ++changedLocal; 2664 ++changedLocal;
2664 } 2665 }
2665 } 2666 }
2666 } else { // no conflict 2667 } else { // no conflict
2667 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2668 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2668 QString des = addresseeLSync->description(); 2669 QString des = addresseeLSync.note();
2669 QString pref = "e"; 2670 QString pref = "a";
2670 if ( inR->type() == "Todo" ) 2671 if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2671 pref = "t"; 2672 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2672 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2673 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2674 //remote->deleteIncidence( inR );
2675 ++deletedAddresseeR; 2673 ++deletedAddresseeR;
2676 } else { 2674 } else {
2677 inR->setLastModified( modifiedCalendar ); 2675 inR.setRevision( modifiedCalendar );
2678 inL = inR->clone(); 2676 remote->insertAddressee( inR );
2679 local->addIncidence( inL ); 2677 inL = inR;
2678 inL.setResource( 0 );
2679 local->insertAddressee( inL );
2680 ++addedAddressee; 2680 ++addedAddressee;
2681 } 2681 }
2682 } else { 2682 } else {
2683 if ( inR->lastModified() > mLastAddressbookSync || mode == 5 ) { 2683 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2684 inR->setLastModified( modifiedCalendar ); 2684 inR.setRevision( modifiedCalendar );
2685 local->addIncidence( inR->clone() ); 2685 remote->insertAddressee( inR );
2686 inR.setResource( 0 );
2687 local->insertAddressee( inR );
2686 ++addedAddressee; 2688 ++addedAddressee;
2687 } else { 2689 } else {
2688 checkExternSyncAddressee(addresseeRSyncSharp, inR); 2690 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2689 remote->deleteIncidence( inR ); 2691 remote->removeAddressee( inR );
2690 ++deletedAddresseeR; 2692 ++deletedAddresseeR;
2691 } 2693 }
2692 } 2694 }
2693 } 2695 }
2694 } 2696 }
2695 inR = er.next(); 2697 ++incCounter;
2696 } 2698 }
2697 QPtrList<Incidence> el = local->rawIncidences(); 2699 er.clear();
2698 inL = el.first(); 2700 QStringList el = remote->uidList();
2699 modulo = (el.count()/10)+1; 2701 modulo = (el.count()/10)+1;
2700 bar.setCaption (i18n("Add / remove addressees") ); 2702 bar.setCaption (i18n("Add / remove addressees") );
2701 bar.setTotalSteps ( el.count() ) ; 2703 bar.setTotalSteps ( el.count() ) ;
2702 bar.show(); 2704 bar.show();
2703 incCounter = 0; 2705 incCounter = 0;
2704 2706 while ( incCounter < el.count()) {
2705 while ( inL ) {
2706 2707
2707 qApp->processAddressees(); 2708 qApp->processEvents();
2708 if ( ! bar.isVisible() ) 2709 if ( ! bar.isVisible() )
2709 return false; 2710 return false;
2710 if ( incCounter % modulo == 0 ) 2711 if ( incCounter % modulo == 0 )
2711 bar.setProgress( incCounter ); 2712 bar.setProgress( incCounter );
2712 ++incCounter; 2713 uid = el[ incCounter ];
2713 uid = inL->uid();
2714 bool skipIncidence = false; 2714 bool skipIncidence = false;
2715 if ( uid.left(15) == QString("last-syncAddressee-") ) 2715 if ( uid.left(20) == QString("last-syncAddressee-") )
2716 skipIncidence = true; 2716 skipIncidence = true;
2717 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 2717 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2718 skipIncidence = true; 2718 skipIncidence = true;
2719 if ( !skipIncidence ) { 2719 if ( !skipIncidence ) {
2720 inR = remote->incidence( uid ); 2720 inL = local->findByUid( uid );
2721 if ( ! inR ) { 2721 inR = remote->findByUid( uid );
2722 if ( inR.isEmpty() ) {
2722 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2723 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2723 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2724 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2724 checkExternSyncAddressee(addresseeLSyncSharp, inL); 2725 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2725 local->deleteIncidence( inL ); 2726 local->removeAddressee( inL );
2726 ++deletedAddresseeL; 2727 ++deletedAddresseeL;
2727 } else { 2728 } else {
2728 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 2729 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2729 inL->removeID(mCurrentSyncDevice ); 2730 inL.removeID(mCurrentSyncDevice );
2730 ++addedAddresseeR; 2731 ++addedAddresseeR;
2731 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 2732 //qDebug("remote added Incidence %s ", inL.summary().latin1());
2732 inL->setLastModified( modifiedCalendar ); 2733 inL.setRevision( modifiedCalendar );
2733 inR = inL->clone(); 2734 local->insertAddressee( inL );
2734 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2735 inR = inL;
2735 remote->addIncidence( inR ); 2736 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2737 inR.setResource( 0 );
2738 remote->insertAddressee( inR );
2736 } 2739 }
2737 } 2740 }
2738 } else { 2741 } else {
2739 if ( inL->lastModified() < mLastAddressbookSync && mode != 4 ) { 2742 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2740 checkExternSyncAddressee(addresseeLSyncSharp, inL); 2743 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2741 local->deleteIncidence( inL ); 2744 local->removeAddressee( inL );
2742 ++deletedAddresseeL; 2745 ++deletedAddresseeL;
2743 } else { 2746 } else {
2744 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 2747 if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
2745 ++addedAddresseeR; 2748 ++addedAddresseeR;
2746 inL->setLastModified( modifiedCalendar ); 2749 inL.setRevision( modifiedCalendar );
2747 remote->addIncidence( inL->clone() ); 2750 local->insertAddressee( inL );
2751 inR = inL;
2752 inR.setResource( 0 );
2753 remote->insertAddressee( inR );
2748 } 2754 }
2749 } 2755 }
2750 } 2756 }
2751 } 2757 }
2752 } 2758 }
2753 inL = el.next(); 2759 ++incCounter;
2754 } 2760 }
2761 el.clear();
2755 int delFut = 0; 2762 int delFut = 0;
2756 if ( KOPrefs::instance()->mWriteBackInFuture ) { 2763
2757 er = remote->rawIncidences(); 2764 #if 0
2758 inR = er.first(); 2765
2759 QDateTime dt;
2760 QDateTime cur = QDateTime::currentDateTime();
2761 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
2762 while ( inR ) {
2763 if ( inR->type() == "Todo" ) {
2764 Todo * t = (Todo*)inR;
2765 if ( t->hasDueDate() )
2766 dt = t->dtDue();
2767 else
2768 dt = cur.addSecs( 62 );
2769 }
2770 else if (inR->type() == "Addressee" ) {
2771 bool ok;
2772 dt = inR->getNextOccurence( cur, &ok );
2773 if ( !ok )
2774 dt = cur.addSecs( -62 );
2775 }
2776 else
2777 dt = inR->dtStart();
2778 if ( dt < cur || dt > end ) {
2779 remote->deleteIncidence( inR );
2780 ++delFut;
2781 }
2782 inR = er.next();
2783 }
2784 }
2785 bar.hide(); 2766 bar.hide();
2786 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2767 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2787 addresseeLSync->setReadOnly( false ); 2768 addresseeLSync.setRevision( mLastAddressbookSync );
2788 addresseeLSync->setDtStart( mLastAddressbookSync ); 2769 addresseeRSync.setRevision( mLastAddressbookSync );
2789 addresseeRSync->setDtStart( mLastAddressbookSync ); 2770 addresseeRSync.setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
2790 addresseeLSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); 2771 addresseeLSync.setLocation(i18n("Local from: ") + mCurrentSyncName );
2791 addresseeRSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); 2772 addresseeLSync.setReadOnly( true );
2792 addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
2793 addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
2794 addresseeLSync->setReadOnly( true );
2795 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2773 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2796 remote->addAddressee( addresseeRSync ); 2774 remote->addAddressee( addresseeRSync );
2797 QString mes; 2775 QString mes;
2798 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 ); 2776 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 );
2799 QString delmess; 2777 QString delmess;
2800 if ( delFut ) { 2778 if ( delFut ) {
2801 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 2779 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
2802 mes += delmess; 2780 mes += delmess;
2803 } 2781 }
2804 if ( KOPrefs::instance()->mShowSyncSummary ) { 2782 if ( KOPrefs::instance()->mShowSyncSummary ) {
2805 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 2783 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
2806 } 2784 }
2807 qDebug( mes ); 2785 qDebug( mes );
2808 mCalendar->checkAlarmForIncidence( 0, true ); 2786 mCalendar->checkAlarmForIncidence( 0, true );
2809 return syncOK; 2787 return syncOK;
2810#endif 2788#endif
2811 return false; 2789 return false;
2812} 2790}
2813bool KABCore::syncAB(QString filename, int mode) 2791bool KABCore::syncAB(QString filename, int mode)
2814{ 2792{
2815 2793
2816 //pending prepare addresseeview for output 2794 //pending prepare addresseeview for output
2817 //pending detect, if remote file has REV field. if not switch to external sync 2795 //pending detect, if remote file has REV field. if not switch to external sync
2818 mGlobalSyncMode = SYNC_MODE_NORMAL; 2796 mGlobalSyncMode = SYNC_MODE_NORMAL;
2819 AddressBook abLocal(filename,"syncContact"); 2797 AddressBook abLocal(filename,"syncContact");
2820 bool syncOK = false; 2798 bool syncOK = false;
2821 if ( abLocal.load() ) { 2799 if ( abLocal.load() ) {
2822 qDebug("AB loaded %s mode %d",filename.latin1(), mode ); 2800 qDebug("AB loaded %s mode %d",filename.latin1(), mode );
2823 AddressBook::Iterator it; 2801 AddressBook::Iterator it;
2824 QStringList vcards; 2802 QStringList vcards;
2825 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2803 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2826 qDebug("Name %s ", (*it).familyName().latin1()); 2804 qDebug("Name %s ", (*it).familyName().latin1());
2827 } 2805 }
2828 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2806 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2829 if ( syncOK ) { 2807 if ( syncOK ) {
2830 if ( KABPrefs::instance()->mWriteBackFile ) 2808 if ( KABPrefs::instance()->mWriteBackFile )
2831 { 2809 {
2832 qDebug("saving remote AB "); 2810 qDebug("saving remote AB ");
2833 abLocal.saveAB(); 2811 abLocal.saveAB();
2834 } 2812 }
2835 } 2813 }
2836 setModified(); 2814 setModified();
2837 2815
2838 } 2816 }
2839 if ( syncOK ) 2817 if ( syncOK )
2840 mViewManager->refreshView(); 2818 mViewManager->refreshView();
2841 return syncOK; 2819 return syncOK;
2842#if 0 2820#if 0
2843 2821
2844 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2822 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2845 getEventViewerDialog()->setSyncMode( true ); 2823 getEventViewerDialog()->setSyncMode( true );
2846 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2824 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2847 getEventViewerDialog()->setSyncMode( false ); 2825 getEventViewerDialog()->setSyncMode( false );
2848 if ( syncOK ) { 2826 if ( syncOK ) {
2849 if ( KOPrefs::instance()->mWriteBackFile ) 2827 if ( KOPrefs::instance()->mWriteBackFile )
2850 { 2828 {
2851 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2829 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2852 storage->save(); 2830 storage->save();
2853 } 2831 }
2854 } 2832 }
2855 setModified(); 2833 setModified();
2856 } 2834 }
2857 2835
2858#endif 2836#endif
2859} 2837}
2860 2838
2861 2839
2862void KABCore::confSync() 2840void KABCore::confSync()
2863{ 2841{
2864 static KSyncPrefsDialog* sp = 0; 2842 static KSyncPrefsDialog* sp = 0;
2865 if ( ! sp ) { 2843 if ( ! sp ) {
2866 sp = new KSyncPrefsDialog( this, "syncprefs", true ); 2844 sp = new KSyncPrefsDialog( this, "syncprefs", true );
2867 } 2845 }
2868 sp->usrReadConfig(); 2846 sp->usrReadConfig();
2869#ifndef DESKTOP_VERSION 2847#ifndef DESKTOP_VERSION
2870 sp->showMaximized(); 2848 sp->showMaximized();
2871#else 2849#else
2872 sp->show(); 2850 sp->show();
2873#endif 2851#endif
2874 sp->exec(); 2852 sp->exec();
2875 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); 2853 KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
2876 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); 2854 KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
2877 fillSyncMenu(); 2855 fillSyncMenu();
2878} 2856}
2879void KABCore::syncSharp() 2857void KABCore::syncSharp()
2880{ 2858{
2881 if ( mModified ) 2859 if ( mModified )
2882 save(); 2860 save();
2883 qDebug("pending syncSharp() "); 2861 qDebug("pending syncSharp() ");
2884 //mView->syncSharp(); 2862 //mView->syncSharp();
2885 setModified(); 2863 setModified();
2886 2864
2887} 2865}
2888void KABCore::syncPhone() 2866void KABCore::syncPhone()
2889{ 2867{
2890 if ( mModified ) 2868 if ( mModified )
2891 save(); 2869 save();
2892 qDebug("pending syncPhone(); "); 2870 qDebug("pending syncPhone(); ");
2893 //mView->syncPhone(); 2871 //mView->syncPhone();
2894 setModified(); 2872 setModified();
2895 2873
2896} 2874}