pidgin: f5644cc4: Add support in Pidgin for playing back a...
qulogic at pidgin.im
qulogic at pidgin.im
Sat Jul 11 03:05:39 EDT 2009
-----------------------------------------------------------------
Revision: f5644cc4891cdcc46fafcec5127d00e48aa48e22
Ancestor: f16870e8dd591a9e962df6d058c15a07dda28fc4
Author: qulogic at pidgin.im
Date: 2009-07-11T07:01:00
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f5644cc4891cdcc46fafcec5127d00e48aa48e22
Modified files:
ChangeLog pidgin/gtkconv.c pidgin/gtkutils.c
ChangeLog:
Add support in Pidgin for playing back audio:// links. Also include a "Save
File" menu item to save a permanent copy.
Playback uses purple_sound_play_file, which uses a playbin. This will not
correctly play back the Siren codec until Bug 588218 is fixed, but that
looks like it will be soon.
Also, if anyone has a better idea for GtkIMHtml->PidginConversation than
g_object_[gs]_data, feel free to fix it.
References #393.
-------------- next part --------------
============================================================
--- ChangeLog 57ab63b111f9711485e150ae4e2ffbc1500202fe
+++ ChangeLog 16b604e428236f384e15fe8d6639102726ce36ad
@@ -29,6 +29,7 @@ version 2.6.0 (??/??/2009):
* Add support for receiving handwritten (ink) messages on MSN.
* Don't do IPv6 address lookups if the computer does not have an IPv6
address configured.
+ * Add support for receiving audio clips on MSN.
AIM and ICQ:
* Preliminary support for a new authentication scheme called
============================================================
--- pidgin/gtkconv.c f6508421e7282993dd2e543bf571bc3c428e602f
+++ pidgin/gtkconv.c e6550fda7d912b25b7df70c7e0dc078e8a5518b4
@@ -4939,6 +4939,7 @@ setup_common_pane(PidginConversation *gt
gtk_widget_set_name(gtkconv->imhtml, "pidgin_conv_imhtml");
gtk_imhtml_show_comments(GTK_IMHTML(gtkconv->imhtml),TRUE);
+ g_object_set_data(gtkconv->imhtml, "gtkconv", gtkconv);
gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(imhtml_sw),
&imhtml_sw_hscroll, NULL);
============================================================
--- pidgin/gtkutils.c 92f0868f0a50bb8082f457453c0726002c9811cc
+++ pidgin/gtkutils.c e60a46ccf1a319be32da76edfa262d238c8bfc3e
@@ -54,6 +54,7 @@
#include "prpl.h"
#include "request.h"
#include "signals.h"
+#include "sound.h"
#include "util.h"
#include "gtkaccount.h"
@@ -3707,6 +3708,83 @@ file_context_menu(GtkIMHtml *imhtml, Gtk
return TRUE;
}
+#define AUDIOLINKSIZE (sizeof("audio://") - 1)
+static gboolean
+audio_clicked_cb(GtkIMHtml *imhtml, GtkIMHtmlLink *link)
+{
+ const char *uri;
+ PidginConversation *conv = g_object_get_data(G_OBJECT(imhtml), "gtkconv");
+ if (!conv) /* no playback in debug window */
+ return TRUE;
+ uri = gtk_imhtml_link_get_url(link) + AUDIOLINKSIZE;
+ purple_sound_play_file(uri, NULL);
+ return TRUE;
+}
+
+static void
+savefile_write_cb(gpointer user_data, char *file)
+{
+ char *temp_file = user_data;
+ gchar *contents;
+ gsize length;
+ GError *error;
+
+ if (!g_file_get_contents(temp_file, &contents, &length, &error)) {
+ purple_debug_error("gtkutils", "Unable to read contents of %s: %s\n",
+ temp_file, error->message);
+ g_error_free(error);
+ return;
+ }
+
+ if (!g_file_set_contents(file, contents, length, &error)) {
+ purple_debug_error("gtkutils", "Unable to write contents to %s: %s\n",
+ file, error->message);
+ g_error_free(error);
+ }
+}
+
+static gboolean
+save_file_cb(GtkWidget *item, const char *url)
+{
+ PidginConversation *conv = g_object_get_data(G_OBJECT(item), "gtkconv");
+ if (!conv)
+ return TRUE;
+ purple_request_file(conv->active_conv, _("Save File"), NULL, TRUE,
+ G_CALLBACK(savefile_write_cb), NULL,
+ conv->active_conv->account, NULL, conv->active_conv,
+ (void *)url);
+ return TRUE;
+}
+
+static gboolean
+audio_context_menu(GtkIMHtml *imhtml, GtkIMHtmlLink *link, GtkWidget *menu)
+{
+ GtkWidget *img, *item;
+ const char *url;
+ PidginConversation *conv = g_object_get_data(G_OBJECT(imhtml), "gtkconv");
+ if (!conv) /* No menu in debug window */
+ return TRUE;
+
+ url = gtk_imhtml_link_get_url(link);
+
+ /* Play Sound */
+ img = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_MENU);
+ item = gtk_image_menu_item_new_with_mnemonic(_("_Play Sound"));
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
+ g_signal_connect_swapped(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_link_activate), link);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+
+ /* Save File */
+ img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU);
+ item = gtk_image_menu_item_new_with_mnemonic(_("_Save File"));
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
+ g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(save_file_cb), (gpointer)(url+AUDIOLINKSIZE));
+ g_object_set_data(G_OBJECT(item), "gtkconv", conv);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+
+ return TRUE;
+}
+
/* XXX: The following two functions are for demonstration purposes only! */
static gboolean
open_dialog(GtkIMHtml *imhtml, GtkIMHtmlLink *link)
@@ -3814,6 +3892,7 @@ void pidgin_utils_init(void)
gtk_imhtml_class_register_protocol("mailto:", url_clicked_cb, copy_email_address);
gtk_imhtml_class_register_protocol("file://", file_clicked_cb, file_context_menu);
+ gtk_imhtml_class_register_protocol("audio://", audio_clicked_cb, audio_context_menu);
/* Example custom URL handler. */
gtk_imhtml_class_register_protocol("open://", open_dialog, dummy);
@@ -3840,6 +3919,8 @@ void pidgin_utils_uninit(void)
gnome_url_handlers = NULL;
return;
}
+
+ gtk_imhtml_class_register_protocol("audio://", NULL, NULL);
gtk_imhtml_class_register_protocol("file://", NULL, NULL);
gtk_imhtml_class_register_protocol("http://", NULL, NULL);
More information about the Commits
mailing list