From 25b0233d54a6d4bea457fd843073e57183d8bea0 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sat, 23 Oct 2004 11:40:59 +0000 Subject: global settings bugfixes --- (limited to 'libkdepim') diff --git a/libkdepim/kpimglobalprefs.cpp b/libkdepim/kpimglobalprefs.cpp index 0a580ca..5298f0c 100644 --- a/libkdepim/kpimglobalprefs.cpp +++ b/libkdepim/kpimglobalprefs.cpp @@ -35,16 +35,19 @@ $Id$ #include #include +#include +#include +#include #include "kpimglobalprefs.h" KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0; -static KStaticDeleter staticDeleter; +static KStaticDeleter staticDeleterGP; KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) : KPrefs("microkdeglobalrc") { - + mLocaleDict = 0; KPrefs::setCurrentGroup("Locale"); addItemInt("PreferredLanguage",&mPreferredLanguage,0); addItemInt("PreferredTime",&mPreferredTime,0); @@ -104,9 +107,68 @@ KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) } - void KPimGlobalPrefs::setGlobalConfig() { + if ( mLocaleDict == 0 ) { + QString fileName ; + QString name = KGlobal::getAppName() +"/"; +#ifndef DESKTOP_VERSION + fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/"+name +#else + fileName = qApp->applicationDirPath () + "/kdepim/"+ name; +#endif + mLocaleDict = 0; + if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) { + + if ( mPreferredLanguage == 1 ) + fileName = fileName+"germantranslation.txt"; + else if ( mPreferredLanguage == 4 ) + fileName = fileName+"usertranslation.txt"; + else if ( mPreferredLanguage == 2 ) + fileName = fileName+"frenchtranslation.txt"; + else if ( mPreferredLanguage == 3 ) + fileName = fileName+"italiantranslation.txt"; + QFile file( fileName ); + if (file.open( IO_ReadOnly ) ) { + QTextStream ts( &file ); + ts.setEncoding( QTextStream::Latin1 ); + //ts.setCodec( QTextCodec::latin1 ); + QString text = ts.read(); + file.close(); + text.replace( QRegExp("\\\\n"), "\n" ); + QString line; + QString we; + QString wt; + int br = 0; + int nbr; + nbr = text.find ( "},", br ); + line = text.mid( br, nbr - br ); + br = nbr+1; + int se, ee, st, et; + mLocaleDict = new QDict; + QString end = "{ \"\",\"\" }"; + while ( (line != end) && (br > 1) ) { + //qDebug("%d *%s* ", br, line.latin1()); + se = line.find("\"")+1; + et = line.findRev("\"",-1); + ee = line.find("\",\""); + st = ee+3; + we = line.mid( se, ee-se ); + wt = line.mid( st, et-st ); + //qDebug("*%s* *%s* ", we.latin1(), wt.latin1()); + mLocaleDict->insert( we, new QString (wt) ); + nbr = text.find ( "}", br ); + line = text.mid( br, nbr - br ); + br = nbr+1; + } + //qDebug("end *%s* ", end.latin1()); + + setLocaleDict( mLocaleDict ); + } else { + qDebug("KO: Cannot find translation file %s",fileName.latin1() ); + } + } + } KGlobal::locale()->setHore24Format( !mPreferredTime ); KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); @@ -124,14 +186,20 @@ void KPimGlobalPrefs::setGlobalConfig() } KPimGlobalPrefs::~KPimGlobalPrefs() { + if (sInstance == this) + sInstance = staticDeleterGP.setObject(0); + else + qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?"); //qDebug("KPimGlobalPrefs::~KPimGlobalPrefs() "); writeConfig(); + if ( mLocaleDict ) + delete mLocaleDict; } KPimGlobalPrefs *KPimGlobalPrefs::instance() { if ( !sInstance ) { - sInstance = staticDeleter.setObject( new KPimGlobalPrefs() ); + sInstance = staticDeleterGP.setObject( new KPimGlobalPrefs() ); sInstance->readConfig(); } diff --git a/libkdepim/kpimglobalprefs.h b/libkdepim/kpimglobalprefs.h index d09c3da..11c534a 100644 --- a/libkdepim/kpimglobalprefs.h +++ b/libkdepim/kpimglobalprefs.h @@ -32,6 +32,7 @@ $Id$ #define KPIMGLOBALPREFS_H #include "kprefs.h" +#include class KPimGlobalPrefs : public KPrefs { @@ -83,6 +84,7 @@ class KPimGlobalPrefs : public KPrefs KPimGlobalPrefs( const QString &name = QString::null ); static KPimGlobalPrefs *sInstance; + QDict *mLocaleDict; public: -- cgit v0.9.0.2