[gnome-calendar] source-dialog: sort online accounts



commit 7482469b014b2e4abe89c9689d414d3741a2c5e4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri May 1 12:05:34 2015 -0300

    source-dialog: sort online accounts

 src/gcal-source-dialog.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c
index 52c9ffd..3b4e4fe 100644
--- a/src/gcal-source-dialog.c
+++ b/src/gcal-source-dialog.c
@@ -178,6 +178,10 @@ static void       online_accounts_listbox_row_activated (GtkListBox          *bo
                                                          GtkListBoxRow       *row,
                                                          gpointer             user_data);
 
+static gint       online_accounts_listbox_sort_func      (GtkListBoxRow       *row1,
+                                                          GtkListBoxRow       *row2,
+                                                          gpointer             user_data);
+
 static void       online_accounts_settings_button_clicked (GtkWidget         *button,
                                                           gpointer            user_data);
 
@@ -1821,6 +1825,8 @@ gcal_source_dialog_constructed (GObject *object)
                               object, NULL);
 
   gtk_list_box_set_header_func (GTK_LIST_BOX (priv->online_accounts_listbox), display_header_func, NULL, 
NULL);
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->online_accounts_listbox), (GtkListBoxSortFunc) 
online_accounts_listbox_sort_func,
+                              object, NULL);
 
   // Action group
   priv->action_group = g_simple_action_group_new ();
@@ -1942,6 +1948,27 @@ get_account_type (GoaAccount *account)
   return GCAL_ACCOUNT_TYPE_NOT_SUPPORTED;
 }
 
+static gint
+online_accounts_listbox_sort_func (GtkListBoxRow *row1,
+                                   GtkListBoxRow *row2,
+                                   gpointer       user_data)
+{
+  GoaAccount *a1 = g_object_get_data (G_OBJECT (row1), "goa-account");
+  GoaAccount *a2 = g_object_get_data (G_OBJECT (row2), "goa-account");
+  GcalAccountType t1, t2;
+
+  if (!a1 || !a2)
+    return a1 ? -1 : (a2 ? 1 : 0);
+
+  t1 = get_account_type (a1);
+  t2 = get_account_type (a2);
+
+  if (t1 != t2)
+    return t1 - t2;
+
+  return g_strcmp0 (goa_account_get_identity (a1), goa_account_get_identity (a2));
+}
+
 static void
 account_calendar_disable_changed (GObject    *object,
                                   GParamSpec *pspec,


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