]> git.0d.be Git - empathy.git/blob - libempathy-gtk/gossip-profile-chooser.c
[darcs-to-svn @ Adding salut profile]
[empathy.git] / libempathy-gtk / gossip-profile-chooser.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Xavier Claessens <xclaesse@gmail.com>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include <config.h>
22
23 #include <gtk/gtk.h>
24 #include <libmissioncontrol/mc-profile.h>
25
26 #include <libempathy-gtk/gossip-ui-utils.h>
27
28 #include "gossip-profile-chooser.h"
29
30 enum {
31         COL_ICON,
32         COL_LABEL,
33         COL_PROFILE,
34         COL_COUNT
35 };
36
37 McProfile*
38 gossip_profile_chooser_get_selected (GtkWidget *widget)
39 {
40         GtkTreeModel *model;
41         GtkTreeIter   iter;
42         McProfile    *profile = NULL;
43
44         model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
45         if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) {
46                 gtk_tree_model_get (model, &iter,
47                                     COL_PROFILE, &profile,
48                                     -1);
49         }
50
51         return profile;
52 }
53
54 GtkWidget *
55 gossip_profile_chooser_new (void)
56 {
57         GList           *profiles, *l;
58         GtkListStore    *store;
59         GtkCellRenderer *renderer;
60         GtkWidget       *combo_box;
61         GtkTreeIter      iter;
62
63         /* set up combo box with new store */
64         store = gtk_list_store_new (COL_COUNT,
65                                     GDK_TYPE_PIXBUF,  /* Icon    */
66                                     G_TYPE_STRING,    /* Label   */
67                                     MC_TYPE_PROFILE); /* Profile */
68         combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
69
70
71         renderer = gtk_cell_renderer_pixbuf_new ();
72         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, FALSE);
73         gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
74                                         "pixbuf", COL_ICON,
75                                         NULL);
76         renderer = gtk_cell_renderer_text_new ();
77         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
78         gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,
79                                         "text", COL_LABEL,
80                                         NULL);
81
82         profiles = mc_profiles_list ();
83         for (l = profiles; l; l = l->next) {
84                 McProfile *profile;
85
86                 profile = l->data;
87
88                 gtk_list_store_append (store, &iter);
89                 gtk_list_store_set (store, &iter,
90                                     COL_ICON, gossip_pixbuf_from_profile (profile, GTK_ICON_SIZE_BUTTON),
91                                     COL_LABEL, mc_profile_get_display_name (profile),
92                                     COL_PROFILE, profile,
93                                     -1);
94                 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
95         }
96
97         mc_profiles_free_list (profiles);
98         g_object_unref (store);
99
100         return combo_box;
101 }
102