Permalink
Browse files

Add a warning when enabling the LVFS remote

Distributions like RHEL do not enable the LVFS by default and the legal team
here say we need to add some agreement text which is shown before we enable
downloading content from an external source.

No new strings, so no translation freeze break.
  • Loading branch information...
hughsie committed Apr 16, 2018
1 parent 3f510b6 commit d695afcf9a762fdee500c26e9d42e7f42149d950
Showing with 120 additions and 10 deletions.
  1. +40 −0 lib/gs-app.c
  2. +4 −1 lib/gs-app.h
  3. +3 −0 plugins/fwupd/gs-plugin-fwupd.c
  4. +73 −9 src/gs-repos-dialog.c
@@ -71,6 +71,7 @@ typedef struct
GPtrArray *source_ids;
gchar *project_group;
gchar *developer_name;
gchar *agreement;
gchar *version;
gchar *version_ui;
gchar *summary;
@@ -1688,6 +1689,44 @@ gs_app_add_icon (GsApp *app, AsIcon *icon)
g_ptr_array_add (priv->icons, g_object_ref (icon));
}

/**
* gs_app_get_agreement:
* @app: a #GsApp
*
* Gets the agreement text for the application.
*
* Returns: a string in AppStream description format, or %NULL for unset
*
* Since: 3.28
**/
const gchar *
gs_app_get_agreement (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
g_return_val_if_fail (GS_IS_APP (app), NULL);
return priv->agreement;
}

/**
* gs_app_set_agreement:
* @app: a #GsApp
* @agreement: The agreement text, e.g. "<p>Foobar</p>"
*
* Sets the application end-user agreement (e.g. a EULA) in AppStream
* description format.
*
* Since: 3.28
**/
void
gs_app_set_agreement (GsApp *app, const gchar *agreement)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
locker = g_mutex_locker_new (&priv->mutex);
_g_set_str (&priv->agreement, agreement);
}

/**
* gs_app_get_local_file:
* @app: a #GsApp
@@ -4208,6 +4247,7 @@ gs_app_finalize (GObject *object)
g_ptr_array_unref (priv->source_ids);
g_free (priv->project_group);
g_free (priv->developer_name);
g_free (priv->agreement);
g_free (priv->version);
g_free (priv->version_ui);
g_free (priv->summary);
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2013-2017 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2013-2018 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2014-2015 Kalev Lember <klember@redhat.com>
*
* Licensed under the GNU General Public License Version 2
@@ -166,6 +166,9 @@ void gs_app_set_project_group (GsApp *app,
const gchar *gs_app_get_developer_name (GsApp *app);
void gs_app_set_developer_name (GsApp *app,
const gchar *developer_name);
const gchar *gs_app_get_agreement (GsApp *app);
void gs_app_set_agreement (GsApp *app,
const gchar *agreement);
const gchar *gs_app_get_version (GsApp *app);
const gchar *gs_app_get_version_ui (GsApp *app);
void gs_app_set_version (GsApp *app,
@@ -1080,6 +1080,9 @@ gs_plugin_add_sources (GsPlugin *plugin,
gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
gs_app_set_name (app, GS_APP_QUALITY_LOWEST,
fwupd_remote_get_title (remote));
#if FWUPD_CHECK_VERSION(1,0,7)
gs_app_set_agreement (app, fwupd_remote_get_agreement (remote));
#endif
gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
fwupd_remote_get_metadata_uri (remote));
gs_app_set_metadata (app, "fwupd::remote-id",
@@ -181,19 +181,13 @@ repo_enabled_cb (GObject *source,
}

static void
enable_repo (GsReposDialog *dialog, GsApp *repo)
_enable_repo (InstallRemoveData *install_data)
{
InstallRemoveData *install_data;
GsReposDialog *dialog = install_data->dialog;
g_autoptr(GsPluginJob) plugin_job = NULL;

install_data = g_slice_new0 (InstallRemoveData);
install_data->action = GS_PLUGIN_ACTION_INSTALL;
install_data->repo = g_object_ref (repo);
install_data->dialog = g_object_ref (dialog);

g_debug ("enabling repo %s", gs_app_get_id (install_data->repo));
plugin_job = gs_plugin_job_newv (install_data->action,
"app", repo,
"app", install_data->repo,
"failure-flags", GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS,
NULL);
gs_plugin_loader_job_process_async (dialog->plugin_loader, plugin_job,
@@ -202,6 +196,76 @@ enable_repo (GsReposDialog *dialog, GsApp *repo)
install_data);
}

static void
enable_repo_response_cb (GtkDialog *confirm_dialog,
gint response,
gpointer user_data)
{
g_autoptr(InstallRemoveData) install_data = (InstallRemoveData *) user_data;

/* unmap the dialog */
gtk_widget_destroy (GTK_WIDGET (confirm_dialog));

/* not agreed */
if (response != GTK_RESPONSE_OK)
return;

_enable_repo (g_steal_pointer (&install_data));
}

static void
enable_repo (GsReposDialog *dialog, GsApp *repo)
{
g_autoptr(InstallRemoveData) install_data = NULL;

install_data = g_slice_new0 (InstallRemoveData);
install_data->action = GS_PLUGIN_ACTION_INSTALL;
install_data->repo = g_object_ref (repo);
install_data->dialog = g_object_ref (dialog);

/* user needs to confirm acceptance of an agreement */
if (gs_app_get_agreement (repo) != NULL) {
GtkWidget *confirm_dialog;
g_autofree gchar *message = NULL;
g_autoptr(GError) error = NULL;

/* convert from AppStream markup */
message = as_markup_convert_simple (gs_app_get_agreement (repo), &error);
if (message == NULL) {
/* failed, so just try and show the original markup */
message = g_strdup (gs_app_get_agreement (repo));
g_warning ("Failed to process AppStream markup: %s",
error->message);
}

/* ask for confirmation */
confirm_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_CANCEL,
/* TRANSLATORS: window title */
"%s", _("Enable Third-Party Software Repository?"));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (confirm_dialog),
"%s", message);

/* TRANSLATORS: button to accept the agreement */
gtk_dialog_add_button (GTK_DIALOG (confirm_dialog), _("Enable"),
GTK_RESPONSE_OK);

/* handle this async */
g_signal_connect (confirm_dialog, "response",
G_CALLBACK (enable_repo_response_cb),
g_steal_pointer (&install_data));

gtk_window_set_modal (GTK_WINDOW (confirm_dialog), TRUE);
gtk_window_present (GTK_WINDOW (confirm_dialog));
return;
}

/* no prompt required */
_enable_repo (g_steal_pointer (&install_data));
}

static void
remove_repo_response_cb (GtkDialog *confirm_dialog,
gint response,

0 comments on commit d695afc

Please sign in to comment.