diff --git a/src/java/org/jivesoftware/LoginDialog.java b/src/java/org/jivesoftware/LoginDialog.java
index db4ba275..d94980e7 100644
--- a/src/java/org/jivesoftware/LoginDialog.java
+++ b/src/java/org/jivesoftware/LoginDialog.java
@@ -901,7 +901,9 @@ public final class LoginDialog {
if (!ModelUtil.hasLength(resource)) {
resource = "spark";
}
- connection.login(getUsername(), getPassword(), modifyWildcards(resource));
+
+ connection.login(getUsername(), getPassword(),
+ org.jivesoftware.spark.util.StringUtils.modifyWildcards(resource));
sessionManager.setServerAddress(connection.getServiceName());
sessionManager.initializeSession(connection, getUsername(), getPassword());
@@ -1009,26 +1011,6 @@ public final class LoginDialog {
return !hasErrors;
}
- /**
- * Modifies Wildcards such as $r,$s,$v
- * into what they represent r = randomnumber , s=os.name, v=os.version
- * @param resource
- * @return
- */
- private String modifyWildcards(String resource) {
-
- resource = resource.replace("$r",
- "" + Math.round((Math.random() * 1000)));
-
- resource = resource.replace("$s", System.getProperty("os.name")
- .replace(" ", ""));
-
- resource = resource.replace("$v", System.getProperty("os.version")
- .replace(" ", ""));
-
- return resource;
- }
-
public void handle(Callback[] callbacks) throws IOException {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
diff --git a/src/java/org/jivesoftware/spark/ui/status/StatusBar.java b/src/java/org/jivesoftware/spark/ui/status/StatusBar.java
index c0207afa..fca01a84 100644
--- a/src/java/org/jivesoftware/spark/ui/status/StatusBar.java
+++ b/src/java/org/jivesoftware/spark/ui/status/StatusBar.java
@@ -64,6 +64,7 @@ import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.PresenceListener;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.ModelUtil;
+import org.jivesoftware.spark.util.StringUtils;
import org.jivesoftware.spark.util.SwingTimerTask;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.TaskEngine;
@@ -124,6 +125,7 @@ public class StatusBar extends JPanel implements VCardListener {
SparkManager.getSessionManager().addPresenceListener(new PresenceListener() {
public void presenceChanged(Presence presence) {
+ presence.setStatus(StringUtils.modifyWildcards(presence.getStatus()));
changeAvailability(presence);
}
});
diff --git a/src/java/org/jivesoftware/spark/util/StringUtils.java b/src/java/org/jivesoftware/spark/util/StringUtils.java
index 781386c9..fc64886d 100644
--- a/src/java/org/jivesoftware/spark/util/StringUtils.java
+++ b/src/java/org/jivesoftware/spark/util/StringUtils.java
@@ -27,8 +27,10 @@ import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.BreakIterator;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.BitSet;
+import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
@@ -1913,6 +1915,12 @@ public class StringUtils {
return "unknown(0x" + Integer.toString(keyCode, 16) + ")";
}
+ /**
+ * Converts the first Character of a String to its Uppercase Instance
+ * test -> Test
+ * @param word
+ * @return String, with first char uppercased
+ */
public static String makeFirstWordCaptial(String word) {
if (word.length() < 2) {
return word;
@@ -1923,4 +1931,48 @@ public class StringUtils {
return firstWord.toUpperCase() + restOfWord;
}
+
+ /**
+ * Modifies Wildcards such as %random%,%system%,
+ * %version%,%time% into what they represent
+ *
+ * for properties see System.getProperties() + * + * @param resource + * String to modify + * @return modified String + * @author wolf.posdorfer + */ + public static String modifyWildcards(String resource) { + + resource = resource.replace("%random%", + "" + Math.round((Math.random() * 1000))); + + resource = resource.replace("%system%", System.getProperty("os.name") + .replace(" ", "")); + + resource = resource.replace("%version%", + System.getProperty("os.version").replace(" ", "")); + + final String DATE_FORMAT_NOW = "HH:mm"; + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); + + resource = resource.replace("%time%", sdf.format(cal.getTime())); + + while (resource.contains("%property{")) { + if (resource.contains("%property{") && resource.contains("}/%")) { + int indexofbeginning = resource.indexOf("%property{"); + int indexofending = resource.indexOf("}/%"); + + String begin = resource.substring(0, indexofbeginning); + String middle = System.getProperty(resource.substring( + indexofbeginning+10, indexofending)); + String end = resource.substring(indexofending + 3); + resource = begin + middle + end; + } + } + + return resource; + } } \ No newline at end of file diff --git a/src/java/org/jivesoftware/sparkimpl/plugin/idle/UserIdlePlugin.java b/src/java/org/jivesoftware/sparkimpl/plugin/idle/UserIdlePlugin.java index 1a20c4b2..e95f854c 100644 --- a/src/java/org/jivesoftware/sparkimpl/plugin/idle/UserIdlePlugin.java +++ b/src/java/org/jivesoftware/sparkimpl/plugin/idle/UserIdlePlugin.java @@ -28,10 +28,10 @@ import java.util.Timer; import java.util.TimerTask; import org.jivesoftware.Spark; -import org.jivesoftware.resource.Res; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.spark.SparkManager; import org.jivesoftware.spark.plugin.Plugin; +import org.jivesoftware.spark.util.StringUtils; import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.sparkimpl.settings.local.LocalPreferences; import org.jivesoftware.sparkimpl.settings.local.SettingsManager; @@ -94,7 +94,7 @@ public class UserIdlePlugin extends TimerTask implements Plugin { if ((latestPresence.getMode() == Presence.Mode.available) || latestPresence.getMode() == Presence.Mode.chat) { Presence presence = new Presence(Presence.Type.available, - Res.getString("status.away"), 1, Presence.Mode.away); + StringUtils.modifyWildcards(pref.getIdleMessage()), 1, Presence.Mode.away); SparkManager.getSessionManager().changePresence(presence); } } diff --git a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreference.java b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreference.java index f3a5f019..cb160e26 100644 --- a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreference.java +++ b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreference.java @@ -79,6 +79,7 @@ public class LocalPreference implements Preference { preferences.setStartedHidden(panel.startInSystemTray()); preferences.setStartOnStartup(panel.startOnStartup()); preferences.setReconnectPanelType(panel.getReconnectPanelType()); + preferences.setIdleMessage(panel.getIdleMessage()); return preferences; } diff --git a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferencePanel.java b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferencePanel.java index 449d51ab..afeb019a 100644 --- a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferencePanel.java +++ b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferencePanel.java @@ -46,10 +46,12 @@ public class LocalPreferencePanel extends JPanel { private JLabel _portLabel = new JLabel(); private JLabel _idleLabel = new JLabel(); private JLabel _timeOutLabel = new JLabel(); + private JLabel _idleStatusLabel = new JLabel(); private JTextField _portField = new JTextField(); private JTextField _timeOutField = new JTextField(); private JTextField _idleField = new JTextField(); + private JTextField _idleStatusText; private JCheckBox _autoLoginBox = new JCheckBox(); private JCheckBox _savePasswordBox = new JCheckBox(); @@ -77,6 +79,8 @@ public class LocalPreferencePanel extends JPanel { _autoLoginBox.setSelected(preferences.isAutoLogin()); _savePasswordBox.setSelected(preferences.isSavePassword()); _startMinimizedBox.setSelected(preferences.isStartedHidden()); + + _idleStatusText = new JTextField(preferences.getIdleMessage()); _showReconnectBox.setSelectedIndex(preferences.getReconnectPanelType()); @@ -118,10 +122,13 @@ public class LocalPreferencePanel extends JPanel { inputPanel.setBorder(BorderFactory.createTitledBorder(Res .getString("group.login.information"))); - ResourceUtils.resLabel(_portLabel, _portField, - Res.getString("label.xmpp.port") + ":"); + ResourceUtils.resLabel(_portLabel, _portField,Res.getString("label.xmpp.port") + ":"); ResourceUtils.resLabel(_timeOutLabel, _timeOutField, Res.getString("label.response.timeout") + ":"); + + ResourceUtils.resLabel(_idleStatusLabel, _idleStatusText, + Res.getString("label.time.till.idlemessage") + ":"); + ResourceUtils.resButton(_autoLoginBox, Res.getString("checkbox.auto.login")); ResourceUtils.resButton(_savePasswordBox, @@ -130,44 +137,28 @@ public class LocalPreferencePanel extends JPanel { Res.getString("label.time.till.idle") + ":"); ResourceUtils.resButton(_idleBox, Res.getString("checkbox.idle.enabled")); + ResourceUtils.resButton(_launchOnStartupBox, Res.getString("checkbox.launch.on.startup")); ResourceUtils.resButton(_startMinimizedBox, Res.getString("checkbox.start.in.tray")); - inputPanel.add(_portLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, - new Insets(5, 5, 5, 5), 0, 0)); - inputPanel.add(_portField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, - GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, - new Insets(5, 5, 5, 5), 0, 0)); - inputPanel.add(_timeOutLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, - 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, - new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(_timeOutField, new GridBagConstraints(1, 1, 1, 1, 1.0, - 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(_idleLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, - GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, - new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(_idleField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, - GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, - new Insets(5, 5, 5, 5), 50, 0)); + + inputPanel.add(_portLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + inputPanel.add(_portField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,new Insets(5, 5, 5, 5), 0, 0)); + inputPanel.add(_timeOutLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_timeOutField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_idleLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_idleField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_idleStatusLabel,new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_idleStatusText, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_idleBox, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(_idleBox, new GridBagConstraints(0, 3, 2, 1, 1.0, 0.0, - GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, - new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(_savePasswordBox, new GridBagConstraints(0, 4, 2, 1, - 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(_autoLoginBox, new GridBagConstraints(0, 5, 2, 1, 0.0, - 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + + inputPanel.add(_savePasswordBox, new GridBagConstraints(0, 5, 2, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_autoLoginBox, new GridBagConstraints(0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); if (Spark.isWindows()) { - inputPanel.add(_launchOnStartupBox, new GridBagConstraints(0, 6, 2, - 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, - 0)); + inputPanel.add(_launchOnStartupBox, new GridBagConstraints(0, 7, 2, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50,0)); _launchOnStartupBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setStartOnStartup(_launchOnStartupBox.isSelected()); @@ -177,16 +168,12 @@ public class LocalPreferencePanel extends JPanel { _launchOnStartupBox.setSelected(preferences.getStartOnStartup()); } - inputPanel.add(_startMinimizedBox, new GridBagConstraints(0, 7, 2, 1, - 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(new JLabel(), new GridBagConstraints(0, 8, 2, 1, 1.0, - 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, - new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_startMinimizedBox, new GridBagConstraints(0, 8, 2, 1,0.0, 0.0, GridBagConstraints.NORTHWEST,GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(new JLabel(), new GridBagConstraints(0, 9, 2, 1, 1.0,1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,new Insets(5, 5, 5, 5), 50, 0)); JLabel reconnectionlabel= new JLabel(Res.getString("checkbox.reconnet.info")); - inputPanel.add(reconnectionlabel, new GridBagConstraints(0, 9, 1, 1,0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); - inputPanel.add(_showReconnectBox, new GridBagConstraints(1, 9, 3, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(reconnectionlabel, new GridBagConstraints(0, 10, 1, 1,0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); + inputPanel.add(_showReconnectBox, new GridBagConstraints(1, 10, 3, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0)); add(inputPanel); } @@ -339,5 +326,12 @@ public class LocalPreferencePanel extends JPanel { public void setShowReconnectPanel(int reconnect) { _showReconnectBox.setSelectedIndex(reconnect); } + + public String getIdleMessage(){ + return _idleStatusText.getText(); + } + public void setIdleMessage(String text){ + _idleStatusText.setText(text); + } } diff --git a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java index a5803447..8a4bd358 100644 --- a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java +++ b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java @@ -22,6 +22,7 @@ package org.jivesoftware.sparkimpl.settings.local; import org.jivesoftware.Spark; import org.jivesoftware.resource.Default; +import org.jivesoftware.resource.Res; import org.jivesoftware.spark.SparkManager; import java.io.File; import java.util.Date; @@ -128,6 +129,21 @@ public class LocalPreferences { public void setIdleOn(boolean idleOn) { props.setProperty("idleOn", Boolean.toString(idleOn)); } + /** + * Returns the Idle Message to Display when going automatically away + * @return + */ + public String getIdleMessage(){ + return props.getProperty("idleOnMessage",Res.getString("status.away")); + } + + /** + * Sets the idle Message when going automatically away + * @param message + */ + public void setIdleMessage(String message){ + props.setProperty("idleOnMessage",message); + } /** * Returns the number of minutes to set to unavailable if the computer has diff --git a/src/resources/i18n/spark_i18n.properties b/src/resources/i18n/spark_i18n.properties index 55035b83..86deecbf 100644 --- a/src/resources/i18n/spark_i18n.properties +++ b/src/resources/i18n/spark_i18n.properties @@ -458,6 +458,7 @@ label.state.and.province = State/province label.street.address = Street address label.time = Time: {0} label.time.till.idle = &Time till idle (min) +label.time.till.idlemessage = Automatic idl&e message label.timeformat = Use {0} label.transfer.download.directory = &Download directory: label.transfer.timeout = &Transfer timeout (min): diff --git a/src/resources/i18n/spark_i18n_de.properties b/src/resources/i18n/spark_i18n_de.properties index a5cb447b..5c9140c9 100644 --- a/src/resources/i18n/spark_i18n_de.properties +++ b/src/resources/i18n/spark_i18n_de.properties @@ -310,6 +310,7 @@ label.search.service = &Such-Service label.xmpp.port = &XMPP Port label.response.timeout = &Zeitspanne bis zum Abbruch (sec) label.time.till.idle = Zeitspanne für automatisches 'Away' bei &Inaktivität (min) +label.time.till.idlemessage = Stat&usnachricht für automatisches 'Away' label.jabber.id = &Jabber ID label.group = &Gruppe label.enter.group.name = Namen für neue Gruppe eingeben