blob: e928027788bd9264f4af594d98b986721798bde6 [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;
69 GtkWidget *label_uri;
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
84 /* flag used to keep track of the video quality scale pressed state;
85 * we do not want to update the codec bitrate until the user releases the
86 * scale button */
87 gboolean quality_scale_pressed;
Stepan Salenikovicha448f602015-05-29 13:33:06 -040088
89 Call *call;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050090
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050091 QMetaObject::Connection state_change_connection;
92 QMetaObject::Connection call_details_connection;
Stepan Salenikovichc5f08152015-03-19 00:53:23 -040093 QMetaObject::Connection local_renderer_connection;
94 QMetaObject::Connection remote_renderer_connection;
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -050095
96 GSettings *settings;
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -050097
98 // for clutter animations and to know when to fade in/out the overlays
99 ClutterTransition *fade_info;
100 ClutterTransition *fade_controls;
101 gint64 time_last_mouse_motion;
102 guint timer_fade;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400103
104 // smart info
105 QMetaObject::Connection smartinfo_refresh_connection;
106 guint smartinfo_action;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500107};
108
109G_DEFINE_TYPE_WITH_PRIVATE(CurrentCallView, current_call_view, GTK_TYPE_BOX);
110
111#define CURRENT_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CURRENT_CALL_VIEW_TYPE, CurrentCallViewPrivate))
112
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500113enum {
114 VIDEO_DOUBLE_CLICKED,
115 LAST_SIGNAL
116};
117
118static guint current_call_view_signals[LAST_SIGNAL] = { 0 };
119
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500120static void
121current_call_view_dispose(GObject *object)
122{
123 CurrentCallView *view;
124 CurrentCallViewPrivate *priv;
125
126 view = CURRENT_CALL_VIEW(object);
127 priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
128
129 QObject::disconnect(priv->state_change_connection);
130 QObject::disconnect(priv->call_details_connection);
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400131 QObject::disconnect(priv->local_renderer_connection);
132 QObject::disconnect(priv->remote_renderer_connection);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400133 QObject::disconnect(priv->smartinfo_refresh_connection);
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500134 g_clear_object(&priv->settings);
135
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500136 g_source_remove(priv->timer_fade);
137
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400138 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
139 g_signal_handler_disconnect(display_smartinfo, priv->smartinfo_action);
140
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500141 G_OBJECT_CLASS(current_call_view_parent_class)->dispose(object);
142}
143
144static void
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500145show_chat_view(CurrentCallView *self)
146{
147 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
148 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
149
150 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
151}
152
153static void
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400154chat_toggled(GtkToggleButton *togglebutton, CurrentCallView *self)
155{
156 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
157 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
158
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400159 if (gtk_toggle_button_get_active(togglebutton)) {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500160 gtk_widget_show_all(priv->frame_chat);
161 gtk_widget_grab_focus(priv->frame_chat);
Stepan Salenikovicha5129f62015-11-05 15:10:59 -0500162 } else {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500163 gtk_widget_hide(priv->frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400164 }
165}
166
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500167gboolean
168map_boolean_to_orientation(GValue *value, GVariant *variant, G_GNUC_UNUSED gpointer user_data)
169{
170 if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
171 if (g_variant_get_boolean(variant)) {
172 // true, chat should be horizontal (to the right)
173 g_value_set_enum(value, GTK_ORIENTATION_HORIZONTAL);
174 } else {
175 // false, chat should be vertical (at the bottom)
176 g_value_set_enum(value, GTK_ORIENTATION_VERTICAL);
177 }
178 return TRUE;
179 }
180 return FALSE;
181}
182
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500183static gboolean
184timeout_check_last_motion_event(CurrentCallView *self)
185{
186 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), G_SOURCE_REMOVE);
187 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
188
189 auto current_time = g_get_monotonic_time();
190 if (current_time - priv->time_last_mouse_motion >= CONTROLS_FADE_TIMEOUT) {
191 // timeout has passed, hide the controls
192 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_BACKWARD) {
193 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_FORWARD);
194 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_FORWARD);
195 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
196 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
197 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
198 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
199 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
200 }
201 }
202 }
203
204 return G_SOURCE_CONTINUE;
205}
206
207static gboolean
208mouse_moved(CurrentCallView *self)
209{
210 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
211 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
212
213 priv->time_last_mouse_motion = g_get_monotonic_time();
214
215 // since the mouse moved, make sure the controls are shown
216 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_FORWARD) {
217 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
218 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
219 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
220 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
221 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
222 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
223 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
224 }
225 }
226
227 return FALSE; // propogate event
228}
229
230static ClutterTransition *
231create_fade_out_transition()
232{
233 auto transition = clutter_property_transition_new("opacity");
234 clutter_transition_set_from(transition, G_TYPE_UINT, 255);
235 clutter_transition_set_to(transition, G_TYPE_UINT, 0);
236 clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), FADE_DURATION);
237 clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), 0);
238 clutter_timeline_set_progress_mode(CLUTTER_TIMELINE(transition), CLUTTER_EASE_IN_OUT_CUBIC);
239 return transition;
240}
241
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500242static gboolean
243video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self)
244{
245 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
246 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
247
248 // if this widget already has focus, we want the focus to move to the next widget, otherwise we
249 // will get stuck in a focus loop on the buttons
250 if (gtk_widget_has_focus(widget))
251 return FALSE;
252
253 // otherwise we want the focus to go to and change between the call control buttons
254 if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
255 // selected a child, make sure call controls are shown
256 mouse_moved(self);
257 return TRUE;
258 }
259
260 // did not select the next child, propogate the event
261 return FALSE;
262}
263
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500264static GtkBox *
265gtk_scale_button_get_box(GtkScaleButton *button)
266{
267 GtkWidget *box = NULL;
268 if (auto dock = gtk_scale_button_get_popup(button)) {
269 // the dock is a popover which contains the box
270 box = gtk_bin_get_child(GTK_BIN(dock));
271 if (box) {
272 if (GTK_IS_FRAME(box)) {
273 // support older versions of gtk; the box used to be in a frame
274 box = gtk_bin_get_child(GTK_BIN(box));
275 }
276 }
277 }
278
279 return GTK_BOX(box);
280}
281
282/**
283 * This gets the GtkScaleButtonScale widget (which is a GtkScale) from the
284 * given GtkScaleButton in order to be able to modify its properties and connect
285 * to its signals
286 */
287static GtkScale *
288gtk_scale_button_get_scale(GtkScaleButton *button)
289{
290 GtkScale *scale = NULL;
291
292 if (auto box = gtk_scale_button_get_box(button)) {
293 GList *children = gtk_container_get_children(GTK_CONTAINER(box));
294 for (GList *c = children; c && !scale; c = c->next) {
295 if (GTK_IS_SCALE(c->data))
296 scale = GTK_SCALE(c->data);
297 }
298 g_list_free(children);
299 }
300
301 return scale;
302}
303
304static void
305set_quality(Call *call, gboolean auto_quality_on, double desired_quality)
306{
307 /* set auto quality true or false, also set the bitrate and quality values;
308 * the slider is from 0 to 100, use the min and max vals to scale each value accordingly */
309 if (const auto& codecModel = call->account()->codecModel()) {
310 const auto& videoCodecs = codecModel->videoCodecs();
311
312 for (int i=0; i < videoCodecs->rowCount();i++) {
313 const auto& idx = videoCodecs->index(i,0);
314
315 if (auto_quality_on) {
316 // g_debug("enable auto quality");
317 videoCodecs->setData(idx, "true", CodecModel::Role::AUTO_QUALITY_ENABLED);
318 } else {
319 auto min_bitrate = idx.data(static_cast<int>(CodecModel::Role::MIN_BITRATE)).toInt();
320 auto max_bitrate = idx.data(static_cast<int>(CodecModel::Role::MAX_BITRATE)).toInt();
321 auto min_quality = idx.data(static_cast<int>(CodecModel::Role::MIN_QUALITY)).toInt();
322 auto max_quality = idx.data(static_cast<int>(CodecModel::Role::MAX_QUALITY)).toInt();
323
324 // g_debug("bitrate min: %d, max: %d, quality min: %d, max: %d", min_bitrate, max_bitrate, min_quality, max_quality);
325
326 double bitrate;
327 bitrate = min_bitrate + (double)(max_bitrate - min_bitrate)*(desired_quality/100.0);
328 if (bitrate < 0) bitrate = 0;
329
330 double quality;
331 // note: a lower value means higher quality
332 quality = (double)min_quality - (min_quality - max_quality)*(desired_quality/100.0);
333 if (quality < 0) quality = 0;
334
335 // g_debug("disable auto quality; %% quality: %d; bitrate: %d; quality: %d", (int)desired_quality, (int)bitrate, (int)quality);
336 videoCodecs->setData(idx, "false", CodecModel::Role::AUTO_QUALITY_ENABLED);
337 videoCodecs->setData(idx, QString::number((int)bitrate), CodecModel::Role::BITRATE);
338 videoCodecs->setData(idx, QString::number((int)quality), CodecModel::Role::QUALITY);
339 }
340 }
341 codecModel << CodecModel::EditAction::SAVE;
342 }
343}
344
345static void
346autoquality_toggled(GtkToggleButton *button, CurrentCallView *self)
347{
348 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
349 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
350
351 gboolean auto_quality_on = gtk_toggle_button_get_active(button);
352
353 auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality));
354 auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
355 auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
356
357 gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on);
358 gtk_widget_set_sensitive(plus_button, !auto_quality_on);
359 gtk_widget_set_sensitive(minus_button, !auto_quality_on);
360
361 double desired_quality = gtk_scale_button_get_value(GTK_SCALE_BUTTON(priv->scalebutton_quality));
362
363 if (priv->call)
364 set_quality(priv->call, auto_quality_on, desired_quality);
365}
366
367static void
368quality_changed(GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self)
369{
370 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
371 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
372
373 /* no need to upate quality if auto quality is enabled */
374 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return;
375
376 /* only update if the scale button is released, to reduce the number of updates */
377 if (priv->quality_scale_pressed) return;
378
379 /* we get the value directly from the widget, in case this function is not
380 * called from the event */
381 if (priv->call)
382 set_quality(priv->call, FALSE, gtk_scale_button_get_value(button));
383}
384
385static gboolean
386quality_button_pressed(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
387{
388 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
389 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
390
391 priv->quality_scale_pressed = TRUE;
392
393 return GDK_EVENT_PROPAGATE;
394}
395
396static gboolean
397quality_button_released(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
398{
399 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
400 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
401
402 priv->quality_scale_pressed = FALSE;
403
404 /* now make sure the quality gets updated */
405 quality_changed(GTK_SCALE_BUTTON(priv->scalebutton_quality), 0, self);
406
407 return GDK_EVENT_PROPAGATE;
408}
409
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400410static void
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500411current_call_view_init(CurrentCallView *view)
412{
413 gtk_widget_init_template(GTK_WIDGET(view));
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400414
415 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
416
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500417 /* create video widget and overlay the call info and controls on it */
418 priv->video_widget = video_widget_new();
419 gtk_container_add(GTK_CONTAINER(priv->frame_video), priv->video_widget);
420 gtk_widget_show_all(priv->frame_video);
421
422 auto stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->video_widget));
423 auto actor_info = gtk_clutter_actor_new_with_contents(priv->hbox_call_info);
424 auto actor_controls = gtk_clutter_actor_new_with_contents(priv->hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400425 auto actor_smartInfo = gtk_clutter_actor_new_with_contents(priv->vbox_call_smartInfo);
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500426
427 clutter_actor_add_child(stage, actor_info);
428 clutter_actor_set_x_align(actor_info, CLUTTER_ACTOR_ALIGN_FILL);
429 clutter_actor_set_y_align(actor_info, CLUTTER_ACTOR_ALIGN_START);
430
431 clutter_actor_add_child(stage, actor_controls);
432 clutter_actor_set_x_align(actor_controls, CLUTTER_ACTOR_ALIGN_CENTER);
433 clutter_actor_set_y_align(actor_controls, CLUTTER_ACTOR_ALIGN_END);
434
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400435 clutter_actor_add_child(stage, actor_smartInfo);
436 clutter_actor_set_x_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_END);
437 clutter_actor_set_y_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_START);
438 ClutterMargin clutter_margin_smartInfo;
439 clutter_margin_smartInfo.top = 50;
440 clutter_margin_smartInfo.right = 10;
441 clutter_actor_set_margin (actor_smartInfo, &clutter_margin_smartInfo);
442
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500443 /* add fade in and out states to the info and controls */
444 priv->time_last_mouse_motion = g_get_monotonic_time();
445 priv->fade_info = create_fade_out_transition();
446 priv->fade_controls = create_fade_out_transition();
447 clutter_actor_add_transition(actor_info, "fade_info", priv->fade_info);
448 clutter_actor_add_transition(actor_controls, "fade_controls", priv->fade_controls);
449 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
450 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
451 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_info));
452 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_controls));
453
454 /* have a timer check every 1 second if the controls should fade out */
455 priv->timer_fade = g_timeout_add(1000, (GSourceFunc)timeout_check_last_motion_event, view);
456
457 /* connect to the mouse motion event to reset the last moved time */
458 g_signal_connect_swapped(priv->video_widget, "motion-notify-event", G_CALLBACK(mouse_moved), view);
459 g_signal_connect_swapped(priv->video_widget, "button-press-event", G_CALLBACK(mouse_moved), view);
460 g_signal_connect_swapped(priv->video_widget, "button-release-event", G_CALLBACK(mouse_moved), view);
461
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500462 /* manually handle the focus of the video widget to be able to focus on the call controls */
463 g_signal_connect(priv->video_widget, "focus", G_CALLBACK(video_widget_focus), view);
464
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500465 /* toggle whether or not the chat is displayed */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400466 g_signal_connect(priv->togglebutton_chat, "toggled", G_CALLBACK(chat_toggled), view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400467
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500468 /* bind the chat orientation to the gsetting */
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500469 priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
470 g_settings_bind_with_mapping(priv->settings, "chat-pane-horizontal",
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500471 priv->paned_call, "orientation",
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500472 G_SETTINGS_BIND_GET,
473 map_boolean_to_orientation,
474 nullptr, nullptr, nullptr);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500475
476 g_signal_connect(priv->scalebutton_quality, "value-changed", G_CALLBACK(quality_changed), view);
477 /* customize the quality button scale */
478 if (auto scale_box = gtk_scale_button_get_box(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
479 priv->checkbutton_autoquality = gtk_check_button_new_with_label(C_("Enable automatic video quality", "Auto"));
480 gtk_widget_show(priv->checkbutton_autoquality);
481 gtk_box_pack_start(GTK_BOX(scale_box), priv->checkbutton_autoquality, FALSE, TRUE, 0);
482 g_signal_connect(priv->checkbutton_autoquality, "toggled", G_CALLBACK(autoquality_toggled), view);
483 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), TRUE);
484 }
485 if (auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
486 g_signal_connect(scale, "button-press-event", G_CALLBACK(quality_button_pressed), view);
487 g_signal_connect(scale, "button-release-event", G_CALLBACK(quality_button_released), view);
488 }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500489}
490
491static void
492current_call_view_class_init(CurrentCallViewClass *klass)
493{
494 G_OBJECT_CLASS(klass)->dispose = current_call_view_dispose;
495
496 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
497 "/cx/ring/RingGnome/currentcallview.ui");
498
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500499 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_info);
500 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400501 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, vbox_call_smartInfo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500502 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, image_peer);
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400503 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_name);
504 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_uri);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500505 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_status);
506 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_duration);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400507 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_description);
508 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_value);
509 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_general_information);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500510 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, paned_call);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500511 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500512 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400513 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat);
Stepan Salenikovich77baa522015-07-07 15:29:14 -0400514 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, button_hangup);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500515 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, scalebutton_quality);
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500516
517 current_call_view_signals[VIDEO_DOUBLE_CLICKED] = g_signal_new (
518 "video-double-clicked",
519 G_TYPE_FROM_CLASS(klass),
520 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
521 0,
522 nullptr,
523 nullptr,
524 g_cclosure_marshal_VOID__VOID,
525 G_TYPE_NONE, 0);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500526}
527
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500528static void
529update_state(CurrentCallView *view, Call *call)
530{
531 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
532
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400533 gchar *status = g_strdup_printf("%s", call->toHumanStateName().toUtf8().constData());
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500534
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400535 gtk_label_set_text(GTK_LABEL(priv->label_status), status);
536
537 g_free(status);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500538}
539
540static void
541update_details(CurrentCallView *view, Call *call)
542{
543 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
544
545 /* update call duration */
546 QByteArray ba_length = call->length().toLocal8Bit();
547 gtk_label_set_text(GTK_LABEL(priv->label_duration), ba_length.constData());
548}
549
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400550static void
551update_smartInfo(CurrentCallView *view)
552{
553 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
554
555 if (!SmartInfoHub::instance().isConference()) {
556 gchar* general_information = g_strdup_printf("Call ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
557 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
558 g_free(general_information);
559
560 gchar* description = g_strdup_printf("You\n"
561 "Framerate:\n"
562 "Video codec:\n"
563 "Audio codec:\n"
564 "Resolution:\n\n"
565 "Peer\n"
566 "Framerate:\n"
567 "Video codec:\n"
568 "Audio codec:\n"
569 "Resolution:");
570 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
571 g_free(description);
572
573 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",
574 (double)SmartInfoHub::instance().localFps(),
575 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
576 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
577 SmartInfoHub::instance().localWidth(),
578 SmartInfoHub::instance().localHeight(),
579 (double)SmartInfoHub::instance().remoteFps(),
580 SmartInfoHub::instance().remoteVideoCodec().toStdString().c_str(),
581 SmartInfoHub::instance().remoteAudioCodec().toStdString().c_str(),
582 SmartInfoHub::instance().remoteWidth(),
583 SmartInfoHub::instance().remoteHeight());
584 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
585 g_free(value);
586 } else {
587 gchar* general_information = g_strdup_printf("Conference ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
588 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
589 g_free(general_information);
590
591 gchar* description = g_strdup_printf("You\n"
592 "Framerate:\n"
593 "Video codec:\n"
594 "Audio codec:\n"
595 "Resolution:");
596 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
597 g_free(description);
598
599 gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d",
600 (double)SmartInfoHub::instance().localFps(),
601 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
602 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
603 SmartInfoHub::instance().localWidth(),
604 SmartInfoHub::instance().localHeight());
605 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
606 g_free(value);
607 }
608}
609
610
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500611static gboolean
612on_button_press_in_video_event(GtkWidget *self, GdkEventButton *event, CurrentCallView *view)
613{
614 g_return_val_if_fail(IS_VIDEO_WIDGET(self), FALSE);
615 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
616
617 /* on double click */
618 if (event->type == GDK_2BUTTON_PRESS) {
619 g_debug("double click in video");
620 g_signal_emit(G_OBJECT(view), current_call_view_signals[VIDEO_DOUBLE_CLICKED], 0);
621 }
622
623 return GDK_EVENT_PROPAGATE;
624}
625
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400626static void
627toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget* vbox_call_smartInfo)
628{
629 if (g_variant_get_boolean(g_action_get_state(G_ACTION(action)))) {
630 gtk_widget_show(vbox_call_smartInfo);
631 } else {
632 gtk_widget_hide(vbox_call_smartInfo);
633 }
634}
635
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400636static void
637set_call_info(CurrentCallView *view, Call *call) {
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500638 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
639
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400640 priv->call = call;
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400641
642 /* get call image */
Stepan Salenikovichbbd6c132015-08-20 15:21:48 -0400643 QVariant var_i = GlobalInstances::pixmapManipulator().callPhoto(priv->call, QSize(60, 60), false);
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400644 std::shared_ptr<GdkPixbuf> image = var_i.value<std::shared_ptr<GdkPixbuf>>();
645 gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_peer), image.get());
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500646
647 /* get name */
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400648 auto name = call->formattedName();
649 gtk_label_set_text(GTK_LABEL(priv->label_name), name.toUtf8().constData());
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400650
651 /* get uri, if different from name */
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400652 auto uri = call->peerContactMethod()->uri();
653 if (name != uri) {
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400654 auto cat_uri = g_strdup_printf("(%s) %s"
655 ,priv->call->peerContactMethod()->category()->name().toUtf8().constData()
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400656 ,uri.toUtf8().constData());
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400657 gtk_label_set_text(GTK_LABEL(priv->label_uri), cat_uri);
658 g_free(cat_uri);
659 gtk_widget_show(priv->label_uri);
660 }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500661
662 /* change some things depending on call state */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400663 update_state(view, priv->call);
664 update_details(view, priv->call);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500665
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400666 priv->smartinfo_refresh_connection = QObject::connect(
667 &SmartInfoHub::instance(),
668 &SmartInfoHub::changed,
669 [view, priv]() { update_smartInfo(view); }
670 );
671
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500672 priv->state_change_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400673 priv->call,
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500674 &Call::stateChanged,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400675 [view, priv]() { update_state(view, priv->call); }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500676 );
677
678 priv->call_details_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400679 priv->call,
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500680 static_cast<void (Call::*)(void)>(&Call::changed),
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400681 [view, priv]() { update_details(view, priv->call); }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500682 );
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500683
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500684 /* check if we already have a renderer */
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400685 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400686 priv->call->videoRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400687 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500688
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400689 /* callback for remote renderer */
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400690 priv->remote_renderer_connection = QObject::connect(
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400691 priv->call,
Stepan Salenikovich9c1f6682015-03-09 16:21:28 -0400692 &Call::videoStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400693 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400694 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
695 renderer,
696 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500697 }
698 );
Stepan Salenikovich4ac89f12015-03-10 16:48:47 -0400699
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400700 /* local renderer */
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400701 if (Video::PreviewManager::instance().isPreviewing())
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400702 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400703 Video::PreviewManager::instance().previewRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400704 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400705
706 /* callback for local renderer */
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400707 priv->local_renderer_connection = QObject::connect(
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400708 &Video::PreviewManager::instance(),
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400709 &Video::PreviewManager::previewStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400710 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400711 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
712 renderer,
713 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400714 }
715 );
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400716
Julien Grossholtza0d4f102015-10-22 14:24:17 -0400717 /* handle video widget button click event */
718 g_signal_connect(priv->video_widget, "button-press-event", G_CALLBACK(video_widget_on_button_press_in_screen_event), priv->call);
719
720 /* handle video widget drag and drop*/
721 g_signal_connect(priv->video_widget, "drag-data-received", G_CALLBACK(video_widget_on_drag_data_received), priv->call);
722
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400723 /* catch double click to make full screen */
724 g_signal_connect(priv->video_widget, "button-press-event",
725 G_CALLBACK(on_button_press_in_video_event),
726 view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400727
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400728 /* handle smartinfo in right click menu */
729 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
730 priv->smartinfo_action = g_signal_connect(display_smartinfo,
731 "notify::state",
732 G_CALLBACK(toggle_smartinfo),
733 priv->vbox_call_smartInfo);
734
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500735 /* check if auto quality is enabled or not; */
736 if (const auto& codecModel = priv->call->account()->codecModel()) {
737 const auto& videoCodecs = codecModel->videoCodecs();
738 if (videoCodecs->rowCount() > 0) {
739 /* we only need to check the first codec since by default it is ON for all, and the
740 * gnome client sets its ON or OFF for all codecs as well */
741 const auto& idx = videoCodecs->index(0,0);
742 auto auto_quality_enabled = idx.data(static_cast<int>(CodecModel::Role::AUTO_QUALITY_ENABLED)).toString() == "true";
743 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), auto_quality_enabled);
744
745 // TODO: save the manual quality setting in the client and set the slider to that value here;
746 // the daemon resets the bitrate/quality between each call, and the default may be
747 // different for each codec, so there is no reason to check it here
748 }
749 }
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500750
751 /* init chat view */
Stepan Salenikovichc6a3b982016-01-11 18:11:39 -0500752 auto chat_view = chat_view_new_call(priv->call);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500753 gtk_container_add(GTK_CONTAINER(priv->frame_chat), chat_view);
754
755 /* check if there were any chat notifications and open the chat view if so */
Stepan Salenikovich26cd1602016-01-20 13:43:17 -0500756 if (ring_notify_close_chat_notification(priv->call->peerContactMethod()))
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500757 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
758
759 /* show chat view on any new incoming messages */
760 g_signal_connect_swapped(chat_view, "new-messages-displayed", G_CALLBACK(show_chat_view), view);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500761}
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400762
763GtkWidget *
764current_call_view_new(Call *call)
765{
766 auto self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
767 set_call_info(CURRENT_CALL_VIEW(self), call);
768
769 return GTK_WIDGET(self);
770}
771
772Call*
773current_call_view_get_call(CurrentCallView *self)
774{
775 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), nullptr);
776 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
777
778 return priv->call;
779}