36 files changed, 210 insertions, 488 deletions
diff --git a/libopie2/opiecore/device/odevice.cpp b/libopie2/opiecore/device/odevice.cpp index 27b0e53..f3e2cfb 100644 --- a/libopie2/opiecore/device/odevice.cpp +++ b/libopie2/opiecore/device/odevice.cpp @@ -61,5 +61,5 @@ _;:, .> :=|. This program is free software; you can const char* PATH_PROC_CPUINFO = "/proc/cpuinfo"; -using namespace Opie; +using namespace Opie::Core; ODevice *ODevice::inst() @@ -82,9 +82,9 @@ ODevice *ODevice::inst() { qDebug( "ODevice() - found '%s'", (const char*) line ); - if ( line.contains( "sharp", false ) ) dev = new Zaurus(); - else if ( line.contains( "ipaq", false ) ) dev = new iPAQ(); - else if ( line.contains( "simpad", false ) ) dev = new SIMpad(); - else if ( line.contains( "jornada", false ) ) dev = new Jornada(); - else if ( line.contains( "ramses", false ) ) dev = new Ramses(); + if ( line.contains( "sharp", false ) ) dev = new Private::Zaurus(); + else if ( line.contains( "ipaq", false ) ) dev = new Private::iPAQ(); + else if ( line.contains( "simpad", false ) ) dev = new Private::SIMpad(); + else if ( line.contains( "jornada", false ) ) dev = new Private::Jornada(); + else if ( line.contains( "ramses", false ) ) dev = new Private::Ramses(); else qWarning( "ODevice() - unknown hardware - using default." ); break; @@ -625,4 +625,7 @@ void ODevice::virtual_hook(int, void* ){ void ODevice::sendSuspendmsg() { + if ( isQWS() ) + return; + QCopEnvelope ( "QPE/System", "aboutToSuspend()" ); } diff --git a/libopie2/opiecore/device/odevice.h b/libopie2/opiecore/device/odevice.h index bccb449..5ee9cca 100644 --- a/libopie2/opiecore/device/odevice.h +++ b/libopie2/opiecore/device/odevice.h @@ -41,6 +41,7 @@ _;:, .> :=|. This program is free software; you can #include <qstrlist.h> -namespace Opie -{ +namespace Opie{ +namespace Core{ + class ODeviceData; /** @@ -315,4 +316,5 @@ class ODeviceData { } +} static inline bool isQWS() @@ -329,4 +331,5 @@ static QCString makeChannel ( const char *str ) } + #endif diff --git a/libopie2/opiecore/device/odevice_ipaq.cpp b/libopie2/opiecore/device/odevice_ipaq.cpp index 8ecea1b..177fd4c 100644 --- a/libopie2/opiecore/device/odevice_ipaq.cpp +++ b/libopie2/opiecore/device/odevice_ipaq.cpp @@ -54,4 +54,8 @@ #endif + +using namespace Opie::Core; +using namespace Opie::Core::Private; + /* KERNEL */ #define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) diff --git a/libopie2/opiecore/device/odevice_ipaq.h b/libopie2/opiecore/device/odevice_ipaq.h index f512344..4f4af46 100644 --- a/libopie2/opiecore/device/odevice_ipaq.h +++ b/libopie2/opiecore/device/odevice_ipaq.h @@ -36,5 +36,7 @@ #include <qwindowsystem_qws.h> -using namespace Opie; +namespace Opie { +namespace Core { +namespace Private { class iPAQ : public ODevice, public QWSServer::KeyboardFilter @@ -82,3 +84,7 @@ struct i_button { }; +} +} +} + #endif diff --git a/libopie2/opiecore/device/odevice_jornada.cpp b/libopie2/opiecore/device/odevice_jornada.cpp index 37bd6e9..b79b0b5 100644 --- a/libopie2/opiecore/device/odevice_jornada.cpp +++ b/libopie2/opiecore/device/odevice_jornada.cpp @@ -78,5 +78,5 @@ typedef struct { #define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) -using namespace Opie; +using namespace Opie::Core::Private; void Jornada::init() diff --git a/libopie2/opiecore/device/odevice_jornada.h b/libopie2/opiecore/device/odevice_jornada.h index 59be8da..c37d75e 100644 --- a/libopie2/opiecore/device/odevice_jornada.h +++ b/libopie2/opiecore/device/odevice_jornada.h @@ -33,6 +33,7 @@ #include <opie2/odevice.h> -using namespace Opie; - +namespace Opie { +namespace Core { +namespace Private { class Jornada : public ODevice { @@ -46,5 +47,7 @@ class Jornada : public ODevice virtual int displayBrightnessResolution() const; }; - +} +} +} #endif diff --git a/libopie2/opiecore/device/odevice_ramses.cpp b/libopie2/opiecore/device/odevice_ramses.cpp index 5bcf6a9..77de8c5 100644 --- a/libopie2/opiecore/device/odevice_ramses.cpp +++ b/libopie2/opiecore/device/odevice_ramses.cpp @@ -54,4 +54,7 @@ #endif +using namespace Opie::Core; +using namespace Opie::Core::Private; + struct r_button ramses_buttons [] = { { Model_Ramses_MNCI, diff --git a/libopie2/opiecore/device/odevice_ramses.h b/libopie2/opiecore/device/odevice_ramses.h index 1b660ab..e673b1a 100644 --- a/libopie2/opiecore/device/odevice_ramses.h +++ b/libopie2/opiecore/device/odevice_ramses.h @@ -35,5 +35,7 @@ #include <qwindowsystem_qws.h> -using namespace Opie; +namespace Opie { +namespace Core { +namespace Private { class Ramses : public ODevice, public QWSServer::KeyboardFilter @@ -69,4 +71,7 @@ struct r_button { char *fheldaction; }; +} +} +} #endif diff --git a/libopie2/opiecore/device/odevice_simpad.cpp b/libopie2/opiecore/device/odevice_simpad.cpp index 90aca2f..80d40a3 100644 --- a/libopie2/opiecore/device/odevice_simpad.cpp +++ b/libopie2/opiecore/device/odevice_simpad.cpp @@ -54,5 +54,6 @@ _;:, .> :=|. This program is free software; you can #endif -using namespace Opie; +using namespace Opie::Core; +using namespace Opie::Core::Private; struct s_button simpad_buttons [] = { diff --git a/libopie2/opiecore/device/odevice_simpad.h b/libopie2/opiecore/device/odevice_simpad.h index 3287ee8..1848151 100644 --- a/libopie2/opiecore/device/odevice_simpad.h +++ b/libopie2/opiecore/device/odevice_simpad.h @@ -36,5 +36,7 @@ #include <qwindowsystem_qws.h> -using namespace Opie; +namespace Opie { +namespace Core { +namespace Private { class SIMpad : public ODevice, public QWSServer::KeyboardFilter @@ -79,3 +81,7 @@ struct s_button { }; +} +} +} + #endif diff --git a/libopie2/opiecore/device/odevice_yopy.cpp b/libopie2/opiecore/device/odevice_yopy.cpp index d241db8..f7a4025 100644 --- a/libopie2/opiecore/device/odevice_yopy.cpp +++ b/libopie2/opiecore/device/odevice_yopy.cpp @@ -54,5 +54,6 @@ _;:, .> :=|. This program is free software; you can #endif -using namespace Opie; +using namespace Opie::Core; +using namespace Opie::Core::Private; struct yopy_button yopy_buttons [] = { diff --git a/libopie2/opiecore/device/odevice_yopy.h b/libopie2/opiecore/device/odevice_yopy.h index be8f62c..7d85479 100644 --- a/libopie2/opiecore/device/odevice_yopy.h +++ b/libopie2/opiecore/device/odevice_yopy.h @@ -33,6 +33,7 @@ _;:, .> :=|. This program is free software; you can #include <opie2/odevice.h> -using namespace Opie; - +namespace Opie { +namespace Core { +namespace Private { class Yopy : public ODevice { @@ -60,3 +61,7 @@ struct yopy_button }; +} +} +} + #endif diff --git a/libopie2/opiecore/device/odevice_zaurus.cpp b/libopie2/opiecore/device/odevice_zaurus.cpp index 8ab3cbe..0d21f26 100644 --- a/libopie2/opiecore/device/odevice_zaurus.cpp +++ b/libopie2/opiecore/device/odevice_zaurus.cpp @@ -54,5 +54,6 @@ _;:, .> :=|. This program is free software; you can #endif -using namespace Opie; +using namespace Opie::Core; +using namespace Opie::Core::Private; struct z_button z_buttons [] = { diff --git a/libopie2/opiecore/device/odevice_zaurus.h b/libopie2/opiecore/device/odevice_zaurus.h index f5c5172..ffb648f 100644 --- a/libopie2/opiecore/device/odevice_zaurus.h +++ b/libopie2/opiecore/device/odevice_zaurus.h @@ -46,6 +46,8 @@ #define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) -using namespace Opie; +namespace Opie { +namespace Core { +namespace Private { class Zaurus : public ODevice { @@ -93,4 +95,6 @@ struct z_button { char *fheldaction; }; - +} +} +} #endif diff --git a/libopie2/opiecore/device/odevicebutton.cpp b/libopie2/opiecore/device/odevicebutton.cpp index 0b593d5..a081b7f 100644 --- a/libopie2/opiecore/device/odevicebutton.cpp +++ b/libopie2/opiecore/device/odevicebutton.cpp @@ -34,5 +34,8 @@ #include <opie2/odevicebutton.h> -using namespace Opie; + +namespace Opie { +namespace Core { +namespace Private { class OQCopMessageData @@ -43,5 +46,8 @@ class OQCopMessageData QByteArray m_data; }; +} +using namespace Opie::Core; +using namespace Opie::Core::Private; OQCopMessage::OQCopMessage() @@ -125,6 +131,6 @@ void OQCopMessage::setData ( const QByteArray &data ) } -/*! \class Opie::ODeviceButton - \brief The Opie::ODeviceButton class represents a physical user mappable button on a Qtopia device. +/*! \class Opie::Core::ODeviceButton + \brief The Opie::Core::ODeviceButton class represents a physical user mappable button on a Qtopia device. This class represents a physical button on a Qtopia device. A @@ -245,2 +251,5 @@ void ODeviceButton::setHeldAction(const OQCopMessage& action) m_HeldAction = action; } + +} +} diff --git a/libopie2/opiecore/device/odevicebutton.h b/libopie2/opiecore/device/odevicebutton.h index a66b88f..4000144 100644 --- a/libopie2/opiecore/device/odevicebutton.h +++ b/libopie2/opiecore/device/odevicebutton.h @@ -24,8 +24,10 @@ #include <qstring.h> -class OQCopMessageData; -namespace Opie -{ +namespace Opie{ +namespace Core{ +namespace Private { +class OQCopMessageData; +} class OQCopMessage @@ -53,5 +55,5 @@ private: void init ( const QCString &m_channel, const QCString &message, const QByteArray &args ); - OQCopMessageData *d; + Private::OQCopMessageData *d; class Private; Private* m_data; @@ -105,4 +107,5 @@ class ODeviceButton } +} #endif diff --git a/libopie2/opiecore/oapplication.cpp b/libopie2/opiecore/oapplication.cpp index d340c0e..e2f6e82 100644 --- a/libopie2/opiecore/oapplication.cpp +++ b/libopie2/opiecore/oapplication.cpp @@ -35,4 +35,7 @@ #include <stdio.h> +using namespace Opie::Core; + + OApplication* OApplication::_instance = 0; @@ -41,4 +44,7 @@ OApplication* OApplication::_instance = 0; **************************************************************************************************/ +namespace Opie { +namespace Core { +namespace Private { class OApplicationPrivate { @@ -47,4 +53,5 @@ class OApplicationPrivate ~OApplicationPrivate() {}; }; +} /************************************************************************************************** @@ -85,5 +92,5 @@ OConfig* OApplication::config() void OApplication::init() { - d = new OApplicationPrivate(); + d = new Private::OApplicationPrivate(); if ( !OApplication::_instance ) { @@ -126,2 +133,4 @@ void OApplication::setTitle( const QString& title ) const } +} +} diff --git a/libopie2/opiecore/oapplication.h b/libopie2/opiecore/oapplication.h index cc506a2..c1e32a6 100644 --- a/libopie2/opiecore/oapplication.h +++ b/libopie2/opiecore/oapplication.h @@ -31,11 +31,15 @@ #define OAPPLICATION_H -#define oApp OApplication::oApplication() +#define oApp Opie::Core::OApplication::oApplication() #include <qpe/qpeapplication.h> - +namespace Opie { +namespace Core { +namespace Private { class OApplicationPrivate; +} // private class + class OConfig; @@ -99,6 +103,9 @@ class OApplication : public QPEApplication static OApplication* _instance; OConfig* _config; - OApplicationPrivate* d; + Private::OApplicationPrivate* d; }; +} // Core +} // Opie + #endif // OAPPLICATION_H diff --git a/libopie2/opiecore/oconfig.cpp b/libopie2/opiecore/oconfig.cpp index fb5eabb..05d8070 100644 --- a/libopie2/opiecore/oconfig.cpp +++ b/libopie2/opiecore/oconfig.cpp @@ -39,4 +39,6 @@ #include <opie2/oconfig.h> +using namespace Opie::Core; + OConfig::OConfig( const QString &name, Domain domain ) :Config( name, domain ) diff --git a/libopie2/opiecore/oconfig.h b/libopie2/opiecore/oconfig.h index becf70d..29c1f86 100644 --- a/libopie2/opiecore/oconfig.h +++ b/libopie2/opiecore/oconfig.h @@ -41,4 +41,7 @@ class QColor; class QFont; +namespace Opie { +namespace Core { + /** * A Configuration class based on the Qtopia @ref Config class @@ -63,4 +66,5 @@ class OConfig : public Config * @returns the name of the current group. * The current group is used for searching keys and accessing entries. + * @todo make const */ const QString& group() { return git.key(); }; @@ -73,4 +77,8 @@ class OConfig : public Config */ QFont readFontEntry( const QString& key, const QFont* pDefault ) const; + +private: + class Private; + Private *d; }; @@ -137,5 +145,10 @@ class OConfigGroupSaver OConfigGroupSaver( const OConfigGroupSaver& ); OConfigGroupSaver& operator=( const OConfigGroupSaver& ); + + class Private; + Private *d; }; +} +} #endif // OCONFIG_H diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp index a40ef53..cac985b 100644 --- a/libopie2/opiecore/odebug.cpp +++ b/libopie2/opiecore/odebug.cpp @@ -66,5 +66,6 @@ #endif - +namespace Opie { +namespace Core { /*====================================================================================== * debug levels @@ -615,6 +616,10 @@ void odClearDebugConfig() } + #ifdef OPIE_NO_DEBUG #define odDebug ondDebug #define odBacktrace ondBacktrace #endif + +} +}
\ No newline at end of file diff --git a/libopie2/opiecore/odebug.h b/libopie2/opiecore/odebug.h index 85941fd..a5c9ded 100644 --- a/libopie2/opiecore/odebug.h +++ b/libopie2/opiecore/odebug.h @@ -48,4 +48,7 @@ class QColor; class QBrush; +namespace Opie { +namespace Core { + class odbgstream; class ondbgstream; @@ -395,4 +398,8 @@ class ondbgstream { ondbgstream& operator<<( const QColor & ) { return *this; } ondbgstream& operator<<( const QBrush & ) { return *this; } + +private: + class Private; + Private *d; }; @@ -473,2 +480,4 @@ void odClearDebugConfig(); #endif +} +} diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp index 1aa206e..ea02058 100644 --- a/libopie2/opiecore/oglobal.cpp +++ b/libopie2/opiecore/oglobal.cpp @@ -39,4 +39,6 @@ #include <sys/types.h> +using namespace Opie::Core; + static const char Base64EncMap[64] = { @@ -313,5 +315,5 @@ QByteArray OGlobal::decodeBase64( const QByteArray& in) { bool OGlobal::isAppLnkFileName( const QString& str ) { - if (str.length()==0||str.at(str.length()-1)==QDir::separator()) return false; + if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false; return str.startsWith(MimeType::appsFolderName()+QDir::separator()); } @@ -324,5 +326,5 @@ bool OGlobal::isAppLnkFileName( const QString& str ) bool OGlobal::isDocumentFileName( const QString& file ) { - if (file.length()==0||file.at(file.length()-1)==QDir::separator()) return false; + if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false; if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; StorageInfo si; diff --git a/libopie2/opiecore/oglobal.h b/libopie2/opiecore/oglobal.h index aeee75e..e6a6c46 100644 --- a/libopie2/opiecore/oglobal.h +++ b/libopie2/opiecore/oglobal.h @@ -53,4 +53,9 @@ class QFile; class QString; class DateFormat; + + + +namespace Opie { +namespace Core { /** *\brief OGlobal contains a list of generic functions @@ -147,5 +152,8 @@ private: static OConfig* _config; static OConfig* _qpe_config; + class Private; + Private *d; }; - +} +} #endif // OGLOBAL_H diff --git a/libopie2/opiecore/oglobalsettings.cpp b/libopie2/opiecore/oglobalsettings.cpp index 192e55b..f34c531 100644 --- a/libopie2/opiecore/oglobalsettings.cpp +++ b/libopie2/opiecore/oglobalsettings.cpp @@ -45,4 +45,7 @@ #include <stdlib.h> + +using namespace Opie::Core; + QString* OGlobalSettings::s_desktopPath = 0; QString* OGlobalSettings::s_autostartPath = 0; diff --git a/libopie2/opiecore/oglobalsettings.h b/libopie2/opiecore/oglobalsettings.h index e3ac148..8eea709 100644 --- a/libopie2/opiecore/oglobalsettings.h +++ b/libopie2/opiecore/oglobalsettings.h @@ -37,4 +37,7 @@ #include <qfont.h> +/** + * \todo make real const values + */ #define OPIE_DEFAULT_SINGLECLICK true #define OPIE_DEFAULT_INSERTTEAROFFHANDLES true @@ -50,4 +53,7 @@ // we should not habe too much configure options!!!!!! -zecke +namespace Opie { +namespace Core { + /** * Access the OPIE global configuration settings. @@ -369,5 +375,11 @@ private: friend class OApplication; +private: + class Private; + Private *d; }; +} +} + #endif diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro index 523d6a7..ff3c036 100644 --- a/libopie2/opiecore/opiecore.pro +++ b/libopie2/opiecore/opiecore.pro @@ -10,6 +10,5 @@ HEADERS = oapplication.h \ oprocctrl.h \ osmartpointer.h \ - ostorageinfo.h \ - xmltree.h + ostorageinfo.h SOURCES = oapplication.cpp \ @@ -20,6 +19,5 @@ SOURCES = oapplication.cpp \ oprocess.cpp \ oprocctrl.cpp \ - ostorageinfo.cpp \ - xmltree.cc + ostorageinfo.cpp include ( device/device.pro ) @@ -27,5 +25,5 @@ include ( device/device.pro ) INTERFACES = TARGET = opiecore2 -VERSION = 1.8.5 +VERSION = 1.9.0 INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include diff --git a/libopie2/opiecore/oprocctrl.cpp b/libopie2/opiecore/oprocctrl.cpp index 0403526..46708ba 100644 --- a/libopie2/opiecore/oprocctrl.cpp +++ b/libopie2/opiecore/oprocctrl.cpp @@ -42,4 +42,6 @@ #include "oprocctrl.h" +using namespace Opie::Core::Private; + OProcessController *OProcessController::theOProcessController = 0; diff --git a/libopie2/opiecore/oprocctrl.h b/libopie2/opiecore/oprocctrl.h index 44b8a48..4922ba2 100644 --- a/libopie2/opiecore/oprocctrl.h +++ b/libopie2/opiecore/oprocctrl.h @@ -35,7 +35,12 @@ #include "oprocess.h" -class OProcessControllerPrivate; class QSocketNotifier; + +namespace Opie { +namespace Core { +namespace Private { +class OProcessControllerPrivate; + /** * @short Used internally by @ref OProcess @@ -116,4 +121,7 @@ private: }; +} +} +} diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp index 6349c83..dfde74a 100644 --- a/libopie2/opiecore/oprocess.cpp +++ b/libopie2/opiecore/oprocess.cpp @@ -62,4 +62,9 @@ _;:, .> :=|. This program is free software; you can #endif +using namespace Opie::Core::Private; + +namespace Opie { +namespace Core { +namespace Private { class OProcessPrivate { @@ -73,5 +78,5 @@ public: QCString shell; }; - +} OProcess::OProcess( QObject *parent, const char *name ) @@ -942,2 +947,5 @@ int OProcess::processPID( const QString& process ) } } + +} +} diff --git a/libopie2/opiecore/oprocess.h b/libopie2/opiecore/oprocess.h index 1a2472d..eb56b03 100644 --- a/libopie2/opiecore/oprocess.h +++ b/libopie2/opiecore/oprocess.h @@ -44,5 +44,11 @@ _;:, .> :=|. This program is free software; you can class QSocketNotifier; + +namespace Opie { +namespace Core { +namespace Private { +class OProcessController; class OProcessPrivate; +} /** @@ -398,4 +404,5 @@ public: /** * Lets you see what your arguments are for debugging. + * \todo make const */ @@ -717,5 +724,5 @@ protected: * access to various data members. */ - friend class OProcessController; + friend class Private::OProcessController; private: @@ -746,6 +753,8 @@ private: private: void init ( ); - OProcessPrivate *d; + Private::OProcessPrivate *d; }; +} +} #endif diff --git a/libopie2/opiecore/osmartpointer.h b/libopie2/opiecore/osmartpointer.h index 9000e71..8f9da7f 100644 --- a/libopie2/opiecore/osmartpointer.h +++ b/libopie2/opiecore/osmartpointer.h @@ -41,4 +41,5 @@ _;:, .> :=|. This program is free software; you can namespace Opie { +namespace Core { //! simple reference counter class @@ -141,4 +142,5 @@ public: } +} #endif diff --git a/libopie2/opiecore/ostorageinfo.cpp b/libopie2/opiecore/ostorageinfo.cpp index aa8d2fc..8fcf5fc 100644 --- a/libopie2/opiecore/ostorageinfo.cpp +++ b/libopie2/opiecore/ostorageinfo.cpp @@ -30,4 +30,6 @@ #include <opie2/ostorageinfo.h> +using namespace Opie::Core; + OStorageInfo::OStorageInfo( QObject *parent ) : StorageInfo( parent ) diff --git a/libopie2/opiecore/ostorageinfo.h b/libopie2/opiecore/ostorageinfo.h index 740fa85..4e1097f 100644 --- a/libopie2/opiecore/ostorageinfo.h +++ b/libopie2/opiecore/ostorageinfo.h @@ -33,4 +33,7 @@ #include <qpe/storage.h> +namespace Opie { +namespace Core { + class OStorageInfo : public StorageInfo { @@ -57,6 +60,11 @@ class OStorageInfo : public StorageInfo **/ QString mmcPath() const; +private: + class Private; + Private *d; }; +} +} #endif // OSTORAGE_H diff --git a/libopie2/opiecore/xmltree.cc b/libopie2/opiecore/xmltree.cc deleted file mode 100644 index 059791b..0000000 --- a/libopie2/opiecore/xmltree.cc +++ b/dev/null @@ -1,323 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 Simon Hausmann <hausmann@kde.org> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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/xmltree.h> - -#include <qpe/stringutil.h> - -#include <qxml.h> - -#include <assert.h> - -using namespace Opie; - -XMLElement::XMLElement() - : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 ) -{ -} - -XMLElement::~XMLElement() -{ - XMLElement *n = m_first; - - while ( n ) - { - XMLElement *tmp = n; - n = n->m_next; - delete tmp; - } -} - -void XMLElement::appendChild( XMLElement *child ) -{ - if ( child->m_parent ) - child->m_parent->removeChild( child ); - - child->m_parent = this; - - if ( m_last ) - m_last->m_next = child; - - child->m_prev = m_last; - - if ( !m_first ) - m_first = child; - - m_last = child; -} - -void XMLElement::insertAfter( XMLElement *newChild, XMLElement *refChild ) -{ - assert( newChild != refChild ); - - if ( refChild == m_last ) - { - appendChild( newChild ); - return; - } - - assert( refChild ); - assert( refChild->m_parent ); - assert( refChild->m_parent == this ); - - if ( newChild->m_parent && newChild != refChild ) - newChild->m_parent->removeChild( newChild ); - - newChild->m_parent = this; - - XMLElement *next = refChild->m_next; - - refChild->m_next = newChild; - - newChild->m_prev = refChild; - newChild->m_next = next; - - if ( next ) - next->m_prev = newChild; -} - -QString XMLElement::attribute( const QString &attr ) const -{ - AttributeMap::ConstIterator it = m_attributes.find( attr ); - if ( it == m_attributes.end() ) - return QString::null; - return it.data(); -} - -void XMLElement::setAttribute( const QString &attr, const QString &value ) -{ - m_attributes.replace( attr, value ); -} - -void XMLElement::insertBefore( XMLElement *newChild, XMLElement *refChild ) -{ - assert( refChild ); - assert( refChild->m_parent ); - assert( refChild->m_parent == this ); - assert( newChild != refChild ); - - if ( newChild->m_parent && newChild != refChild ) - newChild->m_parent->removeChild( newChild ); - - newChild->m_parent = this; - - XMLElement *prev = refChild->m_prev; - - refChild->m_prev = newChild; - - newChild->m_prev = prev; - newChild->m_next = refChild; - - if ( prev ) - prev->m_next = newChild; - - if ( refChild == m_first ) - m_first = newChild; -} - -void XMLElement::removeChild( XMLElement *child ) -{ - if ( child->m_parent != this ) - return; - - if ( m_first == child ) - m_first = child->m_next; - - if ( m_last == child ) - m_last = child->m_prev; - - if ( child->m_prev ) - child->m_prev->m_next = child->m_next; - - if ( child->m_next ) - child->m_next->m_prev = child->m_prev; - - child->m_parent = 0; - child->m_prev = 0; - child->m_next = 0; -} - -void XMLElement::save( QTextStream &s, uint indent ) -{ - if ( !m_value.isEmpty() ) - { - s << Qtopia::escapeString( m_value ); - return; - } - - for ( uint i = 0; i < indent; ++i ) - s << " "; - - s << "<" << m_tag; - - if ( !m_attributes.isEmpty() ) - { - s << " "; - AttributeMap::ConstIterator it = m_attributes.begin(); - AttributeMap::ConstIterator end = m_attributes.end(); - for (; it != end; ++it ) - { - s << it.key() << "=\"" << Qtopia::escapeString( it.data() ) << "\""; - s << " "; - } - } - - if ( m_last ) - { - if ( ( m_first && !m_first->value().isEmpty() ) || !m_parent ) - s << ">"; - else - s << ">" << endl; - - int newIndent = indent; - if ( m_parent ) - newIndent++; - - XMLElement *n = m_first; - while ( n ) - { - n->save( s, newIndent ); - n = n->nextChild(); - } - - if ( m_last && m_last->value().isEmpty() && m_parent ) - for ( uint i = 0; i < indent; ++i ) - s << " "; - - if ( m_parent ) - s << "</" << m_tag << ">" << endl; - } - else - s << "/>" << endl; -} - -class Handler : public QXmlDefaultHandler -{ -public: - Handler() : m_node( 0 ), m_root( 0 ) {} - - XMLElement *root() const { return m_root; } - - virtual bool startDocument(); - virtual bool endDocument(); - virtual bool startElement( const QString &ns, const QString &ln, const QString &qName, - const QXmlAttributes &attr ); - virtual bool endElement( const QString &ns, const QString &ln, const QString &qName ); - virtual bool characters( const QString &ch ); - -private: - XMLElement *m_node; - XMLElement *m_root; -}; - -bool Handler::startDocument() -{ - m_root = m_node = new XMLElement; - - return true; -} - -bool Handler::endDocument() -{ - return m_root == m_node; -} - -bool Handler::startElement( const QString &, const QString &, const QString &qName, - const QXmlAttributes &attr ) -{ - XMLElement *bm = new XMLElement; - - XMLElement::AttributeMap attributes; - for ( int i = 0; i < attr.length(); ++i ) - attributes[ attr.qName( i ) ] = attr.value( i ); - - bm->setAttributes( attributes ); - - bm->setTagName( qName ); - - m_node->appendChild( bm ); - m_node = bm; - - return true; -} - -bool Handler::endElement( const QString &, const QString &, const QString & ) -{ - if ( m_node == m_root ) - return false; - - m_node = m_node->parent(); - return true; -} - -bool Handler::characters( const QString &ch ) -{ - XMLElement *textNode = new XMLElement; - textNode->setValue( ch ); - m_node->appendChild( textNode ); - return true; -} - -XMLElement *XMLElement::namedItem( const QString &name ) -{ - XMLElement *e = m_first; - - for (; e; e = e->nextChild() ) - if ( e->tagName() == name ) - return e; - - return 0; -} - -XMLElement *XMLElement::clone() const -{ - XMLElement *res = new XMLElement; - - res->setTagName( m_tag ); - res->setValue( m_value ); - res->setAttributes( m_attributes ); - - XMLElement *e = m_first; - for (; e; e = e->m_next ) - res->appendChild( e->clone() ); - - return res; -} - -XMLElement *XMLElement::load( const QString &fileName ) -{ - QFile f( fileName ); - if ( !f.open( IO_ReadOnly ) ) - return 0; - - QTextStream stream( &f ); - stream.setEncoding( QTextStream::UnicodeUTF8 ); - QXmlInputSource src( stream ); - QXmlSimpleReader reader; - Handler handler; - - reader.setFeature( "http://trolltech.com/xml/features/report-whitespace-only-CharData", false ); - reader.setContentHandler( &handler ); - reader.parse( src ); - - return handler.root();; -} - -/* vim: et sw=4 - */ diff --git a/libopie2/opiecore/xmltree.h b/libopie2/opiecore/xmltree.h deleted file mode 100644 index 4b6bdfa..0000000 --- a/libopie2/opiecore/xmltree.h +++ b/dev/null @@ -1,119 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2000,2001 Simon Hausmann <hausmann@kde.org> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 __bookmarks_h__ -#define __bookmarks_h__ - -#include <qstring.h> -#include <qmap.h> -#include <qtextstream.h> - -namespace Opie -{ - -/** - * A small xml lib written by Simon Hausmann. - */ -class XMLElement -{ -public: - typedef QMap<QString, QString> AttributeMap; - - /** - * The constructor of XMLElement - */ - XMLElement(); - ~XMLElement(); - - /** appendChild appends a child to the XMLElement behind the last element. - * The ownership of the child get's transfered to the - * this XMLElement. - * If child is already the child of another parent - * it's get removed from the other parent first. - */ - void appendChild( XMLElement *child ); - - /** inserts newChild after refChild. If newChild is the child - * of another parent the child will get removed. - * The ownership of child gets transfered. - * - */ - void insertAfter( XMLElement *newChild, XMLElement *refChild ); - - /** same as insertAfter but the element get's inserted before refChild. - * - */ - void insertBefore( XMLElement *newChild, XMLElement *refChild ); - - /** removeChild removes the child from the XMLElement. - * The ownership gets dropped. You need to delete the - * child yourself. - */ - void removeChild( XMLElement *child ); - - /** parent() returns the parent of this XMLElement - * If there is no parent 0l gets returned - */ - XMLElement *parent() const { return m_parent; } - XMLElement *firstChild() const { return m_first; } - XMLElement *nextChild() const { return m_next; } - XMLElement *prevChild() const { return m_prev; } - XMLElement *lastChild() const { return m_last; } - - void setTagName( const QString &tag ) { m_tag = tag; } - QString tagName() const { return m_tag; } - - void setValue( const QString &val ) { m_value = val; } - QString value() const { return m_value; } - - void setAttributes( const AttributeMap &attrs ) { m_attributes = attrs; } - AttributeMap attributes() const { return m_attributes; } - AttributeMap &attributes() { return m_attributes; } - - QString attribute( const QString & ) const; - void setAttribute( const QString &attr, const QString &value ); - void save( QTextStream &stream, uint indent = 0 ); - - XMLElement *namedItem( const QString &name ); - - XMLElement *clone() const; - - static XMLElement *load( const QString &fileName ); - -private: - QString m_tag; - QString m_value; - AttributeMap m_attributes; - - XMLElement *m_parent; - XMLElement *m_next; - XMLElement *m_prev; - XMLElement *m_first; - XMLElement *m_last; - - XMLElement( const XMLElement &rhs ); - XMLElement &operator=( const XMLElement &rhs ); - class Private; - Private* d; -}; - -} // namespace Opie - -#endif |