[gnome-control-center/info-rename-sensitivity: 12/12] info-overview: Set "Rename" button insensitive if no changes are made



commit 3bae641f760743149179cfe18a66ea7ad95e4fe1
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Feb 20 15:24:52 2020 +0100

    info-overview: Set "Rename" button insensitive if no changes are made
    
    Fixes #879

 panels/info-overview/cc-info-overview-panel.c  | 14 ++++++++++++++
 panels/info-overview/cc-info-overview-panel.ui |  1 +
 2 files changed, 15 insertions(+)
---
diff --git a/panels/info-overview/cc-info-overview-panel.c b/panels/info-overview/cc-info-overview-panel.c
index fea919745..2f07509fc 100644
--- a/panels/info-overview/cc-info-overview-panel.c
+++ b/panels/info-overview/cc-info-overview-panel.c
@@ -58,6 +58,7 @@ struct _CcInfoOverviewPanel
   CcPanel          parent_instance;
 
   GtkEntry        *device_name_entry;
+  GtkWidget       *rename_button;
   CcListRow       *disk_row;
   CcListRow       *gnome_version_row;
   CcListRow       *graphics_row;
@@ -743,6 +744,17 @@ open_software_update (CcInfoOverviewPanel *self)
       g_warning ("Failed to spawn %s: %s", argv[0], error->message);
 }
 
+static void
+on_device_name_entry_changed (CcInfoOverviewPanel *self)
+{
+  const gchar *current_hostname, *new_hostname;
+
+  current_hostname = gtk_entry_get_text (GTK_ENTRY (self->hostname_entry));
+  new_hostname = gtk_entry_get_text (GTK_ENTRY (self->device_name_entry));
+  gtk_widget_set_sensitive (self->rename_button,
+                            !g_strcmp0 (current_hostname, new_hostname) == 0);
+}
+
 static void
 open_hostname_edit_dialog (CcInfoOverviewPanel *self)
 {
@@ -807,11 +819,13 @@ cc_info_overview_panel_class_init (CcInfoOverviewPanelClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, os_name_row);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, os_type_row);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, processor_row);
+  gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, rename_button);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, software_updates_row);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, virtualization_row);
   gtk_widget_class_bind_template_child (widget_class, CcInfoOverviewPanel, windowing_system_row);
 
   gtk_widget_class_bind_template_callback (widget_class, cc_info_panel_row_activated_cb);
+  gtk_widget_class_bind_template_callback (widget_class, on_device_name_entry_changed);
 
   g_type_ensure (CC_TYPE_LIST_ROW);
   g_type_ensure (CC_TYPE_HOSTNAME_ENTRY);
diff --git a/panels/info-overview/cc-info-overview-panel.ui b/panels/info-overview/cc-info-overview-panel.ui
index bd43be8c9..de377bb69 100644
--- a/panels/info-overview/cc-info-overview-panel.ui
+++ b/panels/info-overview/cc-info-overview-panel.ui
@@ -212,6 +212,7 @@
         <child>
           <object class="GtkEntry" id="device_name_entry">
             <property name="visible">True</property>
+            <signal name="changed" handler="on_device_name_entry_changed" swapped="yes"/>
           </object>
         </child>
       </object>


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