diff options
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/Makefile.am | 2 | ||||
-rw-r--r-- | libempathy-gtk/empathy-dialpad-widget.c | 187 | ||||
-rw-r--r-- | libempathy-gtk/empathy-dialpad-widget.h | 57 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.c | 102 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.h | 5 |
5 files changed, 246 insertions, 107 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index cac2fe6f1..11a2927f8 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -51,6 +51,7 @@ libempathy_gtk_handwritten_source = \ empathy-contact-search-dialog.c \ empathy-contact-selector-dialog.c \ empathy-contact-widget.c \ + empathy-dialpad-widget.c \ empathy-geometry.c \ empathy-groups-widget.c \ empathy-individual-dialogs.c \ @@ -117,6 +118,7 @@ libempathy_gtk_headers = \ empathy-contact-search-dialog.h \ empathy-contact-selector-dialog.h \ empathy-contact-widget.h \ + empathy-dialpad-widget.h \ empathy-geometry.h \ empathy-groups-widget.h \ empathy-images.h \ diff --git a/libempathy-gtk/empathy-dialpad-widget.c b/libempathy-gtk/empathy-dialpad-widget.c new file mode 100644 index 000000000..fd93b834e --- /dev/null +++ b/libempathy-gtk/empathy-dialpad-widget.c @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk> + */ + +#include <config.h> + +#include <telepathy-glib/telepathy-glib.h> + +#include "empathy-dialpad-widget.h" + +G_DEFINE_TYPE (EmpathyDialpadWidget, empathy_dialpad_widget, GTK_TYPE_BOX); + +enum /* signals */ +{ + START_TONE, + STOP_TONE, + + NUM_SIGNALS +}; + +static guint signals[NUM_SIGNALS] = { 0, }; + +struct _EmpathyDialpadWidgetPrivate +{ + GtkWidget *entry; +}; + +static void +empathy_dialpad_widget_class_init (EmpathyDialpadWidgetClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + signals[START_TONE] = g_signal_new ("start-tone", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 1, G_TYPE_UINT); + + signals[STOP_TONE] = g_signal_new ("stop-tone", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 1, G_TYPE_UINT); + + g_type_class_add_private (gobject_class, + sizeof (EmpathyDialpadWidgetPrivate)); +} + +static gboolean +dtmf_dialpad_button_pressed_cb (GtkWidget *button, + GdkEventButton *event, + EmpathyDialpadWidget *self) +{ + GtkEntryBuffer *buffer = gtk_entry_get_buffer (GTK_ENTRY (self->priv->entry)); + TpDTMFEvent tone = GPOINTER_TO_UINT (g_object_get_data ( + G_OBJECT (button), "dtmf-value")); + const gchar *label = g_object_get_data (G_OBJECT (button), "string-value"); + + g_signal_emit (self, signals[START_TONE], 0, tone); + + gtk_entry_buffer_insert_text (buffer, -1, label, -1); + + return FALSE; +} + +static gboolean +dtmf_dialpad_button_released_cb (GtkWidget *button, + GdkEventButton *event, + EmpathyDialpadWidget *self) +{ + TpDTMFEvent tone = GPOINTER_TO_UINT (g_object_get_data ( + G_OBJECT (button), "dtmf-value")); + + g_signal_emit (self, signals[STOP_TONE], 0, tone); + + return FALSE; +} + +static void +empathy_dialpad_widget_init (EmpathyDialpadWidget *self) +{ + GtkWidget *table; + int i; + + struct { + const gchar *label; + const gchar *sublabel; + TpDTMFEvent event; + } dtmfbuttons[] = { { "1", "", TP_DTMF_EVENT_DIGIT_1 }, + { "2", "abc", TP_DTMF_EVENT_DIGIT_2 }, + { "3", "def", TP_DTMF_EVENT_DIGIT_3 }, + { "4", "ghi", TP_DTMF_EVENT_DIGIT_4 }, + { "5", "jkl", TP_DTMF_EVENT_DIGIT_5 }, + { "6", "mno", TP_DTMF_EVENT_DIGIT_6 }, + { "7", "pqrs", TP_DTMF_EVENT_DIGIT_7 }, + { "8", "tuv", TP_DTMF_EVENT_DIGIT_8 }, + { "9", "wxyz", TP_DTMF_EVENT_DIGIT_9 }, + { "#", "", TP_DTMF_EVENT_HASH }, + { "0", "", TP_DTMF_EVENT_DIGIT_0 }, + { "*", "", TP_DTMF_EVENT_ASTERISK }, + { NULL, } }; + + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_DIALPAD_WIDGET, + EmpathyDialpadWidgetPrivate); + + gtk_orientable_set_orientation (GTK_ORIENTABLE (self), + GTK_ORIENTATION_VERTICAL); + gtk_box_set_spacing (GTK_BOX (self), 3); + + self->priv->entry = gtk_entry_new (); + gtk_editable_set_editable (GTK_EDITABLE (self->priv->entry), FALSE); + + gtk_box_pack_start (GTK_BOX (self), self->priv->entry, FALSE, FALSE, 3); + + table = gtk_table_new (4, 3, TRUE); + + for (i = 0; dtmfbuttons[i].label != NULL; i++) + { + GtkWidget *vbox = gtk_vbox_new (FALSE, 0); + GtkWidget *button = gtk_button_new (); + GtkWidget *label; + gchar *str; + + gtk_container_add (GTK_CONTAINER (button), vbox); + + /* main label */ + label = gtk_label_new (""); + str = g_strdup_printf ("<span size='x-large'>%s</span>", + dtmfbuttons[i].label); + gtk_label_set_markup (GTK_LABEL (label), str); + g_free (str); + + gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 3); + + /* sub label */ + label = gtk_label_new (""); + str = g_strdup_printf ( + "<span foreground='#555555'>%s</span>", + dtmfbuttons[i].sublabel); + gtk_label_set_markup (GTK_LABEL (label), str); + g_free (str); + + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0); + + gtk_table_attach (GTK_TABLE (table), button, i % 3, i % 3 + 1, + i / 3, i / 3 + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1); + + g_object_set_data (G_OBJECT (button), "dtmf-value", + GUINT_TO_POINTER (dtmfbuttons[i].event)); + g_object_set_data (G_OBJECT (button), "string-value", + (gpointer) dtmfbuttons[i].label); + + g_signal_connect (G_OBJECT (button), "button-press-event", + G_CALLBACK (dtmf_dialpad_button_pressed_cb), self); + g_signal_connect (G_OBJECT (button), "button-release-event", + G_CALLBACK (dtmf_dialpad_button_released_cb), self); + } + + gtk_box_pack_start (GTK_BOX (self), table, FALSE, FALSE, 3); +} + +GtkWidget * +empathy_dialpad_widget_new (void) +{ + return g_object_new (EMPATHY_TYPE_DIALPAD_WIDGET, NULL); +} diff --git a/libempathy-gtk/empathy-dialpad-widget.h b/libempathy-gtk/empathy-dialpad-widget.h new file mode 100644 index 000000000..f4cb83052 --- /dev/null +++ b/libempathy-gtk/empathy-dialpad-widget.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Danielle Madeley <danielle.madeley@collabora.co.uk> + */ + +#ifndef __EMPATHY_DIALPAD_WIDGET_H__ +#define __EMPATHY_DIALPAD_WIDGET_H__ + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_DIALPAD_WIDGET (empathy_dialpad_widget_get_type ()) +#define EMPATHY_DIALPAD_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_DIALPAD_WIDGET, EmpathyDialpadWidget)) +#define EMPATHY_DIALPAD_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), EMPATHY_TYPE_DIALPAD_WIDGET, EmpathyDialpadWidgetClass)) +#define EMPATHY_IS_DIALPAD_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_DIALPAD_WIDGET)) +#define EMPATHY_IS_DIALPAD_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), EMPATHY_TYPE_DIALPAD_WIDGET)) +#define EMPATHY_DIALPAD_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_DIALPAD_WIDGET, EmpathyDialpadWidgetClass)) + +typedef struct _EmpathyDialpadWidget EmpathyDialpadWidget; +typedef struct _EmpathyDialpadWidgetClass EmpathyDialpadWidgetClass; +typedef struct _EmpathyDialpadWidgetPrivate EmpathyDialpadWidgetPrivate; + +struct _EmpathyDialpadWidget +{ + GtkBox parent; + + EmpathyDialpadWidgetPrivate *priv; +}; + +struct _EmpathyDialpadWidgetClass +{ + GtkBoxClass parent_class; +}; + +GType empathy_dialpad_widget_get_type (void); +GtkWidget *empathy_dialpad_widget_new (void); + +G_END_DECLS + +#endif diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index 32ad451a1..b52d9ef94 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -2099,108 +2099,6 @@ empathy_individual_match_string (FolksIndividual *individual, return retval; } -static gboolean -dtmf_dialpad_button_pressed_cb (GObject *button, - GtkEntry *entry) -{ - GtkEntryBuffer *buffer = gtk_entry_get_buffer (entry); - const gchar *label; - - label = g_object_get_data (button, "label"); - gtk_entry_buffer_insert_text (buffer, -1, label, -1); - - return FALSE; -} - -GtkWidget * -empathy_create_dtmf_dialpad (GObject *self, - GCallback dtmf_button_pressed_cb, - GCallback dtmf_button_released_cb) -{ - GtkWidget *box, *entry, *table; - int i; - GQuark button_quark; - struct { - const gchar *label; - const gchar *sublabel; - TpDTMFEvent event; - } dtmfbuttons[] = { { "1", "", TP_DTMF_EVENT_DIGIT_1 }, - { "2", "abc", TP_DTMF_EVENT_DIGIT_2 }, - { "3", "def", TP_DTMF_EVENT_DIGIT_3 }, - { "4", "ghi", TP_DTMF_EVENT_DIGIT_4 }, - { "5", "jkl", TP_DTMF_EVENT_DIGIT_5 }, - { "6", "mno", TP_DTMF_EVENT_DIGIT_6 }, - { "7", "pqrs", TP_DTMF_EVENT_DIGIT_7 }, - { "8", "tuv", TP_DTMF_EVENT_DIGIT_8 }, - { "9", "wxyz", TP_DTMF_EVENT_DIGIT_9 }, - { "#", "", TP_DTMF_EVENT_HASH }, - { "0", "", TP_DTMF_EVENT_DIGIT_0 }, - { "*", "", TP_DTMF_EVENT_ASTERISK }, - { NULL, } }; - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3); - - entry = gtk_entry_new (); - gtk_editable_set_editable (GTK_EDITABLE (entry), FALSE); - - gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 3); - - button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID); - - table = gtk_table_new (4, 3, TRUE); - - for (i = 0; dtmfbuttons[i].label != NULL; i++) - { - GtkWidget *vbox = gtk_vbox_new (FALSE, 0); - GtkWidget *button = gtk_button_new (); - GtkWidget *label; - gchar *str; - - gtk_container_add (GTK_CONTAINER (button), vbox); - - /* main label */ - label = gtk_label_new (""); - str = g_strdup_printf ("<span size='x-large'>%s</span>", - dtmfbuttons[i].label); - gtk_label_set_markup (GTK_LABEL (label), str); - g_free (str); - - g_object_set_data (G_OBJECT (button), "label", - (gpointer) dtmfbuttons[i].label); - - gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 3); - - /* sub label */ - label = gtk_label_new (""); - str = g_strdup_printf ( - "<span foreground='#555555'>%s</span>", - dtmfbuttons[i].sublabel); - gtk_label_set_markup (GTK_LABEL (label), str); - g_free (str); - - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0); - - gtk_table_attach (GTK_TABLE (table), button, i % 3, i % 3 + 1, - i/3, i/3 + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1); - - g_object_set_qdata (G_OBJECT (button), button_quark, - GUINT_TO_POINTER (dtmfbuttons[i].event)); - - /* To update the GtkEntry */ - g_signal_connect (G_OBJECT (button), "pressed", - G_CALLBACK (dtmf_dialpad_button_pressed_cb), entry); - - g_signal_connect (G_OBJECT (button), "pressed", - dtmf_button_pressed_cb, self); - g_signal_connect (G_OBJECT (button), "released", - dtmf_button_released_cb, self); - } - - gtk_box_pack_start (GTK_BOX (box), table, FALSE, FALSE, 3); - - return box; -} - void empathy_launch_program (const gchar *dir, const gchar *name, diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index b65206bbe..f76b7491b 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -49,8 +49,6 @@ G_BEGIN_DECLS (x) < gdk_screen_width () && \ (y) < gdk_screen_height ()) -#define EMPATHY_DTMF_BUTTON_ID "empathy-call-dtmf-button-id" - typedef void (*EmpathyPixbufAvatarFromIndividualCb) (FolksIndividual *individual, GdkPixbuf *pixbuf, gpointer user_data); @@ -143,9 +141,6 @@ void empathy_send_file_from_uri_list (EmpathyContact *conta const gchar *uri_list); void empathy_send_file_with_file_chooser (EmpathyContact *contact); void empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler); -GtkWidget * empathy_create_dtmf_dialpad (GObject *self, - GCallback pressed_cb, - GCallback released_cb); /* Misc */ void empathy_make_color_whiter (GdkRGBA *color); |