Bug 92463 - Add method for renaming of printers
Summary: Add method for renaming of printers
Status: RESOLVED FIXED
Alias: None
Product: cups-pk-helper
Classification: Unclassified
Component: General (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Marek Kasik
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-14 16:35 UTC by Marek Kasik
Modified: 2015-11-12 11:07 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
printer renaming (15.90 KB, patch)
2015-10-20 09:48 UTC, mhatina
Details | Splinter Review
printer renaming (15.91 KB, patch)
2015-11-03 09:07 UTC, mhatina
Details | Splinter Review
printer renaming (15.88 KB, patch)
2015-11-10 09:14 UTC, mhatina
Details | Splinter Review

Description Marek Kasik 2015-10-14 16:35:28 UTC
It would be cool to have a method for renaming of printers so that applications managing printers don't need to implement it themselves (e.g. gnome-control-center and system-config-printer) and can utilize async call for that.
I've asked Martin to work on this.
Comment 1 mhatina 2015-10-20 09:48:42 UTC
Created attachment 118998 [details] [review]
printer renaming
Comment 2 Marek Kasik 2015-10-26 14:54:20 UTC
Comment on attachment 118998 [details] [review]
printer renaming

Review of attachment 118998 [details] [review]:
-----------------------------------------------------------------

Thank you for working on this,

I have few comments on the patch. I'll push it once you apply them.

::: src/cups-pk-helper-mechanism.c
@@ +912,5 @@
> +        gboolean      ret;
> +
> +        _cph_mechanism_emit_called (mechanism);
> +
> +        if (!_check_polkit_for_printer (mechanism, context, old_printer_name, NULL))

We need to check more policies here. See _check_polkit_for_printer_class() and _cph_mechanism_get_action_for_name() + add "printer-set-default", "printer-enable" and "job-edit" or "job-not-owned-edit" if there are jobs to move (and select appropriate one).

::: src/cups.c
@@ +2170,5 @@
> +
> +        num_jobs = cupsGetJobs (&jobs, old_printer_name, 0, CUPS_WHICHJOBS_ACTIVE);
> +        for (i = 0; i < num_jobs; i++) {
> +                if (jobs[i].state == IPP_JSTATE_PENDING
> +                    || jobs[i].state == IPP_JSTATE_PROCESSING) {

Move the logical OR to the end of the previous line please.

@@ +2209,5 @@
> +
> +        if (response != NULL) {
> +                if (ippGetStatusCode (response) <= IPP_OK_CONFLICT) {
> +                        attr = ippFindAttribute (response, "printer-error-policy", IPP_TAG_NAME);
> +                        if (attr)

Do all such checks against NULL value please.

@@ +2239,5 @@
> +                        }
> +                }
> +        }
> +
> +        ippDelete (response);

Include this in the "if (response != NULL)" block.

@@ +2260,5 @@
> +                                                       printer_info,
> +                                                       printer_location)) {
> +                for (i = 0; i < num_dests; i++) {
> +                        if (!cph_cups_is_class (cups, dests[i].name))
> +                                continue;

Negate the condition and place the following block into it please (you can join the 2 ifs to one then).

@@ +2300,5 @@
> +                        start_sheet = sheets[0];
> +                        end_sheet = sheets[1];
> +                }
> +        }
> +        cph_cups_printer_class_set_job_sheets (cups, new_printer_name, start_sheet, end_sheet);

You can move this to the inner if so we don't run it when not needed.

@@ +2304,5 @@
> +        cph_cups_printer_class_set_job_sheets (cups, new_printer_name, start_sheet, end_sheet);
> +        cph_cups_printer_set_enabled (cups, new_printer_name, !printer_paused);
> +        cph_cups_printer_class_set_shared (cups, new_printer_name, printer_shared);
> +        cph_cups_printer_class_set_users_allowed (cups, new_printer_name, users_allowed);
> +        cph_cups_printer_class_set_users_denied (cups, new_printer_name, users_denied);

Cast the "users_allowed" and "users_denied" to "(const char * const *)" so we don't get warnings about that.

@@ +2334,5 @@
> +                g_strfreev (sheets);
> +        if (users_allowed)
> +                g_strfreev (users_allowed);
> +        if (users_denied)
> +                g_strfreev (users_denied);

g_strfreev() and g_free() don't need the NULL checks they check themselves.
Comment 3 Marek Kasik 2015-10-26 14:55:46 UTC
See the comments above please.
Comment 4 Marek Kasik 2015-10-29 15:35:18 UTC
(In reply to Marek Kasik from comment #2)
> ::: src/cups-pk-helper-mechanism.c
> @@ +912,5 @@
> > +        gboolean      ret;
> > +
> > +        _cph_mechanism_emit_called (mechanism);
> > +
> > +        if (!_check_polkit_for_printer (mechanism, context, old_printer_name, NULL))
> 
> We need to check more policies here. See _check_polkit_for_printer_class()
> and _cph_mechanism_get_action_for_name() + add "printer-set-default",
> "printer-enable" and "job-edit" or "job-not-owned-edit" if there are jobs to
> move (and select appropriate one).

I've looked at this again, the _check_polkit_for_printer_class() will be enough here.
Comment 5 mhatina 2015-11-03 09:07:19 UTC
Created attachment 119369 [details] [review]
printer renaming

Fixed.
Comment 6 Marek Kasik 2015-11-09 10:59:18 UTC
Comment on attachment 119369 [details] [review]
printer renaming

Review of attachment 119369 [details] [review]:
-----------------------------------------------------------------

I have 3 requests yet:

::: src/cups.c
@@ +2240,5 @@
> +                }
> +        }
> +
> +        if (response != NULL) {
> +                ippDelete (response);

I meant to move this to the above block which is also "if (response != NULL)". The ippDelete() actually checks the given pointer for NULL too but I prefer to have the free functions in the same block where we check the freed pointer for NULL if present.

@@ +2294,5 @@
> +                cph_cups_printer_set_default (cups, new_printer_name);
> +        cph_cups_printer_class_set_error_policy (cups, new_printer_name, error_policy);
> +        cph_cups_printer_class_set_op_policy (cups, new_printer_name, op_policy);
> +
> +        if (job_sheets) {

Check this against NULL please.

@@ +2322,5 @@
> +
> +
> +        cupsFreeDests (num_dests, dests);
> +
> +        if (ppd_link) {

Check this against NULL too.
Comment 7 mhatina 2015-11-10 09:14:05 UTC
Created attachment 119533 [details] [review]
printer renaming

Fixed.
Comment 8 Marek Kasik 2015-11-12 11:07:10 UTC
Thank you for the patch Martin. I've pushed it into master.

Btw, I plan to do a new release of cups-pk-helper before next stable Gnome comes out (3.20). I will look at some other bugs and improvements we could get there.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.