Update Greek translation
[empathy-mirror.git] / libempathy-gtk / empathy-dialpad-button.c
blob792241fd8739d743a633228de303294ffd4107fb
1 /*
2 * Copyright (C) 2011-2012 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
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 General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
19 * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk>
20 * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
23 #include "config.h"
24 #include "empathy-dialpad-button.h"
26 G_DEFINE_TYPE (EmpathyDialpadButton, empathy_dialpad_button, GTK_TYPE_BUTTON)
28 enum
30 PROP_LABEL = 1,
31 PROP_SUB_LABEL,
32 PROP_EVENT,
33 N_PROPS
37 enum
39 LAST_SIGNAL
42 static guint signals[LAST_SIGNAL];
45 struct _EmpathyDialpadButtonPriv
47 gchar *label;
48 gchar *sub_label;
49 TpDTMFEvent event;
52 static void
53 empathy_dialpad_button_get_property (GObject *object,
54 guint property_id,
55 GValue *value,
56 GParamSpec *pspec)
58 EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
60 switch (property_id)
62 case PROP_LABEL:
63 g_value_set_string (value, self->priv->label);
64 break;
65 case PROP_SUB_LABEL:
66 g_value_set_string (value, self->priv->sub_label);
67 break;
68 case PROP_EVENT:
69 g_value_set_uint (value, self->priv->event);
70 break;
71 default:
72 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
73 break;
77 static void
78 empathy_dialpad_button_set_property (GObject *object,
79 guint property_id,
80 const GValue *value,
81 GParamSpec *pspec)
83 EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
85 switch (property_id)
87 case PROP_LABEL:
88 g_assert (self->priv->label == NULL); /* construct-only */
89 self->priv->label = g_value_dup_string (value);
90 break;
91 case PROP_SUB_LABEL:
92 g_assert (self->priv->sub_label == NULL); /* construct-only */
93 self->priv->sub_label = g_value_dup_string (value);
94 break;
95 case PROP_EVENT:
96 self->priv->event = g_value_get_uint (value);
97 break;
98 default:
99 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
100 break;
104 static void
105 empathy_dialpad_button_constructed (GObject *object)
107 EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
108 void (*chain_up) (GObject *) =
109 ((GObjectClass *) empathy_dialpad_button_parent_class)->constructed;
110 GtkWidget *vbox;
111 GtkWidget *label;
112 gchar *str;
114 g_assert (self->priv->label != NULL);
115 g_assert (self->priv->sub_label != NULL);
117 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
119 gtk_container_add (GTK_CONTAINER (self), vbox);
121 /* main label */
122 label = gtk_label_new ("");
123 str = g_strdup_printf ("<span size='x-large'>%s</span>",
124 self->priv->label);
125 gtk_label_set_markup (GTK_LABEL (label), str);
126 g_free (str);
128 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 3);
130 /* sub label */
131 label = gtk_label_new ("");
132 str = g_strdup_printf (
133 "<span foreground='#555555'>%s</span>",
134 self->priv->sub_label);
135 gtk_label_set_markup (GTK_LABEL (label), str);
136 g_free (str);
138 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
140 if (chain_up != NULL)
141 chain_up (object);
144 static void
145 empathy_dialpad_button_finalize (GObject *object)
147 EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
148 void (*chain_up) (GObject *) =
149 ((GObjectClass *) empathy_dialpad_button_parent_class)->finalize;
151 g_free (self->priv->label);
152 g_free (self->priv->sub_label);
154 if (chain_up != NULL)
155 chain_up (object);
158 static void
159 empathy_dialpad_button_class_init (
160 EmpathyDialpadButtonClass *klass)
162 GObjectClass *oclass = G_OBJECT_CLASS (klass);
163 GParamSpec *spec;
165 oclass->get_property = empathy_dialpad_button_get_property;
166 oclass->set_property = empathy_dialpad_button_set_property;
167 oclass->constructed = empathy_dialpad_button_constructed;
168 oclass->finalize = empathy_dialpad_button_finalize;
170 spec = g_param_spec_string ("label", "label",
171 "Label",
172 NULL,
173 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
174 g_object_class_install_property (oclass, PROP_LABEL, spec);
176 spec = g_param_spec_string ("sub-label", "sub-label",
177 "Sub-label",
178 NULL,
179 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
180 g_object_class_install_property (oclass, PROP_SUB_LABEL, spec);
182 spec = g_param_spec_uint ("event", "event",
183 "TpDTMFEvent",
184 0, TP_NUM_DTMF_EVENTS, 0,
185 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
186 g_object_class_install_property (oclass, PROP_EVENT, spec);
188 g_type_class_add_private (klass, sizeof (EmpathyDialpadButtonPriv));
191 static void
192 empathy_dialpad_button_init (EmpathyDialpadButton *self)
194 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
195 EMPATHY_TYPE_DIALPAD_BUTTON, EmpathyDialpadButtonPriv);
198 GtkWidget *
199 empathy_dialpad_button_new (const gchar *label,
200 const gchar *sub_label,
201 TpDTMFEvent event)
203 return g_object_new (EMPATHY_TYPE_DIALPAD_BUTTON,
204 "label", label,
205 "sub-label", sub_label,
206 "event", event,
207 NULL);
210 const gchar *
211 empathy_dialpad_button_get_label (EmpathyDialpadButton *self)
213 return self->priv->label;
216 const gchar *
217 empathy_dialpad_button_get_sub_label (EmpathyDialpadButton *self)
219 return self->priv->sub_label;
222 TpDTMFEvent
223 empathy_dialpad_button_get_event (EmpathyDialpadButton *self)
225 return self->priv->event;