summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a7a3a76)
raw | patch | inline | side by side (parent: a7a3a76)
author | psc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 20 Feb 2009 12:44:34 +0000 (12:44 +0000) | ||
committer | psc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 20 Feb 2009 12:44:34 +0000 (12:44 +0000) |
- ppdManager::loadDescription now returns a well-formed associative
array instead of a string which is parsed over and over again.
This was neccessary to fix problems that occured after applying
the double-manufacturer-fix, because large parts of the plugin
were dependent on the string structure.
- Fix display of printer names, it should print the manufacturer
only once.
- Adapt all usages of the loadDescription function and variables
storing its return value.
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@13433 594d385d-05f5-0310-b6e9-bd551577e9d8
array instead of a string which is parsed over and over again.
This was neccessary to fix problems that occured after applying
the double-manufacturer-fix, because large parts of the plugin
were dependent on the string structure.
- Fix display of printer names, it should print the manufacturer
only once.
- Adapt all usages of the loadDescription function and variables
storing its return value.
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@13433 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc b/gosa-plugins/goto/admin/systems/goto/class_printGeneric.inc
index fdd8f3809f08d6003fce63b8f9241902326b2ffd..f199a7b393babe01da4a0f46038448e9e7240381 100644 (file)
if((!file_exists($path.$this->gotoPrinterPPD))){
$smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD)."</b>");
}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/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc b/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc
index fe72164d2ea787168b9528d62d5b275d3fec9439..db3e50c60c90f55c7887a7cc7c35fae716af36ae 100644 (file)
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]){
/* 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/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc b/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc
index e2875f57ab05907fd1f8bc1286d9422d5c97f52c..e82e18597c03db6dba7cbf59903c0bf1258c9668 100644 (file)
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;
}
}
}
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);
$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 */
/* 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;
}
}
}
{
$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/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc b/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc
index 546ac7d8b83064fc58c53f2242dc70aefda2b4cf..e0dcd1c939cb9c100783fbd70c7abdd3ead78117 100644 (file)
$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;
}
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;'")
));
}
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));
}
$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;'")
));