From fdf6ceaeede339118ddc2d389ba60be8e3bae9c1 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Thu, 4 May 2006 08:24:19 +0000 Subject: [PATCH] Add support for Named Action links 2006-05-03 Carlos Garcia Campos * backend/ev-link-action.[ch]: * pdf/ev-poppler.cc: (ev_link_from_action): * shell/ev-view-private.h: * shell/ev-view.c: (ev_view_handle_link), (tip_from_action_named): * shell/ev-window.c: (do_action_named), (view_external_link_cb): Add support for Named Action links --- ChangeLog | 10 ++++++++++ backend/ev-link-action.c | 43 +++++++++++++++++++++++++++++++++++++++- backend/ev-link-action.h | 3 +++ pdf/ev-poppler.cc | 2 +- shell/ev-view-private.h | 2 +- shell/ev-view.c | 26 ++++++++++++++++++++++++ shell/ev-window.c | 26 ++++++++++++++++++++++++ 7 files changed, 109 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b583775a..0c60baae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-05-03 Carlos Garcia Campos + + * backend/ev-link-action.[ch]: + * pdf/ev-poppler.cc: (ev_link_from_action): + * shell/ev-view-private.h: + * shell/ev-view.c: (ev_view_handle_link), (tip_from_action_named): + * shell/ev-window.c: (do_action_named), (view_external_link_cb): + + Add support for Named Action links + 2006-05-02 Carlos Garcia Campos * backend/Makefile.am: diff --git a/backend/ev-link-action.c b/backend/ev-link-action.c index 23f41943..bc0a8fc1 100644 --- a/backend/ev-link-action.c +++ b/backend/ev-link-action.c @@ -26,7 +26,8 @@ enum { PROP_DEST, PROP_URI, PROP_FILENAME, - PROP_PARAMS + PROP_PARAMS, + PROP_NAME }; struct _EvLinkAction { @@ -45,6 +46,7 @@ struct _EvLinkActionPrivate { gchar *uri; gchar *filename; gchar *params; + gchar *name; }; G_DEFINE_TYPE (EvLinkAction, ev_link_action, G_TYPE_OBJECT) @@ -63,6 +65,7 @@ ev_link_action_type_get_type (void) { EV_LINK_ACTION_TYPE_GOTO_REMOTE, "EV_LINK_ACTION_TYPE_GOTO_REMOTE", "goto-remote" }, { EV_LINK_ACTION_TYPE_LAUNCH, "EV_LINK_ACTION_TYPE_LAUNCH", "launch" }, { EV_LINK_ACTION_TYPE_EXTERNAL_URI, "EV_LINK_ACTION_TYPE_EXTERNAL_URI", "external-uri"}, + { EV_LINK_ACTION_TYPE_NAMED, "EV_LINK_ACTION_TYPE_NAMED", "named"}, { 0, NULL, NULL } }; @@ -112,6 +115,14 @@ ev_link_action_get_params (EvLinkAction *self) return self->priv->params; } +const gchar * +ev_link_action_get_name (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL); + + return self->priv->name; +} + static void ev_link_action_get_property (GObject *object, guint prop_id, @@ -138,6 +149,9 @@ ev_link_action_get_property (GObject *object, case PROP_PARAMS: g_value_set_string (value, self->priv->params); break; + case PROP_NAME: + g_value_set_string (value, self->priv->name); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, @@ -173,6 +187,10 @@ ev_link_action_set_property (GObject *object, g_free (self->priv->params); self->priv->params = g_value_dup_string (value); break; + case PROP_NAME: + g_free (self->priv->name); + self->priv->name = g_value_dup_string (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, @@ -208,6 +226,11 @@ ev_link_action_finalize (GObject *object) priv->params = NULL; } + if (priv->name) { + g_free (priv->name); + priv->name = NULL; + } + G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object); } @@ -220,6 +243,7 @@ ev_link_action_init (EvLinkAction *ev_link_action) ev_link_action->priv->uri = NULL; ev_link_action->priv->filename = NULL; ev_link_action->priv->params = NULL; + ev_link_action->priv->name = NULL; } static void @@ -276,6 +300,14 @@ ev_link_action_class_init (EvLinkActionClass *ev_link_action_class) NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_NAME, + g_param_spec_string ("name", + "Name", + "The link action name", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); } EvLinkAction * @@ -317,3 +349,12 @@ ev_link_action_new_launch (const gchar *filename, "type", EV_LINK_ACTION_TYPE_LAUNCH, NULL)); } + +EvLinkAction * +ev_link_action_new_named (const gchar *name) +{ + return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION, + "name", name, + "type", EV_LINK_ACTION_TYPE_NAMED, + NULL)); +} diff --git a/backend/ev-link-action.h b/backend/ev-link-action.h index 6ca8d572..32211fe2 100644 --- a/backend/ev-link-action.h +++ b/backend/ev-link-action.h @@ -44,6 +44,7 @@ typedef enum { EV_LINK_ACTION_TYPE_GOTO_REMOTE, EV_LINK_ACTION_TYPE_EXTERNAL_URI, EV_LINK_ACTION_TYPE_LAUNCH, + EV_LINK_ACTION_TYPE_NAMED /* We'll probably fill this in more as we support the other types of * actions */ } EvLinkActionType; @@ -56,6 +57,7 @@ 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); EvLinkAction *ev_link_action_new_dest (EvLinkDest *dest); EvLinkAction *ev_link_action_new_remote (EvLinkDest *dest, @@ -63,6 +65,7 @@ EvLinkAction *ev_link_action_new_remote (EvLinkDest *dest, 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); G_END_DECLS diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index efdd15f2..5c2f54d6 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -873,7 +873,7 @@ ev_link_from_action (PopplerAction *action) ev_action = ev_link_action_new_external_uri (action->uri.uri); break; case POPPLER_ACTION_NAMED: - unimplemented_action = "POPPLER_ACTION_NAMED"; + ev_action = ev_link_action_new_named (action->named.named_dest); break; case POPPLER_ACTION_MOVIE: unimplemented_action = "POPPLER_ACTION_MOVIE"; diff --git a/shell/ev-view-private.h b/shell/ev-view-private.h index 1d09cb37..a53fe546 100644 --- a/shell/ev-view-private.h +++ b/shell/ev-view-private.h @@ -129,7 +129,7 @@ struct _EvViewClass { gboolean horizontal); void (*zoom_invalid) (EvView *view); void (*external_link) (EvView *view, - EvLink *link); + EvLinkAction *action); void (*popup_menu) (EvView *view, EvLink *link); }; diff --git a/shell/ev-view.c b/shell/ev-view.c index 0380e226..e3f07dc9 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -1289,6 +1289,7 @@ ev_view_handle_link (EvView *view, EvLink *link) case EV_LINK_ACTION_TYPE_GOTO_REMOTE: case EV_LINK_ACTION_TYPE_EXTERNAL_URI: case EV_LINK_ACTION_TYPE_LAUNCH: + case EV_LINK_ACTION_TYPE_NAMED: g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, action); break; } @@ -1326,6 +1327,28 @@ page_label_from_dest (EvView *view, EvLinkDest *dest) return msg; } +static char * +tip_from_action_named (EvLinkAction *action) +{ + const gchar *name = ev_link_action_get_name (action); + + if (g_ascii_strcasecmp (name, "FirstPage") == 0) { + return g_strdup (_("Got to fisrt page")); + } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) { + return g_strdup (_("Got to previuos page")); + } else if (g_ascii_strcasecmp (name, "NextPage") == 0) { + return g_strdup (_("Got to next page")); + } else if (g_ascii_strcasecmp (name, "LastPage") == 0) { + return g_strdup (_("Got to last page")); + } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) { + return g_strdup (_("Got to page")); + } else if (g_ascii_strcasecmp (name, "Find") == 0) { + return g_strdup (_("Find")); + } + + return NULL; +} + static char * tip_from_link (EvView *view, EvLink *link) { @@ -1367,6 +1390,9 @@ tip_from_link (EvView *view, EvLink *link) msg = g_strdup_printf (_("Launch %s"), ev_link_action_get_filename (action)); break; + case EV_LINK_ACTION_TYPE_NAMED: + msg = tip_from_action_named (action); + break; default: if (title) msg = g_strdup (title); diff --git a/shell/ev-window.c b/shell/ev-window.c index 2fad47bf..c04801a4 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -3319,6 +3319,29 @@ open_remote_link (EvWindow *window, EvLinkAction *action) g_free (uri); } +static void +do_action_named (EvWindow *window, EvLinkAction *action) +{ + const gchar *name = ev_link_action_get_name (action); + + if (g_ascii_strcasecmp (name, "FirstPage") == 0) { + ev_window_cmd_go_first_page (NULL, window); + } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) { + ev_window_cmd_go_previous_page (NULL, window); + } else if (g_ascii_strcasecmp (name, "NextPage") == 0) { + ev_window_cmd_go_next_page (NULL, window); + } else if (g_ascii_strcasecmp (name, "LastPage") == 0) { + ev_window_cmd_go_last_page (NULL, window); + } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) { + ev_window_cmd_focus_page_selector (NULL, window); + } else if (g_ascii_strcasecmp (name, "Find") == 0) { + ev_window_cmd_edit_find (NULL, window); + } else { + g_warning ("Unimplemented named action: %s, please post a bug report with a testcase.", + name); + } +} + static void view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window) { @@ -3332,6 +3355,9 @@ view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window) case EV_LINK_ACTION_TYPE_GOTO_REMOTE: open_remote_link (window, action); break; + case EV_LINK_ACTION_TYPE_NAMED: + do_action_named (window, action); + break; default: g_assert_not_reached (); } -- 2.43.5