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