blob: 3a9ffbd764284af1a7d35e569bd2ecddf540a50b [file] [log] [blame]
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05001/*
Guillaume Roguez77c579d2018-01-30 15:54:02 -05002 * Copyright (C) 2015-2018 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>
Sébastien Blin3667fa62017-11-23 09:11:53 -050033#include <callmodel.h>
Sébastien Blin55bff9d2017-10-03 15:15:23 -040034#include <codecmodel.h>
35#include <globalinstances.h>
Olivier Gregoire66e4df72016-06-17 18:39:05 -040036#include <smartinfohub.h>
Sébastien Blin55bff9d2017-10-03 15:15:23 -040037#include <video/previewmanager.h>
38
39// Client
40#include "chatview.h"
41#include "native/pixbufmanipulator.h"
42#include "ringnotify.h"
43#include "utils/drawing.h"
44#include "utils/files.h"
45#include "video/video_widget.h"
46
Sébastien Blin784f2a32018-05-30 17:31:13 -040047#include <iostream>
48
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -050049namespace { namespace details
50{
51class CppImpl;
52}}
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -050053
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050054struct _CurrentCallView
55{
56 GtkBox parent;
57};
58
59struct _CurrentCallViewClass
60{
61 GtkBoxClass parent_class;
62};
63
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -050064struct CurrentCallViewPrivate
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050065{
Stepan Salenikoviche178e632015-11-06 13:31:19 -050066 GtkWidget *hbox_call_info;
67 GtkWidget *hbox_call_controls;
Olivier Gregoire66e4df72016-06-17 18:39:05 -040068 GtkWidget *vbox_call_smartInfo;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050069 GtkWidget *image_peer;
Stepan Salenikovich07107e92016-05-06 10:35:17 -040070 GtkWidget *label_name;
Nicolas Jager2e467c32017-01-18 08:52:23 -050071 GtkWidget *label_bestId;
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050072 GtkWidget *label_status;
73 GtkWidget *label_duration;
Olivier Gregoire66e4df72016-06-17 18:39:05 -040074 GtkWidget *label_smartinfo_description;
75 GtkWidget *label_smartinfo_value;
76 GtkWidget *label_smartinfo_general_information;
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050077 GtkWidget *paned_call;
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050078 GtkWidget *frame_video;
79 GtkWidget *video_widget;
Stepan Salenikovichd2cad062016-01-08 13:43:49 -050080 GtkWidget *frame_chat;
Stepan Salenikovicha448f602015-05-29 13:33:06 -040081 GtkWidget *togglebutton_chat;
AmarOke7c02972017-07-17 15:21:20 -040082 GtkWidget *togglebutton_muteaudio;
83 GtkWidget *togglebutton_mutevideo;
Sébastien Blin784f2a32018-05-30 17:31:13 -040084 GtkWidget *togglebutton_transfer;
85 GtkWidget* siptransfer_popover;
86 GtkWidget* siptransfer_filter_entry;
87 GtkWidget* list_conversations;
AmarOke7c02972017-07-17 15:21:20 -040088 GtkWidget *togglebutton_hold;
Sébastien Blin55bff9d2017-10-03 15:15:23 -040089 GtkWidget *togglebutton_record;
Stepan Salenikovich77baa522015-07-07 15:29:14 -040090 GtkWidget *button_hangup;
Stepan Salenikovich7e283552015-12-21 16:17:52 -050091 GtkWidget *scalebutton_quality;
92 GtkWidget *checkbutton_autoquality;
Sébastien Blin366243f2017-11-03 14:14:54 -040093 GtkWidget *chat_view;
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -050094 GtkWidget *webkit_chat_container; // The webkit_chat_container is created once, then reused for all chat views
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -050095
96 GSettings *settings;
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -050097
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -050098 details::CppImpl* cpp; ///< Non-UI and C++ only code
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050099};
100
101G_DEFINE_TYPE_WITH_PRIVATE(CurrentCallView, current_call_view, GTK_TYPE_BOX);
102
103#define CURRENT_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CURRENT_CALL_VIEW_TYPE, CurrentCallViewPrivate))
104
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500105enum {
106 VIDEO_DOUBLE_CLICKED,
107 LAST_SIGNAL
108};
109
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500110//==============================================================================
111
112namespace { namespace details
113{
114
115static constexpr int CONTROLS_FADE_TIMEOUT = 3000000; /* microseconds */
116static constexpr int FADE_DURATION = 500; /* miliseconds */
Stepan Salenikoviche1b54892015-12-13 22:18:44 -0500117static guint current_call_view_signals[LAST_SIGNAL] = { 0 };
118
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500119namespace // Helpers
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500120{
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400121
Stepan Salenikovichdaf3cb32016-10-12 16:39:42 -0400122static gboolean
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500123map_boolean_to_orientation(GValue* value, GVariant* variant, G_GNUC_UNUSED gpointer user_data)
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500124{
125 if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
126 if (g_variant_get_boolean(variant)) {
127 // true, chat should be horizontal (to the right)
128 g_value_set_enum(value, GTK_ORIENTATION_HORIZONTAL);
129 } else {
130 // false, chat should be vertical (at the bottom)
131 g_value_set_enum(value, GTK_ORIENTATION_VERTICAL);
132 }
133 return TRUE;
134 }
135 return FALSE;
136}
137
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500138static ClutterTransition*
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500139create_fade_out_transition()
140{
141 auto transition = clutter_property_transition_new("opacity");
142 clutter_transition_set_from(transition, G_TYPE_UINT, 255);
143 clutter_transition_set_to(transition, G_TYPE_UINT, 0);
144 clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), FADE_DURATION);
145 clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), 0);
146 clutter_timeline_set_progress_mode(CLUTTER_TIMELINE(transition), CLUTTER_EASE_IN_OUT_CUBIC);
147 return transition;
148}
149
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500150static GtkBox *
151gtk_scale_button_get_box(GtkScaleButton *button)
152{
153 GtkWidget *box = NULL;
154 if (auto dock = gtk_scale_button_get_popup(button)) {
155 // the dock is a popover which contains the box
156 box = gtk_bin_get_child(GTK_BIN(dock));
157 if (box) {
158 if (GTK_IS_FRAME(box)) {
159 // support older versions of gtk; the box used to be in a frame
160 box = gtk_bin_get_child(GTK_BIN(box));
161 }
162 }
163 }
164
165 return GTK_BOX(box);
166}
167
168/**
169 * This gets the GtkScaleButtonScale widget (which is a GtkScale) from the
170 * given GtkScaleButton in order to be able to modify its properties and connect
171 * to its signals
172 */
173static GtkScale *
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500174gtk_scale_button_get_scale(GtkScaleButton* button)
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500175{
176 GtkScale *scale = NULL;
177
178 if (auto box = gtk_scale_button_get_box(button)) {
179 GList *children = gtk_container_get_children(GTK_CONTAINER(box));
180 for (GList *c = children; c && !scale; c = c->next) {
181 if (GTK_IS_SCALE(c->data))
182 scale = GTK_SCALE(c->data);
183 }
184 g_list_free(children);
185 }
186
187 return scale;
188}
189
190static void
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500191set_call_quality(Call& call, bool auto_quality_on, double desired_quality)
Sébastien Blin3667fa62017-11-23 09:11:53 -0500192{
193 /* set auto quality true or false, also set the bitrate and quality values;
194 * the slider is from 0 to 100, use the min and max vals to scale each value accordingly */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500195 if (const auto& codecModel = call.account()->codecModel()) {
Sébastien Blin3667fa62017-11-23 09:11:53 -0500196 const auto& videoCodecs = codecModel->videoCodecs();
197
198 for (int i=0; i < videoCodecs->rowCount();i++) {
199 const auto& idx = videoCodecs->index(i,0);
200
201 if (auto_quality_on) {
202 // g_debug("enable auto quality");
203 videoCodecs->setData(idx, "true", CodecModel::Role::AUTO_QUALITY_ENABLED);
204 } else {
205 auto min_bitrate = idx.data(static_cast<int>(CodecModel::Role::MIN_BITRATE)).toInt();
206 auto max_bitrate = idx.data(static_cast<int>(CodecModel::Role::MAX_BITRATE)).toInt();
207 auto min_quality = idx.data(static_cast<int>(CodecModel::Role::MIN_QUALITY)).toInt();
208 auto max_quality = idx.data(static_cast<int>(CodecModel::Role::MAX_QUALITY)).toInt();
209
210 // g_debug("bitrate min: %d, max: %d, quality min: %d, max: %d", min_bitrate, max_bitrate, min_quality, max_quality);
211
212 double bitrate;
213 bitrate = min_bitrate + (double)(max_bitrate - min_bitrate)*(desired_quality/100.0);
214 if (bitrate < 0) bitrate = 0;
215
216 double quality;
217 // note: a lower value means higher quality
218 quality = (double)min_quality - (min_quality - max_quality)*(desired_quality/100.0);
219 if (quality < 0) quality = 0;
220
221 // g_debug("disable auto quality; %% quality: %d; bitrate: %d; quality: %d", (int)desired_quality, (int)bitrate, (int)quality);
222 videoCodecs->setData(idx, "false", CodecModel::Role::AUTO_QUALITY_ENABLED);
223 videoCodecs->setData(idx, QString::number((int)bitrate), CodecModel::Role::BITRATE);
224 videoCodecs->setData(idx, QString::number((int)quality), CodecModel::Role::QUALITY);
225 }
226 }
227 codecModel << CodecModel::EditAction::SAVE;
228 }
229}
230
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500231} // namespace
232
233class CppImpl
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500234{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500235public:
236 explicit CppImpl(CurrentCallView& widget);
237 ~CppImpl();
238
239 void init();
240 void setup(WebKitChatContainer* chat_widget,
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400241 AccountInfoPointer const & account_info,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500242 lrc::api::conversation::Info* conversation);
Sébastien Blin784f2a32018-05-30 17:31:13 -0400243 void add_transfer_contact(const std::string& uri);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500244
245 void insertControls();
246 void checkControlsFading();
247
248 CurrentCallView* self = nullptr; // The GTK widget itself
249 CurrentCallViewPrivate* widgets = nullptr;
250
251 lrc::api::conversation::Info* conversation = nullptr;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400252 AccountInfoPointer const *accountInfo = nullptr;
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500253
254 QMetaObject::Connection state_change_connection;
255 QMetaObject::Connection local_renderer_connection;
256 QMetaObject::Connection remote_renderer_connection;
257 QMetaObject::Connection new_message_connection;
258 QMetaObject::Connection smartinfo_refresh_connection;
259
260 // for clutter animations and to know when to fade in/out the overlays
261 ClutterTransition* fade_info = nullptr;
262 ClutterTransition* fade_controls = nullptr;
263 gint64 time_last_mouse_motion = 0;
264 guint timer_fade = 0;
265
266 /* flag used to keep track of the video quality scale pressed state;
267 * we do not want to update the codec bitrate until the user releases the
268 * scale button */
269 gboolean quality_scale_pressed = FALSE;
270 gulong insert_controls_id = 0;
271 guint smartinfo_action = 0;
272
273private:
274 CppImpl() = delete;
275 CppImpl(const CppImpl&) = delete;
276 CppImpl& operator=(const CppImpl&) = delete;
277
278 void setCallInfo();
279 void updateDetails();
280 void updateState();
281 void updateNameAndPhoto();
282 void updateSmartInfo();
283};
284
285inline namespace gtk_callbacks
286{
287
288static void
289on_new_chat_interactions(CurrentCallView* view)
290{
291 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
292 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
293
294 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE);
295}
296
297static void
298on_togglebutton_chat_toggled(GtkToggleButton* widget, CurrentCallView* view)
299{
300 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
301 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
302
303 if (gtk_toggle_button_get_active(widget)) {
304 gtk_widget_show_all(priv->frame_chat);
305 gtk_widget_grab_focus(priv->frame_chat);
306 } else {
307 gtk_widget_hide(priv->frame_chat);
308 }
309}
310
311static gboolean
312on_timer_fade_timeout(CurrentCallView* view)
313{
314 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), G_SOURCE_REMOVE);
315 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
316 priv->cpp->checkControlsFading();
317 return G_SOURCE_CONTINUE;
318}
319
320static void
321on_size_allocate(CurrentCallView* view)
322{
323 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
324 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
325
326 priv->cpp->insertControls();
327}
328
329static void
330on_button_hangup_clicked(CurrentCallView* view)
331{
332 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
333 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
334
335 auto callToHangUp = priv->cpp->conversation->callId;
336 if (!priv->cpp->conversation->confId.empty())
337 callToHangUp = priv->cpp->conversation->confId;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400338 (*priv->cpp->accountInfo)->callModel->hangUp(callToHangUp);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500339}
340
341static void
342on_togglebutton_hold_clicked(CurrentCallView* view)
343{
344 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
345 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
346
347 auto callToHold = priv->cpp->conversation->callId;
348 if (!priv->cpp->conversation->confId.empty())
349 callToHold = priv->cpp->conversation->confId;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400350 (*priv->cpp->accountInfo)->callModel->togglePause(callToHold);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500351}
352
353static void
354on_togglebutton_record_clicked(CurrentCallView* view)
355{
356 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
357 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
358
359 auto callToRecord = priv->cpp->conversation->callId;
360 if (!priv->cpp->conversation->confId.empty())
361 callToRecord = priv->cpp->conversation->confId;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400362 (*priv->cpp->accountInfo)->callModel->toggleAudioRecord(callToRecord);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500363}
364
365static void
366on_togglebutton_muteaudio_clicked(CurrentCallView* view)
367{
368 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
369 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
370
371 auto callToMute = priv->cpp->conversation->callId;
372 if (!priv->cpp->conversation->confId.empty())
373 callToMute = priv->cpp->conversation->confId;
374 //auto muteAudioBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400375 (*priv->cpp->accountInfo)->callModel->toggleMedia(callToMute,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500376 lrc::api::NewCallModel::Media::AUDIO);
377
378 auto togglebutton = GTK_TOGGLE_BUTTON(priv->togglebutton_muteaudio);
379 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_audio");
380 if (gtk_toggle_button_get_active(togglebutton))
381 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_audio");
382 gtk_button_set_image(GTK_BUTTON(togglebutton), image);
383}
384
385static void
386on_togglebutton_mutevideo_clicked(CurrentCallView* view)
387{
388 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
389 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
390
391 auto callToMute = priv->cpp->conversation->callId;
392 if (!priv->cpp->conversation->confId.empty())
393 callToMute = priv->cpp->conversation->confId;
394 //auto muteVideoBtn = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400395 (*priv->cpp->accountInfo)->callModel->toggleMedia(callToMute,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500396 lrc::api::NewCallModel::Media::VIDEO);
397
398 auto togglebutton = GTK_TOGGLE_BUTTON(priv->togglebutton_mutevideo);
399 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_video");
400 if (gtk_toggle_button_get_active(togglebutton))
401 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_video");
402 gtk_button_set_image(GTK_BUTTON(togglebutton), image);
403}
404
405static gboolean
406on_mouse_moved(CurrentCallView* view)
407{
408 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
409 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
410
411 priv->cpp->time_last_mouse_motion = g_get_monotonic_time();
412
413 // since the mouse moved, make sure the controls are shown
414 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->cpp->fade_info)) == CLUTTER_TIMELINE_FORWARD) {
415 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->cpp->fade_info), CLUTTER_TIMELINE_BACKWARD);
416 clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->cpp->fade_controls), CLUTTER_TIMELINE_BACKWARD);
417 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->cpp->fade_info))) {
418 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->cpp->fade_info));
419 clutter_timeline_rewind(CLUTTER_TIMELINE(priv->cpp->fade_controls));
420 clutter_timeline_start(CLUTTER_TIMELINE(priv->cpp->fade_info));
421 clutter_timeline_start(CLUTTER_TIMELINE(priv->cpp->fade_controls));
422 }
423 }
424
425 return FALSE; // propogate event
426}
427
428static void
429on_autoquality_toggled(GtkToggleButton* button, CurrentCallView* view)
430{
431 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
432 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500433
434 gboolean auto_quality_on = gtk_toggle_button_get_active(button);
435
436 auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality));
437 auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
438 auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality));
439
440 gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on);
441 gtk_widget_set_sensitive(plus_button, !auto_quality_on);
442 gtk_widget_set_sensitive(minus_button, !auto_quality_on);
Sébastien Blin3667fa62017-11-23 09:11:53 -0500443
444 double desired_quality = gtk_scale_button_get_value(GTK_SCALE_BUTTON(priv->scalebutton_quality));
445
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500446 auto callToRender = priv->cpp->conversation->callId;
447 if (!priv->cpp->conversation->confId.empty())
448 callToRender = priv->cpp->conversation->confId;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400449 auto renderer = (*priv->cpp->accountInfo)->callModel->getRenderer(callToRender);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500450 for (auto* activeCall: CallModel::instance().getActiveCalls()) {
451 if (activeCall and activeCall->videoRenderer() == renderer)
452 set_call_quality(*activeCall, auto_quality_on, desired_quality);
453 }
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500454}
455
456static void
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500457on_quality_changed(G_GNUC_UNUSED GtkScaleButton *button, G_GNUC_UNUSED gdouble value,
458 CurrentCallView* view)
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500459{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500460 g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
461 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500462
463 /* no need to upate quality if auto quality is enabled */
464 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return;
465
466 /* only update if the scale button is released, to reduce the number of updates */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500467 if (priv->cpp->quality_scale_pressed) return;
Sébastien Blin3667fa62017-11-23 09:11:53 -0500468
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500469 auto callToRender = priv->cpp->conversation->callId;
470 if (!priv->cpp->conversation->confId.empty())
471 callToRender = priv->cpp->conversation->confId;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400472 auto renderer = (*priv->cpp->accountInfo)->callModel->getRenderer(callToRender);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500473 for (auto* activeCall: CallModel::instance().getActiveCalls())
474 if (activeCall and activeCall->videoRenderer() == renderer)
475 set_call_quality(*activeCall, false, gtk_scale_button_get_value(button));
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500476}
477
478static gboolean
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500479on_quality_button_pressed(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event,
480 CurrentCallView* view)
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500481{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500482 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
483 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
484
485 priv->cpp->quality_scale_pressed = TRUE;
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500486
487 return GDK_EVENT_PROPAGATE;
488}
489
490static gboolean
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500491on_quality_button_released(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event,
492 CurrentCallView* view)
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500493{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500494 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
495 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
496
497 priv->cpp->quality_scale_pressed = FALSE;
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500498
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400499 // now make sure the quality gets updated
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500500 on_quality_changed(GTK_SCALE_BUTTON(priv->scalebutton_quality), 0, view);
501
502 return GDK_EVENT_PROPAGATE;
503}
504
505static gboolean
506on_video_widget_focus(GtkWidget* widget, GtkDirectionType direction, CurrentCallView* view)
507{
508 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
509 auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
510
511 // if this widget already has focus, we want the focus to move to the next widget, otherwise we
512 // will get stuck in a focus loop on the buttons
513 if (gtk_widget_has_focus(widget))
514 return FALSE;
515
516 // otherwise we want the focus to go to and change between the call control buttons
517 if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) {
518 // selected a child, make sure call controls are shown
519 on_mouse_moved(view);
520 return TRUE;
521 }
522
523 // did not select the next child, propogate the event
524 return FALSE;
525}
526
527static gboolean
528on_button_press_in_video_event(GtkWidget* widget, GdkEventButton *event, CurrentCallView* view)
529{
530 g_return_val_if_fail(IS_VIDEO_WIDGET(widget), FALSE);
531 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE);
532
533 // on double click
534 if (event->type == GDK_2BUTTON_PRESS) {
535 g_debug("double click in video");
536 g_signal_emit(G_OBJECT(view), current_call_view_signals[VIDEO_DOUBLE_CLICKED], 0);
537 }
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500538
539 return GDK_EVENT_PROPAGATE;
540}
541
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400542static void
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500543on_toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget* vbox_call_smartInfo)
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400544{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500545 if (g_variant_get_boolean(g_action_get_state(G_ACTION(action)))) {
546 gtk_widget_show(vbox_call_smartInfo);
547 } else {
548 gtk_widget_hide(vbox_call_smartInfo);
549 }
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400550}
551
Sébastien Blin784f2a32018-05-30 17:31:13 -0400552static void
553transfer_to_peer(CurrentCallViewPrivate* priv, const std::string& peerUri)
554{
555 if (peerUri == priv->cpp->conversation->participants.front()) {
556 g_warning("avoid to transfer to the same call, abort.");
557#if GTK_CHECK_VERSION(3,22,0)
558 gtk_popover_popdown(GTK_POPOVER(priv->siptransfer_popover));
559#else
560 gtk_widget_hide(GTK_WIDGET(priv->siptransfer_popover));
561#endif
562 return;
563 }
564 try {
565 // If a call is already present with a peer, try an attended transfer.
566 auto callInfo = (*priv->cpp->accountInfo)->callModel->getCallFromURI(peerUri, true);
567 (*priv->cpp->accountInfo)->callModel->transferToCall(
568 priv->cpp->conversation->callId, callInfo.id);
569 } catch (std::out_of_range&) {
570 // No current call found with this URI, perform a blind transfer
571 (*priv->cpp->accountInfo)->callModel->transfer(
572 priv->cpp->conversation->callId, peerUri);
573 }
574#if GTK_CHECK_VERSION(3,22,0)
575 gtk_popover_popdown(GTK_POPOVER(priv->siptransfer_popover));
576#else
577 gtk_widget_hide(GTK_WIDGET(priv->siptransfer_popover));
578#endif
579}
580
581static void
582on_siptransfer_filter_activated(CurrentCallView* self)
583{
584 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
585 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
586
587 transfer_to_peer(priv, gtk_entry_get_text(GTK_ENTRY(priv->siptransfer_filter_entry)));
588}
589
590static GtkLabel*
591get_sip_address_label(GtkListBoxRow* row)
592{
593 auto* row_children = gtk_container_get_children(GTK_CONTAINER(row));
594 auto* box_infos = g_list_first(row_children)->data;
595 auto* children = gtk_container_get_children(GTK_CONTAINER(box_infos));
596 return GTK_LABEL(g_list_last(children)->data);
597}
598
599static void
600transfer_to_conversation(GtkListBox*, GtkListBoxRow* row, CurrentCallView* self)
601{
602 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
603 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
604 auto* sip_address = get_sip_address_label(row);
605 transfer_to_peer(priv, gtk_label_get_text(GTK_LABEL(sip_address)));
606}
607
608static void
609filter_transfer_list(CurrentCallView *self)
610{
611 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
612 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
613
614 std::string currentFilter = gtk_entry_get_text(GTK_ENTRY(priv->siptransfer_filter_entry));
615
616 auto row = 0;
617 while (GtkWidget* children = GTK_WIDGET(gtk_list_box_get_row_at_index(GTK_LIST_BOX(priv->list_conversations), row))) {
618 auto* sip_address = get_sip_address_label(GTK_LIST_BOX_ROW(children));;
619 if (row == 0) {
620 // Update searching item
621 if (currentFilter.empty() || currentFilter == priv->cpp->conversation->participants.front()) {
622 // Hide temporary item if filter is empty or same number
623 gtk_widget_hide(children);
624 } else {
625 // Else, show the temporary item (and select it)
626 gtk_label_set_text(GTK_LABEL(sip_address), currentFilter.c_str());
627 gtk_widget_show_all(children);
628 gtk_list_box_select_row(GTK_LIST_BOX(priv->list_conversations), GTK_LIST_BOX_ROW(children));
629 }
630 } else {
631 // It's a contact
632 std::string item_address = gtk_label_get_text(GTK_LABEL(sip_address));
633
634 if (item_address == priv->cpp->conversation->participants.front())
635 // if item is the current conversation, hide it
636 gtk_widget_hide(children);
637 else if (currentFilter.empty())
638 // filter is empty, show all items
639 gtk_widget_show_all(children);
640 else if (item_address.find(currentFilter) == std::string::npos || item_address == currentFilter)
641 // avoid duplicates and unwanted numbers
642 gtk_widget_hide(children);
643 else
644 // Item is filtered
645 gtk_widget_show_all(children);
646 }
647 ++row;
648 }
649}
650
651static void
652on_button_transfer_clicked(CurrentCallView *self)
653{
654 // Show and init list
655 g_return_if_fail(IS_CURRENT_CALL_VIEW(self));
656 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
657 gtk_popover_set_relative_to(GTK_POPOVER(priv->siptransfer_popover), GTK_WIDGET(priv->togglebutton_transfer));
658#if GTK_CHECK_VERSION(3,22,0)
659 gtk_popover_popdown(GTK_POPOVER(priv->siptransfer_popover));
660#else
661 gtk_widget_show_all(GTK_WIDGET(priv->siptransfer_popover));
662#endif
663 gtk_widget_show_all(priv->siptransfer_popover);
664 filter_transfer_list(self);
665}
666
667static void
668on_siptransfer_text_changed(GtkSearchEntry*, CurrentCallView* self)
669{
670 filter_transfer_list(self);
671}
672
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500673} // namespace gtk_callbacks
674
675CppImpl::CppImpl(CurrentCallView& widget)
676 : self {&widget}
677 , widgets {CURRENT_CALL_VIEW_GET_PRIVATE(&widget)}
678{}
679
680CppImpl::~CppImpl()
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400681{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500682 QObject::disconnect(state_change_connection);
683 QObject::disconnect(local_renderer_connection);
684 QObject::disconnect(remote_renderer_connection);
685 QObject::disconnect(smartinfo_refresh_connection);
686 QObject::disconnect(new_message_connection);
687 g_clear_object(&widgets->settings);
688
689 g_source_remove(timer_fade);
690
691 auto* display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()),
692 "display-smartinfo");
693 g_signal_handler_disconnect(display_smartinfo, smartinfo_action);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400694}
695
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500696void
697CppImpl::init()
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400698{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500699 // CSS styles
700 auto provider = gtk_css_provider_new();
701 gtk_css_provider_load_from_data(provider,
Sébastien Blin784f2a32018-05-30 17:31:13 -0400702 ".search-entry-style { border: 0; border-radius: 0; } \
703 .smartinfo-block-style { color: #8ae234; background-color: rgba(1, 1, 1, 0.33); } \
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500704 @keyframes blink { 0% {opacity: 1;} 49% {opacity: 1;} 50% {opacity: 0;} 100% {opacity: 0;} } \
705 .record-button { background: rgba(0, 0, 0, 1); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
706 .record-button:checked { animation: blink 1s; animation-iteration-count: infinite; } \
707 .call-button { background: rgba(0, 0, 0, 0.35); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
708 .call-button:hover { background: rgba(0, 0, 0, 0.2); } \
709 .call-button:disabled { opacity: 0.2; } \
710 .can-be-disabled:checked { background: rgba(219, 58, 55, 1); } \
711 .hangup-button-style { background: rgba(219, 58, 55, 1); border-radius: 50%; border: 0; transition: all 0.3s ease; } \
712 .hangup-button-style:hover { background: rgba(219, 39, 25, 1); }",
713 -1, nullptr
714 );
715 gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
716 GTK_STYLE_PROVIDER(provider),
717 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
718
719 widgets->video_widget = video_widget_new();
720 gtk_container_add(GTK_CONTAINER(widgets->frame_video), widgets->video_widget);
721 gtk_widget_show_all(widgets->frame_video);
722
723 // add the overlay controls only once the view has been allocated a size to prevent size
724 // allocation warnings in the log
725 insert_controls_id = g_signal_connect(self, "size-allocate", G_CALLBACK(on_size_allocate), nullptr);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400726}
727
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500728void
729CppImpl::setup(WebKitChatContainer* chat_widget,
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400730 AccountInfoPointer const & account_info,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500731 lrc::api::conversation::Info* conv_info)
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400732{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500733 widgets->webkit_chat_container = GTK_WIDGET(chat_widget);
734 conversation = conv_info;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400735 accountInfo = &account_info;
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500736 setCallInfo();
Sébastien Blin784f2a32018-05-30 17:31:13 -0400737
738 if ((*accountInfo)->profileInfo.type == lrc::api::profile::Type::RING)
739 gtk_widget_hide(widgets->togglebutton_transfer);
740 else {
741 // Remove previous list
742 while (GtkWidget* children = GTK_WIDGET(gtk_list_box_get_row_at_index(GTK_LIST_BOX(widgets->list_conversations), 10)))
743 gtk_container_remove(GTK_CONTAINER(widgets->list_conversations), children);
744 // Fill with SIP contacts
745 add_transfer_contact(""); // Temporary item
746 for (const auto& c : (*accountInfo)->conversationModel->getFilteredConversations(lrc::api::profile::Type::SIP))
747 add_transfer_contact(c.participants.front());
748 gtk_widget_show_all(widgets->list_conversations);
749 gtk_widget_show(widgets->togglebutton_transfer);
750 }
751}
752
753void
754CppImpl::add_transfer_contact(const std::string& uri)
755{
756 auto* box_item = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
757 auto pixbufmanipulator = Interfaces::PixbufManipulator();
758 auto image_buf = pixbufmanipulator.generateAvatar("", uri.empty() ? uri : "sip" + uri);
759 auto scaled = pixbufmanipulator.scaleAndFrame(image_buf.get(), QSize(48, 48));
760 auto* avatar = gtk_image_new_from_pixbuf(scaled.get());
761 auto* address = gtk_label_new(uri.c_str());
762 gtk_container_add(GTK_CONTAINER(box_item), GTK_WIDGET(avatar));
763 gtk_container_add(GTK_CONTAINER(box_item), GTK_WIDGET(address));
764 gtk_list_box_insert(GTK_LIST_BOX(widgets->list_conversations), GTK_WIDGET(box_item), -1);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400765}
766
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500767void
768CppImpl::setCallInfo()
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400769{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500770 // change some things depending on call state
771 updateState();
772 updateDetails();
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400773
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500774 // NOTE/TODO we need to rewrite the video_widget file to use the new LRC.
775 g_signal_connect(widgets->video_widget, "button-press-event",
776 G_CALLBACK(video_widget_on_button_press_in_screen_event), nullptr);
777
778 // check if we already have a renderer
779 auto callToRender = conversation->callId;
780 if (!conversation->confId.empty())
781 callToRender = conversation->confId;
782 video_widget_push_new_renderer(VIDEO_WIDGET(widgets->video_widget),
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400783 (*accountInfo)->callModel->getRenderer(callToRender),
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500784 VIDEO_RENDERER_REMOTE);
785
786 // local renderer
787 if (Video::PreviewManager::instance().isPreviewing())
788 video_widget_push_new_renderer(VIDEO_WIDGET(widgets->video_widget),
789 Video::PreviewManager::instance().previewRenderer(),
790 VIDEO_RENDERER_LOCAL);
791
792 // callback for local renderer
793 local_renderer_connection = QObject::connect(
794 &Video::PreviewManager::instance(),
795 &Video::PreviewManager::previewStarted,
796 [this] (Video::Renderer* renderer) {
797 video_widget_push_new_renderer(VIDEO_WIDGET(widgets->video_widget),
798 renderer,
799 VIDEO_RENDERER_LOCAL);
800 }
801 );
802
803 smartinfo_refresh_connection = QObject::connect(
804 &SmartInfoHub::instance(),
805 &SmartInfoHub::changed,
806 [this] { updateSmartInfo(); }
807 );
808
809 remote_renderer_connection = QObject::connect(
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400810 &*(*accountInfo)->callModel,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500811 &lrc::api::NewCallModel::remotePreviewStarted,
812 [this] (const std::string& callId, Video::Renderer* renderer) {
813 if (conversation->callId == callId) {
814 video_widget_push_new_renderer(VIDEO_WIDGET(widgets->video_widget),
815 renderer,
816 VIDEO_RENDERER_REMOTE);
817 }
818 });
819
820 state_change_connection = QObject::connect(
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400821 &*(*accountInfo)->callModel,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500822 &lrc::api::NewCallModel::callStatusChanged,
823 [this] (const std::string& callId) {
824 if (callId == conversation->callId) {
825 updateState();
826 updateNameAndPhoto();
827 }
828 });
829
830 new_message_connection = QObject::connect(
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400831 &*(*accountInfo)->conversationModel,
Nicolas Jager6635b0d2018-01-24 12:25:28 -0500832 &lrc::api::ConversationModel::newInteraction,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500833 [this] (const std::string& uid, uint64_t msgId, lrc::api::interaction::Info msg) {
834 Q_UNUSED(uid)
835 Q_UNUSED(msgId)
836 Q_UNUSED(msg)
837 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->togglebutton_chat), TRUE);
838 });
839
840 // catch double click to make full screen
841 g_signal_connect(widgets->video_widget, "button-press-event",
842 G_CALLBACK(on_button_press_in_video_event), self);
843
844 // handle smartinfo in right click menu
845 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()),
846 "display-smartinfo");
847 smartinfo_action = g_signal_connect(display_smartinfo,
848 "notify::state",
849 G_CALLBACK(on_toggle_smartinfo),
850 widgets->vbox_call_smartInfo);
851
852 // init chat view
853 widgets->chat_view = chat_view_new(WEBKIT_CHAT_CONTAINER(widgets->webkit_chat_container),
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400854 *accountInfo, conversation);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500855 gtk_container_add(GTK_CONTAINER(widgets->frame_chat), widgets->chat_view);
856
857 g_signal_connect_swapped(widgets->chat_view, "new-interactions-displayed",
858 G_CALLBACK(on_new_chat_interactions), self);
859 chat_view_set_header_visible(CHAT_VIEW(widgets->chat_view), FALSE);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400860}
861
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500862void
863CppImpl::insertControls()
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500864{
Stepan Salenikovich88092932017-05-15 18:19:00 -0400865 /* only add the controls once */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500866 g_signal_handler_disconnect(self, insert_controls_id);
867 insert_controls_id = 0;
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500868
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500869 auto stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(widgets->video_widget));
870 auto actor_info = gtk_clutter_actor_new_with_contents(widgets->hbox_call_info);
871 auto actor_controls = gtk_clutter_actor_new_with_contents(widgets->hbox_call_controls);
872 auto actor_smartInfo = gtk_clutter_actor_new_with_contents(widgets->vbox_call_smartInfo);
Stepan Salenikoviche178e632015-11-06 13:31:19 -0500873
874 clutter_actor_add_child(stage, actor_info);
875 clutter_actor_set_x_align(actor_info, CLUTTER_ACTOR_ALIGN_FILL);
876 clutter_actor_set_y_align(actor_info, CLUTTER_ACTOR_ALIGN_START);
877
878 clutter_actor_add_child(stage, actor_controls);
879 clutter_actor_set_x_align(actor_controls, CLUTTER_ACTOR_ALIGN_CENTER);
880 clutter_actor_set_y_align(actor_controls, CLUTTER_ACTOR_ALIGN_END);
881
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400882 clutter_actor_add_child(stage, actor_smartInfo);
883 clutter_actor_set_x_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_END);
884 clutter_actor_set_y_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_START);
885 ClutterMargin clutter_margin_smartInfo;
886 clutter_margin_smartInfo.top = 50;
887 clutter_margin_smartInfo.right = 10;
philippegorleya7337942017-07-04 15:29:42 -0400888 clutter_margin_smartInfo.left = 10;
889 clutter_margin_smartInfo.bottom = 10;
Olivier Gregoire66e4df72016-06-17 18:39:05 -0400890 clutter_actor_set_margin (actor_smartInfo, &clutter_margin_smartInfo);
891
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500892 /* add fade in and out states to the info and controls */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500893 time_last_mouse_motion = g_get_monotonic_time();
894 fade_info = create_fade_out_transition();
895 fade_controls = create_fade_out_transition();
896 clutter_actor_add_transition(actor_info, "fade_info", fade_info);
897 clutter_actor_add_transition(actor_controls, "fade_controls", fade_controls);
898 clutter_timeline_set_direction(CLUTTER_TIMELINE(fade_info), CLUTTER_TIMELINE_BACKWARD);
899 clutter_timeline_set_direction(CLUTTER_TIMELINE(fade_controls), CLUTTER_TIMELINE_BACKWARD);
900 clutter_timeline_stop(CLUTTER_TIMELINE(fade_info));
901 clutter_timeline_stop(CLUTTER_TIMELINE(fade_controls));
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500902
903 /* have a timer check every 1 second if the controls should fade out */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500904 timer_fade = g_timeout_add(1000, (GSourceFunc)on_timer_fade_timeout, self);
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500905
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400906 /* connect the controllers (new model) */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500907 g_signal_connect_swapped(widgets->button_hangup, "clicked", G_CALLBACK(on_button_hangup_clicked), self);
Sébastien Blin784f2a32018-05-30 17:31:13 -0400908 g_signal_connect_swapped(widgets->togglebutton_transfer, "clicked", G_CALLBACK(on_button_transfer_clicked), self);
909 g_signal_connect_swapped(widgets->siptransfer_filter_entry, "activate", G_CALLBACK(on_siptransfer_filter_activated), self);
910 g_signal_connect(widgets->siptransfer_filter_entry, "search-changed", G_CALLBACK(on_siptransfer_text_changed), self);
911 g_signal_connect(widgets->list_conversations, "row-activated", G_CALLBACK(transfer_to_conversation), self);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500912 g_signal_connect_swapped(widgets->togglebutton_hold, "clicked", G_CALLBACK(on_togglebutton_hold_clicked), self);
913 g_signal_connect_swapped(widgets->togglebutton_muteaudio, "clicked", G_CALLBACK(on_togglebutton_muteaudio_clicked), self);
914 g_signal_connect_swapped(widgets->togglebutton_record, "clicked", G_CALLBACK(on_togglebutton_record_clicked), self);
915 g_signal_connect_swapped(widgets->togglebutton_mutevideo, "clicked", G_CALLBACK(on_togglebutton_mutevideo_clicked), self);
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400916
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500917 /* connect to the mouse motion event to reset the last moved time */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500918 g_signal_connect_swapped(widgets->video_widget, "motion-notify-event", G_CALLBACK(on_mouse_moved), self);
919 g_signal_connect_swapped(widgets->video_widget, "button-press-event", G_CALLBACK(on_mouse_moved), self);
920 g_signal_connect_swapped(widgets->video_widget, "button-release-event", G_CALLBACK(on_mouse_moved), self);
Stepan Salenikovich0c7aa2a2015-11-06 17:00:08 -0500921
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500922 /* manually handle the focus of the video widget to be able to focus on the call controls */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500923 g_signal_connect(widgets->video_widget, "focus", G_CALLBACK(on_video_widget_focus), self);
Stepan Salenikovich5ed1b492015-11-13 14:03:31 -0500924
Sébastien Blin55bff9d2017-10-03 15:15:23 -0400925
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500926 /* toggle whether or not the chat is displayed */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500927 g_signal_connect(widgets->togglebutton_chat, "toggled", G_CALLBACK(on_togglebutton_chat_toggled), self);
Stepan Salenikovicha448f602015-05-29 13:33:06 -0400928
Stepan Salenikovichd2cad062016-01-08 13:43:49 -0500929 /* bind the chat orientation to the gsetting */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500930 widgets->settings = g_settings_new_full(get_ring_schema(), nullptr, nullptr);
931 g_settings_bind_with_mapping(widgets->settings, "chat-pane-horizontal",
932 widgets->paned_call, "orientation",
Stepan Salenikovicha5e8e362015-11-05 16:50:48 -0500933 G_SETTINGS_BIND_GET,
934 map_boolean_to_orientation,
935 nullptr, nullptr, nullptr);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500936
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500937 g_signal_connect(widgets->scalebutton_quality, "value-changed", G_CALLBACK(on_quality_changed), self);
938
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500939 /* customize the quality button scale */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500940 if (auto scale_box = gtk_scale_button_get_box(GTK_SCALE_BUTTON(widgets->scalebutton_quality))) {
941 widgets->checkbutton_autoquality = gtk_check_button_new_with_label(C_("Enable automatic video quality",
942 "Auto"));
943 gtk_widget_show(widgets->checkbutton_autoquality);
944 gtk_box_pack_start(GTK_BOX(scale_box), widgets->checkbutton_autoquality, FALSE, TRUE, 0);
945 g_signal_connect(widgets->checkbutton_autoquality, "toggled", G_CALLBACK(on_autoquality_toggled), self);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500946 }
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500947 if (auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(widgets->scalebutton_quality))) {
948 g_signal_connect(scale, "button-press-event", G_CALLBACK(on_quality_button_pressed), self);
949 g_signal_connect(scale, "button-release-event", G_CALLBACK(on_quality_button_released), self);
Stepan Salenikovich7e283552015-12-21 16:17:52 -0500950 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400951
Sébastien Blin3667fa62017-11-23 09:11:53 -0500952 /* by this time we should have the call already set, but we check to make sure */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500953 auto callToRender = conversation->callId;
954 if (!conversation->confId.empty())
955 callToRender = conversation->confId;
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -0400956 auto renderer = (*accountInfo)->callModel->getRenderer(callToRender);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500957 for (auto* activeCall: CallModel::instance().getActiveCalls())
958 if (activeCall and activeCall->videoRenderer() == renderer) {
959 g_signal_connect(widgets->video_widget, "drag-data-received",
960 G_CALLBACK(video_widget_on_drag_data_received), activeCall);
Sébastien Blin3667fa62017-11-23 09:11:53 -0500961 /* check if auto quality is enabled or not */
962 if (const auto& codecModel = activeCall->account()->codecModel()) {
963 const auto& videoCodecs = codecModel->videoCodecs();
964 if (videoCodecs->rowCount() > 0) {
965 /* we only need to check the first codec since by default it is ON for all, and the
966 * gnome client sets its ON or OFF for all codecs as well */
967 const auto& idx = videoCodecs->index(0,0);
968 auto auto_quality_enabled = idx.data(static_cast<int>(CodecModel::Role::AUTO_QUALITY_ENABLED)).toString() == "true";
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500969 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->checkbutton_autoquality),
970 auto_quality_enabled);
Sébastien Blin3667fa62017-11-23 09:11:53 -0500971
972 // TODO: save the manual quality setting in the client and set the slider to that value here;
973 // the daemon resets the bitrate/quality between each call, and the default may be
974 // different for each codec, so there is no reason to check it here
975 }
976 }
977 } else {
978 /* Auto-quality is off by default */
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500979 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->checkbutton_autoquality), FALSE);
Sébastien Blin3667fa62017-11-23 09:11:53 -0500980 }
981
Sébastien Blin4514eeb2017-07-25 14:17:01 -0400982 // Get if the user wants to show the smartInfo box
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500983 auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()),
984 "display-smartinfo");
Sébastien Blin4514eeb2017-07-25 14:17:01 -0400985 if (g_variant_get_boolean(g_action_get_state(G_ACTION(display_smartinfo)))) {
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500986 gtk_widget_show(widgets->vbox_call_smartInfo);
Sébastien Blin4514eeb2017-07-25 14:17:01 -0400987 } else {
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500988 gtk_widget_hide(widgets->vbox_call_smartInfo);
Sébastien Blin4514eeb2017-07-25 14:17:01 -0400989 }
Stepan Salenikovich88092932017-05-15 18:19:00 -0400990}
991
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -0500992void
993CppImpl::updateDetails()
994{
995 auto callRendered = conversation->callId;
996
997 if (!conversation->confId.empty())
998 callRendered = conversation->confId;
999
1000 gtk_label_set_text(GTK_LABEL(widgets->label_duration),
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -04001001 (*accountInfo)->callModel->getFormattedCallDuration(callRendered).c_str());
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001002
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -04001003 auto call = (*accountInfo)->callModel->getCall(callRendered);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001004 gtk_widget_set_sensitive(GTK_WIDGET(widgets->togglebutton_muteaudio),
1005 (call.type != lrc::api::call::Type::CONFERENCE));
1006 gtk_widget_set_sensitive(GTK_WIDGET(widgets->togglebutton_mutevideo),
1007 (call.type != lrc::api::call::Type::CONFERENCE));
1008}
1009
1010void
1011CppImpl::updateState()
1012{
1013 if (conversation) return;
1014
1015 auto callId = conversation->callId;
1016
1017 try {
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -04001018 auto call = (*accountInfo)->callModel->getCall(callId);
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001019
1020 auto pauseBtn = GTK_TOGGLE_BUTTON(widgets->togglebutton_hold);
1021 auto image = gtk_image_new_from_resource ("/cx/ring/RingGnome/pause");
1022 if (call.status == lrc::api::call::Status::PAUSED)
1023 image = gtk_image_new_from_resource ("/cx/ring/RingGnome/play");
1024 gtk_button_set_image(GTK_BUTTON(pauseBtn), image);
1025
1026 auto audioButton = GTK_TOGGLE_BUTTON(widgets->togglebutton_muteaudio);
1027 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->togglebutton_muteaudio), call.audioMuted);
1028 auto imageMuteAudio = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_audio");
1029 if (call.audioMuted)
1030 imageMuteAudio = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_audio");
1031 gtk_button_set_image(GTK_BUTTON(audioButton), imageMuteAudio);
1032
1033 auto videoButton = GTK_TOGGLE_BUTTON(widgets->togglebutton_mutevideo);
1034 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->togglebutton_mutevideo), call.videoMuted);
1035 auto imageMuteVideo = gtk_image_new_from_resource ("/cx/ring/RingGnome/mute_video");
1036 if (call.videoMuted)
1037 imageMuteVideo = gtk_image_new_from_resource ("/cx/ring/RingGnome/unmute_video");
1038 gtk_button_set_image(GTK_BUTTON(videoButton), imageMuteVideo);
1039
1040 gchar *status = g_strdup_printf("%s", lrc::api::call::to_string(call.status).c_str());
1041 gtk_label_set_text(GTK_LABEL(widgets->label_status), status);
1042 g_free(status);
1043 } catch (std::out_of_range& e) {
1044 g_warning("Can't update state for callId=%s", callId.c_str());
1045 }
1046}
1047
1048void
1049CppImpl::updateNameAndPhoto()
1050{
1051 QVariant var_i = GlobalInstances::pixmapManipulator().conversationPhoto(
1052 *conversation,
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -04001053 **(accountInfo),
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001054 QSize(60, 60),
1055 false
1056 );
1057 std::shared_ptr<GdkPixbuf> image = var_i.value<std::shared_ptr<GdkPixbuf>>();
1058 gtk_image_set_from_pixbuf(GTK_IMAGE(widgets->image_peer), image.get());
1059
1060 try {
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -04001061 auto contactInfo = (*accountInfo)->contactModel->getContact(conversation->participants.front());
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001062 auto name = contactInfo.profileInfo.alias;
1063 gtk_label_set_text(GTK_LABEL(widgets->label_name), name.c_str());
1064
1065 auto bestId = contactInfo.registeredName;
1066 if (name != bestId) {
1067 gtk_label_set_text(GTK_LABEL(widgets->label_bestId), bestId.c_str());
1068 gtk_widget_show(widgets->label_bestId);
1069 }
1070 } catch (const std::out_of_range&) {
1071 // ContactModel::getContact() exception
1072 }
1073}
1074
1075void
1076CppImpl::updateSmartInfo()
1077{
1078 if (!SmartInfoHub::instance().isConference()) {
1079 gchar* general_information = g_strdup_printf(
1080 "Call ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
1081 gtk_label_set_text(GTK_LABEL(widgets->label_smartinfo_general_information), general_information);
1082 g_free(general_information);
1083
1084 gchar* description = g_strdup_printf("You\n"
1085 "Framerate:\n"
1086 "Video codec:\n"
1087 "Audio codec:\n"
1088 "Resolution:\n\n"
1089 "Peer\n"
1090 "Framerate:\n"
1091 "Video codec:\n"
1092 "Audio codec:\n"
1093 "Resolution:");
1094 gtk_label_set_text(GTK_LABEL(widgets->label_smartinfo_description),description);
1095 g_free(description);
1096
1097 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",
1098 (double)SmartInfoHub::instance().localFps(),
1099 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
1100 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
1101 SmartInfoHub::instance().localWidth(),
1102 SmartInfoHub::instance().localHeight(),
1103 (double)SmartInfoHub::instance().remoteFps(),
1104 SmartInfoHub::instance().remoteVideoCodec().toStdString().c_str(),
1105 SmartInfoHub::instance().remoteAudioCodec().toStdString().c_str(),
1106 SmartInfoHub::instance().remoteWidth(),
1107 SmartInfoHub::instance().remoteHeight());
1108 gtk_label_set_text(GTK_LABEL(widgets->label_smartinfo_value),value);
1109 g_free(value);
1110 } else {
1111 gchar* general_information = g_strdup_printf(
1112 "Conference ID: %s", SmartInfoHub::instance().callID().toStdString().c_str());
1113 gtk_label_set_text(GTK_LABEL(widgets->label_smartinfo_general_information), general_information);
1114 g_free(general_information);
1115
1116 gchar* description = g_strdup_printf("You\n"
1117 "Framerate:\n"
1118 "Video codec:\n"
1119 "Audio codec:\n"
1120 "Resolution:");
1121 gtk_label_set_text(GTK_LABEL(widgets->label_smartinfo_description),description);
1122 g_free(description);
1123
1124 gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d",
1125 (double)SmartInfoHub::instance().localFps(),
1126 SmartInfoHub::instance().localVideoCodec().toStdString().c_str(),
1127 SmartInfoHub::instance().localAudioCodec().toStdString().c_str(),
1128 SmartInfoHub::instance().localWidth(),
1129 SmartInfoHub::instance().localHeight());
1130 gtk_label_set_text(GTK_LABEL(widgets->label_smartinfo_value),value);
1131 g_free(value);
1132 }
1133}
1134
1135void
1136CppImpl::checkControlsFading()
1137{
1138 auto current_time = g_get_monotonic_time();
1139 if (current_time - time_last_mouse_motion >= CONTROLS_FADE_TIMEOUT) {
1140 // timeout has passed, hide the controls
1141 if (clutter_timeline_get_direction(CLUTTER_TIMELINE(fade_info)) == CLUTTER_TIMELINE_BACKWARD) {
1142 clutter_timeline_set_direction(CLUTTER_TIMELINE(fade_info), CLUTTER_TIMELINE_FORWARD);
1143 clutter_timeline_set_direction(CLUTTER_TIMELINE(fade_controls), CLUTTER_TIMELINE_FORWARD);
1144 if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(fade_info))) {
1145 clutter_timeline_rewind(CLUTTER_TIMELINE(fade_info));
1146 clutter_timeline_rewind(CLUTTER_TIMELINE(fade_controls));
1147 clutter_timeline_start(CLUTTER_TIMELINE(fade_info));
1148 clutter_timeline_start(CLUTTER_TIMELINE(fade_controls));
1149 }
1150 }
1151 }
1152
1153 updateDetails();
1154}
1155
1156}} // namespace <anonymous>::details
1157
1158//==============================================================================
1159
1160lrc::api::conversation::Info
1161current_call_view_get_conversation(CurrentCallView *self)
1162{
1163 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), lrc::api::conversation::Info());
1164 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
1165 return *priv->cpp->conversation;
1166}
1167
1168GtkWidget *
1169current_call_view_get_chat_view(CurrentCallView *self)
1170{
1171 g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), nullptr);
1172 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
1173 return priv->chat_view;
1174}
1175
1176//==============================================================================
1177
Stepan Salenikovich88092932017-05-15 18:19:00 -04001178static void
1179current_call_view_init(CurrentCallView *view)
1180{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001181 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovich88092932017-05-15 18:19:00 -04001182 gtk_widget_init_template(GTK_WIDGET(view));
1183
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001184 // CppImpl ctor
1185 priv->cpp = new details::CppImpl {*view};
1186 priv->cpp->init();
1187}
Stepan Salenikovich88092932017-05-15 18:19:00 -04001188
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001189static void
1190current_call_view_dispose(GObject *object)
1191{
1192 auto* view = CURRENT_CALL_VIEW(object);
1193 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
Stepan Salenikovich88092932017-05-15 18:19:00 -04001194
Hugo Lefeuvreedad8832018-05-14 16:36:06 -04001195 // navbar was hidden during setCallInfo, we need to make it visible again before view destruction
1196 auto children = gtk_container_get_children(GTK_CONTAINER(priv->frame_chat));
1197 auto chat_view = children->data;
1198 chat_view_set_header_visible(CHAT_VIEW(chat_view), TRUE);
1199
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001200 delete priv->cpp;
1201 priv->cpp = nullptr;
Stepan Salenikovich88092932017-05-15 18:19:00 -04001202
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001203 G_OBJECT_CLASS(current_call_view_parent_class)->dispose(object);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05001204}
1205
1206static void
1207current_call_view_class_init(CurrentCallViewClass *klass)
1208{
1209 G_OBJECT_CLASS(klass)->dispose = current_call_view_dispose;
1210
1211 gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass),
1212 "/cx/ring/RingGnome/currentcallview.ui");
1213
Stepan Salenikoviche178e632015-11-06 13:31:19 -05001214 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_info);
1215 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_controls);
Olivier Gregoire66e4df72016-06-17 18:39:05 -04001216 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, vbox_call_smartInfo);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05001217 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, image_peer);
Stepan Salenikovich07107e92016-05-06 10:35:17 -04001218 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_name);
Nicolas Jager2e467c32017-01-18 08:52:23 -05001219 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_bestId);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05001220 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_status);
1221 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_duration);
Olivier Gregoire66e4df72016-06-17 18:39:05 -04001222 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_description);
1223 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_value);
1224 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_general_information);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -05001225 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, paned_call);
Stepan Salenikovich36c025c2015-03-03 19:06:44 -05001226 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video);
Stepan Salenikovichd2cad062016-01-08 13:43:49 -05001227 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat);
Stepan Salenikovicha448f602015-05-29 13:33:06 -04001228 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat);
Sébastien Blin784f2a32018-05-30 17:31:13 -04001229 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_transfer);
AmarOke7c02972017-07-17 15:21:20 -04001230 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_hold);
1231 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_muteaudio);
Sébastien Blin55bff9d2017-10-03 15:15:23 -04001232 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_record);
AmarOke7c02972017-07-17 15:21:20 -04001233 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_mutevideo);
Stepan Salenikovich77baa522015-07-07 15:29:14 -04001234 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, button_hangup);
Stepan Salenikovich7e283552015-12-21 16:17:52 -05001235 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, scalebutton_quality);
Sébastien Blin784f2a32018-05-30 17:31:13 -04001236 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, siptransfer_popover);
1237 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, siptransfer_filter_entry);
1238 gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, list_conversations);
Stepan Salenikoviche1b54892015-12-13 22:18:44 -05001239
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001240 details::current_call_view_signals[VIDEO_DOUBLE_CLICKED] = g_signal_new (
Stepan Salenikoviche1b54892015-12-13 22:18:44 -05001241 "video-double-clicked",
1242 G_TYPE_FROM_CLASS(klass),
1243 (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
1244 0,
1245 nullptr,
1246 nullptr,
1247 g_cclosure_marshal_VOID__VOID,
1248 G_TYPE_NONE, 0);
Stepan Salenikovichc64523b2015-02-27 16:31:00 -05001249}
1250
Stepan Salenikovich09e0b782016-09-07 16:28:50 -04001251GtkWidget *
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001252current_call_view_new(WebKitChatContainer* chat_widget,
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -04001253 AccountInfoPointer const & accountInfo,
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001254 lrc::api::conversation::Info* conversation)
Stepan Salenikovich09e0b782016-09-07 16:28:50 -04001255{
Guillaume Roguezaaf8b0f2018-01-24 14:38:43 -05001256 auto* self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL);
1257 auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(self);
1258
Hugo Lefeuvre6f2ceb12018-04-18 15:08:01 -04001259 priv->cpp->setup(chat_widget, accountInfo, conversation);
Stepan Salenikovich09e0b782016-09-07 16:28:50 -04001260 return GTK_WIDGET(self);
1261}