use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class ScrapeInfoView method initialize.
private void initialize(Composite parent) {
cParent = parent;
Label label;
GridData gridData;
final Display display = parent.getDisplay();
if (cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
cScrapeInfoView = new Composite(parent, SWT.NONE);
}
gridData = new GridData(GridData.FILL_BOTH);
cScrapeInfoView.setLayoutData(gridData);
GridLayout layoutInfo = new GridLayout();
layoutInfo.numColumns = 4;
cScrapeInfoView.setLayout(layoutInfo);
label = new Label(cScrapeInfoView, SWT.LEFT);
// $NON-NLS-1$
Messages.setLanguageText(label, "GeneralView.label.trackerurl");
label.setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
label.setForeground(Colors.blue);
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
String announce = trackerUrlValue.getText();
if (announce != null && announce.length() != 0) {
new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
}
}
@Override
public void mouseDown(MouseEvent arg0) {
String announce = trackerUrlValue.getText();
if (announce != null && announce.length() != 0) {
new Clipboard(display).setContents(new Object[] { announce }, new Transfer[] { TextTransfer.getInstance() });
}
}
});
menuTracker = new Menu(parent.getShell(), SWT.POP_UP);
itemSelect = new MenuItem(menuTracker, SWT.CASCADE);
Messages.setLanguageText(itemSelect, "GeneralView.menu.selectTracker");
MenuItem itemEdit = new MenuItem(menuTracker, SWT.NULL);
Messages.setLanguageText(itemEdit, "MyTorrentsView.menu.editTracker");
cScrapeInfoView.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
menuTracker.dispose();
}
});
itemEdit.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
final TOTorrent torrent = manager.getTorrent();
if (torrent == null) {
return;
}
List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {
@Override
public void trackersChanged(String str, String str2, List<List<String>> _group) {
TorrentUtils.listToAnnounceGroups(_group, torrent);
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e2) {
Debug.printStackTrace(e2);
}
TRTrackerAnnouncer tc = manager.getTrackerClient();
if (tc != null) {
tc.resetTrackerUrl(true);
}
}
}, true, true);
}
});
TOTorrent torrent = manager == null ? null : manager.getTorrent();
itemEdit.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
final Listener menuListener = new Listener() {
@Override
public void handleEvent(Event e) {
if (e.widget instanceof MenuItem) {
String text = ((MenuItem) e.widget).getText();
TOTorrent torrent = manager.getTorrent();
TorrentUtils.announceGroupsSetFirst(torrent, text);
try {
TorrentUtils.writeToFile(torrent);
} catch (TOTorrentException f) {
Debug.printStackTrace(f);
}
TRTrackerAnnouncer tc = manager.getTrackerClient();
if (tc != null) {
tc.resetTrackerUrl(false);
}
}
}
};
menuTracker.addListener(SWT.Show, new Listener() {
@Override
public void handleEvent(Event e) {
Menu menuSelect = itemSelect.getMenu();
if (menuSelect != null && !menuSelect.isDisposed()) {
menuSelect.dispose();
}
if (manager == null || cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
return;
}
List<List<String>> groups = TorrentUtils.announceGroupsToList(manager.getTorrent());
menuSelect = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
itemSelect.setMenu(menuSelect);
for (List<String> trackers : groups) {
MenuItem menuItem = new MenuItem(menuSelect, SWT.CASCADE);
Messages.setLanguageText(menuItem, "wizard.multitracker.group");
Menu menu = new Menu(cScrapeInfoView.getShell(), SWT.DROP_DOWN);
menuItem.setMenu(menu);
for (String url : trackers) {
MenuItem menuItemTracker = new MenuItem(menu, SWT.CASCADE);
menuItemTracker.setText(url);
menuItemTracker.addListener(SWT.Selection, menuListener);
}
}
}
});
trackerUrlValue = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 70);
trackerUrlValue.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
if (event.button == 3 || (event.button == 1 && event.stateMask == SWT.CONTROL)) {
menuTracker.setVisible(true);
} else if (event.button == 1) {
String url = trackerUrlValue.getText();
if (url.startsWith("http://") || url.startsWith("https://")) {
int pos = -1;
if ((pos = url.indexOf("/announce")) != -1) {
url = url.substring(0, pos + 1);
}
Utils.launch(url);
}
}
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
trackerUrlValue.setLayoutData(gridData);
// //////////////////////
label = new Label(cScrapeInfoView, SWT.LEFT);
Messages.setLanguageText(label, "GeneralView.label.tracker");
tracker_status = new BufferedTruncatedLabel(cScrapeInfoView, SWT.LEFT, 150);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
tracker_status.setLayoutData(gridData);
label = new Label(cScrapeInfoView, SWT.LEFT);
Messages.setLanguageText(label, "GeneralView.label.updatein");
trackerUpdateIn = new BufferedLabel(cScrapeInfoView, SWT.LEFT);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
trackerUpdateIn.setLayoutData(gridData);
updateButton = new Button(cScrapeInfoView, SWT.PUSH);
Messages.setLanguageText(updateButton, "GeneralView.label.trackerurlupdate");
updateButton.setLayoutData(new GridData());
updateButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
new AEThread2("SIV:async") {
@Override
public void run() {
if (manager.getTrackerClient() != null) {
manager.requestTrackerAnnounce(false);
} else {
manager.requestTrackerScrape(true);
}
}
}.start();
}
});
cScrapeInfoView.layout(true);
}
use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class MyTorrentsView method createDragDrop.
private void createDragDrop() {
try {
Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
if (dragSource != null && !dragSource.isDisposed()) {
dragSource.dispose();
}
if (dropTarget != null && !dropTarget.isDisposed()) {
dropTarget.dispose();
}
dragSource = tv.createDragSource(DND.DROP_MOVE | DND.DROP_COPY);
if (dragSource != null) {
dragSource.setTransfer(types);
dragSource.addDragListener(new DragSourceAdapter() {
private String eventData;
@Override
public void dragStart(DragSourceEvent event) {
TableRowCore[] rows = tv.getSelectedRows();
if (rows.length != 0) {
event.doit = true;
// System.out.println("DragStart");
drag_drop_line_start = rows[0].getIndex();
drag_drop_rows = rows;
} else {
event.doit = false;
drag_drop_line_start = -1;
drag_drop_rows = null;
}
// Build eventData here because on OSX, selection gets cleared
// by the time dragSetData occurs
boolean onlyDMs = true;
StringBuilder sb = new StringBuilder();
Object[] selectedDataSources = tv.getSelectedDataSources(true);
for (Object ds : selectedDataSources) {
if (ds instanceof DownloadManager) {
DownloadManager dm = (DownloadManager) ds;
TOTorrent torrent = dm.getTorrent();
if (torrent != null) {
try {
sb.append(torrent.getHashWrapper().toBase32String());
sb.append('\n');
} catch (TOTorrentException e) {
}
}
} else if (ds instanceof DiskManagerFileInfo) {
DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
DownloadManager dm = fileInfo.getDownloadManager();
TOTorrent torrent = dm.getTorrent();
if (torrent != null) {
try {
sb.append(torrent.getHashWrapper().toBase32String());
sb.append(';');
sb.append(fileInfo.getIndex());
sb.append('\n');
onlyDMs = false;
} catch (TOTorrentException e) {
}
}
}
}
eventData = (onlyDMs ? "DownloadManager\n" : "DiskManagerFileInfo\n") + sb.toString();
}
@Override
public void dragSetData(DragSourceEvent event) {
// System.out.println("DragSetData");
event.data = eventData;
}
});
}
dropTarget = tv.createDropTarget(DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
if (dropTarget != null) {
dropTarget.setTransfer(new Transfer[] { FixedHTMLTransfer.getInstance(), FixedURLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
dropTarget.addDropListener(new DropTargetAdapter() {
Point enterPoint = null;
@Override
public void dropAccept(DropTargetEvent event) {
event.currentDataType = FixedURLTransfer.pickBestType(event.dataTypes, event.currentDataType);
}
@Override
public void dragEnter(DropTargetEvent event) {
// if ours
if (drag_drop_line_start < 0) {
if (event.detail != DND.DROP_COPY) {
if ((event.operations & DND.DROP_LINK) > 0)
event.detail = DND.DROP_LINK;
else if ((event.operations & DND.DROP_COPY) > 0)
event.detail = DND.DROP_COPY;
}
} else if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
event.detail = tv.getTableRowWithCursor() == null ? DND.DROP_NONE : DND.DROP_MOVE;
event.feedback = DND.FEEDBACK_SCROLL;
enterPoint = new Point(event.x, event.y);
}
}
// @see org.eclipse.swt.dnd.DropTargetAdapter#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
@Override
public void dragLeave(DropTargetEvent event) {
super.dragLeave(event);
tv.getComposite().redraw();
}
@Override
public void dragOver(DropTargetEvent event) {
if (drag_drop_line_start >= 0) {
if (drag_drop_rows.length > 0 && !(drag_drop_rows[0].getDataSource(true) instanceof DownloadManager)) {
event.detail = DND.DROP_NONE;
return;
}
TableRowCore row = tv.getTableRowWithCursor();
if (row instanceof TableRowPainted) {
boolean dragging_down = row.getIndex() > drag_drop_line_start;
Rectangle bounds = ((TableRowPainted) row).getBounds();
tv.getComposite().redraw();
tv.getComposite().update();
GC gc = new GC(tv.getComposite());
gc.setLineWidth(2);
int y_pos = bounds.y;
if (dragging_down) {
y_pos += bounds.height;
}
gc.drawLine(bounds.x, y_pos, bounds.x + bounds.width, y_pos);
gc.dispose();
}
event.detail = row == null ? DND.DROP_NONE : DND.DROP_MOVE;
event.feedback = DND.FEEDBACK_SCROLL | ((enterPoint != null && enterPoint.y > event.y) ? DND.FEEDBACK_INSERT_BEFORE : DND.FEEDBACK_INSERT_AFTER);
}
}
@Override
public void drop(DropTargetEvent event) {
if (!(event.data instanceof String)) {
TorrentOpener.openDroppedTorrents(event, true);
return;
}
String data = (String) event.data;
if (data.startsWith("DiskManagerFileInfo\n")) {
return;
}
if (!data.startsWith("DownloadManager\n")) {
TorrentOpener.openDroppedTorrents(event, true);
return;
}
event.detail = DND.DROP_NONE;
// Torrent file from shell dropped
if (drag_drop_line_start >= 0) {
// event.data == null
event.detail = DND.DROP_NONE;
TableRowCore row = tv.getRow(event);
if (row == null)
return;
if (row.getParentRowCore() != null) {
row = row.getParentRowCore();
}
int drag_drop_line_end = row.getIndex();
if (drag_drop_line_end != drag_drop_line_start) {
DownloadManager dm = (DownloadManager) row.getDataSource(true);
moveRowsTo(drag_drop_rows, dm.getPosition());
event.detail = DND.DROP_MOVE;
}
drag_drop_line_start = -1;
drag_drop_rows = null;
}
}
});
}
} catch (Throwable t) {
Logger.log(new LogEvent(LOGID, "failed to init drag-n-drop", t));
}
}
use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class TorrentUIUtilsV3 method getContentImage.
/**
* Retrieves the thumbnail for the content, pulling it from the web if
* it can
*
* @param datasource
* @param l When the thumbnail is available, this listener is triggered
* @return If the image is immediately available, the image will be returned
* as well as the trigger being fired. If the image isn't available
* null will be returned and the listener will trigger when avail
*
* @since 4.0.0.5
*/
public static Image[] getContentImage(Object datasource, boolean big, final ContentImageLoadedListener l) {
if (l == null) {
return null;
}
TOTorrent torrent = DataSourceUtils.getTorrent(datasource);
if (torrent == null) {
l.contentImageLoaded(null, true);
return null;
}
if (imageLoaderThumb == null) {
imageLoaderThumb = new ImageLoader(null, null);
}
String thumbnailUrl = PlatformTorrentUtils.getContentThumbnailUrl(torrent);
// System.out.println("thumburl= " + thumbnailUrl);
if (thumbnailUrl != null && imageLoaderThumb.imageExists(thumbnailUrl)) {
// System.out.println("return thumburl");
Image image = imageLoaderThumb.getImage(thumbnailUrl);
l.contentImageLoaded(image, true);
return new Image[] { image };
}
String hash = null;
try {
hash = torrent.getHashWrapper().toBase32String();
} catch (TOTorrentException e) {
}
if (hash == null) {
l.contentImageLoaded(null, true);
return null;
}
int thumbnailVersion = PlatformTorrentUtils.getContentVersion(torrent);
// add torrent size here to differentiate meta-data downloads from actuals
final String id = "Thumbnail." + hash + "." + torrent.getSize() + "." + thumbnailVersion;
Image image = imageLoaderThumb.imageAdded(id) ? imageLoaderThumb.getImage(id) : null;
// System.out.println("image = " + image);
if (image != null && !image.isDisposed()) {
l.contentImageLoaded(image, true);
return new Image[] { image };
}
final byte[] imageBytes = PlatformTorrentUtils.getContentThumbnail(torrent);
// System.out.println("imageBytes = " + imageBytes);
if (imageBytes != null) {
image = (Image) Utils.execSWTThreadWithObject("thumbcreator", new AERunnableObject() {
@Override
public Object runSupport() {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
Image image = new Image(Display.getDefault(), bis);
return image;
} catch (Throwable e) {
return (null);
}
}
}, 500);
}
/**
* if ((image == null || image.isDisposed()) && thumbnailUrl != null) {
* //System.out.println("get image from " + thumbnailUrl);
* image = imageLoader.getUrlImage(thumbnailUrl,
* new ImageDownloaderListener() {
* public void imageDownloaded(Image image, boolean returnedImmediately) {
* l.contentImageLoaded(image, returnedImmediately);
* //System.out.println("got image from thumburl");
* }
* });
* //System.out.println("returning " + image + " (url loading)");
* return image == null ? null : new Image[] { image };
* }
*/
if (image == null || image.isDisposed()) {
// System.out.println("build image from files");
DownloadManager dm = DataSourceUtils.getDM(datasource);
/*
* Try to get an image from the OS
*/
String path = null;
if (dm == null) {
TOTorrentFile[] files = torrent.getFiles();
if (files.length > 0) {
path = files[0].getRelativePath();
}
} else {
DiskManagerFileInfo primaryFile = dm.getDownloadState().getPrimaryFile();
path = primaryFile == null ? null : primaryFile.getFile(true).getName();
}
if (path != null) {
image = ImageRepository.getPathIcon(path, big, false);
if (image != null && !torrent.isSimpleTorrent()) {
Image[] images = new Image[] { image, ImageRepository.getPathIcon(new File(path).getParent(), false, false) };
return images;
}
}
if (image == null) {
imageLoaderThumb.addImageNoDipose(id, ImageLoader.noImage);
} else {
imageLoaderThumb.addImageNoDipose(id, image);
}
} else {
// System.out.println("has mystery image");
imageLoaderThumb.addImage(id, image);
}
l.contentImageLoaded(image, true);
return new Image[] { image };
}
use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class TorrentUIUtilsV3 method releaseContentImage.
public static void releaseContentImage(Object datasource) {
if (imageLoaderThumb == null) {
return;
}
TOTorrent torrent = DataSourceUtils.getTorrent(datasource);
if (torrent == null) {
return;
}
String thumbnailUrl = PlatformTorrentUtils.getContentThumbnailUrl(torrent);
if (thumbnailUrl != null) {
imageLoaderThumb.releaseImage(thumbnailUrl);
} else {
String hash = null;
try {
hash = torrent.getHashWrapper().toBase32String();
} catch (TOTorrentException e) {
}
if (hash == null) {
return;
}
String id = "Thumbnail." + hash + "." + torrent.getSize();
imageLoaderThumb.releaseImage(id);
}
}
use of com.biglybt.core.torrent.TOTorrentException in project BiglyBT by BiglySoftware.
the class ActivitiesEntry method toMap.
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<>();
map.put("timestamp", new Long(timestamp));
if (assetHash != null) {
map.put("assetHash", assetHash);
}
map.put("icon", getIconID());
map.put("id", id);
map.put("text", getText());
map.put("typeID", getTypeID());
map.put("assetImageURL", assetImageURL);
map.put("showThumb", new Long(getShowThumb() ? 1 : 0));
if (imageBytes != null) {
map.put("imageBytes", imageBytes);
} else if (dm != null) {
byte[] thumbnail = PlatformTorrentUtils.getContentThumbnail(dm.getTorrent());
if (thumbnail != null) {
map.put("imageBytes", thumbnail);
}
}
if (torrent != null && (dm == null || assetHash == null)) {
try {
// make a copy of the torrent
Map torrent_map = torrent.serialiseToMap();
TOTorrent torrent_to_send = TOTorrentFactory.deserialiseFromMap(torrent_map);
Map<?, ?> vuze_map = (Map<?, ?>) torrent_map.get("vuze");
// remove any non-standard stuff (e.g. resume data)
torrent_to_send.removeAdditionalProperties();
torrent_map = torrent_to_send.serialiseToMap();
if (vuze_map != null) {
torrent_map.put("vuze", vuze_map);
}
map.put("torrent", torrent_map);
} catch (TOTorrentException e) {
Debug.outNoStack("VuzeActivityEntry.toMap: " + e.toString());
}
}
if (torrentName != null) {
map.put("torrent-name", torrentName);
}
if (playable) {
map.put("playable", new Long(playable ? 1 : 0));
}
map.put("readOn", new Long(readOn));
if (actions != null && actions.length > 0) {
List<String> list = Arrays.asList(actions);
map.put("actions", list);
}
if (callback_class != null) {
map.put("cb_class", callback_class);
}
if (callback_data != null) {
map.put("cb_data", callback_data);
}
map.put("viewed", viewed ? 1 : 0);
return map;
}
Aggregations