use of com.biglybt.pif.ui.UIManager 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.ui.UIManager in project BiglyBT by BiglySoftware.
the class BuddyPluginViewBetaChat method dropFailed.
private void dropFailed(String content, Throwable e) {
UIManager ui_manager = plugin.getPluginInterface().getUIManager();
String details = MessageText.getString("azbuddy.dchat.share.fail.msg", new String[] { content, Debug.getNestedExceptionMessage(e) });
ui_manager.showMessageBox("azbuddy.dchat.share.fail.title", "!" + details + "!", UIManagerEvent.MT_OK);
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class TorrentUtil method init.
public static synchronized void init() {
if (initialised) {
return;
}
initialised = true;
for (String id : TU_ITEMS) {
String key = "IconBar.visible." + id;
if (!COConfigurationManager.hasParameter(key, false)) {
COConfigurationManager.setParameter(key, false);
}
}
UIManager ui_manager = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getUIManager();
ui_manager.addUIListener(new UIManagerListener() {
private List<UIToolBarItem> items = new ArrayList<>();
@Override
public void UIAttached(UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
UIToolBarManager tbm = instance.getToolBarManager();
if (tbm != null) {
UIToolBarItem refresh_item = tbm.createToolBarItem(TU_ITEM_RECHECK);
refresh_item.setGroupID(TU_GROUP);
refresh_item.setImageID("recheck");
refresh_item.setToolTipID("MyTorrentsView.menu.recheck");
refresh_item.setDefaultActivationListener(new UIToolBarActivationListener() {
@Override
public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
List<DownloadManager> dms = getDMs(datasource);
for (DownloadManager dm : dms) {
if (dm.canForceRecheck()) {
dm.forceRecheck();
}
}
return (true);
}
});
addItem(tbm, refresh_item);
// check files exist
UIToolBarItem cfe_item = tbm.createToolBarItem(TU_ITEM_CHECK_FILES);
cfe_item.setGroupID(TU_GROUP);
cfe_item.setImageID("filesexist");
cfe_item.setToolTipID("MyTorrentsView.menu.checkfilesexist");
cfe_item.setDefaultActivationListener(new UIToolBarActivationListener() {
@Override
public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
List<DownloadManager> dms = getDMs(datasource);
for (DownloadManager dm : dms) {
dm.filesExist(true);
}
return (true);
}
});
addItem(tbm, cfe_item);
}
}
}
private List<DownloadManager> getDMs(Object ds) {
List<DownloadManager> result = new ArrayList<>();
if (ds instanceof Download) {
result.add(PluginCoreUtils.unwrap((Download) ds));
} else if (ds instanceof Object[]) {
Object[] objs = (Object[]) ds;
for (Object obj : objs) {
if (obj instanceof Download) {
result.add(PluginCoreUtils.unwrap((Download) obj));
}
}
}
return (result);
}
private void addItem(UIToolBarManager tbm, UIToolBarItem item) {
items.add(item);
tbm.addToolBarItem(item);
}
@Override
public void UIDetached(UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
UIToolBarManager tbm = instance.getToolBarManager();
if (tbm != null) {
for (UIToolBarItem item : items) {
tbm.removeToolBarItem(item.getID());
}
}
items.clear();
}
}
});
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class BaseMDI method skinObjectInitialShow.
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
final UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
ui_manager.addUIListener(new UIManagerListener() {
@Override
public void UIDetached(UIInstance instance) {
}
@Override
public void UIAttached(UIInstance instance) {
if (instance instanceof UISWTInstance) {
ui_manager.removeUIListener(this);
final AESemaphore wait_sem = new AESemaphore("SideBar:wait");
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
try {
try {
loadCloseables();
} catch (Throwable t) {
Debug.out(t);
}
setupPluginViews();
} finally {
wait_sem.release();
}
}
});
if (!wait_sem.reserve(10 * 1000)) {
Debug.out("eh?");
}
}
}
});
return null;
}
use of com.biglybt.pif.ui.UIManager in project BiglyBT by BiglySoftware.
the class ClientStatsView method initColumns.
private void initColumns(Core core) {
synchronized (ClientStatsView.class) {
if (columnsAdded) {
return;
}
columnsAdded = true;
}
UIManager uiManager = PluginInitializer.getDefaultInterface().getUIManager();
TableManager tableManager = uiManager.getTableManager();
tableManager.registerColumn(ClientStatsDataSource.class, ColumnCS_Name.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnCS_Name(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, ColumnCS_Count.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnCS_Count(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, ColumnCS_Discarded.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnCS_Discarded(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, ColumnCS_Received.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnCS_Received(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, ColumnCS_ReceivedPer.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnCS_ReceivedPer(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, ColumnCS_Sent.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnCS_Sent(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, ColumnCS_Pct.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnCS_Pct(column);
}
});
for (final String network : AENetworkClassifier.AT_NETWORKS) {
tableManager.registerColumn(ClientStatsDataSource.class, network + "." + ColumnCS_Sent.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
column.setUserData("network", network);
new ColumnCS_Sent(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, network + "." + ColumnCS_Discarded.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
column.setUserData("network", network);
new ColumnCS_Discarded(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, network + "." + ColumnCS_Received.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
column.setUserData("network", network);
new ColumnCS_Received(column);
}
});
tableManager.registerColumn(ClientStatsDataSource.class, network + "." + ColumnCS_Count.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
column.setUserData("network", network);
new ColumnCS_Count(column);
}
});
}
TableColumnManager tcManager = TableColumnManager.getInstance();
tcManager.setDefaultColumnNames(TABLEID, new String[] { ColumnCS_Name.COLUMN_ID, ColumnCS_Pct.COLUMN_ID, ColumnCS_Count.COLUMN_ID, ColumnCS_Received.COLUMN_ID, ColumnCS_Sent.COLUMN_ID, ColumnCS_Discarded.COLUMN_ID });
}
Aggregations