From 5ccbb741b056e94ec20cfc7921715a7a7c539fe1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 2 Jan 2011 23:42:46 +0000 Subject: [PATCH] (trunk qt) #3863 "accept info hash in 'Add url...' dialog, not just magnet uris" -- added. --- qt/add-data.cc | 5 +++++ qt/utils.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/qt/add-data.cc b/qt/add-data.cc index 94d3551fe..cc02feb0f 100644 --- a/qt/add-data.cc +++ b/qt/add-data.cc @@ -40,6 +40,11 @@ AddData :: set( const QString& key ) metainfo = file.readAll( ); file.close( ); } + else if( Utils::isHexHashcode( key ) ) + { + magnet = QString("magnet:?xt=urn:btih:") + key; + type = MAGNET; + } else { int len; diff --git a/qt/utils.h b/qt/utils.h index 0557cf3e7..e28683dcc 100644 --- a/qt/utils.h +++ b/qt/utils.h @@ -17,6 +17,8 @@ #include #include +#include // isxdigit() + #include "speed.h" class Utils: public QObject @@ -40,6 +42,13 @@ class Utils: public QObject static bool isMagnetLink( const QString& s ) { return s.startsWith( "magnet:?" ); } + static bool isHexHashcode( const QString& s ) + { + if( s.length() != 40 ) return false; + foreach( QChar ch, s ) if( !isxdigit( ch.toAscii() ) ) return false; + return true; + } + static bool isURL( const QString& s ) { return s.startsWith( "http://" ) || s.startsWith( "https://" ) || s.startsWith( "ftp://" ); }