Commit 65f1e481 authored by Bob Ham's avatar Bob Ham
Browse files

Merge branch 'view-switcher' into 'master'

calls-main-window: Use HdyViewSwitcher and friends

Closes #56

See merge request Librem5/calls!50
parents dbebc17d 251e3b00
......@@ -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,19 +264,18 @@ 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);
}
parent_class->constructed (object);
}
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);
static void
calls_main_window_init (CallsMainWindow *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
parent_class->constructed (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);
}
......@@ -67,45 +67,91 @@
</object>
</child>
<child>
<object class="GtkStack" id="main_stack">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="CallsHistoryBox" id="history_view">
<object class="GtkStack" id="main_stack">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
<property name="expand">True</property>
<child>
<object class="CallsHistoryBox" id="history_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="name">recent</property>
<property name="title" translatable="yes">Recent</property>
<property name="icon_name">document-open-recent</property>
</packing>
</child>
<child>
<object class="GtkBox" id="contacts">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="name">contacts</property>
<property name="title" translatable="yes">Contacts</property>
<property name="icon_name">system-users</property>
</packing>
</child>
</object>
</child>
<child>
<object class="HdyViewSwitcherBar" id="switcher_bar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stack">main_stack</property>
<property name="reveal">True</property>
</object>
<packing>
<property name="name">history</property>
<property name="title" translatable="yes">History</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkStack" id="header_bar_stack">
<property name="can_focus">False</property>
<object class="HdyHeaderBar">
<property name="visible">True</property>
<property name="visible_child_name" bind-source="main_stack" bind-property="visible_child_name" bind-flags="bidirectional|sync-create"/>
<child>
<object class="CallsHistoryHeaderBar" id="history_header_bar">
<property name="can_focus">False</property>
<property name="visible">True</property>
</object>
<packing>
<property name="name">history</property>
</packing>
</child>
<child>
<object class="CallsNewCallHeaderBar" id="new_call_header_bar">
<property name="can_focus">False</property>
<property name="centering_policy">strict</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
<property name="title">Calls</property>
<child type="title">
<object class="HdySqueezer" id="squeezer">
<property name="visible">True</property>
<property name="transition-type">crossfade</property>
<child>
<object class="HdyViewSwitcher" id="wide_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="policy">wide</property>
<property name="stack">main_stack</property>
</object>
</child>
<child>
<object class="HdyViewSwitcher" id="narrow_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="policy">narrow</property>
<property name="stack">main_stack</property>
</object>
</child>
<child>
<object class="GtkLabel" id="title_label">
<property name="visible">True</property>
<property name="halign">center</property>
<property name="label">Calls</property>
<style>
<class name="title"/>
</style>
</object>
</child>
</object>
<packing>
<property name="name">new-call</property>
</packing>
</child>
</object>
</child>
......
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