changeset 159:b771ddf0b683

should remove old icon files when pidgin-twitter create new one.
author Yoshiki Yazawa <yaz@honeyplnaet.jp>
date Sat, 26 Jul 2008 04:47:47 +0900
parents ae09f0d93b17
children aef26b56a54b
files pidgin-twitter.c pidgin-twitter.h
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Sat Jul 26 03:46:23 2008 +0900
+++ b/pidgin-twitter.c	Sat Jul 26 04:47:47 2008 +0900
@@ -1905,29 +1905,44 @@
     if(ensure_path_exists(dirname)) {
         gchar *filename = NULL;
         gchar *path = NULL;
+        const gchar *suffix = NULL;
+        gchar **extp;
 
         switch(service) {
         case twitter_service:
-            filename = g_strdup_printf("%s_twitter.%s",
-                                       user_name, data->img_type);
+            suffix = "twitter";
             break;
         case wassr_service:
-            filename = g_strdup_printf("%s_wassr.%s",
-                                       user_name, data->img_type);
+            suffix = "wassr";
             break;
         case identica_service:
-            filename = g_strdup_printf("%s_identica.%s",
-                                       user_name, data->img_type);
+            suffix = "identica";
             break;
         default:
             twitter_debug("unknown service\n");
             break;
         }
 
+        /* remove old file first */
+        for(extp = ext_list; *extp; extp++) {
+            filename = g_strdup_printf("%s_%s.%s",
+                                       user_name, suffix, *extp);
+            path = g_build_filename(dirname, filename, NULL);
+            g_remove(path);
+
+            g_free(filename);
+            g_free(path);
+        }
+
+        /* setup path */
+        filename = g_strdup_printf("%s_%s.%s",
+                                   user_name, suffix, data->img_type);
+
         path = g_build_filename(dirname, filename, NULL);
         g_free(filename); filename = NULL;
 
         g_file_set_contents(path, url_text, len, NULL);
+        g_free(path); path = NULL;
 
         data->mtime = time(NULL);
     }
--- a/pidgin-twitter.h	Sat Jul 26 03:46:23 2008 +0900
+++ b/pidgin-twitter.h	Sat Jul 26 04:47:47 2008 +0900
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
+#include <glib/gstdio.h>
 #include <sys/stat.h>
 #include <time.h>
 #include <locale.h>