*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id$
*/
#include <unistd.h>
#include <string.h>
#include <libxml/tree.h>
-#include <gdk/gdkproperty.h>
+#include <gdk/gdk.h>
-static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass);
-static void egg_toolbars_model_init (EggToolbarsModel *model);
static void egg_toolbars_model_finalize (GObject *object);
enum
static guint signals[LAST_SIGNAL] = { 0 };
-static GObjectClass *parent_class = NULL;
-
#define EGG_TOOLBARS_MODEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_TOOLBARS_MODEL, EggToolbarsModelPrivate))
struct EggToolbarsModelPrivate
GHashTable *flags;
};
-GType
-egg_toolbars_model_get_type (void)
-{
- static GType type = 0;
-
- if (G_UNLIKELY (type == 0))
- {
- const GTypeInfo our_info = {
- sizeof (EggToolbarsModelClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) egg_toolbars_model_class_init,
- NULL,
- NULL, /* class_data */
- sizeof (EggToolbarsModel),
- 0, /* n_preallocs */
- (GInstanceInitFunc) egg_toolbars_model_init
- };
- volatile GType flags_type; /* work around gcc's optimiser */
-
- /* make sure the flags type is known */
- flags_type = EGG_TYPE_TB_MODEL_FLAGS;
-
- type = g_type_register_static (G_TYPE_OBJECT,
- "EggToolbarsModel",
- &our_info, 0);
- }
-
- return type;
-}
+G_DEFINE_TYPE (EggToolbarsModel, egg_toolbars_model, G_TYPE_OBJECT)
static xmlDocPtr
egg_toolbars_model_to_xml (EggToolbarsModel *model)
node = xmlNewChild (tnode, NULL, (const xmlChar*) "separator", NULL);
continue;
}
-
+
node = xmlNewChild (tnode, NULL, (const xmlChar*) "toolitem", NULL);
xmlSetProp (node, (const xmlChar*) "name", (const xmlChar*) item->name);
{
xmlNodePtr dnode;
char *tmp;
-
+
tmp = type->get_data (type, item->name);
if (tmp != NULL)
{
dnode = xmlNewTextChild (node, NULL, (const xmlChar*) "data", (const xmlChar*) tmp);
g_free (tmp);
-
+
tmp = gdk_atom_name (type->type);
xmlSetProp (dnode, (const xmlChar*) "type", (const xmlChar*) tmp);
g_free (tmp);
{
EggToolbarsItem *idata2;
GNode *toolbar, *item;
-
-
+
+
for(toolbar = g_node_first_child (model->priv->toolbars);
toolbar != NULL; toolbar = g_node_next_sibling (toolbar))
{
item != NULL; item = g_node_next_sibling (item))
{
idata2 = item->data;
-
+
if (idata != idata2 && strcmp (idata->name, idata2->name) == 0)
{
return FALSE;
}
}
}
-
+
return TRUE;
}
g_node_children_foreach (toolbar_node, G_TRAVERSE_ALL,
(GNodeForeachFunc) item_node_free, model);
-
+
g_free (toolbar->name);
g_free (toolbar);
EggToolbarsItemType *t;
char *data = NULL;
GList *l;
-
+
if (type == GDK_NONE || type == gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE))
{
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (*name != 0, NULL);
return strdup (name);
}
-
+
for (l = model->priv->types; l != NULL; l = l->next)
{
t = l->data;
if (data != NULL) break;
}
}
-
+
return data;
}
EggToolbarsItemType *t;
char *name = NULL;
GList *l;
-
+
if (type == GDK_NONE || type == gdk_atom_intern (EGG_TOOLBAR_ITEM_TYPE, FALSE))
{
g_return_val_if_fail (data, NULL);
g_return_val_if_fail (*data, NULL);
return strdup (data);
}
-
+
if (create)
{
for (l = model->priv->types; name == NULL && l != NULL; l = l->next)
if (t->type == type && t->new_name != NULL)
name = t->new_name (t, data);
}
-
+
return name;
}
else
if (t->type == type && t->get_name != NULL)
name = t->get_name (t, data);
}
-
+
return name;
- }
+ }
}
static gboolean
{
xmlChar *type = xmlGetProp (child, (const xmlChar*) "type");
xmlChar *data = xmlNodeGetContent (child);
-
+
if (type != NULL)
{
GdkAtom atom = gdk_atom_intern ((const char*) type, TRUE);
name = egg_toolbars_model_get_name (model, atom, (const char*) data, create);
}
-
+
xmlFree (type);
xmlFree (data);
}
-
+
child = child->next;
}
-
+
return name;
}
{
name = parse_data_list (model, child->children, TRUE);
}
-
+
/* If that fails, try to use the name. */
if (name == NULL)
{
xmlChar *type = xmlGetProp (child, (const xmlChar*) "type");
xmlChar *data = xmlGetProp (child, (const xmlChar*) "name");
GdkAtom atom = type ? gdk_atom_intern ((const char*) type, TRUE) : GDK_NONE;
-
+
/* If an old format, try to use it. */
name = egg_toolbars_model_get_name (model, atom, (const char*) data, FALSE);
if (name == NULL)
{
name = egg_toolbars_model_get_name (model, atom, (const char*) data, TRUE);
}
-
+
xmlFree (type);
xmlFree (data);
}
-
+
if (name != NULL)
{
egg_toolbars_model_add_item (model, position, -1, name);
xmlFree (string);
egg_toolbars_model_set_flags (model, position, flags);
-
+
parse_item_list (model, child->children, position);
}
xmlNodePtr child)
{
gint flags;
-
+
while (child)
{
if (xmlStrEqual (child->name, (const xmlChar*) "toolitem"))
egg_toolbars_model_class_init (EggToolbarsModelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ volatile GType flags_type; /* work around gcc's optimiser */
- parent_class = g_type_class_peek_parent (klass);
+ /* make sure the flags type is known */
+ flags_type = EGG_TYPE_TB_MODEL_FLAGS;
object_class->finalize = egg_toolbars_model_finalize;
model->priv->toolbars = g_node_new (NULL);
model->priv->flags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- egg_toolbars_model_set_name_flags (model, "_separator",
+ egg_toolbars_model_set_name_flags (model, "_separator",
EGG_TB_MODEL_NAME_KNOWN |
EGG_TB_MODEL_NAME_INFINITE);
}
g_node_destroy (model->priv->toolbars);
g_hash_table_destroy (model->priv->flags);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (egg_toolbars_model_parent_class)->finalize (object);
}
EggToolbarsModel *
int tpos, ipos;
g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model));
-
+
toolbar = g_node_first_child (model->priv->toolbars);
tpos = 0;
-
+
while (toolbar != NULL)
{
item = g_node_first_child (toolbar);
ipos = 0;
-
+
/* Don't delete toolbars that were already empty */
if (item == NULL)
{
toolbar = g_node_next_sibling (toolbar);
continue;
}
-
+
while (item != NULL)
{
next = g_node_next_sibling (item);
{
ipos++;
}
-
+
item = next;
}
-
+
next = g_node_next_sibling (toolbar);
tdata = toolbar->data;
if (!(tdata->flags & EGG_TB_MODEL_NOT_REMOVABLE) &&
{
tpos++;
}
-
+
toolbar = next;
}
}