hide action entries depending on command presence

git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@12484 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Marcus Meissner
2009-10-04 19:47:09 +00:00
parent fa534c0dca
commit aa206e8062
2 changed files with 69 additions and 30 deletions

View File

@@ -449,13 +449,25 @@ have_prop(Camera *camera, uint16_t vendor, uint16_t prop) {
if (!prop && (camera->pl->params.deviceinfo.VendorExtensionID==vendor))
return 1;
for (i=0; i<camera->pl->params.deviceinfo.DevicePropertiesSupported_len; i++) {
if (prop != camera->pl->params.deviceinfo.DevicePropertiesSupported[i])
continue;
if ((prop & 0xf000) == 0x5000) /* generic property */
return 1;
if (camera->pl->params.deviceinfo.VendorExtensionID==vendor)
return 1;
if ((prop & 0x7000) == 0x5000) { /* properties */
for (i=0; i<camera->pl->params.deviceinfo.DevicePropertiesSupported_len; i++) {
if (prop != camera->pl->params.deviceinfo.DevicePropertiesSupported[i])
continue;
if ((prop & 0xf000) == 0x5000) /* generic property */
return 1;
if (camera->pl->params.deviceinfo.VendorExtensionID==vendor)
return 1;
}
}
if ((prop & 0x7000) == 0x1000) { /* commands */
for (i=0; i<camera->pl->params.deviceinfo.OperationsSupported_len; i++) {
if (prop != camera->pl->params.deviceinfo.OperationsSupported[i])
continue;
if ((prop & 0xf000) == 0x1000) /* generic property */
return 1;
if (camera->pl->params.deviceinfo.VendorExtensionID==vendor)
return 1;
}
}
return 0;
}
@@ -3584,14 +3596,14 @@ _put_wifi_profiles_menu (CONFIG_MENU_PUT_ARGS)
static struct submenu camera_actions_menu[] = {
/* { N_("Viewfinder Mode"), "viewfinder", PTP_DPC_CANON_ViewFinderMode, PTP_VENDOR_CANON, PTP_DTC_UINT32, _get_Canon_ViewFinderMode, _put_Canon_ViewFinderMode}, */
{ N_("Focus Lock"), "focuslock", 0, PTP_VENDOR_CANON, 0, _get_Canon_FocusLock, _put_Canon_FocusLock},
{ N_("Bulb Mode"), "bulb", 0, PTP_VENDOR_CANON, 0, _get_Canon_EOS_Bulb, _put_Canon_EOS_Bulb},
{ N_("Focus Lock"), "focuslock", PTP_OC_CANON_FocusLock, PTP_VENDOR_CANON, 0, _get_Canon_FocusLock, _put_Canon_FocusLock},
{ N_("Bulb Mode"), "bulb", 0, PTP_VENDOR_CANON, PTP_OC_CANON_EOS_BulbStart, _get_Canon_EOS_Bulb, _put_Canon_EOS_Bulb},
{ N_("Synchronize camera date and time with PC"), "syncdatetime", PTP_DPC_CANON_UnixTime, PTP_VENDOR_CANON, PTP_DTC_UINT32, _get_Canon_SyncTime, _put_Canon_SyncTime },
{ N_("Synchronize camera date and time with PC"), "syncdatetime", PTP_DPC_CANON_EOS_CameraTime, PTP_VENDOR_CANON, PTP_DTC_UINT32, _get_Canon_SyncTime, _put_Canon_SyncTime },
{ N_("Drive Nikon DSLR Autofocus"), "autofocusdrive", 0, PTP_VENDOR_NIKON, 0, _get_Nikon_AFDrive, _put_Nikon_AFDrive },
{ N_("Drive Canon DSLR Autofocus"), "autofocusdrive", 0, PTP_VENDOR_CANON, 0, _get_Canon_EOS_AFDrive, _put_Canon_EOS_AFDrive },
{ N_("Drive Nikon DSLR Manual focus"), "manualfocusdrive", 0, PTP_VENDOR_NIKON, 0, _get_Nikon_MFDrive, _put_Nikon_MFDrive },
{ N_("Drive Canon DSLR Manual focus"), "manualfocusdrive", 0, PTP_VENDOR_CANON, 0, _get_Canon_EOS_MFDrive, _put_Canon_EOS_MFDrive },
{ N_("Drive Nikon DSLR Autofocus"), "autofocusdrive", 0, PTP_VENDOR_NIKON, PTP_OC_NIKON_AfDrive, _get_Nikon_AFDrive, _put_Nikon_AFDrive },
{ N_("Drive Canon DSLR Autofocus"), "autofocusdrive", 0, PTP_VENDOR_CANON, PTP_OC_CANON_EOS_DoAf, _get_Canon_EOS_AFDrive, _put_Canon_EOS_AFDrive },
{ N_("Drive Nikon DSLR Manual focus"), "manualfocusdrive", 0, PTP_VENDOR_NIKON, PTP_OC_NIKON_MfDrive, _get_Nikon_MFDrive, _put_Nikon_MFDrive },
{ N_("Drive Canon DSLR Manual focus"), "manualfocusdrive", 0, PTP_VENDOR_CANON, PTP_OC_CANON_EOS_DriveLens, _get_Canon_EOS_MFDrive, _put_Canon_EOS_MFDrive },
{ 0,0,0,0,0,0,0 },
};

View File

@@ -1408,6 +1408,7 @@ camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
/* Canon EOS DSLR preview mode */
if (ptp_operation_issupported(&camera->pl->params, PTP_OC_CANON_EOS_GetViewFinderData)) {
PTPPropertyValue val;
int tries = 20;
SET_CONTEXT_P(params, context);
@@ -1420,29 +1421,55 @@ camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
gp_log (GP_LOG_ERROR,"ptp2_prepare_eos_preview", "setval of evf outputmode to 2 failed!");
return GP_ERROR;
}
while (tries--) {
ret = ptp_canon_eos_get_viewfinder_image (params , &data, &size);
if (ret == PTP_RC_OK) {
uint32_t len = dtoh32a(data);
ret = ptp_canon_eos_get_viewfinder_image (params , &data, &size);
if (ret == PTP_RC_OK) {
uint32_t len = dtoh32a(data);
/* 4 byte len of jpeg data, 4 byte unknown */
/* JPEG blob */
/* stuff */
/* 4 byte len of jpeg data, 4 byte unknown */
/* JPEG blob */
/* stuff */
if (len > size) len = size;
gp_file_append ( file, (char*)data+8, len );
gp_file_set_mime_type (file, GP_MIME_JPEG); /* always */
/* Add an arbitrary file name so caller won't crash */
gp_file_set_name (file, "preview.jpg");
free (data);
SET_CONTEXT_P(params, NULL);
return GP_OK;
} else {
if (ret == 0xa102) { /* means "not there yet" ... so wait */
PTPCanon_changes_entry *entries = NULL;
int nrofentries = 0;
if (len > size) len = size;
gp_file_append ( file, (char*)data+8, len );
gp_file_set_mime_type (file, GP_MIME_JPEG); /* always */
/* Add an arbitrary file name so caller won't crash */
gp_file_set_name (file, "preview.jpg");
free (data);
gp_context_idle (context);
usleep (50*1000);
/* Poll for camera events */
while (1) {
ret = ptp_canon_eos_getevent (params, &entries, &nrofentries);
if (ret != PTP_RC_OK) {
gp_log (GP_LOG_ERROR,"ptp2_capture_eos_preview", "getevent failed!");
return GP_ERROR;
}
if (nrofentries == 0)
break;
free (entries);
nrofentries = 0;
entries = NULL;
}
continue;
}
gp_log (GP_LOG_ERROR,"ptp2_capture_eos_preview", "get_viewfinder_image failed: 0x%x", ret);
SET_CONTEXT_P(params, NULL);
return GP_ERROR;
}
}
else
gp_log (GP_LOG_ERROR,"ptp2_prepare_eos_preview", "get_viewfinder_image failed: 0x%x", ret);
gp_log (GP_LOG_ERROR,"ptp2_capture_eos_preview","get_viewfinder_image failed after 20 tries with ret: 0x%x\n", ret);
SET_CONTEXT_P(params, NULL);
return GP_OK;
return GP_ERROR;
}
gp_context_error (context,
_("Sorry, your Canon camera does not support Canon Viewfinder mode"));
gp_context_error (context, _("Sorry, your Canon camera does not support Canon Viewfinder mode"));
return GP_ERROR_NOT_SUPPORTED;
case PTP_VENDOR_NIKON: {
PTPPropertyValue value;