summaryrefslogtreecommitdiffstats
path: root/src/itdb_device.c
diff options
context:
space:
mode:
authorjcsjcs <jcsjcs@f01d2545-417e-4e96-918e-98f8d0dbbcb6>2006-06-07 15:41:50 +0000
committerjcsjcs <jcsjcs@f01d2545-417e-4e96-918e-98f8d0dbbcb6>2006-06-07 15:41:50 +0000
commitecf6e0643133f75540e17a50320b407143d2b0c4 (patch)
tree2b8204d9d37a11e3316321c23fe4767797461bc0 /src/itdb_device.c
parent2c121fd262a3dba275177b10364e04edacda4431 (diff)
* src/itdb.h
src/itdb_device.c: Added itdb_device_write_sysinfo() and itdb_device_set_sysinfo(). * src/itdb_itunesdb.c (itdb_create_directories): Use functions introduced above. (itdb_write): Write SynsInfo file when writing the iTunesDB if SysInfo hash has been changed by application. * src/itdb_device.[ch]: mark sysinfo hash as changed/unchanged. * src/itdb_photoalbum.c (itdb_photodb_write): Write SynsInfo file when writing the iTunesDB if SysInfo hash has been changed by application. git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1302 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/itdb_device.c')
-rw-r--r--src/itdb_device.c107
1 files changed, 101 insertions, 6 deletions
diff --git a/src/itdb_device.c b/src/itdb_device.c
index 4407a56..4f987b8 100644
--- a/src/itdb_device.c
+++ b/src/itdb_device.c
@@ -1,4 +1,4 @@
-/* Time-stamp: <2006-06-06 00:13:09 jcs>
+/* Time-stamp: <2006-06-07 23:49:33 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -237,6 +237,7 @@ static void itdb_device_reset_sysinfo (Itdb_Device *device)
g_hash_table_destroy (device->sysinfo);
device->sysinfo = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
+ device->sysinfo_changed = FALSE;
}
@@ -343,13 +344,10 @@ gboolean itdb_device_read_sysinfo (Itdb_Device *device)
ptr = strchr (buf, ':');
if (ptr && (ptr!=buf))
{
- gchar *key, *value;
*ptr = 0;
++ptr;
- key = g_strdup (buf);
- g_strstrip (ptr);
- value = g_strdup (ptr);
- g_hash_table_insert (device->sysinfo, key, value);
+ itdb_device_set_sysinfo (device,
+ buf, g_strstrip(ptr));
}
}
fclose (fd);
@@ -357,10 +355,78 @@ gboolean itdb_device_read_sysinfo (Itdb_Device *device)
g_free (sysinfo_path);
}
g_free (dev_path);
+ /* indicate that sysinfo is identical to what is on the iPod */
+ device->sysinfo_changed = FALSE;
return result;
}
+
+/* used by itdb_device_write_sysinfo() */
+static void write_sysinfo_entry (const gchar *key,
+ const gchar *value,
+ FILE *file)
+{
+ fprintf (file, "%s: %s\n", key, value);
+}
+
+
+
+/**
+ * itdb_device_write_sysinfo:
+ * @device: an #Itdb_Device
+ *
+ * Fills the SysInfo file with information in device->sysinfo. Note:
+ * no directories are created if not already existent.
+ *
+ * Return value: TRUE if file could be read, FALSE otherwise
+ **/
+gboolean itdb_device_write_sysinfo (Itdb_Device *device, GError **error)
+{
+ gchar *devicedir;
+ gboolean success = FALSE;
+
+ g_return_val_if_fail (device, FALSE);
+ g_return_val_if_fail (device->mountpoint, FALSE);
+
+ devicedir = itdb_get_device_dir (device->mountpoint);
+ if (devicedir)
+ {
+ gchar *sysfile = g_build_filename (devicedir, "SysInfo", NULL);
+ FILE *sysinfo = fopen (sysfile, "w");
+ if (sysinfo)
+ {
+ if (device->sysinfo)
+ {
+ g_hash_table_foreach (device->sysinfo,
+ (GHFunc)write_sysinfo_entry,
+ sysinfo);
+ }
+ fclose (sysinfo);
+ success = TRUE;
+ }
+ else
+ {
+ g_set_error (error, 0, -1,
+ _("Could not open '%s' for writing."),
+ sysfile);
+ }
+ g_free (sysfile);
+ g_free (devicedir);
+ }
+ else
+ {
+ g_set_error (error, 0, -1,
+ _("Device directory does not exist."));
+ }
+
+ if (success)
+ device->sysinfo_changed = FALSE;
+
+ return success;
+}
+
+
/**
* itdb_device_get_sysinfo:
* @device: an #Itdb_Device
@@ -380,6 +446,35 @@ gchar *itdb_device_get_sysinfo (Itdb_Device *device, const gchar *field)
return g_strdup (g_hash_table_lookup (device->sysinfo, field));
}
+/**
+ * itdb_device_set_sysinfo:
+ * @device: an #Itdb_Device
+ * @field: field to set
+ * @value: value to set (or NULL to remove the field).
+ *
+ * Set specified field. It can later be written to the iPod using
+ * itdb_device_read_sysinfo
+ *
+ **/
+void itdb_device_set_sysinfo (Itdb_Device *device,
+ const gchar *field, const gchar *value)
+{
+ g_return_if_fail (device);
+ g_return_if_fail (device->sysinfo);
+ g_return_if_fail (field);
+
+ if (field)
+ {
+ g_hash_table_insert (device->sysinfo,
+ g_strdup (field), g_strdup (value));
+ }
+ else
+ {
+ g_hash_table_remove (device->sysinfo, field);
+ }
+ device->sysinfo_changed = TRUE;
+}
+
/**
* itdb_device_get_ipod_info: