mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-11-17 16:05:36 +00:00
calls-main-window: Use HdyViewSwitcher and friends
Use HdyViewSwitcher to navigate between the dial pad, call history and a contacts list. Closes #56
This commit is contained in:
parent
dbebc17dbd
commit
251e3b0076
2 changed files with 149 additions and 73 deletions
|
@ -49,8 +49,12 @@ struct _CallsMainWindow
|
||||||
GtkInfoBar *info;
|
GtkInfoBar *info;
|
||||||
GtkLabel *info_label;
|
GtkLabel *info_label;
|
||||||
|
|
||||||
|
HdySqueezer *squeezer;
|
||||||
|
GtkLabel *title_label;
|
||||||
|
HdyViewSwitcher *wide_switcher;
|
||||||
|
HdyViewSwitcher *narrow_switcher;
|
||||||
|
HdyViewSwitcherBar *switcher_bar;
|
||||||
GtkStack *main_stack;
|
GtkStack *main_stack;
|
||||||
GtkStack *header_bar_stack;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (CallsMainWindow, calls_main_window, GTK_TYPE_APPLICATION_WINDOW);
|
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 [] =
|
static const GActionEntry window_entries [] =
|
||||||
{
|
{
|
||||||
{ "about", about_action },
|
{ "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
|
static gboolean
|
||||||
show_message_timeout_cb (CallsMainWindow *self)
|
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
|
static void
|
||||||
set_property (GObject *object,
|
set_property (GObject *object,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
|
@ -264,7 +246,12 @@ constructed (GObject *object)
|
||||||
/* Add new call box */
|
/* Add new call box */
|
||||||
new_call_box = calls_new_call_box_new (self->provider);
|
new_call_box = calls_new_call_box_new (self->provider);
|
||||||
gtk_stack_add_titled (self->main_stack, GTK_WIDGET (new_call_box),
|
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 */
|
/* Add actions */
|
||||||
simple_action_group = g_simple_action_group_new ();
|
simple_action_group = g_simple_action_group_new ();
|
||||||
|
@ -277,22 +264,21 @@ constructed (GObject *object)
|
||||||
G_ACTION_GROUP (simple_action_group));
|
G_ACTION_GROUP (simple_action_group));
|
||||||
g_object_unref (simple_action_group);
|
g_object_unref (simple_action_group);
|
||||||
|
|
||||||
// FIXME: if (no history)
|
|
||||||
{
|
g_object_bind_property_full (self->squeezer,
|
||||||
new_call_action (NULL, NULL, self);
|
"visible-child",
|
||||||
}
|
self->switcher_bar,
|
||||||
|
"reveal",
|
||||||
|
G_BINDING_SYNC_CREATE,
|
||||||
|
set_switcher_bar_reveal,
|
||||||
|
NULL,
|
||||||
|
self->title_label,
|
||||||
|
NULL);
|
||||||
|
|
||||||
parent_class->constructed (object);
|
parent_class->constructed (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
calls_main_window_init (CallsMainWindow *self)
|
|
||||||
{
|
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dispose (GObject *object)
|
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
|
static void
|
||||||
calls_main_window_class_init (CallsMainWindowClass *klass)
|
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);
|
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_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_revealer);
|
||||||
gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, info);
|
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, 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, 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);
|
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>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStack" id="main_stack">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="CallsHistoryBox" id="history_view">
|
<object class="GtkStack" id="main_stack">
|
||||||
<property name="visible">True</property>
|
<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>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="name">history</property>
|
|
||||||
<property name="title" translatable="yes">History</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child type="titlebar">
|
<child type="titlebar">
|
||||||
<object class="GtkStack" id="header_bar_stack">
|
<object class="HdyHeaderBar">
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="visible_child_name" bind-source="main_stack" bind-property="visible_child_name" bind-flags="bidirectional|sync-create"/>
|
<property name="centering_policy">strict</property>
|
||||||
<child>
|
<property name="can_focus">False</property>
|
||||||
<object class="CallsHistoryHeaderBar" id="history_header_bar">
|
<property name="show_close_button">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="title">Calls</property>
|
||||||
|
<child type="title">
|
||||||
|
<object class="HdySqueezer" id="squeezer">
|
||||||
<property name="visible">True</property>
|
<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>
|
</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="visible">True</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="name">new-call</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|
Loading…
Reference in a new issue