[rhythmbox] uri-dialog: try to populate the entry with a URL from the clipboard (bug #633542)
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] uri-dialog: try to populate the entry with a URL from the clipboard (bug #633542)
- Date: Sun, 31 Oct 2010 23:46:11 +0000 (UTC)
commit 75d05fd452ad2452ed564ea34ba5c49211db1af9
Author: Diogo F. S. Ramos <diogofsr gmail com>
Date: Mon Nov 1 09:44:53 2010 +1000
uri-dialog: try to populate the entry with a URL from the clipboard (bug #633542)
widgets/rb-uri-dialog.c | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/widgets/rb-uri-dialog.c b/widgets/rb-uri-dialog.c
index 6e4ca83..a0ba9bc 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 char *text,
+ gpointer data);
struct RBURIDialogPrivate
{
@@ -173,6 +177,16 @@ rb_uri_dialog_init (RBURIDialog *dialog)
G_CALLBACK (rb_uri_dialog_text_changed),
dialog, 0);
+ /* if we can get a url from the clipboard, populate the entry with that,
+ * since there's a good chance that's what the user wants to do anyway.
+ */
+ gtk_clipboard_request_text (gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
+ rb_uri_dialog_clipboard_yank_url,
+ dialog);
+ gtk_clipboard_request_text (gtk_clipboard_get(GDK_SELECTION_PRIMARY),
+ rb_uri_dialog_clipboard_yank_url,
+ dialog);
+
/* default focus */
gtk_widget_grab_focus (dialog->priv->url);
@@ -272,3 +286,24 @@ 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 char *text, gpointer data)
+{
+ RBURIDialog *dialog = RB_URI_DIALOG (data);
+ SoupURI *uri;
+
+ if (text == NULL) {
+ return;
+ }
+
+ uri = soup_uri_new (text);
+ if (SOUP_URI_VALID_FOR_HTTP (uri)) {
+ gtk_entry_set_text (GTK_ENTRY (dialog->priv->url),
+ soup_uri_to_string (uri, FALSE));
+ gtk_editable_select_region (GTK_EDITABLE (dialog->priv->url), 0, -1);
+ }
+
+ if (uri != NULL) {
+ soup_uri_free (uri);
+ }
+}
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]