1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program 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 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
26 #include <libmissioncontrol/mc-profile.h>
28 #include "empathy-profile-chooser.h"
29 #include "empathy-ui-utils.h"
39 empathy_profile_chooser_get_selected (GtkWidget *widget)
43 McProfile *profile = NULL;
45 model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
46 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) {
47 gtk_tree_model_get (model, &iter,
48 COL_PROFILE, &profile,
56 profile_chooser_sort_protocol_value (const gchar *protocol_name)
58 if (strcmp (protocol_name, "jabber") == 0) {
61 else if (strcmp (protocol_name, "salut") == 0) {
69 profile_chooser_sort_func (GtkTreeModel *model,
80 gtk_tree_model_get (model, iter_a,
81 COL_PROFILE, &profile_a,
83 gtk_tree_model_get (model, iter_b,
84 COL_PROFILE, &profile_b,
87 proto_a = mc_profile_get_protocol_name (profile_a);
88 proto_b = mc_profile_get_protocol_name (profile_b);
89 cmp = profile_chooser_sort_protocol_value (proto_a);
90 cmp -= profile_chooser_sort_protocol_value (proto_b);
92 cmp = strcmp (mc_profile_get_display_name (profile_a),
93 mc_profile_get_display_name (profile_b));
96 g_object_unref (profile_a);
97 g_object_unref (profile_b);
103 empathy_profile_chooser_new (void)
107 GtkCellRenderer *renderer;
108 GtkWidget *combo_box;
111 /* set up combo box with new store */
112 store = gtk_list_store_new (COL_COUNT,
113 G_TYPE_STRING, /* Icon name */
114 G_TYPE_STRING, /* Label */
115 MC_TYPE_PROFILE); /* Profile */
116 combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
119 renderer = gtk_cell_renderer_pixbuf_new ();
120 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
121 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
122 "icon-name", COL_ICON,
124 g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
126 renderer = gtk_cell_renderer_text_new ();
127 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
128 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
132 /* Set the profile sort function */
133 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
136 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
138 profile_chooser_sort_func,
141 profiles = mc_profiles_list ();
142 for (l = profiles; l; l = l->next) {
147 gtk_list_store_append (store, &iter);
148 gtk_list_store_set (store, &iter,
149 COL_ICON, mc_profile_get_icon_name (profile),
150 COL_LABEL, mc_profile_get_display_name (profile),
151 COL_PROFILE, profile,
155 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
157 mc_profiles_free_list (profiles);
158 g_object_unref (store);