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