static int show_section (CmdConfig *cmd_config, CameraWidget *section) { CameraWidget *child, *parent; CameraWidgetType type; CDKSCROLL *scroll = NULL; const char *label; char *items[100]; int count, x, selection; char title[1024]; int show_parent = 0, show_child = 0; /* Create the scroll list */ gp_widget_get_type (section, &type); gp_widget_get_label (section, &label); snprintf (title, sizeof (title), "<C></5>%s", label); if (type == GP_WIDGET_WINDOW) items[0] = copyChar (_("Exit")); else items[0] = copyChar (_("Back")); count = gp_widget_count_children (section); for (x = 0; x < count; x++) { gp_widget_get_child (section, x, &child); gp_widget_get_label (child, &label); items[x + 1] = copyChar ((char *) label); } count++; scroll = newCDKScroll (cmd_config->screen, CENTER, CENTER, RIGHT, 10, 50, title, items, count, NUMBERS, A_REVERSE, TRUE, FALSE); if (!scroll) return (GP_ERROR); selection = activateCDKScroll (scroll, 0); if (scroll->exitType == vNORMAL) { if (selection) show_child = selection; else if (type != GP_WIDGET_WINDOW) show_parent = 1; } /* Clean up */ destroyCDKScroll (scroll); if (show_parent) { gp_widget_get_parent (section, &parent); show_widget (cmd_config, parent); } else if (show_child) { gp_widget_get_child (section, show_child - 1, &child); show_widget (cmd_config, child); } return (GP_OK); }
static int show_range_int (CmdConfig *cmd_config, CameraWidget *range) { CDKSLIDER *slider = NULL; float value, min, max, increment; const char *label; char title[1024]; int selection; CHECK (gp_widget_get_value (range, &value)); CHECK (gp_widget_get_label (range, &label)); snprintf (title, sizeof (title), "<C></5>%s", label); CHECK (gp_widget_get_range (range, &min, &max, &increment)); slider = newCDKSlider (cmd_config->screen, CENTER, CENTER, title, _("Value: "), '-', 50, (int) value, min, max, increment, MAX (increment, (max - min)/20.0), TRUE, FALSE); if (!slider) return (GP_ERROR); selection = activateCDKSlider (slider, 0); if (slider->exitType == vNORMAL) { value = selection; gp_widget_set_value (range, &value); set_config (cmd_config); } destroyCDKSlider (slider); return (GP_OK); }
static int show_text (CmdConfig *cmd_config, CameraWidget *text) { CDKENTRY *entry = NULL; const char *label, *value; char title[1024], *info; CHECK (gp_widget_get_value (text, &value)); CHECK (gp_widget_get_label (text, &label)); snprintf (title, sizeof (title), "<C></5>%s", label); entry = newCDKEntry (cmd_config->screen, CENTER, CENTER, title, _("Value: "), A_NORMAL, ' ', vMIXED, 40, 0, 256, TRUE, FALSE); if (!entry) return (GP_ERROR); setCDKEntryValue (entry, (char*) value); info = activateCDKEntry (entry, 0); if (entry->exitType == vNORMAL) { gp_widget_set_value (text, info); set_config (cmd_config); } destroyCDKEntry (entry); return (GP_OK); }
static int show_toggle (CmdConfig *cmd_config, CameraWidget *toggle) { CDKITEMLIST *list = NULL; int value, selection; const char *label; char title[1024], *info[] = {N_("Yes"), N_("No")}; CHECK (gp_widget_get_value (toggle, &value)); CHECK (gp_widget_get_label (toggle, &label)); snprintf (title, sizeof (title), "<C></5>%s", label); list = newCDKItemlist (cmd_config->screen, CENTER, CENTER, title, "", info, 2, 1 - value, TRUE, FALSE); if (!list) return (GP_ERROR); selection = activateCDKItemlist (list, 0); if (list->exitType == vNORMAL) { selection = 1 - selection; gp_widget_set_value (toggle, &selection); set_config (cmd_config); } destroyCDKItemlist (list); return (GP_OK); }
static int show_date (CmdConfig *cmd_config, CameraWidget *date) { CDKCALENDAR *calendar = NULL; int day, month, year, selection; time_t time; struct tm *date_info; const char *label; char title[1024]; gp_widget_get_value (date, &time); date_info = localtime (&time); /* Month in CDK starts with 1 */ day = date_info->tm_mday; month = date_info->tm_mon + 1; year = date_info->tm_year + 1900; gp_widget_get_label (date, &label); snprintf (title, sizeof (title), "<C></5>%s", label); /* Create the calendar */ calendar = newCDKCalendar (cmd_config->screen, CENTER, CENTER, title, day, month, year, COLOR_PAIR(16)|A_BOLD, COLOR_PAIR(24)|A_BOLD, COLOR_PAIR(32)|A_BOLD, COLOR_PAIR(40)|A_REVERSE, TRUE, FALSE); if (!calendar) return (GP_ERROR); drawCDKCalendar (calendar, TRUE); selection = activateCDKCalendar (calendar, 0); if (calendar->exitType == vNORMAL) { date_info = localtime (&time); /* Month in CDK starts with 1 */ date_info->tm_mday = calendar->day; date_info->tm_mon = calendar->month - 1; date_info->tm_year = calendar->year - 1900; time = mktime (date_info); gp_widget_set_value (date, &time); set_config (cmd_config); } destroyCDKCalendar (calendar); return (GP_OK); }
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, ¤t_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); }
void get_all_widgets(Camera *camera,GPContext *context,CameraWidget *widget, char *prefix,widgets_list_node *first) { int ret, n, i; char *newprefix; const char *label, *name, *uselabel; CameraWidgetType type; gp_widget_get_label (widget, &label); /* fprintf(stderr,"label is %s\n", label); */ ret = gp_widget_get_name (widget, &name); /* fprintf(stderr,"name is %s\n", name); */ gp_widget_get_type (widget, &type); if (strlen(name)) uselabel = name; else uselabel = label; n = gp_widget_count_children (widget); newprefix = malloc(strlen(prefix)+1+strlen(uselabel)+1); if (!newprefix) { abort(); } sprintf(newprefix,"%s/%s",prefix,uselabel); if ((type != GP_WIDGET_WINDOW) && (type != GP_WIDGET_SECTION)) { // int readonly; // gp_widget_get_readonly(widget,&readonly); // printf("name: %s readonly: %i \n",name,readonly); add_widget(&first,widget); } for (i=0; i<n; i++) { CameraWidget *child; ret = gp_widget_get_child (widget, i, &child); if (ret != GP_OK) continue; get_all_widgets(camera,context,child,newprefix,first); } free(newprefix); }
static int show_range_float (CmdConfig *cmd_config, CameraWidget *range) { #ifdef HAVE_CDK_20010421 return (show_range_int (cmd_config, range)); #else CDKFSCALE *fscale = NULL; float value, min, max, increment; const char *label; char title[1024]; float selection; CHECK (gp_widget_get_value (range, &value)); CHECK (gp_widget_get_label (range, &label)); snprintf (title, sizeof (title), "<C></5>%s", label); CHECK (gp_widget_get_range (range, &min, &max, &increment)); fscale = newCDKFScale (cmd_config->screen, CENTER, CENTER, title, _("Value: "), A_STANDOUT, 50, value, min, max, increment, MAX (increment, (max - min) / 20.0), get_digits (increment), TRUE, FALSE); if (!fscale) return (GP_ERROR); selection = activateCDKFScale (fscale, 0); if (fscale->exitType == vNORMAL) { value = selection; gp_widget_set_value (range, &value); set_config (cmd_config); } destroyCDKFScale (fscale); return (GP_OK); #endif }
static int show_time (CmdConfig *cmd_config, CameraWidget *date) { CDKENTRY *entry = NULL; const char *label, *info; char title[1024], time_string[9]; time_t time; struct tm *date_info; gp_widget_get_label (date, &label); snprintf (title, sizeof (title), "<C></5>%s", label); entry = newCDKEntry (cmd_config->screen, CENTER, CENTER, title, _("Time: "), A_NORMAL, ' ', vMIXED, 40, 0, 8, TRUE, FALSE); if (!entry) return (GP_ERROR); gp_widget_get_value (date, &time); date_info = localtime (&time); snprintf (time_string, sizeof (time_string), "%2i:%02i:%02i", date_info->tm_hour, date_info->tm_min, date_info->tm_sec); setCDKEntryValue (entry, time_string); setCDKEntryPreProcess (entry, time_preprocess, NULL); info = activateCDKEntry (entry, 0); if (entry->exitType == vNORMAL) { date_info = localtime (&time); sscanf (info, "%d:%d:%d", &date_info->tm_hour, &date_info->tm_min, &date_info->tm_sec); time = mktime (date_info); gp_widget_set_value (date, &time); set_config (cmd_config); } destroyCDKEntry (entry); return (GP_OK); }
bool 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, ¤t) != 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; }
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; }
/** * @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; }
/** * @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, ¤t); 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); }
/** * 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, ¤t)); 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; }
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; } } */ }
/** * 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; }