[gnome-control-center/wip/msanchez/printers-clean-heads] printers: Expose the newly added 'Clean' maintenance command to users
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/msanchez/printers-clean-heads] printers: Expose the newly added 'Clean' maintenance command to users
- Date: Mon, 13 Jun 2016 13:51:00 +0000 (UTC)
commit 1e44577a8eb792c9eef1e65f88586a03dc528480
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 | 92 ++++++++++++++++++++++++++++++++++++
panels/printers/printer-entry.ui | 17 ++++++-
2 files changed, 106 insertions(+), 3 deletions(-)
---
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index cc817af..ea24a77 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"
@@ -44,6 +45,9 @@ struct _PpPrinterEntry
gchar *printer_location;
gchar *printer_hostname;
+ /* Maintenance commands */
+ PpMaintenanceCommand *clean_command;
+
/* Widgets */
GtkImage *printer_icon;
GtkLabel *printer_status;
@@ -54,6 +58,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 +330,71 @@ set_as_default_printer (GtkToggleButton *button,
}
static void
+check_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_is_supported_finish (command, res, &error))
+ {
+ gtk_widget_show (GTK_WIDGET (self->clean_heads_menuitem));
+ }
+ else if (error != NULL)
+ {
+ g_warning ("Error checking 'Clean' maintenance command for %s: %s", self->printer_name,
error->message);
+ g_error_free (error);
+ }
+ 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);
+ pp_maintenance_command_is_supported_async (self->clean_command,
+ NULL,
+ check_clean_heads_maintenance_command_cb,
+ self);
+}
+
+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)
+{
+ 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)
{
@@ -484,6 +554,12 @@ 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",
+ /* 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);
gtk_label_set_text (self->printer_name_label, instance);
@@ -522,10 +598,24 @@ pp_printer_entry_new (cups_dest_t printer)
}
static void
+pp_printer_entry_dispose (GObject *object)
+{
+ PpPrinterEntry *self = PP_PRINTER_ENTRY (object);
+
+ if (self->clean_command)
+ g_clear_object (&self->clean_command);
+
+ G_OBJECT_CLASS (pp_printer_entry_parent_class)->dispose (object);
+}
+
+static void
pp_printer_entry_class_init (PpPrinterEntryClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ object_class->dispose = pp_printer_entry_dispose;
+
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/printers/printer-entry.ui");
gtk_widget_class_bind_template_child (widget_class, PpPrinterEntry, printer_icon);
@@ -538,10 +628,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_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);
}
diff --git a/panels/printers/printer-entry.ui b/panels/printers/printer-entry.ui
index e6f5592..fc7a79d 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]