[gnome-control-center/wip/msanchez/printers-clean-heads: 4/6] Refactor _pp_maintenance_command_execute_thread to use the new function.
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/msanchez/printers-clean-heads: 4/6] Refactor _pp_maintenance_command_execute_thread to use the new function.
- Date: Fri, 29 Apr 2016 11:54:56 +0000 (UTC)
commit fdd960d545cdadd36d943eac7afbada1d2d88d36
Author: Mario Sanchez Prada <mario endlessm com>
Date: Thu Apr 28 18:58:48 2016 +0100
Refactor _pp_maintenance_command_execute_thread to use the new function.
Call pp_maintenance_command_is_supported() instead of duplicating code.
panels/printers/pp-maintenance-command.c | 119 ++++++++++--------------------
1 files changed, 38 insertions(+), 81 deletions(-)
---
diff --git a/panels/printers/pp-maintenance-command.c b/panels/printers/pp-maintenance-command.c
index 4f565c8..f335e0f 100644
--- a/panels/printers/pp-maintenance-command.c
+++ b/panels/printers/pp-maintenance-command.c
@@ -184,104 +184,61 @@ _pp_maintenance_command_execute_thread (GSimpleAsyncResult *res,
{
PpMaintenanceCommand *command = (PpMaintenanceCommand *) object;
PpMaintenanceCommandPrivate *priv = command->priv;
- static const char *attrs[] = {"printer-commands"};
- ipp_attribute_t *attr = NULL;
gboolean success = FALSE;
GError *error = NULL;
- ipp_t *request;
- ipp_t *response = NULL;
- gchar *printer_uri;
- gchar *printer_commands = NULL;
- gchar *printer_commands_lowercase = NULL;
- gchar *command_lowercase;
- gchar *file_name = NULL;
- int fd = -1;
- printer_uri = g_strdup_printf ("ipp://localhost/printers/%s",
- priv->printer_name);
+ if (pp_maintenance_command_is_supported (priv->printer_name, priv->command))
+ {
+ ipp_t *request;
+ ipp_t *response = NULL;
+ gchar *printer_uri;
+ gchar *file_name = NULL;
+ int fd = -1;
- request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
- ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, printer_uri);
- ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes", 1, NULL, attrs);
- response = cupsDoRequest (CUPS_HTTP_DEFAULT, request, "/");
+ printer_uri = g_strdup_printf ("ipp://localhost/printers/%s",
+ priv->printer_name);
- if (response)
- {
- if (ippGetStatusCode (response) <= IPP_OK_CONFLICT)
- {
- attr = ippFindAttribute (response, "printer-commands", IPP_TAG_ZERO);
- if (attr && ippGetCount (attr) > 0 && ippGetValueTag (attr) != IPP_TAG_NOVALUE)
- {
- if (ippGetValueTag (attr) == IPP_TAG_KEYWORD)
- {
- printer_commands = g_strdup (ippGetString (attr, 0, NULL));
- }
- }
- else
- {
- success = TRUE;
- }
- }
+ request = ippNewRequest (IPP_PRINT_JOB);
- ippDelete (response);
- }
+ ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
+ "printer-uri", NULL, printer_uri);
+ ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ "job-name", NULL, priv->title);
+ ippAddString (request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
+ "document-format", NULL, "application/vnd.cups-command");
- if (printer_commands)
- {
- command_lowercase = g_ascii_strdown (priv->command, -1);
- printer_commands_lowercase = g_ascii_strdown (printer_commands, -1);
+ fd = g_file_open_tmp ("ccXXXXXX", &file_name, &error);
- if (g_strrstr (printer_commands_lowercase, command_lowercase))
+ if (fd != -1)
{
- request = ippNewRequest (IPP_PRINT_JOB);
+ FILE *file;
- ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, printer_uri);
- ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "job-name", NULL, priv->title);
- ippAddString (request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
- "document-format", NULL, "application/vnd.cups-command");
+ file = fdopen (fd, "w");
+ fprintf (file, "#CUPS-COMMAND\n");
+ fprintf (file, "%s\n", priv->command);
+ fclose (file);
- fd = g_file_open_tmp ("ccXXXXXX", &file_name, &error);
+ response = cupsDoFileRequest (CUPS_HTTP_DEFAULT, request, "/", file_name);
+ g_unlink (file_name);
- if (fd != -1)
+ if (response)
{
- FILE *file;
-
- file = fdopen (fd, "w");
- fprintf (file, "#CUPS-COMMAND\n");
- fprintf (file, "%s\n", priv->command);
- fclose (file);
-
- response = cupsDoFileRequest (CUPS_HTTP_DEFAULT, request, "/", file_name);
- g_unlink (file_name);
-
- if (response)
+ if (ippGetStatusCode (response) <= IPP_OK_CONFLICT)
{
- if (ippGetStatusCode (response) <= IPP_OK_CONFLICT)
- {
- success = TRUE;
- }
-
- ippDelete (response);
+ success = TRUE;
}
- }
- g_free (file_name);
- }
- else
- {
- success = TRUE;
+ ippDelete (response);
+ }
}
- g_free (command_lowercase);
- g_free (printer_commands_lowercase);
- g_free (printer_commands);
+ g_free (file_name);
+ g_free (printer_uri);
+ }
+ else
+ {
+ success = TRUE;
}
-
- g_free (printer_uri);
if (!success)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]