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 <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>
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 );
160 * Test whether we can move off file page.
161 * \return <i>TRUE</i> if OK to move off page.
163 static gboolean exp_ldif_move_file( void ) {
164 gchar *sFile, *msg, *reason;
165 gboolean errFlag = FALSE;
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 );
173 /* Test that something was supplied */
174 if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
175 gtk_widget_grab_focus( expldif_dlg.entryLdif );
179 if( errFlag ) return FALSE;
181 /* Test for directory */
182 if( exportldif_test_dir( _exportCtl_ ) ) {
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 );
194 if( aval != G_ALERTDEFAULT ) return FALSE;
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" ),
202 aval = alertpanel_with_type( _( "Failed to Create Directory" ),
203 msg, _( "Close" ), NULL, NULL, NULL, ALERT_ERROR );
212 * Test whether we can move off distinguished name page.
213 * \return <i>TRUE</i> if OK to move off page.
215 static gboolean exp_ldif_move_dn( void ) {
216 gboolean retVal = FALSE;
217 gboolean errFlag = FALSE;
219 GtkWidget *menu, *menuItem;
223 suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
224 g_strchug( suffix ); g_strchomp( suffix );
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 );
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 ) ) );
240 if( *suffix == '\0' || strlen( suffix ) < 1 ) {
244 _( "Suffix was not supplied" ),
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?"
250 _( "Yes" ), _( "No" ), NULL );
251 if( aval != G_ALERTDEFAULT ) {
252 gtk_widget_grab_focus( expldif_dlg.entrySuffix );
259 exportldif_process( _exportCtl_, _addressCache_ );
260 if( _exportCtl_->retVal == MGU_SUCCESS ) {
264 export_ldif_status_show( _( "Error creating LDIF file" ) );
272 * Display finish page.
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 );
281 * Callback function to select previous page.
282 * \param widget Widget (button).
284 static void export_ldif_prev( GtkWidget *widget ) {
287 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
288 if( pageNum == PAGE_DN ) {
289 /* Goto file page stuff */
290 gtk_notebook_set_current_page(
291 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
292 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
294 else if( pageNum == PAGE_FINISH ) {
295 /* Goto format page */
296 gtk_notebook_set_current_page(
297 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
298 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
300 export_ldif_message();
304 * Callback function to select next page.
305 * \param widget Widget (button).
307 static void export_ldif_next( GtkWidget *widget ) {
310 pageNum = gtk_notebook_get_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_current_page(
315 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
316 gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE );
318 export_ldif_message();
320 else if( pageNum == PAGE_DN ) {
321 /* Goto finish page */
322 if( exp_ldif_move_dn() ) {
323 gtk_notebook_set_current_page(
324 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH );
325 exp_ldif_finish_show();
326 exportldif_save_settings( _exportCtl_ );
327 export_ldif_message();
333 * Callback function to accept LDIF file selection.
334 * \param widget Widget (button).
335 * \param data User data.
337 static void exp_ldif_file_ok( GtkWidget *widget, gpointer data ) {
339 AddressFileSelection *afs;
342 afs = ( AddressFileSelection * ) data;
343 fileSel = afs->fileSelector;
344 sFile = gtk_file_selection_get_filename( GTK_FILE_SELECTION(fileSel) );
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 );
354 * Callback function to cancel LDIF file selection dialog.
355 * \param widget Widget (button).
356 * \param data User data.
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 );
367 * Create LDIF file selection dialog.
368 * \param afs Address file selection data.
370 static void exp_ldif_file_select_create( AddressFileSelection *afs ) {
371 GtkWidget *fileSelector;
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 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(fileSelector)->ok_button),
378 G_CALLBACK(exp_ldif_file_ok), (gpointer)afs);
379 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(fileSelector)->cancel_button),
381 G_CALLBACK(exp_ldif_file_cancel), (gpointer)afs);
382 afs->fileSelector = fileSelector;
383 afs->cancelled = TRUE;
387 * Callback function to display LDIF file selection dialog.
389 static void exp_ldif_file_select( void ) {
391 if( ! _exp_ldif_file_selector_.fileSelector )
392 exp_ldif_file_select_create( & _exp_ldif_file_selector_ );
394 sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
395 gtk_file_selection_set_filename(
396 GTK_FILE_SELECTION( _exp_ldif_file_selector_.fileSelector ),
399 gtk_widget_show( _exp_ldif_file_selector_.fileSelector );
400 gtk_grab_add( _exp_ldif_file_selector_.fileSelector );
404 * Format notebook file specification page.
405 * \param pageNum Page (tab) number.
406 * \param pageLbl Page (tab) label.
408 static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) {
412 GtkWidget *labelBook;
413 GtkWidget *entryLdif;
417 vbox = gtk_vbox_new(FALSE, 8);
418 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
419 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
421 label = gtk_label_new( pageLbl );
422 gtk_widget_show( label );
423 gtk_notebook_set_tab_label(
424 GTK_NOTEBOOK( expldif_dlg.notebook ),
425 gtk_notebook_get_nth_page(
426 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
429 table = gtk_table_new( 3, 3, FALSE );
430 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
431 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
432 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
433 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
437 label = gtk_label_new( _( "Address Book" ) );
438 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
440 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
442 labelBook = gtk_label_new( "Address book name goes here" );
443 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
444 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
445 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
449 label = gtk_label_new( _( "LDIF Output File" ) );
450 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
452 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
454 entryLdif = gtk_entry_new();
455 gtk_table_attach(GTK_TABLE(table), entryLdif, 1, 2, top, (top + 1),
456 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
458 btnFile = gtk_button_new_with_label( _(" ... "));
459 gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
462 gtk_widget_show_all(vbox);
465 g_signal_connect(G_OBJECT(btnFile), "clicked",
466 G_CALLBACK(exp_ldif_file_select), NULL);
468 expldif_dlg.labelBook = labelBook;
469 expldif_dlg.entryLdif = entryLdif;
473 * Format notebook distinguished name page.
474 * \param pageNum Page (tab) number.
475 * \param pageLbl Page (tab) label.
477 static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) {
481 GtkWidget *entrySuffix;
482 GtkWidget *optmenuRDN;
483 GtkWidget *checkUseDN;
484 GtkWidget *checkEMail;
487 GtkTooltips *toolTip;
490 vbox = gtk_vbox_new(FALSE, 8);
491 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
492 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
494 label = gtk_label_new( pageLbl );
495 gtk_widget_show( label );
496 gtk_notebook_set_tab_label(
497 GTK_NOTEBOOK( expldif_dlg.notebook ),
498 gtk_notebook_get_nth_page(
499 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
502 table = gtk_table_new( 5, 2, FALSE );
503 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
504 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
505 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
506 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
510 label = gtk_label_new( _( "Suffix" ) );
511 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
513 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
515 entrySuffix = gtk_entry_new();
516 gtk_table_attach(GTK_TABLE(table), entrySuffix, 1, 2, top, (top + 1),
517 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
519 toolTip = gtk_tooltips_new();
520 gtk_tooltips_set_tip(
521 GTK_TOOLTIPS(toolTip), entrySuffix, _(
522 "The suffix is used to create a \"Distinguished Name\" " \
523 "(or DN) for an LDAP entry. Examples include:\n" \
524 " dc=sylpheed,dc=org\n" \
525 " ou=people,dc=domainname,dc=com\n" \
526 " o=Organization Name,c=Country\n"
531 label = gtk_label_new( _( "Relative DN" ) );
532 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
534 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
536 menu = gtk_menu_new();
538 menuItem = gtk_menu_item_new_with_label( _( "Unique ID" ) );
539 gtk_object_set_user_data( GTK_OBJECT( menuItem ),
540 GINT_TO_POINTER( EXPORT_LDIF_ID_UID ) );
541 gtk_menu_append( GTK_MENU(menu), menuItem );
542 gtk_widget_show( menuItem );
543 toolTip = gtk_tooltips_new();
544 gtk_tooltips_set_tip(
545 GTK_TOOLTIPS(toolTip), menuItem, _(
546 "The address book Unique ID is used to create a DN that is " \
547 "formatted similar to:\n" \
548 " uid=102376,ou=people,dc=sylpheed,dc=org"
551 menuItem = gtk_menu_item_new_with_label( _( "Display Name" ) );
552 gtk_object_set_user_data( GTK_OBJECT( menuItem ),
553 GINT_TO_POINTER( EXPORT_LDIF_ID_DNAME ) );
554 gtk_menu_append( GTK_MENU(menu), menuItem );
555 gtk_widget_show( menuItem );
556 toolTip = gtk_tooltips_new();
557 gtk_tooltips_set_tip(
558 GTK_TOOLTIPS(toolTip), menuItem, _(
559 "The address book Display Name is used to create a DN that " \
560 "is formatted similar to:\n" \
561 " cn=John Doe,ou=people,dc=sylpheed,dc=org"
564 menuItem = gtk_menu_item_new_with_label( _( "E-Mail Address" ) );
565 gtk_object_set_user_data( GTK_OBJECT( menuItem ),
566 GINT_TO_POINTER( EXPORT_LDIF_ID_EMAIL ) );
567 gtk_menu_append( GTK_MENU(menu), menuItem );
568 gtk_widget_show( menuItem );
569 toolTip = gtk_tooltips_new();
570 gtk_tooltips_set_tip(
571 GTK_TOOLTIPS(toolTip), menuItem, _(
572 "The first E-Mail Address belonging to a person is used to " \
573 "create a DN that is formatted similar to:\n" \
574 " mail=john.doe@domain.com,ou=people,dc=sylpheed,dc=org"
577 optmenuRDN = gtk_option_menu_new();
578 gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuRDN ), menu );
580 gtk_table_attach(GTK_TABLE(table), optmenuRDN, 1, 2, top, (top + 1),
583 toolTip = gtk_tooltips_new();
584 gtk_tooltips_set_tip(
585 GTK_TOOLTIPS(toolTip), optmenuRDN, _(
586 "The LDIF file contains several data records that " \
587 "are usually loaded into an LDAP server. Each data " \
588 "record in the LDIF file is uniquely identified by " \
589 "a \"Distinguished Name\" (or DN). The suffix is " \
590 "appended to the \"Relative Distinguished Name\" "\
591 "(or RDN) to create the DN. Please select one of " \
592 "the available RDN options that will be used to " \
598 checkUseDN = gtk_check_button_new_with_label(
599 _( "Use DN attribute if present in data" ) );
600 gtk_table_attach(GTK_TABLE(table), checkUseDN, 1, 2, top, (top + 1),
603 toolTip = gtk_tooltips_new();
604 gtk_tooltips_set_tip(
605 GTK_TOOLTIPS(toolTip), checkUseDN, _(
606 "The addressbook may contain entries that were " \
607 "previously imported from an LDIF file. The " \
608 "\"Distinguished Name\" (DN) user attribute, if " \
609 "present in the address book data, may be used in " \
610 "the exported LDIF file. The RDN selected above " \
611 "will be used if the DN user attribute is not found."
616 checkEMail = gtk_check_button_new_with_label(
617 _( "Exclude record if no E-Mail Address" ) );
618 gtk_table_attach(GTK_TABLE(table), checkEMail, 1, 2, top, (top + 1),
621 toolTip = gtk_tooltips_new();
622 gtk_tooltips_set_tip(
623 GTK_TOOLTIPS(toolTip), checkEMail, _(
624 "An addressbook may contain entries without " \
625 "E-Mail Addresses. Check this option to ignore " \
630 gtk_widget_show_all(vbox);
632 expldif_dlg.entrySuffix = entrySuffix;
633 expldif_dlg.optmenuRDN = optmenuRDN;
634 expldif_dlg.checkUseDN = checkUseDN;
635 expldif_dlg.checkEMail = checkEMail;
639 * Format notebook finish page.
640 * \param pageNum Page (tab) number.
641 * \param pageLbl Page (tab) label.
643 static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
647 GtkWidget *labelBook;
648 GtkWidget *labelFile;
651 vbox = gtk_vbox_new(FALSE, 8);
652 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
653 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
655 label = gtk_label_new( pageLbl );
656 gtk_widget_show( label );
657 gtk_notebook_set_tab_label(
658 GTK_NOTEBOOK( expldif_dlg.notebook ),
659 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
661 table = gtk_table_new( 3, 3, FALSE );
662 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
663 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
664 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
665 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
669 label = gtk_label_new( _( "Address Book :" ) );
670 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
671 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
673 labelBook = gtk_label_new("Full name of address book goes here");
674 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
675 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
679 label = gtk_label_new( _( "File Name :" ) );
680 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
681 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
683 labelFile = gtk_label_new("File name goes here");
684 gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
685 gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
687 gtk_widget_show_all(vbox);
689 expldif_dlg.labelOutBook = labelBook;
690 expldif_dlg.labelOutFile = labelFile;
694 * Create main dialog decorations (excluding notebook pages).
696 static void export_ldif_dialog_create( void ) {
704 GtkWidget *btnCancel;
706 GtkWidget *statusbar;
708 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
709 gtk_widget_set_usize(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
710 gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
711 gtk_window_set_title( GTK_WINDOW(window),
712 _("Export Address Book to LDIF File") );
713 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
714 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
715 g_signal_connect(G_OBJECT(window), "delete_event",
716 G_CALLBACK(export_ldif_delete_event),
718 g_signal_connect(G_OBJECT(window), "key_press_event",
719 G_CALLBACK(export_ldif_key_pressed),
722 vbox = gtk_vbox_new(FALSE, 4);
723 gtk_widget_show(vbox);
724 gtk_container_add(GTK_CONTAINER(window), vbox);
726 vnbox = gtk_vbox_new(FALSE, 4);
727 gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
728 gtk_widget_show(vnbox);
729 gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
732 notebook = gtk_notebook_new();
733 gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
734 /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
735 gtk_widget_show(notebook);
736 gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
737 gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
740 hsbox = gtk_hbox_new(FALSE, 0);
741 gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
742 statusbar = gtk_statusbar_new();
743 gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
746 gtkut_button_set_create(&hbbox, &btnPrev, _( "Prev" ),
747 &btnNext, _( "Next" ),
748 &btnCancel, _( "Cancel" ) );
749 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
750 gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
751 gtk_widget_grab_default(btnNext);
753 /* Button handlers */
754 g_signal_connect(G_OBJECT(btnPrev), "clicked",
755 G_CALLBACK(export_ldif_prev), NULL);
756 g_signal_connect(G_OBJECT(btnNext), "clicked",
757 G_CALLBACK(export_ldif_next), NULL);
758 g_signal_connect(G_OBJECT(btnCancel), "clicked",
759 G_CALLBACK(export_ldif_cancel), NULL);
761 gtk_widget_show_all(vbox);
763 expldif_dlg.window = window;
764 expldif_dlg.notebook = notebook;
765 expldif_dlg.btnPrev = btnPrev;
766 expldif_dlg.btnNext = btnNext;
767 expldif_dlg.btnCancel = btnCancel;
768 expldif_dlg.statusbar = statusbar;
769 expldif_dlg.status_cid = gtk_statusbar_get_context_id(
770 GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
774 * Create export LDIF dialog.
776 static void export_ldif_create( void ) {
777 export_ldif_dialog_create();
778 export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
779 export_ldif_page_dn( PAGE_DN, _( "Distguished Name" ) );
780 export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
781 gtk_widget_show_all( expldif_dlg.window );
785 * Populate fields from control data.
786 * \param ctl Export control data.
788 static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
789 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
791 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
794 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
796 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
800 gtk_option_menu_set_history(
801 GTK_OPTION_MENU( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
802 gtk_toggle_button_set_active(
803 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
804 gtk_toggle_button_set_active(
805 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
809 * Process export address dialog.
810 * \param cache Address book/data source cache.
812 void addressbook_exp_ldif( AddressCache *cache ) {
813 /* Set references to control data */
814 _addressCache_ = cache;
816 _exportCtl_ = exportldif_create();
817 exportldif_load_settings( _exportCtl_ );
820 if( ! expldif_dlg.window )
821 export_ldif_create();
822 expldif_dlg.cancelled = FALSE;
823 gtk_widget_show(expldif_dlg.window);
824 manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
826 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
827 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
828 export_ldif_fill_fields( _exportCtl_ );
830 gtk_widget_grab_default(expldif_dlg.btnNext);
831 gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
832 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
833 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
835 export_ldif_message();
836 gtk_widget_grab_focus(expldif_dlg.entryLdif);
839 gtk_widget_hide(expldif_dlg.window);
840 exportldif_free( _exportCtl_ );
843 _addressCache_ = NULL;
847 * ============================================================================
849 * ============================================================================