From c43d8117b5174476437718101d58117ad9191c84 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 7 Jan 2005 13:35:18 +0000 Subject: [PATCH] Add a way to open bookmarks 2005-01-07 Marco Pesenti Gritti * shell/ev-application.c: (ev_application_open), (ev_application_open_bookmark): * shell/ev-application.h: Add a way to open bookmarks * backend/ev-bookmark.c: (ev_bookmark_get_uri), (ev_bookmark_set_uri), (ev_bookmark_get_property), (ev_bookmark_set_property), (ev_bookmark_class_init), (ev_bookmark_new_title), (ev_bookmark_new_link), (ev_bookmark_new_external): Support for external uris, better constructors. * backend/ev-bookmark.h: * pdf/xpdf/pdf-document.cc: * shell/ev-sidebar-bookmarks.c: (selection_changed_cb): Handle external uris --- ChangeLog | 22 +++++++++ backend/ev-bookmark.c | 66 ++++++++++++++++++++++++-- backend/ev-bookmark.h | 9 +++- pdf/xpdf/pdf-document.cc | 92 ++++++++++++++++-------------------- shell/ev-application.c | 29 +++++++++++- shell/ev-application.h | 9 +++- shell/ev-sidebar-bookmarks.c | 7 +-- 7 files changed, 171 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9491e85a..ca0222cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2005-01-07 Marco Pesenti Gritti + + * shell/ev-application.c: (ev_application_open), + (ev_application_open_bookmark): + * shell/ev-application.h: + + Add a way to open bookmarks + + * backend/ev-bookmark.c: (ev_bookmark_get_uri), + (ev_bookmark_set_uri), (ev_bookmark_get_property), + (ev_bookmark_set_property), (ev_bookmark_class_init), + (ev_bookmark_new_title), (ev_bookmark_new_link), + (ev_bookmark_new_external): + + Support for external uris, better constructors. + + * backend/ev-bookmark.h: + * pdf/xpdf/pdf-document.cc: + * shell/ev-sidebar-bookmarks.c: (selection_changed_cb): + + Handle external uris + 2005-01-07 Marco Pesenti Gritti * shell/ev-sidebar-bookmarks.c: (selection_changed_cb), diff --git a/backend/ev-bookmark.c b/backend/ev-bookmark.c index f28c32bf..f2d9f235 100644 --- a/backend/ev-bookmark.c +++ b/backend/ev-bookmark.c @@ -28,11 +28,13 @@ enum { PROP_0, PROP_TITLE, PROP_TYPE, - PROP_PAGE + PROP_PAGE, + PROP_URI }; struct _EvBookmarkPrivate { char *title; + char *uri; EvBookmarkType type; int page; }; @@ -86,6 +88,29 @@ ev_bookmark_set_title (EvBookmark* self, const char *title) g_object_notify (G_OBJECT (self), "title"); } +const char * +ev_bookmark_get_uri (EvBookmark *self) +{ + g_return_val_if_fail (EV_IS_BOOKMARK (self), NULL); + + return self->priv->uri; +} + +void +ev_bookmark_set_uri (EvBookmark* self, const char *uri) +{ + g_assert (EV_IS_BOOKMARK (self)); + g_assert (uri != NULL); + + if (self->priv->uri != NULL) { + g_free (self->priv->uri); + } + + self->priv->uri = g_strdup (uri); + + g_object_notify (G_OBJECT (self), "uri"); +} + EvBookmarkType ev_bookmark_get_bookmark_type (EvBookmark *self) { @@ -134,6 +159,9 @@ ev_bookmark_get_property (GObject *object, guint prop_id, GValue *value, 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; @@ -160,6 +188,9 @@ ev_bookmark_set_property (GObject *object, guint prop_id, const GValue *value, case PROP_TITLE: ev_bookmark_set_title (self, g_value_get_string (value)); break; + case PROP_URI: + ev_bookmark_set_uri (self, g_value_get_string (value)); + break; case PROP_TYPE: ev_bookmark_set_bookmark_type (self, g_value_get_enum (value)); break; @@ -221,6 +252,14 @@ ev_bookmark_class_init (EvBookmarkClass *ev_window_class) NULL, G_PARAM_READWRITE)); + g_object_class_install_property (g_object_class, + PROP_URI, + g_param_spec_string ("uri", + "Bookmark URI", + "The bookmark URI", + NULL, + G_PARAM_READWRITE)); + g_object_class_install_property (g_object_class, PROP_TYPE, g_param_spec_enum ("type", @@ -242,13 +281,30 @@ ev_bookmark_class_init (EvBookmarkClass *ev_window_class) } EvBookmark * -ev_bookmark_new (const char *title, - EvBookmarkType type, - int page) +ev_bookmark_new_title (const char *title) +{ + return EV_BOOKMARK (g_object_new (EV_TYPE_BOOKMARK, + "title", title, + "type", EV_BOOKMARK_TYPE_TITLE, + NULL)); +} + +EvBookmark * +ev_bookmark_new_link (const char *title, int page) { return EV_BOOKMARK (g_object_new (EV_TYPE_BOOKMARK, "title", title, "page", page, - "type", type, + "type", EV_BOOKMARK_TYPE_LINK, + NULL)); +} + +EvBookmark * +ev_bookmark_new_external (const char *title, const char *uri) +{ + return EV_BOOKMARK (g_object_new (EV_TYPE_BOOKMARK, + "title", title, + "uri", uri, + "type", EV_BOOKMARK_TYPE_EXTERNAL_URI, NULL)); } diff --git a/backend/ev-bookmark.h b/backend/ev-bookmark.h index 6b688382..654ee94d 100644 --- a/backend/ev-bookmark.h +++ b/backend/ev-bookmark.h @@ -56,12 +56,17 @@ struct _EvBookmarkClass { GType ev_bookmark_type_get_type (void); GType ev_bookmark_get_type (void); -EvBookmark *ev_bookmark_new (const char *title, - EvBookmarkType type, +EvBookmark *ev_bookmark_new_title (const char *title); +EvBookmark *ev_bookmark_new_link (const char *title, int page); +EvBookmark *ev_bookmark_new_external (const char *title, + const char *uri); const char *ev_bookmark_get_title (EvBookmark *bookmark); void ev_bookmark_set_title (EvBookmark *bookmark, const char *title); +const char *ev_bookmark_get_uri (EvBookmark *bookmark); +void ev_bookmark_set_uri (EvBookmark *bookmark, + const char *uri); EvBookmarkType ev_bookmark_get_bookmark_type (EvBookmark *bookmark); void ev_bookmark_set_bookmark_type (EvBookmark *bookmark, EvBookmarkType type); diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc index feb009d0..6e077162 100644 --- a/pdf/xpdf/pdf-document.cc +++ b/pdf/xpdf/pdf-document.cc @@ -745,18 +745,12 @@ pdf_document_bookmarks_get_bookmark (EvDocumentBookmarks *document_bookmark EvDocumentBookmarksIter *bookmarks_iter) { PdfDocument *pdf_document = PDF_DOCUMENT (document_bookmarks); - EvBookmark *bookmark; + EvBookmark *bookmark = NULL; BookmarksIter *iter = (BookmarksIter *)bookmarks_iter; OutlineItem *anItem; LinkAction *link_action; - LinkDest *link_dest = NULL; - LinkURI *link_uri = NULL; - LinkGoTo *link_goto = NULL; - GString *named_dest; Unicode *link_title; - Ref page_ref; - gint page_num = 0; - char *title; + const char *title; g_return_val_if_fail (PDF_IS_DOCUMENT (document_bookmarks), FALSE); g_return_val_if_fail (iter != NULL, FALSE); @@ -764,55 +758,51 @@ pdf_document_bookmarks_get_bookmark (EvDocumentBookmarks *document_bookmark anItem = (OutlineItem *)iter->items->get(iter->index); link_action = anItem->getAction (); link_title = anItem->getTitle (); - - if (link_action) { - switch (link_action->getKind ()) { - - case actionGoTo: - link_goto = dynamic_cast (link_action); - link_dest = link_goto->getDest (); - named_dest = link_goto->getNamedDest (); - - /* Wow! This seems excessively slow on large - * documents. I need to investigate more... -jrb */ - if (link_dest != NULL) { - link_dest = link_dest->copy (); - } else if (named_dest != NULL) { - named_dest = named_dest->copy (); - link_dest = pdf_document->doc->findDest (named_dest); - delete named_dest; - } - if (link_dest != NULL) { - if (link_dest->isPageRef ()) { - page_ref = link_dest->getPageRef (); - page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen); - } else { - page_num = link_dest->getPageNum (); - } - - delete link_dest; + title = unicode_to_char (anItem, pdf_document->umap); + + if (link_action == NULL) { + bookmark = ev_bookmark_new_title (title); + } else if (link_action->getKind () == actionGoTo) { + LinkDest *link_dest; + LinkGoTo *link_goto; + Ref page_ref; + gint page_num = 0; + GString *named_dest; + + link_goto = dynamic_cast (link_action); + link_dest = link_goto->getDest (); + named_dest = link_goto->getNamedDest (); + + /* Wow! This seems excessively slow on large + * documents. I need to investigate more... -jrb */ + if (link_dest != NULL) { + link_dest = link_dest->copy (); + } else if (named_dest != NULL) { + named_dest = named_dest->copy (); + link_dest = pdf_document->doc->findDest (named_dest); + delete named_dest; + } + if (link_dest != NULL) { + if (link_dest->isPageRef ()) { + page_ref = link_dest->getPageRef (); + page_num = pdf_document->doc->findPage (page_ref.num, page_ref.gen); + } else { + page_num = link_dest->getPageNum (); } + delete link_dest; + } - break; - case actionURI: - link_uri = dynamic_cast (link_action); - break; + bookmark = ev_bookmark_new_link (title, page_num); + } else if (link_action->getKind () == actionURI) { + LinkURI *link_uri; - case actionNamed: + link_uri = dynamic_cast (link_action); + bookmark = ev_bookmark_new_external + (title, link_uri->getURI()->getCString()); + } else if (link_action->getKind () == actionNamed) { /*Skip, for now */ - default: - g_warning ("Unknown link action type: %d", link_action->getKind ()); - } - - title = g_strdup (unicode_to_char (anItem, pdf_document->umap)); - } else if (link_title) { - title = g_strdup (unicode_to_char (anItem, pdf_document->umap)); } - bookmark = ev_bookmark_new (title, EV_BOOKMARK_TYPE_LINK, page_num); - - g_free (title); - return bookmark; } diff --git a/shell/ev-application.c b/shell/ev-application.c index 4f006cc5..6fe50aaa 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -29,8 +29,9 @@ #include #include #include +#include -#include +#include "ev-window.h" struct _EvApplicationPrivate { GList *windows; @@ -168,6 +169,32 @@ ev_application_open (EvApplication *application, GError *err) gtk_widget_destroy (GTK_WIDGET (chooser)); } +void +ev_application_open_bookmark (EvApplication *application, + EvDocument *document, + EvBookmark *bookmark, + GError *error) +{ + EvBookmarkType type; + const char *uri; + int page; + + type = ev_bookmark_get_bookmark_type (bookmark); + + switch (type) { + case EV_BOOKMARK_TYPE_TITLE: + break; + case EV_BOOKMARK_TYPE_LINK: + page = ev_bookmark_get_page (bookmark); + ev_document_set_page (document, page); + break; + case EV_BOOKMARK_TYPE_EXTERNAL_URI: + uri = ev_bookmark_get_uri (bookmark); + gnome_vfs_url_show (uri); + break; + } +} + static void ev_application_class_init (EvApplicationClass *ev_application_class) { diff --git a/shell/ev-application.h b/shell/ev-application.h index b9f64c16..674d799f 100644 --- a/shell/ev-application.h +++ b/shell/ev-application.h @@ -27,6 +27,8 @@ #include #include "ev-window.h" +#include "ev-document.h" +#include "ev-bookmark.h" G_BEGIN_DECLS @@ -54,8 +56,13 @@ struct _EvApplicationClass { GType ev_application_get_type (void); EvApplication *ev_application_get_instance (void); -void ev_application_open (EvApplication *application, GError *err); +void ev_application_open (EvApplication *application, + GError *err); EvWindow *ev_application_new_window (EvApplication *application); +void ev_application_open_bookmark (EvApplication *application, + EvDocument *document, + EvBookmark *bookmark, + GError *err); G_END_DECLS diff --git a/shell/ev-sidebar-bookmarks.c b/shell/ev-sidebar-bookmarks.c index 29851b91..e54e4a5c 100644 --- a/shell/ev-sidebar-bookmarks.c +++ b/shell/ev-sidebar-bookmarks.c @@ -29,6 +29,7 @@ #include "ev-sidebar-bookmarks.h" #include "ev-document-bookmarks.h" +#include "ev-application.h" /* Amount of time we devote to each iteration of the idle, in microseconds */ #define IDLE_WORK_LENGTH 5000 @@ -104,8 +105,8 @@ selection_changed_cb (GtkTreeSelection *selection, if (gtk_tree_selection_get_selected (selection, &model, &iter)) { EvBookmark *bookmark; + EvApplication *app; GValue value = {0, }; - int page; gtk_tree_model_get_value (model, &iter, BOOKMARKS_COLUMN_BOOKMARK, &value); @@ -113,8 +114,8 @@ selection_changed_cb (GtkTreeSelection *selection, bookmark = EV_BOOKMARK (g_value_get_object (&value)); g_return_if_fail (bookmark != NULL); - page = ev_bookmark_get_page (bookmark); - ev_document_set_page (document, page); + app = ev_application_get_instance (); + ev_application_open_bookmark (app, document, bookmark, NULL); } } -- 2.43.5