+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),
PROP_0,
PROP_TITLE,
PROP_TYPE,
- PROP_PAGE
+ PROP_PAGE,
+ PROP_URI
};
struct _EvBookmarkPrivate {
char *title;
+ char *uri;
EvBookmarkType type;
int page;
};
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)
{
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_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;
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",
}
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));
}
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);
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);
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;
}
#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;
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)
{
#include <glib-object.h>
#include "ev-window.h"
+#include "ev-document.h"
+#include "ev-bookmark.h"
G_BEGIN_DECLS
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
#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
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);
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);
}
}