From: mike Date: Sat, 4 Oct 2008 15:34:08 +0000 (+0000) Subject: Make auto-configure wait for auto-configure job to complete. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2e17d3ef30a9e7101c1b74c6ef24436d265fe4ba;p=thirdparty%2Fcups.git Make auto-configure wait for auto-configure job to complete. More UI cleanup. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@8012 7a7537e8-13f0-0310-91df-b6672ffda945 --- diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c index 59a3566da2..e5ed77a60a 100644 --- a/cgi-bin/admin.c +++ b/cgi-bin/admin.c @@ -3197,19 +3197,34 @@ do_set_options(http_t *http, /* I - HTTP connection */ int job_id; /* Command file job */ char refresh[1024]; /* Refresh URL */ http_status_t status; /* Document status */ + cups_option_t hold_option; /* job-hold-until option */ static const char *autoconfigure =/* Command file */ "#CUPS-COMMAND\n" "AutoConfigure\n"; + static const char const *job_attrs[] = + { + "job-state", + "job-printer-state-message" + }; + cgiStartMultipart(); + cgiStartHTML(title); + cgiCopyTemplateLang("autoconfigure.tmpl"); + cgiEndHTML(); + fflush(stdout); + + hold_option.name = "job-hold-until"; + hold_option.value = "no-hold"; if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, printer, "Auto-Configure", - 0, NULL)) < 1) + 1, &hold_option)) < 1) { cgiSetVariable("ERROR", cgiText(_("Unable to send auto-configure command " "to printer driver!"))); cgiStartHTML(title); cgiCopyTemplateLang("error.tmpl"); cgiEndHTML(); + cgiEndMultipart(); return; } @@ -3227,11 +3242,55 @@ do_set_options(http_t *http, /* I - HTTP connection */ cgiStartHTML(title); cgiCopyTemplateLang("error.tmpl"); cgiEndHTML(); + cgiEndMultipart(); cupsCancelJob(printer, job_id); return; } + /* + * Wait for the job to complete... + */ + + for (;;) + { + /* + * Get the current job state... + */ + + snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id); + request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES); + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", + NULL, uri); + if (getenv("REMOTE_USER")) + ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, + "requesting-user-name", NULL, getenv("REMOTE_USER")); + ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, + "requested-attributes", 2, NULL, job_attrs); + + response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); + attr = ippFindAttribute(response, "job-state", IPP_TAG_ENUM); + if (!attr || attr->values[0].integer >= IPP_JOB_STOPPED) + { + ippDelete(response); + break; + } + + /* + * Job not complete, so update the status... + */ + + cgiSetIPPVars(response, NULL, NULL, NULL, 0); + ippDelete(response); + + cgiStartHTML(title); + cgiCopyTemplateLang("autoconfigure.tmpl"); + cgiEndHTML(); + fflush(stdout); + + sleep(5); + } + /* * Redirect successful updates back to the printer page... */ @@ -3245,6 +3304,7 @@ do_set_options(http_t *http, /* I - HTTP connection */ cgiCopyTemplateLang("printer-configured.tmpl"); cgiEndHTML(); + cgiEndMultipart(); return; } diff --git a/templates/Makefile b/templates/Makefile index 44da1b4d74..fb25f7d0bf 100644 --- a/templates/Makefile +++ b/templates/Makefile @@ -24,6 +24,7 @@ FILES = \ add-printer.tmpl \ add-rss-subscription.tmpl \ admin.tmpl \ + autoconfigure.tmpl \ choose-device.tmpl \ choose-make.tmpl \ choose-model.tmpl \ diff --git a/templates/autoconfigure.tmpl b/templates/autoconfigure.tmpl new file mode 100644 index 0000000000..93aa493d74 --- /dev/null +++ b/templates/autoconfigure.tmpl @@ -0,0 +1,11 @@ +
+ +

Set Default Options for {printer_name}

+ +

Query job {job_state=3?pending:{job_state=4?held: +{job_state=5?processing:{job_state=6?stopped: +{job_state=7?canceled:{job_state=8?aborted:completed}}}}}}{job_printer_state_message?, +"{job_printer_state_message}":}

+ +
diff --git a/templates/class-confirm.tmpl b/templates/class-confirm.tmpl index d5641498ce..c14d354820 100644 --- a/templates/class-confirm.tmpl +++ b/templates/class-confirm.tmpl @@ -1,5 +1,7 @@
+

Delete Class {printer_name}

+

Warning: Are you sure you want to delete class {printer_name}?

diff --git a/templates/option-boolean.tmpl b/templates/option-boolean.tmpl index 72c85189a4..2d0dd551a1 100644 --- a/templates/option-boolean.tmpl +++ b/templates/option-boolean.tmpl @@ -1,5 +1,5 @@ -{keytext}: +{keytext}: {[choices]{text}} diff --git a/templates/option-header.tmpl b/templates/option-header.tmpl index cafc9f9fef..f34865c375 100644 --- a/templates/option-header.tmpl +++ b/templates/option-header.tmpl @@ -1,3 +1,3 @@ -

{printer_name}: {group}

+

{group}

- +
diff --git a/templates/option-pickmany.tmpl b/templates/option-pickmany.tmpl index d2534af75a..067075aec0 100644 --- a/templates/option-pickmany.tmpl +++ b/templates/option-pickmany.tmpl @@ -1,5 +1,5 @@ - + diff --git a/templates/option-pickone.tmpl b/templates/option-pickone.tmpl index a2ce9d8c8c..05b83ee8a7 100644 --- a/templates/option-pickone.tmpl +++ b/templates/option-pickone.tmpl @@ -1,5 +1,5 @@ - +
{keytext}:{keytext}:
{keytext}:{keytext}: diff --git a/templates/printer-configured.tmpl b/templates/printer-configured.tmpl index b80db4569a..6f8104e231 100644 --- a/templates/printer-configured.tmpl +++ b/templates/printer-configured.tmpl @@ -1,6 +1,8 @@
-

{OP=set-class-options?Class :Printer }{printer_name} has -been configured successfully. +

Set Default Options for {printer_name}

+ +

{OP=set-class-options?Class :Printer }{printer_name} +default options have been set successfully.

diff --git a/templates/printer-confirm.tmpl b/templates/printer-confirm.tmpl index 4cac6c3661..db16d691b3 100644 --- a/templates/printer-confirm.tmpl +++ b/templates/printer-confirm.tmpl @@ -1,5 +1,7 @@
+

Delete Printer {printer_name}

+

Warning: Are you sure you want to delete printer {printer_name}?

diff --git a/templates/set-printer-options-header.tmpl b/templates/set-printer-options-header.tmpl index dad328a83a..124094ecec 100644 --- a/templates/set-printer-options-header.tmpl +++ b/templates/set-printer-options-header.tmpl @@ -1,9 +1,11 @@
+

Set Default Options for {printer_name}

+
-{HAVE_AUTOCONFIGURE?:} +{HAVE_AUTOCONFIGURE?:}