use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method changePriority.
public static void changePriority(Object type, final List<DiskManagerFileInfo> file_list) {
if (file_list == null || file_list.size() == 0) {
return;
}
if (type == PRIORITY_NUMERIC) {
changePriorityManual(file_list);
return;
} else if (type == PRIORITY_NUMERIC_AUTO) {
changePriorityAuto(file_list);
return;
}
Map<DownloadManager, ArrayList<DiskManagerFileInfo>> mapDMtoDMFI = new IdentityHashMap<>();
for (DiskManagerFileInfo file : file_list) {
DownloadManager dm = file.getDownloadManager();
ArrayList<DiskManagerFileInfo> listFileInfos = mapDMtoDMFI.get(dm);
if (listFileInfos == null) {
listFileInfos = new ArrayList<>(1);
mapDMtoDMFI.put(dm, listFileInfos);
}
listFileInfos.add(file);
}
boolean skipped = (type == PRIORITY_SKIPPED || type == PRIORITY_DELETE);
boolean delete_action = (type == PRIORITY_DELETE);
for (DownloadManager dm : mapDMtoDMFI.keySet()) {
ArrayList<DiskManagerFileInfo> list = mapDMtoDMFI.get(dm);
DiskManagerFileInfo[] fileInfos = list.toArray(new DiskManagerFileInfo[0]);
if (type == PRIORITY_NORMAL) {
dm.setFilePriorities(fileInfos, 0);
} else if (type == PRIORITY_HIGH) {
dm.setFilePriorities(fileInfos, 1);
} else if (type == PRIORITY_LOW) {
dm.setFilePriorities(fileInfos, -1);
}
boolean paused = setSkipped(dm, fileInfos, skipped, delete_action);
if (paused) {
dm.resume();
}
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo 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.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method revertFiles.
public static void revertFiles(final TableView<?> tv, DownloadManager[] dms) {
List<DiskManagerFileInfo> files = new ArrayList<>();
for (DownloadManager dm : dms) {
DiskManagerFileInfo[] dm_files = dm.getDiskManagerFileInfoSet().getFiles();
LinkFileMap links = dm.getDownloadState().getFileLinks();
Iterator<LinkFileMap.Entry> it = links.entryIterator();
while (it.hasNext()) {
LinkFileMap.Entry entry = it.next();
if (entry.getToFile() != null) {
files.add(dm_files[entry.getIndex()]);
}
}
}
if (files.size() > 0) {
revertFiles(tv, files);
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method changePriorityAuto.
private static void changePriorityAuto(List<DiskManagerFileInfo> file_list) {
int priority = 0;
Map<DownloadManager, ArrayList<DiskManagerFileInfo>> mapDMtoDMFI = new IdentityHashMap<>();
for (DiskManagerFileInfo file : file_list) {
DownloadManager dm = file.getDownloadManager();
ArrayList<DiskManagerFileInfo> listFileInfos = mapDMtoDMFI.get(dm);
if (listFileInfos == null) {
listFileInfos = new ArrayList<>(1);
mapDMtoDMFI.put(dm, listFileInfos);
}
listFileInfos.add(file);
file.setPriority(priority++);
}
for (Map.Entry<DownloadManager, ArrayList<DiskManagerFileInfo>> entry : mapDMtoDMFI.entrySet()) {
DiskManagerFileInfo[] all_files = entry.getKey().getDiskManagerFileInfoSet().getFiles();
ArrayList<DiskManagerFileInfo> files = entry.getValue();
int next_priority = 0;
if (all_files.length != files.size()) {
Set<Integer> affected_indexes = new HashSet<>();
for (DiskManagerFileInfo file : files) {
affected_indexes.add(file.getIndex());
}
for (DiskManagerFileInfo file : all_files) {
if (!(affected_indexes.contains(file.getIndex()) || file.isSkipped())) {
next_priority = Math.max(next_priority, file.getPriority() + 1);
}
}
}
next_priority += files.size();
for (DiskManagerFileInfo file : files) {
file.setPriority(--next_priority);
}
}
for (DownloadManager dm : mapDMtoDMFI.keySet()) {
ArrayList<DiskManagerFileInfo> list = mapDMtoDMFI.get(dm);
DiskManagerFileInfo[] fileInfos = list.toArray(new DiskManagerFileInfo[0]);
boolean paused = setSkipped(dm, fileInfos, false, false);
if (paused) {
dm.resume();
}
}
}
use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.
the class ColumnProgressETA method getETA.
private long getETA(TableCell cell) {
Object ds = cell.getDataSource();
if (ds instanceof DiskManagerFileInfo) {
return 0;
}
DownloadManager dm = (DownloadManager) cell.getDataSource();
long diff = SystemTime.getCurrentTime() - dm.getStats().getTimeStarted();
if (diff > SHOW_ETA_AFTER_MS) {
return dm.getStats().getSmoothedETA();
}
return 0;
}
Aggregations