8 * This function looks up a label or key entry of
9 * a configuration widget.
10 * The functions descend recursively, so you can just
11 * specify the last component.
15 _lookup_widget(CameraWidget*widget, const char *key, CameraWidget **child) {
17 ret = gp_widget_get_child_by_name (widget, key, child);
19 ret = gp_widget_get_child_by_label (widget, key, child);
23 /* Gets a string configuration value.
26 * - The current selection of a Radio Button choice
27 * - The current selection of a Menu choice
29 * Sample (for Canons eg):
30 * get_config_value_string (camera, "owner", &ownerstr, context);
33 get_config_value_string (Camera *camera, const char *key, char **str, GPContext *context) {
34 CameraWidget *widget = NULL, *child = NULL;
35 CameraWidgetType type;
39 ret = gp_camera_get_config (camera, &widget, context);
41 fprintf (stderr, "camera_get_config failed: %d\n", ret);
44 ret = _lookup_widget (widget, key, &child);
46 fprintf (stderr, "lookup widget failed: %d\n", ret);
50 /* This type check is optional, if you know what type the label
51 * has already. If you are not sure, better check. */
52 ret = gp_widget_get_type (child, &type);
54 fprintf (stderr, "widget get type failed: %d\n", ret);
63 fprintf (stderr, "widget has bad type %d\n", type);
64 ret = GP_ERROR_BAD_PARAMETERS;
68 /* This is the actual query call. Note that we just
69 * a pointer reference to the string, not a copy... */
70 ret = gp_widget_get_value (child, &val);
72 fprintf (stderr, "could not query widget value: %d\n", ret);
75 /* Create a new copy for our caller. */
78 gp_widget_free (widget);
83 /* Sets a string configuration value.
86 * - The current selection of a Radio Button choice
87 * - The current selection of a Menu choice
89 * Sample (for Canons eg):
90 * get_config_value_string (camera, "owner", &ownerstr, context);
93 set_config_value_string (Camera *camera, const char *key, const char *val, GPContext *context) {
94 CameraWidget *widget = NULL, *child = NULL;
95 CameraWidgetType type;
98 ret = gp_camera_get_config (camera, &widget, context);
100 fprintf (stderr, "camera_get_config failed: %d\n", ret);
103 ret = _lookup_widget (widget, key, &child);
105 fprintf (stderr, "lookup widget failed: %d\n", ret);
109 /* This type check is optional, if you know what type the label
110 * has already. If you are not sure, better check. */
111 ret = gp_widget_get_type (child, &type);
113 fprintf (stderr, "widget get type failed: %d\n", ret);
118 case GP_WIDGET_RADIO:
122 fprintf (stderr, "widget has bad type %d\n", type);
123 ret = GP_ERROR_BAD_PARAMETERS;
127 /* This is the actual set call. Note that we keep
128 * ownership of the string and have to free it if necessary.
130 ret = gp_widget_set_value (child, val);
132 fprintf (stderr, "could not set widget value: %d\n", ret);
135 /* This stores it on the camera again */
136 ret = gp_camera_set_config (camera, widget, context);
138 fprintf (stderr, "camera_set_config failed: %d\n", ret);
142 gp_widget_free (widget);
148 * This enables/disables the specific canon capture mode.
150 * For non canons this is not required, and will just return
151 * with an error (but without negative effects).
154 canon_enable_capture (Camera *camera, int onoff, GPContext *context) {
155 CameraWidget *widget = NULL, *child = NULL;
156 CameraWidgetType type;
159 ret = gp_camera_get_config (camera, &widget, context);
161 fprintf (stderr, "camera_get_config failed: %d\n", ret);
164 ret = _lookup_widget (widget, "capture", &child);
166 /*fprintf (stderr, "lookup widget failed: %d\n", ret);*/
170 ret = gp_widget_get_type (child, &type);
172 fprintf (stderr, "widget get type failed: %d\n", ret);
176 case GP_WIDGET_TOGGLE:
179 fprintf (stderr, "widget has bad type %d\n", type);
180 ret = GP_ERROR_BAD_PARAMETERS;
183 /* Now set the toggle to the wanted value */
184 ret = gp_widget_set_value (child, &onoff);
186 fprintf (stderr, "toggling Canon capture to %d failed with %d\n", onoff, ret);
190 ret = gp_camera_set_config (camera, widget, context);
192 fprintf (stderr, "camera_set_config failed: %d\n", ret);
196 gp_widget_free (widget);