Blame SOURCES/evince-3.28.4-reset-form-action.patch

a0a0aa
From fe9573da1278463a76b685c5cb3116d6e8241e27 Mon Sep 17 00:00:00 2001
a0a0aa
From: Marek Kasik <mkasik@redhat.com>
a0a0aa
Date: Wed, 22 Jul 2020 16:26:17 +0200
a0a0aa
Subject: [PATCH] Handle reset form action
a0a0aa
a0a0aa
Add new type of action EV_LINK_ACTION_TYPE_RESET_FORM for EvLinkAction
a0a0aa
together with properties "reset-fields" and "exclude-reset-fields".
a0a0aa
The properties controls which fields are reset and are set in PDF document.
a0a0aa
This commit extends EvDocumentFormsInterface with new method "reset_form".
a0a0aa
Check for poppler 0.90.0 or higher when calling its methods for resetting
a0a0aa
of forms.
a0a0aa
a0a0aa
Issue #46
a0a0aa
---
a0a0aa
 backend/pdf/ev-poppler.cc       | 29 ++++++++++
a0a0aa
 libdocument/ev-document-forms.c | 10 ++++
a0a0aa
 libdocument/ev-document-forms.h |  4 ++
a0a0aa
 libdocument/ev-link-action.c    | 81 ++++++++++++++++++++++++++++++++-
a0a0aa
 libdocument/ev-link-action.h    | 51 +++++++++++----------
a0a0aa
 libview/ev-view.c               |  4 ++
a0a0aa
 shell/ev-window.c               | 15 ++++++
a0a0aa
 7 files changed, 166 insertions(+), 24 deletions(-)
a0a0aa
a0a0aa
diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
a0a0aa
index ee9a5c9f..efffef0b 100644
a0a0aa
--- a/backend/pdf/ev-poppler.cc
a0a0aa
+++ b/backend/pdf/ev-poppler.cc
a0a0aa
@@ -1721,6 +1721,23 @@ ev_link_from_action (PdfDocument   *pdf_document,
a0a0aa
 	        case POPPLER_ACTION_JAVASCRIPT:
a0a0aa
 			unimplemented_action = "POPPLER_ACTION_JAVASCRIPT";
a0a0aa
 			break;
a0a0aa
+#if POPPLER_CHECK_VERSION(0, 90, 0)
a0a0aa
+	        case POPPLER_ACTION_RESET_FORM: {
a0a0aa
+			gboolean  exclude_reset_fields;
a0a0aa
+			GList    *reset_fields = NULL;
a0a0aa
+			GList    *iter;
a0a0aa
+
a0a0aa
+			for (iter = action->reset_form.fields; iter; iter = iter->next)
a0a0aa
+				reset_fields = g_list_prepend (reset_fields, g_strdup ((char *) iter->data));
a0a0aa
+
a0a0aa
+			exclude_reset_fields = action->reset_form.exclude;
a0a0aa
+
a0a0aa
+			/* The action takes the ownership of the list */
a0a0aa
+			ev_action = ev_link_action_new_reset_form (g_list_reverse (reset_fields),
a0a0aa
+								   exclude_reset_fields);
a0a0aa
+			break;
a0a0aa
+		}
a0a0aa
+#endif
a0a0aa
 	        case POPPLER_ACTION_UNKNOWN:
a0a0aa
 			unimplemented_action = "POPPLER_ACTION_UNKNOWN";
a0a0aa
 	}
a0a0aa
@@ -2845,6 +2860,17 @@ pdf_document_forms_document_is_modified (EvDocumentForms *document)
a0a0aa
 	return PDF_DOCUMENT (document)->forms_modified;
a0a0aa
 }
a0a0aa
 
a0a0aa
+static void
a0a0aa
+pdf_document_forms_reset_form (EvDocumentForms *document,
a0a0aa
+                               EvLinkAction    *action)
a0a0aa
+{
a0a0aa
+#if POPPLER_CHECK_VERSION(0, 90, 0)
a0a0aa
+	poppler_document_reset_form (PDF_DOCUMENT (document)->document,
a0a0aa
+	                             ev_link_action_get_reset_fields (action),
a0a0aa
+	                             ev_link_action_get_exclude_reset_fields (action));
a0a0aa
+#endif
a0a0aa
+}
a0a0aa
+
a0a0aa
 static gchar *
a0a0aa
 pdf_document_forms_form_field_text_get_text (EvDocumentForms *document,
a0a0aa
 					     EvFormField     *field)
a0a0aa
@@ -3044,6 +3068,7 @@ pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface)
a0a0aa
 {
a0a0aa
 	iface->get_form_fields = pdf_document_forms_get_form_fields;
a0a0aa
 	iface->document_is_modified = pdf_document_forms_document_is_modified;
a0a0aa
+	iface->reset_form = pdf_document_forms_reset_form;
a0a0aa
 	iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text;
a0a0aa
 	iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text;
a0a0aa
 	iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state;
a0a0aa
diff --git a/libdocument/ev-document-forms.c b/libdocument/ev-document-forms.c
a0a0aa
index 19417c77..1fe983b1 100644
a0a0aa
--- a/libdocument/ev-document-forms.c
a0a0aa
+++ b/libdocument/ev-document-forms.c
a0a0aa
@@ -45,6 +45,16 @@ ev_document_forms_document_is_modified (EvDocumentForms *document_forms)
a0a0aa
 	return (iface->document_is_modified) ? iface->document_is_modified (document_forms) : FALSE;
a0a0aa
 }
a0a0aa
 
a0a0aa
+void
a0a0aa
+ev_document_forms_reset_form (EvDocumentForms *document_forms,
a0a0aa
+                              EvLinkAction    *action)
a0a0aa
+{
a0a0aa
+	EvDocumentFormsInterface *iface = EV_DOCUMENT_FORMS_GET_IFACE (document_forms);
a0a0aa
+
a0a0aa
+	if (iface->reset_form)
a0a0aa
+		iface->reset_form (document_forms, action);
a0a0aa
+}
a0a0aa
+
a0a0aa
 gchar *
a0a0aa
 ev_document_forms_form_field_text_get_text (EvDocumentForms *document_forms, 
a0a0aa
 					    EvFormField     *field)
a0a0aa
diff --git a/libdocument/ev-document-forms.h b/libdocument/ev-document-forms.h
a0a0aa
index 198f3eb5..f78dba6b 100644
a0a0aa
--- a/libdocument/ev-document-forms.h
a0a0aa
+++ b/libdocument/ev-document-forms.h
a0a0aa
@@ -82,6 +82,8 @@ struct _EvDocumentFormsInterface
a0a0aa
 							       const gchar       *text);
a0a0aa
 	gchar         *(* form_field_choice_get_text)         (EvDocumentForms   *document_forms,
a0a0aa
 							       EvFormField       *field);
a0a0aa
+	void           (* reset_form)                         (EvDocumentForms   *document_forms,
a0a0aa
+							       EvLinkAction      *action);
a0a0aa
 };
a0a0aa
 
a0a0aa
 GType          ev_document_forms_get_type                           (void) G_GNUC_CONST;
a0a0aa
@@ -122,6 +124,8 @@ void 	       ev_document_forms_form_field_choice_set_text         (EvDocumentFor
a0a0aa
 								     const gchar       *text);
a0a0aa
 gchar         *ev_document_forms_form_field_choice_get_text         (EvDocumentForms   *document_forms,
a0a0aa
 								     EvFormField       *field);
a0a0aa
+void           ev_document_forms_reset_form                         (EvDocumentForms   *document_forms,
a0a0aa
+								     EvLinkAction      *action);
a0a0aa
 
a0a0aa
 G_END_DECLS
a0a0aa
 
a0a0aa
diff --git a/libdocument/ev-link-action.c b/libdocument/ev-link-action.c
a0a0aa
index 0e7761d7..cbc5d620 100644
a0a0aa
--- a/libdocument/ev-link-action.c
a0a0aa
+++ b/libdocument/ev-link-action.c
a0a0aa
@@ -32,7 +32,9 @@ enum {
a0a0aa
 	PROP_NAME,
a0a0aa
 	PROP_SHOW_LIST,
a0a0aa
 	PROP_HIDE_LIST,
a0a0aa
-	PROP_TOGGLE_LIST
a0a0aa
+	PROP_TOGGLE_LIST,
a0a0aa
+	PROP_RESET_FIELDS,
a0a0aa
+	PROP_EXCLUDE_RESET_FIELDS
a0a0aa
 };
a0a0aa
 
a0a0aa
 struct _EvLinkAction {
a0a0aa
@@ -55,6 +57,8 @@ struct _EvLinkActionPrivate {
a0a0aa
 	GList            *show_list;
a0a0aa
 	GList            *hide_list;
a0a0aa
 	GList            *toggle_list;
a0a0aa
+	GList            *reset_fields;
a0a0aa
+	gboolean          exclude_reset_fields;
a0a0aa
 };
a0a0aa
 
a0a0aa
 G_DEFINE_TYPE (EvLinkAction, ev_link_action, G_TYPE_OBJECT)
a0a0aa
@@ -155,6 +159,34 @@ ev_link_action_get_toggle_list (EvLinkAction *self)
a0a0aa
 	return self->priv->toggle_list;
a0a0aa
 }
a0a0aa
 
a0a0aa
+/**
a0a0aa
+ * ev_link_action_get_reset_fields:
a0a0aa
+ * @self: an #EvLinkAction
a0a0aa
+ *
a0a0aa
+ * Returns: (transfer none) (element-type gchar *): a list of fields to reset
a0a0aa
+ */
a0a0aa
+GList *
a0a0aa
+ev_link_action_get_reset_fields (EvLinkAction *self)
a0a0aa
+{
a0a0aa
+	g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
a0a0aa
+
a0a0aa
+	return self->priv->reset_fields;
a0a0aa
+}
a0a0aa
+
a0a0aa
+/**
a0a0aa
+ * ev_link_action_get_exclude_reset_fields:
a0a0aa
+ * @self: an #EvLinkAction
a0a0aa
+ *
a0a0aa
+ * Returns: whether to exclude reset fields when resetting form
a0a0aa
+ */
a0a0aa
+gboolean
a0a0aa
+ev_link_action_get_exclude_reset_fields (EvLinkAction *self)
a0a0aa
+{
a0a0aa
+	g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL);
a0a0aa
+
a0a0aa
+	return self->priv->exclude_reset_fields;
a0a0aa
+}
a0a0aa
+
a0a0aa
 static void
a0a0aa
 ev_link_action_get_property (GObject    *object,
a0a0aa
 			     guint       prop_id,
a0a0aa
@@ -193,6 +225,12 @@ ev_link_action_get_property (GObject    *object,
a0a0aa
 	        case PROP_TOGGLE_LIST:
a0a0aa
 			g_value_set_pointer (value, self->priv->toggle_list);
a0a0aa
 			break;
a0a0aa
+	        case PROP_RESET_FIELDS:
a0a0aa
+			g_value_set_pointer (value, self->priv->reset_fields);
a0a0aa
+			break;
a0a0aa
+	        case PROP_EXCLUDE_RESET_FIELDS:
a0a0aa
+			g_value_set_boolean (value, self->priv->exclude_reset_fields);
a0a0aa
+			break;
a0a0aa
 	        default:
a0a0aa
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
a0a0aa
 							   prop_id,
a0a0aa
@@ -241,6 +279,12 @@ ev_link_action_set_property (GObject      *object,
a0a0aa
 	        case PROP_TOGGLE_LIST:
a0a0aa
 			self->priv->toggle_list = g_value_get_pointer (value);
a0a0aa
 			break;
a0a0aa
+	        case PROP_RESET_FIELDS:
a0a0aa
+			self->priv->reset_fields = g_value_get_pointer (value);
a0a0aa
+			break;
a0a0aa
+	        case PROP_EXCLUDE_RESET_FIELDS:
a0a0aa
+			self->priv->exclude_reset_fields = g_value_get_boolean (value);
a0a0aa
+			break;
a0a0aa
 	        default:
a0a0aa
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
a0a0aa
 							   prop_id,
a0a0aa
@@ -296,6 +340,11 @@ ev_link_action_finalize (GObject *object)
a0a0aa
 		priv->toggle_list = NULL;
a0a0aa
 	}
a0a0aa
 
a0a0aa
+	if (priv->reset_fields) {
a0a0aa
+		g_list_free_full (priv->reset_fields, g_free);
a0a0aa
+		priv->reset_fields = NULL;
a0a0aa
+	}
a0a0aa
+
a0a0aa
 	G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object);
a0a0aa
 }
a0a0aa
 
a0a0aa
@@ -309,6 +358,8 @@ ev_link_action_init (EvLinkAction *ev_link_action)
a0a0aa
 	ev_link_action->priv->filename = NULL;
a0a0aa
 	ev_link_action->priv->params = NULL;
a0a0aa
 	ev_link_action->priv->name = NULL;
a0a0aa
+	ev_link_action->priv->reset_fields = NULL;
a0a0aa
+	ev_link_action->priv->exclude_reset_fields = FALSE;
a0a0aa
 }
a0a0aa
 
a0a0aa
 static void
a0a0aa
@@ -402,6 +453,23 @@ ev_link_action_class_init (EvLinkActionClass *ev_link_action_class)
a0a0aa
 							       G_PARAM_READWRITE |
a0a0aa
 							       G_PARAM_CONSTRUCT_ONLY |
a0a0aa
                                                                G_PARAM_STATIC_STRINGS));
a0a0aa
+	g_object_class_install_property (g_object_class,
a0a0aa
+					 PROP_RESET_FIELDS,
a0a0aa
+					 g_param_spec_pointer ("reset-fields",
a0a0aa
+							       "ResetFields",
a0a0aa
+							       "The list of fields that should be/should not be reset",
a0a0aa
+							       G_PARAM_READWRITE |
a0a0aa
+							       G_PARAM_CONSTRUCT_ONLY |
a0a0aa
+							       G_PARAM_STATIC_STRINGS));
a0a0aa
+	g_object_class_install_property (g_object_class,
a0a0aa
+					 PROP_EXCLUDE_RESET_FIELDS,
a0a0aa
+					 g_param_spec_boolean ("exclude-reset-fields",
a0a0aa
+							       "ExcludeResetFields",
a0a0aa
+							       "Whether to exclude/include reset-fields when resetting form",
a0a0aa
+							       FALSE,
a0a0aa
+							       G_PARAM_READWRITE |
a0a0aa
+							       G_PARAM_CONSTRUCT_ONLY |
a0a0aa
+							       G_PARAM_STATIC_STRINGS));
a0a0aa
 }
a0a0aa
 
a0a0aa
 EvLinkAction *
a0a0aa
@@ -474,6 +542,17 @@ ev_link_action_new_layers_state (GList *show_list,
a0a0aa
 					     NULL));
a0a0aa
 }
a0a0aa
 
a0a0aa
+EvLinkAction *
a0a0aa
+ev_link_action_new_reset_form (GList    *reset_fields,
a0a0aa
+			       gboolean  exclude_reset_fields)
a0a0aa
+{
a0a0aa
+	return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION,
a0a0aa
+					     "exclude-reset-fields", exclude_reset_fields,
a0a0aa
+					     "reset-fields", reset_fields,
a0a0aa
+					     "type", EV_LINK_ACTION_TYPE_RESET_FORM,
a0a0aa
+					     NULL));
a0a0aa
+}
a0a0aa
+
a0a0aa
 /**
a0a0aa
  * ev_link_action_equal:
a0a0aa
  * @a: a #EvLinkAction
a0a0aa
diff --git a/libdocument/ev-link-action.h b/libdocument/ev-link-action.h
a0a0aa
index 3d6c5fd8..4dffeb74 100644
a0a0aa
--- a/libdocument/ev-link-action.h
a0a0aa
+++ b/libdocument/ev-link-action.h
a0a0aa
@@ -47,36 +47,41 @@ typedef enum {
a0a0aa
 	EV_LINK_ACTION_TYPE_EXTERNAL_URI,
a0a0aa
 	EV_LINK_ACTION_TYPE_LAUNCH,
a0a0aa
 	EV_LINK_ACTION_TYPE_NAMED,
a0a0aa
-	EV_LINK_ACTION_TYPE_LAYERS_STATE
a0a0aa
+	EV_LINK_ACTION_TYPE_LAYERS_STATE,
a0a0aa
+	EV_LINK_ACTION_TYPE_RESET_FORM
a0a0aa
 	/* We'll probably fill this in more as we support the other types of
a0a0aa
 	 * actions */
a0a0aa
 } EvLinkActionType;
a0a0aa
 
a0a0aa
-GType            ev_link_action_get_type         (void) G_GNUC_CONST;
a0a0aa
+GType            ev_link_action_get_type                 (void) G_GNUC_CONST;
a0a0aa
 
a0a0aa
-EvLinkActionType ev_link_action_get_action_type  (EvLinkAction *self);
a0a0aa
-EvLinkDest      *ev_link_action_get_dest         (EvLinkAction *self);
a0a0aa
-const gchar     *ev_link_action_get_uri          (EvLinkAction *self);
a0a0aa
-const gchar     *ev_link_action_get_filename     (EvLinkAction *self);
a0a0aa
-const gchar     *ev_link_action_get_params       (EvLinkAction *self);
a0a0aa
-const gchar     *ev_link_action_get_name         (EvLinkAction *self);
a0a0aa
-GList           *ev_link_action_get_show_list    (EvLinkAction *self);
a0a0aa
-GList           *ev_link_action_get_hide_list    (EvLinkAction *self);
a0a0aa
-GList           *ev_link_action_get_toggle_list  (EvLinkAction *self);
a0a0aa
+EvLinkActionType ev_link_action_get_action_type          (EvLinkAction *self);
a0a0aa
+EvLinkDest      *ev_link_action_get_dest                 (EvLinkAction *self);
a0a0aa
+const gchar     *ev_link_action_get_uri                  (EvLinkAction *self);
a0a0aa
+const gchar     *ev_link_action_get_filename             (EvLinkAction *self);
a0a0aa
+const gchar     *ev_link_action_get_params               (EvLinkAction *self);
a0a0aa
+const gchar     *ev_link_action_get_name                 (EvLinkAction *self);
a0a0aa
+GList           *ev_link_action_get_show_list            (EvLinkAction *self);
a0a0aa
+GList           *ev_link_action_get_hide_list            (EvLinkAction *self);
a0a0aa
+GList           *ev_link_action_get_toggle_list          (EvLinkAction *self);
a0a0aa
+GList           *ev_link_action_get_reset_fields         (EvLinkAction *self);
a0a0aa
+gboolean         ev_link_action_get_exclude_reset_fields (EvLinkAction *self);
a0a0aa
 
a0a0aa
-EvLinkAction    *ev_link_action_new_dest         (EvLinkDest   *dest);
a0a0aa
-EvLinkAction    *ev_link_action_new_remote       (EvLinkDest   *dest,
a0a0aa
-						  const gchar  *filename);
a0a0aa
-EvLinkAction    *ev_link_action_new_external_uri (const gchar  *uri);
a0a0aa
-EvLinkAction    *ev_link_action_new_launch       (const gchar  *filename,
a0a0aa
-						  const gchar  *params);
a0a0aa
-EvLinkAction    *ev_link_action_new_named        (const gchar  *name);
a0a0aa
-EvLinkAction    *ev_link_action_new_layers_state (GList        *show_list,
a0a0aa
-						  GList        *hide_list,
a0a0aa
-						  GList        *toggle_list);
a0a0aa
+EvLinkAction    *ev_link_action_new_dest                 (EvLinkDest   *dest);
a0a0aa
+EvLinkAction    *ev_link_action_new_remote               (EvLinkDest   *dest,
a0a0aa
+						          const gchar  *filename);
a0a0aa
+EvLinkAction    *ev_link_action_new_external_uri         (const gchar  *uri);
a0a0aa
+EvLinkAction    *ev_link_action_new_launch               (const gchar  *filename,
a0a0aa
+						          const gchar  *params);
a0a0aa
+EvLinkAction    *ev_link_action_new_named                (const gchar  *name);
a0a0aa
+EvLinkAction    *ev_link_action_new_layers_state         (GList        *show_list,
a0a0aa
+						          GList        *hide_list,
a0a0aa
+						          GList        *toggle_list);
a0a0aa
+EvLinkAction    *ev_link_action_new_reset_form           (GList        *fields,
a0a0aa
+						          gboolean      exclude_fields);
a0a0aa
 
a0a0aa
-gboolean         ev_link_action_equal            (EvLinkAction *a,
a0a0aa
-                                                  EvLinkAction *b);
a0a0aa
+gboolean         ev_link_action_equal                    (EvLinkAction *a,
a0a0aa
+                                                          EvLinkAction *b);
a0a0aa
 
a0a0aa
 G_END_DECLS
a0a0aa
 
a0a0aa
diff --git a/libview/ev-view.c b/libview/ev-view.c
a0a0aa
index c52ecaf3..e2ca6b5a 100644
a0a0aa
--- a/libview/ev-view.c
a0a0aa
+++ b/libview/ev-view.c
a0a0aa
@@ -2095,6 +2095,7 @@ ev_view_handle_link (EvView *view, EvLink *link)
a0a0aa
 	        case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
a0a0aa
 	        case EV_LINK_ACTION_TYPE_LAUNCH:
a0a0aa
 	        case EV_LINK_ACTION_TYPE_NAMED:
a0a0aa
+	        case EV_LINK_ACTION_TYPE_RESET_FORM:
a0a0aa
 			g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, action);
a0a0aa
 			break;
a0a0aa
 	}
a0a0aa
@@ -2167,6 +2168,9 @@ tip_from_link (EvView *view, EvLink *link)
a0a0aa
 	        case EV_LINK_ACTION_TYPE_NAMED:
a0a0aa
 			msg = tip_from_action_named (action);
a0a0aa
 			break;
a0a0aa
+	        case EV_LINK_ACTION_TYPE_RESET_FORM:
a0a0aa
+			msg = g_strdup_printf (_("Reset form"));
a0a0aa
+			break;
a0a0aa
 	        default:
a0a0aa
 			if (title)
a0a0aa
 				msg = g_strdup (title);
a0a0aa
diff --git a/shell/ev-window.c b/shell/ev-window.c
a0a0aa
index 1f3ea24d..81a6ede1 100644
a0a0aa
--- a/shell/ev-window.c
a0a0aa
+++ b/shell/ev-window.c
a0a0aa
@@ -6867,6 +6867,18 @@ do_action_named (EvWindow *window, EvLinkAction *action)
a0a0aa
 	}
a0a0aa
 }
a0a0aa
 
a0a0aa
+static void
a0a0aa
+reset_form (EvWindow *window, EvLinkAction *action)
a0a0aa
+{
a0a0aa
+	EvWindowPrivate *priv = window->priv;
a0a0aa
+	EvDocument      *document = priv->document;
a0a0aa
+
a0a0aa
+	if (EV_IS_DOCUMENT_FORMS (document)) {
a0a0aa
+		ev_document_forms_reset_form (EV_DOCUMENT_FORMS (document), action);
a0a0aa
+		ev_view_reload (EV_VIEW (priv->view));
a0a0aa
+	}
a0a0aa
+}
a0a0aa
+
a0a0aa
 static void
a0a0aa
 view_external_link_cb (EvWindow *window, EvLinkAction *action)
a0a0aa
 {
a0a0aa
@@ -6893,6 +6905,9 @@ view_external_link_cb (EvWindow *window, EvLinkAction *action)
a0a0aa
 	        case EV_LINK_ACTION_TYPE_NAMED:
a0a0aa
 			do_action_named (window, action);
a0a0aa
 			break;
a0a0aa
+	        case EV_LINK_ACTION_TYPE_RESET_FORM:
a0a0aa
+			reset_form (window, action);
a0a0aa
+			break;
a0a0aa
 	        default:
a0a0aa
 			g_assert_not_reached ();
a0a0aa
 	}
a0a0aa
-- 
a0a0aa
2.28.0
a0a0aa