summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Bastien Nocera2010-12-01 16:09:29 +0100
committerGravatar Nikias Bassen2010-12-01 16:09:29 +0100
commit59d520af8bbb6ff7702575036be387a9875b440d (patch)
tree7aa5a1b59fa2fb099b0b21ef705d01ae2090ce3f
parent652e1793bc8a499d07299356a5f3f28a125c71b9 (diff)
downloadsbmanager-59d520af8bbb6ff7702575036be387a9875b440d.tar.gz
sbmanager-59d520af8bbb6ff7702575036be387a9875b440d.tar.bz2
Stop putting files in /tmp
Whether the wallpaper or the icons themselves, save them in $XDG_CACHE_DIR, and simplify saving.
-rw-r--r--src/device.c35
-rw-r--r--src/device.h2
-rw-r--r--src/gui.c13
-rw-r--r--src/sbitem.c23
4 files changed, 57 insertions, 16 deletions
diff --git a/src/device.c b/src/device.c
index 46a01ee..fbb3ecb 100644
--- a/src/device.c
+++ b/src/device.c
@@ -157,10 +157,7 @@ gboolean device_sbs_save_icon(sbservices_client_t sbc, char *display_identifier,
if ((sbservices_get_icon_pngdata(sbc, display_identifier, &png, &pngsize) == SBSERVICES_E_SUCCESS) && (pngsize > 0)) {
/* save png icon to disk */
- FILE *f = fopen(filename, "w");
- fwrite(png, 1, pngsize, f);
- fclose(f);
- res = TRUE;
+ res = g_file_set_contents (filename, png, pngsize, error);
} else {
if (error)
*error = g_error_new(device_domain, EIO, _("Could not get icon png data for '%s'"), display_identifier);
@@ -193,18 +190,36 @@ gboolean device_sbs_set_iconstate(sbservices_client_t sbc, plist_t iconstate, GE
}
#ifdef HAVE_LIBIMOBILEDEVICE_1_1
-gboolean device_sbs_save_wallpaper(sbservices_client_t sbc, const char *filename, GError **error)
+char *device_sbs_save_wallpaper(sbservices_client_t sbc, const char *uuid, GError **error)
{
- gboolean res = FALSE;
+ char *res = NULL;
char *png = NULL;
uint64_t pngsize = 0;
if ((sbservices_get_home_screen_wallpaper_pngdata(sbc, &png, &pngsize) == SBSERVICES_E_SUCCESS) && (pngsize > 0)) {
/* save png icon to disk */
- FILE *f = fopen(filename, "w");
- fwrite(png, 1, pngsize, f);
- fclose(f);
- res = TRUE;
+ char *path;
+ char *filename;
+
+ path = g_build_filename (g_get_user_cache_dir (),
+ "libimobiledevice",
+ "wallpaper", NULL);
+ g_mkdir_with_parents (path, 0755);
+ g_free (path);
+
+ filename = g_strdup_printf ("%s.png", uuid);
+ path = g_build_filename (g_get_user_cache_dir (),
+ "libimobiledevice",
+ "wallpaper",
+ filename, NULL);
+ g_free (filename);
+
+ if (g_file_set_contents (path, png, pngsize, error) == FALSE) {
+ g_free (filename);
+ free (png);
+ return NULL;
+ }
+ res = path;
} else {
if (error)
*error = g_error_new(device_domain, EIO, _("Could not get wallpaper png data"));
diff --git a/src/device.h b/src/device.h
index f6d0adf..4714368 100644
--- a/src/device.h
+++ b/src/device.h
@@ -42,7 +42,7 @@ void device_sbs_free(sbservices_client_t sbc);
gboolean device_sbs_get_iconstate(sbservices_client_t sbc, plist_t *iconstate, const char *format_version, GError **error);
gboolean device_sbs_save_icon(sbservices_client_t sbc, char *display_identifier, char *filename, GError **error);
gboolean device_sbs_set_iconstate(sbservices_client_t sbc, plist_t iconstate, GError **error);
-gboolean device_sbs_save_wallpaper(sbservices_client_t sbc, const char *filename, GError **error);
+char *device_sbs_save_wallpaper(sbservices_client_t sbc, const char *uuid, GError **error);
device_info_t device_info_new();
void device_info_free(device_info_t device_info);
diff --git a/src/gui.c b/src/gui.c
index f86d677..fcaa34d 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -1808,9 +1808,16 @@ static gboolean gui_pages_init_cb(gpointer user_data)
/* Load wallpaper if available */
if (osversion >= 0x03020000) {
- if (device_sbs_save_wallpaper(sbc, "/tmp/wallpaper.png", &error)) {
- gui_set_wallpaper("/tmp/wallpaper.png");
- }
+ char *path;
+ path = device_sbs_save_wallpaper(sbc, uuid, &error);
+ if (path == NULL) {
+ g_printerr("%s", error->message);
+ g_error_free(error);
+ error = NULL;
+ } else {
+ gui_set_wallpaper(path);
+ }
+ g_free (path);
}
#endif
/* Load icon data */
diff --git a/src/sbitem.c b/src/sbitem.c
index b49a98f..9b49186 100644
--- a/src/sbitem.c
+++ b/src/sbitem.c
@@ -117,9 +117,28 @@ void g_func_sbitem_free(SBItem *item, gpointer data)
char *sbitem_get_icon_filename(SBItem *item)
{
- char *value = sbitem_get_display_identifier(item);
+ static gboolean create_dir = FALSE;
+ const char *value;
+ char *filename, *path;
+
+ if (create_dir == FALSE) {
+ path = g_build_filename (g_get_user_cache_dir (),
+ "libimobiledevice",
+ "icons", NULL);
+ if (g_mkdir_with_parents (path, 0755) >= 0)
+ create_dir = TRUE;
+ g_free (path);
+ }
+
+ value = sbitem_get_display_identifier(item);
if (!value)
return NULL;
- return g_strdup_printf("/tmp/%s.png", value);
+ filename = g_strdup_printf ("%s.png", value);
+ path = g_build_filename (g_get_user_cache_dir (),
+ "libimobiledevice",
+ "icons",
+ filename, NULL);
+ g_free (filename);
+ return path;
}