Fix bug #3559 more correctly
[claws.git] / src / exphtmldlg.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002-2014 Match Grun and the Claws Mail team
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 /*
21  * Export address book to HTML file.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #include "claws-features.h"
27 #endif
28
29 #include "defs.h"
30
31 #include <glib.h>
32 #include <glib/gi18n.h>
33 #include <gdk/gdkkeysyms.h>
34 #include <gtk/gtk.h>
35
36 #include "gtkutils.h"
37 #include "prefs_common.h"
38 #include "alertpanel.h"
39 #include "mgutils.h"
40 #include "addrcache.h"
41 #include "addressitem.h"
42 #include "exporthtml.h"
43 #include "utils.h"
44 #include "manage_window.h"
45 #include "filesel.h"
46 #include "combobox.h"
47
48 #define PAGE_FILE_INFO             0
49 #define PAGE_FORMAT                1
50 #define PAGE_FINISH                2
51
52 /**
53  * Dialog object.
54  */
55 static struct _ExpHtml_Dlg {
56         GtkWidget *window;
57         GtkWidget *notebook;
58         GtkWidget *labelBook;
59         GtkWidget *entryHtml;
60         GtkWidget *optmenuCSS;
61         GtkWidget *optmenuName;
62         GtkWidget *checkBanding;
63         GtkWidget *checkLinkEMail;
64         GtkWidget *checkAttributes;
65         GtkWidget *labelOutBook;
66         GtkWidget *labelOutFile;
67         GtkWidget *btnPrev;
68         GtkWidget *btnNext;
69         GtkWidget *btnCancel;
70         GtkWidget *statusbar;
71         gint      status_cid;
72         gboolean  cancelled;
73 } exphtml_dlg;
74
75 static struct _AddressFileSelection _exp_html_file_selector_;
76
77 static ExportHtmlCtl *_exportCtl_ = NULL;
78 static AddressCache *_addressCache_ = NULL;
79
80 /**
81  * Display message in status field.
82  * \param msg Message to display.
83  */
84 static void export_html_status_show( gchar *msg ) {
85         if( exphtml_dlg.statusbar != NULL ) {
86                 gtk_statusbar_pop(
87                         GTK_STATUSBAR(exphtml_dlg.statusbar),
88                         exphtml_dlg.status_cid );
89                 if( msg ) {
90                         gtk_statusbar_push(
91                                 GTK_STATUSBAR(exphtml_dlg.statusbar),
92                                 exphtml_dlg.status_cid, msg );
93                 }
94         }
95 }
96
97 /**
98  * Select and display status message appropriate for the page being displayed.
99  */
100 static void export_html_message( void ) {
101         gchar *sMsg = NULL;
102         gint pageNum;
103
104         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
105         if( pageNum == PAGE_FILE_INFO ) {
106                 sMsg = _( "Please specify output directory and file to create." );
107         }
108         else if( pageNum == PAGE_FORMAT ) {
109                 sMsg = _( "Select stylesheet and formatting." );
110         }
111         else if( pageNum == PAGE_FINISH ) {
112                 sMsg = _( "File exported successfully." );
113         }
114         export_html_status_show( sMsg );
115 }
116
117 /**
118  * Callback function to cancel HTML file selection dialog.
119  * \param widget Widget (button).
120  * \param data   User data.
121  */
122 static void export_html_cancel( GtkWidget *widget, gpointer data ) {
123         gint pageNum;
124
125         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
126         if( pageNum != PAGE_FINISH ) {
127                 exphtml_dlg.cancelled = TRUE;
128         }
129         gtk_main_quit();
130 }
131
132 /**
133  * Callback function to handle dialog close event.
134  * \param widget Widget (dialog).
135  * \param event  Event object.
136  * \param data   User data.
137  */
138 static gint export_html_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
139         export_html_cancel( widget, data );
140         return TRUE;
141 }
142
143 /**
144  * Callback function to respond to dialog key press events.
145  * \param widget Widget.
146  * \param event  Event object.
147  * \param data   User data.
148  */
149 static gboolean export_html_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
150         if (event && event->keyval == GDK_KEY_Escape) {
151                 export_html_cancel( widget, data );
152         }
153         return FALSE;
154 }
155
156 /**
157  * Test whether we can move off file page.
158  * \return <i>TRUE</i> if OK to move off page.
159  */
160 static gboolean exp_html_move_file( void ) {
161         gchar *sFile, *msg, *reason;
162         AlertValue aval;
163
164         sFile = gtk_editable_get_chars( GTK_EDITABLE(exphtml_dlg.entryHtml), 0, -1 );
165         g_strchug( sFile ); g_strchomp( sFile );
166         gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), sFile );
167         exporthtml_parse_filespec( _exportCtl_, sFile );
168         g_free( sFile );
169
170         /* Test for directory */
171         if( g_file_test(_exportCtl_->dirOutput,
172                                 G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) {
173                 return TRUE;
174         }
175
176         /* Prompt to create */
177         msg = g_strdup_printf( _(
178                 "The HTML output directory '%s'\n" \
179                 "does not exist. Do you want to create it?" ),
180                 _exportCtl_->dirOutput );
181         aval = alertpanel( _("Create directory" ),
182                 msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
183         g_free( msg );
184         if( aval != G_ALERTALTERNATE ) return FALSE;
185
186         /* Create directory */
187         if( ! exporthtml_create_dir( _exportCtl_ ) ) {
188                 reason = exporthtml_get_create_msg( _exportCtl_ );
189                 msg = g_strdup_printf( _(
190                         "Could not create output directory for HTML file:\n%s" ),
191                         reason );
192                 aval = alertpanel_full(_("Failed to Create Directory"), msg,
193                                        GTK_STOCK_CLOSE, NULL, NULL, FALSE,
194                                        NULL, ALERT_ERROR, G_ALERTDEFAULT);
195                 g_free( msg );
196                 return FALSE;
197         }
198
199         return TRUE;
200 }
201
202 /**
203  * Test whether we can move off format page.
204  * \return <i>TRUE</i> if OK to move off page.
205  */
206 static gboolean exp_html_move_format( void ) {
207         gboolean retVal = FALSE;
208         gint id;
209
210         /* Set stylesheet */
211         id = combobox_get_active_data(GTK_COMBO_BOX(exphtml_dlg.optmenuCSS));
212         exporthtml_set_stylesheet( _exportCtl_, id );
213
214         /* Set name format */
215         id = combobox_get_active_data(GTK_COMBO_BOX(exphtml_dlg.optmenuName));
216         exporthtml_set_name_format( _exportCtl_, id );
217
218         exporthtml_set_banding( _exportCtl_,
219                 gtk_toggle_button_get_active(
220                         GTK_TOGGLE_BUTTON( exphtml_dlg.checkBanding ) ) );
221         exporthtml_set_link_email( _exportCtl_,
222                 gtk_toggle_button_get_active(
223                         GTK_TOGGLE_BUTTON( exphtml_dlg.checkLinkEMail ) ) );
224         exporthtml_set_attributes( _exportCtl_,
225                 gtk_toggle_button_get_active(
226                         GTK_TOGGLE_BUTTON( exphtml_dlg.checkAttributes ) ) );
227
228         /* Process export */
229         exporthtml_process( _exportCtl_, _addressCache_ );
230         if( _exportCtl_->retVal == MGU_SUCCESS ) {
231                 retVal = TRUE;
232         }
233         else {
234                 export_html_status_show( _( "Error creating HTML file" ) );
235         }
236         return retVal;
237 }
238
239 /**
240  * Display finish page.
241  */
242 static void exp_html_finish_show( void ) {
243         gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelOutFile), _exportCtl_->path );
244         gtk_widget_set_sensitive( exphtml_dlg.btnNext, FALSE );
245         gtk_widget_grab_focus( exphtml_dlg.btnCancel );
246 }
247
248 /**
249  * Callback function to select previous page.
250  * \param widget Widget (button).
251  */
252 static void export_html_prev( GtkWidget *widget ) {
253         gint pageNum;
254
255         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
256         if( pageNum == PAGE_FORMAT ) {
257                 /* Goto file page stuff */
258                 gtk_notebook_set_current_page(
259                         GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FILE_INFO );
260                 gtk_widget_set_sensitive( exphtml_dlg.btnPrev, FALSE );
261         }
262         else if( pageNum == PAGE_FINISH ) {
263                 /* Goto format page */
264                 gtk_notebook_set_current_page(
265                         GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FORMAT );
266                 gtk_widget_set_sensitive( exphtml_dlg.btnNext, TRUE );
267         }
268         export_html_message();
269 }
270
271 /**
272  * Callback function to select previous page.
273  * \param widget Widget (button).
274  */
275 static void export_html_next( GtkWidget *widget ) {
276         gint pageNum;
277
278         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
279         if( pageNum == PAGE_FILE_INFO ) {
280                 /* Goto format page */
281                 if( exp_html_move_file() ) {
282                         gtk_notebook_set_current_page(
283                                 GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FORMAT );
284                         gtk_widget_set_sensitive( exphtml_dlg.btnPrev, TRUE );
285                 }
286                 export_html_message();
287         }
288         else if( pageNum == PAGE_FORMAT ) {
289                 /* Goto finish page */
290                 if( exp_html_move_format() ) {
291                         gtk_notebook_set_current_page(
292                                 GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FINISH );
293                         gtk_button_set_label(GTK_BUTTON(exphtml_dlg.btnCancel),
294                                 GTK_STOCK_CLOSE);
295                         exp_html_finish_show();
296                         exporthtml_save_settings( _exportCtl_ );
297                         export_html_message();
298                 }
299         }
300 }
301
302 /**
303  * Open file with web browser.
304  * \param widget Widget (button).
305  * \param data   User data.
306  */
307 static void export_html_browse( GtkWidget *widget, gpointer data ) {
308         gchar *uri;
309
310         uri = g_filename_to_uri(_exportCtl_->path, NULL, NULL);
311         open_uri( uri, prefs_common_get_uri_cmd() );
312         g_free( uri );
313 }
314
315 /**
316  * Create HTML file selection dialog.
317  * \param afs Address file selection data.
318  */
319 static void exp_html_file_select_create( AddressFileSelection *afs ) {
320         gchar *file = filesel_select_file_save(_("Select HTML output file"), NULL);
321         
322         if (file == NULL)
323                 afs->cancelled = TRUE;
324         else {
325                 afs->cancelled = FALSE;
326                 gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), file );
327                 g_free(file);
328         }
329 }
330
331 /**
332  * Callback function to display HTML file selection dialog.
333  */
334 static void exp_html_file_select( void ) {
335         exp_html_file_select_create( & _exp_html_file_selector_ );
336 }
337
338 /**
339  * Format notebook file specification page.
340  * \param pageNum Page (tab) number.
341  * \param pageLbl Page (tab) label.
342  */
343 static void export_html_page_file( gint pageNum, gchar *pageLbl ) {
344         GtkWidget *vbox;
345         GtkWidget *table;
346         GtkWidget *label;
347         GtkWidget *labelBook;
348         GtkWidget *entryHtml;
349         GtkWidget *btnFile;
350         gint top;
351
352         vbox = gtk_vbox_new(FALSE, 8);
353         gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
354         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
355
356         label = gtk_label_new( pageLbl );
357         gtk_widget_show( label );
358         gtk_notebook_set_tab_label(
359                 GTK_NOTEBOOK( exphtml_dlg.notebook ),
360                 gtk_notebook_get_nth_page(
361                         GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ),
362                 label );
363
364         table = gtk_table_new( 3, 3, FALSE );
365         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
366         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
367         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
368         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
369
370         /* First row */
371         top = 0;
372         label = gtk_label_new( _( "Address Book" ) );
373         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
374                 GTK_FILL, 0, 0, 0);
375         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
376
377         labelBook = gtk_label_new( "Address book name goes here" );
378         gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
379                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
380         gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
381
382         /* Second row */
383         top++;
384         label = gtk_label_new( _( "HTML Output File" ) );
385         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
386                 GTK_FILL, 0, 0, 0);
387         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
388
389         entryHtml = gtk_entry_new();
390         gtk_table_attach(GTK_TABLE(table), entryHtml, 1, 2, top, (top + 1),
391                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
392
393         btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
394         gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
395                 GTK_FILL, 0, 3, 0);
396
397         gtk_widget_show_all(vbox);
398
399         /* Button handler */
400         g_signal_connect(G_OBJECT(btnFile), "clicked",
401                          G_CALLBACK(exp_html_file_select), NULL);
402
403         exphtml_dlg.labelBook = labelBook;
404         exphtml_dlg.entryHtml = entryHtml;
405 }
406
407 /**
408  * Format notebook format page.
409  * \param pageNum Page (tab) number.
410  * \param pageLbl Page (tab) label.
411  */
412 static void export_html_page_format( gint pageNum, gchar *pageLbl ) {
413         GtkWidget *vbox;
414         GtkWidget *table;
415         GtkWidget *label;
416         GtkWidget *optmenuCSS;
417         GtkWidget *optmenuName;
418         GtkListStore *menu;
419         GtkTreeIter iter;
420         GtkWidget *checkBanding;
421         GtkWidget *checkLinkEMail;
422         GtkWidget *checkAttributes;
423
424         gint top;
425
426         vbox = gtk_vbox_new(FALSE, 8);
427         gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
428         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
429
430         label = gtk_label_new( pageLbl );
431         gtk_widget_show( label );
432         gtk_notebook_set_tab_label(
433                 GTK_NOTEBOOK( exphtml_dlg.notebook ),
434                 gtk_notebook_get_nth_page(
435                         GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ),
436                 label );
437
438         table = gtk_table_new( 5, 3, FALSE );
439         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
440         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
441         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
442         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
443
444         /* First row */
445         top = 0;
446         label = gtk_label_new( _( "Stylesheet" ) );
447         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
448                 GTK_FILL, 0, 0, 0);
449         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
450
451         optmenuCSS = gtkut_sc_combobox_create(NULL, TRUE);
452         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuCSS)));
453
454         COMBOBOX_ADD(menu, _("None"), EXPORT_HTML_ID_NONE);
455         COMBOBOX_ADD(menu, _("Default"), EXPORT_HTML_ID_DEFAULT);
456         COMBOBOX_ADD(menu, _("Full"), EXPORT_HTML_ID_FULL);
457         COMBOBOX_ADD(menu, _("Custom"), EXPORT_HTML_ID_CUSTOM);
458         COMBOBOX_ADD(menu, _("Custom-2"), EXPORT_HTML_ID_CUSTOM2);
459         COMBOBOX_ADD(menu, _("Custom-3"), EXPORT_HTML_ID_CUSTOM3);
460         COMBOBOX_ADD(menu, _("Custom-4"), EXPORT_HTML_ID_CUSTOM4);
461
462         gtk_table_attach(GTK_TABLE(table), optmenuCSS, 1, 2, top, (top + 1),
463                 GTK_FILL, 0, 0, 0);
464
465         /* Second row */
466         top++;
467         label = gtk_label_new( _( "Full Name Format" ) );
468         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
469                 GTK_FILL, 0, 0, 0);
470         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
471
472         optmenuName = gtkut_sc_combobox_create(NULL, TRUE);
473         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuName)));
474
475         COMBOBOX_ADD(menu, _("First Name, Last Name"), EXPORT_HTML_FIRST_LAST);
476         COMBOBOX_ADD(menu, _("Last Name, First Name"), EXPORT_HTML_LAST_FIRST);
477
478         gtk_table_attach(GTK_TABLE(table), optmenuName, 1, 2, top, (top + 1),
479                 GTK_FILL, 0, 0, 0);
480
481         /* Third row */
482         top++;
483         checkBanding = gtk_check_button_new_with_label( _( "Color Banding" ) );
484         gtk_table_attach(GTK_TABLE(table), checkBanding, 1, 2, top, (top + 1),
485                 GTK_FILL, 0, 0, 0);
486
487         /* Fourth row */
488         top++;
489         checkLinkEMail = gtk_check_button_new_with_label( _( "Format Email Links" ) );
490         gtk_table_attach(GTK_TABLE(table), checkLinkEMail, 1, 2, top, (top + 1),
491                 GTK_FILL, 0, 0, 0);
492
493         /* Fifth row */
494         top++;
495         checkAttributes = gtk_check_button_new_with_label( _( "Format User Attributes" ) );
496         gtk_table_attach(GTK_TABLE(table), checkAttributes, 1, 2, top, (top + 1),
497                 GTK_FILL, 0, 0, 0);
498
499         gtk_widget_show_all(vbox);
500
501         exphtml_dlg.optmenuCSS      = optmenuCSS;
502         exphtml_dlg.optmenuName     = optmenuName;
503         exphtml_dlg.checkBanding    = checkBanding;
504         exphtml_dlg.checkLinkEMail  = checkLinkEMail;
505         exphtml_dlg.checkAttributes = checkAttributes;
506 }
507
508 /**
509  * Format notebook finish page.
510  * \param pageNum Page (tab) number.
511  * \param pageLbl Page (tab) label.
512  */
513 static void export_html_page_finish( gint pageNum, gchar *pageLbl ) {
514         GtkWidget *vbox;
515         GtkWidget *table;
516         GtkWidget *label;
517         GtkWidget *labelBook;
518         GtkWidget *labelFile;
519         GtkWidget *btnBrowse;
520         gint top;
521
522         vbox = gtk_vbox_new(FALSE, 8);
523         gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
524         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
525
526         label = gtk_label_new( pageLbl );
527         gtk_widget_show( label );
528         gtk_notebook_set_tab_label(
529                 GTK_NOTEBOOK( exphtml_dlg.notebook ),
530                 gtk_notebook_get_nth_page( GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ), label );
531
532         table = gtk_table_new( 3, 3, FALSE );
533         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
534         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
535         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
536         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
537
538         /* First row */
539         top = 0;
540         label = gtk_label_new( _( "Address Book :" ) );
541         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
542         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
543
544         labelBook = gtk_label_new("Full name of address book goes here");
545         gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
546         gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
547
548         /* Second row */
549         top++;
550         label = gtk_label_new( _( "File Name :" ) );
551         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
552         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
553
554         labelFile = gtk_label_new("File name goes here");
555         gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
556         gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
557
558         /* Third row */
559         top++;
560         btnBrowse = gtk_button_new_with_label( _( "Open with Web Browser" ) );
561         gtk_table_attach(GTK_TABLE(table), btnBrowse, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
562
563         gtk_widget_show_all(vbox);
564
565         /* Button handlers */
566         g_signal_connect(G_OBJECT(btnBrowse), "clicked",
567                          G_CALLBACK(export_html_browse), NULL);
568
569         exphtml_dlg.labelOutBook = labelBook;
570         exphtml_dlg.labelOutFile = labelFile;
571 }
572
573 /**
574  * Create main dialog decorations (excluding notebook pages).
575  */
576 static void export_html_dialog_create( void ) {
577         GtkWidget *window;
578         GtkWidget *vbox;
579         GtkWidget *vnbox;
580         GtkWidget *notebook;
581         GtkWidget *hbbox;
582         GtkWidget *btnPrev;
583         GtkWidget *btnNext;
584         GtkWidget *btnCancel;
585         GtkWidget *hsbox;
586         GtkWidget *statusbar;
587
588         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "exphtmldlg");
589         gtk_widget_set_size_request(window, -1, -1 );
590         gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
591         gtk_window_set_title( GTK_WINDOW(window),
592                 _("Export Address Book to HTML File") );
593         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
594         g_signal_connect(G_OBJECT(window), "delete_event",
595                          G_CALLBACK(export_html_delete_event),
596                          NULL );
597         g_signal_connect(G_OBJECT(window), "key_press_event",
598                          G_CALLBACK(export_html_key_pressed),
599                          NULL );
600
601         vbox = gtk_vbox_new(FALSE, 4);
602         gtk_widget_show(vbox);
603         gtk_container_add(GTK_CONTAINER(window), vbox);
604
605         vnbox = gtk_vbox_new(FALSE, 4);
606         gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
607         gtk_widget_show(vnbox);
608         gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
609
610         /* Notebook */
611         notebook = gtk_notebook_new();
612         gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
613         /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
614         gtk_widget_show(notebook);
615         gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
616         gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
617
618         /* Status line */
619         hsbox = gtk_hbox_new(FALSE, 0);
620         gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
621         statusbar = gtk_statusbar_new();
622         gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
623
624         /* Button panel */
625         gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
626                                       &btnNext, GTK_STOCK_GO_FORWARD,
627                                       &btnCancel, GTK_STOCK_CANCEL);
628         gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
629         gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
630         gtk_widget_grab_default(btnNext);
631
632         /* Button handlers */
633         g_signal_connect(G_OBJECT(btnPrev), "clicked",
634                          G_CALLBACK(export_html_prev), NULL);
635         g_signal_connect(G_OBJECT(btnNext), "clicked",
636                          G_CALLBACK(export_html_next), NULL);
637         g_signal_connect(G_OBJECT(btnCancel), "clicked",
638                          G_CALLBACK(export_html_cancel), NULL);
639
640         gtk_widget_show_all(vbox);
641
642         exphtml_dlg.window     = window;
643         exphtml_dlg.notebook   = notebook;
644         exphtml_dlg.btnPrev    = btnPrev;
645         exphtml_dlg.btnNext    = btnNext;
646         exphtml_dlg.btnCancel  = btnCancel;
647         exphtml_dlg.statusbar  = statusbar;
648         exphtml_dlg.status_cid = gtk_statusbar_get_context_id(
649                         GTK_STATUSBAR(statusbar), "Export HTML Dialog" );
650 }
651
652 /**
653  * Create export HTML dialog.
654  */
655 static void export_html_create( void ) {
656         export_html_dialog_create();
657         export_html_page_file( PAGE_FILE_INFO, _( "File Info" ) );
658         export_html_page_format( PAGE_FORMAT, _( "Format" ) );
659         export_html_page_finish( PAGE_FINISH, _( "Finish" ) );
660         gtk_widget_show_all( exphtml_dlg.window );
661 }
662
663 /**
664  * Populate fields from control data.
665  * \param ctl Export control data.
666  */
667 static void export_html_fill_fields( ExportHtmlCtl *ctl ) {
668         gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), "" );
669         if( ctl->path ) {
670                 gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml),
671                         ctl->path );
672         }
673
674         combobox_select_by_data(
675                         GTK_COMBO_BOX(exphtml_dlg.optmenuCSS), ctl->stylesheet );
676         combobox_select_by_data(
677                         GTK_COMBO_BOX(exphtml_dlg.optmenuName), ctl->nameFormat );
678         gtk_toggle_button_set_active(
679                 GTK_TOGGLE_BUTTON( exphtml_dlg.checkBanding ), ctl->banding );
680         gtk_toggle_button_set_active(
681                 GTK_TOGGLE_BUTTON( exphtml_dlg.checkLinkEMail ), ctl->linkEMail );
682         gtk_toggle_button_set_active(
683                 GTK_TOGGLE_BUTTON( exphtml_dlg.checkAttributes ), ctl->showAttribs );
684 }
685
686 /**
687  * Process export address dialog.
688  * \param cache Address book/data source cache.
689  */
690 void addressbook_exp_html( AddressCache *cache ) {
691         /* Set references to control data */
692         _addressCache_ = cache;
693
694         _exportCtl_ = exporthtml_create();
695         exporthtml_load_settings( _exportCtl_ );
696
697         /* Setup GUI */
698         if( ! exphtml_dlg.window )
699                 export_html_create();
700
701         gtk_button_set_label(GTK_BUTTON(exphtml_dlg.btnCancel),
702                              GTK_STOCK_CANCEL);
703         exphtml_dlg.cancelled = FALSE;
704         gtk_widget_show(exphtml_dlg.window);
705         manage_window_set_transient(GTK_WINDOW(exphtml_dlg.window));
706         gtk_window_set_modal(GTK_WINDOW(exphtml_dlg.window), TRUE);
707         gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelBook), cache->name );
708         gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelOutBook), cache->name );
709         export_html_fill_fields( _exportCtl_ );
710
711         gtk_widget_grab_default(exphtml_dlg.btnNext);
712         gtk_notebook_set_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FILE_INFO );
713         gtk_widget_set_sensitive( exphtml_dlg.btnPrev, FALSE );
714         gtk_widget_set_sensitive( exphtml_dlg.btnNext, TRUE );
715
716         export_html_message();
717         gtk_widget_grab_focus(exphtml_dlg.entryHtml);
718
719         gtk_main();
720         gtk_widget_hide(exphtml_dlg.window);
721         gtk_window_set_modal(GTK_WINDOW(exphtml_dlg.window), FALSE);
722         exporthtml_free( _exportCtl_ );
723         _exportCtl_ = NULL;
724
725         _addressCache_ = NULL;
726 }
727
728 /*
729  * ============================================================================
730  * End of Source.
731  * ============================================================================
732  */
733