]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-profile-chooser.c
Updatre python binding
[empathy.git] / libempathy-gtk / empathy-profile-chooser.c
index 4bc1d6c959b6f0653c4df6187cf603224c280c22..6c46b6cc56148734e79459e8a6b544b57aececb8 100644 (file)
@@ -1,21 +1,20 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
- * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007-2008 Collabora Ltd.
  *
- * 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 the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
@@ -55,6 +54,16 @@ empathy_profile_chooser_get_selected (GtkWidget *widget)
        return profile;
 }
 
+gint
+empathy_profile_chooser_n_profiles (GtkWidget *widget)
+{
+       GtkTreeModel *model;
+
+       model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+
+       return gtk_tree_model_iter_n_children (model, NULL);
+}
+
 static gint
 profile_chooser_sort_profile_value (McProfile *profile)
 {
@@ -114,6 +123,7 @@ empathy_profile_chooser_new (void)
        GtkCellRenderer *renderer;
        GtkWidget       *combo_box;
        GtkTreeIter      iter;
+       gboolean         iter_set = FALSE;
 
        /* set up combo box with new store */
        store = gtk_list_store_new (COL_COUNT,
@@ -136,15 +146,6 @@ empathy_profile_chooser_new (void)
                                        "text", COL_LABEL,
                                        NULL);
 
-       /* Set the profile sort function */
-       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
-                                             COL_PROFILE,
-                                             GTK_SORT_ASCENDING);
-       gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
-                                        COL_PROFILE,
-                                        profile_chooser_sort_func,
-                                        NULL, NULL);
-
        profiles = mc_profiles_list ();
        for (l = profiles; l; l = l->next) {
                McProfile  *profile;
@@ -160,15 +161,26 @@ empathy_profile_chooser_new (void)
                }
                g_object_unref (protocol);
 
-               gtk_list_store_append (store, &iter);
-               gtk_list_store_set (store, &iter,
-                                   COL_ICON, mc_profile_get_icon_name (profile),
-                                   COL_LABEL, mc_profile_get_display_name (profile),
-                                   COL_PROFILE, profile,
-                                   -1);
+               gtk_list_store_insert_with_values (store, &iter, 0,
+                                                  COL_ICON, mc_profile_get_icon_name (profile),
+                                                  COL_LABEL, mc_profile_get_display_name (profile),
+                                                  COL_PROFILE, profile,
+                                                  -1);
+                iter_set = TRUE;
        }
 
-       gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
+       /* Set the profile sort function */
+       gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
+                                        COL_PROFILE,
+                                        profile_chooser_sort_func,
+                                        NULL, NULL);
+       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+                                             COL_PROFILE,
+                                             GTK_SORT_ASCENDING);
+
+        if (iter_set) {
+               gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
+        }
 
        mc_profiles_free_list (profiles);
        g_object_unref (store);