blob: 89282fb9ef53c38ed007ef8032fe5db9d419521a [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 Salenikovich46bb1572017-05-19 16:09:43 -040097 QMetaObject::Connection cm_changed_connection;
98 QMetaObject::Connection person_changed_connection;
99 QMetaObject::Connection cm_person_changed_connection;
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400100 QMetaObject::Connection local_renderer_connection;
101 QMetaObject::Connection remote_renderer_connection;
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500102
103 GSettings *settings;
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500104
105 // for clutter animations and to know when to fade in/out the overlays
106 ClutterTransition *fade_info;
107 ClutterTransition *fade_controls;
108 gint64 time_last_mouse_motion;
109 guint timer_fade;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400110
Stepan Salenikovich88092932017-05-15 18:19:00 -0400111 gulong insert_controls_id;
112
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400113 // smart info
114 QMetaObject::Connection smartinfo_refresh_connection;
115 guint smartinfo_action;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500116};
117
118G_DEFINE_TYPE_WITH_PRIVATE(CurrentCallView, current_call_view, GTK_TYPE_BOX);
119
120#define CURRENT_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CURRENT_CALL_VIEW_TYPE, CurrentCallViewPrivate))
121
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500122enum {
123 VIDEO_DOUBLE_CLICKED,
124 LAST_SIGNAL
125};
126
127static guint current_call_view_signals[LAST_SIGNAL] = { 0 };
128
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500129static void
130current_call_view_dispose(GObject *object)
131{
132 CurrentCallView *view;
133 CurrentCallViewPrivate *priv;
134
135 view = CURRENT_CALL_VIEW(object);
136 priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
137
138 QObject::disconnect(priv->state_change_connection);
139 QObject::disconnect(priv->call_details_connection);
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400140 QObject::disconnect(priv->cm_changed_connection);
141 QObject::disconnect(priv->person_changed_connection);
142 QObject::disconnect(priv->cm_person_changed_connection);
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400143 QObject::disconnect(priv->local_renderer_connection);
144 QObject::disconnect(priv->remote_renderer_connection);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400145 QObject::disconnect(priv->smartinfo_refresh_connection);
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500146 g_clear_object(&priv->settings);
147
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500148 g_source_remove(priv->timer_fade);
149
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400150 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
151 g_signal_handler_disconnect(display_smartinfo, priv->smartinfo_action);
152
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500153 G_OBJECT_CLASS(current_call_view_parent_class)->dispose(object);
154}
155
156static void
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500157show_chat_view(CurrentCallView *self)
158{
159 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
160 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
161
162 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
163}
164
165static void
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400166chat_toggled(GtkToggleButton *togglebutton, CurrentCallView *self)
167{
168 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
169 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
170
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400171 if (gtk_toggle_button_get_active(togglebutton)) {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500172 gtk_widget_show_all(priv->frame_chat);
173 gtk_widget_grab_focus(priv->frame_chat);
Stepan Salenikovicha5129f62015-11-05 15:10:59 -0500174 } else {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500175 gtk_widget_hide(priv->frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400176 }
177}
178
Stepan Salenikovichdaf3cb32016-10-12 16:39:42 -0400179static gboolean
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500180map_boolean_to_orientation(GValue *value, GVariant *variant, G_GNUC_UNUSED gpointer user_data)
181{
182 if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
183 if (g_variant_get_boolean(variant)) {
184 // true, chat should be horizontal (to the right)
185 g_value_set_enum(value, GTK_ORIENTATION_HORIZONTAL);
186 } else {
187 // false, chat should be vertical (at the bottom)
188 g_value_set_enum(value, GTK_ORIENTATION_VERTICAL);
189 }
190 return TRUE;
191 }
192 return FALSE;
193}
194
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500195static gboolean
196timeout_check_last_motion_event(CurrentCallView *self)
197{
198 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), G_SOURCE_REMOVE);
199 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
200
201 auto current_time = g_get_monotonic_time();
202 if (current_time - priv->time_last_mouse_motion >= CONTROLS_FADE_TIMEOUT) {
203 // timeout has passed, hide the controls
204 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_BACKWARD) {
205 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_FORWARD);
206 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_FORWARD);
207 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
208 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
209 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
210 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
211 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
212 }
213 }
214 }
215
216 return G_SOURCE_CONTINUE;
217}
218
219static gboolean
220mouse_moved(CurrentCallView *self)
221{
222 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
223 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
224
225 priv->time_last_mouse_motion = g_get_monotonic_time();
226
227 // since the mouse moved, make sure the controls are shown
228 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_FORWARD) {
229 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
230 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
231 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
232 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
233 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
234 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
235 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
236 }
237 }
238
239 return FALSE; // propogate event
240}
241
242static ClutterTransition *
243create_fade_out_transition()
244{
245 auto transition = clutter_property_transition_new("opacity");
246 clutter_transition_set_from(transition, G_TYPE_UINT, 255);
247 clutter_transition_set_to(transition, G_TYPE_UINT, 0);
248 clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), FADE_DURATION);
249 clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), 0);
250 clutter_timeline_set_progress_mode(CLUTTER_TIMELINE(transition), CLUTTER_EASE_IN_OUT_CUBIC);
251 return transition;
252}
253
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500254static gboolean
255video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self)
256{
257 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
258 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
259
260 // if this widget already has focus, we want the focus to move to the next widget, otherwise we
261 // will get stuck in a focus loop on the buttons
262 if (gtk_widget_has_focus(widget))
263 return FALSE;
264
265 // otherwise we want the focus to go to and change between the call control buttons
266 if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
267 // selected a child, make sure call controls are shown
268 mouse_moved(self);
269 return TRUE;
270 }
271
272 // did not select the next child, propogate the event
273 return FALSE;
274}
275
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500276static GtkBox *
277gtk_scale_button_get_box(GtkScaleButton *button)
278{
279 GtkWidget *box = NULL;
280 if (auto dock = gtk_scale_button_get_popup(button)) {
281 // the dock is a popover which contains the box
282 box = gtk_bin_get_child(GTK_BIN(dock));
283 if (box) {
284 if (GTK_IS_FRAME(box)) {
285 // support older versions of gtk; the box used to be in a frame
286 box = gtk_bin_get_child(GTK_BIN(box));
287 }
288 }
289 }
290
291 return GTK_BOX(box);
292}
293
294/**
295 * This gets the GtkScaleButtonScale widget (which is a GtkScale) from the
296 * given GtkScaleButton in order to be able to modify its properties and connect
297 * to its signals
298 */
299static GtkScale *
300gtk_scale_button_get_scale(GtkScaleButton *button)
301{
302 GtkScale *scale = NULL;
303
304 if (auto box = gtk_scale_button_get_box(button)) {
305 GList *children = gtk_container_get_children(GTK_CONTAINER(box));
306 for (GList *c = children; c && !scale; c = c->next) {
307 if (GTK_IS_SCALE(c->data))
308 scale = GTK_SCALE(c->data);
309 }
310 g_list_free(children);
311 }
312
313 return scale;
314}
315
316static void
317set_quality(Call *call, gboolean auto_quality_on, double desired_quality)
318{
319 /* set auto quality true or false, also set the bitrate and quality values;
320 * the slider is from 0 to 100, use the min and max vals to scale each value accordingly */
321 if (const auto& codecModel = call->account()->codecModel()) {
322 const auto& videoCodecs = codecModel->videoCodecs();
323
324 for (int i=0; i < videoCodecs->rowCount();i++) {
325 const auto& idx = videoCodecs->index(i,0);
326
327 if (auto_quality_on) {
328 // g_debug("enable auto quality");
329 videoCodecs->setData(idx, "true", CodecModel::Role::AUTO_QUALITY_ENABLED);
330 } else {
331 auto min_bitrate = idx.data(static_cast<int>(CodecModel::Role::MIN_BITRATE)).toInt();
332 auto max_bitrate = idx.data(static_cast<int>(CodecModel::Role::MAX_BITRATE)).toInt();
333 auto min_quality = idx.data(static_cast<int>(CodecModel::Role::MIN_QUALITY)).toInt();
334 auto max_quality = idx.data(static_cast<int>(CodecModel::Role::MAX_QUALITY)).toInt();
335
336 // g_debug("bitrate min: %d, max: %d, quality min: %d, max: %d", min_bitrate, max_bitrate, min_quality, max_quality);
337
338 double bitrate;
339 bitrate = min_bitrate + (double)(max_bitrate - min_bitrate)*(desired_quality/100.0);
340 if (bitrate < 0) bitrate = 0;
341
342 double quality;
343 // note: a lower value means higher quality
344 quality = (double)min_quality - (min_quality - max_quality)*(desired_quality/100.0);
345 if (quality < 0) quality = 0;
346
347 // g_debug("disable auto quality; %% quality: %d; bitrate: %d; quality: %d", (int)desired_quality, (int)bitrate, (int)quality);
348 videoCodecs->setData(idx, "false", CodecModel::Role::AUTO_QUALITY_ENABLED);
349 videoCodecs->setData(idx, QString::number((int)bitrate), CodecModel::Role::BITRATE);
350 videoCodecs->setData(idx, QString::number((int)quality), CodecModel::Role::QUALITY);
351 }
352 }
353 codecModel << CodecModel::EditAction::SAVE;
354 }
355}
356
357static void
358autoquality_toggled(GtkToggleButton *button, CurrentCallView *self)
359{
360 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
361 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
362
363 gboolean auto_quality_on = gtk_toggle_button_get_active(button);
364
365 auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality));
366 auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
367 auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
368
369 gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on);
370 gtk_widget_set_sensitive(plus_button, !auto_quality_on);
371 gtk_widget_set_sensitive(minus_button, !auto_quality_on);
372
373 double desired_quality = gtk_scale_button_get_value(GTK_SCALE_BUTTON(priv->scalebutton_quality));
374
375 if (priv->call)
376 set_quality(priv->call, auto_quality_on, desired_quality);
377}
378
379static void
380quality_changed(GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self)
381{
382 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
383 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
384
385 /* no need to upate quality if auto quality is enabled */
386 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return;
387
388 /* only update if the scale button is released, to reduce the number of updates */
389 if (priv->quality_scale_pressed) return;
390
391 /* we get the value directly from the widget, in case this function is not
392 * called from the event */
393 if (priv->call)
394 set_quality(priv->call, FALSE, gtk_scale_button_get_value(button));
395}
396
397static gboolean
398quality_button_pressed(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
399{
400 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
401 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
402
403 priv->quality_scale_pressed = TRUE;
404
405 return GDK_EVENT_PROPAGATE;
406}
407
408static gboolean
409quality_button_released(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
410{
411 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
412 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
413
414 priv->quality_scale_pressed = FALSE;
415
416 /* now make sure the quality gets updated */
417 quality_changed(GTK_SCALE_BUTTON(priv->scalebutton_quality), 0, self);
418
419 return GDK_EVENT_PROPAGATE;
420}
421
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400422static void
Stepan Salenikovich88092932017-05-15 18:19:00 -0400423insert_controls(CurrentCallView *view)
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500424{
Stepan Salenikovich88092932017-05-15 18:19:00 -0400425 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400426
Stepan Salenikovich88092932017-05-15 18:19:00 -0400427 /* only add the controls once */
428 g_signal_handler_disconnect(view, priv->insert_controls_id);
429 priv->insert_controls_id = 0;
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500430
431 auto stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->video_widget));
432 auto actor_info = gtk_clutter_actor_new_with_contents(priv->hbox_call_info);
433 auto actor_controls = gtk_clutter_actor_new_with_contents(priv->hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400434 auto actor_smartInfo = gtk_clutter_actor_new_with_contents(priv->vbox_call_smartInfo);
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500435
436 clutter_actor_add_child(stage, actor_info);
437 clutter_actor_set_x_align(actor_info, CLUTTER_ACTOR_ALIGN_FILL);
438 clutter_actor_set_y_align(actor_info, CLUTTER_ACTOR_ALIGN_START);
439
440 clutter_actor_add_child(stage, actor_controls);
441 clutter_actor_set_x_align(actor_controls, CLUTTER_ACTOR_ALIGN_CENTER);
442 clutter_actor_set_y_align(actor_controls, CLUTTER_ACTOR_ALIGN_END);
443
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400444 clutter_actor_add_child(stage, actor_smartInfo);
445 clutter_actor_set_x_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_END);
446 clutter_actor_set_y_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_START);
447 ClutterMargin clutter_margin_smartInfo;
448 clutter_margin_smartInfo.top = 50;
449 clutter_margin_smartInfo.right = 10;
philippegorleya7337942017-07-04 15:29:42 -0400450 clutter_margin_smartInfo.left = 10;
451 clutter_margin_smartInfo.bottom = 10;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400452 clutter_actor_set_margin (actor_smartInfo, &clutter_margin_smartInfo);
453
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500454 /* add fade in and out states to the info and controls */
455 priv->time_last_mouse_motion = g_get_monotonic_time();
456 priv->fade_info = create_fade_out_transition();
457 priv->fade_controls = create_fade_out_transition();
458 clutter_actor_add_transition(actor_info, "fade_info", priv->fade_info);
459 clutter_actor_add_transition(actor_controls, "fade_controls", priv->fade_controls);
460 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
461 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
462 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_info));
463 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_controls));
464
465 /* have a timer check every 1 second if the controls should fade out */
466 priv->timer_fade = g_timeout_add(1000, (GSourceFunc)timeout_check_last_motion_event, view);
467
468 /* connect to the mouse motion event to reset the last moved time */
469 g_signal_connect_swapped(priv->video_widget, "motion-notify-event", G_CALLBACK(mouse_moved), view);
470 g_signal_connect_swapped(priv->video_widget, "button-press-event", G_CALLBACK(mouse_moved), view);
471 g_signal_connect_swapped(priv->video_widget, "button-release-event", G_CALLBACK(mouse_moved), view);
472
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500473 /* manually handle the focus of the video widget to be able to focus on the call controls */
474 g_signal_connect(priv->video_widget, "focus", G_CALLBACK(video_widget_focus), view);
475
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500476 /* toggle whether or not the chat is displayed */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400477 g_signal_connect(priv->togglebutton_chat, "toggled", G_CALLBACK(chat_toggled), view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400478
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500479 /* bind the chat orientation to the gsetting */
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500480 priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
481 g_settings_bind_with_mapping(priv->settings, "chat-pane-horizontal",
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500482 priv->paned_call, "orientation",
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500483 G_SETTINGS_BIND_GET,
484 map_boolean_to_orientation,
485 nullptr, nullptr, nullptr);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500486
487 g_signal_connect(priv->scalebutton_quality, "value-changed", G_CALLBACK(quality_changed), view);
488 /* customize the quality button scale */
489 if (auto scale_box = gtk_scale_button_get_box(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
490 priv->checkbutton_autoquality = gtk_check_button_new_with_label(C_("Enable automatic video quality", "Auto"));
491 gtk_widget_show(priv->checkbutton_autoquality);
492 gtk_box_pack_start(GTK_BOX(scale_box), priv->checkbutton_autoquality, FALSE, TRUE, 0);
493 g_signal_connect(priv->checkbutton_autoquality, "toggled", G_CALLBACK(autoquality_toggled), view);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500494 }
495 if (auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
496 g_signal_connect(scale, "button-press-event", G_CALLBACK(quality_button_pressed), view);
497 g_signal_connect(scale, "button-release-event", G_CALLBACK(quality_button_released), view);
498 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400499
500 /* by this time we should have the call already set, but we check to make sure */
501 if (priv->call) {
502 /* check if auto quality is enabled or not */
503 if (const auto& codecModel = priv->call->account()->codecModel()) {
504 const auto& videoCodecs = codecModel->videoCodecs();
505 if (videoCodecs->rowCount() > 0) {
506 /* we only need to check the first codec since by default it is ON for all, and the
507 * gnome client sets its ON or OFF for all codecs as well */
508 const auto& idx = videoCodecs->index(0,0);
509 auto auto_quality_enabled = idx.data(static_cast<int>(CodecModel::Role::AUTO_QUALITY_ENABLED)).toString() == "true";
510 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), auto_quality_enabled);
511
512 // TODO: save the manual quality setting in the client and set the slider to that value here;
513 // the daemon resets the bitrate/quality between each call, and the default may be
514 // different for each codec, so there is no reason to check it here
515 }
516 }
Guillaume Roguez567a97b2017-05-23 14:10:05 -0400517 } else {
518 /* Auto-quality is off by default */
519 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), FALSE);
Stepan Salenikovich88092932017-05-15 18:19:00 -0400520 }
521}
522
523static void
524current_call_view_init(CurrentCallView *view)
525{
526 gtk_widget_init_template(GTK_WIDGET(view));
527
528 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
529
530 // CSS styles
531 auto provider = gtk_css_provider_new();
532 gtk_css_provider_load_from_data(provider,
533 ".smartinfo-block-style { color: #8ae234; background-color: rgba(1, 1, 1, 0.33); }",
534 -1, nullptr
535 );
536 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
537 GTK_STYLE_PROVIDER(provider),
538 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
539
540 priv->video_widget = video_widget_new();
541 gtk_container_add(GTK_CONTAINER(priv->frame_video), priv->video_widget);
542 gtk_widget_show_all(priv->frame_video);
543
544 /* add the overlay controls only once the view has been allocated a size to prevent size
545 * allocation warnings in the log */
546 priv->insert_controls_id = g_signal_connect(view, "size-allocate", G_CALLBACK(insert_controls), nullptr);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500547}
548
549static void
550current_call_view_class_init(CurrentCallViewClass *klass)
551{
552 G_OBJECT_CLASS(klass)->dispose = current_call_view_dispose;
553
554 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
555 "/cx/ring/RingGnome/currentcallview.ui");
556
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500557 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_info);
558 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400559 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, vbox_call_smartInfo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500560 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, image_peer);
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400561 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_name);
Nicolas Jager2e467c32017-01-18 08:52:23 -0500562 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_bestId);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500563 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_status);
564 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_duration);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400565 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_description);
566 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_value);
567 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_general_information);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500568 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, paned_call);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500569 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500570 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400571 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat);
Stepan Salenikovich77baa522015-07-07 15:29:14 -0400572 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, button_hangup);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500573 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, scalebutton_quality);
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500574
575 current_call_view_signals[VIDEO_DOUBLE_CLICKED] = g_signal_new (
576 "video-double-clicked",
577 G_TYPE_FROM_CLASS(klass),
578 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
579 0,
580 nullptr,
581 nullptr,
582 g_cclosure_marshal_VOID__VOID,
583 G_TYPE_NONE, 0);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500584}
585
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500586static void
587update_state(CurrentCallView *view, Call *call)
588{
589 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
590
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400591 gchar *status = g_strdup_printf("%s", call->toHumanStateName().toUtf8().constData());
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500592
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400593 gtk_label_set_text(GTK_LABEL(priv->label_status), status);
594
595 g_free(status);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500596}
597
598static void
599update_details(CurrentCallView *view, Call *call)
600{
601 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
602
603 /* update call duration */
604 QByteArray ba_length = call->length().toLocal8Bit();
605 gtk_label_set_text(GTK_LABEL(priv->label_duration), ba_length.constData());
606}
607
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400608static void
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400609update_name_and_photo(CurrentCallView *view)
610{
611 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
612
613 /* get call image */
614 QVariant var_i = GlobalInstances::pixmapManipulator().callPhoto(priv->call, QSize(60, 60), false);
615 std::shared_ptr<GdkPixbuf> image = var_i.value<std::shared_ptr<GdkPixbuf>>();
616 gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_peer), image.get());
617
618 /* get name */
619 auto name = priv->call->formattedName();
620 gtk_label_set_text(GTK_LABEL(priv->label_name), name.toUtf8().constData());
621
622 /* get contact best id, if different from name */
623 auto contactId = priv->call->peerContactMethod()->bestId();
624 if (name != contactId) {
625 auto cat_contactId = g_strdup_printf("(%s) %s"
626 ,priv->call->peerContactMethod()->category()->name().toUtf8().constData()
627 ,contactId.toUtf8().constData());
628 gtk_label_set_text(GTK_LABEL(priv->label_bestId), cat_contactId);
629 g_free(cat_contactId);
630 gtk_widget_show(priv->label_bestId);
631 }
632}
633
634static void
635update_person(CurrentCallView *view, Person *new_person)
636{
637 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
638
639 update_name_and_photo(view);
640
641 QObject::disconnect(priv->person_changed_connection);
642 if (new_person) {
643 priv->person_changed_connection = QObject::connect(
644 new_person,
645 &Person::changed,
646 [view]() { update_name_and_photo(view); }
647 );
648 }
649}
650
651static void
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400652update_smartInfo(CurrentCallView *view)
653{
654 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
655
656 if (!SmartInfoHub::instance().isConference()) {
657 gchar* general_information = g_strdup_printf("Call ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
658 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
659 g_free(general_information);
660
661 gchar* description = g_strdup_printf("You\n"
662 "Framerate:\n"
663 "Video codec:\n"
664 "Audio codec:\n"
665 "Resolution:\n\n"
666 "Peer\n"
667 "Framerate:\n"
668 "Video codec:\n"
669 "Audio codec:\n"
670 "Resolution:");
671 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
672 g_free(description);
673
674 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",
675 (double)SmartInfoHub::instance().localFps(),
676 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
677 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
678 SmartInfoHub::instance().localWidth(),
679 SmartInfoHub::instance().localHeight(),
680 (double)SmartInfoHub::instance().remoteFps(),
681 SmartInfoHub::instance().remoteVideoCodec().toStdString().c_str(),
682 SmartInfoHub::instance().remoteAudioCodec().toStdString().c_str(),
683 SmartInfoHub::instance().remoteWidth(),
684 SmartInfoHub::instance().remoteHeight());
685 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
686 g_free(value);
687 } else {
688 gchar* general_information = g_strdup_printf("Conference ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
689 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
690 g_free(general_information);
691
692 gchar* description = g_strdup_printf("You\n"
693 "Framerate:\n"
694 "Video codec:\n"
695 "Audio codec:\n"
696 "Resolution:");
697 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
698 g_free(description);
699
700 gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d",
701 (double)SmartInfoHub::instance().localFps(),
702 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
703 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
704 SmartInfoHub::instance().localWidth(),
705 SmartInfoHub::instance().localHeight());
706 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
707 g_free(value);
708 }
709}
710
711
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500712static gboolean
713on_button_press_in_video_event(GtkWidget *self, GdkEventButton *event, CurrentCallView *view)
714{
715 g_return_val_if_fail(IS_VIDEO_WIDGET(self), FALSE);
716 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
717
718 /* on double click */
719 if (event->type == GDK_2BUTTON_PRESS) {
720 g_debug("double click in video");
721 g_signal_emit(G_OBJECT(view), current_call_view_signals[VIDEO_DOUBLE_CLICKED], 0);
722 }
723
724 return GDK_EVENT_PROPAGATE;
725}
726
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400727static void
728toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget* vbox_call_smartInfo)
729{
730 if (g_variant_get_boolean(g_action_get_state(G_ACTION(action)))) {
731 gtk_widget_show(vbox_call_smartInfo);
732 } else {
733 gtk_widget_hide(vbox_call_smartInfo);
734 }
735}
736
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400737static void
738set_call_info(CurrentCallView *view, Call *call) {
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500739 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
740
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400741 priv->call = call;
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400742
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500743
744 /* change some things depending on call state */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400745 update_state(view, priv->call);
746 update_details(view, priv->call);
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400747 update_person(view, priv->call->peerContactMethod()->contact());
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500748
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400749 priv->smartinfo_refresh_connection = QObject::connect(
750 &SmartInfoHub::instance(),
751 &SmartInfoHub::changed,
752 [view, priv]() { update_smartInfo(view); }
753 );
754
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500755 priv->state_change_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400756 priv->call,
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500757 &Call::stateChanged,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400758 [view, priv]() { update_state(view, priv->call); }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500759 );
760
761 priv->call_details_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400762 priv->call,
Stepan Salenikovich6dbaf262017-05-19 15:42:24 -0400763 &Call::changed,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400764 [view, priv]() { update_details(view, priv->call); }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500765 );
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500766
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400767 priv->cm_changed_connection = QObject::connect(
768 priv->call->peerContactMethod(),
769 &ContactMethod::changed,
770 [view]() { update_name_and_photo(view); }
771 );
772
773 priv->cm_person_changed_connection = QObject::connect(
774 priv->call->peerContactMethod(),
775 &ContactMethod::contactChanged,
776 [view] (Person* newPerson, Person*) { update_person(view, newPerson); }
777 );
778
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500779 /* check if we already have a renderer */
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400780 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400781 priv->call->videoRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400782 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500783
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400784 /* callback for remote renderer */
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400785 priv->remote_renderer_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400786 priv->call,
Stepan Salenikovich9c1f6682015-03-09 16:21:28 -0400787 &Call::videoStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400788 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400789 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
790 renderer,
791 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500792 }
793 );
Stepan Salenikovich4ac89f12015-03-10 16:48:47 -0400794
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400795 /* local renderer */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400796 if (Video::PreviewManager::instance().isPreviewing())
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400797 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400798 Video::PreviewManager::instance().previewRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400799 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400800
801 /* callback for local renderer */
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400802 priv->local_renderer_connection = QObject::connect(
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400803 &Video::PreviewManager::instance(),
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400804 &Video::PreviewManager::previewStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400805 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400806 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
807 renderer,
808 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400809 }
810 );
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400811
Julien Grossholtza0d4f102015-10-22 14:24:17 -0400812 /* handle video widget button click event */
813 g_signal_connect(priv->video_widget, "button-press-event", G_CALLBACK(video_widget_on_button_press_in_screen_event), priv->call);
814
815 /* handle video widget drag and drop*/
816 g_signal_connect(priv->video_widget, "drag-data-received", G_CALLBACK(video_widget_on_drag_data_received), priv->call);
817
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400818 /* catch double click to make full screen */
819 g_signal_connect(priv->video_widget, "button-press-event",
820 G_CALLBACK(on_button_press_in_video_event),
821 view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400822
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400823 /* handle smartinfo in right click menu */
824 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
825 priv->smartinfo_action = g_signal_connect(display_smartinfo,
826 "notify::state",
827 G_CALLBACK(toggle_smartinfo),
828 priv->vbox_call_smartInfo);
829
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500830 /* init chat view */
aviau039001d2016-09-29 16:39:05 -0400831 auto chat_view = chat_view_new_call(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), priv->call);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500832 gtk_container_add(GTK_CONTAINER(priv->frame_chat), chat_view);
833
834 /* check if there were any chat notifications and open the chat view if so */
Stepan Salenikovich26cd1602016-01-20 13:43:17 -0500835 if (ring_notify_close_chat_notification(priv->call->peerContactMethod()))
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500836 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
837
838 /* show chat view on any new incoming messages */
839 g_signal_connect_swapped(chat_view, "new-messages-displayed", G_CALLBACK(show_chat_view), view);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500840}
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400841
842GtkWidget *
aviau039001d2016-09-29 16:39:05 -0400843current_call_view_new(Call *call, WebKitChatContainer *webkit_chat_container)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400844{
845 auto self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
aviau039001d2016-09-29 16:39:05 -0400846 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
847 priv->webkit_chat_container = GTK_WIDGET(webkit_chat_container);
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400848 set_call_info(CURRENT_CALL_VIEW(self), call);
849
850 return GTK_WIDGET(self);
851}
852
853Call*
854current_call_view_get_call(CurrentCallView *self)
855{
856 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), nullptr);
857 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
858
859 return priv->call;
860}