~ubuntu-branches/ubuntu/lucid/tomboy/lucid-proposed

« back to all changes in this revision

Viewing changes to Tomboy/Plugins/GalagoPresence.cs

Tags: upstream-0.3.9+dfsg
ImportĀ upstreamĀ versionĀ 0.3.9+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
using System.Collections;
4
4
using System.Runtime.InteropServices;
5
5
using System.Diagnostics;
6
 
using Mono.Posix;
 
6
using Mono.Unix;
7
7
 
8
8
using Gtk;
9
9
using Galago;
13
13
class GalagoManager
14
14
{
15
15
        TrieTree trie;
16
 
        bool initial_update;
17
16
 
18
17
        public GalagoManager ()
19
18
        {
20
 
                Galago.Core.Init ("tomboy", false);
 
19
                Galago.Global.Init ("tomboy", Galago.InitFlags.Client);
21
20
 
22
21
                ///// 
23
22
                ///// Connecting these cause crashes with the current 0.3.2 bindings...
40
39
 
41
40
        void OnUpdated (object sender, EventArgs args)
42
41
        {
43
 
                Console.WriteLine ("Got Presence Updated!");
 
42
                Logger.Log ("Got Presence Updated!");
44
43
                if (PresenceChanged != null)
45
44
                        PresenceChanged (this, args);
46
45
        }
47
46
 
48
 
        void OnPersonAdded (object sender, Galago.AddedArgs args)
 
47
        void OnPersonAdded (object sender, Galago.PersonAddedArgs args)
49
48
        {
50
 
                Console.WriteLine ("Person Added!");
 
49
                Logger.Log ("Person Added!");
51
50
 
52
51
                UpdateTrie (false);
53
52
                if (PeopleChanged != null)
54
53
                        PeopleChanged (this, args);
55
54
        }
56
55
 
57
 
        void OnPersonRemoved (object sender, Galago.RemovedArgs args)
 
56
        void OnPersonRemoved (object sender, Galago.PersonRemovedArgs args)
58
57
        {
59
 
                Console.WriteLine ("Person Removed!");
 
58
                Logger.Log ("Person Removed!");
60
59
 
61
60
                UpdateTrie (false);
62
61
                if (PeopleChanged != null)
68
67
                trie = new TrieTree (false /* !case_sensitive */);
69
68
                ArrayList people = new ArrayList ();
70
69
 
71
 
                Console.WriteLine ("Loading up the person trie, Part 1...");
72
 
 
73
 
                foreach (Person person in Galago.Core.GetPeople (false, refresh_query)) {
74
 
                        string fname, mname, lname;
75
 
                        person.GetProperty ("first-name", out fname);
76
 
                        person.GetProperty ("middle-name", out mname);
77
 
                        person.GetProperty ("last-name", out lname);
78
 
 
79
 
                        if (person.DisplayName != null) {
 
70
                Logger.Log ("Loading up the person trie, Part 1...");
 
71
 
 
72
                foreach (Person person in Galago.Global.GetPeople (Galago.Origin.Remote, 
 
73
                                                                   refresh_query)) {
 
74
                        string name = person.DisplayName;
 
75
 
 
76
                        if (name != null) {
80
77
                                people.Add (new PersonLink (LinkType.PersonDisplayName, person));
81
78
                        }
82
79
 
83
 
                        // Joe
84
 
                        if (fname != null) {
85
 
                                people.Add (new PersonLink (LinkType.FirstName, person));
86
 
                        }
87
 
 
88
 
                        // Joe Smith & Smith Joe
89
 
                        if (fname != null && lname != null) {
90
 
                                people.Add (new PersonLink (LinkType.FirstLastName, person));
91
 
                                people.Add (new PersonLink (LinkType.LastFirstName, person));
92
 
                        }
93
 
 
94
 
                        // Joe Michael Smith
95
 
                        if (fname != null && mname != null && lname != null) {
96
 
                                people.Add (new PersonLink (LinkType.FirstMiddleLastName, person));
97
 
                        }
98
 
 
99
80
                        foreach (Account account in person.GetAccounts(true)) {
100
81
                                if (account.DisplayName != null) {
101
82
                                        people.Add (new PersonLink (LinkType.AccountDisplayName, 
102
83
                                                                    account));
103
84
                                }
104
85
 
105
 
                                if (account.UserName != null &&
106
 
                                    account.UserName != account.DisplayName) {
 
86
                                if (account.Username != null &&
 
87
                                    account.Username != account.DisplayName) {
107
88
                                        people.Add (new PersonLink (LinkType.AccountUserName, 
108
89
                                                                    account));
109
90
                                }
110
91
                        }
111
92
                }
112
93
 
113
 
                Console.WriteLine ("Loading up the person trie, Part 2...");
 
94
                Logger.Log ("Loading up the person trie, Part 2...");
114
95
 
115
96
                foreach (PersonLink plink in people) {
116
97
                        trie.AddKeyword (plink.LinkText, plink);
117
98
                }
118
99
 
119
 
                Console.WriteLine ("Done.");
 
100
                Logger.Log ("Done.");
120
101
        }
121
102
}
122
103
 
125
106
        PersonDisplayName,
126
107
        AccountUserName,
127
108
        AccountDisplayName,
128
 
        FirstName,
129
 
        FirstLastName,
130
 
        LastFirstName,
131
 
        FirstMiddleLastName
132
109
}
133
110
 
134
111
class PersonLink
143
120
                this.person = person;
144
121
                this.account = null;
145
122
 
146
 
                Console.WriteLine ("Added person {0}: {1}", link_type, LinkText);
 
123
                Logger.Log ("Added person {0}: {1}", link_type, LinkText);
147
124
        }
148
125
 
149
126
        public PersonLink (LinkType type, Account account)
152
129
                this.person = account.Person;
153
130
                this.account = account;         
154
131
 
155
 
                Console.WriteLine ("Added account {0}: {1}", link_type, LinkText);
 
132
                Logger.Log ("Added account {0}: {1}", link_type, LinkText);
156
133
        }
157
134
 
158
135
        public string LinkText
159
136
        {
160
137
                get {
161
 
                        string fname, mname, lname;
162
 
                        person.GetProperty ("first-name", out fname);
163
 
                        person.GetProperty ("middle-name", out mname);
164
 
                        person.GetProperty ("last-name", out lname);
165
 
 
 
138
                        
166
139
                        switch (link_type) {
167
140
                        case LinkType.PersonDisplayName:
168
141
                                return person.DisplayName;
169
142
                        case LinkType.AccountUserName:
170
 
                                return account.UserName;
 
143
                                return account.Username;
171
144
                        case LinkType.AccountDisplayName:
172
145
                                return account.DisplayName;
173
 
                        case LinkType.FirstName:
174
 
                                return fname;
175
 
                        case LinkType.FirstLastName:
176
 
                                return fname + " " + lname;
177
 
                        case LinkType.LastFirstName:
178
 
                                return lname + " " + fname;
179
 
                        case LinkType.FirstMiddleLastName:
180
 
                                return fname + " " + mname + " " + lname;
181
146
                        }
182
147
                        return null;
183
148
                }
189
154
                        return account;
190
155
 
191
156
                if (person != null) {
192
 
                        // BINDING BUG: Returns a Person instead of Account
193
 
                        Person foo = person.PriorityAccount;
194
 
                        Account best = new Account (foo.Handle);
 
157
                        Account best = person.PriorityAccount;
195
158
                        
196
 
                        Console.WriteLine ("Using priority account '{0}' for {1}", 
197
 
                                           best.UserName, 
198
 
                                           LinkText);
 
159
                        Logger.Log ("Using priority account '{0}' for {1}", 
 
160
                                    best.Username, 
 
161
                                    LinkText);
199
162
 
200
163
                        return best;
201
164
                }
212
175
                p.StartInfo.FileName = "gaim-remote";
213
176
                p.StartInfo.Arguments = 
214
177
                        "uri " + 
215
 
                        best.Service.Id + ":goim?screenname=" + best.UserName;
 
178
                        best.Service.Id + ":goim?screenname=" + best.Username;
216
179
                p.StartInfo.UseShellExecute = false;
217
180
 
218
181
                p.Start ();
275
238
                        string message = Catalog.GetString ("Error running gaim-remote: {0}");
276
239
                        message = String.Format (message, e.Message);
277
240
 
278
 
                        Console.WriteLine (message);
 
241
                        Logger.Log (message);
279
242
 
280
243
                        HIGMessageDialog dialog = 
281
244
                                new HIGMessageDialog (editor.Toplevel as Gtk.Window,
315
278
                if (person_tag == null) {
316
279
                        person_tag = new PersonTag ("link:person", galago);
317
280
 
318
 
                        Console.WriteLine ("Adding link:person tag...");
 
281
                        Logger.Log ("Adding link:person tag...");
319
282
                        Note.TagTable.Add (person_tag);
320
283
                }
321
284
 
369
332
                        Gtk.TextIter match_end = match_start;
370
333
                        match_end.ForwardChars (hit.End - hit.Start);
371
334
 
372
 
                        Console.WriteLine ("Matching Person '{0}' at {1}-{2}...", 
373
 
                                           hit.Key, 
374
 
                                           hit.Start, 
375
 
                                           hit.End);
 
335
                        Logger.Log ("Matching Person '{0}' at {1}-{2}...", 
 
336
                                    hit.Key, 
 
337
                                    hit.Start, 
 
338
                                    hit.End);
376
339
                        Buffer.ApplyTag (person_tag, match_start, match_end);
377
340
                }
378
341
        }