public void Load(bool from_cache)
        {
            bool retreiving = false;

            if (cached && from_cache)
            {
                retreiving = LoadFromCache();
            }

            try {
                if (!retreiving)
                {
                    uint [] handles = { Contact.Handle };

                    State = AvatarState.Loading;

                    IDictionary <uint, string> tokens = avatars.GetKnownAvatarTokens(handles);
                    if (tokens.Count == 0)
                    {
                        State = AvatarState.NoAvatar;
                    }
                    else
                    {
                        avatars.AvatarRetrieved += OnAvatarRetrieved;
                        avatars.RequestAvatars(handles);
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
                State = AvatarState.NoAvatar;
            }
        }
示例#2
0
        public Contact(UInt32 contactUInt, Account account)
        {
            ContactUInt = contactUInt;
            Account     = account;

            IContacts       contacts             = Bus.Session.GetObject <IContacts> (Account.connectionBusIFace, Account.connectionPath);
            ISimplePresence presence             = Bus.Session.GetObject <ISimplePresence> (Account.connectionBusIFace, Account.connectionPath);
            IAvatars        avatars              = Bus.Session.GetObject <IAvatars> (Account.connectionBusIFace, Account.connectionPath);
            Properties      connectionProperties = Bus.Session.GetObject <Properties> (Account.connectionBusIFace, Account.connectionPath);

            // TODO: géré les protocols sans IAvatars
            IDictionary <uint, string> tokens = avatars.GetKnownAvatarTokens(new uint[] { ContactUInt });
            string strTmp = "";

            if (tokens.TryGetValue(contactUInt, out strTmp) && strTmp.Length > 0)
            {
                // ajout du préfix "_3" si le premier token commence par un nombre
                if (Regex.IsMatch(strTmp.Substring(0, 1), "[0-9]"))
                {
                    strTmp = "_3" + strTmp;
                }
            }
            AvatarToken = strTmp;
            SimplePresence sTmp;

            presence.GetPresences(new uint[] { ContactUInt }).TryGetValue(ContactUInt, out sTmp);
            SimplePresence = sTmp;

            IDictionary <string, object> tmp;

            string[] itf = (string[])connectionProperties.Get(EmpathyPlugin.CONNECTION_CONTACT_IFACE, "ContactAttributeInterfaces");
            // FIXME: cette interface fait planter DBus avec MSN, on remet un interface bidon
            int idx = Array.IndexOf(itf, EmpathyPlugin.CONNECTION_CAPABILITIES_IFACE);

            if (idx != -1)
            {
                itf[idx] = EmpathyPlugin.CONNECTION_IFACE;
            }

            IDictionary <uint, IDictionary <string, object> > allAttributes =
                contacts.GetContactAttributes(new uint[] { ContactUInt }, itf, false);

            allAttributes.TryGetValue(ContactUInt, out tmp);
            Attributes = tmp;
        }