Commit 09e0b784 authored by Stepan Salenikovich's avatar Stepan Salenikovich Committed by gerrit2

show chat/call view from selection in history and contacts

Previoiusly, the chat/call view displayed could only be changed by
changing the selection in the converstaions list view. The contacts
and history list views would only change the call view if a new
call was initiated by double clicking on the selection.

This patch changes this behaviour, now slecting an item in any of
the three contact list views will result in showing the chat view
with that Person or ContactMethod, or showing the call view if there
is an ongoing call with the selected item.

In order to prevent conflicts between different selections in the
different views, only one selection at a time is allowed. So,
changing the selection in the conversations view, for example, will
clear the selection in the other 2 list views except in the case
that the item selected is the same one. For example, if the Person
selected in the Contacts view is the same as the one in the
Conversations view, then both selections will remain.

Change-Id: Icc00c5801e66ca0013b730d6d008ebf904a999e1
Tuleap: #956
parent fc79fc13
......@@ -478,3 +478,30 @@ chat_view_new_person(Person *p)
return (GtkWidget *)self;
}
Call*
chat_view_get_call(ChatView *self)
{
g_return_val_if_fail(IS_CHAT_VIEW(self), nullptr);
auto priv = CHAT_VIEW_GET_PRIVATE(self);
return priv->call;
}
ContactMethod*
chat_view_get_cm(ChatView *self)
{
g_return_val_if_fail(IS_CHAT_VIEW(self), nullptr);
auto priv = CHAT_VIEW_GET_PRIVATE(self);
return priv->cm;
}
Person*
chat_view_get_person(ChatView *self)
{
g_return_val_if_fail(IS_CHAT_VIEW(self), nullptr);
auto priv = CHAT_VIEW_GET_PRIVATE(self);
return priv->person;
}
......@@ -38,10 +38,13 @@ typedef struct _ChatView ChatView;
typedef struct _ChatViewClass ChatViewClass;
GType chat_view_get_type (void) G_GNUC_CONST;
GtkWidget *chat_view_new_call (Call* call);
GtkWidget *chat_view_new_cm (ContactMethod* cm);
GtkWidget *chat_view_new_person (Person* p);
GType chat_view_get_type (void) G_GNUC_CONST;
GtkWidget *chat_view_new_call (Call*);
GtkWidget *chat_view_new_cm (ContactMethod*);
GtkWidget *chat_view_new_person (Person* p);
Call *chat_view_get_call (ChatView*);
ContactMethod *chat_view_get_cm (ChatView*);
Person *chat_view_get_person (ChatView*);
G_END_DECLS
......
......@@ -525,12 +525,6 @@ current_call_view_class_init(CurrentCallViewClass *klass)
G_TYPE_NONE, 0);
}
GtkWidget *
current_call_view_new(void)
{
return (GtkWidget *)g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
}
static void
update_state(CurrentCallView *view, Call *call)
{
......@@ -639,11 +633,11 @@ toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget
}
}
void
current_call_view_set_call_info(CurrentCallView *view, const QModelIndex& idx) {
static void
set_call_info(CurrentCallView *view, Call *call) {
CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
priv->call = CallModel::instance().getCall(idx);
priv->call = call;
/* get call image */
QVariant var_i = GlobalInstances::pixmapManipulator().callPhoto(priv->call, QSize(60, 60), false);
......@@ -651,15 +645,15 @@ current_call_view_set_call_info(CurrentCallView *view, const QModelIndex& idx) {
gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_peer), image.get());
/* get name */
auto name = idx.model()->data(idx, static_cast<int>(Ring::Role::Name));
gtk_label_set_text(GTK_LABEL(priv->label_name), name.toString().toUtf8().constData());
auto name = call->formattedName();
gtk_label_set_text(GTK_LABEL(priv->label_name), name.toUtf8().constData());
/* get uri, if different from name */
auto uri = idx.model()->data(idx, static_cast<int>(Ring::Role::Number));
if (name.toString() != uri.toString()) {
auto uri = call->peerContactMethod()->uri();
if (name != uri) {
auto cat_uri = g_strdup_printf("(%s) %s"
,priv->call->peerContactMethod()->category()->name().toUtf8().constData()
,uri.toString().toUtf8().constData());
,uri.toUtf8().constData());
gtk_label_set_text(GTK_LABEL(priv->label_uri), cat_uri);
g_free(cat_uri);
gtk_widget_show(priv->label_uri);
......@@ -765,3 +759,21 @@ current_call_view_set_call_info(CurrentCallView *view, const QModelIndex& idx) {
/* show chat view on any new incoming messages */
g_signal_connect_swapped(chat_view, "new-messages-displayed", G_CALLBACK(show_chat_view), view);
}
GtkWidget *
current_call_view_new(Call *call)
{
auto self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
set_call_info(CURRENT_CALL_VIEW(self), call);
return GTK_WIDGET(self);
}
Call*
current_call_view_get_call(CurrentCallView *self)
{
g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), nullptr);
auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
return priv->call;
}
......@@ -22,7 +22,7 @@
#include <gtk/gtk.h>
class QModelIndex;
class Call;
G_BEGIN_DECLS
......@@ -37,8 +37,8 @@ typedef struct _CurrentCallViewClass CurrentCallViewClass;
GType current_call_view_get_type (void) G_GNUC_CONST;
GtkWidget *current_call_view_new (void);
void current_call_view_set_call_info (CurrentCallView *view, const QModelIndex& idx);
GtkWidget *current_call_view_new (Call*);
Call *current_call_view_get_call (CurrentCallView*);
G_END_DECLS
......
......@@ -54,6 +54,8 @@ struct _IncomingCallViewPrivate
GtkWidget *button_reject_incoming;
GtkWidget *button_end_call;
Call *call;
QMetaObject::Connection state_change_connection;
};
......@@ -101,12 +103,6 @@ incoming_call_view_class_init(IncomingCallViewClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), IncomingCallView, button_end_call);
}
GtkWidget *
incoming_call_view_new(void)
{
return (GtkWidget *)g_object_new(INCOMING_CALL_VIEW_TYPE, NULL);
}
static void
update_state(IncomingCallView *view, Call *call)
{
......@@ -160,11 +156,11 @@ update_state(IncomingCallView *view, Call *call)
}
}
void
incoming_call_view_set_call_info(IncomingCallView *view, const QModelIndex& idx) {
static void
set_call_info(IncomingCallView *view, Call *call) {
IncomingCallViewPrivate *priv = INCOMING_CALL_VIEW_GET_PRIVATE(view);
Call *call = CallModel::instance().getCall(idx);
priv->call = call;
/* get call image */
QVariant var_i = GlobalInstances::pixmapManipulator().callPhoto(call, QSize(110, 110), false);
......@@ -172,15 +168,15 @@ incoming_call_view_set_call_info(IncomingCallView *view, const QModelIndex& idx)
gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_incoming), image.get());
/* get name */
auto name = idx.model()->data(idx, static_cast<int>(Ring::Role::Name));
gtk_label_set_text(GTK_LABEL(priv->label_name), name.toString().toUtf8().constData());
auto name = call->formattedName();
gtk_label_set_text(GTK_LABEL(priv->label_name), name.toUtf8().constData());
/* get uri, if different from name */
auto uri = idx.model()->data(idx, static_cast<int>(Ring::Role::Number));
if (name.toString() != uri.toString()) {
auto uri = call->peerContactMethod()->uri();
if (name != uri) {
auto cat_uri = g_strdup_printf("(%s) %s"
,call->peerContactMethod()->category()->name().toUtf8().constData()
,uri.toString().toUtf8().constData());
,uri.toUtf8().constData());
gtk_label_set_text(GTK_LABEL(priv->label_uri), cat_uri);
g_free(cat_uri);
gtk_widget_show(priv->label_uri);
......@@ -195,3 +191,21 @@ incoming_call_view_set_call_info(IncomingCallView *view, const QModelIndex& idx)
[=]() { update_state(view, call); }
);
}
GtkWidget *
incoming_call_view_new(Call *call)
{
auto self = g_object_new(INCOMING_CALL_VIEW_TYPE, NULL);
set_call_info(INCOMING_CALL_VIEW(self), call);
return GTK_WIDGET(self);
}
Call*
incoming_call_view_get_call(IncomingCallView *self)
{
g_return_val_if_fail(IS_INCOMING_CALL_VIEW(self), nullptr);
auto priv = INCOMING_CALL_VIEW_GET_PRIVATE(self);
return priv->call;
}
......@@ -22,7 +22,7 @@
#include <gtk/gtk.h>
class QModelIndex;
class Call;
G_BEGIN_DECLS
......@@ -37,8 +37,8 @@ typedef struct _IncomingCallViewClass IncomingCallViewClass;
GType incoming_call_view_get_type (void) G_GNUC_CONST;
GtkWidget *incoming_call_view_new (void);
void incoming_call_view_set_call_info (IncomingCallView *view, const QModelIndex& idx);
GtkWidget *incoming_call_view_new (Call*);
Call *incoming_call_view_get_call (IncomingCallView*);
G_END_DECLS
......
This diff is collapsed.
......@@ -205,7 +205,7 @@
<property name="visible">True</property>
</object>
<packing>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
......@@ -214,7 +214,7 @@
<property name="hexpand">True</property>
</object>
<packing>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
<!-- end contacts list -->
......@@ -224,7 +224,7 @@
<property name="visible">True</property>
</object>
<packing>
<property name="position">3</property>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
......@@ -233,7 +233,7 @@
<property name="hexpand">True</property>
</object>
<packing>
<property name="position">3</property>
<property name="position">2</property>
</packing>
</child>
<!-- end history -->
......
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