replace deprecated gtk_window_set_policy
[claws.git] / src / export.c
index 6a5f5c19c5e9ac2a3622e7ccf95cf1974c7f41b0..bc73c9dd1cb4a3a8f16dca490d45340939553c92 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto
  *
  * 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
@@ -38,6 +38,7 @@
 #include <gtk/gtksignal.h>
 
 #include "intl.h"
+#include "sylpheed.h"
 #include "main.h"
 #include "inc.h"
 #include "mbox.h"
@@ -47,6 +48,7 @@
 #include "manage_window.h"
 #include "folder.h"
 #include "utils.h"
+#include "codeconv.h"
 
 static GtkWidget *window;
 static GtkWidget *src_entry;
@@ -63,22 +65,27 @@ 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)
 {
        gint ok = 0;
+       gchar *src_id = NULL;
 
        if (!window)
                export_create();
        else
                gtk_widget_show(window);
 
-       change_dir(startup_dir);
+       change_dir(sylpheed_get_startup_dir());
 
        if (default_src && default_src->path)
-               gtk_entry_set_text(GTK_ENTRY(src_entry), default_src->path);
-       else
+               src_id = folder_item_get_identifier(default_src);
+
+       if (src_id) {
+               gtk_entry_set_text(GTK_ENTRY(src_entry), src_id);
+               g_free(src_id);
+       } else
                gtk_entry_set_text(GTK_ENTRY(src_entry), "");
        gtk_entry_set_text(GTK_ENTRY(file_entry), "");
        gtk_widget_grab_focus(file_entry);
@@ -88,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));
-
-               if (mbox && *mbox) {
-                       src = folder_find_item_from_path(srcdir);
+               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);
+                       }
+
+                       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);
                }
        }
 
@@ -118,20 +137,17 @@ 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);
-       gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
-                          GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
-       gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
-                          GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
+       gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
+       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);
        gtk_container_add(GTK_CONTAINER(window), vbox);
@@ -149,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,
@@ -172,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"),
@@ -188,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);
 }
@@ -214,8 +230,21 @@ static void export_filesel_cb(GtkWidget *widget, gpointer data)
 {
        gchar *filename;
 
-       filename = filesel_select_file(_("Select exporting file"), NULL);
-       if (filename)
+       filename = filesel_select_file_save(_("Select exporting file"), NULL);
+       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);
 }
 
@@ -234,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;
 }