[nautilus/wip/apoos-maximus/gsoc2020] properties-window: Add volume usage grid to template



commit 4233faa1f1f99bf2fac47a839ad2569d6b3f096d
Author: Apoorv Sachan <apoorv 99 sachan gmail com>
Date:   Fri Jul 3 04:38:36 2020 +0530

    properties-window: Add volume usage grid to template
    
    The skeleton, layouting of grid cells, and styling of widgets
    inside the volume usage widget is done in the template. Only the
    GtkDrawing areas are drawn using code, in callbacks for ::draw.

 src/nautilus-properties-window.c               | 153 ++++----------------
 src/resources/ui/nautilus-properties-window.ui | 193 ++++++++++++++++++++++++-
 2 files changed, 223 insertions(+), 123 deletions(-)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 631b8bc83..dc80f289d 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -143,6 +143,14 @@ struct _NautilusPropertiesWindow
     GtkWidget *volume_widget_box;
     GtkWidget *open_in_disks_button;
 
+    GtkWidget *pie_chart;
+    GtkWidget *used_color;
+    GtkWidget *used_value;
+    GtkWidget *free_color;
+    GtkWidget *free_value;
+    GtkWidget *total_capacity_value;
+    GtkWidget *file_system_value;
+
     /* Permissions tab Widgets */
 
     GtkWidget *permissions_box;
@@ -303,7 +311,7 @@ static GtkLabel *attach_ellipsizing_value_label (GtkGrid    *grid,
                                                  GtkWidget  *sibling,
                                                  const char *initial_text);
 
-static GtkWidget *create_pie_widget (NautilusPropertiesWindow *window);
+static void setup_pie_widget (NautilusPropertiesWindow *window);
 
 G_DEFINE_TYPE (NautilusPropertiesWindow, nautilus_properties_window, GTK_TYPE_WINDOW);
 
@@ -2896,24 +2904,10 @@ paint_pie_chart (GtkWidget *widget,
                  free, used, "used");
 }
 
-static GtkWidget *
-create_pie_widget (NautilusPropertiesWindow *window)
+static void
+setup_pie_widget (NautilusPropertiesWindow *window)
 {
     NautilusFile *file;
-    GtkGrid *grid;
-    GtkStyleContext *style;
-    GtkWidget *pie_canvas;
-    GtkWidget *used_canvas;
-    GtkWidget *used_label;
-    GtkWidget *used_type_label;
-    GtkWidget *free_canvas;
-    GtkWidget *free_label;
-    GtkWidget *free_type_label;
-    GtkWidget *capacity_label;
-    GtkWidget *capacity_value_label;
-    GtkWidget *fstype_label;
-    GtkWidget *fstype_value_label;
-    GtkWidget *spacer_label;
     gchar *capacity;
     gchar *used;
     gchar *free;
@@ -2930,44 +2924,15 @@ create_pie_widget (NautilusPropertiesWindow *window)
 
     uri = nautilus_file_get_activation_uri (file);
 
-    grid = GTK_GRID (gtk_grid_new ());
-    gtk_widget_set_hexpand (GTK_WIDGET (grid), FALSE);
-    gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
-    gtk_grid_set_row_spacing (GTK_GRID (grid), 10);
-    gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
-
-    pie_canvas = gtk_drawing_area_new ();
-    gtk_widget_set_size_request (pie_canvas, 200, 200);
-    style = gtk_widget_get_style_context (pie_canvas);
-    gtk_style_context_add_class (style, "disk-space-display");
-
-    used_canvas = gtk_drawing_area_new ();
-    gtk_widget_set_size_request (used_canvas, 20, 20);
-    style = gtk_widget_get_style_context (used_canvas);
-    gtk_style_context_add_class (style, "disk-space-display");
-    gtk_style_context_add_class (style, "used");
-
-    used_label = gtk_label_new (used);
     /* Translators: "used" refers to the capacity of the filesystem */
-    used_type_label = gtk_label_new (_("used"));
-
-    free_canvas = gtk_drawing_area_new ();
-    gtk_widget_set_size_request (free_canvas, 20, 20);
-    style = gtk_widget_get_style_context (free_canvas);
-    gtk_style_context_add_class (style, "disk-space-display");
-    gtk_style_context_add_class (style, "free");
+    gtk_label_set_text (GTK_LABEL (window->used_value), used);
 
-    free_label = gtk_label_new (free);
     /* Translators: "free" refers to the capacity of the filesystem */
-    free_type_label = gtk_label_new (_("free"));
+    gtk_label_set_text (GTK_LABEL (window->free_value), free);
 
-    capacity_label = gtk_label_new (_("Total capacity:"));
-    capacity_value_label = gtk_label_new (capacity);
+    gtk_label_set_text (GTK_LABEL (window->total_capacity_value), capacity);
 
-    fstype_label = gtk_label_new (_("Filesystem type:"));
-    fstype_value_label = gtk_label_new (NULL);
-
-    spacer_label = gtk_label_new ("");
+    gtk_label_set_text (GTK_LABEL (window->file_system_value), NULL);
 
     location = g_file_new_for_uri (uri);
     info = g_file_query_filesystem_info (location, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
@@ -2977,7 +2942,7 @@ create_pie_widget (NautilusPropertiesWindow *window)
         fs_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
         if (fs_type != NULL)
         {
-            gtk_label_set_text (GTK_LABEL (fstype_value_label), fs_type);
+            gtk_label_set_text (GTK_LABEL (window->file_system_value), fs_type);
         }
 
         g_object_unref (info);
@@ -2989,72 +2954,17 @@ create_pie_widget (NautilusPropertiesWindow *window)
     g_free (used);
     g_free (free);
 
-    gtk_container_add_with_properties (GTK_CONTAINER (grid), pie_canvas,
-                                       "height", 5,
-                                       NULL);
-
-    gtk_widget_set_vexpand (spacer_label, TRUE);
-    gtk_grid_attach_next_to (grid, spacer_label, pie_canvas,
-                             GTK_POS_RIGHT, 1, 1);
-
-    gtk_widget_set_halign (used_canvas, GTK_ALIGN_END);
-    gtk_widget_set_vexpand (used_canvas, FALSE);
-    gtk_grid_attach_next_to (grid, used_canvas, spacer_label,
-                             GTK_POS_BOTTOM, 1, 1);
-    gtk_widget_set_halign (used_label, GTK_ALIGN_END);
-    gtk_widget_set_vexpand (used_label, FALSE);
-    gtk_grid_attach_next_to (grid, used_label, used_canvas,
-                             GTK_POS_RIGHT, 1, 1);
-    gtk_widget_set_halign (used_type_label, GTK_ALIGN_START);
-    gtk_widget_set_vexpand (used_type_label, FALSE);
-    gtk_grid_attach_next_to (grid, used_type_label, used_label,
-                             GTK_POS_RIGHT, 1, 1);
-
-    gtk_widget_set_halign (free_canvas, GTK_ALIGN_END);
-    gtk_widget_set_vexpand (free_canvas, FALSE);
-    gtk_grid_attach_next_to (grid, free_canvas, used_canvas,
-                             GTK_POS_BOTTOM, 1, 1);
-    gtk_widget_set_halign (free_label, GTK_ALIGN_END);
-    gtk_widget_set_vexpand (free_label, FALSE);
-    gtk_grid_attach_next_to (grid, free_label, free_canvas,
-                             GTK_POS_RIGHT, 1, 1);
-    gtk_widget_set_halign (free_type_label, GTK_ALIGN_START);
-    gtk_widget_set_vexpand (free_type_label, FALSE);
-    gtk_grid_attach_next_to (grid, free_type_label, free_label,
-                             GTK_POS_RIGHT, 1, 1);
-
-    gtk_widget_set_halign (capacity_label, GTK_ALIGN_END);
-    gtk_widget_set_vexpand (capacity_label, FALSE);
-    gtk_grid_attach_next_to (grid, capacity_label, free_canvas,
-                             GTK_POS_BOTTOM, 1, 1);
-    gtk_widget_set_halign (capacity_value_label, GTK_ALIGN_START);
-    gtk_widget_set_vexpand (capacity_value_label, FALSE);
-    gtk_grid_attach_next_to (grid, capacity_value_label, capacity_label,
-                             GTK_POS_RIGHT, 1, 1);
-
-    gtk_widget_set_halign (fstype_label, GTK_ALIGN_END);
-    gtk_widget_set_vexpand (fstype_label, FALSE);
-    gtk_grid_attach_next_to (grid, fstype_label, capacity_label,
-                             GTK_POS_BOTTOM, 1, 1);
-    gtk_widget_set_halign (fstype_value_label, GTK_ALIGN_START);
-    gtk_widget_set_vexpand (fstype_value_label, FALSE);
-    gtk_grid_attach_next_to (grid, fstype_value_label, fstype_label,
-                             GTK_POS_RIGHT, 1, 1);
-
-    g_signal_connect (pie_canvas, "draw",
+    g_signal_connect (window->pie_chart, "draw",
                       G_CALLBACK (paint_pie_chart), window);
-    g_signal_connect (used_canvas, "draw",
+    g_signal_connect (window->used_color, "draw",
                       G_CALLBACK (paint_legend), window);
-    g_signal_connect (free_canvas, "draw",
+    g_signal_connect (window->free_color, "draw",
                       G_CALLBACK (paint_legend), window);
-
-    return GTK_WIDGET (grid);
 }
 
-static GtkWidget *
-create_volume_usage_widget (NautilusPropertiesWindow *window)
+static void
+setup_volume_usage_widget (NautilusPropertiesWindow *window)
 {
-    GtkWidget *piewidget = NULL;
     gchar *uri;
     NautilusFile *file;
     GFile *location;
@@ -3093,11 +3003,8 @@ create_volume_usage_widget (NautilusPropertiesWindow *window)
 
     if (window->volume_capacity > 0)
     {
-        piewidget = create_pie_widget (window);
-        gtk_widget_show_all (piewidget);
+        setup_pie_widget (window);
     }
-
-    return piewidget;
 }
 
 static void
@@ -3129,7 +3036,6 @@ static void
 create_basic_page (NautilusPropertiesWindow *window)
 {
     GtkGrid *grid;
-    GtkWidget *volume_usage;
 
     /* Icon pixmap */
 
@@ -3340,12 +3246,7 @@ create_basic_page (NautilusPropertiesWindow *window)
     {
         gtk_widget_show (window->volume_widget_box);
         gtk_widget_show (window->open_in_disks_button);
-        volume_usage = create_volume_usage_widget (window);
-        if (volume_usage != NULL)
-        {
-            gtk_container_add (GTK_CONTAINER (window->volume_widget_box), volume_usage);
-        }
-
+        setup_volume_usage_widget (window);
         /*Translators: Here Disks mean the name of application GNOME Disks.*/
         g_signal_connect (window->open_in_disks_button, "clicked", G_CALLBACK (open_in_disks), NULL);
     }
@@ -5916,6 +5817,14 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, spacer_8);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, 
change_permissions_button_box);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, change_permissions_button);
+
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, pie_chart);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, used_color);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, used_value);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, free_color);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, free_value);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, total_capacity_value);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, file_system_value);
 }
 
 static void
diff --git a/src/resources/ui/nautilus-properties-window.ui b/src/resources/ui/nautilus-properties-window.ui
index e1b6dfa63..5b9416470 100644
--- a/src/resources/ui/nautilus-properties-window.ui
+++ b/src/resources/ui/nautilus-properties-window.ui
@@ -430,7 +430,198 @@
                             <property name="can_focus">False</property>
                             <property name="orientation">vertical</property>
                             <child>
-                              <placeholder/>
+                              <object class="GtkGrid" id="volume_grid">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="hexpand">False</property>
+                                <property name="border_width">5</property>
+                                <property name="row_spacing">10</property>
+                                <property name="column_spacing">10</property>
+                                <child>
+                                  <object class="GtkDrawingArea" id="pie_chart">
+                                    <property name="width_request">200</property>
+                                    <property name="height_request">200</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <style>
+                                      <class name="disk-space-display"/>
+                                    </style>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">0</property>
+                                    <property name="top_attach">0</property>
+                                    <property name="height">5</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="spacer_label">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="vexpand">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkDrawingArea" id="used_color">
+                                    <property name="width_request">20</property>
+                                    <property name="height_request">20</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">end</property>
+                                    <property name="vexpand">False</property>
+                                    <style>
+                                      <class name="disk-space-display"/>
+                                      <class name="used"/>
+                                    </style>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkDrawingArea" id="free_color">
+                                    <property name="width_request">20</property>
+                                    <property name="height_request">20</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">end</property>
+                                    <property name="vexpand">False</property>
+                                    <style>
+                                      <class name="disk-space-display"/>
+                                      <class name="free"/>
+                                    </style>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">end</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label" translatable="yes">Total capacity:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">3</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">end</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label" translatable="yes">Filesystem type:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="top_attach">4</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="total_capacity_value">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">start</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label">0</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">2</property>
+                                    <property name="top_attach">3</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="file_system_value">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">start</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label">0</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">2</property>
+                                    <property name="top_attach">4</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="used_value">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">end</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label">0</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">2</property>
+                                    <property name="top_attach">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="free_value">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">end</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label">0</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">2</property>
+                                    <property name="top_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">start</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label" translatable="yes" comments="Refers to the 
capacity of the filesystem">used</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">3</property>
+                                    <property name="top_attach">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="halign">start</property>
+                                    <property name="vexpand">False</property>
+                                    <property name="label" translatable="yes" comments="Refers to the 
capacity of the filesystem">free</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">3</property>
+                                    <property name="top_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
                             </child>
                           </object>
                           <packing>


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