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

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