[gnome-software/eula-dialog] temp commit
- From: Jonathan Kang <jonathankang src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/eula-dialog] temp commit
- Date: Mon, 2 Dec 2019 08:55:54 +0000 (UTC)
commit 4a76c3e40d784d8ad6365e077385fe340c620dc8
Author: Jonathan Kang <jonathankang gnome org>
Date: Fri Oct 25 08:44:00 2019 +0800
temp commit
lib/gs-plugin-types.h | 2 +
lib/gs-plugin.c | 4 +
meson.build | 1 +
plugins/packagekit/gs-plugin-packagekit-refresh.c | 23 ++-
plugins/packagekit/gs-task.c | 167 ++++++++++++++++++++++
plugins/packagekit/gs-task.h | 23 +++
plugins/packagekit/meson.build | 1 +
src/gnome-software.gresource.xml | 1 +
src/gs-eula-dialog.c | 117 +++++++++++++++
src/gs-eula-dialog.h | 21 +++
src/gs-eula-dialog.ui | 54 +++++++
src/gs-shell.c | 40 ++++++
src/meson.build | 1 +
13 files changed, 454 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-plugin-types.h b/lib/gs-plugin-types.h
index d6d30d52..3292f3a7 100644
--- a/lib/gs-plugin-types.h
+++ b/lib/gs-plugin-types.h
@@ -227,6 +227,7 @@ typedef enum {
* @GS_PLUGIN_ACTION_DOWNLOAD: Download an application
* @GS_PLUGIN_ACTION_GET_ALTERNATES: Get the alternates for a specific application
* @GS_PLUGIN_ACTION_GET_LANGPACKS: Get appropriate language pack
+ * @GS_PLUGIN_ACTION_SHOW_EULA: Show EULA
*
* The plugin action.
**/
@@ -272,6 +273,7 @@ typedef enum {
GS_PLUGIN_ACTION_DOWNLOAD,
GS_PLUGIN_ACTION_GET_ALTERNATES,
GS_PLUGIN_ACTION_GET_LANGPACKS,
+ GS_PLUGIN_ACTION_SHOW_EULA,
/*< private >*/
GS_PLUGIN_ACTION_LAST
} GsPluginAction;
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index 005e6cdb..a9698e24 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -1591,6 +1591,8 @@ gs_plugin_action_to_function_name (GsPluginAction action)
return "gs_plugin_add_alternates";
if (action == GS_PLUGIN_ACTION_GET_LANGPACKS)
return "gs_plugin_add_langpacks";
+ if (action == GS_PLUGIN_ACTION_SHOW_EULA)
+ return "gs_plugin_show_eula";
return NULL;
}
@@ -1687,6 +1689,8 @@ gs_plugin_action_to_string (GsPluginAction action)
return "get-alternates";
if (action == GS_PLUGIN_ACTION_GET_LANGPACKS)
return "get-langpacks";
+ if (action == GS_PLUGIN_ACTION_SHOW_EULA)
+ return "show-eula";
return NULL;
}
diff --git a/meson.build b/meson.build
index 36e117d7..0222f993 100644
--- a/meson.build
+++ b/meson.build
@@ -96,6 +96,7 @@ add_project_arguments('-D_GNU_SOURCE', language : 'c')
conf.set('HAVE_LINUX_UNISTD_H', cc.has_header('linux/unistd.h'))
+packagekit_glib = dependency('packagekit-glib2')
appstream_glib = dependency('appstream-glib', version : '>= 0.7.14')
gdk_pixbuf = dependency('gdk-pixbuf-2.0', version : '>= 2.32.0')
libxmlb = dependency('xmlb', version : '>= 0.1.7', fallback : ['libxmlb', 'libxmlb_dep'])
diff --git a/plugins/packagekit/gs-plugin-packagekit-refresh.c
b/plugins/packagekit/gs-plugin-packagekit-refresh.c
index 7805853c..d896e747 100644
--- a/plugins/packagekit/gs-plugin-packagekit-refresh.c
+++ b/plugins/packagekit/gs-plugin-packagekit-refresh.c
@@ -13,6 +13,7 @@
#include "gs-metered.h"
#include "gs-packagekit-helper.h"
+#include "gs-task.h"
#include "packagekit-common.h"
/*
@@ -26,15 +27,35 @@ struct GsPluginData {
GMutex task_mutex;
};
+static void
+eula_question_cb (GsTask *task,
+ PkEulaRequired *item,
+ gpointer user_data)
+{
+ GsPlugin *plugin = GS_PLUGIN (user_data);
+ g_autoptr(GsPluginEvent) event = gs_plugin_event_new ();
+ g_autoptr(GError) error = NULL;
+
+ error = g_error_new_literal (GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_AUTH_REQUIRED,
+ "You've to agree/decline a license");
+ gs_plugin_event_set_error (event, error);
+ gs_plugin_event_set_action (event, GS_PLUGIN_ACTION_SHOW_EULA);
+ gs_plugin_event_add_flag (event, GS_PLUGIN_EVENT_FLAG_INTERACTIVE);
+ gs_plugin_report_event (plugin, event);
+}
+
void
gs_plugin_initialize (GsPlugin *plugin)
{
GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
g_mutex_init (&priv->task_mutex);
- priv->task = pk_task_new ();
+ priv->task = PK_TASK (gs_task_new ());
pk_task_set_only_download (priv->task, TRUE);
pk_client_set_background (PK_CLIENT (priv->task), TRUE);
+ g_signal_connect (GS_TASK (priv->task), "eula-question",
+ G_CALLBACK (eula_question_cb), plugin);
/* we can return better results than dpkg directly */
gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "dpkg");
diff --git a/plugins/packagekit/gs-task.c b/plugins/packagekit/gs-task.c
new file mode 100644
index 00000000..25189f31
--- /dev/null
+++ b/plugins/packagekit/gs-task.c
@@ -0,0 +1,167 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2019 Jonathan Kang <jonathankang gnome com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <packagekit-glib2/packagekit.h>
+
+#include "gs-task.h"
+
+enum
+{
+ EULA_QUESTION,
+ LAST_SIGNAL
+};
+
+struct _GsTask
+{
+ /*< private >*/
+ PkTask parent_instance;
+
+ gchar *package_id;
+ gchar *vendor_name;
+ gchar *license_agreement;
+ guint request;
+};
+
+struct _GsTaskClass
+{
+ PkTaskClass parent_class;
+};
+
+G_DEFINE_TYPE (GsTask, gs_task, PK_TYPE_TASK)
+
+ static guint signals[LAST_SIGNAL] = { 0 };
+
+const gchar *
+gs_task_get_package_id (GsTask *self)
+{
+ g_return_val_if_fail (GS_IS_TASK (self), NULL);
+
+ return self->package_id;
+}
+
+const gchar *
+gs_task_get_vendor_name (GsTask *self)
+{
+ g_return_val_if_fail (GS_IS_TASK (self), NULL);
+
+ return self->vendor_name;
+}
+
+const gchar *
+gs_task_get_license_agreement (GsTask *self)
+{
+ g_return_val_if_fail (GS_IS_TASK (self), NULL);
+
+ return self->license_agreement;
+}
+
+static void
+gs_task_untrusted_question (PkTask *task,
+ guint request,
+ PkResults *results)
+{}
+
+static void
+gs_task_key_question (PkTask *task,
+ guint request,
+ PkResults *results)
+{
+ g_warning ("key question\n");
+}
+
+static void
+gs_task_media_change_question (PkTask *task,
+ guint request,
+ PkResults *results)
+{
+ g_warning ("media change question\n");
+}
+
+static void
+gs_task_eula_question (PkTask *task,
+ guint request,
+ PkResults *results)
+{
+ PkEulaRequired *item;
+ g_autoptr(GPtrArray) array = NULL;
+ GsTask *self;
+
+ g_warning ("eula question\n");
+
+ self = GS_TASK (task);
+
+ /* Save the current request. */
+ self->request = request;
+
+ array = pk_results_get_eula_required_array (results);
+ if (array->len != 1)
+ {
+ g_warning ("array length %u, aborting", array->len);
+ }
+
+ item = g_ptr_array_index (array, 0);
+ g_object_get (item,
+ "package-id", &self->package_id,
+ "vendor-name", &self->vendor_name,
+ "license-agreement", &self->license_agreement,
+ NULL);
+
+ /* Show the eula window here. Emit a signal? */
+ g_signal_emit (GS_TASK (task), signals[EULA_QUESTION], 0, item);
+}
+
+static void
+gs_task_finalize (GObject *object)
+{
+ GsTask *self;
+
+ self = GS_TASK (object);
+
+ g_free (self->package_id);
+ g_free (self->vendor_name);
+ g_free (self->license_agreement);
+
+ G_OBJECT_CLASS (gs_task_parent_class)->finalize (object);
+}
+
+static void
+gs_task_class_init (GsTaskClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ PkTaskClass *task_class = PK_TASK_CLASS (klass);
+
+ object_class->finalize = gs_task_finalize;
+ task_class->untrusted_question = gs_task_untrusted_question;
+ task_class->key_question = gs_task_key_question;
+ task_class->eula_question = gs_task_eula_question;
+ task_class->media_change_question = gs_task_media_change_question;
+
+ signals[EULA_QUESTION] = g_signal_new ("eula-question",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 1,
+ PK_TYPE_EULA_REQUIRED);
+}
+
+static void
+gs_task_init (GsTask *self)
+{
+ self->package_id = NULL;
+ self->vendor_name = NULL;
+ self->license_agreement = NULL;
+}
+
+GsTask *
+gs_task_new (void)
+{
+ return g_object_new (GS_TYPE_TASK, NULL);
+}
diff --git a/plugins/packagekit/gs-task.h b/plugins/packagekit/gs-task.h
new file mode 100644
index 00000000..4843fc21
--- /dev/null
+++ b/plugins/packagekit/gs-task.h
@@ -0,0 +1,23 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2019 Jonathan Kang <jonathankang gnome com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#pragma once
+
+#include <glib-object.h>
+#include <packagekit-glib2/packagekit.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_TASK (gs_task_get_type ())
+G_DECLARE_FINAL_TYPE (GsTask, gs_task, GS, TASK, PkTask)
+
+const gchar *gs_task_get_package_id (GsTask *task);
+const gchar *gs_task_get_vendor_name (GsTask *task);
+const gchar *gs_task_get_license_agreement (GsTask *task);
+GsTask *gs_task_new (void);
+
+G_END_DECLS
diff --git a/plugins/packagekit/meson.build b/plugins/packagekit/meson.build
index a295b1b1..4575024c 100644
--- a/plugins/packagekit/meson.build
+++ b/plugins/packagekit/meson.build
@@ -95,6 +95,7 @@ shared_module(
sources : [
'gs-plugin-packagekit-refresh.c',
'gs-packagekit-helper.c',
+ 'gs-task.c',
'packagekit-common.c',
],
include_directories : [
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 2a523021..b5142750 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -8,6 +8,7 @@
<file preprocess="xml-stripblanks">gs-category-page.ui</file>
<file preprocess="xml-stripblanks">gs-category-tile.ui</file>
<file preprocess="xml-stripblanks">gs-details-page.ui</file>
+ <file preprocess="xml-stripblanks">gs-eula-dialog.ui</file>
<file preprocess="xml-stripblanks">gs-extras-page.ui</file>
<file preprocess="xml-stripblanks">gs-feature-tile.ui</file>
<file preprocess="xml-stripblanks">gs-first-run-dialog.ui</file>
diff --git a/src/gs-eula-dialog.c b/src/gs-eula-dialog.c
new file mode 100644
index 00000000..506ca700
--- /dev/null
+++ b/src/gs-eula-dialog.c
@@ -0,0 +1,117 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2019 Jonathan Kang <jonathankang gnome com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <gtk/gtk.h>
+
+#include "gs-eula-dialog.h"
+
+enum
+{
+ REJECT,
+ ACCEPT,
+ LAST_SIGNAL
+};
+
+struct _GsEulaDialog
+{
+ /*< private >*/
+ GtkDialog parent_instance;
+};
+
+typedef struct
+{
+ GtkWidget *accept_button;
+ GtkWidget *reject_button;
+ GtkWidget *details_textview;
+} GsEulaDialogPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GsEulaDialog, gs_eula_dialog, GTK_TYPE_DIALOG)
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+void
+gs_eula_dialog_populate_license_agreement (GsEulaDialog *self,
+ const gchar *license_acceptment)
+{
+ g_autoptr(GtkTextBuffer) buffer = NULL;
+ GsEulaDialogPrivate *priv;
+
+ priv = gs_eula_dialog_get_instance_private (self);
+
+ buffer = gtk_text_buffer_new (NULL);
+ gtk_text_buffer_insert_at_cursor (buffer,
+ license_acceptment, strlen (license_acceptment));
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->details_textview), buffer);
+}
+
+static void
+gs_eula_dialog_response_cb (GtkDialog *dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ GsEulaDialog *self = GS_EULA_DIALOG (dialog);
+
+ if (response_id == GTK_RESPONSE_CANCEL)
+ {
+ g_signal_emit (self, signals[REJECT], 0);
+ }
+
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ g_signal_emit (self, signals[ACCEPT], 0);
+ }
+}
+
+static void
+gs_eula_dialog_class_init (GsEulaDialogClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ signals[REJECT] = g_signal_new ("reject",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 0);
+
+ signals[ACCEPT] = g_signal_new ("accept",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 0);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/Software/gs-eula-dialog.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, GsEulaDialog,
+ accept_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GsEulaDialog,
+ reject_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GsEulaDialog,
+ details_textview);
+ gtk_widget_class_bind_template_callback (widget_class, gs_eula_dialog_response_cb);
+}
+
+static void
+gs_eula_dialog_init (GsEulaDialog *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GsEulaDialog *
+gs_eula_dialog_new (void)
+{
+ return g_object_new (GS_TYPE_EULA_DIALOG,
+ "use-header-bar", 1,
+ NULL);
+}
diff --git a/src/gs-eula-dialog.h b/src/gs-eula-dialog.h
new file mode 100644
index 00000000..c8f5d457
--- /dev/null
+++ b/src/gs-eula-dialog.h
@@ -0,0 +1,21 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2019 Jonathan Kang <jonathankang gnome com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_EULA_DIALOG (gs_eula_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (GsEulaDialog, gs_eula_dialog, GS, EULA_DIALOG, GtkDialog)
+
+void gs_eula_dialog_populate_license_agreement (GsEulaDialog *dialog,
+ const gchar *license_agreement);
+GsEulaDialog *gs_eula_dialog_new (void);
+
+G_END_DECLS
diff --git a/src/gs-eula-dialog.ui b/src/gs-eula-dialog.ui
new file mode 100644
index 00000000..6874c505
--- /dev/null
+++ b/src/gs-eula-dialog.ui
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GsEulaDialog" parent="GtkDialog">
+ <property name="default-height">500</property>
+ <property name="default-width">500</property>
+ <property name="modal">True</property>
+ <property name="title" translatable="yes">License Agreement Required</property>
+ <signal name="response" handler="gs_eula_dialog_response_cb"/>
+ <child type="action">
+ <object class="GtkButton" id="reject_button">
+ <property name="label">Reject</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="accept_button">
+ <property name="can-default">True</property>
+ <property name="label" translatable="yes">Accept</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow">
+ <property name="can-focus">False</property>
+ <property name="shadow-type">in</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkTextView" id="details_textview">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="border-width">6</property>
+ <property name="editable">False</property>
+ <property name="wrap-mode">word</property>
+ <property name="cursor-visible">False</property>
+ <property name="accepts-tab">False</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="cancel">reject_button</action-widget>
+ <action-widget response="ok" default="true">accept_button</action-widget>
+ </action-widgets>
+ </template>
+</interface>
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 918b794f..4ce286ea 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -13,6 +13,7 @@
#include <glib/gi18n.h>
#include "gs-common.h"
+#include "gs-eula-dialog.h"
#include "gs-shell.h"
#include "gs-details-page.h"
#include "gs-installed-page.h"
@@ -66,6 +67,7 @@ typedef struct
gchar *events_info_uri;
gboolean in_mode_change;
GsPage *page;
+ //GsTask *task;
} GsShellPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GsShell, gs_shell, G_TYPE_OBJECT)
@@ -1658,6 +1660,41 @@ gs_shell_show_event_url_to_app (GsShell *shell, GsPluginEvent *event)
return TRUE;
}
+static gboolean
+gs_shell_show_event_show_eula (GsShell *shell, GsPluginEvent *event)
+{
+
+ /* const gchar *package_id; */
+ /* const gchar *vendor_name; */
+ /* const gchar *license_agreement; */
+ /* g_autofree gchar *printable = NULL; */
+ /* g_auto(GStrv) split = NULL; */
+ GsEulaDialog *eula_dialog;
+ GsShellPrivate *priv;
+
+ priv = gs_shell_get_instance_private (shell);
+
+ /* Get needed data from GsTask and populate them to GsEulaDialog. */
+ /* package_id = gs_task_get_package_id (task); */
+ /* vendor_name = gs_task_get_vendor_name (task); */
+ /* license_agreement = gs_task_get_license_agreement (task); */
+ /* split = pk_package_id_split (package_id); */
+ /* printable = g_markup_printf_escaped ("<b><big>License required for %s by %s</big></b>", */
+ /* split[0], vendor_name); */
+
+ eula_dialog = gs_eula_dialog_new ();
+ /* gs_eula_dialog_set_label here. */
+ gs_eula_dialog_populate_license_agreement (eula_dialog,
+ "license agreement");
+ //license_agreement);
+
+ gtk_window_set_transient_for (GTK_WINDOW (eula_dialog),
+ priv->main_window);
+ gtk_widget_show (GTK_WIDGET (eula_dialog));
+
+ return TRUE;
+}
+
static gboolean
gs_shell_show_event_fallback (GsShell *shell, GsPluginEvent *event)
{
@@ -1777,6 +1814,8 @@ gs_shell_show_event (GsShell *shell, GsPluginEvent *event)
return gs_shell_show_event_file_to_app (shell, event);
case GS_PLUGIN_ACTION_URL_TO_APP:
return gs_shell_show_event_url_to_app (shell, event);
+ case GS_PLUGIN_ACTION_SHOW_EULA:
+ return gs_shell_show_event_show_eula (shell, event);
default:
break;
}
@@ -2224,6 +2263,7 @@ gs_shell_dispose (GObject *object)
g_clear_object (&priv->header_start_widget);
g_clear_object (&priv->header_end_widget);
g_clear_object (&priv->page);
+ /* g_clear_object (&priv->task); */
g_clear_pointer (&priv->pages, g_hash_table_unref);
g_clear_pointer (&priv->events_info_uri, g_free);
g_clear_pointer (&priv->modal_dialogs, g_ptr_array_unref);
diff --git a/src/meson.build b/src/meson.build
index 5e18c750..58dc90a9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -27,6 +27,7 @@ gnome_software_sources = [
'gs-css.c',
'gs-content-rating.c',
'gs-details-page.c',
+ 'gs-eula-dialog.c',
'gs-extras-page.c',
'gs-feature-tile.c',
'gs-first-run-dialog.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]