use of com.biglybt.core.stats.transfer.OverallStats in project BiglyBT by BiglySoftware.
the class DonationWindow method checkForDonationPopup.
public static void checkForDonationPopup() {
if (shell != null) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Already Open").open(null);
}
return;
}
long maxDate = COConfigurationManager.getLongParameter("donations.maxDate", 0);
boolean force = maxDate > 0 && SystemTime.getCurrentTime() > maxDate;
// Check if user has already donated first
boolean alreadyDonated = COConfigurationManager.getBooleanParameter("donations.donated", false);
if (alreadyDonated && !force) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Already Donated! I like you.").open(null);
}
return;
}
OverallStats stats = StatsFactory.getStats();
if (stats == null) {
return;
}
long upTime = stats.getTotalUpTime();
// secs * mins
int hours = (int) (upTime / (60 * 60));
// Ask every DONATIONS_ASK_AFTER hours.
int nextAsk = COConfigurationManager.getIntParameter("donations.nextAskHours", 0);
if (nextAsk == 0) {
// First Time
COConfigurationManager.setParameter("donations.nextAskHours", hours + initialAskHours);
COConfigurationManager.save();
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Newbie. You're active for " + hours + ".").open(null);
}
return;
}
if (hours < nextAsk && !force) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Wait " + (nextAsk - hours) + ".").open(null);
}
return;
}
long minDate = COConfigurationManager.getLongParameter("donations.minDate", 0);
if (minDate > 0 && minDate > SystemTime.getCurrentTime()) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donation Test", "Wait " + ((SystemTime.getCurrentTime() - minDate) / 1000 / 3600 / 24) + " days").open(null);
}
return;
}
COConfigurationManager.setParameter("donations.nextAskHours", hours + reAskEveryHours);
COConfigurationManager.save();
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
open(false, "check");
}
});
}
use of com.biglybt.core.stats.transfer.OverallStats in project BiglyBT by BiglySoftware.
the class MainStatusBar method _addFeedBack.
private void _addFeedBack() {
/*
* Feedback
*
*/
// only show after restart after 15 mins uptime
OverallStats stats = StatsFactory.getStats();
long secs_uptime = stats.getTotalUpTime();
long last_uptime = COConfigurationManager.getLongParameter("statusbar.feedback.uptime", 0);
if (last_uptime == 0) {
COConfigurationManager.setParameter("statusbar.feedback.uptime", secs_uptime);
} else if (secs_uptime - last_uptime > 15 * 60) {
createStatusEntry(new CLabelUpdater() {
@Override
public boolean update(CLabelPadding label) {
return (false);
}
@Override
public void created(CLabelPadding feedback) {
feedback.setText(MessageText.getString("statusbar.feedback"));
Listener feedback_listener = new Listener() {
@Override
public void handleEvent(Event e) {
String url = "feedback.start?" + Utils.getWidgetBGColorURLParam() + "&fromWeb=false&os.name=" + UrlUtils.encode(Constants.OSName) + "&os.version=" + UrlUtils.encode(System.getProperty("os.version")) + "&java.version=" + UrlUtils.encode(Constants.JAVA_VERSION);
// Utils.launch( url );
UIFunctionsManagerSWT.getUIFunctionsSWT().viewURL(url, null, 600, 520, true, false);
}
};
feedback.setToolTipText(MessageText.getString("statusbar.feedback.tooltip"));
feedback.setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
feedback.setForeground(Colors.blue);
feedback.addListener(SWT.MouseUp, feedback_listener);
feedback.addListener(SWT.MouseDoubleClick, feedback_listener);
feedback.setVisible(true);
}
});
}
}
use of com.biglybt.core.stats.transfer.OverallStats in project BiglyBT by BiglySoftware.
the class MainStatusBar method initStatusBar.
/**
* @return composite holding the statusbar
*/
public Composite initStatusBar(final Composite _parent) {
this.parent = _parent;
this.display = parent.getDisplay();
this.uiFunctions = UIFunctionsManager.getUIFunctions();
ImageLoader imageLoader = ImageLoader.getInstance();
FormData formData;
Color fgColor = parent.getForeground();
statusBar = new Composite(parent, SWT.NONE);
statusBar.setForeground(fgColor);
isAZ3 = "az3".equalsIgnoreCase(COConfigurationManager.getStringParameter("ui"));
statusBar.getShell().addListener(SWT.Deiconify, new Listener() {
@Override
public void handleEvent(Event event) {
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
if (!statusBar.isDisposed()) {
statusBar.layout();
}
}
});
}
});
statusBar.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (uiFunctions != null) {
UIUpdater uiUpdater = uiFunctions.getUIUpdater();
if (uiUpdater != null) {
uiUpdater.removeUpdater(MainStatusBar.this);
}
}
PRManager.removeListener(progressListener);
Utils.disposeSWTObjects(imgRec, imgSent);
Utils.removeParameterListeners(mapConfigListeners);
if (alert_flasher_event != null) {
alert_flasher_event.cancel();
alert_flasher_event = null;
}
if (alertHistoryListener != null) {
Alerts.removeMessageHistoryListener(alertHistoryListener);
alertHistoryListener = null;
}
}
});
GridLayout layout_status = new GridLayout();
layout_status.numColumns = 20;
layout_status.horizontalSpacing = 0;
layout_status.verticalSpacing = 0;
layout_status.marginHeight = 0;
if (Constants.isOSX) {
// OSX has a resize widget on the bottom right. It's about 15px wide.
try {
layout_status.marginRight = 15;
} catch (NoSuchFieldError e) {
// Pre SWT 3.1
layout_status.marginWidth = 15;
}
} else {
layout_status.marginWidth = 0;
}
statusBar.setLayout(layout_status);
// Either the Status Text
statusText = new CLabel(statusBar, borderFlag);
statusText.setForeground(fgColor);
Utils.setLayoutData(statusText, new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
addStatusBarMenu(statusText);
GC gc = new GC(statusText);
// add 6, because CLabel forces a 3 pixel indent
int height = Math.max(16, gc.getFontMetrics().getHeight()) + 6;
gc.dispose();
formData = new FormData();
formData.height = height;
// 2 params for Pre SWT 3.0
formData.bottom = new FormAttachment(100, 0);
// 2 params for Pre SWT 3.0
formData.left = new FormAttachment(0, 0);
// 2 params for Pre SWT 3.0
formData.right = new FormAttachment(100, 0);
statusBar.setLayoutData(formData);
Listener listener = new Listener() {
@Override
public void handleEvent(Event e) {
if (clickListener == null) {
if (updateWindow != null) {
updateWindow.show();
}
} else {
clickListener.UIStatusTextClicked();
}
}
};
statusText.addListener(SWT.MouseUp, listener);
statusText.addListener(SWT.MouseDoubleClick, listener);
// KN: Don't know why OSX is treated differently but this check was already here from the previous code
if (Constants.isOSX) {
progressBar = new AZProgressBar(statusBar, true);
} else {
progressBar = new AZProgressBar(statusBar, false);
}
progressBar.setVisible(false);
progressGridData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
progressGridData.widthHint = 5;
Utils.setLayoutData(progressBar, progressGridData);
// addRIP();
/*
* Progress reporting window image label
*/
progressViewerImageLabel = new CLabelPadding(statusBar, SWT.NONE);
// image set below after adding listener
progressViewerImageLabel.setToolTipText(MessageText.getString("Progress.reporting.statusbar.button.tooltip"));
progressViewerImageLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
/*
* Opens the progress viewer if any of the reporters in the array is NOT already opened
* KN: TODO -- This is only a partial solution to minimize the occurrence of the main progress window
* opening more than once. The one remaining case where multiple windows will still open is
* when you have one opened already... then run another process such as a torrent file download...
* at this point this new process is not in the already opened window so the check would
* allow the second window to open.
*/
IProgressReporter[] reporters = PRManager.getReportersArray(false);
if (reporters.length == 0) {
/*
* If there's nothing to see then open the window; the default widow will say there's nothing to see
* KN: calling isShowingEmpty return true is there is already a window opened showing the empty panel
*/
if (!ProgressReporterWindow.isShowingEmpty()) {
ProgressReporterWindow.open(reporters, ProgressReporterWindow.SHOW_TOOLBAR);
}
} else {
for (int i = 0; i < reporters.length; i++) {
if (!ProgressReporterWindow.isOpened(reporters[i])) {
ProgressReporterWindow.open(reporters, ProgressReporterWindow.SHOW_TOOLBAR);
break;
}
}
}
}
});
progressViewerImageLabel.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.releaseImage("progress_error");
imageLoader.releaseImage("progress_info");
imageLoader.releaseImage("progress_viewer");
}
});
this.plugin_label_composite = new Composite(statusBar, SWT.NONE);
this.plugin_label_composite.setForeground(fgColor);
GridLayout gridLayout = new GridLayout();
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = 0;
gridLayout.marginBottom = 0;
gridLayout.marginTop = 0;
gridLayout.marginLeft = 0;
gridLayout.marginRight = 0;
// Something nice and big. :)
gridLayout.numColumns = 20;
GridData gridData = new GridData(GridData.FILL_VERTICAL);
gridData.heightHint = height;
gridData.minimumHeight = height;
plugin_label_composite.setLayout(gridLayout);
plugin_label_composite.setLayoutData(gridData);
srStatus = new CLabelPadding(statusBar, borderFlag);
srStatus.setText(MessageText.getString("SpeedView.stats.ratio"));
Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show SR", new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
srStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
natStatus = new CLabelPadding(statusBar, borderFlag);
natStatus.setText("");
final Menu natStatusMenu = new Menu(statusBar.getShell(), SWT.POP_UP);
natStatus.setMenu(natStatusMenu);
MenuItem nat_test = new MenuItem(natStatusMenu, SWT.PUSH);
Messages.setLanguageText(nat_test, "MainWindow.menu.tools.nattest");
nat_test.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
new NatTestWindow();
}
});
Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show NAT", new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
natStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
dhtStatus = new CLabelPadding(statusBar, borderFlag);
dhtStatus.setText("");
dhtStatus.setToolTipText(MessageText.getString("MainWindow.dht.status.tooltip"));
Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show DDB", new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
dhtStatus.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
// ip filters
ipBlocked = new CLabelPadding(statusBar, borderFlag);
// $NON-NLS-1$
ipBlocked.setText("{} IPs:");
Messages.setLanguageText(ipBlocked, "MainWindow.IPs.tooltip");
ipBlocked.addListener(SWT.MouseDoubleClick, new ListenerNeedingCoreRunning() {
@Override
public void handleEvent(Core core, Event event) {
BlockedIpsWindow.showBlockedIps(core, parent.getShell());
}
});
final Menu menuIPFilter = new Menu(statusBar.getShell(), SWT.POP_UP);
ipBlocked.setMenu(menuIPFilter);
menuIPFilter.addListener(SWT.Show, new Listener() {
@Override
public void handleEvent(Event e) {
MenuItem[] oldItems = menuIPFilter.getItems();
for (int i = 0; i < oldItems.length; i++) {
oldItems[i].dispose();
}
if (!CoreFactory.isCoreRunning()) {
return;
}
Core core = CoreFactory.getSingleton();
final IpFilter ip_filter = core.getIpFilterManager().getIPFilter();
final MenuItem ipfEnable = new MenuItem(menuIPFilter, SWT.CHECK);
ipfEnable.setSelection(ip_filter.isEnabled());
Messages.setLanguageText(ipfEnable, "MyTorrentsView.menu.ipf_enable");
ipfEnable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ip_filter.setEnabled(ipfEnable.getSelection());
}
});
final MenuItem ipfOptions = new MenuItem(menuIPFilter, SWT.PUSH);
Messages.setLanguageText(ipfOptions, "ipfilter.options");
ipfOptions.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, "ipfilter");
}
}
});
}
});
Utils.addAndFireParameterListener(mapConfigListeners, true, "Status Area Show IPF", new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
ipBlocked.setVisible(COConfigurationManager.getBooleanParameter(parameterName));
statusBar.layout();
}
});
// down speed
statusDown = new CLabelPadding(statusBar, borderFlag);
statusDown.setImage(imageLoader.getImage("down"));
// statusDown.setText(/*MessageText.getString("ConfigView.download.abbreviated") +*/"n/a");
Messages.setLanguageText(statusDown, "MainWindow.status.updowndetails.tooltip");
Listener lStats = new Listener() {
@Override
public void handleEvent(Event e) {
uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "TransferStatsView");
}
};
statusUp = new CLabelPadding(statusBar, borderFlag);
statusUp.setImage(imageLoader.getImage("up"));
// statusUp.setText(/*MessageText.getString("ConfigView.upload.abbreviated") +*/"n/a");
Messages.setLanguageText(statusUp, "MainWindow.status.updowndetails.tooltip");
statusDown.addListener(SWT.MouseDoubleClick, lStats);
statusUp.addListener(SWT.MouseDoubleClick, lStats);
Listener lDHT = new Listener() {
@Override
public void handleEvent(Event e) {
uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "DHTView");
}
};
dhtStatus.addListener(SWT.MouseDoubleClick, lDHT);
Listener lSR = new Listener() {
@Override
public void handleEvent(Event e) {
uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "SpeedView");
OverallStats stats = StatsFactory.getStats();
if (stats == null) {
return;
}
long ratio = (1000 * stats.getUploadedBytes() / (stats.getDownloadedBytes() + 1));
if (ratio < 900) {
// Utils.launch(Constants.AZUREUS_WIKI + "Share_Ratio");
}
}
};
srStatus.addListener(SWT.MouseDoubleClick, lSR);
Listener lNAT = new ListenerNeedingCoreRunning() {
@Override
public void handleEvent(Core core, Event e) {
uiFunctions.getMDI().loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, true, false, ConfigSection.SECTION_CONNECTION);
if (PluginInitializer.getDefaultInterface().getConnectionManager().getNATStatus() != ConnectionManager.NAT_OK) {
Utils.launch(Constants.AZUREUS_WIKI + "NAT_problem");
}
}
};
natStatus.addListener(SWT.MouseDoubleClick, lNAT);
boolean bSpeedMenu = COConfigurationManager.getBooleanParameter("GUI_SWT_bOldSpeedMenu");
if (bSpeedMenu) {
// Status Bar Menu construction
final Menu menuUpSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
menuUpSpeed.addListener(SWT.Show, new Listener() {
@Override
public void handleEvent(Event e) {
if (!CoreFactory.isCoreRunning()) {
return;
}
Core core = CoreFactory.getSingleton();
GlobalManager globalManager = core.getGlobalManager();
SelectableSpeedMenu.generateMenuItems(menuUpSpeed, core, globalManager, true);
}
});
statusUp.setMenu(menuUpSpeed);
} else {
statusUp.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
return;
}
Event event = new Event();
event.type = SWT.MouseUp;
event.widget = e.widget;
event.stateMask = e.stateMask;
event.button = e.button;
e.widget.getDisplay().post(event);
CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
SelectableSpeedMenu.invokeSlider(statusUp, core, true);
}
});
}
});
}
if (bSpeedMenu) {
final Menu menuDownSpeed = new Menu(statusBar.getShell(), SWT.POP_UP);
menuDownSpeed.addListener(SWT.Show, new Listener() {
@Override
public void handleEvent(Event e) {
if (!CoreFactory.isCoreRunning()) {
return;
}
Core core = CoreFactory.getSingleton();
GlobalManager globalManager = core.getGlobalManager();
SelectableSpeedMenu.generateMenuItems(menuDownSpeed, core, globalManager, false);
}
});
statusDown.setMenu(menuDownSpeed);
} else {
statusDown.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))) {
return;
}
Event event = new Event();
event.type = SWT.MouseUp;
event.widget = e.widget;
event.stateMask = e.stateMask;
event.button = e.button;
e.widget.getDisplay().post(event);
CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
SelectableSpeedMenu.invokeSlider(statusDown, core, false);
}
});
}
});
}
statusWarnings = new CLabelPadding(statusBar, borderFlag);
warningIcon = imageLoader.getImage("image.sidebar.vitality.alert");
warningGreyIcon = imageLoader.getImage("image.sidebar.vitality.alert-gray");
infoIcon = imageLoader.getImage("image.sidebar.vitality.info");
updateStatusWarnings(null, false);
Messages.setLanguageText(statusWarnings, "MainWindow.status.warning.tooltip");
alertHistoryListener = new AlertHistoryListener() {
@Override
public void alertHistoryAdded(LogAlert alert) {
updateStatusWarnings(alert, true);
}
@Override
public void alertHistoryRemoved(LogAlert alert) {
updateStatusWarnings(alert, false);
}
};
Alerts.addMessageHistoryListener(alertHistoryListener);
statusWarnings.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
if (e.button != 1) {
return;
}
if (SystemWarningWindow.numWarningWindowsOpen > 0) {
return;
}
ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
if (alerts.size() == 0) {
return;
}
Shell shell = statusWarnings.getShell();
Rectangle bounds = statusWarnings.getClientArea();
Point ptBottomRight = statusWarnings.toDisplay(bounds.x + bounds.width, bounds.y);
new SystemWarningWindow(alerts.get(0), ptBottomRight, shell, 0);
}
@Override
public void mouseDown(MouseEvent e) {
}
@Override
public void mouseDoubleClick(MouseEvent e) {
}
});
Menu menuStatusWarnings = new Menu(statusBar.getShell(), SWT.POP_UP);
statusWarnings.setMenu(menuStatusWarnings);
final MenuItem dismissAllItem = new MenuItem(menuStatusWarnings, SWT.PUSH);
menuStatusWarnings.addListener(SWT.Show, new Listener() {
@Override
public void handleEvent(Event e) {
dismissAllItem.setEnabled(Alerts.getUnviewedLogAlerts().size() > 0);
}
});
Messages.setLanguageText(dismissAllItem, "label.dismiss.all");
dismissAllItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
ArrayList<LogAlert> alerts = Alerts.getUnviewedLogAlerts();
for (LogAlert a : alerts) {
Alerts.markAlertAsViewed(a);
}
}
});
Utils.addAndFireParameterListener(mapConfigListeners, true, "status.rategraphs", new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
boolean doRateGraphs = COConfigurationManager.getBooleanParameter("status.rategraphs");
if (doRateGraphs) {
if (imgRec == null || imgRec.isDisposed()) {
imgRec = new Image(display, 100, 20);
GC gc = new GC(imgRec);
gc.setBackground(statusDown.getBackground());
gc.fillRectangle(0, 0, 100, 20);
gc.dispose();
statusDown.setBackgroundImage(imgRec);
}
if (imgSent == null || imgSent.isDisposed()) {
imgSent = new Image(display, 100, 20);
GC gc = new GC(imgSent);
gc.setBackground(statusUp.getBackground());
gc.fillRectangle(0, 0, 100, 20);
gc.dispose();
statusUp.setBackgroundImage(imgSent);
}
} else {
statusUp.setBackgroundImage(null);
statusDown.setBackgroundImage(null);
Utils.disposeSWTObjects(imgRec, imgSent);
imgRec = imgSent = null;
}
}
});
// ///////
progressListener = new ProgressListener();
PRManager.addListener(progressListener);
uiFunctions.getUIUpdater().addUpdater(this);
ArrayList<Runnable> list;
this_mon.enter();
try {
list = listRunAfterInit;
listRunAfterInit = null;
} finally {
this_mon.exit();
}
for (Runnable runnable : list) {
try {
runnable.run();
} catch (Exception e) {
Debug.out(e);
}
}
statusBar.layout(true);
return statusBar;
}
use of com.biglybt.core.stats.transfer.OverallStats in project BiglyBT by BiglySoftware.
the class VersionCheckClient method constructVersionCheckMessage.
/**
* Construct the default version check message.
* @return message to send
*/
public static Map<String, Object> constructVersionCheckMessage(String reason) {
// only send if anonymous-check flag is not set
boolean send_info = COConfigurationManager.getBooleanParameter("Send Version Info");
Map<String, Object> message = new HashMap<>();
// always send
message.put("appid", SystemProperties.getApplicationIdentifier());
message.put("appname", SystemProperties.getApplicationName());
message.put("version", Constants.AZUREUS_VERSION);
message.put("first_version", COConfigurationManager.getStringParameter("First Recorded Version", ""));
String sub_ver = Constants.AZUREUS_SUBVER;
if (sub_ver.length() > 0) {
message.put("subver", sub_ver);
}
if (COConfigurationManager.getBooleanParameter("Beta Programme Enabled")) {
message.put("beta_prog", "true");
}
message.put("ui", COConfigurationManager.getStringParameter("ui", "unknown"));
message.put("os", Constants.OSName);
message.put("os_version", System.getProperty("os.version"));
// see http://lopica.sourceforge.net/os.html
message.put("os_arch", System.getProperty("os.arch"));
// might be needed to openjdk on osx
message.put("os_arch_dm", System.getProperty("sun.arch.data.model"));
boolean using_phe = COConfigurationManager.getBooleanParameter("network.transport.encrypted.require");
message.put("using_phe", using_phe ? new Long(1) : new Long(0));
message.put("imode", COConfigurationManager.getStringParameter("installer.mode", ""));
// swt stuff
try {
Class c = Class.forName("org.eclipse.swt.SWT");
String swt_platform = (String) c.getMethod("getPlatform", new Class[] {}).invoke(null, new Object[] {});
message.put("swt_platform", swt_platform);
Integer swt_version = (Integer) c.getMethod("getVersion", new Class[] {}).invoke(null, new Object[] {});
message.put("swt_version", new Long(swt_version.longValue()));
} catch (ClassNotFoundException e) {
/* ignore */
} catch (NoClassDefFoundError er) {
/* ignore */
} catch (InvocationTargetException err) {
/* ignore */
} catch (Throwable t) {
t.printStackTrace();
}
int last_send_time = COConfigurationManager.getIntParameter("Send Version Info Last Time", -1);
int current_send_time = (int) (SystemTime.getCurrentTime() / 1000);
COConfigurationManager.setParameter("Send Version Info Last Time", current_send_time);
String id = COConfigurationManager.getStringParameter("ID", null);
if (id != null && send_info) {
message.put("id", id);
try {
byte[] id2 = CryptoManagerFactory.getSingleton().getSecureID();
message.put("id2", id2);
} catch (Throwable e) {
}
if (last_send_time != -1 && last_send_time < current_send_time) {
// time since last
message.put("tsl", new Long(current_send_time - last_send_time));
}
message.put("reason", reason);
String java_version = Constants.JAVA_VERSION;
if (java_version == null) {
java_version = "unknown";
}
message.put("java", java_version);
String java_vendor = System.getProperty("java.vm.vendor");
if (java_vendor == null) {
java_vendor = "unknown";
}
message.put("javavendor", java_vendor);
int api_level = Constants.API_LEVEL;
if (api_level > 0) {
message.put("api_level", api_level);
}
long max_mem = Runtime.getRuntime().maxMemory() / (1024 * 1024);
message.put("javamx", new Long(max_mem));
String java_rt_name = System.getProperty("java.runtime.name");
if (java_rt_name != null) {
message.put("java_rt_name", java_rt_name);
}
String java_rt_version = System.getProperty("java.runtime.version");
if (java_rt_version != null) {
message.put("java_rt_version", java_rt_version);
}
OverallStats stats = StatsFactory.getStats();
if (stats != null) {
// long total_bytes_downloaded = stats.getDownloadedBytes();
// long total_bytes_uploaded = stats.getUploadedBytes();
long total_uptime = stats.getTotalUpTime();
// removed due to complaints about anonymous stats collection
// message.put( "total_bytes_downloaded", new Long( total_bytes_downloaded ) );
// message.put( "total_bytes_uploaded", new Long( total_bytes_uploaded ) );
message.put("total_uptime", new Long(total_uptime));
// message.put( "dlstats", stats.getDownloadStats());
}
try {
int port = UDPNetworkManager.getSingleton().getUDPNonDataListeningPortNumber();
message.put("dht", port);
} catch (Throwable e) {
Debug.out(e);
}
try {
NetworkAdminASN current_asn = NetworkAdmin.getSingleton().getCurrentASN();
message.put("ip_as", current_asn.getAS());
String asn = current_asn.getASName();
if (asn.length() > 64) {
asn = asn.substring(0, 64);
}
message.put("ip_asn", asn);
} catch (Throwable e) {
Debug.out(e);
}
// send locale, so we can determine which languages need attention
message.put("locale", Locale.getDefault().toString());
String originalLocale = System.getProperty("user.language") + "_" + System.getProperty("user.country");
String variant = System.getProperty("user.variant");
if (variant != null && variant.length() > 0) {
originalLocale += "_" + variant;
}
message.put("orig_locale", originalLocale);
// We may want to reply differently if the user is in Beginner mode vs Advanced
message.put("user_mode", COConfigurationManager.getIntParameter("User Mode", -1));
try {
if (CoreFactory.isCoreAvailable() && CoreFactory.getSingleton().getPluginManager().isInitialized()) {
// installed plugin IDs
PluginInterface[] plugins = CoreFactory.getSingleton().getPluginManager().getPluginInterfaces();
List pids = new ArrayList();
List vs_data = new ArrayList();
for (int i = 0; i < plugins.length; i++) {
PluginInterface plugin = plugins[i];
String pid = plugin.getPluginID();
String info = plugin.getPluginconfig().getPluginStringParameter("plugin.info");
// filter out built-in and core ones
if ((info != null && info.length() > 0) || (!pid.startsWith("<") && !pid.startsWith("azbp") && !pid.startsWith("azupdater") && !pid.startsWith("azplatform") && !pids.contains(pid))) {
if (info != null && info.length() > 0) {
if (info.length() < 256) {
pid += ":" + info;
} else {
Debug.out("Plugin '" + pid + "' reported excessive info string '" + info + "'");
}
}
pids.add(pid);
}
Map data = plugin.getPluginconfig().getPluginMapParameter("plugin.versionserver.data", null);
if (data != null) {
Map payload = new HashMap();
byte[] data_bytes = BEncoder.encode(data);
if (data_bytes.length > 16 * 1024) {
Debug.out("Plugin '" + pid + "' reported excessive version server data (length=" + data_bytes.length + ")");
payload.put("error", "data too long: " + data_bytes.length);
} else {
payload.put("data", data_bytes);
}
payload.put("id", pid);
payload.put("version", plugin.getPluginVersion());
vs_data.add(payload);
}
}
message.put("plugins", pids);
if (vs_data.size() > 0) {
message.put("plugin_data", vs_data);
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
return message;
}
use of com.biglybt.core.stats.transfer.OverallStats in project BiglyBT by BiglySoftware.
the class ConfigSectionStats method configSectionCreate.
@Override
public Composite configSectionCreate(final Composite parent) {
ImageLoader imageLoader = ImageLoader.getInstance();
Image imgOpenFolder = imageLoader.getImage("openFolderButton");
GridData gridData;
GridLayout layout;
Composite gOutter = new Composite(parent, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
gOutter.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 1;
gOutter.setLayout(layout);
// general
Group gGeneral = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gGeneral, "ConfigView.section.general");
layout = new GridLayout(2, false);
gGeneral.setLayout(layout);
gGeneral.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label lSmooth = new Label(gGeneral, SWT.NULL);
Messages.setLanguageText(lSmooth, "stats.general.smooth_secs");
IntParameter smooth_secs = new IntParameter(gGeneral, "Stats Smoothing Secs", 30, 30 * 60);
// display
Group gDisplay = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gDisplay, "stats.display.group");
layout = new GridLayout(1, false);
gDisplay.setLayout(layout);
gDisplay.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
gridData = new GridData();
BooleanParameter graph_dividers = new BooleanParameter(gDisplay, "Stats Graph Dividers", "ConfigView.section.stats.graph_update_dividers");
graph_dividers.setLayoutData(gridData);
// snapshots
Group gSnap = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gSnap, "stats.snapshot.group");
layout = new GridLayout(3, false);
gSnap.setLayout(layout);
gSnap.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// row
gridData = new GridData();
gridData.horizontalSpan = 3;
BooleanParameter enableStats = new BooleanParameter(gSnap, "Stats Enable", "ConfigView.section.stats.enable");
enableStats.setLayoutData(gridData);
Control[] controls = new Control[13];
// row
Label lStatsPath = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lStatsPath, "ConfigView.section.stats.defaultsavepath");
gridData = new GridData();
gridData.widthHint = 150;
// $NON-NLS-1$ //$NON-NLS-2$
final StringParameter pathParameter = new StringParameter(gSnap, "Stats Dir", "");
pathParameter.setLayoutData(gridData);
controls[0] = lStatsPath;
controls[1] = pathParameter.getControl();
Button browse = new Button(gSnap, SWT.PUSH);
browse.setImage(imgOpenFolder);
imgOpenFolder.setBackground(browse.getBackground());
browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
controls[2] = browse;
browse.addListener(SWT.Selection, new Listener() {
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
@Override
public void handleEvent(Event event) {
DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
dialog.setFilterPath(pathParameter.getValue());
// $NON-NLS-1$
dialog.setText(MessageText.getString("ConfigView.section.stats.choosedefaultsavepath"));
String path = dialog.open();
if (path != null) {
pathParameter.setValue(path);
}
}
});
// row
Label lSaveFile = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lSaveFile, "ConfigView.section.stats.savefile");
controls[3] = lSaveFile;
gridData = new GridData();
gridData.widthHint = 150;
final StringParameter fileParameter = new StringParameter(gSnap, "Stats File", StatsWriterPeriodic.DEFAULT_STATS_FILE_NAME);
fileParameter.setLayoutData(gridData);
controls[4] = fileParameter.getControl();
new Label(gSnap, SWT.NULL);
// row
Label lxslFile = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lxslFile, "ConfigView.section.stats.xslfile");
controls[5] = lxslFile;
gridData = new GridData();
gridData.widthHint = 150;
final StringParameter xslParameter = new StringParameter(gSnap, "Stats XSL File", "");
xslParameter.setLayoutData(gridData);
controls[6] = xslParameter.getControl();
Label lxslDetails = new Label(gSnap, SWT.NULL);
// $NON-NLS-1$
Messages.setLanguageText(lxslDetails, "ConfigView.section.stats.xslfiledetails");
final String linkFAQ = Constants.PLUGINS_WEB_SITE + "faq.php#20";
lxslDetails.setCursor(lxslDetails.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
lxslDetails.setForeground(Colors.blue);
lxslDetails.setData(linkFAQ);
lxslDetails.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
Utils.launch(linkFAQ);
}
@Override
public void mouseDown(MouseEvent arg0) {
Utils.launch(linkFAQ);
}
});
ClipboardCopy.addCopyToClipMenu(lxslDetails);
controls[7] = lxslDetails;
// row
Label lSaveFreq = new Label(gSnap, SWT.NULL);
Messages.setLanguageText(lSaveFreq, "ConfigView.section.stats.savefreq");
controls[8] = lSaveFreq;
final String[] spLabels = new String[statsPeriods.length];
final int[] spValues = new int[statsPeriods.length];
for (int i = 0; i < statsPeriods.length; i++) {
int num = statsPeriods[i];
if (num % 3600 == 0)
spLabels[i] = " " + (statsPeriods[i] / 3600) + " " + MessageText.getString("ConfigView.section.stats.hours");
else if (num % 60 == 0)
spLabels[i] = " " + (statsPeriods[i] / 60) + " " + MessageText.getString("ConfigView.section.stats.minutes");
else
spLabels[i] = " " + statsPeriods[i] + " " + MessageText.getString("ConfigView.section.stats.seconds");
spValues[i] = statsPeriods[i];
}
controls[9] = lSaveFreq;
controls[10] = new IntListParameter(gSnap, "Stats Period", defaultStatsPeriod, spLabels, spValues).getControl();
new Label(gSnap, SWT.NULL);
// ROW
gridData = new GridData();
gridData.horizontalSpan = 3;
BooleanParameter exportPeers = new BooleanParameter(gSnap, "Stats Export Peer Details", "ConfigView.section.stats.exportpeers");
exportPeers.setLayoutData(gridData);
controls[11] = exportPeers.getControl();
// ROW
gridData = new GridData();
gridData.horizontalSpan = 3;
BooleanParameter exportFiles = new BooleanParameter(gSnap, "Stats Export File Details", "ConfigView.section.stats.exportfiles");
exportFiles.setLayoutData(gridData);
controls[12] = exportFiles.getControl();
// control stuff
enableStats.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(controls));
// xfer
Group gXfer = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gXfer, "ConfigView.section.transfer");
layout = new GridLayout(3, false);
gXfer.setLayout(layout);
gXfer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
List<Button> buttons = new ArrayList<>();
// set mark
Label set_mark_label = new Label(gXfer, SWT.NULL);
Messages.setLanguageText(set_mark_label, "ConfigView.section.transfer.setmark");
Button set_mark_button = new Button(gXfer, SWT.PUSH);
buttons.add(set_mark_button);
Messages.setLanguageText(set_mark_button, "Button.set");
set_mark_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
OverallStats stats = StatsFactory.getStats();
stats.setMark();
}
});
Button clear_mark_button = new Button(gXfer, SWT.PUSH);
buttons.add(clear_mark_button);
Messages.setLanguageText(clear_mark_button, "Button.clear");
clear_mark_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
OverallStats stats = StatsFactory.getStats();
stats.clearMark();
}
});
// long term
Group gLong = new Group(gOutter, SWT.NULL);
Messages.setLanguageText(gLong, "stats.longterm.group");
layout = new GridLayout(2, false);
gLong.setLayout(layout);
gLong.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// row
gridData = new GridData();
gridData.horizontalSpan = 2;
BooleanParameter enableLongStats = new BooleanParameter(gLong, "long.term.stats.enable", "ConfigView.section.stats.enable");
enableLongStats.setLayoutData(gridData);
// week start
Label lWeekStart = new Label(gLong, SWT.NULL);
Messages.setLanguageText(lWeekStart, "stats.long.weekstart");
final String[] wsLabels = new String[7];
final int[] wsValues = new int[7];
Calendar cal = new GregorianCalendar();
SimpleDateFormat format = new SimpleDateFormat("E");
for (int i = 0; i < 7; i++) {
// sun = 1 etc
int dow = i + 1;
cal.set(Calendar.DAY_OF_WEEK, dow);
wsLabels[i] = format.format(cal.getTime());
wsValues[i] = i + 1;
}
IntListParameter week_start = new IntListParameter(gLong, "long.term.stats.weekstart", Calendar.SUNDAY, wsLabels, wsValues);
// month start
Label lMonthStart = new Label(gLong, SWT.NULL);
Messages.setLanguageText(lMonthStart, "stats.long.monthstart");
IntParameter month_start = new IntParameter(gLong, "long.term.stats.monthstart", 1, 28);
enableLongStats.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(new Control[] { lWeekStart, lMonthStart }));
enableLongStats.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(week_start, month_start));
// reset
Label lt_reset_label = new Label(gLong, SWT.NULL);
Messages.setLanguageText(lt_reset_label, "ConfigView.section.transfer.lts.reset");
Button lt_reset_button = new Button(gLong, SWT.PUSH);
buttons.add(lt_reset_button);
Messages.setLanguageText(lt_reset_button, "Button.clear");
lt_reset_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("ConfigView.section.security.resetcerts.warning.title"), MessageText.getString("ConfigView.section.transfer.ltsreset.warning.msg"));
mb.setDefaultButtonUsingStyle(SWT.CANCEL);
mb.setParent(parent.getShell());
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int returnVal) {
if (returnVal != SWT.OK) {
return;
}
Utils.getOffOfSWTThread(new AERunnable() {
@Override
public void runSupport() {
StatsFactory.clearLongTermStats();
}
});
}
});
}
});
Utils.makeButtonsEqualWidth(buttons);
return gOutter;
}
Aggregations