[gnome-control-center/introduce-cc-permission-infobar: 2/3] common: Introduce "CcPermissionInfobar" widget



commit 85dd9d94fe7860bac10ec18a6e2ddbec6e6794b2
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Dec 19 15:45:23 2019 +0100

    common: Introduce "CcPermissionInfobar" widget
    
    The "CcPermissionInfobar" widget is a more descriptive way to
    communicate that some Settings panel needs authentication in order
    to perform certain actions.
    
    This widget doesn't handle the permissions (as in GPermission)
    itself. It needs to be binded to an existing instance of GPermission,
    and it will react to the permission's state (show when the current
    user is not authorized, and hide when the user is authorized).
    
    This is part of a big set of changes that aim to set a consistent
    authentication method accross Settings panels.
    
    See #685, #556, and #771

 panels/common/cc-permission-infobar.c  | 84 ++++++++++++++++++++++++++++++++++
 panels/common/cc-permission-infobar.h  | 34 ++++++++++++++
 panels/common/cc-permission-infobar.ui | 64 ++++++++++++++++++++++++++
 panels/common/common.gresource.xml     |  1 +
 panels/common/meson.build              |  2 +
 5 files changed, 185 insertions(+)
---
diff --git a/panels/common/cc-permission-infobar.c b/panels/common/cc-permission-infobar.c
new file mode 100644
index 000000000..31329ad81
--- /dev/null
+++ b/panels/common/cc-permission-infobar.c
@@ -0,0 +1,84 @@
+/* cc-permission-infobar.c
+ *
+ * Copyright (C) 2020 Red Hat, Inc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s):
+ *   Felipe Borges <felipeborges gnome org>
+ *
+ */
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "cc-permission-infobar"
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "cc-permission-infobar.h"
+
+struct _CcPermissionInfobar
+{
+  GtkRevealer    parent_instance;
+
+  GtkLockButton *lock_button;
+};
+
+G_DEFINE_TYPE (CcPermissionInfobar, cc_permission_infobar, GTK_TYPE_REVEALER)
+
+static void
+on_permission_changed (CcPermissionInfobar *self)
+{
+  GPermission *permission;
+  gboolean is_authorized;
+
+  permission = gtk_lock_button_get_permission (self->lock_button);
+  is_authorized = g_permission_get_allowed (permission);
+
+  gtk_revealer_set_reveal_child (GTK_REVEALER (self), !is_authorized);
+}
+
+static void
+cc_permission_infobar_class_init (CcPermissionInfobarClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               "/org/gnome/control-center/"
+                                               "common/cc-permission-infobar.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, CcPermissionInfobar, lock_button);
+}
+
+static void
+cc_permission_infobar_init (CcPermissionInfobar *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+void
+cc_permission_infobar_set_permission (CcPermissionInfobar *self,
+                                      GPermission         *permission)
+{
+  g_return_if_fail (CC_IS_PERMISSION_INFOBAR (self));
+
+  gtk_lock_button_set_permission (self->lock_button, permission);
+
+  g_signal_connect_object (permission, "notify",
+                           G_CALLBACK (on_permission_changed),
+                           self,
+                           G_CONNECT_SWAPPED);
+  on_permission_changed (self);
+}
diff --git a/panels/common/cc-permission-infobar.h b/panels/common/cc-permission-infobar.h
new file mode 100644
index 000000000..4595a8b47
--- /dev/null
+++ b/panels/common/cc-permission-infobar.h
@@ -0,0 +1,34 @@
+/* cc-permission-infobar.h
+ *
+ * Copyright (C) 2020 Red Hat, Inc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s):
+ *   Felipe Borges <felipeborges gnome org>
+ *
+ */
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_PERMISSION_INFOBAR (cc_permission_infobar_get_type())
+G_DECLARE_FINAL_TYPE (CcPermissionInfobar, cc_permission_infobar, CC, PERMISSION_INFOBAR, GtkRevealer)
+
+void            cc_permission_infobar_set_permission (CcPermissionInfobar *self,
+                                                      GPermission         *permission);
+
+G_END_DECLS
diff --git a/panels/common/cc-permission-infobar.ui b/panels/common/cc-permission-infobar.ui
new file mode 100644
index 000000000..f4fe7da1a
--- /dev/null
+++ b/panels/common/cc-permission-infobar.ui
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="CcPermissionInfobar" parent="GtkRevealer">
+    <property name="reveal-child">True</property>
+    <property name="valign">start</property>
+    <child>
+      <object class="GtkInfoBar">
+        <property name="visible">True</property>
+        <property name="can-focus">False</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can-focus">False</property>
+            <property name="layout-style">end</property>
+            <child>
+              <object class="GtkLockButton" id="lock_button">
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">True</property>
+                <property name="label" translatable="yes">Unlockā€¦</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child internal-child="content_area">
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="border-width">10</property>
+            <property name="spacing">10</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="icon-name">system-lock-screen-symbolic</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="halign">start</property>
+                    <property name="label" translatable="yes">Unlock to Change Settings</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="visible">True</property>
+                    <property name="halign">start</property>
+                    <property name="label" translatable="yes">Some settings must be unlocked before they can 
be changed.</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/panels/common/common.gresource.xml b/panels/common/common.gresource.xml
index e02a835f0..fb421b48f 100644
--- a/panels/common/common.gresource.xml
+++ b/panels/common/common.gresource.xml
@@ -3,5 +3,6 @@
   <gresource prefix="/org/gnome/control-center/common">
     <file preprocess="xml-stripblanks">cc-language-chooser.ui</file>
     <file preprocess="xml-stripblanks">cc-list-row.ui</file>
+    <file preprocess="xml-stripblanks">cc-permission-infobar.ui</file>
   </gresource>
 </gresources>
diff --git a/panels/common/meson.build b/panels/common/meson.build
index 2d5121297..32f18dfac 100644
--- a/panels/common/meson.build
+++ b/panels/common/meson.build
@@ -46,12 +46,14 @@ sources = common_sources + files(
   'cc-common-language.c',
   'cc-language-chooser.c',
   'cc-list-row.c',
+  'cc-permission-infobar.c',
   'cc-util.c'
 )
 
 resource_data = files(
   'cc-language-chooser.ui',
   'cc-list-row.ui',
+  'cc-permission-infobar.ui',
 )
 
 sources += gnome.compile_resources(


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