diff --git a/build.xml b/build.xml index 51fd3f45b..e1b73671e 100644 --- a/build.xml +++ b/build.xml @@ -948,7 +948,8 @@ bundle-provisioning,bundle-addrbook,bundle-plugin-ldap, bundle-plugin-contactsourceconfig,bundle-plugin-certconfig, bundle-globalshortcut,bundle-plugin-msofficecomm,bundle-libjitsi, - bundle-customcontactactions, bundle-phonenumbercontactsource"/> + bundle-customcontactactions, bundle-phonenumbercontactsource, + bundle-demuxcontactsource"/> @@ -2766,4 +2767,14 @@ javax.swing.event, javax.swing.border"/> prefix="net/java/sip/communicator/plugin/phonenumbercontactsource"/> + + + + + + + + diff --git a/lib/felix.client.run.properties b/lib/felix.client.run.properties index b97e09e03..4cf89c54a 100644 --- a/lib/felix.client.run.properties +++ b/lib/felix.client.run.properties @@ -174,7 +174,8 @@ felix.auto.start.67= \ reference:file:sc-bundles/plugin-ldap.jar \ reference:file:sc-bundles/plugin-contactsourceconfig.jar \ reference:file:sc-bundles/plugin-certconfig.jar \ - reference:file:sc-bundles/phonenumbercontactsource.jar + reference:file:sc-bundles/phonenumbercontactsource.jar \ + reference:file:sc-bundles/demuxcontactsource.jar # Level 68 is for profiler4j. Either don't use it or change the build.xml file # accordingly. diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index 089d1721f..c569f601d 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -95,6 +95,8 @@ public class GuiActivator implements BundleActivator private static SecurityAuthority securityAuthority; + private static DemuxContactSourceService demuxContactSourceService; + private static final Map providerFactoriesMap = new Hashtable(); @@ -685,6 +687,25 @@ public static MediaService getMediaService() return mediaService; } + /** + * Returns the DemuxContactSourceService obtained from the bundle + * context. + * + * @return the DemuxContactSourceService obtained from the bundle + * context + */ + public static DemuxContactSourceService getDemuxContactSourceService() + { + if (demuxContactSourceService == null) + { + demuxContactSourceService + = ServiceUtils.getService( + bundleContext, + DemuxContactSourceService.class); + } + return demuxContactSourceService; + } + /** * Returns a list of all registered contact sources. * @return a list of all registered contact sources diff --git a/src/net/java/sip/communicator/impl/gui/main/call/TransferCallDialog.java b/src/net/java/sip/communicator/impl/gui/main/call/TransferCallDialog.java index af176d630..1947ea518 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/TransferCallDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/TransferCallDialog.java @@ -77,14 +77,18 @@ public void actionPerformed(ActionEvent e) } /** - * Initializes the left contact list with the contacts that could be added - * to the current chat session. - * - * @param protocolProvider the protocol provider from which to initialize - * the contact list data + * Initializes contact list sources. */ - private void initContactListData(ProtocolProviderService protocolProvider) + private void initContactSources() { + DemuxContactSourceService demuxCSService + = GuiActivator.getDemuxContactSourceService(); + + // If the DemuxContactSourceService isn't registered we use the default + // contact source set. + if (demuxCSService == null) + return; + Iterator sourcesIter = new ArrayList( contactList.getContactSources()).iterator(); @@ -97,8 +101,20 @@ private void initContactListData(ProtocolProviderService protocolProvider) = sourcesIter.next().getContactSourceService(); contactList.addContactSource( - new DemuxContactSource(contactSource)); + demuxCSService.createDemuxContactSource(contactSource)); } + } + + /** + * Initializes the left contact list with the contacts that could be added + * to the current chat session. + * + * @param protocolProvider the protocol provider from which to initialize + * the contact list data + */ + private void initContactListData(ProtocolProviderService protocolProvider) + { + initContactSources(); contactList.addContactSource( new ProtocolContactSourceServiceImpl( diff --git a/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java b/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java index 465c72ad9..edf6dde55 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java @@ -98,7 +98,7 @@ public ConferenceInviteDialog(CallConference conference) { public void run() { - initContactListSources(); + initContactSources(); // Initialize the list of contacts to select from. initContactListData( @@ -252,10 +252,18 @@ else if (accountSelectorBox.getItemCount() > 0) } /** - * Initializes contact sources for the source contact list. + * Initializes contact list sources. */ - private void initContactListSources() + private void initContactSources() { + DemuxContactSourceService demuxCSService + = GuiActivator.getDemuxContactSourceService(); + + // If the DemuxContactSourceService isn't registered we use the default + // contact source set. + if (demuxCSService == null) + return; + Iterator sourcesIter = new ArrayList( srcContactList.getContactSources()).iterator(); @@ -268,7 +276,7 @@ private void initContactListSources() = sourcesIter.next().getContactSourceService(); srcContactList.addContactSource( - new DemuxContactSource(contactSource)); + demuxCSService.createDemuxContactSource(contactSource)); } } @@ -282,6 +290,23 @@ private void initContactListData(ProtocolProviderService protocolProvider) { this.setCurrentProvider(protocolProvider); + Iterator sourcesIter + = new ArrayList( + srcContactList.getContactSources()).iterator(); + + while (sourcesIter.hasNext()) + { + ContactSourceService contactSource + = sourcesIter.next().getContactSourceService(); + + if (contactSource instanceof ProtocolAwareContactSourceService) + { + ((ProtocolAwareContactSourceService) contactSource) + .setPreferredProtocolProvider( + OperationSetBasicTelephony.class, protocolProvider); + } + } + srcContactList.removeContactSource(currentProviderContactSource); srcContactList.removeContactSource(currentStringContactSource); diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/DemuxContactSource.java b/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSource.java similarity index 74% rename from src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/DemuxContactSource.java rename to src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSource.java index 8c1d3e997..60731c062 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/DemuxContactSource.java +++ b/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSource.java @@ -4,12 +4,13 @@ * Distributable under LGPL license. * See terms of license at gnu.org. */ -package net.java.sip.communicator.impl.gui.main.contactlist.contactsource; +package net.java.sip.communicator.plugin.demuxcontactsource; import java.util.*; import java.util.regex.*; import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.protocol.*; /** * The DemuxContactSource is a contact source that takes as parameter @@ -20,13 +21,19 @@ * @author Yana Stamcheva */ public class DemuxContactSource - implements ContactSourceService + implements ProtocolAwareContactSourceService { /** * The underlying contact source service. */ private final ContactSourceService contactSource; + /** + * The preferred protocol provider for this contact source. + */ + private Map, ProtocolProviderService> + preferredProtocolProviders; + /** * Create an instance of DemuxContactSource by specifying the * underlying ContactSourceService to be demuxed. @@ -39,6 +46,23 @@ public DemuxContactSource(ContactSourceService contactSource) this.contactSource = contactSource; } + /** + * Sets the preferred protocol provider for this contact source. + * + * @param protocolProvider the ProtocolProviderService to set + */ + public void setPreferredProtocolProvider( + Class opSetClass, + ProtocolProviderService protocolProvider) + { + if (preferredProtocolProviders == null) + preferredProtocolProviders + = new HashMap< Class, + ProtocolProviderService>(); + + preferredProtocolProviders.put(opSetClass, protocolProvider); + } + /** * Returns the type of the underlying contact source. * @@ -182,9 +206,14 @@ public List getQueryResults() while (detailsIter.hasNext()) { ContactDetail detail = detailsIter.next(); - newSourceContacts.add( - createSourceContact(sourceContact, - detail)); + + if (preferredProtocolProviders == null + || isPreferredContactDetail(detail)) + { + newSourceContacts.add( + createSourceContact(sourceContact, + detail)); + } } } @@ -224,8 +253,12 @@ public void contactReceived(ContactReceivedEvent event) { ContactDetail detail = detailsIter.next(); - fireContactReceived( - createSourceContact(sourceContact, detail)); + if (preferredProtocolProviders == null + || isPreferredContactDetail(detail)) + { + fireContactReceived( + createSourceContact(sourceContact, detail)); + } } } @@ -269,4 +302,38 @@ public void contactRemoved(ContactRemovedEvent event) {} public void contactChanged(ContactChangedEvent event) {} } + + /** + * Indicates if the given contact detail has a pair of OperationSet and + * ProtocolProviderService that matches the preferred pairs indicated for + * this contact source. + * + * @param c the ContactDetail to check + * @return true if the given ContactDetail contains one + * of the preferred pairs or has no preferred pairs, + * false - otherwise. + */ + private boolean isPreferredContactDetail(ContactDetail c) + { + Iterator> preferredProviderOpSets + = preferredProtocolProviders.keySet().iterator(); + + while (preferredProviderOpSets.hasNext()) + { + Class opSetClass + = preferredProviderOpSets.next(); + + ProtocolProviderService preferredProvider + = c.getPreferredProtocolProvider(opSetClass); + + if (preferredProvider == null + || preferredProvider.equals( + preferredProtocolProviders.get(opSetClass))) + { + return true; + } + } + + return false; + } } \ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSourceActivator.java b/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSourceActivator.java new file mode 100644 index 000000000..cb0035cee --- /dev/null +++ b/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSourceActivator.java @@ -0,0 +1,58 @@ +/* + * 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.demuxcontactsource; + +import net.java.sip.communicator.service.contactsource.*; + +import org.osgi.framework.*; + +/** + * Implements BundleActivator for the demux contact source plug-in. + * + * @author Yana Stamcheva + */ +public class DemuxContactSourceActivator + implements BundleActivator +{ + private ServiceRegistration demuxServiceRegistration; + + /** + * Starts the demux contact source plug-in. + * + * @param bundleContext the BundleContext in which the demux + * contact source plug-in is to be started + * @throws Exception if anything goes wrong while starting the demux + * contact source plug-in + * @see BundleActivator#start(BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception + { + // Registers the service implementation provided by this plugin. + demuxServiceRegistration = bundleContext.registerService( + DemuxContactSourceService.class.getName(), + new DemuxContactSourceServiceImpl(), + null); + } + + /** + * Stops the addrbook plug-in. + * + * @param bundleContext the BundleContext in which the addrbook + * plug-in is to be stopped + * @throws Exception if anything goes wrong while stopping the addrbook + * plug-in + * @see BundleActivator#stop(BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception + { + if (demuxServiceRegistration != null) + { + demuxServiceRegistration.unregister(); + demuxServiceRegistration = null; + } + } +} diff --git a/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSourceServiceImpl.java b/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSourceServiceImpl.java new file mode 100644 index 000000000..3bcc4dbb2 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/demuxcontactsource/DemuxContactSourceServiceImpl.java @@ -0,0 +1,36 @@ +/* + * 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.demuxcontactsource; + +import net.java.sip.communicator.service.contactsource.*; + +/** + * Provides an implementation of the DemuxContactSourceService abstract + * class. This implementation provides a de-multiplexed protocol aware copy of + * the given ContactSourceService. + * + * @author Yana Stamcheva + */ +public class DemuxContactSourceServiceImpl + extends DemuxContactSourceService +{ + /** + * Creates a demultiplexed copy of the given ContactSourceService, + * where each contact detail like telephone number or protocol contact + * address is represented as a single entry in the query result set. + * + * @param contactSourceService the original ContactSourceService to + * be demultiplexed + * @return a demultiplexed copy of the given ContactSourceService + */ + @Override + public ContactSourceService createDemuxContactSource( + ContactSourceService contactSourceService) + { + return new DemuxContactSource(contactSourceService); + } +} diff --git a/src/net/java/sip/communicator/plugin/demuxcontactsource/demuxcontactsource.manifest.mf b/src/net/java/sip/communicator/plugin/demuxcontactsource/demuxcontactsource.manifest.mf new file mode 100644 index 000000000..f93560f9b --- /dev/null +++ b/src/net/java/sip/communicator/plugin/demuxcontactsource/demuxcontactsource.manifest.mf @@ -0,0 +1,9 @@ +Bundle-Activator: net.java.sip.communicator.plugin.demuxcontactsource.DemuxContactSourceActivator +Bundle-Description: Demultiplexing contact source +Bundle-Name: Demux Contact Source +Bundle-Vendor: jitsi.org +Bundle-Version: 0.0.1 +Import-Package: net.java.sip.communicator.service.contactsource, + net.java.sip.communicator.service.protocol, + org.osgi.framework +System-Bundle: yes diff --git a/src/net/java/sip/communicator/service/contactsource/DemuxContactSourceService.java b/src/net/java/sip/communicator/service/contactsource/DemuxContactSourceService.java new file mode 100644 index 000000000..d77b6a803 --- /dev/null +++ b/src/net/java/sip/communicator/service/contactsource/DemuxContactSourceService.java @@ -0,0 +1,30 @@ +/* + * 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.service.contactsource; + +/** + * The DemuxContactSourceService provides a de-multiplexed copy of + * the given ContactSourceService, where each contact detail like + * telephone number or protocol contact address is represented as a single entry + * in the query result set. + * + * @author Yana Stamcheva + */ +public abstract class DemuxContactSourceService +{ + /** + * Creates a demultiplexed copy of the given ContactSourceService, + * where each contact detail like telephone number or protocol contact + * address is represented as a single entry in the query result set. + * + * @param contactSourceService the original ContactSourceService to + * be demultiplexed + * @return a demultiplexed copy of the given ContactSourceService + */ + public abstract ContactSourceService createDemuxContactSource( + ContactSourceService contactSourceService); +} diff --git a/src/net/java/sip/communicator/service/contactsource/ProtocolAwareContactSourceService.java b/src/net/java/sip/communicator/service/contactsource/ProtocolAwareContactSourceService.java new file mode 100644 index 000000000..cb401701f --- /dev/null +++ b/src/net/java/sip/communicator/service/contactsource/ProtocolAwareContactSourceService.java @@ -0,0 +1,38 @@ +/* + * 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.service.contactsource; + +import net.java.sip.communicator.service.protocol.*; + +/** + * The ProtocolAwareContactSourceService extends the basic + * ContactSourceService interface to provide a protocol aware contact + * source. In other words a preferred ProtocolProviderService can be + * set for a given OperationSet class that would affect the query + * result by excluding source contacts that has a preferred provider different + * from the one specified as a preferred provider. + * + * @author Yana Stamcheva + */ +public interface ProtocolAwareContactSourceService + extends ContactSourceService +{ + /** + * Sets the preferred protocol provider for this contact source. The + * preferred ProtocolProviderService set for a given + * OperationSet class would affect the query result by excluding + * source contacts that has a preferred provider different from the one + * specified here. + * + * @param opSetClass the OperationSet class, for which the + * preferred provider is set + * @param protocolProvider the ProtocolProviderService to set + */ + public void setPreferredProtocolProvider( + Class opSetClass, + ProtocolProviderService protocolProvider); +}