diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2011-08-24 22:31:17 +0200 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2011-08-24 23:07:40 +0200 |
commit | f3dd6328aefdbc14876cdd52e1f931589a54ed3e (patch) | |
tree | 0646f17a1128bed96598fe6be0f25ffd18a48cb7 /examples/client | |
parent | 27ccfd17bd8801c043ac1f0e99aabfe08571cebe (diff) |
Add contact list JS example
Diffstat (limited to 'examples/client')
-rw-r--r-- | examples/client/Makefile.am | 2 | ||||
-rw-r--r-- | examples/client/js/Makefile.am | 2 | ||||
-rwxr-xr-x | examples/client/js/contact-list.js | 33 |
3 files changed, 36 insertions, 1 deletions
diff --git a/examples/client/Makefile.am b/examples/client/Makefile.am index 48a82f508..3481a0f4d 100644 --- a/examples/client/Makefile.am +++ b/examples/client/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = stream-tubes python +SUBDIRS = stream-tubes python js EXAMPLES = diff --git a/examples/client/js/Makefile.am b/examples/client/js/Makefile.am new file mode 100644 index 000000000..10781bf4d --- /dev/null +++ b/examples/client/js/Makefile.am @@ -0,0 +1,2 @@ +EXTRA_DIST = \ + contact-list.js diff --git a/examples/client/js/contact-list.js b/examples/client/js/contact-list.js new file mode 100755 index 000000000..e0112f7d9 --- /dev/null +++ b/examples/client/js/contact-list.js @@ -0,0 +1,33 @@ +#! /usr/bin/gjs + +const Tp = imports.gi.TelepathyGLib; +const Mainloop = imports.mainloop; + +let manager = Tp.AccountManager.dup(); +let factory = manager.get_factory(); +factory.add_account_features([Tp.Account.get_feature_quark_connection()]); +factory.add_connection_features([Tp.Connection.get_feature_quark_contact_list()]); +factory.add_contact_features([Tp.ContactFeature.CONTACT_GROUPS]); + +manager.prepare_async(null, function(self, result) { + manager.prepare_finish(result); + + let accounts = manager.get_valid_accounts(); + for (let i = 0; i < accounts.length; i++) { + let connection = accounts[i].get_connection(); + + if (connection != null && + connection.get_contact_list_state() == Tp.ContactListState.SUCCESS) { + + let contacts = connection.dup_contact_list(); + for (let j = 0; j < contacts.length; j++) { + let contact = contacts[j]; + // poor man's printf... + print (contact.get_identifier() + ' (' + contact.get_contact_groups() + ')'); + } + } + } + Mainloop.quit('example'); +}); + +Mainloop.run('example'); |