Exemple #1
0
/**
 * itdb_photodb_remove_photo:
 * @db: the #Itdb_PhotoDB to remove the photo from
 * @album: the album to remove the photo from. If album is NULL, then
 * it will first be removed from all photoalbums and then from the
 * photo database as well.
 * @photo: #Itdb_Artwork (photo) to remove.
 *
 * Remove photo. If @album is not the first photoalbum, the photo will
 * be removed from that album only. If @album is NULL or the first
 * photoalbum (Photo Library), the photo will be removed from all
 * albums and the #Itdb_PhotoDB.
 *
 * @photo will be freed and can no longer be used if removed from the
 * first photoalbum.
 */
void itdb_photodb_remove_photo (Itdb_PhotoDB *db,
				Itdb_PhotoAlbum *album,
				Itdb_Artwork *photo)
{
    GList *it;

    g_return_if_fail (db);

    /* If album==NULL, or album is the master album, remove from all
     * albums */
    if ((album == NULL) || (album == g_list_nth_data (db->photoalbums, 0)))
    {
        /* Remove the photo from any albums containing it */
        for (it = db->photoalbums; it != NULL; it = it->next)
	{
            Itdb_PhotoAlbum *_album = it->data;
	    while (g_list_find (_album->members, photo))
	    {
		_album->members = g_list_remove (_album->members, photo);
	    }
        }
        /* Remove the photo from the image list */
	db->photos = g_list_remove (db->photos, photo);
	/* Free the photo */
	itdb_artwork_free (photo);
    }
    /* If album is specified, only remove it from that album */
    else
    {
        album->members = g_list_remove (album->members, photo);
    }
}
Exemple #2
0
/**
 * itdb_track_free:
 * @track: an #Itdb_Track
 *
 * Frees the memory used by @track
 */
void itdb_track_free (Itdb_Track *track)
{
    g_return_if_fail (track);

    g_free (track->title);
    g_free (track->ipod_path);
    g_free (track->album);
    g_free (track->artist);
    g_free (track->genre);
    g_free (track->filetype);
    g_free (track->comment);
    g_free (track->category);
    g_free (track->composer);
    g_free (track->grouping);
    g_free (track->description);
    g_free (track->podcasturl);
    g_free (track->podcastrss);
    g_free (track->subtitle);
    g_free (track->tvshow);
    g_free (track->tvepisode);
    g_free (track->tvnetwork);
    g_free (track->albumartist);
    g_free (track->keywords);
    g_free (track->sort_artist);
    g_free (track->sort_title);
    g_free (track->sort_album);
    g_free (track->sort_albumartist);
    g_free (track->sort_composer);
    g_free (track->sort_tvshow);

    itdb_chapterdata_free (track->chapterdata);

    itdb_artwork_free (track->artwork);

    if (track->userdata && track->userdata_destroy)
	(*track->userdata_destroy) (track->userdata);

    g_free (track->priv);
    g_free (track);
}
Exemple #3
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
}