diff options
author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-06-01 15:45:28 +0000 |
---|---|---|
committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-06-01 15:45:28 +0000 |
commit | 4b4d3bf8d9f1fbe1d15e260a08fda2c347eb4d52 (patch) | |
tree | 357ea03987d9101f0cadb57d1906d4bebae99d36 /src | |
parent | 821efbba91524de002c812c2b43a9ef21c3a912e (diff) | |
download | libgpod-4b4d3bf8d9f1fbe1d15e260a08fda2c347eb4d52.tar.gz libgpod-4b4d3bf8d9f1fbe1d15e260a08fda2c347eb4d52.tar.xz libgpod-4b4d3bf8d9f1fbe1d15e260a08fda2c347eb4d52.zip |
* src/itdb.h:
src/itdb_private.h:
moved Itdb_DB to private part.
* src/itdb.h:
src/itdb_private.h:
src/itdb_itunesdb:
New: db_get_itunesdb(), db_get_photodb()
* src/db-artwork-parser.c
src/db-artwork-writer.c
src/db-image-parser.c
src/db-image-parser.h
src/db-parse-context.c
src/db-parse-context.h
src/itdb_endianness.h
src/itdb_itunesdb.c
src/ithumb-writer.c:
Remove all direct access to Itdb_DB->db. enum
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1296 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src')
-rw-r--r-- | src/db-artwork-parser.c | 32 | ||||
-rw-r--r-- | src/db-artwork-writer.c | 44 | ||||
-rw-r--r-- | src/db-image-parser.c | 10 | ||||
-rw-r--r-- | src/db-image-parser.h | 1 | ||||
-rw-r--r-- | src/db-parse-context.c | 11 | ||||
-rw-r--r-- | src/db-parse-context.h | 2 | ||||
-rw-r--r-- | src/itdb.h | 18 | ||||
-rw-r--r-- | src/itdb_endianness.h | 15 | ||||
-rw-r--r-- | src/itdb_itunesdb.c | 87 | ||||
-rw-r--r-- | src/itdb_private.h | 22 | ||||
-rw-r--r-- | src/ithumb-writer.c | 25 |
11 files changed, 154 insertions, 113 deletions
diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c index 52de373..b5d7fde 100644 --- a/src/db-artwork-parser.c +++ b/src/db-artwork-parser.c @@ -87,9 +87,10 @@ 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)); - db_parse_context_set_total_len (ctx, get_gint32_db (ctx->db, mhia->total_len)); + photo_album->members = g_list_append (photo_album->members, + GINT_TO_POINTER(image_id)); + db_parse_context_set_total_len (ctx, + get_gint32_db (ctx->db, mhia->total_len)); return 0; } @@ -309,6 +310,8 @@ parse_mhii (DBParseContext *ctx, GError *error) off_t cur_offset; iPodSong *song; Itdb_Artwork *artwork; + Itdb_PhotoDB *photodb; + Itdb_iTunesDB *itunesdb; mhii = db_parse_context_get_m_header (ctx, MhiiHeader, "mhii"); if (mhii == NULL) { @@ -335,13 +338,20 @@ parse_mhii (DBParseContext *ctx, GError *error) g_free (mhod_ctx); mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); } - ctx->db->db.photodb->photos = g_list_append (ctx->db->db.photodb->photos, artwork); + photodb = db_get_photodb (ctx->db); + g_return_val_if_fail (photodb, -1); + photodb->photos = g_list_append (photodb->photos, + artwork); break; case DB_TYPE_ITUNES: #ifdef NOT_DEFINED_DEBUG_ARTWORKDB song = NULL; #else - song = get_song_by_dbid (ctx->db->db.itdb, get_gint64 (mhii->song_id, ctx->byte_order)); + itunesdb = db_get_itunesdb (ctx->db); + g_return_val_if_fail (itunesdb, -1); + song = get_song_by_dbid (itunesdb, + get_gint64 (mhii->song_id, + ctx->byte_order)); if (song == NULL) { return -1; } @@ -364,6 +374,8 @@ parse_mhii (DBParseContext *ctx, GError *error) mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); } break; + default: + g_return_val_if_reached (-1); } return 0; } @@ -376,6 +388,7 @@ parse_mhba (DBParseContext *ctx, GError *error) DBParseContext *mhod_ctx; DBParseContext *mhia_ctx; Itdb_PhotoAlbum *photo_album; + Itdb_PhotoDB *photodb; int num_children; off_t cur_offset; @@ -419,7 +432,10 @@ parse_mhba (DBParseContext *ctx, GError *error) g_free (mhia_ctx); mhia_ctx = db_parse_context_get_sub_context (ctx, cur_offset); } - ctx->db->db.photodb->photoalbums = g_list_append (ctx->db->db.photodb->photoalbums, photo_album); + photodb = db_get_photodb (ctx->db); + g_return_val_if_fail (photodb, -1); + photodb->photoalbums = g_list_append (photodb->photoalbums, + photo_album); return 0; } @@ -635,11 +651,11 @@ ipod_parse_artwork_db (Itdb_iTunesDB *itdb) g_return_val_if_fail (itdb, -1); - if (!ipod_supports_cover_art (db.db.itdb->device)) { + if (!ipod_supports_cover_art (itdb->device)) { return -1; } ctx = NULL; - filename = ipod_db_get_artwork_db_path (itdb_get_mountpoint (db.db.itdb)); + filename = ipod_db_get_artwork_db_path (itdb_get_mountpoint (itdb)); if (filename == NULL) { goto error; } diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c index cd97e56..38ec1f8 100644 --- a/src/db-artwork-writer.c +++ b/src/db-artwork-writer.c @@ -443,26 +443,32 @@ write_mhni (Itdb_DB *db, Itdb_Thumb *thumb, int correlation_id, iPodBuffer *buff if (mhni == NULL) { return -1; } - total_bytes = get_gint32 (mhni->header_len, buffer->byte_order); - mhni->total_len = get_gint32 (total_bytes, buffer->byte_order); - - mhni->correlation_id = get_gint32 (correlation_id, buffer->byte_order); - mhni->image_width = get_gint16 (thumb->width, buffer->byte_order); - mhni->image_height = get_gint16 (thumb->height, buffer->byte_order); - mhni->image_size = get_gint32 (thumb->size, buffer->byte_order); - mhni->ithmb_offset = get_gint32 (thumb->offset, buffer->byte_order); + total_bytes = get_gint32 (mhni->header_len, + buffer->byte_order); + mhni->total_len = get_gint32 (total_bytes, + buffer->byte_order); + mhni->correlation_id = get_gint32 (correlation_id, + buffer->byte_order); + mhni->image_width = get_gint16 (thumb->width, + buffer->byte_order); + mhni->image_height = get_gint16 (thumb->height, + buffer->byte_order); + mhni->image_size = get_gint32 (thumb->size, + buffer->byte_order); + mhni->ithmb_offset = get_gint32 (thumb->offset, + buffer->byte_order); /* Work out the image padding */ - format = itdb_device_get_artwork_formats (db_get_device (db)); + format = itdb_get_artwork_info_from_type ( + db_get_device(db), thumb->type); g_return_val_if_fail (format, 0); - while( format->type != thumb->type && format->type != -1 ) - format++; + mhni->vertical_padding = get_gint16 ( - (format->height - thumb->height) - , buffer->byte_order); + format->height - thumb->height, + buffer->byte_order); mhni->horizontal_padding = get_gint16 ( - (format->width - thumb->width) - , buffer->byte_order); + format->width - thumb->width, + buffer->byte_order); sub_buffer = ipod_buffer_get_sub_buffer (buffer, total_bytes); if (sub_buffer == NULL) { @@ -615,11 +621,13 @@ write_mhli (Itdb_DB *db, iPodBuffer *buffer ) total_bytes = get_gint32 (mhli->header_len, buffer->byte_order); switch (buffer->db_type) { case DB_TYPE_PHOTO: - it = db->db.photodb->photos; + it = db_get_photodb(db)->photos; break; case DB_TYPE_ITUNES: - it = db->db.itdb->tracks; + it = db_get_itunesdb(db)->tracks; break; + default: + g_return_val_if_reached (-1); } while (it != NULL) { Itdb_Track *song; @@ -738,7 +746,7 @@ write_mhla (Itdb_DB *db, iPodBuffer *buffer) if (buffer->db_type == DB_TYPE_PHOTO) { unsigned int bytes_written; - for (it = db->db.photodb->photoalbums; it != NULL; it = it->next) { + for (it = db_get_photodb(db)->photoalbums; it != NULL; it = it->next) { Itdb_PhotoAlbum *photo_album = (Itdb_PhotoAlbum *)it->data; sub_buffer = ipod_buffer_get_sub_buffer (buffer, total_bytes); diff --git a/src/db-image-parser.c b/src/db-image-parser.c index 06f8f1e..64c23a3 100644 --- a/src/db-image-parser.c +++ b/src/db-image-parser.c @@ -102,14 +102,8 @@ ipod_image_new_from_mhni (MhniHeader *mhni, Itdb_DB *db) img->width = get_gint16_db (db, mhni->image_width); img->height = get_gint16_db (db, mhni->image_height); - switch (db->db_type) { - case DB_TYPE_ITUNES: - device = db->db.itdb->device; - break; - case DB_TYPE_PHOTO: - device = db->db.photodb->device; - break; - } + device = db_get_device (db); + g_return_val_if_fail (device, NULL); corr_id = get_gint32_db (db, mhni->correlation_id); img->type = image_type_from_corr_id (device, corr_id); diff --git a/src/db-image-parser.h b/src/db-image-parser.h index 39f5fd4..3b1e49c 100644 --- a/src/db-image-parser.h +++ b/src/db-image-parser.h @@ -27,6 +27,7 @@ #include "db-itunes-parser.h" #include "itdb_device.h" +#include "itdb_private.h" #include "itdb.h" #define RED_BITS 5 diff --git a/src/db-parse-context.c b/src/db-parse-context.c index 0adbe30..ceb8313 100644 --- a/src/db-parse-context.c +++ b/src/db-parse-context.c @@ -179,16 +179,7 @@ db_parse_context_new_from_file (const char *filename, Itdb_DB *db) buffer = NULL; ctx = NULL; - switch (db->db_type) { - case DB_TYPE_ITUNES: - device = db->db.itdb->device; - break; - case DB_TYPE_PHOTO: - device = db->db.photodb->device; - break; - default: - g_return_val_if_reached (NULL); - } + device = db_get_device (db); g_return_val_if_fail (device, NULL); fd = open (filename, O_RDONLY); diff --git a/src/db-parse-context.h b/src/db-parse-context.h index 4e18baa..9d75c31 100644 --- a/src/db-parse-context.h +++ b/src/db-parse-context.h @@ -28,6 +28,8 @@ #include <sys/types.h> #include "itdb.h" +#include "itdb_private.h" + struct _DBParseContext { const unsigned char *buffer; const unsigned char *cur_pos; @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-05-30 21:59:40 jcs> +/* Time-stamp: <2006-06-01 23:07:57 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -62,7 +62,6 @@ typedef struct _SPLRule SPLRule; typedef struct _SPLRules SPLRules; typedef struct _Itdb_iTunesDB Itdb_iTunesDB; typedef struct _Itdb_PhotoDB Itdb_PhotoDB; -typedef struct _Itdb_DB Itdb_DB; typedef struct _Itdb_Playlist Itdb_Playlist; typedef struct _Itdb_PhotoAlbum Itdb_PhotoAlbum; typedef struct _Itdb_Track Itdb_Track; @@ -405,21 +404,6 @@ struct _SPLRules /* one star is how much (track->rating) */ #define ITDB_RATING_STEP 20 -enum _DbType { - DB_TYPE_ITUNES, - DB_TYPE_PHOTO -}; - -typedef enum _DbType DbType; - -struct _Itdb_DB{ - DbType db_type; - union { - Itdb_PhotoDB *photodb; - Itdb_iTunesDB *itdb; - } db; -}; - struct _Itdb_PhotoDB { GList *photos; diff --git a/src/itdb_endianness.h b/src/itdb_endianness.h index 3eb129c..4147dd0 100644 --- a/src/itdb_endianness.h +++ b/src/itdb_endianness.h @@ -27,6 +27,7 @@ #include <glib.h> #include "itdb.h" #include "itdb_device.h" +#include "itdb_private.h" #define DB_TO_CPU_GET(lower_case_type, upper_case_type) \ static inline lower_case_type \ @@ -57,20 +58,12 @@ static inline lower_case_type \ get_##lower_case_type##_db (Itdb_DB *db, lower_case_type val) \ { \ - switch (db->db_type) { \ - case DB_TYPE_ITUNES: \ - g_assert (db->db.itdb->device != NULL); \ - return get_##lower_case_type (val, db->db.itdb->device->byte_order); \ - case DB_TYPE_PHOTO: \ - g_assert (db->db.photodb->device != NULL); \ - return get_##lower_case_type (val, db->db.photodb->device->byte_order); \ - } \ - return 0; \ -} + g_assert (db_get_device(db) != NULL); \ + return get_##lower_case_type (val, db_get_device(db)->byte_order); \ + } DB_TO_CPU_GET_DB(guint32, GUINT32) DB_TO_CPU_GET_DB(gint32, GINT32) DB_TO_CPU_GET_DB(gint16, GINT16) DB_TO_CPU_GET_DB(gint64, GINT64) - /*DB_TO_CPU_GET(gint, GINT)*/ #endif diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c index b4e4ac1..2b7a39a 100644 --- a/src/itdb_itunesdb.c +++ b/src/itdb_itunesdb.c @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-06-01 22:09:17 jcs> +/* Time-stamp: <2006-06-01 23:31:27 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -4799,36 +4799,6 @@ const gchar *itdb_photodb_get_mountpoint (Itdb_PhotoDB *photodb) return photodb->device->mountpoint; } -/* Retrieve a reference to the mountpoint */ -gchar *db_get_mountpoint(Itdb_DB *db) -{ - g_return_val_if_fail (db, NULL); - - switch (db->db_type) { - case DB_TYPE_ITUNES: - g_return_val_if_fail (db->db.itdb->device, NULL); - return db->db.itdb->device->mountpoint; - case DB_TYPE_PHOTO: - g_return_val_if_fail (db->db.photodb->device, NULL); - return db->db.photodb->device->mountpoint; - } - return NULL; -} - -Itdb_Device *db_get_device(Itdb_DB *db) -{ - g_return_val_if_fail (db, NULL); - - switch (db->db_type) { - case DB_TYPE_ITUNES: - return db->db.itdb->device; - case DB_TYPE_PHOTO: - return db->db.photodb->device; - } - g_return_val_if_reached (NULL); -} - - /** * itdb_musicdirs_number: * @itdb: an #Itdb_iTunesDB @@ -5543,6 +5513,61 @@ gboolean itdb_init_ipod (const gchar *mountpoint, return TRUE; } + + +/*------------------------------------------------------------------*\ + * * + * Some functions to access Itdb_DB safely * + * * +\*------------------------------------------------------------------*/ +G_GNUC_INTERNAL +Itdb_iTunesDB *db_get_itunesdb (Itdb_DB *db) +{ + g_return_val_if_fail (db, NULL); + g_return_val_if_fail (db->db_type == DB_TYPE_ITUNES, NULL); + + return db->db.itdb; +} + +G_GNUC_INTERNAL +Itdb_PhotoDB *db_get_photodb (Itdb_DB *db) +{ + g_return_val_if_fail (db, NULL); + g_return_val_if_fail (db->db_type == DB_TYPE_PHOTO, NULL); + + return db->db.photodb; +} + +G_GNUC_INTERNAL +Itdb_Device *db_get_device(Itdb_DB *db) +{ + g_return_val_if_fail (db, NULL); + + switch (db->db_type) { + case DB_TYPE_ITUNES: + g_return_val_if_fail (db_get_itunesdb(db), NULL); + return db_get_itunesdb(db)->device; + case DB_TYPE_PHOTO: + g_return_val_if_fail (db_get_photodb(db), NULL); + return db_get_photodb(db)->device; + } + g_return_val_if_reached (NULL); +} + +G_GNUC_INTERNAL +gchar *db_get_mountpoint(Itdb_DB *db) +{ + Itdb_Device *device; + g_return_val_if_fail (db, NULL); + + device = db_get_device (db); + g_return_val_if_fail (device, NULL); + + return device->mountpoint; +} + + + /*------------------------------------------------------------------*\ * * * Create iPod directory hierarchy * diff --git a/src/itdb_private.h b/src/itdb_private.h index e13e79e..037b762 100644 --- a/src/itdb_private.h +++ b/src/itdb_private.h @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-05-28 01:11:35 jcs> +/* Time-stamp: <2006-06-01 23:31:27 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -123,11 +123,29 @@ typedef struct } FExport; +enum _DbType { + DB_TYPE_ITUNES, + DB_TYPE_PHOTO +}; + +typedef enum _DbType DbType; + +struct _Itdb_DB{ + DbType db_type; + union { + Itdb_PhotoDB *photodb; + Itdb_iTunesDB *itdb; + } db; +}; + +typedef struct _Itdb_DB Itdb_DB; + G_GNUC_INTERNAL gboolean itdb_spl_action_known (SPLAction action); G_GNUC_INTERNAL void itdb_splr_free (SPLRule *splr); G_GNUC_INTERNAL const gchar *itdb_photodb_get_mountpoint (Itdb_PhotoDB *photodb); G_GNUC_INTERNAL gchar *db_get_mountpoint (Itdb_DB *db); G_GNUC_INTERNAL Itdb_Device *db_get_device(Itdb_DB *db); G_GNUC_INTERNAL gint itdb_get_free_photo_id ( Itdb_PhotoDB *db ); - +G_GNUC_INTERNAL Itdb_iTunesDB *db_get_itunesdb (Itdb_DB *db); +G_GNUC_INTERNAL Itdb_PhotoDB *db_get_photodb (Itdb_DB *db); #endif diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c index a94c289..88e1b95 100644 --- a/src/ithumb-writer.c +++ b/src/ithumb-writer.c @@ -94,6 +94,7 @@ pack_RGB_565 (GdkPixbuf *pixbuf, iThumbWriter *writer ) horizontal_padding = (writer->img_info->width - width)/2; vertical_padding = (writer->img_info->height - height)/2; + for (h = 0; h < height; h++) { for (w = 0; w < width; w++) { gint r; @@ -589,7 +590,7 @@ ithmb_rearrange_existing_thumbnails (Itdb_DB *db, allows to adjust the offset pointers */ switch (db->db_type) { case DB_TYPE_ITUNES: - for (gl=db->db.itdb->tracks; gl; gl=gl->next) + for (gl=db_get_itunesdb(db)->tracks; gl; gl=gl->next) { Itdb_Thumb *thumb; Itdb_Track *track = gl->data; @@ -599,8 +600,9 @@ ithmb_rearrange_existing_thumbnails (Itdb_DB *db, info->type); if (thumb && thumb->filename && (thumb->size != 0)) { - filename = itdb_thumb_get_filename (db->db.itdb->device, - thumb); + filename = itdb_thumb_get_filename ( + db_get_device(db), + thumb); if (filename) { thumbs = g_hash_table_lookup (filenamehash, filename); @@ -609,8 +611,9 @@ ithmb_rearrange_existing_thumbnails (Itdb_DB *db, } } } + break; case DB_TYPE_PHOTO: - for (gl=db->db.photodb->photos; gl; gl=gl->next) + for (gl=db_get_photodb(db)->photos; gl; gl=gl->next) { Itdb_Thumb *thumb; Itdb_Artwork *artwork = gl->data; @@ -619,8 +622,9 @@ ithmb_rearrange_existing_thumbnails (Itdb_DB *db, info->type); if (thumb && thumb->filename && (thumb->size != 0)) { - filename = itdb_thumb_get_filename (db->db.photodb->device, - thumb); + filename = itdb_thumb_get_filename ( + db_get_device (db), + thumb); if (filename) { thumbs = g_hash_table_lookup (filenamehash, filename); @@ -629,6 +633,9 @@ ithmb_rearrange_existing_thumbnails (Itdb_DB *db, } } } + break; + default: + g_return_val_if_reached (FALSE); } /* Check for files present on the iPod but no longer referenced by @@ -714,7 +721,7 @@ itdb_write_ithumb_files (Itdb_DB *db) } switch (db->db_type) { case DB_TYPE_ITUNES: - for (it = db->db.itdb->tracks; it != NULL; it = it->next) { + for (it = db_get_itunesdb(db)->tracks; it != NULL; it = it->next) { Itdb_Track *track; track = it->data; @@ -724,7 +731,7 @@ itdb_write_ithumb_files (Itdb_DB *db) } break; case DB_TYPE_PHOTO: - for (it = db->db.photodb->photos; it != NULL; it = it->next) { + for (it = db_get_photodb(db)->photos; it != NULL; it = it->next) { Itdb_Artwork *photo; photo = it->data; @@ -733,6 +740,8 @@ itdb_write_ithumb_files (Itdb_DB *db) g_list_foreach (writers, write_thumbnail, photo); } break; + default: + g_return_val_if_reached (-1); } g_list_foreach (writers, (GFunc)ithumb_writer_free, NULL); |