2011-04-08 [colin] 3.7.8cvs73
[claws.git] / src / gtk / filesel.c
index fc2a318deb8c425078312b4f17039c7710b49237..a511aabf142ba88e4476e4c7985a128709b40003 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto 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,8 @@
  * 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/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
 
 #include <glib.h>
 #include <gdk/gdkkeysyms.h>
-#include <gtk/gtkwidget.h>
-#include <gtk/gtkfilesel.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkmain.h>
-#include <gtk/gtksignal.h>
-#include <gtk/gtkeditable.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtkdialog.h>
-#include <gtk/gtkfilechooser.h>
-#include <gtk/gtkfilechooserdialog.h>
+#include <gtk/gtk.h>
 
 #ifdef MAEMO
+#ifdef CHINOOK
+#include <hildon/hildon-file-chooser-dialog.h>
+#else
 #include <hildon-widgets/hildon-file-chooser-dialog.h>
 #endif
+#endif
 
 #include "claws.h"
 #include "filesel.h"
@@ -73,7 +68,7 @@ update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
        if (pixbuf) {
                have_preview = TRUE;
                gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
-               gdk_pixbuf_unref (pixbuf);
+               g_object_unref(G_OBJECT(pixbuf));
        }
 
        gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
@@ -97,22 +92,43 @@ static GList *filesel_create(const gchar *title, const gchar *path,
 #ifdef MAEMO
        GtkWidget *chooser;
        if( path && strcmp(path, get_plugin_dir()) == 0 ) {
+#if !GTK_CHECK_VERSION(2,14,0)
                chooser = gtk_file_chooser_dialog_new_with_backend
                                        (title, NULL, action, "gtk+",
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        action_btn, GTK_RESPONSE_ACCEPT, 
                                        NULL);
+#else
+               chooser = gtk_file_chooser_dialog_new
+                                       (title, NULL, action,
+                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                       action_btn, GTK_RESPONSE_ACCEPT, 
+                                       NULL);
+#endif
        }
        else {
                chooser = hildon_file_chooser_dialog_new (NULL, action);
        }
 #else
+#if !GTK_CHECK_VERSION(2,14,0)
        GtkWidget *chooser = gtk_file_chooser_dialog_new_with_backend
                                (title, NULL, action, "gtk+",
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                action_btn, GTK_RESPONSE_ACCEPT, 
                                NULL);
+#else
+       GtkWidget *chooser = gtk_file_chooser_dialog_new
+                               (title, NULL, action, 
+                               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                               action_btn, GTK_RESPONSE_ACCEPT, 
+                               NULL);
+#endif
+#endif
+
+#if GLIB_CHECK_VERSION(2,16,0)
+       gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(chooser), FALSE);
 #endif
+
        if (filter != NULL) {
                GtkFileFilter *file_filter = gtk_file_filter_new();
                gtk_file_filter_add_pattern(file_filter, filter);
@@ -152,21 +168,13 @@ static GList *filesel_create(const gchar *title, const gchar *path,
                        g_free(realpath); 
                        realpath = g_strdup(get_home_dir());
                }
-               tmp = NULL;
                if (g_utf8_validate(realpath, -1, NULL))
-                       tmp = g_filename_from_utf8(realpath, -1, NULL, NULL, NULL);
-               if (tmp == NULL)
-                       tmp = g_strdup(realpath);
-               gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), tmp);
-               g_free(tmp);
+                       gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),
+                                                           realpath);
                if (action == GTK_FILE_CHOOSER_ACTION_SAVE) {
-                       tmp = NULL;
                        if (g_utf8_validate(filename, -1, NULL))
-                               tmp = g_filename_from_utf8(filename, -1, NULL, NULL, NULL);
-                       if (tmp == NULL)
-                               tmp = g_strdup(filename);
-                       gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser), tmp);
-                       g_free(tmp);
+                               gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser),
+                                                                 filename);
                }
                g_free(realpath);
        } else {