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

Jannis Pohlmann jannis at xfce.org
Sat Apr 11 01:14:50 CEST 2009


Author: jannis
Date: 2009-04-10 23:14:49 +0000 (Fri, 10 Apr 2009)
New Revision: 29760

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-gio-extensions.c
Log:
	* thunar/thunar-file.{c,h}: Re-implement thunar_file_get_parent(),
	  thunar_file_launch(), thunar_file_is_root() and
	  thunar_file_has_parent() based on GFile/GFileInfo/GAppInfo.
	* thunar/thunar-gio-extensions.c: Fix problem in g_file_is_root().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-10 22:31:19 UTC (rev 29759)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-10 23:14:49 UTC (rev 29760)
@@ -1,5 +1,12 @@
 2009-04-11	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-file.{c,h}: Re-implement thunar_file_get_parent(), 
+	  thunar_file_launch(), thunar_file_is_root() and
+	  thunar_file_has_parent() based on GFile/GFileInfo/GAppInfo.
+	* thunar/thunar-gio-extensions.c: Fix problem in g_file_is_root().
+
+2009-04-11	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-file.{c,h}: Replace all occurances of
 	  ThunarVfsFileMode with ThunarFileMode, which is the same, just moved
 	  from ThunarVFS into thunar-file.h. Re-implement

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-10 22:31:19 UTC (rev 29759)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-10 23:14:49 UTC (rev 29760)
@@ -795,16 +795,30 @@
 thunar_file_get_parent (const ThunarFile *file,
                         GError          **error)
 {
+  ThunarFile *parent = NULL;
+  GFile      *parent_file;
+  gchar      *uri;
+
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
   _thunar_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-  if (!thunar_file_has_parent (file))
+  /* TODO Rewrite based on thunar_file_get() */
+
+  parent_file = g_file_get_parent (file->gfile);
+
+  if (parent_file == NULL)
     {
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT, _("The root folder has no parent"));
       return NULL;
     }
 
-  return thunar_file_get_for_path (thunar_vfs_path_get_parent (file->info->path), error);
+  uri = g_file_get_uri (parent_file);
+  parent = thunar_file_get_for_uri (uri, error);
+  g_free (uri);
+
+  g_object_unref (parent_file);
+
+  return parent;
 }
 
 
@@ -862,12 +876,12 @@
                     gpointer    parent,
                     GError    **error)
 {
-  ThunarVfsMimeApplication *handler;
-  ThunarVfsMimeDatabase    *database;
-  ThunarApplication        *application;
-  GdkScreen                *screen;
-  gboolean                  succeed;
-  GList                     path_list;
+  GdkAppLaunchContext *context;
+  ThunarApplication   *application;
+  GdkScreen           *screen;
+  GAppInfo            *app_info;
+  gboolean             succeed;
+  GList                path_list;
 
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
   _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -881,10 +895,6 @@
   else
     screen = GDK_SCREEN (parent);
 
-  /* check if we should execute the file */
-  if (thunar_file_is_executable (file))
-    return thunar_file_execute (file, screen, NULL, error);
-
   /* check if we have a folder here */
   if (thunar_file_is_directory (file))
     {
@@ -894,27 +904,38 @@
       return TRUE;
     }
 
-  /* determine the default handler for the file */
-  database = thunar_vfs_mime_database_get_default ();
-  handler = thunar_vfs_mime_database_get_default_application (database, thunar_file_get_mime_info (file));
-  g_object_unref (G_OBJECT (database));
+  /* check if we should execute the file */
+  if (thunar_file_is_executable (file))
+    return thunar_file_execute (file, screen, NULL, error);
 
-  /* if we don't have any default handler, just popup the application chooser */
-  if (G_UNLIKELY (handler == NULL))
+  /* determine the default application to open the file */
+  /* TODO We should probably add a cancellable argument to thunar_file_launch() */
+  app_info = g_file_query_default_handler (file->gfile, NULL, error);
+
+  /* display the application chooser if no application is defined for this file
+   * type yet */
+  if (G_UNLIKELY (app_info == NULL))
     {
       thunar_show_chooser_dialog (parent, file, TRUE);
       return TRUE;
     }
 
   /* fake a path list */
-  path_list.data = thunar_file_get_path (file);
+  path_list.data = file->gfile;
   path_list.next = path_list.prev = NULL;
 
+  /* create a launch context */
+  context = gdk_app_launch_context_new ();
+  gdk_app_launch_context_set_screen (context, screen);
+
   /* otherwise try to execute the application */
-  succeed = thunar_vfs_mime_handler_exec (THUNAR_VFS_MIME_HANDLER (handler), screen, &path_list, error);
+  succeed = g_app_info_launch (app_info, &path_list, G_APP_LAUNCH_CONTEXT (context), error);
 
+  /* destroy the launch context */
+  g_object_unref (context);
+
   /* release the handler reference */
-  g_object_unref (G_OBJECT (handler));
+  g_object_unref (G_OBJECT (app_info));
 
   return succeed;
 }

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-10 22:31:19 UTC (rev 29759)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-10 23:14:49 UTC (rev 29760)
@@ -22,6 +22,7 @@
 #define __THUNAR_FILE_H__
 
 #include <thunar/thunar-enum-types.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-metafile.h>
 #include <thunar/thunar-user.h>
 #include <thunarx/thunarx.h>
@@ -240,6 +241,16 @@
 gboolean         thunar_file_is_desktop              (const ThunarFile *file);
 
 /**
+ * thunar_file_is_root:
+ * @file : a #ThunarFile.
+ *
+ * Checks whether @file refers to the root directory.
+ *
+ * Return value: %TRUE if @file is the root directory.
+ **/
+#define thunar_file_is_root(file) (g_file_is_root (THUNAR_FILE ((file))->gfile))
+
+/**
  * thunar_file_has_parent:
  * @file : a #ThunarFile instance.
  *
@@ -248,7 +259,7 @@
  *
  * Return value: whether @file has a parent.
  **/
-#define thunar_file_has_parent(file) (!thunar_vfs_path_is_root (THUNAR_FILE ((file))->info->path))
+#define thunar_file_has_parent(file) (!thunar_file_is_root (THUNAR_FILE ((file))))
 
 /**
  * thunar_file_get_info:
@@ -406,7 +417,7 @@
  * Return value: %TRUE if @file is in the trash, or
  *               the trash folder itself.
  **/
-#define thunar_file_is_trashed(file) (g_file_is_trashed (THUNAR_FILE (file)->gfile))
+#define thunar_file_is_trashed(file) (g_file_is_trashed (THUNAR_FILE ((file))->gfile))
 
 /**
  * thunar_file_is_ancestor:
@@ -496,16 +507,6 @@
 #define thunar_file_is_regular(file) (THUNAR_FILE ((file))->info->type == THUNAR_VFS_FILE_TYPE_REGULAR)
 
 /**
- * thunar_file_is_root:
- * @file : a #ThunarFile.
- *
- * Checks whether @file refers to the root directory.
- *
- * Return value: %TRUE if @file is the root directory.
- **/
-#define thunar_file_is_root(file) (thunar_vfs_path_is_root (THUNAR_FILE ((file))->info->path))
-
-/**
  * thunar_file_is_symlink:
  * @file : a #ThunarFile.
  *

Modified: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-10 22:31:19 UTC (rev 29759)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-10 23:14:49 UTC (rev 29760)
@@ -58,12 +58,14 @@
 g_file_is_root (GFile *file)
 {
   GFile   *parent;
-  gboolean is_root = FALSE;
+  gboolean is_root = TRUE;
 
   parent = g_file_get_parent (file);
-  if (G_UNLIKELY (parent == NULL))
-    is_root = TRUE;
-  g_object_unref (parent);
+  if (G_UNLIKELY (parent != NULL))
+    {
+      is_root = FALSE;
+      g_object_unref (parent);
+    }
 
   return is_root;
 }




More information about the Xfce4-commits mailing list