Search in sources :

Example 91 with DownloadManager

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

the class Priority method execute.

@Override
public void execute(String commandName, ConsoleInput console, CommandLine commandLine) {
    String tnumstr, fnumstr, newpriostr;
    int tnumber;
    DiskManagerFileInfo[] files;
    String[] sections;
    List args = commandLine.getArgList();
    LinkedList fs, fe;
    DownloadManager dm;
    if (args.isEmpty()) {
        console.out.println("Torrent # required!");
        return;
    } else {
        tnumstr = (String) args.remove(0);
    }
    if (args.isEmpty()) {
        console.out.println("File # required!");
        return;
    } else {
        fnumstr = (String) args.remove(0);
    }
    if ((console.torrents == null) || console.torrents.isEmpty()) {
        console.out.println("> Command 'prio': No torrents in list (try 'show torrents' first).");
        return;
    }
    try {
        tnumber = Integer.parseInt(tnumstr);
        if ((tnumber == 0) || (tnumber > console.torrents.size())) {
            console.out.println("> Command 'prio': Torrent #" + tnumber + " unknown.");
            return;
        }
        dm = (DownloadManager) console.torrents.get(tnumber - 1);
        files = dm.getDiskManagerFileInfo();
    } catch (Exception e) {
        e.printStackTrace();
        console.out.println("> Command 'prio': Torrent # '" + tnumstr + "' unknown.");
        return;
    }
    if (args.isEmpty()) {
        console.out.println("> Command 'prio': missing parameter for new priority");
        return;
    } else {
        newpriostr = (String) args.remove(0);
    }
    if (newpriostr.equalsIgnoreCase("normal")) {
        newprio = NORMAL;
    } else if (newpriostr.equalsIgnoreCase("high")) {
        newprio = HIGH;
    } else if (newpriostr.equalsIgnoreCase("dnd")) {
        newprio = DONOTDOWNLOAD;
    } else if (newpriostr.equalsIgnoreCase("del")) {
        newprio = DELETE;
    } else {
        console.out.println("> Command 'prio': unknown priority " + newpriostr);
        return;
    }
    if (fnumstr.equalsIgnoreCase("all")) {
        sections = new String[1];
        sections[0] = "1-" + files.length;
    } else
        sections = fnumstr.split(",");
    fs = new LinkedList();
    fe = new LinkedList();
    int dash, start, end;
    for (int i = 0; i < sections.length; i++) {
        try {
            if ((dash = sections[i].indexOf('-')) != -1) {
                start = Integer.parseInt(sections[i].substring(0, dash));
                end = Integer.parseInt(sections[i].substring(dash + 1));
            } else
                start = end = Integer.parseInt(sections[i]);
            if ((start == 0) || (end > files.length)) {
                console.out.println("> Command 'prio': Invalid file range " + sections[i]);
                return;
            }
            if (start > end) {
                console.out.println("> Command 'prio': Invalid file range '" + sections[i] + "'");
            }
            // -1 compensates for 0-based offsets
            fs.add(new Integer(start - 1));
            fe.add(new Integer(end - 1));
        } catch (Exception e) {
            console.out.println("> Command 'prio': File # '" + sections[i] + "' unknown.");
            return;
        }
    }
    // console.out.println("DM was " + dm.getState());
    if ((newprio == DELETE) && (dm.getState() != DownloadManager.STATE_STOPPED)) {
        try {
            dm.stopIt(DownloadManager.STATE_STOPPED, false, false);
        } catch (Exception e) {
            console.out.println("Failed to stop torrent " + tnumber);
            return;
        }
    }
    // console.out.println("DM is " + dm.getState());
    int nummod = 0;
    while (fs.size() > 0) {
        start = ((Integer) fs.removeFirst()).intValue();
        end = ((Integer) fe.removeFirst()).intValue();
        for (int i = start; i <= end; i++) {
            nummod++;
            // console.out.println("Setting priority for file " + i + " to " + newprio);
            if (newprio == NORMAL) {
                files[i].setPriority(0);
                files[i].setSkipped(false);
            } else if (newprio == HIGH) {
                files[i].setPriority(1);
                files[i].setSkipped(false);
            } else if (newprio == DONOTDOWNLOAD) {
                files[i].setPriority(0);
                files[i].setSkipped(true);
            } else if (newprio == DELETE) {
                int st = files[i].getStorageType();
                int target_st = -1;
                if (st == DiskManagerFileInfo.ST_LINEAR) {
                    target_st = DiskManagerFileInfo.ST_COMPACT;
                } else if (st == DiskManagerFileInfo.ST_REORDER) {
                    target_st = DiskManagerFileInfo.ST_REORDER_COMPACT;
                }
                if (target_st != -1 && files[i].setStorageType(target_st)) {
                    files[i].setPriority(0);
                    files[i].setSkipped(true);
                } else {
                    console.out.println("> Command 'prio': Failed to delete file " + (i + 1));
                    nummod--;
                }
            }
        }
    }
    if ((newprio == DELETE) && (dm.getState() == DownloadManager.STATE_STOPPED)) {
        try {
            dm.stopIt(DownloadManager.STATE_QUEUED, false, false);
        } catch (Exception e) {
            console.out.println("Failed to restart torrent " + tnumber);
            return;
        }
    }
    // console.out.println("DM is again " + dm.getState());
    console.out.println(nummod + " file(s) priority set to " + priostr[newprio - 1]);
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) List(java.util.List) LinkedList(java.util.LinkedList) DownloadManager(com.biglybt.core.download.DownloadManager) LinkedList(java.util.LinkedList)

Example 92 with DownloadManager

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

the class ColumnUnopened method cellMouseTrigger.

// @see com.biglybt.pif.ui.tables.TableCellMouseListener#cellMouseTrigger(com.biglybt.pif.ui.tables.TableCellMouseEvent)
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    if (event.eventType == TableRowMouseEvent.EVENT_MOUSEUP && event.button == 1) {
        Object ds = event.cell.getDataSource();
        boolean hasBeenOpened;
        if (ds instanceof DownloadManager) {
            DownloadManager dm = (DownloadManager) event.cell.getDataSource();
            boolean complete = dm.getAssumedComplete();
            if (!complete)
                return;
            hasBeenOpened = !PlatformTorrentUtils.getHasBeenOpened(dm);
            PlatformTorrentUtils.setHasBeenOpened(dm, hasBeenOpened);
        } else {
            DiskManagerFileInfo file = (DiskManagerFileInfo) ds;
            boolean complete = file.getLength() == file.getDownloaded();
            if (!complete)
                return;
            DownloadManager dm = file.getDownloadManager();
            int ff = dm.getDownloadState().getFileFlags(file.getIndex());
            ff ^= DownloadManagerState.FILE_FLAG_NOT_NEW;
            hasBeenOpened = (ff & DownloadManagerState.FILE_FLAG_NOT_NEW) != 0;
            dm.getDownloadState().setFileFlags(file.getIndex(), ff);
        }
        event.cell.setGraphic(hasBeenOpened ? graphicUnCheck : graphicCheck);
        event.cell.invalidate();
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 93 with DownloadManager

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

the class ColumnActivityActions method refresh.

// @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
@Override
public void refresh(TableCell cell) {
    ActivitiesEntry entry = (ActivitiesEntry) cell.getDataSource();
    if (entry == null)
        return;
    String[] actions = entry.getActions();
    String sort_value = "";
    for (String action : actions) {
        sort_value += "," + action;
    }
    if (sort_value.isEmpty()) {
        sort_value = entry.getTypeID();
    }
    if (!cell.setSortValue(sort_value) && cell.isValid()) {
        return;
    }
    DownloadManager dm = entry.getDownloadManger();
    boolean canPlay = PlayUtils.canPlayDS(entry, -1, false);
    boolean canDL = dm == null && entry.getDownloadManger() == null && (entry.getTorrent() != null || entry.getAssetHash() != null);
    boolean canRun = !canPlay && dm != null;
    if (canRun && dm != null && !dm.getAssumedComplete()) {
        canRun = false;
    }
    StringBuilder sb = new StringBuilder();
    if (canDL) {
        if (sb.length() > 0) {
            sb.append(" | ");
        }
        sb.append("<A HREF=\"download\">Download</A>");
    }
    if (canPlay) {
        if (sb.length() > 0) {
            sb.append(" | ");
        }
        sb.append("<A HREF=\"play\">Play</A>");
    }
    if (canRun) {
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append("<A HREF=\"launch\">Launch</A>");
    }
    for (String action : actions) {
        if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append("<A HREF=\"action:").append(action).append("\">").append(action).append("</A>");
    }
    cell.getTableRow().setData("text", sb.toString());
}
Also used : ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 94 with DownloadManager

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

the class ColumnProgressETA method cellPaint.

// @see com.biglybt.ui.swt.views.table.TableCellSWTPaintListener#cellPaint(org.eclipse.swt.graphics.GC, com.biglybt.ui.swt.views.table.TableCellSWT)
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        TableRowCore row = cell.getTableRowCore();
        if (row != null) {
            fileProgress.fillInfoProgressETA(row, gc, (DiskManagerFileInfo) ds, cell.getBounds());
        }
        return;
    }
    if (!(ds instanceof DownloadManager)) {
        return;
    }
    DownloadManager dm = (DownloadManager) ds;
    String tooltip = null;
    if (dm.getState() == DownloadManager.STATE_QUEUED) {
        tooltip = MessageText.getString("ManagerItem.queued.tooltip");
    }
    int percentDone = getPercentDone(ds);
    long eta = showETA ? getETA(cell) : 0;
    // Compute bounds ...
    int newWidth = cell.getWidth();
    if (newWidth <= 0) {
        return;
    }
    int newHeight = cell.getHeight();
    Color fgFirst = gc.getForeground();
    final Color fgOriginal = fgFirst;
    Rectangle cellBounds = cell.getBounds();
    int xStart = cellBounds.x;
    int yStart = cellBounds.y;
    int xRelProgressFillStart = borderWidth;
    int yRelProgressFillStart = borderWidth;
    int xRelProgressFillEnd = newWidth - xRelProgressFillStart - borderWidth;
    int yRelProgressFillEnd = yRelProgressFillStart + 13;
    boolean showSecondLine = yRelProgressFillEnd + 10 < newHeight;
    if (xRelProgressFillEnd < 10) {
        return;
    }
    String sStatusLine = null;
    // Draw Progress bar
    // ImageLoader imageLoader = ImageLoader.getInstance();
    Rectangle boundsImgBG;
    if (!ImageLoader.isRealImage(imgBGTorrent)) {
        boundsImgBG = new Rectangle(0, 0, 0, 13);
    } else {
        boundsImgBG = imgBGTorrent.getBounds();
    }
    if (fontText == null) {
        fontText = FontUtils.getFontWithHeight(gc.getFont(), gc, boundsImgBG.height - 3);
    }
    if (!showSecondLine) {
        yRelProgressFillStart = (cellBounds.height / 2) - ((boundsImgBG.height) / 2);
    }
    yRelProgressFillEnd = yRelProgressFillStart + boundsImgBG.height;
    int progressWidth = newWidth - 1;
    gc.setForeground(cBorder);
    gc.drawRectangle(xStart + xRelProgressFillStart - 1, yStart + yRelProgressFillStart - 1, progressWidth + 1, boundsImgBG.height + 1);
    int pctWidth = (int) (percentDone * (progressWidth) / 1000);
    gc.setBackground(percentDone == 1000 || dm.isDownloadComplete(false) ? cBGcd : cBGdl);
    gc.fillRectangle(xStart + xRelProgressFillStart, yStart + yRelProgressFillStart, pctWidth, boundsImgBG.height);
    if (progressWidth > pctWidth) {
        gc.setBackground(Colors.white);
        gc.fillRectangle(xStart + xRelProgressFillStart + pctWidth, yStart + yRelProgressFillStart, progressWidth - pctWidth, boundsImgBG.height);
    }
    if (boundsImgBG.width > 0) {
        gc.drawImage(imgBGTorrent, 0, 0, boundsImgBG.width, boundsImgBG.height, xStart + xRelProgressFillStart, yStart + yRelProgressFillStart, progressWidth, boundsImgBG.height);
    }
    if (sStatusLine == null) {
        if (dm.isUnauthorisedOnTracker()) {
            sStatusLine = dm.getTrackerStatus();
        // fgFirst = Colors.colorError;	pftt, no colours allowed apparently
        } else {
            if (showETA && eta > 0) {
                String sETA = ViewUtils.formatETA(eta, progress_eta_absolute, cdf.getDateFormat());
                sStatusLine = MessageText.getString("MyTorrents.column.ColumnProgressETA.2ndLine", new String[] { sETA });
            } else {
                sStatusLine = DisplayFormatters.formatDownloadStatus(dm).toUpperCase();
            }
        }
        int cursor_id;
        if (sStatusLine != null && !sStatusLine.contains("http://")) {
            dm.setUserData(CLICK_KEY, null);
            cursor_id = SWT.CURSOR_ARROW;
        } else {
            dm.setUserData(CLICK_KEY, sStatusLine);
            cursor_id = SWT.CURSOR_HAND;
            if (!cell.getTableRow().isSelected()) {
                fgFirst = Colors.blue;
            }
        }
        ((TableCellSWT) cell).setCursorID(cursor_id);
    }
    gc.setTextAntialias(SWT.ON);
    gc.setFont(fontText);
    if (showSecondLine && sStatusLine != null) {
        gc.setForeground(fgFirst);
        boolean fit = GCStringPrinter.printString(gc, sStatusLine, new Rectangle(cellBounds.x, yStart + yRelProgressFillEnd, cellBounds.width, newHeight - yRelProgressFillEnd), true, false, SWT.CENTER);
        if (!fit) {
            if (tooltip == null) {
                tooltip = sStatusLine;
            } else {
                tooltip = sStatusLine + ": " + tooltip;
            }
        }
        gc.setForeground(fgOriginal);
    }
    String sSpeed = "";
    if (showSpeed) {
        long lSpeed = getSpeed(ds);
        if (lSpeed > 0) {
            sSpeed = " (" + DisplayFormatters.formatByteCountToKiBEtcPerSec(lSpeed, true) + ")";
        }
    }
    String sPercent = DisplayFormatters.formatPercentFromThousands(percentDone);
    Rectangle area = new Rectangle(xStart + xRelProgressFillStart + 3, yStart + yRelProgressFillStart, xRelProgressFillEnd - xRelProgressFillStart - 6, yRelProgressFillEnd - yRelProgressFillStart);
    GCStringPrinter sp = new GCStringPrinter(gc, sPercent + sSpeed, area, true, false, SWT.LEFT);
    if (cTextDrop != null) {
        area.x++;
        area.y++;
        gc.setForeground(cTextDrop);
        sp.printString();
        area.x--;
        area.y--;
    }
    gc.setForeground(cText);
    sp.printString();
    Point pctExtent = sp.getCalculatedSize();
    area.width -= (pctExtent.x + 3);
    area.x += (pctExtent.x + 3);
    if (!showSecondLine && sStatusLine != null) {
        boolean fit = GCStringPrinter.printString(gc, sStatusLine, area.intersection(cellBounds), true, false, SWT.RIGHT);
        if (!fit) {
            if (tooltip == null) {
                tooltip = sStatusLine;
            } else {
                tooltip = sStatusLine + ": " + tooltip;
            }
        }
    }
    cell.setToolTip(tooltip);
    gc.setFont(null);
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) DownloadManager(com.biglybt.core.download.DownloadManager) EnhancedDownloadManager(com.biglybt.core.download.EnhancedDownloadManager) TableRowCore(com.biglybt.ui.common.table.TableRowCore)

Example 95 with DownloadManager

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

the class ColumnProgressETA method cellMouseTrigger.

@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    Object ds = event.cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        fileProgress.fileInfoMouseTrigger(event);
        return;
    }
    DownloadManager dm = (DownloadManager) ds;
    if (dm == null) {
        return;
    }
    String clickable = (String) dm.getUserData(CLICK_KEY);
    if (clickable == null) {
        return;
    }
    event.skipCoreFunctionality = true;
    if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
        String url = UrlUtils.getURL(clickable);
        if (url != null) {
            Utils.launch(url);
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManager(com.biglybt.core.download.DownloadManager) EnhancedDownloadManager(com.biglybt.core.download.EnhancedDownloadManager)

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