示例#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);
            }
        }
示例#2
0
        private void AddBuddy(XmlNode node, string group_alias)
        {
            string protocol     = null;
            string owner        = null;
            string buddy        = null;
            string alias        = null;
            string iconlocation = null;
            string iconchecksum = null;

            foreach (XmlAttribute attr in node.Attributes)
            {
                switch (attr.Name)
                {
                case "account":
                    owner = attr.Value;
                    break;

                case "proto":
                    protocol = attr.Value;
                    break;
                }
            }

            foreach (XmlNode attr in node.ChildNodes)
            {
                switch (attr.LocalName)
                {
                case "name":
                    buddy = attr.InnerText;
                    break;

                case "alias":
                    alias = attr.InnerText;
                    break;

                case "setting":
                    foreach (XmlAttribute subattr in attr.Attributes)
                    {
                        if (subattr.Name == "name" && subattr.Value == "buddy_icon")
                        {
                            iconlocation = Path.Combine(icons_dir, attr.InnerText);
                        }
                        else if (subattr.Name == "name" && subattr.Value == "icon_checksum")
                        {
                            iconchecksum = attr.InnerText;
                        }
                    }
                    break;
                }
            }

            if (!String.IsNullOrEmpty(group_alias))
            {
                alias = group_alias;
            }

            if (BuddyList.ContainsKey(Format(buddy)))
            {
                ImBuddy old = Search(buddy);

                if (String.IsNullOrEmpty(old.Alias) && !String.IsNullOrEmpty(alias))
                {
                    old.Alias = alias;
                }

                if (String.IsNullOrEmpty(old.BuddyIconLocation) && !String.IsNullOrEmpty(iconlocation))
                {
                    old.BuddyIconLocation = iconlocation;
                    old.BuddyIconChecksum = iconchecksum;
                }
            }
            else
            {
                ImBuddy im_buddy = new ImBuddy(protocol, owner, Format(buddy), alias, iconlocation, iconchecksum);
                BuddyList.Add(Format(buddy), im_buddy);
            }
        }