Top |
A DbusmenuMenuitem is the lowest level of represenation of a single item in a menu. It gets created on the server side and copied over to the client side where it gets rendered. As the server starts to change it, and grow it, and do all kinds of fun stuff that information is transfered over DBus and the client updates its understanding of the object model.
Most people using either the client or the server should be able to deal mostly with DbusmenuMenuitem objects. These are simple, but then they can be attached to more complex objects and handled appropriately.
void (*dbusmenu_menuitem_about_to_show_cb) (DbusmenuMenuitem *mi
,gpointer user_data
);
Callback prototype for a callback that is called when the menu should be shown.
GVariant * (*dbusmenu_menuitem_buildvariant_slot_t) (DbusmenuMenuitem *mi
,gchar **properties
);
This is the function that is called to represent this menu item as a variant. Should call its own children.
DbusmenuMenuitem *
dbusmenu_menuitem_new (void
);
Create a new DbusmenuMenuitem with all default values.
DbusmenuMenuitem *
dbusmenu_menuitem_new_with_id (gint id
);
This creates a blank DbusmenuMenuitem with a specific ID.
gint
dbusmenu_menuitem_get_id (DbusmenuMenuitem *mi
);
Gets the unique ID for mi
.
GList *
dbusmenu_menuitem_get_children (DbusmenuMenuitem *mi
);
Returns simply the list of children that this menu item has. The list is valid until another child related function is called, where it might be changed.
A GList of pointers to DbusmenuMenuitem objects.
[transfer none][element-type Dbusmenu.Menuitem]
GList *
dbusmenu_menuitem_take_children (DbusmenuMenuitem *mi
);
While the name sounds devious that's exactly what this function
does. It takes the list of children from the mi
and clears the
internal list. The calling function is now in charge of the ref's
on the children it has taken. A lot of responsibility involved
in taking children.
A GList of pointers to DbusmenuMenuitem objects.
[transfer full][element-type Dbusmenu.Menuitem]
guint dbusmenu_menuitem_get_position (DbusmenuMenuitem *mi
,DbusmenuMenuitem *parent
);
This function returns the position of the menu item mi
in the children of parent
. It will return zero if the
menu item can't be found.
mi |
The DbusmenuMenuitem to find the position of |
|
parent |
The DbusmenuMenuitem who's children contain |
guint dbusmenu_menuitem_get_position_realized (DbusmenuMenuitem *mi
,DbusmenuMenuitem *parent
);
This function is very similar to dbusmenu_menuitem_get_position except that it only counts in the children that have been realized.
mi |
The DbusmenuMenuitem to find the position of |
|
parent |
The DbusmenuMenuitem who's children contain |
gboolean dbusmenu_menuitem_child_append (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
);
This function adds child
to the list of children on mi
at
the end of that list.
mi |
The DbusmenuMenuitem which will become a new parent |
|
child |
The DbusmenMenuitem that will be a child |
gboolean dbusmenu_menuitem_child_prepend (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
);
This function adds child
to the list of children on mi
at
the beginning of that list.
mi |
The DbusmenuMenuitem which will become a new parent |
|
child |
The DbusmenMenuitem that will be a child |
gboolean dbusmenu_menuitem_child_delete (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
);
This function removes child
from the children list of mi
. It does
not call g_object_unref on child
.
mi |
The DbusmenuMenuitem which has |
|
child |
The child DbusmenuMenuitem that you want to no longer
be a child of |
gboolean dbusmenu_menuitem_child_add_position (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
,guint position
);
Puts child
in the list of children for mi
at the location
specified in position
. If there is not enough entires available
then child
will be placed at the end of the list.
mi |
The DbusmenuMenuitem that we're adding the child |
|
child |
The DbusmenuMenuitem to make a child of |
|
position |
Where in |
gboolean dbusmenu_menuitem_child_reorder (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
,guint position
);
This function moves a child on the list of children. It is for a child that is already in the list, but simply needs a new location.
mi |
The DbusmenuMenuitem that has children needing realignment |
|
child |
The DbusmenuMenuitem that is a child needing to be moved |
|
position |
The position in the list to place it in |
DbusmenuMenuitem * dbusmenu_menuitem_child_find (DbusmenuMenuitem *mi
,gint id
);
Search the children of mi
to find one with the ID of id
.
If it doesn't exist then we return NULL.
mi |
The DbusmenuMenuitem who's children to look on |
|
id |
The ID of the child that we're looking for. |
DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem *mi
,gint id
);
This function searchs the whole tree of children that
are attached to mi
. This could be quite a few nodes, all
the way down the tree. It is a depth first search.
mi |
DbusmenuMenuitem at the top of the tree to search |
|
id |
ID of the DbusmenuMenuitem to search for |
The DbusmenuMenuitem with the ID of id
or NULL if there isn't such a menu item in the tree
represented by mi
.
[transfer none]
gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem *mi
,const gchar *property
,const gchar *value
);
Takes the pair of property
and value
and places them as a
property on mi
. If a property already exists by that name,
then the value is set to the new value. If not, the property
is added. If the value is changed or the property was previously
unset then the signal “prop-changed” will be
emitted by this function.
mi |
The DbusmenuMenuitem to set the property on. |
|
property |
Name of the property to set. |
|
value |
The value of the property. |
gboolean dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem *mi
,const gchar *property
,const gboolean value
);
Takes a boolean value
and sets it on property
as a
property on mi
. If a property already exists by that name,
then the value is set to the new value. If not, the property
is added. If the value is changed or the property was previously
unset then the signal “prop-changed” will be
emitted by this function.
mi |
The DbusmenuMenuitem to set the property on. |
|
property |
Name of the property to set. |
|
value |
The value of the property. |
gboolean dbusmenu_menuitem_property_set_byte_array (DbusmenuMenuitem *mi
,const gchar *property
,const guchar *value
,gsize nelements
);
Takes a byte array value
and sets it on property
as a
property on mi
. If a property already exists by that name,
then the value is set to the new value. If not, the property
is added. If the value is changed or the property was previously
unset then the signal “prop-changed” will be
emitted by this function.
mi |
The DbusmenuMenuitem to set the property on. |
|
property |
Name of the property to set. |
|
value |
The byte array. |
|
nelements |
The number of elements in the byte array. |
gboolean dbusmenu_menuitem_property_set_int (DbusmenuMenuitem *mi
,const gchar *property
,const gint value
);
Takes a boolean value
and sets it on property
as a
property on mi
. If a property already exists by that name,
then the value is set to the new value. If not, the property
is added. If the value is changed or the property was previously
unset then the signal “prop-changed” will be
emitted by this function.
mi |
The DbusmenuMenuitem to set the property on. |
|
property |
Name of the property to set. |
|
value |
The value of the property. |
gboolean dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem *mi
,const gchar *property
,GVariant *value
);
Takes the pair of property
and value
and places them as a
property on mi
. If a property already exists by that name,
then the value is set to the new value. If not, the property
is added. If the value is changed or the property was previously
unset then the signal “prop-changed” will be
emitted by this function.
mi |
The DbusmenuMenuitem to set the property on. |
|
property |
Name of the property to set. |
|
value |
The value of the property. |
const gchar * dbusmenu_menuitem_property_get (const DbusmenuMenuitem *mi
,const gchar *property
);
Look up a property on mi
and return the value of it if
it exits. NULL will be returned if the property doesn't
exist.
A string with the value of the property that shouldn't be free'd. Or NULL if the property is not set or is not a string.
[transfer none]
gboolean dbusmenu_menuitem_property_get_bool (const DbusmenuMenuitem *mi
,const gchar *property
);
Look up a property on mi
and return the value of it if
it exits. Returns FALSE if the property doesn't exist.
const guchar * dbusmenu_menuitem_property_get_byte_array (const DbusmenuMenuitem *mi
,const gchar *property
,gsize *nelements
);
Look up a property on mi
and return the value of it if
it exits. NULL will be returned if the property doesn't
exist.
mi |
The DbusmenuMenuitem to look for the property on. |
|
property |
The property to grab. |
|
nelements |
A pointer to the location to store the number of items (out) |
A byte array with the value of the property that shouldn't be free'd. Or NULL if the property is not set or is not a byte array.
[array length=nelements][element-type guint8][transfer none]
gint dbusmenu_menuitem_property_get_int (const DbusmenuMenuitem *mi
,const gchar *property
);
Look up a property on mi
and return the value of it if
it exits. Returns zero if the property doesn't exist.
GVariant * dbusmenu_menuitem_property_get_variant (const DbusmenuMenuitem *mi
,const gchar *property
);
Look up a property on mi
and return the value of it if
it exits. NULL will be returned if the property doesn't
exist.
gboolean dbusmenu_menuitem_property_exist (const DbusmenuMenuitem *mi
,const gchar *property
);
Checkes to see if a particular property exists on mi
and
returns TRUE if so.
GList *
dbusmenu_menuitem_properties_list (DbusmenuMenuitem *mi
);
This functiong gets a list of the names of all the properties
that are set on this menu item. This data on the list is owned
by the menuitem but the list is not and should be freed using
g_list_free()
when the calling function is done with it.
GHashTable *
dbusmenu_menuitem_properties_copy (DbusmenuMenuitem *mi
);
This function takes the properties of a DbusmenuMenuitem and puts them into a GHashTable that is referenced by the key of a string and has the value of a string. The hash table may not have any entries if there aren't any or there is an error in processing. It is the caller's responsibility to destroy the created GHashTable.
A brand new GHashTable that contains all of
theroperties that are on this DbusmenuMenuitem mi
.
[transfer full]
void dbusmenu_menuitem_property_remove (DbusmenuMenuitem *mi
,const gchar *property
);
Removes a property from the menuitem.
void dbusmenu_menuitem_set_root (DbusmenuMenuitem *mi
,gboolean root
);
This function sets the internal value of whether this is a root node or not.
gboolean
dbusmenu_menuitem_get_root (DbusmenuMenuitem *mi
);
This function returns the internal value of whether this is a root node or not.
void dbusmenu_menuitem_foreach (DbusmenuMenuitem *mi
,void (*func) (DbusmenuMenuitem * mi, gpointer data)
,gpointer data
);
This calls the function func
on this menu item and all
of the children of this item. And their children. And
their children. And... you get the point. It will get
called on the whole tree.
void dbusmenu_menuitem_handle_event (DbusmenuMenuitem *mi
,const gchar *name
,GVariant *variant
,guint timestamp
);
This function is called to create an event. It is likely to be overrided by subclasses. The default menu item will respond to the activate signal and do:
Emits the “item-activate” signal on this menu item. Called by server objects when they get the appropriate DBus signals from the client.
If you subclass this function you should really think about calling the parent function unless you have a good reason not to.
mi |
The DbusmenuMenuitem to send the signal on. |
|
name |
The name of the signal |
|
variant |
A value that could be set for the event |
|
timestamp |
The timestamp of when the event happened |
void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem *mi
,void (*cb) (DbusmenuMenuitem * mi, gpointer user_data)
,gpointer cb_data
);
This function is used to send the even that the submenu of this item is about to be shown. Callers to this event should delay showing the menu until their callback is called if possible.
mi |
The DbusmenuMenuitem to send the signal on. |
|
cb |
Callback to call when the call has returned. |
|
cb_data |
Data to pass to the callback. |
[closure] |
void dbusmenu_menuitem_show_to_user (DbusmenuMenuitem *mi
,guint timestamp
);
Signals that this menu item should be shown to the user. If this is server side the server will then take it and send it over the bus.
DbusmenuMenuitem *
dbusmenu_menuitem_get_parent (DbusmenuMenuitem *mi
);
This function looks up the parent of mi
gboolean dbusmenu_menuitem_set_parent (DbusmenuMenuitem *mi
,DbusmenuMenuitem *parent
);
Sets the parent of mi
to parent
. If mi
already
has a parent, then this call will fail. The parent will
be set automatically when using the usual methods to add a
child menuitem, so this function should not normally be
called directly
mi |
The DbusmenuMenuitem for which to set the parent |
|
parent |
The new parent DbusmenuMenuitem |
gboolean
dbusmenu_menuitem_unparent (DbusmenuMenuitem *mi
);
Unparents the menu item mi
. If mi
doesn't have a
parent, then this call will fail. The menuitem will
be unparented automatically when using the usual methods
to delete a child menuitem, so this function should not
normally be called directly
#define DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED "property-changed"
String to attach to signal “property-changed”
#define DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED "item-activated"
String to attach to signal “item-activated”
#define DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED "child-added"
String to attach to signal “child-added”
#define DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED "child-removed"
String to attach to signal “child-removed”
#define DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED "child-moved"
String to attach to signal “child-moved”
#define DBUSMENU_MENUITEM_SIGNAL_EVENT "event"
String to attach to signal “event”
#define DBUSMENU_MENUITEM_SIGNAL_REALIZED "realized"
String to attach to signal “realized”
#define DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID (g_signal_lookup(DBUSMENU_MENUITEM_SIGNAL_REALIZED, DBUSMENU_TYPE_MENUITEM))
ID to attach to signal “realized”
#define DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW "about-to-show"
String to attach to signal “about-to-show”
#define DBUSMENU_MENUITEM_SIGNAL_SHOW_TO_USER "show-to-user"
String to attach to signal “show-to-user”
#define DBUSMENU_MENUITEM_PROP_TYPE "type"
DbusmenuMenuitem property used to represent what type of menuitem this object represents. Type: G_VARIANT_TYPE_STRING.
#define DBUSMENU_MENUITEM_PROP_VISIBLE "visible"
DbusmenuMenuitem property used to represent whether the menuitem should be shown or not. Type: G_VARIANT_TYPE_BOOLEAN.
#define DBUSMENU_MENUITEM_PROP_ENABLED "enabled"
DbusmenuMenuitem property used to represent whether the menuitem is clickable or not. Type: G_VARIANT_TYPE_BOOLEAN.
#define DBUSMENU_MENUITEM_PROP_LABEL "label"
DbusmenuMenuitem property used for the text on the menu item. Type: G_VARIANT_TYPE_STRING
#define DBUSMENU_MENUITEM_PROP_ICON_NAME "icon-name"
DbusmenuMenuitem property that is the name of the icon under the Freedesktop.org icon naming spec. Type: G_VARIANT_TYPE_STRING
#define DBUSMENU_MENUITEM_PROP_ICON_DATA "icon-data"
DbusmenuMenuitem property that is the raw data of a custom icon used in the application. Type: G_VARIANT_TYPE_VARIANT
It is recommended that this is not set directly but instead the
libdbusmenu-gtk library is used with the function dbusmenu_menuitem_property_set_image()
#define DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE "toggle-type"
DbusmenuMenuitem property that says what type of toggle entry should be shown in the menu. Should be either DBUSMENU_MENUITEM_TOGGLE_CHECK or DBUSMENU_MENUITEM_TOGGLE_RADIO. Type: G_VARIANT_TYPE_STRING
#define DBUSMENU_MENUITEM_PROP_TOGGLE_STATE "toggle-state"
DbusmenuMenuitem property that says what state a toggle entry should be shown as the menu. Should be either DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED or DBUSMENU_MENUITEM_TOGGLE_STATUE_UNKNOWN. Type: G_VARIANT_TYPE_INT32
#define DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY "children-display"
DbusmenuMenuitem property that tells how the children of this menuitem should be displayed. Most likely this will be unset or of the value DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU. Type: G_VARIANT_TYPE_STRING
#define DBUSMENU_MENUITEM_PROP_SHORTCUT "shortcut"
DbusmenuMenuitem property that is the entries that represent a shortcut to activate the menuitem. It is an array of arrays of strings. Type: G_VARIANT_TYPE_ARRAY
It is recommended that this is not set directly but instead the
libdbusmenu-gtk library is used with the function dbusmenu_menuitem_property_set_shortcut()
#define DBUSMENU_MENUITEM_PROP_DISPOSITION "disposition"
DbusmenuMenuitem property to tell what type of information that the menu item is displaying to the user. Type: G_VARIANT_TYPE_STRING
#define DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC "accessible-desc"
DbusmenuMenuitem property used to provide a textual description of any information that the icon may convey. The contents of this property are passed through to assistive technologies such as the Orca screen reader. The contents of this property will not be visible in the menu item. If this property is set, Orca will use this property instead of the label property. Type: G_VARIANT_TYPE_STRING
#define DBUSMENU_MENUITEM_TOGGLE_CHECK "checkmark"
Used to set DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE to be a standard check mark item.
#define DBUSMENU_MENUITEM_TOGGLE_RADIO "radio"
Used to set DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE to be a standard radio item.
#define DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED 0
Used to set DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's toggle item is empty.
#define DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED 1
Used to set DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's toggle item is filled.
#define DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN -1
Used to set DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's toggle item is undecided.
#define DBUSMENU_MENUITEM_ICON_NAME_BLANK "blank-icon"
Used to set DBUSMENU_MENUITEM_PROP_TOGGLE_STATE so that the menu's toggle item is undecided.
#define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU "submenu"
Used in DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY to have the subitems displayed as a submenu.
#define DBUSMENU_MENUITEM_SHORTCUT_ALT "Alt"
Used in DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the alternate key.
#define DBUSMENU_MENUITEM_SHORTCUT_CONTROL "Control"
Used in DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the control key.
#define DBUSMENU_MENUITEM_SHORTCUT_SHIFT "Shift"
Used in DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the shift key.
#define DBUSMENU_MENUITEM_SHORTCUT_SUPER "Super"
Used in DBUSMENU_MENUITEM_PROP_SHORTCUT to represent the super key.
#define DBUSMENU_MENUITEM_DISPOSITION_NORMAL "normal"
Used in DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu item displayed in the normal manner. Default value.
#define DBUSMENU_MENUITEM_DISPOSITION_INFORMATIVE "informative"
Used in DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu item displayed in a way that conveys it's giving additional information to the user.
#define DBUSMENU_MENUITEM_DISPOSITION_WARNING "warning"
Used in DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu item displayed in a way that conveys it's giving a warning to the user.
#define DBUSMENU_MENUITEM_DISPOSITION_ALERT "alert"
Used in DBUSMENU_MENUITEM_PROP_DISPOSITION to have a menu item displayed in a way that conveys it's giving an alert to the user.
#define DBUSMENU_MENUITEM_EVENT_ACTIVATED "clicked"
String for the event identifier when a menu item is clicked on by the user.
#define DBUSMENU_MENUITEM_EVENT_CLOSED "closed"
String for the event identifier when a menu is closed and displayed to the user. Only valid for items that contain submenus.
#define DBUSMENU_MENUITEM_EVENT_OPENED "opened"
String for the event identifier when a menu is opened and displayed to the user. Only valid for items that contain submenus.
struct DbusmenuMenuitem { GObject parent; /*< Private >*/ DbusmenuMenuitemPrivate * priv; };
This is the GObject based object that represents a menu item. It gets created the same on both the client and the server side and libdbusmenu-glib does the work of making this object model appear on both sides of DBus. Simple really, though through updates and people coming on and off the bus it can lead to lots of fun complex scenarios.
struct DbusmenuMenuitemClass { GObjectClass parent_class; /* Signals */ void (*property_changed) (gchar * property, GVariant * value); void (*item_activated) (guint timestamp); void (*child_added) (DbusmenuMenuitem * child, guint position); void (*child_removed) (DbusmenuMenuitem * child); void (*child_moved) (DbusmenuMenuitem * child, guint newpos, guint oldpos); void (*realized) (void); /* Virtual functions */ dbusmenu_menuitem_buildvariant_slot_t buildvariant; void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp); void (*send_about_to_show) (DbusmenuMenuitem * mi, dbusmenu_menuitem_about_to_show_cb cb, gpointer cb_data); void (*show_to_user) (DbusmenuMenuitem * mi, guint timestamp, gpointer cb_data); gboolean (*about_to_show) (void); void (*event) (const gchar * name, GVariant * value, guint timestamp); /*< Private >*/ void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); void (*reserved4) (void); void (*reserved5) (void); };
Functions and signals that every menuitem should know something about.
Slot for “property-changed”. |
||
Slot for “item-activated”. |
||
Slot for “child-added”. |
||
Slot for “child-removed”. |
||
Slot for “child-moved”. |
||
Slot for “realized”. |
||
dbusmenu_menuitem_buildvariant_slot_t |
Virtual function that appends the strings required to represent this menu item in the menu variant. |
|
This function is to override how events are handled by subclasses. Look at dbusmenu_menuitem_handle_event for lots of good information. |
||
Virtual function that notifies server that the client is about to show a menu. |
||
Slot for “show-to-user”. |
||
Slot for “about-to-show”. |
||
Slot for “event”. |
||
Reserved for future use. |
||
Reserved for future use. |
||
Reserved for future use. |
||
Reserved for future use. |
||
Reserved for future use. |