]> www.fi.muni.cz Git - evince.git/blob - shell/ev-history.c
Don't delete history
[evince.git] / shell / ev-history.c
1 /*
2  *  Copyright (C) 2005 Marco Pesenti Gritti
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2, or (at your option)
7  *  any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19
20 #include "config.h"
21
22 #include <glib/gi18n.h>
23
24 #include "ev-history.h"
25
26 struct _EvHistoryPrivate
27 {
28         GList *links;
29         int current_index;
30 };
31
32 enum {
33         PROP_0,
34         PROP_INDEX
35 };
36
37 static void ev_history_init       (EvHistory *history);
38 static void ev_history_class_init (EvHistoryClass *class);
39
40 G_DEFINE_TYPE (EvHistory, ev_history, G_TYPE_OBJECT)
41
42 #define EV_HISTORY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_HISTORY, EvHistoryPrivate))
43
44 static void
45 ev_history_init (EvHistory *history)
46 {
47         history->priv = EV_HISTORY_GET_PRIVATE (history);
48
49         history->priv->links = NULL;
50         history->priv->current_index = -1;
51 }
52
53 static void
54 free_links_list (GList *l)
55 {
56         g_list_foreach (l, (GFunc)g_object_unref, NULL);
57         g_list_free (l);
58 }
59
60 static void
61 ev_history_finalize (GObject *object)
62 {
63         EvHistory *history = EV_HISTORY (object);
64
65         free_links_list (history->priv->links);
66
67         G_OBJECT_CLASS (ev_history_parent_class)->finalize (object);
68 }
69
70 static void
71 ev_history_get_property (GObject *object, guint prop_id, GValue *value,
72                          GParamSpec *param_spec)
73 {
74         EvHistory *self;
75
76         self = EV_HISTORY (object);
77
78         switch (prop_id) {
79         case PROP_INDEX:
80                 g_value_set_int (value, self->priv->current_index);
81                 break;
82         default:
83                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
84                                                    prop_id,
85                                                    param_spec);
86                 break;
87         }
88 }
89
90 static void
91 ev_history_set_property (GObject *object, guint prop_id, const GValue *value,
92                          GParamSpec *param_spec)
93 {
94         EvHistory *self;
95         
96         self = EV_HISTORY (object);
97         
98         switch (prop_id) {
99         case PROP_INDEX:
100                 ev_history_set_current_index (self, g_value_get_int (value));
101                 break;
102         default:
103                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
104                                                    prop_id,
105                                                    param_spec);
106                 break;
107         }
108 }
109
110 static void
111 ev_history_class_init (EvHistoryClass *class)
112 {
113         GObjectClass *object_class = G_OBJECT_CLASS (class);
114
115         object_class->finalize = ev_history_finalize;
116         object_class->set_property = ev_history_set_property;
117         object_class->get_property = ev_history_get_property;
118
119         g_object_class_install_property (object_class,
120                                          PROP_INDEX,
121                                          g_param_spec_int ("index",
122                                                            "Current Index",
123                                                            "The current index",
124                                                             -1,
125                                                             G_MAXINT,
126                                                             0,
127                                                             G_PARAM_READWRITE));
128
129         g_type_class_add_private (object_class, sizeof (EvHistoryPrivate));
130 }
131
132 void
133 ev_history_add_link (EvHistory *history, EvLink *link)
134 {
135         int length;
136
137         g_return_if_fail (EV_IS_HISTORY (history));
138         g_return_if_fail (EV_IS_LINK (link));
139
140
141         g_object_ref (link);
142         history->priv->links = g_list_append (history->priv->links,
143                                               link);
144
145         length = g_list_length (history->priv->links);
146         history->priv->current_index = length - 1;
147 }
148
149 void
150 ev_history_add_page (EvHistory *history, int page, const gchar *label)
151 {
152         EvLink *link;
153         EvLinkDest *dest;
154         EvLinkAction *action;
155         gchar *title;
156
157         g_return_if_fail (EV_IS_HISTORY (history));
158         
159         title = g_strdup_printf (_("Page: %s"), label);
160
161         dest = ev_link_dest_new_page (page);
162         action = ev_link_action_new_dest (dest);
163         link = ev_link_new (title, action);
164         g_free (title);
165
166         ev_history_add_link (history, link);
167 }
168
169 EvLink *
170 ev_history_get_link_nth (EvHistory *history, int index)
171 {
172         GList *l;
173
174         g_return_val_if_fail (EV_IS_HISTORY (history), NULL);
175
176         l = g_list_nth (history->priv->links, index);
177
178         return EV_LINK (l->data);
179 }
180
181 int
182 ev_history_get_n_links (EvHistory *history)
183 {
184         g_return_val_if_fail (EV_IS_HISTORY (history), -1);
185
186         return g_list_length (history->priv->links);
187 }
188
189 int
190 ev_history_get_current_index (EvHistory *history)
191 {
192         g_return_val_if_fail (EV_IS_HISTORY (history), -1);
193
194         return history->priv->current_index;
195 }
196
197 void
198 ev_history_set_current_index (EvHistory *history, int index)
199 {
200         g_return_if_fail (EV_IS_HISTORY (history));
201
202         history->priv->current_index = index;
203
204         g_object_notify (G_OBJECT (history), "index");
205 }
206
207 EvHistory *
208 ev_history_new (void)
209 {
210         return EV_HISTORY (g_object_new (EV_TYPE_HISTORY, NULL));
211 }