]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-dialpad-button.c
Reorder header inclusions accordingly to the Telepathy coding style
[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 #include "config.h"
24 #include "empathy-dialpad-button.h"
25
26 G_DEFINE_TYPE (EmpathyDialpadButton, empathy_dialpad_button, GTK_TYPE_BUTTON)
27
28 enum
29 {
30   PROP_LABEL = 1,
31   PROP_SUB_LABEL,
32   PROP_EVENT,
33   N_PROPS
34 };
35
36 /*
37 enum
38 {
39   LAST_SIGNAL
40 };
41
42 static guint signals[LAST_SIGNAL];
43 */
44
45 struct _EmpathyDialpadButtonPriv
46 {
47   gchar *label;
48   gchar *sub_label;
49   TpDTMFEvent event;
50 };
51
52 static void
53 empathy_dialpad_button_get_property (GObject *object,
54     guint property_id,
55     GValue *value,
56     GParamSpec *pspec)
57 {
58   EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
59
60   switch (property_id)
61     {
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;
74     }
75 }
76
77 static void
78 empathy_dialpad_button_set_property (GObject *object,
79     guint property_id,
80     const GValue *value,
81     GParamSpec *pspec)
82 {
83   EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
84
85   switch (property_id)
86     {
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;
101     }
102 }
103
104 static void
105 empathy_dialpad_button_constructed (GObject *object)
106 {
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;
113
114   g_assert (self->priv->label != NULL);
115   g_assert (self->priv->sub_label != NULL);
116
117   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
118
119   gtk_container_add (GTK_CONTAINER (self), vbox);
120
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);
127
128   gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 3);
129
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);
137
138   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
139
140   if (chain_up != NULL)
141     chain_up (object);
142 }
143
144 static void
145 empathy_dialpad_button_finalize (GObject *object)
146 {
147   EmpathyDialpadButton *self = EMPATHY_DIALPAD_BUTTON (object);
148   void (*chain_up) (GObject *) =
149       ((GObjectClass *) empathy_dialpad_button_parent_class)->finalize;
150
151   g_free (self->priv->label);
152   g_free (self->priv->sub_label);
153
154   if (chain_up != NULL)
155     chain_up (object);
156 }
157
158 static void
159 empathy_dialpad_button_class_init (
160     EmpathyDialpadButtonClass *klass)
161 {
162   GObjectClass *oclass = G_OBJECT_CLASS (klass);
163   GParamSpec *spec;
164
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;
169
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);
175
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);
181
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);
187
188   g_type_class_add_private (klass, sizeof (EmpathyDialpadButtonPriv));
189 }
190
191 static void
192 empathy_dialpad_button_init (EmpathyDialpadButton *self)
193 {
194   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
195       EMPATHY_TYPE_DIALPAD_BUTTON, EmpathyDialpadButtonPriv);
196 }
197
198 GtkWidget *
199 empathy_dialpad_button_new (const gchar *label,
200     const gchar *sub_label,
201     TpDTMFEvent event)
202 {
203   return g_object_new (EMPATHY_TYPE_DIALPAD_BUTTON,
204       "label", label,
205       "sub-label", sub_label,
206       "event", event,
207       NULL);
208 }
209
210 const gchar *
211 empathy_dialpad_button_get_label (EmpathyDialpadButton *self)
212 {
213   return self->priv->label;
214 }
215
216 const gchar *
217 empathy_dialpad_button_get_sub_label (EmpathyDialpadButton *self)
218 {
219   return self->priv->sub_label;
220 }
221
222 TpDTMFEvent
223 empathy_dialpad_button_get_event (EmpathyDialpadButton *self)
224 {
225   return self->priv->event;
226 }