blob: 0c1e63ce772f42b0feae02ef1a9d683deeaab9eb [file] [log] [blame]
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05001/*
Stepan Salenikovichbe87d2c2016-01-25 14:14:34 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05003 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050018 */
19
20#include "currentcallview.h"
21
22#include <gtk/gtk.h>
Stepan Salenikovich7e283552015-12-21 16:17:52 -050023#include <glib/gi18n.h>
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050024#include <call.h>
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050025#include <callmodel.h>
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050026#include "utils/drawing.h"
27#include "video/video_widget.h"
Stepan Salenikovich4ac89f12015-03-10 16:48:47 -040028#include <video/previewmanager.h>
Stepan Salenikovich6f687072015-03-26 10:43:37 -040029#include <contactmethod.h>
30#include <person.h>
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -040031#include <globalinstances.h>
32#include "native/pixbufmanipulator.h"
Stepan Salenikovicha448f602015-05-29 13:33:06 -040033#include <media/media.h>
34#include <media/text.h>
35#include <media/textrecording.h>
36#include "models/gtkqtreemodel.h"
Stepan Salenikovich67112d12015-06-16 16:57:06 -040037#include "ringnotify.h"
Edric Milaret58e71072016-03-21 12:16:37 -040038#include <codecmodel.h>
Stepan Salenikovichf6f42652015-07-15 12:46:14 -040039#include <account.h>
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -050040#include "utils/files.h"
Stepan Salenikoviche178e632015-11-06 13:31:19 -050041#include <clutter-gtk/clutter-gtk.h>
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050042#include "chatview.h"
Stepan Salenikovich07107e92016-05-06 10:35:17 -040043#include <itemdataroles.h>
44#include <numbercategory.h>
Olivier Gregoire66e4df72016-06-17 18:39:05 -040045#include <smartinfohub.h>
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050046
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -050047static constexpr int CONTROLS_FADE_TIMEOUT = 3000000; /* microseconds */
48static constexpr int FADE_DURATION = 500; /* miliseconds */
49
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050050struct _CurrentCallView
51{
52 GtkBox parent;
53};
54
55struct _CurrentCallViewClass
56{
57 GtkBoxClass parent_class;
58};
59
60typedef struct _CurrentCallViewPrivate CurrentCallViewPrivate;
61
62struct _CurrentCallViewPrivate
63{
Stepan Salenikoviche178e632015-11-06 13:31:19 -050064 GtkWidget *hbox_call_info;
65 GtkWidget *hbox_call_controls;
Olivier Gregoire66e4df72016-06-17 18:39:05 -040066 GtkWidget *vbox_call_smartInfo;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050067 GtkWidget *image_peer;
Stepan Salenikovich07107e92016-05-06 10:35:17 -040068 GtkWidget *label_name;
Nicolas Jager2e467c32017-01-18 08:52:23 -050069 GtkWidget *label_bestId;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050070 GtkWidget *label_status;
71 GtkWidget *label_duration;
Olivier Gregoire66e4df72016-06-17 18:39:05 -040072 GtkWidget *label_smartinfo_description;
73 GtkWidget *label_smartinfo_value;
74 GtkWidget *label_smartinfo_general_information;
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050075 GtkWidget *paned_call;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050076 GtkWidget *frame_video;
77 GtkWidget *video_widget;
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050078 GtkWidget *frame_chat;
Stepan Salenikovicha448f602015-05-29 13:33:06 -040079 GtkWidget *togglebutton_chat;
Stepan Salenikovich77baa522015-07-07 15:29:14 -040080 GtkWidget *button_hangup;
Stepan Salenikovich7e283552015-12-21 16:17:52 -050081 GtkWidget *scalebutton_quality;
82 GtkWidget *checkbutton_autoquality;
83
aviau039001d2016-09-29 16:39:05 -040084 /* The webkit_chat_container is created once, then reused for all chat
85 * views */
86 GtkWidget *webkit_chat_container;
87
Stepan Salenikovich7e283552015-12-21 16:17:52 -050088 /* flag used to keep track of the video quality scale pressed state;
89 * we do not want to update the codec bitrate until the user releases the
90 * scale button */
91 gboolean quality_scale_pressed;
Stepan Salenikovicha448f602015-05-29 13:33:06 -040092
93 Call *call;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050094
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050095 QMetaObject::Connection state_change_connection;
96 QMetaObject::Connection call_details_connection;
Stepan Salenikovichc5f08152015-03-19 00:53:23 -040097 QMetaObject::Connection local_renderer_connection;
98 QMetaObject::Connection remote_renderer_connection;
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -050099
100 GSettings *settings;
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500101
102 // for clutter animations and to know when to fade in/out the overlays
103 ClutterTransition *fade_info;
104 ClutterTransition *fade_controls;
105 gint64 time_last_mouse_motion;
106 guint timer_fade;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400107
Stepan Salenikovich88092932017-05-15 18:19:00 -0400108 gulong insert_controls_id;
109
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400110 // smart info
111 QMetaObject::Connection smartinfo_refresh_connection;
112 guint smartinfo_action;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500113};
114
115G_DEFINE_TYPE_WITH_PRIVATE(CurrentCallView, current_call_view, GTK_TYPE_BOX);
116
117#define CURRENT_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CURRENT_CALL_VIEW_TYPE, CurrentCallViewPrivate))
118
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500119enum {
120 VIDEO_DOUBLE_CLICKED,
121 LAST_SIGNAL
122};
123
124static guint current_call_view_signals[LAST_SIGNAL] = { 0 };
125
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500126static void
127current_call_view_dispose(GObject *object)
128{
129 CurrentCallView *view;
130 CurrentCallViewPrivate *priv;
131
132 view = CURRENT_CALL_VIEW(object);
133 priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
134
135 QObject::disconnect(priv->state_change_connection);
136 QObject::disconnect(priv->call_details_connection);
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400137 QObject::disconnect(priv->local_renderer_connection);
138 QObject::disconnect(priv->remote_renderer_connection);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400139 QObject::disconnect(priv->smartinfo_refresh_connection);
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500140 g_clear_object(&priv->settings);
141
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500142 g_source_remove(priv->timer_fade);
143
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400144 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
145 g_signal_handler_disconnect(display_smartinfo, priv->smartinfo_action);
146
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500147 G_OBJECT_CLASS(current_call_view_parent_class)->dispose(object);
148}
149
150static void
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500151show_chat_view(CurrentCallView *self)
152{
153 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
154 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
155
156 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
157}
158
159static void
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400160chat_toggled(GtkToggleButton *togglebutton, CurrentCallView *self)
161{
162 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
163 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
164
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400165 if (gtk_toggle_button_get_active(togglebutton)) {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500166 gtk_widget_show_all(priv->frame_chat);
167 gtk_widget_grab_focus(priv->frame_chat);
Stepan Salenikovicha5129f62015-11-05 15:10:59 -0500168 } else {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500169 gtk_widget_hide(priv->frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400170 }
171}
172
Stepan Salenikovichdaf3cb32016-10-12 16:39:42 -0400173static gboolean
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500174map_boolean_to_orientation(GValue *value, GVariant *variant, G_GNUC_UNUSED gpointer user_data)
175{
176 if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
177 if (g_variant_get_boolean(variant)) {
178 // true, chat should be horizontal (to the right)
179 g_value_set_enum(value, GTK_ORIENTATION_HORIZONTAL);
180 } else {
181 // false, chat should be vertical (at the bottom)
182 g_value_set_enum(value, GTK_ORIENTATION_VERTICAL);
183 }
184 return TRUE;
185 }
186 return FALSE;
187}
188
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500189static gboolean
190timeout_check_last_motion_event(CurrentCallView *self)
191{
192 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), G_SOURCE_REMOVE);
193 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
194
195 auto current_time = g_get_monotonic_time();
196 if (current_time - priv->time_last_mouse_motion >= CONTROLS_FADE_TIMEOUT) {
197 // timeout has passed, hide the controls
198 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_BACKWARD) {
199 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_FORWARD);
200 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_FORWARD);
201 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
202 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
203 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
204 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
205 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
206 }
207 }
208 }
209
210 return G_SOURCE_CONTINUE;
211}
212
213static gboolean
214mouse_moved(CurrentCallView *self)
215{
216 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
217 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
218
219 priv->time_last_mouse_motion = g_get_monotonic_time();
220
221 // since the mouse moved, make sure the controls are shown
222 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_FORWARD) {
223 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
224 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
225 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
226 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
227 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
228 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
229 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
230 }
231 }
232
233 return FALSE; // propogate event
234}
235
236static ClutterTransition *
237create_fade_out_transition()
238{
239 auto transition = clutter_property_transition_new("opacity");
240 clutter_transition_set_from(transition, G_TYPE_UINT, 255);
241 clutter_transition_set_to(transition, G_TYPE_UINT, 0);
242 clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), FADE_DURATION);
243 clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), 0);
244 clutter_timeline_set_progress_mode(CLUTTER_TIMELINE(transition), CLUTTER_EASE_IN_OUT_CUBIC);
245 return transition;
246}
247
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500248static gboolean
249video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self)
250{
251 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
252 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
253
254 // if this widget already has focus, we want the focus to move to the next widget, otherwise we
255 // will get stuck in a focus loop on the buttons
256 if (gtk_widget_has_focus(widget))
257 return FALSE;
258
259 // otherwise we want the focus to go to and change between the call control buttons
260 if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
261 // selected a child, make sure call controls are shown
262 mouse_moved(self);
263 return TRUE;
264 }
265
266 // did not select the next child, propogate the event
267 return FALSE;
268}
269
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500270static GtkBox *
271gtk_scale_button_get_box(GtkScaleButton *button)
272{
273 GtkWidget *box = NULL;
274 if (auto dock = gtk_scale_button_get_popup(button)) {
275 // the dock is a popover which contains the box
276 box = gtk_bin_get_child(GTK_BIN(dock));
277 if (box) {
278 if (GTK_IS_FRAME(box)) {
279 // support older versions of gtk; the box used to be in a frame
280 box = gtk_bin_get_child(GTK_BIN(box));
281 }
282 }
283 }
284
285 return GTK_BOX(box);
286}
287
288/**
289 * This gets the GtkScaleButtonScale widget (which is a GtkScale) from the
290 * given GtkScaleButton in order to be able to modify its properties and connect
291 * to its signals
292 */
293static GtkScale *
294gtk_scale_button_get_scale(GtkScaleButton *button)
295{
296 GtkScale *scale = NULL;
297
298 if (auto box = gtk_scale_button_get_box(button)) {
299 GList *children = gtk_container_get_children(GTK_CONTAINER(box));
300 for (GList *c = children; c && !scale; c = c->next) {
301 if (GTK_IS_SCALE(c->data))
302 scale = GTK_SCALE(c->data);
303 }
304 g_list_free(children);
305 }
306
307 return scale;
308}
309
310static void
311set_quality(Call *call, gboolean auto_quality_on, double desired_quality)
312{
313 /* set auto quality true or false, also set the bitrate and quality values;
314 * the slider is from 0 to 100, use the min and max vals to scale each value accordingly */
315 if (const auto& codecModel = call->account()->codecModel()) {
316 const auto& videoCodecs = codecModel->videoCodecs();
317
318 for (int i=0; i < videoCodecs->rowCount();i++) {
319 const auto& idx = videoCodecs->index(i,0);
320
321 if (auto_quality_on) {
322 // g_debug("enable auto quality");
323 videoCodecs->setData(idx, "true", CodecModel::Role::AUTO_QUALITY_ENABLED);
324 } else {
325 auto min_bitrate = idx.data(static_cast<int>(CodecModel::Role::MIN_BITRATE)).toInt();
326 auto max_bitrate = idx.data(static_cast<int>(CodecModel::Role::MAX_BITRATE)).toInt();
327 auto min_quality = idx.data(static_cast<int>(CodecModel::Role::MIN_QUALITY)).toInt();
328 auto max_quality = idx.data(static_cast<int>(CodecModel::Role::MAX_QUALITY)).toInt();
329
330 // g_debug("bitrate min: %d, max: %d, quality min: %d, max: %d", min_bitrate, max_bitrate, min_quality, max_quality);
331
332 double bitrate;
333 bitrate = min_bitrate + (double)(max_bitrate - min_bitrate)*(desired_quality/100.0);
334 if (bitrate < 0) bitrate = 0;
335
336 double quality;
337 // note: a lower value means higher quality
338 quality = (double)min_quality - (min_quality - max_quality)*(desired_quality/100.0);
339 if (quality < 0) quality = 0;
340
341 // g_debug("disable auto quality; %% quality: %d; bitrate: %d; quality: %d", (int)desired_quality, (int)bitrate, (int)quality);
342 videoCodecs->setData(idx, "false", CodecModel::Role::AUTO_QUALITY_ENABLED);
343 videoCodecs->setData(idx, QString::number((int)bitrate), CodecModel::Role::BITRATE);
344 videoCodecs->setData(idx, QString::number((int)quality), CodecModel::Role::QUALITY);
345 }
346 }
347 codecModel << CodecModel::EditAction::SAVE;
348 }
349}
350
351static void
352autoquality_toggled(GtkToggleButton *button, CurrentCallView *self)
353{
354 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
355 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
356
357 gboolean auto_quality_on = gtk_toggle_button_get_active(button);
358
359 auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality));
360 auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
361 auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
362
363 gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on);
364 gtk_widget_set_sensitive(plus_button, !auto_quality_on);
365 gtk_widget_set_sensitive(minus_button, !auto_quality_on);
366
367 double desired_quality = gtk_scale_button_get_value(GTK_SCALE_BUTTON(priv->scalebutton_quality));
368
369 if (priv->call)
370 set_quality(priv->call, auto_quality_on, desired_quality);
371}
372
373static void
374quality_changed(GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self)
375{
376 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
377 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
378
379 /* no need to upate quality if auto quality is enabled */
380 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return;
381
382 /* only update if the scale button is released, to reduce the number of updates */
383 if (priv->quality_scale_pressed) return;
384
385 /* we get the value directly from the widget, in case this function is not
386 * called from the event */
387 if (priv->call)
388 set_quality(priv->call, FALSE, gtk_scale_button_get_value(button));
389}
390
391static gboolean
392quality_button_pressed(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
393{
394 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
395 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
396
397 priv->quality_scale_pressed = TRUE;
398
399 return GDK_EVENT_PROPAGATE;
400}
401
402static gboolean
403quality_button_released(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
404{
405 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
406 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
407
408 priv->quality_scale_pressed = FALSE;
409
410 /* now make sure the quality gets updated */
411 quality_changed(GTK_SCALE_BUTTON(priv->scalebutton_quality), 0, self);
412
413 return GDK_EVENT_PROPAGATE;
414}
415
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400416static void
Stepan Salenikovich88092932017-05-15 18:19:00 -0400417insert_controls(CurrentCallView *view)
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500418{
Stepan Salenikovich88092932017-05-15 18:19:00 -0400419 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400420
Stepan Salenikovich88092932017-05-15 18:19:00 -0400421 /* only add the controls once */
422 g_signal_handler_disconnect(view, priv->insert_controls_id);
423 priv->insert_controls_id = 0;
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500424
425 auto stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->video_widget));
426 auto actor_info = gtk_clutter_actor_new_with_contents(priv->hbox_call_info);
427 auto actor_controls = gtk_clutter_actor_new_with_contents(priv->hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400428 auto actor_smartInfo = gtk_clutter_actor_new_with_contents(priv->vbox_call_smartInfo);
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500429
430 clutter_actor_add_child(stage, actor_info);
431 clutter_actor_set_x_align(actor_info, CLUTTER_ACTOR_ALIGN_FILL);
432 clutter_actor_set_y_align(actor_info, CLUTTER_ACTOR_ALIGN_START);
433
434 clutter_actor_add_child(stage, actor_controls);
435 clutter_actor_set_x_align(actor_controls, CLUTTER_ACTOR_ALIGN_CENTER);
436 clutter_actor_set_y_align(actor_controls, CLUTTER_ACTOR_ALIGN_END);
437
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400438 clutter_actor_add_child(stage, actor_smartInfo);
439 clutter_actor_set_x_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_END);
440 clutter_actor_set_y_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_START);
441 ClutterMargin clutter_margin_smartInfo;
442 clutter_margin_smartInfo.top = 50;
443 clutter_margin_smartInfo.right = 10;
444 clutter_actor_set_margin (actor_smartInfo, &clutter_margin_smartInfo);
445
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500446 /* add fade in and out states to the info and controls */
447 priv->time_last_mouse_motion = g_get_monotonic_time();
448 priv->fade_info = create_fade_out_transition();
449 priv->fade_controls = create_fade_out_transition();
450 clutter_actor_add_transition(actor_info, "fade_info", priv->fade_info);
451 clutter_actor_add_transition(actor_controls, "fade_controls", priv->fade_controls);
452 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
453 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
454 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_info));
455 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_controls));
456
457 /* have a timer check every 1 second if the controls should fade out */
458 priv->timer_fade = g_timeout_add(1000, (GSourceFunc)timeout_check_last_motion_event, view);
459
460 /* connect to the mouse motion event to reset the last moved time */
461 g_signal_connect_swapped(priv->video_widget, "motion-notify-event", G_CALLBACK(mouse_moved), view);
462 g_signal_connect_swapped(priv->video_widget, "button-press-event", G_CALLBACK(mouse_moved), view);
463 g_signal_connect_swapped(priv->video_widget, "button-release-event", G_CALLBACK(mouse_moved), view);
464
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500465 /* manually handle the focus of the video widget to be able to focus on the call controls */
466 g_signal_connect(priv->video_widget, "focus", G_CALLBACK(video_widget_focus), view);
467
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500468 /* toggle whether or not the chat is displayed */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400469 g_signal_connect(priv->togglebutton_chat, "toggled", G_CALLBACK(chat_toggled), view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400470
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500471 /* bind the chat orientation to the gsetting */
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500472 priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
473 g_settings_bind_with_mapping(priv->settings, "chat-pane-horizontal",
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500474 priv->paned_call, "orientation",
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500475 G_SETTINGS_BIND_GET,
476 map_boolean_to_orientation,
477 nullptr, nullptr, nullptr);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500478
479 g_signal_connect(priv->scalebutton_quality, "value-changed", G_CALLBACK(quality_changed), view);
480 /* customize the quality button scale */
481 if (auto scale_box = gtk_scale_button_get_box(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
482 priv->checkbutton_autoquality = gtk_check_button_new_with_label(C_("Enable automatic video quality", "Auto"));
483 gtk_widget_show(priv->checkbutton_autoquality);
484 gtk_box_pack_start(GTK_BOX(scale_box), priv->checkbutton_autoquality, FALSE, TRUE, 0);
485 g_signal_connect(priv->checkbutton_autoquality, "toggled", G_CALLBACK(autoquality_toggled), view);
486 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), TRUE);
487 }
488 if (auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
489 g_signal_connect(scale, "button-press-event", G_CALLBACK(quality_button_pressed), view);
490 g_signal_connect(scale, "button-release-event", G_CALLBACK(quality_button_released), view);
491 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400492
493 /* by this time we should have the call already set, but we check to make sure */
494 if (priv->call) {
495 /* check if auto quality is enabled or not */
496 if (const auto& codecModel = priv->call->account()->codecModel()) {
497 const auto& videoCodecs = codecModel->videoCodecs();
498 if (videoCodecs->rowCount() > 0) {
499 /* we only need to check the first codec since by default it is ON for all, and the
500 * gnome client sets its ON or OFF for all codecs as well */
501 const auto& idx = videoCodecs->index(0,0);
502 auto auto_quality_enabled = idx.data(static_cast<int>(CodecModel::Role::AUTO_QUALITY_ENABLED)).toString() == "true";
503 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), auto_quality_enabled);
504
505 // TODO: save the manual quality setting in the client and set the slider to that value here;
506 // the daemon resets the bitrate/quality between each call, and the default may be
507 // different for each codec, so there is no reason to check it here
508 }
509 }
510 }
511}
512
513static void
514current_call_view_init(CurrentCallView *view)
515{
516 gtk_widget_init_template(GTK_WIDGET(view));
517
518 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
519
520 // CSS styles
521 auto provider = gtk_css_provider_new();
522 gtk_css_provider_load_from_data(provider,
523 ".smartinfo-block-style { color: #8ae234; background-color: rgba(1, 1, 1, 0.33); }",
524 -1, nullptr
525 );
526 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
527 GTK_STYLE_PROVIDER(provider),
528 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
529
530 priv->video_widget = video_widget_new();
531 gtk_container_add(GTK_CONTAINER(priv->frame_video), priv->video_widget);
532 gtk_widget_show_all(priv->frame_video);
533
534 /* add the overlay controls only once the view has been allocated a size to prevent size
535 * allocation warnings in the log */
536 priv->insert_controls_id = g_signal_connect(view, "size-allocate", G_CALLBACK(insert_controls), nullptr);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500537}
538
539static void
540current_call_view_class_init(CurrentCallViewClass *klass)
541{
542 G_OBJECT_CLASS(klass)->dispose = current_call_view_dispose;
543
544 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
545 "/cx/ring/RingGnome/currentcallview.ui");
546
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500547 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_info);
548 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400549 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, vbox_call_smartInfo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500550 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, image_peer);
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400551 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_name);
Nicolas Jager2e467c32017-01-18 08:52:23 -0500552 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_bestId);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500553 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_status);
554 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_duration);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400555 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_description);
556 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_value);
557 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_general_information);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500558 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, paned_call);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500559 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500560 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400561 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat);
Stepan Salenikovich77baa522015-07-07 15:29:14 -0400562 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, button_hangup);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500563 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, scalebutton_quality);
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500564
565 current_call_view_signals[VIDEO_DOUBLE_CLICKED] = g_signal_new (
566 "video-double-clicked",
567 G_TYPE_FROM_CLASS(klass),
568 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
569 0,
570 nullptr,
571 nullptr,
572 g_cclosure_marshal_VOID__VOID,
573 G_TYPE_NONE, 0);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500574}
575
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500576static void
577update_state(CurrentCallView *view, Call *call)
578{
579 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
580
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400581 gchar *status = g_strdup_printf("%s", call->toHumanStateName().toUtf8().constData());
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500582
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400583 gtk_label_set_text(GTK_LABEL(priv->label_status), status);
584
585 g_free(status);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500586}
587
588static void
589update_details(CurrentCallView *view, Call *call)
590{
591 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
592
593 /* update call duration */
594 QByteArray ba_length = call->length().toLocal8Bit();
595 gtk_label_set_text(GTK_LABEL(priv->label_duration), ba_length.constData());
596}
597
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400598static void
599update_smartInfo(CurrentCallView *view)
600{
601 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
602
603 if (!SmartInfoHub::instance().isConference()) {
604 gchar* general_information = g_strdup_printf("Call ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
605 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
606 g_free(general_information);
607
608 gchar* description = g_strdup_printf("You\n"
609 "Framerate:\n"
610 "Video codec:\n"
611 "Audio codec:\n"
612 "Resolution:\n\n"
613 "Peer\n"
614 "Framerate:\n"
615 "Video codec:\n"
616 "Audio codec:\n"
617 "Resolution:");
618 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
619 g_free(description);
620
621 gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d\n\n\n%f\n%s\n%s\n%dx%d",
622 (double)SmartInfoHub::instance().localFps(),
623 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
624 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
625 SmartInfoHub::instance().localWidth(),
626 SmartInfoHub::instance().localHeight(),
627 (double)SmartInfoHub::instance().remoteFps(),
628 SmartInfoHub::instance().remoteVideoCodec().toStdString().c_str(),
629 SmartInfoHub::instance().remoteAudioCodec().toStdString().c_str(),
630 SmartInfoHub::instance().remoteWidth(),
631 SmartInfoHub::instance().remoteHeight());
632 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
633 g_free(value);
634 } else {
635 gchar* general_information = g_strdup_printf("Conference ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
636 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
637 g_free(general_information);
638
639 gchar* description = g_strdup_printf("You\n"
640 "Framerate:\n"
641 "Video codec:\n"
642 "Audio codec:\n"
643 "Resolution:");
644 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
645 g_free(description);
646
647 gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d",
648 (double)SmartInfoHub::instance().localFps(),
649 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
650 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
651 SmartInfoHub::instance().localWidth(),
652 SmartInfoHub::instance().localHeight());
653 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
654 g_free(value);
655 }
656}
657
658
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500659static gboolean
660on_button_press_in_video_event(GtkWidget *self, GdkEventButton *event, CurrentCallView *view)
661{
662 g_return_val_if_fail(IS_VIDEO_WIDGET(self), FALSE);
663 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
664
665 /* on double click */
666 if (event->type == GDK_2BUTTON_PRESS) {
667 g_debug("double click in video");
668 g_signal_emit(G_OBJECT(view), current_call_view_signals[VIDEO_DOUBLE_CLICKED], 0);
669 }
670
671 return GDK_EVENT_PROPAGATE;
672}
673
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400674static void
675toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget* vbox_call_smartInfo)
676{
677 if (g_variant_get_boolean(g_action_get_state(G_ACTION(action)))) {
678 gtk_widget_show(vbox_call_smartInfo);
679 } else {
680 gtk_widget_hide(vbox_call_smartInfo);
681 }
682}
683
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400684static void
685set_call_info(CurrentCallView *view, Call *call) {
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500686 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
687
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400688 priv->call = call;
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400689
690 /* get call image */
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -0400691 QVariant var_i = GlobalInstances::pixmapManipulator().callPhoto(priv->call, QSize(60, 60), false);
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400692 std::shared_ptr<GdkPixbuf> image = var_i.value<std::shared_ptr<GdkPixbuf>>();
693 gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_peer), image.get());
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500694
695 /* get name */
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400696 auto name = call->formattedName();
697 gtk_label_set_text(GTK_LABEL(priv->label_name), name.toUtf8().constData());
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400698
Nicolas Jager4a1f0642017-01-17 14:01:19 -0500699 /* get contact best id, if different from name */
Houminbeab3c92017-05-16 11:12:16 +0800700 auto contactId = call->peerContactMethod()->bestId();
Nicolas Jager4a1f0642017-01-17 14:01:19 -0500701 if (name != contactId) {
702 auto cat_contactId = g_strdup_printf("(%s) %s"
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400703 ,priv->call->peerContactMethod()->category()->name().toUtf8().constData()
Nicolas Jager4a1f0642017-01-17 14:01:19 -0500704 ,contactId.toUtf8().constData());
Nicolas Jager2e467c32017-01-18 08:52:23 -0500705 gtk_label_set_text(GTK_LABEL(priv->label_bestId), cat_contactId);
Nicolas Jager4a1f0642017-01-17 14:01:19 -0500706 g_free(cat_contactId);
Nicolas Jager2e467c32017-01-18 08:52:23 -0500707 gtk_widget_show(priv->label_bestId);
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400708 }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500709
710 /* change some things depending on call state */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400711 update_state(view, priv->call);
712 update_details(view, priv->call);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500713
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400714 priv->smartinfo_refresh_connection = QObject::connect(
715 &SmartInfoHub::instance(),
716 &SmartInfoHub::changed,
717 [view, priv]() { update_smartInfo(view); }
718 );
719
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500720 priv->state_change_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400721 priv->call,
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500722 &Call::stateChanged,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400723 [view, priv]() { update_state(view, priv->call); }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500724 );
725
726 priv->call_details_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400727 priv->call,
Stepan Salenikovich6dbaf262017-05-19 15:42:24 -0400728 &Call::changed,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400729 [view, priv]() { update_details(view, priv->call); }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500730 );
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500731
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500732 /* check if we already have a renderer */
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400733 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400734 priv->call->videoRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400735 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500736
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400737 /* callback for remote renderer */
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400738 priv->remote_renderer_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400739 priv->call,
Stepan Salenikovich9c1f6682015-03-09 16:21:28 -0400740 &Call::videoStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400741 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400742 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
743 renderer,
744 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500745 }
746 );
Stepan Salenikovich4ac89f12015-03-10 16:48:47 -0400747
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400748 /* local renderer */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400749 if (Video::PreviewManager::instance().isPreviewing())
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400750 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400751 Video::PreviewManager::instance().previewRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400752 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400753
754 /* callback for local renderer */
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400755 priv->local_renderer_connection = QObject::connect(
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400756 &Video::PreviewManager::instance(),
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400757 &Video::PreviewManager::previewStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400758 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400759 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
760 renderer,
761 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400762 }
763 );
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400764
Julien Grossholtza0d4f102015-10-22 14:24:17 -0400765 /* handle video widget button click event */
766 g_signal_connect(priv->video_widget, "button-press-event", G_CALLBACK(video_widget_on_button_press_in_screen_event), priv->call);
767
768 /* handle video widget drag and drop*/
769 g_signal_connect(priv->video_widget, "drag-data-received", G_CALLBACK(video_widget_on_drag_data_received), priv->call);
770
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400771 /* catch double click to make full screen */
772 g_signal_connect(priv->video_widget, "button-press-event",
773 G_CALLBACK(on_button_press_in_video_event),
774 view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400775
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400776 /* handle smartinfo in right click menu */
777 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
778 priv->smartinfo_action = g_signal_connect(display_smartinfo,
779 "notify::state",
780 G_CALLBACK(toggle_smartinfo),
781 priv->vbox_call_smartInfo);
782
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500783 /* init chat view */
aviau039001d2016-09-29 16:39:05 -0400784 auto chat_view = chat_view_new_call(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), priv->call);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500785 gtk_container_add(GTK_CONTAINER(priv->frame_chat), chat_view);
786
787 /* check if there were any chat notifications and open the chat view if so */
Stepan Salenikovich26cd1602016-01-20 13:43:17 -0500788 if (ring_notify_close_chat_notification(priv->call->peerContactMethod()))
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500789 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
790
791 /* show chat view on any new incoming messages */
792 g_signal_connect_swapped(chat_view, "new-messages-displayed", G_CALLBACK(show_chat_view), view);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500793}
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400794
795GtkWidget *
aviau039001d2016-09-29 16:39:05 -0400796current_call_view_new(Call *call, WebKitChatContainer *webkit_chat_container)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400797{
798 auto self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
aviau039001d2016-09-29 16:39:05 -0400799 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
800 priv->webkit_chat_container = GTK_WIDGET(webkit_chat_container);
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400801 set_call_info(CURRENT_CALL_VIEW(self), call);
802
803 return GTK_WIDGET(self);
804}
805
806Call*
807current_call_view_get_call(CurrentCallView *self)
808{
809 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), nullptr);
810 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
811
812 return priv->call;
813}