fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[claws.git] / src / exphtmldlg.c
index f85050b001633c6ca2cd1f23e828293f58dc1add..e6c4def961a6e875ed9591094c05c5c1bc065199 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2002-2006 Match Grun and the Sylpheed-Claws team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2002-2015 Match Grun and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
@@ -23,6 +22,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
-#include <gtk/gtkwindow.h>
-#include <gtk/gtksignal.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtktable.h>
-#include <gtk/gtkbutton.h>
+#include <gtk/gtk.h>
 
 #include "gtkutils.h"
 #include "prefs_common.h"
 #include "utils.h"
 #include "manage_window.h"
 #include "filesel.h"
+#include "combobox.h"
 
 #define PAGE_FILE_INFO             0
 #define PAGE_FORMAT                1
 #define PAGE_FINISH                2
 
-#define EXPORTHTML_WIDTH           480
-#define EXPORTHTML_HEIGHT          -1
-
 /**
  * Dialog object.
  */
@@ -153,7 +146,7 @@ static gint export_html_delete_event( GtkWidget *widget, GdkEventAny *event, gpo
  * \param data   User data.
  */
 static gboolean export_html_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                export_html_cancel( widget, data );
        }
        return FALSE;
@@ -168,23 +161,24 @@ static gboolean exp_html_move_file( void ) {
        AlertValue aval;
 
        sFile = gtk_editable_get_chars( GTK_EDITABLE(exphtml_dlg.entryHtml), 0, -1 );
-       g_strchug( sFile ); g_strchomp( sFile );
+       g_strstrip( sFile );
        gtk_entry_set_text( GTK_ENTRY(exphtml_dlg.entryHtml), sFile );
        exporthtml_parse_filespec( _exportCtl_, sFile );
        g_free( sFile );
 
        /* Test for directory */
-       if( exporthtml_test_dir( _exportCtl_ ) ) {
+       if( g_file_test(_exportCtl_->dirOutput,
+                               G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) {
                return TRUE;
        }
 
        /* Prompt to create */
        msg = g_strdup_printf( _(
-               "HTML Output Directory '%s'\n" \
-               "does not exist. OK to create new directory?" ),
+               "The HTML output directory '%s'\n" \
+               "does not exist. Do you want to create it?" ),
                _exportCtl_->dirOutput );
-       aval = alertpanel( _("Create Directory" ),
-               msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL );
+       aval = alertpanel( _("Create directory" ),
+               msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL, ALERTFOCUS_FIRST );
        g_free( msg );
        if( aval != G_ALERTALTERNATE ) return FALSE;
 
@@ -195,8 +189,8 @@ static gboolean exp_html_move_file( void ) {
                        "Could not create output directory for HTML file:\n%s" ),
                        reason );
                aval = alertpanel_full(_("Failed to Create Directory"), msg,
-                                      GTK_STOCK_CLOSE, NULL, NULL, FALSE,
-                                      NULL, ALERT_ERROR, G_ALERTDEFAULT);
+                                      GTK_STOCK_CLOSE, NULL, NULL, ALERTFOCUS_FIRST, FALSE,
+                                      NULL, ALERT_ERROR);
                g_free( msg );
                return FALSE;
        }
@@ -210,19 +204,14 @@ static gboolean exp_html_move_file( void ) {
  */
 static gboolean exp_html_move_format( void ) {
        gboolean retVal = FALSE;
-       GtkWidget *menu, *menuItem;
        gint id;
 
        /* Set stylesheet */
-       menu = gtk_option_menu_get_menu( GTK_OPTION_MENU( exphtml_dlg.optmenuCSS ) );
-       menuItem = gtk_menu_get_active( GTK_MENU( menu ) );
-       id = GPOINTER_TO_INT( gtk_object_get_user_data(GTK_OBJECT(menuItem)) );
+       id = combobox_get_active_data(GTK_COMBO_BOX(exphtml_dlg.optmenuCSS));
        exporthtml_set_stylesheet( _exportCtl_, id );
 
        /* Set name format */
-       menu = gtk_option_menu_get_menu( GTK_OPTION_MENU( exphtml_dlg.optmenuName ) );
-       menuItem = gtk_menu_get_active( GTK_MENU( menu ) );
-       id = GPOINTER_TO_INT( gtk_object_get_user_data(GTK_OBJECT(menuItem)) );
+       id = combobox_get_active_data(GTK_COMBO_BOX(exphtml_dlg.optmenuName));
        exporthtml_set_name_format( _exportCtl_, id );
 
        exporthtml_set_banding( _exportCtl_,
@@ -317,8 +306,8 @@ static void export_html_next( GtkWidget *widget ) {
 static void export_html_browse( GtkWidget *widget, gpointer data ) {
        gchar *uri;
 
-       uri = g_strconcat( "file://", _exportCtl_->path, NULL );
-       open_uri( uri, prefs_common.uri_cmd );
+       uri = g_filename_to_uri(_exportCtl_->path, NULL, NULL);
+       open_uri( uri, prefs_common_get_uri_cmd() );
        g_free( uri );
 }
 
@@ -425,11 +414,12 @@ static void export_html_page_format( gint pageNum, gchar *pageLbl ) {
        GtkWidget *label;
        GtkWidget *optmenuCSS;
        GtkWidget *optmenuName;
-       GtkWidget *menu;
-       GtkWidget *menuItem;
+       GtkListStore *menu;
+       GtkTreeIter iter;
        GtkWidget *checkBanding;
        GtkWidget *checkLinkEMail;
        GtkWidget *checkAttributes;
+
        gint top;
 
        vbox = gtk_vbox_new(FALSE, 8);
@@ -457,52 +447,16 @@ static void export_html_page_format( gint pageNum, gchar *pageLbl ) {
                GTK_FILL, 0, 0, 0);
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
-       menu = gtk_menu_new();
-
-       menuItem = gtk_menu_item_new_with_label( _( "None" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_ID_NONE ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       menuItem = gtk_menu_item_new_with_label( _( "Default" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_ID_DEFAULT ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       menuItem = gtk_menu_item_new_with_label( _( "Full" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_ID_FULL ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       menuItem = gtk_menu_item_new_with_label( _( "Custom" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       menuItem = gtk_menu_item_new_with_label( _( "Custom-2" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM2 ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       menuItem = gtk_menu_item_new_with_label( _( "Custom-3" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM3 ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       menuItem = gtk_menu_item_new_with_label( _( "Custom-4" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_ID_CUSTOM4 ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       optmenuCSS = gtk_option_menu_new();
-       gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuCSS ), menu );
+       optmenuCSS = gtkut_sc_combobox_create(NULL, TRUE);
+       menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuCSS)));
+
+       COMBOBOX_ADD(menu, _("None"), EXPORT_HTML_ID_NONE);
+       COMBOBOX_ADD(menu, _("Default"), EXPORT_HTML_ID_DEFAULT);
+       COMBOBOX_ADD(menu, _("Full"), EXPORT_HTML_ID_FULL);
+       COMBOBOX_ADD(menu, _("Custom"), EXPORT_HTML_ID_CUSTOM);
+       COMBOBOX_ADD(menu, _("Custom-2"), EXPORT_HTML_ID_CUSTOM2);
+       COMBOBOX_ADD(menu, _("Custom-3"), EXPORT_HTML_ID_CUSTOM3);
+       COMBOBOX_ADD(menu, _("Custom-4"), EXPORT_HTML_ID_CUSTOM4);
 
        gtk_table_attach(GTK_TABLE(table), optmenuCSS, 1, 2, top, (top + 1),
                GTK_FILL, 0, 0, 0);
@@ -514,22 +468,11 @@ static void export_html_page_format( gint pageNum, gchar *pageLbl ) {
                GTK_FILL, 0, 0, 0);
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
-       menu = gtk_menu_new();
+       optmenuName = gtkut_sc_combobox_create(NULL, TRUE);
+       menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuName)));
 
-       menuItem = gtk_menu_item_new_with_label( _( "First Name, Last Name" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_FIRST_LAST ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       menuItem = gtk_menu_item_new_with_label( _( "Last Name, First Name" ) );
-       gtk_object_set_user_data( GTK_OBJECT( menuItem ),
-                       GINT_TO_POINTER( EXPORT_HTML_LAST_FIRST ) );
-       gtk_menu_append( GTK_MENU(menu), menuItem );
-       gtk_widget_show( menuItem );
-
-       optmenuName = gtk_option_menu_new();
-       gtk_option_menu_set_menu( GTK_OPTION_MENU( optmenuName ), menu );
+       COMBOBOX_ADD(menu, _("First Name, Last Name"), EXPORT_HTML_FIRST_LAST);
+       COMBOBOX_ADD(menu, _("Last Name, First Name"), EXPORT_HTML_LAST_FIRST);
 
        gtk_table_attach(GTK_TABLE(table), optmenuName, 1, 2, top, (top + 1),
                GTK_FILL, 0, 0, 0);
@@ -593,7 +536,7 @@ static void export_html_page_finish( gint pageNum, gchar *pageLbl ) {
 
        /* First row */
        top = 0;
-       label = gtk_label_new( _( "Address Book :" ) );
+       label = gtk_label_new( _( "Address Book:" ) );
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
 
@@ -603,7 +546,7 @@ static void export_html_page_finish( gint pageNum, gchar *pageLbl ) {
 
        /* Second row */
        top++;
-       label = gtk_label_new( _( "File Name :" ) );
+       label = gtk_label_new( _( "File Name:" ) );
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
 
@@ -641,13 +584,13 @@ static void export_html_dialog_create( void ) {
        GtkWidget *hsbox;
        GtkWidget *statusbar;
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-       gtk_widget_set_size_request(window, EXPORTHTML_WIDTH, EXPORTHTML_HEIGHT );
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "exphtmldlg");
+       gtk_widget_set_size_request(window, -1, -1 );
        gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
        gtk_window_set_title( GTK_WINDOW(window),
                _("Export Address Book to HTML File") );
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_modal(GTK_WINDOW(window), TRUE); 
+       gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(export_html_delete_event),
                         NULL );
@@ -728,10 +671,10 @@ static void export_html_fill_fields( ExportHtmlCtl *ctl ) {
                        ctl->path );
        }
 
-       gtk_option_menu_set_history(
-               GTK_OPTION_MENU( exphtml_dlg.optmenuCSS ), ctl->stylesheet );
-       gtk_option_menu_set_history(
-               GTK_OPTION_MENU( exphtml_dlg.optmenuName ), ctl->nameFormat );
+       combobox_select_by_data(
+                       GTK_COMBO_BOX(exphtml_dlg.optmenuCSS), ctl->stylesheet );
+       combobox_select_by_data(
+                       GTK_COMBO_BOX(exphtml_dlg.optmenuName), ctl->nameFormat );
        gtk_toggle_button_set_active(
                GTK_TOGGLE_BUTTON( exphtml_dlg.checkBanding ), ctl->banding );
        gtk_toggle_button_set_active(
@@ -760,7 +703,7 @@ void addressbook_exp_html( AddressCache *cache ) {
        exphtml_dlg.cancelled = FALSE;
        gtk_widget_show(exphtml_dlg.window);
        manage_window_set_transient(GTK_WINDOW(exphtml_dlg.window));
-
+       gtk_window_set_modal(GTK_WINDOW(exphtml_dlg.window), TRUE);
        gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelBook), cache->name );
        gtk_label_set_text( GTK_LABEL(exphtml_dlg.labelOutBook), cache->name );
        export_html_fill_fields( _exportCtl_ );
@@ -775,6 +718,7 @@ void addressbook_exp_html( AddressCache *cache ) {
 
        gtk_main();
        gtk_widget_hide(exphtml_dlg.window);
+       gtk_window_set_modal(GTK_WINDOW(exphtml_dlg.window), FALSE);
        exporthtml_free( _exportCtl_ );
        _exportCtl_ = NULL;