-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 363 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.h | 115 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedirconfig.cpp | 123 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedirconfig.h | 61 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 389 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.h | 162 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefileconfig.cpp | 144 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefileconfig.h | 65 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.cpp | 444 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.h | 99 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldapconfig.cpp | 254 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldapconfig.h | 100 |
12 files changed, 2319 insertions, 0 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp new file mode 100644 index 0000000..f354a9e --- a/dev/null +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -0,0 +1,363 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | |||
29 | #include <sys/types.h> | ||
30 | #include <sys/stat.h> | ||
31 | #ifndef _WIN32_ | ||
32 | #include <unistd.h> | ||
33 | #endif | ||
34 | |||
35 | #include <qregexp.h> | ||
36 | #include <qtimer.h> | ||
37 | #include <qwidget.h> | ||
38 | |||
39 | #include <kapplication.h> | ||
40 | #include <kconfig.h> | ||
41 | #include <kdebug.h> | ||
42 | //US #include <kgenericfactory.h> | ||
43 | #include <kglobal.h> | ||
44 | #include <klocale.h> | ||
45 | #include <kstandarddirs.h> | ||
46 | #include <kurlrequester.h> | ||
47 | |||
48 | #include "addressbook.h" | ||
49 | |||
50 | //US #include "formatfactory.h" | ||
51 | |||
52 | #include "resourcedirconfig.h" | ||
53 | #include "stdaddressbook.h" | ||
54 | |||
55 | //US | ||
56 | #include <qdir.h> | ||
57 | #include <formats/vcardformatplugin2.h> | ||
58 | #include <formats/binaryformat.h> | ||
59 | |||
60 | #include "resourcedir.h" | ||
61 | |||
62 | using namespace KABC; | ||
63 | |||
64 | extern "C" | ||
65 | { | ||
66 | void *init_kabc_dir() | ||
67 | { | ||
68 | qDebug("resourcedir.cpp : init_kabc_dir has to be changed"); | ||
69 | //US return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); | ||
70 | return 0; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | |||
75 | ResourceDir::ResourceDir( const KConfig *config ) | ||
76 | : Resource( config ) | ||
77 | { | ||
78 | QString path; | ||
79 | |||
80 | KConfig *cfg = (KConfig *)config; | ||
81 | if ( cfg ) { | ||
82 | //US path = config->readEntry( "FilePath" ); | ||
83 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); | ||
84 | //US mFormatName = config->readEntry( "FileFormat" ); | ||
85 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); | ||
86 | } else { | ||
87 | path = StdAddressBook::directoryName(); | ||
88 | mFormatName = "vcard"; | ||
89 | } | ||
90 | |||
91 | |||
92 | /*US FormatFactory *factory = FormatFactory::self(); | ||
93 | mFormat = factory->format( mFormatName ); | ||
94 | |||
95 | if ( !mFormat ) { | ||
96 | mFormatName = "vcard"; | ||
97 | mFormat = factory->format( mFormatName ); | ||
98 | } | ||
99 | */ | ||
100 | |||
101 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); | ||
102 | if (mFormatName == "vcard") | ||
103 | mFormat = new VCardFormatPlugin2(); | ||
104 | else if (mFormatName == "binary") | ||
105 | mFormat = new BinaryFormat(); | ||
106 | else | ||
107 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); | ||
108 | |||
109 | |||
110 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | ||
111 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); | ||
112 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); | ||
113 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); | ||
114 | */ | ||
115 | |||
116 | setPath( path ); | ||
117 | } | ||
118 | |||
119 | ResourceDir::~ResourceDir() | ||
120 | { | ||
121 | delete mFormat; | ||
122 | mFormat = 0; | ||
123 | } | ||
124 | |||
125 | void ResourceDir::writeConfig( KConfig *config ) | ||
126 | { | ||
127 | Resource::writeConfig( config ); | ||
128 | |||
129 | config->writeEntry( "FilePath", mPath ); | ||
130 | config->writeEntry( "FileFormat", mFormatName ); | ||
131 | } | ||
132 | |||
133 | Ticket *ResourceDir::requestSaveTicket() | ||
134 | { | ||
135 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; | ||
136 | |||
137 | if ( !addressBook() ) return 0; | ||
138 | |||
139 | if ( !lock( mPath ) ) { | ||
140 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" | ||
141 | << mPath << "'" << endl; | ||
142 | return 0; | ||
143 | } | ||
144 | return createTicket( this ); | ||
145 | } | ||
146 | |||
147 | |||
148 | bool ResourceDir::doOpen() | ||
149 | { | ||
150 | QDir dir( mPath ); | ||
151 | if ( !dir.exists() ) { // no directory available | ||
152 | return dir.mkdir( dir.path() ); | ||
153 | } else { | ||
154 | QString testName = dir.entryList( QDir::Files )[0]; | ||
155 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory | ||
156 | return true; | ||
157 | |||
158 | QFile file( mPath + "/" + testName ); | ||
159 | if ( file.open( IO_ReadOnly ) ) | ||
160 | return true; | ||
161 | |||
162 | if ( file.size() == 0 ) | ||
163 | return true; | ||
164 | |||
165 | bool ok = mFormat->checkFormat( &file ); | ||
166 | file.close(); | ||
167 | return ok; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | void ResourceDir::doClose() | ||
172 | { | ||
173 | } | ||
174 | |||
175 | bool ResourceDir::load() | ||
176 | { | ||
177 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; | ||
178 | |||
179 | QDir dir( mPath ); | ||
180 | QStringList files = dir.entryList( QDir::Files ); | ||
181 | |||
182 | QStringList::Iterator it; | ||
183 | bool ok = true; | ||
184 | for ( it = files.begin(); it != files.end(); ++it ) { | ||
185 | QFile file( mPath + "/" + (*it) ); | ||
186 | |||
187 | if ( !file.open( IO_ReadOnly ) ) { | ||
188 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); | ||
189 | ok = false; | ||
190 | continue; | ||
191 | } | ||
192 | |||
193 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) | ||
194 | ok = false; | ||
195 | |||
196 | file.close(); | ||
197 | } | ||
198 | |||
199 | return ok; | ||
200 | } | ||
201 | |||
202 | bool ResourceDir::save( Ticket *ticket ) | ||
203 | { | ||
204 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; | ||
205 | |||
206 | AddressBook::Iterator it; | ||
207 | bool ok = true; | ||
208 | |||
209 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | ||
210 | if ( (*it).resource() != this || !(*it).changed() ) | ||
211 | continue; | ||
212 | |||
213 | QFile file( mPath + "/" + (*it).uid() ); | ||
214 | if ( !file.open( IO_WriteOnly ) ) { | ||
215 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); | ||
216 | continue; | ||
217 | } | ||
218 | |||
219 | mFormat->save( *it, &file ); | ||
220 | |||
221 | // mark as unchanged | ||
222 | (*it).setChanged( false ); | ||
223 | |||
224 | file.close(); | ||
225 | } | ||
226 | |||
227 | delete ticket; | ||
228 | unlock( mPath ); | ||
229 | |||
230 | return ok; | ||
231 | } | ||
232 | |||
233 | bool ResourceDir::lock( const QString &path ) | ||
234 | { | ||
235 | kdDebug(5700) << "ResourceDir::lock()" << endl; | ||
236 | |||
237 | QString p = path; | ||
238 | //US change the implementation how the lockfilename is getting created | ||
239 | //US p.replace( QRegExp("/"), "_" ); | ||
240 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); | ||
241 | KURL url(p); | ||
242 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
243 | |||
244 | |||
245 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
246 | |||
247 | if ( QFile::exists( lockName ) ) return false; | ||
248 | |||
249 | QString lockUniqueName; | ||
250 | lockUniqueName = p + KApplication::randomString( 8 ); | ||
251 | |||
252 | url = lockUniqueName; | ||
253 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | ||
254 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | ||
255 | |||
256 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | ||
257 | |||
258 | // Create unique file | ||
259 | QFile file( mLockUniqueName ); | ||
260 | file.open( IO_WriteOnly ); | ||
261 | file.close(); | ||
262 | |||
263 | // Create lock file | ||
264 | #ifdef _WIN32_ | ||
265 | int result = 0; | ||
266 | qDebug("WARNING: ResourceDir::lock cannot link "); | ||
267 | #else | ||
268 | int result = ::link( QFile::encodeName( mLockUniqueName ), | ||
269 | QFile::encodeName( lockName ) ); | ||
270 | #endif | ||
271 | if ( result == 0 ) { | ||
272 | addressBook()->emitAddressBookLocked(); | ||
273 | return true; | ||
274 | } | ||
275 | |||
276 | // TODO: check stat | ||
277 | |||
278 | return false; | ||
279 | } | ||
280 | |||
281 | void ResourceDir::unlock( const QString &path ) | ||
282 | { | ||
283 | QString p = path; | ||
284 | //US change the implementation how the lockfilename is getting created | ||
285 | //US p.replace( QRegExp( "/" ), "_" ); | ||
286 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); | ||
287 | KURL url(p); | ||
288 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
289 | |||
290 | ::unlink( QFile::encodeName( lockName ) ); | ||
291 | QFile::remove( mLockUniqueName ); | ||
292 | addressBook()->emitAddressBookUnlocked(); | ||
293 | } | ||
294 | |||
295 | void ResourceDir::setPath( const QString &path ) | ||
296 | { | ||
297 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
298 | mDirWatch.stopScan(); | ||
299 | mDirWatch.removeDir( mPath ); | ||
300 | */ | ||
301 | mPath = path; | ||
302 | |||
303 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
304 | mDirWatch.addDir( mPath, true ); | ||
305 | mDirWatch.startScan(); | ||
306 | */ | ||
307 | |||
308 | //US simulate KDirWatch event | ||
309 | pathChanged(); | ||
310 | |||
311 | } | ||
312 | |||
313 | QString ResourceDir::path() const | ||
314 | { | ||
315 | return mPath; | ||
316 | } | ||
317 | |||
318 | void ResourceDir::setFormat( const QString &format ) | ||
319 | { | ||
320 | mFormatName = format; | ||
321 | |||
322 | if ( mFormat ) | ||
323 | delete mFormat; | ||
324 | |||
325 | //US FormatFactory *factory = FormatFactory::self(); | ||
326 | //US mFormat = factory->format( mFormatName ); | ||
327 | |||
328 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); | ||
329 | if (mFormatName == "vcard") | ||
330 | mFormat = new VCardFormatPlugin2(); | ||
331 | else if (mFormatName == "binary") | ||
332 | mFormat = new BinaryFormat(); | ||
333 | else | ||
334 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); | ||
335 | |||
336 | |||
337 | } | ||
338 | |||
339 | QString ResourceDir::format() const | ||
340 | { | ||
341 | return mFormatName; | ||
342 | } | ||
343 | |||
344 | void ResourceDir::pathChanged() | ||
345 | { | ||
346 | if ( !addressBook() ) | ||
347 | return; | ||
348 | |||
349 | load(); | ||
350 | addressBook()->emitAddressBookChanged(); | ||
351 | } | ||
352 | |||
353 | void ResourceDir::removeAddressee( const Addressee& addr ) | ||
354 | { | ||
355 | QFile::remove( mPath + "/" + addr.uid() ); | ||
356 | } | ||
357 | |||
358 | void ResourceDir::cleanUp() | ||
359 | { | ||
360 | unlock( mPath ); | ||
361 | } | ||
362 | |||
363 | //US #include "resourcedir.moc" | ||
diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h new file mode 100644 index 0000000..6e35695 --- a/dev/null +++ b/kabc/plugins/dir/resourcedir.h | |||
@@ -0,0 +1,115 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #ifndef KABC_RESOURCEDIR_H | ||
29 | #define KABC_RESOURCEDIR_H | ||
30 | |||
31 | #include <kconfig.h> | ||
32 | #include <kdirwatch.h> | ||
33 | |||
34 | #include <sys/types.h> | ||
35 | |||
36 | #include "resource.h" | ||
37 | |||
38 | class QTimer; | ||
39 | |||
40 | namespace KABC { | ||
41 | |||
42 | class FormatPlugin; | ||
43 | |||
44 | /** | ||
45 | @internal | ||
46 | */ | ||
47 | class ResourceDir : public Resource | ||
48 | { | ||
49 | Q_OBJECT | ||
50 | |||
51 | public: | ||
52 | ResourceDir( const KConfig* ); | ||
53 | ~ResourceDir(); | ||
54 | |||
55 | virtual void writeConfig( KConfig* ); | ||
56 | |||
57 | virtual bool doOpen(); | ||
58 | virtual void doClose(); | ||
59 | |||
60 | virtual Ticket *requestSaveTicket(); | ||
61 | |||
62 | virtual bool load(); | ||
63 | virtual bool save( Ticket * ); | ||
64 | |||
65 | /** | ||
66 | * Set path to be used for saving. | ||
67 | */ | ||
68 | void setPath( const QString & ); | ||
69 | |||
70 | /** | ||
71 | * Return path used for loading and saving the address book. | ||
72 | */ | ||
73 | QString path() const; | ||
74 | |||
75 | /** | ||
76 | * Set the format by name. | ||
77 | */ | ||
78 | void setFormat( const QString &format ); | ||
79 | |||
80 | /** | ||
81 | * Returns the format name. | ||
82 | */ | ||
83 | QString format() const; | ||
84 | |||
85 | /** | ||
86 | * Remove a addressee from its source. | ||
87 | * This method is mainly called by KABC::AddressBook. | ||
88 | */ | ||
89 | virtual void removeAddressee( const Addressee& addr ); | ||
90 | |||
91 | /** | ||
92 | * This method is called by an error handler if the application | ||
93 | * crashed | ||
94 | */ | ||
95 | virtual void cleanUp(); | ||
96 | |||
97 | protected slots: | ||
98 | void pathChanged(); | ||
99 | |||
100 | protected: | ||
101 | bool lock( const QString &path ); | ||
102 | void unlock( const QString &path ); | ||
103 | |||
104 | private: | ||
105 | FormatPlugin *mFormat; | ||
106 | |||
107 | KDirWatch mDirWatch; | ||
108 | |||
109 | QString mPath; | ||
110 | QString mFormatName; | ||
111 | QString mLockUniqueName; | ||
112 | }; | ||
113 | |||
114 | } | ||
115 | #endif | ||
diff --git a/kabc/plugins/dir/resourcedirconfig.cpp b/kabc/plugins/dir/resourcedirconfig.cpp new file mode 100644 index 0000000..98d18fe --- a/dev/null +++ b/kabc/plugins/dir/resourcedirconfig.cpp | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <qlabel.h> | ||
29 | #include <qlayout.h> | ||
30 | |||
31 | #include <kdebug.h> | ||
32 | #include <klocale.h> | ||
33 | #include <kstandarddirs.h> | ||
34 | #include <kdialog.h> | ||
35 | |||
36 | //US #include "formatfactory.h" | ||
37 | #include "resourcedir.h" | ||
38 | #include "stdaddressbook.h" | ||
39 | |||
40 | #include "resourcedirconfig.h" | ||
41 | |||
42 | using namespace KABC; | ||
43 | |||
44 | ResourceDirConfig::ResourceDirConfig( QWidget* parent, const char* name ) | ||
45 | : KRES::ConfigWidget( parent, name ) | ||
46 | { | ||
47 | QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0, | ||
48 | KDialog::spacingHint() ); | ||
49 | |||
50 | QLabel *label = new QLabel( i18n( "Format:" ), this ); | ||
51 | mFormatBox = new KComboBox( this ); | ||
52 | |||
53 | mainLayout->addWidget( label, 0, 0 ); | ||
54 | mainLayout->addWidget( mFormatBox, 0, 1 ); | ||
55 | |||
56 | label = new QLabel( i18n( "Location:" ), this ); | ||
57 | mFileNameEdit = new KURLRequester( this ); | ||
58 | //US mFileNameEdit->setMode( KFile::Directory ); | ||
59 | |||
60 | mainLayout->addWidget( label, 1, 0 ); | ||
61 | mainLayout->addWidget( mFileNameEdit, 1, 1 ); | ||
62 | |||
63 | /*US lets hardcode the formats instead of using a factory | ||
64 | FormatFactory *factory = FormatFactory::self(); | ||
65 | QStringList formats = factory->formats(); | ||
66 | QStringList::Iterator it; | ||
67 | for ( it = formats.begin(); it != formats.end(); ++it ) { | ||
68 | FormatInfo *info = factory->info( *it ); | ||
69 | if ( info ) { | ||
70 | mFormatTypes << (*it); | ||
71 | mFormatBox->insertItem( info->nameLabel ); | ||
72 | } | ||
73 | } | ||
74 | */ | ||
75 | mFormatTypes << "vcard"; | ||
76 | mFormatTypes << "binary"; | ||
77 | mFormatBox->insertItem( "vcard" ); | ||
78 | mFormatBox->insertItem( "binary" ); | ||
79 | |||
80 | |||
81 | mInEditMode = false; | ||
82 | } | ||
83 | |||
84 | void ResourceDirConfig::setEditMode( bool value ) | ||
85 | { | ||
86 | mFormatBox->setEnabled( !value ); | ||
87 | mInEditMode = value; | ||
88 | } | ||
89 | |||
90 | void ResourceDirConfig::loadSettings( KRES::Resource *res ) | ||
91 | { | ||
92 | //US ResourceDir *resource = dynamic_cast<ResourceDir*>( res ); | ||
93 | ResourceDir *resource = (ResourceDir*)( res ); | ||
94 | |||
95 | if ( !resource ) { | ||
96 | kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl; | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) ); | ||
101 | |||
102 | mFileNameEdit->setURL( resource->path() ); | ||
103 | if ( mFileNameEdit->url().isEmpty() ) | ||
104 | mFileNameEdit->setURL( KABC::StdAddressBook::directoryName() ); | ||
105 | } | ||
106 | |||
107 | void ResourceDirConfig::saveSettings( KRES::Resource *res ) | ||
108 | { | ||
109 | //US ResourceDir *resource = dynamic_cast<ResourceDir*>( res ); | ||
110 | ResourceDir *resource = (ResourceDir*)( res ); | ||
111 | |||
112 | if ( !resource ) { | ||
113 | kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl; | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | if ( mInEditMode ) | ||
118 | resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] ); | ||
119 | |||
120 | resource->setPath( mFileNameEdit->url() ); | ||
121 | } | ||
122 | |||
123 | //US #include "resourcedirconfig.moc" | ||
diff --git a/kabc/plugins/dir/resourcedirconfig.h b/kabc/plugins/dir/resourcedirconfig.h new file mode 100644 index 0000000..5af38a5 --- a/dev/null +++ b/kabc/plugins/dir/resourcedirconfig.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #ifndef RESOURCEDIRCONFIG_H | ||
29 | #define RESOURCEDIRCONFIG_H | ||
30 | |||
31 | #include <kcombobox.h> | ||
32 | #include <kurlrequester.h> | ||
33 | |||
34 | #include <kresources/configwidget.h> | ||
35 | |||
36 | namespace KABC { | ||
37 | |||
38 | class ResourceDirConfig : public KRES::ConfigWidget | ||
39 | { | ||
40 | Q_OBJECT | ||
41 | |||
42 | public: | ||
43 | ResourceDirConfig( QWidget* parent = 0, const char* name = 0 ); | ||
44 | |||
45 | void setEditMode( bool value ); | ||
46 | |||
47 | public slots: | ||
48 | void loadSettings( KRES::Resource* ); | ||
49 | void saveSettings( KRES::Resource* ); | ||
50 | |||
51 | private: | ||
52 | KComboBox* mFormatBox; | ||
53 | KURLRequester* mFileNameEdit; | ||
54 | |||
55 | QStringList mFormatTypes; | ||
56 | |||
57 | bool mInEditMode; | ||
58 | }; | ||
59 | |||
60 | } | ||
61 | #endif | ||
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp new file mode 100644 index 0000000..d30ed2f --- a/dev/null +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -0,0 +1,389 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <sys/types.h> | ||
29 | #include <sys/stat.h> | ||
30 | #ifndef _WIN32_ | ||
31 | #include <unistd.h> | ||
32 | #endif | ||
33 | |||
34 | #include <qfile.h> | ||
35 | #include <qfileinfo.h> | ||
36 | #include <qregexp.h> | ||
37 | #include <qtimer.h> | ||
38 | |||
39 | #include <kapplication.h> | ||
40 | #include <kconfig.h> | ||
41 | #include <kdebug.h> | ||
42 | #include <klocale.h> | ||
43 | //US #include <ksavefile.h> | ||
44 | #include <kstandarddirs.h> | ||
45 | |||
46 | //US #include "formatfactory.h" | ||
47 | |||
48 | #include "resource.h" | ||
49 | #include "resourcefileconfig.h" | ||
50 | #include "stdaddressbook.h" | ||
51 | |||
52 | #include <formats/vcardformatplugin2.h> | ||
53 | #include <formats/binaryformat.h> | ||
54 | |||
55 | |||
56 | #include "resourcefile.h" | ||
57 | |||
58 | using namespace KABC; | ||
59 | |||
60 | extern "C" | ||
61 | { | ||
62 | void *init_kabc_file() | ||
63 | { | ||
64 | qDebug("!!!resourcefile.cpp : init_kabc_file has to be changed"); | ||
65 | //US return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); | ||
66 | return 0; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | |||
71 | ResourceFile::ResourceFile( const KConfig *config ) | ||
72 | : Resource( config ) , mFormat( 0 ) | ||
73 | { | ||
74 | QString fileName, formatName; | ||
75 | |||
76 | KConfig *cfg = (KConfig *)config; | ||
77 | if ( cfg ) { | ||
78 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | ||
79 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | ||
80 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
81 | } else { | ||
82 | fileName = StdAddressBook::fileName(); | ||
83 | formatName = "vcard"; | ||
84 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
85 | } | ||
86 | |||
87 | init( fileName, formatName ); | ||
88 | } | ||
89 | |||
90 | ResourceFile::ResourceFile( const QString &fileName, | ||
91 | const QString &formatName ) | ||
92 | : Resource( 0 ) | ||
93 | { | ||
94 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | ||
95 | init( fileName, formatName ); | ||
96 | } | ||
97 | |||
98 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | ||
99 | { | ||
100 | mFormatName = formatName; | ||
101 | |||
102 | /*US FormatFactory *factory = FormatFactory::self(); | ||
103 | mFormat = factory->format( mFormatName ); | ||
104 | |||
105 | if ( !mFormat ) { | ||
106 | mFormatName = "vcard"; | ||
107 | mFormat = factory->format( mFormatName ); | ||
108 | } | ||
109 | */ | ||
110 | |||
111 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); | ||
112 | if (mFormatName == "vcard") { | ||
113 | mFormat = new VCardFormatPlugin2(); | ||
114 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); | ||
115 | } | ||
116 | else if (mFormatName == "binary") { | ||
117 | mFormat = new BinaryFormat(); | ||
118 | // qDebug("ResourceFile::init format BinaryFormat"); | ||
119 | } | ||
120 | else | ||
121 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); | ||
122 | |||
123 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | ||
124 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | ||
125 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | ||
126 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | ||
127 | */ | ||
128 | |||
129 | setFileName( fileName ); | ||
130 | } | ||
131 | |||
132 | ResourceFile::~ResourceFile() | ||
133 | { | ||
134 | delete mFormat; | ||
135 | mFormat = 0; | ||
136 | } | ||
137 | |||
138 | void ResourceFile::writeConfig( KConfig *config ) | ||
139 | { | ||
140 | Resource::writeConfig( config ); | ||
141 | |||
142 | config->writeEntry( "FileName", mFileName ); | ||
143 | config->writeEntry( "FileFormat", mFormatName ); | ||
144 | |||
145 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
146 | |||
147 | } | ||
148 | |||
149 | Ticket *ResourceFile::requestSaveTicket() | ||
150 | { | ||
151 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | ||
152 | |||
153 | if ( !addressBook() ) return 0; | ||
154 | |||
155 | if ( !lock( mFileName ) ) { | ||
156 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | ||
157 | << mFileName << "'" << endl; | ||
158 | return 0; | ||
159 | } | ||
160 | return createTicket( this ); | ||
161 | } | ||
162 | |||
163 | |||
164 | bool ResourceFile::doOpen() | ||
165 | { | ||
166 | QFile file( mFileName ); | ||
167 | |||
168 | if ( !file.exists() ) { | ||
169 | // try to create the file | ||
170 | bool ok = file.open( IO_WriteOnly ); | ||
171 | if ( ok ) | ||
172 | file.close(); | ||
173 | |||
174 | return ok; | ||
175 | } else { | ||
176 | if ( !file.open( IO_ReadWrite ) ) | ||
177 | return false; | ||
178 | |||
179 | if ( file.size() == 0 ) { | ||
180 | file.close(); | ||
181 | return true; | ||
182 | } | ||
183 | |||
184 | bool ok = mFormat->checkFormat( &file ); | ||
185 | file.close(); | ||
186 | |||
187 | return ok; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | void ResourceFile::doClose() | ||
192 | { | ||
193 | } | ||
194 | |||
195 | bool ResourceFile::load() | ||
196 | { | ||
197 | kdDebug(5700) << "ResourceFile::load(): '" << mFileName << "'" << endl; | ||
198 | |||
199 | QFile file( mFileName ); | ||
200 | if ( !file.open( IO_ReadOnly ) ) { | ||
201 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | ||
202 | return false; | ||
203 | } | ||
204 | |||
205 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
206 | |||
207 | return mFormat->loadAll( addressBook(), this, &file ); | ||
208 | } | ||
209 | |||
210 | bool ResourceFile::save( Ticket *ticket ) | ||
211 | { | ||
212 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
213 | kdDebug(5700) << "ResourceFile::save()" << endl; | ||
214 | |||
215 | // create backup file | ||
216 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
217 | |||
218 | /*US we use a simpler method to create a backupfile | ||
219 | |||
220 | (void) KSaveFile::backupFile( mFileName, QString::null /*directory*/ | ||
221 | /*US ,extension ); | ||
222 | |||
223 | KSaveFile saveFile( mFileName ); | ||
224 | bool ok = false; | ||
225 | if ( saveFile.status() == 0 && saveFile.file() ) | ||
226 | { | ||
227 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | ||
228 | ok = saveFile.close(); | ||
229 | } | ||
230 | */ | ||
231 | |||
232 | //US ToDo: write backupfile | ||
233 | QFile info; | ||
234 | info.setName( mFileName ); | ||
235 | bool ok = info.open( IO_WriteOnly ); | ||
236 | if ( ok ) { | ||
237 | mFormat->saveAll( addressBook(), this, &info ); | ||
238 | |||
239 | info.close(); | ||
240 | ok = true; | ||
241 | } | ||
242 | else { | ||
243 | |||
244 | } | ||
245 | |||
246 | if ( !ok ) | ||
247 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | ||
248 | |||
249 | delete ticket; | ||
250 | unlock( mFileName ); | ||
251 | |||
252 | return ok; | ||
253 | |||
254 | qDebug("ResourceFile::save has to be changed"); | ||
255 | return true; | ||
256 | } | ||
257 | |||
258 | bool ResourceFile::lock( const QString &fileName ) | ||
259 | { | ||
260 | kdDebug(5700) << "ResourceFile::lock()" << endl; | ||
261 | |||
262 | QString fn = fileName; | ||
263 | |||
264 | //US change the implementation how the lockfilename is getting created | ||
265 | //US fn.replace( QRegExp("/"), "_" ); | ||
266 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
267 | |||
268 | KURL url(fn); | ||
269 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
270 | |||
271 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
272 | |||
273 | if (QFile::exists( lockName )) return false; | ||
274 | |||
275 | QString lockUniqueName; | ||
276 | lockUniqueName = fn + KApplication::randomString( 8 ); | ||
277 | |||
278 | url = lockUniqueName; | ||
279 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | ||
280 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | ||
281 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | ||
282 | |||
283 | // Create unique file | ||
284 | QFile file( mLockUniqueName ); | ||
285 | file.open( IO_WriteOnly ); | ||
286 | file.close(); | ||
287 | |||
288 | // Create lock file | ||
289 | int result = 0;//::link( QFile::encodeName( mLockUniqueName ), | ||
290 | // QFile::encodeName( lockName ) ); | ||
291 | qDebug("lock files %s, %s needs to be fixed", mLockUniqueName.latin1(), lockName.latin1() ); | ||
292 | |||
293 | if ( result == 0 ) { | ||
294 | addressBook()->emitAddressBookLocked(); | ||
295 | return true; | ||
296 | } | ||
297 | |||
298 | // TODO: check stat | ||
299 | |||
300 | return false; | ||
301 | } | ||
302 | |||
303 | void ResourceFile::unlock( const QString &fileName ) | ||
304 | { | ||
305 | QString fn = fileName; | ||
306 | //US change the implementation how the lockfilename is getting created | ||
307 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
308 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
309 | //US QString lockName = fn + ".lock"; | ||
310 | KURL url(fn); | ||
311 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
312 | |||
313 | QFile::remove( lockName ); | ||
314 | QFile::remove( mLockUniqueName ); | ||
315 | addressBook()->emitAddressBookUnlocked(); | ||
316 | } | ||
317 | |||
318 | void ResourceFile::setFileName( const QString &fileName ) | ||
319 | { | ||
320 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
321 | mDirWatch.stopScan(); | ||
322 | mDirWatch.removeFile( mFileName ); | ||
323 | */ | ||
324 | mFileName = fileName; | ||
325 | |||
326 | |||
327 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
328 | mDirWatch.addFile( mFileName ); | ||
329 | mDirWatch.startScan(); | ||
330 | */ | ||
331 | //US simulate KDirWatch event | ||
332 | fileChanged(); | ||
333 | } | ||
334 | |||
335 | QString ResourceFile::fileName() const | ||
336 | { | ||
337 | return mFileName; | ||
338 | } | ||
339 | |||
340 | void ResourceFile::setFormat( const QString &format ) | ||
341 | { | ||
342 | mFormatName = format; | ||
343 | delete mFormat; | ||
344 | |||
345 | //US FormatFactory *factory = FormatFactory::self(); | ||
346 | //US mFormat = factory->format( mFormatName ); | ||
347 | |||
348 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | ||
349 | if (mFormatName == "vcard") { | ||
350 | mFormat = new VCardFormatPlugin2(); | ||
351 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | ||
352 | } | ||
353 | else if (mFormatName == "binary") { | ||
354 | mFormat = new BinaryFormat(); | ||
355 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | ||
356 | } | ||
357 | else | ||
358 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | ||
359 | |||
360 | } | ||
361 | |||
362 | QString ResourceFile::format() const | ||
363 | { | ||
364 | return mFormatName; | ||
365 | } | ||
366 | |||
367 | void ResourceFile::fileChanged() | ||
368 | { | ||
369 | // There is a small theoretical chance that KDirWatch calls us before | ||
370 | // we are fully constructed | ||
371 | if (!addressBook()) | ||
372 | return; | ||
373 | load(); | ||
374 | addressBook()->emitAddressBookChanged(); | ||
375 | } | ||
376 | |||
377 | void ResourceFile::removeAddressee( const Addressee &addr ) | ||
378 | { | ||
379 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | ||
380 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | ||
381 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | ||
382 | } | ||
383 | |||
384 | void ResourceFile::cleanUp() | ||
385 | { | ||
386 | unlock( mFileName ); | ||
387 | } | ||
388 | |||
389 | //US #include "resourcefile.moc" | ||
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h new file mode 100644 index 0000000..4522d78 --- a/dev/null +++ b/kabc/plugins/file/resourcefile.h | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | |||
29 | #ifndef KABC_RESOURCEFILE_H | ||
30 | #define KABC_RESOURCEFILE_H | ||
31 | |||
32 | #include <kconfig.h> | ||
33 | #include <kdirwatch.h> | ||
34 | |||
35 | #include <sys/types.h> | ||
36 | |||
37 | #include <resource.h> | ||
38 | |||
39 | class QTimer; | ||
40 | class FormatPlugin; | ||
41 | |||
42 | namespace KABC { | ||
43 | |||
44 | //US class FormatPlugin; | ||
45 | class ResourceConfigWidget; | ||
46 | |||
47 | /** | ||
48 | @internal | ||
49 | */ | ||
50 | class ResourceFile : public Resource | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | |||
54 | public: | ||
55 | |||
56 | /** | ||
57 | Constructor. | ||
58 | |||
59 | @param cfg The config object where custom resource settings are stored. | ||
60 | */ | ||
61 | ResourceFile( const KConfig *cfg ); | ||
62 | |||
63 | /** | ||
64 | Construct file resource on file @arg fileName using format @arg formatName. | ||
65 | */ | ||
66 | ResourceFile( const QString &fileName, const QString &formatName = "vcard" ); | ||
67 | |||
68 | /** | ||
69 | * Destructor. | ||
70 | */ | ||
71 | ~ResourceFile(); | ||
72 | |||
73 | /** | ||
74 | Writes the config back. | ||
75 | */ | ||
76 | virtual void writeConfig( KConfig *cfg ); | ||
77 | |||
78 | /** | ||
79 | * Tries to open the file and checks for the proper format. | ||
80 | * This method should be called before @ref load(). | ||
81 | */ | ||
82 | virtual bool doOpen(); | ||
83 | |||
84 | /** | ||
85 | * Closes the file again. | ||
86 | */ | ||
87 | virtual void doClose(); | ||
88 | |||
89 | /** | ||
90 | * Requests a save ticket, that is used by @ref save() | ||
91 | */ | ||
92 | virtual Ticket *requestSaveTicket(); | ||
93 | |||
94 | /** | ||
95 | * Loads all addressees from file to the address book. | ||
96 | * Returns true if all addressees could be loaded otherwise false. | ||
97 | */ | ||
98 | virtual bool load(); | ||
99 | |||
100 | /** | ||
101 | * Saves all addresses from address book to file. | ||
102 | * Returns true if all addressees could be saved otherwise false. | ||
103 | * | ||
104 | * @param ticket The ticket returned by @ref requestSaveTicket() | ||
105 | */ | ||
106 | virtual bool save( Ticket *ticket ); | ||
107 | |||
108 | /** | ||
109 | * Set name of file to be used for saving. | ||
110 | */ | ||
111 | void setFileName( const QString & ); | ||
112 | |||
113 | /** | ||
114 | * Return name of file used for loading and saving the address book. | ||
115 | */ | ||
116 | QString fileName() const; | ||
117 | |||
118 | /** | ||
119 | Sets a new format by name. | ||
120 | */ | ||
121 | void setFormat( const QString &name ); | ||
122 | |||
123 | /** | ||
124 | Returns the format name. | ||
125 | */ | ||
126 | QString format() const; | ||
127 | |||
128 | /** | ||
129 | * Remove a addressee from its source. | ||
130 | * This method is mainly called by KABC::AddressBook. | ||
131 | */ | ||
132 | virtual void removeAddressee( const Addressee& addr ); | ||
133 | |||
134 | /** | ||
135 | * This method is called by an error handler if the application | ||
136 | * crashed | ||
137 | */ | ||
138 | virtual void cleanUp(); | ||
139 | |||
140 | protected slots: | ||
141 | void fileChanged(); | ||
142 | |||
143 | protected: | ||
144 | void init( const QString &fileName, const QString &format ); | ||
145 | |||
146 | bool lock( const QString &fileName ); | ||
147 | void unlock( const QString &fileName ); | ||
148 | |||
149 | private: | ||
150 | QString mFileName; | ||
151 | QString mFormatName; | ||
152 | |||
153 | FormatPlugin *mFormat; | ||
154 | |||
155 | QString mLockUniqueName; | ||
156 | |||
157 | KDirWatch mDirWatch; | ||
158 | }; | ||
159 | |||
160 | } | ||
161 | |||
162 | #endif | ||
diff --git a/kabc/plugins/file/resourcefileconfig.cpp b/kabc/plugins/file/resourcefileconfig.cpp new file mode 100644 index 0000000..b63775d --- a/dev/null +++ b/kabc/plugins/file/resourcefileconfig.cpp | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <qlabel.h> | ||
29 | #include <qlayout.h> | ||
30 | #include <qfileinfo.h> | ||
31 | |||
32 | #include <kdebug.h> | ||
33 | #include <klocale.h> | ||
34 | #include <kstandarddirs.h> | ||
35 | #include <kdialog.h> | ||
36 | #ifndef _WIN32_ | ||
37 | #include <unistd.h> | ||
38 | #endif | ||
39 | //US #include "formatfactory.h" | ||
40 | #include <qfile.h> | ||
41 | #include "resourcefile.h" | ||
42 | #include "stdaddressbook.h" | ||
43 | |||
44 | #include "resourcefileconfig.h" | ||
45 | |||
46 | using namespace KABC; | ||
47 | |||
48 | ResourceFileConfig::ResourceFileConfig( QWidget* parent, const char* name ) | ||
49 | : ConfigWidget( parent, name ) | ||
50 | { | ||
51 | //qDebug("ResourceFileConfig::ResourceFileConfig"); | ||
52 | |||
53 | QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0, | ||
54 | KDialog::spacingHint() ); | ||
55 | |||
56 | QLabel *label = new QLabel( i18n( "Format:" ), this ); | ||
57 | mFormatBox = new KComboBox( this ); | ||
58 | |||
59 | mainLayout->addWidget( label, 0, 0 ); | ||
60 | mainLayout->addWidget( mFormatBox, 0, 1 ); | ||
61 | |||
62 | label = new QLabel( i18n( "Location:" ), this ); | ||
63 | mFileNameEdit = new KURLRequester( this ); | ||
64 | |||
65 | connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), | ||
66 | SLOT( checkFilePermissions( const QString & ) ) ); | ||
67 | |||
68 | mainLayout->addWidget( label, 1, 0 ); | ||
69 | mainLayout->addWidget( mFileNameEdit, 1, 1 ); | ||
70 | |||
71 | |||
72 | /*US lets hardcode the formats instead of using a factory | ||
73 | FormatFactory *factory = FormatFactory::self(); | ||
74 | QStringList formats = factory->formats(); | ||
75 | QStringList::Iterator it; | ||
76 | |||
77 | for ( it = formats.begin(); it != formats.end(); ++it ) { | ||
78 | FormatInfo *info = factory->info( *it ); | ||
79 | if ( info ) { | ||
80 | mFormatTypes << (*it); | ||
81 | mFormatBox->insertItem( info->nameLabel ); | ||
82 | } | ||
83 | } | ||
84 | */ | ||
85 | mFormatTypes << "vcard"; | ||
86 | mFormatTypes << "binary"; | ||
87 | mFormatBox->insertItem( "vcard" ); | ||
88 | mFormatBox->insertItem( "binary" ); | ||
89 | |||
90 | mInEditMode = false; | ||
91 | } | ||
92 | |||
93 | void ResourceFileConfig::setEditMode( bool value ) | ||
94 | { | ||
95 | mFormatBox->setEnabled( !value ); | ||
96 | mInEditMode = value; | ||
97 | } | ||
98 | |||
99 | void ResourceFileConfig::loadSettings( KRES::Resource *res ) | ||
100 | { | ||
101 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | ||
102 | ResourceFile *resource = (ResourceFile*)( res ); | ||
103 | |||
104 | if ( !resource ) { | ||
105 | kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl; | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) ); | ||
110 | |||
111 | mFileNameEdit->setURL( resource->fileName() ); | ||
112 | if ( mFileNameEdit->url().isEmpty() ) | ||
113 | mFileNameEdit->setURL( KABC::StdAddressBook::fileName() ); | ||
114 | } | ||
115 | |||
116 | void ResourceFileConfig::saveSettings( KRES::Resource *res ) | ||
117 | { | ||
118 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | ||
119 | ResourceFile *resource = (ResourceFile*)( res ); | ||
120 | |||
121 | if ( !resource ) { | ||
122 | kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl; | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | if ( !mInEditMode ) | ||
127 | resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] ); | ||
128 | |||
129 | resource->setFileName( mFileNameEdit->url() ); | ||
130 | } | ||
131 | void ResourceFileConfig::checkFilePermissions( const QString& fileName ) | ||
132 | { | ||
133 | // If file exist but is not writeable... | ||
134 | #ifdef _WIN32_ | ||
135 | QFileInfo fi ( QFile::encodeName( fileName ) ); | ||
136 | if ( fi.exists() ) | ||
137 | emit setReadOnly(!fi.isReadable() ); | ||
138 | #else | ||
139 | if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) | ||
140 | emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); | ||
141 | #endif | ||
142 | } | ||
143 | |||
144 | //US #include "resourcefileconfig.moc" | ||
diff --git a/kabc/plugins/file/resourcefileconfig.h b/kabc/plugins/file/resourcefileconfig.h new file mode 100644 index 0000000..31ccaaf --- a/dev/null +++ b/kabc/plugins/file/resourcefileconfig.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | |||
22 | /* | ||
23 | Enhanced Version of the file for platform independent KDE tools. | ||
24 | Copyright (c) 2004 Ulf Schenk | ||
25 | |||
26 | $Id$ | ||
27 | */ | ||
28 | |||
29 | #ifndef RESOURCEFILECONFIG_H | ||
30 | #define RESOURCEFILECONFIG_H | ||
31 | |||
32 | #include <kcombobox.h> | ||
33 | #include <kurlrequester.h> | ||
34 | |||
35 | #include <kresources/configwidget.h> | ||
36 | |||
37 | namespace KABC { | ||
38 | |||
39 | class ResourceFileConfig : public KRES::ConfigWidget | ||
40 | { | ||
41 | Q_OBJECT | ||
42 | |||
43 | public: | ||
44 | ResourceFileConfig( QWidget* parent = 0, const char* name = 0 ); | ||
45 | |||
46 | void setEditMode( bool value ); | ||
47 | |||
48 | public slots: | ||
49 | void loadSettings( KRES::Resource *resource ); | ||
50 | void saveSettings( KRES::Resource *resource ); | ||
51 | |||
52 | protected slots: | ||
53 | void checkFilePermissions( const QString& fileName ); | ||
54 | |||
55 | private: | ||
56 | KComboBox* mFormatBox; | ||
57 | KURLRequester* mFileNameEdit; | ||
58 | bool mInEditMode; | ||
59 | |||
60 | QStringList mFormatTypes; | ||
61 | }; | ||
62 | |||
63 | } | ||
64 | |||
65 | #endif | ||
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp new file mode 100644 index 0000000..1c54f63 --- a/dev/null +++ b/kabc/plugins/ldap/resourceldap.cpp | |||
@@ -0,0 +1,444 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <kdebug.h> | ||
29 | #include <kglobal.h> | ||
30 | #include <klineedit.h> | ||
31 | #include <klocale.h> | ||
32 | #include <kconfig.h> | ||
33 | #include <kstringhandler.h> | ||
34 | |||
35 | #include <stdlib.h> | ||
36 | |||
37 | #include "resourceldap.h" | ||
38 | #include "resourceldapconfig.h" | ||
39 | |||
40 | using namespace KABC; | ||
41 | |||
42 | extern "C" | ||
43 | { | ||
44 | void *init_kabc_ldap() | ||
45 | { | ||
46 | qDebug("resourceldap.cpp : init_kabc_ldap has to be changed"); | ||
47 | //US return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig>(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); | ||
52 | |||
53 | |||
54 | ResourceLDAP::ResourceLDAP( const KConfig *config ) | ||
55 | : Resource( config ), mPort( 389 ), mLdap( 0 ) | ||
56 | { | ||
57 | KConfig *cfg = (KConfig *)config; | ||
58 | if ( cfg ) { | ||
59 | mUser = cfg->readEntry( "LdapUser" ); | ||
60 | mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); | ||
61 | mDn = cfg->readEntry( "LdapDn" ); | ||
62 | mHost = cfg->readEntry( "LdapHost" ); | ||
63 | mPort = cfg->readNumEntry( "LdapPort", 389 ); | ||
64 | mFilter = cfg->readEntry( "LdapFilter" ); | ||
65 | mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); | ||
66 | |||
67 | QStringList attributes = cfg->readListEntry( "LdapAttributes" ); | ||
68 | for ( uint pos = 0; pos < attributes.count(); pos += 2 ) | ||
69 | mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | If you want to add new attributes, append them here, add a | ||
74 | translation string in the ctor of AttributesDialog and | ||
75 | handle them in the load() method below. | ||
76 | These are the default values from | ||
77 | */ | ||
78 | if ( mAttributes.count() == 0 ) { | ||
79 | mAttributes.insert( "commonName", "cn" ); | ||
80 | mAttributes.insert( "formattedName", "displayName" ); | ||
81 | mAttributes.insert( "familyName", "sn" ); | ||
82 | mAttributes.insert( "givenName", "givenName" ); | ||
83 | mAttributes.insert( "mail", "mail" ); | ||
84 | mAttributes.insert( "mailAlias", "" ); | ||
85 | mAttributes.insert( "phoneNumber", "telephoneNumber" ); | ||
86 | mAttributes.insert( "uid", "uid" ); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void ResourceLDAP::writeConfig( KConfig *config ) | ||
91 | { | ||
92 | Resource::writeConfig( config ); | ||
93 | |||
94 | config->writeEntry( "LdapUser", mUser ); | ||
95 | config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); | ||
96 | config->writeEntry( "LdapDn", mDn ); | ||
97 | config->writeEntry( "LdapHost", mHost ); | ||
98 | config->writeEntry( "LdapPort", mPort ); | ||
99 | config->writeEntry( "LdapFilter", mFilter ); | ||
100 | config->writeEntry( "LdapAnonymous", mAnonymous ); | ||
101 | |||
102 | QStringList attributes; | ||
103 | QMap<QString, QString>::Iterator it; | ||
104 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) | ||
105 | attributes << it.key() << it.data(); | ||
106 | |||
107 | config->writeEntry( "LdapAttributes", attributes ); | ||
108 | } | ||
109 | |||
110 | Ticket *ResourceLDAP::requestSaveTicket() | ||
111 | { | ||
112 | if ( !addressBook() ) { | ||
113 | kdDebug(5700) << "no addressbook" << endl; | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | return createTicket( this ); | ||
118 | } | ||
119 | |||
120 | bool ResourceLDAP::doOpen() | ||
121 | { | ||
122 | if ( mLdap ) | ||
123 | return false; | ||
124 | |||
125 | if ( !mPort ) | ||
126 | mPort = 389; | ||
127 | |||
128 | mLdap = ldap_init( mHost.local8Bit(), mPort ); | ||
129 | if ( !mLdap ) { | ||
130 | addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); | ||
131 | return false; | ||
132 | } | ||
133 | |||
134 | if ( !mUser.isEmpty() && !mAnonymous ) { | ||
135 | if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { | ||
136 | addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); | ||
137 | return false; | ||
138 | } | ||
139 | |||
140 | kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; | ||
141 | } else { | ||
142 | if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { | ||
143 | addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); | ||
144 | return false; | ||
145 | } | ||
146 | |||
147 | kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; | ||
148 | } | ||
149 | |||
150 | int deref = LDAP_DEREF_ALWAYS; | ||
151 | if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { | ||
152 | kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; | ||
153 | return false; | ||
154 | } | ||
155 | |||
156 | if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { | ||
157 | kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; | ||
158 | return false; | ||
159 | } | ||
160 | |||
161 | return true; | ||
162 | } | ||
163 | |||
164 | void ResourceLDAP::doClose() | ||
165 | { | ||
166 | if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { | ||
167 | kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | mLdap = 0; | ||
172 | } | ||
173 | |||
174 | bool ResourceLDAP::load() | ||
175 | { | ||
176 | LDAPMessage *res; | ||
177 | LDAPMessage *msg; | ||
178 | BerElement *track; | ||
179 | char *names; | ||
180 | char **values; | ||
181 | |||
182 | char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; | ||
183 | |||
184 | QMap<QString, QString>::Iterator it; | ||
185 | int i = 0; | ||
186 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { | ||
187 | if ( !it.data().isEmpty() ) { | ||
188 | unsigned int len = it.data().utf8().length(); | ||
189 | LdapSearchAttr[ i ] = new char[ len+1 ]; | ||
190 | memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); | ||
191 | LdapSearchAttr[ i ][ len ] = 0; | ||
192 | ++i; | ||
193 | } | ||
194 | } | ||
195 | LdapSearchAttr[ i ] = 0; | ||
196 | |||
197 | QString filter = mFilter; | ||
198 | if ( filter.isEmpty() ) | ||
199 | filter = "cn=*"; | ||
200 | |||
201 | int result; | ||
202 | if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), | ||
203 | LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { | ||
204 | addressBook()->error( i18n( "Unable to search on server '%1': %2" ) | ||
205 | .arg( mHost ) | ||
206 | .arg( ldap_err2string( result ) ) ); | ||
207 | |||
208 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) | ||
209 | delete [] LdapSearchAttr[ i ]; | ||
210 | delete [] LdapSearchAttr; | ||
211 | |||
212 | return false; | ||
213 | } | ||
214 | |||
215 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { | ||
216 | Addressee addr; | ||
217 | addr.setResource( this ); | ||
218 | for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { | ||
219 | values = ldap_get_values( mLdap, msg, names ); | ||
220 | for ( int i = 0; i < ldap_count_values( values ); ++i ) { | ||
221 | QString name = QString::fromUtf8( names ).lower(); | ||
222 | QString value = QString::fromUtf8( values[ i ] ); | ||
223 | |||
224 | if ( name == mAttributes[ "commonName" ].lower() ) { | ||
225 | if ( !addr.formattedName().isEmpty() ) { | ||
226 | QString fn = addr.formattedName(); | ||
227 | addr.setNameFromString( value ); | ||
228 | addr.setFormattedName( fn ); | ||
229 | } else | ||
230 | addr.setNameFromString( value ); | ||
231 | } else if ( name == mAttributes[ "formattedName" ].lower() ) { | ||
232 | addr.setFormattedName( value ); | ||
233 | } else if ( name == mAttributes[ "givenName" ].lower() ) { | ||
234 | addr.setGivenName( value ); | ||
235 | } else if ( name == mAttributes[ "mail" ].lower() ) { | ||
236 | addr.insertEmail( value, true ); | ||
237 | } else if ( name == mAttributes[ "mailAlias" ].lower() ) { | ||
238 | addr.insertEmail( value, false ); | ||
239 | } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { | ||
240 | PhoneNumber phone; | ||
241 | phone.setNumber( value ); | ||
242 | addr.insertPhoneNumber( phone ); | ||
243 | break; // read only the home number | ||
244 | } else if ( name == mAttributes[ "familyName" ].lower() ) { | ||
245 | addr.setFamilyName( value ); | ||
246 | } else if ( name == mAttributes[ "uid" ].lower() ) { | ||
247 | addr.setUid( value ); | ||
248 | } | ||
249 | } | ||
250 | ldap_value_free( values ); | ||
251 | } | ||
252 | ber_free( track, 0 ); | ||
253 | |||
254 | addressBook()->insertAddressee( addr ); | ||
255 | } | ||
256 | |||
257 | ldap_msgfree( res ); | ||
258 | |||
259 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) | ||
260 | delete [] LdapSearchAttr[ i ]; | ||
261 | delete [] LdapSearchAttr; | ||
262 | |||
263 | return true; | ||
264 | } | ||
265 | |||
266 | bool ResourceLDAP::save( Ticket * ) | ||
267 | { | ||
268 | AddressBook::Iterator it; | ||
269 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | ||
270 | if ( (*it).resource() == this && (*it).changed() ) { | ||
271 | LDAPMod **mods = NULL; | ||
272 | |||
273 | addModOp( &mods, "objectClass", "organizationalPerson" ); | ||
274 | addModOp( &mods, "objectClass", "person" ); | ||
275 | addModOp( &mods, "objectClass", "Top" ); | ||
276 | addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() ); | ||
277 | addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() ); | ||
278 | addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() ); | ||
279 | addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() ); | ||
280 | addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() ); | ||
281 | |||
282 | QStringList emails = (*it).emails(); | ||
283 | QStringList::ConstIterator mailIt; | ||
284 | bool first = true; | ||
285 | for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) { | ||
286 | if ( first ) { | ||
287 | addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) ); | ||
288 | first = false; | ||
289 | } else | ||
290 | addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) ); | ||
291 | } | ||
292 | |||
293 | PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home ); | ||
294 | addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() ); | ||
295 | |||
296 | QString dn = "cn=" + (*it).assembledName() + "," + mDn; | ||
297 | |||
298 | int retval; | ||
299 | if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS ) | ||
300 | addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) ); | ||
301 | |||
302 | ldap_mods_free( mods, 1 ); | ||
303 | |||
304 | // mark as unchanged | ||
305 | (*it).setChanged( false ); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | return true; | ||
310 | } | ||
311 | |||
312 | void ResourceLDAP::removeAddressee( const Addressee &addr ) | ||
313 | { | ||
314 | LDAPMessage *res; | ||
315 | LDAPMessage *msg; | ||
316 | |||
317 | QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter ); | ||
318 | |||
319 | kdDebug(5700) << "ldap:removeAddressee" << filter << endl; | ||
320 | |||
321 | ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(), | ||
322 | 0, 0, &res ); | ||
323 | |||
324 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { | ||
325 | char *dn = ldap_get_dn( mLdap, msg ); | ||
326 | kdDebug(5700) << "found " << dn << endl; | ||
327 | if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS ) | ||
328 | addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) ); | ||
329 | ldap_memfree( dn ); | ||
330 | } | ||
331 | |||
332 | ldap_msgfree( res ); | ||
333 | } | ||
334 | |||
335 | void ResourceLDAP::setUser( const QString &user ) | ||
336 | { | ||
337 | mUser = user; | ||
338 | } | ||
339 | |||
340 | QString ResourceLDAP::user() const | ||
341 | { | ||
342 | return mUser; | ||
343 | } | ||
344 | |||
345 | void ResourceLDAP::setPassword( const QString &password ) | ||
346 | { | ||
347 | mPassword = password; | ||
348 | } | ||
349 | |||
350 | QString ResourceLDAP::password() const | ||
351 | { | ||
352 | return mPassword; | ||
353 | } | ||
354 | |||
355 | void ResourceLDAP::setDn( const QString &dn ) | ||
356 | { | ||
357 | mDn = dn; | ||
358 | } | ||
359 | |||
360 | QString ResourceLDAP::dn() const | ||
361 | { | ||
362 | return mDn; | ||
363 | } | ||
364 | |||
365 | void ResourceLDAP::setHost( const QString &host ) | ||
366 | { | ||
367 | mHost = host; | ||
368 | } | ||
369 | |||
370 | QString ResourceLDAP::host() const | ||
371 | { | ||
372 | return mHost; | ||
373 | } | ||
374 | |||
375 | void ResourceLDAP::setPort( int port ) | ||
376 | { | ||
377 | mPort = port; | ||
378 | } | ||
379 | |||
380 | int ResourceLDAP::port() const | ||
381 | { | ||
382 | return mPort; | ||
383 | } | ||
384 | |||
385 | void ResourceLDAP::setFilter( const QString &filter ) | ||
386 | { | ||
387 | mFilter = filter; | ||
388 | } | ||
389 | |||
390 | QString ResourceLDAP::filter() const | ||
391 | { | ||
392 | return mFilter; | ||
393 | } | ||
394 | |||
395 | void ResourceLDAP::setIsAnonymous( bool value ) | ||
396 | { | ||
397 | mAnonymous = value; | ||
398 | } | ||
399 | |||
400 | bool ResourceLDAP::isAnonymous() const | ||
401 | { | ||
402 | return mAnonymous; | ||
403 | } | ||
404 | |||
405 | void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes ) | ||
406 | { | ||
407 | mAttributes = attributes; | ||
408 | } | ||
409 | |||
410 | QMap<QString, QString> ResourceLDAP::attributes() const | ||
411 | { | ||
412 | return mAttributes; | ||
413 | } | ||
414 | |||
415 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ) | ||
416 | { | ||
417 | if ( value.isNull() ) | ||
418 | return; | ||
419 | |||
420 | LDAPMod**mods; | ||
421 | |||
422 | mods = *pmods; | ||
423 | |||
424 | uint i = 0; | ||
425 | if ( mods != 0 ) | ||
426 | for ( ; mods[ i ] != 0; ++i ); | ||
427 | |||
428 | if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) { | ||
429 | kdError() << "ResourceLDAP: realloc" << endl; | ||
430 | return; | ||
431 | } | ||
432 | |||
433 | *pmods = mods; | ||
434 | mods[ i + 1 ] = 0; | ||
435 | |||
436 | mods[ i ] = new LDAPMod; | ||
437 | |||
438 | mods[ i ]->mod_op = 0; | ||
439 | mods[ i ]->mod_type = strdup( attr.utf8() ); | ||
440 | mods[ i ]->mod_values = new char*[ 2 ]; | ||
441 | mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() ); | ||
442 | mods[ i ]->mod_values[ 1 ] = 0; | ||
443 | } | ||
444 | |||
diff --git a/kabc/plugins/ldap/resourceldap.h b/kabc/plugins/ldap/resourceldap.h new file mode 100644 index 0000000..0625f30 --- a/dev/null +++ b/kabc/plugins/ldap/resourceldap.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #ifndef KABC_RESOURCELDAP_H | ||
29 | #define KABC_RESOURCELDAP_H | ||
30 | |||
31 | |||
32 | #include <lber.h> | ||
33 | #include <ldap.h> | ||
34 | |||
35 | #include "addressbook.h" | ||
36 | #include "resource.h" | ||
37 | |||
38 | class KConfig; | ||
39 | |||
40 | namespace KABC { | ||
41 | |||
42 | class ResourceLDAP : public Resource | ||
43 | { | ||
44 | public: | ||
45 | |||
46 | ResourceLDAP( const KConfig* ); | ||
47 | |||
48 | virtual void writeConfig( KConfig* ); | ||
49 | |||
50 | virtual bool doOpen(); | ||
51 | virtual void doClose(); | ||
52 | |||
53 | virtual Ticket *requestSaveTicket(); | ||
54 | |||
55 | virtual bool load(); | ||
56 | virtual bool save( Ticket * ); | ||
57 | |||
58 | virtual void removeAddressee( const Addressee& addr ); | ||
59 | |||
60 | void setUser( const QString &user ); | ||
61 | QString user() const; | ||
62 | |||
63 | void setPassword( const QString &password ); | ||
64 | QString password() const; | ||
65 | |||
66 | void setDn( const QString &dn ); | ||
67 | QString dn() const; | ||
68 | |||
69 | void setHost( const QString &host ); | ||
70 | QString host() const; | ||
71 | |||
72 | void setPort( int port ); | ||
73 | int port() const; | ||
74 | |||
75 | void setFilter( const QString &filter ); | ||
76 | QString filter() const; | ||
77 | |||
78 | void setIsAnonymous( bool value ); | ||
79 | bool isAnonymous() const; | ||
80 | |||
81 | void setAttributes( const QMap<QString, QString> &attributes ); | ||
82 | QMap<QString, QString> attributes() const; | ||
83 | |||
84 | private: | ||
85 | QString mUser; | ||
86 | QString mPassword; | ||
87 | QString mDn; | ||
88 | QString mHost; | ||
89 | QString mFilter; | ||
90 | int mPort; | ||
91 | bool mAnonymous; | ||
92 | QMap<QString, QString> mAttributes; | ||
93 | |||
94 | LDAP *mLdap; | ||
95 | }; | ||
96 | |||
97 | } | ||
98 | |||
99 | #endif | ||
diff --git a/kabc/plugins/ldap/resourceldapconfig.cpp b/kabc/plugins/ldap/resourceldapconfig.cpp new file mode 100644 index 0000000..2c0d030 --- a/dev/null +++ b/kabc/plugins/ldap/resourceldapconfig.cpp | |||
@@ -0,0 +1,254 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <qcheckbox.h> | ||
29 | #include <qlabel.h> | ||
30 | #include <qlayout.h> | ||
31 | #include <qpushbutton.h> | ||
32 | #include <qspinbox.h> | ||
33 | #include <qvbox.h> | ||
34 | |||
35 | //US #include <kaccelmanager.h> | ||
36 | #include <kcombobox.h> | ||
37 | #include <kdebug.h> | ||
38 | #include <kdialogbase.h> | ||
39 | #include <klocale.h> | ||
40 | #include <klineedit.h> | ||
41 | |||
42 | #include "resourceldap.h" | ||
43 | |||
44 | #include "resourceldapconfig.h" | ||
45 | |||
46 | using namespace KABC; | ||
47 | |||
48 | ResourceLDAPConfig::ResourceLDAPConfig( QWidget* parent, const char* name ) | ||
49 | : KRES::ConfigWidget( parent, name ) | ||
50 | { | ||
51 | QGridLayout *mainLayout = new QGridLayout( this, 8, 2, 0, | ||
52 | KDialog::spacingHint() ); | ||
53 | |||
54 | QLabel *label = new QLabel( i18n( "User:" ), this ); | ||
55 | mUser = new KLineEdit( this ); | ||
56 | |||
57 | mainLayout->addWidget( label, 0, 0 ); | ||
58 | mainLayout->addWidget( mUser, 0, 1 ); | ||
59 | |||
60 | label = new QLabel( i18n( "Password:" ), this ); | ||
61 | mPassword = new KLineEdit( this ); | ||
62 | mPassword->setEchoMode( KLineEdit::Password ); | ||
63 | |||
64 | mainLayout->addWidget( label, 1, 0 ); | ||
65 | mainLayout->addWidget( mPassword, 1, 1 ); | ||
66 | |||
67 | label = new QLabel( i18n( "Host:" ), this ); | ||
68 | mHost = new KLineEdit( this ); | ||
69 | |||
70 | mainLayout->addWidget( label, 2, 0 ); | ||
71 | mainLayout->addWidget( mHost, 2, 1 ); | ||
72 | |||
73 | label = new QLabel( i18n( "Port:" ), this ); | ||
74 | QVBox *box = new QVBox( this ); | ||
75 | mPort = new QSpinBox( 0, 65535, 1, box ); | ||
76 | mPort->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); | ||
77 | mPort->setValue( 389 ); | ||
78 | new QWidget( box, "dummy" ); | ||
79 | |||
80 | mainLayout->addWidget( label, 3, 0 ); | ||
81 | mainLayout->addWidget( box, 3, 1 ); | ||
82 | |||
83 | label = new QLabel( i18n( "Dn:" ), this ); | ||
84 | mDn = new KLineEdit( this ); | ||
85 | |||
86 | mainLayout->addWidget( label, 4, 0 ); | ||
87 | mainLayout->addWidget( mDn, 4, 1 ); | ||
88 | |||
89 | label = new QLabel( i18n( "Filter:" ), this ); | ||
90 | mFilter = new KLineEdit( this ); | ||
91 | |||
92 | mainLayout->addWidget( label, 5, 0 ); | ||
93 | mainLayout->addWidget( mFilter, 5, 1 ); | ||
94 | |||
95 | mAnonymous = new QCheckBox( i18n( "Anonymous login" ), this ); | ||
96 | mainLayout->addMultiCellWidget( mAnonymous, 6, 6, 0, 1 ); | ||
97 | |||
98 | mEditButton = new QPushButton( i18n( "Edit Attributes..." ), this ); | ||
99 | mainLayout->addMultiCellWidget( mEditButton, 7, 7, 0, 1 ); | ||
100 | |||
101 | connect( mAnonymous, SIGNAL( toggled(bool) ), mUser, SLOT( setDisabled(bool) ) ); | ||
102 | connect( mAnonymous, SIGNAL( toggled(bool) ), mPassword, SLOT( setDisabled(bool) ) ); | ||
103 | connect( mEditButton, SIGNAL( clicked() ), SLOT( editAttributes() ) ); | ||
104 | } | ||
105 | |||
106 | void ResourceLDAPConfig::loadSettings( KRES::Resource *res ) | ||
107 | { | ||
108 | //US ResourceLDAP *resource = dynamic_cast<ResourceLDAP*>( res ); | ||
109 | ResourceLDAP *resource = (ResourceLDAP*)( res ); | ||
110 | |||
111 | if ( !resource ) { | ||
112 | kdDebug(5700) << "ResourceLDAPConfig::loadSettings(): cast failed" << endl; | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | mUser->setText( resource->user() ); | ||
117 | mPassword->setText( resource->password() ); | ||
118 | mHost->setText( resource->host() ); | ||
119 | mPort->setValue( resource->port() ); | ||
120 | mDn->setText( resource->dn() ); | ||
121 | mFilter->setText( resource->filter() ); | ||
122 | mAnonymous->setChecked( resource->isAnonymous() ); | ||
123 | mAttributes = resource->attributes(); | ||
124 | } | ||
125 | |||
126 | void ResourceLDAPConfig::saveSettings( KRES::Resource *res ) | ||
127 | { | ||
128 | //US ResourceLDAP *resource = dynamic_cast<ResourceLDAP*>( res ); | ||
129 | ResourceLDAP *resource = (ResourceLDAP*)( res ); | ||
130 | |||
131 | if ( !resource ) { | ||
132 | kdDebug(5700) << "ResourceLDAPConfig::saveSettings(): cast failed" << endl; | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | resource->setUser( mUser->text() ); | ||
137 | resource->setPassword( mPassword->text() ); | ||
138 | resource->setHost( mHost->text() ); | ||
139 | resource->setPort( mPort->value() ); | ||
140 | resource->setDn( mDn->text() ); | ||
141 | resource->setFilter( mFilter->text() ); | ||
142 | resource->setIsAnonymous( mAnonymous->isChecked() ); | ||
143 | resource->setAttributes( mAttributes ); | ||
144 | } | ||
145 | |||
146 | void ResourceLDAPConfig::editAttributes() | ||
147 | { | ||
148 | AttributesDialog dlg( mAttributes, this ); | ||
149 | if ( dlg.exec() ) | ||
150 | mAttributes = dlg.attributes(); | ||
151 | } | ||
152 | |||
153 | AttributesDialog::AttributesDialog( const QMap<QString, QString> &attributes, | ||
154 | QWidget *parent, const char *name ) | ||
155 | : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel, | ||
156 | Ok, parent, name, true, true ) | ||
157 | { | ||
158 | mNameDict.setAutoDelete( true ); | ||
159 | mNameDict.insert( "commonName", new QString( i18n( "Common name" ) ) ); | ||
160 | mNameDict.insert( "formattedName", new QString( i18n( "Formatted name" ) ) ); | ||
161 | mNameDict.insert( "familyName", new QString( i18n( "Family name" ) ) ); | ||
162 | mNameDict.insert( "givenName", new QString( i18n( "Given name" ) ) ); | ||
163 | mNameDict.insert( "mail", new QString( i18n( "Email" ) ) ); | ||
164 | mNameDict.insert( "mailAlias", new QString( i18n( "Email alias" ) ) ); | ||
165 | mNameDict.insert( "phoneNumber", new QString( i18n( "Telephone number" ) ) ); | ||
166 | mNameDict.insert( "uid", new QString( i18n( "UID" ) ) ); | ||
167 | |||
168 | // overwrite the default values here | ||
169 | QMap<QString, QString> kolabMap, netscapeMap, evolutionMap, outlookMap; | ||
170 | |||
171 | // kolab | ||
172 | kolabMap.insert( "formattedName", "display-name" ); | ||
173 | kolabMap.insert( "mailAlias", "mailalias" ); | ||
174 | |||
175 | // evolution | ||
176 | evolutionMap.insert( "formattedName", "fileAs" ); | ||
177 | |||
178 | mMapList.append( attributes ); | ||
179 | mMapList.append( kolabMap ); | ||
180 | mMapList.append( netscapeMap ); | ||
181 | mMapList.append( evolutionMap ); | ||
182 | mMapList.append( outlookMap ); | ||
183 | |||
184 | QFrame *page = plainPage(); | ||
185 | QGridLayout *layout = new QGridLayout( page, 2, attributes.count() + 1, | ||
186 | 0, spacingHint() ); | ||
187 | |||
188 | QLabel *label = new QLabel( i18n( "Template:" ), page ); | ||
189 | layout->addWidget( label, 0, 0 ); | ||
190 | mMapCombo = new KComboBox( page ); | ||
191 | layout->addWidget( mMapCombo, 0, 1 ); | ||
192 | |||
193 | mMapCombo->insertItem( i18n( "User Defined" ) ); | ||
194 | mMapCombo->insertItem( i18n( "Kolab" ) ); | ||
195 | mMapCombo->insertItem( i18n( "Netscape" ) ); | ||
196 | mMapCombo->insertItem( i18n( "Evolution" ) ); | ||
197 | mMapCombo->insertItem( i18n( "Outlook" ) ); | ||
198 | connect( mMapCombo, SIGNAL( activated( int ) ), SLOT( mapChanged( int ) ) ); | ||
199 | |||
200 | QMap<QString, QString>::ConstIterator it; | ||
201 | int i; | ||
202 | for ( i = 1, it = attributes.begin(); it != attributes.end(); ++it, ++i ) { | ||
203 | label = new QLabel( *mNameDict[ it.key() ] + ":", page ); | ||
204 | KLineEdit *lineedit = new KLineEdit( page ); | ||
205 | mLineEditDict.insert( it.key(), lineedit ); | ||
206 | lineedit->setText( it.data() ); | ||
207 | label->setBuddy( lineedit ); | ||
208 | layout->addWidget( label, i, 0 ); | ||
209 | layout->addWidget( lineedit, i, 1 ); | ||
210 | } | ||
211 | |||
212 | //US KAcceleratorManager::manage( this ); | ||
213 | } | ||
214 | |||
215 | AttributesDialog::~AttributesDialog() | ||
216 | { | ||
217 | } | ||
218 | |||
219 | QMap<QString, QString> AttributesDialog::attributes() const | ||
220 | { | ||
221 | QMap<QString, QString> map; | ||
222 | |||
223 | QDictIterator<KLineEdit> it( mLineEditDict ); | ||
224 | for ( ; it.current(); ++it ) | ||
225 | map.insert( it.currentKey(), it.current()->text() ); | ||
226 | |||
227 | return map; | ||
228 | } | ||
229 | |||
230 | void AttributesDialog::mapChanged( int pos ) | ||
231 | { | ||
232 | // default map | ||
233 | QMap<QString, QString> defaultMap; | ||
234 | defaultMap.insert( "commonName", "cn" ); | ||
235 | defaultMap.insert( "formattedName", "displayName" ); | ||
236 | defaultMap.insert( "familyName", "sn" ); | ||
237 | defaultMap.insert( "givenName", "givenName" ); | ||
238 | defaultMap.insert( "mail", "mail" ); | ||
239 | defaultMap.insert( "mailAlias", "" ); | ||
240 | defaultMap.insert( "phoneNumber", "telephoneNumber" ); | ||
241 | defaultMap.insert( "uid", "uid" ); | ||
242 | |||
243 | // apply first the default and than the spezific changes | ||
244 | QMap<QString, QString>::Iterator it; | ||
245 | for ( it = defaultMap.begin(); it != defaultMap.end(); ++it ) | ||
246 | mLineEditDict[ it.key() ]->setText( it.data() ); | ||
247 | |||
248 | for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) { | ||
249 | if ( !it.data().isEmpty() ) | ||
250 | mLineEditDict[ it.key() ]->setText( it.data() ); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | //US #include "resourceldapconfig.moc" | ||
diff --git a/kabc/plugins/ldap/resourceldapconfig.h b/kabc/plugins/ldap/resourceldapconfig.h new file mode 100644 index 0000000..42d30ff --- a/dev/null +++ b/kabc/plugins/ldap/resourceldapconfig.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #ifndef RESOURCELDAPCONFIG_H | ||
29 | #define RESOURCELDAPCONFIG_H | ||
30 | |||
31 | #include <qmap.h> | ||
32 | //US | ||
33 | #include <qdict.h> | ||
34 | |||
35 | #include <kdialogbase.h> | ||
36 | #include <kresources/configwidget.h> | ||
37 | |||
38 | class QCheckBox; | ||
39 | class QPushButton; | ||
40 | class QSpinBox; | ||
41 | class QString; | ||
42 | |||
43 | class KComboBox; | ||
44 | class KLineEdit; | ||
45 | |||
46 | namespace KABC { | ||
47 | |||
48 | class ResourceLDAPConfig : public KRES::ConfigWidget | ||
49 | { | ||
50 | Q_OBJECT | ||
51 | |||
52 | public: | ||
53 | ResourceLDAPConfig( QWidget* parent = 0, const char* name = 0 ); | ||
54 | |||
55 | public slots: | ||
56 | void loadSettings( KRES::Resource* ); | ||
57 | void saveSettings( KRES::Resource* ); | ||
58 | |||
59 | private slots: | ||
60 | void editAttributes(); | ||
61 | |||
62 | private: | ||
63 | KLineEdit *mUser; | ||
64 | KLineEdit *mPassword; | ||
65 | KLineEdit *mHost; | ||
66 | QSpinBox *mPort; | ||
67 | KLineEdit *mDn; | ||
68 | KLineEdit *mFilter; | ||
69 | QCheckBox *mAnonymous; | ||
70 | QPushButton *mEditButton; | ||
71 | QMap<QString, QString> mAttributes; | ||
72 | }; | ||
73 | |||
74 | class AttributesDialog : public KDialogBase | ||
75 | { | ||
76 | Q_OBJECT | ||
77 | |||
78 | public: | ||
79 | AttributesDialog( const QMap<QString, QString> &attributes, QWidget *parent, | ||
80 | const char *name = 0 ); | ||
81 | ~AttributesDialog(); | ||
82 | |||
83 | QMap<QString, QString> attributes() const; | ||
84 | |||
85 | private slots: | ||
86 | void mapChanged( int pos ); | ||
87 | |||
88 | private: | ||
89 | enum { UserMap, KolabMap, NetscapeMap, EvolutionMap, OutlookMap }; | ||
90 | |||
91 | KComboBox *mMapCombo; | ||
92 | QValueList< QMap<QString, QString> > mMapList; | ||
93 | |||
94 | QDict<KLineEdit> mLineEditDict; | ||
95 | QDict<QString> mNameDict; | ||
96 | }; | ||
97 | |||
98 | } | ||
99 | |||
100 | #endif | ||