forked from enlightenment/efl
[elm] Support optional properties in D-Bus menu
The D-Bus menu interface description requests that properties with default values should be optimized out. Patch by: Henrique Dante de Almeida <hdante@profusion.mobi> SVN revision: 81807
This commit is contained in:
parent
cdfe5155f8
commit
849567e4e7
|
@ -106,7 +106,43 @@ _str_to_property(const char *str)
|
||||||
return ELM_DBUS_PROPERTY_UNKNOWN;
|
return ELM_DBUS_PROPERTY_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Eina_Bool
|
||||||
|
_property_exists(Elm_Menu_Item *item,
|
||||||
|
Elm_DBus_Property property)
|
||||||
|
{
|
||||||
|
Elm_Object_Item *item_obj;
|
||||||
|
|
||||||
|
if (item->separator)
|
||||||
|
{
|
||||||
|
if (property == ELM_DBUS_PROPERTY_TYPE) return EINA_TRUE;
|
||||||
|
return EINA_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (property)
|
||||||
|
{
|
||||||
|
case ELM_DBUS_PROPERTY_LABEL:
|
||||||
|
// Allow _property_append to handle the label
|
||||||
|
return EINA_TRUE;
|
||||||
|
|
||||||
|
case ELM_DBUS_PROPERTY_CHILDREN_DISPLAY:
|
||||||
|
if (eina_list_count(item->submenu.items)) return EINA_TRUE;
|
||||||
|
return EINA_FALSE;
|
||||||
|
|
||||||
|
case ELM_DBUS_PROPERTY_ENABLED:
|
||||||
|
item_obj = (Elm_Object_Item *)item;
|
||||||
|
return elm_object_item_disabled_get(item_obj);
|
||||||
|
|
||||||
|
case ELM_DBUS_PROPERTY_TYPE:
|
||||||
|
case ELM_DBUS_PROPERTY_UNKNOWN:
|
||||||
|
return EINA_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ERR("Invalid code path");
|
||||||
|
return EINA_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
// Ad-hoc dbusmenu property dictionary subset implementation
|
// Ad-hoc dbusmenu property dictionary subset implementation
|
||||||
|
// Depends on _property_exists results
|
||||||
static void
|
static void
|
||||||
_property_append(Elm_Menu_Item *item,
|
_property_append(Elm_Menu_Item *item,
|
||||||
Elm_DBus_Property property,
|
Elm_DBus_Property property,
|
||||||
|
@ -115,7 +151,6 @@ _property_append(Elm_Menu_Item *item,
|
||||||
EDBus_Message_Iter *variant = NULL;
|
EDBus_Message_Iter *variant = NULL;
|
||||||
Elm_Object_Item *item_obj = (Elm_Object_Item *)item;
|
Elm_Object_Item *item_obj = (Elm_Object_Item *)item;
|
||||||
const char *t;
|
const char *t;
|
||||||
Eina_Bool b;
|
|
||||||
|
|
||||||
switch (property)
|
switch (property)
|
||||||
{
|
{
|
||||||
|
@ -128,28 +163,17 @@ _property_append(Elm_Menu_Item *item,
|
||||||
|
|
||||||
case ELM_DBUS_PROPERTY_CHILDREN_DISPLAY:
|
case ELM_DBUS_PROPERTY_CHILDREN_DISPLAY:
|
||||||
variant = edbus_message_iter_container_new(iter, 'v', "s");
|
variant = edbus_message_iter_container_new(iter, 'v', "s");
|
||||||
|
edbus_message_iter_basic_append(variant, 's', "submenu");
|
||||||
if (eina_list_count(item->submenu.items))
|
|
||||||
t = "submenu";
|
|
||||||
else
|
|
||||||
t = "";
|
|
||||||
|
|
||||||
edbus_message_iter_basic_append(variant, 's', t);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ELM_DBUS_PROPERTY_ENABLED:
|
case ELM_DBUS_PROPERTY_ENABLED:
|
||||||
variant = edbus_message_iter_container_new(iter, 'v', "b");
|
variant = edbus_message_iter_container_new(iter, 'v', "b");
|
||||||
b = !elm_object_item_disabled_get(item_obj);
|
edbus_message_iter_basic_append(variant, 'b', EINA_FALSE);
|
||||||
edbus_message_iter_basic_append(variant, 'b', b);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ELM_DBUS_PROPERTY_TYPE:
|
case ELM_DBUS_PROPERTY_TYPE:
|
||||||
variant = edbus_message_iter_container_new(iter, 'v', "s");
|
variant = edbus_message_iter_container_new(iter, 'v', "s");
|
||||||
if (item->separator)
|
edbus_message_iter_basic_append(variant, 's', "separator");
|
||||||
t = "separator";
|
|
||||||
else
|
|
||||||
t = "standard";
|
|
||||||
edbus_message_iter_basic_append(variant, 's', t);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ELM_DBUS_PROPERTY_UNKNOWN:
|
case ELM_DBUS_PROPERTY_UNKNOWN:
|
||||||
|
@ -176,6 +200,7 @@ _property_dict_build(Elm_Menu_Item *item,
|
||||||
property = _str_to_property(propstr);
|
property = _str_to_property(propstr);
|
||||||
|
|
||||||
if (property == ELM_DBUS_PROPERTY_UNKNOWN) continue;
|
if (property == ELM_DBUS_PROPERTY_UNKNOWN) continue;
|
||||||
|
if (!_property_exists(item, property)) continue;
|
||||||
|
|
||||||
pair = edbus_message_iter_container_new(array, 'e', NULL);
|
pair = edbus_message_iter_container_new(array, 'e', NULL);
|
||||||
edbus_message_iter_basic_append(pair, 's', propstr);
|
edbus_message_iter_basic_append(pair, 's', propstr);
|
||||||
|
@ -528,6 +553,13 @@ _method_property_get(const EDBus_Service_Interface *iface,
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_property_exists(item, property))
|
||||||
|
{
|
||||||
|
reply = edbus_message_error_new(msg, DBUS_INTERFACE ".Error",
|
||||||
|
"Property not found");
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
reply = edbus_message_method_return_new(msg);
|
reply = edbus_message_method_return_new(msg);
|
||||||
iter = edbus_message_iter_get(reply);
|
iter = edbus_message_iter_get(reply);
|
||||||
_property_append(item, property, iter);
|
_property_append(item, property, iter);
|
||||||
|
|
Loading…
Reference in New Issue