1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2013 Intel Corporation
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU Lesser General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
19 * Author: Tristan Van Berkom <tristanvb@openismus.com>
22 #include <libebook/libebook.h>
24 #include "cursor-slot.h"
27 static void cursor_slot_class_init (CursorSlotClass *klass);
28 static void cursor_slot_init (CursorSlot *slot);
30 struct _CursorSlotPrivate {
34 GtkLabel *emails_label;
35 GtkLabel *telephones_label;
38 G_DEFINE_TYPE_WITH_PRIVATE (CursorSlot, cursor_slot, GTK_TYPE_GRID);
40 /************************************************************************
42 ************************************************************************/
44 cursor_slot_class_init (CursorSlotClass *klass)
46 GtkWidgetClass *widget_class;
48 /* Bind to template */
49 widget_class = GTK_WIDGET_CLASS (klass);
50 gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/evolution/cursor-example/cursor-slot.ui");
51 gtk_widget_class_bind_template_child_private (widget_class, CursorSlot, area);
52 gtk_widget_class_bind_template_child_private (widget_class, CursorSlot, name_label);
53 gtk_widget_class_bind_template_child_private (widget_class, CursorSlot, emails_label);
54 gtk_widget_class_bind_template_child_private (widget_class, CursorSlot, telephones_label);
58 cursor_slot_init (CursorSlot *slot)
60 slot->priv = cursor_slot_get_instance_private (slot);
62 gtk_widget_init_template (GTK_WIDGET (slot));
65 /************************************************************************
67 ************************************************************************/
69 cursor_slot_new (EContact *contact)
73 slot = g_object_new (CURSOR_TYPE_SLOT, NULL);
75 cursor_slot_set_from_contact (slot, contact);
77 return (GtkWidget *)slot;
81 make_string_from_list (EContact *contact,
87 string = g_string_new ("<span size=\"x-small\">");
88 values = e_contact_get (contact, field);
90 for (l = values; l; l = l->next) {
91 gchar *value = (gchar *) l->data;
94 g_string_append (string, ", ");
96 g_string_append (string, value);
100 g_string_append (string, " - none - ");
102 e_contact_attr_list_free (values);
103 g_string_append (string, "</span>");
105 return g_string_free (string, FALSE);
109 cursor_slot_set_from_contact (CursorSlot *slot,
112 CursorSlotPrivate *priv;
113 const gchar *family_name, *given_name;
116 g_return_if_fail (CURSOR_IS_SLOT (slot));
117 g_return_if_fail (contact == NULL || E_IS_CONTACT (contact));
122 gtk_widget_hide (priv->area);
126 family_name = (const gchar *)e_contact_get_const (contact, E_CONTACT_FAMILY_NAME);
127 given_name = (const gchar *)e_contact_get_const (contact, E_CONTACT_GIVEN_NAME);
129 str = g_strdup_printf ("%s, %s", family_name, given_name);
130 gtk_label_set_text (priv->name_label, str);
133 str = make_string_from_list (contact, E_CONTACT_EMAIL);
134 gtk_label_set_markup (priv->emails_label, str);
137 str = make_string_from_list (contact, E_CONTACT_TEL);
138 gtk_label_set_markup (priv->telephones_label, str);
141 gtk_widget_show (priv->area);