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