-rw-r--r-- | libopie2/opiecore/.cvsignore | 6 | ||||
-rw-r--r-- | libopie2/opiecore/config.in | 6 | ||||
-rw-r--r-- | libopie2/opiecore/oapplication.cpp | 110 | ||||
-rw-r--r-- | libopie2/opiecore/oapplication.h | 114 | ||||
-rw-r--r-- | libopie2/opiecore/oconfig.cpp | 201 | ||||
-rw-r--r-- | libopie2/opiecore/oconfig.h | 167 | ||||
-rw-r--r-- | libopie2/opiecore/odebug.cpp | 628 | ||||
-rw-r--r-- | libopie2/opiecore/odebug.h | 474 | ||||
-rw-r--r-- | libopie2/opiecore/oglobal.cpp | 36 | ||||
-rw-r--r-- | libopie2/opiecore/oglobal.h | 48 | ||||
-rw-r--r-- | libopie2/opiecore/oglobalsettings.cpp | 547 | ||||
-rw-r--r-- | libopie2/opiecore/oglobalsettings.h | 368 | ||||
-rw-r--r-- | libopie2/opiecore/opiecore.pro | 31 |
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 @@ +Makefile* +moc* +*moc +*.o +~* + 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 @@ + config LIBOPIE2CORE + boolean "libopie2core (application, configuration and debug related classes)" + default "n" + depends ( LIBQPE || LIBQPE-X11 ) + comment "libopie2core needs a libqpe (yet)" + 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 @@ +/* + This file is part of the Opie Project + + Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include <opie2/oapplication.h> +#include <opie2/oconfig.h> + +OApplication* OApplication::_instance = 0; + +/**************************************************************************************************/ +/* OApplicationPrivate +/**************************************************************************************************/ + +class OApplicationPrivate +{ + public: + OApplicationPrivate() {}; + ~OApplicationPrivate() {}; +}; + +/**************************************************************************************************/ +/* OApplication +/**************************************************************************************************/ + + +OApplication::OApplication( int& argc, char** argv, const QCString& rAppName ) + :OApplicationBaseClass( argc, argv ), + _appname( rAppName ), + _config( 0 ) +{ + init(); +} + + +OApplication::~OApplication() +{ + delete d; + if ( _config ) + delete _config; + OApplication::_instance = 0; + // after deconstruction of the one-and-only application object, + // the construction of another object is allowed +} + + +OConfig* OApplication::config() +{ + if ( not _config ) + { + _config = new OConfig( _appname ); + } + return _config; +} + + +void OApplication::init() +{ + d = new OApplicationPrivate(); + if ( !OApplication::_instance ) + { + OApplication::_instance = this; + } + else + { + qFatal( "OApplication: Can't create more than one OApplication object. Aborting." ); + } +} + +void OApplication::setMainWidget( QWidget* widget ) +{ + showMainWidget( widget ); +} + +void OApplication::showMainWidget( QWidget* widget, bool nomax ) +{ + #ifdef Q_WS_QWS + QPEApplication::showMainWidget( widget, nomax ); + #else + QApplication::setMainWidget( widget ); + widget->show(); + #endif + widget->setCaption( _appname ); + +} 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 @@ +/* + This file is part of the Opie Project + + Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OAPPLICATION_H +#define OAPPLICATION_H + +#define oApp OApplication::oApplication() + +#ifdef QWS + #include <qpe/qpeapplication.h> + #define OApplicationBaseClass QPEApplication +#else + #include <qapplication.h> + #define OApplicationBaseClass QApplication +#endif + +class OApplicationPrivate; +class OConfig; + +class OApplication: public OApplicationBaseClass +{ + public: + + /** + * Constructor. Parses command-line arguments and sets the window caption. + * + * @param rAppName application name. Will be used for finding the + * associated message, icon and configuration files + * + */ + OApplication( int& argc, char** argv, const QCString& rAppName ); + /** + * Destructor. Destroys the application object and its children. + */ + virtual ~OApplication(); + + /** + * Returns the current application object. + * + * This is similar to the global @ref QApplication pointer qApp. It + * allows access to the single global OApplication object, since + * more than one cannot be created in the same application. It + * saves you the trouble of having to pass the pointer explicitly + * to every function that may require it. + * @return the current application object + */ + static const OApplication* oApplication() { return _instance; }; + + /** + * Returns the application name as given during creation. + * + * @return A reference to the application name + */ + const QCString& appName() const { return _appname; }; + + /** + * Returns the application session config object. + * + * @return A pointer to the application's instance specific + * @ref OConfig object. + * @see OConfig + */ + OConfig* config(); + + /** + * Sets the main widget - reimplemented to call showMainWidget() + * on Qt/Embedded. + */ + virtual void setMainWidget( QWidget *mainWidget ); + + /** + * Shows the main widget - reimplemented to call setMainWidget() + * on platforms other than Qt/Embedded. + */ + virtual void showMainWidget( QWidget* widget, bool nomax = false ); + + protected: + void init(); + + private: + const QCString _appname; + static OApplication* _instance; + OConfig* _config; + OApplicationPrivate* d; +}; + +#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 @@ +/* + This file is part of the Opie Project + + (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> + Inspired by the config classes from the KDE Project which are + =. (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/* QT */ + +#include <qfont.h> +#include <qcolor.h> + +/* OPIE */ + +#include <opie2/oconfig.h> + +OConfig::OConfig( const QString &name, Domain domain ) + :Config( name, domain ) +{ +} + +OConfig::~OConfig() +{ +} + +QColor OConfig::readColorEntry( const QString& key, const QColor* pDefault ) const +{ + QColor aRetColor; + int nRed = 0, nGreen = 0, nBlue = 0; + + QString aValue = readEntry( key ); + if( !aValue.isEmpty() ) + { + if ( aValue.at(0) == '#' ) + { + aRetColor.setNamedColor(aValue); + } + else + { + bool bOK; + + // find first part (red) + int nIndex = aValue.find( ',' ); + + if( nIndex == -1 ) + { + // return a sensible default -- Bernd + if( pDefault ) + aRetColor = *pDefault; + return aRetColor; + } + + nRed = aValue.left( nIndex ).toInt( &bOK ); + + // find second part (green) + int nOldIndex = nIndex; + nIndex = aValue.find( ',', nOldIndex+1 ); + + if( nIndex == -1 ) + { + // return a sensible default -- Bernd + if( pDefault ) + aRetColor = *pDefault; + return aRetColor; + } + nGreen = aValue.mid( nOldIndex+1, + nIndex-nOldIndex-1 ).toInt( &bOK ); + + // find third part (blue) + nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK ); + + aRetColor.setRgb( nRed, nGreen, nBlue ); + } + } + else { + + if( pDefault ) + aRetColor = *pDefault; + } + + return aRetColor; +} + +// FIXME: The whole font handling has to be revised for Opie + +QFont OConfig::readFontEntry( const QString& key, const QFont* pDefault ) const +{ + /* + QFont aRetFont; + + QString aValue = readEntry( key ); + if( !aValue.isNull() ) { + if ( aValue.contains( ',' ) > 5 ) { + // KDE3 and upwards entry + if ( !aRetFont.fromString( aValue ) && pDefault ) + aRetFont = *pDefault; + } + else { + // backward compatibility with older font formats + // ### remove KDE 3.1 ? + // find first part (font family) + int nIndex = aValue.find( ',' ); + if( nIndex == -1 ){ + if( pDefault ) + aRetFont = *pDefault; + return aRetFont; + } + aRetFont.setFamily( aValue.left( nIndex ) ); + + // find second part (point size) + int nOldIndex = nIndex; + nIndex = aValue.find( ',', nOldIndex+1 ); + if( nIndex == -1 ){ + if( pDefault ) + aRetFont = *pDefault; + return aRetFont; + } + + aRetFont.setPointSize( aValue.mid( nOldIndex+1, + nIndex-nOldIndex-1 ).toInt() ); + + // find third part (style hint) + nOldIndex = nIndex; + nIndex = aValue.find( ',', nOldIndex+1 ); + + if( nIndex == -1 ){ + if( pDefault ) + aRetFont = *pDefault; + return aRetFont; + } + + aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() ); + + // find fourth part (char set) + nOldIndex = nIndex; + nIndex = aValue.find( ',', nOldIndex+1 ); + + if( nIndex == -1 ){ + if( pDefault ) + aRetFont = *pDefault; + return aRetFont; + } + + QString chStr=aValue.mid( nOldIndex+1, + nIndex-nOldIndex-1 ); + // find fifth part (weight) + nOldIndex = nIndex; + nIndex = aValue.find( ',', nOldIndex+1 ); + + if( nIndex == -1 ){ + if( pDefault ) + aRetFont = *pDefault; + return aRetFont; + } + + aRetFont.setWeight( aValue.mid( nOldIndex+1, + nIndex-nOldIndex-1 ).toUInt() ); + + // find sixth part (font bits) + uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt(); + + aRetFont.setItalic( nFontBits & 0x01 ); + aRetFont.setUnderline( nFontBits & 0x02 ); + aRetFont.setStrikeOut( nFontBits & 0x04 ); + aRetFont.setFixedPitch( nFontBits & 0x08 ); + aRetFont.setRawMode( nFontBits & 0x20 ); + } + } + else + { + if( pDefault ) + aRetFont = *pDefault; + } + return aRetFont; + */ + return QFont("Helvetica",10); +} 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 @@ +/* + This file is part of the Opie Project + + (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + Inspired by the config classes from the KDE Project which are + =. (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OCONFIG_H +#define OCONFIG_H + +//FIXME: Implement for X11 or reuse libqpe/Config there also? + +#include <qpe/config.h> + +class QColor; +class QFont; + +/** + * A Configuration class based on the Qtopia @ref Config class + * featuring additional handling of color and font entries + */ + +class OConfig : public Config +{ + public: + + /** + * Constructs a OConfig object. + * + * @param name A file to parse. + */ + OConfig( const QString &name, Domain domain = User ); + + /** + * Destructs the OConfig object. + * + * Writes back any dirty configuration entries, and destroys + * dynamically created objects. + */ + virtual ~OConfig(); + + /** + * Returns the name of the group in which we are + * searching for keys and from which we are retrieving entries. + * + * @return The current group. + */ + const QString& group() { return git.key(); }; + + /** + * Reads a @ref QColor entry. + * + * Read the value of an entry specified by @p pKey in the current group + * and interpret it as a color. + * + * @param pKey The key to search for. + * @param pDefault A default value (null QColor by default) returned if the + * key was not found or if the value cannot be interpreted. + * @return The value for this key. + */ + QColor readColorEntry( const QString& key, const QColor* pDefault ) const; + + /** + * Reads a @ref QFont value. + * + * Read the value of an entry specified by @p pKey in the current group + * and interpret it as a font object. + * + * @param pKey The key to search for. + * @param pDefault A default value (null QFont by default) returned if the + * key was not found or if the read value cannot be interpreted. + * @return The value for this key. + */ + QFont readFontEntry( const QString& key, const QFont* pDefault ) const; + +}; + +/** + * Helper class to facilitate working with @ref OConfig / @ref OSimpleConfig + * groups. + * + * Careful programmers always set the group of a + * @ref OConfig object to the group they want to read from + * and set it back to the old one of afterwards. This is usually + * written as: + * <pre> + * + * QString oldgroup config()->group(); + * config()->setGroup( "TheGroupThatIWant" ); + * ... + * config()->writeEntry( "Blah", "Blubb" ); + * + * config()->setGroup( oldgroup ); + * </pre> + * + * In order to facilitate this task, you can use + * OConfigGroupSaver. Simply construct such an object ON THE STACK + * when you want to switch to a new group. Then, when the object goes + * out of scope, the group will automatically be restored. If you + * want to use several different groups within a function or method, + * you can still use OConfigGroupSaver: Simply enclose all work with + * one group (including the creation of the OConfigGroupSaver object) + * in one block. + * + * @author Matthias Kalle Dalheimer <Kalle@kde.org> + * @version $Id$ + * @see OConfig + * @short Helper class for easier use of OConfig groups + */ + +class OConfigGroupSaver +{ + public: + /** + * Constructor. You pass a pointer to the OConfigBase-derived + * object you want to work with and a string indicating the _new_ + * group. + * @param config The OConfig-derived object this + * OConfigGroupSaver works on. + * @param group The new group that the config object should switch to. + */ + OConfigGroupSaver( OConfig* config, QString group ) :_config(config), _oldgroup(config->group() ) + { _config->setGroup( group ); } + + OConfigGroupSaver( OConfig* config, const char *group ) :_config(config), _oldgroup(config->group()) + { _config->setGroup( group ); } + + OConfigGroupSaver( OConfig* config, const QCString &group ) : _config(config), _oldgroup(config->group()) + { _config->setGroup( group ); } + + ~OConfigGroupSaver() { _config->setGroup( _oldgroup ); } + + OConfig* config() { return _config; }; + + private: + OConfig* _config; + QString _oldgroup; + + OConfigGroupSaver( const OConfigGroupSaver& ); + OConfigGroupSaver& operator=( const OConfigGroupSaver& ); +}; + +#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 @@ +/* + This file is part of the Opie Project + (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) + Inspired by the KDE debug classes, which are + (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) + (C) 2002 Holger Freyther (freyther@kde.org) + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo +// functions inlined to noops (which would then conflict with their definition here). + +#include <opie2/odebug.h> + +#ifdef OPIE_NO_DEBUG +#undef odDebug +#undef odBacktrace +#endif + +/* OPIE */ + +#include <opie2/oapplication.h> +#include <opie2/oglobalsettings.h> +#include <opie2/oconfig.h> + +/* QT */ + +#include <qbrush.h> +#include <qdatetime.h> +#include <qfile.h> +#include <qhostaddress.h> +#include <qmessagebox.h> +#include <qintdict.h> +#include <qpoint.h> +#include <qrect.h> +#include <qregion.h> +#include <qsize.h> +#include <qsocketdevice.h> +#include <qstring.h> +#include <qstringlist.h> +#include <qtextstream.h> + +/* UNIX */ + +#include <stdlib.h> // abort +#include <unistd.h> // getpid +#include <stdarg.h> // vararg stuff +#include <ctype.h> // isprint +#include <syslog.h> +#include <errno.h> +#include <string.h> + +#ifndef OPIE_NO_BACKTRACE +#include <execinfo.h> +#endif + + +/*====================================================================================== + * debug levels + *======================================================================================*/ + +enum DebugLevels { + ODEBUG_INFO = 0, + ODEBUG_WARN = 1, + ODEBUG_ERROR = 2, + ODEBUG_FATAL = 3 +}; + +/*====================================================================================== + * oDebug private data + *======================================================================================*/ + +/*====================================================================================== + * the main debug function + *======================================================================================*/ + +static void oDebugBackend( unsigned short level, unsigned int area, const char *data) +{ + //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); + + // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an + // ML: example use. I think it's not necessary to implement such a strategy here. + // ML: Comments? + + int priority = 0; + QString caption; + QString lev; + switch( level ) + { + case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; + case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; + case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; + default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); + case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; + } + + short output = OGlobalSettings::debugMode(); + if (!oApp && (output == 1)) + { + qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); + output = 2; // need an application object to use MsgBox + } + + QString areaName = (oApp) ? oApp->appName() : "<unknown>"; + + // Output + switch( output ) + { + case -1: // ignore + { + return; + } + case 0: // File + { + QString outputFilename = OGlobalSettings::debugOutput(); + + const int BUFSIZE = 4096; + char buf[BUFSIZE] = ""; + buf[BUFSIZE-1] = '\0'; + int nSize; + + nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); + + QFile outputFile( outputFilename ); + if ( outputFile.open( IO_WriteOnly | IO_Append ) ) + { + if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) + { + outputFile.writeBlock( buf, BUFSIZE-1 ); + } + else + { + outputFile.writeBlock( buf, nSize ); + } + } + else + { + qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); + } + break; + } // automatic close of file here + + case 1: // Message Box + { + // Since we are in opiecore here, we cannot use OMsgBox and use + // QMessageBox instead + + caption += QString("(") + areaName + ")"; + QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? + break; + } + + case 2: // Shell + { + FILE *output = stderr; + fprintf( output, "%s: ", (const char*) areaName ); + fputs( data, output); + break; + } + + case 3: // syslog + { + syslog( priority, "%s", data); + break; + } + + case 4: // socket + { + QString destination = OGlobalSettings::debugOutput(); + if ( destination && destination.find(":") != -1 ) + { + QString host = destination.left( destination.find(":") ); + QString port = destination.right( destination.length()-host.length()-1 ); + QHostAddress addr; + addr.setAddress( host ); + // TODO: sanity check the address + QString line; + line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); + QSocketDevice s( QSocketDevice::Datagram ); + int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); + if ( result == -1 ) + { + qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); + } + } + break; + } + } + + // check if we should abort + + /* + + if( ( nLevel == ODEBUG_FATAL ) + && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) + abort(); + + */ +} + +/*====================================================================================== + * odbgstream + *======================================================================================*/ + +odbgstream& perror( odbgstream &s) +{ + return s << QString::fromLocal8Bit(strerror(errno)); +} + +odbgstream odDebug(int area) +{ + return odbgstream(area, ODEBUG_INFO); +} +odbgstream odDebug(bool cond, int area) +{ + if (cond) return odbgstream(area, ODEBUG_INFO); + else return odbgstream(0, 0, false); +} + +odbgstream odError(int area) +{ + return odbgstream("ERROR: ", area, ODEBUG_ERROR); +} + +odbgstream odError(bool cond, int area) +{ + if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); +} + +odbgstream odWarning(int area) +{ + return odbgstream("WARNING: ", area, ODEBUG_WARN); +} + +odbgstream odWarning(bool cond, int area) +{ + if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); +} + +odbgstream odFatal(int area) +{ + return odbgstream("FATAL: ", area, ODEBUG_FATAL); +} + +odbgstream odFatal(bool cond, int area) +{ + if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false); +} + +odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) + :area(_area), level(_level), print(_print) +{ +} + + +odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print) + :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) +{ +} + + +odbgstream::odbgstream(odbgstream &str) + :output(str.output), area(str.area), level(str.level), print(str.print) +{ + str.output.truncate(0); +} + + +odbgstream::odbgstream(const odbgstream &str) + :output(str.output), area(str.area), level(str.level), print(str.print) +{ +} + +odbgstream& odbgstream::operator<<(bool i) +{ + if (!print) return *this; + output += QString::fromLatin1(i ? "true" : "false"); + return *this; +} + + +odbgstream& odbgstream::operator<<(short i) +{ + if (!print) return *this; + QString tmp; tmp.setNum(i); output += tmp; + return *this; +} + + +odbgstream& odbgstream::operator<<(unsigned short i) +{ + if (!print) return *this; + QString tmp; tmp.setNum(i); output += tmp; + return *this; +} + + +odbgstream& odbgstream::operator<<(unsigned char i) +{ + return operator<<( static_cast<char>( i ) ); +} + + +odbgstream& odbgstream::operator<<(int i) +{ + if (!print) return *this; + QString tmp; tmp.setNum(i); output += tmp; + return *this; +} + + +odbgstream& odbgstream::operator<<(unsigned int i) +{ + if (!print) return *this; + QString tmp; tmp.setNum(i); output += tmp; + return *this; +} + + +odbgstream& odbgstream::operator<<(long i) +{ + if (!print) return *this; + QString tmp; tmp.setNum(i); output += tmp; + return *this; +} + + +odbgstream& odbgstream::operator<<(unsigned long i) +{ + if (!print) return *this; + QString tmp; tmp.setNum(i); output += tmp; + return *this; +} + + +odbgstream& odbgstream::operator<<(const QString& string) +{ + if (!print) return *this; + output += string; + if (output.at(output.length() -1 ) == '\n') + flush(); + return *this; +} + + +odbgstream& odbgstream::operator<<(const char *string) +{ + if (!print) return *this; + output += QString::fromUtf8(string); + if (output.at(output.length() - 1) == '\n') + flush(); + return *this; +} + + +odbgstream& odbgstream::operator<<(const QCString& string) +{ + *this << string.data(); + return *this; +} + + +odbgstream& odbgstream::operator<<(const void * p) +{ + form("%p", p); + return *this; +} + +odbgstream& odbgstream::operator<<(double d) +{ + QString tmp; tmp.setNum(d); output += tmp; + return *this; +} + +/* +odbgstream::odbgstream &form(const char *format, ...) +#ifdef __GNUC__ + __attribute__ ( ( format ( printf, 2, 3 ) ) ) +#endif + ; +*/ + +void odbgstream::flush() +{ + if ( output.isEmpty() || !print ) + { + return; + } + else + { + oDebugBackend( level, area, output.local8Bit().data() ); + output = QString::null; + } +} + +odbgstream& odbgstream::form(const char *format, ...) +{ + char buf[4096]; + va_list arguments; + va_start( arguments, format ); + buf[sizeof(buf)-1] = '\0'; + vsnprintf( buf, sizeof(buf)-1, format, arguments ); + va_end(arguments); + *this << buf; + return *this; +} + +odbgstream::~odbgstream() +{ + if (!output.isEmpty()) + { + fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); + *this << "\n"; + } +} + +odbgstream& odbgstream::operator<<(char ch) +{ + if (!print) return *this; + if (!isprint(ch)) + { + output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); + } + else + { + output += ch; + if (ch == '\n') flush(); + } + return *this; +} + +odbgstream& odbgstream::operator<<( QWidget* widget ) +{ + QString string, temp; + // ----- + if(widget==0) + { + string=(QString)"[Null pointer]"; + } else + { + temp.setNum((ulong)widget, 16); + string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; + if(widget->name(0)==0) + { + string += " to unnamed widget, "; + } else + { + string += (QString)" to widget " + widget->name() + ", "; + } + string += "geometry=" + + QString().setNum(widget->width()) + + "x"+QString().setNum(widget->height()) + + "+"+QString().setNum(widget->x()) + + "+"+QString().setNum(widget->y()) + + "]"; + } + if (!print) return *this; + + output += string; + if (output.at(output.length()-1) == '\n') + { + flush(); + } + return *this; +} + +/* + * either use 'output' directly and do the flush if needed + * or use the QString operator which calls the char* operator + * + */ +odbgstream& odbgstream::operator<<( const QDateTime& time) +{ + *this << time.toString(); + return *this; +} + + +odbgstream& odbgstream::operator<<( const QDate& date) +{ + *this << date.toString(); + + return *this; +} + + +odbgstream& odbgstream::operator<<( const QTime& time ) +{ + *this << time.toString(); + return *this; +} + + +odbgstream& odbgstream::operator<<( const QPoint& p ) +{ + *this << "(" << p.x() << ", " << p.y() << ")"; + return *this; +} + + +odbgstream& odbgstream::operator<<( const QSize& s ) +{ + *this << "[" << s.width() << "x" << s.height() << "]"; + return *this; +} + + +odbgstream& odbgstream::operator<<( const QRect& r ) +{ + *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]"; + return *this; +} + + +odbgstream& odbgstream::operator<<( const QRegion& reg ) +{ + /* Qt2 doesn't have a QMemArray... :( + *this << "[ "; + QMemArray<QRect>rs=reg.rects(); + for (uint i=0;i<rs.size();++i) + *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; + *this <<"]"; + */ + return *this; +} + + +odbgstream& odbgstream::operator<<( const QStringList& l ) +{ + *this << "("; + *this << l.join(","); + *this << ")"; + + return *this; +} + + +odbgstream& odbgstream::operator<<( const QColor& c ) +{ + if ( c.isValid() ) + *this << c.name(); + else + *this << "(invalid/default)"; + return *this; +} + + +odbgstream& odbgstream::operator<<( const QBrush& b) +{ + static const char* const s_brushStyles[] = { + "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern", + "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern", + "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern", + "DiagCrossPattern" }; + + *this <<"[ style: "; + *this <<s_brushStyles[ b.style() ]; + *this <<" color: "; + // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes) + if ( b.color().isValid() ) + *this <<b.color().name() ; + else + *this <<"(invalid/default)"; + if ( b.pixmap() ) + *this <<" has a pixmap"; + *this <<" ]"; + return *this; +} + + + +QString odBacktrace( int levels ) +{ + QString s; +#ifndef OPIE_NO_BACKTRACE + void* trace[256]; + int n = backtrace(trace, 256); + char** strings = backtrace_symbols (trace, n); + + if ( levels != -1 ) + n = QMIN( n, levels ); + s = "[\n"; + + for (int i = 0; i < n; ++i) + s += QString::number(i) + + QString::fromLatin1(": ") + + QString::fromLatin1(strings[i]) + QString::fromLatin1("\n"); + s += "]\n"; + free (strings); +#endif + return s; +} + +void odClearDebugConfig() +{ + /* + delete oDebug_data->config; + oDebug_data->config = 0; + */ +} + +#ifdef OPIE_NO_DEBUG +#define odDebug ondDebug +#define odBacktrace ondBacktrace +#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 @@ +/* + This file is part of the Opie Project + (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) + Inspired by the KDE debug classes, which are + (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) + (C) 2002 Holger Freyther (freyther@kde.org) + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef ODEBUG_H +#define ODEBUG_H + +#include <qstring.h> + +class QWidget; +class QDateTime; +class QDate; +class QTime; +class QPoint; +class QSize; +class QRect; +class QRegion; +class QStringList; +class QColor; +class QBrush; + +class odbgstream; +class ondbgstream; + +#ifdef __GNUC__ +#define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] " +#else +#define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] " +#endif + +#define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] " + +#define owarn odWarning() +#define oerr odError() +#define odebug odDebug() +#define ofatal odFatal() +#define oendl "\n" + +class odbgstreamprivate; +/** + * odbgstream is a text stream that allows you to print debug messages. + * Using the overloaded "<<" operator you can send messages. Usually + * you do not create the odbgstream yourself, but use @ref odDebug() (odebug) + * @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one. + * + * Example: + * <pre> + * int i = 5; + * odebug << "The value of i is " << i << oendl; + * </pre> + * @see odbgstream + */ + +/*====================================================================================== + * odbgstream + *======================================================================================*/ + +class odbgstream +{ + public: + /** + * @internal + */ + odbgstream(unsigned int _area, unsigned int _level, bool _print = true); + odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true); + odbgstream(odbgstream &str); + odbgstream(const odbgstream &str); + virtual ~odbgstream(); + + /** + * Prints the given value. + * @param i the boolean to print (as "true" or "false") + * @return this stream + */ + odbgstream &operator<<(bool i); + /** + * Prints the given value. + * @param i the short to print + * @return this stream + */ + odbgstream &operator<<(short i); + /** + * Prints the given value. + * @param i the unsigned short to print + * @return this stream + */ + odbgstream &operator<<(unsigned short i); + /** + * Prints the given value. + * @param i the char to print + * @return this stream + */ + odbgstream &operator<<(char i); + /** + * Prints the given value. + * @param i the unsigned char to print + * @return this stream + */ + odbgstream &operator<<(unsigned char i); + /** + * Prints the given value. + * @param i the int to print + * @return this stream + */ + odbgstream &operator<<(int i); + /** + * Prints the given value. + * @param i the unsigned int to print + * @return this stream + */ + odbgstream &operator<<(unsigned int i); + /** + * Prints the given value. + * @param i the long to print + * @return this stream + */ + odbgstream &operator<<(long i); + /** + * Prints the given value. + * @param i the unsigned long to print + * @return this stream + */ + odbgstream &operator<<(unsigned long i); + /** + * Flushes the output. + */ + virtual void flush(); + /** + * Prints the given value. + * @param string the string to print + * @return this stream + */ + odbgstream &operator<<(const QString& string); + /** + * Prints the given value. + * @param string the string to print + * @return this stream + */ + odbgstream &operator<<(const char *string); + /** + * Prints the given value. + * @param string the string to print + * @return this stream + */ + odbgstream &operator<<(const QCString& string); + /** + * Prints the given value. + * @param p a pointer to print (in number form) + * @return this stream + */ + odbgstream& operator<<(const void * p); + /** + * Prints the given value. + * @param d the double to print + * @return this stream + */ + odbgstream& operator<<(double d); + /** + * Prints the string @p format which can contain + * printf-style formatted values. + * @param format the printf-style format + * @return this stream + */ + odbgstream &form(const char *format, ...); + /** Operator to print out basic information about a QWidget. + * Output of class names only works if the class is moc'ified. + * @param widget the widget to print + * @return this stream + */ + odbgstream& operator<< (QWidget* widget); + + /** + * Prints the given value. + * @param dateTime the datetime to print + * @return this stream + */ + odbgstream& operator<< ( const QDateTime& dateTime ); + + /** + * Prints the given value. + * @param date the date to print + * @return this stream + */ + odbgstream& operator<< ( const QDate& date ); + + /** + * Prints the given value. + * @param time the time to print + * @return this stream + */ + odbgstream& operator<< ( const QTime& time ); + + /** + * Prints the given value. + * @param point the point to print + * @return this stream + */ + odbgstream& operator<< ( const QPoint& point ); + + /** + * Prints the given value. + * @param size the QSize to print + * @return this stream + */ + odbgstream& operator<< ( const QSize& size ); + + /** + * Prints the given value. + * @param rect the QRect to print + * @return this stream + */ + odbgstream& operator<< ( const QRect& rect); + + /** + * Prints the given value. + * @param region the QRegion to print + * @return this stream + */ + odbgstream& operator<< ( const QRegion& region); + + /** + * Prints the given value. + * @param list the stringlist to print + * @return this stream + */ + odbgstream& operator<< ( const QStringList& list); + + /** + * Prints the given value. + * @param color the color to print + * @return this stream + */ + odbgstream& operator<< ( const QColor& color); + + /** + * Prints the given value. + * @param brush the brush to print + * @return this stream + */ + odbgstream& operator<< ( const QBrush& brush ); + + private: + QString output; + unsigned int area, level; + bool print; + odbgstreamprivate* d; +}; + +/** + * Prints an "\n". + * @param s the debug stream to write to + * @return the debug stream (@p s) + */ +inline odbgstream& endl( odbgstream &s) { s << "\n"; return s; } +/** + * Flushes the stream. + * @param s the debug stream to write to + * @return the debug stream (@p s) + */ +inline odbgstream& flush( odbgstream &s) { s.flush(); return s; } + +odbgstream &perror( odbgstream &s); + +/** + * ondbgstream is a dummy variant of @ref odbgstream. All functions do + * nothing. + * @see ondDebug() + */ +class ondbgstream { + public: + /// Empty constructor. + ondbgstream() {} + ~ondbgstream() {} + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(short int ) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(unsigned short int ) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(char ) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(unsigned char ) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(int ) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(unsigned int ) { return *this; } + /** + * Does nothing. + */ + void flush() {} + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(const QString& ) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(const QCString& ) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &operator<<(const char *) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream& operator<<(const void *) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream& operator<<(void *) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream& operator<<(double) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream& operator<<(long) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream& operator<<(unsigned long) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream& operator << (QWidget*) { return *this; } + /** + * Does nothing. + * @return this stream + */ + ondbgstream &form(const char *, ...) { return *this; } + + ondbgstream& operator<<( const QDateTime& ) { return *this; } + ondbgstream& operator<<( const QDate& ) { return *this; } + ondbgstream& operator<<( const QTime& ) { return *this; } + ondbgstream& operator<<( const QPoint & ) { return *this; } + ondbgstream& operator<<( const QSize & ) { return *this; } + ondbgstream& operator<<( const QRect & ) { return *this; } + ondbgstream& operator<<( const QRegion & ) { return *this; } + ondbgstream& operator<<( const QStringList & ) { return *this; } + ondbgstream& operator<<( const QColor & ) { return *this; } + ondbgstream& operator<<( const QBrush & ) { return *this; } +}; + +/*====================================================================================== + * related functions + *======================================================================================*/ + +/** + * Does nothing. + * @param a stream + * @return the given @p s + */ +inline ondbgstream& endl( ondbgstream & s) { return s; } +/** + * Does nothing. + * @param a stream + * @return the given @p s + */ +inline ondbgstream& flush( ondbgstream & s) { return s; } +inline ondbgstream& perror( ondbgstream & s) { return s; } + +/** + * Returns a debug stream. You can use it to print debug + * information. + * @param area an id to identify the output, 0 for default + */ +odbgstream odDebug(int area = 0); +odbgstream odDebug(bool cond, int area = 0); +/** + * Returns a backtrace. + * @param levels the number of levels (-1 for unlimited) of the backtrace + * @return a backtrace + */ +QString odBacktrace(int levels = -1); +/** + * Returns a dummy debug stream. The stream does not print anything. + * @param area an id to identify the output, 0 for default + * @see odDebug() + */ +inline ondbgstream ondDebug(int = 0) { return ondbgstream(); } +inline ondbgstream ondDebug(bool , int = 0) { return ondbgstream(); } +inline QString ondBacktrace() { return QString::null; } +inline QString ondBacktrace(int) { return QString::null; } + +/** + * Returns a warning stream. You can use it to print warning + * information. + * @param area an id to identify the output, 0 for default + */ +odbgstream odWarning(int area = 0); +odbgstream odWarning(bool cond, int area = 0); +/** + * Returns an error stream. You can use it to print error + * information. + * @param area an id to identify the output, 0 for default + */ +odbgstream odError(int area = 0); +odbgstream odError(bool cond, int area = 0); +/** + * Returns a fatal error stream. You can use it to print fatal error + * information. + * @param area an id to identify the output, 0 for default + */ +odbgstream odFatal(int area = 0); +odbgstream odFatal(bool cond, int area = 0); + +/** + * Deletes the odebugrc cache and therefore forces KDebug to reread the + * config file + */ +void odClearDebugConfig(); + +#ifdef OPIE_NO_DEBUG +#define odDebug ondDebug +#define odBacktrace ondBacktrace +#endif + +#endif + 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 @@ +/* + This file is part of the Opie Project + + Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include <opie2/oglobal.h> + +OConfig* OGlobal::config() +{ + return &globalconfig; +} 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 @@ +/* + This file is part of the Opie Project + + Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OGLOBAL_H +#define OGLOBAL_H + +#include <qpe/global.h> +#include <opie2/oconfig.h> + +static OConfig globalconfig = OConfig( "global" ); + +//FIXME: Is it wise or even necessary to inherit OGlobal from Global? + +class OGlobal : public Global +{ + public: + + static OConfig* config(); +}; + +#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 @@ +/* + This file is part of the Opie Project + + Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> + Inspired by the KDE globalsettings which are + Copyright (C) 2000 David Faure <faure@kde.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/* OPIE */ + +#include <opie2/oglobalsettings.h> +#include <opie2/oconfig.h> +#include <opie2/oglobal.h> + +/* QT */ + +#include <qdir.h> +#include <qpixmap.h> +#include <qfontinfo.h> + +/* UNIX */ + +#include <stdlib.h> + +QString* OGlobalSettings::s_desktopPath = 0; +QString* OGlobalSettings::s_autostartPath = 0; +QString* OGlobalSettings::s_trashPath = 0; +QString* OGlobalSettings::s_documentPath = 0; +QFont *OGlobalSettings::_generalFont = 0; +QFont *OGlobalSettings::_fixedFont = 0; +QFont *OGlobalSettings::_toolBarFont = 0; +QFont *OGlobalSettings::_menuFont = 0; +QFont *OGlobalSettings::_windowTitleFont = 0; +QFont *OGlobalSettings::_taskbarFont = 0; + +QColor *OGlobalSettings::OpieGray = 0; +QColor *OGlobalSettings::OpieHighlight = 0; +QColor *OGlobalSettings::OpieAlternate = 0; + +OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0; + +//FIXME: Add manipulators to the accessors + +int OGlobalSettings::dndEventDelay() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "General" ); + return c->readNumEntry("DndDelay", 2); +} + +bool OGlobalSettings::singleClick() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "OPIE" ); + return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK); +} + +bool OGlobalSettings::insertTearOffHandle() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "OPIE" ); + return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES); +} + +bool OGlobalSettings::changeCursorOverIcon() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "OPIE" ); + return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR); +} + +bool OGlobalSettings::visualActivate() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "OPIE" ); + return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE); +} + +unsigned int OGlobalSettings::visualActivateSpeed() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "OPIE" ); + return + c->readNumEntry( + "VisualActivateSpeed", + OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED + ); +} + +int OGlobalSettings::autoSelectDelay() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "OPIE" ); + return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY); +} + +OGlobalSettings::Completion OGlobalSettings::completionMode() +{ + int completion; + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "General" ); + completion = c->readNumEntry("completionMode", -1); + if ((completion < (int) CompletionNone) || + (completion > (int) CompletionPopupAuto)) + { + completion = (int) CompletionPopup; // Default + } + return (Completion) completion; +} + + +bool OGlobalSettings::showContextMenusOnPress () +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs (c, "ContextMenus"); + + return cgs.config()->readBoolEntry("ShowOnPress", true); +} + + +int OGlobalSettings::contextMenuKey () +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs (c, "Shortcuts"); + + //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu")); + //return cut.keyCodeQt(); + + return 0; // FIXME +} + + +OGlobalSettings::Debug OGlobalSettings::debugMode() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "General" ); + int debug = c->readNumEntry( "debugMode", -1 ); + if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) ) + { + debug = (int) DebugStdErr; // Default + } + return (Debug) debug; +} + + +QString OGlobalSettings::debugOutput() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, "General" ); + QString deflt = QString::null; + switch( debugMode() ) + { + case DebugNone: break; // no additional information needed + case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in + case DebugMsgBox: break; // no additional information needed + case DebugStdErr: break; // no additional information needed + case DebugSysLog: break; // no additional information needed + case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to + } + + return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt ); +} + + +QColor OGlobalSettings::toolBarHighlightColor() +{ + initColors(); + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") ); + return c->readColorEntry("HighlightColor", OpieHighlight); +} + +QColor OGlobalSettings::inactiveTitleColor() +{ + if (!OpieGray) OpieGray = new QColor(220, 220, 220); + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); + return c->readColorEntry( "inactiveBackground", OpieGray ); +} + +QColor OGlobalSettings::inactiveTextColor() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); + return c->readColorEntry( "inactiveForeground", &Qt::darkGray ); +} + +QColor OGlobalSettings::activeTitleColor() +{ + initColors(); + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); + return c->readColorEntry( "activeBackground", OpieHighlight); +} + +QColor OGlobalSettings::activeTextColor() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); + return c->readColorEntry( "activeForeground", &Qt::white ); +} + +int OGlobalSettings::contrast() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") ); + return c->readNumEntry( "contrast", 7 ); +} + +// following functions should work in OPIE - how to sync with appearance changes? + +QColor OGlobalSettings::baseColor() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + return c->readColorEntry( "Base", &Qt::white ); +} + +QColor OGlobalSettings::textColor() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + return c->readColorEntry( "Text", &Qt::black ); +} + +QColor OGlobalSettings::highlightedTextColor() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + return c->readColorEntry( "HighlightedText", &Qt::white ); +} + +QColor OGlobalSettings::highlightColor() +{ + initColors(); + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + return c->readColorEntry( "Highlight", OpieHighlight ); +} + +QColor OGlobalSettings::alternateBackgroundColor() +{ + initColors(); + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + *OpieAlternate = calculateAlternateBackgroundColor( baseColor() ); + return c->readColorEntry( "alternateBackground", OpieAlternate ); +} + +QColor OGlobalSettings::calculateAlternateBackgroundColor(const QColor& base) +{ + if (base == Qt::white) + return QColor(238,246,255); + else + { + int h, s, v; + base.hsv( &h, &s, &v ); + if (v > 128) + return base.dark(106); + else if (base != Qt::black) + return base.light(110); + + return QColor(32,32,32); + } +} + +QColor OGlobalSettings::linkColor() +{ + initColors(); + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + return c->readColorEntry( "linkColor", OpieGray ); +} + +QColor OGlobalSettings::visitedLinkColor() +{ + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + return c->readColorEntry( "visitedLinkColor", &Qt::magenta ); +} + +// FIXME: font stuff currently uses a different format in OPIE, so the +// functions below are not yet applicable. The whole font stuff for OPIE +// has to be revised anyway + +QFont OGlobalSettings::generalFont() +{ + if (_generalFont) + return *_generalFont; + + _generalFont = new QFont("helvetica", 10); + _generalFont->setPixelSize(10); + _generalFont->setStyleHint(QFont::SansSerif); + + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); + *_generalFont = c->readFontEntry("font", _generalFont); + + return *_generalFont; +} + +QFont OGlobalSettings::fixedFont() +{ + if (_fixedFont) + return *_fixedFont; + + _fixedFont = new QFont("courier", 12); + _fixedFont->setPixelSize(12); + _fixedFont->setStyleHint(QFont::TypeWriter); + + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); + *_fixedFont = c->readFontEntry("fixed", _fixedFont); + + return *_fixedFont; +} + +QFont OGlobalSettings::toolBarFont() +{ + if(_toolBarFont) + return *_toolBarFont; + + _toolBarFont = new QFont("helvetica", 10); + _toolBarFont->setPixelSize(10); + _toolBarFont->setStyleHint(QFont::SansSerif); + + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); + *_toolBarFont = c->readFontEntry("toolBarFont", _toolBarFont); + + return *_toolBarFont; +} + +QFont OGlobalSettings::menuFont() +{ + if(_menuFont) + return *_menuFont; + + _menuFont = new QFont("helvetica", 12); + _menuFont->setPixelSize(12); + _menuFont->setStyleHint(QFont::SansSerif); + + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); + *_menuFont = c->readFontEntry("menuFont", _menuFont); + + return *_menuFont; +} + +QFont OGlobalSettings::windowTitleFont() +{ + if(_windowTitleFont) + return *_windowTitleFont; + + _windowTitleFont = new QFont("helvetica", 12, QFont::Bold); + _windowTitleFont->setPixelSize(12); + _windowTitleFont->setStyleHint(QFont::SansSerif); + + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); + *_windowTitleFont = c->readFontEntry("activeFont", _windowTitleFont); // inconsistency + + return *_windowTitleFont; +} + +QFont OGlobalSettings::taskbarFont() +{ + if(_taskbarFont) + return *_taskbarFont; + + _taskbarFont = new QFont("helvetica", 8); + _taskbarFont->setPixelSize(8); + _taskbarFont->setStyleHint(QFont::SansSerif); + + OConfig *c = OGlobal::config(); + OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); + *_taskbarFont = c->readFontEntry("taskbarFont", _taskbarFont); + + return *_taskbarFont; +} + +// FIXME: the whole path stuff has to be revised for OPIE + +void OGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here. +{ + if ( s_desktopPath != 0 ) + return; + + s_desktopPath = new QString(); + s_autostartPath = new QString(); + s_trashPath = new QString(); + s_documentPath = new QString(); + + OConfig *config = OGlobal::config(); + //bool dollarExpansion = config->isDollarExpansion(); + //config->setDollarExpansion(true); + OConfigGroupSaver cgs( config, "Paths" ); + + // Desktop Path + *s_desktopPath = QDir::homeDirPath() + "/" + "Desktop" + "/"; + *s_desktopPath = config->readEntry( "Desktop", *s_desktopPath); + if ( (*s_desktopPath)[0] != '/' ) + s_desktopPath->prepend( QDir::homeDirPath() + "/" ); + *s_desktopPath = QDir::cleanDirPath( *s_desktopPath ); + if ( s_desktopPath->right(1) != "/") + *s_desktopPath += "/"; + + // Trash Path + *s_trashPath = *s_desktopPath + QObject::tr("Trash") + "/"; + *s_trashPath = config->readEntry( "Trash" , *s_trashPath); + if ( (*s_trashPath)[0] != '/' ) + s_trashPath->prepend( QDir::homeDirPath() + "/" ); + *s_trashPath = QDir::cleanDirPath( *s_trashPath ); + if ( s_trashPath->right(1) != "/") + *s_trashPath += "/"; + // We need to save it in any case, in case the language changes later on, + if ( !config->hasKey( "Trash" ) ) + { + //config->writePathEntry( "Trash", *s_trashPath, true, true ); + config->writeEntry( "Trash", *s_trashPath ); + //config->sync(); + } + +/* // Autostart Path + *s_autostartPath = OGlobal::dirs()->localkdedir() + "Autostart" + "/"; + *s_autostartPath = config->readEntry( "Autostart" , *s_autostartPath); + if ( (*s_autostartPath)[0] != '/' ) + s_autostartPath->prepend( QDir::homeDirPath() + "/" ); + *s_autostartPath = QDir::cleanDirPath( *s_autostartPath ); + if ( s_autostartPath->right(1) != "/") + *s_autostartPath += "/"; +*/ + // Document Path + *s_documentPath = QString::null; + *s_documentPath = config->readEntry( "Documents" , *s_documentPath); + if ( (*s_documentPath)[0] != '/' ) + s_documentPath->prepend( QDir::homeDirPath() + "/" ); + *s_documentPath = QDir::cleanDirPath( *s_documentPath ); + if ( s_documentPath->right(1) != "/") + *s_documentPath += "/"; + + //config->setDollarExpansion(dollarExpansion); + + // Make sure this app gets the notifications about those paths + //if (kapp) + //kapp->addKipcEventMask(KIPC::SettingsChanged); +} + +void OGlobalSettings::initColors() +{ + if ( not OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 ); + if ( not OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 ); + if ( not OpieGray ) OpieGray = new QColor( 220, 210, 215 ); +} + +void OGlobalSettings::rereadFontSettings() +{ + delete _generalFont; + _generalFont = 0L; + delete _fixedFont; + _fixedFont = 0L; + delete _menuFont; + _menuFont = 0L; + delete _toolBarFont; + _toolBarFont = 0L; + delete _windowTitleFont; + _windowTitleFont = 0L; + delete _taskbarFont; + _taskbarFont = 0L; +} + +void OGlobalSettings::rereadPathSettings() +{ + qDebug( "OGlobalSettings::rereadPathSettings" ); + delete s_autostartPath; + s_autostartPath = 0L; + delete s_trashPath; + s_trashPath = 0L; + delete s_desktopPath; + s_desktopPath = 0L; + delete s_documentPath; + s_documentPath = 0L; +} + +OGlobalSettings::OMouseSettings & OGlobalSettings::mouseSettings() +{ + if ( ! s_mouseSettings ) + { + s_mouseSettings = new OMouseSettings; + OMouseSettings & s = *s_mouseSettings; // for convenience + + OConfigGroupSaver cgs( OGlobal::config(), "Mouse" ); + QString setting = OGlobal::config()->readEntry("MouseButtonMapping"); + if (setting == "RightHanded") + s.handed = OMouseSettings::RightHanded; + else if (setting == "LeftHanded") + s.handed = OMouseSettings::LeftHanded; + else + { + + // FIXME: Implement for Opie / Qt Embedded + + } + } + return *s_mouseSettings; +} + +void OGlobalSettings::rereadMouseSettings() +{ + delete s_mouseSettings; + s_mouseSettings = 0L; +} + +// FIXME: This won't be necessary, or will it? :-D + +bool OGlobalSettings::isMultiHead() +{ + QCString multiHead = getenv("OPIE_MULTIHEAD"); + if (!multiHead.isEmpty()) { + return (multiHead.lower() == "true"); + } + return false; +} 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 @@ +/* + This file is part of the Opie Project + Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> + Inspired by KDE OGlobalSettings + Copyright (C) 2000 David Faure <faure@kde.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OGLOBALSETTINGS_H +#define OGLOBALSETTINGS_H + +#include <qstring.h> +#include <qcolor.h> +#include <qfont.h> + +#define OPIE_DEFAULT_SINGLECLICK true +#define OPIE_DEFAULT_INSERTTEAROFFHANDLES true +#define OPIE_DEFAULT_AUTOSELECTDELAY -1 +#define OPIE_DEFAULT_CHANGECURSOR true +#define OPIE_DEFAULT_LARGE_CURSOR false +#define OPIE_DEFAULT_VISUAL_ACTIVATE true +#define OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED 50 + +//FIXME: There's still a whole lot of stuff in here which has to be revised +//FIXME: before public usage... lack of time to do it at once - so it will +//FIXME: happen step-by-step. ML. + +/** + * Access the OPIE global configuration settings. + * + */ +class OGlobalSettings +{ + public: + + /** + * Returns a threshold in pixels for drag & drop operations. + * As long as the mouse movement has not exceeded this number + * of pixels in either X or Y direction no drag operation may + * be started. This prevents spurious drags when the user intended + * to click on something but moved the mouse a bit while doing so. + * + * For this to work you must save the position of the mouse (oldPos) + * in the @ref QWidget::mousePressEvent(). + * When the position of the mouse (newPos) + * in a @ref QWidget::mouseMoveEvent() exceeds this threshold + * you may start a drag + * which should originate from oldPos. + * + * Example code: + * <pre> + * void OColorCells::mousePressEvent( QMouseEvent *e ) + * { + * mOldPos = e->pos(); + * } + * + * void OColorCells::mouseMoveEvent( QMouseEvent *e ) + * { + * if( !(e->state() && LeftButton)) return; + * + * int delay = OGlobalSettings::dndEventDelay(); + * QPoint newPos = e->pos(); + * if(newPos.x() > mOldPos.x()+delay || newPos.x() < mOldPos.x()-delay || + * newPos.y() > mOldPos.y()+delay || newPos.y() < mOldPos.y()-delay) + * { + * // Drag color object + * int cell = posToCell(mOldPos); // Find color at mOldPos + * if ((cell != -1) && colors[cell].isValid()) + * { + * OColorDrag *d = OColorDrag::makeDrag( colors[cell], this); + * d->dragCopy(); + * } + * } + * } + * </pre> + * + */ + + static int dndEventDelay(); + + /** + * Returns whether OPIE runs in single (default) or double click + * mode. + * + * @return @p true if single click mode, or @p false if double click mode. + * + * see @ref http://opie.handhelds.org/documentation/standards/opie/style/mouse/index.html + **/ + static bool singleClick(); + + /** + * Returns whether tear-off handles are inserted in OPopupMenus. + **/ + static bool insertTearOffHandle(); + + /** + * @return the OPIE setting for "change cursor over icon" + */ + static bool changeCursorOverIcon(); + + /** + * @return whether to show some feedback when an item (specifically an + * icon) is activated. + */ + static bool visualActivate(); + static unsigned int visualActivateSpeed(); + + /** + * Returns the OPIE setting for the auto-select option + * + * @return the auto-select delay or -1 if auto-select is disabled. + */ + static int autoSelectDelay(); + + /** + * Returns the OPIE setting for the shortcut key to open + * context menus. + * + * @return the key that pops up context menus. + */ + static int contextMenuKey(); + + /** + * Returns the OPIE setting for context menus. + * + * @return whether context menus should be shown on button press + * or button release (click). + */ + static bool showContextMenusOnPress (); + + /** + * This enum describes the completion mode used for by the @ref OCompletion class. + * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/keys/completion.html"> + * the styleguide</a>. + **/ + enum Completion { + /** + * No completion is used. + */ + CompletionNone=1, + /** + * Text is automatically filled in whenever possible. + */ + CompletionAuto, + /** + * Same as automatic except shortest match is used for completion. + */ + CompletionMan, + /** + * Complete text much in the same way as a typical *nix shell would. + */ + CompletionShell, + /** + * Lists all possible matches in a popup list-box to choose from. + */ + CompletionPopup, + /** + * Lists all possible matches in a popup list-box to choose from, and automatically + * fill the result whenever possible. + */ + CompletionPopupAuto + }; + /** + * Returns the preferred completion mode setting. + * + * @return @ref Completion. Default is @p CompletionPopup. + */ + static Completion completionMode(); + + /** + * This enum describes the debug mode used for by the @ref odbgstream class. + * See <a href="http://opie.handhelds.org/documentation/standards/opie/style/debug/debug.html"> + * the styleguide</a>. + **/ + enum Debug { + /** + * Debug messages are ignored. + */ + DebugNone=-1, + /** + * Debug output is sent to files /var/log/***. + */ + DebugFiles=0, + /** + * Debug output is written in a QMessageBox. + */ + DebugMsgBox=1, + /** + * Debug output is sent to stderr. + */ + DebugStdErr=2, + /** + * Debug output is sent to syslog. + */ + DebugSysLog=3, + /** + * Debug output is sent via udp over a socket. + */ + DebugSocket=4 + }; + /** + * Returns the preferred debug mode setting. + * + * @return @ref Debug. Default is @p DebugStdErr. + */ + static Debug debugMode(); + + /** + * Returns additional information for debug output (dependent on the debug mode). + * + * @return Additional debug output information. + */ + static QString debugOutput(); + /** + * This is a structure containing the possible mouse settings. + */ + struct OMouseSettings + { + enum { RightHanded = 0, LeftHanded = 1 }; + int handed; // left or right + }; + + /** + * This returns the current mouse settings. + */ + static OMouseSettings & mouseSettings(); + + /** + * The path to the desktop directory of the current user. + */ + static QString desktopPath() { initStatic(); return *s_desktopPath; } + + /** + * The path to the autostart directory of the current user. + */ + static QString autostartPath() { initStatic(); return *s_autostartPath; } + + /** + * The path to the trash directory of the current user. + */ + static QString trashPath() { initStatic(); return *s_trashPath; } + + /** + * The path where documents are stored of the current user. + */ + static QString documentPath() { initStatic(); return *s_documentPath; } + + + /** + * The default color to use when highlighting toolbar buttons + */ + static QColor toolBarHighlightColor(); + static QColor inactiveTitleColor(); + static QColor inactiveTextColor(); + static QColor activeTitleColor(); + static QColor activeTextColor(); + static int contrast(); + + /** + * The default colors to use for text and links. + */ + static QColor baseColor(); // Similair to QColorGroup::base() + static QColor textColor(); // Similair to QColorGroup::text() + static QColor linkColor(); + static QColor visitedLinkColor(); + static QColor highlightedTextColor(); // Similair to QColorGroup::hightlightedText() + static QColor highlightColor(); // Similair to QColorGroup::highlight() + + /** + * Returns the alternate background color used by @ref OListView with + * @ref OListViewItem. Any other list that uses alternating background + * colors should use this too, to obey to the user's preferences. Returns + * an invalid color if the user doesn't want alternating backgrounds. + * @see #calculateAlternateBackgroundColor + */ + static QColor alternateBackgroundColor(); + /** + * Calculates a color based on @p base to be used as alternating + * color for e.g. listviews. + * @see #alternateBackgroundColor + */ + static QColor calculateAlternateBackgroundColor(const QColor& base); + + + static QFont generalFont(); + static QFont fixedFont(); + static QFont toolBarFont(); + static QFont menuFont(); + static QFont windowTitleFont(); + static QFont taskbarFont(); + + /** + * Returns if the user specified multihead. In case the display + * has multiple screens, the return value of this function specifies + * if the user wants OPIE to run on all of them or just on the primary + */ + static bool isMultiHead(); + +private: + /** + * reads in all paths from kdeglobals + */ + static void initStatic(); + /** + * initialise kde2Blue + */ + static void initColors(); + /** + * drop cached values for fonts (called by OApplication) + */ + static void rereadFontSettings(); + /** + * drop cached values for paths (called by OApplication) + */ + static void rereadPathSettings(); + /** + * drop cached values for mouse settings (called by OApplication) + */ + static void rereadMouseSettings(); + + + static QString* s_desktopPath; + static QString* s_autostartPath; + static QString* s_trashPath; + static QString* s_documentPath; + static QFont *_generalFont; + static QFont *_fixedFont; + static QFont *_toolBarFont; + static QFont *_menuFont; + static QFont *_windowTitleFont; + static QFont *_taskbarFont; + static QColor * kde2Gray; + static QColor * kde2Blue; + static QColor * kde2AlternateColor; + static OMouseSettings *s_mouseSettings; + + static QColor * OpieGray; + static QColor * OpieBlue; + static QColor * OpieAlternate; + static QColor * OpieHighlight; + + friend class OApplication; +}; + +#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 @@ +TEMPLATE = lib +CONFIG += qt warn_on debug +DESTDIR = $(OPIEDIR)/lib +HEADERS = oapplication.h \ + oconfig.h \ + ocompletionbase.h \ + ocompletion.h \ + odebug.h \ + oglobal.h \ + oglobalsettings.h \ + osortablevaluelist.h + +SOURCES = oapplication.cpp \ + oconfig.cpp \ + ocompletionbase.cpp \ + ocompletion.cpp \ + odebug.cpp \ + oglobal.cpp \ + oglobalsettings.cpp + +INTERFACES = +TARGET = opiecore2 +VERSION = 1.8.1 +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS = -lqpe +MOC_DIR = moc +OBJECTS_DIR = obj + +include ( $(OPIEDIR)/include.pro ) + |