[gnome-contacts] Show all contacts or just main.



commit ed64a43f4a44f0b8e96fc1c156ea45532293bb94
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Sat Feb 16 10:31:04 2013 -0500

    Show all contacts or just main.
    
    Ignoring the rest of the possible values of the enum.
    Calling refilter on every setting change to update the View.
    
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=676411

 src/app-menu.ui             |   13 +++++++++++++
 src/contacts-app.vala       |   10 ++++++++++
 src/contacts-list-pane.vala |   16 +++++++++++-----
 3 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/src/app-menu.ui b/src/app-menu.ui
index b51a646..dfa85c5 100644
--- a/src/app-menu.ui
+++ b/src/app-menu.ui
@@ -1,6 +1,19 @@
 <interface>
   <menu id="app-menu">
     <section>
+      <attribute name="label" translatable="yes">View</attribute>
+      <item>
+       <attribute name="action">app.view_subset</attribute>
+       <attribute name="target">main</attribute>
+       <attribute name="label" translatable="yes">Main contacts</attribute>
+      </item>
+      <item>
+       <attribute name="action">app.view_subset</attribute>
+       <attribute name="target">all</attribute>
+       <attribute name="label" translatable="yes">All contacts</attribute>
+      </item>
+    </section>
+    <section>
       <item>
        <attribute name="action">app.change_book</attribute>
        <attribute name="label" translatable="yes">_Change Address Book...</attribute>
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 2189a6d..6465dc9 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -261,6 +261,16 @@ public class Contacts.App : Gtk.Application {
     this.add_action (action);
     this.add_accelerator ("<Primary>n", "app.new_contact", null);
 
+    var view_action = new GLib.SimpleAction.stateful ("view_subset", VariantType.STRING, settings.get_value 
("view-subset"));
+    this.add_action (view_action);
+    settings.changed["view-subset"].connect (() => {
+       view_action.set_state (settings.get_value ("view-subset"));
+       list_pane.refilter ();
+      });
+    view_action.activate.connect ((act, parameter) => {
+       settings.set_value ("view-subset", parameter);
+      });
+
     var builder = new Builder ();
     builder.set_translation_domain (Config.GETTEXT_PACKAGE);
     try {
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index abb330c..acf0159 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -36,7 +36,7 @@ public class Contacts.ListPane : Frame {
   public signal void link_contacts (LinkedList<Contact> contacts_list);
   public signal void delete_contacts (LinkedList<Contact> contacts_list);
 
-  private void refilter () {
+  public void refilter () {
     string []? values;
     string str = filter_entry.get_text ();
 
@@ -48,10 +48,16 @@ public class Contacts.ListPane : Frame {
     }
 
     contacts_view.set_filter_values (values);
-    if (values == null)
-      contacts_view.set_show_subset (View.Subset.MAIN);
-    else
-      contacts_view.set_show_subset (View.Subset.ALL_SEPARATED);
+
+    var subset = App.app.settings.get_enum ("view-subset");
+    if (subset == View.Subset.MAIN) {
+      if (values == null)
+       contacts_view.set_show_subset (View.Subset.MAIN);
+      else
+       contacts_view.set_show_subset (View.Subset.ALL_SEPARATED);
+    } else {
+       contacts_view.set_show_subset (View.Subset.ALL);
+    }
   }
 
   private bool filter_entry_changed_timeout () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]