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

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