inital gtk2 patch
[claws.git] / src / export.c
index a0886c6..7859b31 100644 (file)
@@ -48,6 +48,7 @@
 #include "manage_window.h"
 #include "folder.h"
 #include "utils.h"
+#include "codeconv.h"
 
 static GtkWidget *window;
 static GtkWidget *src_entry;
@@ -64,7 +65,7 @@ static void export_cancel_cb(GtkWidget *widget, gpointer data);
 static void export_srcsel_cb(GtkWidget *widget, gpointer data);
 static void export_filesel_cb(GtkWidget *widget, gpointer data);
 static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data);
-static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
+static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
 
 gint export_mbox(FolderItem *default_src)
 {
@@ -94,18 +95,30 @@ gint export_mbox(FolderItem *default_src)
        gtk_main();
 
        if (export_ack) {
-               gchar *srcdir, *mbox;
+               const gchar *srcdir, *utf8mbox;
                FolderItem *src;
 
                srcdir = gtk_entry_get_text(GTK_ENTRY(src_entry));
-               mbox = gtk_entry_get_text(GTK_ENTRY(file_entry));
+               utf8mbox = gtk_entry_get_text(GTK_ENTRY(file_entry));
+               if (utf8mbox && *utf8mbox) {
+                       const gchar *src_codeset = CS_UTF_8;
+                       const gchar *dest_codeset = conv_get_current_charset_str();
+                       gchar *mbox;
+
+#warning FIXME_GTK2 /* should we use g_filename_from_utf8()? */
+                       mbox = conv_codeset_strdup(utf8mbox, src_codeset, dest_codeset);
+                       if (!mbox) {
+                               g_warning("faild to convert character set\n");
+                               mbox = g_strdup(utf8mbox);
+                       }
 
-               if (mbox && *mbox) {
                        src = folder_find_item_from_identifier(srcdir);
                        if (!src)
                                g_warning("Can't find the folder.\n");
                        else
                                ok = export_to_mbox(src, mbox);
+
+                       g_free(mbox);
                }
        }
 
@@ -124,16 +137,16 @@ static void export_create(void)
        GtkWidget *src_label;
        GtkWidget *confirm_area;
 
-       window = gtk_window_new(GTK_WINDOW_DIALOG);
+       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(window), _("Export"));
        gtk_container_set_border_width(GTK_CONTAINER(window), 5);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
        gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
-       gtk_signal_connect(GTK_OBJECT(window), "delete_event",
-                          GTK_SIGNAL_FUNC(delete_event), NULL);
-       gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
-                          GTK_SIGNAL_FUNC(key_pressed), NULL);
+       g_signal_connect(G_OBJECT(window), "delete_event",
+                        G_CALLBACK(delete_event), NULL);
+       g_signal_connect(G_OBJECT(window), "key_press_event",
+                        G_CALLBACK(key_pressed), NULL);
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
 
        vbox = gtk_vbox_new(FALSE, 4);
@@ -152,7 +165,7 @@ static void export_create(void)
        gtk_container_set_border_width(GTK_CONTAINER(table), 8);
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
-       gtk_widget_set_usize(table, 420, -1);
+       gtk_widget_set_size_request(table, 420, -1);
 
        src_label = gtk_label_new(_("Source dir:"));
        gtk_table_attach(GTK_TABLE(table), src_label, 0, 1, 0, 1,
@@ -175,14 +188,14 @@ static void export_create(void)
        src_button = gtk_button_new_with_label(_(" Select... "));
        gtk_table_attach(GTK_TABLE(table), src_button, 2, 3, 0, 1,
                         0, 0, 0, 0);
-       gtk_signal_connect(GTK_OBJECT(src_button), "clicked",
-                          GTK_SIGNAL_FUNC(export_srcsel_cb), NULL);
+       g_signal_connect(G_OBJECT(src_button), "clicked",
+                        G_CALLBACK(export_srcsel_cb), NULL);
 
        file_button = gtk_button_new_with_label(_(" Select... "));
        gtk_table_attach(GTK_TABLE(table), file_button, 2, 3, 1, 2,
                         0, 0, 0, 0);
-       gtk_signal_connect(GTK_OBJECT(file_button), "clicked",
-                          GTK_SIGNAL_FUNC(export_filesel_cb), NULL);
+       g_signal_connect(G_OBJECT(file_button), "clicked",
+                        G_CALLBACK(export_filesel_cb), NULL);
 
        gtkut_button_set_create(&confirm_area,
                                &ok_button,     _("OK"),
@@ -191,10 +204,10 @@ static void export_create(void)
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(ok_button);
 
-       gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
-                          GTK_SIGNAL_FUNC(export_ok_cb), NULL);
-       gtk_signal_connect(GTK_OBJECT(cancel_button), "clicked",
-                          GTK_SIGNAL_FUNC(export_cancel_cb), NULL);
+       g_signal_connect(G_OBJECT(ok_button), "clicked",
+                        G_CALLBACK(export_ok_cb), NULL);
+       g_signal_connect(G_OBJECT(cancel_button), "clicked",
+                        G_CALLBACK(export_cancel_cb), NULL);
 
        gtk_widget_show_all(window);
 }
@@ -218,7 +231,20 @@ static void export_filesel_cb(GtkWidget *widget, gpointer data)
        gchar *filename;
 
        filename = filesel_select_file(_("Select exporting file"), NULL);
-       if (filename)
+       if (!filename) return;
+
+       if (g_getenv ("G_BROKEN_FILENAMES")) {
+               const gchar *oldstr = filename;
+               filename = conv_codeset_strdup (filename,
+                                               conv_get_current_charset_str(),
+                                               CS_UTF_8);
+               if (!filename) {
+                       g_warning("export_filesel_cb(): faild to convert character set.");
+                       filename = g_strdup(oldstr);
+               }
+               gtk_entry_set_text(GTK_ENTRY(file_entry), filename);
+               g_free(filename);
+       } else
                gtk_entry_set_text(GTK_ENTRY(file_entry), filename);
 }
 
@@ -237,8 +263,9 @@ static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
        return TRUE;
 }
 
-static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        if (event && event->keyval == GDK_Escape)
                export_cancel_cb(NULL, NULL);
+       return FALSE;
 }