]> granicus.if.org Git - transmission/commitdiff
(trunk qt) #3930 - "Add URL" - auto-copy links from the clipboard
authorJordan Lee <jordan@transmissionbt.com>
Fri, 21 Jan 2011 21:51:50 +0000 (21:51 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Fri, 21 Jan 2011 21:51:50 +0000 (21:51 +0000)
When opening the "Add URL" dialog, check the clipboard selection & clipboard proper to see if either contains a URL, magnet link, or info hash code. If it has any of those things, put that in the dialog's entry field as the default action. Patch by cantabile.

qt/add-data.h
qt/mainwin.cc

index dee851329ba2945af6270926dabe92f2c46ef8e8..159282c7f68337a591fbb01bfe93812a1d174345 100644 (file)
@@ -40,6 +40,10 @@ class AddData
         QByteArray toBase64( ) const;
 
         QString readableName( ) const;
+
+    public:
+
+        static bool isSupported( const QString& str ) { return AddData(str).type != NONE; }
 };
 
 #endif
index d15e2cad98621232aebc6247f00b5feec4e00ee5..beb800cfde11ff6aca8ad02d28a32ba8fe8fd151 100644 (file)
@@ -20,6 +20,7 @@
 #include <libtransmission/version.h>
 
 #include "about.h"
+#include "add-data.h"
 #include "app.h"
 #include "details.h"
 #include "filterbar.h"
@@ -1047,8 +1048,15 @@ TrMainWindow :: openTorrent( )
 void
 TrMainWindow :: openURL( )
 {
-    QString tmp;
-    openURL( tmp );
+    QString str = QApplication::clipboard()->text( QClipboard::Selection );
+
+    if( !AddData::isSupported( str ) )
+        str = QApplication::clipboard()->text( QClipboard::Clipboard );
+
+    if( !AddData::isSupported( str ) )
+        str.clear();
+
+    openURL( str );
 }
 
 void