From c30aefaa3219514a75ee95c24aa6de70d34608ad Mon Sep 17 00:00:00 2001 From: cajus Date: Tue, 24 Feb 2009 08:47:38 +0000 Subject: [PATCH] Added changeset:13433 done by psc git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@13446 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../admin/systems/goto/class_printGeneric.inc | 3 +- .../admin/systems/ppd/class_ppdManager.inc | 21 ++++--- .../systems/ppd/class_printerPPDDialog.inc | 55 +++++++++---------- .../ppd/class_printerPPDSelectionDialog.inc | 9 ++- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/trunk/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc b/trunk/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc index e12c79d6b..377f6c4b1 100644 --- a/trunk/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc +++ b/trunk/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc @@ -512,7 +512,8 @@ class printgeneric extends plugin if((!file_exists($path.$this->gotoPrinterPPD))){ $smarty->assign("driverInfo", "".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD).""); }else{ - $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD)); + $ppdDesc = $ppdManager->loadDescription($path.$this->gotoPrinterPPD); + $smarty->assign("driverInfo", $ppdDesc['name']); } }else{ $smarty->assign("driverInfo", _("Not defined")); 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 fe72164d2..db3e50c60 100644 --- a/trunk/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc +++ b/trunk/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc @@ -291,10 +291,8 @@ class ppdManager function loadDescription($ppdFile) { - $model= ""; - $manufacturer= ""; - - + $ppdDesc = array(); + /* Only parse complete PPD file again, if it was changed */ $modified = filemtime($ppdFile); if(isset($this->cachedList[$ppdFile]) && isset($this->timestamps[$ppdFile]) && $modified == $this->timestamps[$ppdFile]){ @@ -315,26 +313,31 @@ class ppdManager /* Extract interesting informations */ if (preg_match('/^\*Manufacturer:/i', $line)){ - $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line); + $ppdDesc['manufacturer'] = trim(preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line)); } if (preg_match('/^\*ModelName:/i', $line)){ - $model= preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line); + $ppdDesc['model'] = trim(preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line)); } /* Got everything we need? Skip rest for speed reasons... */ - if ($model != '' && $manufacturer != ''){ + if (isset($ppdDesc['manufacturer']) && isset($ppdDesc['model'])){ break; } } gzclose ($fh); + /* If model contains manufacturer strip it */ + $ppdDesc['model'] = str_replace($ppdDesc['manufacturer']." ", '', $ppdDesc['model']); + /* Write out a notice that the PPD file seems to be broken if we can't extract any usefull informations */ - if ($model == '' || $manufacturer == ''){ + if ($ppdDesc['manufacturer'] == '' || $ppdDesc['model'] == ''){ trigger_error(sprintf(_('Parsing PPD file %s failed - no information found.'), $ppdFile), E_USER_WARNING); } - return ($manufacturer.' - '.$model); + $ppdDesc['name'] = $ppdDesc['manufacturer'] . " - " . $ppdDesc['model']; + + return $ppdDesc; } 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 2f176e75a..149dc8608 100644 --- a/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc +++ b/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc @@ -71,15 +71,14 @@ class printerPPDDialog extends plugin if(!file_exists($this->pathToPPD.$this->pathToModified.$ppdfile)){ msg_dialog::display(_("PPD error"), sprintf(_("Cannot open PPD '%s'!"), $ppdfile), ERROR_DIALOG); }else{ - $res = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$ppdfile); - if($res){ - $tmp = split("\n",$res); - $tmp3 = array(); - $tmp3['name'] = trim(preg_replace("/^\-/","",trim($tmp[1]))); - $tmp3['link'] = $ppdfile; - $tmp3['ppd'] = $res; + $ppdDesc = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$ppdfile); + if($ppdDesc){ + $selectedPPD = array(); + $selectedPPD['name'] = $ppdDesc['name']; + $selectedPPD['link'] = $ppdfile; + $selectedPPD['ppd'] = $ppdDesc; } - $this->selectedPPD = $tmp3; + $this->selectedPPD = $selectedPPD; } } } @@ -223,12 +222,11 @@ class printerPPDDialog extends plugin msg_dialog::display(_("PPD error"), msgPool::cannotReadFile($AbsoluteSourceName), ERROR_DIALOG); return; } - $res = $this->ppdManager->loadDescription($AbsoluteSourceName); - if($res){ - $tmp = split("\n",$res); - $Name = trim(preg_replace("/^\-/","",trim($tmp[1]))); - $Vendor = trim($tmp[0]); - $Model = trim(preg_replace("/".$Vendor."/","",$Name)); + $ppdDesc = $this->ppdManager->loadDescription($AbsoluteSourceName); + if($ppdDesc){ + $Name = $ppdDesc['name']; + $Vendor = $ppdDesc['manufacturer']; + $Model = $ppdDesc['model']; } $PrinterName = $this->cn."-".preg_replace("/[^a-z0-9-_\.]/i","_",$Name); @@ -277,12 +275,11 @@ class printerPPDDialog extends plugin $this->getPrinterReload(); /* Get Description from ppd, & parse out some informations */ - $res = @$this->ppdManager->loadDescription($_PathOnHdd); - if($res){ - $tmp = split("\n",$res); - $name = @trim(preg_replace("/^\-/","",trim($tmp[1]))); - $vendor = @trim($tmp[0]); - $model = @trim(preg_replace("/".$vendor."/","",$name)); + $ppdDesc = @$this->ppdManager->loadDescription($_PathOnHdd); + if($ppdDesc){ + $name = $ppdDesc['name']; + $vendor = $ppdDesc['manufacturer']; + $model = $ppdDesc['model']; } /* Check if parse was successfull */ @@ -368,18 +365,18 @@ class printerPPDDialog extends plugin /* Sort all available files, and create header (Vendor index) */ foreach($tmp as $file=>$ppd){ - + if(preg_match("#".$this->pathToModified."#",$file)) continue; - $tmp2 = split("\n",$ppd); - if(!isset($this->ppdListHeader[$tmp2[0]])){ - $this->ppdListHeader[$tmp2[0]]=0; + if(!isset($this->ppdListHeader[$ppd['manufacturer']])){ + $this->ppdListHeader[$ppd['manufacturer']]=0; } - $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]); + + $tmp3['name'] =$ppd['name']; $tmp3['link'] =$file; $tmp3['ppd'] =$ppd; - $this->ppdListHeader[$tmp2[0]]++; - $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3; + $this->ppdListHeader[$ppd['manufacturer']]++; + $this->ppdList[$ppd['manufacturer']][$ppd['name']]=$tmp3; } } } @@ -428,12 +425,12 @@ class printerPPDDialog extends plugin { $str = "none"; if(!empty($this->selectedPPD)){ - $str = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']); + $ppdDesc = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']); + $str = $ppdDesc['name']; } return($str) ; } - /* Display all options from the selected ppd file */ function generateProperties() { diff --git a/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc b/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc index 8d109d11b..f9f32f8da 100644 --- a/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc +++ b/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc @@ -106,7 +106,8 @@ class printerPPDSelectionDialog extends plugin $list = array(); foreach($this->list as $cat => $ppds){ foreach($ppds as $ppd){ - if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){ + $name = $ppd['ppd']['name']; + if(preg_match("/^".str_replace("*",".*",$regex)."/i",$name)){ if(is_readable($ppd['link'])){ $list[$ppd['link']] = $ppd; } @@ -142,6 +143,7 @@ class printerPPDSelectionDialog extends plugin if(empty($this->Vendor)){ foreach($this-> header as $key => $entry){ $div ->AddEntry (array( + array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'") )); } @@ -150,7 +152,8 @@ class printerPPDSelectionDialog extends plugin array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'") )); foreach($list as $key => $ppd){ - if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){ + $name = $ppd['ppd']['name']; + if(preg_match("/^".$this->Vendor."/", $name)){ if(is_writeable($ppd['link'])){ $del_str = sprintf($dellink,base64_encode($key)); @@ -159,7 +162,7 @@ class printerPPDSelectionDialog extends plugin } $div ->AddEntry (array( - array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])), + array("string"=>sprintf($uselink,base64_encode($key),$name)), array("string"=>$del_str,"attach"=>"style='border-right:0px;'") )); -- 2.30.2