]> granicus.if.org Git - transmission/commitdiff
(trunk gtk) #3132 "paste clipboard contents into textbox in Add URL dialog" -- implem...
authorCharles Kerr <charles@transmissionbt.com>
Sun, 11 Apr 2010 14:18:29 +0000 (14:18 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 11 Apr 2010 14:18:29 +0000 (14:18 +0000)
gtk/add-dialog.c

index f2bf20a4c7a112dbb817dcc3ed946b6eef41b6f8..c11e1d13cbf969dd27ca58b94d51bb89f23e3e81 100644 (file)
@@ -492,6 +492,28 @@ onAddURLResponse( GtkDialog * dialog, int response, gpointer user_data )
         gtk_widget_destroy( GTK_WIDGET( dialog ) );
 }
 
+static void
+paste_clipboard_url_into_entry( GtkWidget * e )
+{
+  size_t i;
+
+  char * text[] = {
+    gtk_clipboard_wait_for_text( gtk_clipboard_get( GDK_SELECTION_PRIMARY ) ),
+    gtk_clipboard_wait_for_text( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ) )
+  };
+
+  for( i=0; i<G_N_ELEMENTS(text); ++i ) {
+      char * s = text[i];
+      if( s && ( gtr_is_supported_url( s ) || gtr_is_magnet_link( s ) ) ) {
+          gtk_entry_set_text( GTK_ENTRY( e ), s );
+          break;
+      }
+  }
+
+  for( i=0; i<G_N_ELEMENTS(text); ++i )
+    g_free( text[i] );
+}
+
 GtkWidget*
 addURLDialog( GtkWindow * parent, TrCore * core )
 {
@@ -515,6 +537,7 @@ addURLDialog( GtkWindow * parent, TrCore * core )
     t = hig_workarea_create( );
     hig_workarea_add_section_title( t, &row, _( "Add torrent from URL" ) );
     e = gtk_entry_new( );
+    paste_clipboard_url_into_entry( e );
     g_object_set_data( G_OBJECT( w ), "url-entry", e );
     hig_workarea_add_row( t, &row, _( "_URL" ), e, NULL );