[evolution] Bug 794465 - [Automatic Contacts] Option to File under as "First Last"



commit 6127b49fb8bf46fe0b936a25fc711124842c0dcf
Author: Milan Crha <mcrha redhat com>
Date:   Fri Mar 23 11:19:59 2018 +0100

    Bug 794465 - [Automatic Contacts] Option to File under as "First Last"

 ...me.evolution.plugin.autocontacts.gschema.xml.in |    5 +++
 src/plugins/bbdb/bbdb.c                            |   35 +++++++++++++++++++-
 src/plugins/bbdb/bbdb.h                            |    1 +
 3 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.evolution.plugin.autocontacts.gschema.xml.in 
b/data/org.gnome.evolution.plugin.autocontacts.gschema.xml.in
index f0758ac..a93f384 100644
--- a/data/org.gnome.evolution.plugin.autocontacts.gschema.xml.in
+++ b/data/org.gnome.evolution.plugin.autocontacts.gschema.xml.in
@@ -15,6 +15,11 @@
       <_summary>Enable autocontacts</_summary>
       <_description>Whether contacts should be automatically added to the user’s address book.</_description>
     </key>
+    <key name="file-under-as-first-last" type="b">
+      <default>false</default>
+      <_summary>Whether to set “File under” field as “First Last” </_summary>
+      <_description>Set File under as “First Last”, instead of “Last, First”.</_description>
+    </key>
     <key name="gaim-addressbook-source" type="s">
       <default>''</default>
       <_summary>Pidgin address book source</_summary>
diff --git a/src/plugins/bbdb/bbdb.c b/src/plugins/bbdb/bbdb.c
index 62d0e42..a5d7906 100644
--- a/src/plugins/bbdb/bbdb.c
+++ b/src/plugins/bbdb/bbdb.c
@@ -306,6 +306,7 @@ bbdb_do_it (EBookClient *client,
        EClientCache *client_cache;
        GList *addressbooks;
        GList *aux_addressbooks;
+       GSettings *settings;
        EBookClient *client_addressbook;
        ESourceAutocomplete *autocomplete_extension;
        gboolean on_autocomplete, has_autocomplete;
@@ -319,7 +320,7 @@ bbdb_do_it (EBookClient *client,
                return;
 
        /* don't miss the entry if the mail has only e-mail id and no name */
-       if (name == NULL || !strcmp (name, "")) {
+       if (!name || !*name) {
                temp_name = g_strndup (email, delim - email);
                name = temp_name;
        }
@@ -453,6 +454,26 @@ bbdb_do_it (EBookClient *client,
        /* Otherwise, create a new contact. */
        contact = e_contact_new ();
        e_contact_set (contact, E_CONTACT_FULL_NAME, (gpointer) name);
+
+       settings = e_util_ref_settings (CONF_SCHEMA);
+       if (g_settings_get_boolean (settings, CONF_KEY_FILE_UNDER_AS_FIRST_LAST)) {
+               EContactName *cnt_name = e_contact_name_from_string (name);
+
+               if (cnt_name) {
+                       if (cnt_name->family && *cnt_name->family &&
+                           cnt_name->given && *cnt_name->given) {
+                               gchar *str;
+
+                               str = g_strconcat (cnt_name->given, " ", cnt_name->family, NULL);
+                               e_contact_set (contact, E_CONTACT_FILE_AS, str);
+                               g_free (str);
+                       }
+
+                       e_contact_name_free (cnt_name);
+               }
+       }
+       g_clear_object (&settings);
+
        add_email_to_contact (contact, email);
        g_free (temp_name);
 
@@ -757,6 +778,18 @@ bbdb_create_config_widget (void)
                G_CALLBACK (enable_toggled_cb), stuff);
        gtk_box_pack_start (GTK_BOX (inner_vbox), check, FALSE, FALSE, 0);
 
+       /* File Under setting */
+       check = gtk_check_button_new_with_mnemonic (_("Set File _under as “First Last”, instead of “Last, 
First”"));
+       g_settings_bind (
+               settings, CONF_KEY_FILE_UNDER_AS_FIRST_LAST,
+               check, "active",
+               G_SETTINGS_BIND_DEFAULT);
+       g_settings_bind (
+               settings, CONF_KEY_ENABLE,
+               check, "sensitive",
+               G_SETTINGS_BIND_GET);
+       gtk_box_pack_start (GTK_BOX (inner_vbox), check, FALSE, FALSE, 0);
+
        label = gtk_label_new (_("Select Address book for Automatic Contacts"));
        gtk_box_pack_start (GTK_BOX (inner_vbox), label, FALSE, FALSE, 0);
 
diff --git a/src/plugins/bbdb/bbdb.h b/src/plugins/bbdb/bbdb.h
index a297815..766fb19 100644
--- a/src/plugins/bbdb/bbdb.h
+++ b/src/plugins/bbdb/bbdb.h
@@ -29,6 +29,7 @@
 #define CONF_KEY_GAIM_LAST_SYNC_TIME   "gaim-last-sync-time"
 #define CONF_KEY_GAIM_LAST_SYNC_MD5    "gaim-last-sync-md5"
 #define CONF_KEY_GAIM_CHECK_INTERVAL   "gaim-check-interval"
+#define CONF_KEY_FILE_UNDER_AS_FIRST_LAST "file-under-as-first-last"
 
 /* How often to poll the buddy list for changes (every two minutes is default) */
 #define BBDB_BLIST_DEFAULT_CHECK_INTERVAL (2 * 60)


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