summaryrefslogtreecommitdiff
path: root/libopie2/opiecore
authormickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
committer mickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
commit11304d02942e9fa493e4e80943a828f9c65f6772 (patch) (unidiff)
treea0223c10c067e1afc70d15c2b82be3f3c15e41ae /libopie2/opiecore
parentb271d575fa05cf570a1a829136517761bd47e69b (diff)
downloadopie-11304d02942e9fa493e4e80943a828f9c65f6772.zip
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.gz
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.bz2
skeleton and the start of libopie2, please read README, ROADMAP and STATUS and comment...
Diffstat (limited to 'libopie2/opiecore') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/.cvsignore6
-rw-r--r--libopie2/opiecore/config.in6
-rw-r--r--libopie2/opiecore/oapplication.cpp110
-rw-r--r--libopie2/opiecore/oapplication.h114
-rw-r--r--libopie2/opiecore/oconfig.cpp201
-rw-r--r--libopie2/opiecore/oconfig.h167
-rw-r--r--libopie2/opiecore/odebug.cpp628
-rw-r--r--libopie2/opiecore/odebug.h474
-rw-r--r--libopie2/opiecore/oglobal.cpp36
-rw-r--r--libopie2/opiecore/oglobal.h48
-rw-r--r--libopie2/opiecore/oglobalsettings.cpp547
-rw-r--r--libopie2/opiecore/oglobalsettings.h368
-rw-r--r--libopie2/opiecore/opiecore.pro31
13 files changed, 2736 insertions, 0 deletions
diff --git a/libopie2/opiecore/.cvsignore b/libopie2/opiecore/.cvsignore
new file mode 100644
index 0000000..8f7300c
--- a/dev/null
+++ b/libopie2/opiecore/.cvsignore
@@ -0,0 +1,6 @@
1Makefile*
2moc*
3*moc
4*.o
5~*
6
diff --git a/libopie2/opiecore/config.in b/libopie2/opiecore/config.in
new file mode 100644
index 0000000..f4483a2
--- a/dev/null
+++ b/libopie2/opiecore/config.in
@@ -0,0 +1,6 @@
1 config LIBOPIE2CORE
2 boolean "libopie2core (application, configuration and debug related classes)"
3 default "n"
4 depends ( LIBQPE || LIBQPE-X11 )
5 comment "libopie2core needs a libqpe (yet)"
6 depends !( LIBQPE || LIBQPE-X11 )
diff --git a/libopie2/opiecore/oapplication.cpp b/libopie2/opiecore/oapplication.cpp
new file mode 100644
index 0000000..a0abcc2
--- a/dev/null
+++ b/libopie2/opiecore/oapplication.cpp
@@ -0,0 +1,110 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29*/
30
31#include <opie2/oapplication.h>
32#include <opie2/oconfig.h>
33
34OApplication* OApplication::_instance = 0;
35
36/**************************************************************************************************/
37/* OApplicationPrivate
38/**************************************************************************************************/
39
40class OApplicationPrivate
41{
42 public:
43 OApplicationPrivate() {};
44 ~OApplicationPrivate() {};
45};
46
47/**************************************************************************************************/
48/* OApplication
49/**************************************************************************************************/
50
51
52OApplication::OApplication( int& argc, char** argv, const QCString& rAppName )
53 :OApplicationBaseClass( argc, argv ),
54 _appname( rAppName ),
55 _config( 0 )
56{
57 init();
58}
59
60
61OApplication::~OApplication()
62{
63 delete d;
64 if ( _config )
65 delete _config;
66 OApplication::_instance = 0;
67 // after deconstruction of the one-and-only application object,
68 // the construction of another object is allowed
69}
70
71
72OConfig* OApplication::config()
73{
74 if ( not _config )
75 {
76 _config = new OConfig( _appname );
77 }
78 return _config;
79}
80
81
82void OApplication::init()
83{
84 d = new OApplicationPrivate();
85 if ( !OApplication::_instance )
86 {
87 OApplication::_instance = this;
88 }
89 else
90 {
91 qFatal( "OApplication: Can't create more than one OApplication object. Aborting." );
92 }
93}
94
95void OApplication::setMainWidget( QWidget* widget )
96{
97 showMainWidget( widget );
98}
99
100void OApplication::showMainWidget( QWidget* widget, bool nomax )
101{
102 #ifdef Q_WS_QWS
103 QPEApplication::showMainWidget( widget, nomax );
104 #else
105 QApplication::setMainWidget( widget );
106 widget->show();
107 #endif
108 widget->setCaption( _appname );
109
110}
diff --git a/libopie2/opiecore/oapplication.h b/libopie2/opiecore/oapplication.h
new file mode 100644
index 0000000..736e786
--- a/dev/null
+++ b/libopie2/opiecore/oapplication.h
@@ -0,0 +1,114 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29*/
30
31#ifndef OAPPLICATION_H
32#define OAPPLICATION_H
33
34#define oApp OApplication::oApplication()
35
36#ifdef QWS
37 #include <qpe/qpeapplication.h>
38 #define OApplicationBaseClass QPEApplication
39#else
40 #include <qapplication.h>
41 #define OApplicationBaseClass QApplication
42#endif
43
44class OApplicationPrivate;
45class OConfig;
46
47class OApplication: public OApplicationBaseClass
48{
49 public:
50
51 /**
52 * Constructor. Parses command-line arguments and sets the window caption.
53 *
54 * @param rAppName application name. Will be used for finding the
55 * associated message, icon and configuration files
56 *
57 */
58 OApplication( int& argc, char** argv, const QCString& rAppName );
59 /**
60 * Destructor. Destroys the application object and its children.
61 */
62 virtual ~OApplication();
63
64 /**
65 * Returns the current application object.
66 *
67 * This is similar to the global @ref QApplication pointer qApp. It
68 * allows access to the single global OApplication object, since
69 * more than one cannot be created in the same application. It
70 * saves you the trouble of having to pass the pointer explicitly
71 * to every function that may require it.
72 * @return the current application object
73 */
74 static const OApplication* oApplication() { return _instance; };
75
76 /**
77 * Returns the application name as given during creation.
78 *
79 * @return A reference to the application name
80 */
81 const QCString& appName() const { return _appname; };
82
83 /**
84 * Returns the application session config object.
85 *
86 * @return A pointer to the application's instance specific
87 * @ref OConfig object.
88 * @see OConfig
89 */
90 OConfig* config();
91
92 /**
93 * Sets the main widget - reimplemented to call showMainWidget()
94 * on Qt/Embedded.
95 */
96 virtual void setMainWidget( QWidget *mainWidget );
97
98 /**
99 * Shows the main widget - reimplemented to call setMainWidget()
100 * on platforms other than Qt/Embedded.
101 */
102 virtual void showMainWidget( QWidget* widget, bool nomax = false );
103
104 protected:
105 void init();
106
107 private:
108 const QCString _appname;
109 static OApplication* _instance;
110 OConfig* _config;
111 OApplicationPrivate* d;
112};
113
114#endif // OAPPLICATION_H
diff --git a/libopie2/opiecore/oconfig.cpp b/libopie2/opiecore/oconfig.cpp
new file mode 100644
index 0000000..40edbc7
--- a/dev/null
+++ b/libopie2/opiecore/oconfig.cpp
@@ -0,0 +1,201 @@
1/*
2                 This file is part of the Opie Project
3
4 (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Inspired by the config classes from the KDE Project which are
6 =. (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org>
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30*/
31
32/* QT */
33
34#include <qfont.h>
35#include <qcolor.h>
36
37/* OPIE */
38
39#include <opie2/oconfig.h>
40
41OConfig::OConfig( const QString &name, Domain domain )
42 :Config( name, domain )
43{
44}
45
46OConfig::~OConfig()
47{
48}
49
50QColor OConfig::readColorEntry( const QString& key, const QColor* pDefault ) const
51{
52 QColor aRetColor;
53 int nRed = 0, nGreen = 0, nBlue = 0;
54
55 QString aValue = readEntry( key );
56 if( !aValue.isEmpty() )
57 {
58 if ( aValue.at(0) == '#' )
59 {
60 aRetColor.setNamedColor(aValue);
61 }
62 else
63 {
64 bool bOK;
65
66 // find first part (red)
67 int nIndex = aValue.find( ',' );
68
69 if( nIndex == -1 )
70 {
71 // return a sensible default -- Bernd
72 if( pDefault )
73 aRetColor = *pDefault;
74 return aRetColor;
75 }
76
77 nRed = aValue.left( nIndex ).toInt( &bOK );
78
79 // find second part (green)
80 int nOldIndex = nIndex;
81 nIndex = aValue.find( ',', nOldIndex+1 );
82
83 if( nIndex == -1 )
84 {
85 // return a sensible default -- Bernd
86 if( pDefault )
87 aRetColor = *pDefault;
88 return aRetColor;
89 }
90 nGreen = aValue.mid( nOldIndex+1,
91 nIndex-nOldIndex-1 ).toInt( &bOK );
92
93 // find third part (blue)
94 nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK );
95
96 aRetColor.setRgb( nRed, nGreen, nBlue );
97 }
98 }
99 else {
100
101 if( pDefault )
102 aRetColor = *pDefault;
103 }
104
105 return aRetColor;
106}
107
108// FIXME: The whole font handling has to be revised for Opie
109
110QFont OConfig::readFontEntry( const QString& key, const QFont* pDefault ) const
111{
112 /*
113 QFont aRetFont;
114
115 QString aValue = readEntry( key );
116 if( !aValue.isNull() ) {
117 if ( aValue.contains( ',' ) > 5 ) {
118 // KDE3 and upwards entry
119 if ( !aRetFont.fromString( aValue ) && pDefault )
120 aRetFont = *pDefault;
121 }
122 else {
123 // backward compatibility with older font formats
124 // ### remove KDE 3.1 ?
125 // find first part (font family)
126 int nIndex = aValue.find( ',' );
127 if( nIndex == -1 ){
128 if( pDefault )
129 aRetFont = *pDefault;
130 return aRetFont;
131 }
132 aRetFont.setFamily( aValue.left( nIndex ) );
133
134 // find second part (point size)
135 int nOldIndex = nIndex;
136 nIndex = aValue.find( ',', nOldIndex+1 );
137 if( nIndex == -1 ){
138 if( pDefault )
139 aRetFont = *pDefault;
140 return aRetFont;
141 }
142
143 aRetFont.setPointSize( aValue.mid( nOldIndex+1,
144 nIndex-nOldIndex-1 ).toInt() );
145
146 // find third part (style hint)
147 nOldIndex = nIndex;
148 nIndex = aValue.find( ',', nOldIndex+1 );
149
150 if( nIndex == -1 ){
151 if( pDefault )
152 aRetFont = *pDefault;
153 return aRetFont;
154 }
155
156 aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() );
157
158 // find fourth part (char set)
159 nOldIndex = nIndex;
160 nIndex = aValue.find( ',', nOldIndex+1 );
161
162 if( nIndex == -1 ){
163 if( pDefault )
164 aRetFont = *pDefault;
165 return aRetFont;
166 }
167
168 QString chStr=aValue.mid( nOldIndex+1,
169 nIndex-nOldIndex-1 );
170 // find fifth part (weight)
171 nOldIndex = nIndex;
172 nIndex = aValue.find( ',', nOldIndex+1 );
173
174 if( nIndex == -1 ){
175 if( pDefault )
176 aRetFont = *pDefault;
177 return aRetFont;
178 }
179
180 aRetFont.setWeight( aValue.mid( nOldIndex+1,
181 nIndex-nOldIndex-1 ).toUInt() );
182
183 // find sixth part (font bits)
184 uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
185
186 aRetFont.setItalic( nFontBits & 0x01 );
187 aRetFont.setUnderline( nFontBits & 0x02 );
188 aRetFont.setStrikeOut( nFontBits & 0x04 );
189 aRetFont.setFixedPitch( nFontBits & 0x08 );
190 aRetFont.setRawMode( nFontBits & 0x20 );
191 }
192 }
193 else
194 {
195 if( pDefault )
196 aRetFont = *pDefault;
197 }
198 return aRetFont;
199 */
200 return QFont("Helvetica",10);
201}
diff --git a/libopie2/opiecore/oconfig.h b/libopie2/opiecore/oconfig.h
new file mode 100644
index 0000000..afe14b1
--- a/dev/null
+++ b/libopie2/opiecore/oconfig.h
@@ -0,0 +1,167 @@
1/*
2                 This file is part of the Opie Project
3
4 (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Inspired by the config classes from the KDE Project which are
6 =. (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org>
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30*/
31
32#ifndef OCONFIG_H
33#define OCONFIG_H
34
35//FIXME: Implement for X11 or reuse libqpe/Config there also?
36
37#include <qpe/config.h>
38
39class QColor;
40class QFont;
41
42/**
43 * A Configuration class based on the Qtopia @ref Config class
44 * featuring additional handling of color and font entries
45 */
46
47class OConfig : public Config
48{
49 public:
50
51 /**
52 * Constructs a OConfig object.
53 *
54 * @param name A file to parse.
55 */
56 OConfig( const QString &name, Domain domain = User );
57
58 /**
59 * Destructs the OConfig object.
60 *
61 * Writes back any dirty configuration entries, and destroys
62 * dynamically created objects.
63 */
64 virtual ~OConfig();
65
66 /**
67 * Returns the name of the group in which we are
68 * searching for keys and from which we are retrieving entries.
69 *
70 * @return The current group.
71 */
72 const QString& group() { return git.key(); };
73
74 /**
75 * Reads a @ref QColor entry.
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;
86
87 /**
88 * Reads a @ref QFont value.
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;
99
100};
101
102/**
103 * Helper class to facilitate working with @ref OConfig / @ref OSimpleConfig
104 * groups.
105 *
106 * Careful programmers always set the group of a
107 * @ref OConfig object to the group they want to read from
108 * and set it back to the old one of afterwards. This is usually
109 * written as:
110 * <pre>
111 *
112 * QString oldgroup config()->group();
113 * config()->setGroup( "TheGroupThatIWant" );
114 * ...
115 * config()->writeEntry( "Blah", "Blubb" );
116 *
117 * config()->setGroup( oldgroup );
118 * </pre>
119 *
120 * In order to facilitate this task, you can use
121 * OConfigGroupSaver. Simply construct such an object ON THE STACK
122 * when you want to switch to a new group. Then, when the object goes
123 * out of scope, the group will automatically be restored. If you
124 * want to use several different groups within a function or method,
125 * you can still use OConfigGroupSaver: Simply enclose all work with
126 * one group (including the creation of the OConfigGroupSaver object)
127 * in one block.
128 *
129 * @author Matthias Kalle Dalheimer <Kalle@kde.org>
130 * @version $Id$
131 * @see OConfig
132 * @short Helper class for easier use of OConfig groups
133 */
134
135class OConfigGroupSaver
136{
137 public:
138 /**
139 * Constructor. You pass a pointer to the OConfigBase-derived
140 * object you want to work with and a string indicating the _new_
141 * group.
142 * @param config The OConfig-derived object this
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() )
147 { _config->setGroup( group ); }
148
149 OConfigGroupSaver( OConfig* config, const char *group ) :_config(config), _oldgroup(config->group())
150 { _config->setGroup( group ); }
151
152 OConfigGroupSaver( OConfig* config, const QCString &group ) : _config(config), _oldgroup(config->group())
153 { _config->setGroup( group ); }
154
155 ~OConfigGroupSaver() { _config->setGroup( _oldgroup ); }
156
157 OConfig* config() { return _config; };
158
159 private:
160 OConfig* _config;
161 QString _oldgroup;
162
163 OConfigGroupSaver( const OConfigGroupSaver& );
164 OConfigGroupSaver& operator=( const OConfigGroupSaver& );
165};
166
167#endif // OCONFIG_H
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp
new file mode 100644
index 0000000..b4eaf2d
--- a/dev/null
+++ b/libopie2/opiecore/odebug.cpp
@@ -0,0 +1,628 @@
1/*
2 This file is part of the Opie Project
3 (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de)
4 Inspired by the KDE debug classes, which are
5 (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
6 (C) 2002 Holger Freyther (freyther@kde.org)
7 =.
8 .=l.
9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details.
24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31*/
32
33// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo
34// functions inlined to noops (which would then conflict with their definition here).
35
36#include <opie2/odebug.h>
37
38#ifdef OPIE_NO_DEBUG
39#undef odDebug
40#undef odBacktrace
41#endif
42
43/* OPIE */
44
45#include <opie2/oapplication.h>
46#include <opie2/oglobalsettings.h>
47#include <opie2/oconfig.h>
48
49/* QT */
50
51#include <qbrush.h>
52#include <qdatetime.h>
53#include <qfile.h>
54#include <qhostaddress.h>
55#include <qmessagebox.h>
56#include <qintdict.h>
57#include <qpoint.h>
58#include <qrect.h>
59#include <qregion.h>
60#include <qsize.h>
61#include <qsocketdevice.h>
62#include <qstring.h>
63#include <qstringlist.h>
64#include <qtextstream.h>
65
66/* UNIX */
67
68#include <stdlib.h> // abort
69#include <unistd.h> // getpid
70#include <stdarg.h> // vararg stuff
71#include <ctype.h> // isprint
72#include <syslog.h>
73#include <errno.h>
74#include <string.h>
75
76#ifndef OPIE_NO_BACKTRACE
77#include <execinfo.h>
78#endif
79
80
81/*======================================================================================
82 * debug levels
83 *======================================================================================*/
84
85enum DebugLevels {
86 ODEBUG_INFO = 0,
87 ODEBUG_WARN = 1,
88 ODEBUG_ERROR = 2,
89 ODEBUG_FATAL = 3
90};
91
92/*======================================================================================
93 * oDebug private data
94 *======================================================================================*/
95
96/*======================================================================================
97 * the main debug function
98 *======================================================================================*/
99
100static void oDebugBackend( unsigned short level, unsigned int area, const char *data)
101{
102 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data );
103
104 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an
105 // ML: example use. I think it's not necessary to implement such a strategy here.
106 // ML: Comments?
107
108 int priority = 0;
109 QString caption;
110 QString lev;
111 switch( level )
112 {
113 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break;
114 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break;
115 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break;
116 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." );
117 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break;
118 }
119
120 short output = OGlobalSettings::debugMode();
121 if (!oApp && (output == 1))
122 {
123 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" );
124 output = 2; // need an application object to use MsgBox
125 }
126
127 QString areaName = (oApp) ? oApp->appName() : "<unknown>";
128
129 // Output
130 switch( output )
131 {
132 case -1: // ignore
133 {
134 return;
135 }
136 case 0: // File
137 {
138 QString outputFilename = OGlobalSettings::debugOutput();
139
140 const int BUFSIZE = 4096;
141 char buf[BUFSIZE] = "";
142 buf[BUFSIZE-1] = '\0';
143 int nSize;
144
145 nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data);
146
147 QFile outputFile( outputFilename );
148 if ( outputFile.open( IO_WriteOnly | IO_Append ) )
149 {
150 if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) )
151 {
152 outputFile.writeBlock( buf, BUFSIZE-1 );
153 }
154 else
155 {
156 outputFile.writeBlock( buf, nSize );
157 }
158 }
159 else
160 {
161 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) );
162 }
163 break;
164 } // automatic close of file here
165
166 case 1: // Message Box
167 {
168 // Since we are in opiecore here, we cannot use OMsgBox and use
169 // QMessageBox instead
170
171 caption += QString("(") + areaName + ")";
172 QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr?
173 break;
174 }
175
176 case 2: // Shell
177 {
178 FILE *output = stderr;
179 fprintf( output, "%s: ", (const char*) areaName );
180 fputs( data, output);
181 break;
182 }
183
184 case 3: // syslog
185 {
186 syslog( priority, "%s", data);
187 break;
188 }
189
190 case 4: // socket
191 {
192 QString destination = OGlobalSettings::debugOutput();
193 if ( destination && destination.find(":") != -1 )
194 {
195 QString host = destination.left( destination.find(":") );
196 QString port = destination.right( destination.length()-host.length()-1 );
197 QHostAddress addr;
198 addr.setAddress( host );
199 // TODO: sanity check the address
200 QString line;
201 line.sprintf( "%s: %s", (const char*) areaName, (const char*) data );
202 QSocketDevice s( QSocketDevice::Datagram );
203 int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() );
204 if ( result == -1 )
205 {
206 qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) );
207 }
208 }
209 break;
210 }
211 }
212
213 // check if we should abort
214
215 /*
216
217 if( ( nLevel == ODEBUG_FATAL )
218 && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) )
219 abort();
220
221 */
222}
223
224/*======================================================================================
225 * odbgstream
226 *======================================================================================*/
227
228odbgstream& perror( odbgstream &s)
229{
230 return s << QString::fromLocal8Bit(strerror(errno));
231}
232
233odbgstream odDebug(int area)
234{
235 return odbgstream(area, ODEBUG_INFO);
236}
237odbgstream odDebug(bool cond, int area)
238{
239 if (cond) return odbgstream(area, ODEBUG_INFO);
240 else return odbgstream(0, 0, false);
241}
242
243odbgstream odError(int area)
244{
245 return odbgstream("ERROR: ", area, ODEBUG_ERROR);
246}
247
248odbgstream odError(bool cond, int area)
249{
250 if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false);
251}
252
253odbgstream odWarning(int area)
254{
255 return odbgstream("WARNING: ", area, ODEBUG_WARN);
256}
257
258odbgstream odWarning(bool cond, int area)
259{
260 if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false);
261}
262
263odbgstream odFatal(int area)
264{
265 return odbgstream("FATAL: ", area, ODEBUG_FATAL);
266}
267
268odbgstream odFatal(bool cond, int area)
269{
270 if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false);
271}
272
273odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print)
274 :area(_area), level(_level), print(_print)
275{
276}
277
278
279odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print)
280 :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print)
281{
282}
283
284
285odbgstream::odbgstream(odbgstream &str)
286 :output(str.output), area(str.area), level(str.level), print(str.print)
287{
288 str.output.truncate(0);
289}
290
291
292odbgstream::odbgstream(const odbgstream &str)
293 :output(str.output), area(str.area), level(str.level), print(str.print)
294{
295}
296
297odbgstream& odbgstream::operator<<(bool i)
298{
299 if (!print) return *this;
300 output += QString::fromLatin1(i ? "true" : "false");
301 return *this;
302}
303
304
305odbgstream& odbgstream::operator<<(short i)
306{
307 if (!print) return *this;
308 QString tmp; tmp.setNum(i); output += tmp;
309 return *this;
310}
311
312
313odbgstream& odbgstream::operator<<(unsigned short i)
314{
315 if (!print) return *this;
316 QString tmp; tmp.setNum(i); output += tmp;
317 return *this;
318}
319
320
321odbgstream& odbgstream::operator<<(unsigned char i)
322{
323 return operator<<( static_cast<char>( i ) );
324}
325
326
327odbgstream& odbgstream::operator<<(int i)
328{
329 if (!print) return *this;
330 QString tmp; tmp.setNum(i); output += tmp;
331 return *this;
332}
333
334
335odbgstream& odbgstream::operator<<(unsigned int i)
336{
337 if (!print) return *this;
338 QString tmp; tmp.setNum(i); output += tmp;
339 return *this;
340}
341
342
343odbgstream& odbgstream::operator<<(long i)
344{
345 if (!print) return *this;
346 QString tmp; tmp.setNum(i); output += tmp;
347 return *this;
348}
349
350
351odbgstream& odbgstream::operator<<(unsigned long i)
352{
353 if (!print) return *this;
354 QString tmp; tmp.setNum(i); output += tmp;
355 return *this;
356}
357
358
359odbgstream& odbgstream::operator<<(const QString& string)
360{
361 if (!print) return *this;
362 output += string;
363 if (output.at(output.length() -1 ) == '\n')
364 flush();
365 return *this;
366}
367
368
369odbgstream& odbgstream::operator<<(const char *string)
370{
371 if (!print) return *this;
372 output += QString::fromUtf8(string);
373 if (output.at(output.length() - 1) == '\n')
374 flush();
375 return *this;
376}
377
378
379odbgstream& odbgstream::operator<<(const QCString& string)
380{
381 *this << string.data();
382 return *this;
383}
384
385
386odbgstream& odbgstream::operator<<(const void * p)
387{
388 form("%p", p);
389 return *this;
390}
391
392odbgstream& odbgstream::operator<<(double d)
393{
394 QString tmp; tmp.setNum(d); output += tmp;
395 return *this;
396}
397
398/*
399odbgstream::odbgstream &form(const char *format, ...)
400#ifdef __GNUC__
401 __attribute__ ( ( format ( printf, 2, 3 ) ) )
402#endif
403 ;
404*/
405
406void odbgstream::flush()
407{
408 if ( output.isEmpty() || !print )
409 {
410 return;
411 }
412 else
413 {
414 oDebugBackend( level, area, output.local8Bit().data() );
415 output = QString::null;
416 }
417}
418
419odbgstream& odbgstream::form(const char *format, ...)
420{
421 char buf[4096];
422 va_list arguments;
423 va_start( arguments, format );
424 buf[sizeof(buf)-1] = '\0';
425 vsnprintf( buf, sizeof(buf)-1, format, arguments );
426 va_end(arguments);
427 *this << buf;
428 return *this;
429}
430
431odbgstream::~odbgstream()
432{
433 if (!output.isEmpty())
434 {
435 fprintf(stderr, "ASSERT: debug output not ended with \\n\n");
436 *this << "\n";
437 }
438}
439
440odbgstream& odbgstream::operator<<(char ch)
441{
442 if (!print) return *this;
443 if (!isprint(ch))
444 {
445 output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2);
446 }
447 else
448 {
449 output += ch;
450 if (ch == '\n') flush();
451 }
452 return *this;
453}
454
455odbgstream& odbgstream::operator<<( QWidget* widget )
456{
457 QString string, temp;
458 // -----
459 if(widget==0)
460 {
461 string=(QString)"[Null pointer]";
462 } else
463 {
464 temp.setNum((ulong)widget, 16);
465 string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")";
466 if(widget->name(0)==0)
467 {
468 string += " to unnamed widget, ";
469 } else
470 {
471 string += (QString)" to widget " + widget->name() + ", ";
472 }
473 string += "geometry="
474 + QString().setNum(widget->width())
475 + "x"+QString().setNum(widget->height())
476 + "+"+QString().setNum(widget->x())
477 + "+"+QString().setNum(widget->y())
478 + "]";
479 }
480 if (!print) return *this;
481
482 output += string;
483 if (output.at(output.length()-1) == '\n')
484 {
485 flush();
486 }
487 return *this;
488}
489
490/*
491 * either use 'output' directly and do the flush if needed
492 * or use the QString operator which calls the char* operator
493 *
494 */
495odbgstream& odbgstream::operator<<( const QDateTime& time)
496{
497 *this << time.toString();
498 return *this;
499}
500
501
502odbgstream& odbgstream::operator<<( const QDate& date)
503{
504 *this << date.toString();
505
506 return *this;
507}
508
509
510odbgstream& odbgstream::operator<<( const QTime& time )
511{
512 *this << time.toString();
513 return *this;
514}
515
516
517odbgstream& odbgstream::operator<<( const QPoint& p )
518{
519 *this << "(" << p.x() << ", " << p.y() << ")";
520 return *this;
521}
522
523
524odbgstream& odbgstream::operator<<( const QSize& s )
525{
526 *this << "[" << s.width() << "x" << s.height() << "]";
527 return *this;
528}
529
530
531odbgstream& odbgstream::operator<<( const QRect& r )
532{
533 *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]";
534 return *this;
535}
536
537
538odbgstream& odbgstream::operator<<( const QRegion& reg )
539{
540 /* Qt2 doesn't have a QMemArray... :(
541 *this << "[ ";
542 QMemArray<QRect>rs=reg.rects();
543 for (uint i=0;i<rs.size();++i)
544 *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ;
545 *this <<"]";
546 */
547 return *this;
548}
549
550
551odbgstream& odbgstream::operator<<( const QStringList& l )
552{
553 *this << "(";
554 *this << l.join(",");
555 *this << ")";
556
557 return *this;
558}
559
560
561odbgstream& odbgstream::operator<<( const QColor& c )
562{
563 if ( c.isValid() )
564 *this << c.name();
565 else
566 *this << "(invalid/default)";
567 return *this;
568}
569
570
571odbgstream& odbgstream::operator<<( const QBrush& b)
572{
573 static const char* const s_brushStyles[] = {
574 "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern",
575 "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern",
576 "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern",
577 "DiagCrossPattern" };
578
579 *this <<"[ style: ";
580 *this <<s_brushStyles[ b.style() ];
581 *this <<" color: ";
582 // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes)
583 if ( b.color().isValid() )
584 *this <<b.color().name() ;
585 else
586 *this <<"(invalid/default)";
587 if ( b.pixmap() )
588 *this <<" has a pixmap";
589 *this <<" ]";
590 return *this;
591}
592
593
594
595QString odBacktrace( int levels )
596{
597 QString s;
598#ifndef OPIE_NO_BACKTRACE
599 void* trace[256];
600 int n = backtrace(trace, 256);
601 char** strings = backtrace_symbols (trace, n);
602
603 if ( levels != -1 )
604 n = QMIN( n, levels );
605 s = "[\n";
606
607 for (int i = 0; i < n; ++i)
608 s += QString::number(i) +
609 QString::fromLatin1(": ") +
610 QString::fromLatin1(strings[i]) + QString::fromLatin1("\n");
611 s += "]\n";
612 free (strings);
613#endif
614 return s;
615}
616
617void odClearDebugConfig()
618{
619 /*
620 delete oDebug_data->config;
621 oDebug_data->config = 0;
622 */
623}
624
625#ifdef OPIE_NO_DEBUG
626#define odDebug ondDebug
627#define odBacktrace ondBacktrace
628#endif
diff --git a/libopie2/opiecore/odebug.h b/libopie2/opiecore/odebug.h
new file mode 100644
index 0000000..85941fd
--- a/dev/null
+++ b/libopie2/opiecore/odebug.h
@@ -0,0 +1,474 @@
1/*
2 This file is part of the Opie Project
3 (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de)
4 Inspired by the KDE debug classes, which are
5 (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
6 (C) 2002 Holger Freyther (freyther@kde.org)
7 =.
8 .=l.
9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details.
24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31*/
32
33#ifndef ODEBUG_H
34#define ODEBUG_H
35
36#include <qstring.h>
37
38class QWidget;
39class QDateTime;
40class QDate;
41class QTime;
42class QPoint;
43class QSize;
44class QRect;
45class QRegion;
46class QStringList;
47class QColor;
48class QBrush;
49
50class odbgstream;
51class ondbgstream;
52
53#ifdef __GNUC__
54#define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
55#else
56#define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
57#endif
58
59#define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
60
61#define owarn odWarning()
62#define oerr odError()
63#define odebug odDebug()
64#define ofatal odFatal()
65#define oendl "\n"
66
67class odbgstreamprivate;
68/**
69 * odbgstream is a text stream that allows you to print debug messages.
70 * Using the overloaded "<<" operator you can send messages. Usually
71 * you do not create the odbgstream yourself, but use @ref odDebug() (odebug)
72 * @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one.
73 *
74 * Example:
75 * <pre>
76 * int i = 5;
77 * odebug << "The value of i is " << i << oendl;
78 * </pre>
79 * @see odbgstream
80 */
81
82/*======================================================================================
83 * odbgstream
84 *======================================================================================*/
85
86class odbgstream
87{
88 public:
89 /**
90 * @internal
91 */
92 odbgstream(unsigned int _area, unsigned int _level, bool _print = true);
93 odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true);
94 odbgstream(odbgstream &str);
95 odbgstream(const odbgstream &str);
96 virtual ~odbgstream();
97
98 /**
99 * Prints the given value.
100 * @param i the boolean to print (as "true" or "false")
101 * @return this stream
102 */
103 odbgstream &operator<<(bool i);
104 /**
105 * Prints the given value.
106 * @param i the short to print
107 * @return this stream
108 */
109 odbgstream &operator<<(short i);
110 /**
111 * Prints the given value.
112 * @param i the unsigned short to print
113 * @return this stream
114 */
115 odbgstream &operator<<(unsigned short i);
116 /**
117 * Prints the given value.
118 * @param i the char to print
119 * @return this stream
120 */
121 odbgstream &operator<<(char i);
122 /**
123 * Prints the given value.
124 * @param i the unsigned char to print
125 * @return this stream
126 */
127 odbgstream &operator<<(unsigned char i);
128 /**
129 * Prints the given value.
130 * @param i the int to print
131 * @return this stream
132 */
133 odbgstream &operator<<(int i);
134 /**
135 * Prints the given value.
136 * @param i the unsigned int to print
137 * @return this stream
138 */
139 odbgstream &operator<<(unsigned int i);
140 /**
141 * Prints the given value.
142 * @param i the long to print
143 * @return this stream
144 */
145 odbgstream &operator<<(long i);
146 /**
147 * Prints the given value.
148 * @param i the unsigned long to print
149 * @return this stream
150 */
151 odbgstream &operator<<(unsigned long i);
152 /**
153 * Flushes the output.
154 */
155 virtual void flush();
156 /**
157 * Prints the given value.
158 * @param string the string to print
159 * @return this stream
160 */
161 odbgstream &operator<<(const QString& string);
162 /**
163 * Prints the given value.
164 * @param string the string to print
165 * @return this stream
166 */
167 odbgstream &operator<<(const char *string);
168 /**
169 * Prints the given value.
170 * @param string the string to print
171 * @return this stream
172 */
173 odbgstream &operator<<(const QCString& string);
174 /**
175 * Prints the given value.
176 * @param p a pointer to print (in number form)
177 * @return this stream
178 */
179 odbgstream& operator<<(const void * p);
180 /**
181 * Prints the given value.
182 * @param d the double to print
183 * @return this stream
184 */
185 odbgstream& operator<<(double d);
186 /**
187 * Prints the string @p format which can contain
188 * printf-style formatted values.
189 * @param format the printf-style format
190 * @return this stream
191 */
192 odbgstream &form(const char *format, ...);
193 /** Operator to print out basic information about a QWidget.
194 * Output of class names only works if the class is moc'ified.
195 * @param widget the widget to print
196 * @return this stream
197 */
198 odbgstream& operator<< (QWidget* widget);
199
200 /**
201 * Prints the given value.
202 * @param dateTime the datetime to print
203 * @return this stream
204 */
205 odbgstream& operator<< ( const QDateTime& dateTime );
206
207 /**
208 * Prints the given value.
209 * @param date the date to print
210 * @return this stream
211 */
212 odbgstream& operator<< ( const QDate& date );
213
214 /**
215 * Prints the given value.
216 * @param time the time to print
217 * @return this stream
218 */
219 odbgstream& operator<< ( const QTime& time );
220
221 /**
222 * Prints the given value.
223 * @param point the point to print
224 * @return this stream
225 */
226 odbgstream& operator<< ( const QPoint& point );
227
228 /**
229 * Prints the given value.
230 * @param size the QSize to print
231 * @return this stream
232 */
233 odbgstream& operator<< ( const QSize& size );
234
235 /**
236 * Prints the given value.
237 * @param rect the QRect to print
238 * @return this stream
239 */
240 odbgstream& operator<< ( const QRect& rect);
241
242 /**
243 * Prints the given value.
244 * @param region the QRegion to print
245 * @return this stream
246 */
247 odbgstream& operator<< ( const QRegion& region);
248
249 /**
250 * Prints the given value.
251 * @param list the stringlist to print
252 * @return this stream
253 */
254 odbgstream& operator<< ( const QStringList& list);
255
256 /**
257 * Prints the given value.
258 * @param color the color to print
259 * @return this stream
260 */
261 odbgstream& operator<< ( const QColor& color);
262
263 /**
264 * Prints the given value.
265 * @param brush the brush to print
266 * @return this stream
267 */
268 odbgstream& operator<< ( const QBrush& brush );
269
270 private:
271 QString output;
272 unsigned int area, level;
273 bool print;
274 odbgstreamprivate* d;
275};
276
277/**
278 * Prints an "\n".
279 * @param s the debug stream to write to
280 * @return the debug stream (@p s)
281 */
282inline odbgstream& endl( odbgstream &s) { s << "\n"; return s; }
283/**
284 * Flushes the stream.
285 * @param s the debug stream to write to
286 * @return the debug stream (@p s)
287 */
288inline odbgstream& flush( odbgstream &s) { s.flush(); return s; }
289
290odbgstream &perror( odbgstream &s);
291
292/**
293 * ondbgstream is a dummy variant of @ref odbgstream. All functions do
294 * nothing.
295 * @see ondDebug()
296 */
297class ondbgstream {
298 public:
299 /// Empty constructor.
300 ondbgstream() {}
301 ~ondbgstream() {}
302 /**
303 * Does nothing.
304 * @return this stream
305 */
306 ondbgstream &operator<<(short int ) { return *this; }
307 /**
308 * Does nothing.
309 * @return this stream
310 */
311 ondbgstream &operator<<(unsigned short int ) { return *this; }
312 /**
313 * Does nothing.
314 * @return this stream
315 */
316 ondbgstream &operator<<(char ) { return *this; }
317 /**
318 * Does nothing.
319 * @return this stream
320 */
321 ondbgstream &operator<<(unsigned char ) { return *this; }
322 /**
323 * Does nothing.
324 * @return this stream
325 */
326 ondbgstream &operator<<(int ) { return *this; }
327 /**
328 * Does nothing.
329 * @return this stream
330 */
331 ondbgstream &operator<<(unsigned int ) { return *this; }
332 /**
333 * Does nothing.
334 */
335 void flush() {}
336 /**
337 * Does nothing.
338 * @return this stream
339 */
340 ondbgstream &operator<<(const QString& ) { return *this; }
341 /**
342 * Does nothing.
343 * @return this stream
344 */
345 ondbgstream &operator<<(const QCString& ) { return *this; }
346 /**
347 * Does nothing.
348 * @return this stream
349 */
350 ondbgstream &operator<<(const char *) { return *this; }
351 /**
352 * Does nothing.
353 * @return this stream
354 */
355 ondbgstream& operator<<(const void *) { return *this; }
356 /**
357 * Does nothing.
358 * @return this stream
359 */
360 ondbgstream& operator<<(void *) { return *this; }
361 /**
362 * Does nothing.
363 * @return this stream
364 */
365 ondbgstream& operator<<(double) { return *this; }
366 /**
367 * Does nothing.
368 * @return this stream
369 */
370 ondbgstream& operator<<(long) { return *this; }
371 /**
372 * Does nothing.
373 * @return this stream
374 */
375 ondbgstream& operator<<(unsigned long) { return *this; }
376 /**
377 * Does nothing.
378 * @return this stream
379 */
380 ondbgstream& operator << (QWidget*) { return *this; }
381 /**
382 * Does nothing.
383 * @return this stream
384 */
385 ondbgstream &form(const char *, ...) { return *this; }
386
387 ondbgstream& operator<<( const QDateTime& ) { return *this; }
388 ondbgstream& operator<<( const QDate& ) { return *this; }
389 ondbgstream& operator<<( const QTime& ) { return *this; }
390 ondbgstream& operator<<( const QPoint & ) { return *this; }
391 ondbgstream& operator<<( const QSize & ) { return *this; }
392 ondbgstream& operator<<( const QRect & ) { return *this; }
393 ondbgstream& operator<<( const QRegion & ) { return *this; }
394 ondbgstream& operator<<( const QStringList & ) { return *this; }
395 ondbgstream& operator<<( const QColor & ) { return *this; }
396 ondbgstream& operator<<( const QBrush & ) { return *this; }
397};
398
399/*======================================================================================
400 * related functions
401 *======================================================================================*/
402
403/**
404 * Does nothing.
405 * @param a stream
406 * @return the given @p s
407 */
408inline ondbgstream& endl( ondbgstream & s) { return s; }
409/**
410 * Does nothing.
411 * @param a stream
412 * @return the given @p s
413 */
414inline ondbgstream& flush( ondbgstream & s) { return s; }
415inline ondbgstream& perror( ondbgstream & s) { return s; }
416
417/**
418 * Returns a debug stream. You can use it to print debug
419 * information.
420 * @param area an id to identify the output, 0 for default
421 */
422odbgstream odDebug(int area = 0);
423odbgstream odDebug(bool cond, int area = 0);
424/**
425 * Returns a backtrace.
426 * @param levels the number of levels (-1 for unlimited) of the backtrace
427 * @return a backtrace
428 */
429QString odBacktrace(int levels = -1);
430/**
431 * Returns a dummy debug stream. The stream does not print anything.
432 * @param area an id to identify the output, 0 for default
433 * @see odDebug()
434 */
435inline ondbgstream ondDebug(int = 0) { return ondbgstream(); }
436inline ondbgstream ondDebug(bool , int = 0) { return ondbgstream(); }
437inline QString ondBacktrace() { return QString::null; }
438inline QString ondBacktrace(int) { return QString::null; }
439
440/**
441 * Returns a warning stream. You can use it to print warning
442 * information.
443 * @param area an id to identify the output, 0 for default
444 */
445odbgstream odWarning(int area = 0);
446odbgstream odWarning(bool cond, int area = 0);
447/**
448 * Returns an error stream. You can use it to print error
449 * information.
450 * @param area an id to identify the output, 0 for default
451 */
452odbgstream odError(int area = 0);
453odbgstream odError(bool cond, int area = 0);
454/**
455 * Returns a fatal error stream. You can use it to print fatal error
456 * information.
457 * @param area an id to identify the output, 0 for default
458 */
459odbgstream odFatal(int area = 0);
460odbgstream odFatal(bool cond, int area = 0);
461
462/**
463 * Deletes the odebugrc cache and therefore forces KDebug to reread the
464 * config file
465 */
466void odClearDebugConfig();
467
468#ifdef OPIE_NO_DEBUG
469#define odDebug ondDebug
470#define odBacktrace ondBacktrace
471#endif
472
473#endif
474
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp
new file mode 100644
index 0000000..2eb4108
--- a/dev/null
+++ b/libopie2/opiecore/oglobal.cpp
@@ -0,0 +1,36 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29 */
30
31#include <opie2/oglobal.h>
32
33OConfig* OGlobal::config()
34{
35 return &globalconfig;
36}
diff --git a/libopie2/opiecore/oglobal.h b/libopie2/opiecore/oglobal.h
new file mode 100644
index 0000000..8345c6a
--- a/dev/null
+++ b/libopie2/opiecore/oglobal.h
@@ -0,0 +1,48 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29*/
30
31#ifndef OGLOBAL_H
32#define OGLOBAL_H
33
34#include <qpe/global.h>
35#include <opie2/oconfig.h>
36
37static OConfig globalconfig = OConfig( "global" );
38
39//FIXME: Is it wise or even necessary to inherit OGlobal from Global?
40
41class OGlobal : public Global
42{
43 public:
44
45 static OConfig* config();
46};
47
48#endif // OGLOBAL_H
diff --git a/libopie2/opiecore/oglobalsettings.cpp b/libopie2/opiecore/oglobalsettings.cpp
new file mode 100644
index 0000000..184ee69
--- a/dev/null
+++ b/libopie2/opiecore/oglobalsettings.cpp
@@ -0,0 +1,547 @@
1/*
2                 This file is part of the Opie Project
3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Inspired by the KDE globalsettings which are
6 Copyright (C) 2000 David Faure <faure@kde.org>
7 =.
8 .=l.
9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details.
24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31*/
32
33/* OPIE */
34
35#include <opie2/oglobalsettings.h>
36#include <opie2/oconfig.h>
37#include <opie2/oglobal.h>
38
39/* QT */
40
41#include <qdir.h>
42#include <qpixmap.h>
43#include <qfontinfo.h>
44
45/* UNIX */
46
47#include <stdlib.h>
48
49QString* OGlobalSettings::s_desktopPath = 0;
50QString* OGlobalSettings::s_autostartPath = 0;
51QString* OGlobalSettings::s_trashPath = 0;
52QString* OGlobalSettings::s_documentPath = 0;
53QFont *OGlobalSettings::_generalFont = 0;
54QFont *OGlobalSettings::_fixedFont = 0;
55QFont *OGlobalSettings::_toolBarFont = 0;
56QFont *OGlobalSettings::_menuFont = 0;
57QFont *OGlobalSettings::_windowTitleFont = 0;
58QFont *OGlobalSettings::_taskbarFont = 0;
59
60QColor *OGlobalSettings::OpieGray = 0;
61QColor *OGlobalSettings::OpieHighlight = 0;
62QColor *OGlobalSettings::OpieAlternate = 0;
63
64OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0;
65
66//FIXME: Add manipulators to the accessors
67
68int OGlobalSettings::dndEventDelay()
69{
70 OConfig *c = OGlobal::config();
71 OConfigGroupSaver cgs( c, "General" );
72 return c->readNumEntry("DndDelay", 2);
73}
74
75bool OGlobalSettings::singleClick()
76{
77 OConfig *c = OGlobal::config();
78 OConfigGroupSaver cgs( c, "OPIE" );
79 return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK);
80}
81
82bool OGlobalSettings::insertTearOffHandle()
83{
84 OConfig *c = OGlobal::config();
85 OConfigGroupSaver cgs( c, "OPIE" );
86 return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES);
87}
88
89bool OGlobalSettings::changeCursorOverIcon()
90{
91 OConfig *c = OGlobal::config();
92 OConfigGroupSaver cgs( c, "OPIE" );
93 return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR);
94}
95
96bool OGlobalSettings::visualActivate()
97{
98 OConfig *c = OGlobal::config();
99 OConfigGroupSaver cgs( c, "OPIE" );
100 return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE);
101}
102
103unsigned int OGlobalSettings::visualActivateSpeed()
104{
105 OConfig *c = OGlobal::config();
106 OConfigGroupSaver cgs( c, "OPIE" );
107 return
108 c->readNumEntry(
109 "VisualActivateSpeed",
110 OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED
111 );
112}
113
114int OGlobalSettings::autoSelectDelay()
115{
116 OConfig *c = OGlobal::config();
117 OConfigGroupSaver cgs( c, "OPIE" );
118 return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY);
119}
120
121OGlobalSettings::Completion OGlobalSettings::completionMode()
122{
123 int completion;
124 OConfig *c = OGlobal::config();
125 OConfigGroupSaver cgs( c, "General" );
126 completion = c->readNumEntry("completionMode", -1);
127 if ((completion < (int) CompletionNone) ||
128 (completion > (int) CompletionPopupAuto))
129 {
130 completion = (int) CompletionPopup; // Default
131 }
132 return (Completion) completion;
133}
134
135
136bool OGlobalSettings::showContextMenusOnPress ()
137{
138 OConfig *c = OGlobal::config();
139 OConfigGroupSaver cgs (c, "ContextMenus");
140
141 return cgs.config()->readBoolEntry("ShowOnPress", true);
142}
143
144
145int OGlobalSettings::contextMenuKey ()
146{
147 OConfig *c = OGlobal::config();
148 OConfigGroupSaver cgs (c, "Shortcuts");
149
150 //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu"));
151 //return cut.keyCodeQt();
152
153 return 0; // FIXME
154}
155
156
157OGlobalSettings::Debug OGlobalSettings::debugMode()
158{
159 OConfig *c = OGlobal::config();
160 OConfigGroupSaver cgs( c, "General" );
161 int debug = c->readNumEntry( "debugMode", -1 );
162 if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) )
163 {
164 debug = (int) DebugStdErr; // Default
165 }
166 return (Debug) debug;
167}
168
169
170QString OGlobalSettings::debugOutput()
171{
172 OConfig *c = OGlobal::config();
173 OConfigGroupSaver cgs( c, "General" );
174 QString deflt = QString::null;
175 switch( debugMode() )
176 {
177 case DebugNone: break; // no additional information needed
178 case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in
179 case DebugMsgBox: break; // no additional information needed
180 case DebugStdErr: break; // no additional information needed
181 case DebugSysLog: break; // no additional information needed
182 case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to
183 }
184
185 return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt );
186}
187
188
189QColor OGlobalSettings::toolBarHighlightColor()
190{
191 initColors();
192 OConfig *c = OGlobal::config();
193 OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") );
194 return c->readColorEntry("HighlightColor", OpieHighlight);
195}
196
197QColor OGlobalSettings::inactiveTitleColor()
198{
199 if (!OpieGray) OpieGray = new QColor(220, 220, 220);
200 OConfig *c = OGlobal::config();
201 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
202 return c->readColorEntry( "inactiveBackground", OpieGray );
203}
204
205QColor OGlobalSettings::inactiveTextColor()
206{
207 OConfig *c = OGlobal::config();
208 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
209 return c->readColorEntry( "inactiveForeground", &Qt::darkGray );
210}
211
212QColor OGlobalSettings::activeTitleColor()
213{
214 initColors();
215 OConfig *c = OGlobal::config();
216 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
217 return c->readColorEntry( "activeBackground", OpieHighlight);
218}
219
220QColor OGlobalSettings::activeTextColor()
221{
222 OConfig *c = OGlobal::config();
223 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
224 return c->readColorEntry( "activeForeground", &Qt::white );
225}
226
227int OGlobalSettings::contrast()
228{
229 OConfig *c = OGlobal::config();
230 OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") );
231 return c->readNumEntry( "contrast", 7 );
232}
233
234// following functions should work in OPIE - how to sync with appearance changes?
235
236QColor OGlobalSettings::baseColor()
237{
238 OConfig *c = OGlobal::config();
239 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
240 return c->readColorEntry( "Base", &Qt::white );
241}
242
243QColor OGlobalSettings::textColor()
244{
245 OConfig *c = OGlobal::config();
246 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
247 return c->readColorEntry( "Text", &Qt::black );
248}
249
250QColor OGlobalSettings::highlightedTextColor()
251{
252 OConfig *c = OGlobal::config();
253 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
254 return c->readColorEntry( "HighlightedText", &Qt::white );
255}
256
257QColor OGlobalSettings::highlightColor()
258{
259 initColors();
260 OConfig *c = OGlobal::config();
261 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
262 return c->readColorEntry( "Highlight", OpieHighlight );
263}
264
265QColor OGlobalSettings::alternateBackgroundColor()
266{
267 initColors();
268 OConfig *c = OGlobal::config();
269 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
270 *OpieAlternate = calculateAlternateBackgroundColor( baseColor() );
271 return c->readColorEntry( "alternateBackground", OpieAlternate );
272}
273
274QColor OGlobalSettings::calculateAlternateBackgroundColor(const QColor& base)
275{
276 if (base == Qt::white)
277 return QColor(238,246,255);
278 else
279 {
280 int h, s, v;
281 base.hsv( &h, &s, &v );
282 if (v > 128)
283 return base.dark(106);
284 else if (base != Qt::black)
285 return base.light(110);
286
287 return QColor(32,32,32);
288 }
289}
290
291QColor OGlobalSettings::linkColor()
292{
293 initColors();
294 OConfig *c = OGlobal::config();
295 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
296 return c->readColorEntry( "linkColor", OpieGray );
297}
298
299QColor OGlobalSettings::visitedLinkColor()
300{
301 OConfig *c = OGlobal::config();
302 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
303 return c->readColorEntry( "visitedLinkColor", &Qt::magenta );
304}
305
306// FIXME: font stuff currently uses a different format in OPIE, so the
307// functions below are not yet applicable. The whole font stuff for OPIE
308// has to be revised anyway
309
310QFont OGlobalSettings::generalFont()
311{
312 if (_generalFont)
313 return *_generalFont;
314
315 _generalFont = new QFont("helvetica", 10);
316 _generalFont->setPixelSize(10);
317 _generalFont->setStyleHint(QFont::SansSerif);
318
319 OConfig *c = OGlobal::config();
320 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
321 *_generalFont = c->readFontEntry("font", _generalFont);
322
323 return *_generalFont;
324}
325
326QFont OGlobalSettings::fixedFont()
327{
328 if (_fixedFont)
329 return *_fixedFont;
330
331 _fixedFont = new QFont("courier", 12);
332 _fixedFont->setPixelSize(12);
333 _fixedFont->setStyleHint(QFont::TypeWriter);
334
335 OConfig *c = OGlobal::config();
336 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
337 *_fixedFont = c->readFontEntry("fixed", _fixedFont);
338
339 return *_fixedFont;
340}
341
342QFont OGlobalSettings::toolBarFont()
343{
344 if(_toolBarFont)
345 return *_toolBarFont;
346
347 _toolBarFont = new QFont("helvetica", 10);
348 _toolBarFont->setPixelSize(10);
349 _toolBarFont->setStyleHint(QFont::SansSerif);
350
351 OConfig *c = OGlobal::config();
352 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
353 *_toolBarFont = c->readFontEntry("toolBarFont", _toolBarFont);
354
355 return *_toolBarFont;
356}
357
358QFont OGlobalSettings::menuFont()
359{
360 if(_menuFont)
361 return *_menuFont;
362
363 _menuFont = new QFont("helvetica", 12);
364 _menuFont->setPixelSize(12);
365 _menuFont->setStyleHint(QFont::SansSerif);
366
367 OConfig *c = OGlobal::config();
368 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
369 *_menuFont = c->readFontEntry("menuFont", _menuFont);
370
371 return *_menuFont;
372}
373
374QFont OGlobalSettings::windowTitleFont()
375{
376 if(_windowTitleFont)
377 return *_windowTitleFont;
378
379 _windowTitleFont = new QFont("helvetica", 12, QFont::Bold);
380 _windowTitleFont->setPixelSize(12);
381 _windowTitleFont->setStyleHint(QFont::SansSerif);
382
383 OConfig *c = OGlobal::config();
384 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
385 *_windowTitleFont = c->readFontEntry("activeFont", _windowTitleFont); // inconsistency
386
387 return *_windowTitleFont;
388}
389
390QFont OGlobalSettings::taskbarFont()
391{
392 if(_taskbarFont)
393 return *_taskbarFont;
394
395 _taskbarFont = new QFont("helvetica", 8);
396 _taskbarFont->setPixelSize(8);
397 _taskbarFont->setStyleHint(QFont::SansSerif);
398
399 OConfig *c = OGlobal::config();
400 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
401 *_taskbarFont = c->readFontEntry("taskbarFont", _taskbarFont);
402
403 return *_taskbarFont;
404}
405
406// FIXME: the whole path stuff has to be revised for OPIE
407
408void OGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here.
409{
410 if ( s_desktopPath != 0 )
411 return;
412
413 s_desktopPath = new QString();
414 s_autostartPath = new QString();
415 s_trashPath = new QString();
416 s_documentPath = new QString();
417
418 OConfig *config = OGlobal::config();
419 //bool dollarExpansion = config->isDollarExpansion();
420 //config->setDollarExpansion(true);
421 OConfigGroupSaver cgs( config, "Paths" );
422
423 // Desktop Path
424 *s_desktopPath = QDir::homeDirPath() + "/" + "Desktop" + "/";
425 *s_desktopPath = config->readEntry( "Desktop", *s_desktopPath);
426 if ( (*s_desktopPath)[0] != '/' )
427 s_desktopPath->prepend( QDir::homeDirPath() + "/" );
428 *s_desktopPath = QDir::cleanDirPath( *s_desktopPath );
429 if ( s_desktopPath->right(1) != "/")
430 *s_desktopPath += "/";
431
432 // Trash Path
433 *s_trashPath = *s_desktopPath + QObject::tr("Trash") + "/";
434 *s_trashPath = config->readEntry( "Trash" , *s_trashPath);
435 if ( (*s_trashPath)[0] != '/' )
436 s_trashPath->prepend( QDir::homeDirPath() + "/" );
437 *s_trashPath = QDir::cleanDirPath( *s_trashPath );
438 if ( s_trashPath->right(1) != "/")
439 *s_trashPath += "/";
440 // We need to save it in any case, in case the language changes later on,
441 if ( !config->hasKey( "Trash" ) )
442 {
443 //config->writePathEntry( "Trash", *s_trashPath, true, true );
444 config->writeEntry( "Trash", *s_trashPath );
445 //config->sync();
446 }
447
448/* // Autostart Path
449 *s_autostartPath = OGlobal::dirs()->localkdedir() + "Autostart" + "/";
450 *s_autostartPath = config->readEntry( "Autostart" , *s_autostartPath);
451 if ( (*s_autostartPath)[0] != '/' )
452 s_autostartPath->prepend( QDir::homeDirPath() + "/" );
453 *s_autostartPath = QDir::cleanDirPath( *s_autostartPath );
454 if ( s_autostartPath->right(1) != "/")
455 *s_autostartPath += "/";
456*/
457 // Document Path
458 *s_documentPath = QString::null;
459 *s_documentPath = config->readEntry( "Documents" , *s_documentPath);
460 if ( (*s_documentPath)[0] != '/' )
461 s_documentPath->prepend( QDir::homeDirPath() + "/" );
462 *s_documentPath = QDir::cleanDirPath( *s_documentPath );
463 if ( s_documentPath->right(1) != "/")
464 *s_documentPath += "/";
465
466 //config->setDollarExpansion(dollarExpansion);
467
468 // Make sure this app gets the notifications about those paths
469 //if (kapp)
470 //kapp->addKipcEventMask(KIPC::SettingsChanged);
471}
472
473void OGlobalSettings::initColors()
474{
475 if ( not OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 );
476 if ( not OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 );
477 if ( not OpieGray ) OpieGray = new QColor( 220, 210, 215 );
478}
479
480void OGlobalSettings::rereadFontSettings()
481{
482 delete _generalFont;
483 _generalFont = 0L;
484 delete _fixedFont;
485 _fixedFont = 0L;
486 delete _menuFont;
487 _menuFont = 0L;
488 delete _toolBarFont;
489 _toolBarFont = 0L;
490 delete _windowTitleFont;
491 _windowTitleFont = 0L;
492 delete _taskbarFont;
493 _taskbarFont = 0L;
494}
495
496void OGlobalSettings::rereadPathSettings()
497{
498 qDebug( "OGlobalSettings::rereadPathSettings" );
499 delete s_autostartPath;
500 s_autostartPath = 0L;
501 delete s_trashPath;
502 s_trashPath = 0L;
503 delete s_desktopPath;
504 s_desktopPath = 0L;
505 delete s_documentPath;
506 s_documentPath = 0L;
507}
508
509OGlobalSettings::OMouseSettings & OGlobalSettings::mouseSettings()
510{
511 if ( ! s_mouseSettings )
512 {
513 s_mouseSettings = new OMouseSettings;
514 OMouseSettings & s = *s_mouseSettings; // for convenience
515
516 OConfigGroupSaver cgs( OGlobal::config(), "Mouse" );
517 QString setting = OGlobal::config()->readEntry("MouseButtonMapping");
518 if (setting == "RightHanded")
519 s.handed = OMouseSettings::RightHanded;
520 else if (setting == "LeftHanded")
521 s.handed = OMouseSettings::LeftHanded;
522 else
523 {
524
525 // FIXME: Implement for Opie / Qt Embedded
526
527 }
528 }
529 return *s_mouseSettings;
530}
531
532void OGlobalSettings::rereadMouseSettings()
533{
534 delete s_mouseSettings;
535 s_mouseSettings = 0L;
536}
537
538// FIXME: This won't be necessary, or will it? :-D
539
540bool OGlobalSettings::isMultiHead()
541{
542 QCString multiHead = getenv("OPIE_MULTIHEAD");
543 if (!multiHead.isEmpty()) {
544 return (multiHead.lower() == "true");
545 }
546 return false;
547}
diff --git a/libopie2/opiecore/oglobalsettings.h b/libopie2/opiecore/oglobalsettings.h
new file mode 100644
index 0000000..6481251
--- a/dev/null
+++ b/libopie2/opiecore/oglobalsettings.h
@@ -0,0 +1,368 @@
1/*
2                 This file is part of the Opie Project
3              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
4 Inspired by KDE OGlobalSettings
5 Copyright (C) 2000 David Faure <faure@kde.org>
6 =.
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30*/
31
32#ifndef OGLOBALSETTINGS_H
33#define OGLOBALSETTINGS_H
34
35#include <qstring.h>
36#include <qcolor.h>
37#include <qfont.h>
38
39#define OPIE_DEFAULT_SINGLECLICK true
40#define OPIE_DEFAULT_INSERTTEAROFFHANDLES true
41#define OPIE_DEFAULT_AUTOSELECTDELAY -1
42#define OPIE_DEFAULT_CHANGECURSOR true
43#define OPIE_DEFAULT_LARGE_CURSOR false
44#define OPIE_DEFAULT_VISUAL_ACTIVATE true
45#define OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED 50
46
47//FIXME: There's still a whole lot of stuff in here which has to be revised
48//FIXME: before public usage... lack of time to do it at once - so it will
49//FIXME: happen step-by-step. ML.
50
51/**
52 * Access the OPIE global configuration settings.
53 *
54 */
55class OGlobalSettings
56{
57 public:
58
59 /**
60 * Returns a threshold in pixels for drag & drop operations.
61 * As long as the mouse movement has not exceeded this number
62 * of pixels in either X or Y direction no drag operation may
63 * be started. This prevents spurious drags when the user intended
64 * to click on something but moved the mouse a bit while doing so.
65 *
66 * For this to work you must save the position of the mouse (oldPos)
67 * in the @ref QWidget::mousePressEvent().
68 * When the position of the mouse (newPos)
69 * in a @ref QWidget::mouseMoveEvent() exceeds this threshold
70 * you may start a drag
71 * which should originate from oldPos.
72 *
73 * Example code:
74 * <pre>
75 * void OColorCells::mousePressEvent( QMouseEvent *e )
76 * {
77 * mOldPos = e->pos();
78 * }
79 *
80 * void OColorCells::mouseMoveEvent( QMouseEvent *e )
81 * {
82 * if( !(e->state() && LeftButton)) return;
83 *
84 * int delay = OGlobalSettings::dndEventDelay();
85 * QPoint newPos = e->pos();
86 * if(newPos.x() > mOldPos.x()+delay || newPos.x() < mOldPos.x()-delay ||
87 * newPos.y() > mOldPos.y()+delay || newPos.y() < mOldPos.y()-delay)
88 * {
89 * // Drag color object
90 * int cell = posToCell(mOldPos); // Find color at mOldPos
91 * if ((cell != -1) && colors[cell].isValid())
92 * {
93 * OColorDrag *d = OColorDrag::makeDrag( colors[cell], this);
94 * d->dragCopy();
95 * }
96 * }
97 * }
98 * </pre>
99 *
100 */
101
102 static int dndEventDelay();
103
104 /**
105 * Returns whether OPIE runs in single (default) or double click
106 * mode.
107 *
108 * @return @p true if single click mode, or @p false if double click mode.
109 *
110 * see @ref http://opie.handhelds.org/documentation/standards/opie/style/mouse/index.html
111 **/
112 static bool singleClick();
113
114 /**
115 * Returns whether tear-off handles are inserted in OPopupMenus.
116 **/
117 static bool insertTearOffHandle();
118
119 /**
120 * @return the OPIE setting for "change cursor over icon"
121 */
122 static bool changeCursorOverIcon();
123
124 /**
125 * @return whether to show some feedback when an item (specifically an
126 * icon) is activated.
127 */
128 static bool visualActivate();
129 static unsigned int visualActivateSpeed();
130
131 /**
132 * Returns the OPIE setting for the auto-select option
133 *
134 * @return the auto-select delay or -1 if auto-select is disabled.
135 */
136 static int autoSelectDelay();
137
138 /**
139 * Returns the OPIE setting for the shortcut key to open
140 * context menus.
141 *
142 * @return the key that pops up context menus.
143 */
144 static int contextMenuKey();
145
146 /**
147 * Returns the OPIE setting for context menus.
148 *
149 * @return whether context menus should be shown on button press
150 * or button release (click).
151 */
152 static bool showContextMenusOnPress ();
153
154 /**
155 * This enum describes the completion mode used for by the @ref OCompletion class.
156 * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/keys/completion.html">
157 * the styleguide</a>.
158 **/
159 enum Completion {
160 /**
161 * No completion is used.
162 */
163 CompletionNone=1,
164 /**
165 * Text is automatically filled in whenever possible.
166 */
167 CompletionAuto,
168 /**
169 * Same as automatic except shortest match is used for completion.
170 */
171 CompletionMan,
172 /**
173 * Complete text much in the same way as a typical *nix shell would.
174 */
175 CompletionShell,
176 /**
177 * Lists all possible matches in a popup list-box to choose from.
178 */
179 CompletionPopup,
180 /**
181 * Lists all possible matches in a popup list-box to choose from, and automatically
182 * fill the result whenever possible.
183 */
184 CompletionPopupAuto
185 };
186 /**
187 * Returns the preferred completion mode setting.
188 *
189 * @return @ref Completion. Default is @p CompletionPopup.
190 */
191 static Completion completionMode();
192
193 /**
194 * This enum describes the debug mode used for by the @ref odbgstream class.
195 * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/debug/debug.html">
196 * the styleguide</a>.
197 **/
198 enum Debug {
199 /**
200 * Debug messages are ignored.
201 */
202 DebugNone=-1,
203 /**
204 * Debug output is sent to files /var/log/***.
205 */
206 DebugFiles=0,
207 /**
208 * Debug output is written in a QMessageBox.
209 */
210 DebugMsgBox=1,
211 /**
212 * Debug output is sent to stderr.
213 */
214 DebugStdErr=2,
215 /**
216 * Debug output is sent to syslog.
217 */
218 DebugSysLog=3,
219 /**
220 * Debug output is sent via udp over a socket.
221 */
222 DebugSocket=4
223 };
224 /**
225 * Returns the preferred debug mode setting.
226 *
227 * @return @ref Debug. Default is @p DebugStdErr.
228 */
229 static Debug debugMode();
230
231 /**
232 * Returns additional information for debug output (dependent on the debug mode).
233 *
234 * @return Additional debug output information.
235 */
236 static QString debugOutput();
237 /**
238 * This is a structure containing the possible mouse settings.
239 */
240 struct OMouseSettings
241 {
242 enum { RightHanded = 0, LeftHanded = 1 };
243 int handed; // left or right
244 };
245
246 /**
247 * This returns the current mouse settings.
248 */
249 static OMouseSettings & mouseSettings();
250
251 /**
252 * The path to the desktop directory of the current user.
253 */
254 static QString desktopPath() { initStatic(); return *s_desktopPath; }
255
256 /**
257 * The path to the autostart directory of the current user.
258 */
259 static QString autostartPath() { initStatic(); return *s_autostartPath; }
260
261 /**
262 * The path to the trash directory of the current user.
263 */
264 static QString trashPath() { initStatic(); return *s_trashPath; }
265
266 /**
267 * The path where documents are stored of the current user.
268 */
269 static QString documentPath() { initStatic(); return *s_documentPath; }
270
271
272 /**
273 * The default color to use when highlighting toolbar buttons
274 */
275 static QColor toolBarHighlightColor();
276 static QColor inactiveTitleColor();
277 static QColor inactiveTextColor();
278 static QColor activeTitleColor();
279 static QColor activeTextColor();
280 static int contrast();
281
282 /**
283 * The default colors to use for text and links.
284 */
285 static QColor baseColor(); // Similair to QColorGroup::base()
286 static QColor textColor(); // Similair to QColorGroup::text()
287 static QColor linkColor();
288 static QColor visitedLinkColor();
289 static QColor highlightedTextColor(); // Similair to QColorGroup::hightlightedText()
290 static QColor highlightColor(); // Similair to QColorGroup::highlight()
291
292 /**
293 * Returns the alternate background color used by @ref OListView with
294 * @ref OListViewItem. Any other list that uses alternating background
295 * colors should use this too, to obey to the user's preferences. Returns
296 * an invalid color if the user doesn't want alternating backgrounds.
297 * @see #calculateAlternateBackgroundColor
298 */
299 static QColor alternateBackgroundColor();
300 /**
301 * Calculates a color based on @p base to be used as alternating
302 * color for e.g. listviews.
303 * @see #alternateBackgroundColor
304 */
305 static QColor calculateAlternateBackgroundColor(const QColor& base);
306
307
308 static QFont generalFont();
309 static QFont fixedFont();
310 static QFont toolBarFont();
311 static QFont menuFont();
312 static QFont windowTitleFont();
313 static QFont taskbarFont();
314
315 /**
316 * Returns if the user specified multihead. In case the display
317 * has multiple screens, the return value of this function specifies
318 * if the user wants OPIE to run on all of them or just on the primary
319 */
320 static bool isMultiHead();
321
322private:
323 /**
324 * reads in all paths from kdeglobals
325 */
326 static void initStatic();
327 /**
328 * initialise kde2Blue
329 */
330 static void initColors();
331 /**
332 * drop cached values for fonts (called by OApplication)
333 */
334 static void rereadFontSettings();
335 /**
336 * drop cached values for paths (called by OApplication)
337 */
338 static void rereadPathSettings();
339 /**
340 * drop cached values for mouse settings (called by OApplication)
341 */
342 static void rereadMouseSettings();
343
344
345 static QString* s_desktopPath;
346 static QString* s_autostartPath;
347 static QString* s_trashPath;
348 static QString* s_documentPath;
349 static QFont *_generalFont;
350 static QFont *_fixedFont;
351 static QFont *_toolBarFont;
352 static QFont *_menuFont;
353 static QFont *_windowTitleFont;
354 static QFont *_taskbarFont;
355 static QColor * kde2Gray;
356 static QColor * kde2Blue;
357 static QColor * kde2AlternateColor;
358 static OMouseSettings *s_mouseSettings;
359
360 static QColor * OpieGray;
361 static QColor * OpieBlue;
362 static QColor * OpieAlternate;
363 static QColor * OpieHighlight;
364
365 friend class OApplication;
366};
367
368#endif
diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro
new file mode 100644
index 0000000..ed7d6d7
--- a/dev/null
+++ b/libopie2/opiecore/opiecore.pro
@@ -0,0 +1,31 @@
1TEMPLATE = lib
2CONFIG += qt warn_on debug
3DESTDIR = $(OPIEDIR)/lib
4HEADERS = oapplication.h \
5 oconfig.h \
6 ocompletionbase.h \
7 ocompletion.h \
8 odebug.h \
9 oglobal.h \
10 oglobalsettings.h \
11 osortablevaluelist.h
12
13SOURCES = oapplication.cpp \
14 oconfig.cpp \
15 ocompletionbase.cpp \
16 ocompletion.cpp \
17 odebug.cpp \
18 oglobal.cpp \
19 oglobalsettings.cpp
20
21INTERFACES =
22TARGET = opiecore2
23VERSION = 1.8.1
24INCLUDEPATH += $(OPIEDIR)/include
25DEPENDPATH += $(OPIEDIR)/include
26LIBS = -lqpe
27MOC_DIR = moc
28OBJECTS_DIR = obj
29
30include ( $(OPIEDIR)/include.pro )
31