diff options
author | Aurelien Gateau <aurelien.gateau@canonical.com> | 2010-03-03 12:29:28 +0100 |
---|---|---|
committer | Aurelien Gateau <aurelien.gateau@canonical.com> | 2010-03-03 12:29:28 +0100 |
commit | 761cd05f56dd236e787ce7da56740b7e0c6ae399 (patch) | |
tree | 25816f38fee0e3b6bf926ceefcccf1cc02b10e53 /libdbusmenu-glib | |
parent | ffc0d5b49e0d12c8d1f3701951c3abfb5ee2ad8a (diff) | |
download | libdbusmenu-761cd05f56dd236e787ce7da56740b7e0c6ae399.tar.gz libdbusmenu-761cd05f56dd236e787ce7da56740b7e0c6ae399.tar.bz2 libdbusmenu-761cd05f56dd236e787ce7da56740b7e0c6ae399.zip |
Started to implement about-to-show support
Diffstat (limited to 'libdbusmenu-glib')
-rw-r--r-- | libdbusmenu-glib/client-menuitem.c | 10 | ||||
-rw-r--r-- | libdbusmenu-glib/client.c | 30 | ||||
-rw-r--r-- | libdbusmenu-glib/client.h | 2 | ||||
-rw-r--r-- | libdbusmenu-glib/dbus-menu.xml | 5 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.c | 14 | ||||
-rw-r--r-- | libdbusmenu-glib/menuitem.h | 6 | ||||
-rw-r--r-- | libdbusmenu-glib/server.c | 23 |
7 files changed, 89 insertions, 1 deletions
diff --git a/libdbusmenu-glib/client-menuitem.c b/libdbusmenu-glib/client-menuitem.c index 5d16a66..f4dd583 100644 --- a/libdbusmenu-glib/client-menuitem.c +++ b/libdbusmenu-glib/client-menuitem.c @@ -46,6 +46,7 @@ static void dbusmenu_client_menuitem_init (DbusmenuClientMenuitem *self); static void dbusmenu_client_menuitem_dispose (GObject *object); static void dbusmenu_client_menuitem_finalize (GObject *object); static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); +static void send_about_to_show (DbusmenuMenuitem * mi); G_DEFINE_TYPE (DbusmenuClientMenuitem, dbusmenu_client_menuitem, DBUSMENU_TYPE_MENUITEM); @@ -61,6 +62,7 @@ dbusmenu_client_menuitem_class_init (DbusmenuClientMenuitemClass *klass) DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass); mclass->handle_event = handle_event; + mclass->send_about_to_show = send_about_to_show; return; } @@ -104,3 +106,11 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, value, timestamp); return; } + +static void +send_about_to_show (DbusmenuMenuitem * mi) +{ + DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi); + dbusmenu_client_send_about_to_show(priv->client, dbusmenu_menuitem_get_id(mi)); + return; +} diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 309a11c..7cf5a14 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -668,6 +668,36 @@ dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name return; } +static void +about_to_show_cb (DBusGProxy * proxy, gboolean need_update, GError * error, gpointer userdata) +{ + DbusmenuClient * client = DBUSMENU_CLIENT(userdata); + if (error != NULL) { + g_warning("Unable to send about_to_show: %s", error->message); + return; + } + + if (need_update) { + update_layout(client); + } + return; +} + +void +dbusmenu_client_send_about_to_show(DbusmenuClient * client, gint id) +{ + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + org_ayatana_dbusmenu_about_to_show_async (priv->menuproxy, id, about_to_show_cb, client); + /* + FIXME: We should wait until either + - about_to_show_cb has been called and need_update was false + - about_to_show_cb has been called, need_update was true and menu has been + updated + - about_to_show_cb has not been called and we already waited for 10msecs + */ + return; +} + /* Parse recursively through the XML and make it into objects as need be */ static DbusmenuMenuitem * diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 3909578..5f1c8d1 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -109,6 +109,8 @@ void dbusmenu_client_send_event (DbusmenuClient * client, const gchar * name, const GValue * value, guint timestamp); +void dbusmenu_client_send_about_to_show(DbusmenuClient * client, + gint id); /** SECTION:client diff --git a/libdbusmenu-glib/dbus-menu.xml b/libdbusmenu-glib/dbus-menu.xml index 9af78fa..e4f33df 100644 --- a/libdbusmenu-glib/dbus-menu.xml +++ b/libdbusmenu-glib/dbus-menu.xml @@ -265,6 +265,11 @@ License version 3 and version 2.1 along with this program. If not, see </arg> </method> + <method name="AboutToShow"> + <arg type="i" name="id" direction="in"></arg> + <arg type="b" name="needUpdate" direction="out"></arg> + </method> + <!-- Signals --> <signal name="ItemPropertyUpdated"> <dox:d> diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index a2d2682..75dd9aa 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1203,3 +1203,17 @@ dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const } return; } +void +dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi) +{ + g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); + #ifdef MASSIVEDEBUGGING + g_debug("Submenu for menuitem %d (%s) is about to be shown", ID(mi), LABEL(mi)); + #endif + DbusmenuMenuitemClass * class = DBUSMENU_MENUITEM_GET_CLASS(mi); + + if (class->send_about_to_show != NULL) { + return class->send_about_to_show(mi); + } + return; +} diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index 1382335..777c3ca 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -95,6 +95,8 @@ struct _DbusmenuMenuitem @handle_event: This function is to override how events are handled by subclasses. Look at #dbusmenu_menuitem_handle_event for lots of good information. + @send_about_to_show: Virtual function that notifies server that the + client is about to show a menu. @reserved1: Reserved for future use. @reserved2: Reserved for future use. @reserved3: Reserved for future use. @@ -116,9 +118,10 @@ struct _DbusmenuMenuitemClass /* Virtual functions */ void (*buildxml) (GPtrArray * stringarray); void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); + void (*send_about_to_show) (DbusmenuMenuitem * mi); void (*reserved1) (void); - void (*reserved2) (void); + /* void (*reserved2) (void); */ /* void (*reserved3) (void); */ /* void (*reserved4) (void); -- realized, realloc when bumping lib version */ }; @@ -159,6 +162,7 @@ gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi); void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data); void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); +void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi); /** SECTION:menuitem diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index f6dddf1..dd1238b 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -41,6 +41,7 @@ static gboolean _dbusmenu_server_get_properties (DbusmenuServer * server, gint i static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, GArray * properties, GHashTable ** values, GError ** error); static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error); static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error); +static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error); #include "dbusmenu-server.h" @@ -578,6 +579,28 @@ _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValu return TRUE; } +static gboolean +_dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error) +{ + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id); + + if (mi == NULL) { + if (error != NULL) { + g_set_error(error, + error_quark(), + INVALID_MENUITEM_ID, + "The ID supplied %d does not refer to a menu item we have", + id); + } + return FALSE; + } + + /* GTK+ does not support about-to-show concept for now */ + *need_update = FALSE; + return TRUE; +} + /* Public Interface */ /** dbusmenu_server_new: |