Exemplo n.º 1
0
        //We're only using this to get link-local (bonjour) buddies
        ContactItem CreateBuddy(int buddyID)
        {
            ContactItem buddy;
            string      alias, proto, icon, accountAlias;

            proto        = "prpl-bonjour";
            icon         = Pidgin.GetBuddyIconPath(buddyID);
            alias        = Pidgin.GetBuddyServerAlias(buddyID);
            accountAlias = Pidgin.GetBuddyLocalAlias(buddyID);
            buddy        = ContactItem.Create(alias);

            //if for some reason this buddy has multiple prpl-bonjour accounts associated with it
            //make sure we add them all in this fashion: prpl-bonjour, prpl-bonjour-1, etc.
            int similarProtos = buddy.Details.Where(k => k.StartsWith(proto)).Count();

            if (similarProtos > 0)
            {
                proto = string.Format("{0}-{1}", proto, similarProtos.ToString());
            }

            buddy[proto] = accountAlias;
            if (!string.IsNullOrEmpty(icon))
            {
                buddy[iconPrefix + proto] = icon;
            }
            if (string.IsNullOrEmpty(buddy["photo"]))
            {
                buddy["photo"] = icon;
            }

            return(buddy);
        }
Exemplo n.º 2
0
        public void ForceUpdateItems()
        {
            if (EmpathyPlugin.IsInstanceRunning())
            {
                contacts.Clear();
                try
                {
                    foreach (Contact contact in EmpathyPlugin.GetAllContacts())
                    {
                        ContactItem contactItem = ContactItem.Create(contact.Alias);
                        contactItem["email"]      = contact.ContactId;
                        contactItem["is-empathy"] = "true";
                        if (contact.AvatarToken != null && contact.AvatarToken != "")
                        {
                            string[] elts = new string[] { Environment.GetFolderPath(Environment.SpecialFolder.Personal), EmpathyPlugin.AVATAR_PATH, contact.Account.cm, contact.Account.proto, contact.AvatarToken };
                            contactItem["photo"] = elts.Aggregate((aggregation, val) => Path.Combine(aggregation, val));
                        }
                        contacts.Add(contactItem);
                    }
                }
                catch (Exception e)
                {
                    Log <EmpathyContactItemSource> .Error("Could not get Empathy contacts: {0}", e.Message);

                    Log <EmpathyContactItemSource> .Error(e.StackTrace);
                }
            }
        }
Exemplo n.º 3
0
        void CreateThunderbirdContactItem(string name, EmailList emails)
        {
            int emailCount = emails.Count;

            ThunderbirdEmail[] sortedEmails = new ThunderbirdEmail[emailCount];

            int i = 0;

            foreach (string key in emails.Keys)
            {
                sortedEmails [i] = new ThunderbirdEmail(key, emails [key]);
                i++;
            }
            Array.Sort(sortedEmails, (x, y) => (int)(y.popularity - x.popularity));

            ContactItem contact = ContactItem.Create(name);

            for (i = 0; i < emailCount; i++)
            {
                string detail = THUNDERBIRD_EMAIL + "." + i;
                contact [detail] = sortedEmails [i].email;
            }

            if (!contacts.ContainsKey(name.ToLower()))
            {
                contacts.Add(name.ToLower(), contact);
            }
        }
Exemplo n.º 4
0
        private ContactItem CreateContact(string handle)
        {
            string contactName;

            contactName = (string.IsNullOrEmpty(Skype.ContactDisplayName(handle))) ?
                          (string.IsNullOrEmpty(Skype.ContactFullName(handle))) ?
                          handle : Skype.ContactFullName(handle) :
                          Skype.ContactDisplayName(handle);

            ContactItem contact = ContactItem.Create(contactName);

            MaybeAddDetail(contact, "handle", handle);

            MaybeAddDetail(contact, "phone.home", Skype.ContactHomePhone(handle));
            MaybeAddDetail(contact, "phone.mobile", Skype.ContactMobilePhone(handle));
            MaybeAddDetail(contact, "phone.work", Skype.ContactOfficePhone(handle));

            return(contact);
        }
Exemplo n.º 5
0
        ContactItem CreateBuddy(XmlNode buddyNode)
        {
            ContactItem buddy;
            string      name, alias, proto;

            Dictionary <string, string> icons  = new Dictionary <string, string> ();
            Dictionary <string, string> protos = new Dictionary <string, string> ();

            alias = name = null;

            //we favor aliases in this order: metacontact alias, local alias, server alias
            //metacontact alias
            try {
                alias = buddyNode.Attributes.GetNamedItem("alias").Value;
            }
            catch {}

            foreach (XmlNode node in buddyNode.ChildNodes)
            {
                switch (node.Name)
                {
                case "buddy":
                    proto = node.Attributes.GetNamedItem("proto").Value;
                    //for metacontacts, add similar protocol keys like this:
                    // prpl-msn, prpl-msn-1, prpl-msn-2 etc.
                    int similarProtos = protos.Keys.Where(k => k.StartsWith(proto)).Count();
                    if (similarProtos > 0)
                    {
                        proto = string.Format("{0}-{1}", proto, similarProtos.ToString());
                    }
                    foreach (XmlNode attr in node.ChildNodes)
                    {
                        switch (attr.Name)
                        {
                        // The screen name.
                        case "name":
                            protos[proto] = attr.InnerText;
                            break;

                        // The alias, or real name, only if one isn't set yet.
                        case "alias":
                            if (string.IsNullOrEmpty(alias))
                            {
                                alias = attr.InnerText;
                            }
                            break;

                        // Buddy icon image file.
                        case "setting":
                            if (attr.Attributes.GetNamedItem("name").Value == "buddy_icon")
                            {
                                icons[iconPrefix + proto] = Path.Combine(BuddyIconDirectory, attr.InnerText);
                                if (!icons.Keys.Contains("default"))
                                {
                                    icons["default"] = icons[iconPrefix + proto];
                                }
                            }
                            break;
                        }
                    }
                    //if the alias is still null, let's try to get the server alias
                    if (string.IsNullOrEmpty(alias))
                    {
                        alias = (string)Pidgin.GetBuddyServerAlias(protos[proto]) ?? null;
                    }
                    break;

                //let's pick up the custom icon as the metacontact's icon
                case "setting":
                    if (node.Attributes.GetNamedItem("name").Value == "custom_buddy_icon")
                    {
                        icons["default"] = Path.Combine(BuddyIconDirectory, node.InnerText);
                    }
                    break;
                }
            }

            //in case we don't have an alias, take one of the proto values for the name
            name = alias ?? protos.Values.FirstOrDefault();

            // If crucial details are missing, we can't make a buddy.
            if (name == null || protos.Values.Count() <= 0)
            {
                return(null);
            }

            // Create a new buddy, add the details we have.
            buddy = ContactItem.Create(alias ?? name);

            //assign the default buddy icon as the ContactItem's photo
            if (icons.Keys.Contains("default"))
            {
                buddy["photo"] = icons["default"];
            }

            //add all of the protocol handles we found for this buddy
            //skip bonjour keys, they'll get picked up later
            foreach (string k in protos.Keys.Where(k => !k.Contains("bonjour")))
            {
                buddy[k] = protos[k];
            }

            //add the icons keys to create individual icons for childitems
            foreach (string k in icons.Keys.Where(k => k != "default" && !k.Contains("bonjour")))
            {
                buddy[k] = icons[k];
            }

            return(buddy);
        }