~people-project/people-glib/trunk

« back to all changes in this revision

Viewing changes to people-glib/contact.vala

  • Committer: Ali Sabil
  • Date: 2009-02-05 16:32:05 UTC
  • Revision ID: ali.sabil@gmail.com-20090205163205-ihfypioi3nuektnb
Simplified the Contact interface by avoiding to map directly the DBus interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
        }
34
34
 
35
35
        public class Contact : Object {
 
36
                public enum State {
 
37
                        EMPTY,
 
38
                        FETCHED;
 
39
                }
 
40
 
36
41
                public DBus.Connection connection {
37
42
                        private get;
38
43
                        construct;
56
61
                        }
57
62
                }
58
63
 
59
 
                public signal void defined_fields_retrieved (string[] fields);
60
 
                public signal void fields_retrieved (HashTable<string, string> fields);
 
64
                public State state {
 
65
                        get;
 
66
                        private set;
 
67
                }
61
68
 
 
69
                private IContact contact;
62
70
                private string _id = null;
63
 
                private IContact contact;
 
71
                private HashTable<string, string> fields;
64
72
 
65
73
                construct {
66
74
                        this.contact = connection.get_object (bus_name, object_path) as IContact;
67
75
                        this.contact.defined_fields_retrieved += on_defined_fields_retrieved;
68
76
                        this.contact.fields_retrieved += on_fields_retrieved;
 
77
 
 
78
                        this.fields = new HashTable<string, string> (str_hash, str_equal);
69
79
                }
70
80
 
71
81
                public Contact (DBus.Connection connection, string bus_name, string object_path) {
74
84
                        this.object_path = object_path;
75
85
                }
76
86
 
77
 
                public void request_defined_fields () {
 
87
                public List<string> get_fields () {
 
88
                        return this.fields.get_keys ();
 
89
                }
 
90
 
 
91
                public string? get (string field_id) {
 
92
                        return this.fields.lookup (field_id);
 
93
                }
 
94
 
 
95
                public void fetch () requires (state == State.EMPTY) {
78
96
                        this.contact.request_defined_fields ();
79
97
                }
80
98
 
82
100
                        this.contact.request_fields (fields);
83
101
                }
84
102
 
85
 
                private void on_defined_fields_retrieved (dynamic DBus.Object contact, string[] fields) {
86
 
                        this.defined_fields_retrieved (fields);
 
103
                private void on_defined_fields_retrieved (IContact contact, string[] fields) {
 
104
                        if (state == State.EMPTY) {
 
105
                                this.request_fields (fields);
 
106
                        }
87
107
                }
88
108
 
89
 
                private void on_fields_retrieved (dynamic DBus.Object contact, HashTable<string, string> fields) {
90
 
                        this.fields_retrieved (fields);
 
109
                private void on_fields_retrieved (IContact contact, HashTable<string, string> fields) {
 
110
                        if (state == State.EMPTY) {
 
111
                                foreach (string field_name in fields.get_keys ()) {
 
112
                                        this.fields.insert (field_name, fields.lookup (field_name));
 
113
                                }
 
114
                                state = State.FETCHED;
 
115
                        }
91
116
                }
92
117
        }
93
118
}