81
95
object_class->set_property = set_property;
82
96
object_class->get_property = get_property;
99
DbusmenuMenuitem::property-changed:
100
@arg0: The #DbusmenuMenuitem object.
101
@arg1: The name of the property that changed
102
@arg2: The new value of the property
104
Emitted everytime a property on a menuitem is either
107
signals[PROPERTY_CHANGED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED,
108
G_TYPE_FROM_CLASS(klass),
110
G_STRUCT_OFFSET(DbusmenuMenuitemClass, property_changed),
112
_dbusmenu_menuitem_marshal_VOID__STRING_STRING,
113
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
115
DbusmenuMenuitem::item-activated:
116
@arg0: The #DbusmenuMenuitem object.
118
Emitted on the objects on the server side when
119
they are signaled on the client side.
121
signals[ITEM_ACTIVATED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
122
G_TYPE_FROM_CLASS(klass),
124
G_STRUCT_OFFSET(DbusmenuMenuitemClass, item_activated),
126
_dbusmenu_menuitem_marshal_VOID__VOID,
127
G_TYPE_NONE, 0, G_TYPE_NONE);
129
DbusmenuMenuitem::child-added:
130
@arg0: The #DbusmenuMenuitem which is the parent.
131
@arg1: The #DbusmenuMenuitem which is the child.
133
Signaled when the child menuitem has been added to
136
signals[CHILD_ADDED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED,
137
G_TYPE_FROM_CLASS(klass),
139
G_STRUCT_OFFSET(DbusmenuMenuitemClass, child_added),
141
_dbusmenu_menuitem_marshal_VOID__OBJECT,
142
G_TYPE_NONE, 2, G_TYPE_OBJECT);
144
DbusmenuMenuitem::child-removed:
145
@arg0: The #DbusmenuMenuitem which was the parent.
146
@arg1: The #DbusmenuMenuitem which was the child.
148
Signaled when the child menuitem has been requested to
149
be removed from the parent. This signal is called when
150
it has been removed from the list but not yet had
151
#g_object_unref called on it.
153
signals[CHILD_REMOVED] = g_signal_new(DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED,
154
G_TYPE_FROM_CLASS(klass),
156
G_STRUCT_OFFSET(DbusmenuMenuitemClass, child_removed),
158
_dbusmenu_menuitem_marshal_VOID__OBJECT,
159
G_TYPE_NONE, 2, G_TYPE_OBJECT);
84
161
g_object_class_install_property (object_class, PROP_ID,
85
162
g_param_spec_uint("id", "ID for the menu item",
86
163
"This is a unique indentifier for the menu item.",
473
DbusmenuMenuitem * mi;
477
/* Basically the heart of the find_id that matches the
478
API of GFunc. Unfortunately, this goes through all the
479
children, but it rejects them quickly. */
481
find_id_helper (gpointer in_mi, gpointer in_find_id)
483
DbusmenuMenuitem * mi = (DbusmenuMenuitem *)in_mi;
484
find_id_t * find_id = (find_id_t *)in_find_id;
486
if (find_id->mi != NULL) return;
487
if (find_id->id == dbusmenu_menuitem_get_id(mi)) {
492
g_list_foreach(dbusmenu_menuitem_get_children(mi), find_id_helper, in_find_id);
497
dbusmenu_menuitem_find_id:
498
@mi: #DbusmenuMenuitem at the top of the tree to search
499
@id: ID of the #DbusmenuMenuitem to search for
501
This function searchs the whole tree of children that
502
are attached to @mi. This could be quite a few nodes, all
503
the way down the tree. It is a depth first search.
505
Return value: The #DbusmenuMenuitem with the ID of @id
506
or #NULL if there isn't such a menu item in the tree
510
dbusmenu_menuitem_find_id (DbusmenuMenuitem * mi, guint id)
512
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL);
513
find_id_t find_id = {mi: NULL, id: id};
514
find_id_helper(mi, &find_id);
519
dbusmenu_menuitem_property_set:
520
@mi: The #DbusmenuMenuitem to set the property on.
521
@property: Name of the property to set.
522
@value: The value of the property.
524
Takes the pair of @property and @value and places them as a
525
property on @mi. If a property already exists by that name,
526
then the value is set to the new value. If not, the property
527
is added. If the value is changed or the property was previously
528
unset then the signal #DbusmenuMenuitem::prop-changed will be
529
emitted by this function.
531
Return value: A boolean representing if the property value was set.
375
534
dbusmenu_menuitem_property_set (DbusmenuMenuitem * mi, const gchar * property, const gchar * value)
536
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE);
537
g_return_val_if_fail(property != NULL, FALSE);
539
DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
540
/* g_debug("Setting a property. ID: %d Prop: %s Value: %s", priv->id, property, value); */
542
gpointer lookup = g_hash_table_lookup(priv->properties, property);
543
if (g_strcmp0((gchar *)lookup, value) == 0) {
544
/* The value is the same as the value currently in the
545
table so we don't really care. Just say everything's okay */
549
gchar * lprop = g_strdup(property);
550
gchar * lval = g_strdup(value);
552
g_hash_table_insert(priv->properties, lprop, lval);
553
g_signal_emit(G_OBJECT(mi), signals[PROPERTY_CHANGED], 0, property, value, TRUE);
559
dbusmenu_menuitem_property_get:
560
@mi: The #DbusmenuMenuitem to look for the property on.
561
@property: The property to grab.
563
Look up a property on @mi and return the value of it if
564
it exits. #NULL will be returned if the property doesn't
567
Return value: A string with the value of the property
568
that shouldn't be free'd. Or #NULL if the property
382
572
dbusmenu_menuitem_property_get (DbusmenuMenuitem * mi, const gchar * property)
574
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL);
575
g_return_val_if_fail(property != NULL, NULL);
577
DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
579
return (const gchar *)g_hash_table_lookup(priv->properties, property);
583
dbusmenu_menuitem_property_exit:
584
@mi: The #DbusmenuMenuitem to look for the property on.
585
@property: The property to look for.
587
Checkes to see if a particular property exists on @mi and
590
Return value: A boolean checking to see if the property is available
389
593
dbusmenu_menuitem_property_exist (DbusmenuMenuitem * mi, const gchar * property)
595
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE);
596
g_return_val_if_fail(property != NULL, FALSE);
598
DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
600
gpointer value = g_hash_table_lookup(priv->properties, property);
602
return value != NULL;
606
dbusmenu_menuitem_properties_list:
607
@mi: #DbusmenuMenuitem to list the properties on
609
This functiong gets a list of the names of all the properties
610
that are set on this menu item. This data on the list is owned
611
by the menuitem but the list is not and should be freed using
612
g_list_free() when the calling function is done with it.
614
Return value: A list of strings or NULL if there are none.
617
dbusmenu_menuitem_properties_list (DbusmenuMenuitem * mi)
619
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL);
621
DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
622
return g_hash_table_get_keys(priv->properties);
626
copy_helper (gpointer in_key, gpointer in_value, gpointer in_data)
628
GHashTable * table = (GHashTable *)in_data;
629
g_hash_table_insert(table, in_key, in_value);
634
dbusmenu_menuitem_properties_copy:
635
@mi: #DbusmenuMenuitem that we're interested in the properties of
637
This function takes the properties of a #DbusmenuMenuitem
638
and puts them into a #GHashTable that is referenced by the
639
key of a string and has the value of a string. The hash
640
table may not have any entries if there aren't any or there
641
is an error in processing. It is the caller's responsibility
642
to destroy the created #GHashTable.
644
Return value: A brand new #GHashTable that contains all of the
645
properties that are on this #DbusmenuMenuitem @mi.
648
dbusmenu_menuitem_properties_copy (DbusmenuMenuitem * mi)
650
GHashTable * ret = g_hash_table_new(g_str_hash, g_str_equal);
652
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), ret);
654
DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
655
g_hash_table_foreach(priv->properties, copy_helper, ret);
691
void (*func) (DbusmenuMenuitem * mi, gpointer data);
696
foreach_helper (gpointer data, gpointer user_data)
698
dbusmenu_menuitem_foreach(DBUSMENU_MENUITEM(data), ((foreach_struct_t *)user_data)->func, ((foreach_struct_t *)user_data)->data);
703
dbusmenu_menuitem_foreach:
704
@mi: The #DbusmenItem to start from
705
@func: Function to call on every node in the tree
706
@data: User data to pass to the function
708
This calls the function @func on this menu item and all
709
of the children of this item. And their children. And
710
their children. And... you get the point. It will get
711
called on the whole tree.
714
dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data)
716
g_return_if_fail(DBUSMENU_IS_MENUITEM(mi));
717
g_return_if_fail(func != NULL);
720
GList * children = dbusmenu_menuitem_get_children(mi);
721
foreach_struct_t foreach_data = {func: func, data: data};
722
g_list_foreach(children, foreach_helper, &foreach_data);
727
dbusmenu_menuitem_activate:
728
@mi: The #DbusmenuMenuitem to send the signal on.
730
Emits the #DbusmenuMenuitem::item-activate signal on this
731
menu item. Called by server objects when they get the
732
appropriate DBus signals from the client.
735
dbusmenu_menuitem_activate (DbusmenuMenuitem * mi)
737
g_return_if_fail(DBUSMENU_IS_MENUITEM(mi));
738
g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, TRUE);