Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 3 | * 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 Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "currentcallview.h" |
| 21 | |
| 22 | #include <gtk/gtk.h> |
Stepan Salenikovich | 7e28355 | 2015-12-21 16:17:52 -0500 | [diff] [blame] | 23 | #include <glib/gi18n.h> |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 24 | #include <call.h> |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 25 | #include <callmodel.h> |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 26 | #include "utils/drawing.h" |
| 27 | #include "video/video_widget.h" |
Stepan Salenikovich | 4ac89f1 | 2015-03-10 16:48:47 -0400 | [diff] [blame] | 28 | #include <video/previewmanager.h> |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 29 | #include <contactmethod.h> |
| 30 | #include <person.h> |
Stepan Salenikovich | bbd6c13 | 2015-08-20 15:21:48 -0400 | [diff] [blame] | 31 | #include <globalinstances.h> |
| 32 | #include "native/pixbufmanipulator.h" |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 33 | #include <media/media.h> |
| 34 | #include <media/text.h> |
| 35 | #include <media/textrecording.h> |
| 36 | #include "models/gtkqtreemodel.h" |
Stepan Salenikovich | 67112d1 | 2015-06-16 16:57:06 -0400 | [diff] [blame] | 37 | #include "ringnotify.h" |
Edric Milaret | 58e7107 | 2016-03-21 12:16:37 -0400 | [diff] [blame] | 38 | #include <codecmodel.h> |
Stepan Salenikovich | f6f4265 | 2015-07-15 12:46:14 -0400 | [diff] [blame] | 39 | #include <account.h> |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 40 | #include "utils/files.h" |
Stepan Salenikovich | e178e63 | 2015-11-06 13:31:19 -0500 | [diff] [blame] | 41 | #include <clutter-gtk/clutter-gtk.h> |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 42 | #include "chatview.h" |
Stepan Salenikovich | 07107e9 | 2016-05-06 10:35:17 -0400 | [diff] [blame] | 43 | #include <itemdataroles.h> |
| 44 | #include <numbercategory.h> |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 45 | #include <smartinfohub.h> |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 46 | |
Stepan Salenikovich | 0c7aa2a | 2015-11-06 17:00:08 -0500 | [diff] [blame] | 47 | static constexpr int CONTROLS_FADE_TIMEOUT = 3000000; /* microseconds */ |
| 48 | static constexpr int FADE_DURATION = 500; /* miliseconds */ |
| 49 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 50 | struct _CurrentCallView |
| 51 | { |
| 52 | GtkBox parent; |
| 53 | }; |
| 54 | |
| 55 | struct _CurrentCallViewClass |
| 56 | { |
| 57 | GtkBoxClass parent_class; |
| 58 | }; |
| 59 | |
| 60 | typedef struct _CurrentCallViewPrivate CurrentCallViewPrivate; |
| 61 | |
| 62 | struct _CurrentCallViewPrivate |
| 63 | { |
Stepan Salenikovich | e178e63 | 2015-11-06 13:31:19 -0500 | [diff] [blame] | 64 | GtkWidget *hbox_call_info; |
| 65 | GtkWidget *hbox_call_controls; |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 66 | GtkWidget *vbox_call_smartInfo; |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 67 | GtkWidget *image_peer; |
Stepan Salenikovich | 07107e9 | 2016-05-06 10:35:17 -0400 | [diff] [blame] | 68 | GtkWidget *label_name; |
Nicolas Jager | 2e467c3 | 2017-01-18 08:52:23 -0500 | [diff] [blame] | 69 | GtkWidget *label_bestId; |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 70 | GtkWidget *label_status; |
| 71 | GtkWidget *label_duration; |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 72 | GtkWidget *label_smartinfo_description; |
| 73 | GtkWidget *label_smartinfo_value; |
| 74 | GtkWidget *label_smartinfo_general_information; |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 75 | GtkWidget *paned_call; |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 76 | GtkWidget *frame_video; |
| 77 | GtkWidget *video_widget; |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 78 | GtkWidget *frame_chat; |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 79 | GtkWidget *togglebutton_chat; |
Stepan Salenikovich | 77baa52 | 2015-07-07 15:29:14 -0400 | [diff] [blame] | 80 | GtkWidget *button_hangup; |
Stepan Salenikovich | 7e28355 | 2015-12-21 16:17:52 -0500 | [diff] [blame] | 81 | GtkWidget *scalebutton_quality; |
| 82 | GtkWidget *checkbutton_autoquality; |
| 83 | |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 84 | /* The webkit_chat_container is created once, then reused for all chat |
| 85 | * views */ |
| 86 | GtkWidget *webkit_chat_container; |
| 87 | |
Stepan Salenikovich | 7e28355 | 2015-12-21 16:17:52 -0500 | [diff] [blame] | 88 | /* flag used to keep track of the video quality scale pressed state; |
| 89 | * we do not want to update the codec bitrate until the user releases the |
| 90 | * scale button */ |
| 91 | gboolean quality_scale_pressed; |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 92 | |
| 93 | Call *call; |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 94 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 95 | QMetaObject::Connection state_change_connection; |
| 96 | QMetaObject::Connection call_details_connection; |
Stepan Salenikovich | 46bb157 | 2017-05-19 16:09:43 -0400 | [diff] [blame^] | 97 | QMetaObject::Connection cm_changed_connection; |
| 98 | QMetaObject::Connection person_changed_connection; |
| 99 | QMetaObject::Connection cm_person_changed_connection; |
Stepan Salenikovich | c5f0815 | 2015-03-19 00:53:23 -0400 | [diff] [blame] | 100 | QMetaObject::Connection local_renderer_connection; |
| 101 | QMetaObject::Connection remote_renderer_connection; |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 102 | |
| 103 | GSettings *settings; |
Stepan Salenikovich | 0c7aa2a | 2015-11-06 17:00:08 -0500 | [diff] [blame] | 104 | |
| 105 | // for clutter animations and to know when to fade in/out the overlays |
| 106 | ClutterTransition *fade_info; |
| 107 | ClutterTransition *fade_controls; |
| 108 | gint64 time_last_mouse_motion; |
| 109 | guint timer_fade; |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 110 | |
Stepan Salenikovich | 8809293 | 2017-05-15 18:19:00 -0400 | [diff] [blame] | 111 | gulong insert_controls_id; |
| 112 | |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 113 | // smart info |
| 114 | QMetaObject::Connection smartinfo_refresh_connection; |
| 115 | guint smartinfo_action; |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | G_DEFINE_TYPE_WITH_PRIVATE(CurrentCallView, current_call_view, GTK_TYPE_BOX); |
| 119 | |
| 120 | #define CURRENT_CALL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CURRENT_CALL_VIEW_TYPE, CurrentCallViewPrivate)) |
| 121 | |
Stepan Salenikovich | e1b5489 | 2015-12-13 22:18:44 -0500 | [diff] [blame] | 122 | enum { |
| 123 | VIDEO_DOUBLE_CLICKED, |
| 124 | LAST_SIGNAL |
| 125 | }; |
| 126 | |
| 127 | static guint current_call_view_signals[LAST_SIGNAL] = { 0 }; |
| 128 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 129 | static void |
| 130 | current_call_view_dispose(GObject *object) |
| 131 | { |
| 132 | CurrentCallView *view; |
| 133 | CurrentCallViewPrivate *priv; |
| 134 | |
| 135 | view = CURRENT_CALL_VIEW(object); |
| 136 | priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 137 | |
| 138 | QObject::disconnect(priv->state_change_connection); |
| 139 | QObject::disconnect(priv->call_details_connection); |
Stepan Salenikovich | 46bb157 | 2017-05-19 16:09:43 -0400 | [diff] [blame^] | 140 | QObject::disconnect(priv->cm_changed_connection); |
| 141 | QObject::disconnect(priv->person_changed_connection); |
| 142 | QObject::disconnect(priv->cm_person_changed_connection); |
Stepan Salenikovich | c5f0815 | 2015-03-19 00:53:23 -0400 | [diff] [blame] | 143 | QObject::disconnect(priv->local_renderer_connection); |
| 144 | QObject::disconnect(priv->remote_renderer_connection); |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 145 | QObject::disconnect(priv->smartinfo_refresh_connection); |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 146 | g_clear_object(&priv->settings); |
| 147 | |
Stepan Salenikovich | 0c7aa2a | 2015-11-06 17:00:08 -0500 | [diff] [blame] | 148 | g_source_remove(priv->timer_fade); |
| 149 | |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 150 | auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo"); |
| 151 | g_signal_handler_disconnect(display_smartinfo, priv->smartinfo_action); |
| 152 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 153 | G_OBJECT_CLASS(current_call_view_parent_class)->dispose(object); |
| 154 | } |
| 155 | |
| 156 | static void |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 157 | show_chat_view(CurrentCallView *self) |
| 158 | { |
| 159 | g_return_if_fail(IS_CURRENT_CALL_VIEW(self)); |
| 160 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 161 | |
| 162 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE); |
| 163 | } |
| 164 | |
| 165 | static void |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 166 | chat_toggled(GtkToggleButton *togglebutton, CurrentCallView *self) |
| 167 | { |
| 168 | g_return_if_fail(IS_CURRENT_CALL_VIEW(self)); |
| 169 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 170 | |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 171 | if (gtk_toggle_button_get_active(togglebutton)) { |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 172 | gtk_widget_show_all(priv->frame_chat); |
| 173 | gtk_widget_grab_focus(priv->frame_chat); |
Stepan Salenikovich | a5129f6 | 2015-11-05 15:10:59 -0500 | [diff] [blame] | 174 | } else { |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 175 | gtk_widget_hide(priv->frame_chat); |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
Stepan Salenikovich | daf3cb3 | 2016-10-12 16:39:42 -0400 | [diff] [blame] | 179 | static gboolean |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 180 | map_boolean_to_orientation(GValue *value, GVariant *variant, G_GNUC_UNUSED gpointer user_data) |
| 181 | { |
| 182 | if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) { |
| 183 | if (g_variant_get_boolean(variant)) { |
| 184 | // true, chat should be horizontal (to the right) |
| 185 | g_value_set_enum(value, GTK_ORIENTATION_HORIZONTAL); |
| 186 | } else { |
| 187 | // false, chat should be vertical (at the bottom) |
| 188 | g_value_set_enum(value, GTK_ORIENTATION_VERTICAL); |
| 189 | } |
| 190 | return TRUE; |
| 191 | } |
| 192 | return FALSE; |
| 193 | } |
| 194 | |
Stepan Salenikovich | 0c7aa2a | 2015-11-06 17:00:08 -0500 | [diff] [blame] | 195 | static gboolean |
| 196 | timeout_check_last_motion_event(CurrentCallView *self) |
| 197 | { |
| 198 | g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), G_SOURCE_REMOVE); |
| 199 | auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 200 | |
| 201 | auto current_time = g_get_monotonic_time(); |
| 202 | if (current_time - priv->time_last_mouse_motion >= CONTROLS_FADE_TIMEOUT) { |
| 203 | // timeout has passed, hide the controls |
| 204 | if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_BACKWARD) { |
| 205 | clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_FORWARD); |
| 206 | clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_FORWARD); |
| 207 | if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) { |
| 208 | clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info)); |
| 209 | clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls)); |
| 210 | clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info)); |
| 211 | clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls)); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return G_SOURCE_CONTINUE; |
| 217 | } |
| 218 | |
| 219 | static gboolean |
| 220 | mouse_moved(CurrentCallView *self) |
| 221 | { |
| 222 | g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE); |
| 223 | auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 224 | |
| 225 | priv->time_last_mouse_motion = g_get_monotonic_time(); |
| 226 | |
| 227 | // since the mouse moved, make sure the controls are shown |
| 228 | if (clutter_timeline_get_direction(CLUTTER_TIMELINE(priv->fade_info)) == CLUTTER_TIMELINE_FORWARD) { |
| 229 | clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD); |
| 230 | clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD); |
| 231 | if (!clutter_timeline_is_playing(CLUTTER_TIMELINE(priv->fade_info))) { |
| 232 | clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_info)); |
| 233 | clutter_timeline_rewind(CLUTTER_TIMELINE(priv->fade_controls)); |
| 234 | clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_info)); |
| 235 | clutter_timeline_start(CLUTTER_TIMELINE(priv->fade_controls)); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | return FALSE; // propogate event |
| 240 | } |
| 241 | |
| 242 | static ClutterTransition * |
| 243 | create_fade_out_transition() |
| 244 | { |
| 245 | auto transition = clutter_property_transition_new("opacity"); |
| 246 | clutter_transition_set_from(transition, G_TYPE_UINT, 255); |
| 247 | clutter_transition_set_to(transition, G_TYPE_UINT, 0); |
| 248 | clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), FADE_DURATION); |
| 249 | clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), 0); |
| 250 | clutter_timeline_set_progress_mode(CLUTTER_TIMELINE(transition), CLUTTER_EASE_IN_OUT_CUBIC); |
| 251 | return transition; |
| 252 | } |
| 253 | |
Stepan Salenikovich | 5ed1b49 | 2015-11-13 14:03:31 -0500 | [diff] [blame] | 254 | static gboolean |
| 255 | video_widget_focus(GtkWidget *widget, GtkDirectionType direction, CurrentCallView *self) |
| 256 | { |
| 257 | g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE); |
| 258 | auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 259 | |
| 260 | // if this widget already has focus, we want the focus to move to the next widget, otherwise we |
| 261 | // will get stuck in a focus loop on the buttons |
| 262 | if (gtk_widget_has_focus(widget)) |
| 263 | return FALSE; |
| 264 | |
| 265 | // otherwise we want the focus to go to and change between the call control buttons |
| 266 | if (gtk_widget_child_focus(GTK_WIDGET(priv->hbox_call_controls), direction)) { |
| 267 | // selected a child, make sure call controls are shown |
| 268 | mouse_moved(self); |
| 269 | return TRUE; |
| 270 | } |
| 271 | |
| 272 | // did not select the next child, propogate the event |
| 273 | return FALSE; |
| 274 | } |
| 275 | |
Stepan Salenikovich | 7e28355 | 2015-12-21 16:17:52 -0500 | [diff] [blame] | 276 | static GtkBox * |
| 277 | gtk_scale_button_get_box(GtkScaleButton *button) |
| 278 | { |
| 279 | GtkWidget *box = NULL; |
| 280 | if (auto dock = gtk_scale_button_get_popup(button)) { |
| 281 | // the dock is a popover which contains the box |
| 282 | box = gtk_bin_get_child(GTK_BIN(dock)); |
| 283 | if (box) { |
| 284 | if (GTK_IS_FRAME(box)) { |
| 285 | // support older versions of gtk; the box used to be in a frame |
| 286 | box = gtk_bin_get_child(GTK_BIN(box)); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | return GTK_BOX(box); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * This gets the GtkScaleButtonScale widget (which is a GtkScale) from the |
| 296 | * given GtkScaleButton in order to be able to modify its properties and connect |
| 297 | * to its signals |
| 298 | */ |
| 299 | static GtkScale * |
| 300 | gtk_scale_button_get_scale(GtkScaleButton *button) |
| 301 | { |
| 302 | GtkScale *scale = NULL; |
| 303 | |
| 304 | if (auto box = gtk_scale_button_get_box(button)) { |
| 305 | GList *children = gtk_container_get_children(GTK_CONTAINER(box)); |
| 306 | for (GList *c = children; c && !scale; c = c->next) { |
| 307 | if (GTK_IS_SCALE(c->data)) |
| 308 | scale = GTK_SCALE(c->data); |
| 309 | } |
| 310 | g_list_free(children); |
| 311 | } |
| 312 | |
| 313 | return scale; |
| 314 | } |
| 315 | |
| 316 | static void |
| 317 | set_quality(Call *call, gboolean auto_quality_on, double desired_quality) |
| 318 | { |
| 319 | /* set auto quality true or false, also set the bitrate and quality values; |
| 320 | * the slider is from 0 to 100, use the min and max vals to scale each value accordingly */ |
| 321 | if (const auto& codecModel = call->account()->codecModel()) { |
| 322 | const auto& videoCodecs = codecModel->videoCodecs(); |
| 323 | |
| 324 | for (int i=0; i < videoCodecs->rowCount();i++) { |
| 325 | const auto& idx = videoCodecs->index(i,0); |
| 326 | |
| 327 | if (auto_quality_on) { |
| 328 | // g_debug("enable auto quality"); |
| 329 | videoCodecs->setData(idx, "true", CodecModel::Role::AUTO_QUALITY_ENABLED); |
| 330 | } else { |
| 331 | auto min_bitrate = idx.data(static_cast<int>(CodecModel::Role::MIN_BITRATE)).toInt(); |
| 332 | auto max_bitrate = idx.data(static_cast<int>(CodecModel::Role::MAX_BITRATE)).toInt(); |
| 333 | auto min_quality = idx.data(static_cast<int>(CodecModel::Role::MIN_QUALITY)).toInt(); |
| 334 | auto max_quality = idx.data(static_cast<int>(CodecModel::Role::MAX_QUALITY)).toInt(); |
| 335 | |
| 336 | // g_debug("bitrate min: %d, max: %d, quality min: %d, max: %d", min_bitrate, max_bitrate, min_quality, max_quality); |
| 337 | |
| 338 | double bitrate; |
| 339 | bitrate = min_bitrate + (double)(max_bitrate - min_bitrate)*(desired_quality/100.0); |
| 340 | if (bitrate < 0) bitrate = 0; |
| 341 | |
| 342 | double quality; |
| 343 | // note: a lower value means higher quality |
| 344 | quality = (double)min_quality - (min_quality - max_quality)*(desired_quality/100.0); |
| 345 | if (quality < 0) quality = 0; |
| 346 | |
| 347 | // g_debug("disable auto quality; %% quality: %d; bitrate: %d; quality: %d", (int)desired_quality, (int)bitrate, (int)quality); |
| 348 | videoCodecs->setData(idx, "false", CodecModel::Role::AUTO_QUALITY_ENABLED); |
| 349 | videoCodecs->setData(idx, QString::number((int)bitrate), CodecModel::Role::BITRATE); |
| 350 | videoCodecs->setData(idx, QString::number((int)quality), CodecModel::Role::QUALITY); |
| 351 | } |
| 352 | } |
| 353 | codecModel << CodecModel::EditAction::SAVE; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | static void |
| 358 | autoquality_toggled(GtkToggleButton *button, CurrentCallView *self) |
| 359 | { |
| 360 | g_return_if_fail(IS_CURRENT_CALL_VIEW(self)); |
| 361 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 362 | |
| 363 | gboolean auto_quality_on = gtk_toggle_button_get_active(button); |
| 364 | |
| 365 | auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality)); |
| 366 | auto plus_button = gtk_scale_button_get_plus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality)); |
| 367 | auto minus_button = gtk_scale_button_get_minus_button(GTK_SCALE_BUTTON(priv->scalebutton_quality)); |
| 368 | |
| 369 | gtk_widget_set_sensitive(GTK_WIDGET(scale), !auto_quality_on); |
| 370 | gtk_widget_set_sensitive(plus_button, !auto_quality_on); |
| 371 | gtk_widget_set_sensitive(minus_button, !auto_quality_on); |
| 372 | |
| 373 | double desired_quality = gtk_scale_button_get_value(GTK_SCALE_BUTTON(priv->scalebutton_quality)); |
| 374 | |
| 375 | if (priv->call) |
| 376 | set_quality(priv->call, auto_quality_on, desired_quality); |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | quality_changed(GtkScaleButton *button, G_GNUC_UNUSED gdouble value, CurrentCallView *self) |
| 381 | { |
| 382 | g_return_if_fail(IS_CURRENT_CALL_VIEW(self)); |
| 383 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 384 | |
| 385 | /* no need to upate quality if auto quality is enabled */ |
| 386 | if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality))) return; |
| 387 | |
| 388 | /* only update if the scale button is released, to reduce the number of updates */ |
| 389 | if (priv->quality_scale_pressed) return; |
| 390 | |
| 391 | /* we get the value directly from the widget, in case this function is not |
| 392 | * called from the event */ |
| 393 | if (priv->call) |
| 394 | set_quality(priv->call, FALSE, gtk_scale_button_get_value(button)); |
| 395 | } |
| 396 | |
| 397 | static gboolean |
| 398 | quality_button_pressed(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self) |
| 399 | { |
| 400 | g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE); |
| 401 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 402 | |
| 403 | priv->quality_scale_pressed = TRUE; |
| 404 | |
| 405 | return GDK_EVENT_PROPAGATE; |
| 406 | } |
| 407 | |
| 408 | static gboolean |
| 409 | quality_button_released(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, CurrentCallView *self) |
| 410 | { |
| 411 | g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), FALSE); |
| 412 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 413 | |
| 414 | priv->quality_scale_pressed = FALSE; |
| 415 | |
| 416 | /* now make sure the quality gets updated */ |
| 417 | quality_changed(GTK_SCALE_BUTTON(priv->scalebutton_quality), 0, self); |
| 418 | |
| 419 | return GDK_EVENT_PROPAGATE; |
| 420 | } |
| 421 | |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 422 | static void |
Stepan Salenikovich | 8809293 | 2017-05-15 18:19:00 -0400 | [diff] [blame] | 423 | insert_controls(CurrentCallView *view) |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 424 | { |
Stepan Salenikovich | 8809293 | 2017-05-15 18:19:00 -0400 | [diff] [blame] | 425 | auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 426 | |
Stepan Salenikovich | 8809293 | 2017-05-15 18:19:00 -0400 | [diff] [blame] | 427 | /* only add the controls once */ |
| 428 | g_signal_handler_disconnect(view, priv->insert_controls_id); |
| 429 | priv->insert_controls_id = 0; |
Stepan Salenikovich | e178e63 | 2015-11-06 13:31:19 -0500 | [diff] [blame] | 430 | |
| 431 | auto stage = gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(priv->video_widget)); |
| 432 | auto actor_info = gtk_clutter_actor_new_with_contents(priv->hbox_call_info); |
| 433 | auto actor_controls = gtk_clutter_actor_new_with_contents(priv->hbox_call_controls); |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 434 | auto actor_smartInfo = gtk_clutter_actor_new_with_contents(priv->vbox_call_smartInfo); |
Stepan Salenikovich | e178e63 | 2015-11-06 13:31:19 -0500 | [diff] [blame] | 435 | |
| 436 | clutter_actor_add_child(stage, actor_info); |
| 437 | clutter_actor_set_x_align(actor_info, CLUTTER_ACTOR_ALIGN_FILL); |
| 438 | clutter_actor_set_y_align(actor_info, CLUTTER_ACTOR_ALIGN_START); |
| 439 | |
| 440 | clutter_actor_add_child(stage, actor_controls); |
| 441 | clutter_actor_set_x_align(actor_controls, CLUTTER_ACTOR_ALIGN_CENTER); |
| 442 | clutter_actor_set_y_align(actor_controls, CLUTTER_ACTOR_ALIGN_END); |
| 443 | |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 444 | clutter_actor_add_child(stage, actor_smartInfo); |
| 445 | clutter_actor_set_x_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_END); |
| 446 | clutter_actor_set_y_align(actor_smartInfo, CLUTTER_ACTOR_ALIGN_START); |
| 447 | ClutterMargin clutter_margin_smartInfo; |
| 448 | clutter_margin_smartInfo.top = 50; |
| 449 | clutter_margin_smartInfo.right = 10; |
| 450 | clutter_actor_set_margin (actor_smartInfo, &clutter_margin_smartInfo); |
| 451 | |
Stepan Salenikovich | 0c7aa2a | 2015-11-06 17:00:08 -0500 | [diff] [blame] | 452 | /* add fade in and out states to the info and controls */ |
| 453 | priv->time_last_mouse_motion = g_get_monotonic_time(); |
| 454 | priv->fade_info = create_fade_out_transition(); |
| 455 | priv->fade_controls = create_fade_out_transition(); |
| 456 | clutter_actor_add_transition(actor_info, "fade_info", priv->fade_info); |
| 457 | clutter_actor_add_transition(actor_controls, "fade_controls", priv->fade_controls); |
| 458 | clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_info), CLUTTER_TIMELINE_BACKWARD); |
| 459 | clutter_timeline_set_direction(CLUTTER_TIMELINE(priv->fade_controls), CLUTTER_TIMELINE_BACKWARD); |
| 460 | clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_info)); |
| 461 | clutter_timeline_stop(CLUTTER_TIMELINE(priv->fade_controls)); |
| 462 | |
| 463 | /* have a timer check every 1 second if the controls should fade out */ |
| 464 | priv->timer_fade = g_timeout_add(1000, (GSourceFunc)timeout_check_last_motion_event, view); |
| 465 | |
| 466 | /* connect to the mouse motion event to reset the last moved time */ |
| 467 | g_signal_connect_swapped(priv->video_widget, "motion-notify-event", G_CALLBACK(mouse_moved), view); |
| 468 | g_signal_connect_swapped(priv->video_widget, "button-press-event", G_CALLBACK(mouse_moved), view); |
| 469 | g_signal_connect_swapped(priv->video_widget, "button-release-event", G_CALLBACK(mouse_moved), view); |
| 470 | |
Stepan Salenikovich | 5ed1b49 | 2015-11-13 14:03:31 -0500 | [diff] [blame] | 471 | /* manually handle the focus of the video widget to be able to focus on the call controls */ |
| 472 | g_signal_connect(priv->video_widget, "focus", G_CALLBACK(video_widget_focus), view); |
| 473 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 474 | /* toggle whether or not the chat is displayed */ |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 475 | g_signal_connect(priv->togglebutton_chat, "toggled", G_CALLBACK(chat_toggled), view); |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 476 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 477 | /* bind the chat orientation to the gsetting */ |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 478 | priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL); |
| 479 | g_settings_bind_with_mapping(priv->settings, "chat-pane-horizontal", |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 480 | priv->paned_call, "orientation", |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 481 | G_SETTINGS_BIND_GET, |
| 482 | map_boolean_to_orientation, |
| 483 | nullptr, nullptr, nullptr); |
Stepan Salenikovich | 7e28355 | 2015-12-21 16:17:52 -0500 | [diff] [blame] | 484 | |
| 485 | g_signal_connect(priv->scalebutton_quality, "value-changed", G_CALLBACK(quality_changed), view); |
| 486 | /* customize the quality button scale */ |
| 487 | if (auto scale_box = gtk_scale_button_get_box(GTK_SCALE_BUTTON(priv->scalebutton_quality))) { |
| 488 | priv->checkbutton_autoquality = gtk_check_button_new_with_label(C_("Enable automatic video quality", "Auto")); |
| 489 | gtk_widget_show(priv->checkbutton_autoquality); |
| 490 | gtk_box_pack_start(GTK_BOX(scale_box), priv->checkbutton_autoquality, FALSE, TRUE, 0); |
| 491 | g_signal_connect(priv->checkbutton_autoquality, "toggled", G_CALLBACK(autoquality_toggled), view); |
| 492 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), TRUE); |
| 493 | } |
| 494 | if (auto scale = gtk_scale_button_get_scale(GTK_SCALE_BUTTON(priv->scalebutton_quality))) { |
| 495 | g_signal_connect(scale, "button-press-event", G_CALLBACK(quality_button_pressed), view); |
| 496 | g_signal_connect(scale, "button-release-event", G_CALLBACK(quality_button_released), view); |
| 497 | } |
Stepan Salenikovich | 8809293 | 2017-05-15 18:19:00 -0400 | [diff] [blame] | 498 | |
| 499 | /* by this time we should have the call already set, but we check to make sure */ |
| 500 | if (priv->call) { |
| 501 | /* check if auto quality is enabled or not */ |
| 502 | if (const auto& codecModel = priv->call->account()->codecModel()) { |
| 503 | const auto& videoCodecs = codecModel->videoCodecs(); |
| 504 | if (videoCodecs->rowCount() > 0) { |
| 505 | /* we only need to check the first codec since by default it is ON for all, and the |
| 506 | * gnome client sets its ON or OFF for all codecs as well */ |
| 507 | const auto& idx = videoCodecs->index(0,0); |
| 508 | auto auto_quality_enabled = idx.data(static_cast<int>(CodecModel::Role::AUTO_QUALITY_ENABLED)).toString() == "true"; |
| 509 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_autoquality), auto_quality_enabled); |
| 510 | |
| 511 | // TODO: save the manual quality setting in the client and set the slider to that value here; |
| 512 | // the daemon resets the bitrate/quality between each call, and the default may be |
| 513 | // different for each codec, so there is no reason to check it here |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | static void |
| 520 | current_call_view_init(CurrentCallView *view) |
| 521 | { |
| 522 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 523 | |
| 524 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 525 | |
| 526 | // CSS styles |
| 527 | auto provider = gtk_css_provider_new(); |
| 528 | gtk_css_provider_load_from_data(provider, |
| 529 | ".smartinfo-block-style { color: #8ae234; background-color: rgba(1, 1, 1, 0.33); }", |
| 530 | -1, nullptr |
| 531 | ); |
| 532 | gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()), |
| 533 | GTK_STYLE_PROVIDER(provider), |
| 534 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
| 535 | |
| 536 | priv->video_widget = video_widget_new(); |
| 537 | gtk_container_add(GTK_CONTAINER(priv->frame_video), priv->video_widget); |
| 538 | gtk_widget_show_all(priv->frame_video); |
| 539 | |
| 540 | /* add the overlay controls only once the view has been allocated a size to prevent size |
| 541 | * allocation warnings in the log */ |
| 542 | priv->insert_controls_id = g_signal_connect(view, "size-allocate", G_CALLBACK(insert_controls), nullptr); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static void |
| 546 | current_call_view_class_init(CurrentCallViewClass *klass) |
| 547 | { |
| 548 | G_OBJECT_CLASS(klass)->dispose = current_call_view_dispose; |
| 549 | |
| 550 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 551 | "/cx/ring/RingGnome/currentcallview.ui"); |
| 552 | |
Stepan Salenikovich | e178e63 | 2015-11-06 13:31:19 -0500 | [diff] [blame] | 553 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_info); |
| 554 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, hbox_call_controls); |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 555 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, vbox_call_smartInfo); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 556 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, image_peer); |
Stepan Salenikovich | 07107e9 | 2016-05-06 10:35:17 -0400 | [diff] [blame] | 557 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_name); |
Nicolas Jager | 2e467c3 | 2017-01-18 08:52:23 -0500 | [diff] [blame] | 558 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_bestId); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 559 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_status); |
| 560 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_duration); |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 561 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_description); |
| 562 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_value); |
| 563 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, label_smartinfo_general_information); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 564 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, paned_call); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 565 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 566 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat); |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 567 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat); |
Stepan Salenikovich | 77baa52 | 2015-07-07 15:29:14 -0400 | [diff] [blame] | 568 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, button_hangup); |
Stepan Salenikovich | 7e28355 | 2015-12-21 16:17:52 -0500 | [diff] [blame] | 569 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, scalebutton_quality); |
Stepan Salenikovich | e1b5489 | 2015-12-13 22:18:44 -0500 | [diff] [blame] | 570 | |
| 571 | current_call_view_signals[VIDEO_DOUBLE_CLICKED] = g_signal_new ( |
| 572 | "video-double-clicked", |
| 573 | G_TYPE_FROM_CLASS(klass), |
| 574 | (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION), |
| 575 | 0, |
| 576 | nullptr, |
| 577 | nullptr, |
| 578 | g_cclosure_marshal_VOID__VOID, |
| 579 | G_TYPE_NONE, 0); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 580 | } |
| 581 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 582 | static void |
| 583 | update_state(CurrentCallView *view, Call *call) |
| 584 | { |
| 585 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 586 | |
Stepan Salenikovich | 7ec8fe8 | 2015-06-02 18:26:39 -0400 | [diff] [blame] | 587 | gchar *status = g_strdup_printf("%s", call->toHumanStateName().toUtf8().constData()); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 588 | |
Stepan Salenikovich | 7ec8fe8 | 2015-06-02 18:26:39 -0400 | [diff] [blame] | 589 | gtk_label_set_text(GTK_LABEL(priv->label_status), status); |
| 590 | |
| 591 | g_free(status); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static void |
| 595 | update_details(CurrentCallView *view, Call *call) |
| 596 | { |
| 597 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 598 | |
| 599 | /* update call duration */ |
| 600 | QByteArray ba_length = call->length().toLocal8Bit(); |
| 601 | gtk_label_set_text(GTK_LABEL(priv->label_duration), ba_length.constData()); |
| 602 | } |
| 603 | |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 604 | static void |
Stepan Salenikovich | 46bb157 | 2017-05-19 16:09:43 -0400 | [diff] [blame^] | 605 | update_name_and_photo(CurrentCallView *view) |
| 606 | { |
| 607 | auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 608 | |
| 609 | /* get call image */ |
| 610 | QVariant var_i = GlobalInstances::pixmapManipulator().callPhoto(priv->call, QSize(60, 60), false); |
| 611 | std::shared_ptr<GdkPixbuf> image = var_i.value<std::shared_ptr<GdkPixbuf>>(); |
| 612 | gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_peer), image.get()); |
| 613 | |
| 614 | /* get name */ |
| 615 | auto name = priv->call->formattedName(); |
| 616 | gtk_label_set_text(GTK_LABEL(priv->label_name), name.toUtf8().constData()); |
| 617 | |
| 618 | /* get contact best id, if different from name */ |
| 619 | auto contactId = priv->call->peerContactMethod()->bestId(); |
| 620 | if (name != contactId) { |
| 621 | auto cat_contactId = g_strdup_printf("(%s) %s" |
| 622 | ,priv->call->peerContactMethod()->category()->name().toUtf8().constData() |
| 623 | ,contactId.toUtf8().constData()); |
| 624 | gtk_label_set_text(GTK_LABEL(priv->label_bestId), cat_contactId); |
| 625 | g_free(cat_contactId); |
| 626 | gtk_widget_show(priv->label_bestId); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | static void |
| 631 | update_person(CurrentCallView *view, Person *new_person) |
| 632 | { |
| 633 | auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 634 | |
| 635 | update_name_and_photo(view); |
| 636 | |
| 637 | QObject::disconnect(priv->person_changed_connection); |
| 638 | if (new_person) { |
| 639 | priv->person_changed_connection = QObject::connect( |
| 640 | new_person, |
| 641 | &Person::changed, |
| 642 | [view]() { update_name_and_photo(view); } |
| 643 | ); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | static void |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 648 | update_smartInfo(CurrentCallView *view) |
| 649 | { |
| 650 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 651 | |
| 652 | if (!SmartInfoHub::instance().isConference()) { |
| 653 | gchar* general_information = g_strdup_printf("Call ID: %s", SmartInfoHub::instance().callID().toStdString().c_str()); |
| 654 | gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information); |
| 655 | g_free(general_information); |
| 656 | |
| 657 | gchar* description = g_strdup_printf("You\n" |
| 658 | "Framerate:\n" |
| 659 | "Video codec:\n" |
| 660 | "Audio codec:\n" |
| 661 | "Resolution:\n\n" |
| 662 | "Peer\n" |
| 663 | "Framerate:\n" |
| 664 | "Video codec:\n" |
| 665 | "Audio codec:\n" |
| 666 | "Resolution:"); |
| 667 | gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description); |
| 668 | g_free(description); |
| 669 | |
| 670 | 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", |
| 671 | (double)SmartInfoHub::instance().localFps(), |
| 672 | SmartInfoHub::instance().localVideoCodec().toStdString().c_str(), |
| 673 | SmartInfoHub::instance().localAudioCodec().toStdString().c_str(), |
| 674 | SmartInfoHub::instance().localWidth(), |
| 675 | SmartInfoHub::instance().localHeight(), |
| 676 | (double)SmartInfoHub::instance().remoteFps(), |
| 677 | SmartInfoHub::instance().remoteVideoCodec().toStdString().c_str(), |
| 678 | SmartInfoHub::instance().remoteAudioCodec().toStdString().c_str(), |
| 679 | SmartInfoHub::instance().remoteWidth(), |
| 680 | SmartInfoHub::instance().remoteHeight()); |
| 681 | gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value); |
| 682 | g_free(value); |
| 683 | } else { |
| 684 | gchar* general_information = g_strdup_printf("Conference ID: %s", SmartInfoHub::instance().callID().toStdString().c_str()); |
| 685 | gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_general_information), general_information); |
| 686 | g_free(general_information); |
| 687 | |
| 688 | gchar* description = g_strdup_printf("You\n" |
| 689 | "Framerate:\n" |
| 690 | "Video codec:\n" |
| 691 | "Audio codec:\n" |
| 692 | "Resolution:"); |
| 693 | gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_description),description); |
| 694 | g_free(description); |
| 695 | |
| 696 | gchar* value = g_strdup_printf("\n%f\n%s\n%s\n%dx%d", |
| 697 | (double)SmartInfoHub::instance().localFps(), |
| 698 | SmartInfoHub::instance().localVideoCodec().toStdString().c_str(), |
| 699 | SmartInfoHub::instance().localAudioCodec().toStdString().c_str(), |
| 700 | SmartInfoHub::instance().localWidth(), |
| 701 | SmartInfoHub::instance().localHeight()); |
| 702 | gtk_label_set_text(GTK_LABEL(priv->label_smartinfo_value),value); |
| 703 | g_free(value); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | |
Stepan Salenikovich | e1b5489 | 2015-12-13 22:18:44 -0500 | [diff] [blame] | 708 | static gboolean |
| 709 | on_button_press_in_video_event(GtkWidget *self, GdkEventButton *event, CurrentCallView *view) |
| 710 | { |
| 711 | g_return_val_if_fail(IS_VIDEO_WIDGET(self), FALSE); |
| 712 | g_return_val_if_fail(IS_CURRENT_CALL_VIEW(view), FALSE); |
| 713 | |
| 714 | /* on double click */ |
| 715 | if (event->type == GDK_2BUTTON_PRESS) { |
| 716 | g_debug("double click in video"); |
| 717 | g_signal_emit(G_OBJECT(view), current_call_view_signals[VIDEO_DOUBLE_CLICKED], 0); |
| 718 | } |
| 719 | |
| 720 | return GDK_EVENT_PROPAGATE; |
| 721 | } |
| 722 | |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 723 | static void |
| 724 | toggle_smartinfo(GSimpleAction* action, G_GNUC_UNUSED GVariant* state, GtkWidget* vbox_call_smartInfo) |
| 725 | { |
| 726 | if (g_variant_get_boolean(g_action_get_state(G_ACTION(action)))) { |
| 727 | gtk_widget_show(vbox_call_smartInfo); |
| 728 | } else { |
| 729 | gtk_widget_hide(vbox_call_smartInfo); |
| 730 | } |
| 731 | } |
| 732 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 733 | static void |
| 734 | set_call_info(CurrentCallView *view, Call *call) { |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 735 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(view); |
| 736 | |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 737 | priv->call = call; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 738 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 739 | |
| 740 | /* change some things depending on call state */ |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 741 | update_state(view, priv->call); |
| 742 | update_details(view, priv->call); |
Stepan Salenikovich | 46bb157 | 2017-05-19 16:09:43 -0400 | [diff] [blame^] | 743 | update_person(view, priv->call->peerContactMethod()->contact()); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 744 | |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 745 | priv->smartinfo_refresh_connection = QObject::connect( |
| 746 | &SmartInfoHub::instance(), |
| 747 | &SmartInfoHub::changed, |
| 748 | [view, priv]() { update_smartInfo(view); } |
| 749 | ); |
| 750 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 751 | priv->state_change_connection = QObject::connect( |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 752 | priv->call, |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 753 | &Call::stateChanged, |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 754 | [view, priv]() { update_state(view, priv->call); } |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 755 | ); |
| 756 | |
| 757 | priv->call_details_connection = QObject::connect( |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 758 | priv->call, |
Stepan Salenikovich | 6dbaf26 | 2017-05-19 15:42:24 -0400 | [diff] [blame] | 759 | &Call::changed, |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 760 | [view, priv]() { update_details(view, priv->call); } |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 761 | ); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 762 | |
Stepan Salenikovich | 46bb157 | 2017-05-19 16:09:43 -0400 | [diff] [blame^] | 763 | priv->cm_changed_connection = QObject::connect( |
| 764 | priv->call->peerContactMethod(), |
| 765 | &ContactMethod::changed, |
| 766 | [view]() { update_name_and_photo(view); } |
| 767 | ); |
| 768 | |
| 769 | priv->cm_person_changed_connection = QObject::connect( |
| 770 | priv->call->peerContactMethod(), |
| 771 | &ContactMethod::contactChanged, |
| 772 | [view] (Person* newPerson, Person*) { update_person(view, newPerson); } |
| 773 | ); |
| 774 | |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 775 | /* check if we already have a renderer */ |
Stepan Salenikovich | 0f69323 | 2015-04-22 10:45:08 -0400 | [diff] [blame] | 776 | video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget), |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 777 | priv->call->videoRenderer(), |
Stepan Salenikovich | 0f69323 | 2015-04-22 10:45:08 -0400 | [diff] [blame] | 778 | VIDEO_RENDERER_REMOTE); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 779 | |
Stepan Salenikovich | 8e5c9d0 | 2015-03-11 14:07:10 -0400 | [diff] [blame] | 780 | /* callback for remote renderer */ |
Stepan Salenikovich | c5f0815 | 2015-03-19 00:53:23 -0400 | [diff] [blame] | 781 | priv->remote_renderer_connection = QObject::connect( |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 782 | priv->call, |
Stepan Salenikovich | 9c1f668 | 2015-03-09 16:21:28 -0400 | [diff] [blame] | 783 | &Call::videoStarted, |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 784 | [priv](Video::Renderer *renderer) { |
Stepan Salenikovich | 0f69323 | 2015-04-22 10:45:08 -0400 | [diff] [blame] | 785 | video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget), |
| 786 | renderer, |
| 787 | VIDEO_RENDERER_REMOTE); |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 788 | } |
| 789 | ); |
Stepan Salenikovich | 4ac89f1 | 2015-03-10 16:48:47 -0400 | [diff] [blame] | 790 | |
Stepan Salenikovich | 8e5c9d0 | 2015-03-11 14:07:10 -0400 | [diff] [blame] | 791 | /* local renderer */ |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 792 | if (Video::PreviewManager::instance().isPreviewing()) |
Stepan Salenikovich | 0f69323 | 2015-04-22 10:45:08 -0400 | [diff] [blame] | 793 | video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 794 | Video::PreviewManager::instance().previewRenderer(), |
Stepan Salenikovich | 0f69323 | 2015-04-22 10:45:08 -0400 | [diff] [blame] | 795 | VIDEO_RENDERER_LOCAL); |
Stepan Salenikovich | 8e5c9d0 | 2015-03-11 14:07:10 -0400 | [diff] [blame] | 796 | |
| 797 | /* callback for local renderer */ |
Stepan Salenikovich | c5f0815 | 2015-03-19 00:53:23 -0400 | [diff] [blame] | 798 | priv->local_renderer_connection = QObject::connect( |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 799 | &Video::PreviewManager::instance(), |
Stepan Salenikovich | 8e5c9d0 | 2015-03-11 14:07:10 -0400 | [diff] [blame] | 800 | &Video::PreviewManager::previewStarted, |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 801 | [priv](Video::Renderer *renderer) { |
Stepan Salenikovich | 0f69323 | 2015-04-22 10:45:08 -0400 | [diff] [blame] | 802 | video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget), |
| 803 | renderer, |
| 804 | VIDEO_RENDERER_LOCAL); |
Stepan Salenikovich | 8e5c9d0 | 2015-03-11 14:07:10 -0400 | [diff] [blame] | 805 | } |
| 806 | ); |
Stepan Salenikovich | bfe9ac6 | 2015-03-11 12:49:20 -0400 | [diff] [blame] | 807 | |
Julien Grossholtz | a0d4f10 | 2015-10-22 14:24:17 -0400 | [diff] [blame] | 808 | /* handle video widget button click event */ |
| 809 | g_signal_connect(priv->video_widget, "button-press-event", G_CALLBACK(video_widget_on_button_press_in_screen_event), priv->call); |
| 810 | |
| 811 | /* handle video widget drag and drop*/ |
| 812 | g_signal_connect(priv->video_widget, "drag-data-received", G_CALLBACK(video_widget_on_drag_data_received), priv->call); |
| 813 | |
Stepan Salenikovich | bfe9ac6 | 2015-03-11 12:49:20 -0400 | [diff] [blame] | 814 | /* catch double click to make full screen */ |
| 815 | g_signal_connect(priv->video_widget, "button-press-event", |
| 816 | G_CALLBACK(on_button_press_in_video_event), |
| 817 | view); |
Stepan Salenikovich | a448f60 | 2015-05-29 13:33:06 -0400 | [diff] [blame] | 818 | |
Olivier Gregoire | 66e4df7 | 2016-06-17 18:39:05 -0400 | [diff] [blame] | 819 | /* handle smartinfo in right click menu */ |
| 820 | auto display_smartinfo = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), "display-smartinfo"); |
| 821 | priv->smartinfo_action = g_signal_connect(display_smartinfo, |
| 822 | "notify::state", |
| 823 | G_CALLBACK(toggle_smartinfo), |
| 824 | priv->vbox_call_smartInfo); |
| 825 | |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 826 | /* init chat view */ |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 827 | auto chat_view = chat_view_new_call(WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container), priv->call); |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 828 | gtk_container_add(GTK_CONTAINER(priv->frame_chat), chat_view); |
| 829 | |
| 830 | /* check if there were any chat notifications and open the chat view if so */ |
Stepan Salenikovich | 26cd160 | 2016-01-20 13:43:17 -0500 | [diff] [blame] | 831 | if (ring_notify_close_chat_notification(priv->call->peerContactMethod())) |
Stepan Salenikovich | d2cad06 | 2016-01-08 13:43:49 -0500 | [diff] [blame] | 832 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->togglebutton_chat), TRUE); |
| 833 | |
| 834 | /* show chat view on any new incoming messages */ |
| 835 | g_signal_connect_swapped(chat_view, "new-messages-displayed", G_CALLBACK(show_chat_view), view); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 836 | } |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 837 | |
| 838 | GtkWidget * |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 839 | current_call_view_new(Call *call, WebKitChatContainer *webkit_chat_container) |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 840 | { |
| 841 | auto self = g_object_new(CURRENT_CALL_VIEW_TYPE, NULL); |
aviau | 039001d | 2016-09-29 16:39:05 -0400 | [diff] [blame] | 842 | CurrentCallViewPrivate *priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 843 | priv->webkit_chat_container = GTK_WIDGET(webkit_chat_container); |
Stepan Salenikovich | 09e0b78 | 2016-09-07 16:28:50 -0400 | [diff] [blame] | 844 | set_call_info(CURRENT_CALL_VIEW(self), call); |
| 845 | |
| 846 | return GTK_WIDGET(self); |
| 847 | } |
| 848 | |
| 849 | Call* |
| 850 | current_call_view_get_call(CurrentCallView *self) |
| 851 | { |
| 852 | g_return_val_if_fail(IS_CURRENT_CALL_VIEW(self), nullptr); |
| 853 | auto priv = CURRENT_CALL_VIEW_GET_PRIVATE(self); |
| 854 | |
| 855 | return priv->call; |
| 856 | } |