File: TestBook.cs

package info (click to toggle)
evolution-sharp 0.11.1-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,684 kB
  • ctags: 3,577
  • sloc: ansic: 11,275; sh: 8,735; cs: 1,145; makefile: 222; xml: 46
file content (100 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download
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
using System;
using System.Collections;
using Gtk;
using GLib;
using Evolution;

namespace BookBindingsTest {
	public class BookBindingsTest {

                private void OnContactsAdded (object o,
                                              Evolution.ContactsAddedArgs args)
                {
			Console.WriteLine ("Contacts added:");
			foreach (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 static void Main (string[] args)
		{
			Application.Init ();

			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) {
					Console.WriteLine ("UID: {0}, Name: {1}", group.Uid, group.Name);
					SList src_list = group.Sources;
					foreach (Evolution.Source src in src_list) {
						Book bk = Book.NewSystemAddressbook ();
						//Book bk = new Book (src);
					       	bk.Open (true);

						Console.WriteLine ("UID: {0}, Name: {1}", src.Uid, src.Name);
						Evolution.BookQuery q = Evolution.BookQuery.AnyFieldContains ("");
						
						ArrayList dummy = new ArrayList ();
						BookView bk_view = bk.GetBookView (q, dummy, -1);

						BookBindingsTest t = new BookBindingsTest ();
						bk_view.ContactsChanged += t.OnContactsChanged;
						bk_view.ContactsAdded += t.OnContactsAdded;
						bk_view.ContactsRemoved += t.OnContactsRemoved;
							
						bk_view.Start ();
						
						Contact[] contactlist = bk.GetContacts (q);
						Console.WriteLine ("Contact count (range) : {0}", contactlist.Length);
												 
						
						if (contactlist != null) {
							foreach (Contact comp in contactlist) {
								Console.WriteLine ("Id: {0}", comp.Id);
								Console.WriteLine ("Fullname: {0}", comp.FullName);
							}
						} else 
							Console.WriteLine ("No event strings found");

						Contact[] newcontacts;
						Contact[] updated;
						string[] removed;

						bk.GetChanges ("TestBook-testing", 
							       out newcontacts, 
							       out updated, 
							       out removed);
						if (newcontacts != null)
							Console.WriteLine ("Newly added: {0}", newcontacts.Length);

						if (updated != null)
							Console.WriteLine ("Updated : {0}", updated.Length);

						if (removed != null)
							Console.WriteLine ("removed added: {0}", removed.Length);
					}
					
				}
				
			}
			else
				Console.WriteLine ("slist is NULL");

			Application.Run ();
		}
	}
}