[Rhythmbox-devel] [PATCH] Automatic inserts an uri for a new radio station



Whenever a user wants to insert a new radio station, the odds are that
he or she already had selected or copied the address of that station
to the clipboard.

I propose this patch, which automatic inserts a uri, if there is any
inside of the clipboard, at the entry address of the uri dialog.

-- 
Diogo F. S. Ramos
>From d054465f4946f0136c468c012d820be7421e6a78 Mon Sep 17 00:00:00 2001
From: Diogo F. S. Ramos <diogofsr gmail com>
Date: Fri, 29 Oct 2010 13:55:18 -0200
Subject: [PATCH] Automatic inserts an uri for a new radio station.

---
 widgets/rb-uri-dialog.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/widgets/rb-uri-dialog.c b/widgets/rb-uri-dialog.c
index 6e4ca83..95fd9f7 100644
--- a/widgets/rb-uri-dialog.c
+++ b/widgets/rb-uri-dialog.c
@@ -33,6 +33,7 @@
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <libsoup/soup.h>
 
 #include "rb-uri-dialog.h"
 #include "rb-builder-helpers.h"
@@ -62,6 +63,9 @@ static void rb_uri_dialog_get_property (GObject *object,
 					guint prop_id,
 					GValue *value,
 					GParamSpec *pspec);
+static void rb_uri_dialog_clipboard_yank_url(GtkClipboard *clipboard,
+					     const gchar *url,
+					     gpointer data);
 
 struct RBURIDialogPrivate
 {
@@ -173,6 +177,13 @@ rb_uri_dialog_init (RBURIDialog *dialog)
 				 G_CALLBACK (rb_uri_dialog_text_changed),
 				 dialog, 0);
 
+	gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
+				   &rb_uri_dialog_clipboard_yank_url,
+				   dialog->priv->url);
+	gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY),
+				   &rb_uri_dialog_clipboard_yank_url,
+				   dialog->priv->url);
+
 	/* default focus */
 	gtk_widget_grab_focus (dialog->priv->url);
 
@@ -272,3 +283,16 @@ rb_uri_dialog_text_changed (GtkEditable *buffer,
 	gtk_widget_set_sensitive (dialog->priv->okbutton, has_text);
 }
 
+static void
+rb_uri_dialog_clipboard_yank_url(GtkClipboard *clipboard, const gchar *url, gpointer data)
+{
+	if (url) {
+		SoupURI * soup = soup_uri_new (url);
+		if (soup) {
+			GtkEntry *url_entry = GTK_ENTRY (data);
+			gtk_entry_set_text (url_entry,
+					    soup_uri_to_string(soup, FALSE));
+			soup_uri_free (soup);
+		}
+	}
+}
-- 
1.7.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]