diff options
Diffstat (limited to 'gnome-extra/gnome-utils/files/0001-New-feature-uploading-screenshots-to-imgur.com.patch')
-rw-r--r-- | gnome-extra/gnome-utils/files/0001-New-feature-uploading-screenshots-to-imgur.com.patch | 398 |
1 files changed, 398 insertions, 0 deletions
diff --git a/gnome-extra/gnome-utils/files/0001-New-feature-uploading-screenshots-to-imgur.com.patch b/gnome-extra/gnome-utils/files/0001-New-feature-uploading-screenshots-to-imgur.com.patch new file mode 100644 index 0000000..7fb0ec7 --- /dev/null +++ b/gnome-extra/gnome-utils/files/0001-New-feature-uploading-screenshots-to-imgur.com.patch @@ -0,0 +1,398 @@ +From 2cc75e214336b858a6e634bb109592dc712f9cd7 Mon Sep 17 00:00:00 2001 +From: Nirbheek Chauhan <nirbheek@gentoo.org> +Date: Sat, 18 Feb 2012 20:03:53 +0530 +Subject: [PATCH] New feature: uploading screenshots to imgur.com + +--- + configure.ac | 9 ++ + gnome-screenshot/Makefile.am | 6 ++ + gnome-screenshot/gnome-screenshot.c | 12 +++ + gnome-screenshot/gnome-screenshot.ui | 18 ++++ + gnome-screenshot/screenshot-dialog.c | 11 --- + gnome-screenshot/screenshot-dialog.h | 12 +++ + gnome-screenshot/screenshot-share.c | 155 ++++++++++++++++++++++++++++++++++ + gnome-screenshot/screenshot-share.h | 32 +++++++ + 8 files changed, 244 insertions(+), 11 deletions(-) + create mode 100644 gnome-screenshot/screenshot-share.c + create mode 100644 gnome-screenshot/screenshot-share.h + +diff --git a/configure.ac b/configure.ac +index d75bbe2..93b54f0 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -142,6 +142,15 @@ AS_IF([test "x$GCONFTOOL" = "xno"], + [AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])] + ) + ++# gnome-screenshot checks ++PKG_CHECK_MODULES([LIBSOUP], [libsoup-2.4]) ++AC_SUBST(LIBSOUP_CFLAGS) ++AC_SUBST(LIBSOUP_LIBS) ++ ++PKG_CHECK_MODULES([JSON_GLIB], [json-glib-1.0 >= 0.14]) ++AC_SUBST(JSON_GLIB_CFLAGS) ++AC_SUBST(JSON_GLIB_LIBS) ++ + # Baobab checks + PKG_CHECK_MODULES([LIBGTOP], [libgtop-2.0 >= $LIBGTOP_REQUIRED]) + AC_SUBST(LIBGTOP_CFLAGS) +diff --git a/gnome-screenshot/Makefile.am b/gnome-screenshot/Makefile.am +index d9a11c7..3be0074 100644 +--- a/gnome-screenshot/Makefile.am ++++ b/gnome-screenshot/Makefile.am +@@ -28,6 +28,8 @@ gnome_screenshot_SOURCES = \ + screenshot-interactive-dialog.h \ + screenshot-shadow.c \ + screenshot-shadow.h \ ++ screenshot-share.c \ ++ screenshot-share.h \ + screenshot-utils.c \ + screenshot-utils.h \ + $(NULL) +@@ -36,6 +38,8 @@ gnome_screenshot_CFLAGS = \ + $(GLIB_CFLAGS) \ + $(GIO_CFLAGS) \ + $(LIBCANBERRA_GTK_CFLAGS) \ ++ $(LIBSOUP_CFLAGS) \ ++ $(JSON_GLIB_CFLAGS) \ + $(GTHREAD_CFLAGS) \ + $(GTK_CFLAGS) \ + $(NULL) +@@ -47,6 +51,8 @@ gnome_screenshot_LDADD = \ + $(GLIB_LIBS) \ + $(GIO_LIBS) \ + $(LIBCANBERRA_GTK_LIBS) \ ++ $(LIBSOUP_LIBS) \ ++ $(JSON_GLIB_LIBS) \ + $(GTHREAD_LIBS) \ + $(GTK_LIBS) \ + -lm \ +diff --git a/gnome-screenshot/gnome-screenshot.c b/gnome-screenshot/gnome-screenshot.c +index 3390914..714b2d1 100644 +--- a/gnome-screenshot/gnome-screenshot.c ++++ b/gnome-screenshot/gnome-screenshot.c +@@ -1,4 +1,5 @@ + /* gnome-screenshot.c - Take a screenshot of the desktop ++ * vim: set sts=2 sw=2 et : + * + * Copyright (C) 2001 Jonathan Blandford <jrb@alum.mit.edu> + * Copyright (C) 2006 Emmanuele Bassi <ebassi@gnome.org> +@@ -47,6 +48,7 @@ + #include "screenshot-filename-builder.h" + #include "screenshot-interactive-dialog.h" + #include "screenshot-shadow.h" ++#include "screenshot-share.h" + #include "screenshot-utils.h" + #include "screenshot-dialog.h" + #include "cheese-flash.h" +@@ -260,6 +262,13 @@ screenshot_save_to_clipboard (void) + } + + static void ++screenshot_upload (ScreenshotDialog *dialog) ++{ ++ /* TODO: Add libsocialweb support and convert 'upload' to 'share' everywhere */ ++ screenshot_upload_imgur (dialog); ++} ++ ++static void + screenshot_dialog_response_cb (GtkDialog *d, + gint response_id, + ScreenshotDialog *dialog) +@@ -275,6 +284,9 @@ screenshot_dialog_response_cb (GtkDialog *d, + case SCREENSHOT_RESPONSE_COPY: + screenshot_save_to_clipboard (); + break; ++ case SCREENSHOT_RESPONSE_UPLOAD: ++ screenshot_upload (dialog); ++ break; + default: + gtk_widget_destroy (GTK_WIDGET (d)); + gtk_main_quit (); +diff --git a/gnome-screenshot/gnome-screenshot.ui b/gnome-screenshot/gnome-screenshot.ui +index 62f1265..6ce9612 100644 +--- a/gnome-screenshot/gnome-screenshot.ui ++++ b/gnome-screenshot/gnome-screenshot.ui +@@ -42,6 +42,23 @@ + </packing> + </child> + <child> ++ <object class="GtkButton" id="upload_button"> ++ <property name="visible">True</property> ++ <property name="can_default">True</property> ++ <property name="can_focus">True</property> ++ <property name="use_underline">True</property> ++ <property name="label" translatable="yes">_Upload</property> ++ <property name="relief">GTK_RELIEF_NORMAL</property> ++ <property name="focus_on_click">True</property> ++ </object> ++ <packing> ++ <property name="expand">False</property> ++ <property name="fill">False</property> ++ <property name="position">1</property> ++ <property name="secondary">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 @@ + <action-widget response="-6">cancel_button</action-widget> + <action-widget response="-5">ok_button</action-widget> + <action-widget response="1">copy_button</action-widget> ++ <action-widget response="2">upload_button</action-widget> + </action-widgets> + </object> + </interface> +diff --git a/gnome-screenshot/screenshot-dialog.c b/gnome-screenshot/screenshot-dialog.c +index d6d954d..6cb8bba 100644 +--- a/gnome-screenshot/screenshot-dialog.c ++++ b/gnome-screenshot/screenshot-dialog.c +@@ -36,17 +36,6 @@ static GtkTargetEntry drag_types[] = + { "image/png", 0, TYPE_IMAGE_PNG }, + }; + +-struct ScreenshotDialog +-{ +- GtkBuilder *ui; +- GdkPixbuf *screenshot; +- GdkPixbuf *preview_image; +- GtkWidget *save_widget; +- GtkWidget *filename_entry; +- gint drag_x; +- gint drag_y; +-}; +- + static void + on_preview_draw (GtkWidget *drawing_area, + cairo_t *cr, +diff --git a/gnome-screenshot/screenshot-dialog.h b/gnome-screenshot/screenshot-dialog.h +index 7741198..8f2cff7 100644 +--- a/gnome-screenshot/screenshot-dialog.h ++++ b/gnome-screenshot/screenshot-dialog.h +@@ -22,10 +22,22 @@ + + #include <gtk/gtk.h> + ++struct ScreenshotDialog ++{ ++ GtkBuilder *ui; ++ GdkPixbuf *screenshot; ++ GdkPixbuf *preview_image; ++ GtkWidget *save_widget; ++ GtkWidget *filename_entry; ++ gint drag_x; ++ gint drag_y; ++}; ++ + typedef struct ScreenshotDialog ScreenshotDialog; + + /* Keep in sync with the value defined in the UI file */ + #define SCREENSHOT_RESPONSE_COPY 1 ++#define SCREENSHOT_RESPONSE_UPLOAD 2 + + ScreenshotDialog *screenshot_dialog_new (GdkPixbuf *screenshot, + char *initial_uri); +diff --git a/gnome-screenshot/screenshot-share.c b/gnome-screenshot/screenshot-share.c +new file mode 100644 +index 0000000..2442cfa +--- /dev/null ++++ b/gnome-screenshot/screenshot-share.c +@@ -0,0 +1,155 @@ ++/* screenshot-share.c - online screenshot sharing ++ * vim: set sts=2 sw=2 et : ++ * ++ * Copyright (C) 2012 Nirbheek Chauhan <nirbheek.chauhan@gmail.com> ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public ++ * License as published by the Free Software Foundation; either ++ * version 2 of the License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public ++ * License along with this program; if not, write to the ++ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, ++ */ ++ ++#include <glib.h> ++#include <gtk/gtk.h> ++#include <libsoup/soup.h> ++#include <json-glib/json-glib.h> ++#include <gdk-pixbuf/gdk-pixbuf.h> ++ ++#include "gnome-screenshot.h" ++#include "screenshot-share.h" ++#include "screenshot-dialog.h" ++ ++#define IMGUR_API_KEY "b3625162d3418ac51a9ee805b1840452" ++#define IMGUR_UPLOAD_URI "http://api.imgur.com/1/upload.json" ++ ++static void imgur_response_cb (SoupSession *session, ++ SoupMessage *msg, ++ gpointer user_data); ++ ++static void imgur_wrote_data_cb (SoupMessage *msg, ++ SoupBuffer *chunk, ++ gpointer user_data); ++ ++static void screenshot_display_uris (gchar *image_uri, ++ gchar *delete_uri); ++ ++ ++void ++screenshot_upload_imgur (ScreenshotDialog *dialog) ++{ ++ GtkButton *button; ++ SoupSession *session; ++ SoupMessage *msg; ++ gchar *temp; ++ gchar *image_data; ++ gsize image_size; ++ GError *tmp_error; ++ ++ tmp_error = NULL; ++ if (!gdk_pixbuf_save_to_buffer (GDK_PIXBUF (dialog->screenshot), ++ &image_data, &image_size, ++ "png", &tmp_error, NULL)) ++ goto out; ++ ++ button = GTK_BUTTON (gtk_builder_get_object (dialog->ui, "upload_button")); ++ ++ 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); ++ 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_free (temp); ++ ++out: ++ g_free (image_data); ++} ++ ++static void ++imgur_response_cb (SoupSession *session, ++ SoupMessage *msg, ++ gpointer user_data) ++{ ++ 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); ++ if (error) ++ goto out; ++ ++ node = json_path_query ("$.rsp.image.imgur_page", json_parser_get_root (parser), &error); ++ if (!node || error) ++ goto out; ++ image_uri = json_node_dup_string (json_array_get_element (json_node_get_array (node), 0)); ++ json_node_free (node); ++ ++ node = json_path_query ("$.rsp.image.delete_page", json_parser_get_root (parser), &error); ++ if (!node || error) ++ goto out; ++ delete_uri = json_node_dup_string (json_array_get_element (json_node_get_array (node), 0)); ++ json_node_free (node); ++ ++ screenshot_display_uris (image_uri, delete_uri); ++ g_free (image_uri); ++ g_free (delete_uri); ++ ++out: ++ if (error) ++ g_error_free (error); ++ g_free (response); ++ g_object_unref (parser); ++} ++ ++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) ++{ ++ g_app_info_launch_default_for_uri (image_uri, NULL, NULL); ++ g_app_info_launch_default_for_uri (delete_uri, NULL, NULL); ++} +diff --git a/gnome-screenshot/screenshot-share.h b/gnome-screenshot/screenshot-share.h +new file mode 100644 +index 0000000..6d39220 +--- /dev/null ++++ b/gnome-screenshot/screenshot-share.h +@@ -0,0 +1,32 @@ ++/* screenshot-share.h - online screenshot sharing ++ * vim: set sts=2 sw=2 et : ++ * ++ * Copyright (C) 2012 Nirbheek Chauhan <nirbheek.chauhan@gmail.com> ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public ++ * License as published by the Free Software Foundation; either ++ * version 2 of the License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public ++ * License along with this program; if not, write to the ++ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, ++ */ ++ ++#ifndef __SCREENSHOT_SHARE_H__ ++#define __SCREENSHOT_SHARE_H__ ++ ++#include "screenshot-dialog.h" ++ ++G_BEGIN_DECLS ++ ++void screenshot_upload_imgur (ScreenshotDialog *dialog); ++ ++G_END_DECLS ++ ++#endif /* __SCREENSHOT_SHARE_H__ */ +-- +1.7.3.4 + |