2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003 Match Grun
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.
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.
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.
21 * Export address book to LDIF file.
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkwindow.h>
34 #include <gtk/gtksignal.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkentry.h>
37 #include <gtk/gtktable.h>
38 #include <gtk/gtkbutton.h>
41 #include "prefs_common.h"
42 #include "alertpanel.h"
44 #include "addrcache.h"
45 #include "addressitem.h"
46 #include "exportldif.h"
48 #include "manage_window.h"
50 #define PAGE_FILE_INFO 0
54 #define EXPORTLDIF_WIDTH 480
55 #define EXPORTLDIF_HEIGHT -1
60 static struct _ExpLdif_Dlg {
65 GtkWidget *entrySuffix;
66 GtkWidget *optmenuRDN;
67 GtkWidget *checkUseDN;
68 GtkWidget *checkEMail;
69 GtkWidget *labelOutBook;
70 GtkWidget *labelOutFile;
79 static struct _AddressFileSelection _exp_ldif_file_selector_;
81 static ExportLdifCtl *_exportCtl_ = NULL;
82 static AddressCache *_addressCache_ = NULL;
85 * Display message in status field.
86 * \param msg Message to display.
88 static void export_ldif_status_show( gchar *msg ) {
89 if( expldif_dlg.statusbar != NULL ) {
91 GTK_STATUSBAR(expldif_dlg.statusbar),
92 expldif_dlg.status_cid );
95 GTK_STATUSBAR(expldif_dlg.statusbar),
96 expldif_dlg.status_cid, msg );
102 * Select and display status message appropriate for the page being displayed.
104 static void export_ldif_message( void ) {
108 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
109 if( pageNum == PAGE_FILE_INFO ) {
110 sMsg = _( "Please specify output directory and LDIF filename to create." );
112 else if( pageNum == PAGE_DN ) {
113 sMsg = _( "Specify parameters to format distinguished name." );
115 else if( pageNum == PAGE_FINISH ) {
116 sMsg = _( "File exported successfully." );
118 export_ldif_status_show( sMsg );
122 * Callback function to cancel LDIF file selection dialog.
123 * \param widget Widget (button).
124 * \param data User data.
126 static void export_ldif_cancel( GtkWidget *widget, gpointer data ) {
129 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
130 if( pageNum != PAGE_FINISH ) {
131 expldif_dlg.cancelled = TRUE;
137 * Callback function to handle dialog close event.
138 * \param widget Widget (dialog).
139 * \param event Event object.
140 * \param data User data.
142 static gint export_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
143 export_ldif_cancel( widget, data );
148 * Callback function to respond to dialog key press events.
149 * \param widget Widget.
150 * \param event Event object.
151 * \param data User data.
153 static gboolean export_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
154 if (event && event->keyval == GDK_Escape) {
155 export_ldif_cancel( widget, data );
161 * Test whether we can move off file page.
162 * \return <i>TRUE</i> if OK to move off page.
164 static gboolean exp_ldif_move_file( void ) {
165 gchar *sFile, *msg, *reason;
166 gboolean errFlag = FALSE;
169 sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
170 g_strchug( sFile ); g_strchomp( sFile );
171 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
172 exportldif_parse_filespec( _exportCtl_, sFile );
174 /* Test that something was supplied */
175 if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
176 gtk_widget_grab_focus( expldif_dlg.entryLdif );
180 if( errFlag ) return FALSE;
182 /* Test for directory */
183 if( exportldif_test_dir( _exportCtl_ ) ) {
187 /* Prompt to create */
188 msg = g_strdup_printf( _(
189 "LDIF Output Directory '%s'\n" \
190 "does not exist. OK to create new directory?" ),
191 _exportCtl_->dirOutput );
192 aval = alertpanel( _("Create Directory" ),
193 msg, GTK_STOCK_YES, GTK_STOCK_NO, NULL );
195 if( aval != G_ALERTDEFAULT ) return FALSE;
197 /* Create directory */
198 if( ! exportldif_create_dir( _exportCtl_ ) ) {
199 reason = exportldif_get_create_msg( _exportCtl_ );
200 msg = g_strdup_printf( _(
201 "Could not create output directory for LDIF file:\n%s" ),
203 aval = alertpanel_full(_("Failed to Create Directory"), msg,
204 GTK_STOCK_CLOSE, NULL, NULL, FALSE,
205 NULL, ALERT_ERROR, G_ALERTDEFAULT);
214 * Test whether we can move off distinguished name page.
215 * \return <i>TRUE</i> if OK to move off page.
217 static gboolean exp_ldif_move_dn( void ) {
218 gboolean retVal = FALSE;
219 gboolean errFlag = FALSE;
221 GtkWidget *menu, *menuItem;
225 suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
226 g_strchug( suffix ); g_strchomp( suffix );
229 menu = gtk_option_menu_get_menu( GTK_OPTION_MENU( expldif_dlg.optmenuRDN ) );
230 menuItem = gtk_menu_get_active( GTK_MENU( menu ) );
231 id = GPOINTER_TO_INT( gtk_object_get_user_data(GTK_OBJECT(menuItem)) );
232 exportldif_set_rdn( _exportCtl_, id );
234 exportldif_set_suffix( _exportCtl_, suffix );
235 exportldif_set_use_dn( _exportCtl_,
236 gtk_toggle_button_get_active(
237 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
238 exportldif_set_exclude_email( _exportCtl_,
239 gtk_toggle_button_get_active(
240 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );
242 if( *suffix == '\0' || strlen( suffix ) < 1 ) {
246 _( "Suffix was not supplied" ),
248 "A suffix is required if data is to be used " \
249 "for an LDAP server. Are you sure you wish " \
250 "to proceed without a suffix?"
252 GTK_STOCK_YES, GTK_STOCK_NO, NULL );
253 if( aval != G_ALERTDEFAULT ) {
254 gtk_widget_grab_focus( expldif_dlg.entrySuffix );
261 exportldif_process( _exportCtl_, _addressCache_ );
262 if( _exportCtl_->retVal == MGU_SUCCESS ) {
266 export_ldif_status_show( _( "Error creating LDIF file" ) );
274 * Display finish page.
276 static void exp_ldif_finish_show( void ) {
277 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutFile), _exportCtl_->path );
278 gtk_widget_set_sensitive( expldif_dlg.btnNext, FALSE );
279 gtk_widget_grab_focus( expldif_dlg.btnCancel );
283 * Callback function to select previous page.
284 * \param widget Widget (button).
286 static void export_ldif_prev( GtkWidget *widget ) {
289 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
290 if( pageNum == PAGE_DN ) {
291 /* Goto file page stuff */
292 gtk_notebook_set_current_page(
293 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
294 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
296 else if( pageNum == PAGE_FINISH ) {
297 /* Goto format page */
298 gtk_notebook_set_current_page(
299 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
300 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
302 export_ldif_message();
306 * Callback function to select next page.
307 * \param widget Widget (button).
309 static void export_ldif_next( GtkWidget *widget ) {
312 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
313 if( pageNum == PAGE_FILE_INFO ) {
314 /* Goto distinguished name page */
315 if( exp_ldif_move_file() ) {
316 gtk_notebook_set_current_page(
317 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
318 gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE );
320 export_ldif_message();
322 else if( pageNum == PAGE_DN ) {
323 /* Goto finish page */
324 if( exp_ldif_move_dn() ) {
325 gtk_notebook_set_current_page(
326 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH );
327 exp_ldif_finish_show();
328 exportldif_save_settings( _exportCtl_ );
329 export_ldif_message();
335 * Callback function to accept LDIF file selection.
336 * \param widget Widget (button).
337 * \param data User data.
339 static void exp_ldif_file_ok( GtkWidget *widget, gpointer data ) {
341 AddressFileSelection *afs;
344 afs = ( AddressFileSelection * ) data;
345 fileSel = afs->fileSelector;
346 sFile = gtk_file_selection_get_filename( GTK_FILE_SELECTION(fileSel) );
348 afs->cancelled = FALSE;
349 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
350 gtk_widget_hide( afs->fileSelector );
351 gtk_grab_remove( afs->fileSelector );
352 gtk_widget_grab_focus( expldif_dlg.entryLdif );
356 * Callback function to cancel LDIF file selection dialog.
357 * \param widget Widget (button).
358 * \param data User data.
360 static void exp_ldif_file_cancel( GtkWidget *widget, gpointer data ) {
361 AddressFileSelection *afs = ( AddressFileSelection * ) data;
362 afs->cancelled = TRUE;
363 gtk_widget_hide( afs->fileSelector );
364 gtk_grab_remove( afs->fileSelector );
365 gtk_widget_grab_focus( expldif_dlg.entryLdif );
369 * Create LDIF file selection dialog.
370 * \param afs Address file selection data.
372 static void exp_ldif_file_select_create( AddressFileSelection *afs ) {
373 GtkWidget *fileSelector;
375 fileSelector = gtk_file_selection_new( _("Select LDIF Output File") );
376 gtk_file_selection_hide_fileop_buttons( GTK_FILE_SELECTION(fileSelector) );
377 gtk_file_selection_complete( GTK_FILE_SELECTION(fileSelector), "*.html" );
378 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(fileSelector)->ok_button),
380 G_CALLBACK(exp_ldif_file_ok), (gpointer)afs);
381 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(fileSelector)->cancel_button),
383 G_CALLBACK(exp_ldif_file_cancel), (gpointer)afs);
384 afs->fileSelector = fileSelector;
385 afs->cancelled = TRUE;
389 * Callback function to display LDIF file selection dialog.
391 static void exp_ldif_file_select( void ) {
393 if( ! _exp_ldif_file_selector_.fileSelector )
394 exp_ldif_file_select_create( & _exp_ldif_file_selector_ );
396 sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
397 gtk_file_selection_set_filename(
398 GTK_FILE_SELECTION( _exp_ldif_file_selector_.fileSelector ),
401 gtk_widget_show( _exp_ldif_file_selector_.fileSelector );
402 gtk_grab_add( _exp_ldif_file_selector_.fileSelector );
406 * Format notebook file specification page.
407 * \param pageNum Page (tab) number.
408 * \param pageLbl Page (tab) label.
410 static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) {
414 GtkWidget *labelBook;
415 GtkWidget *entryLdif;
419 vbox = gtk_vbox_new(FALSE, 8);
420 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
421 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
423 label = gtk_label_new( pageLbl );
424 gtk_widget_show( label );
425 gtk_notebook_set_tab_label(
426 GTK_NOTEBOOK( expldif_dlg.notebook ),
427 gtk_notebook_get_nth_page(
428 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
431 table = gtk_table_new( 3, 3, FALSE );
432 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
433 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
434 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
435 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
439 label = gtk_label_new( _( "Address Book" ) );
440 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
442 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
444 labelBook = gtk_label_new( "Address book name goes here" );
445 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
446 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
447 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
451 label = gtk_label_new( _( "LDIF Output File" ) );
452 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
454 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
456 entryLdif = gtk_entry_new();
457 gtk_table_attach(GTK_TABLE(table), entryLdif, 1, 2, top, (top + 1),
458 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
460 btnFile = gtk_button_new_with_label( _(" ... "));
461 gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
464 gtk_widget_show_all(vbox);
467 g_signal_connect(G_OBJECT(btnFile), "clicked",
468 G_CALLBACK(exp_ldif_file_select), NULL);
470 expldif_dlg.labelBook = labelBook;
471 expldif_dlg.entryLdif = entryLdif;
475 * Format notebook distinguished name page.
476 * \param pageNum Page (tab) number.
477 * \param pageLbl Page (tab) label.
479 static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) {
483 GtkWidget *entrySuffix;
484 GtkWidget *optmenuRDN;
485 GtkWidget *checkUseDN;
486 GtkWidget *checkEMail;
489 GtkTooltips *toolTip;
492 vbox = gtk_vbox_new(FALSE, 8);
493 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
494 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
496 label = gtk_label_new( pageLbl );
497 gtk_widget_show( label );
498 gtk_notebook_set_tab_label(
499 GTK_NOTEBOOK( expldif_dlg.notebook ),
500 gtk_notebook_get_nth_page(
501 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
504 table = gtk_table_new( 5, 2, FALSE );
505 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
506 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
507 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
508 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
512 label = gtk_label_new( _( "Suffix" ) );
513 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
515 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
517 entrySuffix = gtk_entry_new();
518 gtk_table_attach(GTK_TABLE(table), entrySuffix, 1, 2, top, (top + 1),
519 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
521 toolTip = gtk_tooltips_new();
522 gtk_tooltips_set_tip(
523 GTK_TOOLTIPS(toolTip), entrySuffix, _(
524 "The suffix is used to create a \"Distinguished Name\" " \
525 "(or DN) for an LDAP entry. Examples include:\n" \
526 " dc=sylpheed,dc=org\n" \
527 " ou=people,dc=domainname,dc=com\n" \
528 " o=Organization Name,c=Country\n"
533 label = gtk_label_new( _( "Relative DN" ) );
534 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
536 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
538 menu = gtk_menu_new();
540 menuItem = gtk_menu_item_new_with_label( _( "Unique ID" ) );
541 gtk_object_set_user_data( GTK_OBJECT( menuItem ),
542 GINT_TO_POINTER( EXPORT_LDIF_ID_UID ) );
543 gtk_menu_append( GTK_MENU(menu), menuItem );
544 gtk_widget_show( menuItem );
545 toolTip = gtk_tooltips_new();
546 gtk_tooltips_set_tip(
547 GTK_TOOLTIPS(toolTip), menuItem, _(
548 "The address book Unique ID is used to create a DN that is " \
549 "formatted similar to:\n" \
550 " uid=102376,ou=people,dc=sylpheed,dc=org"
553 menuItem = gtk_menu_item_new_with_label( _( "Display Name" ) );
554 gtk_object_set_user_data( GTK_OBJECT( menuItem ),
555 GINT_TO_POINTER( EXPORT_LDIF_ID_DNAME ) );
556 gtk_menu_append( GTK_MENU(menu), menuItem );
557 gtk_widget_show( menuItem );
558 toolTip = gtk_tooltips_new();
559 gtk_tooltips_set_tip(
560 GTK_TOOLTIPS(toolTip), menuItem, _(
561 "The address book Display Name is used to create a DN that " \
562 "is formatted similar to:\n" \
563 " cn=John Doe,ou=people,dc=sylpheed,dc=org"
566 menuItem = gtk_menu_item_new_with_label( _( "E-Mail Address" ) );
567 gtk_object_set_user_data( GTK_OBJECT( menuItem ),
568 GINT_TO_POINTER( EXPORT_LDIF_ID_EMAIL ) );
569 gtk_menu_append( GTK_MENU(menu), menuItem );
570 gtk_widget_show( menuItem );
571 toolTip = gtk_tooltips_new();
572 gtk_tooltips_set_tip(
573 GTK_TOOLTIPS(toolTip), menuItem, _(
574 "The first E-Mail Address belonging to a person is used to " \
575 "create a DN that is formatted similar to:\n" \
576 " mail=john.doe@domain.com,ou=people,dc=sylpheed,dc=org"
579 optmenuRDN = gtk_option_menu_new();
580 gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuRDN ), menu );
582 gtk_table_attach(GTK_TABLE(table), optmenuRDN, 1, 2, top, (top + 1),
585 toolTip = gtk_tooltips_new();
586 gtk_tooltips_set_tip(
587 GTK_TOOLTIPS(toolTip), optmenuRDN, _(
588 "The LDIF file contains several data records that " \
589 "are usually loaded into an LDAP server. Each data " \
590 "record in the LDIF file is uniquely identified by " \
591 "a \"Distinguished Name\" (or DN). The suffix is " \
592 "appended to the \"Relative Distinguished Name\" "\
593 "(or RDN) to create the DN. Please select one of " \
594 "the available RDN options that will be used to " \
600 checkUseDN = gtk_check_button_new_with_label(
601 _( "Use DN attribute if present in data" ) );
602 gtk_table_attach(GTK_TABLE(table), checkUseDN, 1, 2, top, (top + 1),
605 toolTip = gtk_tooltips_new();
606 gtk_tooltips_set_tip(
607 GTK_TOOLTIPS(toolTip), checkUseDN, _(
608 "The addressbook may contain entries that were " \
609 "previously imported from an LDIF file. The " \
610 "\"Distinguished Name\" (DN) user attribute, if " \
611 "present in the address book data, may be used in " \
612 "the exported LDIF file. The RDN selected above " \
613 "will be used if the DN user attribute is not found."
618 checkEMail = gtk_check_button_new_with_label(
619 _( "Exclude record if no E-Mail Address" ) );
620 gtk_table_attach(GTK_TABLE(table), checkEMail, 1, 2, top, (top + 1),
623 toolTip = gtk_tooltips_new();
624 gtk_tooltips_set_tip(
625 GTK_TOOLTIPS(toolTip), checkEMail, _(
626 "An addressbook may contain entries without " \
627 "E-Mail Addresses. Check this option to ignore " \
632 gtk_widget_show_all(vbox);
634 expldif_dlg.entrySuffix = entrySuffix;
635 expldif_dlg.optmenuRDN = optmenuRDN;
636 expldif_dlg.checkUseDN = checkUseDN;
637 expldif_dlg.checkEMail = checkEMail;
641 * Format notebook finish page.
642 * \param pageNum Page (tab) number.
643 * \param pageLbl Page (tab) label.
645 static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
649 GtkWidget *labelBook;
650 GtkWidget *labelFile;
653 vbox = gtk_vbox_new(FALSE, 8);
654 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
655 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
657 label = gtk_label_new( pageLbl );
658 gtk_widget_show( label );
659 gtk_notebook_set_tab_label(
660 GTK_NOTEBOOK( expldif_dlg.notebook ),
661 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
663 table = gtk_table_new( 3, 3, FALSE );
664 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
665 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
666 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
667 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
671 label = gtk_label_new( _( "Address Book :" ) );
672 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
673 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
675 labelBook = gtk_label_new("Full name of address book goes here");
676 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
677 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
681 label = gtk_label_new( _( "File Name :" ) );
682 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
683 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
685 labelFile = gtk_label_new("File name goes here");
686 gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
687 gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
689 gtk_widget_show_all(vbox);
691 expldif_dlg.labelOutBook = labelBook;
692 expldif_dlg.labelOutFile = labelFile;
696 * Create main dialog decorations (excluding notebook pages).
698 static void export_ldif_dialog_create( void ) {
706 GtkWidget *btnCancel;
708 GtkWidget *statusbar;
710 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
711 gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
712 gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
713 gtk_window_set_title( GTK_WINDOW(window),
714 _("Export Address Book to LDIF File") );
715 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
716 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
717 g_signal_connect(G_OBJECT(window), "delete_event",
718 G_CALLBACK(export_ldif_delete_event),
720 g_signal_connect(G_OBJECT(window), "key_press_event",
721 G_CALLBACK(export_ldif_key_pressed),
724 vbox = gtk_vbox_new(FALSE, 4);
725 gtk_widget_show(vbox);
726 gtk_container_add(GTK_CONTAINER(window), vbox);
728 vnbox = gtk_vbox_new(FALSE, 4);
729 gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
730 gtk_widget_show(vnbox);
731 gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
734 notebook = gtk_notebook_new();
735 gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
736 /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
737 gtk_widget_show(notebook);
738 gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
739 gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
742 hsbox = gtk_hbox_new(FALSE, 0);
743 gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
744 statusbar = gtk_statusbar_new();
745 gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
748 gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
749 &btnNext, GTK_STOCK_GO_FORWARD,
750 &btnCancel, GTK_STOCK_CANCEL);
751 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
752 gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
753 gtk_widget_grab_default(btnNext);
755 /* Button handlers */
756 g_signal_connect(G_OBJECT(btnPrev), "clicked",
757 G_CALLBACK(export_ldif_prev), NULL);
758 g_signal_connect(G_OBJECT(btnNext), "clicked",
759 G_CALLBACK(export_ldif_next), NULL);
760 g_signal_connect(G_OBJECT(btnCancel), "clicked",
761 G_CALLBACK(export_ldif_cancel), NULL);
763 gtk_widget_show_all(vbox);
765 expldif_dlg.window = window;
766 expldif_dlg.notebook = notebook;
767 expldif_dlg.btnPrev = btnPrev;
768 expldif_dlg.btnNext = btnNext;
769 expldif_dlg.btnCancel = btnCancel;
770 expldif_dlg.statusbar = statusbar;
771 expldif_dlg.status_cid = gtk_statusbar_get_context_id(
772 GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
776 * Create export LDIF dialog.
778 static void export_ldif_create( void ) {
779 export_ldif_dialog_create();
780 export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
781 export_ldif_page_dn( PAGE_DN, _( "Distguished Name" ) );
782 export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
783 gtk_widget_show_all( expldif_dlg.window );
787 * Populate fields from control data.
788 * \param ctl Export control data.
790 static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
791 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
793 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
796 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
798 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
802 gtk_option_menu_set_history(
803 GTK_OPTION_MENU( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
804 gtk_toggle_button_set_active(
805 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
806 gtk_toggle_button_set_active(
807 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
811 * Process export address dialog.
812 * \param cache Address book/data source cache.
814 void addressbook_exp_ldif( AddressCache *cache ) {
815 /* Set references to control data */
816 _addressCache_ = cache;
818 _exportCtl_ = exportldif_create();
819 exportldif_load_settings( _exportCtl_ );
822 if( ! expldif_dlg.window )
823 export_ldif_create();
824 expldif_dlg.cancelled = FALSE;
825 gtk_widget_show(expldif_dlg.window);
826 manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
828 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
829 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
830 export_ldif_fill_fields( _exportCtl_ );
832 gtk_widget_grab_default(expldif_dlg.btnNext);
833 gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
834 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
835 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
837 export_ldif_message();
838 gtk_widget_grab_focus(expldif_dlg.entryLdif);
841 gtk_widget_hide(expldif_dlg.window);
842 exportldif_free( _exportCtl_ );
845 _addressCache_ = NULL;
849 * ============================================================================
851 * ============================================================================