[Xfce4-commits] r29790 - in thunar/branches/migration-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Mon Apr 13 04:59:04 CEST 2009
Author: jannis
Date: 2009-04-13 02:59:04 +0000 (Mon, 13 Apr 2009)
New Revision: 29790
Modified:
thunar/branches/migration-to-gio/ChangeLog
thunar/branches/migration-to-gio/configure.in.in
thunar/branches/migration-to-gio/thunar/main.c
thunar/branches/migration-to-gio/thunar/thunar-chooser-dialog.c
thunar/branches/migration-to-gio/thunar/thunar-chooser-model.c
thunar/branches/migration-to-gio/thunar/thunar-chooser-model.h
thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
Log:
* configure.in.in: Bump exo dependency for the "gicon" property of
ExoCellRendererIcon.
* thunar/main.c: Set the desktop environment for GDesktopAppInfo if
gio-unix is available.
* thunar/thunar-chooser-dialog.c, thunar-chooser-model.{c,h}: Replace
all ThunarVfsMime* references with code based on GAppInfo. Use the
new "gicon" property of ExoCellRendererIcon. Only regression is that
there is no way to check whether a GAppInfo was created by the user
in GIO.
Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog 2009-04-13 02:22:25 UTC (rev 29789)
+++ thunar/branches/migration-to-gio/ChangeLog 2009-04-13 02:59:04 UTC (rev 29790)
@@ -1,5 +1,17 @@
2009-04-13 Jannis Pohlmann <jannis at xfce.org>
+ * configure.in.in: Bump exo dependency for the "gicon" property of
+ ExoCellRendererIcon.
+ * thunar/main.c: Set the desktop environment for GDesktopAppInfo if
+ gio-unix is available.
+ * thunar/thunar-chooser-dialog.c, thunar-chooser-model.{c,h}: Replace
+ all ThunarVfsMime* references with code based on GAppInfo. Use the
+ new "gicon" property of ExoCellRendererIcon. Only regression is that
+ there is no way to check whether a GAppInfo was created by the user
+ in GIO.
+
+2009-04-13 Jannis Pohlmann <jannis at xfce.org>
+
* thunar/thunar-properties-dialog.c: Remove ThunarVfsMimeInfo and use
a content type string in thunar_properties_dialog_update().
Modified: thunar/branches/migration-to-gio/configure.in.in
===================================================================
--- thunar/branches/migration-to-gio/configure.in.in 2009-04-13 02:22:25 UTC (rev 29789)
+++ thunar/branches/migration-to-gio/configure.in.in 2009-04-13 02:59:04 UTC (rev 29790)
@@ -159,7 +159,7 @@
dnl ***********************************
dnl *** Check for required packages ***
dnl ***********************************
-XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.100])
+XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.101svn-r29789])
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.16.0])
XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.16.0])
XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.16.0])
Modified: thunar/branches/migration-to-gio/thunar/main.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/main.c 2009-04-13 02:22:25 UTC (rev 29789)
+++ thunar/branches/migration-to-gio/thunar/main.c 2009-04-13 02:59:04 UTC (rev 29790)
@@ -29,6 +29,9 @@
#endif
#include <glib/gstdio.h>
+#ifdef HAVE_GIO_UNIX
+#include <gio/gdesktopappinfo.h>
+#endif
#include <thunar/thunar-application.h>
#include <thunar/thunar-dbus-client.h>
@@ -129,6 +132,11 @@
return EXIT_SUCCESS;
}
+#ifdef HAVE_GIO_UNIX
+ /* set desktop environment for app infos */
+ g_desktop_app_info_set_desktop_env ("XFCE");
+#endif
+
/* register additional transformation functions */
thunar_g_initialize_transformations ();
Modified: thunar/branches/migration-to-gio/thunar/thunar-chooser-dialog.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-chooser-dialog.c 2009-04-13 02:22:25 UTC (rev 29789)
+++ thunar/branches/migration-to-gio/thunar/thunar-chooser-dialog.c 2009-04-13 02:59:04 UTC (rev 29790)
@@ -1,6 +1,7 @@
/* $Id$ */
/*-
- * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>.
+ * 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
@@ -268,7 +269,7 @@
renderer = g_object_new (EXO_TYPE_CELL_RENDERER_ICON, "follow-state", FALSE, "size", 24, NULL);
gtk_tree_view_column_pack_start (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer,
- "icon", THUNAR_CHOOSER_MODEL_COLUMN_ICON,
+ "gicon", THUNAR_CHOOSER_MODEL_COLUMN_ICON,
NULL);
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
@@ -408,23 +409,12 @@
thunar_chooser_dialog_realize (GtkWidget *widget)
{
ThunarChooserDialog *dialog = THUNAR_CHOOSER_DIALOG (widget);
- GtkTreeModel *model;
- GdkCursor *cursor;
/* let the GtkWindow class realize the dialog */
(*GTK_WIDGET_CLASS (thunar_chooser_dialog_parent_class)->realize) (widget);
/* update the dialog header */
thunar_chooser_dialog_update_header (dialog);
-
- /* setup a watch cursor if we're currently loading the model */
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tree_view));
- if (thunar_chooser_model_get_loading (THUNAR_CHOOSER_MODEL (model)))
- {
- cursor = gdk_cursor_new (GDK_WATCH);
- gdk_window_set_cursor (widget->window, cursor);
- gdk_cursor_unref (cursor);
- }
}
@@ -433,37 +423,34 @@
thunar_chooser_dialog_response (GtkDialog *widget,
gint response)
{
- ThunarVfsMimeApplication *application = NULL;
- ThunarVfsMimeDatabase *mime_database;
- ThunarChooserDialog *dialog = THUNAR_CHOOSER_DIALOG (widget);
- ThunarVfsMimeInfo *mime_info;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- const gchar *exec;
- gboolean succeed = TRUE;
- GError *error = NULL;
- gchar *path;
- gchar *name;
- gchar *s;
- GList list;
+ GdkAppLaunchContext *context;
+ ThunarChooserDialog *dialog = THUNAR_CHOOSER_DIALOG (widget);
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ const gchar *content_type;
+ const gchar *exec;
+ GAppInfo *app_info;
+ gboolean succeed = TRUE;
+ GError *error = NULL;
+ gchar *path;
+ gchar *name;
+ gchar *s;
+ GList list;
/* no special processing for non-accept responses */
if (G_UNLIKELY (response != GTK_RESPONSE_ACCEPT))
return;
- /* grab a reference on the mime database */
- mime_database = thunar_vfs_mime_database_get_default ();
+ /* determine the content type for the file */
+ content_type = thunar_file_get_content_type (dialog->file);
- /* determine the mime info for the file */
- mime_info = thunar_file_get_mime_info (dialog->file);
-
/* determine the application that was chosen by the user */
if (!gtk_expander_get_expanded (GTK_EXPANDER (dialog->custom_expander)))
{
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->tree_view));
if (gtk_tree_selection_get_selected (selection, &model, &iter))
- gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &application, -1);
+ gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &app_info, -1);
}
else
{
@@ -480,10 +467,10 @@
name = g_path_get_basename (path);
/* try to add an application for the custom command */
- application = thunar_vfs_mime_database_add_application (mime_database, mime_info, name, exec, &error);
+ app_info = g_app_info_create_from_commandline (exec, name, G_APP_INFO_CREATE_NONE, &error);
/* verify the application */
- if (G_UNLIKELY (application == NULL))
+ if (G_UNLIKELY (app_info == NULL))
{
/* display an error to the user */
thunar_dialogs_show_error (GTK_WIDGET (dialog), error, _("Failed to add new application \"%s\""), name);
@@ -498,20 +485,22 @@
}
/* verify that we have a valid application */
- if (G_UNLIKELY (application == NULL))
- goto cleanup;
+ if (G_UNLIKELY (app_info == NULL))
+ return;
/* check if we should also set the application as default */
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->default_button)))
{
/* remember the application as default for these kind of file */
- succeed = thunar_vfs_mime_database_set_default_application (mime_database, mime_info, application, &error);
+ succeed = g_app_info_set_as_default_for_type (app_info, content_type, &error);
/* verify that we were successfull */
if (G_UNLIKELY (!succeed))
{
/* display an error to the user */
- thunar_dialogs_show_error (GTK_WIDGET (dialog), error, _("Failed to set default application for \"%s\""),
+ thunar_dialogs_show_error (GTK_WIDGET (dialog),
+ error,
+ _("Failed to set default application for \"%s\""),
thunar_file_get_display_name (dialog->file));
/* release the error */
@@ -526,23 +515,31 @@
/* check if we should also execute the application */
if (G_LIKELY (succeed && dialog->open))
{
- /* open the file using the specified application */
- list.data = thunar_file_get_path (dialog->file); list.next = list.prev = NULL;
- if (!thunar_vfs_mime_handler_exec (THUNAR_VFS_MIME_HANDLER (application), gtk_widget_get_screen (GTK_WIDGET (dialog)), &list, &error))
+ /* create launch context */
+ context = gdk_app_launch_context_new ();
+ gdk_app_launch_context_set_screen (context, gtk_widget_get_screen (GTK_WIDGET (dialog)));
+
+ /* create fake file list */
+ list.data = thunar_file_get_file (dialog->file); list.next = list.prev = NULL;
+
+ if (!g_app_info_launch (app_info, &list, G_APP_LAUNCH_CONTEXT (context), &error))
{
/* display an error to the user */
- thunar_dialogs_show_error (GTK_WIDGET (dialog), error, _("Failed to execute \"%s\""),
- thunar_vfs_mime_handler_get_name (THUNAR_VFS_MIME_HANDLER (application)));
+ thunar_dialogs_show_error (GTK_WIDGET (dialog),
+ error,
+ _("Failed to execute application \"%s\""),
+ g_app_info_get_name (app_info));
/* release the error */
g_error_free (error);
}
+
+ /* destroy the launch context */
+ g_object_unref (context);
}
/* cleanup */
- g_object_unref (G_OBJECT (application));
-cleanup:
- g_object_unref (G_OBJECT (mime_database));
+ g_object_unref (app_info);
}
@@ -578,13 +575,13 @@
guint button,
guint32 time)
{
- ThunarVfsMimeApplication *mime_application;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkWidget *image;
- GtkWidget *item;
- GtkWidget *menu;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkWidget *image;
+ GtkWidget *item;
+ GtkWidget *menu;
+ GAppInfo *app_info;
_thunar_return_val_if_fail (THUNAR_IS_CHOOSER_DIALOG (dialog), FALSE);
@@ -593,9 +590,9 @@
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return FALSE;
- /* determine the mime application for the row */
- gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &mime_application, -1);
- if (G_UNLIKELY (mime_application == NULL))
+ /* determine the app info for the row */
+ gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &app_info, -1);
+ if (G_UNLIKELY (app_info == NULL))
return FALSE;
/* prepare the popup menu */
@@ -603,7 +600,8 @@
/* append the "Remove Launcher" item */
item = gtk_image_menu_item_new_with_mnemonic (_("_Remove Launcher"));
- gtk_widget_set_sensitive (item, thunar_vfs_mime_application_is_usercreated (mime_application));
+ /* FIXME Need a way to find out whether the appinfo was created by the user: */
+ gtk_widget_set_sensitive (item, FALSE);
g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_chooser_dialog_action_remove), dialog);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
@@ -616,7 +614,7 @@
thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (dialog), NULL, NULL, button, time);
/* clean up */
- g_object_unref (G_OBJECT (mime_application));
+ g_object_unref (app_info);
return TRUE;
}
@@ -662,11 +660,12 @@
static void
thunar_chooser_dialog_update_header (ThunarChooserDialog *dialog)
{
- ThunarVfsMimeInfo *mime_info;
ThunarIconFactory *icon_factory;
GtkIconTheme *icon_theme;
+ const gchar *content_type;
const gchar *icon_name;
- GdkPixbuf *icon;
+ GIcon *icon;
+ gchar *description;
gchar *text;
_thunar_return_if_fail (THUNAR_IS_CHOOSER_DIALOG (dialog));
@@ -675,32 +674,22 @@
/* check if we have a valid file set */
if (G_UNLIKELY (dialog->file == NULL))
{
-#if GTK_CHECK_VERSION(2,8,0)
gtk_image_clear (GTK_IMAGE (dialog->header_image));
-#endif
gtk_label_set_text (GTK_LABEL (dialog->header_label), NULL);
}
else
{
- /* determine the mime info for the file */
- mime_info = thunar_file_get_mime_info (dialog->file);
+ content_type = thunar_file_get_content_type (dialog->file);
+ description = g_content_type_get_description (content_type);
- /* determine the icon theme/factory for the widget */
- icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (dialog)));
- icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme);
+ icon = g_content_type_get_icon (content_type);
+ gtk_image_set_from_gicon (GTK_IMAGE (dialog->header_image), icon, GTK_ICON_SIZE_DIALOG);
+ g_object_unref (icon);
- /* update the header image with the icon for the mime type */
- icon_name = thunar_vfs_mime_info_lookup_icon_name (mime_info, icon_theme);
- icon = thunar_icon_factory_load_icon (icon_factory, icon_name, 48, NULL, FALSE);
- gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->header_image), icon);
- gtk_window_set_icon (GTK_WINDOW (dialog), icon);
- if (G_LIKELY (icon != NULL))
- g_object_unref (G_OBJECT (icon));
-
/* update the header label */
text = g_strdup_printf (_("Open <i>%s</i> and other files of type \"%s\" with:"),
thunar_file_get_display_name (dialog->file),
- thunar_vfs_mime_info_get_comment (mime_info));
+ description);
gtk_label_set_markup (GTK_LABEL (dialog->header_label), text);
g_free (text);
@@ -708,16 +697,16 @@
thunar_gtk_widget_set_tooltip (dialog->custom_button,
_("Browse the file system to select an "
"application to open files of type \"%s\"."),
- thunar_vfs_mime_info_get_comment (mime_info));
+ description);
/* update the "Use as default for this kind of file" tooltip */
thunar_gtk_widget_set_tooltip (dialog->default_button,
_("Change the default application for files "
"of type \"%s\" to the selected application."),
- thunar_vfs_mime_info_get_comment (mime_info));
+ description);
/* cleanup */
- g_object_unref (G_OBJECT (icon_factory));
+ g_free (description);
}
}
@@ -726,14 +715,14 @@
static void
thunar_chooser_dialog_action_remove (ThunarChooserDialog *dialog)
{
- ThunarVfsMimeApplication *mime_application;
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GtkTreeIter iter;
- const gchar *name;
- GtkWidget *message;
- GError *error = NULL;
- gint response;
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ const gchar *name;
+ GtkWidget *message;
+ GAppInfo *app_info;
+ GError *error = NULL;
+ gint response;
_thunar_return_if_fail (THUNAR_IS_CHOOSER_DIALOG (dialog));
@@ -742,16 +731,16 @@
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return;
- /* determine the mime application for the row */
- gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &mime_application, -1);
- if (G_UNLIKELY (mime_application == NULL))
+ /* determine the app info for the row */
+ gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &app_info, -1);
+ if (G_UNLIKELY (app_info == NULL))
return;
- /* verify that the application is usercreated */
- if (thunar_vfs_mime_application_is_usercreated (mime_application))
+ /* FIXME need a way to verify that the application is usercreated */
+ if (FALSE)
{
- /* determine the name of the mime application */
- name = thunar_vfs_mime_handler_get_name (THUNAR_VFS_MIME_HANDLER (mime_application));
+ /* determine the name of the app info */
+ name = g_app_info_get_name (app_info);
/* ask the user whether to remove the application launcher */
message = gtk_message_dialog_new (GTK_WINDOW (dialog),
@@ -792,7 +781,7 @@
}
/* cleanup */
- g_object_unref (G_OBJECT (mime_application));
+ g_object_unref (app_info);
}
@@ -1072,19 +1061,19 @@
thunar_chooser_dialog_selection_changed (GtkTreeSelection *selection,
ThunarChooserDialog *dialog)
{
- ThunarVfsMimeApplication *mime_application;
- GtkTreeModel *model;
- const gchar *exec;
- GtkTreeIter iter;
+ GAppInfo *app_info;
+ GtkTreeModel *model;
+ const gchar *exec;
+ GtkTreeIter iter;
/* determine the iterator for the selected row */
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
- /* determine the mime application for the selected row */
- gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &mime_application, -1);
+ /* determine the app info for the selected row */
+ gtk_tree_model_get (model, &iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &app_info, -1);
- /* determine the command for the mime application */
- exec = thunar_vfs_mime_handler_get_command (THUNAR_VFS_MIME_HANDLER (mime_application));
+ /* determine the command for the app info */
+ exec = g_app_info_get_executable (app_info);
if (G_LIKELY (exec != NULL && g_utf8_validate (exec, -1, NULL)))
{
/* setup the command as default for the custom command box */
@@ -1092,7 +1081,7 @@
}
/* cleanup */
- g_object_unref (G_OBJECT (mime_application));
+ g_object_unref (app_info);
}
/* update the sensitivity of the "Ok"/"Open" button */
@@ -1146,7 +1135,6 @@
ThunarFile *file)
{
ThunarChooserModel *model;
- ThunarVfsMimeInfo *mime_info;
_thunar_return_if_fail (THUNAR_IS_CHOOSER_DIALOG (dialog));
_thunar_return_if_fail (file == NULL || THUNAR_IS_FILE (file));
@@ -1179,8 +1167,7 @@
g_signal_connect_swapped (G_OBJECT (file), "destroy", G_CALLBACK (gtk_widget_destroy), dialog);
/* allocate the new chooser model */
- mime_info = thunar_file_get_mime_info (file);
- model = thunar_chooser_model_new (mime_info);
+ model = thunar_chooser_model_new (thunar_file_get_content_type (file));
gtk_tree_view_set_model (GTK_TREE_VIEW (dialog->tree_view), GTK_TREE_MODEL (model));
g_signal_connect (G_OBJECT (model), "notify::loading", G_CALLBACK (thunar_chooser_dialog_notify_loading), dialog);
g_object_unref (G_OBJECT (model));
Modified: thunar/branches/migration-to-gio/thunar/thunar-chooser-model.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-chooser-model.c 2009-04-13 02:22:25 UTC (rev 29789)
+++ thunar/branches/migration-to-gio/thunar/thunar-chooser-model.c 2009-04-13 02:59:04 UTC (rev 29790)
@@ -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
@@ -39,14 +40,14 @@
enum
{
PROP_0,
- PROP_LOADING,
- PROP_MIME_INFO,
+ PROP_CONTENT_TYPE,
};
static void thunar_chooser_model_class_init (ThunarChooserModelClass *klass);
static void thunar_chooser_model_init (ThunarChooserModel *model);
+static void thunar_chooser_model_constructed (GObject *object);
static void thunar_chooser_model_finalize (GObject *object);
static void thunar_chooser_model_get_property (GObject *object,
guint prop_id,
@@ -56,22 +57,10 @@
guint prop_id,
const GValue *value,
GParamSpec *pspec);
-static void thunar_chooser_model_append (ThunarChooserModel *model,
- const gchar *title,
- const gchar *icon_name,
- GList *applications);
-static void thunar_chooser_model_import (ThunarChooserModel *model,
- GList *applications);
-static GList *thunar_chooser_model_readdir (ThunarChooserModel *model,
- const gchar *absdir,
- const gchar *reldir);
-static gpointer thunar_chooser_model_thread (gpointer user_data);
-static gboolean thunar_chooser_model_timer (gpointer user_data);
-static void thunar_chooser_model_timer_destroy (gpointer user_data);
+static void thunar_chooser_model_reload (ThunarChooserModel *model);
-
struct _ThunarChooserModelClass
{
GtkTreeStoreClass __parent__;
@@ -81,13 +70,7 @@
{
GtkTreeStore __parent__;
- ThunarVfsMimeInfo *mime_info;
-
- /* thread interaction */
- gint timer_id;
- GThread *thread;
- volatile gboolean finished;
- volatile gboolean cancelled;
+ gchar *content_type;
};
@@ -135,31 +118,23 @@
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = thunar_chooser_model_finalize;
+ gobject_class->constructed = thunar_chooser_model_constructed;
gobject_class->get_property = thunar_chooser_model_get_property;
gobject_class->set_property = thunar_chooser_model_set_property;
/**
- * ThunarChooserModel::loading:
+ * ThunarChooserModel::content-type:
*
- * Whether the contents of the #ThunarChooserModel are
- * currently being loaded from disk.
+ * The content type for the model.
**/
g_object_class_install_property (gobject_class,
- PROP_LOADING,
- g_param_spec_boolean ("loading", "loading", "loading",
- FALSE,
- EXO_PARAM_READABLE));
-
- /**
- * ThunarChooserModel::mime-info:
- *
- * The #ThunarVfsMimeInfo info for the model.
- **/
- g_object_class_install_property (gobject_class,
- PROP_MIME_INFO,
- g_param_spec_boxed ("mime-info", "mime-info", "mime-info",
- THUNAR_VFS_TYPE_MIME_INFO,
- G_PARAM_CONSTRUCT_ONLY | EXO_PARAM_READWRITE));
+ PROP_CONTENT_TYPE,
+ g_param_spec_string ("content-type",
+ "content-type",
+ "content-type",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY |
+ EXO_PARAM_READWRITE));
}
@@ -171,8 +146,8 @@
GType column_types[THUNAR_CHOOSER_MODEL_N_COLUMNS] =
{
G_TYPE_STRING,
- G_TYPE_STRING,
- THUNAR_VFS_TYPE_MIME_APPLICATION,
+ G_TYPE_ICON,
+ G_TYPE_APP_INFO,
PANGO_TYPE_STYLE,
G_TYPE_BOOLEAN,
PANGO_TYPE_WEIGHT,
@@ -180,45 +155,31 @@
};
/* register the column types */
- gtk_tree_store_set_column_types (GTK_TREE_STORE (model), G_N_ELEMENTS (column_types), column_types);
-
- /* start to load the applications installed on the system */
- model->thread = g_thread_create (thunar_chooser_model_thread, model, TRUE, NULL);
-
- /* start the timer to monitor the thread */
- model->timer_id = g_timeout_add_full (G_PRIORITY_LOW, 200, thunar_chooser_model_timer,
- model, thunar_chooser_model_timer_destroy);
+ gtk_tree_store_set_column_types (GTK_TREE_STORE (model),
+ G_N_ELEMENTS (column_types),
+ column_types);
}
static void
-thunar_chooser_model_finalize (GObject *object)
+thunar_chooser_model_constructed (GObject *object)
{
ThunarChooserModel *model = THUNAR_CHOOSER_MODEL (object);
- GList *applications;
- /* drop any pending timer */
- if (G_UNLIKELY (model->timer_id >= 0))
- g_source_remove (model->timer_id);
+ /* start to load the applications installed on the system */
+ thunar_chooser_model_reload (model);
+}
- /* cancel the thread (if running) */
- if (G_UNLIKELY (model->thread != NULL))
- {
- /* set the cancellation flag */
- model->cancelled = TRUE;
- /* join the thread */
- applications = g_thread_join (model->thread);
- /* ditch the returned application list */
- g_list_foreach (applications, (GFunc) g_object_unref, NULL);
- g_list_free (applications);
- }
+static void
+thunar_chooser_model_finalize (GObject *object)
+{
+ ThunarChooserModel *model = THUNAR_CHOOSER_MODEL (object);
- /* drop the mime info (if any) */
- if (G_LIKELY (model->mime_info != NULL))
- thunar_vfs_mime_info_unref (model->mime_info);
+ /* free the content type */
+ g_free (model->content_type);
(*G_OBJECT_CLASS (thunar_chooser_model_parent_class)->finalize) (object);
}
@@ -235,14 +196,10 @@
switch (prop_id)
{
- case PROP_LOADING:
- g_value_set_boolean (value, thunar_chooser_model_get_loading (model));
+ case PROP_CONTENT_TYPE:
+ g_value_set_string (value, thunar_chooser_model_get_content_type (model));
break;
- case PROP_MIME_INFO:
- g_value_set_boxed (value, thunar_chooser_model_get_mime_info (model));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -261,9 +218,8 @@
switch (prop_id)
{
- case PROP_MIME_INFO:
- if (G_LIKELY (model->mime_info == NULL))
- model->mime_info = g_value_dup_boxed (value);
+ case PROP_CONTENT_TYPE:
+ model->content_type = g_value_dup_string (value);
break;
default:
@@ -278,40 +234,39 @@
thunar_chooser_model_append (ThunarChooserModel *model,
const gchar *title,
const gchar *icon_name,
- GList *applications)
+ GList *app_infos)
{
- GtkIconTheme *icon_theme;
- GtkTreeIter parent_iter;
- GtkTreeIter child_iter;
- GList *lp;
+ GtkTreeIter child_iter;
+ GtkTreeIter parent_iter;
+ GIcon *icon;
+ GList *lp;
_thunar_return_if_fail (THUNAR_IS_CHOOSER_MODEL (model));
_thunar_return_if_fail (title != NULL);
_thunar_return_if_fail (icon_name != NULL);
- /* query the default icon theme */
- icon_theme = gtk_icon_theme_get_default ();
+ icon = g_themed_icon_new (icon_name);
- /* insert the section title */
gtk_tree_store_append (GTK_TREE_STORE (model), &parent_iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model), &parent_iter,
THUNAR_CHOOSER_MODEL_COLUMN_NAME, title,
- THUNAR_CHOOSER_MODEL_COLUMN_ICON, icon_name,
+ THUNAR_CHOOSER_MODEL_COLUMN_ICON, icon,
THUNAR_CHOOSER_MODEL_COLUMN_WEIGHT, PANGO_WEIGHT_SEMIBOLD,
THUNAR_CHOOSER_MODEL_COLUMN_WEIGHT_SET, TRUE,
-1);
- /* check if we have any program items */
- if (G_LIKELY (applications != NULL))
+ g_object_unref (icon);
+
+ if (G_LIKELY (app_infos != NULL))
{
/* insert the program items */
- for (lp = applications; lp != NULL; lp = lp->next)
+ for (lp = app_infos; lp != NULL; lp = lp->next)
{
/* append the tree row with the program data */
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &parent_iter);
gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
- THUNAR_CHOOSER_MODEL_COLUMN_NAME, thunar_vfs_mime_handler_get_name (lp->data),
- THUNAR_CHOOSER_MODEL_COLUMN_ICON, thunar_vfs_mime_handler_lookup_icon_name (lp->data, icon_theme),
+ THUNAR_CHOOSER_MODEL_COLUMN_NAME, g_app_info_get_name (lp->data),
+ THUNAR_CHOOSER_MODEL_COLUMN_ICON, g_app_info_get_icon (lp->data),
THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, lp->data,
-1);
}
@@ -330,286 +285,96 @@
-static void
-thunar_chooser_model_import (ThunarChooserModel *model,
- GList *applications)
+static gint
+compare_app_infos (gconstpointer a,
+ gconstpointer b)
{
- ThunarVfsMimeDatabase *mime_database;
- GList *recommended;
- GList *other = NULL;
- GList *lp;
- GList *p;
-
- _thunar_return_if_fail (THUNAR_IS_CHOOSER_MODEL (model));
- _thunar_return_if_fail (model->mime_info != NULL);
-
- /* determine the recommended applications for the mime info */
- mime_database = thunar_vfs_mime_database_get_default ();
- recommended = thunar_vfs_mime_database_get_applications (mime_database, model->mime_info);
- g_object_unref (G_OBJECT (mime_database));
-
- /* add all applications to other that are not already on recommended */
- for (lp = applications; lp != NULL; lp = lp->next)
- {
- /* check if this application is already on the recommended list */
- for (p = recommended; p != NULL; p = p->next)
- if (thunar_vfs_mime_application_equal (p->data, lp->data))
- break;
-
- /* add to the list of other applications if it's not on recommended */
- if (G_LIKELY (p == NULL))
- other = g_list_append (other, lp->data);
- }
-
- /* append the "Recommended Applications:" category */
- thunar_chooser_model_append (model, _("Recommended Applications"), "preferences-desktop-default-applications", recommended);
-
- /* append the "Other Applications:" category */
- thunar_chooser_model_append (model, _("Other Applications"), "gnome-applications", other);
-
- /* cleanup */
- g_list_foreach (recommended, (GFunc) g_object_unref, NULL);
- g_list_free (recommended);
- g_list_free (other);
+ return g_app_info_equal (G_APP_INFO (a), G_APP_INFO (b)) ? 0 : 1;
}
-static GList*
-thunar_chooser_model_readdir (ThunarChooserModel *model,
- const gchar *absdir,
- const gchar *reldir)
+static void
+thunar_chooser_model_reload (ThunarChooserModel *model)
{
- ThunarVfsMimeApplication *application;
- const gchar *name;
- GList *applications = NULL;
- gchar *abspath;
- gchar *relpath;
- gchar *p;
- GDir *dp;
+ GList *all;
+ GList *lp;
+ GList *other = NULL;
+ GList *recommended;
- _thunar_return_val_if_fail (THUNAR_IS_CHOOSER_MODEL (model), NULL);
- _thunar_return_val_if_fail (reldir == NULL || !g_path_is_absolute (reldir), NULL);
- _thunar_return_val_if_fail (g_path_is_absolute (absdir), NULL);
+ _thunar_return_if_fail (THUNAR_IS_CHOOSER_MODEL (model));
+ _thunar_return_if_fail (model->content_type != NULL);
- /* try to open the directory */
- dp = g_dir_open (absdir, 0, NULL);
- if (G_LIKELY (dp != NULL))
- {
- /* process the files within the directory */
- while (!model->cancelled)
- {
- /* read the next file entry */
- name = g_dir_read_name (dp);
- if (G_UNLIKELY (name == NULL))
- break;
+ gtk_tree_store_clear (GTK_TREE_STORE (model));
- /* generate the absolute path to the file entry */
- abspath = g_build_filename (absdir, name, NULL);
+ /* check if we have any applications for this type */
+ recommended = g_app_info_get_all_for_type (model->content_type);
- /* generate the relative path to the file entry */
- relpath = (reldir != NULL) ? g_build_filename (reldir, name, NULL) : g_strdup (name);
+ /* append them as recommended */
+ thunar_chooser_model_append (model,
+ _("Recommended Applications"),
+ "preferences-desktop-default-applications",
+ recommended);
- /* check if we have a directory or a regular file here */
- if (g_file_test (abspath, G_FILE_TEST_IS_DIR))
- {
- /* recurse for directories */
- applications = g_list_concat (applications, thunar_chooser_model_readdir (model, abspath, relpath));
- }
- else if (g_file_test (abspath, G_FILE_TEST_IS_REGULAR) && g_str_has_suffix (name, ".desktop"))
- {
- /* generate the desktop-id from the relative path */
- for (p = relpath; *p != '\0'; ++p)
- if (*p == G_DIR_SEPARATOR)
- *p = '-';
-
- /* try to load the application for the given desktop-id */
- application = thunar_vfs_mime_application_new_from_file (abspath, relpath);
-
- /* check if we have successfully loaded the application */
- if (G_LIKELY (application != NULL))
- {
- /* check if the application supports atleast one mime-type */
- if (thunar_vfs_mime_application_get_mime_types (application) != NULL)
- applications = g_list_append (applications, application);
- else
- g_object_unref (G_OBJECT (application));
- }
- }
-
- /* cleanup */
- g_free (abspath);
- g_free (relpath);
- }
-
- /* close the directory handle */
- g_dir_close (dp);
- }
-
- return applications;
-}
-
-
-
-static gint
-compare_application_by_name (gconstpointer a,
- gconstpointer b)
-{
- return strcmp (thunar_vfs_mime_handler_get_name (a),
- thunar_vfs_mime_handler_get_name (b));
-}
-
-
-
-static gpointer
-thunar_chooser_model_thread (gpointer user_data)
-{
- ThunarChooserModel *model = THUNAR_CHOOSER_MODEL (user_data);
- GList *applications = NULL;
- GList *list;
- GList *lp;
- GList *p;
- gchar **paths;
- guint n;
-
- /* determine the available applications/ directories */
- paths = xfce_resource_lookup_all (XFCE_RESOURCE_DATA, "applications/");
- for (n = 0; !model->cancelled && paths[n] != NULL; ++n)
+ all = g_app_info_get_all ();
+ for (lp = g_list_last (all); lp != NULL; lp = lp->prev)
{
- /* lookup the applications in this directory */
- list = thunar_chooser_model_readdir (model, paths[n], NULL);
-
- /* merge the applications with what we already have */
- for (lp = list; lp != NULL; lp = lp->next)
+ if (g_list_find_custom (recommended,
+ lp->data,
+ (GCompareFunc) compare_app_infos) == NULL)
{
- /* ignore hidden applications to be compatible with the Nautilus mess */
- if ((thunar_vfs_mime_handler_get_flags (lp->data) & THUNAR_VFS_MIME_HANDLER_HIDDEN) != 0)
- {
- g_object_unref (G_OBJECT (lp->data));
- continue;
- }
-
- /* check if we have that application already */
- for (p = applications; p != NULL; p = p->next)
- {
- /* compare the desktop-ids */
- if (thunar_vfs_mime_application_equal (p->data, lp->data))
- break;
- }
-
- /* no need to add if we have it already */
- if (G_UNLIKELY (p != NULL))
- {
- g_object_unref (G_OBJECT (lp->data));
- continue;
- }
-
- /* insert the application into the list */
- applications = g_list_insert_sorted (applications, lp->data, compare_application_by_name);
+ other = g_list_prepend (other, lp->data);
}
-
- /* free the temporary list */
- g_list_free (list);
}
- g_strfreev (paths);
- /* tell the model that we're done */
- model->finished = TRUE;
+ /* append the other applications */
+ thunar_chooser_model_append (model,
+ _("Other Applications"),
+ "gnome-applications",
+ other);
- return applications;
-}
+ g_list_foreach (recommended, (GFunc) g_object_unref, NULL);
+ g_list_free (recommended);
+ g_list_foreach (all, (GFunc) g_object_unref, NULL);
+ g_list_free (all);
-
-static gboolean
-thunar_chooser_model_timer (gpointer user_data)
-{
- ThunarChooserModel *model = THUNAR_CHOOSER_MODEL (user_data);
- gboolean finished;
- GList *applications;
-
- /* check if the applications are loaded */
- GDK_THREADS_ENTER ();
- finished = model->finished;
- if (G_LIKELY (finished))
- {
- /* grab the application list from the thread */
- applications = g_thread_join (model->thread);
- model->thread = NULL;
-
- /* process the applications list */
- thunar_chooser_model_import (model, applications);
-
- /* tell everybody that the model is loaded */
- g_object_notify (G_OBJECT (model), "loading");
-
- /* free the application list */
- g_list_foreach (applications, (GFunc) g_object_unref, NULL);
- g_list_free (applications);
- }
- GDK_THREADS_LEAVE ();
-
- return !finished;
+ g_list_free (other);
}
-static void
-thunar_chooser_model_timer_destroy (gpointer user_data)
-{
- THUNAR_CHOOSER_MODEL (user_data)->timer_id = -1;
-}
-
-
-
/**
* thunar_chooser_model_new:
- * @mime_info : a #ThunarVfsMimeInfo.
+ * @content_type : the content type for this model.
*
- * Allocates a new #ThunarChooserModel for @mime_info.
+ * Allocates a new #ThunarChooserModel for @content_type.
*
* Return value: the newly allocated #ThunarChooserModel.
**/
-ThunarChooserModel*
-thunar_chooser_model_new (ThunarVfsMimeInfo *mime_info)
+ThunarChooserModel *
+thunar_chooser_model_new (const gchar *content_type)
{
return g_object_new (THUNAR_TYPE_CHOOSER_MODEL,
- "mime-info", mime_info,
+ "content-type", content_type,
NULL);
}
/**
- * thunar_chooser_model_get_loading:
+ * thunar_chooser_model_get_content_type:
* @model : a #ThunarChooserModel.
*
- * Returns %TRUE if @model is currently being loaded.
+ * Returns the content type for @model.
*
- * Return value: %TRUE if @model is currently being loaded.
+ * Return value: the content type for @model.
**/
-gboolean
-thunar_chooser_model_get_loading (ThunarChooserModel *model)
+const gchar *
+thunar_chooser_model_get_content_type (ThunarChooserModel *model)
{
- _thunar_return_val_if_fail (THUNAR_IS_CHOOSER_MODEL (model), FALSE);
- return (model->thread != NULL);
-}
-
-
-
-/**
- * thunar_chooser_model_get_mime_info:
- * @model : a #ThunarChooserModel.
- *
- * Returns the #ThunarVfsMimeInfo for @model.
- *
- * Return value: the #ThunarVfsMimeInfo for @model.
- **/
-ThunarVfsMimeInfo*
-thunar_chooser_model_get_mime_info (ThunarChooserModel *model)
-{
_thunar_return_val_if_fail (THUNAR_IS_CHOOSER_MODEL (model), NULL);
- return model->mime_info;
+ return model->content_type;
}
@@ -631,25 +396,30 @@
GtkTreeIter *iter,
GError **error)
{
- ThunarVfsMimeApplication *mime_application;
- ThunarVfsMimeDatabase *mime_database;
- gboolean succeed;
+ GAppInfo *app_info;
+ gboolean succeed;
_thunar_return_val_if_fail (THUNAR_IS_CHOOSER_MODEL (model), FALSE);
_thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
_thunar_return_val_if_fail (gtk_tree_store_iter_is_valid (GTK_TREE_STORE (model), iter), FALSE);
- /* determine the mime application for the iter */
- gtk_tree_model_get (GTK_TREE_MODEL (model), iter, THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &mime_application, -1);
- if (G_UNLIKELY (mime_application == NULL))
+ /* determine the app info for the iter */
+ gtk_tree_model_get (GTK_TREE_MODEL (model),
+ iter,
+ THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION, &app_info,
+ -1);
+
+ if (G_UNLIKELY (app_info == NULL))
return TRUE;
- /* try to remove the application from the database */
- mime_database = thunar_vfs_mime_database_get_default ();
- succeed = thunar_vfs_mime_database_remove_application (mime_database, mime_application, error);
- g_object_unref (G_OBJECT (mime_application));
- g_object_unref (G_OBJECT (mime_database));
+ /* try to remove support for this content type */
+ succeed = g_app_info_remove_supports_type (app_info,
+ model->content_type,
+ error);
+ /* clean up */
+ g_object_unref (app_info);
+
/* if the removal was successfull, delete the row from the model */
if (G_LIKELY (succeed))
gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
Modified: thunar/branches/migration-to-gio/thunar/thunar-chooser-model.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-chooser-model.h 2009-04-13 02:22:25 UTC (rev 29789)
+++ thunar/branches/migration-to-gio/thunar/thunar-chooser-model.h 2009-04-13 02:59:04 UTC (rev 29790)
@@ -1,6 +1,7 @@
/* $Id$ */
/*-
- * Copyright (c) 2005-2006 Benedikt Meurer <benny at xfce.org>.
+ * 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
@@ -20,7 +21,7 @@
#ifndef __THUNAR_CHOOSER_MODEL_H__
#define __THUNAR_CHOOSER_MODEL_H__
-#include <thunar-vfs/thunar-vfs.h>
+#include <gtk/gtk.h>
G_BEGIN_DECLS;
@@ -38,7 +39,7 @@
* ThunarChooserModelColumn:
* @THUNAR_CHOOSER_MODEL_COLUMN_NAME : the name of the application.
* @THUNAR_CHOOSER_MODEL_COLUMN_ICON : the name or absolute path of the application's icon.
- * @THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION : the #ThunarVfsMimeApplication object.
+ * @THUNAR_CHOOSER_MODEL_COLUMN_APPLICATION : the #GAppInfo object.
* @THUNAR_CHOOSER_MODEL_COLUMN_STYLE : custom font style.
* @THUNAR_CHOOSER_MODEL_COLUMN_STYLE_SET : whether to actually use the custom font style.
* @THUNAR_CHOOSER_MODEL_N_COLUMNS : the number of columns in #ThunarChooserModel.
@@ -57,18 +58,14 @@
THUNAR_CHOOSER_MODEL_N_COLUMNS,
} ThunarChooserModelColumn;
-GType thunar_chooser_model_get_type (void) G_GNUC_CONST;
+GType thunar_chooser_model_get_type (void) G_GNUC_CONST;
-ThunarChooserModel *thunar_chooser_model_new (ThunarVfsMimeInfo *mime_info) G_GNUC_MALLOC;
+ThunarChooserModel *thunar_chooser_model_new (const gchar *content_type) G_GNUC_MALLOC;
+const gchar *thunar_chooser_model_get_content_type (ThunarChooserModel *model);
+gboolean thunar_chooser_model_remove (ThunarChooserModel *model,
+ GtkTreeIter *iter,
+ GError **error);
-gboolean thunar_chooser_model_get_loading (ThunarChooserModel *model);
-
-ThunarVfsMimeInfo *thunar_chooser_model_get_mime_info (ThunarChooserModel *model);
-
-gboolean thunar_chooser_model_remove (ThunarChooserModel *model,
- GtkTreeIter *iter,
- GError **error);
-
G_END_DECLS;
#endif /* !__THUNAR_CHOOSER_MODEL_H__ */
Modified: thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c 2009-04-13 02:22:25 UTC (rev 29789)
+++ thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c 2009-04-13 02:59:04 UTC (rev 29790)
@@ -1,6 +1,7 @@
/* $Id$ */
/*-
* Copyright (c) 2005-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
More information about the Xfce4-commits
mailing list