Commit 8043a562 authored by Stepan Salenikovich's avatar Stepan Salenikovich

Add button to hide chat view

This allows the user to go back to the "welcome" view to be able
to copy their RingID.

Change-Id: I723e9692d2e975fb1e70c8dee7a18c589a279900
Tuleap: #417
parent 58e71073
......@@ -54,6 +54,7 @@ struct _ChatViewPrivate
GtkWidget *hbox_chat_info;
GtkWidget *label_peer;
GtkWidget *combobox_cm;
GtkWidget *button_close_chatview;
/* only one of the three following pointers should be non void;
* either this is an in-call chat (and so the in-call chat APIs will be used)
......@@ -72,6 +73,7 @@ G_DEFINE_TYPE_WITH_PRIVATE(ChatView, chat_view, GTK_TYPE_BOX);
enum {
NEW_MESSAGES_DISPLAYED,
HIDE_VIEW_CLICKED,
LAST_SIGNAL
};
......@@ -136,6 +138,12 @@ scroll_to_bottom(GtkAdjustment *adjustment, G_GNUC_UNUSED gpointer user_data)
gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment));
}
static void
hide_chat_view(G_GNUC_UNUSED GtkWidget *widget, ChatView *self)
{
g_signal_emit(G_OBJECT(self), chat_view_signals[HIDE_VIEW_CLICKED], 0);
}
static void
chat_view_init(ChatView *view)
{
......@@ -151,6 +159,8 @@ chat_view_init(ChatView *view)
* the chat treeview */
GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(priv->scrolledwindow_chat));
g_signal_connect(adjustment, "changed", G_CALLBACK(scroll_to_bottom), NULL);
g_signal_connect(priv->button_close_chatview, "clicked", G_CALLBACK(hide_chat_view), view);
}
static void
......@@ -168,6 +178,7 @@ chat_view_class_init(ChatViewClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, hbox_chat_info);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, label_peer);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, combobox_cm);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), ChatView, button_close_chatview);
chat_view_signals[NEW_MESSAGES_DISPLAYED] = g_signal_new (
"new-messages-displayed",
......@@ -178,6 +189,16 @@ chat_view_class_init(ChatViewClass *klass)
nullptr,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
chat_view_signals[HIDE_VIEW_CLICKED] = g_signal_new (
"hide-view-clicked",
G_TYPE_FROM_CLASS(klass),
(GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
0,
nullptr,
nullptr,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
static void
......
......@@ -804,10 +804,14 @@ recent_contacts_view_init(RecentContactsView *self)
auto current_proxy = RecentModel::instance().peopleProxy()->mapFromSource(current);
/* select the current */
GtkTreeIter new_iter;
if (gtk_q_sort_filter_tree_model_source_index_to_iter(recent_model, current_proxy, &new_iter)) {
gtk_tree_selection_select_iter(selection, &new_iter);
if (current.isValid()) {
/* select the current */
GtkTreeIter new_iter;
if (gtk_q_sort_filter_tree_model_source_index_to_iter(recent_model, current_proxy, &new_iter)) {
gtk_tree_selection_select_iter(selection, &new_iter);
}
} else {
gtk_tree_selection_unselect_all(selection);
}
}
);
......
......@@ -173,6 +173,15 @@ video_double_clicked(G_GNUC_UNUSED CurrentCallView *view, RingMainWindow *self)
}
}
static void
hide_view_clicked(G_GNUC_UNUSED GtkWidget *view, RingMainWindow *self)
{
g_return_if_fail(IS_RING_MAIN_WINDOW(self));
/* clear selection */
RecentModel::instance().selectionModel()->clear();
}
/**
* This takes the RecentModel index as the argument and displays the corresponding view:
* - incoming call view
......@@ -232,12 +241,14 @@ selection_changed(const QModelIndex& recent_idx, RingMainWindow *win)
} else if (type == Ring::ObjectType::Person && object.isValid()) {
/* show chat view constructed from Person object */
auto new_chat_view = chat_view_new_person(object.value<Person *>());
g_signal_connect(new_chat_view, "hide-view-clicked", G_CALLBACK(hide_view_clicked), win);
gtk_container_remove(GTK_CONTAINER(priv->frame_call), old_call_view);
gtk_container_add(GTK_CONTAINER(priv->frame_call), new_chat_view);
gtk_widget_show(new_chat_view);
} else if (type == Ring::ObjectType::ContactMethod && object.isValid()) {
/* show chat view constructed from CM */
auto new_chat_view = chat_view_new_cm(object.value<ContactMethod *>());
g_signal_connect(new_chat_view, "hide-view-clicked", G_CALLBACK(hide_view_clicked), win);
gtk_container_remove(GTK_CONTAINER(priv->frame_call), old_call_view);
gtk_container_add(GTK_CONTAINER(priv->frame_call), new_chat_view);
gtk_widget_show(new_chat_view);
......@@ -313,12 +324,14 @@ selected_item_changed(RingMainWindow *win)
if (type == Ring::ObjectType::Person && object.isValid()) {
/* show chat view constructed from Person object */
auto new_view = chat_view_new_person(object.value<Person *>());
g_signal_connect(new_view, "hide-view-clicked", G_CALLBACK(hide_view_clicked), win);
gtk_container_remove(GTK_CONTAINER(priv->frame_call), current_view);
gtk_container_add(GTK_CONTAINER(priv->frame_call), new_view);
gtk_widget_show(new_view);
} else if (type == Ring::ObjectType::ContactMethod && object.isValid()) {
/* show chat view constructed from CM */
auto new_view = chat_view_new_cm(object.value<ContactMethod *>());
g_signal_connect(new_view, "hide-view-clicked", G_CALLBACK(hide_view_clicked), win);
gtk_container_remove(GTK_CONTAINER(priv->frame_call), current_view);
gtk_container_add(GTK_CONTAINER(priv->frame_call), new_view);
gtk_widget_show(new_view);
......
......@@ -12,6 +12,18 @@
<property name="orientation">horizontal</property>
<property name="spacing">5</property>
<property name="border-width">5</property>
<child>
<object class="GtkButton" id="button_close_chatview">
<property name="image">image_back_arrow</property>
<property name="visible">True</property>
<property name="tooltip-text" translatable="yes">Hide chat view</property>
<child internal-child="accessible">
<object class="AtkObject" id="button_close_chatview-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Hide chat view</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel" id="label_peer">
<property name="visible">True</property>
......@@ -97,4 +109,9 @@
<!-- end of chat entry -->
</template>
<object class="GtkImage" id="image_back_arrow">
<property name="visible">True</property>
<property name="icon-name">go-previous-symbolic</property>
</object>
</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