From b6b89c9b74e0e2a90d8af7749d817a512bde95d8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 18 Feb 2011 16:05:09 -0600 Subject: Adds a status property that is gotten over DBus --- libdbusmenu-glib/client.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++- libdbusmenu-glib/client.h | 2 ++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 5f967d0..61ea91d 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -49,7 +49,8 @@ License version 3 and version 2.1 along with this program. If not, see enum { PROP_0, PROP_DBUSOBJECT, - PROP_DBUSNAME + PROP_DBUSNAME, + PROP_STATUS }; /* Signals */ @@ -94,6 +95,7 @@ struct _DbusmenuClientPrivate gint delayed_idle; DbusmenuTextDirection text_direction; + DbusmenuStatus status; }; typedef struct _newItemPropData newItemPropData; @@ -294,6 +296,11 @@ dbusmenu_client_class_init (DbusmenuClientClass *klass) "Name of the DBus client we're connecting to.", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, PROP_STATUS, + g_param_spec_enum(DBUSMENU_CLIENT_PROP_STATUS, "Status of viewing the menus", + "Whether the menus should be given special visuals", + DBUSMENU_TYPE_STATUS, DBUSMENU_STATUS_NORMAL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); if (dbusmenu_node_info == NULL) { GError * error = NULL; @@ -349,6 +356,7 @@ dbusmenu_client_init (DbusmenuClient *self) priv->delayed_property_listeners = g_array_new(FALSE, FALSE, sizeof(properties_listener_t)); priv->text_direction = DBUSMENU_TEXT_DIRECTION_NONE; + priv->status = DBUSMENU_STATUS_NORMAL; return; } @@ -494,6 +502,9 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) case PROP_DBUSOBJECT: g_value_set_string(value, priv->dbus_object); break; + case PROP_STATUS: + g_value_set_enum(value, priv->status); + break; default: g_warning("Unknown property %d.", id); return; @@ -1043,6 +1054,7 @@ menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv inva { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(user_data); DbusmenuTextDirection olddir = priv->text_direction; + DbusmenuStatus oldstatus = priv->status; /* Invalidate first */ gchar * invalid; @@ -1051,6 +1063,9 @@ menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv inva if (g_strcmp0(invalid, "text-direction") == 0) { priv->text_direction = DBUSMENU_TEXT_DIRECTION_NONE; } + if (g_strcmp0(invalid, "status") == 0) { + priv->status = DBUSMENU_STATUS_NORMAL; + } } /* Check updates */ @@ -1066,6 +1081,14 @@ menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv inva priv->text_direction = dbusmenu_text_direction_get_value_from_nick(g_variant_get_string(str, NULL)); } + if (g_strcmp0(key, "status") == 0) { + GVariant * str = value; + if (g_variant_is_of_type(str, G_VARIANT_TYPE_VARIANT)) { + str = g_variant_get_variant(str); + } + + priv->status = dbusmenu_status_get_value_from_nick(g_variant_get_string(str, NULL)); + } g_variant_unref(value); g_free(key); @@ -1075,6 +1098,10 @@ menuproxy_prop_changed_cb (GDBusProxy * proxy, GVariant * properties, GStrv inva g_signal_emit(G_OBJECT(user_data), signals[TEXT_DIRECTION_CHANGED], 0, priv->text_direction, TRUE); } + if (oldstatus != priv->status) { + g_object_notify(G_OBJECT(user_data), DBUSMENU_CLIENT_PROP_STATUS); + } + return; } @@ -1928,3 +1955,25 @@ dbusmenu_client_get_text_direction (DbusmenuClient * client) DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); return priv->text_direction; } + +/** + dbusmenu_client_get_status: + @client: #DbusmenuClient to check the status on + + Gets the recommended current status that the server + is exporting for the menus. In situtations where the + value is #DBUSMENU_STATUS_NOTICE it is recommended that + the client show the menus to the user an a more noticible + way. + + Return value: Status being exported. +*/ +DbusmenuStatus +dbusmenu_client_get_status (DbusmenuClient * client) +{ + g_return_val_if_fail(DBUSMENU_IS_CLIENT(client), DBUSMENU_STATUS_NORMAL); + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + return priv->status; +} + + diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 3bab503..e812aa2 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -53,6 +53,7 @@ G_BEGIN_DECLS #define DBUSMENU_CLIENT_PROP_DBUS_NAME "dbus-name" #define DBUSMENU_CLIENT_PROP_DBUS_OBJECT "dbus-object" +#define DBUSMENU_CLIENT_PROP_STATUS "status" #define DBUSMENU_CLIENT_TYPES_DEFAULT "standard" #define DBUSMENU_CLIENT_TYPES_SEPARATOR "separator" @@ -159,6 +160,7 @@ void dbusmenu_client_send_about_to_show(DbusmenuClient * client, void (*cb) (gpointer user_data), gpointer cb_data); DbusmenuTextDirection dbusmenu_client_get_text_direction (DbusmenuClient * client); +DbusmenuStatus dbusmenu_client_get_status (DbusmenuClient * client); /** SECTION:client -- cgit v1.2.3