Option to use hostname as a resource

https://igniterealtime.org/issues/browse/SPARK-1503
This commit is contained in:
wroot
2015-05-02 19:22:59 +03:00
parent 0dff0142e5
commit ac4cf87972
6 changed files with 66 additions and 8 deletions

View File

@ -45,6 +45,8 @@ import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collections;
@ -1053,6 +1055,13 @@ public class LoginDialog {
}
String resource = localPref.getResource();
if (localPref.isUseHostnameAsResource()) {
try {
resource = InetAddress.getLocalHost().getHostName();
} catch(UnknownHostException e) {
Log.error("unable to retrieve hostname",e);
}
}
connection.login(getLoginUsername(), getLoginPassword(),
org.jivesoftware.spark.util.StringUtils.modifyWildcards(resource).trim());

View File

@ -61,6 +61,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.Principal;
import java.util.Properties;
import java.io.File;
@ -198,6 +200,7 @@ public class LoginSettingDialog implements PropertyChangeListener {
private JTextField timeOutField = new JTextField();
private JLabel resourceLabel = new JLabel();
private JTextField resourceField = new JTextField();
private JCheckBox useHostnameAsResourceBox = new JCheckBox();
private JCheckBox autoLoginBox = new JCheckBox();
private JCheckBox useSSLBox = new JCheckBox();
private JCheckBox compressionBox = new JCheckBox();
@ -217,6 +220,8 @@ public class LoginSettingDialog implements PropertyChangeListener {
Res.getString("checkbox.auto.discover.port"));
ResourceUtils.resLabel(resourceLabel, resourceField,
Res.getString("label.resource"));
ResourceUtils.resButton(useHostnameAsResourceBox,
Res.getString("checkbox.use.hostname.as.resource"));
ResourceUtils.resButton(compressionBox,
Res.getString("checkbox.use.compression"));
ResourceUtils.resButton(debuggerBox,
@ -230,6 +235,10 @@ public class LoginSettingDialog implements PropertyChangeListener {
xmppHostField.setText(localPreferences.getXmppHost());
resourceField.setText(localPreferences.getResource());
useHostnameAsResourceBox.addActionListener(this);
useHostnameAsResourceBox.setSelected(localPreferences.isUseHostnameAsResource());
updateResource();
autoDiscoverBox.addActionListener(this);
autoDiscoverBox.setSelected(!localPreferences
@ -270,19 +279,22 @@ public class LoginSettingDialog implements PropertyChangeListener {
add(resourceField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(5, 5, 5, 5), 100, 0));
add(timeOutLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
add(useHostnameAsResourceBox, new GridBagConstraints(0, 3, 2, 1, 0.0, 1.0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(5, 5, 5, 5), 0, 0));
add(timeOutField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
add(timeOutLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(5, 5, 5, 5), 0, 0));
add(timeOutField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(5, 5, 5, 5), 50, 0));
add(useSSLBox, new GridBagConstraints(0, 4, 2, 1, 0.0, 1.0,
add(useSSLBox, new GridBagConstraints(0, 5, 2, 1, 0.0, 1.0,
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(5, 5, 5, 5), 0, 0));
add(compressionBox, new GridBagConstraints(0, 5, 2, 1, 0.0, 1.0,
add(compressionBox, new GridBagConstraints(0, 6, 2, 1, 0.0, 1.0,
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(5, 5, 5, 5), 0, 0));
add(debuggerBox, new GridBagConstraints(0, 6, 2, 1, 0.0, 1.0,
add(debuggerBox, new GridBagConstraints(0, 7, 2, 1, 0.0, 1.0,
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(5, 5, 5, 5), 0, 0));
}
@ -298,10 +310,35 @@ public class LoginSettingDialog implements PropertyChangeListener {
SettingsManager.saveSettings();
}
/**
* Updates resource settings.
*/
private void updateResource() {
boolean isSelected = useHostnameAsResourceBox.isSelected();
try {
if (isSelected) {
String resource = InetAddress.getLocalHost().getHostName();
resourceField.setText(resource);
}
resourceField.setEnabled(!isSelected);
} catch (UnknownHostException e) {
JOptionPane
.showMessageDialog(optionsDialog,
Res.getString("message.unable.to.use.hostname.as.resource"),
Res.getString("title.error"),
JOptionPane.ERROR_MESSAGE);
}
//localPreferences.setHostAndPortConfigured(!isSelected);
SettingsManager.saveSettings();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == autoDiscoverBox) {
updateAutoDiscovery();
}
else if (e.getSource() == useHostnameAsResourceBox) {
updateResource();
}
}
public boolean validate_settings() {
@ -358,6 +395,7 @@ public class LoginSettingDialog implements PropertyChangeListener {
localPreferences.setCompressionEnabled(compressionBox.isSelected());
localPreferences.setDebuggerEnabled(debuggerBox.isSelected());
localPreferences.setResource(resourceField.getText());
localPreferences.setUseHostnameAsResource(useHostnameAsResourceBox.isSelected());
SettingsManager.saveSettings();
}
}

View File

@ -8,7 +8,7 @@ APPLICATION_NAME = Spark
SHORT_NAME = Spark
############# Auto Set During Build #############
APPLICATION_VERSION =
APPLICATION_VERSION = 2.7.0
# Passed into ant via cmd line argument:
# -Dbuild.number=<build number>
# If not passed in, this field is ignored.

View File

@ -1197,5 +1197,12 @@ public class LocalPreferences {
}
public boolean isUseHostnameAsResource() {
return getBoolean("useHostnameAsResource", false);
}
public void setUseHostnameAsResource(boolean useHostnameAsResource) {
setBoolean("useHostnameAsResource", useHostnameAsResource);
}
}

View File

@ -375,6 +375,7 @@ checkbox.use.specify.below = Specify below
checkbox.use.pki.authentication = Use PKI authentication
checkbox.transport.tab.setting = Show available transports in tab (requires restart)
checkbox.conference.tab.setting = Show conference service in tab (requires restart)
checkbox.use.hostname.as.resource = Use hostname as resource
delete.log.permanently = Permanently delete log
delete.permanently = Permanently delete?
@ -815,6 +816,7 @@ message.unable.to.load.profile = Unable to locate a profile for {0}
message.unable.to.retrieve.last.activity = Unable to determine last activity for {0}
message.unable.to.save.password = Unable to change password, please contact your server admin
message.unable.to.send.file = You were unable to send the file to {0}
message.unable.to.use.hostname.as.resource = Unable to use hostname as resource
message.unrecoverable.error = Invalid username or password
message.update.room.list = Update room list
message.updating.cancelled = Updating has been canceled

View File

@ -223,6 +223,7 @@ checkbox.allow.buzz = \u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0
checkbox.enable.emoticons = \u0420\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0441\u043c\u0430\u0439\u043b\u0438\u043a\u0438
checkbox.use.system.look.and.feel = \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043c\u044b (System Look And &Feel) (\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a)
checkbox.disable.prev.chat.history = \u041e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u043e\u043a\u0430\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0431\u0435\u0441\u0435\u0434 \u0432 \u0447\u0430\u0442\u0435
checkbox.use.hostname.as.resource = \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0438\u043C\u044F \u0445\u043E\u0441\u0442\u0430 \u0432 \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430
label.user.on.public.network = User is on a public network
@ -520,6 +521,7 @@ message.receiving.file = \u0412\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435
message.reconnect.attempting = \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f...
message.reconnect.failed = \u041d\u0435\u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f
message.reconnect.wait = \u041f\u0435\u0440\u0435\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 {0} \u0441\u0435\u043a.
message.unable.to.use.hostname.as.resource = \u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0438\u043C\u044F \u0445\u043E\u0441\u0442\u0430 \u0432 \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430
title.appearance = \u0412\u043d\u0435\u0448\u043d\u0438\u0439 \u0432\u0438\u0434
title.appearance.preferences = \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430