]> git.0d.be Git - empathy.git/commitdiff
Merge remote-tracking branch 'glassrose/debug-window-send-to-pastebin-button-658724'
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 21 Feb 2012 13:11:57 +0000 (14:11 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 21 Feb 2012 13:11:57 +0000 (14:11 +0100)
PASTEBIN-API-KEY.txt [new file with mode: 0644]
src/empathy-debug-window.c

diff --git a/PASTEBIN-API-KEY.txt b/PASTEBIN-API-KEY.txt
new file mode 100644 (file)
index 0000000..71c8e9c
--- /dev/null
@@ -0,0 +1,110 @@
+MIME-Version: 1.0
+Received: by 10.231.11.1 with HTTP; Tue, 11 Oct 2011 22:59:10 -0700 (PDT)
+In-Reply-To:
+<CADttZZpfye8-Pi9=UDK3OUq8NmsagYV5AF_oewVNEUMRp7joFg@mail.gmail.com>
+References: <CADttZZoDLnv+aoZBPLcHT43-yKCH8LB+3objC-ST1qRp3P3Lnw@mail.gmail.com>
+    <CACuygeBuekJwr3t+7GxLA8Ft+A-Q6QmZUhe_2VU2LozSYduYxQ@mail.gmail.com>
+    <CADttZZqadJP3441etHxd2JFmNCqqHxDhg-uiCqqV=Qs3hUCynA@mail.gmail.com>
+    <CADttZZrWAw7hjQb1+qN+4z42d10FEWwOvLG-P_s85Htf_fwbEg@mail.gmail.com>
+    <CACuygeCOpAmYBogzay2VOb7SGnEhLsKfeaU-07QXQG=mj-ZRfg@mail.gmail.com>
+    <CADttZZrmrz5Dr7d9THQsSPJtWvy_P_-vkAx=UDcUEo_c+RE2nQ@mail.gmail.com>
+    <CADttZZqGfRUjcr8Cppz5oWniXwmreomd3wshCBzwx1E32A=Kdw@mail.gmail.com>
+    <CACuygeDDcW1NZYGCzTuxAUrJ92BgEnG+0ewME-yhR03Pwvd02A@mail.gmail.com>
+    <CADttZZpfye8-Pi9=UDK3OUq8NmsagYV5AF_oewVNEUMRp7joFg@mail.gmail.com>
+Date: Wed, 12 Oct 2011 11:29:10 +0530
+Delivered-To: chandniverma2112@gmail.com
+Message-ID: <CADttZZrP+XkPtNgAzxM56WkQAT72hjcQD0Z1UcFj8=q86Cpxeg@mail.gmail.com>
+Subject: Re: API issues
+From: Chandni Verma <chandniverma2112@gmail.com>
+To: Pastebin Support <admin@pastebin.com>
+Content-Type: multipart/alternative; boundary=001636ef068e08c10c04af13b9e5
+
+--001636ef068e08c10c04af13b9e5
+Content-Type: text/plain; charset=ISO-8859-1
+
+Hi Admin,
+
+One thing which I want to ask you since it it not answered anywhere on the
+pastebin.com website is that who is allowed to use the API developer key in
+their codes. Are there any licences to keep in mind?
+It's crucial to the open source project I have used the pastebin API for.
+
+Can we publish a member's (my) key in the open source code?
+
+Regards,
+Chandni
+
+_______
+
+Delivered-To: chandniverma2112@gmail.com
+Received: by 10.231.11.1 with SMTP id r1cs44531ibr;
+        Wed, 12 Oct 2011 02:27:32 -0700 (PDT)
+Return-Path: <godius@gmail.com>
+Received-SPF: pass (google.com: domain of godius@gmail.com designates
+10.182.187.100 as permitted sender) client-ip=10.182.187.100;
+Authentication-Results: mr.google.com; spf=pass (google.com: domain of
+godius@gmail.com designates 10.182.187.100 as permitted sender)
+smtp.mail=godius@gmail.com; dkim=pass header.i=godius@gmail.com
+Received: from mr.google.com ([10.182.187.100])
+        by 10.182.187.100 with SMTP id fr4mr13834663obc.79.1318411651457
+(num_hops = 1);
+        Wed, 12 Oct 2011 02:27:31 -0700 (PDT)
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
+        d=gmail.com; s=gamma;
+        h=mime-version:sender:in-reply-to:references:date
+         :x-google-sender-auth:message-id:subject:from:to:content-type;
+        bh=pv3X2ILKj91U9H2lw/fwrkHPzZRFCaB8pPO2Y6pBzSA=;
+        b=T2XQR8CcrP3jF/9wJPYJxBQPToZp2ckFMelfmdRFd7akc6f8iEQRXUjEsYXvRPbuzS
+         6TWaTHiT0QLBZaqh1D6AifP2E4m84H+h8LwEkYXXAN4dJyTIbAM8rQ5KfbTiaoKzuv48
+         7dS26KA2YOB1bWTlhEm0zW4bdPCGSBxsCW67Y=
+MIME-Version: 1.0
+Received: by 10.182.187.100 with SMTP id fr4mr13834663obc.79.1318411651452;
+ Wed, 12 Oct 2011 02:27:31 -0700 (PDT)
+Sender: godius@gmail.com
+Received: by 10.182.118.36 with HTTP; Wed, 12 Oct 2011 02:27:31 -0700 (PDT)
+In-Reply-To:
+<CADttZZrP+XkPtNgAzxM56WkQAT72hjcQD0Z1UcFj8=q86Cpxeg@mail.gmail.com>
+References: <CADttZZoDLnv+aoZBPLcHT43-yKCH8LB+3objC-ST1qRp3P3Lnw@mail.gmail.com>
+    <CACuygeBuekJwr3t+7GxLA8Ft+A-Q6QmZUhe_2VU2LozSYduYxQ@mail.gmail.com>
+    <CADttZZqadJP3441etHxd2JFmNCqqHxDhg-uiCqqV=Qs3hUCynA@mail.gmail.com>
+    <CADttZZrWAw7hjQb1+qN+4z42d10FEWwOvLG-P_s85Htf_fwbEg@mail.gmail.com>
+    <CACuygeCOpAmYBogzay2VOb7SGnEhLsKfeaU-07QXQG=mj-ZRfg@mail.gmail.com>
+    <CADttZZrmrz5Dr7d9THQsSPJtWvy_P_-vkAx=UDcUEo_c+RE2nQ@mail.gmail.com>
+    <CADttZZqGfRUjcr8Cppz5oWniXwmreomd3wshCBzwx1E32A=Kdw@mail.gmail.com>
+    <CACuygeDDcW1NZYGCzTuxAUrJ92BgEnG+0ewME-yhR03Pwvd02A@mail.gmail.com>
+    <CADttZZpfye8-Pi9=UDK3OUq8NmsagYV5AF_oewVNEUMRp7joFg@mail.gmail.com>
+    <CADttZZrP+XkPtNgAzxM56WkQAT72hjcQD0Z1UcFj8=q86Cpxeg@mail.gmail.com>
+Date: Wed, 12 Oct 2011 11:27:31 +0200
+X-Google-Sender-Auth: cXD_1Zj39UiHBWVSdEJRk04LVC8
+Message-ID: <CACuygeDAqGCP+=KsV+ZyxNuLoy9L0CTQ63NpRhrig-9bzeFp6A@mail.gmail.com>
+Subject: Re: API issues
+From: Pastebin Support <admin@pastebin.com>
+To: Chandni Verma <chandniverma2112@gmail.com>
+Content-Type: multipart/alternative; boundary=14dae9398ea5270f6904af16a25e
+
+--14dae9398ea5270f6904af16a25e
+Content-Type: text/plain; charset=ISO-8859-1
+
+Hello,
+
+Yes you can use your api developer key in the open for your project.
+Regards,
+
+Pastebin
+
+
+On Wed, Oct 12, 2011 at 7:59 AM, Chandni Verma
+<chandniverma2112@gmail.com>wrote:
+
+> Hi Admin,
+>
+> One thing which I want to ask you since it it not answered anywhere on the
+> pastebin.com website is that who is allowed to use the API developer key
+> in their codes. Are there any licences to keep in mind?
+> It's crucial to the open source project I have used the pastebin API for.
+>
+> Can we publish a member's (my) key in the open source code?
+>
+> Regards,
+> Chandni
+>
index 3aa8c1502f7a5b15dc347b90419b4dfef891ec39..448c06f6921da5be506fe8cd0fbcc473b8ddfc54 100644 (file)
 
 #include "config.h"
 
+#include <string.h>
+
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <gio/gio.h>
 #include <gdk/gdkkeysyms.h>
+#include <libsoup/soup.h>
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include <libempathy/empathy-debug.h>
@@ -88,6 +91,7 @@ typedef struct
   /* Toolbar items */
   GtkWidget *chooser;
   GtkToolItem *save_button;
+  GtkToolItem *send_to_pastebin;
   GtkToolItem *copy_button;
   GtkToolItem *clear_button;
   GtkToolItem *pause_button;
@@ -223,7 +227,7 @@ insert_values_in_buffer (GtkListStore *store,
       COL_DEBUG_LEVEL_STRING, log_level_to_string (level),
       COL_DEBUG_MESSAGE, string,
       COL_DEBUG_LEVEL_VALUE, level,
-      -1); 
+      -1);
 }
 
 static void
@@ -322,6 +326,7 @@ debug_window_set_toolbar_sensitivity (EmpathyDebugWindow *debug_window,
   GtkWidget *vbox = gtk_bin_get_child (GTK_BIN (debug_window));
 
   gtk_widget_set_sensitive (GTK_WIDGET (priv->save_button), sensitive);
+  gtk_widget_set_sensitive (GTK_WIDGET (priv->send_to_pastebin), sensitive);
   gtk_widget_set_sensitive (GTK_WIDGET (priv->copy_button), sensitive);
   gtk_widget_set_sensitive (GTK_WIDGET (priv->clear_button), sensitive);
   gtk_widget_set_sensitive (GTK_WIDGET (priv->pause_button), sensitive);
@@ -600,7 +605,6 @@ static gboolean
 tree_view_search_equal_func_cb (GtkTreeModel *model,
     gint column,
     const gchar *key,
-
     GtkTreeIter *iter,
     gpointer search_data)
 {
@@ -1482,12 +1486,10 @@ debug_window_store_filter_foreach (GtkTreeModel *model,
     GtkTreeIter *iter,
     gpointer user_data)
 {
-  GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
+  gchar **debug_data = (gchar **)user_data;
   gchar *domain, *category, *message, *level_str, *level_upper;
   gdouble timestamp;
-  gchar *line, *time_str;
-  GError *error = NULL;
-  gboolean out = FALSE;
+  gchar *line, *time_str, *tmp;
 
   gtk_tree_model_get (model, iter,
       COL_DEBUG_TIMESTAMP, &timestamp,
@@ -1507,15 +1509,14 @@ debug_window_store_filter_foreach (GtkTreeModel *model,
 
   g_free (time_str);
 
-  g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
-      strlen (line), NULL, &error);
+  /* Compact all message lines in the out parameter debug_data */
+  if (!tp_str_empty (*debug_data))
+    tmp = g_strconcat (*debug_data, line, NULL);
+  else
+    tmp = g_strdup (line);
 
-  if (error != NULL)
-    {
-      DEBUG ("Failed to write to file: %s", error->message);
-      g_error_free (error);
-      out = TRUE;
-    }
+  g_free (*debug_data);
+  *debug_data = tmp;
 
   g_free (line);
   g_free (level_upper);
@@ -1524,7 +1525,7 @@ debug_window_store_filter_foreach (GtkTreeModel *model,
   g_free (category);
   g_free (message);
 
-  return out;
+  return FALSE;
 }
 
 static void
@@ -1535,8 +1536,10 @@ debug_window_save_file_chooser_response_cb (GtkDialog *dialog,
   EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
   gchar *filename = NULL;
   GFile *gfile = NULL;
+  gchar *debug_data = NULL;
   GFileOutputStream *output_stream = NULL;
-  GError *error = NULL;
+  GError *file_open_error = NULL;
+  GError *file_write_error = NULL;
 
   if (response_id != GTK_RESPONSE_ACCEPT)
     goto OUT;
@@ -1547,17 +1550,27 @@ debug_window_save_file_chooser_response_cb (GtkDialog *dialog,
 
   gfile = g_file_new_for_path (filename);
   output_stream = g_file_replace (gfile, NULL, FALSE,
-      G_FILE_CREATE_NONE, NULL, &error);
+      G_FILE_CREATE_NONE, NULL, &file_open_error);
 
-  if (error != NULL)
+  if (file_open_error != NULL)
     {
-      DEBUG ("Failed to open file for writing: %s", error->message);
-      g_error_free (error);
+      DEBUG ("Failed to open file for writing: %s", file_open_error->message);
+      g_error_free (file_open_error);
       goto OUT;
     }
 
   gtk_tree_model_foreach (priv->store_filter,
-      debug_window_store_filter_foreach, output_stream);
+      debug_window_store_filter_foreach, &debug_data);
+
+  g_output_stream_write (G_OUTPUT_STREAM (output_stream), debug_data,
+      strlen (debug_data), NULL, &file_write_error);
+  g_free (debug_data);
+
+  if (file_write_error != NULL)
+    {
+      DEBUG ("Failed to write to file: %s", file_write_error->message);
+      g_error_free (file_write_error);
+    }
 
 OUT:
   if (gfile != NULL)
@@ -1619,6 +1632,135 @@ debug_window_save_clicked_cb (GtkToolButton *tool_button,
   gtk_widget_show (file_chooser);
 }
 
+static void
+debug_window_pastebin_response_dialog_closed_cb (GtkDialog *dialog,
+    gint response_id,
+    SoupBuffer *buffer)
+{
+  soup_buffer_free (buffer);
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static void
+debug_window_pastebin_callback (SoupSession *session,
+    SoupMessage *msg,
+    gpointer debug_window)
+{
+  GtkWidget *dialog;
+  SoupBuffer *buffer;
+
+  buffer = soup_message_body_flatten (msg->response_body);
+  if (g_str_has_prefix (buffer->data, "http://pastebin.com/"))
+    {
+      dialog = gtk_message_dialog_new (GTK_WINDOW (debug_window),
+          GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
+          _("Pastebin link"));
+
+      gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
+          "<a href=\"%s\">%s</a>", buffer->data, buffer->data);
+    }
+  else
+    {
+      dialog = gtk_message_dialog_new (GTK_WINDOW (debug_window),
+          GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
+          _("Pastebin response"));
+
+      if (!tp_str_empty (buffer->data))
+        gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
+            _("%s"), buffer->data);
+      else
+        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+            _("Data too large for a single paste. Please save logs to file."));
+    }
+
+  g_object_unref (session);
+
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), debug_window);
+
+  gtk_widget_show_all (GTK_WIDGET (dialog));
+
+  g_signal_connect_after (dialog, "response", G_CALLBACK (
+      debug_window_pastebin_response_dialog_closed_cb), buffer);
+}
+
+static void
+debug_window_message_dialog (EmpathyDebugWindow *debug_window,
+    const gchar *primary_text,
+    const gchar *secondary_text)
+{
+  GtkWidget *dialog;
+
+  dialog = gtk_message_dialog_new (GTK_WINDOW (debug_window),
+      GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
+      "%s", _(primary_text));
+  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+      "%s", _(secondary_text));
+  gtk_window_set_transient_for (GTK_WINDOW (dialog),
+      GTK_WINDOW (debug_window));
+
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+}
+
+static void
+debug_window_send_to_pastebin (EmpathyDebugWindow *debug_window,
+    gchar *debug_data)
+{
+  SoupSession *session;
+  SoupMessage *msg;
+  gchar       *api_dev_key, *api_paste_code, *api_paste_name, *formdata;
+
+  if (tp_str_empty (debug_data))
+    {
+      debug_window_message_dialog (debug_window, "Error", "No data to send");
+      return;
+    }
+
+  /* Constructing a valid URL for http post. See http://pastebin.com/api#2 */
+
+  /* The api_dev_key is the author's developer key to access the Pastebin API
+   * This developer key is published here with the autorization of pastebin;
+   * see PASTEBIN-API-KEY.txt */
+  api_dev_key = soup_uri_encode ("f6ccfabfdcd4b77b825ee38a30d11d52", NULL);
+  api_paste_code = soup_uri_encode (debug_data, NULL);
+  api_paste_name = soup_uri_encode ("Empathy debug data", NULL);
+  formdata = g_strdup_printf ("api_dev_key=%s&api_paste_code=%s"
+      "&api_paste_name=%s&api_paste_format=text&api_option=paste",
+      api_dev_key, api_paste_code, api_paste_name);
+
+  session = soup_session_async_new ();
+
+  msg = soup_message_new ("POST", "http://pastebin.com/api/api_post.php");
+  soup_message_set_request (msg,
+      "application/x-www-form-urlencoded;charset=UTF-8", SOUP_MEMORY_COPY,
+      formdata, strlen (formdata));
+
+  g_free (api_dev_key);
+  g_free (api_paste_code);
+  g_free (api_paste_name);
+  g_free (formdata);
+
+  soup_session_queue_message (session, msg, debug_window_pastebin_callback,
+      debug_window);
+}
+
+static void
+debug_window_send_to_pastebin_cb (GtkToolButton *tool_button,
+    EmpathyDebugWindow *debug_window)
+{
+  EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
+  gchar *debug_data = NULL;
+
+  DEBUG ("Preparing debug data for sending to pastebin.");
+
+  gtk_tree_model_foreach (priv->store_filter,
+      debug_window_store_filter_foreach, &debug_data);
+
+  debug_window_send_to_pastebin (debug_window, debug_data);
+  g_free (debug_data);
+}
+
 static gboolean
 debug_window_copy_model_foreach (GtkTreeModel *model,
     GtkTreePath *path,
@@ -1813,6 +1955,16 @@ am_prepared_cb (GObject *am,
   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->save_button), TRUE);
   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->save_button, -1);
 
+  /* Send to pastebin */
+  priv->send_to_pastebin = gtk_tool_button_new_from_stock (GTK_STOCK_PASTE);
+  gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->send_to_pastebin),
+      _("Send to pastebin"));
+  g_signal_connect (priv->send_to_pastebin, "clicked",
+      G_CALLBACK (debug_window_send_to_pastebin_cb), object);
+  gtk_widget_show (GTK_WIDGET (priv->send_to_pastebin));
+  gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->send_to_pastebin), TRUE);
+  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->send_to_pastebin, -1);
+
   /* Copy */
   priv->copy_button = gtk_tool_button_new_from_stock (GTK_STOCK_COPY);
   g_signal_connect (priv->copy_button, "clicked",