]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfilesystem.c
Revert the patch to #137520, as 2.4.1 is for conservative bug fixes only.
[~andy/gtk] / gtk / gtkfilesystem.c
index 8be7443bbfd395e783441af37884550ed94f8081..4f176f6fe239125c7c0d0e2ba7eec0917b3a6bb8 100644 (file)
@@ -18,6 +18,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
 #include <gmodule.h>
 #include "gtkfilesystem.h"
 #include "gtkicontheme.h"
@@ -145,6 +146,9 @@ gtk_file_info_set_display_name (GtkFileInfo *info,
 {
   g_return_if_fail (info != NULL);
 
+  if (display_name == info->display_name)
+    return;
+
   if (info->display_name)
     g_free (info->display_name);
   if (info->display_key)
@@ -340,9 +344,12 @@ gtk_file_system_create_folder(GtkFileSystem     *file_system,
  * @path: a #GtkFilePath
  * 
  * Queries the file system volume that corresponds to a specific path.
+ * There might not be a volume for all paths (consinder for instance remote
+ * shared), so this can return NULL.
  * 
  * Return value: the #GtkFileSystemVolume that corresponds to the specified
- * @path.  You should free this value with gtk_file_system_volume_free().
+ * @path, or NULL if there is no such volume. You should free this value with
+ * gtk_file_system_volume_free().
  **/
 GtkFileSystemVolume *
 gtk_file_system_get_volume_for_path (GtkFileSystem     *file_system,
@@ -497,12 +504,13 @@ gtk_file_system_volume_render_icon (GtkFileSystem        *file_system,
  * @parent: location to store parent path name
  * @error: location to store error, or %NULL
  * 
- * Gets the name of the parent folder of a file.
+ * Gets the name of the parent folder of a path.  If the path has no parent, as when
+ * you request the parent of a file system root, then @parent will be set to %NULL.
  * 
- * Return value: TRUE if the operation was successful; note that in this case @parent
- * can be returned as %NULL if the base @path has no parent folder (i.e. if it is
- * already a file system root).  If the operation fails, this function returns FALSE
- * and sets the @error value if it is specified.
+ * Return value: %TRUE if the operation was successful:  @parent will be set to
+ * the name of the @path's parent, or to %NULL if @path is already a file system
+ * root.  If the operation fails, this function returns %FALSE, sets @parent to
+ * NULL, and sets the @error value if it is specified.
  **/
 gboolean
 gtk_file_system_get_parent (GtkFileSystem     *file_system,
@@ -510,21 +518,18 @@ gtk_file_system_get_parent (GtkFileSystem     *file_system,
                            GtkFilePath      **parent,
                            GError           **error)
 {
-  GtkFilePath *tmp_parent = NULL;
   gboolean result;
   
   g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
   g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (parent != NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_parent (file_system, path, &tmp_parent, error);
-  g_assert (result || tmp_parent == NULL);
+  *parent = NULL;
+
+  result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->get_parent (file_system, path, parent, error);
+  g_assert (result || *parent == NULL);
 
-  if (parent)
-    *parent = tmp_parent;
-  else
-    gtk_file_path_free (tmp_parent);
-  
   return result;
 }
 
@@ -649,6 +654,33 @@ gtk_file_system_filename_to_path (GtkFileSystem *file_system,
   return GTK_FILE_SYSTEM_GET_IFACE (file_system)->filename_to_path (file_system, filename);
 }
 
+/**
+ * gtk_file_system_path_is_local:
+ * @filesystem: a #GtkFileSystem
+ * @path: A #GtkFilePath from that filesystem
+ * 
+ * Checks whether a #GtkFilePath is local; that is whether
+ * gtk_file_system_path_to_filename would return non-%NULL.
+ * 
+ * Return value: %TRUE if the path is loca
+ **/
+gboolean
+gtk_file_system_path_is_local (GtkFileSystem     *file_system,
+                              const GtkFilePath *path)
+{
+  gchar *filename;
+  gboolean result;
+    
+  g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
+  g_return_val_if_fail (path != NULL, FALSE);
+
+  filename = gtk_file_system_path_to_filename (file_system, path);
+  result = filename != NULL;
+  g_free (filename);
+
+  return result;
+}
+
 GdkPixbuf *
 gtk_file_system_render_icon (GtkFileSystem      *file_system,
                             const GtkFilePath  *path,
@@ -839,12 +871,44 @@ gtk_file_folder_get_info (GtkFileFolder     *folder,
                          GError           **error)
 {
   g_return_val_if_fail (GTK_IS_FILE_FOLDER (folder), NULL);
-  g_return_val_if_fail (path != NULL, NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
   return GTK_FILE_FOLDER_GET_IFACE (folder)->get_info (folder, path, error);
 }
 
+
+/*****************************************
+ *         GtkFilePath modules           *
+ *****************************************/
+
+/* We make these real functions in case either copy or free are implemented as macros
+ */
+static gpointer
+gtk_file_path_real_copy (gpointer boxed)
+{
+  return gtk_file_path_copy ((GtkFilePath *) boxed);
+}
+
+static void
+gtk_file_path_real_free        (gpointer boxed)
+{
+  gtk_file_path_free (boxed);
+}
+
+GType
+gtk_file_path_get_type (void)
+{
+  static GType our_type = 0;
+  
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static ("GtkFilePath",
+                                            (GBoxedCopyFunc) gtk_file_path_real_copy,
+                                            (GBoxedFreeFunc) gtk_file_path_real_free);
+
+  return our_type;
+}
+
+
 GSList *
 gtk_file_paths_sort (GSList *paths)
 {