~bcurtiswx/ubuntu/precise/empathy/3.4.2.1-0ubuntu1

« back to all changes in this revision

Viewing changes to libempathy-gtk/gossip-profile-chooser.c

  • Committer: Bazaar Package Importer
  • Author(s): Sjoerd Simons
  • Date: 2007-05-20 15:31:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070520153142-r3auwguxdgxhktqb
Tags: upstream-0.4
ImportĀ upstreamĀ versionĀ 0.4

Show diffs side-by-side

added added

removed removed

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