summaryrefslogtreecommitdiffstats
path: root/src/evolution.cs
blob: 5622a699babf843c491ae2ba67465cd2c69606ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//  GFAX - Gnome fax application
//  Copyright (C) 2003 - 2008 George A. Farris
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

namespace gfax {
	using System;
	using System.IO;
	using GLib;
	using Gtk;
	using GtkSharp;
	using System.Collections;
	using System.Reflection;
	using Evolution;
	
	//************************************************************************
	//
	// 
	// 
	public class EdsPhoneBooks
	{
	
		private void OnContactsAdded (object o,	Evolution.ContactsAddedArgs args)
		{
			Console.WriteLine ("Contacts added:");
			foreach (Evolution.Contact contact in args.Contacts) {
				Console.WriteLine ("\nId: {0}", contact.Id);
				Console.WriteLine ("Fullname: {0}", contact.FullName);
			}
		}

        private void OnContactsChanged (object o, Evolution.ContactsChangedArgs args)
		{
		}

        private void OnContactsRemoved (object o, Evolution.ContactsRemovedArgs args)
		{
		
		}

		public ArrayList GetPhoneBooks ()
		{
			ArrayList ebooks = new ArrayList();
						
			SourceList slist = new SourceList ("/apps/evolution/addressbook/sources");
			if (slist != null) {
				SList group_list = slist.Groups;
				//Console.WriteLine ("Group count: {0}", group_list.Count);

				foreach (SourceGroup group in group_list) {
					//Only get phone books on this machine.
					if (group.Name == "On This Computer") {
						SList src_list = group.Sources;
					
						foreach (Evolution.Source src in src_list) {
							ebooks.Add(src.Name);
						}
					}
				}
			}
			return ebooks;
		}

		
		public ArrayList GetContacts (string bookName)
		{
			string contact_fax = null;
			ArrayList ebooks = new ArrayList();
			ArrayList records = new ArrayList();
			
			SourceList slist = new SourceList ("/apps/evolution/addressbook/sources");
			if (slist != null) {
				SList group_list = slist.Groups;
				foreach (SourceGroup group in group_list) {
					//Only get phone books on this machine.
					if (group.Name == "On This Computer") {
						SList src_list = group.Sources;
					
						foreach (Evolution.Source src in src_list) {
							if (src.Name == bookName) {
								//Book bk = Book.NewSystemAddressbook ();
								Book bk = new Book(src);
								bk.Open (true);

								BookQuery q = BookQuery.AnyFieldContains ("");
								Contact[] contactlist = bk.GetContacts (q);
								//Console.WriteLine ("Contact count (range) : {0}", contactlist.Length);
								
								if (contactlist != null) {
									
									foreach (Contact comp in contactlist) {
										contact_fax = null;
										
										if (comp.BusinessFax != null && comp.BusinessFax != String.Empty) {
											contact_fax = comp.BusinessFax;
										}
										else if (comp.OtherFax != null && comp.OtherFax != String.Empty) {
											contact_fax = comp.OtherFax;
										}
										else if (comp.HomeFax != null && comp.HomeFax != String.Empty) {
											contact_fax = comp.HomeFax;
										}

										if (contact_fax != null) {
											GfaxContact gc = new GfaxContact();
											//Console.WriteLine ("Id: {0}", comp.Id);
											gc.PhoneNumber = contact_fax;
											gc.ContactPerson = comp.FullName;
											gc.Organization = comp.Org;
											records.Add(gc);
										}
									}
								}
							}
						}
					}
				}
			}
			return records;
		}
	}
}