Пример #1
0
void UploadDialog::createIpodAlbum()
{
    QString helper;

#if KIPI_PLUGIN
    ImageCollection album = iface()->currentAlbum();
    if( album.isValid() )
        helper = album.name();
#endif

    bool ok = false;
    QString newAlbum = KInputDialog::getText( i18n("New iPod Photo Album"),
                                              i18n("Create a new album:"),
                                              helper, &ok, this );
    if( ok )
    {
        kDebug() << "creating album " << newAlbum ;

        Itdb_PhotoAlbum* photoAlbum = itdb_photodb_photoalbum_create( m_itdb, QFile::encodeName( newAlbum ), -1/*end*/ );
        // add the new album to the list view
        new IpodAlbumItem( m_ipodAlbumList, photoAlbum );
        m_ipodAlbumList->clearSelection();

        // commit the changes to the iPod
        GError* err = 0;
        itdb_photodb_write( m_itdb, &err );
    }
}
Пример #2
0
/**
 * itdb_photodb_create:
 * @mountpoint: mountpoint or NULL.
 *
 * Creates a new Itdb_PhotoDB. If mountpoint is NULL, you will have to
 * set it manually later by calling itdb_device_set_mountpoint().
 *
 * Return value: a newly created Itdb_PhotoDB to be freed with
 * itdb_photodb_free() when it's no longer needed. The Photo Library
 * Album is created automatically.
 **/
Itdb_PhotoDB *itdb_photodb_create (const gchar *mountpoint)
{
    Itdb_PhotoDB *photodb = itdb_photodb_new ();
    Itdb_PhotoAlbum *album;

    album = itdb_photodb_photoalbum_create (photodb, _("Photo Library"), -1);
    album->album_type = 1; /* Photo Library */

    if (mountpoint)
    {
	itdb_device_set_mountpoint (photodb->device, mountpoint);
    }

    return photodb;
}
Пример #3
0
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;
}
Пример #4
0
/* called by itdb_photodb_add_photo() and
   itdb_photodb_add_photo_from_data() */
static Itdb_Artwork *itdb_photodb_add_photo_internal (Itdb_PhotoDB *db,
						      const gchar *filename,
						      const guchar *image_data,
						      gsize image_data_len,
						      gpointer pixbuf,
						      gint position,
						      gint rotation,
						      GError **error)
{
#ifdef HAVE_GDKPIXBUF
    gboolean result;
    Itdb_Artwork *artwork;
    Itdb_PhotoAlbum *album;
    const Itdb_ArtworkFormat *format;

    g_return_val_if_fail (db, NULL);
    g_return_val_if_fail (db->device, NULL);
    g_return_val_if_fail (filename || image_data, NULL);
    g_return_val_if_fail (!(image_data && (image_data_len == 0)), NULL);
    g_return_val_if_fail (!(pixbuf && (!GDK_IS_PIXBUF (pixbuf))), NULL);

    if (!ipod_supports_photos (db->device))
    {
	const Itdb_IpodInfo *ipodinfo = itdb_device_get_ipod_info (db->device);
	const gchar *model, *generation;

	if (!ipodinfo)
	{
	    g_set_error (error, 0, -1,
			 _("You need to specify the iPod model used before photos can be added."));
	    return NULL;
	    /* For information: The model is set by calling the rather
	       unintuitive function itdb_device_set_sysinfo as
	       follows:

	       itdb_device_set_sysinfo (db->device, "ModelNumStr", model);

	       For example, "MA450" would stand for an 80 GB 6th
	       generation iPod Video. See itdb_device.c for a list of
	       supported models.

	       This information will be written to the iPod when the
	       PhotoDB is saved (itdb_device_write_sysinfo() is called).
	    */
	}

	model = itdb_info_get_ipod_model_name_string (ipodinfo->ipod_model);
	generation = itdb_info_get_ipod_generation_string (ipodinfo->ipod_generation);
	g_return_val_if_fail (model && generation, NULL);
	g_set_error (error, 0, -1,
		     _("Your iPod does not seem to support photos. Maybe you need to specify the correct iPod model number? It is currently set to 'x%s' (%s/%s)."),
		     ipodinfo->model_number, generation, model);
	return NULL;
    }

    /* check if filename is valid */
    if (filename)
    {
	struct stat statbuf;
	if (g_stat  (filename, &statbuf) != 0)
	{
	    g_set_error (error, 0, -1,
			 _("Could not access file '%s'. Photo not added."),
			 filename);
	    return NULL;
	}
    }

    artwork = itdb_artwork_new ();

    /* Add a thumbnail for every supported format */
    format = itdb_device_get_artwork_formats (db->device);
    g_return_val_if_fail (format, NULL);

    for(result = TRUE; format->type != -1 && result == TRUE; format++)
    {
	if((format->type == ITDB_THUMB_COVER_SMALL) ||
	   (format->type == ITDB_THUMB_COVER_LARGE))
	    continue;
	if (filename)
	{
	    result = itdb_artwork_add_thumbnail (artwork,
						 format->type,
						 filename,
						 rotation,
						 error);
	}
	if (image_data)
	{
	    result = itdb_artwork_add_thumbnail_from_data (artwork,
							   format->type,
							   image_data,
							   image_data_len,
							   rotation,
							   error);
	}
	if (pixbuf) 
	{
	  result = itdb_artwork_add_thumbnail_from_pixbuf (artwork,
							   format->type, 
							   pixbuf,
							   rotation,
							   error);
	}
    }

    if (result != TRUE)
    {
	itdb_artwork_free (artwork);
	g_set_error (error, 0, -1,
		     _("Unexpected error in itdb_photodb_add_photo_internal() while adding photo, please report."));
	return NULL;
    }

    /* Add artwork to the list of photos */
    /* (it would be sufficient to append to the end) */
    db->photos = g_list_insert (db->photos, artwork, position);

    /* Add artwork to the first album */
    album = itdb_photodb_photoalbum_by_name (db, NULL);
    if (!album)
    {
	album = itdb_photodb_photoalbum_create (db, _("Photo Library"), -1);
	album->album_type = 1; /* Photo Library */
    }
    itdb_photodb_photoalbum_add_photo (db, album, artwork, position);

    return artwork;
#else
    g_set_error (error, 0, -1,
		 _("Library compiled without gdk-pixbuf support. Picture support is disabled."));
    return NULL;
#endif
}