summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/opie/resourceopie.cpp39
-rw-r--r--kabc/plugins/opie/resourceopie.h10
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp49
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.h10
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp30
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.h10
-rw-r--r--kabc/resource.cpp15
-rw-r--r--kabc/resource.h11
-rw-r--r--kabc/tmpaddressbook.cpp14
-rw-r--r--kaddressbook/xxport/opie_xxport.cpp120
-rw-r--r--kaddressbook/xxport/opie_xxport.h4
-rw-r--r--kaddressbook/xxport/qtopia_xxport.cpp225
-rw-r--r--kaddressbook/xxport/sharpdtm_xxport.cpp228
-rw-r--r--kaddressbook/xxport/sharpdtm_xxport.h2
-rw-r--r--kaddressbook/xxportobject.cpp106
-rw-r--r--kaddressbook/xxportobject.h9
16 files changed, 167 insertions, 715 deletions
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index 5559827..9dfd473 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -1,375 +1,348 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#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" 53#include "syncprefwidget.h"
54 54
55#include "opieconverter.h" 55#include "opieconverter.h"
56 56
57#include "resourceopie.h" 57#include "resourceopie.h"
58 58
59using namespace KABC; 59using namespace KABC;
60extern "C" 60extern "C"
61{ 61{
62 void *init_microkabc_opie() 62 void *init_microkabc_opie()
63 { 63 {
64 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidget>(); 64 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidget>();
65 } 65 }
66} 66}
67 67
68ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) 68ResourceOpie::ResourceOpie( const KConfig *config, bool syncable )
69 : Resource( config, syncable ), mAccess(0), mConverter (0) 69 : Resource( config, syncable ), mAccess(0), mConverter (0)
70{ 70{
71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
72 72
73 KConfig *cfg = (KConfig *)config; 73 KConfig *cfg = (KConfig *)config;
74 if ( cfg ) { 74 if ( cfg ) {
75 fileName = cfg->readEntry( "FileName", fileName ); 75 fileName = cfg->readEntry( "FileName", fileName );
76 76
77 } 77 }
78 78
79 init( fileName ); 79 init( fileName );
80} 80}
81 81
82ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) 82ResourceOpie::ResourceOpie( const QString &fileName, bool syncable )
83 : Resource( 0, syncable ) 83 : Resource( 0, syncable )
84{ 84{
85 init( fileName ); 85 init( fileName );
86} 86}
87 87
88void ResourceOpie::init( const QString &fileName ) 88void ResourceOpie::init( const QString &fileName )
89{ 89{
90 qDebug("ResourceOpie::init()");
90 91
91 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 92 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
92 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 93 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
93 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 94 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
94 95
95 setFileName( fileName ); 96 setFileName( fileName );
96} 97}
97 98
98ResourceOpie::~ResourceOpie() 99ResourceOpie::~ResourceOpie()
99{ 100{
100 if (mConverter != 0) 101 if (mConverter != 0)
101 delete mConverter; 102 delete mConverter;
102 103
103 if(mAccess != 0) 104 if(mAccess != 0)
104 delete mAccess; 105 delete mAccess;
105} 106}
106 107
107void ResourceOpie::writeConfig( KConfig *config ) 108void ResourceOpie::writeConfig( KConfig *config )
108{ 109{
109 Resource::writeConfig( config ); 110 Resource::writeConfig( config );
110 111
111 config->writeEntry( "FileName", fileName() ); 112 config->writeEntry( "FileName", fileName() );
112} 113}
113 114
114Ticket *ResourceOpie::requestSaveTicket() 115Ticket *ResourceOpie::requestSaveTicket()
115{ 116{
116 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; 117 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl;
117 118
118 qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); 119 qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1());
119 120
120 if ( !addressBook() ) return 0; 121 if ( !addressBook() ) return 0;
121 122
122 if ( !lock( fileName() ) ) { 123 if ( !lock( fileName() ) ) {
123 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" 124 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '"
124 << fileName() << "'" << endl; 125 << fileName() << "'" << endl;
125 return 0; 126 return 0;
126 } 127 }
127 return createTicket( this ); 128 return createTicket( this );
128} 129}
129 130
130 131
131bool ResourceOpie::doOpen() 132bool ResourceOpie::doOpen()
132{ 133{
133 qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); 134 qDebug("ResourceOpie::doOpen: %s", fileName().latin1());
134 135
135 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); 136 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() );
136 mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); 137 mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false);
137 138
138 if ( !mAccess ) { 139 if ( !mAccess ) {
139 qDebug("Unable to load file() %s", fileName().latin1()); 140 qDebug("Unable to load file() %s", fileName().latin1());
140 return false; 141 return false;
141 } 142 }
142 143
143 mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available 144 mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available
144 145
145 146
146 if (mConverter == 0) 147 if (mConverter == 0)
147 { 148 {
148 mConverter = new OpieConverter(); 149 mConverter = new OpieConverter();
149 bool res = mConverter->init(); 150 bool res = mConverter->init();
150 if ( !res ) 151 if ( !res )
151 { 152 {
152 qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); 153 qDebug("Unable to initialize opie converter. Most likely a problem with the category file");
153 delete mAccess; 154 delete mAccess;
154 mAccess = 0; 155 mAccess = 0;
155 return false; 156 return false;
156 } 157 }
157 } 158 }
158 159
159 160
160 161
161 return true; 162 return true;
162} 163}
163 164
164void ResourceOpie::doClose() 165void ResourceOpie::doClose()
165{ 166{
166 qDebug("ResourceOpie::doClose: %s", fileName().latin1()); 167 qDebug("ResourceOpie::doClose: %s", fileName().latin1());
167 168
168 if(mAccess) 169 if(mAccess)
169 { 170 {
170 delete mAccess; 171 delete mAccess;
171 mAccess = 0; 172 mAccess = 0;
172 } 173 }
173 // it seems so, that deletion of access deletes backend as well 174 // it seems so, that deletion of access deletes backend as well
174 //delete backend; 175 //delete backend;
175 176
176 return; 177 return;
177 178
178} 179}
179 180
180 181
181bool ResourceOpie::load() 182bool ResourceOpie::load()
182{ 183{
183 qDebug("ResourceOpie::load: %s", fileName().latin1()); 184 qDebug("ResourceOpie::load: %s", fileName().latin1());
184 185
185 bool res = false; 186 bool res = false;
186 187
187 OContactAccess::List::Iterator it; 188 OContactAccess::List::Iterator it;
188 OContactAccess::List allList = mAccess->allRecords(); 189 OContactAccess::List allList = mAccess->allRecords();
189 for ( it = allList.begin(); it != allList.end(); ++it ) 190 for ( it = allList.begin(); it != allList.end(); ++it )
190 { 191 {
191 const OContact c = (*it); 192 const OContact c = (*it);
192 193
193 KABC::Addressee addressee; 194 KABC::Addressee addressee;
194 195
195 res = mConverter->opieToAddressee( c, addressee ); 196 res = mConverter->opieToAddressee( c, addressee );
196 197
197 if ( !addressee.isEmpty() && res ) 198 if ( !addressee.isEmpty() && res )
198 { 199 {
199 addressee.setResource( this ); 200 addressee.setResource( this );
200 addressBook()->insertAddressee( addressee ); 201 addressBook()->insertAddressee( addressee );
201 } 202 }
202 203
203 } 204 }
204 205
205 206
206 return true; 207 return true;
207} 208}
208 209
209bool ResourceOpie::save( Ticket *ticket ) 210bool ResourceOpie::save( Ticket *ticket )
210{ 211{
211 qDebug("ResourceOpie::save: %s", fileName().latin1()); 212 qDebug("ResourceOpie::save: %s", fileName().latin1());
212 213
213 214
214 215
215 KABC::AddressBook::Iterator it; 216 KABC::AddressBook::Iterator it;
216 bool res; 217 bool res;
217 218
218 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 219 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
219 OContact c; 220 OContact c;
220 KABC::Addressee addressee = (*it); 221 KABC::Addressee addressee = (*it);
221 222
222 res = mConverter->addresseeToOpie( *it, c ); 223 res = mConverter->addresseeToOpie( *it, c );
223 if (res == true) 224 if (res == true)
224 { 225 {
225 res = mAccess->add(c); 226 res = mAccess->add(c);
226 if (res == false) 227 if (res == false)
227 qDebug("Unable to append Contact %s", c.fullName().latin1()); 228 qDebug("Unable to append Contact %s", c.fullName().latin1());
228 } 229 }
229 else 230 else
230 { 231 {
231 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 232 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
232 } 233 }
233 } 234 }
234 235
235 mAccess->save(); 236 mAccess->save();
236 237
237 delete ticket; 238 delete ticket;
238 unlock( fileName() ); 239 unlock( fileName() );
239 240
240 return true; 241 return true;
241 242
242} 243}
243 244
244bool ResourceOpie::lock( const QString &lockfileName ) 245bool ResourceOpie::lock( const QString &lockfileName )
245{ 246{
246 qDebug("ResourceOpie::lock: %s", fileName().latin1()); 247 qDebug("ResourceOpie::lock: %s", fileName().latin1());
247 248
248 kdDebug(5700) << "ResourceOpie::lock()" << endl; 249 kdDebug(5700) << "ResourceOpie::lock()" << endl;
249 250
250 QString fn = lockfileName; 251 QString fn = lockfileName;
251 252
252 KURL url(fn); 253 KURL url(fn);
253 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 254 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
254 255
255 kdDebug(5700) << "-- lock name: " << lockName << endl; 256 kdDebug(5700) << "-- lock name: " << lockName << endl;
256 257
257 if (QFile::exists( lockName )) return false; 258 if (QFile::exists( lockName ))
259 {
260 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
261 return false;
262 }
258 263
259 QString lockUniqueName; 264 QString lockUniqueName;
260 lockUniqueName = fn + KApplication::randomString( 8 ); 265 lockUniqueName = fn + KApplication::randomString( 8 );
261 266
262 url = lockUniqueName; 267 url = lockUniqueName;
263//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 268//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
264 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 269 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
265 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 270 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
266 271
267 // Create unique file 272 // Create unique file
268 QFile file( mLockUniqueName ); 273 QFile file( mLockUniqueName );
269 file.open( IO_WriteOnly ); 274 file.open( IO_WriteOnly );
270 file.close(); 275 file.close();
271 276
272 // Create lock file 277 // Create lock file
273 int result = 0; 278 int result = 0;
274#ifndef _WIN32_ 279#ifndef _WIN32_
275 result = ::link( QFile::encodeName( mLockUniqueName ), 280 result = ::link( QFile::encodeName( mLockUniqueName ),
276 QFile::encodeName( lockName ) ); 281 QFile::encodeName( lockName ) );
277#endif 282#endif
278 if ( result == 0 ) { 283 if ( result == 0 ) {
279 addressBook()->emitAddressBookLocked(); 284 addressBook()->emitAddressBookLocked();
280 return true; 285 return true;
281 } 286 }
282 287
283 // TODO: check stat 288 // TODO: check stat
284 289
285 return false; 290 return false;
286} 291}
287 292
288void ResourceOpie::unlock( const QString &fileName ) 293void ResourceOpie::unlock( const QString &fileName )
289{ 294{
290 qDebug("ResourceOpie::unlock() %s", fileName.latin1()); 295 qDebug("ResourceOpie::unlock() %s", fileName.latin1());
291 296
292 QString fn = fileName; 297 QString fn = fileName;
293 KURL url(fn); 298 KURL url(fn);
294 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 299 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
295 300
296 QFile::remove( lockName ); 301 QFile::remove( lockName );
297 QFile::remove( mLockUniqueName ); 302 QFile::remove( mLockUniqueName );
298 addressBook()->emitAddressBookUnlocked(); 303 addressBook()->emitAddressBookUnlocked();
299} 304}
300 305
301void ResourceOpie::setFileName( const QString &newFileName ) 306void ResourceOpie::setFileName( const QString &newFileName )
302{ 307{
303 mDirWatch.stopScan(); 308 mDirWatch.stopScan();
304 mDirWatch.removeFile( fileName() ); 309 mDirWatch.removeFile( fileName() );
305 310
306 Resource::setFileName( newFileName ); 311 Resource::setFileName( newFileName );
307 312
308 mDirWatch.addFile( fileName() ); 313 mDirWatch.addFile( fileName() );
309 mDirWatch.startScan(); 314 mDirWatch.startScan();
310 315
311} 316}
312 317
313 318
314void ResourceOpie::fileChanged() 319void ResourceOpie::fileChanged()
315{ 320{
316 // There is a small theoretical chance that KDirWatch calls us before 321 // There is a small theoretical chance that KDirWatch calls us before
317 // we are fully constructed 322 // we are fully constructed
318 if (!addressBook()) 323 if (!addressBook())
319 return; 324 return;
320 325
321 QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 326 QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
322 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 327 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
323 load(); 328 load();
324 addressBook()->emitAddressBookChanged(); 329 addressBook()->emitAddressBookChanged();
325 } 330 }
326 331
327 load(); 332 load();
328 addressBook()->emitAddressBookChanged(); 333 addressBook()->emitAddressBookChanged();
329} 334}
330 335
331void ResourceOpie::removeAddressee( const Addressee &addr ) 336void ResourceOpie::removeAddressee( const Addressee &addr )
332{ 337{
333} 338}
334 339
335void ResourceOpie::cleanUp() 340void ResourceOpie::cleanUp()
336{ 341{
337// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); 342// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1());
338 343
339 unlock( fileName() ); 344 unlock( fileName() );
340} 345}
341 346
342 347
343/**
344 * This method returns the number of elements that are currently in the resource.
345 */
346int ResourceOpie::count() const
347{
348 qDebug("ResourceOpie::count: %x", mAccess);
349
350 if (mAccess != 0)
351 {
352 OContactAccess::List contactList = mAccess->allRecords();
353 return contactList.count();
354 }
355 else
356 return 0;
357}
358
359
360/**
361 * This method removes all elements from the resource!! (Not from the addressbook)
362 */
363bool ResourceOpie::clear()
364{
365 if (mAccess != 0) {
366 mAccess->clear();
367 return true;
368 }
369 else
370 return false;
371}
372
373
374
375//US #include "resourceopie.moc" 348//US #include "resourceopie.moc"
diff --git a/kabc/plugins/opie/resourceopie.h b/kabc/plugins/opie/resourceopie.h
index ca30fee..d5b4ebd 100644
--- a/kabc/plugins/opie/resourceopie.h
+++ b/kabc/plugins/opie/resourceopie.h
@@ -1,156 +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, bool syncable );
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, bool syncable );
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 /**
126 * This method returns the number of elements that are currently in the resource.
127 */
128 virtual int count() const;
129
130 /**
131 * This method removes all elements from the resource!! (Not from the addressbook)
132 */
133 virtual bool clear();
134
135 125
136protected slots: 126protected slots:
137 void fileChanged(); 127 void fileChanged();
138 128
139protected: 129protected:
140 void init( const QString &fileName ); 130 void init( const QString &fileName );
141 131
142 bool lock( const QString &fileName ); 132 bool lock( const QString &fileName );
143 void unlock( const QString &fileName ); 133 void unlock( const QString &fileName );
144 134
145private: 135private:
146 OContactAccess* mAccess; 136 OContactAccess* mAccess;
147 OpieConverter* mConverter; 137 OpieConverter* mConverter;
148 138
149 QString mLockUniqueName; 139 QString mLockUniqueName;
150 140
151 KDirWatch mDirWatch; 141 KDirWatch mDirWatch;
152}; 142};
153 143
154} 144}
155 145
156#endif 146#endif
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 4a35f19..242e0c6 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -1,358 +1,319 @@
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" 52#include "syncprefwidget.h"
53 53
54#include "resourceqtopia.h" 54#include "resourceqtopia.h"
55 55
56using namespace KABC; 56using namespace KABC;
57extern "C" 57extern "C"
58{ 58{
59 void *init_microkabc_qtopia() 59 void *init_microkabc_qtopia()
60 { 60 {
61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidget>(); 61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidget>();
62 } 62 }
63} 63}
64 64
65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable )
66 : Resource( config, syncable ), mConverter (0) 66 : Resource( config, syncable ), mConverter (0)
67{ 67{
68 // we can not choose the filename. Therefore use the default to display 68 // we can not choose the filename. Therefore use the default to display
69 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 69 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
70 init( fileName ); 70 init( fileName );
71} 71}
72 72
73ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) 73ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable )
74 : Resource( 0, syncable ) 74 : Resource( 0, syncable )
75{ 75{
76 init( fileName ); 76 init( fileName );
77} 77}
78 78
79void ResourceQtopia::init( const QString &fileName ) 79void ResourceQtopia::init( const QString &fileName )
80{ 80{
81 81
82 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 82 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
83 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 83 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
84 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 84 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
85 85
86 setFileName( fileName ); 86 setFileName( fileName );
87} 87}
88 88
89ResourceQtopia::~ResourceQtopia() 89ResourceQtopia::~ResourceQtopia()
90{ 90{
91 if (mConverter != 0) 91 if (mConverter != 0)
92 delete mConverter; 92 delete mConverter;
93 93
94 if(mAccess != 0) 94 if(mAccess != 0)
95 delete mAccess; 95 delete mAccess;
96} 96}
97 97
98void ResourceQtopia::writeConfig( KConfig *config ) 98void ResourceQtopia::writeConfig( KConfig *config )
99{ 99{
100 Resource::writeConfig( config ); 100 Resource::writeConfig( config );
101} 101}
102 102
103Ticket *ResourceQtopia::requestSaveTicket() 103Ticket *ResourceQtopia::requestSaveTicket()
104{ 104{
105 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; 105 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
106 106
107 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); 107 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1());
108 108
109 if ( !addressBook() ) return 0; 109 if ( !addressBook() ) return 0;
110 110
111 if ( !lock( fileName() ) ) { 111 if ( !lock( fileName() ) ) {
112 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 112 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
113 << fileName() << "'" << endl; 113 << fileName() << "'" << endl;
114 return 0; 114 return 0;
115 } 115 }
116 return createTicket( this ); 116 return createTicket( this );
117} 117}
118 118
119 119
120bool ResourceQtopia::doOpen() 120bool ResourceQtopia::doOpen()
121{ 121{
122 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); 122 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
123 123
124 mAccess = new AddressBookAccess(); 124 mAccess = new AddressBookAccess();
125 125
126 if ( !mAccess ) { 126 if ( !mAccess ) {
127 qDebug("Unable to load file() %s", fileName().latin1()); 127 qDebug("Unable to load file() %s", fileName().latin1());
128 return false; 128 return false;
129 } 129 }
130 130
131 131
132 if (mConverter == 0) 132 if (mConverter == 0)
133 { 133 {
134 mConverter = new QtopiaConverter(); 134 mConverter = new QtopiaConverter();
135 bool res = mConverter->init(); 135 bool res = mConverter->init();
136 if ( !res ) 136 if ( !res )
137 { 137 {
138 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 138 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
139 qDebug(msg); 139 qDebug(msg);
140 delete mAccess; 140 delete mAccess;
141 mAccess = 0; 141 mAccess = 0;
142 return false; 142 return false;
143 } 143 }
144 } 144 }
145 145
146 return true; 146 return true;
147} 147}
148 148
149void ResourceQtopia::doClose() 149void ResourceQtopia::doClose()
150{ 150{
151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
152 152
153 if(mAccess) 153 if(mAccess)
154 { 154 {
155 delete mAccess; 155 delete mAccess;
156 mAccess = 0; 156 mAccess = 0;
157 } 157 }
158 // it seems so, that deletion of access deletes backend as well 158 // it seems so, that deletion of access deletes backend as well
159 //delete backend; 159 //delete backend;
160 160
161 return; 161 return;
162} 162}
163 163
164bool ResourceQtopia::load() 164bool ResourceQtopia::load()
165{ 165{
166 qDebug("ResourceQtopia::load: %s", fileName().latin1()); 166 qDebug("ResourceQtopia::load: %s", fileName().latin1());
167 167
168 AddressBookIterator it(*mAccess); 168 AddressBookIterator it(*mAccess);
169 const PimContact* contact; 169 const PimContact* contact;
170 bool res; 170 bool res;
171 171
172 for (contact=it.toFirst(); it.current(); ++it) 172 for (contact=it.toFirst(); it.current(); ++it)
173 { 173 {
174 contact = it.current(); 174 contact = it.current();
175 175
176 KABC::Addressee addressee; 176 KABC::Addressee addressee;
177 177
178 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 178 res = mConverter->qtopiaToAddressee( (*contact), addressee );
179 179
180 if ( !addressee.isEmpty() && res ) 180 if ( !addressee.isEmpty() && res )
181 { 181 {
182 addressee.setResource( this ); 182 addressee.setResource( this );
183 addressBook()->insertAddressee( addressee ); 183 addressBook()->insertAddressee( addressee );
184 } 184 }
185 } 185 }
186 186
187 return true; 187 return true;
188} 188}
189 189
190bool ResourceQtopia::save( Ticket *ticket ) 190bool ResourceQtopia::save( Ticket *ticket )
191{ 191{
192 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 192 qDebug("ResourceQtopia::save: %s", fileName().latin1());
193 193
194 194
195 KABC::AddressBook::Iterator it; 195 KABC::AddressBook::Iterator it;
196 bool res; 196 bool res;
197 197
198 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 198 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
199 PimContact c; 199 PimContact c;
200 KABC::Addressee addressee = (*it); 200 KABC::Addressee addressee = (*it);
201 201
202 res = mConverter->addresseeToQtopia( *it, c ); 202 res = mConverter->addresseeToQtopia( *it, c );
203 if (res == true) 203 if (res == true)
204 { 204 {
205 mAccess->addContact(c); 205 mAccess->addContact(c);
206// if (res == false) 206// if (res == false)
207// qDebug("Unable to append Contact %s", c.fullName().latin1()); 207// qDebug("Unable to append Contact %s", c.fullName().latin1());
208 } 208 }
209 else 209 else
210 { 210 {
211 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 211 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
212 } 212 }
213 } 213 }
214 214
215// mAccess->addressBookUpdated(); 215// mAccess->addressBookUpdated();
216 216
217 delete ticket; 217 delete ticket;
218 unlock( fileName() ); 218 unlock( fileName() );
219 219
220 return true; 220 return true;
221} 221}
222 222
223bool ResourceQtopia::lock( const QString &lockfileName ) 223bool ResourceQtopia::lock( const QString &lockfileName )
224{ 224{
225 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 225 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
226 226
227 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 227 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
228 228
229 QString fn = lockfileName; 229 QString fn = lockfileName;
230 230
231 KURL url(fn); 231 KURL url(fn);
232 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 232 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
233 233
234 kdDebug(5700) << "-- lock name: " << lockName << endl; 234 kdDebug(5700) << "-- lock name: " << lockName << endl;
235 235
236 if (QFile::exists( lockName )) return false; 236 if (QFile::exists( lockName ))
237 {
238 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
239 return false;
240 }
237 241
238 QString lockUniqueName; 242 QString lockUniqueName;
239 lockUniqueName = fn + KApplication::randomString( 8 ); 243 lockUniqueName = fn + KApplication::randomString( 8 );
240 244
241 url = lockUniqueName; 245 url = lockUniqueName;
242//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 246//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
243 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 247 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
244 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 248 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
245 249
246 // Create unique file 250 // Create unique file
247 QFile file( mLockUniqueName ); 251 QFile file( mLockUniqueName );
248 file.open( IO_WriteOnly ); 252 file.open( IO_WriteOnly );
249 file.close(); 253 file.close();
250 254
251 // Create lock file 255 // Create lock file
252 int result = 0; 256 int result = 0;
253#ifndef _WIN32_ 257#ifndef _WIN32_
254 result = ::link( QFile::encodeName( mLockUniqueName ), 258 result = ::link( QFile::encodeName( mLockUniqueName ),
255 QFile::encodeName( lockName ) ); 259 QFile::encodeName( lockName ) );
256#endif 260#endif
257 if ( result == 0 ) { 261 if ( result == 0 ) {
258 addressBook()->emitAddressBookLocked(); 262 addressBook()->emitAddressBookLocked();
259 return true; 263 return true;
260 } 264 }
261 265
262 // TODO: check stat 266 // TODO: check stat
263 267
264 return false; 268 return false;
265} 269}
266 270
267void ResourceQtopia::unlock( const QString &fileName ) 271void ResourceQtopia::unlock( const QString &fileName )
268{ 272{
269 qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); 273 qDebug("ResourceQtopia::unlock() %s", fileName.latin1());
270 274
271 QString fn = fileName; 275 QString fn = fileName;
272 KURL url(fn); 276 KURL url(fn);
273 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 277 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
274 278
275 QFile::remove( lockName ); 279 QFile::remove( lockName );
276 QFile::remove( mLockUniqueName ); 280 QFile::remove( mLockUniqueName );
277 addressBook()->emitAddressBookUnlocked(); 281 addressBook()->emitAddressBookUnlocked();
278} 282}
279 283
280void ResourceQtopia::setFileName( const QString &newFileName ) 284void ResourceQtopia::setFileName( const QString &newFileName )
281{ 285{
282 mDirWatch.stopScan(); 286 mDirWatch.stopScan();
283 mDirWatch.removeFile( fileName() ); 287 mDirWatch.removeFile( fileName() );
284 288
285 Resource::setFileName( newFileName ); 289 Resource::setFileName( newFileName );
286 290
287 mDirWatch.addFile( fileName() ); 291 mDirWatch.addFile( fileName() );
288 mDirWatch.startScan(); 292 mDirWatch.startScan();
289} 293}
290 294
291 295
292void ResourceQtopia::fileChanged() 296void ResourceQtopia::fileChanged()
293{ 297{
294 // There is a small theoretical chance that KDirWatch calls us before 298 // There is a small theoretical chance that KDirWatch calls us before
295 // we are fully constructed 299 // we are fully constructed
296 if (!addressBook()) 300 if (!addressBook())
297 return; 301 return;
298 302
299 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 303 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
300 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 304 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
301 load(); 305 load();
302 addressBook()->emitAddressBookChanged(); 306 addressBook()->emitAddressBookChanged();
303 } 307 }
304} 308}
305 309
306void ResourceQtopia::removeAddressee( const Addressee &addr ) 310void ResourceQtopia::removeAddressee( const Addressee &addr )
307{ 311{
308} 312}
309 313
310void ResourceQtopia::cleanUp() 314void ResourceQtopia::cleanUp()
311{ 315{
312 unlock( fileName() ); 316 unlock( fileName() );
313} 317}
314 318
315
316
317/**
318 * This method returns the number of elements that are currently in the resource.
319 */
320int ResourceQtopia::count() const
321{
322 if (mAccess != 0)
323 {
324 int counter = 0;
325 AddressBookIterator it2(*mAccess);
326 for (it2.toFirst(); it2.current(); ++it2) {
327 counter++;
328 }
329
330 return counter;
331 }
332 else
333 return 0;
334}
335
336
337/**
338 * This method removes all elements from the resource!! (Not from the addressbook)
339 */
340bool ResourceQtopia::clear()
341{
342 if (mAccess != 0)
343 {
344 AddressBookIterator it2(*mAccess);
345 for (it2.toFirst(); it2.current(); ++it2) {
346 mAccess->removeContact(*it2.current());
347 }
348 return true;
349 }
350 else
351 return false;
352}
353
354
355
356
357
358//US #include "resourceqtopia.moc" 319//US #include "resourceqtopia.moc"
diff --git a/kabc/plugins/qtopia/resourceqtopia.h b/kabc/plugins/qtopia/resourceqtopia.h
index 90ab1f4..eace280 100644
--- a/kabc/plugins/qtopia/resourceqtopia.h
+++ b/kabc/plugins/qtopia/resourceqtopia.h
@@ -1,155 +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, bool syncable );
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, bool syncable );
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
125 /**
126 * This method returns the number of elements that are currently in the resource.
127 */
128 virtual int count() const;
129
130 /**
131 * This method removes all elements from the resource!! (Not from the addressbook)
132 */
133 virtual bool clear();
134
135protected slots: 125protected slots:
136 void fileChanged(); 126 void fileChanged();
137 127
138protected: 128protected:
139 void init( const QString &fileName ); 129 void init( const QString &fileName );
140 130
141 bool lock( const QString &fileName ); 131 bool lock( const QString &fileName );
142 void unlock( const QString &fileName ); 132 void unlock( const QString &fileName );
143 133
144private: 134private:
145 AddressBookAccess* mAccess; 135 AddressBookAccess* mAccess;
146 QtopiaConverter* mConverter; 136 QtopiaConverter* mConverter;
147 137
148 QString mLockUniqueName; 138 QString mLockUniqueName;
149 139
150 KDirWatch mDirWatch; 140 KDirWatch mDirWatch;
151}; 141};
152 142
153} 143}
154 144
155#endif 145#endif
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 14f272d..70c3718 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,355 +1,337 @@
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 48
49#include "resourcesharpdtmconfig.h" 49#include "resourcesharpdtmconfig.h"
50#include "resourcesharpdtm.h" 50#include "resourcesharpdtm.h"
51 51
52#include "syncprefwidget.h" 52#include "syncprefwidget.h"
53 53
54#include "stdaddressbook.h" 54#include "stdaddressbook.h"
55 55
56#include "sharpdtmconverter.h" 56#include "sharpdtmconverter.h"
57 57
58using namespace KABC; 58using namespace KABC;
59extern "C" 59extern "C"
60{ 60{
61 void *init_microkabc_sharpdtm() 61 void *init_microkabc_sharpdtm()
62 { 62 {
63 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidget>(); 63 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidget>();
64 } 64 }
65} 65}
66 66
67ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) 67ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable )
68 : Resource( config, syncable ), mConverter (0) 68 : Resource( config, syncable ), mConverter (0)
69{ 69{
70 // we can not choose the filename. Therefore use the default to display 70 // we can not choose the filename. Therefore use the default to display
71 71
72 QString fileName = SlZDataBase::addressbookFileName(); 72 QString fileName = SlZDataBase::addressbookFileName();
73 init( fileName ); 73 init( fileName );
74} 74}
75 75
76ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) 76ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable )
77 : Resource( 0, syncable ) 77 : Resource( 0, syncable )
78{ 78{
79 init( fileName ); 79 init( fileName );
80} 80}
81 81
82void ResourceSharpDTM::init( const QString &fileName ) 82void ResourceSharpDTM::init( const QString &fileName )
83{ 83{
84 84
85 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 85 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
86 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
87 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 87 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
88 88
89 setFileName( fileName ); 89 setFileName( fileName );
90} 90}
91 91
92ResourceSharpDTM::~ResourceSharpDTM() 92ResourceSharpDTM::~ResourceSharpDTM()
93{ 93{
94 if (mConverter != 0) 94 if (mConverter != 0)
95 delete mConverter; 95 delete mConverter;
96 96
97 if(mAccess != 0) 97 if(mAccess != 0)
98 delete mAccess; 98 delete mAccess;
99} 99}
100 100
101void ResourceSharpDTM::writeConfig( KConfig *config ) 101void ResourceSharpDTM::writeConfig( KConfig *config )
102{ 102{
103 Resource::writeConfig( config ); 103 Resource::writeConfig( config );
104} 104}
105 105
106Ticket *ResourceSharpDTM::requestSaveTicket() 106Ticket *ResourceSharpDTM::requestSaveTicket()
107{ 107{
108 kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl; 108 kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl;
109 109
110 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 110 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
111 111
112 if ( !addressBook() ) return 0; 112 if ( !addressBook() ) return 0;
113 113
114 if ( !lock( fileName() ) ) { 114 if ( !lock( fileName() ) ) {
115 kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '" 115 kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '"
116 << fileName() << "'" << endl; 116 << fileName() << "'" << endl;
117 return 0; 117 return 0;
118 } 118 }
119 return createTicket( this ); 119 return createTicket( this );
120} 120}
121 121
122 122
123bool ResourceSharpDTM::doOpen() 123bool ResourceSharpDTM::doOpen()
124{ 124{
125 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); 125 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1());
126 126
127 // the last parameter in the SlZDataBase constructor means "readonly" 127 // the last parameter in the SlZDataBase constructor means "readonly"
128 mAccess = new SlZDataBase(fileName(), 128 mAccess = new SlZDataBase(fileName(),
129 SlZDataBase::addressbookItems(), 129 SlZDataBase::addressbookItems(),
130 NULL, true); 130 NULL, true);
131 131
132 if ( !mAccess ) { 132 if ( !mAccess ) {
133 qDebug("Unable to load file() %s", fileName().latin1()); 133 qDebug("Unable to load file() %s", fileName().latin1());
134 return false; 134 return false;
135 } 135 }
136 136
137 if (mConverter == 0) 137 if (mConverter == 0)
138 { 138 {
139 mConverter = new SharpDTMConverter(); 139 mConverter = new SharpDTMConverter();
140 bool res = mConverter->init(); 140 bool res = mConverter->init();
141 if ( !res ) 141 if ( !res )
142 { 142 {
143 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");
144 144
145 qDebug(msg); 145 qDebug(msg);
146 delete mAccess; 146 delete mAccess;
147 mAccess = 0; 147 mAccess = 0;
148 return false; 148 return false;
149 } 149 }
150 } 150 }
151 151
152 return true; 152 return true;
153} 153}
154 154
155void ResourceSharpDTM::doClose() 155void ResourceSharpDTM::doClose()
156{ 156{
157 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); 157 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
158 158
159 if(mAccess) 159 if(mAccess)
160 { 160 {
161 delete mAccess; 161 delete mAccess;
162 mAccess = 0; 162 mAccess = 0;
163 } 163 }
164 // it seems so, that deletion of access deletes backend as well 164 // it seems so, that deletion of access deletes backend as well
165 //delete backend; 165 //delete backend;
166 166
167 return; 167 return;
168} 168}
169 169
170bool ResourceSharpDTM::load() 170bool ResourceSharpDTM::load()
171{ 171{
172 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 172 qDebug("ResourceSharpDTM::load: %s", fileName().latin1());
173 173
174 bool res = false; 174 bool res = false;
175 175
176 CardId id; 176 CardId id;
177 177
178 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 178 for (bool res=mAccess->first(); res == true; res=mAccess->next())
179 { 179 {
180 id = mAccess->cardId(); 180 id = mAccess->cardId();
181 181
182 KABC::Addressee addressee; 182 KABC::Addressee addressee;
183 183
184 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 184 res = mConverter->sharpToAddressee( id, mAccess, addressee );
185 185
186 if ( !addressee.isEmpty() && res ) 186 if ( !addressee.isEmpty() && res )
187 { 187 {
188 addressee.setResource( this ); 188 addressee.setResource( this );
189 addressBook()->insertAddressee( addressee ); 189 addressBook()->insertAddressee( addressee );
190 } 190 }
191 } 191 }
192 192
193 return true; 193 return true;
194} 194}
195 195
196bool ResourceSharpDTM::save( Ticket *ticket ) 196bool ResourceSharpDTM::save( Ticket *ticket )
197{ 197{
198 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 198 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
199 199
200 200
201 KABC::AddressBook::Iterator it; 201 KABC::AddressBook::Iterator it;
202 bool res; 202 bool res;
203 203
204 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 204 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
205 CardId id = 0;// 0 means new card 205 CardId id = 0;// 0 means new card
206 KABC::Addressee addressee = (*it); 206 KABC::Addressee addressee = (*it);
207 207
208 res = mAccess->startEditCard(id); 208 res = mAccess->startEditCard(id);
209 if (res == true) 209 if (res == true)
210 { 210 {
211 res = mConverter->addresseeToSharp( *it, mAccess, id ); 211 res = mConverter->addresseeToSharp( *it, mAccess, id );
212 if (res == true) 212 if (res == true)
213 { 213 {
214 res = mAccess->finishEditCard(&id); 214 res = mAccess->finishEditCard(&id);
215 if (res == false) 215 if (res == false)
216 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 216 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
217 } 217 }
218 else 218 else
219 { 219 {
220 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 220 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
221 mAccess->cancelEditCard(); 221 mAccess->cancelEditCard();
222 } 222 }
223 } 223 }
224 else 224 else
225 { 225 {
226 qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); 226 qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1());
227 } 227 }
228 228
229 } 229 }
230 230
231//US mAccess->save(); 231//US mAccess->save();
232 232
233 delete ticket; 233 delete ticket;
234 unlock( fileName() ); 234 unlock( fileName() );
235 235
236 return true; 236 return true;
237} 237}
238 238
239bool ResourceSharpDTM::lock( const QString &lockfileName ) 239bool ResourceSharpDTM::lock( const QString &lockfileName )
240{ 240{
241 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); 241 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
242 242
243 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; 243 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
244 244
245 QString fn = lockfileName; 245 QString fn = lockfileName;
246 246
247 KURL url(fn); 247 KURL url(fn);
248 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 248 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
249 249
250 kdDebug(5700) << "-- lock name: " << lockName << endl; 250 kdDebug(5700) << "-- lock name: " << lockName << endl;
251 251
252 if (QFile::exists( lockName )) return false; 252 if (QFile::exists( lockName ))
253 {
254 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
255 return false;
256 }
257
253 258
254 QString lockUniqueName; 259 QString lockUniqueName;
255 lockUniqueName = fn + KApplication::randomString( 8 ); 260 lockUniqueName = fn + KApplication::randomString( 8 );
256 261
257 url = lockUniqueName; 262 url = lockUniqueName;
258//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 263//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
259 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 264 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
260 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 265 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
261 266
262 // Create unique file 267 // Create unique file
263 QFile file( mLockUniqueName ); 268 QFile file( mLockUniqueName );
264 file.open( IO_WriteOnly ); 269 file.open( IO_WriteOnly );
265 file.close(); 270 file.close();
266 271
267 // Create lock file 272 // Create lock file
268 int result = 0; 273 int result = 0;
269#ifndef _WIN32_ 274#ifndef _WIN32_
270 result = ::link( QFile::encodeName( mLockUniqueName ), 275 result = ::link( QFile::encodeName( mLockUniqueName ),
271 QFile::encodeName( lockName ) ); 276 QFile::encodeName( lockName ) );
272#endif 277#endif
273 if ( result == 0 ) { 278 if ( result == 0 ) {
274 addressBook()->emitAddressBookLocked(); 279 addressBook()->emitAddressBookLocked();
275 return true; 280 return true;
276 } 281 }
277 282
278 // TODO: check stat 283 // TODO: check stat
279 284
280 return false; 285 return false;
281} 286}
282 287
283void ResourceSharpDTM::unlock( const QString &fileName ) 288void ResourceSharpDTM::unlock( const QString &fileName )
284{ 289{
285 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); 290 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
286 291
287 QString fn = fileName; 292 QString fn = fileName;
288 KURL url(fn); 293 KURL url(fn);
289 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 294 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
290 295
291 QFile::remove( lockName ); 296 QFile::remove( lockName );
292 QFile::remove( mLockUniqueName ); 297 QFile::remove( mLockUniqueName );
293 addressBook()->emitAddressBookUnlocked(); 298 addressBook()->emitAddressBookUnlocked();
294} 299}
295 300
296void ResourceSharpDTM::setFileName( const QString &newFileName ) 301void ResourceSharpDTM::setFileName( const QString &newFileName )
297{ 302{
298 mDirWatch.stopScan(); 303 mDirWatch.stopScan();
299 mDirWatch.removeFile( fileName() ); 304 mDirWatch.removeFile( fileName() );
300 305
301 Resource::setFileName( newFileName ); 306 Resource::setFileName( newFileName );
302 307
303 mDirWatch.addFile( fileName() ); 308 mDirWatch.addFile( fileName() );
304 mDirWatch.startScan(); 309 mDirWatch.startScan();
305 310
306} 311}
307 312
308void ResourceSharpDTM::fileChanged() 313void ResourceSharpDTM::fileChanged()
309{ 314{
310 // There is a small theoretical chance that KDirWatch calls us before 315 // There is a small theoretical chance that KDirWatch calls us before
311 // we are fully constructed 316 // we are fully constructed
312 if (!addressBook()) 317 if (!addressBook())
313 return; 318 return;
314 319
315 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 320 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
316 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 321 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
317 load(); 322 load();
318 addressBook()->emitAddressBookChanged(); 323 addressBook()->emitAddressBookChanged();
319 } 324 }
320} 325}
321 326
322void ResourceSharpDTM::removeAddressee( const Addressee &addr ) 327void ResourceSharpDTM::removeAddressee( const Addressee &addr )
323{ 328{
324} 329}
325 330
326void ResourceSharpDTM::cleanUp() 331void ResourceSharpDTM::cleanUp()
327{ 332{
328 unlock( fileName() ); 333 unlock( fileName() );
329} 334}
330 335
331/**
332 * This method returns the number of elements that are currently in the resource.
333 */
334int ResourceSharpDTM::count() const
335{
336 if (mAccess != 0)
337 return mAccess->count();
338 else
339 return 0;
340}
341
342
343/**
344 * This method removes all elements from the resource!! (Not from the addressbook)
345 */
346bool ResourceSharpDTM::clear()
347{
348 if (mAccess != 0)
349 return mAccess->deleteCard(0, SlZDataBase::AllCard );
350 else
351 return false;
352}
353
354 336
355 337
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.h b/kabc/plugins/sharpdtm/resourcesharpdtm.h
index 60d38a1..f386e69 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.h
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.h
@@ -1,156 +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, bool syncable );
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, bool syncable );
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 /**
126 * This method returns the number of elements that are currently in the resource.
127 */
128 virtual int count() const;
129
130 /**
131 * This method removes all elements from the resource!! (Not from the addressbook)
132 */
133 virtual bool clear();
134
135 125
136protected slots: 126protected slots:
137 void fileChanged(); 127 void fileChanged();
138 128
139protected: 129protected:
140 void init( const QString &fileName ); 130 void init( const QString &fileName );
141 131
142 bool lock( const QString &fileName ); 132 bool lock( const QString &fileName );
143 void unlock( const QString &fileName ); 133 void unlock( const QString &fileName );
144 134
145private: 135private:
146 SlZDataBase* mAccess; 136 SlZDataBase* mAccess;
147 SharpDTMConverter* mConverter; 137 SharpDTMConverter* mConverter;
148 138
149 QString mLockUniqueName; 139 QString mLockUniqueName;
150 140
151 KDirWatch mDirWatch; 141 KDirWatch mDirWatch;
152}; 142};
153 143
154} 144}
155 145
156#endif 146#endif
diff --git a/kabc/resource.cpp b/kabc/resource.cpp
index 9632a3f..2f03927 100644
--- a/kabc/resource.cpp
+++ b/kabc/resource.cpp
@@ -1,154 +1,139 @@
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> 30#include <ksyncprofile.h>
31 31
32#include "resource.h" 32#include "resource.h"
33 33
34using namespace KABC; 34using namespace KABC;
35 35
36Resource::Resource( const KConfig *config, bool syncable ) 36Resource::Resource( const KConfig *config, bool syncable )
37 : KRES::Resource( config ), mAddressBook( 0 ), mSyncProfile( 0 ) 37 : KRES::Resource( config ), mAddressBook( 0 ), mSyncProfile( 0 )
38{ 38{
39 if(syncable == true) { 39 if(syncable == true) {
40 mSyncProfile = new KSyncProfile( identifier() ); 40 mSyncProfile = new KSyncProfile( identifier() );
41 mSyncProfile->setName(resourceName()); 41 mSyncProfile->setName(resourceName());
42 mSyncProfile->readConfig( (KConfig *)config ); 42 mSyncProfile->readConfig( (KConfig *)config );
43 } 43 }
44} 44}
45 45
46Resource::~Resource() 46Resource::~Resource()
47{ 47{
48 if (mSyncProfile != 0) { 48 if (mSyncProfile != 0) {
49 delete mSyncProfile; 49 delete mSyncProfile;
50 } 50 }
51} 51}
52 52
53void Resource::writeConfig( KConfig *config ) 53void Resource::writeConfig( KConfig *config )
54{ 54{
55 KRES::Resource::writeConfig( config ); 55 KRES::Resource::writeConfig( config );
56 56
57 if(mSyncProfile != 0) 57 if(mSyncProfile != 0)
58 mSyncProfile->writeConfig( config ); 58 mSyncProfile->writeConfig( config );
59} 59}
60 60
61 61
62void Resource::setAddressBook( AddressBook *ab ) 62void Resource::setAddressBook( AddressBook *ab )
63{ 63{
64 mAddressBook = ab; 64 mAddressBook = ab;
65} 65}
66 66
67AddressBook *Resource::addressBook() 67AddressBook *Resource::addressBook()
68{ 68{
69 return mAddressBook; 69 return mAddressBook;
70} 70}
71 71
72bool Resource::doOpen() 72bool Resource::doOpen()
73{ 73{
74 return true; 74 return true;
75} 75}
76 76
77void Resource::doClose() 77void Resource::doClose()
78{ 78{
79} 79}
80 80
81Ticket *Resource::requestSaveTicket() 81Ticket *Resource::requestSaveTicket()
82{ 82{
83 return 0; 83 return 0;
84} 84}
85 85
86bool Resource::load() 86bool Resource::load()
87{ 87{
88 return true; 88 return true;
89} 89}
90 90
91bool Resource::save( Ticket * ) 91bool Resource::save( Ticket * )
92{ 92{
93 return false; 93 return false;
94} 94}
95 95
96Ticket *Resource::createTicket( Resource *resource ) 96Ticket *Resource::createTicket( Resource *resource )
97{ 97{
98 return new Ticket( resource ); 98 return new Ticket( resource );
99} 99}
100 100
101void Resource::removeAddressee( const Addressee& ) 101void Resource::removeAddressee( const Addressee& )
102{ 102{
103 // do nothing 103 // do nothing
104} 104}
105 105
106void Resource::cleanUp() 106void Resource::cleanUp()
107{ 107{
108 // do nothing 108 // do nothing
109} 109}
110 110
111bool Resource::isSyncable() const 111bool Resource::isSyncable() const
112{ 112{
113 return (mSyncProfile != 0); 113 return (mSyncProfile != 0);
114} 114}
115 115
116/**
117 * This method returns the number of elements that are currently in the resource.
118 */
119int Resource::count() const
120{
121 return 0;
122}
123
124/**
125 * This method removes all elements from the resource!! (Not from the addressbook)
126 */
127bool Resource::clear()
128{
129 return false;
130}
131 116
132QString Resource::fileName() const 117QString Resource::fileName() const
133{ 118{
134 return mFileName; 119 return mFileName;
135} 120}
136 121
137void Resource::setFileName( const QString &fileName ) 122void Resource::setFileName( const QString &fileName )
138{ 123{
139 mFileName = fileName; 124 mFileName = fileName;
140} 125}
141 126
142/** 127/**
143 * Set the name of resource.You can override this method, 128 * Set the name of resource.You can override this method,
144 * but also remember to call Resource::setResourceName(). 129 * but also remember to call Resource::setResourceName().
145 */ 130 */
146void Resource::setResourceName( const QString &name ) 131void Resource::setResourceName( const QString &name )
147{ 132{
148 KRES::Resource::setResourceName(name); 133 KRES::Resource::setResourceName(name);
149 if(mSyncProfile != 0) { 134 if(mSyncProfile != 0) {
150 mSyncProfile->setName( name ); 135 mSyncProfile->setName( name );
151 } 136 }
152 137
153} 138}
154 139
diff --git a/kabc/resource.h b/kabc/resource.h
index db806a6..7d42f81 100644
--- a/kabc/resource.h
+++ b/kabc/resource.h
@@ -1,180 +1,169 @@
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; 36class KSyncProfile;
37 37
38namespace KABC { 38namespace KABC {
39 39
40/** 40/**
41 * @short Helper class for handling coordinated save of address books. 41 * @short Helper class for handling coordinated save of address books.
42 * 42 *
43 * This class is used as helper class for saving address book. 43 * This class is used as helper class for saving address book.
44 * @see requestSaveTicket(), save(). 44 * @see requestSaveTicket(), save().
45 */ 45 */
46class Ticket 46class Ticket
47{ 47{
48 friend class Resource; 48 friend class Resource;
49 public: 49 public:
50 Resource *resource() { return mResource; } 50 Resource *resource() { return mResource; }
51 51
52 private: 52 private:
53 Ticket( Resource *resource ) : mResource( resource ) {} 53 Ticket( Resource *resource ) : mResource( resource ) {}
54 54
55 Resource *mResource; 55 Resource *mResource;
56}; 56};
57 57
58/** 58/**
59 * @internal 59 * @internal
60 */ 60 */
61class Resource : public KRES::Resource 61class Resource : public KRES::Resource
62{ 62{
63private: 63private:
64 /** 64 /**
65 * make this constructor private to force everybody to use the other one 65 * make this constructor private to force everybody to use the other one
66 */ 66 */
67 Resource( const KConfig *config); 67 Resource( const KConfig *config);
68 68
69public: 69public:
70 /** 70 /**
71 * Constructor 71 * Constructor
72 */ 72 */
73 Resource( const KConfig *config, bool syncable ); 73 Resource( const KConfig *config, bool syncable );
74 74
75 /** 75 /**
76 * Destructor. 76 * Destructor.
77 */ 77 */
78 virtual ~Resource(); 78 virtual ~Resource();
79 79
80 /** 80 /**
81 * Sets the address book of the resource. 81 * Sets the address book of the resource.
82 */ 82 */
83 void setAddressBook( AddressBook* ); 83 void setAddressBook( AddressBook* );
84 84
85 /** 85 /**
86 * Returns a pointer to the addressbook. 86 * Returns a pointer to the addressbook.
87 */ 87 */
88 AddressBook *addressBook(); 88 AddressBook *addressBook();
89 89
90 /** 90 /**
91 * Writes the resource specific config to file. 91 * Writes the resource specific config to file.
92 */ 92 */
93 virtual void writeConfig( KConfig *config ); 93 virtual void writeConfig( KConfig *config );
94 94
95 /** 95 /**
96 * Open the resource and returns if it was successfully 96 * Open the resource and returns if it was successfully
97 */ 97 */
98 virtual bool doOpen(); 98 virtual bool doOpen();
99 99
100 100
101 /** 101 /**
102 * Request a ticket, you have to pass through @ref save() to 102 * Request a ticket, you have to pass through @ref save() to
103 * allow locking. 103 * allow locking.
104 */ 104 */
105 virtual Ticket *requestSaveTicket(); 105 virtual Ticket *requestSaveTicket();
106 106
107 /** 107 /**
108 * Load all addressees to the addressbook 108 * Load all addressees to the addressbook
109 */ 109 */
110 virtual bool load(); 110 virtual bool load();
111 111
112 /** 112 /**
113 * Save all addressees to the addressbook. 113 * Save all addressees to the addressbook.
114 * 114 *
115 * @param ticket The ticket you get by @ref requestSaveTicket() 115 * @param ticket The ticket you get by @ref requestSaveTicket()
116 */ 116 */
117 virtual bool save( Ticket *ticket ); 117 virtual bool save( Ticket *ticket );
118 118
119 /** 119 /**
120 * Removes a addressee from resource. This method is mainly 120 * Removes a addressee from resource. This method is mainly
121 * used by record-based resources like LDAP or SQL. 121 * used by record-based resources like LDAP or SQL.
122 */ 122 */
123 virtual void removeAddressee( const Addressee& addr ); 123 virtual void removeAddressee( const Addressee& addr );
124 124
125 125
126 /** 126 /**
127 * This method is called by an error handler if the application 127 * This method is called by an error handler if the application
128 * crashed 128 * crashed
129 */ 129 */
130 virtual void cleanUp(); 130 virtual void cleanUp();
131 131
132
133 /**
134 * This method returns the number of elements that are currently in the resource.
135 */
136 virtual int count() const;
137
138 /**
139 * This method removes all elements from the resource!! (Not from the addressbook)
140 */
141 virtual bool clear();
142
143 /** 132 /**
144 * Set name of file to be used for saving. 133 * Set name of file to be used for saving.
145 */ 134 */
146 virtual void setFileName( const QString & ); 135 virtual void setFileName( const QString & );
147 136
148 /** 137 /**
149 * Return name of file used for loading and saving the address book. 138 * Return name of file used for loading and saving the address book.
150 */ 139 */
151 virtual QString fileName() const; 140 virtual QString fileName() const;
152 141
153 142
154 virtual bool isSyncable() const; 143 virtual bool isSyncable() const;
155 144
156 /** 145 /**
157 * Set the name of resource.You can override this method, 146 * Set the name of resource.You can override this method,
158 * but also remember to call Resource::setResourceName(). 147 * but also remember to call Resource::setResourceName().
159 */ 148 */
160 virtual void setResourceName( const QString &name ); 149 virtual void setResourceName( const QString &name );
161 150
162 151
163 152
164protected: 153protected:
165 Ticket *createTicket( Resource * ); 154 Ticket *createTicket( Resource * );
166 virtual void doClose(); 155 virtual void doClose();
167 156
168private: 157private:
169 AddressBook *mAddressBook; 158 AddressBook *mAddressBook;
170 KSyncProfile *mSyncProfile; 159 KSyncProfile *mSyncProfile;
171 QString mFileName; 160 QString mFileName;
172 161
173}; 162};
174 163
175 164
176} 165}
177 166
178 167
179 168
180#endif 169#endif
diff --git a/kabc/tmpaddressbook.cpp b/kabc/tmpaddressbook.cpp
index e6699df..ca47ca4 100644
--- a/kabc/tmpaddressbook.cpp
+++ b/kabc/tmpaddressbook.cpp
@@ -1,44 +1,56 @@
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#include <qptrlist.h>
27 28
28#include "tmpaddressbook.h" 29#include "tmpaddressbook.h"
29 30
30using namespace KABC; 31using namespace KABC;
31 32
33#include "resource.h"
34
32TmpAddressBook::TmpAddressBook() 35TmpAddressBook::TmpAddressBook()
33 : AddressBook(0, "tmpcontact") 36 : AddressBook(0, "tmpcontact")
34{ 37{
35} 38}
36 39
37TmpAddressBook::TmpAddressBook( const QString &config ) 40TmpAddressBook::TmpAddressBook( const QString &config )
38 : AddressBook( config, "tmpcontact" ) 41 : AddressBook( config, "tmpcontract" )
39{ 42{
40} 43}
41 44
42TmpAddressBook::~TmpAddressBook() 45TmpAddressBook::~TmpAddressBook()
43{ 46{
47 //remove all possible resources. This should cleanup the configfile.
48 QPtrList<KABC::Resource> mResources = resources();
49
50 QPtrListIterator<KABC::Resource> it(mResources);
51 for ( ; it.current(); ++it ) {
52 KABC::Resource *res = it.current();
53 removeResource(res);
54 }
44} 55}
56
diff --git a/kaddressbook/xxport/opie_xxport.cpp b/kaddressbook/xxport/opie_xxport.cpp
index 192b803..7b29b0a 100644
--- a/kaddressbook/xxport/opie_xxport.cpp
+++ b/kaddressbook/xxport/opie_xxport.cpp
@@ -1,195 +1,91 @@
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 <qdir.h> 31#include <qdir.h>
32 32
33#include <kfiledialog.h> 33#include <kfiledialog.h>
34#include <kmessagebox.h>
35
36//US #include <opie/ocontactaccess.h>
37//US #include <opie/ocontactaccessbackend_xml.h>
38
39//US #include "stdaddressbook.h"
40#include "resource.h"
41#include "tmpaddressbook.h"
42
43/*US
44#include <qfile.h>
45#include <qtextstream.h>
46
47#include <kabc/vcardconverter.h>
48#ifndef KAB_EMBEDDED
49#include <kio/netaccess.h>
50#endif //KAB_EMBEDDED
51
52#include <klocale.h>
53#include <kmessagebox.h>
54#include <ktempfile.h>
55#include <kurl.h>
56*/
57
58#include <factory.h>
59
60 34
35#include "addressee.h"
61#include "xxportmanager.h" 36#include "xxportmanager.h"
62
63#include "opie_xxport.h" 37#include "opie_xxport.h"
64 38
65/*US 39/*US
66class OpieXXPortFactory : public XXPortFactory 40class OpieXXPortFactory : public XXPortFactory
67{ 41{
68 public: 42 public:
69 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 43 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
70 { 44 {
71 return new OpieXXPort( ab, parent, name ); 45 return new OpieXXPort( ab, parent, name );
72 } 46 }
73}; 47};
74*/ 48*/
75 49
76 50
77extern "C" 51extern "C"
78{ 52{
79 void *init_microkaddrbk_opie_xxport() 53 void *init_microkaddrbk_opie_xxport()
80 { 54 {
81 return ( new OpieXXPortFactory() ); 55 return ( new OpieXXPortFactory() );
82 } 56 }
83} 57}
84 58
85 59
86OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 60OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
87 : XXPortResourceObject( ab, parent, name ) 61 : XXPortResourceObject( ab, parent, name )
88{ 62{
89 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 63 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
90 64
91 KRES::Factory* mFactory = KRES::Factory::self( "contact" ); 65 if ( mFactory && !mFactory->typeName( "opie" ).isEmpty() )
92
93 if ( mFactory )
94 { 66 {
95 mResource = (KABC::Resource*)(mFactory->resource( "opie", 0, false )); 67 createImportAction( i18n( "Import Opie..." ) );
96 68 createExportAction( i18n( "Export Opie..." ) );
97 if ( mResource )
98 {
99 createImportAction( i18n( "Import Opie..." ) );
100 createExportAction( i18n( "Export Opie..." ) );
101 }
102 } 69 }
103} 70}
104 71
105bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 72bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier )
106{ 73{
107 if (mResource == 0)
108 return false;
109
110 QString fileName = KFileDialog::getSaveFileName( defaultFileName, i18n("Save file"), parentWidget() ); 74 QString fileName = KFileDialog::getSaveFileName( defaultFileName, i18n("Save file"), parentWidget() );
111 75
112 if ( fileName.isEmpty() ) 76 if ( fileName.isEmpty() )
113 return false; 77 return false;
114 78
115 mResource->setFileName( fileName ); 79 return _exportContacts( list, identifier, fileName );
116
117
118 KABC::TmpAddressBook tmpAB;
119
120 tmpAB.addResource( mResource );
121
122 qDebug("11111");
123
124 //Now check if the file has already entries, and ask the user if he wants to delete them first.
125 KABC::AddressBook::Iterator it2 = tmpAB.begin();
126 for ( it2 = tmpAB.begin(); it2 != tmpAB.end(); ++it2 ) {
127 KABC::Addressee addressee = (*it2);
128 qDebug("found %s", addressee.formattedName().latin1());
129 }
130
131 if (it2 != tmpAB.end())
132 {
133 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
134 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
135 // Clean the database..
136 tmpAB.clear();
137 }
138 }
139 qDebug("22222");
140
141//US debug
142 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
143 QPtrListIterator<KABC::Resource> resIt( kabcResources );
144 KABC::Resource *resource;
145 while ( ( resource = resIt.current() ) != 0 ) {
146 ++resIt;
147 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
148 }
149
150
151 KABC::Addressee::List::ConstIterator it;
152 for ( it = list.begin(); it != list.end(); ++it ) {
153 tmpAB.insertAddressee(*it);
154 }
155
156 bool res = false;
157 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
158
159 if (ticket != 0)
160 res = tmpAB.save( ticket );
161
162 tmpAB.removeResource( mResource );
163
164 return res;
165} 80}
166 81
167 82
168KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const 83KABC::AddresseeList OpieXXPort::importContacts( const QString &identifier ) const
169{ 84{
170 if (mResource == 0)
171 return KABC::AddresseeList();
172
173 KABC::AddresseeList adrlst;
174
175 QString fileName = KFileDialog::getOpenFileName( defaultFileName, i18n("Load file"), parentWidget() ); 85 QString fileName = KFileDialog::getOpenFileName( defaultFileName, i18n("Load file"), parentWidget() );
176 86
177 if ( fileName.isEmpty() ) 87 if ( fileName.isEmpty() )
178 return KABC::AddresseeList(); 88 return KABC::AddresseeList();
179 89
180 mResource->setFileName( fileName ); 90 return _importContacts( identifier, fileName );
181
182
183 KABC::TmpAddressBook tmpAB;
184
185 tmpAB.addResource( mResource );
186
187 bool res = tmpAB.load();
188
189 adrlst = tmpAB.allAddressees();
190
191 tmpAB.removeResource( mResource );
192
193 return adrlst;
194
195} 91}
diff --git a/kaddressbook/xxport/opie_xxport.h b/kaddressbook/xxport/opie_xxport.h
index 106f38b..d2b55cd 100644
--- a/kaddressbook/xxport/opie_xxport.h
+++ b/kaddressbook/xxport/opie_xxport.h
@@ -1,68 +1,68 @@
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#ifndef OPIE_XXPORT_H 31#ifndef OPIE_XXPORT_H
32#define OPIE_XXPORT_H 32#define OPIE_XXPORT_H
33 33
34#include <xxportobject.h> 34#include <xxportobject.h>
35 35
36 36
37class KABC::Resource; 37class KABC::Resource;
38 38
39class OpieXXPort : public XXPortResourceObject 39class OpieXXPort : public XXPortResourceObject
40{ 40{
41 Q_OBJECT 41 Q_OBJECT
42 42
43 public: 43 public:
44 OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 44 OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
45 45
46 QString identifier() const { return "opie"; } 46 QString identifier() const { return "opie"; }
47 47
48 public slots: 48 public slots:
49 bool exportContacts( const KABC::AddresseeList &list, const QString &data ); 49 bool exportContacts( const KABC::AddresseeList &list, const QString &identifier );
50 KABC::AddresseeList importContacts( const QString &data ) const; 50 KABC::AddresseeList importContacts( const QString &identifier ) const;
51 51
52 private: 52 private:
53 QString defaultFileName; 53 QString defaultFileName;
54 54
55}; 55};
56 56
57 57
58class OpieXXPortFactory : public XXPortFactory 58class OpieXXPortFactory : public XXPortFactory
59{ 59{
60 public: 60 public:
61 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 61 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
62 { 62 {
63 return new OpieXXPort( ab, parent, name ); 63 return new OpieXXPort( ab, parent, name );
64 } 64 }
65}; 65};
66 66
67 67
68#endif 68#endif
diff --git a/kaddressbook/xxport/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia_xxport.cpp
index 8377cd5..0cf6546 100644
--- a/kaddressbook/xxport/qtopia_xxport.cpp
+++ b/kaddressbook/xxport/qtopia_xxport.cpp
@@ -1,287 +1,78 @@
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 <qdir.h> 31#include <qdir.h>
32 32
33#include <kfiledialog.h> 33#include "addressee.h"
34#include <kmessagebox.h>
35
36//US #include <qpe/pim/addressbookaccess.h>
37
38#include "addressbook.h"
39
40/*US
41#include <qfile.h>
42#include <qtextstream.h>
43
44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED
48
49#include <klocale.h>
50#include <kmessagebox.h>
51#include <ktempfile.h>
52#include <kurl.h>
53*/
54
55#include "xxportmanager.h" 34#include "xxportmanager.h"
56//US #include "qtopiaconverter.h"
57
58#include "qtopia_xxport.h" 35#include "qtopia_xxport.h"
59 36
60/*US 37/*US
61class QtopiaXXPortFactory : public XXPortFactory 38class QtopiaXXPortFactory : public XXPortFactory
62{ 39{
63 public: 40 public:
64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 41 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
65 { 42 {
66 return new QtopiaXXPort( ab, parent, name ); 43 return new QtopiaXXPort( ab, parent, name );
67 } 44 }
68}; 45};
69*/ 46*/
70 47
71extern "C" 48extern "C"
72{ 49{
73 void *init_microkaddrbk_qtopia_xxport() 50 void *init_microkaddrbk_qtopia_xxport()
74 { 51 {
75 return ( new QtopiaXXPortFactory() ); 52 return ( new QtopiaXXPortFactory() );
76 } 53 }
77} 54}
78 55
79 56
80 57
81QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 58QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
82 : XXPortResourceObject( ab, parent, name ) 59 : XXPortResourceObject( ab, parent, name )
83{ 60{
84 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 61 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
85 62
86 KRES::Factory* mFactory = KRES::Factory::self( "contact" ); 63 if ( mFactory && !mFactory->typeName( "qtopia" ).isEmpty() )
87
88 if ( mFactory )
89 { 64 {
90 mResource = (KABC::Resource*)(mFactory->resource( "qtopia", 0, false )); 65 createImportAction( i18n( "Import Qtopia..." ) );
91 66 createExportAction( i18n( "Export Qtopia..." ) );
92 if ( mResource )
93 {
94 createImportAction( i18n( "Import Qtopia..." ) );
95 createExportAction( i18n( "Export Qtopia..." ) );
96 }
97 } 67 }
98} 68}
99 69
100bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 70bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier )
101{ 71{
102/*US 72 return _exportContacts( list, identifier, defaultFileName );
103 // we can not choose the filename. Therefore use the default to display
104 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
105
106 AddressBookAccess* access = new AddressBookAccess();
107
108 if ( !access ) {
109 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
110 qDebug(text.latin1());
111 KMessageBox::error( parentWidget(), text );
112 addressBook()->error( text );
113 return false;
114 }
115
116 KABC::QtopiaConverter mConverter;
117
118 bool res = mConverter.init();
119 if (!res)
120 {
121 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
122 qDebug(text);
123 KMessageBox::error( parentWidget(), text );
124 delete access;
125 return false;
126 }
127
128 //Now check if the file has already entries, and ask the user if he wants to delete them first.
129 { //create a new scope
130 AddressBookIterator it(*access);
131 const PimContact* firstcontact = it.toFirst();
132 if (firstcontact)
133 {
134 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
135 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
136 // Clean the database..
137
138 AddressBookIterator it2(*access);
139 for (it2.toFirst(); it2.current(); ++it2) {
140 access->removeContact(*it2.current());
141 }
142 }
143 }
144 }
145
146 KABC::Addressee::List::ConstIterator it;
147 for ( it = list.begin(); it != list.end(); ++it ) {
148 PimContact c;
149
150 res = mConverter.addresseeToQtopia( *it, c );
151 if (res == true)
152 {
153 access->addContact(c);
154 }
155 }
156
157 delete access;
158
159 return true;
160*/
161
162 if (mResource == 0)
163 return false;
164
165 QString fileName = defaultFileName;
166
167
168 mResource->setFileName( fileName );
169
170 //Now check if the file has already entries, and ask the user if he wants to delete them first.
171 if (mResource->count() > 0)
172 {
173 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
174 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
175 // Clean the database.
176 mResource->clear();
177 }
178 }
179
180 KABC::AddressBook tmpAB;
181
182 tmpAB.addResource( mResource );
183
184//US debug
185 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
186 QPtrListIterator<KABC::Resource> resIt( kabcResources );
187 KABC::Resource *resource;
188 while ( ( resource = resIt.current() ) != 0 ) {
189 ++resIt;
190 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
191 }
192
193
194 KABC::Addressee::List::ConstIterator it;
195 for ( it = list.begin(); it != list.end(); ++it ) {
196 tmpAB.insertAddressee(*it);
197 }
198
199 KABC::Ticket * ticket = mResource->requestSaveTicket();
200 return tmpAB.save( ticket );
201
202
203
204} 73}
205 74
206KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const 75KABC::AddresseeList QtopiaXXPort::importContacts( const QString &identifier ) const
207{ 76{
208/*US 77 return _importContacts( identifier, defaultFileName );
209 KABC::AddresseeList adrlst;
210
211 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
212
213 AddressBookAccess* access = new AddressBookAccess();
214
215 if ( !access ) {
216 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
217 qDebug(text.latin1());
218 addressBook()->error( text );
219 KMessageBox::error( parentWidget(), text );
220 return KABC::AddresseeList();
221 }
222
223 KABC::QtopiaConverter mConverter;
224
225 bool res = mConverter.init();
226 if (!res)
227 {
228 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
229 qDebug(text);
230 KMessageBox::error( parentWidget(), text );
231 delete access;
232 return KABC::AddresseeList();
233 }
234
235
236
237 { //create a new scope
238 AddressBookIterator it(*access);
239
240 for (it.toFirst(); it.current(); ++it) {
241 const PimContact*contact = it.current();
242
243 KABC::Addressee addressee;
244
245 res = mConverter.qtopiaToAddressee( (*contact), addressee );
246
247 if ( !addressee.isEmpty() && res )
248 {
249 adrlst.append( addressee );
250 }
251 }
252 }
253
254 delete access;
255//US the deletion of the access object deletes the backend object as well.
256
257 return adrlst;
258*/
259
260 if (mResource == 0)
261 return KABC::AddresseeList();
262
263 KABC::AddresseeList adrlst;
264
265 QString fileName = defaultFileName;
266
267 mResource->setFileName( fileName );
268
269
270 KABC::AddressBook tmpAB;
271
272 tmpAB.addResource( mResource );
273
274//US debug
275 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
276 QPtrListIterator<KABC::Resource> resIt( kabcResources );
277 KABC::Resource *resource;
278 while ( ( resource = resIt.current() ) != 0 ) {
279 ++resIt;
280 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
281 }
282
283 bool res = tmpAB.load();
284
285 return tmpAB.allAddressees();
286
287} 78}
diff --git a/kaddressbook/xxport/sharpdtm_xxport.cpp b/kaddressbook/xxport/sharpdtm_xxport.cpp
index 8c2e07a..130bc00 100644
--- a/kaddressbook/xxport/sharpdtm_xxport.cpp
+++ b/kaddressbook/xxport/sharpdtm_xxport.cpp
@@ -1,284 +1,72 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
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 <qdir.h> 31#include "addressee.h"
32
33#include <kfiledialog.h>
34#include <kmessagebox.h>
35
36//US #include <sl/slzdb.h>
37
38#include "addressbook.h"
39
40/*US
41#include <qfile.h>
42#include <qtextstream.h>
43
44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED
48
49#include <klocale.h>
50#include <kmessagebox.h>
51#include <ktempfile.h>
52#include <kurl.h>
53*/
54
55#include "xxportmanager.h" 32#include "xxportmanager.h"
56
57#include "sharpdtm_xxport.h" 33#include "sharpdtm_xxport.h"
58 34
59/*US 35/*US
60class SharpDTMXXPortFactory : public XXPortFactory 36class SharpDTMXXPortFactory : public XXPortFactory
61{ 37{
62 public: 38 public:
63 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 39 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
64 { 40 {
65 return new SharpDTMXXPort( ab, parent, name ); 41 return new SharpDTMXXPort( ab, parent, name );
66 } 42 }
67}; 43};
68*/ 44*/
69 45
70extern "C" 46extern "C"
71{ 47{
72 void *init_microkaddrbk_sharpdtm_xxport() 48 void *init_microkaddrbk_sharpdtm_xxport()
73 { 49 {
74 return ( new SharpDTMXXPortFactory() ); 50 return ( new SharpDTMXXPortFactory() );
75 } 51 }
76} 52}
77 53
78SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 54SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
79 : XXPortResourceObject( ab, parent, name ) 55 : XXPortResourceObject( ab, parent, name )
80{ 56{
81 KRES::Factory* mFactory = KRES::Factory::self( "contact" ); 57 if ( mFactory && !mFactory->typeName( "sharpdtm" ).isEmpty() )
82
83 if ( mFactory )
84 { 58 {
85 mResource = (KABC::Resource*)(mFactory->resource( "sharpdtm", 0, false )); 59 createImportAction( i18n( "Import Sharp..." ) );
86 if ( mResource ) 60 createExportAction( i18n( "Export Sharp..." ) );
87 {
88 createImportAction( i18n( "Import Sharp..." ) );
89 createExportAction( i18n( "Export Sharp..." ) );
90 }
91 } 61 }
92} 62}
93 63
94bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 64bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier )
95{ 65{
96/*US 66 return _exportContacts( list, identifier, QString::null );
97 // we can not choose the filename. Therefore use the default to display
98 QString fileName = SlZDataBase::addressbookFileName();
99
100 SlZDataBase* access = new SlZDataBase(fileName,
101 SlZDataBase::addressbookItems());
102
103 if ( !access ) {
104 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
105 qDebug(text.latin1());
106 KMessageBox::error( parentWidget(), text );
107 addressBook()->error( text );
108 return false;
109 }
110
111 KABC::SharpDTMConverter mConverter;
112
113 bool res = mConverter.init();
114 if (!res)
115 {
116 QString text( i18n( "Unable to initialize sharpdtm converter.<br>Most likely a problem with the category file." ) );
117 qDebug(text);
118 KMessageBox::error( parentWidget(), text );
119 delete access;
120 return false;
121 }
122
123 //Now check if the file has already entries, and ask the user if he wants to delete them first.
124 if (access->count() > 0)
125 {
126 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
127 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
128 // Clean the database..
129 access->deleteCard(0, SlZDataBase::AllCard );
130 }
131 }
132
133 KABC::Addressee::List::ConstIterator it;
134 for ( it = list.begin(); it != list.end(); ++it ) {
135 CardId c;
136 res = access->editNewCard();
137
138 if (res == true)
139 {
140 res = mConverter.addresseeToSharp( *it, access, c );
141
142 if (res == true)
143 access->finishEditCard(&c);
144 else
145 access->cancelEditCard();
146 }
147 }
148
149 delete access;
150
151 return true;
152*/
153
154 if (mResource == 0)
155 return false;
156
157 // we can not choose the filename. Therefore use the default to display
158 QString fileName = mResource->fileName();
159
160 if ( fileName.isEmpty() )
161 return false;
162
163 //Now check if the file has already entries, and ask the user if he wants to delete them first.
164 if (mResource->count() > 0)
165 {
166 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
167 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
168 // Clean the database..
169 mResource->clear();
170 }
171 }
172
173 KABC::AddressBook tmpAB;
174
175 tmpAB.addResource( mResource );
176
177//US debug
178 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
179 QPtrListIterator<KABC::Resource> resIt( kabcResources );
180 KABC::Resource *resource;
181 while ( ( resource = resIt.current() ) != 0 ) {
182 ++resIt;
183 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
184 }
185
186
187 KABC::Addressee::List::ConstIterator it;
188 for ( it = list.begin(); it != list.end(); ++it ) {
189 tmpAB.insertAddressee(*it);
190 }
191
192 KABC::Ticket * ticket = mResource->requestSaveTicket();
193 return tmpAB.save( ticket );
194
195
196} 67}
197 68
198KABC::AddresseeList SharpDTMXXPort::importContacts( const QString& ) const 69KABC::AddresseeList SharpDTMXXPort::importContacts( const QString &identifier ) const
199{ 70{
200/*US 71 return _importContacts( identifier, QString::null );
201 KABC::AddresseeList adrlst;
202
203 QString fileName = SlZDataBase::addressbookFileName();
204
205 // the last parameter in the SlZDataBase constructor means "readonly"
206 SlZDataBase* access = new SlZDataBase(fileName,
207 SlZDataBase::addressbookItems(), NULL, true);
208
209
210 if ( !access ) {
211 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
212 qDebug(text.latin1());
213 addressBook()->error( text );
214 KMessageBox::error( parentWidget(), text );
215 return KABC::AddresseeList();
216 }
217
218 KABC::SharpDTMConverter mConverter;
219
220 bool res = mConverter.init();
221 if (!res)
222 {
223 QString text( i18n( "Unable to initialize sharp converter.<br>Most likely a problem with the category file." ) );
224 qDebug(text);
225 KMessageBox::error( parentWidget(), text );
226 delete access;
227 return KABC::AddresseeList();
228 }
229
230
231 { //create a new scope
232 CardId id;
233
234 for (bool res=access->first(); res == true; res=access->next()) {
235 id = access->cardId();
236
237 KABC::Addressee addressee;
238
239 res = mConverter.sharpToAddressee( id, access, addressee );
240
241 if ( !addressee.isEmpty() && res )
242 {
243 adrlst.append( addressee );
244 }
245 }
246 }
247
248 delete access;
249
250 return adrlst;
251*/
252
253 if (mResource == 0)
254 return KABC::AddresseeList();
255
256 KABC::AddresseeList adrlst;
257
258 QString fileName = mResource->fileName();
259
260 if ( fileName.isEmpty() )
261 return KABC::AddresseeList();
262
263 mResource->setFileName( fileName );
264
265
266 KABC::AddressBook tmpAB;
267
268 tmpAB.addResource( mResource );
269
270//US debug
271 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
272 QPtrListIterator<KABC::Resource> resIt( kabcResources );
273 KABC::Resource *resource;
274 while ( ( resource = resIt.current() ) != 0 ) {
275 ++resIt;
276 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
277 }
278
279 bool res = tmpAB.load();
280
281 return tmpAB.allAddressees();
282
283
284} 72}
diff --git a/kaddressbook/xxport/sharpdtm_xxport.h b/kaddressbook/xxport/sharpdtm_xxport.h
index 43fd434..0797b01 100644
--- a/kaddressbook/xxport/sharpdtm_xxport.h
+++ b/kaddressbook/xxport/sharpdtm_xxport.h
@@ -1,60 +1,60 @@
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#ifndef SHARPDTM_XXPORT_H 31#ifndef SHARPDTM_XXPORT_H
32#define SHARPDTM_XXPORT_H 32#define SHARPDTM_XXPORT_H
33 33
34#include <xxportobject.h> 34#include <xxportobject.h>
35 35
36class SharpDTMXXPort : public XXPortResourceObject 36class SharpDTMXXPort : public XXPortResourceObject
37{ 37{
38 Q_OBJECT 38 Q_OBJECT
39 39
40 public: 40 public:
41 SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 41 SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
42 42
43 QString identifier() const { return "qtopia"; } 43 QString identifier() const { return "sharpdtm"; }
44 44
45 public slots: 45 public slots:
46 bool exportContacts( const KABC::AddresseeList &list, const QString &data ); 46 bool exportContacts( const KABC::AddresseeList &list, const QString &data );
47 KABC::AddresseeList importContacts( const QString &data ) const; 47 KABC::AddresseeList importContacts( const QString &data ) const;
48 48
49}; 49};
50 50
51class SharpDTMXXPortFactory : public XXPortFactory 51class SharpDTMXXPortFactory : public XXPortFactory
52{ 52{
53 public: 53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 { 55 {
56 return new SharpDTMXXPort( ab, parent, name ); 56 return new SharpDTMXXPort( ab, parent, name );
57 } 57 }
58}; 58};
59 59
60#endif 60#endif
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
index bb985a6..4351753 100644
--- a/kaddressbook/xxportobject.cpp
+++ b/kaddressbook/xxportobject.cpp
@@ -1,173 +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 37
37#include "kabcore.h" 38#include "kabcore.h"
38 39#include "addressee.h"
40#include "tmpaddressbook.h"
39#include "xxportobject.h" 41#include "xxportobject.h"
40 42
43
41class XXPortObject::XXPortObjectPrivate 44class XXPortObject::XXPortObjectPrivate
42{ 45{
43 public: 46 public:
44 QSignalMapper *mExportMapper; 47 QSignalMapper *mExportMapper;
45 QSignalMapper *mImportMapper; 48 QSignalMapper *mImportMapper;
46}; 49};
47 50
48XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent, 51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
49 const char *name ) 52 const char *name )
50 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ), 53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
51 d( new XXPortObjectPrivate ) 54 d( new XXPortObjectPrivate )
52{ 55{
53 d->mExportMapper = new QSignalMapper( this ); 56 d->mExportMapper = new QSignalMapper( this );
54 d->mImportMapper = new QSignalMapper( this ); 57 d->mImportMapper = new QSignalMapper( this );
55 58
56 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ), 59 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ),
57 SLOT( slotExportActivated( const QString& ) ) ); 60 SLOT( slotExportActivated( const QString& ) ) );
58 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ), 61 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ),
59 SLOT( slotImportActivated( const QString& ) ) ); 62 SLOT( slotImportActivated( const QString& ) ) );
60} 63}
61 64
62XXPortObject::~XXPortObject() 65XXPortObject::~XXPortObject()
63{ 66{
64 delete d; 67 delete d;
65 d = 0; 68 d = 0;
66} 69}
67 70
68bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& ) 71bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& )
69{ 72{
70 // do nothing 73 // do nothing
71 return false; 74 return false;
72} 75}
73 76
74KABC::AddresseeList XXPortObject::importContacts( const QString& ) const 77KABC::AddresseeList XXPortObject::importContacts( const QString& ) const
75{ 78{
76 // do nothing 79 // do nothing
77 return KABC::AddresseeList(); 80 return KABC::AddresseeList();
78} 81}
79 82
80void XXPortObject::createImportAction( const QString &label, const QString &data ) 83void XXPortObject::createImportAction( const QString &label, const QString &data )
81{ 84{
82#ifdef KAB_EMBEDDED 85#ifdef KAB_EMBEDDED
83 KABCore* kabcore = (KABCore*)mParentWidget; 86 KABCore* kabcore = (KABCore*)mParentWidget;
84#endif //KAB_EMBEDDED 87#endif //KAB_EMBEDDED
85 88
86 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 89 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
87#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
88 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() );
89#else //KAB_EMBEDDED 92#else //KAB_EMBEDDED
90 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() );
91#endif //KAB_EMBEDDED 94#endif //KAB_EMBEDDED
92 95
93 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 96 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
94 97
95#ifndef KAB_EMBEDDED 98#ifndef KAB_EMBEDDED
96 setXMLFile( identifier() + "_xxportui.rc" ); 99 setXMLFile( identifier() + "_xxportui.rc" );
97#endif //KAB_EMBEDDED 100#endif //KAB_EMBEDDED
98 101
99#ifdef KAB_EMBEDDED 102#ifdef KAB_EMBEDDED
100 action->plug((QWidget*)kabcore->getImportMenu()); 103 action->plug((QWidget*)kabcore->getImportMenu());
101#endif //KAB_EMBEDDED 104#endif //KAB_EMBEDDED
102 105
103} 106}
104 107
105void XXPortObject::createExportAction( const QString &label, const QString &data ) 108void XXPortObject::createExportAction( const QString &label, const QString &data )
106{ 109{
107#ifdef KAB_EMBEDDED 110#ifdef KAB_EMBEDDED
108 KABCore* kabcore = (KABCore*)mParentWidget; 111 KABCore* kabcore = (KABCore*)mParentWidget;
109#endif //KAB_EMBEDDED 112#endif //KAB_EMBEDDED
110 113
111 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 114 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
112#ifndef KAB_EMBEDDED 115#ifndef KAB_EMBEDDED
113 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() );
114#else //KAB_EMBEDDED 117#else //KAB_EMBEDDED
115 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() );
116#endif //KAB_EMBEDDED 119#endif //KAB_EMBEDDED
117 120
118 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 121 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
119 122
120#ifndef KAB_EMBEDDED 123#ifndef KAB_EMBEDDED
121 setXMLFile( identifier() + "_xxportui.rc" ); 124 setXMLFile( identifier() + "_xxportui.rc" );
122#endif //KAB_EMBEDDED 125#endif //KAB_EMBEDDED
123 126
124#ifdef KAB_EMBEDDED 127#ifdef KAB_EMBEDDED
125 action->plug((QWidget*)kabcore->getExportMenu()); 128 action->plug((QWidget*)kabcore->getExportMenu());
126#endif //KAB_EMBEDDED 129#endif //KAB_EMBEDDED
127 130
128} 131}
129 132
130KABC::AddressBook *XXPortObject::addressBook() const 133KABC::AddressBook *XXPortObject::addressBook() const
131{ 134{
132 return mAddressBook; 135 return mAddressBook;
133} 136}
134 137
135QWidget *XXPortObject::parentWidget() const 138QWidget *XXPortObject::parentWidget() const
136{ 139{
137 return mParentWidget; 140 return mParentWidget;
138} 141}
139 142
140void XXPortObject::slotExportActivated( const QString &data ) 143void XXPortObject::slotExportActivated( const QString &data )
141{ 144{
142 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 145 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
143} 146}
144 147
145void XXPortObject::slotImportActivated( const QString &data ) 148void XXPortObject::slotImportActivated( const QString &data )
146{ 149{
147 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 150 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
148} 151}
149 152
150/******************************************************************** 153/********************************************************************
151 * 154 *
152 *******************************************************************/ 155 *******************************************************************/
153 156
154 157
155XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, 158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent,
156 const char *name ) 159 const char *name )
157 : XXPortObject( ab, parent, name ), mResource(0) 160 : XXPortObject( ab, parent, name ), mFactory(0)
158{ 161{
162 mFactory = KRES::Factory::self( "tmpcontact" );
159} 163}
160 164
161XXPortResourceObject::~XXPortResourceObject() 165XXPortResourceObject::~XXPortResourceObject()
162{ 166{
167 //do not delete the factory. It is a singleton, and selfcontained
163} 168}
164 169
165bool XXPortResourceObject::isAvailable() 170bool XXPortResourceObject::isAvailable()
166{ 171{
167 return (mResource != 0); 172 return (mFactory != 0);
168} 173}
169 174
170 175
176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName )
177{
178 //create new resource
179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false ));
180
181 if (mResource == 0)
182 return false;
183
184 if (fileName != QString::null)
185 mResource->setFileName( fileName );
186
187
188 KABC::TmpAddressBook tmpAB;
189
190 bool res = tmpAB.addResource( mResource );
191 if (res == false)
192 {
193 delete mResource;
194 return false;
195 }
196
197 res = tmpAB.load();
198 if (res == false)
199 {
200 //removeResource deletes also the resource object, if the linkcount is 0
201 tmpAB.removeResource( mResource );
202 return false;
203 }
204
205
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())
208 {
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 ) {
211 // Clean the database..
212 tmpAB.clear();
213 }
214 }
215
216
217 KABC::Addressee::List::ConstIterator it;
218 for ( it = list.begin(); it != list.end(); ++it ) {
219 tmpAB.insertAddressee(*it);
220 }
221
222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
223
224 res = false;
225 if (ticket != 0)
226 res = tmpAB.save( ticket );
227
228 //removeResource deletes also the resource object, if the linkcount is 0
229 tmpAB.removeResource( mResource );
230
231 return res;
232}
233
234
235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const
236{
237
238
239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false ));
240
241 if (mResource == 0)
242 return KABC::AddresseeList();
243
244 KABC::AddresseeList adrlst;
245
246 if (fileName != QString::null)
247 mResource->setFileName( fileName );
248
249
250 KABC::TmpAddressBook tmpAB;
251
252 bool res = tmpAB.addResource( mResource );
253 if (res == false)
254 {
255 delete mResource;
256 return KABC::AddresseeList();
257 }
258
259 res = tmpAB.load();
260
261 adrlst = tmpAB.allAddressees();
262
263 //remove resource deletes also the Resourceobject, if the linkcount is 0
264 tmpAB.removeResource( mResource );
265
266 return adrlst;
267}
268
269
270
171#ifndef KAB_EMBEDDED 271#ifndef KAB_EMBEDDED
172#include "xxportobject.moc" 272#include "xxportobject.moc"
173#endif //KAB_EMBEDDED 273#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxportobject.h b/kaddressbook/xxportobject.h
index d547855..de39b9f 100644
--- a/kaddressbook/xxportobject.h
+++ b/kaddressbook/xxportobject.h
@@ -1,170 +1,175 @@
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#ifndef XXPORTOBJECT_H 31#ifndef XXPORTOBJECT_H
32#define XXPORTOBJECT_H 32#define XXPORTOBJECT_H
33 33
34#include <qobject.h> 34#include <qobject.h>
35 35
36#include <kabc/addressbook.h> 36#include <kabc/addressbook.h>
37#include <kabc/addresseelist.h> 37#include <kabc/addresseelist.h>
38#include <kabc/resource.h> 38#include <kabc/resource.h>
39#include <kxmlguiclient.h> 39#include <kxmlguiclient.h>
40#include <klibloader.h> 40#include <klibloader.h>
41 41
42 42
43 43class KRES::Factory;
44 44
45 45
46class XXPortObject : public QObject, virtual public KXMLGUIClient 46class XXPortObject : public QObject, virtual public KXMLGUIClient
47{ 47{
48 Q_OBJECT 48 Q_OBJECT
49 49
50 public: 50 public:
51 XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 51 XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
52 ~XXPortObject(); 52 ~XXPortObject();
53 53
54 /** 54 /**
55 Returns the unique identifier of this xxport modul, it should 55 Returns the unique identifier of this xxport modul, it should
56 be the lowercase name of the import/export format e.g. 'vcard' 56 be the lowercase name of the import/export format e.g. 'vcard'
57 */ 57 */
58 virtual QString identifier() const = 0; 58 virtual QString identifier() const = 0;
59 59
60 /** 60 /**
61 Reimplement this method if the XXPortManager shall 61 Reimplement this method if the XXPortManager shall
62 pass a sorted list to @ref exportContacts(). 62 pass a sorted list to @ref exportContacts().
63 */ 63 */
64 virtual bool requiresSorting() const { return false; } 64 virtual bool requiresSorting() const { return false; }
65 65
66 /** 66 /**
67 Returns true if the XXPortObject can be used. 67 Returns true if the XXPortObject can be used.
68 One case it can not be used is for example if a needed lib could not be loaded. 68 One case it can not be used is for example if a needed lib could not be loaded.
69 */ 69 */
70 virtual bool isAvailable() const { return true; }; 70 virtual bool isAvailable() const { return true; };
71 71
72 72
73 public slots: 73 public slots:
74 /** 74 /**
75 Reimplement this method for exporting the contacts. 75 Reimplement this method for exporting the contacts.
76 */ 76 */
77 virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier ); 77 virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier );
78 78
79 /** 79 /**
80 Reimplement this method for importing the contacts. 80 Reimplement this method for importing the contacts.
81 */ 81 */
82 virtual KABC::AddresseeList importContacts( const QString& identifier ) const; 82 virtual KABC::AddresseeList importContacts( const QString& identifier ) const;
83 83
84 signals: 84 signals:
85 /** 85 /**
86 Emitted whenever the export action is activated. 86 Emitted whenever the export action is activated.
87 The parameter contains the @ref identifier() for 87 The parameter contains the @ref identifier() for
88 unique identification. 88 unique identification.
89 */ 89 */
90 void exportActivated( const QString&, const QString& ); 90 void exportActivated( const QString&, const QString& );
91 91
92 /** 92 /**
93 Emitted whenever the import action is activated. 93 Emitted whenever the import action is activated.
94 The parameter contains the @ref identifier() for 94 The parameter contains the @ref identifier() for
95 unique identification. 95 unique identification.
96 */ 96 */
97 void importActivated( const QString&, const QString& ); 97 void importActivated( const QString&, const QString& );
98 98
99 protected: 99 protected:
100 /** 100 /**
101 Create the import action. The identifier is passed in the import slot. 101 Create the import action. The identifier is passed in the import slot.
102 */ 102 */
103 void createImportAction( const QString &label, const QString &identifier = QString::null ); 103 void createImportAction( const QString &label, const QString &identifier = QString::null );
104 104
105 /** 105 /**
106 Create the export action. The identifier is passed in the export slot. 106 Create the export action. The identifier is passed in the export slot.
107 */ 107 */
108 void createExportAction( const QString &label, const QString &identifier = QString::null ); 108 void createExportAction( const QString &label, const QString &identifier = QString::null );
109 109
110 /** 110 /**
111 Returns a pointer to the address book object. 111 Returns a pointer to the address book object.
112 */ 112 */
113 KABC::AddressBook *addressBook() const; 113 KABC::AddressBook *addressBook() const;
114 114
115 /** 115 /**
116 Returns a pointer to the parent widget. It can be used as parent for 116 Returns a pointer to the parent widget. It can be used as parent for
117 message boxes. 117 message boxes.
118 */ 118 */
119 QWidget *parentWidget() const; 119 QWidget *parentWidget() const;
120 120
121 121
122 private slots: 122 private slots:
123 void slotImportActivated( const QString& ); 123 void slotImportActivated( const QString& );
124 void slotExportActivated( const QString& ); 124 void slotExportActivated( const QString& );
125 125
126 private: 126 private:
127 KABC::AddressBook *mAddressBook; 127 KABC::AddressBook *mAddressBook;
128 QWidget *mParentWidget; 128 QWidget *mParentWidget;
129 129
130 class XXPortObjectPrivate; 130 class XXPortObjectPrivate;
131 XXPortObjectPrivate *d; 131 XXPortObjectPrivate *d;
132}; 132};
133 133
134 134
135 135
136class XXPortResourceObject : public XXPortObject 136class XXPortResourceObject : public XXPortObject
137{ 137{
138 Q_OBJECT 138 Q_OBJECT
139 139
140 public: 140 public:
141 XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 141 XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
142 ~XXPortResourceObject(); 142 ~XXPortResourceObject();
143 143
144 /** 144 /**
145 Returns true if the XXPortObject can be used. 145 Returns true if the XXPortObject can be used.
146 One case it can not be used is for example if a needed lib could not be loaded. 146 One case it can not be used is for example if a needed lib could not be loaded.
147 */ 147 */
148 virtual bool isAvailable(); 148 virtual bool isAvailable();
149
150 protected:
151 bool _exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName );
152 KABC::AddresseeList _importContacts( const QString& identifier, const QString& fileName ) const;
153
149 protected: 154 protected:
150 KABC::Resource* mResource; 155 KRES::Factory* mFactory;
151}; 156};
152 157
153 158
154 159
155 160
156class XXPortFactory : public KLibFactory 161class XXPortFactory : public KLibFactory
157{ 162{
158 public: 163 public:
159 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, 164 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
160 const char *name = 0 ) = 0; 165 const char *name = 0 ) = 0;
161 166
162 protected: 167 protected:
163 virtual QObject* createObject( QObject*, const char*, const char*, 168 virtual QObject* createObject( QObject*, const char*, const char*,
164 const QStringList & ) 169 const QStringList & )
165 { 170 {
166 return 0; 171 return 0;
167 } 172 }
168}; 173};
169 174
170#endif 175#endif