From 5ef9baa7cf38156a729f45f5280fe07fe001390d Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sat, 11 Apr 2015 22:31:40 -0300 Subject: [PATCH] source-dialog: better sort calendars Make GOA calendars go first. GOA one are sorted by their account name. Then, other calendars are placed, grouped by their types and then sorted by their named. --- src/gcal-source-dialog.c | 42 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c index 5c269d1e..188f2529 100644 --- a/src/gcal-source-dialog.c +++ b/src/gcal-source-dialog.c @@ -326,12 +326,48 @@ calendar_listbox_sort_func (GtkListBoxRow *row1, GtkListBoxRow *row2, gpointer user_data) { - ESource *source1, *source2; + GcalSourceDialogPrivate *priv = GCAL_SOURCE_DIALOG (user_data)->priv; + ESource *source1; + ESource *source2; + gboolean is_goa1; + gboolean is_goa2; + gint retval; + // first source source1 = g_object_get_data (G_OBJECT (row1), "source"); - source2 = g_object_get_data (G_OBJECT (row2), "source"); + is_goa1 = is_goa_source (GCAL_SOURCE_DIALOG (user_data), source1); - return g_strcmp0 (e_source_get_display_name (source1), e_source_get_display_name (source2)); + // second source + source2 = g_object_get_data (G_OBJECT (row2), "source"); + is_goa2 = is_goa_source (GCAL_SOURCE_DIALOG (user_data), source2); + + if (is_goa1 == is_goa2) + { + gchar *parent_name1 = NULL; + gchar *parent_name2 = NULL; + + // Retrieve parent names + get_source_parent_name_color (priv->manager, source1, &parent_name1, NULL); + get_source_parent_name_color (priv->manager, source1, &parent_name2, NULL); + + retval = g_strcmp0 (parent_name1, parent_name2); + + // If they have the same parent names, compare by the source display names + if (retval == 0) + retval = g_strcmp0 (e_source_get_display_name (source1), e_source_get_display_name (source2)); + + if (parent_name1 != NULL) + g_free (parent_name1); + if (parent_name2 != NULL) + g_free (parent_name2); + } + else + { + // If one is a GOA account and the other isn't, make the GOA one go first + retval = is_goa1 ? -1 : 1; + } + + return retval; } static void