diff options
Diffstat (limited to 'lib/egg')
-rwxr-xr-x | lib/egg/egg-editable-toolbar.c | 10 | ||||
-rwxr-xr-x | lib/egg/egg-editable-toolbar.h | 2 | ||||
-rwxr-xr-x | lib/egg/egg-toolbar-editor.c | 8 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.c | 210 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.h | 35 | ||||
-rw-r--r-- | lib/egg/eggtoolbar.c | 1 |
6 files changed, 211 insertions, 55 deletions
diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c index 81a7c1a58..2fc401cde 100755 --- a/lib/egg/egg-editable-toolbar.c +++ b/lib/egg/egg-editable-toolbar.c @@ -180,11 +180,17 @@ drag_data_received_cb (GtkWidget *widget, else { GdkAtom target; + char *type; + char *id; target = gtk_drag_dest_find_target (widget, context, NULL); + type = egg_toolbars_model_get_item_type (etoolbar->priv->model, target); + id = egg_toolbars_model_get_item_id (etoolbar->priv->model, type, + selection_data->data); egg_toolbars_model_add_item (etoolbar->priv->model, - toolbar_pos, pos, target, - selection_data->data); + toolbar_pos, pos, id, type); + g_free (type); + g_free (id); } } diff --git a/lib/egg/egg-editable-toolbar.h b/lib/egg/egg-editable-toolbar.h index 28b9976a2..6460d724a 100755 --- a/lib/egg/egg-editable-toolbar.h +++ b/lib/egg/egg-editable-toolbar.h @@ -39,8 +39,6 @@ typedef struct EggEditableToolbarClass EggEditableToolbarClass; typedef struct EggEditableToolbar EggEditableToolbar; typedef struct EggEditableToolbarPrivate EggEditableToolbarPrivate; -#define EGG_TOOLBAR_ITEM_TYPE "application/x-toolbar-item" - struct EggEditableToolbar { GtkVBox parent_object; diff --git a/lib/egg/egg-toolbar-editor.c b/lib/egg/egg-toolbar-editor.c index a373b520c..2813d992b 100755 --- a/lib/egg/egg-toolbar-editor.c +++ b/lib/egg/egg-toolbar-editor.c @@ -494,11 +494,11 @@ parse_item_list (EggToolbarEditor *t, { if (xmlStrEqual (child->name, "toolitem")) { - xmlChar *verb; + xmlChar *name; - verb = xmlGetProp (child, "verb"); - egg_toolbar_editor_add_action (t, verb); - xmlFree (verb); + name = xmlGetProp (child, "name"); + egg_toolbar_editor_add_action (t, name); + xmlFree (name); } child = child->next; } 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); +} diff --git a/lib/egg/egg-toolbars-model.h b/lib/egg/egg-toolbars-model.h index 5d79787b9..5de72fbcb 100755 --- a/lib/egg/egg-toolbars-model.h +++ b/lib/egg/egg-toolbars-model.h @@ -21,7 +21,7 @@ #include <glib.h> #include <glib-object.h> -#include "gdk/gdktypes.h" +#include <gdk/gdktypes.h> G_BEGIN_DECLS @@ -37,6 +37,8 @@ typedef struct EggToolbarsModelClass EggToolbarsModelClass; typedef struct EggToolbarsModel EggToolbarsModel; typedef struct EggToolbarsModelPrivate EggToolbarsModelPrivate; +#define EGG_TOOLBAR_ITEM_TYPE "application/x-toolbar-item" + typedef enum { EGG_TB_MODEL_NOT_REMOVABLE = 1, @@ -68,12 +70,14 @@ struct EggToolbarsModelClass int position); /* Virtual Table */ - const char * (* add_item) (EggToolbarsModel *t, - int toolbar_position, - int position, - GdkAtom type, - const char *item_name); - + char * (* get_item_type) (EggToolbarsModel *t, + GdkAtom dnd_type); + char * (* get_item_id) (EggToolbarsModel *t, + const char *type, + const char *name); + char * (* get_item_name) (EggToolbarsModel *t, + const char *type, + const char *id); }; GType egg_toolbars_model_get_type (void); @@ -81,7 +85,8 @@ EggToolbarsModel *egg_toolbars_model_new (void); void egg_toolbars_model_load (EggToolbarsModel *t, const char *xml_file); void egg_toolbars_model_save (EggToolbarsModel *t, - const char *xml_file); + const char *xml_file, + const char *version); int egg_toolbars_model_add_toolbar (EggToolbarsModel *t, int position, const char *name); @@ -93,11 +98,19 @@ void egg_toolbars_model_set_flags (EggToolbarsModel *t, void egg_toolbars_model_add_separator (EggToolbarsModel *t, int toolbar_position, int position); -const char *egg_toolbars_model_add_item (EggToolbarsModel *t, +char *egg_toolbars_model_get_item_type (EggToolbarsModel *t, + GdkAtom dnd_type); +char *egg_toolbars_model_get_item_id (EggToolbarsModel *t, + const char *type, + const char *name); +char *egg_toolbars_model_get_item_name (EggToolbarsModel *t, + const char *type, + const char *id); +void egg_toolbars_model_add_item (EggToolbarsModel *t, int toolbar_position, int position, - GdkAtom type, - const char *item_name); + const char *id, + const char *type); void egg_toolbars_model_remove_toolbar (EggToolbarsModel *t, int position); void egg_toolbars_model_remove_item (EggToolbarsModel *t, diff --git a/lib/egg/eggtoolbar.c b/lib/egg/eggtoolbar.c index bae64f324..547f0e33c 100644 --- a/lib/egg/eggtoolbar.c +++ b/lib/egg/eggtoolbar.c @@ -494,7 +494,6 @@ static void egg_toolbar_finalize (GObject *object) { EggToolbar *toolbar = EGG_TOOLBAR (object); - GList *list; if (toolbar->tooltips) g_object_unref (GTK_OBJECT (toolbar->tooltips)); |