Search in sources :

Example 46 with DownloadManager

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

the class SwarmAverageSpeed method refresh.

@Override
public void refresh(TableCell cell) {
    long speed = -1;
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm != null) {
        speed = dm.getStats().getTotalAveragePerPeer();
    }
    if (!cell.setSortValue(speed) && cell.isValid()) {
        return;
    }
    if (speed < 0) {
        cell.setText("");
    } else {
        cell.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(speed));
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 47 with DownloadManager

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

the class TagColorsItem method cellPaint.

@Override
public void cellPaint(GC gc, TableCellSWT cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    List<Color> colors = new ArrayList<>();
    if (dm != null) {
        List<Tag> tags = tag_manager.getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, dm);
        for (Tag tag : tags) {
            int[] rgb = tag.getColor();
            if (rgb != null && rgb.length == 3) {
                colors.add(ColorCache.getColor(gc.getDevice(), rgb));
            }
        }
    }
    int num_colors = colors.size();
    if (num_colors > 0) {
        Rectangle bounds = cell.getBounds();
        bounds.x += 1;
        bounds.y += 1;
        bounds.width -= 1;
        bounds.height -= 1;
        if (num_colors == 1) {
            gc.setBackground(colors.get(0));
            gc.fillRectangle(bounds);
        } else {
            int width = bounds.width;
            int chunk = width / num_colors;
            if (chunk == 0) {
                chunk = 1;
            }
            bounds.width = chunk;
            for (int i = 0; i < num_colors; i++) {
                if (i == num_colors - 1) {
                    int rem = width - (chunk * (num_colors - 1));
                    if (rem > 0) {
                        bounds.width = rem;
                    }
                }
                gc.setBackground(colors.get(i));
                gc.fillRectangle(bounds);
                bounds.x += chunk;
            }
        }
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) Tag(com.biglybt.core.tag.Tag) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 48 with DownloadManager

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

the class TimeSinceDownloadItem method refresh.

@Override
public void refresh(TableCell cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    int value = (dm == null) ? -2 : dm.getStats().getTimeSinceLastDataReceivedInSeconds();
    if (!cell.setSortValue(value == -1 ? Integer.MAX_VALUE : value) && cell.isValid())
        return;
    cell.setText(value == -2 ? "" : (value == -1 ? Constants.INFINITY_STRING : TimeFormatter.format(value)));
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 49 with DownloadManager

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

the class TorrentCreateDateItem method refresh.

@Override
public void refresh(TableCell cell, long timestamp) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    timestamp = (dm == null) ? 0 : dm.getTorrentCreationDate();
    super.refresh(cell, timestamp * 1000);
// cell.setText(DisplayFormatters.formatDate(timestamp));
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 50 with DownloadManager

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

the class SeedToPeerRatioItem method refresh.

@Override
public void refresh(TableCell cell) {
    float ratio = -1;
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm != null) {
        TRTrackerScraperResponse response = dm.getTrackerScrapeResponse();
        int seeds;
        int peers;
        if (response != null && response.isValid()) {
            seeds = Math.max(dm.getNbSeeds(), response.getSeeds());
            int trackerPeerCount = response.getPeers();
            peers = dm.getNbPeers();
            if (peers == 0 || trackerPeerCount > peers) {
                if (trackerPeerCount <= 0) {
                    peers = dm.getActivationCount();
                } else {
                    peers = trackerPeerCount;
                }
            }
        } else {
            seeds = dm.getNbSeeds();
            peers = dm.getNbPeers();
        }
        if (peers < 0 || seeds < 0) {
            ratio = 0;
        } else {
            if (peers == 0) {
                if (seeds == 0)
                    ratio = 0;
                else
                    ratio = Float.POSITIVE_INFINITY;
            } else {
                ratio = (float) seeds / peers;
            }
        }
    }
    if (!cell.setSortValue(ratio) && cell.isValid()) {
        return;
    }
    if (ratio == -1) {
        cell.setText("");
    } else if (ratio == 0) {
        cell.setText("??");
    } else {
        cell.setText(DisplayFormatters.formatDecimal(ratio, 3));
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) 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