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) noexcept
48 gnc_html_history * hist = g_new0(gnc_html_history, 1);
49 hist->nodes =
nullptr;
50 hist->current_node =
nullptr;
51 hist->last_node =
nullptr;
62 gnc_html_history_destroy(gnc_html_history * hist) noexcept
64 for (GList *n = hist->nodes; n ; n = n->next)
68 (hist->destroy_cb)((gnc_html_history_node *)n->data,
69 hist->destroy_cb_data);
71 gnc_html_history_node_destroy((gnc_html_history_node *)n->data);
73 g_list_free(hist->nodes);
75 hist->nodes =
nullptr;
76 hist->current_node =
nullptr;
77 hist->last_node =
nullptr;
86 gnc_html_history_set_node_destroy_cb(gnc_html_history * hist,
87 gnc_html_history_destroy_cb cb,
88 gpointer cb_data) noexcept
90 hist->destroy_cb = cb;
91 hist->destroy_cb_data = cb_data;
95 g_strcmp(
char * a,
char * b)
121 gnc_html_history_append(gnc_html_history * hist,
122 gnc_html_history_node * node) noexcept
124 if (hist->current_node)
126 auto hn =
static_cast<gnc_html_history_node *
>(hist->current_node->data);
127 if ((hn->type == node->type) &&
128 !g_strcmp(hn->location, node->location) &&
129 !g_strcmp(hn->label, node->label))
131 if (hist->destroy_cb)
133 (hist->destroy_cb)(hn, hist->destroy_cb_data);
135 gnc_html_history_node_destroy(node);
140 for (GList *n = hist->current_node->next; n; n = n->next)
142 if (hist->destroy_cb)
144 (hist->destroy_cb)((gnc_html_history_node *)n->data,
145 hist->destroy_cb_data);
147 gnc_html_history_node_destroy((gnc_html_history_node *)n->data);
149 g_list_free(hist->current_node->next);
150 hist->current_node->next =
nullptr;
151 hist->last_node = hist->current_node;
154 GList *n = g_list_alloc();
155 n->data = (gpointer) node;
159 if (hist->nodes && hist->last_node)
161 n->prev = hist->last_node;
162 hist->last_node->next = n;
164 hist->current_node = n;
171 g_print (
"???? hist->nodes non-NULL, but no last_node!\n");
175 hist->current_node = n;
184 gnc_html_history_node *
185 gnc_html_history_get_current(gnc_html_history * hist) noexcept
187 if (!hist || !(hist->current_node))
return nullptr;
189 return static_cast<gnc_html_history_node *
>(hist->current_node->data);
197 gnc_html_history_node *
198 gnc_html_history_forward(gnc_html_history * hist) noexcept
200 if (!hist || !(hist->current_node))
205 if (hist->current_node->next)
207 hist->current_node = hist->current_node->next;
210 return static_cast<gnc_html_history_node *
>(hist->current_node->data);
218 gnc_html_history_node *
219 gnc_html_history_back(gnc_html_history * hist) noexcept
222 if (!hist || !(hist->current_node))
227 if (hist->current_node->prev)
229 hist->current_node = hist->current_node->prev;
232 return static_cast<gnc_html_history_node *
>(hist->current_node->data);
242 gnc_html_history_back_p(gnc_html_history * hist) noexcept
244 if (hist && hist->current_node && hist->current_node->prev)
261 gnc_html_history_forward_p(gnc_html_history * hist) noexcept
263 if (hist && hist->current_node && hist->current_node->next)
278 gnc_html_history_node *
279 gnc_html_history_node_new(URLType type,
const gchar * location,
280 const gchar * label) noexcept
282 gnc_html_history_node * rv = g_new0(gnc_html_history_node, 1);
284 rv->type = g_strdup(type);
285 rv->location = g_strdup(location);
286 rv->label = g_strdup(label);
296 gnc_html_history_node_destroy(gnc_html_history_node * node) noexcept
301 g_free(node->location);
304 node->location =
nullptr;
305 node->label =
nullptr;