/* Frees 'urls' */ static void process_urls(PurpleConversation *conv, GList *urls) { GList *iter; int c; FinchConv *fconv = FINCH_CONV(conv); GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); for (iter = urls, c = 1; iter; iter = iter->next, c++) { int i; CbInfo *cbdata; gchar *url, *str; gchar *original_url; const gchar *tiny_url; i = gnt_text_view_get_lines_below(tv); original_url = purple_unescape_html((char *)iter->data); tiny_url = g_hash_table_lookup(tinyurl_cache, original_url); if (tiny_url) { gchar *str = g_strdup_printf("\n[%d] %s", c, tiny_url); g_free(original_url); gnt_text_view_append_text_with_flags(tv, str, GNT_TEXT_FLAG_DIM); if (i == 0) gnt_text_view_scroll(tv, 0); g_free(str); continue; } cbdata = g_new(CbInfo, 1); cbdata->num = c; cbdata->original_url = original_url; cbdata->tag = g_strdup_printf("%s%d", "tiny_", tag_num++); cbdata->conv = conv; if (g_ascii_strncasecmp(original_url, "http://", 7) && g_ascii_strncasecmp(original_url, "https://", 8)) { url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); } else { url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); } purple_http_get(NULL, url_fetched, cbdata, url); str = g_strdup_printf(_("\nFetching TinyURL...")); gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag); g_free(str); if (i == 0) gnt_text_view_scroll(tv, 0); g_free(iter->data); g_free(url); } g_list_free(urls); }
static void * tinyurl_notify_uri(const char *uri) { char *fullurl = NULL; GntWidget *win; PurpleHttpConnection *hc; const gchar *tiny_url; /* XXX: The following expects that finch_notify_message gets called. This * may not always happen, e.g. when another plugin sets its own * notify_message. So tread carefully. */ win = purple_notify_message(NULL, PURPLE_NOTIFY_MSG_INFO, _("URI"), uri, _("Please wait while TinyURL fetches a shorter URL ..."), NULL, NULL, NULL); if (!GNT_IS_WINDOW(win) || !g_object_get_data(G_OBJECT(win), "info-widget")) return win; tiny_url = g_hash_table_lookup(tinyurl_cache, uri); if (tiny_url) { tinyurl_notify_tinyuri(win, tiny_url); return win; } if (g_ascii_strncasecmp(uri, "http://", 7) && g_ascii_strncasecmp(uri, "https://", 8)) { fullurl = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(uri)); } else { fullurl = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(uri)); } g_object_set_data_full(G_OBJECT(win), "gnttinyurl-original", g_strdup(uri), g_free); /* Store the return value of purple_http_get and destroy that when win * is destroyed, so that the callback for purple_http_get does not try * to molest a non-existent window */ hc = purple_http_get(NULL, tinyurl_notify_fetch_cb, win, fullurl); g_free(fullurl); g_signal_connect_swapped(G_OBJECT(win), "destroy", G_CALLBACK(purple_http_conn_cancel), hc); return win; }
void fb_data_image_queue(FbData *fata) { const gchar *url; FbDataImage *img; FbDataPrivate *priv; GHashTableIter iter; guint active = 0; g_return_if_fail(FB_IS_DATA(fata)); priv = fata->priv; g_hash_table_iter_init(&iter, priv->imgs); while (g_hash_table_iter_next(&iter, (gpointer*) &img, NULL)) { if (fb_data_image_get_active(img)) { active++; } } if (active >= FB_DATA_ICON_MAX) { return; } g_hash_table_iter_init(&iter, priv->imgs); while (g_hash_table_iter_next(&iter, (gpointer*) &img, NULL)) { if (fb_data_image_get_active(img)) { continue; } img->priv->active = TRUE; url = fb_data_image_get_url(img); purple_http_get(priv->gc, fb_data_image_cb, img, url); if (++active >= FB_DATA_ICON_MAX) { break; } } }