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