[empathy: 1/3] Move dialpad into a widget of its own
- From: Danielle Madeley <daniellem src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy: 1/3] Move dialpad into a widget of its own
- Date: Wed, 19 Oct 2011 22:19:49 +0000 (UTC)
commit c68091255ef12850aade51ce317292179515377f
Author: Danielle Madeley <danielle madeley collabora co uk>
Date: Wed Oct 19 16:40:22 2011 +1100
Move dialpad into a widget of its own
Let's face it, the whole thing was getting a little unwieldly there in the
UI utils, and if we're going to be using it in more places, let's start by
abstracting it into a widget.
libempathy-gtk/Makefile.am | 2 +
libempathy-gtk/empathy-dialpad-widget.c | 187 +++++++++++++++++++++++++++++++
libempathy-gtk/empathy-dialpad-widget.h | 57 ++++++++++
libempathy-gtk/empathy-ui-utils.c | 102 -----------------
libempathy-gtk/empathy-ui-utils.h | 5 -
src/empathy-call-window.c | 23 +---
src/empathy-streamed-media-window.c | 23 ++--
7 files changed, 264 insertions(+), 135 deletions(-)
---
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index cac2fe6..11a2927 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 0000000..fd93b83
--- /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 0000000..f4cb830
--- /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 32ad451..b52d9ef 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 b65206b..f76b749 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);
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index 2a92e94..d2e32a1 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -47,6 +47,7 @@
#include <libempathy/empathy-utils.h>
#include <libempathy-gtk/empathy-avatar-image.h>
+#include <libempathy-gtk/empathy-dialpad-widget.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include <libempathy-gtk/empathy-sound-manager.h>
#include <libempathy-gtk/empathy-geometry.h>
@@ -397,29 +398,17 @@ empathy_call_window_tones_stopped_cb (TpChannel *proxy,
}
static void
-dtmf_button_pressed_cb (GtkButton *button,
+dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
+ TpDTMFEvent event,
EmpathyCallWindow *self)
{
EmpathyCallWindowPriv *priv = GET_PRIV (self);
- GQuark button_quark;
- TpDTMFEvent event;
-
- button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
- event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
- button_quark));
g_string_append_c (priv->tones, tp_dtmf_event_to_char (event));
empathy_call_window_maybe_emit_tones (self);
}
-/* empathy_create_dtmf_dialpad() requires a callback, even if empty */
-static void
-dtmf_button_released_cb (GtkButton *button,
- EmpathyCallWindow *self)
-{
-}
-
static void
empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
{
@@ -1819,9 +1808,9 @@ empathy_call_window_init (EmpathyCallWindow *self)
/* The call will be started as soon the pipeline is playing */
priv->start_call_when_playing = TRUE;
- priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
- G_CALLBACK (dtmf_button_pressed_cb),
- G_CALLBACK (dtmf_button_released_cb));
+ priv->dtmf_panel = empathy_dialpad_widget_new ();
+ g_signal_connect (priv->dtmf_panel, "start-tone",
+ G_CALLBACK (dtmf_start_tone_cb), self);
priv->tones = g_string_new ("");
diff --git a/src/empathy-streamed-media-window.c b/src/empathy-streamed-media-window.c
index 26bd689..27d2884 100644
--- a/src/empathy-streamed-media-window.c
+++ b/src/empathy-streamed-media-window.c
@@ -38,6 +38,7 @@
#include <libempathy/empathy-tp-contact-factory.h>
#include <libempathy/empathy-utils.h>
#include <libempathy-gtk/empathy-avatar-image.h>
+#include <libempathy-gtk/empathy-dialpad-widget.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include <libempathy-gtk/empathy-sound-manager.h>
#include <libempathy-gtk/empathy-geometry.h>
@@ -335,26 +336,24 @@ empathy_streamed_media_window_setup_toolbar (EmpathyStreamedMediaWindow *self)
}
static void
-dtmf_button_pressed_cb (GtkButton *button, EmpathyStreamedMediaWindow *window)
+dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
+ TpDTMFEvent event,
+ EmpathyStreamedMediaWindow *window)
{
EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
EmpathyTpStreamedMedia *call;
- GQuark button_quark;
- TpDTMFEvent event;
g_object_get (priv->handler, "tp-call", &call, NULL);
- button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
- event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
- button_quark));
-
empathy_tp_streamed_media_start_tone (call, event);
g_object_unref (call);
}
static void
-dtmf_button_released_cb (GtkButton *button, EmpathyStreamedMediaWindow *window)
+dtmf_stop_tone_cb (EmpathyDialpadWidget *self,
+ TpDTMFEvent event,
+ EmpathyStreamedMediaWindow *window)
{
EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
EmpathyTpStreamedMedia *call;
@@ -1133,9 +1132,11 @@ empathy_streamed_media_window_init (EmpathyStreamedMediaWindow *self)
ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
_("Video input"), page);
- priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
- G_CALLBACK (dtmf_button_pressed_cb),
- G_CALLBACK (dtmf_button_released_cb));
+ priv->dtmf_panel = empathy_dialpad_widget_new ();
+ g_signal_connect (priv->dtmf_panel, "start-tone",
+ G_CALLBACK (dtmf_start_tone_cb), self);
+ g_signal_connect (priv->dtmf_panel, "stop-tone",
+ G_CALLBACK (dtmf_stop_tone_cb), self);
ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
_("Dialpad"), priv->dtmf_panel);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]