Statistics
| Revision:

root / src / editldap.c @ 1

History | View | Annotate | Download (20.3 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 2001 Match Grun
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program 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
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 */
19

    
20
/*
21
 * Edit LDAP address book data.
22
 */
23

    
24
#ifdef HAVE_CONFIG_H
25
#  include "config.h"
26
#endif
27

    
28
#ifdef USE_LDAP
29

    
30
#include "defs.h"
31

    
32
#include <glib.h>
33
#include <gdk/gdkkeysyms.h>
34
#include <gtk/gtkwindow.h>
35
#include <gtk/gtksignal.h>
36
#include <gtk/gtklabel.h>
37
#include <gtk/gtkentry.h>
38
#include <gtk/gtktable.h>
39
#include <gtk/gtkbutton.h>
40

    
41
#include "intl.h"
42
#include "addressbook.h"
43
#include "prefs_common.h"
44
#include "addressitem.h"
45
#include "mgutils.h"
46
#include "syldap.h"
47
#include "editldap_basedn.h"
48
#include "manage_window.h"
49
#include "gtkutils.h"
50

    
51
#define ADDRESSBOOK_GUESS_LDAP_NAME        "MyServer"
52
#define ADDRESSBOOK_GUESS_LDAP_SERVER        "localhost"
53

    
54
#define LDAPEDIT_TABLE_ROWS        6
55
#define LDAPEDIT_TABLE_COLS        3
56

    
57
static struct _LDAPEdit {
58
        GtkWidget *window;
59
        GtkWidget *notebook;
60
        GtkWidget *ok_btn;
61
        GtkWidget *cancel_btn;
62
        GtkWidget *statusbar;
63
        gint status_cid;
64
        GtkWidget *entry_name;
65
        GtkWidget *entry_server;
66
        GtkWidget *spinbtn_port;
67
        GtkWidget *entry_baseDN;
68
        GtkWidget *spinbtn_timeout;
69
        GtkWidget *entry_bindDN;
70
        GtkWidget *entry_bindPW;
71
        GtkWidget *entry_criteria;
72
        GtkWidget *spinbtn_maxentry;
73
} ldapedit;
74

    
75
/*
76
* Edit functions.
77
*/
78
static void edit_ldap_status_show( gchar *msg ) {
79
        if( ldapedit.statusbar != NULL ) {
80
                gtk_statusbar_pop( GTK_STATUSBAR(ldapedit.statusbar), ldapedit.status_cid );
81
                if( msg ) {
82
                        gtk_statusbar_push( GTK_STATUSBAR(ldapedit.statusbar), ldapedit.status_cid, msg );
83
                }
84
        }
85
}
86

    
87
static void edit_ldap_ok( GtkWidget *widget, gboolean *cancelled ) {
88
        *cancelled = FALSE;
89
        gtk_main_quit();
90
}
91

    
92
static void edit_ldap_cancel( GtkWidget *widget, gboolean *cancelled ) {
93
        *cancelled = TRUE;
94
        gtk_main_quit();
95
}
96

    
97
static gint edit_ldap_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) {
98
        *cancelled = TRUE;
99
        gtk_main_quit();
100
        return TRUE;
101
}
102

    
103
static gboolean edit_ldap_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) {
104
        if (event && event->keyval == GDK_Escape) {
105
                *cancelled = TRUE;
106
                gtk_main_quit();
107
        }
108
        return FALSE;
109
}
110

    
111
static void edit_ldap_switch_page( GtkWidget *widget ) {
112
        edit_ldap_status_show( "" );
113
}
114

    
115
static void edit_ldap_server_check( void ) {
116
        gchar *sHost, *sBind, *sPass;
117
        gint iPort, iTime;
118
        gchar *sMsg;
119
        gchar *sBaseDN = NULL;
120
        gint iBaseDN = 0;
121
        gboolean flg;
122

    
123
        edit_ldap_status_show( "" );
124
        flg = FALSE;
125
        sHost = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_server), 0, -1 );
126
        sBind = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindDN), 0, -1 );
127
        sPass = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindPW), 0, -1 );
128
        iPort = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_port ) );
129
        iTime = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ) );
130
        g_strchomp( sHost ); g_strchug( sHost );
131
        g_strchomp( sBind ); g_strchug( sBind );
132
        g_strchomp( sPass ); g_strchug( sPass );
133
        if( *sHost != '\0' ) {
134
                /* Test connection to server */
135
                if( syldap_test_connect_s( sHost, iPort ) ) {
136
                        /* Attempt to read base DN */
137
                        GList *baseDN = syldap_read_basedn_s( sHost, iPort, sBind, sPass, iTime );
138
                        if( baseDN ) {
139
                                GList *node = baseDN;
140
                                while( node ) {
141
                                        ++iBaseDN;
142
                                        if( ! sBaseDN ) {
143
                                                sBaseDN = g_strdup( node->data );
144
                                        }
145
                                        node = g_list_next( node );
146
                                }
147
                                mgu_free_dlist( baseDN );
148
                                baseDN = node = NULL;
149
                        }
150
                        flg = TRUE;
151
                }
152
        }
153
        g_free( sHost );
154
        g_free( sBind );
155
        g_free( sPass );
156

    
157
        if( sBaseDN ) {
158
                /* Load search DN */
159
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), sBaseDN);
160
                g_free( sBaseDN );
161
        }
162

    
163
        /* Display appropriate message */
164
        if( flg ) {
165
                sMsg = _( "Connected successfully to server" );
166
        }
167
        else {
168
                sMsg = _( "Could not connect to server" );
169
        }
170
        edit_ldap_status_show( sMsg );
171
}
172

    
173
static void edit_ldap_basedn_select( void ) {
174
        gchar *sHost, *sBind, *sPass, *sBase;
175
        gint iPort, iTime;
176
        gchar *selectDN;
177

    
178
        sHost = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_server), 0, -1 );
179
        sBase = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_baseDN), 0, -1 );
180
        sBind = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindDN), 0, -1 );
181
        sPass = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindPW), 0, -1 );
182
        iPort = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_port ) );
183
        iTime = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ) );
184
        g_strchomp( sHost ); g_strchug( sHost );
185
        g_strchomp( sBind ); g_strchug( sBind );
186
        g_strchomp( sPass ); g_strchug( sPass );
187
        selectDN = edit_ldap_basedn_selection( sHost, iPort, sBase, iTime, sBind, sPass );
188
        if( selectDN ) {
189
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), selectDN);
190
                g_free( selectDN );
191
                selectDN = NULL;
192
        }
193
        g_free( sHost );
194
        g_free( sBase );
195
        g_free( sBind );
196
        g_free( sPass );
197
}
198

    
199
static void edit_ldap_search_reset( void ) {
200
        gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), SYLDAP_DFL_CRITERIA );
201
}
202

    
203
static void addressbook_edit_ldap_dialog_create( gboolean *cancelled ) {
204
        GtkWidget *window;
205
        GtkWidget *vbox;
206
        GtkWidget *notebook;
207
        GtkWidget *hbbox;
208
        GtkWidget *ok_btn;
209
        GtkWidget *cancel_btn;
210
        GtkWidget *hsbox;
211
        GtkWidget *statusbar;
212

    
213
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
214
        gtk_widget_set_size_request(window, 450, -1);
215
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
216
        gtk_window_set_title(GTK_WINDOW(window), _("Edit LDAP Server"));
217
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
218
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);        
219
        g_signal_connect(G_OBJECT(window), "delete_event",
220
                         G_CALLBACK(edit_ldap_delete_event),
221
                         cancelled);
222
        g_signal_connect(G_OBJECT(window), "key_press_event",
223
                         G_CALLBACK(edit_ldap_key_pressed),
224
                         cancelled);
225

    
226
        vbox = gtk_vbox_new( FALSE, 6 );
227
        /* gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH); */
228
        gtk_widget_show( vbox );
229
        gtk_container_add( GTK_CONTAINER( window ), vbox );
230

    
231
        /* Notebook */
232
        notebook = gtk_notebook_new();
233
        gtk_widget_show( notebook );
234
        gtk_box_pack_start( GTK_BOX( vbox ), notebook, TRUE, TRUE, 0 );
235
        gtk_container_set_border_width( GTK_CONTAINER( notebook ), 6 );
236

    
237
        /* Status line */
238
        hsbox = gtk_hbox_new(FALSE, 0);
239
        gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
240
        statusbar = gtk_statusbar_new();
241
        gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
242

    
243
        /* Button panel */
244
        gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
245
                                &cancel_btn, _("Cancel"), NULL, NULL);
246
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
247
        gtk_widget_grab_default(ok_btn);
248

    
249
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
250
                         G_CALLBACK(edit_ldap_ok), cancelled);
251
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
252
                         G_CALLBACK(edit_ldap_cancel), cancelled);
253
        g_signal_connect(G_OBJECT(notebook), "switch_page",
254
                         G_CALLBACK(edit_ldap_switch_page), NULL );
255

    
256
        gtk_widget_show_all(vbox);
257

    
258
        ldapedit.window     = window;
259
        ldapedit.notebook   = notebook;
260
        ldapedit.ok_btn     = ok_btn;
261
        ldapedit.cancel_btn = cancel_btn;
262
        ldapedit.statusbar  = statusbar;
263
        ldapedit.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit LDAP Server Dialog" );
264
}
265

    
266
void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
267
        GtkWidget *vbox;
268
        GtkWidget *table;
269
        GtkWidget *label;
270
        GtkWidget *entry_name;
271
        GtkWidget *entry_server;
272
        GtkWidget *hbox_spin;
273
        GtkObject *spinbtn_port_adj;
274
        GtkWidget *spinbtn_port;
275
        GtkWidget *entry_baseDN;
276
        GtkWidget *check_btn;
277
        GtkWidget *lookdn_btn;
278
        gint top;
279

    
280
        vbox = gtk_vbox_new( FALSE, 8 );
281
        gtk_widget_show( vbox );
282
        gtk_container_add( GTK_CONTAINER( ldapedit.notebook ), vbox );
283
        /* gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); */
284

    
285
        label = gtk_label_new( pageLbl );
286
        gtk_widget_show( label );
287
        gtk_notebook_set_tab_label(
288
                GTK_NOTEBOOK( ldapedit.notebook ),
289
                gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit.notebook ), pageNum ), label );
290

    
291
        table = gtk_table_new( LDAPEDIT_TABLE_ROWS, LDAPEDIT_TABLE_COLS, FALSE);
292
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
293
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
294
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
295
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
296

    
297
        /* First row */
298
        top = 0;
299
        label = gtk_label_new(_("Name"));
300
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
301
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
302

    
303
        entry_name = gtk_entry_new();
304
        gtk_table_attach(GTK_TABLE(table), entry_name, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
305

    
306
        /* Next row */
307
        ++top;
308
        label = gtk_label_new(_("Hostname"));
309
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
310
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
311

    
312
        entry_server = gtk_entry_new();
313
        gtk_table_attach(GTK_TABLE(table), entry_server, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
314

    
315
        /* Next row */
316
        ++top;
317
        label = gtk_label_new(_("Port"));
318
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
319
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
320

    
321
        hbox_spin = gtk_hbox_new (FALSE, 8);
322
        spinbtn_port_adj = gtk_adjustment_new (389, 1, 65535, 100, 1000, 1000);
323
        spinbtn_port = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_port_adj), 1, 0);
324
        gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_port, FALSE, FALSE, 0);
325
        gtk_widget_set_size_request (spinbtn_port, 64, -1);
326
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_port), TRUE);
327
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
328

    
329
        check_btn = gtk_button_new_with_label( _(" Check Server "));
330
        gtk_table_attach(GTK_TABLE(table), check_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
331

    
332
        /* Next row */
333
        ++top;
334
        label = gtk_label_new(_("Search Base"));
335
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
336
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
337

    
338
        entry_baseDN = gtk_entry_new();
339
        gtk_table_attach(GTK_TABLE(table), entry_baseDN, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
340

    
341
        lookdn_btn = gtk_button_new_with_label( _(" ... "));
342
        gtk_table_attach(GTK_TABLE(table), lookdn_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
343

    
344
        g_signal_connect(G_OBJECT(check_btn), "clicked",
345
                         G_CALLBACK(edit_ldap_server_check), NULL);
346
        g_signal_connect(G_OBJECT(lookdn_btn), "clicked",
347
                         G_CALLBACK(edit_ldap_basedn_select), NULL);
348

    
349
        gtk_widget_show_all(vbox);
350

    
351
        ldapedit.entry_name   = entry_name;
352
        ldapedit.entry_server = entry_server;
353
        ldapedit.spinbtn_port = spinbtn_port;
354
        ldapedit.entry_baseDN = entry_baseDN;
355
}
356

    
357
void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl ) {
358
        GtkWidget *vbox;
359
        GtkWidget *table;
360
        GtkWidget *label;
361
        GtkWidget *entry_bindDN;
362
        GtkWidget *entry_bindPW;
363
        GtkWidget *entry_criteria;
364
        GtkWidget *hbox_spin;
365
        GtkObject *spinbtn_timeout_adj;
366
        GtkWidget *spinbtn_timeout;
367
        GtkObject *spinbtn_maxentry_adj;
368
        GtkWidget *spinbtn_maxentry;
369
        GtkWidget *reset_btn;
370
        gint top;
371

    
372
        vbox = gtk_vbox_new( FALSE, 8 );
373
        gtk_widget_show( vbox );
374
        gtk_container_add( GTK_CONTAINER( ldapedit.notebook ), vbox );
375
        /* gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); */
376

    
377
        label = gtk_label_new( pageLbl );
378
        gtk_widget_show( label );
379
        gtk_notebook_set_tab_label(
380
                GTK_NOTEBOOK( ldapedit.notebook ),
381
                gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit.notebook ), pageNum ), label );
382

    
383
        table = gtk_table_new( LDAPEDIT_TABLE_ROWS, LDAPEDIT_TABLE_COLS, FALSE);
384
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
385
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
386
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
387
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
388

    
389
        /* First row */
390
        top = 0;
391
        label = gtk_label_new(_("Search Criteria"));
392
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
393
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
394

    
395
        entry_criteria = gtk_entry_new();
396
        gtk_table_attach(GTK_TABLE(table), entry_criteria, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
397

    
398
        reset_btn = gtk_button_new_with_label( _(" Reset "));
399
        gtk_table_attach(GTK_TABLE(table), reset_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
400

    
401
        /* Next row */
402
        ++top;
403
        label = gtk_label_new(_("Bind DN"));
404
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
405
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
406

    
407
        entry_bindDN = gtk_entry_new();
408
        gtk_table_attach(GTK_TABLE(table), entry_bindDN, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
409

    
410
        /* Next row */
411
        ++top;
412
        label = gtk_label_new(_("Bind Password"));
413
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
414
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
415

    
416
        entry_bindPW = gtk_entry_new();
417
        gtk_table_attach(GTK_TABLE(table), entry_bindPW, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
418

    
419
        /* Next row */
420
        ++top;
421
        label = gtk_label_new(_("Timeout (secs)"));
422
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
423
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
424

    
425
        hbox_spin = gtk_hbox_new (FALSE, 8);
426
        spinbtn_timeout_adj = gtk_adjustment_new (0, 0, 300, 1, 10, 10);
427
        spinbtn_timeout = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_timeout_adj), 1, 0);
428
        gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_timeout, FALSE, FALSE, 0);
429
        gtk_widget_set_size_request (spinbtn_timeout, 64, -1);
430
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_timeout), TRUE);
431
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
432

    
433
        /* Next row */
434
        ++top;
435
        label = gtk_label_new(_("Maximum Entries"));
436
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
437
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
438

    
439
        hbox_spin = gtk_hbox_new (FALSE, 8);
440
        spinbtn_maxentry_adj = gtk_adjustment_new (0, 0, 500, 1, 10, 10);
441
        spinbtn_maxentry = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_maxentry_adj), 1, 0);
442
        gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_maxentry, FALSE, FALSE, 0);
443
        gtk_widget_set_size_request (spinbtn_maxentry, 64, -1);
444
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_maxentry), TRUE);
445
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
446

    
447
        g_signal_connect(G_OBJECT(reset_btn), "clicked",
448
                         G_CALLBACK(edit_ldap_search_reset), NULL);
449

    
450
        gtk_widget_show_all(vbox);
451

    
452
        ldapedit.entry_criteria   = entry_criteria;
453
        ldapedit.entry_bindDN     = entry_bindDN;
454
        ldapedit.entry_bindPW     = entry_bindPW;
455
        ldapedit.spinbtn_timeout  = spinbtn_timeout;
456
        ldapedit.spinbtn_maxentry = spinbtn_maxentry;
457
}
458

    
459
static void addressbook_edit_ldap_create( gboolean *cancelled ) {
460
        gint page = 0;
461
        addressbook_edit_ldap_dialog_create( cancelled );
462
        addressbook_edit_ldap_page_basic( page++, _( "Basic" ) );
463
        addressbook_edit_ldap_page_extended( page++, _( "Extended" ) );
464
        gtk_widget_show_all( ldapedit.window );
465
}
466

    
467
void edit_ldap_set_optmenu( GtkOptionMenu *optmenu, const gint value ) {
468
        GList *cur;
469
        GtkWidget *menu;
470
        GtkWidget *menuitem;
471
        gint menuVal;
472
        gint n = 0;
473

    
474
        g_return_if_fail(optmenu != NULL);
475

    
476
        menu = gtk_option_menu_get_menu(optmenu);
477
        for( cur = GTK_MENU_SHELL(menu)->children; cur != NULL; cur = cur->next ) {
478
                menuitem = GTK_WIDGET(cur->data);
479
                menuVal = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), "user_data"));
480
                if( menuVal == value ) {
481
                        gtk_option_menu_set_history(optmenu, n);
482
                        return;
483
                }
484
                n++;
485
        }
486
        gtk_option_menu_set_history(optmenu, 0);
487
}
488

    
489
gint edit_ldap_get_optmenu( GtkOptionMenu *optmenu ) {
490
        GtkWidget *menu;
491
        GtkWidget *menuitem;
492

    
493
        g_return_val_if_fail(optmenu != NULL, -1);
494

    
495
        menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
496
        menuitem = gtk_menu_get_active(GTK_MENU(menu));
497
        return GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), "user_data"));
498
}
499

    
500
AdapterDSource *addressbook_edit_ldap( AddressIndex *addrIndex, AdapterDSource *ads ) {
501
        static gboolean cancelled;
502
        gchar *sName, *sHost, *sBase, *sBind, *sPass, *sCrit;
503
        gint iPort, iMaxE, iTime;
504
        AddressDataSource *ds = NULL;
505
        SyldapServer *server = NULL;
506
        gboolean fin;
507

    
508
        if (!ldapedit.window)
509
                addressbook_edit_ldap_create(&cancelled);
510
        gtk_notebook_set_current_page( GTK_NOTEBOOK(ldapedit.notebook), 0 );
511
        gtk_widget_grab_focus(ldapedit.ok_btn);
512
        gtk_widget_grab_focus(ldapedit.entry_name);
513
        gtk_widget_show(ldapedit.window);
514
        manage_window_set_transient(GTK_WINDOW(ldapedit.window));
515

    
516
        edit_ldap_status_show( "" );
517
        if( ads ) {
518
                ds = ads->dataSource;
519
                server = ds->rawDataSource;
520
                if (server->name)
521
                        gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_name), server->name);
522
                if (server->hostName)
523
                        gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_server), server->hostName);
524
                gtk_spin_button_set_value( GTK_SPIN_BUTTON( ldapedit.spinbtn_port ), server->port );
525
                gtk_spin_button_set_value( GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ), server->timeOut );
526
                if (server->baseDN)
527
                        gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), server->baseDN);
528
                if (server->searchCriteria)
529
                        gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), server->searchCriteria);
530
                if (server->bindDN)
531
                        gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindDN), server->bindDN);
532
                if (server->bindPass)
533
                        gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindPW), server->bindPass);
534
                gtk_spin_button_set_value( GTK_SPIN_BUTTON( ldapedit.spinbtn_maxentry ), server->maxEntries );
535
                gtk_window_set_title( GTK_WINDOW(ldapedit.window), _("Edit LDAP Server"));
536
        }
537
        else {
538
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_name), ADDRESSBOOK_GUESS_LDAP_NAME );
539
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_server), ADDRESSBOOK_GUESS_LDAP_SERVER );
540
                gtk_spin_button_set_value( GTK_SPIN_BUTTON( ldapedit.spinbtn_port ), SYLDAP_DFL_PORT );
541
                gtk_spin_button_set_value( GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ), SYLDAP_DFL_TIMEOUT );
542
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), "");
543
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), SYLDAP_DFL_CRITERIA );
544
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindDN), "");
545
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindPW), "");
546
                gtk_spin_button_set_value( GTK_SPIN_BUTTON( ldapedit.spinbtn_maxentry ), SYLDAP_MAX_ENTRIES );
547
                gtk_window_set_title( GTK_WINDOW(ldapedit.window), _("Add New LDAP Server"));
548
        }
549

    
550
        gtk_main();
551
        gtk_widget_hide(ldapedit.window);
552
        if (cancelled == TRUE) return NULL;
553

    
554
        fin = FALSE;
555
        sName = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_name), 0, -1 );
556
        sHost = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_server), 0, -1 );
557
        iPort = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_port ) );
558
        iTime = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ) );
559
        sBase = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_baseDN), 0, -1 );
560
        sCrit = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_criteria), 0, -1 );
561
        sBind = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindDN), 0, -1 );
562
        sPass = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindPW), 0, -1 );
563
        iMaxE = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_maxentry ) );
564

    
565
        if( *sName == '\0' ) fin = TRUE;
566
        if( *sHost == '\0' ) fin = TRUE;
567
        if( *sBase == '\0' ) fin = TRUE;
568

    
569
        if( ! fin ) {
570
                if( ! ads ) {
571
                        server = syldap_create();
572
                        ds = addrindex_index_add_datasource( addrIndex, ADDR_IF_LDAP, server );
573
                        ads = addressbook_create_ds_adapter( ds, ADDR_LDAP, NULL );
574
                }
575
                addressbook_ads_set_name( ads, sName );
576
                syldap_set_name( server, sName );
577
                syldap_set_host( server, sHost );
578
                syldap_set_port( server, iPort );
579
                syldap_set_base_dn( server, sBase );
580
                syldap_set_bind_dn( server, sBind );
581
                syldap_set_bind_password( server, sPass );
582
                syldap_set_search_criteria( server, sCrit );
583
                syldap_set_max_entries( server, iMaxE );
584
                syldap_set_timeout( server, iTime );
585
        }
586
        g_free( sName );
587
        g_free( sHost );
588
        g_free( sBase );
589
        g_free( sBind );
590
        g_free( sPass );
591
        g_free( sCrit );
592

    
593
        return ads;
594
}
595

    
596
#endif /* USE_LDAP */
597

    
598
/*
599
* End of Source.
600
*/