use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.
the class MainStatusBar method updateUI.
@Override
public void updateUI(boolean is_visible) {
if (statusBar.isDisposed()) {
return;
}
// see if this fixes occasional issue with status bar vanishing when bringing back from taskbar/tray
boolean is_hidden = (!is_visible) || statusBar.getDisplay().getFocusControl() == null;
if (is_hidden) {
was_hidden = true;
} else {
if (was_hidden) {
statusBar.layout(true, true);
was_hidden = false;
}
}
if (!is_visible) {
return;
}
// Plugins.
Control[] plugin_elements = this.plugin_label_composite.getChildren();
for (int i = 0; i < plugin_elements.length; i++) {
if (plugin_elements[i] instanceof UpdateableCLabel) {
((UpdateableCLabel) plugin_elements[i]).checkForRefresh();
}
}
if (ipBlocked.isVisible()) {
updateIPBlocked();
}
if (srStatus.isVisible()) {
updateShareRatioStatus();
}
if (natStatus.isVisible()) {
updateNatStatus();
}
if (dhtStatus.isVisible()) {
updateDHTStatus();
}
// UL/DL Status Sections
if (CoreFactory.isCoreRunning()) {
Core core = CoreFactory.getSingleton();
GlobalManager gm = core.getGlobalManager();
GlobalManagerStats stats = gm.getStats();
int dl_limit = NetworkManager.getMaxDownloadRateBPS() / 1024;
long rec_data = stats.getDataReceiveRate();
long rec_prot = stats.getProtocolReceiveRate();
if (last_dl_limit != dl_limit || last_rec_data != rec_data || last_rec_prot != rec_prot) {
last_dl_limit = dl_limit;
last_rec_data = rec_data;
last_rec_prot = rec_prot;
statusDown.setText((dl_limit == 0 ? "" : "[" + dl_limit + "K] ") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(rec_data, rec_prot));
}
boolean auto_up = TransferSpeedValidator.isAutoSpeedActive(gm) && TransferSpeedValidator.isAutoUploadAvailable(core);
int ul_limit_norm = NetworkManager.getMaxUploadRateBPSNormal() / 1024;
String seeding_only;
if (NetworkManager.isSeedingOnlyUploadRate()) {
int ul_limit_seed = NetworkManager.getMaxUploadRateBPSSeedingOnly() / 1024;
if (ul_limit_seed == 0) {
seeding_only = "+" + Constants.INFINITY_STRING + "K";
} else {
int diff = ul_limit_seed - ul_limit_norm;
seeding_only = (diff >= 0 ? "+" : "") + diff + "K";
}
} else {
seeding_only = "";
}
int sent_data = stats.getDataSendRate();
if (imgRec != null && !imgRec.isDisposed()) {
updateGraph(statusDown, imgRec, rec_data, max_rec);
updateGraph(statusUp, imgSent, sent_data, max_sent);
}
statusUp.setText((ul_limit_norm == 0 ? "" : "[" + ul_limit_norm + "K" + seeding_only + "]") + (auto_up ? "* " : " ") + DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(sent_data, stats.getProtocolSendRate()));
}
}
use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.
the class MainWindowImpl method createWindow.
/**
* @param uiInitializer
*
* called in both delayedCore and !delayedCore
*/
private void createWindow(IUIIntializer uiInitializer) {
// System.out.println("MainWindow: createWindow)");
long startTime = SystemTime.getCurrentTime();
UIFunctionsSWT existing_uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
uiFunctions = new UIFunctionsImpl(this);
UIFunctionsManager.setUIFunctions(uiFunctions);
Utils.disposeComposite(shell);
increaseProgress(uiInitializer, "splash.initializeGui");
System.out.println("UIFunctions/ImageLoad took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
shell = existing_uif == null ? new Shell(Utils.getDisplay(), SWT.SHELL_TRIM) : existing_uif.getMainShell();
if (Constants.isWindows) {
try {
Class<?> ehancerClass = Class.forName("com.biglybt.ui.swt.win32.Win32UIEnhancer");
Method method = ehancerClass.getMethod("initMainShell", Shell.class);
method.invoke(null, shell);
} catch (Exception e) {
Debug.outNoStack(Debug.getCompressedStackTrace(e, 0, 30), true);
}
}
try {
shell.setData("class", this);
shell.setText(UIFunctions.MAIN_WINDOW_NAME);
Utils.setShellIcon(shell);
Utils.linkShellMetricsToConfig(shell, "window");
// Shell activeShell = display.getActiveShell();
// shell.setVisible(true);
// shell.moveBelow(activeShell);
System.out.println("new shell took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
increaseProgress(uiInitializer, "v3.splash.initSkin");
skin = SWTSkinFactory.getInstance();
if (Utils.isAZ2UI()) {
SWTSkinProperties skinProperties = skin.getSkinProperties();
String skinPath = SkinPropertiesImpl.PATH_SKIN_DEFS + "skin3_classic";
ResourceBundle rb = ResourceBundle.getBundle(skinPath);
skinProperties.addResourceBundle(rb, skinPath);
}
/*
* KN: passing the skin to the uifunctions so it can be used by UIFunctionsSWT.createMenu()
*/
uiFunctions.setSkin(skin);
System.out.println("new shell setup took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
initSkinListeners();
increaseProgress(uiInitializer, "v3.splash.initSkin");
// 0ms
// System.out.println("skinlisteners init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
String startID = Utils.isAZ2UI() ? "classic.shell" : "main.shell";
skin.initialize(shell, startID, uiInitializer);
increaseProgress(uiInitializer, "v3.splash.initSkin");
System.out.println("skin init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
menu = uiFunctions.createMainMenu(shell);
shell.setData("MainMenu", menu);
System.out.println("MainMenu init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
increaseProgress(uiInitializer, "v3.splash.initSkin");
skin.layout();
try {
Utils.createTorrentDropTarget(shell, false);
} catch (Throwable e) {
Logger.log(new LogEvent(LOGID, "Drag and Drop not available", e));
}
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (configIconBarEnabledListener != null) {
COConfigurationManager.removeParameterListener("IconBar.enabled", configIconBarEnabledListener);
}
if (configShowStatusInTitleListener != null) {
COConfigurationManager.removeParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
}
if (configShowDLBasketListener != null) {
COConfigurationManager.removeParameterListener("Show Download Basket", configShowDLBasketListener);
}
if (configMonitorClipboardListener != null) {
COConfigurationManager.removeParameterListener("Monitor Clipboard For Torrents", configMonitorClipboardListener);
}
if (gmListener != null) {
GlobalManager gm = core.getGlobalManager();
if (gm != null) {
gm.removeListener(gmListener);
}
gmListener = null;
}
if (uiFunctions != null) {
uiFunctions.dispose();
}
if (navigationListener != null) {
NavigationHelper.removeListener(navigationListener);
navigationListener = null;
}
StimulusRPC.unhookListeners();
UISkinnableManagerSWT skinnableManagerSWT = UISkinnableManagerSWT.getInstance();
skinnableManagerSWT.removeSkinnableListener(MessageBoxShell.class.toString(), uiSkinnableSWTListener);
// comment out: shell can dispose without us wanting core to be..
// dispose(false, false);
}
});
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent event) {
if (disposedOrDisposing) {
return;
}
if (COConfigurationManager.getBooleanParameter("Close To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
minimizeToTray(event);
} else {
event.doit = dispose(false, false);
}
}
@Override
public void shellActivated(ShellEvent e) {
Shell shellAppModal = Utils.findFirstShellWithStyle(SWT.APPLICATION_MODAL);
if (shellAppModal != null) {
shellAppModal.forceActive();
} else {
shell.forceActive();
}
}
@Override
public void shellIconified(ShellEvent event) {
if (disposedOrDisposing) {
return;
}
if (COConfigurationManager.getBooleanParameter("Minimize To Tray") && ((systemTraySWT != null && COConfigurationManager.getBooleanParameter("Enable System Tray")) || COConfigurationManager.getBooleanParameter("System Tray Disabled Override"))) {
minimizeToTray(event);
}
}
@Override
public void shellDeiconified(ShellEvent e) {
if (Constants.isOSX && COConfigurationManager.getBooleanParameter("Password enabled")) {
shell.setVisible(false);
if (PasswordWindow.showPasswordWindow(Utils.getDisplay())) {
shell.setVisible(true);
}
}
}
});
Utils.getDisplay().addFilter(SWT.KeyDown, new Listener() {
@Override
public void handleEvent(Event event) {
// Another window has control, skip filter
Control focus_control = event.display.getFocusControl();
if (focus_control != null && focus_control.getShell() != shell)
return;
int key = event.character;
if ((event.stateMask & SWT.MOD1) != 0 && event.character <= 26 && event.character > 0)
key += 'a' - 1;
if (key == 'l' && (event.stateMask & SWT.MOD1) != 0) {
// Ctrl-L: Open URL
if (core == null) {
return;
}
GlobalManager gm = core.getGlobalManager();
if (gm != null) {
UIFunctionsManagerSWT.getUIFunctionsSWT().openTorrentWindow();
event.doit = false;
}
} else if (key == 'd' && (event.stateMask & SWT.MOD1) != 0) {
// dump
if (Constants.isCVSVersion()) {
Utils.dump(shell);
}
} else if (key == 'f' && (event.stateMask & (SWT.MOD1 + SWT.SHIFT)) == SWT.MOD1 + SWT.SHIFT) {
shell.setFullScreen(!shell.getFullScreen());
} else if (event.keyCode == SWT.F1) {
Utils.launch(Constants.URL_WIKI);
}
}
});
increaseProgress(uiInitializer, "v3.splash.initSkin");
System.out.println("pre skin widgets init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
if (core != null) {
StimulusRPC.hookListeners(core, this);
}
increaseProgress(uiInitializer, "v3.splash.initSkin");
// 0ms
// System.out.println("hooks init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
initMDI();
System.out.println("skin widgets (1/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
initWidgets2();
increaseProgress(uiInitializer, "v3.splash.initSkin");
System.out.println("skin widgets (2/2) init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
System.out.println("pre SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
startTime = SystemTime.getCurrentTime();
TableColumnCreatorV3.initCoreColumns();
System.out.println("Init Core Columns took " + (SystemTime.getCurrentTime() - startTime) + "ms");
increaseProgress(uiInitializer, "v3.splash.hookPluginUI");
startTime = SystemTime.getCurrentTime();
// attach the UI to plugins
// Must be done before initializing views, since plugins may register
// table columns and other objects
uiSWTInstanceImpl = new UISWTInstanceImpl();
uiSWTInstanceImpl.init(uiInitializer);
System.out.println("SWTInstance init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
increaseProgress(uiInitializer, "splash.initializeGui");
startTime = SystemTime.getCurrentTime();
} catch (Throwable t) {
Debug.out(t);
} finally {
String configID = SkinConstants.VIEWID_PLUGINBAR + ".visible";
if (!ConfigurationDefaults.getInstance().doesParameterDefaultExist(configID)) {
COConfigurationManager.setBooleanDefault(configID, true);
}
setVisible(WINDOW_ELEMENT_TOPBAR, COConfigurationManager.getBooleanParameter(configID) && COConfigurationManager.getIntParameter("User Mode") > 1);
setVisible(WINDOW_ELEMENT_TOOLBAR, COConfigurationManager.getBooleanParameter("IconBar.enabled"));
shell.layout(true, true);
System.out.println("shell.layout took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
showMainWindow();
// ================
increaseProgress(uiInitializer, "splash.initializeGui");
System.out.println("shell.open took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
processStartupDMS();
System.out.println("processStartupDMS took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
if (core != null) {
postPluginSetup(core);
}
System.out.println("postPluginSetup init took " + (SystemTime.getCurrentTime() - startTime) + "ms");
startTime = SystemTime.getCurrentTime();
navigationListener = new navigationListener() {
@Override
public void processCommand(final int type, final String[] args) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (type == NavigationHelper.COMMAND_SWITCH_TO_TAB) {
MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
if (mdi == null) {
return;
}
mdi.showEntryByID(args[0]);
if (uif != null) {
uif.bringToFront();
}
} else if (type == NavigationHelper.COMMAND_CONDITION_CHECK) {
}
}
});
}
};
NavigationHelper.addListener(navigationListener);
if (!Constants.isOSX) {
configShowStatusInTitleListener = new ParameterListener() {
private TimerEventPeriodic timer;
private String old_text;
private String my_last_text;
@Override
public void parameterChanged(final String name) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
boolean enable = COConfigurationManager.getBooleanParameter(name);
if (enable) {
if (timer == null) {
timer = SimpleTimer.addPeriodicEvent("window.title.updater", 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (shell.isDisposed()) {
return;
}
String current_txt = shell.getText();
if (current_txt != null && !current_txt.equals(my_last_text)) {
old_text = current_txt;
}
String txt = getCurrentTitleText();
if (txt != null) {
if (!txt.equals(current_txt)) {
shell.setText(txt);
}
my_last_text = txt;
}
}
});
}
});
}
} else {
if (timer != null) {
timer.cancel();
timer = null;
}
if (old_text != null && !shell.isDisposed()) {
shell.setText(old_text);
}
}
}
});
}
};
COConfigurationManager.addAndFireParameterListener("Show Status In Window Title", configShowStatusInTitleListener);
}
}
}
use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.
the class MainWindowImpl method getCurrentTitleText.
private String getCurrentTitleText() {
if (core == null) {
return (null);
}
GlobalManager gm = core.getGlobalManager();
if (gm == null) {
return (null);
}
GlobalManagerStats stats = gm.getStats();
int down = stats.getDataReceiveRate() + stats.getProtocolReceiveRate();
int up = stats.getDataSendRate() + stats.getProtocolSendRate();
eta_tick_count++;
String eta_str = last_eta_str;
if (eta_str == null || last_eta < 120 || eta_tick_count % 10 == 0) {
long min_eta = Long.MAX_VALUE;
int num_downloading = 0;
List<DownloadManager> dms = gm.getDownloadManagers();
for (DownloadManager dm : dms) {
if (dm.getState() == DownloadManager.STATE_DOWNLOADING) {
num_downloading++;
long dm_eta = dm.getStats().getSmoothedETA();
if (dm_eta < min_eta) {
min_eta = dm_eta;
}
}
}
if (min_eta == Long.MAX_VALUE) {
min_eta = Constants.CRAPPY_INFINITE_AS_LONG;
}
last_eta = min_eta;
eta_str = last_eta_str = num_downloading == 0 ? "" : DisplayFormatters.formatETA(min_eta);
}
String down_str = formatRateCompact(down);
String up_str = formatRateCompact(up);
StringBuilder result = new StringBuilder(50);
result.append(MessageText.getString("ConfigView.download.abbreviated"));
result.append(" ");
result.append(down_str);
result.append(" ");
result.append(MessageText.getString("ConfigView.upload.abbreviated"));
result.append(" ");
result.append(up_str);
if (eta_str.length() > 0) {
result.append(" ");
result.append(MessageText.getString("ConfigView.eta.abbreviated"));
result.append(" ");
result.append(eta_str);
}
return (result.toString());
}
use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.
the class EnhancedDownloadManager method setProgressiveMode.
protected boolean setProgressiveMode(boolean active, boolean switching_progressive_downloads) {
TOTorrent torrent = download_manager.getTorrent();
DiskManagerFileInfo primaryFile = download_manager.getDownloadState().getPrimaryFile();
if (torrent == null || primaryFile == null) {
return (false);
}
EnhancedDownloadManagerFile enhanced_file = enhanced_files[primaryFile.getIndex()];
synchronized (this) {
if (progressive_active == active) {
return (true);
}
if (active && !supportsProgressiveMode()) {
Debug.out("Attempt to set progress mode on non-progressible content - " + getName());
return (false);
}
log("Progressive mode changed to " + active);
final GlobalManager gm = download_manager.getGlobalManager();
if (active) {
if (dmListener == null) {
dmListener = new DownloadManagerAdapter() {
@Override
public void downloadComplete(DownloadManager manager) {
enhancer.resume();
}
};
}
download_manager.addListener(dmListener);
// Check existing downloading torrents and turn off any
// existing progressive/downloading
Object[] dms = gm.getDownloadManagers().toArray();
for (int i = 0; i < dms.length; i++) {
DownloadManager dmCheck = (DownloadManager) dms[i];
if (dmCheck.equals(download_manager)) {
continue;
}
if (!dmCheck.isDownloadComplete(false)) {
int state = dmCheck.getState();
if (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_QUEUED) {
enhancer.pause(dmCheck);
}
EnhancedDownloadManager edmCheck = enhancer.getEnhancedDownload(dmCheck);
if (edmCheck != null && edmCheck.getProgressiveMode()) {
edmCheck.setProgressiveMode(false, true);
}
}
}
if (download_manager.isPaused()) {
enhancer.resume(download_manager);
}
// and putting at top
if (download_manager.getState() == DownloadManager.STATE_STOPPED) {
download_manager.setStateWaiting();
}
if (download_manager.getPosition() != 1) {
download_manager.getGlobalManager().moveTo(download_manager, 1);
}
} else {
download_manager.removeListener(dmListener);
if (!switching_progressive_downloads) {
enhancer.resume();
}
}
progressive_active = active;
if (progressive_active) {
enhancer.progressiveActivated();
}
if (current_piece_pickler != null) {
if (progressive_active) {
buffer_provider.activate(current_piece_pickler);
progressive_stats.update(0);
} else {
buffer_provider.deactivate(current_piece_pickler);
progressive_stats = createProgressiveStats(download_manager, enhanced_file);
}
} else {
progressive_stats = createProgressiveStats(download_manager, enhanced_file);
}
if (!switching_progressive_downloads) {
if (active) {
RealTimeInfo.setProgressiveActive(progressive_stats.getStreamBytesPerSecondMax());
} else {
RealTimeInfo.setProgressiveInactive();
}
}
}
return (true);
}
use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.
the class DownloadManagerEnhancer method resume.
protected void resume() {
Set<HashWrapper> copy;
synchronized (pause_set) {
copy = new HashSet<>(pause_set);
pause_set.clear();
}
GlobalManager gm = core.getGlobalManager();
for (HashWrapper hw : copy) {
DownloadManager dm = gm.getDownloadManager(hw);
if (dm != null) {
dm.resume();
}
}
}
Aggregations