コード例 #1
0
ファイル: itdb_photoalbum.c プロジェクト: alan707/senuti
/**
 * itdb_photodb_parse:
 * @mp: mountpoint of the iPod
 * @error: will contain the error description when an error occured.
 *
 * Parses the photo database of an iPod mounted at @mp.
 *
 * Return value: the imported PhotoDB or NULL in case of an error.
 **/
Itdb_PhotoDB *itdb_photodb_parse (const gchar *mp, GError **error)
{
    gchar *photos_dir;
    Itdb_PhotoDB *photodb = NULL;

    photos_dir = itdb_get_photos_dir (mp);

    if (!photos_dir)
    {
	error_no_photos_dir (mp, error);
	return NULL;
    }
    g_free (photos_dir);

    photodb = itdb_photodb_new ();
    itdb_device_set_mountpoint (photodb->device, mp);
    ipod_parse_photo_db (photodb);

    /* if photodb is empty, create a valid photodb including the main
       Photo Library album */
    if (!photodb->photos && !photodb->photoalbums)
    {
	itdb_photodb_free (photodb);
	photodb = itdb_photodb_create (mp);
    }

    return photodb;
}
コード例 #2
0
ファイル: test-photos.c プロジェクト: Silvirus/libgpod
static int do_add (int argc, char **argv)
{
    GError *error = NULL;
    Itdb_PhotoAlbum *album = NULL;
    Itdb_PhotoDB *db;
    gint i; 

    if (argc < 4)
    {
	g_print (_("Insufficient number of command line arguments.\n"));
	usage (argc, argv);
	return 1;
    }

    db = itdb_photodb_parse (argv[2], &error);
    if (db == NULL)
    {
	if (error)
	{
	    g_print (_("Error reading iPod photo database (%s).\nWill attempt to create a new database.\n"), error->message);
	    g_error_free (error);
	    error = NULL;
	}
	else
	{
	    g_print (_("Error reading iPod photo database, will attempt to create a new database\n"));
	}
	db = itdb_photodb_create (argv[2]);
    }

    /* Find or create specified photoalbum */
    if (strcmp (argv[3], "NULL") != 0)
    {
	album = itdb_photodb_photoalbum_by_name (db, argv[3]);
	if (!album)
	{
	    album = itdb_photodb_photoalbum_create (db, argv[3], -1);
	}
    }

    for (i=4; i<argc; ++i)
    {
	Itdb_Artwork *photo;
	
	photo = itdb_photodb_add_photo (db, argv[i],
					-1, GDK_PIXBUF_ROTATE_NONE, &error);
	if (photo == NULL)
	{
	    if (error)
	    {
		g_print (_("Error adding photo (%s) to photo database: %s\n"),
			 argv[i], error->message);
		g_error_free (error);
		error = NULL;
	    }
	}
	else
	{
	    if (album)
	    {
		itdb_photodb_photoalbum_add_photo (db, album, photo, -1);
	    }
	}
    }

    itdb_photodb_write (db, NULL);
    itdb_photodb_free (db);
    return 0;
}