Example #1
0
bool UploadDialog::deleteIpodPhoto(IpodPhotoItem* const photo) const
{
    if( !photo )
        return false;

    IpodAlbumItem* album = static_cast<IpodAlbumItem*>( photo->parent() );

    if( !album )
        return false;

    Itdb_Artwork* artwork = photo->artwork();

    if( !artwork )
    {
        kDebug() << "Could not find photo artwork with id: " << photo->text(0) ;
        return false;
    }

    Itdb_PhotoAlbum* photo_album = album->photoAlbum();
    itdb_photodb_remove_photo( m_itdb, photo_album, artwork );

    // if we remove from the library, remove from all sub albums too
    if( photo_album->album_type == 0x01 ) // master album
    {
        for( int i = 1; // skip library
             i < m_ipodAlbumList->topLevelItemCount(); ++ i )
        {
            QTreeWidgetItem* albumItem = m_ipodAlbumList->topLevelItem( i );

            for( int j = 0; j < albumItem->childCount(); ++j )
            {
                QTreeWidgetItem *photoItem = albumItem->child( j );

                if( photoItem->text(0) == photo->text(0) ) // FIXME
                {
                    kDebug() << "removing reference to photo from album " << albumItem->text(0) ;
                    delete photoItem;
                    break; // Items can't be duplicated in the same album
                }
            }
        }
    }
    return true;
}
Example #2
0
/**
 * itdb_photodb_photoalbum_remove:
 * @db: the #Itdb_PhotoDB to apply changes to
 * @album: the album to be removed from the database
 * @remove_pics: TRUE to remove pics in that album permanently from
 * the database.
 *
 * Remove @album from the Photo Database. If remove_pics is TRUE,
 * remove all photos contained in @album from the Photo Database.
 *
 * Memory used by the removed album will be freed and the album cannot
 * be accessed any more.
 **/
void itdb_photodb_photoalbum_remove (Itdb_PhotoDB *db,
				     Itdb_PhotoAlbum *album,
				     gboolean remove_pics)
{
        GList *it;

        g_return_if_fail (db);
        g_return_if_fail (album);

        /* if remove_pics, iterate over the photos within that album
	 * and remove them from the database */
        if (remove_pics)
	{
            for (it = album->members; it != NULL; it = it->next )
	    {
                Itdb_Artwork *photo = it->data;
                itdb_photodb_remove_photo (db, NULL, photo);
            }
        }
        db->photoalbums = g_list_remove (db->photoalbums, album);
	itdb_photodb_photoalbum_free (album);
}
Example #3
0
static int do_remove (int argc, char **argv)
{
    GError *error = NULL;
    Itdb_PhotoDB *db;
    Itdb_PhotoAlbum *album = NULL;

    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).\n"),
		     error->message);
	    g_error_free (error);
	    error = NULL;
	}
	else
	{
	    g_print (_("Error reading iPod photo database.\n"));
	}
	return 1;
    }

    /* Find specified photoalbum */
    if (strcmp (argv[3], "NULL") != 0)
    {
	album = itdb_photodb_photoalbum_by_name (db, argv[3]);
	if (!album)
	{
	    g_print (_("Specified album '%s' not found. Aborting.\n"),
		     argv[3]);
	    itdb_photodb_free (db);
	    return 1;
	}
    }

    if (argc == 4)
    {
	/* Remove photoalbum altogether, but preserve pics */
	if (album == NULL)
	{
	    g_print (_("Cannot remove Photo Library playlist. Aborting.\n"));
	    itdb_photodb_free (db);
	    return 1;
	}
	itdb_photodb_photoalbum_remove (db, album, FALSE);
    }
    else
    {
	/* Remove specified pictures */
	int i;
	for (i=4; i<argc; ++i)
	{
	    Itdb_Artwork *photo;
	    guint32 id;

	    id = g_strtod (argv[i], NULL);

	    photo = get_photo_by_id (db, id);

	    if (photo == NULL)
	    {
		g_print (_("Warning: could not find photo with ID <%d>. Skipping...\n"),
			 id);
	    }
	    else
	    {
		itdb_photodb_remove_photo (db, album, photo);
	    }
	}
    }

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