Main Page · Namespace List · Alphabetical List · Class List · File List · Namespace Members · Class Members · File Members · Related Pages

printersetupdb.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2006 by Konrad Wilhelm Kleine
00003  *   konrad@plothe-kleine.de
00004  *
00005  *   This file contains the class implementation for the LinuxPrinterSetup
00006  *   Database (lpsdb). The database is a subclassed Qt QDomDocument with
00007  *   extended functionality to get information about manufacturers models
00008  *   and drivers.
00009  *   As the LinuxPrinterSetup project is splitted up into three different
00010  *   subprojects (PrinterDriverToXML, PrinterAutoSetup, PrinterManualSetup)
00011  *   but only one of it (PrinterDriverToXML) really writes to the Database,
00012  *   this library only contains methods to query the database read-only.
00013  *
00014  *   PLEASE NOTICE: If not stated otherwise, whenever we speak of 'printer
00015  *                  drivers' or simply 'drivers', we mean the PPD files
00016  *                  and not the actual drivers.
00017  *
00018  *   STATUS: File has been reviewed and commented
00019  *
00020  *   $Id: printersetupdb.cpp,v 1.7 2006/04/23 16:06:22 hbci Exp $
00021  *
00022  *   This program is free software; you can redistribute it and/or modify
00023  *   it under the terms of the GNU General Public License as published by
00024  *   the Free Software Foundation; either version 2 of the License, or
00025  *   (at your option) any later version.
00026  *
00027  *   This program is distributed in the hope that it will be useful,
00028  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00029  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00030  *   GNU General Public License for more details.
00031  *
00032  *   You should have received a copy of the GNU General Public License
00033  *   along with this program; if not, write to the Free Software Foundation,
00034  *   Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00035  ***************************************************************************/
00036 
00037 // Lib includes
00038 #include "printersetupdb.h"
00039 
00040 
00046 PrinterSetupDb::PrinterSetupDb(const QString & name)
00047     : QDomDocument(name)
00048 {
00049 }
00050 
00051 
00055 PrinterSetupDb::~PrinterSetupDb()
00056 {
00057 }
00058 
00059 
00063 QDomNodeList PrinterSetupDb::getManufacturers() const
00064 {
00065   QDomElement root = documentElement();
00066 
00067   return root.childNodes();
00068 }
00069 
00070 
00076 QDomNodeList PrinterSetupDb::getModels( const QString & manufacturer ) const
00077 {
00078   QDomNodeList manufacturerNodes= getManufacturers();
00079 
00080   QDomNodeList result;
00081 
00082   for (uint i = 0; i < manufacturerNodes.length(); i++)
00083   {
00084     QDomElement manufacturerEle = manufacturerNodes.item(i).toElement();
00085 
00086     if ( !manufacturerEle.isNull() )
00087     {
00088       if ( manufacturerEle.attribute("name").upper() == manufacturer.upper() )
00089       {
00090         result = manufacturerEle.childNodes();
00091         break;
00092       }
00093     }
00094   }
00095 
00096   return result;
00097 }
00098 
00099 
00106 QDomNodeList PrinterSetupDb::getDriversByModel( const QString & manufacturer,
00107                                                 const QString & model
00108                                               ) const
00109 {
00110   QDomNodeList modelNodes= getModels(manufacturer);
00111 
00112   QDomNodeList result;
00113 
00114   for (uint i = 0; i < modelNodes.length(); i++)
00115   {
00116     QDomElement modelElement = modelNodes.item(i).toElement();
00117 
00118     if (!modelElement.isNull())
00119     {
00120       if (modelElement.attribute("name").upper()== model.upper())
00121       {
00122         result = modelElement.childNodes();
00123         break;
00124       }
00125     }
00126   }
00127 
00128   return result;
00129 }
00130 
00131 
00138 QDomNodeList PrinterSetupDb::getDriversByProduct( const QString & manufacturer,
00139                                                   const QString & product
00140                                                 ) const
00141 {
00142   QDomNodeList modelNodes = getModels(manufacturer);
00143 
00144   QDomNodeList result;
00145 
00146   for ( uint i = 0; i < modelNodes.length(); i++ )
00147   {
00148     QDomElement modelElement = modelNodes.item(i).toElement();
00149 
00150     if ( !modelElement.isNull() )
00151     {
00152       if ( modelElement.attribute("product").upper() == product.upper() )
00153       {
00154         result = modelElement.childNodes();
00155         break;
00156       }
00157     }
00158   }
00159 
00160   return result;
00161 }
00162 
00163 
00173 QDomElement PrinterSetupDb::getDriverByModel( const QString & manufacturer,
00174                                               const QString & model,
00175                                               const QString & driver
00176                                             ) const
00177 {
00178   return getDriver( getDriversByModel(manufacturer, model), driver );
00179 }
00180 
00181 
00195 QDomElement PrinterSetupDb::getDriverByProduct( const QString & manufacturer,
00196                                                 const QString & product,
00197                                                 const QString & driver
00198                                               ) const
00199 {
00200   return getDriver( getDriversByProduct(manufacturer, product), driver );
00201 }
00202 
00203 
00209 bool PrinterSetupDb::manufacturerExists( const QString & manufacturer ) const
00210 {
00211   return ! getManufacturer(manufacturer).isNull();
00212 }
00213 
00214 
00220 QDomElement PrinterSetupDb::getManufacturer( const QString & manufacturer ) const
00221 {
00222   QDomNodeList manufacturerNodes = getManufacturers();
00223 
00224   QDomElement result = QDomElement();
00225 
00226   for ( uint i = 0; i < manufacturerNodes.length(); i++ )
00227   {
00228     QDomElement manufacturerElement = manufacturerNodes.item(i).toElement();
00229 
00230     if ( manufacturerElement.attribute("name").upper() == manufacturer.upper() )
00231     {
00232       result = manufacturerElement;
00233       break;
00234     }
00235   }
00236 
00237   return result;
00238 }
00239 
00240 
00248 QDomElement PrinterSetupDb::getModel( const QString & manufacturer,
00249                                       const QString & model,
00250                                       const QString & product
00251                                     ) const
00252 {
00253   QDomNodeList modelNodes = getModels(manufacturer);
00254 
00255   QDomElement result;
00256 
00257   for ( uint i = 0; i < modelNodes.length(); i++ )
00258   {
00259     QDomElement modelElement = modelNodes.item(i).toElement();
00260 
00261     if ( model != "" && product != "" )
00262     {
00263       if (  modelElement.attribute("name").upper() == model.upper()       &&
00264             modelElement.attribute("product").upper() == product.upper()
00265          )
00266       {
00267         result = modelElement;
00268         break;
00269       }
00270     }
00271     else
00272     {
00273       if (  modelElement.attribute("name").upper() == model.upper()       ||
00274             modelElement.attribute("product").upper() == product.upper()
00275         )
00276       {
00277         result = modelElement;
00278         break;
00279       }
00280     }
00281   }
00282 
00283   return result;
00284 }
00285 
00286 
00292 QDomNodeList PrinterSetupDb::getDrivers( const QString & name ) const
00293 {
00294   QDomNodeList modelNodes = elementsByTagName("Model");
00295 
00296   QDomNodeList result;
00297 
00298   for ( uint i = 0; i < modelNodes.length(); i++ )
00299   {
00300     QDomElement modelElement = modelNodes.item(i).toElement();
00301 
00302     QString modelName = name.upper();
00303 
00304     if (  modelElement.attribute("name").upper() ==modelName      ||
00305           modelElement.attribute("product").upper() == modelName
00306        )
00307     {
00308       result = modelElement.childNodes();
00309       break;
00310     }
00311   }
00312 
00313   return result;
00314 }
00315 
00316 
00327 QDomElement PrinterSetupDb::getDriver(  const QDomNodeList & driverNodes,
00328                                         const QString & driver
00329                                      ) const
00330 {
00331   QDomElement result;
00332 
00333   for ( uint i = 0; i < driverNodes.length(); i++ )
00334   {
00335     QDomElement driverEle = driverNodes.item(i).toElement();
00336 
00337     if ( !driverEle.isNull() )
00338     {
00339       if ( driverEle.attribute("nickName").upper() == driver.upper() )
00340       {
00341         result = driverEle;
00342         break;
00343       }
00344     }
00345   }
00346 
00347   return result;
00348 }


To get more information, please visit our project site hosted at SourceForge.net Logo
To support this project, please click on this image: Support This Project

Copyright © 2005-2006 Linux Printer Setup Documentation generated by Doxygen 1.4.4 LPS 1.0 (Disclaimer)