changeset 310:aa1f0dd1a723

use .dat extension for icons uniformly.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 02 Jul 2009 15:54:44 +0900
parents e922ad73c07e
children 5a22c65d019c
files icon.c pidgin-twitter.h
diffstat 2 files changed, 54 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/icon.c	Thu Jul 02 05:54:58 2009 +0900
+++ b/icon.c	Thu Jul 02 15:54:44 2009 +0900
@@ -4,14 +4,6 @@
 extern GHashTable *icon_hash[];
 extern GRegex *regp[];
 
-static gchar *ext_list[] = {
-    ".png",
-    ".gif",
-    ".jpg",
-    ".bmp",
-    NULL
-};
-
 /* prototypes */
 static void insert_icon_at_mark(GtkTextMark *requested_mark, gpointer user_data);
 static void insert_requested_icon(const gchar *user_name, gint service);
@@ -294,16 +286,15 @@
     data->use_count = 0;
     data->mtime = time(NULL); /* xxx is there a better way? */
 
-    twitter_debug("requested url=%s\n", url);
-
     /* request fetch image */
     if(url) {
+        twitter_debug("request %s's icon\n", user_name);
+        twitter_debug("requested url = %s\n", url);
         /* reuse gotdata. just pass given one */
         /* gotdata will be released in got_icon_cb */
         data->fetch_data =
             purple_util_fetch_url_request(url, TRUE, NULL, TRUE, NULL,
                                           FALSE, got_icon_cb, gotdata);
-        twitter_debug("request %s's icon\n", user_name);
         g_free(url);
     }
 }
@@ -440,30 +431,6 @@
     if(hash)
         g_hash_table_insert(hash, g_strdup(user_name), data);
 
-    /* find out extension */
-    gchar *slash = strrchr(url_data->url, '/');
-    gchar *lower = g_ascii_strdown(purple_url_decode(slash+1), -1);
-
-    gchar **extp;
-    data->img_type = NULL;
-
-    for(extp = ext_list; *extp; extp++) {
-        if(g_strrstr(lower, *extp)) {
-            data->img_type = *extp+1;
-            break;
-        }
-    }
-    if(!data->img_type && g_strrstr(lower, ".jpeg"))
-        data->img_type = ext_list[2]+1; /* jpg */
-
-    g_free(lower);
-
-    /* return if no suitable image found */
-    if(!data->img_type) {
-        g_free(gotdata->user_name);
-        g_free(gotdata);
-        return;
-    }
 
     dirname = purple_prefs_get_string(OPT_ICON_DIR);
 
@@ -472,7 +439,6 @@
         gchar *filename = NULL;
         gchar *path = NULL;
         const gchar *suffix = NULL;
-        gchar **extp;
 
         switch(service) {
         case twitter_service:
@@ -496,19 +462,17 @@
         }
 
         /* 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);
+        filename = g_strdup_printf("%s_%s.dat",
+                                   user_name, suffix);
+        path = g_build_filename(dirname, filename, NULL);
+        g_remove(path);
 
-            g_free(filename);
-            g_free(path);
-        }
+        g_free(filename);
+        g_free(path);
 
         /* setup path */
-        filename = g_strdup_printf("%s_%s.%s",
-                                   user_name, suffix, data->img_type);
+        filename = g_strdup_printf("%s_%s.dat",
+                                   user_name, suffix);
 
         path = g_build_filename(dirname, filename, NULL);
         g_free(filename); filename = NULL;
@@ -581,57 +545,52 @@
     /* check if saved file exists */
     if(suffix && !renew) {
         gchar *filename = NULL;
-        gchar **extp;
 
-        for(extp = ext_list; *extp; extp++) {
-            filename = g_strdup_printf("%s_%s.%s", user_name, suffix, *extp);
-            path = g_build_filename(purple_prefs_get_string(OPT_ICON_DIR),
-                                    filename, NULL);
-            g_free(filename);
+        filename = g_strdup_printf("%s_%s.dat", user_name, suffix);
+        path = g_build_filename(purple_prefs_get_string(OPT_ICON_DIR),
+                                filename, NULL);
+        g_free(filename);
+
+        twitter_debug("path = %s\n", path);
 
-            twitter_debug("path = %s\n", path);
-
-            /* build image from file, if file exists */
-            if(g_file_test(path, G_FILE_TEST_EXISTS)) {
-                gchar *imgdata = NULL;
-                size_t len;
-                GError *err = NULL;
-                GdkPixbuf *pixbuf = NULL;
-                struct stat buf;
+        /* build image from file, if file exists */
+        if(g_file_test(path, G_FILE_TEST_EXISTS)) {
+            gchar *imgdata = NULL;
+            size_t len;
+            GError *err = NULL;
+            GdkPixbuf *pixbuf = NULL;
+            struct stat buf;
 
-                if (!g_file_get_contents(path, &imgdata, &len, &err)) {
-                    twitter_debug("Error reading %s: %s\n",
-                                  path, err->message);
-                    g_error_free(err);
-                }
+            if (!g_file_get_contents(path, &imgdata, &len, &err)) {
+                twitter_debug("Error reading %s: %s\n",
+                              path, err->message);
+                g_error_free(err);
+            }
 
-                if(stat(path, &buf))
-                    data->mtime = buf.st_mtime;
-
-                pixbuf = make_scaled_pixbuf(imgdata, len);
-                g_free(imgdata);
+            if(stat(path, &buf))
+                data->mtime = buf.st_mtime;
 
-                if(pixbuf) {
-                    data->pixbuf = pixbuf;
+            pixbuf = make_scaled_pixbuf(imgdata, len);
+            g_free(imgdata);
 
-                    twitter_debug("new icon pixbuf = %p size = %d\n",
-                                  pixbuf,
-                                  gdk_pixbuf_get_rowstride(pixbuf) *
-                                  gdk_pixbuf_get_height(pixbuf));
+            if(pixbuf) {
+                data->pixbuf = pixbuf;
 
-                    data->img_type = *extp;
+                twitter_debug("new icon pixbuf = %p size = %d\n",
+                              pixbuf,
+                              gdk_pixbuf_get_rowstride(pixbuf) *
+                              gdk_pixbuf_get_height(pixbuf));
 
-                    twitter_debug("icon data has been loaded from file\n");
-                    insert_requested_icon(user_name, service);
-                }
-
-                g_free(path);
-                return;
+                twitter_debug("icon data has been loaded from file\n");
+                insert_requested_icon(user_name, service);
             }
 
             g_free(path);
+            return;
+        }
 
-        } /* for */
+        g_free(path);
+
     } /* suffix */
 
     /* Return if user's icon has been requested already. */
@@ -648,8 +607,8 @@
     case wassr_service:
         url = g_strdup_printf("http://wassr.jp/user/%s", user_name);
         break;
-    case identica_service: /* make use of Version0 API */
-        url = g_strdup_printf("http://identi.ca/%s/avatar/96", user_name);
+    case identica_service:
+        url = g_strdup_printf("http://identi.ca/%s", user_name);
         break;
     case jisko_service:
         url = g_strdup_printf("http://jisko.net/%s", user_name);
@@ -667,23 +626,26 @@
         gotdata->user_name = g_strdup(user_name);
         gotdata->service = service;
 
+        twitter_debug("request %s's icon\n", user_name);
+
         /* gotdata will be released in got_icon_cb */
         if(service == twitter_service ||
            service == wassr_service ||
+           service == identica_service ||
            service == jisko_service ||
            service == ffeed_service) {
             data->fetch_data =
                 purple_util_fetch_url_request(url, TRUE, NULL, TRUE, NULL,
                                               TRUE, got_page_cb, gotdata);
+            twitter_debug("requested url = %s\n", url);
         }
-        else { /* typically, identica_service */
+        else { /* probably it is unnecessary */
             data->fetch_data =
                 purple_util_fetch_url_request(url, TRUE, NULL, TRUE, NULL,
                                               FALSE, got_icon_cb, gotdata);
+            twitter_debug("requested url = %s\n", url);
         }
         g_free(url); url = NULL;
-
-        twitter_debug("request %s's icon\n", user_name);
     }
 }
 
--- a/pidgin-twitter.h	Thu Jul 02 05:54:58 2009 +0900
+++ b/pidgin-twitter.h	Thu Jul 02 15:54:44 2009 +0900
@@ -68,7 +68,6 @@
     gboolean requested;     /* TRUE if download icon has been requested */
     GList *request_list;    /* marker list */
     PurpleUtilFetchUrlData *fetch_data; /* icon fetch data */
-    const gchar *img_type;  /* image type */
     gchar *icon_url;        /* url for the user's icon */
     gint use_count;         /* usage count */
     time_t mtime;           /* mtime of file */
@@ -189,7 +188,7 @@
 #define P_GROUP_IDENTICA    "!([-A-Za-z0-9_]+)"
 #define P_IMAGE_TWITTER     "<img .*=\"profile-(?:image|img)\".*src=\"(https?://.+?)\".*/>"
 #define P_IMAGE_WASSR       "<div class=\"image\"><a href=\".+\"><img src=\"(.+)\" width=\".+?\" /></a></div>"
-#define P_IMAGE_IDENTICA    "<img src=\"(https?://.+.identi.ca/.+)\" class=\"avatar profile photo\" width=\"96\" height=\"96\" alt=\"[A-Za-z0-9_]+\"/>"
+#define P_IMAGE_IDENTICA    "<img src=\"(https?://.+.identi.ca/.+)\" class=\"photo avatar\""
 #define P_IMAGE_JISKO       "<img src=\"(https?://jisko.net/users/.+/img/avatar/thumb_side\\..+)\" alt=\"Avatar\" />"
 #define P_IMAGE_FFEED       "<img src=\"(https?://i.friendfeed.com/.+)\" alt=\""
 #define P_SIZE_128_WASSR    "\\.128\\."
@@ -217,7 +216,7 @@
 
 /* identica specific macros */
 #define IDENTICA_POST_LEN (140)
-#define IDENTICA_DEFAULT_ICON_URL "http://theme.identi.ca/identica/default-avatar-profile.png"
+#define IDENTICA_DEFAULT_ICON_URL "http://theme.status.net/0.8.0dev/identica/default-avatar-profile.png"
 
 /* jisko specific macro */
 #define JISKO_DEFAULT_ICON_URL "http://jisko.net/static/img/avatar/default_note.png"