static int do_add (int argc, char **argv) { GError *error = NULL; Itdb_PhotoAlbum *album = NULL; Itdb_PhotoDB *db; gint i; 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).\nWill attempt to create a new database.\n"), error->message); g_error_free (error); error = NULL; } else { g_print (_("Error reading iPod photo database, will attempt to create a new database\n")); } db = itdb_photodb_create (argv[2]); } /* Find or create specified photoalbum */ if (strcmp (argv[3], "NULL") != 0) { album = itdb_photodb_photoalbum_by_name (db, argv[3]); if (!album) { album = itdb_photodb_photoalbum_create (db, argv[3], -1); } } for (i=4; i<argc; ++i) { Itdb_Artwork *photo; photo = itdb_photodb_add_photo (db, argv[i], -1, GDK_PIXBUF_ROTATE_NONE, &error); if (photo == NULL) { if (error) { g_print (_("Error adding photo (%s) to photo database: %s\n"), argv[i], error->message); g_error_free (error); error = NULL; } } else { if (album) { itdb_photodb_photoalbum_add_photo (db, album, photo, -1); } } } itdb_photodb_write (db, NULL); itdb_photodb_free (db); return 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; }
/* 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 }