2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2003-2006 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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"
51 #define PAGE_FILE_INFO 0
55 #define EXPORTLDIF_WIDTH 480
56 #define EXPORTLDIF_HEIGHT -1
61 static struct _ExpLdif_Dlg
{
66 GtkWidget
*entrySuffix
;
67 GtkWidget
*optmenuRDN
;
68 GtkWidget
*checkUseDN
;
69 GtkWidget
*checkEMail
;
70 GtkWidget
*labelOutBook
;
71 GtkWidget
*labelOutFile
;
80 static struct _AddressFileSelection _exp_ldif_file_selector_
;
82 static ExportLdifCtl
*_exportCtl_
= NULL
;
83 static AddressCache
*_addressCache_
= NULL
;
86 * Display message in status field.
87 * \param msg Message to display.
89 static void export_ldif_status_show( gchar
*msg
) {
90 if( expldif_dlg
.statusbar
!= NULL
) {
92 GTK_STATUSBAR(expldif_dlg
.statusbar
),
93 expldif_dlg
.status_cid
);
96 GTK_STATUSBAR(expldif_dlg
.statusbar
),
97 expldif_dlg
.status_cid
, msg
);
103 * Select and display status message appropriate for the page being displayed.
105 static void export_ldif_message( void ) {
109 pageNum
= gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg
.notebook
) );
110 if( pageNum
== PAGE_FILE_INFO
) {
111 sMsg
= _( "Please specify output directory and LDIF filename to create." );
113 else if( pageNum
== PAGE_DN
) {
114 sMsg
= _( "Specify parameters to format distinguished name." );
116 else if( pageNum
== PAGE_FINISH
) {
117 sMsg
= _( "File exported successfully." );
119 export_ldif_status_show( sMsg
);
123 * Callback function to cancel LDIF file selection dialog.
124 * \param widget Widget (button).
125 * \param data User data.
127 static void export_ldif_cancel( GtkWidget
*widget
, gpointer data
) {
130 pageNum
= gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg
.notebook
) );
131 if( pageNum
!= PAGE_FINISH
) {
132 expldif_dlg
.cancelled
= TRUE
;
138 * Callback function to handle dialog close event.
139 * \param widget Widget (dialog).
140 * \param event Event object.
141 * \param data User data.
143 static gint
export_ldif_delete_event( GtkWidget
*widget
, GdkEventAny
*event
, gpointer data
) {
144 export_ldif_cancel( widget
, data
);
149 * Callback function to respond to dialog key press events.
150 * \param widget Widget.
151 * \param event Event object.
152 * \param data User data.
154 static gboolean
export_ldif_key_pressed( GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
) {
155 if (event
&& event
->keyval
== GDK_Escape
) {
156 export_ldif_cancel( widget
, data
);
162 * Test whether we can move off file page.
163 * \return <i>TRUE</i> if OK to move off page.
165 static gboolean
exp_ldif_move_file( void ) {
166 gchar
*sFile
, *msg
, *reason
;
167 gboolean errFlag
= FALSE
;
170 sFile
= gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg
.entryLdif
), 0, -1 );
171 g_strchug( sFile
); g_strchomp( sFile
);
172 gtk_entry_set_text( GTK_ENTRY(expldif_dlg
.entryLdif
), sFile
);
173 exportldif_parse_filespec( _exportCtl_
, sFile
);
175 /* Test that something was supplied */
176 if( *sFile
== '\0'|| strlen( sFile
) < 1 ) {
177 gtk_widget_grab_focus( expldif_dlg
.entryLdif
);
181 if( errFlag
) return FALSE
;
183 /* Test for directory */
184 if( exportldif_test_dir( _exportCtl_
) ) {
188 /* Prompt to create */
189 msg
= g_strdup_printf( _(
190 "LDIF Output Directory '%s'\n" \
191 "does not exist. OK to create new directory?" ),
192 _exportCtl_
->dirOutput
);
193 aval
= alertpanel( _("Create Directory" ),
194 msg
, GTK_STOCK_NO
, GTK_STOCK_YES
, NULL
);
196 if( aval
!= G_ALERTALTERNATE
) return FALSE
;
198 /* Create directory */
199 if( ! exportldif_create_dir( _exportCtl_
) ) {
200 reason
= exportldif_get_create_msg( _exportCtl_
);
201 msg
= g_strdup_printf( _(
202 "Could not create output directory for LDIF file:\n%s" ),
204 aval
= alertpanel_full(_("Failed to Create Directory"), msg
,
205 GTK_STOCK_CLOSE
, NULL
, NULL
, FALSE
,
206 NULL
, ALERT_ERROR
, G_ALERTDEFAULT
);
215 * Test whether we can move off distinguished name page.
216 * \return <i>TRUE</i> if OK to move off page.
218 static gboolean
exp_ldif_move_dn( void ) {
219 gboolean retVal
= FALSE
;
220 gboolean errFlag
= FALSE
;
222 GtkWidget
*menu
, *menuItem
;
226 suffix
= gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg
.entrySuffix
), 0, -1 );
227 g_strchug( suffix
); g_strchomp( suffix
);
230 menu
= gtk_option_menu_get_menu( GTK_OPTION_MENU( expldif_dlg
.optmenuRDN
) );
231 menuItem
= gtk_menu_get_active( GTK_MENU( menu
) );
232 id
= GPOINTER_TO_INT( g_object_get_data(G_OBJECT(menuItem
), "user_data"));
233 exportldif_set_rdn( _exportCtl_
, id
);
235 exportldif_set_suffix( _exportCtl_
, suffix
);
236 exportldif_set_use_dn( _exportCtl_
,
237 gtk_toggle_button_get_active(
238 GTK_TOGGLE_BUTTON( expldif_dlg
.checkUseDN
) ) );
239 exportldif_set_exclude_email( _exportCtl_
,
240 gtk_toggle_button_get_active(
241 GTK_TOGGLE_BUTTON( expldif_dlg
.checkEMail
) ) );
243 if( *suffix
== '\0' || strlen( suffix
) < 1 ) {
247 _( "Suffix was not supplied" ),
249 "A suffix is required if data is to be used " \
250 "for an LDAP server. Are you sure you wish " \
251 "to proceed without a suffix?"
253 GTK_STOCK_NO
, GTK_STOCK_YES
, NULL
);
254 if( aval
!= G_ALERTALTERNATE
) {
255 gtk_widget_grab_focus( expldif_dlg
.entrySuffix
);
262 exportldif_process( _exportCtl_
, _addressCache_
);
263 if( _exportCtl_
->retVal
== MGU_SUCCESS
) {
267 export_ldif_status_show( _( "Error creating LDIF file" ) );
275 * Display finish page.
277 static void exp_ldif_finish_show( void ) {
278 gtk_label_set_text( GTK_LABEL(expldif_dlg
.labelOutFile
), _exportCtl_
->path
);
279 gtk_widget_set_sensitive( expldif_dlg
.btnNext
, FALSE
);
280 gtk_widget_grab_focus( expldif_dlg
.btnCancel
);
284 * Callback function to select previous page.
285 * \param widget Widget (button).
287 static void export_ldif_prev( GtkWidget
*widget
) {
290 pageNum
= gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg
.notebook
) );
291 if( pageNum
== PAGE_DN
) {
292 /* Goto file page stuff */
293 gtk_notebook_set_current_page(
294 GTK_NOTEBOOK(expldif_dlg
.notebook
), PAGE_FILE_INFO
);
295 gtk_widget_set_sensitive( expldif_dlg
.btnPrev
, FALSE
);
297 else if( pageNum
== PAGE_FINISH
) {
298 /* Goto format page */
299 gtk_notebook_set_current_page(
300 GTK_NOTEBOOK(expldif_dlg
.notebook
), PAGE_DN
);
301 gtk_widget_set_sensitive( expldif_dlg
.btnNext
, TRUE
);
303 export_ldif_message();
307 * Callback function to select next page.
308 * \param widget Widget (button).
310 static void export_ldif_next( GtkWidget
*widget
) {
313 pageNum
= gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg
.notebook
) );
314 if( pageNum
== PAGE_FILE_INFO
) {
315 /* Goto distinguished name page */
316 if( exp_ldif_move_file() ) {
317 gtk_notebook_set_current_page(
318 GTK_NOTEBOOK(expldif_dlg
.notebook
), PAGE_DN
);
319 gtk_widget_set_sensitive( expldif_dlg
.btnPrev
, TRUE
);
321 export_ldif_message();
323 else if( pageNum
== PAGE_DN
) {
324 /* Goto finish page */
325 if( exp_ldif_move_dn() ) {
326 gtk_notebook_set_current_page(
327 GTK_NOTEBOOK(expldif_dlg
.notebook
), PAGE_FINISH
);
328 gtk_button_set_label(GTK_BUTTON(expldif_dlg
.btnCancel
),
330 exp_ldif_finish_show();
331 exportldif_save_settings( _exportCtl_
);
332 export_ldif_message();
338 * Create LDIF file selection dialog.
339 * \param afs Address file selection data.
341 static void exp_ldif_file_select_create( AddressFileSelection
*afs
) {
342 gchar
*file
= filesel_select_file_save(_("Select LDIF output file"), NULL
);
345 afs
->cancelled
= TRUE
;
347 afs
->cancelled
= FALSE
;
348 gtk_entry_set_text( GTK_ENTRY(expldif_dlg
.entryLdif
), file
);
354 * Callback function to display LDIF file selection dialog.
356 static void exp_ldif_file_select( void ) {
357 exp_ldif_file_select_create( & _exp_ldif_file_selector_
);
361 * Format notebook file specification page.
362 * \param pageNum Page (tab) number.
363 * \param pageLbl Page (tab) label.
365 static void export_ldif_page_file( gint pageNum
, gchar
*pageLbl
) {
369 GtkWidget
*labelBook
;
370 GtkWidget
*entryLdif
;
374 vbox
= gtk_vbox_new(FALSE
, 8);
375 gtk_container_add( GTK_CONTAINER( expldif_dlg
.notebook
), vbox
);
376 gtk_container_set_border_width( GTK_CONTAINER (vbox
), BORDER_WIDTH
);
378 label
= gtk_label_new( pageLbl
);
379 gtk_widget_show( label
);
380 gtk_notebook_set_tab_label(
381 GTK_NOTEBOOK( expldif_dlg
.notebook
),
382 gtk_notebook_get_nth_page(
383 GTK_NOTEBOOK( expldif_dlg
.notebook
), pageNum
),
386 table
= gtk_table_new( 3, 3, FALSE
);
387 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
388 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
389 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
390 gtk_table_set_col_spacings(GTK_TABLE(table
), 8 );
394 label
= gtk_label_new( _( "Address Book" ) );
395 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1),
397 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
399 labelBook
= gtk_label_new( "Address book name goes here" );
400 gtk_table_attach(GTK_TABLE(table
), labelBook
, 1, 2, top
, (top
+ 1),
401 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
402 gtk_misc_set_alignment(GTK_MISC(labelBook
), 0, 0.5);
406 label
= gtk_label_new( _( "LDIF Output File" ) );
407 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1),
409 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
411 entryLdif
= gtk_entry_new();
412 gtk_table_attach(GTK_TABLE(table
), entryLdif
, 1, 2, top
, (top
+ 1),
413 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
415 btnFile
= gtkut_get_browse_file_btn(_("B_rowse"));
416 gtk_table_attach(GTK_TABLE(table
), btnFile
, 2, 3, top
, (top
+ 1),
419 gtk_widget_show_all(vbox
);
422 g_signal_connect(G_OBJECT(btnFile
), "clicked",
423 G_CALLBACK(exp_ldif_file_select
), NULL
);
425 expldif_dlg
.labelBook
= labelBook
;
426 expldif_dlg
.entryLdif
= entryLdif
;
430 * Format notebook distinguished name page.
431 * \param pageNum Page (tab) number.
432 * \param pageLbl Page (tab) label.
434 static void export_ldif_page_dn( gint pageNum
, gchar
*pageLbl
) {
438 GtkWidget
*entrySuffix
;
439 GtkWidget
*optmenuRDN
;
440 GtkWidget
*checkUseDN
;
441 GtkWidget
*checkEMail
;
444 GtkTooltips
*toolTip
;
447 vbox
= gtk_vbox_new(FALSE
, 8);
448 gtk_container_add( GTK_CONTAINER( expldif_dlg
.notebook
), vbox
);
449 gtk_container_set_border_width( GTK_CONTAINER (vbox
), BORDER_WIDTH
);
451 label
= gtk_label_new( pageLbl
);
452 gtk_widget_show( label
);
453 gtk_notebook_set_tab_label(
454 GTK_NOTEBOOK( expldif_dlg
.notebook
),
455 gtk_notebook_get_nth_page(
456 GTK_NOTEBOOK( expldif_dlg
.notebook
), pageNum
),
459 table
= gtk_table_new( 5, 2, FALSE
);
460 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
461 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
462 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
463 gtk_table_set_col_spacings(GTK_TABLE(table
), 8 );
467 label
= gtk_label_new( _( "Suffix" ) );
468 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1),
470 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
472 entrySuffix
= gtk_entry_new();
473 gtk_table_attach(GTK_TABLE(table
), entrySuffix
, 1, 2, top
, (top
+ 1),
474 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
476 toolTip
= gtk_tooltips_new();
477 gtk_tooltips_set_tip(
478 GTK_TOOLTIPS(toolTip
), entrySuffix
, _(
479 "The suffix is used to create a \"Distinguished Name\" " \
480 "(or DN) for an LDAP entry. Examples include:\n" \
481 " dc=claws-mail,dc=org\n" \
482 " ou=people,dc=domainname,dc=com\n" \
483 " o=Organization Name,c=Country\n"
488 label
= gtk_label_new( _( "Relative DN" ) );
489 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1),
491 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
493 menu
= gtk_menu_new();
495 menuItem
= gtk_menu_item_new_with_label( _( "Unique ID" ) );
496 g_object_set_data( G_OBJECT( menuItem
), "user_data",
497 GINT_TO_POINTER( EXPORT_LDIF_ID_UID
) );
498 gtk_menu_append( GTK_MENU(menu
), menuItem
);
499 gtk_widget_show( menuItem
);
500 toolTip
= gtk_tooltips_new();
501 gtk_tooltips_set_tip(
502 GTK_TOOLTIPS(toolTip
), menuItem
, _(
503 "The address book Unique ID is used to create a DN that is " \
504 "formatted similar to:\n" \
505 " uid=102376,ou=people,dc=claws-mail,dc=org"
508 menuItem
= gtk_menu_item_new_with_label( _( "Display Name" ) );
509 g_object_set_data( G_OBJECT( menuItem
), "user_data",
510 GINT_TO_POINTER( EXPORT_LDIF_ID_DNAME
) );
511 gtk_menu_append( GTK_MENU(menu
), menuItem
);
512 gtk_widget_show( menuItem
);
513 toolTip
= gtk_tooltips_new();
514 gtk_tooltips_set_tip(
515 GTK_TOOLTIPS(toolTip
), menuItem
, _(
516 "The address book Display Name is used to create a DN that " \
517 "is formatted similar to:\n" \
518 " cn=John Doe,ou=people,dc=claws-mail,dc=org"
521 menuItem
= gtk_menu_item_new_with_label( _( "Email Address" ) );
522 g_object_set_data( G_OBJECT( menuItem
), "user_data",
523 GINT_TO_POINTER( EXPORT_LDIF_ID_EMAIL
) );
524 gtk_menu_append( GTK_MENU(menu
), menuItem
);
525 gtk_widget_show( menuItem
);
526 toolTip
= gtk_tooltips_new();
527 gtk_tooltips_set_tip(
528 GTK_TOOLTIPS(toolTip
), menuItem
, _(
529 "The first Email Address belonging to a person is used to " \
530 "create a DN that is formatted similar to:\n" \
531 " mail=john.doe@domain.com,ou=people,dc=claws-mail,dc=org"
534 optmenuRDN
= gtk_option_menu_new();
535 gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuRDN
), menu
);
537 gtk_table_attach(GTK_TABLE(table
), optmenuRDN
, 1, 2, top
, (top
+ 1),
540 toolTip
= gtk_tooltips_new();
541 gtk_tooltips_set_tip(
542 GTK_TOOLTIPS(toolTip
), optmenuRDN
, _(
543 "The LDIF file contains several data records that " \
544 "are usually loaded into an LDAP server. Each data " \
545 "record in the LDIF file is uniquely identified by " \
546 "a \"Distinguished Name\" (or DN). The suffix is " \
547 "appended to the \"Relative Distinguished Name\" "\
548 "(or RDN) to create the DN. Please select one of " \
549 "the available RDN options that will be used to " \
555 checkUseDN
= gtk_check_button_new_with_label(
556 _( "Use DN attribute if present in data" ) );
557 gtk_table_attach(GTK_TABLE(table
), checkUseDN
, 1, 2, top
, (top
+ 1),
560 toolTip
= gtk_tooltips_new();
561 gtk_tooltips_set_tip(
562 GTK_TOOLTIPS(toolTip
), checkUseDN
, _(
563 "The addressbook may contain entries that were " \
564 "previously imported from an LDIF file. The " \
565 "\"Distinguished Name\" (DN) user attribute, if " \
566 "present in the address book data, may be used in " \
567 "the exported LDIF file. The RDN selected above " \
568 "will be used if the DN user attribute is not found."
573 checkEMail
= gtk_check_button_new_with_label(
574 _( "Exclude record if no Email Address" ) );
575 gtk_table_attach(GTK_TABLE(table
), checkEMail
, 1, 2, top
, (top
+ 1),
578 toolTip
= gtk_tooltips_new();
579 gtk_tooltips_set_tip(
580 GTK_TOOLTIPS(toolTip
), checkEMail
, _(
581 "An addressbook may contain entries without " \
582 "Email Addresses. Check this option to ignore " \
587 gtk_widget_show_all(vbox
);
589 expldif_dlg
.entrySuffix
= entrySuffix
;
590 expldif_dlg
.optmenuRDN
= optmenuRDN
;
591 expldif_dlg
.checkUseDN
= checkUseDN
;
592 expldif_dlg
.checkEMail
= checkEMail
;
596 * Format notebook finish page.
597 * \param pageNum Page (tab) number.
598 * \param pageLbl Page (tab) label.
600 static void export_ldif_page_finish( gint pageNum
, gchar
*pageLbl
) {
604 GtkWidget
*labelBook
;
605 GtkWidget
*labelFile
;
608 vbox
= gtk_vbox_new(FALSE
, 8);
609 gtk_container_add( GTK_CONTAINER( expldif_dlg
.notebook
), vbox
);
610 gtk_container_set_border_width( GTK_CONTAINER (vbox
), BORDER_WIDTH
);
612 label
= gtk_label_new( pageLbl
);
613 gtk_widget_show( label
);
614 gtk_notebook_set_tab_label(
615 GTK_NOTEBOOK( expldif_dlg
.notebook
),
616 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg
.notebook
), pageNum
), label
);
618 table
= gtk_table_new( 3, 3, FALSE
);
619 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
620 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
621 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
622 gtk_table_set_col_spacings(GTK_TABLE(table
), 8 );
626 label
= gtk_label_new( _( "Address Book :" ) );
627 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
628 gtk_misc_set_alignment(GTK_MISC(label
), 1, 0.5);
630 labelBook
= gtk_label_new("Full name of address book goes here");
631 gtk_table_attach(GTK_TABLE(table
), labelBook
, 1, 2, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
632 gtk_misc_set_alignment(GTK_MISC(labelBook
), 0, 0.5);
636 label
= gtk_label_new( _( "File Name :" ) );
637 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
638 gtk_misc_set_alignment(GTK_MISC(label
), 1, 0.5);
640 labelFile
= gtk_label_new("File name goes here");
641 gtk_table_attach(GTK_TABLE(table
), labelFile
, 1, 2, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
642 gtk_misc_set_alignment(GTK_MISC(labelFile
), 0, 0.5);
644 gtk_widget_show_all(vbox
);
646 expldif_dlg
.labelOutBook
= labelBook
;
647 expldif_dlg
.labelOutFile
= labelFile
;
651 * Create main dialog decorations (excluding notebook pages).
653 static void export_ldif_dialog_create( void ) {
661 GtkWidget
*btnCancel
;
663 GtkWidget
*statusbar
;
665 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
666 gtk_widget_set_size_request(window
, EXPORTLDIF_WIDTH
, EXPORTLDIF_HEIGHT
);
667 gtk_container_set_border_width( GTK_CONTAINER(window
), 0 );
668 gtk_window_set_title( GTK_WINDOW(window
),
669 _("Export Address Book to LDIF File") );
670 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
671 gtk_window_set_modal(GTK_WINDOW(window
), TRUE
);
672 g_signal_connect(G_OBJECT(window
), "delete_event",
673 G_CALLBACK(export_ldif_delete_event
),
675 g_signal_connect(G_OBJECT(window
), "key_press_event",
676 G_CALLBACK(export_ldif_key_pressed
),
679 vbox
= gtk_vbox_new(FALSE
, 4);
680 gtk_widget_show(vbox
);
681 gtk_container_add(GTK_CONTAINER(window
), vbox
);
683 vnbox
= gtk_vbox_new(FALSE
, 4);
684 gtk_container_set_border_width(GTK_CONTAINER(vnbox
), 4);
685 gtk_widget_show(vnbox
);
686 gtk_box_pack_start(GTK_BOX(vbox
), vnbox
, TRUE
, TRUE
, 0);
689 notebook
= gtk_notebook_new();
690 gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook
), FALSE
); /* Hide */
691 /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
692 gtk_widget_show(notebook
);
693 gtk_box_pack_start(GTK_BOX(vnbox
), notebook
, TRUE
, TRUE
, 0);
694 gtk_container_set_border_width(GTK_CONTAINER(notebook
), 6);
697 hsbox
= gtk_hbox_new(FALSE
, 0);
698 gtk_box_pack_end(GTK_BOX(vbox
), hsbox
, FALSE
, FALSE
, BORDER_WIDTH
);
699 statusbar
= gtk_statusbar_new();
700 gtk_box_pack_start(GTK_BOX(hsbox
), statusbar
, TRUE
, TRUE
, BORDER_WIDTH
);
703 gtkut_stock_button_set_create(&hbbox
, &btnPrev
, GTK_STOCK_GO_BACK
,
704 &btnNext
, GTK_STOCK_GO_FORWARD
,
705 &btnCancel
, GTK_STOCK_CANCEL
);
706 gtk_box_pack_end(GTK_BOX(vbox
), hbbox
, FALSE
, FALSE
, 0);
707 gtk_container_set_border_width(GTK_CONTAINER(hbbox
), 2);
708 gtk_widget_grab_default(btnNext
);
710 /* Button handlers */
711 g_signal_connect(G_OBJECT(btnPrev
), "clicked",
712 G_CALLBACK(export_ldif_prev
), NULL
);
713 g_signal_connect(G_OBJECT(btnNext
), "clicked",
714 G_CALLBACK(export_ldif_next
), NULL
);
715 g_signal_connect(G_OBJECT(btnCancel
), "clicked",
716 G_CALLBACK(export_ldif_cancel
), NULL
);
718 gtk_widget_show_all(vbox
);
720 expldif_dlg
.window
= window
;
721 expldif_dlg
.notebook
= notebook
;
722 expldif_dlg
.btnPrev
= btnPrev
;
723 expldif_dlg
.btnNext
= btnNext
;
724 expldif_dlg
.btnCancel
= btnCancel
;
725 expldif_dlg
.statusbar
= statusbar
;
726 expldif_dlg
.status_cid
= gtk_statusbar_get_context_id(
727 GTK_STATUSBAR(statusbar
), "Export LDIF Dialog" );
731 * Create export LDIF dialog.
733 static void export_ldif_create( void ) {
734 export_ldif_dialog_create();
735 export_ldif_page_file( PAGE_FILE_INFO
, _( "File Info" ) );
736 export_ldif_page_dn( PAGE_DN
, _( "Distguished Name" ) );
737 export_ldif_page_finish( PAGE_FINISH
, _( "Finish" ) );
738 gtk_widget_show_all( expldif_dlg
.window
);
742 * Populate fields from control data.
743 * \param ctl Export control data.
745 static void export_ldif_fill_fields( ExportLdifCtl
*ctl
) {
746 gtk_entry_set_text( GTK_ENTRY(expldif_dlg
.entryLdif
), "" );
748 gtk_entry_set_text( GTK_ENTRY(expldif_dlg
.entryLdif
),
751 gtk_entry_set_text( GTK_ENTRY(expldif_dlg
.entrySuffix
), "" );
753 gtk_entry_set_text( GTK_ENTRY(expldif_dlg
.entrySuffix
),
757 gtk_option_menu_set_history(
758 GTK_OPTION_MENU( expldif_dlg
.optmenuRDN
), ctl
->rdnIndex
);
759 gtk_toggle_button_set_active(
760 GTK_TOGGLE_BUTTON( expldif_dlg
.checkUseDN
), ctl
->useDN
);
761 gtk_toggle_button_set_active(
762 GTK_TOGGLE_BUTTON( expldif_dlg
.checkEMail
), ctl
->excludeEMail
);
766 * Process export address dialog.
767 * \param cache Address book/data source cache.
769 void addressbook_exp_ldif( AddressCache
*cache
) {
770 /* Set references to control data */
771 _addressCache_
= cache
;
773 _exportCtl_
= exportldif_create();
774 exportldif_load_settings( _exportCtl_
);
777 if( ! expldif_dlg
.window
)
778 export_ldif_create();
780 gtk_button_set_label(GTK_BUTTON(expldif_dlg
.btnCancel
),
782 expldif_dlg
.cancelled
= FALSE
;
783 gtk_widget_show(expldif_dlg
.window
);
784 manage_window_set_transient(GTK_WINDOW(expldif_dlg
.window
));
786 gtk_label_set_text( GTK_LABEL(expldif_dlg
.labelBook
), cache
->name
);
787 gtk_label_set_text( GTK_LABEL(expldif_dlg
.labelOutBook
), cache
->name
);
788 export_ldif_fill_fields( _exportCtl_
);
790 gtk_widget_grab_default(expldif_dlg
.btnNext
);
791 gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg
.notebook
), PAGE_FILE_INFO
);
792 gtk_widget_set_sensitive( expldif_dlg
.btnPrev
, FALSE
);
793 gtk_widget_set_sensitive( expldif_dlg
.btnNext
, TRUE
);
795 export_ldif_message();
796 gtk_widget_grab_focus(expldif_dlg
.entryLdif
);
799 gtk_widget_hide(expldif_dlg
.window
);
800 exportldif_free( _exportCtl_
);
803 _addressCache_
= NULL
;
807 * ============================================================================
809 * ============================================================================