use of com.biglybt.core.peermanager.piecepicker.PiecePicker in project BiglyBT by BiglySoftware.
the class PiecesView method fillMenu.
@Override
public void fillMenu(String sColumnName, Menu menu) {
final List<Object> selected = tv.getSelectedDataSources();
if (selected.size() == 0) {
return;
}
if (manager == null) {
return;
}
PEPeerManager pm = manager.getPeerManager();
if (pm == null) {
return;
}
final PiecePicker picker = pm.getPiecePicker();
boolean has_undone = false;
boolean has_unforced = false;
for (Object obj : selected) {
PEPiece piece = (PEPiece) obj;
if (!piece.getDMPiece().isDone()) {
has_undone = true;
if (picker.isForcePiece(piece.getPieceNumber())) {
has_unforced = true;
}
}
}
final MenuItem force_piece = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(force_piece, "label.force.piece");
force_piece.setEnabled(has_undone);
if (has_undone) {
force_piece.setSelection(has_unforced);
force_piece.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean forced = force_piece.getSelection();
for (Object obj : selected) {
PEPiece piece = (PEPiece) obj;
if (!piece.getDMPiece().isDone()) {
picker.setForcePiece(piece.getPieceNumber(), forced);
}
}
}
});
}
final MenuItem cancel_reqs_piece = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(cancel_reqs_piece, "label.rerequest.blocks");
cancel_reqs_piece.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Object obj : selected) {
PEPiece piece = (PEPiece) obj;
for (int i = 0; i < piece.getNbBlocks(); i++) {
if (piece.isRequested(i)) {
piece.clearRequested(i);
}
}
}
}
});
final MenuItem reset_piece = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(reset_piece, "label.reset.piece");
reset_piece.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Object obj : selected) {
PEPiece piece = (PEPiece) obj;
piece.reset();
}
}
});
new MenuItem(menu, SWT.SEPARATOR);
}
use of com.biglybt.core.peermanager.piecepicker.PiecePicker in project BiglyBT by BiglySoftware.
the class BlocksItem method refresh.
@Override
public void refresh(final TableCell cell) {
final PEPiece pePiece = (PEPiece) cell.getDataSource();
if (pePiece == null) {
cell.setSortValue(0);
dispose(cell);
cell.setGraphic(null);
return;
}
cell.setSortValue(pePiece.getNbWritten());
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
PiecePicker picker = pePiece.getPiecePicker();
long lNumBlocks = pePiece.getNbBlocks();
int newWidth = cell.getWidth();
if (newWidth <= 0) {
dispose(cell);
cell.setGraphic(null);
return;
}
int newHeight = cell.getHeight();
int x1 = newWidth - 2;
int y1 = newHeight - 3;
if (x1 < 10 || y1 < 3) {
dispose(cell);
cell.setGraphic(null);
return;
}
Image image = new Image(Utils.getDisplay(), newWidth, newHeight);
Color color;
GC gcImage = new GC(image);
gcImage.setForeground(Colors.grey);
gcImage.drawRectangle(0, 0, x1 + 1, y1 + 1);
int blocksPerPixel = 0;
int iPixelsPerBlock = 0;
int pxRes = 0;
long pxBlockStep = 0;
int factor = 4;
while (iPixelsPerBlock <= 0) {
blocksPerPixel++;
iPixelsPerBlock = (int) ((x1 + 1) / (lNumBlocks / blocksPerPixel));
}
pxRes = (int) (x1 - ((lNumBlocks / blocksPerPixel) * iPixelsPerBlock));
if (pxRes <= 0)
pxRes = 1;
pxBlockStep = (lNumBlocks * factor) / pxRes;
long addBlocks = (lNumBlocks * factor) / pxBlockStep;
if ((addBlocks * iPixelsPerBlock) > pxRes)
pxBlockStep += 1;
/* String msg = "iPixelsPerBlock = "+iPixelsPerBlock + ", blocksPerPixel = " + blocksPerPixel;
msg += ", pxRes = " + pxRes + ", pxBlockStep = " + pxBlockStep + ", addBlocks = " + addBlocks + ", x1 = " + x1;
Debug.out(msg);*/
TOTorrent torrent = pePiece.getManager().getDiskManager().getTorrent();
boolean[] written = pePiece.getDMPiece().getWritten();
boolean piece_written = pePiece.isWritten();
int drawnWidth = 0;
int blockStep = 0;
int pieceNumber = pePiece.getPieceNumber();
long[] offsets = new long[(int) lNumBlocks];
long[] lengths = (long[]) offsets.clone();
Arrays.fill(offsets, (long) pePiece.getManager().getDiskManager().getPieceLength() * (long) pieceNumber);
for (int i = 0; i < lNumBlocks; lengths[i] = pePiece.getBlockSize(i), offsets[i] += DiskManager.BLOCK_SIZE * i, i++) ;
boolean egm = picker.isInEndGameMode();
boolean[] isCached = cacheStats == null ? new boolean[(int) lNumBlocks] : cacheStats.getBytesInCache(torrent, offsets, lengths);
for (int i = 0; i < lNumBlocks; i += blocksPerPixel) {
int nextWidth = iPixelsPerBlock;
blockStep += blocksPerPixel * factor;
if (blockStep >= pxBlockStep) {
nextWidth += (int) (blockStep / pxBlockStep);
blockStep -= pxBlockStep;
}
if (i >= lNumBlocks - blocksPerPixel) {
nextWidth = x1 - drawnWidth;
}
color = Colors.white;
int num = -1;
if ((written == null && piece_written) || (written != null && written[i])) {
color = colors[COLOR_WRITTEN];
} else if (pePiece.isDownloaded(i)) {
color = colors[COLOR_DOWNLOADED];
} else if (pePiece.isRequested(i)) {
if (egm) {
int req_count = picker.getEGMRequestCount(pieceNumber, i);
if (req_count < 2) {
color = colors[COLOR_REQUESTED];
} else {
color = colors[COLOR_EGM];
num = req_count;
}
} else {
color = colors[COLOR_REQUESTED];
}
}
gcImage.setBackground(color);
gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, y1);
if (isCached[i]) {
gcImage.setBackground(colors[COLOR_INCACHE]);
gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, 3);
}
if (num >= 0) {
gcImage.setForeground(Colors.black);
gcImage.drawString(String.valueOf(num), drawnWidth + 1, 0, true);
}
drawnWidth += nextWidth;
}
gcImage.dispose();
Image oldImage = null;
Graphic graphic = cell.getGraphic();
if (graphic instanceof UISWTGraphic) {
oldImage = ((UISWTGraphic) graphic).getImage();
}
if (cell instanceof TableCellSWT) {
((TableCellSWT) cell).setGraphic(image);
} else {
cell.setGraphic(new UISWTGraphicImpl(image));
}
if (oldImage != null && !oldImage.isDisposed())
oldImage.dispose();
gcImage.dispose();
}
});
}
use of com.biglybt.core.peermanager.piecepicker.PiecePicker in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method fillMenu.
public static void fillMenu(final TableView<?> tv, String columnName, final Menu menu, final DownloadManager[] manager_list, final DiskManagerFileInfo[][] files_list) {
Shell shell = menu.getShell();
final List<DiskManagerFileInfo> all_files = new ArrayList<>();
for (DiskManagerFileInfo[] files : files_list) {
all_files.addAll(Arrays.asList(files));
}
boolean hasSelection = (all_files.size() > 0);
final MenuItem itemOpen = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemOpen, "FilesView.menu.open");
Utils.setMenuItemImage(itemOpen, "run");
// Invoke open on enter, double click
menu.setDefaultItem(itemOpen);
// Explore (Copied from MyTorrentsView)
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
final MenuItem itemExplore = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemExplore, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"));
itemExplore.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (int i = all_files.size() - 1; i >= 0; i--) {
DiskManagerFileInfo info = (DiskManagerFileInfo) all_files.get(i);
if (info != null) {
ManagerUtils.open(info, use_open_containing_folder);
}
}
}
});
itemExplore.setEnabled(hasSelection);
// open in browser
final Menu menuBrowse = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem itemBrowse = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(itemBrowse, "MyTorrentsView.menu.browse");
itemBrowse.setMenu(menuBrowse);
final MenuItem itemBrowsePublic = new MenuItem(menuBrowse, SWT.PUSH);
itemBrowsePublic.setText(MessageText.getString("label.public") + "...");
itemBrowsePublic.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (int i = all_files.size() - 1; i >= 0; i--) {
DiskManagerFileInfo info = (DiskManagerFileInfo) all_files.get(i);
if (info != null) {
ManagerUtils.browse(info, false, true);
}
}
}
});
final MenuItem itemBrowseAnon = new MenuItem(menuBrowse, SWT.PUSH);
itemBrowseAnon.setText(MessageText.getString("label.anon") + "...");
itemBrowseAnon.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (int i = all_files.size() - 1; i >= 0; i--) {
DiskManagerFileInfo info = all_files.get(i);
if (info != null) {
ManagerUtils.browse(info, 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(all_files.get(0), true, false);
if (url != null) {
ClipboardCopy.copyToClipBoard(url);
}
}
});
}
});
itemBrowseURL.setEnabled(all_files.size() == 1);
itemBrowse.setEnabled(hasSelection);
// rename/retarget
MenuItem itemRenameOrRetarget = null, itemRenameOrRetargetBatch = null, itemRename = null, itemRetarget = null;
// "Rename or Retarget" -- Opens up file chooser (can choose new dir and new name)
itemRenameOrRetarget = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRenameOrRetarget, "FilesView.menu.rename");
itemRenameOrRetarget.setData("rename", Boolean.valueOf(true));
itemRenameOrRetarget.setData("retarget", Boolean.valueOf(true));
itemRenameOrRetarget.setData("batch", Boolean.valueOf(false));
// "Rename or Retarget (Batch)"
itemRenameOrRetargetBatch = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRenameOrRetargetBatch, "FilesView.menu.rename.batch");
itemRenameOrRetargetBatch.setData("rename", Boolean.valueOf(true));
itemRenameOrRetargetBatch.setData("retarget", Boolean.valueOf(true));
itemRenameOrRetargetBatch.setData("batch", Boolean.valueOf(true));
// "Quick Rename" -- opens up input box with name
itemRename = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRename, "FilesView.menu.rename_only");
itemRename.setData("rename", Boolean.valueOf(true));
itemRename.setData("retarget", Boolean.valueOf(false));
itemRename.setData("batch", Boolean.valueOf(false));
// "Move Files" -- opens up directory chooser
itemRetarget = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRetarget, "FilesView.menu.retarget");
itemRetarget.setData("rename", Boolean.valueOf(false));
itemRetarget.setData("retarget", Boolean.valueOf(true));
itemRename.setData("batch", Boolean.valueOf(false));
// revert
final MenuItem itemRevertFiles = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRevertFiles, "MyTorrentsView.menu.revertfiles");
// locate files
final MenuItem itemLocateFiles = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemLocateFiles, "MyTorrentsView.menu.locatefiles");
// find more
final MenuItem itemfindMore = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemfindMore, "MyTorrentsView.menu.findmorelikethis");
// clear links
MenuItem itemClearLinks = null;
final int userMode = COConfigurationManager.getIntParameter("User Mode");
if (userMode > 1) {
itemClearLinks = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemClearLinks, "FilesView.menu.clear.links");
}
// quick view
final MenuItem itemQuickView = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(itemQuickView, "MainWindow.menu.quick_view");
itemQuickView.setEnabled(all_files.size() == 1 && Utils.isQuickViewSupported(all_files.get(0)));
itemQuickView.setSelection(all_files.size() == 1 && Utils.isQuickViewActive(all_files.get(0)));
itemQuickView.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg) {
Utils.setQuickViewActive(all_files.get(0), itemQuickView.getSelection());
}
});
if (manager_list.length == 1) {
// lazy for the moment
MenuFactory.addAlertsMenu(menu, manager_list[0], files_list[0]);
}
// personal share
final MenuItem itemPersonalShare = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemPersonalShare, "MyTorrentsView.menu.create_personal_share");
// priority
final MenuItem itemPriority = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(itemPriority, "FilesView.menu.setpriority");
final Menu menuPriority = new Menu(shell, SWT.DROP_DOWN);
itemPriority.setMenu(menuPriority);
final MenuItem itemHigh = new MenuItem(menuPriority, SWT.CASCADE);
itemHigh.setData("Priority", PRIORITY_HIGH);
Messages.setLanguageText(itemHigh, "FilesView.menu.setpriority.high");
final MenuItem itemNormal = new MenuItem(menuPriority, SWT.CASCADE);
itemNormal.setData("Priority", PRIORITY_NORMAL);
Messages.setLanguageText(itemNormal, "FilesView.menu.setpriority.normal");
final MenuItem itemLow = new MenuItem(menuPriority, SWT.CASCADE);
itemLow.setData("Priority", PRIORITY_LOW);
Messages.setLanguageText(itemLow, "FileItem.low");
final MenuItem itemNumeric = new MenuItem(menuPriority, SWT.CASCADE);
itemNumeric.setData("Priority", PRIORITY_NUMERIC);
Messages.setLanguageText(itemNumeric, "FilesView.menu.setpriority.numeric");
final MenuItem itemNumericAuto = new MenuItem(menuPriority, SWT.CASCADE);
itemNumericAuto.setData("Priority", PRIORITY_NUMERIC_AUTO);
Messages.setLanguageText(itemNumericAuto, "FilesView.menu.setpriority.numeric.auto");
final MenuItem itemSkipped = new MenuItem(menuPriority, SWT.CASCADE);
itemSkipped.setData("Priority", PRIORITY_SKIPPED);
Messages.setLanguageText(itemSkipped, "FilesView.menu.setpriority.skipped");
final MenuItem itemDelete = new MenuItem(menuPriority, SWT.CASCADE);
itemDelete.setData("Priority", PRIORITY_DELETE);
// lazy but we're near release
Messages.setLanguageText(itemDelete, "wizard.multitracker.delete");
if (all_files.size() == 1) {
DiskManagerFileInfo file = all_files.get(0);
final MenuItem itemSequential = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(itemSequential, "menu.sequential.file");
PEPeerManager pm = file.getDownloadManager().getPeerManager();
if (pm == null || file.getDownloaded() == file.getLength() || file.isSkipped()) {
itemSequential.setEnabled(false);
} else {
PiecePicker pp = pm.getPiecePicker();
int info = pp.getSequentialInfo();
itemSequential.setSelection(file.getFirstPieceNumber() == info - 1);
itemSequential.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg) {
if (itemSequential.getSelection()) {
pp.setSequentialAscendingFrom(file.getFirstPieceNumber());
} else {
pp.clearSequential();
}
}
});
}
}
new MenuItem(menu, SWT.SEPARATOR);
if (!hasSelection) {
itemOpen.setEnabled(false);
itemPriority.setEnabled(false);
itemRenameOrRetarget.setEnabled(false);
itemRenameOrRetargetBatch.setEnabled(false);
itemRename.setEnabled(false);
itemRetarget.setEnabled(false);
itemRevertFiles.setEnabled(false);
itemLocateFiles.setEnabled(false);
itemfindMore.setEnabled(false);
if (itemClearLinks != null) {
itemClearLinks.setEnabled(false);
}
itemPersonalShare.setEnabled(false);
return;
}
boolean all_persistent = true;
boolean open = true;
boolean all_compact = true;
boolean all_dnd_not_deleted = true;
boolean all_high_pri = true;
boolean all_normal_pri = true;
boolean all_low_pri = true;
boolean all_complete = true;
boolean any_relocated = false;
final List<DiskManagerFileInfo> files_with_links = new ArrayList<>();
for (int j = 0; j < manager_list.length; j++) {
DownloadManager manager = manager_list[j];
int dm_file_count = manager.getNumFileInfos();
if (!manager.isPersistent()) {
all_persistent = false;
}
DiskManagerFileInfo[] files = files_list[j];
DownloadManagerState dm_state = manager.getDownloadState();
int[] storage_types = manager.getStorageType(files);
for (int i = 0; i < files.length; i++) {
DiskManagerFileInfo file_info = files[i];
if (open && file_info.getAccessMode() != DiskManagerFileInfo.READ) {
open = false;
}
boolean isCompact = storage_types[i] == DiskManagerFileInfo.ST_COMPACT || storage_types[i] == DiskManagerFileInfo.ST_REORDER_COMPACT;
if (all_compact && !isCompact) {
all_compact = false;
}
if (all_dnd_not_deleted || all_high_pri || all_normal_pri || all_low_pri) {
if (file_info.isSkipped()) {
all_high_pri = all_normal_pri = all_low_pri = false;
if (isCompact) {
all_dnd_not_deleted = false;
}
} else {
all_dnd_not_deleted = false;
// Only do this check if we need to.
if (all_high_pri || all_normal_pri || all_low_pri) {
int file_pri = file_info.getPriority();
if (file_pri == 0) {
all_high_pri = all_low_pri = false;
} else if (file_pri == 1) {
all_normal_pri = all_low_pri = false;
} else if (file_pri == -1) {
all_normal_pri = all_high_pri = false;
} else {
all_low_pri = all_normal_pri = all_high_pri = false;
}
}
}
}
File file_link = file_info.getFile(true);
File file_nolink = file_info.getFile(false);
if (file_info.getDownloaded() != file_info.getLength() || file_link.length() != file_info.getLength()) {
all_complete = false;
}
if (dm_file_count > 1) {
if (!file_nolink.getAbsolutePath().equals(file_link.getAbsolutePath())) {
files_with_links.add(file_info);
}
}
File target = dm_state.getFileLink(file_info.getIndex(), file_nolink);
if (target != null) {
if (target != file_nolink) {
if (!target.equals(file_nolink)) {
any_relocated = true;
}
}
}
}
}
// we can only open files if they are read-only
itemOpen.setEnabled(open);
// can't rename files for non-persistent downloads (e.g. shares) as these
// are managed "externally"
itemRenameOrRetarget.setEnabled(all_persistent);
itemRenameOrRetargetBatch.setEnabled(all_persistent);
itemRename.setEnabled(all_persistent);
itemRetarget.setEnabled(all_persistent);
// only enable for single files - people prolly don't expect a multi-selection to result
// in multiple shares, rather they would expect one share with the files they selected
// which we don't support
itemPersonalShare.setEnabled(all_complete && all_files.size() == 1);
itemSkipped.setEnabled(!all_dnd_not_deleted);
itemHigh.setEnabled(!all_high_pri);
itemNormal.setEnabled(!all_normal_pri);
itemLow.setEnabled(!all_low_pri);
itemDelete.setEnabled(!all_compact);
itemOpen.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (int i = 0; i < all_files.size(); i++) {
DiskManagerFileInfo info = (DiskManagerFileInfo) all_files.get(i);
if (info != null && info.getAccessMode() == DiskManagerFileInfo.READ) {
Utils.launch(info);
}
}
}
});
Listener rename_listener = new Listener() {
@Override
public void handleEvent(Event event) {
final boolean rename_it = ((Boolean) event.widget.getData("rename")).booleanValue();
final boolean retarget_it = ((Boolean) event.widget.getData("retarget")).booleanValue();
final boolean batch = ((Boolean) event.widget.getData("batch")).booleanValue();
rename(tv, all_files.toArray(new Object[all_files.size()]), rename_it, retarget_it, batch);
}
};
itemRenameOrRetargetBatch.addListener(SWT.Selection, rename_listener);
itemRenameOrRetarget.addListener(SWT.Selection, rename_listener);
itemRename.addListener(SWT.Selection, rename_listener);
itemRetarget.addListener(SWT.Selection, rename_listener);
itemLocateFiles.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
ManagerUtils.locateFiles(manager_list, files_list, menu.getShell());
}
});
itemLocateFiles.setEnabled(true);
if (ManagerUtils.canFindMoreLikeThis()) {
itemfindMore.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
ManagerUtils.findMoreLikeThis(all_files.get(0), menu.getShell());
}
});
itemfindMore.setEnabled(all_files.size() == 1);
}
itemRevertFiles.setEnabled(any_relocated);
itemRevertFiles.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
revertFiles(tv, all_files);
}
});
if (itemClearLinks != null) {
itemClearLinks.setEnabled(files_with_links.size() > 0);
itemClearLinks.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (DiskManagerFileInfo file : files_with_links) {
file.setLink(null);
}
invalidateRows(tv, files_with_links);
}
});
}
itemPersonalShare.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
Map<String, String> properties = new HashMap<>();
properties.put(ShareManager.PR_PERSONAL, "true");
for (int i = 0; i < all_files.size(); i++) {
DiskManagerFileInfo file_info = all_files.get(i);
File file = file_info.getFile(true);
if (file.isFile()) {
ShareUtils.shareFile(file.getAbsolutePath(), properties);
} else if (file.isDirectory()) {
ShareUtils.shareDir(file.getAbsolutePath(), properties);
}
}
}
});
Listener priorityListener = new Listener() {
@Override
public void handleEvent(Event event) {
final Object priority = event.widget.getData("Priority");
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
changePriority(priority, all_files);
}
});
}
};
itemNumeric.addListener(SWT.Selection, priorityListener);
itemNumericAuto.addListener(SWT.Selection, priorityListener);
itemHigh.addListener(SWT.Selection, priorityListener);
itemNormal.addListener(SWT.Selection, priorityListener);
itemLow.addListener(SWT.Selection, priorityListener);
itemSkipped.addListener(SWT.Selection, priorityListener);
itemDelete.addListener(SWT.Selection, priorityListener);
if (columnName.equals(ColumnUnopened.COLUMN_ID)) {
final MenuItem toggle = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(toggle, "label.toggle.new.marker");
toggle.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg) {
for (int i = 0; i < all_files.size(); i++) {
DiskManagerFileInfo file = all_files.get(i);
DownloadManager dm = file.getDownloadManager();
int ff = dm.getDownloadState().getFileFlags(file.getIndex());
ff ^= DownloadManagerState.FILE_FLAG_NOT_NEW;
dm.getDownloadState().setFileFlags(file.getIndex(), ff);
}
}
});
new MenuItem(menu, SWT.SEPARATOR);
}
com.biglybt.pif.ui.menus.MenuItem[] menu_items = MenuItemManager.getInstance().getAllAsArray(MenuManager.MENU_FILE_CONTEXT);
if (menu_items.length > 0) {
// plugins take com.biglybt.pif.disk.DiskManagerFileInfo
com.biglybt.pif.disk.DiskManagerFileInfo[] fileInfos = new com.biglybt.pif.disk.DiskManagerFileInfo[all_files.size()];
for (int i = 0; i < all_files.size(); i++) {
fileInfos[i] = (com.biglybt.pif.disk.DiskManagerFileInfo) PluginCoreUtils.convert(all_files.get(i), false);
}
MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(fileInfos));
}
}
use of com.biglybt.core.peermanager.piecepicker.PiecePicker in project BiglyBT by BiglySoftware.
the class Show method printTorrentDetails.
/**
* prints out the full details of a particular torrent
* @param out
* @param dm
* @param torrentNum
*/
private static void printTorrentDetails(PrintStream out, DownloadManager dm, int torrentNum, List<String> args) {
String name = dm.getDisplayName();
if (name == null)
name = "?";
out.println("> -----");
out.println("Info on Torrent #" + torrentNum + " (" + name + ")");
out.println("- General Info -");
String[] health = { "- no info -", "stopped", "no remote connections", "no tracker", "OK", "ko" };
try {
out.println("Health: " + health[dm.getHealthStatus()]);
} catch (Exception e) {
out.println("Health: " + health[0]);
}
out.println("State: " + Integer.toString(dm.getState()));
if (dm.getState() == DownloadManager.STATE_ERROR)
out.println("Error: " + dm.getErrorDetails());
out.println("Hash: " + TorrentUtils.nicePrintTorrentHash(dm.getTorrent(), true));
out.println("- Torrent file -");
out.println("Torrent Filename: " + dm.getTorrentFileName());
out.println("Saving to: " + dm.getSaveLocation());
out.println("Created By: " + dm.getTorrentCreatedBy());
out.println("Comment: " + dm.getTorrentComment());
Category cat = dm.getDownloadState().getCategory();
if (cat != null) {
out.println("Category: " + cat.getName());
}
List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, dm);
String tags_str;
if (tags.size() == 0) {
tags_str = "None";
} else {
tags_str = "";
for (Tag t : tags) {
tags_str += (tags_str.length() == 0 ? "" : ",") + t.getTagName(true);
}
}
out.println("Tags: " + tags_str);
out.println("- Tracker Info -");
TRTrackerAnnouncer trackerclient = dm.getTrackerClient();
if (trackerclient != null) {
out.println("URL: " + trackerclient.getTrackerURL());
String timestr;
try {
int time = trackerclient.getTimeUntilNextUpdate();
if (time < 0) {
timestr = MessageText.getString("GeneralView.label.updatein.querying");
} else {
int minutes = time / 60;
int seconds = time % 60;
String strSeconds = "" + seconds;
if (seconds < 10) {
// $NON-NLS-1$
strSeconds = "0" + seconds;
}
timestr = minutes + ":" + strSeconds;
}
} catch (Exception e) {
timestr = "unknown";
}
out.println("Time till next Update: " + timestr);
out.println("Status: " + trackerclient.getStatusString());
} else
out.println(" Not available");
out.println("- Files Info -");
DiskManagerFileInfo[] files = dm.getDiskManagerFileInfo();
if (files != null) {
for (int i = 0; i < files.length; i++) {
out.print(((i < 9) ? " " : " ") + Integer.toString(i + 1) + " (");
String tmp = ">";
if (files[i].getPriority() > 0)
tmp = "+";
if (files[i].isSkipped())
tmp = "!";
out.print(tmp + ") ");
if (files[i] != null) {
long fLen = files[i].getLength();
if (fLen > 0) {
DecimalFormat df = new DecimalFormat("000.0%");
out.print(df.format(files[i].getDownloaded() * 1.0 / fLen));
out.println("\t" + files[i].getFile(true).getName());
} else
out.println("Info not available.");
} else
out.println("Info not available.");
}
} else {
out.println(" Info not available.");
}
for (String arg : args) {
arg = arg.toLowerCase();
if (arg.startsWith("pie")) {
out.println("Pieces");
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
PiecePicker picker = pm.getPiecePicker();
PEPiece[] pieces = pm.getPieces();
String line = "";
for (int i = 0; i < pieces.length; i++) {
String str = picker.getPieceString(i);
line += (line.length() == 0 ? (i + " ") : ",") + str;
PEPiece piece = pieces[i];
if (piece != null) {
line += ":" + piece.getString();
}
if ((i + 1) % 10 == 0) {
out.println(line);
line = "";
}
}
if (line.length() > 0) {
out.println(line);
}
}
} else if (arg.startsWith("pee")) {
out.println("Peers");
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
List<PEPeer> peers = pm.getPeers();
out.println("\tConnected to " + peers.size() + " peers");
for (PEPeer peer : peers) {
PEPeerStats stats = peer.getStats();
System.out.println("\t\t" + peer.getIp() + ", in=" + (peer.isIncoming() ? "Y" : "N") + ", prot=" + peer.getProtocol() + ", choked=" + (peer.isChokingMe() ? "Y" : "N") + ", up=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate() + stats.getProtocolSendRate()) + ", down=" + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate() + stats.getProtocolReceiveRate()) + ", in_req=" + peer.getIncomingRequestCount() + ", out_req=" + peer.getOutgoingRequestCount());
}
}
}
}
out.println("> -----");
}
use of com.biglybt.core.peermanager.piecepicker.PiecePicker in project BiglyBT by BiglySoftware.
the class FileInfoView method createFileInfoPanel.
private Composite createFileInfoPanel(Composite parent) {
GridLayout layout;
GridData gridData;
// Peer Info section contains
// - Peer's Block display
// - Peer's Datarate
fileInfoComposite = new Composite(parent, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
fileInfoComposite.setLayout(layout);
gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
fileInfoComposite.setLayoutData(gridData);
new Label(fileInfoComposite, SWT.NULL).setLayoutData(new GridData());
topLabel = new Label(fileInfoComposite, SWT.NULL);
gridData = new GridData(SWT.FILL, SWT.DEFAULT, false, false);
topLabel.setLayoutData(gridData);
sc = new ScrolledComposite(fileInfoComposite, SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
layout = new GridLayout();
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
sc.setLayout(layout);
gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
sc.setLayoutData(gridData);
fileInfoCanvas = new Canvas(sc, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
gridData = new GridData(GridData.FILL, SWT.DEFAULT, true, false);
fileInfoCanvas.setLayoutData(gridData);
fileInfoCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (e.width <= 0 || e.height <= 0)
return;
try {
Rectangle bounds = (img == null) ? null : img.getBounds();
if (bounds == null) {
e.gc.fillRectangle(e.x, e.y, e.width, e.height);
} else {
if (e.x + e.width > bounds.width)
e.gc.fillRectangle(bounds.width, e.y, e.x + e.width - bounds.width + 1, e.height);
if (e.y + e.height > bounds.height)
e.gc.fillRectangle(e.x, bounds.height, e.width, e.y + e.height - bounds.height + 1);
int width = Math.min(e.width, bounds.width - e.x);
int height = Math.min(e.height, bounds.height - e.y);
e.gc.drawImage(img, e.x, e.y, width, height, e.x, e.y, width, height);
}
} catch (Exception ex) {
}
}
});
fileInfoCanvas.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseHover(MouseEvent event) {
showPieceDetails(event.x, event.y);
}
});
Listener doNothingListener = new Listener() {
@Override
public void handleEvent(Event event) {
}
};
fileInfoCanvas.addListener(SWT.KeyDown, doNothingListener);
final Menu menu = new Menu(fileInfoCanvas.getShell(), SWT.POP_UP);
fileInfoCanvas.setMenu(menu);
fileInfoCanvas.addListener(SWT.MenuDetect, new Listener() {
@Override
public void handleEvent(Event event) {
Point pt = fileInfoCanvas.toControl(event.x, event.y);
int piece_number = getPieceNumber(pt.x, pt.y);
menu.setData("pieceNumber", piece_number);
}
});
MenuBuildUtils.addMaintenanceListenerForMenu(menu, new MenuBuildUtils.MenuBuilder() {
@Override
public void buildMenu(Menu menu, MenuEvent event) {
Integer pn = (Integer) menu.getData("pieceNumber");
if (pn != null && pn != -1) {
DownloadManager download_manager = file.getDownloadManager();
if (download_manager == null) {
return;
}
DiskManager disk_manager = download_manager.getDiskManager();
PEPeerManager peer_manager = download_manager.getPeerManager();
if (disk_manager == null || peer_manager == null) {
return;
}
final PiecePicker picker = peer_manager.getPiecePicker();
DiskManagerPiece[] dm_pieces = disk_manager.getPieces();
PEPiece[] pe_pieces = peer_manager.getPieces();
final int piece_number = pn;
final DiskManagerPiece dm_piece = dm_pieces[piece_number];
final PEPiece pe_piece = pe_pieces[piece_number];
final MenuItem force_piece = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(force_piece, "label.force.piece");
boolean done = dm_piece.isDone();
force_piece.setEnabled(!done);
if (!done) {
force_piece.setSelection(picker.isForcePiece(piece_number));
force_piece.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
picker.setForcePiece(piece_number, force_piece.getSelection());
}
});
}
final MenuItem reset_piece = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(reset_piece, "label.reset.piece");
boolean can_reset = dm_piece.isDone() || dm_piece.getNbWritten() > 0;
reset_piece.setEnabled(can_reset);
reset_piece.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dm_piece.reset();
if (pe_piece != null) {
pe_piece.reset();
}
}
});
}
}
});
fileInfoCanvas.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event e) {
if (refreshInfoCanvasQueued) {
return;
}
refreshInfoCanvasQueued = true;
// wrap in asyncexec because sc.setMinWidth (called later) doesn't work
// too well inside a resize (the canvas won't size isn't always updated)
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
if (img != null) {
int iOldColCount = img.getBounds().width / BLOCK_SIZE;
int iNewColCount = fileInfoCanvas.getClientArea().width / BLOCK_SIZE;
if (iOldColCount != iNewColCount)
refreshInfoCanvas();
}
}
});
}
});
sc.setContent(fileInfoCanvas);
Legend.createLegendComposite(fileInfoComposite, blockColors, new String[] { "FileView.BlockView.Done", "FileView.BlockView.Skipped", "FileView.BlockView.Active", "FileView.BlockView.Outstanding" }, new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
int iFontPixelsHeight = 10;
int iFontPointHeight = (iFontPixelsHeight * 72) / Utils.getDPIRaw(fileInfoCanvas.getDisplay()).y;
Font f = fileInfoCanvas.getFont();
FontData[] fontData = f.getFontData();
fontData[0].setHeight(iFontPointHeight);
font = new Font(fileInfoCanvas.getDisplay(), fontData);
return fileInfoComposite;
}
Aggregations