diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-07-27 21:10:56 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-07-27 21:10:56 +0800 |
commit | d1f38adb951f506e11864f0784f325a940a3d232 (patch) | |
tree | d58f9243e7c3926ac2840edb05797fbbe75e1de6 /lib/egg/egg-toolbars-model.c | |
parent | e9f8e15bf4f624f566eb0ea66e47be67098d5dc2 (diff) | |
download | gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.gz gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.bz2 gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.lz gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.xz gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.tar.zst gsoc2013-epiphany-d1f38adb951f506e11864f0784f325a940a3d232.zip |
2003-07-27 Marco Pesenti Gritti <marco@it.gnome.org>
* data/ui/epiphany-toolbar.xml.in:
* lib/egg/egg-editable-toolbar.c: (drag_data_received_cb):
* lib/egg/egg-editable-toolbar.h:
* lib/egg/egg-toolbar-editor.c: (parse_item_list):
* lib/egg/egg-toolbars-model.c: (egg_toolbars_model_to_xml),
(safe_save_xml), (egg_toolbars_model_save), (toolbars_item_new),
(free_item_node), (egg_toolbars_model_add_separator),
(egg_toolbars_model_add_item), (parse_item_list),
(impl_get_item_id), (impl_get_item_name), (impl_get_item_type),
(egg_toolbars_model_class_init), (egg_toolbars_model_item_nth),
(egg_toolbars_model_toolbar_nth), (egg_toolbars_model_get_item_id),
(egg_toolbars_model_get_item_name),
(egg_toolbars_model_get_item_type):
* lib/egg/egg-toolbars-model.h:
* lib/egg/eggtoolbar.c: (egg_toolbar_finalize):
* lib/ephy-dnd.c: (add_one_topic), (ephy_dnd_drag_data_get):
* lib/ephy-dnd.h:
* lib/widgets/ephy-node-view.c: (drag_data_received_cb),
(ephy_node_view_select_node_by_key), (ephy_node_view_construct),
(ephy_node_view_add_data_column),
(ephy_node_view_enable_drag_source):
* lib/widgets/ephy-node-view.h:
* lib/widgets/ephy-tree-model-sort.c:
(ephy_tree_model_sort_class_init), (ephy_tree_model_sort_init),
(ephy_tree_model_sort_multi_row_draggable),
(ephy_tree_model_sort_set_column_id),
(each_property_get_data_binder),
(ephy_tree_model_sort_multi_drag_data_get):
* lib/widgets/ephy-tree-model-sort.h:
* src/bookmarks/ephy-bookmark-properties.c:
(toolbar_checkbox_changed_cb), (build_ui):
* src/bookmarks/ephy-bookmarks-editor.c:
(cmd_show_in_bookmarks_bar), (ephy_bookmarks_editor_update_menu),
(node_dropped_cb), (provide_keyword_uri),
(ephy_bookmarks_editor_construct):
* src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init_defaults),
(ephy_bookmarks_remove_keyword), (ephy_bookmarks_get_topic_uri),
(ephy_bookmarks_find_keyword):
* src/bookmarks/ephy-bookmarks.h:
* src/ephy-history-window.c: (ephy_history_window_construct):
* src/ephy-toolbars-model.c: (ephy_toolbars_model_get_action_name),
(ephy_toolbars_model_get_node), (bookmark_destroy_cb),
(impl_get_item_name), (impl_get_item_id), (impl_get_item_type),
(connect_item), (ephy_toolbars_model_set_bookmarks),
(ephy_toolbars_model_class_init), (save_changes), (item_added),
(item_removed), (toolbar_added), (toolbar_removed),
(ephy_toolbars_model_init), (ephy_toolbars_model_finalize),
(ephy_toolbars_model_remove_bookmark),
Diffstat (limited to 'lib/egg/egg-toolbars-model.c')
-rwxr-xr-x | lib/egg/egg-toolbars-model.c | 210 |
1 files changed, 175 insertions, 35 deletions
diff --git a/lib/egg/egg-toolbars-model.c b/lib/egg/egg-toolbars-model.c index 8d8829dcf..e030bd29d 100755 --- a/lib/egg/egg-toolbars-model.c +++ b/lib/egg/egg-toolbars-model.c @@ -21,6 +21,7 @@ #include <string.h> #include <libxml/tree.h> +#include <gdk/gdkproperty.h> static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass); static void egg_toolbars_model_init (EggToolbarsModel *t); @@ -44,7 +45,8 @@ typedef struct typedef struct { - char *action_name; + char *id; + char *type; gboolean separator; } EggToolbarsItem; @@ -118,8 +120,12 @@ egg_toolbars_model_to_xml (EggToolbarsModel *t) } else { + char *name; + node = xmlNewChild (tnode, NULL, "toolitem", NULL); - xmlSetProp (node, "verb", item->action_name); + name = egg_toolbars_model_get_item_name (t, item->type, item->id); + xmlSetProp (node, "type", item->type); + xmlSetProp (node, "name", name); } } } @@ -127,16 +133,76 @@ egg_toolbars_model_to_xml (EggToolbarsModel *t) return doc; } +gboolean +safe_save_xml (const char *xml_file, xmlDocPtr doc) +{ + char *tmp_file; + char *old_file; + gboolean old_exist; + gboolean retval = TRUE; + + tmp_file = g_strconcat (xml_file, ".tmp", NULL); + old_file = g_strconcat (xml_file, ".old", NULL); + + if (!xmlSaveFormatFile (tmp_file, doc, 1)) + { + g_warning ("Failed to write XML data to %s", tmp_file); + goto failed; + } + + old_exist = g_file_test (xml_file, G_FILE_TEST_EXISTS); + + if (old_exist) + { + if (rename (xml_file, old_file) < 0) + { + g_warning ("Failed to rename %s to %s", xml_file, old_file); + retval = FALSE; + goto failed; + } + } + + if (rename (tmp_file, xml_file) < 0) + { + g_warning ("Failed to rename %s to %s", tmp_file, xml_file); + + if (rename (old_file, xml_file) < 0) + { + g_warning ("Failed to restore %s from %s", xml_file, tmp_file); + } + retval = FALSE; + goto failed; + } + + if (old_exist) + { + if (unlink (old_file) < 0) + { + g_warning ("Failed to delete old file %s", old_file); + } + } + + failed: + g_free (old_file); + g_free (tmp_file); + + return retval; +} + void egg_toolbars_model_save (EggToolbarsModel *t, - const char *xml_file) + const char *xml_file, + const char *version) { xmlDocPtr doc; + xmlNodePtr root; g_return_if_fail (IS_EGG_TOOLBARS_MODEL (t)); doc = egg_toolbars_model_to_xml (t); - xmlSaveFormatFile (xml_file, doc, 1); + root = xmlDocGetRootElement (doc); + xmlSetProp (root, "version", version); + safe_save_xml (xml_file, doc); xmlFreeDoc (doc); } @@ -153,15 +219,18 @@ toolbars_toolbar_new (const char *name) } static EggToolbarsItem * -toolbars_item_new (const char *action, +toolbars_item_new (const char *id, + const char *type, gboolean separator) { EggToolbarsItem *item; - g_return_val_if_fail (action != NULL, NULL); + g_return_val_if_fail (id != NULL, NULL); + g_return_val_if_fail (type != NULL, NULL); item = g_new0 (EggToolbarsItem, 1); - item->action_name = g_strdup (action); + item->id = g_strdup (id); + item->type = g_strdup (type); item->separator = separator; return item; @@ -181,7 +250,8 @@ free_item_node (EggToolbarsItem *item) { g_return_if_fail (item != NULL); - g_free (item->action_name); + g_free (item->id); + g_free (item->type); g_free (item); } @@ -227,46 +297,39 @@ egg_toolbars_model_add_separator (EggToolbarsModel *t, GNode *parent_node; GNode *node; EggToolbarsItem *item; + int real_position; g_return_if_fail (IS_EGG_TOOLBARS_MODEL (t)); parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position); - item = toolbars_item_new ("separator", TRUE); + item = toolbars_item_new ("separator", "separator", TRUE); node = g_node_new (item); g_node_insert (parent_node, position, node); + real_position = g_node_child_position (parent_node, node); + g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_ADDED], 0, - toolbar_position, position); + toolbar_position, real_position); } -const char * +void egg_toolbars_model_add_item (EggToolbarsModel *t, int toolbar_position, int position, - GdkAtom type, - const char *name) -{ - EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); - return klass->add_item (t, toolbar_position, position, type, name); -} - -const char * -impl_add_item (EggToolbarsModel *t, - int toolbar_position, - int position, - GdkAtom type, - const char *name) + const char *id, + const char *type) { GNode *parent_node; GNode *node; EggToolbarsItem *item; int real_position; - g_return_val_if_fail (IS_EGG_TOOLBARS_MODEL (t), NULL); - g_return_val_if_fail (name != NULL, NULL); + g_return_if_fail (IS_EGG_TOOLBARS_MODEL (t)); + g_return_if_fail (id != NULL); + g_return_if_fail (type != NULL); parent_node = g_node_nth_child (t->priv->toolbars, toolbar_position); - item = toolbars_item_new (name, FALSE); + item = toolbars_item_new (id, type, FALSE); node = g_node_new (item); g_node_insert (parent_node, position, node); @@ -274,8 +337,6 @@ impl_add_item (EggToolbarsModel *t, g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_ADDED], 0, toolbar_position, real_position); - - return item->action_name; } static void @@ -287,11 +348,24 @@ parse_item_list (EggToolbarsModel *t, { if (xmlStrEqual (child->name, "toolitem")) { - xmlChar *verb; + xmlChar *name, *type; + char *id; - verb = xmlGetProp (child, "verb"); - egg_toolbars_model_add_item (t, position, -1, NULL, verb); - xmlFree (verb); + name = xmlGetProp (child, "name"); + type = xmlGetProp (child, "type"); + if (type == NULL) + { + type = g_strdup (EGG_TOOLBAR_ITEM_TYPE); + } + + id = egg_toolbars_model_get_item_id (t, type, name); + if (id != NULL) + { + egg_toolbars_model_add_item (t, position, -1, id, type); + } + xmlFree (name); + g_free (type); + g_free (id); } else if (xmlStrEqual (child->name, "separator")) { @@ -363,6 +437,44 @@ egg_toolbars_model_load (EggToolbarsModel *t, xmlFreeDoc (doc); } +char * +impl_get_item_id (EggToolbarsModel *t, + const char *type, + const char *name) +{ + if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) + { + return g_strdup (name); + } + + return NULL; +} + +char * +impl_get_item_name (EggToolbarsModel *t, + const char *type, + const char *id) +{ + if (strcmp (type, EGG_TOOLBAR_ITEM_TYPE) == 0) + { + return g_strdup (id); + } + + return NULL; +} + +char * +impl_get_item_type (EggToolbarsModel *t, + GdkAtom type) +{ + if (gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE) == type) + { + return g_strdup (EGG_TOOLBAR_ITEM_TYPE); + } + + return NULL; +} + static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass) { @@ -372,7 +484,9 @@ egg_toolbars_model_class_init (EggToolbarsModelClass *klass) object_class->finalize = egg_toolbars_model_finalize; - klass->add_item = impl_add_item; + klass->get_item_id = impl_get_item_id; + klass->get_item_name = impl_get_item_name; + klass->get_item_type = impl_get_item_type; egg_toolbars_model_signals[ITEM_ADDED] = g_signal_new ("item_added", @@ -525,7 +639,7 @@ egg_toolbars_model_item_nth (EggToolbarsModel *t, *is_separator = idata->separator; - return idata->action_name; + return idata->id; } int @@ -548,3 +662,29 @@ egg_toolbars_model_toolbar_nth (EggToolbarsModel *t, return tdata->name; } + +char * +egg_toolbars_model_get_item_id (EggToolbarsModel *t, + const char *type, + const char *name) +{ + EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); + return klass->get_item_id (t, type, name); +} + +char * +egg_toolbars_model_get_item_name (EggToolbarsModel *t, + const char *type, + const char *id) +{ + EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); + return klass->get_item_name (t, type, id); +} + +char * +egg_toolbars_model_get_item_type (EggToolbarsModel *t, + GdkAtom type) +{ + EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); + return klass->get_item_type (t, type); +} |