/dev/twasilczyk/imgupload: 90b78170f622: Imgupload: fill image f...

Tomasz Wasilczyk <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 90b78170f62288c516f14a6907c9f19738f69575
Author:	 Tomasz Wasilczyk <[email protected]>
Date:	 2014-05-19 21:22 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/twasilczyk/imgupload/rev/90b78170f622

Description:

Imgupload: fill image file names as link description

diffstat:

 pidgin/plugins/imgupload.c |  23 ++++++++++++++++++-----
 pidgin/plugins/screencap.c |  11 +++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diffs (84 lines):

diff --git a/pidgin/plugins/imgupload.c b/pidgin/plugins/imgupload.c
--- a/pidgin/plugins/imgupload.c
+++ b/pidgin/plugins/imgupload.c
@@ -67,7 +67,7 @@ imgup_imgur_uploaded(PurpleHttpConnectio
 	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 @@ imgup_imgur_uploaded(PurpleHttpConnectio
 	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 @@ imgup_imgur_upload(PidginWebView *webvie
 	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 @@ imgup_imgur_upload(PidginWebView *webvie
 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
diff --git a/pidgin/plugins/screencap.c b/pidgin/plugins/screencap.c
--- a/pidgin/plugins/screencap.c
+++ b/pidgin/plugins/screencap.c
@@ -298,6 +298,9 @@ scrncap_draw_window_response(GtkDialog *
 	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 @@ scrncap_draw_window_response(GtkDialog *
 		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);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.