static FrRegisteredArchive * fr_registered_archive_new (GType command_type) { FrRegisteredArchive *reg_com; FrArchive *archive; const char **mime_types; int i; reg_com = g_new0 (FrRegisteredArchive, 1); reg_com->ref = 1; reg_com->type = command_type; reg_com->caps = g_ptr_array_new (); reg_com->packages = g_ptr_array_new (); archive = (FrArchive*) g_object_new (reg_com->type, NULL); mime_types = fr_archive_get_supported_types (archive); for (i = 0; mime_types[i] != NULL; i++) { const char *mime_type; FrMimeTypeCap *cap; FrMimeTypePackages *packages; mime_type = _g_str_get_static (mime_types[i]); cap = g_new0 (FrMimeTypeCap, 1); cap->mime_type = mime_type; cap->current_capabilities = fr_archive_get_capabilities (archive, mime_type, TRUE); cap->potential_capabilities = fr_archive_get_capabilities (archive, mime_type, FALSE); g_ptr_array_add (reg_com->caps, cap); packages = g_new0 (FrMimeTypePackages, 1); packages->mime_type = mime_type; packages->packages = fr_archive_get_packages (archive, mime_type); g_ptr_array_add (reg_com->packages, packages); } g_object_unref (archive); return reg_com; }
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 */ }