[Xfce4-commits] <postler:master> Implement Autocomplete via DBus using libFolks
Christian Dywan
noreply at xfce.org
Thu Aug 11 00:38:02 CEST 2011
Updating branch refs/heads/master
to 495aabe0932f46af2cf02f178ea4fc7d0c826125 (commit)
from d3b910b0347478fcacd62fd62fb0296e3829ddc1 (commit)
commit 495aabe0932f46af2cf02f178ea4fc7d0c826125
Author: Christian Dywan <christian at twotoasts.de>
Date: Thu Aug 11 00:16:53 2011 +0200
Implement Autocomplete via DBus using libFolks
postler/postler-client.vala | 12 ++++++++++++
postler/postler-index.vala | 21 +++++++++++++++++++--
postler/postler-recipiententry.vala | 20 +++++++++++++-------
postler/postler-service.vala | 4 ++++
4 files changed, 48 insertions(+), 9 deletions(-)
diff --git a/postler/postler-client.vala b/postler/postler-client.vala
index 14cb784..64a658a 100644
--- a/postler/postler-client.vala
+++ b/postler/postler-client.vala
@@ -19,6 +19,7 @@ namespace Postler {
public async abstract string[] get_thread (string thread) throws IOError;
public signal void got_message (GLib.HashTable<string,Variant> message, int64 position);
public async abstract string[] get_messages (string uri) throws IOError;
+ public async abstract string[] autocomplete (string input) throws IOError;
public signal void progress (string account, string text, double fraction);
public abstract void receive (string account) throws IOError;
public signal void received (string account, string error_message);
@@ -120,6 +121,17 @@ namespace Postler {
return messages;
}
+ public async string[] autocomplete (string input) throws GLib.Error {
+ string[] suggestions;
+ try {
+ suggestions = yield client.autocomplete (input);
+ }
+ catch (GLib.Error error) {
+ suggestions = {};
+ }
+ return suggestions;
+ }
+
public signal void progress (string account, string? text, double fraction);
public void receive (string account="") {
diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index 4ea4d92..6908485 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -24,6 +24,7 @@ namespace Postler {
static Sqlite.Statement? statement_guess = null;
static int64 startup_timestamp = new DateTime.now_utc ().to_unix ();
static GLib.HashTable<string,Postler.Contact> names;
+ static GLib.HashTable<string,string> addresses;
#if HAVE_FOLKS
static Folks.IndividualAggregator aggregator;
@@ -32,13 +33,17 @@ namespace Postler {
string? display_name = individual.full_name ?? individual.alias;
if (display_name != null) {
var contact = new Postler.Contact (display_name, individual.avatar);
- foreach (string address in individual.email_addresses)
+ foreach (string address in individual.email_addresses) {
names.insert (address, contact);
+ addresses.insert (display_name, address);
+ }
/* foreach (string address in individual.im_addresses.get_values ())
names.insert (address, contact); */
foreach (var persona in individual.personas) {
- if (persona.display_id.chr (-1, '@') != null)
+ if (persona.display_id.chr (-1, '@') != null) {
names.insert (persona.display_id, contact);
+ addresses.insert (display_name, persona.display_id);
+ }
}
}
}
@@ -71,6 +76,7 @@ namespace Postler {
return;
names = new GLib.HashTable<string,Postler.Contact> (str_hash, str_equal);
+ addresses = new GLib.HashTable<string,string> (str_hash, str_equal);
/* FIXME: Populate addresses from Dexter */
#if HAVE_FOLKS
aggregator = new Folks.IndividualAggregator ();
@@ -509,6 +515,17 @@ namespace Postler {
return -1;
}
+ public string[] autocomplete (string input) {
+ string[] suggestions = new Dexter.Dexter ().autocomplete_contact (input);
+ foreach (string address in names.get_keys ())
+ if (address.has_prefix (input))
+ suggestions += names.lookup (address).display_name + " <" + address + ">";
+ foreach (string name in addresses.get_keys ())
+ if (name.has_prefix (input))
+ suggestions += name + "<" + addresses.lookup (name) + ">";
+ return suggestions;
+ }
+
public Postler.Contact? guess_name (string address) throws GLib.Error {
Postler.Contact? contact = names.lookup (address);
if (contact != null) {
diff --git a/postler/postler-recipiententry.vala b/postler/postler-recipiententry.vala
index a9ec771..24e6339 100644
--- a/postler/postler-recipiententry.vala
+++ b/postler/postler-recipiententry.vala
@@ -11,8 +11,6 @@
namespace Postler {
public class RecipientEntry : FlowBox {
- Dexter.Dexter dexter = new Dexter.Dexter ();
-
public Gtk.Entry entry;
bool invalidated = true;
string real_text;
@@ -159,12 +157,20 @@ namespace Postler {
var model = entry.get_completion ().model as Gtk.ListStore;
if (model.iter_n_children (null) > 0)
return;
- string[] contacts = dexter.autocomplete_contact (entry.text);
- foreach (string contact in contacts) {
- Gtk.TreeIter iter;
- model.append (out iter);
- model.set (iter, 0, contact);
+ autocomplete (entry.text, model);
+ }
+
+ async void autocomplete (string input, Gtk.ListStore model) {
+ try {
+ var client = new Postler.Client ();
+ string[] contacts = yield client.autocomplete (input);
+ foreach (string contact in contacts) {
+ Gtk.TreeIter iter;
+ model.append (out iter);
+ model.set (iter, 0, contact);
+ }
}
+ catch (GLib.Error error) { }
}
}
}
diff --git a/postler/postler-service.vala b/postler/postler-service.vala
index 4950dba..37956bc 100644
--- a/postler/postler-service.vala
+++ b/postler/postler-service.vala
@@ -418,6 +418,10 @@ namespace Postler {
return index.get_messages (uri);
}
+ public string[] autocomplete (string input) throws GLib.Error {
+ return index.autocomplete (input);
+ }
+
public signal void progress (string account, string text, double fraction);
public void receive (string account) {
More information about the Xfce4-commits
mailing list