Search in sources :

Example 11 with ProgressCallback

use of com.biglybt.core.CoreOperationTask.ProgressCallback in project BiglyBT by BiglySoftware.

the class SBC_DiskOpsView method refreshToolBarItems.

@Override
public void refreshToolBarItems(Map<String, Long> list) {
    Object[] selectedDS;
    synchronized (this) {
        if (tvDiskOps == null) {
            return;
        }
        selectedDS = tvDiskOps.getSelectedDataSources().toArray();
    }
    if (selectedDS.length == 0) {
        return;
    }
    boolean can_start = false;
    boolean can_stop = false;
    boolean can_remove = true;
    for (Object ds : selectedDS) {
        CoreOperation op = (CoreOperation) ds;
        ProgressCallback prog = op.getTask().getProgressCallback();
        int states = prog.getSupportedTaskStates();
        int state = prog.getTaskState();
        if ((states & ProgressCallback.ST_PAUSE) != 0) {
            if (state == ProgressCallback.ST_NONE || state == ProgressCallback.ST_QUEUED || (state == ProgressCallback.ST_PAUSE && prog.isAutoPause())) {
                can_stop = true;
            }
        }
        if ((states & ProgressCallback.ST_RESUME) != 0) {
            if (state == ProgressCallback.ST_PAUSE) {
                can_start = true;
            }
        }
        if ((states & ProgressCallback.ST_CANCEL) == 0) {
            can_remove = false;
        } else {
            if (state == ProgressCallback.ST_CANCEL) {
                can_remove = false;
            }
        }
    }
    list.put("stop", can_stop ? UIToolBarItem.STATE_ENABLED : 0);
    list.put("start", can_start ? UIToolBarItem.STATE_ENABLED : 0);
    list.put("startstop", can_start || can_stop ? UIToolBarItem.STATE_ENABLED : 0);
    list.put("remove", can_remove ? UIToolBarItem.STATE_ENABLED : 0);
}
Also used : CoreOperation(com.biglybt.core.CoreOperation) ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Example 12 with ProgressCallback

use of com.biglybt.core.CoreOperationTask.ProgressCallback in project BiglyBT by BiglySoftware.

the class ColumnFO_Progress method cellPaint.

@Override
public void cellPaint(GC gcImage, TableCellSWT cell) {
    CoreOperation op = (CoreOperation) cell.getDataSource();
    int progress = 0;
    boolean has_progress = false;
    if (op != null) {
        ProgressCallback cb = op.getTask().getProgressCallback();
        if (cb != null) {
            progress = cb.getProgress();
            has_progress = true;
        }
    }
    Rectangle bounds = cell.getBounds();
    int yOfs = (bounds.height - 13) / 2;
    int x1 = bounds.width - borderWidth - 2;
    int y1 = bounds.height - 3 - yOfs;
    if (x1 < 10 || y1 < 3) {
        return;
    }
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgEnd = imageLoader.getImage("tc_bar_end");
    Image img0 = imageLoader.getImage("tc_bar_0");
    Image img1 = imageLoader.getImage("tc_bar_1");
    // draw begining and end
    if (!imgEnd.isDisposed()) {
        gcImage.drawImage(imgEnd, bounds.x, bounds.y + yOfs);
        gcImage.drawImage(imgEnd, bounds.x + x1 + 1, bounds.y + yOfs);
    }
    int limit = (x1 * progress) / 1000;
    if (!img1.isDisposed() && limit > 0) {
        Rectangle imgBounds = img1.getBounds();
        gcImage.drawImage(img1, 0, 0, imgBounds.width, imgBounds.height, bounds.x + 1, bounds.y + yOfs, limit, imgBounds.height);
    }
    if (progress < 1000 && !img0.isDisposed()) {
        Rectangle imgBounds = img0.getBounds();
        gcImage.drawImage(img0, 0, 0, imgBounds.width, imgBounds.height, bounds.x + limit + 1, bounds.y + yOfs, x1 - limit, imgBounds.height);
    }
    imageLoader.releaseImage("tc_bar_end");
    imageLoader.releaseImage("tc_bar_0");
    imageLoader.releaseImage("tc_bar_1");
    if (textColor == null) {
        textColor = ColorCache.getColor(gcImage.getDevice(), "#006600");
    }
    gcImage.setForeground(textColor);
    if (fontText == null) {
        fontText = FontUtils.getFontWithHeight(gcImage.getFont(), 10, SWT.DEFAULT);
    }
    gcImage.setFont(fontText);
    String sText;
    if (!has_progress) {
        sText = na_text;
    } else {
        sText = DisplayFormatters.formatPercentFromThousands(progress);
    }
    GCStringPrinter.printString(gcImage, sText, new Rectangle(bounds.x + 4, bounds.y + yOfs, bounds.width - 4, 13), true, false, SWT.CENTER);
}
Also used : CoreOperation(com.biglybt.core.CoreOperation) ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 13 with ProgressCallback

use of com.biglybt.core.CoreOperationTask.ProgressCallback in project BiglyBT by BiglySoftware.

the class ColumnFO_Progress method refresh.

@Override
public void refresh(TableCell cell) {
    CoreOperation op = (CoreOperation) cell.getDataSource();
    int progress = -1;
    if (op != null) {
        ProgressCallback cb = op.getTask().getProgressCallback();
        if (cb != null) {
            progress = cb.getProgress();
        }
    }
    cell.setSortValue(progress);
}
Also used : CoreOperation(com.biglybt.core.CoreOperation) ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback)

Example 14 with ProgressCallback

use of com.biglybt.core.CoreOperationTask.ProgressCallback in project BiglyBT by BiglySoftware.

the class ColumnFO_SubTask method refresh.

@Override
public void refresh(TableCell cell) {
    CoreOperation op = (CoreOperation) cell.getDataSource();
    if (op == null) {
        return;
    }
    ProgressCallback cb = op.getTask().getProgressCallback();
    if (cb == null) {
        return;
    }
    String st = cb.getSubTaskName();
    cell.setText(st == null ? "" : st);
}
Also used : CoreOperation(com.biglybt.core.CoreOperation) ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback)

Example 15 with ProgressCallback

use of com.biglybt.core.CoreOperationTask.ProgressCallback in project BiglyBT by BiglySoftware.

the class DiskManagerOperationScheduler method schedule.

private void schedule() {
    for (Operation op : operations) {
        if ((op.cb.getTaskState() & ProgressCallback.ST_PAUSE) == 0) {
            op.we_paused_it = false;
        } else {
            op.we_resumed_it = false;
        }
    }
    // for check operations we make an exception and will re-pause an active one if order has changed
    Map<String, Operation> first_check_per_fs = new HashMap<>();
    for (Operation op : operations) {
        if (op.op.getOperationType() == CoreOperation.OP_DOWNLOAD_CHECKING) {
            for (String fs : op.unique_fs) {
                if (first_check_per_fs.get(fs) == null) {
                    first_check_per_fs.put(fs, op);
                } else {
                    ProgressCallback cb = op.cb;
                    if ((cb.getTaskState() & ProgressCallback.ST_PAUSE) == 0) {
                        if (op.we_resumed_it) {
                            cb.setTaskState(ProgressCallback.ST_PAUSE);
                            cb.setAutoPause(true);
                            op.we_paused_it = true;
                            op.we_resumed_it = false;
                        }
                    }
                }
            }
        }
    }
    Map<String, int[]> fs_queue_pos = new HashMap<>();
    for (Operation op : operations) {
        if ((op.cb.getTaskState() & ProgressCallback.ST_PAUSE) == 0) {
            op.cb.setAutoPause(false);
            for (String fs : op.unique_fs) {
                int[] x = fs_queue_pos.get(fs);
                if (x == null) {
                    fs_queue_pos.put(fs, new int[] { 1 });
                }
            }
        }
    }
    for (Operation op : operations) {
        ProgressCallback cb = op.cb;
        if ((cb.getTaskState() & ProgressCallback.ST_PAUSE) != 0) {
            if (cb.isAutoPause()) {
                int pos = 0;
                for (String fs : op.unique_fs) {
                    int[] count = fs_queue_pos.get(fs);
                    if (count != null) {
                        pos = Math.max(pos, count[0]);
                        count[0]++;
                    } else {
                        fs_queue_pos.put(fs, new int[] { 1 });
                    }
                }
                if (pos == 0) {
                    cb.setTaskState(ProgressCallback.ST_RESUME);
                    cb.setAutoPause(false);
                    op.we_resumed_it = true;
                    op.we_paused_it = false;
                } else {
                    cb.setOrder(pos);
                }
            }
        }
    }
}
Also used : ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback) CoreOperation(com.biglybt.core.CoreOperation)

Aggregations

ProgressCallback (com.biglybt.core.CoreOperationTask.ProgressCallback)15 CoreOperation (com.biglybt.core.CoreOperation)13 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)4 CoreOperationTask (com.biglybt.core.CoreOperationTask)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 CoreOperationListener (com.biglybt.core.CoreOperationListener)1 ProgressCallbackAdapter (com.biglybt.core.CoreOperationTask.ProgressCallbackAdapter)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 AERunnable (com.biglybt.core.util.AERunnable)1 DelayedEvent (com.biglybt.core.util.DelayedEvent)1 UIExitUtilsSWT.canCloseListener (com.biglybt.ui.swt.UIExitUtilsSWT.canCloseListener)1 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)1 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)1 ArrayList (java.util.ArrayList)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 GridData (org.eclipse.swt.layout.GridData)1