Search in sources :

Example 96 with DownloadManager

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

the class ColumnProgressETA method refresh.

@Override
public void refresh(TableCell cell) {
    Object ds = cell.getDataSource();
    // needs to be long so we can shift it for sortVal
    long percentDone = getPercentDone(ds);
    long sortValue = 0;
    if (ds instanceof DownloadManager) {
        DownloadManager dm = (DownloadManager) cell.getDataSource();
        // close enough to unique with abs..
        int hashCode = Math.abs(DisplayFormatters.formatDownloadStatus(dm).hashCode());
        long completedTime = dm.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME);
        if (completedTime <= 0 || !dm.isDownloadComplete(false)) {
            sortValue = (percentDone << 31) + hashCode;
        } else {
            sortValue = ((completedTime / 1000) << 31) + hashCode;
        }
    } else if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
        int st = fileInfo.getStorageType();
        if ((st == DiskManagerFileInfo.ST_COMPACT || st == DiskManagerFileInfo.ST_REORDER_COMPACT) && fileInfo.isSkipped()) {
            sortValue = 1;
        } else if (fileInfo.isSkipped()) {
            sortValue = 2;
        } else if (fileInfo.getPriority() > 0) {
            int pri = fileInfo.getPriority();
            sortValue = 4;
            if (pri > 1) {
                sortValue += pri;
            }
        } else {
            sortValue = 3;
        }
        sortValue = (fileInfo.getDownloadManager().getState() * 10000) + percentDone + sortValue;
    }
    long eta = showETA ? getETA(cell) : 0;
    long speed = showSpeed ? getSpeed(ds) : 0;
    // System.out.println("REFRESH " + sortValue + ";" + ds);
    Comparable old = cell.getSortValue();
    boolean sortChanged = cell.setSortValue(sortValue);
    if (sortChanged && old != null && !(old instanceof String)) {
        UIFunctionsManagerSWT.getUIFunctionsSWT().refreshIconBar();
    }
    long lastETA = 0;
    long lastSpeed = 0;
    TableRow row = cell.getTableRow();
    if (row != null) {
        if (showETA) {
            Object data = row.getData("lastETA");
            if (data instanceof Number) {
                lastETA = ((Number) data).longValue();
            }
            row.setData("lastETA", new Long(eta));
        }
        if (showSpeed) {
            Object data = row.getData("lastSpeed");
            if (data instanceof Number) {
                lastSpeed = ((Number) data).longValue();
            }
            row.setData("lastSpeed", new Long(speed));
        }
    }
    if (!sortChanged && (lastETA != eta || lastSpeed != speed)) {
        cell.invalidate();
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManager(com.biglybt.core.download.DownloadManager) EnhancedDownloadManager(com.biglybt.core.download.EnhancedDownloadManager)

Example 97 with DownloadManager

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

the class ColumnThumbAndName method refresh.

@Override
public void refresh(TableCell cell, boolean sortOnlyRefresh) {
    String name = null;
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
        if (fileInfo.isSkipped() && (fileInfo.getStorageType() == DiskManagerFileInfo.ST_COMPACT || fileInfo.getStorageType() == DiskManagerFileInfo.ST_REORDER_COMPACT)) {
            TableRowCore row = (TableRowCore) cell.getTableRow();
            if (row != null) {
                row.getParentRowCore().removeSubRow(ds);
            }
        }
        return;
    }
    DownloadManager dm = (DownloadManager) ds;
    if (dm != null) {
        name = dm.getDisplayName();
    }
    if (name == null) {
        name = "";
    }
    cell.setSortValue(name);
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 98 with DownloadManager

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

the class AEProxySelectorSWTImpl method updateStatus.

private void updateStatus() {
    if (!is_visible) {
        return;
    }
    Image icon;
    String tip_key;
    Proxy active_proxy = proxy_selector.getActiveProxy();
    long now = SystemTime.getMonotonousTime();
    if (active_proxy == null) {
        icon = icon_grey;
        tip_key = "label.inactive";
    } else {
        long last_con = proxy_selector.getLastConnectionTime();
        long last_fail = proxy_selector.getLastFailTime();
        long con_ago = now - last_con;
        long fail_ago = now - last_fail;
        if (last_fail < 0) {
            icon = icon_green;
            tip_key = "PeerManager.status.ok";
        } else {
            if (fail_ago > 60 * 1000) {
                if (con_ago < fail_ago) {
                    icon = icon_green;
                    tip_key = "PeerManager.status.ok";
                } else {
                    icon = icon_grey;
                    tip_key = "PeersView.state.pending";
                }
            } else {
                icon = icon_yellow;
                tip_key = "label.con_prob";
            }
        }
    }
    if (flag_incoming) {
        boolean bad_incoming = false;
        if (now - last_bad_peer_update > 15 * 1000) {
            last_bad_peer_update = now;
            List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
            for (DownloadManager dm : dms) {
                PEPeerManager pm = dm.getPeerManager();
                if (pm != null) {
                    if (pm.getNbRemoteTCPConnections() + pm.getNbRemoteUDPConnections() + pm.getNbRemoteUTPConnections() > 0) {
                        List<PEPeer> peers = pm.getPeers();
                        for (PEPeer peer : peers) {
                            if (peer.isIncoming()) {
                                if (!peer.isLANLocal()) {
                                    try {
                                        if (InetAddress.getByAddress(HostNameToIPResolver.hostAddressToBytes(peer.getIp())).isLoopbackAddress()) {
                                            continue;
                                        }
                                    } catch (Throwable e) {
                                    }
                                    bad_incoming = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (bad_incoming) {
                    break;
                }
            }
        } else if (last_icon == icon_red) {
            bad_incoming = true;
        }
        if (bad_incoming) {
            icon = icon_red;
            tip_key = "proxy.socks.bad.incoming";
        }
    }
    if (last_icon != icon) {
        final Image f_icon = icon;
        final String f_key = tip_key;
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                last_icon = f_icon;
                status.setImage(f_icon);
                status.setTooltipText(MessageText.getString("proxy.socks.ui.icon.tip", new String[] { MessageText.getString(f_key) }));
            }
        });
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) PEPeer(com.biglybt.core.peer.PEPeer) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) Proxy(java.net.Proxy) PEPeerManager(com.biglybt.core.peer.PEPeerManager)

Example 99 with DownloadManager

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

the class MainWindowImpl method initSkinListeners.

/**
 * Associates every view ID that we use to a class, and creates the class
 * on first EVENT_SHOW.
 */
private void initSkinListeners() {
    uiSkinnableSWTListener = new UISkinnableSWTListener() {

        @Override
        public void skinBeforeComponents(Composite composite, Object skinnableObject, Object[] relatedObjects) {
            MessageBoxShell shell = (MessageBoxShell) skinnableObject;
            TOTorrent torrent = null;
            DownloadManager dm = (DownloadManager) LogRelationUtils.queryForClass(relatedObjects, DownloadManager.class);
            if (dm != null) {
                torrent = dm.getTorrent();
            } else {
                torrent = (TOTorrent) LogRelationUtils.queryForClass(relatedObjects, TOTorrent.class);
            }
            if (torrent != null && shell.getLeftImage() == null) {
                byte[] contentThumbnail = PlatformTorrentUtils.getContentThumbnail(torrent);
                if (contentThumbnail != null) {
                    try {
                        ByteArrayInputStream bis = new ByteArrayInputStream(contentThumbnail);
                        final Image img = new Image(Display.getDefault(), bis);
                        shell.setLeftImage(img);
                        composite.addDisposeListener(new DisposeListener() {

                            @Override
                            public void widgetDisposed(DisposeEvent e) {
                                if (!img.isDisposed()) {
                                    img.dispose();
                                }
                            }
                        });
                    } catch (Exception ignored) {
                    }
                }
            }
        }

        @Override
        public void skinAfterComponents(Composite composite, Object skinnableObject, Object[] relatedObjects) {
        }
    };
    UISkinnableManagerSWT skinnableManagerSWT = UISkinnableManagerSWT.getInstance();
    skinnableManagerSWT.addSkinnableListener(MessageBoxShell.class.toString(), uiSkinnableSWTListener);
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) DownloadManager(com.biglybt.core.download.DownloadManager) ByteArrayInputStream(java.io.ByteArrayInputStream) TOTorrent(com.biglybt.core.torrent.TOTorrent)

Example 100 with DownloadManager

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

the class MainWindowImpl method downloadAdded.

private static void downloadAdded(final DownloadManager[] dms, boolean allowDonationCheck) {
    boolean oneIsNotLowNoiseOrPersistent = false;
    for (final DownloadManager dm : dms) {
        if (dm == null) {
            continue;
        }
        DownloadManagerState dmState = dm.getDownloadState();
        final TOTorrent torrent = dm.getTorrent();
        if (torrent == null) {
            continue;
        }
        int pfi = PlatformTorrentUtils.getContentPrimaryFileIndex(torrent);
        if (pfi >= 0) {
            dmState.setIntAttribute(DownloadManagerState.AT_PRIMARY_FILE_IDX, pfi);
        }
        if (!oneIsNotLowNoiseOrPersistent && !dmState.getFlag(DownloadManagerState.FLAG_LOW_NOISE) && dm.isPersistent()) {
            oneIsNotLowNoiseOrPersistent = true;
        }
    }
    if (oneIsNotLowNoiseOrPersistent && allowDonationCheck) {
        DonationWindow.checkForDonationPopup();
    }
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState)

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