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; }
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); }
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; }
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); } }
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; }
static int shell_cd (Camera __unused__ *camera, const char *arg) { char folder[MAX_FOLDER_LEN]; CameraList *list; int arg_count = shell_arg_count (arg); if (!arg_count) return (GP_OK); /* shell_arg(arg, 0, arg_dir); */ if (strlen (arg) > 1023) { cli_error_print ("Folder value is too long"); return (GP_ERROR); } /* Get the new folder value */ shell_construct_path (p->folder, arg, folder, NULL); CHECK (gp_list_new (&list)); CL (gp_camera_folder_list_folders (p->camera, folder, list, p->context), list); gp_list_free (list); free (p->folder); p->folder = malloc (sizeof (char) * (strlen (folder) + 1)); if (!p->folder) return (GP_ERROR_NO_MEMORY); strcpy (p->folder, folder); printf (_("Remote directory now '%s'."), p->folder); putchar ('\n'); return (GP_OK); }
void GPhotoContext::cleanup() { if( camera_ ) { gp_camera_free( camera_ ); camera_ = NULL; } if( context_ ) { gp_context_unref( context_ ); context_ = NULL; } if( portinfoList_ ) { gp_port_info_list_free( portinfoList_ ); portinfoList_ = NULL; } if( abilitiesList_ ) { gp_abilities_list_free( abilitiesList_ ); abilitiesList_ = NULL; } if( cameras_ ) { gp_list_free( cameras_ ); cameras_ = NULL; } }
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); }
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); }
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; }
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); }
/** * 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); }
/** 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); }
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); } }
static char * shell_path_generator (const char *text, int state) { static int x; const char *slash, *name; CameraList *list; int file_count, folder_count, r, len; char folder[MAX_FOLDER_LEN], basename[MAX_FILE_LEN], *path; #if 0 printf ("shell_path_generator ('%s', %i)\n", text, state); #endif r = shell_construct_path (p->folder, text, folder, basename); if (r < 0) return (NULL); len = strlen (basename); #if 0 printf ("Searching for '%s' in '%s'...\n", basename, folder); #endif /* If this is a new path to complete, reinitialize */ if (!state) x = 0; r = gp_list_new (&list); if (r < 0) return (NULL); /* First search for matching file */ r = gp_camera_folder_list_files (p->camera, folder, list, p->context); if (r < 0) { gp_list_free (list); return (NULL); } file_count = gp_list_count (list); if (file_count < 0) { gp_list_free (list); return (NULL); } if (x < file_count) { for (; x < file_count; x++) { r = gp_list_get_name (list, x, &name); if (r < 0) return (NULL); if (!strncmp (name, basename, len)) { x++; slash = strrchr (text, '/'); if (!slash) { path = malloc (strlen (name) + 2); if (!path) return (NULL); strcpy (path, name); strcat (path, " "); } else { path = malloc (slash - text + 1 + strlen (name) + 2); if (!path) return (NULL); memset (path, 0, slash - text + 1 + strlen (name) + 2); strncpy (path, text, slash - text); strcat (path, "/"); strcat (path, name); strcat (path, " "); } return (path); } } } /* Ok, we listed all matching files. Now, list matching folders. */ r = gp_camera_folder_list_folders (p->camera, folder, list, p->context); if (r < 0) { gp_list_free (list); return (NULL); } folder_count = gp_list_count (list); if (folder_count < 0) { gp_list_free (list); return (NULL); } if (x - file_count < folder_count) { for (; x - file_count < folder_count; x++) { r = gp_list_get_name (list, x - file_count, &name); if (r < 0) { gp_list_free (list); return (NULL); } if (!strncmp (name, basename, len)) { x++; slash = strrchr (text, '/'); if (!slash) { path = malloc (strlen (name) + 2); if (!path) return (NULL); strcpy (path, name); strcat (path, "/"); } else { path = malloc (slash - text + 1 + strlen (name) + 2); if (!path) return (NULL); memset (path, 0, slash - text + 1 + strlen (name) + 2); strncpy (path, text, slash - text); strcat (path, "/"); strcat (path, name); strcat (path, "/"); } gp_list_free (list); return (path); } } gp_list_free (list); return (NULL); } gp_list_free (list); return (NULL); }
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; }
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); }
/** * Initiate a connection to the \c camera. * * @param camera a #Camera * @param context a #GPContext * @return a gphoto2 error code * * Before calling this function, the * \c camera should be set up using #gp_camera_set_port_path or * #gp_camera_set_port_name and #gp_camera_set_abilities. If that has been * omitted, gphoto2 tries to autodetect any cameras and chooses the first one * if any cameras are found. It is generally a good idea to call * #gp_camera_exit after transactions have been completed in order to give * other applications the chance to access the camera, too. * */ int gp_camera_init (Camera *camera, GPContext *context) { CameraAbilities a; const char *model, *port; CameraLibraryInitFunc init_func; int result; gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Initializing camera..."); CHECK_NULL (camera); /* * Reset the exit_requested flag. If this flag is set, * gp_camera_exit will be called as soon as the camera is no * longer in use (used flag). */ camera->pc->exit_requested = 0; /* * If the model hasn't been indicated, try to * figure it out (USB only). Beware of "Directory Browse". */ if (strcasecmp (camera->pc->a.model, "Directory Browse") && !strcmp ("", camera->pc->a.model)) { CameraAbilitiesList *al; GPPortInfo pinfo; GPPortInfoList *il; int m, p; GPPortInfo info; CameraList *list; result = gp_list_new (&list); if (result < GP_OK) return result; result = gp_port_get_info (camera->port, &pinfo); if (result < GP_OK) return result; gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.type %d", pinfo.type); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.path %s", pinfo.path); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.name %s", pinfo.name); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Neither " "port nor model set. Trying auto-detection..."); /* Call auto-detect and choose the first camera */ gp_abilities_list_new (&al); gp_abilities_list_load (al, context); gp_port_info_list_new (&il); gp_port_info_list_load (il); gp_abilities_list_detect (al, il, list, context); if (!gp_list_count (list)) { gp_abilities_list_free (al); gp_port_info_list_free (il); gp_context_error (context, _("Could not detect any camera")); gp_list_free (list); return (GP_ERROR_MODEL_NOT_FOUND); } p = 0; /* if the port was set before, then use that entry. but not if it is "usb:" */ if ( (pinfo.type == GP_PORT_USB) && strlen(pinfo.path) && strcmp(pinfo.path,"usb:") ) { for (p = gp_list_count (list);p--;) { const char *xp; gp_list_get_value (list, p, &xp); if (!strcmp (xp, pinfo.path)) break; } if (p<0) { gp_context_error (context, _("Could not detect any camera at port %s"), pinfo.path); return (GP_ERROR_FILE_NOT_FOUND); } } gp_list_get_name (list, p, &model); m = gp_abilities_list_lookup_model (al, model); gp_abilities_list_get_abilities (al, m, &a); gp_abilities_list_free (al); CRSL (camera, gp_camera_set_abilities (camera, a), context, list); CRSL (camera, gp_list_get_value (list, p, &port), context, list); p = gp_port_info_list_lookup_path (il, port); gp_port_info_list_get_info (il, p, &info); gp_port_info_list_free (il); CRSL (camera, gp_camera_set_port_info (camera, info), context, list); gp_list_free (list); } if (strcasecmp (camera->pc->a.model, "Directory Browse")) { switch (camera->port->type) { case GP_PORT_NONE: gp_context_error (context, _("You have to set the " "port prior to initialization of the camera.")); return (GP_ERROR_UNKNOWN_PORT); case GP_PORT_USB: if (gp_port_usb_find_device (camera->port, camera->pc->a.usb_vendor, camera->pc->a.usb_product) != GP_OK) { CRS (camera, gp_port_usb_find_device_by_class (camera->port, camera->pc->a.usb_class, camera->pc->a.usb_subclass, camera->pc->a.usb_protocol), context); } break; default: break; } } /* Load the library. */ gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Loading '%s'...", camera->pc->a.library); lt_dlinit (); camera->pc->lh = lt_dlopenext (camera->pc->a.library); if (!camera->pc->lh) { gp_context_error (context, _("Could not load required " "camera driver '%s' (%s)."), camera->pc->a.library, lt_dlerror ()); lt_dlexit (); return (GP_ERROR_LIBRARY); } /* Initialize the camera */ init_func = lt_dlsym (camera->pc->lh, "camera_init"); if (!init_func) { lt_dlclose (camera->pc->lh); lt_dlexit (); camera->pc->lh = NULL; gp_context_error (context, _("Camera driver '%s' is " "missing the 'camera_init' function."), camera->pc->a.library); return (GP_ERROR_LIBRARY); } if (strcasecmp (camera->pc->a.model, "Directory Browse")) { result = gp_port_open (camera->port); if (result < 0) { lt_dlclose (camera->pc->lh); lt_dlexit (); camera->pc->lh = NULL; return (result); } } result = init_func (camera, context); if (result < 0) { gp_port_close (camera->port); lt_dlclose (camera->pc->lh); lt_dlexit (); camera->pc->lh = NULL; memset (camera->functions, 0, sizeof (CameraFunctions)); return (result); } /* We don't care if that goes wrong */ #ifdef HAVE_MULTI gp_port_close (camera->port); #endif return (GP_OK); }
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); }
int GPCamera::autoDetect(QString& model, QString& port) { #ifdef HAVE_GPHOTO2 CameraList* camList = 0; CameraAbilitiesList* abilList = 0; GPPortInfoList* infoList = 0; const char* camModel_ = 0, *camPort_ = 0; GPContext* context = 0; context = gp_context_new(); gp_list_new(&camList); gp_abilities_list_new(&abilList); gp_abilities_list_load(abilList, context); gp_port_info_list_new(&infoList); gp_port_info_list_load(infoList); gp_abilities_list_detect(abilList, infoList, camList, context); gp_abilities_list_free(abilList); gp_port_info_list_free(infoList); gp_context_unref(context); int count = gp_list_count(camList); if (count <= 0) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!"; printGphotoErrorDescription(count); gp_list_free(camList); return -1; } camModel_ = 0; camPort_ = 0; for (int i = 0; i < count; i++) { if (gp_list_get_name(camList, i, &camModel_) != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!"; gp_list_free(camList); return -1; } if (gp_list_get_value(camList, i, &camPort_) != GP_OK) { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!"; gp_list_free(camList); return -1; } if (camModel_ && camPort_) { model = QString::fromLatin1(camModel_); port = QString::fromLatin1(camPort_); gp_list_free(camList); return 0; } } qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!"; gp_list_free(camList); #else Q_UNUSED(model); Q_UNUSED(port); #endif /* HAVE_GPHOTO2 */ return -1; }
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 ); }
bool GPCamera::findConnectedUsbCamera(int vendorId, int productId, QString& model, QString& port) { #ifdef HAVE_GPHOTO2 CameraAbilitiesList* abilList = 0; GPPortInfoList* list = 0; GPContext* context = 0; CameraList* camList = 0; bool success = false; // get name and port of detected camera const char* model_str = 0; const char* port_str = 0; context = gp_context_new(); // get list of all ports gp_port_info_list_new(&list); gp_port_info_list_load(list); gp_abilities_list_new(&abilList); // get list of all supported cameras gp_abilities_list_load(abilList, context); // autodetect all cameras, then match the list to the passed in USB ids gp_list_new (&camList); gp_abilities_list_detect(abilList, list, camList, context); gp_context_unref(context); int count = gp_list_count(camList); int cnt = 0; for (int i = 0 ; i < count ; i++) { const char* xmodel = 0; gp_list_get_name(camList, i, &xmodel); int model = gp_abilities_list_lookup_model (abilList, xmodel); CameraAbilities ab; gp_abilities_list_get_abilities(abilList, model, &ab); if (ab.port != GP_PORT_USB) continue; /* KDE provides us USB Vendor and Product, but we might just * have covered this via a class match. Check class matched * cameras also for matchingo USB vendor/product id */ if (ab.usb_vendor == 0) { int ret; GPPortInfo info; const char* xport = 0; GPPort* gpport = 0; /* get the port path so we only look at this bus position */ gp_list_get_value(camList, i, &xport); ret = gp_port_info_list_lookup_path (list, xport); if (ret < GP_OK) /* should not happen */ continue; /* get the lowlevel port info for the path */ gp_port_info_list_get_info(list, ret, &info); /* open lowlevel driver interface briefly to search */ gp_port_new(&gpport); gp_port_set_info(gpport, info); /* And now call into the lowlevel usb driver to see if the bus position * has that specific vendor/product id */ if (gp_port_usb_find_device(gpport, vendorId, productId) == GP_OK) { ab.usb_vendor = vendorId; ab.usb_product = productId; } gp_port_free (gpport); } if (ab.usb_vendor != vendorId) continue; if (ab.usb_product != productId) continue; /* keep it, and continue iterating, in case we find another one */ gp_list_get_name (camList, i, &model_str); gp_list_get_value(camList, i, &port_str); cnt++; } gp_port_info_list_free(list); gp_abilities_list_free(abilList); if (cnt > 0) { if (cnt > 1) { qCWarning(DIGIKAM_IMPORTUI_LOG) << "More than one camera detected on port " << port << ". Due to restrictions in the GPhoto2 API, " << "only the first camera is used."; } model = QString::fromLatin1(model_str); port = QString::fromLatin1(port_str); success = true; } else { qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get information for the listed camera"; } gp_list_free(camList); return success; #else Q_UNUSED(vendorId); Q_UNUSED(productId); Q_UNUSED(model); Q_UNUSED(port); return false; #endif /* HAVE_GPHOTO2 */ }
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; }
static GnomeVFSResult do_get_file_info ( GnomeVFSMethod* method, GnomeVFSURI* uri, GnomeVFSFileInfo* info, GnomeVFSFileInfoOptions options, GnomeVFSContext* context) { GnomeVFSResult result; GnomeVFSURI *parent; Camera *camera; CameraFileInfo camera_info; CameraList *list; const gchar *path, *name; char *basename; guint i; int count; printf ("ENTER: do_get_file_info (%s)\n", camera_uri_get_path (uri)); G_LOCK (cameras); /* Is this root? */ if (!gnome_vfs_uri_has_parent (uri)) { info->name = g_strdup ("/"); info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE | GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; info->type = GNOME_VFS_FILE_TYPE_DIRECTORY; info->mime_type = g_strdup ("x-directory/normal"); G_UNLOCK (cameras); return (GNOME_VFS_OK); } printf ("Getting camera (do_get_file_info)...\n"); result = get_camera (uri, &camera); if (result != GNOME_VFS_OK) { G_UNLOCK (cameras); return (result); } result = GNOME_VFS_RESULT (gp_list_new (&list)); if (result != GNOME_VFS_OK) { unref_camera (camera); G_UNLOCK (cameras); return (result); } /* * We cannot use get_basename here because of potential trailing * slashes. */ basename = gnome_vfs_uri_extract_short_name (uri); parent = camera_uri_get_parent (uri); path = camera_uri_get_path (parent); result = GNOME_VFS_RESULT (gp_camera_folder_list_folders (camera, path, list, NULL)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } count = gp_list_count (list); if (count < 0) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (GNOME_VFS_RESULT (count)); } for (i = 0; i < count; i++) { result = GNOME_VFS_RESULT (gp_list_get_name (list, i, &name)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } if (!strcmp (name, basename)) { info->name = g_strdup (basename); info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE | GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; info->type = GNOME_VFS_FILE_TYPE_DIRECTORY; info->mime_type = g_strdup ("x-directory/normal"); gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); printf ("Found folder!\n"); return (GNOME_VFS_OK); } } result = GNOME_VFS_RESULT (gp_camera_folder_list_files (camera, path, list, NULL)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } count = gp_list_count (list); if (count < 0) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (GNOME_VFS_RESULT (count)); } for (i = 0; i < count; i++) { result = GNOME_VFS_RESULT (gp_list_get_name (list, i, &name)); if (result != GNOME_VFS_OK) { gnome_vfs_uri_unref (parent); unref_camera (camera); gp_list_free (list); g_free (basename); G_UNLOCK (cameras); return (result); } if (!strcmp (name, basename)) { result = GNOME_VFS_RESULT (gp_camera_file_get_info ( camera, path, basename, &camera_info, NULL)); g_free (basename); unref_camera (camera); gp_list_free (list); if (result != GNOME_VFS_OK) { G_UNLOCK (cameras); return (result); } get_info_from_camera_info (&camera_info, FALSE, info); gnome_vfs_uri_unref (parent); G_UNLOCK (cameras); printf ("Found file!\n"); return (GNOME_VFS_OK); } } gnome_vfs_uri_unref (parent); g_free (basename); unref_camera (camera); gp_list_free (list); G_UNLOCK (cameras); return (GNOME_VFS_ERROR_NOT_FOUND); }