Example #1
0
  private void update() {
    int state = downloader.getDownloadState();
    int percentDone = downloader.getPercentDone();

    IProgressReport pReport = pReporter.getProgressReport();
    switch (state) {
      case TorrentDownloader.STATE_CANCELLED:
        if (false == pReport.isCanceled()) {
          pReporter.cancel();
        }
        return;
      case TorrentDownloader.STATE_DOWNLOADING:
        pReporter.setPercentage(percentDone, downloader.getStatus());
        break;
      case TorrentDownloader.STATE_ERROR:
        /*
         * If the user has canceled then a call  to downloader.cancel() has already been made
         * so don't bother prompting for the user to retry
         */
        if (true == pReport.isCanceled()) {
          return;
        }

        pReporter.setErrorMessage(
            MessageText.getString("fileDownloadWindow.state_error") + downloader.getError());
        return;
      case TorrentDownloader.STATE_FINISHED:
        pReporter.setDone();

        /*
         * If the listener is present then it handle finishing up; otherwise open the torrent that
         * was just downloaded
         */
        if (listener == null) {
          TorrentOpener.openTorrent(downloader.getFile().getAbsolutePath());
        }
        return;
      default:
    }
  }
Example #2
0
  /** Initializes the reporter and show the download dialog if it is not suppressed */
  private void setupAndShowDialog() {
    if (null != pReporter) {
      pReporter.setName(
          MessageText.getString("fileDownloadWindow.state_downloading")
              + ": "
              + getFileName(decoded_url));
      pReporter.appendDetailMessage(
          MessageText.getString("fileDownloadWindow.downloading") + getShortURL(decoded_url));
      pReporter.setTitle(MessageText.getString("fileDownloadWindow.title"));
      pReporter.setIndeterminate(true);
      pReporter.setCancelAllowed(true);
      pReporter.setRetryAllowed(true);

      /*
       * Listen to and respond to events from the reporters
       */
      pReporter.addListener(
          new IProgressReporterListener() {

            public int report(IProgressReport pReport) {

              switch (pReport.getReportType()) {
                case REPORT_TYPE_CANCEL:
                  if (null != downloader) {
                    downloader.cancel();

                    // KN: correct logger id?
                    Logger.log(
                        new LogEvent(
                            LogIDs.LOGGER,
                            MessageText.getString(
                                "FileDownload.canceled", new String[] {getShortURL(decoded_url)})));
                  }
                  break;
                case REPORT_TYPE_DONE:
                  return RETVAL_OK_TO_DISPOSE;
                case REPORT_TYPE_RETRY:
                  if (true == pReport.isRetryAllowed()) {
                    downloader.cancel();
                    downloader =
                        TorrentDownloaderFactory.create(
                            FileDownloadWindow.this,
                            original_url,
                            referrer,
                            request_properties,
                            dirName);
                    downloader.setIgnoreReponseCode(true);
                    downloader.start();
                  }
                  break;
                default:
                  break;
              }

              return RETVAL_OK;
            }
          });

      ProgressReporterWindow.open(pReporter, ProgressReporterWindow.AUTO_CLOSE);
    }
  }