~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to plug-ins/helpbrowser/queue.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * The GIMP Help Browser
 
5
 * Copyright (C) 1999 Sven Neumann <sven@gimp.org>
 
6
 *                    Michael Natterer <mitschel@cs.tu-berlin.de>
 
7
 *
 
8
 * queue.c - a history queue
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
23
 */
 
24
 
 
25
#include "config.h"
 
26
 
 
27
#include <glib.h>
 
28
 
 
29
#include "queue.h"
 
30
 
 
31
struct _Queue
 
32
{
 
33
  GList *queue;
 
34
  GList *current;
 
35
};
 
36
 
 
37
Queue *
 
38
queue_new (void)
 
39
{
 
40
  Queue *h;
 
41
 
 
42
  h = g_malloc (sizeof (Queue));
 
43
  
 
44
  h->queue = NULL;
 
45
  h->current = NULL;
 
46
 
 
47
  return (h);
 
48
}
 
49
 
 
50
void
 
51
queue_free (Queue *h)
 
52
{
 
53
  g_return_if_fail (h != NULL);
 
54
 
 
55
  /* needs to free data in list as well! */
 
56
  if (h->queue)
 
57
    {
 
58
      g_list_foreach (h->queue, (GFunc) g_free, NULL);
 
59
      g_list_free (h->queue);
 
60
    }
 
61
 
 
62
  g_free (h);
 
63
}
 
64
 
 
65
void
 
66
queue_move_prev (Queue *h)
 
67
{
 
68
  if (!h || !h->queue || (h->current == g_list_first (h->queue)))
 
69
    return;
 
70
 
 
71
  h->current = g_list_previous (h->current);
 
72
}
 
73
 
 
74
void
 
75
queue_move_next (Queue *h)
 
76
{
 
77
  if (!h || !h->queue || (h->current == g_list_last (h->queue)))
 
78
    return;
 
79
 
 
80
  h->current = g_list_next (h->current);
 
81
}
 
82
 
 
83
const gchar *
 
84
queue_prev (Queue *h)
 
85
{
 
86
  GList *p;
 
87
 
 
88
  if (!h || !h->queue || (h->current == g_list_first (h->queue)))
 
89
    return NULL;
 
90
 
 
91
  p = g_list_previous (h->current);
 
92
 
 
93
  return (const gchar *) p->data;
 
94
}
 
95
 
 
96
const gchar *
 
97
queue_next (Queue *h)
 
98
{
 
99
  GList *p;
 
100
 
 
101
  if (!h || !h->queue || (h->current == g_list_last(h->queue)))
 
102
    return NULL;
 
103
 
 
104
  p = g_list_next (h->current);
 
105
 
 
106
  return (const gchar *) p->data;
 
107
}
 
108
 
 
109
void 
 
110
queue_add (Queue       *h,
 
111
           const gchar *ref)
 
112
{
 
113
  GList *trash = NULL;
 
114
 
 
115
  g_return_if_fail (h != NULL);
 
116
  g_return_if_fail (ref != NULL);
 
117
 
 
118
  if (h->current)
 
119
    {
 
120
      trash = h->current->next;
 
121
      h->current->next = NULL;
 
122
    }
 
123
 
 
124
  h->queue   = g_list_append (h->queue, g_strdup (ref));
 
125
  h->current = g_list_last (h->queue);
 
126
 
 
127
  if (trash)
 
128
    {
 
129
      g_list_foreach (trash, (GFunc) g_free, NULL);
 
130
      g_list_free (trash);
 
131
    }   
 
132
}
 
133
 
 
134
gboolean
 
135
queue_has_next (Queue *h)
 
136
{
 
137
  if (!h || !h->queue || (h->current == g_list_last (h->queue)))
 
138
    return FALSE;
 
139
  
 
140
  return (g_list_next (h->current) != NULL);
 
141
}
 
142
 
 
143
gboolean
 
144
queue_has_prev (Queue *h)
 
145
{
 
146
  if (!h || !h->queue || (h->current == g_list_first (h->queue)))
 
147
    return FALSE;
 
148
  
 
149
  return (g_list_previous (h->current) != NULL);
 
150
}