Search in sources :

Example 86 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class UI method processArgs.

@Override
public String[] processArgs(CommandLine commands, String[] args) {
    boolean showMainWindow = args.length == 0 || COConfigurationManager.getBooleanParameter("Activate Window On External Download");
    boolean open = true;
    if (commands.hasOption("closedown") || commands.hasOption("shutdown")) {
        try {
            UpdateManager um = core.getPluginManager().getDefaultPluginInterface().getUpdateManager();
            UpdateInstaller[] installers = um.getInstallers();
            for (UpdateInstaller installer : installers) {
                installer.destroy();
            }
        } catch (Throwable e) {
        }
        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
        if (uiFunctions != null) {
            uiFunctions.dispose(false, false);
        }
        return null;
    }
    if (commands.hasOption("restart")) {
        UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
        if (uiFunctions != null) {
            uiFunctions.dispose(true, false);
        }
        return null;
    }
    if (commands.hasOption("share")) {
        showMainWindow = true;
        open = false;
    }
    if (commands.hasOption("open")) {
        showMainWindow = true;
    }
    String[] rest = commands.getArgs();
    for (int i = 0; i < rest.length; i++) {
        String filename = rest[i];
        File file = new File(filename);
        boolean isURI;
        if (!file.exists() && !isURI(filename)) {
            String magnet_uri = UrlUtils.normaliseMagnetURI(filename);
            isURI = magnet_uri != null;
            if (isURI) {
                filename = magnet_uri;
            }
        } else {
            isURI = isURI(filename);
        }
        if (isURI) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "StartServer: args[" + i + "] handling as a URI: " + filename));
        } else {
            try {
                if (!file.exists()) {
                    throw (new Exception("File '" + file + "' not found"));
                }
                filename = file.getCanonicalPath();
                Logger.log(new LogEvent(LOGID, "StartServer: file = " + filename));
            } catch (Throwable e) {
                Logger.log(new LogAlert(LogAlert.REPEATABLE, LogAlert.AT_ERROR, "Failed to access torrent file '" + filename + "'. Ensure sufficient temporary " + "file space available (check browser cache usage)."));
            }
        }
        boolean queued = false;
        try {
            this_mon.enter();
            if (queueTorrents) {
                queued_torrents.add(new Object[] { filename, Boolean.valueOf(open) });
                queued = true;
            }
        } finally {
            this_mon.exit();
        }
        if (!queued) {
            handleFile(filename, open);
        }
    }
    if (showMainWindow) {
        showMainWindow();
    }
    return args;
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) LogAlert(com.biglybt.core.logging.LogAlert) UIFunctions(com.biglybt.ui.UIFunctions) UpdateInstaller(com.biglybt.pif.update.UpdateInstaller) UpdateManager(com.biglybt.pif.update.UpdateManager) File(java.io.File)

Example 87 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class UISWTViewImpl method swt_triggerInitialize.

private void swt_triggerInitialize() {
    if (haveSentInitialize) {
        return;
    }
    if (!created) {
        triggerBooleanEvent(UISWTViewEvent.TYPE_CREATE, this);
    }
    if (composite != null) {
        composite.setRedraw(false);
        composite.setLayoutDeferred(true);
        triggerEvent(UISWTViewEvent.TYPE_INITIALIZE, composite);
        if (composite.getLayout() instanceof GridLayout) {
            // Force children to have GridData layoutdata.
            Control[] children = composite.getChildren();
            for (int i = 0; i < children.length; i++) {
                Control control = children[i];
                Object layoutData = control.getLayoutData();
                if (layoutData == null || !(layoutData instanceof GridData)) {
                    if (layoutData != null) {
                        Logger.log(new LogEvent(LogIDs.PLUGIN, LogEvent.LT_WARNING, "Plugin View '" + id + "' tried to setLayoutData of " + control + " to a " + layoutData.getClass().getName()));
                    }
                    GridData gridData;
                    if (children.length == 1) {
                        gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
                    } else {
                        gridData = new GridData();
                    }
                    control.setLayoutData(gridData);
                }
            }
        }
        composite.layout();
        composite.setLayoutDeferred(false);
        // issues with scroll bars not sizing correctly in Library view - is fixed by doign this...
        Utils.relayoutUp(composite);
        composite.setRedraw(true);
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) LogEvent(com.biglybt.core.logging.LogEvent) GridData(org.eclipse.swt.layout.GridData) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject)

Example 88 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class MyTorrentsView method createDragDrop.

private void createDragDrop() {
    try {
        Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
        if (dragSource != null && !dragSource.isDisposed()) {
            dragSource.dispose();
        }
        if (dropTarget != null && !dropTarget.isDisposed()) {
            dropTarget.dispose();
        }
        dragSource = tv.createDragSource(DND.DROP_MOVE | DND.DROP_COPY);
        if (dragSource != null) {
            dragSource.setTransfer(types);
            dragSource.addDragListener(new DragSourceAdapter() {

                private String eventData;

                @Override
                public void dragStart(DragSourceEvent event) {
                    TableRowCore[] rows = tv.getSelectedRows();
                    if (rows.length != 0) {
                        event.doit = true;
                        // System.out.println("DragStart");
                        drag_drop_line_start = rows[0].getIndex();
                        drag_drop_rows = rows;
                    } else {
                        event.doit = false;
                        drag_drop_line_start = -1;
                        drag_drop_rows = null;
                    }
                    // Build eventData here because on OSX, selection gets cleared
                    // by the time dragSetData occurs
                    boolean onlyDMs = true;
                    StringBuilder sb = new StringBuilder();
                    Object[] selectedDataSources = tv.getSelectedDataSources(true);
                    for (Object ds : selectedDataSources) {
                        if (ds instanceof DownloadManager) {
                            DownloadManager dm = (DownloadManager) ds;
                            TOTorrent torrent = dm.getTorrent();
                            if (torrent != null) {
                                try {
                                    sb.append(torrent.getHashWrapper().toBase32String());
                                    sb.append('\n');
                                } catch (TOTorrentException e) {
                                }
                            }
                        } else if (ds instanceof DiskManagerFileInfo) {
                            DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
                            DownloadManager dm = fileInfo.getDownloadManager();
                            TOTorrent torrent = dm.getTorrent();
                            if (torrent != null) {
                                try {
                                    sb.append(torrent.getHashWrapper().toBase32String());
                                    sb.append(';');
                                    sb.append(fileInfo.getIndex());
                                    sb.append('\n');
                                    onlyDMs = false;
                                } catch (TOTorrentException e) {
                                }
                            }
                        }
                    }
                    eventData = (onlyDMs ? "DownloadManager\n" : "DiskManagerFileInfo\n") + sb.toString();
                }

                @Override
                public void dragSetData(DragSourceEvent event) {
                    // System.out.println("DragSetData");
                    event.data = eventData;
                }
            });
        }
        dropTarget = tv.createDropTarget(DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
        if (dropTarget != null) {
            dropTarget.setTransfer(new Transfer[] { FixedHTMLTransfer.getInstance(), FixedURLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
            dropTarget.addDropListener(new DropTargetAdapter() {

                Point enterPoint = null;

                @Override
                public void dropAccept(DropTargetEvent event) {
                    event.currentDataType = FixedURLTransfer.pickBestType(event.dataTypes, event.currentDataType);
                }

                @Override
                public void dragEnter(DropTargetEvent event) {
                    // if ours
                    if (drag_drop_line_start < 0) {
                        if (event.detail != DND.DROP_COPY) {
                            if ((event.operations & DND.DROP_LINK) > 0)
                                event.detail = DND.DROP_LINK;
                            else if ((event.operations & DND.DROP_COPY) > 0)
                                event.detail = DND.DROP_COPY;
                        }
                    } else if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                        event.detail = tv.getTableRowWithCursor() == null ? DND.DROP_NONE : DND.DROP_MOVE;
                        event.feedback = DND.FEEDBACK_SCROLL;
                        enterPoint = new Point(event.x, event.y);
                    }
                }

                // @see org.eclipse.swt.dnd.DropTargetAdapter#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
                @Override
                public void dragLeave(DropTargetEvent event) {
                    super.dragLeave(event);
                    tv.getComposite().redraw();
                }

                @Override
                public void dragOver(DropTargetEvent event) {
                    if (drag_drop_line_start >= 0) {
                        if (drag_drop_rows.length > 0 && !(drag_drop_rows[0].getDataSource(true) instanceof DownloadManager)) {
                            event.detail = DND.DROP_NONE;
                            return;
                        }
                        TableRowCore row = tv.getTableRowWithCursor();
                        if (row instanceof TableRowPainted) {
                            boolean dragging_down = row.getIndex() > drag_drop_line_start;
                            Rectangle bounds = ((TableRowPainted) row).getBounds();
                            tv.getComposite().redraw();
                            tv.getComposite().update();
                            GC gc = new GC(tv.getComposite());
                            gc.setLineWidth(2);
                            int y_pos = bounds.y;
                            if (dragging_down) {
                                y_pos += bounds.height;
                            }
                            gc.drawLine(bounds.x, y_pos, bounds.x + bounds.width, y_pos);
                            gc.dispose();
                        }
                        event.detail = row == null ? DND.DROP_NONE : DND.DROP_MOVE;
                        event.feedback = DND.FEEDBACK_SCROLL | ((enterPoint != null && enterPoint.y > event.y) ? DND.FEEDBACK_INSERT_BEFORE : DND.FEEDBACK_INSERT_AFTER);
                    }
                }

                @Override
                public void drop(DropTargetEvent event) {
                    if (!(event.data instanceof String)) {
                        TorrentOpener.openDroppedTorrents(event, true);
                        return;
                    }
                    String data = (String) event.data;
                    if (data.startsWith("DiskManagerFileInfo\n")) {
                        return;
                    }
                    if (!data.startsWith("DownloadManager\n")) {
                        TorrentOpener.openDroppedTorrents(event, true);
                        return;
                    }
                    event.detail = DND.DROP_NONE;
                    // Torrent file from shell dropped
                    if (drag_drop_line_start >= 0) {
                        // event.data == null
                        event.detail = DND.DROP_NONE;
                        TableRowCore row = tv.getRow(event);
                        if (row == null)
                            return;
                        if (row.getParentRowCore() != null) {
                            row = row.getParentRowCore();
                        }
                        int drag_drop_line_end = row.getIndex();
                        if (drag_drop_line_end != drag_drop_line_start) {
                            DownloadManager dm = (DownloadManager) row.getDataSource(true);
                            moveRowsTo(drag_drop_rows, dm.getPosition());
                            event.detail = DND.DROP_MOVE;
                        }
                        drag_drop_line_start = -1;
                        drag_drop_rows = null;
                    }
                }
            });
        }
    } catch (Throwable t) {
        Logger.log(new LogEvent(LOGID, "failed to init drag-n-drop", t));
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) LogEvent(com.biglybt.core.logging.LogEvent) DownloadManager(com.biglybt.core.download.DownloadManager) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) FixedURLTransfer(com.biglybt.ui.swt.FixedURLTransfer) TableRowPainted(com.biglybt.ui.swt.views.table.painted.TableRowPainted)

Example 89 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class UIUpdaterSWT method update.

private void update(CopyOnWriteList<UIUpdatable> updateables, boolean is_visible) {
    long start = 0;
    Map<UIUpdatable, Long> mapTimeMap = DEBUG_TIMER ? new HashMap<UIUpdatable, Long>() : null;
    Display display = Utils.getDisplay();
    if (display == null || display.isDisposed()) {
        return;
    }
    for (UIUpdatable updateable : updateables) {
        try {
            if (DEBUG_TIMER) {
                start = SystemTime.getCurrentTime();
            }
            if (updateable instanceof UIUpdatableAlways) {
                ((UIUpdatableAlways) updateable).updateUI(is_visible);
            } else {
                updateable.updateUI();
            }
            if (DEBUG_TIMER) {
                long diff = SystemTime.getCurrentTime() - start;
                if (diff > 0) {
                    mapTimeMap.put(updateable, new Long(diff));
                }
            }
        } catch (Throwable t) {
            Logger.log(new LogEvent(LOGID, "Error while trying to update UI Element " + updateable.getUpdateUIName(), t));
        }
    }
    if (DEBUG_TIMER) {
        makeDebugToolTip(mapTimeMap);
    }
}
Also used : UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) LogEvent(com.biglybt.core.logging.LogEvent) UIUpdatableAlways(com.biglybt.ui.common.updater.UIUpdatableAlways) Display(org.eclipse.swt.widgets.Display)

Example 90 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class UIUpdaterSWT method run.

// @see com.biglybt.core.util.AEThread2#run()
@Override
public void run() {
    final AESemaphore sem = new AESemaphore("UI Updater");
    while (!finished) {
        Utils.execSWTThread(new SWTRunnable() {

            @Override
            public void runWithDisplay(Display display) {
                try {
                    if (finished) {
                        return;
                    }
                    if (display.getActiveShell() == null) {
                        Shell[] shells = display.getShells();
                        boolean noneVisible = true;
                        for (int i = 0; i < shells.length; i++) {
                            if (shells[i].isVisible() && !shells[i].getMinimized()) {
                                noneVisible = false;
                                break;
                            }
                        }
                        if (noneVisible) {
                            // System.out.println("nothing visible!");
                            if (alwaysUpdateables.size() > 0) {
                                update(alwaysUpdateables, false);
                            }
                            return;
                        }
                        // inactive means "active shell is not one of our app's"
                        if (inactiveTicks++ % inactiveFactor != 0) {
                            return;
                        }
                    }
                    update(updateables, true);
                } catch (Exception e) {
                    Logger.log(new LogEvent(LOGID, "Error while trying to update GUI", e));
                } finally {
                    try {
                        for (UIUpdaterListener l : listeners) {
                            try {
                                l.updateComplete(++update_count);
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                    } finally {
                        sem.release();
                    }
                }
            }

            @Override
            public void runNoDisplay() {
                sem.release();
            }
        });
        long start = SystemTime.getHighPrecisionCounter();
        sem.reserve();
        long elapsed = SystemTime.getHighPrecisionCounter() - start;
        long to_sleep = waitTimeMS - (elapsed / 1000000);
        if (to_sleep < 10) {
            to_sleep = 10;
        } else if (to_sleep > 25000) {
            to_sleep = 25000;
        }
        try {
            // System.out.println( "sleep=" + to_sleep );
            Thread.sleep(to_sleep);
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) Display(org.eclipse.swt.widgets.Display)

Aggregations

LogEvent (com.biglybt.core.logging.LogEvent)172 LogAlert (com.biglybt.core.logging.LogAlert)20 IOException (java.io.IOException)14 File (java.io.File)11 URL (java.net.URL)11 ArrayList (java.util.ArrayList)9 InetSocketAddress (java.net.InetSocketAddress)8 InputStream (java.io.InputStream)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ZipInputStream (java.util.zip.ZipInputStream)7 CacheFileManagerException (com.biglybt.core.diskmanager.cache.CacheFileManagerException)6 TOTorrent (com.biglybt.core.torrent.TOTorrent)6 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)6 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)6 UIFunctions (com.biglybt.ui.UIFunctions)6 SocketChannel (java.nio.channels.SocketChannel)6 Iterator (java.util.Iterator)6 ConnectionEndpoint (com.biglybt.core.networkmanager.ConnectionEndpoint)5 ClientIDException (com.biglybt.pif.clientid.ClientIDException)5 ParameterListener (com.biglybt.core.config.ParameterListener)4