summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp2
-rw-r--r--kabc/kabcE.pro2
-rw-r--r--kabc/plugins/dir/resourcedir.cpp7
-rw-r--r--kabc/plugins/dir/resourcedir.h2
-rw-r--r--kabc/plugins/file/resourcefile.cpp16
-rw-r--r--kabc/plugins/file/resourcefile.h4
-rw-r--r--kabc/plugins/ldap/resourceldap.cpp7
-rw-r--r--kabc/plugins/ldap/resourceldap.h2
-rw-r--r--kabc/plugins/opie/resourceopie.cpp11
-rw-r--r--kabc/plugins/opie/resourceopie.h4
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp11
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.h4
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp8
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.h4
-rw-r--r--kabc/resource.cpp32
-rw-r--r--kabc/resource.h16
-rw-r--r--kaddressbook/xxportobject.cpp4
-rw-r--r--microkde/kresources/configdialog.cpp125
-rw-r--r--microkde/kresources/configdialog.h5
-rw-r--r--microkde/kresources/configpage.cpp29
-rw-r--r--microkde/kresources/factory.cpp38
-rw-r--r--microkde/kresources/factory.h15
-rw-r--r--microkde/kresources/manager.h12
-rw-r--r--microkde/kresources/managerimpl.cpp13
-rw-r--r--microkde/kresources/managerimpl.h8
-rw-r--r--microkde/kresources/resource.cpp1
-rw-r--r--microkde/kresources/resource.h24
-rw-r--r--microkde/microkdeE.pro2
28 files changed, 91 insertions, 317 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 592d78d..c584c35 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1210 +1,1210 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h> 50#include <libkdepim/phoneaccess.h>
51#include "addressbook.h" 51#include "addressbook.h"
52#include "resource.h" 52#include "resource.h"
53#include "vcardconverter.h" 53#include "vcardconverter.h"
54#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
55 55
56//US #include "addressbook.moc" 56//US #include "addressbook.moc"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
61{ 61{
62 Addressee::List mAddressees; 62 Addressee::List mAddressees;
63 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
64 Field::List mAllFields; 64 Field::List mAllFields;
65 KConfig *mConfig; 65 KConfig *mConfig;
66 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
67//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
68}; 68};
69 69
70struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
71{ 71{
72 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
73}; 73};
74 74
75struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
76{ 76{
77 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
78}; 78};
79 79
80AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
81{ 81{
82 d = new IteratorData; 82 d = new IteratorData;
83} 83}
84 84
85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
86{ 86{
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89} 89}
90 90
91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
92{ 92{
93 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
94 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
95 d = new IteratorData; 95 d = new IteratorData;
96 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
97 return *this; 97 return *this;
98} 98}
99 99
100AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
101{ 101{
102 delete d; 102 delete d;
103} 103}
104 104
105const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
106{ 106{
107 return *(d->mIt); 107 return *(d->mIt);
108} 108}
109 109
110Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
111{ 111{
112 return *(d->mIt); 112 return *(d->mIt);
113} 113}
114 114
115Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
116{ 116{
117 return &(*(d->mIt)); 117 return &(*(d->mIt));
118} 118}
119 119
120AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
121{ 121{
122 (d->mIt)++; 122 (d->mIt)++;
123 return *this; 123 return *this;
124} 124}
125 125
126AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
127{ 127{
128 (d->mIt)++; 128 (d->mIt)++;
129 return *this; 129 return *this;
130} 130}
131 131
132AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
133{ 133{
134 (d->mIt)--; 134 (d->mIt)--;
135 return *this; 135 return *this;
136} 136}
137 137
138AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
139{ 139{
140 (d->mIt)--; 140 (d->mIt)--;
141 return *this; 141 return *this;
142} 142}
143 143
144bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
145{ 145{
146 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
147} 147}
148 148
149bool AddressBook::Iterator::operator!=( const Iterator &it ) 149bool AddressBook::Iterator::operator!=( const Iterator &it )
150{ 150{
151 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
152} 152}
153 153
154 154
155AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
156{ 156{
157 d = new ConstIteratorData; 157 d = new ConstIteratorData;
158} 158}
159 159
160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
161{ 161{
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164} 164}
165 165
166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
167{ 167{
168 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
169 delete d; // delete the old data because the Iterator was really constructed before 169 delete d; // delete the old data because the Iterator was really constructed before
170 d = new ConstIteratorData; 170 d = new ConstIteratorData;
171 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
172 return *this; 172 return *this;
173} 173}
174 174
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
215{ 215{
216 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
217} 217}
218 218
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
220{ 220{
221 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
222} 222}
223 223
224 224
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
236{ 236{
237 init(config, family); 237 init(config, family);
238 238
239} 239}
240 240
241// the default family is "contact" 241// the default family is "contact"
242void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
243{ 243{
244 blockLSEchange = false; 244 blockLSEchange = false;
245 d = new AddressBookData; 245 d = new AddressBookData;
246 QString fami = family; 246 QString fami = family;
247 if (config != 0) { 247 if (config != 0) {
248 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
249 qDebug("creating sync config "); 249 qDebug("creating sync config ");
250 fami = "contact"; 250 fami = "contact";
251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
252 con->setGroup( "General" ); 252 con->setGroup( "General" );
253 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
254 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
255 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
256 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
257 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
258 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
259 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
260 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
261 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
262 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
263 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
264 } else { 264 } else {
265 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
266 } 266 }
267 //con->sync(); 267 //con->sync();
268 d->mConfig = con; 268 d->mConfig = con;
269 } 269 }
270 else 270 else
271 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
272// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
273 } 273 }
274 else { 274 else {
275 d->mConfig = 0; 275 d->mConfig = 0;
276// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
277 } 277 }
278 278
279//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
280 d->mManager = new KRES::Manager<Resource>( fami, false ); 280 d->mManager = new KRES::Manager<Resource>( fami );
281 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
282 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
283 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
284 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
286 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
287 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
294 if ( res ) 294 if ( res )
295 { 295 {
296 addResource( res ); 296 addResource( res );
297 } 297 }
298 else 298 else
299 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
300 } 300 }
301 setStandardResource( res ); 301 setStandardResource( res );
302 manager->writeConfig(); 302 manager->writeConfig();
303 } 303 }
304 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
305 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
306 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
307 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344 clear(); 344 clear();
345 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 346 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 350 ok = false;
351 } else { 351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); 352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379// exports all Addressees, which are syncable 379// exports all Addressees, which are syncable
380void AddressBook::export2File( QString fileName ) 380void AddressBook::export2File( QString fileName )
381{ 381{
382 382
383 QFile outFile( fileName ); 383 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( IO_WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 387 return ;
388 } 388 }
389 QTextStream t( &outFile ); 389 QTextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( QTextStream::UnicodeUTF8 );
391 Iterator it; 391 Iterator it;
392 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
395 if ( (*it).resource() && (*it).resource()->includeInSync() ) { 395 if ( (*it).resource() && (*it).resource()->includeInSync() ) {
396 if ( !(*it).IDStr().isEmpty() ) { 396 if ( !(*it).IDStr().isEmpty() ) {
397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
398 } 398 }
399 KABC::VCardConverter converter; 399 KABC::VCardConverter converter;
400 QString vcard; 400 QString vcard;
401 //Resource *resource() const; 401 //Resource *resource() const;
402 converter.addresseeToVCard( *it, vcard, version ); 402 converter.addresseeToVCard( *it, vcard, version );
403 t << vcard << "\r\n"; 403 t << vcard << "\r\n";
404 } 404 }
405 } 405 }
406 t << "\r\n\r\n"; 406 t << "\r\n\r\n";
407 outFile.close(); 407 outFile.close();
408} 408}
409// if QStringList uids is empty, all are exported 409// if QStringList uids is empty, all are exported
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
411{ 411{
412 KABC::VCardConverter converter; 412 KABC::VCardConverter converter;
413 QString datastream; 413 QString datastream;
414 Iterator it; 414 Iterator it;
415 bool all = uids.isEmpty(); 415 bool all = uids.isEmpty();
416 for ( it = begin(); it != end(); ++it ) { 416 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 418 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 419 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 420 continue;
421 } 421 }
422 KABC::Addressee a = ( *it ); 422 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 423 if ( a.isEmpty() )
424 continue; 424 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 425 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 426 continue;
427 a.simplifyEmails(); 427 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 428 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 429 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 430 a.simplifyAddresses();
431 431
432 QString vcard; 432 QString vcard;
433 QString vcardnew; 433 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 434 converter.addresseeToVCard( a, vcard );
435 int start = 0; 435 int start = 0;
436 int next; 436 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 438 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 439 int dopp = vcard.find(":", next);
440 int sep; 440 int sep;
441 if ( semi < dopp && semi >= 0 ) 441 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 442 sep = semi ;
443 else 443 else
444 sep = dopp; 444 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 445 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 447 start = sep;
448 } 448 }
449 vcardnew += vcard.mid( start,vcard.length() ); 449 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 450 vcard = "";
451 start = 0; 451 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 453 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 454 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 455 start = sep;
456 } 456 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 457 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 458 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 459 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 460 datastream += vcard;
461 461
462 } 462 }
463 463
464 QFile outFile(fileName); 464 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 465 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 467 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 468 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 469 t <<datastream;
470 t << "\r\n\r\n"; 470 t << "\r\n\r\n";
471 outFile.close(); 471 outFile.close();
472 472
473 } else { 473 } else {
474 qDebug("Error open temp file "); 474 qDebug("Error open temp file ");
475 return false; 475 return false;
476 } 476 }
477 return true; 477 return true;
478 478
479} 479}
480void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513} 513}
514void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 514void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
515{ 515{
516 Iterator ait; 516 Iterator ait;
517 for ( ait = begin(); ait != end(); ++ait ) { 517 for ( ait = begin(); ait != end(); ++ait ) {
518 if ( setNonSyncTagged ) { 518 if ( setNonSyncTagged ) {
519 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 519 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
520 (*ait).setTagged( true ); 520 (*ait).setTagged( true );
521 } else 521 } else
522 (*ait).setTagged( false ); 522 (*ait).setTagged( false );
523 } else 523 } else
524 (*ait).setTagged( false ); 524 (*ait).setTagged( false );
525 } 525 }
526} 526}
527void AddressBook::removeUntagged() 527void AddressBook::removeUntagged()
528{ 528{
529 Iterator ait; 529 Iterator ait;
530 bool todelete = false; 530 bool todelete = false;
531 Iterator todel; 531 Iterator todel;
532 for ( ait = begin(); ait != end(); ++ait ) { 532 for ( ait = begin(); ait != end(); ++ait ) {
533 if ( todelete ) 533 if ( todelete )
534 removeAddressee( todel ); 534 removeAddressee( todel );
535 if (!(*ait).tagged()) { 535 if (!(*ait).tagged()) {
536 todelete = true; 536 todelete = true;
537 todel = ait; 537 todel = ait;
538 } else 538 } else
539 todelete = false; 539 todelete = false;
540 } 540 }
541 if ( todelete ) 541 if ( todelete )
542 removeAddressee( todel ); 542 removeAddressee( todel );
543 deleteRemovedAddressees(); 543 deleteRemovedAddressees();
544} 544}
545void AddressBook::smplifyAddressees() 545void AddressBook::smplifyAddressees()
546{ 546{
547 Iterator ait; 547 Iterator ait;
548 for ( ait = begin(); ait != end(); ++ait ) { 548 for ( ait = begin(); ait != end(); ++ait ) {
549 (*ait).simplifyEmails(); 549 (*ait).simplifyEmails();
550 (*ait).simplifyPhoneNumbers(); 550 (*ait).simplifyPhoneNumbers();
551 (*ait).simplifyPhoneNumberTypes(); 551 (*ait).simplifyPhoneNumberTypes();
552 (*ait).simplifyAddresses(); 552 (*ait).simplifyAddresses();
553 } 553 }
554} 554}
555void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 555void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
556{ 556{
557 Iterator ait; 557 Iterator ait;
558 for ( ait = begin(); ait != end(); ++ait ) { 558 for ( ait = begin(); ait != end(); ++ait ) {
559 QString id = (*ait).IDStr(); 559 QString id = (*ait).IDStr();
560 (*ait).setIDStr( ":"); 560 (*ait).setIDStr( ":");
561 (*ait).setExternalUID( id ); 561 (*ait).setExternalUID( id );
562 (*ait).setOriginalExternalUID( id ); 562 (*ait).setOriginalExternalUID( id );
563 if ( isPreSync ) 563 if ( isPreSync )
564 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 564 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
565 else { 565 else {
566 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 566 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
567 (*ait).setID( currentSyncDevice,id ); 567 (*ait).setID( currentSyncDevice,id );
568 568
569 } 569 }
570 } 570 }
571} 571}
572void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 572void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
573{ 573{
574 574
575 setUntagged(); 575 setUntagged();
576 KABC::Addressee::List list; 576 KABC::Addressee::List list;
577 QFile file( fileName ); 577 QFile file( fileName );
578 file.open( IO_ReadOnly ); 578 file.open( IO_ReadOnly );
579 QByteArray rawData = file.readAll(); 579 QByteArray rawData = file.readAll();
580 file.close(); 580 file.close();
581 QString data; 581 QString data;
582 582
583 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 583 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
584 KABC::VCardTool tool; 584 KABC::VCardTool tool;
585 list = tool.parseVCards( data ); 585 list = tool.parseVCards( data );
586 KABC::Addressee::List::Iterator it; 586 KABC::Addressee::List::Iterator it;
587 for ( it = list.begin(); it != list.end(); ++it ) { 587 for ( it = list.begin(); it != list.end(); ++it ) {
588 Iterator ait; 588 Iterator ait;
589 for ( ait = begin(); ait != end(); ++ait ) { 589 for ( ait = begin(); ait != end(); ++ait ) {
590 if ( !(*ait).tagged() ) { 590 if ( !(*ait).tagged() ) {
591 if ( (*ait).containsAdr(*it)) { 591 if ( (*ait).containsAdr(*it)) {
592 (*ait).setTagged(true); 592 (*ait).setTagged(true);
593 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 593 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
594 (*it).setIDStr( ":"); 594 (*it).setIDStr( ":");
595 (*it).setID( currentSyncDevice,id ); 595 (*it).setID( currentSyncDevice,id );
596 (*it).setExternalUID( id ); 596 (*it).setExternalUID( id );
597 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 597 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
598 (*it).setUid( ( (*ait).uid() )); 598 (*it).setUid( ( (*ait).uid() ));
599 break; 599 break;
600 } 600 }
601 } 601 }
602 602
603 } 603 }
604 if ( ait == end() ) 604 if ( ait == end() )
605 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 605 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
606 } 606 }
607 clear(); 607 clear();
608 for ( it = list.begin(); it != list.end(); ++it ) { 608 for ( it = list.begin(); it != list.end(); ++it ) {
609 insertAddressee( (*it) ); 609 insertAddressee( (*it) );
610 } 610 }
611} 611}
612 612
613bool AddressBook::saveABphone( QString fileName ) 613bool AddressBook::saveABphone( QString fileName )
614{ 614{
615 //smplifyAddressees(); 615 //smplifyAddressees();
616 qDebug("saveABphone:: saving AB... "); 616 qDebug("saveABphone:: saving AB... ");
617 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 617 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
618 return false; 618 return false;
619 qDebug("saveABphone:: writing to phone... "); 619 qDebug("saveABphone:: writing to phone... ");
620 if ( !PhoneAccess::writeToPhone( fileName) ) { 620 if ( !PhoneAccess::writeToPhone( fileName) ) {
621 return false; 621 return false;
622 } 622 }
623 qDebug("saveABphone:: re-reading from phone... "); 623 qDebug("saveABphone:: re-reading from phone... ");
624 if ( !PhoneAccess::readFromPhone( fileName) ) { 624 if ( !PhoneAccess::readFromPhone( fileName) ) {
625 return false; 625 return false;
626 } 626 }
627 return true; 627 return true;
628} 628}
629bool AddressBook::saveAB() 629bool AddressBook::saveAB()
630{ 630{
631 bool ok = true; 631 bool ok = true;
632 632
633 deleteRemovedAddressees(); 633 deleteRemovedAddressees();
634 Iterator ait; 634 Iterator ait;
635 for ( ait = begin(); ait != end(); ++ait ) { 635 for ( ait = begin(); ait != end(); ++ait ) {
636 if ( !(*ait).IDStr().isEmpty() ) { 636 if ( !(*ait).IDStr().isEmpty() ) {
637 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 637 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
638 } 638 }
639 } 639 }
640 KRES::Manager<Resource>::ActiveIterator it; 640 KRES::Manager<Resource>::ActiveIterator it;
641 KRES::Manager<Resource> *manager = d->mManager; 641 KRES::Manager<Resource> *manager = d->mManager;
642 qDebug("SaveAB::saving..." ); 642 qDebug("SaveAB::saving..." );
643 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 643 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
644 qDebug("SaveAB::checking resource..." ); 644 qDebug("SaveAB::checking resource..." );
645 if ( (*it)->readOnly() ) 645 if ( (*it)->readOnly() )
646 qDebug("resource is readonly." ); 646 qDebug("resource is readonly." );
647 if ( (*it)->isOpen() ) 647 if ( (*it)->isOpen() )
648 qDebug("resource is open" ); 648 qDebug("resource is open" );
649 649
650 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 650 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
651 Ticket *ticket = requestSaveTicket( *it ); 651 Ticket *ticket = requestSaveTicket( *it );
652 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 652 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
653 if ( !ticket ) { 653 if ( !ticket ) {
654 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 654 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
655 .arg( (*it)->resourceName() ) ); 655 .arg( (*it)->resourceName() ) );
656 return false; 656 return false;
657 } 657 }
658 658
659 //if ( !save( ticket ) ) 659 //if ( !save( ticket ) )
660 if ( ticket->resource() ) { 660 if ( ticket->resource() ) {
661 QString name = ticket->resource()->resourceName(); 661 QString name = ticket->resource()->resourceName();
662 if ( ! ticket->resource()->save( ticket ) ) 662 if ( ! ticket->resource()->save( ticket ) )
663 ok = false; 663 ok = false;
664 else 664 else
665 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 665 qDebug("StdAddressBook::resource saved '%s'", name.latin1() );
666 666
667 } else 667 } else
668 ok = false; 668 ok = false;
669 669
670 } 670 }
671 } 671 }
672 return ok; 672 return ok;
673} 673}
674 674
675AddressBook::Iterator AddressBook::begin() 675AddressBook::Iterator AddressBook::begin()
676{ 676{
677 Iterator it = Iterator(); 677 Iterator it = Iterator();
678 it.d->mIt = d->mAddressees.begin(); 678 it.d->mIt = d->mAddressees.begin();
679 return it; 679 return it;
680} 680}
681 681
682AddressBook::ConstIterator AddressBook::begin() const 682AddressBook::ConstIterator AddressBook::begin() const
683{ 683{
684 ConstIterator it = ConstIterator(); 684 ConstIterator it = ConstIterator();
685 it.d->mIt = d->mAddressees.begin(); 685 it.d->mIt = d->mAddressees.begin();
686 return it; 686 return it;
687} 687}
688 688
689AddressBook::Iterator AddressBook::end() 689AddressBook::Iterator AddressBook::end()
690{ 690{
691 Iterator it = Iterator(); 691 Iterator it = Iterator();
692 it.d->mIt = d->mAddressees.end(); 692 it.d->mIt = d->mAddressees.end();
693 return it; 693 return it;
694} 694}
695 695
696AddressBook::ConstIterator AddressBook::end() const 696AddressBook::ConstIterator AddressBook::end() const
697{ 697{
698 ConstIterator it = ConstIterator(); 698 ConstIterator it = ConstIterator();
699 it.d->mIt = d->mAddressees.end(); 699 it.d->mIt = d->mAddressees.end();
700 return it; 700 return it;
701} 701}
702 702
703void AddressBook::clear() 703void AddressBook::clear()
704{ 704{
705 d->mAddressees.clear(); 705 d->mAddressees.clear();
706} 706}
707 707
708Ticket *AddressBook::requestSaveTicket( Resource *resource ) 708Ticket *AddressBook::requestSaveTicket( Resource *resource )
709{ 709{
710 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 710 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
711 711
712 if ( !resource ) 712 if ( !resource )
713 { 713 {
714 qDebug("AddressBook::requestSaveTicket no resource" ); 714 qDebug("AddressBook::requestSaveTicket no resource" );
715 resource = standardResource(); 715 resource = standardResource();
716 } 716 }
717 717
718 KRES::Manager<Resource>::ActiveIterator it; 718 KRES::Manager<Resource>::ActiveIterator it;
719 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 719 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
720 if ( (*it) == resource ) { 720 if ( (*it) == resource ) {
721 if ( (*it)->readOnly() || !(*it)->isOpen() ) 721 if ( (*it)->readOnly() || !(*it)->isOpen() )
722 return 0; 722 return 0;
723 else 723 else
724 return (*it)->requestSaveTicket(); 724 return (*it)->requestSaveTicket();
725 } 725 }
726 } 726 }
727 727
728 return 0; 728 return 0;
729} 729}
730//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 730//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
731void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 731void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
732{ 732{
733 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 733 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
734 //qDebug("block insert "); 734 //qDebug("block insert ");
735 return; 735 return;
736 } 736 }
737 //qDebug("inserting.... %s ",a.uid().latin1() ); 737 //qDebug("inserting.... %s ",a.uid().latin1() );
738 bool found = false; 738 bool found = false;
739 Addressee::List::Iterator it; 739 Addressee::List::Iterator it;
740 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 740 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
741 if ( a.uid() == (*it).uid() ) { 741 if ( a.uid() == (*it).uid() ) {
742 742
743 bool changed = false; 743 bool changed = false;
744 Addressee addr = a; 744 Addressee addr = a;
745 if ( addr != (*it) ) 745 if ( addr != (*it) )
746 changed = true; 746 changed = true;
747 747
748 if ( takeResource ) { 748 if ( takeResource ) {
749 Resource * res = (*it).resource(); 749 Resource * res = (*it).resource();
750 (*it) = a; 750 (*it) = a;
751 (*it).setResource( res ); 751 (*it).setResource( res );
752 } else { 752 } else {
753 (*it) = a; 753 (*it) = a;
754 if ( (*it).resource() == 0 ) 754 if ( (*it).resource() == 0 )
755 (*it).setResource( standardResource() ); 755 (*it).setResource( standardResource() );
756 } 756 }
757 if ( changed ) { 757 if ( changed ) {
758 if ( setRev ) { 758 if ( setRev ) {
759 759
760 // get rid of micro seconds 760 // get rid of micro seconds
761 QDateTime dt = QDateTime::currentDateTime(); 761 QDateTime dt = QDateTime::currentDateTime();
762 QTime t = dt.time(); 762 QTime t = dt.time();
763 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 763 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
764 (*it).setRevision( dt ); 764 (*it).setRevision( dt );
765 } 765 }
766 (*it).setChanged( true ); 766 (*it).setChanged( true );
767 } 767 }
768 768
769 found = true; 769 found = true;
770 } else { 770 } else {
771 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 771 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
772 QString name = (*it).uid().mid( 19 ); 772 QString name = (*it).uid().mid( 19 );
773 Addressee b = a; 773 Addressee b = a;
774 QString id = b.getID( name ); 774 QString id = b.getID( name );
775 if ( ! id.isEmpty() ) { 775 if ( ! id.isEmpty() ) {
776 QString des = (*it).note(); 776 QString des = (*it).note();
777 int startN; 777 int startN;
778 if( (startN = des.find( id ) ) >= 0 ) { 778 if( (startN = des.find( id ) ) >= 0 ) {
779 int endN = des.find( ",", startN+1 ); 779 int endN = des.find( ",", startN+1 );
780 des = des.left( startN ) + des.mid( endN+1 ); 780 des = des.left( startN ) + des.mid( endN+1 );
781 (*it).setNote( des ); 781 (*it).setNote( des );
782 } 782 }
783 } 783 }
784 } 784 }
785 } 785 }
786 } 786 }
787 if ( found ) 787 if ( found )
788 return; 788 return;
789 d->mAddressees.append( a ); 789 d->mAddressees.append( a );
790 Addressee& addr = d->mAddressees.last(); 790 Addressee& addr = d->mAddressees.last();
791 if ( addr.resource() == 0 ) 791 if ( addr.resource() == 0 )
792 addr.setResource( standardResource() ); 792 addr.setResource( standardResource() );
793 793
794 addr.setChanged( true ); 794 addr.setChanged( true );
795} 795}
796 796
797void AddressBook::removeAddressee( const Addressee &a ) 797void AddressBook::removeAddressee( const Addressee &a )
798{ 798{
799 Iterator it; 799 Iterator it;
800 Iterator it2; 800 Iterator it2;
801 bool found = false; 801 bool found = false;
802 for ( it = begin(); it != end(); ++it ) { 802 for ( it = begin(); it != end(); ++it ) {
803 if ( a.uid() == (*it).uid() ) { 803 if ( a.uid() == (*it).uid() ) {
804 found = true; 804 found = true;
805 it2 = it; 805 it2 = it;
806 } else { 806 } else {
807 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 807 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
808 QString name = (*it).uid().mid( 19 ); 808 QString name = (*it).uid().mid( 19 );
809 Addressee b = a; 809 Addressee b = a;
810 QString id = b.getID( name ); 810 QString id = b.getID( name );
811 if ( ! id.isEmpty() ) { 811 if ( ! id.isEmpty() ) {
812 QString des = (*it).note(); 812 QString des = (*it).note();
813 if( des.find( id ) < 0 ) { 813 if( des.find( id ) < 0 ) {
814 des += id + ","; 814 des += id + ",";
815 (*it).setNote( des ); 815 (*it).setNote( des );
816 } 816 }
817 } 817 }
818 } 818 }
819 819
820 } 820 }
821 } 821 }
822 822
823 if ( found ) 823 if ( found )
824 removeAddressee( it2 ); 824 removeAddressee( it2 );
825 825
826} 826}
827 827
828void AddressBook::removeSyncAddressees( bool removeDeleted ) 828void AddressBook::removeSyncAddressees( bool removeDeleted )
829{ 829{
830 Iterator it = begin(); 830 Iterator it = begin();
831 Iterator it2 ; 831 Iterator it2 ;
832 QDateTime dt ( QDate( 2004,1,1) ); 832 QDateTime dt ( QDate( 2004,1,1) );
833 while ( it != end() ) { 833 while ( it != end() ) {
834 (*it).setRevision( dt ); 834 (*it).setRevision( dt );
835 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 835 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
836 (*it).setIDStr(""); 836 (*it).setIDStr("");
837 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 837 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
838 it2 = it; 838 it2 = it;
839 //qDebug("removing %s ",(*it).uid().latin1() ); 839 //qDebug("removing %s ",(*it).uid().latin1() );
840 ++it; 840 ++it;
841 removeAddressee( it2 ); 841 removeAddressee( it2 );
842 } else { 842 } else {
843 //qDebug("skipping %s ",(*it).uid().latin1() ); 843 //qDebug("skipping %s ",(*it).uid().latin1() );
844 ++it; 844 ++it;
845 } 845 }
846 } 846 }
847 deleteRemovedAddressees(); 847 deleteRemovedAddressees();
848} 848}
849 849
850void AddressBook::removeAddressee( const Iterator &it ) 850void AddressBook::removeAddressee( const Iterator &it )
851{ 851{
852 d->mRemovedAddressees.append( (*it) ); 852 d->mRemovedAddressees.append( (*it) );
853 d->mAddressees.remove( it.d->mIt ); 853 d->mAddressees.remove( it.d->mIt );
854} 854}
855 855
856AddressBook::Iterator AddressBook::find( const Addressee &a ) 856AddressBook::Iterator AddressBook::find( const Addressee &a )
857{ 857{
858 Iterator it; 858 Iterator it;
859 for ( it = begin(); it != end(); ++it ) { 859 for ( it = begin(); it != end(); ++it ) {
860 if ( a.uid() == (*it).uid() ) { 860 if ( a.uid() == (*it).uid() ) {
861 return it; 861 return it;
862 } 862 }
863 } 863 }
864 return end(); 864 return end();
865} 865}
866 866
867Addressee AddressBook::findByUid( const QString &uid ) 867Addressee AddressBook::findByUid( const QString &uid )
868{ 868{
869 Iterator it; 869 Iterator it;
870 for ( it = begin(); it != end(); ++it ) { 870 for ( it = begin(); it != end(); ++it ) {
871 if ( uid == (*it).uid() ) { 871 if ( uid == (*it).uid() ) {
872 return *it; 872 return *it;
873 } 873 }
874 } 874 }
875 return Addressee(); 875 return Addressee();
876} 876}
877void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 877void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
878{ 878{
879 //qDebug("AddressBook::preExternSync "); 879 //qDebug("AddressBook::preExternSync ");
880 AddressBook::Iterator it; 880 AddressBook::Iterator it;
881 for ( it = begin(); it != end(); ++it ) { 881 for ( it = begin(); it != end(); ++it ) {
882 (*it).setID( csd, (*it).externalUID() ); 882 (*it).setID( csd, (*it).externalUID() );
883 (*it).computeCsum( csd ); 883 (*it).computeCsum( csd );
884 } 884 }
885 mergeAB( aBook ,csd, isSubset ); 885 mergeAB( aBook ,csd, isSubset );
886} 886}
887void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 887void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
888{ 888{
889 //qDebug("AddressBook::postExternSync "); 889 //qDebug("AddressBook::postExternSync ");
890 AddressBook::Iterator it; 890 AddressBook::Iterator it;
891 for ( it = begin(); it != end(); ++it ) { 891 for ( it = begin(); it != end(); ++it ) {
892 // qDebug("check uid %s ", (*it).uid().latin1() ); 892 // qDebug("check uid %s ", (*it).uid().latin1() );
893 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 893 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
894 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 894 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
895 Addressee ad = aBook->findByUid( ( (*it).uid() )); 895 Addressee ad = aBook->findByUid( ( (*it).uid() ));
896 if ( ad.isEmpty() ) { 896 if ( ad.isEmpty() ) {
897 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 897 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
898 } else { 898 } else {
899 (*it).computeCsum( csd ); 899 (*it).computeCsum( csd );
900 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 900 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
901 ad.setID( csd, (*it).externalUID() ); 901 ad.setID( csd, (*it).externalUID() );
902 ad.setCsum( csd, (*it).getCsum( csd ) ); 902 ad.setCsum( csd, (*it).getCsum( csd ) );
903 aBook->insertAddressee( ad ); 903 aBook->insertAddressee( ad );
904 } 904 }
905 } 905 }
906 } 906 }
907} 907}
908 908
909bool AddressBook::containsExternalUid( const QString& uid ) 909bool AddressBook::containsExternalUid( const QString& uid )
910{ 910{
911 Iterator it; 911 Iterator it;
912 for ( it = begin(); it != end(); ++it ) { 912 for ( it = begin(); it != end(); ++it ) {
913 if ( uid == (*it).externalUID( ) ) 913 if ( uid == (*it).externalUID( ) )
914 return true; 914 return true;
915 } 915 }
916 return false; 916 return false;
917} 917}
918Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 918Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
919{ 919{
920 Iterator it; 920 Iterator it;
921 for ( it = begin(); it != end(); ++it ) { 921 for ( it = begin(); it != end(); ++it ) {
922 if ( uid == (*it).getID( profile ) ) 922 if ( uid == (*it).getID( profile ) )
923 return (*it); 923 return (*it);
924 } 924 }
925 return Addressee(); 925 return Addressee();
926} 926}
927void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 927void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
928{ 928{
929 Iterator it; 929 Iterator it;
930 Addressee ad; 930 Addressee ad;
931 for ( it = begin(); it != end(); ++it ) { 931 for ( it = begin(); it != end(); ++it ) {
932 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 932 ad = aBook->findByExternUid( (*it).externalUID(), profile );
933 if ( !ad.isEmpty() ) { 933 if ( !ad.isEmpty() ) {
934 (*it).mergeContact( ad ,isSubset); 934 (*it).mergeContact( ad ,isSubset);
935 } 935 }
936 } 936 }
937#if 0 937#if 0
938 // test only 938 // test only
939 for ( it = begin(); it != end(); ++it ) { 939 for ( it = begin(); it != end(); ++it ) {
940 940
941 qDebug("uid %s ", (*it).uid().latin1()); 941 qDebug("uid %s ", (*it).uid().latin1());
942 } 942 }
943#endif 943#endif
944} 944}
945 945
946#if 0 946#if 0
947Addressee::List AddressBook::getExternLastSyncAddressees() 947Addressee::List AddressBook::getExternLastSyncAddressees()
948{ 948{
949 Addressee::List results; 949 Addressee::List results;
950 950
951 Iterator it; 951 Iterator it;
952 for ( it = begin(); it != end(); ++it ) { 952 for ( it = begin(); it != end(); ++it ) {
953 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 953 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
954 if ( (*it).familyName().left(4) == "!E: " ) 954 if ( (*it).familyName().left(4) == "!E: " )
955 results.append( *it ); 955 results.append( *it );
956 } 956 }
957 } 957 }
958 958
959 return results; 959 return results;
960} 960}
961#endif 961#endif
962void AddressBook::resetTempSyncStat() 962void AddressBook::resetTempSyncStat()
963{ 963{
964 Iterator it; 964 Iterator it;
965 for ( it = begin(); it != end(); ++it ) { 965 for ( it = begin(); it != end(); ++it ) {
966 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 966 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
967 } 967 }
968 968
969} 969}
970 970
971QStringList AddressBook:: uidList() 971QStringList AddressBook:: uidList()
972{ 972{
973 QStringList results; 973 QStringList results;
974 Iterator it; 974 Iterator it;
975 for ( it = begin(); it != end(); ++it ) { 975 for ( it = begin(); it != end(); ++it ) {
976 results.append( (*it).uid() ); 976 results.append( (*it).uid() );
977 } 977 }
978 return results; 978 return results;
979} 979}
980 980
981 981
982Addressee::List AddressBook::allAddressees() 982Addressee::List AddressBook::allAddressees()
983{ 983{
984 return d->mAddressees; 984 return d->mAddressees;
985 985
986} 986}
987 987
988Addressee::List AddressBook::findByName( const QString &name ) 988Addressee::List AddressBook::findByName( const QString &name )
989{ 989{
990 Addressee::List results; 990 Addressee::List results;
991 991
992 Iterator it; 992 Iterator it;
993 for ( it = begin(); it != end(); ++it ) { 993 for ( it = begin(); it != end(); ++it ) {
994 if ( name == (*it).realName() ) { 994 if ( name == (*it).realName() ) {
995 results.append( *it ); 995 results.append( *it );
996 } 996 }
997 } 997 }
998 998
999 return results; 999 return results;
1000} 1000}
1001 1001
1002Addressee::List AddressBook::findByEmail( const QString &email ) 1002Addressee::List AddressBook::findByEmail( const QString &email )
1003{ 1003{
1004 Addressee::List results; 1004 Addressee::List results;
1005 QStringList mailList; 1005 QStringList mailList;
1006 1006
1007 Iterator it; 1007 Iterator it;
1008 for ( it = begin(); it != end(); ++it ) { 1008 for ( it = begin(); it != end(); ++it ) {
1009 mailList = (*it).emails(); 1009 mailList = (*it).emails();
1010 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1010 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1011 if ( email == (*ite) ) { 1011 if ( email == (*ite) ) {
1012 results.append( *it ); 1012 results.append( *it );
1013 } 1013 }
1014 } 1014 }
1015 } 1015 }
1016 1016
1017 return results; 1017 return results;
1018} 1018}
1019 1019
1020Addressee::List AddressBook::findByCategory( const QString &category ) 1020Addressee::List AddressBook::findByCategory( const QString &category )
1021{ 1021{
1022 Addressee::List results; 1022 Addressee::List results;
1023 1023
1024 Iterator it; 1024 Iterator it;
1025 for ( it = begin(); it != end(); ++it ) { 1025 for ( it = begin(); it != end(); ++it ) {
1026 if ( (*it).hasCategory( category) ) { 1026 if ( (*it).hasCategory( category) ) {
1027 results.append( *it ); 1027 results.append( *it );
1028 } 1028 }
1029 } 1029 }
1030 1030
1031 return results; 1031 return results;
1032} 1032}
1033 1033
1034void AddressBook::dump() const 1034void AddressBook::dump() const
1035{ 1035{
1036 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1036 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1037 1037
1038 ConstIterator it; 1038 ConstIterator it;
1039 for( it = begin(); it != end(); ++it ) { 1039 for( it = begin(); it != end(); ++it ) {
1040 (*it).dump(); 1040 (*it).dump();
1041 } 1041 }
1042 1042
1043 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1043 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1044} 1044}
1045 1045
1046QString AddressBook::identifier() 1046QString AddressBook::identifier()
1047{ 1047{
1048 QStringList identifier; 1048 QStringList identifier;
1049 1049
1050 1050
1051 KRES::Manager<Resource>::ActiveIterator it; 1051 KRES::Manager<Resource>::ActiveIterator it;
1052 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1052 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1053 if ( !(*it)->identifier().isEmpty() ) 1053 if ( !(*it)->identifier().isEmpty() )
1054 identifier.append( (*it)->identifier() ); 1054 identifier.append( (*it)->identifier() );
1055 } 1055 }
1056 1056
1057 return identifier.join( ":" ); 1057 return identifier.join( ":" );
1058} 1058}
1059 1059
1060Field::List AddressBook::fields( int category ) 1060Field::List AddressBook::fields( int category )
1061{ 1061{
1062 if ( d->mAllFields.isEmpty() ) { 1062 if ( d->mAllFields.isEmpty() ) {
1063 d->mAllFields = Field::allFields(); 1063 d->mAllFields = Field::allFields();
1064 } 1064 }
1065 1065
1066 if ( category == Field::All ) return d->mAllFields; 1066 if ( category == Field::All ) return d->mAllFields;
1067 1067
1068 Field::List result; 1068 Field::List result;
1069 Field::List::ConstIterator it; 1069 Field::List::ConstIterator it;
1070 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1070 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1071 if ( (*it)->category() & category ) result.append( *it ); 1071 if ( (*it)->category() & category ) result.append( *it );
1072 } 1072 }
1073 1073
1074 return result; 1074 return result;
1075} 1075}
1076 1076
1077bool AddressBook::addCustomField( const QString &label, int category, 1077bool AddressBook::addCustomField( const QString &label, int category,
1078 const QString &key, const QString &app ) 1078 const QString &key, const QString &app )
1079{ 1079{
1080 if ( d->mAllFields.isEmpty() ) { 1080 if ( d->mAllFields.isEmpty() ) {
1081 d->mAllFields = Field::allFields(); 1081 d->mAllFields = Field::allFields();
1082 } 1082 }
1083//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1083//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1084 QString a = app.isNull() ? KGlobal::getAppName() : app; 1084 QString a = app.isNull() ? KGlobal::getAppName() : app;
1085 1085
1086 QString k = key.isNull() ? label : key; 1086 QString k = key.isNull() ? label : key;
1087 1087
1088 Field *field = Field::createCustomField( label, category, k, a ); 1088 Field *field = Field::createCustomField( label, category, k, a );
1089 1089
1090 if ( !field ) return false; 1090 if ( !field ) return false;
1091 1091
1092 d->mAllFields.append( field ); 1092 d->mAllFields.append( field );
1093 1093
1094 return true; 1094 return true;
1095} 1095}
1096 1096
1097QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1097QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1098{ 1098{
1099 if (!ab.d) return s; 1099 if (!ab.d) return s;
1100 1100
1101 return s << ab.d->mAddressees; 1101 return s << ab.d->mAddressees;
1102} 1102}
1103 1103
1104QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1104QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1105{ 1105{
1106 if (!ab.d) return s; 1106 if (!ab.d) return s;
1107 1107
1108 s >> ab.d->mAddressees; 1108 s >> ab.d->mAddressees;
1109 1109
1110 return s; 1110 return s;
1111} 1111}
1112 1112
1113bool AddressBook::addResource( Resource *resource ) 1113bool AddressBook::addResource( Resource *resource )
1114{ 1114{
1115 if ( !resource->open() ) { 1115 if ( !resource->open() ) {
1116 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1116 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1117 return false; 1117 return false;
1118 } 1118 }
1119 1119
1120 resource->setAddressBook( this ); 1120 resource->setAddressBook( this );
1121 1121
1122 d->mManager->add( resource ); 1122 d->mManager->add( resource );
1123 return true; 1123 return true;
1124} 1124}
1125 1125
1126bool AddressBook::removeResource( Resource *resource ) 1126bool AddressBook::removeResource( Resource *resource )
1127{ 1127{
1128 resource->close(); 1128 resource->close();
1129 1129
1130 if ( resource == standardResource() ) 1130 if ( resource == standardResource() )
1131 d->mManager->setStandardResource( 0 ); 1131 d->mManager->setStandardResource( 0 );
1132 1132
1133 resource->setAddressBook( 0 ); 1133 resource->setAddressBook( 0 );
1134 1134
1135 d->mManager->remove( resource ); 1135 d->mManager->remove( resource );
1136 return true; 1136 return true;
1137} 1137}
1138 1138
1139QPtrList<Resource> AddressBook::resources() 1139QPtrList<Resource> AddressBook::resources()
1140{ 1140{
1141 QPtrList<Resource> list; 1141 QPtrList<Resource> list;
1142 1142
1143// qDebug("AddressBook::resources() 1"); 1143// qDebug("AddressBook::resources() 1");
1144 1144
1145 KRES::Manager<Resource>::ActiveIterator it; 1145 KRES::Manager<Resource>::ActiveIterator it;
1146 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1146 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1147 list.append( *it ); 1147 list.append( *it );
1148 1148
1149 return list; 1149 return list;
1150} 1150}
1151 1151
1152/*US 1152/*US
1153void AddressBook::setErrorHandler( ErrorHandler *handler ) 1153void AddressBook::setErrorHandler( ErrorHandler *handler )
1154{ 1154{
1155 delete d->mErrorHandler; 1155 delete d->mErrorHandler;
1156 d->mErrorHandler = handler; 1156 d->mErrorHandler = handler;
1157} 1157}
1158*/ 1158*/
1159 1159
1160void AddressBook::error( const QString& msg ) 1160void AddressBook::error( const QString& msg )
1161{ 1161{
1162/*US 1162/*US
1163 if ( !d->mErrorHandler ) // create default error handler 1163 if ( !d->mErrorHandler ) // create default error handler
1164 d->mErrorHandler = new ConsoleErrorHandler; 1164 d->mErrorHandler = new ConsoleErrorHandler;
1165 1165
1166 if ( d->mErrorHandler ) 1166 if ( d->mErrorHandler )
1167 d->mErrorHandler->error( msg ); 1167 d->mErrorHandler->error( msg );
1168 else 1168 else
1169 kdError(5700) << "no error handler defined" << endl; 1169 kdError(5700) << "no error handler defined" << endl;
1170*/ 1170*/
1171 kdDebug(5700) << "msg" << endl; 1171 kdDebug(5700) << "msg" << endl;
1172 qDebug(msg); 1172 qDebug(msg);
1173} 1173}
1174 1174
1175void AddressBook::deleteRemovedAddressees() 1175void AddressBook::deleteRemovedAddressees()
1176{ 1176{
1177 Addressee::List::Iterator it; 1177 Addressee::List::Iterator it;
1178 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1178 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1179 Resource *resource = (*it).resource(); 1179 Resource *resource = (*it).resource();
1180 if ( resource && !resource->readOnly() && resource->isOpen() ) 1180 if ( resource && !resource->readOnly() && resource->isOpen() )
1181 resource->removeAddressee( *it ); 1181 resource->removeAddressee( *it );
1182 } 1182 }
1183 1183
1184 d->mRemovedAddressees.clear(); 1184 d->mRemovedAddressees.clear();
1185} 1185}
1186 1186
1187void AddressBook::setStandardResource( Resource *resource ) 1187void AddressBook::setStandardResource( Resource *resource )
1188{ 1188{
1189// qDebug("AddressBook::setStandardResource 1"); 1189// qDebug("AddressBook::setStandardResource 1");
1190 d->mManager->setStandardResource( resource ); 1190 d->mManager->setStandardResource( resource );
1191} 1191}
1192 1192
1193Resource *AddressBook::standardResource() 1193Resource *AddressBook::standardResource()
1194{ 1194{
1195 return d->mManager->standardResource(); 1195 return d->mManager->standardResource();
1196} 1196}
1197 1197
1198KRES::Manager<Resource> *AddressBook::resourceManager() 1198KRES::Manager<Resource> *AddressBook::resourceManager()
1199{ 1199{
1200 return d->mManager; 1200 return d->mManager;
1201} 1201}
1202 1202
1203void AddressBook::cleanUp() 1203void AddressBook::cleanUp()
1204{ 1204{
1205 KRES::Manager<Resource>::ActiveIterator it; 1205 KRES::Manager<Resource>::ActiveIterator it;
1206 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1206 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1207 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1207 if ( !(*it)->readOnly() && (*it)->isOpen() )
1208 (*it)->cleanUp(); 1208 (*it)->cleanUp();
1209 } 1209 }
1210} 1210}
diff --git a/kabc/kabcE.pro b/kabc/kabcE.pro
index 061909b..96fe39e 100644
--- a/kabc/kabcE.pro
+++ b/kabc/kabcE.pro
@@ -1,198 +1,196 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3TARGET = kamicrokabc 3TARGET = kamicrokabc
4 4
5 5
6INCLUDEPATH += . $(KDEPIMDIR) vcard/include vcard/include/generated $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kdeui $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/libkdepim $(KDEPIMDIR)/qtcompat $(QPEDIR)/include 6INCLUDEPATH += . $(KDEPIMDIR) vcard/include vcard/include/generated $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kdeui $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/libkdepim $(KDEPIMDIR)/qtcompat $(QPEDIR)/include
7OBJECTS_DIR = obj/$(PLATFORM) 7OBJECTS_DIR = obj/$(PLATFORM)
8MOC_DIR = moc/$(PLATFORM) 8MOC_DIR = moc/$(PLATFORM)
9DESTDIR = $(QPEDIR)/lib 9DESTDIR = $(QPEDIR)/lib
10LIBS += -lmicrokde 10LIBS += -lmicrokde
11LIBS += -lmicrokdepim 11LIBS += -lmicrokdepim
12#LIBS += -lldap 12#LIBS += -lldap
13LIBS += -L$(QPEDIR)/lib 13LIBS += -L$(QPEDIR)/lib
14DEFINES += KAB_EMBEDDED 14DEFINES += KAB_EMBEDDED
15 15
16#enable the following line if you want to get debugoutput while loading adresses 16#enable the following line if you want to get debugoutput while loading adresses
17#DEFINES += VCARD_DEBUG 17#DEFINES += VCARD_DEBUG
18 18
19INTERFACES = \ 19INTERFACES = \
20 20
21HEADERS = \ 21HEADERS = \
22 address.h \ 22 address.h \
23 addressbook.h \ 23 addressbook.h \
24 addressee.h \ 24 addressee.h \
25 addresseedialog.h \ 25 addresseedialog.h \
26 addresseelist.h \ 26 addresseelist.h \
27 addresseeview.h \ 27 addresseeview.h \
28 agent.h \ 28 agent.h \
29 distributionlist.h \ 29 distributionlist.h \
30 distributionlistdialog.h \ 30 distributionlistdialog.h \
31 distributionlisteditor.h \ 31 distributionlisteditor.h \
32 field.h \ 32 field.h \
33 formatfactory.h \ 33 formatfactory.h \
34 formatplugin.h \ 34 formatplugin.h \
35 geo.h \ 35 geo.h \
36 key.h \ 36 key.h \
37 phonenumber.h \ 37 phonenumber.h \
38 picture.h \ 38 picture.h \
39 plugin.h \ 39 plugin.h \
40 resource.h \ 40 resource.h \
41 secrecy.h \ 41 secrecy.h \
42 sound.h \ 42 sound.h \
43 stdaddressbook.h \ 43 stdaddressbook.h \
44 syncprefwidget.h \
45 timezone.h \ 44 timezone.h \
46 tmpaddressbook.h \ 45 tmpaddressbook.h \
47 vcardconverter.h \ 46 vcardconverter.h \
48 vcard21parser.h \ 47 vcard21parser.h \
49 vcardformatimpl.h \ 48 vcardformatimpl.h \
50 vcardformatplugin.h \ 49 vcardformatplugin.h \
51 vcardparser/vcardline.h \ 50 vcardparser/vcardline.h \
52 vcardparser/vcard.h \ 51 vcardparser/vcard.h \
53 vcardparser/vcardtool.h \ 52 vcardparser/vcardtool.h \
54 vcardparser/vcardparser.h \ 53 vcardparser/vcardparser.h \
55 vcard/include/VCardAdrParam.h \ 54 vcard/include/VCardAdrParam.h \
56 vcard/include/VCardAdrValue.h \ 55 vcard/include/VCardAdrValue.h \
57 vcard/include/VCardAgentParam.h \ 56 vcard/include/VCardAgentParam.h \
58 vcard/include/VCardContentLine.h \ 57 vcard/include/VCardContentLine.h \
59 vcard/include/VCardDateParam.h \ 58 vcard/include/VCardDateParam.h \
60 vcard/include/VCardDateValue.h \ 59 vcard/include/VCardDateValue.h \
61 vcard/include/VCardEmailParam.h \ 60 vcard/include/VCardEmailParam.h \
62 vcard/include/VCardGeoValue.h \ 61 vcard/include/VCardGeoValue.h \
63 vcard/include/VCardGroup.h \ 62 vcard/include/VCardGroup.h \
64 vcard/include/VCardImageParam.h \ 63 vcard/include/VCardImageParam.h \
65 vcard/include/VCardImageValue.h \ 64 vcard/include/VCardImageValue.h \
66 vcard/include/VCardLangValue.h \ 65 vcard/include/VCardLangValue.h \
67 vcard/include/VCardNValue.h \ 66 vcard/include/VCardNValue.h \
68 vcard/include/VCardParam.h \ 67 vcard/include/VCardParam.h \
69 vcard/include/VCardPhoneNumberValue.h \ 68 vcard/include/VCardPhoneNumberValue.h \
70 vcard/include/VCardSourceParam.h \ 69 vcard/include/VCardSourceParam.h \
71 vcard/include/VCardTelParam.h \ 70 vcard/include/VCardTelParam.h \
72 vcard/include/VCardTextParam.h \ 71 vcard/include/VCardTextParam.h \
73 vcard/include/VCardTextNSParam.h \ 72 vcard/include/VCardTextNSParam.h \
74 vcard/include/VCardTextValue.h \ 73 vcard/include/VCardTextValue.h \
75 vcard/include/VCardTextBinParam.h \ 74 vcard/include/VCardTextBinParam.h \
76 vcard/include/VCardURIValue.h \ 75 vcard/include/VCardURIValue.h \
77 vcard/include/VCardVCard.h \ 76 vcard/include/VCardVCard.h \
78 vcard/include/VCardEntity.h \ 77 vcard/include/VCardEntity.h \
79 vcard/include/VCardValue.h \ 78 vcard/include/VCardValue.h \
80 vcard/include/VCardSoundValue.h \ 79 vcard/include/VCardSoundValue.h \
81 vcard/include/VCardAgentValue.h \ 80 vcard/include/VCardAgentValue.h \
82 vcard/include/VCardTelValue.h \ 81 vcard/include/VCardTelValue.h \
83 vcard/include/VCardTextBinValue.h \ 82 vcard/include/VCardTextBinValue.h \
84 vcard/include/VCardOrgValue.h \ 83 vcard/include/VCardOrgValue.h \
85 vcard/include/VCardUTCValue.h \ 84 vcard/include/VCardUTCValue.h \
86 vcard/include/VCardClassValue.h \ 85 vcard/include/VCardClassValue.h \
87 vcard/include/VCardFloatValue.h \ 86 vcard/include/VCardFloatValue.h \
88 vcard/include/VCardTextListValue.h \ 87 vcard/include/VCardTextListValue.h \
89 vcard/include/generated/AdrParam-generated.h \ 88 vcard/include/generated/AdrParam-generated.h \
90 vcard/include/generated/AdrValue-generated.h \ 89 vcard/include/generated/AdrValue-generated.h \
91 vcard/include/generated/AgentParam-generated.h \ 90 vcard/include/generated/AgentParam-generated.h \
92 vcard/include/generated/ContentLine-generated.h \ 91 vcard/include/generated/ContentLine-generated.h \
93 vcard/include/generated/DateParam-generated.h \ 92 vcard/include/generated/DateParam-generated.h \
94 vcard/include/generated/DateValue-generated.h \ 93 vcard/include/generated/DateValue-generated.h \
95 vcard/include/generated/EmailParam-generated.h \ 94 vcard/include/generated/EmailParam-generated.h \
96 vcard/include/generated/GeoValue-generated.h \ 95 vcard/include/generated/GeoValue-generated.h \
97 vcard/include/generated/Group-generated.h \ 96 vcard/include/generated/Group-generated.h \
98 vcard/include/generated/ImageParam-generated.h \ 97 vcard/include/generated/ImageParam-generated.h \
99 vcard/include/generated/ImageValue-generated.h \ 98 vcard/include/generated/ImageValue-generated.h \
100 vcard/include/generated/LangValue-generated.h \ 99 vcard/include/generated/LangValue-generated.h \
101 vcard/include/generated/NValue-generated.h \ 100 vcard/include/generated/NValue-generated.h \
102 vcard/include/generated/Param-generated.h \ 101 vcard/include/generated/Param-generated.h \
103 vcard/include/generated/PhoneNumberValue-generated.h \ 102 vcard/include/generated/PhoneNumberValue-generated.h \
104 vcard/include/generated/SourceParam-generated.h \ 103 vcard/include/generated/SourceParam-generated.h \
105 vcard/include/generated/TelParam-generated.h \ 104 vcard/include/generated/TelParam-generated.h \
106 vcard/include/generated/TextParam-generated.h \ 105 vcard/include/generated/TextParam-generated.h \
107 vcard/include/generated/TextNSParam-generated.h \ 106 vcard/include/generated/TextNSParam-generated.h \
108 vcard/include/generated/TextValue-generated.h \ 107 vcard/include/generated/TextValue-generated.h \
109 vcard/include/generated/TextBinParam-generated.h \ 108 vcard/include/generated/TextBinParam-generated.h \
110 vcard/include/generated/URIValue-generated.h \ 109 vcard/include/generated/URIValue-generated.h \
111 vcard/include/generated/VCard-generated.h \ 110 vcard/include/generated/VCard-generated.h \
112 vcard/include/generated/VCardEntity-generated.h \ 111 vcard/include/generated/VCardEntity-generated.h \
113 vcard/include/generated/Value-generated.h \ 112 vcard/include/generated/Value-generated.h \
114 vcard/include/generated/SoundValue-generated.h \ 113 vcard/include/generated/SoundValue-generated.h \
115 vcard/include/generated/AgentValue-generated.h \ 114 vcard/include/generated/AgentValue-generated.h \
116 vcard/include/generated/TelValue-generated.h \ 115 vcard/include/generated/TelValue-generated.h \
117 vcard/include/generated/TextBinValue-generated.h \ 116 vcard/include/generated/TextBinValue-generated.h \
118 vcard/include/generated/OrgValue-generated.h \ 117 vcard/include/generated/OrgValue-generated.h \
119 vcard/include/generated/UTCValue-generated.h \ 118 vcard/include/generated/UTCValue-generated.h \
120 vcard/include/generated/ClassValue-generated.h \ 119 vcard/include/generated/ClassValue-generated.h \
121 vcard/include/generated/FloatValue-generated.h \ 120 vcard/include/generated/FloatValue-generated.h \
122 vcard/include/generated/TextListValue-generated.h 121 vcard/include/generated/TextListValue-generated.h
123 122
124 123
125 124
126 125
127SOURCES = \ 126SOURCES = \
128 address.cpp \ 127 address.cpp \
129 addressbook.cpp \ 128 addressbook.cpp \
130 addressee.cpp \ 129 addressee.cpp \
131 addresseedialog.cpp \ 130 addresseedialog.cpp \
132 addresseelist.cpp \ 131 addresseelist.cpp \
133 addresseeview.cpp \ 132 addresseeview.cpp \
134 agent.cpp \ 133 agent.cpp \
135 distributionlist.cpp \ 134 distributionlist.cpp \
136 distributionlistdialog.cpp \ 135 distributionlistdialog.cpp \
137 distributionlisteditor.cpp \ 136 distributionlisteditor.cpp \
138 field.cpp \ 137 field.cpp \
139 formatfactory.cpp \ 138 formatfactory.cpp \
140 geo.cpp \ 139 geo.cpp \
141 key.cpp \ 140 key.cpp \
142 phonenumber.cpp \ 141 phonenumber.cpp \
143 picture.cpp \ 142 picture.cpp \
144 plugin.cpp \ 143 plugin.cpp \
145 resource.cpp \ 144 resource.cpp \
146 secrecy.cpp \ 145 secrecy.cpp \
147 sound.cpp \ 146 sound.cpp \
148 stdaddressbook.cpp \ 147 stdaddressbook.cpp \
149 syncprefwidget.cpp \
150 timezone.cpp \ 148 timezone.cpp \
151 tmpaddressbook.cpp \ 149 tmpaddressbook.cpp \
152 vcardconverter.cpp \ 150 vcardconverter.cpp \
153 vcard21parser.cpp \ 151 vcard21parser.cpp \
154 vcardformatimpl.cpp \ 152 vcardformatimpl.cpp \
155 vcardformatplugin.cpp \ 153 vcardformatplugin.cpp \
156 vcardparser/vcardline.cpp \ 154 vcardparser/vcardline.cpp \
157 vcardparser/vcard.cpp \ 155 vcardparser/vcard.cpp \
158 vcardparser/vcardtool.cpp \ 156 vcardparser/vcardtool.cpp \
159 vcardparser/vcardparser.cpp \ 157 vcardparser/vcardparser.cpp \
160vcard/AdrParam.cpp \ 158vcard/AdrParam.cpp \
161vcard/AdrValue.cpp \ 159vcard/AdrValue.cpp \
162vcard/AgentParam.cpp \ 160vcard/AgentParam.cpp \
163vcard/ContentLine.cpp \ 161vcard/ContentLine.cpp \
164vcard/DateParam.cpp \ 162vcard/DateParam.cpp \
165vcard/DateValue.cpp \ 163vcard/DateValue.cpp \
166vcard/EmailParam.cpp \ 164vcard/EmailParam.cpp \
167vcard/Entity.cpp \ 165vcard/Entity.cpp \
168vcard/Enum.cpp \ 166vcard/Enum.cpp \
169vcard/GeoValue.cpp \ 167vcard/GeoValue.cpp \
170vcard/ImageParam.cpp \ 168vcard/ImageParam.cpp \
171vcard/ImageValue.cpp \ 169vcard/ImageValue.cpp \
172vcard/LangValue.cpp \ 170vcard/LangValue.cpp \
173vcard/NValue.cpp \ 171vcard/NValue.cpp \
174vcard/Param.cpp \ 172vcard/Param.cpp \
175vcard/PhoneNumberValue.cpp \ 173vcard/PhoneNumberValue.cpp \
176vcard/RToken.cpp \ 174vcard/RToken.cpp \
177vcard/SourceParam.cpp \ 175vcard/SourceParam.cpp \
178vcard/TelParam.cpp \ 176vcard/TelParam.cpp \
179vcard/TextParam.cpp \ 177vcard/TextParam.cpp \
180vcard/TextValue.cpp \ 178vcard/TextValue.cpp \
181vcard/TextBinParam.cpp \ 179vcard/TextBinParam.cpp \
182vcard/URIValue.cpp \ 180vcard/URIValue.cpp \
183vcard/VCardv.cpp \ 181vcard/VCardv.cpp \
184vcard/VCardEntity.cpp \ 182vcard/VCardEntity.cpp \
185vcard/Value.cpp \ 183vcard/Value.cpp \
186vcard/SoundValue.cpp \ 184vcard/SoundValue.cpp \
187vcard/AgentValue.cpp \ 185vcard/AgentValue.cpp \
188vcard/TelValue.cpp \ 186vcard/TelValue.cpp \
189vcard/TextBinValue.cpp \ 187vcard/TextBinValue.cpp \
190vcard/OrgValue.cpp \ 188vcard/OrgValue.cpp \
191vcard/UTCValue.cpp \ 189vcard/UTCValue.cpp \
192vcard/ClassValue.cpp \ 190vcard/ClassValue.cpp \
193vcard/FloatValue.cpp \ 191vcard/FloatValue.cpp \
194vcard/TextListValue.cpp 192vcard/TextListValue.cpp
195 193
196 194
197# plugins/ldap/resourceldap.cpp \ 195# plugins/ldap/resourceldap.cpp \
198# plugins/ldap/resourceldapconfig.cpp \ 196# plugins/ldap/resourceldapconfig.cpp \
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index e58e4f7..e2b7b08 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -1,375 +1,374 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@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 28
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31#ifndef _WIN32_ 31#ifndef _WIN32_
32#include <unistd.h> 32#include <unistd.h>
33#endif 33#endif
34 34
35#include <qregexp.h> 35#include <qregexp.h>
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qwidget.h> 37#include <qwidget.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42//US #include <kgenericfactory.h> 42//US #include <kgenericfactory.h>
43#include <kglobal.h> 43#include <kglobal.h>
44#include <klocale.h> 44#include <klocale.h>
45#include <kstandarddirs.h> 45#include <kstandarddirs.h>
46#include <kurlrequester.h> 46#include <kurlrequester.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48 48
49#include "addressbook.h" 49#include "addressbook.h"
50 50
51#include "formatfactory.h" 51#include "formatfactory.h"
52 52
53#include "resourcedirconfig.h" 53#include "resourcedirconfig.h"
54#include "stdaddressbook.h" 54#include "stdaddressbook.h"
55 55
56//US 56//US
57#include <qdir.h> 57#include <qdir.h>
58 58
59#define NO_DIRWATCH 59#define NO_DIRWATCH
60#include "resourcedir.h" 60#include "resourcedir.h"
61#include "syncprefwidget.h"
62 61
63//#define ALLOW_LOCKING 62//#define ALLOW_LOCKING
64 63
65using namespace KABC; 64using namespace KABC;
66 65
67extern "C" 66extern "C"
68#ifdef _WIN32_ 67#ifdef _WIN32_
69__declspec(dllexport) 68__declspec(dllexport)
70#else 69#else
71{ 70{
72#endif 71#endif
73 72
74//US void *init_kabc_dir() 73//US void *init_kabc_dir()
75 void *init_microkabc_dir() 74 void *init_microkabc_dir()
76 { 75 {
77 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>(); 76 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
78 } 77 }
79#ifndef _WIN32_ 78#ifndef _WIN32_
80} 79}
81#endif 80#endif
82 81
83ResourceDir::ResourceDir( const KConfig *config, bool syncable ) 82ResourceDir::ResourceDir( const KConfig *config )
84 : Resource( config, syncable ) 83 : Resource( config )
85{ 84{
86 QString path; 85 QString path;
87 86
88 KConfig *cfg = (KConfig *)config; 87 KConfig *cfg = (KConfig *)config;
89 if ( cfg ) { 88 if ( cfg ) {
90//US path = config->readEntry( "FilePath" ); 89//US path = config->readEntry( "FilePath" );
91 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); 90 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() );
92//US mFormatName = config->readEntry( "FileFormat" ); 91//US mFormatName = config->readEntry( "FileFormat" );
93 mFormatName = cfg->readEntry( "FileFormat", "vcard" ); 92 mFormatName = cfg->readEntry( "FileFormat", "vcard" );
94 } else { 93 } else {
95 path = StdAddressBook::directoryName(); 94 path = StdAddressBook::directoryName();
96 mFormatName = "vcard"; 95 mFormatName = "vcard";
97 } 96 }
98 97
99 98
100 FormatFactory *factory = FormatFactory::self(); 99 FormatFactory *factory = FormatFactory::self();
101 mFormat = factory->format( mFormatName ); 100 mFormat = factory->format( mFormatName );
102 101
103 if ( !mFormat ) { 102 if ( !mFormat ) {
104 mFormatName = "vcard"; 103 mFormatName = "vcard";
105 mFormat = factory->format( mFormatName ); 104 mFormat = factory->format( mFormatName );
106 } 105 }
107 106
108/*US 107/*US
109//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); 108//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
110 if (mFormatName == "vcard") 109 if (mFormatName == "vcard")
111 mFormat = new VCardFormatPlugin2(); 110 mFormat = new VCardFormatPlugin2();
112 else if (mFormatName == "binary") 111 else if (mFormatName == "binary")
113 mFormat = new BinaryFormat(); 112 mFormat = new BinaryFormat();
114 else 113 else
115 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); 114 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
116*/ 115*/
117#ifndef NO_DIRWATCH 116#ifndef NO_DIRWATCH
118 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); 117 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
119 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); 118 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
120 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); 119 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
121#endif 120#endif
122 setPath( path ); 121 setPath( path );
123} 122}
124 123
125ResourceDir::~ResourceDir() 124ResourceDir::~ResourceDir()
126{ 125{
127 delete mFormat; 126 delete mFormat;
128 mFormat = 0; 127 mFormat = 0;
129} 128}
130 129
131void ResourceDir::writeConfig( KConfig *config ) 130void ResourceDir::writeConfig( KConfig *config )
132{ 131{
133 config->setGroup( "Resource_" + identifier() ); 132 config->setGroup( "Resource_" + identifier() );
134 Resource::writeConfig( config ); 133 Resource::writeConfig( config );
135 134
136 config->writeEntry( "FilePath", mPath ); 135 config->writeEntry( "FilePath", mPath );
137 config->writeEntry( "FileFormat", mFormatName ); 136 config->writeEntry( "FileFormat", mFormatName );
138} 137}
139 138
140Ticket *ResourceDir::requestSaveTicket() 139Ticket *ResourceDir::requestSaveTicket()
141{ 140{
142 141
143 142
144 if ( !addressBook() ) return 0; 143 if ( !addressBook() ) return 0;
145#ifdef ALLOW_LOCKING 144#ifdef ALLOW_LOCKING
146 if ( !lock( mPath ) ) { 145 if ( !lock( mPath ) ) {
147 146
148 return 0; 147 return 0;
149 } 148 }
150#endif 149#endif
151 return createTicket( this ); 150 return createTicket( this );
152 151
153} 152}
154 153
155 154
156bool ResourceDir::doOpen() 155bool ResourceDir::doOpen()
157{ 156{
158 QDir dir( mPath ); 157 QDir dir( mPath );
159 if ( !dir.exists() ) { // no directory available 158 if ( !dir.exists() ) { // no directory available
160 return dir.mkdir( dir.path() ); 159 return dir.mkdir( dir.path() );
161 } else { 160 } else {
162 QString testName = dir.entryList( QDir::Files )[0]; 161 QString testName = dir.entryList( QDir::Files )[0];
163 if ( testName.isNull() || testName.isEmpty() ) // no file in directory 162 if ( testName.isNull() || testName.isEmpty() ) // no file in directory
164 return true; 163 return true;
165 164
166 QFile file( mPath + "/" + testName ); 165 QFile file( mPath + "/" + testName );
167 if ( file.open( IO_ReadOnly ) ) 166 if ( file.open( IO_ReadOnly ) )
168 return true; 167 return true;
169 168
170 if ( file.size() == 0 ) 169 if ( file.size() == 0 )
171 return true; 170 return true;
172 171
173 bool ok = mFormat->checkFormat( &file ); 172 bool ok = mFormat->checkFormat( &file );
174 file.close(); 173 file.close();
175 return ok; 174 return ok;
176 } 175 }
177} 176}
178 177
179void ResourceDir::doClose() 178void ResourceDir::doClose()
180{ 179{
181} 180}
182 181
183bool ResourceDir::load() 182bool ResourceDir::load()
184{ 183{
185 QDir dir( mPath ); 184 QDir dir( mPath );
186 QStringList files = dir.entryList( QDir::Files ); 185 QStringList files = dir.entryList( QDir::Files );
187 186
188 QStringList::Iterator it; 187 QStringList::Iterator it;
189 bool ok = true; 188 bool ok = true;
190 for ( it = files.begin(); it != files.end(); ++it ) { 189 for ( it = files.begin(); it != files.end(); ++it ) {
191 QFile file( mPath + "/" + (*it) ); 190 QFile file( mPath + "/" + (*it) );
192 191
193 if ( !file.open( IO_ReadOnly ) ) { 192 if ( !file.open( IO_ReadOnly ) ) {
194 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); 193 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
195 ok = false; 194 ok = false;
196 continue; 195 continue;
197 } 196 }
198 197
199 if ( !mFormat->loadAll( addressBook(), this, &file ) ) 198 if ( !mFormat->loadAll( addressBook(), this, &file ) )
200 ok = false; 199 ok = false;
201 200
202 file.close(); 201 file.close();
203 } 202 }
204 203
205 return ok; 204 return ok;
206} 205}
207 206
208bool ResourceDir::save( Ticket *ticket ) 207bool ResourceDir::save( Ticket *ticket )
209{ 208{
210 AddressBook::Iterator it; 209 AddressBook::Iterator it;
211 bool ok = true; 210 bool ok = true;
212#ifndef NO_DIRWATCH 211#ifndef NO_DIRWATCH
213 mDirWatch.stopScan(); 212 mDirWatch.stopScan();
214#endif 213#endif
215 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 214 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
216 if ( (*it).resource() != this || !(*it).changed() ) 215 if ( (*it).resource() != this || !(*it).changed() )
217 continue; 216 continue;
218 217
219 QFile file( mPath + "/" + (*it).uid() ); 218 QFile file( mPath + "/" + (*it).uid() );
220 if ( !file.open( IO_WriteOnly ) ) { 219 if ( !file.open( IO_WriteOnly ) ) {
221 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); 220 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) );
222 continue; 221 continue;
223 } 222 }
224 223
225 mFormat->save( *it, &file ); 224 mFormat->save( *it, &file );
226 225
227 // mark as unchanged 226 // mark as unchanged
228 (*it).setChanged( false ); 227 (*it).setChanged( false );
229 228
230 file.close(); 229 file.close();
231 } 230 }
232#ifndef NO_DIRWATCH 231#ifndef NO_DIRWATCH
233 mDirWatch.startScan(); 232 mDirWatch.startScan();
234#endif 233#endif
235 delete ticket; 234 delete ticket;
236#ifdef ALLOW_LOCKING 235#ifdef ALLOW_LOCKING
237 unlock( mPath ); 236 unlock( mPath );
238#endif 237#endif
239 return ok; 238 return ok;
240} 239}
241 240
242bool ResourceDir::lock( const QString &path ) 241bool ResourceDir::lock( const QString &path )
243{ 242{
244#ifdef ALLOW_LOCKING 243#ifdef ALLOW_LOCKING
245 QString p = path; 244 QString p = path;
246//US change the implementation how the lockfilename is getting created 245//US change the implementation how the lockfilename is getting created
247//US p.replace( QRegExp("/"), "_" ); 246//US p.replace( QRegExp("/"), "_" );
248//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); 247//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
249 KURL url(p); 248 KURL url(p);
250 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 249 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
251 250
252 251
253 if ( QFile::exists( lockName ) ) return false; 252 if ( QFile::exists( lockName ) ) return false;
254 253
255 QString lockUniqueName; 254 QString lockUniqueName;
256 lockUniqueName = p + KApplication::randomString( 8 ); 255 lockUniqueName = p + KApplication::randomString( 8 );
257 256
258 url = lockUniqueName; 257 url = lockUniqueName;
259//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 258//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
260 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 259 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
261 260
262 // Create unique file 261 // Create unique file
263 QFile file( mLockUniqueName ); 262 QFile file( mLockUniqueName );
264 file.open( IO_WriteOnly ); 263 file.open( IO_WriteOnly );
265 file.close(); 264 file.close();
266 265
267 // Create lock file 266 // Create lock file
268 int result = 0; 267 int result = 0;
269#ifndef _WIN32_ 268#ifndef _WIN32_
270 result = ::link( QFile::encodeName( mLockUniqueName ), 269 result = ::link( QFile::encodeName( mLockUniqueName ),
271 QFile::encodeName( lockName ) ); 270 QFile::encodeName( lockName ) );
272#endif 271#endif
273 if ( result == 0 ) { 272 if ( result == 0 ) {
274 addressBook()->emitAddressBookLocked(); 273 addressBook()->emitAddressBookLocked();
275 return true; 274 return true;
276 } 275 }
277 276
278 // TODO: check stat 277 // TODO: check stat
279 278
280 return false; 279 return false;
281#else 280#else
282 return true; 281 return true;
283#endif 282#endif
284} 283}
285 284
286void ResourceDir::unlock( const QString &path ) 285void ResourceDir::unlock( const QString &path )
287{ 286{
288#ifdef ALLOW_LOCKING 287#ifdef ALLOW_LOCKING
289 QString p = path; 288 QString p = path;
290//US change the implementation how the lockfilename is getting created 289//US change the implementation how the lockfilename is getting created
291//US p.replace( QRegExp( "/" ), "_" ); 290//US p.replace( QRegExp( "/" ), "_" );
292//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); 291//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" );
293 KURL url(p); 292 KURL url(p);
294 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); 293 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" );
295 294
296 ::unlink( QFile::encodeName( lockName ) ); 295 ::unlink( QFile::encodeName( lockName ) );
297 QFile::remove( mLockUniqueName ); 296 QFile::remove( mLockUniqueName );
298 addressBook()->emitAddressBookUnlocked(); 297 addressBook()->emitAddressBookUnlocked();
299#else 298#else
300 return; 299 return;
301#endif 300#endif
302} 301}
303 302
304void ResourceDir::setPath( const QString &path ) 303void ResourceDir::setPath( const QString &path )
305{ 304{
306#ifndef NO_DIRWATCH 305#ifndef NO_DIRWATCH
307 mDirWatch.stopScan(); 306 mDirWatch.stopScan();
308 mDirWatch.removeDir( mPath ); 307 mDirWatch.removeDir( mPath );
309 308
310 mPath = path; 309 mPath = path;
311 310
312 mDirWatch.addDir( mPath, true ); 311 mDirWatch.addDir( mPath, true );
313 mDirWatch.startScan(); 312 mDirWatch.startScan();
314#else 313#else
315 mPath = path; 314 mPath = path;
316#endif 315#endif
317//US simulate KDirWatch event 316//US simulate KDirWatch event
318//US pathChanged(); 317//US pathChanged();
319 318
320} 319}
321 320
322QString ResourceDir::path() const 321QString ResourceDir::path() const
323{ 322{
324 return mPath; 323 return mPath;
325} 324}
326 325
327void ResourceDir::setFormat( const QString &format ) 326void ResourceDir::setFormat( const QString &format )
328{ 327{
329 mFormatName = format; 328 mFormatName = format;
330 329
331 if ( mFormat ) 330 if ( mFormat )
332 delete mFormat; 331 delete mFormat;
333 332
334 FormatFactory *factory = FormatFactory::self(); 333 FormatFactory *factory = FormatFactory::self();
335 mFormat = factory->format( mFormatName ); 334 mFormat = factory->format( mFormatName );
336/*US 335/*US
337qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); 336qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
338 if (mFormatName == "vcard") 337 if (mFormatName == "vcard")
339 mFormat = new VCardFormatPlugin2(); 338 mFormat = new VCardFormatPlugin2();
340 else if (mFormatName == "binary") 339 else if (mFormatName == "binary")
341 mFormat = new BinaryFormat(); 340 mFormat = new BinaryFormat();
342 else 341 else
343 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); 342 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1());
344*/ 343*/
345 344
346} 345}
347 346
348QString ResourceDir::format() const 347QString ResourceDir::format() const
349{ 348{
350 return mFormatName; 349 return mFormatName;
351} 350}
352 351
353void ResourceDir::pathChanged() 352void ResourceDir::pathChanged()
354{ 353{
355 if ( !addressBook() ) 354 if ( !addressBook() )
356 return; 355 return;
357 356
358 QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); 357 QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) );
359 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 358 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
360 load(); 359 load();
361 addressBook()->emitAddressBookChanged(); 360 addressBook()->emitAddressBookChanged();
362 } 361 }
363} 362}
364 363
365void ResourceDir::removeAddressee( const Addressee& addr ) 364void ResourceDir::removeAddressee( const Addressee& addr )
366{ 365{
367 QFile::remove( mPath + "/" + addr.uid() ); 366 QFile::remove( mPath + "/" + addr.uid() );
368} 367}
369 368
370void ResourceDir::cleanUp() 369void ResourceDir::cleanUp()
371{ 370{
372 unlock( mPath ); 371 unlock( mPath );
373} 372}
374 373
375//US #include "resourcedir.moc" 374//US #include "resourcedir.moc"
diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h
index 77cd18c..6c1e922 100644
--- a/kabc/plugins/dir/resourcedir.h
+++ b/kabc/plugins/dir/resourcedir.h
@@ -1,116 +1,116 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@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_RESOURCEDIR_H 28#ifndef KABC_RESOURCEDIR_H
29#define KABC_RESOURCEDIR_H 29#define KABC_RESOURCEDIR_H
30 30
31#include <kconfig.h> 31#include <kconfig.h>
32#include <kdirwatch.h> 32#include <kdirwatch.h>
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35 35
36#include "resource.h" 36#include "resource.h"
37 37
38class QTimer; 38class QTimer;
39 39
40namespace KABC { 40namespace KABC {
41 41
42class FormatPlugin; 42class FormatPlugin;
43 43
44/** 44/**
45 @internal 45 @internal
46*/ 46*/
47class ResourceDir : public Resource 47class ResourceDir : public Resource
48{ 48{
49 Q_OBJECT 49 Q_OBJECT
50 50
51public: 51public:
52 ResourceDir( const KConfig*, bool syncable ); 52 ResourceDir( const KConfig* );
53 ~ResourceDir(); 53 ~ResourceDir();
54 54
55 virtual void writeConfig( KConfig* ); 55 virtual void writeConfig( KConfig* );
56 56
57 virtual bool doOpen(); 57 virtual bool doOpen();
58 virtual void doClose(); 58 virtual void doClose();
59 59
60 virtual Ticket *requestSaveTicket(); 60 virtual Ticket *requestSaveTicket();
61 61
62 virtual bool load(); 62 virtual bool load();
63 virtual bool save( Ticket * ); 63 virtual bool save( Ticket * );
64 64
65 /** 65 /**
66 * Set path to be used for saving. 66 * Set path to be used for saving.
67 */ 67 */
68 void setPath( const QString & ); 68 void setPath( const QString & );
69 69
70 /** 70 /**
71 * Return path used for loading and saving the address book. 71 * Return path used for loading and saving the address book.
72 */ 72 */
73 QString path() const; 73 QString path() const;
74 74
75 /** 75 /**
76 * Set the format by name. 76 * Set the format by name.
77 */ 77 */
78 void setFormat( const QString &format ); 78 void setFormat( const QString &format );
79 79
80 /** 80 /**
81 * Returns the format name. 81 * Returns the format name.
82 */ 82 */
83 QString format() const; 83 QString format() const;
84 84
85 /** 85 /**
86 * Remove a addressee from its source. 86 * Remove a addressee from its source.
87 * This method is mainly called by KABC::AddressBook. 87 * This method is mainly called by KABC::AddressBook.
88 */ 88 */
89 virtual void removeAddressee( const Addressee& addr ); 89 virtual void removeAddressee( const Addressee& addr );
90 90
91 /** 91 /**
92 * This method is called by an error handler if the application 92 * This method is called by an error handler if the application
93 * crashed 93 * crashed
94 */ 94 */
95 virtual void cleanUp(); 95 virtual void cleanUp();
96 96
97protected slots: 97protected slots:
98 void pathChanged(); 98 void pathChanged();
99 99
100protected: 100protected:
101 bool lock( const QString &path ); 101 bool lock( const QString &path );
102 void unlock( const QString &path ); 102 void unlock( const QString &path );
103 103
104private: 104private:
105 FormatPlugin *mFormat; 105 FormatPlugin *mFormat;
106 106
107#ifndef NO_DIRWATCH 107#ifndef NO_DIRWATCH
108 KDirWatch mDirWatch; 108 KDirWatch mDirWatch;
109#endif 109#endif
110 QString mPath; 110 QString mPath;
111 QString mFormatName; 111 QString mFormatName;
112 QString mLockUniqueName; 112 QString mLockUniqueName;
113}; 113};
114 114
115} 115}
116#endif 116#endif
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 163f2b4..dc5932f 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -1,408 +1,404 @@
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#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#ifndef _WIN32_ 30#ifndef _WIN32_
31#include <unistd.h> 31#include <unistd.h>
32#endif 32#endif
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qregexp.h> 36#include <qregexp.h>
37#include <qtimer.h> 37#include <qtimer.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <klocale.h> 42#include <klocale.h>
43//US #include <ksavefile.h> 43//US #include <ksavefile.h>
44#include <kstandarddirs.h> 44#include <kstandarddirs.h>
45#include <kmessagebox.h> 45#include <kmessagebox.h>
46 46
47#include "formatfactory.h" 47#include "formatfactory.h"
48 48
49#include "resource.h" 49#include "resource.h"
50#include "resourcefileconfig.h" 50#include "resourcefileconfig.h"
51#include "stdaddressbook.h" 51#include "stdaddressbook.h"
52#define NO_DIRWATCH 52#define NO_DIRWATCH
53#include "resourcefile.h" 53#include "resourcefile.h"
54#include "syncprefwidget.h"
55 54
56//#define ALLOW_LOCKING 55//#define ALLOW_LOCKING
57 56
58 57
59 58
60using namespace KABC; 59using namespace KABC;
61 60
62extern "C" 61extern "C"
63#ifdef _WIN32_ 62#ifdef _WIN32_
64__declspec(dllexport) 63__declspec(dllexport)
65#else 64#else
66{ 65{
67#endif 66#endif
68 67
69//US void *init_kabc_file() 68//US void *init_kabc_file()
70 void *init_microkabc_file() 69 void *init_microkabc_file()
71 { 70 {
72 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); 71 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
73 } 72 }
74#ifndef _WIN32_ 73#ifndef _WIN32_
75} 74}
76#endif 75#endif
77 76
78ResourceFile::ResourceFile( const KConfig *config, bool syncable ) 77ResourceFile::ResourceFile( const KConfig *config )
79 : Resource( config, syncable ) , mFormat( 0 ) 78 : Resource( config ) , mFormat( 0 )
80{ 79{
81 QString fileName, formatName, default_fileName; 80 QString fileName, formatName, default_fileName;
82 81
83 if (syncable == true) 82 default_fileName = StdAddressBook::fileName();
84 default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf";
85 else
86 default_fileName = StdAddressBook::fileName();
87 83
88 KConfig *cfg = (KConfig *)config; 84 KConfig *cfg = (KConfig *)config;
89 if ( cfg ) { 85 if ( cfg ) {
90 fileName = cfg->readEntry( "FileName", default_fileName ); 86 fileName = cfg->readEntry( "FileName", default_fileName );
91 formatName = cfg->readEntry( "FileFormat", "vcard" ); 87 formatName = cfg->readEntry( "FileFormat", "vcard" );
92 } else { 88 } else {
93 fileName = default_fileName; 89 fileName = default_fileName;
94 formatName = "vcard"; 90 formatName = "vcard";
95 } 91 }
96 92
97 init( fileName, formatName ); 93 init( fileName, formatName );
98} 94}
99 95
100ResourceFile::ResourceFile( const QString &fileName, bool syncable , 96ResourceFile::ResourceFile( const QString &fileName ,
101 const QString &formatName ) 97 const QString &formatName )
102 : Resource( 0, syncable ) 98 : Resource( 0 )
103{ 99{
104// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 100// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
105 init( fileName, formatName ); 101 init( fileName, formatName );
106} 102}
107 103
108void ResourceFile::init( const QString &fileName, const QString &formatName ) 104void ResourceFile::init( const QString &fileName, const QString &formatName )
109{ 105{
110 mFormatName = formatName; 106 mFormatName = formatName;
111 107
112 FormatFactory *factory = FormatFactory::self(); 108 FormatFactory *factory = FormatFactory::self();
113 mFormat = factory->format( mFormatName ); 109 mFormat = factory->format( mFormatName );
114 110
115 if ( !mFormat ) { 111 if ( !mFormat ) {
116 mFormatName = "vcard"; 112 mFormatName = "vcard";
117 mFormat = factory->format( mFormatName ); 113 mFormat = factory->format( mFormatName );
118 } 114 }
119 115
120#ifndef NO_DIRWATCH 116#ifndef NO_DIRWATCH
121 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 117 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
122 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 118 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
123 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 119 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
124#endif 120#endif
125 setFileName( fileName ); 121 setFileName( fileName );
126} 122}
127 123
128ResourceFile::~ResourceFile() 124ResourceFile::~ResourceFile()
129{ 125{
130 delete mFormat; 126 delete mFormat;
131 mFormat = 0; 127 mFormat = 0;
132} 128}
133 129
134void ResourceFile::writeConfig( KConfig *config ) 130void ResourceFile::writeConfig( KConfig *config )
135{ 131{
136 132
137 config->setGroup( "Resource_" + identifier() ); 133 config->setGroup( "Resource_" + identifier() );
138 Resource::writeConfig( config ); 134 Resource::writeConfig( config );
139 135
140 config->writeEntry( "FileName", mFileName ); 136 config->writeEntry( "FileName", mFileName );
141 config->writeEntry( "FileFormat", mFormatName ); 137 config->writeEntry( "FileFormat", mFormatName );
142 138
143// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 139// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
144 140
145} 141}
146 142
147Ticket *ResourceFile::requestSaveTicket() 143Ticket *ResourceFile::requestSaveTicket()
148{ 144{
149 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 145 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
150 146
151 if ( !addressBook() ) return 0; 147 if ( !addressBook() ) return 0;
152 148
153#ifdef ALLOW_LOCKING 149#ifdef ALLOW_LOCKING
154 if ( !lock( mFileName ) ) { 150 if ( !lock( mFileName ) ) {
155 qDebug("unablt to lock file "); 151 qDebug("unablt to lock file ");
156 return 0; 152 return 0;
157 } 153 }
158#endif 154#endif
159 return createTicket( this ); 155 return createTicket( this );
160} 156}
161 157
162 158
163bool ResourceFile::doOpen() 159bool ResourceFile::doOpen()
164{ 160{
165 QFile file( mFileName ); 161 QFile file( mFileName );
166 qDebug("ResourceFile::openfile %s ", mFileName.latin1()); 162 qDebug("ResourceFile::openfile %s ", mFileName.latin1());
167 163
168 if ( !file.exists() ) { 164 if ( !file.exists() ) {
169 // try to create the file 165 // try to create the file
170 bool ok = file.open( IO_WriteOnly ); 166 bool ok = file.open( IO_WriteOnly );
171 if ( ok ) 167 if ( ok )
172 file.close(); 168 file.close();
173 169
174 return ok; 170 return ok;
175 } else { 171 } else {
176 if ( !file.open( IO_ReadWrite ) ) 172 if ( !file.open( IO_ReadWrite ) )
177 return false; 173 return false;
178 174
179 if ( file.size() == 0 ) { 175 if ( file.size() == 0 ) {
180 file.close(); 176 file.close();
181 return true; 177 return true;
182 } 178 }
183 179
184 bool ok = mFormat->checkFormat( &file ); 180 bool ok = mFormat->checkFormat( &file );
185 file.close(); 181 file.close();
186 182
187 return ok; 183 return ok;
188 } 184 }
189} 185}
190 186
191void ResourceFile::doClose() 187void ResourceFile::doClose()
192{ 188{
193} 189}
194 190
195bool ResourceFile::load() 191bool ResourceFile::load()
196{ 192{
197 193
198 QFile file( mFileName ); 194 QFile file( mFileName );
199 if ( !file.open( IO_ReadOnly ) ) { 195 if ( !file.open( IO_ReadOnly ) ) {
200 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); 196 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
201 return false; 197 return false;
202 } 198 }
203 199
204// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 200// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
205 201
206 return mFormat->loadAll( addressBook(), this, &file ); 202 return mFormat->loadAll( addressBook(), this, &file );
207} 203}
208 204
209bool ResourceFile::save( Ticket *ticket ) 205bool ResourceFile::save( Ticket *ticket )
210{ 206{
211// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 207// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
212 208
213 209
214 // create backup file 210 // create backup file
215 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 211 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
216 212
217/*US we use a simpler method to create a backupfile 213/*US we use a simpler method to create a backupfile
218 214
219 (void) KSaveFile::backupFile( mFileName, QString::null 215 (void) KSaveFile::backupFile( mFileName, QString::null
220 ,extension ); 216 ,extension );
221 217
222 KSaveFile saveFile( mFileName ); 218 KSaveFile saveFile( mFileName );
223 bool ok = false; 219 bool ok = false;
224 if ( saveFile.status() == 0 && saveFile.file() ) 220 if ( saveFile.status() == 0 && saveFile.file() )
225 { 221 {
226 mFormat->saveAll( addressBook(), this, saveFile.file() ); 222 mFormat->saveAll( addressBook(), this, saveFile.file() );
227 ok = saveFile.close(); 223 ok = saveFile.close();
228 } 224 }
229*/ 225*/
230 226
231//US ToDo: write backupfile 227//US ToDo: write backupfile
232#ifndef NO_DIRWATCH 228#ifndef NO_DIRWATCH
233 mDirWatch.stopScan(); 229 mDirWatch.stopScan();
234#endif 230#endif
235 QFile info; 231 QFile info;
236 info.setName( mFileName ); 232 info.setName( mFileName );
237 bool ok = info.open( IO_WriteOnly ); 233 bool ok = info.open( IO_WriteOnly );
238 if ( ok ) { 234 if ( ok ) {
239 mFormat->saveAll( addressBook(), this, &info ); 235 mFormat->saveAll( addressBook(), this, &info );
240 236
241 info.close(); 237 info.close();
242 ok = true; 238 ok = true;
243 } 239 }
244 else { 240 else {
245 241
246 } 242 }
247 243
248 if ( !ok ) 244 if ( !ok )
249 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 245 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
250#ifndef NO_DIRWATCH 246#ifndef NO_DIRWATCH
251 mDirWatch.startScan(); 247 mDirWatch.startScan();
252#endif 248#endif
253 delete ticket; 249 delete ticket;
254#ifdef ALLOW_LOCKING 250#ifdef ALLOW_LOCKING
255 unlock( mFileName ); 251 unlock( mFileName );
256#endif 252#endif
257 253
258 return ok; 254 return ok;
259} 255}
260 256
261bool ResourceFile::lock( const QString &fileName ) 257bool ResourceFile::lock( const QString &fileName )
262{ 258{
263#ifdef ALLOW_LOCKING 259#ifdef ALLOW_LOCKING
264 260
265 261
266 QString fn = fileName; 262 QString fn = fileName;
267 263
268//US change the implementation how the lockfilename is getting created 264//US change the implementation how the lockfilename is getting created
269//US fn.replace( QRegExp("/"), "_" ); 265//US fn.replace( QRegExp("/"), "_" );
270//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 266//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
271 267
272 KURL url(fn); 268 KURL url(fn);
273 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 269 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
274 270
275 271
276 272
277 if (QFile::exists( lockName )) return false; 273 if (QFile::exists( lockName )) return false;
278 274
279 QString lockUniqueName; 275 QString lockUniqueName;
280 lockUniqueName = fn + KApplication::randomString( 8 ); 276 lockUniqueName = fn + KApplication::randomString( 8 );
281 277
282 url = lockUniqueName; 278 url = lockUniqueName;
283//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 279//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
284 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 280 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
285 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
286 282
287 // Create unique file 283 // Create unique file
288 QFile file( mLockUniqueName ); 284 QFile file( mLockUniqueName );
289 file.open( IO_WriteOnly ); 285 file.open( IO_WriteOnly );
290 file.close(); 286 file.close();
291 287
292 // Create lock file 288 // Create lock file
293 int result = 0; 289 int result = 0;
294#ifndef _WIN32_ 290#ifndef _WIN32_
295 result = ::link( QFile::encodeName( mLockUniqueName ), 291 result = ::link( QFile::encodeName( mLockUniqueName ),
296 QFile::encodeName( lockName ) ); 292 QFile::encodeName( lockName ) );
297#endif 293#endif
298 if ( result == 0 ) { 294 if ( result == 0 ) {
299 addressBook()->emitAddressBookLocked(); 295 addressBook()->emitAddressBookLocked();
300 return true; 296 return true;
301 } 297 }
302 298
303 // TODO: check stat 299 // TODO: check stat
304 300
305 return false; 301 return false;
306#else 302#else
307 return true; 303 return true;
308#endif 304#endif
309} 305}
310 306
311void ResourceFile::unlock( const QString &fileName ) 307void ResourceFile::unlock( const QString &fileName )
312{ 308{
313#ifdef ALLOW_LOCKING 309#ifdef ALLOW_LOCKING
314 QString fn = fileName; 310 QString fn = fileName;
315//US change the implementation how the lockfilename is getting created 311//US change the implementation how the lockfilename is getting created
316//US fn.replace( QRegExp( "/" ), "_" ); 312//US fn.replace( QRegExp( "/" ), "_" );
317//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 313//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
318//US QString lockName = fn + ".lock"; 314//US QString lockName = fn + ".lock";
319 KURL url(fn); 315 KURL url(fn);
320 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 316 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
321 317
322 QFile::remove( lockName ); 318 QFile::remove( lockName );
323 QFile::remove( mLockUniqueName ); 319 QFile::remove( mLockUniqueName );
324 addressBook()->emitAddressBookUnlocked(); 320 addressBook()->emitAddressBookUnlocked();
325#else 321#else
326 return; 322 return;
327#endif 323#endif
328} 324}
329 325
330void ResourceFile::setFileName( const QString &fileName ) 326void ResourceFile::setFileName( const QString &fileName )
331{ 327{
332#ifndef NO_DIRWATCH 328#ifndef NO_DIRWATCH
333 mDirWatch.stopScan(); 329 mDirWatch.stopScan();
334 mDirWatch.removeFile( mFileName ); 330 mDirWatch.removeFile( mFileName );
335 mFileName = fileName; 331 mFileName = fileName;
336 332
337 333
338 mDirWatch.addFile( mFileName ); 334 mDirWatch.addFile( mFileName );
339 mDirWatch.startScan(); 335 mDirWatch.startScan();
340#else 336#else
341 mFileName = fileName; 337 mFileName = fileName;
342#endif 338#endif
343 339
344//US simulate KDirWatch event 340//US simulate KDirWatch event
345//US fileChanged(); 341//US fileChanged();
346} 342}
347 343
348QString ResourceFile::fileName() const 344QString ResourceFile::fileName() const
349{ 345{
350 return mFileName; 346 return mFileName;
351} 347}
352 348
353void ResourceFile::setFormat( const QString &format ) 349void ResourceFile::setFormat( const QString &format )
354{ 350{
355 mFormatName = format; 351 mFormatName = format;
356 delete mFormat; 352 delete mFormat;
357 353
358 FormatFactory *factory = FormatFactory::self(); 354 FormatFactory *factory = FormatFactory::self();
359 mFormat = factory->format( mFormatName ); 355 mFormat = factory->format( mFormatName );
360/*US 356/*US
361//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); 357//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
362 if (mFormatName == "vcard") { 358 if (mFormatName == "vcard") {
363 mFormat = new VCardFormatPlugin2(); 359 mFormat = new VCardFormatPlugin2();
364// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 360// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
365 } 361 }
366 else if (mFormatName == "binary") { 362 else if (mFormatName == "binary") {
367 mFormat = new BinaryFormat(); 363 mFormat = new BinaryFormat();
368// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 364// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
369 } 365 }
370 else 366 else
371 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); 367 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
372*/ 368*/
373 369
374} 370}
375 371
376QString ResourceFile::format() const 372QString ResourceFile::format() const
377{ 373{
378 return mFormatName; 374 return mFormatName;
379} 375}
380 376
381void ResourceFile::fileChanged() 377void ResourceFile::fileChanged()
382{ 378{
383 // There is a small theoretical chance that KDirWatch calls us before 379 // There is a small theoretical chance that KDirWatch calls us before
384 // we are fully constructed 380 // we are fully constructed
385 if (!addressBook()) 381 if (!addressBook())
386 return; 382 return;
387 383
388 384
389 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); 385 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) );
390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 386 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
391 load(); 387 load();
392 addressBook()->emitAddressBookChanged(); 388 addressBook()->emitAddressBookChanged();
393 } 389 }
394} 390}
395 391
396void ResourceFile::removeAddressee( const Addressee &addr ) 392void ResourceFile::removeAddressee( const Addressee &addr )
397{ 393{
398 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); 394 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
399 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); 395 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
400 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); 396 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
401} 397}
402 398
403void ResourceFile::cleanUp() 399void ResourceFile::cleanUp()
404{ 400{
405 unlock( mFileName ); 401 unlock( mFileName );
406} 402}
407 403
408//US #include "resourcefile.moc" 404//US #include "resourcefile.moc"
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h
index 8339340..b4421b2 100644
--- a/kabc/plugins/file/resourcefile.h
+++ b/kabc/plugins/file/resourcefile.h
@@ -1,163 +1,163 @@
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 28
29#ifndef KABC_RESOURCEFILE_H 29#ifndef KABC_RESOURCEFILE_H
30#define KABC_RESOURCEFILE_H 30#define KABC_RESOURCEFILE_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include <resource.h> 37#include <resource.h>
38 38
39class QTimer; 39class QTimer;
40class FormatPlugin; 40class FormatPlugin;
41 41
42namespace KABC { 42namespace KABC {
43 43
44//US class FormatPlugin; 44//US class FormatPlugin;
45class ResourceConfigWidget; 45class ResourceConfigWidget;
46 46
47/** 47/**
48 @internal 48 @internal
49*/ 49*/
50class ResourceFile : public Resource 50class ResourceFile : public Resource
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 55
56 /** 56 /**
57 Constructor. 57 Constructor.
58 58
59 @param cfg The config object where custom resource settings are stored. 59 @param cfg The config object where custom resource settings are stored.
60 */ 60 */
61 ResourceFile( const KConfig *cfg, bool syncable ); 61 ResourceFile( const KConfig *cfg );
62 62
63 /** 63 /**
64 Construct file resource on file @arg fileName using format @arg formatName. 64 Construct file resource on file @arg fileName using format @arg formatName.
65 */ 65 */
66 ResourceFile( const QString &fileName, bool syncable , const QString &formatName = "vcard" ); 66 ResourceFile( const QString &fileName , const QString &formatName = "vcard" );
67 67
68 /** 68 /**
69 * Destructor. 69 * Destructor.
70 */ 70 */
71 ~ResourceFile(); 71 ~ResourceFile();
72 72
73 /** 73 /**
74 Writes the config back. 74 Writes the config back.
75 */ 75 */
76 virtual void writeConfig( KConfig *cfg ); 76 virtual void writeConfig( KConfig *cfg );
77 77
78 /** 78 /**
79 * Tries to open the file and checks for the proper format. 79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load(). 80 * This method should be called before @ref load().
81 */ 81 */
82 virtual bool doOpen(); 82 virtual bool doOpen();
83 83
84 /** 84 /**
85 * Closes the file again. 85 * Closes the file again.
86 */ 86 */
87 virtual void doClose(); 87 virtual void doClose();
88 88
89 /** 89 /**
90 * Requests a save ticket, that is used by @ref save() 90 * Requests a save ticket, that is used by @ref save()
91 */ 91 */
92 virtual Ticket *requestSaveTicket(); 92 virtual Ticket *requestSaveTicket();
93 93
94 /** 94 /**
95 * Loads all addressees from file to the address book. 95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false. 96 * Returns true if all addressees could be loaded otherwise false.
97 */ 97 */
98 virtual bool load(); 98 virtual bool load();
99 99
100 /** 100 /**
101 * Saves all addresses from address book to file. 101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false. 102 * Returns true if all addressees could be saved otherwise false.
103 * 103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket() 104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */ 105 */
106 virtual bool save( Ticket *ticket ); 106 virtual bool save( Ticket *ticket );
107 107
108 /** 108 /**
109 * Set name of file to be used for saving. 109 * Set name of file to be used for saving.
110 */ 110 */
111 void setFileName( const QString & ); 111 void setFileName( const QString & );
112 112
113 /** 113 /**
114 * Return name of file used for loading and saving the address book. 114 * Return name of file used for loading and saving the address book.
115 */ 115 */
116 QString fileName() const; 116 QString fileName() const;
117 117
118 /** 118 /**
119 Sets a new format by name. 119 Sets a new format by name.
120 */ 120 */
121 void setFormat( const QString &name ); 121 void setFormat( const QString &name );
122 122
123 /** 123 /**
124 Returns the format name. 124 Returns the format name.
125 */ 125 */
126 QString format() const; 126 QString format() const;
127 127
128 /** 128 /**
129 * Remove a addressee from its source. 129 * Remove a addressee from its source.
130 * This method is mainly called by KABC::AddressBook. 130 * This method is mainly called by KABC::AddressBook.
131 */ 131 */
132 virtual void removeAddressee( const Addressee& addr ); 132 virtual void removeAddressee( const Addressee& addr );
133 133
134 /** 134 /**
135 * This method is called by an error handler if the application 135 * This method is called by an error handler if the application
136 * crashed 136 * crashed
137 */ 137 */
138 virtual void cleanUp(); 138 virtual void cleanUp();
139 139
140protected slots: 140protected slots:
141 void fileChanged(); 141 void fileChanged();
142 142
143protected: 143protected:
144 void init( const QString &fileName, const QString &format ); 144 void init( const QString &fileName, const QString &format );
145 145
146 bool lock( const QString &fileName ); 146 bool lock( const QString &fileName );
147 void unlock( const QString &fileName ); 147 void unlock( const QString &fileName );
148 148
149private: 149private:
150 QString mFileName; 150 QString mFileName;
151 QString mFormatName; 151 QString mFormatName;
152 152
153 FormatPlugin *mFormat; 153 FormatPlugin *mFormat;
154 154
155 QString mLockUniqueName; 155 QString mLockUniqueName;
156#ifndef NO_DIRWATCH 156#ifndef NO_DIRWATCH
157 KDirWatch mDirWatch; 157 KDirWatch mDirWatch;
158#endif 158#endif
159}; 159};
160 160
161} 161}
162 162
163#endif 163#endif
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp
index 17f115d..55c43af 100644
--- a/kabc/plugins/ldap/resourceldap.cpp
+++ b/kabc/plugins/ldap/resourceldap.cpp
@@ -1,445 +1,444 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@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#include <kdebug.h> 28#include <kdebug.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klineedit.h> 30#include <klineedit.h>
31#include <klocale.h> 31#include <klocale.h>
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kstringhandler.h> 33#include <kstringhandler.h>
34 34
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37#include "resourceldap.h" 37#include "resourceldap.h"
38#include "resourceldapconfig.h" 38#include "resourceldapconfig.h"
39#include "syncprefwidget.h"
40 39
41using namespace KABC; 40using namespace KABC;
42 41
43extern "C" 42extern "C"
44{ 43{
45//US void *init_kabc_ldap() 44//US void *init_kabc_ldap()
46 void *init_microkabc_ldap() 45 void *init_microkabc_ldap()
47 { 46 {
48 return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidgetContainer>(); 47 return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig>();
49 } 48 }
50} 49}
51 50
52void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); 51void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value );
53 52
54 53
55ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) 54ResourceLDAP::ResourceLDAP( const KConfig *config )
56 : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) 55 : Resource( config ), mPort( 389 ), mLdap( 0 )
57{ 56{
58 KConfig *cfg = (KConfig *)config; 57 KConfig *cfg = (KConfig *)config;
59 if ( cfg ) { 58 if ( cfg ) {
60 mUser = cfg->readEntry( "LdapUser" ); 59 mUser = cfg->readEntry( "LdapUser" );
61 mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); 60 mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) );
62 mDn = cfg->readEntry( "LdapDn" ); 61 mDn = cfg->readEntry( "LdapDn" );
63 mHost = cfg->readEntry( "LdapHost" ); 62 mHost = cfg->readEntry( "LdapHost" );
64 mPort = cfg->readNumEntry( "LdapPort", 389 ); 63 mPort = cfg->readNumEntry( "LdapPort", 389 );
65 mFilter = cfg->readEntry( "LdapFilter" ); 64 mFilter = cfg->readEntry( "LdapFilter" );
66 mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); 65 mAnonymous = cfg->readBoolEntry( "LdapAnonymous" );
67 66
68 QStringList attributes = cfg->readListEntry( "LdapAttributes" ); 67 QStringList attributes = cfg->readListEntry( "LdapAttributes" );
69 for ( uint pos = 0; pos < attributes.count(); pos += 2 ) 68 for ( uint pos = 0; pos < attributes.count(); pos += 2 )
70 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); 69 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] );
71 } 70 }
72 71
73 /** 72 /**
74 If you want to add new attributes, append them here, add a 73 If you want to add new attributes, append them here, add a
75 translation string in the ctor of AttributesDialog and 74 translation string in the ctor of AttributesDialog and
76 handle them in the load() method below. 75 handle them in the load() method below.
77 These are the default values from 76 These are the default values from
78 */ 77 */
79 if ( mAttributes.count() == 0 ) { 78 if ( mAttributes.count() == 0 ) {
80 mAttributes.insert( "commonName", "cn" ); 79 mAttributes.insert( "commonName", "cn" );
81 mAttributes.insert( "formattedName", "displayName" ); 80 mAttributes.insert( "formattedName", "displayName" );
82 mAttributes.insert( "familyName", "sn" ); 81 mAttributes.insert( "familyName", "sn" );
83 mAttributes.insert( "givenName", "givenName" ); 82 mAttributes.insert( "givenName", "givenName" );
84 mAttributes.insert( "mail", "mail" ); 83 mAttributes.insert( "mail", "mail" );
85 mAttributes.insert( "mailAlias", "" ); 84 mAttributes.insert( "mailAlias", "" );
86 mAttributes.insert( "phoneNumber", "telephoneNumber" ); 85 mAttributes.insert( "phoneNumber", "telephoneNumber" );
87 mAttributes.insert( "uid", "uid" ); 86 mAttributes.insert( "uid", "uid" );
88 } 87 }
89} 88}
90 89
91void ResourceLDAP::writeConfig( KConfig *config ) 90void ResourceLDAP::writeConfig( KConfig *config )
92{ 91{
93 Resource::writeConfig( config ); 92 Resource::writeConfig( config );
94 93
95 config->writeEntry( "LdapUser", mUser ); 94 config->writeEntry( "LdapUser", mUser );
96 config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); 95 config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) );
97 config->writeEntry( "LdapDn", mDn ); 96 config->writeEntry( "LdapDn", mDn );
98 config->writeEntry( "LdapHost", mHost ); 97 config->writeEntry( "LdapHost", mHost );
99 config->writeEntry( "LdapPort", mPort ); 98 config->writeEntry( "LdapPort", mPort );
100 config->writeEntry( "LdapFilter", mFilter ); 99 config->writeEntry( "LdapFilter", mFilter );
101 config->writeEntry( "LdapAnonymous", mAnonymous ); 100 config->writeEntry( "LdapAnonymous", mAnonymous );
102 101
103 QStringList attributes; 102 QStringList attributes;
104 QMap<QString, QString>::Iterator it; 103 QMap<QString, QString>::Iterator it;
105 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) 104 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it )
106 attributes << it.key() << it.data(); 105 attributes << it.key() << it.data();
107 106
108 config->writeEntry( "LdapAttributes", attributes ); 107 config->writeEntry( "LdapAttributes", attributes );
109} 108}
110 109
111Ticket *ResourceLDAP::requestSaveTicket() 110Ticket *ResourceLDAP::requestSaveTicket()
112{ 111{
113 if ( !addressBook() ) { 112 if ( !addressBook() ) {
114 kdDebug(5700) << "no addressbook" << endl; 113 kdDebug(5700) << "no addressbook" << endl;
115 return 0; 114 return 0;
116 } 115 }
117 116
118 return createTicket( this ); 117 return createTicket( this );
119} 118}
120 119
121bool ResourceLDAP::doOpen() 120bool ResourceLDAP::doOpen()
122{ 121{
123 if ( mLdap ) 122 if ( mLdap )
124 return false; 123 return false;
125 124
126 if ( !mPort ) 125 if ( !mPort )
127 mPort = 389; 126 mPort = 389;
128 127
129 mLdap = ldap_init( mHost.local8Bit(), mPort ); 128 mLdap = ldap_init( mHost.local8Bit(), mPort );
130 if ( !mLdap ) { 129 if ( !mLdap ) {
131 addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); 130 addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) );
132 return false; 131 return false;
133 } 132 }
134 133
135 if ( !mUser.isEmpty() && !mAnonymous ) { 134 if ( !mUser.isEmpty() && !mAnonymous ) {
136 if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { 135 if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) {
137 addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); 136 addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) );
138 return false; 137 return false;
139 } 138 }
140 139
141 kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; 140 kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl;
142 } else { 141 } else {
143 if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { 142 if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) {
144 addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); 143 addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) );
145 return false; 144 return false;
146 } 145 }
147 146
148 kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; 147 kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl;
149 } 148 }
150 149
151 int deref = LDAP_DEREF_ALWAYS; 150 int deref = LDAP_DEREF_ALWAYS;
152 if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { 151 if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) {
153 kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; 152 kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl;
154 return false; 153 return false;
155 } 154 }
156 155
157 if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { 156 if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) {
158 kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; 157 kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl;
159 return false; 158 return false;
160 } 159 }
161 160
162 return true; 161 return true;
163} 162}
164 163
165void ResourceLDAP::doClose() 164void ResourceLDAP::doClose()
166{ 165{
167 if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { 166 if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) {
168 kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; 167 kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl;
169 return; 168 return;
170 } 169 }
171 170
172 mLdap = 0; 171 mLdap = 0;
173} 172}
174 173
175bool ResourceLDAP::load() 174bool ResourceLDAP::load()
176{ 175{
177 LDAPMessage *res; 176 LDAPMessage *res;
178 LDAPMessage *msg; 177 LDAPMessage *msg;
179 BerElement *track; 178 BerElement *track;
180 char *names; 179 char *names;
181 char **values; 180 char **values;
182 181
183 char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; 182 char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ];
184 183
185 QMap<QString, QString>::Iterator it; 184 QMap<QString, QString>::Iterator it;
186 int i = 0; 185 int i = 0;
187 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { 186 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
188 if ( !it.data().isEmpty() ) { 187 if ( !it.data().isEmpty() ) {
189 unsigned int len = it.data().utf8().length(); 188 unsigned int len = it.data().utf8().length();
190 LdapSearchAttr[ i ] = new char[ len+1 ]; 189 LdapSearchAttr[ i ] = new char[ len+1 ];
191 memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); 190 memcpy( LdapSearchAttr[ i ], it.data().utf8(), len );
192 LdapSearchAttr[ i ][ len ] = 0; 191 LdapSearchAttr[ i ][ len ] = 0;
193 ++i; 192 ++i;
194 } 193 }
195 } 194 }
196 LdapSearchAttr[ i ] = 0; 195 LdapSearchAttr[ i ] = 0;
197 196
198 QString filter = mFilter; 197 QString filter = mFilter;
199 if ( filter.isEmpty() ) 198 if ( filter.isEmpty() )
200 filter = "cn=*"; 199 filter = "cn=*";
201 200
202 int result; 201 int result;
203 if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), 202 if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(),
204 LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { 203 LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) {
205 addressBook()->error( i18n( "Unable to search on server '%1': %2" ) 204 addressBook()->error( i18n( "Unable to search on server '%1': %2" )
206 .arg( mHost ) 205 .arg( mHost )
207 .arg( ldap_err2string( result ) ) ); 206 .arg( ldap_err2string( result ) ) );
208 207
209 for ( i = 0; LdapSearchAttr[ i ]; ++i ) 208 for ( i = 0; LdapSearchAttr[ i ]; ++i )
210 delete [] LdapSearchAttr[ i ]; 209 delete [] LdapSearchAttr[ i ];
211 delete [] LdapSearchAttr; 210 delete [] LdapSearchAttr;
212 211
213 return false; 212 return false;
214 } 213 }
215 214
216 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { 215 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) {
217 Addressee addr; 216 Addressee addr;
218 addr.setResource( this ); 217 addr.setResource( this );
219 for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { 218 for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) {
220 values = ldap_get_values( mLdap, msg, names ); 219 values = ldap_get_values( mLdap, msg, names );
221 for ( int i = 0; i < ldap_count_values( values ); ++i ) { 220 for ( int i = 0; i < ldap_count_values( values ); ++i ) {
222 QString name = QString::fromUtf8( names ).lower(); 221 QString name = QString::fromUtf8( names ).lower();
223 QString value = QString::fromUtf8( values[ i ] ); 222 QString value = QString::fromUtf8( values[ i ] );
224 223
225 if ( name == mAttributes[ "commonName" ].lower() ) { 224 if ( name == mAttributes[ "commonName" ].lower() ) {
226 if ( !addr.formattedName().isEmpty() ) { 225 if ( !addr.formattedName().isEmpty() ) {
227 QString fn = addr.formattedName(); 226 QString fn = addr.formattedName();
228 addr.setNameFromString( value ); 227 addr.setNameFromString( value );
229 addr.setFormattedName( fn ); 228 addr.setFormattedName( fn );
230 } else 229 } else
231 addr.setNameFromString( value ); 230 addr.setNameFromString( value );
232 } else if ( name == mAttributes[ "formattedName" ].lower() ) { 231 } else if ( name == mAttributes[ "formattedName" ].lower() ) {
233 addr.setFormattedName( value ); 232 addr.setFormattedName( value );
234 } else if ( name == mAttributes[ "givenName" ].lower() ) { 233 } else if ( name == mAttributes[ "givenName" ].lower() ) {
235 addr.setGivenName( value ); 234 addr.setGivenName( value );
236 } else if ( name == mAttributes[ "mail" ].lower() ) { 235 } else if ( name == mAttributes[ "mail" ].lower() ) {
237 addr.insertEmail( value, true ); 236 addr.insertEmail( value, true );
238 } else if ( name == mAttributes[ "mailAlias" ].lower() ) { 237 } else if ( name == mAttributes[ "mailAlias" ].lower() ) {
239 addr.insertEmail( value, false ); 238 addr.insertEmail( value, false );
240 } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { 239 } else if ( name == mAttributes[ "phoneNumber" ].lower() ) {
241 PhoneNumber phone; 240 PhoneNumber phone;
242 phone.setNumber( value ); 241 phone.setNumber( value );
243 addr.insertPhoneNumber( phone ); 242 addr.insertPhoneNumber( phone );
244 break; // read only the home number 243 break; // read only the home number
245 } else if ( name == mAttributes[ "familyName" ].lower() ) { 244 } else if ( name == mAttributes[ "familyName" ].lower() ) {
246 addr.setFamilyName( value ); 245 addr.setFamilyName( value );
247 } else if ( name == mAttributes[ "uid" ].lower() ) { 246 } else if ( name == mAttributes[ "uid" ].lower() ) {
248 addr.setUid( value ); 247 addr.setUid( value );
249 } 248 }
250 } 249 }
251 ldap_value_free( values ); 250 ldap_value_free( values );
252 } 251 }
253 ber_free( track, 0 ); 252 ber_free( track, 0 );
254 253
255 addressBook()->insertAddressee( addr ); 254 addressBook()->insertAddressee( addr );
256 } 255 }
257 256
258 ldap_msgfree( res ); 257 ldap_msgfree( res );
259 258
260 for ( i = 0; LdapSearchAttr[ i ]; ++i ) 259 for ( i = 0; LdapSearchAttr[ i ]; ++i )
261 delete [] LdapSearchAttr[ i ]; 260 delete [] LdapSearchAttr[ i ];
262 delete [] LdapSearchAttr; 261 delete [] LdapSearchAttr;
263 262
264 return true; 263 return true;
265} 264}
266 265
267bool ResourceLDAP::save( Ticket * ) 266bool ResourceLDAP::save( Ticket * )
268{ 267{
269 AddressBook::Iterator it; 268 AddressBook::Iterator it;
270 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 269 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
271 if ( (*it).resource() == this && (*it).changed() ) { 270 if ( (*it).resource() == this && (*it).changed() ) {
272 LDAPMod **mods = NULL; 271 LDAPMod **mods = NULL;
273 272
274 addModOp( &mods, "objectClass", "organizationalPerson" ); 273 addModOp( &mods, "objectClass", "organizationalPerson" );
275 addModOp( &mods, "objectClass", "person" ); 274 addModOp( &mods, "objectClass", "person" );
276 addModOp( &mods, "objectClass", "Top" ); 275 addModOp( &mods, "objectClass", "Top" );
277 addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() ); 276 addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() );
278 addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() ); 277 addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() );
279 addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() ); 278 addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() );
280 addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() ); 279 addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() );
281 addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() ); 280 addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() );
282 281
283 QStringList emails = (*it).emails(); 282 QStringList emails = (*it).emails();
284 QStringList::ConstIterator mailIt; 283 QStringList::ConstIterator mailIt;
285 bool first = true; 284 bool first = true;
286 for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) { 285 for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) {
287 if ( first ) { 286 if ( first ) {
288 addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) ); 287 addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) );
289 first = false; 288 first = false;
290 } else 289 } else
291 addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) ); 290 addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) );
292 } 291 }
293 292
294 PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home ); 293 PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home );
295 addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() ); 294 addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() );
296 295
297 QString dn = "cn=" + (*it).assembledName() + "," + mDn; 296 QString dn = "cn=" + (*it).assembledName() + "," + mDn;
298 297
299 int retval; 298 int retval;
300 if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS ) 299 if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS )
301 addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) ); 300 addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) );
302 301
303 ldap_mods_free( mods, 1 ); 302 ldap_mods_free( mods, 1 );
304 303
305 // mark as unchanged 304 // mark as unchanged
306 (*it).setChanged( false ); 305 (*it).setChanged( false );
307 } 306 }
308 } 307 }
309 308
310 return true; 309 return true;
311} 310}
312 311
313void ResourceLDAP::removeAddressee( const Addressee &addr ) 312void ResourceLDAP::removeAddressee( const Addressee &addr )
314{ 313{
315 LDAPMessage *res; 314 LDAPMessage *res;
316 LDAPMessage *msg; 315 LDAPMessage *msg;
317 316
318 QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter ); 317 QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter );
319 318
320 kdDebug(5700) << "ldap:removeAddressee" << filter << endl; 319 kdDebug(5700) << "ldap:removeAddressee" << filter << endl;
321 320
322 ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(), 321 ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(),
323 0, 0, &res ); 322 0, 0, &res );
324 323
325 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { 324 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) {
326 char *dn = ldap_get_dn( mLdap, msg ); 325 char *dn = ldap_get_dn( mLdap, msg );
327 kdDebug(5700) << "found " << dn << endl; 326 kdDebug(5700) << "found " << dn << endl;
328 if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS ) 327 if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS )
329 addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) ); 328 addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) );
330 ldap_memfree( dn ); 329 ldap_memfree( dn );
331 } 330 }
332 331
333 ldap_msgfree( res ); 332 ldap_msgfree( res );
334} 333}
335 334
336void ResourceLDAP::setUser( const QString &user ) 335void ResourceLDAP::setUser( const QString &user )
337{ 336{
338 mUser = user; 337 mUser = user;
339} 338}
340 339
341QString ResourceLDAP::user() const 340QString ResourceLDAP::user() const
342{ 341{
343 return mUser; 342 return mUser;
344} 343}
345 344
346void ResourceLDAP::setPassword( const QString &password ) 345void ResourceLDAP::setPassword( const QString &password )
347{ 346{
348 mPassword = password; 347 mPassword = password;
349} 348}
350 349
351QString ResourceLDAP::password() const 350QString ResourceLDAP::password() const
352{ 351{
353 return mPassword; 352 return mPassword;
354} 353}
355 354
356void ResourceLDAP::setDn( const QString &dn ) 355void ResourceLDAP::setDn( const QString &dn )
357{ 356{
358 mDn = dn; 357 mDn = dn;
359} 358}
360 359
361QString ResourceLDAP::dn() const 360QString ResourceLDAP::dn() const
362{ 361{
363 return mDn; 362 return mDn;
364} 363}
365 364
366void ResourceLDAP::setHost( const QString &host ) 365void ResourceLDAP::setHost( const QString &host )
367{ 366{
368 mHost = host; 367 mHost = host;
369} 368}
370 369
371QString ResourceLDAP::host() const 370QString ResourceLDAP::host() const
372{ 371{
373 return mHost; 372 return mHost;
374} 373}
375 374
376void ResourceLDAP::setPort( int port ) 375void ResourceLDAP::setPort( int port )
377{ 376{
378 mPort = port; 377 mPort = port;
379} 378}
380 379
381int ResourceLDAP::port() const 380int ResourceLDAP::port() const
382{ 381{
383 return mPort; 382 return mPort;
384} 383}
385 384
386void ResourceLDAP::setFilter( const QString &filter ) 385void ResourceLDAP::setFilter( const QString &filter )
387{ 386{
388 mFilter = filter; 387 mFilter = filter;
389} 388}
390 389
391QString ResourceLDAP::filter() const 390QString ResourceLDAP::filter() const
392{ 391{
393 return mFilter; 392 return mFilter;
394} 393}
395 394
396void ResourceLDAP::setIsAnonymous( bool value ) 395void ResourceLDAP::setIsAnonymous( bool value )
397{ 396{
398 mAnonymous = value; 397 mAnonymous = value;
399} 398}
400 399
401bool ResourceLDAP::isAnonymous() const 400bool ResourceLDAP::isAnonymous() const
402{ 401{
403 return mAnonymous; 402 return mAnonymous;
404} 403}
405 404
406void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes ) 405void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes )
407{ 406{
408 mAttributes = attributes; 407 mAttributes = attributes;
409} 408}
410 409
411QMap<QString, QString> ResourceLDAP::attributes() const 410QMap<QString, QString> ResourceLDAP::attributes() const
412{ 411{
413 return mAttributes; 412 return mAttributes;
414} 413}
415 414
416void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ) 415void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value )
417{ 416{
418 if ( value.isNull() ) 417 if ( value.isNull() )
419 return; 418 return;
420 419
421 LDAPMod**mods; 420 LDAPMod**mods;
422 421
423 mods = *pmods; 422 mods = *pmods;
424 423
425 uint i = 0; 424 uint i = 0;
426 if ( mods != 0 ) 425 if ( mods != 0 )
427 for ( ; mods[ i ] != 0; ++i ); 426 for ( ; mods[ i ] != 0; ++i );
428 427
429 if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) { 428 if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) {
430 kdError() << "ResourceLDAP: realloc" << endl; 429 kdError() << "ResourceLDAP: realloc" << endl;
431 return; 430 return;
432 } 431 }
433 432
434 *pmods = mods; 433 *pmods = mods;
435 mods[ i + 1 ] = 0; 434 mods[ i + 1 ] = 0;
436 435
437 mods[ i ] = new LDAPMod; 436 mods[ i ] = new LDAPMod;
438 437
439 mods[ i ]->mod_op = 0; 438 mods[ i ]->mod_op = 0;
440 mods[ i ]->mod_type = strdup( attr.utf8() ); 439 mods[ i ]->mod_type = strdup( attr.utf8() );
441 mods[ i ]->mod_values = new char*[ 2 ]; 440 mods[ i ]->mod_values = new char*[ 2 ];
442 mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() ); 441 mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() );
443 mods[ i ]->mod_values[ 1 ] = 0; 442 mods[ i ]->mod_values[ 1 ] = 0;
444} 443}
445 444
diff --git a/kabc/plugins/ldap/resourceldap.h b/kabc/plugins/ldap/resourceldap.h
index 0aad3c1..0625f30 100644
--- a/kabc/plugins/ldap/resourceldap.h
+++ b/kabc/plugins/ldap/resourceldap.h
@@ -1,99 +1,99 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@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_RESOURCELDAP_H 28#ifndef KABC_RESOURCELDAP_H
29#define KABC_RESOURCELDAP_H 29#define KABC_RESOURCELDAP_H
30 30
31 31
32#include <lber.h> 32#include <lber.h>
33#include <ldap.h> 33#include <ldap.h>
34 34
35#include "addressbook.h" 35#include "addressbook.h"
36#include "resource.h" 36#include "resource.h"
37 37
38class KConfig; 38class KConfig;
39 39
40namespace KABC { 40namespace KABC {
41 41
42class ResourceLDAP : public Resource 42class ResourceLDAP : public Resource
43{ 43{
44public: 44public:
45 45
46 ResourceLDAP( const KConfig*, bool syncable ); 46 ResourceLDAP( const KConfig* );
47 47
48 virtual void writeConfig( KConfig* ); 48 virtual void writeConfig( KConfig* );
49 49
50 virtual bool doOpen(); 50 virtual bool doOpen();
51 virtual void doClose(); 51 virtual void doClose();
52 52
53 virtual Ticket *requestSaveTicket(); 53 virtual Ticket *requestSaveTicket();
54 54
55 virtual bool load(); 55 virtual bool load();
56 virtual bool save( Ticket * ); 56 virtual bool save( Ticket * );
57 57
58 virtual void removeAddressee( const Addressee& addr ); 58 virtual void removeAddressee( const Addressee& addr );
59 59
60 void setUser( const QString &user ); 60 void setUser( const QString &user );
61 QString user() const; 61 QString user() const;
62 62
63 void setPassword( const QString &password ); 63 void setPassword( const QString &password );
64 QString password() const; 64 QString password() const;
65 65
66 void setDn( const QString &dn ); 66 void setDn( const QString &dn );
67 QString dn() const; 67 QString dn() const;
68 68
69 void setHost( const QString &host ); 69 void setHost( const QString &host );
70 QString host() const; 70 QString host() const;
71 71
72 void setPort( int port ); 72 void setPort( int port );
73 int port() const; 73 int port() const;
74 74
75 void setFilter( const QString &filter ); 75 void setFilter( const QString &filter );
76 QString filter() const; 76 QString filter() const;
77 77
78 void setIsAnonymous( bool value ); 78 void setIsAnonymous( bool value );
79 bool isAnonymous() const; 79 bool isAnonymous() const;
80 80
81 void setAttributes( const QMap<QString, QString> &attributes ); 81 void setAttributes( const QMap<QString, QString> &attributes );
82 QMap<QString, QString> attributes() const; 82 QMap<QString, QString> attributes() const;
83 83
84private: 84private:
85 QString mUser; 85 QString mUser;
86 QString mPassword; 86 QString mPassword;
87 QString mDn; 87 QString mDn;
88 QString mHost; 88 QString mHost;
89 QString mFilter; 89 QString mFilter;
90 int mPort; 90 int mPort;
91 bool mAnonymous; 91 bool mAnonymous;
92 QMap<QString, QString> mAttributes; 92 QMap<QString, QString> mAttributes;
93 93
94 LDAP *mLdap; 94 LDAP *mLdap;
95}; 95};
96 96
97} 97}
98 98
99#endif 99#endif
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index 22237dc..f610b38 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -1,350 +1,349 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45//US #include "formatfactory.h" 45//US #include "formatfactory.h"
46//US #include <qpe/qpeapplication.h> 46//US #include <qpe/qpeapplication.h>
47 47
48#include <opie/ocontactaccess.h> 48#include <opie/ocontactaccess.h>
49#include <opie/ocontactaccessbackend_xml.h> 49#include <opie/ocontactaccessbackend_xml.h>
50 50
51#include "resourceopieconfig.h" 51#include "resourceopieconfig.h"
52#include "stdaddressbook.h" 52#include "stdaddressbook.h"
53#include "syncprefwidget.h"
54 53
55#include "opieconverter.h" 54#include "opieconverter.h"
56 55
57#include "resourceopie.h" 56#include "resourceopie.h"
58 57
59using namespace KABC; 58using namespace KABC;
60extern "C" 59extern "C"
61{ 60{
62 void *init_microkabc_opie() 61 void *init_microkabc_opie()
63 { 62 {
64 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidgetContainer>(); 63 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>();
65 } 64 }
66} 65}
67 66
68ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) 67ResourceOpie::ResourceOpie( const KConfig *config )
69 : Resource( config, syncable ), mAccess(0), mConverter (0) 68 : Resource( config ), mAccess(0), mConverter (0)
70{ 69{
71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 70 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
72 71
73 KConfig *cfg = (KConfig *)config; 72 KConfig *cfg = (KConfig *)config;
74 if ( cfg ) { 73 if ( cfg ) {
75 fileName = cfg->readEntry( "FileName", fileName ); 74 fileName = cfg->readEntry( "FileName", fileName );
76 75
77 } 76 }
78 77
79 init( fileName ); 78 init( fileName );
80} 79}
81 80
82ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) 81ResourceOpie::ResourceOpie( const QString &fileName )
83 : Resource( 0, syncable ) 82 : Resource( 0 )
84{ 83{
85 init( fileName ); 84 init( fileName );
86} 85}
87 86
88void ResourceOpie::init( const QString &fileName ) 87void ResourceOpie::init( const QString &fileName )
89{ 88{
90 qDebug("ResourceOpie::init()"); 89 qDebug("ResourceOpie::init()");
91 90
92 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 91 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
93 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 92 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
94 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 93 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
95 94
96 setFileName( fileName ); 95 setFileName( fileName );
97} 96}
98 97
99ResourceOpie::~ResourceOpie() 98ResourceOpie::~ResourceOpie()
100{ 99{
101 if (mConverter != 0) 100 if (mConverter != 0)
102 delete mConverter; 101 delete mConverter;
103 102
104 if(mAccess != 0) 103 if(mAccess != 0)
105 delete mAccess; 104 delete mAccess;
106} 105}
107 106
108void ResourceOpie::writeConfig( KConfig *config ) 107void ResourceOpie::writeConfig( KConfig *config )
109{ 108{
110 Resource::writeConfig( config ); 109 Resource::writeConfig( config );
111 110
112 config->writeEntry( "FileName", fileName() ); 111 config->writeEntry( "FileName", fileName() );
113} 112}
114 113
115Ticket *ResourceOpie::requestSaveTicket() 114Ticket *ResourceOpie::requestSaveTicket()
116{ 115{
117 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; 116 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl;
118 117
119 qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); 118 qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1());
120 119
121 if ( !addressBook() ) return 0; 120 if ( !addressBook() ) return 0;
122 121
123 if ( !lock( fileName() ) ) { 122 if ( !lock( fileName() ) ) {
124 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" 123 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '"
125 << fileName() << "'" << endl; 124 << fileName() << "'" << endl;
126 return 0; 125 return 0;
127 } 126 }
128 return createTicket( this ); 127 return createTicket( this );
129} 128}
130 129
131 130
132bool ResourceOpie::doOpen() 131bool ResourceOpie::doOpen()
133{ 132{
134 qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); 133 qDebug("ResourceOpie::doOpen: %s", fileName().latin1());
135 134
136 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); 135 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() );
137 mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); 136 mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false);
138 137
139 if ( !mAccess ) { 138 if ( !mAccess ) {
140 qDebug("Unable to load file() %s", fileName().latin1()); 139 qDebug("Unable to load file() %s", fileName().latin1());
141 return false; 140 return false;
142 } 141 }
143 142
144 mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available 143 mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available
145 144
146 145
147 if (mConverter == 0) 146 if (mConverter == 0)
148 { 147 {
149 mConverter = new OpieConverter(); 148 mConverter = new OpieConverter();
150 bool res = mConverter->init(); 149 bool res = mConverter->init();
151 if ( !res ) 150 if ( !res )
152 { 151 {
153 qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); 152 qDebug("Unable to initialize opie converter. Most likely a problem with the category file");
154 delete mAccess; 153 delete mAccess;
155 mAccess = 0; 154 mAccess = 0;
156 return false; 155 return false;
157 } 156 }
158 } 157 }
159 158
160 159
161 160
162 return true; 161 return true;
163} 162}
164 163
165void ResourceOpie::doClose() 164void ResourceOpie::doClose()
166{ 165{
167 qDebug("ResourceOpie::doClose: %s", fileName().latin1()); 166 qDebug("ResourceOpie::doClose: %s", fileName().latin1());
168 167
169 if(mAccess) 168 if(mAccess)
170 { 169 {
171 delete mAccess; 170 delete mAccess;
172 mAccess = 0; 171 mAccess = 0;
173 } 172 }
174 // it seems so, that deletion of access deletes backend as well 173 // it seems so, that deletion of access deletes backend as well
175 //delete backend; 174 //delete backend;
176 175
177 return; 176 return;
178 177
179} 178}
180 179
181 180
182bool ResourceOpie::load() 181bool ResourceOpie::load()
183{ 182{
184 qDebug("ResourceOpie::load: %s", fileName().latin1()); 183 qDebug("ResourceOpie::load: %s", fileName().latin1());
185 184
186 bool res = false; 185 bool res = false;
187 186
188 OContactAccess::List::Iterator it; 187 OContactAccess::List::Iterator it;
189 OContactAccess::List allList = mAccess->allRecords(); 188 OContactAccess::List allList = mAccess->allRecords();
190 for ( it = allList.begin(); it != allList.end(); ++it ) 189 for ( it = allList.begin(); it != allList.end(); ++it )
191 { 190 {
192 const OContact c = (*it); 191 const OContact c = (*it);
193 192
194 KABC::Addressee addressee; 193 KABC::Addressee addressee;
195 194
196 res = mConverter->opieToAddressee( c, addressee ); 195 res = mConverter->opieToAddressee( c, addressee );
197 196
198 if ( !addressee.isEmpty() && res ) 197 if ( !addressee.isEmpty() && res )
199 { 198 {
200 addressee.setResource( this ); 199 addressee.setResource( this );
201 addressBook()->insertAddressee( addressee ); 200 addressBook()->insertAddressee( addressee );
202 } 201 }
203 202
204 } 203 }
205 204
206 205
207 return true; 206 return true;
208} 207}
209 208
210bool ResourceOpie::save( Ticket *ticket ) 209bool ResourceOpie::save( Ticket *ticket )
211{ 210{
212 qDebug("ResourceOpie::save: %s", fileName().latin1()); 211 qDebug("ResourceOpie::save: %s", fileName().latin1());
213 212
214 mDirWatch.stopScan(); 213 mDirWatch.stopScan();
215 214
216 KABC::AddressBook::Iterator it; 215 KABC::AddressBook::Iterator it;
217 bool res; 216 bool res;
218 217
219 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 218 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
220 OContact c; 219 OContact c;
221 KABC::Addressee addressee = (*it); 220 KABC::Addressee addressee = (*it);
222 221
223 res = mConverter->addresseeToOpie( *it, c ); 222 res = mConverter->addresseeToOpie( *it, c );
224 if (res == true) 223 if (res == true)
225 { 224 {
226 res = mAccess->add(c); 225 res = mAccess->add(c);
227 if (res == false) 226 if (res == false)
228 qDebug("Unable to append Contact %s", c.fullName().latin1()); 227 qDebug("Unable to append Contact %s", c.fullName().latin1());
229 } 228 }
230 else 229 else
231 { 230 {
232 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 231 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
233 } 232 }
234 } 233 }
235 234
236 mAccess->save(); 235 mAccess->save();
237 236
238 mDirWatch.startScan(); 237 mDirWatch.startScan();
239 238
240 delete ticket; 239 delete ticket;
241 unlock( fileName() ); 240 unlock( fileName() );
242 241
243 return true; 242 return true;
244 243
245} 244}
246 245
247bool ResourceOpie::lock( const QString &lockfileName ) 246bool ResourceOpie::lock( const QString &lockfileName )
248{ 247{
249 qDebug("ResourceOpie::lock: %s", fileName().latin1()); 248 qDebug("ResourceOpie::lock: %s", fileName().latin1());
250 249
251 kdDebug(5700) << "ResourceOpie::lock()" << endl; 250 kdDebug(5700) << "ResourceOpie::lock()" << endl;
252 251
253 QString fn = lockfileName; 252 QString fn = lockfileName;
254 253
255 KURL url(fn); 254 KURL url(fn);
256 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 255 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
257 256
258 kdDebug(5700) << "-- lock name: " << lockName << endl; 257 kdDebug(5700) << "-- lock name: " << lockName << endl;
259 258
260 if (QFile::exists( lockName )) 259 if (QFile::exists( lockName ))
261 { 260 {
262 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 261 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
263 return false; 262 return false;
264 } 263 }
265 264
266 QString lockUniqueName; 265 QString lockUniqueName;
267 lockUniqueName = fn + KApplication::randomString( 8 ); 266 lockUniqueName = fn + KApplication::randomString( 8 );
268 267
269 url = lockUniqueName; 268 url = lockUniqueName;
270//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 269//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
271 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 270 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
272 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 271 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
273 272
274 // Create unique file 273 // Create unique file
275 QFile file( mLockUniqueName ); 274 QFile file( mLockUniqueName );
276 file.open( IO_WriteOnly ); 275 file.open( IO_WriteOnly );
277 file.close(); 276 file.close();
278 277
279 // Create lock file 278 // Create lock file
280 int result = 0; 279 int result = 0;
281#ifndef _WIN32_ 280#ifndef _WIN32_
282 result = ::link( QFile::encodeName( mLockUniqueName ), 281 result = ::link( QFile::encodeName( mLockUniqueName ),
283 QFile::encodeName( lockName ) ); 282 QFile::encodeName( lockName ) );
284#endif 283#endif
285 if ( result == 0 ) { 284 if ( result == 0 ) {
286 addressBook()->emitAddressBookLocked(); 285 addressBook()->emitAddressBookLocked();
287 return true; 286 return true;
288 } 287 }
289 288
290 // TODO: check stat 289 // TODO: check stat
291 290
292 return false; 291 return false;
293} 292}
294 293
295void ResourceOpie::unlock( const QString &fileName ) 294void ResourceOpie::unlock( const QString &fileName )
296{ 295{
297 qDebug("ResourceOpie::unlock() %s", fileName.latin1()); 296 qDebug("ResourceOpie::unlock() %s", fileName.latin1());
298 297
299 QString fn = fileName; 298 QString fn = fileName;
300 KURL url(fn); 299 KURL url(fn);
301 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 300 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
302 301
303 QFile::remove( lockName ); 302 QFile::remove( lockName );
304 QFile::remove( mLockUniqueName ); 303 QFile::remove( mLockUniqueName );
305 addressBook()->emitAddressBookUnlocked(); 304 addressBook()->emitAddressBookUnlocked();
306} 305}
307 306
308void ResourceOpie::setFileName( const QString &newFileName ) 307void ResourceOpie::setFileName( const QString &newFileName )
309{ 308{
310 mDirWatch.stopScan(); 309 mDirWatch.stopScan();
311 mDirWatch.removeFile( fileName() ); 310 mDirWatch.removeFile( fileName() );
312 311
313 Resource::setFileName( newFileName ); 312 Resource::setFileName( newFileName );
314 313
315 mDirWatch.addFile( fileName() ); 314 mDirWatch.addFile( fileName() );
316 mDirWatch.startScan(); 315 mDirWatch.startScan();
317 316
318} 317}
319 318
320 319
321void ResourceOpie::fileChanged() 320void ResourceOpie::fileChanged()
322{ 321{
323 // There is a small theoretical chance that KDirWatch calls us before 322 // There is a small theoretical chance that KDirWatch calls us before
324 // we are fully constructed 323 // we are fully constructed
325 if (!addressBook()) 324 if (!addressBook())
326 return; 325 return;
327 326
328 QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 327 QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
329 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 328 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
330 load(); 329 load();
331 addressBook()->emitAddressBookChanged(); 330 addressBook()->emitAddressBookChanged();
332 } 331 }
333 332
334 load(); 333 load();
335 addressBook()->emitAddressBookChanged(); 334 addressBook()->emitAddressBookChanged();
336} 335}
337 336
338void ResourceOpie::removeAddressee( const Addressee &addr ) 337void ResourceOpie::removeAddressee( const Addressee &addr )
339{ 338{
340} 339}
341 340
342void ResourceOpie::cleanUp() 341void ResourceOpie::cleanUp()
343{ 342{
344// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); 343// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1());
345 344
346 unlock( fileName() ); 345 unlock( fileName() );
347} 346}
348 347
349 348
350//US #include "resourceopie.moc" 349//US #include "resourceopie.moc"
diff --git a/kabc/plugins/opie/resourceopie.h b/kabc/plugins/opie/resourceopie.h
index d5b4ebd..9d05c70 100644
--- a/kabc/plugins/opie/resourceopie.h
+++ b/kabc/plugins/opie/resourceopie.h
@@ -1,146 +1,146 @@
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 28
29#ifndef KABC_RESOURCEOPIE_H 29#ifndef KABC_RESOURCEOPIE_H
30#define KABC_RESOURCEOPIE_H 30#define KABC_RESOURCEOPIE_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include "resource.h" 37#include "resource.h"
38 38
39 39
40class OContactAccess; 40class OContactAccess;
41 41
42namespace KABC { 42namespace KABC {
43 43
44class ResourceConfigWidget; 44class ResourceConfigWidget;
45class OpieConverter; 45class OpieConverter;
46/** 46/**
47 @internal 47 @internal
48*/ 48*/
49class ResourceOpie : public Resource 49class ResourceOpie : public Resource
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 52
53public: 53public:
54 54
55 /** 55 /**
56 Constructor. 56 Constructor.
57 57
58 @param cfg The config object where custom resource settings are stored. 58 @param cfg The config object where custom resource settings are stored.
59 */ 59 */
60 ResourceOpie( const KConfig *cfg, bool syncable ); 60 ResourceOpie( const KConfig *cfg );
61 61
62 /** 62 /**
63 Construct file resource on file @arg fileName using format @arg formatName. 63 Construct file resource on file @arg fileName using format @arg formatName.
64 */ 64 */
65 ResourceOpie( const QString &fileName, bool syncable ); 65 ResourceOpie( const QString &fileName );
66 66
67 /** 67 /**
68 * Destructor. 68 * Destructor.
69 */ 69 */
70 ~ResourceOpie(); 70 ~ResourceOpie();
71 71
72 /** 72 /**
73 Writes the config back. 73 Writes the config back.
74 */ 74 */
75 virtual void writeConfig( KConfig *cfg ); 75 virtual void writeConfig( KConfig *cfg );
76 76
77 /** 77 /**
78 * Tries to open the file and checks for the proper format. 78 * Tries to open the file and checks for the proper format.
79 * This method should be called before @ref load(). 79 * This method should be called before @ref load().
80 */ 80 */
81 virtual bool doOpen(); 81 virtual bool doOpen();
82 82
83 /** 83 /**
84 * Closes the file again. 84 * Closes the file again.
85 */ 85 */
86 virtual void doClose(); 86 virtual void doClose();
87 87
88 /** 88 /**
89 * Requests a save ticket, that is used by @ref save() 89 * Requests a save ticket, that is used by @ref save()
90 */ 90 */
91 virtual Ticket *requestSaveTicket(); 91 virtual Ticket *requestSaveTicket();
92 92
93 /** 93 /**
94 * Loads all addressees from file to the address book. 94 * Loads all addressees from file to the address book.
95 * Returns true if all addressees could be loaded otherwise false. 95 * Returns true if all addressees could be loaded otherwise false.
96 */ 96 */
97 virtual bool load(); 97 virtual bool load();
98 98
99 /** 99 /**
100 * Saves all addresses from address book to file. 100 * Saves all addresses from address book to file.
101 * Returns true if all addressees could be saved otherwise false. 101 * Returns true if all addressees could be saved otherwise false.
102 * 102 *
103 * @param ticket The ticket returned by @ref requestSaveTicket() 103 * @param ticket The ticket returned by @ref requestSaveTicket()
104 */ 104 */
105 virtual bool save( Ticket *ticket ); 105 virtual bool save( Ticket *ticket );
106 106
107 107
108 /** 108 /**
109 * Remove a addressee from its source. 109 * Remove a addressee from its source.
110 * This method is mainly called by KABC::AddressBook. 110 * This method is mainly called by KABC::AddressBook.
111 */ 111 */
112 virtual void removeAddressee( const Addressee& addr ); 112 virtual void removeAddressee( const Addressee& addr );
113 113
114 /** 114 /**
115 * Set name of file to be used for saving. 115 * Set name of file to be used for saving.
116 */ 116 */
117 virtual void setFileName( const QString & ); 117 virtual void setFileName( const QString & );
118 118
119 /** 119 /**
120 * This method is called by an error handler if the application 120 * This method is called by an error handler if the application
121 * crashed 121 * crashed
122 */ 122 */
123 virtual void cleanUp(); 123 virtual void cleanUp();
124 124
125 125
126protected slots: 126protected slots:
127 void fileChanged(); 127 void fileChanged();
128 128
129protected: 129protected:
130 void init( const QString &fileName ); 130 void init( const QString &fileName );
131 131
132 bool lock( const QString &fileName ); 132 bool lock( const QString &fileName );
133 void unlock( const QString &fileName ); 133 void unlock( const QString &fileName );
134 134
135private: 135private:
136 OContactAccess* mAccess; 136 OContactAccess* mAccess;
137 OpieConverter* mConverter; 137 OpieConverter* mConverter;
138 138
139 QString mLockUniqueName; 139 QString mLockUniqueName;
140 140
141 KDirWatch mDirWatch; 141 KDirWatch mDirWatch;
142}; 142};
143 143
144} 144}
145 145
146#endif 146#endif
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index f9cabcb..deb218b 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -1,322 +1,321 @@
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#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qdir.h> 31#include <qdir.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qregexp.h> 34#include <qregexp.h>
35//US #include <qtimer.h> 35//US #include <qtimer.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncprefwidget.h"
53 52
54#include "resourceqtopia.h" 53#include "resourceqtopia.h"
55 54
56using namespace KABC; 55using namespace KABC;
57extern "C" 56extern "C"
58{ 57{
59 void *init_microkabc_qtopia() 58 void *init_microkabc_qtopia()
60 { 59 {
61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); 60 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>();
62 } 61 }
63} 62}
64 63
65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 64ResourceQtopia::ResourceQtopia( const KConfig *config )
66 : Resource( config, syncable ), mConverter (0) 65 : Resource( config ), mConverter (0)
67{ 66{
68 // we can not choose the filename. Therefore use the default to display 67 // we can not choose the filename. Therefore use the default to display
69 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 68 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
70 init( fileName ); 69 init( fileName );
71} 70}
72 71
73ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) 72ResourceQtopia::ResourceQtopia( const QString &fileName )
74 : Resource( 0, syncable ) 73 : Resource( 0 )
75{ 74{
76 init( fileName ); 75 init( fileName );
77} 76}
78 77
79void ResourceQtopia::init( const QString &fileName ) 78void ResourceQtopia::init( const QString &fileName )
80{ 79{
81 80
82 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 81 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
83 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 82 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
84 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 83 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
85 84
86 setFileName( fileName ); 85 setFileName( fileName );
87} 86}
88 87
89ResourceQtopia::~ResourceQtopia() 88ResourceQtopia::~ResourceQtopia()
90{ 89{
91 if (mConverter != 0) 90 if (mConverter != 0)
92 delete mConverter; 91 delete mConverter;
93 92
94 if(mAccess != 0) 93 if(mAccess != 0)
95 delete mAccess; 94 delete mAccess;
96} 95}
97 96
98void ResourceQtopia::writeConfig( KConfig *config ) 97void ResourceQtopia::writeConfig( KConfig *config )
99{ 98{
100 Resource::writeConfig( config ); 99 Resource::writeConfig( config );
101} 100}
102 101
103Ticket *ResourceQtopia::requestSaveTicket() 102Ticket *ResourceQtopia::requestSaveTicket()
104{ 103{
105 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; 104 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
106 105
107 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); 106 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1());
108 107
109 if ( !addressBook() ) return 0; 108 if ( !addressBook() ) return 0;
110 109
111 if ( !lock( fileName() ) ) { 110 if ( !lock( fileName() ) ) {
112 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 111 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
113 << fileName() << "'" << endl; 112 << fileName() << "'" << endl;
114 return 0; 113 return 0;
115 } 114 }
116 return createTicket( this ); 115 return createTicket( this );
117} 116}
118 117
119 118
120bool ResourceQtopia::doOpen() 119bool ResourceQtopia::doOpen()
121{ 120{
122 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); 121 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
123 122
124 mAccess = new AddressBookAccess(); 123 mAccess = new AddressBookAccess();
125 124
126 if ( !mAccess ) { 125 if ( !mAccess ) {
127 qDebug("Unable to load file() %s", fileName().latin1()); 126 qDebug("Unable to load file() %s", fileName().latin1());
128 return false; 127 return false;
129 } 128 }
130 129
131 130
132 if (mConverter == 0) 131 if (mConverter == 0)
133 { 132 {
134 mConverter = new QtopiaConverter(); 133 mConverter = new QtopiaConverter();
135 bool res = mConverter->init(); 134 bool res = mConverter->init();
136 if ( !res ) 135 if ( !res )
137 { 136 {
138 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 137 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
139 qDebug(msg); 138 qDebug(msg);
140 delete mAccess; 139 delete mAccess;
141 mAccess = 0; 140 mAccess = 0;
142 return false; 141 return false;
143 } 142 }
144 } 143 }
145 144
146 return true; 145 return true;
147} 146}
148 147
149void ResourceQtopia::doClose() 148void ResourceQtopia::doClose()
150{ 149{
151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 150 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
152 151
153 if(mAccess) 152 if(mAccess)
154 { 153 {
155 delete mAccess; 154 delete mAccess;
156 mAccess = 0; 155 mAccess = 0;
157 } 156 }
158 // it seems so, that deletion of access deletes backend as well 157 // it seems so, that deletion of access deletes backend as well
159 //delete backend; 158 //delete backend;
160 159
161 return; 160 return;
162} 161}
163 162
164bool ResourceQtopia::load() 163bool ResourceQtopia::load()
165{ 164{
166 qDebug("ResourceQtopia::load: %s", fileName().latin1()); 165 qDebug("ResourceQtopia::load: %s", fileName().latin1());
167 166
168 AddressBookIterator it(*mAccess); 167 AddressBookIterator it(*mAccess);
169 const PimContact* contact; 168 const PimContact* contact;
170 bool res; 169 bool res;
171 170
172 for (contact=it.toFirst(); it.current(); ++it) 171 for (contact=it.toFirst(); it.current(); ++it)
173 { 172 {
174 contact = it.current(); 173 contact = it.current();
175 174
176 KABC::Addressee addressee; 175 KABC::Addressee addressee;
177 176
178 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 177 res = mConverter->qtopiaToAddressee( (*contact), addressee );
179 178
180 if ( !addressee.isEmpty() && res ) 179 if ( !addressee.isEmpty() && res )
181 { 180 {
182 addressee.setResource( this ); 181 addressee.setResource( this );
183 addressBook()->insertAddressee( addressee ); 182 addressBook()->insertAddressee( addressee );
184 } 183 }
185 } 184 }
186 185
187 return true; 186 return true;
188} 187}
189 188
190bool ResourceQtopia::save( Ticket *ticket ) 189bool ResourceQtopia::save( Ticket *ticket )
191{ 190{
192 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 191 qDebug("ResourceQtopia::save: %s", fileName().latin1());
193 192
194 mDirWatch.stopScan(); 193 mDirWatch.stopScan();
195 194
196 KABC::AddressBook::Iterator it; 195 KABC::AddressBook::Iterator it;
197 bool res; 196 bool res;
198 197
199 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 198 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
200 PimContact c; 199 PimContact c;
201 KABC::Addressee addressee = (*it); 200 KABC::Addressee addressee = (*it);
202 201
203 res = mConverter->addresseeToQtopia( *it, c ); 202 res = mConverter->addresseeToQtopia( *it, c );
204 if (res == true) 203 if (res == true)
205 { 204 {
206 mAccess->addContact(c); 205 mAccess->addContact(c);
207// if (res == false) 206// if (res == false)
208// qDebug("Unable to append Contact %s", c.fullName().latin1()); 207// qDebug("Unable to append Contact %s", c.fullName().latin1());
209 } 208 }
210 else 209 else
211 { 210 {
212 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 211 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
213 } 212 }
214 } 213 }
215 214
216// mAccess->addressBookUpdated(); 215// mAccess->addressBookUpdated();
217 216
218 mDirWatch.startScan(); 217 mDirWatch.startScan();
219 218
220 delete ticket; 219 delete ticket;
221 unlock( fileName() ); 220 unlock( fileName() );
222 221
223 return true; 222 return true;
224} 223}
225 224
226bool ResourceQtopia::lock( const QString &lockfileName ) 225bool ResourceQtopia::lock( const QString &lockfileName )
227{ 226{
228 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 227 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
229 228
230 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 229 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
231 230
232 QString fn = lockfileName; 231 QString fn = lockfileName;
233 232
234 KURL url(fn); 233 KURL url(fn);
235 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 234 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
236 235
237 kdDebug(5700) << "-- lock name: " << lockName << endl; 236 kdDebug(5700) << "-- lock name: " << lockName << endl;
238 237
239 if (QFile::exists( lockName )) 238 if (QFile::exists( lockName ))
240 { 239 {
241 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 240 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
242 return false; 241 return false;
243 } 242 }
244 243
245 QString lockUniqueName; 244 QString lockUniqueName;
246 lockUniqueName = fn + KApplication::randomString( 8 ); 245 lockUniqueName = fn + KApplication::randomString( 8 );
247 246
248 url = lockUniqueName; 247 url = lockUniqueName;
249//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 248//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
250 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 249 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
251 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 250 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
252 251
253 // Create unique file 252 // Create unique file
254 QFile file( mLockUniqueName ); 253 QFile file( mLockUniqueName );
255 file.open( IO_WriteOnly ); 254 file.open( IO_WriteOnly );
256 file.close(); 255 file.close();
257 256
258 // Create lock file 257 // Create lock file
259 int result = 0; 258 int result = 0;
260#ifndef _WIN32_ 259#ifndef _WIN32_
261 result = ::link( QFile::encodeName( mLockUniqueName ), 260 result = ::link( QFile::encodeName( mLockUniqueName ),
262 QFile::encodeName( lockName ) ); 261 QFile::encodeName( lockName ) );
263#endif 262#endif
264 if ( result == 0 ) { 263 if ( result == 0 ) {
265 addressBook()->emitAddressBookLocked(); 264 addressBook()->emitAddressBookLocked();
266 return true; 265 return true;
267 } 266 }
268 267
269 // TODO: check stat 268 // TODO: check stat
270 269
271 return false; 270 return false;
272} 271}
273 272
274void ResourceQtopia::unlock( const QString &fileName ) 273void ResourceQtopia::unlock( const QString &fileName )
275{ 274{
276 qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); 275 qDebug("ResourceQtopia::unlock() %s", fileName.latin1());
277 276
278 QString fn = fileName; 277 QString fn = fileName;
279 KURL url(fn); 278 KURL url(fn);
280 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 279 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
281 280
282 QFile::remove( lockName ); 281 QFile::remove( lockName );
283 QFile::remove( mLockUniqueName ); 282 QFile::remove( mLockUniqueName );
284 addressBook()->emitAddressBookUnlocked(); 283 addressBook()->emitAddressBookUnlocked();
285} 284}
286 285
287void ResourceQtopia::setFileName( const QString &newFileName ) 286void ResourceQtopia::setFileName( const QString &newFileName )
288{ 287{
289 mDirWatch.stopScan(); 288 mDirWatch.stopScan();
290 mDirWatch.removeFile( fileName() ); 289 mDirWatch.removeFile( fileName() );
291 290
292 Resource::setFileName( newFileName ); 291 Resource::setFileName( newFileName );
293 292
294 mDirWatch.addFile( fileName() ); 293 mDirWatch.addFile( fileName() );
295 mDirWatch.startScan(); 294 mDirWatch.startScan();
296} 295}
297 296
298 297
299void ResourceQtopia::fileChanged() 298void ResourceQtopia::fileChanged()
300{ 299{
301 // There is a small theoretical chance that KDirWatch calls us before 300 // There is a small theoretical chance that KDirWatch calls us before
302 // we are fully constructed 301 // we are fully constructed
303 if (!addressBook()) 302 if (!addressBook())
304 return; 303 return;
305 304
306 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 305 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
307 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 306 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
308 load(); 307 load();
309 addressBook()->emitAddressBookChanged(); 308 addressBook()->emitAddressBookChanged();
310 } 309 }
311} 310}
312 311
313void ResourceQtopia::removeAddressee( const Addressee &addr ) 312void ResourceQtopia::removeAddressee( const Addressee &addr )
314{ 313{
315} 314}
316 315
317void ResourceQtopia::cleanUp() 316void ResourceQtopia::cleanUp()
318{ 317{
319 unlock( fileName() ); 318 unlock( fileName() );
320} 319}
321 320
322//US #include "resourceqtopia.moc" 321//US #include "resourceqtopia.moc"
diff --git a/kabc/plugins/qtopia/resourceqtopia.h b/kabc/plugins/qtopia/resourceqtopia.h
index eace280..ff6350d 100644
--- a/kabc/plugins/qtopia/resourceqtopia.h
+++ b/kabc/plugins/qtopia/resourceqtopia.h
@@ -1,145 +1,145 @@
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 28
29#ifndef KABC_RESOURCEOPIE_H 29#ifndef KABC_RESOURCEOPIE_H
30#define KABC_RESOURCEOPIE_H 30#define KABC_RESOURCEOPIE_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include "resource.h" 37#include "resource.h"
38 38
39class AddressBookAccess; 39class AddressBookAccess;
40 40
41namespace KABC { 41namespace KABC {
42 42
43//US class FormatPlugin; 43//US class FormatPlugin;
44class ResourceConfigWidget; 44class ResourceConfigWidget;
45class QtopiaConverter; 45class QtopiaConverter;
46 46
47/** 47/**
48 @internal 48 @internal
49*/ 49*/
50class ResourceQtopia : public Resource 50class ResourceQtopia : public Resource
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 55
56 /** 56 /**
57 Constructor. 57 Constructor.
58 58
59 @param cfg The config object where custom resource settings are stored. 59 @param cfg The config object where custom resource settings are stored.
60 */ 60 */
61 ResourceQtopia( const KConfig *cfg, bool syncable ); 61 ResourceQtopia( const KConfig *cfg );
62 62
63 /** 63 /**
64 Construct file resource on file @arg fileName using format @arg formatName. 64 Construct file resource on file @arg fileName using format @arg formatName.
65 */ 65 */
66 ResourceQtopia( const QString &fileName, bool syncable ); 66 ResourceQtopia( const QString &fileName );
67 67
68 /** 68 /**
69 * Destructor. 69 * Destructor.
70 */ 70 */
71 ~ResourceQtopia(); 71 ~ResourceQtopia();
72 72
73 /** 73 /**
74 Writes the config back. 74 Writes the config back.
75 */ 75 */
76 virtual void writeConfig( KConfig *cfg ); 76 virtual void writeConfig( KConfig *cfg );
77 77
78 /** 78 /**
79 * Tries to open the file and checks for the proper format. 79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load(). 80 * This method should be called before @ref load().
81 */ 81 */
82 virtual bool doOpen(); 82 virtual bool doOpen();
83 83
84 /** 84 /**
85 * Closes the file again. 85 * Closes the file again.
86 */ 86 */
87 virtual void doClose(); 87 virtual void doClose();
88 88
89 /** 89 /**
90 * Requests a save ticket, that is used by @ref save() 90 * Requests a save ticket, that is used by @ref save()
91 */ 91 */
92 virtual Ticket *requestSaveTicket(); 92 virtual Ticket *requestSaveTicket();
93 93
94 /** 94 /**
95 * Loads all addressees from file to the address book. 95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false. 96 * Returns true if all addressees could be loaded otherwise false.
97 */ 97 */
98 virtual bool load(); 98 virtual bool load();
99 99
100 /** 100 /**
101 * Saves all addresses from address book to file. 101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false. 102 * Returns true if all addressees could be saved otherwise false.
103 * 103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket() 104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */ 105 */
106 virtual bool save( Ticket *ticket ); 106 virtual bool save( Ticket *ticket );
107 107
108 /** 108 /**
109 * Remove a addressee from its source. 109 * Remove a addressee from its source.
110 * This method is mainly called by KABC::AddressBook. 110 * This method is mainly called by KABC::AddressBook.
111 */ 111 */
112 virtual void removeAddressee( const Addressee& addr ); 112 virtual void removeAddressee( const Addressee& addr );
113 113
114 /** 114 /**
115 * Set name of file to be used for saving. 115 * Set name of file to be used for saving.
116 */ 116 */
117 virtual void setFileName( const QString & ); 117 virtual void setFileName( const QString & );
118 118
119 /** 119 /**
120 * This method is called by an error handler if the application 120 * This method is called by an error handler if the application
121 * crashed 121 * crashed
122 */ 122 */
123 virtual void cleanUp(); 123 virtual void cleanUp();
124 124
125protected slots: 125protected slots:
126 void fileChanged(); 126 void fileChanged();
127 127
128protected: 128protected:
129 void init( const QString &fileName ); 129 void init( const QString &fileName );
130 130
131 bool lock( const QString &fileName ); 131 bool lock( const QString &fileName );
132 void unlock( const QString &fileName ); 132 void unlock( const QString &fileName );
133 133
134private: 134private:
135 AddressBookAccess* mAccess; 135 AddressBookAccess* mAccess;
136 QtopiaConverter* mConverter; 136 QtopiaConverter* mConverter;
137 137
138 QString mLockUniqueName; 138 QString mLockUniqueName;
139 139
140 KDirWatch mDirWatch; 140 KDirWatch mDirWatch;
141}; 141};
142 142
143} 143}
144 144
145#endif 145#endif
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index c013f52..2cdf4bf 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,408 +1,406 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
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#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h> 48#include <libkdepim/ksyncprofile.h>
49 49
50#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
52 52
53#include "syncprefwidget.h"
54
55#include "stdaddressbook.h" 53#include "stdaddressbook.h"
56 54
57#include "sharpdtmconverter.h" 55#include "sharpdtmconverter.h"
58//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
59using namespace KABC; 57using namespace KABC;
60extern "C" 58extern "C"
61{ 59{
62 void *init_microkabc_sharpdtm() 60 void *init_microkabc_sharpdtm()
63 { 61 {
64 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); 62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
65 } 63 }
66} 64}
67 65
68ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) 66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
69 : Resource( config, syncable ), mConverter (0) 67 : Resource( config ), mConverter (0)
70{ 68{
71 // we can not choose the filename. Therefore use the default to display 69 // we can not choose the filename. Therefore use the default to display
72 70
73 QString fileName = SlZDataBase::addressbookFileName(); 71 QString fileName = SlZDataBase::addressbookFileName();
74 init( fileName ); 72 init( fileName );
75} 73}
76 74
77ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) 75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable )
78 : Resource( 0, syncable ) 76 : Resource( 0, syncable )
79{ 77{
80 init( fileName ); 78 init( fileName );
81} 79}
82 80
83void ResourceSharpDTM::init( const QString &fileName ) 81void ResourceSharpDTM::init( const QString &fileName )
84{ 82{
85 83
86 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
87 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
88 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
89 87
90 setFileName( fileName ); 88 setFileName( fileName );
91} 89}
92 90
93ResourceSharpDTM::~ResourceSharpDTM() 91ResourceSharpDTM::~ResourceSharpDTM()
94{ 92{
95 if (mConverter != 0) 93 if (mConverter != 0)
96 delete mConverter; 94 delete mConverter;
97 95
98 if(mAccess != 0) 96 if(mAccess != 0)
99 delete mAccess; 97 delete mAccess;
100} 98}
101 99
102void ResourceSharpDTM::writeConfig( KConfig *config ) 100void ResourceSharpDTM::writeConfig( KConfig *config )
103{ 101{
104 Resource::writeConfig( config ); 102 Resource::writeConfig( config );
105} 103}
106 104
107Ticket *ResourceSharpDTM::requestSaveTicket() 105Ticket *ResourceSharpDTM::requestSaveTicket()
108{ 106{
109 107
110 108
111 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 109 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
112 110
113 if ( !addressBook() ) return 0; 111 if ( !addressBook() ) return 0;
114 112
115#ifdef ALLOW_LOCKING 113#ifdef ALLOW_LOCKING
116 if ( !lock( fileName() ) ) { 114 if ( !lock( fileName() ) ) {
117 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); 115 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
118 return 0; 116 return 0;
119 } 117 }
120#endif 118#endif
121 return createTicket( this ); 119 return createTicket( this );
122} 120}
123 121
124 122
125bool ResourceSharpDTM::doOpen() 123bool ResourceSharpDTM::doOpen()
126{ 124{
127 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); 125 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1());
128 126
129 // the last parameter in the SlZDataBase constructor means "readonly" 127 // the last parameter in the SlZDataBase constructor means "readonly"
130 mAccess = new SlZDataBase(fileName(), 128 mAccess = new SlZDataBase(fileName(),
131 SlZDataBase::addressbookItems(), 129 SlZDataBase::addressbookItems(),
132 NULL, false); 130 NULL, false);
133 131
134 if ( !mAccess ) { 132 if ( !mAccess ) {
135 qDebug("Unable to load file() %s", fileName().latin1()); 133 qDebug("Unable to load file() %s", fileName().latin1());
136 return false; 134 return false;
137 } 135 }
138 136
139 if (mConverter == 0) 137 if (mConverter == 0)
140 { 138 {
141 mConverter = new SharpDTMConverter(); 139 mConverter = new SharpDTMConverter();
142 bool res = mConverter->init(); 140 bool res = mConverter->init();
143 if ( !res ) 141 if ( !res )
144 { 142 {
145 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); 143 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
146 144
147 qDebug(msg); 145 qDebug(msg);
148 delete mAccess; 146 delete mAccess;
149 mAccess = 0; 147 mAccess = 0;
150 return false; 148 return false;
151 } 149 }
152 } 150 }
153 151
154 return true; 152 return true;
155} 153}
156 154
157void ResourceSharpDTM::doClose() 155void ResourceSharpDTM::doClose()
158{ 156{
159 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); 157 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
160 158
161 if(mAccess) 159 if(mAccess)
162 { 160 {
163 delete mAccess; 161 delete mAccess;
164 mAccess = 0; 162 mAccess = 0;
165 } 163 }
166 // it seems so, that deletion of access deletes backend as well 164 // it seems so, that deletion of access deletes backend as well
167 //delete backend; 165 //delete backend;
168 166
169 return; 167 return;
170} 168}
171 169
172bool ResourceSharpDTM::load() 170bool ResourceSharpDTM::load()
173{ 171{
174 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 172 qDebug("ResourceSharpDTM::load: %s", fileName().latin1());
175 173
176 bool res = false; 174 bool res = false;
177 175
178 CardId id; 176 CardId id;
179 177
180 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 178 for (bool res=mAccess->first(); res == true; res=mAccess->next())
181 { 179 {
182 id = mAccess->cardId(); 180 id = mAccess->cardId();
183 181
184 KABC::Addressee addressee; 182 KABC::Addressee addressee;
185 183
186 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 184 res = mConverter->sharpToAddressee( id, mAccess, addressee );
187 185
188 if ( !addressee.isEmpty() && res ) 186 if ( !addressee.isEmpty() && res )
189 { 187 {
190 addressee.setResource( this ); 188 addressee.setResource( this );
191 addressBook()->insertAddressee( addressee ); 189 addressBook()->insertAddressee( addressee );
192 } 190 }
193 } 191 }
194 192
195 return true; 193 return true;
196} 194}
197 195
198bool ResourceSharpDTM::save( Ticket *ticket ) 196bool ResourceSharpDTM::save( Ticket *ticket )
199{ 197{
200 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 198 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
201 199
202 mDirWatch.stopScan(); 200 mDirWatch.stopScan();
203 201
204 KABC::AddressBook::Iterator it; 202 KABC::AddressBook::Iterator it;
205 bool res; 203 bool res;
206 KABC::Addressee::List changedAddressees; 204 KABC::Addressee::List changedAddressees;
207 typedef QMap<int,QString> AddresseeMap; 205 typedef QMap<int,QString> AddresseeMap;
208 AddresseeMap map; 206 AddresseeMap map;
209 CardId id ; 207 CardId id ;
210 208
211 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 209 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
212 210
213 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 211 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
214 QString uid = (*it).originalExternalUID(); 212 QString uid = (*it).originalExternalUID();
215 bool res; 213 bool res;
216 if ( uid.isEmpty() ) 214 if ( uid.isEmpty() )
217 id = 0; 215 id = 0;
218 else 216 else
219 id = uid.toUInt(); 217 id = uid.toUInt();
220 KABC::Addressee addressee = (*it); 218 KABC::Addressee addressee = (*it);
221 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 219 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
222 res = mAccess->startEditCard(id); 220 res = mAccess->startEditCard(id);
223 if (res == true) 221 if (res == true)
224 { 222 {
225 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 223 res = mConverter->addresseeToSharp( (*it), mAccess, id );
226 if (res == true) 224 if (res == true)
227 { 225 {
228 res = mAccess->finishEditCard(&id); 226 res = mAccess->finishEditCard(&id);
229 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 227 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
230 //(*it).setExternalUID( QString::number( id ) ); 228 //(*it).setExternalUID( QString::number( id ) );
231 //(*it).setOriginalExternalUID( QString::number( id ) ); 229 //(*it).setOriginalExternalUID( QString::number( id ) );
232 map.insert(id,(*it).uid()); 230 map.insert(id,(*it).uid());
233 if (res == false) 231 if (res == false)
234 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 232 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
235 233
236 } 234 }
237 else 235 else
238 { 236 {
239 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 237 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
240 mAccess->cancelEditCard(); 238 mAccess->cancelEditCard();
241 } 239 }
242 } 240 }
243 241
244 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 242 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
245 res = mAccess->deleteCard(&id); 243 res = mAccess->deleteCard(&id);
246 if ( !res ) 244 if ( !res )
247 qDebug("delete error "); 245 qDebug("delete error ");
248 246
249 247
250 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 248 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
251 //changed 249 //changed
252 res = mAccess->startEditCard(id); 250 res = mAccess->startEditCard(id);
253 if (res == true) 251 if (res == true)
254 { 252 {
255 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 253 res = mConverter->addresseeToSharp( (*it), mAccess, id );
256 if (res == true) 254 if (res == true)
257 { 255 {
258 res = mAccess->finishEditCard(&id); 256 res = mAccess->finishEditCard(&id);
259 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 257 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
260 map.insert(id,(*it).uid()); 258 map.insert(id,(*it).uid());
261 if (res == false) 259 if (res == false)
262 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 260 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
263 261
264 } 262 }
265 else 263 else
266 { 264 {
267 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 265 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
268 mAccess->cancelEditCard(); 266 mAccess->cancelEditCard();
269 } 267 }
270 } 268 }
271 } 269 }
272 } 270 }
273 271
274 } 272 }
275 AddresseeMap::Iterator itam; 273 AddresseeMap::Iterator itam;
276 for ( res=mAccess->first(); res == true; res=mAccess->next()) 274 for ( res=mAccess->first(); res == true; res=mAccess->next())
277 { 275 {
278 id = mAccess->cardId(); 276 id = mAccess->cardId();
279 int idint = id; 277 int idint = id;
280 itam = map.find( idint ); 278 itam = map.find( idint );
281 if ( itam != map.end() ) { 279 if ( itam != map.end() ) {
282 KABC::Addressee addressee; 280 KABC::Addressee addressee;
283 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 281 res = mConverter->sharpToAddressee( id, mAccess, addressee );
284 282
285 if ( !addressee.isEmpty() && res ) 283 if ( !addressee.isEmpty() && res )
286 { 284 {
287 addressee.setResource( this ); 285 addressee.setResource( this );
288 addressee.setUid( itam.data() ); 286 addressee.setUid( itam.data() );
289 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 287 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
290 addressBook()->insertAddressee( addressee , false ); 288 addressBook()->insertAddressee( addressee , false );
291 } 289 }
292 } 290 }
293 } 291 }
294 292
295 //US mAccess->save(); 293 //US mAccess->save();
296 294
297 mDirWatch.startScan(); 295 mDirWatch.startScan();
298 delete ticket; 296 delete ticket;
299 unlock( fileName() ); 297 unlock( fileName() );
300 298
301 return true; 299 return true;
302} 300}
303 301
304bool ResourceSharpDTM::lock( const QString &lockfileName ) 302bool ResourceSharpDTM::lock( const QString &lockfileName )
305{ 303{
306#ifdef ALLOW_LOCKING 304#ifdef ALLOW_LOCKING
307 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); 305 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
308 306
309 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; 307 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
310 308
311 QString fn = lockfileName; 309 QString fn = lockfileName;
312 310
313 KURL url(fn); 311 KURL url(fn);
314 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 312 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
315 313
316 kdDebug(5700) << "-- lock name: " << lockName << endl; 314 kdDebug(5700) << "-- lock name: " << lockName << endl;
317 315
318 if (QFile::exists( lockName )) 316 if (QFile::exists( lockName ))
319 { 317 {
320 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); 318 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
321 return false; 319 return false;
322 } 320 }
323 321
324 322
325 QString lockUniqueName; 323 QString lockUniqueName;
326 lockUniqueName = fn + KApplication::randomString( 8 ); 324 lockUniqueName = fn + KApplication::randomString( 8 );
327 325
328 url = lockUniqueName; 326 url = lockUniqueName;
329//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 327//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
330 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 328 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
331 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 329 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
332 330
333 // Create unique file 331 // Create unique file
334 QFile file( mLockUniqueName ); 332 QFile file( mLockUniqueName );
335 file.open( IO_WriteOnly ); 333 file.open( IO_WriteOnly );
336 file.close(); 334 file.close();
337 335
338 // Create lock file 336 // Create lock file
339 int result = 0; 337 int result = 0;
340#ifndef _WIN32_ 338#ifndef _WIN32_
341 result = ::link( QFile::encodeName( mLockUniqueName ), 339 result = ::link( QFile::encodeName( mLockUniqueName ),
342 QFile::encodeName( lockName ) ); 340 QFile::encodeName( lockName ) );
343#endif 341#endif
344 if ( result == 0 ) { 342 if ( result == 0 ) {
345 addressBook()->emitAddressBookLocked(); 343 addressBook()->emitAddressBookLocked();
346 return true; 344 return true;
347 } 345 }
348 346
349 // TODO: check stat 347 // TODO: check stat
350 348
351 return false; 349 return false;
352#else 350#else
353 return true; 351 return true;
354#endif 352#endif
355} 353}
356 354
357void ResourceSharpDTM::unlock( const QString &fileName ) 355void ResourceSharpDTM::unlock( const QString &fileName )
358{ 356{
359#ifdef ALLOW_LOCKING 357#ifdef ALLOW_LOCKING
360 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); 358 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
361 359
362 QString fn = fileName; 360 QString fn = fileName;
363 KURL url(fn); 361 KURL url(fn);
364 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 362 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
365 363
366 QFile::remove( lockName ); 364 QFile::remove( lockName );
367 QFile::remove( mLockUniqueName ); 365 QFile::remove( mLockUniqueName );
368 addressBook()->emitAddressBookUnlocked(); 366 addressBook()->emitAddressBookUnlocked();
369#endif 367#endif
370} 368}
371 369
372void ResourceSharpDTM::setFileName( const QString &newFileName ) 370void ResourceSharpDTM::setFileName( const QString &newFileName )
373{ 371{
374 mDirWatch.stopScan(); 372 mDirWatch.stopScan();
375 mDirWatch.removeFile( fileName() ); 373 mDirWatch.removeFile( fileName() );
376 374
377 Resource::setFileName( newFileName ); 375 Resource::setFileName( newFileName );
378 376
379 mDirWatch.addFile( fileName() ); 377 mDirWatch.addFile( fileName() );
380 mDirWatch.startScan(); 378 mDirWatch.startScan();
381 379
382} 380}
383 381
384void ResourceSharpDTM::fileChanged() 382void ResourceSharpDTM::fileChanged()
385{ 383{
386 // There is a small theoretical chance that KDirWatch calls us before 384 // There is a small theoretical chance that KDirWatch calls us before
387 // we are fully constructed 385 // we are fully constructed
388 if (!addressBook()) 386 if (!addressBook())
389 return; 387 return;
390 388
391 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 389 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
392 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
393 load(); 391 load();
394 addressBook()->emitAddressBookChanged(); 392 addressBook()->emitAddressBookChanged();
395 } 393 }
396} 394}
397 395
398void ResourceSharpDTM::removeAddressee( const Addressee &addr ) 396void ResourceSharpDTM::removeAddressee( const Addressee &addr )
399{ 397{
400} 398}
401 399
402void ResourceSharpDTM::cleanUp() 400void ResourceSharpDTM::cleanUp()
403{ 401{
404 unlock( fileName() ); 402 unlock( fileName() );
405} 403}
406 404
407 405
408 406
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.h b/kabc/plugins/sharpdtm/resourcesharpdtm.h
index f386e69..64d06f9 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.h
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.h
@@ -1,146 +1,146 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
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 28
29#ifndef KABC_RESOURCESHARPDTM_H 29#ifndef KABC_RESOURCESHARPDTM_H
30#define KABC_RESOURCESHARPDTM_H 30#define KABC_RESOURCESHARPDTM_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include "resource.h" 37#include "resource.h"
38 38
39 39
40class SlZDataBase; 40class SlZDataBase;
41 41
42namespace KABC { 42namespace KABC {
43 43
44class ResourceConfigWidget; 44class ResourceConfigWidget;
45class SharpDTMConverter; 45class SharpDTMConverter;
46 46
47/** 47/**
48 @internal 48 @internal
49*/ 49*/
50class ResourceSharpDTM : public Resource 50class ResourceSharpDTM : public Resource
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 55
56 /** 56 /**
57 Constructor. 57 Constructor.
58 58
59 @param cfg The config object where custom resource settings are stored. 59 @param cfg The config object where custom resource settings are stored.
60 */ 60 */
61 ResourceSharpDTM( const KConfig *cfg, bool syncable ); 61 ResourceSharpDTM( const KConfig *cfg );
62 62
63 /** 63 /**
64 Construct file resource on file @arg fileName using format @arg formatName. 64 Construct file resource on file @arg fileName using format @arg formatName.
65 */ 65 */
66 ResourceSharpDTM( const QString &fileName, bool syncable ); 66 ResourceSharpDTM( const QString &fileName );
67 67
68 /** 68 /**
69 * Destructor. 69 * Destructor.
70 */ 70 */
71 ~ResourceSharpDTM(); 71 ~ResourceSharpDTM();
72 72
73 /** 73 /**
74 Writes the config back. 74 Writes the config back.
75 */ 75 */
76 virtual void writeConfig( KConfig *cfg ); 76 virtual void writeConfig( KConfig *cfg );
77 77
78 /** 78 /**
79 * Tries to open the file and checks for the proper format. 79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load(). 80 * This method should be called before @ref load().
81 */ 81 */
82 virtual bool doOpen(); 82 virtual bool doOpen();
83 83
84 /** 84 /**
85 * Closes the file again. 85 * Closes the file again.
86 */ 86 */
87 virtual void doClose(); 87 virtual void doClose();
88 88
89 /** 89 /**
90 * Requests a save ticket, that is used by @ref save() 90 * Requests a save ticket, that is used by @ref save()
91 */ 91 */
92 virtual Ticket *requestSaveTicket(); 92 virtual Ticket *requestSaveTicket();
93 93
94 /** 94 /**
95 * Loads all addressees from file to the address book. 95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false. 96 * Returns true if all addressees could be loaded otherwise false.
97 */ 97 */
98 virtual bool load(); 98 virtual bool load();
99 99
100 /** 100 /**
101 * Saves all addresses from address book to file. 101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false. 102 * Returns true if all addressees could be saved otherwise false.
103 * 103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket() 104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */ 105 */
106 virtual bool save( Ticket *ticket ); 106 virtual bool save( Ticket *ticket );
107 107
108 /** 108 /**
109 * Remove a addressee from its source. 109 * Remove a addressee from its source.
110 * This method is mainly called by KABC::AddressBook. 110 * This method is mainly called by KABC::AddressBook.
111 */ 111 */
112 virtual void removeAddressee( const Addressee& addr ); 112 virtual void removeAddressee( const Addressee& addr );
113 113
114 /** 114 /**
115 * Set name of file to be used for saving. 115 * Set name of file to be used for saving.
116 */ 116 */
117 virtual void setFileName( const QString & ); 117 virtual void setFileName( const QString & );
118 118
119 /** 119 /**
120 * This method is called by an error handler if the application 120 * This method is called by an error handler if the application
121 * crashed 121 * crashed
122 */ 122 */
123 virtual void cleanUp(); 123 virtual void cleanUp();
124 124
125 125
126protected slots: 126protected slots:
127 void fileChanged(); 127 void fileChanged();
128 128
129protected: 129protected:
130 void init( const QString &fileName ); 130 void init( const QString &fileName );
131 131
132 bool lock( const QString &fileName ); 132 bool lock( const QString &fileName );
133 void unlock( const QString &fileName ); 133 void unlock( const QString &fileName );
134 134
135private: 135private:
136 SlZDataBase* mAccess; 136 SlZDataBase* mAccess;
137 SharpDTMConverter* mConverter; 137 SharpDTMConverter* mConverter;
138 138
139 QString mLockUniqueName; 139 QString mLockUniqueName;
140 140
141 KDirWatch mDirWatch; 141 KDirWatch mDirWatch;
142}; 142};
143 143
144} 144}
145 145
146#endif 146#endif
diff --git a/kabc/resource.cpp b/kabc/resource.cpp
index 7b91239..267cdaf 100644
--- a/kabc/resource.cpp
+++ b/kabc/resource.cpp
@@ -1,144 +1,116 @@
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#include <kdebug.h> 28#include <kdebug.h>
29 29
30#include <ksyncprofile.h>
31
32#include "resource.h" 30#include "resource.h"
33 31
34using namespace KABC; 32using namespace KABC;
35 33
36Resource::Resource( const KConfig *config, bool syncable ) 34Resource::Resource( const KConfig *config )
37 : KRES::Resource( config ), mAddressBook( 0 ), mSyncProfile( 0 ) 35 : KRES::Resource( config ), mAddressBook( 0 )
38{ 36{
39 if(syncable == true) {
40 mSyncProfile = new KSyncProfile( );
41 mSyncProfile->setName("pending" /*resourceName()*/);
42 mSyncProfile->readConfig( (KConfig *)config );
43 }
44} 37}
45 38
46Resource::~Resource() 39Resource::~Resource()
47{ 40{
48 if (mSyncProfile != 0) {
49 delete mSyncProfile;
50 }
51} 41}
52 42
53void Resource::writeConfig( KConfig *config ) 43void Resource::writeConfig( KConfig *config )
54{ 44{
55 KRES::Resource::writeConfig( config ); 45 KRES::Resource::writeConfig( config );
56
57 if(mSyncProfile != 0)
58 mSyncProfile->writeConfig( config );
59} 46}
60 47
61 48
62void Resource::setAddressBook( AddressBook *ab ) 49void Resource::setAddressBook( AddressBook *ab )
63{ 50{
64 mAddressBook = ab; 51 mAddressBook = ab;
65} 52}
66 53
67AddressBook *Resource::addressBook() 54AddressBook *Resource::addressBook()
68{ 55{
69 return mAddressBook; 56 return mAddressBook;
70} 57}
71 58
72bool Resource::doOpen() 59bool Resource::doOpen()
73{ 60{
74 return true; 61 return true;
75} 62}
76 63
77void Resource::doClose() 64void Resource::doClose()
78{ 65{
79} 66}
80 67
81Ticket *Resource::requestSaveTicket() 68Ticket *Resource::requestSaveTicket()
82{ 69{
83 return 0; 70 return 0;
84} 71}
85 72
86bool Resource::load() 73bool Resource::load()
87{ 74{
88 return true; 75 return true;
89} 76}
90 77
91bool Resource::save( Ticket * ) 78bool Resource::save( Ticket * )
92{ 79{
93 return false; 80 return false;
94} 81}
95 82
96Ticket *Resource::createTicket( Resource *resource ) 83Ticket *Resource::createTicket( Resource *resource )
97{ 84{
98 return new Ticket( resource ); 85 return new Ticket( resource );
99} 86}
100 87
101void Resource::removeAddressee( const Addressee& ) 88void Resource::removeAddressee( const Addressee& )
102{ 89{
103 // do nothing 90 // do nothing
104} 91}
105 92
106void Resource::cleanUp() 93void Resource::cleanUp()
107{ 94{
108 // do nothing 95 // do nothing
109} 96}
110 97
111bool Resource::isSyncable() const
112{
113 return (mSyncProfile != 0);
114}
115
116KSyncProfile* Resource::getSyncProfile()
117{
118 return mSyncProfile;
119}
120
121
122QString Resource::fileName() const 98QString Resource::fileName() const
123{ 99{
124 return mFileName; 100 return mFileName;
125} 101}
126 102
127void Resource::setFileName( const QString &fileName ) 103void Resource::setFileName( const QString &fileName )
128{ 104{
129 mFileName = fileName; 105 mFileName = fileName;
130} 106}
131 107
132/** 108/**
133 * Set the name of resource.You can override this method, 109 * Set the name of resource.You can override this method,
134 * but also remember to call Resource::setResourceName(). 110 * but also remember to call Resource::setResourceName().
135 */ 111 */
136void Resource::setResourceName( const QString &name ) 112void Resource::setResourceName( const QString &name )
137{ 113{
138 KRES::Resource::setResourceName(name); 114 KRES::Resource::setResourceName(name);
139 if(mSyncProfile != 0) {
140 mSyncProfile->setName( name );
141 }
142
143} 115}
144 116
diff --git a/kabc/resource.h b/kabc/resource.h
index 2024d2d..e5f0d5d 100644
--- a/kabc/resource.h
+++ b/kabc/resource.h
@@ -1,171 +1,157 @@
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_RESOURCE_H 28#ifndef KABC_RESOURCE_H
29#define KABC_RESOURCE_H 29#define KABC_RESOURCE_H
30 30
31#include <kresources/resource.h> 31#include <kresources/resource.h>
32 32
33 33
34#include "addressbook.h" 34#include "addressbook.h"
35 35
36class KSyncProfile;
37
38namespace KABC { 36namespace KABC {
39 37
40/** 38/**
41 * @short Helper class for handling coordinated save of address books. 39 * @short Helper class for handling coordinated save of address books.
42 * 40 *
43 * This class is used as helper class for saving address book. 41 * This class is used as helper class for saving address book.
44 * @see requestSaveTicket(), save(). 42 * @see requestSaveTicket(), save().
45 */ 43 */
46class Ticket 44class Ticket
47{ 45{
48 friend class Resource; 46 friend class Resource;
49 public: 47 public:
50 Resource *resource() { return mResource; } 48 Resource *resource() { return mResource; }
51 49
52 private: 50 private:
53 Ticket( Resource *resource ) : mResource( resource ) {} 51 Ticket( Resource *resource ) : mResource( resource ) {}
54 52
55 Resource *mResource; 53 Resource *mResource;
56}; 54};
57 55
58/** 56/**
59 * @internal 57 * @internal
60 */ 58 */
61class Resource : public KRES::Resource 59class Resource : public KRES::Resource
62{ 60{
63private:
64 /**
65 * make this constructor private to force everybody to use the other one
66 */
67 Resource( const KConfig *config);
68
69public: 61public:
70 /** 62 /**
71 * Constructor 63 * Constructor
72 */ 64 */
73 Resource( const KConfig *config, bool syncable ); 65 Resource( const KConfig *config );
74 66
75 /** 67 /**
76 * Destructor. 68 * Destructor.
77 */ 69 */
78 virtual ~Resource(); 70 virtual ~Resource();
79 71
80 /** 72 /**
81 * Sets the address book of the resource. 73 * Sets the address book of the resource.
82 */ 74 */
83 void setAddressBook( AddressBook* ); 75 void setAddressBook( AddressBook* );
84 76
85 /** 77 /**
86 * Returns a pointer to the addressbook. 78 * Returns a pointer to the addressbook.
87 */ 79 */
88 AddressBook *addressBook(); 80 AddressBook *addressBook();
89 81
90 /** 82 /**
91 * Writes the resource specific config to file. 83 * Writes the resource specific config to file.
92 */ 84 */
93 virtual void writeConfig( KConfig *config ); 85 virtual void writeConfig( KConfig *config );
94 86
95 /** 87 /**
96 * Open the resource and returns if it was successfully 88 * Open the resource and returns if it was successfully
97 */ 89 */
98 virtual bool doOpen(); 90 virtual bool doOpen();
99 91
100 92
101 /** 93 /**
102 * Request a ticket, you have to pass through @ref save() to 94 * Request a ticket, you have to pass through @ref save() to
103 * allow locking. 95 * allow locking.
104 */ 96 */
105 virtual Ticket *requestSaveTicket(); 97 virtual Ticket *requestSaveTicket();
106 98
107 /** 99 /**
108 * Load all addressees to the addressbook 100 * Load all addressees to the addressbook
109 */ 101 */
110 virtual bool load(); 102 virtual bool load();
111 103
112 /** 104 /**
113 * Save all addressees to the addressbook. 105 * Save all addressees to the addressbook.
114 * 106 *
115 * @param ticket The ticket you get by @ref requestSaveTicket() 107 * @param ticket The ticket you get by @ref requestSaveTicket()
116 */ 108 */
117 virtual bool save( Ticket *ticket ); 109 virtual bool save( Ticket *ticket );
118 110
119 /** 111 /**
120 * Removes a addressee from resource. This method is mainly 112 * Removes a addressee from resource. This method is mainly
121 * used by record-based resources like LDAP or SQL. 113 * used by record-based resources like LDAP or SQL.
122 */ 114 */
123 virtual void removeAddressee( const Addressee& addr ); 115 virtual void removeAddressee( const Addressee& addr );
124 116
125 117
126 /** 118 /**
127 * This method is called by an error handler if the application 119 * This method is called by an error handler if the application
128 * crashed 120 * crashed
129 */ 121 */
130 virtual void cleanUp(); 122 virtual void cleanUp();
131 123
132 /** 124 /**
133 * Set name of file to be used for saving. 125 * Set name of file to be used for saving.
134 */ 126 */
135 virtual void setFileName( const QString & ); 127 virtual void setFileName( const QString & );
136 128
137 /** 129 /**
138 * Return name of file used for loading and saving the address book. 130 * Return name of file used for loading and saving the address book.
139 */ 131 */
140 virtual QString fileName() const; 132 virtual QString fileName() const;
141 133
142
143 virtual bool isSyncable() const;
144
145 virtual KSyncProfile* getSyncProfile();
146
147 /** 134 /**
148 * Set the name of resource.You can override this method, 135 * Set the name of resource.You can override this method,
149 * but also remember to call Resource::setResourceName(). 136 * but also remember to call Resource::setResourceName().
150 */ 137 */
151 virtual void setResourceName( const QString &name ); 138 virtual void setResourceName( const QString &name );
152 139
153 140
154 141
155protected: 142protected:
156 Ticket *createTicket( Resource * ); 143 Ticket *createTicket( Resource * );
157 virtual void doClose(); 144 virtual void doClose();
158 145
159private: 146private:
160 AddressBook *mAddressBook; 147 AddressBook *mAddressBook;
161 KSyncProfile *mSyncProfile;
162 QString mFileName; 148 QString mFileName;
163 149
164}; 150};
165 151
166 152
167} 153}
168 154
169 155
170 156
171#endif 157#endif
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
index 4351753..67e8406 100644
--- a/kaddressbook/xxportobject.cpp
+++ b/kaddressbook/xxportobject.cpp
@@ -1,273 +1,273 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qmap.h> 31#include <qmap.h>
32#include <qsignalmapper.h> 32#include <qsignalmapper.h>
33 33
34#include <kaction.h> 34#include <kaction.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36#include <factory.h> 36#include <factory.h>
37 37
38#include "kabcore.h" 38#include "kabcore.h"
39#include "addressee.h" 39#include "addressee.h"
40#include "tmpaddressbook.h" 40#include "tmpaddressbook.h"
41#include "xxportobject.h" 41#include "xxportobject.h"
42 42
43 43
44class XXPortObject::XXPortObjectPrivate 44class XXPortObject::XXPortObjectPrivate
45{ 45{
46 public: 46 public:
47 QSignalMapper *mExportMapper; 47 QSignalMapper *mExportMapper;
48 QSignalMapper *mImportMapper; 48 QSignalMapper *mImportMapper;
49}; 49};
50 50
51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent, 51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
52 const char *name ) 52 const char *name )
53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ), 53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
54 d( new XXPortObjectPrivate ) 54 d( new XXPortObjectPrivate )
55{ 55{
56 d->mExportMapper = new QSignalMapper( this ); 56 d->mExportMapper = new QSignalMapper( this );
57 d->mImportMapper = new QSignalMapper( this ); 57 d->mImportMapper = new QSignalMapper( this );
58 58
59 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ), 59 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ),
60 SLOT( slotExportActivated( const QString& ) ) ); 60 SLOT( slotExportActivated( const QString& ) ) );
61 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ), 61 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ),
62 SLOT( slotImportActivated( const QString& ) ) ); 62 SLOT( slotImportActivated( const QString& ) ) );
63} 63}
64 64
65XXPortObject::~XXPortObject() 65XXPortObject::~XXPortObject()
66{ 66{
67 delete d; 67 delete d;
68 d = 0; 68 d = 0;
69} 69}
70 70
71bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& ) 71bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& )
72{ 72{
73 // do nothing 73 // do nothing
74 return false; 74 return false;
75} 75}
76 76
77KABC::AddresseeList XXPortObject::importContacts( const QString& ) const 77KABC::AddresseeList XXPortObject::importContacts( const QString& ) const
78{ 78{
79 // do nothing 79 // do nothing
80 return KABC::AddresseeList(); 80 return KABC::AddresseeList();
81} 81}
82 82
83void XXPortObject::createImportAction( const QString &label, const QString &data ) 83void XXPortObject::createImportAction( const QString &label, const QString &data )
84{ 84{
85#ifdef KAB_EMBEDDED 85#ifdef KAB_EMBEDDED
86 KABCore* kabcore = (KABCore*)mParentWidget; 86 KABCore* kabcore = (KABCore*)mParentWidget;
87#endif //KAB_EMBEDDED 87#endif //KAB_EMBEDDED
88 88
89 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 89 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
90#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
91 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 91 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() );
92#else //KAB_EMBEDDED 92#else //KAB_EMBEDDED
93 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() ); 93 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
94#endif //KAB_EMBEDDED 94#endif //KAB_EMBEDDED
95 95
96 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 96 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
97 97
98#ifndef KAB_EMBEDDED 98#ifndef KAB_EMBEDDED
99 setXMLFile( identifier() + "_xxportui.rc" ); 99 setXMLFile( identifier() + "_xxportui.rc" );
100#endif //KAB_EMBEDDED 100#endif //KAB_EMBEDDED
101 101
102#ifdef KAB_EMBEDDED 102#ifdef KAB_EMBEDDED
103 action->plug((QWidget*)kabcore->getImportMenu()); 103 action->plug((QWidget*)kabcore->getImportMenu());
104#endif //KAB_EMBEDDED 104#endif //KAB_EMBEDDED
105 105
106} 106}
107 107
108void XXPortObject::createExportAction( const QString &label, const QString &data ) 108void XXPortObject::createExportAction( const QString &label, const QString &data )
109{ 109{
110#ifdef KAB_EMBEDDED 110#ifdef KAB_EMBEDDED
111 KABCore* kabcore = (KABCore*)mParentWidget; 111 KABCore* kabcore = (KABCore*)mParentWidget;
112#endif //KAB_EMBEDDED 112#endif //KAB_EMBEDDED
113 113
114 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 114 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
115#ifndef KAB_EMBEDDED 115#ifndef KAB_EMBEDDED
116 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 116 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() );
117#else //KAB_EMBEDDED 117#else //KAB_EMBEDDED
118 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() ); 118 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
119#endif //KAB_EMBEDDED 119#endif //KAB_EMBEDDED
120 120
121 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 121 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
122 122
123#ifndef KAB_EMBEDDED 123#ifndef KAB_EMBEDDED
124 setXMLFile( identifier() + "_xxportui.rc" ); 124 setXMLFile( identifier() + "_xxportui.rc" );
125#endif //KAB_EMBEDDED 125#endif //KAB_EMBEDDED
126 126
127#ifdef KAB_EMBEDDED 127#ifdef KAB_EMBEDDED
128 action->plug((QWidget*)kabcore->getExportMenu()); 128 action->plug((QWidget*)kabcore->getExportMenu());
129#endif //KAB_EMBEDDED 129#endif //KAB_EMBEDDED
130 130
131} 131}
132 132
133KABC::AddressBook *XXPortObject::addressBook() const 133KABC::AddressBook *XXPortObject::addressBook() const
134{ 134{
135 return mAddressBook; 135 return mAddressBook;
136} 136}
137 137
138QWidget *XXPortObject::parentWidget() const 138QWidget *XXPortObject::parentWidget() const
139{ 139{
140 return mParentWidget; 140 return mParentWidget;
141} 141}
142 142
143void XXPortObject::slotExportActivated( const QString &data ) 143void XXPortObject::slotExportActivated( const QString &data )
144{ 144{
145 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 145 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
146} 146}
147 147
148void XXPortObject::slotImportActivated( const QString &data ) 148void XXPortObject::slotImportActivated( const QString &data )
149{ 149{
150 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 150 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
151} 151}
152 152
153/******************************************************************** 153/********************************************************************
154 * 154 *
155 *******************************************************************/ 155 *******************************************************************/
156 156
157 157
158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, 158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent,
159 const char *name ) 159 const char *name )
160 : XXPortObject( ab, parent, name ), mFactory(0) 160 : XXPortObject( ab, parent, name ), mFactory(0)
161{ 161{
162 mFactory = KRES::Factory::self( "tmpcontact" ); 162 mFactory = KRES::Factory::self( "tmpcontact" );
163} 163}
164 164
165XXPortResourceObject::~XXPortResourceObject() 165XXPortResourceObject::~XXPortResourceObject()
166{ 166{
167 //do not delete the factory. It is a singleton, and selfcontained 167 //do not delete the factory. It is a singleton, and selfcontained
168} 168}
169 169
170bool XXPortResourceObject::isAvailable() 170bool XXPortResourceObject::isAvailable()
171{ 171{
172 return (mFactory != 0); 172 return (mFactory != 0);
173} 173}
174 174
175 175
176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName ) 176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName )
177{ 177{
178 //create new resource 178 //create new resource
179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false )); 179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
180 180
181 if (mResource == 0) 181 if (mResource == 0)
182 return false; 182 return false;
183 183
184 if (fileName != QString::null) 184 if (fileName != QString::null)
185 mResource->setFileName( fileName ); 185 mResource->setFileName( fileName );
186 186
187 187
188 KABC::TmpAddressBook tmpAB; 188 KABC::TmpAddressBook tmpAB;
189 189
190 bool res = tmpAB.addResource( mResource ); 190 bool res = tmpAB.addResource( mResource );
191 if (res == false) 191 if (res == false)
192 { 192 {
193 delete mResource; 193 delete mResource;
194 return false; 194 return false;
195 } 195 }
196 196
197 res = tmpAB.load(); 197 res = tmpAB.load();
198 if (res == false) 198 if (res == false)
199 { 199 {
200 //removeResource deletes also the resource object, if the linkcount is 0 200 //removeResource deletes also the resource object, if the linkcount is 0
201 tmpAB.removeResource( mResource ); 201 tmpAB.removeResource( mResource );
202 return false; 202 return false;
203 } 203 }
204 204
205 205
206 //Now check if the file has already entries, and ask the user if he wants to delete them first. 206 //Now check if the file has already entries, and ask the user if he wants to delete them first.
207 if (tmpAB.begin() != tmpAB.end()) 207 if (tmpAB.begin() != tmpAB.end())
208 { 208 {
209 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 209 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
210 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 210 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
211 // Clean the database.. 211 // Clean the database..
212 tmpAB.clear(); 212 tmpAB.clear();
213 } 213 }
214 } 214 }
215 215
216 216
217 KABC::Addressee::List::ConstIterator it; 217 KABC::Addressee::List::ConstIterator it;
218 for ( it = list.begin(); it != list.end(); ++it ) { 218 for ( it = list.begin(); it != list.end(); ++it ) {
219 tmpAB.insertAddressee(*it); 219 tmpAB.insertAddressee(*it);
220 } 220 }
221 221
222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource); 222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
223 223
224 res = false; 224 res = false;
225 if (ticket != 0) 225 if (ticket != 0)
226 res = tmpAB.save( ticket ); 226 res = tmpAB.save( ticket );
227 227
228 //removeResource deletes also the resource object, if the linkcount is 0 228 //removeResource deletes also the resource object, if the linkcount is 0
229 tmpAB.removeResource( mResource ); 229 tmpAB.removeResource( mResource );
230 230
231 return res; 231 return res;
232} 232}
233 233
234 234
235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const 235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const
236{ 236{
237 237
238 238
239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false )); 239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
240 240
241 if (mResource == 0) 241 if (mResource == 0)
242 return KABC::AddresseeList(); 242 return KABC::AddresseeList();
243 243
244 KABC::AddresseeList adrlst; 244 KABC::AddresseeList adrlst;
245 245
246 if (fileName != QString::null) 246 if (fileName != QString::null)
247 mResource->setFileName( fileName ); 247 mResource->setFileName( fileName );
248 248
249 249
250 KABC::TmpAddressBook tmpAB; 250 KABC::TmpAddressBook tmpAB;
251 251
252 bool res = tmpAB.addResource( mResource ); 252 bool res = tmpAB.addResource( mResource );
253 if (res == false) 253 if (res == false)
254 { 254 {
255 delete mResource; 255 delete mResource;
256 return KABC::AddresseeList(); 256 return KABC::AddresseeList();
257 } 257 }
258 258
259 res = tmpAB.load(); 259 res = tmpAB.load();
260 260
261 adrlst = tmpAB.allAddressees(); 261 adrlst = tmpAB.allAddressees();
262 262
263 //remove resource deletes also the Resourceobject, if the linkcount is 0 263 //remove resource deletes also the Resourceobject, if the linkcount is 0
264 tmpAB.removeResource( mResource ); 264 tmpAB.removeResource( mResource );
265 265
266 return adrlst; 266 return adrlst;
267} 267}
268 268
269 269
270 270
271#ifndef KAB_EMBEDDED 271#ifndef KAB_EMBEDDED
272#include "xxportobject.moc" 272#include "xxportobject.moc"
273#endif //KAB_EMBEDDED 273#endif //KAB_EMBEDDED
diff --git a/microkde/kresources/configdialog.cpp b/microkde/kresources/configdialog.cpp
index 030b547..24e82bc 100644
--- a/microkde/kresources/configdialog.cpp
+++ b/microkde/kresources/configdialog.cpp
@@ -1,246 +1,179 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24#include <klocale.h> 24#include <klocale.h>
25#include <kglobal.h> 25#include <kglobal.h>
26#include <kmessagebox.h> 26#include <kmessagebox.h>
27 27
28#include <qgroupbox.h> 28#include <qgroupbox.h>
29#include <qlabel.h> 29#include <qlabel.h>
30#include <qlayout.h> 30#include <qlayout.h>
31#include <qpushbutton.h> 31#include <qpushbutton.h>
32#include <qvbox.h> 32#include <qvbox.h>
33 33
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qscrollview.h> 35#include <qscrollview.h>
36 36
37#include <kbuttonbox.h> 37#include <kbuttonbox.h>
38#include <kdialog.h> 38#include <kdialog.h>
39#include <klineedit.h> 39#include <klineedit.h>
40 40
41#include "factory.h" 41#include "factory.h"
42#include "configwidget.h" 42#include "configwidget.h"
43#include "configdialog.h" 43#include "configdialog.h"
44#include "syncwidget.h"
45 44
46using namespace KRES; 45using namespace KRES;
47 46
48ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, 47ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily,
49 Resource* resource, const char *name ) 48 Resource* resource, const char *name )
50 : KDialogBase( parent, name, true, resource->isSyncable()?i18n( "Sync Profile Configuration" ):i18n( "Resource Configuration" ), 49 : KDialogBase( parent, name, true, i18n( "Resource Configuration" ),
51 Ok|Cancel, Ok, true )/*, mConfig( config )*/, mSyncWidget_Settings(0), mSyncWidget_Conflicts(0),mSyncWidget_Remote(0), mResource( resource ), mPersistentReadOnly(false) 50 Ok|Cancel, Ok, true )/*, mConfig( config )*/, mResource( resource ), mPersistentReadOnly(false)
52{ 51{
53 52
54 Factory *factory = Factory::self( resourceFamily ); 53 Factory *factory = Factory::self( resourceFamily );
55 54
56//US resize( 250, 240 ); 55//US resize( 250, 240 );
57 resize( KMIN(KGlobal::getDesktopWidth(), 250), KMIN(KGlobal::getDesktopHeight(), 240)); 56 resize( KMIN(KGlobal::getDesktopWidth(), 250), KMIN(KGlobal::getDesktopHeight(), 240));
58 57
59 QFrame *main; 58 QFrame *main;
60 59
61 if (!mResource->isSyncable()) 60 main = plainPage();
62 main = plainPage();
63 else
64 main = addPage("Profile");
65 61
66 QVBoxLayout *mainLayout = new QVBoxLayout( main, 0, spacingHint() ); 62 QVBoxLayout *mainLayout = new QVBoxLayout( main, 0, spacingHint() );
67 63
68 64
69 QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); 65 QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, main );
70 generalGroupBox->layout()->setSpacing( spacingHint() ); 66 generalGroupBox->layout()->setSpacing( spacingHint() );
71 generalGroupBox->setTitle( i18n( "General Settings" ) ); 67 generalGroupBox->setTitle( i18n( "General Settings" ) );
72 68
73 new QLabel( mResource->isSyncable()?i18n( "Profile Name:" ):i18n( "Name:" ), generalGroupBox ); 69 new QLabel( i18n( "Name:" ), generalGroupBox );
74 70
75 mName = new KLineEdit( generalGroupBox ); 71 mName = new KLineEdit( generalGroupBox );
76 72
77 if (!mResource->isSyncable()) { 73 new QLabel("", generalGroupBox );
78 new QLabel("", generalGroupBox ); 74 mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox );
79 mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox ); 75 mReadOnly->setChecked( mResource->readOnly() );
80 mReadOnly->setChecked( mResource->readOnly() ); 76
81 new QLabel("", generalGroupBox ); 77 new QLabel("", generalGroupBox );
82 mIncludeInSync = new QCheckBox( i18n( "Include in sync" ), generalGroupBox ); 78 mIncludeInSync = new QCheckBox( i18n( "Include in sync" ), generalGroupBox );
83 mIncludeInSync->setChecked( mResource->includeInSync() ); 79 mIncludeInSync->setChecked( mResource->includeInSync() );
84 }
85 80
86 mName->setText( mResource->resourceName() ); 81 mName->setText( mResource->resourceName() );
87 82
88 mainLayout->addWidget( generalGroupBox ); 83 mainLayout->addWidget( generalGroupBox );
89 84
90 QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); 85 QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal, main );
91 resourceGroupBox->layout()->setSpacing( spacingHint()); 86 resourceGroupBox->layout()->setSpacing( spacingHint());
92 resourceGroupBox->setTitle( i18n( "%1 Resource Settings" ) 87 resourceGroupBox->setTitle( i18n( "%1 Resource Settings" )
93 .arg( factory->typeName( resource->type() ) ) ); 88 .arg( factory->typeName( resource->type() ) ) );
94 mainLayout->addWidget( resourceGroupBox ); 89 mainLayout->addWidget( resourceGroupBox );
95 90
96 mainLayout->addStretch(); 91 mainLayout->addStretch();
97 92
98 mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox ); 93 mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox );
99 if ( mConfigWidget ) { 94 if ( mConfigWidget ) {
100 connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ), 95 connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ),
101 SLOT( setReadOnly( bool ) ) ); 96 SLOT( setReadOnly( bool ) ) );
97 connect( mConfigWidget, SIGNAL( setIncludeInSync( bool ) ),
98 SLOT( setIncludeInSync( bool ) ) );
102 connect( mConfigWidget, SIGNAL( setPersistentReadOnly( bool ) ), 99 connect( mConfigWidget, SIGNAL( setPersistentReadOnly( bool ) ),
103 SLOT( setPersistentReadOnly( bool ) ) ); 100 SLOT( setPersistentReadOnly( bool ) ) );
104 mConfigWidget->setInEditMode( false ); 101 mConfigWidget->setInEditMode( false );
105 mConfigWidget->loadSettings( mResource ); 102 mConfigWidget->loadSettings( mResource );
106 mConfigWidget->show(); 103 mConfigWidget->show();
107 104
108 } 105 }
109 106
110 if (mResource->isSyncable())
111 {
112 SyncWidgetContainer* c = factory->syncWidgetContainer( resource->type() );
113
114 QFrame* syncPage = addPage("Settings");
115 QVBoxLayout *syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() );
116 mSyncWidget_Settings = c->generateSettingsTab(syncPage);
117 syncLayout->addWidget( mSyncWidget_Settings );
118
119 syncPage = addPage("Conflicts");
120 syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() );
121 mSyncWidget_Conflicts = c->generateConflictsTab(syncPage);
122 syncLayout->addWidget( mSyncWidget_Conflicts );
123
124 syncPage = addPage("Remote");
125 syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() );
126 mSyncWidget_Remote = c->generateRemoteTab(syncPage);
127 syncLayout->addWidget( mSyncWidget_Remote );
128
129
130 mSyncWidget_Settings->setInEditMode( false );
131 mSyncWidget_Settings->loadSettings( mResource );
132 mSyncWidget_Settings->show();
133
134 mSyncWidget_Conflicts->setInEditMode( false );
135 mSyncWidget_Conflicts->loadSettings( mResource );
136 mSyncWidget_Conflicts->show();
137
138 mSyncWidget_Remote->setInEditMode( false );
139 mSyncWidget_Remote->loadSettings( mResource );
140 mSyncWidget_Remote->show();
141
142 delete c;
143
144// QGroupBox *syncGroupBox = new QGroupBox( 2, Qt::Horizontal, syncPage );
145// syncGroupBox->layout()->setSpacing( spacingHint());
146// syncGroupBox->setTitle( i18n( "Syncronize Preferences" ) );
147// syncLayout->addWidget( syncGroupBox );
148
149// syncLayout->addStretch();
150/*US
151 mSyncWidget = factory->syncWidget( resource->type(), syncPage );
152 syncLayout->addWidget( mSyncWidget );
153 if ( mSyncWidget ) {
154 mSyncWidget->setInEditMode( false );
155 mSyncWidget->loadSettings( mResource );
156 mSyncWidget->show();
157 }
158 */
159 }
160
161
162
163 107
164 connect( mName, SIGNAL( textChanged(const QString &)), 108 connect( mName, SIGNAL( textChanged(const QString &)),
165 SLOT( slotNameChanged(const QString &))); 109 SLOT( slotNameChanged(const QString &)));
166 110
167 slotNameChanged( mName->text() ); 111 slotNameChanged( mName->text() );
168 112
169//US setMinimumSize( 400, 250 ); 113//US setMinimumSize( 400, 250 );
170 setMinimumSize( KMIN(KGlobal::getDesktopWidth(), 400), KMIN(KGlobal::getDesktopHeight(), 250)); 114 setMinimumSize( KMIN(KGlobal::getDesktopWidth(), 400), KMIN(KGlobal::getDesktopHeight(), 250));
171 115
172} 116}
173 117
174void ConfigDialog::setInEditMode( bool value ) 118void ConfigDialog::setInEditMode( bool value )
175{ 119{
176 if ( mConfigWidget ) 120 if ( mConfigWidget )
177 mConfigWidget->setInEditMode( value ); 121 mConfigWidget->setInEditMode( value );
178
179 if ( mSyncWidget_Settings )
180 mSyncWidget_Settings->setInEditMode( value );
181 if ( mSyncWidget_Conflicts )
182 mSyncWidget_Conflicts->setInEditMode( value );
183 if ( mSyncWidget_Remote )
184 mSyncWidget_Remote->setInEditMode( value );
185
186} 122}
187 123
188void ConfigDialog::slotNameChanged( const QString &text) 124void ConfigDialog::slotNameChanged( const QString &text)
189{ 125{
190 enableButtonOK( !text.isEmpty() ); 126 enableButtonOK( !text.isEmpty() );
191} 127}
192 128
193void ConfigDialog::setReadOnly( bool value ) 129void ConfigDialog::setReadOnly( bool value )
194{ 130{
195 if (!mResource->isSyncable()) {
196
197 if (mPersistentReadOnly == false) 131 if (mPersistentReadOnly == false)
198 mReadOnly->setChecked( value ); 132 mReadOnly->setChecked( value );
199 else 133 else
200 mReadOnly->setChecked( true ); 134 mReadOnly->setChecked( true );
201 }
202} 135}
203 136
204void ConfigDialog::setPersistentReadOnly( bool value ) 137void ConfigDialog::setIncludeInSync( bool value )
205{ 138{
206 if (!mResource->isSyncable()) { 139 if (mPersistentReadOnly == false)
140 mIncludeInSync->setChecked( value );
141 else
142 mIncludeInSync->setChecked( true );
143}
207 144
145void ConfigDialog::setPersistentReadOnly( bool value )
146{
208 mPersistentReadOnly = value; 147 mPersistentReadOnly = value;
209 148
210 if (value == true) 149 if (value == true) {
211 setReadOnly( true ); 150 setReadOnly( true );
151 setIncludeInSync( true );
152 }
212 153
213 mReadOnly->setEnabled( !value ); 154 mReadOnly->setEnabled( !value );
214 } 155 mIncludeInSync->setEnabled (!value );
215} 156}
216 157
158
217void ConfigDialog::accept() 159void ConfigDialog::accept()
218{ 160{
219 if ( mName->text().isEmpty() ) { 161 if ( mName->text().isEmpty() ) {
220 KMessageBox::sorry( this, mResource->isSyncable()?i18n( "Please enter a profile name" ):i18n( "Please enter a resource name" ) ); 162 KMessageBox::sorry( this, i18n( "Please enter a resource name" ) );
221 return; 163 return;
222 } 164 }
223 165
224 mResource->setResourceName( mName->text() ); 166 mResource->setResourceName( mName->text() );
225 if (!mResource->isSyncable()) 167 mResource->setReadOnly( mReadOnly->isChecked() );
226 mResource->setReadOnly( mReadOnly->isChecked() ); 168 mResource->setIncludeInSync( mIncludeInSync->isChecked() );
227 mResource->setIncludeInSync( mIncludeInSync->isChecked() );
228 169
229 if ( mConfigWidget ) { 170 if ( mConfigWidget ) {
230 // First save generic information 171 // First save generic information
231 // Also save setting of specific resource type 172 // Also save setting of specific resource type
232 mConfigWidget->saveSettings( mResource ); 173 mConfigWidget->saveSettings( mResource );
233 } 174 }
234 175
235 if ( mSyncWidget_Settings )
236 mSyncWidget_Settings->saveSettings( mResource );
237 if ( mSyncWidget_Conflicts )
238 mSyncWidget_Conflicts->saveSettings( mResource );
239 if ( mSyncWidget_Remote )
240 mSyncWidget_Remote->saveSettings( mResource );
241
242
243 KDialog::accept(); 176 KDialog::accept();
244} 177}
245 178
246//US #include "configdialog.moc" 179//US #include "configdialog.moc"
diff --git a/microkde/kresources/configdialog.h b/microkde/kresources/configdialog.h
index ed3ecab..b205975 100644
--- a/microkde/kresources/configdialog.h
+++ b/microkde/kresources/configdialog.h
@@ -1,68 +1,65 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 4 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef KRESOURCES_CONFIGDIALOG_H 22#ifndef KRESOURCES_CONFIGDIALOG_H
23#define KRESOURCES_CONFIGDIALOG_H 23#define KRESOURCES_CONFIGDIALOG_H
24 24
25#include <kdialogbase.h> 25#include <kdialogbase.h>
26 26
27class KLineEdit; 27class KLineEdit;
28class QCheckBox; 28class QCheckBox;
29class KButtonBox; 29class KButtonBox;
30 30
31namespace KRES { 31namespace KRES {
32 class Resource; 32 class Resource;
33 class ConfigWidget; 33 class ConfigWidget;
34 class SyncWidget;
35 34
36class ConfigDialog : public KDialogBase 35class ConfigDialog : public KDialogBase
37{ 36{
38 Q_OBJECT 37 Q_OBJECT
39 public: 38 public:
40 // Resource=0: create new resource 39 // Resource=0: create new resource
41 ConfigDialog( QWidget *parent, const QString& resourceFamily, 40 ConfigDialog( QWidget *parent, const QString& resourceFamily,
42 Resource* resource, const char *name = 0); 41 Resource* resource, const char *name = 0);
43 42
44 void setInEditMode( bool value ); 43 void setInEditMode( bool value );
45 44
46 protected slots: 45 protected slots:
47 void accept(); 46 void accept();
48 void setReadOnly( bool value ); 47 void setReadOnly( bool value );
48 void setIncludeInSync( bool value );
49 void setPersistentReadOnly( bool value ); 49 void setPersistentReadOnly( bool value );
50 void slotNameChanged( const QString &text); 50 void slotNameChanged( const QString &text);
51 51
52 private: 52 private:
53 ConfigWidget *mConfigWidget; 53 ConfigWidget *mConfigWidget;
54 SyncWidget *mSyncWidget_Settings;
55 SyncWidget *mSyncWidget_Conflicts;
56 SyncWidget *mSyncWidget_Remote;
57 Resource* mResource; 54 Resource* mResource;
58 55
59 KLineEdit *mName; 56 KLineEdit *mName;
60 QCheckBox *mReadOnly; 57 QCheckBox *mReadOnly;
61 QCheckBox *mIncludeInSync; 58 QCheckBox *mIncludeInSync;
62//US add a persistent readonly flag. We need that for opie and qtopia addressbooks. 59//US add a persistent readonly flag. We need that for opie and qtopia addressbooks.
63 bool mPersistentReadOnly; 60 bool mPersistentReadOnly;
64}; 61};
65 62
66} 63}
67 64
68#endif 65#endif
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp
index 02c5fb1..533be51 100644
--- a/microkde/kresources/configpage.cpp
+++ b/microkde/kresources/configpage.cpp
@@ -1,554 +1,533 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qgroupbox.h> 31#include <qgroupbox.h>
32#include <qinputdialog.h> 32#include <qinputdialog.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qlayout.h> 34#include <qlayout.h>
35 35
36#include <kapplication.h> 36#include <kapplication.h>
37#include <kcombobox.h> 37#include <kcombobox.h>
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kmessagebox.h> 40#include <kmessagebox.h>
41#include <ksimpleconfig.h> 41#include <ksimpleconfig.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kurlrequester.h> 43#include <kurlrequester.h>
44#include <klistview.h> 44#include <klistview.h>
45#include <kbuttonbox.h> 45#include <kbuttonbox.h>
46//US #include <ktrader.h> 46//US #include <ktrader.h>
47 47
48#include "resource.h" 48#include "resource.h"
49#include "configdialog.h" 49#include "configdialog.h"
50 50
51#include "configpage.h" 51#include "configpage.h"
52 52
53//US 53//US
54#include <qpushbutton.h> 54#include <qpushbutton.h>
55#include <qfile.h> 55#include <qfile.h>
56#include <kglobal.h> 56#include <kglobal.h>
57 57
58using namespace KRES; 58using namespace KRES;
59 59
60const QString ConfigPage::syncfamily = "syncprofiles";
61
62
63class ConfigViewItem : public QCheckListItem 60class ConfigViewItem : public QCheckListItem
64{ 61{
65 public: 62 public:
66 ConfigViewItem( QListView *parent, Resource* resource ) : 63 ConfigViewItem( QListView *parent, Resource* resource ) :
67 QCheckListItem( parent, resource->resourceName(), CheckBox ), 64 QCheckListItem( parent, resource->resourceName(), CheckBox ),
68 mResource( resource ), 65 mResource( resource ),
69 mIsStandard( false ) 66 mIsStandard( false )
70 { 67 {
71 setText( 1, mResource->type() ); 68 setText( 1, mResource->type() );
72 setOn( mResource->isActive() ); 69 setOn( mResource->isActive() );
73 } 70 }
74 71
75 void setStandard( bool value ) 72 void setStandard( bool value )
76 { 73 {
77 setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); 74 setText( 2, ( value ? i18n( "Yes" ) : QString::null ) );
78 mIsStandard = value; 75 mIsStandard = value;
79 } 76 }
80 77
81 bool standard() const { return mIsStandard; } 78 bool standard() const { return mIsStandard; }
82 bool readOnly() const { return mResource->readOnly(); } 79 bool readOnly() const { return mResource->readOnly(); }
83 80
84 Resource *resource() { return mResource; } 81 Resource *resource() { return mResource; }
85 82
86 private: 83 private:
87 Resource* mResource; 84 Resource* mResource;
88 85
89 bool mIsStandard; 86 bool mIsStandard;
90}; 87};
91 88
92ConfigPage::ConfigPage( QWidget *parent, const char *name ) 89ConfigPage::ConfigPage( QWidget *parent, const char *name )
93 : QWidget( parent, name ), 90 : QWidget( parent, name ),
94 mCurrentManager( 0 ), 91 mCurrentManager( 0 ),
95 mCurrentConfig( 0 ) 92 mCurrentConfig( 0 )
96{ 93{
97 setCaption( i18n( "Resource Configuration" ) ); 94 setCaption( i18n( "Resource Configuration" ) );
98 95
99 QVBoxLayout *mainLayout = new QVBoxLayout( this ); 96 QVBoxLayout *mainLayout = new QVBoxLayout( this );
100 97
101 QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); 98 QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this );
102 groupBox->setColumnLayout(0, Qt::Vertical ); 99 groupBox->setColumnLayout(0, Qt::Vertical );
103 groupBox->layout()->setSpacing( 3 ); 100 groupBox->layout()->setSpacing( 3 );
104 groupBox->layout()->setMargin( 5 ); 101 groupBox->layout()->setMargin( 5 );
105 QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 ); 102 QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 );
106 103
107//US mFamilyCombo = new KComboBox( false, groupBox ); 104//US mFamilyCombo = new KComboBox( false, groupBox );
108 mFamilyCombo = new KComboBox( groupBox ); 105 mFamilyCombo = new KComboBox( groupBox );
109 groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); 106 groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 );
110 107
111 mListView = new KListView( groupBox ); 108 mListView = new KListView( groupBox );
112 mListView->setAllColumnsShowFocus( true ); 109 mListView->setAllColumnsShowFocus( true );
113 mListView->addColumn( i18n( "Name" ) ); 110 mListView->addColumn( i18n( "Name" ) );
114 mListView->addColumn( i18n( "Type" ) ); 111 mListView->addColumn( i18n( "Type" ) );
115 mListView->addColumn( i18n( "Standard" ) ); 112 mListView->addColumn( i18n( "Standard" ) );
116 113
117//US groupBoxLayout->addWidget( mListView, 1, 0 ); 114//US groupBoxLayout->addWidget( mListView, 1, 0 );
118 groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); 115 groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 );
119 116
120 117
121 mAddButton = new QPushButton( i18n( "&Add..." ), groupBox ); 118 mAddButton = new QPushButton( i18n( "&Add..." ), groupBox );
122 groupBoxLayout->addWidget( mAddButton, 2, 0 ); 119 groupBoxLayout->addWidget( mAddButton, 2, 0 );
123 mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox ); 120 mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox );
124 groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); 121 groupBoxLayout->addWidget( mRemoveButton, 2, 1 );
125 mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox ); 122 mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox );
126 groupBoxLayout->addWidget( mEditButton, 3, 0 ); 123 groupBoxLayout->addWidget( mEditButton, 3, 0 );
127 mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox ); 124 mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox );
128 groupBoxLayout->addWidget( mStandardButton, 3, 1 ); 125 groupBoxLayout->addWidget( mStandardButton, 3, 1 );
129 126
130 mRemoveButton->setEnabled( false ); 127 mRemoveButton->setEnabled( false );
131 mEditButton->setEnabled( false ); 128 mEditButton->setEnabled( false );
132 mStandardButton->setEnabled( false ); 129 mStandardButton->setEnabled( false );
133 130
134 131
135 connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); 132 connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) );
136 connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); 133 connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) );
137 connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); 134 connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) );
138 connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); 135 connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) );
139 136
140 137
141 mainLayout->addWidget( groupBox ); 138 mainLayout->addWidget( groupBox );
142 139
143 connect( mFamilyCombo, SIGNAL( activated( int ) ), 140 connect( mFamilyCombo, SIGNAL( activated( int ) ),
144 SLOT( slotFamilyChanged( int ) ) ); 141 SLOT( slotFamilyChanged( int ) ) );
145 connect( mListView, SIGNAL( selectionChanged() ), 142 connect( mListView, SIGNAL( selectionChanged() ),
146 SLOT( slotSelectionChanged() ) ); 143 SLOT( slotSelectionChanged() ) );
147 connect( mListView, SIGNAL( clicked( QListViewItem * ) ), 144 connect( mListView, SIGNAL( clicked( QListViewItem * ) ),
148 SLOT( slotItemClicked( QListViewItem * ) ) ); 145 SLOT( slotItemClicked( QListViewItem * ) ) );
149 146
150 mLastItem = 0; 147 mLastItem = 0;
151 148
152//US mConfig = new KConfig( "kcmkresourcesrc" ); 149//US mConfig = new KConfig( "kcmkresourcesrc" );
153 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); 150 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") );
154 mConfig->setGroup( "General" ); 151 mConfig->setGroup( "General" );
155 152
156 load(); 153 load();
157} 154}
158 155
159ConfigPage::~ConfigPage() 156ConfigPage::~ConfigPage()
160{ 157{
161 QValueList<ResourcePageInfo>::Iterator it; 158 QValueList<ResourcePageInfo>::Iterator it;
162 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { 159 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) {
163 (*it).mManager->removeListener( this ); 160 (*it).mManager->removeListener( this );
164 delete (*it).mManager; 161 delete (*it).mManager;
165 delete (*it).mConfig; 162 delete (*it).mConfig;
166 } 163 }
167 164
168 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); 165 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() );
169 delete mConfig; 166 delete mConfig;
170 mConfig = 0; 167 mConfig = 0;
171} 168}
172 169
173void ConfigPage::load() 170void ConfigPage::load()
174{ 171{
175 kdDebug(5650) << "ConfigPage::load()" << endl; 172 kdDebug(5650) << "ConfigPage::load()" << endl;
176 173
177 mListView->clear(); 174 mListView->clear();
178 175
179//US we remove the dynamic pluginloader, and set the one family we need (contact) manually. 176//US we remove the dynamic pluginloader, and set the one family we need (contact) manually.
180 177
181//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); 178//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" );
182//US KTrader::OfferList::ConstIterator it; 179//US KTrader::OfferList::ConstIterator it;
183//US for ( it = plugins.begin(); it != plugins.end(); ++it ) { 180//US for ( it = plugins.begin(); it != plugins.end(); ++it ) {
184//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); 181//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" );
185//US QString family = tmp.toString(); 182//US QString family = tmp.toString();
186 QStringList families; 183 QStringList families;
187 families << "contact" << syncfamily; 184 families << "contact";
188 185
189 186
190 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) 187 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it )
191 { 188 {
192 QString family = (*it); 189 QString family = (*it);
193 if ( !family.isEmpty() ) { 190 if ( !family.isEmpty() ) {
194 if ( !mFamilyMap.contains( family ) ) { 191 if ( !mFamilyMap.contains( family ) ) {
195 mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); 192 mCurrentManager = new Manager<Resource>( family );
196 if ( mCurrentManager ) { 193 if ( mCurrentManager ) {
197 mFamilyMap.append( family ); 194 mFamilyMap.append( family );
198 mCurrentManager->addListener( this ); 195 mCurrentManager->addListener( this );
199 196
200 ResourcePageInfo info; 197 ResourcePageInfo info;
201 info.mManager = mCurrentManager; 198 info.mManager = mCurrentManager;
202 QString configDir = KGlobal::dirs()->saveLocation( "config" ); 199 QString configDir = KGlobal::dirs()->saveLocation( "config" );
203 //QString configDir = KStandardDirs::appDir() + "/config"; 200 //QString configDir = KStandardDirs::appDir() + "/config";
204 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { 201 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) {
205 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); 202 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) );
206 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { 203 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) {
207 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); 204 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) );
208 } else if ( family == syncfamily && QFile::exists( configDir + "/kabcsyncrc" ) ) {
209 info.mConfig = new KConfig( locateLocal( "config", "kabcsyncrc" ) );
210 } else { 205 } else {
211 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); 206 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) );
212 info.mConfig = new KConfig( configFile ); 207 info.mConfig = new KConfig( configFile );
213 } 208 }
214 info.mManager->readConfig( info.mConfig ); 209 info.mManager->readConfig( info.mConfig );
215 210
216 mInfoMap.append( info ); 211 mInfoMap.append( info );
217 } 212 }
218 } 213 }
219 } 214 }
220 } 215 }
221 mCurrentManager = 0; 216 mCurrentManager = 0;
222 217
223 mFamilyCombo->insertStringList( mFamilyMap ); 218 mFamilyCombo->insertStringList( mFamilyMap );
224 219
225 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); 220 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 );
226 mFamilyCombo->setCurrentItem( currentFamily ); 221 mFamilyCombo->setCurrentItem( currentFamily );
227 slotFamilyChanged( currentFamily ); 222 slotFamilyChanged( currentFamily );
228} 223}
229 224
230void ConfigPage::save() 225void ConfigPage::save()
231{ 226{
232 saveResourceSettings(); 227 saveResourceSettings();
233 228
234 QValueList<ResourcePageInfo>::Iterator it; 229 QValueList<ResourcePageInfo>::Iterator it;
235 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) 230 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it )
236 (*it).mManager->writeConfig( (*it).mConfig ); 231 (*it).mManager->writeConfig( (*it).mConfig );
237 232
238 emit changed( false ); 233 emit changed( false );
239} 234}
240 235
241void ConfigPage::defaults() 236void ConfigPage::defaults()
242{ 237{
243} 238}
244 239
245void ConfigPage::slotFamilyChanged( int pos ) 240void ConfigPage::slotFamilyChanged( int pos )
246{ 241{
247 if ( pos < 0 || pos >= (int)mFamilyMap.count() ) 242 if ( pos < 0 || pos >= (int)mFamilyMap.count() )
248 return; 243 return;
249 244
250 saveResourceSettings(); 245 saveResourceSettings();
251 246
252 mFamily = mFamilyMap[ pos ]; 247 mFamily = mFamilyMap[ pos ];
253 248
254//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); 249//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1());
255 250
256 mCurrentManager = mInfoMap[ pos ].mManager; 251 mCurrentManager = mInfoMap[ pos ].mManager;
257 mCurrentConfig = mInfoMap[ pos ].mConfig; 252 mCurrentConfig = mInfoMap[ pos ].mConfig;
258 253
259 if ( !mCurrentManager ) 254 if ( !mCurrentManager )
260 kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; 255 kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl;
261 256
262 mListView->clear(); 257 mListView->clear();
263 258
264 if ( mCurrentManager->isEmpty() ) { 259 if ( mCurrentManager->isEmpty() ) {
265//US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); 260//US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager );
266 261
267 defaults(); 262 defaults();
268 } 263 }
269 264
270 Resource *standardResource = mCurrentManager->standardResource(); 265 Resource *standardResource = mCurrentManager->standardResource();
271 266
272//US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); 267//US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1());
273 268
274 269
275 Manager<Resource>::Iterator it; 270 Manager<Resource>::Iterator it;
276 for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { 271 for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) {
277 ConfigViewItem *item = new ConfigViewItem( mListView, *it ); 272 ConfigViewItem *item = new ConfigViewItem( mListView, *it );
278 if ( *it == standardResource ) 273 if ( *it == standardResource )
279 item->setStandard( true ); 274 item->setStandard( true );
280 } 275 }
281 276
282 if ( mListView->childCount() == 0 ) { 277 if ( mListView->childCount() == 0 ) {
283//US qDebug("ConfigPage::slotFamilyChanged 4.5 "); 278//US qDebug("ConfigPage::slotFamilyChanged 4.5 ");
284 279
285 defaults(); 280 defaults();
286 emit changed( true ); 281 emit changed( true );
287 mCurrentManager->writeConfig( mCurrentConfig ); 282 mCurrentManager->writeConfig( mCurrentConfig );
288 } else { 283 } else {
289//US qDebug("ConfigPage::slotFamilyChanged 4.6 "); 284//US qDebug("ConfigPage::slotFamilyChanged 4.6 ");
290 285
291 if ( !standardResource ) { 286 if ( !standardResource ) {
292 KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); 287 KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) );
293 288
294//US qDebug("ConfigPage::slotFamilyChanged 4.7" ); 289//US qDebug("ConfigPage::slotFamilyChanged 4.7" );
295 290
296 } 291 }
297 292
298 emit changed( false ); 293 emit changed( false );
299 } 294 }
300} 295}
301 296
302void ConfigPage::slotAdd() 297void ConfigPage::slotAdd()
303{ 298{
304 if ( !mCurrentManager ) 299 if ( !mCurrentManager )
305 return; 300 return;
306 301
307 QStringList types = mCurrentManager->resourceTypeNames(); 302 QStringList types = mCurrentManager->resourceTypeNames();
308 QStringList descs = mCurrentManager->resourceTypeDescriptions(); 303 QStringList descs = mCurrentManager->resourceTypeDescriptions();
309 bool ok = false; 304 bool ok = false;
310 305
311 QString desc; 306 QString desc;
312 307
313 if (mFamily == syncfamily) 308 desc = QInputDialog::getItem( i18n( "Resource Configuration" ),
314 {
315 desc = QInputDialog::getItem( i18n( "Sync Configuration" ),
316 i18n( "Select resource type for the new sync profile:" ), descs, 0,
317 false, &ok, this );
318 }
319 else
320 {
321 desc = QInputDialog::getItem( i18n( "Resource Configuration" ),
322 i18n( "Select type of the new resource:" ), descs, 0, 309 i18n( "Select type of the new resource:" ), descs, 0,
323 false, &ok, this ); 310 false, &ok, this );
324 }
325 311
326 if ( !ok ) 312 if ( !ok )
327 return; 313 return;
328 314
329 QString type = types[ descs.findIndex( desc ) ]; 315 QString type = types[ descs.findIndex( desc ) ];
330 316
331 // Create new resource 317 // Create new resource
332 Resource *resource = mCurrentManager->createResource( type ); 318 Resource *resource = mCurrentManager->createResource( type );
333 if ( !resource ) { 319 if ( !resource ) {
334 KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") 320 KMessageBox::error( this, i18n("Unable to create resource of type '%1'.")
335 .arg( type ) ); 321 .arg( type ) );
336 return; 322 return;
337 } 323 }
338 324
339 if (mFamily == syncfamily) 325 resource->setResourceName( type + "-resource" );
340 {
341 resource->setResourceName( type + "-syncprofile" );
342 }
343 else
344 {
345 resource->setResourceName( type + "-resource" );
346 }
347 326
348 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); 327 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
349 328
350 if ( dlg.exec() ) { 329 if ( dlg.exec() ) {
351 mCurrentManager->add( resource ); 330 mCurrentManager->add( resource );
352 331
353 ConfigViewItem *item = new ConfigViewItem( mListView, resource ); 332 ConfigViewItem *item = new ConfigViewItem( mListView, resource );
354 333
355 mLastItem = item; 334 mLastItem = item;
356 335
357 // if there are only read-only resources we'll set this resource 336 // if there are only read-only resources we'll set this resource
358 // as standard resource 337 // as standard resource
359 if ( !resource->readOnly() ) { 338 if ( !resource->readOnly() ) {
360 bool onlyReadOnly = true; 339 bool onlyReadOnly = true;
361 QListViewItem *it = mListView->firstChild(); 340 QListViewItem *it = mListView->firstChild();
362 while ( it != 0 ) { 341 while ( it != 0 ) {
363 ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); 342 ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it );
364 if ( !confIt->readOnly() && confIt != item ) 343 if ( !confIt->readOnly() && confIt != item )
365 onlyReadOnly = false; 344 onlyReadOnly = false;
366 345
367 it = it->itemBelow(); 346 it = it->itemBelow();
368 } 347 }
369 348
370 if ( onlyReadOnly ) 349 if ( onlyReadOnly )
371 item->setStandard( true ); 350 item->setStandard( true );
372 } 351 }
373 352
374 emit changed( true ); 353 emit changed( true );
375 } else { 354 } else {
376 delete resource; 355 delete resource;
377 resource = 0; 356 resource = 0;
378 } 357 }
379} 358}
380 359
381void ConfigPage::slotRemove() 360void ConfigPage::slotRemove()
382{ 361{
383 if ( !mCurrentManager ) 362 if ( !mCurrentManager )
384 return; 363 return;
385 364
386 QListViewItem *item = mListView->currentItem(); 365 QListViewItem *item = mListView->currentItem();
387 ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); 366 ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item );
388 367
389 if ( !confItem ) 368 if ( !confItem )
390 return; 369 return;
391 370
392 if ( confItem->standard() ) { 371 if ( confItem->standard() ) {
393 KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); 372 KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) );
394 return; 373 return;
395 } 374 }
396 375
397 mCurrentManager->remove( confItem->resource() ); 376 mCurrentManager->remove( confItem->resource() );
398 377
399 if ( item == mLastItem ) 378 if ( item == mLastItem )
400 mLastItem = 0; 379 mLastItem = 0;
401 380
402 mListView->takeItem( item ); 381 mListView->takeItem( item );
403 delete item; 382 delete item;
404 383
405 emit changed( true ); 384 emit changed( true );
406} 385}
407 386
408void ConfigPage::slotEdit() 387void ConfigPage::slotEdit()
409{ 388{
410 if ( !mCurrentManager ) 389 if ( !mCurrentManager )
411 return; 390 return;
412 391
413 QListViewItem *item = mListView->currentItem(); 392 QListViewItem *item = mListView->currentItem();
414 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); 393 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item );
415 if ( !configItem ) 394 if ( !configItem )
416 return; 395 return;
417 396
418 Resource *resource = configItem->resource(); 397 Resource *resource = configItem->resource();
419 398
420 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); 399 ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" );
421 400
422 if ( dlg.exec() ) { 401 if ( dlg.exec() ) {
423 configItem->setText( 0, resource->resourceName() ); 402 configItem->setText( 0, resource->resourceName() );
424 configItem->setText( 1, resource->type() ); 403 configItem->setText( 1, resource->type() );
425 404
426 if ( configItem->standard() && configItem->readOnly() ) { 405 if ( configItem->standard() && configItem->readOnly() ) {
427 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) ); 406 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) );
428 configItem->setStandard( false ); 407 configItem->setStandard( false );
429 } 408 }
430 409
431 mCurrentManager->resourceChanged( resource ); 410 mCurrentManager->resourceChanged( resource );
432 emit changed( true ); 411 emit changed( true );
433 } 412 }
434} 413}
435 414
436void ConfigPage::slotStandard() 415void ConfigPage::slotStandard()
437{ 416{
438 if ( !mCurrentManager ) 417 if ( !mCurrentManager )
439 return; 418 return;
440 419
441 ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); 420 ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() );
442 if ( !item ) 421 if ( !item )
443 return; 422 return;
444 423
445 if ( item->readOnly() ) { 424 if ( item->readOnly() ) {
446 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) ); 425 KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) );
447 return; 426 return;
448 } 427 }
449 428
450 if ( !item->isOn() ) { 429 if ( !item->isOn() ) {
451 KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) ); 430 KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) );
452 return; 431 return;
453 } 432 }
454 433
455 QListViewItem *it = mListView->firstChild(); 434 QListViewItem *it = mListView->firstChild();
456 while ( it != 0 ) { 435 while ( it != 0 ) {
457 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it ); 436 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it );
458 if ( configItem->standard() ) 437 if ( configItem->standard() )
459 configItem->setStandard( false ); 438 configItem->setStandard( false );
460 it = it->itemBelow(); 439 it = it->itemBelow();
461 } 440 }
462 441
463 item->setStandard( true ); 442 item->setStandard( true );
464 mCurrentManager->setStandardResource( item->resource() ); 443 mCurrentManager->setStandardResource( item->resource() );
465 emit changed( true ); 444 emit changed( true );
466 445
467} 446}
468 447
469void ConfigPage::slotSelectionChanged() 448void ConfigPage::slotSelectionChanged()
470{ 449{
471 bool state = ( mListView->currentItem() != 0 ); 450 bool state = ( mListView->currentItem() != 0 );
472 451
473 mRemoveButton->setEnabled( state ); 452 mRemoveButton->setEnabled( state );
474 mEditButton->setEnabled( state ); 453 mEditButton->setEnabled( state );
475 mStandardButton->setEnabled( state ); 454 mStandardButton->setEnabled( state );
476} 455}
477 456
478void ConfigPage::resourceAdded( Resource* resource ) 457void ConfigPage::resourceAdded( Resource* resource )
479{ 458{
480 qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1()); 459 qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1());
481 kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName() << " )" << endl; 460 kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName() << " )" << endl;
482 ConfigViewItem *item = new ConfigViewItem( mListView, resource ); 461 ConfigViewItem *item = new ConfigViewItem( mListView, resource );
483 462
484 // FIXME: this sucks. This should be in the config file, 463 // FIXME: this sucks. This should be in the config file,
485 // or application-dependent, in which case it's always Off 464 // or application-dependent, in which case it's always Off
486 item->setOn( false ); 465 item->setOn( false );
487 466
488 mLastItem = item; 467 mLastItem = item;
489 468
490 emit changed( true ); 469 emit changed( true );
491} 470}
492 471
493void ConfigPage::resourceModified( Resource* resource ) 472void ConfigPage::resourceModified( Resource* resource )
494{ 473{
495 qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1()); 474 qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1());
496 kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName() << " )" << endl; 475 kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName() << " )" << endl;
497} 476}
498 477
499void ConfigPage::resourceDeleted( Resource* resource ) 478void ConfigPage::resourceDeleted( Resource* resource )
500{ 479{
501 qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1()); 480 qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1());
502 kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl; 481 kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl;
503} 482}
504 483
505void ConfigPage::slotItemClicked( QListViewItem *item ) 484void ConfigPage::slotItemClicked( QListViewItem *item )
506{ 485{
507 ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); 486 ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item );
508 if ( !configItem ) return; 487 if ( !configItem ) return;
509 488
510 if ( configItem->standard() && !configItem->isOn() ) { 489 if ( configItem->standard() && !configItem->isOn() ) {
511 KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) ); 490 KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) );
512 configItem->setOn( true ); 491 configItem->setOn( true );
513 return; 492 return;
514 } 493 }
515 494
516 if ( configItem->isOn() != configItem->resource()->isActive() ) { 495 if ( configItem->isOn() != configItem->resource()->isActive() ) {
517 emit changed( true ); 496 emit changed( true );
518 } 497 }
519} 498}
520 499
521void ConfigPage::saveResourceSettings() 500void ConfigPage::saveResourceSettings()
522{ 501{
523 qDebug("ConfigPage::saveResourceSettings() begin"); 502 qDebug("ConfigPage::saveResourceSettings() begin");
524 503
525 if ( mCurrentManager ) { 504 if ( mCurrentManager ) {
526 505
527 QListViewItem *item = mListView->firstChild(); 506 QListViewItem *item = mListView->firstChild();
528 while ( item ) { 507 while ( item ) {
529 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); 508 ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item );
530 509
531 // check if standard resource 510 // check if standard resource
532 if ( configItem->standard() && !configItem->readOnly() && 511 if ( configItem->standard() && !configItem->readOnly() &&
533 configItem->isOn() ) { 512 configItem->isOn() ) {
534 513
535 mCurrentManager->setStandardResource( configItem->resource() ); 514 mCurrentManager->setStandardResource( configItem->resource() );
536 } 515 }
537 516
538 // check if active or passive resource 517 // check if active or passive resource
539 configItem->resource()->setActive( configItem->isOn() ); 518 configItem->resource()->setActive( configItem->isOn() );
540 519
541 item = item->nextSibling(); 520 item = item->nextSibling();
542 } 521 }
543 mCurrentManager->writeConfig( mCurrentConfig ); 522 mCurrentManager->writeConfig( mCurrentConfig );
544 523
545 if ( !mCurrentManager->standardResource() ) 524 if ( !mCurrentManager->standardResource() )
546 KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) ); 525 KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) );
547 } 526 }
548 527
549 qDebug("ConfigPage::saveResourceSettings() end"); 528 qDebug("ConfigPage::saveResourceSettings() end");
550 529
551} 530}
552 531
553//US #include "configpage.moc" 532//US #include "configpage.moc"
554 533
diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp
index e44fce3..4e4456d 100644
--- a/microkde/kresources/factory.cpp
+++ b/microkde/kresources/factory.cpp
@@ -1,289 +1,255 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24#include <kdebug.h> 24#include <kdebug.h>
25#include <klocale.h> 25#include <klocale.h>
26#include <ksimpleconfig.h> 26#include <ksimpleconfig.h>
27#include <kstandarddirs.h> 27#include <kstandarddirs.h>
28#include <kstaticdeleter.h> 28#include <kstaticdeleter.h>
29//#ifndef DESKTOP_VERSION 29//#ifndef DESKTOP_VERSION
30#include <klibloader.h> 30#include <klibloader.h>
31//#endif 31//#endif
32#include <qfile.h> 32#include <qfile.h>
33 33
34#include "resource.h" 34#include "resource.h"
35#include "factory.h" 35#include "factory.h"
36 36
37using namespace KRES; 37using namespace KRES;
38 38
39QDict<Factory> *Factory::mSelves = 0; 39QDict<Factory> *Factory::mSelves = 0;
40static KStaticDeleter< QDict<Factory> > staticDeleter; 40static KStaticDeleter< QDict<Factory> > staticDeleter;
41 41
42Factory *Factory::self( const QString& resourceFamily) 42Factory *Factory::self( const QString& resourceFamily)
43{ 43{
44 44
45 45
46 Factory *factory = 0; 46 Factory *factory = 0;
47 if ( !mSelves ) 47 if ( !mSelves )
48 { 48 {
49 mSelves = staticDeleter.setObject( new QDict<Factory> ); 49 mSelves = staticDeleter.setObject( new QDict<Factory> );
50 } 50 }
51 51
52 factory = mSelves->find( resourceFamily ); 52 factory = mSelves->find( resourceFamily );
53 53
54 if ( !factory ) { 54 if ( !factory ) {
55 factory = new Factory( resourceFamily); 55 factory = new Factory( resourceFamily);
56 mSelves->insert( resourceFamily, factory ); 56 mSelves->insert( resourceFamily, factory );
57 } 57 }
58 58
59 return factory; 59 return factory;
60} 60}
61 61
62Factory::Factory( const QString& resourceFamily) : 62Factory::Factory( const QString& resourceFamily) :
63 mResourceFamily( resourceFamily ) 63 mResourceFamily( resourceFamily )
64{ 64{
65//US so far we have three types available for resourceFamily "contact" 65//US so far we have three types available for resourceFamily "contact"
66// and that are "file", "dir", "ldap" 66// and that are "file", "dir", "ldap"
67/*US 67/*US
68 68
69 KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", QString( "[X-KDE-ResourceFamily] == '%1'" ) 69 KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", QString( "[X-KDE-ResourceFamily] == '%1'" )
70 .arg( resourceFamily ) ); 70 .arg( resourceFamily ) );
71 KTrader::OfferList::ConstIterator it; 71 KTrader::OfferList::ConstIterator it;
72 for ( it = plugins.begin(); it != plugins.end(); ++it ) { 72 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
73 QVariant type = (*it)->property( "X-KDE-ResourceType" ); 73 QVariant type = (*it)->property( "X-KDE-ResourceType" );
74 if ( !type.toString().isEmpty() ) 74 if ( !type.toString().isEmpty() )
75 mTypeMap.insert( type.toString(), *it ); 75 mTypeMap.insert( type.toString(), *it );
76 } 76 }
77*/ 77*/
78 78
79//US new 79//US new
80 PluginInfo* info = new PluginInfo; 80 PluginInfo* info = new PluginInfo;
81 info->library = "microkabc_file"; 81 info->library = "microkabc_file";
82 info->nameLabel = i18n( "file" ); 82 info->nameLabel = i18n( "file" );
83 info->descriptionLabel = i18n( "Choose one file" ); 83 info->descriptionLabel = i18n( "Choose one file" );
84 mTypeMap.insert( "file", info ); 84 mTypeMap.insert( "file", info );
85 85
86 info = new PluginInfo; 86 info = new PluginInfo;
87 info->library = "microkabc_dir"; 87 info->library = "microkabc_dir";
88 info->nameLabel = i18n( "dir" ); 88 info->nameLabel = i18n( "dir" );
89 info->descriptionLabel = i18n( "Choose a directory with may files" ); 89 info->descriptionLabel = i18n( "Choose a directory with may files" );
90 mTypeMap.insert( "dir", info ); 90 mTypeMap.insert( "dir", info );
91 91
92 info = new PluginInfo; 92 info = new PluginInfo;
93 info->library = "microkabc_ldap"; 93 info->library = "microkabc_ldap";
94 info->nameLabel = i18n( "ldap" ); 94 info->nameLabel = i18n( "ldap" );
95 info->descriptionLabel = i18n( "No description available" ); 95 info->descriptionLabel = i18n( "No description available" );
96 mTypeMap.insert( "ldap", info ); 96 mTypeMap.insert( "ldap", info );
97 97
98 //US add opie plugin only, if the library exists. 98 //US add opie plugin only, if the library exists.
99 QString libname = "microkabc_opie"; 99 QString libname = "microkabc_opie";
100 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 100 QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
101 if ( !path.isEmpty() ) 101 if ( !path.isEmpty() )
102 { 102 {
103 info = new PluginInfo; 103 info = new PluginInfo;
104 info->library = libname; 104 info->library = libname;
105 info->nameLabel = i18n( "opie" ); 105 info->nameLabel = i18n( "opie" );
106 info->descriptionLabel = i18n( "Opie PIM Addressbook." ); 106 info->descriptionLabel = i18n( "Opie PIM Addressbook." );
107 mTypeMap.insert( "opie", info ); 107 mTypeMap.insert( "opie", info );
108 } 108 }
109 109
110 //US add qtopia plugin only, if the library exists. 110 //US add qtopia plugin only, if the library exists.
111 libname = "microkabc_qtopia"; 111 libname = "microkabc_qtopia";
112 path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 112 path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
113 if ( !path.isEmpty() ) 113 if ( !path.isEmpty() )
114 { 114 {
115 info = new PluginInfo; 115 info = new PluginInfo;
116 info->library = libname; 116 info->library = libname;
117 info->nameLabel = i18n( "qtopia" ); 117 info->nameLabel = i18n( "qtopia" );
118 info->descriptionLabel = i18n( "Qtopia PIM Addressbook." ); 118 info->descriptionLabel = i18n( "Qtopia PIM Addressbook." );
119 mTypeMap.insert( "qtopia", info ); 119 mTypeMap.insert( "qtopia", info );
120 } 120 }
121 121
122 //US add sharp plugin only, if the library exists. 122 //US add sharp plugin only, if the library exists.
123 libname = "microkabc_sharpdtm"; 123 libname = "microkabc_sharpdtm";
124 path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); 124 path = KLibLoader::findLibrary( QFile::encodeName( libname ) );
125 if ( !path.isEmpty() ) 125 if ( !path.isEmpty() )
126 { 126 {
127 info = new PluginInfo; 127 info = new PluginInfo;
128 info->library = libname; 128 info->library = libname;
129 info->nameLabel = i18n( "sharp" ); 129 info->nameLabel = i18n( "sharp" );
130 info->descriptionLabel = i18n( "Sharp DTM Addressbook." ); 130 info->descriptionLabel = i18n( "Sharp DTM Addressbook." );
131 mTypeMap.insert( "sharp", info ); 131 mTypeMap.insert( "sharp", info );
132 } 132 }
133 133
134 134
135} 135}
136 136
137Factory::~Factory() 137Factory::~Factory()
138{ 138{
139} 139}
140 140
141QStringList Factory::typeNames() const 141QStringList Factory::typeNames() const
142{ 142{
143//US method QMap::keys() not available yet. SO collect the data manually 143//US method QMap::keys() not available yet. SO collect the data manually
144//US return mTypeMap.keys(); 144//US return mTypeMap.keys();
145 145
146 QStringList result; 146 QStringList result;
147 147
148 QMap<QString, PluginInfo*>::ConstIterator it; 148 QMap<QString, PluginInfo*>::ConstIterator it;
149 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) { 149 for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) {
150 result << it.key().latin1(); 150 result << it.key().latin1();
151// qDebug("Factory::typeNames() : %s ", it.key().latin1()); 151// qDebug("Factory::typeNames() : %s ", it.key().latin1());
152 152
153 } 153 }
154 return result; 154 return result;
155} 155}
156 156
157ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) 157ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
158{ 158{
159 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 159 if ( type.isEmpty() || !mTypeMap.contains( type ) )
160 return 0; 160 return 0;
161 161
162//US KService::Ptr ptr = mTypeMap[ type ]; 162//US KService::Ptr ptr = mTypeMap[ type ];
163//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); 163//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
164 PluginInfo* pi = mTypeMap[ type ]; 164 PluginInfo* pi = mTypeMap[ type ];
165 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); 165 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
166 if ( !factory ) { 166 if ( !factory ) {
167 qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1()); 167 qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1());
168 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl; 168 kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl;
169 return 0; 169 return 0;
170 } 170 }
171 171
172 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); 172 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
173 173
174 if ( !pluginFactory ) { 174 if ( !pluginFactory ) {
175 qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1()); 175 qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1());
176 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl; 176 kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl;
177 return 0; 177 return 0;
178 } 178 }
179 179
180 ConfigWidget *wdg = pluginFactory->configWidget( parent ); 180 ConfigWidget *wdg = pluginFactory->configWidget( parent );
181 if ( !wdg ) { 181 if ( !wdg ) {
182//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 182//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
183 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); 183 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
184 return 0; 184 return 0;
185 } 185 }
186 return wdg; 186 return wdg;
187 187
188} 188}
189 189
190SyncWidgetContainer *Factory::syncWidgetContainer( const QString& type )
191{
192 if ( type.isEmpty() || !mTypeMap.contains( type ) )
193 return 0;
194
195//US KService::Ptr ptr = mTypeMap[ type ];
196//US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
197 PluginInfo* pi = mTypeMap[ type ];
198 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
199 if ( !factory ) {
200 qDebug("KRES::Factory::syncWidget(): Factory creation failed for library %s", pi->library.latin1());
201 kdDebug() << "KRES::Factory::syncWidget(): Factory creation failed" << endl;
202 return 0;
203 }
204
205 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
206
207 if ( !pluginFactory ) {
208 qDebug("KRES::Factory::syncWidget(): no plugin factory for library %s", pi->library.latin1());
209 kdDebug() << "KRES::Factory::syncWidget(): no plugin factory." << endl;
210 return 0;
211 }
212
213 SyncWidgetContainer *wdg = pluginFactory->syncWidgetContainer( );
214 if ( !wdg ) {
215//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
216 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
217 return 0;
218 }
219 return wdg;
220
221}
222
223
224QString Factory::typeName( const QString &type ) const 190QString Factory::typeName( const QString &type ) const
225{ 191{
226 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 192 if ( type.isEmpty() || !mTypeMap.contains( type ) )
227 return QString(); 193 return QString();
228 194
229 195
230//US KService::Ptr ptr = mTypeMap[ type ]; 196//US KService::Ptr ptr = mTypeMap[ type ];
231//US return ptr->name(); 197//US return ptr->name();
232 PluginInfo* pi = mTypeMap[ type ]; 198 PluginInfo* pi = mTypeMap[ type ];
233 return pi->nameLabel; 199 return pi->nameLabel;
234 200
235} 201}
236 202
237QString Factory::typeDescription( const QString &type ) const 203QString Factory::typeDescription( const QString &type ) const
238{ 204{
239 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 205 if ( type.isEmpty() || !mTypeMap.contains( type ) )
240 return QString(); 206 return QString();
241 207
242//US KService::Ptr ptr = mTypeMap[ type ]; 208//US KService::Ptr ptr = mTypeMap[ type ];
243//US return ptr->comment(); 209//US return ptr->comment();
244 PluginInfo* pi = mTypeMap[ type ]; 210 PluginInfo* pi = mTypeMap[ type ];
245 return pi->descriptionLabel; 211 return pi->descriptionLabel;
246} 212}
247 213
248Resource *Factory::resource( const QString& type, const KConfig *config, bool syncable ) 214Resource *Factory::resource( const QString& type, const KConfig *config )
249{ 215{
250 216
251 217
252 if ( type.isEmpty() || !mTypeMap.contains( type ) ) 218 if ( type.isEmpty() || !mTypeMap.contains( type ) )
253 return 0; 219 return 0;
254 220
255/*US load the lib not dynamicly. !! 221/*US load the lib not dynamicly. !!
256 KService::Ptr ptr = mTypeMap[ type ]; 222 KService::Ptr ptr = mTypeMap[ type ];
257 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); 223 KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
258 if ( !factory ) { 224 if ( !factory ) {
259 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; 225 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
260 return 0; 226 return 0;
261 } 227 }
262*/ 228*/
263 PluginInfo* pi = mTypeMap[ type ]; 229 PluginInfo* pi = mTypeMap[ type ];
264 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); 230 KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() );
265 if ( !factory ) { 231 if ( !factory ) {
266 qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1()); 232 qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1());
267 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; 233 kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
268 return 0; 234 return 0;
269 } 235 }
270 236
271 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); 237 PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
272 238
273 if ( !pluginFactory ) { 239 if ( !pluginFactory ) {
274 qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); 240 qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1());
275 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; 241 kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl;
276 return 0; 242 return 0;
277 } 243 }
278 244
279 Resource *resource = pluginFactory->resource( config, syncable ); 245 Resource *resource = pluginFactory->resource( config );
280 if ( !resource ) { 246 if ( !resource ) {
281//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 247//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
282 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); 248 qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1());
283 return 0; 249 return 0;
284 } 250 }
285 251
286 resource->setType( type ); 252 resource->setType( type );
287 253
288 return resource; 254 return resource;
289} 255}
diff --git a/microkde/kresources/factory.h b/microkde/kresources/factory.h
index 0e4231b..ea01b23 100644
--- a/microkde/kresources/factory.h
+++ b/microkde/kresources/factory.h
@@ -1,139 +1,126 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24#ifndef KRESOURCES_FACTORY_H 24#ifndef KRESOURCES_FACTORY_H
25#define KRESOURCES_FACTORY_H 25#define KRESOURCES_FACTORY_H
26 26
27#include <qdict.h> 27#include <qdict.h>
28#include <qstring.h> 28#include <qstring.h>
29 29
30#include <kconfig.h> 30#include <kconfig.h>
31 31
32 32
33#include "resource.h" 33#include "resource.h"
34 34
35namespace KRES { 35namespace KRES {
36 36
37class SyncWidgetContainer;
38class ConfigWidget; 37class ConfigWidget;
39 38
40//US 39//US
41struct PluginInfo 40struct PluginInfo
42{ 41{
43 QString library; 42 QString library;
44 QString nameLabel; 43 QString nameLabel;
45 QString descriptionLabel; 44 QString descriptionLabel;
46}; 45};
47 46
48 47
49/** 48/**
50 * Class for loading resource plugins. 49 * Class for loading resource plugins.
51 * Do not use this class directly. Use ResourceManager instead 50 * Do not use this class directly. Use ResourceManager instead
52 * 51 *
53 * Example: 52 * Example:
54 * 53 *
55 * <pre> 54 * <pre>
56 * KABC::Factory<Calendar> *factory = KABC::Factory<Calendar>::self(); 55 * KABC::Factory<Calendar> *factory = KABC::Factory<Calendar>::self();
57 * 56 *
58 * QStringList list = factory->resources(); 57 * QStringList list = factory->resources();
59 * QStringList::Iterator it; 58 * QStringList::Iterator it;
60 * for ( it = list.begin(); it != list.end(); ++it ) { 59 * for ( it = list.begin(); it != list.end(); ++it ) {
61 * Resource<Calendar> *resource = factory->resource( (*it), 60 * Resource<Calendar> *resource = factory->resource( (*it),
62 * KABC::StdAddressBook::self(), 0 ); 61 * KABC::StdAddressBook::self(), 0 );
63 * // do something with resource 62 * // do something with resource
64 * } 63 * }
65 * </pre> 64 * </pre>
66 */ 65 */
67class Factory 66class Factory
68{ 67{
69 public: 68 public:
70 69
71 70
72 /** 71 /**
73 * Returns the global resource factory. 72 * Returns the global resource factory.
74 */ 73 */
75 static Factory *self( const QString& resourceFamily ); 74 static Factory *self( const QString& resourceFamily );
76 75
77 ~Factory(); 76 ~Factory();
78 77
79 /** 78 /**
80 * Returns the config widget for the given resource type, 79 * Returns the config widget for the given resource type,
81 * or a null pointer if resource type doesn't exist. 80 * or a null pointer if resource type doesn't exist.
82 * 81 *
83 * @param type The type of the resource, returned by @ref resources() 82 * @param type The type of the resource, returned by @ref resources()
84 * @param resource The resource to be editted. 83 * @param resource The resource to be editted.
85 * @param parent The parent widget 84 * @param parent The parent widget
86 */ 85 */
87 ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 ); 86 ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 );
88 87
89 /** 88 /**
90 * Returns the sync widget for the given resource type,
91 * or a null pointer if resource type doesn't exist,
92 * or a null pointer if resource does not support syncing.
93 *
94 * @param type The type of the resource, returned by @ref resources()
95 * @param resource The resource to be editted.
96 * @param parent The parent widget
97 */
98 SyncWidgetContainer *syncWidgetContainer( const QString& type );
99
100 /**
101 * Returns a pointer to a resource object or a null pointer 89 * Returns a pointer to a resource object or a null pointer
102 * if resource type doesn't exist. 90 * if resource type doesn't exist.
103 * 91 *
104 * @param type The type of the resource, returned by @ref resources() 92 * @param type The type of the resource, returned by @ref resources()
105 * @param ab The address book, the resource should belong to 93 * @param ab The address book, the resource should belong to
106 * @param config The config object where the resource get it settings from, or 0 if a new resource should be created. 94 * @param config The config object where the resource get it settings from, or 0 if a new resource should be created.
107 * @param syncable If the resource should support syncing capabilities.
108 */ 95 */
109 Resource *resource( const QString& type, const KConfig *config, bool syncable ); 96 Resource *resource( const QString& type, const KConfig *config);
110 97
111 /** 98 /**
112 * Returns a list of all available resource types. 99 * Returns a list of all available resource types.
113 */ 100 */
114 QStringList typeNames() const; 101 QStringList typeNames() const;
115 102
116 /** 103 /**
117 * Returns the name for a special type. 104 * Returns the name for a special type.
118 */ 105 */
119 QString typeName( const QString &type ) const; 106 QString typeName( const QString &type ) const;
120 107
121 /** 108 /**
122 * Returns the description for a special type. 109 * Returns the description for a special type.
123 */ 110 */
124 QString typeDescription( const QString &type ) const; 111 QString typeDescription( const QString &type ) const;
125 112
126 protected: 113 protected:
127 Factory( const QString& resourceFamily); 114 Factory( const QString& resourceFamily);
128 115
129 private: 116 private:
130 static QDict<Factory> *mSelves; 117 static QDict<Factory> *mSelves;
131 118
132 QString mResourceFamily; 119 QString mResourceFamily;
133//US QMap<QString, KService::Ptr> mTypeMap; 120//US QMap<QString, KService::Ptr> mTypeMap;
134//US lets store the pluginfo struct as value instead of a KService 121//US lets store the pluginfo struct as value instead of a KService
135 QMap<QString, PluginInfo*> mTypeMap; 122 QMap<QString, PluginInfo*> mTypeMap;
136}; 123};
137 124
138} 125}
139#endif 126#endif
diff --git a/microkde/kresources/manager.h b/microkde/kresources/manager.h
index 7e9e19a..0e6f838 100644
--- a/microkde/kresources/manager.h
+++ b/microkde/kresources/manager.h
@@ -1,346 +1,340 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 Copyright (c) 2004 Ulf Schenk 7 Copyright (c) 2004 Ulf Schenk
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either 11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version. 12 version 2 of the License, or (at your option) any later version.
13 13
14 This library is distributed in the hope that it will be useful, 14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details. 17 Library General Public License for more details.
18 18
19 You should have received a copy of the GNU Library General Public License 19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to 20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. 22 Boston, MA 02111-1307, USA.
23*/ 23*/
24 24
25/* 25/*
26Enhanced Version of the file for platform independent KDE tools. 26Enhanced Version of the file for platform independent KDE tools.
27Copyright (c) 2004 Ulf Schenk 27Copyright (c) 2004 Ulf Schenk
28 28
29$Id$ 29$Id$
30*/ 30*/
31 31
32#ifndef KRESOURCES_MANAGER_H 32#ifndef KRESOURCES_MANAGER_H
33#define KRESOURCES_MANAGER_H 33#define KRESOURCES_MANAGER_H
34 34
35#include <qdict.h> 35#include <qdict.h>
36#include <qstringlist.h> 36#include <qstringlist.h>
37 37
38#include "factory.h" 38#include "factory.h"
39#include "managerimpl.h" 39#include "managerimpl.h"
40 40
41namespace KRES { 41namespace KRES {
42 42
43class Resource; 43class Resource;
44 44
45template<class T> 45template<class T>
46class ManagerListener 46class ManagerListener
47{ 47{
48 public: 48 public:
49 virtual void resourceAdded( T *resource ) = 0; 49 virtual void resourceAdded( T *resource ) = 0;
50 virtual void resourceModified( T *resource ) = 0; 50 virtual void resourceModified( T *resource ) = 0;
51 virtual void resourceDeleted( T *resource ) = 0; 51 virtual void resourceDeleted( T *resource ) = 0;
52}; 52};
53 53
54// TODO: 54// TODO:
55// The resource manager should provide some signals 55// The resource manager should provide some signals
56// to warn applications that resources have been added, 56// to warn applications that resources have been added,
57// removed or modified. 57// removed or modified.
58// 58//
59// The manager should also keep track of which (or at least 59// The manager should also keep track of which (or at least
60// how many) applications hve opened a resource, so that it 60// how many) applications hve opened a resource, so that it
61// is only closed if none of them is using it any more 61// is only closed if none of them is using it any more
62 62
63template<class T> 63template<class T>
64class Manager : private ManagerImplListener 64class Manager : private ManagerImplListener
65{ 65{
66 public: 66 public:
67 class Iterator 67 class Iterator
68 { 68 {
69 friend class Manager; 69 friend class Manager;
70 public: 70 public:
71 Iterator() {}; 71 Iterator() {};
72 Iterator( const Iterator &it ) { mIt = it.mIt; } 72 Iterator( const Iterator &it ) { mIt = it.mIt; }
73 73
74 T *operator*() { return static_cast<T *>( *mIt ); } 74 T *operator*() { return static_cast<T *>( *mIt ); }
75 Iterator &operator++() { mIt++; return *this; } 75 Iterator &operator++() { mIt++; return *this; }
76 Iterator &operator++(int) { mIt++; return *this; } 76 Iterator &operator++(int) { mIt++; return *this; }
77 Iterator &operator--() { mIt--; return *this; } 77 Iterator &operator--() { mIt--; return *this; }
78 Iterator &operator--(int) { mIt--; return *this; } 78 Iterator &operator--(int) { mIt--; return *this; }
79 bool operator==( const Iterator &it ) { return mIt == it.mIt; } 79 bool operator==( const Iterator &it ) { return mIt == it.mIt; }
80 bool operator!=( const Iterator &it ) { return mIt != it.mIt; } 80 bool operator!=( const Iterator &it ) { return mIt != it.mIt; }
81 81
82 private: 82 private:
83 Resource::List::Iterator mIt; 83 Resource::List::Iterator mIt;
84 }; 84 };
85 85
86 Iterator begin() 86 Iterator begin()
87 { 87 {
88 Iterator it; 88 Iterator it;
89 it.mIt = mImpl->resourceList()->begin(); 89 it.mIt = mImpl->resourceList()->begin();
90 return it; 90 return it;
91 } 91 }
92 92
93 Iterator end() 93 Iterator end()
94 { 94 {
95 Iterator it; 95 Iterator it;
96 it.mIt = mImpl->resourceList()->end(); 96 it.mIt = mImpl->resourceList()->end();
97 return it; 97 return it;
98 } 98 }
99 99
100 class ActiveIterator 100 class ActiveIterator
101 { 101 {
102 friend class Manager; 102 friend class Manager;
103 public: 103 public:
104 ActiveIterator() : mList( 0 ) {}; 104 ActiveIterator() : mList( 0 ) {};
105 ActiveIterator( const ActiveIterator &it ) 105 ActiveIterator( const ActiveIterator &it )
106 { 106 {
107 mIt = it.mIt; 107 mIt = it.mIt;
108 mList = it.mList; 108 mList = it.mList;
109 } 109 }
110 110
111 T *operator*() { return static_cast<T *>( *mIt ); } 111 T *operator*() { return static_cast<T *>( *mIt ); }
112 ActiveIterator &operator++() 112 ActiveIterator &operator++()
113 { 113 {
114 do { mIt++; } while ( checkActive() ); 114 do { mIt++; } while ( checkActive() );
115 return *this; 115 return *this;
116 } 116 }
117 ActiveIterator &operator++(int) 117 ActiveIterator &operator++(int)
118 { 118 {
119 do { mIt++; } while ( checkActive() ); 119 do { mIt++; } while ( checkActive() );
120 return *this; 120 return *this;
121 } 121 }
122 ActiveIterator &operator--() 122 ActiveIterator &operator--()
123 { 123 {
124 do { mIt--; } while ( checkActive() ); 124 do { mIt--; } while ( checkActive() );
125 return *this; 125 return *this;
126 } 126 }
127 ActiveIterator &operator--(int) 127 ActiveIterator &operator--(int)
128 { 128 {
129 do { mIt--; } while ( checkActive() ); 129 do { mIt--; } while ( checkActive() );
130 return *this; 130 return *this;
131 } 131 }
132 bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; } 132 bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; }
133 bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; } 133 bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; }
134 134
135 private: 135 private:
136 /** 136 /**
137 Check if iterator needs to be advanced once more. 137 Check if iterator needs to be advanced once more.
138 */ 138 */
139 bool checkActive() 139 bool checkActive()
140 { 140 {
141 if ( !mList || mIt == mList->end() ) return false; 141 if ( !mList || mIt == mList->end() ) return false;
142 return !(*mIt)->isActive(); 142 return !(*mIt)->isActive();
143 } 143 }
144 144
145 Resource::List::Iterator mIt; 145 Resource::List::Iterator mIt;
146 Resource::List *mList; 146 Resource::List *mList;
147 }; 147 };
148 148
149 ActiveIterator activeBegin() 149 ActiveIterator activeBegin()
150 { 150 {
151 ActiveIterator it; 151 ActiveIterator it;
152 it.mIt = mImpl->resourceList()->begin(); 152 it.mIt = mImpl->resourceList()->begin();
153 it.mList = mImpl->resourceList(); 153 it.mList = mImpl->resourceList();
154 if ( it.mIt != mImpl->resourceList()->end() ) { 154 if ( it.mIt != mImpl->resourceList()->end() ) {
155 if ( !(*it)->isActive() ) it++; 155 if ( !(*it)->isActive() ) it++;
156 } 156 }
157 return it; 157 return it;
158 } 158 }
159 159
160 ActiveIterator activeEnd() 160 ActiveIterator activeEnd()
161 { 161 {
162 ActiveIterator it; 162 ActiveIterator it;
163 it.mIt = mImpl->resourceList()->end(); 163 it.mIt = mImpl->resourceList()->end();
164 it.mList = mImpl->resourceList(); 164 it.mList = mImpl->resourceList();
165 return it; 165 return it;
166 } 166 }
167 167
168 bool isEmpty() const { return mImpl->resourceList()->isEmpty(); } 168 bool isEmpty() const { return mImpl->resourceList()->isEmpty(); }
169 169
170 /** 170 Manager( const QString &family )
171 Return true, if the manager manages syncable resources.
172 */
173 bool manageSyncable() { return mImpl->manageSyncable(); }
174
175 Manager( const QString &family, bool syncable )
176 { 171 {
177 mFactory = Factory::self( family ); 172 mFactory = Factory::self( family );
178 // The managerimpl will use the same Factory object as the manager 173 // The managerimpl will use the same Factory object as the manager
179 // because of the Factory::self() pattern 174 // because of the Factory::self() pattern
180 mImpl = new ManagerImpl( family, syncable ); 175 mImpl = new ManagerImpl( family );
181 mImpl->setListener( this ); 176 mImpl->setListener( this );
182 177
183 mListeners = new QPtrList<ManagerListener<T> >; 178 mListeners = new QPtrList<ManagerListener<T> >;
184 } 179 }
185 180
186 virtual ~Manager() 181 virtual ~Manager()
187 { 182 {
188 mImpl->setListener( 0 ); 183 mImpl->setListener( 0 );
189 delete mListeners; 184 delete mListeners;
190 delete mImpl; 185 delete mImpl;
191 } 186 }
192 187
193 /** 188 /**
194 Recreate Resource objects from configuration file. If cfg is 0, read standard 189 Recreate Resource objects from configuration file. If cfg is 0, read standard
195 configuration file. 190 configuration file.
196 */ 191 */
197 void readConfig( KConfig *cfg = 0 ) 192 void readConfig( KConfig *cfg = 0 )
198 { 193 {
199 mImpl->readConfig( cfg ); 194 mImpl->readConfig( cfg );
200 } 195 }
201 196
202 /** 197 /**
203 Write configuration of Resource objects to configuration file. If cfg is 0, write 198 Write configuration of Resource objects to configuration file. If cfg is 0, write
204 to standard configuration file. 199 to standard configuration file.
205 */ 200 */
206 void writeConfig( KConfig *cfg = 0 ) 201 void writeConfig( KConfig *cfg = 0 )
207 { 202 {
208 mImpl->writeConfig( cfg ); 203 mImpl->writeConfig( cfg );
209 } 204 }
210 205
211 /** 206 /**
212 Add resource to manager. This passes ownership of the Resource object 207 Add resource to manager. This passes ownership of the Resource object
213 to the manager. 208 to the manager.
214 */ 209 */
215 void add( Resource *resource ) 210 void add( Resource *resource )
216 { 211 {
217 if ( resource ) mImpl->add( resource ); 212 if ( resource ) mImpl->add( resource );
218 } 213 }
219 214
220 void remove( Resource *resource ) 215 void remove( Resource *resource )
221 { 216 {
222 if ( resource ) mImpl->remove( resource ); 217 if ( resource ) mImpl->remove( resource );
223 } 218 }
224 219
225 T* standardResource() 220 T* standardResource()
226 { 221 {
227 return static_cast<T *>( mImpl->standardResource() ); 222 return static_cast<T *>( mImpl->standardResource() );
228 } 223 }
229 224
230 void setStandardResource( T *resource ) 225 void setStandardResource( T *resource )
231 { 226 {
232 if ( resource ) mImpl->setStandardResource( resource ); 227 if ( resource ) mImpl->setStandardResource( resource );
233 } 228 }
234 229
235 void setActive( Resource *resource, bool active ) 230 void setActive( Resource *resource, bool active )
236 { 231 {
237 if ( resource ) mImpl->setActive( resource, active ); 232 if ( resource ) mImpl->setActive( resource, active );
238 } 233 }
239 234
240 /** 235 /**
241 Returns a list of the names of the reources managed by the 236 Returns a list of the names of the reources managed by the
242 Manager for this family. 237 Manager for this family.
243 */ 238 */
244 QStringList resourceNames() const 239 QStringList resourceNames() const
245 { 240 {
246 return mImpl->resourceNames(); 241 return mImpl->resourceNames();
247 } 242 }
248 243
249 ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 ) 244 ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 )
250 { 245 {
251 return mFactory->resourceConfigWidget( type, parent ); 246 return mFactory->resourceConfigWidget( type, parent );
252 } 247 }
253 248
254 /** 249 /**
255 Creates a new resource of type @param type, with default 250 Creates a new resource of type @param type, with default
256 settings. The resource is 251 settings. The resource is
257 not added to the manager, the application has to do that. 252 not added to the manager, the application has to do that.
258 Returns a pointer to a resource object or a null pointer 253 Returns a pointer to a resource object or a null pointer
259 if resource type doesn't exist. 254 if resource type doesn't exist.
260 255
261 @param type The type of the resource, one of those returned 256 @param type The type of the resource, one of those returned
262 by @ref resourceTypeNames() 257 by @ref resourceTypeNames()
263 * @param syncable If the resource should support syncing capabilities.
264 */ 258 */
265 T *createResource( const QString& type ) 259 T *createResource( const QString& type )
266 { 260 {
267 return (T *)( mFactory->resource( type, 0, mImpl->manageSyncable() ) ); 261 return (T *)( mFactory->resource( type, 0 ) );
268 } 262 }
269 263
270 /** 264 /**
271 Returns a list of the names of all available resource types. 265 Returns a list of the names of all available resource types.
272 */ 266 */
273 QStringList resourceTypeNames() const 267 QStringList resourceTypeNames() const
274 { 268 {
275 return mFactory->typeNames(); 269 return mFactory->typeNames();
276 } 270 }
277 271
278 QStringList resourceTypeDescriptions() const 272 QStringList resourceTypeDescriptions() const
279 { 273 {
280 QStringList typeDescs; 274 QStringList typeDescs;
281 QStringList types = mFactory->typeNames(); 275 QStringList types = mFactory->typeNames();
282 276
283 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) { 277 for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) {
284 QString desc = mFactory->typeName( *it ); 278 QString desc = mFactory->typeName( *it );
285 if ( !mFactory->typeDescription( *it ).isEmpty() ) 279 if ( !mFactory->typeDescription( *it ).isEmpty() )
286 desc += " (" + mFactory->typeDescription( *it ) + ")"; 280 desc += " (" + mFactory->typeDescription( *it ) + ")";
287 281
288 typeDescs.append( desc ); 282 typeDescs.append( desc );
289 } 283 }
290 284
291 return typeDescs; 285 return typeDescs;
292 } 286 }
293 287
294 void resourceChanged( T *resource ) 288 void resourceChanged( T *resource )
295 { 289 {
296 mImpl->resourceChanged( resource ); 290 mImpl->resourceChanged( resource );
297 } 291 }
298 292
299 void addListener( ManagerListener<T> *listener ) 293 void addListener( ManagerListener<T> *listener )
300 { 294 {
301 mListeners->append( listener ); 295 mListeners->append( listener );
302 } 296 }
303 297
304 void removeListener( ManagerListener<T> *listener ) 298 void removeListener( ManagerListener<T> *listener )
305 { 299 {
306 mListeners->remove( listener ); 300 mListeners->remove( listener );
307 } 301 }
308 302
309 virtual void resourceAdded( Resource *res ) 303 virtual void resourceAdded( Resource *res )
310 { 304 {
311 kdDebug(5650) << "Manager::resourceAdded " << res->resourceName() << endl; 305 kdDebug(5650) << "Manager::resourceAdded " << res->resourceName() << endl;
312 T* resource = (T *)( res ); 306 T* resource = (T *)( res );
313 ManagerListener<T> *listener; 307 ManagerListener<T> *listener;
314 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) 308 for ( listener = mListeners->first(); listener; listener = mListeners->next() )
315 listener->resourceAdded( resource ); 309 listener->resourceAdded( resource );
316 } 310 }
317 311
318 virtual void resourceModified( Resource *res ) 312 virtual void resourceModified( Resource *res )
319 { 313 {
320 kdDebug(5650) << "Manager::resourceModified " << res->resourceName() << endl; 314 kdDebug(5650) << "Manager::resourceModified " << res->resourceName() << endl;
321 T* resource = (T *)( res ); 315 T* resource = (T *)( res );
322 ManagerListener<T> *listener; 316 ManagerListener<T> *listener;
323 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) 317 for ( listener = mListeners->first(); listener; listener = mListeners->next() )
324 listener->resourceModified( resource ); 318 listener->resourceModified( resource );
325 } 319 }
326 320
327 virtual void resourceDeleted( Resource *res ) 321 virtual void resourceDeleted( Resource *res )
328 { 322 {
329 kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl; 323 kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl;
330 T* resource = (T *)( res ); 324 T* resource = (T *)( res );
331 ManagerListener<T> *listener; 325 ManagerListener<T> *listener;
332 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) { 326 for ( listener = mListeners->first(); listener; listener = mListeners->next() ) {
333 kdDebug(5650) << "Notifying a listener to Manager..." << endl; 327 kdDebug(5650) << "Notifying a listener to Manager..." << endl;
334 listener->resourceDeleted( resource ); 328 listener->resourceDeleted( resource );
335 } 329 }
336 } 330 }
337 331
338 private: 332 private:
339 ManagerImpl *mImpl; 333 ManagerImpl *mImpl;
340 Factory *mFactory; 334 Factory *mFactory;
341 QPtrList<ManagerListener<T> > *mListeners; 335 QPtrList<ManagerListener<T> > *mListeners;
342}; 336};
343 337
344} 338}
345 339
346#endif 340#endif
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp
index 3655f50..81bbbec 100644
--- a/microkde/kresources/managerimpl.cpp
+++ b/microkde/kresources/managerimpl.cpp
@@ -1,374 +1,367 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32 32
33#include <kapplication.h> 33#include <kapplication.h>
34#include <kdebug.h> 34#include <kdebug.h>
35#include <kconfig.h> 35#include <kconfig.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "resource.h" 38#include "resource.h"
39#include "factory.h" 39#include "factory.h"
40#include "managerimpl.h" 40#include "managerimpl.h"
41 41
42using namespace KRES; 42using namespace KRES;
43 43
44ManagerImpl::ManagerImpl( const QString &family, bool syncable ) 44ManagerImpl::ManagerImpl( const QString &family )
45 : mFamily( family ), mSyncable(syncable), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ), 45 : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
46 mFactory( 0 ) 46 mFactory( 0 )
47 47
48{ 48{
49 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl; 49 kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl;
50 50
51 51
52} 52}
53 53
54ManagerImpl::~ManagerImpl() 54ManagerImpl::~ManagerImpl()
55{ 55{
56 kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl; 56 kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl;
57 57
58 Resource::List::ConstIterator it; 58 Resource::List::ConstIterator it;
59 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 59 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
60 delete *it; 60 delete *it;
61 } 61 }
62 62
63 delete mStdConfig; 63 delete mStdConfig;
64} 64}
65 65
66void ManagerImpl::createStandardConfig() 66void ManagerImpl::createStandardConfig()
67{ 67{
68 if ( !mStdConfig ) { 68 if ( !mStdConfig ) {
69 QString file = locateLocal( "data", KGlobal::getAppName() 69 QString file = locateLocal( "data", KGlobal::getAppName()
70 + "/kresources/" + mFamily + "rc" ); 70 + "/kresources/" + mFamily + "rc" );
71 mStdConfig = new KConfig( file ); 71 mStdConfig = new KConfig( file );
72 } 72 }
73 73
74 mConfig = mStdConfig; 74 mConfig = mStdConfig;
75} 75}
76 76
77void ManagerImpl::readConfig( KConfig *cfg ) 77void ManagerImpl::readConfig( KConfig *cfg )
78{ 78{
79 kdDebug(5650) << "ManagerImpl::readConfig()" << endl; 79 kdDebug(5650) << "ManagerImpl::readConfig()" << endl;
80 80
81 delete mFactory; 81 delete mFactory;
82 mFactory = Factory::self( mFamily ); 82 mFactory = Factory::self( mFamily );
83 83
84 if ( !cfg ) { 84 if ( !cfg ) {
85 createStandardConfig(); 85 createStandardConfig();
86 } else { 86 } else {
87 mConfig = cfg; 87 mConfig = cfg;
88 } 88 }
89 89
90 mStandard = 0; 90 mStandard = 0;
91 91
92 mConfig->setGroup( "General" ); 92 mConfig->setGroup( "General" );
93 93
94 QStringList keys = mConfig->readListEntry( "ResourceKeys" ); 94 QStringList keys = mConfig->readListEntry( "ResourceKeys" );
95 keys += mConfig->readListEntry( "PassiveResourceKeys" ); 95 keys += mConfig->readListEntry( "PassiveResourceKeys" );
96 96
97 QString standardKey = mConfig->readEntry( "Standard" ); 97 QString standardKey = mConfig->readEntry( "Standard" );
98 98
99 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { 99 for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
100 readResourceConfig( *it, false ); 100 readResourceConfig( *it, false );
101 } 101 }
102 102
103} 103}
104 104
105void ManagerImpl::writeConfig( KConfig *cfg ) 105void ManagerImpl::writeConfig( KConfig *cfg )
106{ 106{
107//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg); 107//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg);
108 108
109 109
110 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; 110 kdDebug(5650) << "ManagerImpl::writeConfig()" << endl;
111 111
112 if ( !cfg ) { 112 if ( !cfg ) {
113 createStandardConfig(); 113 createStandardConfig();
114 } else { 114 } else {
115 mConfig = cfg; 115 mConfig = cfg;
116 } 116 }
117 117
118 QStringList activeKeys; 118 QStringList activeKeys;
119 QStringList passiveKeys; 119 QStringList passiveKeys;
120 120
121 // First write all keys, collect active and passive keys on the way 121 // First write all keys, collect active and passive keys on the way
122 Resource::List::Iterator it; 122 Resource::List::Iterator it;
123 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 123 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
124 writeResourceConfig( *it, false ); 124 writeResourceConfig( *it, false );
125 125
126 QString key = (*it)->identifier(); 126 QString key = (*it)->identifier();
127 if( (*it)->isActive() ) 127 if( (*it)->isActive() )
128 activeKeys.append( key ); 128 activeKeys.append( key );
129 else 129 else
130 passiveKeys.append( key ); 130 passiveKeys.append( key );
131 } 131 }
132 132
133 // And then the general group 133 // And then the general group
134 134
135 kdDebug(5650) << "Saving general info" << endl; 135 kdDebug(5650) << "Saving general info" << endl;
136 mConfig->setGroup( "General" ); 136 mConfig->setGroup( "General" );
137 mConfig->writeEntry( "ResourceKeys", activeKeys ); 137 mConfig->writeEntry( "ResourceKeys", activeKeys );
138 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); 138 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
139 if ( mStandard ) 139 if ( mStandard )
140 mConfig->writeEntry( "Standard", mStandard->identifier() ); 140 mConfig->writeEntry( "Standard", mStandard->identifier() );
141 else 141 else
142 mConfig->writeEntry( "Standard", "" ); 142 mConfig->writeEntry( "Standard", "" );
143 143
144 mConfig->sync(); 144 mConfig->sync();
145 kdDebug(5650) << "ManagerImpl::save() finished" << endl; 145 kdDebug(5650) << "ManagerImpl::save() finished" << endl;
146 146
147//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg); 147//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg);
148 148
149} 149}
150 150
151void ManagerImpl::add( Resource *resource, bool useDCOP ) 151void ManagerImpl::add( Resource *resource, bool useDCOP )
152{ 152{
153qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource); 153qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
154 154
155 resource->setActive( true ); 155 resource->setActive( true );
156 156
157 if ( mResources.isEmpty() ) { 157 if ( mResources.isEmpty() ) {
158 mStandard = resource; 158 mStandard = resource;
159 } 159 }
160 160
161 mResources.append( resource ); 161 mResources.append( resource );
162 162
163 writeResourceConfig( resource, true ); 163 writeResourceConfig( resource, true );
164 164
165 qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource); 165 qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource);
166 166
167} 167}
168 168
169void ManagerImpl::remove( Resource *resource, bool useDCOP ) 169void ManagerImpl::remove( Resource *resource, bool useDCOP )
170{ 170{
171 if ( mStandard == resource ) mStandard = 0; 171 if ( mStandard == resource ) mStandard = 0;
172 removeResource( resource ); 172 removeResource( resource );
173 173
174 mResources.remove( resource ); 174 mResources.remove( resource );
175 175
176 delete resource; 176 delete resource;
177 177
178 kdDebug(5650) << "Finished ManagerImpl::remove()" << endl; 178 kdDebug(5650) << "Finished ManagerImpl::remove()" << endl;
179} 179}
180 180
181void ManagerImpl::setActive( Resource *resource, bool active ) 181void ManagerImpl::setActive( Resource *resource, bool active )
182{ 182{
183 if ( resource && resource->isActive() != active ) { 183 if ( resource && resource->isActive() != active ) {
184 resource->setActive( active ); 184 resource->setActive( active );
185 } 185 }
186} 186}
187 187
188Resource *ManagerImpl::standardResource() 188Resource *ManagerImpl::standardResource()
189{ 189{
190 return mStandard; 190 return mStandard;
191} 191}
192 192
193void ManagerImpl::setStandardResource( Resource *resource ) 193void ManagerImpl::setStandardResource( Resource *resource )
194{ 194{
195 mStandard = resource; 195 mStandard = resource;
196} 196}
197 197
198void ManagerImpl::resourceChanged( Resource *resource ) 198void ManagerImpl::resourceChanged( Resource *resource )
199{ 199{
200 writeResourceConfig( resource, true ); 200 writeResourceConfig( resource, true );
201 201
202 202
203// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() ); 203// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() );
204// allManagers.dcopResourceModified( resource->identifier() ); 204// allManagers.dcopResourceModified( resource->identifier() );
205} 205}
206 206
207// DCOP asynchronous functions 207// DCOP asynchronous functions
208//US since we work from inside the application, we call the methods directly. 208//US since we work from inside the application, we call the methods directly.
209 209
210QStringList ManagerImpl::resourceNames() 210QStringList ManagerImpl::resourceNames()
211{ 211{
212 QStringList result; 212 QStringList result;
213 213
214 Resource::List::ConstIterator it; 214 Resource::List::ConstIterator it;
215 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 215 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
216 result.append( (*it)->resourceName() ); 216 result.append( (*it)->resourceName() );
217 } 217 }
218 return result; 218 return result;
219} 219}
220 220
221Resource::List *ManagerImpl::resourceList() 221Resource::List *ManagerImpl::resourceList()
222{ 222{
223 return &mResources; 223 return &mResources;
224} 224}
225 225
226QPtrList<Resource> ManagerImpl::resources() 226QPtrList<Resource> ManagerImpl::resources()
227{ 227{
228 QPtrList<Resource> result; 228 QPtrList<Resource> result;
229 229
230 Resource::List::ConstIterator it; 230 Resource::List::ConstIterator it;
231 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 231 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
232 result.append( *it ); 232 result.append( *it );
233 } 233 }
234 return result; 234 return result;
235} 235}
236 236
237QPtrList<Resource> ManagerImpl::resources( bool active ) 237QPtrList<Resource> ManagerImpl::resources( bool active )
238{ 238{
239 QPtrList<Resource> result; 239 QPtrList<Resource> result;
240 240
241 Resource::List::ConstIterator it; 241 Resource::List::ConstIterator it;
242 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 242 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
243 if ( (*it)->isActive() == active ) { 243 if ( (*it)->isActive() == active ) {
244 result.append( *it ); 244 result.append( *it );
245 } 245 }
246 } 246 }
247 return result; 247 return result;
248} 248}
249 249
250void ManagerImpl::setListener( ManagerImplListener *listener ) 250void ManagerImpl::setListener( ManagerImplListener *listener )
251{ 251{
252 mListener = listener; 252 mListener = listener;
253} 253}
254 254
255Resource* ManagerImpl::readResourceConfig( const QString& identifier, 255Resource* ManagerImpl::readResourceConfig( const QString& identifier,
256 bool checkActive ) 256 bool checkActive )
257{ 257{
258 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; 258 kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl;
259 259
260// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); 260// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1());
261 261
262 mConfig->setGroup( "Resource_" + identifier ); 262 mConfig->setGroup( "Resource_" + identifier );
263#ifdef _WIN32_ 263#ifdef _WIN32_
264 // we use plugins on win32. the group is stored in a static variable 264 // we use plugins on win32. the group is stored in a static variable
265 // such that gourp info not avail on win32 plugins 265 // such that gourp info not avail on win32 plugins
266 // to fix that, it would be a looooot of work 266 // to fix that, it would be a looooot of work
267 mConfig->setTempGroup( "Resource_" + identifier ); 267 mConfig->setTempGroup( "Resource_" + identifier );
268#endif 268#endif
269 QString type = mConfig->readEntry( "ResourceType" ); 269 QString type = mConfig->readEntry( "ResourceType" );
270 QString name = mConfig->readEntry( "ResourceName" ); 270 QString name = mConfig->readEntry( "ResourceName" );
271 Resource *resource = mFactory->resource( type, mConfig, mSyncable ); 271 Resource *resource = mFactory->resource( type, mConfig );
272 if ( !resource ) { 272 if ( !resource ) {
273 qDebug("Failed to create resource with id %s ",identifier.latin1() ); 273 qDebug("Failed to create resource with id %s ",identifier.latin1() );
274 return 0; 274 return 0;
275 } 275 }
276 276
277 if ( resource->identifier().isEmpty() ) 277 if ( resource->identifier().isEmpty() )
278 resource->setIdentifier( identifier ); 278 resource->setIdentifier( identifier );
279 279
280 mConfig->setGroup( "General" ); 280 mConfig->setGroup( "General" );
281 281
282 QString standardKey = mConfig->readEntry( "Standard" ); 282 QString standardKey = mConfig->readEntry( "Standard" );
283 if ( standardKey == identifier ) { 283 if ( standardKey == identifier ) {
284 mStandard = resource; 284 mStandard = resource;
285 } 285 }
286 286
287 if ( checkActive ) { 287 if ( checkActive ) {
288 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 288 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
289 resource->setActive( activeKeys.contains( identifier ) ); 289 resource->setActive( activeKeys.contains( identifier ) );
290 } 290 }
291 mResources.append( resource ); 291 mResources.append( resource );
292 292
293 return resource; 293 return resource;
294} 294}
295 295
296void ManagerImpl::writeResourceConfig( Resource *resource, 296void ManagerImpl::writeResourceConfig( Resource *resource,
297 bool checkActive ) 297 bool checkActive )
298{ 298{
299 QString key = resource->identifier(); 299 QString key = resource->identifier();
300 300
301 kdDebug(5650) << "Saving resource " << key << endl; 301 kdDebug(5650) << "Saving resource " << key << endl;
302 302
303 if ( !mConfig ) createStandardConfig(); 303 if ( !mConfig ) createStandardConfig();
304 304
305 mConfig->setGroup( "Resource_" + key ); 305 mConfig->setGroup( "Resource_" + key );
306 resource->writeConfig( mConfig ); 306 resource->writeConfig( mConfig );
307 307
308 mConfig->setGroup( "General" ); 308 mConfig->setGroup( "General" );
309 QString standardKey = mConfig->readEntry( "Standard" ); 309 QString standardKey = mConfig->readEntry( "Standard" );
310 310
311 if ( resource == mStandard && standardKey != key ) 311 if ( resource == mStandard && standardKey != key )
312 mConfig->writeEntry( "Standard", resource->identifier() ); 312 mConfig->writeEntry( "Standard", resource->identifier() );
313 else if ( resource != mStandard && standardKey == key ) 313 else if ( resource != mStandard && standardKey == key )
314 mConfig->writeEntry( "Standard", "" ); 314 mConfig->writeEntry( "Standard", "" );
315 315
316 if ( checkActive ) { 316 if ( checkActive ) {
317 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 317 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
318 if ( resource->isActive() && !activeKeys.contains( key ) ) { 318 if ( resource->isActive() && !activeKeys.contains( key ) ) {
319 activeKeys.append( resource->identifier() ); 319 activeKeys.append( resource->identifier() );
320 mConfig->writeEntry( "ResourceKeys", activeKeys ); 320 mConfig->writeEntry( "ResourceKeys", activeKeys );
321 } else if ( !resource->isActive() && activeKeys.contains( key ) ) { 321 } else if ( !resource->isActive() && activeKeys.contains( key ) ) {
322 activeKeys.remove( key ); 322 activeKeys.remove( key );
323 mConfig->writeEntry( "ResourceKeys", activeKeys ); 323 mConfig->writeEntry( "ResourceKeys", activeKeys );
324 } 324 }
325 } 325 }
326 326
327 mConfig->sync(); 327 mConfig->sync();
328} 328}
329 329
330void ManagerImpl::removeResource( Resource *resource ) 330void ManagerImpl::removeResource( Resource *resource )
331{ 331{
332 QString key = resource->identifier(); 332 QString key = resource->identifier();
333 333
334 if ( !mConfig ) createStandardConfig(); 334 if ( !mConfig ) createStandardConfig();
335 335
336 mConfig->setGroup( "General" ); 336 mConfig->setGroup( "General" );
337 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); 337 QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
338 if ( activeKeys.contains( key ) ) { 338 if ( activeKeys.contains( key ) ) {
339 activeKeys.remove( key ); 339 activeKeys.remove( key );
340 mConfig->writeEntry( "ResourceKeys", activeKeys ); 340 mConfig->writeEntry( "ResourceKeys", activeKeys );
341 } else { 341 } else {
342 QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); 342 QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" );
343 passiveKeys.remove( key ); 343 passiveKeys.remove( key );
344 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); 344 mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
345 } 345 }
346 346
347 QString standardKey = mConfig->readEntry( "Standard" ); 347 QString standardKey = mConfig->readEntry( "Standard" );
348 if ( standardKey == key ) { 348 if ( standardKey == key ) {
349 mConfig->writeEntry( "Standard", "" ); 349 mConfig->writeEntry( "Standard", "" );
350 } 350 }
351 351
352 mConfig->deleteGroup( "Resource_" + resource->identifier() ); 352 mConfig->deleteGroup( "Resource_" + resource->identifier() );
353 353
354 mConfig->sync(); 354 mConfig->sync();
355} 355}
356 356
357Resource* ManagerImpl::getResource( const QString& identifier ) 357Resource* ManagerImpl::getResource( const QString& identifier )
358{ 358{
359 Resource::List::ConstIterator it; 359 Resource::List::ConstIterator it;
360 for ( it = mResources.begin(); it != mResources.end(); ++it ) { 360 for ( it = mResources.begin(); it != mResources.end(); ++it ) {
361 if ( (*it)->identifier() == identifier ) 361 if ( (*it)->identifier() == identifier )
362 return *it; 362 return *it;
363 } 363 }
364 return 0; 364 return 0;
365} 365}
366 366
367/**
368 Return true, if the manager manages syncable resources.
369*/
370bool ManagerImpl::manageSyncable() const
371{
372 return mSyncable;
373}
374 367
diff --git a/microkde/kresources/managerimpl.h b/microkde/kresources/managerimpl.h
index 0425279..56a2db6 100644
--- a/microkde/kresources/managerimpl.h
+++ b/microkde/kresources/managerimpl.h
@@ -1,126 +1,120 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#ifndef KRESOURCES_MANAGERIMPL_H 31#ifndef KRESOURCES_MANAGERIMPL_H
32#define KRESOURCES_MANAGERIMPL_H 32#define KRESOURCES_MANAGERIMPL_H
33 33
34#include <qstring.h> 34#include <qstring.h>
35#include <qptrlist.h> 35#include <qptrlist.h>
36#include <qdict.h> 36#include <qdict.h>
37//US 37//US
38#include <qobject.h> 38#include <qobject.h>
39 39
40#include "resource.h" 40#include "resource.h"
41 41
42 42
43class KConfig; 43class KConfig;
44 44
45namespace KRES { 45namespace KRES {
46 46
47class Resource; 47class Resource;
48class Factory; 48class Factory;
49 49
50class ManagerImplListener 50class ManagerImplListener
51{ 51{
52 public: 52 public:
53 virtual void resourceAdded( Resource *resource ) = 0; 53 virtual void resourceAdded( Resource *resource ) = 0;
54 virtual void resourceModified( Resource *resource ) = 0; 54 virtual void resourceModified( Resource *resource ) = 0;
55 virtual void resourceDeleted( Resource *resource ) = 0; 55 virtual void resourceDeleted( Resource *resource ) = 0;
56}; 56};
57 57
58 58
59/** 59/**
60 @internal 60 @internal
61 61
62 Do not use this class directly. Use ResourceManager instead 62 Do not use this class directly. Use ResourceManager instead
63*/ 63*/
64class ManagerImpl : public QObject 64class ManagerImpl : public QObject
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67 public: 67 public:
68 ManagerImpl( const QString &family, bool syncable); 68 ManagerImpl( const QString &family);
69 ~ManagerImpl(); 69 ~ManagerImpl();
70 70
71 void readConfig( KConfig * ); 71 void readConfig( KConfig * );
72 void writeConfig( KConfig * ); 72 void writeConfig( KConfig * );
73 73
74 void add( Resource *resource, bool useDCOP = true ); 74 void add( Resource *resource, bool useDCOP = true );
75 void remove( Resource *resource, bool useDCOP = true ); 75 void remove( Resource *resource, bool useDCOP = true );
76 76
77 Resource *standardResource(); 77 Resource *standardResource();
78 void setStandardResource( Resource *resource ); 78 void setStandardResource( Resource *resource );
79 79
80 void setActive( Resource *resource, bool active ); 80 void setActive( Resource *resource, bool active );
81 81
82 Resource::List *resourceList(); 82 Resource::List *resourceList();
83 83
84 QPtrList<Resource> resources(); 84 QPtrList<Resource> resources();
85 85
86 // Get only active or passive resources 86 // Get only active or passive resources
87 QPtrList<Resource> resources( bool active ); 87 QPtrList<Resource> resources( bool active );
88 88
89 QStringList resourceNames(); 89 QStringList resourceNames();
90 90
91 void setListener( ManagerImplListener *listener ); 91 void setListener( ManagerImplListener *listener );
92 92
93 /**
94 Return true, if the manager manages syncable resources.
95 */
96 bool manageSyncable() const;
97
98 public slots: 93 public slots:
99 void resourceChanged( Resource *resource ); 94 void resourceChanged( Resource *resource );
100 95
101 private: 96 private:
102 // dcop calls 97 // dcop calls
103 98
104 private: 99 private:
105 void createStandardConfig(); 100 void createStandardConfig();
106 101
107 Resource *readResourceConfig( const QString& identifier, bool checkActive ); 102 Resource *readResourceConfig( const QString& identifier, bool checkActive );
108 void writeResourceConfig( Resource *resource, bool checkActive ); 103 void writeResourceConfig( Resource *resource, bool checkActive );
109 104
110 void removeResource( Resource *resource ); 105 void removeResource( Resource *resource );
111 Resource *getResource( Resource *resource ); 106 Resource *getResource( Resource *resource );
112 Resource *getResource( const QString& identifier ); 107 Resource *getResource( const QString& identifier );
113 108
114 QString mFamily; 109 QString mFamily;
115 bool mSyncable;
116 KConfig *mConfig; 110 KConfig *mConfig;
117 KConfig *mStdConfig; 111 KConfig *mStdConfig;
118 Resource *mStandard; 112 Resource *mStandard;
119 Factory *mFactory; 113 Factory *mFactory;
120 Resource::List mResources; 114 Resource::List mResources;
121 ManagerImplListener *mListener; 115 ManagerImplListener *mListener;
122}; 116};
123 117
124} 118}
125 119
126#endif 120#endif
diff --git a/microkde/kresources/resource.cpp b/microkde/kresources/resource.cpp
index f79bcd0..cccd485 100644
--- a/microkde/kresources/resource.cpp
+++ b/microkde/kresources/resource.cpp
@@ -1,204 +1,205 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24#include <kdebug.h> 24#include <kdebug.h>
25#include <kapplication.h> 25#include <kapplication.h>
26#include <kconfig.h> 26#include <kconfig.h>
27 27
28#include "resource.h" 28#include "resource.h"
29 29
30using namespace KRES; 30using namespace KRES;
31 31
32class Resource::ResourcePrivate 32class Resource::ResourcePrivate
33{ 33{
34 public: 34 public:
35#ifdef QT_THREAD_SUPPORT 35#ifdef QT_THREAD_SUPPORT
36 QMutex mMutex; 36 QMutex mMutex;
37#endif 37#endif
38 int mOpenCount; 38 int mOpenCount;
39 QString mType; 39 QString mType;
40 QString mIdentifier; 40 QString mIdentifier;
41 bool mReadOnly; 41 bool mReadOnly;
42 bool mIncludeInSync; 42 bool mIncludeInSync;
43 QString mName; 43 QString mName;
44 bool mActive; 44 bool mActive;
45 bool mIsOpen; 45 bool mIsOpen;
46}; 46};
47 47
48Resource::Resource( const KConfig* config ) 48Resource::Resource( const KConfig* config )
49 : QObject( 0, "" ), d( new ResourcePrivate ) 49 : QObject( 0, "" ), d( new ResourcePrivate )
50{ 50{
51 d->mOpenCount = 0; 51 d->mOpenCount = 0;
52 d->mIsOpen = false; 52 d->mIsOpen = false;
53 53
54 //US compiler claimed that const discards qualifier 54 //US compiler claimed that const discards qualifier
55 KConfig* cfg = (KConfig*)config; 55 KConfig* cfg = (KConfig*)config;
56 if ( cfg ) { 56 if ( cfg ) {
57#ifdef _WIN32_ 57#ifdef _WIN32_
58 // we use plugins on win32. the group is stored in a static variable 58 // we use plugins on win32. the group is stored in a static variable
59 // such that group info not available on win32 plugins 59 // such that group info not available on win32 plugins
60 // to fix that, it would be a looooot of work 60 // to fix that, it would be a looooot of work
61 if ( !cfg->tempGroup().isEmpty() ) 61 if ( !cfg->tempGroup().isEmpty() )
62 cfg->setGroup( cfg->tempGroup() ); 62 cfg->setGroup( cfg->tempGroup() );
63#endif 63#endif
64 d->mType = cfg->readEntry( "ResourceType" ); 64 d->mType = cfg->readEntry( "ResourceType" );
65 d->mName = cfg->readEntry( "ResourceName" ); 65 d->mName = cfg->readEntry( "ResourceName" );
66 d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false ); 66 d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false );
67 d->mIncludeInSync = cfg->readBoolEntry( "ResourceIncludeInSync", true );; 67 d->mIncludeInSync = cfg->readBoolEntry( "ResourceIncludeInSync", true );;
68 d->mActive = cfg->readBoolEntry( "ResourceIsActive", true ); 68 d->mActive = cfg->readBoolEntry( "ResourceIsActive", true );
69 d->mIdentifier = cfg->readEntry( "ResourceIdentifier" ); 69 d->mIdentifier = cfg->readEntry( "ResourceIdentifier" );
70 } else { 70 } else {
71 d->mType = "type"; 71 d->mType = "type";
72 d->mName = "resource-name"; 72 d->mName = "resource-name";
73 d->mReadOnly = false; 73 d->mReadOnly = false;
74 d->mIncludeInSync = true; 74 d->mIncludeInSync = true;
75 d->mActive = true; 75 d->mActive = true;
76 d->mIdentifier = KApplication::randomString( 10 ); 76 d->mIdentifier = KApplication::randomString( 10 );
77 } 77 }
78} 78}
79 79
80Resource::~Resource() 80Resource::~Resource()
81{ 81{
82 delete d; 82 delete d;
83 d = 0; 83 d = 0;
84} 84}
85 85
86void Resource::writeConfig( KConfig* config ) 86void Resource::writeConfig( KConfig* config )
87{ 87{
88 config->writeEntry( "ResourceType", d->mType ); 88 config->writeEntry( "ResourceType", d->mType );
89 config->writeEntry( "ResourceName", d->mName ); 89 config->writeEntry( "ResourceName", d->mName );
90 config->writeEntry( "ResourceIsReadOnly", d->mReadOnly ); 90 config->writeEntry( "ResourceIsReadOnly", d->mReadOnly );
91 config->writeEntry( "ResourceIncludeInSync", d->mIncludeInSync ); 91 config->writeEntry( "ResourceIncludeInSync", d->mIncludeInSync );
92 config->writeEntry( "ResourceIsActive", d->mActive ); 92 config->writeEntry( "ResourceIsActive", d->mActive );
93 config->writeEntry( "ResourceIdentifier", d->mIdentifier ); 93 config->writeEntry( "ResourceIdentifier", d->mIdentifier );
94} 94}
95 95
96bool Resource::open() 96bool Resource::open()
97{ 97{
98 d->mIsOpen = true; 98 d->mIsOpen = true;
99#ifdef QT_THREAD_SUPPORT 99#ifdef QT_THREAD_SUPPORT
100 QMutexLocker guard( &(d->mMutex) ); 100 QMutexLocker guard( &(d->mMutex) );
101#endif 101#endif
102 if ( !d->mOpenCount ) { 102 if ( !d->mOpenCount ) {
103 kdDebug(5650) << "Opening resource " << resourceName() << endl; 103 kdDebug(5650) << "Opening resource " << resourceName() << endl;
104 d->mIsOpen = doOpen(); 104 d->mIsOpen = doOpen();
105 } 105 }
106 d->mOpenCount++; 106 d->mOpenCount++;
107 return d->mIsOpen; 107 return d->mIsOpen;
108} 108}
109 109
110void Resource::close() 110void Resource::close()
111{ 111{
112#ifdef QT_THREAD_SUPPORT 112#ifdef QT_THREAD_SUPPORT
113 QMutexLocker guard( &(d->mMutex) ); 113 QMutexLocker guard( &(d->mMutex) );
114#endif 114#endif
115 if ( !d->mOpenCount ) { 115 if ( !d->mOpenCount ) {
116 kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl; 116 kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl;
117 return; 117 return;
118 } 118 }
119 d->mOpenCount--; 119 d->mOpenCount--;
120 if ( !d->mOpenCount ) { 120 if ( !d->mOpenCount ) {
121 kdDebug(5650) << "Closing resource " << resourceName() << endl; 121 kdDebug(5650) << "Closing resource " << resourceName() << endl;
122 doClose(); 122 doClose();
123 d->mIsOpen = false; 123 d->mIsOpen = false;
124 } else { 124 } else {
125 kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl; 125 kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl;
126 } 126 }
127} 127}
128 128
129bool Resource::isOpen() const 129bool Resource::isOpen() const
130{ 130{
131 return d->mIsOpen; 131 return d->mIsOpen;
132} 132}
133 133
134void Resource::setIdentifier( const QString& identifier ) 134void Resource::setIdentifier( const QString& identifier )
135{ 135{
136 d->mIdentifier = identifier; 136 d->mIdentifier = identifier;
137} 137}
138 138
139QString Resource::identifier() const 139QString Resource::identifier() const
140{ 140{
141 return d->mIdentifier; 141 return d->mIdentifier;
142} 142}
143 143
144void Resource::setType( const QString& type ) 144void Resource::setType( const QString& type )
145{ 145{
146 d->mType = type; 146 d->mType = type;
147} 147}
148 148
149QString Resource::type() const 149QString Resource::type() const
150{ 150{
151 return d->mType; 151 return d->mType;
152} 152}
153 153
154void Resource::setIncludeInSync( bool value ) 154void Resource::setIncludeInSync( bool value )
155{ 155{
156 d->mIncludeInSync = value; 156 d->mIncludeInSync = value;
157} 157}
158bool Resource::includeInSync() const 158bool Resource::includeInSync() const
159{ 159{
160 return d->mIncludeInSync; 160 return d->mIncludeInSync;
161} 161}
162void Resource::setReadOnly( bool value ) 162void Resource::setReadOnly( bool value )
163{ 163{
164 d->mReadOnly = value; 164 d->mReadOnly = value;
165} 165}
166 166
167bool Resource::readOnly() const 167bool Resource::readOnly() const
168{ 168{
169 return d->mReadOnly; 169 return d->mReadOnly;
170} 170}
171 171
172void Resource::setResourceName( const QString &name ) 172void Resource::setResourceName( const QString &name )
173{ 173{
174 d->mName = name; 174 d->mName = name;
175} 175}
176 176
177QString Resource::resourceName() const 177QString Resource::resourceName() const
178{ 178{
179 return d->mName; 179 return d->mName;
180} 180}
181 181
182void Resource::setActive( bool value ) 182void Resource::setActive( bool value )
183{ 183{
184 d->mActive = value; 184 d->mActive = value;
185} 185}
186 186
187bool Resource::isActive() const 187bool Resource::isActive() const
188{ 188{
189 return d->mActive; 189 return d->mActive;
190} 190}
191 191
192void Resource::dump() const 192void Resource::dump() const
193{ 193{
194 qDebug("Resource::dump() "); 194 qDebug("Resource::dump() ");
195 kdDebug(5650) << "Resource:" << endl; 195 kdDebug(5650) << "Resource:" << endl;
196 kdDebug(5650) << " Name: " << d->mName << endl; 196 kdDebug(5650) << " Name: " << d->mName << endl;
197 kdDebug(5650) << " Identifier: " << d->mIdentifier << endl; 197 kdDebug(5650) << " Identifier: " << d->mIdentifier << endl;
198 kdDebug(5650) << " Type: " << d->mType << endl; 198 kdDebug(5650) << " Type: " << d->mType << endl;
199 kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl; 199 kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl;
200 kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl; 200 kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl;
201 kdDebug(5650) << " IncludeInSync: " << ( d->mIncludeInSync ? "yes" : "no" ) << endl;
201 kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl; 202 kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl;
202 kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl; 203 kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl;
203} 204}
204 205
diff --git a/microkde/kresources/resource.h b/microkde/kresources/resource.h
index 70b5613..ed5af96 100644
--- a/microkde/kresources/resource.h
+++ b/microkde/kresources/resource.h
@@ -1,418 +1,404 @@
1/* 1/*
2 This file is part of libkresources 2 This file is part of libkresources
3 3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#ifndef KRESOURCES_RESOURCE_H 23#ifndef KRESOURCES_RESOURCE_H
24#define KRESOURCES_RESOURCE_H 24#define KRESOURCES_RESOURCE_H
25 25
26//US 26//US
27#ifdef QT_THREAD_SUPPORT 27#ifdef QT_THREAD_SUPPORT
28#include <qmutex.h> 28#include <qmutex.h>
29#endif //QT_THREAD_SUPPORT 29#endif //QT_THREAD_SUPPORT
30 30
31#include <qvaluelist.h> 31#include <qvaluelist.h>
32#include <qwidget.h> 32#include <qwidget.h>
33 33
34#include <qobject.h> 34#include <qobject.h>
35 35
36#include <klibloader.h> 36#include <klibloader.h>
37 37
38class KConfig; 38class KConfig;
39 39
40namespace KRES { 40namespace KRES {
41 41
42class ConfigWidget; 42class ConfigWidget;
43class SyncWidgetContainer;
44 43
45/** 44/**
46 * @internal 45 * @internal
47 * @libdoc The KDE Resource library 46 * @libdoc The KDE Resource library
48 * 47 *
49 * NOTE: this library is NOT (YET?) PUBLIC. Do not publish this 48 * NOTE: this library is NOT (YET?) PUBLIC. Do not publish this
50 * interface, it is in constant flux. 49 * interface, it is in constant flux.
51 * 50 *
52 * The KDE Resource framework can be used to manage resources of 51 * The KDE Resource framework can be used to manage resources of
53 * different types, organized in families. The Resource framework 52 * different types, organized in families. The Resource framework
54 * is currently used for addressbook resources in libkabc and for 53 * is currently used for addressbook resources in libkabc and for
55 * calendar resources in libkcal. 54 * calendar resources in libkcal.
56 * 55 *
57 * When you want to use the framework for a new family, you need to 56 * When you want to use the framework for a new family, you need to
58 * <ul><li>Define a name for your resource family</li> 57 * <ul><li>Define a name for your resource family</li>
59 * <li>subclass Resource and add the fields and method that are needed 58 * <li>subclass Resource and add the fields and method that are needed
60 * in your application</li> 59 * in your application</li>
61 * <li>If needed, override the doOpen() and doClose() methods. 60 * <li>If needed, override the doOpen() and doClose() methods.
62 * <li> Provide a configuration possibility for resources in your 61 * <li> Provide a configuration possibility for resources in your
63 * new family. You can use @ref ResourcesConfigPage to easily create a 62 * new family. You can use @ref ResourcesConfigPage to easily create a
64 * KControl applet</li> 63 * KControl applet</li>
65 * <li>In your application, you can use @ref ResourceManager to keep track 64 * <li>In your application, you can use @ref ResourceManager to keep track
66 * of the resources in your family, and you can use @ref ResourceSelectDialog 65 * of the resources in your family, and you can use @ref ResourceSelectDialog
67 * to let the user select a single resource.</li> 66 * to let the user select a single resource.</li>
68 * </ul> 67 * </ul>
69 * 68 *
70 * When you want to add a new resource type to an existing resource family, 69 * When you want to add a new resource type to an existing resource family,
71 * you need to 70 * you need to
72 * <ul><li>Further subclass the family-specific Resource to implement 71 * <ul><li>Further subclass the family-specific Resource to implement
73 * resource type-specific operation</li> 72 * resource type-specific operation</li>
74 * <li>Subclass ResourceConfigWidget to provide a configuration widget 73 * <li>Subclass ResourceConfigWidget to provide a configuration widget
75 * for your new resource type</li> 74 * for your new resource type</li>
76 * <li>Provide a .desktop file so that the new resource type can be found 75 * <li>Provide a .desktop file so that the new resource type can be found
77 * automatically by the ResourceManager</li> 76 * automatically by the ResourceManager</li>
78 * </ul> 77 * </ul>
79 * 78 *
80 * Example: 79 * Example:
81 * 80 *
82<B>resourceexample.h</B>: 81<B>resourceexample.h</B>:
83<pre> 82<pre>
84#include <kconfig.h> 83#include <kconfig.h>
85#include <kresources/resource.h> 84#include <kresources/resource.h>
86 85
87class ResourceExample : public KRES::ResourceExample 86class ResourceExample : public KRES::ResourceExample
88{ 87{
89public: 88public:
90 ResourceExample( const KConfig * ); 89 ResourceExample( const KConfig * );
91 ~ResourceCalendarExchange(); 90 ~ResourceCalendarExchange();
92 void writeConfig( KConfig *config ); 91 void writeConfig( KConfig *config );
93private: 92private:
94 QString mLocation; 93 QString mLocation;
95 QString mPassword; 94 QString mPassword;
96} 95}
97</pre> 96</pre>
98<B>resourceexample.cpp</B>: 97<B>resourceexample.cpp</B>:
99<pre> 98<pre>
100#include <kconfig.h> 99#include <kconfig.h>
101 100
102#include "resourceexample.h" 101#include "resourceexample.h"
103 102
104ResourceExample::ResourceExample( const KConfig *config ) 103ResourceExample::ResourceExample( const KConfig *config )
105 : Resource( config ) 104 : Resource( config )
106{ 105{
107 if ( config ) { 106 if ( config ) {
108 mLocation = config->readEntry( "Location" ); 107 mLocation = config->readEntry( "Location" );
109 mPassword = KStringHandler::obscure( config->readEntry( "Password" ) ); 108 mPassword = KStringHandler::obscure( config->readEntry( "Password" ) );
110 } else { 109 } else {
111 mLocation = ""; // Or some sensible default 110 mLocation = ""; // Or some sensible default
112 mPassword = ""; 111 mPassword = "";
113 } 112 }
114} 113}
115 114
116void ResourceExample::writeConfig( KConfig *config ) 115void ResourceExample::writeConfig( KConfig *config )
117{ 116{
118 KRES::Resource::writeConfig( config ); 117 KRES::Resource::writeConfig( config );
119 config->writeEntry( "Location", mLocation ); 118 config->writeEntry( "Location", mLocation );
120 config->writeEntry( "Password", KStringHandler::obscure( mPassword ) ); 119 config->writeEntry( "Password", KStringHandler::obscure( mPassword ) );
121} 120}
122 121
123extern "C" 122extern "C"
124{ 123{
125 KRES::ResourceExample *config_widget( QWidget *parent ) { 124 KRES::ResourceExample *config_widget( QWidget *parent ) {
126 return new ResourceExampleConfig( parent, "Configure Example Resource" ); 125 return new ResourceExampleConfig( parent, "Configure Example Resource" );
127 } 126 }
128 127
129 KRES::Resource *resource( const KConfig *config ) { 128 KRES::Resource *resource( const KConfig *config ) {
130 return new ResourceExample( config ); 129 return new ResourceExample( config );
131 } 130 }
132} 131}
133</pre> 132</pre>
134* <B>resourceexampleconfig.h</B>: 133* <B>resourceexampleconfig.h</B>:
135<pre> 134<pre>
136#include <klineedit.h> 135#include <klineedit.h>
137#include <kresources/resourceconfigwidget.h> 136#include <kresources/resourceconfigwidget.h>
138 137
139#include "resourceexample.h" 138#include "resourceexample.h"
140 139
141class ResourceExampleConfig : public KRES::ResourceConfigWidget 140class ResourceExampleConfig : public KRES::ResourceConfigWidget
142{ 141{
143 Q_OBJECT 142 Q_OBJECT
144 143
145public: 144public:
146 ResourceExampleConfig( QWidget* parent = 0, const char* name = 0 ); 145 ResourceExampleConfig( QWidget* parent = 0, const char* name = 0 );
147 146
148public slots: 147public slots:
149 virtual void loadSettings( KRES::Resource *resource); 148 virtual void loadSettings( KRES::Resource *resource);
150 virtual void saveSettings( KRES::Resource *resource ); 149 virtual void saveSettings( KRES::Resource *resource );
151 150
152private: 151private:
153 KLineEdit* mLocationEdit; 152 KLineEdit* mLocationEdit;
154 KLineEdit* mPasswordEdit; 153 KLineEdit* mPasswordEdit;
155}; 154};
156</pre> 155</pre>
157* <B>resourceexampleconfig.cpp</B>: 156* <B>resourceexampleconfig.cpp</B>:
158<pre> 157<pre>
159#include <qlayout.h> 158#include <qlayout.h>
160#include <qlabel.h" 159#include <qlabel.h"
161#include <kresources/resourceconfigwidget.h> 160#include <kresources/resourceconfigwidget.h>
162#include "resourceexample.h" 161#include "resourceexample.h"
163#include "resourceexampleconfig.h" 162#include "resourceexampleconfig.h"
164 163
165ResourceExampleConfig::ResourceExampleConfig( QWidget* parent, const char* name ) 164ResourceExampleConfig::ResourceExampleConfig( QWidget* parent, const char* name )
166 : KRES::ResourceConfigWidget( parent, name ) 165 : KRES::ResourceConfigWidget( parent, name )
167{ 166{
168 resize( 245, 115 ); 167 resize( 245, 115 );
169 QGridLayout *mainLayout = new QGridLayout( this, 2, 2 ); 168 QGridLayout *mainLayout = new QGridLayout( this, 2, 2 );
170 169
171 QLabel *label = new QLabel( i18n( "Location:" ), this ); 170 QLabel *label = new QLabel( i18n( "Location:" ), this );
172 mHostEdit = new KLineEdit( this ); 171 mHostEdit = new KLineEdit( this );
173 mainLayout->addWidget( label, 1, 0 ); 172 mainLayout->addWidget( label, 1, 0 );
174 mainLayout->addWidget( mHostEdit, 1, 1 ); 173 mainLayout->addWidget( mHostEdit, 1, 1 );
175 174
176 label = new QLabel( i18n( "Password:" ), this ); 175 label = new QLabel( i18n( "Password:" ), this );
177 mPasswordEdit = new KLineEdit( this ); 176 mPasswordEdit = new KLineEdit( this );
178 mPasswordEdit->setEchoMode( QLineEdit::Password ); 177 mPasswordEdit->setEchoMode( QLineEdit::Password );
179 mainLayout->addWidget( label, 2, 0 ); 178 mainLayout->addWidget( label, 2, 0 );
180 mainLayout->addWidget( mPasswordEdit, 2, 1 ); 179 mainLayout->addWidget( mPasswordEdit, 2, 1 );
181} 180}
182 181
183void ResourceExampleConfig::loadSettings( KRES::Resource *resource ) 182void ResourceExampleConfig::loadSettings( KRES::Resource *resource )
184{ 183{
185 ResourceExample* res = dynamic_cast<ResourceExample *>( resource ); 184 ResourceExample* res = dynamic_cast<ResourceExample *>( resource );
186 if (res) { 185 if (res) {
187 mHostEdit->setText( res->host() ); 186 mHostEdit->setText( res->host() );
188 mPasswordEdit->setText( res->password() ); 187 mPasswordEdit->setText( res->password() );
189 } else 188 } else
190 kdDebug(5700) << "ERROR: ResourceExampleConfig::loadSettings(): no ResourceExample, cast failed" << endl; 189 kdDebug(5700) << "ERROR: ResourceExampleConfig::loadSettings(): no ResourceExample, cast failed" << endl;
191} 190}
192 191
193void ResourceExampleConfig::saveSettings( KRES::Resource *resource ) 192void ResourceExampleConfig::saveSettings( KRES::Resource *resource )
194{ 193{
195 ResourceExample* res = dynamic_cast<ResourceExample *>( resource ); 194 ResourceExample* res = dynamic_cast<ResourceExample *>( resource );
196 if (res) { 195 if (res) {
197 res->setHost(mHostEdit->text()); 196 res->setHost(mHostEdit->text());
198 res->setPassword(mPasswordEdit->text()); 197 res->setPassword(mPasswordEdit->text());
199 } else 198 } else
200 kdDebug(5700) << "ERROR: ResourceExampleConfig::saveSettings(): no ResourceExample, cast failed" << endl; 199 kdDebug(5700) << "ERROR: ResourceExampleConfig::saveSettings(): no ResourceExample, cast failed" << endl;
201} 200}
202</pre> 201</pre>
203* <B>resourceexample.desktop</B>: 202* <B>resourceexample.desktop</B>:
204<pre> 203<pre>
205[Desktop Entry] 204[Desktop Entry]
206Type=Service 205Type=Service
207 206
208[Misc] 207[Misc]
209Encoding=UTF-8 208Encoding=UTF-8
210Name=Example Resource 209Name=Example Resource
211 210
212[Plugin] 211[Plugin]
213Type=exchange 212Type=exchange
214X-KDE-Library=resourceexample 213X-KDE-Library=resourceexample
215</pre> 214</pre>
216* <B>Makefile.am</B> 215* <B>Makefile.am</B>
217<pre> 216<pre>
218kde_module_LTLIBRARIES = resourceexample.la 217kde_module_LTLIBRARIES = resourceexample.la
219 218
220resourceexample_la_SOURCES = resourceexample.cpp resourceexampleconfig.cpp 219resourceexample_la_SOURCES = resourceexample.cpp resourceexampleconfig.cpp
221resourceexample_la_LDFLAGS= $(all_libraries) -module $(KDE_PLUGIN) 220resourceexample_la_LDFLAGS= $(all_libraries) -module $(KDE_PLUGIN)
222resourceexample_la_LIBADD= -lkderesources 221resourceexample_la_LIBADD= -lkderesources
223 222
224linkdir= $(kde_datadir)/resources/family 223linkdir= $(kde_datadir)/resources/family
225link_DATA= resourceexample.desktop 224link_DATA= resourceexample.desktop
226</pre> 225</pre>
227 * 226 *
228 * 227 *
229 */ 228 */
230 229
231/** 230/**
232 * A @ref Resource is a ... 231 * A @ref Resource is a ...
233 * 232 *
234 * A subclass should reimplement at least the constructor and the 233 * A subclass should reimplement at least the constructor and the
235 * @ref writeConfig method. 234k * @ref writeConfig method.
236 * 235 *
237 */ 236 */
238class Resource : public QObject 237class Resource : public QObject
239{ 238{
240 Q_OBJECT 239 Q_OBJECT
241 240
242 public: 241 public:
243 typedef QValueList<Resource *> List; 242 typedef QValueList<Resource *> List;
244 243
245 /** 244 /**
246 * Constructor. Construct resource from config. 245 * Constructor. Construct resource from config.
247 * @param config Configuration to read persistence information from. 246 * @param config Configuration to read persistence information from.
248 * If config==0, create object using default settings. 247 * If config==0, create object using default settings.
249 */ 248 */
250 Resource( const KConfig* config ); 249 Resource( const KConfig* config );
251 250
252 /** 251 /**
253 * Destructor. 252 * Destructor.
254 */ 253 */
255 virtual ~Resource(); 254 virtual ~Resource();
256 255
257 /** 256 /**
258 * Write configuration information for this resource to a configuration 257 * Write configuration information for this resource to a configuration
259 * file. If you override this method, remember to call Resource::writeConfig 258 * file. If you override this method, remember to call Resource::writeConfig
260 * or Terrible Things(TM) will happen. 259 * or Terrible Things(TM) will happen.
261 * @param config Configuration to write persistence information to. 260 * @param config Configuration to write persistence information to.
262 */ 261 */
263 virtual void writeConfig( KConfig* config ); 262 virtual void writeConfig( KConfig* config );
264 263
265 /** 264 /**
266 * Open this resource, if it not already open. Increase the open 265 * Open this resource, if it not already open. Increase the open
267 * count of this object, and open the resource by calling @ref doOpen(). 266 * count of this object, and open the resource by calling @ref doOpen().
268 * This method may block while another thread is concurrently opening 267 * This method may block while another thread is concurrently opening
269 * or closing the resource. 268 * or closing the resource.
270 * 269 *
271 * Returns true if the resource was already opened or if it was opened 270 * Returns true if the resource was already opened or if it was opened
272 * successfully; returns false if the resource was not opened successfully. 271 * successfully; returns false if the resource was not opened successfully.
273 */ 272 */
274 bool open(); 273 bool open();
275 274
276 /** 275 /**
277 * Decrease the open count of this object, and if the count reaches 276 * Decrease the open count of this object, and if the count reaches
278 * zero, close this resource by calling @ref doClose(). 277 * zero, close this resource by calling @ref doClose().
279 * This method may block while another thread is concurrently closing 278 * This method may block while another thread is concurrently closing
280 * or opening the resource. 279 * or opening the resource.
281 */ 280 */
282 void close(); 281 void close();
283 282
284 /** 283 /**
285 * Returns whether the resource is open or not. 284 * Returns whether the resource is open or not.
286 */ 285 */
287 bool isOpen() const; 286 bool isOpen() const;
288 287
289 /** 288 /**
290 * Returns a unique identifier. The identifier is unique for this resource. 289 * Returns a unique identifier. The identifier is unique for this resource.
291 * It is created when the resource is first created, and it is retained 290 * It is created when the resource is first created, and it is retained
292 * in the resource family configuration file for this resource. 291 * in the resource family configuration file for this resource.
293 * @return This resource's identifier 292 * @return This resource's identifier
294 */ 293 */
295 QString identifier() const; 294 QString identifier() const;
296 295
297 /** 296 /**
298 * Returns the type of this resource. 297 * Returns the type of this resource.
299 */ 298 */
300 QString type() const; 299 QString type() const;
301 300
302 /** 301 /**
303 * Mark the resource as read-only. You can override this method, 302 * Mark the resource as read-only. You can override this method,
304 * but also remember to call Resource::setReadOnly(). 303 * but also remember to call Resource::setReadOnly().
305 */ 304 */
306 virtual void setReadOnly( bool value ); 305 virtual void setReadOnly( bool value );
307 306
308 /** 307 /**
309 * Returns, if the resource is read-only. 308 * Returns, if the resource is read-only.
310 */ 309 */
311 virtual bool readOnly() const; 310 virtual bool readOnly() const;
312 311
313 void setIncludeInSync( bool value ); 312 void setIncludeInSync( bool value );
314 bool includeInSync() const; 313 bool includeInSync() const;
315 /** 314 /**
316 * Set the name of resource.You can override this method, 315 * Set the name of resource.You can override this method,
317 * but also remember to call Resource::setResourceName(). 316 * but also remember to call Resource::setResourceName().
318 */ 317 */
319 virtual void setResourceName( const QString &name ); 318 virtual void setResourceName( const QString &name );
320 319
321 /** 320 /**
322 * Returns the name of resource. 321 * Returns the name of resource.
323 */ 322 */
324 virtual QString resourceName() const; 323 virtual QString resourceName() const;
325 324
326
327
328 virtual bool isSyncable() const = 0;
329
330
331 /** 325 /**
332 Sets, if the resource is active. 326 Sets, if the resource is active.
333 */ 327 */
334 void setActive( bool active ); 328 void setActive( bool active );
335 329
336 /** 330 /**
337 Return true, if the resource is active. 331 Return true, if the resource is active.
338 */ 332 */
339 bool isActive() const; 333 bool isActive() const;
340 334
341 friend class Factory; 335 friend class Factory;
342 friend class ManagerImpl; 336 friend class ManagerImpl;
343 337
344 /** 338 /**
345 Print resource information as debug output. 339 Print resource information as debug output.
346 */ 340 */
347 virtual void dump() const; 341 virtual void dump() const;
348 342
349 343
350 protected: 344 protected:
351 /** 345 /**
352 * Open this resource. When called, the resource must be in 346 * Open this resource. When called, the resource must be in
353 * a closed state. 347 * a closed state.
354 * 348 *
355 * Returns true if the resource was opened successfully; 349 * Returns true if the resource was opened successfully;
356 * returns false if the resource was not opened successfully. 350 * returns false if the resource was not opened successfully.
357 * 351 *
358 * The result of this call can be accessed later by @ref isOpen() 352 * The result of this call can be accessed later by @ref isOpen()
359 */ 353 */
360 virtual bool doOpen() { return true; } 354 virtual bool doOpen() { return true; }
361 355
362 /** 356 /**
363 * Close this resource. Pre-condition: resource is open. 357 * Close this resource. Pre-condition: resource is open.
364 * Post-condition: resource is closed. 358 * Post-condition: resource is closed.
365 */ 359 */
366 virtual void doClose() {} 360 virtual void doClose() {}
367 361
368 void setIdentifier( const QString& identifier ); 362 void setIdentifier( const QString& identifier );
369 void setType( const QString& type ); 363 void setType( const QString& type );
370 364
371 private: 365 private:
372 class ResourcePrivate; 366 class ResourcePrivate;
373 ResourcePrivate *d; 367 ResourcePrivate *d;
374}; 368};
375 369
376class PluginFactoryBase : public KLibFactory 370class PluginFactoryBase : public KLibFactory
377{ 371{
378 public: 372 public:
379 virtual Resource *resource( const KConfig *config, bool syncable ) = 0; 373 virtual Resource *resource( const KConfig *config) = 0;
380 374
381 virtual ConfigWidget *configWidget( QWidget *parent ) = 0; 375 virtual ConfigWidget *configWidget( QWidget *parent ) = 0;
382 376
383 virtual SyncWidgetContainer *syncWidgetContainer() = 0;
384
385 protected: 377 protected:
386 virtual QObject* createObject( QObject*, const char*, const char*, 378 virtual QObject* createObject( QObject*, const char*, const char*,
387 const QStringList & ) 379 const QStringList & )
388 { 380 {
389 return 0; 381 return 0;
390 } 382 }
391}; 383};
392 384
393template<class TR,class TC, class TS> 385template<class TR,class TC>
394class PluginFactory : public PluginFactoryBase 386class PluginFactory : public PluginFactoryBase
395{ 387{
396 public: 388 public:
397 Resource *resource( const KConfig *config, bool syncable ) 389 Resource *resource( const KConfig *config)
398 { 390 {
399 return new TR( config, syncable ); 391 return new TR( config );
400 } 392 }
401 393
402 ConfigWidget *configWidget( QWidget *parent ) 394 ConfigWidget *configWidget( QWidget *parent )
403 { 395 {
404 return new TC( parent ); 396 return new TC( parent );
405 } 397 }
406
407 SyncWidgetContainer *syncWidgetContainer()
408 {
409 return new TS();
410 }
411
412}; 398};
413 399
414 400
415 401
416} 402}
417 403
418#endif 404#endif
diff --git a/microkde/microkdeE.pro b/microkde/microkdeE.pro
index df914ce..071ceb3 100644
--- a/microkde/microkdeE.pro
+++ b/microkde/microkdeE.pro
@@ -1,179 +1,177 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3INCLUDEPATH += . $(KDEPIMDIR)/qtcompat $(KDEPIMDIR)/kabc kdecore kdeui kio/kfile kio/kio $(QPEDIR)/include 3INCLUDEPATH += . $(KDEPIMDIR)/qtcompat $(KDEPIMDIR)/kabc kdecore kdeui kio/kfile kio/kio $(QPEDIR)/include
4 4
5DEPENDPATH += $(QPEDIR)/include 5DEPENDPATH += $(QPEDIR)/include
6LIBS += -lmicroqtcompat -L$(QPEDIR)/lib 6LIBS += -lmicroqtcompat -L$(QPEDIR)/lib
7 7
8DEFINES += KDE_QT_ONLY 8DEFINES += KDE_QT_ONLY
9 9
10 TARGET = microkde 10 TARGET = microkde
11OBJECTS_DIR = obj/$(PLATFORM) 11OBJECTS_DIR = obj/$(PLATFORM)
12MOC_DIR = moc/$(PLATFORM) 12MOC_DIR = moc/$(PLATFORM)
13DESTDIR=$(QPEDIR)/lib 13DESTDIR=$(QPEDIR)/lib
14 14
15 15
16INTERFACES = \ 16INTERFACES = \
17 17
18HEADERS = \ 18HEADERS = \
19qlayoutengine_p.h \ 19qlayoutengine_p.h \
20KDGanttMinimizeSplitter.h \ 20KDGanttMinimizeSplitter.h \
21 kapplication.h \ 21 kapplication.h \
22 kaudioplayer.h \ 22 kaudioplayer.h \
23 kcalendarsystem.h \ 23 kcalendarsystem.h \
24 kcalendarsystemgregorian.h \ 24 kcalendarsystemgregorian.h \
25 kcolorbutton.h \ 25 kcolorbutton.h \
26 kcolordialog.h \ 26 kcolordialog.h \
27 kcombobox.h \ 27 kcombobox.h \
28 kconfig.h \ 28 kconfig.h \
29 kdatetbl.h \ 29 kdatetbl.h \
30 kdebug.h \ 30 kdebug.h \
31 kdialog.h \ 31 kdialog.h \
32 kdialogbase.h \ 32 kdialogbase.h \
33 keditlistbox.h \ 33 keditlistbox.h \
34 kemailsettings.h \ 34 kemailsettings.h \
35 kfiledialog.h \ 35 kfiledialog.h \
36 kfontdialog.h \ 36 kfontdialog.h \
37 kglobal.h \ 37 kglobal.h \
38 kglobalsettings.h \ 38 kglobalsettings.h \
39 kiconloader.h \ 39 kiconloader.h \
40 klineedit.h \ 40 klineedit.h \
41 klineeditdlg.h \ 41 klineeditdlg.h \
42 kmessagebox.h \ 42 kmessagebox.h \
43 knotifyclient.h \ 43 knotifyclient.h \
44 kprinter.h \ 44 kprinter.h \
45 kprocess.h \ 45 kprocess.h \
46 krestrictedline.h \ 46 krestrictedline.h \
47 krun.h \ 47 krun.h \
48 ksimpleconfig.h \ 48 ksimpleconfig.h \
49 kstaticdeleter.h \ 49 kstaticdeleter.h \
50 ksystemtray.h \ 50 ksystemtray.h \
51 ktempfile.h \ 51 ktempfile.h \
52 ktextedit.h \ 52 ktextedit.h \
53 kunload.h \ 53 kunload.h \
54 kurl.h \ 54 kurl.h \
55 ofileselector_p.h \ 55 ofileselector_p.h \
56 ofontselector.h \ 56 ofontselector.h \
57oprocctrl.h \ 57oprocctrl.h \
58oprocess.h \ 58oprocess.h \
59osmartpointer.h \ 59osmartpointer.h \
60 kdeui/kguiitem.h \ 60 kdeui/kguiitem.h \
61 kdeui/kaction.h \ 61 kdeui/kaction.h \
62 kdeui/kactionclasses.h \ 62 kdeui/kactionclasses.h \
63 kdeui/kactioncollection.h \ 63 kdeui/kactioncollection.h \
64 kdeui/kcmodule.h \ 64 kdeui/kcmodule.h \
65 kdeui/kstdaction.h \ 65 kdeui/kstdaction.h \
66 kdeui/kbuttonbox.h \ 66 kdeui/kbuttonbox.h \
67 kdeui/klistbox.h \ 67 kdeui/klistbox.h \
68 kdeui/klistview.h \ 68 kdeui/klistview.h \
69 kdeui/kjanuswidget.h \ 69 kdeui/kjanuswidget.h \
70 kdeui/kseparator.h \ 70 kdeui/kseparator.h \
71 kdeui/kmainwindow.h \ 71 kdeui/kmainwindow.h \
72 kdeui/knuminput.h \ 72 kdeui/knuminput.h \
73 kdeui/knumvalidator.h \ 73 kdeui/knumvalidator.h \
74 kdeui/ksqueezedtextlabel.h \ 74 kdeui/ksqueezedtextlabel.h \
75 kdeui/ktoolbar.h \ 75 kdeui/ktoolbar.h \
76 kdeui/ktoolbarbutton.h \ 76 kdeui/ktoolbarbutton.h \
77 kdeui/ktoolbarhandler.h \ 77 kdeui/ktoolbarhandler.h \
78 kdeui/kxmlguiclient.h \ 78 kdeui/kxmlguiclient.h \
79 kio/job.h \ 79 kio/job.h \
80 kio/kio/kdirwatch.h \ 80 kio/kio/kdirwatch.h \
81 kio/kio/kdirwatch_p.h \ 81 kio/kio/kdirwatch_p.h \
82 kio/kfile/kurlrequester.h \ 82 kio/kfile/kurlrequester.h \
83 kresources/resource.h \ 83 kresources/resource.h \
84 kresources/factory.h \ 84 kresources/factory.h \
85 kresources/managerimpl.h \ 85 kresources/managerimpl.h \
86 kresources/manager.h \ 86 kresources/manager.h \
87 kresources/selectdialog.h \ 87 kresources/selectdialog.h \
88 kresources/configpage.h \ 88 kresources/configpage.h \
89 kresources/configwidget.h \ 89 kresources/configwidget.h \
90 kresources/configdialog.h \ 90 kresources/configdialog.h \
91 kresources/kcmkresources.h \ 91 kresources/kcmkresources.h \
92 kresources/syncwidget.h \
93 kdecore/kmdcodec.h \ 92 kdecore/kmdcodec.h \
94 kdecore/kconfigbase.h \ 93 kdecore/kconfigbase.h \
95 kdecore/klocale.h \ 94 kdecore/klocale.h \
96 kdecore/klibloader.h \ 95 kdecore/klibloader.h \
97 kdecore/kcatalogue.h \ 96 kdecore/kcatalogue.h \
98 kdecore/kprefs.h \ 97 kdecore/kprefs.h \
99 kdecore/ksharedptr.h \ 98 kdecore/ksharedptr.h \
100 kdecore/kshell.h \ 99 kdecore/kshell.h \
101 kdecore/kstandarddirs.h \ 100 kdecore/kstandarddirs.h \
102 kdecore/kstringhandler.h \ 101 kdecore/kstringhandler.h \
103 kdecore/kshortcut.h \ 102 kdecore/kshortcut.h \
104 kutils/kcmultidialog.h \ 103 kutils/kcmultidialog.h \
105 kidmanager.h 104 kidmanager.h
106 105
107 106
108 107
109 108
110SOURCES = \ 109SOURCES = \
111KDGanttMinimizeSplitter.cpp \ 110KDGanttMinimizeSplitter.cpp \
112 kapplication.cpp \ 111 kapplication.cpp \
113 kcalendarsystem.cpp \ 112 kcalendarsystem.cpp \
114 kcalendarsystemgregorian.cpp \ 113 kcalendarsystemgregorian.cpp \
115 kcolorbutton.cpp \ 114 kcolorbutton.cpp \
116 kcolordialog.cpp \ 115 kcolordialog.cpp \
117 kconfig.cpp \ 116 kconfig.cpp \
118 kdatetbl.cpp \ 117 kdatetbl.cpp \
119 kdialog.cpp \ 118 kdialog.cpp \
120 kdialogbase.cpp \ 119 kdialogbase.cpp \
121 keditlistbox.cpp \ 120 keditlistbox.cpp \
122 kemailsettings.cpp \ 121 kemailsettings.cpp \
123 kfontdialog.cpp \ 122 kfontdialog.cpp \
124 kfiledialog.cpp \ 123 kfiledialog.cpp \
125 kglobal.cpp \ 124 kglobal.cpp \
126 kglobalsettings.cpp \ 125 kglobalsettings.cpp \
127 kiconloader.cpp \ 126 kiconloader.cpp \
128 kmessagebox.cpp \ 127 kmessagebox.cpp \
129 kprocess.cpp \ 128 kprocess.cpp \
130 krun.cpp \ 129 krun.cpp \
131 ksystemtray.cpp \ 130 ksystemtray.cpp \
132 ktempfile.cpp \ 131 ktempfile.cpp \
133 kurl.cpp \ 132 kurl.cpp \
134 ktextedit.cpp \ 133 ktextedit.cpp \
135 ofileselector_p.cpp \ 134 ofileselector_p.cpp \
136 ofontselector.cpp \ 135 ofontselector.cpp \
137oprocctrl.cpp \ 136oprocctrl.cpp \
138oprocess.cpp \ 137oprocess.cpp \
139 kdecore/kcatalogue.cpp \ 138 kdecore/kcatalogue.cpp \
140 kdecore/klibloader.cpp \ 139 kdecore/klibloader.cpp \
141 kdecore/klocale.cpp \ 140 kdecore/klocale.cpp \
142 kdecore/kmdcodec.cpp \ 141 kdecore/kmdcodec.cpp \
143 kdecore/kprefs.cpp \ 142 kdecore/kprefs.cpp \
144 kdecore/kshell.cpp \ 143 kdecore/kshell.cpp \
145 kdecore/kstandarddirs.cpp \ 144 kdecore/kstandarddirs.cpp \
146 kdecore/kstringhandler.cpp \ 145 kdecore/kstringhandler.cpp \
147 kdeui/kaction.cpp \ 146 kdeui/kaction.cpp \
148 kdeui/kactionclasses.cpp \ 147 kdeui/kactionclasses.cpp \
149 kdeui/kactioncollection.cpp \ 148 kdeui/kactioncollection.cpp \
150 kdeui/kbuttonbox.cpp \ 149 kdeui/kbuttonbox.cpp \
151 kdeui/kcmodule.cpp \ 150 kdeui/kcmodule.cpp \
152 kdeui/kguiitem.cpp \ 151 kdeui/kguiitem.cpp \
153 kdeui/kjanuswidget.cpp \ 152 kdeui/kjanuswidget.cpp \
154 kdeui/klistbox.cpp \ 153 kdeui/klistbox.cpp \
155 kdeui/klistview.cpp \ 154 kdeui/klistview.cpp \
156 kdeui/kmainwindow.cpp \ 155 kdeui/kmainwindow.cpp \
157 kdeui/knuminput.cpp \ 156 kdeui/knuminput.cpp \
158 kdeui/knumvalidator.cpp \ 157 kdeui/knumvalidator.cpp \
159 kdeui/kseparator.cpp \ 158 kdeui/kseparator.cpp \
160 kdeui/kstdaction.cpp \ 159 kdeui/kstdaction.cpp \
161 kdeui/ksqueezedtextlabel.cpp \ 160 kdeui/ksqueezedtextlabel.cpp \
162 kdeui/ktoolbar.cpp \ 161 kdeui/ktoolbar.cpp \
163 kdeui/ktoolbarbutton.cpp \ 162 kdeui/ktoolbarbutton.cpp \
164 kdeui/ktoolbarhandler.cpp \ 163 kdeui/ktoolbarhandler.cpp \
165 kdeui/kxmlguiclient.cpp \ 164 kdeui/kxmlguiclient.cpp \
166 kio/kfile/kurlrequester.cpp \ 165 kio/kfile/kurlrequester.cpp \
167 kio/kio/kdirwatch.cpp \ 166 kio/kio/kdirwatch.cpp \
168 kresources/configpage.cpp \ 167 kresources/configpage.cpp \
169 kresources/configdialog.cpp \ 168 kresources/configdialog.cpp \
170 kresources/configwidget.cpp \ 169 kresources/configwidget.cpp \
171 kresources/factory.cpp \ 170 kresources/factory.cpp \
172 kresources/kcmkresources.cpp \ 171 kresources/kcmkresources.cpp \
173 kresources/managerimpl.cpp \ 172 kresources/managerimpl.cpp \
174 kresources/resource.cpp \ 173 kresources/resource.cpp \
175 kresources/selectdialog.cpp \ 174 kresources/selectdialog.cpp \
176 kresources/syncwidget.cpp \
177 kutils/kcmultidialog.cpp \ 175 kutils/kcmultidialog.cpp \
178 kidmanager.cpp 176 kidmanager.cpp
179 177