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;
}
Example #2
0
int photo_camera::photo_camera_find_widget_by_name( std::string name, CameraWidget **child, CameraWidget **root)
 {
  int error_code;

  // Get camera configuration
  error_code = gp_camera_get_config( camera_, root, context_ );
  if (error_code != GP_OK)
  {
    photo_reporter::error( "gp_camera_get_config()");
    return error_code;
  }

  // Find child of configuration by name
  if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }

  // Find child of configuration  by label
  if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }

  // If full name is not found, search for last subname.
  // name delimeter is '/'
  size_t found_index = name.length();
  while( found_index == name.length() )
  {
    found_index = name.rfind( '/' );

    if( found_index == std::string::npos ) // No subname, we already failed this search above
    {
      gp_context_error( context_,"%s not found in configuration tree.", name.c_str() );
      gp_widget_free( *root );
      return GP_ERROR;
    }

    if( found_index == name.length() - 1 ) // end of string, cut it off
    {
      name = name.substr( 0, found_index );
    }
  }
  name = name.substr( found_index, name.length() - 1 );

  // Find child using 
  if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }
  if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }

  // all matches have failed
  gp_context_error( context_, "%s not found in configuration tree.", name.c_str() );
  gp_widget_free( *root );
  return GP_ERROR;
}
int getWidget(CameraWidget ** widget, CameraWidget ** child, const char * setting) {
	CameraWidgetType type;

	int 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, setting, child);
	if (ret < GP_OK || child == NULL) {
		fprintf (stderr, "l lookup widget %s failed: %d\n", setting, ret);
		gp_widget_free (*widget);
		return ret;
	}

	/* 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, "l widget get type failed: %d\n", ret);
		gp_widget_free (*widget);
		return ret;
	}

	return GP_OK;
}
Example #4
0
/**
 * @brief CameraHandler::findWidgetByName
 * @param p
 * @param name
 * @param child
 * @param rootConfig
 * @return
 */
int QTLCamera::findWidgetByName(const char *name, CameraWidget **child,
                     CameraWidget **rootConfig) {
    int rc;
    rc = gp_camera_get_config(params->camera, rootConfig, params->context);
    if (rc != GP_OK) {
        return rc;
    }

    rc = gp_widget_get_child_by_name(*rootConfig, name, child);
    if (rc != GP_OK) {
        rc = gp_widget_get_child_by_label(*rootConfig, name, child);
    }
    if (rc != GP_OK) {
        char *part, *s, *newname;

        newname = strdup(name);
        if (!newname) {
            return GP_ERROR_NO_MEMORY;
        }

        *child = *rootConfig;
        part = newname;
        while (part[0] == '/') {
            part++;
        }
        while (1) {
            CameraWidget *tmp;

            s = strchr(part,'/');
            if (s) {
                *s = '\0';
            }
            rc = gp_widget_get_child_by_name(*child, part, &tmp);
            if (rc != GP_OK) {
                rc = gp_widget_get_child_by_label(*child, part, &tmp);
            }
            if (rc != GP_OK) {
                break;
            }
            *child = tmp;
            if (!s) {
                // end of path
                break;
            }
            part = s + 1;
            while (part[0] == '/') {
                part++;
            }
        }
        if (s) {
            // If we have stuff left over, we failed.
            qDebug() << newname << "not found in configuration tree.";
            free(newname);
            gp_widget_free(*rootConfig);
            return GP_ERROR;
        }
        free (newname);
    }
    return GP_OK;
}
Example #5
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;
}
Example #6
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;
}
Example #7
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;
}
Example #8
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 #9
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 #10
0
/**
 * @brief QTLCamera::initCamera
 * @return
 */
QTLError QTLCamera::initCamera() {
    QTLError result;
    result.rc = GP_OK;
    result.errorText = "Camera initialized.";

    // Set aside memory for camera
    result.rc = gp_camera_new(&params->camera);
    if (result.rc != GP_OK) {
        result.errorText = gp_result_as_string(result.rc);
        return result;
    }

    // Initialise camera
    qDebug() << "Detecting Camera.";
    result.rc = gp_camera_init(params->camera, params->context);

    if (result.rc != GP_OK) {
        result.errorText = gp_result_as_string(result.rc);

        if (result.rc == -105) {
            result.errorText = "Failed to initialise camera. Please check the camera " \
                    "is turned on, then re-initialise or restart the program to enable" \
                    " camera paramaters.";
        } else if (result.rc == -60 || result.rc == -53) {
            result.errorText = "Failed to initialise camera. Please check the camera " \
                    "is unmounted and that no other applications are using it, then " \
                    "re-initialise or restart the program to enable camera paramaters.";
        }
    } else {
        qDebug() << "Camera detected";
        qDebug() << "Detecting widgets" << endl;
        CameraWidget *rootConfig;
        result.rc = gp_camera_get_config(params->camera, &rootConfig, params->context);
        if (result.rc == GP_OK) {
            char prefix[] = "";
            _getWidgets(params->widgetList, rootConfig, prefix);
            gp_widget_free(rootConfig);
        }
        qDebug() << "Widgets detected";
    }

    return result;
}
Example #11
0
int
gp_camera_list_config (Camera *camera, CameraList *list, GPContext *context)
{
	CameraWidget		*rootwidget;
	int			ret;
	C_PARAMS (camera);
	CHECK_INIT (camera, context);

	if (camera->functions->list_config) {
		CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->list_config (
						camera, list, 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;
	}

	_get_widget_names (rootwidget, list);


	gp_widget_free (rootwidget);
	CHECK_CLOSE (camera, context);
	CAMERA_UNUSED (camera, context);
	return ret;
}
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);
}
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 #14
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 #15
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 #16
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 photoController::setPhotoQuality()
{
	bool result = true;
	int ret;
	CameraWidget *rootconfig;
	CameraWidget *child;

	DEBUG_PRINTF(V_MESSAGE, "Checking camera detection.\n");
	if(!camera_detected) 
	{
		DEBUG_PRINTF(V_MESSAGE, "Camera not detected.\n");
		return false;
	}

	DEBUG_PRINTF(V_MESSAGE, "Getting camera config.\n");
	ret = gp_camera_get_config(camera, &rootconfig, context);
	if (ret != GP_OK)
	{
		DEBUG_PRINTF(V_MESSAGE, "Getting camera config error.\n");
		result = false;
	}

	DEBUG_PRINTF(V_MESSAGE, "Getting imageformat config.\n");
	ret = gp_widget_get_child_by_name(rootconfig, "imageformat", &child);
	if (ret != GP_OK)
	{
		DEBUG_PRINTF(V_MESSAGE, "Getting imageformat config error.\n");
		result = false;
	}

	// Choice: 0 Large Fine JPEG
	// Choice: 1 Large Normal JPEG
	// Choice: 2 Medium Fine JPEG
	// Choice: 3 Medium Normal JPEG
	// Choice: 4 Small Fine JPEG
	// Choice: 5 Small Normal JPEG
	// Choice: 6 Smaller JPEG
	// Choice: 7 Tiny JPEG
	// Choice: 8 RAW + Large Fine JPEG
	// Choice: 9 RAW

	DEBUG_PRINTF(V_MESSAGE, "Setting image format config.\n");
	const char*  smallerJPEG = NULL;
	ret = gp_widget_get_choice (child, 6, &smallerJPEG); //6 = Smaller JPEG
	if (ret != GP_OK)
	{
		DEBUG_PRINTF(V_MESSAGE, "Getting image format choice error %d.\n", ret);
		result = false;
	}
	ret = gp_widget_set_value(child, smallerJPEG);
	if (ret != GP_OK)
	{
		DEBUG_PRINTF(V_MESSAGE, "Setting image format config error %d.\n", ret);
		result = false;
	}

	DEBUG_PRINTF(V_MESSAGE, "Setting camera config.\n");
	ret = gp_camera_set_config(camera, rootconfig, context);
	if (ret != GP_OK)
	{
		DEBUG_PRINTF(V_MESSAGE, "Setting camera config error %d.\n", ret);
		result = false;
	}
	DEBUG_PRINTF(V_MESSAGE, "Freeing camera config object.\n");
	gp_widget_free(rootconfig);
	return result;
}
Example #18
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 #19
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 #20
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;
}