use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class TorrentInfoView method initialize.
private void initialize(Composite composite) {
this.parent = composite;
if (download_manager == null) {
return;
}
// I don't want to waste my time :) [tux]
if (sc != null && !sc.isDisposed()) {
sc.dispose();
}
sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
sc.getVerticalBar().setIncrement(16);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
Utils.setLayoutData(sc, gridData);
outer_panel = sc;
Composite panel = new Composite(sc, SWT.NULL);
sc.setContent(panel);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 1;
panel.setLayout(layout);
// int userMode = COConfigurationManager.getIntParameter("User Mode");
// header
Composite cHeader = new Composite(panel, SWT.BORDER);
GridLayout configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
cHeader.setLayout(configLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
Utils.setLayoutData(cHeader, gridData);
Display d = panel.getDisplay();
cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
Label lHeader = new Label(cHeader, SWT.NULL);
lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
FontData[] fontData = lHeader.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
int fontHeight = (int) (fontData[0].getHeight() * 1.2);
fontData[0].setHeight(fontHeight);
headerFont = new Font(d, fontData);
lHeader.setFont(headerFont);
lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
Utils.setLayoutData(lHeader, gridData);
Composite gTorrentInfo = new Composite(panel, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
Utils.setLayoutData(gTorrentInfo, gridData);
layout = new GridLayout();
layout.numColumns = 2;
gTorrentInfo.setLayout(layout);
// torrent encoding
Label label = new Label(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(label, gridData);
label.setText(MessageText.getString("TorrentInfoView.torrent.encoding") + ": ");
TOTorrent torrent = download_manager.getTorrent();
BufferedLabel blabel = new BufferedLabel(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(blabel, gridData);
blabel.setText(torrent == null ? "" : LocaleTorrentUtil.getCurrentTorrentEncoding(torrent));
// trackers
label = new Label(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(label, gridData);
label.setText(MessageText.getString("label.tracker") + ": ");
String trackers = "";
if (torrent != null) {
TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
List<String> tracker_list = new ArrayList<>();
URL url = torrent.getAnnounceURL();
tracker_list.add(url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort())));
for (int i = 0; i < sets.length; i++) {
TOTorrentAnnounceURLSet set = sets[i];
URL[] urls = set.getAnnounceURLs();
for (int j = 0; j < urls.length; j++) {
url = urls[j];
String str = url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort()));
if (!tracker_list.contains(str)) {
tracker_list.add(str);
}
}
}
TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
URL active_url = null;
if (announcer != null) {
active_url = announcer.getTrackerURL();
} else {
TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
if (scrape != null) {
active_url = scrape.getURL();
}
}
if (active_url == null) {
active_url = torrent.getAnnounceURL();
}
trackers = active_url.getHost() + (active_url.getPort() == -1 ? "" : (":" + active_url.getPort()));
tracker_list.remove(trackers);
if (tracker_list.size() > 0) {
trackers += " (";
for (int i = 0; i < tracker_list.size(); i++) {
trackers += (i == 0 ? "" : ", ") + tracker_list.get(i);
}
trackers += ")";
}
}
blabel = new BufferedLabel(gTorrentInfo, SWT.WRAP);
Utils.setLayoutData(blabel, Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL));
blabel.setText(trackers);
// columns
Group gColumns = new Group(panel, SWT.NULL);
Messages.setLanguageText(gColumns, "TorrentInfoView.columns");
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(gColumns, gridData);
layout = new GridLayout();
layout.numColumns = 4;
gColumns.setLayout(layout);
Map<String, FakeTableCell> usable_cols = new HashMap<>();
TableColumnManager col_man = TableColumnManager.getInstance();
TableColumnCore[][] cols_sets = { col_man.getAllTableColumnCoreAsArray(DownloadTypeIncomplete.class, TableManager.TABLE_MYTORRENTS_INCOMPLETE), col_man.getAllTableColumnCoreAsArray(DownloadTypeComplete.class, TableManager.TABLE_MYTORRENTS_COMPLETE) };
for (int i = 0; i < cols_sets.length; i++) {
TableColumnCore[] cols = cols_sets[i];
for (int j = 0; j < cols.length; j++) {
TableColumnCore col = cols[j];
String id = col.getName();
if (usable_cols.containsKey(id)) {
continue;
}
FakeTableCell fakeTableCell = null;
try {
fakeTableCell = new FakeTableCell(col, download_manager);
fakeTableCell.setOrentation(SWT.LEFT);
fakeTableCell.setWrapText(false);
col.invokeCellAddedListeners(fakeTableCell);
// One refresh to see if it throws up
fakeTableCell.refresh();
usable_cols.put(id, fakeTableCell);
} catch (Throwable t) {
// System.out.println("not usable col: " + id + " - " + Debug.getCompressedStackTrace());
try {
if (fakeTableCell != null) {
fakeTableCell.dispose();
}
} catch (Throwable t2) {
// ignore;
}
}
}
}
Collection<FakeTableCell> values = usable_cols.values();
cells = new FakeTableCell[values.size()];
values.toArray(cells);
Arrays.sort(cells, new Comparator<FakeTableCell>() {
@Override
public int compare(FakeTableCell o1, FakeTableCell o2) {
TableColumnCore c1 = (TableColumnCore) o1.getTableColumn();
TableColumnCore c2 = (TableColumnCore) o2.getTableColumn();
String key1 = MessageText.getString(c1.getTitleLanguageKey());
String key2 = MessageText.getString(c2.getTitleLanguageKey());
return key1.compareToIgnoreCase(key2);
}
});
for (int i = 0; i < cells.length; i++) {
final FakeTableCell cell = cells[i];
label = new Label(gColumns, SWT.NULL);
gridData = new GridData();
if (i % 2 == 1) {
gridData.horizontalIndent = 16;
}
Utils.setLayoutData(label, gridData);
String key = ((TableColumnCore) cell.getTableColumn()).getTitleLanguageKey();
label.setText(MessageText.getString(key) + ": ");
label.setToolTipText(MessageText.getString(key + ".info", ""));
final Composite c = new Composite(gColumns, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 16;
Utils.setLayoutData(c, gridData);
cell.setControl(c);
cell.invalidate();
cell.refresh();
c.addListener(SWT.MouseHover, new Listener() {
@Override
public void handleEvent(Event event) {
Object toolTip = cell.getToolTip();
if (toolTip instanceof String) {
String s = (String) toolTip;
c.setToolTipText(s);
}
}
});
}
refresh();
sc.setMinSize(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class TrackerView method fillMenu.
@Override
public void fillMenu(String sColumnName, Menu menu) {
final Object[] sources = tv.getSelectedDataSources().toArray();
boolean found_tracker = false;
boolean found_dht_tracker = false;
boolean update_ok = false;
boolean delete_ok = false;
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.getType() == TrackerPeerSource.TP_TRACKER) {
found_tracker = true;
}
if (ps.getType() == TrackerPeerSource.TP_DHT) {
found_dht_tracker = true;
}
int state = ps.getStatus();
if ((state == TrackerPeerSource.ST_ONLINE || state == TrackerPeerSource.ST_QUEUED || state == TrackerPeerSource.ST_ERROR) && !ps.isUpdating() && ps.canManuallyUpdate()) {
update_ok = true;
}
if (ps.canDelete()) {
delete_ok = true;
}
}
boolean needs_sep = false;
if (found_tracker || found_dht_tracker) {
final MenuItem update_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(update_item, "GeneralView.label.trackerurlupdate");
update_item.setEnabled(update_ok);
update_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public void run(TableRowCore row) {
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.canManuallyUpdate()) {
ps.manualUpdate();
}
}
}
});
if (found_tracker) {
final MenuItem edit_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(edit_item, "MyTorrentsView.menu.editTracker");
edit_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public boolean run(TableRowCore[] rows) {
final TOTorrent torrent = manager.getTorrent();
if (torrent != null) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
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);
}
});
}
return (true);
}
});
TOTorrent torrent = manager.getTorrent();
edit_item.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
}
needs_sep = true;
}
if (delete_ok) {
final MenuItem delete_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(delete_item, "Button.remove");
Utils.setMenuItemImage(delete_item, "delete");
delete_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public void run(TableRowCore row) {
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.canDelete()) {
ps.delete();
}
}
}
});
needs_sep = true;
}
if (needs_sep) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
use of com.biglybt.core.torrent.TOTorrent 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.TOTorrent in project BiglyBT by BiglySoftware.
the class MyTorrentsView method filterCheck.
@Override
public boolean filterCheck(DownloadManager dm, String sLastSearch, boolean bRegexSearch) {
if (dm == null) {
return (false);
}
boolean bOurs;
if (sLastSearch.length() > 0) {
try {
String comment = dm.getDownloadState().getUserComment();
if (comment == null) {
comment = "";
}
String[][] name_mapping = { { "", dm.getDisplayName() }, { "t:", // defer (index = 1)this as costly dm.getTorrent().getAnnounceURL().getHost()
"" }, { "st:", "" + dm.getState() }, { "c:", comment }, { "f:", // defer (index = 4)
"" }, { "tag:", "" } };
Object o_name = name_mapping[0][1];
String tmpSearch = sLastSearch;
for (int i = 1; i < name_mapping.length; i++) {
if (tmpSearch.startsWith(name_mapping[i][0])) {
tmpSearch = tmpSearch.substring(name_mapping[i][0].length());
if (i == 1) {
List<String> names = new ArrayList<>();
o_name = names;
TOTorrent t = dm.getTorrent();
if (t != null) {
names.add(t.getAnnounceURL().getHost());
TOTorrentAnnounceURLSet[] sets = t.getAnnounceURLGroup().getAnnounceURLSets();
for (TOTorrentAnnounceURLSet set : sets) {
URL[] urls = set.getAnnounceURLs();
for (URL u : urls) {
names.add(u.getHost());
}
}
try {
byte[] hash = t.getHash();
names.add(ByteFormatter.encodeString(hash));
names.add(Base32.encode(hash));
} catch (Throwable e) {
}
}
} else if (i == 4) {
List<String> names = new ArrayList<>();
o_name = names;
DiskManagerFileInfoSet file_set = dm.getDiskManagerFileInfoSet();
DiskManagerFileInfo[] files = file_set.getFiles();
for (DiskManagerFileInfo f : files) {
File file = f.getFile(true);
String name = tmpSearch.contains(File.separator) ? file.getAbsolutePath() : file.getName();
names.add(name);
}
} else if (i == 5) {
List<String> names = new ArrayList<String>();
o_name = names;
TagManager tagManager = TagManagerFactory.getTagManager();
List<Tag> tags = tagManager.getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, dm);
if (tags.size() > 0) {
tags = TagUIUtils.sortTags(tags);
for (Tag t : tags) {
String str = t.getTagName(true);
names.add(str);
}
}
} else {
o_name = name_mapping[i][1];
}
}
}
String s = bRegexSearch ? tmpSearch : "\\Q" + tmpSearch.replaceAll("[|;]", "\\\\E|\\\\Q") + "\\E";
boolean match_result = true;
if (bRegexSearch && s.startsWith("!")) {
s = s.substring(1);
match_result = false;
}
Pattern pattern = RegExUtil.getCachedPattern("tv:search", s, Pattern.CASE_INSENSITIVE);
if (o_name instanceof String) {
bOurs = pattern.matcher((String) o_name).find() == match_result;
} else {
List<String> names = (List<String>) o_name;
// match_result: true -> at least one match; false -> any fail
bOurs = !match_result;
for (String name : names) {
if (pattern.matcher(name).find()) {
bOurs = match_result;
break;
}
}
}
} catch (Exception e) {
// Future: report PatternSyntaxException message to user.
bOurs = true;
}
} else {
bOurs = true;
}
return bOurs;
}
use of com.biglybt.core.torrent.TOTorrent 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 };
}
Aggregations