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

Jannis Pohlmann jannis at xfce.org
Sun Apr 12 01:04:06 CEST 2009


Author: jannis
Date: 2009-04-11 23:04:06 +0000 (Sat, 11 Apr 2009)
New Revision: 29772

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   thunar/branches/migration-to-gio/thunar/thunar-file.c
   thunar/branches/migration-to-gio/thunar/thunar-file.h
   thunar/branches/migration-to-gio/thunar/thunar-list-model.c
Log:
	* thunar/thunar-file.{c,h}: Add new or re-implement the functions or
	  macros thunar_file_get_content_type(),
	  thunar_file_get_symlink_target(), thunar_file_get_basename(),
	  thunar_file_is_symlink(), thunar_file_get_size() based on GIO.
	* thunar/thunar-list-model.c: Re-implement
	  thunar_list_model_get_value() based on the new/changed functions.
	  Same goes for sort_by_file_name(), sort_by_mime_type(),
	  sort_by_type() and thunar_list_model_get_statusbar_text() which are
	  almost ThunarVFS-free now.

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-11 22:04:43 UTC (rev 29771)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-11 23:04:06 UTC (rev 29772)
@@ -1,5 +1,17 @@
 2009-04-12	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-file.{c,h}: Add new or re-implement the functions or
+	  macros thunar_file_get_content_type(), 
+	  thunar_file_get_symlink_target(), thunar_file_get_basename(), 
+	  thunar_file_is_symlink(), thunar_file_get_size() based on GIO.
+	* thunar/thunar-list-model.c: Re-implement
+	  thunar_list_model_get_value() based on the new/changed functions.
+	  Same goes for sort_by_file_name(), sort_by_mime_type(),
+	  sort_by_type() and thunar_list_model_get_statusbar_text() which are
+	  almost ThunarVFS-free now.
+
+2009-04-12	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-path-entry.c: Re-implement
 	  thunar_path_entry_drag_data_get(), thunar_path_entry_changed() and
 	  thunar_path_entry_set_current_file() with GFile. file:// URI

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-11 22:04:43 UTC (rev 29771)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-11 23:04:06 UTC (rev 29772)
@@ -1453,6 +1453,98 @@
 
 
 /**
+ * thunar_file_get_content_type:
+ * @file : a #ThunarFile.
+ *
+ * Returns the content type of @file.
+ *
+ * Return value: content type of @file.
+ **/
+const gchar *
+thunar_file_get_content_type (const ThunarFile *file)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->ginfo), NULL);
+  return g_file_info_get_content_type (file->ginfo);
+}
+
+
+
+/**
+ * thunar_file_get_symlink_target:
+ * @file : a #ThunarFile.
+ *
+ * Returns the path of the symlink target or %NULL if the @file
+ * is not a symlink.
+ *
+ * Return value: path of the symlink target or %NULL.
+ **/
+const gchar *
+thunar_file_get_symlink_target (const ThunarFile *file)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->ginfo), NULL);
+  return g_file_info_get_symlink_target (file->ginfo);
+}
+
+
+
+/**
+ * thunar_file_get_basename:
+ * @file : a #ThunarFile.
+ *
+ * Returns the basename of the @file in UTF-8 encoding.
+ *
+ * Return value: UTF-8 encoded basename of the @file.
+ **/
+const gchar *
+thunar_file_get_basename (const ThunarFile *file)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->ginfo), NULL);
+  return g_file_info_get_name (file->ginfo);
+}
+
+
+
+/**
+ * thunar_file_is_symlink:
+ * @file : a #ThunarFile.
+ *
+ * Returns %TRUE if @file is a symbolic link.
+ *
+ * Return value: %TRUE if @file is a symbolic link.
+ **/
+gboolean 
+thunar_file_is_symlink (const ThunarFile *file) 
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->ginfo), FALSE);
+  return g_file_info_get_is_symlink (file->ginfo);
+}
+
+
+
+/**
+ * thunar_file_get_size:
+ * @file : a #ThunarFile instance.
+ *
+ * Tries to determine the size of @file in bytes and
+ * returns the size.
+ *
+ * Return value: the size of @file in bytes.
+ **/
+guint64
+thunar_file_get_size (const ThunarFile *file)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_FILE (file), 0);
+  _thunar_return_val_if_fail (G_IS_FILE_INFO (file->ginfo), 0);
+  return g_file_info_get_size (file->ginfo);
+}
+
+
+
+/**
  * thunar_file_get_deletion_date:
  * @file       : a #ThunarFile instance.
  * @date_style : the style used to format the date.

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-11 22:04:43 UTC (rev 29771)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-11 23:04:06 UTC (rev 29772)
@@ -193,6 +193,12 @@
 ThunarGroup      *thunar_file_get_group            (const ThunarFile       *file);
 ThunarUser       *thunar_file_get_user             (const ThunarFile       *file);
 
+const gchar      *thunar_file_get_content_type     (const ThunarFile       *file);
+const gchar      *thunar_file_get_symlink_target   (const ThunarFile       *file);
+const gchar      *thunar_file_get_basename         (const ThunarFile       *file);
+gboolean          thunar_file_is_symlink           (const ThunarFile       *file);
+guint64           thunar_file_get_size             (const ThunarFile       *file);
+
 gchar            *thunar_file_get_deletion_date    (const ThunarFile       *file,
                                                     ThunarDateStyle         date_style) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
 gchar            *thunar_file_get_original_path    (const ThunarFile       *file) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
@@ -357,17 +363,6 @@
 #define thunar_file_get_mode(file) (THUNAR_FILE ((file))->info->mode)
 
 /**
- * thunar_file_get_size:
- * @file : a #ThunarFile instance.
- *
- * Tries to determine the size of @file in bytes and
- * returns the size.
- *
- * Return value: the size of @file in bytes.
- **/
-#define thunar_file_get_size(file) (THUNAR_FILE ((file))->info->size)
-
-/**
  * thunar_file_get_free_space:
  * @file              : a #ThunarFile instance.
  * @free_space_return : return location for the amount of
@@ -536,16 +531,6 @@
 #define thunar_file_is_regular(file) (THUNAR_FILE ((file))->info->type == THUNAR_VFS_FILE_TYPE_REGULAR)
 
 /**
- * thunar_file_is_symlink:
- * @file : a #ThunarFile.
- *
- * Returns %TRUE if @file is a symbolic link.
- *
- * Return value: %TRUE if @file is a symbolic link.
- **/
-#define thunar_file_is_symlink(file) ((THUNAR_FILE ((file))->info->flags & THUNAR_VFS_FILE_FLAGS_SYMLINK) != 0)
-
-/**
  * thunar_file_is_desktop_file:
  * @file : a #ThunarFile.
  *

Modified: thunar/branches/migration-to-gio/thunar/thunar-list-model.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-list-model.c	2009-04-11 22:04:43 UTC (rev 29771)
+++ thunar/branches/migration-to-gio/thunar/thunar-list-model.c	2009-04-11 23:04:06 UTC (rev 29772)
@@ -699,13 +699,12 @@
                              gint          column,
                              GValue       *value)
 {
-  ThunarVfsMimeInfo *mime_info;
-  ThunarGroup       *group;
-  ThunarUser        *user;
-  const gchar       *name;
-  const gchar       *real_name;
-  ThunarFile        *file;
-  gchar             *str;
+  ThunarGroup *group;
+  ThunarUser  *user;
+  const gchar *name;
+  const gchar *real_name;
+  ThunarFile  *file;
+  gchar       *str;
 
   _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model));
   _thunar_return_if_fail (iter->stamp == (THUNAR_LIST_MODEL (model))->stamp);
@@ -742,8 +741,7 @@
 
     case THUNAR_COLUMN_MIME_TYPE:
       g_value_init (value, G_TYPE_STRING);
-      mime_info = thunar_file_get_mime_info (file);
-      g_value_set_static_string (value, thunar_vfs_mime_info_get_name (mime_info));
+      g_value_set_static_string (value, thunar_file_get_content_type (file));
       break;
 
     case THUNAR_COLUMN_NAME:
@@ -781,13 +779,10 @@
 
     case THUNAR_COLUMN_TYPE:
       g_value_init (value, G_TYPE_STRING);
-      mime_info = thunar_file_get_mime_info (file);
-      if (G_UNLIKELY (strcmp (thunar_vfs_mime_info_get_name (mime_info), "inode/symlink") == 0))
-        g_value_set_static_string (value, _("broken link"));
-      else if (G_UNLIKELY (thunar_file_is_symlink (file)))
-        g_value_take_string (value, g_strdup_printf (_("link to %s"), thunar_vfs_mime_info_get_comment (mime_info)));
+      if (G_UNLIKELY (thunar_file_is_symlink (file)))
+        g_value_take_string (value, g_strdup_printf (_("link to %s"), thunar_file_get_symlink_target (file)));
       else
-        g_value_set_static_string (value, thunar_vfs_mime_info_get_comment (mime_info));
+        g_value_take_string (value, g_content_type_get_description (thunar_file_get_content_type (file)));
       break;
 
     case THUNAR_COLUMN_FILE:
@@ -797,7 +792,7 @@
 
     case THUNAR_COLUMN_FILE_NAME:
       g_value_init (value, G_TYPE_STRING);
-      g_value_take_string (value, g_filename_display_name (thunar_vfs_path_get_name (thunar_file_get_path (file))));
+      g_value_set_static_string (value, thunar_file_get_basename (file));
       break;
 
     default:
@@ -1464,8 +1459,8 @@
                    const ThunarFile *b,
                    gboolean          case_sensitive)
 {
-  const gchar *a_name = thunar_vfs_path_get_name (thunar_file_get_path (a));
-  const gchar *b_name = thunar_vfs_path_get_name (thunar_file_get_path (b));
+  const gchar *a_name = thunar_file_get_display_name (a);
+  const gchar *b_name = thunar_file_get_display_name (b);
 
   if (G_UNLIKELY (!case_sensitive))
     return strcasecmp (a_name, b_name);
@@ -1495,15 +1490,14 @@
                    const ThunarFile *b,
                    gboolean          case_sensitive)
 {
-  const ThunarVfsMimeInfo *info_a;
-  const ThunarVfsMimeInfo *info_b;
-  gint                     result;
+  const gchar *content_type_a;
+  const gchar *content_type_b;
+  gint         result;
 
-  info_a = thunar_file_get_mime_info (a);
-  info_b = thunar_file_get_mime_info (b);
+  content_type_a = thunar_file_get_content_type (a);
+  content_type_b = thunar_file_get_content_type (b);
 
-  result = strcasecmp (thunar_vfs_mime_info_get_name (info_a),
-                       thunar_vfs_mime_info_get_name (info_b));
+  result = strcasecmp (content_type_a, content_type_b);
 
   if (result == 0)
     result = sort_by_name (a, b, case_sensitive);
@@ -1585,16 +1579,20 @@
               const ThunarFile *b,
               gboolean          case_sensitive)
 {
-  ThunarVfsMimeInfo *info_a;
-  ThunarVfsMimeInfo *info_b;
-  gint               result;
+  const gchar *content_type_a;
+  const gchar *content_type_b;
+  gchar       *description_a;
+  gchar       *description_b;
+  gint         result;
 
-  info_a = thunar_file_get_mime_info (a);
-  info_b = thunar_file_get_mime_info (b);
+  content_type_a = thunar_file_get_content_type (a);
+  content_type_b = thunar_file_get_content_type (a);
 
-  result = strcasecmp (thunar_vfs_mime_info_get_comment (info_a),
-                       thunar_vfs_mime_info_get_comment (info_b));
+  description_a = g_content_type_get_description (content_type_a);
+  description_b = g_content_type_get_description (content_type_b);
 
+  result = strcasecmp (description_a, description_b);
+
   if (result == 0)
     result = sort_by_name (a, b, case_sensitive);
 
@@ -2202,7 +2200,6 @@
 thunar_list_model_get_statusbar_text (ThunarListModel *store,
                                       GList           *selected_items)
 {
-  ThunarVfsMimeInfo *mime_info;
   ThunarVfsFileSize  size_summary;
   ThunarVfsFileSize  size;
   GtkTreeIter        iter;
@@ -2230,7 +2227,7 @@
       if (G_LIKELY (file != NULL && thunar_file_get_free_space (file, &size)))
         {
           /* humanize the free space */
-          fspace_string = thunar_vfs_humanize_size (size, NULL, 0);
+          fspace_string = g_file_size_humanize (size);
 
           /* check if we have atleast one file in this folder */
           if (G_LIKELY (store->nrows > 0))
@@ -2240,7 +2237,7 @@
                 size_summary += thunar_file_get_size (row->data);
 
               /* humanize the size summary */
-              size_string = thunar_vfs_humanize_size (size_summary, NULL, 0);
+              size_string = g_file_size_humanize (size_summary);
 
               /* generate a text which includes the size of all items in the folder */
               text = g_strdup_printf (ngettext ("%d item (%s), Free space: %s", "%d items (%s), Free space: %s", store->nrows),
@@ -2272,21 +2269,24 @@
       file = THUNAR_FILE (G_SLIST (iter.user_data)->data);
 
       /* calculate the text to be displayed */
-      mime_info = thunar_file_get_mime_info (file);
       size_string = thunar_file_get_size_string (file);
-      if (G_UNLIKELY (strcmp (thunar_vfs_mime_info_get_name (mime_info), "inode/symlink") == 0))
+      if (G_UNLIKELY (g_str_equal (thunar_file_get_content_type (file), "inode/symlink")))
         {
           text = g_strdup_printf (_("\"%s\" broken link"), thunar_file_get_display_name (file));
         }
       else if (G_UNLIKELY (thunar_file_is_symlink (file)))
         {
           text = g_strdup_printf (_("\"%s\" (%s) link to %s"), thunar_file_get_display_name (file),
-                                  size_string, thunar_vfs_mime_info_get_comment (mime_info));
+                                  size_string, thunar_file_get_symlink_target (file));
         }
       else
         {
+          gchar *description;
+          
+          description = g_content_type_get_description (thunar_file_get_content_type (file));
           text = g_strdup_printf (_("\"%s\" (%s) %s"), thunar_file_get_display_name (file),
-                                  size_string, thunar_vfs_mime_info_get_comment (mime_info));
+                                  size_string, description);
+          g_free (description);
         }
       g_free (size_string);
 
@@ -2304,8 +2304,9 @@
       else if (thunar_file_is_local (file) && thunar_file_is_regular (file))
         {
           /* check if we can determine the dimension of this file (only for image files) */
-          absolute_path = thunar_vfs_path_dup_string (thunar_file_get_path (file));
-          if (gdk_pixbuf_get_file_info (absolute_path, &width, &height) != NULL)
+          absolute_path = g_file_get_path (thunar_file_get_file (file));
+          if (absolute_path != NULL
+              && gdk_pixbuf_get_file_info (absolute_path, &width, &height) != NULL)
             {
               /* append the image dimensions to the statusbar text */
               s = g_strdup_printf ("%s, %s %dx%d", text, _("Image Size:"), width, height);
@@ -2326,7 +2327,7 @@
 
       if (size_summary > 0)
         {
-          size_string = thunar_vfs_humanize_size (size_summary, NULL, 0);
+          size_string = g_file_size_humanize (size_summary);
           text = g_strdup_printf (ngettext ("%d item selected (%s)", "%d items selected (%s)", n), n, size_string);
           g_free (size_string);
         }




More information about the Xfce4-commits mailing list