From: wolffc Date: Thu, 16 Sep 2010 14:47:04 +0000 (+0000) Subject: Display all available printer drivers for each model. Collect X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9088a98799b8180615270fce8d312367b8671782;p=gosa.git Display all available printer drivers for each model. Collect 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 --- diff --git a/trunk/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc b/trunk/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc index 4a6d16556..8d1f335a2 100644 --- a/trunk/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc +++ b/trunk/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc @@ -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; } } diff --git a/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc b/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc index 85e23f1e4..955cc21c4 100644 --- a/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc +++ b/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc @@ -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]); + } + } } } }