diff --git a/src/calls-main-window.c b/src/calls-main-window.c index b981053..fc9e7ed 100644 --- a/src/calls-main-window.c +++ b/src/calls-main-window.c @@ -49,8 +49,12 @@ struct _CallsMainWindow GtkInfoBar *info; GtkLabel *info_label; + HdySqueezer *squeezer; + GtkLabel *title_label; + HdyViewSwitcher *wide_switcher; + HdyViewSwitcher *narrow_switcher; + HdyViewSwitcherBar *switcher_bar; GtkStack *main_stack; - GtkStack *header_bar_stack; }; G_DEFINE_TYPE (CallsMainWindow, calls_main_window, GTK_TYPE_APPLICATION_WINDOW); @@ -107,46 +111,12 @@ about_action (GSimpleAction *action, } -static void -new_call_action (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - CallsMainWindow *self = user_data; - - gtk_stack_set_visible_child_name (self->header_bar_stack, "new-call"); -} - - -static void -back_action (GSimpleAction *action, - GVariant *parameter, - gpointer user_data) -{ - CallsMainWindow *self = user_data; - - gtk_stack_set_visible_child_name (self->header_bar_stack, "history"); -} - - static const GActionEntry window_entries [] = { { "about", about_action }, - { "new-call", new_call_action }, - { "back", back_action }, }; -CallsMainWindow * -calls_main_window_new (GtkApplication *application, CallsProvider *provider) -{ - return g_object_new (CALLS_TYPE_MAIN_WINDOW, - "application", application, - "provider", provider, - NULL); -} - - static gboolean show_message_timeout_cb (CallsMainWindow *self) { @@ -202,6 +172,18 @@ call_removed_cb (CallsMainWindow *self, CallsCall *call, const gchar *reason) } +static gboolean +set_switcher_bar_reveal (GBinding *binding, + const GValue *from_value, + GValue *to_value, + gpointer title_label) +{ + g_value_set_boolean (to_value, g_value_get_object (from_value) == title_label); + + return TRUE; +} + + static void set_property (GObject *object, guint property_id, @@ -264,7 +246,12 @@ constructed (GObject *object) /* Add new call box */ new_call_box = calls_new_call_box_new (self->provider); gtk_stack_add_titled (self->main_stack, GTK_WIDGET (new_call_box), - "new-call", _("New call")); + "dial-pad", _("Dial pad")); + gtk_container_child_set (GTK_CONTAINER (self->main_stack), + GTK_WIDGET (new_call_box), + "icon-name", "input-dialpad-symbolic", + NULL); + gtk_stack_set_visible_child_name (self->main_stack, "dial-pad"); /* Add actions */ simple_action_group = g_simple_action_group_new (); @@ -277,22 +264,21 @@ constructed (GObject *object) G_ACTION_GROUP (simple_action_group)); g_object_unref (simple_action_group); - // FIXME: if (no history) - { - new_call_action (NULL, NULL, self); - } + + g_object_bind_property_full (self->squeezer, + "visible-child", + self->switcher_bar, + "reveal", + G_BINDING_SYNC_CREATE, + set_switcher_bar_reveal, + NULL, + self->title_label, + NULL); parent_class->constructed (object); } -static void -calls_main_window_init (CallsMainWindow *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); -} - - static void dispose (GObject *object) { @@ -306,6 +292,24 @@ dispose (GObject *object) } +static void +size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + CallsMainWindow *self = CALLS_MAIN_WINDOW (widget); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (calls_main_window_parent_class); + + hdy_squeezer_set_child_enabled (self->squeezer, + GTK_WIDGET (self->wide_switcher), + allocation->width > 600); + hdy_squeezer_set_child_enabled (self->squeezer, + GTK_WIDGET (self->narrow_switcher), + allocation->width > 400); + + widget_class->size_allocate (widget, allocation); +} + + static void calls_main_window_class_init (CallsMainWindowClass *klass) { @@ -326,11 +330,37 @@ calls_main_window_class_init (CallsMainWindowClass *klass) g_object_class_install_properties (object_class, PROP_LAST_PROP, props); + widget_class->size_allocate = size_allocate; + gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/calls/ui/main-window.ui"); gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, info_revealer); gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, info); gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, info_label); + gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, squeezer); + gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, title_label); + gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, wide_switcher); + gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, narrow_switcher); + gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, switcher_bar); gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, main_stack); - gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, header_bar_stack); gtk_widget_class_bind_template_callback (widget_class, info_response_cb); } + + +static void +calls_main_window_init (CallsMainWindow *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + + +CallsMainWindow * +calls_main_window_new (GtkApplication *application, CallsProvider *provider) +{ + g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL); + g_return_val_if_fail (CALLS_IS_PROVIDER (provider), NULL); + + return g_object_new (CALLS_TYPE_MAIN_WINDOW, + "application", application, + "provider", provider, + NULL); +} diff --git a/src/ui/main-window.ui b/src/ui/main-window.ui index 7395b79..1f7753a 100644 --- a/src/ui/main-window.ui +++ b/src/ui/main-window.ui @@ -67,45 +67,91 @@ - + True False + vertical - + True - True + False + True + + + True + True + + + recent + Recent + document-open-recent + + + + + True + True + + + contacts + Contacts + system-users + + + + + + + True + False + main_stack + True - - history - History - - - False + True - - - - False + strict + False + True + Calls + + True + crossfade + + + True + False + center + wide + main_stack + + + + + True + False + center + narrow + main_stack + + + + + True + center + Calls + + + - - history - - - - - False - True - - - new-call -