1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
27 #include <libmissioncontrol/mc-profile.h>
28 #include <libmissioncontrol/mc-protocol.h>
30 #include "empathy-profile-chooser.h"
31 #include "empathy-ui-utils.h"
41 empathy_profile_chooser_get_selected (GtkWidget *widget)
45 McProfile *profile = NULL;
47 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
48 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) {
49 gtk_tree_model_get (model, &iter,
50 COL_PROFILE, &profile,
58 empathy_profile_chooser_n_profiles (GtkWidget *widget)
62 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
64 return gtk_tree_model_iter_n_children (model, NULL);
68 profile_chooser_sort_profile_value (McProfile *profile)
71 const gchar *profile_name;
72 const gchar *names[] = {"jabber",
77 profile_name = mc_profile_get_unique_name (profile);
79 for (i = 0 ; names[i]; i++) {
80 if (strcmp (profile_name, names[i]) == 0) {
89 profile_chooser_sort_func (GtkTreeModel *model,
98 gtk_tree_model_get (model, iter_a,
99 COL_PROFILE, &profile_a,
101 gtk_tree_model_get (model, iter_b,
102 COL_PROFILE, &profile_b,
105 cmp = profile_chooser_sort_profile_value (profile_a);
106 cmp -= profile_chooser_sort_profile_value (profile_b);
108 cmp = strcmp (mc_profile_get_display_name (profile_a),
109 mc_profile_get_display_name (profile_b));
112 g_object_unref (profile_a);
113 g_object_unref (profile_b);
119 empathy_profile_chooser_new (void)
123 GtkCellRenderer *renderer;
124 GtkWidget *combo_box;
126 gboolean iter_set = FALSE;
128 /* set up combo box with new store */
129 store = gtk_list_store_new (COL_COUNT,
130 G_TYPE_STRING, /* Icon name */
131 G_TYPE_STRING, /* Label */
132 MC_TYPE_PROFILE); /* Profile */
133 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
136 renderer = gtk_cell_renderer_pixbuf_new ();
137 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
138 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
139 "icon-name", COL_ICON,
141 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
143 renderer = gtk_cell_renderer_text_new ();
144 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
145 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
149 profiles = mc_profiles_list ();
150 for (l = profiles; l; l = l->next) {
152 McProtocol *protocol;
156 /* Check if the CM is installed, otherwise skip that profile.
157 * Workaround SF bug #1688779 */
158 protocol = mc_profile_get_protocol (profile);
162 g_object_unref (protocol);
164 gtk_list_store_insert_with_values (store, &iter, 0,
165 COL_ICON, mc_profile_get_icon_name (profile),
166 COL_LABEL, mc_profile_get_display_name (profile),
167 COL_PROFILE, profile,
172 /* Set the profile sort function */
173 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
175 profile_chooser_sort_func,
177 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
182 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
185 mc_profiles_free_list (profiles);
186 g_object_unref (store);