2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2007 Match Grun and the Claws Mail team
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.
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, see <http://www.gnu.org/licenses/>.
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"
52 #define PAGE_FILE_INFO 0
56 #define EXPORTLDIF_WIDTH 480
57 #define EXPORTLDIF_HEIGHT -1
62 static struct _ExpLdif_Dlg {
67 GtkWidget *entrySuffix;
68 GtkWidget *optmenuRDN;
69 GtkWidget *checkUseDN;
70 GtkWidget *checkEMail;
71 GtkWidget *labelOutBook;
72 GtkWidget *labelOutFile;
81 static struct _AddressFileSelection _exp_ldif_file_selector_;
83 static ExportLdifCtl *_exportCtl_ = NULL;
84 static AddressCache *_addressCache_ = NULL;
87 * Display message in status field.
88 * \param msg Message to display.
90 static void export_ldif_status_show( gchar *msg ) {
91 if( expldif_dlg.statusbar != NULL ) {
93 GTK_STATUSBAR(expldif_dlg.statusbar),
94 expldif_dlg.status_cid );
97 GTK_STATUSBAR(expldif_dlg.statusbar),
98 expldif_dlg.status_cid, msg );
104 * Select and display status message appropriate for the page being displayed.
106 static void export_ldif_message( void ) {
110 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
111 if( pageNum == PAGE_FILE_INFO ) {
112 sMsg = _( "Please specify output directory and LDIF filename to create." );
114 else if( pageNum == PAGE_DN ) {
115 sMsg = _( "Specify parameters to format distinguished name." );
117 else if( pageNum == PAGE_FINISH ) {
118 sMsg = _( "File exported successfully." );
120 export_ldif_status_show( sMsg );
124 * Callback function to cancel LDIF file selection dialog.
125 * \param widget Widget (button).
126 * \param data User data.
128 static void export_ldif_cancel( GtkWidget *widget, gpointer data ) {
131 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
132 if( pageNum != PAGE_FINISH ) {
133 expldif_dlg.cancelled = TRUE;
139 * Callback function to handle dialog close event.
140 * \param widget Widget (dialog).
141 * \param event Event object.
142 * \param data User data.
144 static gint export_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
145 export_ldif_cancel( widget, data );
150 * Callback function to respond to dialog key press events.
151 * \param widget Widget.
152 * \param event Event object.
153 * \param data User data.
155 static gboolean export_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
156 if (event && event->keyval == GDK_Escape) {
157 export_ldif_cancel( widget, data );
163 * Test whether we can move off file page.
164 * \return <i>TRUE</i> if OK to move off page.
166 static gboolean exp_ldif_move_file( void ) {
167 gchar *sFile, *msg, *reason;
168 gboolean errFlag = FALSE;
171 sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
172 g_strchug( sFile ); g_strchomp( sFile );
173 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
174 exportldif_parse_filespec( _exportCtl_, sFile );
176 /* Test that something was supplied */
177 if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
178 gtk_widget_grab_focus( expldif_dlg.entryLdif );
182 if( errFlag ) return FALSE;
184 /* Test for directory */
185 if( exportldif_test_dir( _exportCtl_ ) ) {
189 /* Prompt to create */
190 msg = g_strdup_printf( _(
191 "LDIF Output Directory '%s'\n" \
192 "does not exist. OK to create new directory?" ),
193 _exportCtl_->dirOutput );
194 aval = alertpanel( _("Create Directory" ),
195 msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
197 if( aval != G_ALERTALTERNATE ) return FALSE;
199 /* Create directory */
200 if( ! exportldif_create_dir( _exportCtl_ ) ) {
201 reason = exportldif_get_create_msg( _exportCtl_ );
202 msg = g_strdup_printf( _(
203 "Could not create output directory for LDIF file:\n%s" ),
205 aval = alertpanel_full(_("Failed to Create Directory"), msg,
206 GTK_STOCK_CLOSE, NULL, NULL, FALSE,
207 NULL, ALERT_ERROR, G_ALERTDEFAULT);
216 * Test whether we can move off distinguished name page.
217 * \return <i>TRUE</i> if OK to move off page.
219 static gboolean exp_ldif_move_dn( void ) {
220 gboolean retVal = FALSE;
221 gboolean errFlag = FALSE;
226 suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
227 g_strchug( suffix ); g_strchomp( suffix );
230 id = combobox_get_active_data(GTK_COMBO_BOX(expldif_dlg.optmenuRDN));
231 exportldif_set_rdn( _exportCtl_, id );
233 exportldif_set_suffix( _exportCtl_, suffix );
234 exportldif_set_use_dn( _exportCtl_,
235 gtk_toggle_button_get_active(
236 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
237 exportldif_set_exclude_email( _exportCtl_,
238 gtk_toggle_button_get_active(
239 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );
241 if( *suffix == '\0' || strlen( suffix ) < 1 ) {
245 _( "Suffix was not supplied" ),
247 "A suffix is required if data is to be used " \
248 "for an LDAP server. Are you sure you wish " \
249 "to proceed without a suffix?"
251 GTK_STOCK_NO, GTK_STOCK_YES, NULL );
252 if( aval != G_ALERTALTERNATE ) {
253 gtk_widget_grab_focus( expldif_dlg.entrySuffix );
260 exportldif_process( _exportCtl_, _addressCache_ );
261 if( _exportCtl_->retVal == MGU_SUCCESS ) {
265 export_ldif_status_show( _( "Error creating LDIF file" ) );
273 * Display finish page.
275 static void exp_ldif_finish_show( void ) {
276 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutFile), _exportCtl_->path );
277 gtk_widget_set_sensitive( expldif_dlg.btnNext, FALSE );
278 gtk_widget_grab_focus( expldif_dlg.btnCancel );
282 * Callback function to select previous page.
283 * \param widget Widget (button).
285 static void export_ldif_prev( GtkWidget *widget ) {
288 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
289 if( pageNum == PAGE_DN ) {
290 /* Goto file page stuff */
291 gtk_notebook_set_current_page(
292 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
293 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
295 else if( pageNum == PAGE_FINISH ) {
296 /* Goto format page */
297 gtk_notebook_set_current_page(
298 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
299 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
301 export_ldif_message();
305 * Callback function to select next page.
306 * \param widget Widget (button).
308 static void export_ldif_next( GtkWidget *widget ) {
311 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
312 if( pageNum == PAGE_FILE_INFO ) {
313 /* Goto distinguished name page */
314 if( exp_ldif_move_file() ) {
315 gtk_notebook_set_current_page(
316 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
317 gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE );
319 export_ldif_message();
321 else if( pageNum == PAGE_DN ) {
322 /* Goto finish page */
323 if( exp_ldif_move_dn() ) {
324 gtk_notebook_set_current_page(
325 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH );
326 gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
328 exp_ldif_finish_show();
329 exportldif_save_settings( _exportCtl_ );
330 export_ldif_message();
336 * Create LDIF file selection dialog.
337 * \param afs Address file selection data.
339 static void exp_ldif_file_select_create( AddressFileSelection *afs ) {
340 gchar *file = filesel_select_file_save(_("Select LDIF output file"), NULL);
343 afs->cancelled = TRUE;
345 afs->cancelled = FALSE;
346 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), file );
352 * Callback function to display LDIF file selection dialog.
354 static void exp_ldif_file_select( void ) {
355 exp_ldif_file_select_create( & _exp_ldif_file_selector_ );
359 * Format notebook file specification page.
360 * \param pageNum Page (tab) number.
361 * \param pageLbl Page (tab) label.
363 static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) {
367 GtkWidget *labelBook;
368 GtkWidget *entryLdif;
372 vbox = gtk_vbox_new(FALSE, 8);
373 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
374 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
376 label = gtk_label_new( pageLbl );
377 gtk_widget_show( label );
378 gtk_notebook_set_tab_label(
379 GTK_NOTEBOOK( expldif_dlg.notebook ),
380 gtk_notebook_get_nth_page(
381 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
384 table = gtk_table_new( 3, 3, FALSE );
385 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
386 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
387 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
388 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
392 label = gtk_label_new( _( "Address Book" ) );
393 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
395 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
397 labelBook = gtk_label_new( "Address book name goes here" );
398 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
399 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
400 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
404 label = gtk_label_new( _( "LDIF Output File" ) );
405 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
407 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
409 entryLdif = gtk_entry_new();
410 gtk_table_attach(GTK_TABLE(table), entryLdif, 1, 2, top, (top + 1),
411 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
413 btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
414 gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
417 gtk_widget_show_all(vbox);
420 g_signal_connect(G_OBJECT(btnFile), "clicked",
421 G_CALLBACK(exp_ldif_file_select), NULL);
423 expldif_dlg.labelBook = labelBook;
424 expldif_dlg.entryLdif = entryLdif;
427 static void export_ldif_relative_dn_changed(GtkWidget *widget, gpointer data)
429 gint relativeDN = combobox_get_active_data(GTK_COMBO_BOX(widget));
430 GtkLabel *label = GTK_LABEL(data);
433 case EXPORT_LDIF_ID_UID:
434 gtk_label_set_text(label,
435 _("The address book Unique ID is used to create a DN that is " \
436 "formatted similar to:\n" \
437 " uid=102376,ou=people,dc=claws-mail,dc=org"));
439 case EXPORT_LDIF_ID_DNAME:
440 gtk_label_set_text(label,
441 _("The address book Display Name is used to create a DN that " \
442 "is formatted similar to:\n" \
443 " cn=John Doe,ou=people,dc=claws-mail,dc=org"));
445 case EXPORT_LDIF_ID_EMAIL:
446 gtk_label_set_text(label,
447 _("The first Email Address belonging to a person is used to " \
448 "create a DN that is formatted similar to:\n" \
449 " mail=john.doe@domain.com,ou=people,dc=claws-mail,dc=org"));
456 * Format notebook distinguished name page.
457 * \param pageNum Page (tab) number.
458 * \param pageLbl Page (tab) label.
460 static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) {
464 GtkWidget *entrySuffix;
465 GtkWidget *optmenuRDN;
467 GtkWidget *checkUseDN;
468 GtkWidget *checkEMail;
471 GtkTooltips *toolTip;
474 vbox = gtk_vbox_new(FALSE, 8);
475 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
476 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
478 label = gtk_label_new( pageLbl );
479 gtk_widget_show( label );
480 gtk_notebook_set_tab_label(
481 GTK_NOTEBOOK( expldif_dlg.notebook ),
482 gtk_notebook_get_nth_page(
483 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
486 table = gtk_table_new( 6, 2, FALSE );
487 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
488 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
489 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
490 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
494 label = gtk_label_new( _( "Suffix" ) );
495 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
497 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
499 entrySuffix = gtk_entry_new();
500 gtk_table_attach(GTK_TABLE(table), entrySuffix, 1, 2, top, (top + 1),
501 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
503 toolTip = gtk_tooltips_new();
504 gtk_tooltips_set_tip(
505 GTK_TOOLTIPS(toolTip), entrySuffix, _(
506 "The suffix is used to create a \"Distinguished Name\" " \
507 "(or DN) for an LDAP entry. Examples include:\n" \
508 " dc=claws-mail,dc=org\n" \
509 " ou=people,dc=domainname,dc=com\n" \
510 " o=Organization Name,c=Country\n"
515 label = gtk_label_new( _( "Relative DN" ) );
516 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
518 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
520 optmenuRDN = gtkut_sc_combobox_create(NULL, TRUE);
521 store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuRDN)));
523 COMBOBOX_ADD(store, _("Unique ID"), EXPORT_LDIF_ID_UID);
524 COMBOBOX_ADD(store, _("Display Name"), EXPORT_LDIF_ID_DNAME);
525 COMBOBOX_ADD(store, _("Email Address"), EXPORT_LDIF_ID_EMAIL);
527 gtk_table_attach(GTK_TABLE(table), optmenuRDN, 1, 2, top, (top + 1),
530 toolTip = gtk_tooltips_new();
531 gtk_tooltips_set_tip(
532 GTK_TOOLTIPS(toolTip), optmenuRDN, _(
533 "The LDIF file contains several data records that " \
534 "are usually loaded into an LDAP server. Each data " \
535 "record in the LDIF file is uniquely identified by " \
536 "a \"Distinguished Name\" (or DN). The suffix is " \
537 "appended to the \"Relative Distinguished Name\" "\
538 "(or RDN) to create the DN. Please select one of " \
539 "the available RDN options that will be used to " \
545 labelRDN = gtk_label_new("");
546 gtk_label_set_line_wrap(GTK_LABEL(labelRDN), TRUE);
547 gtk_label_set_justify(GTK_LABEL(labelRDN), GTK_JUSTIFY_CENTER);
548 gtk_table_attach(GTK_TABLE(table), labelRDN, 0, 2, top, (top + 1),
553 checkUseDN = gtk_check_button_new_with_label(
554 _( "Use DN attribute if present in data" ) );
555 gtk_table_attach(GTK_TABLE(table), checkUseDN, 1, 2, top, (top + 1),
558 toolTip = gtk_tooltips_new();
559 gtk_tooltips_set_tip(
560 GTK_TOOLTIPS(toolTip), checkUseDN, _(
561 "The addressbook may contain entries that were " \
562 "previously imported from an LDIF file. The " \
563 "\"Distinguished Name\" (DN) user attribute, if " \
564 "present in the address book data, may be used in " \
565 "the exported LDIF file. The RDN selected above " \
566 "will be used if the DN user attribute is not found."
571 checkEMail = gtk_check_button_new_with_label(
572 _( "Exclude record if no Email Address" ) );
573 gtk_table_attach(GTK_TABLE(table), checkEMail, 1, 2, top, (top + 1),
576 toolTip = gtk_tooltips_new();
577 gtk_tooltips_set_tip(
578 GTK_TOOLTIPS(toolTip), checkEMail, _(
579 "An addressbook may contain entries without " \
580 "Email Addresses. Check this option to ignore " \
585 gtk_widget_show_all(vbox);
587 g_signal_connect(G_OBJECT(optmenuRDN), "changed",
588 G_CALLBACK(export_ldif_relative_dn_changed), labelRDN);
589 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenuRDN), 0);
592 expldif_dlg.entrySuffix = entrySuffix;
593 expldif_dlg.optmenuRDN = optmenuRDN;
594 expldif_dlg.checkUseDN = checkUseDN;
595 expldif_dlg.checkEMail = checkEMail;
599 * Format notebook finish page.
600 * \param pageNum Page (tab) number.
601 * \param pageLbl Page (tab) label.
603 static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
607 GtkWidget *labelBook;
608 GtkWidget *labelFile;
611 vbox = gtk_vbox_new(FALSE, 8);
612 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
613 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
615 label = gtk_label_new( pageLbl );
616 gtk_widget_show( label );
617 gtk_notebook_set_tab_label(
618 GTK_NOTEBOOK( expldif_dlg.notebook ),
619 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
621 table = gtk_table_new( 3, 3, FALSE );
622 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
623 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
624 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
625 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
629 label = gtk_label_new( _( "Address Book :" ) );
630 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
631 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
633 labelBook = gtk_label_new("Full name of address book goes here");
634 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
635 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
639 label = gtk_label_new( _( "File Name :" ) );
640 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
641 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
643 labelFile = gtk_label_new("File name goes here");
644 gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
645 gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
647 gtk_widget_show_all(vbox);
649 expldif_dlg.labelOutBook = labelBook;
650 expldif_dlg.labelOutFile = labelFile;
654 * Create main dialog decorations (excluding notebook pages).
656 static void export_ldif_dialog_create( void ) {
664 GtkWidget *btnCancel;
666 GtkWidget *statusbar;
668 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "expldifdlg");
669 gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
670 gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
671 gtk_window_set_title( GTK_WINDOW(window),
672 _("Export Address Book to LDIF File") );
673 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
674 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
675 g_signal_connect(G_OBJECT(window), "delete_event",
676 G_CALLBACK(export_ldif_delete_event),
678 g_signal_connect(G_OBJECT(window), "key_press_event",
679 G_CALLBACK(export_ldif_key_pressed),
682 vbox = gtk_vbox_new(FALSE, 4);
683 gtk_widget_show(vbox);
684 gtk_container_add(GTK_CONTAINER(window), vbox);
686 vnbox = gtk_vbox_new(FALSE, 4);
687 gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
688 gtk_widget_show(vnbox);
689 gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
692 notebook = gtk_notebook_new();
693 gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
694 /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
695 gtk_widget_show(notebook);
696 gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
697 gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
700 hsbox = gtk_hbox_new(FALSE, 0);
701 gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
702 statusbar = gtk_statusbar_new();
703 gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
706 gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
707 &btnNext, GTK_STOCK_GO_FORWARD,
708 &btnCancel, GTK_STOCK_CANCEL);
709 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
710 gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
711 gtk_widget_grab_default(btnNext);
713 /* Button handlers */
714 g_signal_connect(G_OBJECT(btnPrev), "clicked",
715 G_CALLBACK(export_ldif_prev), NULL);
716 g_signal_connect(G_OBJECT(btnNext), "clicked",
717 G_CALLBACK(export_ldif_next), NULL);
718 g_signal_connect(G_OBJECT(btnCancel), "clicked",
719 G_CALLBACK(export_ldif_cancel), NULL);
721 gtk_widget_show_all(vbox);
723 expldif_dlg.window = window;
724 expldif_dlg.notebook = notebook;
725 expldif_dlg.btnPrev = btnPrev;
726 expldif_dlg.btnNext = btnNext;
727 expldif_dlg.btnCancel = btnCancel;
728 expldif_dlg.statusbar = statusbar;
729 expldif_dlg.status_cid = gtk_statusbar_get_context_id(
730 GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
734 * Create export LDIF dialog.
736 static void export_ldif_create( void ) {
737 export_ldif_dialog_create();
738 export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
739 export_ldif_page_dn( PAGE_DN, _( "Distinguished Name" ) );
740 export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
741 gtk_widget_show_all( expldif_dlg.window );
745 * Populate fields from control data.
746 * \param ctl Export control data.
748 static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
749 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
751 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
754 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
756 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
760 gtk_combo_box_set_active(
761 GTK_COMBO_BOX( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
762 gtk_toggle_button_set_active(
763 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
764 gtk_toggle_button_set_active(
765 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
769 * Process export address dialog.
770 * \param cache Address book/data source cache.
772 void addressbook_exp_ldif( AddressCache *cache ) {
773 /* Set references to control data */
774 _addressCache_ = cache;
776 _exportCtl_ = exportldif_create();
777 exportldif_load_settings( _exportCtl_ );
780 if( ! expldif_dlg.window )
781 export_ldif_create();
783 gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
785 expldif_dlg.cancelled = FALSE;
786 gtk_widget_show(expldif_dlg.window);
787 manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
789 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
790 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
791 export_ldif_fill_fields( _exportCtl_ );
793 gtk_widget_grab_default(expldif_dlg.btnNext);
794 gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
795 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
796 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
798 export_ldif_message();
799 gtk_widget_grab_focus(expldif_dlg.entryLdif);
802 gtk_widget_hide(expldif_dlg.window);
803 exportldif_free( _exportCtl_ );
806 _addressCache_ = NULL;
810 * ============================================================================
812 * ============================================================================