Commit 1321b960 authored by Guido Gunther's avatar Guido Gunther

dialer: Remove display

An application will likely want to display it's own thing so don't hard
code it in the keypad.
parent ccb6f7a3
......@@ -11,6 +11,7 @@ struct _ExampleWindow
GtkStackSidebar *sidebar;
GtkStack *stack;
HdyDialer *dialer;
GtkLabel *display;
};
G_DEFINE_TYPE (ExampleWindow, example_window, GTK_TYPE_APPLICATION_WINDOW)
......@@ -68,27 +69,48 @@ static void
example_window_submitted_cb (GtkWidget *widget,
gchar *number)
{
g_print ("Dial %s\n", number);
g_print ("Submit %s\n", number);
}
static void
example_window_notify_number_cb (GtkWidget *widget)
number_notify_cb (ExampleWindow *self,
gpointer unused)
{
g_print ("wuff: %s\n", hdy_dialer_get_number (HDY_DIALER (widget)));
gtk_label_set_label (self->display, hdy_dialer_get_number (self->dialer));
g_print ("wuff: %s\n", hdy_dialer_get_number (self->dialer));
}
ExampleWindow *
example_window_new (GtkApplication *application)
{
return g_object_new (EXAMPLE_TYPE_WINDOW, "application", application, NULL);
}
static void
example_window_constructed (GObject *object)
{
ExampleWindow *self = EXAMPLE_WINDOW (object);
G_OBJECT_CLASS (example_window_parent_class)->constructed (object);
g_signal_connect_swapped (self->dialer,
"notify::number",
G_CALLBACK (number_notify_cb),
self);
}
static void
example_window_class_init (ExampleWindowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructed = example_window_constructed;
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/handy/example/ui/example-window.ui");
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, content_box);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, sub_header_bar);
......@@ -96,6 +118,7 @@ example_window_class_init (ExampleWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, sidebar);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, stack);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, dialer);
gtk_widget_class_bind_template_child (widget_class, ExampleWindow, display);
gtk_widget_class_bind_template_callback_full (widget_class, "key_pressed_cb", G_CALLBACK(example_window_key_pressed_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "notify_folded_cb", G_CALLBACK(example_window_notify_folded_cb));
gtk_widget_class_bind_template_callback_full (widget_class, "notify_visible_child_cb", G_CALLBACK(example_window_notify_visible_child_cb));
......
......@@ -159,14 +159,31 @@
</packing>
</child>
<child>
<object class="HdyDialer" id="dialer">
<object class="GtkBox">
<property name="visible">True</property>
<property name="expand">False</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin">12</property>
<signal name="submitted" after="yes" handler="submitted_cb"/>
<signal name="notify::number" after="yes" handler="notify_number_cb"/>
<property name="margin">18</property>
<child>
<object class="GtkLabel" id="display">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"></property>
<property name="single_line_mode">True</property>
</object>
</child>
<child>
<object class="HdyDialer" id="dialer">
<property name="visible">True</property>
<property name="expand">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin">12</property>
<signal name="submitted" after="yes" handler="submitted_cb"/>
</object>
</child>
</object>
<packing>
<property name="name">dialer</property>
......
......@@ -24,7 +24,6 @@ typedef struct
{
HdyDialerButton *btn_0, *btn_1, *btn_2, *btn_3, *btn_4, *btn_5, *btn_6, *btn_7, *btn_8, *btn_9;
HdyDialerCycleButton *btn_hash, *btn_star, *cycle_btn;
GtkLabel *display;
GtkButton *btn_submit, *btn_del;
GString *number;
} HdyDialerPrivate;
......@@ -120,15 +119,13 @@ submit_button_clicked (HdyDialer *self,
GtkButton *btn)
{
HdyDialerPrivate *priv = hdy_dialer_get_instance_private (self);
const char *number;
g_return_if_fail (HDY_IS_DIALER (self));
g_return_if_fail (GTK_IS_BUTTON (btn));
stop_cycle_mode (self);
number = gtk_label_get_label (priv->display);
g_signal_emit (self, signals[SIGNAL_SUBMITTED], 0, number);
g_signal_emit (self, signals[SIGNAL_SUBMITTED], 0, priv->number->str);
}
static void
......@@ -149,16 +146,6 @@ del_button_clicked (HdyDialer *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NUMBER]);
}
static void
update_label (HdyDialer *self,
gpointer data)
{
HdyDialerPrivate *priv = hdy_dialer_get_instance_private (self);
g_return_if_fail (HDY_IS_DIALER (self));
gtk_label_set_label (priv->display, priv->number->str);
}
static void
hdy_dialer_finalize (GObject *object)
......@@ -263,7 +250,6 @@ hdy_dialer_class_init (HdyDialerClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, HdyDialer, btn_9);
gtk_widget_class_bind_template_child_private (widget_class, HdyDialer, btn_hash);
gtk_widget_class_bind_template_child_private (widget_class, HdyDialer, btn_star);
gtk_widget_class_bind_template_child_private (widget_class, HdyDialer, display);
gtk_widget_class_bind_template_child_private (widget_class, HdyDialer, btn_submit);
gtk_widget_class_bind_template_child_private (widget_class, HdyDialer, btn_del);
}
......@@ -361,10 +347,6 @@ hdy_dialer_init (HdyDialer *self)
G_CALLBACK (del_button_clicked),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (self,
"notify::number",
G_CALLBACK (update_label),
NULL, 0);
/* In GTK+4 we can just use the icon-name property */
image = gtk_image_new_from_icon_name ("edit-clear-symbolic",
......
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated with glade 3.20.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
......@@ -17,7 +17,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
......@@ -30,7 +30,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
......@@ -43,7 +43,7 @@
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
......@@ -56,7 +56,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
......@@ -69,7 +69,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
......@@ -82,7 +82,7 @@
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
<property name="top_attach">1</property>
</packing>
</child>
......@@ -96,7 +96,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">2</property>
</packing>
</child>
......@@ -110,7 +110,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">2</property>
</packing>
</child>
......@@ -124,7 +124,7 @@
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">3</property>
<property name="top_attach">2</property>
</packing>
</child>
......@@ -138,7 +138,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="top_attach">3</property>
</packing>
</child>
......@@ -152,7 +152,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">3</property>
</packing>
</child>
......@@ -166,7 +166,7 @@
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">4</property>
<property name="top_attach">3</property>
</packing>
</child>
......@@ -183,7 +183,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
......@@ -198,22 +198,9 @@
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">5</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="display">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label"></property>
<property name="single_line_mode">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">3</property>
</packing>
</child>
</template>
</interface>
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