int internal_set_setting(const char * setting, const char * value) {
	CameraWidget * widget = NULL; // will hold the root config entry
	CameraWidget * child  = NULL; // will hold the actual config entry from the tree

	int ret = getWidget(&widget, &child, setting);
	if (ret < GP_OK) {
		fprintf (stderr, "camera_get_config failed: %d\n", ret);
		return ret;
	}

	ret = gp_widget_set_value(child, value);
	if (ret < GP_OK) {
		fprintf (stderr, "could not set widget value: %d\n", ret);
		gp_widget_free (widget);
		return ret;
	}

	/* This stores it on the camera again */
	ret = gp_camera_set_config (camera, widget, context);
	if (ret < GP_OK) {
		fprintf (stderr, "camera_set_config failed: %d\n", ret);
		gp_widget_free (widget);
		return ret;
	}

	gp_widget_free (widget);
	return 0;
}
Beispiel #2
0
static int
show_text (CmdConfig *cmd_config, CameraWidget *text)
{
	CDKENTRY *entry = NULL;
	const char *label, *value;
	char title[1024], *info;

	CHECK (gp_widget_get_value (text, &value));
	CHECK (gp_widget_get_label (text, &label));

	snprintf (title, sizeof (title), "<C></5>%s", label);
	entry = newCDKEntry (cmd_config->screen, CENTER, CENTER, title,
			     _("Value: "), A_NORMAL, ' ', vMIXED, 40, 0,
			     256, TRUE, FALSE);
	if (!entry)
		return (GP_ERROR);

	setCDKEntryValue (entry, (char*) value);
	info = activateCDKEntry (entry, 0);
	if (entry->exitType == vNORMAL) {
		gp_widget_set_value (text, info);
		set_config (cmd_config);
	}
	destroyCDKEntry (entry);
	return (GP_OK);
}
Beispiel #3
0
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"), &section);
	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;
}
Beispiel #4
0
static int
show_toggle (CmdConfig *cmd_config, CameraWidget *toggle)
{
	CDKITEMLIST *list = NULL;
	int value, selection;
	const char *label;
	char title[1024], *info[] = {N_("Yes"), N_("No")};

	CHECK (gp_widget_get_value (toggle, &value));
	CHECK (gp_widget_get_label (toggle, &label));
	snprintf (title, sizeof (title), "<C></5>%s", label);

	list = newCDKItemlist (cmd_config->screen, CENTER, CENTER, title, "",
			       info, 2, 1 - value, TRUE, FALSE);
	if (!list)
		return (GP_ERROR);

	selection = activateCDKItemlist (list, 0);
	if (list->exitType == vNORMAL) {
		selection = 1 - selection;
		gp_widget_set_value (toggle, &selection);
		set_config (cmd_config);
	}

	destroyCDKItemlist (list);

	return (GP_OK);
}
Beispiel #5
0
static int
show_range_int (CmdConfig *cmd_config, CameraWidget *range)
{
	CDKSLIDER *slider = NULL;
	float value, min, max, increment;
	const char *label;
	char title[1024];
	int selection;

	CHECK (gp_widget_get_value (range, &value));
	CHECK (gp_widget_get_label (range, &label));
	snprintf (title, sizeof (title), "<C></5>%s", label);
	CHECK (gp_widget_get_range (range, &min, &max, &increment));

	slider = newCDKSlider (cmd_config->screen, CENTER, CENTER, title,
			       _("Value: "), '-',
			       50, (int) value, min, max,
			       increment, 
			       MAX (increment, (max - min)/20.0),
			       TRUE,
			       FALSE);
	if (!slider)
		return (GP_ERROR);

	selection = activateCDKSlider (slider, 0);
	if (slider->exitType == vNORMAL) {
		value = selection;
		gp_widget_set_value (range, &value);
		set_config (cmd_config);
	}
	
	destroyCDKSlider (slider);
	return (GP_OK);
}
Beispiel #6
0
int set_config_value_string (Camera *camera, const char *key, char *val, GPContext *context)
{
	CameraWidget *widget = NULL, *child = NULL;
	CameraWidgetType type;
	int ret;

	ret = gp_camera_get_config (camera, &widget, context);
	if (ret < GP_OK)
	{
		fprintf (stderr, "camera_get_config failed: %d\n", ret);
		return ret;
	}
	ret = _lookup_widget (widget, key, &child);
	if (ret < GP_OK)
	{
		fprintf (stderr, "lookup widget failed: %d\n", ret);
		goto out;
	}
	/* This type check is optional, if you know what type the label
	 * has already. If you are not sure, better check. */
	ret = gp_widget_get_type (child, &type);
	if (ret < GP_OK) 
	{
		fprintf (stderr, "widget get type failed: %d\n", ret);
		goto out;
	}
	switch (type)
	{
        case GP_WIDGET_MENU:
        case GP_WIDGET_RADIO:
        case GP_WIDGET_TEXT:
		break;
	default:
		fprintf (stderr, "widget has bad type %d\n", type);
		ret = GP_ERROR_BAD_PARAMETERS;
		goto out;
	}
	/* This is the actual set call. Note that we keep
	 * ownership of the string and have to free it if necessary.
	 */
	ret = gp_widget_set_value (child, val);
	if (ret < GP_OK) 
	{
		fprintf (stderr, "could not set widget value: %d\n", ret);
		goto out;
	}
	/* This stores it on the camera again */
	ret = gp_camera_set_config (camera, widget, context);
	if (ret < GP_OK) 
	{
		fprintf (stderr, "camera_set_config failed: %d\n", ret);
		return ret;
	}
out:
	gp_widget_free (widget);
	return ret;
}
Beispiel #7
0
//Set the camera's quality to a certain choice
//Current Choices are:
// 0: Large Fine JPEG
// 2: Medium Fine JPEG
int QualityControl(int quality){
	char qualString[20];

	if(quality == currentQuality){ //We don't want to take up cycles changing nothing
		return -1; //Could define set error codes, but we don't look at them anyway
	}

	strncpy(qualString, "", sizeof qualString); //Debatably necessary

	if(quality == 0){
		strncpy(qualString, "Large Fine JPEG", sizeof qualString);
	}
	else if(quality == 2){
		strncpy(qualString, "Medium Fine JPEG", sizeof qualString);
	}
	else{	
		return -1;
	}

	CameraWidget* widget,* child;

	if(gp_camera_get_config(getMyCamera(), &widget, getMyContext()) != 0){ //Get our current config
		free(widget);
		free(child);
		return -1; //If it fails, we have failed.
	}

	//Widgets in libgphoto act sort of as trees of settings/data
	//We need to find the right child of the top level, and the right child of that, etc.
	//until we get down to the appropriate quality setting widget
	//I already parsed through the tree and found the right child, and so
	//have hard-coded the values to get to this child here
	//Check out gphoto2-widget.c for more info

	gp_widget_get_child(widget, 3, &child);
	widget = child;
	gp_widget_get_child(widget, 0, &child);
	widget = child;

	//Here we change the quality value to whatever we want
	//For some reason, it is saved as a string, not a choice
	//Don't ask me why.
	gp_widget_set_value(widget, qualString);
	gp_widget_get_root(widget, &child);

	if(gp_camera_set_config(getMyCamera(), child, getMyContext()) != 0){ //Set the camera's config to our new, modified config
		free(widget);
		free(child);
		return -1;
	}

	free(widget);
	free(child);

	currentQuality = quality; //Remember what quality we currently have
	return 0;
}
Beispiel #8
0
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, &copyright));
	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);
}
Beispiel #9
0
int set_config_value_float (Camera *camera, const char *key, float *value, GPContext *context)
{
	CameraWidget *widget = NULL, *child = NULL;
	CameraWidgetType type;
	int ret;

	printf("Hai sa vedem ce e busit dintre camera si context %p %p\n",camera,context);
	ret = gp_camera_get_config (camera, &widget, context);
	if (ret < GP_OK)
	{
		fprintf (stderr, "camera_get_config failed: %d\n", ret);
		return ret;
	}
	ret = _lookup_widget (widget, key, &child);
	if (ret < GP_OK)
	{
		printf("name: %s",key);
		fprintf (stderr, "lookup widget failed: %d\n", ret);
		goto out;
	}
	/* This type check is optional, if you know what type the label
	 * has already. If you are not sure, better check. */
	ret = gp_widget_get_type (child, &type);
	if (ret < GP_OK) 
	{
		fprintf (stderr, "widget get type failed: %d\n", ret);
		goto out;
	}
	switch (type) 
	{
        case GP_WIDGET_RANGE:
		break;
	default:
		fprintf (stderr, "widget has bad type %d\n", type);
		ret = GP_ERROR_BAD_PARAMETERS;
		goto out;
	}
	ret = gp_widget_set_value (child, value);
	if (ret < GP_OK) 
	{
		fprintf (stderr, "could not set widget value: %d\n", ret);
		goto out;
	}

	/* This stores it on the camera again */
	ret = gp_camera_set_config (camera, widget, context);
	if (ret < GP_OK) 
	{
		fprintf (stderr, "camera_set_config failed: %d\n", ret);
		return ret;
	}
out:
	gp_widget_free (widget);
	return ret;
}
Beispiel #10
0
int
camera_auto_focus(Camera *camera, GPContext *context, int onoff) {
	CameraWidget		*widget = NULL, *child = NULL;
	CameraWidgetType	type;
	int			ret,val;

	ret = gp_camera_get_config (camera, &widget, context);
	if (ret < GP_OK) {
		fprintf (stderr, "camera_get_config failed: %d\n", ret);
		return ret;
	}
	ret = _lookup_widget (widget, "autofocusdrive", &child);
	if (ret < GP_OK) {
		fprintf (stderr, "lookup 'autofocusdrive' failed: %d\n", ret);
		goto out;
	}

	/* check that this is a toggle */
	ret = gp_widget_get_type (child, &type);
	if (ret < GP_OK) {
		fprintf (stderr, "widget get type failed: %d\n", ret);
		goto out;
	}
	switch (type) {
        case GP_WIDGET_TOGGLE:
		break;
	default:
		fprintf (stderr, "widget has bad type %d\n", type);
		ret = GP_ERROR_BAD_PARAMETERS;
		goto out;
	}

	ret = gp_widget_get_value (child, &val);
	if (ret < GP_OK) {
		fprintf (stderr, "could not get widget value: %d\n", ret);
		goto out;
	}

	val = onoff;

	ret = gp_widget_set_value (child, &val);
	if (ret < GP_OK) {
		fprintf (stderr, "could not set widget value to 1: %d\n", ret);
		goto out;
	}

	ret = gp_camera_set_config (camera, widget, context);
	if (ret < GP_OK) {
		fprintf (stderr, "could not set config tree to autofocus: %d\n", ret);
		goto out;
	}
out:
	gp_widget_free (widget);
	return ret;
}
Beispiel #11
0
static int
show_date (CmdConfig *cmd_config, CameraWidget *date)
{
	CDKCALENDAR *calendar = NULL;
	int day, month, year, selection;
	time_t time;
	struct tm *date_info;
	const char *label;
	char title[1024];

	gp_widget_get_value (date, &time);
	date_info = localtime (&time);

	/* Month in CDK starts with 1 */
	day = date_info->tm_mday;
	month = date_info->tm_mon + 1;
	year = date_info->tm_year + 1900;

	gp_widget_get_label (date, &label);
	snprintf (title, sizeof (title), "<C></5>%s", label);

	/* Create the calendar */
	calendar = newCDKCalendar (cmd_config->screen, CENTER, CENTER, title,
				   day, month, year,
				   COLOR_PAIR(16)|A_BOLD,
				   COLOR_PAIR(24)|A_BOLD,
				   COLOR_PAIR(32)|A_BOLD,
				   COLOR_PAIR(40)|A_REVERSE, TRUE, FALSE);
	if (!calendar)
		return (GP_ERROR);

	drawCDKCalendar (calendar, TRUE);
	selection = activateCDKCalendar (calendar, 0);

	if (calendar->exitType == vNORMAL) {
		date_info = localtime (&time);

		/* Month in CDK starts with 1 */
		date_info->tm_mday = calendar->day;
		date_info->tm_mon = calendar->month - 1;
		date_info->tm_year = calendar->year - 1900;

		time = mktime (date_info);
		gp_widget_set_value (date, &time);
		set_config (cmd_config);
	}

	destroyCDKCalendar (calendar);
	return (GP_OK);
}
Beispiel #12
0
static int
camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
{
	CameraWidget *widget;
	struct tm tm;
	time_t t;
	FujiDate date;
	const char *id;

	CR (gp_widget_new (GP_WIDGET_WINDOW, _("Configuration for "
					"your FUJI camera"), window));

	/* Date & Time */
	if (fuji_date_get (camera, &date, context) >= 0) {
		CR (gp_widget_new (GP_WIDGET_DATE, _("Date & Time"), &widget));
		CR (gp_widget_append (*window, widget));
		memset (&tm, 0, sizeof (struct tm));
		tm.tm_year = date.year;
		tm.tm_mon  = date.month;
		tm.tm_mday = date.day;
		tm.tm_hour = date.hour;
		tm.tm_min  = date.min;
		tm.tm_sec  = date.sec;
		t = mktime (&tm);
		CR (gp_widget_set_value (widget, &t));
	}

	/* ID */
	if (fuji_id_get (camera, &id, context) >= 0) {
		CR (gp_widget_new (GP_WIDGET_TEXT, _("ID"), &widget));
		CR (gp_widget_append (*window, widget));
		CR (gp_widget_set_value (widget, (void *) id));
	}

	return (GP_OK);
}
Beispiel #13
0
static int
show_radio (CmdConfig *cmd_config, CameraWidget *radio)
{
	CDKITEMLIST *list = NULL;
	const char *label, *value, *current_value;
	char title[1024], *items[100];
	int x, count, current = 0, selection, found;

	gp_widget_get_label (radio, &label);
	snprintf (title, sizeof (title), "<C></5>%s", label);
	gp_widget_get_value (radio, &current_value);
	count = gp_widget_count_choices (radio);

	/* Check if the current value is in the list */
	current = found = 0;
	for (x = 0; x < count; x++) {
		gp_widget_get_choice (radio, x, &value);
		if (!strcmp (value, current_value)) {
			current = x;
			found = 1;
			break;
		}
	}
	if (!found)
		items[0] = copyChar ((char *) current_value);

	/* Add all items */
	for (x = 0; x < count; x++) {
		gp_widget_get_choice (radio, x, &value);
		items[x + 1 - found] = copyChar ((char *) value);
	}

	list = newCDKItemlist (cmd_config->screen, CENTER, CENTER,
			       title, _("Value: "), items, count,
			       current, TRUE, FALSE);
	if (!list)
		return (GP_ERROR);

	selection = activateCDKItemlist (list, 0);
	if (list->exitType == vNORMAL) {
		gp_widget_get_choice (radio, selection, &value);
		gp_widget_set_value (radio, (void *) value);
		set_config (cmd_config);
	}

	destroyCDKItemlist (list);
	return (GP_OK);
}
Beispiel #14
0
int canon_enable_capture(Camera *camera, int onoff, GPContext *context) {
    CameraWidget *widget = NULL, *child = NULL;
    CameraWidgetType type;
    int ret;

    ret = gp_camera_get_config(camera, &widget, context);
    if (ret < GP_OK) {
        fprintf(stderr, "camera_get_config failed: %d\n", ret);
        return ret;
    }
    ret = _lookup_widget(widget, "capture", &child);
    if (ret < GP_OK) {
        /*fprintf (stderr, "lookup widget failed: %d\n", ret);*/
        goto out;
    }

    ret = gp_widget_get_type(child, &type);
    if (ret < GP_OK) {
        fprintf(stderr, "widget get type failed: %d\n", ret);
        goto out;
    }
    switch (type) {
    case GP_WIDGET_TOGGLE:
        break;
    default:
        fprintf(stderr, "widget has bad type %d\n", type);
        ret = GP_ERROR_BAD_PARAMETERS;
        goto out;
    }
    /* Now set the toggle to the wanted value */
    ret = gp_widget_set_value(child, &onoff);
    if (ret < GP_OK) {
        fprintf(stderr, "toggling Canon capture to %d failed with %d\n", onoff,
                ret);
        goto out;
    }
    /* OK */
    ret = gp_camera_set_config(camera, widget, context);
    if (ret < GP_OK) {
        fprintf(stderr, "camera_set_config failed: %d\n", ret);
        return ret;
    }
out:
    gp_widget_free(widget);
    return ret;
}
Beispiel #15
0
int camera_set(char* name, void* value)
{
	int res;

	CameraWidget* config_root;
	CameraWidget* widget;
	res = gp_camera_get_config(camera, &config_root, context);
	CAMERA_CHECK_GP(res, "gp_camera_get_config");
	res = gp_widget_get_child_by_name(config_root, name, &widget);
	CAMERA_CHECK_GP(res, "gp_widget_get_child_by_name");
	res = gp_widget_set_value(widget, value);
	CAMERA_CHECK_GP(res, "gp_widget_set_value");
	res = gp_camera_set_config(camera, config_root, context);
	CAMERA_CHECK_GP(res, "gp_camera_set_config");
	gp_widget_unref(config_root);
	return 1;
}
Beispiel #16
0
static int
camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
{
	CameraWidget *child;

	GP_DEBUG ("*** camera_get_config");

	gp_widget_new (GP_WIDGET_WINDOW,
			_("Picture Frame Configuration"), window);

	gp_widget_new (GP_WIDGET_TOGGLE,
			_("Synchronize frame data and time with PC"), &child);
	gp_widget_set_value (child, &camera->pl->syncdatetime);
	gp_widget_append (*window, child);

	return GP_OK;
}
Beispiel #17
0
void dt_camctl_camera_stop_live_view(const dt_camctl_t *c)
{
  dt_camctl_t *camctl = (dt_camctl_t*)c;
  dt_camera_t *cam = (dt_camera_t*)camctl->active_camera;
  dt_print(DT_DEBUG_CAMCTL,"[camera_control] Stopping live view\n");
  cam->is_live_viewing = FALSE;
  pthread_join(cam->live_view_thread, NULL);
  //tell camera to get back to normal state (close mirror)
  // this should work like this:
//   dt_camctl_camera_set_property(darktable.camctl, NULL, "eosviewfinder", "0");
  // but it doesn't, passing a string isn't ok in this case. I guess that's a TODO.
  // for the time being I'll do it manually (not nice, I know).
  CameraWidget *config;
  CameraWidget *widget;
  gp_camera_get_config( cam->gpcam, &config, camctl->gpcontext );
  if(  gp_widget_get_child_by_name ( config, "eosviewfinder", &widget) == GP_OK)
  {
    int zero=0;
    gp_widget_set_value ( widget , &zero);
    gp_camera_set_config( cam->gpcam, config, camctl->gpcontext );
  }
}
Beispiel #18
0
static int
show_range_float (CmdConfig *cmd_config, CameraWidget *range)
{
#ifdef HAVE_CDK_20010421
	return (show_range_int (cmd_config, range));
#else
        CDKFSCALE *fscale = NULL;
        float value, min, max, increment;
        const char *label;
        char title[1024];
        float selection;

        CHECK (gp_widget_get_value (range, &value));
        CHECK (gp_widget_get_label (range, &label));
        snprintf (title, sizeof (title), "<C></5>%s", label);
        CHECK (gp_widget_get_range (range, &min, &max, &increment));

        fscale = newCDKFScale (cmd_config->screen, CENTER, CENTER, title,
                               _("Value: "), A_STANDOUT,
                               50, value, min, max,
                               increment, 
			       MAX (increment, (max - min) / 20.0),
			       get_digits (increment),
			       TRUE, FALSE);
        if (!fscale)
                return (GP_ERROR);

	selection = activateCDKFScale (fscale, 0);
        if (fscale->exitType == vNORMAL) {
		value = selection;
                gp_widget_set_value (range, &value);
                set_config (cmd_config);
        }

        destroyCDKFScale (fscale);
        return (GP_OK);
#endif
}
Beispiel #19
0
static int
show_time (CmdConfig *cmd_config, CameraWidget *date)
{
	CDKENTRY *entry = NULL;
	const char *label, *info;
	char title[1024], time_string[9];
	time_t time;
	struct tm *date_info;

	gp_widget_get_label (date, &label);
	snprintf (title, sizeof (title), "<C></5>%s", label);

	entry = newCDKEntry (cmd_config->screen, CENTER, CENTER, title,
			     _("Time: "), A_NORMAL, ' ', vMIXED, 40, 0,
			     8, TRUE, FALSE);
	if (!entry)
		return (GP_ERROR);

	gp_widget_get_value (date, &time);
	date_info = localtime (&time);
	snprintf (time_string, sizeof (time_string), "%2i:%02i:%02i",
		  date_info->tm_hour, date_info->tm_min, date_info->tm_sec);
	setCDKEntryValue (entry, time_string);

	setCDKEntryPreProcess (entry, time_preprocess, NULL);

	info = activateCDKEntry (entry, 0);
	if (entry->exitType == vNORMAL) {
		date_info = localtime (&time);
		sscanf (info, "%d:%d:%d", &date_info->tm_hour,
			&date_info->tm_min, &date_info->tm_sec);
		time = mktime (date_info);
		gp_widget_set_value (date, &time);
		set_config (cmd_config);
	} 
	destroyCDKEntry (entry);
	return (GP_OK);
}
bool Image_GPhoto::doSetProperty(const string& name, const string& value)
{
    lock_guard<recursive_mutex> lock(_gpMutex);

    if (_selectedCameraIndex == -1)
    {
        Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - A camera must be selected before trying to capture" << Log::endl;
        return false;
    }

    GPhotoCamera* camera = &(_cameras[_selectedCameraIndex]);

    CameraWidget* widget;
    if (gp_widget_get_child_by_name(camera->configuration, name.c_str(), &widget) == GP_OK)
    {
        if (gp_widget_set_value(widget, value.c_str()) != GP_OK)
        {
            Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Unable to set parameter " << name << " to value " << value << Log::endl;
            return false;
        }

        if (gp_camera_set_config(camera->cam, camera->configuration, _gpContext) != GP_OK)
        {
            Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Setting parameter " << name << " is not supported for this camera" << Log::endl;
            return false;
        }

        return true;
    }
    else
    {
        Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Parameter " << name << " does not seem to be available" << Log::endl;
    }

    return false;
}
Beispiel #21
0
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);
    }
  }
}
Beispiel #22
0
/*
 * List all informations about the camera
 */
static int
camera_get_config (Camera* camera, CameraWidget** window, GPContext *context)
{
	unsigned char cmd[2], buf[INFO_BUFFER];
	int ret;
        CameraWidget *widget;
        CameraWidget *section;
	time_t timestamp=0;
	float value_float;

	GP_DEBUG ("*** ENTER: camera_get_config ***");

	/* get informations about camera */
	cmd[0] = ESC;
	cmd[1] = GETCAMINFO;
	ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd));
	if (ret<GP_OK)
		return ret;
	ret = gp_port_read (camera->port, (char*)buf, INFO_BUFFER);
	if (ret<GP_OK)
		return ret;

	/* Informations manipulation */
	timestamp = (buf[TIMESTAMP_PTR] << 24) + (buf[TIMESTAMP_PTR+1] << 16)
		+ (buf[TIMESTAMP_PTR+2] << 8) + buf[TIMESTAMP_PTR+3];
	/*
	 * This timestamp start the 1 January 1980 at 00:00 
	 * but UNIX timestamp start the 1 January 1970 at 00:00
	 * so we calculate the UNIX timestamp with the camera's one
	 */
	timestamp += (8*365 + 2*366)*24*3600-3600;

	/* Window creation */
	gp_widget_new (GP_WIDGET_WINDOW, _("Konica Configuration"), window);

        /************************/
        /* Persistent Settings  */
        /************************/
        gp_widget_new (GP_WIDGET_SECTION, _("Persistent Settings"), &section);
        gp_widget_append (*window, section);

        /* Date */
        gp_widget_new (GP_WIDGET_DATE, _("Date and Time"), &widget);
        gp_widget_append (section, widget);
        gp_widget_set_value (widget, &timestamp);

        /* Auto Off Time */
        gp_widget_new (GP_WIDGET_RANGE, _("Auto Off Time"), &widget);
        gp_widget_append (section, widget);
        gp_widget_set_range (widget, 1, 255, 1);
        value_float = ((buf[AUTO_OFF_PTR] << 8) + buf[AUTO_OFF_PTR+1]) / 60;
        gp_widget_set_value (widget, &value_float);


        /* Resolution */
        gp_widget_new (GP_WIDGET_RADIO, _("Resolution"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Low"));
        gp_widget_add_choice (widget, _("Medium"));
        gp_widget_add_choice (widget, _("High"));
        switch (buf[RESOLUTION_PTR]) {
	        case 1:
        	        gp_widget_set_value (widget, _("High"));
                	break;
	        case 2:
        	        gp_widget_set_value (widget, _("Low"));
	               	break;
		case 0:
        	        gp_widget_set_value (widget, _("Medium"));
                	break;
        }

        /* LCD */
        gp_widget_new (GP_WIDGET_RADIO, _("LCD"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("On"));
        gp_widget_add_choice (widget, _("Off"));
        switch (buf[LCD_STATE_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("On"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("Off"));
                	break;
        }

        /* Icons */
        gp_widget_new (GP_WIDGET_RADIO, _("Icons"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("On"));
        gp_widget_add_choice (widget, _("Off"));
        switch (buf[ICON_STATE_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("On"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("Off"));
                	break;
        }

        /****************/
        /* Localization */
        /****************/
        gp_widget_new (GP_WIDGET_SECTION, _("Localization"), &section);
        gp_widget_append (*window, section);

        /* Date format */
        gp_widget_new (GP_WIDGET_MENU, _("Date Format"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Month/Day/Year"));
        gp_widget_add_choice (widget, _("Day/Month/Year"));
        gp_widget_add_choice (widget, _("Year/Month/Day"));
	switch (buf[DATE_FORMAT_PTR]) {
		case 0:
			gp_widget_set_value (widget, _("Month/Day/Year"));
			break;
		case 1:
			gp_widget_set_value (widget, _("Day/Month/Year"));
			break;
		case 2:
			gp_widget_set_value (widget, _("Year/Month/Day"));
			break;
	}

	/********************************/
        /* Session-persistent Settings  */
        /********************************/
        gp_widget_new (GP_WIDGET_SECTION, _("Session-persistent Settings"),
                       &section);
        gp_widget_append (*window, section);

        /* Flash */
        gp_widget_new (GP_WIDGET_RADIO, _("Flash"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Off"));
        gp_widget_add_choice (widget, _("On"));
        gp_widget_add_choice (widget, _("On, red-eye reduction"));
        gp_widget_add_choice (widget, _("Auto"));
        gp_widget_add_choice (widget, _("Auto, red-eye reduction"));
        switch (buf[FLASH_STATE_PTR]) {
	        case 2:
        	        gp_widget_set_value (widget, _("Off"));
                	break;
	        case 1:
			if (buf[RED_EYE_STATE_PTR] == 1)
	        	        gp_widget_set_value (widget, 
					_("On, red-eye reduction"));
			else
				gp_widget_set_value (widget, _("On"));
                	break;
	        case 0:
			if (buf[RED_EYE_STATE_PTR] == 1)
	        	        gp_widget_set_value (widget, 
					_("Auto, red-eye reduction"));
			else
				gp_widget_set_value (widget, _("Auto"));
                	break;
        }

        /* Exposure */
        gp_widget_new (GP_WIDGET_RANGE, _("Exposure"), &widget);
        gp_widget_append (section, widget);
        gp_widget_set_range (widget, -2, 2, 0.1);
	switch(buf[EXPOSURE_TIME_PTR]) {
		case 0:
			value_float = 0;
			break;
		case 1:
			value_float = 0.3;
			break;
		case 2:
			value_float = 0.5;
			break;
		case 3:
			value_float = 0.8;
			break;
		case 4:
			value_float = 1.0;
			break;
		case 5:
			value_float = 1.3;
			break;
		case 6:
			value_float = 1.5;
			break;
		case 7:
			value_float = 1.8;
			break;
		case 8:
			value_float = 2.0;
			break;
		case 0xF8:
			value_float = -2.0;
			break;
		case 0xF9:
			value_float = -1.8;
			break;
		case 0xFA:
			value_float = -1.5;
			break;
		case 0xFB:
			value_float = -1.3;
			break;
		case 0xFC:
			value_float = -1.0;
			break;
		case 0xFD:
			value_float = -0.8;
			break;
		case 0xFE:
			value_float = -0.5;
			break;
		case 0xFF:
			value_float = -0.3;
			break;
	}
        gp_widget_set_value (widget, &value_float);

       /* Focus */
        gp_widget_new (GP_WIDGET_RADIO, _("Focus"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("2.0 m"));
	gp_widget_add_choice (widget, _("0.5 m"));
	gp_widget_add_choice (widget, _("0.1 m"));
        gp_widget_add_choice (widget, _("Auto"));
        switch (buf[FOCUS_PTR]) {
		case 0:
			gp_widget_set_value (widget, _("Auto"));
			break;
		case 1:
	                gp_widget_set_value (widget, _("2.0 m"));
	                break;
	        case 2:
        	        gp_widget_set_value (widget, _("0.5 m"));
                	break;
	        case 3:
        	        gp_widget_set_value (widget, _("0.1 m"));
                	break;
        }

       /* white balance */
        gp_widget_new (GP_WIDGET_RADIO, _("White balance"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Office"));
	gp_widget_add_choice (widget, _("Daylight"));
	gp_widget_add_choice (widget, _("Auto"));
        switch (buf[WHITE_BALANCE_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("Auto"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("Daylight"));
                	break;
	        case 2:
        	        gp_widget_set_value (widget, _("Office"));
                	break;
	}

       /* Sharpness */
        gp_widget_new (GP_WIDGET_RADIO, _("Sharpness"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Sharp"));
	gp_widget_add_choice (widget, _("Soft"));
	gp_widget_add_choice (widget, _("Auto"));
        switch (buf[SHARPNESS_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("Auto"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("Sharp"));
                	break;
	        case 2:
        	        gp_widget_set_value (widget, _("Soft"));
                	break;
	}

       /* Color */
        gp_widget_new (GP_WIDGET_RADIO, _("Color"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Light"));
	gp_widget_add_choice (widget, _("Deep"));
	gp_widget_add_choice (widget, _("Black and White"));
	gp_widget_add_choice (widget, _("Sepia"));
	gp_widget_add_choice (widget, _("Auto"));
        switch (buf[COLOR_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("Auto"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("Light"));
                	break;
	        case 2:
        	        gp_widget_set_value (widget, _("Deep"));
                	break;
	        case 3:
        	        gp_widget_set_value (widget, _("Black and White"));
                	break;
	        case 4:
        	        gp_widget_set_value (widget, _("Sepia"));
                	break;
	}

       /* Macro */
        gp_widget_new (GP_WIDGET_RADIO, _("Macro"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("On"));
	gp_widget_add_choice (widget, _("Off"));
        switch (buf[MACRO_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("Off"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("On"));
                	break;
	}

       /* Zoom */
        gp_widget_new (GP_WIDGET_RADIO, _("Zoom"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("On"));
	gp_widget_add_choice (widget, _("Off"));
        switch (buf[ZOOM_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("Off"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("On"));
                	break;
	}

       /* Capture */
        gp_widget_new (GP_WIDGET_RADIO, _("Capture"), &widget);
        gp_widget_append (section, widget);
	gp_widget_add_choice (widget, _("Single"));
	gp_widget_add_choice (widget, _("Sequence 9"));
        switch (buf[CAPTURE_TYPE_PTR]) {
	        case 0:
        	        gp_widget_set_value (widget, _("Single"));
                	break;
	        case 1:
        	        gp_widget_set_value (widget, _("Sequence 9"));
                	break;
	}

       /* Date display */
        gp_widget_new (GP_WIDGET_RADIO, _("Date display"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Anywhere"));
	gp_widget_add_choice (widget, _("Play mode"));
	gp_widget_add_choice (widget, _("Record mode"));
	gp_widget_add_choice (widget, _("Everywhere"));
        switch (buf[REC_DATE_DISP_PTR]) {
	        case 0:
			if (buf[PLAY_DATE_DISP_PTR] == 0)
				gp_widget_set_value (widget, _("Play mode"));
			else
        	        	gp_widget_set_value (widget, _("Anywhere"));
                	break;
	        case 1:
			if (buf[PLAY_DATE_DISP_PTR] == 0)
				gp_widget_set_value (widget, _("Everywhere"));
			else
        	        	gp_widget_set_value (widget, _("Record mode"));
                	break;
	}

        /************************/
        /* Volatile Settings    */
        /************************/
        gp_widget_new (GP_WIDGET_SECTION, _("Volatile Settings"), &section);
        gp_widget_append (*window, section);

        /* Self Timer */
        gp_widget_new (GP_WIDGET_RADIO, _("Self Timer"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Self Timer (next picture only)"));
        gp_widget_add_choice (widget, _("Normal"));
        switch (buf[TIMER_PTR]) {
	        case 1:
        	        gp_widget_set_value (widget, _("Self Timer ("
                	                     "next picture only)"));
	                break;
	        case 0:
        	        gp_widget_set_value (widget, _("Normal"));
                	break;
	        }
	return (GP_OK);
}
Beispiel #23
0
static void _camera_process_job(const dt_camctl_t *c,const dt_camera_t *camera, gpointer job)
{
  dt_camera_t *cam=(dt_camera_t *)camera;
  _camctl_camera_job_t *j = (_camctl_camera_job_t *)job;
  switch( j->type )
  {

    case _JOB_TYPE_EXECUTE_CAPTURE:
    {
      dt_print (DT_DEBUG_CAMCTL,"[camera_control] executing remote camera capture job\n");
      CameraFilePath fp;
      int res=GP_OK;
      if( (res = gp_camera_capture (camera->gpcam, GP_CAPTURE_IMAGE,&fp, c->gpcontext)) == GP_OK )
      {
        CameraFile *destination;
        const char *output_path = _dispatch_request_image_path(c,camera);
        if( !output_path ) output_path="/tmp";
        const char *fname = _dispatch_request_image_filename(c,fp.name,cam);
        if( !fname ) fname=fp.name;

        char *output = g_build_filename (output_path,fname,(char *)NULL);

        int handle = open (output, O_CREAT | O_WRONLY,0666);
        gp_file_new_from_fd (&destination , handle);
        gp_camera_file_get (camera->gpcam, fp.folder , fp.name, GP_FILE_TYPE_NORMAL, destination,  c->gpcontext);
        close (handle);

        // Notify listerners of captured image
        _dispatch_camera_image_downloaded (c,camera,output);
        g_free (output);
      }
      else
        dt_print (DT_DEBUG_CAMCTL,"[camera_control] capture job failed to capture image: %s\n",gp_result_as_string(res));


    }
    break;

    case _JOB_TYPE_EXECUTE_LIVE_VIEW:
    {
      CameraFile *fp = NULL;
      int res = GP_OK;
      const gchar* data = NULL;
      unsigned long int data_size = 0;

      gp_file_new(&fp);

      if( (res = gp_camera_capture_preview (cam->gpcam, fp, c->gpcontext)) != GP_OK )
      {
        dt_print (DT_DEBUG_CAMCTL,"[camera_control] live view failed to capture preview: %s\n", gp_result_as_string(res));
      }
      else if( (res = gp_file_get_data_and_size(fp, &data, &data_size)) != GP_OK )
      {
        dt_print (DT_DEBUG_CAMCTL,"[camera_control] live view failed to get preview data: %s\n", gp_result_as_string(res));
      }
      else
      {
        // everything worked
        GdkPixbufLoader *loader = gdk_pixbuf_loader_new();
        if(gdk_pixbuf_loader_write(loader, (guchar*)data, data_size, NULL) == TRUE)
        {
          dt_pthread_mutex_lock(&cam->live_view_pixbuf_mutex);
          if(cam->live_view_pixbuf != NULL)
            g_object_unref(cam->live_view_pixbuf);
          cam->live_view_pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
          dt_pthread_mutex_unlock(&cam->live_view_pixbuf_mutex);
        }
        gdk_pixbuf_loader_close(loader, NULL);
      }
      if(fp)
        gp_file_free(fp);
      dt_pthread_mutex_unlock(&cam->live_view_synch);
      dt_control_queue_redraw_center();
    }
    break;

    case _JOB_TYPE_SET_PROPERTY:
    {
      _camctl_camera_set_property_job_t *spj=(_camctl_camera_set_property_job_t *)job;
      dt_print(DT_DEBUG_CAMCTL,"[camera_control] executing set camera config job %s=%s\n",spj->name,spj->value);

      CameraWidget *config; // Copy of camera configuration
      CameraWidget *widget;
      gp_camera_get_config( cam->gpcam, &config, c->gpcontext );
      if(  gp_widget_get_child_by_name ( config, spj->name, &widget) == GP_OK)
      {
        gp_widget_set_value ( widget , spj->value);
        gp_camera_set_config( cam->gpcam, config, c->gpcontext );
      }
      /* dt_pthread_mutex_lock( &cam->config_lock );
       CameraWidget *widget;
       if(  gp_widget_get_child_by_name ( camera->configuration, spj->name, &widget) == GP_OK) {
      	 gp_widget_set_value ( widget , spj->value);
      	 //gp_widget_set_changed( widget, 1 );
      	 cam->config_changed=TRUE;
       }

       dt_pthread_mutex_unlock( &cam->config_lock);*/
    }
    break;

    default:
      dt_print(DT_DEBUG_CAMCTL,"[camera_control] process of unknown job type %lx\n",(unsigned long int)j->type);
      break;
  }

  g_free(j);
}
Beispiel #24
0
bool photo_camera::photo_camera_set_config( std::string param, std::string value )
{
  CameraWidget *root, *child;
  int error_code;
  const char *label;
  CameraWidgetType type;

  // Locate the widget that corresponds to this parameter
  if( photo_camera_find_widget_by_name( param, &child, &root ) != GP_OK )
  {
    photo_reporter::error( "photo_camera_find_widget_by_name()");
    return false;
  }

  // Get the widget label
  if( gp_widget_get_label(child, &label) != GP_OK )
  {
    photo_reporter::error( "gp_widget_get_label()");
    gp_widget_free( root );
    return false;
  }

  // Get the widget type
  if( gp_widget_get_type( child, &type ) != GP_OK )
  {
    photo_reporter::error( "gp_widget_get_type()");
    gp_widget_free( root );
    return false;
  }
    
  switch( type )
  {

  case GP_WIDGET_TEXT: // char*
    if( gp_widget_set_value(child, value.c_str()) != GP_OK )
    {
      photo_reporter::error( "gp_widget_set_value()");
      gp_context_error( context_, "Failed to set the value of text widget %s to %s.", param.c_str(), value.c_str() );
      gp_widget_free( root );
      return false;
    }
    break;

  case GP_WIDGET_RANGE: // float
    float f, t, b, s;

    if( gp_widget_get_range( child, &b, &t, &s) != GP_OK )
    {
      photo_reporter::error( "gp_widget_get_range()" );
      gp_widget_free( root );
      return false;
    }
    if( !sscanf( value.c_str(), "%f", &f ) )
    {
      gp_context_error( context_, "The passed value %s is not a floating point value.", value.c_str() );
      gp_widget_free( root );
      return false;
    }
    if( (f < b) || (f > t) )
    {
      gp_context_error( context_ , "The passed value %f is not within the expected range of %f -- %f.", f, b, t );
      gp_widget_free( root );
      return false;
    }
    if( gp_widget_set_value( child, &f ) != GP_OK )
    {
      photo_reporter::error( "gp_widget_set_value()" );
      gp_context_error( context_, "Failed to set the value of range widget %s to %f.", param.c_str(), f );
      gp_widget_free( root );
      return false;
    }
    break;

  case GP_WIDGET_TOGGLE: // int
    bool tog;
    if( photo_camera_check_toggle_value( value, &tog ) == false )
    {
      gp_context_error(context_, "The passed value %s is not a valid toggle value.", value.c_str() );
      gp_widget_free( root );
      return false;
    }
    if( gp_widget_set_value( child, &tog ) != GP_OK )
    {
      photo_reporter::error( "gp_widget_set_value()" );
      gp_context_error( context_, "Failed to set values %s of toggle widget %s.", value.c_str(), param.c_str() );
      gp_widget_free( root );
      return false;
    }
    break;
  
  case GP_WIDGET_DATE: // int
  {
    int time = -1;
#ifdef HAVE_STRPTIME
    struct tm xtm;
    
    if( strptime( value.c_str(), "%c", &xtm ) || strptime( value.c_str(), "%Ec", &xtm ) )
    {
      time = mktime( &xtm );
    }
#endif
    if( time == -1 )
    {
      if( !sscanf( value.c_str(), "%d", &time ) )
      {
        gp_context_error( context_, "The passed value %s is neither a valid time nor an integer.", value.c_str() );
	gp_widget_free( root );
	return false;
      }
    }
    if( gp_widget_set_value(child, &time) != GP_OK )
    {
      photo_reporter::error( "gp_widget_set_value()" );
      gp_context_error( context_, "Failed to set new time of date/time widget %s to %s.", param.c_str(), value.c_str() );
      gp_widget_free( root );
      return false;
    }
    break;
  }

  case GP_WIDGET_MENU:
  case GP_WIDGET_RADIO: // char*
    int count, i;
    count = gp_widget_count_choices( child );
    if( count < GP_OK )
    {
      photo_reporter::error( "gp_widget_count_choices()" );
      gp_widget_free( root );
      return false;
    }

    error_code = GP_ERROR_BAD_PARAMETERS;
    for( i = 0; i < count; i++ )
    {
      const char *choice;
      if( gp_widget_get_choice( child, i, &choice ) == GP_OK )
      {
	if( value.compare( choice ) == 0 )
	{
	  if( gp_widget_set_value( child, value.c_str() ) == GP_OK )
	  {
	    break;
	  }
	}
      }
    }
    // attemt a different method for setting a radio button
    if( sscanf( value.c_str(), "%d", &i ) )
    {
      if( (i >= 0) && (i < count) )
      {
        const char *choice;
        if( gp_widget_get_choice( child, i, &choice ) == GP_OK )
	{
	  if( gp_widget_set_value( child, choice ) == GP_OK )
	  {
	    break;
	  }
	}
      }
    }
    gp_context_error( context_, "Choice %s not found within list of choices.", value.c_str() );
    gp_widget_free( root );
    return false;
  
  case GP_WIDGET_WINDOW:
  case GP_WIDGET_SECTION:
  case GP_WIDGET_BUTTON:
  default:
    gp_context_error( context_,"The %s widget is not configurable.", param.c_str() );
    gp_widget_free( root );
    return false;
  }


  // Configuration parameters are correct, so set the camera
  if( gp_camera_set_config( camera_, root, context_ ) != GP_OK )
  {
    photo_reporter::error( "gp_camera_set_config()" );
    gp_context_error( context_, "Failed to set new configuration value %s for configuration entry %s.", value.c_str(), param.c_str() );
    gp_widget_free( root );
    return false;
  }

  gp_widget_free( root );
  return true;
}
Beispiel #25
0
/* Manual focusing a camera...
 * xx is -3 / -2 / -1 / 0 / 1 / 2 / 3
 */
int
camera_manual_focus (Camera *camera, int xx, GPContext *context) {
	CameraWidget		*widget = NULL, *child = NULL;
	CameraWidgetType	type;
	int			ret;
	float			rval;
	char			*mval;

	ret = gp_camera_get_config (camera, &widget, context);
	if (ret < GP_OK) {
		fprintf (stderr, "camera_get_config failed: %d\n", ret);
		return ret;
	}
	ret = _lookup_widget (widget, "manualfocusdrive", &child);
	if (ret < GP_OK) {
		fprintf (stderr, "lookup 'manualfocusdrive' failed: %d\n", ret);
		goto out;
	}

	/* check that this is a toggle */
	ret = gp_widget_get_type (child, &type);
	if (ret < GP_OK) {
		fprintf (stderr, "widget get type failed: %d\n", ret);
		goto out;
	}
	switch (type) {
        case GP_WIDGET_RADIO: {
		int choices = gp_widget_count_choices (child);

		ret = gp_widget_get_value (child, &mval);
		if (ret < GP_OK) {
			fprintf (stderr, "could not get widget value: %d\n", ret);
			goto out;
		}
		if (choices == 7) { /* see what Canon has in EOS_MFDrive */
			ret = gp_widget_get_choice (child, xx+4, (const char**)&mval);
			if (ret < GP_OK) {
				fprintf (stderr, "could not get widget choice %d: %d\n", xx+2, ret);
				goto out;
			}
			fprintf(stderr,"manual focus %d -> %s\n", xx, mval);
		}
		ret = gp_widget_set_value (child, mval);
		if (ret < GP_OK) {
			fprintf (stderr, "could not set widget value to 1: %d\n", ret);
			goto out;
		}
		break;
	}
        case GP_WIDGET_RANGE:
		ret = gp_widget_get_value (child, &rval);
		if (ret < GP_OK) {
			fprintf (stderr, "could not get widget value: %d\n", ret);
			goto out;
		}
	
		switch (xx) { /* Range is on Nikon from -32768 <-> 32768 */
		case -3:	rval = -1024;break;
		case -2:	rval =  -512;break;
		case -1:	rval =  -128;break;
		case  0:	rval =     0;break;
		case  1:	rval =   128;break;
		case  2:	rval =   512;break;
		case  3:	rval =  1024;break;

		default:	rval = xx;	break; /* hack */
		}

		fprintf(stderr,"manual focus %d -> %f\n", xx, rval);

		ret = gp_widget_set_value (child, &rval);
		if (ret < GP_OK) {
			fprintf (stderr, "could not set widget value to 1: %d\n", ret);
			goto out;
		}
		break;
	default:
		fprintf (stderr, "widget has bad type %d\n", type);
		ret = GP_ERROR_BAD_PARAMETERS;
		goto out;
	}


	ret = gp_camera_set_config (camera, widget, context);
	if (ret < GP_OK) {
		fprintf (stderr, "could not set config tree to autofocus: %d\n", ret);
		goto out;
	}
out:
	gp_widget_free (widget);
	return ret;
}
Beispiel #26
0
/**
 * @brief CameraHandler::setConfigAction
 * @param p
 * @param name
 * @param value
 * @return
 */
int QTLCamera::setConfigAction(const char *name, const char *value) {
    CameraWidget *rootConfig,*child;
    int rc;
    const char *label;
    CameraWidgetType type;

    rc = findWidgetByName(name, &child, &rootConfig);
    if (rc != GP_OK) {
        return rc;
    }

    rc = gp_widget_get_type (child, &type);
    if (rc != GP_OK) {
        gp_widget_free(rootConfig);
        return rc;
    }
    rc = gp_widget_get_label(child, &label);
    if (rc != GP_OK) {
        gp_widget_free(rootConfig);
        return rc;
    }

    switch (type) {
    case GP_WIDGET_TOGGLE: {
    }
    case GP_WIDGET_TEXT: {      /* char *       */
        rc = gp_widget_set_value(child, value);
        if (rc != GP_OK) {
            qDebug() << "Failed to set the value of text widget" << name << value;
        }
        break;
    }
    case GP_WIDGET_RANGE: { /* float        */
        float floatValue, top, bottom, s;

        rc = gp_widget_get_range(child, &bottom, &top, &s);
        if (rc != GP_OK)
            break;
        if (!sscanf(value, "%f", &floatValue)) {
            qDebug() << "The passed value" << value << "is not a floating point value.";
            rc = GP_ERROR_BAD_PARAMETERS;
            break;
        }
        if ((floatValue < bottom) || (floatValue > top)) {
            qDebug () << "The passed value" << floatValue << "is not within the expected range"
                      << bottom << "-" << top << ".";
            rc = GP_ERROR_BAD_PARAMETERS;
            break;
        }
        rc = gp_widget_set_value(child, &floatValue);
        if (rc != GP_OK) {
            qDebug() << "Failed to set the value of range widget" << name << "to"
                     << floatValue << ".";
        }
        break;
    }
    case GP_WIDGET_DATE:  {     /* int          */
        int t = -1;
        if (t == -1) {
            if (!sscanf(value, "%d", &t)) {
                qDebug() << "The passed value" << value
                         << "is neither a valid time nor an integer.";
                rc = GP_ERROR_BAD_PARAMETERS;
                break;
            }
        }
        rc = gp_widget_set_value(child, &t);
        if (rc != GP_OK) {
            qDebug() << "Failed to set new time of date/time widget " << name
                     << " to " << value << ".";
        }
        break;
    }
    case GP_WIDGET_MENU:
    case GP_WIDGET_RADIO: { /* char *       */
        int cnt, i;

        cnt = gp_widget_count_choices(child);
        if (cnt < GP_OK) {
            rc = cnt;
            break;
        }
        rc = GP_ERROR_BAD_PARAMETERS;
        for (i=0; i<cnt; i++) {
            const char *choice;

            rc = gp_widget_get_choice(child, i, &choice);
            if (rc != GP_OK) {
                continue;
            }
            if (!strcmp(choice, value)) {
                rc = gp_widget_set_value(child, value);
                break;
            }
        }
        if (i != cnt) {
            break;
        }

        if (sscanf(value, "%d", &i)) {
            if ((i >= 0) && (i < cnt)) {
                const char *choice;

                rc = gp_widget_get_choice(child, i, &choice);
                if (rc == GP_OK) {
                    rc = gp_widget_set_value(child, choice);
                }
                break;
            }
        }
        qDebug() << "Choice " << value << " not found within list of choices.";
        break;
    }

    /* ignore: */
    case GP_WIDGET_WINDOW:
    case GP_WIDGET_SECTION:
    case GP_WIDGET_BUTTON:
        //gp_context_error(p->context, _("The %s widget is not configurable."), name);
        rc = GP_ERROR_BAD_PARAMETERS;
        break;
    }
    if (rc == GP_OK) {
        rc = gp_camera_set_config(params->camera, rootConfig, params->context);
        if (rc != GP_OK) {
            qDebug() << "Failed to set new configuration value " << value << " for configuration entry " << name << ".";
        }
    }
    gp_widget_free(rootConfig);
    return rc;
}
Beispiel #27
0
static int
camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
{
	CameraWidget *section, *widget;
	CameraAbilities abilities;
	GPPortSettings settings;
	int i;
	char * wvalue;
	char stringbuffer[12];
	
	dc210_status status;

	if (dc210_get_status(camera, &status) == GP_ERROR) return GP_ERROR;

	gp_widget_new (GP_WIDGET_WINDOW, _("Camera Configuration"), window);

	gp_widget_new (GP_WIDGET_SECTION, _("File"), &section);
	gp_widget_append (*window, section);

        gp_widget_new (GP_WIDGET_RADIO, _("File type"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("JPEG"));
        gp_widget_add_choice (widget, _("FlashPix"));

	switch (status.file_type){
	case DC210_FILE_TYPE_JPEG:  
	  gp_widget_set_value (widget, _("JPEG")); break;
	case DC210_FILE_TYPE_FPX:  
	  gp_widget_set_value (widget, _("FlashPix")); break;
	};
	gp_widget_get_value (widget, &wvalue);

        gp_widget_new (GP_WIDGET_RADIO, _("File resolution"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("640 x 480"));
        gp_widget_add_choice (widget, _("1152 x 864"));

	switch (status.resolution){
	case DC210_FILE_640:  
	  gp_widget_set_value (widget, _("640 x 480")); break;
	case DC210_FILE_1152:  
	  gp_widget_set_value (widget, _("1152 x 864")); break;
	default:
	  DC210_DEBUG("Undefined value for file resolution.\n"); break;
	};
	gp_widget_get_value (widget, &wvalue);

        gp_widget_new (GP_WIDGET_MENU, _("File compression"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Low (best quality)"));
        gp_widget_add_choice (widget, _("Medium (better quality)"));
        gp_widget_add_choice (widget, _("High (good quality)"));

	switch (status.compression_type){
	case DC210_LOW_COMPRESSION:  
	  gp_widget_set_value (widget, _("Low (best quality)")); break;
	case DC210_MEDIUM_COMPRESSION:  
	  gp_widget_set_value (widget, _("Medium (better quality)")); break;
	case DC210_HIGH_COMPRESSION:  
	  gp_widget_set_value (widget, _("High (good quality)")); break;
	};
	gp_widget_get_value (widget, &wvalue);

	gp_widget_new (GP_WIDGET_SECTION, _("Capture"), &section);
	gp_widget_append (*window, section);

        gp_widget_new (GP_WIDGET_MENU, _("Zoom"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, "58 mm"); /* no need to translate strings with SI units! */
        gp_widget_add_choice (widget, "51 mm");
        gp_widget_add_choice (widget, "41 mm");
        gp_widget_add_choice (widget, "34 mm");
        gp_widget_add_choice (widget, "29 mm");
        gp_widget_add_choice (widget, _("Macro"));

	switch (status.zoom){
	case DC210_ZOOM_58:  
	  gp_widget_set_value (widget, _("58 mm")); break;
	case DC210_ZOOM_51:  
	  gp_widget_set_value (widget, _("51 mm")); break;
	case DC210_ZOOM_41:  
	  gp_widget_set_value (widget, _("41 mm")); break;
	case DC210_ZOOM_34:  
	  gp_widget_set_value (widget, _("34 mm")); break;
	case DC210_ZOOM_29:  
	  gp_widget_set_value (widget, _("29 mm")); break;
	case DC210_ZOOM_MACRO:  
	  gp_widget_set_value (widget, _("Macro")); break;
	};
	gp_widget_get_value (widget, &wvalue);

        gp_widget_new (GP_WIDGET_MENU, _("Exposure compensation"), &widget);
        gp_widget_append (section, widget);
	for (i = 0; i < sizeof(exp_comp)/sizeof(*exp_comp); i++){
		gp_widget_add_choice (widget, exp_comp[i]);
		if (status.exp_compensation + 4 == i)
			gp_widget_set_value (widget, exp_comp[i]);
	};

        gp_widget_new (GP_WIDGET_RADIO, _("Flash"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("Auto"));
        gp_widget_add_choice (widget, _("Force"));
        gp_widget_add_choice (widget, _("None"));

	switch (status.flash){
	case DC210_FLASH_AUTO:  
	  gp_widget_set_value (widget, _("Auto")); break;
	case DC210_FLASH_FORCE:  
	  gp_widget_set_value (widget, _("Force")); break;
	case DC210_FLASH_NONE:  
	  gp_widget_set_value (widget, _("None")); break;
	};
	gp_widget_get_value (widget, &wvalue);

        gp_widget_new (GP_WIDGET_RADIO, _("Red eye flash"), &widget);
        gp_widget_append (section, widget);
        gp_widget_add_choice (widget, _("On"));
        gp_widget_add_choice (widget, _("Off"));

	if (status.preflash)
	  gp_widget_set_value (widget, _("On"));
	else
	  gp_widget_set_value (widget, _("Off"));
	gp_widget_get_value (widget, &wvalue);

	gp_widget_new (GP_WIDGET_SECTION, _("Other"), &section);
	gp_widget_append (*window, section);

        gp_widget_new (GP_WIDGET_BUTTON, "Set time to system time", &widget);
        gp_widget_append (section, widget);
	gp_widget_set_value (widget, dc210_system_time_callback);
	gp_widget_set_info (widget, _("Set clock in camera"));
	
	gp_camera_get_abilities(camera, &abilities);
	gp_port_get_settings (camera->port, &settings);
        gp_widget_new (GP_WIDGET_MENU, _("Port speed"), &widget);
        gp_widget_append (section, widget);
	for (i = 0; i < sizeof(abilities.speed); i++){
		if (abilities.speed[i] == 0) break;
		snprintf(stringbuffer, 12, "%d", abilities.speed[i]);
		gp_widget_add_choice (widget, stringbuffer);
		if (settings.serial.speed == abilities.speed[i])
			gp_widget_set_value (widget, stringbuffer);
	};

        gp_widget_new (GP_WIDGET_TEXT, _("Album name"), &widget);
        gp_widget_append (section, widget);
	gp_widget_set_value (widget, status.album_name);
	gp_widget_set_info (widget, _("Name to set on card when formatting."));

        gp_widget_new (GP_WIDGET_BUTTON, _("Format compact flash"), &widget);
        gp_widget_append (section, widget);
	gp_widget_set_value (widget, dc210_format_callback);
	gp_widget_set_info (widget, _("Format card and set album name."));

#ifdef DEBUG
	gp_widget_new (GP_WIDGET_SECTION, _("Debug"), &section);
	gp_widget_append (*window, section);

        gp_widget_new (GP_WIDGET_TEXT, "Parameter 1", &widget);
        gp_widget_append (section, widget);
	gp_widget_set_value (widget, "0");

        gp_widget_new (GP_WIDGET_TEXT, "Parameter 2", &widget);
        gp_widget_append (section, widget);
	gp_widget_set_value (widget, "0");

        gp_widget_new (GP_WIDGET_TEXT, "Parameter 3", &widget);
        gp_widget_append (section, widget);
	gp_widget_set_value (widget, "0");

        gp_widget_new (GP_WIDGET_BUTTON, "Execute debug command", &widget);
        gp_widget_append (section, widget);
	gp_widget_set_value (widget, dc210_debug_callback);
	gp_widget_set_info (widget, _("Execute predefined command\nwith parameter values."));
#endif

	return GP_OK;
}
Beispiel #28
0
static int
camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
{
	CameraWidget *w, *w2;
	char *wvalue, *w2value;
	int i;

	gp_widget_get_child_by_label (window, _("File type"), &w);
	if (gp_widget_changed (w)) {
		gp_widget_get_value (w, &wvalue);
		if (wvalue[0] == 'J')
			dc210_set_file_type(camera, DC210_FILE_TYPE_JPEG);
		else
			dc210_set_file_type(camera, DC210_FILE_TYPE_FPX);
	};

	gp_widget_get_child_by_label (window, _("File resolution"), &w);
	if (gp_widget_changed (w)) {
		gp_widget_get_value (w, &wvalue);
		switch(wvalue[0]){
		case '6':
		  dc210_set_resolution(camera, DC210_FILE_640);
		  break;
		case '1':
		  dc210_set_resolution(camera, DC210_FILE_1152);
		  break;
		};
	};

	gp_widget_get_child_by_label (window, _("File compression"), &w);
	if (gp_widget_changed (w)) {
		gp_widget_get_value (w, &wvalue);
		switch(wvalue[0]){
		case 'L':
		  dc210_set_compression(camera, DC210_LOW_COMPRESSION);
		  break;
		case 'M':
		  dc210_set_compression(camera, DC210_MEDIUM_COMPRESSION);
		  break;
		case 'H':
		  dc210_set_compression(camera, DC210_HIGH_COMPRESSION);
		};
	};

	gp_widget_get_child_by_label (window, _("Zoom"), &w);
	if (gp_widget_changed (w)) {
		gp_widget_get_value (w, &wvalue);
		switch(wvalue[0]){
		case '5':
			if (wvalue[1] == '8')
				dc210_set_zoom(camera, DC210_ZOOM_58);
			else
				dc210_set_zoom(camera, DC210_ZOOM_51);
			break;
		case '4':
			dc210_set_zoom(camera, DC210_ZOOM_41);
			break;
		case '3':
			dc210_set_zoom(camera, DC210_ZOOM_34);
			break;
		case '2':
			dc210_set_zoom(camera, DC210_ZOOM_29);
			break;
		case 'M':
			dc210_set_zoom(camera, DC210_ZOOM_MACRO);
			break;
		};
	};

	gp_widget_get_child_by_label (window, _("Exposure compensation"), &w);
	if (gp_widget_changed (w)) {
		gp_widget_get_value (w, &wvalue);
		for (i = 0; i < sizeof(exp_comp)/sizeof(*exp_comp); i++){
			if (strncmp(wvalue, exp_comp[i], 4) == 0){
				dc210_set_exp_compensation(camera, i - 4);
				break;
			};
		};
	};

	gp_widget_get_child_by_label (window, _("Port speed"), &w);
	if (gp_widget_changed (w)) {
		gp_widget_get_value (w, &wvalue);
		dc210_set_speed(camera, atoi(wvalue));
	};

	gp_widget_get_child_by_label (window, _("Flash"), &w);
	gp_widget_get_child_by_label (window, _("Red eye flash"), &w2);
	if (gp_widget_changed (w) || gp_widget_changed(w2)) {
		gp_widget_get_value (w, &wvalue);
		gp_widget_get_value (w2, &w2value);
		switch(wvalue[0]){
		case 'A':
			dc210_set_flash(camera, DC210_FLASH_AUTO, 
					w2value[1] == 'n' ? 1 : 0);
			break;
		case 'F':
			dc210_set_flash(camera, DC210_FLASH_FORCE, 
					w2value[1] == 'n' ? 1 : 0);
			break;
		case 'N':
			dc210_set_flash(camera, DC210_FLASH_NONE, 0);
			gp_widget_set_value(w2, _("Off"));
			break;
		};
	};

	return GP_OK;
}
bool GPhotoCameraWorker::setParameter(const QString &name, const QVariant &value)
{
    CameraWidget *root;
    int ret = gp_camera_get_config(m_camera, &root, m_context);
    if (ret < GP_OK) {
        qWarning() << "Unable to get root option from gphoto";
        return false;
    }

    // Get widget pointer
    CameraWidget *option;
    ret = gp_widget_get_child_by_name(root, qPrintable(name), &option);
    if (ret < GP_OK) {
        qWarning() << "Unable to get option" << qPrintable(name) << "from gphoto";
        return false;
    }

    // Get option type
    CameraWidgetType type;
    ret = gp_widget_get_type(option, &type);
    if (ret < GP_OK) {
        qWarning() << "Unable to get option type from gphoto";
        gp_widget_free(option);
        return false;
    }

    if (type == GP_WIDGET_RADIO) {
        if (value.type() == QVariant::String) {
            // String, need no conversion
            ret = gp_widget_set_value(option, qPrintable(value.toString()));

            if (ret < GP_OK) {
                qWarning() << "Failed to set value" << value << "to" << name << "option:" << ret;
                return false;
            }

            ret = gp_camera_set_config(m_camera, root, m_context);

            if (ret < GP_OK) {
                qWarning() << "Failed to set config to camera";
                return false;
            }

            waitForOperationCompleted();
            return true;
        } else if (value.type() == QVariant::Double) {
            // Trying to find nearest possible value (with the distance of 0.1) and set it to property
            double v = value.toDouble();

            int count = gp_widget_count_choices(option);
            for (int i = 0; i < count; ++i) {
                const char* choice;
                gp_widget_get_choice(option, i, &choice);

                // We use a workaround for flawed russian i18n of gphoto2 strings
                bool ok;
                double choiceValue = QString::fromLocal8Bit(choice).replace(',', '.').toDouble(&ok);
                if (!ok) {
                    qDebug() << "Failed to convert value" << choice << "to double";
                    continue;
                }

                if (qAbs(choiceValue - v) < 0.1) {
                    ret = gp_widget_set_value(option, choice);
                    if (ret < GP_OK) {
                        qWarning() << "Failed to set value" << choice << "to" << name << "option:" << ret;
                        return false;
                    }

                    ret = gp_camera_set_config(m_camera, root, m_context);
                    if (ret < GP_OK) {
                        qWarning() << "Failed to set config to camera";
                        return false;
                    }

                    waitForOperationCompleted();
                    return true;
                }
            }

            qWarning() << "Can't find value matching to" << v << "for option" << name;
            return false;
        } else if (value.type() == QVariant::Int) {
            // Little hacks for 'ISO' option: if the value is -1, we pick the first non-integer value
            // we found and set it as a parameter
            int v = value.toInt();


            int count = gp_widget_count_choices(option);
            for (int i = 0; i < count; ++i) {
                const char* choice;
                gp_widget_get_choice(option, i, &choice);

                bool ok;
                int choiceValue = QString::fromLocal8Bit(choice).toInt(&ok);

                if ((ok && choiceValue == v) || (!ok && v == -1)) {
                    ret = gp_widget_set_value(option, choice);
                    if (ret < GP_OK) {
                        qWarning() << "Failed to set value" << choice << "to" << name << "option:" << ret;
                        return false;
                    }

                    ret = gp_camera_set_config(m_camera, root, m_context);
                    if (ret < GP_OK) {
                        qWarning() << "Failed to set config to camera";
                        return false;
                    }

                    waitForOperationCompleted();
                    return true;
                }
            }

            qWarning() << "Can't find value matching to" << v << "for option" << name;
            return false;
        } else {
            qWarning() << "Failed to set value" << value << "to" << name << "option. Type" << value.type()
                       << "is not supported";
            gp_widget_free(option);
            return false;
        }
    } else if (type == GP_WIDGET_TOGGLE) {
        int v = 0;
        if (value.canConvert<int>()) {
            v = value.toInt();
        } else {
            qWarning() << "Failed to set value" << value << "to" << name << "option. Type" << value.type()
                       << "is not supported";
            gp_widget_free(option);
            return false;
        }

        ret = gp_widget_set_value(option, &v);
        if (ret < GP_OK) {
          qWarning() << "Failed to set value" << v << "to" << name << "option:" << ret;
          return false;
        }

        ret = gp_camera_set_config(m_camera, root, m_context);
        if (ret < GP_OK) {
          qWarning() << "Failed to set config to camera";
          return false;
        }

        waitForOperationCompleted();
        return true;
    } else {
        qWarning() << "Options of type" << type << "are currently not supported";
    }

    gp_widget_free(option);
    return false;
}
Beispiel #30
0
/**
 * 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;
}