summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
authorulf69 <ulf69>2004-10-13 21:27:10 (UTC)
committer ulf69 <ulf69>2004-10-13 21:27:10 (UTC)
commit737183a5abd7d7b02048e8a939bafd0a8e803918 (patch) (unidiff)
treeddacf864a06a6669911b1d48862e564399eeb33b /kabc/plugins
parent7bb6c5f55d29ad4632b1f5c7361eee4c0d8b7cb0 (diff)
downloadkdepimpi-737183a5abd7d7b02048e8a939bafd0a8e803918.zip
kdepimpi-737183a5abd7d7b02048e8a939bafd0a8e803918.tar.gz
kdepimpi-737183a5abd7d7b02048e8a939bafd0a8e803918.tar.bz2
removal of syncresources
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/dir/resourcedir.cpp7
-rw-r--r--kabc/plugins/dir/resourcedir.h2
-rw-r--r--kabc/plugins/file/resourcefile.cpp16
-rw-r--r--kabc/plugins/file/resourcefile.h4
-rw-r--r--kabc/plugins/ldap/resourceldap.cpp7
-rw-r--r--kabc/plugins/ldap/resourceldap.h2
-rw-r--r--kabc/plugins/opie/resourceopie.cpp11
-rw-r--r--kabc/plugins/opie/resourceopie.h4
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp11
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.h4
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp8
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.h4
12 files changed, 35 insertions, 45 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index e58e4f7..e2b7b08 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -1,276 +1,275 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28 28
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31#ifndef _WIN32_ 31#ifndef _WIN32_
32#include <unistd.h> 32#include <unistd.h>
33#endif 33#endif
34 34
35#include <qregexp.h> 35#include <qregexp.h>
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qwidget.h> 37#include <qwidget.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42//US #include <kgenericfactory.h> 42//US #include <kgenericfactory.h>
43#include <kglobal.h> 43#include <kglobal.h>
44#include <klocale.h> 44#include <klocale.h>
45#include <kstandarddirs.h> 45#include <kstandarddirs.h>
46#include <kurlrequester.h> 46#include <kurlrequester.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48 48
49#include "addressbook.h" 49#include "addressbook.h"
50 50
51#include "formatfactory.h" 51#include "formatfactory.h"
52 52
53#include "resourcedirconfig.h" 53#include "resourcedirconfig.h"
54#include "stdaddressbook.h" 54#include "stdaddressbook.h"
55 55
56//US 56//US
57#include <qdir.h> 57#include <qdir.h>
58 58
59#define NO_DIRWATCH 59#define NO_DIRWATCH
60#include "resourcedir.h" 60#include "resourcedir.h"
61#include "syncprefwidget.h"
62 61
63//#define ALLOW_LOCKING 62//#define ALLOW_LOCKING
64 63
65using namespace KABC; 64using namespace KABC;
66 65
67extern "C" 66extern "C"
68#ifdef _WIN32_ 67#ifdef _WIN32_
69__declspec(dllexport) 68__declspec(dllexport)
70#else 69#else
71{ 70{
72#endif 71#endif
73 72
74//US void *init_kabc_dir() 73//US void *init_kabc_dir()
75 void *init_microkabc_dir() 74 void *init_microkabc_dir()
76 { 75 {
77 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>(); 76 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
78 } 77 }
79#ifndef _WIN32_ 78#ifndef _WIN32_
80} 79}
81#endif 80#endif
82 81
83ResourceDir::ResourceDir( const KConfig *config, bool syncable ) 82ResourceDir::ResourceDir( const KConfig *config )
84 : Resource( config, syncable ) 83 : Resource( config )
85{ 84{
86 QString path; 85 QString path;
87 86
88 KConfig *cfg = (KConfig *)config; 87 KConfig *cfg = (KConfig *)config;
89 if ( cfg ) { 88 if ( cfg ) {
90//US path = config->readEntry( "FilePath" ); 89//US path = config->readEntry( "FilePath" );
91 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); 90 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() );
92//US mFormatName = config->readEntry( "FileFormat" ); 91//US mFormatName = config->readEntry( "FileFormat" );
93 mFormatName = cfg->readEntry( "FileFormat", "vcard" ); 92 mFormatName = cfg->readEntry( "FileFormat", "vcard" );
94 } else { 93 } else {
95 path = StdAddressBook::directoryName(); 94 path = StdAddressBook::directoryName();
96 mFormatName = "vcard"; 95 mFormatName = "vcard";
97 } 96 }
98 97
99 98
100 FormatFactory *factory = FormatFactory::self(); 99 FormatFactory *factory = FormatFactory::self();
101 mFormat = factory->format( mFormatName ); 100 mFormat = factory->format( mFormatName );
102 101
103 if ( !mFormat ) { 102 if ( !mFormat ) {
104 mFormatName = "vcard"; 103 mFormatName = "vcard";
105 mFormat = factory->format( mFormatName ); 104 mFormat = factory->format( mFormatName );
106 } 105 }
107 106
108/*US 107/*US
109//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); 108//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
110 if (mFormatName == "vcard") 109 if (mFormatName == "vcard")
111 mFormat = new VCardFormatPlugin2(); 110 mFormat = new VCardFormatPlugin2();
112 else if (mFormatName == "binary") 111 else if (mFormatName == "binary")
113 mFormat = new BinaryFormat(); 112 mFormat = new BinaryFormat();
114 else 113 else
115 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); 114 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
116*/ 115*/
117#ifndef NO_DIRWATCH 116#ifndef NO_DIRWATCH
118 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); 117 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
119 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); 118 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
120 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); 119 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
121#endif 120#endif
122 setPath( path ); 121 setPath( path );
123} 122}
124 123
125ResourceDir::~ResourceDir() 124ResourceDir::~ResourceDir()
126{ 125{
127 delete mFormat; 126 delete mFormat;
128 mFormat = 0; 127 mFormat = 0;
129} 128}
130 129
131void ResourceDir::writeConfig( KConfig *config ) 130void ResourceDir::writeConfig( KConfig *config )
132{ 131{
133 config->setGroup( "Resource_" + identifier() ); 132 config->setGroup( "Resource_" + identifier() );
134 Resource::writeConfig( config ); 133 Resource::writeConfig( config );
135 134
136 config->writeEntry( "FilePath", mPath ); 135 config->writeEntry( "FilePath", mPath );
137 config->writeEntry( "FileFormat", mFormatName ); 136 config->writeEntry( "FileFormat", mFormatName );
138} 137}
139 138
140Ticket *ResourceDir::requestSaveTicket() 139Ticket *ResourceDir::requestSaveTicket()
141{ 140{
142 141
143 142
144 if ( !addressBook() ) return 0; 143 if ( !addressBook() ) return 0;
145#ifdef ALLOW_LOCKING 144#ifdef ALLOW_LOCKING
146 if ( !lock( mPath ) ) { 145 if ( !lock( mPath ) ) {
147 146
148 return 0; 147 return 0;
149 } 148 }
150#endif 149#endif
151 return createTicket( this ); 150 return createTicket( this );
152 151
153} 152}
154 153
155 154
156bool ResourceDir::doOpen() 155bool ResourceDir::doOpen()
157{ 156{
158 QDir dir( mPath ); 157 QDir dir( mPath );
159 if ( !dir.exists() ) { // no directory available 158 if ( !dir.exists() ) { // no directory available
160 return dir.mkdir( dir.path() ); 159 return dir.mkdir( dir.path() );
161 } else { 160 } else {
162 QString testName = dir.entryList( QDir::Files )[0]; 161 QString testName = dir.entryList( QDir::Files )[0];
163 if ( testName.isNull() || testName.isEmpty() ) // no file in directory 162 if ( testName.isNull() || testName.isEmpty() ) // no file in directory
164 return true; 163 return true;
165 164
166 QFile file( mPath + "/" + testName ); 165 QFile file( mPath + "/" + testName );
167 if ( file.open( IO_ReadOnly ) ) 166 if ( file.open( IO_ReadOnly ) )
168 return true; 167 return true;
169 168
170 if ( file.size() == 0 ) 169 if ( file.size() == 0 )
171 return true; 170 return true;
172 171
173 bool ok = mFormat->checkFormat( &file ); 172 bool ok = mFormat->checkFormat( &file );
174 file.close(); 173 file.close();
175 return ok; 174 return ok;
176 } 175 }
177} 176}
178 177
179void ResourceDir::doClose() 178void ResourceDir::doClose()
180{ 179{
181} 180}
182 181
183bool ResourceDir::load() 182bool ResourceDir::load()
184{ 183{
185 QDir dir( mPath ); 184 QDir dir( mPath );
186 QStringList files = dir.entryList( QDir::Files ); 185 QStringList files = dir.entryList( QDir::Files );
187 186
188 QStringList::Iterator it; 187 QStringList::Iterator it;
189 bool ok = true; 188 bool ok = true;
190 for ( it = files.begin(); it != files.end(); ++it ) { 189 for ( it = files.begin(); it != files.end(); ++it ) {
191 QFile file( mPath + "/" + (*it) ); 190 QFile file( mPath + "/" + (*it) );
192 191
193 if ( !file.open( IO_ReadOnly ) ) { 192 if ( !file.open( IO_ReadOnly ) ) {
194 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); 193 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
195 ok = false; 194 ok = false;
196 continue; 195 continue;
197 } 196 }
198 197
199 if ( !mFormat->loadAll( addressBook(), this, &file ) ) 198 if ( !mFormat->loadAll( addressBook(), this, &file ) )
200 ok = false; 199 ok = false;
201 200
202 file.close(); 201 file.close();
203 } 202 }
204 203
205 return ok; 204 return ok;
206} 205}
207 206
208bool ResourceDir::save( Ticket *ticket ) 207bool ResourceDir::save( Ticket *ticket )
209{ 208{
210 AddressBook::Iterator it; 209 AddressBook::Iterator it;
211 bool ok = true; 210 bool ok = true;
212#ifndef NO_DIRWATCH 211#ifndef NO_DIRWATCH
213 mDirWatch.stopScan(); 212 mDirWatch.stopScan();
214#endif 213#endif
215 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 214 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
216 if ( (*it).resource() != this || !(*it).changed() ) 215 if ( (*it).resource() != this || !(*it).changed() )
217 continue; 216 continue;
218 217
219 QFile file( mPath + "/" + (*it).uid() ); 218 QFile file( mPath + "/" + (*it).uid() );
220 if ( !file.open( IO_WriteOnly ) ) { 219 if ( !file.open( IO_WriteOnly ) ) {
221 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); 220 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) );
222 continue; 221 continue;
223 } 222 }
224 223
225 mFormat->save( *it, &file ); 224 mFormat->save( *it, &file );
226 225
227 // mark as unchanged 226 // mark as unchanged
228 (*it).setChanged( false ); 227 (*it).setChanged( false );
229 228
230 file.close(); 229 file.close();
231 } 230 }
232#ifndef NO_DIRWATCH 231#ifndef NO_DIRWATCH
233 mDirWatch.startScan(); 232 mDirWatch.startScan();
234#endif 233#endif
235 delete ticket; 234 delete ticket;
236#ifdef ALLOW_LOCKING 235#ifdef ALLOW_LOCKING
237 unlock( mPath ); 236 unlock( mPath );
238#endif 237#endif
239 return ok; 238 return ok;
240} 239}
241 240
242bool ResourceDir::lock( const QString &path ) 241bool ResourceDir::lock( const QString &path )
243{ 242{
244#ifdef ALLOW_LOCKING 243#ifdef ALLOW_LOCKING
245 QString p = path; 244 QString p = path;
246//US change the implementation how the lockfilename is getting created 245//US change the implementation how the lockfilename is getting created
247//US p.replace( QRegExp("/"), "_" ); 246//US p.replace( QRegExp("/"), "_" );
248//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); 247//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
249 KURL url(p); 248 KURL url(p);
250 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 249 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
251 250
252 251
253 if ( QFile::exists( lockName ) ) return false; 252 if ( QFile::exists( lockName ) ) return false;
254 253
255 QString lockUniqueName; 254 QString lockUniqueName;
256 lockUniqueName = p + KApplication::randomString( 8 ); 255 lockUniqueName = p + KApplication::randomString( 8 );
257 256
258 url = lockUniqueName; 257 url = lockUniqueName;
259//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 258//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
260 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 259 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
261 260
262 // Create unique file 261 // Create unique file
263 QFile file( mLockUniqueName ); 262 QFile file( mLockUniqueName );
264 file.open( IO_WriteOnly ); 263 file.open( IO_WriteOnly );
265 file.close(); 264 file.close();
266 265
267 // Create lock file 266 // Create lock file
268 int result = 0; 267 int result = 0;
269#ifndef _WIN32_ 268#ifndef _WIN32_
270 result = ::link( QFile::encodeName( mLockUniqueName ), 269 result = ::link( QFile::encodeName( mLockUniqueName ),
271 QFile::encodeName( lockName ) ); 270 QFile::encodeName( lockName ) );
272#endif 271#endif
273 if ( result == 0 ) { 272 if ( result == 0 ) {
274 addressBook()->emitAddressBookLocked(); 273 addressBook()->emitAddressBookLocked();
275 return true; 274 return true;
276 } 275 }
diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h
index 77cd18c..6c1e922 100644
--- a/kabc/plugins/dir/resourcedir.h
+++ b/kabc/plugins/dir/resourcedir.h
@@ -1,116 +1,116 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_RESOURCEDIR_H 28#ifndef KABC_RESOURCEDIR_H
29#define KABC_RESOURCEDIR_H 29#define KABC_RESOURCEDIR_H
30 30
31#include <kconfig.h> 31#include <kconfig.h>
32#include <kdirwatch.h> 32#include <kdirwatch.h>
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35 35
36#include "resource.h" 36#include "resource.h"
37 37
38class QTimer; 38class QTimer;
39 39
40namespace KABC { 40namespace KABC {
41 41
42class FormatPlugin; 42class FormatPlugin;
43 43
44/** 44/**
45 @internal 45 @internal
46*/ 46*/
47class ResourceDir : public Resource 47class ResourceDir : public Resource
48{ 48{
49 Q_OBJECT 49 Q_OBJECT
50 50
51public: 51public:
52 ResourceDir( const KConfig*, bool syncable ); 52 ResourceDir( const KConfig* );
53 ~ResourceDir(); 53 ~ResourceDir();
54 54
55 virtual void writeConfig( KConfig* ); 55 virtual void writeConfig( KConfig* );
56 56
57 virtual bool doOpen(); 57 virtual bool doOpen();
58 virtual void doClose(); 58 virtual void doClose();
59 59
60 virtual Ticket *requestSaveTicket(); 60 virtual Ticket *requestSaveTicket();
61 61
62 virtual bool load(); 62 virtual bool load();
63 virtual bool save( Ticket * ); 63 virtual bool save( Ticket * );
64 64
65 /** 65 /**
66 * Set path to be used for saving. 66 * Set path to be used for saving.
67 */ 67 */
68 void setPath( const QString & ); 68 void setPath( const QString & );
69 69
70 /** 70 /**
71 * Return path used for loading and saving the address book. 71 * Return path used for loading and saving the address book.
72 */ 72 */
73 QString path() const; 73 QString path() const;
74 74
75 /** 75 /**
76 * Set the format by name. 76 * Set the format by name.
77 */ 77 */
78 void setFormat( const QString &format ); 78 void setFormat( const QString &format );
79 79
80 /** 80 /**
81 * Returns the format name. 81 * Returns the format name.
82 */ 82 */
83 QString format() const; 83 QString format() const;
84 84
85 /** 85 /**
86 * Remove a addressee from its source. 86 * Remove a addressee from its source.
87 * This method is mainly called by KABC::AddressBook. 87 * This method is mainly called by KABC::AddressBook.
88 */ 88 */
89 virtual void removeAddressee( const Addressee& addr ); 89 virtual void removeAddressee( const Addressee& addr );
90 90
91 /** 91 /**
92 * This method is called by an error handler if the application 92 * This method is called by an error handler if the application
93 * crashed 93 * crashed
94 */ 94 */
95 virtual void cleanUp(); 95 virtual void cleanUp();
96 96
97protected slots: 97protected slots:
98 void pathChanged(); 98 void pathChanged();
99 99
100protected: 100protected:
101 bool lock( const QString &path ); 101 bool lock( const QString &path );
102 void unlock( const QString &path ); 102 void unlock( const QString &path );
103 103
104private: 104private:
105 FormatPlugin *mFormat; 105 FormatPlugin *mFormat;
106 106
107#ifndef NO_DIRWATCH 107#ifndef NO_DIRWATCH
108 KDirWatch mDirWatch; 108 KDirWatch mDirWatch;
109#endif 109#endif
110 QString mPath; 110 QString mPath;
111 QString mFormatName; 111 QString mFormatName;
112 QString mLockUniqueName; 112 QString mLockUniqueName;
113}; 113};
114 114
115} 115}
116#endif 116#endif
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 163f2b4..dc5932f 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -1,294 +1,290 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#ifndef _WIN32_ 30#ifndef _WIN32_
31#include <unistd.h> 31#include <unistd.h>
32#endif 32#endif
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qregexp.h> 36#include <qregexp.h>
37#include <qtimer.h> 37#include <qtimer.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <klocale.h> 42#include <klocale.h>
43//US #include <ksavefile.h> 43//US #include <ksavefile.h>
44#include <kstandarddirs.h> 44#include <kstandarddirs.h>
45#include <kmessagebox.h> 45#include <kmessagebox.h>
46 46
47#include "formatfactory.h" 47#include "formatfactory.h"
48 48
49#include "resource.h" 49#include "resource.h"
50#include "resourcefileconfig.h" 50#include "resourcefileconfig.h"
51#include "stdaddressbook.h" 51#include "stdaddressbook.h"
52#define NO_DIRWATCH 52#define NO_DIRWATCH
53#include "resourcefile.h" 53#include "resourcefile.h"
54#include "syncprefwidget.h"
55 54
56//#define ALLOW_LOCKING 55//#define ALLOW_LOCKING
57 56
58 57
59 58
60using namespace KABC; 59using namespace KABC;
61 60
62extern "C" 61extern "C"
63#ifdef _WIN32_ 62#ifdef _WIN32_
64__declspec(dllexport) 63__declspec(dllexport)
65#else 64#else
66{ 65{
67#endif 66#endif
68 67
69//US void *init_kabc_file() 68//US void *init_kabc_file()
70 void *init_microkabc_file() 69 void *init_microkabc_file()
71 { 70 {
72 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); 71 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
73 } 72 }
74#ifndef _WIN32_ 73#ifndef _WIN32_
75} 74}
76#endif 75#endif
77 76
78ResourceFile::ResourceFile( const KConfig *config, bool syncable ) 77ResourceFile::ResourceFile( const KConfig *config )
79 : Resource( config, syncable ) , mFormat( 0 ) 78 : Resource( config ) , mFormat( 0 )
80{ 79{
81 QString fileName, formatName, default_fileName; 80 QString fileName, formatName, default_fileName;
82 81
83 if (syncable == true) 82 default_fileName = StdAddressBook::fileName();
84 default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf";
85 else
86 default_fileName = StdAddressBook::fileName();
87 83
88 KConfig *cfg = (KConfig *)config; 84 KConfig *cfg = (KConfig *)config;
89 if ( cfg ) { 85 if ( cfg ) {
90 fileName = cfg->readEntry( "FileName", default_fileName ); 86 fileName = cfg->readEntry( "FileName", default_fileName );
91 formatName = cfg->readEntry( "FileFormat", "vcard" ); 87 formatName = cfg->readEntry( "FileFormat", "vcard" );
92 } else { 88 } else {
93 fileName = default_fileName; 89 fileName = default_fileName;
94 formatName = "vcard"; 90 formatName = "vcard";
95 } 91 }
96 92
97 init( fileName, formatName ); 93 init( fileName, formatName );
98} 94}
99 95
100ResourceFile::ResourceFile( const QString &fileName, bool syncable , 96ResourceFile::ResourceFile( const QString &fileName ,
101 const QString &formatName ) 97 const QString &formatName )
102 : Resource( 0, syncable ) 98 : Resource( 0 )
103{ 99{
104// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 100// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
105 init( fileName, formatName ); 101 init( fileName, formatName );
106} 102}
107 103
108void ResourceFile::init( const QString &fileName, const QString &formatName ) 104void ResourceFile::init( const QString &fileName, const QString &formatName )
109{ 105{
110 mFormatName = formatName; 106 mFormatName = formatName;
111 107
112 FormatFactory *factory = FormatFactory::self(); 108 FormatFactory *factory = FormatFactory::self();
113 mFormat = factory->format( mFormatName ); 109 mFormat = factory->format( mFormatName );
114 110
115 if ( !mFormat ) { 111 if ( !mFormat ) {
116 mFormatName = "vcard"; 112 mFormatName = "vcard";
117 mFormat = factory->format( mFormatName ); 113 mFormat = factory->format( mFormatName );
118 } 114 }
119 115
120#ifndef NO_DIRWATCH 116#ifndef NO_DIRWATCH
121 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 117 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
122 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 118 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
123 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 119 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
124#endif 120#endif
125 setFileName( fileName ); 121 setFileName( fileName );
126} 122}
127 123
128ResourceFile::~ResourceFile() 124ResourceFile::~ResourceFile()
129{ 125{
130 delete mFormat; 126 delete mFormat;
131 mFormat = 0; 127 mFormat = 0;
132} 128}
133 129
134void ResourceFile::writeConfig( KConfig *config ) 130void ResourceFile::writeConfig( KConfig *config )
135{ 131{
136 132
137 config->setGroup( "Resource_" + identifier() ); 133 config->setGroup( "Resource_" + identifier() );
138 Resource::writeConfig( config ); 134 Resource::writeConfig( config );
139 135
140 config->writeEntry( "FileName", mFileName ); 136 config->writeEntry( "FileName", mFileName );
141 config->writeEntry( "FileFormat", mFormatName ); 137 config->writeEntry( "FileFormat", mFormatName );
142 138
143// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 139// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
144 140
145} 141}
146 142
147Ticket *ResourceFile::requestSaveTicket() 143Ticket *ResourceFile::requestSaveTicket()
148{ 144{
149 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 145 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
150 146
151 if ( !addressBook() ) return 0; 147 if ( !addressBook() ) return 0;
152 148
153#ifdef ALLOW_LOCKING 149#ifdef ALLOW_LOCKING
154 if ( !lock( mFileName ) ) { 150 if ( !lock( mFileName ) ) {
155 qDebug("unablt to lock file "); 151 qDebug("unablt to lock file ");
156 return 0; 152 return 0;
157 } 153 }
158#endif 154#endif
159 return createTicket( this ); 155 return createTicket( this );
160} 156}
161 157
162 158
163bool ResourceFile::doOpen() 159bool ResourceFile::doOpen()
164{ 160{
165 QFile file( mFileName ); 161 QFile file( mFileName );
166 qDebug("ResourceFile::openfile %s ", mFileName.latin1()); 162 qDebug("ResourceFile::openfile %s ", mFileName.latin1());
167 163
168 if ( !file.exists() ) { 164 if ( !file.exists() ) {
169 // try to create the file 165 // try to create the file
170 bool ok = file.open( IO_WriteOnly ); 166 bool ok = file.open( IO_WriteOnly );
171 if ( ok ) 167 if ( ok )
172 file.close(); 168 file.close();
173 169
174 return ok; 170 return ok;
175 } else { 171 } else {
176 if ( !file.open( IO_ReadWrite ) ) 172 if ( !file.open( IO_ReadWrite ) )
177 return false; 173 return false;
178 174
179 if ( file.size() == 0 ) { 175 if ( file.size() == 0 ) {
180 file.close(); 176 file.close();
181 return true; 177 return true;
182 } 178 }
183 179
184 bool ok = mFormat->checkFormat( &file ); 180 bool ok = mFormat->checkFormat( &file );
185 file.close(); 181 file.close();
186 182
187 return ok; 183 return ok;
188 } 184 }
189} 185}
190 186
191void ResourceFile::doClose() 187void ResourceFile::doClose()
192{ 188{
193} 189}
194 190
195bool ResourceFile::load() 191bool ResourceFile::load()
196{ 192{
197 193
198 QFile file( mFileName ); 194 QFile file( mFileName );
199 if ( !file.open( IO_ReadOnly ) ) { 195 if ( !file.open( IO_ReadOnly ) ) {
200 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); 196 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
201 return false; 197 return false;
202 } 198 }
203 199
204// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 200// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
205 201
206 return mFormat->loadAll( addressBook(), this, &file ); 202 return mFormat->loadAll( addressBook(), this, &file );
207} 203}
208 204
209bool ResourceFile::save( Ticket *ticket ) 205bool ResourceFile::save( Ticket *ticket )
210{ 206{
211// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 207// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
212 208
213 209
214 // create backup file 210 // create backup file
215 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 211 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
216 212
217/*US we use a simpler method to create a backupfile 213/*US we use a simpler method to create a backupfile
218 214
219 (void) KSaveFile::backupFile( mFileName, QString::null 215 (void) KSaveFile::backupFile( mFileName, QString::null
220 ,extension ); 216 ,extension );
221 217
222 KSaveFile saveFile( mFileName ); 218 KSaveFile saveFile( mFileName );
223 bool ok = false; 219 bool ok = false;
224 if ( saveFile.status() == 0 && saveFile.file() ) 220 if ( saveFile.status() == 0 && saveFile.file() )
225 { 221 {
226 mFormat->saveAll( addressBook(), this, saveFile.file() ); 222 mFormat->saveAll( addressBook(), this, saveFile.file() );
227 ok = saveFile.close(); 223 ok = saveFile.close();
228 } 224 }
229*/ 225*/
230 226
231//US ToDo: write backupfile 227//US ToDo: write backupfile
232#ifndef NO_DIRWATCH 228#ifndef NO_DIRWATCH
233 mDirWatch.stopScan(); 229 mDirWatch.stopScan();
234#endif 230#endif
235 QFile info; 231 QFile info;
236 info.setName( mFileName ); 232 info.setName( mFileName );
237 bool ok = info.open( IO_WriteOnly ); 233 bool ok = info.open( IO_WriteOnly );
238 if ( ok ) { 234 if ( ok ) {
239 mFormat->saveAll( addressBook(), this, &info ); 235 mFormat->saveAll( addressBook(), this, &info );
240 236
241 info.close(); 237 info.close();
242 ok = true; 238 ok = true;
243 } 239 }
244 else { 240 else {
245 241
246 } 242 }
247 243
248 if ( !ok ) 244 if ( !ok )
249 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 245 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
250#ifndef NO_DIRWATCH 246#ifndef NO_DIRWATCH
251 mDirWatch.startScan(); 247 mDirWatch.startScan();
252#endif 248#endif
253 delete ticket; 249 delete ticket;
254#ifdef ALLOW_LOCKING 250#ifdef ALLOW_LOCKING
255 unlock( mFileName ); 251 unlock( mFileName );
256#endif 252#endif
257 253
258 return ok; 254 return ok;
259} 255}
260 256
261bool ResourceFile::lock( const QString &fileName ) 257bool ResourceFile::lock( const QString &fileName )
262{ 258{
263#ifdef ALLOW_LOCKING 259#ifdef ALLOW_LOCKING
264 260
265 261
266 QString fn = fileName; 262 QString fn = fileName;
267 263
268//US change the implementation how the lockfilename is getting created 264//US change the implementation how the lockfilename is getting created
269//US fn.replace( QRegExp("/"), "_" ); 265//US fn.replace( QRegExp("/"), "_" );
270//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 266//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
271 267
272 KURL url(fn); 268 KURL url(fn);
273 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 269 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
274 270
275 271
276 272
277 if (QFile::exists( lockName )) return false; 273 if (QFile::exists( lockName )) return false;
278 274
279 QString lockUniqueName; 275 QString lockUniqueName;
280 lockUniqueName = fn + KApplication::randomString( 8 ); 276 lockUniqueName = fn + KApplication::randomString( 8 );
281 277
282 url = lockUniqueName; 278 url = lockUniqueName;
283//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 279//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
284 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 280 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
285 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
286 282
287 // Create unique file 283 // Create unique file
288 QFile file( mLockUniqueName ); 284 QFile file( mLockUniqueName );
289 file.open( IO_WriteOnly ); 285 file.open( IO_WriteOnly );
290 file.close(); 286 file.close();
291 287
292 // Create lock file 288 // Create lock file
293 int result = 0; 289 int result = 0;
294#ifndef _WIN32_ 290#ifndef _WIN32_
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h
index 8339340..b4421b2 100644
--- a/kabc/plugins/file/resourcefile.h
+++ b/kabc/plugins/file/resourcefile.h
@@ -1,163 +1,163 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28 28
29#ifndef KABC_RESOURCEFILE_H 29#ifndef KABC_RESOURCEFILE_H
30#define KABC_RESOURCEFILE_H 30#define KABC_RESOURCEFILE_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include <resource.h> 37#include <resource.h>
38 38
39class QTimer; 39class QTimer;
40class FormatPlugin; 40class FormatPlugin;
41 41
42namespace KABC { 42namespace KABC {
43 43
44//US class FormatPlugin; 44//US class FormatPlugin;
45class ResourceConfigWidget; 45class ResourceConfigWidget;
46 46
47/** 47/**
48 @internal 48 @internal
49*/ 49*/
50class ResourceFile : public Resource 50class ResourceFile : public Resource
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 55
56 /** 56 /**
57 Constructor. 57 Constructor.
58 58
59 @param cfg The config object where custom resource settings are stored. 59 @param cfg The config object where custom resource settings are stored.
60 */ 60 */
61 ResourceFile( const KConfig *cfg, bool syncable ); 61 ResourceFile( const KConfig *cfg );
62 62
63 /** 63 /**
64 Construct file resource on file @arg fileName using format @arg formatName. 64 Construct file resource on file @arg fileName using format @arg formatName.
65 */ 65 */
66 ResourceFile( const QString &fileName, bool syncable , const QString &formatName = "vcard" ); 66 ResourceFile( const QString &fileName , const QString &formatName = "vcard" );
67 67
68 /** 68 /**
69 * Destructor. 69 * Destructor.
70 */ 70 */
71 ~ResourceFile(); 71 ~ResourceFile();
72 72
73 /** 73 /**
74 Writes the config back. 74 Writes the config back.
75 */ 75 */
76 virtual void writeConfig( KConfig *cfg ); 76 virtual void writeConfig( KConfig *cfg );
77 77
78 /** 78 /**
79 * Tries to open the file and checks for the proper format. 79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load(). 80 * This method should be called before @ref load().
81 */ 81 */
82 virtual bool doOpen(); 82 virtual bool doOpen();
83 83
84 /** 84 /**
85 * Closes the file again. 85 * Closes the file again.
86 */ 86 */
87 virtual void doClose(); 87 virtual void doClose();
88 88
89 /** 89 /**
90 * Requests a save ticket, that is used by @ref save() 90 * Requests a save ticket, that is used by @ref save()
91 */ 91 */
92 virtual Ticket *requestSaveTicket(); 92 virtual Ticket *requestSaveTicket();
93 93
94 /** 94 /**
95 * Loads all addressees from file to the address book. 95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false. 96 * Returns true if all addressees could be loaded otherwise false.
97 */ 97 */
98 virtual bool load(); 98 virtual bool load();
99 99
100 /** 100 /**
101 * Saves all addresses from address book to file. 101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false. 102 * Returns true if all addressees could be saved otherwise false.
103 * 103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket() 104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */ 105 */
106 virtual bool save( Ticket *ticket ); 106 virtual bool save( Ticket *ticket );
107 107
108 /** 108 /**
109 * Set name of file to be used for saving. 109 * Set name of file to be used for saving.
110 */ 110 */
111 void setFileName( const QString & ); 111 void setFileName( const QString & );
112 112
113 /** 113 /**
114 * Return name of file used for loading and saving the address book. 114 * Return name of file used for loading and saving the address book.
115 */ 115 */
116 QString fileName() const; 116 QString fileName() const;
117 117
118 /** 118 /**
119 Sets a new format by name. 119 Sets a new format by name.
120 */ 120 */
121 void setFormat( const QString &name ); 121 void setFormat( const QString &name );
122 122
123 /** 123 /**
124 Returns the format name. 124 Returns the format name.
125 */ 125 */
126 QString format() const; 126 QString format() const;
127 127
128 /** 128 /**
129 * Remove a addressee from its source. 129 * Remove a addressee from its source.
130 * This method is mainly called by KABC::AddressBook. 130 * This method is mainly called by KABC::AddressBook.
131 */ 131 */
132 virtual void removeAddressee( const Addressee& addr ); 132 virtual void removeAddressee( const Addressee& addr );
133 133
134 /** 134 /**
135 * This method is called by an error handler if the application 135 * This method is called by an error handler if the application
136 * crashed 136 * crashed
137 */ 137 */
138 virtual void cleanUp(); 138 virtual void cleanUp();
139 139
140protected slots: 140protected slots:
141 void fileChanged(); 141 void fileChanged();
142 142
143protected: 143protected:
144 void init( const QString &fileName, const QString &format ); 144 void init( const QString &fileName, const QString &format );
145 145
146 bool lock( const QString &fileName ); 146 bool lock( const QString &fileName );
147 void unlock( const QString &fileName ); 147 void unlock( const QString &fileName );
148 148
149private: 149private:
150 QString mFileName; 150 QString mFileName;
151 QString mFormatName; 151 QString mFormatName;
152 152
153 FormatPlugin *mFormat; 153 FormatPlugin *mFormat;
154 154
155 QString mLockUniqueName; 155 QString mLockUniqueName;
156#ifndef NO_DIRWATCH 156#ifndef NO_DIRWATCH
157 KDirWatch mDirWatch; 157 KDirWatch mDirWatch;
158#endif 158#endif
159}; 159};
160 160
161} 161}
162 162
163#endif 163#endif
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp
index 17f115d..55c43af 100644
--- a/kabc/plugins/ldap/resourceldap.cpp
+++ b/kabc/plugins/ldap/resourceldap.cpp
@@ -1,248 +1,247 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <kdebug.h> 28#include <kdebug.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klineedit.h> 30#include <klineedit.h>
31#include <klocale.h> 31#include <klocale.h>
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kstringhandler.h> 33#include <kstringhandler.h>
34 34
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37#include "resourceldap.h" 37#include "resourceldap.h"
38#include "resourceldapconfig.h" 38#include "resourceldapconfig.h"
39#include "syncprefwidget.h"
40 39
41using namespace KABC; 40using namespace KABC;
42 41
43extern "C" 42extern "C"
44{ 43{
45//US void *init_kabc_ldap() 44//US void *init_kabc_ldap()
46 void *init_microkabc_ldap() 45 void *init_microkabc_ldap()
47 { 46 {
48 return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidgetContainer>(); 47 return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig>();
49 } 48 }
50} 49}
51 50
52void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); 51void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value );
53 52
54 53
55ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) 54ResourceLDAP::ResourceLDAP( const KConfig *config )
56 : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) 55 : Resource( config ), mPort( 389 ), mLdap( 0 )
57{ 56{
58 KConfig *cfg = (KConfig *)config; 57 KConfig *cfg = (KConfig *)config;
59 if ( cfg ) { 58 if ( cfg ) {
60 mUser = cfg->readEntry( "LdapUser" ); 59 mUser = cfg->readEntry( "LdapUser" );
61 mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); 60 mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) );
62 mDn = cfg->readEntry( "LdapDn" ); 61 mDn = cfg->readEntry( "LdapDn" );
63 mHost = cfg->readEntry( "LdapHost" ); 62 mHost = cfg->readEntry( "LdapHost" );
64 mPort = cfg->readNumEntry( "LdapPort", 389 ); 63 mPort = cfg->readNumEntry( "LdapPort", 389 );
65 mFilter = cfg->readEntry( "LdapFilter" ); 64 mFilter = cfg->readEntry( "LdapFilter" );
66 mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); 65 mAnonymous = cfg->readBoolEntry( "LdapAnonymous" );
67 66
68 QStringList attributes = cfg->readListEntry( "LdapAttributes" ); 67 QStringList attributes = cfg->readListEntry( "LdapAttributes" );
69 for ( uint pos = 0; pos < attributes.count(); pos += 2 ) 68 for ( uint pos = 0; pos < attributes.count(); pos += 2 )
70 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); 69 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] );
71 } 70 }
72 71
73 /** 72 /**
74 If you want to add new attributes, append them here, add a 73 If you want to add new attributes, append them here, add a
75 translation string in the ctor of AttributesDialog and 74 translation string in the ctor of AttributesDialog and
76 handle them in the load() method below. 75 handle them in the load() method below.
77 These are the default values from 76 These are the default values from
78 */ 77 */
79 if ( mAttributes.count() == 0 ) { 78 if ( mAttributes.count() == 0 ) {
80 mAttributes.insert( "commonName", "cn" ); 79 mAttributes.insert( "commonName", "cn" );
81 mAttributes.insert( "formattedName", "displayName" ); 80 mAttributes.insert( "formattedName", "displayName" );
82 mAttributes.insert( "familyName", "sn" ); 81 mAttributes.insert( "familyName", "sn" );
83 mAttributes.insert( "givenName", "givenName" ); 82 mAttributes.insert( "givenName", "givenName" );
84 mAttributes.insert( "mail", "mail" ); 83 mAttributes.insert( "mail", "mail" );
85 mAttributes.insert( "mailAlias", "" ); 84 mAttributes.insert( "mailAlias", "" );
86 mAttributes.insert( "phoneNumber", "telephoneNumber" ); 85 mAttributes.insert( "phoneNumber", "telephoneNumber" );
87 mAttributes.insert( "uid", "uid" ); 86 mAttributes.insert( "uid", "uid" );
88 } 87 }
89} 88}
90 89
91void ResourceLDAP::writeConfig( KConfig *config ) 90void ResourceLDAP::writeConfig( KConfig *config )
92{ 91{
93 Resource::writeConfig( config ); 92 Resource::writeConfig( config );
94 93
95 config->writeEntry( "LdapUser", mUser ); 94 config->writeEntry( "LdapUser", mUser );
96 config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); 95 config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) );
97 config->writeEntry( "LdapDn", mDn ); 96 config->writeEntry( "LdapDn", mDn );
98 config->writeEntry( "LdapHost", mHost ); 97 config->writeEntry( "LdapHost", mHost );
99 config->writeEntry( "LdapPort", mPort ); 98 config->writeEntry( "LdapPort", mPort );
100 config->writeEntry( "LdapFilter", mFilter ); 99 config->writeEntry( "LdapFilter", mFilter );
101 config->writeEntry( "LdapAnonymous", mAnonymous ); 100 config->writeEntry( "LdapAnonymous", mAnonymous );
102 101
103 QStringList attributes; 102 QStringList attributes;
104 QMap<QString, QString>::Iterator it; 103 QMap<QString, QString>::Iterator it;
105 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) 104 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it )
106 attributes << it.key() << it.data(); 105 attributes << it.key() << it.data();
107 106
108 config->writeEntry( "LdapAttributes", attributes ); 107 config->writeEntry( "LdapAttributes", attributes );
109} 108}
110 109
111Ticket *ResourceLDAP::requestSaveTicket() 110Ticket *ResourceLDAP::requestSaveTicket()
112{ 111{
113 if ( !addressBook() ) { 112 if ( !addressBook() ) {
114 kdDebug(5700) << "no addressbook" << endl; 113 kdDebug(5700) << "no addressbook" << endl;
115 return 0; 114 return 0;
116 } 115 }
117 116
118 return createTicket( this ); 117 return createTicket( this );
119} 118}
120 119
121bool ResourceLDAP::doOpen() 120bool ResourceLDAP::doOpen()
122{ 121{
123 if ( mLdap ) 122 if ( mLdap )
124 return false; 123 return false;
125 124
126 if ( !mPort ) 125 if ( !mPort )
127 mPort = 389; 126 mPort = 389;
128 127
129 mLdap = ldap_init( mHost.local8Bit(), mPort ); 128 mLdap = ldap_init( mHost.local8Bit(), mPort );
130 if ( !mLdap ) { 129 if ( !mLdap ) {
131 addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); 130 addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) );
132 return false; 131 return false;
133 } 132 }
134 133
135 if ( !mUser.isEmpty() && !mAnonymous ) { 134 if ( !mUser.isEmpty() && !mAnonymous ) {
136 if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { 135 if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) {
137 addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); 136 addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) );
138 return false; 137 return false;
139 } 138 }
140 139
141 kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; 140 kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl;
142 } else { 141 } else {
143 if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { 142 if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) {
144 addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); 143 addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) );
145 return false; 144 return false;
146 } 145 }
147 146
148 kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; 147 kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl;
149 } 148 }
150 149
151 int deref = LDAP_DEREF_ALWAYS; 150 int deref = LDAP_DEREF_ALWAYS;
152 if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { 151 if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) {
153 kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; 152 kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl;
154 return false; 153 return false;
155 } 154 }
156 155
157 if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { 156 if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) {
158 kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; 157 kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl;
159 return false; 158 return false;
160 } 159 }
161 160
162 return true; 161 return true;
163} 162}
164 163
165void ResourceLDAP::doClose() 164void ResourceLDAP::doClose()
166{ 165{
167 if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { 166 if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) {
168 kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; 167 kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl;
169 return; 168 return;
170 } 169 }
171 170
172 mLdap = 0; 171 mLdap = 0;
173} 172}
174 173
175bool ResourceLDAP::load() 174bool ResourceLDAP::load()
176{ 175{
177 LDAPMessage *res; 176 LDAPMessage *res;
178 LDAPMessage *msg; 177 LDAPMessage *msg;
179 BerElement *track; 178 BerElement *track;
180 char *names; 179 char *names;
181 char **values; 180 char **values;
182 181
183 char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; 182 char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ];
184 183
185 QMap<QString, QString>::Iterator it; 184 QMap<QString, QString>::Iterator it;
186 int i = 0; 185 int i = 0;
187 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { 186 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
188 if ( !it.data().isEmpty() ) { 187 if ( !it.data().isEmpty() ) {
189 unsigned int len = it.data().utf8().length(); 188 unsigned int len = it.data().utf8().length();
190 LdapSearchAttr[ i ] = new char[ len+1 ]; 189 LdapSearchAttr[ i ] = new char[ len+1 ];
191 memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); 190 memcpy( LdapSearchAttr[ i ], it.data().utf8(), len );
192 LdapSearchAttr[ i ][ len ] = 0; 191 LdapSearchAttr[ i ][ len ] = 0;
193 ++i; 192 ++i;
194 } 193 }
195 } 194 }
196 LdapSearchAttr[ i ] = 0; 195 LdapSearchAttr[ i ] = 0;
197 196
198 QString filter = mFilter; 197 QString filter = mFilter;
199 if ( filter.isEmpty() ) 198 if ( filter.isEmpty() )
200 filter = "cn=*"; 199 filter = "cn=*";
201 200
202 int result; 201 int result;
203 if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), 202 if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(),
204 LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { 203 LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) {
205 addressBook()->error( i18n( "Unable to search on server '%1': %2" ) 204 addressBook()->error( i18n( "Unable to search on server '%1': %2" )
206 .arg( mHost ) 205 .arg( mHost )
207 .arg( ldap_err2string( result ) ) ); 206 .arg( ldap_err2string( result ) ) );
208 207
209 for ( i = 0; LdapSearchAttr[ i ]; ++i ) 208 for ( i = 0; LdapSearchAttr[ i ]; ++i )
210 delete [] LdapSearchAttr[ i ]; 209 delete [] LdapSearchAttr[ i ];
211 delete [] LdapSearchAttr; 210 delete [] LdapSearchAttr;
212 211
213 return false; 212 return false;
214 } 213 }
215 214
216 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { 215 for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) {
217 Addressee addr; 216 Addressee addr;
218 addr.setResource( this ); 217 addr.setResource( this );
219 for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { 218 for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) {
220 values = ldap_get_values( mLdap, msg, names ); 219 values = ldap_get_values( mLdap, msg, names );
221 for ( int i = 0; i < ldap_count_values( values ); ++i ) { 220 for ( int i = 0; i < ldap_count_values( values ); ++i ) {
222 QString name = QString::fromUtf8( names ).lower(); 221 QString name = QString::fromUtf8( names ).lower();
223 QString value = QString::fromUtf8( values[ i ] ); 222 QString value = QString::fromUtf8( values[ i ] );
224 223
225 if ( name == mAttributes[ "commonName" ].lower() ) { 224 if ( name == mAttributes[ "commonName" ].lower() ) {
226 if ( !addr.formattedName().isEmpty() ) { 225 if ( !addr.formattedName().isEmpty() ) {
227 QString fn = addr.formattedName(); 226 QString fn = addr.formattedName();
228 addr.setNameFromString( value ); 227 addr.setNameFromString( value );
229 addr.setFormattedName( fn ); 228 addr.setFormattedName( fn );
230 } else 229 } else
231 addr.setNameFromString( value ); 230 addr.setNameFromString( value );
232 } else if ( name == mAttributes[ "formattedName" ].lower() ) { 231 } else if ( name == mAttributes[ "formattedName" ].lower() ) {
233 addr.setFormattedName( value ); 232 addr.setFormattedName( value );
234 } else if ( name == mAttributes[ "givenName" ].lower() ) { 233 } else if ( name == mAttributes[ "givenName" ].lower() ) {
235 addr.setGivenName( value ); 234 addr.setGivenName( value );
236 } else if ( name == mAttributes[ "mail" ].lower() ) { 235 } else if ( name == mAttributes[ "mail" ].lower() ) {
237 addr.insertEmail( value, true ); 236 addr.insertEmail( value, true );
238 } else if ( name == mAttributes[ "mailAlias" ].lower() ) { 237 } else if ( name == mAttributes[ "mailAlias" ].lower() ) {
239 addr.insertEmail( value, false ); 238 addr.insertEmail( value, false );
240 } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { 239 } else if ( name == mAttributes[ "phoneNumber" ].lower() ) {
241 PhoneNumber phone; 240 PhoneNumber phone;
242 phone.setNumber( value ); 241 phone.setNumber( value );
243 addr.insertPhoneNumber( phone ); 242 addr.insertPhoneNumber( phone );
244 break; // read only the home number 243 break; // read only the home number
245 } else if ( name == mAttributes[ "familyName" ].lower() ) { 244 } else if ( name == mAttributes[ "familyName" ].lower() ) {
246 addr.setFamilyName( value ); 245 addr.setFamilyName( value );
247 } else if ( name == mAttributes[ "uid" ].lower() ) { 246 } else if ( name == mAttributes[ "uid" ].lower() ) {
248 addr.setUid( value ); 247 addr.setUid( value );
diff --git a/kabc/plugins/ldap/resourceldap.h b/kabc/plugins/ldap/resourceldap.h
index 0aad3c1..0625f30 100644
--- a/kabc/plugins/ldap/resourceldap.h
+++ b/kabc/plugins/ldap/resourceldap.h
@@ -1,99 +1,99 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_RESOURCELDAP_H 28#ifndef KABC_RESOURCELDAP_H
29#define KABC_RESOURCELDAP_H 29#define KABC_RESOURCELDAP_H
30 30
31 31
32#include <lber.h> 32#include <lber.h>
33#include <ldap.h> 33#include <ldap.h>
34 34
35#include "addressbook.h" 35#include "addressbook.h"
36#include "resource.h" 36#include "resource.h"
37 37
38class KConfig; 38class KConfig;
39 39
40namespace KABC { 40namespace KABC {
41 41
42class ResourceLDAP : public Resource 42class ResourceLDAP : public Resource
43{ 43{
44public: 44public:
45 45
46 ResourceLDAP( const KConfig*, bool syncable ); 46 ResourceLDAP( const KConfig* );
47 47
48 virtual void writeConfig( KConfig* ); 48 virtual void writeConfig( KConfig* );
49 49
50 virtual bool doOpen(); 50 virtual bool doOpen();
51 virtual void doClose(); 51 virtual void doClose();
52 52
53 virtual Ticket *requestSaveTicket(); 53 virtual Ticket *requestSaveTicket();
54 54
55 virtual bool load(); 55 virtual bool load();
56 virtual bool save( Ticket * ); 56 virtual bool save( Ticket * );
57 57
58 virtual void removeAddressee( const Addressee& addr ); 58 virtual void removeAddressee( const Addressee& addr );
59 59
60 void setUser( const QString &user ); 60 void setUser( const QString &user );
61 QString user() const; 61 QString user() const;
62 62
63 void setPassword( const QString &password ); 63 void setPassword( const QString &password );
64 QString password() const; 64 QString password() const;
65 65
66 void setDn( const QString &dn ); 66 void setDn( const QString &dn );
67 QString dn() const; 67 QString dn() const;
68 68
69 void setHost( const QString &host ); 69 void setHost( const QString &host );
70 QString host() const; 70 QString host() const;
71 71
72 void setPort( int port ); 72 void setPort( int port );
73 int port() const; 73 int port() const;
74 74
75 void setFilter( const QString &filter ); 75 void setFilter( const QString &filter );
76 QString filter() const; 76 QString filter() const;
77 77
78 void setIsAnonymous( bool value ); 78 void setIsAnonymous( bool value );
79 bool isAnonymous() const; 79 bool isAnonymous() const;
80 80
81 void setAttributes( const QMap<QString, QString> &attributes ); 81 void setAttributes( const QMap<QString, QString> &attributes );
82 QMap<QString, QString> attributes() const; 82 QMap<QString, QString> attributes() const;
83 83
84private: 84private:
85 QString mUser; 85 QString mUser;
86 QString mPassword; 86 QString mPassword;
87 QString mDn; 87 QString mDn;
88 QString mHost; 88 QString mHost;
89 QString mFilter; 89 QString mFilter;
90 int mPort; 90 int mPort;
91 bool mAnonymous; 91 bool mAnonymous;
92 QMap<QString, QString> mAttributes; 92 QMap<QString, QString> mAttributes;
93 93
94 LDAP *mLdap; 94 LDAP *mLdap;
95}; 95};
96 96
97} 97}
98 98
99#endif 99#endif
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index 22237dc..f610b38 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -1,275 +1,274 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45//US #include "formatfactory.h" 45//US #include "formatfactory.h"
46//US #include <qpe/qpeapplication.h> 46//US #include <qpe/qpeapplication.h>
47 47
48#include <opie/ocontactaccess.h> 48#include <opie/ocontactaccess.h>
49#include <opie/ocontactaccessbackend_xml.h> 49#include <opie/ocontactaccessbackend_xml.h>
50 50
51#include "resourceopieconfig.h" 51#include "resourceopieconfig.h"
52#include "stdaddressbook.h" 52#include "stdaddressbook.h"
53#include "syncprefwidget.h"
54 53
55#include "opieconverter.h" 54#include "opieconverter.h"
56 55
57#include "resourceopie.h" 56#include "resourceopie.h"
58 57
59using namespace KABC; 58using namespace KABC;
60extern "C" 59extern "C"
61{ 60{
62 void *init_microkabc_opie() 61 void *init_microkabc_opie()
63 { 62 {
64 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidgetContainer>(); 63 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>();
65 } 64 }
66} 65}
67 66
68ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) 67ResourceOpie::ResourceOpie( const KConfig *config )
69 : Resource( config, syncable ), mAccess(0), mConverter (0) 68 : Resource( config ), mAccess(0), mConverter (0)
70{ 69{
71 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 70 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
72 71
73 KConfig *cfg = (KConfig *)config; 72 KConfig *cfg = (KConfig *)config;
74 if ( cfg ) { 73 if ( cfg ) {
75 fileName = cfg->readEntry( "FileName", fileName ); 74 fileName = cfg->readEntry( "FileName", fileName );
76 75
77 } 76 }
78 77
79 init( fileName ); 78 init( fileName );
80} 79}
81 80
82ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) 81ResourceOpie::ResourceOpie( const QString &fileName )
83 : Resource( 0, syncable ) 82 : Resource( 0 )
84{ 83{
85 init( fileName ); 84 init( fileName );
86} 85}
87 86
88void ResourceOpie::init( const QString &fileName ) 87void ResourceOpie::init( const QString &fileName )
89{ 88{
90 qDebug("ResourceOpie::init()"); 89 qDebug("ResourceOpie::init()");
91 90
92 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 91 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
93 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 92 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
94 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 93 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
95 94
96 setFileName( fileName ); 95 setFileName( fileName );
97} 96}
98 97
99ResourceOpie::~ResourceOpie() 98ResourceOpie::~ResourceOpie()
100{ 99{
101 if (mConverter != 0) 100 if (mConverter != 0)
102 delete mConverter; 101 delete mConverter;
103 102
104 if(mAccess != 0) 103 if(mAccess != 0)
105 delete mAccess; 104 delete mAccess;
106} 105}
107 106
108void ResourceOpie::writeConfig( KConfig *config ) 107void ResourceOpie::writeConfig( KConfig *config )
109{ 108{
110 Resource::writeConfig( config ); 109 Resource::writeConfig( config );
111 110
112 config->writeEntry( "FileName", fileName() ); 111 config->writeEntry( "FileName", fileName() );
113} 112}
114 113
115Ticket *ResourceOpie::requestSaveTicket() 114Ticket *ResourceOpie::requestSaveTicket()
116{ 115{
117 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; 116 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl;
118 117
119 qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); 118 qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1());
120 119
121 if ( !addressBook() ) return 0; 120 if ( !addressBook() ) return 0;
122 121
123 if ( !lock( fileName() ) ) { 122 if ( !lock( fileName() ) ) {
124 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" 123 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '"
125 << fileName() << "'" << endl; 124 << fileName() << "'" << endl;
126 return 0; 125 return 0;
127 } 126 }
128 return createTicket( this ); 127 return createTicket( this );
129} 128}
130 129
131 130
132bool ResourceOpie::doOpen() 131bool ResourceOpie::doOpen()
133{ 132{
134 qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); 133 qDebug("ResourceOpie::doOpen: %s", fileName().latin1());
135 134
136 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); 135 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() );
137 mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); 136 mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false);
138 137
139 if ( !mAccess ) { 138 if ( !mAccess ) {
140 qDebug("Unable to load file() %s", fileName().latin1()); 139 qDebug("Unable to load file() %s", fileName().latin1());
141 return false; 140 return false;
142 } 141 }
143 142
144 mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available 143 mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available
145 144
146 145
147 if (mConverter == 0) 146 if (mConverter == 0)
148 { 147 {
149 mConverter = new OpieConverter(); 148 mConverter = new OpieConverter();
150 bool res = mConverter->init(); 149 bool res = mConverter->init();
151 if ( !res ) 150 if ( !res )
152 { 151 {
153 qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); 152 qDebug("Unable to initialize opie converter. Most likely a problem with the category file");
154 delete mAccess; 153 delete mAccess;
155 mAccess = 0; 154 mAccess = 0;
156 return false; 155 return false;
157 } 156 }
158 } 157 }
159 158
160 159
161 160
162 return true; 161 return true;
163} 162}
164 163
165void ResourceOpie::doClose() 164void ResourceOpie::doClose()
166{ 165{
167 qDebug("ResourceOpie::doClose: %s", fileName().latin1()); 166 qDebug("ResourceOpie::doClose: %s", fileName().latin1());
168 167
169 if(mAccess) 168 if(mAccess)
170 { 169 {
171 delete mAccess; 170 delete mAccess;
172 mAccess = 0; 171 mAccess = 0;
173 } 172 }
174 // it seems so, that deletion of access deletes backend as well 173 // it seems so, that deletion of access deletes backend as well
175 //delete backend; 174 //delete backend;
176 175
177 return; 176 return;
178 177
179} 178}
180 179
181 180
182bool ResourceOpie::load() 181bool ResourceOpie::load()
183{ 182{
184 qDebug("ResourceOpie::load: %s", fileName().latin1()); 183 qDebug("ResourceOpie::load: %s", fileName().latin1());
185 184
186 bool res = false; 185 bool res = false;
187 186
188 OContactAccess::List::Iterator it; 187 OContactAccess::List::Iterator it;
189 OContactAccess::List allList = mAccess->allRecords(); 188 OContactAccess::List allList = mAccess->allRecords();
190 for ( it = allList.begin(); it != allList.end(); ++it ) 189 for ( it = allList.begin(); it != allList.end(); ++it )
191 { 190 {
192 const OContact c = (*it); 191 const OContact c = (*it);
193 192
194 KABC::Addressee addressee; 193 KABC::Addressee addressee;
195 194
196 res = mConverter->opieToAddressee( c, addressee ); 195 res = mConverter->opieToAddressee( c, addressee );
197 196
198 if ( !addressee.isEmpty() && res ) 197 if ( !addressee.isEmpty() && res )
199 { 198 {
200 addressee.setResource( this ); 199 addressee.setResource( this );
201 addressBook()->insertAddressee( addressee ); 200 addressBook()->insertAddressee( addressee );
202 } 201 }
203 202
204 } 203 }
205 204
206 205
207 return true; 206 return true;
208} 207}
209 208
210bool ResourceOpie::save( Ticket *ticket ) 209bool ResourceOpie::save( Ticket *ticket )
211{ 210{
212 qDebug("ResourceOpie::save: %s", fileName().latin1()); 211 qDebug("ResourceOpie::save: %s", fileName().latin1());
213 212
214 mDirWatch.stopScan(); 213 mDirWatch.stopScan();
215 214
216 KABC::AddressBook::Iterator it; 215 KABC::AddressBook::Iterator it;
217 bool res; 216 bool res;
218 217
219 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 218 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
220 OContact c; 219 OContact c;
221 KABC::Addressee addressee = (*it); 220 KABC::Addressee addressee = (*it);
222 221
223 res = mConverter->addresseeToOpie( *it, c ); 222 res = mConverter->addresseeToOpie( *it, c );
224 if (res == true) 223 if (res == true)
225 { 224 {
226 res = mAccess->add(c); 225 res = mAccess->add(c);
227 if (res == false) 226 if (res == false)
228 qDebug("Unable to append Contact %s", c.fullName().latin1()); 227 qDebug("Unable to append Contact %s", c.fullName().latin1());
229 } 228 }
230 else 229 else
231 { 230 {
232 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 231 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
233 } 232 }
234 } 233 }
235 234
236 mAccess->save(); 235 mAccess->save();
237 236
238 mDirWatch.startScan(); 237 mDirWatch.startScan();
239 238
240 delete ticket; 239 delete ticket;
241 unlock( fileName() ); 240 unlock( fileName() );
242 241
243 return true; 242 return true;
244 243
245} 244}
246 245
247bool ResourceOpie::lock( const QString &lockfileName ) 246bool ResourceOpie::lock( const QString &lockfileName )
248{ 247{
249 qDebug("ResourceOpie::lock: %s", fileName().latin1()); 248 qDebug("ResourceOpie::lock: %s", fileName().latin1());
250 249
251 kdDebug(5700) << "ResourceOpie::lock()" << endl; 250 kdDebug(5700) << "ResourceOpie::lock()" << endl;
252 251
253 QString fn = lockfileName; 252 QString fn = lockfileName;
254 253
255 KURL url(fn); 254 KURL url(fn);
256 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 255 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
257 256
258 kdDebug(5700) << "-- lock name: " << lockName << endl; 257 kdDebug(5700) << "-- lock name: " << lockName << endl;
259 258
260 if (QFile::exists( lockName )) 259 if (QFile::exists( lockName ))
261 { 260 {
262 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 261 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
263 return false; 262 return false;
264 } 263 }
265 264
266 QString lockUniqueName; 265 QString lockUniqueName;
267 lockUniqueName = fn + KApplication::randomString( 8 ); 266 lockUniqueName = fn + KApplication::randomString( 8 );
268 267
269 url = lockUniqueName; 268 url = lockUniqueName;
270//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 269//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
271 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 270 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
272 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 271 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
273 272
274 // Create unique file 273 // Create unique file
275 QFile file( mLockUniqueName ); 274 QFile file( mLockUniqueName );
diff --git a/kabc/plugins/opie/resourceopie.h b/kabc/plugins/opie/resourceopie.h
index d5b4ebd..9d05c70 100644
--- a/kabc/plugins/opie/resourceopie.h
+++ b/kabc/plugins/opie/resourceopie.h
@@ -1,146 +1,146 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28 28
29#ifndef KABC_RESOURCEOPIE_H 29#ifndef KABC_RESOURCEOPIE_H
30#define KABC_RESOURCEOPIE_H 30#define KABC_RESOURCEOPIE_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include "resource.h" 37#include "resource.h"
38 38
39 39
40class OContactAccess; 40class OContactAccess;
41 41
42namespace KABC { 42namespace KABC {
43 43
44class ResourceConfigWidget; 44class ResourceConfigWidget;
45class OpieConverter; 45class OpieConverter;
46/** 46/**
47 @internal 47 @internal
48*/ 48*/
49class ResourceOpie : public Resource 49class ResourceOpie : public Resource
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 52
53public: 53public:
54 54
55 /** 55 /**
56 Constructor. 56 Constructor.
57 57
58 @param cfg The config object where custom resource settings are stored. 58 @param cfg The config object where custom resource settings are stored.
59 */ 59 */
60 ResourceOpie( const KConfig *cfg, bool syncable ); 60 ResourceOpie( const KConfig *cfg );
61 61
62 /** 62 /**
63 Construct file resource on file @arg fileName using format @arg formatName. 63 Construct file resource on file @arg fileName using format @arg formatName.
64 */ 64 */
65 ResourceOpie( const QString &fileName, bool syncable ); 65 ResourceOpie( const QString &fileName );
66 66
67 /** 67 /**
68 * Destructor. 68 * Destructor.
69 */ 69 */
70 ~ResourceOpie(); 70 ~ResourceOpie();
71 71
72 /** 72 /**
73 Writes the config back. 73 Writes the config back.
74 */ 74 */
75 virtual void writeConfig( KConfig *cfg ); 75 virtual void writeConfig( KConfig *cfg );
76 76
77 /** 77 /**
78 * Tries to open the file and checks for the proper format. 78 * Tries to open the file and checks for the proper format.
79 * This method should be called before @ref load(). 79 * This method should be called before @ref load().
80 */ 80 */
81 virtual bool doOpen(); 81 virtual bool doOpen();
82 82
83 /** 83 /**
84 * Closes the file again. 84 * Closes the file again.
85 */ 85 */
86 virtual void doClose(); 86 virtual void doClose();
87 87
88 /** 88 /**
89 * Requests a save ticket, that is used by @ref save() 89 * Requests a save ticket, that is used by @ref save()
90 */ 90 */
91 virtual Ticket *requestSaveTicket(); 91 virtual Ticket *requestSaveTicket();
92 92
93 /** 93 /**
94 * Loads all addressees from file to the address book. 94 * Loads all addressees from file to the address book.
95 * Returns true if all addressees could be loaded otherwise false. 95 * Returns true if all addressees could be loaded otherwise false.
96 */ 96 */
97 virtual bool load(); 97 virtual bool load();
98 98
99 /** 99 /**
100 * Saves all addresses from address book to file. 100 * Saves all addresses from address book to file.
101 * Returns true if all addressees could be saved otherwise false. 101 * Returns true if all addressees could be saved otherwise false.
102 * 102 *
103 * @param ticket The ticket returned by @ref requestSaveTicket() 103 * @param ticket The ticket returned by @ref requestSaveTicket()
104 */ 104 */
105 virtual bool save( Ticket *ticket ); 105 virtual bool save( Ticket *ticket );
106 106
107 107
108 /** 108 /**
109 * Remove a addressee from its source. 109 * Remove a addressee from its source.
110 * This method is mainly called by KABC::AddressBook. 110 * This method is mainly called by KABC::AddressBook.
111 */ 111 */
112 virtual void removeAddressee( const Addressee& addr ); 112 virtual void removeAddressee( const Addressee& addr );
113 113
114 /** 114 /**
115 * Set name of file to be used for saving. 115 * Set name of file to be used for saving.
116 */ 116 */
117 virtual void setFileName( const QString & ); 117 virtual void setFileName( const QString & );
118 118
119 /** 119 /**
120 * This method is called by an error handler if the application 120 * This method is called by an error handler if the application
121 * crashed 121 * crashed
122 */ 122 */
123 virtual void cleanUp(); 123 virtual void cleanUp();
124 124
125 125
126protected slots: 126protected slots:
127 void fileChanged(); 127 void fileChanged();
128 128
129protected: 129protected:
130 void init( const QString &fileName ); 130 void init( const QString &fileName );
131 131
132 bool lock( const QString &fileName ); 132 bool lock( const QString &fileName );
133 void unlock( const QString &fileName ); 133 void unlock( const QString &fileName );
134 134
135private: 135private:
136 OContactAccess* mAccess; 136 OContactAccess* mAccess;
137 OpieConverter* mConverter; 137 OpieConverter* mConverter;
138 138
139 QString mLockUniqueName; 139 QString mLockUniqueName;
140 140
141 KDirWatch mDirWatch; 141 KDirWatch mDirWatch;
142}; 142};
143 143
144} 144}
145 145
146#endif 146#endif
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index f9cabcb..deb218b 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -1,266 +1,265 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qdir.h> 31#include <qdir.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qregexp.h> 34#include <qregexp.h>
35//US #include <qtimer.h> 35//US #include <qtimer.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44 44
45#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
46 46
47 47
48#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
49#include "stdaddressbook.h" 49#include "stdaddressbook.h"
50 50
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncprefwidget.h"
53 52
54#include "resourceqtopia.h" 53#include "resourceqtopia.h"
55 54
56using namespace KABC; 55using namespace KABC;
57extern "C" 56extern "C"
58{ 57{
59 void *init_microkabc_qtopia() 58 void *init_microkabc_qtopia()
60 { 59 {
61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); 60 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>();
62 } 61 }
63} 62}
64 63
65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) 64ResourceQtopia::ResourceQtopia( const KConfig *config )
66 : Resource( config, syncable ), mConverter (0) 65 : Resource( config ), mConverter (0)
67{ 66{
68 // we can not choose the filename. Therefore use the default to display 67 // we can not choose the filename. Therefore use the default to display
69 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 68 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
70 init( fileName ); 69 init( fileName );
71} 70}
72 71
73ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) 72ResourceQtopia::ResourceQtopia( const QString &fileName )
74 : Resource( 0, syncable ) 73 : Resource( 0 )
75{ 74{
76 init( fileName ); 75 init( fileName );
77} 76}
78 77
79void ResourceQtopia::init( const QString &fileName ) 78void ResourceQtopia::init( const QString &fileName )
80{ 79{
81 80
82 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 81 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
83 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 82 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
84 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 83 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
85 84
86 setFileName( fileName ); 85 setFileName( fileName );
87} 86}
88 87
89ResourceQtopia::~ResourceQtopia() 88ResourceQtopia::~ResourceQtopia()
90{ 89{
91 if (mConverter != 0) 90 if (mConverter != 0)
92 delete mConverter; 91 delete mConverter;
93 92
94 if(mAccess != 0) 93 if(mAccess != 0)
95 delete mAccess; 94 delete mAccess;
96} 95}
97 96
98void ResourceQtopia::writeConfig( KConfig *config ) 97void ResourceQtopia::writeConfig( KConfig *config )
99{ 98{
100 Resource::writeConfig( config ); 99 Resource::writeConfig( config );
101} 100}
102 101
103Ticket *ResourceQtopia::requestSaveTicket() 102Ticket *ResourceQtopia::requestSaveTicket()
104{ 103{
105 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; 104 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
106 105
107 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); 106 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1());
108 107
109 if ( !addressBook() ) return 0; 108 if ( !addressBook() ) return 0;
110 109
111 if ( !lock( fileName() ) ) { 110 if ( !lock( fileName() ) ) {
112 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 111 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
113 << fileName() << "'" << endl; 112 << fileName() << "'" << endl;
114 return 0; 113 return 0;
115 } 114 }
116 return createTicket( this ); 115 return createTicket( this );
117} 116}
118 117
119 118
120bool ResourceQtopia::doOpen() 119bool ResourceQtopia::doOpen()
121{ 120{
122 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); 121 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
123 122
124 mAccess = new AddressBookAccess(); 123 mAccess = new AddressBookAccess();
125 124
126 if ( !mAccess ) { 125 if ( !mAccess ) {
127 qDebug("Unable to load file() %s", fileName().latin1()); 126 qDebug("Unable to load file() %s", fileName().latin1());
128 return false; 127 return false;
129 } 128 }
130 129
131 130
132 if (mConverter == 0) 131 if (mConverter == 0)
133 { 132 {
134 mConverter = new QtopiaConverter(); 133 mConverter = new QtopiaConverter();
135 bool res = mConverter->init(); 134 bool res = mConverter->init();
136 if ( !res ) 135 if ( !res )
137 { 136 {
138 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 137 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
139 qDebug(msg); 138 qDebug(msg);
140 delete mAccess; 139 delete mAccess;
141 mAccess = 0; 140 mAccess = 0;
142 return false; 141 return false;
143 } 142 }
144 } 143 }
145 144
146 return true; 145 return true;
147} 146}
148 147
149void ResourceQtopia::doClose() 148void ResourceQtopia::doClose()
150{ 149{
151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 150 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
152 151
153 if(mAccess) 152 if(mAccess)
154 { 153 {
155 delete mAccess; 154 delete mAccess;
156 mAccess = 0; 155 mAccess = 0;
157 } 156 }
158 // it seems so, that deletion of access deletes backend as well 157 // it seems so, that deletion of access deletes backend as well
159 //delete backend; 158 //delete backend;
160 159
161 return; 160 return;
162} 161}
163 162
164bool ResourceQtopia::load() 163bool ResourceQtopia::load()
165{ 164{
166 qDebug("ResourceQtopia::load: %s", fileName().latin1()); 165 qDebug("ResourceQtopia::load: %s", fileName().latin1());
167 166
168 AddressBookIterator it(*mAccess); 167 AddressBookIterator it(*mAccess);
169 const PimContact* contact; 168 const PimContact* contact;
170 bool res; 169 bool res;
171 170
172 for (contact=it.toFirst(); it.current(); ++it) 171 for (contact=it.toFirst(); it.current(); ++it)
173 { 172 {
174 contact = it.current(); 173 contact = it.current();
175 174
176 KABC::Addressee addressee; 175 KABC::Addressee addressee;
177 176
178 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 177 res = mConverter->qtopiaToAddressee( (*contact), addressee );
179 178
180 if ( !addressee.isEmpty() && res ) 179 if ( !addressee.isEmpty() && res )
181 { 180 {
182 addressee.setResource( this ); 181 addressee.setResource( this );
183 addressBook()->insertAddressee( addressee ); 182 addressBook()->insertAddressee( addressee );
184 } 183 }
185 } 184 }
186 185
187 return true; 186 return true;
188} 187}
189 188
190bool ResourceQtopia::save( Ticket *ticket ) 189bool ResourceQtopia::save( Ticket *ticket )
191{ 190{
192 qDebug("ResourceQtopia::save: %s", fileName().latin1()); 191 qDebug("ResourceQtopia::save: %s", fileName().latin1());
193 192
194 mDirWatch.stopScan(); 193 mDirWatch.stopScan();
195 194
196 KABC::AddressBook::Iterator it; 195 KABC::AddressBook::Iterator it;
197 bool res; 196 bool res;
198 197
199 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 198 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
200 PimContact c; 199 PimContact c;
201 KABC::Addressee addressee = (*it); 200 KABC::Addressee addressee = (*it);
202 201
203 res = mConverter->addresseeToQtopia( *it, c ); 202 res = mConverter->addresseeToQtopia( *it, c );
204 if (res == true) 203 if (res == true)
205 { 204 {
206 mAccess->addContact(c); 205 mAccess->addContact(c);
207// if (res == false) 206// if (res == false)
208// qDebug("Unable to append Contact %s", c.fullName().latin1()); 207// qDebug("Unable to append Contact %s", c.fullName().latin1());
209 } 208 }
210 else 209 else
211 { 210 {
212 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 211 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
213 } 212 }
214 } 213 }
215 214
216// mAccess->addressBookUpdated(); 215// mAccess->addressBookUpdated();
217 216
218 mDirWatch.startScan(); 217 mDirWatch.startScan();
219 218
220 delete ticket; 219 delete ticket;
221 unlock( fileName() ); 220 unlock( fileName() );
222 221
223 return true; 222 return true;
224} 223}
225 224
226bool ResourceQtopia::lock( const QString &lockfileName ) 225bool ResourceQtopia::lock( const QString &lockfileName )
227{ 226{
228 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 227 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
229 228
230 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 229 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
231 230
232 QString fn = lockfileName; 231 QString fn = lockfileName;
233 232
234 KURL url(fn); 233 KURL url(fn);
235 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 234 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
236 235
237 kdDebug(5700) << "-- lock name: " << lockName << endl; 236 kdDebug(5700) << "-- lock name: " << lockName << endl;
238 237
239 if (QFile::exists( lockName )) 238 if (QFile::exists( lockName ))
240 { 239 {
241 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 240 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
242 return false; 241 return false;
243 } 242 }
244 243
245 QString lockUniqueName; 244 QString lockUniqueName;
246 lockUniqueName = fn + KApplication::randomString( 8 ); 245 lockUniqueName = fn + KApplication::randomString( 8 );
247 246
248 url = lockUniqueName; 247 url = lockUniqueName;
249//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 248//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
250 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 249 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
251 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 250 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
252 251
253 // Create unique file 252 // Create unique file
254 QFile file( mLockUniqueName ); 253 QFile file( mLockUniqueName );
255 file.open( IO_WriteOnly ); 254 file.open( IO_WriteOnly );
256 file.close(); 255 file.close();
257 256
258 // Create lock file 257 // Create lock file
259 int result = 0; 258 int result = 0;
260#ifndef _WIN32_ 259#ifndef _WIN32_
261 result = ::link( QFile::encodeName( mLockUniqueName ), 260 result = ::link( QFile::encodeName( mLockUniqueName ),
262 QFile::encodeName( lockName ) ); 261 QFile::encodeName( lockName ) );
263#endif 262#endif
264 if ( result == 0 ) { 263 if ( result == 0 ) {
265 addressBook()->emitAddressBookLocked(); 264 addressBook()->emitAddressBookLocked();
266 return true; 265 return true;
diff --git a/kabc/plugins/qtopia/resourceqtopia.h b/kabc/plugins/qtopia/resourceqtopia.h
index eace280..ff6350d 100644
--- a/kabc/plugins/qtopia/resourceqtopia.h
+++ b/kabc/plugins/qtopia/resourceqtopia.h
@@ -1,145 +1,145 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28 28
29#ifndef KABC_RESOURCEOPIE_H 29#ifndef KABC_RESOURCEOPIE_H
30#define KABC_RESOURCEOPIE_H 30#define KABC_RESOURCEOPIE_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include "resource.h" 37#include "resource.h"
38 38
39class AddressBookAccess; 39class AddressBookAccess;
40 40
41namespace KABC { 41namespace KABC {
42 42
43//US class FormatPlugin; 43//US class FormatPlugin;
44class ResourceConfigWidget; 44class ResourceConfigWidget;
45class QtopiaConverter; 45class QtopiaConverter;
46 46
47/** 47/**
48 @internal 48 @internal
49*/ 49*/
50class ResourceQtopia : public Resource 50class ResourceQtopia : public Resource
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 55
56 /** 56 /**
57 Constructor. 57 Constructor.
58 58
59 @param cfg The config object where custom resource settings are stored. 59 @param cfg The config object where custom resource settings are stored.
60 */ 60 */
61 ResourceQtopia( const KConfig *cfg, bool syncable ); 61 ResourceQtopia( const KConfig *cfg );
62 62
63 /** 63 /**
64 Construct file resource on file @arg fileName using format @arg formatName. 64 Construct file resource on file @arg fileName using format @arg formatName.
65 */ 65 */
66 ResourceQtopia( const QString &fileName, bool syncable ); 66 ResourceQtopia( const QString &fileName );
67 67
68 /** 68 /**
69 * Destructor. 69 * Destructor.
70 */ 70 */
71 ~ResourceQtopia(); 71 ~ResourceQtopia();
72 72
73 /** 73 /**
74 Writes the config back. 74 Writes the config back.
75 */ 75 */
76 virtual void writeConfig( KConfig *cfg ); 76 virtual void writeConfig( KConfig *cfg );
77 77
78 /** 78 /**
79 * Tries to open the file and checks for the proper format. 79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load(). 80 * This method should be called before @ref load().
81 */ 81 */
82 virtual bool doOpen(); 82 virtual bool doOpen();
83 83
84 /** 84 /**
85 * Closes the file again. 85 * Closes the file again.
86 */ 86 */
87 virtual void doClose(); 87 virtual void doClose();
88 88
89 /** 89 /**
90 * Requests a save ticket, that is used by @ref save() 90 * Requests a save ticket, that is used by @ref save()
91 */ 91 */
92 virtual Ticket *requestSaveTicket(); 92 virtual Ticket *requestSaveTicket();
93 93
94 /** 94 /**
95 * Loads all addressees from file to the address book. 95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false. 96 * Returns true if all addressees could be loaded otherwise false.
97 */ 97 */
98 virtual bool load(); 98 virtual bool load();
99 99
100 /** 100 /**
101 * Saves all addresses from address book to file. 101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false. 102 * Returns true if all addressees could be saved otherwise false.
103 * 103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket() 104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */ 105 */
106 virtual bool save( Ticket *ticket ); 106 virtual bool save( Ticket *ticket );
107 107
108 /** 108 /**
109 * Remove a addressee from its source. 109 * Remove a addressee from its source.
110 * This method is mainly called by KABC::AddressBook. 110 * This method is mainly called by KABC::AddressBook.
111 */ 111 */
112 virtual void removeAddressee( const Addressee& addr ); 112 virtual void removeAddressee( const Addressee& addr );
113 113
114 /** 114 /**
115 * Set name of file to be used for saving. 115 * Set name of file to be used for saving.
116 */ 116 */
117 virtual void setFileName( const QString & ); 117 virtual void setFileName( const QString & );
118 118
119 /** 119 /**
120 * This method is called by an error handler if the application 120 * This method is called by an error handler if the application
121 * crashed 121 * crashed
122 */ 122 */
123 virtual void cleanUp(); 123 virtual void cleanUp();
124 124
125protected slots: 125protected slots:
126 void fileChanged(); 126 void fileChanged();
127 127
128protected: 128protected:
129 void init( const QString &fileName ); 129 void init( const QString &fileName );
130 130
131 bool lock( const QString &fileName ); 131 bool lock( const QString &fileName );
132 void unlock( const QString &fileName ); 132 void unlock( const QString &fileName );
133 133
134private: 134private:
135 AddressBookAccess* mAccess; 135 AddressBookAccess* mAccess;
136 QtopiaConverter* mConverter; 136 QtopiaConverter* mConverter;
137 137
138 QString mLockUniqueName; 138 QString mLockUniqueName;
139 139
140 KDirWatch mDirWatch; 140 KDirWatch mDirWatch;
141}; 141};
142 142
143} 143}
144 144
145#endif 145#endif
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index c013f52..2cdf4bf 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,261 +1,259 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h> 48#include <libkdepim/ksyncprofile.h>
49 49
50#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
52 52
53#include "syncprefwidget.h"
54
55#include "stdaddressbook.h" 53#include "stdaddressbook.h"
56 54
57#include "sharpdtmconverter.h" 55#include "sharpdtmconverter.h"
58//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
59using namespace KABC; 57using namespace KABC;
60extern "C" 58extern "C"
61{ 59{
62 void *init_microkabc_sharpdtm() 60 void *init_microkabc_sharpdtm()
63 { 61 {
64 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); 62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
65 } 63 }
66} 64}
67 65
68ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) 66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
69 : Resource( config, syncable ), mConverter (0) 67 : Resource( config ), mConverter (0)
70{ 68{
71 // we can not choose the filename. Therefore use the default to display 69 // we can not choose the filename. Therefore use the default to display
72 70
73 QString fileName = SlZDataBase::addressbookFileName(); 71 QString fileName = SlZDataBase::addressbookFileName();
74 init( fileName ); 72 init( fileName );
75} 73}
76 74
77ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) 75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable )
78 : Resource( 0, syncable ) 76 : Resource( 0, syncable )
79{ 77{
80 init( fileName ); 78 init( fileName );
81} 79}
82 80
83void ResourceSharpDTM::init( const QString &fileName ) 81void ResourceSharpDTM::init( const QString &fileName )
84{ 82{
85 83
86 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
87 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
88 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
89 87
90 setFileName( fileName ); 88 setFileName( fileName );
91} 89}
92 90
93ResourceSharpDTM::~ResourceSharpDTM() 91ResourceSharpDTM::~ResourceSharpDTM()
94{ 92{
95 if (mConverter != 0) 93 if (mConverter != 0)
96 delete mConverter; 94 delete mConverter;
97 95
98 if(mAccess != 0) 96 if(mAccess != 0)
99 delete mAccess; 97 delete mAccess;
100} 98}
101 99
102void ResourceSharpDTM::writeConfig( KConfig *config ) 100void ResourceSharpDTM::writeConfig( KConfig *config )
103{ 101{
104 Resource::writeConfig( config ); 102 Resource::writeConfig( config );
105} 103}
106 104
107Ticket *ResourceSharpDTM::requestSaveTicket() 105Ticket *ResourceSharpDTM::requestSaveTicket()
108{ 106{
109 107
110 108
111 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 109 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
112 110
113 if ( !addressBook() ) return 0; 111 if ( !addressBook() ) return 0;
114 112
115#ifdef ALLOW_LOCKING 113#ifdef ALLOW_LOCKING
116 if ( !lock( fileName() ) ) { 114 if ( !lock( fileName() ) ) {
117 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); 115 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
118 return 0; 116 return 0;
119 } 117 }
120#endif 118#endif
121 return createTicket( this ); 119 return createTicket( this );
122} 120}
123 121
124 122
125bool ResourceSharpDTM::doOpen() 123bool ResourceSharpDTM::doOpen()
126{ 124{
127 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); 125 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1());
128 126
129 // the last parameter in the SlZDataBase constructor means "readonly" 127 // the last parameter in the SlZDataBase constructor means "readonly"
130 mAccess = new SlZDataBase(fileName(), 128 mAccess = new SlZDataBase(fileName(),
131 SlZDataBase::addressbookItems(), 129 SlZDataBase::addressbookItems(),
132 NULL, false); 130 NULL, false);
133 131
134 if ( !mAccess ) { 132 if ( !mAccess ) {
135 qDebug("Unable to load file() %s", fileName().latin1()); 133 qDebug("Unable to load file() %s", fileName().latin1());
136 return false; 134 return false;
137 } 135 }
138 136
139 if (mConverter == 0) 137 if (mConverter == 0)
140 { 138 {
141 mConverter = new SharpDTMConverter(); 139 mConverter = new SharpDTMConverter();
142 bool res = mConverter->init(); 140 bool res = mConverter->init();
143 if ( !res ) 141 if ( !res )
144 { 142 {
145 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); 143 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
146 144
147 qDebug(msg); 145 qDebug(msg);
148 delete mAccess; 146 delete mAccess;
149 mAccess = 0; 147 mAccess = 0;
150 return false; 148 return false;
151 } 149 }
152 } 150 }
153 151
154 return true; 152 return true;
155} 153}
156 154
157void ResourceSharpDTM::doClose() 155void ResourceSharpDTM::doClose()
158{ 156{
159 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); 157 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
160 158
161 if(mAccess) 159 if(mAccess)
162 { 160 {
163 delete mAccess; 161 delete mAccess;
164 mAccess = 0; 162 mAccess = 0;
165 } 163 }
166 // it seems so, that deletion of access deletes backend as well 164 // it seems so, that deletion of access deletes backend as well
167 //delete backend; 165 //delete backend;
168 166
169 return; 167 return;
170} 168}
171 169
172bool ResourceSharpDTM::load() 170bool ResourceSharpDTM::load()
173{ 171{
174 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 172 qDebug("ResourceSharpDTM::load: %s", fileName().latin1());
175 173
176 bool res = false; 174 bool res = false;
177 175
178 CardId id; 176 CardId id;
179 177
180 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 178 for (bool res=mAccess->first(); res == true; res=mAccess->next())
181 { 179 {
182 id = mAccess->cardId(); 180 id = mAccess->cardId();
183 181
184 KABC::Addressee addressee; 182 KABC::Addressee addressee;
185 183
186 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 184 res = mConverter->sharpToAddressee( id, mAccess, addressee );
187 185
188 if ( !addressee.isEmpty() && res ) 186 if ( !addressee.isEmpty() && res )
189 { 187 {
190 addressee.setResource( this ); 188 addressee.setResource( this );
191 addressBook()->insertAddressee( addressee ); 189 addressBook()->insertAddressee( addressee );
192 } 190 }
193 } 191 }
194 192
195 return true; 193 return true;
196} 194}
197 195
198bool ResourceSharpDTM::save( Ticket *ticket ) 196bool ResourceSharpDTM::save( Ticket *ticket )
199{ 197{
200 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 198 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
201 199
202 mDirWatch.stopScan(); 200 mDirWatch.stopScan();
203 201
204 KABC::AddressBook::Iterator it; 202 KABC::AddressBook::Iterator it;
205 bool res; 203 bool res;
206 KABC::Addressee::List changedAddressees; 204 KABC::Addressee::List changedAddressees;
207 typedef QMap<int,QString> AddresseeMap; 205 typedef QMap<int,QString> AddresseeMap;
208 AddresseeMap map; 206 AddresseeMap map;
209 CardId id ; 207 CardId id ;
210 208
211 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 209 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
212 210
213 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 211 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
214 QString uid = (*it).originalExternalUID(); 212 QString uid = (*it).originalExternalUID();
215 bool res; 213 bool res;
216 if ( uid.isEmpty() ) 214 if ( uid.isEmpty() )
217 id = 0; 215 id = 0;
218 else 216 else
219 id = uid.toUInt(); 217 id = uid.toUInt();
220 KABC::Addressee addressee = (*it); 218 KABC::Addressee addressee = (*it);
221 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 219 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
222 res = mAccess->startEditCard(id); 220 res = mAccess->startEditCard(id);
223 if (res == true) 221 if (res == true)
224 { 222 {
225 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 223 res = mConverter->addresseeToSharp( (*it), mAccess, id );
226 if (res == true) 224 if (res == true)
227 { 225 {
228 res = mAccess->finishEditCard(&id); 226 res = mAccess->finishEditCard(&id);
229 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 227 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
230 //(*it).setExternalUID( QString::number( id ) ); 228 //(*it).setExternalUID( QString::number( id ) );
231 //(*it).setOriginalExternalUID( QString::number( id ) ); 229 //(*it).setOriginalExternalUID( QString::number( id ) );
232 map.insert(id,(*it).uid()); 230 map.insert(id,(*it).uid());
233 if (res == false) 231 if (res == false)
234 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 232 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
235 233
236 } 234 }
237 else 235 else
238 { 236 {
239 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 237 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
240 mAccess->cancelEditCard(); 238 mAccess->cancelEditCard();
241 } 239 }
242 } 240 }
243 241
244 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 242 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
245 res = mAccess->deleteCard(&id); 243 res = mAccess->deleteCard(&id);
246 if ( !res ) 244 if ( !res )
247 qDebug("delete error "); 245 qDebug("delete error ");
248 246
249 247
250 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 248 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
251 //changed 249 //changed
252 res = mAccess->startEditCard(id); 250 res = mAccess->startEditCard(id);
253 if (res == true) 251 if (res == true)
254 { 252 {
255 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 253 res = mConverter->addresseeToSharp( (*it), mAccess, id );
256 if (res == true) 254 if (res == true)
257 { 255 {
258 res = mAccess->finishEditCard(&id); 256 res = mAccess->finishEditCard(&id);
259 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); 257 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
260 map.insert(id,(*it).uid()); 258 map.insert(id,(*it).uid());
261 if (res == false) 259 if (res == false)
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.h b/kabc/plugins/sharpdtm/resourcesharpdtm.h
index f386e69..64d06f9 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.h
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.h
@@ -1,146 +1,146 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28 28
29#ifndef KABC_RESOURCESHARPDTM_H 29#ifndef KABC_RESOURCESHARPDTM_H
30#define KABC_RESOURCESHARPDTM_H 30#define KABC_RESOURCESHARPDTM_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include "resource.h" 37#include "resource.h"
38 38
39 39
40class SlZDataBase; 40class SlZDataBase;
41 41
42namespace KABC { 42namespace KABC {
43 43
44class ResourceConfigWidget; 44class ResourceConfigWidget;
45class SharpDTMConverter; 45class SharpDTMConverter;
46 46
47/** 47/**
48 @internal 48 @internal
49*/ 49*/
50class ResourceSharpDTM : public Resource 50class ResourceSharpDTM : public Resource
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 55
56 /** 56 /**
57 Constructor. 57 Constructor.
58 58
59 @param cfg The config object where custom resource settings are stored. 59 @param cfg The config object where custom resource settings are stored.
60 */ 60 */
61 ResourceSharpDTM( const KConfig *cfg, bool syncable ); 61 ResourceSharpDTM( const KConfig *cfg );
62 62
63 /** 63 /**
64 Construct file resource on file @arg fileName using format @arg formatName. 64 Construct file resource on file @arg fileName using format @arg formatName.
65 */ 65 */
66 ResourceSharpDTM( const QString &fileName, bool syncable ); 66 ResourceSharpDTM( const QString &fileName );
67 67
68 /** 68 /**
69 * Destructor. 69 * Destructor.
70 */ 70 */
71 ~ResourceSharpDTM(); 71 ~ResourceSharpDTM();
72 72
73 /** 73 /**
74 Writes the config back. 74 Writes the config back.
75 */ 75 */
76 virtual void writeConfig( KConfig *cfg ); 76 virtual void writeConfig( KConfig *cfg );
77 77
78 /** 78 /**
79 * Tries to open the file and checks for the proper format. 79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load(). 80 * This method should be called before @ref load().
81 */ 81 */
82 virtual bool doOpen(); 82 virtual bool doOpen();
83 83
84 /** 84 /**
85 * Closes the file again. 85 * Closes the file again.
86 */ 86 */
87 virtual void doClose(); 87 virtual void doClose();
88 88
89 /** 89 /**
90 * Requests a save ticket, that is used by @ref save() 90 * Requests a save ticket, that is used by @ref save()
91 */ 91 */
92 virtual Ticket *requestSaveTicket(); 92 virtual Ticket *requestSaveTicket();
93 93
94 /** 94 /**
95 * Loads all addressees from file to the address book. 95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false. 96 * Returns true if all addressees could be loaded otherwise false.
97 */ 97 */
98 virtual bool load(); 98 virtual bool load();
99 99
100 /** 100 /**
101 * Saves all addresses from address book to file. 101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false. 102 * Returns true if all addressees could be saved otherwise false.
103 * 103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket() 104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */ 105 */
106 virtual bool save( Ticket *ticket ); 106 virtual bool save( Ticket *ticket );
107 107
108 /** 108 /**
109 * Remove a addressee from its source. 109 * Remove a addressee from its source.
110 * This method is mainly called by KABC::AddressBook. 110 * This method is mainly called by KABC::AddressBook.
111 */ 111 */
112 virtual void removeAddressee( const Addressee& addr ); 112 virtual void removeAddressee( const Addressee& addr );
113 113
114 /** 114 /**
115 * Set name of file to be used for saving. 115 * Set name of file to be used for saving.
116 */ 116 */
117 virtual void setFileName( const QString & ); 117 virtual void setFileName( const QString & );
118 118
119 /** 119 /**
120 * This method is called by an error handler if the application 120 * This method is called by an error handler if the application
121 * crashed 121 * crashed
122 */ 122 */
123 virtual void cleanUp(); 123 virtual void cleanUp();
124 124
125 125
126protected slots: 126protected slots:
127 void fileChanged(); 127 void fileChanged();
128 128
129protected: 129protected:
130 void init( const QString &fileName ); 130 void init( const QString &fileName );
131 131
132 bool lock( const QString &fileName ); 132 bool lock( const QString &fileName );
133 void unlock( const QString &fileName ); 133 void unlock( const QString &fileName );
134 134
135private: 135private:
136 SlZDataBase* mAccess; 136 SlZDataBase* mAccess;
137 SharpDTMConverter* mConverter; 137 SharpDTMConverter* mConverter;
138 138
139 QString mLockUniqueName; 139 QString mLockUniqueName;
140 140
141 KDirWatch mDirWatch; 141 KDirWatch mDirWatch;
142}; 142};
143 143
144} 144}
145 145
146#endif 146#endif