summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Pérez Castellanos <erick.red@gmail.com>2014-06-09 15:05:51 -0400
committerErick Pérez Castellanos <erick.red@gmail.com>2014-09-19 17:01:15 -0400
commit133d3704731e92632267417c493918cc8d479976 (patch)
treedadc5b9148a7ad89df37b82e21fd0de7ef67ffd4
parent1bd5a9fb6c97fd9bbe086f93131bd544e13cf343 (diff)
downloadgnome-contacts-133d3704731e92632267417c493918cc8d479976.tar.gz
search-provider: update to shell new API
-rw-r--r--data/gnome-contacts-search-provider.ini.in1
-rw-r--r--src/contacts-app.vala16
-rw-r--r--src/contacts-shell-search-provider.vala79
-rw-r--r--src/contacts-window.vala4
4 files changed, 76 insertions, 24 deletions
diff --git a/data/gnome-contacts-search-provider.ini.in b/data/gnome-contacts-search-provider.ini.in
index 9e8da46..1b6f98c 100644
--- a/data/gnome-contacts-search-provider.ini.in
+++ b/data/gnome-contacts-search-provider.ini.in
@@ -4,3 +4,4 @@ Icon=x-office-address-book
DesktopId=gnome-contacts.desktop
BusName=org.gnome.Contacts.SearchProvider
ObjectPath=/org/gnome/Contacts/SearchProvider
+Version=2
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 8d6a0e5..6b86e80 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -154,6 +154,16 @@ public class Contacts.App : Gtk.Application {
}
}
+ public void show_search (string query) {
+ if (contacts_store.is_quiescent) {
+ window.show_search (query);
+ } else {
+ contacts_store.quiescent.connect_after (() => {
+ window.show_search (query);
+ });
+ }
+ }
+
private void create_app_menu () {
var action = new GLib.SimpleAction ("quit", null);
action.activate.connect (() => { this.quit (); });
@@ -302,11 +312,14 @@ public class Contacts.App : Gtk.Application {
private static string individual_id = null;
private static string email_address = null;
+ private static string search_terms = null;
private static const OptionEntry[] options = {
{ "individual", 'i', 0, OptionArg.STRING, ref individual_id,
N_("Show contact with this individual id"), null },
{ "email", 'e', 0, OptionArg.STRING, ref email_address,
N_("Show contact with this email address"), null },
+ { "search", 's', 0, OptionArg.STRING, ref search_terms,
+ null, null },
{ null }
};
@@ -320,6 +333,7 @@ public class Contacts.App : Gtk.Application {
individual_id = null;
email_address = null;
+ search_terms = null;
try {
context.parse (ref _args);
@@ -334,6 +348,8 @@ public class Contacts.App : Gtk.Application {
app.show_individual.begin (individual_id);
if (email_address != null)
app.show_by_email.begin (email_address);
+ if (search_terms != null)
+ app.show_search (search_terms);
return 0;
}
diff --git a/src/contacts-shell-search-provider.vala b/src/contacts-shell-search-provider.vala
index 404d7e6..83babe6 100644
--- a/src/contacts-shell-search-provider.vala
+++ b/src/contacts-shell-search-provider.vala
@@ -1,6 +1,7 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
using Gee;
-[DBus (name = "org.gnome.Shell.SearchProvider")]
+[DBus (name = "org.gnome.Shell.SearchProvider2")]
public class Contacts.SearchProvider : Object {
SearchProviderApp app;
Store store;
@@ -15,16 +16,16 @@ public class Contacts.SearchProvider : Object {
next_id = 0;
store.changed.connect ( (c) => {
- contacts_map.set(c.get_data<string> ("search-id"), c);
- });
+ contacts_map.set(c.get_data<string> ("search-id"), c);
+ });
store.added.connect ( (c) => {
- var id = next_id++.to_string ();
- c.set_data ("search-id", id);
- contacts_map.set(id, c);
- });
+ var id = next_id++.to_string ();
+ c.set_data ("search-id", id);
+ contacts_map.set(id, c);
+ });
store.removed.connect ( (c) => {
- contacts_map.unset(c.get_data<string> ("search-id"));
- });
+ contacts_map.unset(c.get_data<string> ("search-id"));
+ });
}
private static int compare_contacts (Contact a, Contact b) {
@@ -32,9 +33,9 @@ public class Contacts.SearchProvider : Object {
int b_prio = b.is_main ? 0 : -1;
if (a_prio > b_prio)
- return -1;
+ return -1;
if (a_prio < b_prio)
- return 1;
+ return 1;
if (is_set (a.display_name) && is_set (b.display_name))
return a.display_name.collate (b.display_name);
@@ -48,39 +49,41 @@ public class Contacts.SearchProvider : Object {
return 0;
}
- private string[] do_search (string[] terms) {
+ private async string[] do_search (string[] terms) {
app.hold ();
string[] normalized_terms =
- Utils.canonicalize_for_search (string.joinv(" ", terms)).split(" ");
+ Utils.canonicalize_for_search (string.joinv(" ", terms)).split(" ");
var matches = new ArrayList<Contact> ();
foreach (var c in store.get_contacts ()) {
if (c.is_hidden)
- continue;
+ continue;
if (c.contains_strings (normalized_terms))
- matches.add (c);
+ matches.add (c);
}
matches.sort((CompareDataFunc<Contact>) compare_contacts);
var results = new string[matches.size];
for (int i = 0; i < matches.size; i++)
- results[i] = matches[i].get_data ("search-id");
+ results[i] = matches[i].get_data ("search-id");
app.release ();
return results;
}
- public string[] GetInitialResultSet (string[] terms) {
- return do_search (terms);
+ public async string[] GetInitialResultSet (string[] terms) {
+ warning ("GetInitialResultSet %s", string.joinv ("; ", terms));
+ return yield do_search (terms);
}
- public string[] GetSubsearchResultSet (string[] previous_results,
- string[] new_terms) {
- return do_search (new_terms);
+ public async string[] GetSubsearchResultSet (string[] previous_results,
+ string[] new_terms) {
+ warning ("GetSubsearchResultSet %s", string.joinv ("; ", new_terms));
+ return yield do_search (new_terms);
}
- public HashTable<string, Variant>[] GetResultMetas (string[] ids) {
+ private async HashTable<string, Variant>[] get_metas (owned string[] ids) {
app.hold ();
var results = new ArrayList<HashTable> ();
foreach (var id in ids) {
@@ -103,12 +106,20 @@ public class Contacts.SearchProvider : Object {
results.add (meta);
}
app.release ();
+ warning ("GetResultMetas: RETURNED");
return results.to_array ();
}
- public void ActivateResult (string search_id) {
+ public async HashTable<string, Variant>[] GetResultMetas (string[] ids) {
+ warning ("GetResultMetas: %s", string.joinv ("; ", ids));
+ return yield get_metas (ids);
+ }
+
+ public void ActivateResult (string search_id, string[] terms, uint32 timestamp) {
app.hold ();
+ warning ("ActivateResult: %s", search_id);
+
var contact = contacts_map.get (search_id);
if (contact == null) {
@@ -126,9 +137,29 @@ public class Contacts.SearchProvider : Object {
app.release ();
}
+
+ public void LaunchSearch (string[] terms, uint32 timestamp) {
+ app.hold ();
+
+ debug ("LaunchSearch (%s)", string.joinv (", ", terms));
+
+ try {
+ string[] args = {};
+ args += "gnome-contacts";
+ args += "--search";
+ args += string.joinv (" ", terms);
+ if (!Process.spawn_async (null, args, null, SpawnFlags.SEARCH_PATH, null, null))
+ stderr.printf ("Failed to launch Contacts for search\n");
+ } catch (SpawnError error) {
+ stderr.printf ("Failed to launch Contacts for search\n");
+ warning (error.message);
+ }
+
+ app.release ();
+ }
}
-public class Contacts.SearchProviderApp : Gtk.Application {
+public class Contacts.SearchProviderApp : GLib.Application {
public SearchProviderApp () {
Object (application_id: "org.gnome.Contacts.SearchProvider",
flags: ApplicationFlags.IS_SERVICE,
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index fca514c..c49d6a7 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -322,6 +322,10 @@ public class Contacts.Window : Gtk.ApplicationWindow {
contact_pane.new_contact ();
}
+ public void show_search (string query) {
+ list_pane.filter_entry.set_text (query);
+ }
+
/* internal API */
void init_content_widgets () {
string layout_desc;