From 50fc0a5be6e42b505daad973e7a08ece9b4283bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 21 Jul 2020 11:34:01 -0400
Subject: [PATCH] conferences: add ability to change layouts

The UI/UX is not perfect as we can't click on the renderer for now,
but this will change in the future

Change-Id: I0e92abbdd3e0f28ae161eea5e663cc21da58a53a
Gitlab: #1187
---
 pixmaps/pixmaps.gresource.xml |  1 +
 pixmaps/view.svg              |  1 +
 src/currentcallview.cpp       | 37 +++++++++++++++++++++++++++++++++--
 src/mainwindow.cpp            |  3 +++
 ui/currentcallview.ui         | 34 ++++++++++++++++++++++++++++++++
 5 files changed, 74 insertions(+), 2 deletions(-)
 create mode 100644 pixmaps/view.svg

diff --git a/pixmaps/pixmaps.gresource.xml b/pixmaps/pixmaps.gresource.xml
index 41f3823d..c96fdbbb 100644
--- a/pixmaps/pixmaps.gresource.xml
+++ b/pixmaps/pixmaps.gresource.xml
@@ -60,5 +60,6 @@
     <file alias="retry">retry.svg</file>
     <file alias="retry-white">retry-white.svg</file>
     <file alias="plugin_white">extension_white_24dp.svg</file>
+    <file alias="view">view.svg</file>
   </gresource>
 </gresources>
diff --git a/pixmaps/view.svg b/pixmaps/view.svg
new file mode 100644
index 00000000..37eb3ae4
--- /dev/null
+++ b/pixmaps/view.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white" width="24px" height="24px"><path d="M0 0h24v24H0z" fill="none"/><path d="M3 19h6v-7H3v7zm7 0h12v-7H10v7zM3 5v6h19V5H3z"/></svg>
\ No newline at end of file
diff --git a/src/currentcallview.cpp b/src/currentcallview.cpp
index b7e95d29..2e170163 100644
--- a/src/currentcallview.cpp
+++ b/src/currentcallview.cpp
@@ -92,6 +92,7 @@ struct CurrentCallViewPrivate
     GtkWidget *video_widget;
     GtkWidget *frame_chat;
     GtkWidget *togglebutton_chat;
+    GtkWidget *togglebutton_view;
     GtkWidget *togglebutton_muteaudio;
     GtkWidget *togglebutton_mutevideo;
     GtkWidget *togglebutton_add_participant;
@@ -341,6 +342,31 @@ on_togglebutton_chat_toggled(GtkToggleButton* widget, CurrentCallView* view)
     }
 }
 
+static void
+on_togglebutton_view_toggled(GtkToggleButton* widget, CurrentCallView* view)
+{
+    g_return_if_fail(IS_CURRENT_CALL_VIEW(view));
+    auto* priv = CURRENT_CALL_VIEW_GET_PRIVATE(view);
+
+    auto confId = priv->cpp->conversation->confId;
+    if (!confId.isEmpty()) {
+        auto call = (*priv->cpp->accountInfo)->callModel->getCall(confId);
+        switch (call.layout) {
+            case lrc::api::call::Layout::GRID:
+                (*priv->cpp->accountInfo)->callModel->setConferenceLayout(confId, lrc::api::call::Layout::ONE_WITH_SMALL);
+                break;
+            case lrc::api::call::Layout::ONE_WITH_SMALL:
+                (*priv->cpp->accountInfo)->callModel->setConferenceLayout(confId, lrc::api::call::Layout::ONE);
+                break;
+            case lrc::api::call::Layout::ONE:
+                (*priv->cpp->accountInfo)->callModel->setConferenceLayout(confId, lrc::api::call::Layout::GRID);
+                break;
+        }
+    }
+        (*priv->cpp->accountInfo)->callModel->setActiveParticipant(confId, "");
+
+}
+
 static gboolean
 on_timer_fade_timeout(CurrentCallView* view)
 {
@@ -1576,6 +1602,7 @@ CppImpl::insertControls()
 
     /* toggle whether or not the chat is displayed */
     g_signal_connect(widgets->togglebutton_chat, "toggled", G_CALLBACK(on_togglebutton_chat_toggled), self);
+    g_signal_connect(widgets->togglebutton_view, "toggled", G_CALLBACK(on_togglebutton_view_toggled), self);
 
     /* bind the chat orientation to the gsetting */
     widgets->settings = g_settings_new_full(get_settings_schema(), nullptr, nullptr);
@@ -1663,7 +1690,7 @@ CppImpl::updateState()
 
         auto audioButton = GTK_TOGGLE_BUTTON(widgets->togglebutton_muteaudio);
         gtk_widget_set_sensitive(GTK_WIDGET(widgets->togglebutton_muteaudio),
-                                 (call.type != lrc::api::call::Type::CONFERENCE));
+                                 (conversation->confId.isEmpty()));
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->togglebutton_muteaudio), call.audioMuted);
         auto imageMuteAudio = gtk_image_new_from_resource ("/net/jami/JamiGnome/mute_audio");
         if (call.audioMuted)
@@ -1678,7 +1705,7 @@ CppImpl::updateState()
                 imageMuteVideo = gtk_image_new_from_resource ("/net/jami/JamiGnome/unmute_video");
             gtk_button_set_image(GTK_BUTTON(videoButton), imageMuteVideo);
             gtk_widget_set_sensitive(GTK_WIDGET(widgets->togglebutton_mutevideo),
-                                 (call.type != lrc::api::call::Type::CONFERENCE));
+                                 (conversation->confId.isEmpty()));
 
             gtk_widget_show(widgets->togglebutton_mutevideo);
             gtk_widget_show(widgets->scalebutton_quality);
@@ -1693,6 +1720,11 @@ CppImpl::updateState()
     } catch (std::out_of_range& e) {
         g_warning("Can't update state for callId=%s", qUtf8Printable(callId));
     }
+
+    if (conversation->confId.isEmpty())
+        gtk_widget_hide(widgets->togglebutton_view);
+    else
+        gtk_widget_show(widgets->togglebutton_view);
 }
 
 void
@@ -1925,6 +1957,7 @@ current_call_view_class_init(CurrentCallViewClass *klass)
     gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_video);
     gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, frame_chat);
     gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_chat);
+    gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_view);
     gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_add_participant);
     gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_activate_plugin);
     gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), CurrentCallView, togglebutton_transfer);
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 8197b9a7..1a21aa2f 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2440,6 +2440,9 @@ CppImpl::slotShowCallView(const std::string& id, lrc::api::conversation::Info or
             return;
     }
 
+    if (!origin.confId.isEmpty())
+        accountInfo_->callModel->setActiveParticipant(origin.confId, origin.callId);
+
     changeView(CURRENT_CALL_VIEW_TYPE, origin);
 }
 
diff --git a/ui/currentcallview.ui b/ui/currentcallview.ui
index 9743e4d4..a2e50ff3 100644
--- a/ui/currentcallview.ui
+++ b/ui/currentcallview.ui
@@ -442,6 +442,31 @@
         <property name="fill">True</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkToggleButton" id="togglebutton_view">
+        <style>
+          <class name="call-button"/>
+        </style>
+        <property name="visible">True</property>
+        <property name="sensitive">True</property>
+        <property name="can_focus">True</property>
+        <property name="width-request">48</property>
+        <property name="height-request">48</property>
+        <property name="has_tooltip">True</property>
+        <property name="relief">normal</property>
+        <property name="tooltip-text" translatable="yes">Toggle view</property>
+        <property name="image">image_view</property>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="togglebutton_view-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes">Change video layout</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+      </packing>
+    </child>
     <child>
       <object class="GtkToggleButton" id="togglebutton_chat">
         <style>
@@ -477,6 +502,15 @@
       </object>
     </child>
   </object>
+  <object class="GtkImage" id="image_view">
+    <property name="visible">True</property>
+    <property name="resource">/net/jami/JamiGnome/view</property>
+    <child internal-child="accessible">
+      <object class="AtkObject" id="image_view-atkobject">
+        <property name="AtkObject::accessible-description" translatable="yes">View</property>
+      </object>
+    </child>
+  </object>
   <object class="GtkImage" id="image_mute_audio">
     <property name="visible">True</property>
     <property name="resource">/net/jami/JamiGnome/mute_audio</property>
-- 
GitLab