[gnome-control-center/wip/feborges/new-remote-desktop-dialog: 12/14] sharing/remote-desktop: Add copy buttons




commit 0aac6b07caad2bf12f8510a6fa657ce05044c58b
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Feb 23 18:52:33 2022 +0100

    sharing/remote-desktop: Add copy buttons

 panels/sharing/cc-sharing-panel.c  | 39 +++++++++++++++++++++++++++++
 panels/sharing/cc-sharing-panel.ui | 50 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 87 insertions(+), 2 deletions(-)
---
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
index 692a4ba38..8ec246722 100644
--- a/panels/sharing/cc-sharing-panel.c
+++ b/panels/sharing/cc-sharing-panel.c
@@ -82,10 +82,14 @@ struct _CcSharingPanel
 
   GtkWidget *remote_control_checkbutton;
   GtkWidget *remote_desktop_password_entry;
+  GtkWidget *remote_desktop_password_copy;
   GtkWidget *remote_desktop_username_entry;
+  GtkWidget *remote_desktop_username_copy;
   GtkWidget *remote_desktop_dialog;
   GtkWidget *remote_desktop_device_name_label;
+  GtkWidget *remote_desktop_device_name_copy;
   GtkWidget *remote_desktop_address_label;
+  GtkWidget *remote_desktop_address_copy;
   GtkWidget *remote_desktop_row;
   GtkWidget *remote_desktop_switch;
   GtkWidget *remote_desktop_verify_encryption;
@@ -278,9 +282,13 @@ cc_sharing_panel_class_init (CcSharingPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_switch);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_control_checkbutton);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_username_entry);
+  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_username_copy);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_password_entry);
+  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_password_copy);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_device_name_label);
+  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_device_name_copy);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_address_label);
+  gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_address_copy);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_verify_encryption);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_fingerprint_dialog);
   gtk_widget_class_bind_template_child (widget_class, CcSharingPanel, remote_desktop_row);
@@ -1284,6 +1292,24 @@ get_hostname (void)
   return g_variant_dup_string (inner, NULL);
 }
 
+static void
+on_copy_clicked_label (GtkButton *button,
+                       GtkLabel  *label)
+{
+  gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)),
+                          gtk_label_get_text (label));
+}
+
+static void
+on_copy_clicked_entry (GtkButton *button,
+                       GtkEntry  *entry)
+{
+  GtkEntryBuffer *buffer = gtk_entry_get_buffer (entry);
+
+  gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (button)),
+                          gtk_entry_buffer_get_text (buffer));
+}
+
 static void
 cc_sharing_panel_setup_remote_desktop_dialog (CcSharingPanel *self)
 {
@@ -1329,6 +1355,19 @@ cc_sharing_panel_setup_remote_desktop_dialog (CcSharingPanel *self)
                             G_CALLBACK (remote_desktop_credentials_changed),
                             self);
 
+  g_signal_connect (self->remote_desktop_device_name_copy,
+                    "clicked", G_CALLBACK (on_copy_clicked_label),
+                    self->remote_desktop_device_name_label);
+  g_signal_connect (self->remote_desktop_address_copy,
+                    "clicked", G_CALLBACK (on_copy_clicked_label),
+                    self->remote_desktop_address_label);
+  g_signal_connect (self->remote_desktop_username_copy,
+                    "clicked", G_CALLBACK (on_copy_clicked_entry),
+                    self->remote_desktop_username_entry);
+  g_signal_connect (self->remote_desktop_password_copy,
+                    "clicked", G_CALLBACK (on_copy_clicked_entry),
+                    self->remote_desktop_password_entry);
+
   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 093cf5635..2a32cfce1 100644
--- a/panels/sharing/cc-sharing-panel.ui
+++ b/panels/sharing/cc-sharing-panel.ui
@@ -298,7 +298,21 @@
               <object class="AdwActionRow">
                 <property name="title" translatable="yes">Device Name</property>
                 <child type="suffix">
-                  <object class="GtkLabel" id="remote_desktop_device_name_label"/>
+                  <object class="GtkBox">
+                    <property name="spacing">10</property>
+                    <child>
+                      <object class="GtkLabel" id="remote_desktop_device_name_label"/>
+                    </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>
@@ -306,7 +320,21 @@
               <object class="AdwActionRow">
                 <property name="title" translatable="yes">Remote Desktop Address</property>
                 <child type="suffix">
-                  <object class="GtkLabel" id="remote_desktop_address_label"/>
+                  <object class="GtkBox">
+                    <property name="spacing">10</property>
+                    <child>
+                      <object class="GtkLabel" id="remote_desktop_address_label"/>
+                    </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>
@@ -327,6 +355,15 @@
                     <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>
 
@@ -340,6 +377,15 @@
                     <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>
+                </child>
               </object>
             </child>
 


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