~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to Evolution/src/ContactItemSource.cs

  • Committer: Alex Launi
  • Date: 2008-10-20 22:15:56 UTC
  • mfrom: (256.2.3 evolution)
  • Revision ID: alex@eriktorvaldsonn-20081020221556-5fr8ls223i02qous
merge cszikszoy's updates to the Evolution plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
namespace Evolution
30
30
{
 
31
        public struct ContactAttribute
 
32
        {
 
33
                string detail, key;
 
34
                public ContactAttribute(string k, string d)
 
35
                {
 
36
                        this.key = k;
 
37
                        this.detail = d;
 
38
                }
 
39
                public string Detail { get { return detail; } }
 
40
                public string Key { get { return key; } }
 
41
        }
 
42
        
31
43
        public class ContactItemSource : IItemSource
32
44
        {
33
45
                List<IItem> contacts;
68
80
                                        details.Add (new BookmarkItem ("Homepage", contact [detail]));
69
81
                                else if (detail.StartsWith ("url.blog"))
70
82
                                        details.Add (new BookmarkItem ("Blog", contact [detail]));
 
83
                                else if (detail.StartsWith("address"))
 
84
                                        details.Add (new AddressContactDetailItem (contact, detail));
71
85
                        }
72
86
                        return details;
73
87
                }
89
103
                                                                try {
90
104
                                                                        contacts.Add (
91
105
                                                                                CreateEvolutionContactItem (c));
92
 
                                                                } catch { /* bad contact */ }
 
106
                                                                } catch (Exception e) {
 
107
                                                                        /* bad contact */ 
 
108
                                                                        Console.WriteLine(e.Message.ToString());
 
109
                                                                }
93
110
                                                        }
94
111
                                                }
95
112
                                        }
97
114
                        }
98
115
                }
99
116
        
100
 
                ContactItem CreateEvolutionContactItem (Contact e_contact) {
 
117
                ContactItem CreateEvolutionContactItem (Contact eContact) {
101
118
                        ContactItem contact;
102
 
                                                
103
 
                        contact = ContactItem.Create (e_contact.FullName);
104
 
                        
105
 
                        MaybeAddDetail (contact, "email.home", e_contact.Email1);
106
 
                        MaybeAddDetail (contact, "email.work", e_contact.Email2);
107
 
                        MaybeAddDetail (contact, "email.other", e_contact.Email3);
108
 
                        
109
 
                        /*
110
 
                        for (int i = 0; i < e_contact.ImAim.Length; ++i)
111
 
                                contact["aim" + (i>0?i.ToString ():"") + ".evolution"] =
112
 
                                        e_contact.ImAim[i];
113
 
                        for (int i = 0; i < e_contact.ImJabber.Length; ++i)
114
 
                                contact["jabber" + (i>0?i.ToString ():"") + ".evolution"] =
115
 
                                        e_contact.ImJabber[i];
116
 
                        */
117
 
                        
118
 
                        MaybeAddDetail (contact, "phone.mobile", e_contact.MobilePhone);
119
 
                        MaybeAddDetail (contact, "phone.home", e_contact.HomePhone);
120
 
                        MaybeAddDetail (contact, "phone.work", e_contact.CompanyPhone);
121
 
                        MaybeAddDetail (contact, "phone", e_contact.PrimaryPhone);
122
 
                        MaybeAddDetail (contact, "url.home", e_contact.HomepageUrl);
123
 
                        MaybeAddDetail (contact, "url.blog", e_contact.BlogUrl);
 
119
                        if (!(string.IsNullOrEmpty(eContact.FullName)))
 
120
                                contact = ContactItem.Create(eContact.FullName);
 
121
                        else //(!(string.IsNullOrEmpty(eContact.FileAs)))
 
122
                                contact = ContactItem.Create(eContact.FileAs);
 
123
                        List<ContactAttribute> ContactDetails = new List<ContactAttribute>();
 
124
                        ContactDetails.Add(new ContactAttribute("email.home", eContact.Email1));
 
125
                        ContactDetails.Add(new ContactAttribute("email.work", eContact.Email2));
 
126
                        ContactDetails.Add(new ContactAttribute("email.other", eContact.Email3));
 
127
                        ContactDetails.Add(new ContactAttribute("phone.mobile", eContact.MobilePhone));
 
128
                        ContactDetails.Add(new ContactAttribute("phone.home", eContact.HomePhone));
 
129
                        ContactDetails.Add(new ContactAttribute("phone.home2",eContact.HomePhone2));
 
130
                        ContactDetails.Add(new ContactAttribute("phone.work", eContact.CompanyPhone));
 
131
                        ContactDetails.Add(new ContactAttribute("phone.work2",eContact.BusinessPhone));
 
132
                        ContactDetails.Add(new ContactAttribute("phone.work3",eContact.BusinessPhone2));
 
133
                        ContactDetails.Add(new ContactAttribute("phone", eContact.PrimaryPhone));                                                                      
 
134
                        ContactDetails.Add(new ContactAttribute("url.home", eContact.HomepageUrl));
 
135
                        ContactDetails.Add(new ContactAttribute("url.blog", eContact.BlogUrl));
 
136
                        //for address, need to take out the \n characters, otherwise do is not happy
 
137
                        if (!string.IsNullOrEmpty(eContact.AddressLabelHome))
 
138
                                ContactDetails.Add(new ContactAttribute("address.home",eContact.AddressLabelHome.Replace('\n',' ')));
 
139
                        if (!string.IsNullOrEmpty(eContact.AddressLabelWork))
 
140
                                ContactDetails.Add(new ContactAttribute("address.work",eContact.AddressLabelWork.Replace('\n',' ')));
 
141
                        if (!string.IsNullOrEmpty(eContact.AddressLabelOther))
 
142
                                ContactDetails.Add(new ContactAttribute("address.other",eContact.AddressLabelOther.Replace('\n',' ')));
124
143
                        
125
144
                        // Been getting some exceptions from g_boxed_copy
126
145
                        // when I attempt to read contact photos...
127
146
                        if (string.IsNullOrEmpty (contact ["photo.evolution"])) try {
128
 
                                switch (e_contact.Photo.PhotoType) {
 
147
                                switch (eContact.Photo.PhotoType) {
129
148
                                        case ContactPhotoType.Inlined:
130
149
                                                string photo = Paths.GetTemporaryFilePath () + ".jpg";
131
150
                                                try {
132
 
                                                        File.WriteAllBytes (photo, e_contact.Photo.Data);
 
151
                                                        File.WriteAllBytes (photo, eContact.Photo.Data);
133
152
                                                        contact["photo"] = contact["photo.evolution"] =
134
153
                                                                photo;
135
154
                                                } catch { }
136
155
                                                break;
137
156
                                        case ContactPhotoType.Uri:
138
 
                                                if (File.Exists (e_contact.Photo.Uri)) {
 
157
                                                if (File.Exists (eContact.Photo.Uri)) {
139
158
                                                        contact["photo"] = contact["photo.evolution"] =
140
 
                                                                e_contact.Photo.Uri;
 
159
                                                                eContact.Photo.Uri;
141
160
                                                }
142
161
                                                break;
143
162
                                }
147
166
                                        contact["name"], e.Message);
148
167
                                Console.Error.WriteLine (e.StackTrace);
149
168
                        }
 
169
                        //add the details to the contact
 
170
                        foreach (ContactAttribute c in ContactDetails)
 
171
                        {
 
172
                                MaybeAddDetail(contact,c.Key,c.Detail);
 
173
                        }
150
174
                        return contact;
151
175
                }
152
176