1
// Evolution.cs (requires libevolution-cil)
3
// GNOME Do is the legal property of its developers.
4
// 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/>.
22
using System.Collections.Generic;
31
public class EvolutionContactItemSource : IItemSource
36
public EvolutionContactItemSource ()
38
contacts = new List<IItem> ();
42
public Type[] SupportedItemTypes {
50
public string Name { get { return "Evolution Contacts"; } }
51
public string Description { get { return "Evolution Contacts"; } }
52
public string Icon { get { return "evolution"; } }
54
public void UpdateItems ()
58
} catch (Exception e) {
59
Console.WriteLine ("Cannot index evolution contacts because a {0} was thrown: {1}", e.GetType (), e.Message);
64
public ICollection<IItem> Items {
65
get { return contacts; }
68
public ICollection<IItem> ChildrenOfItem (IItem item)
78
sources = new SourceList ("/apps/evolution/addressbook/sources");
79
foreach (SourceGroup group in sources.Groups)
80
foreach (Source source in group.Sources) {
85
// Only index local address books
86
if (!source.IsLocal ()) continue;
87
address_book = new Book (source);
88
address_book.Open (true);
89
e_contacts = address_book.GetContacts (BookQuery.AnyFieldContains (""));
90
foreach (Contact e_contact in e_contacts) {
92
contact = CreateEvolutionContactItem (e_contact);
97
contacts.Add (contact);
102
ContactItem CreateEvolutionContactItem (Contact e_contact) {
105
contact = new ContactItem (e_contact.FullName);
107
if (e_contact.Email1 != null && e_contact.Email1 != "")
108
contact.Emails.Add (e_contact.Email1);
109
if (e_contact.Email2 != null && e_contact.Email2 != "")
110
contact.Emails.Add (e_contact.Email2);
111
if (e_contact.Email3 != null && e_contact.Email3 != "")
112
contact.Emails.Add (e_contact.Email3);
114
contact.AIMs.AddRange (e_contact.ImAim);
115
contact.Jabbers.AddRange (e_contact.ImJabber);
117
switch (e_contact.Photo.PhotoType) {
118
case ContactPhotoType.Inlined:
119
contact.Photo = Path.GetTempFileName () + ".jpg";
121
File.WriteAllBytes (contact.Photo, e_contact.Photo.Data);
123
contact.Photo = null;
126
case ContactPhotoType.Uri:
127
if (File.Exists (e_contact.Photo.Uri)) {
128
contact.Photo = e_contact.Photo.Uri;
132
ContactItemStore.SynchronizeContactWithStore (ref contact);