mirror of https://github.com/sipwise/jitsi.git
tooltips. Patch provided by Marin Dzhigarov on Nov 25, 2013.cusax-fix 4926
parent
25f3208044
commit
9383a5e000
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 419 B |
|
Before Width: | Height: | Size: 408 B After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* Jitsi, 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.otr;
|
||||||
|
|
||||||
|
import java.lang.ref.*;
|
||||||
|
|
||||||
|
import net.java.sip.communicator.service.protocol.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements a <tt>ScOtrEngineListener</tt> and
|
||||||
|
* <tt>ScOtrKeyManagerListener</tt> listener for the purposes of
|
||||||
|
* <tt>OtrContactMenu</tt> and <tt>OtrMetaContactButton</tt> which listen to
|
||||||
|
* <tt>ScOtrEngine</tt> and <tt>ScOtrKeyManager</tt> while weakly referencing
|
||||||
|
* them. Fixes a memory leak of <tt>OtrContactMenu</tt> and
|
||||||
|
* <tt>OtrMetaContactButton</tt> instances because these cannot determine when
|
||||||
|
* they are to be explicitly disposed.
|
||||||
|
*
|
||||||
|
* @author Lyubomir Marinov
|
||||||
|
*/
|
||||||
|
public class OtrWeakListener
|
||||||
|
<T extends ScOtrEngineListener &
|
||||||
|
ScOtrKeyManagerListener>
|
||||||
|
implements ScOtrEngineListener,
|
||||||
|
ScOtrKeyManagerListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The <tt>ScOtrEngine</tt> the <tt>T</tt> associated with
|
||||||
|
* this instance is to listen to.
|
||||||
|
*/
|
||||||
|
private final ScOtrEngine engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <tt>ScOtrKeyManager</tt> the <tt>T</tt> associated
|
||||||
|
* with this instance is to listen to.
|
||||||
|
*/
|
||||||
|
private final ScOtrKeyManager keyManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <tt>T</tt> which is associated with this instance
|
||||||
|
* and which is to listen to {@link #engine} and {@link #keyManager}.
|
||||||
|
*/
|
||||||
|
private final WeakReference<T> listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new <tt>OtrWeakListener</tt> instance which is to allow
|
||||||
|
* a specific <tt>T</tt> to listener to a specific
|
||||||
|
* <tt>ScOtrEngine</tt> and a specific <tt>ScOtrKeyManager</tt> without
|
||||||
|
* being retained by them forever (because they live forever).
|
||||||
|
*
|
||||||
|
* @param listener the <tt>T</tt> which is to listen to the
|
||||||
|
* specified <tt>engine</tt> and <tt>keyManager</tt>
|
||||||
|
* @param engine the <tt>ScOtrEngine</tt> which is to be listened to by
|
||||||
|
* the specified <tt>T</tt>
|
||||||
|
* @param keyManager the <tt>ScOtrKeyManager</tt> which is to be
|
||||||
|
* listened to by the specified <tt>T</tt>
|
||||||
|
*/
|
||||||
|
public OtrWeakListener(
|
||||||
|
T listener,
|
||||||
|
ScOtrEngine engine, ScOtrKeyManager keyManager)
|
||||||
|
{
|
||||||
|
if (listener == null)
|
||||||
|
throw new NullPointerException("listener");
|
||||||
|
|
||||||
|
this.listener = new WeakReference<T>(listener);
|
||||||
|
this.engine = engine;
|
||||||
|
this.keyManager = keyManager;
|
||||||
|
|
||||||
|
this.engine.addListener(this);
|
||||||
|
this.keyManager.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Forwards the event/notification to the associated
|
||||||
|
* <tt>T</tt> if it is still needed by the application.
|
||||||
|
*/
|
||||||
|
public void contactPolicyChanged(Contact contact)
|
||||||
|
{
|
||||||
|
ScOtrEngineListener l = getListener();
|
||||||
|
|
||||||
|
if (l != null)
|
||||||
|
l.contactPolicyChanged(contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Forwards the event/notification to the associated
|
||||||
|
* <tt>T</tt> if it is still needed by the application.
|
||||||
|
*/
|
||||||
|
public void contactVerificationStatusChanged(Contact contact)
|
||||||
|
{
|
||||||
|
ScOtrKeyManagerListener l = getListener();
|
||||||
|
|
||||||
|
if (l != null)
|
||||||
|
l.contactVerificationStatusChanged(contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the <tt>T</tt> which is listening to {@link #engine}
|
||||||
|
* and {@link #keyManager}. If the <tt>T</tt> is no longer needed by
|
||||||
|
* the application, this instance seizes listening to <tt>engine</tt> and
|
||||||
|
* <tt>keyManager</tt> and allows the memory used by this instance to be
|
||||||
|
* reclaimed by the Java virtual machine.
|
||||||
|
*
|
||||||
|
* @return the <tt>T</tt> which is listening to
|
||||||
|
* <tt>engine</tt> and <tt>keyManager</tt> if it is still needed by the
|
||||||
|
* application; otherwise, <tt>null</tt>
|
||||||
|
*/
|
||||||
|
private T getListener()
|
||||||
|
{
|
||||||
|
T l = this.listener.get();
|
||||||
|
|
||||||
|
if (l == null)
|
||||||
|
{
|
||||||
|
engine.removeListener(this);
|
||||||
|
keyManager.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Forwards the event/notification to the associated
|
||||||
|
* <tt>T</tt> if it is still needed by the application.
|
||||||
|
*/
|
||||||
|
public void globalPolicyChanged()
|
||||||
|
{
|
||||||
|
ScOtrEngineListener l = getListener();
|
||||||
|
|
||||||
|
if (l != null)
|
||||||
|
l.globalPolicyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Forwards the event/notification to the associated
|
||||||
|
* <tt>T</tt> if it is still needed by the application.
|
||||||
|
*/
|
||||||
|
public void sessionStatusChanged(Contact contact)
|
||||||
|
{
|
||||||
|
ScOtrEngineListener l = getListener();
|
||||||
|
|
||||||
|
if (l != null)
|
||||||
|
l.sessionStatusChanged(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Jitsi, 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.otr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends otr4j's <tt>SessionStatus</tt> with two additional states.
|
||||||
|
*
|
||||||
|
* @author Marin Dzhigarov
|
||||||
|
*/
|
||||||
|
public enum ScSessionStatus
|
||||||
|
{
|
||||||
|
PLAINTEXT,
|
||||||
|
ENCRYPTED,
|
||||||
|
FINISHED,
|
||||||
|
/*
|
||||||
|
* A Session transitions in LOADING state right before
|
||||||
|
* Session.startSession() is invoked.
|
||||||
|
*/
|
||||||
|
LOADING,
|
||||||
|
/*
|
||||||
|
* A Session transitions in TIMED_OUT state after being in LOADING state for
|
||||||
|
* a long period of time.
|
||||||
|
*/
|
||||||
|
TIMED_OUT
|
||||||
|
}
|
||||||
Loading…
Reference in new issue