~ubuntu-branches/ubuntu/maverick/ekiga/maverick

« back to all changes in this revision

Viewing changes to src/gui/dialpad.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Eugen Dedu, Eugen Dedu, Loic Minier
  • Date: 2008-09-27 10:00:00 UTC
  • mfrom: (1.1.8 upstream)
  • mto: (1.4.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20080927100000-l5k5werb6czr5b3h
Tags: 3.0.1-1
[ Eugen Dedu ]
* New version.  (Closes: #500089).
* Add our own changelog file in /usr/share/doc.
* Remove gnomemeeting transitional package.
* Discover new interfaces.  (Closes: #488199).
* Compile with dbus support.  (Closes: #467212).
* Numeric keypad inserts digits at correct position.  (Closes: #440159).
* Use libnotify upon call.  (Closes: #412604).
* Symlink identical GNOME help files, to reduce size.  (Closes: #505536).
* Explicitely build-depends on a few dev packages, even if they were
  pulled out anyway by the other dependencies.

[ Loic Minier ]
* Use clean:: instead of clean: in rules.
* Don't disable Uploaders: generation for control.in -> control generation
  in rules.
* Fix some tabs which were size 4 anyway.
* Generate a PO template during build by calling intltool-update -p in
  install; thanks Ubuntu and Martin Pitt; closes: #505535.
* Also let the -dbg depend on ${misc:Depends}.
* Cleanup rules; in particular, use dpkg-parsechangelog and honor
  distclean/clean failures, remove old clean rules, commented out stuff,
  gtk-only stuff.
* Pass -s to dh_* in binary-arch.
* Use debian/*.links and debian/*.manpages instead of symlink manually or
  passing files to dh_installman.
* Use ftp.gnome.org in copyright.
* Switch to quilt and fix target deps in the process; build-dep on quilt
  instead of dpatch; rename news.dpatch to 00_news.patch and refresh;
  replace 00list with series.
* Install autotools-dev config.guess and .sub after patching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Ekiga -- A VoIP and Video-Conferencing application
 
2
 * Copyright (C) 2000-2007 Damien Sandras
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (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
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 *
 
19
 * Ekiga is licensed under the GPL license and as a special exception,
 
20
 * you have permission to link or otherwise combine this program with the
 
21
 * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
 
22
 * without applying the requirements of the GNU GPL to the OPAL, OpenH323
 
23
 * and PWLIB programs, as long as you do follow the requirements of the
 
24
 * GNU GPL for all the rest of the software thus combined.
 
25
 */
 
26
 
 
27
/*
 
28
 *                         dialpad.cpp  -  description
 
29
 *                         ---------------------------
 
30
 *   begin                : Thu Jan 3 2008
 
31
 *   copyright            : (C) 2008 by Steve Frécinaux
 
32
 *   description          : Dial pad widget.
 
33
 */
 
34
 
 
35
#include "config.h"
 
36
#include "dialpad.h"
 
37
#include <gdk/gdkkeysyms.h>
 
38
 
 
39
#include <cstring>
 
40
#include <iostream>
 
41
 
 
42
/* Make this flag available with GTK+ 2.10 */
 
43
#ifndef G_PARAM_SPEC_STATIC_STRINGS
 
44
#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
 
45
#endif
 
46
 
 
47
struct const_key_info
 
48
{
 
49
  const char *number;
 
50
  const char *letters;
 
51
  const unsigned code;
 
52
};
 
53
 
 
54
/* Translators: the following strings are letters that stand on mobile phone
 
55
 * keys.
 
56
 */
 
57
static const struct const_key_info keys_info[] = {
 
58
  { "1", "", GDK_KP_1 },
 
59
  { "2", N_("abc"), GDK_KP_2 },
 
60
  { "3", N_("def"), GDK_KP_3 },
 
61
  { "4", N_("ghi"), GDK_KP_4 },
 
62
  { "5", N_("jkl"), GDK_KP_5 },
 
63
  { "6", N_("mno"), GDK_KP_6 },
 
64
  { "7", N_("pqrs"), GDK_KP_7 },
 
65
  { "8", N_("tuv"), GDK_KP_8 },
 
66
  { "9", N_("wxyz"), GDK_KP_9 },
 
67
  { "*", "", GDK_KP_Multiply },
 
68
  { "0", "", GDK_KP_0 },
 
69
  { "#", "", GDK_numbersign }
 
70
};
 
71
 
 
72
struct _EkigaDialpadPrivate
 
73
{
 
74
  GtkAccelGroup *accel_group;
 
75
  GtkWidget *buttons[G_N_ELEMENTS (keys_info)];
 
76
};
 
77
 
 
78
enum
 
79
{
 
80
  BUTTON_CLICKED,
 
81
  LAST_SIGNAL
 
82
};
 
83
 
 
84
static guint ekiga_dialpad_signals[LAST_SIGNAL];
 
85
 
 
86
enum
 
87
{
 
88
  PROP_0,
 
89
  PROP_ACCEL_GROUP
 
90
};
 
91
 
 
92
G_DEFINE_TYPE (EkigaDialpad, ekiga_dialpad, GTK_TYPE_TABLE);
 
93
 
 
94
static void
 
95
ekiga_dialpad_get_property (GObject    *object,
 
96
                            guint       prop_id,
 
97
                            GValue     *value,
 
98
                            GParamSpec *pspec)
 
99
{
 
100
  EkigaDialpad *dialpad = EKIGA_DIALPAD (object);
 
101
 
 
102
  switch (prop_id) {
 
103
    case PROP_ACCEL_GROUP:
 
104
      g_value_set_object (value, dialpad->priv->accel_group);
 
105
      break;
 
106
    default:
 
107
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
108
      break;
 
109
  }
 
110
}
 
111
 
 
112
static void
 
113
ekiga_dialpad_set_property (GObject      *object,
 
114
                            guint         prop_id,
 
115
                            const GValue *value,
 
116
                            GParamSpec   *pspec)
 
117
{
 
118
  EkigaDialpad *dialpad = EKIGA_DIALPAD (object);
 
119
 
 
120
  switch (prop_id) {
 
121
    case PROP_ACCEL_GROUP:
 
122
      dialpad->priv->accel_group = GTK_ACCEL_GROUP (g_value_get_object (value));
 
123
      g_object_ref (dialpad->priv->accel_group);
 
124
      break;
 
125
    default:
 
126
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
127
      break;
 
128
  }
 
129
}
 
130
 
 
131
static void
 
132
on_dialpad_button_clicked (GtkButton    *button,
 
133
                           EkigaDialpad *dialpad)
 
134
{
 
135
  unsigned i;
 
136
 
 
137
  for (i = 0; i < G_N_ELEMENTS (keys_info); i++) {
 
138
    if (GTK_WIDGET (button) == dialpad->priv->buttons[i]) {
 
139
      g_signal_emit (dialpad, ekiga_dialpad_signals[BUTTON_CLICKED], 0,
 
140
                     keys_info[i].number);
 
141
      return;
 
142
    }
 
143
  }
 
144
 
 
145
  g_return_if_reached ();
 
146
}
 
147
 
 
148
static void
 
149
ekiga_dialpad_init (EkigaDialpad *dialpad)
 
150
{
 
151
  unsigned i;
 
152
 
 
153
  dialpad->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialpad,
 
154
                                               EKIGA_TYPE_DIALPAD,
 
155
                                               EkigaDialpadPrivate);
 
156
 
 
157
  gtk_table_set_col_spacings (GTK_TABLE (dialpad), 2);
 
158
  gtk_table_set_row_spacings (GTK_TABLE (dialpad), 2);
 
159
  gtk_table_set_homogeneous (GTK_TABLE (dialpad), true);
 
160
 
 
161
  /* Create the buttons */
 
162
  for (i = 0; i < G_N_ELEMENTS (keys_info); i++) {
 
163
    GtkWidget *box;
 
164
    GtkWidget *label;
 
165
    GtkWidget *button;
 
166
    gchar *text;
 
167
    GtkWidget *alignment;
 
168
 
 
169
    box = gtk_hbox_new (FALSE, 2);
 
170
 
 
171
    label = gtk_label_new (keys_info[i].number);
 
172
    gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
 
173
    gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
 
174
 
 
175
    label = gtk_label_new (NULL);
 
176
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
 
177
 
 
178
    if (strlen (keys_info [i].letters) > 0) {
 
179
      text = g_strdup_printf ("<sub><span size=\"small\">%s</span></sub>",
 
180
                              _(keys_info [i].letters));
 
181
      gtk_label_set_markup (GTK_LABEL (label), text);
 
182
      g_free (text);
 
183
    }
 
184
    gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0);
 
185
 
 
186
    alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
 
187
    gtk_container_add (GTK_CONTAINER (alignment), box);
 
188
 
 
189
    button = gtk_button_new ();
 
190
    gtk_container_set_border_width (GTK_CONTAINER (button), 0);
 
191
    gtk_container_add (GTK_CONTAINER (button), alignment);
 
192
 
 
193
    dialpad->priv->buttons[i] = button;
 
194
 
 
195
    gtk_table_attach (GTK_TABLE (dialpad),  button,
 
196
                      i % 3, i % 3 + 1,
 
197
                      i / 3, i / 3 + 1,
 
198
                      (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
 
199
                      (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
 
200
                      0, 0);
 
201
 
 
202
    g_signal_connect (button, "clicked",
 
203
                      G_CALLBACK (on_dialpad_button_clicked), dialpad);
 
204
  }
 
205
}
 
206
 
 
207
static GObject *
 
208
ekiga_dialpad_constructor (GType                  type,
 
209
                           guint                  n_construct_properties,
 
210
                           GObjectConstructParam *construct_properties)
 
211
{
 
212
  GObjectClass *parent_class;
 
213
  EkigaDialpad *dialpad;
 
214
 
 
215
  /* Invoke parent constructor. */
 
216
  parent_class = G_OBJECT_CLASS (ekiga_dialpad_parent_class);
 
217
  dialpad = EKIGA_DIALPAD (parent_class->constructor (type,
 
218
                                                      n_construct_properties,
 
219
                                                      construct_properties));
 
220
 
 
221
  /* The construct properties have been set -> we can use them (similar to
 
222
   * object_class->construcor which was not available in gtk 2.10) */
 
223
  if (dialpad->priv->accel_group != NULL) {
 
224
    unsigned i;
 
225
    for (i = 0; i < G_N_ELEMENTS (keys_info); i++) {
 
226
      gtk_widget_add_accelerator (dialpad->priv->buttons[i],
 
227
                                  "clicked",
 
228
                                  dialpad->priv->accel_group,
 
229
                                  keys_info[i].code,
 
230
                                  (GdkModifierType) 0, (GtkAccelFlags) 0);
 
231
    }
 
232
  }
 
233
 
 
234
  return G_OBJECT (dialpad);
 
235
}
 
236
 
 
237
static void
 
238
ekiga_dialpad_finalize (GObject *object)
 
239
{
 
240
  EkigaDialpad *dialpad = EKIGA_DIALPAD (object);
 
241
 
 
242
  if (dialpad->priv->accel_group != NULL)
 
243
    g_object_unref (dialpad->priv->accel_group);
 
244
 
 
245
  G_OBJECT_CLASS (ekiga_dialpad_parent_class)->finalize (object);
 
246
}
 
247
 
 
248
static void
 
249
ekiga_dialpad_class_init (EkigaDialpadClass *klass)
 
250
{
 
251
  GType the_type = G_TYPE_FROM_CLASS (klass);
 
252
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
253
 
 
254
  object_class->constructor = ekiga_dialpad_constructor;
 
255
  object_class->finalize = ekiga_dialpad_finalize;
 
256
  object_class->get_property = ekiga_dialpad_get_property;
 
257
  object_class->set_property = ekiga_dialpad_set_property;
 
258
 
 
259
  g_object_class_install_property (object_class,
 
260
                                   PROP_ACCEL_GROUP,
 
261
                                   g_param_spec_object ("accel-group",
 
262
                                                        "Accel group",
 
263
                                                        "Accel group",
 
264
                                                        GTK_TYPE_ACCEL_GROUP,
 
265
                                                        (GParamFlags) (G_PARAM_READWRITE |
 
266
                                                                       G_PARAM_CONSTRUCT_ONLY |
 
267
                                                                       G_PARAM_STATIC_STRINGS)));
 
268
 
 
269
  ekiga_dialpad_signals[BUTTON_CLICKED] =
 
270
            g_signal_new ("button-clicked", the_type,
 
271
                          G_SIGNAL_RUN_LAST,
 
272
                          G_STRUCT_OFFSET (EkigaDialpadClass, button_clicked),
 
273
                          NULL, NULL,
 
274
                          g_cclosure_marshal_VOID__STRING,
 
275
                          G_TYPE_NONE,
 
276
                          1,
 
277
                          G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
 
278
 
 
279
  g_type_class_add_private (klass, sizeof (EkigaDialpadPrivate));
 
280
}
 
281
 
 
282
guint
 
283
ekiga_dialpad_get_button_code (EkigaDialpad * /* dialpad */,
 
284
                               char          number)
 
285
{
 
286
  unsigned i;
 
287
  for (i = 0; i < G_N_ELEMENTS (keys_info); i++)
 
288
    if (keys_info[i].number[0] == number)
 
289
      return keys_info[i].code;
 
290
  return 0;
 
291
}
 
292
 
 
293
GtkWidget *ekiga_dialpad_new (GtkAccelGroup *accel_group)
 
294
{
 
295
  gpointer obj;
 
296
 
 
297
  if (accel_group == NULL)
 
298
    obj = g_object_new (EKIGA_TYPE_DIALPAD, NULL);
 
299
  else
 
300
    obj = g_object_new (EKIGA_TYPE_DIALPAD, "accel-group", accel_group, NULL);
 
301
 
 
302
  return GTK_WIDGET (obj);
 
303
}
 
304
 
 
305
/* ex:set ts=2 sw=2 et: */