]> www.fi.muni.cz Git - evince.git/commitdiff
Add a way to open bookmarks
authorMarco Pesenti Gritti <marco@gnome.org>
Fri, 7 Jan 2005 13:35:18 +0000 (13:35 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Fri, 7 Jan 2005 13:35:18 +0000 (13:35 +0000)
2005-01-07  Marco Pesenti Gritti  <marco@gnome.org>

        * 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
backend/ev-bookmark.c
backend/ev-bookmark.h
pdf/xpdf/pdf-document.cc
shell/ev-application.c
shell/ev-application.h
shell/ev-sidebar-bookmarks.c

index 9491e85ab7c0724b31a4c425c720c4297449230c..ca0222cca8fead5e76f2acd4fdb40361e95d6822 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2005-01-07  Marco Pesenti Gritti  <marco@gnome.org>
+
+       * 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  <marco@gnome.org>
 
        * shell/ev-sidebar-bookmarks.c: (selection_changed_cb),
index f28c32bfa3f79fa75df2ffe3fb63fedaf72f8c41..f2d9f235fa005523f711e967ee9025605f1a31c6 100644 (file)
@@ -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));
 }
index 6b6883824c80f9cd42f3ff46ccbf17dd8a94c6ee..654ee94df9f8d99ab202127c6f6fa891556f1635 100644 (file)
@@ -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);
index feb009d017a7ee263dd46b23bc48f12088deabea..6e077162c59e138e45eefe1246006e94255171bd 100644 (file)
@@ -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 <LinkGoTo *> (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 <LinkGoTo *> (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 <LinkURI *> (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 <LinkURI *> (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;
 }
 
index 4f006cc5f1732bf86bfc575e0659bd016af9eca6..6fe50aaa67a92b8250027200254f4d0ee0c54b05 100644 (file)
@@ -29,8 +29,9 @@
 #include <gtk/gtkstock.h>
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkmain.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
 
-#include <ev-window.h>
+#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)
 {
index b9f64c16f3ffca55e3d5cf398c1b276f525bacc5..674d799f973079095f3ff29a138268902e21f7ea 100644 (file)
@@ -27,6 +27,8 @@
 #include <glib-object.h>
 
 #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
 
index 29851b91f579ade4411043f02abda9bf4645fac8..e54e4a5c0192087b15605ffaab117e1ed7b2b581 100644 (file)
@@ -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);
        }
 }