summaryrefslogtreecommitdiffstats
path: root/src/db-artwork-parser.c
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2006-10-29 08:43:28 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2006-10-29 08:43:28 +0000
commite6d6143818172892e9a667cca4f3a37639586605 (patch)
tree1a7a2a4aac1a5fd450f57fa3da44d6200bb58594 /src/db-artwork-parser.c
parent344770dd26661ef37f7b7974a6b42bb16fe5d8fa (diff)
downloadlibgpod-e6d6143818172892e9a667cca4f3a37639586605.tar.gz
libgpod-e6d6143818172892e9a667cca4f3a37639586605.tar.xz
libgpod-e6d6143818172892e9a667cca4f3a37639586605.zip
Major rework of picture support.
* src/db-artwork-parser.c, src/db-artwork-writer.c, src/itdb.h, src/db-itunes-parser.h: renamed 'master' to 'album_type' in MhbaHeader and Itdb_PhotoAlbum. * src/db-artwork-parser.c, src/db-artwork-writer.c, src/itdb_photoalbum.c: Itdb_Photoalbum->members are now pointers to the corresponding Itdb_Artwork instead of image_ids. * src/itdb_photoalbum.c: album_ids and image_ids are set just before writing the PhotoDB in itdb_photodb_write(). * src/itdb_photoalbum.c: new interface, basically use as follows: itdb_photodb_parse(): Read an existing PhotoDB. itdb_photodb_create(): Create a new Itdb_PhotoDB structure. The Photo Library Album is (first album) is created automatically. itdb_photodb_add_photo(), itdb_photodb_add_photo_from_data(): Add a photo to the PhotoDB (from file or from a chunk of memory). It is automatically added to the Photo Library Album (first album), which is created if it does not exist already. itdb_photodb_photoalbum_craete(): Create and add a new photoalbum. itdb_photodb_photoalbum_add_photo(): Add a photo (Itdb_Artwork) to an existing photoalbum. itdb_photodb_photoalbum_remove(): Remove an existing photoalbum. Pictures can be kept in the Photo Library or automatically removed as well. itdb_photodb_remove_photo(): Remove a photo either from a photoalbum or completely from the database. itdb_photodb_write(): Write out your PhotoDB. itdb_photodb_free(): Free all memory taken by the PhotoDB. itdb_photodb_photoalbum_by_name(): Find the first photoalbum with a given name. * src/itdb_playlist.c (itdb_playlist_add, itdb_playlist_add_track): src/itdb_track.c (itdb_track_add): simplify code by using g_list_insert(). * tests/test-photos.c: change to new interface, add new commands 'list' to list photo IDs in the database, 'remove' to remove IDs from an album or the iPod, or remove entire photoalbums from the iPod. * src/db-itunes-parser.h: added comments to _MhbaHeader definition. git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1329 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/db-artwork-parser.c')
-rw-r--r--src/db-artwork-parser.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c
index 4a848ce..51d81fa 100644
--- a/src/db-artwork-parser.c
+++ b/src/db-artwork-parser.c
@@ -79,7 +79,7 @@ static int
parse_mhia (DBParseContext *ctx, Itdb_PhotoAlbum *photo_album, GError *error)
{
MhiaHeader *mhia;
- gint image_id;
+ guint32 image_id;
mhia = db_parse_context_get_m_header (ctx, MhiaHeader, "mhia");
if (mhia == NULL) {
@@ -88,7 +88,7 @@ parse_mhia (DBParseContext *ctx, Itdb_PhotoAlbum *photo_album, GError *error)
dump_mhia (mhia);
image_id = get_gint32 (mhia->image_id, ctx->byte_order);
photo_album->members = g_list_append (photo_album->members,
- GINT_TO_POINTER(image_id));
+ GUINT_TO_POINTER(image_id));
db_parse_context_set_total_len (ctx,
get_gint32_db (ctx->db, mhia->total_len));
return 0;
@@ -402,7 +402,7 @@ parse_mhba (DBParseContext *ctx, GError *error)
photo_album = g_new0 (Itdb_PhotoAlbum, 1);
photo_album->num_images = get_gint32( mhba->num_mhias, ctx->byte_order);
photo_album->album_id = get_gint32( mhba->playlist_id, ctx->byte_order);
- photo_album->master = get_gint32( mhba->master, ctx->byte_order);
+ photo_album->album_type = get_gint32( mhba->album_type, ctx->byte_order);
photo_album->prev_album_id = get_gint32( mhba->prev_playlist_id, ctx->byte_order);
cur_offset = ctx->header_len;
@@ -766,6 +766,9 @@ ipod_parse_photo_db (Itdb_PhotoDB *photodb)
char *filename;
Itdb_DB db;
+ GList *gl;
+ GHashTable *hash;
+
db.db.photodb = photodb;
db.db_type = DB_TYPE_PHOTO;
@@ -784,6 +787,35 @@ ipod_parse_photo_db (Itdb_PhotoDB *photodb)
parse_mhfd (ctx, NULL);
db_parse_context_destroy (ctx, TRUE);
+ /* Now we need to replace references to artwork_ids in the
+ * photo albums with references to the actual artwork
+ * structure. Since we cannot guarantee that the list with the
+ * photos is read before the album list, we cannot safely do
+ * this at the time of reading the ids. */
+
+ /* Create a hash for faster lookup */
+ hash = g_hash_table_new (g_int_hash, g_int_equal);
+ for (gl=photodb->photos; gl; gl=gl->next)
+ {
+ Itdb_Artwork *photo = gl->data;
+ g_return_val_if_fail (photo, -1);
+ g_hash_table_insert (hash, &photo->id, photo);
+/* printf ("id: %d, photo: %p\n", photo->id, photo);*/
+ }
+ for (gl=photodb->photoalbums; gl; gl=gl->next)
+ {
+ GList *glp;
+ Itdb_PhotoAlbum *album = gl->data;
+ g_return_val_if_fail (album, -1);
+ for (glp=album->members; glp; glp=glp->next)
+ {
+ guint image_id = GPOINTER_TO_UINT (glp->data);
+ Itdb_Artwork *photo = g_hash_table_lookup (hash, &image_id);
+/* printf ("id: %d, photo: %p\n", image_id, photo);*/
+ glp->data = photo;
+ }
+ }
+ g_hash_table_destroy (hash);
return 0;
}