Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Move signature to message start
Browse files Browse the repository at this point in the history
Thanks to Petr Matas <petr.matas@seznam.cz>.
Pull request: #8
  • Loading branch information
kparal committed Apr 23, 2014
1 parent 2c011d5 commit 48ce1e6
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/esmska/data/Config.java
Expand Up @@ -24,7 +24,7 @@ public class Config extends Object implements Serializable {
/** mutex whether config already loaded from disk */
private static boolean loaded = false;

private static final String LATEST_VERSION = "1.6";
private static final String LATEST_VERSION = "1.6.99";
private static final Logger logger = Logger.getLogger(Config.class.getName());

private String version = "";
Expand Down
21 changes: 18 additions & 3 deletions src/esmska/data/Envelope.java
Expand Up @@ -77,6 +77,21 @@ public int getMaxTextLength() {
return min;
}

/** How many characters at the message start are occupied by the prefix
* (i.e. sender name)
*/
public int getPrefixLength() {
int max = 0;
for (Contact c : contacts) {
Gateway gateway = gateways.get(c.getGateway());
if (gateway == null) {
continue;
}
max = Math.max(max, gateway.getSenderName().length());
}
return max;
}

/** get length of one sms
* @return length of one sms or -1 when sms length is unspecified
*/
Expand Down Expand Up @@ -143,10 +158,10 @@ public ArrayList<SMS> generate() {
String msgText = text;
// add user signature to the message
if (gateway != null) {
String signature = gateway.getSenderNameSuffix();
String signature = gateway.getSenderName();
// only if signature is not already added
if (!msgText.trim().toLowerCase().endsWith(signature.trim().toLowerCase())) {
msgText += signature;
if (!msgText.trim().toLowerCase().startsWith(signature.trim().toLowerCase())) {
msgText = signature + msgText;
}
}
String messageId = SMS.generateID();
Expand Down
23 changes: 11 additions & 12 deletions src/esmska/data/Gateway.java
Expand Up @@ -161,13 +161,13 @@ public void setConfig(GatewayConfig config) {
this.config = config;
}

/** Get sender name signature suffix that should be appended to the message
/** Get sender name signature that should be prepended to the message
* before it is sent.
* @return empty string if gateway appends the name signature automatically
* or user does not want any signature to be appended; otherwise user name
* signature prepended with a newline character
* @return empty string if gateway adds the name signature automatically
* or user does not want any signature to be added; otherwise user name
* signature
*/
public String getSenderNameSuffix() {
public String getSenderName() {
if (hasFeature(Feature.SENDER_NAME)) {
// gateway will append sender name signature automatically
return "";
Expand All @@ -180,14 +180,13 @@ public String getSenderNameSuffix() {
return "";
}

// user wants to append his name signature
// prepend it with a single space to separate it from text content
String suffix = "\n" + signature.getUserName();
// user wants to add his name signature
String result = signature.getUserName();
// remove accents if required
if (Config.getInstance().isRemoveAccents()) {
suffix = MiscUtils.removeAccents(suffix);
result = MiscUtils.removeAccents(result);
}
return suffix;
return result;
}

@Override
Expand Down Expand Up @@ -278,8 +277,8 @@ public int getSignatureExtraLength() {
// gateway will append its own string
return signatureExtraLength;
} else {
// we will append a newline character before the sender name
return 1;
// we will not insert anything between signature and message
return 0;
}
}

Expand Down
43 changes: 24 additions & 19 deletions src/esmska/gui/ConfigFrame.form
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
Expand All @@ -16,10 +16,11 @@
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowGainedFocus" listener="java.awt.event.WindowFocusListener" parameters="java.awt.event.WindowEvent" handler="formWindowGainedFocus"/>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
<EventHandler event="componentShown" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="formComponentShown"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
Expand All @@ -40,13 +41,13 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="tabbedPane" alignment="1" pref="724" max="32767" attributes="0"/>
<Component id="tabbedPane" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="advancedCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="498" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="closeButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="restartLabel" alignment="0" pref="724" max="32767" attributes="0"/>
<Component id="restartLabel" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
Expand All @@ -56,7 +57,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="tabbedPane" pref="415" max="32767" attributes="0"/>
<Component id="tabbedPane" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="restartLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
Expand Down Expand Up @@ -95,17 +96,16 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="countryPrefixPanel" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="22" pref="22" max="22" attributes="0"/>
<Component id="unstableUpdatesCheckBox" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="22" pref="22" max="22" attributes="0"/>
<Component id="logLocationLabel" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="removeAccentsCheckBox" min="-2" max="-2" attributes="0"/>
<Component id="announceProgramUpdatesCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="debugCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="22" pref="22" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="unstableUpdatesCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="logLocationLabel" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace pref="363" max="32767" attributes="0"/>
</Group>
Expand Down Expand Up @@ -544,20 +544,20 @@
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel11" linkSize="4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="loginField" pref="119" max="32767" attributes="0"/>
<Component id="loginField" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel12" linkSize="4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="showPasswordCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="passwordField" alignment="0" pref="119" max="32767" attributes="0"/>
<Component id="passwordField" alignment="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="signatureComboBox" pref="72" max="32767" attributes="0"/>
<Component id="signatureComboBox" pref="0" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="sigDelButton" min="-2" max="-2" attributes="0"/>
</Group>
Expand All @@ -567,14 +567,14 @@
<Group type="102" alignment="0" attributes="0">
<Component id="senderNumberLabel" linkSize="10" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="senderNumberTextField" pref="106" max="32767" attributes="1"/>
<Component id="senderNumberTextField" pref="0" max="32767" attributes="1"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="senderNumberWarnLabel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="senderNameLabel" linkSize="10" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="senderNameTextField" pref="128" max="32767" attributes="2"/>
<Component id="senderNameTextField" pref="0" max="32767" attributes="2"/>
</Group>
</Group>
</Group>
Expand Down Expand Up @@ -739,6 +739,11 @@
<ResourceString bundle="esmska/resources/l10n.properties" key="ConfigFrame.senderNameTextField.toolTipText" replaceFormat="l10n.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="senderNameTextFieldFocusGained"/>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="senderNameTextFieldFocusLost"/>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="senderNameTextFieldKeyTyped"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="demandDeliveryReportCheckBox">
<Properties>
Expand Down

0 comments on commit 48ce1e6

Please sign in to comment.