[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/, /sip-communicator/src/net/java/sip/communicator/service/protocol...

damencho at dev.java.net damencho at dev.java.net
Thu Apr 12 13:28:51 CEST 2007


User: damencho
Date: 2007-04-12 11:28:51+0000
Modified:
   sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/ContactJabberImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java
   sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
   sip-communicator/src/net/java/sip/communicator/service/protocol/event/ContactPropertyChangeEvent.java

Log:
 Improve jabber image retreiving

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/
================================================================================

File [changed]: ContactJabberImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/ContactJabberImpl.java?r1=1.7&r2=1.8
Delta lines:  +12 -29
---------------------
--- ContactJabberImpl.java	2007-04-10 15:29:01+0000	1.7
+++ ContactJabberImpl.java	2007-04-12 11:28:48+0000	1.8
@@ -7,7 +7,6 @@
 package net.java.sip.communicator.impl.protocol.jabber;
 
 import org.jivesoftware.smack.*;
-import org.jivesoftware.smackx.packet.*;
 import net.java.sip.communicator.service.protocol.*;
 import net.java.sip.communicator.util.*;
 import net.java.sip.communicator.service.protocol.jabberconstants.*;
@@ -89,15 +88,26 @@
         return isLocal;
     }
 
+    /**
+     *  Returns the image of the contact or null if absent
+     */
     public byte[] getImage()
     {
         if(image == null)
-            image = getAvatar();
+            ssclCallback.addContactForImageUpdate(this);
 
         return image;
     }
 
     /**
+     *  Set the image of the contact
+     */
+    void setImage(byte[] imgBytes)
+    {
+        this.image = imgBytes;
+    }
+
+    /**
      * Returns a hashCode for this contact. The returned hashcode is actually
      * that of the Contact's Address
      * @return the hashcode of this Contact
@@ -292,31 +302,4 @@
     {
         return rosterEntry;
     }
-
-    private byte[] getAvatar()
-    {
-        try
-        {
-            XMPPConnection connection = 
-                ssclCallback.getParentProvider().getConnection();
-            
-            if(connection == null || !connection.isAuthenticated())
-                return null;
-            
-            VCard card = new VCard();
-            card.load(
-                connection,
-                getAddress());
-
-            return card.getAvatar();
-        }
-        catch (Exception exc)
-        {
-            logger.error("Cannot load image for contact "
-                + this + " : " + exc.getMessage()
-                , exc);
-        }
-
-        return null;
-    }
 }
\ No newline at end of file

File [changed]: ServerStoredContactListJabberImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java?r1=1.10&r2=1.11
Delta lines:  +115 -1
---------------------
--- ServerStoredContactListJabberImpl.java	2007-04-04 12:53:06+0000	1.10
+++ ServerStoredContactListJabberImpl.java	2007-04-12 11:28:48+0000	1.11
@@ -10,6 +10,7 @@
 
 import org.jivesoftware.smack.*;
 import org.jivesoftware.smack.packet.*;
+import org.jivesoftware.smackx.packet.*;
 import net.java.sip.communicator.service.protocol.*;
 import net.java.sip.communicator.service.protocol.event.*;
 import net.java.sip.communicator.util.*;
@@ -60,6 +61,11 @@
     private Vector serverStoredGroupListeners = new Vector();
 
     /**
+     *  Thread retreiving images for contacts
+     */
+    private ImageRetriever imageRetriever = null;
+
+    /**
      * Creates a ServerStoredContactList wrapper for the specified BuddyList.
      *
      * @param parentOperationSet the operation set that created us and that
@@ -747,6 +753,23 @@
             SubscriptionEvent.SUBSCRIPTION_RESOLVED, contact, parentGroup);
     }
 
+    /**
+     * when there is no image for contact we must retreive it 
+     * add contacts for image update
+     *
+     * @param c ContactJabberImpl
+     */
+    protected void addContactForImageUpdate(ContactJabberImpl c)
+    {
+        if(imageRetriever == null)
+        {
+            imageRetriever = new ImageRetriever();
+            imageRetriever.start();
+        }
+        
+        imageRetriever.addContact(c);
+    }
+
     private class ChangeListener
         implements RosterListener
     {
@@ -938,4 +961,95 @@
         public void presenceChanged(Presence presence)
         {}
     }
+    
+    private class ImageRetriever
+        extends Thread
+    {
+        /**
+         * list with the accounts with missing image
+         */
+        private Vector contactsForUpdate = new Vector();
+
+        public void run()
+        {
+            try
+            {
+                Collection copyContactsForUpdate = null;
+                while (true)
+                {
+                    synchronized(contactsForUpdate){
+
+                        if(contactsForUpdate.isEmpty())
+                            contactsForUpdate.wait();
+
+                        copyContactsForUpdate = new Vector(contactsForUpdate);
+                        contactsForUpdate.clear();
+                    }
+
+                    Iterator iter = copyContactsForUpdate.iterator();
+                    while (iter.hasNext())
+                    {
+                        ContactJabberImpl contact = (ContactJabberImpl) iter.next();
+                        
+                        byte[] imgBytes = getAvatar(contact);
+                        
+                        if(imgBytes != null)
+                        {
+                            contact.setImage(imgBytes);
+                            
+                            parentOperationSet.fireContactPropertyChangeEvent(
+                                ContactPropertyChangeEvent.PROPERTY_IMAGE, 
+                                contact, null, imgBytes);
+                        }
+                    }
+                }
+            }
+            catch (InterruptedException ex)
+            {
+                logger.error("NickRetriever error waiting will stop now!", ex);
+            }
+        }
+
+        /**
+         * Add contact for retreiving
+         * if the provider is register notify the retreiver to get the nicks
+         * if we are not registered add a listener to wiat for registering
+         *
+         * @param contact ContactJabberImpl
+         */
+        synchronized void addContact(ContactJabberImpl contact)
+        {
+            synchronized(contactsForUpdate){
+                if (!contactsForUpdate.contains(contact))
+                {
+                    contactsForUpdate.add(contact);
+                    contactsForUpdate.notifyAll();
+                }
+            }
+        }
+
+        private byte[] getAvatar(ContactJabberImpl contact)
+        {
+            try
+            {
+                XMPPConnection connection = jabberProvider.getConnection();
+
+                if(connection == null || !connection.isAuthenticated())
+                    return null;
+
+                VCard card = new VCard();
+                card.load(connection, contact.getAddress());
+
+                return card.getAvatar();
+            }
+            catch (Exception exc)
+            {
+                logger.error("Cannot load image for contact "
+                    + this + " : " + exc.getMessage()
+                    , exc);
+            }
+
+            return null;
+        }
+    }
 }

File [changed]: ProtocolProviderServiceJabberImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java?r1=1.29&r2=1.30
Delta lines:  +1 -5
-------------------
--- ProtocolProviderServiceJabberImpl.java	2007-04-11 12:47:41+0000	1.29
+++ ProtocolProviderServiceJabberImpl.java	2007-04-12 11:28:48+0000	1.30
@@ -298,11 +298,7 @@
                 {
                     logger.error("Failed to establish a Jabber connection for "
                         + getAccountID().getAccountUniqueID(), exc);
-                    fireRegistrationStateChanged(
-                        getRegistrationState()
-                        , RegistrationState.CONNECTION_FAILED
-                        , OperationFailedException.NETWORK_FAILURE
-                        , null);
+                    
                     throw new OperationFailedException(
                         "Failed to establish a Jabber connection for "
                         + getAccountID().getAccountUniqueID()

File [changed]: OperationSetPersistentPresenceJabberImpl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java?r1=1.13&r2=1.14
Delta lines:  +40 -0
--------------------
--- OperationSetPersistentPresenceJabberImpl.java	2007-04-12 08:51:44+0000	1.13
+++ OperationSetPersistentPresenceJabberImpl.java	2007-04-12 11:28:48+0000	1.14
@@ -1000,6 +1000,46 @@
     }
 
     /**
+     * Notify all subscription listeners of the corresponding contact property
+     * change event.
+     *
+     * @param eventID the String ID of the event to dispatch
+     * @param sourceContact the ContactJabberImpl instance that this event is
+     * pertaining to.
+     * @param oldValue the value that the changed property had before the change
+     * occurred.
+     * @param newValue the value that the changed property currently has (after
+     * the change has occurred).
+     */
+    void fireContactPropertyChangeEvent( String               eventID,
+                                         ContactJabberImpl    sourceContact,
+                                         Object               oldValue,
+                                         Object               newValue)
+    {
+        ContactPropertyChangeEvent evt =
+            new ContactPropertyChangeEvent(sourceContact, eventID
+                                  , oldValue, newValue);
+
+        logger.debug("Dispatching a Contact Property Change Event to"
+                     +subscriptionListeners.size() + " listeners. Evt="+evt);
+
+        Iterator listeners = null;
+
+        synchronized (subscriptionListeners)
+        {
+            listeners = new ArrayList(subscriptionListeners).iterator();
+        }
+
+        while (listeners.hasNext())
+        {
+            SubscriptionListener listener
+                = (SubscriptionListener) listeners.next();
+
+            listener.contactModified(evt);
+        }
+    }
+
+    /**
      *
      */
     private class ContactChangesListener

Directory: /sip-communicator/src/net/java/sip/communicator/service/protocol/event/
==================================================================================

File [changed]: ContactPropertyChangeEvent.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/service/protocol/event/ContactPropertyChangeEvent.java?r1=1.2&r2=1.3
Delta lines:  +6 -0
-------------------
--- ContactPropertyChangeEvent.java	2006-07-10 13:56:14+0000	1.2
+++ ContactPropertyChangeEvent.java	2007-04-12 11:28:48+0000	1.3
@@ -19,6 +19,12 @@
     public static final String PROPERTY_DISPLAY_NAME = "DisplayName";
 
     /**
+     * Indicates that a change has occurred in the image of the source
+     * contact.
+     */
+    public static final String PROPERTY_IMAGE = "Image";
+
+    /**
      * Creates a ContactPropertyChangeEvent indicating that a change has
      * occurred for property <tt>propertyName</tt> in the <tt>source</tt>
      * contact and that its value has changed from <tt>oldValue</tt> to




---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: cvs-help at sip-communicator.dev.java.net





More information about the commits mailing list