blob: a3e0fbf379f9d4bbf47f0ae0b300e21a2f508fd7 [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;
87
aviau039001d2016-09-29 16:39:05 -040088 /* The webkit_chat_container is created once, then reused for all chat
89 * views */
90 GtkWidget *webkit_chat_container;
91
Stepan Salenikovich7e283552015-12-21 16:17:52 -050092 /* flag used to keep track of the video quality scale pressed state;
93 * we do not want to update the codec bitrate until the user releases the
94 * scale button */
95 gboolean quality_scale_pressed;
Stepan Salenikovicha448f602015-05-29 13:33:06 -040096
Sébastien Blin55bff9d2017-10-03 15:15:23 -040097 lrc::api::conversation::Info* conversation_;
98 AccountContainer* accountContainer_;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050099
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500100 QMetaObject::Connection state_change_connection;
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400101 QMetaObject::Connection local_renderer_connection;
102 QMetaObject::Connection remote_renderer_connection;
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400103 QMetaObject::Connection new_message_connection;
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500104
105 GSettings *settings;
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500106
107 // for clutter animations and to know when to fade in/out the overlays
108 ClutterTransition *fade_info;
109 ClutterTransition *fade_controls;
110 gint64 time_last_mouse_motion;
111 guint timer_fade;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400112
Stepan Salenikovich88092932017-05-15 18:19:00 -0400113 gulong insert_controls_id;
114
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400115 // smart info
116 QMetaObject::Connection smartinfo_refresh_connection;
117 guint smartinfo_action;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500118};
119
120G_DEFINE_TYPE_WITH_PRIVATE(CurrentCallView, current_call_view, GTK_TYPE_BOX);
121
122#define CURRENT_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CURRENT_CALL_VIEW_TYPE, CurrentCallViewPrivate))
123
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500124enum {
125 VIDEO_DOUBLE_CLICKED,
126 LAST_SIGNAL
127};
128
129static guint current_call_view_signals[LAST_SIGNAL] = { 0 };
130
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500131static void
132current_call_view_dispose(GObject *object)
133{
134 CurrentCallView *view;
135 CurrentCallViewPrivate *priv;
136
137 view = CURRENT_CALL_VIEW(object);
138 priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
139
140 QObject::disconnect(priv->state_change_connection);
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400141 QObject::disconnect(priv->local_renderer_connection);
142 QObject::disconnect(priv->remote_renderer_connection);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400143 QObject::disconnect(priv->smartinfo_refresh_connection);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400144 QObject::disconnect(priv->new_message_connection);
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500145 g_clear_object(&priv->settings);
146
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500147 g_source_remove(priv->timer_fade);
148
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400149 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
150 g_signal_handler_disconnect(display_smartinfo, priv->smartinfo_action);
151
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500152 G_OBJECT_CLASS(current_call_view_parent_class)->dispose(object);
153}
154
155static void
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500156show_chat_view(CurrentCallView *self)
157{
158 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
159 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
160
161 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
162}
163
164static void
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400165chat_toggled(GtkToggleButton *togglebutton, CurrentCallView *self)
166{
167 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
168 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
169
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400170 if (gtk_toggle_button_get_active(togglebutton)) {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500171 gtk_widget_show_all(priv->frame_chat);
172 gtk_widget_grab_focus(priv->frame_chat);
Stepan Salenikovicha5129f62015-11-05 15:10:59 -0500173 } else {
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500174 gtk_widget_hide(priv->frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400175 }
176}
177
Stepan Salenikovichdaf3cb32016-10-12 16:39:42 -0400178static gboolean
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500179map_boolean_to_orientation(GValue *value, GVariant *variant, G_GNUC_UNUSED gpointer user_data)
180{
181 if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
182 if (g_variant_get_boolean(variant)) {
183 // true, chat should be horizontal (to the right)
184 g_value_set_enum(value, GTK_ORIENTATION_HORIZONTAL);
185 } else {
186 // false, chat should be vertical (at the bottom)
187 g_value_set_enum(value, GTK_ORIENTATION_VERTICAL);
188 }
189 return TRUE;
190 }
191 return FALSE;
192}
193
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400194static void
195update_details(CurrentCallView *view)
196{
197 auto *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
198 auto callRendered = priv->conversation_->callId;
199
200 if (!priv->conversation_->confId.empty())
201 callRendered = priv->conversation_->confId;
202
203 gtk_label_set_text(GTK_LABEL(priv->label_duration),
204 priv->accountContainer_->info.callModel->getFormattedCallDuration(callRendered).c_str());
205
206 auto call = priv->accountContainer_->info.callModel->getCall(callRendered);
207 gtk_widget_set_sensitive(GTK_WIDGET(priv->togglebutton_muteaudio), (call.type != lrc::api::call::Type::CONFERENCE));
208 gtk_widget_set_sensitive(GTK_WIDGET(priv->togglebutton_mutevideo), (call.type != lrc::api::call::Type::CONFERENCE));
209}
210
211
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500212static gboolean
213timeout_check_last_motion_event(CurrentCallView *self)
214{
215 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), G_SOURCE_REMOVE);
216 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
217
218 auto current_time = g_get_monotonic_time();
219 if (current_time - priv->time_last_mouse_motion >= CONTROLS_FADE_TIMEOUT) {
220 // timeout has passed, hide the controls
221 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_BACKWARD) {
222 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_FORWARD);
223 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_FORWARD);
224 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
225 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
226 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
227 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
228 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
229 }
230 }
231 }
232
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400233 update_details(self);
234
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500235 return G_SOURCE_CONTINUE;
236}
237
238static gboolean
239mouse_moved(CurrentCallView *self)
240{
241 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
242 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
243
244 priv->time_last_mouse_motion = g_get_monotonic_time();
245
246 // since the mouse moved, make sure the controls are shown
247 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_FORWARD) {
248 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
249 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
250 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) {
251 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info));
252 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls));
253 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info));
254 clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls));
255 }
256 }
257
258 return FALSE; // propogate event
259}
260
261static ClutterTransition *
262create_fade_out_transition()
263{
264 auto transition = clutter_property_transition_new("opacity");
265 clutter_transition_set_from(transition, G_TYPE_UINT, 255);
266 clutter_transition_set_to(transition, G_TYPE_UINT, 0);
267 clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), FADE_DURATION);
268 clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), 0);
269 clutter_timeline_set_progress_mode(CLUTTER_TIMELINE(transition), CLUTTER_EASE_IN_OUT_CUBIC);
270 return transition;
271}
272
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500273static gboolean
274video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self)
275{
276 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
277 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
278
279 // if this widget already has focus, we want the focus to move to the next widget, otherwise we
280 // will get stuck in a focus loop on the buttons
281 if (gtk_widget_has_focus(widget))
282 return FALSE;
283
284 // otherwise we want the focus to go to and change between the call control buttons
285 if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
286 // selected a child, make sure call controls are shown
287 mouse_moved(self);
288 return TRUE;
289 }
290
291 // did not select the next child, propogate the event
292 return FALSE;
293}
294
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500295static GtkBox *
296gtk_scale_button_get_box(GtkScaleButton *button)
297{
298 GtkWidget *box = NULL;
299 if (auto dock = gtk_scale_button_get_popup(button)) {
300 // the dock is a popover which contains the box
301 box = gtk_bin_get_child(GTK_BIN(dock));
302 if (box) {
303 if (GTK_IS_FRAME(box)) {
304 // support older versions of gtk; the box used to be in a frame
305 box = gtk_bin_get_child(GTK_BIN(box));
306 }
307 }
308 }
309
310 return GTK_BOX(box);
311}
312
313/**
314 * This gets the GtkScaleButtonScale widget (which is a GtkScale) from the
315 * given GtkScaleButton in order to be able to modify its properties and connect
316 * to its signals
317 */
318static GtkScale *
319gtk_scale_button_get_scale(GtkScaleButton *button)
320{
321 GtkScale *scale = NULL;
322
323 if (auto box = gtk_scale_button_get_box(button)) {
324 GList *children = gtk_container_get_children(GTK_CONTAINER(box));
325 for (GList *c = children; c && !scale; c = c->next) {
326 if (GTK_IS_SCALE(c->data))
327 scale = GTK_SCALE(c->data);
328 }
329 g_list_free(children);
330 }
331
332 return scale;
333}
334
335static void
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500336autoquality_toggled(GtkToggleButton *button, CurrentCallView *self)
337{
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400338 // TODO
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500339 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
340 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
341
342 gboolean auto_quality_on = gtk_toggle_button_get_active(button);
343
344 auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality));
345 auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
346 auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
347
348 gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on);
349 gtk_widget_set_sensitive(plus_button, !auto_quality_on);
350 gtk_widget_set_sensitive(minus_button, !auto_quality_on);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500351}
352
353static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400354quality_changed(G_GNUC_UNUSED GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self)
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500355{
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400356 // TODO
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500357 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
358 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
359
360 /* no need to upate quality if auto quality is enabled */
361 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return;
362
363 /* only update if the scale button is released, to reduce the number of updates */
364 if (priv->quality_scale_pressed) return;
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500365}
366
367static gboolean
368quality_button_pressed(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
369{
370 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
371 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500372 priv->quality_scale_pressed = TRUE;
373
374 return GDK_EVENT_PROPAGATE;
375}
376
377static gboolean
378quality_button_released(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self)
379{
380 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE);
381 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500382 priv->quality_scale_pressed = FALSE;
383
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400384 // now make sure the quality gets updated
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500385 quality_changed(GTK_SCALE_BUTTON(priv->scalebutton_quality), 0, self);
386
387 return GDK_EVENT_PROPAGATE;
388}
389
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400390static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400391button_hangup_clicked(CurrentCallView *view)
392{
393 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
394 auto callToHangUp = priv->conversation_->callId;
395 if (!priv->conversation_->confId.empty())
396 callToHangUp = priv->conversation_->confId;
397 priv->accountContainer_->info.callModel->hangUp(callToHangUp);
398}
399
400static void
401togglebutton_hold_clicked(CurrentCallView *view)
402{
403 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
404 auto callToHold = priv->conversation_->callId;
405 if (!priv->conversation_->confId.empty())
406 callToHold = priv->conversation_->confId;
407 priv->accountContainer_->info.callModel->togglePause(callToHold);
408}
409
410static void
411togglebutton_record_clicked(CurrentCallView *view)
412{
413 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
414 auto callToRecord = priv->conversation_->callId;
415 if (!priv->conversation_->confId.empty())
416 callToRecord = priv->conversation_->confId;
417 priv->accountContainer_->info.callModel->toggleAudioRecord(callToRecord);
418}
419
420static void
421togglebutton_muteaudio_clicked(CurrentCallView *view)
422{
423 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
424 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
425 auto callToMute = priv->conversation_->callId;
426 if (!priv->conversation_->confId.empty())
427 callToMute = priv->conversation_->confId;
428 auto muteAudioBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
429 priv->accountContainer_->info.callModel->toggleMedia(callToMute,
Sébastien Blin1ffd4722017-11-06 15:38:08 -0500430 lrc::api::NewCallModel::Media::AUDIO);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400431
432 auto togglebutton = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
433 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_audio");
434 if (gtk_toggle_button_get_active(togglebutton))
435 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_audio");
436 gtk_button_set_image(GTK_BUTTON(togglebutton), image);
437}
438
439static void
440togglebutton_mutevideo_clicked(CurrentCallView *view)
441{
442 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
443 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
444 auto callToMute = priv->conversation_->callId;
445 if (!priv->conversation_->confId.empty())
446 callToMute = priv->conversation_->confId;
447 auto muteVideoBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
448 priv->accountContainer_->info.callModel->toggleMedia(callToMute,
Sébastien Blin1ffd4722017-11-06 15:38:08 -0500449 lrc::api::NewCallModel::Media::VIDEO);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400450
451 auto togglebutton = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
452 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_video");
453 if (gtk_toggle_button_get_active(togglebutton))
454 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_video");
455 gtk_button_set_image(GTK_BUTTON(togglebutton), image);
456}
457
458static void
Stepan Salenikovich88092932017-05-15 18:19:00 -0400459insert_controls(CurrentCallView *view)
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500460{
Stepan Salenikovich88092932017-05-15 18:19:00 -0400461 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400462
Stepan Salenikovich88092932017-05-15 18:19:00 -0400463 /* only add the controls once */
464 g_signal_handler_disconnect(view, priv->insert_controls_id);
465 priv->insert_controls_id = 0;
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500466
467 auto stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->video_widget));
468 auto actor_info = gtk_clutter_actor_new_with_contents(priv->hbox_call_info);
469 auto actor_controls = gtk_clutter_actor_new_with_contents(priv->hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400470 auto actor_smartInfo = gtk_clutter_actor_new_with_contents(priv->vbox_call_smartInfo);
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500471
472 clutter_actor_add_child(stage, actor_info);
473 clutter_actor_set_x_align(actor_info, CLUTTER_ACTOR_ALIGN_FILL);
474 clutter_actor_set_y_align(actor_info, CLUTTER_ACTOR_ALIGN_START);
475
476 clutter_actor_add_child(stage, actor_controls);
477 clutter_actor_set_x_align(actor_controls, CLUTTER_ACTOR_ALIGN_CENTER);
478 clutter_actor_set_y_align(actor_controls, CLUTTER_ACTOR_ALIGN_END);
479
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400480 clutter_actor_add_child(stage, actor_smartInfo);
481 clutter_actor_set_x_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_END);
482 clutter_actor_set_y_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_START);
483 ClutterMargin clutter_margin_smartInfo;
484 clutter_margin_smartInfo.top = 50;
485 clutter_margin_smartInfo.right = 10;
philippegorleya7337942017-07-04 15:29:42 -0400486 clutter_margin_smartInfo.left = 10;
487 clutter_margin_smartInfo.bottom = 10;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400488 clutter_actor_set_margin (actor_smartInfo, &clutter_margin_smartInfo);
489
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500490 /* add fade in and out states to the info and controls */
491 priv->time_last_mouse_motion = g_get_monotonic_time();
492 priv->fade_info = create_fade_out_transition();
493 priv->fade_controls = create_fade_out_transition();
494 clutter_actor_add_transition(actor_info, "fade_info", priv->fade_info);
495 clutter_actor_add_transition(actor_controls, "fade_controls", priv->fade_controls);
496 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD);
497 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD);
498 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_info));
499 clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_controls));
500
501 /* have a timer check every 1 second if the controls should fade out */
502 priv->timer_fade = g_timeout_add(1000, (GSourceFunc)timeout_check_last_motion_event, view);
503
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400504 /* connect the controllers (new model) */
505 g_signal_connect_swapped(priv->button_hangup, "clicked", G_CALLBACK(button_hangup_clicked), view);
506 g_signal_connect_swapped(priv->togglebutton_hold, "clicked", G_CALLBACK(togglebutton_hold_clicked), view);
507 g_signal_connect_swapped(priv->togglebutton_muteaudio, "clicked", G_CALLBACK(togglebutton_muteaudio_clicked), view);
508 g_signal_connect_swapped(priv->togglebutton_record, "clicked", G_CALLBACK(togglebutton_record_clicked), view);
509 g_signal_connect_swapped(priv->togglebutton_mutevideo, "clicked", G_CALLBACK(togglebutton_mutevideo_clicked), view);
510
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500511 /* connect to the mouse motion event to reset the last moved time */
512 g_signal_connect_swapped(priv->video_widget, "motion-notify-event", G_CALLBACK(mouse_moved), view);
513 g_signal_connect_swapped(priv->video_widget, "button-press-event", G_CALLBACK(mouse_moved), view);
514 g_signal_connect_swapped(priv->video_widget, "button-release-event", G_CALLBACK(mouse_moved), view);
515
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500516 /* manually handle the focus of the video widget to be able to focus on the call controls */
517 g_signal_connect(priv->video_widget, "focus", G_CALLBACK(video_widget_focus), view);
518
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400519
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500520 /* toggle whether or not the chat is displayed */
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400521 g_signal_connect(priv->togglebutton_chat, "toggled", G_CALLBACK(chat_toggled), view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400522
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500523 /* bind the chat orientation to the gsetting */
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500524 priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
525 g_settings_bind_with_mapping(priv->settings, "chat-pane-horizontal",
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500526 priv->paned_call, "orientation",
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500527 G_SETTINGS_BIND_GET,
528 map_boolean_to_orientation,
529 nullptr, nullptr, nullptr);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500530
531 g_signal_connect(priv->scalebutton_quality, "value-changed", G_CALLBACK(quality_changed), view);
532 /* customize the quality button scale */
533 if (auto scale_box = gtk_scale_button_get_box(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
534 priv->checkbutton_autoquality = gtk_check_button_new_with_label(C_("Enable automatic video quality", "Auto"));
535 gtk_widget_show(priv->checkbutton_autoquality);
536 gtk_box_pack_start(GTK_BOX(scale_box), priv->checkbutton_autoquality, FALSE, TRUE, 0);
537 g_signal_connect(priv->checkbutton_autoquality, "toggled", G_CALLBACK(autoquality_toggled), view);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500538 }
539 if (auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality))) {
540 g_signal_connect(scale, "button-press-event", G_CALLBACK(quality_button_pressed), view);
541 g_signal_connect(scale, "button-release-event", G_CALLBACK(quality_button_released), view);
542 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400543
Sébastien Blin4514eeb2017-07-25 14:17:01 -0400544 // Get if the user wants to show the smartInfo box
545 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
546 if (g_variant_get_boolean(g_action_get_state(G_ACTION(display_smartinfo)))) {
547 gtk_widget_show(priv->vbox_call_smartInfo);
548 } else {
549 gtk_widget_hide(priv->vbox_call_smartInfo);
550 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400551}
552
553static void
554current_call_view_init(CurrentCallView *view)
555{
556 gtk_widget_init_template(GTK_WIDGET(view));
557
558 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
559
560 // CSS styles
561 auto provider = gtk_css_provider_new();
562 gtk_css_provider_load_from_data(provider,
AmarOke7c02972017-07-17 15:21:20 -0400563 ".smartinfo-block-style { color: #8ae234; background-color: rgba(1, 1, 1, 0.33); } \
564 @keyframes blink { 0% {opacity: 1;} 49% {opacity: 1;} 50% {opacity: 0;} 100% {opacity: 0;} } \
565 .record-button { background: rgba(0, 0, 0, 1); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
566 .record-button:checked { animation: blink 1s; animation-iteration-count: infinite; } \
567 .call-button { background: rgba(0, 0, 0, 0); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
568 .call-button:hover { background: rgba(200, 200, 200, 0.15); } \
569 .call-button:disabled { opacity: 0.2; } \
570 .can-be-disabled:checked { background: rgba(219, 58, 55, 1); } \
571 .hangup-button-style { background: rgba(219, 58, 55, 1); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
572 .hangup-button-style:hover { background: rgba(219, 39, 25, 1); }",
Stepan Salenikovich88092932017-05-15 18:19:00 -0400573 -1, nullptr
574 );
575 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
576 GTK_STYLE_PROVIDER(provider),
577 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
578
579 priv->video_widget = video_widget_new();
580 gtk_container_add(GTK_CONTAINER(priv->frame_video), priv->video_widget);
581 gtk_widget_show_all(priv->frame_video);
582
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400583 // add the overlay controls only once the view has been allocated a size to prevent size
584 // allocation warnings in the log
Stepan Salenikovich88092932017-05-15 18:19:00 -0400585 priv->insert_controls_id = g_signal_connect(view, "size-allocate", G_CALLBACK(insert_controls), nullptr);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500586}
587
588static void
589current_call_view_class_init(CurrentCallViewClass *klass)
590{
591 G_OBJECT_CLASS(klass)->dispose = current_call_view_dispose;
592
593 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
594 "/cx/ring/RingGnome/currentcallview.ui");
595
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500596 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_info);
597 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400598 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, vbox_call_smartInfo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500599 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, image_peer);
Stepan Salenikovich07107e92016-05-06 10:35:17 -0400600 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_name);
Nicolas Jager2e467c32017-01-18 08:52:23 -0500601 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_bestId);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500602 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_status);
603 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_duration);
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400604 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_description);
605 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_value);
606 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_general_information);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500607 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, paned_call);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500608 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500609 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400610 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat);
AmarOke7c02972017-07-17 15:21:20 -0400611 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_hold);
612 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_muteaudio);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400613 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_record);
AmarOke7c02972017-07-17 15:21:20 -0400614 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_mutevideo);
Stepan Salenikovich77baa522015-07-07 15:29:14 -0400615 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, button_hangup);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500616 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, scalebutton_quality);
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500617
618 current_call_view_signals[VIDEO_DOUBLE_CLICKED] = g_signal_new (
619 "video-double-clicked",
620 G_TYPE_FROM_CLASS(klass),
621 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
622 0,
623 nullptr,
624 nullptr,
625 g_cclosure_marshal_VOID__VOID,
626 G_TYPE_NONE, 0);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500627}
628
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500629static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400630update_state(CurrentCallView *view)
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500631{
632 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400633 if (!priv || !priv->conversation_) return;
634 auto callId = priv->conversation_->callId;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500635
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400636 try {
637 auto call = priv->accountContainer_->info.callModel->getCall(callId);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500638
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400639 auto pauseBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_hold);
640 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/pause");
641 if (call.status == lrc::api::call::Status::PAUSED)
642 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/play");
643 gtk_button_set_image(GTK_BUTTON(pauseBtn), image);
Stepan Salenikovich7ec8fe82015-06-02 18:26:39 -0400644
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400645 auto audioButton = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
646 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio), call.audioMuted);
647 auto imageMuteAudio = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_audio");
648 if (call.audioMuted)
649 imageMuteAudio = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_audio");
650 gtk_button_set_image(GTK_BUTTON(audioButton), imageMuteAudio);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500651
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400652 auto videoButton = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
653 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo), call.videoMuted);
654 auto imageMuteVideo = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_video");
655 if (call.videoMuted)
656 imageMuteVideo = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_video");
657 gtk_button_set_image(GTK_BUTTON(videoButton), imageMuteVideo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500658
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400659 gchar *status = g_strdup_printf("%s", lrc::api::call::to_string(call.status).c_str());
660 gtk_label_set_text(GTK_LABEL(priv->label_status), status);
661 g_free(status);
662 } catch (std::out_of_range& e) {
663 g_warning("Can't update state for callId=%s", callId.c_str());
664 }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500665}
666
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400667static void
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400668update_name_and_photo(CurrentCallView *view)
669{
670 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
671
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400672 QVariant var_i = GlobalInstances::pixmapManipulator().conversationPhoto(
673 *priv->conversation_,
674 priv->accountContainer_->info,
675 QSize(60, 60),
676 false
677 );
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400678 std::shared_ptr<GdkPixbuf> image = var_i.value<std::shared_ptr<GdkPixbuf>>();
679 gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_peer), image.get());
680
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400681 auto contactInfo = priv->accountContainer_->info.contactModel->getContact(priv->conversation_->participants.front());
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400682
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400683 auto name = contactInfo.profileInfo.alias;
684 gtk_label_set_text(GTK_LABEL(priv->label_name), name.c_str());
685
686 auto bestId = contactInfo.registeredName;
687 if (name != bestId) {
688 gtk_label_set_text(GTK_LABEL(priv->label_bestId), bestId.c_str());
Stepan Salenikovich46bb1572017-05-19 16:09:43 -0400689 gtk_widget_show(priv->label_bestId);
690 }
691}
692
693static void
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400694update_smartInfo(CurrentCallView *view)
695{
696 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
697
698 if (!SmartInfoHub::instance().isConference()) {
699 gchar* general_information = g_strdup_printf("Call ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
700 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
701 g_free(general_information);
702
703 gchar* description = g_strdup_printf("You\n"
704 "Framerate:\n"
705 "Video codec:\n"
706 "Audio codec:\n"
707 "Resolution:\n\n"
708 "Peer\n"
709 "Framerate:\n"
710 "Video codec:\n"
711 "Audio codec:\n"
712 "Resolution:");
713 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
714 g_free(description);
715
716 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",
717 (double)SmartInfoHub::instance().localFps(),
718 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
719 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
720 SmartInfoHub::instance().localWidth(),
721 SmartInfoHub::instance().localHeight(),
722 (double)SmartInfoHub::instance().remoteFps(),
723 SmartInfoHub::instance().remoteVideoCodec().toStdString().c_str(),
724 SmartInfoHub::instance().remoteAudioCodec().toStdString().c_str(),
725 SmartInfoHub::instance().remoteWidth(),
726 SmartInfoHub::instance().remoteHeight());
727 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
728 g_free(value);
729 } else {
730 gchar* general_information = g_strdup_printf("Conference ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
731 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information);
732 g_free(general_information);
733
734 gchar* description = g_strdup_printf("You\n"
735 "Framerate:\n"
736 "Video codec:\n"
737 "Audio codec:\n"
738 "Resolution:");
739 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description);
740 g_free(description);
741
742 gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d",
743 (double)SmartInfoHub::instance().localFps(),
744 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
745 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
746 SmartInfoHub::instance().localWidth(),
747 SmartInfoHub::instance().localHeight());
748 gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value);
749 g_free(value);
750 }
751}
752
753
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500754static gboolean
755on_button_press_in_video_event(GtkWidget *self, GdkEventButton *event, CurrentCallView *view)
756{
757 g_return_val_if_fail(IS_VIDEO_WIDGET(self), FALSE);
758 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
759
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400760 // on double click
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500761 if (event->type == GDK_2BUTTON_PRESS) {
762 g_debug("double click in video");
763 g_signal_emit(G_OBJECT(view), current_call_view_signals[VIDEO_DOUBLE_CLICKED], 0);
764 }
765
766 return GDK_EVENT_PROPAGATE;
767}
768
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400769static void
770toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget* vbox_call_smartInfo)
771{
772 if (g_variant_get_boolean(g_action_get_state(G_ACTION(action)))) {
773 gtk_widget_show(vbox_call_smartInfo);
774 } else {
775 gtk_widget_hide(vbox_call_smartInfo);
776 }
777}
778
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400779
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400780static void
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400781set_call_info(CurrentCallView *view) {
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500782 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
783
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400784 // change some things depending on call state
785 update_state(view);
786 update_details(view);
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400787
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400788 // NOTE/TODO we need to rewrite the video_widget file to use the new LRC.
789 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 -0500790
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400791 // check if we already have a renderer
792 auto callToRender = priv->conversation_->callId;
793 if (!priv->conversation_->confId.empty())
794 callToRender = priv->conversation_->confId;
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400795 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400796 priv->accountContainer_->info.callModel->getRenderer(callToRender),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400797 VIDEO_RENDERER_REMOTE);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -0500798
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400799 // local renderer
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400800 if (Video::PreviewManager::instance().isPreviewing())
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400801 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400802 Video::PreviewManager::instance().previewRenderer(),
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400803 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400804
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400805 // callback for local renderer
Stepan Salenikovichc5f08152015-03-19 00:53:23 -0400806 priv->local_renderer_connection = QObject::connect(
Guillaume Roguez5d1514b2015-10-22 15:55:31 -0400807 &Video::PreviewManager::instance(),
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400808 &Video::PreviewManager::previewStarted,
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400809 [priv](Video::Renderer *renderer) {
Stepan Salenikovich0f693232015-04-22 10:45:08 -0400810 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
811 renderer,
812 VIDEO_RENDERER_LOCAL);
Stepan Salenikovich8e5c9d02015-03-11 14:07:10 -0400813 }
814 );
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400815
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400816 priv->smartinfo_refresh_connection = QObject::connect(
817 &SmartInfoHub::instance(),
818 &SmartInfoHub::changed,
819 [view, priv]() { update_smartInfo(view); }
820 );
Julien Grossholtza0d4f102015-10-22 14:24:17 -0400821
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400822 priv->remote_renderer_connection = QObject::connect(
823 &*priv->accountContainer_->info.callModel,
824 &lrc::api::NewCallModel::remotePreviewStarted,
825 [priv](const std::string& callId, Video::Renderer *renderer) {
826 if (priv->conversation_->callId == callId) {
827 video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget),
828 renderer,
829 VIDEO_RENDERER_REMOTE);
830 }
831 }
832 );
Julien Grossholtza0d4f102015-10-22 14:24:17 -0400833
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400834 priv->state_change_connection = QObject::connect(
835 &*priv->accountContainer_->info.callModel,
836 &lrc::api::NewCallModel::callStatusChanged,
837 [view, priv] (const std::string& callId) {
838 if (callId == priv->conversation_->callId) {
839 update_state(view);
840 update_name_and_photo(view);
841 }
842 });
843
844 priv->new_message_connection = QObject::connect(
845 &*priv->accountContainer_->info.conversationModel, &lrc::api::ConversationModel::newUnreadMessage,
846 [priv](const std::string& uid, uint64_t msgId, lrc::api::interaction::Info msg) {
847 Q_UNUSED(uid)
848 Q_UNUSED(msgId)
849 Q_UNUSED(msg)
850 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
851 });
852
853
854 // catch double click to make full screen
Stepan Salenikovichbfe9ac62015-03-11 12:49:20 -0400855 g_signal_connect(priv->video_widget, "button-press-event",
856 G_CALLBACK(on_button_press_in_video_event),
857 view);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400858
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400859 // handle smartinfo in right click menu
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400860 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo");
861 priv->smartinfo_action = g_signal_connect(display_smartinfo,
862 "notify::state",
863 G_CALLBACK(toggle_smartinfo),
864 priv->vbox_call_smartInfo);
865
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400866 // init chat view
867 auto chat_view = chat_view_new(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), priv->accountContainer_, priv->conversation_);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500868 gtk_container_add(GTK_CONTAINER(priv->frame_chat), chat_view);
869
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500870 g_signal_connect_swapped(chat_view, "new-messages-displayed", G_CALLBACK(show_chat_view), view);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400871 chat_view_set_header_visible(CHAT_VIEW(chat_view), FALSE);
872
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500873}
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400874
875GtkWidget *
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400876current_call_view_new(WebKitChatContainer* view, AccountContainer* accountContainer, lrc::api::conversation::Info* conversation)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400877{
878 auto self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
aviau039001d2016-09-29 16:39:05 -0400879 CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400880 priv->webkit_chat_container = GTK_WIDGET(view);
881 priv->conversation_ = conversation;
882 priv->accountContainer_ = accountContainer;
883 set_call_info(CURRENT_CALL_VIEW(self));
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400884
885 return GTK_WIDGET(self);
886}
887
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400888lrc::api::conversation::Info
889current_call_view_get_conversation(CurrentCallView *self)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400890{
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400891 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), lrc::api::conversation::Info());
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400892 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
893
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400894 return *priv->conversation_;
Stepan Salenikovich09e0b782016-09-07 16:28:50 -0400895}