]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-dialpad-button.c
UOA: Do not segfault when "Done" or "Cancel" button clicked but widget is not ready yet
[empathy.git] / libempathy-gtk / empathy-dialpad-button.c
1 /*
2  * Copyright (C) 2011-2012 Collabora Ltd.
3  *
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.
8  *
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.
13  *
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
18  *
19  * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk>
20  *          Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
21  */
22
23
24 #include "config.h"
25
26 #include "empathy-dialpad-button.h"
27
28 G_DEFINE_TYPE (EmpathyDialpadButton, empathy_dialpad_button, GTK_TYPE_BUTTON)
29
30 enum
31 {
32   PROP_LABEL = 1,
33   PROP_SUB_LABEL,
34   PROP_EVENT,
35   N_PROPS
36 };
37
38 /*
39 enum
40 {
41   LAST_SIGNAL
42 };
43
44 static guint signals[LAST_SIGNAL];
45 */
46
47 struct _EmpathyDialpadButtonPriv
48 {
49   gchar *label;
50   gchar *sub_label;
51   TpDTMFEvent event;
52 };
53
54 static void
55 empathy_dialpad_button_get_property (GObject *object,
56     guint property_id,
57     GValue *value,
58     GParamSpec *pspec)
59 {
60   EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
61
62   switch (property_id)
63     {
64       case PROP_LABEL:
65         g_value_set_string (value, self->priv->label);
66         break;
67       case PROP_SUB_LABEL:
68         g_value_set_string (value, self->priv->sub_label);
69         break;
70       case PROP_EVENT:
71         g_value_set_uint (value, self->priv->event);
72         break;
73       default:
74         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
75         break;
76     }
77 }
78
79 static void
80 empathy_dialpad_button_set_property (GObject *object,
81     guint property_id,
82     const GValue *value,
83     GParamSpec *pspec)
84 {
85   EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
86
87   switch (property_id)
88     {
89       case PROP_LABEL:
90         g_assert (self->priv->label == NULL); /* construct-only */
91         self->priv->label = g_value_dup_string (value);
92         break;
93       case PROP_SUB_LABEL:
94         g_assert (self->priv->sub_label == NULL); /* construct-only */
95         self->priv->sub_label = g_value_dup_string (value);
96         break;
97       case PROP_EVENT:
98         self->priv->event = g_value_get_uint (value);
99         break;
100       default:
101         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
102         break;
103     }
104 }
105
106 static void
107 empathy_dialpad_button_constructed (GObject *object)
108 {
109   EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
110   void (*chain_up) (GObject *) =
111       ((GObjectClass *) empathy_dialpad_button_parent_class)->constructed;
112   GtkWidget *vbox;
113   GtkWidget *label;
114   gchar *str;
115
116   g_assert (self->priv->label != NULL);
117   g_assert (self->priv->sub_label != NULL);
118
119   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
120
121   gtk_container_add (GTK_CONTAINER (self), vbox);
122
123   /* main label */
124   label = gtk_label_new ("");
125   str = g_strdup_printf ("<span size='x-large'>%s</span>",
126       self->priv->label);
127   gtk_label_set_markup (GTK_LABEL (label), str);
128   g_free (str);
129
130   gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 3);
131
132   /* sub label */
133   label = gtk_label_new ("");
134   str = g_strdup_printf (
135       "<span foreground='#555555'>%s</span>",
136       self->priv->sub_label);
137   gtk_label_set_markup (GTK_LABEL (label), str);
138   g_free (str);
139
140   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
141
142   if (chain_up != NULL)
143     chain_up (object);
144 }
145
146 static void
147 empathy_dialpad_button_finalize (GObject *object)
148 {
149   EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
150   void (*chain_up) (GObject *) =
151       ((GObjectClass *) empathy_dialpad_button_parent_class)->finalize;
152
153   g_free (self->priv->label);
154   g_free (self->priv->sub_label);
155
156   if (chain_up != NULL)
157     chain_up (object);
158 }
159
160 static void
161 empathy_dialpad_button_class_init (
162     EmpathyDialpadButtonClass *klass)
163 {
164   GObjectClass *oclass = G_OBJECT_CLASS (klass);
165   GParamSpec *spec;
166
167   oclass->get_property = empathy_dialpad_button_get_property;
168   oclass->set_property = empathy_dialpad_button_set_property;
169   oclass->constructed = empathy_dialpad_button_constructed;
170   oclass->finalize = empathy_dialpad_button_finalize;
171
172   spec = g_param_spec_string ("label", "label",
173       "Label",
174       NULL,
175       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
176   g_object_class_install_property (oclass, PROP_LABEL, spec);
177
178   spec = g_param_spec_string ("sub-label", "sub-label",
179       "Sub-label",
180       NULL,
181       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
182   g_object_class_install_property (oclass, PROP_SUB_LABEL, spec);
183
184   spec = g_param_spec_uint ("event", "event",
185       "TpDTMFEvent",
186       0, TP_NUM_DTMF_EVENTS, 0,
187       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
188   g_object_class_install_property (oclass, PROP_EVENT, spec);
189
190   g_type_class_add_private (klass, sizeof (EmpathyDialpadButtonPriv));
191 }
192
193 static void
194 empathy_dialpad_button_init (EmpathyDialpadButton *self)
195 {
196   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
197       EMPATHY_TYPE_DIALPAD_BUTTON, EmpathyDialpadButtonPriv);
198 }
199
200 GtkWidget *
201 empathy_dialpad_button_new (const gchar *label,
202     const gchar *sub_label,
203     TpDTMFEvent event)
204 {
205   return g_object_new (EMPATHY_TYPE_DIALPAD_BUTTON,
206       "label", label,
207       "sub-label", sub_label,
208       "event", event,
209       NULL);
210 }
211
212 const gchar *
213 empathy_dialpad_button_get_label (EmpathyDialpadButton *self)
214 {
215   return self->priv->label;
216 }
217
218 const gchar *
219 empathy_dialpad_button_get_sub_label (EmpathyDialpadButton *self)
220 {
221   return self->priv->sub_label;
222 }
223
224 TpDTMFEvent
225 empathy_dialpad_button_get_event (EmpathyDialpadButton *self)
226 {
227   return self->priv->event;
228 }