mirror of https://github.com/sipwise/jitsi.git
Add global proxy config. Add support for the global proxy config in protocols like ICQ/AIM and Jabber.
parent
96fe4b483e
commit
67106df9d3
|
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,279 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license. See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.globalproxyconfig;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import net.java.sip.communicator.service.configuration.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.swing.*;
|
||||
|
||||
/**
|
||||
* Implementation of the configuration form.
|
||||
*
|
||||
* @author Damian Minkov
|
||||
*/
|
||||
public class GlobalProxyConfigForm
|
||||
extends TransparentPanel
|
||||
implements ActionListener
|
||||
{
|
||||
/**
|
||||
* Hold the available proxy types.
|
||||
*/
|
||||
private JComboBox typeCombo;
|
||||
|
||||
/**
|
||||
* The proxy server address.
|
||||
*/
|
||||
private JTextField serverAddressField = new JTextField();
|
||||
|
||||
/**
|
||||
* The proxy server port.
|
||||
*/
|
||||
private JTextField portField = new JTextField();
|
||||
|
||||
/**
|
||||
* The username if any.
|
||||
*/
|
||||
private JTextField usernameField = new JTextField();
|
||||
|
||||
/**
|
||||
* The password for accessing proxy, if any.
|
||||
*/
|
||||
private JPasswordField passwordField = new JPasswordField();
|
||||
|
||||
/**
|
||||
* Creates the form.
|
||||
*/
|
||||
public GlobalProxyConfigForm()
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
init();
|
||||
loadValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating the configuration form
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
this.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
||||
TransparentPanel centerPanel = new TransparentPanel(new GridBagLayout());
|
||||
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
constraints.anchor = GridBagConstraints.NORTHWEST;
|
||||
constraints.insets = new Insets(5,10,0,0);
|
||||
constraints.gridx = 0;
|
||||
constraints.weightx = 0;
|
||||
constraints.weighty = 0;
|
||||
constraints.gridy = 0;
|
||||
|
||||
centerPanel.add(new JLabel(
|
||||
Resources.getString("plugin.globalproxy.PROXY_TYPE")),
|
||||
constraints);
|
||||
constraints.gridy = 1;
|
||||
centerPanel.add(new JLabel(
|
||||
Resources.getString("plugin.globalproxy.PROXY_ADDRESS")),
|
||||
constraints);
|
||||
constraints.gridy = 2;
|
||||
centerPanel.add(new JLabel(
|
||||
Resources.getString("plugin.globalproxy.PROXY_USERNAME")),
|
||||
constraints);
|
||||
constraints.gridy = 3;
|
||||
centerPanel.add(new JLabel(
|
||||
Resources.getString("plugin.globalproxy.PROXY_PASSWORD")),
|
||||
constraints);
|
||||
|
||||
constraints.weightx = 1;
|
||||
constraints.gridx = 1;
|
||||
constraints.gridy = 0;
|
||||
constraints.gridwidth = 3;
|
||||
typeCombo = new JComboBox(ProxyInfo.ProxyType.values());
|
||||
typeCombo.addActionListener(this);
|
||||
typeCombo.setEditable(false);
|
||||
centerPanel.add(typeCombo, constraints);
|
||||
|
||||
constraints.gridy = 1;
|
||||
constraints.gridwidth = 1;
|
||||
centerPanel.add(serverAddressField, constraints);
|
||||
constraints.gridx = 2;
|
||||
constraints.weightx = 0;
|
||||
centerPanel.add(
|
||||
new JLabel(
|
||||
Resources.getString("plugin.globalproxy.PROXY_PORT")),
|
||||
constraints);
|
||||
constraints.gridx = 3;
|
||||
constraints.weightx = 1;
|
||||
centerPanel.add(portField, constraints);
|
||||
|
||||
constraints.gridx = 1;
|
||||
constraints.gridwidth = 3;
|
||||
constraints.gridy = 2;
|
||||
centerPanel.add(usernameField, constraints);
|
||||
constraints.gridy = 3;
|
||||
centerPanel.add(passwordField, constraints);
|
||||
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 4;
|
||||
constraints.gridwidth = 4;
|
||||
constraints.gridheight = 2;
|
||||
constraints.insets = new Insets(20,20,20,20);
|
||||
JTextPane pane = new JTextPane();
|
||||
pane.setEditable(false);
|
||||
pane.setOpaque(false);
|
||||
pane.setText(Resources.getResources().getI18NString(
|
||||
"plugin.globalproxy.DESCRIPTION",
|
||||
new String[]{Resources.getResources().getSettingsString(
|
||||
"service.gui.APPLICATION_NAME")}));
|
||||
centerPanel.add(
|
||||
pane,
|
||||
constraints);
|
||||
|
||||
add(centerPanel, BorderLayout.NORTH);
|
||||
|
||||
TransparentPanel p = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
JButton saveButton = new JButton(
|
||||
Resources.getString("service.gui.SAVE"));
|
||||
saveButton.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
saveValues();
|
||||
}
|
||||
});
|
||||
p.add(saveButton);
|
||||
|
||||
add(p, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loading the values stored onto configuration form
|
||||
*/
|
||||
private void loadValues()
|
||||
{
|
||||
ConfigurationService configService =
|
||||
GlobalProxyPluginActivator.getConfigurationService();
|
||||
|
||||
try
|
||||
{
|
||||
String type = configService.getString(
|
||||
ProxyInfo.CONNECTON_PROXY_TYPE_PROPERTY_NAME);
|
||||
if(type != null)
|
||||
typeCombo.setSelectedItem(ProxyInfo.ProxyType.valueOf(type));
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
// wrong proxy type stored in configuration
|
||||
}
|
||||
|
||||
String serverAddress = configService.getString(
|
||||
ProxyInfo.CONNECTON_PROXY_ADDRESS_PROPERTY_NAME);
|
||||
if(serverAddress != null)
|
||||
serverAddressField.setText(serverAddress);
|
||||
|
||||
String port = configService.getString(
|
||||
ProxyInfo.CONNECTON_PROXY_PORT_PROPERTY_NAME);
|
||||
if(port != null)
|
||||
portField.setText(port);
|
||||
|
||||
String username = configService.getString(
|
||||
ProxyInfo.CONNECTON_PROXY_USERNAME_PROPERTY_NAME);
|
||||
if(username != null)
|
||||
usernameField.setText(username);
|
||||
|
||||
String password = configService.getString(
|
||||
ProxyInfo.CONNECTON_PROXY_USERNAME_PROPERTY_NAME);
|
||||
if(password != null)
|
||||
passwordField.setText(password);
|
||||
|
||||
if(typeCombo.getSelectedItem().equals(ProxyInfo.ProxyType.NONE))
|
||||
{
|
||||
serverAddressField.setEnabled(false);
|
||||
portField.setEnabled(false);
|
||||
usernameField.setEnabled(false);
|
||||
passwordField.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function which save values onto configuration file after save button is
|
||||
* clicked
|
||||
*/
|
||||
private void saveValues()
|
||||
{
|
||||
ConfigurationService configService =
|
||||
GlobalProxyPluginActivator.getConfigurationService();
|
||||
|
||||
if(typeCombo.getSelectedItem().equals(ProxyInfo.ProxyType.NONE))
|
||||
{
|
||||
configService.setProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_TYPE_PROPERTY_NAME,
|
||||
ProxyInfo.ProxyType.NONE.name());
|
||||
|
||||
configService.removeProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_ADDRESS_PROPERTY_NAME);
|
||||
configService.removeProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_PORT_PROPERTY_NAME);
|
||||
configService.removeProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_USERNAME_PROPERTY_NAME);
|
||||
configService.removeProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_PASSWORD_PROPERTY_NAME);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
configService.setProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_TYPE_PROPERTY_NAME,
|
||||
((ProxyInfo.ProxyType)typeCombo.getSelectedItem()).name());
|
||||
|
||||
String serverAddress = serverAddressField.getText();
|
||||
if(serverAddress != null && serverAddress.length() > 0)
|
||||
configService.setProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_ADDRESS_PROPERTY_NAME, serverAddress);
|
||||
|
||||
String port = portField.getText();
|
||||
if(port != null && port.length() > 0)
|
||||
configService.setProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_PORT_PROPERTY_NAME, port);
|
||||
|
||||
String username = usernameField.getText();
|
||||
if(username != null && username.length() > 0)
|
||||
configService.setProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_USERNAME_PROPERTY_NAME, username);
|
||||
|
||||
char[] password = passwordField.getPassword();
|
||||
if(password.length > 0)
|
||||
configService.setProperty(
|
||||
ProxyInfo.CONNECTON_PROXY_PASSWORD_PROPERTY_NAME,
|
||||
new String(password));
|
||||
}
|
||||
|
||||
/**
|
||||
* A new type was selected in the type combo box.
|
||||
* @param e the event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if(typeCombo.getSelectedItem().equals(ProxyInfo.ProxyType.NONE))
|
||||
{
|
||||
serverAddressField.setEnabled(false);
|
||||
portField.setEnabled(false);
|
||||
usernameField.setEnabled(false);
|
||||
passwordField.setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverAddressField.setEnabled(true);
|
||||
portField.setEnabled(true);
|
||||
usernameField.setEnabled(true);
|
||||
passwordField.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.globalproxyconfig;
|
||||
|
||||
import net.java.sip.communicator.service.configuration.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* Register the configuration form.
|
||||
*
|
||||
* @author Atul Aggarwal
|
||||
* @author Damian Minkov
|
||||
*/
|
||||
public class GlobalProxyPluginActivator implements BundleActivator
|
||||
{
|
||||
/**
|
||||
* Our logger.
|
||||
*/
|
||||
private Logger logger = Logger.getLogger(GlobalProxyPluginActivator.class);
|
||||
|
||||
/**
|
||||
* The Configuration service.
|
||||
*/
|
||||
private static ConfigurationService configService;
|
||||
|
||||
/**
|
||||
* The context of this bundle.
|
||||
*/
|
||||
protected static BundleContext bundleContext;
|
||||
|
||||
/**
|
||||
* Starts the bundle.
|
||||
* @param bc the context
|
||||
* @throws Exception
|
||||
*/
|
||||
public void start(BundleContext bc) throws Exception
|
||||
{
|
||||
bundleContext = bc;
|
||||
|
||||
GlobalProxyConfigForm proxyConfigForm = new GlobalProxyConfigForm();
|
||||
|
||||
bundleContext.registerService(
|
||||
ConfigurationForm.class.getName(),
|
||||
new LazyConfigurationForm(
|
||||
GlobalProxyConfigForm.class.getName(),
|
||||
getClass().getClassLoader(),
|
||||
"plugin.globalproxy.PLUGIN_ICON",
|
||||
"plugin.globalproxy.GLOBAL_PROXY_CONFIG",
|
||||
51),
|
||||
null);
|
||||
|
||||
logger.info("GLOBAL PROXY CONFIGURATION PLUGIN... [REGISTERED]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops it.
|
||||
* @param bc the context.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void stop(BundleContext bc) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>ConfigurationService</tt> obtained from the bundle
|
||||
* context.
|
||||
* @return the <tt>ConfigurationService</tt> obtained from the bundle
|
||||
* context
|
||||
*/
|
||||
public static ConfigurationService getConfigurationService()
|
||||
{
|
||||
if(configService == null)
|
||||
{
|
||||
ServiceReference configReference = bundleContext
|
||||
.getServiceReference(ConfigurationService.class.getName());
|
||||
|
||||
configService = (ConfigurationService) bundleContext
|
||||
.getService(configReference);
|
||||
}
|
||||
|
||||
return configService;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
|
||||
package net.java.sip.communicator.plugin.globalproxyconfig;
|
||||
|
||||
import net.java.sip.communicator.service.resources.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.osgi.framework.*;
|
||||
|
||||
/**
|
||||
* The <tt>Resources</tt> class manages the access to the internationalization
|
||||
* properties files and the image resources used in this plugin.
|
||||
*
|
||||
* @author Atul Aggarwal
|
||||
* @author Damian Minkov
|
||||
*/
|
||||
public class Resources
|
||||
{
|
||||
/**
|
||||
* Our logger.
|
||||
*/
|
||||
private static Logger log = Logger.getLogger(Resources.class);
|
||||
|
||||
/**
|
||||
* The resource management service.
|
||||
*/
|
||||
private static ResourceManagementService resourcesService;
|
||||
|
||||
/**
|
||||
* Returns an internationalized string corresponding to the given key.
|
||||
* @param key The key of the string.
|
||||
* @return An internationalized string corresponding to the given key.
|
||||
*/
|
||||
public static String getString(String key)
|
||||
{
|
||||
return getResources().getI18NString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an application property string corresponding to the given key.
|
||||
* @param key The key of the string.
|
||||
* @return A string corresponding to the given key.
|
||||
*/
|
||||
public static String getApplicationString(String key)
|
||||
{
|
||||
return getResources().getSettingsString(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource service.
|
||||
* @return
|
||||
*/
|
||||
public static ResourceManagementService getResources()
|
||||
{
|
||||
if (resourcesService == null)
|
||||
{
|
||||
ServiceReference serviceReference = GlobalProxyPluginActivator.bundleContext
|
||||
.getServiceReference(ResourceManagementService.class.getName());
|
||||
|
||||
if(serviceReference == null)
|
||||
return null;
|
||||
|
||||
resourcesService =
|
||||
(ResourceManagementService)GlobalProxyPluginActivator.bundleContext
|
||||
.getService(serviceReference);
|
||||
}
|
||||
|
||||
return resourcesService;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
Bundle-Activator: net.java.sip.communicator.plugin.globalproxyconfig.GlobalProxyPluginActivator
|
||||
Bundle-Name: Global Proxy Config Plugin
|
||||
Bundle-Description: A plugin to configure global proxy for sip communicator
|
||||
Bundle-Vendor: sip-communicator.org
|
||||
Bundle-Version: 0.0.1
|
||||
Import-Package: org.osgi.framework,
|
||||
net.java.sip.communicator.util,
|
||||
net.java.sip.communicator.util.swing,
|
||||
net.java.sip.communicator.service.gui,
|
||||
net.java.sip.communicator.service.protocol,
|
||||
net.java.sip.communicator.service.resources,
|
||||
net.java.sip.communicator.service.configuration,
|
||||
javax.swing,
|
||||
javax.swing.event,
|
||||
javax.swing.table,
|
||||
javax.swing.text,
|
||||
javax.swing.text.html,
|
||||
javax.accessibility,
|
||||
javax.swing.plaf,
|
||||
javax.swing.plaf.metal,
|
||||
javax.swing.plaf.basic,
|
||||
javax.imageio,
|
||||
javax.swing.filechooser,
|
||||
javax.swing.tree,
|
||||
javax.swing.undo,
|
||||
javax.swing.border
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.service.protocol;
|
||||
|
||||
/**
|
||||
* The supported proxy types and properties used to store the values
|
||||
* in the configuration service.
|
||||
*
|
||||
* @author Damian Minkov
|
||||
*/
|
||||
public class ProxyInfo
|
||||
{
|
||||
/**
|
||||
* Enum which stores possible proxy types
|
||||
*/
|
||||
public static enum ProxyType
|
||||
{
|
||||
/**
|
||||
* Proxy is not used.
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* HTTP proxy type.
|
||||
*/
|
||||
HTTP,
|
||||
/**
|
||||
* Proxy type socks4.
|
||||
*/
|
||||
SOCKS4,
|
||||
/**
|
||||
* Proxy type socks5.
|
||||
*/
|
||||
SOCKS5
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores in the configuration the connection proxy type.
|
||||
*/
|
||||
public final static String CONNECTON_PROXY_TYPE_PROPERTY_NAME =
|
||||
"net.java.sip.communicator.service.connectionProxyType";
|
||||
|
||||
/**
|
||||
* Stores in the configuration the connection proxy address.
|
||||
*/
|
||||
public final static String CONNECTON_PROXY_ADDRESS_PROPERTY_NAME =
|
||||
"net.java.sip.communicator.service.connectionProxyAddress";
|
||||
|
||||
/**
|
||||
* Stores in the configuration the connection proxy port.
|
||||
*/
|
||||
public final static String CONNECTON_PROXY_PORT_PROPERTY_NAME =
|
||||
"net.java.sip.communicator.service.connectionProxyPort";
|
||||
|
||||
/**
|
||||
* Stores in the configuration the connection proxy username.
|
||||
*/
|
||||
public final static String CONNECTON_PROXY_USERNAME_PROPERTY_NAME =
|
||||
"net.java.sip.communicator.service.connectionProxyUsername";
|
||||
|
||||
/**
|
||||
* Stores in the configuration the connection proxy password.
|
||||
*/
|
||||
public final static String CONNECTON_PROXY_PASSWORD_PROPERTY_NAME =
|
||||
"net.java.sip.communicator.service.connectionProxyPassword";
|
||||
}
|
||||
Loading…
Reference in new issue