-rw-r--r-- | kaddressbook/kabprefs.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/kaddressbook/kabprefs.cpp b/kaddressbook/kabprefs.cpp index 9270a7d..4b3ee47 100644 --- a/kaddressbook/kabprefs.cpp +++ b/kaddressbook/kabprefs.cpp @@ -27,2 +27,6 @@ +#include <qtextstream.h> +#include <qfile.h> +#include <stdlib.h> +#include <libkdepim/kpimglobalprefs.h> @@ -41,2 +45,4 @@ KABPrefs::KABPrefs() { + + mLocaleDict = 0; mDetailsFont = QFont("helvetica",12); @@ -87,2 +93,5 @@ KABPrefs::~KABPrefs() //qDebug("KABPrefs::~KABPrefs() "); + setLocaleDict( 0 ); + if ( mLocaleDict ) + delete mLocaleDict; } @@ -117,2 +126,67 @@ KConfig* KABPrefs::getConfig() } +void KABPrefs::usrReadConfig() +{ + QString fileName ; +#ifndef DESKTOP_VERSION + fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/"; +#else + fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/"; +#endif + int mPreferredLanguage = KPimGlobalPrefs::instance()->mPreferredLanguage; + 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>; + 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() ); + } + + + } + qDebug("KABPrefs::usrReadConfig********************** "); + KPimPrefs::usrReadConfig(); +} |