diff --git a/camlibs/directory/directory.c b/camlibs/directory/directory.c index d43191820..72eaa6292 100644 --- a/camlibs/directory/directory.c +++ b/camlibs/directory/directory.c @@ -241,18 +241,19 @@ int camera_config_get (Camera *camera, CameraWidget *window) { /* Add the Resolution setting radio buttons */ t = gp_widget_new(GP_WIDGET_RADIO, "Resolution"); gp_widget_append(section, t); - gp_widget_choice_add(t, "Normal", 0); - gp_widget_choice_add(t, "High", 0); - gp_widget_choice_add(t, "Best", 1); + gp_widget_choice_add(t, "Normal"); + gp_widget_choice_add(t, "High"); + gp_widget_choice_add(t, "Best"); + gp_widget_value_set(t, "High"); t = gp_widget_new(GP_WIDGET_TEXT, "Camera Name"); gp_widget_append(section, t); - gp_widget_text_set(t, "hey there!"); + gp_widget_value_set(t, "hey there!"); t = gp_widget_new(GP_WIDGET_RANGE, "LCD Brightness"); gp_widget_append(section, t); - gp_widget_range_set(t, 1, 7, 1, 4); - + gp_widget_range_set(t, 1.0, 7.0, 1.0); + gp_widget_value_set(t, "4.0"); /* Create a new section for "Flash/Lens" and append to window */ section = gp_widget_new(GP_WIDGET_SECTION, "Flash/Lens"); @@ -260,15 +261,17 @@ int camera_config_get (Camera *camera, CameraWidget *window) { t = gp_widget_new(GP_WIDGET_MENU, "Flash Setting"); gp_widget_append(section, t); - gp_widget_choice_add(t, "Auto", 0); - gp_widget_choice_add(t, "Red-eye", 0); - gp_widget_choice_add(t, "Force", 1); - gp_widget_choice_add(t, "None", 0); + gp_widget_choice_add(t, "Auto"); + gp_widget_choice_add(t, "Red-eye"); + gp_widget_choice_add(t, "Force"); + gp_widget_choice_add(t, "None"); + gp_widget_value_set(t, "Red-eye"); t = gp_widget_new(GP_WIDGET_RADIO, "Lens Mode"); gp_widget_append(section, t); - gp_widget_choice_add(t, "Normal", 0); - gp_widget_choice_add(t, "Macro", 1); + gp_widget_choice_add(t, "Normal"); + gp_widget_choice_add(t, "Macro"); + gp_widget_value_set(t, "Macro"); return (GP_OK); } diff --git a/include/gphoto2-core.h b/include/gphoto2-core.h index 2473c45fb..6e5d03541 100644 --- a/include/gphoto2-core.h +++ b/include/gphoto2-core.h @@ -158,26 +158,29 @@ /* Retrieve a child pointer from a parent */ CameraWidget* gp_widget_child(CameraWidget *parent, int child_number); + /* Recursively retrieve a child pointer from a parent */ + CameraWidget* gp_widget_child_by_label(CameraWidget *parent, char *child_label); + /* Get the type and label of a widget */ int gp_widget_type (CameraWidget *widget); char *gp_widget_label(CameraWidget *widget); + /* Set and Get the value of a widget */ + int gp_widget_value_set (CameraWidget *widget, char *value); + char *gp_widget_value_get (CameraWidget *widget); + + /* Range functions */ + /* ------------------------ */ + /* Set/get the value of a range widget */ - int gp_widget_range_set (CameraWidget *range, - float low, float high, float increment, float value); - int gp_widget_range_get (CameraWidget *range, - float *low, float *high, float *increment, float *value); + int gp_widget_range_set (CameraWidget *range, float low, float high, float increment); + int gp_widget_range_get (CameraWidget *range, float *low, float *high, float *increment); - /* Set/get the state of a toggle button (0 or 1) */ - int gp_widget_toggle_set (CameraWidget *toggle, int active); - int gp_widget_toggle_get (CameraWidget *toggle); - - /* Set/get the string of a text entry widget */ - int gp_widget_text_set (CameraWidget *text, char *string); - char *gp_widget_text_get (CameraWidget *text); + /* Menu and Radio functions */ + /* ------------------------ */ /* Add a choice to a menu/radio widget */ - int gp_widget_choice_add (CameraWidget *widget, char *choice, int active); + int gp_widget_choice_add (CameraWidget *widget, char *choice); /* Retrieve the number of choices in a menu/radio widget */ int gp_widget_choice_count (CameraWidget *widget); @@ -185,8 +188,8 @@ /* Retrieve a choice from a menu/radio widget */ char *gp_widget_choice (CameraWidget *widget, int choice_number); - /* Retrieve the active choice from a menu/radio widget */ - char *gp_widget_choice_active (CameraWidget *widget); + /* Debugging output */ + /* ------------------------ */ /* Debugging output to stdout. Will dump the widget and all children widgets (and their children, ...) recursively */ diff --git a/include/gphoto2-datatypes.h b/include/gphoto2-datatypes.h index ff6875d32..46dfabd80 100644 --- a/include/gphoto2-datatypes.h +++ b/include/gphoto2-datatypes.h @@ -52,16 +52,11 @@ struct CameraWidget; struct CameraWidget { - /* Publicly accessible - ------------------------------ */ CameraWidgetType type; char label[32]; - /* Private (don't access) - ------------------------------ */ /* Current value of the widget */ - float value; - char value_string[128]; + char value[128]; /* For Radio and Menu */ char choice[32][64]; diff --git a/libgphoto2/widget.c b/libgphoto2/widget.c index 2dcc231cf..28b84f724 100644 --- a/libgphoto2/widget.c +++ b/libgphoto2/widget.c @@ -17,10 +17,15 @@ CameraWidget* gp_widget_new(CameraWidgetType type, char *label) { w->type = type; strcpy(w->label, label); + /* set the value to nothing */ + strcpy(w->value, ""); + /* for now, for ease of mem management, pre-alloc 64 children pointers */ memset(w->children, 0, sizeof(CameraWidget*)*64); + w->children_count = 0; + /* clear out the choices */ for (x=0; x<32; x++) strcpy(w->choice[x], ""); w->choice_count = 0; @@ -68,6 +73,20 @@ char *gp_widget_label(CameraWidget *widget) { return (widget->label); } +/* Set and unset the value of a widget */ +/* -------------------------------------------------------------------------- */ + +int gp_widget_value_set (CameraWidget *widget, char *value) { + + strcpy(widget->value, value); + + return (GP_OK); +} + +char *gp_widget_value_get (CameraWidget *widget) { + + return (widget->value); +} /* Attach/Retrieve widgets to/from a parent widget */ /* -------------------------------------------------------------------------- */ @@ -113,7 +132,7 @@ int gp_widget_child_count(CameraWidget *parent) { return (parent->children_count); } -CameraWidget* gp_widget_child(CameraWidget *parent, int child_number) { +CameraWidget* gp_widget_child(CameraWidget *parent, int child_number) { /* Return if they can't have any children */ if ((parent->type != GP_WIDGET_WINDOW) && (parent->type != GP_WIDGET_SECTION)) @@ -122,11 +141,27 @@ CameraWidget* gp_widget_child(CameraWidget *parent, int child_number) { return (parent->children[child_number]); } +CameraWidget* gp_widget_child_by_label (CameraWidget *widget, char *label) { + + int x; + CameraWidget *child; + + if (strcmp(widget->label, label)==0) + return (widget); + + for (x=0; xchildren_count; x++) { + child = gp_widget_child_by_label(widget->children[x],label); + if (child) + return (child); + } + + return (NULL); +} /* Set/get the value of the range widget */ /* -------------------------------------------------------------------------- */ -int gp_widget_range_set (CameraWidget *range, float min, float max, float increment, float value) { +int gp_widget_range_set (CameraWidget *range, float min, float max, float increment) { if (range->type != GP_WIDGET_RANGE) return (GP_ERROR); @@ -134,12 +169,11 @@ int gp_widget_range_set (CameraWidget *range, float min, float max, float increm range->min = min; range->max = max; range->increment = increment; - range->value = value; return (GP_OK); } -int gp_widget_range_get (CameraWidget *range, float *min, float *max, float *increment, float *value) { +int gp_widget_range_get (CameraWidget *range, float *min, float *max, float *increment) { if (range->type != GP_WIDGET_RANGE) return (GP_ERROR); @@ -147,67 +181,20 @@ int gp_widget_range_get (CameraWidget *range, float *min, float *max, float *inc *min = range->min; *max = range->max; *increment = range->increment; - *value = range->value; return (GP_OK); } -/* Set/get the value of a toggle button */ -/* -------------------------------------------------------------------------- */ - -int gp_widget_toggle_set (CameraWidget *toggle, int active) { - - if (toggle->type != GP_WIDGET_TOGGLE) - return (GP_ERROR); - - toggle->value = active; - - return (GP_OK); - -} - -int gp_widget_toggle_get (CameraWidget *toggle) { - - if (toggle->type != GP_WIDGET_TOGGLE) - return (GP_ERROR); - - return ((int)toggle->value); -} - -/* Set/get the value of the text widget */ -/* -------------------------------------------------------------------------- */ - -int gp_widget_text_set (CameraWidget *text, char *string) { - - if (text->type != GP_WIDGET_TEXT) - return (GP_ERROR); - - strcpy(text->value_string, string); - - return (GP_OK); -} - -char *gp_widget_text_get (CameraWidget *text) { - - if (text->type != GP_WIDGET_TEXT) - return (NULL); - - return (text->value_string); -} - /* Retrieve and set choices for menus/radio buttons */ /* -------------------------------------------------------------------------- */ -int gp_widget_choice_add (CameraWidget *widget, char *choice, int active) { +int gp_widget_choice_add (CameraWidget *widget, char *choice) { if ((widget->type != GP_WIDGET_RADIO) && (widget->type != GP_WIDGET_MENU)) return (GP_ERROR); strncpy(widget->choice[widget->choice_count], choice, 64); - if (active) - widget->value = widget->choice_count; - widget->choice_count += 1; @@ -235,16 +222,6 @@ char *gp_widget_choice (CameraWidget *widget, int choice_number) { return (widget->choice[choice_number]); } - /* Get the active value in the choices */ -char* gp_widget_choice_active(CameraWidget *widget) { - - if ((widget->type != GP_WIDGET_RADIO) && - (widget->type != GP_WIDGET_MENU)) - return (NULL); - - return (widget->choice[(int)widget->value]); -} - /* Debugging output */ /* -------------------------------------------------------------------------- */