]> www.fi.muni.cz Git - evince.git/blob - backend/ev-bookmark.c
Hook up bookmarks navigation
[evince.git] / backend / ev-bookmark.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  *  Copyright (C) 2005 Red Hat, Inc.
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "ev-bookmark.h"
26
27 enum {
28         PROP_0,
29         PROP_TITLE,
30         PROP_TYPE,
31         PROP_PAGE
32 };
33
34 struct _EvBookmarkPrivate {
35         char *title;
36         EvBookmarkType type;
37         int page;
38 };
39
40 static GObjectClass *parent_class = NULL;
41
42 G_DEFINE_TYPE (EvBookmark, ev_bookmark, G_TYPE_OBJECT)
43
44 #define EV_BOOKMARK_GET_PRIVATE(object) \
45         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_BOOKMARK, EvBookmarkPrivate))
46
47 GType
48 ev_bookmark_type_get_type (void)
49 {
50         static GType type = 0;
51
52         if (G_UNLIKELY (type == 0)) {
53                 static const GEnumValue values[] = {
54                         { EV_BOOKMARK_TYPE_TITLE, "EV_BOOKMARK_TYPE_TITLE", "title" },
55                         { EV_BOOKMARK_TYPE_LINK, "EV_BOOKMARK_TYPE_LINK", "link" },
56                         { EV_BOOKMARK_TYPE_EXTERNAL_URI, "EV_BOOKMARK_TYPE_EXTERNAL_URI", "external" },
57                         { 0, NULL, NULL }
58                 };
59
60                 type = g_enum_register_static ("EvBookmarkType", values);
61         }
62
63         return type;
64 }
65
66 const char *
67 ev_bookmark_get_title (EvBookmark *self)
68 {
69         g_return_val_if_fail (EV_IS_BOOKMARK (self), NULL);
70         
71         return self->priv->title;
72 }
73
74 void
75 ev_bookmark_set_title (EvBookmark* self, const char *title)
76 {
77         g_assert (EV_IS_BOOKMARK (self));
78         g_assert (title != NULL);
79
80         if (self->priv->title != NULL) {
81                 g_free (self->priv->title);
82         }
83
84         self->priv->title = g_strdup (title);
85
86         g_object_notify (G_OBJECT (self), "title");
87 }
88
89 EvBookmarkType
90 ev_bookmark_get_bookmark_type (EvBookmark *self)
91 {
92         g_return_val_if_fail (EV_IS_BOOKMARK (self), 0);
93         
94         return self->priv->type;
95 }
96
97 void
98 ev_bookmark_set_bookmark_type (EvBookmark* self, EvBookmarkType type)
99 {
100         g_assert (EV_IS_BOOKMARK (self));
101
102         self->priv->type = type;
103
104         g_object_notify (G_OBJECT (self), "type");
105 }
106
107 int
108 ev_bookmark_get_page (EvBookmark *self)
109 {
110         g_return_val_if_fail (EV_IS_BOOKMARK (self), 0);
111         
112         return self->priv->page;
113 }
114
115 void
116 ev_bookmark_set_page (EvBookmark* self, int page)
117 {
118         g_assert (EV_IS_BOOKMARK (self));
119
120         self->priv->page = page;
121
122         g_object_notify (G_OBJECT (self), "page");
123 }
124
125 static void
126 ev_bookmark_get_property (GObject *object, guint prop_id, GValue *value,
127                           GParamSpec *param_spec)
128 {
129         EvBookmark *self;
130
131         self = EV_BOOKMARK (object);
132
133         switch (prop_id) {
134         case PROP_TITLE:
135                 g_value_set_string (value, self->priv->title);
136                 break;
137         case PROP_TYPE:
138                 g_value_set_enum (value, self->priv->type);
139                 break;
140         case PROP_PAGE:
141                 g_value_set_int (value, self->priv->page);
142                 break;
143         default:
144                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
145                                                    prop_id,
146                                                    param_spec);
147                 break;
148         }
149 }
150
151 static void
152 ev_bookmark_set_property (GObject *object, guint prop_id, const GValue *value,
153                           GParamSpec *param_spec)
154 {
155         EvBookmark *self;
156         
157         self = EV_BOOKMARK (object);
158         
159         switch (prop_id) {
160         case PROP_TITLE:
161                 ev_bookmark_set_title (self, g_value_get_string (value));
162                 break;
163         case PROP_TYPE:
164                 ev_bookmark_set_bookmark_type (self, g_value_get_enum (value));
165                 break;
166         case PROP_PAGE:
167                 ev_bookmark_set_page (self, g_value_get_int (value));
168                 break;
169         default:
170                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
171                                                    prop_id,
172                                                    param_spec);
173                 break;
174         }
175 }
176
177 static void
178 ev_window_dispose (GObject *object)
179 {
180         EvBookmarkPrivate *priv;
181
182         g_return_if_fail (EV_IS_BOOKMARK (object));
183
184         priv = EV_BOOKMARK (object)->priv;
185
186         if (priv->title) {
187                 g_free (priv->title);
188                 priv->title = NULL;
189         }
190
191         G_OBJECT_CLASS (parent_class)->dispose (object);
192 }
193
194 static void
195 ev_bookmark_init (EvBookmark *ev_bookmark)
196 {
197         ev_bookmark->priv = EV_BOOKMARK_GET_PRIVATE (ev_bookmark);
198
199         ev_bookmark->priv->type = EV_BOOKMARK_TYPE_TITLE;
200 }
201
202 static void
203 ev_bookmark_class_init (EvBookmarkClass *ev_window_class)
204 {
205         GObjectClass *g_object_class;
206
207         parent_class = g_type_class_peek_parent (ev_window_class);
208
209         g_object_class = G_OBJECT_CLASS (ev_window_class);
210         g_object_class->dispose = ev_window_dispose;
211         g_object_class->set_property = ev_bookmark_set_property;
212         g_object_class->get_property = ev_bookmark_get_property;
213
214         g_type_class_add_private (g_object_class, sizeof (EvBookmarkPrivate));
215
216         g_object_class_install_property (g_object_class,
217                                          PROP_TITLE,
218                                          g_param_spec_string ("title",
219                                                               "Bookmark Title",
220                                                               "The bookmark title",
221                                                               NULL,
222                                                               G_PARAM_READWRITE));
223
224         g_object_class_install_property (g_object_class,
225                                          PROP_TYPE,
226                                          g_param_spec_enum  ("type",
227                                                              "Bookmark Type",
228                                                              "The bookmark type",
229                                                              EV_TYPE_BOOKMARK_TYPE,
230                                                              EV_BOOKMARK_TYPE_TITLE,
231                                                              G_PARAM_READWRITE));
232
233         g_object_class_install_property (g_object_class,
234                                          PROP_PAGE,
235                                          g_param_spec_int ("page",
236                                                            "Bookmark Page",
237                                                            "The bookmark page",
238                                                             0,
239                                                             G_MAXINT,
240                                                             0,
241                                                             G_PARAM_READWRITE));
242 }
243
244 EvBookmark *
245 ev_bookmark_new (const char     *title,
246                  EvBookmarkType  type,
247                  int             page)
248 {
249         return EV_BOOKMARK (g_object_new (EV_TYPE_BOOKMARK,
250                                           "title", title,
251                                           "page", page,
252                                           "type", type,
253                                           NULL));
254 }