Commit de046ba09a5b84918848170cb073471ee95671dc
1 parent
6dc92b98
Exists in
master
and in
4 other branches
Parsing keypad model elements.
Showing
3 changed files
with
45 additions
and
12 deletions
Show diff stats
src/objects/keypad/keypad.c
@@ -59,6 +59,11 @@ | @@ -59,6 +59,11 @@ | ||
59 | 59 | ||
60 | KeypadModel * model = PW_KEYPAD_MODEL(object); | 60 | KeypadModel * model = PW_KEYPAD_MODEL(object); |
61 | 61 | ||
62 | + if(model->elements) { | ||
63 | + g_list_free_full(model->elements,g_object_unref); | ||
64 | + model->elements = NULL; | ||
65 | + } | ||
66 | + | ||
62 | if(model->name) { | 67 | if(model->name) { |
63 | g_free(model->name); | 68 | g_free(model->name); |
64 | model->name = NULL; | 69 | model->name = NULL; |
@@ -139,7 +144,6 @@ | @@ -139,7 +144,6 @@ | ||
139 | 144 | ||
140 | static void KeypadModel_init(KeypadModel *object) { | 145 | static void KeypadModel_init(KeypadModel *object) { |
141 | 146 | ||
142 | - | ||
143 | } | 147 | } |
144 | 148 | ||
145 | static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { | 149 | static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { |
@@ -235,14 +239,14 @@ | @@ -235,14 +239,14 @@ | ||
235 | return "undefined"; | 239 | return "undefined"; |
236 | } | 240 | } |
237 | 241 | ||
238 | - static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, KeypadModel *model, GError **error) { | 242 | + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, KeypadModel *keypad, GError **error) { |
239 | 243 | ||
240 | debug("%s(%s)",__FUNCTION__,element_name); | 244 | debug("%s(%s)",__FUNCTION__,element_name); |
241 | 245 | ||
242 | if(!g_ascii_strcasecmp(element_name,"button")) { | 246 | if(!g_ascii_strcasecmp(element_name,"button")) { |
243 | 247 | ||
244 | const gchar *row, *col, *width, *height; | 248 | const gchar *row, *col, *width, *height; |
245 | - GObject * element = g_object_new(PW_TYPE_KEYPAD_ELEMENT,NULL); | 249 | + KeypadElement * element = PW_KEYPAD_ELEMENT(g_object_new(PW_TYPE_KEYPAD_ELEMENT,NULL)); |
246 | 250 | ||
247 | if(!g_markup_collect_attributes( | 251 | if(!g_markup_collect_attributes( |
248 | element_name,names,values,error, | 252 | element_name,names,values,error, |
@@ -258,39 +262,59 @@ | @@ -258,39 +262,59 @@ | ||
258 | } | 262 | } |
259 | 263 | ||
260 | if(row) { | 264 | if(row) { |
261 | - PW_KEYPAD_ELEMENT(element)->width = (unsigned short) atoi(row); | 265 | + element->row = (unsigned short) atoi(row); |
266 | + } else { | ||
267 | + element->row = keypad->current.row; | ||
262 | } | 268 | } |
263 | 269 | ||
264 | if(col) { | 270 | if(col) { |
265 | - PW_KEYPAD_ELEMENT(element)->width = (unsigned short) atoi(col); | 271 | + element->col = (unsigned short) atoi(col); |
272 | + } else { | ||
273 | + element->col = keypad->current.col; | ||
266 | } | 274 | } |
267 | 275 | ||
268 | if(width) { | 276 | if(width) { |
269 | - PW_KEYPAD_ELEMENT(element)->width = (unsigned short) atoi(width); | 277 | + element->width = (unsigned short) atoi(width); |
278 | + } else { | ||
279 | + element->width = 1; | ||
270 | } | 280 | } |
271 | 281 | ||
272 | if(height) { | 282 | if(height) { |
273 | - PW_KEYPAD_MODEL(element)->height = (unsigned short) atoi(height); | 283 | + element->height = (unsigned short) atoi(height); |
284 | + } else { | ||
285 | + element->height = 1; | ||
274 | } | 286 | } |
275 | 287 | ||
276 | - keypad_model_element_parse_context(element,context); | 288 | + keypad->elements = g_list_prepend(keypad->elements,element); |
289 | + keypad_model_element_parse_context(G_OBJECT(element),context); | ||
277 | 290 | ||
278 | } | 291 | } |
279 | 292 | ||
280 | 293 | ||
281 | } | 294 | } |
282 | 295 | ||
283 | - static void element_end(GMarkupParseContext *context, const gchar *element_name, GList *keypads, GError **error) { | 296 | + static void element_end(GMarkupParseContext *context, const gchar *element_name, KeypadModel *keypad, GError **error) { |
284 | 297 | ||
285 | debug("%s(%s)",__FUNCTION__,element_name); | 298 | debug("%s(%s)",__FUNCTION__,element_name); |
286 | 299 | ||
287 | if(!g_ascii_strcasecmp(element_name,"button")) { | 300 | if(!g_ascii_strcasecmp(element_name,"button")) { |
288 | g_markup_parse_context_pop(context); | 301 | g_markup_parse_context_pop(context); |
302 | + | ||
303 | + KeypadElement * element = PW_KEYPAD_ELEMENT(g_list_first(keypad->elements)->data); | ||
304 | + | ||
305 | + keypad->current.row = element->row; | ||
306 | + keypad->current.col = element->col + element->width; | ||
307 | + | ||
308 | + if(keypad->width && keypad->current.col >= keypad->width) { | ||
309 | + keypad->current.col = 0; | ||
310 | + keypad->current.row++; | ||
311 | + } | ||
312 | + | ||
289 | } | 313 | } |
290 | 314 | ||
291 | } | 315 | } |
292 | 316 | ||
293 | - void keypad_model_parse_context(GObject *model, GMarkupParseContext *context) { | 317 | + void keypad_model_parse_context(GObject *object, GMarkupParseContext *context) { |
294 | 318 | ||
295 | static const GMarkupParser parser = { | 319 | static const GMarkupParser parser = { |
296 | (void (*)(GMarkupParseContext *, const gchar *, const gchar **, const gchar **, gpointer, GError **)) | 320 | (void (*)(GMarkupParseContext *, const gchar *, const gchar **, const gchar **, gpointer, GError **)) |
@@ -303,6 +327,10 @@ | @@ -303,6 +327,10 @@ | ||
303 | NULL | 327 | NULL |
304 | }; | 328 | }; |
305 | 329 | ||
330 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | ||
331 | + | ||
332 | + model->elements = g_list_reverse(model->elements); | ||
306 | g_markup_parse_context_push(context, &parser, model); | 333 | g_markup_parse_context_push(context, &parser, model); |
334 | + model->elements = g_list_reverse(model->elements); | ||
307 | 335 | ||
308 | } | 336 | } |
src/objects/keypad/load.c
@@ -100,10 +100,9 @@ | @@ -100,10 +100,9 @@ | ||
100 | NULL | 100 | NULL |
101 | }; | 101 | }; |
102 | 102 | ||
103 | - GMarkupParseContext * context = g_markup_parse_context_new(&parser,G_MARKUP_TREAT_CDATA_AS_TEXT,keypads,NULL); | 103 | + GMarkupParseContext * context = g_markup_parse_context_new(&parser,G_MARKUP_TREAT_CDATA_AS_TEXT,keypads,NULL); |
104 | g_markup_parse_context_parse(context,text,strlen(text),&error); | 104 | g_markup_parse_context_parse(context,text,strlen(text),&error); |
105 | g_markup_parse_context_free(context); | 105 | g_markup_parse_context_free(context); |
106 | - | ||
107 | } | 106 | } |
108 | 107 | ||
109 | if(error) { | 108 | if(error) { |
src/objects/keypad/private.h
@@ -85,9 +85,15 @@ | @@ -85,9 +85,15 @@ | ||
85 | unsigned short height; | 85 | unsigned short height; |
86 | unsigned short position; | 86 | unsigned short position; |
87 | 87 | ||
88 | + struct { | ||
89 | + unsigned short row; | ||
90 | + unsigned short col; | ||
91 | + } current; | ||
92 | + | ||
88 | gchar *name; | 93 | gchar *name; |
89 | gchar *label; | 94 | gchar *label; |
90 | 95 | ||
96 | + GList *elements; | ||
91 | 97 | ||
92 | }; | 98 | }; |
93 | 99 |