Exemplo n.º 1
0
const char *dt_camctl_camera_property_get_next_choice(const dt_camctl_t *c,const dt_camera_t *cam,const char *property_name)
{
  const char *value=NULL;
  dt_camctl_t *camctl=(dt_camctl_t *)c;
  if( !cam && ( (cam = camctl->active_camera) == NULL && (cam = camctl->wanted_camera) == NULL ) )
  {
    dt_print(DT_DEBUG_CAMCTL,"[camera_control] Failed to get next choice of property from camera, camera==NULL\n");
    return NULL;
  }
  dt_camera_t *camera=(dt_camera_t *)cam;
  dt_pthread_mutex_lock( &camera->config_lock);
  if( camera->current_choice.widget != NULL )
  {

    if( ++camera->current_choice.index < gp_widget_count_choices( camera->current_choice.widget ) )
    {
      // get the choice value...
      gp_widget_get_choice ( camera->current_choice.widget, camera->current_choice.index , &value);
    }
    else
    {
      // No more choices, reset current_choices for further use
      camera->current_choice.index=0;
      camera->current_choice.widget=NULL;
    }

  }

  dt_pthread_mutex_unlock( &camera->config_lock);
  return value;
}
Exemplo n.º 2
0
static int
show_radio (CmdConfig *cmd_config, CameraWidget *radio)
{
	CDKITEMLIST *list = NULL;
	const char *label, *value, *current_value;
	char title[1024], *items[100];
	int x, count, current = 0, selection, found;

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

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

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

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

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

	destroyCDKItemlist (list);
	return (GP_OK);
}
Exemplo n.º 3
0
void Image_GPhoto::initCameraProperty(GPhotoCamera& camera, const string& property, vector<string>& values)
{
    values.clear();
    CameraWidget* widget;
    if (gp_widget_get_child_by_name(camera.configuration, property.c_str(), &widget) == GP_OK)
    {
        const char* value = nullptr;
        int propCount = gp_widget_count_choices(widget);
        for (int i = 0; i < propCount; ++i)
        {
            gp_widget_get_choice(widget, i, &value);
            values.push_back({value});
        }
    }
    else
    {
        Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Property " << property << " is not available for camera " << camera.model << Log::endl;
    }
}
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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
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;
    }
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
            }
        }
    */
}
Exemplo n.º 13
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;
}