2005-08-31 [paul] 1.9.13cvs74
[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 <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
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_get_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_get_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, GTK_STOCK_YES, GTK_STOCK_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_full(_("Failed to Create Directory"), msg,
197                                        GTK_STOCK_CLOSE, NULL, NULL, FALSE,
198                                        NULL, ALERT_ERROR, G_ALERTDEFAULT);
199                 g_free( msg );
200                 return FALSE;
201         }
202
203         return TRUE;
204 }
205
206 /**
207  * Test whether we can move off format page.
208  * \return <i>TRUE</i> if OK to move off page.
209  */
210 static gboolean exp_html_move_format( void ) {
211         gboolean retVal = FALSE;
212         GtkWidget *menu, *menuItem;
213         gint id;
214
215         /* Set stylesheet */
216         menu = gtk_option_menu_get_menu( GTK_OPTION_MENU( exphtml_dlg.optmenuCSS ) );
217         menuItem = gtk_menu_get_active( GTK_MENU( menu ) );
218         id = GPOINTER_TO_INT( gtk_object_get_user_data(GTK_OBJECT(menuItem)) );
219         exporthtml_set_stylesheet( _exportCtl_, id );
220
221         /* Set name format */
222         menu = gtk_option_menu_get_menu( GTK_OPTION_MENU( exphtml_dlg.optmenuName ) );
223         menuItem = gtk_menu_get_active( GTK_MENU( menu ) );
224         id = GPOINTER_TO_INT( gtk_object_get_user_data(GTK_OBJECT(menuItem)) );
225         exporthtml_set_name_format( _exportCtl_, id );
226
227         exporthtml_set_banding( _exportCtl_,
228                 gtk_toggle_button_get_active(
229                         GTK_TOGGLE_BUTTON( exphtml_dlg.checkBanding ) ) );
230         exporthtml_set_link_email( _exportCtl_,
231                 gtk_toggle_button_get_active(
232                         GTK_TOGGLE_BUTTON( exphtml_dlg.checkLinkEMail ) ) );
233         exporthtml_set_attributes( _exportCtl_,
234                 gtk_toggle_button_get_active(
235                         GTK_TOGGLE_BUTTON( exphtml_dlg.checkAttributes ) ) );
236
237         /* Process export */
238         exporthtml_process( _exportCtl_, _addressCache_ );
239         if( _exportCtl_->retVal == MGU_SUCCESS ) {
240                 retVal = TRUE;
241         }
242         else {
243                 export_html_status_show( _( "Error creating HTML file" ) );
244         }
245         return retVal;
246 }
247
248 /**
249  * Display finish page.
250  */
251 static void exp_html_finish_show( void ) {
252         gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelOutFile), _exportCtl_->path );
253         gtk_widget_set_sensitive( exphtml_dlg.btnNext, FALSE );
254         gtk_widget_grab_focus( exphtml_dlg.btnCancel );
255 }
256
257 /**
258  * Callback function to select previous page.
259  * \param widget Widget (button).
260  */
261 static void export_html_prev( GtkWidget *widget ) {
262         gint pageNum;
263
264         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
265         if( pageNum == PAGE_FORMAT ) {
266                 /* Goto file page stuff */
267                 gtk_notebook_set_current_page(
268                         GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FILE_INFO );
269                 gtk_widget_set_sensitive( exphtml_dlg.btnPrev, FALSE );
270         }
271         else if( pageNum == PAGE_FINISH ) {
272                 /* Goto format page */
273                 gtk_notebook_set_current_page(
274                         GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FORMAT );
275                 gtk_widget_set_sensitive( exphtml_dlg.btnNext, TRUE );
276         }
277         export_html_message();
278 }
279
280 /**
281  * Callback function to select previous page.
282  * \param widget Widget (button).
283  */
284 static void export_html_next( GtkWidget *widget ) {
285         gint pageNum;
286
287         pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook) );
288         if( pageNum == PAGE_FILE_INFO ) {
289                 /* Goto format page */
290                 if( exp_html_move_file() ) {
291                         gtk_notebook_set_current_page(
292                                 GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FORMAT );
293                         gtk_widget_set_sensitive( exphtml_dlg.btnPrev, TRUE );
294                 }
295                 export_html_message();
296         }
297         else if( pageNum == PAGE_FORMAT ) {
298                 /* Goto finish page */
299                 if( exp_html_move_format() ) {
300                         gtk_notebook_set_current_page(
301                                 GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FINISH );
302                         exp_html_finish_show();
303                         exporthtml_save_settings( _exportCtl_ );
304                         export_html_message();
305                 }
306         }
307 }
308
309 /**
310  * Open file with web browser.
311  * \param widget Widget (button).
312  * \param data   User data.
313  */
314 static void export_html_browse( GtkWidget *widget, gpointer data ) {
315         gchar *uri;
316
317         uri = g_strconcat( "file://", _exportCtl_->path, NULL );
318         open_uri( uri, prefs_common.uri_cmd );
319         g_free( uri );
320 }
321
322 /**
323  * Callback function to accept HTML file selection.
324  * \param widget Widget (button).
325  * \param data   User data.
326  */
327 static void exp_html_file_ok( GtkWidget *widget, gpointer data ) {
328         const gchar *sFile;
329         AddressFileSelection *afs;
330         GtkWidget *fileSel;
331
332         afs = ( AddressFileSelection * ) data;
333         fileSel = afs->fileSelector;
334         sFile = gtk_file_selection_get_filename( GTK_FILE_SELECTION(fileSel) );
335
336         afs->cancelled = FALSE;
337         gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), sFile );
338         gtk_widget_hide( afs->fileSelector );
339         gtk_grab_remove( afs->fileSelector );
340         gtk_widget_grab_focus( exphtml_dlg.entryHtml );
341 }
342
343 /**
344  * Callback function to cancel HTML file selection dialog.
345  * \param widget Widget (button).
346  * \param data   User data.
347  */
348 static void exp_html_file_cancel( GtkWidget *widget, gpointer data ) {
349         AddressFileSelection *afs = ( AddressFileSelection * ) data;
350         afs->cancelled = TRUE;
351         gtk_widget_hide( afs->fileSelector );
352         gtk_grab_remove( afs->fileSelector );
353         gtk_widget_grab_focus( exphtml_dlg.entryHtml );
354 }
355
356 /**
357  * Create HTML file selection dialog.
358  * \param afs Address file selection data.
359  */
360 static void exp_html_file_select_create( AddressFileSelection *afs ) {
361         GtkWidget *fileSelector;
362
363         fileSelector = gtk_file_selection_new( _("Select HTML Output File") );
364         gtk_file_selection_hide_fileop_buttons( GTK_FILE_SELECTION(fileSelector) );
365         gtk_file_selection_complete( GTK_FILE_SELECTION(fileSelector), "*.html" );
366         g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(fileSelector)->ok_button),
367                          "clicked", 
368                          G_CALLBACK(exp_html_file_ok), (gpointer)afs);
369         g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(fileSelector)->cancel_button),
370                          "clicked", 
371                          G_CALLBACK(exp_html_file_cancel), (gpointer)afs);
372         afs->fileSelector = fileSelector;
373         afs->cancelled = TRUE;
374 }
375
376 /**
377  * Callback function to display HTML file selection dialog.
378  */
379 static void exp_html_file_select( void ) {
380         gchar *sFile;
381         if( ! _exp_html_file_selector_.fileSelector )
382                 exp_html_file_select_create( & _exp_html_file_selector_ );
383
384         sFile = gtk_editable_get_chars( GTK_EDITABLE(exphtml_dlg.entryHtml), 0, -1 );
385         gtk_file_selection_set_filename(
386                 GTK_FILE_SELECTION( _exp_html_file_selector_.fileSelector ),
387                 sFile );
388         g_free( sFile );
389         gtk_widget_show( _exp_html_file_selector_.fileSelector );
390         gtk_grab_add( _exp_html_file_selector_.fileSelector );
391 }
392
393 /**
394  * Format notebook file specification page.
395  * \param pageNum Page (tab) number.
396  * \param pageLbl Page (tab) label.
397  */
398 static void export_html_page_file( gint pageNum, gchar *pageLbl ) {
399         GtkWidget *vbox;
400         GtkWidget *table;
401         GtkWidget *label;
402         GtkWidget *labelBook;
403         GtkWidget *entryHtml;
404         GtkWidget *btnFile;
405         gint top;
406
407         vbox = gtk_vbox_new(FALSE, 8);
408         gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
409         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
410
411         label = gtk_label_new( pageLbl );
412         gtk_widget_show( label );
413         gtk_notebook_set_tab_label(
414                 GTK_NOTEBOOK( exphtml_dlg.notebook ),
415                 gtk_notebook_get_nth_page(
416                         GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ),
417                 label );
418
419         table = gtk_table_new( 3, 3, FALSE );
420         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
421         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
422         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
423         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
424
425         /* First row */
426         top = 0;
427         label = gtk_label_new( _( "Address Book" ) );
428         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
429                 GTK_FILL, 0, 0, 0);
430         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
431
432         labelBook = gtk_label_new( "Address book name goes here" );
433         gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1),
434                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
435         gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
436
437         /* Second row */
438         top++;
439         label = gtk_label_new( _( "HTML Output File" ) );
440         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
441                 GTK_FILL, 0, 0, 0);
442         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
443
444         entryHtml = gtk_entry_new();
445         gtk_table_attach(GTK_TABLE(table), entryHtml, 1, 2, top, (top + 1),
446                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
447
448         btnFile = gtk_button_new_with_label( _(" ... "));
449         gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
450                 GTK_FILL, 0, 3, 0);
451
452         gtk_widget_show_all(vbox);
453
454         /* Button handler */
455         g_signal_connect(G_OBJECT(btnFile), "clicked",
456                          G_CALLBACK(exp_html_file_select), NULL);
457
458         exphtml_dlg.labelBook = labelBook;
459         exphtml_dlg.entryHtml = entryHtml;
460 }
461
462 /**
463  * Format notebook format page.
464  * \param pageNum Page (tab) number.
465  * \param pageLbl Page (tab) label.
466  */
467 static void export_html_page_format( gint pageNum, gchar *pageLbl ) {
468         GtkWidget *vbox;
469         GtkWidget *table;
470         GtkWidget *label;
471         GtkWidget *optmenuCSS;
472         GtkWidget *optmenuName;
473         GtkWidget *menu;
474         GtkWidget *menuItem;
475         GtkWidget *checkBanding;
476         GtkWidget *checkLinkEMail;
477         GtkWidget *checkAttributes;
478         gint top;
479
480         vbox = gtk_vbox_new(FALSE, 8);
481         gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
482         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
483
484         label = gtk_label_new( pageLbl );
485         gtk_widget_show( label );
486         gtk_notebook_set_tab_label(
487                 GTK_NOTEBOOK( exphtml_dlg.notebook ),
488                 gtk_notebook_get_nth_page(
489                         GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ),
490                 label );
491
492         table = gtk_table_new( 5, 3, FALSE );
493         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
494         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
495         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
496         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
497
498         /* First row */
499         top = 0;
500         label = gtk_label_new( _( "Stylesheet" ) );
501         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
502                 GTK_FILL, 0, 0, 0);
503         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
504
505         menu = gtk_menu_new();
506
507         menuItem = gtk_menu_item_new_with_label( _( "None" ) );
508         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
509                         GINT_TO_POINTER( EXPORT_HTML_ID_NONE ) );
510         gtk_menu_append( GTK_MENU(menu), menuItem );
511         gtk_widget_show( menuItem );
512
513         menuItem = gtk_menu_item_new_with_label( _( "Default" ) );
514         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
515                         GINT_TO_POINTER( EXPORT_HTML_ID_DEFAULT ) );
516         gtk_menu_append( GTK_MENU(menu), menuItem );
517         gtk_widget_show( menuItem );
518
519         menuItem = gtk_menu_item_new_with_label( _( "Full" ) );
520         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
521                         GINT_TO_POINTER( EXPORT_HTML_ID_FULL ) );
522         gtk_menu_append( GTK_MENU(menu), menuItem );
523         gtk_widget_show( menuItem );
524
525         menuItem = gtk_menu_item_new_with_label( _( "Custom" ) );
526         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
527                         GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM ) );
528         gtk_menu_append( GTK_MENU(menu), menuItem );
529         gtk_widget_show( menuItem );
530
531         menuItem = gtk_menu_item_new_with_label( _( "Custom-2" ) );
532         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
533                         GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM2 ) );
534         gtk_menu_append( GTK_MENU(menu), menuItem );
535         gtk_widget_show( menuItem );
536
537         menuItem = gtk_menu_item_new_with_label( _( "Custom-3" ) );
538         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
539                         GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM3 ) );
540         gtk_menu_append( GTK_MENU(menu), menuItem );
541         gtk_widget_show( menuItem );
542
543         menuItem = gtk_menu_item_new_with_label( _( "Custom-4" ) );
544         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
545                         GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM4 ) );
546         gtk_menu_append( GTK_MENU(menu), menuItem );
547         gtk_widget_show( menuItem );
548
549         optmenuCSS = gtk_option_menu_new();
550         gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuCSS ), menu );
551
552         gtk_table_attach(GTK_TABLE(table), optmenuCSS, 1, 2, top, (top + 1),
553                 GTK_FILL, 0, 0, 0);
554
555         /* Second row */
556         top++;
557         label = gtk_label_new( _( "Full Name Format" ) );
558         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
559                 GTK_FILL, 0, 0, 0);
560         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
561
562         menu = gtk_menu_new();
563
564         menuItem = gtk_menu_item_new_with_label( _( "First Name, Last Name" ) );
565         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
566                         GINT_TO_POINTER( EXPORT_HTML_FIRST_LAST ) );
567         gtk_menu_append( GTK_MENU(menu), menuItem );
568         gtk_widget_show( menuItem );
569
570         menuItem = gtk_menu_item_new_with_label( _( "Last Name, First Name" ) );
571         gtk_object_set_user_data( GTK_OBJECT( menuItem ),
572                         GINT_TO_POINTER( EXPORT_HTML_LAST_FIRST ) );
573         gtk_menu_append( GTK_MENU(menu), menuItem );
574         gtk_widget_show( menuItem );
575
576         optmenuName = gtk_option_menu_new();
577         gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuName ), menu );
578
579         gtk_table_attach(GTK_TABLE(table), optmenuName, 1, 2, top, (top + 1),
580                 GTK_FILL, 0, 0, 0);
581
582         /* Third row */
583         top++;
584         checkBanding = gtk_check_button_new_with_label( _( "Color Banding" ) );
585         gtk_table_attach(GTK_TABLE(table), checkBanding, 1, 2, top, (top + 1),
586                 GTK_FILL, 0, 0, 0);
587
588         /* Fourth row */
589         top++;
590         checkLinkEMail = gtk_check_button_new_with_label( _( "Format E-Mail Links" ) );
591         gtk_table_attach(GTK_TABLE(table), checkLinkEMail, 1, 2, top, (top + 1),
592                 GTK_FILL, 0, 0, 0);
593
594         /* Fifth row */
595         top++;
596         checkAttributes = gtk_check_button_new_with_label( _( "Format User Attributes" ) );
597         gtk_table_attach(GTK_TABLE(table), checkAttributes, 1, 2, top, (top + 1),
598                 GTK_FILL, 0, 0, 0);
599
600         gtk_widget_show_all(vbox);
601
602         exphtml_dlg.optmenuCSS      = optmenuCSS;
603         exphtml_dlg.optmenuName     = optmenuName;
604         exphtml_dlg.checkBanding    = checkBanding;
605         exphtml_dlg.checkLinkEMail  = checkLinkEMail;
606         exphtml_dlg.checkAttributes = checkAttributes;
607 }
608
609 /**
610  * Format notebook finish page.
611  * \param pageNum Page (tab) number.
612  * \param pageLbl Page (tab) label.
613  */
614 static void export_html_page_finish( gint pageNum, gchar *pageLbl ) {
615         GtkWidget *vbox;
616         GtkWidget *table;
617         GtkWidget *label;
618         GtkWidget *labelBook;
619         GtkWidget *labelFile;
620         GtkWidget *btnBrowse;
621         gint top;
622
623         vbox = gtk_vbox_new(FALSE, 8);
624         gtk_container_add( GTK_CONTAINER( exphtml_dlg.notebook ), vbox );
625         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
626
627         label = gtk_label_new( pageLbl );
628         gtk_widget_show( label );
629         gtk_notebook_set_tab_label(
630                 GTK_NOTEBOOK( exphtml_dlg.notebook ),
631                 gtk_notebook_get_nth_page( GTK_NOTEBOOK( exphtml_dlg.notebook ), pageNum ), label );
632
633         table = gtk_table_new( 3, 3, FALSE );
634         gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
635         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
636         gtk_table_set_row_spacings(GTK_TABLE(table), 8);
637         gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
638
639         /* First row */
640         top = 0;
641         label = gtk_label_new( _( "Address Book :" ) );
642         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
643         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
644
645         labelBook = gtk_label_new("Full name of address book goes here");
646         gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
647         gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
648
649         /* Second row */
650         top++;
651         label = gtk_label_new( _( "File Name :" ) );
652         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
653         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
654
655         labelFile = gtk_label_new("File name goes here");
656         gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
657         gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
658
659         /* Third row */
660         top++;
661         btnBrowse = gtk_button_new_with_label( _( "Open with Web Browser" ) );
662         gtk_table_attach(GTK_TABLE(table), btnBrowse, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
663
664         gtk_widget_show_all(vbox);
665
666         /* Button handlers */
667         g_signal_connect(G_OBJECT(btnBrowse), "clicked",
668                          G_CALLBACK(export_html_browse), NULL);
669
670         exphtml_dlg.labelOutBook = labelBook;
671         exphtml_dlg.labelOutFile = labelFile;
672 }
673
674 /**
675  * Create main dialog decorations (excluding notebook pages).
676  */
677 static void export_html_dialog_create( void ) {
678         GtkWidget *window;
679         GtkWidget *vbox;
680         GtkWidget *vnbox;
681         GtkWidget *notebook;
682         GtkWidget *hbbox;
683         GtkWidget *btnPrev;
684         GtkWidget *btnNext;
685         GtkWidget *btnCancel;
686         GtkWidget *hsbox;
687         GtkWidget *statusbar;
688
689         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
690         gtk_widget_set_size_request(window, EXPORTHTML_WIDTH, EXPORTHTML_HEIGHT );
691         gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
692         gtk_window_set_title( GTK_WINDOW(window),
693                 _("Export Address Book to HTML File") );
694         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
695         gtk_window_set_modal(GTK_WINDOW(window), TRUE); 
696         g_signal_connect(G_OBJECT(window), "delete_event",
697                          G_CALLBACK(export_html_delete_event),
698                          NULL );
699         g_signal_connect(G_OBJECT(window), "key_press_event",
700                          G_CALLBACK(export_html_key_pressed),
701                          NULL );
702
703         vbox = gtk_vbox_new(FALSE, 4);
704         gtk_widget_show(vbox);
705         gtk_container_add(GTK_CONTAINER(window), vbox);
706
707         vnbox = gtk_vbox_new(FALSE, 4);
708         gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
709         gtk_widget_show(vnbox);
710         gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
711
712         /* Notebook */
713         notebook = gtk_notebook_new();
714         gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */
715         /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */
716         gtk_widget_show(notebook);
717         gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
718         gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
719
720         /* Status line */
721         hsbox = gtk_hbox_new(FALSE, 0);
722         gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
723         statusbar = gtk_statusbar_new();
724         gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
725
726         /* Button panel */
727         gtkut_stock_button_set_create(&hbbox, &btnPrev, GTK_STOCK_GO_BACK,
728                                       &btnNext, GTK_STOCK_GO_FORWARD,
729                                       &btnCancel, GTK_STOCK_CANCEL);
730         gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
731         gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
732         gtk_widget_grab_default(btnNext);
733
734         /* Button handlers */
735         g_signal_connect(G_OBJECT(btnPrev), "clicked",
736                          G_CALLBACK(export_html_prev), NULL);
737         g_signal_connect(G_OBJECT(btnNext), "clicked",
738                          G_CALLBACK(export_html_next), NULL);
739         g_signal_connect(G_OBJECT(btnCancel), "clicked",
740                          G_CALLBACK(export_html_cancel), NULL);
741
742         gtk_widget_show_all(vbox);
743
744         exphtml_dlg.window     = window;
745         exphtml_dlg.notebook   = notebook;
746         exphtml_dlg.btnPrev    = btnPrev;
747         exphtml_dlg.btnNext    = btnNext;
748         exphtml_dlg.btnCancel  = btnCancel;
749         exphtml_dlg.statusbar  = statusbar;
750         exphtml_dlg.status_cid = gtk_statusbar_get_context_id(
751                         GTK_STATUSBAR(statusbar), "Export HTML Dialog" );
752 }
753
754 /**
755  * Create export HTML dialog.
756  */
757 static void export_html_create( void ) {
758         export_html_dialog_create();
759         export_html_page_file( PAGE_FILE_INFO, _( "File Info" ) );
760         export_html_page_format( PAGE_FORMAT, _( "Format" ) );
761         export_html_page_finish( PAGE_FINISH, _( "Finish" ) );
762         gtk_widget_show_all( exphtml_dlg.window );
763 }
764
765 /**
766  * Populate fields from control data.
767  * \param ctl Export control data.
768  */
769 static void export_html_fill_fields( ExportHtmlCtl *ctl ) {
770         gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), "" );
771         if( ctl->path ) {
772                 gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml),
773                         ctl->path );
774         }
775
776         gtk_option_menu_set_history(
777                 GTK_OPTION_MENU( exphtml_dlg.optmenuCSS ), ctl->stylesheet );
778         gtk_option_menu_set_history(
779                 GTK_OPTION_MENU( exphtml_dlg.optmenuName ), ctl->nameFormat );
780         gtk_toggle_button_set_active(
781                 GTK_TOGGLE_BUTTON( exphtml_dlg.checkBanding ), ctl->banding );
782         gtk_toggle_button_set_active(
783                 GTK_TOGGLE_BUTTON( exphtml_dlg.checkLinkEMail ), ctl->linkEMail );
784         gtk_toggle_button_set_active(
785                 GTK_TOGGLE_BUTTON( exphtml_dlg.checkAttributes ), ctl->showAttribs );
786 }
787
788 /**
789  * Process export address dialog.
790  * \param cache Address book/data source cache.
791  */
792 void addressbook_exp_html( AddressCache *cache ) {
793         /* Set references to control data */
794         _addressCache_ = cache;
795
796         _exportCtl_ = exporthtml_create();
797         exporthtml_load_settings( _exportCtl_ );
798
799         /* Setup GUI */
800         if( ! exphtml_dlg.window )
801                 export_html_create();
802         exphtml_dlg.cancelled = FALSE;
803         gtk_widget_show(exphtml_dlg.window);
804         manage_window_set_transient(GTK_WINDOW(exphtml_dlg.window));
805
806         gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelBook), cache->name );
807         gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelOutBook), cache->name );
808         export_html_fill_fields( _exportCtl_ );
809
810         gtk_widget_grab_default(exphtml_dlg.btnNext);
811         gtk_notebook_set_current_page( GTK_NOTEBOOK(exphtml_dlg.notebook), PAGE_FILE_INFO );
812         gtk_widget_set_sensitive( exphtml_dlg.btnPrev, FALSE );
813         gtk_widget_set_sensitive( exphtml_dlg.btnNext, TRUE );
814
815         export_html_message();
816         gtk_widget_grab_focus(exphtml_dlg.entryHtml);
817
818         gtk_main();
819         gtk_widget_hide(exphtml_dlg.window);
820         exporthtml_free( _exportCtl_ );
821         _exportCtl_ = NULL;
822
823         _addressCache_ = NULL;
824 }
825
826 /*
827  * ============================================================================
828  * End of Source.
829  * ============================================================================
830  */
831