[gnome-contacts] Support changing primary address book
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Support changing primary address book
- Date: Mon, 16 Jan 2012 16:02:27 +0000 (UTC)
commit 0df476e229f8bb1db4769cc6735b39b8674d2dbe
Author: Alexander Larsson <alexl redhat com>
Date: Mon Jan 16 16:59:24 2012 +0100
Support changing primary address book
configure.ac | 3 +-
src/contacts-app.vala | 90 +++++++++++++++++++++++++++++++++++++++-
src/contacts-contact-pane.vala | 2 +-
src/contacts-contact.vala | 28 ++++++++++++-
src/contacts-esd-setup.c | 19 ++++++++
src/contacts-esd-setup.h | 1 +
src/contacts-link-dialog.vala | 2 +-
src/contacts-store.vala | 8 ++++
src/contacts-view.vala | 2 +-
vapi/custom.vapi | 2 +
10 files changed, 150 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b941b86..66ef632 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,6 +36,7 @@ pkg_modules="gtk+-3.0
gnome-desktop-3.0
folks >= 0.6.1.1
folks-telepathy
+ folks-eds
libnotify
libebook-1.2
libedataserver-1.2
@@ -44,7 +45,7 @@ pkg_modules="gtk+-3.0
"
PKG_CHECK_MODULES(CONTACTS, [$pkg_modules])
-CONTACTS_PACKAGES="--pkg gtk+-3.0 --pkg gio-2.0 --pkg folks --pkg folks-telepathy --pkg libnotify"
+CONTACTS_PACKAGES="--pkg gtk+-3.0 --pkg gio-2.0 --pkg folks --pkg folks-telepathy --pkg folks-eds --pkg libnotify"
AC_SUBST(CONTACTS_PACKAGES)
AC_OUTPUT
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index d7b1cf7..f60c8d5 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -22,7 +22,7 @@ using Folks;
public class Contacts.App : Gtk.Application {
public ApplicationWindow window;
public static App app;
- private Store contacts_store;
+ public Store contacts_store;
private ListPane list_pane;
private ContactPane contacts_pane;
@@ -79,6 +79,87 @@ 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);
+
+ 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 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 Contact.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);
+ }
+ }
+
+ 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;
+
+ try {
+ E.BookClient.set_default_source (e_store.source);
+ } catch {
+ warning ("Failed to set address book");
+ }
+
+ contacts_store.refresh ();
+ }
+ }
+ dialog.destroy ();
+ });
+ }
+
public void show_about () {
string[] authors = {
"Alexander Larsson <alexl redhat com>",
@@ -139,15 +220,20 @@ public class Contacts.App : Gtk.Application {
action.activate.connect (() => { show_about (); });
this.add_action (action);
+ action = new GLib.SimpleAction ("change_book", null);
+ action.activate.connect (() => { change_address_book (); });
+ this.add_action (action);
+
var builder = new Builder ();
builder.set_translation_domain (Config.GETTEXT_PACKAGE);
try {
builder.add_from_string ("<interface>" +
" <menu id='app-menu'>" +
" <section>" +
- " <item label='_About Contacts' action='app.about'/>" +
+ " <item label='_Change Address Book...' action='app.change_book'/>" +
" </section>" +
" <section>" +
+ " <item label='_About Contacts' action='app.about'/>" +
" <item label='_Quit' action='app.quit' accel='<Primary>q'/>" +
" </section>" +
" </menu>" +
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 625ba90..4fb95eb 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -1285,7 +1285,7 @@ public class Contacts.PersonaSheet : Grid {
Contact.persona_has_writable_property (persona, "postal-addresses");
if (!persona.store.is_primary_store) {
- header = new TitleFieldRow (this, Contact.format_persona_store_name (persona.store));
+ header = new TitleFieldRow (this, Contact.format_persona_store_name_for_contact (persona.store));
this.attach (header, 0, row_nr++, 1, 1);
header.clicked.connect ( () => {
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 2d82d35..d7c2aca 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -807,7 +807,7 @@ public class Contacts.Contact : GLib.Object {
}
}
- private void queue_changed (bool is_persona_change) {
+ public void queue_changed (bool is_persona_change) {
_is_hidden_uptodate = false;
changed_personas |= is_persona_change;
@@ -1059,6 +1059,18 @@ public class Contacts.Contact : GLib.Object {
return find_persona_from_store (store.aggregator.primary_store);
}
+ public static PersonaStore[] get_eds_address_books () {
+ PersonaStore[] stores = {};
+ foreach (var backend in App.app.contacts_store.backend_store.enabled_backends.values) {
+ foreach (var persona_store in backend.persona_stores.values) {
+ if (persona_store.type_id == "eds") {
+ stores += persona_store;
+ }
+ }
+ }
+ return stores;
+ }
+
public static string format_persona_store_name (PersonaStore store) {
if (store.type_id == "eds") {
unowned string? eds_name = lookup_esource_name_by_uid (store.id);
@@ -1073,6 +1085,20 @@ public class Contacts.Contact : GLib.Object {
return store.display_name;
}
+ public static string format_persona_store_name_for_contact (PersonaStore store) {
+ if (store.type_id == "eds") {
+ unowned string? eds_name = lookup_esource_name_by_uid_for_contact (store.id);
+ if (eds_name != null)
+ return eds_name;
+ }
+ if (store.type_id == "telepathy") {
+ var account = (store as Tpf.PersonaStore).account;
+ return format_im_service (account.service, null);
+ }
+
+ return store.display_name;
+ }
+
public Account? is_callable (string proto, string id) {
Tpf.Persona? t_persona = this.find_im_persona (proto, id);
if (t_persona != null && t_persona.contact != null) {
diff --git a/src/contacts-esd-setup.c b/src/contacts-esd-setup.c
index 4e8d650..9efeae6 100644
--- a/src/contacts-esd-setup.c
+++ b/src/contacts-esd-setup.c
@@ -610,6 +610,25 @@ const char *
contacts_lookup_esource_name_by_uid (const char *uid)
{
if (strcmp (uid, contacts_eds_local_store) == 0)
+ return _("Local Address Book");
+
+ if (contacts_source_list) {
+ ESource *source = e_source_list_peek_source_by_uid (contacts_source_list, uid);
+ if (source) {
+ const char *relative_uri = e_source_peek_relative_uri (source);
+ if (relative_uri && g_str_has_suffix (relative_uri, "@gmail.com"))
+ return _("Google");
+
+ return e_source_peek_name (source);
+ }
+ }
+ return NULL;
+}
+
+const char *
+contacts_lookup_esource_name_by_uid_for_contact (const char *uid)
+{
+ if (strcmp (uid, contacts_eds_local_store) == 0)
return _("Local Contact");
if (contacts_source_list) {
diff --git a/src/contacts-esd-setup.h b/src/contacts-esd-setup.h
index bda6294..83ed38c 100644
--- a/src/contacts-esd-setup.h
+++ b/src/contacts-esd-setup.h
@@ -1,5 +1,6 @@
void contacts_ensure_eds_accounts (void);
extern char *contacts_eds_local_store;
const char *contacts_lookup_esource_name_by_uid (const char *uid);
+const char *contacts_lookup_esource_name_by_uid_for_contact (const char *uid);
gboolean contacts_esource_uid_is_google (const char *uid);
char *eds_personal_google_group_name (void);
diff --git a/src/contacts-link-dialog.vala b/src/contacts-link-dialog.vala
index 03c8221..ec03f5c 100644
--- a/src/contacts-link-dialog.vala
+++ b/src/contacts-link-dialog.vala
@@ -56,7 +56,7 @@ public class Contacts.LinkDialog : Dialog {
persona_grid.attach (label, 1, i, 1, 1);
label = new Label ("");
- label.set_markup ("<span font='9'>" + Contact.format_persona_store_name (p.store) + "</span>");
+ label.set_markup ("<span font='9'>" + Contact.format_persona_store_name_for_contact (p.store) + "</span>");
label.set_valign (Align.START);
label.set_halign (Align.START);
label.set_hexpand (true);
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 53699f8..6dcb313 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -28,6 +28,7 @@ public class Contacts.Store : GLib.Object {
public signal void quiescent ();
public IndividualAggregator aggregator { get; private set; }
+ public BackendStore backend_store { get; private set; }
Gee.ArrayList<Contact> contacts;
public Gee.HashMap<string, Account> calling_accounts;
@@ -42,6 +43,12 @@ public class Contacts.Store : GLib.Object {
get { return this.aggregator.is_quiescent; }
}
+ public void refresh () {
+ foreach (var c in contacts) {
+ c.queue_changed (true);
+ }
+ }
+
private bool individual_can_replace_at_split (Individual new_individual) {
foreach (var p in new_individual.personas) {
if (p.get_data<bool> ("contacts-new-contact"))
@@ -58,6 +65,7 @@ public class Contacts.Store : GLib.Object {
public Store () {
contacts = new Gee.ArrayList<Contact>();
+ backend_store = BackendStore.dup ();
aggregator = new IndividualAggregator ();
aggregator.notify["is-quiescent"].connect ( (obj, pspec) => {
// We seem to get this before individuals_changed, so hack around it
diff --git a/src/contacts-view.vala b/src/contacts-view.vala
index 7daf5a5..cd2631a 100644
--- a/src/contacts-view.vala
+++ b/src/contacts-view.vala
@@ -486,7 +486,7 @@ public class Contacts.ViewWidget : TreeView {
foreach (var p in contact.individual.personas) {
if (!first)
stores += ", ";
- stores += Contact.format_persona_store_name (p.store);
+ stores += Contact.format_persona_store_name_for_contact (p.store);
first = false;
}
cell.set ("name", name,
diff --git a/vapi/custom.vapi b/vapi/custom.vapi
index 70b4854..abb83c5 100644
--- a/vapi/custom.vapi
+++ b/vapi/custom.vapi
@@ -31,6 +31,8 @@ namespace Contacts {
public static string? eds_local_store;
[CCode (cname = "contacts_lookup_esource_name_by_uid")]
public static unowned string? lookup_esource_name_by_uid (string uid);
+ [CCode (cname = "contacts_lookup_esource_name_by_uid_for_contact")]
+ public static unowned string? lookup_esource_name_by_uid_for_contact (string uid);
[CCode (cname = "contacts_esource_uid_is_google")]
public static bool esource_uid_is_google (string uid);
[CCode (cname = "eds_personal_google_group_name")]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]