Patches: lastname, fnln

View: New views
1 Messages — Rating Filter:   Alert me  

Patches: lastname, fnln

by Salvatore De Paolis-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm attaching two patches for the autocompletion and the addressbook.

First adds completion of the addressbook also for the lastname field.
Second automatically fill the Name and Last Name entries in the edit personal
details dialog.

If i'll have the right time i want to rewrite the completion thing and get rid
of the redundant (buggy) window and use instead the naturally
GtkEntryCompletion widget.

I recall i said this other times :) i hope this is the good time for doing it.

Cheers
Salvatore


--- claws-mail-3.7.3/src/addr_compl.c 2009-05-11 18:33:56.000000000 +0200
+++ claws/src/addr_compl.c 2009-10-10 16:41:31.000000000 +0200
@@ -220,21 +220,24 @@ static void free_all(void)
  * \param str Index string value.
  * \param ae  Entry containing address data.
  */
-void addr_compl_add_address1(const char *str, address_entry *ae)
+void addr_compl_add_address1(const char *str, address_entry *ae, gint weight)
 {
  completion_entry *ce1;
  ce1 = g_new0(completion_entry, 1),
  /* GCompletion list is case sensitive */
  ce1->string = g_utf8_strdown(str, -1);
  ce1->ref = ae;
-
- g_completion_list = g_list_prepend(g_completion_list, ce1);
+    if (!weight)
+        g_completion_list = g_list_append(g_completion_list, ce1);
+    else
+    g_completion_list = g_list_prepend(g_completion_list, ce1);
 }
 
 /**
  * Adds address to the completion list. This function looks complicated, but
  * it's only allocation checks. Each value will be included in the index.
  * \param name    Recipient name.
+ * \param lastname Recipient lastname.
  * \param address EMail address.
  * \param alias   Alias to append.
  * \param grp_emails the emails in case of a group. List should be freed later,
@@ -242,7 +245,7 @@ void addr_compl_add_address1(const char
  * \return <code>0</code> if entry appended successfully, or <code>-1</code>
  *         if failure.
  */
-static gint add_address(const gchar *name, const gchar *address,
+static gint add_address(const gchar *name, const gchar *lastname, const gchar *address,
  const gchar *nick, const gchar *alias, GList *grp_emails)
 {
  address_entry    *ae;
@@ -260,19 +263,23 @@ static gint add_address(const gchar *nam
  cm_return_val_if_fail(ae != NULL, -1);
 
  ae->name    = g_strdup(name);
+   ae->lastname = g_strdup(lastname);
  ae->address = g_strdup(address);
  ae->grp_emails = grp_emails;
  g_address_list = g_list_prepend(g_address_list, ae);
 
- addr_compl_add_address1(name, ae);
+ addr_compl_add_address1(name, ae, 1);
+    
+    if (lastname)
+        addr_compl_add_address1(lastname, ae, 0);
  if (address != NULL && *address != '\0')
- addr_compl_add_address1(address, ae);
+ addr_compl_add_address1(address, ae, 2);
 
  if (nick != NULL && *nick != '\0')
- addr_compl_add_address1(nick, ae);
+ addr_compl_add_address1(nick, ae, 3);
 
  if ( alias != NULL && *alias != '\0') {
- addr_compl_add_address1(alias, ae);
+ addr_compl_add_address1(alias, ae, 4);
  }
 
  return 0;
@@ -281,7 +288,8 @@ static gint add_address(const gchar *nam
 /**
  * Read address book, creating all entries in the completion index.
  */
-static void read_address_book(gchar *folderpath) {
+static void read_address_book(gchar *folderpath)
+{
  free_all_addresses();
  free_completion_list();
 
@@ -731,7 +739,8 @@ static void address_completion_create_co
  * Create a completion window object.
  * \return Initialized completion window.
  */
-static CompletionWindow *addrcompl_create_window( void ) {
+static CompletionWindow *addrcompl_create_window( void )
+{
  CompletionWindow *cw;
 
  cw = g_new0( CompletionWindow, 1 );
@@ -750,7 +759,8 @@ static CompletionWindow *addrcompl_creat
  * Destroy completion window.
  * \param cw Window to destroy.
  */
-static void addrcompl_destroy_window( CompletionWindow *cw ) {
+static void addrcompl_destroy_window( CompletionWindow *cw )
+{
  /* Stop all searches currently in progress */
  addrindex_stop_search( _queryID_ );
 
@@ -782,7 +792,8 @@ static void addrcompl_destroy_window( Co
  * Free up completion window.
  * \param cw Window to free.
  */
-static void addrcompl_free_window( CompletionWindow *cw ) {
+static void addrcompl_free_window( CompletionWindow *cw )
+{
  if( cw ) {
  addrcompl_destroy_window( cw );
 
@@ -837,7 +848,8 @@ static void completion_window_advance_se
  * Resize window to accommodate maximum number of address entries.
  * \param cw Completion window.
  */
-static void addrcompl_resize_window( CompletionWindow *cw ) {
+static void addrcompl_resize_window( CompletionWindow *cw )
+{
  GtkRequisition r;
  gint x, y, width, height, depth;
 
@@ -864,7 +876,8 @@ static GdkPixbuf *email_pixbuf = NULL;
  * \param cw      Completion window.
  * \param address Address to add.
  */
-static void addrcompl_add_entry( CompletionWindow *cw, gchar *address ) {
+static void addrcompl_add_entry( CompletionWindow *cw, gchar *address )
+{
  GtkListStore *store;
  GtkTreeIter iter;
  GtkTreeSelection *selection;
@@ -933,7 +946,8 @@ static void addrcompl_add_entry( Complet
  * \param data Target completion window to receive email addresses.
  * \return <i>TRUE</i> to ensure that idle event do not get ignored.
  */
-static gboolean addrcompl_idle( gpointer data ) {
+static gboolean addrcompl_idle( gpointer data )
+{
  GList *node;
  gchar *address;
 
@@ -995,7 +1009,8 @@ static gint addrcompl_callback_entry(
 /**
  * Clear the display queue.
  */
-static void addrcompl_clear_queue( void ) {
+static void addrcompl_clear_queue( void )
+{
  /* Clear out display queue */
  pthread_mutex_lock( & _completionMutex_ );
 
@@ -1009,7 +1024,8 @@ static void addrcompl_clear_queue( void
  * Add a single address entry into the display queue.
  * \param address Address to append.
  */
-static void addrcompl_add_queue( gchar *address ) {
+static void addrcompl_add_queue( gchar *address )
+{
  pthread_mutex_lock( & _completionMutex_ );
  _displayQueue_ = g_list_append( _displayQueue_, address );
  pthread_mutex_unlock( & _completionMutex_ );
@@ -1018,7 +1034,8 @@ static void addrcompl_add_queue( gchar *
 /**
  * Load list with entries from local completion index.
  */
-static void addrcompl_load_local( void ) {
+static void addrcompl_load_local( void )
+{
  guint count = 0;
 
  for (count = 0; count < get_completion_count(); count++) {
@@ -1035,7 +1052,8 @@ static void addrcompl_load_local( void )
 /**
  * Start the search.
  */
-static void addrcompl_start_search( void ) {
+static void addrcompl_start_search( void )
+{
  gchar *searchTerm;
 
  searchTerm = g_strdup( _compWindow_->searchTerm );
@@ -1559,7 +1577,8 @@ static gboolean completion_window_key_pr
 /**
  * Setup completion object.
  */
-void addrcompl_initialize( void ) {
+void addrcompl_initialize( void )
+{
  /* g_print( "addrcompl_initialize...\n" ); */
  if( ! _compWindow_ ) {
  _compWindow_ = addrcompl_create_window();
@@ -1572,7 +1591,8 @@ void addrcompl_initialize( void ) {
 /**
  * Teardown completion object.
  */
-void addrcompl_teardown( void ) {
+void addrcompl_teardown( void )
+{
  /* g_print( "addrcompl_teardown...\n" ); */
  addrcompl_free_window( _compWindow_ );
  _compWindow_ = NULL;
diff -up claws-mail-3.7.3/src/addr_compl.h claws/src/addr_compl.h
--- claws-mail-3.7.3/src/addr_compl.h 2009-05-11 18:33:56.000000000 +0200
+++ claws/src/addr_compl.h 2009-10-10 16:18:50.000000000 +0200
@@ -32,6 +32,7 @@
 typedef struct
 {
     gchar *name;
+    gchar *lastname;
     gchar *address;
     GList *grp_emails;
 } address_entry;
@@ -52,6 +53,6 @@ void address_completion_end (GtkWidget
 void addrcompl_initialize ( void );
 void addrcompl_teardown ( void );
 
-void addr_compl_add_address1(const char *str, address_entry *ae);
+void addr_compl_add_address1(const char *str, address_entry *ae, gint weight);
 
 #endif /* __ADDR_COMPL_H__ */
diff -up claws-mail-3.7.3/src/addrindex.c claws/src/addrindex.c
--- claws-mail-3.7.3/src/addrindex.c 2009-02-25 06:22:03.000000000 +0100
+++ claws/src/addrindex.c 2009-10-10 15:37:26.000000000 +0200
@@ -2866,13 +2866,14 @@ void addrindex_remove_results( AddressDa
 */
 
 static void addrindex_load_completion_load_persons(
- gint (*callBackFunc) ( const gchar *, const gchar *,
+ gint (*callBackFunc) ( const gchar *, const gchar *, const gchar *,
        const gchar *, const gchar *, GList * ),
  AddressDataSource *ds)
 {
  GList *listP, *nodeP;
  GList *nodeM;
  gchar *sName;
+    gchar *lastname;
 
  /* Read address book */
  if( addrindex_ds_get_modify_flag( ds ) ) {
@@ -2894,7 +2895,7 @@ static void addrindex_load_completion_lo
  if (email->address)
  emails = g_list_append(emails, email);
  }
- callBackFunc( ((AddrItemObject *)group)->name, NULL,
+ callBackFunc( ((AddrItemObject *)group)->name, NULL, NULL,
       NULL, NULL, emails );
  nodeP = g_list_next( nodeP );
  }
@@ -2913,12 +2914,14 @@ static void addrindex_load_completion_lo
  if( sName == NULL || *sName == '\0' ) {
  sName = person->nickName;
  }
-
+        lastname = person->lastName;
+        if (!lastname)
+            lastname = person->nickName;
  /* Process each E-Mail address */
  while( nodeM ) {
  ItemEMail *email = nodeM->data;
 
- callBackFunc( sName, email->address, person->nickName,
+ callBackFunc( sName, lastname, email->address, person->nickName,
       ADDRITEM_NAME(email), NULL );
 
  nodeM = g_list_next( nodeM );
@@ -2942,7 +2945,7 @@ static void addrindex_load_completion_lo
  */
 
 gboolean addrindex_load_completion(
- gint (*callBackFunc) ( const gchar *, const gchar *,
+ gint (*callBackFunc) ( const gchar *, const gchar *, const gchar *,
        const gchar *, const gchar *, GList * ),
  gchar *folderpath )
 {
@@ -2967,6 +2970,7 @@ gboolean addrindex_load_completion(
  GList *items;
  GList *nodeM;
  gchar *sName;
+           gchar *lastname;
  ItemPerson *person;
 
  debug_print("addrindex_load_completion: folder %p '%s'\n", folder, folder->obj.name);
@@ -2982,12 +2986,15 @@ gboolean addrindex_load_completion(
  if( sName == NULL || *sName == '\0' ) {
  sName = person->nickName;
  }
-
+                lastname = person->lastName;
+                if (!lastname) {
+                    lastname = person->nickName;
+                }
  /* Process each E-Mail address */
  while( nodeM ) {
  ItemEMail *email = nodeM->data;
 
- callBackFunc( sName, email->address, person->nickName,
+ callBackFunc( sName, lastname, email->address, person->nickName,
   ADDRITEM_NAME(email), NULL );
 
  nodeM = g_list_next( nodeM );
diff -up claws-mail-3.7.3/src/addrindex.h claws/src/addrindex.h
--- claws-mail-3.7.3/src/addrindex.h 2009-01-09 18:30:29.000000000 +0100
+++ claws/src/addrindex.h 2009-10-10 15:01:40.000000000 +0200
@@ -169,7 +169,7 @@ void addrindex_remove_results ( Address
 
 gboolean addrindex_load_completion(
  gint (*callBackFunc)
- ( const gchar *, const gchar *,
+ ( const gchar *, const gchar *, const gchar *,
   const gchar *, const gchar *, GList * ),
  gchar *folderpath );
 



--- claws-mail-3.7.3/src/editaddress.c 2009-02-25 06:22:04.000000000 +0100
+++ claws/src/editaddress.c 2009-10-10 19:08:25.000000000 +0200
@@ -869,6 +869,27 @@ static gboolean addressbook_edit_person_
  return TRUE;
 }
 
+static gboolean edit_person_auto_fn_ln(GtkWidget *widget, GdkEventFocus *event, gpointer *data)
+{
+    GtkEntry *entry = GTK_ENTRY(widget);
+    GtkEntry *first_name = GTK_ENTRY(personeditdlg.entry_first);
+    GtkEntry *last_name = GTK_ENTRY(personeditdlg.entry_last);
+
+    const gchar *entry_text = gtk_entry_get_text(entry);
+    const gchar *first_name_text = gtk_entry_get_text(first_name);
+    const gchar *last_name_text = gtk_entry_get_text(last_name);
+    const char *p = NULL;
+    if ((p = strchr(entry_text, 32))) {
+        if (!strlen(first_name_text) && !strlen(last_name_text)) {
+            const gchar *chunk1 = g_strndup(entry_text, strlen(entry_text) - strlen(p));
+            p++;
+            const gchar *chunk2 = p;
+            gtk_entry_set_text(first_name, chunk1);
+            gtk_entry_set_text(last_name, chunk2);
+        }
+    }
+    return FALSE;
+}
 static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) {
  GtkWidget *vbox;
  GtkWidget *hbox;
@@ -984,13 +1005,15 @@ static void addressbook_edit_person_page
  gtk_table_set_row_spacings(GTK_TABLE(table), 15);
  gtk_table_set_col_spacings(GTK_TABLE(table), 8);
 
+    g_signal_connect(G_OBJECT(entry_name),"focus_out_event",
+                   G_CALLBACK(edit_person_auto_fn_ln), NULL);
+
  gtk_widget_show_all(vbox);
  personeditdlg.entry_name  = entry_name;
  personeditdlg.entry_first = entry_fn;
  personeditdlg.entry_last  = entry_ln;
  personeditdlg.entry_nick  = entry_nn;
 }
-
 static gboolean email_adding = FALSE, email_saving = FALSE;
 
 static void edit_person_entry_email_changed (GtkWidget *entry, gpointer data)



signature.asc (204 bytes) Download Attachment