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