2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2012 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.
26 #include "claws-features.h"
32 #include <glib/gi18n.h>
33 #include <gdk/gdkkeysyms.h>
37 #include "prefs_common.h"
38 #include "alertpanel.h"
40 #include "addrcache.h"
41 #include "addressitem.h"
42 #include "exportldif.h"
44 #include "manage_window.h"
48 #define PAGE_FILE_INFO 0
52 #define EXPORTLDIF_WIDTH 480
53 #define EXPORTLDIF_HEIGHT -1
58 static struct _ExpLdif_Dlg {
63 GtkWidget *entrySuffix;
64 GtkWidget *optmenuRDN;
65 GtkWidget *checkUseDN;
66 GtkWidget *checkEMail;
67 GtkWidget *labelOutBook;
68 GtkWidget *labelOutFile;
77 static struct _AddressFileSelection _exp_ldif_file_selector_;
79 static ExportLdifCtl *_exportCtl_ = NULL;
80 static AddressCache *_addressCache_ = NULL;
83 * Display message in status field.
84 * \param msg Message to display.
86 static void export_ldif_status_show( gchar *msg ) {
87 if( expldif_dlg.statusbar != NULL ) {
89 GTK_STATUSBAR(expldif_dlg.statusbar),
90 expldif_dlg.status_cid );
93 GTK_STATUSBAR(expldif_dlg.statusbar),
94 expldif_dlg.status_cid, msg );
100 * Select and display status message appropriate for the page being displayed.
102 static void export_ldif_message( void ) {
106 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
107 if( pageNum == PAGE_FILE_INFO ) {
108 sMsg = _( "Please specify output directory and LDIF filename to create." );
110 else if( pageNum == PAGE_DN ) {
111 sMsg = _( "Specify parameters to format distinguished name." );
113 else if( pageNum == PAGE_FINISH ) {
114 sMsg = _( "File exported successfully." );
116 export_ldif_status_show( sMsg );
120 * Callback function to cancel LDIF file selection dialog.
121 * \param widget Widget (button).
122 * \param data User data.
124 static void export_ldif_cancel( GtkWidget *widget, gpointer data ) {
127 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
128 if( pageNum != PAGE_FINISH ) {
129 expldif_dlg.cancelled = TRUE;
135 * Callback function to handle dialog close event.
136 * \param widget Widget (dialog).
137 * \param event Event object.
138 * \param data User data.
140 static gint export_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
141 export_ldif_cancel( widget, data );
146 * Callback function to respond to dialog key press events.
147 * \param widget Widget.
148 * \param event Event object.
149 * \param data User data.
151 static gboolean export_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
152 if (event && event->keyval == GDK_KEY_Escape) {
153 export_ldif_cancel( widget, data );
159 * Test whether we can move off file page.
160 * \return <i>TRUE</i> if OK to move off page.
162 static gboolean exp_ldif_move_file( void ) {
163 gchar *sFile, *msg, *reason;
164 gboolean errFlag = FALSE;
167 sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
168 g_strchug( sFile ); g_strchomp( sFile );
169 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
170 exportldif_parse_filespec( _exportCtl_, sFile );
172 /* Test that something was supplied */
173 if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
174 gtk_widget_grab_focus( expldif_dlg.entryLdif );
178 if( errFlag ) return FALSE;
180 /* Test for directory */
181 if( g_file_test(_exportCtl_->dirOutput,
182 G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) {
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, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
194 if( aval != G_ALERTALTERNATE ) 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_full(_("Failed to Create Directory"), msg,
203 GTK_STOCK_CLOSE, NULL, NULL, FALSE,
204 NULL, ALERT_ERROR, G_ALERTDEFAULT);
213 * Test whether we can move off distinguished name page.
214 * \return <i>TRUE</i> if OK to move off page.
216 static gboolean exp_ldif_move_dn( void ) {
217 gboolean retVal = FALSE;
218 gboolean errFlag = FALSE;
223 suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
224 g_strchug( suffix ); g_strchomp( suffix );
227 id = combobox_get_active_data(GTK_COMBO_BOX(expldif_dlg.optmenuRDN));
228 exportldif_set_rdn( _exportCtl_, id );
230 exportldif_set_suffix( _exportCtl_, suffix );
231 exportldif_set_use_dn( _exportCtl_,
232 gtk_toggle_button_get_active(
233 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
234 exportldif_set_exclude_email( _exportCtl_,
235 gtk_toggle_button_get_active(
236 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );
238 if( *suffix == '\0' || strlen( suffix ) < 1 ) {
242 _( "Suffix was not supplied" ),
244 "A suffix is required if data is to be used " \
245 "for an LDAP server. Are you sure you wish " \
246 "to proceed without a suffix?"
248 GTK_STOCK_NO, GTK_STOCK_YES, NULL );
249 if( aval != G_ALERTALTERNATE ) {
250 gtk_widget_grab_focus( expldif_dlg.entrySuffix );
257 exportldif_process( _exportCtl_, _addressCache_ );
258 if( _exportCtl_->retVal == MGU_SUCCESS ) {
262 export_ldif_status_show( _( "Error creating LDIF file" ) );
270 * Display finish page.
272 static void exp_ldif_finish_show( void ) {
273 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutFile), _exportCtl_->path );
274 gtk_widget_set_sensitive( expldif_dlg.btnNext, FALSE );
275 gtk_widget_grab_focus( expldif_dlg.btnCancel );
279 * Callback function to select previous page.
280 * \param widget Widget (button).
282 static void export_ldif_prev( GtkWidget *widget ) {
285 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
286 if( pageNum == PAGE_DN ) {
287 /* Goto file page stuff */
288 gtk_notebook_set_current_page(
289 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
290 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
292 else if( pageNum == PAGE_FINISH ) {
293 /* Goto format page */
294 gtk_notebook_set_current_page(
295 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
296 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
298 export_ldif_message();
302 * Callback function to select next page.
303 * \param widget Widget (button).
305 static void export_ldif_next( GtkWidget *widget ) {
308 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
309 if( pageNum == PAGE_FILE_INFO ) {
310 /* Goto distinguished name page */
311 if( exp_ldif_move_file() ) {
312 gtk_notebook_set_current_page(
313 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
314 gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE );
316 export_ldif_message();
318 else if( pageNum == PAGE_DN ) {
319 /* Goto finish page */
320 if( exp_ldif_move_dn() ) {
321 gtk_notebook_set_current_page(
322 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH );
323 gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
325 exp_ldif_finish_show();
326 exportldif_save_settings( _exportCtl_ );
327 export_ldif_message();
333 * Create LDIF file selection dialog.
334 * \param afs Address file selection data.
336 static void exp_ldif_file_select_create( AddressFileSelection *afs ) {
337 gchar *file = filesel_select_file_save(_("Select LDIF output file"), NULL);
340 afs->cancelled = TRUE;
342 afs->cancelled = FALSE;
343 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), file );
349 * Callback function to display LDIF file selection dialog.
351 static void exp_ldif_file_select( void ) {
352 exp_ldif_file_select_create( & _exp_ldif_file_selector_ );
356 * Format notebook file specification page.
357 * \param pageNum Page (tab) number.
358 * \param pageLbl Page (tab) label.
360 static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) {
364 GtkWidget *labelBook;
365 GtkWidget *entryLdif;
369 vbox = gtk_vbox_new(FALSE, 8);
370 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
371 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
373 label = gtk_label_new( pageLbl );
374 gtk_widget_show( label );
375 gtk_notebook_set_tab_label(
376 GTK_NOTEBOOK( expldif_dlg.notebook ),
377 gtk_notebook_get_nth_page(
378 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
381 table = gtk_table_new( 3, 3, FALSE );
382 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
383 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
384 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
385 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
389 label = gtk_label_new( _( "Address Book" ) );
390 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
392 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
394 labelBook = gtk_label_new( "Address book name goes here" );
395 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
396 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
397 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
401 label = gtk_label_new( _( "LDIF Output File" ) );
402 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
404 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
406 entryLdif = gtk_entry_new();
407 gtk_table_attach(GTK_TABLE(table), entryLdif, 1, 2, top, (top + 1),
408 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
410 btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
411 gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
414 gtk_widget_show_all(vbox);
417 g_signal_connect(G_OBJECT(btnFile), "clicked",
418 G_CALLBACK(exp_ldif_file_select), NULL);
420 expldif_dlg.labelBook = labelBook;
421 expldif_dlg.entryLdif = entryLdif;
424 static void export_ldif_relative_dn_changed(GtkWidget *widget, gpointer data)
426 gint relativeDN = combobox_get_active_data(GTK_COMBO_BOX(widget));
427 GtkLabel *label = GTK_LABEL(data);
430 case EXPORT_LDIF_ID_UID:
431 gtk_label_set_text(label,
432 _("The address book Unique ID is used to create a DN that is " \
433 "formatted similar to:\n" \
434 " uid=102376,ou=people,dc=claws-mail,dc=org"));
436 case EXPORT_LDIF_ID_DNAME:
437 gtk_label_set_text(label,
438 _("The address book Display Name is used to create a DN that " \
439 "is formatted similar to:\n" \
440 " cn=John Doe,ou=people,dc=claws-mail,dc=org"));
442 case EXPORT_LDIF_ID_EMAIL:
443 gtk_label_set_text(label,
444 _("The first Email Address belonging to a person is used to " \
445 "create a DN that is formatted similar to:\n" \
446 " mail=john.doe@domain.com,ou=people,dc=claws-mail,dc=org"));
453 * Format notebook distinguished name page.
454 * \param pageNum Page (tab) number.
455 * \param pageLbl Page (tab) label.
457 static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) {
461 GtkWidget *entrySuffix;
462 GtkWidget *optmenuRDN;
464 GtkWidget *checkUseDN;
465 GtkWidget *checkEMail;
470 vbox = gtk_vbox_new(FALSE, 8);
471 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
472 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
474 label = gtk_label_new( pageLbl );
475 gtk_widget_show( label );
476 gtk_notebook_set_tab_label(
477 GTK_NOTEBOOK( expldif_dlg.notebook ),
478 gtk_notebook_get_nth_page(
479 GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
482 table = gtk_table_new( 6, 2, FALSE );
483 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
484 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
485 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
486 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
490 label = gtk_label_new( _( "Suffix" ) );
491 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
493 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
495 entrySuffix = gtk_entry_new();
496 gtk_table_attach(GTK_TABLE(table), entrySuffix, 1, 2, top, (top + 1),
497 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
499 CLAWS_SET_TIP(entrySuffix, _(
500 "The suffix is used to create a \"Distinguished Name\" " \
501 "(or DN) for an LDAP entry. Examples include:\n" \
502 " dc=claws-mail,dc=org\n" \
503 " ou=people,dc=domainname,dc=com\n" \
504 " o=Organization Name,c=Country\n"));
508 label = gtk_label_new( _( "Relative DN" ) );
509 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
511 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
513 optmenuRDN = gtkut_sc_combobox_create(NULL, TRUE);
514 store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuRDN)));
516 COMBOBOX_ADD(store, _("Unique ID"), EXPORT_LDIF_ID_UID);
517 COMBOBOX_ADD(store, _("Display Name"), EXPORT_LDIF_ID_DNAME);
518 COMBOBOX_ADD(store, _("Email Address"), EXPORT_LDIF_ID_EMAIL);
520 gtk_table_attach(GTK_TABLE(table), optmenuRDN, 1, 2, top, (top + 1),
523 CLAWS_SET_TIP(optmenuRDN, _(
524 "The LDIF file contains several data records that " \
525 "are usually loaded into an LDAP server. Each data " \
526 "record in the LDIF file is uniquely identified by " \
527 "a \"Distinguished Name\" (or DN). The suffix is " \
528 "appended to the \"Relative Distinguished Name\" "\
529 "(or RDN) to create the DN. Please select one of " \
530 "the available RDN options that will be used to " \
535 labelRDN = gtk_label_new("");
536 gtk_label_set_line_wrap(GTK_LABEL(labelRDN), TRUE);
537 gtk_label_set_justify(GTK_LABEL(labelRDN), GTK_JUSTIFY_CENTER);
538 gtk_table_attach(GTK_TABLE(table), labelRDN, 0, 2, top, (top + 1),
543 checkUseDN = gtk_check_button_new_with_label(
544 _( "Use DN attribute if present in data" ) );
545 gtk_table_attach(GTK_TABLE(table), checkUseDN, 1, 2, top, (top + 1),
548 CLAWS_SET_TIP(checkUseDN, _(
549 "The addressbook may contain entries that were " \
550 "previously imported from an LDIF file. The " \
551 "\"Distinguished Name\" (DN) user attribute, if " \
552 "present in the address book data, may be used in " \
553 "the exported LDIF file. The RDN selected above " \
554 "will be used if the DN user attribute is not found."));
558 checkEMail = gtk_check_button_new_with_label(
559 _( "Exclude record if no Email Address" ) );
560 gtk_table_attach(GTK_TABLE(table), checkEMail, 1, 2, top, (top + 1),
563 CLAWS_SET_TIP(checkEMail, _(
564 "An addressbook may contain entries without " \
565 "Email Addresses. Check this option to ignore " \
569 gtk_widget_show_all(vbox);
571 g_signal_connect(G_OBJECT(optmenuRDN), "changed",
572 G_CALLBACK(export_ldif_relative_dn_changed), labelRDN);
573 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenuRDN), 0);
576 expldif_dlg.entrySuffix = entrySuffix;
577 expldif_dlg.optmenuRDN = optmenuRDN;
578 expldif_dlg.checkUseDN = checkUseDN;
579 expldif_dlg.checkEMail = checkEMail;
583 * Format notebook finish page.
584 * \param pageNum Page (tab) number.
585 * \param pageLbl Page (tab) label.
587 static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
591 GtkWidget *labelBook;
592 GtkWidget *labelFile;
595 vbox = gtk_vbox_new(FALSE, 8);
596 gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
597 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
599 label = gtk_label_new( pageLbl );
600 gtk_widget_show( label );
601 gtk_notebook_set_tab_label(
602 GTK_NOTEBOOK( expldif_dlg.notebook ),
603 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
605 table = gtk_table_new( 3, 3, FALSE );
606 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
607 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
608 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
609 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
613 label = gtk_label_new( _( "Address Book :" ) );
614 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
615 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
617 labelBook = gtk_label_new("Full name of address book goes here");
618 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
619 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
623 label = gtk_label_new( _( "File Name :" ) );
624 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
625 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
627 labelFile = gtk_label_new("File name goes here");
628 gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
629 gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
631 gtk_widget_show_all(vbox);
633 expldif_dlg.labelOutBook = labelBook;
634 expldif_dlg.labelOutFile = labelFile;
638 * Create main dialog decorations (excluding notebook pages).
640 static void export_ldif_dialog_create( void ) {
648 GtkWidget *btnCancel;
650 GtkWidget *statusbar;
652 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "expldifdlg");
653 gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
654 gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
655 gtk_window_set_title( GTK_WINDOW(window),
656 _("Export Address Book to LDIF File") );
657 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
658 g_signal_connect(G_OBJECT(window), "delete_event",
659 G_CALLBACK(export_ldif_delete_event),
661 g_signal_connect(G_OBJECT(window), "key_press_event",
662 G_CALLBACK(export_ldif_key_pressed),
665 vbox = gtk_vbox_new(FALSE, 4);
666 gtk_widget_show(vbox);
667 gtk_container_add(GTK_CONTAINER(window), vbox);
669 vnbox = gtk_vbox_new(FALSE, 4);
670 gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
671 gtk_widget_show(vnbox);
672 gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
675 notebook = gtk_notebook_new();
676 gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
677 /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
678 gtk_widget_show(notebook);
679 gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
680 gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
683 hsbox = gtk_hbox_new(FALSE, 0);
684 gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
685 statusbar = gtk_statusbar_new();
686 gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
689 gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
690 &btnNext, GTK_STOCK_GO_FORWARD,
691 &btnCancel, GTK_STOCK_CANCEL);
692 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
693 gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
694 gtk_widget_grab_default(btnNext);
696 /* Button handlers */
697 g_signal_connect(G_OBJECT(btnPrev), "clicked",
698 G_CALLBACK(export_ldif_prev), NULL);
699 g_signal_connect(G_OBJECT(btnNext), "clicked",
700 G_CALLBACK(export_ldif_next), NULL);
701 g_signal_connect(G_OBJECT(btnCancel), "clicked",
702 G_CALLBACK(export_ldif_cancel), NULL);
704 gtk_widget_show_all(vbox);
706 expldif_dlg.window = window;
707 expldif_dlg.notebook = notebook;
708 expldif_dlg.btnPrev = btnPrev;
709 expldif_dlg.btnNext = btnNext;
710 expldif_dlg.btnCancel = btnCancel;
711 expldif_dlg.statusbar = statusbar;
712 expldif_dlg.status_cid = gtk_statusbar_get_context_id(
713 GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
717 * Create export LDIF dialog.
719 static void export_ldif_create( void ) {
720 export_ldif_dialog_create();
721 export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
722 export_ldif_page_dn( PAGE_DN, _( "Distinguished Name" ) );
723 export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
724 gtk_widget_show_all( expldif_dlg.window );
728 * Populate fields from control data.
729 * \param ctl Export control data.
731 static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
732 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
734 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
737 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
739 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
743 gtk_combo_box_set_active(
744 GTK_COMBO_BOX( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
745 gtk_toggle_button_set_active(
746 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
747 gtk_toggle_button_set_active(
748 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
752 * Process export address dialog.
753 * \param cache Address book/data source cache.
755 void addressbook_exp_ldif( AddressCache *cache ) {
756 /* Set references to control data */
757 _addressCache_ = cache;
759 _exportCtl_ = exportldif_create();
760 exportldif_load_settings( _exportCtl_ );
763 if( ! expldif_dlg.window )
764 export_ldif_create();
766 gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
768 expldif_dlg.cancelled = FALSE;
769 gtk_widget_show(expldif_dlg.window);
770 manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
771 gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), TRUE);
772 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
773 gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
774 export_ldif_fill_fields( _exportCtl_ );
776 gtk_widget_grab_default(expldif_dlg.btnNext);
777 gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
778 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
779 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
781 export_ldif_message();
782 gtk_widget_grab_focus(expldif_dlg.entryLdif);
785 gtk_widget_hide(expldif_dlg.window);
786 gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), FALSE);
787 exportldif_free( _exportCtl_ );
790 _addressCache_ = NULL;
794 * ============================================================================
796 * ============================================================================