80 const std::string& port_name )
89 if( gp_camera_new( &
camera_ ) != GP_OK )
133 const char *name = NULL;
134 const char *value = NULL;
150 std::cout <<
"Opening camera " << n <<
" by name (" << name <<
") and value (" << value <<
")" << std::endl;
184 if (error_code != GP_OK)
191 if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK )
197 if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK )
204 size_t found_index = name.length();
205 while( found_index == name.length() )
207 found_index = name.rfind(
'/' );
209 if( found_index == std::string::npos )
211 gp_context_error(
context_,
"%s not found in configuration tree.", name.c_str() );
212 gp_widget_free( *root );
216 if( found_index == name.length() - 1 )
218 name = name.substr( 0, found_index );
221 name = name.substr( found_index, name.length() - 1 );
224 if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK )
228 if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK )
234 gp_context_error(
context_,
"%s not found in configuration tree.", name.c_str() );
235 gp_widget_free( *root );
246 std::string toggle_positive[] = {
"on",
"yes",
"true",
"ON",
"YES",
"TRUE"};
247 std::string toggle_negative[] = {
"off",
"no",
"false",
"OFF",
"NO",
"FALSE" };
251 if( value_in.compare(
"0" ) == 0 )
256 if( value_in.compare(
"0" ) == 0 )
263 for(
int i = 0; i < 6; i++ )
265 if( value_in.compare( toggle_positive[i] ) == 0 )
273 for(
int i = 0; i < 6; i++ )
275 if( value_in.compare( toggle_negative[i] ) == 0 )
288 CameraWidget *root, *child;
291 CameraWidgetType type;
301 if( gp_widget_get_label(child, &label) != GP_OK )
304 gp_widget_free( root );
309 if( gp_widget_get_type( child, &type ) != GP_OK )
312 gp_widget_free( root );
320 if( gp_widget_set_value(child, value.c_str()) != GP_OK )
323 gp_context_error(
context_,
"Failed to set the value of text widget %s to %s.", param.c_str(), value.c_str() );
324 gp_widget_free( root );
329 case GP_WIDGET_RANGE:
332 if( gp_widget_get_range( child, &b, &t, &s) != GP_OK )
335 gp_widget_free( root );
338 if( !sscanf( value.c_str(),
"%f", &f ) )
340 gp_context_error(
context_,
"The passed value %s is not a floating point value.", value.c_str() );
341 gp_widget_free( root );
344 if( (f < b) || (f > t) )
346 gp_context_error(
context_ ,
"The passed value %f is not within the expected range of %f -- %f.", f, b, t );
347 gp_widget_free( root );
350 if( gp_widget_set_value( child, &f ) != GP_OK )
353 gp_context_error(
context_,
"Failed to set the value of range widget %s to %f.", param.c_str(), f );
354 gp_widget_free( root );
359 case GP_WIDGET_TOGGLE:
363 gp_context_error(
context_,
"The passed value %s is not a valid toggle value.", value.c_str() );
364 gp_widget_free( root );
367 if( gp_widget_set_value( child, &tog ) != GP_OK )
370 gp_context_error(
context_,
"Failed to set values %s of toggle widget %s.", value.c_str(), param.c_str() );
371 gp_widget_free( root );
382 if( strptime( value.c_str(),
"%c", &xtm ) || strptime( value.c_str(),
"%Ec", &xtm ) )
384 time = mktime( &xtm );
389 if( !sscanf( value.c_str(),
"%d", &time ) )
391 gp_context_error(
context_,
"The passed value %s is neither a valid time nor an integer.", value.c_str() );
392 gp_widget_free( root );
396 if( gp_widget_set_value(child, &time) != GP_OK )
399 gp_context_error(
context_,
"Failed to set new time of date/time widget %s to %s.", param.c_str(), value.c_str() );
400 gp_widget_free( root );
407 case GP_WIDGET_RADIO:
409 count = gp_widget_count_choices( child );
413 gp_widget_free( root );
417 error_code = GP_ERROR_BAD_PARAMETERS;
418 for( i = 0; i < count; i++ )
421 if( gp_widget_get_choice( child, i, &choice ) == GP_OK )
423 if( value.compare( choice ) == 0 )
425 if( gp_widget_set_value( child, value.c_str() ) == GP_OK )
433 if( sscanf( value.c_str(),
"%d", &i ) )
435 if( (i >= 0) && (i < count) )
438 if( gp_widget_get_choice( child, i, &choice ) == GP_OK )
440 if( gp_widget_set_value( child, choice ) == GP_OK )
447 gp_context_error(
context_,
"Choice %s not found within list of choices.", value.c_str() );
448 gp_widget_free( root );
451 case GP_WIDGET_WINDOW:
452 case GP_WIDGET_SECTION:
453 case GP_WIDGET_BUTTON:
455 gp_context_error(
context_,
"The %s widget is not configurable.", param.c_str() );
456 gp_widget_free( root );
465 gp_context_error(
context_,
"Failed to set new configuration value %s for configuration entry %s.", value.c_str(), param.c_str() );
466 gp_widget_free( root );
470 gp_widget_free( root );
478 CameraWidget *root, *child;
480 CameraWidgetType type;
490 if( gp_widget_get_label(child, &label) != GP_OK )
493 gp_widget_free( root );
498 if( gp_widget_get_type( child, &type ) != GP_OK )
501 gp_widget_free( root );
509 if( gp_widget_get_value( child, &txt ) != GP_OK )
511 gp_context_error(
context_,
"Failed to retrieve value of text widget %s.", param.c_str() );
513 sprintf(*value,
"%s", txt);
516 case GP_WIDGET_RANGE:
518 if( gp_widget_get_range( child, &b, &t, &s ) != GP_OK )
520 gp_context_error(
context_,
"Failed to retrieve values of range widget %s.", param.c_str() );
522 if( gp_widget_get_value( child, &f ) != GP_OK )
524 gp_context_error(
context_,
"Failed to value of range widget %s.", param.c_str() );
526 sprintf( *value,
"%f", f );
529 case GP_WIDGET_TOGGLE:
532 if( gp_widget_get_value( child, &t ) != GP_OK )
534 gp_context_error(
context_,
"Failed to retrieve values of toggle widget %s.", param.c_str() );
536 sprintf( *value,
"%d", t );
547 if( gp_widget_get_value( child, &t ) != GP_OK )
549 gp_context_error(
context_,
"Failed to retrieve values of date/time widget %s.", param.c_str() );
553 localtm = localtime( &working_time );
554 error_code = strftime( timebuf,
sizeof(timebuf),
"%c", localtm );
555 sprintf( *value,
"%s", timebuf );
560 case GP_WIDGET_RADIO:
562 if( gp_widget_get_value (child, ¤t) != GP_OK )
564 gp_context_error(
context_,
"Failed to retrieve values of radio widget %s.", param.c_str() );
566 sprintf( *value,
"%s", current );
570 case GP_WIDGET_WINDOW:
571 case GP_WIDGET_SECTION:
572 case GP_WIDGET_BUTTON:
577 gp_widget_free( root );
585 CameraFile *photo_file;
586 CameraFilePath photo_file_path;
589 strcpy( photo_file_path.folder,
"/");
590 strcpy( photo_file_path.name,
"foo.jpg");
592 error_code = gp_camera_capture(
camera_, GP_CAPTURE_IMAGE, &photo_file_path,
context_ );
593 if( error_code < GP_OK )
596 gp_context_error(
context_,
"Could not capture image (error code %d)\n", error_code );
600 fd = open( filename.c_str(), O_CREAT|O_WRONLY, 0644 );
601 error_code = gp_file_new_from_fd( &photo_file, fd );
602 if( error_code < GP_OK )
605 gp_context_error(
context_,
"Could not create a new image file from %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
606 gp_file_free( photo_file );
610 error_code = gp_camera_file_get(
camera_, photo_file_path.folder, photo_file_path.name, GP_FILE_TYPE_NORMAL, photo_file,
context_ );
611 if( error_code < GP_OK )
614 gp_context_error(
context_,
"Could not get file %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
615 gp_file_free( photo_file );
619 error_code = gp_camera_file_delete(
camera_, photo_file_path.folder, photo_file_path.name,
context_ );
620 if( error_code < GP_OK )
623 gp_context_error(
context_,
"Could delete file %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
624 gp_file_free( photo_file );
628 gp_file_free( photo_file );
636 CameraFile *photo_file;
637 CameraFilePath photo_file_path;
638 char temp_file_name[20];
641 strcpy( photo_file_path.folder,
"/" );
642 strcpy( photo_file_path.name,
"foo.jpg" );
644 error_code = gp_camera_capture(
camera_, GP_CAPTURE_IMAGE, &photo_file_path,
context_ );
645 if( error_code < GP_OK )
648 gp_context_error(
context_,
"Could not capture image (error code %d)\n", error_code );
653 strcpy( temp_file_name,
"tmpfileXXXXXX" );
654 fd = mkstemp( temp_file_name );
655 error_code = gp_file_new_from_fd( &photo_file, fd );
656 if( error_code < GP_OK )
659 unlink( temp_file_name );
662 gp_context_error(
context_,
"Could not create a new image file from %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
663 gp_file_free( photo_file );
668 error_code = gp_camera_file_get(
camera_, photo_file_path.folder, photo_file_path.name, GP_FILE_TYPE_NORMAL, photo_file,
context_ );
669 if( error_code < GP_OK )
671 gp_file_unref( photo_file );
672 unlink( temp_file_name );
674 gp_context_error(
context_,
"Could not get file %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
679 error_code = gp_camera_file_delete(
camera_, photo_file_path.folder, photo_file_path.name,
context_ );
680 if( error_code < GP_OK )
682 unlink( temp_file_name );
684 gp_context_error(
context_,
"Could delete file %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
685 gp_file_free( photo_file );
692 gp_file_free( photo_file );
693 unlink( temp_file_name );
698 gp_file_free( photo_file );
699 unlink( temp_file_name );
bool photo_camera_get_config(const std::string &, char **value)
bool photo_camera_capture(photo_image *image)
GPContext * photo_camera_create_context(void)
bool photo_camera_set_config(const std::string ¶m, const std::string &value)
void error(const std::string &function_name)
CameraList * getCameraList(void)
bool photo_image_read(const std::string &filename)
bool photo_camera_open(photo_camera_list *list, int n)
int photo_camera_find_widget_by_name(std::string name, CameraWidget **child, CameraWidget **rootconfig)
void contextError(GPContext *context, const char *error_string, void *data)
CameraAbilities abilities_
bool photo_camera_capture_to_file(const std::string &filename)
bool photo_camera_check_toggle_value(const std::string &value_in, int *value_out)
bool photo_camera_close(void)
bool lookupAbilities(const std::string &model_name, CameraAbilities *abilities)
void contextStatus(GPContext *context, const char *status_string, void *data)
bool lookupPortInfo(const std::string &port_name, GPPortInfo *port_info)