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



commit 7595e057ad4b24bffdb5510ee83dfcc3e089ead6
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Fri Apr 29 12:33:33 2016 +0100

    printers: Expose the newly added 'Clean' maintenance command to users
    
    Use pp_maintenance_command_is_supported() to check whether the CUPS is
    actually supported to decide when to show the new action, and implement
    the action so that it actually executes the command.

 panels/printers/pp-printer-entry.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index 79ed44b..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,10 +327,37 @@ 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)
 {
-  /* TODO: not implemented */
+  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
@@ -506,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));
@@ -545,6 +577,7 @@ 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);


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