pidgin/pidgin

90b78170f622
Parents 262fbc598971
Children 11a0f3837a64
Imgupload: fill image file names as link description
--- a/pidgin/plugins/imgupload.c Mon May 19 18:44:57 2014 +0200
+++ b/pidgin/plugins/imgupload.c Mon May 19 21:22:39 2014 +0200
@@ -67,7 +67,7 @@
const gchar *data;
gsize data_len;
PidginWebView *webview = PIDGIN_WEBVIEW(_webview);
- const gchar *url;
+ const gchar *url, *title;
if (!purple_http_response_is_successful(resp)) {
imgup_upload_failed(webview);
@@ -97,8 +97,12 @@
result = json_object_get_object_member(result, "data");
url = json_object_get_string_member(result, "link");
- /* TODO: pass image name here too */
- imgup_upload_done(webview, url, NULL);
+ title = g_object_get_data(G_OBJECT(webview), "imgupload-imgur-name");
+
+ imgup_upload_done(webview, url, title);
+
+ g_object_unref(parser);
+ g_object_set_data(G_OBJECT(webview), "imgupload-imgur-name", NULL);
}
static PurpleHttpConnection *
@@ -126,6 +130,10 @@
purple_http_request_set_contents(req, req_data, -1);
g_free(req_data);
+ /* TODO: set it to hc, not webview (after gobjectifying it) */
+ g_object_set_data_full(G_OBJECT(webview), "imgupload-imgur-name",
+ g_strdup(purple_image_get_friendly_filename(image)), g_free);
+
hc = purple_http_request(NULL, req, imgup_imgur_uploaded, webview);
purple_http_request_unref(req);
@@ -139,10 +147,15 @@
static void
imgup_upload_done(PidginWebView *webview, const gchar *url, const gchar *title)
{
+ PidginWebViewButtons format;
+ gboolean url_desc;
+
g_object_steal_data(G_OBJECT(webview), "imgupload-hc");
- /* TODO: insert text or insert link */
- pidgin_webview_insert_link(webview, url, title ? title : url);
+ format = pidgin_webview_get_format_functions(webview);
+ url_desc = format & PIDGIN_WEBVIEW_LINKDESC;
+
+ pidgin_webview_insert_link(webview, url, url_desc ? title : NULL);
}
static void
--- a/pidgin/plugins/screencap.c Mon May 19 18:44:57 2014 +0200
+++ b/pidgin/plugins/screencap.c Mon May 19 21:22:39 2014 +0200
@@ -298,6 +298,9 @@
PidginWebView *webview = PIDGIN_WEBVIEW(_webview);
GdkPixbuf *result = NULL;
PurpleImage *image;
+ const gchar *fname_prefix;
+ gchar *fname;
+ static guint fname_no = 0;
if (response_id == SCRNCAP_RESPONSE_COLOR)
return;
@@ -316,6 +319,14 @@
return;
image = scrncap_pixbuf_to_image(result);
+
+ /* translators: this is the file name prefix,
+ * keep it lowercase and pure ASCII */
+ fname_prefix = _("screenshot-");
+ fname = g_strdup_printf("%s%u", fname_prefix, ++fname_no);
+ purple_image_set_friendly_filename(image, fname);
+ g_free(fname);
+
pidgin_webview_insert_image(webview, image);
g_object_unref(image);
}