summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2005-09-13 14:13:00 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2005-09-13 14:13:00 +0000
commit3e2c5a53303d7098198c9a092a1a61c3a6113b02 (patch)
tree4a4ff35edbf59a6928c9ff470160ee20337d88e2
parent7937d11c974cdaf96b0ba7b22f96df77b306a123 (diff)
downloadlibgpod-3e2c5a53303d7098198c9a092a1a61c3a6113b02.tar.gz
libgpod-3e2c5a53303d7098198c9a092a1a61c3a6113b02.tar.xz
libgpod-3e2c5a53303d7098198c9a092a1a61c3a6113b02.zip
* itdb_itunesdb: changed API for itdb_filename_on_ipod ()
* itdb.h: added 'gint musicdirs' to Itdb_iTunesDB (number of F.. dirs available) * itdb_itunesdb: itdb_cp_track_to_ipod() will now determine the number of available F.. dirs before copying by calling new function itdb_count_musicdirs() git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1088 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r--ChangeLog9
-rw-r--r--README2
-rw-r--r--po/Makefile.in.in41
-rw-r--r--src/itdb.h8
-rw-r--r--src/itdb_itunesdb.c101
5 files changed, 123 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index 468211e..dc9d25a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-09-13 Jorg Schuler <jcsjcs at users.sourceforge.net>
+
+ * itdb_itunesdb: changed API for itdb_filename_on_ipod ()
+ * itdb.h: added 'gint musicdirs' to Itdb_iTunesDB (number of
+ F.. dirs available)
+ * itdb_itunesdb: itdb_cp_track_to_ipod() will now determine the
+ number of available F.. dirs before copying by calling new
+ function itdb_count_musicdirs()
+
2005-09-11 Jorg Schuler <jcsjcs at users.sourceforge.net>
* configure.ac: changed position of AC_GNU_SOURCE (caused error
diff --git a/README b/README
index df333ad..e82ef3d 100644
--- a/README
+++ b/README
@@ -2,7 +2,7 @@ libgpod is a library meant to abstract access to an iPod content. It
provides an easy to use API to retrieve the list of files and playlist
stored on an iPod, to modify them and to save them back to the iPod.
-This code was originally part of gtkpod (www.gtkpod.org), when the iPod
+This code was originally part of gtkpod (www.gtkpod.org). When the iPod
content parsing code was made to be self-contained with gtkpod 0.93,
we chose to put this code in a separate library so that other project
can benefit from it without duplicating code.
diff --git a/po/Makefile.in.in b/po/Makefile.in.in
index 1a6961e..22cadc6 100644
--- a/po/Makefile.in.in
+++ b/po/Makefile.in.in
@@ -11,11 +11,6 @@
#
# - Modified by jacob berkman <jacob@ximian.com> to install
# Makefile.in.in and po2tbl.sed.in for use with glib-gettextize
-#
-# - Modified by Rodney Dawes <dobey@novell.com> for use with intltool
-#
-# We have the following line for use by intltoolize:
-# INTLTOOL_MAKEFILE
GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
PACKAGE = @PACKAGE@
@@ -32,13 +27,13 @@ VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
datadir = @datadir@
-datarootdir = @datarootdir@
libdir = @libdir@
localedir = $(libdir)/locale
gnulocaledir = $(datadir)/locale
gettextsrcdir = $(datadir)/glib-2.0/gettext/po
subdir = po
install_sh = @install_sh@
+mkdir_p = @mkdir_p@
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
INSTALL = @INSTALL@
@@ -66,8 +61,7 @@ SOURCES =
POFILES = @POFILES@
GMOFILES = @GMOFILES@
DISTFILES = ChangeLog Makefile.in.in POTFILES.in \
-$(POFILES) $(SOURCES)
-EXTRA_DISTFILES = POTFILES.skip Makevars LINGUAS
+$(POFILES) $(GMOFILES) $(SOURCES)
POTFILES = \
@@ -83,7 +77,7 @@ INSTOBJEXT = @INSTOBJEXT@
.po.pox:
$(MAKE) $(GETTEXT_PACKAGE).pot
- $(MSGMERGE) $< $(GETTEXT_PACKAGE).pot -o $*.pox
+ $(MSGMERGE) $< $(top_builddir)/po/$(GETTEXT_PACKAGE).pot -o $*pox
.po.mo:
$(MSGFMT) -o $@ $<
@@ -180,7 +174,7 @@ uninstall:
rm -f $(DESTDIR)$(gettextsrcdir)/Makefile.in.in; \
fi
-check: all $(GETTEXT_PACKAGE).pot
+check: all
dvi info tags TAGS ID:
@@ -192,21 +186,16 @@ mostlyclean:
clean: mostlyclean
distclean: clean
- rm -f Makefile Makefile.in POTFILES
- rm -f *.mo *.msg *.cat *.cat.m $(GMOFILES)
+ rm -f Makefile Makefile.in POTFILES *.mo *.msg *.cat *.cat.m
maintainer-clean: distclean
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
- rm -f Makefile.in.in
+ rm -f $(GMOFILES)
distdir = ../$(GETTEXT_PACKAGE)-$(VERSION)/$(subdir)
-dist distdir: $(DISTFILES)
+dist distdir: $(DISTFILES) $(GETTEXT_PACKAGE).pot
dists="$(DISTFILES)"; \
- extra_dists="$(EXTRA_DISTFILES)"; \
- for file in $$extra_dists; do \
- test -f $$file && dists="$$dists $$file"; \
- done; \
for file in $$dists; do \
ln $(srcdir)/$$file $(distdir) 2> /dev/null \
|| cp -p $(srcdir)/$$file $(distdir); \
@@ -243,13 +232,17 @@ update-po: Makefile
# and Intltool tags (enclosed in square brackets), and appending a full
# relative path to them
POTFILES: POTFILES.in
- ( posrcprefix='$(top_srcdir)/'; \
+ ( if test 'x$(srcdir)' != 'x.'; then \
+ posrcprefix='$(top_srcdir)/'; \
+ else \
+ posrcprefix="../"; \
+ fi; \
rm -f $@-t $@ \
- && (sed -e '/^#/d' \
- -e 's/^[[].*] *//' \
- -e '/^[ ]*$$/d' \
- -e "s@^@ $$posrcprefix@" $(srcdir)/$@.in \
- | sed -e '$$!s/$$/ \\/') > $@-t \
+ && (sed -e '/^#/d' \
+ -e "s/^\[.*\] +//" \
+ -e '/^[ ]*$$/d' \
+ -e "s@.*@ $$posrcprefix& \\\\@" < $(srcdir)/$@.in \
+ | sed -e '$$s/\\$$//') > $@-t \
&& chmod a-w $@-t \
&& mv $@-t $@ )
diff --git a/src/itdb.h b/src/itdb.h
index 4a14892..229349f 100644
--- a/src/itdb.h
+++ b/src/itdb.h
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-09-11 17:51:54 jcs>
+/* Time-stamp: <2005-09-13 22:40:34 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -317,6 +317,7 @@ typedef struct
GList *playlists;
gchar *filename; /* filename of iTunesDB */
gchar *mountpoint; /* mountpoint of iPod (if available) */
+ gint musicdirs; /* number of /iPod_Control/Music/F.. dirs */
guint32 version;
guint64 id;
/* below is for use by application */
@@ -442,13 +443,14 @@ guint32 itdb_playlists_number (Itdb_iTunesDB *itdb);
gchar * itdb_resolve_path (const gchar *root,
const gchar * const * components);
gboolean itdb_rename_files (const gchar *mp, GError **error);
-gboolean itdb_cp_track_to_ipod (const gchar *mp, Itdb_Track *track,
+gboolean itdb_cp_track_to_ipod (Itdb_Track *track,
gchar *filename, GError **error);
gboolean itdb_cp (const gchar *from_file, const gchar *to_file,
GError **error);
void itdb_filename_fs2ipod (gchar *filename);
void itdb_filename_ipod2fs (gchar *ipod_file);
-gchar *itdb_filename_on_ipod (const gchar *mp, Itdb_Track *track);
+gchar *itdb_filename_on_ipod (Itdb_Track *track);
+void itdb_set_mountpoint (Itdb_iTunesDB *itdb, const gchar *mp);
/* track functions */
Itdb_Track *itdb_track_new (void);
diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c
index 167459b..6c6d53b 100644
--- a/src/itdb_itunesdb.c
+++ b/src/itdb_itunesdb.c
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-08-29 23:23:59 jcs>
+/* Time-stamp: <2005-09-13 23:12:02 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -3313,9 +3313,58 @@ void itdb_filename_ipod2fs (gchar *ipod_file)
+/* Set the mountpoint.
+ *
+ * Always use this function to set the mountpoint as it will reset the
+ * number of available /iPod_Control/Music/F.. dirs
+*/
+void itdb_set_mountpoint (Itdb_iTunesDB *itdb, const gchar *mp)
+{
+ g_return_if_fail (itdb);
+
+ g_free (itdb->mountpoint);
+ itdb->mountpoint = g_strdup (mp);
+ itdb->musicdirs = 0;
+}
+
+
+
+static void itdb_count_musicdirs (Itdb_iTunesDB *itdb)
+{
+ gchar *dest_components[] = {"iPod_Control", "Music",
+ NULL, NULL, NULL};
+ gchar *dir_filename = NULL;
+ gint dir_num;
+
+ g_return_if_fail (itdb);
+ g_return_if_fail (itdb->mountpoint);
+
+ for (dir_num=0; ;++dir_num)
+ {
+ gchar dir_num_str[5];
+
+ g_snprintf (dir_num_str, 5, "F%02d", dir_num);
+ dest_components[2] = dir_num_str;
+
+ dir_filename =
+ itdb_resolve_path (itdb->mountpoint,
+ (const gchar **)dest_components);
+
+ if (!dir_filename) break;
+ g_free (dir_filename);
+ }
+
+ itdb->musicdirs = dir_num;
+}
+
+
+
+
/* Copy one track to the iPod. The PC filename is @filename
and is taken literally.
- @path is the mountpoint of the iPod (in local encoding).
+
+ The mountpoint of the iPod (in local encoding) is expected in
+ track->itdb->mountpoint.
If @track->transferred is set to TRUE, nothing is done. Upon
successful transfer @track->transferred is set to TRUE.
@@ -3330,22 +3379,28 @@ void itdb_filename_ipod2fs (gchar *ipod_file)
If @track->ipod_path is already set, this one will be used
instead. If a file with this name already exists, it will be
overwritten. */
-gboolean itdb_cp_track_to_ipod (const gchar *mp, Itdb_Track *track,
+gboolean itdb_cp_track_to_ipod (Itdb_Track *track,
gchar *filename, GError **error)
{
static gint dir_num = -1;
gchar *track_db_path, *ipod_fullfile;
gboolean success;
gint mplen = 0;
+ const gchar *mp;
+ Itdb_iTunesDB *itdb;
- g_return_val_if_fail (mp, FALSE);
g_return_val_if_fail (track, FALSE);
+ g_return_val_if_fail (track->itdb, FALSE);
+ g_return_val_if_fail (track->itdb->mountpoint, FALSE);
g_return_val_if_fail (filename, FALSE);
if(track->transferred) return TRUE; /* nothing to do */
+ mp = track->itdb->mountpoint;
+ itdb = track->itdb;
+
/* If track->ipod_path exists, we use that one instead. */
- ipod_fullfile = itdb_filename_on_ipod (mp, track);
+ ipod_fullfile = itdb_filename_on_ipod (track);
if (!ipod_fullfile)
{
@@ -3357,9 +3412,26 @@ gboolean itdb_cp_track_to_ipod (const gchar *mp, Itdb_Track *track,
gint32 oops = 0;
gint32 rand = g_random_int_range (0, 899999); /* 0 to 900000 */
- if (dir_num == -1) dir_num = g_random_int_range (0, 20);
- else dir_num = (dir_num + 1) % 20;
-
+ if (itdb->musicdirs <= 0)
+ itdb_count_musicdirs (itdb);
+
+ if (itdb->musicdirs <= 0)
+ {
+ gchar *str = g_build_filename (mp, dest_components[0],
+ dest_components[1], NULL);
+
+ g_set_error (error,
+ ITDB_FILE_ERROR,
+ ITDB_FILE_ERROR_NOTFOUND,
+ _("No 'F..' directories found in '%s'."),
+ str);
+ g_free (str);
+ return FALSE;
+ }
+
+ if (dir_num == -1) dir_num = g_random_int_range (0, itdb->musicdirs);
+ else dir_num = (dir_num + 1) % itdb->musicdirs;
+
g_snprintf (dir_num_str, 5, "F%02d", dir_num);
dest_components[2] = dir_num_str;
@@ -3445,7 +3517,10 @@ gboolean itdb_cp_track_to_ipod (const gchar *mp, Itdb_Track *track,
/* Return the full iPod filename as stored in @track. Return value
must be g_free()d after use.
- @mp: mount point of the iPod file system (in local encoding)
+
+ mount point of the iPod file system (in local encoding) is expected
+ in track->itdb->mountpoint
+
@track: track
Return value: full filename to @track on the iPod or NULL if no
filename is set in @track.
@@ -3456,11 +3531,17 @@ gboolean itdb_cp_track_to_ipod (const gchar *mp, Itdb_Track *track,
itdb_resolve_path() ) and might return a filename with different
case than the original filename. Don't copy it back to @track
unless you must */
-gchar *itdb_filename_on_ipod (const gchar *mp, Itdb_Track *track)
+gchar *itdb_filename_on_ipod (Itdb_Track *track)
{
gchar *result = NULL;
+ const gchar *mp;
g_return_val_if_fail (track, NULL);
+ g_return_val_if_fail (track->itdb, NULL);
+
+ if (!track->itdb->mountpoint) return NULL;
+
+ mp = track->itdb->mountpoint;
if(track->ipod_path && *track->ipod_path)
{