Diffstat (limited to 'libopie2/opienet/omanufacturerdb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/omanufacturerdb.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp index b93b752..209ec94 100644 --- a/libopie2/opienet/omanufacturerdb.cpp +++ b/libopie2/opienet/omanufacturerdb.cpp | |||
@@ -1,135 +1,142 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "omanufacturerdb.h" | 31 | #include "omanufacturerdb.h" |
32 | 32 | ||
33 | #define OPIE_IMPROVE_GUI_LATENCY 1 | 33 | #define OPIE_IMPROVE_GUI_LATENCY 1 |
34 | 34 | ||
35 | /* OPIE */ | 35 | /* OPIE */ |
36 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
37 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 37 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
38 | #include <qpe/global.h> | 38 | #include <qpe/global.h> |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | #include <qapplication.h> | 42 | #include <qapplication.h> |
43 | #include <qfile.h> | 43 | #include <qfile.h> |
44 | #include <qtextstream.h> | 44 | #include <qtextstream.h> |
45 | 45 | ||
46 | using namespace Opie::Core; | ||
47 | namespace Opie { | ||
48 | namespace Net { | ||
49 | |||
46 | OManufacturerDB* OManufacturerDB::_instance = 0; | 50 | OManufacturerDB* OManufacturerDB::_instance = 0; |
47 | 51 | ||
48 | OManufacturerDB* OManufacturerDB::instance() | 52 | OManufacturerDB* OManufacturerDB::instance() |
49 | { | 53 | { |
50 | if ( !OManufacturerDB::_instance ) | 54 | if ( !OManufacturerDB::_instance ) |
51 | { | 55 | { |
52 | odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; | 56 | odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; |
53 | _instance = new OManufacturerDB(); | 57 | _instance = new OManufacturerDB(); |
54 | } | 58 | } |
55 | return _instance; | 59 | return _instance; |
56 | } | 60 | } |
57 | 61 | ||
58 | 62 | ||
59 | OManufacturerDB::OManufacturerDB() | 63 | OManufacturerDB::OManufacturerDB() |
60 | { | 64 | { |
61 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 65 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
62 | Global::statusMessage( "Reading Manufacturers..." ); | 66 | Global::statusMessage( "Reading Manufacturers..." ); |
63 | #endif | 67 | #endif |
64 | QString filename( "/etc/manufacturers" ); | 68 | QString filename( "/etc/manufacturers" ); |
65 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 69 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
66 | if ( !QFile::exists( filename ) ) | 70 | if ( !QFile::exists( filename ) ) |
67 | { | 71 | { |
68 | filename = "/opt/QtPalmtop/etc/manufacturers"; | 72 | filename = "/opt/QtPalmtop/etc/manufacturers"; |
69 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 73 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
70 | if ( !QFile::exists( filename ) ) | 74 | if ( !QFile::exists( filename ) ) |
71 | { | 75 | { |
72 | filename = "/usr/share/wellenreiter/manufacturers"; | 76 | filename = "/usr/share/wellenreiter/manufacturers"; |
73 | odebug << "OManufacturerDB: trying to read " << filename << oendl; | 77 | odebug << "OManufacturerDB: trying to read " << filename << oendl; |
74 | } | 78 | } |
75 | } | 79 | } |
76 | 80 | ||
77 | QFile file( filename ); | 81 | QFile file( filename ); |
78 | bool hasFile = file.open( IO_ReadOnly ); | 82 | bool hasFile = file.open( IO_ReadOnly ); |
79 | if (!hasFile) | 83 | if (!hasFile) |
80 | { | 84 | { |
81 | owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; | 85 | owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; |
82 | } | 86 | } |
83 | else | 87 | else |
84 | { | 88 | { |
85 | odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; | 89 | odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; |
86 | QTextStream s( &file ); | 90 | QTextStream s( &file ); |
87 | QString addr; | 91 | QString addr; |
88 | QString manu; | 92 | QString manu; |
89 | QString extManu; | 93 | QString extManu; |
90 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 94 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
91 | int counter = 0; | 95 | int counter = 0; |
92 | #endif | 96 | #endif |
93 | while (!s.atEnd()) | 97 | while (!s.atEnd()) |
94 | { | 98 | { |
95 | s >> addr; | 99 | s >> addr; |
96 | s >> manu; | 100 | s >> manu; |
97 | s >> extManu; | 101 | s >> extManu; |
98 | 102 | ||
99 | manufacturers.insert( addr, manu ); | 103 | manufacturers.insert( addr, manu ); |
100 | manufacturersExt.insert( addr, extManu ); | 104 | manufacturersExt.insert( addr, extManu ); |
101 | // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; | 105 | // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; |
102 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 106 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
103 | counter++; | 107 | counter++; |
104 | if ( counter == 50 ) | 108 | if ( counter == 50 ) |
105 | { | 109 | { |
106 | qApp->processEvents(); | 110 | qApp->processEvents(); |
107 | counter = 0; | 111 | counter = 0; |
108 | } | 112 | } |
109 | #endif | 113 | #endif |
110 | } | 114 | } |
111 | odebug << "OManufacturerDB: manufacturer list completed." << oendl; | 115 | odebug << "OManufacturerDB: manufacturer list completed." << oendl; |
112 | #ifdef OPIE_IMPROVE_GUI_LATENCY | 116 | #ifdef OPIE_IMPROVE_GUI_LATENCY |
113 | Global::statusMessage( "Manufacturers Complete..." ); | 117 | Global::statusMessage( "Manufacturers Complete..." ); |
114 | #endif | 118 | #endif |
115 | } | 119 | } |
116 | } | 120 | } |
117 | 121 | ||
118 | 122 | ||
119 | OManufacturerDB::~OManufacturerDB() | 123 | OManufacturerDB::~OManufacturerDB() |
120 | { | 124 | { |
121 | } | 125 | } |
122 | 126 | ||
123 | 127 | ||
124 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const | 128 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const |
125 | { | 129 | { |
126 | return manufacturers[macaddr.upper().left(8)]; | 130 | return manufacturers[macaddr.upper().left(8)]; |
127 | } | 131 | } |
128 | 132 | ||
129 | 133 | ||
130 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const | 134 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const |
131 | { | 135 | { |
132 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); | 136 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); |
133 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; | 137 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; |
134 | } | 138 | } |
135 | 139 | ||
140 | } | ||
141 | } | ||
142 | |||