[rhythmbox] task-list: restructure to improve the progress bar's width



commit 68cb18842665d7b3ea8eacfee226c2cc91edab66
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sun Sep 18 22:36:13 2016 +1000

    task-list: restructure to improve the progress bar's width
    
    Now the progress bar's width doesn't depend on the space allocated
    to the labels.  Task list entries are built from a GtkBuilder file
    to make future changes like this easier to manage.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771337

 data/ui/Makefile.am            |    1 +
 data/ui/task-list-entry.ui     |  101 ++++++++++++++++++++++++++++++++++++++++
 shell/rhythmbox.gresource.xml  |    1 +
 widgets/rb-task-list-display.c |   59 ++++++++++-------------
 4 files changed, 128 insertions(+), 34 deletions(-)
---
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am
index a42a59f..3155601 100644
--- a/data/ui/Makefile.am
+++ b/data/ui/Makefile.am
@@ -31,6 +31,7 @@ GTK_BUILDER_FILES =                                   \
        song-info-multiple.ui                           \
        sync-dialog.ui                                  \
        sync-state.ui                                   \
+       task-list-entry.ui                              \
        uri-new.ui
 
 EXTRA_DIST = $(GTK_BUILDER_FILES) style.css
diff --git a/data/ui/task-list-entry.ui b/data/ui/task-list-entry.ui
new file mode 100644
index 0000000..5d6cea3
--- /dev/null
+++ b/data/ui/task-list-entry.ui
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkImage" id="task-cancel-image">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="icon_name">process-stop-symbolic</property>
+  </object>
+  <object class="GtkGrid" id="task-list-entry">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="margin_left">6</property>
+    <property name="margin_right">6</property>
+    <property name="margin_top">6</property>
+    <property name="margin_bottom">6</property>
+    <property name="column_spacing">12</property>
+    <child>
+      <object class="GtkGrid">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="valign">center</property>
+        <property name="hexpand">True</property>
+        <property name="column_homogeneous">True</property>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="valign">center</property>
+            <property name="hexpand">True</property>
+            <child>
+              <object class="GtkLabel" id="task-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+                <property name="hexpand">True</property>
+                <property name="ellipsize">end</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="task-detail">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">center</property>
+                <property name="hexpand">True</property>
+                <property name="ellipsize">end</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="task-progress">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="valign">center</property>
+            <property name="hexpand">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="task-cancel">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="valign">center</property>
+        <property name="image">task-cancel-image</property>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/shell/rhythmbox.gresource.xml b/shell/rhythmbox.gresource.xml
index 5ce4c66..b1fbc4a 100644
--- a/shell/rhythmbox.gresource.xml
+++ b/shell/rhythmbox.gresource.xml
@@ -39,6 +39,7 @@
                <file preprocess="xml-stripblanks">ui/song-info.ui</file>
                <file preprocess="xml-stripblanks">ui/sync-dialog.ui</file>
                <file preprocess="xml-stripblanks">ui/sync-state.ui</file>
+               <file preprocess="xml-stripblanks">ui/task-list-entry.ui</file>
                <file preprocess="xml-stripblanks">ui/uri-new.ui</file>
 
                <file preprocess="xml-stripblanks">playlists.xml</file>
diff --git a/widgets/rb-task-list-display.c b/widgets/rb-task-list-display.c
index c986332..90e608f 100644
--- a/widgets/rb-task-list-display.c
+++ b/widgets/rb-task-list-display.c
@@ -31,6 +31,7 @@
 #include <widgets/rb-task-list-display.h>
 #include <lib/rb-task-progress.h>
 #include <lib/rb-list-model.h>
+#include <lib/rb-builder-helpers.h>
 #include <lib/rb-util.h>
 
 #define TASK_REMOVE_DELAY      15
@@ -94,56 +95,46 @@ task_list_changed_cb (RBListModel *model, int position, int removed, int added,
        }
 
        for (i = 0; i < added; i++) {
-               GtkWidget *tw, *w;
-               RBTaskProgress *task;
+               GtkBuilder *b;
+               GtkWidget *entry;
+               GtkWidget *widget;
                gboolean cancellable;
+               RBTaskProgress *task;
 
                task = RB_TASK_PROGRESS (rb_list_model_get (model, position + i));
-               tw = gtk_grid_new ();
-               g_object_set (tw,
-                             "column-spacing", 12,
-                             "margin", 6,
-                             NULL);
-
-               w = gtk_label_new (NULL);
-               g_object_bind_property (task, "task-label", w, "label", G_BINDING_SYNC_CREATE);
-               g_object_set (w, "hexpand", TRUE, "halign", GTK_ALIGN_START, NULL);
-               gtk_grid_attach (GTK_GRID (tw), w, 0, 0, 1, 1);
-
-               w = gtk_label_new (NULL);
-               gtk_style_context_add_class (gtk_widget_get_style_context (w), GTK_STYLE_CLASS_DIM_LABEL);
-               g_object_bind_property (task, "task-detail", w, "label", G_BINDING_SYNC_CREATE);
-               g_object_set (w, "hexpand", TRUE, "halign", GTK_ALIGN_START, NULL);
-               gtk_grid_attach (GTK_GRID (tw), w, 1, 0, 1, 1);
-
-               w = gtk_progress_bar_new ();
-               g_object_bind_property (task, "task-progress", w, "fraction", G_BINDING_SYNC_CREATE);
-               g_object_set (w, "hexpand", TRUE, "valign", GTK_ALIGN_CENTER, NULL);
-               gtk_grid_attach (GTK_GRID (tw), w, 2, 0, 1, 1);
-
-               /* pause/resume button? */
 
+               b = rb_builder_load ("task-list-entry.ui", NULL);
+
+               entry = GTK_WIDGET (gtk_builder_get_object (b, "task-list-entry"));
+
+               widget = GTK_WIDGET (gtk_builder_get_object (b, "task-label"));
+               g_object_bind_property (task, "task-label", widget, "label", G_BINDING_SYNC_CREATE);
+
+               widget = GTK_WIDGET (gtk_builder_get_object (b, "task-detail"));
+               g_object_bind_property (task, "task-detail", widget, "label", G_BINDING_SYNC_CREATE);
+
+               widget = GTK_WIDGET (gtk_builder_get_object (b, "task-progress"));
+               g_object_bind_property (task, "task-progress", widget, "fraction", G_BINDING_SYNC_CREATE);
+
+               widget = GTK_WIDGET (gtk_builder_get_object (b, "task-cancel"));
                g_object_get (task, "task-cancellable", &cancellable, NULL);
-               w = gtk_button_new ();
-               gtk_container_add (GTK_CONTAINER (w), gtk_image_new_from_icon_name ("process-stop-symbolic", 
GTK_ICON_SIZE_MENU));
                if (cancellable) {
                        g_object_bind_property_full (task, "task-outcome",
-                                                    w, "sensitive",
+                                                    widget, "sensitive",
                                                     G_BINDING_SYNC_CREATE,
                                                     transform_outcome,
                                                     NULL,
                                                     NULL,
                                                     NULL);
                } else {
-                       g_object_set (w, "sensitive", FALSE, NULL);
+                       g_object_set (widget, "sensitive", FALSE, NULL);
                }
-               g_signal_connect_object (w, "clicked", G_CALLBACK (stop_clicked_cb), task, 0);
-               gtk_grid_attach (GTK_GRID (tw), w, 3, 0, 1, 1);
+               g_signal_connect_object (widget, "clicked", G_CALLBACK (stop_clicked_cb), task, 0);
 
                gtk_grid_insert_column (GTK_GRID (list), position + i);
-               gtk_grid_attach (GTK_GRID (list), tw, 0, position + i, 1, 1);
-               gtk_widget_show_all (tw);
-               g_array_insert_val (list->priv->widgets, position + i, tw);
+               gtk_grid_attach (GTK_GRID (list), entry, 0, position + i, 1, 1);
+               gtk_widget_show_all (entry);
+               g_array_insert_val (list->priv->widgets, position + i, entry);
        }
 }
 


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