~ubuntu-branches/debian/squeeze/gnome-do-plugins/squeeze

« back to all changes in this revision

Viewing changes to Emesene/src/EmeseneContactItemSource.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2009-05-07 21:14:41 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090507211441-i6kxltm429t90x26
Tags: 0.8.1.3+dfsg-2
* debian/patches/00_use_system_gdata.dpatch: Patch build system to use
  system copy of gdata libs, allowing Google plugins to be enabled.
* debian/patches/00_dfsg_autofoo.dpatch: Drop, now obsolete.
* debian/control: Add libgdata1.4-cil build-dep for above.
* debian/patches/10_fix_rhythmbox_file.dpatch: Add. Look in the correct place
  for the rhythmbox database (Closes: #526337).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.IO;
 
3
using System.Xml;
 
4
using System.Collections.Generic;
 
5
using Do.Universe;
 
6
using Do.Platform;
 
7
 
 
8
namespace Do.Universe
 
9
{
 
10
        public class EmeseneContactItemSource : ItemSource
 
11
        {
 
12
                private List<Item> contacts;
 
13
                private Dictionary<string, int> contactsRelation;
 
14
                private int lastContact;
 
15
                
 
16
                public EmeseneContactItemSource ()
 
17
                {               
 
18
                        this.contacts = new List<Item> ();
 
19
                        this.contactsRelation = new Dictionary<string, int>();
 
20
                        this.lastContact = -1;
 
21
                }
 
22
                
 
23
                public override string Name { get { return "Emesene Buddies"; } }
 
24
                public override string Description { get { return "Buddies on your emesene buddy list."; }}
 
25
                public override string Icon {get { return "emesene"; } }
 
26
                
 
27
                public override IEnumerable<Type> SupportedItemTypes 
 
28
                {
 
29
                        get { yield return typeof (ContactItem); }
 
30
                }
 
31
                
 
32
                public override IEnumerable<Item> Items 
 
33
                {
 
34
                        get { return this.contacts; }
 
35
                }
 
36
                        
 
37
                public void getDisplayFromDB(ContactItem contact)
 
38
                {
 
39
                        string photo;
 
40
                        Log<EmeseneContactItemSource>.Debug ("Tryng to get display from DB for: {0}...", contact["email"]);
 
41
                        photo = Emesene.get_last_display_picture(contact["email"], false);
 
42
                        if (photo != "noImage") 
 
43
                        {
 
44
                //Log<EmeseneContactItemSource>.Debug ("Display found! in: {0}", photo);
 
45
                                contact["photo"] = photo;
 
46
                        }
 
47
                        else
 
48
                        {   
 
49
                            //Log<EmeseneContactItemSource>.Debug ("No display picture in DB for: {0}", contact["email"]);
 
50
                                if(this.lastContact == -1)
 
51
                                {
 
52
                                        this.lastContact = this.contactsRelation[contact["email"]];
 
53
                                }
 
54
                                do
 
55
                                {
 
56
                                        ContactItem newContact = (ContactItem)this.contacts[lastContact];
 
57
                                        string p = newContact["photo"];
 
58
                                        if(p != "")
 
59
                                        {
 
60
                                                this.lastContact--;
 
61
                                                continue;
 
62
                                        }
 
63
                                        //Log<EmeseneContactItemSource>.Debug ("Now tryng to get display from DB for: {0}", newContact["email"]);
 
64
                                        photo = Emesene.get_last_display_picture(newContact["email"], false);
 
65
                                        if (photo != "noImage")
 
66
                                        {
 
67
                        //Log<EmeseneContactItemSource>.Debug ("Display found! in: {0}", photo);
 
68
                                                newContact["photo"] = photo;
 
69
                                                //Log<EmeseneContactItemSource>.Debug ("Display picture of user: {0} : {1}", newContact["email"], newContact["photo"]);
 
70
                                        }
 
71
                                        else
 
72
                                        {
 
73
                                            //Log<EmeseneContactItemSource>.Debug ("No display picture in DB for user: {0}", newContact["email"]);
 
74
                                        }
 
75
                                        this.lastContact--;
 
76
                                        //Log<EmeseneContactItemSource>.Debug ("lastContact: {0}", this.lastContact);
 
77
                                }while(photo == "noImage" && this.lastContact > 0);
 
78
                        }
 
79
                }
 
80
                
 
81
                public override void UpdateItems ()
 
82
                {   
 
83
            Log<EmeseneContactItemSource>.Debug ("Checking for emesene...");
 
84
                        if (Emesene.checkForEmesene())
 
85
                        {
 
86
                Log<EmeseneContactItemSource>.Debug ("emesene Dbus is ON");
 
87
                        } 
 
88
                        else 
 
89
                        {
 
90
                                Log<EmeseneContactItemSource>.Debug ("emesene Dbus is OFF");
 
91
                        }                       
 
92
                        string contactsFile;                    
 
93
                        if (Emesene.checkForEmesene())
 
94
                        {
 
95
                                if (contacts.Count < 1)
 
96
                                {
 
97
                                        contactsFile = Emesene.getCurrentEmeseneUser();
 
98
                                        contactsFile = contactsFile.Replace(".","_");
 
99
                                        contactsFile = Environment.GetFolderPath
 
100
                                                        (Environment.SpecialFolder.Personal)+
 
101
                                                        "/.config/emesene1.0/"+contactsFile.Replace("@","_")+
 
102
                                                                "/cache/"+Emesene.getCurrentEmeseneUser()+"_di.xml";
 
103
                                        //Log<EmeseneContactItemSource>.Debug (" ------------------EmeseneContactItemSource------------------");
 
104
                                        Log<EmeseneContactItemSource>.Debug ("XML file with contacts: {0}", contactsFile);                                      
 
105
                                        XmlDocument blist;
 
106
                                        Dictionary<ContactItem, bool> buddies_seen;
 
107
                                        buddies_seen = new Dictionary<ContactItem, bool> ();
 
108
                                        blist = new XmlDocument();                              
 
109
                                        string mail;                            
 
110
                                        try 
 
111
                                        {
 
112
                                                blist.Load (contactsFile);
 
113
                                                int i = 0 ;
 
114
                                                int withDP = 0;
 
115
                                                string photo;
 
116
                                                foreach (XmlNode buddy_node in blist.GetElementsByTagName ("passportName"))
 
117
                                                {
 
118
                                                        i++;
 
119
                                                        mail = buddy_node.InnerText;
 
120
                                                        //Log<EmeseneContactItemSource>.Debug ("===============================================");
 
121
                                                        //Log<EmeseneContactItemSource>.Debug ("Emesene > Node#: {0} - PassportName: {1}", i,mail);
 
122
                                                        ContactItem buddy;
 
123
                                                        buddy = ContactItem.CreateWithEmail(mail);
 
124
                                                        photo = Emesene.get_last_display_picture(mail, true);
 
125
                                                        if (photo != "noImage")
 
126
                                                        {
 
127
                                                                buddy["photo"] = photo;
 
128
                                                                //Log<EmeseneContactItemSource>.Debug ("User: {0} - Display: {1}", buddy["email"], photo);
 
129
                                                                withDP++;
 
130
                                                        }
 
131
                                                        else
 
132
                                                        {
 
133
                                                            //Log<EmeseneContactItemSource>.Debug ("User: {0} - Display: None", buddy["email"]);
 
134
                                                        }
 
135
                                                        if (buddy == null) continue;
 
136
                                                        buddies_seen[buddy] = true;
 
137
                                                }
 
138
                                                Log<EmeseneContactItemSource>.Debug ("Total # of node contacts: {0}", --i);
 
139
                                                //Log<EmeseneContactItemSource>.Debug ("Total # of buddies seen: {0}", buddies_seen.Keys.Count);
 
140
                                                //Log<EmeseneContactItemSource>.Debug ("# of buddies with display: {0}", withDP);
 
141
                                        } 
 
142
                                        catch (Exception e) 
 
143
                                        {
 
144
                                            Log<EmeseneContactItemSource>.Error ("Error reading contact list file: {0}", e.Message);
 
145
                                        Log<EmeseneContactItemSource>.Debug (e.StackTrace);
 
146
                                        }
 
147
                                        foreach (ContactItem buddy in buddies_seen.Keys) 
 
148
                                        {
 
149
                                                contacts.Add (buddy);
 
150
                                                contactsRelation[buddy["email"]]= contacts.Count - 1;
 
151
                                        }
 
152
                                }
 
153
                                //contacts > 0
 
154
                                else
 
155
                                {
 
156
                                    Log<EmeseneContactItemSource>.Debug ("Length of the contact list was larger than 0...");
 
157
                                        string photo;
 
158
                                        ContactItem newContact = null;
 
159
                                        foreach (ContactItem contact in contacts)
 
160
                                        {
 
161
                                                if(contact["photo"] == null)
 
162
                                                {
 
163
                                                    //Log<EmeseneContactItemSource>.Debug ("Getting display picture from emesene cache for: {0}...", contact["email"]);
 
164
                                                        photo = Emesene.get_last_display_picture(contact["email"], true);
 
165
                                                        if (photo != "noImage")
 
166
                                                        {
 
167
                                                                contact["photo"] = photo;
 
168
                                                                //Log<EmeseneContactItemSource>.Debug ("Display picture found! : {0}", contact["photo"]);
 
169
                                                        }
 
170
                                                        else
 
171
                                                        {
 
172
                                                                newContact = contact;
 
173
                                                        }
 
174
                                                }
 
175
                                        }
 
176
                                        if(newContact != null)
 
177
                                        {
 
178
                                                this.getDisplayFromDB(newContact);
 
179
                                        }
 
180
                                }
 
181
                                Log<EmeseneContactItemSource>.Debug ("End, waiting to update again...");
 
182
                        }
 
183
                }
 
184
        }
 
185
}