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 11092 2010-08-01 20:36:13Z 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( );
46 char * raw
= tr_base64_decode( key
.toUtf8().constData(), key
.toUtf8().size(), &len
);
48 metainfo
.append( raw
, len
);
59 AddData :: toBase64( ) const
63 if( !metainfo
.isEmpty( ) )
66 char * b64
= tr_base64_encode( metainfo
.constData(), metainfo
.size(), &len
);
67 ret
= QByteArray( b64
, len
);
75 AddData :: readableName( ) const
81 case FILENAME
: ret
= filename
; break;
83 case MAGNET
: ret
= magnet
; break;
85 case URL
: ret
= url
.toString(); break;
89 tr_ctor
* ctor
= tr_ctorNew( NULL
);
90 tr_ctorSetMetainfo( ctor
, (const uint8_t*)metainfo
.constData(), metainfo
.size() );
91 if( tr_torrentParse( ctor
, &inf
) == TR_PARSE_OK
) {
93 tr_metainfoFree( &inf
);