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