Package org.gudy.azureus2.core3.peer

Examples of org.gudy.azureus2.core3.peer.PEPeerManager$StatsReceiver


    if ( isRecheck ){
     
      if ( last_recheck_time > now || now - last_recheck_time < 23*60*60*1000 ){
       
        if (Logger.isEnabled())
          Logger.log(new LogEvent(LOGID,
              "skipping recheck as consecutive recheck too soon"));

        return;
      }
     
      last_recheck_time = now;
     
    }else{
     
      last_recheck_time  = 0;
    }
   
    if (SystemProperties.isJavaWebStartInstance()) {

      // just in case we get here somehome!
      if (Logger.isEnabled())
        Logger.log(new LogEvent(LOGID,
            "skipping update check as java web start"));

      return;
    }

View Full Code Here


             
              pw.close();
             
              final String  info = sw.toString();
             
              Logger.log( new LogEvent(LOGID, "Network Info:\n" + info));

              Utils.execSWTThread(
                new Runnable()
                {
                  public void
                  run()
                  {
                    ClipboardCopy.copyToClipBoard( info );
                  }
                });
            }
          }.start();
        }
      });
   
  // stats
 
  Label generate_stats_info = new Label(gLogging, SWT.NULL);
  Messages.setLanguageText(generate_stats_info, CFG_PREFIX + "statsinfo");

  Button generate_stats_button = new Button(gLogging, SWT.PUSH);
  Messages.setLanguageText(generate_stats_button, CFG_PREFIX + "generatediagnostics");

 
  generate_stats_button.addListener(
      SWT.Selection,
      new Listener()
      {
        public void
        handleEvent(Event event)
        {
          java.util.Set  types = new HashSet();
         
          types.add( AzureusCoreStats.ST_ALL );
         
          Map  reply = AzureusCoreStats.getStats( types );
         
          Iterator  it = reply.entrySet().iterator();
         
          StringBuffer buffer = new StringBuffer(16000);
         
          while( it.hasNext()){
           
            Map.Entry  entry = (Map.Entry)it.next();
           
            buffer.append( entry.getKey() + " -> " + entry.getValue() + "\r\n" );
          }
         
          String  str = buffer.toString();
         
          ClipboardCopy.copyToClipBoard( str );

          Logger.log( new LogEvent(LOGID, "Stats Info:\n" + str));
        }
      });

        // diagnostics

   
  Label generate_info = new Label(gLogging, SWT.NULL);

  Messages.setLanguageText(generate_info, CFG_PREFIX + "generatediagnostics.info");

  Button generate_button = new Button(gLogging, SWT.PUSH);

  Messages.setLanguageText(generate_button, CFG_PREFIX + "generatediagnostics");

  generate_button.addListener(
      SWT.Selection,
      new Listener()
      {
        public void
        handleEvent(Event event)
        {
          StringWriter sw = new StringWriter();
         
          PrintWriter  pw = new PrintWriter( sw );
         
          AEDiagnostics.generateEvidence( pw );
         
          pw.close();
         
          String  evidence = sw.toString();
         
          ClipboardCopy.copyToClipBoard( evidence );

          Logger.log( new LogEvent(LOGID, "Evidence Generation:\n" + evidence));
        }
      });
 
  if ( false ){
    Button test_button = new Button(gLogging, SWT.PUSH);
View Full Code Here

              }
            }
          });
        } else {
          if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING,
                "UpdateMonitor: user dialog already "
                    + "in progress, updates skipped"));
        }

      }
    } else {
      if (Logger.isEnabled())
        Logger.log(new LogEvent(LOGID, "UpdateMonitor: check instance "
            + "resulted in no user-actionable updates"));

    }
  }
View Full Code Here

          }
        });
      }

    } catch (Throwable t) {
      Logger.log(new LogEvent(LOGID, "failed to init drag-n-drop", t));
    }
  }
View Full Code Here

   
    if ( verbose ){
     
      out.println( "Pieces" );
     
      PEPeerManager pm = dm.getPeerManager();
     
      if ( pm != null ){
       
        PiecePicker picker = pm.getPiecePicker();
       
        PEPiece[] pieces = pm.getPieces();
       
        String  line = "";
       
        for (int i=0;i<pieces.length;i++){
         
View Full Code Here

   
    String swarm_completion = "";
    String distributedCopies = "0.000";
    String piecesDoneAndSum = ""+manager.getNbPieces();
   
    PEPeerManager pm = manager.getPeerManager();
    if( pm != null ) {
      int comp = pm.getAverageCompletionInThousandNotation();
      if( comp >= 0 ) {
        swarm_completion = DisplayFormatters.formatPercentFromThousands( comp );
      }
     
      piecesDoneAndSum = pm.getPiecePicker().getNbPiecesDone() + "/" + piecesDoneAndSum;
     
      distributedCopies = new DecimalFormat("0.000").format(pm.getPiecePicker().getMinAvailability()-pm.getNbSeeds()-(pm.isSeeding()&&stats.getDownloadCompleted(false)==1000?1:0));
    }
   
   

    setStats(
View Full Code Here

    try{
      this_mon.enter();
   
      final int[] available;
     
      PEPeerManager  pm = manager.getPeerManager();
     
      if (manager.getPeerManager() == null) {
        if (availabilityPercent.getText() != "")
         
          availabilityPercent.setText("");
     
          available  = new int[manager.getNbPieces()];
      }else{
        available  = pm.getAvailability();
      }
     
      if (display == null || display.isDisposed())
        return;
 
View Full Code Here

        boolean incomplete = !dm.isDownloadComplete(true);

        allScanSelected = incomplete && allScanSelected && scan;
        allScanNotSelected = incomplete && allScanNotSelected && !scan;

        PEPeerManager pm = dm.getPeerManager();

        if (pm != null) {

          if (pm.canToggleSuperSeedMode()) {

            canSetSuperSeed = true;
          }

          if (pm.isSuperSeedMode()) {

            superSeedAllYes = false;

          }
          else {

            superSeedAllNo = false;
          }
        }
        else {
          superSeedAllYes = false;
          superSeedAllNo = false;
        }
      }

      fileRescan = allScanSelected || allScanNotSelected;

    }
    else { // empty right-click
      barsOpened = false;
      forceStart = false;
      forceStartEnabled = false;

      start = false;
      stop = false;
      fileMove = false;
      fileRescan = false;
      upSpeedDisabled = true;
      downSpeedDisabled = true;
      changeUrl = false;
      recheck = false;
      manualUpdate = false;
    }

    // === Root Menu ===

    if (bChangeDir) {
      MenuItem menuItemChangeDir = new MenuItem(menu, SWT.PUSH);
      Messages.setLanguageText(menuItemChangeDir, "MyTorrentsView.menu.changeDirectory");
      menuItemChangeDir.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          changeDirSelectedTorrents(dms, composite.getShell());
        }
      });
    }

    // Open Details
    if (include_show_details) {
      final MenuItem itemDetails = new MenuItem(menu, SWT.PUSH);
      Messages.setLanguageText(itemDetails, "MyTorrentsView.menu.showdetails");
      menu.setDefaultItem(itemDetails);
      Utils.setMenuItemImage(itemDetails, "details");
      itemDetails.addListener(SWT.Selection, new DMTask(dms) {
        public void run(DownloadManager dm) {
          UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
          if (uiFunctions != null) {
            uiFunctions.openView(UIFunctions.VIEW_DM_DETAILS, dm);
          }
        }
      });
      itemDetails.setEnabled(hasSelection);
    }

    // Open Bar
    final MenuItem itemBar = new MenuItem(menu, SWT.CHECK);
    Messages.setLanguageText(itemBar, "MyTorrentsView.menu.showdownloadbar");
    Utils.setMenuItemImage(itemBar, "downloadBar");
    itemBar.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager dm) {
        if (DownloadBar.getManager().isOpen(dm)) {
          DownloadBar.close(dm);
        }
        else {
          DownloadBar.open(dm, menu.getShell());
        }
      } // run
    });
    itemBar.setEnabled(hasSelection);
    itemBar.setSelection(barsOpened);

    // ---
    new MenuItem(menu, SWT.SEPARATOR);

    // Run Data File
    final MenuItem itemOpen = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemOpen, "MyTorrentsView.menu.open");
    Utils.setMenuItemImage(itemOpen, "run");
    itemOpen.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager[] dms) {
        runDataSources(dms);
      }
    });
    itemOpen.setEnabled(hasSelection);

    // Explore (or open containing folder)
    final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
    final MenuItem itemExplore = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemExplore, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"));
    itemExplore.addListener(SWT.Selection, new DMTask(dms, false) {
      public void run(DownloadManager dm) {
        ManagerUtils.open(dm, use_open_containing_folder);
      }
    });
    itemExplore.setEnabled(hasSelection);

    // === advanced menu ===

    final MenuItem itemAdvanced = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(itemAdvanced, "MyTorrentsView.menu.advancedmenu"); //$NON-NLS-1$
    itemAdvanced.setEnabled(hasSelection);

    final Menu menuAdvanced = new Menu(menu.getShell(), SWT.DROP_DOWN);
    itemAdvanced.setMenu(menuAdvanced);

    // advanced > Download Speed Menu //

    long maxDownload = COConfigurationManager.getIntParameter("Max Download Speed KBs", 0) * 1024;
    long maxUpload = COConfigurationManager.getIntParameter("Max Upload Speed KBs", 0) * 1024;

    ViewUtils.addSpeedMenu(menu.getShell(), menuAdvanced, true, hasSelection, downSpeedDisabled, downSpeedUnlimited,
        totalDownSpeed, downSpeedSetMax, maxDownload, upSpeedDisabled, upSpeedUnlimited, totalUpSpeed,
        upSpeedSetMax, maxUpload, dms.length, new ViewUtils.SpeedAdapter() {
          public void setDownSpeed(final int speed) {
            DMTask task = new DMTask(dms) {
              public void run(DownloadManager dm) {
                dm.getStats().setDownloadRateLimitBytesPerSecond(speed);
              }
            };
            task.go();
          }

          public void setUpSpeed(final int speed) {
            DMTask task = new DMTask(dms) {
              public void run(DownloadManager dm) {
                dm.getStats().setUploadRateLimitBytesPerSecond(speed);
              }
            };
            task.go();
          }
        });

    // advanced > Tracker Menu //
    final Menu menuTracker = new Menu(menu.getShell(), SWT.DROP_DOWN);
    final MenuItem itemTracker = new MenuItem(menuAdvanced, SWT.CASCADE);
    Messages.setLanguageText(itemTracker, "MyTorrentsView.menu.tracker");
    itemTracker.setMenu(menuTracker);

    final MenuItem itemChangeTracker = new MenuItem(menuTracker, SWT.PUSH);
    Messages.setLanguageText(itemChangeTracker, "MyTorrentsView.menu.changeTracker"); //$NON-NLS-1$
    Utils.setMenuItemImage(itemChangeTracker, "add_tracker");
    itemChangeTracker.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager[] dms) {
        if ( dms.length > 0 ){
          new TrackerChangerWindow(composite.getDisplay(), dms);
        }
      }
    });
    itemChangeTracker.setEnabled(changeUrl);

    final MenuItem itemEditTracker = new MenuItem(menuTracker, SWT.PUSH);
    Messages.setLanguageText(itemEditTracker, "MyTorrentsView.menu.editTracker");
    Utils.setMenuItemImage(itemEditTracker, "edit_trackers");
    itemEditTracker.addListener(SWT.Selection, new DMTask(dms) {
      public void
      run(
        final DownloadManager[] dms )
      {
        Map<String,List<DownloadManager>>  same_map = new HashMap<String, List<DownloadManager>>();
       
        for ( DownloadManager dm: dms ){
         
          TOTorrent torrent = dm.getTorrent();
         
          if ( torrent == null ){
           
            continue;
          }
         
          List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
         
          String str = "";
         
          for ( List<String> l: group ){
            str += "[[";
           
            for ( String s:l ){
              str += s + ", ";
            }
          }
         
          List<DownloadManager> dl = same_map.get( str );
         
          if ( dl == null ){
           
            dl = new ArrayList<DownloadManager>();
           
            same_map.put( str, dl );
          }
         
          dl.add(dm );
        }
       
        for ( final List<DownloadManager> set: same_map.values()){
                   
          TOTorrent torrent = set.get(0).getTorrent();

          List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);

          new MultiTrackerEditor(
            null,
            group,
            new TrackerEditorListener()
            {
              public void
              trackersChanged(
                String         str,
                String         str2,
                List<List<String>>   group )
              {
                for ( DownloadManager dm: set ){
                 
                  TOTorrent torrent = dm.getTorrent();
                 
                  TorrentUtils.listToAnnounceGroups(group, torrent);
   
                  try{
                    TorrentUtils.writeToFile(torrent);
                   
                  }catch (Throwable e){
                   
                    Debug.printStackTrace(e);
                  }
   
                  if ( dm.getTrackerClient() != null){
                   
                    dm.getTrackerClient().resetTrackerUrl(true);
                  }
                }
              }
            }, true);
        }
      }
    });
   
    itemEditTracker.setEnabled(hasSelection);

      // edit webseeds
   
    final MenuItem itemEditWebSeeds = new MenuItem(menuTracker, SWT.PUSH);
    Messages.setLanguageText(itemEditWebSeeds, "MyTorrentsView.menu.editWebSeeds");
    itemEditWebSeeds.addListener(SWT.Selection, new DMTask(dms) {
      public void
      run(
        final DownloadManager[] dms )
      {
        final TOTorrent torrent = dms[0].getTorrent();
       
        if ( torrent == null ){
         
          return;
        }
       
        List getright = getURLList( torrent, "url-list" );
        List webseeds = getURLList( torrent, "httpseeds" );
       
        Map ws = new HashMap();
               
        ws.put( "getright", getright );               
        ws.put( "webseeds", webseeds );
       
        ws = BDecoder.decodeStrings( ws );
       
        new WebSeedsEditor(
            null, ws,
            new WebSeedsEditorListener()
            {
              public void
              webSeedsChanged(
                String   oldName,
                String   newName,
                Map   ws )
              {
                try{
                    // String -> byte[]
                 
                  ws = BDecoder.decode( BEncoder.encode( ws ));
                 
                  List  getright =  (List)ws.get( "getright" );
                 
                  if ( getright == null || getright.size() == 0 ){
                   
                    torrent.removeAdditionalProperty( "url-list" );
                   
                  }else{
                   
                    torrent.setAdditionalListProperty( "url-list", getright );
                  }
                 
                  List  webseeds =  (List)ws.get( "webseeds" );
                 
                  if ( webseeds == null || webseeds.size() == 0 ){
                   
                    torrent.removeAdditionalProperty( "httpseeds" );
                   
                  }else{
                   
                    torrent.setAdditionalListProperty( "httpseeds", webseeds );
                  }
     
                  PluginInterface pi = AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(ExternalSeedPlugin.class);
                 
                  if ( pi != null ){
                   
                    ExternalSeedPlugin ext_seed_plugin = (ExternalSeedPlugin)pi.getPlugin();
                   
                    ext_seed_plugin.downloadChanged( PluginCoreUtils.wrap( dms[0] ));
                  }
           
                }catch (Throwable e){
           
                  Debug.printStackTrace( e );
                }
              }
            },
            true );

      }
     
      protected List
      getURLList(
        TOTorrent  torrent,
        String    key )
      {
        Object obj = torrent.getAdditionalProperty( key );
       
        if ( obj instanceof byte[] ){
         
                  List l = new ArrayList();
                 
              l.add(obj);
             
              return( l );
             
        }else if ( obj instanceof List ){
         
          return((List)obj);
         
        }else{
         
          return( new ArrayList());
        }
      }
    });
   
    itemEditWebSeeds.setEnabled(dms.length==1);

      // manual update
   
    final MenuItem itemManualUpdate = new MenuItem(menuTracker, SWT.PUSH);
    Messages.setLanguageText(itemManualUpdate, "GeneralView.label.trackerurlupdate"); //$NON-NLS-1$
    //itemManualUpdate.setImage(ImageRepository.getImage("edit_trackers"));
    itemManualUpdate.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager dm) {
        dm.requestTrackerAnnounce(false);
      }
    });
    itemManualUpdate.setEnabled(manualUpdate);

    boolean scrape_enabled = COConfigurationManager.getBooleanParameter("Tracker Client Scrape Enable");

    boolean scrape_stopped = COConfigurationManager.getBooleanParameter("Tracker Client Scrape Stopped Enable");

    boolean manualScrape = (!scrape_enabled) || ((!scrape_stopped) && allStopped);

    final MenuItem itemManualScrape = new MenuItem(menuTracker, SWT.PUSH);
    Messages.setLanguageText(itemManualScrape, "GeneralView.label.trackerscrapeupdate");
    //itemManualUpdate.setImage(ImageRepository.getImage("edit_trackers"));
    itemManualScrape.addListener(SWT.Selection, new DMTask(dms, true, true ) {
      public void run(DownloadManager dm) {
        dm.requestTrackerScrape(true);
      }
    });
    itemManualScrape.setEnabled(manualScrape);

    // advanced > files

    final MenuItem itemFiles = new MenuItem(menuAdvanced, SWT.CASCADE);
    Messages.setLanguageText(itemFiles, "ConfigView.section.files");

    final Menu menuFiles = new Menu(composite.getShell(), SWT.DROP_DOWN);
    itemFiles.setMenu(menuFiles);

    final MenuItem itemFileMoveData = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileMoveData, "MyTorrentsView.menu.movedata");
    itemFileMoveData.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager[] dms) {
        if (dms != null && dms.length > 0) {

          DirectoryDialog dd = new DirectoryDialog(composite.getShell());

          dd.setFilterPath(TorrentOpener.getFilterPathData());

          dd.setText(MessageText.getString("MyTorrentsView.menu.movedata.dialog"));

          String path = dd.open();

          if (path != null) {

            TorrentOpener.setFilterPathData(path);

            File target = new File(path);

            for (int i = 0; i < dms.length; i++) {

              try {
                dms[i].moveDataFiles(target);

              }
              catch (Throwable e) {

                Logger.log(new LogAlert(dms[i], LogAlert.REPEATABLE,
                    "Download data move operation failed", e));
              }
            }
          }
        }
      }
    });
    itemFileMoveData.setEnabled(fileMove);

    final MenuItem itemFileMoveTorrent = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileMoveTorrent, "MyTorrentsView.menu.movetorrent");
    itemFileMoveTorrent.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager[] dms) {
        if (dms != null && dms.length > 0) {

          DirectoryDialog dd = new DirectoryDialog(composite.getShell());
          String filter_path = TorrentOpener.getFilterPathTorrent();
         
          // If we don't have a decent path, default to the path of the first
          // torrent.
          if (filter_path == null || filter_path.trim().length() == 0) {
            filter_path = new File(dms[0].getTorrentFileName()).getParent();
          }
         
          dd.setFilterPath(filter_path);

          dd.setText(MessageText.getString("MyTorrentsView.menu.movedata.dialog"));

          String path = dd.open();

          if (path != null) {

            File target = new File(path);

            TorrentOpener.setFilterPathTorrent(target.toString());

            for (int i = 0; i < dms.length; i++) {

              try {
                dms[i].moveTorrentFile(target);

              }
              catch (Throwable e) {

                Logger.log(new LogAlert(dms[i], LogAlert.REPEATABLE,
                    "Download torrent move operation failed", e));
              }
            }
          }
        }
      }
    });
    itemFileMoveTorrent.setEnabled(fileMove);
   
    final MenuItem itemCheckFilesExist = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemCheckFilesExist, "MyTorrentsView.menu.checkfilesexist");
    itemCheckFilesExist.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager dm) {
        dm.filesExist( true );
      }
    });

    final MenuItem itemFileRescan = new MenuItem(menuFiles, SWT.CHECK);
    Messages.setLanguageText(itemFileRescan, "MyTorrentsView.menu.rescanfile");
    itemFileRescan.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager dm) {
        dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES,
            itemFileRescan.getSelection());
      }
    });
    itemFileRescan.setSelection(allScanSelected);
    itemFileRescan.setEnabled(fileRescan);

      // clear allocation
   
    MenuItem itemFileClearAlloc = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileClearAlloc, "MyTorrentsView.menu.clear_alloc_data");
    itemFileClearAlloc.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager dm) {
        dm.setDataAlreadyAllocated( false );
      }
    });
   
    itemFileClearAlloc.setEnabled(allStopped);
   
      // clear resume
   
    MenuItem itemFileClearResume = new MenuItem(menuFiles, SWT.PUSH);
    Messages.setLanguageText(itemFileClearResume, "MyTorrentsView.menu.clear_resume_data");
    itemFileClearResume.addListener(SWT.Selection, new DMTask(dms) {
      public void run(DownloadManager dm) {
        dm.getDownloadState().clearResumeData();
      }
    });
    itemFileClearResume.setEnabled(allStopped);

    // Advanced - > Rename
    final MenuItem itemRename = new MenuItem(menuAdvanced, SWT.DROP_DOWN);
    Messages.setLanguageText(itemRename, "MyTorrentsView.menu.rename");
    itemRename.setEnabled(hasSelection);
    itemRename.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        for (DownloadManager dm : dms) {
          AdvRenameWindow window = new AdvRenameWindow();
          window.open(dm);
        }
      }
    });

    // === advanced > export ===
    // =========================

    if (userMode > 0) {
      final MenuItem itemExport = new MenuItem(menuAdvanced, SWT.CASCADE);
      Messages.setLanguageText(itemExport, "MyTorrentsView.menu.exportmenu"); //$NON-NLS-1$
      Utils.setMenuItemImage(itemExport, "export");
      itemExport.setEnabled(hasSelection);

      final Menu menuExport = new Menu(composite.getShell(), SWT.DROP_DOWN);
      itemExport.setMenu(menuExport);

      // Advanced > Export > Export XML
      final MenuItem itemExportXML = new MenuItem(menuExport, SWT.PUSH);
      Messages.setLanguageText(itemExportXML, "MyTorrentsView.menu.export");
      itemExportXML.addListener(SWT.Selection, new DMTask(dms) {
        public void run(DownloadManager[] dms) {
          DownloadManager dm = dms[0]; // First only.
          if (dm != null) new ExportTorrentWizard(itemExportXML.getDisplay(), dm);
        }
      });

      // Advanced > Export > Export Torrent
      final MenuItem itemExportTorrent = new MenuItem(menuExport, SWT.PUSH);
      Messages.setLanguageText(itemExportTorrent, "MyTorrentsView.menu.exporttorrent");
      itemExportTorrent.addListener(SWT.Selection, new DMTask(dms) {
        public void run(DownloadManager[] dms) {
          // FileDialog for single download
          // DirectoryDialog for multiple.
          File[] destinations = new File[dms.length];
          if (dms.length == 1) {
            FileDialog fd = new FileDialog(composite.getShell(), SWT.SAVE);
            fd.setFileName(dms[0].getTorrentFileName());
            String path = fd.open();
            if (path == null) {return;}
            destinations[0] = new File(path);
          }
          else {
            DirectoryDialog dd = new DirectoryDialog(composite.getShell(), SWT.SAVE);
            String path = dd.open();
            if (path == null) {return;}
            for (int i=0; i<dms.length; i++) {
              destinations[i] = new File(path, new File(dms[i].getTorrentFileName()).getName());
            }
          }
         
          int i=0;
          try {
            for (; i<dms.length; i++) {
              File target = destinations[i];
              if (target.exists()) {
                MessageBox mb = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                mb.setText(MessageText.getString("exportTorrentWizard.process.outputfileexists.title"));
                mb.setMessage(MessageText.getString("exportTorrentWizard.process.outputfileexists.message") + "\n" + destinations[i].getName());

                int result = mb.open();
                if (result == SWT.NO) {return;}

                if (!target.delete()) {
                  throw (new Exception("Failed to delete file"));
                }
              } // end deal with clashing torrent

              // first copy the torrent - DON'T use "writeTorrent" as this amends the
              // "filename" field in the torrent
              TorrentUtils.copyToFile(dms[i].getDownloadState().getTorrent(), target);

              // now remove the non-standard entries
              TOTorrent dest = TOTorrentFactory.deserialiseFromBEncodedFile(target);
              dest.removeAdditionalProperties();
              dest.serialiseToBEncodedFile(target);
            } // end for
          } // end try
          catch (Throwable e) {
            Logger.log(new LogAlert(dms[i], LogAlert.UNREPEATABLE, "Torrent export failed", e));
          }
        } // end run()
      }); // end DMTask
     
      // Advanced > Export > WebSeed URL
      final MenuItem itemWebSeed = new MenuItem(menuExport, SWT.PUSH);
      Messages.setLanguageText(itemWebSeed, "MyTorrentsView.menu.exporthttpseeds");
      itemWebSeed.addListener(SWT.Selection, new DMTask(dms) {
        public void run(DownloadManager[] dms) {
          final String  NL = "\r\n";
          String  data = "";
         
          boolean http_enable = COConfigurationManager.getBooleanParameter( "HTTP.Data.Listen.Port.Enable" );
         
          String  port;
         
          if ( http_enable ){
           
            int  p = COConfigurationManager.getIntParameter( "HTTP.Data.Listen.Port" );
            int o = COConfigurationManager.getIntParameter( "HTTP.Data.Listen.Port.Override" );
             
            if ( o == 0 ){
             
              port = String.valueOf( p );
             
            }else{
             
              port = String.valueOf( o );
            }
          }else{

            data = "You need to enable the HTTP port or modify the URL(s) appropriately" + NL + NL;
           
            port = "<port>";
          }
           
          String  ip = COConfigurationManager.getStringParameter( "Tracker IP", "" );
         
          if ( ip.length() == 0 ){
           
            data += "You might need to modify the host address in the URL(s)" + NL + NL;
           
            try{
           
              InetAddress ia = AzureusCoreFactory.getSingleton().getInstanceManager().getMyInstance().getExternalAddress();
           
              if ( ia != null ){
               
                ip = IPToHostNameResolver.syncResolve( ia.getHostAddress(), 10000 );
              }
            }catch( Throwable e ){
             
            }
           
            if ( ip.length() == 0 ){
             
              ip = "<host>";
            }
          }
         
          String  base = "http://" + UrlUtils.convertIPV6Host(ip) + ":" + port + "/";
         
          for (int i=0;i<dms.length;i++){
           
            DownloadManager dm = dms[i];
           
            if ( dm == null ){
              continue;
            }
           
            TOTorrent torrent = dm.getTorrent();
           
            if ( torrent == null ){
             
              continue;
            }
           
            data += base + "webseed" + NL;
           
            try{
              data += base + "files/" + URLEncoder.encode( new String( torrent.getHash(), "ISO-8859-1"), "ISO-8859-1" ) + "/" + NL + NL;
             
            }catch( Throwable e ){
             
            }
          }
         
          if ( data.length() > 0){
            ClipboardCopy.copyToClipBoard( data );
          }
        }
      });
    } // export menu

   
    // === advanced > options ===
    // ===========================

    if (userMode > 0) {
      final MenuItem itemExportXML = new MenuItem(menuAdvanced, SWT.PUSH);
      Messages.setLanguageText(itemExportXML, "MainWindow.menu.view.configuration");
      itemExportXML.addListener(SWT.Selection, new DMTask(dms) {
        public void run(DownloadManager[] dms) {
          UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
         
          uiFunctions.openView(UIFunctions.VIEW_DM_MULTI_OPTIONS, dms);
        }
      });
    }
    // === advanced > peer sources ===
    // ===============================

    if (userMode > 0) {
      final MenuItem itemPeerSource = new MenuItem(menuAdvanced, SWT.CASCADE);
      Messages.setLanguageText(itemPeerSource, "MyTorrentsView.menu.peersource"); //$NON-NLS-1$

      final Menu menuPeerSource = new Menu(composite.getShell(), SWT.DROP_DOWN);
      itemPeerSource.setMenu(menuPeerSource);

      for (int i = 0; i < PEPeerSource.PS_SOURCES.length; i++) {

        final String p = PEPeerSource.PS_SOURCES[i];
        String msg_text = "ConfigView.section.connection.peersource." + p;
        final MenuItem itemPS = new MenuItem(menuPeerSource, SWT.CHECK);
        itemPS.setData("peerSource", p);
        Messages.setLanguageText(itemPS, msg_text); //$NON-NLS-1$
        itemPS.addListener(SWT.Selection, new DMTask(dms) {
          public void run(DownloadManager dm) {
            dm.getDownloadState().setPeerSourceEnabled(p, itemPS.getSelection());
          }
        });
        itemPS.setSelection(true);

        boolean bChecked = hasSelection;
        boolean bEnabled = !hasSelection;
        if (bChecked) {
          bEnabled = true;

          // turn on check if just one dm is not enabled
          for (int j = 0; j < dms.length; j++) {
            DownloadManager dm = (DownloadManager) dms[j];

            if (!dm.getDownloadState().isPeerSourceEnabled(p)) {
              bChecked = false;
            }
            if (!dm.getDownloadState().isPeerSourcePermitted(p)) {
              bEnabled = false;
            }
          }
        }

        itemPS.setSelection(bChecked);
        itemPS.setEnabled(bEnabled);
      }
    }

    // === advanced > networks ===
    // ===========================

    if (userMode > 1) {
      final MenuItem itemNetworks = new MenuItem(menuAdvanced, SWT.CASCADE);
      Messages.setLanguageText(itemNetworks, "MyTorrentsView.menu.networks"); //$NON-NLS-1$

      final Menu menuNetworks = new Menu(composite.getShell(), SWT.DROP_DOWN);
      itemNetworks.setMenu(menuNetworks);

      for (int i = 0; i < AENetworkClassifier.AT_NETWORKS.length; i++) {
        final String nn = AENetworkClassifier.AT_NETWORKS[i];
        String msg_text = "ConfigView.section.connection.networks." + nn;
        final MenuItem itemNetwork = new MenuItem(menuNetworks, SWT.CHECK);
        itemNetwork.setData("network", nn);
        Messages.setLanguageText(itemNetwork, msg_text); //$NON-NLS-1$
        itemNetwork.addListener(SWT.Selection, new DMTask(dms) {
          public void run(DownloadManager dm) {
            dm.getDownloadState().setNetworkEnabled(nn, itemNetwork.getSelection());
          }
        });
        boolean bChecked = hasSelection;
        if (bChecked) {
          // turn on check if just one dm is not enabled
          for (int j = 0; j < dms.length; j++) {
            DownloadManager dm = (DownloadManager) dms[j];

            if (!dm.getDownloadState().isNetworkEnabled(nn)) {
              bChecked = false;
              break;
            }
          }
        }

        itemNetwork.setSelection(bChecked);
      }
    }

    // superseed
    if (userMode > 1 && isSeedingView) {

      final MenuItem itemSuperSeed = new MenuItem(menuAdvanced, SWT.CHECK);

      Messages.setLanguageText(itemSuperSeed, "ManagerItem.superseeding");

      boolean enabled = canSetSuperSeed && (superSeedAllNo || superSeedAllYes);

      itemSuperSeed.setEnabled(enabled);

      final boolean selected = superSeedAllNo;

      if (enabled) {

        itemSuperSeed.setSelection(selected);

        itemSuperSeed.addListener(SWT.Selection, new DMTask(dms) {
          public void run(DownloadManager dm) {
            PEPeerManager pm = dm.getPeerManager();

            if (pm != null) {

              if (pm.isSuperSeedMode() == selected && pm.canToggleSuperSeedMode()) {

                pm.setSuperSeedMode(!selected);
              }
            }
          }
        });
      }
View Full Code Here

   * @see org.gudy.azureus2.plugins.ui.tables.TableCellRefreshListener#refresh(org.gudy.azureus2.plugins.ui.tables.TableCell)
   */
  public void refresh(TableCell cell) {
    PEPeer peer = (PEPeer)cell.getDataSource();
    if (peer == null) {cell.setText(""); return;}
    PEPeerManager manager = peer.getManager();
    if (manager == null) {cell.setText(""); return;}
    cell.setText(manager.getDisplayName());
  }
View Full Code Here

      topLabel.setText("");
     
      return;
    }

    PEPeerManager pm = dlm.getPeerManager();

    DiskManager dm = dlm.getDiskManager();

    if (pm == null || dm == null) {
      GC gc = new GC(pieceInfoCanvas);
      gc.fillRectangle(bounds);
      gc.dispose();
      topLabel.setText("");

      return;
    }

    int iNumCols = bounds.width / BLOCK_SIZE;
    int iNeededHeight = (((dm.getNbPieces() - 1) / iNumCols) + 1) * BLOCK_SIZE;

    if (img != null && !img.isDisposed()) {
      Rectangle imgBounds = img.getBounds();
      if (imgBounds.width != bounds.width || imgBounds.height != iNeededHeight) {
        oldBlockInfo = null;
        img.dispose();
        img = null;
      }
    }

    DiskManagerPiece[] dm_pieces = dm.getPieces();

    PEPiece[] currentDLPieces = pm.getPieces();
    byte[] uploadingPieces = new byte[dm_pieces.length];

    // find upload pieces
    Iterator<PEPeer> peer_it = pm.getPeers().iterator();
    while( peer_it.hasNext()){
      PEPeer peer = peer_it.next();
      int[] peerRequestedPieces = peer.getIncomingRequestedPieceNumbers();
      if (peerRequestedPieces != null && peerRequestedPieces.length > 0) {
        int pieceNum = peerRequestedPieces[0];
        if(uploadingPieces[pieceNum] < 2)
          uploadingPieces[pieceNum] = 2;
        for (int j = 1; j < peerRequestedPieces.length; j++) {
          pieceNum = peerRequestedPieces[j];
          if(uploadingPieces[pieceNum] < 1)
            uploadingPieces[pieceNum] = 1;
        }
      }

    }

    if (sc.getMinHeight() != iNeededHeight) {
      sc.setMinHeight(iNeededHeight);
      sc.layout(true, true);
      bounds = pieceInfoCanvas.getClientArea();
    }

    int[] availability = pm.getAvailability();

    int minAvailability = Integer.MAX_VALUE;
    int minAvailability2 = Integer.MAX_VALUE;
    if (availability != null && availability.length > 0) {
      for (int i = 0; i < availability.length; i++) {
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.peer.PEPeerManager$StatsReceiver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.