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

* #6892: simplify, fix leaks in dialpad

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