New method for OAuth2 authentication and receiving of access token from David Fletche...
[claws.git] / src / expldifdlg.c
1 /*
2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2022 the Claws Mail team and Match Grun
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 /*
20  * Export address book to LDIF file.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #include "claws-features.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtk.h>
34
35 #include "gtkutils.h"
36 #include "prefs_common.h"
37 #include "alertpanel.h"
38 #include "mgutils.h"
39 #include "addrcache.h"
40 #include "addressitem.h"
41 #include "exportldif.h"
42 #include "utils.h"
43 #include "manage_window.h"
44 #include "filesel.h"
45 #include "combobox.h"
46
47 #define PAGE_FILE_INFO             0
48 #define PAGE_DN                    1
49 #define PAGE_FINISH                2
50
51 #define EXPORTLDIF_WIDTH           480
52 #define EXPORTLDIF_HEIGHT          -1
53
54 /**
55  * Dialog object.
56  */
57 static struct _ExpLdif_Dlg {
58         GtkWidget *window;
59         GtkWidget *notebook;
60         GtkWidget *labelBook;
61         GtkWidget *entryLdif;
62         GtkWidget *entrySuffix;
63         GtkWidget *optmenuRDN;
64         GtkWidget *checkUseDN;
65         GtkWidget *checkEMail;
66         GtkWidget *labelOutBook;
67         GtkWidget *labelOutFile;
68         GtkWidget *btnPrev;
69         GtkWidget *btnNext;
70         GtkWidget *btnCancel;
71         GtkWidget *statusbar;
72         gint      status_cid;
73         gboolean  cancelled;
74 } expldif_dlg;
75
76 static struct _AddressFileSelection _exp_ldif_file_selector_;
77
78 static ExportLdifCtl *_exportCtl_ = NULL;
79 static AddressCache *_addressCache_ = NULL;
80
81 /**
82  * Display message in status field.
83  * \param msg Message to display.
84  */
85 static void export_ldif_status_show( gchar *msg ) {
86         if( expldif_dlg.statusbar != NULL ) {
87                 gtk_statusbar_pop(
88                         GTK_STATUSBAR(expldif_dlg.statusbar),
89                         expldif_dlg.status_cid );
90                 if( msg ) {
91                         gtk_statusbar_push(
92                                 GTK_STATUSBAR(expldif_dlg.statusbar),
93                                 expldif_dlg.status_cid, msg );
94                 }
95         }
96 }
97
98 /**
99  * Select and display status message appropriate for the page being displayed.
100  */
101 static void export_ldif_message( void ) {
102         gchar *sMsg = NULL;
103         gint pageNum;
104
105         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
106         if( pageNum == PAGE_FILE_INFO ) {
107                 sMsg = _( "Please specify output directory and LDIF filename to create." );
108         }
109         else if( pageNum == PAGE_DN ) {
110                 sMsg = _( "Specify parameters to format distinguished name." );
111         }
112         else if( pageNum == PAGE_FINISH ) {
113                 sMsg = _( "File exported successfully." );
114         }
115         export_ldif_status_show( sMsg );
116 }
117
118 /**
119  * Callback function to cancel LDIF file selection dialog.
120  * \param widget Widget (button).
121  * \param data   User data.
122  */
123 static void export_ldif_cancel( GtkWidget *widget, gpointer data ) {
124         gint pageNum;
125
126         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
127         if( pageNum != PAGE_FINISH ) {
128                 expldif_dlg.cancelled = TRUE;
129         }
130         gtk_main_quit();
131 }
132
133 /**
134  * Callback function to handle dialog close event.
135  * \param widget Widget (dialog).
136  * \param event  Event object.
137  * \param data   User data.
138  */
139 static gint export_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
140         export_ldif_cancel( widget, data );
141         return TRUE;
142 }
143
144 /**
145  * Callback function to respond to dialog key press events.
146  * \param widget Widget.
147  * \param event  Event object.
148  * \param data   User data.
149  */
150 static gboolean export_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
151         if (event && event->keyval == GDK_KEY_Escape) {
152                 export_ldif_cancel( widget, data );
153         }
154         return FALSE;
155 }
156
157 /**
158  * Test whether we can move off file page.
159  * \return <i>TRUE</i> if OK to move off page.
160  */
161 static gboolean exp_ldif_move_file( void ) {
162         gchar *sFile, *msg, *reason;
163         gboolean errFlag = FALSE;
164         AlertValue aval;
165
166         sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 );
167         g_strstrip( sFile );
168         gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile );
169         exportldif_parse_filespec( _exportCtl_, sFile );
170
171         /* Test that something was supplied */
172         if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
173                 gtk_widget_grab_focus( expldif_dlg.entryLdif );
174                 errFlag = TRUE;
175         }
176         g_free( sFile );
177         if( errFlag ) return FALSE;
178
179         /* Test for directory */
180         if( g_file_test(_exportCtl_->dirOutput,
181                                 G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) {
182                 return TRUE;
183         }
184
185         /* Prompt to create */
186         msg = g_strdup_printf( _(
187                 "LDIF Output Directory '%s'\n" \
188                 "does not exist. OK to create new directory?" ),
189                 _exportCtl_->dirOutput );
190         aval = alertpanel( _("Create Directory" ),
191                 msg, NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST );
192         g_free( msg );
193         if( aval != G_ALERTALTERNATE ) return FALSE;
194
195         /* Create directory */
196         if( ! exportldif_create_dir( _exportCtl_ ) ) {
197                 reason = exportldif_get_create_msg( _exportCtl_ );
198                 msg = g_strdup_printf( _(
199                         "Could not create output directory for LDIF file:\n%s" ),
200                         reason );
201                 aval = alertpanel_full(_("Failed to Create Directory"), msg,
202                                        NULL, _("Close"), NULL, NULL, NULL, NULL,
203                                        ALERTFOCUS_FIRST, FALSE, NULL, ALERT_ERROR);
204                 g_free( msg );
205                 return FALSE;
206         }
207
208         return TRUE;
209 }
210
211 /**
212  * Test whether we can move off distinguished name page.
213  * \return <i>TRUE</i> if OK to move off page.
214  */
215 static gboolean exp_ldif_move_dn( void ) {
216         gboolean retVal = FALSE;
217         gboolean errFlag = FALSE;
218         gchar *suffix;
219         gint id;
220
221         /* Set suffix */
222         suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 );
223         g_strstrip( suffix );
224
225         /* Set RDN format */
226         id = combobox_get_active_data(GTK_COMBO_BOX(expldif_dlg.optmenuRDN));
227         exportldif_set_rdn( _exportCtl_, id );
228
229         exportldif_set_suffix( _exportCtl_, suffix );
230         exportldif_set_use_dn( _exportCtl_,
231                 gtk_toggle_button_get_active(
232                         GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) );
233         exportldif_set_exclude_email( _exportCtl_,
234                 gtk_toggle_button_get_active(
235                         GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) );
236
237         if( *suffix == '\0' || strlen( suffix ) < 1 ) {
238                 AlertValue aval;
239
240                 aval = alertpanel(
241                         _( "Suffix was not supplied" ),
242                         _(
243                                 "A suffix is required if data is to be used " \
244                                 "for an LDAP server. Are you sure you wish " \
245                                 "to proceed without a suffix?"
246                          ),
247                          NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST );
248                 if( aval != G_ALERTALTERNATE ) {
249                         gtk_widget_grab_focus( expldif_dlg.entrySuffix );
250                         errFlag = TRUE;
251                 }
252         }
253
254         if( ! errFlag ) {
255                 /* Process export */
256                 exportldif_process( _exportCtl_, _addressCache_ );
257                 if( _exportCtl_->retVal == MGU_SUCCESS ) {
258                         retVal = TRUE;
259                 }
260                 else {
261                         export_ldif_status_show( _( "Error creating LDIF file" ) );
262                 }
263         }
264
265         return retVal;
266 }
267
268 /**
269  * Display finish page.
270  */
271 static void exp_ldif_finish_show( void ) {
272         gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutFile), _exportCtl_->path );
273         gtk_widget_set_sensitive( expldif_dlg.btnNext, FALSE );
274         gtk_widget_grab_focus( expldif_dlg.btnCancel );
275 }
276
277 /**
278  * Callback function to select previous page.
279  * \param widget Widget (button).
280  */
281 static void export_ldif_prev( GtkWidget *widget ) {
282         gint pageNum;
283
284         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
285         if( pageNum == PAGE_DN ) {
286                 /* Goto file page stuff */
287                 gtk_notebook_set_current_page(
288                         GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
289                 gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
290         }
291         else if( pageNum == PAGE_FINISH ) {
292                 /* Goto format page */
293                 gtk_notebook_set_current_page(
294                         GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
295                 gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
296         }
297         export_ldif_message();
298 }
299
300 /**
301  * Callback function to select next page.
302  * \param widget Widget (button).
303  */
304 static void export_ldif_next( GtkWidget *widget ) {
305         gint pageNum;
306
307         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) );
308         if( pageNum == PAGE_FILE_INFO ) {
309                 /* Goto distinguished name page */
310                 if( exp_ldif_move_file() ) {
311                         gtk_notebook_set_current_page(
312                                 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN );
313                         gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE );
314                 }
315                 export_ldif_message();
316         }
317         else if( pageNum == PAGE_DN ) {
318                 /* Goto finish page */
319                 if( exp_ldif_move_dn() ) {
320                         gtk_notebook_set_current_page(
321                                 GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH );
322                         gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
323                                 _("_Close"));
324                         gtk_button_set_image(GTK_BUTTON(expldif_dlg.btnCancel),
325                                 gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_BUTTON));
326                         exp_ldif_finish_show();
327                         exportldif_save_settings( _exportCtl_ );
328                         export_ldif_message();
329                 }
330         }
331 }
332
333 /**
334  * Create LDIF file selection dialog.
335  * \param afs Address file selection data.
336  */
337 static void exp_ldif_file_select_create( AddressFileSelection *afs ) {
338         gchar *file = filesel_select_file_save(_("Select LDIF output file"), NULL);
339         
340         if (file == NULL)
341                 afs->cancelled = TRUE;
342         else {
343                 afs->cancelled = FALSE;
344                 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), file );
345                 g_free(file);
346         }
347 }
348
349 /**
350  * Callback function to display LDIF file selection dialog.
351  */
352 static void exp_ldif_file_select( void ) {
353         exp_ldif_file_select_create( & _exp_ldif_file_selector_ );
354 }
355
356 /**
357  * Format notebook file specification page.
358  * \param pageNum Page (tab) number.
359  * \param pageLbl Page (tab) label.
360  */
361 static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) {
362         GtkWidget *vbox;
363         GtkWidget *table;
364         GtkWidget *label;
365         GtkWidget *labelBook;
366         GtkWidget *entryLdif;
367         GtkWidget *btnFile;
368
369         vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
370         gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
371         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
372
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 ),
379                 label );
380
381         table = gtk_grid_new();
382         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
383         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
384         gtk_grid_set_row_spacing(GTK_GRID(table), 8);
385         gtk_grid_set_column_spacing(GTK_GRID(table), 8);
386
387         /* First row */
388         label = gtk_label_new( _( "Address Book" ) );
389         gtk_label_set_xalign(GTK_LABEL(label), 0.0);
390         gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
391
392         labelBook = gtk_label_new( "Address book name goes here" );
393         gtk_label_set_xalign(GTK_LABEL(labelBook), 0.0);
394         gtk_grid_attach(GTK_GRID(table), labelBook, 1, 0, 1, 1);
395
396         /* Second row */
397         label = gtk_label_new( _( "LDIF Output File" ) );
398         gtk_label_set_xalign(GTK_LABEL(label), 0.0);
399         gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
400
401         entryLdif = gtk_entry_new();
402         gtk_grid_attach(GTK_GRID(table), entryLdif, 1, 1, 1, 1);
403         gtk_widget_set_hexpand(entryLdif, TRUE);
404         gtk_widget_set_halign(entryLdif, GTK_ALIGN_FILL);
405
406         btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
407         gtk_grid_attach(GTK_GRID(table), btnFile, 2, 1, 1, 1);
408
409         gtk_widget_show_all(vbox);
410
411         /* Button handler */
412         g_signal_connect(G_OBJECT(btnFile), "clicked",
413                          G_CALLBACK(exp_ldif_file_select), NULL);
414
415         expldif_dlg.labelBook = labelBook;
416         expldif_dlg.entryLdif = entryLdif;
417 }
418
419 static void export_ldif_relative_dn_changed(GtkWidget *widget, gpointer data)
420 {
421         gint relativeDN = combobox_get_active_data(GTK_COMBO_BOX(widget));
422         GtkLabel *label = GTK_LABEL(data);
423
424         switch(relativeDN) {
425         case EXPORT_LDIF_ID_UID:
426                 gtk_label_set_text(label,
427                 _("The address book Unique ID is used to create a DN that is " \
428                 "formatted similar to:\n" \
429                 "  uid=102376,ou=people,dc=claws-mail,dc=org"));
430                 break;
431         case EXPORT_LDIF_ID_DNAME:
432                 gtk_label_set_text(label,
433                 _("The address book Display Name is used to create a DN that " \
434                 "is formatted similar to:\n" \
435                 "  cn=John Doe,ou=people,dc=claws-mail,dc=org"));       
436                 break;
437         case EXPORT_LDIF_ID_EMAIL:
438                 gtk_label_set_text(label, 
439                 _("The first Email Address belonging to a person is used to " \
440                 "create a DN that is formatted similar to:\n" \
441                 "  mail=john.doe@domain.com,ou=people,dc=claws-mail,dc=org"));  
442                 break;
443         }
444         
445 }
446
447 /**
448  * Format notebook distinguished name page.
449  * \param pageNum Page (tab) number.
450  * \param pageLbl Page (tab) label.
451  */
452 static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) {
453         GtkWidget *vbox;
454         GtkWidget *table;
455         GtkWidget *label;
456         GtkWidget *entrySuffix;
457         GtkWidget *optmenuRDN;
458         GtkWidget *labelRDN;
459         GtkWidget *checkUseDN;
460         GtkWidget *checkEMail;
461         GtkListStore *store;
462         GtkTreeIter iter;
463
464         vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
465         gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
466         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
467
468         label = gtk_label_new( pageLbl );
469         gtk_widget_show( label );
470         gtk_notebook_set_tab_label(
471                 GTK_NOTEBOOK( expldif_dlg.notebook ),
472                 gtk_notebook_get_nth_page(
473                         GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ),
474                 label );
475
476         table = gtk_grid_new();
477         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
478         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
479         gtk_grid_set_row_spacing(GTK_GRID(table), 8);
480         gtk_grid_set_column_spacing(GTK_GRID(table), 8);
481
482         /* First row */
483         label = gtk_label_new( _( "Suffix" ) );
484         gtk_label_set_xalign(GTK_LABEL(label), 0.0);
485         gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
486
487         entrySuffix = gtk_entry_new();
488         gtk_grid_attach(GTK_GRID(table), entrySuffix, 1, 0, 1, 1);
489         gtk_widget_set_hexpand(entrySuffix, TRUE);
490         gtk_widget_set_halign(entrySuffix, GTK_ALIGN_FILL);
491
492         CLAWS_SET_TIP(entrySuffix, _(
493                 "The suffix is used to create a \"Distinguished Name\" " \
494                 "(or DN) for an LDAP entry. Examples include:\n" \
495                 "  dc=claws-mail,dc=org\n" \
496                 "  ou=people,dc=domainname,dc=com\n" \
497                 "  o=Organization Name,c=Country\n"));
498
499         /* Second row */
500         label = gtk_label_new( _( "Relative DN" ) );
501         gtk_label_set_xalign(GTK_LABEL(label), 0.0);
502         gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
503
504         optmenuRDN = gtkut_sc_combobox_create(NULL, TRUE);
505         store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuRDN)));
506         
507         COMBOBOX_ADD(store, _("Unique ID"), EXPORT_LDIF_ID_UID);
508         COMBOBOX_ADD(store, _("Display Name"), EXPORT_LDIF_ID_DNAME);
509         COMBOBOX_ADD(store, _("Email Address"), EXPORT_LDIF_ID_EMAIL);
510
511         gtk_grid_attach(GTK_GRID(table), optmenuRDN, 1, 1, 1, 1);
512
513         CLAWS_SET_TIP(optmenuRDN, _(
514                 "The LDIF file contains several data records that " \
515                 "are usually loaded into an LDAP server. Each data " \
516                 "record in the LDIF file is uniquely identified by " \
517                 "a \"Distinguished Name\" (or DN). The suffix is " \
518                 "appended to the \"Relative Distinguished Name\" "\
519                 "(or RDN) to create the DN. Please select one of " \
520                 "the available RDN options that will be used to " \
521                 "create the DN."));
522         
523         /* Third row*/
524         labelRDN = gtk_label_new("");
525         gtk_label_set_line_wrap(GTK_LABEL(labelRDN), TRUE);
526         gtk_label_set_justify(GTK_LABEL(labelRDN), GTK_JUSTIFY_CENTER);
527         gtk_grid_attach(GTK_GRID(table), labelRDN, 0, 2, 1, 1);
528                 
529         /* Fourth row */
530         checkUseDN = gtk_check_button_new_with_label(
531                         _( "Use DN attribute if present in data" ) );
532         gtk_grid_attach(GTK_GRID(table), checkUseDN, 1, 3, 1, 1);
533
534         CLAWS_SET_TIP(checkUseDN, _(
535                 "The addressbook may contain entries that were " \
536                 "previously imported from an LDIF file. The " \
537                 "\"Distinguished Name\" (DN) user attribute, if " \
538                 "present in the address book data, may be used in " \
539                 "the exported LDIF file. The RDN selected above " \
540                 "will be used if the DN user attribute is not found."));
541
542         /* Fifth row */
543         checkEMail = gtk_check_button_new_with_label(
544                         _( "Exclude record if no Email Address" ) );
545         gtk_grid_attach(GTK_GRID(table), checkEMail, 1, 4, 1, 1);
546
547         CLAWS_SET_TIP(checkEMail, _(
548                 "An addressbook may contain entries without " \
549                 "Email Addresses. Check this option to ignore " \
550                 "these records."));
551
552
553         gtk_widget_show_all(vbox);
554
555         g_signal_connect(G_OBJECT(optmenuRDN), "changed",
556                 G_CALLBACK(export_ldif_relative_dn_changed), labelRDN);
557         gtk_combo_box_set_active(GTK_COMBO_BOX(optmenuRDN), 0);
558
559
560         expldif_dlg.entrySuffix = entrySuffix;
561         expldif_dlg.optmenuRDN  = optmenuRDN;
562         expldif_dlg.checkUseDN  = checkUseDN;
563         expldif_dlg.checkEMail  = checkEMail;
564 }
565
566 /**
567  * Format notebook finish page.
568  * \param pageNum Page (tab) number.
569  * \param pageLbl Page (tab) label.
570  */
571 static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
572         GtkWidget *vbox;
573         GtkWidget *table;
574         GtkWidget *label;
575         GtkWidget *labelBook;
576         GtkWidget *labelFile;
577
578         vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
579         gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox );
580         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
581
582         label = gtk_label_new( pageLbl );
583         gtk_widget_show( label );
584         gtk_notebook_set_tab_label(
585                 GTK_NOTEBOOK( expldif_dlg.notebook ),
586                 gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label );
587
588         table = gtk_grid_new();
589         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
590         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
591         gtk_grid_set_row_spacing(GTK_GRID(table), 8);
592         gtk_grid_set_column_spacing(GTK_GRID(table), 8);
593
594         /* First row */
595         label = gtk_label_new( _( "Address Book:" ) );
596         gtk_label_set_xalign(GTK_LABEL(label), 1.0);
597         gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
598
599         labelBook = gtk_label_new("Full name of address book goes here");
600         gtk_label_set_xalign(GTK_LABEL(labelBook), 0.0);
601         gtk_grid_attach(GTK_GRID(table), labelBook, 1, 0, 1, 1);
602
603         /* Second row */
604         label = gtk_label_new( _( "File Name:" ) );
605         gtk_label_set_xalign(GTK_LABEL(label), 1.0);
606         gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1);
607
608         labelFile = gtk_label_new("File name goes here");
609         gtk_label_set_xalign(GTK_LABEL(labelFile), 0.0);
610         gtk_grid_attach(GTK_GRID(table), labelFile, 1, 1, 1, 1);
611
612         gtk_widget_show_all(vbox);
613
614         expldif_dlg.labelOutBook = labelBook;
615         expldif_dlg.labelOutFile = labelFile;
616 }
617
618 /**
619  * Create main dialog decorations (excluding notebook pages).
620  */
621 static void export_ldif_dialog_create( void ) {
622         GtkWidget *window;
623         GtkWidget *vbox;
624         GtkWidget *vnbox;
625         GtkWidget *notebook;
626         GtkWidget *hbbox;
627         GtkWidget *btnPrev;
628         GtkWidget *btnNext;
629         GtkWidget *btnCancel;
630         GtkWidget *hsbox;
631         GtkWidget *statusbar;
632
633         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "expldifdlg");
634         gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT );
635         gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
636         gtk_window_set_title( GTK_WINDOW(window),
637                 _("Export Address Book to LDIF File") );
638         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
639         gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
640         g_signal_connect(G_OBJECT(window), "delete_event",
641                          G_CALLBACK(export_ldif_delete_event),
642                          NULL );
643         g_signal_connect(G_OBJECT(window), "key_press_event",
644                          G_CALLBACK(export_ldif_key_pressed),
645                          NULL );
646
647         vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
648         gtk_widget_show(vbox);
649         gtk_container_add(GTK_CONTAINER(window), vbox);
650
651         vnbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
652         gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
653         gtk_widget_show(vnbox);
654         gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
655
656         /* Notebook */
657         notebook = gtk_notebook_new();
658         gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
659         /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
660         gtk_widget_show(notebook);
661         gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
662         gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
663
664         /* Status line */
665         hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
666         gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
667         statusbar = gtk_statusbar_new();
668         gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
669
670         /* Button panel */
671         gtkut_stock_button_set_create(&hbbox, &btnPrev, "go-previous", _("_Previous"),
672                                       &btnNext, "go-next", _("_Next"),
673                                       &btnCancel, NULL, _("_Cancel"));
674         gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
675         gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
676         gtk_widget_grab_default(btnNext);
677
678         /* Button handlers */
679         g_signal_connect(G_OBJECT(btnPrev), "clicked",
680                          G_CALLBACK(export_ldif_prev), NULL);
681         g_signal_connect(G_OBJECT(btnNext), "clicked",
682                          G_CALLBACK(export_ldif_next), NULL);
683         g_signal_connect(G_OBJECT(btnCancel), "clicked",
684                          G_CALLBACK(export_ldif_cancel), NULL);
685
686         gtk_widget_show_all(vbox);
687
688         expldif_dlg.window     = window;
689         expldif_dlg.notebook   = notebook;
690         expldif_dlg.btnPrev    = btnPrev;
691         expldif_dlg.btnNext    = btnNext;
692         expldif_dlg.btnCancel  = btnCancel;
693         expldif_dlg.statusbar  = statusbar;
694         expldif_dlg.status_cid = gtk_statusbar_get_context_id(
695                         GTK_STATUSBAR(statusbar), "Export LDIF Dialog" );
696 }
697
698 /**
699  * Create export LDIF dialog.
700  */
701 static void export_ldif_create( void ) {
702         export_ldif_dialog_create();
703         export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
704         export_ldif_page_dn( PAGE_DN, _( "Distinguished Name" ) );
705         export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
706         gtk_widget_show_all( expldif_dlg.window );
707 }
708
709 /**
710  * Populate fields from control data.
711  * \param ctl   Export control data.
712  */
713 static void export_ldif_fill_fields( ExportLdifCtl *ctl ) {
714         gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" );
715         if( ctl->path ) {
716                 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif),
717                         ctl->path );
718         }
719         gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" );
720         if( ctl->suffix ) {
721                 gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix),
722                         ctl->suffix );
723         }
724
725         gtk_combo_box_set_active(
726                 GTK_COMBO_BOX( expldif_dlg.optmenuRDN ), ctl->rdnIndex );
727         gtk_toggle_button_set_active(
728                 GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN );
729         gtk_toggle_button_set_active(
730                 GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail );
731 }
732
733 /**
734  * Process export address dialog.
735  * \param cache Address book/data source cache.
736  */
737 void addressbook_exp_ldif( AddressCache *cache ) {
738         /* Set references to control data */
739         _addressCache_ = cache;
740
741         _exportCtl_ = exportldif_create();
742         exportldif_load_settings( _exportCtl_ );
743
744         /* Setup GUI */
745         if( ! expldif_dlg.window )
746                 export_ldif_create();
747
748         gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel),
749                              _("_Cancel"));
750         expldif_dlg.cancelled = FALSE;
751         gtk_widget_show(expldif_dlg.window);
752         manage_window_set_transient(GTK_WINDOW(expldif_dlg.window));
753         gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), TRUE);
754         gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name );
755         gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name );
756         export_ldif_fill_fields( _exportCtl_ );
757
758         gtk_widget_grab_default(expldif_dlg.btnNext);
759         gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO );
760         gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE );
761         gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE );
762
763         export_ldif_message();
764         gtk_widget_grab_focus(expldif_dlg.entryLdif);
765
766         gtk_main();
767         gtk_widget_hide(expldif_dlg.window);
768         gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), FALSE);
769         exportldif_free( _exportCtl_ );
770         _exportCtl_ = NULL;
771
772         _addressCache_ = NULL;
773 }
774
775 /*
776  * ============================================================================
777  * End of Source.
778  * ============================================================================
779  */
780