nautilus r15171 - in trunk: . libnautilus-private
- From: alexl svn gnome org
- To: svn-commits-list gnome org
- Subject: nautilus r15171 - in trunk: . libnautilus-private
- Date: Wed, 8 Apr 2009 11:12:07 +0000 (UTC)
Author: alexl
Date: Wed Apr 8 11:12:07 2009
New Revision: 15171
URL: http://svn.gnome.org/viewvc/nautilus?rev=15171&view=rev
Log:
2009-04-08 Alexander Larsson <alexl redhat com>
* libnautilus-private/nautilus-mime-actions.c:
Make sure PackageKit is active before showing
install dialog.
Patch from James Westby
Modified:
trunk/ChangeLog
trunk/libnautilus-private/nautilus-mime-actions.c
Modified: trunk/libnautilus-private/nautilus-mime-actions.c
==============================================================================
--- trunk/libnautilus-private/nautilus-mime-actions.c (original)
+++ trunk/libnautilus-private/nautilus-mime-actions.c Wed Apr 8 11:12:07 2009
@@ -1136,6 +1136,7 @@
NautilusWindowOpenFlags flags;
char *activation_directory;
gboolean user_confirmation;
+ char *uri;
} ActivateParametersInstall;
static void
@@ -1150,9 +1151,59 @@
nautilus_file_unref (parameters_install->file);
nautilus_file_list_free (parameters_install->files);
g_free (parameters_install->activation_directory);
+ g_free (parameters_install->uri);
g_free (parameters_install);
}
+static char *
+get_application_no_mime_type_handler_message (NautilusFile *file, char *uri)
+{
+ char *uri_for_display;
+ char *nice_uri;
+ char *error_message;
+ GFile *location;
+
+ /* For local files, we want to use filename if possible */
+ if (nautilus_file_is_local (file)) {
+ location = nautilus_file_get_location (file);
+ nice_uri = g_file_get_parse_name (location);
+ g_object_unref (location);
+ } else {
+ nice_uri = g_strdup (uri);
+ }
+
+ /* Truncate the URI so it doesn't get insanely wide. Note that even
+ * though the dialog uses wrapped text, if the URI doesn't contain
+ * white space then the text-wrapping code is too stupid to wrap it.
+ */
+ uri_for_display = eel_str_middle_truncate (nice_uri, MAX_URI_IN_DIALOG_LENGTH);
+ error_message = g_strdup_printf (_("Could not display \"%s\"."), uri_for_display);
+ g_free (nice_uri);
+ g_free (uri_for_display);
+ return error_message;
+}
+
+static void
+show_unhandled_type_error (ActivateParametersInstall *parameters)
+{
+ char *mime_type = nautilus_file_get_mime_type (parameters->file);
+ char *error_message = get_application_no_mime_type_handler_message (parameters->file, parameters->uri);
+ if (g_content_type_is_unknown (mime_type)) {
+ eel_show_error_dialog (error_message,
+ _("The file is of an unknown type"),
+ parameters->parent_window);
+ } else {
+ char *text;
+ text = g_strdup_printf (_("There is no application installed for %s files"), g_content_type_get_description (mime_type));
+ eel_show_error_dialog (error_message,
+ text,
+ parameters->parent_window);
+ g_free (text);
+ }
+ g_free (error_message);
+ g_free (mime_type);
+}
+
static void
search_for_application_dbus_call_notify_cb (DBusGProxy *proxy, DBusGProxyCall *call, ActivateParametersInstall *parameters_install)
{
@@ -1207,7 +1258,6 @@
/* get bus */
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (connection == NULL) {
- g_warning ("Could not connect to session bus: %s\n", error->message);
g_error_free (error);
goto out;
}
@@ -1218,7 +1268,6 @@
"/org/freedesktop/PackageKit",
"org.freedesktop.PackageKit.Modify");
if (proxy == NULL) {
- g_warning ("Could not connect to PackageKit session service\n");
goto out;
}
@@ -1282,68 +1331,32 @@
}
static void
-application_unhandled_uri (ActivateParameters *parameters, char *uri)
+packagekit_present_dbus_call_notify_cb (DBusGProxy *proxy, DBusGProxyCall *call, ActivateParametersInstall *parameters_install)
{
- char *uri_for_display;
- char *nice_uri;
+ gboolean ret;
+ GError *error = NULL;
+ char *mime_type;
char *error_message;
- gboolean show_install_mime;
+ gboolean present;
GtkWidget *dialog;
- char *mime_type;
- char *text;
- GFile *location;
- NautilusFile *file;
- ActivateParametersInstall *parameters_install;
-
- file = nautilus_file_get_by_uri (uri);
- /* For local files, we want to use filename if possible */
- if (nautilus_file_is_local (file)) {
- location = nautilus_file_get_location (file);
- nice_uri = g_file_get_parse_name (location);
- g_object_unref (location);
- } else {
- nice_uri = g_strdup (uri);
- }
-
- /* Truncate the URI so it doesn't get insanely wide. Note that even
- * though the dialog uses wrapped text, if the URI doesn't contain
- * white space then the text-wrapping code is too stupid to wrap it.
- */
- uri_for_display = eel_str_middle_truncate (nice_uri, MAX_URI_IN_DIALOG_LENGTH);
- error_message = g_strdup_printf (_("Could not display \"%s\"."), uri_for_display);
- g_free (nice_uri);
- g_free (uri_for_display);
- mime_type = nautilus_file_get_mime_type (file);
-
-#ifdef ENABLE_PACKAGEKIT
- /* allow an admin to disable the PackageKit search functionality */
- show_install_mime = eel_preferences_get_boolean (NAUTILUS_PREFERENCES_INSTALL_MIME_ACTIVATION);
-#else
- /* we have no install functionality */
- show_install_mime = FALSE;
-#endif
- /* There is no use trying to look for handlers of application/octet-stream */
- if (g_content_type_is_unknown (mime_type)) {
- show_install_mime = FALSE;
+ ret = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_BOOLEAN, &present, G_TYPE_INVALID);
+ if (!ret) {
+ g_error_free (error);
+ show_unhandled_type_error (parameters_install);
+ activate_parameters_install_free (parameters_install);
+ present = FALSE;
+ goto out;
}
- if (!show_install_mime) {
- /* show an unhelpful dialog */
- if (g_content_type_is_unknown (mime_type)) {
- eel_show_error_dialog (error_message,
- _("The file is of an unknown type"),
- parameters->parent_window);
- } else {
- text = g_strdup_printf (_("There is no application installed for %s files"), g_content_type_get_description (mime_type));
- eel_show_error_dialog (error_message,
- text,
- parameters->parent_window);
- g_free (text);
- }
+ if (!present) {
+ show_unhandled_type_error (parameters_install);
+ activate_parameters_install_free (parameters_install);
goto out;
}
+ mime_type = nautilus_file_get_mime_type (parameters_install->file);
+ error_message = get_application_no_mime_type_handler_message (parameters_install->file, parameters_install->uri);
/* use a custom dialog to prompt the user to install new software */
dialog = gtk_message_dialog_new (NULL, 0,
GTK_MESSAGE_ERROR,
@@ -1354,6 +1367,30 @@
g_content_type_get_description (mime_type));
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ g_signal_connect (dialog, "response", G_CALLBACK (application_unhandled_file_install), parameters_install);
+ gtk_widget_show_all (dialog);
+ g_free (mime_type);
+
+out:
+ g_object_unref (proxy);
+}
+
+static void
+application_unhandled_uri (ActivateParameters *parameters, char *uri)
+{
+ gboolean show_install_mime;
+ char *mime_type;
+ NautilusFile *file;
+ ActivateParametersInstall *parameters_install;
+ DBusGConnection *connection;
+ DBusGProxy *proxy;
+ DBusGProxyCall *call;
+ GError *error = NULL;
+
+ file = nautilus_file_get_by_uri (uri);
+
+ mime_type = nautilus_file_get_mime_type (file);
+
/* copy the parts of parameters we are interested in as the orignal will be unref'd */
parameters_install = g_new0 (ActivateParametersInstall, 1);
parameters_install->slot_info = parameters->slot_info;
@@ -1368,13 +1405,62 @@
parameters_install->mode = parameters->mode;
parameters_install->flags = parameters->flags;
parameters_install->user_confirmation = parameters->user_confirmation;
+ parameters_install->uri = g_strdup(uri);
+
+#ifdef ENABLE_PACKAGEKIT
+ /* allow an admin to disable the PackageKit search functionality */
+ show_install_mime = eel_preferences_get_boolean (NAUTILUS_PREFERENCES_INSTALL_MIME_ACTIVATION);
+#else
+ /* we have no install functionality */
+ show_install_mime = FALSE;
+#endif
+ /* There is no use trying to look for handlers of application/octet-stream */
+ if (g_content_type_is_unknown (mime_type)) {
+ show_install_mime = FALSE;
+ }
+
+ if (!show_install_mime) {
+ goto out;
+ }
+
+ /* Check whether PackageKit can be spawned */
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ if (connection == NULL) {
+ g_error_free (error);
+ show_install_mime = FALSE;
+ goto out;
+ }
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+
+ if (proxy == NULL) {
+ show_install_mime = FALSE;
+ goto out;
+ }
+ call = dbus_g_proxy_begin_call (proxy, "NameHasOwner",
+ (DBusGProxyCallNotify) packagekit_present_dbus_call_notify_cb,
+ parameters_install,
+ NULL, /* Don't want to free user_data as we need to pass it on */
+ G_TYPE_STRING, "org.freedesktop.PackageKit",
+ G_TYPE_INVALID);
+ if (call == NULL) {
+ show_install_mime = FALSE;
+ goto out;
+ }
- g_signal_connect (dialog, "response", G_CALLBACK (application_unhandled_file_install), parameters_install);
- gtk_widget_show_all (dialog);
out:
+ if (!show_install_mime) {
+ /* show an unhelpful dialog */
+ show_unhandled_type_error (parameters_install);
+ /* The callback wasn't started, so we have to free the parameters */
+ activate_parameters_install_free (parameters_install);
+ }
+
nautilus_file_unref (file);
g_free (mime_type);
- g_free (error_message);
}
typedef struct {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]