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.
23 #include <glib/gi18n.h>
25 #include "ev-history.h"
27 struct _EvHistoryPrivate
33 static void ev_history_init (EvHistory *history);
34 static void ev_history_class_init (EvHistoryClass *class);
36 static GObjectClass *parent_class = NULL;
38 G_DEFINE_TYPE (EvHistory, ev_history, G_TYPE_OBJECT)
40 #define EV_HISTORY_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_HISTORY, EvHistoryPrivate))
43 ev_history_init (EvHistory *history)
45 history->priv = EV_HISTORY_GET_PRIVATE (history);
47 history->priv->links = NULL;
51 free_links_list (GList *l)
53 g_list_foreach (l, (GFunc)g_object_unref, NULL);
58 ev_history_finalize (GObject *object)
60 EvHistory *history = EV_HISTORY (object);
62 free_links_list (history->priv->links);
64 parent_class->finalize (object);
68 ev_history_class_init (EvHistoryClass *class)
70 GObjectClass *object_class = G_OBJECT_CLASS (class);
72 object_class->finalize = ev_history_finalize;
74 parent_class = g_type_class_peek_parent (class);
76 g_type_class_add_private (object_class, sizeof (EvHistoryPrivate));
80 ev_history_add_link (EvHistory *history, EvLink *link)
84 g_return_if_fail (EV_IS_HISTORY (history));
85 g_return_if_fail (EV_IS_LINK (link));
88 history->priv->links = g_list_append (history->priv->links,
91 length = g_list_length (history->priv->links);
92 history->priv->current_index = length - 1;
94 g_print ("Set current\n");
98 ev_history_add_page (EvHistory *history, int page)
103 g_return_if_fail (EV_IS_HISTORY (history));
105 title = g_strdup_printf (_("Page %d\n"), page);
106 link = ev_link_new_page (title, page);
109 ev_history_add_link (history, link);
113 ev_history_get_link_nth (EvHistory *history, int index)
117 g_return_val_if_fail (EV_IS_HISTORY (history), NULL);
119 l = g_list_nth (history->priv->links, index);
121 return EV_LINK (l->data);
125 ev_history_get_n_links (EvHistory *history)
127 g_return_val_if_fail (EV_IS_HISTORY (history), -1);
129 return g_list_length (history->priv->links);
133 ev_history_get_current_index (EvHistory *history)
135 g_return_val_if_fail (EV_IS_HISTORY (history), -1);
137 return history->priv->current_index;
141 ev_history_set_current_index (EvHistory *history, int index)
143 g_return_if_fail (EV_IS_HISTORY (history));
145 history->priv->current_index = index;
149 ev_history_new (void)
151 return EV_HISTORY (g_object_new (EV_TYPE_HISTORY, NULL));