From cc3f068fcc2a97cbd396df8b99749d3377fef01d Mon Sep 17 00:00:00 2001 From: Marek Kasik Date: Tue, 9 Jun 2015 14:42:16 +0200 Subject: [PATCH 1/2] Add handling of ResetForm action --- backend/pdf/ev-poppler.cc | 26 +++++++++++++ libdocument/ev-document-forms.c | 10 +++++ libdocument/ev-document-forms.h | 4 ++ libdocument/ev-link-action.c | 81 ++++++++++++++++++++++++++++++++++++++++- libdocument/ev-link-action.h | 51 ++++++++++++++------------ libview/ev-view.c | 4 ++ shell/ev-window.c | 18 +++++++++ 7 files changed, 170 insertions(+), 24 deletions(-) diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index c17461d..1cfa954 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -1427,6 +1427,21 @@ ev_link_from_action (PdfDocument *pdf_document, case POPPLER_ACTION_JAVASCRIPT: unimplemented_action = "POPPLER_ACTION_JAVASCRIPT"; break; + case POPPLER_ACTION_RESET_FORM: { + gboolean exclude_reset_fields; + GList *reset_fields = NULL; + GList *iter; + + for (iter = action->reset_form.fields; iter; iter = iter->next) + reset_fields = g_list_prepend (reset_fields, g_strdup ((char *) iter->data)); + + exclude_reset_fields = action->reset_form.exclude; + + /* The action takes the ownership of the list */ + ev_action = ev_link_action_new_reset_form (g_list_reverse (reset_fields), + exclude_reset_fields); + break; + } case POPPLER_ACTION_UNKNOWN: unimplemented_action = "POPPLER_ACTION_UNKNOWN"; } @@ -2532,6 +2547,16 @@ pdf_document_forms_document_is_modified (EvDocumentForms *document) return PDF_DOCUMENT (document)->forms_modified; } +static void +pdf_document_forms_reset_form (EvDocumentForms *document, + EvLinkAction *action) +{ + + poppler_document_reset_form (PDF_DOCUMENT (document)->document, + ev_link_action_get_reset_fields (action), + ev_link_action_get_exclude_reset_fields (action)); +} + static gchar * pdf_document_forms_form_field_text_get_text (EvDocumentForms *document, EvFormField *field) @@ -2725,6 +2750,7 @@ pdf_document_document_forms_iface_init (EvDocumentFormsInterface *iface) { iface->get_form_fields = pdf_document_forms_get_form_fields; iface->document_is_modified = pdf_document_forms_document_is_modified; + iface->reset_form = pdf_document_forms_reset_form; iface->form_field_text_get_text = pdf_document_forms_form_field_text_get_text; iface->form_field_text_set_text = pdf_document_forms_form_field_text_set_text; iface->form_field_button_set_state = pdf_document_forms_form_field_button_set_state; diff --git a/libdocument/ev-document-forms.c b/libdocument/ev-document-forms.c index 19417c7..1fe983b 100644 --- a/libdocument/ev-document-forms.c +++ b/libdocument/ev-document-forms.c @@ -45,6 +45,16 @@ ev_document_forms_document_is_modified (EvDocumentForms *document_forms) return (iface->document_is_modified) ? iface->document_is_modified (document_forms) : FALSE; } +void +ev_document_forms_reset_form (EvDocumentForms *document_forms, + EvLinkAction *action) +{ + EvDocumentFormsInterface *iface = EV_DOCUMENT_FORMS_GET_IFACE (document_forms); + + if (iface->reset_form) + iface->reset_form (document_forms, action); +} + gchar * ev_document_forms_form_field_text_get_text (EvDocumentForms *document_forms, EvFormField *field) diff --git a/libdocument/ev-document-forms.h b/libdocument/ev-document-forms.h index 198f3eb..75b06f2 100644 --- a/libdocument/ev-document-forms.h +++ b/libdocument/ev-document-forms.h @@ -51,6 +51,8 @@ struct _EvDocumentFormsInterface EvMappingList *(* get_form_fields) (EvDocumentForms *document_forms, EvPage *page); gboolean (* document_is_modified) (EvDocumentForms *document_forms); + void (* reset_form) (EvDocumentForms *document_forms, + EvLinkAction *action); gchar *(* form_field_text_get_text) (EvDocumentForms *document_forms, EvFormField *field); void (* form_field_text_set_text) (EvDocumentForms *document_forms, @@ -88,6 +90,8 @@ GType ev_document_forms_get_type (void) G_GNU EvMappingList *ev_document_forms_get_form_fields (EvDocumentForms *document_forms, EvPage *page); gboolean ev_document_forms_document_is_modified (EvDocumentForms *document_forms); +void ev_document_forms_reset_form (EvDocumentForms *document_forms, + EvLinkAction *action); gchar *ev_document_forms_form_field_text_get_text (EvDocumentForms *document_forms, EvFormField *field); diff --git a/libdocument/ev-link-action.c b/libdocument/ev-link-action.c index 87fb8c6..844f5a9 100644 --- a/libdocument/ev-link-action.c +++ b/libdocument/ev-link-action.c @@ -32,7 +32,9 @@ enum { PROP_NAME, PROP_SHOW_LIST, PROP_HIDE_LIST, - PROP_TOGGLE_LIST + PROP_TOGGLE_LIST, + PROP_RESET_FIELDS, + PROP_EXCLUDE_RESET_FIELDS }; struct _EvLinkAction { @@ -55,6 +57,8 @@ struct _EvLinkActionPrivate { GList *show_list; GList *hide_list; GList *toggle_list; + GList *reset_fields; + gboolean exclude_reset_fields; }; G_DEFINE_TYPE (EvLinkAction, ev_link_action, G_TYPE_OBJECT) @@ -158,6 +162,34 @@ ev_link_action_get_toggle_list (EvLinkAction *self) return self->priv->toggle_list; } +/** + * ev_link_action_get_reset_fields: + * @self: an #EvLinkAction + * + * Returns: (transfer none) (element-type gchar *): a list of fields to reset + */ +GList * +ev_link_action_get_reset_fields (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL); + + return self->priv->reset_fields; +} + +/** + * ev_link_action_get_exclude_reset_fields: + * @self: an #EvLinkAction + * + * Returns: whether to exclude reset fields when resettings form + */ +gboolean +ev_link_action_get_exclude_reset_fields (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL); + + return self->priv->exclude_reset_fields; +} + static void ev_link_action_get_property (GObject *object, guint prop_id, @@ -196,6 +228,12 @@ ev_link_action_get_property (GObject *object, case PROP_TOGGLE_LIST: g_value_set_pointer (value, self->priv->toggle_list); break; + case PROP_RESET_FIELDS: + g_value_set_pointer (value, self->priv->reset_fields); + break; + case PROP_EXCLUDE_RESET_FIELDS: + g_value_set_boolean (value, self->priv->exclude_reset_fields); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, @@ -244,6 +282,12 @@ ev_link_action_set_property (GObject *object, case PROP_TOGGLE_LIST: self->priv->toggle_list = g_value_get_pointer (value); break; + case PROP_RESET_FIELDS: + self->priv->reset_fields = g_value_get_pointer (value); + break; + case PROP_EXCLUDE_RESET_FIELDS: + self->priv->exclude_reset_fields = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, @@ -299,6 +343,11 @@ ev_link_action_finalize (GObject *object) priv->toggle_list = NULL; } + if (priv->reset_fields) { + g_list_free_full (priv->reset_fields, g_free); + priv->reset_fields = NULL; + } + G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object); } @@ -312,6 +361,8 @@ ev_link_action_init (EvLinkAction *ev_link_action) ev_link_action->priv->filename = NULL; ev_link_action->priv->params = NULL; ev_link_action->priv->name = NULL; + ev_link_action->priv->reset_fields = NULL; + ev_link_action->priv->exclude_reset_fields = FALSE; } static void @@ -407,6 +458,23 @@ ev_link_action_class_init (EvLinkActionClass *ev_link_action_class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (g_object_class, + PROP_RESET_FIELDS, + g_param_spec_pointer ("reset-fields", + "ResetFields", + "The list of fields that should be/should not be reset", + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (g_object_class, + PROP_EXCLUDE_RESET_FIELDS, + g_param_spec_boolean ("exclude-reset-fields", + "ExcludeResetFields", + "Whether to exclude/include reset-fields when resetting form", + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); } EvLinkAction * @@ -479,6 +547,17 @@ ev_link_action_new_layers_state (GList *show_list, NULL)); } +EvLinkAction * +ev_link_action_new_reset_form (GList *reset_fields, + gboolean exclude_reset_fields) +{ + return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION, + "exclude-reset-fields", exclude_reset_fields, + "reset-fields", reset_fields, + "type", EV_LINK_ACTION_TYPE_RESET_FORM, + NULL)); +} + /** * ev_link_action_equal: * @a: a #EvLinkAction diff --git a/libdocument/ev-link-action.h b/libdocument/ev-link-action.h index 3d6c5fd..4dffeb7 100644 --- a/libdocument/ev-link-action.h +++ b/libdocument/ev-link-action.h @@ -47,36 +47,41 @@ typedef enum { EV_LINK_ACTION_TYPE_EXTERNAL_URI, EV_LINK_ACTION_TYPE_LAUNCH, EV_LINK_ACTION_TYPE_NAMED, - EV_LINK_ACTION_TYPE_LAYERS_STATE + EV_LINK_ACTION_TYPE_LAYERS_STATE, + EV_LINK_ACTION_TYPE_RESET_FORM /* We'll probably fill this in more as we support the other types of * actions */ } EvLinkActionType; -GType ev_link_action_get_type (void) G_GNUC_CONST; +GType ev_link_action_get_type (void) G_GNUC_CONST; -EvLinkActionType ev_link_action_get_action_type (EvLinkAction *self); -EvLinkDest *ev_link_action_get_dest (EvLinkAction *self); -const gchar *ev_link_action_get_uri (EvLinkAction *self); -const gchar *ev_link_action_get_filename (EvLinkAction *self); -const gchar *ev_link_action_get_params (EvLinkAction *self); -const gchar *ev_link_action_get_name (EvLinkAction *self); -GList *ev_link_action_get_show_list (EvLinkAction *self); -GList *ev_link_action_get_hide_list (EvLinkAction *self); -GList *ev_link_action_get_toggle_list (EvLinkAction *self); +EvLinkActionType ev_link_action_get_action_type (EvLinkAction *self); +EvLinkDest *ev_link_action_get_dest (EvLinkAction *self); +const gchar *ev_link_action_get_uri (EvLinkAction *self); +const gchar *ev_link_action_get_filename (EvLinkAction *self); +const gchar *ev_link_action_get_params (EvLinkAction *self); +const gchar *ev_link_action_get_name (EvLinkAction *self); +GList *ev_link_action_get_show_list (EvLinkAction *self); +GList *ev_link_action_get_hide_list (EvLinkAction *self); +GList *ev_link_action_get_toggle_list (EvLinkAction *self); +GList *ev_link_action_get_reset_fields (EvLinkAction *self); +gboolean ev_link_action_get_exclude_reset_fields (EvLinkAction *self); -EvLinkAction *ev_link_action_new_dest (EvLinkDest *dest); -EvLinkAction *ev_link_action_new_remote (EvLinkDest *dest, - const gchar *filename); -EvLinkAction *ev_link_action_new_external_uri (const gchar *uri); -EvLinkAction *ev_link_action_new_launch (const gchar *filename, - const gchar *params); -EvLinkAction *ev_link_action_new_named (const gchar *name); -EvLinkAction *ev_link_action_new_layers_state (GList *show_list, - GList *hide_list, - GList *toggle_list); +EvLinkAction *ev_link_action_new_dest (EvLinkDest *dest); +EvLinkAction *ev_link_action_new_remote (EvLinkDest *dest, + const gchar *filename); +EvLinkAction *ev_link_action_new_external_uri (const gchar *uri); +EvLinkAction *ev_link_action_new_launch (const gchar *filename, + const gchar *params); +EvLinkAction *ev_link_action_new_named (const gchar *name); +EvLinkAction *ev_link_action_new_layers_state (GList *show_list, + GList *hide_list, + GList *toggle_list); +EvLinkAction *ev_link_action_new_reset_form (GList *fields, + gboolean exclude_fields); -gboolean ev_link_action_equal (EvLinkAction *a, - EvLinkAction *b); +gboolean ev_link_action_equal (EvLinkAction *a, + EvLinkAction *b); G_END_DECLS diff --git a/libview/ev-view.c b/libview/ev-view.c index 3fc4584..f128dea 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -1988,6 +1988,7 @@ ev_view_handle_link (EvView *view, EvLink *link) case EV_LINK_ACTION_TYPE_EXTERNAL_URI: case EV_LINK_ACTION_TYPE_LAUNCH: case EV_LINK_ACTION_TYPE_NAMED: + case EV_LINK_ACTION_TYPE_RESET_FORM: g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, action); break; } @@ -2060,6 +2061,9 @@ tip_from_link (EvView *view, EvLink *link) case EV_LINK_ACTION_TYPE_NAMED: msg = tip_from_action_named (action); break; + case EV_LINK_ACTION_TYPE_RESET_FORM: + msg = g_strdup_printf (_("Reset form")); + break; default: if (title) msg = g_strdup (title); diff --git a/shell/ev-window.c b/shell/ev-window.c index cc61dfc..a3d2ed6 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -6176,6 +6176,21 @@ do_action_named (EvWindow *window, EvLinkAction *action) } static void +do_action_reset_form (EvWindow *window, EvLinkAction *action) +{ + EvDocument *document = window->priv->document; + EvView *view; + + if (EV_IS_DOCUMENT_FORMS (document)) { + ev_document_forms_reset_form (EV_DOCUMENT_FORMS (document), action); + + view = EV_VIEW (window->priv->view); + ev_view_reload (view); + } + +} + +static void view_external_link_cb (EvWindow *window, EvLinkAction *action) { switch (ev_link_action_get_action_type (action)) { @@ -6201,6 +6216,9 @@ view_external_link_cb (EvWindow *window, EvLinkAction *action) case EV_LINK_ACTION_TYPE_NAMED: do_action_named (window, action); break; + case EV_LINK_ACTION_TYPE_RESET_FORM: + do_action_reset_form (window, action); + break; default: g_assert_not_reached (); } -- 2.4.3