From 67297a0108ba18a69972c98ee1771c3dad41d55b Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Tue, 02 May 2006 19:02:46 +0000 Subject: Rework links system, it adds support for remote links now and it makes 2006-05-02 Carlos Garcia Campos * backend/Makefile.am: * backend/ev-document-links.[ch]: * backend/ev-document.[ch]: * backend/ev-link-action.[ch]: * backend/ev-link-dest.[ch]: * backend/ev-link.[ch]: * pdf/ev-poppler.cc: (pdf_document_find_link_dest), (ev_link_dest_from_dest), (ev_link_from_action), (build_tree): * shell/ev-page-action.c: (build_new_tree_cb): * shell/ev-sidebar-links.c: (get_page_from_dest), (print_section_cb), (links_page_num_func), (update_page_callback): * shell/ev-view.[ch]: (ev_view_goto_dest), (ev_view_handle_link), (tip_from_link): * shell/ev-jobs.c: * shell/ev-window.[ch]: (ev_window_open_uri), (sidebar_links_link_activated_cb), (ev_view_popup_cmd_open_link): * shell/ev-application.[ch]: (ev_application_open_window), (ev_application_open_uri): Rework links system, it adds support for remote links now and it makes easier to add new kinds of actions and destinations. Fixes bug #317292 --- (limited to 'backend') diff --git a/backend/Makefile.am b/backend/Makefile.am index c2adf47..db21e4c 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -22,6 +22,10 @@ libevbackend_la_SOURCES= \ ev-backend-marshal.c \ ev-link.c \ ev-link.h \ + ev-link-action.c \ + ev-link-action.h \ + ev-link-dest.c \ + ev-link-dest.h \ ev-document.c \ ev-document.h \ ev-document-factory.c \ diff --git a/backend/ev-document-links.c b/backend/ev-document-links.c index 7ab3468..daec3ea 100644 --- a/backend/ev-document-links.c +++ b/backend/ev-document-links.c @@ -30,10 +30,8 @@ ev_document_links_get_type (void) { static GType type = 0; - if (G_UNLIKELY (type == 0)) - { - static const GTypeInfo our_info = - { + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo our_info = { sizeof (EvDocumentLinksIface), NULL, NULL, @@ -68,3 +66,27 @@ ev_document_links_get_links_model (EvDocumentLinks *document_links) return retval; } + +GList * +ev_document_links_get_links (EvDocumentLinks *document_links, + gint page) +{ + EvDocumentLinksIface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links); + GList *retval; + + retval = iface->get_links (document_links, page); + + return retval; +} + +EvLinkDest * +ev_document_links_find_link_dest (EvDocumentLinks *document_links, + const gchar *link_name) +{ + EvDocumentLinksIface *iface = EV_DOCUMENT_LINKS_GET_IFACE (document_links); + EvLinkDest *retval; + + retval = iface->find_link_dest (document_links, link_name); + + return retval; +} diff --git a/backend/ev-document-links.h b/backend/ev-document-links.h index 1f94596..8e8f20a 100644 --- a/backend/ev-document-links.h +++ b/backend/ev-document-links.h @@ -56,14 +56,23 @@ struct _EvDocumentLinksIface GTypeInterface base_iface; /* Methods */ - gboolean (* has_document_links) (EvDocumentLinks *document_links); - GtkTreeModel *(* get_links_model) (EvDocumentLinks *document_links); + gboolean (* has_document_links) (EvDocumentLinks *document_links); + GtkTreeModel *(* get_links_model) (EvDocumentLinks *document_links); + GList *(* get_links) (EvDocumentLinks *document_links, + gint page); + EvLinkDest *(* find_link_dest) (EvDocumentLinks *document_links, + const gchar *link_name); }; GType ev_document_links_get_type (void); gboolean ev_document_links_has_document_links (EvDocumentLinks *document_links); GtkTreeModel *ev_document_links_get_links_model (EvDocumentLinks *document_links); +GList *ev_document_links_get_links (EvDocumentLinks *document_links, + gint page); +EvLinkDest *ev_document_links_find_link_dest (EvDocumentLinks *document_links, + const gchar *link_name); + G_END_DECLS #endif diff --git a/backend/ev-document.c b/backend/ev-document.c index 10f1d00..8598c11 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -185,21 +185,6 @@ ev_document_get_text (EvDocument *document, return retval; } -GList * -ev_document_get_links (EvDocument *document, - int page) -{ - EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - GList *retval; - - LOG ("ev_document_get_link"); - if (iface->get_links == NULL) - return NULL; - retval = iface->get_links (document, page); - - return retval; -} - gboolean ev_document_has_attachments (EvDocument *document) { diff --git a/backend/ev-document.h b/backend/ev-document.h index ce7714c..0da5fc7 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -44,8 +44,6 @@ typedef struct _EvDocumentIface EvDocumentIface; typedef struct _EvPageCache EvPageCache; typedef struct _EvPageCacheClass EvPageCacheClass; - - #define EV_DOCUMENT_ERROR ev_document_error_quark () #define EV_DOC_MUTEX_LOCK (ev_document_doc_mutex_lock ()) #define EV_DOC_MUTEX_UNLOCK (ev_document_doc_mutex_unlock ()) @@ -90,8 +88,6 @@ struct _EvDocumentIface char * (* get_text) (EvDocument *document, int page, EvRectangle *rect); - GList * (* get_links) (EvDocument *document, - int page); gboolean (* has_attachments) (EvDocument *document); GList * (* get_attachments) (EvDocument *document); GdkPixbuf * (* render_pixbuf) (EvDocument *document, @@ -123,8 +119,6 @@ gboolean ev_document_can_get_text (EvDocument *document); char *ev_document_get_text (EvDocument *document, int page, EvRectangle *rect); -GList *ev_document_get_links (EvDocument *document, - int page); gboolean ev_document_has_attachments (EvDocument *document); GList *ev_document_get_attachments (EvDocument *document); GdkPixbuf *ev_document_render_pixbuf (EvDocument *document, diff --git a/backend/ev-link-action.c b/backend/ev-link-action.c new file mode 100644 index 0000000..23f4194 --- /dev/null +++ b/backend/ev-link-action.c @@ -0,0 +1,319 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2006 Carlos Garcia Campos + * Copyright (C) 2005 Red Hat, Inc. + * + * Evince is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Evince is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "ev-link-action.h" + +enum { + PROP_0, + PROP_TYPE, + PROP_DEST, + PROP_URI, + PROP_FILENAME, + PROP_PARAMS +}; + +struct _EvLinkAction { + GObject base_instance; + + EvLinkActionPrivate *priv; +}; + +struct _EvLinkActionClass { + GObjectClass base_class; +}; + +struct _EvLinkActionPrivate { + EvLinkActionType type; + EvLinkDest *dest; + gchar *uri; + gchar *filename; + gchar *params; +}; + +G_DEFINE_TYPE (EvLinkAction, ev_link_action, G_TYPE_OBJECT) + +#define EV_LINK_ACTION_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_ACTION, EvLinkActionPrivate)) + +GType +ev_link_action_type_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GEnumValue values[] = { + { EV_LINK_ACTION_TYPE_GOTO_DEST, "EV_LINK_ACTION_TYPE_GOTO_DEST", "goto-dest" }, + { 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"}, + { 0, NULL, NULL } + }; + + type = g_enum_register_static ("EvLinkActionType", values); + } + + return type; +} + +EvLinkActionType +ev_link_action_get_action_type (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), 0); + + return self->priv->type; +} + +EvLinkDest * +ev_link_action_get_dest (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL); + + return self->priv->dest; +} + +const gchar * +ev_link_action_get_uri (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL); + + return self->priv->uri; +} + +const gchar * +ev_link_action_get_filename (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL); + + return self->priv->filename; +} + +const gchar * +ev_link_action_get_params (EvLinkAction *self) +{ + g_return_val_if_fail (EV_IS_LINK_ACTION (self), NULL); + + return self->priv->params; +} + +static void +ev_link_action_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *param_spec) +{ + EvLinkAction *self; + + self = EV_LINK_ACTION (object); + + switch (prop_id) { + case PROP_TYPE: + g_value_set_enum (value, self->priv->type); + break; + case PROP_DEST: + g_value_set_pointer (value, self->priv->dest); + break; + case PROP_URI: + g_value_set_string (value, self->priv->uri); + break; + case PROP_FILENAME: + g_value_set_string (value, self->priv->filename); + break; + case PROP_PARAMS: + g_value_set_string (value, self->priv->params); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, + prop_id, + param_spec); + break; + } +} + +static void +ev_link_action_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *param_spec) +{ + EvLinkAction *self = EV_LINK_ACTION (object); + + switch (prop_id) { + case PROP_TYPE: + self->priv->type = g_value_get_enum (value); + break; + case PROP_DEST: + self->priv->dest = g_value_get_pointer (value); + break; + case PROP_URI: + g_free (self->priv->uri); + self->priv->uri = g_value_dup_string (value); + break; + case PROP_FILENAME: + g_free (self->priv->filename); + self->priv->filename = g_value_dup_string (value); + break; + case PROP_PARAMS: + g_free (self->priv->params); + self->priv->params = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, + prop_id, + param_spec); + break; + } +} + +static void +ev_link_action_finalize (GObject *object) +{ + EvLinkActionPrivate *priv; + + priv = EV_LINK_ACTION (object)->priv; + + if (priv->dest) { + g_object_unref (priv->dest); + priv->dest = NULL; + } + + if (priv->uri) { + g_free (priv->uri); + priv->uri = NULL; + } + + if (priv->filename) { + g_free (priv->filename); + priv->filename = NULL; + } + + if (priv->params) { + g_free (priv->params); + priv->params = NULL; + } + + G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object); +} + +static void +ev_link_action_init (EvLinkAction *ev_link_action) +{ + ev_link_action->priv = EV_LINK_ACTION_GET_PRIVATE (ev_link_action); + + ev_link_action->priv->dest = NULL; + ev_link_action->priv->uri = NULL; + ev_link_action->priv->filename = NULL; + ev_link_action->priv->params = NULL; +} + +static void +ev_link_action_class_init (EvLinkActionClass *ev_link_action_class) +{ + GObjectClass *g_object_class; + + g_object_class = G_OBJECT_CLASS (ev_link_action_class); + + g_object_class->set_property = ev_link_action_set_property; + g_object_class->get_property = ev_link_action_get_property; + + g_object_class->finalize = ev_link_action_finalize; + + g_type_class_add_private (g_object_class, sizeof (EvLinkActionPrivate)); + + g_object_class_install_property (g_object_class, + PROP_TYPE, + g_param_spec_enum ("type", + "Action Type", + "The link action type", + EV_TYPE_LINK_ACTION_TYPE, + EV_LINK_ACTION_TYPE_GOTO_DEST, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_DEST, + g_param_spec_pointer ("dest", + "Action destination", + "The link action destination", + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_URI, + g_param_spec_string ("uri", + "Link Action URI", + "The link action URI", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_FILENAME, + g_param_spec_string ("filename", + "Filename", + "The link action filename", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_PARAMS, + g_param_spec_string ("params", + "Params", + "The link action params", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + +EvLinkAction * +ev_link_action_new_dest (EvLinkDest *dest) +{ + return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION, + "dest", dest, + "type", EV_LINK_ACTION_TYPE_GOTO_DEST, + NULL)); +} + +EvLinkAction * +ev_link_action_new_remote (EvLinkDest *dest, + const gchar *filename) +{ + return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION, + "dest", dest, + "filename", filename, + "type", EV_LINK_ACTION_TYPE_GOTO_REMOTE, + NULL)); +} + +EvLinkAction * +ev_link_action_new_external_uri (const gchar *uri) +{ + return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION, + "uri", uri, + "type", EV_LINK_ACTION_TYPE_EXTERNAL_URI, + NULL)); +} + +EvLinkAction * +ev_link_action_new_launch (const gchar *filename, + const gchar *params) +{ + return EV_LINK_ACTION (g_object_new (EV_TYPE_LINK_ACTION, + "filename", filename, + "params", params, + "type", EV_LINK_ACTION_TYPE_LAUNCH, + NULL)); +} diff --git a/backend/ev-link-action.h b/backend/ev-link-action.h new file mode 100644 index 0000000..6ca8d57 --- /dev/null +++ b/backend/ev-link-action.h @@ -0,0 +1,69 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2006 Carlos Garcia Campos + * Copyright (C) 2005 Red Hat, Inc. + * + * Evince is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Evince is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef EV_LINK_ACTION_H +#define EV_LINK_ACTION_H + +#include +#include "ev-link-dest.h" + +G_BEGIN_DECLS + +typedef struct _EvLinkAction EvLinkAction; +typedef struct _EvLinkActionClass EvLinkActionClass; +typedef struct _EvLinkActionPrivate EvLinkActionPrivate; + +#define EV_TYPE_LINK_ACTION (ev_link_action_get_type()) +#define EV_LINK_ACTION(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_LINK_ACTION, EvLinkAction)) +#define EV_LINK_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_LINK_ACTION, EvLinkActionClass)) +#define EV_IS_LINK_ACTION(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_LINK_ACTION)) +#define EV_IS_LINK_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_LINK_ACTION)) +#define EV_LINK_ACTION_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_LINK_ACTION, EvLinkActionClass)) + +#define EV_TYPE_LINK_ACTION_TYPE (ev_link_action_type_get_type ()) + +typedef enum { + EV_LINK_ACTION_TYPE_GOTO_DEST, + EV_LINK_ACTION_TYPE_GOTO_REMOTE, + EV_LINK_ACTION_TYPE_EXTERNAL_URI, + EV_LINK_ACTION_TYPE_LAUNCH, + /* We'll probably fill this in more as we support the other types of + * actions */ +} EvLinkActionType; + +GType ev_link_action_type_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); + +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); + +G_END_DECLS + +#endif /* EV_LINK_ACTION_H */ diff --git a/backend/ev-link-dest.c b/backend/ev-link-dest.c new file mode 100644 index 0000000..2fd2f4d --- /dev/null +++ b/backend/ev-link-dest.c @@ -0,0 +1,429 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2006 Carlos Garcia Campos + * Copyright (C) 2005 Red Hat, Inc. + * + * Evince is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Evince is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "ev-link-dest.h" + +enum { + PROP_0, + PROP_TYPE, + PROP_PAGE, + PROP_LEFT, + PROP_TOP, + PROP_BOTTOM, + PROP_RIGHT, + PROP_ZOOM, + PROP_NAMED +}; + +struct _EvLinkDest { + GObject base_instance; + + EvLinkDestPrivate *priv; +}; + +struct _EvLinkDestClass { + GObjectClass base_class; +}; + +struct _EvLinkDestPrivate { + EvLinkDestType type; + int page; + double top; + double left; + double bottom; + double right; + double zoom; + gchar *named; +}; + +G_DEFINE_TYPE (EvLinkDest, ev_link_dest, G_TYPE_OBJECT) + +#define EV_LINK_DEST_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK_DEST, EvLinkDestPrivate)) + +GType +ev_link_dest_type_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GEnumValue values[] = { + { EV_LINK_DEST_TYPE_PAGE, "EV_LINK_DEST_TYPE_PAGE", "page" }, + { EV_LINK_DEST_TYPE_XYZ, "EV_LINK_DEST_TYPE_XYZ", "xyz" }, + { EV_LINK_DEST_TYPE_FIT, "EV_LINK_DEST_TYPE_FIT", "fit" }, + { EV_LINK_DEST_TYPE_FITH, "EV_LINK_DEST_TYPE_FITH", "fith" }, + { EV_LINK_DEST_TYPE_FITV, "EV_LINK_DEST_TYPE_FITV", "fitv" }, + { EV_LINK_DEST_TYPE_FITR, "EV_LINK_DEST_TYPE_FITR", "fitr" }, + { EV_LINK_DEST_TYPE_NAMED, "EV_LINK_DEST_TYPE_NAMED", "named" }, + { EV_LINK_DEST_TYPE_UNKNOWN, "EV_LINK_DEST_TYPE_UNKNOWN", "unknown" }, + { 0, NULL, NULL } + }; + + type = g_enum_register_static ("EvLinkDestType", values); + } + + return type; +} + +EvLinkDestType +ev_link_dest_get_dest_type (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), 0); + + return self->priv->type; +} + +gint +ev_link_dest_get_page (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), -1); + + return self->priv->page; +} + +gdouble +ev_link_dest_get_top (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), 0); + + return self->priv->top; +} + +gdouble +ev_link_dest_get_left (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), 0); + + return self->priv->left; +} + +gdouble +ev_link_dest_get_bottom (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), 0); + + return self->priv->bottom; +} + +gdouble +ev_link_dest_get_right (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), 0); + + return self->priv->right; +} + +gdouble +ev_link_dest_get_zoom (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), 0); + + return self->priv->zoom; +} + +const gchar * +ev_link_dest_get_named_dest (EvLinkDest *self) +{ + g_return_val_if_fail (EV_IS_LINK_DEST (self), NULL); + + return self->priv->named; +} + +static void +ev_link_dest_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *param_spec) +{ + EvLinkDest *self; + + self = EV_LINK_DEST (object); + + switch (prop_id) { + case PROP_TYPE: + g_value_set_enum (value, self->priv->type); + break; + case PROP_PAGE: + g_value_set_int (value, self->priv->page); + break; + case PROP_TOP: + g_value_set_double (value, self->priv->top); + break; + case PROP_LEFT: + g_value_set_double (value, self->priv->left); + break; + case PROP_BOTTOM: + g_value_set_double (value, self->priv->bottom); + break; + case PROP_RIGHT: + g_value_set_double (value, self->priv->left); + break; + case PROP_ZOOM: + g_value_set_double (value, self->priv->zoom); + break; + case PROP_NAMED: + g_value_set_string (value, self->priv->named); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, + prop_id, + param_spec); + break; + } +} + +static void +ev_link_dest_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *param_spec) +{ + EvLinkDest *self = EV_LINK_DEST (object); + + switch (prop_id) { + case PROP_TYPE: + self->priv->type = g_value_get_enum (value); + break; + case PROP_PAGE: + self->priv->page = g_value_get_int (value); + break; + case PROP_TOP: + self->priv->top = g_value_get_double (value); + break; + case PROP_LEFT: + self->priv->left = g_value_get_double (value); + break; + case PROP_BOTTOM: + self->priv->bottom = g_value_get_double (value); + break; + case PROP_RIGHT: + self->priv->right = g_value_get_double (value); + break; + case PROP_ZOOM: + self->priv->zoom = g_value_get_double (value); + break; + case PROP_NAMED: + self->priv->named = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, + prop_id, + param_spec); + break; + } +} + +static void +ev_link_dest_finalize (GObject *object) +{ + EvLinkDestPrivate *priv; + + priv = EV_LINK_DEST (object)->priv; + + if (priv->named) { + g_free (priv->named); + priv->named = NULL; + } + + G_OBJECT_CLASS (ev_link_dest_parent_class)->finalize (object); +} + +static void +ev_link_dest_init (EvLinkDest *ev_link_dest) +{ + ev_link_dest->priv = EV_LINK_DEST_GET_PRIVATE (ev_link_dest); + + ev_link_dest->priv->named = NULL; +} + +static void +ev_link_dest_class_init (EvLinkDestClass *ev_link_dest_class) +{ + GObjectClass *g_object_class; + + g_object_class = G_OBJECT_CLASS (ev_link_dest_class); + + g_object_class->set_property = ev_link_dest_set_property; + g_object_class->get_property = ev_link_dest_get_property; + + g_object_class->finalize = ev_link_dest_finalize; + + g_type_class_add_private (g_object_class, sizeof (EvLinkDestPrivate)); + + g_object_class_install_property (g_object_class, + PROP_TYPE, + g_param_spec_enum ("type", + "Dest Type", + "The destination type", + EV_TYPE_LINK_DEST_TYPE, + EV_LINK_DEST_TYPE_UNKNOWN, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_PAGE, + g_param_spec_int ("page", + "Dest Page", + "The destination page", + -1, + G_MAXINT, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_LEFT, + g_param_spec_double ("left", + "Left coordinate", + "The left coordinate", + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_TOP, + g_param_spec_double ("top", + "Top coordinate", + "The top coordinate", + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_BOTTOM, + g_param_spec_double ("bottom", + "Bottom coordinate", + "The bottom coordinate", + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_RIGHT, + g_param_spec_double ("right", + "Right coordinate", + "The right coordinate", + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (g_object_class, + PROP_ZOOM, + g_param_spec_double ("zoom", + "Zoom", + "Zoom", + 0, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (g_object_class, + PROP_NAMED, + g_param_spec_string ("named", + "Named destination", + "The named destination", + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); +} + +EvLinkDest * +ev_link_dest_new_page (gint page) +{ + return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST, + "page", page, + "type", EV_LINK_DEST_TYPE_PAGE, + NULL)); +} + +EvLinkDest * +ev_link_dest_new_xyz (gint page, + gdouble left, + gdouble top, + gdouble zoom) +{ + return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST, + "page", page, + "type", EV_LINK_DEST_TYPE_XYZ, + "left", left, + "top", top, + "zoom", zoom, + NULL)); +} + +EvLinkDest * +ev_link_dest_new_fit (gint page) +{ + return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST, + "page", page, + "type", EV_LINK_DEST_TYPE_FIT, + NULL)); +} + +EvLinkDest * +ev_link_dest_new_fith (gint page, + gdouble top) +{ + return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST, + "page", page, + "type", EV_LINK_DEST_TYPE_FITH, + "top", top, + NULL)); +} + +EvLinkDest * +ev_link_dest_new_fitv (gint page, + gdouble left) +{ + return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST, + "page", page, + "type", EV_LINK_DEST_TYPE_FITV, + "left", left, + NULL)); +} + +EvLinkDest * +ev_link_dest_new_fitr (gint page, + gdouble left, + gdouble bottom, + gdouble right, + gdouble top) +{ + return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST, + "page", page, + "type", EV_LINK_DEST_TYPE_FITR, + "left", left, + "bottom", bottom, + "right", right, + "top", top, + NULL)); +} + +EvLinkDest * +ev_link_dest_new_named (const gchar *named_dest) +{ + return EV_LINK_DEST (g_object_new (EV_TYPE_LINK_DEST, + "named", named_dest, + "type", EV_LINK_DEST_TYPE_NAMED, + NULL)); +} diff --git a/backend/ev-link-dest.h b/backend/ev-link-dest.h new file mode 100644 index 0000000..40a8a9b --- /dev/null +++ b/backend/ev-link-dest.h @@ -0,0 +1,83 @@ +/* this file is part of evince, a gnome document viewer + * + * Copyright (C) 2006 Carlos Garcia Campos + * Copyright (C) 2005 Red Hat, Inc. + * + * Evince is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Evince is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef EV_LINK_DEST_H +#define EV_LINK_DEST_H + +#include + +G_BEGIN_DECLS + +typedef struct _EvLinkDest EvLinkDest; +typedef struct _EvLinkDestClass EvLinkDestClass; +typedef struct _EvLinkDestPrivate EvLinkDestPrivate; + +#define EV_TYPE_LINK_DEST (ev_link_dest_get_type()) +#define EV_LINK_DEST(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_LINK_DEST, EvLinkDest)) +#define EV_LINK_DEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_LINK_DEST, EvLinkDestClass)) +#define EV_IS_LINK_DEST(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_LINK_DEST)) +#define EV_IS_LINK_DEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_LINK_DEST)) +#define EV_LINK_DEST_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_LINK_DEST, EvLinkDestClass)) + +#define EV_TYPE_LINK_DEST_TYPE (ev_link_dest_type_get_type ()) + +typedef enum { + EV_LINK_DEST_TYPE_PAGE, + EV_LINK_DEST_TYPE_XYZ, + EV_LINK_DEST_TYPE_FIT, + EV_LINK_DEST_TYPE_FITH, + EV_LINK_DEST_TYPE_FITV, + EV_LINK_DEST_TYPE_FITR, + EV_LINK_DEST_TYPE_NAMED, + EV_LINK_DEST_TYPE_UNKNOWN +} EvLinkDestType; + +GType ev_link_dest_type_get_type (void) G_GNUC_CONST; +GType ev_link_dest_get_type (void) G_GNUC_CONST; + +EvLinkDestType ev_link_dest_get_dest_type (EvLinkDest *self); +gint ev_link_dest_get_page (EvLinkDest *self); +gdouble ev_link_dest_get_top (EvLinkDest *self); +gdouble ev_link_dest_get_left (EvLinkDest *self); +gdouble ev_link_dest_get_bottom (EvLinkDest *self); +gdouble ev_link_dest_get_right (EvLinkDest *self); +gdouble ev_link_dest_get_zoom (EvLinkDest *self); +const gchar *ev_link_dest_get_named_dest (EvLinkDest *self); + +EvLinkDest *ev_link_dest_new_page (gint page); +EvLinkDest *ev_link_dest_new_xyz (gint page, + gdouble left, + gdouble top, + gdouble zoom); +EvLinkDest *ev_link_dest_new_fit (gint page); +EvLinkDest *ev_link_dest_new_fith (gint page, + gdouble top); +EvLinkDest *ev_link_dest_new_fitv (gint page, + gdouble left); +EvLinkDest *ev_link_dest_new_fitr (gint page, + gdouble left, + gdouble bottom, + gdouble right, + gdouble top); +EvLinkDest *ev_link_dest_new_named (const gchar *named_dest); + +G_END_DECLS + +#endif /* EV_LINK_DEST_H */ diff --git a/backend/ev-link.c b/backend/ev-link.c index a325c35..8561914 100644 --- a/backend/ev-link.c +++ b/backend/ev-link.c @@ -18,28 +18,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "ev-link.h" enum { PROP_0, PROP_TITLE, - PROP_TYPE, - PROP_PAGE, - PROP_URI, - PROP_LEFT, - PROP_TOP, - PROP_BOTTOM, - PROP_RIGHT, - PROP_ZOOM, - PROP_FILENAME, - PROP_PARAMS + PROP_ACTION }; - struct _EvLink { GObject base_instance; EvLinkPrivate *priv; @@ -50,17 +36,8 @@ struct _EvLinkClass { }; struct _EvLinkPrivate { - char *title; - char *uri; - char *filename; - char *params; - EvLinkType type; - int page; - double top; - double left; - double bottom; - double right; - double zoom; + gchar *title; + EvLinkAction *action; }; G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT) @@ -68,32 +45,7 @@ G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT) #define EV_LINK_GET_PRIVATE(object) \ (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_LINK, EvLinkPrivate)) -GType -ev_link_type_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - static const GEnumValue values[] = { - { EV_LINK_TYPE_TITLE, "EV_LINK_TYPE_TITLE", "title" }, - { EV_LINK_TYPE_PAGE, "EV_LINK_TYPE_PAGE", "page" }, - { EV_LINK_TYPE_PAGE_XYZ, "EV_LINK_TYPE_PAGE_XYZ", "page-xyz" }, - { EV_LINK_TYPE_PAGE_FIT, "EV_LINK_TYPE_PAGE_FIT", "page-fit" }, - { EV_LINK_TYPE_PAGE_FITH, "EV_LINK_TYPE_PAGE_FITH", "page-fith" }, - { EV_LINK_TYPE_PAGE_FITV, "EV_LINK_TYPE_PAGE_FITV", "page-fitv" }, - { EV_LINK_TYPE_PAGE_FITR, "EV_LINK_TYPE_PAGE_FITR", "page-fitr" }, - { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" }, - { EV_LINK_TYPE_LAUNCH, "EV_LINK_TYPE_LAUNCH", "launch" }, - { 0, NULL, NULL } - }; - - type = g_enum_register_static ("EvLinkType", values); - } - - return type; -} - -const char * +const gchar * ev_link_get_title (EvLink *self) { g_return_val_if_fail (EV_IS_LINK (self), NULL); @@ -101,88 +53,18 @@ ev_link_get_title (EvLink *self) return self->priv->title; } -const char * -ev_link_get_uri (EvLink *self) +EvLinkAction * +ev_link_get_action (EvLink *self) { g_return_val_if_fail (EV_IS_LINK (self), NULL); - return self->priv->uri; -} - -EvLinkType -ev_link_get_link_type (EvLink *self) -{ - g_return_val_if_fail (EV_IS_LINK (self), 0); - - return self->priv->type; -} - -int -ev_link_get_page (EvLink *self) -{ - g_return_val_if_fail (EV_IS_LINK (self), -1); - - return self->priv->page; -} - -double -ev_link_get_top (EvLink *self) -{ - g_return_val_if_fail (EV_IS_LINK (self), 0); - - return self->priv->top; -} - -double -ev_link_get_left (EvLink *self) -{ - g_return_val_if_fail (EV_IS_LINK (self), 0); - - return self->priv->left; -} - -double -ev_link_get_bottom (EvLink *self) -{ - g_return_val_if_fail (EV_IS_LINK (self), 0); - - return self->priv->bottom; -} - -double -ev_link_get_right (EvLink *self) -{ - g_return_val_if_fail (EV_IS_LINK (self), 0); - - return self->priv->right; -} - -const char * -ev_link_get_filename (EvLink *link) -{ - g_return_val_if_fail (EV_IS_LINK (link), NULL); - - return link->priv->filename; -} - -const char * -ev_link_get_params (EvLink *link) -{ - g_return_val_if_fail (EV_IS_LINK (link), NULL); - - return link->priv->params; -} - -double -ev_link_get_zoom (EvLink *self) -{ - g_return_val_if_fail (EV_IS_LINK (self), 0); - - return self->priv->zoom; + return self->priv->action; } static void -ev_link_get_property (GObject *object, guint prop_id, GValue *value, +ev_link_get_property (GObject *object, + guint prop_id, + GValue *value, GParamSpec *param_spec) { EvLink *self; @@ -190,103 +72,48 @@ ev_link_get_property (GObject *object, guint prop_id, GValue *value, self = EV_LINK (object); switch (prop_id) { - case PROP_TITLE: - g_value_set_string (value, self->priv->title); - break; - case PROP_URI: - g_value_set_string (value, self->priv->uri); - break; - case PROP_TYPE: - g_value_set_enum (value, self->priv->type); - break; - case PROP_PAGE: - g_value_set_int (value, self->priv->page); - break; - case PROP_TOP: - g_value_set_double (value, self->priv->top); - break; - case PROP_LEFT: - g_value_set_double (value, self->priv->left); - break; - case PROP_BOTTOM: - g_value_set_double (value, self->priv->bottom); - break; - case PROP_RIGHT: - g_value_set_double (value, self->priv->left); - break; - case PROP_ZOOM: - g_value_set_double (value, self->priv->zoom); - break; - case PROP_FILENAME: - g_value_set_string (value, self->priv->filename); - case PROP_PARAMS: - g_value_set_string (value, self->priv->params); - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, - prop_id, - param_spec); - break; + case PROP_TITLE: + g_value_set_string (value, self->priv->title); + break; + case PROP_ACTION: + g_value_set_pointer (value, self->priv->action); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, + prop_id, + param_spec); + break; } } static void -ev_link_set_property (GObject *object, guint prop_id, const GValue *value, - GParamSpec *param_spec) +ev_link_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *param_spec) { - EvLink *link = EV_LINK (object); + EvLink *self = EV_LINK (object); switch (prop_id) { - case PROP_TITLE: - link->priv->title = g_strdup (g_value_get_string (value)); - break; - case PROP_URI: - link->priv->uri = g_strdup (g_value_get_string (value)); - break; - case PROP_TYPE: - link->priv->type = g_value_get_enum (value); - break; - case PROP_PAGE: - link->priv->page = g_value_get_int (value); - break; - case PROP_TOP: - link->priv->top = g_value_get_double (value); - break; - case PROP_LEFT: - link->priv->left = g_value_get_double (value); - break; - case PROP_BOTTOM: - link->priv->bottom = g_value_get_double (value); - break; - case PROP_RIGHT: - link->priv->right = g_value_get_double (value); - break; - case PROP_ZOOM: - link->priv->zoom = g_value_get_double (value); - break; - case PROP_FILENAME: - g_free (link->priv->filename); - link->priv->filename = g_strdup (g_value_get_string (value)); - break; - case PROP_PARAMS: - g_free (link->priv->params); - link->priv->params = g_strdup (g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, - prop_id, - param_spec); - break; + case PROP_TITLE: + self->priv->title = g_value_dup_string (value); + break; + case PROP_ACTION: + self->priv->action = g_value_get_pointer (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, + prop_id, + param_spec); + break; } } static void -ev_window_dispose (GObject *object) +ev_link_finalize (GObject *object) { EvLinkPrivate *priv; - g_return_if_fail (EV_IS_LINK (object)); - priv = EV_LINK (object)->priv; if (priv->title) { @@ -294,30 +121,21 @@ ev_window_dispose (GObject *object) priv->title = NULL; } - if (priv->uri) { - g_free (priv->uri); - priv->uri = NULL; - } - - if (priv->filename) { - g_free (priv->filename); - priv->filename = NULL; - } - - if (priv->params) { - g_free (priv->params); - priv->params = NULL; + if (priv->action) { + g_object_unref (priv->action); + priv->action = NULL; } - G_OBJECT_CLASS (ev_link_parent_class)->dispose (object); + G_OBJECT_CLASS (ev_link_parent_class)->finalize (object); } static void ev_link_init (EvLink *ev_link) { ev_link->priv = EV_LINK_GET_PRIVATE (ev_link); - ev_link->priv->page = -1; - ev_link->priv->type = EV_LINK_TYPE_TITLE; + + ev_link->priv->title = NULL; + ev_link->priv->action = NULL; } static void @@ -326,10 +144,12 @@ ev_link_class_init (EvLinkClass *ev_window_class) GObjectClass *g_object_class; g_object_class = G_OBJECT_CLASS (ev_window_class); - g_object_class->dispose = ev_window_dispose; + g_object_class->set_property = ev_link_set_property; g_object_class->get_property = ev_link_get_property; + g_object_class->finalize = ev_link_finalize; + g_type_class_add_private (g_object_class, sizeof (EvLinkPrivate)); g_object_class_install_property (g_object_class, @@ -341,216 +161,25 @@ ev_link_class_init (EvLinkClass *ev_window_class) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (g_object_class, - PROP_URI, - g_param_spec_string ("uri", - "Link URI", - "The link URI", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_FILENAME, - g_param_spec_string ("filename", - "Filename", - "The link filename", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_PARAMS, - g_param_spec_string ("params", - "Params", - "The link params", - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_TYPE, - g_param_spec_enum ("type", - "Link Type", - "The link type", - EV_TYPE_LINK_TYPE, - EV_LINK_TYPE_TITLE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_PAGE, - g_param_spec_int ("page", - "Link Page", - "The link page", - -1, - G_MAXINT, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_LEFT, - g_param_spec_double ("left", - "Left coordinate", - "The left coordinate", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_TOP, - g_param_spec_double ("top", - "Top coordinate", - "The top coordinate", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_BOTTOM, - g_param_spec_double ("bottom", - "Bottom coordinate", - "The bottom coordinate", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (g_object_class, - PROP_RIGHT, - g_param_spec_double ("right", - "Right coordinate", - "The right coordinate", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (g_object_class, - PROP_ZOOM, - g_param_spec_double ("zoom", - "Zoom", - "Zoom", - 0, - G_MAXDOUBLE, - 0, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); -} - -EvLink * -ev_link_new_title (const char *title) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "type", EV_LINK_TYPE_TITLE, - NULL)); -} - -EvLink * -ev_link_new_page (const char *title, int page) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "page", page, - "type", EV_LINK_TYPE_PAGE, - NULL)); -} - -EvLink * -ev_link_new_page_xyz (const char *title, - int page, - double left, - double top, - double zoom) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "page", page, - "type", EV_LINK_TYPE_PAGE_XYZ, - "left", left, - "top", top, - "zoom", zoom, - NULL)); -} - -EvLink * -ev_link_new_page_fit (const char *title, - int page) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "page", page, - "type", EV_LINK_TYPE_PAGE_FIT, - NULL)); -} - -EvLink * -ev_link_new_page_fith (const char *title, - int page, - double top) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "page", page, - "type", EV_LINK_TYPE_PAGE_FITH, - "top", top, - NULL)); -} - -EvLink * -ev_link_new_page_fitv (const char *title, - int page, - double left) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "page", page, - "type", EV_LINK_TYPE_PAGE_FITV, - "left", left, - NULL)); -} - -EvLink * -ev_link_new_page_fitr (const char *title, - int page, - double left, - double bottom, - double right, - double top) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "page", page, - "type", EV_LINK_TYPE_PAGE_FITR, - "left", left, - "bottom", bottom, - "right", right, - "top", top, - NULL)); + PROP_ACTION, + g_param_spec_pointer ("action", + "Link Action", + "The link action", + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); } EvLink * -ev_link_new_external (const char *title, const char *uri) +ev_link_new (const char *title, + EvLinkAction *action) { return EV_LINK (g_object_new (EV_TYPE_LINK, "title", title, - "uri", uri, - "type", EV_LINK_TYPE_EXTERNAL_URI, - NULL)); -} - -EvLink * -ev_link_new_launch (const char *title, - const char *filename, - const char *params) -{ - return EV_LINK (g_object_new (EV_TYPE_LINK, - "title", title, - "filename", filename, - "params", params, - "type", EV_LINK_TYPE_LAUNCH, + "action", action, NULL)); } +/* Link Mapping stuff */ static void ev_link_mapping_free_foreach (EvLinkMapping *mapping) { @@ -568,7 +197,6 @@ ev_link_mapping_free (GList *link_mapping) g_list_free (link_mapping); } - EvLink * ev_link_mapping_find (GList *link_mapping, gdouble x, diff --git a/backend/ev-link.h b/backend/ev-link.h index 6ab2811..b7304de 100644 --- a/backend/ev-link.h +++ b/backend/ev-link.h @@ -21,6 +21,7 @@ #define EV_LINK_H #include +#include "ev-link-action.h" G_BEGIN_DECLS @@ -28,77 +29,22 @@ typedef struct _EvLink EvLink; typedef struct _EvLinkClass EvLinkClass; typedef struct _EvLinkPrivate EvLinkPrivate; -#define EV_TYPE_LINK (ev_link_get_type()) -#define EV_LINK(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_LINK, EvLink)) -#define EV_LINK_CLASS(klass) (G_TYPE_CHACK_CLASS_CAST((klass), EV_TYPE_LINK, EvLinkClass)) -#define EV_IS_LINK(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_LINK)) -#define EV_IS_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_LINK)) +#define EV_TYPE_LINK (ev_link_get_type()) +#define EV_LINK(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_LINK, EvLink)) +#define EV_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_LINK, EvLinkClass)) +#define EV_IS_LINK(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_LINK)) +#define EV_IS_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_LINK)) #define EV_LINK_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_LINK, EvLinkClass)) -#define EV_TYPE_LINK_TYPE (ev_link_type_get_type ()) +GType ev_link_get_type (void) G_GNUC_CONST; +EvLink *ev_link_new (const gchar *title, + EvLinkAction *action); - -typedef enum -{ - EV_LINK_TYPE_TITLE, - EV_LINK_TYPE_PAGE, - EV_LINK_TYPE_PAGE_XYZ, - EV_LINK_TYPE_PAGE_FIT, - EV_LINK_TYPE_PAGE_FITH, - EV_LINK_TYPE_PAGE_FITV, - EV_LINK_TYPE_PAGE_FITR, - EV_LINK_TYPE_EXTERNAL_URI, - EV_LINK_TYPE_LAUNCH - /* We'll probably fill this in more as we support the other types of - * links */ -} EvLinkType; - -GType ev_link_type_get_type (void); -GType ev_link_get_type (void); - -EvLink *ev_link_new_title (const char *title); -EvLink *ev_link_new_page (const char *title, - int page); -EvLink *ev_link_new_page_xyz (const char *title, - int page, - double top, - double left, - double zoom); -EvLink *ev_link_new_page_fith (const char *title, - int page, - double top); -EvLink *ev_link_new_page_fitv (const char *title, - int page, - double left); -EvLink *ev_link_new_page_fitr (const char *title, - int page, - double left, - double bottom, - double right, - double top); -EvLink *ev_link_new_page_fit (const char *title, - int page); -EvLink *ev_link_new_external (const char *title, - const char *uri); -EvLink *ev_link_new_launch (const char *title, - const char *filename, - const char *params); - -const char *ev_link_get_title (EvLink *link); -const char *ev_link_get_uri (EvLink *link); -EvLinkType ev_link_get_link_type (EvLink *link); -int ev_link_get_page (EvLink *link); -double ev_link_get_top (EvLink *link); -double ev_link_get_left (EvLink *link); -double ev_link_get_bottom (EvLink *link); -double ev_link_get_right (EvLink *link); -double ev_link_get_zoom (EvLink *link); -const char *ev_link_get_filename (EvLink *link); -const char *ev_link_get_params (EvLink *link); +const gchar *ev_link_get_title (EvLink *self); +EvLinkAction *ev_link_get_action (EvLink *self); /* Link Mapping stuff */ - typedef struct _EvLinkMapping EvLinkMapping; struct _EvLinkMapping { -- cgit v0.9.1