summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp44
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kaddressbook/kabcore.cpp65
-rw-r--r--kaddressbook/kabcore.h3
-rw-r--r--libkcal/phoneformat.cpp12
-rw-r--r--libkdepim/phoneaccess.cpp24
-rw-r--r--libkdepim/phoneaccess.h2
7 files changed, 123 insertions, 30 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16927e2..d037d2f 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1032 +1,1076 @@
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 "addressbook.h" 51#include "addressbook.h"
51#include "resource.h" 52#include "resource.h"
52#include "vcardconverter.h" 53#include "vcardconverter.h"
53#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
54 55
55//US #include "addressbook.moc" 56//US #include "addressbook.moc"
56 57
57using namespace KABC; 58using namespace KABC;
58 59
59struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
60{ 61{
61 Addressee::List mAddressees; 62 Addressee::List mAddressees;
62 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
63 Field::List mAllFields; 64 Field::List mAllFields;
64 KConfig *mConfig; 65 KConfig *mConfig;
65 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
66//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
67}; 68};
68 69
69struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
70{ 71{
71 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
72}; 73};
73 74
74struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
75{ 76{
76 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
77}; 78};
78 79
79AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
80{ 81{
81 d = new IteratorData; 82 d = new IteratorData;
82} 83}
83 84
84AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
85{ 86{
86 d = new IteratorData; 87 d = new IteratorData;
87 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
88} 89}
89 90
90AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
91{ 92{
92 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
93 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
94 d = new IteratorData; 95 d = new IteratorData;
95 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
96 return *this; 97 return *this;
97} 98}
98 99
99AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
100{ 101{
101 delete d; 102 delete d;
102} 103}
103 104
104const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
105{ 106{
106 return *(d->mIt); 107 return *(d->mIt);
107} 108}
108 109
109Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
110{ 111{
111 return *(d->mIt); 112 return *(d->mIt);
112} 113}
113 114
114Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
115{ 116{
116 return &(*(d->mIt)); 117 return &(*(d->mIt));
117} 118}
118 119
119AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
120{ 121{
121 (d->mIt)++; 122 (d->mIt)++;
122 return *this; 123 return *this;
123} 124}
124 125
125AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
126{ 127{
127 (d->mIt)++; 128 (d->mIt)++;
128 return *this; 129 return *this;
129} 130}
130 131
131AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
132{ 133{
133 (d->mIt)--; 134 (d->mIt)--;
134 return *this; 135 return *this;
135} 136}
136 137
137AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
138{ 139{
139 (d->mIt)--; 140 (d->mIt)--;
140 return *this; 141 return *this;
141} 142}
142 143
143bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
144{ 145{
145 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
146} 147}
147 148
148bool AddressBook::Iterator::operator!=( const Iterator &it ) 149bool AddressBook::Iterator::operator!=( const Iterator &it )
149{ 150{
150 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
151} 152}
152 153
153 154
154AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
155{ 156{
156 d = new ConstIteratorData; 157 d = new ConstIteratorData;
157} 158}
158 159
159AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
160{ 161{
161 d = new ConstIteratorData; 162 d = new ConstIteratorData;
162 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
163} 164}
164 165
165AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
166{ 167{
167 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
168 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
169 d = new ConstIteratorData; 170 d = new ConstIteratorData;
170 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
171 return *this; 172 return *this;
172} 173}
173 174
174AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
175{ 176{
176 delete d; 177 delete d;
177} 178}
178 179
179const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
180{ 181{
181 return *(d->mIt); 182 return *(d->mIt);
182} 183}
183 184
184const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
185{ 186{
186 return &(*(d->mIt)); 187 return &(*(d->mIt));
187} 188}
188 189
189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
190{ 191{
191 (d->mIt)++; 192 (d->mIt)++;
192 return *this; 193 return *this;
193} 194}
194 195
195AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
196{ 197{
197 (d->mIt)++; 198 (d->mIt)++;
198 return *this; 199 return *this;
199} 200}
200 201
201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
202{ 203{
203 (d->mIt)--; 204 (d->mIt)--;
204 return *this; 205 return *this;
205} 206}
206 207
207AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
208{ 209{
209 (d->mIt)--; 210 (d->mIt)--;
210 return *this; 211 return *this;
211} 212}
212 213
213bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
214{ 215{
215 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
216} 217}
217 218
218bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
219{ 220{
220 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
221} 222}
222 223
223 224
224AddressBook::AddressBook() 225AddressBook::AddressBook()
225{ 226{
226 init(0, "contact"); 227 init(0, "contact");
227} 228}
228 229
229AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
230{ 231{
231 init(config, "contact"); 232 init(config, "contact");
232} 233}
233 234
234AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
235{ 236{
236 init(config, family); 237 init(config, family);
237 238
238} 239}
239 240
240// the default family is "contact" 241// the default family is "contact"
241void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
242{ 243{
243 blockLSEchange = false; 244 blockLSEchange = false;
244 d = new AddressBookData; 245 d = new AddressBookData;
245 QString fami = family; 246 QString fami = family;
246 if (config != 0) { 247 if (config != 0) {
247 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
248 qDebug("creating sync config "); 249 qDebug("creating sync config ");
249 fami = "contact"; 250 fami = "contact";
250 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
251 con->setGroup( "General" ); 252 con->setGroup( "General" );
252 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
253 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
254 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
255 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
256 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
257 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
258 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
259 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
260 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
261 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
262 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
263 } else { 264 } else {
264 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
265 } 266 }
266 //con->sync(); 267 //con->sync();
267 d->mConfig = con; 268 d->mConfig = con;
268 } 269 }
269 else 270 else
270 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
271// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
272 } 273 }
273 else { 274 else {
274 d->mConfig = 0; 275 d->mConfig = 0;
275// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
276 } 277 }
277 278
278//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
279 d->mManager = new KRES::Manager<Resource>( fami, false ); 280 d->mManager = new KRES::Manager<Resource>( fami, false );
280 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
281 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
282 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
283 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
284 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
285 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
286 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
287 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
288 } 289 }
289 Resource *res = standardResource(); 290 Resource *res = standardResource();
290 if ( !res ) { 291 if ( !res ) {
291 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
292 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
293 if ( res ) 294 if ( res )
294 { 295 {
295 addResource( res ); 296 addResource( res );
296 } 297 }
297 else 298 else
298 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
299 } 300 }
300 setStandardResource( res ); 301 setStandardResource( res );
301 manager->writeConfig(); 302 manager->writeConfig();
302 } 303 }
303 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
304 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
305 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
306 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
307 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
308 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
309 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
310 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
311 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
312 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
313 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
314 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
315 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
316 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
317 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
318 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
319 320
320 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
321 // 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.
322 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
323 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
324 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
325 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
326 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
327 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
328 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
329 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
330} 331}
331 332
332AddressBook::~AddressBook() 333AddressBook::~AddressBook()
333{ 334{
334 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
335 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
336//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
337 delete d; d = 0; 338 delete d; d = 0;
338} 339}
339 340
340bool AddressBook::load() 341bool AddressBook::load()
341{ 342{
342 343
343 344
344 clear(); 345 clear();
345 346
346 KRES::Manager<Resource>::ActiveIterator it; 347 KRES::Manager<Resource>::ActiveIterator it;
347 bool ok = true; 348 bool ok = true;
348 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 349 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
349 if ( !(*it)->load() ) { 350 if ( !(*it)->load() ) {
350 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 351 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
351 ok = false; 352 ok = false;
352 } 353 }
353 354
354 // mark all addressees as unchanged 355 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 356 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 357 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 358 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 359 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 360 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 361 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 362 (*addrIt).setIDStr(id );
362 } 363 }
363 } 364 }
364 blockLSEchange = true; 365 blockLSEchange = true;
365 return ok; 366 return ok;
366} 367}
367 368
368bool AddressBook::save( Ticket *ticket ) 369bool AddressBook::save( Ticket *ticket )
369{ 370{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 371 kdDebug(5700) << "AddressBook::save()"<< endl;
371 372
372 if ( ticket->resource() ) { 373 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 374 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 375 return ticket->resource()->save( ticket );
375 } 376 }
376 377
377 return false; 378 return false;
378} 379}
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).IDStr().isEmpty() ) {
395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 396 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
396 } 397 }
397 KABC::VCardConverter converter; 398 KABC::VCardConverter converter;
398 QString vcard; 399 QString vcard;
399 //Resource *resource() const; 400 //Resource *resource() const;
400 converter.addresseeToVCard( *it, vcard, version ); 401 converter.addresseeToVCard( *it, vcard, version );
401 t << vcard << "\r\n"; 402 t << vcard << "\r\n";
402 } 403 }
403 t << "\r\n\r\n"; 404 t << "\r\n\r\n";
404 outFile.close(); 405 outFile.close();
405} 406}
406void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 407void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
407{ 408{
408 409
409 if ( removeOld ) 410 if ( removeOld )
410 setUntagged(); 411 setUntagged();
411 KABC::Addressee::List list; 412 KABC::Addressee::List list;
412 QFile file( fileName ); 413 QFile file( fileName );
413 file.open( IO_ReadOnly ); 414 file.open( IO_ReadOnly );
414 QByteArray rawData = file.readAll(); 415 QByteArray rawData = file.readAll();
415 file.close(); 416 file.close();
416 QString data; 417 QString data;
417 if ( replaceLabel ) { 418 if ( replaceLabel ) {
418 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 419 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
419 data.replace ( QRegExp("LABEL") , "ADR" ); 420 data.replace ( QRegExp("LABEL") , "ADR" );
420 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 421 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
421 } else 422 } else
422 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 423 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
423 KABC::VCardTool tool; 424 KABC::VCardTool tool;
424 list = tool.parseVCards( data ); 425 list = tool.parseVCards( data );
425 KABC::Addressee::List::Iterator it; 426 KABC::Addressee::List::Iterator it;
426 for ( it = list.begin(); it != list.end(); ++it ) { 427 for ( it = list.begin(); it != list.end(); ++it ) {
427 (*it).setResource( 0 ); 428 (*it).setResource( 0 );
428 if ( replaceLabel ) 429 if ( replaceLabel )
429 (*it).removeVoice(); 430 (*it).removeVoice();
430 if ( removeOld ) 431 if ( removeOld )
431 (*it).setTagged( true ); 432 (*it).setTagged( true );
432 insertAddressee( (*it), false, true ); 433 insertAddressee( (*it), false, true );
433 } 434 }
434 if ( removeOld ) 435 if ( removeOld )
435 removeUntagged(); 436 removeUntagged();
436} 437}
437void AddressBook::setUntagged() 438void AddressBook::setUntagged()
438{ 439{
439 Iterator ait; 440 Iterator ait;
440 for ( ait = begin(); ait != end(); ++ait ) { 441 for ( ait = begin(); ait != end(); ++ait ) {
441 (*ait).setTagged( false ); 442 (*ait).setTagged( false );
442 } 443 }
443} 444}
444void AddressBook::removeUntagged() 445void AddressBook::removeUntagged()
445{ 446{
446 Iterator ait; 447 Iterator ait;
447 bool todelete = false; 448 bool todelete = false;
448 Iterator todel; 449 Iterator todel;
449 for ( ait = begin(); ait != end(); ++ait ) { 450 for ( ait = begin(); ait != end(); ++ait ) {
450 if ( todelete ) 451 if ( todelete )
451 removeAddressee( todel ); 452 removeAddressee( todel );
452 if (!(*ait).tagged()) { 453 if (!(*ait).tagged()) {
453 todelete = true; 454 todelete = true;
454 todel = ait; 455 todel = ait;
455 } else 456 } else
456 todelete = false; 457 todelete = false;
457 } 458 }
458 if ( todelete ) 459 if ( todelete )
459 removeAddressee( todel ); 460 removeAddressee( todel );
460 deleteRemovedAddressees(); 461 deleteRemovedAddressees();
461} 462}
463void AddressBook::smplifyAddressees()
464{
465 Iterator ait;
466 for ( ait = begin(); ait != end(); ++ait ) {
467 (*ait).simplifyEmails();
468 (*ait).simplifyPhoneNumbers();
469 (*ait).simplifyPhoneNumberTypes();
470 (*ait).simplifyAddresses();
471 }
472}
473void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
474{
475 Iterator ait;
476 for ( ait = begin(); ait != end(); ++ait ) {
477 QString id = (*ait).IDStr();
478 (*ait).setIDStr( ":");
479 (*ait).setExternalUID( id );
480 (*ait).setOriginalExternalUID( id );
481 if ( isPreSync )
482 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
483 else
484 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
485 }
486}
487bool AddressBook::saveABphone( QString fileName )
488{
489 smplifyAddressees();
490 qDebug("saveABphone:: saving AB... ");
491 if ( ! saveAB() )
492 return false;
493 qDebug("saveABphone:: writing to phone... ");
494 if ( !PhoneAccess::writeToPhone( fileName) ) {
495 return false;
496 }
497 qDebug("saveABphone:: re-reading from phone... ");
498 if ( !PhoneAccess::readFromPhone( fileName) ) {
499 return false;
500 }
501 qDebug("reloading phone book... ");
502 if ( !load() )
503 return false;
504 return true;
505}
462bool AddressBook::saveAB() 506bool AddressBook::saveAB()
463{ 507{
464 bool ok = true; 508 bool ok = true;
465 509
466 deleteRemovedAddressees(); 510 deleteRemovedAddressees();
467 Iterator ait; 511 Iterator ait;
468 for ( ait = begin(); ait != end(); ++ait ) { 512 for ( ait = begin(); ait != end(); ++ait ) {
469 if ( !(*ait).IDStr().isEmpty() ) { 513 if ( !(*ait).IDStr().isEmpty() ) {
470 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 514 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
471 } 515 }
472 } 516 }
473 KRES::Manager<Resource>::ActiveIterator it; 517 KRES::Manager<Resource>::ActiveIterator it;
474 KRES::Manager<Resource> *manager = d->mManager; 518 KRES::Manager<Resource> *manager = d->mManager;
475 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 519 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
476 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 520 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
477 Ticket *ticket = requestSaveTicket( *it ); 521 Ticket *ticket = requestSaveTicket( *it );
478// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 522// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
479 if ( !ticket ) { 523 if ( !ticket ) {
480 error( i18n( "Unable to save to resource '%1'. It is locked." ) 524 error( i18n( "Unable to save to resource '%1'. It is locked." )
481 .arg( (*it)->resourceName() ) ); 525 .arg( (*it)->resourceName() ) );
482 return false; 526 return false;
483 } 527 }
484 528
485 //if ( !save( ticket ) ) 529 //if ( !save( ticket ) )
486 if ( ticket->resource() ) { 530 if ( ticket->resource() ) {
487 if ( ! ticket->resource()->save( ticket ) ) 531 if ( ! ticket->resource()->save( ticket ) )
488 ok = false; 532 ok = false;
489 } else 533 } else
490 ok = false; 534 ok = false;
491 535
492 } 536 }
493 } 537 }
494 return ok; 538 return ok;
495} 539}
496 540
497AddressBook::Iterator AddressBook::begin() 541AddressBook::Iterator AddressBook::begin()
498{ 542{
499 Iterator it = Iterator(); 543 Iterator it = Iterator();
500 it.d->mIt = d->mAddressees.begin(); 544 it.d->mIt = d->mAddressees.begin();
501 return it; 545 return it;
502} 546}
503 547
504AddressBook::ConstIterator AddressBook::begin() const 548AddressBook::ConstIterator AddressBook::begin() const
505{ 549{
506 ConstIterator it = ConstIterator(); 550 ConstIterator it = ConstIterator();
507 it.d->mIt = d->mAddressees.begin(); 551 it.d->mIt = d->mAddressees.begin();
508 return it; 552 return it;
509} 553}
510 554
511AddressBook::Iterator AddressBook::end() 555AddressBook::Iterator AddressBook::end()
512{ 556{
513 Iterator it = Iterator(); 557 Iterator it = Iterator();
514 it.d->mIt = d->mAddressees.end(); 558 it.d->mIt = d->mAddressees.end();
515 return it; 559 return it;
516} 560}
517 561
518AddressBook::ConstIterator AddressBook::end() const 562AddressBook::ConstIterator AddressBook::end() const
519{ 563{
520 ConstIterator it = ConstIterator(); 564 ConstIterator it = ConstIterator();
521 it.d->mIt = d->mAddressees.end(); 565 it.d->mIt = d->mAddressees.end();
522 return it; 566 return it;
523} 567}
524 568
525void AddressBook::clear() 569void AddressBook::clear()
526{ 570{
527 d->mAddressees.clear(); 571 d->mAddressees.clear();
528} 572}
529 573
530Ticket *AddressBook::requestSaveTicket( Resource *resource ) 574Ticket *AddressBook::requestSaveTicket( Resource *resource )
531{ 575{
532 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 576 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
533 577
534 if ( !resource ) 578 if ( !resource )
535 { 579 {
536 qDebug("AddressBook::requestSaveTicket no resource" ); 580 qDebug("AddressBook::requestSaveTicket no resource" );
537 resource = standardResource(); 581 resource = standardResource();
538 } 582 }
539 583
540 KRES::Manager<Resource>::ActiveIterator it; 584 KRES::Manager<Resource>::ActiveIterator it;
541 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 585 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
542 if ( (*it) == resource ) { 586 if ( (*it) == resource ) {
543 if ( (*it)->readOnly() || !(*it)->isOpen() ) 587 if ( (*it)->readOnly() || !(*it)->isOpen() )
544 return 0; 588 return 0;
545 else 589 else
546 return (*it)->requestSaveTicket(); 590 return (*it)->requestSaveTicket();
547 } 591 }
548 } 592 }
549 593
550 return 0; 594 return 0;
551} 595}
552 596
553void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 597void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
554{ 598{
555 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 599 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
556 //qDebug("block insert "); 600 //qDebug("block insert ");
557 return; 601 return;
558 } 602 }
559 //qDebug("inserting.... %s ",a.uid().latin1() ); 603 //qDebug("inserting.... %s ",a.uid().latin1() );
560 bool found = false; 604 bool found = false;
561 Addressee::List::Iterator it; 605 Addressee::List::Iterator it;
562 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 606 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
563 if ( a.uid() == (*it).uid() ) { 607 if ( a.uid() == (*it).uid() ) {
564 608
565 bool changed = false; 609 bool changed = false;
566 Addressee addr = a; 610 Addressee addr = a;
567 if ( addr != (*it) ) 611 if ( addr != (*it) )
568 changed = true; 612 changed = true;
569 613
570 if ( takeResource ) { 614 if ( takeResource ) {
571 Resource * res = (*it).resource(); 615 Resource * res = (*it).resource();
572 (*it) = a; 616 (*it) = a;
573 (*it).setResource( res ); 617 (*it).setResource( res );
574 } else { 618 } else {
575 (*it) = a; 619 (*it) = a;
576 if ( (*it).resource() == 0 ) 620 if ( (*it).resource() == 0 )
577 (*it).setResource( standardResource() ); 621 (*it).setResource( standardResource() );
578 } 622 }
579 if ( changed ) { 623 if ( changed ) {
580 if ( setRev ) { 624 if ( setRev ) {
581 625
582 // get rid of micro seconds 626 // get rid of micro seconds
583 QDateTime dt = QDateTime::currentDateTime(); 627 QDateTime dt = QDateTime::currentDateTime();
584 QTime t = dt.time(); 628 QTime t = dt.time();
585 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 629 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
586 (*it).setRevision( dt ); 630 (*it).setRevision( dt );
587 } 631 }
588 (*it).setChanged( true ); 632 (*it).setChanged( true );
589 } 633 }
590 634
591 found = true; 635 found = true;
592 } else { 636 } else {
593 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 637 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
594 QString name = (*it).uid().mid( 19 ); 638 QString name = (*it).uid().mid( 19 );
595 Addressee b = a; 639 Addressee b = a;
596 QString id = b.getID( name ); 640 QString id = b.getID( name );
597 if ( ! id.isEmpty() ) { 641 if ( ! id.isEmpty() ) {
598 QString des = (*it).note(); 642 QString des = (*it).note();
599 int startN; 643 int startN;
600 if( (startN = des.find( id ) ) >= 0 ) { 644 if( (startN = des.find( id ) ) >= 0 ) {
601 int endN = des.find( ",", startN+1 ); 645 int endN = des.find( ",", startN+1 );
602 des = des.left( startN ) + des.mid( endN+1 ); 646 des = des.left( startN ) + des.mid( endN+1 );
603 (*it).setNote( des ); 647 (*it).setNote( des );
604 } 648 }
605 } 649 }
606 } 650 }
607 } 651 }
608 } 652 }
609 if ( found ) 653 if ( found )
610 return; 654 return;
611 d->mAddressees.append( a ); 655 d->mAddressees.append( a );
612 Addressee& addr = d->mAddressees.last(); 656 Addressee& addr = d->mAddressees.last();
613 if ( addr.resource() == 0 ) 657 if ( addr.resource() == 0 )
614 addr.setResource( standardResource() ); 658 addr.setResource( standardResource() );
615 659
616 addr.setChanged( true ); 660 addr.setChanged( true );
617} 661}
618 662
619void AddressBook::removeAddressee( const Addressee &a ) 663void AddressBook::removeAddressee( const Addressee &a )
620{ 664{
621 Iterator it; 665 Iterator it;
622 Iterator it2; 666 Iterator it2;
623 bool found = false; 667 bool found = false;
624 for ( it = begin(); it != end(); ++it ) { 668 for ( it = begin(); it != end(); ++it ) {
625 if ( a.uid() == (*it).uid() ) { 669 if ( a.uid() == (*it).uid() ) {
626 found = true; 670 found = true;
627 it2 = it; 671 it2 = it;
628 } else { 672 } else {
629 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 673 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
630 QString name = (*it).uid().mid( 19 ); 674 QString name = (*it).uid().mid( 19 );
631 Addressee b = a; 675 Addressee b = a;
632 QString id = b.getID( name ); 676 QString id = b.getID( name );
633 if ( ! id.isEmpty() ) { 677 if ( ! id.isEmpty() ) {
634 QString des = (*it).note(); 678 QString des = (*it).note();
635 if( des.find( id ) < 0 ) { 679 if( des.find( id ) < 0 ) {
636 des += id + ","; 680 des += id + ",";
637 (*it).setNote( des ); 681 (*it).setNote( des );
638 } 682 }
639 } 683 }
640 } 684 }
641 685
642 } 686 }
643 } 687 }
644 688
645 if ( found ) 689 if ( found )
646 removeAddressee( it2 ); 690 removeAddressee( it2 );
647 691
648} 692}
649 693
650void AddressBook::removeSyncAddressees( bool removeDeleted ) 694void AddressBook::removeSyncAddressees( bool removeDeleted )
651{ 695{
652 Iterator it = begin(); 696 Iterator it = begin();
653 Iterator it2 ; 697 Iterator it2 ;
654 QDateTime dt ( QDate( 2004,1,1) ); 698 QDateTime dt ( QDate( 2004,1,1) );
655 while ( it != end() ) { 699 while ( it != end() ) {
656 (*it).setRevision( dt ); 700 (*it).setRevision( dt );
657 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 701 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
658 (*it).setIDStr(""); 702 (*it).setIDStr("");
659 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 703 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
660 it2 = it; 704 it2 = it;
661 //qDebug("removing %s ",(*it).uid().latin1() ); 705 //qDebug("removing %s ",(*it).uid().latin1() );
662 ++it; 706 ++it;
663 removeAddressee( it2 ); 707 removeAddressee( it2 );
664 } else { 708 } else {
665 //qDebug("skipping %s ",(*it).uid().latin1() ); 709 //qDebug("skipping %s ",(*it).uid().latin1() );
666 ++it; 710 ++it;
667 } 711 }
668 } 712 }
669 deleteRemovedAddressees(); 713 deleteRemovedAddressees();
670} 714}
671 715
672void AddressBook::removeAddressee( const Iterator &it ) 716void AddressBook::removeAddressee( const Iterator &it )
673{ 717{
674 d->mRemovedAddressees.append( (*it) ); 718 d->mRemovedAddressees.append( (*it) );
675 d->mAddressees.remove( it.d->mIt ); 719 d->mAddressees.remove( it.d->mIt );
676} 720}
677 721
678AddressBook::Iterator AddressBook::find( const Addressee &a ) 722AddressBook::Iterator AddressBook::find( const Addressee &a )
679{ 723{
680 Iterator it; 724 Iterator it;
681 for ( it = begin(); it != end(); ++it ) { 725 for ( it = begin(); it != end(); ++it ) {
682 if ( a.uid() == (*it).uid() ) { 726 if ( a.uid() == (*it).uid() ) {
683 return it; 727 return it;
684 } 728 }
685 } 729 }
686 return end(); 730 return end();
687} 731}
688 732
689Addressee AddressBook::findByUid( const QString &uid ) 733Addressee AddressBook::findByUid( const QString &uid )
690{ 734{
691 Iterator it; 735 Iterator it;
692 for ( it = begin(); it != end(); ++it ) { 736 for ( it = begin(); it != end(); ++it ) {
693 if ( uid == (*it).uid() ) { 737 if ( uid == (*it).uid() ) {
694 return *it; 738 return *it;
695 } 739 }
696 } 740 }
697 return Addressee(); 741 return Addressee();
698} 742}
699void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) 743void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
700{ 744{
701 //qDebug("AddressBook::preExternSync "); 745 //qDebug("AddressBook::preExternSync ");
702 AddressBook::Iterator it; 746 AddressBook::Iterator it;
703 for ( it = begin(); it != end(); ++it ) { 747 for ( it = begin(); it != end(); ++it ) {
704 (*it).setID( csd, (*it).externalUID() ); 748 (*it).setID( csd, (*it).externalUID() );
705 (*it).computeCsum( csd ); 749 (*it).computeCsum( csd );
706 } 750 }
707 mergeAB( aBook ,csd ); 751 mergeAB( aBook ,csd );
708} 752}
709void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 753void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
710{ 754{
711 //qDebug("AddressBook::postExternSync "); 755 //qDebug("AddressBook::postExternSync ");
712 AddressBook::Iterator it; 756 AddressBook::Iterator it;
713 for ( it = begin(); it != end(); ++it ) { 757 for ( it = begin(); it != end(); ++it ) {
714 // qDebug("check uid %s ", (*it).uid().latin1() ); 758 // qDebug("check uid %s ", (*it).uid().latin1() );
715 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 759 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
716 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 760 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
717 Addressee ad = aBook->findByUid( ( (*it).uid() )); 761 Addressee ad = aBook->findByUid( ( (*it).uid() ));
718 if ( ad.isEmpty() ) { 762 if ( ad.isEmpty() ) {
719 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 763 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
720 } else { 764 } else {
721 (*it).computeCsum( csd ); 765 (*it).computeCsum( csd );
722 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 766 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
723 ad.setID( csd, (*it).externalUID() ); 767 ad.setID( csd, (*it).externalUID() );
724 ad.setCsum( csd, (*it).getCsum( csd ) ); 768 ad.setCsum( csd, (*it).getCsum( csd ) );
725 aBook->insertAddressee( ad ); 769 aBook->insertAddressee( ad );
726 } 770 }
727 } 771 }
728 } 772 }
729} 773}
730 774
731bool AddressBook::containsExternalUid( const QString& uid ) 775bool AddressBook::containsExternalUid( const QString& uid )
732{ 776{
733 Iterator it; 777 Iterator it;
734 for ( it = begin(); it != end(); ++it ) { 778 for ( it = begin(); it != end(); ++it ) {
735 if ( uid == (*it).externalUID( ) ) 779 if ( uid == (*it).externalUID( ) )
736 return true; 780 return true;
737 } 781 }
738 return false; 782 return false;
739} 783}
740Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 784Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
741{ 785{
742 Iterator it; 786 Iterator it;
743 for ( it = begin(); it != end(); ++it ) { 787 for ( it = begin(); it != end(); ++it ) {
744 if ( uid == (*it).getID( profile ) ) 788 if ( uid == (*it).getID( profile ) )
745 return (*it); 789 return (*it);
746 } 790 }
747 return Addressee(); 791 return Addressee();
748} 792}
749void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) 793void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
750{ 794{
751 Iterator it; 795 Iterator it;
752 Addressee ad; 796 Addressee ad;
753 for ( it = begin(); it != end(); ++it ) { 797 for ( it = begin(); it != end(); ++it ) {
754 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 798 ad = aBook->findByExternUid( (*it).externalUID(), profile );
755 if ( !ad.isEmpty() ) { 799 if ( !ad.isEmpty() ) {
756 (*it).mergeContact( ad ); 800 (*it).mergeContact( ad );
757 } 801 }
758 } 802 }
759#if 0 803#if 0
760 // test only 804 // test only
761 for ( it = begin(); it != end(); ++it ) { 805 for ( it = begin(); it != end(); ++it ) {
762 806
763 qDebug("uid %s ", (*it).uid().latin1()); 807 qDebug("uid %s ", (*it).uid().latin1());
764 } 808 }
765#endif 809#endif
766} 810}
767 811
768#if 0 812#if 0
769Addressee::List AddressBook::getExternLastSyncAddressees() 813Addressee::List AddressBook::getExternLastSyncAddressees()
770{ 814{
771 Addressee::List results; 815 Addressee::List results;
772 816
773 Iterator it; 817 Iterator it;
774 for ( it = begin(); it != end(); ++it ) { 818 for ( it = begin(); it != end(); ++it ) {
775 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 819 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
776 if ( (*it).familyName().left(4) == "!E: " ) 820 if ( (*it).familyName().left(4) == "!E: " )
777 results.append( *it ); 821 results.append( *it );
778 } 822 }
779 } 823 }
780 824
781 return results; 825 return results;
782} 826}
783#endif 827#endif
784void AddressBook::resetTempSyncStat() 828void AddressBook::resetTempSyncStat()
785{ 829{
786 Iterator it; 830 Iterator it;
787 for ( it = begin(); it != end(); ++it ) { 831 for ( it = begin(); it != end(); ++it ) {
788 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 832 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
789 } 833 }
790 834
791} 835}
792 836
793QStringList AddressBook:: uidList() 837QStringList AddressBook:: uidList()
794{ 838{
795 QStringList results; 839 QStringList results;
796 Iterator it; 840 Iterator it;
797 for ( it = begin(); it != end(); ++it ) { 841 for ( it = begin(); it != end(); ++it ) {
798 results.append( (*it).uid() ); 842 results.append( (*it).uid() );
799 } 843 }
800 return results; 844 return results;
801} 845}
802 846
803 847
804Addressee::List AddressBook::allAddressees() 848Addressee::List AddressBook::allAddressees()
805{ 849{
806 return d->mAddressees; 850 return d->mAddressees;
807 851
808} 852}
809 853
810Addressee::List AddressBook::findByName( const QString &name ) 854Addressee::List AddressBook::findByName( const QString &name )
811{ 855{
812 Addressee::List results; 856 Addressee::List results;
813 857
814 Iterator it; 858 Iterator it;
815 for ( it = begin(); it != end(); ++it ) { 859 for ( it = begin(); it != end(); ++it ) {
816 if ( name == (*it).realName() ) { 860 if ( name == (*it).realName() ) {
817 results.append( *it ); 861 results.append( *it );
818 } 862 }
819 } 863 }
820 864
821 return results; 865 return results;
822} 866}
823 867
824Addressee::List AddressBook::findByEmail( const QString &email ) 868Addressee::List AddressBook::findByEmail( const QString &email )
825{ 869{
826 Addressee::List results; 870 Addressee::List results;
827 QStringList mailList; 871 QStringList mailList;
828 872
829 Iterator it; 873 Iterator it;
830 for ( it = begin(); it != end(); ++it ) { 874 for ( it = begin(); it != end(); ++it ) {
831 mailList = (*it).emails(); 875 mailList = (*it).emails();
832 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 876 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
833 if ( email == (*ite) ) { 877 if ( email == (*ite) ) {
834 results.append( *it ); 878 results.append( *it );
835 } 879 }
836 } 880 }
837 } 881 }
838 882
839 return results; 883 return results;
840} 884}
841 885
842Addressee::List AddressBook::findByCategory( const QString &category ) 886Addressee::List AddressBook::findByCategory( const QString &category )
843{ 887{
844 Addressee::List results; 888 Addressee::List results;
845 889
846 Iterator it; 890 Iterator it;
847 for ( it = begin(); it != end(); ++it ) { 891 for ( it = begin(); it != end(); ++it ) {
848 if ( (*it).hasCategory( category) ) { 892 if ( (*it).hasCategory( category) ) {
849 results.append( *it ); 893 results.append( *it );
850 } 894 }
851 } 895 }
852 896
853 return results; 897 return results;
854} 898}
855 899
856void AddressBook::dump() const 900void AddressBook::dump() const
857{ 901{
858 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 902 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
859 903
860 ConstIterator it; 904 ConstIterator it;
861 for( it = begin(); it != end(); ++it ) { 905 for( it = begin(); it != end(); ++it ) {
862 (*it).dump(); 906 (*it).dump();
863 } 907 }
864 908
865 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 909 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
866} 910}
867 911
868QString AddressBook::identifier() 912QString AddressBook::identifier()
869{ 913{
870 QStringList identifier; 914 QStringList identifier;
871 915
872 916
873 KRES::Manager<Resource>::ActiveIterator it; 917 KRES::Manager<Resource>::ActiveIterator it;
874 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 918 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
875 if ( !(*it)->identifier().isEmpty() ) 919 if ( !(*it)->identifier().isEmpty() )
876 identifier.append( (*it)->identifier() ); 920 identifier.append( (*it)->identifier() );
877 } 921 }
878 922
879 return identifier.join( ":" ); 923 return identifier.join( ":" );
880} 924}
881 925
882Field::List AddressBook::fields( int category ) 926Field::List AddressBook::fields( int category )
883{ 927{
884 if ( d->mAllFields.isEmpty() ) { 928 if ( d->mAllFields.isEmpty() ) {
885 d->mAllFields = Field::allFields(); 929 d->mAllFields = Field::allFields();
886 } 930 }
887 931
888 if ( category == Field::All ) return d->mAllFields; 932 if ( category == Field::All ) return d->mAllFields;
889 933
890 Field::List result; 934 Field::List result;
891 Field::List::ConstIterator it; 935 Field::List::ConstIterator it;
892 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 936 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
893 if ( (*it)->category() & category ) result.append( *it ); 937 if ( (*it)->category() & category ) result.append( *it );
894 } 938 }
895 939
896 return result; 940 return result;
897} 941}
898 942
899bool AddressBook::addCustomField( const QString &label, int category, 943bool AddressBook::addCustomField( const QString &label, int category,
900 const QString &key, const QString &app ) 944 const QString &key, const QString &app )
901{ 945{
902 if ( d->mAllFields.isEmpty() ) { 946 if ( d->mAllFields.isEmpty() ) {
903 d->mAllFields = Field::allFields(); 947 d->mAllFields = Field::allFields();
904 } 948 }
905//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 949//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
906 QString a = app.isNull() ? KGlobal::getAppName() : app; 950 QString a = app.isNull() ? KGlobal::getAppName() : app;
907 951
908 QString k = key.isNull() ? label : key; 952 QString k = key.isNull() ? label : key;
909 953
910 Field *field = Field::createCustomField( label, category, k, a ); 954 Field *field = Field::createCustomField( label, category, k, a );
911 955
912 if ( !field ) return false; 956 if ( !field ) return false;
913 957
914 d->mAllFields.append( field ); 958 d->mAllFields.append( field );
915 959
916 return true; 960 return true;
917} 961}
918 962
919QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 963QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
920{ 964{
921 if (!ab.d) return s; 965 if (!ab.d) return s;
922 966
923 return s << ab.d->mAddressees; 967 return s << ab.d->mAddressees;
924} 968}
925 969
926QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 970QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
927{ 971{
928 if (!ab.d) return s; 972 if (!ab.d) return s;
929 973
930 s >> ab.d->mAddressees; 974 s >> ab.d->mAddressees;
931 975
932 return s; 976 return s;
933} 977}
934 978
935bool AddressBook::addResource( Resource *resource ) 979bool AddressBook::addResource( Resource *resource )
936{ 980{
937 if ( !resource->open() ) { 981 if ( !resource->open() ) {
938 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 982 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
939 return false; 983 return false;
940 } 984 }
941 985
942 resource->setAddressBook( this ); 986 resource->setAddressBook( this );
943 987
944 d->mManager->add( resource ); 988 d->mManager->add( resource );
945 return true; 989 return true;
946} 990}
947 991
948bool AddressBook::removeResource( Resource *resource ) 992bool AddressBook::removeResource( Resource *resource )
949{ 993{
950 resource->close(); 994 resource->close();
951 995
952 if ( resource == standardResource() ) 996 if ( resource == standardResource() )
953 d->mManager->setStandardResource( 0 ); 997 d->mManager->setStandardResource( 0 );
954 998
955 resource->setAddressBook( 0 ); 999 resource->setAddressBook( 0 );
956 1000
957 d->mManager->remove( resource ); 1001 d->mManager->remove( resource );
958 return true; 1002 return true;
959} 1003}
960 1004
961QPtrList<Resource> AddressBook::resources() 1005QPtrList<Resource> AddressBook::resources()
962{ 1006{
963 QPtrList<Resource> list; 1007 QPtrList<Resource> list;
964 1008
965// qDebug("AddressBook::resources() 1"); 1009// qDebug("AddressBook::resources() 1");
966 1010
967 KRES::Manager<Resource>::ActiveIterator it; 1011 KRES::Manager<Resource>::ActiveIterator it;
968 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1012 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
969 list.append( *it ); 1013 list.append( *it );
970 1014
971 return list; 1015 return list;
972} 1016}
973 1017
974/*US 1018/*US
975void AddressBook::setErrorHandler( ErrorHandler *handler ) 1019void AddressBook::setErrorHandler( ErrorHandler *handler )
976{ 1020{
977 delete d->mErrorHandler; 1021 delete d->mErrorHandler;
978 d->mErrorHandler = handler; 1022 d->mErrorHandler = handler;
979} 1023}
980*/ 1024*/
981 1025
982void AddressBook::error( const QString& msg ) 1026void AddressBook::error( const QString& msg )
983{ 1027{
984/*US 1028/*US
985 if ( !d->mErrorHandler ) // create default error handler 1029 if ( !d->mErrorHandler ) // create default error handler
986 d->mErrorHandler = new ConsoleErrorHandler; 1030 d->mErrorHandler = new ConsoleErrorHandler;
987 1031
988 if ( d->mErrorHandler ) 1032 if ( d->mErrorHandler )
989 d->mErrorHandler->error( msg ); 1033 d->mErrorHandler->error( msg );
990 else 1034 else
991 kdError(5700) << "no error handler defined" << endl; 1035 kdError(5700) << "no error handler defined" << endl;
992*/ 1036*/
993 kdDebug(5700) << "msg" << endl; 1037 kdDebug(5700) << "msg" << endl;
994 qDebug(msg); 1038 qDebug(msg);
995} 1039}
996 1040
997void AddressBook::deleteRemovedAddressees() 1041void AddressBook::deleteRemovedAddressees()
998{ 1042{
999 Addressee::List::Iterator it; 1043 Addressee::List::Iterator it;
1000 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1044 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1001 Resource *resource = (*it).resource(); 1045 Resource *resource = (*it).resource();
1002 if ( resource && !resource->readOnly() && resource->isOpen() ) 1046 if ( resource && !resource->readOnly() && resource->isOpen() )
1003 resource->removeAddressee( *it ); 1047 resource->removeAddressee( *it );
1004 } 1048 }
1005 1049
1006 d->mRemovedAddressees.clear(); 1050 d->mRemovedAddressees.clear();
1007} 1051}
1008 1052
1009void AddressBook::setStandardResource( Resource *resource ) 1053void AddressBook::setStandardResource( Resource *resource )
1010{ 1054{
1011// qDebug("AddressBook::setStandardResource 1"); 1055// qDebug("AddressBook::setStandardResource 1");
1012 d->mManager->setStandardResource( resource ); 1056 d->mManager->setStandardResource( resource );
1013} 1057}
1014 1058
1015Resource *AddressBook::standardResource() 1059Resource *AddressBook::standardResource()
1016{ 1060{
1017 return d->mManager->standardResource(); 1061 return d->mManager->standardResource();
1018} 1062}
1019 1063
1020KRES::Manager<Resource> *AddressBook::resourceManager() 1064KRES::Manager<Resource> *AddressBook::resourceManager()
1021{ 1065{
1022 return d->mManager; 1066 return d->mManager;
1023} 1067}
1024 1068
1025void AddressBook::cleanUp() 1069void AddressBook::cleanUp()
1026{ 1070{
1027 KRES::Manager<Resource>::ActiveIterator it; 1071 KRES::Manager<Resource>::ActiveIterator it;
1028 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1072 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1029 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1073 if ( !(*it)->readOnly() && (*it)->isOpen() )
1030 (*it)->cleanUp(); 1074 (*it)->cleanUp();
1031 } 1075 }
1032} 1076}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 532e05d..cc755d1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,343 +1,346 @@
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 );
146 void smplifyAddressees();
147 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
145 void export2File( QString fileName ); 148 void export2File( QString fileName );
146 void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 149 void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
147 void setUntagged(); 150 void setUntagged();
148 void removeUntagged(); 151 void removeUntagged();
149 /** 152 /**
150 Returns a iterator for first entry of address book. 153 Returns a iterator for first entry of address book.
151 */ 154 */
152 Iterator begin(); 155 Iterator begin();
153 156
154 /** 157 /**
155 Returns a const iterator for first entry of address book. 158 Returns a const iterator for first entry of address book.
156 */ 159 */
157 ConstIterator begin() const; 160 ConstIterator begin() const;
158 161
159 /** 162 /**
160 Returns a iterator for first entry of address book. 163 Returns a iterator for first entry of address book.
161 */ 164 */
162 Iterator end(); 165 Iterator end();
163 166
164 /** 167 /**
165 Returns a const iterator for first entry of address book. 168 Returns a const iterator for first entry of address book.
166 */ 169 */
167 ConstIterator end() const; 170 ConstIterator end() const;
168 171
169 /** 172 /**
170 Removes all entries from address book. 173 Removes all entries from address book.
171 */ 174 */
172 void clear(); 175 void clear();
173 176
174 /** 177 /**
175 Insert an Addressee object into address book. If an object with the same 178 Insert an Addressee object into address book. If an object with the same
176 unique id already exists in the address book it it replaced by the new 179 unique id already exists in the address book it it replaced by the new
177 one. If not the new object is appended to the address book. 180 one. If not the new object is appended to the address book.
178 */ 181 */
179 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 182 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
180 183
181 /** 184 /**
182 Removes entry from the address book. 185 Removes entry from the address book.
183 */ 186 */
184 void removeAddressee( const Addressee & ); 187 void removeAddressee( const Addressee & );
185 188
186 /** 189 /**
187 This is like @ref removeAddressee() just above, with the difference that 190 This is like @ref removeAddressee() just above, with the difference that
188 the first element is a iterator, returned by @ref begin(). 191 the first element is a iterator, returned by @ref begin().
189 */ 192 */
190 void removeAddressee( const Iterator & ); 193 void removeAddressee( const Iterator & );
191 194
192 /** 195 /**
193 Find the specified entry in address book. Returns end(), if the entry 196 Find the specified entry in address book. Returns end(), if the entry
194 couldn't be found. 197 couldn't be found.
195 */ 198 */
196 Iterator find( const Addressee & ); 199 Iterator find( const Addressee & );
197 200
198 /** 201 /**
199 Find the entry specified by an unique id. Returns an empty Addressee 202 Find the entry specified by an unique id. Returns an empty Addressee
200 object, if the address book does not contain an entry with this id. 203 object, if the address book does not contain an entry with this id.
201 */ 204 */
202 Addressee findByUid( const QString & ); 205 Addressee findByUid( const QString & );
203 206
204 207
205 /** 208 /**
206 Returns a list of all addressees in the address book. This list can 209 Returns a list of all addressees in the address book. This list can
207 be sorted with @ref KABC::AddresseeList for example. 210 be sorted with @ref KABC::AddresseeList for example.
208 */ 211 */
209 Addressee::List allAddressees(); 212 Addressee::List allAddressees();
210 213
211 /** 214 /**
212 Find all entries with the specified name in the address book. Returns 215 Find all entries with the specified name in the address book. Returns
213 an empty list, if no entries could be found. 216 an empty list, if no entries could be found.
214 */ 217 */
215 Addressee::List findByName( const QString & ); 218 Addressee::List findByName( const QString & );
216 219
217 /** 220 /**
218 Find all entries with the specified email address in the address book. 221 Find all entries with the specified email address in the address book.
219 Returns an empty list, if no entries could be found. 222 Returns an empty list, if no entries could be found.
220 */ 223 */
221 Addressee::List findByEmail( const QString & ); 224 Addressee::List findByEmail( const QString & );
222 225
223 /** 226 /**
224 Find all entries wich have the specified category in the address book. 227 Find all entries wich have the specified category in the address book.
225 Returns an empty list, if no entries could be found. 228 Returns an empty list, if no entries could be found.
226 */ 229 */
227 Addressee::List findByCategory( const QString & ); 230 Addressee::List findByCategory( const QString & );
228 231
229 /** 232 /**
230 Return a string identifying this addressbook. 233 Return a string identifying this addressbook.
231 */ 234 */
232 virtual QString identifier(); 235 virtual QString identifier();
233 236
234 /** 237 /**
235 Used for debug output. 238 Used for debug output.
236 */ 239 */
237 void dump() const; 240 void dump() const;
238 241
239 void emitAddressBookLocked() { emit addressBookLocked( this ); } 242 void emitAddressBookLocked() { emit addressBookLocked( this ); }
240 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 243 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
241 void emitAddressBookChanged() { emit addressBookChanged( this ); } 244 void emitAddressBookChanged() { emit addressBookChanged( this ); }
242 245
243 /** 246 /**
244 Return list of all Fields known to the address book which are associated 247 Return list of all Fields known to the address book which are associated
245 with the given field category. 248 with the given field category.
246 */ 249 */
247 Field::List fields( int category = Field::All ); 250 Field::List fields( int category = Field::All );
248 251
249 /** 252 /**
250 Add custom field to address book. 253 Add custom field to address book.
251 254
252 @param label User visible label of the field. 255 @param label User visible label of the field.
253 @param category Ored list of field categories. 256 @param category Ored list of field categories.
254 @param key Identifier used as key for reading and writing the field. 257 @param key Identifier used as key for reading and writing the field.
255 @param app String used as application key for reading and writing 258 @param app String used as application key for reading and writing
256 the field. 259 the field.
257 */ 260 */
258 bool addCustomField( const QString &label, int category = Field::All, 261 bool addCustomField( const QString &label, int category = Field::All,
259 const QString &key = QString::null, 262 const QString &key = QString::null,
260 const QString &app = QString::null ); 263 const QString &app = QString::null );
261 264
262 265
263 /** 266 /**
264 Add address book resource. 267 Add address book resource.
265 */ 268 */
266 bool addResource( Resource * ); 269 bool addResource( Resource * );
267 270
268 /** 271 /**
269 Remove address book resource. 272 Remove address book resource.
270 */ 273 */
271 bool removeResource( Resource * ); 274 bool removeResource( Resource * );
272 275
273 /** 276 /**
274 Return pointer list of all resources. 277 Return pointer list of all resources.
275 */ 278 */
276 QPtrList<Resource> resources(); 279 QPtrList<Resource> resources();
277 280
278 /** 281 /**
279 Set the @p ErrorHandler, that is used by @ref error() to 282 Set the @p ErrorHandler, that is used by @ref error() to
280 provide gui-independend error messages. 283 provide gui-independend error messages.
281 */ 284 */
282 void setErrorHandler( ErrorHandler * ); 285 void setErrorHandler( ErrorHandler * );
283 286
284 /** 287 /**
285 Shows gui independend error messages. 288 Shows gui independend error messages.
286 */ 289 */
287 void error( const QString& ); 290 void error( const QString& );
288 291
289 /** 292 /**
290 Query all resources to clean up their lock files 293 Query all resources to clean up their lock files
291 */ 294 */
292 void cleanUp(); 295 void cleanUp();
293 296
294 // sync stuff 297 // sync stuff
295 //Addressee::List getExternLastSyncAddressees(); 298 //Addressee::List getExternLastSyncAddressees();
296 void resetTempSyncStat(); 299 void resetTempSyncStat();
297 QStringList uidList(); 300 QStringList uidList();
298 void removeSyncAddressees( bool removeDeleted = false ); 301 void removeSyncAddressees( bool removeDeleted = false );
299 void mergeAB( AddressBook *aBook, const QString& profile ); 302 void mergeAB( AddressBook *aBook, const QString& profile );
300 Addressee findByExternUid( const QString& uid , const QString& profile ); 303 Addressee findByExternUid( const QString& uid , const QString& profile );
301 bool containsExternalUid( const QString& uid ); 304 bool containsExternalUid( const QString& uid );
302 305
303 void preExternSync( AddressBook* aBook, const QString& csd ); 306 void preExternSync( AddressBook* aBook, const QString& csd );
304 void postExternSync( AddressBook* aBook, const QString& csd ); 307 void postExternSync( AddressBook* aBook, const QString& csd );
305 signals: 308 signals:
306 /** 309 /**
307 Emitted, when the address book has changed on disk. 310 Emitted, when the address book has changed on disk.
308 */ 311 */
309 void addressBookChanged( AddressBook * ); 312 void addressBookChanged( AddressBook * );
310 313
311 /** 314 /**
312 Emitted, when the address book has been locked for writing. 315 Emitted, when the address book has been locked for writing.
313 */ 316 */
314 void addressBookLocked( AddressBook * ); 317 void addressBookLocked( AddressBook * );
315 318
316 /** 319 /**
317 Emitted, when the address book has been unlocked. 320 Emitted, when the address book has been unlocked.
318 */ 321 */
319 void addressBookUnlocked( AddressBook * ); 322 void addressBookUnlocked( AddressBook * );
320 323
321 protected: 324 protected:
322 void deleteRemovedAddressees(); 325 void deleteRemovedAddressees();
323 void setStandardResource( Resource * ); 326 void setStandardResource( Resource * );
324 Resource *standardResource(); 327 Resource *standardResource();
325 KRES::Manager<Resource> *resourceManager(); 328 KRES::Manager<Resource> *resourceManager();
326 329
327 void init(const QString &config, const QString &family); 330 void init(const QString &config, const QString &family);
328 331
329 private: 332 private:
330//US QPtrList<Resource> mDummy; // Remove in KDE 4 333//US QPtrList<Resource> mDummy; // Remove in KDE 4
331 334
332 335
333 struct AddressBookData; 336 struct AddressBookData;
334 AddressBookData *d; 337 AddressBookData *d;
335 bool blockLSEchange; 338 bool blockLSEchange;
336}; 339};
337 340
338QDataStream &operator<<( QDataStream &, const AddressBook & ); 341QDataStream &operator<<( QDataStream &, const AddressBook & );
339QDataStream &operator>>( QDataStream &, AddressBook & ); 342QDataStream &operator>>( QDataStream &, AddressBook & );
340 343
341} 344}
342 345
343#endif 346#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 452f1bc..a7967cb 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1290,1610 +1290,1635 @@ void KABCore::redo()
1290} 1290}
1291 1291
1292void KABCore::setJumpButtonBarVisible( bool visible ) 1292void KABCore::setJumpButtonBarVisible( bool visible )
1293{ 1293{
1294 if (mMultipleViewsAtOnce) 1294 if (mMultipleViewsAtOnce)
1295 { 1295 {
1296 if ( visible ) 1296 if ( visible )
1297 mJumpButtonBar->show(); 1297 mJumpButtonBar->show();
1298 else 1298 else
1299 mJumpButtonBar->hide(); 1299 mJumpButtonBar->hide();
1300 } 1300 }
1301 else 1301 else
1302 { 1302 {
1303 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1303 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1304 if (mViewManager->isVisible()) 1304 if (mViewManager->isVisible())
1305 { 1305 {
1306 if ( visible ) 1306 if ( visible )
1307 mJumpButtonBar->show(); 1307 mJumpButtonBar->show();
1308 else 1308 else
1309 mJumpButtonBar->hide(); 1309 mJumpButtonBar->hide();
1310 } 1310 }
1311 else 1311 else
1312 { 1312 {
1313 mJumpButtonBar->hide(); 1313 mJumpButtonBar->hide();
1314 } 1314 }
1315 } 1315 }
1316} 1316}
1317 1317
1318 1318
1319void KABCore::setDetailsToState() 1319void KABCore::setDetailsToState()
1320{ 1320{
1321 setDetailsVisible( mActionDetails->isChecked() ); 1321 setDetailsVisible( mActionDetails->isChecked() );
1322} 1322}
1323 1323
1324 1324
1325 1325
1326void KABCore::setDetailsVisible( bool visible ) 1326void KABCore::setDetailsVisible( bool visible )
1327{ 1327{
1328 if (visible && mDetails->isHidden()) 1328 if (visible && mDetails->isHidden())
1329 { 1329 {
1330 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1330 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1331 if ( addrList.count() > 0 ) 1331 if ( addrList.count() > 0 )
1332 mDetails->setAddressee( addrList[ 0 ] ); 1332 mDetails->setAddressee( addrList[ 0 ] );
1333 } 1333 }
1334 1334
1335 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1335 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1336 // the listview and the detailview. We do that by changing the splitbar size. 1336 // the listview and the detailview. We do that by changing the splitbar size.
1337 if (mMultipleViewsAtOnce) 1337 if (mMultipleViewsAtOnce)
1338 { 1338 {
1339 if ( visible ) 1339 if ( visible )
1340 mDetails->show(); 1340 mDetails->show();
1341 else 1341 else
1342 mDetails->hide(); 1342 mDetails->hide();
1343 } 1343 }
1344 else 1344 else
1345 { 1345 {
1346 if ( visible ) { 1346 if ( visible ) {
1347 mViewManager->hide(); 1347 mViewManager->hide();
1348 mDetails->show(); 1348 mDetails->show();
1349 } 1349 }
1350 else { 1350 else {
1351 mViewManager->show(); 1351 mViewManager->show();
1352 mDetails->hide(); 1352 mDetails->hide();
1353 } 1353 }
1354 setJumpButtonBarVisible( !visible ); 1354 setJumpButtonBarVisible( !visible );
1355 } 1355 }
1356 1356
1357} 1357}
1358 1358
1359void KABCore::extensionChanged( int id ) 1359void KABCore::extensionChanged( int id )
1360{ 1360{
1361 //change the details view only for non desktop systems 1361 //change the details view only for non desktop systems
1362#ifndef DESKTOP_VERSION 1362#ifndef DESKTOP_VERSION
1363 1363
1364 if (id == 0) 1364 if (id == 0)
1365 { 1365 {
1366 //the user disabled the extension. 1366 //the user disabled the extension.
1367 1367
1368 if (mMultipleViewsAtOnce) 1368 if (mMultipleViewsAtOnce)
1369 { // enable detailsview again 1369 { // enable detailsview again
1370 setDetailsVisible( true ); 1370 setDetailsVisible( true );
1371 mActionDetails->setChecked( true ); 1371 mActionDetails->setChecked( true );
1372 } 1372 }
1373 else 1373 else
1374 { //go back to the listview 1374 { //go back to the listview
1375 setDetailsVisible( false ); 1375 setDetailsVisible( false );
1376 mActionDetails->setChecked( false ); 1376 mActionDetails->setChecked( false );
1377 mActionDetails->setEnabled(true); 1377 mActionDetails->setEnabled(true);
1378 } 1378 }
1379 1379
1380 } 1380 }
1381 else 1381 else
1382 { 1382 {
1383 //the user enabled the extension. 1383 //the user enabled the extension.
1384 setDetailsVisible( false ); 1384 setDetailsVisible( false );
1385 mActionDetails->setChecked( false ); 1385 mActionDetails->setChecked( false );
1386 1386
1387 if (!mMultipleViewsAtOnce) 1387 if (!mMultipleViewsAtOnce)
1388 { 1388 {
1389 mActionDetails->setEnabled(false); 1389 mActionDetails->setEnabled(false);
1390 } 1390 }
1391 1391
1392 mExtensionManager->setSelectionChanged(); 1392 mExtensionManager->setSelectionChanged();
1393 1393
1394 } 1394 }
1395 1395
1396#endif// DESKTOP_VERSION 1396#endif// DESKTOP_VERSION
1397 1397
1398} 1398}
1399 1399
1400 1400
1401void KABCore::extensionModified( const KABC::Addressee::List &list ) 1401void KABCore::extensionModified( const KABC::Addressee::List &list )
1402{ 1402{
1403 1403
1404 if ( list.count() != 0 ) { 1404 if ( list.count() != 0 ) {
1405 KABC::Addressee::List::ConstIterator it; 1405 KABC::Addressee::List::ConstIterator it;
1406 for ( it = list.begin(); it != list.end(); ++it ) 1406 for ( it = list.begin(); it != list.end(); ++it )
1407 mAddressBook->insertAddressee( *it ); 1407 mAddressBook->insertAddressee( *it );
1408 if ( list.count() > 1 ) 1408 if ( list.count() > 1 )
1409 setModified(); 1409 setModified();
1410 else 1410 else
1411 setModifiedWOrefresh(); 1411 setModifiedWOrefresh();
1412 } 1412 }
1413 if ( list.count() == 0 ) 1413 if ( list.count() == 0 )
1414 mViewManager->refreshView(); 1414 mViewManager->refreshView();
1415 else 1415 else
1416 mViewManager->refreshView( list[ 0 ].uid() ); 1416 mViewManager->refreshView( list[ 0 ].uid() );
1417 1417
1418 1418
1419 1419
1420} 1420}
1421 1421
1422QString KABCore::getNameByPhone( const QString &phone ) 1422QString KABCore::getNameByPhone( const QString &phone )
1423{ 1423{
1424#ifndef KAB_EMBEDDED 1424#ifndef KAB_EMBEDDED
1425 QRegExp r( "[/*/-/ ]" ); 1425 QRegExp r( "[/*/-/ ]" );
1426 QString localPhone( phone ); 1426 QString localPhone( phone );
1427 1427
1428 bool found = false; 1428 bool found = false;
1429 QString ownerName = ""; 1429 QString ownerName = "";
1430 KABC::AddressBook::Iterator iter; 1430 KABC::AddressBook::Iterator iter;
1431 KABC::PhoneNumber::List::Iterator phoneIter; 1431 KABC::PhoneNumber::List::Iterator phoneIter;
1432 KABC::PhoneNumber::List phoneList; 1432 KABC::PhoneNumber::List phoneList;
1433 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1433 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1434 phoneList = (*iter).phoneNumbers(); 1434 phoneList = (*iter).phoneNumbers();
1435 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1435 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1436 ++phoneIter) { 1436 ++phoneIter) {
1437 // Get rid of separator chars so just the numbers are compared. 1437 // Get rid of separator chars so just the numbers are compared.
1438 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1438 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1439 ownerName = (*iter).formattedName(); 1439 ownerName = (*iter).formattedName();
1440 found = true; 1440 found = true;
1441 } 1441 }
1442 } 1442 }
1443 } 1443 }
1444 1444
1445 return ownerName; 1445 return ownerName;
1446#else //KAB_EMBEDDED 1446#else //KAB_EMBEDDED
1447 qDebug("KABCore::getNameByPhone finsih method"); 1447 qDebug("KABCore::getNameByPhone finsih method");
1448 return ""; 1448 return "";
1449#endif //KAB_EMBEDDED 1449#endif //KAB_EMBEDDED
1450 1450
1451} 1451}
1452 1452
1453void KABCore::openConfigDialog() 1453void KABCore::openConfigDialog()
1454{ 1454{
1455 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1455 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1456 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1456 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1457 ConfigureDialog->addModule(kabcfg ); 1457 ConfigureDialog->addModule(kabcfg );
1458 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1458 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1459 ConfigureDialog->addModule(kdelibcfg ); 1459 ConfigureDialog->addModule(kdelibcfg );
1460 1460
1461 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1461 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1462 this, SLOT( configurationChanged() ) ); 1462 this, SLOT( configurationChanged() ) );
1463 connect( ConfigureDialog, SIGNAL( okClicked() ), 1463 connect( ConfigureDialog, SIGNAL( okClicked() ),
1464 this, SLOT( configurationChanged() ) ); 1464 this, SLOT( configurationChanged() ) );
1465 saveSettings(); 1465 saveSettings();
1466#ifndef DESKTOP_VERSION 1466#ifndef DESKTOP_VERSION
1467 ConfigureDialog->showMaximized(); 1467 ConfigureDialog->showMaximized();
1468#endif 1468#endif
1469 if ( ConfigureDialog->exec() ) 1469 if ( ConfigureDialog->exec() )
1470 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1470 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1471 delete ConfigureDialog; 1471 delete ConfigureDialog;
1472} 1472}
1473 1473
1474void KABCore::openLDAPDialog() 1474void KABCore::openLDAPDialog()
1475{ 1475{
1476#ifndef KAB_EMBEDDED 1476#ifndef KAB_EMBEDDED
1477 if ( !mLdapSearchDialog ) { 1477 if ( !mLdapSearchDialog ) {
1478 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1478 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1479 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1479 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1480 SLOT( refreshView() ) ); 1480 SLOT( refreshView() ) );
1481 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1481 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1482 SLOT( setModified() ) ); 1482 SLOT( setModified() ) );
1483 } else 1483 } else
1484 mLdapSearchDialog->restoreSettings(); 1484 mLdapSearchDialog->restoreSettings();
1485 1485
1486 if ( mLdapSearchDialog->isOK() ) 1486 if ( mLdapSearchDialog->isOK() )
1487 mLdapSearchDialog->exec(); 1487 mLdapSearchDialog->exec();
1488#else //KAB_EMBEDDED 1488#else //KAB_EMBEDDED
1489 qDebug("KABCore::openLDAPDialog() finsih method"); 1489 qDebug("KABCore::openLDAPDialog() finsih method");
1490#endif //KAB_EMBEDDED 1490#endif //KAB_EMBEDDED
1491} 1491}
1492 1492
1493void KABCore::print() 1493void KABCore::print()
1494{ 1494{
1495#ifndef KAB_EMBEDDED 1495#ifndef KAB_EMBEDDED
1496 KPrinter printer; 1496 KPrinter printer;
1497 if ( !printer.setup( this ) ) 1497 if ( !printer.setup( this ) )
1498 return; 1498 return;
1499 1499
1500 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1500 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1501 mViewManager->selectedUids(), this ); 1501 mViewManager->selectedUids(), this );
1502 1502
1503 wizard.exec(); 1503 wizard.exec();
1504#else //KAB_EMBEDDED 1504#else //KAB_EMBEDDED
1505 qDebug("KABCore::print() finsih method"); 1505 qDebug("KABCore::print() finsih method");
1506#endif //KAB_EMBEDDED 1506#endif //KAB_EMBEDDED
1507 1507
1508} 1508}
1509 1509
1510 1510
1511void KABCore::addGUIClient( KXMLGUIClient *client ) 1511void KABCore::addGUIClient( KXMLGUIClient *client )
1512{ 1512{
1513 if ( mGUIClient ) 1513 if ( mGUIClient )
1514 mGUIClient->insertChildClient( client ); 1514 mGUIClient->insertChildClient( client );
1515 else 1515 else
1516 KMessageBox::error( this, "no KXMLGUICLient"); 1516 KMessageBox::error( this, "no KXMLGUICLient");
1517} 1517}
1518 1518
1519 1519
1520void KABCore::configurationChanged() 1520void KABCore::configurationChanged()
1521{ 1521{
1522 mExtensionManager->reconfigure(); 1522 mExtensionManager->reconfigure();
1523} 1523}
1524 1524
1525void KABCore::addressBookChanged() 1525void KABCore::addressBookChanged()
1526{ 1526{
1527/*US 1527/*US
1528 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1528 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1529 while ( it.current() ) { 1529 while ( it.current() ) {
1530 if ( it.current()->dirty() ) { 1530 if ( it.current()->dirty() ) {
1531 QString text = i18n( "Data has been changed externally. Unsaved " 1531 QString text = i18n( "Data has been changed externally. Unsaved "
1532 "changes will be lost." ); 1532 "changes will be lost." );
1533 KMessageBox::information( this, text ); 1533 KMessageBox::information( this, text );
1534 } 1534 }
1535 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1535 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1536 ++it; 1536 ++it;
1537 } 1537 }
1538*/ 1538*/
1539 if (mEditorDialog) 1539 if (mEditorDialog)
1540 { 1540 {
1541 if (mEditorDialog->dirty()) 1541 if (mEditorDialog->dirty())
1542 { 1542 {
1543 QString text = i18n( "Data has been changed externally. Unsaved " 1543 QString text = i18n( "Data has been changed externally. Unsaved "
1544 "changes will be lost." ); 1544 "changes will be lost." );
1545 KMessageBox::information( this, text ); 1545 KMessageBox::information( this, text );
1546 } 1546 }
1547 QString currentuid = mEditorDialog->addressee().uid(); 1547 QString currentuid = mEditorDialog->addressee().uid();
1548 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1548 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1549 } 1549 }
1550 mViewManager->refreshView(); 1550 mViewManager->refreshView();
1551// mDetails->refreshView(); 1551// mDetails->refreshView();
1552 1552
1553 1553
1554} 1554}
1555 1555
1556AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1556AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1557 const char *name ) 1557 const char *name )
1558{ 1558{
1559 1559
1560 if ( mEditorDialog == 0 ) { 1560 if ( mEditorDialog == 0 ) {
1561 mEditorDialog = new AddresseeEditorDialog( this, parent, 1561 mEditorDialog = new AddresseeEditorDialog( this, parent,
1562 name ? name : "editorDialog" ); 1562 name ? name : "editorDialog" );
1563 1563
1564 1564
1565 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1565 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1566 SLOT( contactModified( const KABC::Addressee& ) ) ); 1566 SLOT( contactModified( const KABC::Addressee& ) ) );
1567 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1567 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1568 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1568 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1569 } 1569 }
1570 1570
1571 return mEditorDialog; 1571 return mEditorDialog;
1572} 1572}
1573 1573
1574void KABCore::slotEditorDestroyed( const QString &uid ) 1574void KABCore::slotEditorDestroyed( const QString &uid )
1575{ 1575{
1576 //mEditorDict.remove( uid ); 1576 //mEditorDict.remove( uid );
1577} 1577}
1578 1578
1579void KABCore::initGUI() 1579void KABCore::initGUI()
1580{ 1580{
1581#ifndef KAB_EMBEDDED 1581#ifndef KAB_EMBEDDED
1582 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1582 QHBoxLayout *topLayout = new QHBoxLayout( this );
1583 topLayout->setSpacing( KDialogBase::spacingHint() ); 1583 topLayout->setSpacing( KDialogBase::spacingHint() );
1584 1584
1585 mExtensionBarSplitter = new QSplitter( this ); 1585 mExtensionBarSplitter = new QSplitter( this );
1586 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1586 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1587 1587
1588 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1588 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1589 1589
1590 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1590 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1591 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1591 mIncSearchWidget = new IncSearchWidget( viewSpace );
1592 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1592 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1593 SLOT( incrementalSearch( const QString& ) ) ); 1593 SLOT( incrementalSearch( const QString& ) ) );
1594 1594
1595 mViewManager = new ViewManager( this, viewSpace ); 1595 mViewManager = new ViewManager( this, viewSpace );
1596 viewSpace->setStretchFactor( mViewManager, 1 ); 1596 viewSpace->setStretchFactor( mViewManager, 1 );
1597 1597
1598 mDetails = new ViewContainer( mDetailsSplitter ); 1598 mDetails = new ViewContainer( mDetailsSplitter );
1599 1599
1600 mJumpButtonBar = new JumpButtonBar( this, this ); 1600 mJumpButtonBar = new JumpButtonBar( this, this );
1601 1601
1602 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1602 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1603 1603
1604 topLayout->addWidget( mExtensionBarSplitter ); 1604 topLayout->addWidget( mExtensionBarSplitter );
1605 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1605 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1606 topLayout->addWidget( mJumpButtonBar ); 1606 topLayout->addWidget( mJumpButtonBar );
1607 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1607 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1608 1608
1609 mXXPortManager = new XXPortManager( this, this ); 1609 mXXPortManager = new XXPortManager( this, this );
1610 1610
1611#else //KAB_EMBEDDED 1611#else //KAB_EMBEDDED
1612 //US initialize viewMenu before settingup viewmanager. 1612 //US initialize viewMenu before settingup viewmanager.
1613 // Viewmanager needs this menu to plugin submenues. 1613 // Viewmanager needs this menu to plugin submenues.
1614 viewMenu = new QPopupMenu( this ); 1614 viewMenu = new QPopupMenu( this );
1615 settingsMenu = new QPopupMenu( this ); 1615 settingsMenu = new QPopupMenu( this );
1616 //filterMenu = new QPopupMenu( this ); 1616 //filterMenu = new QPopupMenu( this );
1617 ImportMenu = new QPopupMenu( this ); 1617 ImportMenu = new QPopupMenu( this );
1618 ExportMenu = new QPopupMenu( this ); 1618 ExportMenu = new QPopupMenu( this );
1619 syncMenu = new QPopupMenu( this ); 1619 syncMenu = new QPopupMenu( this );
1620 changeMenu= new QPopupMenu( this ); 1620 changeMenu= new QPopupMenu( this );
1621 1621
1622//US since we have no splitter for the embedded system, setup 1622//US since we have no splitter for the embedded system, setup
1623// a layout with two frames. One left and one right. 1623// a layout with two frames. One left and one right.
1624 1624
1625 QBoxLayout *topLayout; 1625 QBoxLayout *topLayout;
1626 1626
1627 // = new QHBoxLayout( this ); 1627 // = new QHBoxLayout( this );
1628// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1628// QBoxLayout *topLayout = (QBoxLayout*)layout();
1629 1629
1630// QWidget *mainBox = new QWidget( this ); 1630// QWidget *mainBox = new QWidget( this );
1631// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1631// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1632 1632
1633#ifdef DESKTOP_VERSION 1633#ifdef DESKTOP_VERSION
1634 topLayout = new QHBoxLayout( this ); 1634 topLayout = new QHBoxLayout( this );
1635 1635
1636 1636
1637 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1637 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1638 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1638 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1639 1639
1640 topLayout->addWidget(mMiniSplitter ); 1640 topLayout->addWidget(mMiniSplitter );
1641 1641
1642 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1642 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1643 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1643 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1644 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1644 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1645 mDetails = new ViewContainer( mMiniSplitter ); 1645 mDetails = new ViewContainer( mMiniSplitter );
1646 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1646 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1647#else 1647#else
1648 if ( QApplication::desktop()->width() > 480 ) { 1648 if ( QApplication::desktop()->width() > 480 ) {
1649 topLayout = new QHBoxLayout( this ); 1649 topLayout = new QHBoxLayout( this );
1650 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1650 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1651 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1651 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1652 } else { 1652 } else {
1653 1653
1654 topLayout = new QHBoxLayout( this ); 1654 topLayout = new QHBoxLayout( this );
1655 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1655 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1656 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1656 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1657 } 1657 }
1658 1658
1659 topLayout->addWidget(mMiniSplitter ); 1659 topLayout->addWidget(mMiniSplitter );
1660 mViewManager = new ViewManager( this, mMiniSplitter ); 1660 mViewManager = new ViewManager( this, mMiniSplitter );
1661 mDetails = new ViewContainer( mMiniSplitter ); 1661 mDetails = new ViewContainer( mMiniSplitter );
1662 1662
1663 1663
1664 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1664 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1665#endif 1665#endif
1666 //eh->hide(); 1666 //eh->hide();
1667 // topLayout->addWidget(mExtensionManager ); 1667 // topLayout->addWidget(mExtensionManager );
1668 1668
1669 1669
1670/*US 1670/*US
1671#ifndef KAB_NOSPLITTER 1671#ifndef KAB_NOSPLITTER
1672 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1672 QHBoxLayout *topLayout = new QHBoxLayout( this );
1673//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1673//US topLayout->setSpacing( KDialogBase::spacingHint() );
1674 topLayout->setSpacing( 10 ); 1674 topLayout->setSpacing( 10 );
1675 1675
1676 mDetailsSplitter = new QSplitter( this ); 1676 mDetailsSplitter = new QSplitter( this );
1677 1677
1678 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1678 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1679 1679
1680 mViewManager = new ViewManager( this, viewSpace ); 1680 mViewManager = new ViewManager( this, viewSpace );
1681 viewSpace->setStretchFactor( mViewManager, 1 ); 1681 viewSpace->setStretchFactor( mViewManager, 1 );
1682 1682
1683 mDetails = new ViewContainer( mDetailsSplitter ); 1683 mDetails = new ViewContainer( mDetailsSplitter );
1684 1684
1685 topLayout->addWidget( mDetailsSplitter ); 1685 topLayout->addWidget( mDetailsSplitter );
1686 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1686 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1687#else //KAB_NOSPLITTER 1687#else //KAB_NOSPLITTER
1688 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1688 QHBoxLayout *topLayout = new QHBoxLayout( this );
1689//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1689//US topLayout->setSpacing( KDialogBase::spacingHint() );
1690 topLayout->setSpacing( 10 ); 1690 topLayout->setSpacing( 10 );
1691 1691
1692// mDetailsSplitter = new QSplitter( this ); 1692// mDetailsSplitter = new QSplitter( this );
1693 1693
1694 QVBox *viewSpace = new QVBox( this ); 1694 QVBox *viewSpace = new QVBox( this );
1695 1695
1696 mViewManager = new ViewManager( this, viewSpace ); 1696 mViewManager = new ViewManager( this, viewSpace );
1697 viewSpace->setStretchFactor( mViewManager, 1 ); 1697 viewSpace->setStretchFactor( mViewManager, 1 );
1698 1698
1699 mDetails = new ViewContainer( this ); 1699 mDetails = new ViewContainer( this );
1700 1700
1701 topLayout->addWidget( viewSpace ); 1701 topLayout->addWidget( viewSpace );
1702// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1702// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1703 topLayout->addWidget( mDetails ); 1703 topLayout->addWidget( mDetails );
1704#endif //KAB_NOSPLITTER 1704#endif //KAB_NOSPLITTER
1705*/ 1705*/
1706 1706
1707 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 1707 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
1708 syncManager->setBlockSave(false); 1708 syncManager->setBlockSave(false);
1709 1709
1710 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); 1710 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
1711 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); 1711 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
1712 syncManager->setDefaultFileName( sentSyncFile()); 1712 syncManager->setDefaultFileName( sentSyncFile());
1713 //connect(syncManager , SIGNAL( ), this, SLOT( ) ); 1713 //connect(syncManager , SIGNAL( ), this, SLOT( ) );
1714 1714
1715#endif //KAB_EMBEDDED 1715#endif //KAB_EMBEDDED
1716 initActions(); 1716 initActions();
1717 1717
1718#ifdef KAB_EMBEDDED 1718#ifdef KAB_EMBEDDED
1719 addActionsManually(); 1719 addActionsManually();
1720 //US make sure the export and import menues are initialized before creating the xxPortManager. 1720 //US make sure the export and import menues are initialized before creating the xxPortManager.
1721 mXXPortManager = new XXPortManager( this, this ); 1721 mXXPortManager = new XXPortManager( this, this );
1722 1722
1723 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1723 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1724 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1724 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1725 // mActionQuit->plug ( mMainWindow->toolBar()); 1725 // mActionQuit->plug ( mMainWindow->toolBar());
1726 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1726 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1727 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1727 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1728 // mIncSearchWidget->hide(); 1728 // mIncSearchWidget->hide();
1729 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1729 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1730 SLOT( incrementalSearch( const QString& ) ) ); 1730 SLOT( incrementalSearch( const QString& ) ) );
1731 1731
1732 1732
1733 mJumpButtonBar = new JumpButtonBar( this, this ); 1733 mJumpButtonBar = new JumpButtonBar( this, this );
1734 1734
1735 topLayout->addWidget( mJumpButtonBar ); 1735 topLayout->addWidget( mJumpButtonBar );
1736//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1736//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1737 1737
1738// mMainWindow->getIconToolBar()->raise(); 1738// mMainWindow->getIconToolBar()->raise();
1739 1739
1740#endif //KAB_EMBEDDED 1740#endif //KAB_EMBEDDED
1741 1741
1742} 1742}
1743void KABCore::initActions() 1743void KABCore::initActions()
1744{ 1744{
1745//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1745//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1746 1746
1747#ifndef KAB_EMBEDDED 1747#ifndef KAB_EMBEDDED
1748 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1748 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1749 SLOT( clipboardDataChanged() ) ); 1749 SLOT( clipboardDataChanged() ) );
1750#endif //KAB_EMBEDDED 1750#endif //KAB_EMBEDDED
1751 1751
1752 // file menu 1752 // file menu
1753 if ( mIsPart ) { 1753 if ( mIsPart ) {
1754 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1754 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1755 SLOT( sendMail() ), actionCollection(), 1755 SLOT( sendMail() ), actionCollection(),
1756 "kaddressbook_mail" ); 1756 "kaddressbook_mail" );
1757 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1757 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1758 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1758 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1759 1759
1760 } else { 1760 } else {
1761 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1761 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1762 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1762 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1763 } 1763 }
1764 1764
1765 1765
1766 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1766 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1767 SLOT( save() ), actionCollection(), "file_sync" ); 1767 SLOT( save() ), actionCollection(), "file_sync" );
1768 1768
1769 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1769 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1770 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1770 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1771 1771
1772 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1772 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1773 this, SLOT( mailVCard() ), 1773 this, SLOT( mailVCard() ),
1774 actionCollection(), "file_mail_vcard"); 1774 actionCollection(), "file_mail_vcard");
1775 1775
1776 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, 1776 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this,
1777 SLOT( export2phone() ), actionCollection(), 1777 SLOT( export2phone() ), actionCollection(),
1778 "kaddressbook_ex2phone" ); 1778 "kaddressbook_ex2phone" );
1779 1779
1780 mActionBeamVCard = 0; 1780 mActionBeamVCard = 0;
1781 mActionBeam = 0; 1781 mActionBeam = 0;
1782 1782
1783#ifndef DESKTOP_VERSION 1783#ifndef DESKTOP_VERSION
1784 if ( Ir::supported() ) { 1784 if ( Ir::supported() ) {
1785 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1785 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1786 SLOT( beamVCard() ), actionCollection(), 1786 SLOT( beamVCard() ), actionCollection(),
1787 "kaddressbook_beam_vcard" ); 1787 "kaddressbook_beam_vcard" );
1788 1788
1789 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1789 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1790 SLOT( beamMySelf() ), actionCollection(), 1790 SLOT( beamMySelf() ), actionCollection(),
1791 "kaddressbook_beam_myself" ); 1791 "kaddressbook_beam_myself" );
1792 } 1792 }
1793#endif 1793#endif
1794 1794
1795 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1795 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1796 this, SLOT( editContact2() ), 1796 this, SLOT( editContact2() ),
1797 actionCollection(), "file_properties" ); 1797 actionCollection(), "file_properties" );
1798 1798
1799#ifdef KAB_EMBEDDED 1799#ifdef KAB_EMBEDDED
1800 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1800 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1801 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1801 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1802 mMainWindow, SLOT( exit() ), 1802 mMainWindow, SLOT( exit() ),
1803 actionCollection(), "quit" ); 1803 actionCollection(), "quit" );
1804#endif //KAB_EMBEDDED 1804#endif //KAB_EMBEDDED
1805 1805
1806 // edit menu 1806 // edit menu
1807 if ( mIsPart ) { 1807 if ( mIsPart ) {
1808 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1808 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1809 SLOT( copyContacts() ), actionCollection(), 1809 SLOT( copyContacts() ), actionCollection(),
1810 "kaddressbook_copy" ); 1810 "kaddressbook_copy" );
1811 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1811 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1812 SLOT( cutContacts() ), actionCollection(), 1812 SLOT( cutContacts() ), actionCollection(),
1813 "kaddressbook_cut" ); 1813 "kaddressbook_cut" );
1814 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1814 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1815 SLOT( pasteContacts() ), actionCollection(), 1815 SLOT( pasteContacts() ), actionCollection(),
1816 "kaddressbook_paste" ); 1816 "kaddressbook_paste" );
1817 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1817 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1818 SLOT( selectAllContacts() ), actionCollection(), 1818 SLOT( selectAllContacts() ), actionCollection(),
1819 "kaddressbook_select_all" ); 1819 "kaddressbook_select_all" );
1820 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1820 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1821 SLOT( undo() ), actionCollection(), 1821 SLOT( undo() ), actionCollection(),
1822 "kaddressbook_undo" ); 1822 "kaddressbook_undo" );
1823 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1823 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1824 this, SLOT( redo() ), actionCollection(), 1824 this, SLOT( redo() ), actionCollection(),
1825 "kaddressbook_redo" ); 1825 "kaddressbook_redo" );
1826 } else { 1826 } else {
1827 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1827 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1828 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1828 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1829 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1829 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1830 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1830 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1831 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1831 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1832 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1832 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1833 } 1833 }
1834 1834
1835 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1835 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1836 Key_Delete, this, SLOT( deleteContacts() ), 1836 Key_Delete, this, SLOT( deleteContacts() ),
1837 actionCollection(), "edit_delete" ); 1837 actionCollection(), "edit_delete" );
1838 1838
1839 mActionUndo->setEnabled( false ); 1839 mActionUndo->setEnabled( false );
1840 mActionRedo->setEnabled( false ); 1840 mActionRedo->setEnabled( false );
1841 1841
1842 // settings menu 1842 // settings menu
1843#ifdef KAB_EMBEDDED 1843#ifdef KAB_EMBEDDED
1844//US special menuentry to configure the addressbook resources. On KDE 1844//US special menuentry to configure the addressbook resources. On KDE
1845// you do that through the control center !!! 1845// you do that through the control center !!!
1846 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1846 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1847 SLOT( configureResources() ), actionCollection(), 1847 SLOT( configureResources() ), actionCollection(),
1848 "kaddressbook_configure_resources" ); 1848 "kaddressbook_configure_resources" );
1849#endif //KAB_EMBEDDED 1849#endif //KAB_EMBEDDED
1850 1850
1851 if ( mIsPart ) { 1851 if ( mIsPart ) {
1852 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1852 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1853 SLOT( openConfigDialog() ), actionCollection(), 1853 SLOT( openConfigDialog() ), actionCollection(),
1854 "kaddressbook_configure" ); 1854 "kaddressbook_configure" );
1855 1855
1856 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1856 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1857 this, SLOT( configureKeyBindings() ), actionCollection(), 1857 this, SLOT( configureKeyBindings() ), actionCollection(),
1858 "kaddressbook_configure_shortcuts" ); 1858 "kaddressbook_configure_shortcuts" );
1859#ifdef KAB_EMBEDDED 1859#ifdef KAB_EMBEDDED
1860 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1860 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1861 mActionConfigureToolbars->setEnabled( false ); 1861 mActionConfigureToolbars->setEnabled( false );
1862#endif //KAB_EMBEDDED 1862#endif //KAB_EMBEDDED
1863 1863
1864 } else { 1864 } else {
1865 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1865 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1866 1866
1867 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1867 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1868 } 1868 }
1869 1869
1870 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1870 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1871 actionCollection(), "options_show_jump_bar" ); 1871 actionCollection(), "options_show_jump_bar" );
1872 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1872 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1873 1873
1874 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1874 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1875 actionCollection(), "options_show_details" ); 1875 actionCollection(), "options_show_details" );
1876 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1876 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1877 1877
1878 // misc 1878 // misc
1879 // only enable LDAP lookup if we can handle the protocol 1879 // only enable LDAP lookup if we can handle the protocol
1880#ifndef KAB_EMBEDDED 1880#ifndef KAB_EMBEDDED
1881 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1881 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1882 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1882 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1883 this, SLOT( openLDAPDialog() ), actionCollection(), 1883 this, SLOT( openLDAPDialog() ), actionCollection(),
1884 "ldap_lookup" ); 1884 "ldap_lookup" );
1885 } 1885 }
1886#else //KAB_EMBEDDED 1886#else //KAB_EMBEDDED
1887 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1887 //qDebug("KABCore::initActions() LDAP has to be implemented");
1888#endif //KAB_EMBEDDED 1888#endif //KAB_EMBEDDED
1889 1889
1890 1890
1891 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1891 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1892 SLOT( setWhoAmI() ), actionCollection(), 1892 SLOT( setWhoAmI() ), actionCollection(),
1893 "set_personal" ); 1893 "set_personal" );
1894 1894
1895 1895
1896 1896
1897 1897
1898 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1898 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1899 SLOT( setCategories() ), actionCollection(), 1899 SLOT( setCategories() ), actionCollection(),
1900 "edit_set_categories" ); 1900 "edit_set_categories" );
1901 1901
1902 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1902 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1903 SLOT( removeVoice() ), actionCollection(), 1903 SLOT( removeVoice() ), actionCollection(),
1904 "remove_voice" ); 1904 "remove_voice" );
1905 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1905 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1906 SLOT( importFromOL() ), actionCollection(), 1906 SLOT( importFromOL() ), actionCollection(),
1907 "import_OL" ); 1907 "import_OL" );
1908#ifdef KAB_EMBEDDED 1908#ifdef KAB_EMBEDDED
1909 mActionLicence = new KAction( i18n( "Licence" ), 0, 1909 mActionLicence = new KAction( i18n( "Licence" ), 0,
1910 this, SLOT( showLicence() ), actionCollection(), 1910 this, SLOT( showLicence() ), actionCollection(),
1911 "licence_about_data" ); 1911 "licence_about_data" );
1912 mActionFaq = new KAction( i18n( "Faq" ), 0, 1912 mActionFaq = new KAction( i18n( "Faq" ), 0,
1913 this, SLOT( faq() ), actionCollection(), 1913 this, SLOT( faq() ), actionCollection(),
1914 "faq_about_data" ); 1914 "faq_about_data" );
1915 1915
1916 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1916 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1917 this, SLOT( createAboutData() ), actionCollection(), 1917 this, SLOT( createAboutData() ), actionCollection(),
1918 "kaddressbook_about_data" ); 1918 "kaddressbook_about_data" );
1919#endif //KAB_EMBEDDED 1919#endif //KAB_EMBEDDED
1920 1920
1921 clipboardDataChanged(); 1921 clipboardDataChanged();
1922 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1922 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1923 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1923 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1924} 1924}
1925 1925
1926//US we need this function, to plug all actions into the correct menues. 1926//US we need this function, to plug all actions into the correct menues.
1927// KDE uses a XML format to plug the actions, but we work her without this overhead. 1927// KDE uses a XML format to plug the actions, but we work her without this overhead.
1928void KABCore::addActionsManually() 1928void KABCore::addActionsManually()
1929{ 1929{
1930//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1930//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1931 1931
1932#ifdef KAB_EMBEDDED 1932#ifdef KAB_EMBEDDED
1933 QPopupMenu *fileMenu = new QPopupMenu( this ); 1933 QPopupMenu *fileMenu = new QPopupMenu( this );
1934 QPopupMenu *editMenu = new QPopupMenu( this ); 1934 QPopupMenu *editMenu = new QPopupMenu( this );
1935 QPopupMenu *helpMenu = new QPopupMenu( this ); 1935 QPopupMenu *helpMenu = new QPopupMenu( this );
1936 1936
1937 KToolBar* tb = mMainWindow->toolBar(); 1937 KToolBar* tb = mMainWindow->toolBar();
1938 1938
1939#ifdef DESKTOP_VERSION 1939#ifdef DESKTOP_VERSION
1940 QMenuBar* mb = mMainWindow->menuBar(); 1940 QMenuBar* mb = mMainWindow->menuBar();
1941 1941
1942 //US setup menubar. 1942 //US setup menubar.
1943 //Disable the following block if you do not want to have a menubar. 1943 //Disable the following block if you do not want to have a menubar.
1944 mb->insertItem( "&File", fileMenu ); 1944 mb->insertItem( "&File", fileMenu );
1945 mb->insertItem( "&Edit", editMenu ); 1945 mb->insertItem( "&Edit", editMenu );
1946 mb->insertItem( "&View", viewMenu ); 1946 mb->insertItem( "&View", viewMenu );
1947 mb->insertItem( "&Settings", settingsMenu ); 1947 mb->insertItem( "&Settings", settingsMenu );
1948 mb->insertItem( i18n("Synchronize"), syncMenu ); 1948 mb->insertItem( i18n("Synchronize"), syncMenu );
1949 mb->insertItem( "&Change selected", changeMenu ); 1949 mb->insertItem( "&Change selected", changeMenu );
1950 mb->insertItem( "&Help", helpMenu ); 1950 mb->insertItem( "&Help", helpMenu );
1951 mIncSearchWidget = new IncSearchWidget( tb ); 1951 mIncSearchWidget = new IncSearchWidget( tb );
1952 // tb->insertWidget(-1, 0, mIncSearchWidget); 1952 // tb->insertWidget(-1, 0, mIncSearchWidget);
1953 1953
1954#else 1954#else
1955 //US setup toolbar 1955 //US setup toolbar
1956 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1956 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1957 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1957 QPopupMenu *popupBarTB = new QPopupMenu( this );
1958 menuBarTB->insertItem( "ME", popupBarTB); 1958 menuBarTB->insertItem( "ME", popupBarTB);
1959 tb->insertWidget(-1, 0, menuBarTB); 1959 tb->insertWidget(-1, 0, menuBarTB);
1960 mIncSearchWidget = new IncSearchWidget( tb ); 1960 mIncSearchWidget = new IncSearchWidget( tb );
1961 1961
1962 tb->enableMoving(false); 1962 tb->enableMoving(false);
1963 popupBarTB->insertItem( "&File", fileMenu ); 1963 popupBarTB->insertItem( "&File", fileMenu );
1964 popupBarTB->insertItem( "&Edit", editMenu ); 1964 popupBarTB->insertItem( "&Edit", editMenu );
1965 popupBarTB->insertItem( "&View", viewMenu ); 1965 popupBarTB->insertItem( "&View", viewMenu );
1966 popupBarTB->insertItem( "&Settings", settingsMenu ); 1966 popupBarTB->insertItem( "&Settings", settingsMenu );
1967 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1967 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1968 mViewManager->getFilterAction()->plug ( popupBarTB); 1968 mViewManager->getFilterAction()->plug ( popupBarTB);
1969 popupBarTB->insertItem( "&Change selected", changeMenu ); 1969 popupBarTB->insertItem( "&Change selected", changeMenu );
1970 popupBarTB->insertItem( "&Help", helpMenu ); 1970 popupBarTB->insertItem( "&Help", helpMenu );
1971 if (QApplication::desktop()->width() > 320 ) { 1971 if (QApplication::desktop()->width() > 320 ) {
1972 // mViewManager->getFilterAction()->plug ( tb); 1972 // mViewManager->getFilterAction()->plug ( tb);
1973 } 1973 }
1974#endif 1974#endif
1975 // mActionQuit->plug ( mMainWindow->toolBar()); 1975 // mActionQuit->plug ( mMainWindow->toolBar());
1976 1976
1977 1977
1978 1978
1979 //US Now connect the actions with the menue entries. 1979 //US Now connect the actions with the menue entries.
1980 mActionPrint->plug( fileMenu ); 1980 mActionPrint->plug( fileMenu );
1981 mActionMail->plug( fileMenu ); 1981 mActionMail->plug( fileMenu );
1982 fileMenu->insertSeparator(); 1982 fileMenu->insertSeparator();
1983 1983
1984 mActionNewContact->plug( fileMenu ); 1984 mActionNewContact->plug( fileMenu );
1985 mActionNewContact->plug( tb ); 1985 mActionNewContact->plug( tb );
1986 1986
1987 mActionEditAddressee->plug( fileMenu ); 1987 mActionEditAddressee->plug( fileMenu );
1988 if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1988 if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1989 (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1989 (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1990 mActionEditAddressee->plug( tb ); 1990 mActionEditAddressee->plug( tb );
1991 1991
1992 fileMenu->insertSeparator(); 1992 fileMenu->insertSeparator();
1993 mActionSave->plug( fileMenu ); 1993 mActionSave->plug( fileMenu );
1994 fileMenu->insertItem( "&Import", ImportMenu ); 1994 fileMenu->insertItem( "&Import", ImportMenu );
1995 fileMenu->insertItem( "&Export", ExportMenu ); 1995 fileMenu->insertItem( "&Export", ExportMenu );
1996 fileMenu->insertSeparator(); 1996 fileMenu->insertSeparator();
1997 mActionMailVCard->plug( fileMenu ); 1997 mActionMailVCard->plug( fileMenu );
1998#ifndef DESKTOP_VERSION 1998#ifndef DESKTOP_VERSION
1999 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1999 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
2000 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 2000 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
2001#endif 2001#endif
2002 fileMenu->insertSeparator(); 2002 fileMenu->insertSeparator();
2003 mActionQuit->plug( fileMenu ); 2003 mActionQuit->plug( fileMenu );
2004#ifdef _WIN32_ 2004#ifdef _WIN32_
2005 mActionImportOL->plug( ImportMenu ); 2005 mActionImportOL->plug( ImportMenu );
2006#endif 2006#endif
2007 // edit menu 2007 // edit menu
2008 mActionUndo->plug( editMenu ); 2008 mActionUndo->plug( editMenu );
2009 mActionRedo->plug( editMenu ); 2009 mActionRedo->plug( editMenu );
2010 editMenu->insertSeparator(); 2010 editMenu->insertSeparator();
2011 mActionCut->plug( editMenu ); 2011 mActionCut->plug( editMenu );
2012 mActionCopy->plug( editMenu ); 2012 mActionCopy->plug( editMenu );
2013 mActionPaste->plug( editMenu ); 2013 mActionPaste->plug( editMenu );
2014 mActionDelete->plug( editMenu ); 2014 mActionDelete->plug( editMenu );
2015 editMenu->insertSeparator(); 2015 editMenu->insertSeparator();
2016 mActionSelectAll->plug( editMenu ); 2016 mActionSelectAll->plug( editMenu );
2017 2017
2018 mActionRemoveVoice->plug( changeMenu ); 2018 mActionRemoveVoice->plug( changeMenu );
2019 // settings menu 2019 // settings menu
2020//US special menuentry to configure the addressbook resources. On KDE 2020//US special menuentry to configure the addressbook resources. On KDE
2021// you do that through the control center !!! 2021// you do that through the control center !!!
2022 mActionConfigResources->plug( settingsMenu ); 2022 mActionConfigResources->plug( settingsMenu );
2023 settingsMenu->insertSeparator(); 2023 settingsMenu->insertSeparator();
2024 2024
2025 mActionConfigKAddressbook->plug( settingsMenu ); 2025 mActionConfigKAddressbook->plug( settingsMenu );
2026 2026
2027 if ( mIsPart ) { 2027 if ( mIsPart ) {
2028 mActionConfigShortcuts->plug( settingsMenu ); 2028 mActionConfigShortcuts->plug( settingsMenu );
2029 mActionConfigureToolbars->plug( settingsMenu ); 2029 mActionConfigureToolbars->plug( settingsMenu );
2030 2030
2031 } else { 2031 } else {
2032 mActionKeyBindings->plug( settingsMenu ); 2032 mActionKeyBindings->plug( settingsMenu );
2033 } 2033 }
2034 2034
2035 settingsMenu->insertSeparator(); 2035 settingsMenu->insertSeparator();
2036 2036
2037 mActionJumpBar->plug( settingsMenu ); 2037 mActionJumpBar->plug( settingsMenu );
2038 mActionDetails->plug( settingsMenu ); 2038 mActionDetails->plug( settingsMenu );
2039 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 2039 if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
2040 mActionDetails->plug( tb ); 2040 mActionDetails->plug( tb );
2041 settingsMenu->insertSeparator(); 2041 settingsMenu->insertSeparator();
2042 2042
2043 mActionWhoAmI->plug( settingsMenu ); 2043 mActionWhoAmI->plug( settingsMenu );
2044 mActionCategories->plug( settingsMenu ); 2044 mActionCategories->plug( settingsMenu );
2045 2045
2046 mActionLicence->plug( helpMenu ); 2046 mActionLicence->plug( helpMenu );
2047 mActionFaq->plug( helpMenu ); 2047 mActionFaq->plug( helpMenu );
2048 mActionAboutKAddressbook->plug( helpMenu ); 2048 mActionAboutKAddressbook->plug( helpMenu );
2049 2049
2050 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 2050 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
2051 2051
2052 mActionSave->plug( tb ); 2052 mActionSave->plug( tb );
2053 mViewManager->getFilterAction()->plug ( tb); 2053 mViewManager->getFilterAction()->plug ( tb);
2054 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 2054 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
2055 mActionUndo->plug( tb ); 2055 mActionUndo->plug( tb );
2056 mActionDelete->plug( tb ); 2056 mActionDelete->plug( tb );
2057 mActionRedo->plug( tb ); 2057 mActionRedo->plug( tb );
2058 } 2058 }
2059 } 2059 }
2060 //mActionQuit->plug ( tb ); 2060 //mActionQuit->plug ( tb );
2061 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 2061 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
2062 2062
2063 //US link the searchwidget first to this. 2063 //US link the searchwidget first to this.
2064 // The real linkage to the toolbar happens later. 2064 // The real linkage to the toolbar happens later.
2065//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 2065//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
2066//US tb->insertItem( mIncSearchWidget ); 2066//US tb->insertItem( mIncSearchWidget );
2067/*US 2067/*US
2068 mIncSearchWidget = new IncSearchWidget( tb ); 2068 mIncSearchWidget = new IncSearchWidget( tb );
2069 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 2069 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
2070 SLOT( incrementalSearch( const QString& ) ) ); 2070 SLOT( incrementalSearch( const QString& ) ) );
2071 2071
2072 mJumpButtonBar = new JumpButtonBar( this, this ); 2072 mJumpButtonBar = new JumpButtonBar( this, this );
2073 2073
2074//US topLayout->addWidget( mJumpButtonBar ); 2074//US topLayout->addWidget( mJumpButtonBar );
2075 this->layout()->add( mJumpButtonBar ); 2075 this->layout()->add( mJumpButtonBar );
2076*/ 2076*/
2077 2077
2078#endif //KAB_EMBEDDED 2078#endif //KAB_EMBEDDED
2079 2079
2080 mActionExport2phone->plug( ExportMenu ); 2080 mActionExport2phone->plug( ExportMenu );
2081 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 2081 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
2082 syncManager->fillSyncMenu(); 2082 syncManager->fillSyncMenu();
2083 2083
2084} 2084}
2085void KABCore::showLicence() 2085void KABCore::showLicence()
2086{ 2086{
2087 KApplication::showLicence(); 2087 KApplication::showLicence();
2088} 2088}
2089void KABCore::removeVoice() 2089void KABCore::removeVoice()
2090{ 2090{
2091 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 ) 2091 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 )
2092 return; 2092 return;
2093 KABC::Addressee::List list = mViewManager->selectedAddressees(); 2093 KABC::Addressee::List list = mViewManager->selectedAddressees();
2094 KABC::Addressee::List::Iterator it; 2094 KABC::Addressee::List::Iterator it;
2095 for ( it = list.begin(); it != list.end(); ++it ) { 2095 for ( it = list.begin(); it != list.end(); ++it ) {
2096 2096
2097 if ( (*it).removeVoice() ) 2097 if ( (*it).removeVoice() )
2098 contactModified((*it) ); 2098 contactModified((*it) );
2099 } 2099 }
2100} 2100}
2101 2101
2102 2102
2103 2103
2104void KABCore::clipboardDataChanged() 2104void KABCore::clipboardDataChanged()
2105{ 2105{
2106 2106
2107 if ( mReadWrite ) 2107 if ( mReadWrite )
2108 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2108 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2109 2109
2110} 2110}
2111 2111
2112void KABCore::updateActionMenu() 2112void KABCore::updateActionMenu()
2113{ 2113{
2114 UndoStack *undo = UndoStack::instance(); 2114 UndoStack *undo = UndoStack::instance();
2115 RedoStack *redo = RedoStack::instance(); 2115 RedoStack *redo = RedoStack::instance();
2116 2116
2117 if ( undo->isEmpty() ) 2117 if ( undo->isEmpty() )
2118 mActionUndo->setText( i18n( "Undo" ) ); 2118 mActionUndo->setText( i18n( "Undo" ) );
2119 else 2119 else
2120 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2120 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2121 2121
2122 mActionUndo->setEnabled( !undo->isEmpty() ); 2122 mActionUndo->setEnabled( !undo->isEmpty() );
2123 2123
2124 if ( !redo->top() ) 2124 if ( !redo->top() )
2125 mActionRedo->setText( i18n( "Redo" ) ); 2125 mActionRedo->setText( i18n( "Redo" ) );
2126 else 2126 else
2127 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 2127 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
2128 2128
2129 mActionRedo->setEnabled( !redo->isEmpty() ); 2129 mActionRedo->setEnabled( !redo->isEmpty() );
2130} 2130}
2131 2131
2132void KABCore::configureKeyBindings() 2132void KABCore::configureKeyBindings()
2133{ 2133{
2134#ifndef KAB_EMBEDDED 2134#ifndef KAB_EMBEDDED
2135 KKeyDialog::configure( actionCollection(), true ); 2135 KKeyDialog::configure( actionCollection(), true );
2136#else //KAB_EMBEDDED 2136#else //KAB_EMBEDDED
2137 qDebug("KABCore::configureKeyBindings() not implemented"); 2137 qDebug("KABCore::configureKeyBindings() not implemented");
2138#endif //KAB_EMBEDDED 2138#endif //KAB_EMBEDDED
2139} 2139}
2140 2140
2141#ifdef KAB_EMBEDDED 2141#ifdef KAB_EMBEDDED
2142void KABCore::configureResources() 2142void KABCore::configureResources()
2143{ 2143{
2144 KRES::KCMKResources dlg( this, "" , 0 ); 2144 KRES::KCMKResources dlg( this, "" , 0 );
2145 2145
2146 if ( !dlg.exec() ) 2146 if ( !dlg.exec() )
2147 return; 2147 return;
2148 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 2148 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
2149} 2149}
2150#endif //KAB_EMBEDDED 2150#endif //KAB_EMBEDDED
2151 2151
2152 2152
2153/* this method will be called through the QCop interface from Ko/Pi to select addresses 2153/* this method will be called through the QCop interface from Ko/Pi to select addresses
2154 * for the attendees list of an event. 2154 * for the attendees list of an event.
2155 */ 2155 */
2156void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 2156void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
2157{ 2157{
2158 QStringList nameList; 2158 QStringList nameList;
2159 QStringList emailList; 2159 QStringList emailList;
2160 QStringList uidList; 2160 QStringList uidList;
2161 2161
2162 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 2162 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
2163 uint i=0; 2163 uint i=0;
2164 for (i=0; i < list.count(); i++) 2164 for (i=0; i < list.count(); i++)
2165 { 2165 {
2166 nameList.append(list[i].realName()); 2166 nameList.append(list[i].realName());
2167 emailList.append(list[i].preferredEmail()); 2167 emailList.append(list[i].preferredEmail());
2168 uidList.append(list[i].uid()); 2168 uidList.append(list[i].uid());
2169 } 2169 }
2170 2170
2171 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2171 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2172 2172
2173} 2173}
2174 2174
2175/* this method will be called through the QCop interface from Ko/Pi to select birthdays 2175/* this method will be called through the QCop interface from Ko/Pi to select birthdays
2176 * to put them into the calendar. 2176 * to put them into the calendar.
2177 */ 2177 */
2178void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) 2178void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
2179{ 2179{
2180 // qDebug("KABCore::requestForBirthdayList"); 2180 // qDebug("KABCore::requestForBirthdayList");
2181 QStringList birthdayList; 2181 QStringList birthdayList;
2182 QStringList anniversaryList; 2182 QStringList anniversaryList;
2183 QStringList realNameList; 2183 QStringList realNameList;
2184 QStringList preferredEmailList; 2184 QStringList preferredEmailList;
2185 QStringList assembledNameList; 2185 QStringList assembledNameList;
2186 QStringList uidList; 2186 QStringList uidList;
2187 2187
2188 KABC::AddressBook::Iterator it; 2188 KABC::AddressBook::Iterator it;
2189 2189
2190 int count = 0; 2190 int count = 0;
2191 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 2191 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2192 ++count; 2192 ++count;
2193 } 2193 }
2194 QProgressBar bar(count,0 ); 2194 QProgressBar bar(count,0 );
2195 int w = 300; 2195 int w = 300;
2196 if ( QApplication::desktop()->width() < 320 ) 2196 if ( QApplication::desktop()->width() < 320 )
2197 w = 220; 2197 w = 220;
2198 int h = bar.sizeHint().height() ; 2198 int h = bar.sizeHint().height() ;
2199 int dw = QApplication::desktop()->width(); 2199 int dw = QApplication::desktop()->width();
2200 int dh = QApplication::desktop()->height(); 2200 int dh = QApplication::desktop()->height();
2201 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2201 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2202 bar.show(); 2202 bar.show();
2203 bar.setCaption (i18n("collecting birthdays - close to abort!") ); 2203 bar.setCaption (i18n("collecting birthdays - close to abort!") );
2204 qApp->processEvents(); 2204 qApp->processEvents();
2205 2205
2206 QDate bday; 2206 QDate bday;
2207 QString anni; 2207 QString anni;
2208 QString formattedbday; 2208 QString formattedbday;
2209 2209
2210 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) 2210 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
2211 { 2211 {
2212 if ( ! bar.isVisible() ) 2212 if ( ! bar.isVisible() )
2213 return; 2213 return;
2214 bar.setProgress( count++ ); 2214 bar.setProgress( count++ );
2215 qApp->processEvents(); 2215 qApp->processEvents();
2216 bday = (*it).birthday().date(); 2216 bday = (*it).birthday().date();
2217 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); 2217 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
2218 2218
2219 if ( bday.isValid() || !anni.isEmpty()) 2219 if ( bday.isValid() || !anni.isEmpty())
2220 { 2220 {
2221 if (bday.isValid()) 2221 if (bday.isValid())
2222 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); 2222 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
2223 else 2223 else
2224 formattedbday = "NOTVALID"; 2224 formattedbday = "NOTVALID";
2225 if (anni.isEmpty()) 2225 if (anni.isEmpty())
2226 anni = "INVALID"; 2226 anni = "INVALID";
2227 2227
2228 birthdayList.append(formattedbday); 2228 birthdayList.append(formattedbday);
2229 anniversaryList.append(anni); //should be ISODate 2229 anniversaryList.append(anni); //should be ISODate
2230 realNameList.append((*it).realName()); 2230 realNameList.append((*it).realName());
2231 preferredEmailList.append((*it).preferredEmail()); 2231 preferredEmailList.append((*it).preferredEmail());
2232 assembledNameList.append((*it).assembledName()); 2232 assembledNameList.append((*it).assembledName());
2233 uidList.append((*it).uid()); 2233 uidList.append((*it).uid());
2234 2234
2235 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() ); 2235 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() );
2236 } 2236 }
2237 } 2237 }
2238 2238
2239 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); 2239 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
2240 2240
2241} 2241}
2242 2242
2243/* this method will be called through the QCop interface from other apps to show details of a contact. 2243/* this method will be called through the QCop interface from other apps to show details of a contact.
2244 */ 2244 */
2245void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2245void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2246{ 2246{
2247 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2247 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2248 2248
2249 QString foundUid = QString::null; 2249 QString foundUid = QString::null;
2250 if ( ! uid.isEmpty() ) { 2250 if ( ! uid.isEmpty() ) {
2251 Addressee adrr = mAddressBook->findByUid( uid ); 2251 Addressee adrr = mAddressBook->findByUid( uid );
2252 if ( !adrr.isEmpty() ) { 2252 if ( !adrr.isEmpty() ) {
2253 foundUid = uid; 2253 foundUid = uid;
2254 } 2254 }
2255 if ( email == "sendbacklist" ) { 2255 if ( email == "sendbacklist" ) {
2256 //qDebug("ssssssssssssssssssssssend "); 2256 //qDebug("ssssssssssssssssssssssend ");
2257 QStringList nameList; 2257 QStringList nameList;
2258 QStringList emailList; 2258 QStringList emailList;
2259 QStringList uidList; 2259 QStringList uidList;
2260 nameList.append(adrr.realName()); 2260 nameList.append(adrr.realName());
2261 emailList = adrr.emails(); 2261 emailList = adrr.emails();
2262 uidList.append( adrr.preferredEmail()); 2262 uidList.append( adrr.preferredEmail());
2263 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2263 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2264 return; 2264 return;
2265 } 2265 }
2266 2266
2267 } 2267 }
2268 2268
2269 if ( email == "sendbacklist" ) 2269 if ( email == "sendbacklist" )
2270 return; 2270 return;
2271 if (foundUid.isEmpty()) 2271 if (foundUid.isEmpty())
2272 { 2272 {
2273 //find the uid of the person first 2273 //find the uid of the person first
2274 Addressee::List namelist; 2274 Addressee::List namelist;
2275 Addressee::List emaillist; 2275 Addressee::List emaillist;
2276 2276
2277 if (!name.isEmpty()) 2277 if (!name.isEmpty())
2278 namelist = mAddressBook->findByName( name ); 2278 namelist = mAddressBook->findByName( name );
2279 2279
2280 if (!email.isEmpty()) 2280 if (!email.isEmpty())
2281 emaillist = mAddressBook->findByEmail( email ); 2281 emaillist = mAddressBook->findByEmail( email );
2282 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2282 qDebug("count %d %d ", namelist.count(),emaillist.count() );
2283 //check if we have a match in Namelist and Emaillist 2283 //check if we have a match in Namelist and Emaillist
2284 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2284 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2285 foundUid = emaillist[0].uid(); 2285 foundUid = emaillist[0].uid();
2286 } 2286 }
2287 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2287 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2288 foundUid = namelist[0].uid(); 2288 foundUid = namelist[0].uid();
2289 else 2289 else
2290 { 2290 {
2291 for (int i = 0; i < namelist.count(); i++) 2291 for (int i = 0; i < namelist.count(); i++)
2292 { 2292 {
2293 for (int j = 0; j < emaillist.count(); j++) 2293 for (int j = 0; j < emaillist.count(); j++)
2294 { 2294 {
2295 if (namelist[i] == emaillist[j]) 2295 if (namelist[i] == emaillist[j])
2296 { 2296 {
2297 foundUid = namelist[i].uid(); 2297 foundUid = namelist[i].uid();
2298 } 2298 }
2299 } 2299 }
2300 } 2300 }
2301 } 2301 }
2302 } 2302 }
2303 else 2303 else
2304 { 2304 {
2305 foundUid = uid; 2305 foundUid = uid;
2306 } 2306 }
2307 2307
2308 if (!foundUid.isEmpty()) 2308 if (!foundUid.isEmpty())
2309 { 2309 {
2310 2310
2311 // raise Ka/Pi if it is in the background 2311 // raise Ka/Pi if it is in the background
2312#ifndef DESKTOP_VERSION 2312#ifndef DESKTOP_VERSION
2313#ifndef KORG_NODCOP 2313#ifndef KORG_NODCOP
2314 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2314 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2315#endif 2315#endif
2316#endif 2316#endif
2317 2317
2318 mMainWindow->showMaximized(); 2318 mMainWindow->showMaximized();
2319 mMainWindow-> raise(); 2319 mMainWindow-> raise();
2320 2320
2321 mViewManager->setSelected( "", false); 2321 mViewManager->setSelected( "", false);
2322 mViewManager->refreshView( "" ); 2322 mViewManager->refreshView( "" );
2323 mViewManager->setSelected( foundUid, true ); 2323 mViewManager->setSelected( foundUid, true );
2324 mViewManager->refreshView( foundUid ); 2324 mViewManager->refreshView( foundUid );
2325 2325
2326 if ( !mMultipleViewsAtOnce ) 2326 if ( !mMultipleViewsAtOnce )
2327 { 2327 {
2328 setDetailsVisible( true ); 2328 setDetailsVisible( true );
2329 mActionDetails->setChecked(true); 2329 mActionDetails->setChecked(true);
2330 } 2330 }
2331 } 2331 }
2332} 2332}
2333 2333
2334 2334
2335void KABCore::faq() 2335void KABCore::faq()
2336{ 2336{
2337 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2337 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2338} 2338}
2339 2339
2340#include <libkcal/syncdefines.h> 2340#include <libkcal/syncdefines.h>
2341 2341
2342KABC::Addressee KABCore::getLastSyncAddressee() 2342KABC::Addressee KABCore::getLastSyncAddressee()
2343{ 2343{
2344 Addressee lse; 2344 Addressee lse;
2345 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2345 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2346 2346
2347 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2347 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2348 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2348 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2349 if (lse.isEmpty()) { 2349 if (lse.isEmpty()) {
2350 qDebug("Creating new last-syncAddressee "); 2350 qDebug("Creating new last-syncAddressee ");
2351 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2351 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2352 QString sum = ""; 2352 QString sum = "";
2353 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2353 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2354 sum = "E: "; 2354 sum = "E: ";
2355 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2355 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2356 lse.setRevision( mLastAddressbookSync ); 2356 lse.setRevision( mLastAddressbookSync );
2357 lse.setCategories( i18n("SyncEvent") ); 2357 lse.setCategories( i18n("SyncEvent") );
2358 mAddressBook->insertAddressee( lse ); 2358 mAddressBook->insertAddressee( lse );
2359 } 2359 }
2360 return lse; 2360 return lse;
2361} 2361}
2362int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2362int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2363{ 2363{
2364 2364
2365 //void setZaurusId(int id); 2365 //void setZaurusId(int id);
2366 // int zaurusId() const; 2366 // int zaurusId() const;
2367 // void setZaurusUid(int id); 2367 // void setZaurusUid(int id);
2368 // int zaurusUid() const; 2368 // int zaurusUid() const;
2369 // void setZaurusStat(int id); 2369 // void setZaurusStat(int id);
2370 // int zaurusStat() const; 2370 // int zaurusStat() const;
2371 // 0 equal 2371 // 0 equal
2372 // 1 take local 2372 // 1 take local
2373 // 2 take remote 2373 // 2 take remote
2374 // 3 cancel 2374 // 3 cancel
2375 QDateTime lastSync = mLastAddressbookSync; 2375 QDateTime lastSync = mLastAddressbookSync;
2376 QDateTime localMod = local->revision(); 2376 QDateTime localMod = local->revision();
2377 QDateTime remoteMod = remote->revision(); 2377 QDateTime remoteMod = remote->revision();
2378 2378
2379 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2379 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2380 2380
2381 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2381 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2382 bool remCh, locCh; 2382 bool remCh, locCh;
2383 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2383 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2384 2384
2385 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2385 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2386 locCh = ( localMod > mLastAddressbookSync ); 2386 locCh = ( localMod > mLastAddressbookSync );
2387 if ( !remCh && ! locCh ) { 2387 if ( !remCh && ! locCh ) {
2388 //qDebug("both not changed "); 2388 //qDebug("both not changed ");
2389 lastSync = localMod.addDays(1); 2389 lastSync = localMod.addDays(1);
2390 if ( mode <= SYNC_PREF_ASK ) 2390 if ( mode <= SYNC_PREF_ASK )
2391 return 0; 2391 return 0;
2392 } else { 2392 } else {
2393 if ( locCh ) { 2393 if ( locCh ) {
2394 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2394 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2395 lastSync = localMod.addDays( -1 ); 2395 lastSync = localMod.addDays( -1 );
2396 if ( !remCh ) 2396 if ( !remCh )
2397 remoteMod =( lastSync.addDays( -1 ) ); 2397 remoteMod =( lastSync.addDays( -1 ) );
2398 } else { 2398 } else {
2399 //qDebug(" not loc changed "); 2399 //qDebug(" not loc changed ");
2400 lastSync = localMod.addDays( 1 ); 2400 lastSync = localMod.addDays( 1 );
2401 if ( remCh ) 2401 if ( remCh )
2402 remoteMod =( lastSync.addDays( 1 ) ); 2402 remoteMod =( lastSync.addDays( 1 ) );
2403 2403
2404 } 2404 }
2405 } 2405 }
2406 full = true; 2406 full = true;
2407 if ( mode < SYNC_PREF_ASK ) 2407 if ( mode < SYNC_PREF_ASK )
2408 mode = SYNC_PREF_ASK; 2408 mode = SYNC_PREF_ASK;
2409 } else { 2409 } else {
2410 if ( localMod == remoteMod ) 2410 if ( localMod == remoteMod )
2411 return 0; 2411 return 0;
2412 2412
2413 } 2413 }
2414 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2414 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2415 2415
2416 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2416 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2417 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2417 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2418 //full = true; //debug only 2418 //full = true; //debug only
2419 if ( full ) { 2419 if ( full ) {
2420 bool equ = ( (*local) == (*remote) ); 2420 bool equ = ( (*local) == (*remote) );
2421 if ( equ ) { 2421 if ( equ ) {
2422 //qDebug("equal "); 2422 //qDebug("equal ");
2423 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2423 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2424 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2424 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2425 } 2425 }
2426 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2426 if ( mode < SYNC_PREF_FORCE_LOCAL )
2427 return 0; 2427 return 0;
2428 2428
2429 }//else //debug only 2429 }//else //debug only
2430 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2430 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2431 } 2431 }
2432 int result; 2432 int result;
2433 bool localIsNew; 2433 bool localIsNew;
2434 //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() ); 2434 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2435 2435
2436 if ( full && mode < SYNC_PREF_NEWEST ) 2436 if ( full && mode < SYNC_PREF_NEWEST )
2437 mode = SYNC_PREF_ASK; 2437 mode = SYNC_PREF_ASK;
2438 2438
2439 switch( mode ) { 2439 switch( mode ) {
2440 case SYNC_PREF_LOCAL: 2440 case SYNC_PREF_LOCAL:
2441 if ( lastSync > remoteMod ) 2441 if ( lastSync > remoteMod )
2442 return 1; 2442 return 1;
2443 if ( lastSync > localMod ) 2443 if ( lastSync > localMod )
2444 return 2; 2444 return 2;
2445 return 1; 2445 return 1;
2446 break; 2446 break;
2447 case SYNC_PREF_REMOTE: 2447 case SYNC_PREF_REMOTE:
2448 if ( lastSync > remoteMod ) 2448 if ( lastSync > remoteMod )
2449 return 1; 2449 return 1;
2450 if ( lastSync > localMod ) 2450 if ( lastSync > localMod )
2451 return 2; 2451 return 2;
2452 return 2; 2452 return 2;
2453 break; 2453 break;
2454 case SYNC_PREF_NEWEST: 2454 case SYNC_PREF_NEWEST:
2455 if ( localMod > remoteMod ) 2455 if ( localMod > remoteMod )
2456 return 1; 2456 return 1;
2457 else 2457 else
2458 return 2; 2458 return 2;
2459 break; 2459 break;
2460 case SYNC_PREF_ASK: 2460 case SYNC_PREF_ASK:
2461 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2461 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2462 if ( lastSync > remoteMod ) 2462 if ( lastSync > remoteMod )
2463 return 1; 2463 return 1;
2464 if ( lastSync > localMod ) 2464 if ( lastSync > localMod )
2465 return 2; 2465 return 2;
2466 localIsNew = localMod >= remoteMod; 2466 localIsNew = localMod >= remoteMod;
2467 //qDebug("conflict! ************************************** "); 2467 //qDebug("conflict! ************************************** ");
2468 { 2468 {
2469 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2469 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2470 result = acd.executeD(localIsNew); 2470 result = acd.executeD(localIsNew);
2471 return result; 2471 return result;
2472 } 2472 }
2473 break; 2473 break;
2474 case SYNC_PREF_FORCE_LOCAL: 2474 case SYNC_PREF_FORCE_LOCAL:
2475 return 1; 2475 return 1;
2476 break; 2476 break;
2477 case SYNC_PREF_FORCE_REMOTE: 2477 case SYNC_PREF_FORCE_REMOTE:
2478 return 2; 2478 return 2;
2479 break; 2479 break;
2480 2480
2481 default: 2481 default:
2482 // SYNC_PREF_TAKE_BOTH not implemented 2482 // SYNC_PREF_TAKE_BOTH not implemented
2483 break; 2483 break;
2484 } 2484 }
2485 return 0; 2485 return 0;
2486} 2486}
2487 2487
2488 2488
2489bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2489bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2490{ 2490{
2491 bool syncOK = true; 2491 bool syncOK = true;
2492 int addedAddressee = 0; 2492 int addedAddressee = 0;
2493 int addedAddresseeR = 0; 2493 int addedAddresseeR = 0;
2494 int deletedAddresseeR = 0; 2494 int deletedAddresseeR = 0;
2495 int deletedAddresseeL = 0; 2495 int deletedAddresseeL = 0;
2496 int changedLocal = 0; 2496 int changedLocal = 0;
2497 int changedRemote = 0; 2497 int changedRemote = 0;
2498 2498
2499 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2499 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2500 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2500 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2501 2501
2502 //QPtrList<Addressee> el = local->rawAddressees(); 2502 //QPtrList<Addressee> el = local->rawAddressees();
2503 Addressee addresseeR; 2503 Addressee addresseeR;
2504 QString uid; 2504 QString uid;
2505 int take; 2505 int take;
2506 Addressee addresseeL; 2506 Addressee addresseeL;
2507 Addressee addresseeRSync; 2507 Addressee addresseeRSync;
2508 Addressee addresseeLSync; 2508 Addressee addresseeLSync;
2509 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2509 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2510 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2510 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2511 bool fullDateRange = false; 2511 bool fullDateRange = false;
2512 local->resetTempSyncStat(); 2512 local->resetTempSyncStat();
2513 mLastAddressbookSync = QDateTime::currentDateTime(); 2513 mLastAddressbookSync = QDateTime::currentDateTime();
2514 QDateTime modifiedCalendar = mLastAddressbookSync;; 2514 QDateTime modifiedCalendar = mLastAddressbookSync;;
2515 addresseeLSync = getLastSyncAddressee(); 2515 addresseeLSync = getLastSyncAddressee();
2516 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2516 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2517 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2517 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2518 if ( !addresseeR.isEmpty() ) { 2518 if ( !addresseeR.isEmpty() ) {
2519 addresseeRSync = addresseeR; 2519 addresseeRSync = addresseeR;
2520 remote->removeAddressee(addresseeR ); 2520 remote->removeAddressee(addresseeR );
2521 2521
2522 } else { 2522 } else {
2523 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2523 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2524 addresseeRSync = addresseeLSync ; 2524 addresseeRSync = addresseeLSync ;
2525 } else { 2525 } else {
2526 qDebug("FULLDATE 1"); 2526 qDebug("FULLDATE 1");
2527 fullDateRange = true; 2527 fullDateRange = true;
2528 Addressee newAdd; 2528 Addressee newAdd;
2529 addresseeRSync = newAdd; 2529 addresseeRSync = newAdd;
2530 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2530 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2531 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2531 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2532 addresseeRSync.setRevision( mLastAddressbookSync ); 2532 addresseeRSync.setRevision( mLastAddressbookSync );
2533 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2533 addresseeRSync.setCategories( i18n("SyncAddressee") );
2534 } 2534 }
2535 } 2535 }
2536 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2536 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2537 qDebug("FULLDATE 2"); 2537 qDebug("FULLDATE 2");
2538 fullDateRange = true; 2538 fullDateRange = true;
2539 } 2539 }
2540 if ( ! fullDateRange ) { 2540 if ( ! fullDateRange ) {
2541 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2541 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2542 2542
2543 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2543 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2544 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2544 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2545 fullDateRange = true; 2545 fullDateRange = true;
2546 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2546 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2547 } 2547 }
2548 } 2548 }
2549 // fullDateRange = true; // debug only! 2549 // fullDateRange = true; // debug only!
2550 if ( fullDateRange ) 2550 if ( fullDateRange )
2551 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2551 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2552 else 2552 else
2553 mLastAddressbookSync = addresseeLSync.revision(); 2553 mLastAddressbookSync = addresseeLSync.revision();
2554 // for resyncing if own file has changed 2554 // for resyncing if own file has changed
2555 // PENDING fixme later when implemented 2555 // PENDING fixme later when implemented
2556#if 0 2556#if 0
2557 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2557 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2558 mLastAddressbookSync = loadedFileVersion; 2558 mLastAddressbookSync = loadedFileVersion;
2559 qDebug("setting mLastAddressbookSync "); 2559 qDebug("setting mLastAddressbookSync ");
2560 } 2560 }
2561#endif 2561#endif
2562 2562
2563 //qDebug("*************************** "); 2563 //qDebug("*************************** ");
2564 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2564 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2565 QStringList er = remote->uidList(); 2565 QStringList er = remote->uidList();
2566 Addressee inR ;//= er.first(); 2566 Addressee inR ;//= er.first();
2567 Addressee inL; 2567 Addressee inL;
2568 2568
2569 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2569 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2570 2570
2571 int modulo = (er.count()/10)+1; 2571 int modulo = (er.count()/10)+1;
2572 int incCounter = 0; 2572 int incCounter = 0;
2573 while ( incCounter < er.count()) { 2573 while ( incCounter < er.count()) {
2574 if (syncManager->isProgressBarCanceled()) 2574 if (syncManager->isProgressBarCanceled())
2575 return false; 2575 return false;
2576 if ( incCounter % modulo == 0 ) 2576 if ( incCounter % modulo == 0 )
2577 syncManager->showProgressBar(incCounter); 2577 syncManager->showProgressBar(incCounter);
2578 2578
2579 uid = er[ incCounter ]; 2579 uid = er[ incCounter ];
2580 bool skipIncidence = false; 2580 bool skipIncidence = false;
2581 if ( uid.left(19) == QString("last-syncAddressee-") ) 2581 if ( uid.left(19) == QString("last-syncAddressee-") )
2582 skipIncidence = true; 2582 skipIncidence = true;
2583 QString idS,OidS; 2583 QString idS,OidS;
2584 qApp->processEvents(); 2584 qApp->processEvents();
2585 if ( !skipIncidence ) { 2585 if ( !skipIncidence ) {
2586 inL = local->findByUid( uid ); 2586 inL = local->findByUid( uid );
2587 inR = remote->findByUid( uid ); 2587 inR = remote->findByUid( uid );
2588 //inL.setResource( 0 ); 2588 //inL.setResource( 0 );
2589 //inR.setResource( 0 ); 2589 //inR.setResource( 0 );
2590 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2590 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2591 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2591 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2592 //qDebug("take %d %s ", take, inL.summary().latin1()); 2592 //qDebug("take %d %s ", take, inL.summary().latin1());
2593 if ( take == 3 ) 2593 if ( take == 3 )
2594 return false; 2594 return false;
2595 if ( take == 1 ) {// take local 2595 if ( take == 1 ) {// take local
2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2597 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2597 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2598 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2598 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2599 local->insertAddressee( inL, false ); 2599 local->insertAddressee( inL, false );
2600 idS = inR.externalUID(); 2600 idS = inR.externalUID();
2601 OidS = inR.originalExternalUID(); 2601 OidS = inR.originalExternalUID();
2602 } 2602 }
2603 else 2603 else
2604 idS = inR.IDStr(); 2604 idS = inR.IDStr();
2605 remote->removeAddressee( inR ); 2605 remote->removeAddressee( inR );
2606 inR = inL; 2606 inR = inL;
2607 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2607 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2608 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2608 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2609 inR.setOriginalExternalUID( OidS ); 2609 inR.setOriginalExternalUID( OidS );
2610 inR.setExternalUID( idS ); 2610 inR.setExternalUID( idS );
2611 } else { 2611 } else {
2612 inR.setIDStr( idS ); 2612 inR.setIDStr( idS );
2613 } 2613 }
2614 inR.setResource( 0 ); 2614 inR.setResource( 0 );
2615 remote->insertAddressee( inR , false); 2615 remote->insertAddressee( inR , false);
2616 ++changedRemote; 2616 ++changedRemote;
2617 } else { // take == 2 take remote 2617 } else { // take == 2 take remote
2618 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2618 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2619 if ( inR.revision().date().year() < 2004 ) 2619 if ( inR.revision().date().year() < 2004 )
2620 inR.setRevision( modifiedCalendar ); 2620 inR.setRevision( modifiedCalendar );
2621 } 2621 }
2622 idS = inL.IDStr(); 2622 idS = inL.IDStr();
2623 local->removeAddressee( inL ); 2623 local->removeAddressee( inL );
2624 inL = inR; 2624 inL = inR;
2625 inL.setIDStr( idS ); 2625 inL.setIDStr( idS );
2626 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2626 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2627 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2627 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2628 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2628 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2629 } 2629 }
2630 inL.setResource( 0 ); 2630 inL.setResource( 0 );
2631 local->insertAddressee( inL , false ); 2631 local->insertAddressee( inL , false );
2632 ++changedLocal; 2632 ++changedLocal;
2633 } 2633 }
2634 } 2634 }
2635 } else { // no conflict 2635 } else { // no conflict
2636 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2636 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2637 QString des = addresseeLSync.note(); 2637 QString des = addresseeLSync.note();
2638 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2638 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2639 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2639 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2640 remote->insertAddressee( inR, false ); 2640 remote->insertAddressee( inR, false );
2641 ++deletedAddresseeR; 2641 ++deletedAddresseeR;
2642 } else { 2642 } else {
2643 inR.setRevision( modifiedCalendar ); 2643 inR.setRevision( modifiedCalendar );
2644 remote->insertAddressee( inR, false ); 2644 remote->insertAddressee( inR, false );
2645 inL = inR; 2645 inL = inR;
2646 inL.setResource( 0 ); 2646 inL.setResource( 0 );
2647 local->insertAddressee( inL , false); 2647 local->insertAddressee( inL , false);
2648 ++addedAddressee; 2648 ++addedAddressee;
2649 } 2649 }
2650 } else { 2650 } else {
2651 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2651 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2652 inR.setRevision( modifiedCalendar ); 2652 inR.setRevision( modifiedCalendar );
2653 remote->insertAddressee( inR, false ); 2653 remote->insertAddressee( inR, false );
2654 inR.setResource( 0 ); 2654 inR.setResource( 0 );
2655 local->insertAddressee( inR, false ); 2655 local->insertAddressee( inR, false );
2656 ++addedAddressee; 2656 ++addedAddressee;
2657 } else { 2657 } else {
2658 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2658 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2659 remote->removeAddressee( inR ); 2659 remote->removeAddressee( inR );
2660 ++deletedAddresseeR; 2660 ++deletedAddresseeR;
2661 } 2661 }
2662 } 2662 }
2663 } 2663 }
2664 } 2664 }
2665 ++incCounter; 2665 ++incCounter;
2666 } 2666 }
2667 er.clear(); 2667 er.clear();
2668 QStringList el = local->uidList(); 2668 QStringList el = local->uidList();
2669 modulo = (el.count()/10)+1; 2669 modulo = (el.count()/10)+1;
2670 2670
2671 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2671 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2672 incCounter = 0; 2672 incCounter = 0;
2673 while ( incCounter < el.count()) { 2673 while ( incCounter < el.count()) {
2674 qApp->processEvents(); 2674 qApp->processEvents();
2675 if (syncManager->isProgressBarCanceled()) 2675 if (syncManager->isProgressBarCanceled())
2676 return false; 2676 return false;
2677 if ( incCounter % modulo == 0 ) 2677 if ( incCounter % modulo == 0 )
2678 syncManager->showProgressBar(incCounter); 2678 syncManager->showProgressBar(incCounter);
2679 uid = el[ incCounter ]; 2679 uid = el[ incCounter ];
2680 bool skipIncidence = false; 2680 bool skipIncidence = false;
2681 if ( uid.left(19) == QString("last-syncAddressee-") ) 2681 if ( uid.left(19) == QString("last-syncAddressee-") )
2682 skipIncidence = true; 2682 skipIncidence = true;
2683 if ( !skipIncidence ) { 2683 if ( !skipIncidence ) {
2684 inL = local->findByUid( uid ); 2684 inL = local->findByUid( uid );
2685 inR = remote->findByUid( uid ); 2685 inR = remote->findByUid( uid );
2686 if ( inR.isEmpty() ) { 2686 if ( inR.isEmpty() ) {
2687 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2687 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2688 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2688 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2689 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2689 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2690 local->removeAddressee( inL ); 2690 local->removeAddressee( inL );
2691 ++deletedAddresseeL; 2691 ++deletedAddresseeL;
2692 } else { 2692 } else {
2693 if ( ! syncManager->mWriteBackExistingOnly ) { 2693 if ( ! syncManager->mWriteBackExistingOnly ) {
2694 inL.removeID(mCurrentSyncDevice ); 2694 inL.removeID(mCurrentSyncDevice );
2695 ++addedAddresseeR; 2695 ++addedAddresseeR;
2696 inL.setRevision( modifiedCalendar ); 2696 inL.setRevision( modifiedCalendar );
2697 local->insertAddressee( inL, false ); 2697 local->insertAddressee( inL, false );
2698 inR = inL; 2698 inR = inL;
2699 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2699 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2700 inR.setResource( 0 ); 2700 inR.setResource( 0 );
2701 remote->insertAddressee( inR, false ); 2701 remote->insertAddressee( inR, false );
2702 } 2702 }
2703 } 2703 }
2704 } else { 2704 } else {
2705 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2705 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2706 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2706 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2707 local->removeAddressee( inL ); 2707 local->removeAddressee( inL );
2708 ++deletedAddresseeL; 2708 ++deletedAddresseeL;
2709 } else { 2709 } else {
2710 if ( ! syncManager->mWriteBackExistingOnly ) { 2710 if ( ! syncManager->mWriteBackExistingOnly ) {
2711 ++addedAddresseeR; 2711 ++addedAddresseeR;
2712 inL.setRevision( modifiedCalendar ); 2712 inL.setRevision( modifiedCalendar );
2713 local->insertAddressee( inL, false ); 2713 local->insertAddressee( inL, false );
2714 inR = inL; 2714 inR = inL;
2715 inR.setResource( 0 ); 2715 inR.setResource( 0 );
2716 remote->insertAddressee( inR, false ); 2716 remote->insertAddressee( inR, false );
2717 } 2717 }
2718 } 2718 }
2719 } 2719 }
2720 } 2720 }
2721 } 2721 }
2722 ++incCounter; 2722 ++incCounter;
2723 } 2723 }
2724 el.clear(); 2724 el.clear();
2725 syncManager->hideProgressBar(); 2725 syncManager->hideProgressBar();
2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2727 // get rid of micro seconds 2727 // get rid of micro seconds
2728 QTime t = mLastAddressbookSync.time(); 2728 QTime t = mLastAddressbookSync.time();
2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2730 addresseeLSync.setRevision( mLastAddressbookSync ); 2730 addresseeLSync.setRevision( mLastAddressbookSync );
2731 addresseeRSync.setRevision( mLastAddressbookSync ); 2731 addresseeRSync.setRevision( mLastAddressbookSync );
2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2738 addresseeRSync.setNote( "" ) ; 2738 addresseeRSync.setNote( "" ) ;
2739 addresseeLSync.setNote( "" ); 2739 addresseeLSync.setNote( "" );
2740 2740
2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2742 remote->insertAddressee( addresseeRSync, false ); 2742 remote->insertAddressee( addresseeRSync, false );
2743 local->insertAddressee( addresseeLSync, false ); 2743 local->insertAddressee( addresseeLSync, false );
2744 QString mes; 2744 QString mes;
2745 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 ); 2745 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 );
2746 if ( syncManager->mShowSyncSummary ) { 2746 if ( syncManager->mShowSyncSummary ) {
2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2748 } 2748 }
2749 qDebug( mes ); 2749 qDebug( mes );
2750 return syncOK; 2750 return syncOK;
2751} 2751}
2752 2752
2753 2753
2754//this is a overwritten callbackmethods from the syncinterface 2754//this is a overwritten callbackmethods from the syncinterface
2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2756{ 2756{
2757 2757
2758 //pending prepare addresseeview for output 2758 //pending prepare addresseeview for output
2759 //pending detect, if remote file has REV field. if not switch to external sync 2759 //pending detect, if remote file has REV field. if not switch to external sync
2760 mGlobalSyncMode = SYNC_MODE_NORMAL; 2760 mGlobalSyncMode = SYNC_MODE_NORMAL;
2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2762 2762
2763 AddressBook abLocal(filename,"syncContact"); 2763 AddressBook abLocal(filename,"syncContact");
2764 bool syncOK = false; 2764 bool syncOK = false;
2765 if ( abLocal.load() ) { 2765 if ( abLocal.load() ) {
2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2767 bool external = false; 2767 bool external = false;
2768 bool isXML = false; 2768 bool isXML = false;
2769 if ( filename.right(4) == ".xml") { 2769 if ( filename.right(4) == ".xml") {
2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2771 isXML = true; 2771 isXML = true;
2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2773 } else { 2773 } else {
2774 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2774 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2775 if ( ! lse.isEmpty() ) { 2775 if ( ! lse.isEmpty() ) {
2776 if ( lse.familyName().left(4) == "!E: " ) 2776 if ( lse.familyName().left(4) == "!E: " )
2777 external = true; 2777 external = true;
2778 } else { 2778 } else {
2779 bool found = false; 2779 bool found = false;
2780 AddressBook::Iterator it; 2780 AddressBook::Iterator it;
2781 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2781 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2782 if ( (*it).revision().date().year() > 2003 ) { 2782 if ( (*it).revision().date().year() > 2003 ) {
2783 found = true; 2783 found = true;
2784 break; 2784 break;
2785 } 2785 }
2786 } 2786 }
2787 external = ! found; 2787 external = ! found;
2788 } 2788 }
2789 2789
2790 if ( external ) { 2790 if ( external ) {
2791 qDebug("Setting vcf mode to external "); 2791 qDebug("Setting vcf mode to external ");
2792 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2792 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2793 AddressBook::Iterator it; 2793 AddressBook::Iterator it;
2794 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2794 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2795 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2795 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2796 (*it).computeCsum( mCurrentSyncDevice ); 2796 (*it).computeCsum( mCurrentSyncDevice );
2797 } 2797 }
2798 } 2798 }
2799 } 2799 }
2800 //AddressBook::Iterator it; 2800 //AddressBook::Iterator it;
2801 //QStringList vcards; 2801 //QStringList vcards;
2802 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2802 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2803 // qDebug("Name %s ", (*it).familyName().latin1()); 2803 // qDebug("Name %s ", (*it).familyName().latin1());
2804 //} 2804 //}
2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2806 if ( syncOK ) { 2806 if ( syncOK ) {
2807 if ( syncManager->mWriteBackFile ) 2807 if ( syncManager->mWriteBackFile )
2808 { 2808 {
2809 if ( external ) 2809 if ( external )
2810 abLocal.removeSyncAddressees( !isXML); 2810 abLocal.removeSyncAddressees( !isXML);
2811 qDebug("Saving remote AB "); 2811 qDebug("Saving remote AB ");
2812 if ( ! abLocal.saveAB()) 2812 if ( ! abLocal.saveAB())
2813 qDebug("Error writing back AB to file "); 2813 qDebug("Error writing back AB to file ");
2814 if ( isXML ) { 2814 if ( isXML ) {
2815 // afterwrite processing 2815 // afterwrite processing
2816 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2816 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2817 } 2817 }
2818 } 2818 }
2819 } 2819 }
2820 setModified(); 2820 setModified();
2821 2821
2822 } 2822 }
2823 if ( syncOK ) 2823 if ( syncOK )
2824 mViewManager->refreshView(); 2824 mViewManager->refreshView();
2825 return syncOK; 2825 return syncOK;
2826#if 0
2827 2826
2828 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2829 getEventViewerDialog()->setSyncMode( true );
2830 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2831 getEventViewerDialog()->setSyncMode( false );
2832 if ( syncOK ) {
2833 if ( KOPrefs::instance()->mWriteBackFile )
2834 {
2835 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2836 storage->save();
2837 }
2838 }
2839 setModified();
2840 }
2841
2842#endif
2843} 2827}
2844 2828
2845 2829
2846//this is a overwritten callbackmethods from the syncinterface 2830//this is a overwritten callbackmethods from the syncinterface
2847bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2831bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2848{ 2832{
2833 if ( resource == "phone" )
2834 return syncPhone();
2849 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2835 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2850 2836
2851 AddressBook abLocal( resource,"syncContact"); 2837 AddressBook abLocal( resource,"syncContact");
2852 bool syncOK = false; 2838 bool syncOK = false;
2853 if ( abLocal.load() ) { 2839 if ( abLocal.load() ) {
2854 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2840 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2855 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2841 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2856 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2842 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2857 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2843 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2858 if ( syncOK ) { 2844 if ( syncOK ) {
2859 if ( syncManager->mWriteBackFile ) { 2845 if ( syncManager->mWriteBackFile ) {
2860 abLocal.saveAB(); 2846 abLocal.saveAB();
2861 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2847 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2862 } 2848 }
2863 } 2849 }
2864 setModified(); 2850 setModified();
2865 } 2851 }
2866 if ( syncOK ) 2852 if ( syncOK )
2867 mViewManager->refreshView(); 2853 mViewManager->refreshView();
2868 return syncOK; 2854 return syncOK;
2869 2855
2870} 2856}
2871 2857void KABCore::message( QString m )
2872void KABCore::getFile( bool success )
2873{ 2858{
2859
2860 topLevelWidget()->setCaption( m );
2874 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); 2861 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
2862}
2863bool KABCore::syncPhone()
2864{
2865 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2866 QString fileName;
2867#ifdef _WIN32_
2868 fileName = locateLocal("tmp", "phonefile.vcf");
2869#else
2870 fileName = "/tmp/phonefile.vcf";
2871#endif
2872 if ( !PhoneAccess::readFromPhone( fileName) ) {
2873 message(i18n("Phone access failed!"));
2874 return false;
2875 }
2876 AddressBook abLocal( fileName,"syncContact");
2877 bool syncOK = false;
2878 if ( abLocal.load() ) {
2879 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2880 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2881 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2882 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2883 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2884 if ( syncOK ) {
2885 if ( syncManager->mWriteBackFile ) {
2886 abLocal.saveABphone( fileName );
2887 abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2889 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2890 }
2891 }
2892 setModified();
2893 }
2894 if ( syncOK )
2895 mViewManager->refreshView();
2896 return syncOK;
2897}
2898void KABCore::getFile( bool success )
2899{
2875 if ( ! success ) { 2900 if ( ! success ) {
2876 setCaption( i18n("Error receiving file. Nothing changed!") ); 2901 message( i18n("Error receiving file. Nothing changed!") );
2877 return; 2902 return;
2878 } 2903 }
2879 mAddressBook->importFromFile( sentSyncFile() , false, true ); 2904 mAddressBook->importFromFile( sentSyncFile() , false, true );
2880 topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 2905 message( i18n("Pi-Sync successful!") );
2881 mViewManager->refreshView(); 2906 mViewManager->refreshView();
2882} 2907}
2883void KABCore::syncFileRequest() 2908void KABCore::syncFileRequest()
2884{ 2909{
2885 mAddressBook->export2File( sentSyncFile() ); 2910 mAddressBook->export2File( sentSyncFile() );
2886} 2911}
2887QString KABCore::sentSyncFile() 2912QString KABCore::sentSyncFile()
2888{ 2913{
2889#ifdef _WIN32_ 2914#ifdef _WIN32_
2890 return locateLocal( "tmp", "copysyncab.vcf" ); 2915 return locateLocal( "tmp", "copysyncab.vcf" );
2891#else 2916#else
2892 return QString( "/tmp/copysyncab.vcf" ); 2917 return QString( "/tmp/copysyncab.vcf" );
2893#endif 2918#endif
2894} 2919}
2895 2920
2896void KABCore::setCaptionBack() 2921void KABCore::setCaptionBack()
2897{ 2922{
2898 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2923 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2899} 2924}
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index 43c5f99..04ce33d 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -1,483 +1,484 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef KABCORE_H 24#ifndef KABCORE_H
25#define KABCORE_H 25#define KABCORE_H
26 26
27#include <kabc/field.h> 27#include <kabc/field.h>
28 28
29#ifndef KAB_EMBEDDED 29#ifndef KAB_EMBEDDED
30#endif //KAB_EMBEDDED 30#endif //KAB_EMBEDDED
31#include <qdict.h> 31#include <qdict.h>
32 32
33#include <qwidget.h> 33#include <qwidget.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <ksyncmanager.h> 35#include <ksyncmanager.h>
36 36
37namespace KABC { 37namespace KABC {
38class AddressBook; 38class AddressBook;
39} 39}
40 40
41#ifndef KAB_EMBEDDED 41#ifndef KAB_EMBEDDED
42class KAboutData; 42class KAboutData;
43class KConfig; 43class KConfig;
44 44
45class KAddressBookService; 45class KAddressBookService;
46class LDAPSearchDialog; 46class LDAPSearchDialog;
47#else //KAB_EMBEDDED 47#else //KAB_EMBEDDED
48class KAddressBookMain; 48class KAddressBookMain;
49//US class QAction; 49//US class QAction;
50#endif //KAB_EMBEDDED 50#endif //KAB_EMBEDDED
51class KCMultiDialog; 51class KCMultiDialog;
52class KXMLGUIClient; 52class KXMLGUIClient;
53class ExtensionManager; 53class ExtensionManager;
54class XXPortManager; 54class XXPortManager;
55class JumpButtonBar; 55class JumpButtonBar;
56class IncSearchWidget; 56class IncSearchWidget;
57class KDGanttMinimizeSplitter; 57class KDGanttMinimizeSplitter;
58class KAction; 58class KAction;
59class KActionCollection; 59class KActionCollection;
60class KToggleAction; 60class KToggleAction;
61class KSyncProfile; 61class KSyncProfile;
62 62
63class QAction; 63class QAction;
64class QMenuBar; 64class QMenuBar;
65class QSplitter; 65class QSplitter;
66class ViewContainer; 66class ViewContainer;
67class ViewManager; 67class ViewManager;
68class AddresseeEditorDialog; 68class AddresseeEditorDialog;
69class Ir; 69class Ir;
70 70
71class KABCore : public QWidget, public KSyncInterface 71class KABCore : public QWidget, public KSyncInterface
72{ 72{
73 Q_OBJECT 73 Q_OBJECT
74 74
75 public: 75 public:
76 KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 ); 76 KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 );
77 77
78 78
79 ~KABCore(); 79 ~KABCore();
80 80
81 81
82#ifdef KAB_EMBEDDED 82#ifdef KAB_EMBEDDED
83 //US added functionality 83 //US added functionality
84 QPopupMenu* getViewMenu() {return viewMenu;} 84 QPopupMenu* getViewMenu() {return viewMenu;}
85 QPopupMenu* getFilterMenu() {return filterMenu;} 85 QPopupMenu* getFilterMenu() {return filterMenu;}
86 QPopupMenu* getSettingsMenu() {return settingsMenu;} 86 QPopupMenu* getSettingsMenu() {return settingsMenu;}
87 void addActionsManually(); 87 void addActionsManually();
88#endif //KAB_EMBEDDED 88#endif //KAB_EMBEDDED
89 /** 89 /**
90 Restores the global settings. 90 Restores the global settings.
91 */ 91 */
92 void restoreSettings(); 92 void restoreSettings();
93 93
94 /** 94 /**
95 Saves the global settings. 95 Saves the global settings.
96 */ 96 */
97 void saveSettings(); 97 void saveSettings();
98 98
99 /** 99 /**
100 Returns a pointer to the StdAddressBook of the application. 100 Returns a pointer to the StdAddressBook of the application.
101 */ 101 */
102 KABC::AddressBook *addressBook() const; 102 KABC::AddressBook *addressBook() const;
103 103
104 /** 104 /**
105 Returns a pointer to the KConfig object of the application. 105 Returns a pointer to the KConfig object of the application.
106 */ 106 */
107 static KConfig *config(); 107 static KConfig *config();
108 108
109 /** 109 /**
110 Returns a pointer to the global KActionCollection object. So 110 Returns a pointer to the global KActionCollection object. So
111 other classes can register their actions easily. 111 other classes can register their actions easily.
112 */ 112 */
113 KActionCollection *actionCollection() const; 113 KActionCollection *actionCollection() const;
114 114
115 /** 115 /**
116 Returns the current search field of the Incremental Search Widget. 116 Returns the current search field of the Incremental Search Widget.
117 */ 117 */
118 KABC::Field *currentSearchField() const; 118 KABC::Field *currentSearchField() const;
119 119
120 /** 120 /**
121 Returns the uid list of the currently selected contacts. 121 Returns the uid list of the currently selected contacts.
122 */ 122 */
123 QStringList selectedUIDs() const; 123 QStringList selectedUIDs() const;
124 124
125 /** 125 /**
126 Displays the ResourceSelectDialog and returns the selected 126 Displays the ResourceSelectDialog and returns the selected
127 resource or a null pointer if no resource was selected by 127 resource or a null pointer if no resource was selected by
128 the user. 128 the user.
129 */ 129 */
130 KABC::Resource *requestResource( QWidget *parent ); 130 KABC::Resource *requestResource( QWidget *parent );
131 131
132#ifndef KAB_EMBEDDED 132#ifndef KAB_EMBEDDED
133 static KAboutData *createAboutData(); 133 static KAboutData *createAboutData();
134#endif //KAB_EMBEDDED 134#endif //KAB_EMBEDDED
135 135
136#ifdef KAB_EMBEDDED 136#ifdef KAB_EMBEDDED
137 inline QPopupMenu* getImportMenu() { return ImportMenu;} 137 inline QPopupMenu* getImportMenu() { return ImportMenu;}
138 inline QPopupMenu* getExportMenu() { return ExportMenu;} 138 inline QPopupMenu* getExportMenu() { return ExportMenu;}
139#endif //KAB_EMBEDDED 139#endif //KAB_EMBEDDED
140 140
141 public slots: 141 public slots:
142#ifdef KAB_EMBEDDED 142#ifdef KAB_EMBEDDED
143 void createAboutData(); 143 void createAboutData();
144#endif //KAB_EMBEDDED 144#endif //KAB_EMBEDDED
145 145
146 void statusMessage(QString, int time = 0 ); 146 void statusMessage(QString, int time = 0 );
147 void showLicence(); 147 void showLicence();
148 void faq(); 148 void faq();
149 149
150 /** 150 /**
151 Is called whenever a contact is selected in the view. 151 Is called whenever a contact is selected in the view.
152 */ 152 */
153 void setContactSelected( const QString &uid ); 153 void setContactSelected( const QString &uid );
154 154
155 /** 155 /**
156 Opens the preferred mail composer with all selected contacts as 156 Opens the preferred mail composer with all selected contacts as
157 arguments. 157 arguments.
158 */ 158 */
159 void sendMail(); 159 void sendMail();
160 160
161 /** 161 /**
162 Opens the preferred mail composer with the given contacts as 162 Opens the preferred mail composer with the given contacts as
163 arguments. 163 arguments.
164 */ 164 */
165 void sendMail( const QString& email ); 165 void sendMail( const QString& email );
166 166
167 167
168 void mailVCard(); 168 void mailVCard();
169 void mailVCard(const QStringList& uids); 169 void mailVCard(const QStringList& uids);
170 170
171 /** 171 /**
172 Beams the "WhoAmI contact. 172 Beams the "WhoAmI contact.
173 */ 173 */
174 void beamMySelf(); 174 void beamMySelf();
175 175
176 void beamVCard(); 176 void beamVCard();
177 void export2phone(); 177 void export2phone();
178 void beamVCard(const QStringList& uids); 178 void beamVCard(const QStringList& uids);
179 void beamDone( Ir *ir ); 179 void beamDone( Ir *ir );
180 180
181 181
182 /** 182 /**
183 Starts the preferred web browser with the given URL as argument. 183 Starts the preferred web browser with the given URL as argument.
184 */ 184 */
185 void browse( const QString& url ); 185 void browse( const QString& url );
186 186
187 /** 187 /**
188 Select all contacts in the view. 188 Select all contacts in the view.
189 */ 189 */
190 void selectAllContacts(); 190 void selectAllContacts();
191 191
192 /** 192 /**
193 Deletes all selected contacts from the address book. 193 Deletes all selected contacts from the address book.
194 */ 194 */
195 void deleteContacts(); 195 void deleteContacts();
196 196
197 /** 197 /**
198 Deletes given contacts from the address book. 198 Deletes given contacts from the address book.
199 199
200 @param uids The uids of the contacts, which shall be deleted. 200 @param uids The uids of the contacts, which shall be deleted.
201 */ 201 */
202 void deleteContacts( const QStringList &uids ); 202 void deleteContacts( const QStringList &uids );
203 203
204 /** 204 /**
205 Copys the selected contacts into clipboard for later pasting. 205 Copys the selected contacts into clipboard for later pasting.
206 */ 206 */
207 void copyContacts(); 207 void copyContacts();
208 208
209 /** 209 /**
210 Cuts the selected contacts and stores them for later pasting. 210 Cuts the selected contacts and stores them for later pasting.
211 */ 211 */
212 void cutContacts(); 212 void cutContacts();
213 213
214 /** 214 /**
215 Paste contacts from clipboard into the address book. 215 Paste contacts from clipboard into the address book.
216 */ 216 */
217 void pasteContacts(); 217 void pasteContacts();
218 218
219 /** 219 /**
220 Paste given contacts into the address book. 220 Paste given contacts into the address book.
221 221
222 @param list The list of addressee, which shall be pasted. 222 @param list The list of addressee, which shall be pasted.
223 */ 223 */
224 void pasteContacts( KABC::Addressee::List &list ); 224 void pasteContacts( KABC::Addressee::List &list );
225 225
226 /** 226 /**
227 Sets the whoAmI contact, that is used by many other programs to 227 Sets the whoAmI contact, that is used by many other programs to
228 get personal information about the current user. 228 get personal information about the current user.
229 */ 229 */
230 void setWhoAmI(); 230 void setWhoAmI();
231 231
232 /** 232 /**
233 Displays the category dialog and applies the result to all 233 Displays the category dialog and applies the result to all
234 selected contacts. 234 selected contacts.
235 */ 235 */
236 void setCategories(); 236 void setCategories();
237 237
238 /** 238 /**
239 Sets the field list of the Incremental Search Widget. 239 Sets the field list of the Incremental Search Widget.
240 */ 240 */
241 void setSearchFields( const KABC::Field::List &fields ); 241 void setSearchFields( const KABC::Field::List &fields );
242 242
243 /** 243 /**
244 Search with the current search field for a contact, that matches 244 Search with the current search field for a contact, that matches
245 the given text, and selects it in the view. 245 the given text, and selects it in the view.
246 */ 246 */
247 void incrementalSearch( const QString& text ); 247 void incrementalSearch( const QString& text );
248 248
249 /** 249 /**
250 Marks the address book as modified. 250 Marks the address book as modified.
251 */ 251 */
252 void setModified(); 252 void setModified();
253 /** 253 /**
254 Marks the address book as modified without refreshing the view. 254 Marks the address book as modified without refreshing the view.
255 */ 255 */
256 void setModifiedWOrefresh(); 256 void setModifiedWOrefresh();
257 257
258 /** 258 /**
259 Marks the address book as modified concerning the argument. 259 Marks the address book as modified concerning the argument.
260 */ 260 */
261 void setModified( bool modified ); 261 void setModified( bool modified );
262 262
263 /** 263 /**
264 Returns whether the address book is modified. 264 Returns whether the address book is modified.
265 */ 265 */
266 bool modified() const; 266 bool modified() const;
267 267
268 /** 268 /**
269 Called whenever an contact is modified in the contact editor 269 Called whenever an contact is modified in the contact editor
270 dialog or the quick edit. 270 dialog or the quick edit.
271 */ 271 */
272 void contactModified( const KABC::Addressee &addr ); 272 void contactModified( const KABC::Addressee &addr );
273 273
274 /** 274 /**
275 DCOP METHODS. 275 DCOP METHODS.
276 */ 276 */
277 void addEmail( QString addr ); 277 void addEmail( QString addr );
278 void importVCard( const KURL& url, bool showPreview ); 278 void importVCard( const KURL& url, bool showPreview );
279 void importVCard( const QString& vCard, bool showPreview ); 279 void importVCard( const QString& vCard, bool showPreview );
280 void newContact(); 280 void newContact();
281 QString getNameByPhone( const QString& phone ); 281 QString getNameByPhone( const QString& phone );
282 /** 282 /**
283 END DCOP METHODS 283 END DCOP METHODS
284 */ 284 */
285 285
286 /** 286 /**
287 Saves the contents of the AddressBook back to disk. 287 Saves the contents of the AddressBook back to disk.
288 */ 288 */
289 void save(); 289 void save();
290 290
291 /** 291 /**
292 Undos the last command using the undo stack. 292 Undos the last command using the undo stack.
293 */ 293 */
294 void undo(); 294 void undo();
295 295
296 /** 296 /**
297 Redos the last command that was undone, using the redo stack. 297 Redos the last command that was undone, using the redo stack.
298 */ 298 */
299 void redo(); 299 void redo();
300 300
301 /** 301 /**
302 Shows the edit dialog for the given uid. If the uid is QString::null, 302 Shows the edit dialog for the given uid. If the uid is QString::null,
303 the method will try to find a selected addressee in the view. 303 the method will try to find a selected addressee in the view.
304 */ 304 */
305 void editContact( const QString &uid /*US = QString::null*/ ); 305 void editContact( const QString &uid /*US = QString::null*/ );
306//US added a second method without defaultparameter 306//US added a second method without defaultparameter
307 void editContact2(); 307 void editContact2();
308 308
309 /** 309 /**
310 Shows or edits the detail view for the given uid. If the uid is QString::null, 310 Shows or edits the detail view for the given uid. If the uid is QString::null,
311 the method will try to find a selected addressee in the view. 311 the method will try to find a selected addressee in the view.
312 */ 312 */
313 void executeContact( const QString &uid /*US = QString::null*/ ); 313 void executeContact( const QString &uid /*US = QString::null*/ );
314 314
315 /** 315 /**
316 Launches the configuration dialog. 316 Launches the configuration dialog.
317 */ 317 */
318 void openConfigDialog(); 318 void openConfigDialog();
319 319
320 /** 320 /**
321 Launches the ldap search dialog. 321 Launches the ldap search dialog.
322 */ 322 */
323 void openLDAPDialog(); 323 void openLDAPDialog();
324 324
325 /** 325 /**
326 Creates a KAddressBookPrinter, which will display the print 326 Creates a KAddressBookPrinter, which will display the print
327 dialog and do the printing. 327 dialog and do the printing.
328 */ 328 */
329 void print(); 329 void print();
330 330
331 /** 331 /**
332 Registers a new GUI client, so plugins can register its actions. 332 Registers a new GUI client, so plugins can register its actions.
333 */ 333 */
334 void addGUIClient( KXMLGUIClient *client ); 334 void addGUIClient( KXMLGUIClient *client );
335 335
336 void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); 336 void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid);
337 void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); 337 void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid);
338 void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid); 338 void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid);
339 339
340 340
341 signals: 341 signals:
342 void contactSelected( const QString &name ); 342 void contactSelected( const QString &name );
343 void contactSelected( const QPixmap &pixmap ); 343 void contactSelected( const QPixmap &pixmap );
344 public slots: 344 public slots:
345 void recieve(QString cmsg ); 345 void recieve(QString cmsg );
346 void getFile( bool success ); 346 void getFile( bool success );
347 void syncFileRequest(); 347 void syncFileRequest();
348 void setDetailsVisible( bool visible ); 348 void setDetailsVisible( bool visible );
349 void setDetailsToState(); 349 void setDetailsToState();
350 // void slotSyncMenu( int ); 350 // void slotSyncMenu( int );
351 private slots: 351 private slots:
352 void setJumpButtonBarVisible( bool visible ); 352 void setJumpButtonBarVisible( bool visible );
353 void setCaptionBack(); 353 void setCaptionBack();
354 void importFromOL(); 354 void importFromOL();
355 void extensionModified( const KABC::Addressee::List &list ); 355 void extensionModified( const KABC::Addressee::List &list );
356 void extensionChanged( int id ); 356 void extensionChanged( int id );
357 void clipboardDataChanged(); 357 void clipboardDataChanged();
358 void updateActionMenu(); 358 void updateActionMenu();
359 void configureKeyBindings(); 359 void configureKeyBindings();
360 void removeVoice(); 360 void removeVoice();
361#ifdef KAB_EMBEDDED 361#ifdef KAB_EMBEDDED
362 void configureResources(); 362 void configureResources();
363#endif //KAB_EMBEDDED 363#endif //KAB_EMBEDDED
364 364
365 void slotEditorDestroyed( const QString &uid ); 365 void slotEditorDestroyed( const QString &uid );
366 void configurationChanged(); 366 void configurationChanged();
367 void addressBookChanged(); 367 void addressBookChanged();
368 368
369 private: 369 private:
370 void initGUI(); 370 void initGUI();
371 void initActions(); 371 void initActions();
372 372
373 AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, 373 AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent,
374 const char *name = 0 ); 374 const char *name = 0 );
375 375
376 KXMLGUIClient *mGUIClient; 376 KXMLGUIClient *mGUIClient;
377 377
378 KABC::AddressBook *mAddressBook; 378 KABC::AddressBook *mAddressBook;
379 379
380 ViewManager *mViewManager; 380 ViewManager *mViewManager;
381 // QSplitter *mDetailsSplitter; 381 // QSplitter *mDetailsSplitter;
382 KDGanttMinimizeSplitter *mExtensionBarSplitter; 382 KDGanttMinimizeSplitter *mExtensionBarSplitter;
383 ViewContainer *mDetails; 383 ViewContainer *mDetails;
384 KDGanttMinimizeSplitter* mMiniSplitter; 384 KDGanttMinimizeSplitter* mMiniSplitter;
385 XXPortManager *mXXPortManager; 385 XXPortManager *mXXPortManager;
386 JumpButtonBar *mJumpButtonBar; 386 JumpButtonBar *mJumpButtonBar;
387 IncSearchWidget *mIncSearchWidget; 387 IncSearchWidget *mIncSearchWidget;
388 ExtensionManager *mExtensionManager; 388 ExtensionManager *mExtensionManager;
389 389
390 KCMultiDialog *mConfigureDialog; 390 KCMultiDialog *mConfigureDialog;
391 391
392#ifndef KAB_EMBEDDED 392#ifndef KAB_EMBEDDED
393 LDAPSearchDialog *mLdapSearchDialog; 393 LDAPSearchDialog *mLdapSearchDialog;
394#endif //KAB_EMBEDDED 394#endif //KAB_EMBEDDED
395 // QDict<AddresseeEditorDialog> mEditorDict; 395 // QDict<AddresseeEditorDialog> mEditorDict;
396 AddresseeEditorDialog *mEditorDialog; 396 AddresseeEditorDialog *mEditorDialog;
397 bool mReadWrite; 397 bool mReadWrite;
398 bool mModified; 398 bool mModified;
399 bool mIsPart; 399 bool mIsPart;
400 bool mMultipleViewsAtOnce; 400 bool mMultipleViewsAtOnce;
401 401
402 402
403 //US file menu 403 //US file menu
404 KAction *mActionMail; 404 KAction *mActionMail;
405 KAction *mActionBeam; 405 KAction *mActionBeam;
406 KAction *mActionExport2phone; 406 KAction *mActionExport2phone;
407 KAction* mActionPrint; 407 KAction* mActionPrint;
408 KAction* mActionNewContact; 408 KAction* mActionNewContact;
409 KAction *mActionSave; 409 KAction *mActionSave;
410 KAction *mActionEditAddressee; 410 KAction *mActionEditAddressee;
411 KAction *mActionMailVCard; 411 KAction *mActionMailVCard;
412 KAction *mActionBeamVCard; 412 KAction *mActionBeamVCard;
413 413
414 KAction *mActionQuit; 414 KAction *mActionQuit;
415 415
416 //US edit menu 416 //US edit menu
417 KAction *mActionCopy; 417 KAction *mActionCopy;
418 KAction *mActionCut; 418 KAction *mActionCut;
419 KAction *mActionPaste; 419 KAction *mActionPaste;
420 KAction *mActionSelectAll; 420 KAction *mActionSelectAll;
421 KAction *mActionUndo; 421 KAction *mActionUndo;
422 KAction *mActionRedo; 422 KAction *mActionRedo;
423 KAction *mActionDelete; 423 KAction *mActionDelete;
424 424
425 //US settings menu 425 //US settings menu
426 KAction *mActionConfigResources; 426 KAction *mActionConfigResources;
427 KAction *mActionConfigKAddressbook; 427 KAction *mActionConfigKAddressbook;
428 KAction *mActionConfigShortcuts; 428 KAction *mActionConfigShortcuts;
429 KAction *mActionConfigureToolbars; 429 KAction *mActionConfigureToolbars;
430 KAction *mActionKeyBindings; 430 KAction *mActionKeyBindings;
431 KToggleAction *mActionJumpBar; 431 KToggleAction *mActionJumpBar;
432 KToggleAction *mActionDetails; 432 KToggleAction *mActionDetails;
433 KAction *mActionWhoAmI; 433 KAction *mActionWhoAmI;
434 KAction *mActionCategories; 434 KAction *mActionCategories;
435 KAction *mActionAboutKAddressbook; 435 KAction *mActionAboutKAddressbook;
436 KAction *mActionLicence; 436 KAction *mActionLicence;
437 KAction *mActionFaq; 437 KAction *mActionFaq;
438 438
439 KAction *mActionDeleteView; 439 KAction *mActionDeleteView;
440 440
441 QPopupMenu *viewMenu; 441 QPopupMenu *viewMenu;
442 QPopupMenu *filterMenu; 442 QPopupMenu *filterMenu;
443 QPopupMenu *settingsMenu; 443 QPopupMenu *settingsMenu;
444 QPopupMenu *changeMenu; 444 QPopupMenu *changeMenu;
445//US QAction *mActionSave; 445//US QAction *mActionSave;
446 QPopupMenu *ImportMenu; 446 QPopupMenu *ImportMenu;
447 QPopupMenu *ExportMenu; 447 QPopupMenu *ExportMenu;
448 //LR additional methods 448 //LR additional methods
449 KAction *mActionRemoveVoice; 449 KAction *mActionRemoveVoice;
450 KAction * mActionImportOL; 450 KAction * mActionImportOL;
451 451
452#ifndef KAB_EMBEDDED 452#ifndef KAB_EMBEDDED
453 KAddressBookService *mAddressBookService; 453 KAddressBookService *mAddressBookService;
454#endif //KAB_EMBEDDED 454#endif //KAB_EMBEDDED
455 455
456 class KABCorePrivate; 456 class KABCorePrivate;
457 KABCorePrivate *d; 457 KABCorePrivate *d;
458 //US bool mBlockSaveFlag; 458 //US bool mBlockSaveFlag;
459 459
460#ifdef KAB_EMBEDDED 460#ifdef KAB_EMBEDDED
461 KAddressBookMain *mMainWindow; // should be the same like mGUIClient 461 KAddressBookMain *mMainWindow; // should be the same like mGUIClient
462#endif //KAB_EMBEDDED 462#endif //KAB_EMBEDDED
463 463
464 //this are the overwritten callbackmethods from the syncinterface 464 //this are the overwritten callbackmethods from the syncinterface
465 virtual bool sync(KSyncManager* manager, QString filename, int mode); 465 virtual bool sync(KSyncManager* manager, QString filename, int mode);
466 virtual bool syncExternal(KSyncManager* manager, QString resource); 466 virtual bool syncExternal(KSyncManager* manager, QString resource);
467 467 bool syncPhone();
468 void message( QString m );
468 469
469 // LR ******************************* 470 // LR *******************************
470 // sync stuff! 471 // sync stuff!
471 QString sentSyncFile(); 472 QString sentSyncFile();
472 QPopupMenu *syncMenu; 473 QPopupMenu *syncMenu;
473 KSyncManager* syncManager; 474 KSyncManager* syncManager;
474 int mGlobalSyncMode; 475 int mGlobalSyncMode;
475 bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); 476 bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode);
476 KABC::Addressee getLastSyncAddressee(); 477 KABC::Addressee getLastSyncAddressee();
477 QDateTime mLastAddressbookSync; 478 QDateTime mLastAddressbookSync;
478 int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); 479 int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full );
479 // ********************* 480 // *********************
480 481
481}; 482};
482 483
483#endif 484#endif
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index c39413e..3555dc6 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,637 +1,633 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> 4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38#include <kmessagebox.h> 38#include <kmessagebox.h>
39#include <phoneaccess.h> 39#include <phoneaccess.h>
40 40
41#include "calendar.h" 41#include "calendar.h"
42#include "alarm.h" 42#include "alarm.h"
43#include "recurrence.h" 43#include "recurrence.h"
44#include "calendarlocal.h" 44#include "calendarlocal.h"
45 45
46#include "phoneformat.h" 46#include "phoneformat.h"
47#include "syncdefines.h" 47#include "syncdefines.h"
48 48
49using namespace KCal; 49using namespace KCal;
50class PhoneParser : public QObject 50class PhoneParser : public QObject
51{ 51{
52public: 52public:
53 PhoneParser( ) { 53 PhoneParser( ) {
54 ; 54 ;
55 } 55 }
56 56
57 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 57 static QString dtToString( const QDateTime& dti, bool useTZ = false )
58 { 58 {
59 QString datestr; 59 QString datestr;
60 QString timestr; 60 QString timestr;
61 int offset = KGlobal::locale()->localTimeOffset( dti ); 61 int offset = KGlobal::locale()->localTimeOffset( dti );
62 QDateTime dt; 62 QDateTime dt;
63 if (useTZ) 63 if (useTZ)
64 dt = dti.addSecs ( -(offset*60)); 64 dt = dti.addSecs ( -(offset*60));
65 else 65 else
66 dt = dti; 66 dt = dti;
67 if(dt.date().isValid()){ 67 if(dt.date().isValid()){
68 const QDate& date = dt.date(); 68 const QDate& date = dt.date();
69 datestr.sprintf("%04d%02d%02d", 69 datestr.sprintf("%04d%02d%02d",
70 date.year(), date.month(), date.day()); 70 date.year(), date.month(), date.day());
71 } 71 }
72 if(dt.time().isValid()){ 72 if(dt.time().isValid()){
73 const QTime& time = dt.time(); 73 const QTime& time = dt.time();
74 timestr.sprintf("T%02d%02d%02d", 74 timestr.sprintf("T%02d%02d%02d",
75 time.hour(), time.minute(), time.second()); 75 time.hour(), time.minute(), time.second());
76 } 76 }
77 return datestr + timestr; 77 return datestr + timestr;
78 } 78 }
79 79
80 80
81}; 81};
82 82
83 83
84 84
85PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 85PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
86{ 86{
87 mProfileName = profileName; 87 mProfileName = profileName;
88 PhoneAccess::writeConfig( device, connection, model ); 88 PhoneAccess::writeConfig( device, connection, model );
89} 89}
90 90
91PhoneFormat::~PhoneFormat() 91PhoneFormat::~PhoneFormat()
92{ 92{
93} 93}
94 94
95#if 0 95#if 0
96int PhoneFormat::initDevice(GSM_StateMachine *s) 96int PhoneFormat::initDevice(GSM_StateMachine *s)
97{ 97{
98 GSM_ReadConfig(NULL, &s->Config[0], 0); 98 GSM_ReadConfig(NULL, &s->Config[0], 0);
99 s->ConfigNum = 1; 99 s->ConfigNum = 1;
100 GSM_Config *cfg = &s->Config[0]; 100 GSM_Config *cfg = &s->Config[0];
101 if ( ! mConnection.isEmpty() ) { 101 if ( ! mConnection.isEmpty() ) {
102 cfg->Connection = strdup(mConnection.latin1()); 102 cfg->Connection = strdup(mConnection.latin1());
103 cfg->DefaultConnection = false; 103 cfg->DefaultConnection = false;
104 qDebug("Connection set %s ", cfg->Connection ); 104 qDebug("Connection set %s ", cfg->Connection );
105 105
106 } 106 }
107 if ( ! mDevice.isEmpty() ) { 107 if ( ! mDevice.isEmpty() ) {
108 cfg->Device = strdup(mDevice.latin1()); 108 cfg->Device = strdup(mDevice.latin1());
109 cfg->DefaultDevice = false; 109 cfg->DefaultDevice = false;
110 qDebug("Device set %s ", cfg->Device); 110 qDebug("Device set %s ", cfg->Device);
111 111
112 } 112 }
113 if ( ! mModel.isEmpty() ) { 113 if ( ! mModel.isEmpty() ) {
114 strcpy(cfg->Model,mModel.latin1() ); 114 strcpy(cfg->Model,mModel.latin1() );
115 cfg->DefaultModel = false; 115 cfg->DefaultModel = false;
116 qDebug("Model set %s ",cfg->Model ); 116 qDebug("Model set %s ",cfg->Model );
117 } 117 }
118 int error=GSM_InitConnection(s,3); 118 int error=GSM_InitConnection(s,3);
119 return error; 119 return error;
120} 120}
121#endif 121#endif
122ulong PhoneFormat::getCsumTodo( Todo* todo ) 122ulong PhoneFormat::getCsumTodo( Todo* todo )
123{ 123{
124 QStringList attList; 124 QStringList attList;
125 if ( todo->hasDueDate() ) 125 if ( todo->hasDueDate() )
126 attList << PhoneParser::dtToString ( todo->dtDue() ); 126 attList << PhoneParser::dtToString ( todo->dtDue() );
127 attList << todo->summary(); 127 attList << todo->summary();
128 QString completedString = "no"; 128 QString completedString = "no";
129 if ( todo->isCompleted() ) 129 if ( todo->isCompleted() )
130 completedString = "yes"; 130 completedString = "yes";
131 attList << completedString; 131 attList << completedString;
132 int prio = todo->priority(); 132 int prio = todo->priority();
133 if( prio == 2 ) prio = 1; 133 if( prio == 2 ) prio = 1;
134 if (prio == 4 ) prio = 5 ; 134 if (prio == 4 ) prio = 5 ;
135 attList << QString::number( prio ); 135 attList << QString::number( prio );
136 QString alarmString = "na"; 136 QString alarmString = "na";
137 Alarm *alarm; 137 Alarm *alarm;
138 if ( todo->alarms().count() > 0 ) { 138 if ( todo->alarms().count() > 0 ) {
139 alarm = todo->alarms().first(); 139 alarm = todo->alarms().first();
140 if ( alarm->enabled() ) { 140 if ( alarm->enabled() ) {
141 alarmString = QString::number(alarm->offset() ); 141 alarmString = QString::number(alarm->offset() );
142 } 142 }
143 } 143 }
144 attList << alarmString; 144 attList << alarmString;
145 attList << todo->categoriesStr(); 145 attList << todo->categoriesStr();
146 attList << todo->secrecyStr(); 146 attList << todo->secrecyStr();
147 return PhoneFormat::getCsum(attList ); 147 return PhoneFormat::getCsum(attList );
148 148
149} 149}
150ulong PhoneFormat::getCsumEvent( Event* event ) 150ulong PhoneFormat::getCsumEvent( Event* event )
151{ 151{
152 QStringList attList; 152 QStringList attList;
153 attList << PhoneParser::dtToString ( event->dtStart() ); 153 attList << PhoneParser::dtToString ( event->dtStart() );
154 attList << PhoneParser::dtToString ( event->dtEnd() ); 154 attList << PhoneParser::dtToString ( event->dtEnd() );
155 attList << event->summary(); 155 attList << event->summary();
156 attList << event->location(); 156 attList << event->location();
157 QString alarmString = "na"; 157 QString alarmString = "na";
158 Alarm *alarm; 158 Alarm *alarm;
159 if ( event->alarms().count() > 0 ) { 159 if ( event->alarms().count() > 0 ) {
160 alarm = event->alarms().first(); 160 alarm = event->alarms().first();
161 if ( alarm->enabled() ) { 161 if ( alarm->enabled() ) {
162 alarmString = QString::number( alarm->offset() ); 162 alarmString = QString::number( alarm->offset() );
163 } 163 }
164 } 164 }
165 attList << alarmString; 165 attList << alarmString;
166 Recurrence* rec = event->recurrence(); 166 Recurrence* rec = event->recurrence();
167 QStringList list; 167 QStringList list;
168 bool writeEndDate = false; 168 bool writeEndDate = false;
169 switch ( rec->doesRecur() ) 169 switch ( rec->doesRecur() )
170 { 170 {
171 case Recurrence::rDaily: // 0 171 case Recurrence::rDaily: // 0
172 list.append( "0" ); 172 list.append( "0" );
173 list.append( QString::number( rec->frequency() ));//12 173 list.append( QString::number( rec->frequency() ));//12
174 list.append( "0" ); 174 list.append( "0" );
175 list.append( "0" ); 175 list.append( "0" );
176 writeEndDate = true; 176 writeEndDate = true;
177 break; 177 break;
178 case Recurrence::rWeekly:// 1 178 case Recurrence::rWeekly:// 1
179 list.append( "1" ); 179 list.append( "1" );
180 list.append( QString::number( rec->frequency()) );//12 180 list.append( QString::number( rec->frequency()) );//12
181 list.append( "0" ); 181 list.append( "0" );
182 { 182 {
183 int days = 0; 183 int days = 0;
184 QBitArray weekDays = rec->days(); 184 QBitArray weekDays = rec->days();
185 int i; 185 int i;
186 for( i = 1; i <= 7; ++i ) { 186 for( i = 1; i <= 7; ++i ) {
187 if ( weekDays[i-1] ) { 187 if ( weekDays[i-1] ) {
188 days += 1 << (i-1); 188 days += 1 << (i-1);
189 } 189 }
190 } 190 }
191 list.append( QString::number( days ) ); 191 list.append( QString::number( days ) );
192 } 192 }
193 //pending weekdays 193 //pending weekdays
194 writeEndDate = true; 194 writeEndDate = true;
195 195
196 break; 196 break;
197 case Recurrence::rMonthlyPos:// 2 197 case Recurrence::rMonthlyPos:// 2
198 list.append( "2" ); 198 list.append( "2" );
199 list.append( QString::number( rec->frequency()) );//12 199 list.append( QString::number( rec->frequency()) );//12
200 200
201 writeEndDate = true; 201 writeEndDate = true;
202 { 202 {
203 int count = 1; 203 int count = 1;
204 QPtrList<Recurrence::rMonthPos> rmp; 204 QPtrList<Recurrence::rMonthPos> rmp;
205 rmp = rec->monthPositions(); 205 rmp = rec->monthPositions();
206 if ( rmp.first()->negative ) 206 if ( rmp.first()->negative )
207 count = 5 - rmp.first()->rPos - 1; 207 count = 5 - rmp.first()->rPos - 1;
208 else 208 else
209 count = rmp.first()->rPos - 1; 209 count = rmp.first()->rPos - 1;
210 list.append( QString::number( count ) ); 210 list.append( QString::number( count ) );
211 211
212 } 212 }
213 213
214 list.append( "0" ); 214 list.append( "0" );
215 break; 215 break;
216 case Recurrence::rMonthlyDay:// 3 216 case Recurrence::rMonthlyDay:// 3
217 list.append( "3" ); 217 list.append( "3" );
218 list.append( QString::number( rec->frequency()) );//12 218 list.append( QString::number( rec->frequency()) );//12
219 list.append( "0" ); 219 list.append( "0" );
220 list.append( "0" ); 220 list.append( "0" );
221 writeEndDate = true; 221 writeEndDate = true;
222 break; 222 break;
223 case Recurrence::rYearlyMonth://4 223 case Recurrence::rYearlyMonth://4
224 list.append( "4" ); 224 list.append( "4" );
225 list.append( QString::number( rec->frequency()) );//12 225 list.append( QString::number( rec->frequency()) );//12
226 list.append( "0" ); 226 list.append( "0" );
227 list.append( "0" ); 227 list.append( "0" );
228 writeEndDate = true; 228 writeEndDate = true;
229 break; 229 break;
230 230
231 default: 231 default:
232 list.append( "255" ); 232 list.append( "255" );
233 list.append( QString() ); 233 list.append( QString() );
234 list.append( "0" ); 234 list.append( "0" );
235 list.append( QString() ); 235 list.append( QString() );
236 list.append( "0" ); 236 list.append( "0" );
237 list.append( "20991231T000000" ); 237 list.append( "20991231T000000" );
238 break; 238 break;
239 } 239 }
240 if ( writeEndDate ) { 240 if ( writeEndDate ) {
241 241
242 if ( rec->endDate().isValid() ) { // 15 + 16 242 if ( rec->endDate().isValid() ) { // 15 + 16
243 list.append( "1" ); 243 list.append( "1" );
244 list.append( PhoneParser::dtToString( rec->endDate()) ); 244 list.append( PhoneParser::dtToString( rec->endDate()) );
245 } else { 245 } else {
246 list.append( "0" ); 246 list.append( "0" );
247 list.append( "20991231T000000" ); 247 list.append( "20991231T000000" );
248 } 248 }
249 249
250 } 250 }
251 attList << list.join(""); 251 attList << list.join("");
252 attList << event->categoriesStr(); 252 attList << event->categoriesStr();
253 //qDebug("csum cat %s", event->categoriesStr().latin1()); 253 //qDebug("csum cat %s", event->categoriesStr().latin1());
254 254
255 attList << event->secrecyStr(); 255 attList << event->secrecyStr();
256 return PhoneFormat::getCsum(attList ); 256 return PhoneFormat::getCsum(attList );
257} 257}
258ulong PhoneFormat::getCsum( const QStringList & attList) 258ulong PhoneFormat::getCsum( const QStringList & attList)
259{ 259{
260 int max = attList.count(); 260 int max = attList.count();
261 ulong cSum = 0; 261 ulong cSum = 0;
262 int j,k,i; 262 int j,k,i;
263 int add; 263 int add;
264 for ( i = 0; i < max ; ++i ) { 264 for ( i = 0; i < max ; ++i ) {
265 QString s = attList[i]; 265 QString s = attList[i];
266 if ( ! s.isEmpty() ){ 266 if ( ! s.isEmpty() ){
267 j = s.length(); 267 j = s.length();
268 for ( k = 0; k < j; ++k ) { 268 for ( k = 0; k < j; ++k ) {
269 int mul = k +1; 269 int mul = k +1;
270 add = s[k].unicode (); 270 add = s[k].unicode ();
271 if ( k < 16 ) 271 if ( k < 16 )
272 mul = mul * mul; 272 mul = mul * mul;
273 int ii = i+1; 273 int ii = i+1;
274 add = add * mul *ii*ii*ii; 274 add = add * mul *ii*ii*ii;
275 cSum += add; 275 cSum += add;
276 } 276 }
277 } 277 }
278 278
279 } 279 }
280 //QString dump = attList.join(","); 280 //QString dump = attList.join(",");
281 //qDebug("csum: %d %s", cSum,dump.latin1()); 281 //qDebug("csum: %d %s", cSum,dump.latin1());
282 282
283 return cSum; 283 return cSum;
284 284
285} 285}
286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 286//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
287#include <stdlib.h> 287#include <stdlib.h>
288#define DEBUGMODE false 288#define DEBUGMODE false
289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 289bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
290{ 290{
291 291
292 QString fileName; 292 QString fileName;
293#ifdef _WIN32_ 293#ifdef _WIN32_
294 fileName = locateLocal("tmp", "tempfile.vcs"); 294 fileName = locateLocal("tmp", "phonefile.vcs");
295#else 295#else
296 fileName = "/tmp/kdepimtemp.vcs"; 296 fileName = "/tmp/phonefile.vcs";
297#endif 297#endif
298#ifdef DESKTOP_VERSION 298 QString command;
299 QString command ="./kammu --backup " + fileName + " -yes" ; 299 int ret = PhoneAccess::readFromPhone( fileName );
300#else
301 QString command ="kammu --backup " + fileName + " -yes" ;
302#endif
303 int ret = system ( command.latin1() );
304 if ( ret != 0 ) { 300 if ( ret != 0 ) {
305 qDebug("Error::command returned %d", ret); 301 qDebug("Error::command returned %d", ret);
306 return false; 302 return false;
307 } 303 }
308 VCalFormat vfload; 304 VCalFormat vfload;
309 vfload.setLocalTime ( true ); 305 vfload.setLocalTime ( true );
310 qDebug("loading file ..."); 306 qDebug("loading file ...");
311 307
312 if ( ! vfload.load( calendar, fileName ) ) 308 if ( ! vfload.load( calendar, fileName ) )
313 return false; 309 return false;
314 QPtrList<Event> er = calendar->rawEvents(); 310 QPtrList<Event> er = calendar->rawEvents();
315 Event* ev = er.first(); 311 Event* ev = er.first();
316 qDebug("reading events... "); 312 qDebug("reading events... ");
317 while ( ev ) { 313 while ( ev ) {
318 QStringList cat = ev->categories(); 314 QStringList cat = ev->categories();
319 if ( cat.contains( "MeetingDEF" )) { 315 if ( cat.contains( "MeetingDEF" )) {
320 ev->setCategories( QStringList() ); 316 ev->setCategories( QStringList() );
321 } 317 }
322 int id = ev->pilotId(); 318 int id = ev->pilotId();
323 Event *event; 319 Event *event;
324 event = existingCal->event( mProfileName ,QString::number( id ) ); 320 event = existingCal->event( mProfileName ,QString::number( id ) );
325 if ( event ) { 321 if ( event ) {
326 event = (Event*)event->clone(); 322 event = (Event*)event->clone();
327 copyEvent( event, ev ); 323 copyEvent( event, ev );
328 calendar->deleteEvent( ev ); 324 calendar->deleteEvent( ev );
329 calendar->addEvent( event); 325 calendar->addEvent( event);
330 } 326 }
331 else 327 else
332 event = ev; 328 event = ev;
333 uint cSum; 329 uint cSum;
334 cSum = PhoneFormat::getCsumEvent( event ); 330 cSum = PhoneFormat::getCsumEvent( event );
335 event->setCsum( mProfileName, QString::number( cSum )); 331 event->setCsum( mProfileName, QString::number( cSum ));
336 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 332 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
337 event->setID( mProfileName,QString::number( id ) ); 333 event->setID( mProfileName,QString::number( id ) );
338 ev = er.next(); 334 ev = er.next();
339 } 335 }
340 { 336 {
341 qDebug("reading todos... "); 337 qDebug("reading todos... ");
342 QPtrList<Todo> tr = calendar->rawTodos(); 338 QPtrList<Todo> tr = calendar->rawTodos();
343 Todo* ev = tr.first(); 339 Todo* ev = tr.first();
344 while ( ev ) { 340 while ( ev ) {
345 341
346 QStringList cat = ev->categories(); 342 QStringList cat = ev->categories();
347 if ( cat.contains( "MeetingDEF" )) { 343 if ( cat.contains( "MeetingDEF" )) {
348 ev->setCategories( QStringList() ); 344 ev->setCategories( QStringList() );
349 } 345 }
350 int id = ev->pilotId(); 346 int id = ev->pilotId();
351 Todo *event; 347 Todo *event;
352 event = existingCal->todo( mProfileName ,QString::number( id ) ); 348 event = existingCal->todo( mProfileName ,QString::number( id ) );
353 if ( event ) { 349 if ( event ) {
354 //qDebug("copy todo %s ", event->summary().latin1()); 350 //qDebug("copy todo %s ", event->summary().latin1());
355 351
356 event = (Todo*)event->clone(); 352 event = (Todo*)event->clone();
357 copyTodo( event, ev ); 353 copyTodo( event, ev );
358 calendar->deleteTodo( ev ); 354 calendar->deleteTodo( ev );
359 calendar->addTodo( event); 355 calendar->addTodo( event);
360 } 356 }
361 else 357 else
362 event = ev; 358 event = ev;
363 uint cSum; 359 uint cSum;
364 cSum = PhoneFormat::getCsumTodo( event ); 360 cSum = PhoneFormat::getCsumTodo( event );
365 event->setCsum( mProfileName, QString::number( cSum )); 361 event->setCsum( mProfileName, QString::number( cSum ));
366 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 362 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
367 event->setID( mProfileName,QString::number( id ) ); 363 event->setID( mProfileName,QString::number( id ) );
368 ev = tr.next(); 364 ev = tr.next();
369 } 365 }
370 } 366 }
371 return true; 367 return true;
372} 368}
373void PhoneFormat::copyEvent( Event* to, Event* from ) 369void PhoneFormat::copyEvent( Event* to, Event* from )
374{ 370{
375 if ( from->dtStart().isValid() ) 371 if ( from->dtStart().isValid() )
376 to->setDtStart( from->dtStart() ); 372 to->setDtStart( from->dtStart() );
377 if ( from->dtEnd().isValid() ) 373 if ( from->dtEnd().isValid() )
378 to->setDtEnd( from->dtEnd() ); 374 to->setDtEnd( from->dtEnd() );
379 if ( !from->location().isEmpty() ) 375 if ( !from->location().isEmpty() )
380 to->setLocation( from->location() ); 376 to->setLocation( from->location() );
381 if ( !from->description().isEmpty() ) 377 if ( !from->description().isEmpty() )
382 to->setDescription( from->description() ); 378 to->setDescription( from->description() );
383 if ( !from->summary().isEmpty() ) 379 if ( !from->summary().isEmpty() )
384 to->setSummary( from->summary() ); 380 to->setSummary( from->summary() );
385 381
386 if ( from->alarms().count() ) { 382 if ( from->alarms().count() ) {
387 to->clearAlarms(); 383 to->clearAlarms();
388 Alarm *a = from->alarms().first(); 384 Alarm *a = from->alarms().first();
389 Alarm *b = to->newAlarm( ); 385 Alarm *b = to->newAlarm( );
390 b->setEnabled( a->enabled() ); 386 b->setEnabled( a->enabled() );
391 if ( a->hasStartOffset() ) { 387 if ( a->hasStartOffset() ) {
392 b->setStartOffset( a->startOffset() ); 388 b->setStartOffset( a->startOffset() );
393 } 389 }
394 if ( a->hasTime() ) 390 if ( a->hasTime() )
395 b->setTime( a->time() ); 391 b->setTime( a->time() );
396 392
397 } 393 }
398 QStringList cat = to->categories(); 394 QStringList cat = to->categories();
399 QStringList catFrom = from->categories(); 395 QStringList catFrom = from->categories();
400 QString nCat; 396 QString nCat;
401 int iii; 397 int iii;
402 for ( iii = 0; iii < catFrom.count();++iii ) { 398 for ( iii = 0; iii < catFrom.count();++iii ) {
403 nCat = catFrom[iii]; 399 nCat = catFrom[iii];
404 if ( !nCat.isEmpty() ) 400 if ( !nCat.isEmpty() )
405 if ( !cat.contains( nCat )) { 401 if ( !cat.contains( nCat )) {
406 cat << nCat; 402 cat << nCat;
407 } 403 }
408 } 404 }
409 to->setCategories( cat ); 405 to->setCategories( cat );
410 Recurrence * r = new Recurrence( *from->recurrence(),to); 406 Recurrence * r = new Recurrence( *from->recurrence(),to);
411 to->setRecurrence( r ) ; 407 to->setRecurrence( r ) ;
412 408
413 409
414} 410}
415void PhoneFormat::copyTodo( Todo* to, Todo* from ) 411void PhoneFormat::copyTodo( Todo* to, Todo* from )
416{ 412{
417 if ( from->dtStart().isValid() ) 413 if ( from->dtStart().isValid() )
418 to->setDtStart( from->dtStart() ); 414 to->setDtStart( from->dtStart() );
419 if ( from->dtDue().isValid() ) 415 if ( from->dtDue().isValid() )
420 to->setDtDue( from->dtDue() ); 416 to->setDtDue( from->dtDue() );
421 if ( !from->location().isEmpty() ) 417 if ( !from->location().isEmpty() )
422 to->setLocation( from->location() ); 418 to->setLocation( from->location() );
423 if ( !from->description().isEmpty() ) 419 if ( !from->description().isEmpty() )
424 to->setDescription( from->description() ); 420 to->setDescription( from->description() );
425 if ( !from->summary().isEmpty() ) 421 if ( !from->summary().isEmpty() )
426 to->setSummary( from->summary() ); 422 to->setSummary( from->summary() );
427 423
428 if ( from->alarms().count() ) { 424 if ( from->alarms().count() ) {
429 to->clearAlarms(); 425 to->clearAlarms();
430 Alarm *a = from->alarms().first(); 426 Alarm *a = from->alarms().first();
431 Alarm *b = to->newAlarm( ); 427 Alarm *b = to->newAlarm( );
432 b->setEnabled( a->enabled() ); 428 b->setEnabled( a->enabled() );
433 if ( a->hasStartOffset() ) 429 if ( a->hasStartOffset() )
434 b->setStartOffset( a->startOffset() ); 430 b->setStartOffset( a->startOffset() );
435 if ( a->hasTime() ) 431 if ( a->hasTime() )
436 b->setTime( a->time() ); 432 b->setTime( a->time() );
437 } 433 }
438 434
439 QStringList cat = to->categories(); 435 QStringList cat = to->categories();
440 QStringList catFrom = from->categories(); 436 QStringList catFrom = from->categories();
441 QString nCat; 437 QString nCat;
442 int iii; 438 int iii;
443 for ( iii = 0; iii < catFrom.count();++iii ) { 439 for ( iii = 0; iii < catFrom.count();++iii ) {
444 nCat = catFrom[iii]; 440 nCat = catFrom[iii];
445 if ( !nCat.isEmpty() ) 441 if ( !nCat.isEmpty() )
446 if ( !cat.contains( nCat )) { 442 if ( !cat.contains( nCat )) {
447 cat << nCat; 443 cat << nCat;
448 } 444 }
449 } 445 }
450 to->setCategories( cat ); 446 to->setCategories( cat );
451 if ( from->isCompleted() ) { 447 if ( from->isCompleted() ) {
452 to->setCompleted( true ); 448 to->setCompleted( true );
453 if( from->completed().isValid() ) 449 if( from->completed().isValid() )
454 to->setCompleted( from->completed() ); 450 to->setCompleted( from->completed() );
455 } else { 451 } else {
456 // set percentcomplete only, if to->isCompleted() 452 // set percentcomplete only, if to->isCompleted()
457 if ( to->isCompleted() ) 453 if ( to->isCompleted() )
458 to->setPercentComplete(from->percentComplete()); 454 to->setPercentComplete(from->percentComplete());
459 } 455 }
460 if( to->priority() == 2 && from->priority() == 1 ) 456 if( to->priority() == 2 && from->priority() == 1 )
461 ; //skip 457 ; //skip
462 else if (to->priority() == 4 && from->priority() == 5 ) 458 else if (to->priority() == 4 && from->priority() == 5 )
463 ; 459 ;
464 else 460 else
465 to->setPriority(from->priority()); 461 to->setPriority(from->priority());
466 462
467} 463}
468#include <qcstring.h> 464#include <qcstring.h>
469 465
470void PhoneFormat::afterSave( Incidence* inc) 466void PhoneFormat::afterSave( Incidence* inc)
471{ 467{
472 uint csum; 468 uint csum;
473 inc->removeID( mProfileName ); 469 inc->removeID( mProfileName );
474 if ( inc->type() == "Event") 470 if ( inc->type() == "Event")
475 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 471 csum = PhoneFormat::getCsumEvent( (Event*) inc );
476 else 472 else
477 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 473 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
478 inc->setCsum( mProfileName, QString::number( csum )); 474 inc->setCsum( mProfileName, QString::number( csum ));
479 475
480 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 476 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
481 477
482} 478}
483 479
484bool PhoneFormat::writeToPhone( Calendar * calendar) 480bool PhoneFormat::writeToPhone( Calendar * calendar)
485{ 481{
486#ifdef _WIN32_ 482#ifdef _WIN32_
487 QString fileName = locateLocal("tmp", "tempfile.vcs"); 483 QString fileName = locateLocal("tmp", "tempfile.vcs");
488#else 484#else
489 QString fileName = "/tmp/kdepimtemp.vcs"; 485 QString fileName = "/tmp/kdepimtemp.vcs";
490#endif 486#endif
491 487
492 VCalFormat vfsave; 488 VCalFormat vfsave;
493 vfsave.setLocalTime ( true ); 489 vfsave.setLocalTime ( true );
494 if ( ! vfsave.save( calendar, fileName ) ) 490 if ( ! vfsave.save( calendar, fileName ) )
495 return false; 491 return false;
496 return PhoneAccess::writeToPhone( fileName ); 492 return PhoneAccess::writeToPhone( fileName );
497} 493}
498bool PhoneFormat::save( Calendar *calendar) 494bool PhoneFormat::save( Calendar *calendar)
499{ 495{
500 QLabel status ( i18n(" Opening device ..."), 0 ); 496 QLabel status ( i18n(" Opening device ..."), 0 );
501 int w = status.sizeHint().width()+20 ; 497 int w = status.sizeHint().width()+20 ;
502 if ( w < 200 ) w = 230; 498 if ( w < 200 ) w = 230;
503 int h = status.sizeHint().height()+20 ; 499 int h = status.sizeHint().height()+20 ;
504 int dw = QApplication::desktop()->width(); 500 int dw = QApplication::desktop()->width();
505 int dh = QApplication::desktop()->height(); 501 int dh = QApplication::desktop()->height();
506 status.setCaption(i18n("Writing to phone...") ); 502 status.setCaption(i18n("Writing to phone...") );
507 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 503 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
508 status.show(); 504 status.show();
509 status.raise(); 505 status.raise();
510 qApp->processEvents(); 506 qApp->processEvents();
511 QString message; 507 QString message;
512 508
513 // 1 remove events which should be deleted 509 // 1 remove events which should be deleted
514 QPtrList<Event> er = calendar->rawEvents(); 510 QPtrList<Event> er = calendar->rawEvents();
515 Event* ev = er.first(); 511 Event* ev = er.first();
516 while ( ev ) { 512 while ( ev ) {
517 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 513 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
518 calendar->deleteEvent( ev ); 514 calendar->deleteEvent( ev );
519 } else { 515 } else {
520 516
521 } 517 }
522 ev = er.next(); 518 ev = er.next();
523 } 519 }
524 // 2 remove todos which should be deleted 520 // 2 remove todos which should be deleted
525 QPtrList<Todo> tl = calendar->rawTodos(); 521 QPtrList<Todo> tl = calendar->rawTodos();
526 Todo* to = tl.first(); 522 Todo* to = tl.first();
527 while ( to ) { 523 while ( to ) {
528 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 524 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
529 calendar->deleteTodo( to ); 525 calendar->deleteTodo( to );
530 } else { 526 } else {
531 if ( to->isCompleted()) { 527 if ( to->isCompleted()) {
532 calendar->deleteTodo( to ); 528 calendar->deleteTodo( to );
533 } 529 }
534 } 530 }
535 to = tl.next(); 531 to = tl.next();
536 } 532 }
537 // 3 save file 533 // 3 save file
538 if ( !writeToPhone( calendar ) ) 534 if ( !writeToPhone( calendar ) )
539 return false; 535 return false;
540 536
541 // 5 reread data 537 // 5 reread data
542 message = i18n(" Rereading all data ... "); 538 message = i18n(" Rereading all data ... ");
543 status.setText ( message ); 539 status.setText ( message );
544 qApp->processEvents(); 540 qApp->processEvents();
545 CalendarLocal* calendarTemp = new CalendarLocal(); 541 CalendarLocal* calendarTemp = new CalendarLocal();
546 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 542 calendarTemp->setTimeZoneId( calendar->timeZoneId());
547 if ( ! load( calendarTemp,calendar) ){ 543 if ( ! load( calendarTemp,calendar) ){
548 qDebug("error reloading calendar "); 544 qDebug("error reloading calendar ");
549 delete calendarTemp; 545 delete calendarTemp;
550 return false; 546 return false;
551 } 547 }
552 // 6 compare data 548 // 6 compare data
553 549
554//algo 6 compare event 550//algo 6 compare event
555 er = calendar->rawEvents(); 551 er = calendar->rawEvents();
556 ev = er.first(); 552 ev = er.first();
557 message = i18n(" Comparing event # "); 553 message = i18n(" Comparing event # ");
558 QPtrList<Event> er1 = calendarTemp->rawEvents(); 554 QPtrList<Event> er1 = calendarTemp->rawEvents();
559 Event* ev1; 555 Event* ev1;
560 int procCount = 0; 556 int procCount = 0;
561 while ( ev ) { 557 while ( ev ) {
562 //qDebug("event new ID %s",ev->summary().latin1()); 558 //qDebug("event new ID %s",ev->summary().latin1());
563 status.setText ( message + QString::number ( ++procCount ) ); 559 status.setText ( message + QString::number ( ++procCount ) );
564 qApp->processEvents(); 560 qApp->processEvents();
565 uint csum; 561 uint csum;
566 csum = PhoneFormat::getCsumEvent( ev ); 562 csum = PhoneFormat::getCsumEvent( ev );
567 QString cSum = QString::number( csum ); 563 QString cSum = QString::number( csum );
568 //ev->setCsum( mProfileName, cSum ); 564 //ev->setCsum( mProfileName, cSum );
569 //qDebug("Event cSum %s ", cSum.latin1()); 565 //qDebug("Event cSum %s ", cSum.latin1());
570 ev1 = er1.first(); 566 ev1 = er1.first();
571 while ( ev1 ) { 567 while ( ev1 ) {
572 if ( ev1->getCsum( mProfileName ) == cSum ) { 568 if ( ev1->getCsum( mProfileName ) == cSum ) {
573 er1.remove( ev1 ); 569 er1.remove( ev1 );
574 afterSave( ev ); 570 afterSave( ev );
575 ev->setID(mProfileName, ev1->getID(mProfileName) ); 571 ev->setID(mProfileName, ev1->getID(mProfileName) );
576 //qDebug("Event found on phone for %s ", ev->summary().latin1()); 572 //qDebug("Event found on phone for %s ", ev->summary().latin1());
577 573
578 break; 574 break;
579 } 575 }
580 ev1 = er1.next(); 576 ev1 = er1.next();
581 } 577 }
582 if ( ! ev1 ) { 578 if ( ! ev1 ) {
583 // ev->removeID(mProfileName); 579 // ev->removeID(mProfileName);
584 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 580 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
585 } 581 }
586 582
587 583
588 ev = er.next(); 584 ev = er.next();
589 } 585 }
590 //algo 6 compare todo 586 //algo 6 compare todo
591 tl = calendar->rawTodos(); 587 tl = calendar->rawTodos();
592 to = tl.first(); 588 to = tl.first();
593 procCount = 0; 589 procCount = 0;
594 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 590 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
595 Todo* to1 ; 591 Todo* to1 ;
596 message = i18n(" Comparing todo # "); 592 message = i18n(" Comparing todo # ");
597 while ( to ) { 593 while ( to ) {
598 status.setText ( message + QString::number ( ++procCount ) ); 594 status.setText ( message + QString::number ( ++procCount ) );
599 qApp->processEvents(); 595 qApp->processEvents();
600 uint csum; 596 uint csum;
601 csum = PhoneFormat::getCsumTodo( to ); 597 csum = PhoneFormat::getCsumTodo( to );
602 QString cSum = QString::number( csum ); 598 QString cSum = QString::number( csum );
603 //to->setCsum( mProfileName, cSum ); 599 //to->setCsum( mProfileName, cSum );
604 //qDebug("Todo cSum %s ", cSum.latin1()); 600 //qDebug("Todo cSum %s ", cSum.latin1());
605 Todo* to1 = tl1.first(); 601 Todo* to1 = tl1.first();
606 while ( to1 ) { 602 while ( to1 ) {
607 if ( to1->getCsum( mProfileName ) == cSum ) { 603 if ( to1->getCsum( mProfileName ) == cSum ) {
608 tl1.remove( to1 ); 604 tl1.remove( to1 );
609 afterSave( to ); 605 afterSave( to );
610 to->setID(mProfileName, to1->getID(mProfileName) ); 606 to->setID(mProfileName, to1->getID(mProfileName) );
611 break; 607 break;
612 } 608 }
613 to1 = tl1.next(); 609 to1 = tl1.next();
614 } 610 }
615 if ( ! to1 ) { 611 if ( ! to1 ) {
616 //to->removeID(mProfileName); 612 //to->removeID(mProfileName);
617 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 613 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
618 } 614 }
619 615
620 to = tl.next(); 616 to = tl.next();
621 } 617 }
622 delete calendarTemp; 618 delete calendarTemp;
623 return true; 619 return true;
624 620
625 621
626 622
627} 623}
628 624
629 625
630QString PhoneFormat::toString( Calendar * ) 626QString PhoneFormat::toString( Calendar * )
631{ 627{
632 return QString::null; 628 return QString::null;
633} 629}
634bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 630bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
635{ 631{
636 return false; 632 return false;
637} 633}
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp
index fe914dd..5fafa1f 100644
--- a/libkdepim/phoneaccess.cpp
+++ b/libkdepim/phoneaccess.cpp
@@ -1,151 +1,173 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 3
4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> 4 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22 22
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qfile.h> 27#include <qfile.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qtextcodec.h> 29#include <qtextcodec.h>
30#include <qdir.h> 30#include <qdir.h>
31#include <kmessagebox.h> 31#include <kmessagebox.h>
32#include <stdlib.h> 32#include <stdlib.h>
33#include "phoneaccess.h" 33#include "phoneaccess.h"
34 34
35void PhoneAccess::writeConfig( QString device, QString connection, QString model ) 35void PhoneAccess::writeConfig( QString device, QString connection, QString model )
36{ 36{
37#ifdef _WIN32_ 37#ifdef _WIN32_
38 QString fileName = qApp->applicationDirPath () +"\\gammurc"; 38 QString fileName = qApp->applicationDirPath () +"\\gammurc";
39#else 39#else
40 QString fileName = QDir::homeDirPath() +"/.gammurc"; 40 QString fileName = QDir::homeDirPath() +"/.gammurc";
41#endif 41#endif
42 //qDebug("save %d ", load ); 42 //qDebug("save %d ", load );
43 QString content = "[gammu]\n";; 43 QString content = "[gammu]\n";;
44 bool write = false; 44 bool write = false;
45 bool addPort = true, addConnection = true, addModel = true; 45 bool addPort = true, addConnection = true, addModel = true;
46 QFile file( fileName ); 46 QFile file( fileName );
47 if ( QFile::exists( fileName) ) { 47 if ( QFile::exists( fileName) ) {
48 if (!file.open( IO_ReadOnly ) ) { 48 if (!file.open( IO_ReadOnly ) ) {
49 qDebug("Error: cannot open %s ", fileName.latin1() ); 49 qDebug("Error: cannot open %s ", fileName.latin1() );
50 return; 50 return;
51 } 51 }
52 QString line; 52 QString line;
53 while ( file.readLine( line, 1024 ) > 0 ) { 53 while ( file.readLine( line, 1024 ) > 0 ) {
54 //qDebug("*%s* ", line.latin1() ); 54 //qDebug("*%s* ", line.latin1() );
55 if ( line.left(7 ) == "[gammu]" ) { 55 if ( line.left(7 ) == "[gammu]" ) {
56 ; 56 ;
57 } else 57 } else
58 if ( line.left(4 ) == "port" ) { 58 if ( line.left(4 ) == "port" ) {
59 if ( line == "port = " + device+"\n" ) { 59 if ( line == "port = " + device+"\n" ) {
60 content += line ; 60 content += line ;
61 addPort = false; 61 addPort = false;
62 //qDebug("port found" ); 62 //qDebug("port found" );
63 } 63 }
64 64
65 } else if ( line.left(5 ) == "model" ) { 65 } else if ( line.left(5 ) == "model" ) {
66 if ( line == "model = " + model +"\n") { 66 if ( line == "model = " + model +"\n") {
67 content += line ; 67 content += line ;
68 addModel = false; 68 addModel = false;
69 //qDebug("model found" ); 69 //qDebug("model found" );
70 } 70 }
71 71
72 } else if ( line.left( 10 ) == "connection" ) { 72 } else if ( line.left( 10 ) == "connection" ) {
73 if ( line == "connection = " + connection +"\n") { 73 if ( line == "connection = " + connection +"\n") {
74 addConnection = false; 74 addConnection = false;
75 content += line ; 75 content += line ;
76 //qDebug("con found" ); 76 //qDebug("con found" );
77 } 77 }
78 78
79 } else { 79 } else {
80 content += line ; 80 content += line ;
81 } 81 }
82 } 82 }
83 file.close(); 83 file.close();
84 } else { 84 } else {
85 if ( ! connection.isEmpty() ) { 85 if ( ! connection.isEmpty() ) {
86 addConnection = true; 86 addConnection = true;
87 } 87 }
88 if ( ! device.isEmpty() ) { 88 if ( ! device.isEmpty() ) {
89 addPort = true; 89 addPort = true;
90 90
91 } 91 }
92 if ( ! model.isEmpty() ) { 92 if ( ! model.isEmpty() ) {
93 addModel = true; 93 addModel = true;
94 } 94 }
95 } 95 }
96 96
97 if ( addConnection ) { 97 if ( addConnection ) {
98 write = true; 98 write = true;
99 content += "connection = "; 99 content += "connection = ";
100 content += connection; 100 content += connection;
101 content += "\n"; 101 content += "\n";
102 } 102 }
103 if ( addPort ) { 103 if ( addPort ) {
104 write = true; 104 write = true;
105 content += "port = "; 105 content += "port = ";
106 content += device; 106 content += device;
107 content += "\n"; 107 content += "\n";
108 108
109 } 109 }
110 if ( addModel ) { 110 if ( addModel ) {
111 write = true; 111 write = true;
112 content += "model = "; 112 content += "model = ";
113 content += model; 113 content += model;
114 content += "\n"; 114 content += "\n";
115 } 115 }
116 if ( write ) { 116 if ( write ) {
117 if (!file.open( IO_WriteOnly ) ) { 117 if (!file.open( IO_WriteOnly ) ) {
118 qDebug("Error: cannot write file %s ", fileName.latin1() ); 118 qDebug("Error: cannot write file %s ", fileName.latin1() );
119 return; 119 return;
120 } 120 }
121 qDebug("Writing file %s ", fileName.latin1() ); 121 qDebug("Writing file %s ", fileName.latin1() );
122 QTextStream ts( &file ); 122 QTextStream ts( &file );
123 ts << content ; 123 ts << content ;
124 file.close(); 124 file.close();
125 } 125 }
126 126
127} 127}
128 128
129 129
130bool PhoneAccess::writeToPhone( QString fileName) 130bool PhoneAccess::writeToPhone( QString fileName)
131{ 131{
132 132
133#ifdef DESKTOP_VERSION 133#ifdef DESKTOP_VERSION
134#ifdef _WIN32_ 134#ifdef _WIN32_
135 QString command ="kammu --restore " + fileName ; 135 QString command ="kammu --restore " + fileName ;
136#else 136#else
137 QString command ="./kammu --restore " + fileName ; 137 QString command ="./kammu --restore " + fileName ;
138#endif 138#endif
139#else 139#else
140 QString command ="kammu --restore " + fileName ; 140 QString command ="kammu --restore " + fileName ;
141#endif 141#endif
142 int ret; 142 int ret;
143 while ( (ret = system ( command.latin1())) != 0 ) { 143 while ( (ret = system ( command.latin1())) != 0 ) {
144 qDebug("Error S::command returned %d.", ret); 144 qDebug("Error S::command returned %d.", ret);
145 int retval = KMessageBox::warningContinueCancel(0, 145 int retval = KMessageBox::warningContinueCancel(0,
146 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); 146 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel"));
147 if ( retval != KMessageBox::Continue )
148 return false;
149 }
150 return true;
151}
152bool PhoneAccess::readFromPhone( QString fileName)
153{
154
155#ifdef DESKTOP_VERSION
156#ifdef _WIN32_
157 QString command ="kammu --backup " + fileName + " -yes" ;
158#else
159 QString command ="./kammu --backup " + fileName + " -yes" ;
160#endif
161#else
162 QString command ="kammu --backup " + fileName + " -yes" ;
163#endif
164 int ret;
165 while ( (ret = system ( command.latin1())) != 0 ) {
166 qDebug("Error S::command returned %d.", ret);
167 int retval = KMessageBox::warningContinueCancel(0,
168 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel"));
147 if ( retval != KMessageBox::Continue ) 169 if ( retval != KMessageBox::Continue )
148 return false; 170 return false;
149 } 171 }
150 return true; 172 return true;
151} 173}
diff --git a/libkdepim/phoneaccess.h b/libkdepim/phoneaccess.h
index b7c4732..80840e2 100644
--- a/libkdepim/phoneaccess.h
+++ b/libkdepim/phoneaccess.h
@@ -1,42 +1,44 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21#ifndef PHONEACCESS_H 21#ifndef PHONEACCESS_H
22#define PHONEACCESS_H 22#define PHONEACCESS_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qobject.h>
25 26
26 27
27 28
28/** 29/**
29 This class implements the calendar format used by Phone. 30 This class implements the calendar format used by Phone.
30*/ 31*/
31 32
32class PhoneAccess : public QObject { 33class PhoneAccess : public QObject {
33 public: 34 public:
34 35
35 static void writeConfig( QString device,QString connection, QString model ); 36 static void writeConfig( QString device,QString connection, QString model );
36 static bool writeToPhone( QString fileName ); 37 static bool writeToPhone( QString fileName );
38 static bool readFromPhone( QString fileName );
37 39
38}; 40};
39 41
40 42
41 43
42#endif 44#endif