00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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 }