[gnome-contacts] Set primary store with the new AccontsList widget



commit b216f43231a56eba471df49721ca5ab89741b5ad
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Tue Jul 23 00:35:50 2013 -0400

    Set primary store with the new AccontsList widget
    
    Reworked "Change Address Book" to show not only the provider of
    the account, but some of its details.

 .gitignore                      |    1 +
 src/Makefile.am                 |    1 +
 src/contacts-accounts-list.vala |  160 +++++++++++++++++++++++++++++++++++++++
 src/contacts-app.vala           |   79 ++++---------------
 4 files changed, 178 insertions(+), 63 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ba4e7f3..560a5d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,6 +71,7 @@ src/contacts-contact-sheet.c
 src/contacts-linked-accounts-dialog.c
 src/contacts-setup-window.c
 src/contacts-shell-search-provider.c
+src/contacts-accounts-list.c
 src/gnome-contacts-search-provider
 src/memory-icon.c
 src/org.gnome.Contacts.enums.xml
diff --git a/src/Makefile.am b/src/Makefile.am
index 48542df..a27a739 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,6 +40,7 @@ vala_sources = \
        contacts-clickable.vala \
        contacts-new-contact-dialog.vala \
        contacts-avatar-dialog.vala \
+       contacts-accounts-list.vala \
        contacts-contact-frame.vala \
        contacts-revealer.vala \
        contacts-setup-window.vala \
diff --git a/src/contacts-accounts-list.vala b/src/contacts-accounts-list.vala
new file mode 100644
index 0000000..5056c87
--- /dev/null
+++ b/src/contacts-accounts-list.vala
@@ -0,0 +1,160 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 8 -*- */
+/*
+ * Copyright (C) 2011 Erick Pérez Castellanos <erick red gmail com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+using Folks;
+
+public class Contacts.AccountsGrid : Frame {
+  ListBox accounts_view;
+  ListBoxRow last_selected_row;
+  Button add_account_button;
+
+  public PersonaStore selected_store;
+
+  public AccountsGrid () {
+    selected_store = null;
+
+    accounts_view = new ListBox ();
+    accounts_view.set_selection_mode (SelectionMode.BROWSE);
+    accounts_view.set_size_request (400, -1);
+    accounts_view.set_activate_on_single_click (true);
+
+    var scrolled = new ScrolledWindow(null, null);
+    scrolled.set_size_request (-1, 280);
+    scrolled.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
+    scrolled.set_shadow_type (ShadowType.NONE);
+    scrolled.add (accounts_view);
+
+    var toolbar = new Toolbar ();
+    toolbar.get_style_context ().add_class (STYLE_CLASS_PRIMARY_TOOLBAR);
+
+    add_account_button = new Button.with_label (_("Add an Online Account"));
+    add_account_button.get_style_context ().add_class (STYLE_CLASS_RAISED);
+    (add_account_button as Bin).get_child ().margin_left = 6;
+    (add_account_button as Bin).get_child ().margin_right = 6;
+    (add_account_button as Bin).get_child ().margin_top = 3;
+    (add_account_button as Bin).get_child ().margin_bottom = 3;
+    add_account_button.clicked.connect (() => {
+        try {
+          Process.spawn_command_line_async ("gnome-control-center online-accounts");
+        }
+        catch (Error e) {
+          // TODO: Show error dialog
+        }
+      });
+
+    var spacer = new SeparatorToolItem ();
+    spacer.set_draw (false);
+    spacer.set_expand (true);
+    toolbar.add (spacer);
+
+    var item = new ToolItem ();
+    item.add (add_account_button);
+    toolbar.add (item);
+
+    spacer = new SeparatorToolItem ();
+    spacer.set_draw (false);
+    spacer.set_expand (true);
+    toolbar.add (spacer);
+
+    var box = new Grid ();
+    box.set_orientation (Orientation.VERTICAL);
+    box.add (scrolled);
+    box.add (toolbar);
+
+    add (box);
+    show_all ();
+
+    update_contents ();
+  }
+
+  public void update_contents () {
+    PersonaStore local_store = null;
+    foreach (var persona_store in App.get_eds_address_books ()) {
+      if (persona_store.id == "system-address-book") {
+        local_store = persona_store;
+        continue;
+      }
+      var source = (persona_store as Edsf.PersonaStore).source;
+      var parent_source = eds_source_registry.ref_source (source.parent);
+      stdout.printf ("store.id: %s\n", persona_store.id);
+      stdout.printf ("source.display_name: %s\n", source.display_name);
+      stdout.printf ("parent_source.display_name: %s\n", parent_source.display_name);
+
+      var provider_name = Contact.format_persona_store_name (persona_store);
+
+      var row_data = new Grid ();
+      row_data.set_data ("store", persona_store);
+      row_data.margin = 12;
+
+      var provider_label = new Label (provider_name);
+      row_data.add (provider_label);
+
+      var account_name = parent_source.display_name;
+      var account_label = new Label (account_name);
+      account_label.set_halign (Align.END);
+      account_label.set_hexpand (true);
+      account_label.get_style_context ().add_class ("dim-label");
+      row_data.add (account_label);
+
+      accounts_view.add (row_data);
+
+      if (persona_store == App.app.contacts_store.aggregator.primary_store) {
+        var row = row_data.get_parent () as ListBoxRow;
+        accounts_view.select_row (row);
+      }
+    }
+
+    var local_data = new Grid ();
+    local_data.margin = 12;
+    local_data.set_data ("store", local_store);
+    var local_label = new Label (_("Keep contacts on this computer only"));
+    local_data.add (local_label);
+    accounts_view.add (local_data);
+    if (local_store == App.app.contacts_store.aggregator.primary_store) {
+      var row = local_data.get_parent () as ListBoxRow;
+      accounts_view.select_row (row);
+    }
+
+    accounts_view.set_header_func ((row) => {
+        if (row.get_header () == null)
+          row.set_header (new Separator (Orientation.HORIZONTAL));
+      });
+
+    accounts_view.row_selected.connect ((row) => {
+        if (row == null)
+          return;
+
+        var row_data = (row as Bin).get_child ();
+        var account_label = (row_data as Grid).get_child_at (1, 0);
+        if (account_label != null)
+          account_label.get_style_context ().remove_class ("dim-label");
+
+        if (last_selected_row != null) {
+          var last_row_data = (last_selected_row as Bin).get_child ();
+          var last_account_label = (last_row_data as Grid).get_child_at (1, 0);
+          if (last_account_label != null)
+            last_account_label.get_style_context ().add_class ("dim-label");
+        }
+
+        last_selected_row = row;
+
+        selected_store = row_data.get_data<PersonaStore> ("store");
+      });
+  }
+}
\ No newline at end of file
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index a197534..4d8ce55 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -116,78 +116,31 @@ public class Contacts.App : Gtk.Application {
 
   public void change_address_book () {
     var title = _("Change Address Book");
-    var dialog = new Dialog.with_buttons ("",
-                                          (Window) window,
-                                          DialogFlags.MODAL | DialogFlags.DESTROY_WITH_PARENT,
-                                          Stock.CANCEL, ResponseType.CANCEL,
-                                          _("Select"), ResponseType.OK);
+    var dialog = new Dialog.with_buttons (_("Primary Contacts Account"),
+                                         (Window) window,
+                                         DialogFlags.MODAL | DialogFlags.DESTROY_WITH_PARENT,
+                                         _("Cancel"), ResponseType.CANCEL,
+                                         _("Done"), ResponseType.OK);
 
+    dialog.set_title (_("Accounts"));
     dialog.set_resizable (false);
     dialog.set_default_response (ResponseType.OK);
 
-    var tree_view = new TreeView ();
-    var store = new ListStore (2, typeof (string), typeof (Folks.PersonaStore));
-    tree_view.set_model (store);
-    tree_view.set_headers_visible (false);
-    tree_view.get_selection ().set_mode (SelectionMode.BROWSE);
-
-    var column = new Gtk.TreeViewColumn ();
-    tree_view.append_column (column);
-
-    var renderer = new Gtk.CellRendererText ();
-    column.pack_start (renderer, false);
-    column.add_attribute (renderer, "text", 0);
-
-    var scrolled = new ScrolledWindow(null, null);
-    scrolled.set_size_request (340, 300);
-    scrolled.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
-    scrolled.set_vexpand (true);
-    scrolled.set_hexpand (true);
-    scrolled.set_shadow_type (ShadowType.IN);
-    scrolled.add (tree_view);
-
-    var grid = new Grid ();
-    grid.set_orientation (Orientation.VERTICAL);
-    grid.set_row_spacing (6);
-
-    var l = new Label (title);
-    l.set_halign (Align.START);
-
-    grid.add (l);
-    grid.add (scrolled);
+    var acc = new AccountsGrid ();
 
     var box = dialog.get_content_area () as Box;
-    box.pack_start (grid, true, true, 0);
-    grid.set_border_width (6);
-
-    TreeIter iter;
-
-    foreach (var persona_store in get_eds_address_books ()) {
-      var name = Contact.format_persona_store_name (persona_store);
-      store.append (out iter);
-      store.set (iter, 0, name, 1, persona_store);
-      if (persona_store == contacts_store.aggregator.primary_store) {
-        tree_view.get_selection ().select_iter (iter);
-      }
-    }
+    box.pack_start (acc, true, true, 0);
 
     dialog.show_all ();
     dialog.response.connect ( (response) => {
-        if (response == ResponseType.OK) {
-          PersonaStore selected_store;
-          TreeIter iter2;
-
-          if (tree_view.get_selection() .get_selected (null, out iter2)) {
-            store.get (iter2, 1, out selected_store);
-
-            var e_store = selected_store as Edsf.PersonaStore;
-
-            eds_source_registry.set_default_address_book (e_store.source);
-
-            contacts_store.refresh ();
-          }
-        }
-        dialog.destroy ();
+       if (response == ResponseType.OK) {
+         var e_store = acc.selected_store as Edsf.PersonaStore;
+         if (e_store != null) {
+           eds_source_registry.set_default_address_book (e_store.source);
+           contacts_store.refresh ();
+         }
+       }
+       dialog.destroy ();
       });
   }
 


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