Search in sources :

Example 11 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class ToolBarView method moveBottom.

protected boolean moveBottom() {
    if (!CoreFactory.isCoreRunning()) {
        return false;
    }
    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
    DownloadManager[] dms = SelectedContentManager.getDMSFromSelectedContent();
    if (dms != null) {
        gm.moveEnd(dms);
    }
    return true;
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 12 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class FileInfoView method getPieceNumber.

private int getPieceNumber(int x, int y) {
    Rectangle bounds = fileInfoCanvas.getClientArea();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return (-1);
    }
    if (file == null) {
        return (-1);
    }
    DownloadManager download_manager = file.getDownloadManager();
    if (download_manager == null) {
        return (-1);
    }
    DiskManager disk_manager = download_manager.getDiskManager();
    PEPeerManager peer_manager = download_manager.getPeerManager();
    if (disk_manager == null || peer_manager == null) {
        return (-1);
    }
    int first_piece = file.getFirstPieceNumber();
    int num_pieces = file.getNbPieces();
    int iNumCols = bounds.width / BLOCK_SIZE;
    int x_block = x / BLOCK_SIZE;
    int y_block = y / BLOCK_SIZE;
    int piece_number = y_block * iNumCols + x_block + first_piece;
    if (piece_number >= first_piece && piece_number < first_piece + num_pieces) {
        return (piece_number);
    } else {
        return (-1);
    }
}
Also used : PEPeerManager(com.biglybt.core.peer.PEPeerManager) DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 13 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class FileInfoView method showPieceDetails.

protected void showPieceDetails(int x, int y) {
    int piece_number = getPieceNumber(x, y);
    if (piece_number >= 0) {
        DownloadManager download_manager = file.getDownloadManager();
        if (download_manager == null) {
            topLabel.setText("");
            return;
        }
        DiskManager disk_manager = download_manager.getDiskManager();
        PEPeerManager peer_manager = download_manager.getPeerManager();
        if (disk_manager == null || peer_manager == null) {
            topLabel.setText("");
            return;
        }
        DiskManagerPiece[] dm_pieces = disk_manager.getPieces();
        PEPiece[] pe_pieces = peer_manager.getPieces();
        DiskManagerPiece dm_piece = dm_pieces[piece_number];
        PEPiece pe_piece = pe_pieces[piece_number];
        String text = "Piece " + piece_number + ": " + dm_piece.getString();
        if (pe_piece != null) {
            text += ", active: " + pe_piece.getString();
        } else {
            if (dm_piece.isNeeded() && !dm_piece.isDone()) {
                text += ", inactive: " + peer_manager.getPiecePicker().getPieceString(piece_number);
            }
        }
        topLabel.setText(text);
    } else {
        topLabel.setText("");
    }
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DiskManagerPiece(com.biglybt.core.disk.DiskManagerPiece) DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 14 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class PieceInfoView method createPeerInfoPanel.

private void createPeerInfoPanel(Composite parent) {
    GridLayout layout;
    GridData gridData;
    // Peer Info section contains
    // - Peer's Block display
    // - Peer's Datarate
    pieceInfoComposite = new Composite(parent, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    pieceInfoComposite.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    pieceInfoComposite.setLayoutData(gridData);
    imageLabel = new Label(pieceInfoComposite, SWT.NULL);
    gridData = new GridData();
    imageLabel.setLayoutData(gridData);
    topLabel = new Label(pieceInfoComposite, SWT.NULL);
    topLabel.setBackground(Colors.white);
    gridData = new GridData(SWT.FILL, SWT.DEFAULT, false, false);
    topLabel.setLayoutData(gridData);
    sc = new ScrolledComposite(pieceInfoComposite, SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    layout = new GridLayout();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    sc.setLayout(layout);
    gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
    sc.setLayoutData(gridData);
    sc.getVerticalBar().setIncrement(BLOCK_SIZE);
    pieceInfoCanvas = new Canvas(sc, SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL, SWT.DEFAULT, true, false);
    pieceInfoCanvas.setLayoutData(gridData);
    pieceInfoCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (e.width <= 0 || e.height <= 0)
                return;
            try {
                Rectangle bounds = (img == null) ? null : img.getBounds();
                if (bounds == null || dlm == null || dlm.getPeerManager() == null) {
                    e.gc.fillRectangle(e.x, e.y, e.width, e.height);
                } else {
                    if (e.x + e.width > bounds.width)
                        e.gc.fillRectangle(bounds.width, e.y, e.x + e.width - bounds.width + 1, e.height);
                    if (e.y + e.height > bounds.height)
                        e.gc.fillRectangle(e.x, bounds.height, e.width, e.y + e.height - bounds.height + 1);
                    int width = Math.min(e.width, bounds.width - e.x);
                    int height = Math.min(e.height, bounds.height - e.y);
                    e.gc.drawImage(img, e.x, e.y, width, height, e.x, e.y, width, height);
                }
            } catch (Exception ex) {
            }
        }
    });
    pieceInfoCanvas.addListener(SWT.KeyDown, new DoNothingListener());
    pieceInfoCanvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            synchronized (PieceInfoView.this) {
                if (alreadyFilling) {
                    return;
                }
                alreadyFilling = true;
            }
            // wrap in asyncexec because sc.setMinWidth (called later) doesn't work
            // too well inside a resize (the canvas won't size isn't always updated)
            Utils.execSWTThreadLater(0, new AERunnable() {

                @Override
                public void runSupport() {
                    if (img != null) {
                        int iOldColCount = img.getBounds().width / BLOCK_SIZE;
                        int iNewColCount = pieceInfoCanvas.getClientArea().width / BLOCK_SIZE;
                        if (iOldColCount != iNewColCount)
                            refreshInfoCanvas();
                    }
                    synchronized (PieceInfoView.this) {
                        alreadyFilling = false;
                    }
                }
            });
        }
    });
    sc.setContent(pieceInfoCanvas);
    pieceInfoCanvas.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent event) {
            int piece_number = getPieceNumber(event.x, event.y);
            if (piece_number != selectedPiece) {
                selectedPieceShowFilePending = -1;
            }
        }
    });
    pieceInfoCanvas.addMouseTrackListener(new MouseTrackAdapter() {

        @Override
        public void mouseHover(MouseEvent event) {
            int piece_number = getPieceNumber(event.x, event.y);
            if (piece_number >= 0) {
                selectedPiece = piece_number;
                selectedPieceShowFilePending = piece_number;
                SimpleTimer.addEvent("ShowFile", SystemTime.getOffsetTime(1000), new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent event) {
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                if (selectedPieceShowFilePending == piece_number) {
                                    selectedPieceShowFile = true;
                                    refreshInfoCanvas();
                                }
                            }
                        });
                    }
                });
                refreshInfoCanvas();
                DiskManager disk_manager = dlm.getDiskManager();
                PEPeerManager pm = dlm.getPeerManager();
                DiskManagerPiece dm_piece = disk_manager.getPiece(piece_number);
                PEPiece pm_piece = pm.getPiece(piece_number);
                String text = "Piece " + piece_number + ": " + dm_piece.getString();
                if (pm_piece != null) {
                    text += ", active: " + pm_piece.getString();
                } else {
                    if (dm_piece.isNeeded() && !dm_piece.isDone()) {
                        text += ", inactive: " + pm.getPiecePicker().getPieceString(piece_number);
                    }
                }
                text += " - ";
                DMPieceList l = disk_manager.getPieceList(piece_number);
                for (int i = 0; i < l.size(); i++) {
                    DMPieceMapEntry entry = l.get(i);
                    DiskManagerFileInfo info = entry.getFile();
                    text += (i == 0 ? "" : "; ") + info.getFile(true).getName();
                }
                topLabelRHS = text;
            } else {
                topLabelRHS = "";
            }
            updateTopLabel();
        }

        @Override
        public void mouseExit(MouseEvent e) {
            selectedPiece = -1;
            selectedPieceShowFile = false;
            refreshInfoCanvas();
        }
    });
    final Menu menu = new Menu(pieceInfoCanvas.getShell(), SWT.POP_UP);
    pieceInfoCanvas.setMenu(menu);
    pieceInfoCanvas.addListener(SWT.MenuDetect, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Point pt = pieceInfoCanvas.toControl(event.x, event.y);
            int piece_number = getPieceNumber(pt.x, pt.y);
            menu.setData("pieceNumber", piece_number);
        }
    });
    MenuBuildUtils.addMaintenanceListenerForMenu(menu, new MenuBuildUtils.MenuBuilder() {

        @Override
        public void buildMenu(Menu menu, MenuEvent event) {
            Integer pn = (Integer) menu.getData("pieceNumber");
            if (pn != null && pn != -1) {
                DownloadManager download_manager = dlm;
                if (download_manager == null) {
                    return;
                }
                DiskManager disk_manager = download_manager.getDiskManager();
                PEPeerManager peer_manager = download_manager.getPeerManager();
                if (disk_manager == null || peer_manager == null) {
                    return;
                }
                final PiecePicker picker = peer_manager.getPiecePicker();
                DiskManagerPiece[] dm_pieces = disk_manager.getPieces();
                PEPiece[] pe_pieces = peer_manager.getPieces();
                final int piece_number = pn;
                final DiskManagerPiece dm_piece = dm_pieces[piece_number];
                final PEPiece pm_piece = pe_pieces[piece_number];
                final MenuItem force_piece = new MenuItem(menu, SWT.CHECK);
                Messages.setLanguageText(force_piece, "label.force.piece");
                boolean done = dm_piece.isDone();
                force_piece.setEnabled(!done);
                if (!done) {
                    force_piece.setSelection(picker.isForcePiece(piece_number));
                    force_piece.addSelectionListener(new SelectionListenerForcePiece(picker, piece_number, force_piece));
                }
                final MenuItem reset_piece = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(reset_piece, "label.reset.piece");
                boolean can_reset = dm_piece.isDone() || dm_piece.getNbWritten() > 0;
                reset_piece.setEnabled(can_reset);
                reset_piece.addSelectionListener(new SelectionListenerResetPiece(dm_piece, pm_piece));
                new MenuItem(menu, SWT.SEPARATOR);
                final MenuItem seq_asc = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(seq_asc, "label.seq.asc.from", new String[] { String.valueOf(piece_number) });
                seq_asc.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        download_manager.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, false);
                        picker.setReverseBlockOrder(false);
                        picker.setSequentialAscendingFrom(piece_number);
                    }
                });
                final MenuItem seq_desc = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(seq_desc, "label.seq.desc.from", new String[] { String.valueOf(piece_number) });
                seq_desc.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        download_manager.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, false);
                        picker.setReverseBlockOrder(true);
                        picker.setSequentialDescendingFrom(piece_number);
                    }
                });
                final MenuItem seq_clear = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(seq_clear, "label.seq.clear", new String[] { String.valueOf(piece_number) });
                seq_clear.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        download_manager.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, false);
                        picker.setReverseBlockOrder(false);
                        picker.clearSequential();
                    }
                });
            }
        }
    });
    Legend.createLegendComposite(pieceInfoComposite, blockColors, new String[] { "PiecesView.BlockView.Have", "PiecesView.BlockView.NoHave", "PeersView.BlockView.Transfer", "PeersView.BlockView.NextRequest", "PeersView.BlockView.AvailCount", "PeersView.BlockView.ShowFile" }, new GridData(SWT.FILL, SWT.DEFAULT, true, false, 2, 1));
    int iFontPixelsHeight = 10;
    int iFontPointHeight = (iFontPixelsHeight * 72) / Utils.getDPIRaw(pieceInfoCanvas.getDisplay()).y;
    Font f = pieceInfoCanvas.getFont();
    FontData[] fontData = f.getFontData();
    fontData[0].setHeight(iFontPointHeight);
    font = new Font(pieceInfoCanvas.getDisplay(), fontData);
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) DownloadManagerPieceListener(com.biglybt.core.download.DownloadManagerPieceListener) PiecePicker(com.biglybt.core.peermanager.piecepicker.PiecePicker) DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager) GridLayout(org.eclipse.swt.layout.GridLayout) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TimerEvent(com.biglybt.core.util.TimerEvent) DiskManagerPiece(com.biglybt.core.disk.DiskManagerPiece) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DMPieceList(com.biglybt.core.disk.impl.piecemapper.DMPieceList) PEPiece(com.biglybt.core.peer.PEPiece) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) DMPieceMapEntry(com.biglybt.core.disk.impl.piecemapper.DMPieceMapEntry) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) LogEvent(com.biglybt.core.logging.LogEvent) TimerEvent(com.biglybt.core.util.TimerEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 15 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class SBC_LibraryTableView method doDefaultClick.

public static void doDefaultClick(final TableRowCore[] rows, final int stateMask, final boolean neverPlay, int origin) {
    if (rows == null || rows.length != 1) {
        return;
    }
    final Object ds = rows[0].getDataSource(true);
    boolean webInBrowser = COConfigurationManager.getBooleanParameter("Library.LaunchWebsiteInBrowser");
    if (webInBrowser) {
        DiskManagerFileInfo fileInfo = DataSourceUtils.getFileInfo(ds);
        if (fileInfo != null) {
            if (ManagerUtils.browseWebsite(fileInfo)) {
                return;
            }
        } else {
            DownloadManager dm = DataSourceUtils.getDM(ds);
            if (dm != null) {
                if (ManagerUtils.browseWebsite(dm)) {
                    return;
                }
            }
        }
    }
    String mode = COConfigurationManager.getStringParameter("list.dm.dblclick");
    if (origin == 1) {
        String enter_mode = COConfigurationManager.getStringParameter("list.dm.enteraction");
        if (!enter_mode.equals("-1")) {
            mode = enter_mode;
        }
    }
    if (mode.equals("1")) {
        if (UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, ds)) {
            return;
        }
    } else if (mode.equals("2")) {
        // Show in explorer
        boolean openMode = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
        DiskManagerFileInfo file = DataSourceUtils.getFileInfo(ds);
        if (file != null) {
            ManagerUtils.open(file, openMode);
            return;
        }
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            ManagerUtils.open(dm, openMode);
            return;
        }
    } else if (mode.equals("3") || mode.equals("4")) {
        // Launch
        DiskManagerFileInfo file = DataSourceUtils.getFileInfo(ds);
        if (file != null) {
            if (mode.equals("4") && file.getDownloaded() == file.getLength() && Utils.isQuickViewSupported(file)) {
                Utils.setQuickViewActive(file, true);
            } else {
                TorrentUtil.runDataSources(new Object[] { file });
            }
            return;
        }
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            TorrentUtil.runDataSources(new Object[] { dm });
            return;
        }
    } else if (mode.equals("5")) {
        DiskManagerFileInfo fileInfo = DataSourceUtils.getFileInfo(ds);
        if (fileInfo != null) {
            ManagerUtils.browse(fileInfo);
            return;
        }
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            ManagerUtils.browse(dm);
            return;
        }
    }
    if (neverPlay) {
        return;
    }
    if (PlayUtils.canPlayDS(ds, -1, true) || (stateMask & SWT.CONTROL) != 0) {
        TorrentListViewsUtils.playOrStreamDataSource(ds, DLReferals.DL_REFERAL_DBLCLICK, false, true);
        return;
    }
    if (PlayUtils.canStreamDS(ds, -1, true)) {
        TorrentListViewsUtils.playOrStreamDataSource(ds, DLReferals.DL_REFERAL_DBLCLICK, true, false);
        return;
    }
    DownloadManager dm = DataSourceUtils.getDM(ds);
    DiskManagerFileInfo file = DataSourceUtils.getFileInfo(ds);
    TOTorrent torrent = DataSourceUtils.getTorrent(ds);
    if (torrent == null && file != null) {
        DownloadManager dmFile = file.getDownloadManager();
        if (dmFile != null) {
            torrent = dmFile.getTorrent();
        }
    }
    if (file != null && file.getDownloaded() == file.getLength()) {
        TorrentUtil.runDataSources(new Object[] { file });
    } else if (dm != null) {
        TorrentUtil.runDataSources(new Object[] { dm });
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TOTorrent(com.biglybt.core.torrent.TOTorrent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)307 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)54 TOTorrent (com.biglybt.core.torrent.TOTorrent)35 GlobalManager (com.biglybt.core.global.GlobalManager)33 PEPeerManager (com.biglybt.core.peer.PEPeerManager)29 File (java.io.File)29 List (java.util.List)21 Core (com.biglybt.core.Core)17 Download (com.biglybt.pif.download.Download)17 Point (org.eclipse.swt.graphics.Point)17 UIFunctions (com.biglybt.ui.UIFunctions)16 Tag (com.biglybt.core.tag.Tag)15 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)14 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)13 ArrayList (java.util.ArrayList)13 DiskManager (com.biglybt.core.disk.DiskManager)12 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)12 CoreRunningListener (com.biglybt.core.CoreRunningListener)11 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)11 PEPeer (com.biglybt.core.peer.PEPeer)11