use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class ColumnProgressETA method refresh.
@Override
public void refresh(TableCell cell) {
Object ds = cell.getDataSource();
// needs to be long so we can shift it for sortVal
long percentDone = getPercentDone(ds);
long sortValue = 0;
if (ds instanceof DownloadManager) {
DownloadManager dm = (DownloadManager) cell.getDataSource();
// close enough to unique with abs..
int hashCode = Math.abs(DisplayFormatters.formatDownloadStatus(dm).hashCode());
long completedTime = dm.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME);
if (completedTime <= 0 || !dm.isDownloadComplete(false)) {
sortValue = (percentDone << 31) + hashCode;
} else {
sortValue = ((completedTime / 1000) << 31) + hashCode;
}
} else if (ds instanceof DiskManagerFileInfo) {
DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
int st = fileInfo.getStorageType();
if ((st == DiskManagerFileInfo.ST_COMPACT || st == DiskManagerFileInfo.ST_REORDER_COMPACT) && fileInfo.isSkipped()) {
sortValue = 1;
} else if (fileInfo.isSkipped()) {
sortValue = 2;
} else if (fileInfo.getPriority() > 0) {
int pri = fileInfo.getPriority();
sortValue = 4;
if (pri > 1) {
sortValue += pri;
}
} else {
sortValue = 3;
}
sortValue = (fileInfo.getDownloadManager().getState() * 10000) + percentDone + sortValue;
}
long eta = showETA ? getETA(cell) : 0;
long speed = showSpeed ? getSpeed(ds) : 0;
// System.out.println("REFRESH " + sortValue + ";" + ds);
Comparable old = cell.getSortValue();
boolean sortChanged = cell.setSortValue(sortValue);
if (sortChanged && old != null && !(old instanceof String)) {
UIFunctionsManagerSWT.getUIFunctionsSWT().refreshIconBar();
}
long lastETA = 0;
long lastSpeed = 0;
TableRow row = cell.getTableRow();
if (row != null) {
if (showETA) {
Object data = row.getData("lastETA");
if (data instanceof Number) {
lastETA = ((Number) data).longValue();
}
row.setData("lastETA", new Long(eta));
}
if (showSpeed) {
Object data = row.getData("lastSpeed");
if (data instanceof Number) {
lastSpeed = ((Number) data).longValue();
}
row.setData("lastSpeed", new Long(speed));
}
}
if (!sortChanged && (lastETA != eta || lastSpeed != speed)) {
cell.invalidate();
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class ColumnThumbAndName method refresh.
@Override
public void refresh(TableCell cell, boolean sortOnlyRefresh) {
String name = null;
Object ds = cell.getDataSource();
if (ds instanceof DiskManagerFileInfo) {
DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
if (fileInfo.isSkipped() && (fileInfo.getStorageType() == DiskManagerFileInfo.ST_COMPACT || fileInfo.getStorageType() == DiskManagerFileInfo.ST_REORDER_COMPACT)) {
TableRowCore row = (TableRowCore) cell.getTableRow();
if (row != null) {
row.getParentRowCore().removeSubRow(ds);
}
}
return;
}
DownloadManager dm = (DownloadManager) ds;
if (dm != null) {
name = dm.getDisplayName();
}
if (name == null) {
name = "";
}
cell.setSortValue(name);
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method updateSelectedContent.
public void updateSelectedContent() {
TableView tv = tvFiles != null ? tvFiles : tvDevices;
Object[] dataSources = tv.getSelectedDataSources(true);
List<SelectedContent> listSelected = new ArrayList<>(dataSources.length);
for (Object ds : dataSources) {
if (ds instanceof DiskManagerFileInfo) {
DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
listSelected.add(new SelectedContent(fileInfo.getDownloadManager(), fileInfo.getIndex()));
}
}
SelectedContent[] sc = listSelected.toArray(new SelectedContent[0]);
SelectedContentManager.changeCurrentlySelectedContent(tv.getTableID(), null, tv);
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class EnhancedDownloadManager method setProgressiveMode.
protected boolean setProgressiveMode(boolean active, boolean switching_progressive_downloads) {
TOTorrent torrent = download_manager.getTorrent();
DiskManagerFileInfo primaryFile = download_manager.getDownloadState().getPrimaryFile();
if (torrent == null || primaryFile == null) {
return (false);
}
EnhancedDownloadManagerFile enhanced_file = enhanced_files[primaryFile.getIndex()];
synchronized (this) {
if (progressive_active == active) {
return (true);
}
if (active && !supportsProgressiveMode()) {
Debug.out("Attempt to set progress mode on non-progressible content - " + getName());
return (false);
}
log("Progressive mode changed to " + active);
final GlobalManager gm = download_manager.getGlobalManager();
if (active) {
if (dmListener == null) {
dmListener = new DownloadManagerAdapter() {
@Override
public void downloadComplete(DownloadManager manager) {
enhancer.resume();
}
};
}
download_manager.addListener(dmListener);
// Check existing downloading torrents and turn off any
// existing progressive/downloading
Object[] dms = gm.getDownloadManagers().toArray();
for (int i = 0; i < dms.length; i++) {
DownloadManager dmCheck = (DownloadManager) dms[i];
if (dmCheck.equals(download_manager)) {
continue;
}
if (!dmCheck.isDownloadComplete(false)) {
int state = dmCheck.getState();
if (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_QUEUED) {
enhancer.pause(dmCheck);
}
EnhancedDownloadManager edmCheck = enhancer.getEnhancedDownload(dmCheck);
if (edmCheck != null && edmCheck.getProgressiveMode()) {
edmCheck.setProgressiveMode(false, true);
}
}
}
if (download_manager.isPaused()) {
enhancer.resume(download_manager);
}
// and putting at top
if (download_manager.getState() == DownloadManager.STATE_STOPPED) {
download_manager.setStateWaiting();
}
if (download_manager.getPosition() != 1) {
download_manager.getGlobalManager().moveTo(download_manager, 1);
}
} else {
download_manager.removeListener(dmListener);
if (!switching_progressive_downloads) {
enhancer.resume();
}
}
progressive_active = active;
if (progressive_active) {
enhancer.progressiveActivated();
}
if (current_piece_pickler != null) {
if (progressive_active) {
buffer_provider.activate(current_piece_pickler);
progressive_stats.update(0);
} else {
buffer_provider.deactivate(current_piece_pickler);
progressive_stats = createProgressiveStats(download_manager, enhanced_file);
}
} else {
progressive_stats = createProgressiveStats(download_manager, enhanced_file);
}
if (!switching_progressive_downloads) {
if (active) {
RealTimeInfo.setProgressiveActive(progressive_stats.getStreamBytesPerSecondMax());
} else {
RealTimeInfo.setProgressiveInactive();
}
}
}
return (true);
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class PluginCoreUtils method convert.
public static Object convert(Object datasource, boolean toCore) {
if (datasource instanceof Object[]) {
Object[] array = (Object[]) datasource;
Object[] newArray = new Object[array.length];
for (int i = 0; i < array.length; i++) {
Object o = array[i];
newArray[i] = convert(o, toCore);
}
return newArray;
}
try {
if (toCore) {
if (datasource instanceof com.biglybt.core.download.DownloadManager) {
return datasource;
}
if (datasource instanceof DownloadImpl) {
return ((DownloadImpl) datasource).getDownload();
}
if (datasource instanceof com.biglybt.core.disk.DiskManager) {
return datasource;
}
if (datasource instanceof DiskManagerImpl) {
return ((DiskManagerImpl) datasource).getDiskmanager();
}
if (datasource instanceof PEPeerManager) {
return datasource;
}
if (datasource instanceof PeerManagerImpl) {
return ((PeerManagerImpl) datasource).getDelegate();
}
if (datasource instanceof PEPeer) {
return datasource;
}
if (datasource instanceof PeerImpl) {
return ((PeerImpl) datasource).getPEPeer();
}
if (datasource instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
return datasource;
}
if (datasource instanceof com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) {
return ((com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) datasource).getCore();
}
if (datasource instanceof TRHostTorrent) {
return datasource;
}
if (datasource instanceof TrackerTorrentImpl) {
((TrackerTorrentImpl) datasource).getHostTorrent();
}
} else {
// to PI
if (datasource instanceof com.biglybt.core.download.DownloadManager) {
return wrap((com.biglybt.core.download.DownloadManager) datasource);
}
if (datasource instanceof DownloadImpl) {
return datasource;
}
if (datasource instanceof com.biglybt.core.disk.DiskManager) {
return wrap((com.biglybt.core.disk.DiskManager) datasource);
}
if (datasource instanceof DiskManagerImpl) {
return datasource;
}
if (datasource instanceof PEPeerManager) {
return wrap((PEPeerManager) datasource);
}
if (datasource instanceof PeerManagerImpl) {
return datasource;
}
if (datasource instanceof PEPeer) {
return PeerManagerImpl.getPeerForPEPeer((PEPeer) datasource);
}
if (datasource instanceof Peer) {
return datasource;
}
if (datasource instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
DiskManagerFileInfo fileInfo = (com.biglybt.core.disk.DiskManagerFileInfo) datasource;
if (fileInfo != null) {
try {
DownloadManager dm = fileInfo.getDownloadManager();
return new com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl(dm == null ? null : DownloadManagerImpl.getDownloadStatic(dm), fileInfo);
} catch (DownloadException e) {
/* Ignore */
}
}
}
if (datasource instanceof com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) {
return datasource;
}
if (datasource instanceof TRHostTorrent) {
TRHostTorrent item = (TRHostTorrent) datasource;
return new TrackerTorrentImpl(item);
}
if (datasource instanceof TrackerTorrentImpl) {
return datasource;
}
}
} catch (Throwable t) {
Debug.out(t);
}
return datasource;
}
Aggregations