28 #include "gnc-html-history.h" 37 gnc_html_history_destroy_cb destroy_cb;
38 gpointer destroy_cb_data;
46 gnc_html_history_new(
void)
48 gnc_html_history * hist = g_new0(gnc_html_history, 1);
50 hist->current_node = NULL;
51 hist->last_node = NULL;
62 gnc_html_history_destroy(gnc_html_history * hist)
66 for (n = hist->nodes; n ; n = n->next)
70 (hist->destroy_cb)((gnc_html_history_node *)n->data,
71 hist->destroy_cb_data);
73 gnc_html_history_node_destroy((gnc_html_history_node *)n->data);
75 g_list_free(hist->nodes);
78 hist->current_node = NULL;
79 hist->last_node = NULL;
88 gnc_html_history_set_node_destroy_cb(gnc_html_history * hist,
89 gnc_html_history_destroy_cb cb,
92 hist->destroy_cb = cb;
93 hist->destroy_cb_data = cb_data;
97 g_strcmp(
char * a,
char * b)
123 gnc_html_history_append(gnc_html_history * hist,
124 gnc_html_history_node * node)
127 gnc_html_history_node * hn;
129 if (hist->current_node)
131 hn = hist->current_node->data;
132 if ((hn->type == node->type) &&
133 !g_strcmp(hn->location, node->location) &&
134 !g_strcmp(hn->label, node->label))
136 if (hist->destroy_cb)
138 (hist->destroy_cb)(hn, hist->destroy_cb_data);
140 gnc_html_history_node_destroy(node);
145 for (n = hist->current_node->next; n; n = n->next)
147 if (hist->destroy_cb)
149 (hist->destroy_cb)((gnc_html_history_node *)n->data,
150 hist->destroy_cb_data);
152 gnc_html_history_node_destroy((gnc_html_history_node *)n->data);
154 g_list_free(hist->current_node->next);
155 hist->current_node->next = NULL;
156 hist->last_node = hist->current_node;
160 n->data = (gpointer) node;
164 if (hist->nodes && hist->last_node)
166 n->prev = hist->last_node;
167 hist->last_node->next = n;
169 hist->current_node = n;
176 g_print (
"???? hist->nodes non-NULL, but no last_node!\n");
180 hist->current_node = n;
189 gnc_html_history_node *
190 gnc_html_history_get_current(gnc_html_history * hist)
192 if (!hist || !(hist->current_node))
return NULL;
194 return hist->current_node->data;
202 gnc_html_history_node *
203 gnc_html_history_forward(gnc_html_history * hist)
205 if (!hist || !(hist->current_node))
210 if (hist->current_node->next)
212 hist->current_node = hist->current_node->next;
215 return hist->current_node->data;
223 gnc_html_history_node *
224 gnc_html_history_back(gnc_html_history * hist)
227 if (!hist || !(hist->current_node))
232 if (hist->current_node->prev)
234 hist->current_node = hist->current_node->prev;
237 return hist->current_node->data;
247 gnc_html_history_back_p(gnc_html_history * hist)
249 if (hist && hist->current_node && hist->current_node->prev)
266 gnc_html_history_forward_p(gnc_html_history * hist)
268 if (hist && hist->current_node && hist->current_node->next)
283 gnc_html_history_node *
284 gnc_html_history_node_new(URLType type,
const gchar * location,
287 gnc_html_history_node * rv = g_new0(gnc_html_history_node, 1);
289 rv->type = g_strdup(type);
290 rv->location = g_strdup(location);
291 rv->label = g_strdup(label);
301 gnc_html_history_node_destroy(gnc_html_history_node * node)
306 g_free(node->location);
309 node->location = NULL;