[Xfce4-commits] r29795 - in thunar/branches/migration-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Mon Apr 13 17:00:58 CEST 2009


Author: jannis
Date: 2009-04-13 15:00:58 +0000 (Mon, 13 Apr 2009)
New Revision: 29795

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c
   thunar/branches/migration-to-gio/thunar/thunar-path-entry.c
   thunar/branches/migration-to-gio/thunar/thunar-renamer-model.c
   thunar/branches/migration-to-gio/thunar/thunar-util.c
   thunar/branches/migration-to-gio/thunar/thunar-util.h
Log:
	* thunar/thunar-icon-factory.c: Replace ThunarVfsFileTime with
	  guint64.
	* thunar/thunar-path-entry.c, thunar/thunar-util.{c,h}: Replace
	  thunar_vfs_expand_filename() with thunar_util_expand_filename().
	* thunar/thunar-renamer-model.c: Use GFile instead of ThunarVfsPath in
	  trm_same_directory().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-13 11:37:18 UTC (rev 29794)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-13 15:00:58 UTC (rev 29795)
@@ -1,5 +1,14 @@
 2009-04-13	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-icon-factory.c: Replace ThunarVfsFileTime with
+	  guint64.
+	* thunar/thunar-path-entry.c, thunar/thunar-util.{c,h}: Replace
+	  thunar_vfs_expand_filename() with thunar_util_expand_filename().
+	* thunar/thunar-renamer-model.c: Use GFile instead of ThunarVfsPath in
+	  trm_same_directory(). 
+
+2009-04-13	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-permissions-chooser.c: Rename all occurances of
 	  ThunarVfsFileMode to ThunarFileMode.
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c	2009-04-13 11:37:18 UTC (rev 29794)
+++ thunar/branches/migration-to-gio/thunar/thunar-icon-factory.c	2009-04-13 15:00:58 UTC (rev 29795)
@@ -921,12 +921,12 @@
                                     gint                icon_size)
 {
   ThunarFileThumbState thumb_state;
-  ThunarVfsFileTime    time;
   ThunarVfsInfo       *info;
   ThunarVfsPath       *path;
   ThunarIconKey        key;
+  GdkPixbuf           *icon;
+  guint64              time;
   gchar               *icon_name;
-  GdkPixbuf           *icon;
   gchar               *thumb_path;
 
   _thunar_return_val_if_fail (THUNAR_IS_ICON_FACTORY (factory), NULL);

Modified: thunar/branches/migration-to-gio/thunar/thunar-path-entry.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-path-entry.c	2009-04-13 11:37:18 UTC (rev 29794)
+++ thunar/branches/migration-to-gio/thunar/thunar-path-entry.c	2009-04-13 15:00:58 UTC (rev 29795)
@@ -1257,7 +1257,7 @@
   _thunar_return_val_if_fail (file_part != NULL, FALSE);
 
   /* expand the filename */
-  filename = thunar_vfs_expand_filename (gtk_entry_get_text (GTK_ENTRY (path_entry)), error);
+  filename = thunar_util_expand_filename (gtk_entry_get_text (GTK_ENTRY (path_entry)), error);
   if (G_UNLIKELY (filename == NULL))
     return FALSE;
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-renamer-model.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-renamer-model.c	2009-04-13 11:37:18 UTC (rev 29794)
+++ thunar/branches/migration-to-gio/thunar/thunar-renamer-model.c	2009-04-13 15:00:58 UTC (rev 29795)
@@ -1,6 +1,7 @@
 /* $Id$ */
 /*-
  * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
  *
  * 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
@@ -753,15 +754,15 @@
 trm_same_directory (ThunarFile *a,
                     ThunarFile *b)
 {
-  ThunarVfsPath *parent_a;
-  ThunarVfsPath *parent_b;
+  GFile *parent_a;
+  GFile *parent_b;
 
   /* determine the parent paths for both files */
-  parent_a = thunar_vfs_path_get_parent (thunar_file_get_path (a));
-  parent_b = thunar_vfs_path_get_parent (thunar_file_get_path (b));
+  parent_a = g_file_get_parent (thunar_file_get_file (a));
+  parent_b = g_file_get_parent (thunar_file_get_file (b));
 
   /* check if both files have the same parent */
-  return (parent_a != NULL && parent_b != NULL && thunar_vfs_path_equal (parent_a, parent_b));
+  return (parent_a != NULL && parent_b != NULL && g_file_equal (parent_a, parent_b));
 }
 
 

Modified: thunar/branches/migration-to-gio/thunar/thunar-util.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-util.c	2009-04-13 11:37:18 UTC (rev 29794)
+++ thunar/branches/migration-to-gio/thunar/thunar-util.c	2009-04-13 15:00:58 UTC (rev 29795)
@@ -1,6 +1,7 @@
 /* $Id$ */
 /*-
  * Copyright (c) 2006-2007 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
  *
  * 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
@@ -21,9 +22,16 @@
 #include <config.h>
 #endif
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
 #ifdef HAVE_MEMORY_H
 #include <memory.h>
 #endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
@@ -70,6 +78,85 @@
 
 
 /**
+ * thunar_util_expand_filename:
+ * @filename : a local filename.
+ * @error    : return location for errors or %NULL.
+ *
+ * Takes a user-typed @filename and expands a tilde at the
+ * beginning of the @filename.
+ *
+ * The caller is responsible to free the returned string using
+ * g_free() when no longer needed.
+ *
+ * Return value: the expanded @filename or %NULL on error.
+ **/
+gchar *
+thunar_util_expand_filename (const gchar  *filename,
+                             GError      **error)
+{
+  struct passwd *passwd;
+  const gchar   *replacement;
+  const gchar   *remainder;
+  const gchar   *slash;
+  gchar         *username;
+
+  g_return_val_if_fail (filename != NULL, NULL);
+
+  /* check if we have a valid (non-empty!) filename */
+  if (G_UNLIKELY (*filename == '\0'))
+    {
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, _("Invalid path"));
+      return NULL;
+    }
+
+  /* check if we start with a '~' */
+  if (G_LIKELY (*filename != '~'))
+    return g_strdup (filename);
+
+  /* examine the remainder of the filename */
+  remainder = filename + 1;
+
+  /* if we have only the slash, then we want the home dir */
+  if (G_UNLIKELY (*remainder == '\0'))
+    return g_strdup (xfce_get_homedir ());
+
+  /* lookup the slash */
+  for (slash = remainder; *slash != '\0' && *slash != G_DIR_SEPARATOR; ++slash)
+    ;
+
+  /* check if a username was given after the '~' */
+  if (G_LIKELY (slash == remainder))
+    {
+      /* replace the tilde with the home dir */
+      replacement = xfce_get_homedir ();
+    }
+  else
+    {
+      /* lookup the pwd entry for the username */
+      username = g_strndup (remainder, slash - remainder);
+      passwd = getpwnam (username);
+      g_free (username);
+
+      /* check if we have a valid entry */
+      if (G_UNLIKELY (passwd == NULL))
+        {
+          username = g_strndup (remainder, slash - remainder);
+          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, _("Unknown user \"%s\""), username);
+          g_free (username);
+          return NULL;
+        }
+
+      /* use the homedir of the specified user */
+      replacement = passwd->pw_dir;
+    }
+
+  /* generate the filename */
+  return g_build_filename (replacement, slash, NULL);
+}
+
+
+
+/**
  * thunar_util_humanize_file_time:
  * @file_time   : a #ThunarVfsFileTime.
  * @date_format : the #ThunarDateFormat used to humanize the @file_time.

Modified: thunar/branches/migration-to-gio/thunar/thunar-util.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-util.h	2009-04-13 11:37:18 UTC (rev 29794)
+++ thunar/branches/migration-to-gio/thunar/thunar-util.h	2009-04-13 15:00:58 UTC (rev 29795)
@@ -1,6 +1,7 @@
 /* $Id$ */
 /*-
  * Copyright (c) 2006-2007 Benedikt Meurer <benny at xfce.org>
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
  *
  * 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
@@ -28,6 +29,9 @@
 
 gboolean   thunar_util_looks_like_an_uri  (const gchar      *string) G_GNUC_INTERNAL G_GNUC_WARN_UNUSED_RESULT;
 
+gchar     *thunar_util_expand_filename    (const gchar      *filename,
+                                           GError          **error);
+
 gchar     *thunar_util_humanize_file_time (ThunarVfsFileTime file_time,
                                            ThunarDateStyle   date_style) G_GNUC_INTERNAL G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 




More information about the Xfce4-commits mailing list