Example #1
0
int set_config_value_string(Camera *camera, const char *key, const 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:
    case GP_WIDGET_TOGGLE:
        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;
}
Example #2
0
/* calls the Nikon DSLR or Canon DSLR autofocus method. */
int
camera_eosviewfinder(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, "eosviewfinder", &child);
	if (ret < GP_OK) {
		fprintf (stderr, "lookup 'eosviewfinder' 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 eosviewfinder: %d\n", ret);
		goto out;
	}
out:
	gp_widget_free (widget);
	return ret;
}
Example #3
0
int get_config_value_string (Camera *camera, const char *key, char **str, GPContext *context)
{
	CameraWidget *widget = NULL, *child = NULL;
	CameraWidgetType type;
	int	ret;
	char *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, 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 query call. Note that we just
	 * a pointer reference to the string, not a copy... */
	ret = gp_widget_get_value (child, &val);
	if (ret < GP_OK) 
	{
		fprintf (stderr, "could not query widget value: %d\n", ret);
		goto out;
	}
	/* Create a new copy for our caller. */
	*str = strdup (val);
out:
	gp_widget_free (widget);
	return ret;
}
Example #4
0
void _camera_build_property_menu (CameraWidget *widget,GtkMenu *menu, GCallback item_activate,gpointer user_data)
{
  int childs = 0;
  const char *sk;
  CameraWidgetType type;

  /* if widget has children lets add menutitem and recurse into container */
  if( ( childs = gp_widget_count_children ( widget ) ) > 0 )
  {
    CameraWidget *child = NULL;
    for (int i = 0 ; i < childs ; i++)
    {
      gp_widget_get_child (widget, i, &child);
      gp_widget_get_name (child, &sk);

      /* Check if widget is submenu */
      if ( gp_widget_count_children (child) > 0 )
      {
        /* create submenu item */
        GtkMenuItem *item = GTK_MENU_ITEM (gtk_menu_item_new_with_label (sk));
        gtk_menu_item_set_submenu (item, gtk_menu_new ());

        /* recurse into submenu */
        _camera_build_property_menu (child, GTK_MENU (gtk_menu_item_get_submenu (item)), item_activate, user_data);

        /* add submenu item to menu if not empty*/
        if (gtk_container_get_children(GTK_CONTAINER(gtk_menu_item_get_submenu (item))) != NULL)
          gtk_menu_shell_append(GTK_MENU_SHELL (menu),GTK_WIDGET (item));
      }
      else
      {
        /* check widget type */
        gp_widget_get_type( child, &type );
        if(
          type == GP_WIDGET_MENU || type == GP_WIDGET_TEXT || type == GP_WIDGET_RADIO
        )
        {
          /* construct menu item for property */
          gp_widget_get_name (child, &sk);
          GtkMenuItem *item =  GTK_MENU_ITEM (gtk_menu_item_new_with_label (sk));
          g_signal_connect (G_OBJECT (item), "activate", item_activate, user_data);
          /* add submenu item to menu */
          gtk_menu_shell_append(GTK_MENU_SHELL (menu),GTK_WIDGET (item));
        }
      }
    }
  }
}
QVariant GPhotoCameraWorker::parameter(const QString &name)
{
    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 QVariant();
    }

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

    CameraWidgetType type;
    ret = gp_widget_get_type(option, &type);
    if (ret < GP_OK) {
        qWarning() << "Unable to get config widget type from gphoto";
        return QVariant();
    }

    if (type == GP_WIDGET_RADIO) {
        char *value;
        ret = gp_widget_get_value(option, &value);
        if (ret < GP_OK) {
            qWarning() << "Unable to get value for option" << qPrintable(name) << "from gphoto";
            return QVariant();
        } else {
            return QString::fromLocal8Bit(value);
        }
    } else if (type == GP_WIDGET_TOGGLE) {
        int value;
        ret = gp_widget_get_value(option, &value);
        if (ret < GP_OK) {
            qWarning() << "Unable to get value for option" << qPrintable(name) << "from gphoto";
            return QVariant();
        } else {
            return value == 0 ? false : true;
        }
    } else {
        qWarning() << "Options of type" << type << "are currently not supported";
    }

    return QVariant();
}
Example #6
0
void get_all_widgets(Camera	*camera,GPContext *context,CameraWidget *widget, char *prefix,widgets_list_node *first)
{
	int ret, n, i;
	char *newprefix;
	const char *label, *name, *uselabel;
	CameraWidgetType type;

	gp_widget_get_label (widget, &label);
	/* fprintf(stderr,"label is %s\n", label); */
	ret = gp_widget_get_name (widget, &name);
	/* fprintf(stderr,"name is %s\n", name); */
	gp_widget_get_type (widget, &type);

	if (strlen(name))
		uselabel = name;
	else
		uselabel = label;

	n = gp_widget_count_children (widget);

	newprefix = malloc(strlen(prefix)+1+strlen(uselabel)+1);
	if (!newprefix)
	{
		abort();
	}
	sprintf(newprefix,"%s/%s",prefix,uselabel);

	if ((type != GP_WIDGET_WINDOW) && (type != GP_WIDGET_SECTION)) 
	{
		// int readonly;
		// gp_widget_get_readonly(widget,&readonly);
		// printf("name: %s  readonly: %i \n",name,readonly);
		add_widget(&first,widget);
	}
	for (i=0; i<n; i++) 
	{
		CameraWidget *child;
	
		ret = gp_widget_get_child (widget, i, &child);
		if (ret != GP_OK)
			continue;

		get_all_widgets(camera,context,child,newprefix,first);
	}
	free(newprefix);
}
Example #7
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;
}
Example #8
0
Widget::WidgetType Widget::type() const {
	CameraWidgetType type;
	gp_widget_get_type(widget, &type);
	switch (type) {
		case GP_WIDGET_WINDOW:  return WIDGET_WINDOW;
		case GP_WIDGET_SECTION: return WIDGET_SECTION;
		case GP_WIDGET_TEXT:    return WIDGET_TEXT;
		case GP_WIDGET_RANGE:   return WIDGET_RANGE;
		case GP_WIDGET_TOGGLE:  return WIDGET_TOGGLE;
		case GP_WIDGET_RADIO:   return WIDGET_RADIO;
		case GP_WIDGET_MENU:    return WIDGET_MENU;
		case GP_WIDGET_DATE:    return WIDGET_DATE;
		case GP_WIDGET_BUTTON:  return WIDGET_BUTTON;
	};
	throw std::invalid_argument("Unknown type "
			+ std::to_string(static_cast<int>(type)));
}
Example #9
0
static int
show_widget (CmdConfig *cmd_config, CameraWidget *widget)
{
	CameraWidget *parent;
	CameraWidgetType type;

	CHECK (gp_widget_get_type (widget, &type));
	switch (type) {
	case GP_WIDGET_WINDOW:
	case GP_WIDGET_SECTION:
		CHECK (show_section (cmd_config, widget));
		break;
	case GP_WIDGET_DATE:
		CHECK (show_date (cmd_config, widget));
		CHECK (show_time (cmd_config, widget));
		CHECK (gp_widget_get_parent (widget, &parent));
		CHECK (show_widget (cmd_config, parent));
		break;
	case GP_WIDGET_MENU:
	case GP_WIDGET_RADIO:
		CHECK (show_radio (cmd_config, widget));
		CHECK (gp_widget_get_parent (widget, &parent));
		CHECK (show_widget (cmd_config, parent));
		break;
	case GP_WIDGET_RANGE:
		CHECK (show_range (cmd_config, widget));
		CHECK (gp_widget_get_parent (widget, &parent));
		CHECK (show_widget (cmd_config, parent));
		break;
	case GP_WIDGET_TEXT:
		CHECK (show_text (cmd_config, widget));
		CHECK (gp_widget_get_parent (widget, &parent));
		CHECK (show_widget (cmd_config, parent));
		break;
	case GP_WIDGET_TOGGLE:
		CHECK (show_toggle (cmd_config, widget));
		CHECK (gp_widget_get_parent (widget, &parent));
		CHECK (show_widget (cmd_config, parent));
		break;
	default:
		return (GP_ERROR_NOT_SUPPORTED);
	}

	return (GP_OK);
}
Example #10
0
/**
 * Write all widget descriptions to @param os.
 * @return maximum of widget ID
 */
int DigitalCameraCapture::collectWidgets(std::ostream & os,
        CameraWidget * widget)
{
    int id = widgetDescription(os, widget);
    os << lineDelimiter;

    widgets[id - noOfWidgets] = widget;

    CameraWidget * child;
    CameraWidgetType type;
    CR(gp_widget_get_type(widget, &type));
    if ((type == GP_WIDGET_WINDOW) || (type == GP_WIDGET_SECTION))
    {
        for (int x = 0; x < gp_widget_count_children(widget); x++)
        {
            CR(gp_widget_get_child(widget, x, &child));
            id = std::max(id, collectWidgets(os, child));
        }
    }
    return id;
}
Example #11
0
static void
_get_widget_names (CameraWidget *widget, CameraList *list)
{
	CameraWidgetType	type;

	gp_widget_get_type (widget, &type);
	switch (type) {
        case GP_WIDGET_MENU:
        case GP_WIDGET_RADIO:
        case GP_WIDGET_TEXT:
        case GP_WIDGET_RANGE:
        case GP_WIDGET_TOGGLE:
        case GP_WIDGET_DATE: {
		const char *name;

		gp_widget_get_name (widget, &name);
		gp_list_append (list, name, NULL);
                break;
	}
        case GP_WIDGET_SECTION:
        case GP_WIDGET_WINDOW: {
		int i, nrofchildren;

		nrofchildren = gp_widget_count_children (widget);
		for (i = 0; i < nrofchildren; i++) {
			CameraWidget *child;

			gp_widget_get_child (widget, i, &child);
			_get_widget_names (child, list);
		}
		break;
	}
        case GP_WIDGET_BUTTON:
        default:
		break;
	}

}
void GPhotoCameraWorker::logOption(const char *name)
{
    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;
    }

    CameraWidget *option;
    ret = gp_widget_get_child_by_name(root, name, &option);
    if (ret < GP_OK)
        qWarning() << "Unable to get config widget from gphoto";

    CameraWidgetType type;
    ret = gp_widget_get_type(option, &type);
    if (ret < GP_OK)
        qWarning() << "Unable to get config widget type from gphoto";

    char *value;
    ret = gp_widget_get_value(option, &value);

    qDebug() << "Option" << type << name << value;
    if (type == GP_WIDGET_RADIO) {
        int count = gp_widget_count_choices(option);
        qDebug() << "Choices count:" << count;

        for (int i = 0; i < count; ++i) {
            const char* choice;
            gp_widget_get_choice(option, i, &choice);
            qDebug() << "  value:" << choice;
        }
    }

    gp_widget_free(option);
}
Example #13
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;
}
Example #14
0
/**
 * 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;
}
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;
}
Example #16
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;
}
Example #17
0
bool photo_camera::photo_camera_get_config( std::string param, char** value )
{
  CameraWidget *root, *child;
  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*
    char *txt;
    if( gp_widget_get_value( child, &txt ) != GP_OK )
    {
      gp_context_error( context_, "Failed to retrieve value of text widget %s.", param.c_str() );
    }
    *value = txt;
    break;
 
  case GP_WIDGET_RANGE: // float
    float f, t,b,s;
    if( gp_widget_get_range( child, &b, &t, &s ) != GP_OK )
    {
      gp_context_error( context_, "Failed to retrieve values of range widget %s.", param.c_str() );
    }
    if( gp_widget_get_value( child, &f ) != GP_OK )
    {
      gp_context_error( context_, "Failed to value of range widget %s.", param.c_str() );
    }
    sprintf( *value, "%f", f );
    break;

  case GP_WIDGET_TOGGLE: // int
  {
    int t;
    if( gp_widget_get_value( child, &t ) != GP_OK )
    {
      gp_context_error( context_,"Failed to retrieve values of toggle widget %s.", param.c_str() );
    }
    sprintf( *value, "%d", t );
    break;
  }

  case GP_WIDGET_DATE: // int
  {
    int error_code, t;
    time_t working_time;
    struct tm *localtm;
    char timebuf[200];

    if( gp_widget_get_value( child, &t ) != GP_OK )
    {
      gp_context_error( context_,"Failed to retrieve values of date/time widget %s.", param.c_str() );
      break;
    }
    working_time = t;
    localtm = localtime( &working_time );
    error_code = strftime( timebuf, sizeof(timebuf), "%c", localtm );
    sprintf( *value, "%s", timebuf );
    break;
  }

  case GP_WIDGET_MENU:
  case GP_WIDGET_RADIO: //char*
    char *current;
    if( gp_widget_get_value (child, &current) != GP_OK )
    {
      gp_context_error( context_,"Failed to retrieve values of radio widget %s.", param.c_str() );
    }
    sprintf( *value, "%s", current );
    break;

  // No values, so nothing to return
  case GP_WIDGET_WINDOW:
  case GP_WIDGET_SECTION:
  case GP_WIDGET_BUTTON:
  default:
    break;
  }

  gp_widget_free( root );
  return true;
}
Example #18
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);
    }
  }
}
Example #19
0
void GPConfigDlg::updateWidgetValue(CameraWidget* widget)
{
    CameraWidgetType widget_type;
    gp_widget_get_type(widget, &widget_type);

    switch (widget_type)
    {
        case GP_WIDGET_WINDOW:
            // nothing to do
            break;

        case GP_WIDGET_SECTION:
            // nothing to do
            break;

        case GP_WIDGET_TEXT:
        {
            QLineEdit* lineEdit = static_cast<QLineEdit*>(d->wmap[widget]);
            gp_widget_set_value(widget, (void*)lineEdit->text().toLocal8Bit().data());

            break;
        }

        case GP_WIDGET_RANGE:
        {
            QSlider* slider = static_cast<QSlider*>(d->wmap[widget]);
            float value_float = slider->value();
            gp_widget_set_value(widget, (void*)&value_float);

            break;
        }

        case GP_WIDGET_TOGGLE:
        {
            QCheckBox* checkBox = static_cast<QCheckBox*>(d->wmap[widget]);
            int value_int = checkBox->isChecked() ? 1 : 0;
            gp_widget_set_value(widget, (void*)&value_int);

            break;
        }

        case GP_WIDGET_RADIO:
        {
            Q3ButtonGroup* buttonGroup = static_cast<Q3VButtonGroup*>(d->wmap[widget]);
            gp_widget_set_value(widget, (void*)buttonGroup->selected()->text().toLocal8Bit().data());

            break;
        }

        case GP_WIDGET_MENU:
        {
            QComboBox* comboBox = static_cast<QComboBox*>(d->wmap[widget]);
            gp_widget_set_value(widget, (void*)comboBox->currentText().toLocal8Bit().data());

            break;
        }

        case GP_WIDGET_BUTTON:
            // nothing to do
            break;

        case GP_WIDGET_DATE:
        {
            // not implemented
            break;
        }
    }

    // Copy child widget values
    for (int i = 0; i < gp_widget_count_children(widget); ++i)
    {
        CameraWidget* widget_child;
        gp_widget_get_child(widget, i, &widget_child);
        updateWidgetValue(widget_child);
    }
}
Example #20
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;
}
Example #21
0
void GPConfigDlg::appendWidget(QWidget* parent, CameraWidget* widget)
{
    QWidget* newParent = parent;

    CameraWidgetType widget_type;
    const char* widget_name;
    const char* widget_info;
    const char* widget_label;
    float widget_value_float;
    int widget_value_int;
    const char* widget_value_string;
    gp_widget_get_type(widget, &widget_type);
    gp_widget_get_label(widget, &widget_label);
    gp_widget_get_info(widget, &widget_info);
    gp_widget_get_name(widget, &widget_name);

    // gphoto2 doesn't seem to have any standard for i18n
    QString whats_this = QString::fromLocal8Bit(widget_info);

    // Add this widget to parent
    switch (widget_type)
    {
        case GP_WIDGET_WINDOW:
        {
            setCaption(widget_label);

            break;
        }

        case GP_WIDGET_SECTION:
        {
            if (!d->tabWidget)
            {
                d->tabWidget = new QTabWidget(parent);
                parent->layout()->addWidget(d->tabWidget);
            }

            QWidget* tab = new QWidget(d->tabWidget);
            // widgets are to be aligned vertically in the tab
            QVBoxLayout* tabLayout = new QVBoxLayout(tab, marginHint(),
                                                     spacingHint());
            d->tabWidget->insertTab(tab, widget_label);
            KVBox* tabContainer = new KVBox(tab);
            tabContainer->setSpacing(spacingHint());
            tabLayout->addWidget(tabContainer);
            newParent = tabContainer;

            tabLayout->addStretch();

            break;
        }

        case GP_WIDGET_TEXT:
        {
            gp_widget_get_value(widget, &widget_value_string);

            Q3Grid* grid = new Q3Grid(2, Qt::Horizontal, parent);
            parent->layout()->addWidget(grid);
            grid->setSpacing(spacingHint());
            new QLabel(QString::fromLocal8Bit(widget_label) + ':', grid);
            QLineEdit* lineEdit = new QLineEdit(widget_value_string, grid);
            d->wmap.insert(widget, lineEdit);

            if (!whats_this.isEmpty())
            {
                grid->setWhatsThis(whats_this);
            }

            break;
        }

        case GP_WIDGET_RANGE:
        {
            float widget_low;
            float widget_high;
            float widget_increment;
            gp_widget_get_range(widget, &widget_low, &widget_high, &widget_increment);
            gp_widget_get_value(widget, &widget_value_float);

            Q3GroupBox* groupBox = new Q3GroupBox(1, Qt::Horizontal, widget_label, parent);
            parent->layout()->addWidget(groupBox);
            QSlider* slider = new QSlider(
                (int)widget_low,
                (int)widget_high,
                (int)widget_increment,
                (int)widget_value_float,
                Qt::Horizontal,
                groupBox);
            d->wmap.insert(widget, slider);

            if (!whats_this.isEmpty())
            {
                groupBox->setWhatsThis(whats_this);
            }

            break;
        }

        case GP_WIDGET_TOGGLE:
        {
            gp_widget_get_value(widget, &widget_value_int);

            QCheckBox* checkBox = new QCheckBox(widget_label, parent);
            parent->layout()->addWidget(checkBox);
            checkBox->setChecked(widget_value_int);
            d->wmap.insert(widget, checkBox);

            if (!whats_this.isEmpty())
            {
                checkBox->setWhatsThis(whats_this);
            }

            break;
        }

        case GP_WIDGET_RADIO:
        {
            gp_widget_get_value(widget, &widget_value_string);

            int count = gp_widget_count_choices(widget);

            // for less than 5 options, align them horizontally
            Q3ButtonGroup* buttonGroup;

            if (count > 4)
            {
                buttonGroup = new Q3VButtonGroup(widget_label, parent);
            }
            else
            {
                buttonGroup = new Q3HButtonGroup(widget_label, parent);
            }

            parent->layout()->addWidget(buttonGroup);

            for (int i = 0; i < count; ++i)
            {
                const char* widget_choice;
                gp_widget_get_choice(widget, i, &widget_choice);

                new QRadioButton(widget_choice, buttonGroup);

                if (!strcmp(widget_value_string, widget_choice))
                {
                    buttonGroup->setButton(i);
                }
            }

            d->wmap.insert(widget, buttonGroup);

            if (!whats_this.isEmpty())
            {
                buttonGroup->setWhatsThis(whats_this);
            }

            break;
        }

        case GP_WIDGET_MENU:
        {
            gp_widget_get_value(widget, &widget_value_string);

            QComboBox* comboBox = new KComboBox(parent);
            parent->layout()->addWidget(comboBox);
            comboBox->clear();

            for (int i = 0; i < gp_widget_count_choices(widget); ++i)
            {
                const char* widget_choice;
                gp_widget_get_choice(widget, i, &widget_choice);

                comboBox->insertItem(widget_choice);

                if (!strcmp(widget_value_string, widget_choice))
                {
                    comboBox->setCurrentItem(i);
                }
            }

            d->wmap.insert(widget, comboBox);

            if (!whats_this.isEmpty())
            {
                comboBox->setWhatsThis(whats_this);
            }

            break;
        }

        case GP_WIDGET_BUTTON:
        {
            // TODO
            // I can't see a way of implementing this. Since there is
            // no way of telling which button sent you a signal, we
            // can't map to the appropriate widget->callback
            QLabel* label = new QLabel(i18n("Button (not supported by KControl)"), parent);
            parent->layout()->addWidget(label);

            break;
        }

        case GP_WIDGET_DATE:
        {
            // TODO
            QLabel* label = new QLabel(i18n("Date (not supported by KControl)"), parent);
            parent->layout()->addWidget(label);

            break;
        }

        default:
            return;
    }

    // Append all this widgets children
    for (int i = 0; i < gp_widget_count_children(widget); ++i)
    {
        CameraWidget* widget_child;
        gp_widget_get_child(widget, i, &widget_child);
        appendWidget(newParent, widget_child);
    }

    // Things that must be done after all children were added
    /*
        switch (widget_type) {
        case GP_WIDGET_SECTION:
            {
                tabLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding) );
                break;
            }
        }
    */
}
Example #22
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;
}
Example #23
0
/**
 * @brief QTLCamera::_getWidgets
 * @param widgetList
 * @param widget
 * @param prefix
 */
void QTLCamera::_getWidgets(vector<QTLWidget> *widgetList, CameraWidget *widget,
                           char *prefix) {
    int rc, n;
    char *newprefix;
    const char *label, *name, *uselabel;
    CameraWidgetType type;
    CameraWidget *rootConfig, *child;
    QTLWidget qtlWidget;

    gp_widget_get_label(widget, &label);
    gp_widget_get_name(widget, &name);
    gp_widget_get_type(widget, &type);

    if (strlen(name)) {
        uselabel = name;
    } else {
        uselabel = label;
    }

    n = gp_widget_count_children(widget);

    newprefix = new char[strlen(prefix) + 1 + strlen(uselabel) + 1];

    if (!newprefix) {
        return;
    }

    sprintf(newprefix, "%s/%s", prefix, uselabel);

    //XXX Was this supposed to be a conditional for the whole section?
    // Assuming yes due to indenting.
    qDebug() << "\tDetected widget: " << uselabel;
    if ((type != GP_WIDGET_WINDOW) && (type != GP_WIDGET_SECTION)) {
        rc = findWidgetByName(uselabel, &child, &rootConfig);
        rc = gp_widget_get_type(child, &type);
        rc = gp_widget_get_label(child, &label);

        if (type == GP_WIDGET_RADIO) {
            int count, i;
            char *current;

            rc = gp_widget_get_value(child, &current);
            if (rc == GP_OK) {
                count = gp_widget_count_choices(child);
                if (type == GP_WIDGET_MENU) {
                } else {

                    for (i=0; i<count; i++) {
                        const char *choice;
                        rc = gp_widget_get_choice(child, i, &choice);
                        qtlWidget.choices.push_back(choice);
                        qDebug() << "\t\tDetected choice: " << choice;
                    }

                    qtlWidget.title = label;
                    qtlWidget.name = name;
                    qtlWidget.defaultChoice = current;
                    qtlWidget.choiceLabel = uselabel;

                    params->widgetList->push_back(qtlWidget);
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        CameraWidget *child;
        rc = gp_widget_get_child(widget, i, &child);
        if (rc != GP_OK) {
            continue;
        }
        _getWidgets(widgetList, child, newprefix);
    }
    free(newprefix);
}
Example #24
0
/**
 * Print widget description in @param os.
 * @return real widget ID (if config was reloaded couple of times
 *         then IDs won't be the same)
 */
int DigitalCameraCapture::widgetDescription(std::ostream &os,
        CameraWidget * widget) const
{
    const char * label, *name, *info;
    int id, readonly;
    CameraWidgetType type;

    CR(gp_widget_get_id(widget, &id));
    CR(gp_widget_get_label(widget, &label));
    CR(gp_widget_get_name(widget, &name));
    CR(gp_widget_get_info(widget, &info));
    CR(gp_widget_get_type(widget, &type));
    CR(gp_widget_get_readonly(widget, &readonly));

    if ((type == GP_WIDGET_WINDOW) || (type == GP_WIDGET_SECTION)
            || (type == GP_WIDGET_BUTTON))
    {
        readonly = 1;
    }
    os << (id - noOfWidgets) << separator << label << separator << name
            << separator << info << separator << readonly << separator;

    switch (type)
    {
        case GP_WIDGET_WINDOW:
        {
            os << "window" << separator /* no value */<< separator;
            break;
        }
        case GP_WIDGET_SECTION:
        {
            os << "section" << separator /* no value */<< separator;
            break;
        }
        case GP_WIDGET_TEXT:
        {
            os << "text" << separator;
            char *txt;
            CR(gp_widget_get_value(widget, &txt));
            os << txt << separator;
            break;
        }
        case GP_WIDGET_RANGE:
        {
            os << "range" << separator;
            float f, t, b, s;
            CR(gp_widget_get_range(widget, &b, &t, &s));
            CR(gp_widget_get_value(widget, &f));
            os << "(" << b << ":" << t << ":" << s << "):" << f << separator;
            break;
        }
        case GP_WIDGET_TOGGLE:
        {
            os << "toggle" << separator;
            int t;
            CR(gp_widget_get_value(widget, &t));
            os << t << separator;
            break;
        }
        case GP_WIDGET_RADIO:
        case GP_WIDGET_MENU:
        {
            if (type == GP_WIDGET_RADIO)
            {
                os << "radio" << separator;
            }
            else
            {
                os << "menu" << separator;
            }
            int cnt = 0, i;
            char *current;
            CR(gp_widget_get_value(widget, &current));
            CR(cnt = gp_widget_count_choices(widget));
            os << "(";
            for (i = 0; i < cnt; i++)
            {
                const char *choice;
                CR(gp_widget_get_choice(widget, i, &choice));
                os << i << ":" << choice;
                if (i + 1 < cnt)
                {
                    os << ";";
                }
            }
            os << "):" << current << separator;
            break;
        }
        case GP_WIDGET_BUTTON:
        {
            os << "button" << separator /* no value */<< separator;
            break;
        }
        case GP_WIDGET_DATE:
        {
            os << "date" << separator;
            int t;
            time_t xtime;
            struct tm *xtm;
            char timebuf[200];
            CR(gp_widget_get_value(widget, &t));
            xtime = t;
            xtm = localtime(&xtime);
            strftime(timebuf, sizeof(timebuf), "%c", xtm);
            os << t << ":" << timebuf << separator;
            break;
        }
    }
    return id;
}
Example #25
0
/**
 * 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;
}
Example #26
0
/**
 * Get property.
 * @see DigitalCameraCapture for more information about returned double type.
 */
double DigitalCameraCapture::getProperty(int propertyId) const
{
    CameraWidget * widget = NULL;
    double output = 0;
    if (propertyId < 0)
    {
        widget = getWidget(-propertyId);
    }
    else
    {
        switch (propertyId)
        {
            // gphoto2 cap featured
            case CV_CAP_PROP_GPHOTO2_PREVIEW:
                return preview;
            case CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE:
                if (rootWidget == NULL)
                    return 0;
                return (intptr_t) widgetInfo.c_str();
            case CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG:
                return 0; // Trigger, only by set
            case CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE:
                return reloadOnChange;
            case CV_CAP_PROP_GPHOTO2_COLLECT_MSGS:
                return collectMsgs;
            case CV_CAP_PROP_GPHOTO2_FLUSH_MSGS:
                lastFlush = msgsBuffer.str();
                msgsBuffer.str("");
                msgsBuffer.clear();
                return (intptr_t) lastFlush.c_str();
            default:
                widget = getGenericProperty(propertyId, output);
                /* no break */
        }
    }
    if (widget == NULL)
        return output;
    try
    {
        CameraWidgetType type;
        CR(gp_widget_get_type(widget, &type));
        switch (type)
        {
            case GP_WIDGET_MENU:
            case GP_WIDGET_RADIO:
            {
                int cnt = 0, i;
                const char * current;
                CR(gp_widget_get_value(widget, &current));
                CR(cnt = gp_widget_count_choices(widget));
                for (i = 0; i < cnt; i++)
                {
                    const char *choice;
                    CR(gp_widget_get_choice(widget, i, &choice));
                    if (std::strcmp(choice, current) == 0)
                    {
                        return i;
                    }
                }
                return -1;
            }
            case GP_WIDGET_TOGGLE:
            {
                int value;
                CR(gp_widget_get_value(widget, &value));
                return value;
            }
            case GP_WIDGET_RANGE:
            {
                float value;
                CR(gp_widget_get_value(widget, &value));
                return value;
            }
            default:
            {
                char* value;
                CR(gp_widget_get_value(widget, &value));
                return (intptr_t) value;
            }
        }
    }
    catch (GPhoto2Exception & e)
    {
        char buf[128] = "";
        sprintf(buf, "cannot get property: %d", propertyId);
        message(WARNING, (const char *) buf, e);
        return 0;
    }
}