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