[gnome-control-center/wip/msanchez/printers-clean-heads: 3/3] printers: Expose the newly added 'Clean' maintenance command to users



commit 635138ba75fb2ead82d360acbda15589d6781742
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Fri Apr 29 12:05:21 2016 +0100

    printers: Expose the newly added 'Clean' maintenance command to users
    
    Add an extra button "Clean Print Heads" that will be shown when the relevant
    maintenance command is available for a printer, to bring this feature back.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764620

 panels/printers/pp-printer-entry.c |   41 ++++++++++++++++++++++++++++++++++++
 panels/printers/printer-entry.ui   |   17 ++++++++++++--
 2 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index 1e6e863..f0b127b 100644
--- a/panels/printers/pp-printer-entry.c
+++ b/panels/printers/pp-printer-entry.c
@@ -25,6 +25,7 @@
 #include <glib/gstdio.h>
 
 #include "pp-details-dialog.h"
+#include "pp-maintenance-command.h"
 #include "pp-options-dialog.h"
 #include "pp-jobs-dialog.h"
 #include "pp-utils.h"
@@ -54,6 +55,7 @@ struct _PpPrinterEntry
   GtkLabel       *printer_location_address_label;
   GtkDrawingArea *supply_drawing_area;
   GtkWidget      *show_jobs_dialog_button;
+  GtkWidget      *clean_heads_menuitem;
   GtkCheckButton *printer_default_checkbutton;
 
   /* Dialogs */
@@ -325,6 +327,40 @@ set_as_default_printer (GtkToggleButton *button,
 }
 
 static void
+clean_heads_maintenance_command_cb (GObject      *source_object,
+                                    GAsyncResult *res,
+                                    gpointer      user_data)
+{
+  PpPrinterEntry       *self = (PpPrinterEntry *) user_data;
+  PpMaintenanceCommand *command = (PpMaintenanceCommand *) source_object;
+  GError               *error = NULL;
+
+  if (!pp_maintenance_command_execute_finish (command, res, &error))
+    {
+      g_warning ("Error cleaning print heads for %s: %s", self->printer_name, error->message);
+      g_error_free (error);
+    }
+  g_object_unref (source_object);
+}
+
+static void
+clean_heads (GtkButton *button,
+             PpPrinterEntry *self)
+{
+  PpMaintenanceCommand *command;
+
+  command = pp_maintenance_command_new (self->printer_name,
+                                        "clean",
+      /* Translators: Name of job which makes printer to clean its heads */
+                                        _("Clean print heads"));
+
+  pp_maintenance_command_execute_async (command,
+                                        NULL,
+                                        clean_heads_maintenance_command_cb,
+                                        self);
+}
+
+static void
 remove_printer (GtkButton *button,
                PpPrinterEntry *self)
 {
@@ -499,6 +535,9 @@ pp_printer_entry_new (cups_dest_t  printer)
 
   gtk_label_set_text (self->printer_model, self->printer_make_and_model);
 
+  if (pp_maintenance_command_is_supported (self->printer_name, "Clean"))
+    gtk_widget_show (GTK_WIDGET (self->clean_heads_menuitem));
+
   if (location[0] == '\0')
     {
       gtk_widget_hide (GTK_WIDGET (self->printer_location_label));
@@ -538,10 +577,12 @@ pp_printer_entry_class_init (PpPrinterEntryClass *klass)
   gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, supply_drawing_area);
   gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_default_checkbutton);
   gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, show_jobs_dialog_button);
+  gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, clean_heads_menuitem);
 
   gtk_widget_class_bind_template_callback (widget_class, on_show_printer_options_dialog);
   gtk_widget_class_bind_template_callback (widget_class, on_show_printer_details_dialog);
   gtk_widget_class_bind_template_callback (widget_class, set_as_default_printer);
+  gtk_widget_class_bind_template_callback (widget_class, clean_heads);
   gtk_widget_class_bind_template_callback (widget_class, remove_printer);
   gtk_widget_class_bind_template_callback (widget_class, show_jobs_dialog);
 }
diff --git a/panels/printers/printer-entry.ui b/panels/printers/printer-entry.ui
index e0a84c7..cd16343 100644
--- a/panels/printers/printer-entry.ui
+++ b/panels/printers/printer-entry.ui
@@ -29,6 +29,17 @@
           </packing>
         </child>
         <child>
+          <object class="GtkModelButton" id="clean_heads_menuitem">
+            <property name="visible">False</property>
+            <property name="text" translatable="yes" comments="Translators: This button executes command 
which cleans print heads of the printer.">Clean Print Heads</property>
+           <signal name="clicked" handler="clean_heads"/>
+         </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">2</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkCheckButton" id="printer_default_checkbutton">
             <property name="visible">True</property>
             <property name="valign">center</property>
@@ -36,7 +47,7 @@
           </object>
           <packing>
             <property name="left-attach">0</property>
-            <property name="top-attach">2</property>
+            <property name="top-attach">3</property>
           </packing>
         </child>
         <child>
@@ -47,7 +58,7 @@
          </object>
           <packing>
             <property name="left-attach">1</property>
-            <property name="top-attach">2</property>
+            <property name="top-attach">3</property>
           </packing>
         </child>
         <child>
@@ -58,7 +69,7 @@
          </object>
           <packing>
             <property name="left-attach">1</property>
-            <property name="top-attach">3</property>
+            <property name="top-attach">4</property>
           </packing>
         </child>
       </object>


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