From 11d2d98b1f110508b0962753a7f18b5cf189fefc Mon Sep 17 00:00:00 2001 From: Marek Kasik Date: Mon, 15 Jun 2015 14:08:45 +0200 Subject: [PATCH 4/4] glib: Add ability to reset forms Add new PopplerActionType POPPLER_ACTION_RESET_FORM and its handling to PopplerAction. Add poppler_document_reset_form() to PopplerDocument. --- glib/demo/utils.c | 3 +++ glib/poppler-action.cc | 38 ++++++++++++++++++++++++++++++++++++++ glib/poppler-action.h | 15 ++++++++++++++- glib/poppler-document.cc | 39 +++++++++++++++++++++++++++++++++++++++ glib/poppler-document.h | 4 ++++ 5 files changed, 98 insertions(+), 1 deletion(-) diff --git a/glib/demo/utils.c b/glib/demo/utils.c index 5833104..3129524 100644 --- a/glib/demo/utils.c +++ b/glib/demo/utils.c @@ -462,6 +462,9 @@ pgd_action_view_set_action (GtkWidget *action_view, gtk_widget_show (swindow); } break; + case POPPLER_ACTION_RESET_FORM: + pgd_table_add_property (GTK_GRID (table), "Type:", "ResetForm Action", &row); + break; default: g_assert_not_reached (); } diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc index 384530f..e3933ed 100644 --- a/glib/poppler-action.cc +++ b/glib/poppler-action.cc @@ -144,6 +144,10 @@ poppler_action_free (PopplerAction *action) if (action->javascript.script) g_free (action->javascript.script); break; + case POPPLER_ACTION_RESET_FORM: + if (action->reset_form.fields) + g_list_free_full (action->reset_form.fields, g_free); + break; default: break; } @@ -222,6 +226,17 @@ poppler_action_copy (PopplerAction *action) if (action->javascript.script) new_action->javascript.script = g_strdup (action->javascript.script); break; + case POPPLER_ACTION_RESET_FORM: + if (action->reset_form.fields) { + GList *iter; + + new_action->reset_form.fields = NULL; + for (iter = action->reset_form.fields; iter; iter = iter->next) + new_action->reset_form.fields = g_list_append (new_action->reset_form.fields, + g_strdup ((char *) iter->data)); + } + new_action->reset_form.exclude = action->reset_form.exclude; + break; default: break; } @@ -534,6 +549,25 @@ build_javascript (PopplerAction *action, } static void +build_reset_form (PopplerAction *action, + LinkResetForm *link) +{ + GooList *fields; + + action->reset_form.fields = NULL; + + fields = link->getFields (); + if (fields) { + for (int i = 0; i < fields->getLength (); i++) { + action->reset_form.fields = g_list_append (action->reset_form.fields, + g_strdup ((((GooString *) fields->get (i)))->getCString ())); + } + } + + action->reset_form.exclude = link->getExclude (); +} + +static void build_rendition (PopplerAction *action, LinkRendition *link) { @@ -674,6 +708,10 @@ _poppler_action_new (PopplerDocument *document, action->type = POPPLER_ACTION_JAVASCRIPT; build_javascript (action, dynamic_cast (link)); break; + case actionResetForm: + action->type = POPPLER_ACTION_RESET_FORM; + build_reset_form (action, dynamic_cast (link)); + break; case actionUnknown: default: action->type = POPPLER_ACTION_UNKNOWN; diff --git a/glib/poppler-action.h b/glib/poppler-action.h index 2a5d7f8..fff31c9 100644 --- a/glib/poppler-action.h +++ b/glib/poppler-action.h @@ -37,6 +37,7 @@ G_BEGIN_DECLS * @POPPLER_ACTION_RENDITION: play multimedia content. Since 0.14 * @POPPLER_ACTION_OCG_STATE: state of layer. Since 0.14 * @POPPLER_ACTION_JAVASCRIPT: Javascript. Since 0.18 + * @POPPLER_ACTION_RESET_FORM: resets form. Since 0.34 * * Action types */ @@ -52,7 +53,8 @@ typedef enum POPPLER_ACTION_MOVIE, /* movie action */ POPPLER_ACTION_RENDITION, /* rendition action */ POPPLER_ACTION_OCG_STATE, /* Set-OCG-State action */ - POPPLER_ACTION_JAVASCRIPT /* Javascript action */ + POPPLER_ACTION_JAVASCRIPT, /* Javascript action */ + POPPLER_ACTION_RESET_FORM /* ResetForm action */ } PopplerActionType; /** @@ -148,6 +150,7 @@ typedef struct _PopplerActionMovie PopplerActionMovie; typedef struct _PopplerActionRendition PopplerActionRendition; typedef struct _PopplerActionOCGState PopplerActionOCGState; typedef struct _PopplerActionJavascript PopplerActionJavascript; +typedef struct _PopplerActionResetForm PopplerActionResetForm; /** * PopplerDest: @@ -276,6 +279,15 @@ struct _PopplerActionJavascript gchar *script; }; +struct _PopplerActionResetForm +{ + PopplerActionType type; + gchar *title; + + GList *fields; + gboolean exclude; +}; + /** * PopplerAction: * @@ -294,6 +306,7 @@ union _PopplerAction PopplerActionRendition rendition; PopplerActionOCGState ocg_state; PopplerActionJavascript javascript; + PopplerActionResetForm reset_form; }; #define POPPLER_TYPE_ACTION (poppler_action_get_type ()) diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc index 61d92e8..7542b59 100644 --- a/glib/poppler-document.cc +++ b/glib/poppler-document.cc @@ -1220,6 +1220,45 @@ poppler_document_get_metadata (PopplerDocument *document) return retval; } +/** + * poppler_document_reset_form: + * @document: A #PopplerDocument + * + * Resets the form fields specified by fields if exclude_fields is FALSE + * or all others if exclude_fields is TRUE. + * All form_fields a resetted regardless of the exclude_fields flag + * if fields is empty, + * + * Since: 0.34 + **/ +void +poppler_document_reset_form (PopplerDocument *document, + GList *fields, + gboolean exclude_fields) +{ + Catalog *catalog; + GooList *list; + Form *form; + GList *iter; + + g_return_if_fail (POPPLER_IS_DOCUMENT (document)); + + catalog = document->doc->getCatalog (); + if (catalog && catalog->isOk ()) { + form = catalog->getForm (); + + if (form) { + list = new GooList (g_list_length (fields)); + for (iter = fields; iter != NULL; iter = iter->next) + list->append (new GooString ((char *) iter->data)); + + form->reset (list, exclude_fields); + + deleteGooList (list, GooString); + } + } +} + static void poppler_document_get_property (GObject *object, guint prop_id, diff --git a/glib/poppler-document.h b/glib/poppler-document.h index a34e88c..ca18b1e 100644 --- a/glib/poppler-document.h +++ b/glib/poppler-document.h @@ -227,6 +227,10 @@ PopplerDest *poppler_document_find_dest (PopplerDocument *do PopplerFormField *poppler_document_get_form_field (PopplerDocument *document, gint id); +void poppler_document_reset_form (PopplerDocument *document, + GList *fields, + gboolean exclude_fields); + /* Interface for getting the Index of a poppler_document */ #define POPPLER_TYPE_INDEX_ITER (poppler_index_iter_get_type ()) GType poppler_index_iter_get_type (void) G_GNUC_CONST; -- 2.4.3