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; }
/** * @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; }
/* * This function looks up a label or key entry of * a configuration widget. * The functions descend recursively, so you can just * specify the last component. */ int _lookup_widget(CameraWidget*widget, const char *key, CameraWidget **child) { int ret = gp_widget_get_child_by_name (widget, key, child); if (ret < GP_OK) { ret = gp_widget_get_child_by_label (widget, key, child); } return ret; }
CameraWidget* Widget::get_gp_child(const char *name_or_label) const { CameraWidget* child; int ret = gp_widget_get_child_by_name(widget, name_or_label, &child); if (ret < GP_OK) ret = gp_widget_get_child_by_label(widget, name_or_label, &child); if (ret < GP_OK) throw std::out_of_range("no widget found"); return child; }
static int camera_set_config (Camera *c, CameraWidget *window, GPContext *co) { CameraWidget *w; const char *v_char; time_t time; RicohMode mode; /* We need to be in record mode to set settings. */ CR (ricoh_get_mode (c, co, &mode)); if (mode != RICOH_MODE_RECORD) CR (ricoh_set_mode (c, co, RICOH_MODE_RECORD)); /* Copyright */ CR (gp_widget_get_child_by_name (window, "copyright", &w)); if (gp_widget_changed (w)) { CR (gp_widget_get_value (w, &v_char)); CR (ricoh_set_copyright (c, co, v_char)); } /* Date */ CR (gp_widget_get_child_by_name (window, "date", &w)); if (gp_widget_changed (w)) { CR (gp_widget_get_value (w, &time)); CR (ricoh_set_date (c, co, time)); } R_CHECK_RADIO (c, co, window, resolution, N_("Resolution")) R_CHECK_RADIO (c, co, window, exposure, N_("Exposure")) R_CHECK_RADIO (c, co, window, white_level, N_("White level")) R_CHECK_RADIO (c, co, window, macro, N_("Macro")) R_CHECK_RADIO (c, co, window, zoom, N_("Zoom")) R_CHECK_RADIO (c, co, window, flash, N_("Flash")) R_CHECK_RADIO (c, co, window, rec_mode, N_("Record Mode")) R_CHECK_RADIO (c, co, window, compression, N_("Compression")) return (GP_OK); }
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(); }
int camera_set(char* name, void* value) { int res; CameraWidget* config_root; CameraWidget* widget; res = gp_camera_get_config(camera, &config_root, context); CAMERA_CHECK_GP(res, "gp_camera_get_config"); res = gp_widget_get_child_by_name(config_root, name, &widget); CAMERA_CHECK_GP(res, "gp_widget_get_child_by_name"); res = gp_widget_set_value(widget, value); CAMERA_CHECK_GP(res, "gp_widget_set_value"); res = gp_camera_set_config(camera, config_root, context); CAMERA_CHECK_GP(res, "gp_camera_set_config"); gp_widget_unref(config_root); return 1; }
const char*dt_camctl_camera_get_property(const dt_camctl_t *c,const dt_camera_t *cam,const char *property_name) { 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 property from camera, camera==NULL\n"); return NULL; } dt_camera_t *camera=(dt_camera_t *)cam; dt_pthread_mutex_lock( &camera->config_lock ); const char *value=NULL; CameraWidget *widget; if( gp_widget_get_child_by_name ( camera->configuration, property_name, &widget) == GP_OK) { gp_widget_get_value ( widget , &value); } dt_pthread_mutex_unlock( &camera->config_lock); return value; }
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; } }
int dt_camctl_camera_property_exists(const dt_camctl_t *c,const dt_camera_t *cam,const char *property_name) { int exists=0; 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 check if property exists in camera configuration, camera==NULL\n"); return 0; } dt_camera_t *camera=(dt_camera_t *)cam; dt_pthread_mutex_lock( &camera->config_lock ); CameraWidget *widget; if( gp_widget_get_child_by_name ( camera->configuration, property_name, &widget) == GP_OK) exists=1; dt_pthread_mutex_unlock( &camera->config_lock); return exists; }
void dt_camctl_camera_stop_live_view(const dt_camctl_t *c) { dt_camctl_t *camctl = (dt_camctl_t*)c; dt_camera_t *cam = (dt_camera_t*)camctl->active_camera; dt_print(DT_DEBUG_CAMCTL,"[camera_control] Stopping live view\n"); cam->is_live_viewing = FALSE; pthread_join(cam->live_view_thread, NULL); //tell camera to get back to normal state (close mirror) // this should work like this: // dt_camctl_camera_set_property(darktable.camctl, NULL, "eosviewfinder", "0"); // but it doesn't, passing a string isn't ok in this case. I guess that's a TODO. // for the time being I'll do it manually (not nice, I know). CameraWidget *config; CameraWidget *widget; gp_camera_get_config( cam->gpcam, &config, camctl->gpcontext ); if( gp_widget_get_child_by_name ( config, "eosviewfinder", &widget) == GP_OK) { int zero=0; gp_widget_set_value ( widget , &zero); gp_camera_set_config( cam->gpcam, config, camctl->gpcontext ); } }
bool Image_GPhoto::doGetProperty(const string& name, string& value) { lock_guard<recursive_mutex> lock(_gpMutex); if (_selectedCameraIndex == -1) { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - A camera must be selected before trying to capture" << Log::endl; return false; } GPhotoCamera* camera = &(_cameras[_selectedCameraIndex]); CameraWidget* widget; if (gp_widget_get_child_by_name(camera->configuration, name.c_str(), &widget) == GP_OK) { const char* cvalue = nullptr; gp_widget_get_value(widget, &cvalue); value = string(cvalue); return true; } return false; }
const char *dt_camctl_camera_property_get_first_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 first 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( gp_widget_get_child_by_name ( camera->configuration, property_name, &camera->current_choice.widget) == GP_OK ) { camera->current_choice.index=0; gp_widget_get_choice ( camera->current_choice.widget, camera->current_choice.index , &value); } else dt_print(DT_DEBUG_CAMCTL,"[camera_control] property name '%s' not found in camera configuration.\n",property_name); dt_pthread_mutex_unlock( &camera->config_lock); return value; }
bool Image_GPhoto::doSetProperty(const string& name, const string& value) { lock_guard<recursive_mutex> lock(_gpMutex); if (_selectedCameraIndex == -1) { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - A camera must be selected before trying to capture" << Log::endl; return false; } GPhotoCamera* camera = &(_cameras[_selectedCameraIndex]); CameraWidget* widget; if (gp_widget_get_child_by_name(camera->configuration, name.c_str(), &widget) == GP_OK) { if (gp_widget_set_value(widget, value.c_str()) != GP_OK) { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Unable to set parameter " << name << " to value " << value << Log::endl; return false; } if (gp_camera_set_config(camera->cam, camera->configuration, _gpContext) != GP_OK) { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Setting parameter " << name << " is not supported for this camera" << Log::endl; return false; } return true; } else { Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Parameter " << name << " does not seem to be available" << Log::endl; } return false; }
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); }
static int camera_config_set (Camera *camera, CameraWidget *window, GPContext *context) { int ret; CameraWidget *turbo; ret = gp_widget_get_child_by_name (window, "turbo", &turbo); if (ret != GP_OK) { gp_log (GP_LOG_ERROR, "camera_config_set", "did not find turbo menu entry?\n"); return GP_OK; } if (gp_widget_changed (turbo)) { const char* val; int ival; ret = gp_widget_get_value (turbo, &val); if (ret == GP_OK) { ival = !strcmp (val, _("On")); gp_log (GP_LOG_DEBUG, "camera_config_set", "val %s, ival %d\n", val, ival); gp_setting_set ("topfield", "turbo", ival?"yes":"no"); } } return GP_OK; }
/** * 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; }
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; }
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; }
int _lookup_widget(CameraWidget*widget, const char *key, CameraWidget **child) { int ret; ret = gp_widget_get_child_by_name (widget, key, child); return ret; }
/** * 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; }
static void _camera_process_job(const dt_camctl_t *c,const dt_camera_t *camera, gpointer job) { dt_camera_t *cam=(dt_camera_t *)camera; _camctl_camera_job_t *j = (_camctl_camera_job_t *)job; switch( j->type ) { case _JOB_TYPE_EXECUTE_CAPTURE: { dt_print (DT_DEBUG_CAMCTL,"[camera_control] executing remote camera capture job\n"); CameraFilePath fp; int res=GP_OK; if( (res = gp_camera_capture (camera->gpcam, GP_CAPTURE_IMAGE,&fp, c->gpcontext)) == GP_OK ) { CameraFile *destination; const char *output_path = _dispatch_request_image_path(c,camera); if( !output_path ) output_path="/tmp"; const char *fname = _dispatch_request_image_filename(c,fp.name,cam); if( !fname ) fname=fp.name; char *output = g_build_filename (output_path,fname,(char *)NULL); int handle = open (output, O_CREAT | O_WRONLY,0666); gp_file_new_from_fd (&destination , handle); gp_camera_file_get (camera->gpcam, fp.folder , fp.name, GP_FILE_TYPE_NORMAL, destination, c->gpcontext); close (handle); // Notify listerners of captured image _dispatch_camera_image_downloaded (c,camera,output); g_free (output); } else dt_print (DT_DEBUG_CAMCTL,"[camera_control] capture job failed to capture image: %s\n",gp_result_as_string(res)); } break; case _JOB_TYPE_EXECUTE_LIVE_VIEW: { CameraFile *fp = NULL; int res = GP_OK; const gchar* data = NULL; unsigned long int data_size = 0; gp_file_new(&fp); if( (res = gp_camera_capture_preview (cam->gpcam, fp, c->gpcontext)) != GP_OK ) { dt_print (DT_DEBUG_CAMCTL,"[camera_control] live view failed to capture preview: %s\n", gp_result_as_string(res)); } else if( (res = gp_file_get_data_and_size(fp, &data, &data_size)) != GP_OK ) { dt_print (DT_DEBUG_CAMCTL,"[camera_control] live view failed to get preview data: %s\n", gp_result_as_string(res)); } else { // everything worked GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); if(gdk_pixbuf_loader_write(loader, (guchar*)data, data_size, NULL) == TRUE) { dt_pthread_mutex_lock(&cam->live_view_pixbuf_mutex); if(cam->live_view_pixbuf != NULL) g_object_unref(cam->live_view_pixbuf); cam->live_view_pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); dt_pthread_mutex_unlock(&cam->live_view_pixbuf_mutex); } gdk_pixbuf_loader_close(loader, NULL); } if(fp) gp_file_free(fp); dt_pthread_mutex_unlock(&cam->live_view_synch); dt_control_queue_redraw_center(); } break; case _JOB_TYPE_SET_PROPERTY: { _camctl_camera_set_property_job_t *spj=(_camctl_camera_set_property_job_t *)job; dt_print(DT_DEBUG_CAMCTL,"[camera_control] executing set camera config job %s=%s\n",spj->name,spj->value); CameraWidget *config; // Copy of camera configuration CameraWidget *widget; gp_camera_get_config( cam->gpcam, &config, c->gpcontext ); if( gp_widget_get_child_by_name ( config, spj->name, &widget) == GP_OK) { gp_widget_set_value ( widget , spj->value); gp_camera_set_config( cam->gpcam, config, c->gpcontext ); } /* dt_pthread_mutex_lock( &cam->config_lock ); CameraWidget *widget; if( gp_widget_get_child_by_name ( camera->configuration, spj->name, &widget) == GP_OK) { gp_widget_set_value ( widget , spj->value); //gp_widget_set_changed( widget, 1 ); cam->config_changed=TRUE; } dt_pthread_mutex_unlock( &cam->config_lock);*/ } break; default: dt_print(DT_DEBUG_CAMCTL,"[camera_control] process of unknown job type %lx\n",(unsigned long int)j->type); break; } g_free(j); }
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); } } }