use of com.biglybt.core.download.DownloadManagerState in project BiglyBT by BiglySoftware.
the class DiskManagerImpl method storeFileDownloaded.
protected static void storeFileDownloaded(DownloadManager download_manager, DiskManagerFileInfo[] files, boolean persist) {
DownloadManagerState state = download_manager.getDownloadState();
Map details = new HashMap();
List downloaded = new ArrayList();
details.put("downloaded", downloaded);
for (int i = 0; i < files.length; i++) {
downloaded.add(new Long(files[i].getDownloaded()));
}
state.setMapAttribute(DownloadManagerState.AT_FILE_DOWNLOADED, details);
if (persist) {
state.save();
}
}
use of com.biglybt.core.download.DownloadManagerState in project BiglyBT by BiglySoftware.
the class DiskManagerImpl method getStorageType.
// Used by DownloadManagerImpl too.
public static String getStorageType(DownloadManager download_manager, int fileIndex) {
DownloadManagerState state = download_manager.getDownloadState();
String type = state.getListAttribute(DownloadManagerState.AT_FILE_STORE_TYPES, fileIndex);
if (type != null) {
return (type);
}
return (getStorageTypes(download_manager)[fileIndex]);
}
use of com.biglybt.core.download.DownloadManagerState in project BiglyBT by BiglySoftware.
the class DiskManagerUtil method loadFileDownloaded.
protected static void loadFileDownloaded(DownloadManager download_manager, DiskManagerFileInfoHelper[] files) {
DownloadManagerState state = download_manager.getDownloadState();
Map details = state.getMapAttribute(DownloadManagerState.AT_FILE_DOWNLOADED);
if (details == null) {
return;
}
List downloaded = (List) details.get("downloaded");
if (downloaded == null) {
return;
}
try {
for (int i = 0; i < files.length; i++) {
files[i].setDownloaded(((Long) downloaded.get(i)).longValue());
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
use of com.biglybt.core.download.DownloadManagerState in project BiglyBT by BiglySoftware.
the class DefaultRankCalculator method attributeEventOccurred.
@Override
public void attributeEventOccurred(DownloadManager download, String attribute, int event_type) {
DownloadManagerState dm_state = core_dm.getDownloadState();
dlSpecificMinShareRatio = dm_state.getIntParameter(DownloadManagerState.PARAM_MIN_SHARE_RATIO);
dlSpecificMaxShareRatio = dm_state.getIntParameter(DownloadManagerState.PARAM_MAX_SHARE_RATIO);
dlLastActiveTime = dm_state.getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_LAST_ACTIVE_TIME);
if (dlLastActiveTime <= 0) {
dlLastActiveTime = dm_state.getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME);
}
}
use of com.biglybt.core.download.DownloadManagerState in project BiglyBT by BiglySoftware.
the class TorrentMenuFancy method buildTorrentCustomMenu_Content.
protected void buildTorrentCustomMenu_Content(final Composite detailArea, final DownloadManager[] dms) {
// Run Data File
if (hasSelection) {
createRow(detailArea, "MyTorrentsView.menu.open", "run", new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
TorrentUtil.runDataSources(dms);
}
});
}
// Explore (or open containing folder)
if (hasSelection) {
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
createRow(detailArea, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"), null, new ListenerDMTask(dms, false) {
@Override
public void run(DownloadManager dm) {
ManagerUtils.open(dm, use_open_containing_folder);
}
});
}
if (hasSelection) {
createMenuRow(detailArea, "MyTorrentsView.menu.browse", null, new FancyMenuRowInfoListener() {
@Override
public void buildMenu(Menu menuBrowse) {
final MenuItem itemBrowsePublic = new MenuItem(menuBrowse, SWT.PUSH);
itemBrowsePublic.setText(MessageText.getString("label.public") + "...");
itemBrowsePublic.addListener(SWT.Selection, new ListenerDMTask(dms, false) {
@Override
public void run(DownloadManager dm) {
ManagerUtils.browse(dm, false, true);
}
});
final MenuItem itemBrowseAnon = new MenuItem(menuBrowse, SWT.PUSH);
itemBrowseAnon.setText(MessageText.getString("label.anon") + "...");
itemBrowseAnon.addListener(SWT.Selection, new ListenerDMTask(dms, false) {
@Override
public void run(DownloadManager dm) {
ManagerUtils.browse(dm, true, true);
}
});
new MenuItem(menuBrowse, SWT.SEPARATOR);
final MenuItem itemBrowseURL = new MenuItem(menuBrowse, SWT.PUSH);
Messages.setLanguageText(itemBrowseURL, "label.copy.url.to.clip");
itemBrowseURL.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
String url = ManagerUtils.browse(dms[0], true, false);
if (url != null) {
ClipboardCopy.copyToClipBoard(url);
}
}
});
}
});
itemBrowseURL.setEnabled(dms.length == 1);
new MenuItem(menuBrowse, SWT.SEPARATOR);
final MenuItem itemBrowseDir = new MenuItem(menuBrowse, SWT.CHECK);
Messages.setLanguageText(itemBrowseDir, "library.launch.web.in.browser.dir.list");
itemBrowseDir.setSelection(COConfigurationManager.getBooleanParameter("Library.LaunchWebsiteInBrowserDirList"));
itemBrowseDir.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
COConfigurationManager.setParameter("Library.LaunchWebsiteInBrowserDirList", itemBrowseDir.getSelection());
}
});
}
});
}
// set thumbnail
createRow(detailArea, "MyTorrentsView.menu.torrent.set.thumb", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
FileDialog fDialog = new FileDialog(parentShell, SWT.OPEN | SWT.MULTI);
fDialog.setText(MessageText.getString("MainWindow.dialog.choose.thumb"));
String path = fDialog.open();
if (path == null)
return;
File file = new File(path);
try {
byte[] thumbnail = FileUtil.readFileAsByteArray(file);
String name = file.getName();
int pos = name.lastIndexOf(".");
String ext;
if (pos != -1) {
ext = name.substring(pos + 1);
} else {
ext = "";
}
String type = HTTPUtils.guessContentTypeFromFileType(ext);
for (DownloadManager dm : dms) {
try {
TOTorrent torrent = dm.getTorrent();
PlatformTorrentUtils.setContentThumbnail(torrent, thumbnail, type);
} catch (Throwable e) {
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
boolean fileMove = true;
boolean locateFiles = false;
boolean exportFiles = true;
boolean canSetMOC = dms.length > 0;
boolean canClearMOC = false;
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
if (!dm.canMoveDataFiles()) {
fileMove = false;
}
if (!dm.canExportDownload()) {
exportFiles = false;
}
if (!dm.isDownloadComplete(false)) {
locateFiles = true;
}
boolean incomplete = !dm.isDownloadComplete(true);
DownloadManagerState dm_state = dm.getDownloadState();
String moc_dir = dm_state.getAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR);
canSetMOC &= incomplete;
canClearMOC |= (moc_dir != null && moc_dir.length() > 0);
}
if (fileMove) {
createRow(detailArea, "MyTorrentsView.menu.movedata", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
TorrentUtil.moveDataFiles(parentShell, dms);
}
});
}
if (canSetMOC || canClearMOC) {
boolean f_canSetMOC = canSetMOC;
boolean f_canClearMOC = canClearMOC;
createMenuRow(detailArea, "label.move.on.comp", null, new FancyMenuRowInfoListener() {
@Override
public void buildMenu(Menu moc_menu) {
MenuItem clear_item = new MenuItem(moc_menu, SWT.PUSH);
Messages.setLanguageText(clear_item, "Button.clear");
clear_item.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
TorrentUtil.clearMOC(dms);
}
});
clear_item.setEnabled(f_canClearMOC);
MenuItem set_item = new MenuItem(moc_menu, SWT.PUSH);
Messages.setLanguageText(set_item, "label.set");
set_item.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
TorrentUtil.setMOC(parentShell, dms);
}
});
set_item.setEnabled(f_canSetMOC);
}
});
}
if (exportFiles) {
createRow(detailArea, "MyTorrentsView.menu.exportdownload", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
TorrentUtil.exportDownloads(parentShell, dms);
}
});
}
createRow(detailArea, "MyTorrentsView.menu.checkfilesexist", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.filesExist(true);
}
});
if (locateFiles) {
createRow(detailArea, "MyTorrentsView.menu.locatefiles", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
ManagerUtils.locateFiles(dms, parentShell);
}
});
}
if (dms.length == 1 && ManagerUtils.canFindMoreLikeThis()) {
createRow(detailArea, "MyTorrentsView.menu.findmorelikethis", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
ManagerUtils.findMoreLikeThis(dms[0], parentShell);
}
});
}
createRow(detailArea, "MyTorrentsView.menu.thisColumn.toClipboard", null, new Listener() {
@Override
public void handleEvent(Event event) {
String sToClipboard = "";
if (column == null) {
return;
}
String columnName = column.getName();
if (columnName == null) {
return;
}
TableRowCore[] rows = tv.getSelectedRows();
for (TableRowCore row : rows) {
if (row != rows[0]) {
sToClipboard += "\n";
}
TableCellCore cell = row.getTableCellCore(columnName);
if (cell != null) {
sToClipboard += cell.getClipboardText();
}
}
if (sToClipboard.length() == 0) {
return;
}
new Clipboard(Display.getDefault()).setContents(new Object[] { sToClipboard }, new Transfer[] { TextTransfer.getInstance() });
}
});
}
Aggregations