static int camera_config_get (Camera *camera, CameraWidget **window, GPContext *context) { CameraWidget *section, *turbo; char buf[1024]; int val; gp_widget_new (GP_WIDGET_WINDOW, _("Camera Configuration"), window); gp_widget_set_name (*window, "config"); gp_widget_new (GP_WIDGET_SECTION, _("Driver Settings"), §ion); gp_widget_set_name (section, "driver"); gp_widget_append (*window, section); gp_widget_new (GP_WIDGET_RADIO, _("Turbo mode"), &turbo); gp_widget_set_name (turbo, "turbo"); gp_widget_add_choice (turbo,_("On")); gp_widget_add_choice (turbo,_("Off")); gp_widget_append (section, turbo); if (GP_OK == gp_setting_get("topfield","turbo", buf)) { if (!strcmp(buf,"no")) val = 0; else val = 1; } else { val = 1; /* enabled by default */ } gp_widget_set_value ( turbo, val?_("On"):_("Off")); return GP_OK; }
static int camera_get_config (Camera *c, CameraWidget **window, GPContext *co) { CameraWidget *s, *w; const char *copyright; time_t time; CR (gp_widget_new (GP_WIDGET_WINDOW, _("Configuration"), window)); /* General settings */ CR (gp_widget_new (GP_WIDGET_SECTION, _("General"), &s)); CR (gp_widget_append (*window, s)); /* Copyright */ CR (gp_widget_new (GP_WIDGET_TEXT, _("Copyright"), &w)); CR (gp_widget_set_name (w, "copyright")); CR (gp_widget_set_info (w, _("Copyright (max. 20 characters)"))); CR (gp_widget_append (s, w)); CR (ricoh_get_copyright (c, co, ©right)); CR (gp_widget_set_value (w, (void *) copyright)); /* Date */ CR (gp_widget_new (GP_WIDGET_DATE, _("Date & Time"), &w)); CRW (gp_widget_set_name (w, "date"), w); CRW (gp_widget_set_info (w, _("Date & Time")), w); CRW (gp_widget_append (s, w), w); CR (ricoh_get_date (c, co, &time)); CR (gp_widget_set_value (w, &time)); /* Picture related settings */ CR (gp_widget_new (GP_WIDGET_SECTION, _("Pictures"), &s)); CRW (gp_widget_append (*window, s), w); R_ADD_RADIO (c, co, s, RicohResolution, resolution, "Resolution") R_ADD_RADIO (c, co, s, RicohExposure, exposure, "Exposure") R_ADD_RADIO (c, co, s, RicohMacro, macro, "Macro") R_ADD_RADIO (c, co, s, RicohFlash, flash, "Flash") R_ADD_RADIO (c, co, s, RicohZoom, zoom, "Zoom") R_ADD_RADIO (c, co, s, RicohCompression, compression, "Compression") R_ADD_RADIO (c, co, s, RicohWhiteLevel, white_level, "White Level") R_ADD_RADIO (c, co, s, RicohRecMode, rec_mode, "Record Mode") return (GP_OK); }
static int camera_cam_desc_get_widget (Camera *camera, CameraRegisterType *reg_p, CameraWidget *section, GPContext *context) { int ind, vind, ret, value; int mask; char buff[1024]; CameraWidget *child; RegisterDescriptorType *reg_desc_p; GP_DEBUG ("register %d", reg_p->reg_number); if (reg_p->reg_len == 0) { /* * This is 0 for GP_WIDGET_BUTTON (callbacks), since is no * register for call backs. Frontends "get" the value, and * call the function directly. */ ret = GP_OK; } else if (reg_p->reg_len == 4) { int rval; ret = sierra_get_int_register (camera, reg_p->reg_number, &rval, context); reg_p->reg_value = rval; } else if (reg_p->reg_len == 8) { /* * reg_value is 8 bytes maximum. If you need a bigger * value, change the reg_value size, or allocate space on * the fly and make a union with reg_value and a void*. */ ret = sierra_get_string_register (camera, reg_p->reg_number, -1, NULL, (unsigned char *)buff, (unsigned int *)&value, context); if ((ret == GP_OK) && value != reg_p->reg_len) { GP_DEBUG ("Bad length result %d", value); return (GP_ERROR); } memcpy (®_p->reg_value, buff, reg_p->reg_len); } else { GP_DEBUG ("Bad register length %d", reg_p->reg_number); return (GP_ERROR); } GP_DEBUG ("... '%s'.", gp_result_as_string (ret)); if (ret < 0) { return (ret); } for (ind = 0; ind < reg_p->reg_desc_cnt; ind++) { reg_desc_p = ®_p->reg_desc[ind]; mask = reg_desc_p->regs_mask; GP_DEBUG ("window name is %s", reg_desc_p->regs_long_name); gp_widget_new (reg_desc_p->reg_widget_type, _(reg_desc_p->regs_long_name), &child); gp_widget_set_name (child, reg_desc_p->regs_short_name); /* * Setting the info for the preference settings does not * make sense like it does for an icon button. This is * used as the tool-tip field (mouse over hint that pops * up after a second in gtkam). We don't want this used * at all; setting it to space doesn't work well, so just * set it to the same as regs_long_name. */ gp_widget_set_info (child, _(reg_desc_p->regs_long_name)); GP_DEBUG ("reg_value 0x%016llx", (long long unsigned)reg_p->reg_value); for (vind = 0; vind < reg_desc_p->reg_val_name_cnt; vind++) { camera_cam_desc_get_value (®_desc_p->regs_value_names[vind], reg_desc_p->reg_widget_type, reg_p->reg_len, (char*) ®_p->reg_value, mask, child); } /* * For radio and menu values: if there has been no change, it * means the value was not set, and so it is unknown. */ if (((reg_desc_p->reg_widget_type == GP_WIDGET_RADIO) || (reg_desc_p->reg_widget_type == GP_WIDGET_MENU)) && !gp_widget_changed (child)) { sprintf (buff, _("%lld (unknown)"), (long long)reg_p->reg_value); gp_widget_add_choice (child, buff); gp_widget_set_value (child, buff); } gp_widget_append (section, child); } return (GP_OK); }
/** * Retrieve 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 will then contain the current and the possible values and the type. * */ int gp_camera_get_single_config (Camera *camera, const char *name, CameraWidget **widget, GPContext *context) { CameraWidget *rootwidget, *child; CameraWidgetType type; const char *label; int ret, ro; C_PARAMS (camera); CHECK_INIT (camera, context); if (camera->functions->get_single_config) { CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->get_single_config ( camera, name, widget, context), context); CAMERA_UNUSED (camera, context); return GP_OK; } if (!camera->functions->get_config) { gp_context_error (context, _("This camera does not provide any configuration options.")); CAMERA_UNUSED (camera, context); return GP_ERROR_NOT_SUPPORTED; } /* emulate it ... */ 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; } /* We need to duplicate the widget, as we will free the widgettree */ gp_widget_get_type (child, &type); gp_widget_get_label (child, &label); gp_widget_get_readonly (child, &ro); ret = gp_widget_new (type, label, widget); if (ret != GP_OK) goto out; gp_widget_set_name (*widget, name); gp_widget_set_readonly (*widget, ro); switch (type) { case GP_WIDGET_MENU: case GP_WIDGET_RADIO: { char *value; int i, nrofchoices; nrofchoices = gp_widget_count_choices (child); for (i = 0; i < nrofchoices; i++) { const char *choice; gp_widget_get_choice (child, i, &choice); gp_widget_add_choice (*widget, choice); } gp_widget_get_value (child, &value); gp_widget_set_value (*widget, value); break; } case GP_WIDGET_TEXT: { char *value; gp_widget_get_value (child, &value); gp_widget_set_value (*widget, value); break; } case GP_WIDGET_RANGE: { float value, rmin, rmax, rstep; gp_widget_get_range (child, &rmin, &rmax, &rstep); gp_widget_set_range (*widget, rmin, rmax, rstep); gp_widget_get_value (child, &value); gp_widget_set_value (*widget, &value); break; } case GP_WIDGET_TOGGLE: case GP_WIDGET_DATE: { int value; gp_widget_get_value (child, &value); gp_widget_set_value (*widget, &value); break; } case GP_WIDGET_BUTTON: case GP_WIDGET_SECTION: case GP_WIDGET_WINDOW: default: ret = GP_ERROR_BAD_PARAMETERS; break; } out: gp_widget_free (rootwidget); CHECK_CLOSE (camera, context); CAMERA_UNUSED (camera, context); return ret; }