int for_each_file (GPParams *p, FileAction action) { CameraList *list; int i, count, r; const char *name = NULL; char *f = NULL; CR (gp_list_new (&list)); /* Iterate on all files */ CR (gp_camera_folder_list_files (p->camera, p->folder, list, p->context)); CR (count = gp_list_count (list)); if (p->flags & FLAGS_REVERSE) { for (i = count ; i--; ) { CL (gp_list_get_name (list, i, &name), list); CL (action (p, name), list); } } else { for (i = 0; i < count; i++) { CL (gp_list_get_name (list, i, &name), list); CL (action (p, name), list); } } /* If no recursion is requested, we are done. */ if (!(p->flags & FLAGS_RECURSE)) { gp_list_free (list); return (GP_OK); } /* Recursion requested. Descend into subfolders. */ CL (gp_camera_folder_list_folders (p->camera, p->folder, list, p->context), list); CL (count = gp_list_count (list), list); for (i = 0; i < count; i++) { CL (gp_list_get_name (list, i, &name), list); f = p->folder; p->folder = malloc (sizeof (char) * (strlen (f) + 1 + strlen (name) + 1)); if (!p->folder) { p->folder = f; gp_list_free (list); return (GP_ERROR_NO_MEMORY); } strcpy (p->folder, f); if (p->folder[strlen (p->folder) - 1] != '/') strcat (p->folder, "/"); strcat (p->folder, name); r = for_each_file (p, action); free (p->folder); p->folder = f; CL (r, list); } gp_list_free (list); return (GP_OK); }
static int shell_ls (Camera __unused__ *camera, const char *arg) { CameraList *list; char buf[1024], folder[MAX_FOLDER_LEN]; int x, y=1; int arg_count = shell_arg_count(arg); const char *name; if (arg_count) { shell_construct_path (p->folder, arg, folder, NULL); } else { strcpy (folder, p->folder); } CHECK (gp_list_new (&list)); CL (gp_camera_folder_list_folders (p->camera, folder, list, p->context), list); if (p->flags & FLAGS_QUIET) printf ("%i\n", gp_list_count (list)); for (x = 1; x <= gp_list_count (list); x++) { CL (gp_list_get_name (list, x - 1, &name), list); if (p->flags & FLAGS_QUIET) printf ("%s\n", name); else { sprintf (buf, "%s/", name); printf ("%-20s", buf); if (y++ % 4 == 0) putchar ('\n'); } } CL (gp_camera_folder_list_files (p->camera, folder, list, p->context), list); if (p->flags & FLAGS_QUIET) printf("%i\n", gp_list_count(list)); for (x = 1; x <= gp_list_count (list); x++) { gp_list_get_name (list, x - 1, &name); if (p->flags & FLAGS_QUIET) printf ("%s\n", name); else { printf ("%-20s", name); if (y++ % 4 == 0) putchar ('\n'); } } if ((p->flags & FLAGS_QUIET) == 0 && (y % 4 != 1)) putchar ('\n'); gp_list_free (list); return (GP_OK); }
static int get_path_for_id_rec (GPParams *p, const char *base_folder, unsigned int id, unsigned int *base_id, char *folder, char *filename) { char subfolder[1024]; int n_folders, n_files, r; unsigned int i; const char *name; CameraList *list; strncpy (folder, base_folder, MAX_FOLDER_LEN); CR (gp_list_new(&list)); CL (gp_camera_folder_list_files (p->camera, base_folder, list, p->context), list); CL (n_files = gp_list_count (list), list); if (id - *base_id < (unsigned int) n_files) { /* ID is in this folder */ GP_DEBUG ("ID %i is in folder '%s'.", id, base_folder); CL (gp_list_get_name (list, id - *base_id, &name), list); strncpy (filename, name, MAX_FILE_LEN); gp_list_free (list); return (GP_OK); } else { /* Look for IDs in subfolders */ GP_DEBUG ("ID %i is not in folder '%s'.", id, base_folder); *base_id += n_files; CL (gp_camera_folder_list_folders (p->camera, base_folder, list, p->context), list); CL (n_folders = gp_list_count (list), list); for (i = 0; i < (unsigned int)n_folders; i++) { CL (gp_list_get_name (list, i, &name), list); strncpy (subfolder, base_folder, sizeof (subfolder)); if (strlen (base_folder) > 1) strncat (subfolder, "/", sizeof (subfolder) - strlen(subfolder) - 1); strncat (subfolder, name, sizeof (subfolder) - strlen(subfolder) - 1); r = get_path_for_id_rec (p, subfolder, id, base_id, folder, filename); switch (r) { case GP_ERROR_FRONTEND_BAD_ID: break; default: gp_list_free (list); return (r); } } gp_list_free (list); return (GP_ERROR_FRONTEND_BAD_ID); } }
/** * Autodetect all detectable camera * * @param list a #CameraList that receives the autodetected cameras * @param context a #GPContext * @return a gphoto2 error code * * This camera will autodetected all cameras that can be autodetected. * This will for instance detect all USB cameras. * * CameraList *list; * gp_list_new (&list); * gp_camera_autodetect (list, context); * ... done! ... */ int gp_camera_autodetect (CameraList *list, GPContext *context) { CameraAbilitiesList *al = NULL; GPPortInfoList *il = NULL; int ret, i; CameraList *xlist = NULL; ret = gp_list_new (&xlist); if (ret < GP_OK) goto out; if (!il) { /* Load all the port drivers we have... */ ret = gp_port_info_list_new (&il); if (ret < GP_OK) goto out; ret = gp_port_info_list_load (il); if (ret < 0) goto out; ret = gp_port_info_list_count (il); if (ret < 0) goto out; } /* Load all the camera drivers we have... */ ret = gp_abilities_list_new (&al); if (ret < GP_OK) goto out; ret = gp_abilities_list_load (al, context); if (ret < GP_OK) goto out; /* ... and autodetect the currently attached cameras. */ ret = gp_abilities_list_detect (al, il, xlist, context); if (ret < GP_OK) goto out; /* Filter out the "usb:" entry */ ret = gp_list_count (xlist); if (ret < GP_OK) goto out; for (i=0;i<ret;i++) { const char *name, *value; gp_list_get_name (xlist, i, &name); gp_list_get_value (xlist, i, &value); if (!strcmp ("usb:",value)) continue; gp_list_append (list, name, value); } out: if (il) gp_port_info_list_free (il); if (al) gp_abilities_list_free (al); gp_list_free (xlist); if (ret < GP_OK) return ret; return gp_list_count(list); }
int cam_detect_camera (GPParams *gp_params) { int x, count; CameraList *list; const char *name = NULL, *value = NULL; int ret = 0; _get_portinfo_list (gp_params); if ( (ret = gp_list_new (&list)) < 0) goto err_no; gp_abilities_list_detect (gp_params_abilities_list(gp_params), gp_params->portinfo_list, list, gp_params->context); if ((ret = count = gp_list_count (list)) < 0) goto err_list; LOG_I(("%-30s %-16s\n"), ("Model"), ("Port")); LOG_I(("----------------------------------------------------------\n")); for (x = 0; x < count; x++) { (gp_list_get_name (list, x, &name), list); (gp_list_get_value (list, x, &value), list); LOG_I(("%-30s %-16s\n"), name, value); } gp_list_free (list); return count; err_list: gp_list_free (list); err_no: return ret; }
static int camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path, GPContext *context) { CameraList *list; int count; const char* name; if (type != GP_CAPTURE_IMAGE) return (GP_ERROR_NOT_SUPPORTED); /* capture a image to flash (note: we do not check if full */ CHECK_RESULT (dc120_capture(camera, path, context)); /* Get the last picture in the Flash memory */ gp_list_new(&list); dc120_get_filenames (camera, 0, 0, list, context); count = gp_list_count(list); gp_list_get_name (list, count - 1, &name); gp_list_free(list); /* Set the filename */ snprintf(path->folder, sizeof(path->folder), "/"); CHECK_RESULT (gp_filesystem_append (camera->fs, path->folder, path->name, context)); return (GP_OK); }
int auto_detect_action (CameraList *list,GPContext *context) { int count, result; GPPortInfoList *portinfo_list; CameraAbilitiesList *al = NULL; if ((result = gp_port_info_list_new (&portinfo_list)) < GP_OK) return result; result = gp_port_info_list_load (portinfo_list); if (result < 0) { gp_port_info_list_free (portinfo_list); return result; } count = gp_port_info_list_count (portinfo_list); if (count < 0) { gp_port_info_list_free (portinfo_list); return count; } gp_abilities_list_new (&al); gp_abilities_list_load (al, context); gp_abilities_list_detect (al, portinfo_list, list, context); gp_abilities_list_free (al); count = gp_list_count (list); return count > 0 ? GP_OK : GP_ERROR; }
static TW_UINT16 GPHOTO2_GetIdentity( pTW_IDENTITY pOrigin, pTW_IDENTITY self) { int count; const char *cname, *pname; if (TWRC_SUCCESS != gphoto2_auto_detect()) return TWRC_FAILURE; count = gp_list_count (detected_cameras); if (count < GP_OK) { gp_list_free (detected_cameras); return TWRC_FAILURE; } TRACE("%d cameras detected.\n", count); self->ProtocolMajor = TWON_PROTOCOLMAJOR; self->ProtocolMinor = TWON_PROTOCOLMINOR; lstrcpynA (self->Manufacturer, "The Wine Team", sizeof(self->Manufacturer) - 1); lstrcpynA (self->ProductFamily, "GPhoto2 Camera", sizeof(self->ProductFamily) - 1); if (!count) { /* No camera detected. But we need to return an IDENTITY anyway. */ lstrcpynA (self->ProductName, "GPhoto2 Camera", sizeof(self->ProductName) - 1); return TWRC_SUCCESS; } gp_list_get_name (detected_cameras, curcamera, &cname); gp_list_get_value (detected_cameras, curcamera, &pname); if (count == 1) /* Normal case, only one camera. */ snprintf (self->ProductName, sizeof(self->ProductName), "%s", cname); else snprintf (self->ProductName, sizeof(self->ProductName), "%s@%s", cname, pname); curcamera = (curcamera+1) % count; return TWRC_SUCCESS; }
void Camera::for_each_file_in_folder(const FileFunc& func, const std::string& folder) { int ret; CameraList *files; gp_list_new(&files); if ((ret = gp_camera_folder_list_files(camera, folder.c_str(), files, ctx->context)) < GP_OK) { throw Exception("gp_camera_folder_list_files", ret); } for (int i = 0; i < gp_list_count(files); ++i) { std::string file_name; { const char *c_file_name; gp_list_get_name(files, i, &c_file_name); file_name = c_file_name; } CameraFileInfo file_info; if ((ret = gp_camera_file_get_info(camera, folder.c_str(), file_name.c_str(), &file_info, ctx->context)) < GP_OK) { throw Exception("gp_camera_file_get_info", ret); } FileInfo info; info.folder = folder; info.name = file_name; if (file_info.file.fields & GP_FILE_INFO_MTIME) { info.fields |= FILE_INFO_TIME; info.time = file_info.file.mtime; } if (file_info.file.fields & GP_FILE_INFO_TYPE) { info.fields |= FILE_INFO_TYPE; info.type = file_info.file.type; } func(info); } gp_list_free(files); CameraList *folders; gp_list_new(&folders); if ((ret = gp_camera_folder_list_folders(camera, folder.c_str(), folders, ctx->context)) < GP_OK) { throw Exception("gp_camera_folder_list_folders", ret); } for (int i = 0; i < gp_list_count(folders); ++i) { const char *child_name; gp_list_get_name(folders, i, &child_name); std::string absolute_path = folder + "/" + child_name; for_each_file_in_folder(func, absolute_path); } gp_list_free(folders); }
void Image_GPhoto::detectCameras() { lock_guard<recursive_mutex> lock(_gpMutex); if (_gpPorts != nullptr) gp_port_info_list_free(_gpPorts); gp_port_info_list_new(&_gpPorts); gp_port_info_list_load(_gpPorts); CameraList* availableCameras = nullptr; gp_list_new(&availableCameras); gp_abilities_list_detect(_gpCams, _gpPorts, availableCameras, _gpContext); Log::get() << Log::MESSAGE << "Image_GPhoto::" << __FUNCTION__ << " - " << (gp_list_count(availableCameras) > 0 ? gp_list_count(availableCameras) : 0) << " cameras detected" << Log::endl; // Create the list of tetherable cameras for (int i = 0; i < gp_list_count(availableCameras); ++i) { GPhotoCamera camera; const char* s; gp_list_get_name(availableCameras, i, &s); camera.model = string(s); gp_list_get_value(availableCameras, i, &s); camera.port = string(s); if (!initCamera(camera)) { releaseCamera(camera); Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Unable to initialize camera " << camera.model << " on port " << camera.port << Log::endl; } else if (!camera.canTether && !camera.canImport) { releaseCamera(camera); Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Camera " << camera.model << " on port " << camera.port << " does not support import or tethering" << Log::endl; } else { releaseCamera(camera); _cameras.push_back(camera); Log::get() << Log::MESSAGE << "Image_GPhoto::" << __FUNCTION__ << " - Camera " << camera.model << " on port " << camera.port << " initialized correctly" << Log::endl; } } }
static int foreach_entry(char* folder, GPParams* gp_params, enum EntryType type, PHandleFunc func, void* args) { CameraList *list = NULL; int ret = 0, count = 0; CK00 (ret = gp_list_new (&list), err_newlist); if (type == ET_FOLDER) CK00 (ret = gp_camera_folder_list_folders (gp_params->camera, folder, list, gp_params->context), err_listfolder); else if (type == ET_FILE) CK00 (ret = gp_camera_folder_list_files (gp_params->camera, folder, list, gp_params->context), err_listfiles); else { LOG_E("unknow type :%d\n", type); goto release_list; } CK00 (count = ret = gp_list_count (list), err_listcount); int i = 0; for (i = 0; i < count; ++i) { const char* tmp_name = NULL; CK00 (ret= gp_list_get_name (list, i, &tmp_name), err_listgetname); if (type == ET_FILE && try_get_camera_file(gp_params, folder, tmp_name) < 0) { continue; } char* new_folder = NULL; CK01 (new_folder = make_new_path(folder,tmp_name), err_makpath); func(new_folder, gp_params, args); safe_free(new_folder); } release_list: if (list) gp_list_free (list); out: return ret; err_newlist: LOG_E("gp_list_new error,retcode = %d", ret); ret = -1; goto out; err_listfolder: LOG_E("gp_camera_folder_list_folders error,retcode = %d", ret); ret = -1; goto release_list; err_listfiles: LOG_E("gp_camera_folder_list_files error,retcode = %d", ret); ret = -1; goto release_list; err_listcount: LOG_E("gp_list_count error,retcode = %d", ret); ret = -1; goto release_list; err_listgetname: LOG_E("gp_list_get_name error,retcode = %d", ret); ret = -1; goto release_list; err_makpath: ret = -1; goto release_list; }
bool photo_camera_list::filterCameraList( GPContext* context, const std::string match_string ) { CameraList *working_list = NULL; const char *name, *value; int count = 0; if( gp_list_new( &working_list ) != GP_OK ) { photo_reporter::error( "gp_list_new()" ); gp_list_free( working_list ); return false; } // Autodetect the currently attached photo_cameras. if( gp_abilities_list_detect( abilities_list_, port_info_list_, working_list, context) != GP_OK ) { photo_reporter::error( "gp_abilities_list_detect()" ); gp_list_free( working_list ); return false; } count = gp_list_count( working_list ); if( count < GP_OK ) { photo_reporter::error( "gp_list_count()" ); gp_list_free( working_list ); return false; } // Clear camera_list_ for appending if( gp_list_reset( camera_list_ ) != GP_OK ) { photo_reporter::error( "gp_list_reset()" ); gp_list_free( working_list ); return false; } // Filter out the generic 'usb:' entry for( int i = 0; i < count; i++ ) { gp_list_get_name( working_list, i, &name ); gp_list_get_value( working_list, i, &value ); if( match_string.compare( value ) != 0 ) { gp_list_append( camera_list_, name, value ); } } gp_list_free( working_list ); return true; }
bool GPCamera::getFolders(const QString& folder) { #ifdef HAVE_GPHOTO2 int errorCode; CameraList* clist = 0; gp_list_new(&clist); d->status->cancel = false; errorCode = gp_camera_folder_list_folders(d->camera, QFile::encodeName(folder).constData(), clist, d->status->context); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folders list from camera!"; printGphotoErrorDescription(errorCode); gp_list_unref(clist); return false; } QStringList subFolderList; int count = gp_list_count(clist); if (count < 1) { return true; } for (int i = 0 ; i < count ; ++i) { const char* subFolder = 0; errorCode = gp_list_get_name(clist, i, &subFolder); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folder name from camera!"; printGphotoErrorDescription(errorCode); gp_list_unref(clist); return false; } subFolderList.append(folder + QFile::decodeName(subFolder) + QLatin1Char('/')); } gp_list_unref(clist); emit signalFolderList(subFolderList); return true; #else Q_UNUSED(folder); return false; #endif /* HAVE_GPHOTO2 */ }
static TW_UINT16 gphoto2_auto_detect(void) { int result, count; if (detected_cameras && (gp_list_count (detected_cameras) == 0)) { /* Reload if previously no cameras, we might detect new ones. */ TRACE("Reloading portlist trying to detect cameras.\n"); if (port_list) { gp_port_info_list_free (port_list); port_list = NULL; } } if (!port_list) { TRACE("Auto detecting gphoto cameras.\n"); TRACE("Loading ports...\n"); if (gp_port_info_list_new (&port_list) < GP_OK) return TWRC_FAILURE; result = gp_port_info_list_load (port_list); if (result < 0) { gp_port_info_list_free (port_list); return TWRC_FAILURE; } count = gp_port_info_list_count (port_list); if (count <= 0) return TWRC_FAILURE; if (gp_list_new (&detected_cameras) < GP_OK) return TWRC_FAILURE; if (!abilities_list) { /* Load only once per program start */ gp_abilities_list_new (&abilities_list); TRACE("Loading cameras...\n"); gp_abilities_list_load (abilities_list, NULL); } TRACE("Detecting cameras...\n"); gp_abilities_list_detect (abilities_list, port_list, detected_cameras, NULL); curcamera = 0; TRACE("%d cameras detected\n", gp_list_count(detected_cameras)); } return TWRC_SUCCESS; }
bool GPCamera::getItemsInfoList(const QString& folder, bool useMetadata, CamItemInfoList& items) { #ifdef HAVE_GPHOTO2 int errorCode; CameraList* clist = 0; const char* cname = 0; gp_list_new(&clist); d->status->cancel = false; errorCode = gp_camera_folder_list_files(d->camera, QFile::encodeName(folder).constData(), clist, d->status->context); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folder files list from camera!"; printGphotoErrorDescription(errorCode); gp_list_unref(clist); return false; } int count = gp_list_count(clist); for (int i = 0 ; i < count ; ++i) { errorCode = gp_list_get_name(clist, i, &cname); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get file name from camera!"; printGphotoErrorDescription(errorCode); gp_list_unref(clist); return false; } // TODO for further speed-up, getItemInfoInternal call could be called separately when needed CamItemInfo info; getItemInfoInternal(folder, QFile::decodeName(cname), info, useMetadata); items.append(info); } gp_list_unref(clist); return true; #else Q_UNUSED(folder); Q_UNUSED(useMetadata); Q_UNUSED(items); return false; #endif /* HAVE_GPHOTO2 */ }
// TODO unused, remove? bool GPCamera::getItemsList(const QString& folder, QStringList& itemsList) { #ifdef HAVE_GPHOTO2 int errorCode; CameraList* clist = 0; const char* cname = 0; gp_list_new(&clist); d->status->cancel = false; errorCode = gp_camera_folder_list_files(d->camera, QFile::encodeName(folder).constData(), clist, d->status->context); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get folder files list from camera!"; printGphotoErrorDescription(errorCode); gp_list_unref(clist); return false; } int count = gp_list_count(clist); for (int i = 0 ; i < count ; ++i) { errorCode = gp_list_get_name(clist, i, &cname); if (errorCode != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get file name from camera!"; printGphotoErrorDescription(errorCode); gp_list_unref(clist); return false; } itemsList.append(QFile::decodeName(cname)); } gp_list_unref(clist); return true; #else Q_UNUSED(folder); Q_UNUSED(itemsList); return false; #endif /* HAVE_GPHOTO2 */ }
static void on_detect_clicked (GtkButton *button, GtkamChooser *chooser) { GtkWidget *d, *status; CameraList *list; int result; const char *name; status = gtkam_status_new (_("Detecting cameras...")); gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status); gp_list_new (&list); result = gp_abilities_list_detect (chooser->priv->al, chooser->priv->il, list, GTKAM_STATUS (status)->context->context); switch (result) { case GP_OK: if (!gp_list_count (list)) { d = gtkam_close_new (_("No cameras detected.")); gtk_window_set_transient_for (GTK_WINDOW (d), GTK_WINDOW (chooser)); gtk_widget_show (d); } else { /* FIXME: Let user choose from the list */ gp_list_get_name (list, 0, &name); gtk_entry_set_text (chooser->priv->entry_model, name); gtk_entry_set_text (chooser->priv->entry_port, "Universal Serial Bus (usb:)"); } break; case GP_ERROR_CANCEL: break; default: d = gtkam_error_new (result, GTKAM_STATUS (status)->context, GTK_WIDGET (chooser), _("Could not detect any cameras.")); gtk_widget_show (d); break; } gp_list_unref (list); gtk_object_destroy (GTK_OBJECT (status)); }
bool photoController::checkCameraDetection() { START_CHRONOMETER(); CameraList *list; gp_list_new (&list); int ret = auto_detect_action(list, context); DEBUG_PRINTF(V_MESSAGE, "gp_camera_autodetect return %d wanted %d\n", ret, GP_OK); if(ret >= GP_OK) { int cameraCount = gp_list_count(list); DEBUG_PRINTF(V_MESSAGE, "Camera count: %d\n", cameraCount); if(cameraCount > 0) { DEBUG_PRINTF(V_MESSAGE, "Got a camera\n"); camera_detected = true; if(!camera && !initCamera()) { camera = NULL; } } } else { if(camera) { DEBUG_PRINTF(V_MESSAGE, "Exit camera\n"); gp_camera_exit(camera, context); camera = NULL; } camera_detected = false; DEBUG_PRINTF(V_MESSAGE, "Error while getting camera list\n"); } gp_list_unref (list); STOP_CHRONOMETER("Camera detection"); return camera_detected; }
static int camera_file_action (Camera *camera, int action, CameraFile *file, const char *folder, const char *filename, GPContext *context) { CameraList *files = NULL; const char* file_name; int file_nr; int i; char *dot; int picnum=0; int result = GP_OK; /* first find the file */ int from_card; int folder_nr; result = find_folder( camera, folder, &from_card, &folder_nr, context ); if( result != (GP_OK) ) { return result; } result = gp_list_new( &files ); if( result != GP_OK ) { goto fail; } result = dc120_get_filenames(camera, from_card, folder_nr, files, context); if( result != GP_OK ) { goto fail; } /* now we have the list, search for the file. */ file_nr = -1; for( i = 0; i<gp_list_count( files ); i++ ) { gp_list_get_name( files, i, &file_name ); if( strcmp( file_name, filename ) == 0 ) { file_nr = i; /* ok, we found it. */ break; } } gp_list_free( files ); if( file_nr == -1 ) { /* not found */ return GP_ERROR; } picnum = gp_filesystem_number(camera->fs, folder, filename, context); if (picnum < 0) return picnum; if (action == DC120_ACTION_PREVIEW) { /* FIXME: marcus, fix type */ dot = strrchr(filename, '.'); if( dot && strlen( dot )>3 ) { strcpy( dot+1, "ppm"); } } return (dc120_file_action(camera, action, from_card, folder_nr, picnum+1, file, context)); /* yes, after that it is to handle failures. */ fail: if (files) gp_list_free( files ); return result; }
int for_each_folder (GPParams *p, FolderAction action) { CameraList *list; int r, i, count; const char *name = NULL; char *f = NULL; if (!p) return (GP_ERROR_BAD_PARAMETERS); /* Execute the action for this folder. */ for (i = 0; FolderActions[i].name; i++) if (FolderActions[i].action == action) break; gp_log (GP_LOG_DEBUG, "foreach", "Executing action '%s' for folder '%s'.", FolderActions[i].name, p->folder); CR (action (p)); /* If no recursion is requested, we are done. */ if (!(p->flags & FLAGS_RECURSE)) return GP_OK; CR (gp_list_new (&list)); /* Recursion requested. Descend into subfolders. */ CL (gp_camera_folder_list_folders (p->camera, p->folder, list, p->context), list); CL (count = gp_list_count (list), list); if (p->flags & FLAGS_REVERSE) { for (i = count - 1; i >= 0; i--) { CL (gp_list_get_name (list, i, &name), list); f = p->folder; p->folder = malloc (sizeof (char) * (strlen (f) + 1 + strlen (name) + 1)); if (!p->folder) { p->folder = f; gp_list_free (list); return (GP_ERROR_NO_MEMORY); } strcpy (p->folder, f); if (p->folder[strlen (p->folder) - 1] != '/') strcat (p->folder, "/"); strcat (p->folder, name); r = for_each_folder (p, action); free (p->folder); p->folder = f; CL (r, list); } } else { for (i = 0; i < count; i++) { CL (gp_list_get_name (list, i, &name), list); f = p->folder; p->folder = malloc (sizeof (char) * (strlen (f) + 1 + strlen (name) + 1)); if (!p->folder) { p->folder = f; gp_list_free (list); return (GP_ERROR_NO_MEMORY); } strcpy (p->folder, f); if (p->folder[strlen (p->folder) - 1] != '/') strcat (p->folder, "/"); strcat (p->folder, name); r = for_each_folder (p, action); free (p->folder); p->folder = f; CL (r, list); } } gp_list_free (list); return (GP_OK); }
static int get_path_for_id (GPParams *p, const char *base_folder, unsigned int id, char *folder, char *filename) { int r; unsigned int base_id; const char *name; strncpy (folder, base_folder, MAX_FOLDER_LEN); if (p->flags & FLAGS_RECURSE) { base_id = 0; r = get_path_for_id_rec (p, base_folder, id, &base_id, folder, filename); switch (r) { case GP_ERROR_FRONTEND_BAD_ID: gp_context_error (p->context, _("Bad file number. " "You specified %i, but there are only %i " "files available in '%s' or its subfolders. " "Please obtain a valid file number from " "a file listing first."), id + 1, base_id, base_folder); return (GP_ERROR_BAD_PARAMETERS); default: return (r); } } else { CameraList *list; int list_count; /* If we have no recursion, things are easy. */ GP_DEBUG ("No recursion. Taking file %i from folder '%s'.", id, base_folder); CR (gp_list_new (&list)); CL (gp_camera_folder_list_files (p->camera, base_folder, list, p->context), list); CL ((list_count = gp_list_count (list)), list); if (id >= (unsigned int) list_count) { switch (list_count) { case 0: gp_context_error (p->context, _("There are no files in " "folder '%s'."), base_folder); gp_list_free (list); return (GP_ERROR_BAD_PARAMETERS); case 1: gp_context_error (p->context, _("Bad file number. " "You specified %i, but there is only " "1 file available in '%s'."), id + 1, base_folder); gp_list_free (list); return (GP_ERROR_BAD_PARAMETERS); default: gp_context_error (p->context, _("Bad file number. " "You specified %i, but there are only " "%i files available in '%s'. " "Please obtain a valid file number " "from a file listing first."), id + 1, gp_list_count (list), base_folder); gp_list_free (list); return (GP_ERROR_BAD_PARAMETERS); } } CL (gp_list_get_name (list, id, &name), list); strncpy (filename, name, MAX_FILE_LEN); gp_list_free (list); return (GP_OK); } }
int _camctl_recursive_get_previews(const dt_camctl_t *c,dt_camera_preview_flags_t flags,char *path) { CameraList *files; CameraList *folders; const char *filename; const char *foldername; gp_list_new (&files); gp_list_new (&folders); // Process files in current folder... if( gp_camera_folder_list_files(c->active_camera->gpcam,path,files,c->gpcontext) == GP_OK ) { for(int i=0; i < gp_list_count(files); i++) { gp_list_get_name (files, i, &filename); char *file = g_strconcat(path, "/", filename, NULL); // Lets check the type of file... CameraFileInfo cfi; if( gp_camera_file_get_info(c->active_camera->gpcam, path, filename,&cfi,c->gpcontext) == GP_OK) { CameraFile *preview=NULL; CameraFile *exif=NULL; /* * Fetch image preview if flagged... */ if( flags & CAMCTL_IMAGE_PREVIEW_DATA ) { gp_file_new(&preview); if( gp_camera_file_get(c->active_camera->gpcam, path, filename, GP_FILE_TYPE_PREVIEW,preview,c->gpcontext) < GP_OK ) { // No preview for file lets check image size to se if we should download full image for preview... if( cfi.file.size > 0 && cfi.file.size < 512000 ) if( gp_camera_file_get(c->active_camera->gpcam, path, filename, GP_FILE_TYPE_NORMAL,preview,c->gpcontext) < GP_OK ) { preview=NULL; dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to retreive preview of file %s\n",filename); } } } if( flags & CAMCTL_IMAGE_EXIF_DATA ) { gp_file_new(&exif); if( gp_camera_file_get(c->active_camera->gpcam, path, filename, GP_FILE_TYPE_EXIF,exif,c->gpcontext) < GP_OK ) { exif=NULL; dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to retreive exif of file %s\n",filename); } } // let's dispatch to host app.. return if we should stop... if (!_dispatch_camera_storage_image_filename(c,c->active_camera,file,preview,exif)) { g_free(file); return 0; } } else dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to get file information of %s in folder %s on device\n",filename,path); g_free(file); } } // Recurse into folders in current folder... if( gp_camera_folder_list_folders(c->active_camera->gpcam,path,folders,c->gpcontext)==GP_OK) { for(int i=0; i < gp_list_count(folders); i++) { char buffer[4096]= {0}; g_strlcat(buffer,path, 4096); if(path[1]!='\0') g_strlcat(buffer,"/", 4096); gp_list_get_name (folders, i, &foldername); g_strlcat(buffer,foldername, 4096); if( !_camctl_recursive_get_previews(c,flags,buffer)) return 0; } } gp_list_free (files); gp_list_free (folders); return 1; }
void dt_camctl_detect_cameras(const dt_camctl_t *c) { dt_camctl_t *camctl=(dt_camctl_t *)c; dt_pthread_mutex_lock(&camctl->lock); /* reload portdrivers */ if (camctl->gpports) gp_port_info_list_free (camctl->gpports); gp_port_info_list_new( &camctl->gpports ); gp_port_info_list_load( camctl->gpports ); dt_print(DT_DEBUG_CAMCTL,"[camera_control] loaded %d port drivers.\n", gp_port_info_list_count( camctl->gpports ) ); CameraList *available_cameras=NULL; gp_list_new( &available_cameras ); gp_abilities_list_detect (c->gpcams,c->gpports, available_cameras, c->gpcontext ); dt_print(DT_DEBUG_CAMCTL,"[camera_control] %d cameras connected\n",gp_list_count( available_cameras )>0?gp_list_count( available_cameras ):0); for(int i=0; i<gp_list_count( available_cameras ); i++) { dt_camera_t *camera=g_malloc(sizeof(dt_camera_t)); memset( camera,0,sizeof(dt_camera_t)); gp_list_get_name (available_cameras, i, &camera->model); gp_list_get_value (available_cameras, i, &camera->port); dt_pthread_mutex_init(&camera->config_lock, NULL); dt_pthread_mutex_init(&camera->live_view_pixbuf_mutex, NULL); dt_pthread_mutex_init(&camera->live_view_synch, NULL); // if(strcmp(camera->port,"usb:")==0) { g_free(camera); continue; } GList *citem; if( (citem=g_list_find_custom(c->cameras,camera,_compare_camera_by_port)) == NULL || strcmp(((dt_camera_t *)citem->data)->model,camera->model)!=0 ) { if(citem==NULL) { // Newly connected camera if(_camera_initialize(c,camera)==FALSE) { dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to initialize device %s on port %s, probably causes are: locked by another application, no access to udev etc.\n", camera->model,camera->port); g_free(camera); continue; } // Check if camera has capabililties for being presented to darktable if( camera->can_import==FALSE && camera->can_tether==FALSE ) { dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s doesn't support import or tether, skipping device.\n", camera->model,camera->port); g_free(camera); continue; } // Fetch some summary of camera if( gp_camera_get_summary(camera->gpcam, &camera->summary, c->gpcontext) == GP_OK ) { // Remove device property summary: char *eos=strstr(camera->summary.text,"Device Property Summary:\n"); if (eos) eos[0]='\0'; } // Add to camera list camctl->cameras = g_list_append(camctl->cameras,camera); // Notify listeners of connected camera _dispatch_camera_connected(camctl,camera); } } else g_free(camera); } /* check c->cameras in available_cameras */ if( c->cameras && g_list_length(c->cameras)>0) { GList *citem = c->cameras; do { int index=0; dt_camera_t *cam=(dt_camera_t *)citem->data; if (gp_list_find_by_name(available_cameras,&index,cam->model)!= GP_OK) { /* remove camera from cached list.. */ dt_camctl_t *camctl=(dt_camctl_t *)c; dt_camera_t *oldcam = (dt_camera_t *)citem->data; camctl->cameras=citem= g_list_delete_link (c->cameras,citem); g_free(oldcam); } } while ( citem && (citem=g_list_next(citem))!=NULL); } dt_pthread_mutex_unlock(&camctl->lock); }
static TW_UINT16 GPHOTO2_OpenDS( pTW_IDENTITY pOrigin, pTW_IDENTITY self) { int ret, m, p, count, i; CameraAbilities a; GPPortInfo info; const char *model, *port; if (TWRC_SUCCESS != gphoto2_auto_detect()) return TWRC_FAILURE; if (lstrcmpA(self->ProductFamily,"GPhoto2 Camera")) { FIXME("identity passed is not a gphoto camera, but %s!?!\n", self->ProductFamily); return TWRC_FAILURE; } count = gp_list_count (detected_cameras); if (!count) { ERR("No camera found by autodetection. Returning failure.\n"); return TWRC_FAILURE; } if (!lstrcmpA (self->ProductName, "GPhoto2 Camera")) { TRACE("Potential undetected camera. Just using the first autodetected one.\n"); i = 0; } else { for (i=0;i<count;i++) { const char *cname, *pname; TW_STR32 name; gp_list_get_name (detected_cameras, i, &cname); gp_list_get_value (detected_cameras, i, &pname); if (!lstrcmpA(self->ProductName,cname)) break; snprintf(name, sizeof(name), "%s", cname); if (!lstrcmpA(self->ProductName,name)) break; snprintf(name, sizeof(name), "%s@%s", cname, pname); if (!lstrcmpA(self->ProductName,name)) break; } if (i == count) { TRACE("Camera %s not found in autodetected list. Using first entry.\n", self->ProductName); i=0; } } gp_list_get_name (detected_cameras, i, &model); gp_list_get_value (detected_cameras, i, &port); TRACE("model %s, port %s\n", model, port); ret = gp_camera_new (&activeDS.camera); if (ret < GP_OK) { ERR("gp_camera_new: %d\n", ret); return TWRC_FAILURE; } m = gp_abilities_list_lookup_model (abilities_list, model); if (m < GP_OK) { FIXME("Model %s not found, %d!\n", model, m); return TWRC_FAILURE; } ret = gp_abilities_list_get_abilities (abilities_list, m, &a); if (ret < GP_OK) { FIXME("gp_camera_list_get_abilities failed? %d\n", ret); return TWRC_FAILURE; } ret = gp_camera_set_abilities (activeDS.camera, a); if (ret < GP_OK) { FIXME("gp_camera_set_abilities failed? %d\n", ret); return TWRC_FAILURE; } p = gp_port_info_list_lookup_path (port_list, port); if (p < GP_OK) { FIXME("port %s not in portlist?\n", port); return TWRC_FAILURE; } ret = gp_port_info_list_get_info (port_list, p, &info); if (ret < GP_OK) { FIXME("could not get portinfo for port %s?\n", port); return TWRC_FAILURE; } ret = gp_camera_set_port_info (activeDS.camera, info); if (ret < GP_OK) { FIXME("could not set portinfo for port %s to camera?\n", port); return TWRC_FAILURE; } list_init( &(activeDS.files) ); activeDS.currentState = 4; activeDS.twCC = TWRC_SUCCESS; activeDS.pixelflavor = TWPF_CHOCOLATE; activeDS.pixeltype = TWPT_RGB; activeDS.capXferMech = TWSX_MEMORY; TRACE("OK!\n"); return TWRC_SUCCESS; }
static void load_filesystem(const char *folder) { #ifdef HAVE_GPHOTO2 int i, count, ret; CameraList *list; ret = gp_list_new (&list); if (ret < GP_OK) return; ret = gp_camera_folder_list_files (activeDS.camera, folder, list, activeDS.context); if (ret < GP_OK) { gp_list_free (list); return; } count = gp_list_count (list); if (count < GP_OK) { gp_list_free (list); return; } for (i = 0; i < count; i++) { const char *name; struct gphoto2_file *gpfile; ret = gp_list_get_name (list, i, &name); if (ret < GP_OK) continue; gpfile = malloc(sizeof(struct gphoto2_file)); if (!gpfile) continue; TRACE("adding %s/%s\n", folder, name); gpfile->folder = strdup(folder); gpfile->filename = strdup(name); gpfile->download = FALSE; list_add_head( &activeDS.files, &gpfile->entry ); } gp_list_reset (list); ret = gp_camera_folder_list_folders (activeDS.camera, folder, list, activeDS.context); if (ret < GP_OK) { FIXME("list_folders failed\n"); gp_list_free (list); return; } count = gp_list_count (list); if (count < GP_OK) { FIXME("list_folders failed\n"); gp_list_free (list); return; } for (i = 0; i < count; i++) { const char *name; char *newfolder; ret = gp_list_get_name (list, i, &name); if (ret < GP_OK) continue; TRACE("recursing into %s\n", name); newfolder = malloc(strlen(folder)+1+strlen(name)+1); if (!strcmp(folder,"/")) sprintf (newfolder, "/%s", name); else sprintf (newfolder, "%s/%s", folder, name); load_filesystem (newfolder); /* recurse ... happily */ } gp_list_free (list); #endif }
void KKameraConfig::load(bool useDefaults ) { m_config->setReadDefaults( useDefaults ); QStringList groupList = m_config->groupList(); QStringList::Iterator it; int i, count; CameraList *list; CameraAbilitiesList *al; GPPortInfoList *il; const char *model, *value; KCamera *kcamera; for (it = groupList.begin(); it != groupList.end(); it++) { if (*it != "<default>") { m_config->setGroup(*it); if (m_config->readEntry("Path").contains("usb:")) continue; kcamera = new KCamera(*it,m_config->readEntry("Path")); connect(kcamera, SIGNAL(error(const QString &)), SLOT(slot_error(const QString &))); connect(kcamera, SIGNAL(error(const QString &, const QString &)), SLOT(slot_error(const QString &, const QString &))); kcamera->load(m_config); m_devices[*it] = kcamera; } } m_cancelPending = false; gp_list_new (&list); gp_abilities_list_new (&al); gp_abilities_list_load (al, m_context); gp_port_info_list_new (&il); gp_port_info_list_load (il); gp_abilities_list_detect (al, il, list, m_context); gp_abilities_list_free (al); gp_port_info_list_free (il); count = gp_list_count (list); QMap<QString,QString> ports, names; for (i = 0 ; i<count ; i++) { gp_list_get_name (list, i, &model); gp_list_get_value (list, i, &value); ports[value] = model; if (!strcmp(value,"usb:")) names[model] = value; } if (ports.contains("usb:") && names[ports["usb:"]]!="usb:") ports.remove("usb:"); QMap<QString,QString>::iterator portit; for (portit = ports.begin() ; portit != ports.end(); portit++) { /* kdDebug() << "Adding USB camera: " << portit.data() << " at " << portit.key() << endl; */ kcamera = new KCamera(portit.data(),portit.key()); connect(kcamera, SIGNAL(error(const QString &)), SLOT(slot_error(const QString &))); connect(kcamera, SIGNAL(error(const QString &, const QString &)), SLOT(slot_error(const QString &, const QString &))); m_devices[portit.data()] = kcamera; } populateDeviceListView(); gp_list_free (list); emit changed( useDefaults ); }
/** Parses a path for a folder and returns folder number and card */ static int find_folder( Camera *camera, const char *folder, int *from_card, int *folder_nr, GPContext *context) { CameraList *albums = NULL; const char* album_name; int folder_len; int i; char *dc120_folder_card = _("CompactFlash Card"); if( folder[0] != '/' ) { return (GP_ERROR); } folder++; if( folder[0] == '\0') { /* From memory */ *from_card = FALSE; *folder_nr = 0; return (GP_OK); } else if( strncmp(folder, dc120_folder_card, strlen(dc120_folder_card) )==0) { /* From card */ *from_card = TRUE; folder += strlen(dc120_folder_card); } else { /* Subfolder in memory */ *from_card = FALSE; folder--; /* step back to slash */ } if ( (folder[0] == 0) || (folder[0] == '/' && folder[1] == 0) ) { /* ok, finished */ *folder_nr = 0; return (GP_OK); } else if( folder[0] != '/' ) return (GP_ERROR); folder++; /* remove slash */ /* Have trailing slash */ folder_len = strlen(folder); if (folder[folder_len-1] == '/') { folder_len--; } /* ok, now we have a album. first get all albums */ if( gp_list_new( &albums ) != (GP_OK) ) { return (GP_ERROR); } if( dc120_get_albums(camera, *from_card, albums, context) != (GP_OK) ) { gp_list_free( albums ); return (GP_ERROR); } /* no check if such a album exist */ for( i = 0; i<gp_list_count( albums ); i++ ) { gp_list_get_name( albums, i, &album_name ); if( strlen( album_name ) == folder_len && strncmp( album_name, folder, folder_len ) == 0 ) { *folder_nr = i+1; gp_list_free( albums ); /* ok, we found it. */ return (GP_OK); } } /* oh, we did not find the folder. bummer. */ gp_list_free( albums ); return (GP_ERROR); }
int main () { CameraFilesystem *fs; CameraFileInfo info; CameraList *list; int x, count; const char *name; char *foldername; GPContext *context; #ifdef HAVE_MCHECK_H mtrace(); #endif CHECK (gp_list_new(&list)); gp_log_add_func (GP_LOG_DEBUG, log_func, NULL); context = gp_context_new (); gp_context_set_error_func (context, error_func, NULL); printf ("*** Creating file system...\n"); CHECK (gp_filesystem_new (&fs)); printf ("*** Setting the callbacks...\n"); CHECK (gp_filesystem_set_funcs (fs, &fsfuncs, NULL)); printf ("*** Adding a file...\n"); CHECK (gp_filesystem_append (fs, "/", "my.file", context)); gp_filesystem_dump (fs); printf ("*** Removing this file...\n"); CHECK (gp_filesystem_delete_file (fs, "/", "my.file", context)); gp_filesystem_dump (fs); printf ("*** Resetting...\n"); CHECK (gp_filesystem_reset (fs)); gp_filesystem_dump (fs); printf ("*** Adding /...\n"); CHECK (gp_filesystem_append (fs, "/", NULL, context)); printf ("*** Adding /whatever ...\n"); CHECK (gp_filesystem_append (fs, "/whatever", NULL, context)); printf ("*** Adding /whatever/dir...\n"); CHECK (gp_filesystem_append (fs, "/whatever/dir", NULL, context)); printf ("*** Adding /whatever/dir/file1...\n"); CHECK (gp_filesystem_append (fs, "/whatever/dir", "file1", context)); gp_filesystem_dump (fs); printf ("*** Adding /whatever/dir/file2...\n"); CHECK (gp_filesystem_append (fs, "/whatever/dir", "file2", context)); CHECK (gp_filesystem_append (fs, "/whatever/dir", "file3", context)); CHECK (gp_filesystem_append (fs, "/whatever/dir", "file4", context)); CHECK (gp_filesystem_append (fs, "/whatever/dir", "file5", context)); gp_filesystem_dump (fs); printf ("*** Deleting everything below root...\n"); CHECK (gp_filesystem_delete_all (fs, "/", context)); gp_filesystem_dump (fs); printf ("*** Appending root directory...\n"); CHECK (gp_filesystem_append (fs, "/", NULL, context)); printf ("*** Appending some directories...\n"); CHECK (gp_filesystem_append (fs, "/whatever", NULL, context)); CHECK (gp_filesystem_append (fs, "/whatever/directory", NULL, context)); printf ("*** Adding some files...\n"); CHECK (gp_filesystem_append (fs, "/whatever/directory", "some.file", context)); CHECK (gp_filesystem_append (fs, "/whatever/directory", "some.file2", context)); CHECK (gp_filesystem_append (fs, "/another/directory", "another.file", context)); gp_filesystem_dump (fs); printf ("*** Getting info about a file...\n"); CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file", &info, context)); printf ("*** Getting info again (cache!)...\n"); CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file", &info, context)); printf ("*** Set info about another file...\n"); CHECK (gp_filesystem_set_info (fs, "/whatever/directory", "some.file2", info, context)); printf ("*** Getting info about this file (cache!)...\n"); CHECK (gp_filesystem_get_info (fs, "/whatever/directory", "some.file2", &info, context)); printf ("*** Deleting a file...\n"); CHECK (gp_filesystem_delete_file (fs, "/whatever/directory", "some.file2", context)); gp_filesystem_dump (fs); printf ("*** Resetting the filesystem...\n"); CHECK (gp_filesystem_reset (fs)); gp_filesystem_dump (fs); printf ("*** Getting file list for folder '/whatever/directory'...\n"); CHECK (gp_filesystem_list_folders (fs, "/whatever/directory", list, context)); printf ("*** Getting file list for folder '/whatever/directory' " "again (cached!)...\n"); CHECK (gp_filesystem_list_folders (fs, "/whatever/directory", list, context)); printf ("*** Counting the contents...\n"); CHECK (count = gp_list_count (list)); printf ("*** Listing the contents...\n"); for (x = 0; x < count; x++) { CHECK (gp_list_get_name (list, x, &name)); printf (" %i: '%s'\n", x, name); } printf ("*** Getting folder of 'file1'...\n"); CHECK (gp_filesystem_get_folder (fs, "file1", &foldername, context)); printf ("... found in '%s'.\n", foldername); free(foldername); printf ("*** Deleting a couple of files...\n"); CHECK (gp_filesystem_delete_file (fs, "/whatever", "file5", context)); CHECK (gp_filesystem_delete_file (fs, "/whatever", "file4", context)); CHECK (gp_filesystem_delete_file (fs, "/whatever", "file3", context)); gp_filesystem_dump (fs); printf ("*** Freeing file system...\n"); CHECK (gp_filesystem_free (fs)); gp_context_unref (context); CHECK (gp_list_free(list)); #ifdef HAVE_MCHECK_H muntrace(); #endif return (0); }
static int recursive_directory(Camera *camera, const char *folder, GPContext *context, int *foundfile) { int i, ret; CameraList *list; const char *newfile; CameraFileInfo fileinfo; CameraFile *file; ret = gp_list_new (&list); if (ret < GP_OK) { printf ("Could not allocate list.\n"); return ret; } ret = gp_camera_folder_list_folders (camera, folder, list, context); if (ret < GP_OK) { printf ("Could not list folders.\n"); gp_list_free (list); return ret; } gp_list_sort (list); for (i = 0; i < gp_list_count (list); i++) { const char *newfolder; char *buf; int havefile = 0; gp_list_get_name (list, i, &newfolder); buf = malloc (strlen(folder) + 1 + strlen(newfolder) + 1); strcpy(buf, folder); if (strcmp(folder,"/")) /* avoid double / */ strcat(buf, "/"); strcat(buf, newfolder); ret = recursive_directory (camera, buf, context, &havefile); free (buf); if (ret != GP_OK) { gp_list_free (list); printf ("Failed to recursively list folders.\n"); return ret; } if (havefile) /* only look for the first directory with a file */ break; } gp_list_reset (list); ret = gp_camera_folder_list_files (camera, folder, list, context); if (ret < GP_OK) { gp_list_free (list); printf ("Could not list files.\n"); return ret; } gp_list_sort (list); if (gp_list_count (list) <= 0) { gp_list_free (list); return GP_OK; } gp_list_get_name (list, 0, &newfile); /* only entry 0 needed */ ret = gp_camera_file_get_info (camera, folder, newfile, &fileinfo, context); if (ret != GP_OK) { gp_list_free (list); printf ("Could not get file info.\n"); return ret; } /* Trigger the ptp things */ gp_file_new (&file); ret = gp_camera_file_get (camera, folder, newfile, GP_FILE_TYPE_METADATA, file, context); if ((ret != GP_OK) && (ret != GP_ERROR_NOT_SUPPORTED)) { gp_list_free (list); printf ("Could not get file metadata.\n"); return ret; } gp_file_free (file); if (foundfile) *foundfile = 1; gp_list_free (list); return GP_OK; }
int gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir, GPContext *context) { CameraLibraryIdFunc id; CameraLibraryAbilitiesFunc ab; CameraText text; int ret, x, old_count, new_count; unsigned int i, p; const char *filename; CameraList *flist; int count; lt_dlhandle lh; CHECK_NULL (list && dir); gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Using ltdl to load camera libraries from '%s'...", dir); CHECK_RESULT (gp_list_new (&flist)); ret = gp_list_reset (flist); if (ret < GP_OK) { gp_list_free (flist); return ret; } if (1) { /* a new block in which we can define a temporary variable */ foreach_data_t foreach_data = { NULL, GP_OK }; foreach_data.list = flist; lt_dlinit (); lt_dladdsearchdir (dir); ret = lt_dlforeachfile (dir, foreach_func, &foreach_data); lt_dlexit (); if (ret != 0) { gp_list_free (flist); gp_log (GP_LOG_ERROR, "gp-abilities-list", "Internal error looking for camlibs (%d)", ret); gp_context_error (context, _("Internal error looking for camlibs. " "(path names too long?)")); return (foreach_data.result!=GP_OK)?foreach_data.result:GP_ERROR; } } count = gp_list_count (flist); if (count < GP_OK) { gp_list_free (flist); return ret; } gp_log (GP_LOG_DEBUG, "gp-abilities-list", "Found %i " "camera drivers.", count); lt_dlinit (); p = gp_context_progress_start (context, count, _("Loading camera drivers from '%s'..."), dir); for (i = 0; i < count; i++) { ret = gp_list_get_name (flist, i, &filename); if (ret < GP_OK) { gp_list_free (flist); return ret; } lh = lt_dlopenext (filename); if (!lh) { gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Failed to load '%s': %s.", filename, lt_dlerror ()); continue; } /* camera_id */ id = lt_dlsym (lh, "camera_id"); if (!id) { gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Library '%s' does not seem to " "contain a camera_id function: %s", filename, lt_dlerror ()); lt_dlclose (lh); continue; } /* * Make sure the camera driver hasn't been * loaded yet. */ if (id (&text) != GP_OK) { lt_dlclose (lh); continue; } if (gp_abilities_list_lookup_id (list, text.text) >= 0) { lt_dlclose (lh); continue; } /* camera_abilities */ ab = lt_dlsym (lh, "camera_abilities"); if (!ab) { gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Library '%s' does not seem to " "contain a camera_abilities function: " "%s", filename, lt_dlerror ()); lt_dlclose (lh); continue; } old_count = gp_abilities_list_count (list); if (old_count < 0) { lt_dlclose (lh); continue; } if (ab (list) != GP_OK) { lt_dlclose (lh); continue; } lt_dlclose (lh); new_count = gp_abilities_list_count (list); if (new_count < 0) continue; /* Copy in the core-specific information */ for (x = old_count; x < new_count; x++) { strcpy (list->abilities[x].id, text.text); strcpy (list->abilities[x].library, filename); } gp_context_progress_update (context, p, i); if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) { lt_dlexit (); gp_list_free (flist); return (GP_ERROR_CANCEL); } } gp_context_progress_stop (context, p); lt_dlexit (); gp_list_free (flist); return (GP_OK); }