summaryrefslogtreecommitdiffstats
path: root/src/itdb_device.c
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2007-04-27 14:09:59 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2007-04-27 14:09:59 +0000
commit4e34b34b9c9ea5df23548c86da080b700666f00f (patch)
tree3edd7b23d5848a943cfaa9a177800fc8f94f44e4 /src/itdb_device.c
parent0a8bf8b3ac053452aab77d6842b4f7ae475419e4 (diff)
downloadlibgpod-4e34b34b9c9ea5df23548c86da080b700666f00f.tar.gz
libgpod-4e34b34b9c9ea5df23548c86da080b700666f00f.tar.xz
libgpod-4e34b34b9c9ea5df23548c86da080b700666f00f.zip
* docs/reference/tmpl/device.sgml
docs/reference/tmpl/itunesdb-time.sgml docs/reference/tmpl/libgpod-unused.sgml docs/reference/tmpl/track.sgml src/db-artwork-parser.c src/db-artwork-writer.c src/db-itunes-parser.h src/itdb.h src/itdb_device.c src/itdb_device.h src/itdb_itunesdb.c src/itdb_private.h tests/Makefile.am: Christophe's patch for automatic correction of timestamps depending on which timezone the iPod is set to. ATTENTION DEVELOPERS: as a consequence all exported timestamps are no longer guint32 mac-type timestamps but standard time_t timestamps. This also includes the 64 bit timestamps in smart playlists. The following functions are therefore no longer needed and are deprecated: itdb_time_mac_to_host(), itdb_time_host_to_mac(): simply return the argument without changing it. Argument and return value are now both of type 'time_t'. itunesdb_time_get_mac_time(): returns the seconds passed since Epoch in seconds and is equivalent to time(NULL). These functions may be removed in a future version of libgpod. Programs linking to libgpod may need to be changed slightly if they made any assumptions on the type of timestamps used. This should be obvious through compile-time warnings. tests/test-ls.c: print a list of recently played tracks. git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1417 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/itdb_device.c')
-rw-r--r--src/itdb_device.c80
1 files changed, 76 insertions, 4 deletions
diff --git a/src/itdb_device.c b/src/itdb_device.c
index 35836fb..8c5b9fb 100644
--- a/src/itdb_device.c
+++ b/src/itdb_device.c
@@ -1,6 +1,5 @@
-/* Time-stamp: <27-mar-2007 10:09:48 teuf>
-|
-| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
+/*
+| Copyright (C) 2002-2007 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
|
| URL: http://www.gtkpod.org/
@@ -268,6 +267,8 @@ static const Itdb_ArtworkFormat *ipod_artwork_info_table[] = {
};
+static void itdb_device_set_timezone_info (Itdb_Device *device);
+
/* Reset or create the SysInfo hash table */
static void itdb_device_reset_sysinfo (Itdb_Device *device)
{
@@ -328,8 +329,10 @@ void itdb_device_set_mountpoint (Itdb_Device *device, const gchar *mp)
g_free (device->mountpoint);
device->mountpoint = g_strdup (mp);
- if (mp)
+ if (mp) {
itdb_device_read_sysinfo (device);
+ itdb_device_set_timezone_info (device);
+ }
}
@@ -834,3 +837,72 @@ gboolean itdb_device_supports_photo (Itdb_Device *device)
return (it->type != -1);
}
+
+
+/* This function reads the timezone information from the iPod and sets it in
+ * the Itdb_Device structure. If an error occurs, the function returns silently
+ * and the timezone shift is set to 0
+ */
+static void itdb_device_set_timezone_info (Itdb_Device *device)
+{
+ const gchar *p_preferences[] = {"Preferences", NULL};
+ char *dev_path;
+ char *prefs_filename;
+ FILE *f;
+ gint32 timezone;
+ const int GMT_OFFSET = 0x19;
+ int result;
+
+ device->timezone_shift = 0;
+
+ if (device->mountpoint == NULL) {
+ /* Assumes the iPod is in the UTC timezone for those cases */
+ return;
+ }
+
+ dev_path = itdb_get_device_dir (device->mountpoint);
+
+ if (dev_path == NULL) {
+ return ;
+ }
+
+ prefs_filename = itdb_resolve_path (dev_path, p_preferences);
+ g_free (dev_path);
+
+ f = fopen (prefs_filename, "r");
+ if (f == NULL) {
+ g_free (prefs_filename);
+ return;
+ }
+
+ result = fseek (f, 0xB10, SEEK_SET);
+ if (result != 0) {
+ fclose (f);
+ g_free (prefs_filename);
+ return;
+ }
+
+ result = fread (&timezone, sizeof (timezone), 1, f);
+ if (result != 1) {
+ fclose (f);
+ g_free (prefs_filename);
+ return;
+ }
+
+ fclose (f);
+ g_free (prefs_filename);
+
+ timezone = GINT32_FROM_LE (timezone);
+ if ((timezone < 0) || (timezone > (2*12) << 1)) {
+ /* invalid timezone */
+ return;
+ }
+
+ timezone -= GMT_OFFSET;
+
+ device->timezone_shift = (timezone >> 1) * 3600;
+ if (timezone & 1) {
+ /* Adjust for DST */
+ device->timezone_shift += 3600;
+ }
+}