Search in sources :

Example 31 with UserPrompterResultListener

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.
}
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)

Example 32 with UserPrompterResultListener

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();
    }
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener)

Aggregations

UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)32 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)25 GridLayout (org.eclipse.swt.layout.GridLayout)6 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)5 ArrayList (java.util.ArrayList)5 GridData (org.eclipse.swt.layout.GridData)5 SWTSkin (com.biglybt.ui.swt.skin.SWTSkin)4 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)4 List (java.util.List)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Composite (org.eclipse.swt.widgets.Composite)4 AERunnable (com.biglybt.core.util.AERunnable)3 UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)3 UIManagerEvent (com.biglybt.pif.ui.UIManagerEvent)3 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)3 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)3 VuzeMessageBox (com.biglybt.ui.swt.views.skin.VuzeMessageBox)3 VuzeMessageBoxListener (com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener)3 File (java.io.File)3