[gnome-contacts] Window: ListPane instance made internal widget



commit 66c9b8add5edd6976c250989428ebaebff5ec538
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Sat Apr 26 10:45:49 2014 -0400

    Window: ListPane instance made internal widget

 src/contacts-app.vala    |  114 +--------------------------------------
 src/contacts-window.ui   |    3 +
 src/contacts-window.vala |  135 +++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 138 insertions(+), 114 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index c367e02..c6e3efd 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -16,6 +16,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+/* FIXME: remove using Gee if not needed */
 using Gee;
 using Gtk;
 using Folks;
@@ -29,12 +30,10 @@ public class Contacts.App : Gtk.Application {
 
   public Contacts.Window window;
 
-  private weak ListPane list_pane;
   private weak ContactPane contacts_pane;
 
   private bool app_menu_created;
 
-
   private void selection_changed (Contact? new_selection) {
     /* FIXME: ask the user lo teave edit-mode and act accordingly */
     if (contacts_pane.on_edit_mode) {
@@ -56,10 +55,7 @@ public class Contacts.App : Gtk.Application {
   }
 
   public void show_contact (Contact? contact) {
-    list_pane.select_contact (contact);
-
-    /* hack for showing contact */
-    selection_changed (contact);
+    window.set_shown_contact (contact);
   }
 
   public async void show_individual (string id) {
@@ -210,41 +206,13 @@ public class Contacts.App : Gtk.Application {
 
     contacts_store = window.contacts_store;
 
-    list_pane = window.list_pane;
-    list_pane.selection_changed.connect (selection_changed);
-    list_pane.link_contacts.connect (link_contacts);
-    list_pane.delete_contacts.connect (delete_contacts);
-
     contacts_pane = window.contacts_pane;
 
     contacts_pane.will_delete.connect (delete_contact);
     contacts_pane.contacts_linked.connect (contacts_linked);
 
-    list_pane.contacts_marked.connect ((nr_contacts) => {
-       if (nr_contacts == 0) {
-         window.left_title = _("Select");
-       } else {
-         window.left_title = ngettext ("%d Selected",
-                                       "%d Selected", nr_contacts).printf (nr_contacts);
-       }
-      });
-
     window.add_button.clicked.connect (app.new_contact);
 
-    window.select_button.toggled.connect (() => {
-        if (window.select_button.active) {
-         /* Update UI */
-         window.activate_selection_mode (true);
-
-          list_pane.show_selection ();
-       } else {
-          list_pane.hide_selection ();
-
-         /* Update UI */
-         window.activate_selection_mode (false);
-       }
-      });
-
     window.edit_button.clicked.connect (() => {
        if (contacts_pane.contact == null)
          return;
@@ -361,84 +329,6 @@ public class Contacts.App : Gtk.Application {
     dialog.show_all ();
   }
 
-  private void link_contacts (LinkedList<Contact> contact_list) {
-    /* getting out of selection mode */
-    show_contact (null);
-    window.select_button.set_active (false);
-
-    LinkOperation2 operation = null;
-    link_contacts_list.begin (contact_list, (obj, result) => {
-        operation = link_contacts_list.end (result);
-      });
-
-    var notification = new Gd.Notification ();
-    notification.timeout = 5;
-
-    var g = new Grid ();
-    g.set_column_spacing (8);
-    notification.add (g);
-
-    string msg = ngettext ("%d contacts linked",
-                           "%d contacts linked",
-                           contact_list.size).printf (contact_list.size);
-
-    var b = new Button.with_mnemonic (_("_Undo"));
-    g.add (new Label (msg));
-    g.add (b);
-
-    notification.show_all ();
-    window.add_notification (notification);
-
-    /* signal handlers */
-    b.clicked.connect ( () => {
-        /* here, we will unlink the thing in question */
-        operation.undo.begin ();
-
-        notification.dismiss ();
-      });
-  }
-
-  private void delete_contacts (LinkedList<Contact> contact_list) {
-    /* getting out of selection mode */
-    show_contact (null);
-    window.select_button.set_active (false);
-
-    var notification = new Gd.Notification ();
-    notification.timeout = 5;
-
-    var g = new Grid ();
-    g.set_column_spacing (8);
-    notification.add (g);
-
-    string msg = ngettext ("%d contact deleted",
-                           "%d contacts deleted",
-                           contact_list.size).printf (contact_list.size);
-
-    var b = new Button.with_mnemonic (_("_Undo"));
-    g.add (new Label (msg));
-    g.add (b);
-
-    notification.show_all ();
-    window.add_notification (notification);
-
-    /* signal handlers */
-    bool really_delete = true;
-    notification.dismissed.connect ( () => {
-        if (really_delete) {
-          foreach (var c in contact_list) {
-            c.remove_personas.begin ();
-          }
-        }
-      });
-    b.clicked.connect ( () => {
-        really_delete = false;
-        notification.dismiss ();
-       foreach (var c in contact_list) {
-         c.show ();
-       }
-      });
-  }
-
   private void delete_contact (Contact contact) {
     /* unsetting edit-mode */
     window.right_title = "";
diff --git a/src/contacts-window.ui b/src/contacts-window.ui
index ad40a57..7ee6039 100644
--- a/src/contacts-window.ui
+++ b/src/contacts-window.ui
@@ -160,6 +160,9 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="store">contacts_store</property>
+                <signal name="selection-changed" handler="list_pane_selection_changed_cb" 
object="ContactsWindow" after="no" swapped="no"/>
+                <signal name="link-contacts" handler="list_pane_link_contacts_cb" object="ContactsWindow" 
after="no" swapped="no"/>
+                <signal name="delete-contacts" handler="list_pane_delete_contacts_cb" 
object="ContactsWindow" after="no" swapped="no"/>
               </object>
               <packing>
                 <property name="left_attach">0</property>
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index dfae97a..9f76af3 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -16,6 +16,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+using Gee;
 using Gtk;
 using Folks;
 
@@ -27,13 +28,13 @@ public class Contacts.Window : Gtk.ApplicationWindow {
   private HeaderBar right_toolbar;
   [GtkChild]
   private Overlay overlay;
+  [GtkChild]
+  private ListPane list_pane;
 
   [GtkChild]
   public Store contacts_store;
 
   [GtkChild]
-  public ListPane list_pane;
-  [GtkChild]
   public ContactPane contacts_pane;
 
   /* FIXME: remove from public what it is not needed */
@@ -101,6 +102,50 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     overlay.add_overlay (notification);
   }
 
+  public void set_shown_contact (Contact? c) {
+    /* FIXME: ask the user lo teave edit-mode and act accordingly */
+    if (contacts_pane.on_edit_mode) {
+      contacts_pane.set_edit_mode (false);
+
+      right_title = "";
+      done_button.hide ();
+    }
+
+    contacts_pane.show_contact (c, false);
+
+    /* clearing right_toolbar */
+    if (c != null) {
+      right_title = c.display_name;
+    }
+    edit_button.visible = (c != null);
+  }
+
+  /* internal API */
+  void connect_content_widgets () {
+    list_pane.contacts_marked.connect ((nr_contacts) => {
+       if (nr_contacts == 0) {
+         left_title = _("Select");
+       } else {
+         left_title = ngettext ("%d Selected",
+                                "%d Selected", nr_contacts).printf (nr_contacts);
+       }
+      });
+
+    select_button.toggled.connect (() => {
+        if (select_button.active) {
+         /* Update UI */
+         activate_selection_mode (true);
+
+          list_pane.show_selection ();
+       } else {
+          list_pane.hide_selection ();
+
+         /* Update UI */
+         activate_selection_mode (false);
+       }
+      });
+  }
+
   [GtkCallback]
   bool key_press_event_cb (Gdk.EventKey event) {
     if ((event.keyval == Gdk.keyval_from_name ("q")) &&
@@ -132,4 +177,90 @@ public class Contacts.Window : Gtk.ApplicationWindow {
     contacts_pane.show_contact (null);
     return false;
   }
+
+  [GtkCallback]
+  void list_pane_selection_changed_cb (Contact? new_selection) {
+    set_shown_contact (new_selection);
+  }
+
+  [GtkCallback]
+  void list_pane_link_contacts_cb (LinkedList<Contact> contact_list) {
+    /* getting out of selection mode */
+    set_shown_contact (null);
+    select_button.set_active (false);
+
+    LinkOperation2 operation = null;
+    link_contacts_list.begin (contact_list, (obj, result) => {
+        operation = link_contacts_list.end (result);
+      });
+
+    var notification = new Gd.Notification ();
+    notification.timeout = 5;
+
+    var g = new Grid ();
+    g.set_column_spacing (8);
+    notification.add (g);
+
+    string msg = ngettext ("%d contacts linked",
+                           "%d contacts linked",
+                           contact_list.size).printf (contact_list.size);
+
+    var b = new Button.with_mnemonic (_("_Undo"));
+    g.add (new Label (msg));
+    g.add (b);
+
+    notification.show_all ();
+    add_notification (notification);
+
+    /* signal handlers */
+    b.clicked.connect ( () => {
+        /* here, we will unlink the thing in question */
+        operation.undo.begin ();
+
+        notification.dismiss ();
+      });
+  }
+
+  [GtkCallback]
+  void list_pane_delete_contacts_cb (LinkedList<Contact> contact_list) {
+    /* getting out of selection mode */
+    set_shown_contact (null);
+    select_button.set_active (false);
+
+    var notification = new Gd.Notification ();
+    notification.timeout = 5;
+
+    var g = new Grid ();
+    g.set_column_spacing (8);
+    notification.add (g);
+
+    string msg = ngettext ("%d contact deleted",
+                           "%d contacts deleted",
+                           contact_list.size).printf (contact_list.size);
+
+    var b = new Button.with_mnemonic (_("_Undo"));
+    g.add (new Label (msg));
+    g.add (b);
+
+    notification.show_all ();
+    add_notification (notification);
+
+    /* signal handlers */
+    bool really_delete = true;
+    notification.dismissed.connect ( () => {
+        if (really_delete) {
+          foreach (var c in contact_list) {
+            c.remove_personas.begin ();
+          }
+        }
+      });
+    b.clicked.connect ( () => {
+        really_delete = false;
+        notification.dismiss ();
+       foreach (var c in contact_list) {
+         c.show ();
+       }
+       set_shown_contact (contact_list.last ());
+      });
+  }
 }


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