Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-history.c File Reference
#include "config.h"
#include <glib/gi18n.h>
#include <string.h>
#include "ev-history.h"
+ Include dependency graph for ev-history.c:

Go to the source code of this file.

Data Structures

struct  _EvHistoryPrivate
 

Macros

#define EV_HISTORY_MAX_LENGTH   (32)
 

Enumerations

enum  { CHANGED, ACTIVATE_LINK, N_SIGNALS }
 

Functions

static void ev_history_set_model (EvHistory *history, EvDocumentModel *model)
 
static void clear_list (GList *list)
 
static void ev_history_clear (EvHistory *history)
 
static void ev_history_prune (EvHistory *history)
 
static void ev_history_finalize (GObject *object)
 
static void ev_history_class_init (EvHistoryClass *class)
 
static void ev_history_init (EvHistory *history)
 
gboolean ev_history_is_frozen (EvHistory *history)
 
void ev_history_add_link (EvHistory *history, EvLink *link)
 
static void ev_history_activate_current_link (EvHistory *history)
 
gboolean ev_history_can_go_back (EvHistory *history)
 
void ev_history_go_back (EvHistory *history)
 
gboolean ev_history_can_go_forward (EvHistory *history)
 
void ev_history_go_forward (EvHistory *history)
 
static gint compare_link (EvLink *a, EvLink *b)
 
gboolean ev_history_go_to_link (EvHistory *history, EvLink *link)
 
GList * ev_history_get_back_list (EvHistory *history)
 
GList * ev_history_get_forward_list (EvHistory *history)
 
void ev_history_freeze (EvHistory *history)
 
void ev_history_thaw (EvHistory *history)
 
static gint ev_history_get_current_page (EvHistory *history)
 
static void ev_history_add_link_for_page (EvHistory *history, gint page)
 
static void page_changed_cb (EvDocumentModel *model, gint old_page, gint new_page, EvHistory *history)
 
static void document_changed_cb (EvDocumentModel *model, GParamSpec *pspec, EvHistory *history)
 
EvHistoryev_history_new (EvDocumentModel *model)
 

Variables

static guint signals [N_SIGNALS] = {0, }
 

Macro Definition Documentation

#define EV_HISTORY_MAX_LENGTH   (32)

Definition at line 34 of file ev-history.c.

Enumeration Type Documentation

anonymous enum
Enumerator
CHANGED 
ACTIVATE_LINK 
N_SIGNALS 

Definition at line 27 of file ev-history.c.

27  {
28  CHANGED,
30 
31  N_SIGNALS
32 };

Function Documentation

static void clear_list ( GList *  list)
static

Definition at line 54 of file ev-history.c.

55 {
56  g_list_free_full (list, (GDestroyNotify) g_object_unref);
57 }

+ Here is the caller graph for this function:

static gint compare_link ( EvLink a,
EvLink b 
)
static

Definition at line 254 of file ev-history.c.

256 {
257  if (a == b)
258  return 0;
259 
261 }

+ Here is the caller graph for this function:

static void document_changed_cb ( EvDocumentModel model,
GParamSpec *  pspec,
EvHistory history 
)
static

Definition at line 452 of file ev-history.c.

455 {
456  ev_history_clear (history);
458 }

+ Here is the caller graph for this function:

static void ev_history_activate_current_link ( EvHistory history)
static

Definition at line 176 of file ev-history.c.

177 {
178  g_assert (history->priv->current);
179 
180  ev_history_freeze (history);
181  g_signal_handler_block (history->priv->model, history->priv->page_changed_handler_id);
182  g_signal_emit (history, signals[ACTIVATE_LINK], 0, history->priv->current->data);
183  g_signal_handler_unblock (history->priv->model, history->priv->page_changed_handler_id);
184  ev_history_thaw (history);
185 
186  g_signal_emit (history, signals[CHANGED], 0);
187 }

+ Here is the caller graph for this function:

void ev_history_add_link ( EvHistory history,
EvLink link 
)

Definition at line 147 of file ev-history.c.

149 {
150  EvHistoryPrivate *priv;
151 
152  g_return_if_fail (EV_IS_HISTORY (history));
153  g_return_if_fail (EV_IS_LINK (link));
154 
155  if (ev_history_is_frozen (history))
156  return;
157 
158  priv = history->priv;
159 
160  if (priv->current) {
161  /* Truncate forward history at @current */
162  clear_list (priv->current->next);
163  priv->current->next = NULL;
164  }
165 
166  /* Push @link to the list */
167  priv->current = g_list_append (NULL, g_object_ref (link));
168  priv->list = g_list_concat (priv->list, priv->current);
169 
170  ev_history_prune (history);
171 
172  g_signal_emit (history, signals[CHANGED], 0);
173 }

+ Here is the caller graph for this function:

static void ev_history_add_link_for_page ( EvHistory history,
gint  page 
)
static

Definition at line 402 of file ev-history.c.

404 {
405  EvDocument *document;
406  EvLinkDest *dest;
407  EvLinkAction *action;
408  EvLink *link;
409  gchar *page_label;
410  gchar *title;
411 
412  if (ev_history_is_frozen (history))
413  return;
414 
415  if (ev_history_get_current_page (history) == page)
416  return;
417 
418  document = ev_document_model_get_document (history->priv->model);
419  if (!document)
420  return;
421 
422  page_label = ev_document_get_page_label (document, page);
423  if (!page_label)
424  return;
425 
426  title = g_strdup_printf (_("Page %s"), page_label);
427  g_free (page_label);
428 
429  dest = ev_link_dest_new_page (page);
430  action = ev_link_action_new_dest (dest);
431  g_object_unref (dest);
432 
433  link = ev_link_new (title, action);
434  g_object_unref (action);
435  g_free (title);
436 
437  ev_history_add_link (history, link);
438  g_object_unref (link);
439 }

+ Here is the caller graph for this function:

gboolean ev_history_can_go_back ( EvHistory history)

Definition at line 190 of file ev-history.c.

191 {
192  EvHistoryPrivate *priv;
193 
194  g_return_val_if_fail (EV_IS_HISTORY (history), FALSE);
195 
196  if (ev_history_is_frozen (history))
197  return FALSE;
198 
199  priv = history->priv;
200  return priv->current && priv->current->prev;
201 }

+ Here is the caller graph for this function:

gboolean ev_history_can_go_forward ( EvHistory history)

Definition at line 222 of file ev-history.c.

223 {
224  EvHistoryPrivate *priv;
225 
226  g_return_val_if_fail (EV_IS_HISTORY (history), FALSE);
227 
228  if (ev_history_is_frozen (history))
229  return FALSE;
230 
231  priv = history->priv;
232  return priv->current && priv->current->next;
233 }

+ Here is the caller graph for this function:

static void ev_history_class_init ( EvHistoryClass class)
static

Definition at line 106 of file ev-history.c.

107 {
108  GObjectClass *object_class = G_OBJECT_CLASS (class);
109 
110  object_class->finalize = ev_history_finalize;
111 
112  signals[CHANGED] =
113  g_signal_new ("changed",
114  G_OBJECT_CLASS_TYPE (object_class),
115  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
116  G_STRUCT_OFFSET (EvHistoryClass, changed),
117  NULL, NULL,
118  g_cclosure_marshal_VOID__VOID,
119  G_TYPE_NONE, 0);
120 
122  g_signal_new ("activate-link",
123  G_OBJECT_CLASS_TYPE (object_class),
124  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
125  G_STRUCT_OFFSET (EvHistoryClass, activate_link),
126  NULL, NULL,
127  g_cclosure_marshal_VOID__OBJECT,
128  G_TYPE_NONE, 1,
129  G_TYPE_OBJECT);
130 
131  g_type_class_add_private (object_class, sizeof (EvHistoryPrivate));
132 }
static void ev_history_clear ( EvHistory history)
static

Definition at line 60 of file ev-history.c.

61 {
62  clear_list (history->priv->list);
63  history->priv->list = NULL;
64 
65  history->priv->current = NULL;
66 }

+ Here is the caller graph for this function:

static void ev_history_finalize ( GObject *  object)
static

Definition at line 95 of file ev-history.c.

96 {
97  EvHistory *history = EV_HISTORY (object);
98 
99  ev_history_clear (history);
100  ev_history_set_model (history, NULL);
101 
102  G_OBJECT_CLASS (ev_history_parent_class)->finalize (object);
103 }

+ Here is the caller graph for this function:

void ev_history_freeze ( EvHistory history)

Definition at line 340 of file ev-history.c.

341 {
342  g_return_if_fail (EV_IS_HISTORY (history));
343 
344  history->priv->frozen++;
345 }

+ Here is the caller graph for this function:

GList* ev_history_get_back_list ( EvHistory history)

ev_history_get_back_list: : a EvHistory

Returns: (transfer container): the back history

Definition at line 306 of file ev-history.c.

307 {
308  EvHistoryPrivate *priv;
309  GList *list, *l;
310 
311  g_return_val_if_fail (EV_IS_HISTORY (history), NULL);
312 
313  priv = history->priv;
314 
315  if (priv->current == NULL)
316  return NULL;
317 
318  list = NULL;
319  for (l = priv->current->prev; l != NULL; l = l->prev)
320  list = g_list_prepend (list, l->data);
321 
322  return g_list_reverse (list);
323 }

+ Here is the caller graph for this function:

static gint ev_history_get_current_page ( EvHistory history)
static

Definition at line 357 of file ev-history.c.

358 {
359  EvLink *link;
360  EvDocument *document;
361  EvLinkDest *dest;
362  EvLinkAction *action;
363 
364  if (!history->priv->current)
365  return -1;
366 
367  link = history->priv->current->data;
368  action = ev_link_get_action (link);
369  if (!action)
370  return -1;
371 
372  dest = ev_link_action_get_dest (action);
373  if (!dest)
374  return -1;
375 
376  switch (ev_link_dest_get_dest_type (dest)) {
378  document = ev_document_model_get_document (history->priv->model);
379  if (!EV_IS_DOCUMENT_LINKS (document))
380  return -1;
381 
385  gint page = -1;
386 
387  document = ev_document_model_get_document (history->priv->model);
390  &page);
391 
392  return page;
393  }
394  default:
395  return ev_link_dest_get_page (dest);
396  }
397 
398  return -1;
399 }

+ Here is the caller graph for this function:

GList* ev_history_get_forward_list ( EvHistory history)

ev_history_get_forward_list: : a EvHistory

Returns: (transfer container): the forward history

Definition at line 332 of file ev-history.c.

333 {
334  g_return_val_if_fail (EV_IS_HISTORY (history), NULL);
335 
336  return g_list_copy (history->priv->current->next);
337 }

+ Here is the caller graph for this function:

void ev_history_go_back ( EvHistory history)

Definition at line 204 of file ev-history.c.

205 {
206  EvHistoryPrivate *priv;
207 
208  g_return_if_fail (EV_IS_HISTORY (history));
209 
210  if (!ev_history_can_go_back (history))
211  return;
212 
213  priv = history->priv;
214 
215  /* Move current back one step */
216  priv->current = priv->current->prev;
217 
219 }

+ Here is the caller graph for this function:

void ev_history_go_forward ( EvHistory history)

Definition at line 236 of file ev-history.c.

237 {
238  EvHistoryPrivate *priv;
239 
240  g_return_if_fail (EV_IS_HISTORY (history));
241 
242  if (!ev_history_can_go_forward (history))
243  return;
244 
245  priv = history->priv;
246 
247  /* Move current forward one step */
248  priv->current = priv->current->next;
249 
251 }

+ Here is the caller graph for this function:

gboolean ev_history_go_to_link ( EvHistory history,
EvLink link 
)

Definition at line 273 of file ev-history.c.

275 {
276  EvHistoryPrivate *priv;
277  GList *l;
278 
279  g_return_val_if_fail (EV_IS_HISTORY (history), FALSE);
280  g_return_val_if_fail (EV_IS_LINK (link), FALSE);
281 
282  if (ev_history_is_frozen (history))
283  return FALSE;
284 
285  priv = history->priv;
286 
287  l = g_list_find_custom (priv->list, link, (GCompareFunc) compare_link);
288  if (l == NULL)
289  return FALSE;
290 
291  /* Set the link as current */
292  priv->current = l;
293 
295 
296  return TRUE;
297 }

+ Here is the caller graph for this function:

static void ev_history_init ( EvHistory history)
static

Definition at line 135 of file ev-history.c.

136 {
137  history->priv = G_TYPE_INSTANCE_GET_PRIVATE (history, EV_TYPE_HISTORY, EvHistoryPrivate);
138 }
gboolean ev_history_is_frozen ( EvHistory history)

Definition at line 141 of file ev-history.c.

142 {
143  return history->priv->frozen > 0;
144 }

+ Here is the caller graph for this function:

EvHistory* ev_history_new ( EvDocumentModel model)

Definition at line 495 of file ev-history.c.

496 {
497  EvHistory *history;
498 
499  g_return_val_if_fail (EV_IS_DOCUMENT_MODEL (model), NULL);
500 
501  history = EV_HISTORY (g_object_new (EV_TYPE_HISTORY, NULL));
502  ev_history_set_model (history, model);
503 
504  return history;
505 }

+ Here is the caller graph for this function:

static void ev_history_prune ( EvHistory history)
static

Definition at line 69 of file ev-history.c.

70 {
71  EvHistoryPrivate *priv = history->priv;
72  GList *l;
73  guint i;
74 
75  g_assert (priv->current->next == NULL);
76 
77  for (i = 0, l = priv->current; i < EV_HISTORY_MAX_LENGTH && l != NULL; i++, l = l->prev)
78  /* empty */;
79 
80  if (l == NULL)
81  return;
82 
83  /* Throw away all history up to @l */
84  l = l->next;
85  l->prev->next = NULL;
86  l->prev = NULL;
87 
88  clear_list (priv->list);
89  priv->list = l;
90 
91  g_assert (g_list_length (priv->list) == EV_HISTORY_MAX_LENGTH);
92 }

+ Here is the caller graph for this function:

static void ev_history_set_model ( EvHistory history,
EvDocumentModel model 
)
static

Definition at line 461 of file ev-history.c.

463 {
464  if (history->priv->model == model)
465  return;
466 
467  if (history->priv->model) {
468  g_object_remove_weak_pointer (G_OBJECT (history->priv->model),
469  (gpointer)&history->priv->model);
470 
471  if (history->priv->page_changed_handler_id) {
472  g_signal_handler_disconnect (history->priv->model,
473  history->priv->page_changed_handler_id);
474  history->priv->page_changed_handler_id = 0;
475  }
476  }
477 
478  history->priv->model = model;
479  if (!model)
480  return;
481 
482  g_object_add_weak_pointer (G_OBJECT (model),
483  (gpointer)&history->priv->model);
484 
485  g_signal_connect (history->priv->model, "notify::document",
486  G_CALLBACK (document_changed_cb),
487  history);
488  history->priv->page_changed_handler_id =
489  g_signal_connect (history->priv->model, "page-changed",
490  G_CALLBACK (page_changed_cb),
491  history);
492 }

+ Here is the caller graph for this function:

void ev_history_thaw ( EvHistory history)

Definition at line 348 of file ev-history.c.

349 {
350  g_return_if_fail (EV_IS_HISTORY (history));
351  g_return_if_fail (history->priv->frozen > 0);
352 
353  history->priv->frozen--;
354 }

+ Here is the caller graph for this function:

static void page_changed_cb ( EvDocumentModel model,
gint  old_page,
gint  new_page,
EvHistory history 
)
static

Definition at line 442 of file ev-history.c.

446 {
447  if (ABS (new_page - old_page) > 1)
448  ev_history_add_link_for_page (history, new_page);
449 }

+ Here is the caller graph for this function:

Variable Documentation

guint signals[N_SIGNALS] = {0, }
static

Definition at line 36 of file ev-history.c.