Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting list of contacts with Gnome-Shell JS interface
    primarykey
    data
    text
    <p>I've just started fiddling with writing gnome-shell extensions, and would like to know how to get a list of contacts a user has.</p> <p>I've tracked down some likely files: <code>gnome-shell/js/ui/contactDisplay.js</code> and <code>gnome-shell/src/shell_contact_system.c</code>.</p> <p>Now I notice in <code>shell_contact_system.c</code> the following function:</p> <pre><code>/** * shell_contact_system_get_all: * @self: A #ShellContactSystem * * Returns: (transfer none): All individuals */ GeeMap * shell_contact_system_get_all (ShellContactSystem *self) { GeeMap *individuals; g_return_val_if_fail (SHELL_IS_CONTACT_SYSTEM (self), NULL); individuals = folks_individual_aggregator_get_individuals (self-&gt;priv-&gt;aggregator); return individuals; } </code></pre> <p>This suggests that inthe javascript interface I can use function <code>get_all</code> (my belief is reinforced by the fact that the <code>.c</code> file also has a <code>shell_contact_system_get_individual</code> and <code>contactDisplay.js</code> demonstrates the use of <code>Shell.ContactSystem.get_default().get_individual</code>), so I try:</p> <pre><code>contactSys = Shell.ContactSystem.get_default(); // get contacts contacts = contactSys.get_all(); </code></pre> <p>It works! (I'm trying it out in Gnome-shell's "looking glass" javascript interpreter).</p> <p>It appears to be a 'Gobject' so I have no idea what to do with this object to get the names of my contacts out. I notice (from the C code) that this object is a <code>GeeMap *</code>, so looking at the <a href="http://people.gnome.org/~dvillevalois/libgee/doc/gee-1.0/Gee.Map.html" rel="nofollow">documentation for Gee.Map</a>, I see I can do the following:</p> <pre><code>contacts.size // returns 31, which is the number of contacts I have ! contacts.values // is a Gee.Collection contacts.keys // is a Gee.Set </code></pre> <p>I then try to look at <code>contacts.values</code> and <code>contacts.key</code>, noting the <code>to_array()</code> method these have:</p> <pre><code>contacts.values.to_array() contacts.keys.to_array() </code></pre> <p>However when I do this I get an <strong>empty array</strong> back out: <code>contacts.xxx.to_array().size</code> is 0, yet <code>contacts.size</code> is 31 ?? !!</p> <p>The same occurs when I attempt to use a <code>contacts.map_iterator()</code> to iterate through the map; <code>it.get_value()</code> and <code>it.get_key()</code> appear to be null.</p> <p>So, my question is: <strong>How can I access the individual elements of <code>contacts</code>?</strong></p> <p>I do note that the comment for <code>shell_contact_system_get_all</code> says <code>Returns: (transfer none): ...</code> whilst <code>shell_contact_system_get_individual</code> says <code>Returns: (transfer full): ...</code>, and the latter function works (provided I know the ID of the individual I want to look up, which is my problem), whereas the former doesn't. Could this be something to do with it?</p> <p>Also, as a workaround, I can currently make use of the <code>contactSearchProvider</code> class to achieve this (used by the overview when you intall <code>gnome-contacts</code> where you can type the name of a contact and they'll appear in the overview). I basically search for <code>''</code> which should return me a list of every contact. It seems roundabout though - I feel I should just be able to use the <code>get_all()</code> method to get all the contacts without having to search on an empty string...</p> <pre><code> const ContactDisplay = imports.ui.contactDisplay; cds = new ContactDisplay.contactSearchProvider; res = cds.getInitialResultSet(['']); // woohoo! res.length is 31, and res[0], res[1], ... are all not null! </code></pre> <p>Any help would be greatly appreciated (by the way, is there any sort of documentation about for this? I feel extremely inadequate when I stare at the source and try to deduce all the documentation from it!)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload