use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.
the class TorrentListViewsUtils method _playOrStream.
private static void _playOrStream(final DownloadManager dm, final int file_index, final boolean complete_only, final String referal) {
if (dm == null) {
return;
}
// if (!canPlay(dm)) {
// return false;
// }
final TOTorrent torrent = dm.getTorrent();
if (torrent == null) {
return;
}
if (file_index == -1) {
final int[] playableFileIndexes = PlayUtils.getExternallyPlayableFileIndexes(PluginCoreUtils.wrap(dm), complete_only);
if (playableFileIndexes.length == 1) {
int open_result = openInEMP(dm, file_index, complete_only, referal);
if (open_result == 0) {
PlatformTorrentUtils.setHasBeenOpened(dm, true);
}
} else if (playableFileIndexes.length > 1) {
VuzeMessageBox mb = new VuzeMessageBox(MessageText.getString("ConfigView.option.dm.dblclick.play"), null, new String[] { MessageText.getString("iconBar.play"), MessageText.getString("Button.cancel") }, 0);
final Map<Integer, Integer> mapPositionToFileInfo = new HashMap<>();
final int[] selectedIndex = { // default selection is first entry
0 };
mb.setSubTitle(MessageText.getString("play.select.content"));
mb.setListener(new VuzeMessageBoxListener() {
@Override
public void shellReady(Shell shell, SWTSkinObjectContainer soExtra) {
SWTSkin skin = soExtra.getSkin();
Composite composite = soExtra.getComposite();
final Table table = new Table(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE);
table.setBackground(composite.getBackground());
table.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
selectedIndex[0] = table.getSelectionIndex();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
FormData formData = Utils.getFilledFormData();
formData.bottom.offset = -20;
Utils.setLayoutData(table, formData);
table.setHeaderVisible(false);
table.addListener(SWT.MeasureItem, new Listener() {
@Override
public void handleEvent(Event event) {
int w = table.getClientArea().width - 5;
if (w == 0) {
return;
}
if (event.width < w) {
event.width = w;
}
}
});
String prefix = dm.getSaveLocation().toString();
int i = 0;
DiskManagerFileInfo[] fileInfos = dm.getDiskManagerFileInfoSet().getFiles();
for (int fileIndex : playableFileIndexes) {
if (fileIndex < 0 || fileIndex >= fileInfos.length) {
continue;
}
File f = fileInfos[fileIndex].getFile(true);
String path = f.getParent();
if (path.startsWith(prefix)) {
path = path.length() > prefix.length() ? path.substring(prefix.length() + 1) : "";
}
String s = f.getName();
if (path.length() > 0) {
s += " in " + path;
}
TableItem item = new TableItem(table, SWT.NONE);
item.setText(s);
mapPositionToFileInfo.put(i++, fileIndex);
}
Image alphaImage = Utils.createAlphaImage(table.getDisplay(), 1, 25, (byte) 255);
TableItem item = table.getItem(0);
item.setImage(alphaImage);
item.setImage((Image) null);
alphaImage.dispose();
table.setSelection(0);
}
});
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result != 0 || selectedIndex[0] < 0) {
return;
}
Integer file_index = mapPositionToFileInfo.get(selectedIndex[0]);
if (file_index != null) {
int open_result = openInEMP(dm, file_index, complete_only, referal);
if (open_result == 0) {
PlatformTorrentUtils.setHasBeenOpened(dm, file_index, true);
}
}
}
});
}
return;
}
if (PlayUtils.canUseEMP(torrent, file_index, complete_only)) {
debug("Can use EMP");
int open_result = openInEMP(dm, file_index, complete_only, referal);
if (open_result == 0) {
PlatformTorrentUtils.setHasBeenOpened(dm, file_index, true);
return;
} else if (open_result == 2) {
debug("Open in EMP abandoned");
return;
} else {
debug("Open EMP Failed");
}
// fallback to normal
} else {
debug("Can't use EMP.");
}
// We used to pop up a dialog saying we didn't know how to play the file
// But now the play toolbar and play 'default' action aren't even enabled
// if we can't use EMP. So there's no point.
}
use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.
the class VuzeMessageBox method skinDialogClosed.
/* (non-Javadoc)
* @see SkinnedDialog.SkinnedDialogClosedListener#skinDialogClosed(SkinnedDialog)
*/
@Override
public void skinDialogClosed(SkinnedDialog dialog) {
synchronized (resultListeners) {
int realResult = buttonsArea.getButtonVal(result);
for (UserPrompterResultListener l : resultListeners) {
try {
l.prompterClosed(realResult);
} catch (Exception e) {
Debug.out(e);
}
}
resultListeners.clear();
}
}
Aggregations