author | zautrix <zautrix> | 2004-07-08 11:20:17 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-08 11:20:17 (UTC) |
commit | 3f84322a2da502f95be386372da9f75ed17df574 (patch) (side-by-side diff) | |
tree | 9a4ccd4568c38d60bb1efa7a6713f4d0914aae86 /microkde | |
parent | 40cf8102d2f38b5e952b889ffbd19cb1d428fc9b (diff) | |
download | kdepimpi-3f84322a2da502f95be386372da9f75ed17df574.zip kdepimpi-3f84322a2da502f95be386372da9f75ed17df574.tar.gz kdepimpi-3f84322a2da502f95be386372da9f75ed17df574.tar.bz2 |
Fixes for resource plugin handling on wintendo
-rw-r--r-- | microkde/kconfig.cpp | 20 | ||||
-rw-r--r-- | microkde/kconfig.h | 4 | ||||
-rw-r--r-- | microkde/kresources/managerimpl.cpp | 9 | ||||
-rw-r--r-- | microkde/kresources/resource.cpp | 7 |
4 files changed, 34 insertions, 6 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp index 737b3f2..4cbec94 100644 --- a/microkde/kconfig.cpp +++ b/microkde/kconfig.cpp @@ -1,96 +1,108 @@ #include <qfile.h> #include <qtextstream.h> #include <qwidget.h> #include "kdebug.h" #include "kurl.h" #include "kstandarddirs.h" #include "kconfig.h" QString KConfig::mGroup = ""; //QString KConfig::mGroup = "General"; KConfig::KConfig( const QString &fileName ) : mFileName( fileName ), mDirty( false ) { - kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl; + mTempGroup = ""; load(); } KConfig::~KConfig() { sync(); } +// we need the temp group for plugins on windows +void KConfig::setTempGroup( const QString &group ) +{ + mTempGroup = group; + + if ( mTempGroup.right( 1 ) != "/" ) mTempGroup += "/"; +} + + +QString KConfig::tempGroup() const { + return mTempGroup; +} void KConfig::setGroup( const QString &group ) { - kdDebug() << "KConfig::setGroup(): '" << group << "'" << endl; + mGroup = group; if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; } //US QString KConfig::group() const { return mGroup; } //US added method QValueList<int> KConfig::readIntListEntry( const QString & key) { // qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); QValueList<int> result; QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); if ( mit == mStringMap.end() ) { return result; } QStringList valuesAsStrings = QStringList::split(":", *mit ); bool ok = false; bool ok2 = true; int val; for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { val = (*sit).toInt(&ok); result << val; if (ok == false) { qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); ok2 = false; } } if (ok2 == false) { - kdDebug() << "KConfig::readIntListEntry: error while reading one of the intvalues." << endl; + qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); } return result; } int KConfig::readNumEntry( const QString & key, int def ) { QString res = readEntry(key, QString::number(def ) ); bool ok = false; int result = res.toInt(&ok); if ( ok ) return result; return def; } QString KConfig::readEntry( const QString &key, const QString &def ) { QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); if ( it == mStringMap.end() ) { return def; } @@ -206,49 +218,49 @@ void KConfig::writeEntry( const QString & e, const QColor & c ) QStringList l; l.append( QString::number ( c.red() ) ); l.append( QString::number ( c.green() ) ); l.append( QString::number ( c.blue() ) ); writeEntry( e, l ); } void KConfig::writeEntry( const QString & e , const QFont & f ) { QStringList font; font.append( f.family()); font.append( (!f.bold ()?"nonbold":"bold") ); font.append( QString::number ( f.pointSize () ) ); font.append( !f.italic ()?"nonitalic":"italic" ); writeEntry( e, font ); } void KConfig::writeEntry( const QString &key, const QDateTime &dt ) { mDateTimeMap.insert( mGroup + key, dt ); } void KConfig::load() { - kdDebug() << "KConfig::load(): " << mFileName << endl; + QFile f( mFileName ); if ( !f.open( IO_ReadOnly ) ) { qDebug("KConfig: could not open file %s ",mFileName.latin1() ); return; } mBoolMap.clear(); mStringMap.clear(); QTextStream t( &f ); QString line = t.readLine(); while ( !line.isNull() ) { QStringList tokens = QStringList::split( ",", line ); if ( tokens[0] == "bool" ) { bool value = false; if ( tokens[2] == "1" ) value = true; mBoolMap.insert( tokens[1], value ); } else if ( tokens[0] == "QString" ) { QString value = tokens[2]; mStringMap.insert( tokens[1], value ); } else if ( tokens[0] == "QDateTime" ) { diff --git a/microkde/kconfig.h b/microkde/kconfig.h index bfedf53..a01b1a5 100644 --- a/microkde/kconfig.h +++ b/microkde/kconfig.h @@ -1,41 +1,44 @@ #ifndef MINIKDE_KCONFIG_H #define MINIKDE_KCONFIG_H #include <qstring.h> #include <qstringlist.h> #include <qvaluelist.h> #include <qcolor.h> #include <qfont.h> #include <qmap.h> #include <qdatetime.h> class KConfig { public: KConfig( const QString & ); ~KConfig(); + void setTempGroup( const QString &group ); + QString tempGroup() const; + void setGroup( const QString & ); //US /** * Returns the name of the group in which we are * searching for keys and from which we are retrieving entries. * * @return The current group. */ QString group() const; //US I took the following deleteGroup method from a newer version from KDE. /** * Deletes a configuration entry group * * If the group is not empty and bDeep is false, nothing gets * deleted and false is returned. * If this group is the current group and it is deleted, the * current group is undefined and should be set with setGroup() * before the next operation on the configuration object. * * @param group The name of the group * returns true if we deleted at least one entry. */ @@ -66,35 +69,36 @@ class KConfig bool hasKey( const QString &); void writeEntry( const QString &, const QValueList<int>& ); void writeEntry( const QString &, int ); void writeEntry( const QString &key , unsigned int value) { writeEntry( key, int( value ) ); } void writeEntry( const char *key , unsigned int value) { writeEntry( QString( key ), value ); } void writeEntry( const char *key, int value ) { writeEntry( QString( key ), value ); } void writeEntry( const QString &, const QString & ); void writeEntry( const char *key, const QString &value ) { writeEntry( QString( key ), value ); } void writeEntry( const QString &, const QStringList & ); void writeEntry( const QString &, bool ); void writeEntry( const char *key, bool value ) { writeEntry( QString( key ), value ); } void writeEntry( const QString &, const QColor & ); void writeEntry( const QString &, const QFont & ); void writeEntry( const QString &, const QDateTime & ); void deleteEntry( const QString &); void load(); void sync(); private: static QString mGroup; + QString mTempGroup; QString mFileName; QMap<QString,bool> mBoolMap; QMap<QString,QString> mStringMap; QMap<QString,QDateTime> mDateTimeMap; bool mDirty; }; #endif diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp index 1baa6be..785b6b4 100644 --- a/microkde/kresources/managerimpl.cpp +++ b/microkde/kresources/managerimpl.cpp @@ -232,54 +232,59 @@ QPtrList<Resource> ManagerImpl::resources( bool active ) QPtrList<Resource> result; Resource::List::ConstIterator it; for ( it = mResources.begin(); it != mResources.end(); ++it ) { if ( (*it)->isActive() == active ) { result.append( *it ); } } return result; } void ManagerImpl::setListener( ManagerImplListener *listener ) { mListener = listener; } Resource* ManagerImpl::readResourceConfig( const QString& identifier, bool checkActive ) { kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl; // qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1()); mConfig->setGroup( "Resource_" + identifier ); - +#ifdef _WIN32_ + // we use plugins on win32. the group is stored in a static variable + // such that gourp info not avail on win32 plugins + // to fix that, it would be a looooot of work + mConfig->setTempGroup( "Resource_" + identifier ); +#endif QString type = mConfig->readEntry( "ResourceType" ); QString name = mConfig->readEntry( "ResourceName" ); Resource *resource = mFactory->resource( type, mConfig ); if ( !resource ) { - kdDebug(5650) << "Failed to create resource with id " << identifier << endl; + qDebug("Failed to create resource with id %s ",identifier.latin1() ); return 0; } if ( resource->identifier().isEmpty() ) resource->setIdentifier( identifier ); mConfig->setGroup( "General" ); QString standardKey = mConfig->readEntry( "Standard" ); if ( standardKey == identifier ) { mStandard = resource; } if ( checkActive ) { QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); resource->setActive( activeKeys.contains( identifier ) ); } mResources.append( resource ); return resource; } void ManagerImpl::writeResourceConfig( Resource *resource, bool checkActive ) diff --git a/microkde/kresources/resource.cpp b/microkde/kresources/resource.cpp index 7827a67..991d53d 100644 --- a/microkde/kresources/resource.cpp +++ b/microkde/kresources/resource.cpp @@ -32,48 +32,55 @@ using namespace KRES; class Resource::ResourcePrivate { public: #ifdef QT_THREAD_SUPPORT QMutex mMutex; #endif int mOpenCount; QString mType; QString mIdentifier; bool mReadOnly; QString mName; bool mActive; bool mIsOpen; }; Resource::Resource( const KConfig* config ) : QObject( 0, "" ), d( new ResourcePrivate ) { d->mOpenCount = 0; d->mIsOpen = false; //US compiler claimed that const discards qualifier KConfig* cfg = (KConfig*)config; if ( cfg ) { +#ifdef _WIN32_ + // we use plugins on win32. the group is stored in a static variable + // such that group info not available on win32 plugins + // to fix that, it would be a looooot of work + if ( !cfg->tempGroup().isEmpty() ) + cfg->setGroup( cfg->tempGroup() ); +#endif d->mType = cfg->readEntry( "ResourceType" ); d->mName = cfg->readEntry( "ResourceName" ); d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false ); d->mActive = cfg->readBoolEntry( "ResourceIsActive", true ); d->mIdentifier = cfg->readEntry( "ResourceIdentifier" ); } else { d->mType = "type"; d->mName = "resource-name"; d->mReadOnly = false; d->mActive = true; d->mIdentifier = KApplication::randomString( 10 ); } } Resource::~Resource() { delete d; d = 0; } void Resource::writeConfig( KConfig* config ) { |