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;
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 CLAWS_SET_TIP(entrySuffix, _(
504 "The suffix is used to create a \"Distinguished Name\" " \
505 "(or DN) for an LDAP entry. Examples include:\n" \
506 " dc=claws-mail,dc=org\n" \
507 " ou=people,dc=domainname,dc=com\n" \
508 " o=Organization Name,c=Country\n"));
512 label = gtk_label_new( _( "Relative DN" ) );
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 optmenuRDN = gtkut_sc_combobox_create(NULL, TRUE);
518 store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuRDN)));
520 COMBOBOX_ADD(store, _("Unique ID"), EXPORT_LDIF_ID_UID);
521 COMBOBOX_ADD(store, _("Display Name"), EXPORT_LDIF_ID_DNAME);
522 COMBOBOX_ADD(store, _("Email Address"), EXPORT_LDIF_ID_EMAIL);
524 gtk_table_attach(GTK_TABLE(table), optmenuRDN, 1, 2, top, (top + 1),
527 CLAWS_SET_TIP(optmenuRDN, _(
528 "The LDIF file contains several data records that " \
529 "are usually loaded into an LDAP server. Each data " \
530 "record in the LDIF file is uniquely identified by " \
531 "a \"Distinguished Name\" (or DN). The suffix is " \
532 "appended to the \"Relative Distinguished Name\" "\
533 "(or RDN) to create the DN. Please select one of " \
534 "the available RDN options that will be used to " \
539 labelRDN = gtk_label_new("");
540 gtk_label_set_line_wrap(GTK_LABEL(labelRDN), TRUE);
541 gtk_label_set_justify(GTK_LABEL(labelRDN), GTK_JUSTIFY_CENTER);
542 gtk_table_attach(GTK_TABLE(table), labelRDN, 0, 2, top, (top + 1),
547 checkUseDN = gtk_check_button_new_with_label(
548 _( "Use DN attribute if present in data" ) );
549 gtk_table_attach(GTK_TABLE(table), checkUseDN, 1, 2, top, (top + 1),
552 CLAWS_SET_TIP(checkUseDN, _(
553 "The addressbook may contain entries that were " \
554 "previously imported from an LDIF file. The " \
555 "\"Distinguished Name\" (DN) user attribute, if " \
556 "present in the address book data, may be used in " \
557 "the exported LDIF file. The RDN selected above " \
558 "will be used if the DN user attribute is not found."));
562 checkEMail = gtk_check_button_new_with_label(
563 _( "Exclude record if no Email Address" ) );
564 gtk_table_attach(GTK_TABLE(table), checkEMail, 1, 2, top, (top + 1),
567 CLAWS_SET_TIP(checkEMail, _(
568 "An addressbook may contain entries without " \
569 "Email Addresses. Check this option to ignore " \
573 gtk_widget_show_all(vbox);
575 g_signal_connect(G_OBJECT(optmenuRDN), "changed",
576 G_CALLBACK(export_ldif_relative_dn_changed), labelRDN);
577 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenuRDN), 0);
580 expldif_dlg.entrySuffix = entrySuffix;
581 expldif_dlg.optmenuRDN = optmenuRDN;
582 expldif_dlg.checkUseDN = checkUseDN;
583 expldif_dlg.checkEMail = checkEMail;
587 * Format notebook finish page.
588 * \param pageNum Page (tab) number.
589 * \param pageLbl Page (tab) label.
591 static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
595 GtkWidget *labelBook;
596 GtkWidget *labelFile;
599 vbox = gtk_vbox_new(FALSE, 8);
600 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
601 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
603 label = gtk_label_new( pageLbl );
604 gtk_widget_show( label );
605 gtk_notebook_set_tab_label(
606 GTK_NOTEBOOK( expldif_dlg.notebook ),
607 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
609 table = gtk_table_new( 3, 3, FALSE );
610 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
611 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
612 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
613 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
617 label = gtk_label_new( _( "Address Book :" ) );
618 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
619 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
621 labelBook = gtk_label_new("Full name of address book goes here");
622 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
623 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
627 label = gtk_label_new( _( "File Name :" ) );
628 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
629 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
631 labelFile = gtk_label_new("File name goes here");
632 gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
633 gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
635 gtk_widget_show_all(vbox);
637 expldif_dlg.labelOutBook = labelBook;
638 expldif_dlg.labelOutFile = labelFile;
642 * Create main dialog decorations (excluding notebook pages).
644 static void export_ldif_dialog_create( void ) {
652 GtkWidget *btnCancel;
654 GtkWidget *statusbar;
656 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "expldifdlg");
657 gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
658 gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
659 gtk_window_set_title( GTK_WINDOW(window),
660 _("Export Address Book to LDIF File") );
661 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
662 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
663 g_signal_connect(G_OBJECT(window), "delete_event",
664 G_CALLBACK(export_ldif_delete_event),
666 g_signal_connect(G_OBJECT(window), "key_press_event",
667 G_CALLBACK(export_ldif_key_pressed),
670 vbox = gtk_vbox_new(FALSE, 4);
671 gtk_widget_show(vbox);
672 gtk_container_add(GTK_CONTAINER(window), vbox);
674 vnbox = gtk_vbox_new(FALSE, 4);
675 gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
676 gtk_widget_show(vnbox);
677 gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
680 notebook = gtk_notebook_new();
681 gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
682 /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
683 gtk_widget_show(notebook);
684 gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
685 gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
688 hsbox = gtk_hbox_new(FALSE, 0);
689 gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
690 statusbar = gtk_statusbar_new();
691 gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
694 gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
695 &btnNext, GTK_STOCK_GO_FORWARD,
696 &btnCancel, GTK_STOCK_CANCEL);
697 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
698 gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
699 gtk_widget_grab_default(btnNext);
701 /* Button handlers */
702 g_signal_connect(G_OBJECT(btnPrev), "clicked",
703 G_CALLBACK(export_ldif_prev), NULL);
704 g_signal_connect(G_OBJECT(btnNext), "clicked",
705 G_CALLBACK(export_ldif_next), NULL);
706 g_signal_connect(G_OBJECT(btnCancel), "clicked",
707 G_CALLBACK(export_ldif_cancel), NULL);
709 gtk_widget_show_all(vbox);
711 expldif_dlg.window = window;
712 expldif_dlg.notebook = notebook;
713 expldif_dlg.btnPrev = btnPrev;
714 expldif_dlg.btnNext = btnNext;
715 expldif_dlg.btnCancel = btnCancel;
716 expldif_dlg.statusbar = statusbar;
717 expldif_dlg.status_cid = gtk_statusbar_get_context_id(
718 GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
722 * Create export LDIF dialog.
724 static void export_ldif_create( void ) {
725 export_ldif_dialog_create();
726 export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
727 export_ldif_page_dn( PAGE_DN, _( "Distinguished Name" ) );
728 export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
729 gtk_widget_show_all( expldif_dlg.window );
733 * Populate fields from control data.
734 * \param ctl Export control data.
736 static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
737 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
739 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
742 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
744 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
748 gtk_combo_box_set_active(
749 GTK_COMBO_BOX( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
750 gtk_toggle_button_set_active(
751 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
752 gtk_toggle_button_set_active(
753 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
757 * Process export address dialog.
758 * \param cache Address book/data source cache.
760 void addressbook_exp_ldif( AddressCache *cache ) {
761 /* Set references to control data */
762 _addressCache_ = cache;
764 _exportCtl_ = exportldif_create();
765 exportldif_load_settings( _exportCtl_ );
768 if( ! expldif_dlg.window )
769 export_ldif_create();
771 gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
773 expldif_dlg.cancelled = FALSE;
774 gtk_widget_show(expldif_dlg.window);
775 manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
777 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
778 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
779 export_ldif_fill_fields( _exportCtl_ );
781 gtk_widget_grab_default(expldif_dlg.btnNext);
782 gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
783 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
784 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
786 export_ldif_message();
787 gtk_widget_grab_focus(expldif_dlg.entryLdif);
790 gtk_widget_hide(expldif_dlg.window);
791 exportldif_free( _exportCtl_ );
794 _addressCache_ = NULL;
798 * ============================================================================
800 * ============================================================================