2 * This file Copyright (C) Mnemosyne LLC
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
8 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10 * $Id: add-data.cc 11623 2011-01-02 23:42:46Z charles $
13 #include <libtransmission/transmission.h>
14 #include <libtransmission/bencode.h> // tr_base64_encode()
15 #include <libtransmission/utils.h> // tr_base64_encode()
21 AddData :: set( const QString
& key
)
23 if( Utils::isMagnetLink( key
) )
28 else if ( Utils::isURL( key
) )
33 else if( QFile(key
).exists( ) )
39 file
.open( QIODevice::ReadOnly
);
40 metainfo
= file
.readAll( );
43 else if( Utils::isHexHashcode( key
) )
45 magnet
= QString("magnet:?xt=urn:btih:") + key
;
51 char * raw
= tr_base64_decode( key
.toUtf8().constData(), key
.toUtf8().size(), &len
);
53 metainfo
.append( raw
, len
);
64 AddData :: toBase64( ) const
68 if( !metainfo
.isEmpty( ) )
71 char * b64
= tr_base64_encode( metainfo
.constData(), metainfo
.size(), &len
);
72 ret
= QByteArray( b64
, len
);
80 AddData :: readableName( ) const
86 case FILENAME
: ret
= filename
; break;
88 case MAGNET
: ret
= magnet
; break;
90 case URL
: ret
= url
.toString(); break;
94 tr_ctor
* ctor
= tr_ctorNew( NULL
);
95 tr_ctorSetMetainfo( ctor
, (const uint8_t*)metainfo
.constData(), metainfo
.size() );
96 if( tr_torrentParse( ctor
, &inf
) == TR_PARSE_OK
) {
98 tr_metainfoFree( &inf
);