Search in sources :

Example 11 with SWTSkin

use of com.biglybt.ui.swt.skin.SWTSkin 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.
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Image(org.eclipse.swt.graphics.Image) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormData(org.eclipse.swt.layout.FormData) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) TOTorrent(com.biglybt.core.torrent.TOTorrent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HashMap(java.util.HashMap) Map(java.util.Map) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SWTSkin (com.biglybt.ui.swt.skin.SWTSkin)11 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)8 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)4 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)4 VuzeMessageBox (com.biglybt.ui.swt.views.skin.VuzeMessageBox)4 VuzeMessageBoxListener (com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener)4 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3 SWTSkinObjectText (com.biglybt.ui.swt.skin.SWTSkinObjectText)3 SkinnedDialogClosedListener (com.biglybt.ui.swt.views.skin.SkinnedDialog.SkinnedDialogClosedListener)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 SkinnedDialog (com.biglybt.ui.swt.views.skin.SkinnedDialog)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 FormData (org.eclipse.swt.layout.FormData)2 RowLayout (org.eclipse.swt.layout.RowLayout)2 Shell (org.eclipse.swt.widgets.Shell)2 Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 DeviceManufacturer (com.biglybt.core.devices.DeviceManager.DeviceManufacturer)1