Add a common error infratructure for widget_tell
Signed-off-by: Marco Candrian <mac@calmar.ws>
This commit is contained in:
parent
3efadded39
commit
0e69534a65
13
structs.h
13
structs.h
|
@ -91,6 +91,17 @@ struct Button
|
||||||
Button *next;
|
Button *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Widget tell status code */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
WIDGET_NOERROR = 0,
|
||||||
|
WIDGET_ERROR,
|
||||||
|
WIDGET_ERROR_CUSTOM,
|
||||||
|
WIDGET_ERROR_FORMAT_BOOL,
|
||||||
|
WIDGET_ERROR_FORMAT_FONT,
|
||||||
|
WIDGET_ERROR_FORMAT_SECTION
|
||||||
|
} widget_tell_status_t;
|
||||||
|
|
||||||
/** Widget */
|
/** Widget */
|
||||||
typedef struct Widget Widget;
|
typedef struct Widget Widget;
|
||||||
typedef struct Statusbar Statusbar;
|
typedef struct Statusbar Statusbar;
|
||||||
|
@ -101,7 +112,7 @@ struct Widget
|
||||||
/** Draw function */
|
/** Draw function */
|
||||||
int (*draw)(Widget *, DrawCtx *, int, int);
|
int (*draw)(Widget *, DrawCtx *, int, int);
|
||||||
/** Update function */
|
/** Update function */
|
||||||
void (*tell)(Widget *, char *, char *);
|
widget_tell_status_t (*tell)(Widget *, char *, char *);
|
||||||
/** ButtonPressedEvent handler */
|
/** ButtonPressedEvent handler */
|
||||||
void (*button_press)(Widget *, XButtonPressedEvent *);
|
void (*button_press)(Widget *, XButtonPressedEvent *);
|
||||||
/** Statusbar */
|
/** Statusbar */
|
||||||
|
|
27
widget.c
27
widget.c
|
@ -128,12 +128,14 @@ widget_common_button_press(Widget *widget, XButtonPressedEvent *ev)
|
||||||
* cannot be told anything
|
* cannot be told anything
|
||||||
* \param widget the widget
|
* \param widget the widget
|
||||||
* \param command unused argument
|
* \param command unused argument
|
||||||
|
* \return widget_tell_status_t enum (strucs.h)
|
||||||
*/
|
*/
|
||||||
static void
|
static widget_tell_status_t
|
||||||
widget_common_tell(Widget *widget, char *property __attribute__ ((unused)),
|
widget_common_tell(Widget *widget, char *property __attribute__ ((unused)),
|
||||||
char *command __attribute__ ((unused)))
|
char *command __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
warn("%s widget does not accept commands.\n", widget->name);
|
warn("%s widget does not accept commands.\n", widget->name);
|
||||||
|
return WIDGET_ERROR_CUSTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Common function for creating a widget
|
/** Common function for creating a widget
|
||||||
|
@ -222,7 +224,28 @@ uicb_widget_tell(int screen, char *arg)
|
||||||
len = a_strlen(p);
|
len = a_strlen(p);
|
||||||
command = p_new(char, len + 1);
|
command = p_new(char, len + 1);
|
||||||
a_strncpy(command, len + 1, p, len);
|
a_strncpy(command, len + 1, p, len);
|
||||||
widget->tell(widget, property, command);
|
switch(widget->tell(widget, property, command))
|
||||||
|
{
|
||||||
|
case WIDGET_ERROR:
|
||||||
|
warn("error changing property %s of widget %s\n",
|
||||||
|
property, widget->name);
|
||||||
|
break;
|
||||||
|
case WIDGET_ERROR_FORMAT_BOOL:
|
||||||
|
warn("error changing property %s of widget %s, must is boolean (0 or 1)\n",
|
||||||
|
property, widget->name);
|
||||||
|
break;
|
||||||
|
case WIDGET_ERROR_FORMAT_FONT:
|
||||||
|
warn("error changing property %s of widget %s, must be a valid font\n",
|
||||||
|
property, widget->name);
|
||||||
|
break;
|
||||||
|
case WIDGET_ERROR_FORMAT_SECTION:
|
||||||
|
warn("error changing property %s of widget %s, section not found\n",
|
||||||
|
property, widget->name);
|
||||||
|
break;
|
||||||
|
case WIDGET_NOERROR:
|
||||||
|
case WIDGET_ERROR_CUSTOM:
|
||||||
|
break;
|
||||||
|
}
|
||||||
p_delete(&command);
|
p_delete(&command);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -174,7 +174,7 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
return widget->area.width;
|
return widget->area.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static widget_tell_status_t
|
||||||
graph_tell(Widget *widget, char *property, char *command)
|
graph_tell(Widget *widget, char *property, char *command)
|
||||||
{
|
{
|
||||||
Data *d = widget->data;
|
Data *d = widget->data;
|
||||||
|
@ -183,7 +183,7 @@ graph_tell(Widget *widget, char *property, char *command)
|
||||||
char *title, *setting;
|
char *title, *setting;
|
||||||
|
|
||||||
if(!property || !command || d->width < 1 || !(d->data_items > 0))
|
if(!property || !command || d->width < 1 || !(d->data_items > 0))
|
||||||
return;
|
return WIDGET_ERROR;
|
||||||
|
|
||||||
if(!a_strcmp(property, "data"))
|
if(!a_strcmp(property, "data"))
|
||||||
{
|
{
|
||||||
|
@ -237,38 +237,28 @@ graph_tell(Widget *widget, char *property, char *command)
|
||||||
else
|
else
|
||||||
d->lines[i][d->index[i]] = d->box_height;
|
d->lines[i][d->index[i]] = d->box_height;
|
||||||
}
|
}
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
warn("No such data-section title: %s\n", title);
|
warn("no such data-section title: %s\n", title);
|
||||||
|
return WIDGET_ERROR;
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "width"))
|
else if(!a_strcmp(property, "width"))
|
||||||
d->width = atoi(command);
|
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"))
|
else if(!a_strcmp(property, "padding_left"))
|
||||||
d->padding_left = atoi(command);
|
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),
|
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
||||||
command, &d->bg);
|
command, &d->bg);
|
||||||
|
|
||||||
else if(!a_strcmp(property, "bordercolor"))
|
else if(!a_strcmp(property, "bordercolor"))
|
||||||
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
||||||
command, &d->bordercolor);
|
command, &d->bordercolor);
|
||||||
|
|
||||||
else if(!a_strcmp(property, "fg") || !a_strcmp(property, "fg_center") ||
|
|
||||||
!a_strcmp(property, "fg_end") || !a_strcmp(property, "scale") ||
|
|
||||||
!a_strcmp(property, "max") || !a_strcmp(property, "style") ||
|
|
||||||
!a_strcmp(property, "align") || !a_strcmp(property, "mouse") ||
|
|
||||||
!a_strcmp(property, "x") || !a_strcmp(property, "y"))
|
|
||||||
warn("Property \"%s\" can't get changed.\n", property);
|
|
||||||
else
|
else
|
||||||
warn("No such property: %s\n", property);
|
return WIDGET_ERROR;
|
||||||
|
|
||||||
return;
|
return WIDGET_NOERROR;;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
|
|
|
@ -63,13 +63,14 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
return widget->area.width;
|
return widget->area.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static widget_tell_status_t
|
||||||
iconbox_tell(Widget *widget, char *property, char *command)
|
iconbox_tell(Widget *widget, char *property, char *command)
|
||||||
{
|
{
|
||||||
|
Bool b;
|
||||||
Data *d = widget->data;
|
Data *d = widget->data;
|
||||||
|
|
||||||
if(!property || !command)
|
if(!property || !command)
|
||||||
return;
|
return WIDGET_ERROR;
|
||||||
|
|
||||||
if(!a_strcmp(property, "image"))
|
if(!a_strcmp(property, "image"))
|
||||||
{
|
{
|
||||||
|
@ -77,25 +78,17 @@ iconbox_tell(Widget *widget, char *property, char *command)
|
||||||
p_delete(&d->image);
|
p_delete(&d->image);
|
||||||
d->image = a_strdup(command);
|
d->image = a_strdup(command);
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "resize")) /* XXX how to ignorecase compare? */
|
else if(!a_strcmp(property, "resize"))
|
||||||
{
|
{
|
||||||
if(!a_strcmp(command, "true") || !a_strcmp(command, "1"))
|
if((b = cfg_parse_boolean(command)) != -1)
|
||||||
d->resize = True;
|
d->resize = b;
|
||||||
else if (!a_strcmp(command, "false") || !a_strcmp(command, "0"))
|
|
||||||
d->resize = False;
|
|
||||||
else
|
else
|
||||||
warn("Resize value must be (case-sensitive) \"true\", \"false\",\
|
return WIDGET_ERROR_FORMAT_BOOL;
|
||||||
\"1\" or \"0\". But is: %s.\n", command);
|
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "align") || !a_strcmp(property, "mouse") ||
|
|
||||||
!a_strcmp(property, "x") || !a_strcmp(property, "y"))
|
|
||||||
warn("Property \"%s\" can't get changed.\n", property);
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
return WIDGET_ERROR;
|
||||||
warn("No such property: %s\n", property);
|
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
|
|
|
@ -119,7 +119,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
|
||||||
return widget->area.width;
|
return widget->area.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
||||||
|
@ -128,7 +128,7 @@ progressbar_tell(Widget *widget, char *property, char *command)
|
||||||
char *title, *setting;
|
char *title, *setting;
|
||||||
|
|
||||||
if(!property || !command || !d->data_items)
|
if(!property || !command || !d->data_items)
|
||||||
return;
|
return WIDGET_ERROR;
|
||||||
|
|
||||||
if(!a_strcmp(property, "data"))
|
if(!a_strcmp(property, "data"))
|
||||||
{
|
{
|
||||||
|
@ -139,9 +139,9 @@ progressbar_tell(Widget *widget, char *property, char *command)
|
||||||
{
|
{
|
||||||
percent = atoi(setting);
|
percent = atoi(setting);
|
||||||
d->percent[i] = (percent < 0 ? 0 : (percent > 100 ? 100 : percent));
|
d->percent[i] = (percent < 0 ? 0 : (percent > 100 ? 100 : percent));
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
warn("No such data section title: %s\n", title);
|
return WIDGET_ERROR_FORMAT_SECTION;
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "fg"))
|
else if(!a_strcmp(property, "fg"))
|
||||||
{
|
{
|
||||||
|
@ -152,9 +152,9 @@ progressbar_tell(Widget *widget, char *property, char *command)
|
||||||
{
|
{
|
||||||
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
||||||
setting, &d->fg[i]);
|
setting, &d->fg[i]);
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
warn("No such data section title: %s\n", title);
|
return WIDGET_ERROR_FORMAT_SECTION;
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "bg"))
|
else if(!a_strcmp(property, "bg"))
|
||||||
{
|
{
|
||||||
|
@ -165,9 +165,9 @@ progressbar_tell(Widget *widget, char *property, char *command)
|
||||||
{
|
{
|
||||||
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
||||||
setting, &d->bg[i]);
|
setting, &d->bg[i]);
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
warn("No such data section title: %s\n", title);
|
return WIDGET_ERROR_FORMAT_SECTION;
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "fg_center"))
|
else if(!a_strcmp(property, "fg_center"))
|
||||||
{
|
{
|
||||||
|
@ -189,9 +189,9 @@ progressbar_tell(Widget *widget, char *property, char *command)
|
||||||
p_delete(&d->pfg_center[i]);
|
p_delete(&d->pfg_center[i]);
|
||||||
d->pfg_center[i] = NULL;
|
d->pfg_center[i] = NULL;
|
||||||
}
|
}
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
warn("No such data section title: %s\n", title);
|
return WIDGET_ERROR_FORMAT_SECTION;
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "fg_end"))
|
else if(!a_strcmp(property, "fg_end"))
|
||||||
{
|
{
|
||||||
|
@ -213,9 +213,8 @@ progressbar_tell(Widget *widget, char *property, char *command)
|
||||||
p_delete(&d->pfg_end[i]);
|
p_delete(&d->pfg_end[i]);
|
||||||
d->pfg_end[i] = NULL;
|
d->pfg_end[i] = NULL;
|
||||||
}
|
}
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
warn("No such data section title: %s\n", title);
|
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "bordercolor"))
|
else if(!a_strcmp(property, "bordercolor"))
|
||||||
{
|
{
|
||||||
|
@ -226,34 +225,27 @@ progressbar_tell(Widget *widget, char *property, char *command)
|
||||||
{
|
{
|
||||||
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
draw_color_new(globalconf.display, get_phys_screen(widget->statusbar->screen),
|
||||||
setting, &d->bordercolor[i]);
|
setting, &d->bordercolor[i]);
|
||||||
return;
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
warn("No such data section title: %s\n", title);
|
return WIDGET_ERROR_FORMAT_SECTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(!a_strcmp(property, "gap"))
|
else if(!a_strcmp(property, "gap"))
|
||||||
d->gap = atoi(command);
|
d->gap = atoi(command);
|
||||||
|
|
||||||
else if(!a_strcmp(property, "width"))
|
else if(!a_strcmp(property, "width"))
|
||||||
{
|
{
|
||||||
d->width = atoi(command);
|
d->width = atoi(command);
|
||||||
if(d->width - d->padding < 3)
|
if(d->width - d->padding < 3)
|
||||||
warn("Progressbar widget needs: (width - padding) >= 3\n");
|
warn("progressbar widget needs: (width - padding) >= 3\n");
|
||||||
|
return WIDGET_ERROR_CUSTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
d->padding = atoi(command);
|
||||||
|
|
||||||
else if(!a_strcmp(property, "align") || !a_strcmp(property, "mouse") ||
|
|
||||||
!a_strcmp(property, "x") || !a_strcmp(property, "y"))
|
|
||||||
warn("Property \"%s\" can't get changed.\n", property);
|
|
||||||
|
|
||||||
else
|
else
|
||||||
warn("No such property: %s\n", property);
|
return WIDGET_ERROR;
|
||||||
return;
|
|
||||||
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
|
@ -280,7 +272,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
||||||
|
|
||||||
if(!(d->data_items = cfg_size(config, "data")))
|
if(!(d->data_items = cfg_size(config, "data")))
|
||||||
{
|
{
|
||||||
warn("Progressbar widget needs at least one bar section\n");
|
warn("progressbar widget needs at least one bar section\n");
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +321,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
||||||
/* complete setup, since someone might 'enable' it with increasing the width with widget_tell */
|
/* complete setup, since someone might 'enable' it with increasing the width with widget_tell */
|
||||||
if(d->width - d->padding < 3)
|
if(d->width - d->padding < 3)
|
||||||
{
|
{
|
||||||
warn("Progressbar widget needs: (width - padding) >= 3\n");
|
warn("progressbar widget needs: (width - padding) >= 3\n");
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,13 +64,13 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
|
||||||
return widget->area.width;
|
return widget->area.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static widget_tell_status_t
|
||||||
textbox_tell(Widget *widget, char *property, char *command)
|
textbox_tell(Widget *widget, char *property, char *command)
|
||||||
{
|
{
|
||||||
Data *d = widget->data;
|
Data *d = widget->data;
|
||||||
|
|
||||||
if(!property || !command)
|
if(!property || !command)
|
||||||
return;
|
return WIDGET_ERROR;
|
||||||
|
|
||||||
if(!a_strcmp(property, "text"))
|
if(!a_strcmp(property, "text"))
|
||||||
{
|
{
|
||||||
|
@ -80,38 +80,26 @@ textbox_tell(Widget *widget, char *property, char *command)
|
||||||
}
|
}
|
||||||
else if(!a_strcmp(property, "fg"))
|
else if(!a_strcmp(property, "fg"))
|
||||||
draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->fg);
|
draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->fg);
|
||||||
|
|
||||||
else if(!a_strcmp(property, "bg"))
|
else if(!a_strcmp(property, "bg"))
|
||||||
draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->bg);
|
draw_color_new(globalconf.display, widget->statusbar->screen, command, &d->bg);
|
||||||
|
|
||||||
else if(!a_strcmp(property, "font"))
|
else if(!a_strcmp(property, "font"))
|
||||||
{
|
{
|
||||||
widget->font = XftFontOpenName(globalconf.display,
|
widget->font = XftFontOpenName(globalconf.display,
|
||||||
get_phys_screen(widget->statusbar->screen), command);
|
get_phys_screen(widget->statusbar->screen), command);
|
||||||
if(!widget->font)
|
if(!widget->font)
|
||||||
|
{
|
||||||
widget->font = globalconf.screens[widget->statusbar->screen].font;
|
widget->font = globalconf.screens[widget->statusbar->screen].font;
|
||||||
|
return WIDGET_ERROR_FORMAT_FONT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(!a_strcmp(property, "width"))
|
else if(!a_strcmp(property, "width"))
|
||||||
d->width = atoi(command);
|
d->width = atoi(command);
|
||||||
|
|
||||||
else if(!a_strcmp(property, "text_align"))
|
else if(!a_strcmp(property, "text_align"))
|
||||||
{
|
d->align = draw_get_align(command);
|
||||||
if(!a_strcmp(command, "center") || !a_strcmp(command, "left") ||
|
|
||||||
!a_strcmp(command, "right"))
|
|
||||||
d->align = draw_get_align(command);
|
|
||||||
else
|
|
||||||
warn("text_align value must be (case-sensitive) \"center\", \"left\",\
|
|
||||||
or \"right\". But is: %s.\n", command);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(!a_strcmp(property, "align") || !a_strcmp(property, "mouse") ||
|
|
||||||
!a_strcmp(property, "x") || !a_strcmp(property, "y"))
|
|
||||||
warn("Property \"%s\" can't get changed.\n", property);
|
|
||||||
|
|
||||||
else
|
else
|
||||||
warn("No such property: %s\n", property);
|
return WIDGET_ERROR;
|
||||||
return;
|
|
||||||
|
return WIDGET_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget *
|
Widget *
|
||||||
|
|
Loading…
Reference in New Issue