2011-10-23 [holger] 3.7.10cvs43
[claws.git] / src / expldifdlg.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2011 Match Grun and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 /*
21  * Export address book to LDIF file.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtk.h>
34
35 #include "gtkutils.h"
36 #include "prefs_common.h"
37 #include "alertpanel.h"
38 #include "mgutils.h"
39 #include "addrcache.h"
40 #include "addressitem.h"
41 #include "exportldif.h"
42 #include "utils.h"
43 #include "manage_window.h"
44 #include "filesel.h"
45 #include "combobox.h"
46
47 #define PAGE_FILE_INFO             0
48 #define PAGE_DN                    1
49 #define PAGE_FINISH                2
50
51 #define EXPORTLDIF_WIDTH           480
52 #define EXPORTLDIF_HEIGHT          -1
53
54 /**
55  * Dialog object.
56  */
57 static struct _ExpLdif_Dlg {
58         GtkWidget *window;
59         GtkWidget *notebook;
60         GtkWidget *labelBook;
61         GtkWidget *entryLdif;
62         GtkWidget *entrySuffix;
63         GtkWidget *optmenuRDN;
64         GtkWidget *checkUseDN;
65         GtkWidget *checkEMail;
66         GtkWidget *labelOutBook;
67         GtkWidget *labelOutFile;
68         GtkWidget *btnPrev;
69         GtkWidget *btnNext;
70         GtkWidget *btnCancel;
71         GtkWidget *statusbar;
72         gint      status_cid;
73         gboolean  cancelled;
74 } expldif_dlg;
75
76 static struct _AddressFileSelection _exp_ldif_file_selector_;
77
78 static ExportLdifCtl *_exportCtl_ = NULL;
79 static AddressCache *_addressCache_ = NULL;
80
81 /**
82  * Display message in status field.
83  * \param msg Message to display.
84  */
85 static void export_ldif_status_show( gchar *msg ) {
86         if( expldif_dlg.statusbar != NULL ) {
87                 gtk_statusbar_pop(
88                         GTK_STATUSBAR(expldif_dlg.statusbar),
89                         expldif_dlg.status_cid );
90                 if( msg ) {
91                         gtk_statusbar_push(
92                                 GTK_STATUSBAR(expldif_dlg.statusbar),
93                                 expldif_dlg.status_cid, msg );
94                 }
95         }
96 }
97
98 /**
99  * Select and display status message appropriate for the page being displayed.
100  */
101 static void export_ldif_message( void ) {
102         gchar *sMsg = NULL;
103         gint pageNum;
104
105         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
106         if( pageNum == PAGE_FILE_INFO ) {
107                 sMsg = _( "Please specify output directory and LDIF filename to create." );
108         }
109         else if( pageNum == PAGE_DN ) {
110                 sMsg = _( "Specify parameters to format distinguished name." );
111         }
112         else if( pageNum == PAGE_FINISH ) {
113                 sMsg = _( "File exported successfully." );
114         }
115         export_ldif_status_show( sMsg );
116 }
117
118 /**
119  * Callback function to cancel LDIF file selection dialog.
120  * \param widget Widget (button).
121  * \param data   User data.
122  */
123 static void export_ldif_cancel( GtkWidget *widget, gpointer data ) {
124         gint pageNum;
125
126         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
127         if( pageNum != PAGE_FINISH ) {
128                 expldif_dlg.cancelled = TRUE;
129         }
130         gtk_main_quit();
131 }
132
133 /**
134  * Callback function to handle dialog close event.
135  * \param widget Widget (dialog).
136  * \param event  Event object.
137  * \param data   User data.
138  */
139 static gint export_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
140         export_ldif_cancel( widget, data );
141         return TRUE;
142 }
143
144 /**
145  * Callback function to respond to dialog key press events.
146  * \param widget Widget.
147  * \param event  Event object.
148  * \param data   User data.
149  */
150 static gboolean export_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
151         if (event && event->keyval == GDK_KEY_Escape) {
152                 export_ldif_cancel( widget, data );
153         }
154         return FALSE;
155 }
156
157 /**
158  * Test whether we can move off file page.
159  * \return <i>TRUE</i> if OK to move off page.
160  */
161 static gboolean exp_ldif_move_file( void ) {
162         gchar *sFile, *msg, *reason;
163         gboolean errFlag = FALSE;
164         AlertValue aval;
165
166         sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
167         g_strchug( sFile ); g_strchomp( sFile );
168         gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
169         exportldif_parse_filespec( _exportCtl_, sFile );
170
171         /* Test that something was supplied */
172         if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
173                 gtk_widget_grab_focus( expldif_dlg.entryLdif );
174                 errFlag = TRUE;
175         }
176         g_free( sFile );
177         if( errFlag ) return FALSE;
178
179         /* Test for directory */
180         if( exportldif_test_dir( _exportCtl_ ) ) {
181                 return TRUE;
182         }
183
184         /* Prompt to create */
185         msg = g_strdup_printf( _(
186                 "LDIF Output Directory '%s'\n" \
187                 "does not exist. OK to create new directory?" ),
188                 _exportCtl_->dirOutput );
189         aval = alertpanel( _("Create Directory" ),
190                 msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
191         g_free( msg );
192         if( aval != G_ALERTALTERNATE ) return FALSE;
193
194         /* Create directory */
195         if( ! exportldif_create_dir( _exportCtl_ ) ) {
196                 reason = exportldif_get_create_msg( _exportCtl_ );
197                 msg = g_strdup_printf( _(
198                         "Could not create output directory for LDIF file:\n%s" ),
199                         reason );
200                 aval = alertpanel_full(_("Failed to Create Directory"), msg,
201                                        GTK_STOCK_CLOSE, NULL, NULL, FALSE,
202                                        NULL, ALERT_ERROR, G_ALERTDEFAULT);
203                 g_free( msg );
204                 return FALSE;
205         }
206
207         return TRUE;
208 }
209
210 /**
211  * Test whether we can move off distinguished name page.
212  * \return <i>TRUE</i> if OK to move off page.
213  */
214 static gboolean exp_ldif_move_dn( void ) {
215         gboolean retVal = FALSE;
216         gboolean errFlag = FALSE;
217         gchar *suffix;
218         gint id;
219
220         /* Set suffix */
221         suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
222         g_strchug( suffix ); g_strchomp( suffix );
223
224         /* Set RDN format */
225         id = combobox_get_active_data(GTK_COMBO_BOX(expldif_dlg.optmenuRDN));
226         exportldif_set_rdn( _exportCtl_, id );
227
228         exportldif_set_suffix( _exportCtl_, suffix );
229         exportldif_set_use_dn( _exportCtl_,
230                 gtk_toggle_button_get_active(
231                         GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
232         exportldif_set_exclude_email( _exportCtl_,
233                 gtk_toggle_button_get_active(
234                         GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );
235
236         if( *suffix == '\0' || strlen( suffix ) < 1 ) {
237                 AlertValue aval;
238
239                 aval = alertpanel(
240                         _( "Suffix was not supplied" ),
241                         _(
242                                 "A suffix is required if data is to be used " \
243                                 "for an LDAP server. Are you sure you wish " \
244                                 "to proceed without a suffix?"
245                          ),
246                         GTK_STOCK_NO, GTK_STOCK_YES, NULL );
247                 if( aval != G_ALERTALTERNATE ) {
248                         gtk_widget_grab_focus( expldif_dlg.entrySuffix );
249                         errFlag = TRUE;
250                 }
251         }
252
253         if( ! errFlag ) {
254                 /* Process export */
255                 exportldif_process( _exportCtl_, _addressCache_ );
256                 if( _exportCtl_->retVal == MGU_SUCCESS ) {
257                         retVal = TRUE;
258                 }
259                 else {
260                         export_ldif_status_show( _( "Error creating LDIF file" ) );
261                 }
262         }
263
264         return retVal;
265 }
266
267 /**
268  * Display finish page.
269  */
270 static void exp_ldif_finish_show( void ) {
271         gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutFile), _exportCtl_->path );
272         gtk_widget_set_sensitive( expldif_dlg.btnNext, FALSE );
273         gtk_widget_grab_focus( expldif_dlg.btnCancel );
274 }
275
276 /**
277  * Callback function to select previous page.
278  * \param widget Widget (button).
279  */
280 static void export_ldif_prev( GtkWidget *widget ) {
281         gint pageNum;
282
283         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
284         if( pageNum == PAGE_DN ) {
285                 /* Goto file page stuff */
286                 gtk_notebook_set_current_page(
287                         GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
288                 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
289         }
290         else if( pageNum == PAGE_FINISH ) {
291                 /* Goto format page */
292                 gtk_notebook_set_current_page(
293                         GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
294                 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
295         }
296         export_ldif_message();
297 }
298
299 /**
300  * Callback function to select next page.
301  * \param widget Widget (button).
302  */
303 static void export_ldif_next( GtkWidget *widget ) {
304         gint pageNum;
305
306         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
307         if( pageNum == PAGE_FILE_INFO ) {
308                 /* Goto distinguished name page */
309                 if( exp_ldif_move_file() ) {
310                         gtk_notebook_set_current_page(
311                                 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
312                         gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE );
313                 }
314                 export_ldif_message();
315         }
316         else if( pageNum == PAGE_DN ) {
317                 /* Goto finish page */
318                 if( exp_ldif_move_dn() ) {
319                         gtk_notebook_set_current_page(
320                                 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH );
321                         gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
322                                 GTK_STOCK_CLOSE);
323                         exp_ldif_finish_show();
324                         exportldif_save_settings( _exportCtl_ );
325                         export_ldif_message();
326                 }
327         }
328 }
329
330 /**
331  * Create LDIF file selection dialog.
332  * \param afs Address file selection data.
333  */
334 static void exp_ldif_file_select_create( AddressFileSelection *afs ) {
335         gchar *file = filesel_select_file_save(_("Select LDIF output file"), NULL);
336         
337         if (file == NULL)
338                 afs->cancelled = TRUE;
339         else {
340                 afs->cancelled = FALSE;
341                 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), file );
342                 g_free(file);
343         }
344 }
345
346 /**
347  * Callback function to display LDIF file selection dialog.
348  */
349 static void exp_ldif_file_select( void ) {
350         exp_ldif_file_select_create( & _exp_ldif_file_selector_ );
351 }
352
353 /**
354  * Format notebook file specification page.
355  * \param pageNum Page (tab) number.
356  * \param pageLbl Page (tab) label.
357  */
358 static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) {
359         GtkWidget *vbox;
360         GtkWidget *table;
361         GtkWidget *label;
362         GtkWidget *labelBook;
363         GtkWidget *entryLdif;
364         GtkWidget *btnFile;
365         gint top;
366
367         vbox = gtk_vbox_new(FALSE, 8);
368         gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
369         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
370
371         label = gtk_label_new( pageLbl );
372         gtk_widget_show( label );
373         gtk_notebook_set_tab_label(
374                 GTK_NOTEBOOK( expldif_dlg.notebook ),
375                 gtk_notebook_get_nth_page(
376                         GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
377                 label );
378
379         table = gtk_table_new( 3, 3, FALSE );
380         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
381         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
382         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
383         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
384
385         /* First row */
386         top = 0;
387         label = gtk_label_new( _( "Address Book" ) );
388         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
389                 GTK_FILL, 0, 0, 0);
390         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
391
392         labelBook = gtk_label_new( "Address book name goes here" );
393         gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
394                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
395         gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
396
397         /* Second row */
398         top++;
399         label = gtk_label_new( _( "LDIF Output File" ) );
400         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
401                 GTK_FILL, 0, 0, 0);
402         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
403
404         entryLdif = gtk_entry_new();
405         gtk_table_attach(GTK_TABLE(table), entryLdif, 1, 2, top, (top + 1),
406                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
407
408         btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
409         gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
410                 GTK_FILL, 0, 3, 0);
411
412         gtk_widget_show_all(vbox);
413
414         /* Button handler */
415         g_signal_connect(G_OBJECT(btnFile), "clicked",
416                          G_CALLBACK(exp_ldif_file_select), NULL);
417
418         expldif_dlg.labelBook = labelBook;
419         expldif_dlg.entryLdif = entryLdif;
420 }
421
422 static void export_ldif_relative_dn_changed(GtkWidget *widget, gpointer data)
423 {
424         gint relativeDN = combobox_get_active_data(GTK_COMBO_BOX(widget));
425         GtkLabel *label = GTK_LABEL(data);
426
427         switch(relativeDN) {
428         case EXPORT_LDIF_ID_UID:
429                 gtk_label_set_text(label,
430                 _("The address book Unique ID is used to create a DN that is " \
431                 "formatted similar to:\n" \
432                 "  uid=102376,ou=people,dc=claws-mail,dc=org"));
433                 break;
434         case EXPORT_LDIF_ID_DNAME:
435                 gtk_label_set_text(label,
436                 _("The address book Display Name is used to create a DN that " \
437                 "is formatted similar to:\n" \
438                 "  cn=John Doe,ou=people,dc=claws-mail,dc=org"));       
439                 break;
440         case EXPORT_LDIF_ID_EMAIL:
441                 gtk_label_set_text(label, 
442                 _("The first Email Address belonging to a person is used to " \
443                 "create a DN that is formatted similar to:\n" \
444                 "  mail=john.doe@domain.com,ou=people,dc=claws-mail,dc=org"));  
445                 break;
446         }
447         
448 }
449
450 /**
451  * Format notebook distinguished name page.
452  * \param pageNum Page (tab) number.
453  * \param pageLbl Page (tab) label.
454  */
455 static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) {
456         GtkWidget *vbox;
457         GtkWidget *table;
458         GtkWidget *label;
459         GtkWidget *entrySuffix;
460         GtkWidget *optmenuRDN;
461         GtkWidget *labelRDN;
462         GtkWidget *checkUseDN;
463         GtkWidget *checkEMail;
464         GtkListStore *store;
465         GtkTreeIter iter;
466         gint top;
467
468         vbox = gtk_vbox_new(FALSE, 8);
469         gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
470         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
471
472         label = gtk_label_new( pageLbl );
473         gtk_widget_show( label );
474         gtk_notebook_set_tab_label(
475                 GTK_NOTEBOOK( expldif_dlg.notebook ),
476                 gtk_notebook_get_nth_page(
477                         GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
478                 label );
479
480         table = gtk_table_new( 6, 2, FALSE );
481         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
482         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
483         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
484         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
485
486         /* First row */
487         top = 0;
488         label = gtk_label_new( _( "Suffix" ) );
489         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
490                 GTK_FILL, 0, 0, 0);
491         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
492
493         entrySuffix = gtk_entry_new();
494         gtk_table_attach(GTK_TABLE(table), entrySuffix, 1, 2, top, (top + 1),
495                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
496
497         CLAWS_SET_TIP(entrySuffix, _(
498                 "The suffix is used to create a \"Distinguished Name\" " \
499                 "(or DN) for an LDAP entry. Examples include:\n" \
500                 "  dc=claws-mail,dc=org\n" \
501                 "  ou=people,dc=domainname,dc=com\n" \
502                 "  o=Organization Name,c=Country\n"));
503
504         /* Second row */
505         top++;
506         label = gtk_label_new( _( "Relative DN" ) );
507         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
508                 GTK_FILL, 0, 0, 0);
509         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
510
511         optmenuRDN = gtkut_sc_combobox_create(NULL, TRUE);
512         store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuRDN)));
513         
514         COMBOBOX_ADD(store, _("Unique ID"), EXPORT_LDIF_ID_UID);
515         COMBOBOX_ADD(store, _("Display Name"), EXPORT_LDIF_ID_DNAME);
516         COMBOBOX_ADD(store, _("Email Address"), EXPORT_LDIF_ID_EMAIL);
517
518         gtk_table_attach(GTK_TABLE(table), optmenuRDN, 1, 2, top, (top + 1),
519                 GTK_FILL, 0, 0, 0);
520
521         CLAWS_SET_TIP(optmenuRDN, _(
522                 "The LDIF file contains several data records that " \
523                 "are usually loaded into an LDAP server. Each data " \
524                 "record in the LDIF file is uniquely identified by " \
525                 "a \"Distinguished Name\" (or DN). The suffix is " \
526                 "appended to the \"Relative Distinguished Name\" "\
527                 "(or RDN) to create the DN. Please select one of " \
528                 "the available RDN options that will be used to " \
529                 "create the DN."));
530         
531         /* Third row*/
532         top++;
533         labelRDN = gtk_label_new("");
534         gtk_label_set_line_wrap(GTK_LABEL(labelRDN), TRUE);
535         gtk_label_set_justify(GTK_LABEL(labelRDN), GTK_JUSTIFY_CENTER);
536         gtk_table_attach(GTK_TABLE(table), labelRDN, 0, 2, top, (top + 1),
537                 GTK_FILL, 0, 0, 0);
538                 
539         /* Fourth row */
540         top++;
541         checkUseDN = gtk_check_button_new_with_label(
542                         _( "Use DN attribute if present in data" ) );
543         gtk_table_attach(GTK_TABLE(table), checkUseDN, 1, 2, top, (top + 1),
544                 GTK_FILL, 0, 0, 0);
545
546         CLAWS_SET_TIP(checkUseDN, _(
547                 "The addressbook may contain entries that were " \
548                 "previously imported from an LDIF file. The " \
549                 "\"Distinguished Name\" (DN) user attribute, if " \
550                 "present in the address book data, may be used in " \
551                 "the exported LDIF file. The RDN selected above " \
552                 "will be used if the DN user attribute is not found."));
553
554         /* Fifth row */
555         top++;
556         checkEMail = gtk_check_button_new_with_label(
557                         _( "Exclude record if no Email Address" ) );
558         gtk_table_attach(GTK_TABLE(table), checkEMail, 1, 2, top, (top + 1),
559                 GTK_FILL, 0, 0, 0);
560
561         CLAWS_SET_TIP(checkEMail, _(
562                 "An addressbook may contain entries without " \
563                 "Email Addresses. Check this option to ignore " \
564                 "these records."));
565
566
567         gtk_widget_show_all(vbox);
568
569         g_signal_connect(G_OBJECT(optmenuRDN), "changed",
570                 G_CALLBACK(export_ldif_relative_dn_changed), labelRDN);
571         gtk_combo_box_set_active(GTK_COMBO_BOX(optmenuRDN), 0);
572
573
574         expldif_dlg.entrySuffix = entrySuffix;
575         expldif_dlg.optmenuRDN  = optmenuRDN;
576         expldif_dlg.checkUseDN  = checkUseDN;
577         expldif_dlg.checkEMail  = checkEMail;
578 }
579
580 /**
581  * Format notebook finish page.
582  * \param pageNum Page (tab) number.
583  * \param pageLbl Page (tab) label.
584  */
585 static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
586         GtkWidget *vbox;
587         GtkWidget *table;
588         GtkWidget *label;
589         GtkWidget *labelBook;
590         GtkWidget *labelFile;
591         gint top;
592
593         vbox = gtk_vbox_new(FALSE, 8);
594         gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
595         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
596
597         label = gtk_label_new( pageLbl );
598         gtk_widget_show( label );
599         gtk_notebook_set_tab_label(
600                 GTK_NOTEBOOK( expldif_dlg.notebook ),
601                 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
602
603         table = gtk_table_new( 3, 3, FALSE );
604         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
605         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
606         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
607         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
608
609         /* First row */
610         top = 0;
611         label = gtk_label_new( _( "Address Book :" ) );
612         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
613         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
614
615         labelBook = gtk_label_new("Full name of address book goes here");
616         gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
617         gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
618
619         /* Second row */
620         top++;
621         label = gtk_label_new( _( "File Name :" ) );
622         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
623         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
624
625         labelFile = gtk_label_new("File name goes here");
626         gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
627         gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
628
629         gtk_widget_show_all(vbox);
630
631         expldif_dlg.labelOutBook = labelBook;
632         expldif_dlg.labelOutFile = labelFile;
633 }
634
635 /**
636  * Create main dialog decorations (excluding notebook pages).
637  */
638 static void export_ldif_dialog_create( void ) {
639         GtkWidget *window;
640         GtkWidget *vbox;
641         GtkWidget *vnbox;
642         GtkWidget *notebook;
643         GtkWidget *hbbox;
644         GtkWidget *btnPrev;
645         GtkWidget *btnNext;
646         GtkWidget *btnCancel;
647         GtkWidget *hsbox;
648         GtkWidget *statusbar;
649
650         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "expldifdlg");
651         gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
652         gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
653         gtk_window_set_title( GTK_WINDOW(window),
654                 _("Export Address Book to LDIF File") );
655         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
656         g_signal_connect(G_OBJECT(window), "delete_event",
657                          G_CALLBACK(export_ldif_delete_event),
658                          NULL );
659         g_signal_connect(G_OBJECT(window), "key_press_event",
660                          G_CALLBACK(export_ldif_key_pressed),
661                          NULL );
662
663         vbox = gtk_vbox_new(FALSE, 4);
664         gtk_widget_show(vbox);
665         gtk_container_add(GTK_CONTAINER(window), vbox);
666
667         vnbox = gtk_vbox_new(FALSE, 4);
668         gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
669         gtk_widget_show(vnbox);
670         gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
671
672         /* Notebook */
673         notebook = gtk_notebook_new();
674         gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
675         /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
676         gtk_widget_show(notebook);
677         gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
678         gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
679
680         /* Status line */
681         hsbox = gtk_hbox_new(FALSE, 0);
682         gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
683         statusbar = gtk_statusbar_new();
684         gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
685
686         /* Button panel */
687         gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
688                                       &btnNext, GTK_STOCK_GO_FORWARD,
689                                       &btnCancel, GTK_STOCK_CANCEL);
690         gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
691         gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
692         gtk_widget_grab_default(btnNext);
693
694         /* Button handlers */
695         g_signal_connect(G_OBJECT(btnPrev), "clicked",
696                          G_CALLBACK(export_ldif_prev), NULL);
697         g_signal_connect(G_OBJECT(btnNext), "clicked",
698                          G_CALLBACK(export_ldif_next), NULL);
699         g_signal_connect(G_OBJECT(btnCancel), "clicked",
700                          G_CALLBACK(export_ldif_cancel), NULL);
701
702         gtk_widget_show_all(vbox);
703
704         expldif_dlg.window     = window;
705         expldif_dlg.notebook   = notebook;
706         expldif_dlg.btnPrev    = btnPrev;
707         expldif_dlg.btnNext    = btnNext;
708         expldif_dlg.btnCancel  = btnCancel;
709         expldif_dlg.statusbar  = statusbar;
710         expldif_dlg.status_cid = gtk_statusbar_get_context_id(
711                         GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
712 }
713
714 /**
715  * Create export LDIF dialog.
716  */
717 static void export_ldif_create( void ) {
718         export_ldif_dialog_create();
719         export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
720         export_ldif_page_dn( PAGE_DN, _( "Distinguished Name" ) );
721         export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
722         gtk_widget_show_all( expldif_dlg.window );
723 }
724
725 /**
726  * Populate fields from control data.
727  * \param ctl   Export control data.
728  */
729 static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
730         gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
731         if( ctl->path ) {
732                 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
733                         ctl->path );
734         }
735         gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
736         if( ctl->suffix ) {
737                 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
738                         ctl->suffix );
739         }
740
741         gtk_combo_box_set_active(
742                 GTK_COMBO_BOX( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
743         gtk_toggle_button_set_active(
744                 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
745         gtk_toggle_button_set_active(
746                 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
747 }
748
749 /**
750  * Process export address dialog.
751  * \param cache Address book/data source cache.
752  */
753 void addressbook_exp_ldif( AddressCache *cache ) {
754         /* Set references to control data */
755         _addressCache_ = cache;
756
757         _exportCtl_ = exportldif_create();
758         exportldif_load_settings( _exportCtl_ );
759
760         /* Setup GUI */
761         if( ! expldif_dlg.window )
762                 export_ldif_create();
763
764         gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
765                              GTK_STOCK_CANCEL);
766         expldif_dlg.cancelled = FALSE;
767         gtk_widget_show(expldif_dlg.window);
768         manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
769         gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), TRUE);
770         gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
771         gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
772         export_ldif_fill_fields( _exportCtl_ );
773
774         gtk_widget_grab_default(expldif_dlg.btnNext);
775         gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
776         gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
777         gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
778
779         export_ldif_message();
780         gtk_widget_grab_focus(expldif_dlg.entryLdif);
781
782         gtk_main();
783         gtk_widget_hide(expldif_dlg.window);
784         gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), FALSE);
785         exportldif_free( _exportCtl_ );
786         _exportCtl_ = NULL;
787
788         _addressCache_ = NULL;
789 }
790
791 /*
792  * ============================================================================
793  * End of Source.
794  * ============================================================================
795  */
796