Basic support for contact capabilities in the user interface.

cusax-fix
Yana Stamcheva 16 years ago
parent 2b328eedf7
commit a0d7953432

@ -2071,4 +2071,14 @@ public void metaContactAvatarUpdated(MetaContactAvatarUpdateEvent evt)
{
// TODO: Store meta contact avatar.
}
/**
* Indicates that the capabilities of a given <tt>MetaContact</tt> have
* changed.
* @param evt the <tt>MetaContactCapabilitiesEvent</tt> that notified us
*/
public void metaContactCapabilitiesChanged(MetaContactCapabilitiesEvent evt)
{
// TODO Auto-generated method stub
}
}

@ -364,41 +364,68 @@ public Contact getDefaultContact(Class<? extends OperationSet> operationSet)
// if the current default contact supports the requested operationSet
// we use it
if (defaultContact != null
&& defaultContact.getProtocolProvider()
.getOperationSet(operationSet) != null)
if (defaultContact != null)
{
defaultOpSetContact = defaultContact;
ProtocolProviderService contactProvider
= defaultContact.getProtocolProvider();
// First try to ask the capabilities operation set if such is
// available.
OperationSetContactCapabilities capOpSet = contactProvider
.getOperationSet(OperationSetContactCapabilities.class);
if (capOpSet != null)
{
if (capOpSet.getOperationSet(defaultContact, operationSet)
!= null)
defaultOpSetContact = defaultContact;
}
else if (contactProvider.getOperationSet(operationSet) != null)
defaultOpSetContact = defaultContact;
}
else
if (defaultOpSetContact == null)
{
PresenceStatus currentStatus = null;
for (Contact protoContact : protoContacts)
{
// we filter to care only about contact which support
ProtocolProviderService contactProvider
= protoContact.getProtocolProvider();
// First try to ask the capabilities operation set if such is
// available.
OperationSetContactCapabilities capOpSet = contactProvider
.getOperationSet(OperationSetContactCapabilities.class);
// We filter to care only about contact which support
// the needed opset.
if (protoContact.getProtocolProvider()
.getOperationSet(operationSet) != null)
if (capOpSet != null)
{
PresenceStatus contactStatus
= protoContact.getPresenceStatus();
if (capOpSet.getOperationSet(defaultContact, operationSet)
== null)
continue;
}
else if (contactProvider.getOperationSet(operationSet) == null)
continue;
if (currentStatus != null)
{
if (currentStatus.getStatus()
< contactStatus.getStatus())
{
currentStatus = contactStatus;
defaultOpSetContact = protoContact;
}
}
else
PresenceStatus contactStatus
= protoContact.getPresenceStatus();
if (currentStatus != null)
{
if (currentStatus.getStatus()
< contactStatus.getStatus())
{
currentStatus = contactStatus;
defaultOpSetContact = protoContact;
}
}
else
{
currentStatus = contactStatus;
defaultOpSetContact = protoContact;
}
}
}
return defaultOpSetContact;

@ -29,7 +29,8 @@
public class MetaContactListServiceImpl
implements MetaContactListService,
ServiceListener,
ContactPresenceStatusListener
ContactPresenceStatusListener,
ContactCapabilitiesListener
{
private static final Logger logger
= Logger.getLogger(MetaContactListServiceImpl.class);
@ -1673,6 +1674,15 @@ private synchronized void handleProviderAdded(
//events for all contacts that we have already extracted
if(opSetPersPresence != null)
opSetPersPresence.addContactPresenceStatusListener(this);
// Check if the capabilities operation set is available for this
// contact and add a listener to it in order to track capabilities'
// changes for all contained protocol contacts.
OperationSetContactCapabilities capOpSet
= provider.getOperationSet(OperationSetContactCapabilities.class);
if (capOpSet != null)
capOpSet.addContactCapabilitiesListener(this);
}
/**
@ -1697,37 +1707,48 @@ private void handleProviderRemoved(
provider.getOperationSet(OperationSetPersistentPresence.class);
//ignore if persistent presence is not supported.
if(persPresOpSet == null)
return;
if(persPresOpSet != null)
{
//we don't gare about subscription and presence status events here any
//longer
persPresOpSet.removeContactPresenceStatusListener(this);
persPresOpSet.removeSubscriptionListener(
clSubscriptionEventHandler);
persPresOpSet.removeServerStoredGroupChangeListener(
clGroupEventHandler);
//we don't gare about subscription and presence status events here any
//longer
persPresOpSet.removeContactPresenceStatusListener(this);
persPresOpSet.removeSubscriptionListener(clSubscriptionEventHandler);
persPresOpSet.removeServerStoredGroupChangeListener(clGroupEventHandler);
ContactGroup rootGroup
= persPresOpSet.getServerStoredContactListRoot();
ContactGroup rootGroup
= persPresOpSet.getServerStoredContactListRoot();
//iterate all sub groups and remove them one by one
//(we dont simply remove the root group because the mcl storage
// manager is stupid (i wrote it) and doesn't know root groups exist.
// that's why it needs to hear an event for every single group.)
Iterator<ContactGroup> subgroups = rootGroup.subgroups();
//iterate all sub groups and remove them one by one
//(we dont simply remove the root group because the mcl storage manager
//is stupid (i wrote it) and doesn't know root groups exist. that's why
//it needs to hear an event for every single group.)
Iterator<ContactGroup> subgroups = rootGroup.subgroups();
while(subgroups.hasNext())
{
ContactGroup group = subgroups.next();
//remove the group
this.removeContactGroupFromMetaContactGroup(
(MetaContactGroupImpl) findMetaContactGroupByContactGroup(
group),
group,
provider);
}
while(subgroups.hasNext())
{
ContactGroup group = subgroups.next();
//remove the group
//remove the root group
this.removeContactGroupFromMetaContactGroup(
(MetaContactGroupImpl)findMetaContactGroupByContactGroup(group),
group,
provider);
this.rootMetaGroup, rootGroup, provider);
}
//remove the root group
this.removeContactGroupFromMetaContactGroup(
this.rootMetaGroup, rootGroup, provider);
// Check if the capabilities operation set is available for this
// contact and remove previously added listeners.
OperationSetContactCapabilities capOpSet
= provider.getOperationSet(OperationSetContactCapabilities.class);
if (capOpSet != null)
capOpSet.removeContactCapabilitiesListener(this);
}
/**
@ -3146,4 +3167,79 @@ public synchronized void waitForEvent(long millis)
}
}
}
/**
* Notifies this listener that the list of the <tt>OperationSet</tt>
* capabilities of a <tt>Contact</tt> has changed.
*
* @param event a <tt>ContactCapabilitiesEvent</tt> with ID
* {@link ContactCapabilitiesEvent#SUPPORTED_OPERATION_SETS_CHANGED} which
* specifies the <tt>Contact</tt> whose list of <tt>OperationSet</tt>
* capabilities has changed
*/
public void supportedOperationSetsChanged(ContactCapabilitiesEvent event)
{
// If the source contact isn't contained in this meta contact we have
// nothing more to do here.
MetaContactImpl metaContactImpl
= (MetaContactImpl) findMetaContactByContact(
event.getSourceContact());
//ignore if we have no meta contact.
if(metaContactImpl == null)
return;
fireCapabilitiesEvent(metaContactImpl,
MetaContactCapabilitiesEvent.SUPPORTED_OPERATION_SETS_CHANGED);
}
/**
* Fires a new <tt>MetaContactCapabilitiesEvent</tt> to notify the
* registered <tt>MetaContactCapabilitiesListener</tt>s that this
* <tt>MetaContact</tt> has changed its list of <tt>OperationSet</tt>
* capabilities.
*
* @param metaContact the source <tt>MetaContact</tt>, which capabilities
* has changed
* @param eventID the ID of the event to be fired which indicates the
* specifics of the change of the list of <tt>OperationSet</tt> capabilities
* of the specified <tt>sourceContact</tt> and the details of the event
*/
private void fireCapabilitiesEvent(MetaContact metaContact, int eventID)
{
MetaContactListListener[] listeners;
synchronized (metaContactListListeners)
{
listeners
= metaContactListListeners.toArray(
new MetaContactListListener[
metaContactListListeners.size()]);
}
if (listeners.length != 0)
{
MetaContactCapabilitiesEvent event
= new MetaContactCapabilitiesEvent(metaContact, eventID);
for (MetaContactListListener listener : listeners)
{
switch (eventID)
{
case MetaContactCapabilitiesEvent
.SUPPORTED_OPERATION_SETS_CHANGED:
listener.metaContactCapabilitiesChanged(event);
break;
default:
if (logger.isDebugEnabled())
{
logger.debug(
"Cannot fire MetaContactCapabilitiesEvent with"
+ " unsupported eventID: "
+ eventID);
}
throw new IllegalArgumentException("eventID");
}
}
}
}
}

@ -372,6 +372,9 @@ public void metaContactRemoved(MetaContactEvent evt)
public void metaContactAvatarUpdated(MetaContactAvatarUpdateEvent evt) {}
public void metaContactCapabilitiesChanged(MetaContactCapabilitiesEvent evt)
{}
/**
* Implements <tt>MetaContactListListener.metaContactRenamed</tt> method.
* When a meta contact is renamed, updates all related labels in this

@ -219,6 +219,9 @@ public void metaContactMoved(MetaContactMovedEvent evt)
public void metaContactAvatarUpdated(MetaContactAvatarUpdateEvent evt) {}
public void metaContactCapabilitiesChanged(
MetaContactCapabilitiesEvent evt) {}
/**
* Handles the <tt>MetaContactGroupEvent</tt>. Refreshes the list model
* when a new meta contact group has been added.

@ -513,7 +513,12 @@ public void protoContactRemoved(ProtoContactEvent evt)
= MetaContactListSource.getUIContact(oldParent);
if (oldUIContact != null)
removeContact(oldUIContact);
{
ContactNode contactNode = oldUIContact.getContactNode();
if (contactNode != null)
treeModel.nodeChanged(contactNode);
}
}
/**
@ -588,6 +593,29 @@ public void metaGroupReceived(MetaGroupQueryEvent event)
MetaContactListSource.createUIGroup(event.getMetaGroup()), true);
}
/**
* Updates the corresponding node when the list of the <tt>OperationSet</tt>
* capabilities of a <tt>MetaContact</tt> has changed.
* @param evt a <tt>ContactCapabilitiesEvent</tt> with ID
* {@link MetaContactCapabilitiesEvent#SUPPORTED_OPERATION_SETS_CHANGED}
* which specifies the <tt>Contact</tt> whose list of <tt>OperationSet</tt>
* capabilities has changed
*/
public void metaContactCapabilitiesChanged(MetaContactCapabilitiesEvent evt)
{
UIContact uiContact = MetaContactListSource
.getUIContact(evt.getSourceContact());
if (uiContact != null && evt.getEventID()
== MetaContactCapabilitiesEvent.SUPPORTED_OPERATION_SETS_CHANGED)
{
ContactNode contactNode = uiContact.getContactNode();
if (contactNode != null)
treeModel.nodeChanged(contactNode);
}
}
/**
* Indicates that the status of a query has changed.
* @param event the <tt>ContactQueryStatusEvent</tt> that notified us

@ -11,7 +11,7 @@
import net.java.sip.communicator.service.protocol.*;
/**
* A MetaContact is an abstraction used for merging mutltiple Contacts (most
* A MetaContact is an abstraction used for merging multiple Contacts (most
* often) belonging to different <tt>ProtocolProvider</tt>s.
* <p>
* Instances of a MetaContact are read-only objects that cannot be modified

@ -0,0 +1,80 @@
/*
* 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.service.contactlist.event;
import java.util.*;
import net.java.sip.communicator.service.contactlist.*;
/**
* Represents an event/<tt>EventObject</tt> fired by
* <tt>OperationSetClientCapabilities</tt> in order to notify about changes in
* the list of the <tt>OperationSet</tt> capabilities of a <tt>Contact</tt>.
*
* @author Yana Stamcheva
*/
public class MetaContactCapabilitiesEvent
extends EventObject
{
/**ContactList.java
* The ID of the <tt>MetaContactCapabilitiesEvent</tt> which notifies about
* changes in the list of the <tt>OperationSet</tt> capabilities of a
* <tt>MetaContact</tt>.
*/
public static final int SUPPORTED_OPERATION_SETS_CHANGED = 1;
/**
* The ID of this event which indicates the specifics of the change in the
* list of <tt>OperationSet</tt> capabilities of the associated
* <tt>Contact</tt> and the details this event carries.
*/
private final int eventID;
/**
* Initializes a new <tt>ContactCapabilitiesEvent</tt> instance which is to
* notify about a specific change in the list of <tt>OperationSet</tt>
* capabilities of a specific <tt>Contact</tt>.
*
* @param sourceContact the <tt>MetaContact</tt> which is to be considered
* the source/cause of the new event
* @param eventID the ID of the new event which indicates the specifics of
* the change in the list of <tt>OperationSet</tt> capabilities of the
* specified <tt>sourceContact</tt> and the details to be carried by the new
* event
*/
public MetaContactCapabilitiesEvent(MetaContact sourceContact, int eventID)
{
super(sourceContact);
this.eventID = eventID;
}
/**
* Gets the ID of this event which indicates the specifics of the change in
* the list of <tt>OperationSet</tt> capabilities of the associated
* <tt>sourceContact</tt> and the details it carries.
*
* @return the ID of this event which indicates the specifics of the change
* in the list of <tt>OperationSet</tt> capabilities of the associated
* <tt>sourceContact</tt> and the details it carries
*/
public int getEventID()
{
return eventID;
}
/**
* Gets the <tt>MetaContact</tt> which is the source/cause of this event i.e.
* which has changed its list of <tt>OperationSet</tt> capabilities.
*
* @return the <tt>MetaContact</tt> which is the source/cause of this event
*/
public MetaContact getSourceContact()
{
return (MetaContact) getSource();
}
}

@ -115,7 +115,8 @@ public interface MetaContactListListener
/**
* Indicates that a MetaContact has been modified.
* @param evt the MetaContactModifiedEvent containing the corresponding contact
* @param evt the MetaContactModifiedEvent containing the corresponding
* contact
*/
public void metaContactModified(MetaContactModifiedEvent evt);
@ -125,4 +126,15 @@ public interface MetaContactListListener
* of this event
*/
public void metaContactAvatarUpdated(MetaContactAvatarUpdateEvent evt);
/**
* Notifies this listener that the list of the <tt>OperationSet</tt>
* capabilities of a <tt>MetaContact</tt> has changed.
*
* @param evt a <tt>ContactCapabilitiesEvent</tt> with ID
* {@link MetaContactCapabilitiesEvent#SUPPORTED_OPERATION_SETS_CHANGED}
* which specifies the <tt>Contact</tt> whose list of <tt>OperationSet</tt>
* capabilities has changed
*/
public void metaContactCapabilitiesChanged(MetaContactCapabilitiesEvent evt);
}

@ -1245,5 +1245,16 @@ public void metaContactAvatarUpdated(MetaContactAvatarUpdateEvent evt)
{
collectedMetaContactGroupEvents.add(evt);
}
/**
* Indicates that a <tt>MetaContact</tt> capabilities have changed.
* @param evt the <tt>MetaContactCapabilitiesEvent</tt> that notified
* us
*/
public void metaContactCapabilitiesChanged(
MetaContactCapabilitiesEvent evt)
{
collectedMetaContactEvents.add(evt);
}
}
}

Loading…
Cancel
Save