void dlg_package_installer (FrWindow *window, FrArchive *archive, FrAction action) { InstallerData *idata; GType command_type; FrCommand *command; idata = g_new0 (InstallerData, 1); idata->window = g_object_ref (window); idata->archive = g_object_ref (archive); idata->action = action; command_type = get_preferred_command_for_mime_type (idata->archive->content_type, FR_COMMAND_CAN_READ_WRITE); if (command_type == 0) command_type = get_preferred_command_for_mime_type (idata->archive->content_type, FR_COMMAND_CAN_READ); if (command_type == 0) { package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, _("Archive type not supported.")); return; } command = g_object_new (command_type, 0); idata->packages = fr_command_get_packages (command, idata->archive->content_type); g_object_unref (command); if (idata->packages == NULL) { package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, _("Archive type not supported.")); return; } #ifdef ENABLE_PACKAGEKIT { char *secondary_text; GtkWidget *dialog; secondary_text = g_strdup_printf (_("There is no command installed for %s files.\nDo you want to search for a command to open this file?"), g_content_type_get_description (idata->archive->content_type)); dialog = _gtk_message_dialog_new (GTK_WINDOW (idata->window), GTK_DIALOG_MODAL, GTK_STOCK_DIALOG_ERROR, _("Could not open this file type"), secondary_text, GTK_STOCK_CANCEL, GTK_RESPONSE_NO, _("_Search Command"), GTK_RESPONSE_YES, NULL); g_signal_connect (dialog, "response", G_CALLBACK (confirm_search_dialog_response_cb), idata); gtk_widget_show (dialog); g_free (secondary_text); } #else /* ! ENABLE_PACKAGEKIT */ package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, _("Archive type not supported.")); #endif /* ENABLE_PACKAGEKIT */ }
static void packagekit_install_package_names_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { InstallerData *idata = user_data; GDBusProxy *proxy; GVariant *values; GError *error = NULL; char *message = NULL; proxy = G_DBUS_PROXY (source_object); values = g_dbus_proxy_call_finish (proxy, res, &error); if (values == NULL) { message = g_strdup_printf ("%s\n%s", _("There was an internal error trying to search for applications:"), error->message); g_clear_error (&error); } package_installer_terminated (idata, message); g_free (message); if (values != NULL) g_variant_unref (values); g_object_unref (proxy); }
static void packagekit_install_package_names_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { InstallerData *idata = user_data; GDBusProxy *proxy; GVariant *values; GError *error = NULL; FrProcErrorType error_type = FR_PROC_ERROR_NONE; char *error_message = NULL; proxy = G_DBUS_PROXY (source_object); values = g_dbus_proxy_call_finish (proxy, res, &error); if (values == NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) || (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR) && (error->message != NULL) && (strstr (error->message, "org.freedesktop.Packagekit.Modify.Cancelled") != NULL))) { error_type = FR_PROC_ERROR_STOPPED; error_message = NULL; } else { error_type = FR_PROC_ERROR_GENERIC; error_message = g_strdup_printf ("%s\n%s", _("There was an internal error trying to search for applications:"), error->message); } g_clear_error (&error); } package_installer_terminated (idata, error_type, error_message); g_free (error_message); if (values != NULL) g_variant_unref (values); g_object_unref (proxy); }
static void install_packages (InstallerData *idata) { GDBusConnection *connection; GError *error = NULL; connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (connection != NULL) { GdkWindow *window; GDBusProxy *proxy; window = gtk_widget_get_window (GTK_WIDGET (idata->window)); if (window != NULL) { GdkCursor *cursor; GdkDisplay *display; display = gtk_widget_get_display (GTK_WIDGET (idata)); cursor = gdk_cursor_new_for_display (display, GDK_WATCH); gdk_window_set_cursor (window, cursor); g_object_unref (cursor); } proxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit.Modify", NULL, &error); if (proxy != NULL) { guint xid; char **names; char **real_names; if (window != NULL) xid = GDK_WINDOW_XID (window); else xid = 0; names = g_strsplit (idata->packages, ",", -1); real_names = get_packages_real_names (names); g_dbus_proxy_call (proxy, "InstallPackageNames", g_variant_new ("(u^ass)", xid, names, "hide-confirm-search,hide-finished,hide-warning"), G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, packagekit_install_package_names_ready_cb, idata); g_strfreev (real_names); g_strfreev (names); } } if (error != NULL) { char *message; message = g_strdup_printf ("%s\n%s", _("There was an internal error trying to search for applications:"), error->message); package_installer_terminated (idata, FR_PROC_ERROR_GENERIC, message); g_clear_error (&error); } }
static void file_buffer_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { InstallerData *idata = user_data; GFile *file; char *buffer; gsize buffer_size; GError *error = NULL; char *uri; const char *mime_type; gboolean result_uncertain; GType archive_type; FrArchive *preferred_archive; file = G_FILE (source_object); if (! _g_file_load_buffer_finish (file, result, &buffer, &buffer_size, &error)) { package_installer_terminated (idata, FR_ERROR_GENERIC, error->message); g_error_free (error); return; } uri = g_file_get_uri (file); mime_type = g_content_type_guess (uri, (guchar *) buffer, buffer_size, &result_uncertain); if (result_uncertain) { mime_type = _g_mime_type_get_from_content (buffer, buffer_size); if (mime_type == NULL) mime_type = _g_mime_type_get_from_filename (file); } g_free (uri); g_free (buffer); archive_type = get_preferred_archive_for_mime_type (mime_type, FR_ARCHIVE_CAN_READ_WRITE); if (archive_type == 0) archive_type = get_preferred_archive_for_mime_type (mime_type, FR_ARCHIVE_CAN_READ); if (archive_type == 0) { package_installer_terminated (idata, FR_ERROR_GENERIC, _("Archive type not supported.")); return; } preferred_archive = g_object_new (archive_type, 0); idata->packages = fr_archive_get_packages (preferred_archive, mime_type); g_object_unref (preferred_archive); if (idata->packages == NULL) { package_installer_terminated (idata, FR_ERROR_GENERIC, _("Archive type not supported.")); return; } #ifdef ENABLE_PACKAGEKIT { char *secondary_text; GtkWidget *dialog; secondary_text = g_strdup_printf (_("There is no command installed for %s files.\nDo you want to search for a command to open this file?"), g_content_type_get_description (mime_type)); dialog = _gtk_message_dialog_new (GTK_WINDOW (idata->window), GTK_DIALOG_MODAL, GTK_STOCK_DIALOG_ERROR, _("Could not open this file type"), secondary_text, GTK_STOCK_CANCEL, GTK_RESPONSE_NO, _("_Search Command"), GTK_RESPONSE_YES, NULL); g_signal_connect (dialog, "response", G_CALLBACK (confirm_search_dialog_response_cb), idata); gtk_widget_show (dialog); g_free (secondary_text); } #else /* ! ENABLE_PACKAGEKIT */ package_installer_terminated (idata, FR_ERROR_GENERIC, _("Archive type not supported.")); #endif /* ENABLE_PACKAGEKIT */ }