Improves the OTR policy so that automatic sessions will no longer be reinitiated if OTR is stopped manually. Also cleans up outdated javadoc.

cusax-fix 5050
Marin 13 years ago
parent cd1b39f253
commit ada034b18a

@ -30,12 +30,6 @@ public class OtrActivator
extends AbstractServiceDependentActivator
implements ServiceListener
{
/**
* A property specifying whether private messaging should be automatically
* initiated.
*/
public static final String AUTO_INIT_OTR_PROP =
"net.java.sip.communicator.plugin.otr.AUTO_INIT_PRIVATE_MESSAGING";
/**
* The {@link BundleContext} of the {@link OtrActivator}.

@ -23,6 +23,7 @@
*
* @author George Politis
* @author Lyubomir Marinov
* @author Marin Dzhigarov
*/
class OtrContactMenu
implements ActionListener,
@ -191,12 +192,28 @@ public void actionPerformed(ActionEvent e)
String actionCommand = e.getActionCommand();
if (ACTION_COMMAND_END_OTR.equals(actionCommand))
{
OtrPolicy policy =
OtrActivator.scOtrEngine.getContactPolicy(contact.contact);
policy.setSendWhitespaceTag(false);
OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy);
// End session.
OtrActivator.scOtrEngine.endSession(contact);
}
else if (ACTION_COMMAND_START_OTR.equals(actionCommand))
{
OtrPolicy policy =
OtrActivator.scOtrEngine.getContactPolicy(contact.contact);
OtrPolicy globalPolicy =
OtrActivator.scOtrEngine.getGlobalPolicy();
policy.setSendWhitespaceTag(globalPolicy.getSendWhitespaceTag());
OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy);
// Start session.
OtrActivator.scOtrEngine.startSession(contact);
}
else if (ACTION_COMMAND_REFRESH_OTR.equals(actionCommand))
// Refresh session.
@ -222,7 +239,6 @@ else if (ACTION_COMMAND_CB_AUTO.equals(actionCommand))
OtrActivator.scOtrEngine.getContactPolicy(contact.contact);
boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected();
policy.setEnableAlways(state);
policy.setSendWhitespaceTag(state);
OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy);
@ -234,13 +250,8 @@ else if (ACTION_COMMAND_CB_AUTO_ALL.equals(actionCommand))
OtrActivator.scOtrEngine.getGlobalPolicy();
boolean state = ((JCheckBoxMenuItem) e.getSource()).isSelected();
globalPolicy.setEnableAlways(state);
globalPolicy.setSendWhitespaceTag(state);
OtrActivator.configService.setProperty(
OtrActivator.AUTO_INIT_OTR_PROP,
Boolean.toString(state));
OtrActivator.scOtrEngine.setGlobalPolicy(globalPolicy);
}
@ -420,13 +431,9 @@ private void buildMenu()
.getI18NString("plugin.otr.menu.CB_AUTO_ALL"));
cbAlwaysAll.setEnabled(policy.getEnableManual());
String autoInitPropValue
= OtrActivator.configService.getString(
OtrActivator.AUTO_INIT_OTR_PROP);
boolean isAutoInit =
OtrActivator.scOtrEngine.getGlobalPolicy().getEnableAlways();
if (autoInitPropValue != null)
isAutoInit = Boolean.parseBoolean(autoInitPropValue);
cbAlwaysAll.setSelected(isAutoInit);
cbAlwaysAll.setActionCommand(ACTION_COMMAND_CB_AUTO_ALL);

@ -28,6 +28,7 @@
* the main chat toolbar.
*
* @author George Politis
* @author Marin Dzhigarov
*/
public class OtrMetaContactButton
extends AbstractPluginComponent
@ -55,10 +56,6 @@ public class OtrMetaContactButton
private Image timedoutPadlockImage;
/**
* The timer task that changes the padlock icon to "loading" and
* then to "broken" if the specified timeout passed
*/
public void sessionStatusChanged(OtrContact otrContact)
{
// OtrMetaContactButton.this.contact can be null.
@ -180,6 +177,12 @@ public void actionPerformed(ActionEvent e)
switch (OtrActivator.scOtrEngine.getSessionStatus(otrContact))
{
case ENCRYPTED:
OtrPolicy policy =
OtrActivator.scOtrEngine.getContactPolicy(
otrContact.contact);
policy.setSendWhitespaceTag(false);
OtrActivator.scOtrEngine.setContactPolicy(
otrContact.contact, policy);
case FINISHED:
case LOADING:
// Default action for finished, encrypted and loading
@ -188,6 +191,15 @@ public void actionPerformed(ActionEvent e)
break;
case TIMED_OUT:
case PLAINTEXT:
policy =
OtrActivator.scOtrEngine.getContactPolicy(
otrContact.contact);
OtrPolicy globalPolicy =
OtrActivator.scOtrEngine.getGlobalPolicy();
policy.setSendWhitespaceTag(
globalPolicy.getSendWhitespaceTag());
OtrActivator.scOtrEngine.setContactPolicy(
otrContact.contact, policy);
// Default action for timed_out and plaintext sessions
// is start session.
OtrActivator.scOtrEngine.startSession(otrContact);

@ -249,12 +249,7 @@ public void loadPolicy()
cbAutoInitiate.setEnabled(otrEnabled);
cbRequireOtr.setEnabled(otrEnabled);
String autoInitPropValue
= OtrActivator.configService.getString(
OtrActivator.AUTO_INIT_OTR_PROP);
boolean isAutoInit = otrPolicy.getEnableAlways();
if (autoInitPropValue != null)
isAutoInit = Boolean.parseBoolean(autoInitPropValue);
cbAutoInitiate.setSelected(isAutoInit);
@ -322,10 +317,7 @@ public void actionPerformed(ActionEvent e)
boolean isAutoInit
= ((JCheckBox) e.getSource()).isSelected();
otrPolicy.setEnableAlways(isAutoInit);
OtrActivator.configService.setProperty(
OtrActivator.AUTO_INIT_OTR_PROP,
Boolean.toString(isAutoInit));
otrPolicy.setSendWhitespaceTag(isAutoInit);
OtrActivator.scOtrEngine.setGlobalPolicy(otrPolicy);

Loading…
Cancel
Save