示例#1
0
/**
 * Retrieves information about a file.
 *
 * @param camera a #Camera
 * @param folder a folder
 * @param file the name of the file
 * @param info
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 **/
int
gp_camera_file_get_info (Camera *camera, const char *folder, 
			 const char *file, CameraFileInfo *info,
			 GPContext *context)
{
	int result = GP_OK;
	const char *mime_type;
	const char *data;
	/* long int size; */
	CameraFile *cfile;

	gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Getting file info for '%s' "
		"in '%s'...", file, folder);

	CHECK_NULL (camera && folder && file && info);
	CHECK_INIT (camera, context);

	memset (info, 0, sizeof (CameraFileInfo));

	/* Check first if the camera driver supports the filesystem */
	CHECK_OPEN (camera, context);
	result = gp_filesystem_get_info (camera->fs, folder, file, info,
					 context);
	CHECK_CLOSE (camera, context);
	if (result != GP_ERROR_NOT_SUPPORTED) {
		CAMERA_UNUSED (camera, context);
		return (result);
	}

	/*
	 * The CameraFilesystem doesn't support file info. We simply get
	 * the preview and the file and look for ourselves...
	 */

	/* It takes too long to get the file */
	info->file.fields = GP_FILE_INFO_NONE;

	/* Get the preview */
	info->preview.fields = GP_FILE_INFO_NONE;
	CRS (camera, gp_file_new (&cfile), context);
	if (gp_camera_file_get (camera, folder, file, GP_FILE_TYPE_PREVIEW,
						cfile, context) == GP_OK) {
		unsigned long size;
		info->preview.fields |= GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE;
		gp_file_get_data_and_size (cfile, &data, &size);
		info->preview.size = size;
		gp_file_get_mime_type (cfile, &mime_type);
		strncpy (info->preview.type, mime_type,
			 sizeof (info->preview.type));
	}
	gp_file_unref (cfile);

	/* We don't trust the camera libraries */
	info->file.fields |= GP_FILE_INFO_NAME;
	strncpy (info->file.name, file, sizeof (info->file.name));
	info->preview.fields &= ~GP_FILE_INFO_NAME;

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
示例#2
0
static int
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
               CameraFileType type, CameraFile *file, void *data,
               GPContext *context)
{
        Camera *camera = data;
        unsigned long image_id;
        char image_id_string[] = {0, 0, 0, 0, 0, 0, 0};
        unsigned int size;
        CameraFileInfo info;
        int r;
	KncCamRes cr;
	KncCntrlRes cntrl_res = KNC_CNTRL_OK;

        if (strlen (filename) != 11) return (GP_ERROR_FILE_NOT_FOUND);
        if (strcmp (folder, "/")) return (GP_ERROR_DIRECTORY_NOT_FOUND);

        /* Check if we can get the image id from the filename. */
        strncpy (image_id_string, filename, 6);
        image_id = atol (image_id_string);

        /* Get information about the image */
        C (gp_filesystem_get_info (camera->fs, folder,
                                        filename, &info, context));

        /*
         * Remove the timeout, get the image and start the timeout
         * afterwards.
         */
        gp_camera_stop_timeout (camera, camera->pl->timeout);
	knc_cntrl_set_func_data (camera->pl->c, data_func, file);
        switch (type) {
        case GP_FILE_TYPE_PREVIEW:
                size = 2048;
                cntrl_res = knc_get_image (camera->pl->c, &cr,
                        image_id, KNC_SOURCE_CARD, KNC_IMAGE_THUMB);
                break;
        case GP_FILE_TYPE_NORMAL:
                size = info.file.size;
                cntrl_res = knc_get_image (camera->pl->c, &cr,
                        image_id, KNC_SOURCE_CARD, KNC_IMAGE_EXIF);
                break;
        default:
                r = GP_ERROR_NOT_SUPPORTED;
        }
        camera->pl->timeout = gp_camera_start_timeout (camera, PING_TIMEOUT,
                                                       timeout_func);
        CR (cntrl_res, context);
	CCR (cr, context);

        C (gp_file_set_mime_type (file, GP_MIME_JPEG));

        return (GP_OK);
}
示例#3
0
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);
}