use of com.biglybt.pif.PluginConfig in project BiglyBT by BiglySoftware.
the class BuddyPluginViewInstance method createClassic.
private void createClassic(Composite main) {
GridLayout layout = new GridLayout();
layout.numColumns = 1;
main.setLayout(layout);
GridData grid_data = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(main, grid_data);
// info
Composite info_area = new Composite(main, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 4;
layout.marginHeight = 0;
layout.marginWidth = 0;
info_area.setLayout(layout);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.horizontalSpan = 3;
Utils.setLayoutData(info_area, grid_data);
Label label = new Label(info_area, SWT.NULL);
label.setText(lu.getLocalisedMessageText("azbuddy.classic.info"));
new LinkLabel(info_area, "ConfigView.label.please.visit.here", lu.getLocalisedMessageText("azbuddy.classic.link.url"));
label = new Label(info_area, SWT.NULL);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
label.setLayoutData(grid_data);
final Button config_button = new Button(info_area, SWT.NULL);
config_button.setText(lu.getLocalisedMessageText("plugins.basicview.config"));
config_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
plugin.showConfig();
}
});
classic_enabled = plugin.isClassicEnabled();
if (!classic_enabled) {
Label control_label = new Label(main, SWT.NULL);
control_label.setText(lu.getLocalisedMessageText("azbuddy.disabled"));
return;
}
// control area
final Composite controls = new Composite(main, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 5;
layout.marginHeight = 0;
layout.marginWidth = 0;
controls.setLayout(layout);
grid_data = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(controls, grid_data);
Label control_label = new Label(controls, SWT.NULL);
control_label.setText(lu.getLocalisedMessageText("azbuddy.ui.new_buddy") + " ");
final Text control_text = new Text(controls, SWT.BORDER);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(control_text, gridData);
final Button control_button = new Button(controls, SWT.NULL);
control_button.setText(lu.getLocalisedMessageText("Button.add"));
control_button.setEnabled(false);
control_text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
control_button.setEnabled(plugin.verifyPublicKey(control_text.getText().trim()));
}
});
control_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
plugin.addBuddy(control_text.getText().trim(), BuddyPlugin.SUBSYSTEM_AZ2);
control_text.setText("");
}
});
final Label control_lab_pk = new Label(controls, SWT.NULL);
control_lab_pk.setText(lu.getLocalisedMessageText("azbuddy.ui.mykey") + " ");
final Label control_val_pk = new Label(controls, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(control_val_pk, gridData);
ClipboardCopy.addCopyToClipMenu(control_val_pk, new ClipboardCopy.copyToClipProvider() {
@Override
public String getText() {
return ((String) control_val_pk.getData("key"));
}
});
control_val_pk.setData("key", "");
final CryptoManager crypt_man = CryptoManagerFactory.getSingleton();
byte[] public_key = crypt_man.getECCHandler().peekPublicKey();
if (public_key == null) {
Messages.setLanguageText(control_val_pk, "ConfigView.section.security.publickey.undef");
} else {
String str = Base32.encode(public_key);
control_val_pk.setData("key", str);
control_val_pk.setText(truncate(str));
}
Messages.setLanguageText(control_val_pk, "ConfigView.copy.to.clipboard.tooltip", true);
control_val_pk.setCursor(main.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
control_val_pk.setForeground(Colors.blue);
control_val_pk.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
copyToClipboard();
}
@Override
public void mouseDown(MouseEvent arg0) {
copyToClipboard();
}
protected void copyToClipboard() {
new Clipboard(control_val_pk.getDisplay()).setContents(new Object[] { control_val_pk.getData("key") }, new Transfer[] { TextTransfer.getInstance() });
}
});
cryptoManagerKeyListener = new CryptoManagerKeyListener() {
@Override
public void keyChanged(final CryptoHandler handler) {
if (control_val_pk.isDisposed()) {
crypt_man.removeKeyListener(this);
} else if (handler.getType() == CryptoManager.HANDLER_ECC) {
control_val_pk.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
byte[] public_key = handler.peekPublicKey();
if (public_key == null) {
Messages.setLanguageText(control_val_pk, "ConfigView.section.security.publickey.undef");
control_val_pk.setData("key", "");
} else {
String str = Base32.encode(public_key);
control_val_pk.setText(truncate(str));
control_val_pk.setData("key", str);
}
controls.layout();
}
});
}
}
@Override
public void keyLockStatusChanged(CryptoHandler handler) {
}
};
crypt_man.addKeyListener(cryptoManagerKeyListener);
main.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (cryptoManagerKeyListener != null) {
CryptoManagerFactory.getSingleton().removeKeyListener(cryptoManagerKeyListener);
}
}
});
// table and log
final Composite form = new Composite(main, SWT.NONE);
FormLayout flayout = new FormLayout();
flayout.marginHeight = 0;
flayout.marginWidth = 0;
form.setLayout(flayout);
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(form, gridData);
final Composite child1 = new Composite(form, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 1;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
child1.setLayout(layout);
final Sash sash = new Sash(form, SWT.HORIZONTAL);
final Composite child2 = new Composite(form, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 1;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
child2.setLayout(layout);
FormData formData;
// child1
formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.top = new FormAttachment(0, 0);
Utils.setLayoutData(child1, formData);
final FormData child1Data = formData;
final int SASH_WIDTH = 4;
// sash
formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.top = new FormAttachment(child1);
formData.height = SASH_WIDTH;
Utils.setLayoutData(sash, formData);
// child2
formData = new FormData();
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(100, 0);
formData.top = new FormAttachment(sash);
Utils.setLayoutData(child2, formData);
final PluginConfig pc = plugin.getPluginInterface().getPluginconfig();
sash.setData("PCT", new Float(pc.getPluginFloatParameter("swt.sash.position", 0.7f)));
sash.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.DRAG) {
return;
}
child1Data.height = e.y + e.height - SASH_WIDTH;
form.layout();
Float l = new Float((double) child1.getBounds().height / form.getBounds().height);
sash.setData("PCT", l);
pc.setPluginParameter("swt.sash.position", l.floatValue());
}
});
form.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event e) {
Float l = (Float) sash.getData("PCT");
if (l != null) {
child1Data.height = (int) (form.getBounds().height * l.doubleValue());
form.layout();
}
}
});
// table
Comparator<BuddyPluginBuddy> comparator = addBuddyTable(child1);
Label pblab = new Label(child1, SWT.NULL);
pblab.setText(lu.getLocalisedMessageText("label.partial.friends"));
Comparator<PartialBuddy> pbcomparator = addPartialBuddyTable(child1);
// log area
log = new StyledText(child2, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
grid_data = new GridData(GridData.FILL_BOTH);
grid_data.horizontalSpan = 1;
grid_data.horizontalIndent = 4;
Utils.setLayoutData(log, grid_data);
log.setIndent(4);
buddies = plugin.getBuddies();
for (int i = 0; i < buddies.size(); i++) {
buddyAdded(buddies.get(i));
}
Collections.sort(buddies, comparator);
partial_buddies = plugin.getPartialBuddies();
for (int i = 0; i < partial_buddies.size(); i++) {
partialBuddyAdded(partial_buddies.get(i));
}
Collections.sort(partial_buddies, pbcomparator);
plugin.addListener(this);
plugin.addPartialBuddyListener(this);
plugin.addRequestListener(this);
init_complete = true;
updateTable();
updatePartialBuddyTable();
}
use of com.biglybt.pif.PluginConfig in project BiglyBT by BiglySoftware.
the class UPnPPlugin method updateIgnoreList.
protected void updateIgnoreList() {
try {
String param = "";
if (ignore_bad_devices.getValue()) {
PluginConfig pc = plugin_interface.getPluginconfig();
Map ignored = pc.getPluginMapParameter("upnp.device.ignorelist", new HashMap());
Iterator it = ignored.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
Map value = (Map) entry.getValue();
param += "\n " + entry.getKey() + ": " + new String((byte[]) value.get("Location"));
}
if (ignored.size() > 0) {
log.log("Devices currently being ignored: " + param);
}
}
String text = plugin_interface.getUtilities().getLocaleUtilities().getLocalisedMessageText("upnp.ignorebaddevices.info", new String[] { param });
ignored_devices_list.setLabelText(text);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
use of com.biglybt.pif.PluginConfig in project BiglyBT by BiglySoftware.
the class UPnPPlugin method incrementDeviceStats.
protected long incrementDeviceStats(String USN, String stat_key) {
String key = "upnp.device.stats." + stat_key;
PluginConfig pc = plugin_interface.getPluginconfig();
Map counts = pc.getPluginMapParameter(key, new HashMap());
Long count = (Long) counts.get(USN);
if (count == null) {
count = new Long(1);
} else {
count = new Long(count.longValue() + 1);
}
counts.put(USN, count);
pc.getPluginMapParameter(key, counts);
return (count.longValue());
}
use of com.biglybt.pif.PluginConfig in project BiglyBT by BiglySoftware.
the class UPnPPlugin method initialize.
@Override
public void initialize(PluginInterface _plugin_interface) {
plugin_interface = _plugin_interface;
log = plugin_interface.getLogger().getTimeStampedChannel("UPnP");
log.setDiagnostic();
log.setForce(true);
UIManager ui_manager = plugin_interface.getUIManager();
final BasicPluginViewModel model = ui_manager.createBasicPluginViewModel("UPnP");
model.setConfigSectionID(UPNP_PLUGIN_CONFIGSECTION_ID);
BasicPluginConfigModel upnp_config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, UPNP_PLUGIN_CONFIGSECTION_ID);
// NATPMP
BasicPluginConfigModel natpmp_config = ui_manager.createBasicPluginConfigModel(UPNP_PLUGIN_CONFIGSECTION_ID, NATPMP_PLUGIN_CONFIGSECTION_ID);
natpmp_config.addLabelParameter2("natpmp.info");
ActionParameter natpmp_wiki = natpmp_config.addActionParameter2("Utils.link.visit", "MainWindow.about.internet.wiki");
natpmp_wiki.setStyle(ActionParameter.STYLE_LINK);
natpmp_wiki.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
try {
plugin_interface.getUIManager().openURL(new URL(Constants.URL_WIKI + "w/NATPMP"));
} catch (Throwable e) {
e.printStackTrace();
}
}
});
natpmp_enable_param = natpmp_config.addBooleanParameter2("natpmp.enable", "natpmp.enable", false);
nat_pmp_router = natpmp_config.addStringParameter2("natpmp.routeraddress", "natpmp.routeraddress", "");
natpmp_enable_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
setNATPMPEnableState();
}
});
natpmp_enable_param.addEnabledOnSelection(nat_pmp_router);
// UPNP
upnp_config.addLabelParameter2("upnp.info");
upnp_config.addHyperlinkParameter2("upnp.wiki_link", Constants.URL_WIKI + "w/UPnP");
upnp_enable_param = upnp_config.addBooleanParameter2("upnp.enable", "upnp.enable", true);
grab_ports_param = upnp_config.addBooleanParameter2("upnp.grabports", "upnp.grabports", false);
release_mappings_param = upnp_config.addBooleanParameter2("upnp.releasemappings", "upnp.releasemappings", true);
ActionParameter refresh_param = upnp_config.addActionParameter2("upnp.refresh.label", "upnp.refresh.button");
refresh_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
UPnPPlugin.this.refreshMappings();
}
});
// Auto-refresh mappings every minute when enabled.
final BooleanParameter auto_refresh_on_bad_nat_param = upnp_config.addBooleanParameter2("upnp.refresh_on_bad_nat", "upnp.refresh_mappings_on_bad_nat", false);
plugin_interface.getUtilities().createTimer("upnp mapping auto-refresh", true).addPeriodicEvent(1 * 60 * 1000, new UTTimerEventPerformer() {
private long last_bad_nat = 0;
@Override
public void perform(UTTimerEvent event) {
if (upnp == null) {
return;
}
if (!auto_refresh_on_bad_nat_param.getValue()) {
return;
}
if (!upnp_enable_param.getValue()) {
return;
}
int status = plugin_interface.getConnectionManager().getNATStatus();
if (status == ConnectionManager.NAT_BAD) {
// Only try to refresh the mappings if this is the first bad NAT
// message we've been given in the last 15 minutes - we don't want
// to endlessly retry performing the mappings
long now = plugin_interface.getUtilities().getCurrentSystemTime();
if (last_bad_nat + (15 * 60 * 1000) < now) {
last_bad_nat = now;
log.log(LoggerChannel.LT_WARNING, "NAT status is firewalled - trying to refresh UPnP mappings");
refreshMappings(true);
}
}
}
});
upnp_config.addLabelParameter2("blank.resource");
alert_success_param = upnp_config.addBooleanParameter2("upnp.alertsuccess", "upnp.alertsuccess", false);
alert_other_port_param = upnp_config.addBooleanParameter2("upnp.alertothermappings", "upnp.alertothermappings", true);
alert_device_probs_param = upnp_config.addBooleanParameter2("upnp.alertdeviceproblems", "upnp.alertdeviceproblems", true);
selected_interfaces_param = upnp_config.addStringParameter2("upnp.selectedinterfaces", "upnp.selectedinterfaces", "");
selected_interfaces_param.setGenerateIntermediateEvents(false);
selected_addresses_param = upnp_config.addStringParameter2("upnp.selectedaddresses", "upnp.selectedaddresses", "");
selected_addresses_param.setGenerateIntermediateEvents(false);
desc_prefix_param = upnp_config.addStringParameter2("upnp.descprefix", "upnp.descprefix", Constants.APP_NAME + " UPnP");
desc_prefix_param.setGenerateIntermediateEvents(false);
ignore_bad_devices = upnp_config.addBooleanParameter2("upnp.ignorebaddevices", "upnp.ignorebaddevices", true);
ignored_devices_list = upnp_config.addLabelParameter2("upnp.ignorebaddevices.info");
ActionParameter reset_param = upnp_config.addActionParameter2("upnp.ignorebaddevices.reset", "upnp.ignorebaddevices.reset.action");
reset_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
PluginConfig pc = plugin_interface.getPluginconfig();
for (int i = 0; i < STATS_KEYS.length; i++) {
String key = "upnp.device.stats." + STATS_KEYS[i];
pc.setPluginMapParameter(key, new HashMap());
}
pc.setPluginMapParameter("upnp.device.ignorelist", new HashMap());
updateIgnoreList();
}
});
trace_to_log = upnp_config.addBooleanParameter2("upnp.trace_to_log", "upnp.trace_to_log", false);
final boolean enabled = upnp_enable_param.getValue();
upnp_enable_param.addEnabledOnSelection(alert_success_param);
upnp_enable_param.addEnabledOnSelection(grab_ports_param);
upnp_enable_param.addEnabledOnSelection(refresh_param);
auto_refresh_on_bad_nat_param.addEnabledOnSelection(refresh_param);
upnp_enable_param.addEnabledOnSelection(alert_other_port_param);
upnp_enable_param.addEnabledOnSelection(alert_device_probs_param);
upnp_enable_param.addEnabledOnSelection(release_mappings_param);
upnp_enable_param.addEnabledOnSelection(selected_interfaces_param);
upnp_enable_param.addEnabledOnSelection(selected_addresses_param);
upnp_enable_param.addEnabledOnSelection(desc_prefix_param);
upnp_enable_param.addEnabledOnSelection(ignore_bad_devices);
upnp_enable_param.addEnabledOnSelection(ignored_devices_list);
upnp_enable_param.addEnabledOnSelection(reset_param);
upnp_enable_param.addEnabledOnSelection(trace_to_log);
natpmp_enable_param.setEnabled(enabled);
model.getStatus().setText(enabled ? "Running" : "Disabled");
upnp_enable_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter p) {
boolean e = upnp_enable_param.getValue();
natpmp_enable_param.setEnabled(e);
model.getStatus().setText(e ? "Running" : "Disabled");
if (e) {
startUp();
} else {
closeDown(true);
}
setNATPMPEnableState();
}
});
model.getActivity().setVisible(false);
model.getProgress().setVisible(false);
log.addListener(new LoggerChannelListener() {
@Override
public void messageLogged(int type, String message) {
model.getLogArea().appendText(message + "\n");
}
@Override
public void messageLogged(String str, Throwable error) {
model.getLogArea().appendText(error.toString() + "\n");
}
});
// startup() used to be called on initializationComplete()
// Moved to delayed task because rootDeviceFound can take
// a lot of CPU cycle. Let's hope nothing breaks
DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {
@Override
public void run() {
if (enabled) {
updateIgnoreList();
startUp();
}
}
});
dt.queue();
plugin_interface.addListener(new PluginListener() {
@Override
public void initializationComplete() {
}
@Override
public void closedownInitiated() {
if (services.size() == 0) {
plugin_interface.getPluginconfig().setPluginParameter("plugin.info", "");
}
}
@Override
public void closedownComplete() {
closeDown(true);
}
});
}
use of com.biglybt.pif.PluginConfig in project BiglyBT by BiglySoftware.
the class UPnPPlugin method addService.
protected void addService(UPnPWANConnection wan_service) throws UPnPException {
wan_service.addListener(this);
mapping_manager.serviceFound(wan_service);
log.log(" Found " + (!wan_service.getGenericService().getServiceType().contains("PPP") ? "WANIPConnection" : "WANPPPConnection"));
UPnPWANConnectionPortMapping[] ports;
String usn = wan_service.getGenericService().getDevice().getRootDevice().getUSN();
if (getDeviceStats(usn, STATS_READ_OK) == 0 && getDeviceStats(usn, STATS_READ_BAD) > 2) {
ports = new UPnPWANConnectionPortMapping[0];
wan_service.periodicallyRecheckMappings(false);
log.log(" Not reading port mappings from device due to previous failures");
} else {
ports = wan_service.getPortMappings();
}
for (int j = 0; j < ports.length; j++) {
log.log(" mapping [" + j + "] " + ports[j].getExternalPort() + "/" + (ports[j].isTCP() ? "TCP" : "UDP") + " [" + ports[j].getDescription() + "] -> " + ports[j].getInternalHost());
}
try {
this_mon.enter();
services.add(new UPnPPluginService(wan_service, ports, desc_prefix_param, alert_success_param, grab_ports_param, alert_other_port_param, release_mappings_param));
if (services.size() > 1) {
// check this isn't a single device with multiple services
String new_usn = wan_service.getGenericService().getDevice().getRootDevice().getUSN();
boolean multiple_found = false;
for (int i = 0; i < services.size() - 1; i++) {
UPnPPluginService service = (UPnPPluginService) services.get(i);
String existing_usn = service.getService().getGenericService().getDevice().getRootDevice().getUSN();
if (!new_usn.equals(existing_usn)) {
multiple_found = true;
break;
}
}
if (multiple_found) {
PluginConfig pc = plugin_interface.getPluginconfig();
if (!pc.getPluginBooleanParameter("upnp.device.multipledevices.warned", false)) {
pc.setPluginParameter("upnp.device.multipledevices.warned", true);
String text = MessageText.getString("upnp.alert.multipledevice.warning");
log.logAlertRepeatable(LoggerChannel.LT_WARNING, text);
}
}
}
checkState();
} finally {
this_mon.exit();
}
}
Aggregations