2 * Copyright (C) 2005 Marco Pesenti Gritti
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)
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.
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.
22 #include <glib/gi18n.h>
24 #include "ev-history.h"
26 struct _EvHistoryPrivate
37 static void ev_history_init (EvHistory *history);
38 static void ev_history_class_init (EvHistoryClass *class);
40 G_DEFINE_TYPE (EvHistory, ev_history, G_TYPE_OBJECT)
42 #define EV_HISTORY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_HISTORY, EvHistoryPrivate))
45 ev_history_init (EvHistory *history)
47 history->priv = EV_HISTORY_GET_PRIVATE (history);
49 history->priv->links = NULL;
50 history->priv->current_index = -1;
54 free_links_list (GList *l)
56 g_list_foreach (l, (GFunc)g_object_unref, NULL);
61 ev_history_finalize (GObject *object)
63 EvHistory *history = EV_HISTORY (object);
65 free_links_list (history->priv->links);
67 G_OBJECT_CLASS (ev_history_parent_class)->finalize (object);
71 ev_history_get_property (GObject *object, guint prop_id, GValue *value,
72 GParamSpec *param_spec)
76 self = EV_HISTORY (object);
80 g_value_set_int (value, self->priv->current_index);
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
91 ev_history_set_property (GObject *object, guint prop_id, const GValue *value,
92 GParamSpec *param_spec)
96 self = EV_HISTORY (object);
100 ev_history_set_current_index (self, g_value_get_int (value));
103 G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
111 ev_history_class_init (EvHistoryClass *class)
113 GObjectClass *object_class = G_OBJECT_CLASS (class);
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;
119 g_object_class_install_property (object_class,
121 g_param_spec_int ("index",
129 g_type_class_add_private (object_class, sizeof (EvHistoryPrivate));
133 ev_history_add_link (EvHistory *history, EvLink *link)
137 g_return_if_fail (EV_IS_HISTORY (history));
138 g_return_if_fail (EV_IS_LINK (link));
140 length = g_list_length (history->priv->links);
141 if (history->priv->current_index < length - 1) {
142 GList *l = g_list_nth (history->priv->links,
143 history->priv->current_index + 1);
146 l->prev->next = NULL;
149 free_links_list (history->priv->links);
150 history->priv->links = NULL;
155 history->priv->links = g_list_append (history->priv->links,
158 length = g_list_length (history->priv->links);
159 history->priv->current_index = length - 1;
163 ev_history_add_page (EvHistory *history, int page, const gchar *label)
167 EvLinkAction *action;
170 g_return_if_fail (EV_IS_HISTORY (history));
172 title = g_strdup_printf (_("Page: %s"), label);
174 dest = ev_link_dest_new_page (page);
175 action = ev_link_action_new_dest (dest);
176 link = ev_link_new (title, action);
179 ev_history_add_link (history, link);
183 ev_history_get_link_nth (EvHistory *history, int index)
187 g_return_val_if_fail (EV_IS_HISTORY (history), NULL);
189 l = g_list_nth (history->priv->links, index);
191 return EV_LINK (l->data);
195 ev_history_get_n_links (EvHistory *history)
197 g_return_val_if_fail (EV_IS_HISTORY (history), -1);
199 return g_list_length (history->priv->links);
203 ev_history_get_current_index (EvHistory *history)
205 g_return_val_if_fail (EV_IS_HISTORY (history), -1);
207 return history->priv->current_index;
211 ev_history_set_current_index (EvHistory *history, int index)
213 g_return_if_fail (EV_IS_HISTORY (history));
215 history->priv->current_index = index;
217 g_object_notify (G_OBJECT (history), "index");
221 ev_history_new (void)
223 return EV_HISTORY (g_object_new (EV_TYPE_HISTORY, NULL));