widget error infrastructure additions

This commit is contained in:
marco candrian 2008-03-06 14:30:18 +01:00 committed by Julien Danjou
parent 0e69534a65
commit 397aa33163
5 changed files with 112 additions and 58 deletions

View File

@ -96,9 +96,11 @@ typedef enum
{ {
WIDGET_NOERROR = 0, WIDGET_NOERROR = 0,
WIDGET_ERROR, WIDGET_ERROR,
WIDGET_ERROR_NOVALUE,
WIDGET_ERROR_CUSTOM, WIDGET_ERROR_CUSTOM,
WIDGET_ERROR_FORMAT_BOOL, WIDGET_ERROR_FORMAT_BOOL,
WIDGET_ERROR_FORMAT_FONT, WIDGET_ERROR_FORMAT_FONT,
WIDGET_ERROR_FORMAT_COLOR,
WIDGET_ERROR_FORMAT_SECTION WIDGET_ERROR_FORMAT_SECTION
} widget_tell_status_t; } widget_tell_status_t;

View File

@ -230,6 +230,10 @@ uicb_widget_tell(int screen, char *arg)
warn("error changing property %s of widget %s\n", warn("error changing property %s of widget %s\n",
property, widget->name); property, widget->name);
break; break;
case WIDGET_ERROR_NOVALUE:
warn("error changing property %s of widget %s, no value given\n",
property, widget->name);
break;
case WIDGET_ERROR_FORMAT_BOOL: case WIDGET_ERROR_FORMAT_BOOL:
warn("error changing property %s of widget %s, must is boolean (0 or 1)\n", warn("error changing property %s of widget %s, must is boolean (0 or 1)\n",
property, widget->name); property, widget->name);
@ -238,8 +242,12 @@ uicb_widget_tell(int screen, char *arg)
warn("error changing property %s of widget %s, must be a valid font\n", warn("error changing property %s of widget %s, must be a valid font\n",
property, widget->name); property, widget->name);
break; break;
case WIDGET_ERROR_FORMAT_COLOR:
warn("error changing property %s of widget %s, must be a valid color\n",
property, widget->name);
break;
case WIDGET_ERROR_FORMAT_SECTION: case WIDGET_ERROR_FORMAT_SECTION:
warn("error changing property %s of widget %s, section not found\n", warn("error changing property %s of widget %s, section/title not found\n",
property, widget->name); property, widget->name);
break; break;
case WIDGET_NOERROR: case WIDGET_NOERROR:

View File

@ -85,7 +85,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
Data *d = widget->data; Data *d = widget->data;
Area rectangle; Area rectangle;
if(d->width < 1 || !d->data_items) if(!d->data_items)
return 0; return 0;
if(!widget->user_supplied_x) if(!widget->user_supplied_x)
@ -182,13 +182,17 @@ graph_tell(Widget *widget, char *property, char *command)
float value; float value;
char *title, *setting; char *title, *setting;
if(!property || !command || d->width < 1 || !(d->data_items > 0)) if(!d->data_items)
return WIDGET_ERROR; return WIDGET_ERROR_CUSTOM; /* error already printed on _new */
if(!command)
return WIDGET_ERROR_NOVALUE;
if(!a_strcmp(property, "data")) if(!a_strcmp(property, "data"))
{ {
title = strtok(command, " "); title = strtok(command, " ");
setting = strtok(NULL, " "); if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < d->data_items; i++) for(i = 0; i < d->data_items; i++)
{ {
@ -240,25 +244,26 @@ graph_tell(Widget *widget, char *property, char *command)
return WIDGET_NOERROR; return WIDGET_NOERROR;
} }
} }
warn("no such data-section title: %s\n", title); return WIDGET_ERROR_FORMAT_SECTION;
return WIDGET_ERROR;
} }
else if(!a_strcmp(property, "width"))
d->width = atoi(command);
else if(!a_strcmp(property, "height")) else if(!a_strcmp(property, "height"))
d->height = atof(command); d->height = atof(command);
else if(!a_strcmp(property, "padding_left"))
d->padding_left = atoi(command);
else if(!a_strcmp(property, "bg")) else if(!a_strcmp(property, "bg"))
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), {
command, &d->bg); if(!draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
command, &d->bg))
return WIDGET_ERROR_FORMAT_COLOR;
}
else if(!a_strcmp(property, "bordercolor")) else if(!a_strcmp(property, "bordercolor"))
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), {
command, &d->bordercolor); if(!draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
command, &d->bordercolor))
return WIDGET_ERROR_FORMAT_COLOR;
}
else else
return WIDGET_ERROR; return WIDGET_ERROR;
return WIDGET_NOERROR;; return WIDGET_NOERROR;
} }
Widget * Widget *

View File

@ -63,7 +63,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
Data *d = widget->data; Data *d = widget->data;
if (!(d->data_items) || (d->width - d->padding < 3)) if (!d->data_items)
return 0; return 0;
width = d->width - 2 * d->padding; width = d->width - 2 * d->padding;
@ -123,17 +123,21 @@ static widget_tell_status_t
progressbar_tell(Widget *widget, char *property, char *command) progressbar_tell(Widget *widget, char *property, char *command)
{ {
Data *d = widget->data; Data *d = widget->data;
int i = 0, percent; int i = 0, percent, tmp;
Bool flag; Bool flag;
char *title, *setting; char *title, *setting;
if(!property || !command || !d->data_items) if(!d->data_items)
return WIDGET_ERROR; return WIDGET_ERROR_CUSTOM; /* error already printed on _new */
if(!command)
return WIDGET_ERROR_NOVALUE;
if(!a_strcmp(property, "data")) if(!a_strcmp(property, "data"))
{ {
title = strtok(command, " "); title = strtok(command, " ");
setting = strtok(NULL, " "); if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < d->data_items; i++) for(i = 0; i < d->data_items; i++)
if(!a_strcmp(title, d->data_title[i])) if(!a_strcmp(title, d->data_title[i]))
{ {
@ -146,49 +150,59 @@ progressbar_tell(Widget *widget, char *property, char *command)
else if(!a_strcmp(property, "fg")) else if(!a_strcmp(property, "fg"))
{ {
title = strtok(command, " "); title = strtok(command, " ");
setting = strtok(NULL, " "); if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < d->data_items; i++) for(i = 0; i < d->data_items; i++)
if(!a_strcmp(title, d->data_title[i])) if(!a_strcmp(title, d->data_title[i]))
{ {
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), if(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
setting, &d->fg[i]); setting, &d->fg[i]))
return WIDGET_NOERROR; return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
} }
return WIDGET_ERROR_FORMAT_SECTION; return WIDGET_ERROR_FORMAT_SECTION;
} }
else if(!a_strcmp(property, "bg")) else if(!a_strcmp(property, "bg"))
{ {
title = strtok(command, " "); title = strtok(command, " ");
setting = strtok(NULL, " "); if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < d->data_items; i++) for(i = 0; i < d->data_items; i++)
if(!a_strcmp(title, d->data_title[i])) if(!a_strcmp(title, d->data_title[i]))
{ {
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), if(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
setting, &d->bg[i]); setting, &d->bg[i]))
return WIDGET_NOERROR; return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
} }
return WIDGET_ERROR_FORMAT_SECTION; return WIDGET_ERROR_FORMAT_SECTION;
} }
else if(!a_strcmp(property, "fg_center")) else if(!a_strcmp(property, "fg_center"))
{ {
title = strtok(command, " "); title = strtok(command, " ");
setting = strtok(NULL, " "); if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < d->data_items; i++) for(i = 0; i < d->data_items; i++)
if(!a_strcmp(title, d->data_title[i])) if(!a_strcmp(title, d->data_title[i]))
{ {
flag = False; flag = False;
if(!d->pfg_center[i]) if(!d->pfg_center[i])
{ {
flag = True; /* restore to NULL & p_delete */ flag = True; /* p_delete && restore to NULL, if draw_color_new unsuccessful */
d->pfg_center[i] = p_new(XColor, 1); d->pfg_center[i] = p_new(XColor, 1);
} }
if(!(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), if(!(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
setting, d->pfg_center[i]))) setting, d->pfg_center[i])))
{
if(flag) /* restore */ if(flag) /* restore */
{ {
p_delete(&d->pfg_center[i]); p_delete(&d->pfg_center[i]);
d->pfg_center[i] = NULL; d->pfg_center[i] = NULL;
} }
return WIDGET_ERROR_FORMAT_COLOR;
}
return WIDGET_NOERROR; return WIDGET_NOERROR;
} }
return WIDGET_ERROR_FORMAT_SECTION; return WIDGET_ERROR_FORMAT_SECTION;
@ -196,36 +210,43 @@ progressbar_tell(Widget *widget, char *property, char *command)
else if(!a_strcmp(property, "fg_end")) else if(!a_strcmp(property, "fg_end"))
{ {
title = strtok(command, " "); title = strtok(command, " ");
setting = strtok(NULL, " "); if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < d->data_items; i++) for(i = 0; i < d->data_items; i++)
if(!a_strcmp(title, d->data_title[i])) if(!a_strcmp(title, d->data_title[i]))
{ {
flag = False; flag = False;
if(!d->pfg_end[i]) if(!d->pfg_end[i])
{ {
flag = True; /* restore to NULL & p_delete */ flag = True;
d->pfg_end[i] = p_new(XColor, 1); d->pfg_end[i] = p_new(XColor, 1);
} }
if(!(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), if(!(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
setting, d->pfg_end[i]))) setting, d->pfg_end[i])))
{
if(flag) /* restore */ if(flag) /* restore */
{ {
p_delete(&d->pfg_end[i]); p_delete(&d->pfg_end[i]);
d->pfg_end[i] = NULL; d->pfg_end[i] = NULL;
} }
return WIDGET_ERROR_FORMAT_COLOR;
}
return WIDGET_NOERROR; return WIDGET_NOERROR;
} }
} }
else if(!a_strcmp(property, "bordercolor")) else if(!a_strcmp(property, "bordercolor"))
{ {
title = strtok(command, " "); title = strtok(command, " ");
setting = strtok(NULL, " "); if(!(setting = strtok(NULL, " ")))
return WIDGET_ERROR_NOVALUE;
for(i = 0; i < d->data_items; i++) for(i = 0; i < d->data_items; i++)
if(!a_strcmp(title, d->data_title[i])) if(!a_strcmp(title, d->data_title[i]))
{ {
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen), if(draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
setting, &d->bordercolor[i]); setting, &d->bordercolor[i]))
return WIDGET_NOERROR; return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
} }
return WIDGET_ERROR_FORMAT_SECTION; return WIDGET_ERROR_FORMAT_SECTION;
} }
@ -233,15 +254,28 @@ progressbar_tell(Widget *widget, char *property, char *command)
d->gap = atoi(command); d->gap = atoi(command);
else if(!a_strcmp(property, "width")) else if(!a_strcmp(property, "width"))
{ {
d->width = atoi(command); tmp = atoi(command);
if(d->width - d->padding < 3) if(tmp - d->padding < 3)
warn("progressbar widget needs: (width - padding) >= 3\n"); {
warn("progressbar widget needs: (width - padding) >= 3. Ignoring command.\n");
return WIDGET_ERROR_CUSTOM; return WIDGET_ERROR_CUSTOM;
} }
else
d->width = tmp;
}
else if(!a_strcmp(property, "height")) else if(!a_strcmp(property, "height"))
d->height = atof(command); d->height = atof(command);
else if(!a_strcmp(property, "padding")) else if(!a_strcmp(property, "padding"))
d->padding = atoi(command); {
tmp = atoi(command);
if(d->width - tmp < 3)
{
warn("progressbar widget needs: (width - padding) >= 3. Ignoring command.\n");
return WIDGET_ERROR_CUSTOM;
}
else
d->padding = tmp;
}
else else
return WIDGET_ERROR; return WIDGET_ERROR;
@ -263,12 +297,18 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
w->tell = progressbar_tell; w->tell = progressbar_tell;
d = w->data = p_new(Data, 1); d = w->data = p_new(Data, 1);
d->width = cfg_getint(config, "width"); d->width = cfg_getint(config, "width");
d->height = cfg_getfloat(config, "height");
d->gap = cfg_getint(config, "gap");
d->padding = cfg_getint(config, "padding"); d->padding = cfg_getint(config, "padding");
w->alignment = draw_get_align(cfg_getstr(config, "align")); if(d->width - d->padding < 3)
{
warn("progressbar widget needs: (width - padding) >= 3\n");
return w;
}
d->height = cfg_getfloat(config, "height");
d->gap = cfg_getint(config, "gap");
w->alignment = draw_get_align(cfg_getstr(config, "align"));
if(!(d->data_items = cfg_size(config, "data"))) if(!(d->data_items = cfg_size(config, "data")))
{ {
@ -318,13 +358,6 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
d->bordercolor[i] = d->fg[i]; d->bordercolor[i] = d->fg[i];
} }
/* complete setup, since someone might 'enable' it with increasing the width with widget_tell */
if(d->width - d->padding < 3)
{
warn("progressbar widget needs: (width - padding) >= 3\n");
return w;
}
return w; return w;
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -69,8 +69,8 @@ textbox_tell(Widget *widget, char *property, char *command)
{ {
Data *d = widget->data; Data *d = widget->data;
if(!property || !command) if(!command)
return WIDGET_ERROR; return WIDGET_ERROR_NOVALUE;
if(!a_strcmp(property, "text")) if(!a_strcmp(property, "text"))
{ {
@ -79,9 +79,15 @@ textbox_tell(Widget *widget, char *property, char *command)
d->text = a_strdup(command); d->text = a_strdup(command);
} }
else if(!a_strcmp(property, "fg")) else if(!a_strcmp(property, "fg"))
draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->fg); if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->fg))
return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
else if(!a_strcmp(property, "bg")) else if(!a_strcmp(property, "bg"))
draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->bg); if(draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->bg))
return WIDGET_NOERROR;
else
return WIDGET_ERROR_FORMAT_COLOR;
else if(!a_strcmp(property, "font")) else if(!a_strcmp(property, "font"))
{ {
widget->font = XftFontOpenName(globalconf.display, widget->font = XftFontOpenName(globalconf.display,