[gnome-software/wip/rancell/permissions] Flesh out permission dialog



commit fa5d8123fb7ce172b3ba360825d96453e5a3c69b
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Aug 14 16:25:44 2017 +1200

    Flesh out permission dialog

 src/gs-details-page.c       |    4 ++-
 src/gs-permission-dialog.c  |   28 +++++++++++++++++
 src/gs-permission-dialog.ui |   71 ++++++++++++++++++++++++++++++-------------
 3 files changed, 81 insertions(+), 22 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 6417acd..c2c0910 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -243,6 +243,7 @@ gs_details_page_switch_to (GsPage *page, gboolean scroll_up)
        g_autofree gchar *text = NULL;
        GtkStyleContext *sc;
        GtkAdjustment *adj;
+       GPtrArray *permissions;
 
        if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_DETAILS) {
                g_warning ("Called switch_to(details) when in mode %s",
@@ -403,7 +404,8 @@ gs_details_page_switch_to (GsPage *page, gboolean scroll_up)
        case AS_APP_STATE_INSTALLED:
        case AS_APP_STATE_UPDATABLE:
        case AS_APP_STATE_UPDATABLE_LIVE:
-               gtk_widget_set_visible (self->button_permissions, TRUE);
+               permissions = gs_app_get_permissions (self->app);
+               gtk_widget_set_visible (self->button_permissions, permissions->len > 0);
                break;
        default:
                gtk_widget_set_visible (self->button_permissions, FALSE);
diff --git a/src/gs-permission-dialog.c b/src/gs-permission-dialog.c
index de1fd57..c2d035c 100644
--- a/src/gs-permission-dialog.c
+++ b/src/gs-permission-dialog.c
@@ -28,6 +28,7 @@ struct _GsPermissionDialog
        GtkDialog        parent_instance;
 
        GsApp           *app;
+       GtkWidget       *permission_grid;
 };
 
 G_DEFINE_TYPE (GsPermissionDialog, gs_permission_dialog, GTK_TYPE_DIALOG)
@@ -57,17 +58,44 @@ gs_permission_dialog_class_init (GsPermissionDialogClass *klass)
        object_class->dispose = gs_permission_dialog_dispose;
 
        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-permission-dialog.ui");
+
+       gtk_widget_class_bind_template_child (widget_class, GsPermissionDialog, permission_grid);
+}
+
+static void
+set_row (GsPermissionDialog *dialog, int row, const gchar *text)
+{
+       GtkWidget *label;
+       GtkWidget *sw;
+
+       label = gtk_label_new (text);
+       gtk_label_set_xalign (GTK_LABEL (label), 1.0);
+       gtk_widget_set_hexpand (label, TRUE);
+       gtk_widget_show (label);
+       gtk_grid_attach (GTK_GRID (dialog->permission_grid), label, 0, row, 1, 1);
+
+       sw = gtk_switch_new ();
+       gtk_widget_show (sw);
+       gtk_grid_attach (GTK_GRID (dialog->permission_grid), sw, 1, row, 1, 1);
 }
 
 GtkWidget *
 gs_permission_dialog_new (GsApp *app)
 {
        GsPermissionDialog *dialog;
+       GPtrArray *permissions;
+       guint i;
 
        dialog = g_object_new (GS_TYPE_PERMISSION_DIALOG,
                               "use-header-bar", TRUE,
                               NULL);
        dialog->app = g_object_ref (app);
 
+       permissions = gs_app_get_permissions (app);
+       for (i = 0; i < permissions->len; i++) {
+               GsPermission *permission = g_ptr_array_index (permissions, i);
+               set_row (dialog, i, gs_permission_get_label (permission));
+       }
+
        return GTK_WIDGET (dialog);
 }
diff --git a/src/gs-permission-dialog.ui b/src/gs-permission-dialog.ui
index b4c96c7..57a3f87 100644
--- a/src/gs-permission-dialog.ui
+++ b/src/gs-permission-dialog.ui
@@ -1,33 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
   <template class="GsPermissionDialog" parent="GtkDialog">
     <property name="can_focus">False</property>
-    <property name="title" translatable="yes" comments="Translators: Title of the dialog box where app 
permissions can be controlled.">Permissions</property>
+    <property name="resizable">False</property>
     <property name="modal">True</property>
-    <property name="default_width">600</property>
-    <property name="default_height">300</property>
     <property name="destroy_with_parent">True</property>
     <property name="type_hint">dialog</property>
-    <property name="use_header_bar">1</property>
-    <child internal-child="headerbar">
-      <object class="GtkHeaderBar">
-        <property name="show_close_button">True</property>
-      </object>
-    </child>
+    <property name="deletable">False</property>
     <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox">
+      <object class="GtkBox" id="box_dialog">
         <property name="can_focus">False</property>
-        <property name="margin_start">40</property>
-        <property name="margin_end">40</property>
-        <property name="margin_top">25</property>
-        <property name="margin_bottom">25</property>
         <property name="orientation">vertical</property>
-        <property name="spacing">9</property>
+        <property name="spacing">2</property>
         <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
+          <object class="GtkButtonBox">
             <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -36,19 +29,55 @@
           </packing>
         </child>
         <child>
-          <object class="GtkBox" id="box1">
+          <object class="GtkGrid" id="permission_grid">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">20</property>
+            <property name="border_width">21</property>
+            <property name="row_spacing">12</property>
+            <property name="column_spacing">12</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
             <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
       </object>
     </child>
+    <child type="titlebar">
+      <object class="GtkHeaderBar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="title">Permissions</property>
+        <property name="show_close_button">True</property>
+      </object>
+    </child>
   </template>
 </interface>


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