-rw-r--r-- | libopie2/opiecore/oapplication.h | 2 | ||||
-rw-r--r-- | libopie2/opiecore/oconfig.h | 143 | ||||
-rw-r--r-- | libopie2/opienet/omanufacturerdb.cpp | 6 |
3 files changed, 64 insertions, 87 deletions
diff --git a/libopie2/opiecore/oapplication.h b/libopie2/opiecore/oapplication.h index 1bd34e2..6bc2b1c 100644 --- a/libopie2/opiecore/oapplication.h +++ b/libopie2/opiecore/oapplication.h | |||
@@ -43,49 +43,49 @@ class OApplication: public QPEApplication | |||
43 | Q_OBJECT | 43 | Q_OBJECT |
44 | 44 | ||
45 | public: | 45 | public: |
46 | /** | 46 | /** |
47 | * Constructor. Parses command-line arguments and sets the window caption. | 47 | * Constructor. Parses command-line arguments and sets the window caption. |
48 | * | 48 | * |
49 | * @param rAppName application name. Will be used for finding the | 49 | * @param rAppName application name. Will be used for finding the |
50 | * associated message, icon and configuration files | 50 | * associated message, icon and configuration files |
51 | * | 51 | * |
52 | */ | 52 | */ |
53 | OApplication( int& argc, char** argv, const QCString& rAppName ); | 53 | OApplication( int& argc, char** argv, const QCString& rAppName ); |
54 | /** | 54 | /** |
55 | * Destructor. Destroys the application object and its children. | 55 | * Destructor. Destroys the application object and its children. |
56 | */ | 56 | */ |
57 | virtual ~OApplication(); | 57 | virtual ~OApplication(); |
58 | /** | 58 | /** |
59 | * @returns the process-wide application object | 59 | * @returns the process-wide application object |
60 | * | 60 | * |
61 | * This is similar to the global @ref QApplication pointer qApp. It | 61 | * This is similar to the global @ref QApplication pointer qApp. It |
62 | * allows access to the single global OApplication object, since | 62 | * allows access to the single global OApplication object, since |
63 | * more than one cannot be created in the same application. It | 63 | * more than one cannot be created in the same application. It |
64 | * saves you the trouble of having to pass the pointer explicitly | 64 | * saves you the trouble of having to pass the pointer explicitly |
65 | * to every function that may require it. | 65 | * to every function that may require it. |
66 | */ | 66 | */ |
67 | static const OApplication* oApplication() { return _instance; }; | 67 | static OApplication* oApplication() { return _instance; }; |
68 | /** | 68 | /** |
69 | * Returns the application name as given during creation. | 69 | * Returns the application name as given during creation. |
70 | * | 70 | * |
71 | * @returns a reference to the application name | 71 | * @returns a reference to the application name |
72 | */ | 72 | */ |
73 | const QCString& appName() const { return _appname; }; | 73 | const QCString& appName() const { return _appname; }; |
74 | /** | 74 | /** |
75 | * @returns the application session config object. | 75 | * @returns the application session config object. |
76 | * | 76 | * |
77 | * @see OConfig | 77 | * @see OConfig |
78 | */ | 78 | */ |
79 | OConfig* config(); | 79 | OConfig* config(); |
80 | /** | 80 | /** |
81 | * Shows the main @a widget and sets the name of the application as window caption. | 81 | * Shows the main @a widget and sets the name of the application as window caption. |
82 | */ | 82 | */ |
83 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); | 83 | virtual void showMainWidget( QWidget* widget, bool nomax = false ); |
84 | /** | 84 | /** |
85 | * Set the application title. The application title will be concatenated | 85 | * Set the application title. The application title will be concatenated |
86 | * to the application name given in the constructor. | 86 | * to the application name given in the constructor. |
87 | * | 87 | * |
88 | * @param title the title. If not given, resets caption to appname | 88 | * @param title the title. If not given, resets caption to appname |
89 | */ | 89 | */ |
90 | virtual void setTitle( const QString& title = QString::null ) const; | 90 | virtual void setTitle( const QString& title = QString::null ) const; |
91 | 91 | ||
diff --git a/libopie2/opiecore/oconfig.h b/libopie2/opiecore/oconfig.h index afe14b1..444d280 100644 --- a/libopie2/opiecore/oconfig.h +++ b/libopie2/opiecore/oconfig.h | |||
@@ -12,156 +12,129 @@ | |||
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | */ | 30 | */ |
31 | 31 | ||
32 | #ifndef OCONFIG_H | 32 | #ifndef OCONFIG_H |
33 | #define OCONFIG_H | 33 | #define OCONFIG_H |
34 | 34 | ||
35 | //FIXME: Implement for X11 or reuse libqpe/Config there also? | 35 | //FIXME: Implement for X11 or reuse libqpe/Config there also? |
36 | //FIXME: Or rather use QSettings also for libqpe? | ||
36 | 37 | ||
37 | #include <qpe/config.h> | 38 | #include <qpe/config.h> |
38 | 39 | ||
39 | class QColor; | 40 | class QColor; |
40 | class QFont; | 41 | class QFont; |
41 | 42 | ||
42 | /** | 43 | /** |
43 | * A Configuration class based on the Qtopia @ref Config class | 44 | * A Configuration class based on the Qtopia @ref Config class |
44 | * featuring additional handling of color and font entries | 45 | * featuring additional handling of color and font entries |
45 | */ | 46 | */ |
46 | 47 | ||
47 | class OConfig : public Config | 48 | class OConfig : public Config |
48 | { | 49 | { |
49 | public: | 50 | public: |
50 | 51 | /** | |
51 | /** | 52 | * Constructs a OConfig object with a @a name. |
52 | * Constructs a OConfig object. | 53 | */ |
53 | * | ||
54 | * @param name A file to parse. | ||
55 | */ | ||
56 | OConfig( const QString &name, Domain domain = User ); | 54 | OConfig( const QString &name, Domain domain = User ); |
57 | 55 | /** | |
58 | /** | 56 | * Destructs the OConfig object. |
59 | * Destructs the OConfig object. | 57 | * |
60 | * | 58 | * Writes back any dirty configuration entries, and destroys |
61 | * Writes back any dirty configuration entries, and destroys | 59 | * dynamically created objects. |
62 | * dynamically created objects. | 60 | */ |
63 | */ | ||
64 | virtual ~OConfig(); | 61 | virtual ~OConfig(); |
65 | 62 | /** | |
66 | /** | 63 | * @returns the name of the current group. |
67 | * Returns the name of the group in which we are | 64 | * The current group is used for searching keys and accessing entries. |
68 | * searching for keys and from which we are retrieving entries. | 65 | */ |
69 | * | ||
70 | * @return The current group. | ||
71 | */ | ||
72 | const QString& group() { return git.key(); }; | 66 | const QString& group() { return git.key(); }; |
73 | 67 | /** | |
74 | /** | 68 | * @returns a @ref QColor entry or a @a default value if the key is not found. |
75 | * Reads a @ref QColor entry. | 69 | */ |
76 | * | ||
77 | * Read the value of an entry specified by @p pKey in the current group | ||
78 | * and interpret it as a color. | ||
79 | * | ||
80 | * @param pKey The key to search for. | ||
81 | * @param pDefault A default value (null QColor by default) returned if the | ||
82 | * key was not found or if the value cannot be interpreted. | ||
83 | * @return The value for this key. | ||
84 | */ | ||
85 | QColor readColorEntry( const QString& key, const QColor* pDefault ) const; | 70 | QColor readColorEntry( const QString& key, const QColor* pDefault ) const; |
86 | 71 | /** | |
87 | /** | 72 | * @returns a @ref QFont value or a @a default value if the key is not found. |
88 | * Reads a @ref QFont value. | 73 | */ |
89 | * | ||
90 | * Read the value of an entry specified by @p pKey in the current group | ||
91 | * and interpret it as a font object. | ||
92 | * | ||
93 | * @param pKey The key to search for. | ||
94 | * @param pDefault A default value (null QFont by default) returned if the | ||
95 | * key was not found or if the read value cannot be interpreted. | ||
96 | * @return The value for this key. | ||
97 | */ | ||
98 | QFont readFontEntry( const QString& key, const QFont* pDefault ) const; | 74 | QFont readFontEntry( const QString& key, const QFont* pDefault ) const; |
99 | |||
100 | }; | 75 | }; |
101 | 76 | ||
102 | /** | 77 | /** |
103 | * Helper class to facilitate working with @ref OConfig / @ref OSimpleConfig | 78 | * @brief Helper class for easier use of OConfig groups. |
104 | * groups. | 79 | * |
105 | * | 80 | * Careful programmers always set the group of a |
106 | * Careful programmers always set the group of a | 81 | * @ref OConfig object to the group they want to read from |
107 | * @ref OConfig object to the group they want to read from | 82 | * and set it back to the old one of afterwards. This is usually |
108 | * and set it back to the old one of afterwards. This is usually | 83 | * written as: |
109 | * written as: | 84 | * <pre> |
110 | * <pre> | 85 | * |
111 | * | 86 | * QString oldgroup config()->group(); |
112 | * QString oldgroup config()->group(); | 87 | * config()->setGroup( "TheGroupThatIWant" ); |
113 | * config()->setGroup( "TheGroupThatIWant" ); | 88 | * ... |
114 | * ... | 89 | * config()->writeEntry( "Blah", "Blubb" ); |
115 | * config()->writeEntry( "Blah", "Blubb" ); | 90 | * |
116 | * | 91 | * config()->setGroup( oldgroup ); |
117 | * config()->setGroup( oldgroup ); | 92 | * </pre> |
118 | * </pre> | 93 | * |
119 | * | 94 | * In order to facilitate this task, you can use |
120 | * In order to facilitate this task, you can use | 95 | * OConfigGroupSaver. Simply construct such an object ON THE STACK |
121 | * OConfigGroupSaver. Simply construct such an object ON THE STACK | 96 | * when you want to switch to a new group. Then, when the object goes |
122 | * when you want to switch to a new group. Then, when the object goes | 97 | * out of scope, the group will automatically be restored. If you |
123 | * out of scope, the group will automatically be restored. If you | 98 | * want to use several different groups within a function or method, |
124 | * want to use several different groups within a function or method, | 99 | * you can still use OConfigGroupSaver: Simply enclose all work with |
125 | * you can still use OConfigGroupSaver: Simply enclose all work with | 100 | * one group (including the creation of the OConfigGroupSaver object) |
126 | * one group (including the creation of the OConfigGroupSaver object) | 101 | * in one block. |
127 | * in one block. | 102 | * |
128 | * | 103 | * @author Matthias Kalle Dalheimer <Kalle@kde.org> |
129 | * @author Matthias Kalle Dalheimer <Kalle@kde.org> | 104 | * @version $Id$ |
130 | * @version $Id$ | 105 | * @see OConfig |
131 | * @see OConfig | 106 | */ |
132 | * @short Helper class for easier use of OConfig groups | ||
133 | */ | ||
134 | 107 | ||
135 | class OConfigGroupSaver | 108 | class OConfigGroupSaver |
136 | { | 109 | { |
137 | public: | 110 | public: |
138 | /** | 111 | /** |
139 | * Constructor. You pass a pointer to the OConfigBase-derived | 112 | * Constructor. |
140 | * object you want to work with and a string indicating the _new_ | 113 | * Create the object giving a @config object and a @a group to become |
141 | * group. | 114 | * the current group. |
142 | * @param config The OConfig-derived object this | 115 | */ |
143 | * OConfigGroupSaver works on. | ||
144 | * @param group The new group that the config object should switch to. | ||
145 | */ | ||
146 | OConfigGroupSaver( OConfig* config, QString group ) :_config(config), _oldgroup(config->group() ) | 116 | OConfigGroupSaver( OConfig* config, QString group ) :_config(config), _oldgroup(config->group() ) |
147 | { _config->setGroup( group ); } | 117 | { _config->setGroup( group ); } |
148 | 118 | ||
149 | OConfigGroupSaver( OConfig* config, const char *group ) :_config(config), _oldgroup(config->group()) | 119 | OConfigGroupSaver( OConfig* config, const char *group ) :_config(config), _oldgroup(config->group()) |
150 | { _config->setGroup( group ); } | 120 | { _config->setGroup( group ); } |
151 | 121 | ||
152 | OConfigGroupSaver( OConfig* config, const QCString &group ) : _config(config), _oldgroup(config->group()) | 122 | OConfigGroupSaver( OConfig* config, const QCString &group ) : _config(config), _oldgroup(config->group()) |
153 | { _config->setGroup( group ); } | 123 | { _config->setGroup( group ); } |
154 | 124 | /** | |
125 | * Destructor. | ||
126 | * Restores the last current group. | ||
127 | */ | ||
155 | ~OConfigGroupSaver() { _config->setGroup( _oldgroup ); } | 128 | ~OConfigGroupSaver() { _config->setGroup( _oldgroup ); } |
156 | 129 | ||
157 | OConfig* config() { return _config; }; | 130 | OConfig* config() { return _config; }; |
158 | 131 | ||
159 | private: | 132 | private: |
160 | OConfig* _config; | 133 | OConfig* _config; |
161 | QString _oldgroup; | 134 | QString _oldgroup; |
162 | 135 | ||
163 | OConfigGroupSaver( const OConfigGroupSaver& ); | 136 | OConfigGroupSaver( const OConfigGroupSaver& ); |
164 | OConfigGroupSaver& operator=( const OConfigGroupSaver& ); | 137 | OConfigGroupSaver& operator=( const OConfigGroupSaver& ); |
165 | }; | 138 | }; |
166 | 139 | ||
167 | #endif // OCONFIG_H | 140 | #endif // OCONFIG_H |
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp index c185fc5..c3c213c 100644 --- a/libopie2/opienet/omanufacturerdb.cpp +++ b/libopie2/opienet/omanufacturerdb.cpp | |||
@@ -1,42 +1,42 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Opie Environment. | 4 | ** This file is part of Opie Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "omanufacturerdb.h" | 16 | #include "omanufacturerdb.h" |
17 | 17 | ||
18 | // Qt | 18 | /* QT */ |
19 | #include <qstring.h> | 19 | #include <qstring.h> |
20 | #include <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qtextstream.h> | 21 | #include <qtextstream.h> |
22 | 22 | ||
23 | OManufacturerDB* OManufacturerDB::_instance = 0; | 23 | OManufacturerDB* OManufacturerDB::_instance = 0; |
24 | 24 | ||
25 | OManufacturerDB* OManufacturerDB::instance() | 25 | OManufacturerDB* OManufacturerDB::instance() |
26 | { | 26 | { |
27 | if ( !OManufacturerDB::_instance ) | 27 | if ( !OManufacturerDB::_instance ) |
28 | { | 28 | { |
29 | qDebug( "OManufacturerDB::instance(): creating OManufacturerDB..." ); | 29 | qDebug( "OManufacturerDB::instance(): creating OManufacturerDB..." ); |
30 | _instance = new OManufacturerDB(); | 30 | _instance = new OManufacturerDB(); |
31 | } | 31 | } |
32 | return _instance; | 32 | return _instance; |
33 | } | 33 | } |
34 | 34 | ||
35 | 35 | ||
36 | OManufacturerDB::OManufacturerDB() | 36 | OManufacturerDB::OManufacturerDB() |
37 | { | 37 | { |
38 | QString filename( "/etc/manufacturers" ); | 38 | QString filename( "/etc/manufacturers" ); |
39 | qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename ); | 39 | qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename ); |
40 | if ( !QFile::exists( filename ) ) | 40 | if ( !QFile::exists( filename ) ) |
41 | { | 41 | { |
42 | filename = "/opt/QtPalmtop/etc/manufacturers"; | 42 | filename = "/opt/QtPalmtop/etc/manufacturers"; |
@@ -60,54 +60,58 @@ OManufacturerDB::OManufacturerDB() | |||
60 | QTextStream s( &file ); | 60 | QTextStream s( &file ); |
61 | QString addr; | 61 | QString addr; |
62 | QString manu; | 62 | QString manu; |
63 | QString extManu; | 63 | QString extManu; |
64 | while (!s.atEnd()) | 64 | while (!s.atEnd()) |
65 | { | 65 | { |
66 | s >> addr; | 66 | s >> addr; |
67 | if ( !addr ) // read nothing!? | 67 | if ( !addr ) // read nothing!? |
68 | { | 68 | { |
69 | continue; | 69 | continue; |
70 | } | 70 | } |
71 | else | 71 | else |
72 | if ( addr[0] == '#' ) | 72 | if ( addr[0] == '#' ) |
73 | { | 73 | { |
74 | continue; | 74 | continue; |
75 | } | 75 | } |
76 | s.skipWhiteSpace(); | 76 | s.skipWhiteSpace(); |
77 | s >> manu; | 77 | s >> manu; |
78 | s.skipWhiteSpace(); | 78 | s.skipWhiteSpace(); |
79 | s >> extManu; | 79 | s >> extManu; |
80 | if ( extManu[0] == '#' ) // we have an extended manufacturer | 80 | if ( extManu[0] == '#' ) // we have an extended manufacturer |
81 | { | 81 | { |
82 | s.skipWhiteSpace(); | 82 | s.skipWhiteSpace(); |
83 | extManu = s.readLine(); | 83 | extManu = s.readLine(); |
84 | #ifdef DEBUG | ||
84 | qDebug( "OManufacturerDB: read '%s' as extended manufacturer string", (const char*) extManu ); | 85 | qDebug( "OManufacturerDB: read '%s' as extended manufacturer string", (const char*) extManu ); |
86 | #endif | ||
85 | manufacturersExt.insert( addr, extManu ); | 87 | manufacturersExt.insert( addr, extManu ); |
86 | } | 88 | } |
87 | else | 89 | else |
88 | s.readLine(); | 90 | s.readLine(); |
91 | #ifdef DEBUG | ||
89 | qDebug( "ManufacturerDB: read tuple %s, %s", (const char*) addr, (const char*) manu ); | 92 | qDebug( "ManufacturerDB: read tuple %s, %s", (const char*) addr, (const char*) manu ); |
93 | #endif | ||
90 | manufacturers.insert( addr, manu ); | 94 | manufacturers.insert( addr, manu ); |
91 | 95 | ||
92 | } | 96 | } |
93 | } | 97 | } |
94 | 98 | ||
95 | } | 99 | } |
96 | 100 | ||
97 | 101 | ||
98 | OManufacturerDB::~OManufacturerDB() | 102 | OManufacturerDB::~OManufacturerDB() |
99 | { | 103 | { |
100 | } | 104 | } |
101 | 105 | ||
102 | 106 | ||
103 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const | 107 | const QString& OManufacturerDB::lookup( const QString& macaddr ) const |
104 | { | 108 | { |
105 | return manufacturers[macaddr.upper().left(8)]; | 109 | return manufacturers[macaddr.upper().left(8)]; |
106 | } | 110 | } |
107 | 111 | ||
108 | 112 | ||
109 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const | 113 | const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const |
110 | { | 114 | { |
111 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); | 115 | QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); |
112 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; | 116 | return it == manufacturersExt.end() ? lookup( macaddr ) : *it; |
113 | } | 117 | } |