~crisoagf/do-plugins/do-music

« back to all changes in this revision

Viewing changes to Empathy/src/EmpathyContactItemSource.cs

  • Committer: Christopher James Halse Rogers
  • Date: 2011-02-06 08:01:08 UTC
  • mfrom: (687.1.12 empathy)
  • Revision ID: raof@ubuntu.com-20110206080108-cuzq3femqkmsiagy
Merge the long-sought Empathy plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  EmpathyContactItemSource.cs
 
2
//
 
3
//  Author:
 
4
//       Xavier Calland <xavier.calland@gmail.com>
 
5
//
 
6
//  Copyright © 2010
 
7
//
 
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.
 
12
//
 
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.
 
17
//
 
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/>.
 
20
 
 
21
using System;
 
22
using System.IO;
 
23
using System.Linq;
 
24
using System.Collections.Generic;
 
25
using Mono.Addins;
 
26
using Do.Universe;
 
27
using Do.Platform;
 
28
using Do.Platform.ServiceStack;
 
29
 
 
30
namespace EmpathyPlugin
 
31
{
 
32
 
 
33
        public class EmpathyContactItemSource : ItemSource
 
34
        {
 
35
                const string iconPrefix = "icon-";
 
36
 
 
37
                List<Item> contacts;
 
38
 
 
39
                public EmpathyContactItemSource ()
 
40
                {
 
41
                        contacts = new List<Item> ();
 
42
                }
 
43
 
 
44
                public override IEnumerable<Type> SupportedItemTypes
 
45
                {
 
46
                        get
 
47
                        {
 
48
                                yield return typeof (ContactItem); 
 
49
                                yield return typeof (IApplicationItem);
 
50
                                yield return typeof (EmpathyBrowseBuddyItem);
 
51
                        }
 
52
                }
 
53
 
 
54
                public override string Name
 
55
                {
 
56
                        get { return AddinManager.CurrentLocalizer.GetString ("Empathy Contacts"); }
 
57
                }
 
58
 
 
59
                public override string Description
 
60
                {
 
61
                        get { return AddinManager.CurrentLocalizer.GetString ("Contacts on your Empathy contact alist."); }
 
62
                }
 
63
 
 
64
                public override string Icon
 
65
                {
 
66
                        get { return "empathy"; }
 
67
                }
 
68
 
 
69
                public override IEnumerable<Item> Items 
 
70
                {
 
71
                        get { return contacts; }
 
72
                }
 
73
 
 
74
                public override IEnumerable<Item> ChildrenOfItem (Item item)
 
75
                {
 
76
                        if (EmpathyPlugin.IsTelepathy (item))
 
77
                        {
 
78
                                yield return new EmpathyBrowseBuddyItem ();
 
79
                        }
 
80
                        else if (item is EmpathyBrowseBuddyItem)
 
81
                        {
 
82
                                foreach (ContactItem contact in contacts)
 
83
                                {
 
84
                                        yield return contact;
 
85
                                }
 
86
                        }
 
87
                }
 
88
 
 
89
                public void ForceUpdateItems ()
 
90
                {
 
91
                        if (EmpathyPlugin.IsInstanceRunning ())
 
92
                        {
 
93
                                contacts.Clear ();
 
94
                                try
 
95
                                {
 
96
                                        foreach (Contact contact in EmpathyPlugin.GetAllContacts ())
 
97
                                        {
 
98
                                                ContactItem contactItem = ContactItem.Create (contact.Alias);
 
99
                                                contactItem["email"] = contact.ContactId;
 
100
                                                contactItem["is-empathy"] = "true";
 
101
                                                if(contact.AvatarToken != null && contact.AvatarToken != "")
 
102
                                                {
 
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));
 
105
                                                }
 
106
                                                contacts.Add (contactItem);
 
107
                                        }
 
108
                                }
 
109
                                catch (Exception e)
 
110
                                {
 
111
                                        Log<EmpathyContactItemSource>.Error ("Could not get Empathy contacts: {0}", e.Message);
 
112
                                        Log<EmpathyContactItemSource>.Error (e.StackTrace);
 
113
                                }
 
114
                        }
 
115
                }
 
116
 
 
117
                public override void UpdateItems ()
 
118
                {
 
119
                        ForceUpdateItems();
 
120
                }
 
121
        }
 
122
}
 
 
b'\\ No newline at end of file'