Example #1
0
        private void AddContact(XmlNode contact)
        {
            string protocol = null;
            string owner    = null;
            string buddy    = null;
            string alias    = null;

            // For each and every meta-contact, there can be multiple
            // buddy information entries if we have a contact added on
            // multiple protocols. Loop through them.

            foreach (XmlNode plugin_node in contact.SelectNodes("plugin-data"))
            {
                // Determine the protocol
                XmlAttribute plugin_id_attr = plugin_node.Attributes ["plugin-id"];
                protocol = plugin_id_attr.Value.Substring(0, plugin_id_attr.Value.Length - 8).ToLower();

                // Fetch all the buddy properties
                foreach (XmlNode plugin_data_node in plugin_node.SelectNodes("plugin-data-field"))
                {
                    switch (plugin_data_node.Attributes ["key"].Value)
                    {
                    case "contactId":
                        buddy = plugin_data_node.InnerText;
                        break;

                    case "accountId":
                        owner = plugin_data_node.InnerText;
                        break;

                    case "displayName":
                        alias = plugin_data_node.InnerText;
                        break;
                    }
                }

                string buddy_name = Format(buddy);

                // Replace any earlier buddies with the same screenname
                // FIXME: Not safe since we can have the same screenname on different accounts.
                if (BuddyList.ContainsKey(buddy_name))
                {
                    BuddyList.Remove(buddy_name);
                }

                ImBuddy im_buddy = new ImBuddy(protocol, owner, buddy_name, alias, null, null);

                BuddyList.Add(buddy_name, im_buddy);
            }
        }