Search in sources :

Example 1 with BackgroundAction

use of ch.cyberduck.core.threading.BackgroundAction in project cyberduck by iterate-ch.

the class BrowserController method setStatus.

public void setStatus() {
    final BackgroundAction current = registry.getCurrent();
    this.message(null != current ? current.getActivity() : null);
}
Also used : BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DisconnectBackgroundAction(ch.cyberduck.core.threading.DisconnectBackgroundAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) BrowserTransferBackgroundAction(ch.cyberduck.core.threading.BrowserTransferBackgroundAction)

Example 2 with BackgroundAction

use of ch.cyberduck.core.threading.BackgroundAction in project cyberduck by iterate-ch.

the class TransferController method bandwidthPopupChanged.

@Action
public void bandwidthPopupChanged(NSMenuItem sender) {
    if (null == sender.representedObject()) {
        return;
    }
    final NSIndexSet selected = transferTable.selectedRowIndexes();
    final float bandwidth = Float.parseFloat(sender.representedObject());
    for (NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) {
        final Transfer transfer = collection.get(index.intValue());
        transfer.setBandwidth(bandwidth);
        if (transfer.isRunning()) {
            // Find matching background task
            for (BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) {
                if (action instanceof TransferBackgroundAction) {
                    final TransferBackgroundAction t = (TransferBackgroundAction) action;
                    if (t.getTransfer().equals(transfer)) {
                        final TransferSpeedometer meter = t.getMeter();
                        meter.reset();
                    }
                }
            }
        }
    }
}
Also used : DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) NSIndexSet(ch.cyberduck.binding.foundation.NSIndexSet) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) TransferBackgroundAction(ch.cyberduck.core.threading.TransferBackgroundAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) TransferBackgroundAction(ch.cyberduck.core.threading.TransferBackgroundAction) TransferCollectionBackgroundAction(ch.cyberduck.core.threading.TransferCollectionBackgroundAction) Action(ch.cyberduck.binding.Action) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) ControllerMainAction(ch.cyberduck.core.threading.ControllerMainAction) TransferBackgroundAction(ch.cyberduck.core.threading.TransferBackgroundAction) TransferCollectionBackgroundAction(ch.cyberduck.core.threading.TransferCollectionBackgroundAction)

Example 3 with BackgroundAction

use of ch.cyberduck.core.threading.BackgroundAction in project cyberduck by iterate-ch.

the class TransferControllerFactory method applicationShouldTerminate.

/**
 * @param app Singleton
 * @return NSApplication.TerminateLater or NSApplication.TerminateNow depending if there are
 * running transfers to be checked first
 */
public static NSUInteger applicationShouldTerminate(final NSApplication app) {
    if (null == shared) {
        return NSApplication.NSTerminateNow;
    }
    // Saving state of transfer window
    PreferencesFactory.get().setProperty("queue.window.open.default", shared.isVisible());
    if (TransferCollection.defaultCollection().numberOfRunningTransfers() > 0) {
        final NSAlert alert = // title
        NSAlert.alert(// title
        LocaleFactory.localizedString("Transfer in progress"), // message
        LocaleFactory.localizedString("There are files currently being transferred. Quit anyway?"), // defaultbutton
        LocaleFactory.localizedString("Quit"), // alternative button
        LocaleFactory.localizedString("Cancel"), // other button
        null);
        shared.alert(alert, new SheetCallback() {

            @Override
            public void callback(int returncode) {
                if (returncode == DEFAULT_OPTION) {
                    // Quit
                    final BackgroundActionRegistry registry = shared.getRegistry();
                    for (BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) {
                        action.cancel();
                    }
                    app.replyToApplicationShouldTerminate(true);
                }
                if (returncode == CANCEL_OPTION) {
                    // Cancel
                    app.replyToApplicationShouldTerminate(false);
                }
            }
        });
        // break
        return NSApplication.NSTerminateLater;
    }
    return NSApplication.NSTerminateNow;
}
Also used : SheetCallback(ch.cyberduck.binding.application.SheetCallback) BackgroundActionRegistry(ch.cyberduck.core.threading.BackgroundActionRegistry) NSAlert(ch.cyberduck.binding.application.NSAlert) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction)

Example 4 with BackgroundAction

use of ch.cyberduck.core.threading.BackgroundAction in project cyberduck by iterate-ch.

the class ActivityController method awakeFromNib.

@Override
public void awakeFromNib() {
    super.awakeFromNib();
    // Initialize to listen for background tasks
    registry.addListener(backgroundActionListener);
    // Add already running background actions
    final BackgroundAction[] actions = registry.toArray(new BackgroundAction[registry.size()]);
    for (final BackgroundAction action : actions) {
        tasks.put(action, new TaskController(action));
    }
    this.reload();
}
Also used : BackgroundAction(ch.cyberduck.core.threading.BackgroundAction)

Aggregations

BackgroundAction (ch.cyberduck.core.threading.BackgroundAction)4 Action (ch.cyberduck.binding.Action)1 NSAlert (ch.cyberduck.binding.application.NSAlert)1 SheetCallback (ch.cyberduck.binding.application.SheetCallback)1 NSIndexSet (ch.cyberduck.binding.foundation.NSIndexSet)1 BackgroundActionRegistry (ch.cyberduck.core.threading.BackgroundActionRegistry)1 BrowserTransferBackgroundAction (ch.cyberduck.core.threading.BrowserTransferBackgroundAction)1 ControllerMainAction (ch.cyberduck.core.threading.ControllerMainAction)1 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)1 DisconnectBackgroundAction (ch.cyberduck.core.threading.DisconnectBackgroundAction)1 TransferBackgroundAction (ch.cyberduck.core.threading.TransferBackgroundAction)1 TransferCollectionBackgroundAction (ch.cyberduck.core.threading.TransferCollectionBackgroundAction)1 WindowMainAction (ch.cyberduck.core.threading.WindowMainAction)1 WorkerBackgroundAction (ch.cyberduck.core.threading.WorkerBackgroundAction)1 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)1 Transfer (ch.cyberduck.core.transfer.Transfer)1 TransferSpeedometer (ch.cyberduck.core.transfer.TransferSpeedometer)1 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)1