Code

Display all available printer drivers for each model. Collect
authorwolffc <wolffc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 16 Sep 2010 14:47:04 +0000 (14:47 +0000)
committerwolffc <wolffc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 16 Sep 2010 14:47:04 +0000 (14:47 +0000)
ShortNickName attribute from PPD files and add an extension to the
model name if more than one entry exists for each model. The extension
consists of the base directory (foomatic-rip, hpijs, etc.) and the
short nick name.

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@19727 594d385d-05f5-0310-b6e9-bd551577e9d8

trunk/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc
trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc

index 4a6d16556e00330cab372ada37b23a165a77a666..8d1f335a2f9fab2cd429f676f37c6ec0f92f57e5 100644 (file)
@@ -337,8 +337,12 @@ class ppdManager
                                $ppdDesc['model'] = trim(preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line));
                        }
 
+      if (preg_match('/^\*ShortNickName:/i', $line)) {
+        $ppdDesc['nickname'] = trim(preg_replace('/^\*ShortNickName:\s+"?([^"]+)"?.*$/i', '\1', $line));
+      }
+
                        /* Got everything we need? Skip rest for speed reasons... */
-                       if (isset($ppdDesc['manufacturer'])  && isset($ppdDesc['model'])){
+                       if (isset($ppdDesc['manufacturer']) && isset($ppdDesc['model']) && isset($ppdDesc['nickname'])){
                                break;
                        }
                }
index 85e23f1e4625c3e0ce3acc9c756a8540740cef2a..955cc21c4e6c1b7359b457aa7bb212342cdb0ab7 100644 (file)
@@ -365,7 +365,59 @@ class printerPPDDialog extends plugin
         $tmp3['link']   =$file;
         $tmp3['ppd']    =$ppd;
         $this->ppdListHeader[$ppd['manufacturer']]++;
-        $this->ppdList[$ppd['manufacturer']][$ppd['name']]=$tmp3;
+        if (isset($this->ppdList[$ppd['manufacturer']][$ppd['name']])) {
+
+          # Printer exists already, add directory/nickname to identify it
+          
+          $tmp4 = $this->ppdList[$ppd['manufacturer']][$ppd['name']]['link'];
+
+          # Remove the default path (e.g. /srv/www/ppd) plus a possible debian/ directory
+          $extension = preg_replace("#".$this->pathToPPD."/(debian/)?#", "", $tmp3['link']);
+
+          # Remove all further directories, just keep the first level (e.g. foomatic-rip, hpijs)
+          $extension = preg_replace("#/.*#", "", $extension);
+
+          # Add the nickname as well to distinguish between two drivers for the same model in one directory
+          $extension = $extension." / ".$ppd['nickname'];
+
+          # Generate the updated extension from the original path and nickname, same way as above
+          $updated_nickname = $this->ppdList[$ppd['manufacturer']][$ppd['name']]['ppd']['nickname'];
+          $updated_extension = preg_replace("#".$this->pathToPPD."/(debian/)?#", "", $tmp4);
+          $updated_extension = preg_replace("#/.*#", "", $updated_extension);
+          $updated_extension = $updated_extension." / ".$updated_nickname;
+          $updated_name = $ppd['name']." ($updated_extension)";
+
+          if (!isset($this->ppdList[$ppd['manufacturer']][$updated_name]['name'])) {
+            $old_ppd = array_keys($this->ppdList[$ppd['manufacturer']][$ppd['name']]);
+            # Copy old printer attributes to new name
+            foreach($old_ppd as $entry){ 
+               $this->ppdList[$ppd['manufacturer']][$updated_name][$entry] = $this->ppdList[$ppd['manufacturer']][$ppd['name']][$entry];
+            }  
+
+            # Add old printer under updated name
+            $this->ppdList[$ppd['manufacturer']][$updated_name]['name'] = $updated_name;
+            $this->ppdList[$ppd['manufacturer']][$updated_name]['ppd']['name'] = $ppd['name']." ($updated_extension)";
+            $this->ppdList[$ppd['manufacturer']][$updated_name]['ppd']['model'] = $ppd['model']." ($updated_extension)";
+          }
+          
+          # Now generate name/model including extension for new printer
+          $tmp3['ppd']['name'] = $tmp3['name']." ($extension)";
+          $tmp3['ppd']['model'] = $tmp3['ppd']['model']." ($extension)";
+          $tmp3['name'] = $tmp3['name']." ($extension)";
+          $myname = $tmp3['name'];
+        }
+        $this->ppdList[$ppd['manufacturer']][$tmp3['name']]=$tmp3;
+      }
+
+      # Remove all non-nicknamed/directorized printers from list who have a
+      # nicknamed counterpart already, those are dupes.
+      foreach($this->ppdList as $manufacturer => $printers) {
+        foreach($printers as $ppd) {
+          $to_remove = preg_replace("/ \(.*\)$/", "", $ppd['name']); 
+          if ($to_remove != $ppd['name'] && isset($this->ppdList[$manufacturer][$to_remove])) {
+            unset($this->ppdList[$manufacturer][$to_remove]);
+          }
+        }
       }
     }
   }