[gnome-control-center] printers: Expose the newly added 'Clean' maintenance command to users



commit b74293697095124a331bbb106bc580fdd5567d44
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Thu Mar 23 13:30:22 2017 +0000

    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.
    
    Additionally, this commit adds a 'parameters' attribute to PpMaintenanceCommand,
    which is needed as the "Clean" command requires to at least be passed "all" as
    its single parameter: https://www.cups.org/doc/spec-command.html#Clean
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764620

 panels/printers/pp-maintenance-command.c |   24 +++++++-
 panels/printers/pp-maintenance-command.h |    1 +
 panels/printers/pp-new-printer.c         |    1 +
 panels/printers/pp-printer-entry.c       |   95 ++++++++++++++++++++++++++++++
 panels/printers/printer-entry.ui         |   14 ++++-
 5 files changed, 132 insertions(+), 3 deletions(-)
---
diff --git a/panels/printers/pp-maintenance-command.c b/panels/printers/pp-maintenance-command.c
index 2b0b864..e707314 100644
--- a/panels/printers/pp-maintenance-command.c
+++ b/panels/printers/pp-maintenance-command.c
@@ -39,6 +39,7 @@ struct _PpMaintenanceCommandPrivate
 {
   gchar *printer_name;
   gchar *command;
+  gchar *parameters;
   gchar *title;
 };
 
@@ -48,6 +49,7 @@ enum {
   PROP_0 = 0,
   PROP_PRINTER_NAME,
   PROP_COMMAND,
+  PROP_PARAMETERS,
   PROP_TITLE
 };
 
@@ -60,6 +62,7 @@ pp_maintenance_command_finalize (GObject *object)
 
   g_clear_pointer (&priv->printer_name, g_free);
   g_clear_pointer (&priv->command, g_free);
+  g_clear_pointer (&priv->parameters, g_free);
   g_clear_pointer (&priv->title, g_free);
 
   G_OBJECT_CLASS (pp_maintenance_command_parent_class)->finalize (object);
@@ -83,6 +86,9 @@ pp_maintenance_command_get_property (GObject    *object,
       case PROP_COMMAND:
         g_value_set_string (value, self->priv->command);
         break;
+      case PROP_PARAMETERS:
+        g_value_set_string (value, self->priv->parameters);
+        break;
       case PROP_TITLE:
         g_value_set_string (value, self->priv->title);
         break;
@@ -112,6 +118,10 @@ pp_maintenance_command_set_property (GObject      *object,
         g_free (self->priv->command);
         self->priv->command = g_value_dup_string (value);
         break;
+      case PROP_PARAMETERS:
+        g_free (self->priv->parameters);
+        self->priv->parameters = g_value_dup_string (value);
+        break;
       case PROP_TITLE:
         g_free (self->priv->title);
         self->priv->title = g_value_dup_string (value);
@@ -149,6 +159,13 @@ pp_maintenance_command_class_init (PpMaintenanceCommandClass *klass)
                          NULL,
                          G_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class, PROP_PARAMETERS,
+    g_param_spec_string ("parameters",
+                         "Optional parameters",
+                         "Optional parameters for the maintenance command",
+                         NULL,
+                         G_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class, PROP_TITLE,
     g_param_spec_string ("title",
                          "Command title",
@@ -168,11 +185,13 @@ pp_maintenance_command_init (PpMaintenanceCommand *command)
 PpMaintenanceCommand *
 pp_maintenance_command_new (const gchar *printer_name,
                             const gchar *command,
+                            const gchar *parameters,
                             const gchar *title)
 {
   return g_object_new (PP_TYPE_MAINTENANCE_COMMAND,
                        "printer-name", printer_name,
                        "command", command,
+                       "parameters", parameters,
                        "title", title,
                        NULL);
 }
@@ -219,7 +238,10 @@ _pp_maintenance_command_execute_thread (GTask        *task,
 
           file = fdopen (fd, "w");
           fprintf (file, "#CUPS-COMMAND\n");
-          fprintf (file, "%s\n", priv->command);
+          fprintf (file, "%s", priv->command);
+          if (priv->parameters)
+            fprintf (file, " %s", priv->parameters);
+          fprintf (file, "\n");
           fclose (file);
 
           response = cupsDoFileRequest (CUPS_HTTP_DEFAULT, request, "/", file_name);
diff --git a/panels/printers/pp-maintenance-command.h b/panels/printers/pp-maintenance-command.h
index cf9a44e..5069a01 100644
--- a/panels/printers/pp-maintenance-command.h
+++ b/panels/printers/pp-maintenance-command.h
@@ -52,6 +52,7 @@ GType   pp_maintenance_command_get_type                          (void) G_GNUC_C
 
 PpMaintenanceCommand *pp_maintenance_command_new                 (const gchar *printer_name,
                                                                   const gchar *command,
+                                                                  const gchar *parameters,
                                                                   const gchar *title);
 
 void                  pp_maintenance_command_execute_async       (PpMaintenanceCommand *command,
diff --git a/panels/printers/pp-new-printer.c b/panels/printers/pp-new-printer.c
index d84cc1f..cc0d259 100644
--- a/panels/printers/pp-new-printer.c
+++ b/panels/printers/pp-new-printer.c
@@ -1315,6 +1315,7 @@ printer_configure_async (PpNewPrinter *new_printer)
       PpMaintenanceCommand *command;
       command = pp_maintenance_command_new (priv->name,
                                             "autoconfigure",
+                                            NULL,
       /* Translators: Name of job which makes printer to autoconfigure itself */
                                             _("Automatic configuration"));
 
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index 4823924..6fd705c 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-printer.h"
@@ -47,6 +48,10 @@ struct _PpPrinterEntry
   gboolean  is_authorized;
   gint      printer_state;
 
+  /* Maintenance commands */
+  PpMaintenanceCommand *clean_command;
+  GCancellable *check_clean_heads_cancellable;
+
   /* Widgets */
   GtkImage       *printer_icon;
   GtkLabel       *printer_status;
@@ -57,6 +62,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;
   GtkModelButton *remove_printer_menuitem;
   GtkBox         *printer_error;
@@ -402,6 +408,79 @@ set_as_default_printer (GtkToggleButton *button,
 }
 
 static void
+check_clean_heads_maintenance_command_cb (GObject      *source_object,
+                                          GAsyncResult *res,
+                                          gpointer      user_data)
+{
+  PpMaintenanceCommand *command = (PpMaintenanceCommand *) source_object;
+  gboolean              is_supported = FALSE;
+  GError               *error = NULL;
+
+  is_supported = pp_maintenance_command_is_supported_finish (command, res, &error);
+  if (error != NULL)
+    {
+      g_debug ("Could not check 'Clean' maintenance command: %s", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  if (is_supported)
+    {
+      PpPrinterEntry *self = PP_PRINTER_ENTRY (user_data);
+      gtk_widget_show (GTK_WIDGET (self->clean_heads_menuitem));
+    }
+
+ out:
+  g_object_unref (source_object);
+}
+
+static void
+check_clean_heads_maintenance_command (PpPrinterEntry *self)
+{
+  if (self->clean_command == NULL)
+    return;
+
+  g_object_ref (self->clean_command);
+  self->check_clean_heads_cancellable = g_cancellable_new ();
+
+  pp_maintenance_command_is_supported_async (self->clean_command,
+                                             self->check_clean_heads_cancellable,
+                                             check_clean_heads_maintenance_command_cb,
+                                             self);
+}
+
+static void
+clean_heads_maintenance_command_cb (GObject      *source_object,
+                                    GAsyncResult *res,
+                                    gpointer      user_data)
+{
+  PpPrinterEntry       *self = PP_PRINTER_ENTRY (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)
+{
+  if (self->clean_command == NULL)
+    return;
+
+  g_object_ref (self->clean_command);
+  pp_maintenance_command_execute_async (self->clean_command,
+                                        NULL,
+                                        clean_heads_maintenance_command_cb,
+                                        self);
+}
+
+static void
 remove_printer (GtkButton      *button,
                 PpPrinterEntry *self)
 {
@@ -751,6 +830,13 @@ pp_printer_entry_new (cups_dest_t  printer,
 
   self->printer_hostname = printer_get_hostname (printer_type, self->printer_uri, printer_uri);
 
+  self->clean_command = pp_maintenance_command_new (self->printer_name,
+                                                    "Clean",
+                                                    "all",
+                                                    /* Translators: Name of job which makes printer to clean 
its heads */
+                                                    _("Clean print heads"));
+  check_clean_heads_maintenance_command (self);
+
   gtk_image_set_from_icon_name (self->printer_icon, printer_icon_name, GTK_ICON_SIZE_DIALOG);
   gtk_label_set_text (self->printer_status, printer_status);
   g_free (printer_status);
@@ -823,6 +909,13 @@ pp_printer_entry_dispose (GObject *object)
       g_clear_object (&self->get_jobs_cancellable);
     }
 
+  if (self->check_clean_heads_cancellable)
+    {
+      g_cancellable_cancel (self->check_clean_heads_cancellable);
+      g_clear_object (&self->check_clean_heads_cancellable);
+    }
+  g_clear_object (&self->clean_command);
+
   G_OBJECT_CLASS (pp_printer_entry_parent_class)->dispose (object);
 }
 
@@ -844,6 +937,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_child (widget_class, PpPrinterEntry, remove_printer_menuitem);
   gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, error_status);
   gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_error);
@@ -851,6 +945,7 @@ pp_printer_entry_class_init (PpPrinterEntryClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, on_show_printer_details_dialog);
   gtk_widget_class_bind_template_callback (widget_class, on_show_printer_options_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);
   gtk_widget_class_bind_template_callback (widget_class, restart_printer);
diff --git a/panels/printers/printer-entry.ui b/panels/printers/printer-entry.ui
index 9f0d6f2..b898df1 100644
--- a/panels/printers/printer-entry.ui
+++ b/panels/printers/printer-entry.ui
@@ -44,7 +44,17 @@
             <property name="width">3</property>
           </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">3</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkModelButton" id="remove_printer_menuitem">
             <property name="visible">True</property>
@@ -53,7 +63,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]