00001 /* 00002 This file is part of the Opie Project 00003 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 00004 .=l. 00005 .>+-= 00006 _;:, .> :=|. This program is free software; you can 00007 .> <`_, > . <= redistribute it and/or modify it under 00008 :`=1 )Y*s>-.-- : the terms of the GNU Library General Public 00009 .="- .-=="i, .._ License as published by the Free Software 00010 - . .-<_> .<> Foundation; version 2 of the License. 00011 ._= =} : 00012 .%`+i> _;_. 00013 .i_,=:_. -<s. This program is distributed in the hope that 00014 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 00015 : .. .:, . . . without even the implied warranty of 00016 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 00017 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 00018 ..}^=.= = ; Library General Public License for more 00019 ++= -. .` .: details. 00020 : = ...= . :.=- 00021 -. .:....=;==+<; You should have received a copy of the GNU 00022 -_. . . )=. = Library General Public License along with 00023 -- :-=` this library; see the file COPYING.LIB. 00024 If not, write to the Free Software Foundation, 00025 Inc., 59 Temple Place - Suite 330, 00026 Boston, MA 02111-1307, USA. 00027 */ 00028 00029 #include "omanufacturerdb.h" 00030 00031 /* OPIE */ 00032 #include <opie2/odebug.h> 00033 #include <qpe/qpeapplication.h> 00034 #ifdef OPIE_IMPROVE_GUI_LATENCY 00035 #include <qpe/global.h> 00036 #endif 00037 00038 00039 00040 /* QT */ 00041 #include <qapplication.h> 00042 #include <qfile.h> 00043 #include <qtextstream.h> 00044 00045 using namespace Opie::Core; 00046 namespace Opie { 00047 namespace Net { 00048 00049 OManufacturerDB* OManufacturerDB::_instance = 0; 00050 00051 OManufacturerDB* OManufacturerDB::instance() 00052 { 00053 if ( !OManufacturerDB::_instance ) 00054 { 00055 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; 00056 _instance = new OManufacturerDB(); 00057 } 00058 return _instance; 00059 } 00060 00061 00062 OManufacturerDB::OManufacturerDB() 00063 { 00064 if ( qApp ) Global::statusMessage( "Reading Manufacturers..." ); 00065 QString filename( "/etc/manufacturers" ); 00066 odebug << "OManufacturerDB: trying to read " << filename << oendl; 00067 if ( !QFile::exists( filename ) ) 00068 { 00069 filename = QPEApplication::qpeDir()+"etc/manufacturers"; 00070 odebug << "OManufacturerDB: trying to read " << filename << oendl; 00071 if ( !QFile::exists( filename ) ) 00072 { 00073 filename = "/usr/share/wellenreiter/manufacturers"; 00074 odebug << "OManufacturerDB: trying to read " << filename << oendl; 00075 } 00076 } 00077 00078 QFile file( filename ); 00079 bool hasFile = file.open( IO_ReadOnly ); 00080 if (!hasFile) 00081 { 00082 owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; 00083 } 00084 else 00085 { 00086 odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; 00087 QTextStream s( &file ); 00088 QString addr; 00089 QString manu; 00090 QString extManu; 00091 int counter = 0; 00092 00093 while (!s.atEnd()) 00094 { 00095 s >> addr; 00096 s >> manu; 00097 s >> extManu; 00098 00099 manufacturers.insert( addr, manu ); 00100 manufacturersExt.insert( addr, extManu ); 00101 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; 00102 counter++; 00103 if ( counter == 50 ) 00104 { 00105 if ( qApp ) qApp->processEvents(); 00106 counter = 0; 00107 } 00108 } 00109 odebug << "OManufacturerDB: manufacturer list completed." << oendl; 00110 if ( qApp ) Global::statusMessage( "Manufacturers Complete..." ); 00111 } 00112 } 00113 00114 00115 OManufacturerDB::~OManufacturerDB() 00116 { 00117 } 00118 00119 00120 const QString& OManufacturerDB::lookup( const QString& macaddr ) const 00121 { 00122 return manufacturers[macaddr.upper().left(8)]; 00123 } 00124 00125 00126 const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const 00127 { 00128 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); 00129 return it == manufacturersExt.end() ? lookup( macaddr ) : *it; 00130 } 00131 00132 } 00133 } 00134
1.4.2