static int camera_set_config (Camera *camera, CameraWidget *window, GPContext *context) { CameraWidget *widget; FujiDate date; time_t t; struct tm *tm; const char *id; /* Date & Time */ if ((gp_widget_get_child_by_label (window, _("Date & Time"), &widget) >= 0) && gp_widget_changed (widget)) { gp_widget_set_changed (widget, 0); CR (gp_widget_get_value (widget, &t)); tm = localtime (&t); date.year = tm->tm_year; date.month = tm->tm_mon; date.day = tm->tm_mday; date.hour = tm->tm_hour; date.min = tm->tm_min; date.sec = tm->tm_sec; CR (fuji_date_set (camera, date, context)); } /* ID */ if ((gp_widget_get_child_by_label (window, _("ID"), &widget) >= 0) && gp_widget_changed (widget)) { gp_widget_set_changed (widget, 0); CR (gp_widget_get_value (widget, &id)); CR (fuji_id_set (camera, id, context)); } return (GP_OK); }
void _camera_configuration_merge(const dt_camctl_t *c,const dt_camera_t *camera,CameraWidget *source, CameraWidget *destination, gboolean notify_all) { int childs = 0; const char *sk; const char *stv; CameraWidget *dw; const char *dtv; CameraWidgetType type; // If source widget has childs let's recurse into each children if( ( childs = gp_widget_count_children ( source ) ) > 0 ) { CameraWidget *child = NULL; for( int i = 0 ; i < childs ; i++) { gp_widget_get_child( source, i, &child ); //gp_widget_get_name( source, &sk ); _camera_configuration_merge( c, camera,child, destination, notify_all ); } } else { gboolean changed = TRUE; gp_widget_get_type( source, &type ); // Get the two keys to compare gp_widget_get_name( source, &sk ); gp_widget_get_child_by_name ( destination, sk, &dw); // // First of all check if widget has change accessibility // /// TODO: Resolve this 2.4.8 libgphoto2 dependency /* int sa,da; gp_widget_get_readonly( source, &sa ); gp_widget_get_readonly( dw, &da ); if( notify_all || ( sa != da ) ) { // update destination widget to new accessibility if differ then notify of the change if( ( sa != da ) ) gp_widget_set_readonly( dw, sa ); _dispatch_camera_property_accessibility_changed(c, camera,sk, ( sa == 1 ) ? TRUE: FALSE) ; } */ // // Lets compare values and notify on change or by notifyAll flag // if( type == GP_WIDGET_MENU || type == GP_WIDGET_TEXT || type == GP_WIDGET_RADIO ) { // Get source and destination value to be compared gp_widget_get_value( source, &stv ); gp_widget_get_value( dw, &dtv ); if( ( ( stv && dtv ) && strcmp( stv, dtv ) != 0 ) && ( changed = TRUE ) ) { gp_widget_set_value( dw, stv ); // Dont flag this change as changed, otherwise a read-only widget might get tried // to update the camera configuration... gp_widget_set_changed( dw, 0 ); } if( ( stv && dtv ) && ( notify_all || changed ) ) _dispatch_camera_property_value_changed(c,camera,sk,stv); } } }
/** * Set property. * @see DigitalCameraCapture for more information about value, double typed, argument. */ bool DigitalCameraCapture::setProperty(int propertyId, double value) { CameraWidget * widget = NULL; bool output = false; if (propertyId < 0) { widget = getWidget(-propertyId); } else { switch (propertyId) { // gphoto2 cap featured case CV_CAP_PROP_GPHOTO2_PREVIEW: preview = value != 0; return true; case CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE: return false; case CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG: reloadConfig(); return true; case CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE: reloadOnChange = value != 0; return true; case CV_CAP_PROP_GPHOTO2_COLLECT_MSGS: collectMsgs = value != 0; return true; case CV_CAP_PROP_GPHOTO2_FLUSH_MSGS: return false; default: widget = setGenericProperty(propertyId, value, output); /* no break */ } } if (widget == NULL) return output; try { CameraWidgetType type; CR(gp_widget_get_type(widget, &type)); switch (type) { case GP_WIDGET_RADIO: case GP_WIDGET_MENU: { int i = static_cast<int>(value); char *choice; CR(gp_widget_get_choice(widget, i, (const char**)&choice)); CR(gp_widget_set_value(widget, choice)); break; } case GP_WIDGET_TOGGLE: { int i = static_cast<int>(value); CR(gp_widget_set_value(widget, &i)); break; } case GP_WIDGET_RANGE: { float v = static_cast<float>(value); CR(gp_widget_set_value(widget, &v)); break; } default: { CR(gp_widget_set_value(widget, (void* )(intptr_t )&value)); break; } } if (!reloadOnChange) { // force widget change CR(gp_widget_set_changed(widget, 1)); } // Use the same locale setting as while getting rootWidget. char * localeTmp = setlocale(LC_ALL, "C"); CR(gp_camera_set_config(camera, rootWidget, context)); setlocale(LC_ALL, localeTmp); if (reloadOnChange) { reloadConfig(); } else { CR(gp_widget_set_changed(widget, 0)); } } catch (GPhoto2Exception & e) { char buf[128] = ""; sprintf(buf, "cannot set property: %d to %f", propertyId, value); message(WARNING, (const char *) buf, e); return false; } return true; }
static int camera_cam_desc_set_widget (Camera *camera, CameraRegisterType *reg_p, CameraWidget *window, GPContext *context) { int ind, vind, ret; union value_in { char *charp; int val; float flt; } value_in; CameraWidget *child; RegisterDescriptorType *reg_desc_p; GP_DEBUG ("register %d", reg_p->reg_number); for (ind = 0; ind < reg_p->reg_desc_cnt; ind++) { reg_desc_p = ®_p->reg_desc[ind]; GP_DEBUG ("window name is %s", reg_desc_p->regs_long_name); if ((gp_widget_get_child_by_label (window, _(reg_desc_p->regs_long_name), &child) >= 0) && gp_widget_changed (child)) { gp_widget_get_value (child, &value_in); for (vind = 0; vind < reg_desc_p->reg_val_name_cnt; vind++) { ret = camera_cam_desc_set_value (camera, reg_p, reg_desc_p, ®_desc_p->regs_value_names[vind], &value_in, context); if (ret == GP_OK) { /* * Something got set, mark the * widget as changed, so the user * can repeat any actions - like * going to the "next" picture by * repeatedly hitting apply while * in operation play mode. * * This has the side affect of * changing whatever was just set * twice when using the apply in * gtkam - once when applied and * once when OK. */ gp_widget_set_changed (child, 1); } if (ret <= 0) { /* * Value was set (GP_OK is 0), or * some an error occurred (< 0), * don't bother checking any other * value/name pairs. */ break; } } } } return (GP_OK); }
/** * Set a single configuration \c widget for the \c camera. * * @param camera a #Camera * @param name the name of a configuration widget * @param widget a #CameraWidget * @param context a #GPContext * @return gphoto2 error code * * This \c widget contains the new value of the widget to set. * */ int gp_camera_set_single_config (Camera *camera, const char *name, CameraWidget *widget, GPContext *context) { CameraWidget *rootwidget, *child; CameraWidgetType type; int ret; C_PARAMS (camera); CHECK_INIT (camera, context); if (camera->functions->set_single_config) { CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->set_single_config ( camera, name, widget, context), context); CAMERA_UNUSED (camera, context); return GP_OK; } if (!camera->functions->set_config) { gp_context_error (context, _("This camera does not provide any configuration options.")); CAMERA_UNUSED (camera, context); return GP_ERROR_NOT_SUPPORTED; } /* emulate single config with the full tree */ CHECK_OPEN (camera, context); ret = camera->functions->get_config ( camera, &rootwidget, context); if (ret != GP_OK) { CHECK_CLOSE (camera, context); CAMERA_UNUSED (camera, context); return ret; } ret = gp_widget_get_child_by_name (rootwidget, name, &child); if (ret != GP_OK) { gp_widget_free (rootwidget); CHECK_CLOSE (camera, context); CAMERA_UNUSED (camera, context); return ret; } gp_widget_get_type (child, &type); ret = GP_OK; switch (type) { case GP_WIDGET_MENU: case GP_WIDGET_RADIO: case GP_WIDGET_TEXT: { char *value; gp_widget_get_value (widget, &value); gp_widget_set_value (child, value); break; } case GP_WIDGET_RANGE: { float value; gp_widget_get_value (widget, &value); gp_widget_set_value (child, &value); break; } case GP_WIDGET_TOGGLE: case GP_WIDGET_DATE: { int value; gp_widget_get_value (widget, &value); gp_widget_set_value (child, &value); break; } case GP_WIDGET_BUTTON: case GP_WIDGET_SECTION: case GP_WIDGET_WINDOW: default: ret = GP_ERROR_BAD_PARAMETERS; break; } gp_widget_set_changed (child, 1); if (ret == GP_OK) ret = camera->functions->set_config (camera, rootwidget, context); gp_widget_free (rootwidget); CHECK_CLOSE (camera, context); CAMERA_UNUSED (camera, context); return ret; }