Commit 378de489 authored by Tristan Matthews's avatar Tristan Matthews

* #6892: simplify, fix leaks in dialpad

parent d5e607c1
......@@ -36,82 +36,55 @@
* button pressed event
*/
static void
dialpad_pressed (GtkWidget * widget UNUSED, gpointer data)
dialpad_pressed(GtkWidget * widget UNUSED, gpointer data)
{
gtk_widget_grab_focus (GTK_WIDGET (current_calls->view));
sflphone_keypad (0, (gchar*) data);
gtk_widget_grab_focus(GTK_WIDGET(current_calls->view));
sflphone_keypad(0, (gchar*) data);
}
GtkWidget *
get_numpad_button (const gchar* number, gboolean twolines, const gchar * letters)
get_numpad_button(const gchar* number, gboolean twolines, const gchar * letters)
{
GtkWidget * button;
GtkWidget * label;
gchar * markup;
button = gtk_button_new ();
label = gtk_label_new ("1");
gtk_label_set_single_line_mode (GTK_LABEL (label), FALSE);
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
markup = g_markup_printf_escaped ("<big><b>%s</b></big>%s%s", number, (twolines == TRUE ? "\n": ""), letters);
gtk_label_set_markup (GTK_LABEL (label), markup);
gtk_container_add (GTK_CONTAINER (button), label);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (dialpad_pressed), (gchar*) number);
GtkWidget *button = gtk_button_new();
GtkWidget *label = gtk_label_new("1");
gtk_label_set_single_line_mode(GTK_LABEL(label), FALSE);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
gchar *markup = g_markup_printf_escaped("<big><b>%s</b></big>%s%s", number,(twolines == TRUE ? "\n": ""), letters);
gtk_label_set_markup(GTK_LABEL(label), markup);
gtk_container_add(GTK_CONTAINER(button), label);
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(dialpad_pressed),(gchar*) number);
g_free(markup);
return button;
}
GtkWidget *
create_dialpad()
{
GtkWidget * button;
GtkWidget * table;
table = gtk_table_new (4, 3, TRUE /* homogeneous */);
gtk_table_set_row_spacings (GTK_TABLE (table), 5);
gtk_table_set_col_spacings (GTK_TABLE (table), 5);
gtk_container_set_border_width (GTK_CONTAINER (table), 5);
button = get_numpad_button ("1", TRUE, "");
gtk_table_attach (GTK_TABLE (table), button, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("2", TRUE, "a b c");
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("3", TRUE, "d e f");
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("4", TRUE, "g h i");
gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("5", TRUE, "j k l");
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("6", TRUE, "m n o");
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("7", TRUE, "p q r s");
gtk_table_attach (GTK_TABLE (table), button, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("8", TRUE, "t u v");
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("9", TRUE, "w x y z");
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("*", FALSE, "");
gtk_table_attach (GTK_TABLE (table), button, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("0", FALSE, "");
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
button = get_numpad_button ("#", FALSE, "");
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
static const gchar * const key_strings[] = {"1", "",
"2", "a b c",
"3", "d e f",
"4", "g h i",
"5", "j k l",
"6", "m n o",
"7", "p q r s",
"8", "t u v",
"9", "w x y z",
"*", "",
"0", "",
"#", ""};
enum {ROWS = 4, COLS = 3};
GtkWidget *table = gtk_table_new(ROWS, COLS, TRUE /* homogeneous */);
gtk_table_set_row_spacings(GTK_TABLE(table), 5);
gtk_table_set_col_spacings(GTK_TABLE(table), 5);
gtk_container_set_border_width(GTK_CONTAINER(table), 5);
for (int row = 0, entry = 0; row != ROWS; ++row)
for (int col = 0; col != COLS; ++col) {
GtkWidget *button = get_numpad_button(key_strings[entry], TRUE, key_strings[entry + 1]);
gtk_table_attach(GTK_TABLE(table), button, col, col + 1, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
entry += 2;
}
return table;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment