![]() |
![]() |
![]() |
libdbusmenu-glib Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <libdbusmenu-glib/menuitem.h> #define DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED #define DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED #define DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED #define DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED #define DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED #define DBUSMENU_MENUITEM_SIGNAL_REALIZED #define DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID #define DBUSMENU_MENUITEM_PROP_TYPE #define DBUSMENU_MENUITEM_PROP_VISIBLE #define DBUSMENU_MENUITEM_PROP_ENABLED #define DBUSMENU_MENUITEM_PROP_LABEL #define DBUSMENU_MENUITEM_PROP_ICON_NAME #define DBUSMENU_MENUITEM_PROP_ICON_DATA #define DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE #define DBUSMENU_MENUITEM_PROP_TOGGLE_STATE #define DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY #define DBUSMENU_MENUITEM_TOGGLE_CHECK #define DBUSMENU_MENUITEM_TOGGLE_RADIO #define DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED #define DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED #define DBUSMENU_MENUITEM_TOGGLE_STATE_UNKNOWN #define DBUSMENU_MENUITEM_ICON_NAME_BLANK #define DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU DbusmenuMenuitem; void (*dbusmenu_menuitem_about_to_show_cb) (DbusmenuMenuitem *mi
,gpointer user_data
); void (*dbusmenu_menuitem_buildxml_slot_t) (DbusmenuMenuitem *mi
,GPtrArray *stringarray
); DbusmenuMenuitemClass; DbusmenuMenuitem * dbusmenu_menuitem_new (void
); DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (gint id
); gint dbusmenu_menuitem_get_id (DbusmenuMenuitem *mi
); GList * dbusmenu_menuitem_get_children (DbusmenuMenuitem *mi
); GList * dbusmenu_menuitem_take_children (DbusmenuMenuitem *mi
); guint dbusmenu_menuitem_get_position (DbusmenuMenuitem *mi
,DbusmenuMenuitem *parent
); guint dbusmenu_menuitem_get_position_realized (DbusmenuMenuitem *mi
,DbusmenuMenuitem *parent
); gboolean dbusmenu_menuitem_child_append (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
); gboolean dbusmenu_menuitem_child_prepend (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
); gboolean dbusmenu_menuitem_child_delete (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
); gboolean dbusmenu_menuitem_child_add_position (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
,guint position
); gboolean dbusmenu_menuitem_child_reorder (DbusmenuMenuitem *mi
,DbusmenuMenuitem *child
,guint position
); DbusmenuMenuitem * dbusmenu_menuitem_child_find (DbusmenuMenuitem *mi
,gint id
); DbusmenuMenuitem * dbusmenu_menuitem_find_id (DbusmenuMenuitem *mi
,gint id
); gboolean dbusmenu_menuitem_property_set (DbusmenuMenuitem *mi
,const gchar *property
,const gchar *value
); gboolean dbusmenu_menuitem_property_set_bool (DbusmenuMenuitem *mi
,const gchar *property
,const gboolean value
); gboolean dbusmenu_menuitem_property_set_int (DbusmenuMenuitem *mi
,const gchar *property
,const gint value
); const gchar * dbusmenu_menuitem_property_get (DbusmenuMenuitem *mi
,const gchar *property
); gboolean dbusmenu_menuitem_property_get_bool (DbusmenuMenuitem *mi
,const gchar *property
); gint dbusmenu_menuitem_property_get_int (DbusmenuMenuitem *mi
,const gchar *property
); gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem *mi
,const gchar *property
); GList * dbusmenu_menuitem_properties_list (DbusmenuMenuitem *mi
); GHashTable * dbusmenu_menuitem_properties_copy (DbusmenuMenuitem *mi
); void dbusmenu_menuitem_property_remove (DbusmenuMenuitem *mi
,const gchar *property
); void dbusmenu_menuitem_set_root (DbusmenuMenuitem *mi
,gboolean root
); gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem *mi
); void dbusmenu_menuitem_foreach (DbusmenuMenuitem *mi
,void (funcDbusmenuMenuitem * mi, gpointer data) ()
,gpointer data
); void dbusmenu_menuitem_handle_event (DbusmenuMenuitem *mi
,const gchar *name
,GVariant *value
,guint timestamp
); void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem *mi
,void (cbDbusmenuMenuitem * mi, gpointer user_data) ()
,gpointer cb_data
);
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 it's 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.
#define DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED "property-changed"
#define DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED "item-activated"
#define DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED "child-removed"
#define DBUSMENU_MENUITEM_SIGNAL_REALIZED_ID (g_signal_lookup(DBUSMENU_MENUITEM_SIGNAL_REALIZED, DBUSMENU_TYPE_MENUITEM))
#define DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY "children-display"
typedef struct { GObject parent; /*< Private >*/ DbusmenuMenuitemPrivate * priv; } DbusmenuMenuitem;
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.
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.
|
Menu item that should be shown |
|
Extra user data sent with the function. [closure] |
void (*dbusmenu_menuitem_buildxml_slot_t) (DbusmenuMenuitem *mi
,GPtrArray *stringarray
);
This is the function that is called to represent this menu item as an XML fragment. Should call it's own children.
|
Menu item that should be built from. [in] |
|
An array of strings that can be combined into an XML file. [inout][transfer none][array][element-type utf8] |
typedef struct { 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_buildxml_slot_t buildxml; void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, GVariant * value, guint timestamp); void (*send_about_to_show) (DbusmenuMenuitem * mi, void (*cb) (DbusmenuMenuitem * mi, gpointer user_data), gpointer cb_data); void (*show_to_user) (DbusmenuMenuitem * mi, guint timestamp, gpointer cb_data); gboolean (*about_to_show) (void); /*< Private >*/ void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); void (*reserved4) (void); void (*reserved5) (void); void (*reserved6) (void); } DbusmenuMenuitemClass;
reserved1
: Reserved for future use.
reserved2
: Reserved for future use.
reserved3
: Reserved for future use.
reserved4
: Reserved for future use.
reserved5
: Reserved for future use.
reserved6
: Reserved for future use.
GObjectClass |
|
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_buildxml_slot_t |
Virtual function that appends the strings required to represent this menu item in the menu XML file. |
This function is to override how events are handled by subclasses. Look at dbusmenu_menuitem_handle_event for lots of good information. | |
Slot for "show-to-user". | |
Slot for "about-to-show". | |
DbusmenuMenuitem * dbusmenu_menuitem_new (void
);
Create a new DbusmenuMenuitem with all default values.
Returns : |
A newly allocated DbusmenuMenuitem. |
DbusmenuMenuitem * dbusmenu_menuitem_new_with_id (gint id
);
This creates a blank DbusmenuMenuitem with a specific ID.
|
ID to use for this menuitem |
Returns : |
A newly allocated DbusmenuMenuitem. |
gint dbusmenu_menuitem_get_id (DbusmenuMenuitem *mi
);
Gets the unique ID for mi
.
|
The DbusmenuMenuitem to query. |
Returns : |
The ID of the 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.
|
The DbusmenuMenuitem to query. |
Returns : |
A GList of pointers to DbusmenuMenuitem objects. |
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.
|
The DbusmenMenuitem to take the children from. |
Returns : |
A GList of pointers to DbusmenuMenuitem objects. |
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.
|
The DbusmenuMenuitem to find the position of |
|
The DbusmenuMenuitem who's children contain mi
|
Returns : |
The position of mi in the children of parent .
|
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.
|
The DbusmenuMenuitem to find the position of |
|
The DbusmenuMenuitem who's children contain mi
|
Returns : |
The position of mi in the realized children of parent .
|
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.
|
The DbusmenuMenuitem which will become a new parent |
|
The DbusmenMenuitem that will be a child |
Returns : |
Whether the child has been added successfully. |
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.
|
The DbusmenuMenuitem which will become a new parent |
|
The DbusmenMenuitem that will be a child |
Returns : |
Whether the child has been added successfully. |
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
.
|
The DbusmenuMenuitem which has child as a child
|
|
The child DbusmenuMenuitem that you want to no longer
be a child of mi .
|
Returns : |
If we were able to delete child .
|
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.
|
The DbusmenuMenuitem that we're adding the child child to.
|
|
The DbusmenuMenuitem to make a child of mi .
|
|
Where in mi object's list of chidren child should be placed.
|
Returns : |
Whether child was added successfully.
|
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.
|
|
|
The DbusmenuMenuitem that is a child needing to be moved |
|
The position in the list to place it in |
Returns : |
Whether the move was successful. |
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.
|
The DbusmenuMenuitem who's children to look on |
|
The ID of the child that we're looking for. |
Returns : |
The menu item with the ID id or NULL if it
can't be found.
|
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.
|
DbusmenuMenuitem at the top of the tree to search |
|
ID of the DbusmenuMenuitem to search for |
Returns : |
The DbusmenuMenuitem with the ID of id
or NULL if there isn't such a menu item in the tree
represented by mi .
|
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.
|
The DbusmenuMenuitem to set the property on. |
|
Name of the property to set. |
|
The value of the property. |
Returns : |
A boolean representing if the property value was set. |
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.
|
The DbusmenuMenuitem to set the property on. |
|
Name of the property to set. |
|
The value of the property. |
Returns : |
A boolean representing if the property value was set. |
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.
|
The DbusmenuMenuitem to set the property on. |
|
Name of the property to set. |
|
The value of the property. |
Returns : |
A boolean representing if the property value was set. |
const gchar * dbusmenu_menuitem_property_get (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.
|
The DbusmenuMenuitem to look for the property on. |
|
The property to grab. |
Returns : |
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. |
gboolean dbusmenu_menuitem_property_get_bool (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.
|
The DbusmenuMenuitem to look for the property on. |
|
The property to grab. |
Returns : |
The value of the property or FALSE. |
gint dbusmenu_menuitem_property_get_int (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.
|
The DbusmenuMenuitem to look for the property on. |
|
The property to grab. |
Returns : |
The value of the property or zero. |
gboolean dbusmenu_menuitem_property_exist (DbusmenuMenuitem *mi
,const gchar *property
);
|
|
|
|
Returns : |
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.
|
DbusmenuMenuitem to list the properties on |
Returns : |
A list of strings or NULL if there are none. |
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.
|
DbusmenuMenuitem that we're interested in the properties of |
Returns : |
A brand new GHashTable that contains all of the
properties that are on this DbusmenuMenuitem mi .
|
void dbusmenu_menuitem_property_remove (DbusmenuMenuitem *mi
,const gchar *property
);
Removes a property from the menuitem.
|
The DbusmenuMenuitem to remove the property on. |
|
The property to look for. |
void dbusmenu_menuitem_set_root (DbusmenuMenuitem *mi
,gboolean root
);
This function sets the internal value of whether this is a root node or not.
|
DbusmenuMenuitem to set whether it's root |
|
Whether mi 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.
|
DbusmenuMenuitem to see whether it's root |
Returns : |
TRUE if this is a root node |
void dbusmenu_menuitem_foreach (DbusmenuMenuitem *mi
,void (funcDbusmenuMenuitem * 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.
|
The DbusmenItem to start from |
|
User data to pass to the function. [closure] |
void dbusmenu_menuitem_handle_event (DbusmenuMenuitem *mi
,const gchar *name
,GVariant *value
,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.
|
The DbusmenuMenuitem to send the signal on. |
|
The name of the signal |
|
|
|
The timestamp of when the event happened |
void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem *mi
,void (cbDbusmenuMenuitem * 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.
|
The DbusmenuMenuitem to send the signal on. |
|
Data to pass to the callback. [closure] |