/**
 * pk_action_lookup_package_ids_to_string:
 **/
static gchar *
pk_action_lookup_package_ids_to_string (gchar **package_ids)
{
	gchar **split;
	GPtrArray *array = NULL;
	gchar **names = NULL;
	gchar *names_str = NULL;
	guint i;
	guint len;

	/* invalid */
	if (package_ids == NULL)
		goto out;

	/* we show different data for different numbers of packages */
	len = g_strv_length (package_ids);
	if (len > 5) {
		/* TRANSLATORS: too many packages to list each one */
		names_str = g_strdup (N_("Many packages"));
		goto out;
	}

	/* create array of name-version */
	array = g_ptr_array_new ();
	for (i=0; package_ids[i] != NULL; i++) {
		split = pk_package_id_split (package_ids[i]);
		if (len == 1) {
			names_str = g_strdup_printf ("%s-%s (%s)",
						     split[PK_PACKAGE_ID_NAME],
						     split[PK_PACKAGE_ID_VERSION],
						     split[PK_PACKAGE_ID_DATA]);
		} else if (len <= 3) {
			names_str = g_strdup_printf ("%s-%s",
						     split[PK_PACKAGE_ID_NAME],
						     split[PK_PACKAGE_ID_VERSION]);
		} else {
			names_str = g_strdup (split[PK_PACKAGE_ID_NAME]);
		}
		g_ptr_array_add (array, names_str);
		g_strfreev (split);
	}

	/* create string */
	names = pk_ptr_array_to_strv (array);
	names_str = g_strjoinv (", ", names);
out:
	if (array != NULL) {
		g_ptr_array_foreach (array, (GFunc) g_free, NULL);
		g_ptr_array_free (array, TRUE);
	}
	g_strfreev (names);
	return names_str;
}
Esempio n. 2
0
/**
 * pk_debuginfo_install_packages_install:
 **/
static gboolean
pk_debuginfo_install_packages_install (PkDebuginfoInstallPrivate *priv, GPtrArray *array, GError **error)
{
	gboolean ret = TRUE;
	PkResults *results = NULL;
	gchar **package_ids;
	GError *error_local = NULL;
	PkError *error_code = NULL;

	/* mush back into a char** */
	package_ids = pk_ptr_array_to_strv (array);

	/* TRANSLATORS: we are starting to install the packages */
	pk_progress_bar_start (priv->progress_bar, _("Starting install"));

	/* enable this repo */
	results = pk_task_install_packages_sync (PK_TASK(priv->client), package_ids, NULL,
						 (PkProgressCallback) pk_debuginfo_install_progress_cb, priv, &error_local);
	if (results == NULL) {
		*error = g_error_new (1, 0, "failed to install packages: %s", error_local->message);
		g_error_free (error_local);
		ret = FALSE;
		goto out;
	}

	/* check error code */
	error_code = pk_results_get_error_code (results);
	if (error_code != NULL) {
		*error = g_error_new (1, 0, "failed to resolve: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code));
		ret = FALSE;
		goto out;
	}

	/* end progressbar output */
	pk_progress_bar_end (priv->progress_bar);
out:
	if (error_code != NULL)
		g_object_unref (error_code);
	if (results != NULL)
		g_object_unref (results);
	g_strfreev (package_ids);
	return ret;
}
Esempio n. 3
0
/**
 * main:
 **/
int
main (int argc, gchar **argv)
{
    GOptionContext *context;
    guint i;
    guint len;
    gboolean ret;
    gchar **codecs = NULL;
    gint xid = 0;
    const gchar *suffix;
    gchar *resource;
    _cleanup_error_free_ GError *error = NULL;
    _cleanup_free_ gchar *desktop_id = NULL;
    _cleanup_free_ gchar *interaction = NULL;
    _cleanup_free_ gchar *startup_id = NULL;
    _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
    _cleanup_strv_free_ gchar **resources = NULL;

    const GOptionEntry options[] = {
        { "transient-for", '\0', 0, G_OPTION_ARG_INT, &xid, "The XID of the parent window", NULL },
        { "desktop-id", '\0', 0, G_OPTION_ARG_STRING, &desktop_id, "The desktop ID of the calling application", NULL },
        { "interaction", '\0', 0, G_OPTION_ARG_STRING, &interaction, "Interaction mode specifying which UI elements should be shown", NULL },
        { "startup-notification-id", '\0', 0, G_OPTION_ARG_STRING, &startup_id, "The startup notification ID for focus stealing prevention", NULL },
        { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL },
        { NULL }
    };

#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 35)
    g_type_init ();
#endif

    gst_init (&argc, &argv);

    context = g_option_context_new ("Install missing codecs");
    g_option_context_add_main_entries (context, options, NULL);

    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
                 error->message, argv[0]);
        return GST_INSTALL_PLUGINS_ERROR;
    }
    if (codecs == NULL) {
        g_print ("Missing codecs information\n");
        g_print ("Run 'with --help' to see a full list of available command line options.\n");
        return GST_INSTALL_PLUGINS_ERROR;
    }

    /* this is our parent window */
    g_message ("PackageKit: xid = %i", xid);
    g_message ("PackageKit: desktop_id = %s", desktop_id);

    /* use a ()(64bit) suffix for 64 bit */
    suffix = pk_gst_get_arch_suffix ();

    array = g_ptr_array_new_with_free_func (g_free);
    len = g_strv_length (codecs);

    /* process argv */
    for (i = 0; i < len; i++) {
        PkGstCodecInfo *info;
        gchar *type;
        const gchar *gstreamer_version;

        info = pk_gst_parse_codec (codecs[i]);
        if (info == NULL) {
            g_message ("skipping %s", codecs[i]);
            continue;
        }

        /* gstreamer1 is the provide name used for the
         * first version of the new release */
        if (g_strcmp0 (info->gstreamer_version, "1.0") == 0)
            gstreamer_version = "1";
        else
            gstreamer_version = info->gstreamer_version;

        g_message ("PackageKit: Codec nice name: %s", info->codec_name);
        if (info->structure != NULL) {
            _cleanup_free_ gchar *s = NULL;
            s = pk_gst_structure_to_provide (info->structure);
            type = g_strdup_printf ("gstreamer%s(%s-%s)%s%s",
                                    gstreamer_version,
                                    info->type_name,
                                    gst_structure_get_name (info->structure),
                                    s, suffix);
            g_message ("PackageKit: structure: %s", type);
        } else {
            type = g_strdup_printf ("gstreamer%s(%s)%s",
                                    gstreamer_version,
                                    info->type_name,
                                    suffix);
            g_message ("PackageKit: non-structure: %s", type);
        }

        /* "encode" */
        resource = g_strdup_printf ("%s|%s", info->codec_name, type);
        g_ptr_array_add (array, resource);

        /* free codec structure */
        pk_gst_codec_free (info);
    }

    /* nothing parsed */
    if (array->len == 0) {
        g_message ("no codec lines could be parsed");
        return GST_INSTALL_PLUGINS_ERROR;
    }

    /* convert to a GStrv */
    resources = pk_ptr_array_to_strv (array);

    /* first try the new interface */
    ret = pk_gst_dbus_install_resources (resources, desktop_id, startup_id, interaction, &error);
    if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
        /* ... and if that fails, fall back to the compat interface */
        g_clear_error (&error);
        g_message ("PackageKit: falling back to compat dbus interface");
        ret = pk_gst_dbus_install_resources_compat (resources, xid, &error);
    }
    if (!ret) {
        /* use the error string to return a good GStreamer exit code */
        g_message ("PackageKit: Did not install codec: %s", error->message);
        if (g_strrstr (error->message, "did not agree to search") != NULL)
            return GST_INSTALL_PLUGINS_USER_ABORT;
        if (g_strrstr (error->message, "not all codecs were installed") != NULL)
            return GST_INSTALL_PLUGINS_PARTIAL_SUCCESS;
        return GST_INSTALL_PLUGINS_NOT_FOUND;
    }
    return GST_INSTALL_PLUGINS_SUCCESS;
}
Esempio n. 4
0
/**
 * pk_debuginfo_install_add_deps:
 **/
static gboolean
pk_debuginfo_install_add_deps (PkDebuginfoInstallPrivate *priv, GPtrArray *packages_search, GPtrArray *packages_results, GError **error)
{
	gboolean ret = TRUE;
	PkResults *results = NULL;
	PkPackage *item;
	gchar *package_id = NULL;
	GPtrArray *list = NULL;
	GError *error_local = NULL;
	gchar **package_ids = NULL;
	gchar *name_debuginfo;
	guint i;
	gchar **split;
	PkError *error_code = NULL;

	/* get depends for them all, not adding dup's */
	package_ids = pk_ptr_array_to_strv (packages_search);
	results = pk_client_get_depends (priv->client, pk_bitfield_value (PK_FILTER_ENUM_NONE), package_ids, TRUE, NULL, NULL, NULL, &error_local);
	if (results == NULL) {
		*error = g_error_new (1, 0, "failed to get_depends: %s", error_local->message);
		g_error_free (error_local);
		ret = FALSE;
		goto out;
	}

	/* check error code */
	error_code = pk_results_get_error_code (results);
	if (error_code != NULL) {
		*error = g_error_new (1, 0, "failed to get depends: %s, %s", pk_error_enum_to_string (pk_error_get_code (error_code)), pk_error_get_details (error_code));
		ret = FALSE;
		goto out;
	}

	/* add dependent packages */
	list = pk_results_get_package_array (results);
	for (i=0; i<list->len; i++) {
		item = g_ptr_array_index (list, i);
		split = pk_package_id_split (pk_package_get_id (item));
		/* add -debuginfo */
		name_debuginfo = pk_debuginfo_install_name_to_debuginfo (split[PK_PACKAGE_ID_NAME]);
		g_strfreev (split);

		/* resolve name */
		g_debug ("resolving: %s", name_debuginfo);
		package_id = pk_debuginfo_install_resolve_name_to_id (priv, name_debuginfo, &error_local);
		if (package_id == NULL) {
			/* TRANSLATORS: we couldn't find the package name, non-fatal */
			g_print (_("Failed to find the package %s, or already installed: %s"), name_debuginfo, error_local->message);
			g_print ("\n");
			g_error_free (error_local);
			/* don't quit, this is non-fatal */
			error = NULL;
		}

		/* add to array to install */
		if (package_id != NULL && !g_str_has_suffix (package_id, "installed")) {
			g_debug ("going to try to install (for deps): %s", package_id);
			g_ptr_array_add (packages_results, g_strdup (package_id));
		}

		g_free (package_id);
		g_free (name_debuginfo);
	}
out:
	if (error_code != NULL)
		g_object_unref (error_code);
	if (results != NULL)
		g_object_unref (results);
	if (list != NULL)
		g_ptr_array_unref (list);
	g_strfreev (package_ids);
	return ret;
}
/**
 * pk_plugin_transaction_finished_results:
 */
void
pk_plugin_transaction_finished_results (PkPlugin *plugin,
					PkTransaction *transaction)
{
	gchar **package_ids = NULL;
	gchar *package_id_tmp;
	GPtrArray *array = NULL;
	GPtrArray *list = NULL;
	guint i;
	PkInfoEnum info;
	PkPackage *item;
	PkResults *results;
	PkRoleEnum role;

	/* skip simulate actions */
	if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction),
				 PK_TRANSACTION_FLAG_ENUM_SIMULATE)) {
		goto out;
	}

	/* skip only-download */
	if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction),
				 PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) {
		goto out;
	}

	/* load */
	if (plugin->priv->db == NULL)
		pk_transaction_plugin_load_db (plugin, transaction);

	/* no database */
	if (plugin->priv->db == NULL)
		goto out;

	/* check the role */
	role = pk_transaction_get_role (transaction);
	if (role != PK_ROLE_ENUM_INSTALL_PACKAGES)
		goto out;

	/* connect to backend */
	if (!pk_backend_is_implemented (plugin->backend,
					PK_ROLE_ENUM_GET_FILES)) {
		g_debug ("cannot get files");
		goto out;
	}

	/* get results */
	results = pk_transaction_get_results (transaction);
	array = pk_results_get_package_array (results);

	/* filter on INSTALLING | UPDATING */
	list = g_ptr_array_new_with_free_func (g_free);
	for (i=0; i<array->len; i++) {
		item = g_ptr_array_index (array, i);
		info = pk_package_get_info (item);
		if (info == PK_INFO_ENUM_INSTALLING ||
		    info == PK_INFO_ENUM_UPDATING) {
			/* we convert the package_id data to be 'installed' */
			package_id_tmp = pk_package_id_build (pk_package_get_name (item),
							      pk_package_get_version (item),
							      pk_package_get_arch (item),
							      "installed");
			g_ptr_array_add (list, package_id_tmp);
		}
	}

	/* process file lists on these packages */
	g_debug ("processing %i packags for desktop files", list->len);
	if (list->len == 0)
		goto out;

	/* get all the files touched in the packages we just installed */
	pk_backend_reset_job (plugin->backend, plugin->job);
	pk_backend_job_set_vfunc (plugin->job,
				  PK_BACKEND_SIGNAL_FINISHED,
				  (PkBackendJobVFunc) pk_plugin_finished_cb,
				  plugin);
	pk_backend_job_set_vfunc (plugin->job,
				  PK_BACKEND_SIGNAL_FILES,
				  (PkBackendJobVFunc) pk_plugin_files_cb,
				  plugin);
	pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_SCAN_APPLICATIONS);
	pk_backend_job_set_percentage (plugin->job, 101);
	package_ids = pk_ptr_array_to_strv (list);
	pk_backend_get_files (plugin->backend, plugin->job, package_ids);

	/* wait for finished */
	g_main_loop_run (plugin->priv->loop);

	pk_backend_job_set_percentage (plugin->job, 100);
out:
	if (array != NULL)
		g_ptr_array_unref (array);
	if (list != NULL)
		g_ptr_array_unref (list);
	g_strfreev (package_ids);
}
Esempio n. 6
0
/**
 * main:
 **/
int
main (int argc, gchar **argv)
{
	GOptionContext *context;
	guint i;
	guint len;
	gchar **codecs = NULL;
	gint xid = 0;
	const gchar *suffix;
	gchar *resource;
	_cleanup_error_free_ GError *error = NULL;
	_cleanup_object_unref_ GDBusProxy *proxy = NULL;
	_cleanup_ptrarray_unref_ GPtrArray *array = NULL;
	_cleanup_strv_free_ gchar **resources = NULL;
	_cleanup_variant_unref_ GVariant *value = NULL;

	const GOptionEntry options[] = {
		{ "transient-for", '\0', 0, G_OPTION_ARG_INT, &xid, "The XID of the parent window", NULL },
		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL },
		{ NULL }
	};

#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 35)
	g_type_init ();
#endif

	gst_init (&argc, &argv);

	context = g_option_context_new ("Install missing codecs");
	g_option_context_add_main_entries (context, options, NULL);

	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
			 error->message, argv[0]);
		return GST_INSTALL_PLUGINS_ERROR;
	}
	if (codecs == NULL) {
		g_print ("Missing codecs information\n");
		g_print ("Run 'with --help' to see a full list of available command line options.\n");
		return GST_INSTALL_PLUGINS_ERROR;
	}

	/* this is our parent window */
	g_message ("PackageKit: xid = %i", xid);

	/* get proxy */
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
					       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
					       G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
					       NULL,
					       "org.freedesktop.PackageKit",
					       "/org/freedesktop/PackageKit",
					       "org.freedesktop.PackageKit.Modify",
					       NULL,
					       &error);
	if (proxy == NULL) {
		g_warning ("Cannot connect to PackageKit session service: %s",
			   error->message);
		return GST_INSTALL_PLUGINS_ERROR;
	}

	/* use a ()(64bit) suffix for 64 bit */
	suffix = pk_gst_get_arch_suffix ();

	array = g_ptr_array_new_with_free_func (g_free);
	len = g_strv_length (codecs);

	/* process argv */
	for (i = 0; i < len; i++) {
		PkGstCodecInfo *info;
		gchar *type;
		const gchar *gstreamer_version;

		info = pk_gst_parse_codec (codecs[i]);
		if (info == NULL) {
			g_message ("skipping %s", codecs[i]);
			continue;
		}

		/* gstreamer1 is the provide name used for the
		 * first version of the new release */
		if (g_strcmp0 (info->gstreamer_version, "1.0") == 0)
			gstreamer_version = "1";
		else
			gstreamer_version = info->gstreamer_version;

		g_message ("PackageKit: Codec nice name: %s", info->codec_name);
		if (info->structure != NULL) {
			_cleanup_free_ gchar *s = NULL;
			s = pk_gst_structure_to_provide (info->structure);
			type = g_strdup_printf ("gstreamer%s(%s-%s)%s%s",
						gstreamer_version,
						info->type_name,
						gst_structure_get_name (info->structure),
						s, suffix);
			g_message ("PackageKit: structure: %s", type);
		} else {
			type = g_strdup_printf ("gstreamer%s(%s)%s",
						gstreamer_version,
						info->type_name,
						suffix);
			g_message ("PackageKit: non-structure: %s", type);
		}

		/* "encode" */
		resource = g_strdup_printf ("%s|%s", info->codec_name, type);
		g_ptr_array_add (array, resource);

		/* free codec structure */
		pk_gst_codec_free (info);
	}

	/* nothing parsed */
	if (array->len == 0) {
		g_message ("no codec lines could be parsed");
		return GST_INSTALL_PLUGINS_ERROR;
	}

	/* convert to a GStrv */
	resources = pk_ptr_array_to_strv (array);

	/* invoke the method */
	value = g_dbus_proxy_call_sync (proxy,
					"InstallGStreamerResources",
					g_variant_new ("(u^a&ss)",
						       xid,
						       resources,
						       "hide-finished"),
					G_DBUS_CALL_FLAGS_NONE,
					60 * 60 * 1000, /* 1 hour */
					NULL,
					&error);
	if (value == NULL) {
		/* use the error string to return a good GStreamer exit code */
		g_message ("PackageKit: Did not install codec: %s", error->message);
		if (g_strrstr (error->message, "did not agree to search") != NULL)
			return GST_INSTALL_PLUGINS_USER_ABORT;
		if (g_strrstr (error->message, "not all codecs were installed") != NULL)
			return GST_INSTALL_PLUGINS_PARTIAL_SUCCESS;
		return GST_INSTALL_PLUGINS_NOT_FOUND;
	}
	return GST_INSTALL_PLUGINS_SUCCESS;
}