[gnome-contacts] Show warning if id to show isn't found
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Show warning if id to show isn't found
- Date: Mon, 5 Sep 2011 09:54:18 +0000 (UTC)
commit 8687a4ddc16d31cad2cdb22f048cf113fa990ffc
Author: Alexander Larsson <alexl redhat com>
Date: Mon Sep 5 11:42:07 2011 +0200
Show warning if id to show isn't found
src/contacts-app.vala | 34 ++++++++++++----------------------
src/contacts-store.vala | 36 +++++++++++++++++++++++++++++++-----
2 files changed, 43 insertions(+), 27 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 139ffe7..d85a62f 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -41,31 +41,21 @@ public class Contacts.App : Gtk.Application {
contacts_pane.show_contact (new_selection);
}
- private string show_individual_id = null;
- private void show_individual_cb (Contact contact) {
- if (contact.individual.id == show_individual_id) {
- show_individual_id = null;
- contacts_store.changed.disconnect (show_individual_cb);
- contacts_store.added.disconnect (show_individual_cb);
-
- list_pane.select_contact (contact);
- contacts_pane.show_contact (contact);
- }
- }
-
- public void show_individual (string id) {
- var contact = contacts_store.find_contact_with_id (id);
+ public async void show_individual (string id) {
+ var contact = yield contacts_store.find_contact ( (c) => {
+ return c.individual.id == id;
+ });
if (contact != null) {
list_pane.select_contact (contact);
contacts_pane.show_contact (contact);
} else {
- if (show_individual_id == null) {
- contacts_store.changed.connect (show_individual_cb);
- contacts_store.added.connect (show_individual_cb);
-
- // TODO: Wait for quiescent state to detect no such contact
- }
- show_individual_id = id;
+ var dialog = new MessageDialog (App.app.window, DialogFlags.DESTROY_WITH_PARENT, MessageType.ERROR, ButtonsType.CLOSE,
+ _("No contact with id %s found").printf (id));
+ dialog.set_title(_("Contact not found"));
+ dialog.show ();
+ dialog.response.connect ( (id) => {
+ dialog.destroy ();
+ });
}
}
@@ -182,7 +172,7 @@ public class Contacts.App : Gtk.Application {
activate ();
if (individual_id != null)
- app.show_individual (individual_id);
+ app.show_individual.begin (individual_id);
if (email_address != null)
app.show_by_email (email_address);
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 8c382e4..742936b 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -106,12 +106,38 @@ public class Contacts.Store : GLib.Object {
changed (c);
}
- public Contact? find_contact_with_id (string individual_id) {
- foreach (var contact in contacts) {
- if (contact.individual.id == individual_id)
- return contact;
+ public delegate bool ContactMatcher (Contact c);
+ public async Contact? find_contact (ContactMatcher matcher) {
+ foreach (var c in contacts) {
+ if (matcher (c))
+ return c;
}
- return null;
+ if (is_quiescent)
+ return null;
+
+ Contact? matched = null;
+ ulong id1, id2, id3;
+ SourceFunc callback = find_contact.callback;
+ id1 = this.changed.connect ( (c) => {
+ if (matcher (c)) {
+ matched = c;
+ callback ();
+ }
+ });
+ id2 = this.added.connect ( (c) => {
+ if (matcher (c)) {
+ matched = c;
+ callback ();
+ }
+ });
+ id3 = this.quiescent.connect ( () => {
+ callback();
+ });
+ yield;
+ this.disconnect (id1);
+ this.disconnect (id2);
+ this.disconnect (id3);
+ return matched;
}
public Contact? find_contact_with_email (string email_address) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]