author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kabc/plugins/ldap/resourceldapconfig.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'kabc/plugins/ldap/resourceldapconfig.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kabc/plugins/ldap/resourceldapconfig.cpp | 254 |
1 files changed, 254 insertions, 0 deletions
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" | ||