Commit fbf60410 authored by Guido Gunther's avatar Guido Gunther

dialer: Make it simple to clear the stored number

This also makes sure we don't send multiple number changed events
when nothing changed.
parent 36bb094c
......@@ -436,6 +436,27 @@ hdy_dialer_set_number (HdyDialer *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NUMBER]);
}
/**
* hdy_dialer_clear_number:
* @self: a #HdyDialer
*
* Set the current number to the empty string. When the number is already
* cleared no action is performed.
*
*/
void
hdy_dialer_clear_number (HdyDialer *self)
{
HdyDialerPrivate *priv;
g_return_if_fail (HDY_IS_DIALER (self));
priv = hdy_dialer_get_instance_private (self);
if (g_strcmp0(priv->number->str, "")) {
hdy_dialer_set_number (self, "");
}
}
/**
* hdy_dialer_get_show_action_buttons:
* @self: a #HdyDialer
......
......@@ -38,6 +38,8 @@ GtkWidget *hdy_dialer_new (void);
const gchar *hdy_dialer_get_number (HdyDialer *self);
void hdy_dialer_set_number (HdyDialer *self,
const char *number);
void hdy_dialer_clear_number (HdyDialer *self);
gboolean hdy_dialer_get_show_action_buttons (HdyDialer *self);
void hdy_dialer_set_show_action_buttons (HdyDialer *self,
gboolean show);
......
......@@ -22,6 +22,7 @@ test_hdy_dialer_setnumber(void)
{
GtkWidget *dialer;
notified = 0;
dialer = hdy_dialer_new();
g_signal_connect (dialer, "notify::number", G_CALLBACK (notify_cb), NULL);
......@@ -44,6 +45,29 @@ test_hdy_dialer_setnumber(void)
}
static void
test_hdy_dialer_clear_number(void)
{
GtkWidget *dialer;
notified = 0;
dialer = hdy_dialer_new();
g_signal_connect (dialer, "notify::number", G_CALLBACK (notify_cb), NULL);
g_assert_cmpstr("", ==, hdy_dialer_get_number(HDY_DIALER (dialer)));
hdy_dialer_clear_number (HDY_DIALER (dialer));
g_assert_cmpint(0, ==, notified);
hdy_dialer_set_number(HDY_DIALER (dialer), "#1234");
g_assert_cmpstr("#1234", ==, hdy_dialer_get_number(HDY_DIALER (dialer)));
g_assert_cmpint(1, ==, notified);
hdy_dialer_clear_number (HDY_DIALER (dialer));
g_assert_cmpint(2, ==, notified);
hdy_dialer_clear_number (HDY_DIALER (dialer));
g_assert_cmpint(2, ==, notified);
}
gint
main (gint argc,
gchar *argv[])
......@@ -51,5 +75,6 @@ main (gint argc,
gtk_test_init (&argc, &argv, NULL);
g_test_add_func("/Handy/Dialer/setnumber", test_hdy_dialer_setnumber);
g_test_add_func("/Handy/Dialer/clear_number", test_hdy_dialer_clear_number);
return g_test_run();
}
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