diff options
-rw-r--r-- | ChangeLog | 63 | ||||
-rw-r--r-- | docs/reference/tmpl/artwork.sgml | 1 | ||||
-rw-r--r-- | docs/reference/tmpl/device.sgml | 60 | ||||
-rw-r--r-- | docs/reference/tmpl/libgpod-unused.sgml | 36 | ||||
-rw-r--r-- | src/db-artwork-debug.h | 1 | ||||
-rw-r--r-- | src/db-artwork-parser.c | 57 | ||||
-rw-r--r-- | src/db-artwork-parser.h | 3 | ||||
-rw-r--r-- | src/db-artwork-writer.c | 2 | ||||
-rw-r--r-- | src/db-image-parser.c | 20 | ||||
-rw-r--r-- | src/db-image-parser.h | 6 | ||||
-rw-r--r-- | src/db-parse-context.h | 29 | ||||
-rw-r--r-- | src/glib-compat.h | 26 | ||||
-rw-r--r-- | src/itdb.h | 67 | ||||
-rw-r--r-- | src/itdb_artwork.c | 59 | ||||
-rw-r--r-- | src/itdb_device.c | 308 | ||||
-rw-r--r-- | src/itdb_device.h | 58 | ||||
-rw-r--r-- | src/itdb_endianness.h | 25 | ||||
-rw-r--r-- | src/itdb_itunesdb.c | 41 | ||||
-rw-r--r-- | src/itdb_photoalbum.c | 4 | ||||
-rw-r--r-- | src/itdb_track.c | 12 | ||||
-rw-r--r-- | src/ithumb-writer.c | 10 |
21 files changed, 610 insertions, 278 deletions
@@ -1,5 +1,68 @@ +2006-06-05 Jorg Schuler <jcsjcs at users.sourceforge.net> + + * src/db-artwork-parser.h + src/db-artwork-parserc (ipod_supports_cover_art): made + available G_GNUC_INTERNAL. + Added ipod_supports_photos(). + + * src/itdb_itunesdb.c (itdb_create_directories): + Create Photos directory. + + +2006-06-04 Jorg Schuler <jcsjcs at users.sourceforge.net> + + * src/db-image-parser.c + src/itdb_artwork.c + src/itdb_device.c + src/itdb_photoalbum.c + src/itdb_track.c + src/ithumb-writer.c: Phased out private + IPOD_COVER_SMALL... enum in favor of identical public enum + "ItdbThumbType" ITDB_THUMB_COVER_SMALL... + + * src/db-image-parser.c (ipod_image_new_from_mhni): + Accept all thumbnail types we know about (i.e. type != -1). + + * src/db-artwork-debug.h + src/db-artwork-parser.h + src/db-image-parser.h + src/db-parse-context.h + src/glib-compat.h + src/itdb_endianness.h: Added CVS "$Id:" line, added copyright + notices where missing, added explanations to itdb_endianess.h + ;-) + + * src/itdb_itunesdb.c + src/itdb_track.c + src/itdb_device.c + src/itdb_device.h + Made naming consistent and suitable for export: + Itdb_IpodModel -> Itdb_IpodInfo + ipod_model_table -> ipod_info_table + itdb_device_get_model_info() -> itdb_device_get_ipod_info() + MODEL_TYPE_... -> ITDB_IPOD_MODEL_... + nth_GENERATION -> ITDB_IPOD_GENERATION_nth + + Exported Itdb_IpodModel, Itdb_IpodGeneration, Itdb_IpodInfo, + itdb_device_get_ipod_info(). + + * src/itdb_device.c: new API: + itdb_info_get_ipod_info_table(), + itdb_info_get_ipod_model_name() + + * src/itdb.h + src/itdb_artwork.c: + Removed unused field ->type in Itdb_Artwork and corresponding + enum ItdbArtworkType. + 2006-06-03 Jorg Schuler <jcsjcs at users.sourceforge.net> + * src/itdb_artwork.c (itdb_thumb_get_gdk_pixbuf): handle thumbnail + padding correctly -- who would have thought that iTunes + indicates _negative_ padding at times... Please use the + test-photos program to check out whether or not your photos show + up correctly without black bars or funny colors. + * src/db-artwork-writer.c src/db-image-parser.c src/itdb.h diff --git a/docs/reference/tmpl/artwork.sgml b/docs/reference/tmpl/artwork.sgml index fafde75..94d2343 100644 --- a/docs/reference/tmpl/artwork.sgml +++ b/docs/reference/tmpl/artwork.sgml @@ -24,7 +24,6 @@ Data structure to store iPod artwork (cover and photos) @thumbnails: @artwork_size: -@type: @id: @creation_date: @usertype: diff --git a/docs/reference/tmpl/device.sgml b/docs/reference/tmpl/device.sgml index 8852576..f984e1e 100644 --- a/docs/reference/tmpl/device.sgml +++ b/docs/reference/tmpl/device.sgml @@ -71,16 +71,28 @@ Data structure holding information about the iPod (model, mount point, ...) @Returns: -<!-- ##### STRUCT Itdb_IpodModel ##### --> +<!-- ##### ENUM Itdb_IpodModel ##### --> <para> </para> -@model_number: -@capacity: -@model_type: -@generation: -@musicdirs: +@ITDB_IPOD_MODEL_INVALID: +@ITDB_IPOD_MODEL_UNKNOWN: +@ITDB_IPOD_MODEL_COLOR: +@ITDB_IPOD_MODEL_COLOR_U2: +@ITDB_IPOD_MODEL_REGULAR: +@ITDB_IPOD_MODEL_REGULAR_U2: +@ITDB_IPOD_MODEL_MINI: +@ITDB_IPOD_MODEL_MINI_BLUE: +@ITDB_IPOD_MODEL_MINI_PINK: +@ITDB_IPOD_MODEL_MINI_GREEN: +@ITDB_IPOD_MODEL_MINI_GOLD: +@ITDB_IPOD_MODEL_SHUFFLE: +@ITDB_IPOD_MODEL_NANO_WHITE: +@ITDB_IPOD_MODEL_NANO_BLACK: +@ITDB_IPOD_MODEL_VIDEO_WHITE: +@ITDB_IPOD_MODEL_VIDEO_BLACK: +@ITDB_IPOD_MODEL_MOBILE_1: <!-- ##### STRUCT Itdb_ArtworkFormat ##### --> <para> @@ -92,39 +104,3 @@ Data structure holding information about the iPod (model, mount point, ...) @height: @correlation_id: -<!-- ##### ENUM Itdb_Generation ##### --> -<para> - -</para> - -@UNKNOWN_GENERATION: -@FIRST_GENERATION: -@SECOND_GENERATION: -@THIRD_GENERATION: -@FOURTH_GENERATION: -@FIFTH_GENERATION: -@MOBILE_GENERATION: - -<!-- ##### ENUM Itdb_ModelType ##### --> -<para> - -</para> - -@MODEL_TYPE_INVALID: -@MODEL_TYPE_UNKNOWN: -@MODEL_TYPE_COLOR: -@MODEL_TYPE_COLOR_U2: -@MODEL_TYPE_REGULAR: -@MODEL_TYPE_REGULAR_U2: -@MODEL_TYPE_MINI: -@MODEL_TYPE_MINI_BLUE: -@MODEL_TYPE_MINI_PINK: -@MODEL_TYPE_MINI_GREEN: -@MODEL_TYPE_MINI_GOLD: -@MODEL_TYPE_SHUFFLE: -@MODEL_TYPE_NANO_WHITE: -@MODEL_TYPE_NANO_BLACK: -@MODEL_TYPE_VIDEO_WHITE: -@MODEL_TYPE_VIDEO_BLACK: -@MODEL_TYPE_MOBILE_1: - diff --git a/docs/reference/tmpl/libgpod-unused.sgml b/docs/reference/tmpl/libgpod-unused.sgml index 6fd94dc..aaf7c7f 100644 --- a/docs/reference/tmpl/libgpod-unused.sgml +++ b/docs/reference/tmpl/libgpod-unused.sgml @@ -39,6 +39,42 @@ iTunesDB @ITDB_FILE_ERROR_RENAME: @ITDB_FILE_ERROR_ITDB_CORRUPT: +<!-- ##### ENUM Itdb_Generation ##### --> +<para> + +</para> + +@UNKNOWN_GENERATION: +@FIRST_GENERATION: +@SECOND_GENERATION: +@THIRD_GENERATION: +@FOURTH_GENERATION: +@FIFTH_GENERATION: +@MOBILE_GENERATION: + +<!-- ##### ENUM Itdb_ModelType ##### --> +<para> + +</para> + +@MODEL_TYPE_INVALID: +@MODEL_TYPE_UNKNOWN: +@MODEL_TYPE_COLOR: +@MODEL_TYPE_COLOR_U2: +@MODEL_TYPE_REGULAR: +@MODEL_TYPE_REGULAR_U2: +@MODEL_TYPE_MINI: +@MODEL_TYPE_MINI_BLUE: +@MODEL_TYPE_MINI_PINK: +@MODEL_TYPE_MINI_GREEN: +@MODEL_TYPE_MINI_GOLD: +@MODEL_TYPE_SHUFFLE: +@MODEL_TYPE_NANO_WHITE: +@MODEL_TYPE_NANO_BLACK: +@MODEL_TYPE_VIDEO_WHITE: +@MODEL_TYPE_VIDEO_BLACK: +@MODEL_TYPE_MOBILE_1: + <!-- ##### MACRO SPLACTION_LAST_FORTNIGHT ##### --> <para> diff --git a/src/db-artwork-debug.h b/src/db-artwork-debug.h index cd4d4d3..604ea84 100644 --- a/src/db-artwork-debug.h +++ b/src/db-artwork-debug.h @@ -20,6 +20,7 @@ * * This product is not supported/written/published by Apple! * + * $Id$ */ #ifndef DB_ARTWORK_DEBUG_H #define DB_ARTWORK_DEBUG_H diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c index b5d7fde..4a848ce 100644 --- a/src/db-artwork-parser.c +++ b/src/db-artwork-parser.c @@ -323,7 +323,6 @@ parse_mhii (DBParseContext *ctx, GError *error) switch (ctx->db->db_type) { case DB_TYPE_PHOTO: artwork = g_new0( Itdb_Artwork, 1 ); - artwork->type = ITDB_PHOTO; artwork->artwork_size = get_gint32 (mhii->orig_img_size, ctx->byte_order); artwork->id = get_gint32 (mhii->image_id, ctx->byte_order); artwork->creation_date = itdb_time_mac_to_host( get_gint32 (mhii->digitised_date, ctx->byte_order) ); @@ -614,7 +613,7 @@ ipod_db_get_artwork_db_path (const char *mount_point) return filename; } -static gboolean +G_GNUC_INTERNAL gboolean ipod_supports_cover_art (Itdb_Device *device) { const Itdb_ArtworkFormat *formats; @@ -628,17 +627,59 @@ ipod_supports_cover_art (Itdb_Device *device) return FALSE; } - while (formats->type != -1) { - if ((formats->type == IPOD_COVER_SMALL) - || (formats->type == IPOD_COVER_LARGE)) { - return TRUE; - } - formats++; + while (formats->type != -1) + { + switch (formats->type) + { + case ITDB_THUMB_COVER_SMALL: + case ITDB_THUMB_COVER_LARGE: + return TRUE; + case ITDB_THUMB_PHOTO_SMALL: + case ITDB_THUMB_PHOTO_LARGE: + case ITDB_THUMB_PHOTO_FULL_SCREEN: + case ITDB_THUMB_PHOTO_TV_SCREEN: + break; + } + formats++; } return FALSE; } +G_GNUC_INTERNAL gboolean +ipod_supports_photos (Itdb_Device *device) +{ + const Itdb_ArtworkFormat *formats; + + if (device == NULL) { + return FALSE; + } + + formats = itdb_device_get_artwork_formats (device); + if (formats == NULL) { + return FALSE; + } + + while (formats->type != -1) + { + switch (formats->type) + { + case ITDB_THUMB_COVER_SMALL: + case ITDB_THUMB_COVER_LARGE: + break; + case ITDB_THUMB_PHOTO_SMALL: + case ITDB_THUMB_PHOTO_LARGE: + case ITDB_THUMB_PHOTO_FULL_SCREEN: + case ITDB_THUMB_PHOTO_TV_SCREEN: + return TRUE; + } + formats++; + } + + return FALSE; +} + + int ipod_parse_artwork_db (Itdb_iTunesDB *itdb) { diff --git a/src/db-artwork-parser.h b/src/db-artwork-parser.h index eb84e8d..58c0fb2 100644 --- a/src/db-artwork-parser.h +++ b/src/db-artwork-parser.h @@ -20,6 +20,7 @@ * * This product is not supported/written/published by Apple! * + * $Id$ */ @@ -36,4 +37,6 @@ G_GNUC_INTERNAL char *ipod_db_get_artwork_db_path (const char *mount_point); G_GNUC_INTERNAL char *ipod_db_get_photos_db_path (const char *mount_point); G_GNUC_INTERNAL int ipod_parse_photo_db (Itdb_PhotoDB *photodb); G_GNUC_INTERNAL int ipod_write_photo_db (Itdb_PhotoDB *db); +G_GNUC_INTERNAL gboolean ipod_supports_cover_art (Itdb_Device *device); +G_GNUC_INTERNAL gboolean ipod_supports_photos (Itdb_Device *device); #endif diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c index 0f21f22..08de094 100644 --- a/src/db-artwork-writer.c +++ b/src/db-artwork-writer.c @@ -1105,7 +1105,7 @@ ipod_write_artwork_db (Itdb_iTunesDB *itdb) } int -ipod_write_photo_db (Itdb_PhotoDB *db) +ipod_write_photo_db (Itdb_PhotoDB *photodb) { return -1; } diff --git a/src/db-image-parser.c b/src/db-image-parser.c index e845b92..9130bdc 100644 --- a/src/db-image-parser.c +++ b/src/db-image-parser.c @@ -62,7 +62,8 @@ image_type_from_corr_id (Itdb_Device *device, gint16 corr_id) G_GNUC_INTERNAL const Itdb_ArtworkFormat * -itdb_get_artwork_info_from_type (Itdb_Device *device, int image_type) +itdb_get_artwork_info_from_type (Itdb_Device *device, + ItdbThumbType image_type) { const Itdb_ArtworkFormat *formats; @@ -112,18 +113,13 @@ ipod_image_new_from_mhni (MhniHeader *mhni, Itdb_DB *db) corr_id = get_gint32_db (db, mhni->correlation_id); img->type = image_type_from_corr_id (device, corr_id); - if ( img->type != IPOD_COVER_SMALL - && img->type != IPOD_COVER_LARGE - && img->type != IPOD_PHOTO_SMALL - && img->type != IPOD_PHOTO_LARGE - && img->type != IPOD_PHOTO_FULL_SCREEN - && img->type != IPOD_PHOTO_TV_SCREEN) + if (img->type == -1) { - g_warning ("Unexpected cover type in mhni: type %d, size: %ux%u (%d), offset: %d\n", - img->type, img->width, img->height, - corr_id, img->offset); - g_free (img); - return NULL; + g_warning (_("Unexpected image type in mhni: size: %ux%u (%d), offset: %d\n"), + img->width, img->height, + corr_id, img->offset); + g_free (img); + return NULL; } return img; diff --git a/src/db-image-parser.h b/src/db-image-parser.h index 3b1e49c..f09e574 100644 --- a/src/db-image-parser.h +++ b/src/db-image-parser.h @@ -20,6 +20,7 @@ * * This product is not supported/written/published by Apple! * + * $Id$ */ #ifndef IMAGE_PARSER_H @@ -47,7 +48,8 @@ G_GNUC_INTERNAL Itdb_Thumb *ipod_image_new_from_mhni (MhniHeader *mhni, G_GNUC_INTERNAL int itdb_write_ithumb_files (Itdb_DB *db); -G_GNUC_INTERNAL const Itdb_ArtworkFormat *itdb_get_artwork_info_from_type ( - Itdb_Device *ipod, int image_type); +G_GNUC_INTERNAL +const Itdb_ArtworkFormat *itdb_get_artwork_info_from_type ( + Itdb_Device *ipod, ItdbThumbType image_type); #endif diff --git a/src/db-parse-context.h b/src/db-parse-context.h index 9d75c31..a081c1c 100644 --- a/src/db-parse-context.h +++ b/src/db-parse-context.h @@ -14,12 +14,39 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this code; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA * * iTunes and iPod are trademarks of Apple * * This product is not supported/written/published by Apple! * + * $Id$ + */ +/* + * Copyright (C) 2005 Christophe Fergeau + * + * + * The code contained in this file is free software; you can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either version + * 2.1 of the License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this code; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + * iTunes and iPod are trademarks of Apple + * + * This product is not supported/written/published by Apple! + * + * $Id$ */ diff --git a/src/glib-compat.h b/src/glib-compat.h index 3040d68..47ba310 100644 --- a/src/glib-compat.h +++ b/src/glib-compat.h @@ -1,3 +1,29 @@ +/* + * Copyright (C) 2005 Christophe Fergeau + * + * + * The code contained in this file is free software; you can redistribute + * it and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either version + * 2.1 of the License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this code; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + * iTunes and iPod are trademarks of Apple + * + * This product is not supported/written/published by Apple! + * + * $Id$ + */ + #ifndef GLIB_COMPAT_H #define GLIB_COMPAT_H @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-06-03 02:25:03 jcs> +/* Time-stamp: <2006-06-04 19:21:02 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -65,6 +65,7 @@ typedef struct _Itdb_PhotoDB Itdb_PhotoDB; typedef struct _Itdb_Playlist Itdb_Playlist; typedef struct _Itdb_PhotoAlbum Itdb_PhotoAlbum; typedef struct _Itdb_Track Itdb_Track; +typedef struct _Itdb_IpodInfo Itdb_IpodInfo; /* ------------------------------------------------------------ *\ @@ -114,15 +115,9 @@ struct _Itdb_Thumb { gint16 vertical_padding; }; -typedef enum { - ITDB_COVERART, - ITDB_PHOTO -} ItdbArtworkType; - struct _Itdb_Artwork { GList *thumbnails; /* list of Itdb_Thumbs */ guint32 artwork_size; /* Size in bytes of the original source image */ - ItdbArtworkType type; /* Cover art or photo */ guint32 id; /* Artwork id used by photoalbums, starts at * 0x40... libgpod will set this on sync. */ gint32 creation_date; /* Date the image was created */ @@ -138,6 +133,60 @@ struct _Itdb_Artwork { /* ------------------------------------------------------------ *\ * + * iPod model-relevant definitions + * +\* ------------------------------------------------------------ */ + +typedef enum { + ITDB_IPOD_GENERATION_UNKNOWN, + ITDB_IPOD_GENERATION_FIRST, + ITDB_IPOD_GENERATION_SECOND, + ITDB_IPOD_GENERATION_THIRD, + ITDB_IPOD_GENERATION_FOURTH, + ITDB_IPOD_GENERATION_FIFTH, + ITDB_IPOD_GENERATION_MOBILE +} Itdb_IpodGeneration; + +typedef enum { + ITDB_IPOD_MODEL_INVALID, + ITDB_IPOD_MODEL_UNKNOWN, + ITDB_IPOD_MODEL_COLOR, + ITDB_IPOD_MODEL_COLOR_U2, + ITDB_IPOD_MODEL_REGULAR, + ITDB_IPOD_MODEL_REGULAR_U2, + ITDB_IPOD_MODEL_MINI, + ITDB_IPOD_MODEL_MINI_BLUE, + ITDB_IPOD_MODEL_MINI_PINK, + ITDB_IPOD_MODEL_MINI_GREEN, + ITDB_IPOD_MODEL_MINI_GOLD, + ITDB_IPOD_MODEL_SHUFFLE, + ITDB_IPOD_MODEL_NANO_WHITE, + ITDB_IPOD_MODEL_NANO_BLACK, + ITDB_IPOD_MODEL_VIDEO_WHITE, + ITDB_IPOD_MODEL_VIDEO_BLACK, + ITDB_IPOD_MODEL_MOBILE_1 +} Itdb_IpodModel; + +struct _Itdb_IpodInfo { + /* model_number is abbreviated: if the first character is not + numeric, it is ommited. e.g. "MA350 -> A350", "M9829 -> 9829" */ + const gchar *model_number; + const double capacity; /* in GB */ + const Itdb_IpodModel ipod_model; + const Itdb_IpodGeneration ipod_generation; + /* Number of music (Fnn) dirs created by iTunes. The exact + number seems to be version dependent. Therefore, the + numbers here represent a mixture of reported values and + common sense. Note: this number does not necessarily + represent the number of dirs present on a particular + iPod. It is used when setting up a new iPod from + scratch. */ + const guint musicdirs; +}; + + +/* ------------------------------------------------------------ *\ + * * Smart Playlists (Rules) * \* ------------------------------------------------------------ */ @@ -814,6 +863,10 @@ void itdb_device_free (Itdb_Device *device); void itdb_device_set_mountpoint (Itdb_Device *device, const gchar *mp); gboolean itdb_device_read_sysinfo (Itdb_Device *device); gchar *itdb_device_get_sysinfo (Itdb_Device *device, const gchar *field); +const Itdb_IpodInfo *itdb_device_get_ipod_info (Itdb_Device *device); +const Itdb_IpodInfo *itdb_info_get_ipod_info_table (void); +const gchar *itdb_info_get_ipod_model_name (Itdb_IpodModel model); +const gchar *itdb_info_get_ipod_generation_name (Itdb_IpodGeneration generation); /* track functions */ Itdb_Track *itdb_track_new (void); diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c index 8a5b119..99b027f 100644 --- a/src/itdb_artwork.c +++ b/src/itdb_artwork.c @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-06-03 01:57:04 jcs> +/* Time-stamp: <2006-06-04 17:30:39 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -39,6 +39,7 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #endif #include <glib/gi18n-lib.h> +#include <stdlib.h> /** * itdb_artwork_new: @@ -503,6 +504,15 @@ itdb_thumb_get_gdk_pixbuf (Itdb_Device *device, Itdb_Thumb *thumb) else { /* pixbuf is already on the iPod -> read from there */ + GdkPixbuf *pixbuf_full; + GdkPixbuf *pixbuf_sub; + gint pad_x = thumb->horizontal_padding; + gint pad_y = thumb->vertical_padding; + gint width = thumb->width; + gint height = thumb->height; + +/* printf ("hp%d vp%d w%d h%d\n", + pad_x, pad_y, width, height);*/ if (img_info == NULL) { @@ -517,17 +527,46 @@ itdb_thumb_get_gdk_pixbuf (Itdb_Device *device, Itdb_Thumb *thumb) return NULL; } - pixbuf = gdk_pixbuf_new_from_data (pixels, - GDK_COLORSPACE_RGB, - FALSE, - 8, thumb->width, - thumb->height, - img_info->width*3, - (GdkPixbufDestroyNotify)g_free, - NULL); - + pixbuf_full = + gdk_pixbuf_new_from_data (pixels, + GDK_COLORSPACE_RGB, + FALSE, 8, + img_info->width, img_info->height, + img_info->width*3, + (GdkPixbufDestroyNotify)g_free, + NULL); /* !! do not g_free(pixels) here: it will be freed when doing a * gdk_pixbuf_unref() on the GdkPixbuf !! */ + + /* Remove padding from the pixmap and/or cut the pixmap to the + right size. */ + + /* Negative offsets indicate that part of the image was cut + off at the left/top. thumb->width/height include that part + of the image. Positive offsets indicate that part of the + thumbnail are padded in black. thumb->width/height also + include that part of the image -> reduce width and height + by the absolute value of the padding */ + width = width - abs (pad_x); + height = height - abs (pad_y); + /* And throw out "negative" padding */ + if (pad_x < 0) pad_x = 0; + if (pad_y < 0) pad_y = 0; + /* Width/height might still be larger than + img_info->width/height, indicating that part of the image + was cut off at the right/bottom (similar to negative + padding above). Adjust width/height accordingly. */ + if (pad_x + width > img_info->width) + width = img_info->width - pad_x; + if (pad_y + height > img_info->height) + height = img_info->height - pad_y; + + pixbuf_sub = gdk_pixbuf_new_subpixbuf (pixbuf_full, + pad_x, pad_y, + width, height); + pixbuf = gdk_pixbuf_copy (pixbuf_sub); + gdk_pixbuf_unref (pixbuf_full); + gdk_pixbuf_unref (pixbuf_sub); } return pixbuf; diff --git a/src/itdb_device.c b/src/itdb_device.c index dd2e2ad..17d6a98 100644 --- a/src/itdb_device.c +++ b/src/itdb_device.c @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-05-29 23:55:05 jcs> +/* Time-stamp: <2006-06-04 19:22:40 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -39,168 +39,176 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> +#include <glib/gi18n-lib.h> -#define GB 1024 - -static const Itdb_IpodModel ipod_model_table [] = { +static const Itdb_IpodInfo ipod_info_table [] = { /* Handle idiots who hose their iPod file system, or lucky people with iPods we don't yet know about*/ - {"Invalid", 0, MODEL_TYPE_INVALID, UNKNOWN_GENERATION, 0}, - {"Unknown", 0, MODEL_TYPE_UNKNOWN, UNKNOWN_GENERATION, 0}, + {"Invalid", 0, ITDB_IPOD_MODEL_INVALID, ITDB_IPOD_GENERATION_UNKNOWN, 0}, + {"Unknown", 0, ITDB_IPOD_MODEL_UNKNOWN, ITDB_IPOD_GENERATION_UNKNOWN, 0}, /* First Generation */ /* Mechanical buttons arranged around rotating "scroll wheel". 8513, 8541 and 8709 are Mac types, 8697 is PC */ - {"8513", 5*GB, MODEL_TYPE_REGULAR, FIRST_GENERATION, 20}, - {"8541", 5*GB, MODEL_TYPE_REGULAR, FIRST_GENERATION, 20}, - {"8697", 5*GB, MODEL_TYPE_REGULAR, FIRST_GENERATION, 20}, - {"8709", 10*GB, MODEL_TYPE_REGULAR, FIRST_GENERATION, 20}, + {"8513", 5, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_FIRST, 20}, + {"8541", 5, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_FIRST, 20}, + {"8697", 5, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_FIRST, 20}, + {"8709", 10, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_FIRST, 20}, /* Second Generation */ /* Same buttons as First Generation but around touch-sensitive "touch wheel". 8737 and 8738 are Mac types, 8740 and 8741 * are PC */ - {"8737", 10*GB, MODEL_TYPE_REGULAR, SECOND_GENERATION, 20}, - {"8740", 10*GB, MODEL_TYPE_REGULAR, SECOND_GENERATION, 20}, - {"8738", 20*GB, MODEL_TYPE_REGULAR, SECOND_GENERATION, 50}, - {"8741", 20*GB, MODEL_TYPE_REGULAR, SECOND_GENERATION, 50}, + {"8737", 10, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_SECOND, 20}, + {"8740", 10, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_SECOND, 20}, + {"8738", 20, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_SECOND, 50}, + {"8741", 20, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_SECOND, 50}, /* Third Generation */ /* Touch sensitive buttons and arranged in a line above "touch wheel". Docking connector was introduced here, same models for Mac and PC from now on. */ - {"8976", 10*GB, MODEL_TYPE_REGULAR, THIRD_GENERATION, 20}, - {"8946", 15*GB, MODEL_TYPE_REGULAR, THIRD_GENERATION, 50}, - {"9460", 15*GB, MODEL_TYPE_REGULAR, THIRD_GENERATION, 50}, - {"9244", 20*GB, MODEL_TYPE_REGULAR, THIRD_GENERATION, 50}, - {"8948", 30*GB, MODEL_TYPE_REGULAR, THIRD_GENERATION, 50}, - {"9245", 40*GB, MODEL_TYPE_REGULAR, THIRD_GENERATION, 50}, + {"8976", 10, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_THIRD, 20}, + {"8946", 15, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_THIRD, 50}, + {"9460", 15, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_THIRD, 50}, + {"9244", 20, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_THIRD, 50}, + {"8948", 30, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_THIRD, 50}, + {"9245", 40, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_THIRD, 50}, /* Fourth Generation */ /* Buttons are now integrated into the "touch wheel". */ - {"9282", 20*GB, MODEL_TYPE_REGULAR, FOURTH_GENERATION, 50}, - {"9787", 25*GB, MODEL_TYPE_REGULAR_U2, FOURTH_GENERATION, 50}, - {"9268", 40*GB, MODEL_TYPE_REGULAR, FOURTH_GENERATION, 50}, - {"A079", 20*GB, MODEL_TYPE_COLOR, FOURTH_GENERATION, 50}, - {"A127", 20*GB, MODEL_TYPE_COLOR_U2, FOURTH_GENERATION, 50}, - {"9830", 60*GB, MODEL_TYPE_COLOR, FOURTH_GENERATION, 50}, + {"9282", 20, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"9787", 25, ITDB_IPOD_MODEL_REGULAR_U2, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"9268", 40, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"A079", 20, ITDB_IPOD_MODEL_COLOR, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"A127", 20, ITDB_IPOD_MODEL_COLOR_U2, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"9830", 60, ITDB_IPOD_MODEL_COLOR, ITDB_IPOD_GENERATION_FOURTH, 50}, /* First Generation Mini */ - {"9160", 4*GB, MODEL_TYPE_MINI, FIRST_GENERATION, 6}, - {"9436", 4*GB, MODEL_TYPE_MINI_BLUE, FIRST_GENERATION, 6}, - {"9435", 4*GB, MODEL_TYPE_MINI_PINK, FIRST_GENERATION, 6}, - {"9434", 4*GB, MODEL_TYPE_MINI_GREEN, FIRST_GENERATION, 6}, - {"9437", 4*GB, MODEL_TYPE_MINI_GOLD, FIRST_GENERATION, 6}, + {"9160", 4, ITDB_IPOD_MODEL_MINI, ITDB_IPOD_GENERATION_FIRST, 6}, + {"9436", 4, ITDB_IPOD_MODEL_MINI_BLUE, ITDB_IPOD_GENERATION_FIRST, 6}, + {"9435", 4, ITDB_IPOD_MODEL_MINI_PINK, ITDB_IPOD_GENERATION_FIRST, 6}, + {"9434", 4, ITDB_IPOD_MODEL_MINI_GREEN, ITDB_IPOD_GENERATION_FIRST, 6}, + {"9437", 4, ITDB_IPOD_MODEL_MINI_GOLD, ITDB_IPOD_GENERATION_FIRST, 6}, /* Second Generation Mini */ - {"9800", 4*GB, MODEL_TYPE_MINI, SECOND_GENERATION, 6}, - {"9802", 4*GB, MODEL_TYPE_MINI_BLUE, SECOND_GENERATION, 6}, - {"9804", 4*GB, MODEL_TYPE_MINI_PINK, SECOND_GENERATION, 6}, - {"9806", 4*GB, MODEL_TYPE_MINI_GREEN, SECOND_GENERATION, 6}, - {"9801", 6*GB, MODEL_TYPE_MINI, SECOND_GENERATION, 20}, - {"9803", 6*GB, MODEL_TYPE_MINI_BLUE, SECOND_GENERATION, 20}, - {"9805", 6*GB, MODEL_TYPE_MINI_PINK, SECOND_GENERATION, 20}, - {"9807", 6*GB, MODEL_TYPE_MINI_GREEN, SECOND_GENERATION, 20}, + {"9800", 4, ITDB_IPOD_MODEL_MINI, ITDB_IPOD_GENERATION_SECOND, 6}, + {"9802", 4, ITDB_IPOD_MODEL_MINI_BLUE, ITDB_IPOD_GENERATION_SECOND, 6}, + {"9804", 4, ITDB_IPOD_MODEL_MINI_PINK, ITDB_IPOD_GENERATION_SECOND, 6}, + {"9806", 4, ITDB_IPOD_MODEL_MINI_GREEN, ITDB_IPOD_GENERATION_SECOND, 6}, + {"9801", 6, ITDB_IPOD_MODEL_MINI, ITDB_IPOD_GENERATION_SECOND, 20}, + {"9803", 6, ITDB_IPOD_MODEL_MINI_BLUE, ITDB_IPOD_GENERATION_SECOND, 20}, + {"9805", 6, ITDB_IPOD_MODEL_MINI_PINK, ITDB_IPOD_GENERATION_SECOND, 20}, + {"9807", 6, ITDB_IPOD_MODEL_MINI_GREEN, ITDB_IPOD_GENERATION_SECOND, 20}, /* Photo / Fourth Generation */ /* Buttons are integrated into the "touch wheel". */ - {"9829", 30*GB, MODEL_TYPE_COLOR, FOURTH_GENERATION, 50}, - {"9585", 40*GB, MODEL_TYPE_COLOR, FOURTH_GENERATION, 50}, - {"9586", 60*GB, MODEL_TYPE_COLOR, FOURTH_GENERATION, 50}, - {"9830", 60*GB, MODEL_TYPE_COLOR, FOURTH_GENERATION, 50}, + {"9829", 30, ITDB_IPOD_MODEL_COLOR, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"9585", 40, ITDB_IPOD_MODEL_COLOR, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"9586", 60, ITDB_IPOD_MODEL_COLOR, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"9830", 60, ITDB_IPOD_MODEL_COLOR, ITDB_IPOD_GENERATION_FOURTH, 50}, /* Shuffle / Fourth Generation */ - {"9724", GB/2, MODEL_TYPE_SHUFFLE, FOURTH_GENERATION, 3}, - {"9725", GB, MODEL_TYPE_SHUFFLE, FOURTH_GENERATION, 3}, + {"9724", 0.5,ITDB_IPOD_MODEL_SHUFFLE, ITDB_IPOD_GENERATION_FOURTH, 3}, + {"9725", 1, ITDB_IPOD_MODEL_SHUFFLE, ITDB_IPOD_GENERATION_FOURTH, 3}, /* Nano / Fifth Generation */ /* Buttons are integrated into the "touch wheel". */ - {"A350", 1*GB, MODEL_TYPE_NANO_WHITE, FIFTH_GENERATION, 3}, - {"A352", 1*GB, MODEL_TYPE_NANO_BLACK, FIFTH_GENERATION, 3}, - {"A004", 2*GB, MODEL_TYPE_NANO_WHITE, FIFTH_GENERATION, 3}, - {"A099", 2*GB, MODEL_TYPE_NANO_BLACK, FIFTH_GENERATION, 3}, - {"A005", 4*GB, MODEL_TYPE_NANO_WHITE, FIFTH_GENERATION, 6}, - {"A107", 4*GB, MODEL_TYPE_NANO_BLACK, FIFTH_GENERATION, 6}, + {"A350", 1, ITDB_IPOD_MODEL_NANO_WHITE, ITDB_IPOD_GENERATION_FIFTH, 3}, + {"A352", 1, ITDB_IPOD_MODEL_NANO_BLACK, ITDB_IPOD_GENERATION_FIFTH, 3}, + {"A004", 2, ITDB_IPOD_MODEL_NANO_WHITE, ITDB_IPOD_GENERATION_FIFTH, 3}, + {"A099", 2, ITDB_IPOD_MODEL_NANO_BLACK, ITDB_IPOD_GENERATION_FIFTH, 3}, + {"A005", 4, ITDB_IPOD_MODEL_NANO_WHITE, ITDB_IPOD_GENERATION_FIFTH, 6}, + {"A107", 4, ITDB_IPOD_MODEL_NANO_BLACK, ITDB_IPOD_GENERATION_FIFTH, 6}, /* Video / Fifth Generation */ /* Buttons are integrated into the "touch wheel". */ - {"A002", 30*GB, MODEL_TYPE_VIDEO_WHITE, FIFTH_GENERATION, 50}, - {"A146", 30*GB, MODEL_TYPE_VIDEO_BLACK, FIFTH_GENERATION, 50}, - {"A003", 60*GB, MODEL_TYPE_VIDEO_WHITE, FIFTH_GENERATION, 50}, - {"A147", 60*GB, MODEL_TYPE_VIDEO_BLACK, FIFTH_GENERATION, 50}, + {"A002", 30, ITDB_IPOD_MODEL_VIDEO_WHITE, ITDB_IPOD_GENERATION_FIFTH, 50}, + {"A146", 30, ITDB_IPOD_MODEL_VIDEO_BLACK, ITDB_IPOD_GENERATION_FIFTH, 50}, + {"A003", 60, ITDB_IPOD_MODEL_VIDEO_WHITE, ITDB_IPOD_GENERATION_FIFTH, 50}, + {"A147", 60, ITDB_IPOD_MODEL_VIDEO_BLACK, ITDB_IPOD_GENERATION_FIFTH, 50}, /* HP iPods, need contributions for this table */ /* Buttons are integrated into the "touch wheel". */ - {"E436", 40*GB, MODEL_TYPE_REGULAR, FOURTH_GENERATION, 50}, - {"S492", 30*GB, MODEL_TYPE_COLOR, FOURTH_GENERATION, 50}, + {"E436", 40, ITDB_IPOD_MODEL_REGULAR, ITDB_IPOD_GENERATION_FOURTH, 50}, + {"S492", 30, ITDB_IPOD_MODEL_COLOR, ITDB_IPOD_GENERATION_FOURTH, 50}, /* No known model number -- create a Device/SysInfo file with * one entry, e.g.: ModelNumStr: Mmobile1 */ - {"mobile1", -1, MODEL_TYPE_MOBILE_1, MOBILE_GENERATION}, + {"mobile1", -1, ITDB_IPOD_MODEL_MOBILE_1, ITDB_IPOD_GENERATION_MOBILE}, {NULL, 0, 0, 0, 0} }; -#if 0 static const gchar *ipod_model_name_table [] = { - "Invalid", - "Unknown", - "Color", - "Color U2", - "Grayscale", - "Grayscale U2", - "Mini (Silver)", - "Mini (Blue)", - "Mini (Pink)", - "Mini (Green)", - "Mini (Gold)", - "Shuffle", - "Nano (White)", - "Nano (Black)", - "Video (White)", - "Video (Black)", - "Mobile (1)", + N_("Invalid"), + N_("Unknown"), + N_("Color"), + N_("Color U2"), + N_("Grayscale"), + N_("Grayscale U2"), + N_("Mini (Silver)"), + N_("Mini (Blue)"), + N_("Mini (Pink)"), + N_("Mini (Green)"), + N_("Mini (Gold)"), + N_("Shuffle"), + N_("Nano (White)"), + N_("Nano (Black)"), + N_("Video (White)"), + N_("Video (Black)"), + N_("Mobile (1)"), + NULL +}; + +static const gchar *ipod_generation_name_table [] = { + N_("Unknown"), + N_("First Generation"), + N_("Second Generation"), + N_("Third Generation"), + N_("Fourth Generation"), + N_("Fifth Generation"), + N_("Mobile Phone"), NULL }; -#endif static const Itdb_ArtworkFormat ipod_color_artwork_info[] = { - {IPOD_COVER_SMALL, 56, 56, 1017}, - {IPOD_COVER_LARGE, 140, 140, 1016}, - {IPOD_PHOTO_SMALL, 42, 30, 1009}, - {IPOD_PHOTO_LARGE, 130, 88, 1015}, - {IPOD_PHOTO_FULL_SCREEN, 220, 176, 1013}, - {IPOD_PHOTO_TV_SCREEN, 720, 480, 1019}, - {-1, -1, -1, -1} + {ITDB_THUMB_COVER_SMALL, 56, 56, 1017}, + {ITDB_THUMB_COVER_LARGE, 140, 140, 1016}, + {ITDB_THUMB_PHOTO_SMALL, 42, 30, 1009}, + {ITDB_THUMB_PHOTO_LARGE, 130, 88, 1015}, + {ITDB_THUMB_PHOTO_FULL_SCREEN, 220, 176, 1013}, + {ITDB_THUMB_PHOTO_TV_SCREEN, 720, 480, 1019}, + {-1, -1, -1, -1} }; static const Itdb_ArtworkFormat ipod_nano_artwork_info[] = { - {IPOD_COVER_SMALL, 42, 42, 1031}, - {IPOD_COVER_LARGE, 100, 100, 1027}, - {IPOD_PHOTO_LARGE, 42, 37, 1032}, - {IPOD_PHOTO_FULL_SCREEN, 176, 132, 1023}, - {-1, -1, -1, -1} + {ITDB_THUMB_COVER_SMALL, 42, 42, 1031}, + {ITDB_THUMB_COVER_LARGE, 100, 100, 1027}, + {ITDB_THUMB_PHOTO_LARGE, 42, 37, 1032}, + {ITDB_THUMB_PHOTO_FULL_SCREEN, 176, 132, 1023}, + {-1, -1, -1, -1} }; static const Itdb_ArtworkFormat ipod_video_artwork_info[] = { - {IPOD_COVER_SMALL, 100, 100, 1028}, - {IPOD_COVER_LARGE, 200, 200, 1029}, - {IPOD_PHOTO_SMALL, 50, 41, 1036}, - {IPOD_PHOTO_LARGE, 130, 88, 1015}, - {IPOD_PHOTO_FULL_SCREEN, 320, 240, 1024}, - {IPOD_PHOTO_TV_SCREEN, 720, 480, 1019}, - {-1, -1, -1, -1} + {ITDB_THUMB_COVER_SMALL, 100, 100, 1028}, + {ITDB_THUMB_COVER_LARGE, 200, 200, 1029}, + {ITDB_THUMB_PHOTO_SMALL, 50, 41, 1036}, + {ITDB_THUMB_PHOTO_LARGE, 130, 88, 1015}, + {ITDB_THUMB_PHOTO_FULL_SCREEN, 320, 240, 1024}, + {ITDB_THUMB_PHOTO_TV_SCREEN, 720, 480, 1019}, + {-1, -1, -1, -1} }; static const Itdb_ArtworkFormat ipod_mobile_1_artwork_info[] = { - {IPOD_COVER_SMALL, 50, 50, 2002}, - {IPOD_COVER_LARGE, 150, 150, 2003}, - {-1, -1, -1, -1} + {ITDB_THUMB_COVER_SMALL, 50, 50, 2002}, + {ITDB_THUMB_COVER_LARGE, 150, 150, 2003}, + {-1, -1, -1, -1} }; -/* This will be indexed using a value from the MODEL_TYPE enum */ +/* This will be indexed using a value from the ITDB_IPOD_MODEL enum */ static const Itdb_ArtworkFormat *ipod_artwork_info_table[] = { NULL, /* Invalid */ NULL, /* Unknown */ @@ -373,9 +381,16 @@ gchar *itdb_device_get_sysinfo (Itdb_Device *device, const gchar *field) } -/* Return Itdb_IpodModel entry for this iPod */ -G_GNUC_INTERNAL const Itdb_IpodModel * -itdb_device_get_ipod_model (Itdb_Device *device) +/** + * itdb_device_get_ipod_info: + * @device: an #Itdb_Device + * + * Retrieve the #Itdb_IpodInfo entry for this iPod + * + * Return value: the #Itdb_IpodInfo entry for this iPod + **/ +const Itdb_IpodInfo * +itdb_device_get_ipod_info (Itdb_Device *device) { gint i; gchar *model_num, *p; @@ -383,39 +398,40 @@ itdb_device_get_ipod_model (Itdb_Device *device) model_num = itdb_device_get_sysinfo (device, "ModelNumStr"); if (!model_num) - return &ipod_model_table[0]; + return &ipod_info_table[0]; p = model_num; if(isalpha(model_num[0])) p++; - for(i=2; ipod_model_table[i].model_number != NULL; i++) + for(i=2; ipod_info_table[i].model_number != NULL; i++) { - if(g_strncasecmp(p, ipod_model_table[i].model_number, 4) == 0) + if(g_strncasecmp(p, ipod_info_table[i].model_number, 4) == 0) { g_free(model_num); - return &ipod_model_table[i]; + return &ipod_info_table[i]; } } g_free(model_num); - return &ipod_model_table[1]; + return &ipod_info_table[1]; } + /* Return supported artwork formats supported by this iPod */ G_GNUC_INTERNAL const Itdb_ArtworkFormat * itdb_device_get_artwork_formats (Itdb_Device *device) { - const Itdb_IpodModel *model; + const Itdb_IpodInfo *info; g_return_val_if_fail (device, NULL); - model = itdb_device_get_ipod_model (device); + info = itdb_device_get_ipod_info (device); - g_return_val_if_fail (model, NULL); + g_return_val_if_fail (info, NULL); - return ipod_artwork_info_table[model->model_type]; + return ipod_artwork_info_table[info->ipod_model]; } @@ -559,3 +575,71 @@ itdb_device_autodetect_endianess (Itdb_Device *device) device->byte_order = byte_order; } + +/*------------------------------------------------------------------*\ + * * + * Functions for applications to obtain general infos about various * + * iPods. * + * * +\*------------------------------------------------------------------*/ + +/** + * itdb_info_get_ipod_info_table: + * + * Return a pointer to the start of valid iPod model descriptions, + * which is an array of #Itdb_IpodInfo entries. + * + * Return value: a pointer to the array of #Itdb_IpodInfo entries. + **/ +const Itdb_IpodInfo *itdb_info_get_ipod_info_table (void) +{ + return &ipod_info_table[2]; +} + + +/** + * itdb_info_get_ipod_model_name: + * + * Return the iPod's generic model name, like "Color", "Nano"... + * + * Return value: a pointer to the model name. This is a static string + * and must not be g_free()d. + **/ +const gchar *itdb_info_get_ipod_model_name (Itdb_IpodModel model) +{ + gint i=0; + + /* Instead of returning ipod_model_name_table[model] directly, + verify if @model is valid */ + while (ipod_model_name_table[i]) + { + if (i==model) return gettext (ipod_model_name_table[i]); + ++i; + } + return NULL; +} + + +/** + * itdb_info_get_ipod_generation_name: + * + * Return the iPod's generic generation name, like "First Generation", + * "Mobile Phone"... + * + * Return value: a pointer to the generation name. This is a static + * string and must not be g_free()d. + **/ +const gchar *itdb_info_get_ipod_generation_name (Itdb_IpodGeneration generation) +{ + gint i=0; + + /* Instead of returning ipod_generation_name_table[generation] + directly, verify if @generation is valid */ + while (ipod_generation_name_table[i]) + { + if (i==generation) + return gettext (ipod_generation_name_table[i]); + ++i; + } + return NULL; +} diff --git a/src/itdb_device.h b/src/itdb_device.h index 115e08e..ecd2bfd 100644 --- a/src/itdb_device.h +++ b/src/itdb_device.h @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-05-30 21:53:34 jcs> +/* Time-stamp: <2006-06-04 18:44:50 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -46,7 +46,6 @@ G_BEGIN_DECLS -typedef struct _Itdb_IpodModel Itdb_IpodModel; typedef struct _Itdb_ArtworkFormat Itdb_ArtworkFormat; struct _Itdb_Device @@ -63,66 +62,13 @@ struct _Itdb_Device struct _Itdb_ArtworkFormat { - gint type; + ItdbThumbType type; gint16 width; gint16 height; gint16 correlation_id; }; -struct _Itdb_IpodModel { - const gchar *model_number; - const guint64 capacity; - guint model_type; - guint generation; - /* number of music (Fnn) dirs created by iTunes. The exact - number seems to be version dependent. Therefore, the - numbers here represent a mixture of reported values and - common sense. */ - guint musicdirs; -}; - -typedef enum { - UNKNOWN_GENERATION, - FIRST_GENERATION, - SECOND_GENERATION, - THIRD_GENERATION, - FOURTH_GENERATION, - FIFTH_GENERATION, - MOBILE_GENERATION -} Itdb_Generation; - -typedef enum { - MODEL_TYPE_INVALID, - MODEL_TYPE_UNKNOWN, - MODEL_TYPE_COLOR, - MODEL_TYPE_COLOR_U2, - MODEL_TYPE_REGULAR, - MODEL_TYPE_REGULAR_U2, - MODEL_TYPE_MINI, - MODEL_TYPE_MINI_BLUE, - MODEL_TYPE_MINI_PINK, - MODEL_TYPE_MINI_GREEN, - MODEL_TYPE_MINI_GOLD, - MODEL_TYPE_SHUFFLE, - MODEL_TYPE_NANO_WHITE, - MODEL_TYPE_NANO_BLACK, - MODEL_TYPE_VIDEO_WHITE, - MODEL_TYPE_VIDEO_BLACK, - MODEL_TYPE_MOBILE_1 -} Itdb_ModelType; - - -enum { - IPOD_COVER_SMALL, - IPOD_COVER_LARGE, - IPOD_PHOTO_SMALL, - IPOD_PHOTO_LARGE, - IPOD_PHOTO_FULL_SCREEN, - IPOD_PHOTO_TV_SCREEN -}; - G_GNUC_INTERNAL const Itdb_ArtworkFormat *itdb_device_get_artwork_formats (Itdb_Device *device); -G_GNUC_INTERNAL const Itdb_IpodModel *itdb_device_get_ipod_model (Itdb_Device *device); G_GNUC_INTERNAL gint itdb_device_musicdirs_number (Itdb_Device *device); G_GNUC_INTERNAL void itdb_device_autodetect_endianess (Itdb_Device *device); G_END_DECLS diff --git a/src/itdb_endianness.h b/src/itdb_endianness.h index 4147dd0..95a5cf1 100644 --- a/src/itdb_endianness.h +++ b/src/itdb_endianness.h @@ -14,13 +14,16 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this code; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA * * iTunes and iPod are trademarks of Apple * * This product is not supported/written/published by Apple! * + * $Id$ */ + #ifndef __ITDB_ENDIANNESS_H__ #define __ITDB_ENDIANNESS_H__ @@ -66,4 +69,24 @@ 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) + +/* OK, for 'normal' people an effective summary of what this file is + * doing: + * + * The following inline functions are defined: + * + * guint32 get_guint32 (guint32 val, guint byte_order); + * guint32 get_gint32 (gint32 val, guint byte_order); + * guint32 get_gint16 (gint16 val, guint byte_order); + * guint32 get_gint64 (gint64 val, guint byte_order); + * guint32 get_guint32_db (guint32 val, guint byte_order); + * guint32 get_gint32_db (gint32 val, guint byte_order); + * guint32 get_gint16_db (gint16 val, guint byte_order); + * guint32 get_gint64_db (gint64 val, guint byte_order); + * + + * They are used to retrieve integer data from or store integer data + * to the iPod's databases which may use a different byte order + * (@byte_order) than the host system on which this library runs on. + */ #endif diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c index 2b7a39a..28a9c39 100644 --- a/src/itdb_itunesdb.c +++ b/src/itdb_itunesdb.c @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-06-01 23:31:27 jcs> +/* Time-stamp: <2006-06-05 01:22:23 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -24,7 +24,8 @@ | | You should have received a copy of the GNU Lesser General Public | License along with this code; if not, write to the Free Software -| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +| USA | | iTunes and iPod are trademarks of Apple | @@ -5657,7 +5658,7 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) gchar *pbuf; gint i, dirnum; FILE *sysinfo = NULL; - Itdb_IpodModel const *model = NULL; + Itdb_IpodInfo const *info = NULL; gboolean calconnotes, devicefile; gchar *podpath; @@ -5667,22 +5668,22 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) g_return_val_if_fail (mp, FALSE); /* Retrieve the model from the device information */ - model = itdb_device_get_ipod_model(device); + info = itdb_device_get_ipod_info(device); /* Set up special treatment for shuffle and mobile */ - switch(model->model_type) + switch(info->ipod_model) { - case MODEL_TYPE_SHUFFLE: + case ITDB_IPOD_MODEL_SHUFFLE: podpath = g_strdup ("iPod_Control"); calconnotes = FALSE; devicefile = TRUE; break; - case MODEL_TYPE_MOBILE_1: + case ITDB_IPOD_MODEL_MOBILE_1: podpath = g_build_filename ("iTunes", "iTunes_Control", NULL); calconnotes = FALSE; devicefile = TRUE; break; - case MODEL_TYPE_UNKNOWN: + case ITDB_IPOD_MODEL_UNKNOWN: podpath = g_strdup ("iPod_Control"); calconnotes = TRUE; devicefile = TRUE; @@ -5730,8 +5731,8 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) /* Build Artwork directory only for devices requiring artwork * (assume that 'unknown models' are new and will support * artwork) */ - if (itdb_device_get_artwork_formats(device) || - (model->model_type == MODEL_TYPE_UNKNOWN)) + if (ipod_supports_cover_art(device) || + (info->ipod_model == ITDB_IPOD_MODEL_UNKNOWN)) { pbuf = g_build_filename (mp, podpath, "Artwork", NULL); if (!g_file_test (pbuf, G_FILE_TEST_EXISTS)) @@ -5743,8 +5744,24 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) g_free (pbuf); } + /* Build Photo directory only for devices requiring it */ + if (ipod_supports_photos(device) || + (info->ipod_model == ITDB_IPOD_MODEL_UNKNOWN)) + { + pbuf = g_build_filename (mp, "Photos", "Thumbs", NULL); + if (!g_file_test (pbuf, G_FILE_TEST_EXISTS)) + { + if (mkdir_with_parents(pbuf, 0777) != 0) + { + goto error_dir; + } + } + g_free (pbuf); + } + + /* Build the directories that hold the music files */ - dirnum = model->musicdirs; + dirnum = info->musicdirs; if (dirnum == 0) { /* do a guess */ struct statvfs stat; @@ -5831,7 +5848,7 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) if(sysinfo != NULL) { fprintf(sysinfo, "ModelNumStr:%s", - model->model_number); + info->model_number); fclose(sysinfo); } else diff --git a/src/itdb_photoalbum.c b/src/itdb_photoalbum.c index 3351da0..d204238 100644 --- a/src/itdb_photoalbum.c +++ b/src/itdb_photoalbum.c @@ -273,8 +273,8 @@ gboolean itdb_photodb_add_photo (Itdb_PhotoDB *db, /* Add a thumbnail for every supported format */ format = itdb_device_get_artwork_formats(db->device); for( result = TRUE; format->type != -1 && result == TRUE; format++) { - if( format->type == IPOD_COVER_SMALL - || format->type == IPOD_COVER_LARGE ) + if((format->type == ITDB_THUMB_COVER_SMALL) || + (format->type == ITDB_THUMB_COVER_LARGE)) continue; result = itdb_artwork_add_thumbnail (artwork, format->type, diff --git a/src/itdb_track.c b/src/itdb_track.c index 1e21866..119785c 100644 --- a/src/itdb_track.c +++ b/src/itdb_track.c @@ -1,4 +1,4 @@ -/* Time-stamp: <2006-04-04 00:08:14 jcs> +/* Time-stamp: <2006-06-04 18:08:42 jcs> | | Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net> | Part of the gtkpod project. @@ -35,16 +35,16 @@ static gboolean is_video_ipod (Itdb_Device *device) { - const Itdb_IpodModel *model; + const Itdb_IpodInfo *info; g_return_val_if_fail (device, FALSE); - model = itdb_device_get_ipod_model (device); + info = itdb_device_get_ipod_info (device); - if (!model) return FALSE; + if (!info) return FALSE; - if ((model->model_type == MODEL_TYPE_VIDEO_WHITE) || - (model->model_type == MODEL_TYPE_VIDEO_BLACK)) + if ((info->ipod_model == ITDB_IPOD_MODEL_VIDEO_WHITE) || + (info->ipod_model == ITDB_IPOD_MODEL_VIDEO_BLACK)) return TRUE; else return FALSE; diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c index 58fd279..2aad604 100644 --- a/src/ithumb-writer.c +++ b/src/ithumb-writer.c @@ -718,11 +718,11 @@ itdb_write_ithumb_files (Itdb_DB *db) iThumbWriter *writer; switch (format->type) { - case IPOD_COVER_SMALL: - case IPOD_COVER_LARGE: - case IPOD_PHOTO_SMALL: - case IPOD_PHOTO_LARGE: - case IPOD_PHOTO_FULL_SCREEN: + case ITDB_THUMB_COVER_SMALL: + case ITDB_THUMB_COVER_LARGE: + case ITDB_THUMB_PHOTO_SMALL: + case ITDB_THUMB_PHOTO_LARGE: + case ITDB_THUMB_PHOTO_FULL_SCREEN: ithmb_rearrange_existing_thumbnails (db, format ); writer = ithumb_writer_new (mount_point, |