// TODO fix to go through all folders // TODO this was never even used.. bool GPCamera::deleteAllItems(const QString& folder) { #ifdef HAVE_GPHOTO2 int errorCode; QStringList folderList; d->status->cancel = false; errorCode = gp_camera_folder_delete_all(d->camera, QFile::encodeName(folder).constData(), d->status->context); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to delete camera folder!"; printGphotoErrorDescription(errorCode); return false; } return true; #else Q_UNUSED(folder); return false; #endif /* HAVE_GPHOTO2 */ }
bool photoController::capture(const char *filename) { if(checkCameraDetection() == false) { DEBUG_PRINTF(V_WARNING, "No camera detected.\n"); return false; } int fd, retval; CameraFile *file; CameraFilePath camera_file_path; START_CHRONOMETER(); DEBUG_PRINTF(V_MESSAGE, "Deleting old files.\n"); retval = gp_camera_folder_delete_all(camera, "/", context); if(retval != GP_OK) // Error. { DEBUG_PRINTF(V_WARNING, "ERROR: Couldn't delete old files in camera memory. Code: %d\n", retval); return false; } DEBUG_PRINTF(V_MESSAGE, "Camera capture.\n"); retval = gp_camera_capture(camera, GP_CAPTURE_IMAGE, &camera_file_path, context); if(retval != GP_OK) // Error. { if(retval == GP_ERROR_NOT_SUPPORTED) DEBUG_PRINTF(V_WARNING, "ERROR: This camera can not capture.\n"); else { DEBUG_PRINTF(V_WARNING, "ERROR: Unexpected gp_camera_capture return. Code: %d\n", retval); releaseCamera(&camera, context); camera_detected = false; initCamera(); } return false; } DEBUG_PRINTF(V_MESSAGE, "camera_file_path.folder %s!\n", camera_file_path.folder); DEBUG_PRINTF(V_MESSAGE, "Open %s!\n", filename); fd = open(filename, O_CREAT | O_WRONLY, 0644); if(fd < 0) // Error. { DEBUG_PRINTF(V_WARNING, "Error opening file: %s!\n", strerror(errno)); return false; } DEBUG_PRINTF(V_MESSAGE, "Create new CameraFile object from a file descriptor FD: %d.\n", fd); retval = gp_file_new_from_fd(&file, fd); if(retval != GP_OK) // Error. { DEBUG_PRINTF(V_WARNING, "ERROR: Unexpected gp_file_new_from_fd return. Code: %d\n", retval); gp_file_free(file); close(fd); return false; } if(checkCameraDetection() == false) { DEBUG_PRINTF(V_WARNING, "No camera detected 2.\n"); gp_file_free(file); close(fd); return false; } DEBUG_PRINTF(V_MESSAGE, "Copy file from camera.\n"); retval = gp_camera_file_get(camera, camera_file_path.folder, camera_file_path.name, GP_FILE_TYPE_NORMAL, file, context); if(retval != GP_OK) // Error. { if(retval == GP_ERROR_DIRECTORY_NOT_FOUND) DEBUG_PRINTF(V_WARNING, "Photo directory not found.\n"); else if(retval == GP_ERROR_FILE_NOT_FOUND) DEBUG_PRINTF(V_WARNING, "Photo file name not found.\n"); else DEBUG_PRINTF(V_WARNING, "ERROR: Unexpected gp_camera_file_get return. Code: %d\n", retval); gp_file_free(file); close(fd); return false; } if(checkCameraDetection() == false) { DEBUG_PRINTF(V_WARNING, "No camera detected 3.\n"); gp_file_free(file); close(fd); return false; } DEBUG_PRINTF(V_MESSAGE, "Delete file from camera.\n"); retval = gp_camera_file_delete(camera, camera_file_path.folder, camera_file_path.name, context); if(retval != GP_OK) // Error. { DEBUG_PRINTF(V_WARNING, "ERROR: Unexpected gp_camera_file_delete return. Code: %d\n", retval); gp_file_free(file); close(fd); return false; } DEBUG_PRINTF(V_MESSAGE, "Free CameraFile object.\n"); gp_file_unref(file); close(fd); cv::Mat raw = cv::imread(filename); if(raw.data == NULL) { DEBUG_PRINTF(V_WARNING, "ERROR: OpenCV failed to open image file.\n"); return false; } cv::Size raw_size = raw.size(); DEBUG_PRINTF(V_MESSAGE, "capture() cv::Mat total=%u width=%d height=%d refcount=%d\n", raw.total(), raw_size.width, raw_size.height, (int)(void*)raw.refcount); crop(raw); raw.release(); STOP_CHRONOMETER("Capture"); return true; }