File: | cut-n-paste/toolbar-editor/egg-toolbars-model.c |
Warning: | line 101, column 15 Value stored to 'node' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (C) 2002-2004 Marco Pesenti Gritti |
3 | * Copyright (C) 2004 Christian Persch |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2, or (at your option) |
8 | * any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * |
19 | * $Id$ |
20 | */ |
21 | |
22 | #include "config.h" |
23 | |
24 | #include "egg-toolbars-model.h" |
25 | #include "eggtypebuiltins.h" |
26 | #include "eggmarshalers.h" |
27 | |
28 | #include <unistd.h> |
29 | #include <string.h> |
30 | #include <libxml/tree.h> |
31 | #include <cdk/cdk.h> |
32 | |
33 | static void egg_toolbars_model_finalize (GObject *object); |
34 | |
35 | enum |
36 | { |
37 | ITEM_ADDED, |
38 | ITEM_REMOVED, |
39 | TOOLBAR_ADDED, |
40 | TOOLBAR_CHANGED, |
41 | TOOLBAR_REMOVED, |
42 | LAST_SIGNAL |
43 | }; |
44 | |
45 | typedef struct |
46 | { |
47 | char *name; |
48 | EggTbModelFlags flags; |
49 | } EggToolbarsToolbar; |
50 | |
51 | typedef struct |
52 | { |
53 | char *name; |
54 | } EggToolbarsItem; |
55 | |
56 | static guint signals[LAST_SIGNAL] = { 0 }; |
57 | |
58 | struct EggToolbarsModelPrivate |
59 | { |
60 | GNode *toolbars; |
61 | GList *types; |
62 | GHashTable *flags; |
63 | }; |
64 | |
65 | G_DEFINE_TYPE_WITH_PRIVATE (EggToolbarsModel, egg_toolbars_model, G_TYPE_OBJECT)static void egg_toolbars_model_init (EggToolbarsModel *self); static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass); static GType egg_toolbars_model_get_type_once (void ); static gpointer egg_toolbars_model_parent_class = ((void*) 0); static gint EggToolbarsModel_private_offset; static void egg_toolbars_model_class_intern_init (gpointer klass) { egg_toolbars_model_parent_class = g_type_class_peek_parent (klass); if (EggToolbarsModel_private_offset != 0) g_type_class_adjust_private_offset (klass, &EggToolbarsModel_private_offset); egg_toolbars_model_class_init ((EggToolbarsModelClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer egg_toolbars_model_get_instance_private (EggToolbarsModel *self) { return (((gpointer) ((guint8*) (self ) + (glong) (EggToolbarsModel_private_offset)))); } GType egg_toolbars_model_get_type (void) { static gsize static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) *(&static_g_define_type_id) : ((void*)0)); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter (&static_g_define_type_id )); }))) { GType g_define_type_id = egg_toolbars_model_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id) = (g_define_type_id) ) : (void) 0; g_once_init_leave ((&static_g_define_type_id ), (gsize) (g_define_type_id)); })); } return static_g_define_type_id ; } __attribute__ ((__noinline__)) static GType egg_toolbars_model_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("EggToolbarsModel" ), sizeof (EggToolbarsModelClass), (GClassInitFunc)(void (*)( void)) egg_toolbars_model_class_intern_init, sizeof (EggToolbarsModel ), (GInstanceInitFunc)(void (*)(void)) egg_toolbars_model_init , (GTypeFlags) 0); { {{ EggToolbarsModel_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (EggToolbarsModelPrivate)); };} } return g_define_type_id; } |
66 | |
67 | static xmlDocPtr |
68 | egg_toolbars_model_to_xml (EggToolbarsModel *model) |
69 | { |
70 | GNode *l1, *l2, *tl; |
71 | GList *l3; |
72 | xmlDocPtr doc; |
73 | |
74 | g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return (((void*)0)); } } while (0); |
75 | |
76 | tl = model->priv->toolbars; |
77 | |
78 | xmlIndentTreeOutput(*(__xmlIndentTreeOutput())) = TRUE(!(0)); |
79 | doc = xmlNewDoc ((const xmlChar*) "1.0"); |
80 | doc->children = xmlNewDocNode (doc, NULL((void*)0), (const xmlChar*) "toolbars", NULL((void*)0)); |
81 | |
82 | for (l1 = tl->children; l1 != NULL((void*)0); l1 = l1->next) |
83 | { |
84 | xmlNodePtr tnode; |
85 | EggToolbarsToolbar *toolbar = l1->data; |
86 | |
87 | tnode = xmlNewChild (doc->children, NULL((void*)0), (const xmlChar*) "toolbar", NULL((void*)0)); |
88 | xmlSetProp (tnode, (const xmlChar*) "name", (const xmlChar*) toolbar->name); |
89 | xmlSetProp (tnode, (const xmlChar*) "hidden", |
90 | (toolbar->flags&EGG_TB_MODEL_HIDDEN) ? (const xmlChar*) "true" : (const xmlChar*) "false"); |
91 | xmlSetProp (tnode, (const xmlChar*) "editable", |
92 | (toolbar->flags&EGG_TB_MODEL_NOT_EDITABLE) ? (const xmlChar*) "false" : (const xmlChar*) "true"); |
93 | |
94 | for (l2 = l1->children; l2 != NULL((void*)0); l2 = l2->next) |
95 | { |
96 | xmlNodePtr node; |
97 | EggToolbarsItem *item = l2->data; |
98 | |
99 | if (strcmp (item->name, "_separator") == 0) |
100 | { |
101 | node = xmlNewChild (tnode, NULL((void*)0), (const xmlChar*) "separator", NULL((void*)0)); |
Value stored to 'node' is never read | |
102 | continue; |
103 | } |
104 | |
105 | node = xmlNewChild (tnode, NULL((void*)0), (const xmlChar*) "toolitem", NULL((void*)0)); |
106 | xmlSetProp (node, (const xmlChar*) "name", (const xmlChar*) item->name); |
107 | |
108 | /* Add 'data' nodes for each data type which can be written out for this |
109 | * item. Only write types which can be used to restore the data. */ |
110 | for (l3 = model->priv->types; l3 != NULL((void*)0); l3 = l3->next) |
111 | { |
112 | EggToolbarsItemType *type = l3->data; |
113 | if (type->get_name != NULL((void*)0) && type->get_data != NULL((void*)0)) |
114 | { |
115 | xmlNodePtr dnode; |
116 | char *tmp; |
117 | |
118 | tmp = type->get_data (type, item->name); |
119 | if (tmp != NULL((void*)0)) |
120 | { |
121 | dnode = xmlNewTextChild (node, NULL((void*)0), (const xmlChar*) "data", (const xmlChar*) tmp); |
122 | g_free (tmp); |
123 | |
124 | tmp = cdk_atom_name (type->type); |
125 | xmlSetProp (dnode, (const xmlChar*) "type", (const xmlChar*) tmp); |
126 | g_free (tmp); |
127 | } |
128 | } |
129 | } |
130 | } |
131 | } |
132 | |
133 | return doc; |
134 | } |
135 | |
136 | static gboolean |
137 | safe_save_xml (const char *xml_file, xmlDocPtr doc) |
138 | { |
139 | char *tmp_file; |
140 | char *old_file; |
141 | gboolean old_exist; |
142 | gboolean retval = TRUE(!(0)); |
143 | |
144 | tmp_file = g_strconcat (xml_file, ".tmp", NULL((void*)0)); |
145 | old_file = g_strconcat (xml_file, ".old", NULL((void*)0)); |
146 | |
147 | if (xmlSaveFormatFile (tmp_file, doc, 1) <= 0) |
148 | { |
149 | g_warning ("Failed to write XML data to %s", tmp_file); |
150 | goto failed; |
151 | } |
152 | |
153 | old_exist = g_file_test (xml_file, G_FILE_TEST_EXISTS); |
154 | |
155 | if (old_exist) |
156 | { |
157 | if (rename (xml_file, old_file) < 0) |
158 | { |
159 | g_warning ("Failed to rename %s to %s", xml_file, old_file); |
160 | retval = FALSE(0); |
161 | goto failed; |
162 | } |
163 | } |
164 | |
165 | if (rename (tmp_file, xml_file) < 0) |
166 | { |
167 | g_warning ("Failed to rename %s to %s", tmp_file, xml_file); |
168 | |
169 | if (rename (old_file, xml_file) < 0) |
170 | { |
171 | g_warning ("Failed to restore %s from %s", xml_file, tmp_file); |
172 | } |
173 | retval = FALSE(0); |
174 | goto failed; |
175 | } |
176 | |
177 | if (old_exist) |
178 | { |
179 | if (unlink (old_file) < 0) |
180 | { |
181 | g_warning ("Failed to delete old file %s", old_file); |
182 | } |
183 | } |
184 | |
185 | failed: |
186 | g_free (old_file); |
187 | g_free (tmp_file); |
188 | |
189 | return retval; |
190 | } |
191 | |
192 | void |
193 | egg_toolbars_model_save_toolbars (EggToolbarsModel *model, |
194 | const char *xml_file, |
195 | const char *version) |
196 | { |
197 | xmlDocPtr doc; |
198 | xmlNodePtr root; |
199 | |
200 | g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ; } } while (0); |
201 | |
202 | doc = egg_toolbars_model_to_xml (model); |
203 | root = xmlDocGetRootElement (doc); |
204 | xmlSetProp (root, (const xmlChar*) "version", (const xmlChar*) version); |
205 | safe_save_xml (xml_file, doc); |
206 | xmlFreeDoc (doc); |
207 | } |
208 | |
209 | static gboolean |
210 | is_unique (EggToolbarsModel *model, |
211 | EggToolbarsItem *idata) |
212 | { |
213 | EggToolbarsItem *idata2; |
214 | GNode *toolbar, *item; |
215 | |
216 | |
217 | for(toolbar = g_node_first_child (model->priv->toolbars)((model->priv->toolbars) ? ((GNode*) (model->priv-> toolbars))->children : ((void*)0)); |
218 | toolbar != NULL((void*)0); toolbar = g_node_next_sibling (toolbar)((toolbar) ? ((GNode*) (toolbar))->next : ((void*)0))) |
219 | { |
220 | for(item = g_node_first_child (toolbar)((toolbar) ? ((GNode*) (toolbar))->children : ((void*)0)); |
221 | item != NULL((void*)0); item = g_node_next_sibling (item)((item) ? ((GNode*) (item))->next : ((void*)0))) |
222 | { |
223 | idata2 = item->data; |
224 | |
225 | if (idata != idata2 && strcmp (idata->name, idata2->name) == 0) |
226 | { |
227 | return FALSE(0); |
228 | } |
229 | } |
230 | } |
231 | |
232 | return TRUE(!(0)); |
233 | } |
234 | |
235 | static GNode * |
236 | toolbar_node_new (const char *name) |
237 | { |
238 | EggToolbarsToolbar *toolbar; |
239 | |
240 | toolbar = g_new (EggToolbarsToolbar, 1)((EggToolbarsToolbar *) g_malloc_n ((1), sizeof (EggToolbarsToolbar ))); |
241 | toolbar->name = g_strdup (name)g_strdup_inline (name); |
242 | toolbar->flags = 0; |
243 | |
244 | return g_node_new (toolbar); |
245 | } |
246 | |
247 | static GNode * |
248 | item_node_new (const char *name, EggToolbarsModel *model) |
249 | { |
250 | EggToolbarsItem *item; |
251 | int flags; |
252 | |
253 | g_return_val_if_fail (name != NULL, NULL)do { if ((name != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "name != NULL"); return (((void*)0)); } } while (0); |
254 | |
255 | item = g_new (EggToolbarsItem, 1)((EggToolbarsItem *) g_malloc_n ((1), sizeof (EggToolbarsItem ))); |
256 | item->name = g_strdup (name)g_strdup_inline (name); |
257 | |
258 | flags = GPOINTER_TO_INT (g_hash_table_lookup (model->priv->flags, item->name))((gint) (glong) (g_hash_table_lookup (model->priv->flags , item->name))); |
259 | if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0) |
260 | g_hash_table_insert (model->priv->flags, |
261 | g_strdup (item->name)g_strdup_inline (item->name), |
262 | GINT_TO_POINTER (flags | EGG_TB_MODEL_NAME_USED)((gpointer) (glong) (flags | EGG_TB_MODEL_NAME_USED))); |
263 | |
264 | return g_node_new (item); |
265 | } |
266 | |
267 | static void |
268 | item_node_free (GNode *item_node, EggToolbarsModel *model) |
269 | { |
270 | EggToolbarsItem *item = item_node->data; |
271 | int flags; |
272 | |
273 | flags = GPOINTER_TO_INT (g_hash_table_lookup (model->priv->flags, item->name))((gint) (glong) (g_hash_table_lookup (model->priv->flags , item->name))); |
274 | if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0 && is_unique (model, item)) |
275 | g_hash_table_insert (model->priv->flags, |
276 | g_strdup (item->name)g_strdup_inline (item->name), |
277 | GINT_TO_POINTER (flags & ~EGG_TB_MODEL_NAME_USED)((gpointer) (glong) (flags & ~EGG_TB_MODEL_NAME_USED))); |
278 | |
279 | g_free (item->name); |
280 | g_free (item); |
281 | |
282 | g_node_destroy (item_node); |
283 | } |
284 | |
285 | static void |
286 | toolbar_node_free (GNode *toolbar_node, EggToolbarsModel *model) |
287 | { |
288 | EggToolbarsToolbar *toolbar = toolbar_node->data; |
289 | |
290 | g_node_children_foreach (toolbar_node, G_TRAVERSE_ALL, |
291 | (GNodeForeachFunc) item_node_free, model); |
292 | |
293 | g_free (toolbar->name); |
294 | g_free (toolbar); |
295 | |
296 | g_node_destroy (toolbar_node); |
297 | } |
298 | |
299 | EggTbModelFlags |
300 | egg_toolbars_model_get_flags (EggToolbarsModel *model, |
301 | int toolbar_position) |
302 | { |
303 | GNode *toolbar_node; |
304 | EggToolbarsToolbar *toolbar; |
305 | |
306 | toolbar_node = g_node_nth_child (model->priv->toolbars, toolbar_position); |
307 | g_return_val_if_fail (toolbar_node != NULL, 0)do { if ((toolbar_node != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "toolbar_node != NULL" ); return (0); } } while (0); |
308 | |
309 | toolbar = toolbar_node->data; |
310 | |
311 | return toolbar->flags; |
312 | } |
313 | |
314 | void |
315 | egg_toolbars_model_set_flags (EggToolbarsModel *model, |
316 | int toolbar_position, |
317 | EggTbModelFlags flags) |
318 | { |
319 | GNode *toolbar_node; |
320 | EggToolbarsToolbar *toolbar; |
321 | |
322 | toolbar_node = g_node_nth_child (model->priv->toolbars, toolbar_position); |
323 | g_return_if_fail (toolbar_node != NULL)do { if ((toolbar_node != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "toolbar_node != NULL" ); return; } } while (0); |
324 | |
325 | toolbar = toolbar_node->data; |
326 | |
327 | toolbar->flags = flags; |
328 | |
329 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), signals[TOOLBAR_CHANGED], |
330 | 0, toolbar_position); |
331 | } |
332 | |
333 | |
334 | char * |
335 | egg_toolbars_model_get_data (EggToolbarsModel *model, |
336 | CdkAtom type, |
337 | const char *name) |
338 | { |
339 | EggToolbarsItemType *t; |
340 | char *data = NULL((void*)0); |
341 | GList *l; |
342 | |
343 | if (type == CDK_NONE((CdkAtom)((gpointer) (gulong) (0))) || type == cdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE"application/x-toolbar-item", FALSE(0))) |
344 | { |
345 | g_return_val_if_fail (name != NULL, NULL)do { if ((name != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "name != NULL"); return (((void*)0)); } } while (0); |
346 | g_return_val_if_fail (*name != 0, NULL)do { if ((*name != 0)) { } else { g_return_if_fail_warning (( (gchar*) 0), ((const char*) (__func__)), "*name != 0"); return (((void*)0)); } } while (0); |
347 | return strdup (name); |
348 | } |
349 | |
350 | for (l = model->priv->types; l != NULL((void*)0); l = l->next) |
351 | { |
352 | t = l->data; |
353 | if (t->type == type && t->get_data != NULL((void*)0)) |
354 | { |
355 | data = t->get_data (t, name); |
356 | if (data != NULL((void*)0)) break; |
357 | } |
358 | } |
359 | |
360 | return data; |
361 | } |
362 | |
363 | char * |
364 | egg_toolbars_model_get_name (EggToolbarsModel *model, |
365 | CdkAtom type, |
366 | const char *data, |
367 | gboolean create) |
368 | { |
369 | EggToolbarsItemType *t; |
370 | char *name = NULL((void*)0); |
371 | GList *l; |
372 | |
373 | if (type == CDK_NONE((CdkAtom)((gpointer) (gulong) (0))) || type == cdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE"application/x-toolbar-item", FALSE(0))) |
374 | { |
375 | g_return_val_if_fail (data, NULL)do { if ((data)) { } else { g_return_if_fail_warning (((gchar *) 0), ((const char*) (__func__)), "data"); return (((void*)0 )); } } while (0); |
376 | g_return_val_if_fail (*data, NULL)do { if ((*data)) { } else { g_return_if_fail_warning (((gchar *) 0), ((const char*) (__func__)), "*data"); return (((void*) 0)); } } while (0); |
377 | return strdup (data); |
378 | } |
379 | |
380 | if (create) |
381 | { |
382 | for (l = model->priv->types; name == NULL((void*)0) && l != NULL((void*)0); l = l->next) |
383 | { |
384 | t = l->data; |
385 | if (t->type == type && t->new_name != NULL((void*)0)) |
386 | name = t->new_name (t, data); |
387 | } |
388 | |
389 | return name; |
390 | } |
391 | else |
392 | { |
393 | for (l = model->priv->types; name == NULL((void*)0) && l != NULL((void*)0); l = l->next) |
394 | { |
395 | t = l->data; |
396 | if (t->type == type && t->get_name != NULL((void*)0)) |
397 | name = t->get_name (t, data); |
398 | } |
399 | |
400 | return name; |
401 | } |
402 | } |
403 | |
404 | static gboolean |
405 | impl_add_item (EggToolbarsModel *model, |
406 | int toolbar_position, |
407 | int position, |
408 | const char *name) |
409 | { |
410 | GNode *parent_node; |
411 | GNode *child_node; |
412 | int real_position; |
413 | |
414 | g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ((0)); } } while (0); |
415 | g_return_val_if_fail (name != NULL, FALSE)do { if ((name != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "name != NULL"); return ((0)); } } while (0); |
416 | |
417 | parent_node = g_node_nth_child (model->priv->toolbars, toolbar_position); |
418 | child_node = item_node_new (name, model); |
419 | g_node_insert (parent_node, position, child_node); |
420 | |
421 | real_position = g_node_child_position (parent_node, child_node); |
422 | |
423 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), signals[ITEM_ADDED], 0, |
424 | toolbar_position, real_position); |
425 | |
426 | return TRUE(!(0)); |
427 | } |
428 | |
429 | gboolean |
430 | egg_toolbars_model_add_item (EggToolbarsModel *model, |
431 | int toolbar_position, |
432 | int position, |
433 | const char *name) |
434 | { |
435 | EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (model)((((EggToolbarsModelClass*) (((GTypeInstance*) ((model)))-> g_class)))); |
436 | return klass->add_item (model, toolbar_position, position, name); |
437 | } |
438 | |
439 | int |
440 | egg_toolbars_model_add_toolbar (EggToolbarsModel *model, |
441 | int position, |
442 | const char *name) |
443 | { |
444 | GNode *node; |
445 | int real_position; |
446 | |
447 | g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), -1)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return (-1); } } while (0); |
448 | |
449 | node = toolbar_node_new (name); |
450 | g_node_insert (model->priv->toolbars, position, node); |
451 | |
452 | real_position = g_node_child_position (model->priv->toolbars, node); |
453 | |
454 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), signals[TOOLBAR_ADDED], |
455 | 0, real_position); |
456 | |
457 | return g_node_child_position (model->priv->toolbars, node); |
458 | } |
459 | |
460 | static char * |
461 | parse_data_list (EggToolbarsModel *model, |
462 | xmlNodePtr child, |
463 | gboolean create) |
464 | { |
465 | char *name = NULL((void*)0); |
466 | while (child && name == NULL((void*)0)) |
467 | { |
468 | if (xmlStrEqual (child->name, (const xmlChar*) "data")) |
469 | { |
470 | xmlChar *type = xmlGetProp (child, (const xmlChar*) "type"); |
471 | xmlChar *data = xmlNodeGetContent (child); |
472 | |
473 | if (type != NULL((void*)0)) |
474 | { |
475 | CdkAtom atom = cdk_atom_intern ((const char*) type, TRUE(!(0))); |
476 | name = egg_toolbars_model_get_name (model, atom, (const char*) data, create); |
477 | } |
478 | |
479 | xmlFree (type); |
480 | xmlFree (data); |
481 | } |
482 | |
483 | child = child->next; |
484 | } |
485 | |
486 | return name; |
487 | } |
488 | |
489 | static void |
490 | parse_item_list (EggToolbarsModel *model, |
491 | xmlNodePtr child, |
492 | int position) |
493 | { |
494 | while (child) |
495 | { |
496 | if (xmlStrEqual (child->name, (const xmlChar*) "toolitem")) |
497 | { |
498 | char *name; |
499 | |
500 | /* Try to get the name using the data elements first, |
501 | as they are more 'portable' or 'persistent'. */ |
502 | name = parse_data_list (model, child->children, FALSE(0)); |
503 | if (name == NULL((void*)0)) |
504 | { |
505 | name = parse_data_list (model, child->children, TRUE(!(0))); |
506 | } |
507 | |
508 | /* If that fails, try to use the name. */ |
509 | if (name == NULL((void*)0)) |
510 | { |
511 | xmlChar *type = xmlGetProp (child, (const xmlChar*) "type"); |
512 | xmlChar *data = xmlGetProp (child, (const xmlChar*) "name"); |
513 | CdkAtom atom = type ? cdk_atom_intern ((const char*) type, TRUE(!(0))) : CDK_NONE((CdkAtom)((gpointer) (gulong) (0))); |
514 | |
515 | /* If an old format, try to use it. */ |
516 | name = egg_toolbars_model_get_name (model, atom, (const char*) data, FALSE(0)); |
517 | if (name == NULL((void*)0)) |
518 | { |
519 | name = egg_toolbars_model_get_name (model, atom, (const char*) data, TRUE(!(0))); |
520 | } |
521 | |
522 | xmlFree (type); |
523 | xmlFree (data); |
524 | } |
525 | |
526 | if (name != NULL((void*)0)) |
527 | { |
528 | egg_toolbars_model_add_item (model, position, -1, name); |
529 | g_free (name); |
530 | } |
531 | } |
532 | else if (xmlStrEqual (child->name, (const xmlChar*) "separator")) |
533 | { |
534 | egg_toolbars_model_add_item (model, position, -1, "_separator"); |
535 | } |
536 | |
537 | child = child->next; |
538 | } |
539 | } |
540 | |
541 | static void |
542 | parse_toolbars (EggToolbarsModel *model, |
543 | xmlNodePtr child) |
544 | { |
545 | while (child) |
546 | { |
547 | if (xmlStrEqual (child->name, (const xmlChar*) "toolbar")) |
548 | { |
549 | xmlChar *string; |
550 | int position; |
551 | EggTbModelFlags flags; |
552 | |
553 | string = xmlGetProp (child, (const xmlChar*) "name"); |
554 | position = egg_toolbars_model_add_toolbar (model, -1, (const char*) string); |
555 | flags = egg_toolbars_model_get_flags (model, position); |
556 | xmlFree (string); |
557 | |
558 | string = xmlGetProp (child, (const xmlChar*) "editable"); |
559 | if (string && xmlStrEqual (string, (const xmlChar*) "false")) |
560 | flags |= EGG_TB_MODEL_NOT_EDITABLE; |
561 | xmlFree (string); |
562 | |
563 | string = xmlGetProp (child, (const xmlChar*) "hidden"); |
564 | if (string && xmlStrEqual (string, (const xmlChar*) "true")) |
565 | flags |= EGG_TB_MODEL_HIDDEN; |
566 | xmlFree (string); |
567 | |
568 | string = xmlGetProp (child, (const xmlChar*) "style"); |
569 | if (string && xmlStrEqual (string, (const xmlChar*) "icons-only")) |
570 | flags |= EGG_TB_MODEL_ICONS; |
571 | xmlFree (string); |
572 | |
573 | egg_toolbars_model_set_flags (model, position, flags); |
574 | |
575 | parse_item_list (model, child->children, position); |
576 | } |
577 | |
578 | child = child->next; |
579 | } |
580 | } |
581 | |
582 | gboolean |
583 | egg_toolbars_model_load_toolbars (EggToolbarsModel *model, |
584 | const char *xml_file) |
585 | { |
586 | xmlDocPtr doc; |
587 | xmlNodePtr root; |
588 | |
589 | g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ((0)); } } while (0); |
590 | |
591 | if (!xml_file || !g_file_test (xml_file, G_FILE_TEST_EXISTS)) return FALSE(0); |
592 | |
593 | doc = xmlParseFile (xml_file); |
594 | if (doc == NULL((void*)0)) |
595 | { |
596 | g_warning ("Failed to load XML data from %s", xml_file); |
597 | return FALSE(0); |
598 | } |
599 | root = xmlDocGetRootElement (doc); |
600 | |
601 | parse_toolbars (model, root->children); |
602 | |
603 | xmlFreeDoc (doc); |
604 | |
605 | return TRUE(!(0)); |
606 | } |
607 | |
608 | gboolean |
609 | egg_toolbars_model_load_toolbars_from_resource (EggToolbarsModel *model, |
610 | const char *path) |
611 | { |
612 | xmlDocPtr doc; |
613 | xmlNodePtr root; |
614 | GBytes *bytes; |
615 | GError *error = NULL((void*)0); |
616 | const guint8 *data; |
617 | gsize data_len; |
618 | |
619 | g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ((0)); } } while (0); |
620 | |
621 | bytes = g_resources_lookup_data (path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); |
622 | g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "egg-toolbars-model.c" , 622, ((const char*) (__func__)), "error", error, 0, 0); } while (0); |
623 | |
624 | data = g_bytes_get_data (bytes, &data_len); |
625 | doc = xmlParseMemory ((const char *) data, data_len); |
626 | if (doc == NULL((void*)0)) |
627 | g_error ("Failed to load XML data from resource %s", path); |
628 | |
629 | root = xmlDocGetRootElement (doc); |
630 | parse_toolbars (model, root->children); |
631 | |
632 | xmlFreeDoc (doc); |
633 | g_bytes_unref (bytes); |
634 | |
635 | return TRUE(!(0)); |
636 | } |
637 | |
638 | static void |
639 | parse_available_list (EggToolbarsModel *model, |
640 | xmlNodePtr child) |
641 | { |
642 | gint flags; |
643 | |
644 | while (child) |
645 | { |
646 | if (xmlStrEqual (child->name, (const xmlChar*) "toolitem")) |
647 | { |
648 | xmlChar *name; |
649 | |
650 | name = xmlGetProp (child, (const xmlChar*) "name"); |
651 | flags = egg_toolbars_model_get_name_flags |
652 | (model, (const char*)name); |
653 | egg_toolbars_model_set_name_flags |
654 | (model, (const char*)name, flags | EGG_TB_MODEL_NAME_KNOWN); |
655 | xmlFree (name); |
656 | } |
657 | child = child->next; |
658 | } |
659 | } |
660 | |
661 | static void |
662 | parse_names (EggToolbarsModel *model, |
663 | xmlNodePtr child) |
664 | { |
665 | while (child) |
666 | { |
667 | if (xmlStrEqual (child->name, (const xmlChar*) "available")) |
668 | { |
669 | parse_available_list (model, child->children); |
670 | } |
671 | |
672 | child = child->next; |
673 | } |
674 | } |
675 | |
676 | gboolean |
677 | egg_toolbars_model_load_names (EggToolbarsModel *model, |
678 | const char *xml_file) |
679 | { |
680 | xmlDocPtr doc; |
681 | xmlNodePtr root; |
682 | |
683 | g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ((0)); } } while (0); |
684 | |
685 | if (!xml_file || !g_file_test (xml_file, G_FILE_TEST_EXISTS)) return FALSE(0); |
686 | |
687 | doc = xmlParseFile (xml_file); |
688 | if (doc == NULL((void*)0)) |
689 | { |
690 | g_warning ("Failed to load XML data from %s", xml_file); |
691 | return FALSE(0); |
692 | } |
693 | root = xmlDocGetRootElement (doc); |
694 | |
695 | parse_names (model, root->children); |
696 | |
697 | xmlFreeDoc (doc); |
698 | |
699 | return TRUE(!(0)); |
700 | } |
701 | |
702 | gboolean |
703 | egg_toolbars_model_load_names_from_resource (EggToolbarsModel *model, |
704 | const char *path) |
705 | { |
706 | xmlDocPtr doc; |
707 | xmlNodePtr root; |
708 | GBytes *bytes; |
709 | GError *error = NULL((void*)0); |
710 | const guint8 *data; |
711 | gsize data_len; |
712 | |
713 | g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ((0)); } } while (0); |
714 | |
715 | bytes = g_resources_lookup_data (path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error); |
716 | g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "egg-toolbars-model.c" , 716, ((const char*) (__func__)), "error", error, 0, 0); } while (0); |
717 | |
718 | data = g_bytes_get_data (bytes, &data_len); |
719 | doc = xmlParseMemory ((const char *) data, data_len); |
720 | if (doc == NULL((void*)0)) |
721 | g_error ("Failed to load XML data from resource %s", path); |
722 | |
723 | root = xmlDocGetRootElement (doc); |
724 | parse_names (model, root->children); |
725 | |
726 | xmlFreeDoc (doc); |
727 | g_bytes_unref (bytes); |
728 | |
729 | return TRUE(!(0)); |
730 | } |
731 | |
732 | static void |
733 | egg_toolbars_model_class_init (EggToolbarsModelClass *klass) |
734 | { |
735 | GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); |
736 | |
737 | /* make sure the flags type is known */ |
738 | g_type_ensure (EGG_TYPE_TB_MODEL_FLAGSegg_tb_model_flags_get_type()); |
739 | |
740 | object_class->finalize = egg_toolbars_model_finalize; |
741 | |
742 | klass->add_item = impl_add_item; |
743 | |
744 | signals[ITEM_ADDED] = |
745 | g_signal_new ("item_added", |
746 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), |
747 | G_SIGNAL_RUN_LAST, |
748 | G_STRUCT_OFFSET (EggToolbarsModelClass, item_added)((glong) __builtin_offsetof(EggToolbarsModelClass, item_added )), |
749 | NULL((void*)0), NULL((void*)0), _egg_marshal_VOID__INT_INT, |
750 | G_TYPE_NONE((GType) ((1) << (2))), 2, G_TYPE_INT((GType) ((6) << (2))), G_TYPE_INT((GType) ((6) << (2)))); |
751 | signals[TOOLBAR_ADDED] = |
752 | g_signal_new ("toolbar_added", |
753 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), |
754 | G_SIGNAL_RUN_LAST, |
755 | G_STRUCT_OFFSET (EggToolbarsModelClass, toolbar_added)((glong) __builtin_offsetof(EggToolbarsModelClass, toolbar_added )), |
756 | NULL((void*)0), NULL((void*)0), g_cclosure_marshal_VOID__INT, |
757 | G_TYPE_NONE((GType) ((1) << (2))), 1, G_TYPE_INT((GType) ((6) << (2)))); |
758 | signals[ITEM_REMOVED] = |
759 | g_signal_new ("item_removed", |
760 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), |
761 | G_SIGNAL_RUN_LAST, |
762 | G_STRUCT_OFFSET (EggToolbarsModelClass, item_removed)((glong) __builtin_offsetof(EggToolbarsModelClass, item_removed )), |
763 | NULL((void*)0), NULL((void*)0), _egg_marshal_VOID__INT_INT, |
764 | G_TYPE_NONE((GType) ((1) << (2))), 2, G_TYPE_INT((GType) ((6) << (2))), G_TYPE_INT((GType) ((6) << (2)))); |
765 | signals[TOOLBAR_REMOVED] = |
766 | g_signal_new ("toolbar_removed", |
767 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), |
768 | G_SIGNAL_RUN_LAST, |
769 | G_STRUCT_OFFSET (EggToolbarsModelClass, toolbar_removed)((glong) __builtin_offsetof(EggToolbarsModelClass, toolbar_removed )), |
770 | NULL((void*)0), NULL((void*)0), g_cclosure_marshal_VOID__INT, |
771 | G_TYPE_NONE((GType) ((1) << (2))), 1, G_TYPE_INT((GType) ((6) << (2)))); |
772 | signals[TOOLBAR_CHANGED] = |
773 | g_signal_new ("toolbar_changed", |
774 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), |
775 | G_SIGNAL_RUN_LAST, |
776 | G_STRUCT_OFFSET (EggToolbarsModelClass, toolbar_changed)((glong) __builtin_offsetof(EggToolbarsModelClass, toolbar_changed )), |
777 | NULL((void*)0), NULL((void*)0), g_cclosure_marshal_VOID__INT, |
778 | G_TYPE_NONE((GType) ((1) << (2))), 1, G_TYPE_INT((GType) ((6) << (2)))); |
779 | } |
780 | |
781 | static void |
782 | egg_toolbars_model_init (EggToolbarsModel *model) |
783 | { |
784 | model->priv =egg_toolbars_model_get_instance_private (model); |
785 | |
786 | model->priv->toolbars = g_node_new (NULL((void*)0)); |
787 | model->priv->flags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL((void*)0)); |
788 | egg_toolbars_model_set_name_flags (model, "_separator", |
789 | EGG_TB_MODEL_NAME_KNOWN | |
790 | EGG_TB_MODEL_NAME_INFINITE); |
791 | } |
792 | |
793 | static void |
794 | egg_toolbars_model_finalize (GObject *object) |
795 | { |
796 | EggToolbarsModel *model = EGG_TOOLBARS_MODEL (object)((((EggToolbarsModel*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((object)), ((egg_toolbars_model_get_type ()) ))))); |
797 | |
798 | g_node_children_foreach (model->priv->toolbars, G_TRAVERSE_ALL, |
799 | (GNodeForeachFunc) toolbar_node_free, model); |
800 | g_node_destroy (model->priv->toolbars); |
801 | g_hash_table_destroy (model->priv->flags); |
802 | |
803 | G_OBJECT_CLASS (egg_toolbars_model_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((egg_toolbars_model_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); |
804 | } |
805 | |
806 | EggToolbarsModel * |
807 | egg_toolbars_model_new (void) |
808 | { |
809 | return EGG_TOOLBARS_MODEL (g_object_new (EGG_TYPE_TOOLBARS_MODEL, NULL))((((EggToolbarsModel*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((g_object_new ((egg_toolbars_model_get_type ( )), ((void*)0)))), ((egg_toolbars_model_get_type ())))))); |
810 | } |
811 | |
812 | void |
813 | egg_toolbars_model_remove_toolbar (EggToolbarsModel *model, |
814 | int position) |
815 | { |
816 | GNode *node; |
817 | EggTbModelFlags flags; |
818 | |
819 | g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ; } } while (0); |
820 | |
821 | flags = egg_toolbars_model_get_flags (model, position); |
822 | |
823 | if (!(flags & EGG_TB_MODEL_NOT_REMOVABLE)) |
824 | { |
825 | node = g_node_nth_child (model->priv->toolbars, position); |
826 | g_return_if_fail (node != NULL)do { if ((node != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "node != NULL"); return ; } } while (0); |
827 | |
828 | toolbar_node_free (node, model); |
829 | |
830 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), signals[TOOLBAR_REMOVED], |
831 | 0, position); |
832 | } |
833 | } |
834 | |
835 | void |
836 | egg_toolbars_model_remove_item (EggToolbarsModel *model, |
837 | int toolbar_position, |
838 | int position) |
839 | { |
840 | GNode *node, *toolbar; |
841 | |
842 | g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ; } } while (0); |
843 | |
844 | toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); |
845 | g_return_if_fail (toolbar != NULL)do { if ((toolbar != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "toolbar != NULL" ); return; } } while (0); |
846 | |
847 | node = g_node_nth_child (toolbar, position); |
848 | g_return_if_fail (node != NULL)do { if ((node != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "node != NULL"); return ; } } while (0); |
849 | |
850 | item_node_free (node, model); |
851 | |
852 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), signals[ITEM_REMOVED], 0, |
853 | toolbar_position, position); |
854 | } |
855 | |
856 | void |
857 | egg_toolbars_model_move_item (EggToolbarsModel *model, |
858 | int toolbar_position, |
859 | int position, |
860 | int new_toolbar_position, |
861 | int new_position) |
862 | { |
863 | GNode *node, *toolbar, *new_toolbar; |
864 | |
865 | g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ; } } while (0); |
866 | |
867 | toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); |
868 | g_return_if_fail (toolbar != NULL)do { if ((toolbar != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "toolbar != NULL" ); return; } } while (0); |
869 | |
870 | new_toolbar = g_node_nth_child (model->priv->toolbars, new_toolbar_position); |
871 | g_return_if_fail (new_toolbar != NULL)do { if ((new_toolbar != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "new_toolbar != NULL" ); return; } } while (0); |
872 | |
873 | node = g_node_nth_child (toolbar, position); |
874 | g_return_if_fail (node != NULL)do { if ((node != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "node != NULL"); return ; } } while (0); |
875 | |
876 | g_node_unlink (node); |
877 | |
878 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), signals[ITEM_REMOVED], 0, |
879 | toolbar_position, position); |
880 | |
881 | g_node_insert (new_toolbar, new_position, node); |
882 | |
883 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), signals[ITEM_ADDED], 0, |
884 | new_toolbar_position, new_position); |
885 | } |
886 | |
887 | void |
888 | egg_toolbars_model_delete_item (EggToolbarsModel *model, |
889 | const char *name) |
890 | { |
891 | EggToolbarsItem *idata; |
892 | EggToolbarsToolbar *tdata; |
893 | GNode *toolbar, *item, *next; |
894 | int tpos, ipos; |
895 | |
896 | g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((model)); GType __t = ((egg_toolbars_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "EGG_IS_TOOLBARS_MODEL (model)"); return ; } } while (0); |
897 | |
898 | toolbar = g_node_first_child (model->priv->toolbars)((model->priv->toolbars) ? ((GNode*) (model->priv-> toolbars))->children : ((void*)0)); |
899 | tpos = 0; |
900 | |
901 | while (toolbar != NULL((void*)0)) |
902 | { |
903 | item = g_node_first_child (toolbar)((toolbar) ? ((GNode*) (toolbar))->children : ((void*)0)); |
904 | ipos = 0; |
905 | |
906 | /* Don't delete toolbars that were already empty */ |
907 | if (item == NULL((void*)0)) |
908 | { |
909 | toolbar = g_node_next_sibling (toolbar)((toolbar) ? ((GNode*) (toolbar))->next : ((void*)0)); |
910 | continue; |
911 | } |
912 | |
913 | while (item != NULL((void*)0)) |
914 | { |
915 | next = g_node_next_sibling (item)((item) ? ((GNode*) (item))->next : ((void*)0)); |
916 | idata = item->data; |
917 | if (strcmp (idata->name, name) == 0) |
918 | { |
919 | item_node_free (item, model); |
920 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), |
921 | signals[ITEM_REMOVED], |
922 | 0, tpos, ipos); |
923 | } |
924 | else |
925 | { |
926 | ipos++; |
927 | } |
928 | |
929 | item = next; |
930 | } |
931 | |
932 | next = g_node_next_sibling (toolbar)((toolbar) ? ((GNode*) (toolbar))->next : ((void*)0)); |
933 | tdata = toolbar->data; |
934 | if (!(tdata->flags & EGG_TB_MODEL_NOT_REMOVABLE) && |
935 | g_node_first_child (toolbar)((toolbar) ? ((GNode*) (toolbar))->children : ((void*)0)) == NULL((void*)0)) |
936 | { |
937 | toolbar_node_free (toolbar, model); |
938 | |
939 | g_signal_emit (G_OBJECT (model)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((model)), (((GType) ((20) << (2)))))))), |
940 | signals[TOOLBAR_REMOVED], |
941 | 0, tpos); |
942 | } |
943 | else |
944 | { |
945 | tpos++; |
946 | } |
947 | |
948 | toolbar = next; |
949 | } |
950 | } |
951 | |
952 | int |
953 | egg_toolbars_model_n_items (EggToolbarsModel *model, |
954 | int toolbar_position) |
955 | { |
956 | GNode *toolbar; |
957 | |
958 | toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); |
959 | g_return_val_if_fail (toolbar != NULL, -1)do { if ((toolbar != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "toolbar != NULL" ); return (-1); } } while (0); |
960 | |
961 | return g_node_n_children (toolbar); |
962 | } |
963 | |
964 | const char * |
965 | egg_toolbars_model_item_nth (EggToolbarsModel *model, |
966 | int toolbar_position, |
967 | int position) |
968 | { |
969 | GNode *toolbar; |
970 | GNode *item; |
971 | EggToolbarsItem *idata; |
972 | |
973 | toolbar = g_node_nth_child (model->priv->toolbars, toolbar_position); |
974 | g_return_val_if_fail (toolbar != NULL, NULL)do { if ((toolbar != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "toolbar != NULL" ); return (((void*)0)); } } while (0); |
975 | |
976 | item = g_node_nth_child (toolbar, position); |
977 | g_return_val_if_fail (item != NULL, NULL)do { if ((item != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "item != NULL"); return (((void*)0)); } } while (0); |
978 | |
979 | idata = item->data; |
980 | return idata->name; |
981 | } |
982 | |
983 | int |
984 | egg_toolbars_model_n_toolbars (EggToolbarsModel *model) |
985 | { |
986 | return g_node_n_children (model->priv->toolbars); |
987 | } |
988 | |
989 | const char * |
990 | egg_toolbars_model_toolbar_nth (EggToolbarsModel *model, |
991 | int position) |
992 | { |
993 | GNode *toolbar; |
994 | EggToolbarsToolbar *tdata; |
995 | |
996 | toolbar = g_node_nth_child (model->priv->toolbars, position); |
997 | g_return_val_if_fail (toolbar != NULL, NULL)do { if ((toolbar != ((void*)0))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const char*) (__func__)), "toolbar != NULL" ); return (((void*)0)); } } while (0); |
998 | |
999 | tdata = toolbar->data; |
1000 | |
1001 | return tdata->name; |
1002 | } |
1003 | |
1004 | /** |
1005 | * egg_toolbars_model_get_types: |
1006 | * @model: |
1007 | * |
1008 | * Returns: (transfer none) (element-type EggToolbarsItemType): |
1009 | */ |
1010 | GList * |
1011 | egg_toolbars_model_get_types (EggToolbarsModel *model) |
1012 | { |
1013 | return model->priv->types; |
1014 | } |
1015 | |
1016 | /** |
1017 | * egg_toolbars_model_set_types: |
1018 | * @model: |
1019 | * @types: (element-type EggToolbarsItemType): |
1020 | * |
1021 | */ |
1022 | void |
1023 | egg_toolbars_model_set_types (EggToolbarsModel *model, GList *types) |
1024 | { |
1025 | model->priv->types = types; |
1026 | } |
1027 | |
1028 | static void |
1029 | fill_avail_array (gpointer key, gpointer value, GPtrArray *array) |
1030 | { |
1031 | int flags = GPOINTER_TO_INT (value)((gint) (glong) (value)); |
1032 | if ((flags & EGG_TB_MODEL_NAME_KNOWN) && !(flags & EGG_TB_MODEL_NAME_USED)) |
1033 | g_ptr_array_add (array, key); |
1034 | } |
1035 | |
1036 | /** |
1037 | * egg_toolbars_model_get_name_avail: |
1038 | * @model: |
1039 | * |
1040 | * Returns: (element-type utf8) (transfer container): |
1041 | */ |
1042 | GPtrArray * |
1043 | egg_toolbars_model_get_name_avail (EggToolbarsModel *model) |
1044 | { |
1045 | GPtrArray *array = g_ptr_array_new (); |
1046 | g_hash_table_foreach (model->priv->flags, (GHFunc) fill_avail_array, array); |
1047 | return array; |
1048 | } |
1049 | |
1050 | gint |
1051 | egg_toolbars_model_get_name_flags (EggToolbarsModel *model, const char *name) |
1052 | { |
1053 | return GPOINTER_TO_INT (g_hash_table_lookup (model->priv->flags, name))((gint) (glong) (g_hash_table_lookup (model->priv->flags , name))); |
1054 | } |
1055 | |
1056 | void |
1057 | egg_toolbars_model_set_name_flags (EggToolbarsModel *model, const char *name, gint flags) |
1058 | { |
1059 | g_hash_table_insert (model->priv->flags, g_strdup (name)g_strdup_inline (name), GINT_TO_POINTER (flags)((gpointer) (glong) (flags))); |
1060 | } |