1
// EmpathyContactItemSource.cs
4
// Xavier Calland <xavier.calland@gmail.com>
8
// This program is free software: you can redistribute it and/or modify
9
// it under the terms of the GNU Lesser General Public License as published by
10
// the Free Software Foundation, either version 3 of the License, or
11
// (at your option) any later version.
13
// This program is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU Lesser General Public License for more details.
18
// You should have received a copy of the GNU Lesser General Public License
19
// along with this program. If not, see <http://www.gnu.org/licenses/>.
24
using System.Collections.Generic;
28
using Do.Platform.ServiceStack;
30
namespace EmpathyPlugin
33
public class EmpathyContactItemSource : ItemSource
35
const string iconPrefix = "icon-";
39
public EmpathyContactItemSource ()
41
contacts = new List<Item> ();
44
public override IEnumerable<Type> SupportedItemTypes
48
yield return typeof (ContactItem);
49
yield return typeof (IApplicationItem);
50
yield return typeof (EmpathyBrowseBuddyItem);
54
public override string Name
56
get { return AddinManager.CurrentLocalizer.GetString ("Empathy Contacts"); }
59
public override string Description
61
get { return AddinManager.CurrentLocalizer.GetString ("Contacts on your Empathy contact alist."); }
64
public override string Icon
66
get { return "empathy"; }
69
public override IEnumerable<Item> Items
71
get { return contacts; }
74
public override IEnumerable<Item> ChildrenOfItem (Item item)
76
if (EmpathyPlugin.IsTelepathy (item))
78
yield return new EmpathyBrowseBuddyItem ();
80
else if (item is EmpathyBrowseBuddyItem)
82
foreach (ContactItem contact in contacts)
89
public void ForceUpdateItems ()
91
if (EmpathyPlugin.IsInstanceRunning ())
96
foreach (Contact contact in EmpathyPlugin.GetAllContacts ())
98
ContactItem contactItem = ContactItem.Create (contact.Alias);
99
contactItem["email"] = contact.ContactId;
100
contactItem["is-empathy"] = "true";
101
if(contact.AvatarToken != null && contact.AvatarToken != "")
103
string[] elts = new string[]{Environment.GetFolderPath (Environment.SpecialFolder.Personal), EmpathyPlugin.AVATAR_PATH, contact.Account.cm, contact.Account.proto, contact.AvatarToken};
104
contactItem["photo"] = elts.Aggregate((aggregation, val) => Path.Combine (aggregation, val));
106
contacts.Add (contactItem);
111
Log<EmpathyContactItemSource>.Error ("Could not get Empathy contacts: {0}", e.Message);
112
Log<EmpathyContactItemSource>.Error (e.StackTrace);
117
public override void UpdateItems ()
b'\\ No newline at end of file'