protected String[] getAuthenticationDialog(final String realm, final String tracker) {
    final Display display = SWTThread.getInstance().getDisplay();

    if (display.isDisposed()) {

      return (null);
    }

    final AESemaphore sem = new AESemaphore("SWTAuth");

    final authDialog[] dialog = new authDialog[1];

    TOTorrent torrent = TorrentUtils.getTLSTorrent();

    final String torrent_name;

    if (torrent == null) {

      torrent_name = null;

    } else {

      torrent_name = TorrentUtils.getLocalisedName(torrent);
    }

    try {
      display.asyncExec(
          new AERunnable() {
            public void runSupport() {
              dialog[0] = new authDialog(sem, display, realm, tracker, torrent_name);
            }
          });
    } catch (Throwable e) {

      Debug.printStackTrace(e);

      return (null);
    }
    sem.reserve();

    String user = dialog[0].getUsername();
    String pw = dialog[0].getPassword();
    String persist = dialog[0].savePassword() ? "true" : "false";

    if (user == null) {

      return (null);
    }

    return (new String[] {user, pw == null ? "" : pw, persist});
  }
Example #2
0
  protected AssociationChecker(final PlatformManager _platform) {
    platform = _platform;

    display = SWTThread.getInstance().getDisplay();

    if (display.isDisposed()) {

      return;
    }

    Utils.execSWTThread(
        new AERunnable() {
          public void runSupport() {
            check();
          }
        });
  }
Example #3
0
    public void refresh(TableCell cell, boolean sortOnly) {
      final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
      int percentDone = 0;
      if (fileInfo != null && fileInfo.getLength() != 0)
        percentDone = (int) ((1000 * fileInfo.getDownloaded()) / fileInfo.getLength());
      cell.setSortValue(percentDone);
      if (sortOnly) {
        dispose(cell);
        return;
      }

      // Compute bounds ...
      int newWidth = cell.getWidth();
      if (newWidth <= 0) return;
      final int newHeight = cell.getHeight();
      final int x1 = newWidth - borderWidth - 1;
      final int y1 = newHeight - borderWidth - 1;

      if (x1 < 10 || y1 < 3) return;

      final DiskManager manager = fileInfo.getDiskManager();
      // we want to run through the image part once one the transition from with a disk manager
      // (running)
      // to without a disk manager (stopped) in order to clear the pieces view
      boolean running = manager != null;
      boolean hasGraphic = false;
      Graphic graphic = cell.getGraphic();
      if (graphic instanceof UISWTGraphic) {
        Image img = ((UISWTGraphic) graphic).getImage();
        hasGraphic = img != null && !img.isDisposed();
      }
      final boolean bImageBufferValid =
          (lastPercentDone == percentDone)
              && cell.isValid()
              && bNoRed
              && running == was_running
              && hasGraphic;

      if (bImageBufferValid) return;

      was_running = running;
      lastPercentDone = percentDone;
      Image piecesImage = null;

      if (graphic instanceof UISWTGraphic) piecesImage = ((UISWTGraphic) graphic).getImage();
      if (piecesImage != null && !piecesImage.isDisposed()) piecesImage.dispose();

      if (!running) {
        cell.setGraphic(null);
        return;
      }

      piecesImage = new Image(SWTThread.getInstance().getDisplay(), newWidth, newHeight);
      final GC gcImage = new GC(piecesImage);

      // dm may be null if this is a skeleton file view
      DownloadManager download_manager = fileInfo.getDownloadManager();
      PEPeerManager peer_manager =
          download_manager == null ? null : download_manager.getPeerManager();
      PEPiece[] pe_pieces = peer_manager == null ? null : peer_manager.getPieces();
      final long now = SystemTime.getCurrentTime();

      if (fileInfo != null && manager != null) {
        if (percentDone == 1000) {
          gcImage.setForeground(Colors.blues[Colors.BLUES_DARKEST]);
          gcImage.setBackground(Colors.blues[Colors.BLUES_DARKEST]);
          gcImage.fillRectangle(1, 1, newWidth - 2, newHeight - 2);
        } else {
          final int firstPiece = fileInfo.getFirstPieceNumber();
          final int nbPieces = fileInfo.getNbPieces();
          final DiskManagerPiece[] dm_pieces = manager.getPieces();
          bNoRed = true;
          for (int i = 0; i < newWidth; i++) {
            final int a0 = (i * nbPieces) / newWidth;
            int a1 = ((i + 1) * nbPieces) / newWidth;
            if (a1 == a0) a1++;
            if (a1 > nbPieces && nbPieces != 0) a1 = nbPieces;
            int nbAvailable = 0;
            boolean written = false;
            boolean partially_written = false;
            if (firstPiece >= 0)
              for (int j = a0; j < a1; j++) {
                final int this_index = j + firstPiece;
                final DiskManagerPiece dm_piece = dm_pieces[this_index];
                if (dm_piece.isDone()) nbAvailable++;
                if (written) continue;
                if (pe_pieces != null) {
                  PEPiece pe_piece = pe_pieces[this_index];
                  if (pe_piece != null)
                    written = written || (pe_piece.getLastDownloadTime(now) + 500) > last_draw_time;
                }
                if ((!written) && (!partially_written)) {
                  final boolean[] blocks = dm_piece.getWritten();
                  if (blocks != null)
                    for (int k = 0; k < blocks.length; k++)
                      if (blocks[k]) {
                        partially_written = true;
                        break;
                      }
                }
              } // for j
            else nbAvailable = 1;
            gcImage.setBackground(
                written
                    ? Colors.red
                    : partially_written
                        ? Colors.grey
                        : Colors.blues[(nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0)]);
            gcImage.fillRectangle(i, 1, 1, newHeight - 2);
            if (written) bNoRed = false;
          }
          gcImage.setForeground(Colors.grey);
        }
      } else gcImage.setForeground(Colors.grey);

      if (manager != null) gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1);
      gcImage.dispose();

      last_draw_time = now;

      if (cell instanceof TableCellSWT) ((TableCellSWT) cell).setGraphic(piecesImage);
      else cell.setGraphic(new UISWTGraphicImpl(piecesImage));
    }
  protected String[] getAuthenticationDialog(final String realm, final String location) {
    final Display display = SWTThread.getInstance().getDisplay();

    if (display.isDisposed()) {

      return (null);
    }

    final AESemaphore sem = new AESemaphore("SWTAuth");

    final authDialog[] dialog = new authDialog[1];

    TOTorrent torrent = TorrentUtils.getTLSTorrent();

    final boolean is_tracker;
    final String details;

    if (torrent == null) {

      is_tracker = false;

      details = TorrentUtils.getTLSDescription();

    } else {

      details = TorrentUtils.getLocalisedName(torrent);
      is_tracker = true;
    }

    try {
      if (display.getThread() == Thread.currentThread()) {

        dialog[0] = new authDialog(sem, display, realm, is_tracker, location, details);

        while (!(display.isDisposed() || sem.isReleasedForever())) {

          if (!display.readAndDispatch()) {

            display.sleep();
          }
        }

        if (display.isDisposed()) {

          return (null);
        }
      } else {

        display.asyncExec(
            new AERunnable() {
              public void runSupport() {
                dialog[0] = new authDialog(sem, display, realm, is_tracker, location, details);
              }
            });
      }
    } catch (Throwable e) {

      Debug.printStackTrace(e);

      return (null);
    }

    sem.reserve();

    String user = dialog[0].getUsername();
    String pw = dialog[0].getPassword();
    String persist = dialog[0].savePassword() ? "true" : "false";

    if (user == null) {

      return (null);
    }

    return (new String[] {user, pw == null ? "" : pw, persist});
  }