blob: 3256032e9d1da45242c1b4bee27ef6e70e2b2d4b [file] [log] [blame]
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05001/*
Guillaume Roguez2a6150d2017-07-19 18:24:47 -04002 * Copyright (C) 2015-2017 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
Sébastien Blin55bff9d2017-10-03 15:15:23 -040022// Gtk
23#include <clutter-gtk/clutter-gtk.h>
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050024#include <gtk/gtk.h>
Stepan Salenikovich7e283552015-12-21 16:17:52 -050025#include <glib/gi18n.h>
Sébastien Blin55bff9d2017-10-03 15:15:23 -040026
27// Lrc
Stepan Salenikovichf6f42652015-07-15 12:46:14 -040028#include <account.h>
Sébastien Blin55bff9d2017-10-03 15:15:23 -040029#include <api/conversationmodel.h>
30#include <api/contact.h>
31#include <api/contactmodel.h>
32#include <api/newcallmodel.h>
33#include <codecmodel.h>
34#include <globalinstances.h>
Olivier Gregoire66e4df72016-06-17 18:39:05 -040035#include <smartinfohub.h>
Sébastien Blin55bff9d2017-10-03 15:15:23 -040036#include <video/previewmanager.h>
37
38// Client
39#include "chatview.h"
40#include "native/pixbufmanipulator.h"
41#include "ringnotify.h"
42#include "utils/drawing.h"
43#include "utils/files.h"
44#include "video/video_widget.h"
45
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;
AmarOke7c02972017-07-17 15:21:20 -040080 GtkWidget *togglebutton_muteaudio;
81 GtkWidget *togglebutton_mutevideo;
82 GtkWidget *togglebutton_hold;
Sébastien Blin55bff9d2017-10-03 15:15:23 -040083 GtkWidget *togglebutton_record;
Stepan Salenikovich77baa522015-07-07 15:29:14 -040084 GtkWidget *button_hangup;
Stepan Salenikovich7e283552015-12-21 16:17:52 -050085 GtkWidget *scalebutton_quality;
86 GtkWidget *checkbutton_autoquality;
Sébastien Blin366243f2017-11-03 14:14:54 -040087 GtkWidget *chat_view;
Stepan Salenikovich7e283552015-12-21 16:17:52 -050088
aviau039001d2016-09-29 16:39:05 -040089 /* The webkit_chat_container is created once, then reused for all chat
90 * views */
91 GtkWidget *webkit_chat_container;
92
Stepan Salenikovich7e283552015-12-21 16:17:52 -050093 /* flag used to keep track of the video quality scale pressed state;
94 * we do not want to update the codec bitrate until the user releases the
95 * scale button */
96 gboolean quality_scale_pressed;
Stepan Salenikovicha448f602015-05-29 13:33:06 -040097
Sébastien Blin55bff9d2017-10-03 15:15:23 -040098 lrc::api::conversation::Info* conversation_;
99 AccountContainer* accountContainer_;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500100
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500101 QMetaObject::Connection state_change_connection;
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400102 QMetaObject::Connection local_renderer_connection;
103 QMetaObject::Connection remote_renderer_connection;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400104 QMetaObject::Connection new_message_connection;
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500105
106 GSettings *settings;
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500107
108 // for clutter animations and to know when to fade in/out the overlays
109 ClutterTransition *fade_info;
110 ClutterTransition *fade_controls;
111 gint64 time_last_mouse_motion;
112 guint timer_fade;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400113
Stepan Salenikovich88092932017-05-15 18:19:00 -0400114 gulong insert_controls_id;
115
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400116 // smart info
117 QMetaObject::Connection smartinfo_refresh_connection;
118 guint smartinfo_action;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500119};
120
121G_DEFINE_TYPE_WITH_PRIVATE(CurrentCallView, current_call_view, GTK_TYPE_BOX);
122
123#define CURRENT_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CURRENT_CALL_VIEW_TYPE, CurrentCallViewPrivate))
124
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500125enum {
126 VIDEO_DOUBLE_CLICKED,
127 LAST_SIGNAL
128};
129
130static guint current_call_view_signals[LAST_SIGNAL] = { 0 };
131
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500132static void
133current_call_view_dispose(GObject *object)
134{
135 CurrentCallView *view;
136 CurrentCallViewPrivate *priv;
137
138 view = CURRENT_CALL_VIEW(object);
139 priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
140
141 QObject::disconnect(priv->state_change_connection);
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400142 QObject::disconnect(priv->local_renderer_connection);
143 QObject::disconnect(priv->remote_renderer_connection);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400144 QObject::disconnect(priv->smartinfo_refresh_connection);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400145 QObject::disconnect(priv->new_message_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
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400195static void
196update_details(CurrentCallView *view)
197{
198 auto *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
199 auto callRendered = priv->conversation_->callId;
200
201 if (!priv->conversation_->confId.empty())
202 callRendered = priv->conversation_->confId;
203
204 gtk_label_set_text(GTK_LABEL(priv->label_duration),
205 priv->accountContainer_->info.callModel->getFormattedCallDuration(callRendered).c_str());
206
207 auto call = priv->accountContainer_->info.callModel->getCall(callRendered);
208 gtk_widget_set_sensitive(GTK_WIDGET(priv->togglebutton_muteaudio), (call.type != lrc::api::call::Type::CONFERENCE));
209 gtk_widget_set_sensitive(GTK_WIDGET(priv->togglebutton_mutevideo), (call.type != lrc::api::call::Type::CONFERENCE));
210}
211
212
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500213static gboolean
214timeout_check_last_motion_event(CurrentCallView *self)
215{
216 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), G_SOURCE_REMOVE);
217 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
218
219 auto current_time = g_get_monotonic_time();
220 if (current_time - priv->time_last_mouse_motion >= CONTROLS_FADE_TIMEOUT) {
221 // timeout has passed, hide the controls
222 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_BACKWARD) {
223 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_FORWARD);
224 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_FORWARD);
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
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400234 update_details(self);
235
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500236 return G_SOURCE_CONTINUE;
237}
238
239static gboolean
240mouse_moved(CurrentCallView *self)
241{
242 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
243 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
244
245 priv->time_last_mouse_motion = g_get_monotonic_time();
246
247 // since the mouse moved, make sure the controls are shown
248 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_FORWARD) {
249 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
250 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
251 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
252 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
253 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
254 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
255 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
256 }
257 }
258
259 return FALSE; // propogate event
260}
261
262static ClutterTransition *
263create_fade_out_transition()
264{
265 auto transition = clutter_property_transition_new("opacity");
266 clutter_transition_set_from(transition, G_TYPE_UINT, 255);
267 clutter_transition_set_to(transition, G_TYPE_UINT, 0);
268 clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), FADE_DURATION);
269 clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), 0);
270 clutter_timeline_set_progress_mode(CLUTTER_TIMELINE(transition), CLUTTER_EASE_IN_OUT_CUBIC);
271 return transition;
272}
273
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500274static gboolean
275video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self)
276{
277 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
278 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
279
280 // if this widget already has focus, we want the focus to move to the next widget, otherwise we
281 // will get stuck in a focus loop on the buttons
282 if (gtk_widget_has_focus(widget))
283 return FALSE;
284
285 // otherwise we want the focus to go to and change between the call control buttons
286 if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
287 // selected a child, make sure call controls are shown
288 mouse_moved(self);
289 return TRUE;
290 }
291
292 // did not select the next child, propogate the event
293 return FALSE;
294}
295
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500296static GtkBox *
297gtk_scale_button_get_box(GtkScaleButton *button)
298{
299 GtkWidget *box = NULL;
300 if (auto dock = gtk_scale_button_get_popup(button)) {
301 // the dock is a popover which contains the box
302 box = gtk_bin_get_child(GTK_BIN(dock));
303 if (box) {
304 if (GTK_IS_FRAME(box)) {
305 // support older versions of gtk; the box used to be in a frame
306 box = gtk_bin_get_child(GTK_BIN(box));
307 }
308 }
309 }
310
311 return GTK_BOX(box);
312}
313
314/**
315 * This gets the GtkScaleButtonScale widget (which is a GtkScale) from the
316 * given GtkScaleButton in order to be able to modify its properties and connect
317 * to its signals
318 */
319static GtkScale *
320gtk_scale_button_get_scale(GtkScaleButton *button)
321{
322 GtkScale *scale = NULL;
323
324 if (auto box = gtk_scale_button_get_box(button)) {
325 GList *children = gtk_container_get_children(GTK_CONTAINER(box));
326 for (GList *c = children; c && !scale; c = c->next) {
327 if (GTK_IS_SCALE(c->data))
328 scale = GTK_SCALE(c->data);
329 }
330 g_list_free(children);
331 }
332
333 return scale;
334}
335
336static void
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500337autoquality_toggled(GtkToggleButton *button, CurrentCallView *self)
338{
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400339 // TODO
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500340 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
341 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
342
343 gboolean auto_quality_on = gtk_toggle_button_get_active(button);
344
345 auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality));
346 auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
347 auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
348
349 gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on);
350 gtk_widget_set_sensitive(plus_button, !auto_quality_on);
351 gtk_widget_set_sensitive(minus_button, !auto_quality_on);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500352}
353
354static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400355quality_changed(G_GNUC_UNUSED GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self)
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500356{
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400357 // TODO
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500358 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
359 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
360
361 /* no need to upate quality if auto quality is enabled */
362 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return;
363
364 /* only update if the scale button is released, to reduce the number of updates */
365 if (priv->quality_scale_pressed) return;
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500366}
367
368static gboolean
369quality_button_pressed(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
370{
371 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
372 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500373 priv->quality_scale_pressed = TRUE;
374
375 return GDK_EVENT_PROPAGATE;
376}
377
378static gboolean
379quality_button_released(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
380{
381 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
382 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500383 priv->quality_scale_pressed = FALSE;
384
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400385 // now make sure the quality gets updated
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500386 quality_changed(GTK_SCALE_BUTTON(priv->scalebutton_quality), 0, self);
387
388 return GDK_EVENT_PROPAGATE;
389}
390
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400391static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400392button_hangup_clicked(CurrentCallView *view)
393{
394 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
395 auto callToHangUp = priv->conversation_->callId;
396 if (!priv->conversation_->confId.empty())
397 callToHangUp = priv->conversation_->confId;
398 priv->accountContainer_->info.callModel->hangUp(callToHangUp);
399}
400
401static void
402togglebutton_hold_clicked(CurrentCallView *view)
403{
404 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
405 auto callToHold = priv->conversation_->callId;
406 if (!priv->conversation_->confId.empty())
407 callToHold = priv->conversation_->confId;
408 priv->accountContainer_->info.callModel->togglePause(callToHold);
409}
410
411static void
412togglebutton_record_clicked(CurrentCallView *view)
413{
414 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
415 auto callToRecord = priv->conversation_->callId;
416 if (!priv->conversation_->confId.empty())
417 callToRecord = priv->conversation_->confId;
418 priv->accountContainer_->info.callModel->toggleAudioRecord(callToRecord);
419}
420
421static void
422togglebutton_muteaudio_clicked(CurrentCallView *view)
423{
424 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
425 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
426 auto callToMute = priv->conversation_->callId;
427 if (!priv->conversation_->confId.empty())
428 callToMute = priv->conversation_->confId;
429 auto muteAudioBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
430 priv->accountContainer_->info.callModel->toggleMedia(callToMute,
Sébastien Blin1ffd4722017-11-06 15:38:08 -0500431 lrc::api::NewCallModel::Media::AUDIO);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400432
433 auto togglebutton = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
434 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_audio");
435 if (gtk_toggle_button_get_active(togglebutton))
436 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_audio");
437 gtk_button_set_image(GTK_BUTTON(togglebutton), image);
438}
439
440static void
441togglebutton_mutevideo_clicked(CurrentCallView *view)
442{
443 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
444 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
445 auto callToMute = priv->conversation_->callId;
446 if (!priv->conversation_->confId.empty())
447 callToMute = priv->conversation_->confId;
448 auto muteVideoBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
449 priv->accountContainer_->info.callModel->toggleMedia(callToMute,
Sébastien Blin1ffd4722017-11-06 15:38:08 -0500450 lrc::api::NewCallModel::Media::VIDEO);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400451
452 auto togglebutton = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
453 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_video");
454 if (gtk_toggle_button_get_active(togglebutton))
455 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_video");
456 gtk_button_set_image(GTK_BUTTON(togglebutton), image);
457}
458
459static void
Stepan Salenikovich88092932017-05-15 18:19:00 -0400460insert_controls(CurrentCallView *view)
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500461{
Stepan Salenikovich88092932017-05-15 18:19:00 -0400462 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400463
Stepan Salenikovich88092932017-05-15 18:19:00 -0400464 /* only add the controls once */
465 g_signal_handler_disconnect(view, priv->insert_controls_id);
466 priv->insert_controls_id = 0;
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500467
468 auto stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->video_widget));
469 auto actor_info = gtk_clutter_actor_new_with_contents(priv->hbox_call_info);
470 auto actor_controls = gtk_clutter_actor_new_with_contents(priv->hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400471 auto actor_smartInfo = gtk_clutter_actor_new_with_contents(priv->vbox_call_smartInfo);
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500472
473 clutter_actor_add_child(stage, actor_info);
474 clutter_actor_set_x_align(actor_info, CLUTTER_ACTOR_ALIGN_FILL);
475 clutter_actor_set_y_align(actor_info, CLUTTER_ACTOR_ALIGN_START);
476
477 clutter_actor_add_child(stage, actor_controls);
478 clutter_actor_set_x_align(actor_controls, CLUTTER_ACTOR_ALIGN_CENTER);
479 clutter_actor_set_y_align(actor_controls, CLUTTER_ACTOR_ALIGN_END);
480
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400481 clutter_actor_add_child(stage, actor_smartInfo);
482 clutter_actor_set_x_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_END);
483 clutter_actor_set_y_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_START);
484 ClutterMargin clutter_margin_smartInfo;
485 clutter_margin_smartInfo.top = 50;
486 clutter_margin_smartInfo.right = 10;
philippegorleya7337942017-07-04 15:29:42 -0400487 clutter_margin_smartInfo.left = 10;
488 clutter_margin_smartInfo.bottom = 10;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400489 clutter_actor_set_margin (actor_smartInfo, &clutter_margin_smartInfo);
490
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500491 /* add fade in and out states to the info and controls */
492 priv->time_last_mouse_motion = g_get_monotonic_time();
493 priv->fade_info = create_fade_out_transition();
494 priv->fade_controls = create_fade_out_transition();
495 clutter_actor_add_transition(actor_info, "fade_info", priv->fade_info);
496 clutter_actor_add_transition(actor_controls, "fade_controls", priv->fade_controls);
497 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
498 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
499 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_info));
500 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_controls));
501
502 /* have a timer check every 1 second if the controls should fade out */
503 priv->timer_fade = g_timeout_add(1000, (GSourceFunc)timeout_check_last_motion_event, view);
504
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400505 /* connect the controllers (new model) */
506 g_signal_connect_swapped(priv->button_hangup, "clicked", G_CALLBACK(button_hangup_clicked), view);
507 g_signal_connect_swapped(priv->togglebutton_hold, "clicked", G_CALLBACK(togglebutton_hold_clicked), view);
508 g_signal_connect_swapped(priv->togglebutton_muteaudio, "clicked", G_CALLBACK(togglebutton_muteaudio_clicked), view);
509 g_signal_connect_swapped(priv->togglebutton_record, "clicked", G_CALLBACK(togglebutton_record_clicked), view);
510 g_signal_connect_swapped(priv->togglebutton_mutevideo, "clicked", G_CALLBACK(togglebutton_mutevideo_clicked), view);
511
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500512 /* connect to the mouse motion event to reset the last moved time */
513 g_signal_connect_swapped(priv->video_widget, "motion-notify-event", G_CALLBACK(mouse_moved), view);
514 g_signal_connect_swapped(priv->video_widget, "button-press-event", G_CALLBACK(mouse_moved), view);
515 g_signal_connect_swapped(priv->video_widget, "button-release-event", G_CALLBACK(mouse_moved), view);
516
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500517 /* manually handle the focus of the video widget to be able to focus on the call controls */
518 g_signal_connect(priv->video_widget, "focus", G_CALLBACK(video_widget_focus), view);
519
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400520
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500521 /* toggle whether or not the chat is displayed */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400522 g_signal_connect(priv->togglebutton_chat, "toggled", G_CALLBACK(chat_toggled), view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400523
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500524 /* bind the chat orientation to the gsetting */
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500525 priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
526 g_settings_bind_with_mapping(priv->settings, "chat-pane-horizontal",
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500527 priv->paned_call, "orientation",
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500528 G_SETTINGS_BIND_GET,
529 map_boolean_to_orientation,
530 nullptr, nullptr, nullptr);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500531
532 g_signal_connect(priv->scalebutton_quality, "value-changed", G_CALLBACK(quality_changed), view);
533 /* customize the quality button scale */
534 if (auto scale_box = gtk_scale_button_get_box(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
535 priv->checkbutton_autoquality = gtk_check_button_new_with_label(C_("Enable automatic video quality", "Auto"));
536 gtk_widget_show(priv->checkbutton_autoquality);
537 gtk_box_pack_start(GTK_BOX(scale_box), priv->checkbutton_autoquality, FALSE, TRUE, 0);
538 g_signal_connect(priv->checkbutton_autoquality, "toggled", G_CALLBACK(autoquality_toggled), view);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500539 }
540 if (auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
541 g_signal_connect(scale, "button-press-event", G_CALLBACK(quality_button_pressed), view);
542 g_signal_connect(scale, "button-release-event", G_CALLBACK(quality_button_released), view);
543 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400544
Sébastien Blin4514eeb2017-07-25 14:17:01 -0400545 // Get if the user wants to show the smartInfo box
546 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
547 if (g_variant_get_boolean(g_action_get_state(G_ACTION(display_smartinfo)))) {
548 gtk_widget_show(priv->vbox_call_smartInfo);
549 } else {
550 gtk_widget_hide(priv->vbox_call_smartInfo);
551 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400552}
553
554static void
555current_call_view_init(CurrentCallView *view)
556{
557 gtk_widget_init_template(GTK_WIDGET(view));
558
559 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
560
561 // CSS styles
562 auto provider = gtk_css_provider_new();
563 gtk_css_provider_load_from_data(provider,
AmarOke7c02972017-07-17 15:21:20 -0400564 ".smartinfo-block-style { color: #8ae234; background-color: rgba(1, 1, 1, 0.33); } \
565 @keyframes blink { 0% {opacity: 1;} 49% {opacity: 1;} 50% {opacity: 0;} 100% {opacity: 0;} } \
566 .record-button { background: rgba(0, 0, 0, 1); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
567 .record-button:checked { animation: blink 1s; animation-iteration-count: infinite; } \
568 .call-button { background: rgba(0, 0, 0, 0); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
569 .call-button:hover { background: rgba(200, 200, 200, 0.15); } \
570 .call-button:disabled { opacity: 0.2; } \
571 .can-be-disabled:checked { background: rgba(219, 58, 55, 1); } \
572 .hangup-button-style { background: rgba(219, 58, 55, 1); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
573 .hangup-button-style:hover { background: rgba(219, 39, 25, 1); }",
Stepan Salenikovich88092932017-05-15 18:19:00 -0400574 -1, nullptr
575 );
576 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
577 GTK_STYLE_PROVIDER(provider),
578 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
579
580 priv->video_widget = video_widget_new();
581 gtk_container_add(GTK_CONTAINER(priv->frame_video), priv->video_widget);
582 gtk_widget_show_all(priv->frame_video);
583
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400584 // add the overlay controls only once the view has been allocated a size to prevent size
585 // allocation warnings in the log
Stepan Salenikovich88092932017-05-15 18:19:00 -0400586 priv->insert_controls_id = g_signal_connect(view, "size-allocate", G_CALLBACK(insert_controls), nullptr);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500587}
588
589static void
590current_call_view_class_init(CurrentCallViewClass *klass)
591{
592 G_OBJECT_CLASS(klass)->dispose = current_call_view_dispose;
593
594 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
595 "/cx/ring/RingGnome/currentcallview.ui");
596
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500597 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_info);
598 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400599 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, vbox_call_smartInfo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500600 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, image_peer);
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400601 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_name);
Nicolas Jager2e467c32017-01-18 08:52:23 -0500602 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_bestId);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500603 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_status);
604 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_duration);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400605 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_description);
606 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_value);
607 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_general_information);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500608 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, paned_call);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500609 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500610 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400611 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat);
AmarOke7c02972017-07-17 15:21:20 -0400612 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_hold);
613 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_muteaudio);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400614 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_record);
AmarOke7c02972017-07-17 15:21:20 -0400615 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_mutevideo);
Stepan Salenikovich77baa522015-07-07 15:29:14 -0400616 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, button_hangup);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500617 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, scalebutton_quality);
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500618
619 current_call_view_signals[VIDEO_DOUBLE_CLICKED] = g_signal_new (
620 "video-double-clicked",
621 G_TYPE_FROM_CLASS(klass),
622 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
623 0,
624 nullptr,
625 nullptr,
626 g_cclosure_marshal_VOID__VOID,
627 G_TYPE_NONE, 0);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500628}
629
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500630static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400631update_state(CurrentCallView *view)
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500632{
633 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400634 if (!priv || !priv->conversation_) return;
635 auto callId = priv->conversation_->callId;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500636
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400637 try {
638 auto call = priv->accountContainer_->info.callModel->getCall(callId);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500639
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400640 auto pauseBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_hold);
641 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/pause");
642 if (call.status == lrc::api::call::Status::PAUSED)
643 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/play");
644 gtk_button_set_image(GTK_BUTTON(pauseBtn), image);
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400645
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400646 auto audioButton = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
647 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio), call.audioMuted);
648 auto imageMuteAudio = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_audio");
649 if (call.audioMuted)
650 imageMuteAudio = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_audio");
651 gtk_button_set_image(GTK_BUTTON(audioButton), imageMuteAudio);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500652
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400653 auto videoButton = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
654 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo), call.videoMuted);
655 auto imageMuteVideo = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_video");
656 if (call.videoMuted)
657 imageMuteVideo = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_video");
658 gtk_button_set_image(GTK_BUTTON(videoButton), imageMuteVideo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500659
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400660 gchar *status = g_strdup_printf("%s", lrc::api::call::to_string(call.status).c_str());
661 gtk_label_set_text(GTK_LABEL(priv->label_status), status);
662 g_free(status);
663 } catch (std::out_of_range& e) {
664 g_warning("Can't update state for callId=%s", callId.c_str());
665 }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500666}
667
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400668static void
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400669update_name_and_photo(CurrentCallView *view)
670{
671 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
672
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400673 QVariant var_i = GlobalInstances::pixmapManipulator().conversationPhoto(
674 *priv->conversation_,
675 priv->accountContainer_->info,
676 QSize(60, 60),
677 false
678 );
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400679 std::shared_ptr<GdkPixbuf> image = var_i.value<std::shared_ptr<GdkPixbuf>>();
680 gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_peer), image.get());
681
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400682 auto contactInfo = priv->accountContainer_->info.contactModel->getContact(priv->conversation_->participants.front());
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400683
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400684 auto name = contactInfo.profileInfo.alias;
685 gtk_label_set_text(GTK_LABEL(priv->label_name), name.c_str());
686
687 auto bestId = contactInfo.registeredName;
688 if (name != bestId) {
689 gtk_label_set_text(GTK_LABEL(priv->label_bestId), bestId.c_str());
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400690 gtk_widget_show(priv->label_bestId);
691 }
692}
693
694static void
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400695update_smartInfo(CurrentCallView *view)
696{
697 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
698
699 if (!SmartInfoHub::instance().isConference()) {
700 gchar* general_information = g_strdup_printf("Call ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
701 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
702 g_free(general_information);
703
704 gchar* description = g_strdup_printf("You\n"
705 "Framerate:\n"
706 "Video codec:\n"
707 "Audio codec:\n"
708 "Resolution:\n\n"
709 "Peer\n"
710 "Framerate:\n"
711 "Video codec:\n"
712 "Audio codec:\n"
713 "Resolution:");
714 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
715 g_free(description);
716
717 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",
718 (double)SmartInfoHub::instance().localFps(),
719 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
720 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
721 SmartInfoHub::instance().localWidth(),
722 SmartInfoHub::instance().localHeight(),
723 (double)SmartInfoHub::instance().remoteFps(),
724 SmartInfoHub::instance().remoteVideoCodec().toStdString().c_str(),
725 SmartInfoHub::instance().remoteAudioCodec().toStdString().c_str(),
726 SmartInfoHub::instance().remoteWidth(),
727 SmartInfoHub::instance().remoteHeight());
728 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
729 g_free(value);
730 } else {
731 gchar* general_information = g_strdup_printf("Conference ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
732 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
733 g_free(general_information);
734
735 gchar* description = g_strdup_printf("You\n"
736 "Framerate:\n"
737 "Video codec:\n"
738 "Audio codec:\n"
739 "Resolution:");
740 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
741 g_free(description);
742
743 gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d",
744 (double)SmartInfoHub::instance().localFps(),
745 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
746 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
747 SmartInfoHub::instance().localWidth(),
748 SmartInfoHub::instance().localHeight());
749 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
750 g_free(value);
751 }
752}
753
754
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500755static gboolean
756on_button_press_in_video_event(GtkWidget *self, GdkEventButton *event, CurrentCallView *view)
757{
758 g_return_val_if_fail(IS_VIDEO_WIDGET(self), FALSE);
759 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
760
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400761 // on double click
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500762 if (event->type == GDK_2BUTTON_PRESS) {
763 g_debug("double click in video");
764 g_signal_emit(G_OBJECT(view), current_call_view_signals[VIDEO_DOUBLE_CLICKED], 0);
765 }
766
767 return GDK_EVENT_PROPAGATE;
768}
769
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400770static void
771toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget* vbox_call_smartInfo)
772{
773 if (g_variant_get_boolean(g_action_get_state(G_ACTION(action)))) {
774 gtk_widget_show(vbox_call_smartInfo);
775 } else {
776 gtk_widget_hide(vbox_call_smartInfo);
777 }
778}
779
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400780
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400781static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400782set_call_info(CurrentCallView *view) {
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500783 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
784
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400785 // change some things depending on call state
786 update_state(view);
787 update_details(view);
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400788
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400789 // NOTE/TODO we need to rewrite the video_widget file to use the new LRC.
790 g_signal_connect(priv->video_widget, "button-press-event", G_CALLBACK(video_widget_on_button_press_in_screen_event), nullptr);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500791
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400792 // check if we already have a renderer
793 auto callToRender = priv->conversation_->callId;
794 if (!priv->conversation_->confId.empty())
795 callToRender = priv->conversation_->confId;
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400796 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400797 priv->accountContainer_->info.callModel->getRenderer(callToRender),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400798 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500799
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400800 // local renderer
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400801 if (Video::PreviewManager::instance().isPreviewing())
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400802 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400803 Video::PreviewManager::instance().previewRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400804 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400805
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400806 // callback for local renderer
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400807 priv->local_renderer_connection = QObject::connect(
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400808 &Video::PreviewManager::instance(),
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400809 &Video::PreviewManager::previewStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400810 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400811 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
812 renderer,
813 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400814 }
815 );
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400816
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400817 priv->smartinfo_refresh_connection = QObject::connect(
818 &SmartInfoHub::instance(),
819 &SmartInfoHub::changed,
820 [view, priv]() { update_smartInfo(view); }
821 );
Julien Grossholtza0d4f102015-10-22 14:24:17 -0400822
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400823 priv->remote_renderer_connection = QObject::connect(
824 &*priv->accountContainer_->info.callModel,
825 &lrc::api::NewCallModel::remotePreviewStarted,
826 [priv](const std::string& callId, Video::Renderer *renderer) {
827 if (priv->conversation_->callId == callId) {
828 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
829 renderer,
830 VIDEO_RENDERER_REMOTE);
831 }
832 }
833 );
Julien Grossholtza0d4f102015-10-22 14:24:17 -0400834
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400835 priv->state_change_connection = QObject::connect(
836 &*priv->accountContainer_->info.callModel,
837 &lrc::api::NewCallModel::callStatusChanged,
838 [view, priv] (const std::string& callId) {
839 if (callId == priv->conversation_->callId) {
840 update_state(view);
841 update_name_and_photo(view);
842 }
843 });
844
845 priv->new_message_connection = QObject::connect(
846 &*priv->accountContainer_->info.conversationModel, &lrc::api::ConversationModel::newUnreadMessage,
847 [priv](const std::string& uid, uint64_t msgId, lrc::api::interaction::Info msg) {
848 Q_UNUSED(uid)
849 Q_UNUSED(msgId)
850 Q_UNUSED(msg)
851 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
852 });
853
854
855 // catch double click to make full screen
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400856 g_signal_connect(priv->video_widget, "button-press-event",
857 G_CALLBACK(on_button_press_in_video_event),
858 view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400859
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400860 // handle smartinfo in right click menu
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400861 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
862 priv->smartinfo_action = g_signal_connect(display_smartinfo,
863 "notify::state",
864 G_CALLBACK(toggle_smartinfo),
865 priv->vbox_call_smartInfo);
866
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400867 // init chat view
Sébastien Blin366243f2017-11-03 14:14:54 -0400868 priv->chat_view = chat_view_new(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), priv->accountContainer_, priv->conversation_);
869 gtk_container_add(GTK_CONTAINER(priv->frame_chat), priv->chat_view);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500870
Sébastien Blin366243f2017-11-03 14:14:54 -0400871 g_signal_connect_swapped(priv->chat_view, "new-interactions-displayed", G_CALLBACK(show_chat_view), view);
872 chat_view_set_header_visible(CHAT_VIEW(priv->chat_view), FALSE);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400873
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500874}
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400875
876GtkWidget *
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400877current_call_view_new(WebKitChatContainer* view, AccountContainer* accountContainer, lrc::api::conversation::Info* conversation)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400878{
879 auto self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
aviau039001d2016-09-29 16:39:05 -0400880 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400881 priv->webkit_chat_container = GTK_WIDGET(view);
882 priv->conversation_ = conversation;
883 priv->accountContainer_ = accountContainer;
884 set_call_info(CURRENT_CALL_VIEW(self));
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400885
886 return GTK_WIDGET(self);
887}
888
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400889lrc::api::conversation::Info
890current_call_view_get_conversation(CurrentCallView *self)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400891{
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400892 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), lrc::api::conversation::Info());
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400893 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
894
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400895 return *priv->conversation_;
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400896}
Sébastien Blin366243f2017-11-03 14:14:54 -0400897
898GtkWidget *
899current_call_view_get_chat_view(CurrentCallView *self)
900{
901 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), nullptr);
902 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
903 return priv->chat_view;
904}