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