Removes special symbols before callng phone numbers and lets the user configure a property to enable/disable this functionality.

cusax-fix
Yana Stamcheva 15 years ago
parent f19eb013da
commit 5cb8b89cbe

@ -722,6 +722,8 @@ plugin.generalconfig.ERROR_PORT_NUMBER=Wrong port number
plugin.generalconfig.CHECK_FOR_UPDATES=Check for updates on startup
plugin.generalconfig.STARTUP_CONFIG=Startup
plugin.generalconfig.LEAVE_CHATROOM_ON_WINDOW_CLOSE=Leave chat rooms when closing window
plugin.generalconfig.REMOVE_SPECIAL_PHONE_SYMBOLS=Remove special symbols before callng phone numbers
plugin.generalconfig.SIP_CALL_CONFIG=SIP configurations
# gibberish accregwizz
plugin.gibberishaccregwizz.PROTOCOL_NAME=Gibberish

@ -80,6 +80,8 @@ public class GuiActivator implements BundleActivator
private static SmiliesReplacementService smiliesService;
private static PhoneNumberI18nService phoneNumberService;
private static AccountManager accountManager;
private static List<ContactSourceService> contactSources;
@ -805,6 +807,24 @@ public static SmiliesReplacementService getSmiliesReplacementSource()
return smiliesService;
}
/**
* Returns the <tt>PhoneNumberI18nService</tt> obtained from the bundle
* context.
*
* @return the <tt>PhoneNumberI18nService</tt> implementation obtained
* from the bundle context
*/
public static PhoneNumberI18nService getPhoneNumberService()
{
if (phoneNumberService == null)
{
phoneNumberService
= ServiceUtils.getService(bundleContext,
PhoneNumberI18nService.class);
}
return phoneNumberService;
}
/**
* Returns the <tt>SecurityAuthority</tt> implementation registered to
* handle security authority events.

@ -15,6 +15,7 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.call.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.skin.*;
@ -276,7 +277,20 @@ private void updateCallIcon(MouseEvent evt)
if (searchText == null)
return;
searchText = GuiUtils.formatCallString(searchText);
if (ConfigurationManager.isNormalizePhoneNumber())
{
if (!StringUtils.containsLetters(searchText)
&& GuiActivator.getPhoneNumberService()
.isPhoneNumber(searchText))
{
searchText = GuiActivator.getPhoneNumberService()
.normalize(searchText);
}
else
{
searchText = StringUtils.concatenateWords(searchText);
}
}
// Show a tool tip over the call button.
getComponent().setToolTipText(callString + " " + searchText);

@ -737,6 +737,19 @@ public static String getSendFileLastDir()
return sendFileLastDir;
}
/**
* Returns <code>true</code> if phone numbers should be normalized,
* <code>false</code> otherwise.
*
* @return <code>true</code> if phone numbers should be normalized,
* <code>false</code> otherwise.
*/
public static boolean isNormalizePhoneNumber()
{
return configService.getBoolean(
"impl.gui.NORMALIZE_PHONE_NUMBER", true);
}
/**
* Sets the transparency value for all transparent windows.
*

@ -88,4 +88,40 @@ public boolean phoneNumbersMatch(String aPhoneNumber, String bPhoneNumber)
throw new IllegalArgumentException(npex);
}
}
public boolean isNumber(String possibleNumber)
{
PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
try
{
if (numberUtil.isPossibleNumber(possibleNumber, null))
return true;
else
return numberUtil.isPossibleNumber(
numberUtil.parse( possibleNumber,
Locale.getDefault().getCountry()));
}
catch (NumberParseException e)
{
return false;
}
}
public boolean isPhoneNumber(String possibleNumber)
{
PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
try
{
if (numberUtil.isPossibleNumber(possibleNumber, null))
return true;
else
return numberUtil.isPossibleNumber(
numberUtil.parse( possibleNumber,
Locale.getDefault().getCountry()));
}
catch (NumberParseException e)
{
return false;
}
}
}

@ -15,32 +15,37 @@
public class ConfigurationManager
{
public static final String ENTER_COMMAND = "Enter";
public static final String CTRL_ENTER_COMMAND = "Ctrl-Enter";
/**
* Indicates whether the message automatic popup is enabled.
*/
private static boolean autoPopupNewMessage;
private static String sendMessageCommand;
private static boolean isSendTypingNotifications;
private static boolean isMultiChatWindowEnabled;
private static boolean isLeaveChatRoomOnWindowCloseEnabled;
private static boolean isHistoryLoggingEnabled;
private static boolean isHistoryShown;
private static int chatHistorySize;
private static int windowTransparency;
private static boolean isTransparentWindowEnabled;
/**
* Indicates if phone numbers should be normalized before dialed.
*/
private static boolean isNormalizePhoneNumber;
private static ConfigurationService configService
= GeneralConfigPluginActivator.getConfigurationService();
@ -52,12 +57,12 @@ public static void loadGuiConfigurations()
// Load the "auPopupNewMessage" property.
String autoPopupProperty =
"service.gui.AUTO_POPUP_NEW_MESSAGE";
String autoPopup = configService.getString(autoPopupProperty);
if(autoPopup == null)
autoPopup = Resources.getSettingsString(autoPopupProperty);
if(autoPopup != null && autoPopup.equalsIgnoreCase("yes"))
autoPopupNewMessage = true;
@ -65,7 +70,7 @@ public static void loadGuiConfigurations()
String messageCommandProperty =
"service.gui.SEND_MESSAGE_COMMAND";
String messageCommand = configService.getString(messageCommandProperty);
if(messageCommand == null)
messageCommand =
Resources.getSettingsString(messageCommandProperty);
@ -134,11 +139,11 @@ public static void loadGuiConfigurations()
// Load the "isHistoryLoggingEnabled" property.
String isHistoryLoggingEnabledPropertyString =
"impl.msghistory.IS_MESSAGE_HISTORY_ENABLED";
String isHistoryLoggingEnabledString
= configService.getString(
isHistoryLoggingEnabledPropertyString);
if(isHistoryLoggingEnabledString == null)
isHistoryLoggingEnabledString =
Resources.
@ -151,14 +156,14 @@ public static void loadGuiConfigurations()
= new Boolean(isHistoryLoggingEnabledString)
.booleanValue();
}
// Load the "isHistoryShown" property.
String isHistoryShownStringProperty =
"service.gui.IS_MESSAGE_HISTORY_SHOWN";
String isHistoryShownString
= configService.getString(isHistoryShownStringProperty);
if(isHistoryShownString == null)
isHistoryShownString =
Resources.getSettingsString(isHistoryShownStringProperty);
@ -223,6 +228,14 @@ public static void loadGuiConfigurations()
windowTransparency
= Integer.parseInt(windowTransparencyString);
}
// Load the "NORMALIZE_PHONE_NUMBER" property.
String normalizePhoneNumberProperty =
"impl.gui.NORMALIZE_PHONE_NUMBER";
isNormalizePhoneNumber
= GeneralConfigPluginActivator.getConfigurationService()
.getBoolean(normalizePhoneNumberProperty, true);
}
/**
@ -364,6 +377,32 @@ public static void setTransparentWindowEnabled(
new Boolean(isTransparentWindowEnabled).toString());
}
/**
* Returns <code>true</code> if phone numbers should be normalized,
* <code>false</code> otherwise.
*
* @return <code>true</code> if phone numbers should be normalized,
* <code>false</code> otherwise.
*/
public static boolean isNormalizePhoneNumber()
{
return isNormalizePhoneNumber;
}
/**
* Updates the "NORMALIZE_PHONE_NUMBER" property.
*
* @param isNormalize indicates to the user interface whether all dialed
* phone numbers should be normalized
*/
public static void setNormalizePhoneNumber(boolean isNormalize)
{
ConfigurationManager.isNormalizePhoneNumber = isNormalize;
configService.setProperty("impl.gui.NORMALIZE_PHONE_NUMBER",
Boolean.toString(isNormalize));
}
/**
* Returns the transparency value for all transparent windows.
*
@ -374,6 +413,12 @@ public static int getWindowTransparency()
return windowTransparency;
}
/**
* Updates the "WINDOW_TRANSPARENCY" property.
*
* @param windowTransparency indicates to the user interface what is the
* window transparency value
**/
public static void setWindowTransparency(int windowTransparency)
{
ConfigurationManager.windowTransparency = windowTransparency;

@ -102,13 +102,27 @@ public void start(BundleContext bc)
.registerService(
ConfigurationForm.class.getName(),
new LazyConfigurationForm(
"net.java.sip.communicator.plugin.generalconfig.GeneralConfigurationPanel",
"net.java.sip.communicator.plugin." +
"generalconfig.GeneralConfigurationPanel",
getClass().getClassLoader(),
"plugin.generalconfig.PLUGIN_ICON",
"service.gui.GENERAL",
0),
properties);
// Registers the sip config panel as advanced configuration form.
properties.put( ConfigurationForm.FORM_TYPE,
ConfigurationForm.ADVANCED_TYPE);
bundleContext.registerService(
ConfigurationForm.class.getName(),
new LazyConfigurationForm(
SIPConfigForm.class.getName(),
getClass().getClassLoader(),
null,
"plugin.generalconfig.SIP_CALL_CONFIG",
51, true),
properties);
/*
* Wait for the first ProtocolProviderService to register in order to
* start the auto-away functionality i.e. to call #startThread().

@ -79,7 +79,7 @@ public GeneralConfigurationPanel()
mainPanel.add(new JSeparator());
mainPanel.add(Box.createVerticalStrut(10));
mainPanel.add(createSipConfigPanel());
mainPanel.add(createCallConfigPanel());
mainPanel.add(Box.createVerticalStrut(10));
}
@ -596,10 +596,11 @@ public void actionPerformed(ActionEvent e)
}
/**
* Initializes the sip port configuration panel.
* @return the created panel
* Creates the call configuration panel.
*
* @return the call configuration panel
*/
private Component createSipConfigPanel()
private Component createCallConfigPanel()
{
JPanel callConfigPanel = new TransparentPanel(new BorderLayout());
@ -608,120 +609,51 @@ private Component createSipConfigPanel()
Resources.getString("service.gui.CALL") + ":"),
BorderLayout.WEST);
TransparentPanel sipClientPortConfigPanel = new TransparentPanel();
sipClientPortConfigPanel.setLayout(new BorderLayout(10, 10));
sipClientPortConfigPanel.setPreferredSize(new Dimension(250, 72));
callConfigPanel.add(createNormalizeNumberCheckBox());
callConfigPanel.add(sipClientPortConfigPanel);
return callConfigPanel;
}
TransparentPanel labelPanel
= new TransparentPanel(new GridLayout(0, 1, 2, 2));
TransparentPanel valuePanel
= new TransparentPanel(new GridLayout(0, 1, 2, 2));
/**
* Creates the normalized phone number check box.
*
* @return the created component
*/
private Component createNormalizeNumberCheckBox()
{
JPanel checkBoxPanel = new TransparentPanel(new BorderLayout());
sipClientPortConfigPanel.add(labelPanel,
BorderLayout.WEST);
sipClientPortConfigPanel.add(valuePanel,
BorderLayout.CENTER);
JCheckBox formatPhoneNumber = new JCheckBox("",
ConfigurationManager.isNormalizePhoneNumber());
labelPanel.add(new JLabel(
Resources.getString(
"plugin.generalconfig.SIP_CLIENT_PORT")));
labelPanel.add(new JLabel(
Resources.getString(
"plugin.generalconfig.SIP_CLIENT_SECURE_PORT")));
formatPhoneNumber.setAlignmentY(Component.TOP_ALIGNMENT);
TransparentPanel emptyPanel = new TransparentPanel();
emptyPanel.setMaximumSize(new Dimension(40, 35));
labelPanel.add(emptyPanel);
final JTextField clientPortField = new JTextField(6);
clientPortField.setText(
String.valueOf(ConfigurationManager.getClientPort()));
valuePanel.add(clientPortField);
clientPortField.addFocusListener(new FocusListener()
formatPhoneNumber.addActionListener(new ActionListener()
{
private String oldValue = null;
public void focusLost(FocusEvent e)
{
try
{
int port =
Integer.valueOf(clientPortField.getText());
if(port <= 0 || port > 65535)
throw new NumberFormatException(
"Not a port number");
ConfigurationManager.setClientPort(port);
}
catch (NumberFormatException ex)
{
// not a number for port
String error =
Resources.getString(
"plugin.generalconfig.ERROR_PORT_NUMBER");
GeneralConfigPluginActivator.getUIService().
getPopupDialog().showMessagePopupDialog(
error,
error,
PopupDialog.ERROR_MESSAGE);
clientPortField.setText(oldValue);
}
}
public void focusGained(FocusEvent e)
public void actionPerformed(ActionEvent e)
{
oldValue = clientPortField.getText();
ConfigurationManager.setNormalizePhoneNumber(
((JCheckBox)e.getSource()).isSelected());
}
});
final JTextField clientSecurePortField = new JTextField(6);
clientSecurePortField.setText(
String.valueOf(ConfigurationManager.getClientSecurePort()));
valuePanel.add(clientSecurePortField);
clientSecurePortField.addFocusListener(new FocusListener()
{
private String oldValue = null;
public void focusLost(FocusEvent e)
{
try
{
int port =
Integer.valueOf(clientSecurePortField.getText());
StyledHTMLEditorPane checkBoxTextLabel = new StyledHTMLEditorPane();
if(port <= 0 || port > 65535)
throw new NumberFormatException(
"Not a port number");
checkBoxTextLabel.setContentType("text/html");
checkBoxTextLabel.appendToEnd(
"<html>" + GeneralConfigPluginActivator.getResources().getI18NString(
"plugin.generalconfig.REMOVE_SPECIAL_PHONE_SYMBOLS") + "</html>");
ConfigurationManager.setClientSecurePort(port);
}
catch (NumberFormatException ex)
{
// not a number for port
String error =
Resources.getString(
"plugin.generalconfig.ERROR_PORT_NUMBER");
GeneralConfigPluginActivator.getUIService().
getPopupDialog().showMessagePopupDialog(
error,
error,
PopupDialog.ERROR_MESSAGE);
clientSecurePortField.setText(oldValue);
}
}
checkBoxTextLabel.setBorder(
BorderFactory.createEmptyBorder(3, 0, 0, 0));
checkBoxTextLabel.setOpaque(false);
checkBoxTextLabel.setEditable(false);
public void focusGained(FocusEvent e)
{
oldValue = clientSecurePortField.getText();
}
});
checkBoxPanel.add(formatPhoneNumber, BorderLayout.WEST);
checkBoxPanel.add(checkBoxTextLabel, BorderLayout.CENTER);
return callConfigPanel;
return checkBoxPanel;
}
/**
* Initializes the startup config panel.
* @return the created component

@ -0,0 +1,138 @@
/*
* 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.generalconfig;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.swing.*;
/**
* Implementation of the configuration form.
*
* @author Damian Minkov
*/
public class SIPConfigForm
extends TransparentPanel
{
/**
* Creates the form.
*/
public SIPConfigForm()
{
super(new BorderLayout());
TransparentPanel sipClientPortConfigPanel = new TransparentPanel();
sipClientPortConfigPanel.setLayout(new BorderLayout(10, 10));
sipClientPortConfigPanel.setPreferredSize(new Dimension(250, 72));
add(sipClientPortConfigPanel, BorderLayout.NORTH);
TransparentPanel labelPanel
= new TransparentPanel(new GridLayout(0, 1, 2, 2));
TransparentPanel valuePanel
= new TransparentPanel(new GridLayout(0, 1, 2, 2));
sipClientPortConfigPanel.add(labelPanel,
BorderLayout.WEST);
sipClientPortConfigPanel.add(valuePanel,
BorderLayout.CENTER);
labelPanel.add(new JLabel(
Resources.getString(
"plugin.generalconfig.SIP_CLIENT_PORT")));
labelPanel.add(new JLabel(
Resources.getString(
"plugin.generalconfig.SIP_CLIENT_SECURE_PORT")));
final JTextField clientPortField = new JTextField(6);
clientPortField.setText(
String.valueOf(ConfigurationManager.getClientPort()));
valuePanel.add(clientPortField);
clientPortField.addFocusListener(new FocusListener()
{
private String oldValue = null;
public void focusLost(FocusEvent e)
{
try
{
int port =
Integer.valueOf(clientPortField.getText());
if(port <= 0 || port > 65535)
throw new NumberFormatException(
"Not a port number");
ConfigurationManager.setClientPort(port);
}
catch (NumberFormatException ex)
{
// not a number for port
String error =
Resources.getString(
"plugin.generalconfig.ERROR_PORT_NUMBER");
GeneralConfigPluginActivator.getUIService().
getPopupDialog().showMessagePopupDialog(
error,
error,
PopupDialog.ERROR_MESSAGE);
clientPortField.setText(oldValue);
}
}
public void focusGained(FocusEvent e)
{
oldValue = clientPortField.getText();
}
});
final JTextField clientSecurePortField = new JTextField(6);
clientSecurePortField.setText(
String.valueOf(ConfigurationManager.getClientSecurePort()));
valuePanel.add(clientSecurePortField);
clientSecurePortField.addFocusListener(new FocusListener()
{
private String oldValue = null;
public void focusLost(FocusEvent e)
{
try
{
int port
= Integer.valueOf(clientSecurePortField.getText());
if(port <= 0 || port > 65535)
throw new NumberFormatException(
"Not a port number");
ConfigurationManager.setClientSecurePort(port);
}
catch (NumberFormatException ex)
{
// not a number for port
String error =
Resources.getString(
"plugin.generalconfig.ERROR_PORT_NUMBER");
GeneralConfigPluginActivator.getUIService().
getPopupDialog().showMessagePopupDialog(
error,
error,
PopupDialog.ERROR_MESSAGE);
clientSecurePortField.setText(oldValue);
}
}
public void focusGained(FocusEvent e)
{
oldValue = clientSecurePortField.getText();
}
});
}
}

@ -37,4 +37,12 @@ public interface PhoneNumberI18nService
* numbers; otherwise, <tt>false</tt>
*/
public boolean phoneNumbersMatch(String aPhoneNumber, String bPhoneNumber);
/**
* Indicates if the given string is possibly a phone number.
*
* @param possibleNumber the string to be verified
* @return
*/
public boolean isPhoneNumber(String possibleNumber);
}

@ -327,60 +327,6 @@ public static String formatTime(long time)
return timeStrBuf.toString();
}
/**
* Formats the given call string by removing any special characters, such as
* intervals and brackets. Dashes are removed from number only strings.
*
* @param callString a string that would be called
* @return the formatted string, ready to be called
*/
public static String formatCallString(String callString)
{
boolean isDigitsOnly = isDigitsOnly(callString);
StringBuffer normalizedCallString
= new StringBuffer(callString.length());
char[] stringAsCharArray = callString.toCharArray();
for (char character : stringAsCharArray)
{
if ((character != ' '
&& character != '('
&& character != ')')
&& (!isDigitsOnly || character != '-'))
{
normalizedCallString.append(character);
}
}
return normalizedCallString.toString();
}
/**
* Indicates if the given string contains only digits.
*
* @param s the string to verify
* @return <tt>true</tt> if the given string contains only digits or
* <tt>false</tt> if the string contains also other characters
*/
public static boolean isDigitsOnly(String s)
{
char[] stringAsCharArray = s.toCharArray();
boolean digitsOnly = true;
for (char character : stringAsCharArray)
{
if (character != ' '
&& character != '('
&& character != ')'
&& character != '-'
&& DIGIT_MAPPINGS.get(Character.toUpperCase(character)) == null)
digitsOnly = false;
}
return digitsOnly;
}
/**
* Subtracts the two dates.
* @param date1 the first date argument

@ -7,7 +7,6 @@
package net.java.sip.communicator.util;
import java.io.*;
import java.util.*;
/**
* Utility class that helps to work with <tt>String</tt> class.
@ -195,4 +194,44 @@ public static boolean isNumber(String string)
return true;
}
/**
* Indicates if the given string contains any letters.
*
* @param string the string to check for letters
* @return <tt>true</tt> if the given string contains letters,
* <tt>false</tt> - otherwise
*/
public static boolean containsLetters(String string)
{
for (int i = 0; i < string.length(); i++)
{
if (Character.isLetter(string.charAt(i)))
return true;
}
return false;
}
/**
* Removes all spaces from the given string and returns a concatenated
* result string.
*
* @param string the string to concatenate
* @return the concatenated string
*/
public static String concatenateWords(String string)
{
StringBuffer buff = new StringBuffer();
char[] stringAsCharArray = string.toCharArray();
for (char character : stringAsCharArray)
{
if (character != ' ')
{
buff.append(character);
}
}
return buff.toString();
}
}

Loading…
Cancel
Save