[gnome-control-center] sharing/remote-desktop: Show toasts when copying



commit 6affceebeeb49142a0981935980f05239a40f42d
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Mar 3 19:41:35 2022 +0100

    sharing/remote-desktop: Show toasts when copying

 panels/sharing/cc-sharing-panel.c  |  63 +++++++++---
 panels/sharing/cc-sharing-panel.ui | 206 +++++++++++++++++++------------------
 2 files changed, 156 insertions(+), 113 deletions(-)
---
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
index 76e9e7b6e..603e4cc18 100644
--- a/panels/sharing/cc-sharing-panel.c
+++ b/panels/sharing/cc-sharing-panel.c
@@ -86,6 +86,8 @@ struct _CcSharingPanel
   GtkWidget *remote_login_switch;
 
   GtkWidget *remote_control_switch;
+  GtkWidget *remote_control_checkbutton;
+  GtkWidget *remote_desktop_toast_overlay;
   GtkWidget *remote_desktop_password_entry;
   GtkWidget *remote_desktop_password_copy;
   GtkWidget *remote_desktop_username_entry;
@@ -284,6 +286,7 @@ cc_sharing_panel_class_init (CcSharingPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_row);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_login_switch);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_dialog);
+  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_toast_overlay);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_switch);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_switch);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_username_entry);
@@ -1277,19 +1280,55 @@ get_hostname (void)
 }
 
 static void
-on_copy_clicked_label (GtkButton *button,
-                       GtkLabel  *label)
+add_toast (CcSharingPanel *self,
+           const char     *message)
 {
+  adw_toast_overlay_add_toast (ADW_TOAST_OVERLAY (self->remote_desktop_toast_overlay),
+                               adw_toast_new (message));
+}
+
+static void
+on_device_name_copy_clicked (GtkButton      *button,
+                             CcSharingPanel *self)
+{
+  GtkLabel *label = GTK_LABEL (self->remote_desktop_device_name_label);
+
+  gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)),
+                          gtk_label_get_text (label));
+  add_toast (self, _("Device name copied"));
+}
+
+static void
+on_device_address_copy_clicked (GtkButton      *button,
+                                CcSharingPanel *self)
+{
+  GtkLabel *label = GTK_LABEL (self->remote_desktop_address_label);
+
   gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)),
                           gtk_label_get_text (label));
+  add_toast (self, _("Device address copied"));
+}
+
+static void
+on_username_copy_clicked (GtkButton      *button,
+                          CcSharingPanel *self)
+{
+  GtkEditable *editable = GTK_EDITABLE (self->remote_desktop_username_entry);
+
+  gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)),
+                          gtk_editable_get_text (editable));
+  add_toast (self, _("Username copied"));
 }
 
 static void
-on_copy_clicked_editable (GtkButton   *button,
-                          GtkEditable *editable)
+on_password_copy_clicked (GtkButton      *button,
+                          CcSharingPanel *self)
 {
+  GtkEditable *editable = GTK_EDITABLE (self->remote_desktop_password_entry);
+
   gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)),
                           gtk_editable_get_text (editable));
+  add_toast (self, _("Password copied"));
 }
 
 static pwquality_settings_t *
@@ -1400,17 +1439,17 @@ cc_sharing_panel_setup_remote_desktop_dialog (CcSharingPanel *self)
                            pw_generate ());
 
   g_signal_connect (self->remote_desktop_device_name_copy,
-                    "clicked", G_CALLBACK (on_copy_clicked_label),
-                    self->remote_desktop_device_name_label);
+                    "clicked", G_CALLBACK (on_device_name_copy_clicked),
+                    self);
   g_signal_connect (self->remote_desktop_address_copy,
-                    "clicked", G_CALLBACK (on_copy_clicked_label),
-                    self->remote_desktop_address_label);
+                    "clicked", G_CALLBACK (on_device_address_copy_clicked),
+                    self);
   g_signal_connect (self->remote_desktop_username_copy,
-                    "clicked", G_CALLBACK (on_copy_clicked_editable),
-                    self->remote_desktop_username_entry);
+                    "clicked", G_CALLBACK (on_username_copy_clicked),
+                    self);
   g_signal_connect (self->remote_desktop_password_copy,
-                    "clicked", G_CALLBACK (on_copy_clicked_editable),
-                    self->remote_desktop_password_entry);
+                    "clicked", G_CALLBACK (on_password_copy_clicked),
+                    self);
 
   g_signal_connect (self->remote_desktop_switch, "notify::state",
                     G_CALLBACK (on_remote_desktop_state_changed), self);
diff --git a/panels/sharing/cc-sharing-panel.ui b/panels/sharing/cc-sharing-panel.ui
index 8ae9ab5c0..20ca0050b 100644
--- a/panels/sharing/cc-sharing-panel.ui
+++ b/panels/sharing/cc-sharing-panel.ui
@@ -257,56 +257,112 @@
     </child>
 
     <child>
-      <object class="AdwPreferencesPage">
+      <object class="AdwToastOverlay" id="remote_desktop_toast_overlay">
         <child>
-          <object class="AdwPreferencesGroup">
-            <property name="description" translatable="yes">Remote desktop allows viewing and controlling 
your desktop from another computer.</property>
-
+          <object class="AdwPreferencesPage">
             <child>
-              <object class="AdwActionRow">
-                <property name="title" translatable="yes">Remote Desktop</property>
-                <property name="subtitle" translatable="yes">Enable or disable remote desktop connections to 
this computer.</property>
-                <child type="suffix">
-                  <object class="GtkSwitch" id="remote_desktop_switch">
-                    <property name="state">False</property>
-                    <property name="valign">center</property>
+              <object class="AdwPreferencesGroup">
+                <property name="description" translatable="yes">Remote desktop allows viewing and 
controlling your desktop from another computer.</property>
+
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="yes">Remote Desktop</property>
+                    <property name="subtitle" translatable="yes">Enable or disable remote desktop 
connections to this computer.</property>
+                    <child type="suffix">
+                      <object class="GtkSwitch" id="remote_desktop_switch">
+                        <property name="state">False</property>
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="yes">Remote Control</property>
+                    <property name="subtitle" translatable="yes">Allows remote connections to control the 
screen.</property>
+                    <child type="suffix">
+                      <object class="GtkSwitch" id="remote_control_switch">
+                        <property name="valign">center</property>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
             </child>
 
             <child>
-              <object class="AdwActionRow">
-                <property name="title" translatable="yes">Remote Control</property>
-                <property name="subtitle" translatable="yes">Allows remote connections to control the 
screen.</property>
-                <child type="suffix">
-                  <object class="GtkSwitch" id="remote_control_switch">
-                    <property name="valign">center</property>
+              <object class="AdwPreferencesGroup">
+                <property name="title" translatable="yes">How to Connect</property>
+                <property name="description" translatable="yes">Connect to this computer using the device 
name or remote desktop address.</property>
+
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="yes">Device Name</property>
+                    <child type="suffix">
+                      <object class="GtkBox">
+                        <property name="spacing">10</property>
+                        <child>
+                          <object class="GtkLabel" id="remote_desktop_device_name_label">
+                            <property name="selectable">True</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="remote_desktop_device_name_copy">
+                            <property name="valign">center</property>
+                            <property name="icon-name">edit-copy-symbolic</property>
+                            <style>
+                              <class name="flat"/>
+                            </style>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="yes">Remote Desktop Address</property>
+                    <child type="suffix">
+                      <object class="GtkBox">
+                        <property name="spacing">10</property>
+                        <child>
+                          <object class="GtkLabel" id="remote_desktop_address_label">
+                            <property name="selectable">True</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="remote_desktop_address_copy">
+                            <property name="valign">center</property>
+                            <property name="icon-name">edit-copy-symbolic</property>
+                            <style>
+                              <class name="flat"/>
+                            </style>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
             </child>
-          </object>
-        </child>
-
-        <child>
-          <object class="AdwPreferencesGroup">
-            <property name="title" translatable="yes">How to Connect</property>
-            <property name="description" translatable="yes">Connect to this computer using the device name 
or remote desktop address.</property>
 
             <child>
-              <object class="AdwActionRow">
-                <property name="title" translatable="yes">Device Name</property>
-                <child type="suffix">
-                  <object class="GtkBox">
-                    <property name="spacing">10</property>
-                    <child>
-                      <object class="GtkLabel" id="remote_desktop_device_name_label">
-                        <property name="selectable">True</property>
+              <object class="AdwPreferencesGroup">
+                <property name="title" translatable="yes">Authentication</property>
+                <property name="description" translatable="yes">The user name and password are required to 
connect to this computer.</property>
+
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="yes">User Name</property>
+                    <child type="suffix">
+                      <object class="GtkEntry" id="remote_desktop_username_entry">
+                        <property name="hexpand">True</property>
+                        <property name="valign">center</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkButton" id="remote_desktop_device_name_copy">
+                      <object class="GtkButton" id="remote_desktop_username_copy">
                         <property name="valign">center</property>
                         <property name="icon-name">edit-copy-symbolic</property>
                         <style>
@@ -316,21 +372,19 @@
                     </child>
                   </object>
                 </child>
-              </object>
-            </child>
-            <child>
-              <object class="AdwActionRow">
-                <property name="title" translatable="yes">Remote Desktop Address</property>
-                <child type="suffix">
-                  <object class="GtkBox">
-                    <property name="spacing">10</property>
-                    <child>
-                      <object class="GtkLabel" id="remote_desktop_address_label">
-                        <property name="selectable">True</property>
+
+                <child>
+                  <object class="AdwActionRow">
+                    <property name="title" translatable="yes">Password</property>
+                    <child type="suffix">
+                      <object class="GtkPasswordEntry" id="remote_desktop_password_entry">
+                        <property name="hexpand">True</property>
+                        <property name="show-peek-icon">True</property>
+                        <property name="valign">center</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkButton" id="remote_desktop_address_copy">
+                      <object class="GtkButton" id="remote_desktop_password_copy">
                         <property name="valign">center</property>
                         <property name="icon-name">edit-copy-symbolic</property>
                         <style>
@@ -340,68 +394,18 @@
                     </child>
                   </object>
                 </child>
-              </object>
-            </child>
-          </object>
-        </child>
-
-        <child>
-          <object class="AdwPreferencesGroup">
-            <property name="title" translatable="yes">Authentication</property>
-            <property name="description" translatable="yes">The user name and password are required to 
connect to this computer.</property>
-
-            <child>
-              <object class="AdwActionRow">
-                <property name="title" translatable="yes">User Name</property>
-                <child type="suffix">
-                  <object class="GtkEntry" id="remote_desktop_username_entry">
-                    <property name="hexpand">True</property>
-                    <property name="valign">center</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkButton" id="remote_desktop_username_copy">
-                    <property name="valign">center</property>
-                    <property name="icon-name">edit-copy-symbolic</property>
-                    <style>
-                      <class name="flat"/>
-                    </style>
-                  </object>
-                </child>
-              </object>
-            </child>
 
-            <child>
-              <object class="AdwActionRow">
-                <property name="title" translatable="yes">Password</property>
-                <child type="suffix">
-                  <object class="GtkPasswordEntry" id="remote_desktop_password_entry">
-                    <property name="hexpand">True</property>
-                    <property name="show-peek-icon">True</property>
-                    <property name="valign">center</property>
-                  </object>
-                </child>
                 <child>
-                  <object class="GtkButton" id="remote_desktop_password_copy">
-                    <property name="valign">center</property>
-                    <property name="icon-name">edit-copy-symbolic</property>
-                    <style>
-                      <class name="flat"/>
-                    </style>
+                  <object class="GtkButton" id="remote_desktop_verify_encryption">
+                    <property name="sensitive">False</property>
+                    <property name="halign">end</property>
+                    <property name="margin-top">12</property>
+                    <property name="label" translatable="yes">Verify Encryption</property>
+                    <signal name="clicked" handler="remote_desktop_show_encryption_fingerprint" 
swapped="yes"/>
                   </object>
                 </child>
               </object>
             </child>
-
-            <child>
-              <object class="GtkButton" id="remote_desktop_verify_encryption">
-                <property name="sensitive">False</property>
-                <property name="halign">end</property>
-                <property name="margin-top">12</property>
-                <property name="label" translatable="yes">Verify Encryption</property>
-                <signal name="clicked" handler="remote_desktop_show_encryption_fingerprint" swapped="yes"/>
-              </object>
-            </child>
           </object>
         </child>
       </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]