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