After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 658544 - Add printers without exactly matching drivers
Add printers without exactly matching drivers
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: printers
3.1.x
Other Linux
: Normal normal
: ---
Assigned To: Marek Kašík
gnome-settings-daemon-maint
Depends on:
Blocks:
 
 
Reported: 2011-09-08 11:39 UTC by Marek Kašík
Modified: 2011-09-19 10:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
find best matching ppd (39.24 KB, patch)
2011-09-08 11:39 UTC, Marek Kašík
needs-work Details | Review
find best matching ppd modified (40.55 KB, patch)
2011-09-08 16:00 UTC, Marek Kašík
needs-work Details | Review
modified patch (39.10 KB, patch)
2011-09-09 10:21 UTC, Marek Kašík
committed Details | Review

Description Marek Kašík 2011-09-08 11:39:44 UTC
Created attachment 195976 [details] [review]
find best matching ppd

Current gnome-settings-daemon doesn't add printer if there is not exactly matching PPD file for the new printer.
The attached patch is a backport of this functionality from gnome-control-center. It calls system-config-printer's method "GetBestDrivers" to find the best matching PPD and use it for the new printer if there was no exact match. This pulls in new dependency on cups-pk-helper which is used for installation of the new printer.

Marek
Comment 1 Bastien Nocera 2011-09-08 13:55:19 UTC
Review of attachment 195976 [details] [review]:

You're leaking memory in various places, and the coding style doesn't match what's already there.

I would also make the get_missing_executables() and find_packages_for_executables() use GHashTables to avoid the duplicates in the first place (so you don't need to sort and uniq the GLists).

::: plugins/print-notifications/gsd-printer.c
@@ +398,3 @@
+                        name_index++;
+                } else
+

missing { and it doesn't line up.

@@ +454,3 @@
+                                                 input,
+                                                 G_DBUS_CALL_FLAGS_NONE,
+                }

magic values should use defines.

@@ +511,3 @@
+                        if (error) {
+                                g_warning ("%s", error->message);
+                                               NULL,

g_error_free() actually.

@@ +562,3 @@
+                        if (error) {
+                                g_warning ("%s", error->message);
+                                                tuple = g_variant_get_child_value (array, i);

Ditto.

@@ +616,3 @@
+                fd = g_file_open_tmp ("ccXXXXXX", &file_name, &error);
+
+static gchar *

No need to check for !error.
And you're leaking error.

@@ +719,3 @@
+                                               MECHANISM_BUS,
+                                               NULL,
+                      new_name = g_strdup (name);

You're leaking the error again.

@@ +721,3 @@
+                                               &error);
+
+

Turn this condition around, and exit early instead of creating gigantic if branches.

@@ +784,3 @@
+                                if (error) {
+                                        g_warning ("%s", error->message);
+        gint         i;

g_error_free() again.
Comment 2 Marek Kašík 2011-09-08 16:00:39 UTC
Created attachment 196006 [details] [review]
find best matching ppd modified

Hi Bastien,

thank you for your review. I've modified the patch according to it. The patch is attached.

Marek
Comment 3 Bastien Nocera 2011-09-08 16:41:26 UTC
Review of attachment 196006 [details] [review]:

Avoid the giant branches, it makes reading the code really hard.

Also do not check for "error != NULL", check for the error retval for the particular function.

::: plugins/print-notifications/gsd-printer.c
@@ +87,3 @@
+        GHashTable *executables = NULL;
+
+        if (ppd_file_name) {

if !ppd_file_name.

@@ +137,3 @@
+                }
+
+                                                         "MissingExecutables",

That's incorrect. You need to check for proxy == NULL, not for error != NULL.

@@ +151,3 @@
+        GHashTable *packages = NULL;
+
+                        if (output && g_variant_n_children (output) == 1) {

Giant branch!

@@ +238,3 @@
+                                                       &error);
+
+                                                       NULL,

Giant branch!

@@ +309,3 @@
+                                               &error);
+
+                                }

Again, exit out of the loop if you have !proxy instead of creating a giant branch.

@@ +340,3 @@
+                                                                ppd_name = g_strdup (name);
+
+

Why do you strdup() match and name to free them a couple of lines below?

@@ +456,3 @@
+                                               &error);
+
+                        g_object_unref (proxy);

if !proxy

@@ +502,3 @@
+        GError     *error = NULL;
+
+        gchar       *match = NULL;

if !printer_name return;

@@ +552,3 @@
+        GError     *error = NULL;
+
+                                                 "GetBestDrivers",

Ditto.

@@ +608,3 @@
+                                   cupsEncryption ());
+
+                }

if !http.

@@ +702,3 @@
+        ipp_t *response = NULL;
+
+        gchar       *new_name = NULL;

if !printer_name

@@ +753,3 @@
+                locale = setlocale (LC_MESSAGES, NULL);
+
+                                already_present = TRUE;

if !locale...

@@ +839,3 @@
+        printer_name = create_name (device_id);
+
+                                       ppd_name ? ppd_name : "",

Again.

@@ +959,3 @@
+
+                        ppd_file_name = cupsGetPPD (name);
+                        if (ppd_file_name) {

If !ppf_file_name.

@@ +960,3 @@
+                        ppd_file_name = cupsGetPPD (name);
+                        if (ppd_file_name) {
+                                GHashTable *executables = NULL;

Why do you initialise them when you set them 2 lines below?
Comment 4 Marek Kašík 2011-09-09 10:21:01 UTC
Created attachment 196084 [details] [review]
modified patch

I have change the patch according to your comment except one thing:

> 959	 
> 960	ppd_file_name = cupsGetPPD (name);
> 961	if (ppd_file_name) {
> 	
> If !ppf_file_name.

Changing this would insert more code.

Marek
Comment 5 Bastien Nocera 2011-09-09 16:31:36 UTC
Review of attachment 196084 [details] [review]:

::: plugins/print-notifications/gsd-printer.c
@@ +725,3 @@
+        commands_lowercase = g_ascii_strdown (commands, -1);
+
+                        name = g_strcanon (name, ALLOWED_CHARACTERS, '-');

lower case isn't going to match upper case letters.
Comment 6 Bastien Nocera 2011-09-09 16:32:18 UTC
Committed with a few bug/style fixes in separate commits.
Comment 7 Marek Kašík 2011-09-19 10:19:34 UTC
Hi,

thank you for the commit and those fixes.

Marek