~renatofilho/+junk/libsocialweb

« back to all changes in this revision

Viewing changes to contactlist.vala

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2012-09-26 22:03:04 UTC
  • Revision ID: renato.filho@canonical.com-20120926220304-k7uph4vk0x75l1jd
Example code for folks + libsocialweb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Renato Araujo Oliveira Filho <renato@canonical.com>
 
6
 *
 
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; version 3.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
//using Dee;
 
21
using Gee;
 
22
using Folks;
 
23
using SocialWebClient;
 
24
 
 
25
namespace Unity.Contacts {
 
26
    public class ContactList : GLib.Object
 
27
    {
 
28
        private Folks.IndividualAggregator aggregator;
 
29
        construct
 
30
        {
 
31
            initialize_folks ();
 
32
            GLib.Timeout.add(100, list_all);
 
33
        }
 
34
 
 
35
        private void initialize_folks ()
 
36
        {
 
37
            aggregator = new Folks.IndividualAggregator();
 
38
            aggregator.prepare();
 
39
        }
 
40
 
 
41
        private void dump_social_web(Contact contact)
 
42
        {
 
43
            stdout.printf ("\tLibsocialweb: %s\n", contact.uuid);
 
44
            foreach(var prop_name in contact.props.get_keys()) {
 
45
                stdout.printf ("\t\tprop %s: %s\n",
 
46
                               prop_name,
 
47
                               contact.get_value(prop_name));
 
48
            }
 
49
        }
 
50
 
 
51
        public bool list_all ()
 
52
        {
 
53
            stdout.printf ("Started contact list.\n");
 
54
 
 
55
            var contacts = aggregator.individuals.values;
 
56
            foreach (var contact in contacts) {
 
57
                stdout.printf ("\nContact:\n\tNickname: %s\n\tAlias: %s\n\tFull Name: %s\n",
 
58
                                contact.nickname, contact.alias, contact.full_name);
 
59
 
 
60
                // Check for e-mail
 
61
                foreach(var email in contact.email_addresses) {
 
62
                    stdout.printf("\tEmail: %s\n", email.value);
 
63
                }
 
64
                foreach (var persona in contact.personas) {
 
65
                    stdout.printf("Persona:\n");
 
66
                    Value prop_value = new Contact();
 
67
                    persona.get_property("lsw_contact", ref prop_value);
 
68
                    Contact c  = (Contact) prop_value;
 
69
                    if (c != null) {
 
70
                        dump_social_web (c);
 
71
                    }
 
72
                }
 
73
            }
 
74
            stdout.printf ("DONE\n");
 
75
            return false;
 
76
        }
 
77
    }
 
78
}