1
// PidginContactItemSource.cs
3
// GNOME Do is the legal property of its developers, whose names are too numerous
4
// to list here. Please refer to the COPYRIGHT file distributed with this
5
// source distribution.
7
// This program is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
23
using System.Collections.Generic;
29
public class PidginContactItemSource : IItemSource
32
static readonly string kBuddyListFile;
33
static readonly string kBuddyIconDirectory;
35
static PidginContactItemSource () {
38
home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
39
kBuddyListFile = "~/.purple/blist.xml".Replace("~", home);
40
kBuddyIconDirectory = "~/.purple/icons".Replace("~", home);
45
public PidginContactItemSource ()
47
buddies = new List<IItem> ();
51
public Type[] SupportedItemTypes {
59
public string Name { get { return "Pidgin Buddies"; } }
60
public string Description { get { return "Buddies on your Pidgin buddy list."; } }
61
public string Icon {get { return "pidgin"; } }
63
public ICollection<IItem> Items {
64
get { return buddies; }
67
public ICollection<IItem> ChildrenOfItem (IItem item)
72
public void UpdateItems ()
75
// Add buddies as they are encountered to this hash so we don't create duplicates.
76
Dictionary<ContactItem, bool> buddies_seen;
79
buddies_seen = new Dictionary<ContactItem, bool> ();
80
blist = new XmlDocument ();
82
blist.Load (kBuddyListFile);
84
foreach (XmlNode contact_node in blist.GetElementsByTagName ("contact"))
85
foreach (XmlNode buddy_node in contact_node.ChildNodes) {
88
buddy = ContactItemFromBuddyXmlNode (buddy_node);
89
if (buddy == null) continue;
90
ContactItemStore.SynchronizeContactWithStore (ref buddy);
91
buddies_seen[buddy] = true;
94
} catch (Exception e) {
95
Console.Error.WriteLine ("Could not read Pidgin buddy list file: " + e.Message);
97
foreach (ContactItem buddy in buddies_seen.Keys) {
102
ContactItem ContactItemFromBuddyXmlNode (XmlNode buddy_node)
105
string proto, name, alias, icon;
108
name = alias = icon = null;
109
// The messaging protocol (e.g. "prpl-jabber" for Jabber).
110
proto = buddy_node.Attributes.GetNamedItem ("proto").Value;
111
foreach (XmlNode attr in buddy_node.ChildNodes) {
115
name = attr.InnerText;
117
// The alias, or real name.
119
alias = attr.InnerText;
121
// Buddy icon image file.
123
if (attr.Attributes.GetNamedItem ("name").Value == "buddy_icon") {
124
icon = Path.Combine (kBuddyIconDirectory, attr.InnerText);
133
// If crucial details are missing, we can't make a buddy.
134
if (name == null || proto == null) return null;
136
// Create a new buddy, add the details we have.
137
buddy = new ContactItem ();
142
AddScreenNameToContact (buddy, proto, name);
146
void AddScreenNameToContact (ContactItem buddy, string proto, string name)
148
if (buddy == null || proto == null || name == null)
153
if (!buddy.AIMs.Contains (name))
154
buddy.AIMs.Add (name);
157
if (!buddy.Jabbers.Contains (name))
158
buddy.Jabbers.Add (name);