]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilechooser.c
Add the new functions.
[~andy/gtk] / gtk / gtkfilechooser.c
index 6e8f54d32ebe49f00399ea1998f92a4a1cfd2954..ecc4701018f30308f4fb3ad783cbf5c029417400 100644 (file)
  */
 
 #include <config.h>
-#include "gtkalias.h"
 #include "gtkfilechooser.h"
 #include "gtkfilechooserprivate.h"
 #include "gtkfilesystem.h"
 #include "gtkintl.h"
 #include "gtktypebuiltins.h"
+#include "gtkprivate.h"
+#include "gtkmarshalers.h"
+#include "gtkalias.h"
 
 static void gtk_file_chooser_class_init (gpointer g_iface);
 
@@ -55,6 +57,22 @@ gtk_file_chooser_get_type (void)
   return file_chooser_type;
 }
 
+static gboolean
+confirm_overwrite_accumulator (GSignalInvocationHint *ihint,
+                              GValue                *return_accu,
+                              const GValue          *handler_return,
+                              gpointer               dummy)
+{
+  gboolean continue_emission;
+  GtkFileChooserConfirmation conf;
+
+  conf = g_value_get_enum (handler_return);
+  g_value_set_enum (return_accu, conf);
+  continue_emission = (conf == GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM);
+
+  return continue_emission;
+}
+
 static void
 gtk_file_chooser_class_init (gpointer g_iface)
 {
@@ -170,6 +188,15 @@ gtk_file_chooser_class_init (gpointer g_iface)
                NULL, NULL,
                g_cclosure_marshal_VOID__VOID,
                G_TYPE_NONE, 0);
+
+  /* Documented in the docbook files */
+  g_signal_new ("confirm-overwrite",
+               iface_type,
+               G_SIGNAL_RUN_LAST,
+               G_STRUCT_OFFSET (GtkFileChooserIface, confirm_overwrite),
+               confirm_overwrite_accumulator, NULL,
+               _gtk_marshal_ENUM__VOID,
+               GTK_TYPE_FILE_CHOOSER_CONFIRMATION, 0);
   
   g_object_interface_install_property (g_iface,
                                       g_param_spec_enum ("action",
@@ -177,62 +204,71 @@ gtk_file_chooser_class_init (gpointer g_iface)
                                                          P_("The type of operation that the file selector is performing"),
                                                          GTK_TYPE_FILE_CHOOSER_ACTION,
                                                          GTK_FILE_CHOOSER_ACTION_OPEN,
-                                                         G_PARAM_READWRITE));
+                                                         GTK_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_string ("file-system-backend",
                                                            P_("File System Backend"),
                                                            P_("Name of file system backend to use"),
                                                            NULL, 
-                                                           G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+                                                           GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_object ("filter",
                                                            P_("Filter"),
                                                            P_("The current filter for selecting which files are displayed"),
                                                            GTK_TYPE_FILE_FILTER,
-                                                           G_PARAM_READWRITE));
+                                                           GTK_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_boolean ("local-only",
                                                             P_("Local Only"),
                                                             P_("Whether the selected file(s) should be limited to local file: URLs"),
                                                             TRUE,
-                                                            G_PARAM_READWRITE));
+                                                            GTK_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_object ("preview-widget",
                                                            P_("Preview widget"),
                                                            P_("Application supplied widget for custom previews."),
                                                            GTK_TYPE_WIDGET,
-                                                           G_PARAM_READWRITE));
+                                                           GTK_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_boolean ("preview-widget-active",
                                                             P_("Preview Widget Active"),
                                                             P_("Whether the application supplied widget for custom previews should be shown."),
                                                             TRUE,
-                                                            G_PARAM_READWRITE));
+                                                            GTK_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_boolean ("use-preview-label",
                                                             P_("Use Preview Label"),
                                                             P_("Whether to display a stock label with the name of the previewed file."),
                                                             TRUE,
-                                                            G_PARAM_READWRITE));
+                                                            GTK_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_object ("extra-widget",
                                                            P_("Extra widget"),
                                                            P_("Application supplied widget for extra options."),
                                                            GTK_TYPE_WIDGET,
-                                                           G_PARAM_READWRITE));
+                                                           GTK_PARAM_READWRITE));
   g_object_interface_install_property (g_iface,
                                       g_param_spec_boolean ("select-multiple",
                                                             P_("Select Multiple"),
                                                             P_("Whether to allow multiple files to be selected"),
                                                             FALSE,
-                                                            G_PARAM_READWRITE));
+                                                            GTK_PARAM_READWRITE));
   
   g_object_interface_install_property (g_iface,
                                       g_param_spec_boolean ("show-hidden",
                                                             P_("Show Hidden"),
                                                             P_("Whether the hidden files and folders should be displayed"),
                                                             FALSE,
-                                                            G_PARAM_READWRITE));
+                                                            GTK_PARAM_READWRITE));
+
+  g_object_interface_install_property (g_iface,
+                                      g_param_spec_boolean ("do-overwrite-confirmation",
+                                                            P_("Do overwrite confirmation"),
+                                                            P_("Whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE "
+                                                               "will present an overwrite confirmation dialog if the user "
+                                                               "selects a file name that already exists."),
+                                                            FALSE,
+                                                            GTK_PARAM_READWRITE));
 }
 
 /**
@@ -1741,7 +1777,7 @@ gtk_file_chooser_remove_shortcut_folder_uri (GtkFileChooser    *chooser,
   g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
   g_return_val_if_fail (uri != NULL, FALSE);
 
-  path = gtk_file_system_filename_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
+  path = gtk_file_system_uri_to_path (_gtk_file_chooser_get_file_system (chooser), uri);
   if (!path)
     {
       g_set_error (error,
@@ -1831,6 +1867,58 @@ gtk_file_chooser_get_show_hidden (GtkFileChooser *chooser)
   return show_hidden;
 }
 
+/**
+ * gtk_file_chooser_set_do_overwrite_confirmation:
+ * @chooser: a #GtkFileChooser
+ * @do_overwrite_confirmation: whether to confirm overwriting in save mode
+ * 
+ * Sets whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode will present
+ * a confirmation dialog if the user types a file name that already exists.  This
+ * is %FALSE by default.
+ *
+ * Regardless of this setting, the @chooser will emit the "confirm-overwrite"
+ * signal when appropriate.
+ *
+ * If all you need is the stock confirmation dialog, set this property to %TRUE.
+ * You can override the way confirmation is done by actually handling the
+ * "confirm-overwrite" signal; please refer to its documentation for the
+ * details.
+ *
+ * Since: 2.8
+ **/
+void
+gtk_file_chooser_set_do_overwrite_confirmation (GtkFileChooser *chooser,
+                                               gboolean        do_overwrite_confirmation)
+{
+  g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
+
+  g_object_set (chooser, "do-overwrite-confirmation", do_overwrite_confirmation, NULL);
+}
+
+/**
+ * gtk_file_chooser_get_do_overwrite_confirmation:
+ * @chooser: a #GtkFileChooser
+ * 
+ * Queries whether a file chooser is set to confirm for overwriting when the user
+ * types a file name that already exists.
+ * 
+ * Return value: %TRUE if the file chooser will present a confirmation dialog;
+ * %FALSE otherwise.
+ *
+ * Since: 2.8
+ **/
+gboolean
+gtk_file_chooser_get_do_overwrite_confirmation (GtkFileChooser *chooser)
+{
+  gboolean do_overwrite_confirmation;
+
+  g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), FALSE);
+
+  g_object_get (chooser, "do-overwrite-confirmation", &do_overwrite_confirmation, NULL);
+
+  return do_overwrite_confirmation;
+}
+
 #ifdef G_OS_WIN32
 
 /* DLL ABI stability backward compatibility versions */
@@ -1999,3 +2087,6 @@ gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
 }
 
 #endif
+
+#define __GTK_FILE_CHOOSER_C__
+#include "gtkaliasdef.c"