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: } }
private void init() { if (COConfigurationManager.getBooleanParameter("Save Torrent Files")) { try { dirName = COConfigurationManager.getDirectoryParameter("General_sDefaultTorrent_Directory"); } catch (Exception egnore) { } } if (dirName == null) { DirectoryDialog dd = new DirectoryDialog(parent, SWT.NULL); dd.setText(MessageText.getString("fileDownloadWindow.saveTorrentIn")); dirName = dd.open(); } if (dirName == null) return; pReporter = ProgressReportingManager.getInstance().addReporter(); setupAndShowDialog(); downloader = TorrentDownloaderFactory.create(this, original_url, referrer, request_properties, dirName); downloader.setIgnoreReponseCode(true); downloader.start(); }