diff options
author | Thorsten Wißmann <edu@thorsten-wissmann.de> | 2013-01-06 15:33:43 +0100 |
---|---|---|
committer | Thorsten Wißmann <edu@thorsten-wissmann.de> | 2013-02-17 12:23:59 +0100 |
commit | c1b7dc8fa6a77a1712665489e039d3f8098555f4 (patch) | |
tree | be8dbe50974bbf1ed6f198fff280e33a81593737 /src/object.c | |
parent | d6e4544a26a78064ba02df2c2b201b027658fbbd (diff) |
Add attribute handling to objects
Diffstat (limited to 'src/object.c')
-rw-r--r-- | src/object.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/src/object.c b/src/object.c index bc1bdd28..398f00cd 100644 --- a/src/object.c +++ b/src/object.c @@ -34,6 +34,8 @@ HSObject* hsobject_root() { } bool hsobject_init(HSObject* obj) { + obj->attributes = NULL; + obj->attribute_count = 0; obj->children = NULL; return true; } @@ -143,10 +145,26 @@ int list_objects_command(int argc, char* argv[], GString* output) { return HERBST_INVALID_ARGUMENT; } } - // list object contents - // TODO: list attributes + // list attributes + g_string_append_printf(output, "attributes:\n"); + for (int i = 0; i < obj->attribute_count; i++) { + HSAttribute* a = obj->attributes + i; + g_string_append_printf(output, "%-20s = ", a->name); + switch (a->type) { + case HSATTR_TYPE_BOOL: + if (*(a->value.b)) { + g_string_append_printf(output, "true\n"); + } else { + g_string_append_printf(output, "false\n"); + } + break; + case HSATTR_TYPE_STRING: + g_string_append_printf(output, "\"%s\"\n", (*(a->value.str))->str); + break; + } + } // list children - g_string_append_printf(output, "children:\n"); + g_string_append_printf(output, "\nchildren:\n"); g_list_foreach(obj->children, (GFunc) print_child_name, output); return 0; } @@ -197,3 +215,25 @@ int print_object_tree_command(int argc, char* argv[], GString* output) { return 0; } +bool ATTR_ACCEPT_ALL(HSObject* obj, HSAttribute* attr) { + (void) obj; + (void) attr; + return true; +} + +bool ATTR_DENY_ALL(HSObject* obj, HSAttribute* attr) { + (void) obj; + (void) attr; + return false; +} + +void hsobject_set_attributes(HSObject* obj, HSAttribute* attributes) { + // calculate new size + size_t count; + for (count = 0; attributes[count].name != NULL; count++) + ; + obj->attributes = g_renew(HSAttribute, obj->attributes, count); + obj->attribute_count = count; + memcpy(obj->attributes, attributes, count * sizeof(HSAttribute)); +} + |