e.printStackTrace();
}
}
};
final TableContextMenuItem menu1 = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, "MagnetPlugin.contextmenu.exporturi" );
final TableContextMenuItem menu2 = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE, "MagnetPlugin.contextmenu.exporturi" );
menu1.addListener( listener );
menu2.addListener( listener );
MagnetURIHandler.getSingleton().addListener(
new MagnetURIHandlerListener()
{
public byte[]
badge()
{
InputStream is = getClass().getClassLoader().getResourceAsStream( "com/aelitis/azureus/plugins/magnet/Magnet.gif" );
if ( is == null ){
return( null );
}
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try{
byte[] buffer = new byte[8192];
while( true ){
int len = is.read( buffer );
if ( len <= 0 ){
break;
}
baos.write( buffer, 0, len );
}
}finally{
is.close();
}
return( baos.toByteArray());
}catch( Throwable e ){
Debug.printStackTrace(e);
return( null );
}
}
public byte[]
download(
final MagnetURIHandlerProgressListener muh_listener,
final byte[] hash,
final String args,
final InetSocketAddress[] sources,
final long timeout )
throws MagnetURIHandlerException
{
// see if we've already got it!
try{
Download dl = plugin_interface.getDownloadManager().getDownload( hash );
if ( dl != null ){
Torrent torrent = dl.getTorrent();
if ( torrent != null ){
return( torrent.writeToBEncodedData());
}
}
}catch( Throwable e ){
Debug.printStackTrace(e);
}
return( MagnetPlugin.this.download(
new MagnetPluginProgressListener()
{
public void
reportSize(
long size )
{
muh_listener.reportSize( size );
}
public void
reportActivity(
String str )
{
muh_listener.reportActivity( str );
}
public void
reportCompleteness(
int percent )
{
muh_listener.reportCompleteness( percent );
}
public void
reportContributor(
InetSocketAddress address )
{
}
public boolean
verbose()
{
return( muh_listener.verbose());
}
},
hash,
args,
sources,
timeout ));
}
public boolean
download(
URL url )
throws MagnetURIHandlerException
{
try{
plugin_interface.getDownloadManager().addDownload( url, false );
return( true );
}catch( DownloadException e ){
throw( new MagnetURIHandlerException( "Operation failed", e ));
}
}
public boolean
set(
String name,
Map values )
{
List l = listeners.getList();
for (int i=0;i<l.size();i++){
if (((MagnetPluginListener)l.get(i)).set( name, values )){
return( true );
}
}
return( false );
}
public int
get(
String name,
Map values )
{
List l = listeners.getList();
for (int i=0;i<l.size();i++){
int res = ((MagnetPluginListener)l.get(i)).get( name, values );
if ( res != Integer.MIN_VALUE ){
return( res );
}
}
return( Integer.MIN_VALUE );
}
});
plugin_interface.addListener(
new PluginListener()
{
public void
initializationComplete()
{
// make sure DDB is initialised as we need it to register its
// transfer types
AEThread2 t =
new AEThread2( "MagnetPlugin:init", true )
{
public void
run()
{
plugin_interface.getDistributedDatabase();
}
};
t.start();
}
public void
closedownInitiated(){}
public void
closedownComplete(){}
});
plugin_interface.getUIManager().addUIListener(
new UIManagerListener()
{
public void
UIAttached(
UIInstance instance )
{
if ( instance instanceof UISWTInstance ){
UISWTInstance swt = (UISWTInstance)instance;
Image image = swt.loadImage( "com/aelitis/azureus/plugins/magnet/icons/magnet.gif" );
menu1.setGraphic( swt.createGraphic( image ));
menu2.setGraphic( swt.createGraphic( image ));
}
}
public void
UIDetached(