Blob Blame History Raw
From 5d4cb8ea9c35b0a21259328e75d8672924f754e6 Mon Sep 17 00:00:00 2001
From: Felipe Borges <felipeborges@gnome.org>
Date: Tue, 21 Nov 2017 15:16:53 +0100
Subject: [PATCH] printer: Don't show the supply level bar by default

We were checking for the ink supply level at the callback of the
supply bar "draw" signal. This way we were making the the widget
visible, causing it to allocate vertical space even when it isn't
desired.

Now we check for the supply level before setting the visiblity of
the supply level widget.

https://bugzilla.gnome.org/show_bug.cgi?id=790667
---
 panels/printers/pp-printer-entry.c | 16 ++++++++++++++--
 panels/printers/printer-entry.ui   |  2 --
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index ba704b9c7..6aa202aba 100644
--- a/panels/printers/pp-printer-entry.c
+++ b/panels/printers/pp-printer-entry.c
@@ -227,6 +227,15 @@ sanitize_printer_model (gchar *printer_make_and_model)
   return g_strdup (printer_model);
 }
 
+static gboolean
+supply_level_is_empty (PpPrinterEntry *self)
+{
+    return !((self->inklevel->marker_levels != NULL) &&
+             (self->inklevel->marker_colors != NULL) &&
+             (self->inklevel->marker_names != NULL) &&
+             (self->inklevel->marker_types != NULL));
+}
+
 /* To tone down the colors in the supply level bar
  * we shade them by darkening the hue.
  *
@@ -267,8 +276,7 @@ supply_levels_draw_cb (GtkWidget      *widget,
 
   gtk_render_background (context, cr, 0, 0, width, height);
 
-  if (self->inklevel->marker_levels && self->inklevel->marker_colors &&
-      self->inklevel->marker_names && self->inklevel->marker_types)
+  if (!supply_level_is_empty (self))
     {
       GSList   *markers = NULL;
       GSList   *tmp_list = NULL;
@@ -694,6 +702,7 @@ pp_printer_entry_new (cups_dest_t  printer,
   PpPrinterEntry *self;
   cups_ptype_t    printer_type = 0;
   gboolean        is_accepting_jobs;
+  gboolean        ink_supply_is_empty;
   gchar          *instance;
   gchar          *printer_uri = NULL;
   gchar          *location = NULL;
@@ -935,6 +944,9 @@ pp_printer_entry_new (cups_dest_t  printer,
     }
 
   g_signal_connect (self->supply_drawing_area, "draw", G_CALLBACK (supply_levels_draw_cb), self);
+  ink_supply_is_empty = supply_level_is_empty (self);
+  gtk_widget_set_visible (GTK_WIDGET (self->printer_inklevel_label), !ink_supply_is_empty);
+  gtk_widget_set_visible (GTK_WIDGET (self->supply_frame), !ink_supply_is_empty);
 
   pp_printer_entry_update_jobs_count (self);
 
diff --git a/panels/printers/printer-entry.ui b/panels/printers/printer-entry.ui
index 5ac2eb1e3..c72b90a99 100644
--- a/panels/printers/printer-entry.ui
+++ b/panels/printers/printer-entry.ui
@@ -245,7 +245,6 @@
 
             <child>
               <object class="GtkLabel" id="printer_inklevel_label">
-                <property name="visible">True</property>
                 <property name="label" translatable="yes">Ink Level</property>
                 <property name="halign">end</property>
                 <property name="xalign">1</property>
@@ -261,7 +260,6 @@
 
             <child>
               <object class="GtkFrame" id="supply_frame">
-                <property name="visible">True</property>
                 <property name="valign">center</property>
                 <property name="halign">start</property>
                 <property name="height_request">18</property>
-- 
2.14.3