Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2005-01-07 12:16:43 (GMT)
committer Marco Pesenti Gritti <marco@src.gnome.org>2005-01-07 12:16:43 (GMT)
commit8b3ebe4d7024547993d3b4660f3f22036e327be3 (patch)
tree0862e57165cef77db894dd5123ec4b81ed42738f /backend
parent3a87fe3d6bd17d8151c675c9b4e9294619127b1b (diff)
Add a bookmark object to the backend and use it instead of get_values
2005-01-07 Marco Pesenti Gritti <marco@gnome.org> * backend/Makefile.am: * backend/ev-bookmark.c: (ev_bookmark_type_get_type), (ev_bookmark_get_title), (ev_bookmark_set_title), (ev_bookmark_get_bookmark_type), (ev_bookmark_set_bookmark_type), (ev_bookmark_get_page), (ev_bookmark_set_page), (ev_bookmark_get_property), (ev_bookmark_set_property), (ev_window_dispose), (ev_bookmark_init), (ev_bookmark_class_init), (ev_bookmark_new): * backend/ev-bookmark.h: * backend/ev-document-bookmarks.c: (ev_document_bookmarks_get_bookmark): * backend/ev-document-bookmarks.h: * pdf/xpdf/pdf-document.cc: * shell/ev-sidebar-bookmarks.c: (do_one_iteration): Add a bookmark object to the backend and use it instead of get_values
Diffstat (limited to 'backend')
-rw-r--r--backend/Makefile.am2
-rw-r--r--backend/ev-bookmark.c254
-rw-r--r--backend/ev-bookmark.h74
-rw-r--r--backend/ev-document-bookmarks.c15
-rw-r--r--backend/ev-document-bookmarks.h23
5 files changed, 340 insertions, 28 deletions
diff --git a/backend/Makefile.am b/backend/Makefile.am
index e2c3245..03a9103 100644
--- a/backend/Makefile.am
+++ b/backend/Makefile.am
@@ -11,6 +11,8 @@ noinst_LTLIBRARIES = libevbackend.la
libevbackend_la_SOURCES= \
ev-backend-marshal.c \
+ ev-bookmark.c \
+ ev-bookmark.h \
ev-document.c \
ev-document.h \
ev-document-thumbnails.c \
diff --git a/backend/ev-bookmark.c b/backend/ev-bookmark.c
new file mode 100644
index 0000000..f28c32b
--- /dev/null
+++ b/backend/ev-bookmark.c
@@ -0,0 +1,254 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/* this file is part of evince, a gnome document viewer
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ev-bookmark.h"
+
+enum {
+ PROP_0,
+ PROP_TITLE,
+ PROP_TYPE,
+ PROP_PAGE
+};
+
+struct _EvBookmarkPrivate {
+ char *title;
+ EvBookmarkType type;
+ int page;
+};
+
+static GObjectClass *parent_class = NULL;
+
+G_DEFINE_TYPE (EvBookmark, ev_bookmark, G_TYPE_OBJECT)
+
+#define EV_BOOKMARK_GET_PRIVATE(object) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_BOOKMARK, EvBookmarkPrivate))
+
+GType
+ev_bookmark_type_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static const GEnumValue values[] = {
+ { EV_BOOKMARK_TYPE_TITLE, "EV_BOOKMARK_TYPE_TITLE", "title" },
+ { EV_BOOKMARK_TYPE_LINK, "EV_BOOKMARK_TYPE_LINK", "link" },
+ { EV_BOOKMARK_TYPE_EXTERNAL_URI, "EV_BOOKMARK_TYPE_EXTERNAL_URI", "external" },
+ { 0, NULL, NULL }
+ };
+
+ type = g_enum_register_static ("EvBookmarkType", values);
+ }
+
+ return type;
+}
+
+const char *
+ev_bookmark_get_title (EvBookmark *self)
+{
+ g_return_val_if_fail (EV_IS_BOOKMARK (self), NULL);
+
+ return self->priv->title;
+}
+
+void
+ev_bookmark_set_title (EvBookmark* self, const char *title)
+{
+ g_assert (EV_IS_BOOKMARK (self));
+ g_assert (title != NULL);
+
+ if (self->priv->title != NULL) {
+ g_free (self->priv->title);
+ }
+
+ self->priv->title = g_strdup (title);
+
+ g_object_notify (G_OBJECT (self), "title");
+}
+
+EvBookmarkType
+ev_bookmark_get_bookmark_type (EvBookmark *self)
+{
+ g_return_val_if_fail (EV_IS_BOOKMARK (self), 0);
+
+ return self->priv->type;
+}
+
+void
+ev_bookmark_set_bookmark_type (EvBookmark* self, EvBookmarkType type)
+{
+ g_assert (EV_IS_BOOKMARK (self));
+
+ self->priv->type = type;
+
+ g_object_notify (G_OBJECT (self), "type");
+}
+
+int
+ev_bookmark_get_page (EvBookmark *self)
+{
+ g_return_val_if_fail (EV_IS_BOOKMARK (self), 0);
+
+ return self->priv->page;
+}
+
+void
+ev_bookmark_set_page (EvBookmark* self, int page)
+{
+ g_assert (EV_IS_BOOKMARK (self));
+
+ self->priv->page = page;
+
+ g_object_notify (G_OBJECT (self), "page");
+}
+
+static void
+ev_bookmark_get_property (GObject *object, guint prop_id, GValue *value,
+ GParamSpec *param_spec)
+{
+ EvBookmark *self;
+
+ self = EV_BOOKMARK (object);
+
+ switch (prop_id) {
+ case PROP_TITLE:
+ g_value_set_string (value, self->priv->title);
+ 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;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
+ prop_id,
+ param_spec);
+ break;
+ }
+}
+
+static void
+ev_bookmark_set_property (GObject *object, guint prop_id, const GValue *value,
+ GParamSpec *param_spec)
+{
+ EvBookmark *self;
+
+ self = EV_BOOKMARK (object);
+
+ switch (prop_id) {
+ case PROP_TITLE:
+ ev_bookmark_set_title (self, g_value_get_string (value));
+ break;
+ case PROP_TYPE:
+ ev_bookmark_set_bookmark_type (self, g_value_get_enum (value));
+ break;
+ case PROP_PAGE:
+ ev_bookmark_set_page (self, g_value_get_int (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
+ prop_id,
+ param_spec);
+ break;
+ }
+}
+
+static void
+ev_window_dispose (GObject *object)
+{
+ EvBookmarkPrivate *priv;
+
+ g_return_if_fail (EV_IS_BOOKMARK (object));
+
+ priv = EV_BOOKMARK (object)->priv;
+
+ if (priv->title) {
+ g_free (priv->title);
+ priv->title = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+ev_bookmark_init (EvBookmark *ev_bookmark)
+{
+ ev_bookmark->priv = EV_BOOKMARK_GET_PRIVATE (ev_bookmark);
+
+ ev_bookmark->priv->type = EV_BOOKMARK_TYPE_TITLE;
+}
+
+static void
+ev_bookmark_class_init (EvBookmarkClass *ev_window_class)
+{
+ GObjectClass *g_object_class;
+
+ parent_class = g_type_class_peek_parent (ev_window_class);
+
+ g_object_class = G_OBJECT_CLASS (ev_window_class);
+ g_object_class->dispose = ev_window_dispose;
+ g_object_class->set_property = ev_bookmark_set_property;
+ g_object_class->get_property = ev_bookmark_get_property;
+
+ g_type_class_add_private (g_object_class, sizeof (EvBookmarkPrivate));
+
+ g_object_class_install_property (g_object_class,
+ PROP_TITLE,
+ g_param_spec_string ("title",
+ "Bookmark Title",
+ "The bookmark title",
+ NULL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (g_object_class,
+ PROP_TYPE,
+ g_param_spec_enum ("type",
+ "Bookmark Type",
+ "The bookmark type",
+ EV_TYPE_BOOKMARK_TYPE,
+ EV_BOOKMARK_TYPE_TITLE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (g_object_class,
+ PROP_PAGE,
+ g_param_spec_int ("page",
+ "Bookmark Page",
+ "The bookmark page",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE));
+}
+
+EvBookmark *
+ev_bookmark_new (const char *title,
+ EvBookmarkType type,
+ int page)
+{
+ return EV_BOOKMARK (g_object_new (EV_TYPE_BOOKMARK,
+ "title", title,
+ "page", page,
+ "type", type,
+ NULL));
+}
diff --git a/backend/ev-bookmark.h b/backend/ev-bookmark.h
new file mode 100644
index 0000000..6b68838
--- /dev/null
+++ b/backend/ev-bookmark.h
@@ -0,0 +1,74 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ * 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_BOOKMARK_H
+#define EV_BOOKMARK_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EvBookmark EvBookmark;
+typedef struct _EvBookmarkClass EvBookmarkClass;
+typedef struct _EvBookmarkPrivate EvBookmarkPrivate;
+
+#define EV_TYPE_BOOKMARK (ev_bookmark_get_type())
+#define EV_BOOKMARK(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_BOOKMARK, EvBookmark))
+#define EV_BOOKMARK_CLASS(klass) (G_TYPE_CHACK_CLASS_CAST((klass), EV_TYPE_BOOKMARK, EvBookmarkClass))
+#define EV_IS_BOOKMARK(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_BOOKMARK))
+#define EV_IS_BOOKMARK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_BOOKMARK))
+#define EV_BOOKMARK_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_BOOKMARK, EvBookmarkClass))
+
+#define EV_TYPE_BOOKMARK_TYPE (ev_bookmark_type_get_type ())
+
+typedef enum
+{
+ EV_BOOKMARK_TYPE_TITLE,
+ EV_BOOKMARK_TYPE_LINK,
+ EV_BOOKMARK_TYPE_EXTERNAL_URI
+} EvBookmarkType;
+
+struct _EvBookmark {
+ GObject base_instance;
+ EvBookmarkPrivate *priv;
+};
+
+struct _EvBookmarkClass {
+ GObjectClass base_class;
+};
+
+GType ev_bookmark_type_get_type (void);
+GType ev_bookmark_get_type (void);
+
+EvBookmark *ev_bookmark_new (const char *title,
+ EvBookmarkType type,
+ int page);
+const char *ev_bookmark_get_title (EvBookmark *bookmark);
+void ev_bookmark_set_title (EvBookmark *bookmark,
+ const char *title);
+EvBookmarkType ev_bookmark_get_bookmark_type (EvBookmark *bookmark);
+void ev_bookmark_set_bookmark_type (EvBookmark *bookmark,
+ EvBookmarkType type);
+int ev_bookmark_get_page (EvBookmark *bookmark);
+void ev_bookmark_set_page (EvBookmark *bookmark,
+ int page);
+
+G_END_DECLS
+
+#endif /* !EV_BOOKMARK_H */
diff --git a/backend/ev-document-bookmarks.c b/backend/ev-document-bookmarks.c
index 1806cd9..7b0d141 100644
--- a/backend/ev-document-bookmarks.c
+++ b/backend/ev-document-bookmarks.c
@@ -62,20 +62,13 @@ ev_document_bookmarks_begin_read (EvDocumentBookmarks *document_bookmarks)
return iface->begin_read (document_bookmarks);
}
- /*
- * This function gets the values at a node. You need to g_free the title.
- * Additionally, if page is -1, the link doesn't go anywhere.
- */
-gboolean
-ev_document_bookmarks_get_values (EvDocumentBookmarks *document_bookmarks,
- EvDocumentBookmarksIter *iter,
- char **title,
- EvDocumentBookmarksType *type,
- gint *page)
+EvBookmark *
+ev_document_bookmarks_get_bookmark (EvDocumentBookmarks *document_bookmarks,
+ EvDocumentBookmarksIter *iter)
{
EvDocumentBookmarksIface *iface = EV_DOCUMENT_BOOKMARKS_GET_IFACE (document_bookmarks);
- return iface->get_values (document_bookmarks, iter, title, type, page);
+ return iface->get_bookmark (document_bookmarks, iter);
}
EvDocumentBookmarksIter *
diff --git a/backend/ev-document-bookmarks.h b/backend/ev-document-bookmarks.h
index 98a53a6..6ee36a7 100644
--- a/backend/ev-document-bookmarks.h
+++ b/backend/ev-document-bookmarks.h
@@ -32,7 +32,9 @@
#include <glib-object.h>
#include <glib.h>
#include <gdk/gdk.h>
+
#include "ev-document.h"
+#include "ev-bookmark.h"
G_BEGIN_DECLS
@@ -48,13 +50,6 @@ typedef struct _EvDocumentBookmarks EvDocumentBookmarks;
typedef struct _EvDocumentBookmarksIface EvDocumentBookmarksIface;
typedef struct _EvDocumentBookmarksIter EvDocumentBookmarksIter;
-typedef enum
-{
- EV_DOCUMENT_BOOKMARKS_TYPE_TITLE,
- EV_DOCUMENT_BOOKMARKS_TYPE_LINK,
- EV_DOCUMENT_BOOKMARKS_TYPE_EXTERNAL_URI,
-} EvDocumentBookmarksType;
-
struct _EvDocumentBookmarksIface
{
GTypeInterface base_iface;
@@ -62,11 +57,8 @@ struct _EvDocumentBookmarksIface
/* Methods */
gboolean (* has_document_bookmarks) (EvDocumentBookmarks *document_bookmarks);
EvDocumentBookmarksIter *(* begin_read) (EvDocumentBookmarks *document_bookmarks);
- gboolean (* get_values) (EvDocumentBookmarks *document_bookmarks,
- EvDocumentBookmarksIter *iter,
- gchar **title,
- EvDocumentBookmarksType *type,
- gint *page);
+ EvBookmark *(* get_bookmark) (EvDocumentBookmarks *document_bookmarks,
+ EvDocumentBookmarksIter *iter);
EvDocumentBookmarksIter *(* get_child) (EvDocumentBookmarks *document_bookmarks,
EvDocumentBookmarksIter *iter);
gboolean (* next) (EvDocumentBookmarks *document_bookmarks,
@@ -78,11 +70,8 @@ struct _EvDocumentBookmarksIface
GType ev_document_bookmarks_get_type (void);
gboolean ev_document_bookmarks_has_document_bookmarks (EvDocumentBookmarks *document_bookmarks);
EvDocumentBookmarksIter *ev_document_bookmarks_begin_read (EvDocumentBookmarks *document_bookmarks);
-gboolean ev_document_bookmarks_get_values (EvDocumentBookmarks *document_bookmarks,
- EvDocumentBookmarksIter *iter,
- char **title,
- EvDocumentBookmarksType *type,
- gint *page);
+EvBookmark *ev_document_bookmarks_get_bookmark (EvDocumentBookmarks *document_bookmarks,
+ EvDocumentBookmarksIter *iter);
EvDocumentBookmarksIter *ev_document_bookmarks_get_child (EvDocumentBookmarks *document_bookmarks,
EvDocumentBookmarksIter *iter);
gboolean ev_document_bookmarks_next (EvDocumentBookmarks *document_bookmarks,