From 84dd6ce9eb82d51fefcc0f77a104adbf786feea1 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 2 Jan 2008 03:03:35 +0000 Subject: [PATCH] 2008-01-01 Jim Evins * src/merge-evolution.c: Sort evolution by "file_under" field. Original patch provided by Peter Cherriman in Patch #1860423. * AUTHORS: Added acknowledgement for above patch. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/branches/glabels-2_2@720 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/AUTHORS | 1 + glabels2/ChangeLog | 9 ++++++++ glabels2/src/merge-evolution.c | 38 +++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/glabels2/AUTHORS b/glabels2/AUTHORS index 5a493529..114644b7 100644 --- a/glabels2/AUTHORS +++ b/glabels2/AUTHORS @@ -44,6 +44,7 @@ Glabels includes contributions from: Akkana Dag Wieers Mário Meyer + Peter Cherriman Translations: diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 15851e0a..8c2623ac 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,12 @@ +2008-01-01 Jim Evins + + * src/merge-evolution.c: + Sort evolution by "file_under" field. Original patch provided + by Peter Cherriman in + Patch #1860423. + * AUTHORS: + Added acknowledgement for above patch. + 2007-12-25 Jim Evins * glabels.spec.in: diff --git a/glabels2/src/merge-evolution.c b/glabels2/src/merge-evolution.c index cf5d283e..8cad010a 100644 --- a/glabels2/src/merge-evolution.c +++ b/glabels2/src/merge-evolution.c @@ -8,6 +8,8 @@ * Copyright (C) 2001 Jim Evins . * and * Copyright (C) 2005 Austin Henry + * and + * Copyright (C) 2007 Peter Cherriman * * 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 @@ -256,6 +258,34 @@ gl_merge_evolution_get_primary_key (glMerge *merge) return g_strdup (e_contact_pretty_name(E_CONTACT_FILE_AS)); } +/* Sort compare function for sorting contacts by file-as element + * by Peter Cherriman (PJC) + * called by GList* g_list_sort(GList *list, sort_contact_by_file_as); + */ +static gint sort_contact_by_file_as(gconstpointer *a, gconstpointer *b) +{ + /* + * Returns : negative value if a < b; zero if a = b; positive value if a > b + */ + + // Check and cast a and b to EContact + EContact *contact_a = E_CONTACT(a); + EContact *contact_b = E_CONTACT(b); + + // Extract file_as for each contact and compare... + char *a_file_as = e_contact_get (contact_a, E_CONTACT_FILE_AS); + char *b_file_as = e_contact_get (contact_b, E_CONTACT_FILE_AS); + int res = strcmp(a_file_as, b_file_as); + + gl_debug(DEBUG_MERGE, "Sort comparing contacts '%s' and '%s' = %d", a_file_as, b_file_as, res); + + // free file_as strings created earlier.... + g_free (a_file_as); + g_free (b_file_as); + + return res; +} + /*--------------------------------------------------------------------------*/ /* Open merge source. */ /*--------------------------------------------------------------------------*/ @@ -359,10 +389,16 @@ gl_merge_evolution_open (glMerge *merge) e_book_query_unref(query); + /* Sort contacts using file-as element.... + * by Peter Cherriman (PJC) + */ + gl_debug (DEBUG_MERGE, "Starting sort"); + merge_evolution->priv->contacts = g_list_sort(merge_evolution->priv->contacts, (GCompareFunc)sort_contact_by_file_as); + gl_debug (DEBUG_MERGE, "Ended sort"); + gl_debug (DEBUG_MERGE, "END"); return; - /* XXX I should probably sort the list by name (or the file-as element)*/ } /*--------------------------------------------------------------------------*/ -- 2.39.5