summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@gentoo.org>2012-02-20 03:45:39 +0530
committerNirbheek Chauhan <nirbheek@gentoo.org>2012-02-20 03:45:46 +0530
commit9b958cb3244f6100d2916226f47ca64f1b684f9b (patch)
treeaeeb902bddf362f7f0c8177cedb3338bc0b6aae4
parentBrown-paper-bag fix (diff)
downloadnirbheek-9b958cb3244f6100d2916226f47ca64f1b684f9b.tar.gz
nirbheek-9b958cb3244f6100d2916226f47ca64f1b684f9b.tar.bz2
nirbheek-9b958cb3244f6100d2916226f47ca64f1b684f9b.zip
gnome-extra/gnome-utils: new, improved screenshot uploading patch!
-rw-r--r--gnome-extra/gnome-utils/Manifest2
-rw-r--r--gnome-extra/gnome-utils/files/gnome-utils-3.2.1-upload-screenshots.patch301
2 files changed, 241 insertions, 62 deletions
diff --git a/gnome-extra/gnome-utils/Manifest b/gnome-extra/gnome-utils/Manifest
index 5631d47..ede1c53 100644
--- a/gnome-extra/gnome-utils/Manifest
+++ b/gnome-extra/gnome-utils/Manifest
@@ -1,3 +1,3 @@
-AUX gnome-utils-3.2.1-upload-screenshots.patch 13009 RMD160 8121d8052f98f8f285555ff9f16da7e113cd0968 SHA1 5a23536030b04725caa4a1ac45f98ae9f9531090 SHA256 13807ea2e9ae6cb7228a57d9100dfa803d3ba29f7c17428464e8375af54f1d12
+AUX gnome-utils-3.2.1-upload-screenshots.patch 19253 RMD160 3713b8f89e33cf16a762207e0c8e89e13a6bbc46 SHA1 0784b31d200d41b94e7c5799e49bece71a57a2ad SHA256 47bd5d67ee2160d09831acf91351e33eb8b5f1a3055c88e9fe9609e3e1465cba
DIST gnome-utils-3.2.1.tar.xz 7273572 RMD160 a0e34b7057c0b77b58f7310ec8a8a3af238071bd SHA1 2f837a420ea73ad1a1cab56656b450e704f2faab SHA256 3ac1942dbf4d9d394e2fcc5f30a4480b1b1e5d44ee0c2d4f61689f4a221ba328
EBUILD gnome-utils-3.2.1.ebuild 2297 RMD160 a435cfdf9a8d269c2f6c713eac0ed4f300714245 SHA1 9f44b9dbfccb55331430463f03763c21e53d57e9 SHA256 a1f628eb2d10e1925292f4fcc6babadcd3b16565f63df8b2bcb2295e9a146f7d
diff --git a/gnome-extra/gnome-utils/files/gnome-utils-3.2.1-upload-screenshots.patch b/gnome-extra/gnome-utils/files/gnome-utils-3.2.1-upload-screenshots.patch
index 4267108..46b187a 100644
--- a/gnome-extra/gnome-utils/files/gnome-utils-3.2.1-upload-screenshots.patch
+++ b/gnome-extra/gnome-utils/files/gnome-utils-3.2.1-upload-screenshots.patch
@@ -1,6 +1,6 @@
diff -Naur gnome-utils-3.2.1//configure.ac gnome-utils-3.2.1.new//configure.ac
--- gnome-utils-3.2.1//configure.ac 2011-10-17 19:44:53.000000000 +0530
-+++ gnome-utils-3.2.1.new//configure.ac 2012-02-18 20:23:01.776675767 +0530
++++ gnome-utils-3.2.1.new//configure.ac 2012-02-20 03:37:08.072570280 +0530
@@ -142,6 +142,15 @@
[AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])]
)
@@ -19,7 +19,7 @@ diff -Naur gnome-utils-3.2.1//configure.ac gnome-utils-3.2.1.new//configure.ac
AC_SUBST(LIBGTOP_CFLAGS)
diff -Naur gnome-utils-3.2.1//gnome-screenshot/gnome-screenshot.c gnome-utils-3.2.1.new//gnome-screenshot/gnome-screenshot.c
--- gnome-utils-3.2.1//gnome-screenshot/gnome-screenshot.c 2011-10-17 19:40:18.000000000 +0530
-+++ gnome-utils-3.2.1.new//gnome-screenshot/gnome-screenshot.c 2012-02-18 20:29:34.978650924 +0530
++++ gnome-utils-3.2.1.new//gnome-screenshot/gnome-screenshot.c 2012-02-20 03:37:08.073570286 +0530
@@ -1,4 +1,5 @@
/* gnome-screenshot.c - Take a screenshot of the desktop
+ * vim: set sts=2 sw=2 et :
@@ -61,11 +61,15 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/gnome-screenshot.c gnome-utils-3.
GtkClipboard *clipboard;
diff -Naur gnome-utils-3.2.1//gnome-screenshot/gnome-screenshot.ui gnome-utils-3.2.1.new//gnome-screenshot/gnome-screenshot.ui
--- gnome-utils-3.2.1//gnome-screenshot/gnome-screenshot.ui 2011-09-28 02:57:36.000000000 +0530
-+++ gnome-utils-3.2.1.new//gnome-screenshot/gnome-screenshot.ui 2012-02-18 20:23:01.779675766 +0530
-@@ -42,6 +42,23 @@
- </packing>
- </child>
- <child>
++++ gnome-utils-3.2.1.new//gnome-screenshot/gnome-screenshot.ui 2012-02-20 03:37:20.952569474 +0530
+@@ -39,6 +39,39 @@
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ <property name="secondary">True</property>
++ <property name="non_homogeneous">True</property>
++ </packing>
++ </child>
++ <child>
+ <object class="GtkButton" id="upload_button">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
@@ -74,19 +78,55 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/gnome-screenshot.ui gnome-utils-3
+ <property name="label" translatable="yes">_Upload</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
++ <property name="width_request">75</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ <property name="secondary">True</property>
++ <property name="non_homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
- <object class="GtkButton" id="cancel_button">
- <property name="visible">True</property>
- <property name="can_default">True</property>
-@@ -241,6 +258,7 @@
++ <object class="GtkProgressBar" id="upload_progress">
++ <property name="visible">False</property>
++ <property name="can_default">False</property>
++ <property name="no_show_all">True</property>
++ </object>
++ <packing>
++ <property name="expand">False</property>
++ <property name="fill">False</property>
++ <property name="position">2</property>
++ <property name="secondary">True</property>
+ </packing>
+ </child>
+ <child>
+@@ -50,7 +83,11 @@
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
++ <property name="width_request">75</property>
+ </object>
++ <packing>
++ <property name="non_homogeneous">True</property>
++ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="ok_button">
+@@ -62,7 +99,11 @@
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
++ <property name="width_request">75</property>
+ </object>
++ <packing>
++ <property name="non_homogeneous">True</property>
++ </packing>
+ </child>
+ </object>
+ <packing>
+@@ -241,6 +282,7 @@
<action-widget response="-6">cancel_button</action-widget>
<action-widget response="-5">ok_button</action-widget>
<action-widget response="1">copy_button</action-widget>
@@ -96,7 +136,7 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/gnome-screenshot.ui gnome-utils-3
</interface>
diff -Naur gnome-utils-3.2.1//gnome-screenshot/Makefile.am gnome-utils-3.2.1.new//gnome-screenshot/Makefile.am
--- gnome-utils-3.2.1//gnome-screenshot/Makefile.am 2011-10-17 19:35:06.000000000 +0530
-+++ gnome-utils-3.2.1.new//gnome-screenshot/Makefile.am 2012-02-18 20:23:01.777675767 +0530
++++ gnome-utils-3.2.1.new//gnome-screenshot/Makefile.am 2012-02-20 03:37:08.077570288 +0530
@@ -19,6 +19,8 @@
screenshot-dialog.h \
screenshot-shadow.c \
@@ -126,7 +166,7 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/Makefile.am gnome-utils-3.2.1.new
-lm \
diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-dialog.c gnome-utils-3.2.1.new//gnome-screenshot/screenshot-dialog.c
--- gnome-utils-3.2.1//gnome-screenshot/screenshot-dialog.c 2011-10-17 19:35:06.000000000 +0530
-+++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-dialog.c 2012-02-18 20:23:01.779675766 +0530
++++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-dialog.c 2012-02-20 03:37:08.077570288 +0530
@@ -39,17 +39,6 @@
{ "text/uri-list", 0, TYPE_TEXT_URI_LIST },
};
@@ -147,7 +187,7 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-dialog.c gnome-utils-3
cairo_t *cr,
diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-dialog.h gnome-utils-3.2.1.new//gnome-screenshot/screenshot-dialog.h
--- gnome-utils-3.2.1//gnome-screenshot/screenshot-dialog.h 2011-10-17 19:35:06.000000000 +0530
-+++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-dialog.h 2012-02-18 20:23:01.780675765 +0530
++++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-dialog.h 2012-02-20 03:37:08.078570287 +0530
@@ -22,10 +22,22 @@
#include <gtk/gtk.h>
@@ -173,8 +213,8 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-dialog.h gnome-utils-3
char *initial_uri,
diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c gnome-utils-3.2.1.new//gnome-screenshot/screenshot-share.c
--- gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c 1970-01-01 05:30:00.000000000 +0530
-+++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-share.c 2012-02-18 20:23:01.780675765 +0530
-@@ -0,0 +1,156 @@
++++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-share.c 2012-02-20 03:37:25.214569203 +0530
+@@ -0,0 +1,284 @@
+/* screenshot-share.c - online screenshot sharing
+ * vim: set sts=2 sw=2 et :
+ *
@@ -199,6 +239,7 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c gnome-utils-3.
+
+#include <glib.h>
+#include <gtk/gtk.h>
++#include <glib/gi18n.h>
+#include <libsoup/soup.h>
+#include <json-glib/json-glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
@@ -206,49 +247,94 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c gnome-utils-3.
+#include "screenshot-share.h"
+#include "screenshot-dialog.h"
+
++/* API key is taken from http://imgur.com/tools/imgurbash.sh
++ * Presumably they're fine with FOSS applications using this key
++ * TODO: They're cool guys, ask them! */
+#define IMGUR_API_KEY "b3625162d3418ac51a9ee805b1840452"
++/* We use v1 of the API because v2 is in beta */
+#define IMGUR_UPLOAD_URI "http://api.imgur.com/1/upload.json"
+
-+static void imgur_response_cb (SoupSession *session,
-+ SoupMessage *msg,
-+ gpointer user_data);
++/* The two states for the upload button */
++#define BUTTON_TEXT_UPLOAD "_Upload"
++#define BUTTON_TEXT_PAUSE "Pa_use"
++
++/* Function prototypes */
++static void message_completed_cb (SoupSession *session,
++ SoupMessage *msg,
++ gpointer user_data);
++
++static void wrote_data_cb (SoupMessage *msg,
++ SoupBuffer *chunk,
++ gpointer user_data);
++
++static void request_started_cb (SoupSession *session,
++ SoupMessage *msg,
++ SoupSocket *socket,
++ gpointer user_data);
+
-+static void imgur_wrote_data_cb (SoupMessage *msg,
-+ SoupBuffer *chunk,
-+ gpointer user_data);
++static void toggle_request_cb (GtkButton *widget,
++ gpointer user_data);
++
++static void screenshot_uploaded_cb (SoupMessage *msg,
++ gpointer user_data);
++
++static void imgur_response_cb (SoupMessage *msg);
++
++static void reset_upload_button (ScreenshotSoupContext *context);
+
+static void screenshot_display_uris (gchar *image_uri,
+ gchar *delete_uri);
+
++/* Global variables */
++static gboolean uploading = FALSE;
+
++/* Upload the given screenshot to imgur.com */
+void
+screenshot_upload_imgur (ScreenshotDialog *dialog)
+{
-+ GtkButton *button;
++ ScreenshotSoupContext *context;
+ SoupSession *session;
+ SoupMessage *msg;
++ GtkButton *button;
++ GtkProgressBar *progress_bar;
+ gchar *temp;
+ gchar *image_data;
+ gsize image_size;
-+ GError *tmp_error;
+
-+ tmp_error = NULL;
++ /* Are we already uploading? Then just return. */
++ if (uploading)
++ return;
++ uploading = TRUE;
++
+ if (!gdk_pixbuf_save_to_buffer (GDK_PIXBUF (dialog->screenshot),
+ &image_data, &image_size,
-+ "png", &tmp_error, NULL))
++ "png", NULL, NULL))
+ goto out;
+
+ button = GTK_BUTTON (gtk_builder_get_object (dialog->ui, "upload_button"));
++ progress_bar = GTK_PROGRESS_BAR (gtk_builder_get_object (dialog->ui, "upload_progress"));
+
+ temp = g_base64_encode (image_data, image_size);
+ session = soup_session_async_new ();
+ msg = soup_form_request_new (SOUP_METHOD_POST, IMGUR_UPLOAD_URI,
+ "key", IMGUR_API_KEY,
+ "image", temp, NULL);
++
++ context = g_new0 (ScreenshotSoupContext, 1);
++ context->session = session;
++ context->msg = msg;
++ context->upload_button = button;
++ context->upload_progress = progress_bar;
++
++ g_signal_connect (session, "request-started",
++ G_CALLBACK (request_started_cb),
++ (gpointer)context);
++
+ g_signal_connect (msg, "wrote-body-data",
-+ G_CALLBACK (imgur_wrote_data_cb),
-+ (gpointer)button);
-+ soup_session_queue_message (session, msg, imgur_response_cb, NULL);
++ G_CALLBACK (wrote_data_cb),
++ (gpointer)progress_bar);
++
++ soup_session_queue_message (session, msg, message_completed_cb, (gpointer)context);
+ g_free (temp);
+
+out:
@@ -256,23 +342,126 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c gnome-utils-3.
+}
+
+static void
-+imgur_response_cb (SoupSession *session,
-+ SoupMessage *msg,
-+ gpointer user_data)
++reset_upload_button (ScreenshotSoupContext *context)
++{
++ g_signal_handlers_disconnect_by_func (G_OBJECT (context->upload_button),
++ G_CALLBACK (toggle_request_cb),
++ (gpointer)context);
++
++ gtk_widget_set_visible (GTK_WIDGET (context->upload_progress), FALSE);
++ gtk_button_set_label (context->upload_button, _(BUTTON_TEXT_UPLOAD));
++}
++
++/* Handle SoupMessage completion
++ *
++ * TODO: handle HTTP errors properly
++ * Right now we just reset the upload button upon *all* message completion
++ * We should probably display an error so the user knows the upload failed
++ */
++static void
++message_completed_cb (SoupSession *session,
++ SoupMessage *msg,
++ gpointer user_data)
++{
++ reset_upload_button ((ScreenshotSoupContext*)user_data);
++ uploading = FALSE;
++
++ switch (msg->status_code) {
++ case SOUP_STATUS_OK:
++ screenshot_uploaded_cb (msg, user_data);
++ break;
++ case SOUP_STATUS_CANCELLED:
++ g_debug ("User cancelled upload!\n");
++ break;
++ default:
++ if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
++ g_warning ("Got an error from imgur:\n%s\n", msg->request_body->data);
++ break;
++ }
++}
++
++/* Request successfully started, start the progress bar */
++static void
++request_started_cb (SoupSession *session,
++ SoupMessage *msg,
++ SoupSocket *socket,
++ gpointer user_data)
++{
++ ScreenshotSoupContext *context = user_data;
++
++ gtk_button_set_label (GTK_BUTTON (context->upload_button), _(BUTTON_TEXT_PAUSE));
++
++ g_signal_connect (G_OBJECT (context->upload_button),
++ "clicked",
++ G_CALLBACK (toggle_request_cb),
++ user_data);
++}
++
++/* Pause/Unpause the screenshot upload. Not MT-safe */
++static void
++toggle_request_cb (GtkButton *widget,
++ gpointer user_data)
++{
++ ScreenshotSoupContext *context = user_data;
++ static gboolean paused;
++
++ if (paused) {
++ soup_session_unpause_message (context->session,
++ context->msg);
++ gtk_button_set_label (context->upload_button, _(BUTTON_TEXT_PAUSE));
++ paused = FALSE;
++ } else {
++ soup_session_pause_message (context->session,
++ context->msg);
++ gtk_button_set_label (context->upload_button, _(BUTTON_TEXT_UPLOAD));
++ paused = TRUE;
++ }
++}
++
++/* Update the progress bar */
++static void
++wrote_data_cb (SoupMessage *msg,
++ SoupBuffer *chunk,
++ gpointer user_data)
++{
++ static int total_sent;
++ float fraction;
++
++ if (!gtk_widget_get_visible (GTK_WIDGET (user_data)))
++ gtk_widget_set_visible (GTK_WIDGET (user_data), TRUE);
++
++ total_sent += chunk->length;
++ fraction = ((float)total_sent) / msg->request_body->length;
++ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (user_data), fraction);
++
++ /* Upload finished? Reset the counter. */
++ if (total_sent == msg->request_body->length)
++ total_sent = 0;
++}
++
++static void
++screenshot_uploaded_cb (SoupMessage *msg,
++ gpointer user_data)
++{
++ imgur_response_cb (msg);
++}
++
++/* Process the screenshot upload response from imgur.com
++ *
++ * Also opens the image and delete links for the uploaded image
++ * in the default http:// handler
++ * */
++static void
++imgur_response_cb (SoupMessage *msg)
+{
+ JsonParser *parser = NULL;
+ JsonNode *node = NULL;
-+ GMainLoop *loop;
+ GError *error = NULL;
+ gchar *response;
+ gchar *image_uri;
+ gchar *delete_uri;
+
+ response = g_strdup (msg->response_body->data);
-+ if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-+ g_debug ("Got an error from imgur:\n%s\n", response);
-+ goto out;
-+ }
+
+ parser = json_parser_new ();
+ json_parser_load_from_data (parser, response, -1, &error);
@@ -292,6 +481,7 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c gnome-utils-3.
+ json_node_free (node);
+
+ screenshot_display_uris (image_uri, delete_uri);
++
+ g_free (image_uri);
+ g_free (delete_uri);
+
@@ -303,28 +493,6 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c gnome-utils-3.
+}
+
+static void
-+imgur_wrote_data_cb (SoupMessage *msg,
-+ SoupBuffer *chunk,
-+ gpointer user_data)
-+{
-+ gchar *upload_percent;
-+ static int total_sent;
-+ int percent;
-+
-+ total_sent += (float) chunk->length;
-+ percent = (int)nearbyint(100*((float)total_sent) / msg->request_body->length);
-+ upload_percent = g_strdup_printf ("Uploading... %i%%", percent);
-+
-+ gtk_button_set_label (GTK_BUTTON (user_data), upload_percent);
-+
-+ /* Upload finished? Reset the counter. */
-+ if (total_sent == msg->request_body->length)
-+ total_sent = 0;
-+
-+ g_free (upload_percent);
-+}
-+
-+static void
+screenshot_display_uris (gchar *image_uri,
+ gchar *delete_uri)
+{
@@ -333,8 +501,8 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.c gnome-utils-3.
+}
diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.h gnome-utils-3.2.1.new//gnome-screenshot/screenshot-share.h
--- gnome-utils-3.2.1//gnome-screenshot/screenshot-share.h 1970-01-01 05:30:00.000000000 +0530
-+++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-share.h 2012-02-18 20:23:01.780675765 +0530
-@@ -0,0 +1,32 @@
++++ gnome-utils-3.2.1.new//gnome-screenshot/screenshot-share.h 2012-02-20 03:37:25.214569203 +0530
+@@ -0,0 +1,43 @@
+/* screenshot-share.h - online screenshot sharing
+ * vim: set sts=2 sw=2 et :
+ *
@@ -358,8 +526,19 @@ diff -Naur gnome-utils-3.2.1//gnome-screenshot/screenshot-share.h gnome-utils-3.
+#ifndef __SCREENSHOT_SHARE_H__
+#define __SCREENSHOT_SHARE_H__
+
++#include <libsoup/soup.h>
++
+#include "screenshot-dialog.h"
+
++struct ScreenshotSoupContext {
++ SoupSession *session;
++ SoupMessage *msg;
++ GtkButton *upload_button;
++ GtkProgressBar *upload_progress;
++};
++
++typedef struct ScreenshotSoupContext ScreenshotSoupContext;
++
+G_BEGIN_DECLS
+
+void screenshot_upload_imgur (ScreenshotDialog *dialog);