//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); }
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); }