use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.
the class ConfigView method initialize.
private void initialize(final Composite composite) {
// need to initalize composite now, since getComposite can
// be called at any time
cConfig = new Composite(composite, SWT.NONE);
GridLayout configLayout = new GridLayout();
configLayout.marginHeight = 0;
configLayout.marginWidth = 0;
cConfig.setLayout(configLayout);
GridData gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(cConfig, gridData);
final Label label = new Label(cConfig, SWT.CENTER);
Messages.setLanguageText(label, "view.waiting.core");
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(label, gridData);
// Need to delay initialation until core is done so we can guarantee
// all config sections are loaded (ie. plugin ones).
// TODO: Maybe add them on the fly?
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
_initialize(composite);
label.dispose();
composite.layout(true, true);
}
});
}
});
}
use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.
the class TopBarView method skinObjectInitialShow.
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
this.skin = skinObject.getSkin();
skin.addListener("topbar-plugins", new SWTSkinObjectListener() {
@Override
public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
if (eventType == SWTSkinObjectListener.EVENT_SHOW) {
skin.removeListener("topbar-plugins", this);
// building needs UISWTInstance, which needs core.
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
buildTopBarViews();
}
});
}
});
}
return null;
}
});
// trigger autobuild and hook in events
skin.getSkinObject("topbar-area-plugin").addListener(new SWTSkinObjectListener() {
@Override
public Object eventOccured(SWTSkinObject skinObject, int eventType, Object params) {
if (eventType == SWTSkinObjectListener.EVENT_SHOW) {
if (activeTopBar != null) {
activeTopBar.triggerEvent(UISWTViewEvent.TYPE_FOCUSGAINED, null);
}
} else if (eventType == SWTSkinObjectListener.EVENT_HIDE) {
if (activeTopBar != null) {
activeTopBar.triggerEvent(UISWTViewEvent.TYPE_FOCUSLOST, null);
}
}
return (null);
}
});
return null;
}
use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.
the class ViewQuickConfig method addTemporaryRates.
private void addTemporaryRates(Composite composite) {
Group temp_rates = new Group(composite, SWT.NULL);
Messages.setLanguageText(temp_rates, "label.temporary.rates");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 4;
Utils.setLayoutData(temp_rates, gridData);
GridLayout layout = new GridLayout(10, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
temp_rates.setLayout(layout);
// label = new Label(temp_rates, SWT.NULL);
// Messages.setLanguageText( label, "label.temporary.rates" );
Label label = new Label(temp_rates, SWT.NULL);
gridData = new GridData();
gridData.horizontalIndent = 4;
Utils.setLayoutData(label, gridData);
Messages.setLanguageText(label, "label.upload.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final IntParameter tempULRate = new IntParameter(temp_rates, "global.download.rate.temp.kbps", 0, Integer.MAX_VALUE);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.download.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final IntParameter tempDLRate = new IntParameter(temp_rates, "global.upload.rate.temp.kbps", 0, Integer.MAX_VALUE);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.duration.mins");
final IntParameter tempMins = new IntParameter(temp_rates, "global.rate.temp.min", 0, Integer.MAX_VALUE);
final Button activate = new Button(temp_rates, SWT.TOGGLE);
Messages.setLanguageText(activate, "label.activate");
final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 150;
Utils.setLayoutData(remLabel, gridData);
activate.addSelectionListener(new SelectionAdapter() {
private CoreLifecycleAdapter listener;
private TimerEventPeriodic event;
private boolean auto_up_enabled;
private boolean auto_up_seeding_enabled;
private boolean seeding_limits_enabled;
private int up_limit;
private int down_limit;
private long end_time;
@Override
public void widgetSelected(SelectionEvent e) {
if (activate.getSelection()) {
listener = new CoreLifecycleAdapter() {
@Override
public void stopping(Core core) {
deactivate(true);
}
};
CoreFactory.getSingleton().addLifecycleListener(listener);
Messages.setLanguageText(activate, "FileView.BlockView.Active");
tempDLRate.setEnabled(false);
tempULRate.setEnabled(false);
tempMins.setEnabled(false);
auto_up_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY);
auto_up_seeding_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY);
seeding_limits_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY);
up_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY);
down_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, tempULRate.getValue());
COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, tempDLRate.getValue());
end_time = SystemTime.getCurrentTime() + tempMins.getValue() * 60 * 1000;
event = SimpleTimer.addPeriodicEvent("TempRates", 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent e) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (event == null) {
return;
}
long now = SystemTime.getCurrentTime();
long rem = end_time - now;
if (rem < 1000 || composite.isDisposed()) {
deactivate(false);
} else {
remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatTime(rem));
}
}
});
}
});
} else {
deactivate(false);
}
}
private void deactivate(boolean closing) {
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, auto_up_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, auto_up_seeding_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, seeding_limits_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, up_limit);
COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, down_limit);
if (!closing) {
if (listener != null) {
CoreFactory.getSingleton().removeLifecycleListener(listener);
listener = null;
}
if (!composite.isDisposed()) {
Messages.setLanguageText(activate, "label.activate");
activate.setSelection(false);
tempDLRate.setEnabled(true);
tempULRate.setEnabled(true);
tempMins.setEnabled(true);
remLabel.setText("");
}
}
if (event != null) {
event.cancel();
event = null;
}
}
});
activate.setEnabled(tempMins.getValue() > 0);
tempMins.addChangeListener(new ParameterChangeAdapter() {
@Override
public void parameterChanged(Parameter p, boolean caused_internally) {
activate.setEnabled(tempMins.getValue() > 0);
}
});
}
use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.
the class ViewQuickConfig method addTemporaryData.
private void addTemporaryData(Composite composite) {
Group temp_rates = new Group(composite, SWT.NULL);
Messages.setLanguageText(temp_rates, "label.temporary.data");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 4;
Utils.setLayoutData(temp_rates, gridData);
GridLayout layout = new GridLayout(10, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
temp_rates.setLayout(layout);
// label = new Label(temp_rates, SWT.NULL);
// Messages.setLanguageText( label, "label.temporary.rates" );
Label label = new Label(temp_rates, SWT.NULL);
gridData = new GridData();
gridData.horizontalIndent = 4;
Utils.setLayoutData(label, gridData);
Messages.setLanguageText(label, "label.upload.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
final IntParameter tempULLimit = new IntParameter(temp_rates, "global.upload.limit.temp.mb", 0, Integer.MAX_VALUE);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.download.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
final IntParameter tempDLLimit = new IntParameter(temp_rates, "global.download.limit.temp.mb", 0, Integer.MAX_VALUE);
final Button activate = new Button(temp_rates, SWT.TOGGLE);
Messages.setLanguageText(activate, "label.activate");
final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 200;
Utils.setLayoutData(remLabel, gridData);
activate.addSelectionListener(new SelectionAdapter() {
private CoreLifecycleAdapter listener;
private TimerEventPeriodic event;
private long end_upload;
private long end_download;
@Override
public void widgetSelected(SelectionEvent e) {
if (activate.getSelection()) {
listener = new CoreLifecycleAdapter() {
@Override
public void stopping(Core core) {
deactivate(true);
}
};
Core core = CoreFactory.getSingleton();
core.addLifecycleListener(listener);
Messages.setLanguageText(activate, "FileView.BlockView.Active");
final GlobalManagerStats stats = core.getGlobalManager().getStats();
tempULLimit.setEnabled(false);
tempDLLimit.setEnabled(false);
long u_limit = tempULLimit.getValue();
if (u_limit > 0) {
end_upload = stats.getTotalDataProtocolBytesSent() + u_limit * DisplayFormatters.getMinB();
} else {
end_upload = 0;
}
long d_limit = tempDLLimit.getValue();
if (d_limit > 0) {
end_download = stats.getTotalDataProtocolBytesReceived() + d_limit * DisplayFormatters.getMinB();
} else {
end_download = 0;
}
event = SimpleTimer.addPeriodicEvent("TempData", 5000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent e) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (event == null) {
return;
}
long rem_up = 0;
long rem_down = 0;
if (end_upload > 0) {
rem_up = end_upload - stats.getTotalDataProtocolBytesSent();
}
if (end_download > 0) {
rem_down = end_download - stats.getTotalDataProtocolBytesReceived();
}
if (end_upload > 0 && rem_up <= 0) {
java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
if (!dm.isForceStart()) {
int state = dm.getState();
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
ManagerUtils.stop(dm, null);
dm.setStopReason(MessageText.getString("label.temporary.data"));
}
}
}
}
if (end_download > 0 && rem_down <= 0) {
java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
if (!dm.isForceStart()) {
int state = dm.getState();
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
if (!dm.isDownloadComplete(false)) {
ManagerUtils.stop(dm, null);
dm.setStopReason(MessageText.getString("label.temporary.data"));
}
}
}
}
}
if ((rem_up <= 0 && rem_down <= 0) || composite.isDisposed()) {
deactivate(false);
} else {
remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatByteCountToKiBEtc(rem_up < 0 ? 0 : rem_up) + "/" + DisplayFormatters.formatByteCountToKiBEtc(rem_down < 0 ? 0 : rem_down));
temp_rates.layout(new Control[] { remLabel.getControl() });
}
}
});
}
});
} else {
deactivate(false);
}
}
private void deactivate(boolean closing) {
if (!closing) {
if (listener != null) {
CoreFactory.getSingleton().removeLifecycleListener(listener);
listener = null;
}
if (!composite.isDisposed()) {
Messages.setLanguageText(activate, "label.activate");
activate.setSelection(false);
tempULLimit.setEnabled(true);
tempDLLimit.setEnabled(true);
remLabel.setText("");
temp_rates.layout(true);
}
}
if (event != null) {
event.cancel();
event = null;
}
}
});
activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
ParameterChangeAdapter adapter = new ParameterChangeAdapter() {
@Override
public void parameterChanged(Parameter p, boolean caused_internally) {
activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
}
};
tempULLimit.addChangeListener(adapter);
tempDLLimit.addChangeListener(adapter);
}
use of com.biglybt.core.Core in project BiglyBT by BiglySoftware.
the class SearchSubsUtils method getHashStatus.
public static int getHashStatus(SearchSubsResultBase result) {
if (result == null) {
return (HS_NONE);
}
byte[] hash = result.getHash();
if (hash == null || hash.length != 20) {
return (HS_UNKNOWN);
}
long now = SystemTime.getMonotonousTime();
Object[] entry = (Object[]) result.getUserData(HS_KEY);
if (entry != null) {
long time = (Long) entry[0];
if (now - time < 10 * 1000) {
return ((Integer) entry[1]);
}
}
synchronized (HS_KEY) {
if (gm == null) {
Core core = CoreFactory.getSingleton();
gm = core.getGlobalManager();
dm = core.getPluginManager().getDefaultPluginInterface().getDownloadManager();
hm = (DownloadHistoryManager) gm.getDownloadHistoryManager();
}
}
int hs_result;
if (gm.getDownloadManager(new HashWrapper(hash)) != null) {
hs_result = HS_LIBRARY;
} else if (dm.lookupDownloadStub(hash) != null) {
hs_result = HS_ARCHIVE;
} else if (hm.getDates(hash) != null) {
hs_result = HS_HISTORY;
} else {
hs_result = HS_NONE;
}
result.setUserData(HS_KEY, new Object[] { now + RandomUtils.nextInt(2500), hs_result });
return (hs_result);
}
Aggregations