-rw-r--r-- | libkdepim/kpimglobalprefs.cpp | 76 | ||||
-rw-r--r-- | libkdepim/kpimglobalprefs.h | 2 |
2 files changed, 74 insertions, 4 deletions
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$ | |||
35 | #include <kstaticdeleter.h> | 35 | #include <kstaticdeleter.h> |
36 | 36 | ||
37 | #include <qregexp.h> | 37 | #include <qregexp.h> |
38 | #include <qfile.h> | ||
39 | #include <qtextstream.h> | ||
40 | #include <qapplication.h> | ||
38 | #include "kpimglobalprefs.h" | 41 | #include "kpimglobalprefs.h" |
39 | 42 | ||
40 | KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0; | 43 | KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0; |
41 | static KStaticDeleter<KPimGlobalPrefs> staticDeleter; | 44 | static KStaticDeleter<KPimGlobalPrefs> staticDeleterGP; |
42 | 45 | ||
43 | 46 | ||
44 | KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) | 47 | KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) |
45 | : KPrefs("microkdeglobalrc") | 48 | : KPrefs("microkdeglobalrc") |
46 | { | 49 | { |
47 | 50 | mLocaleDict = 0; | |
48 | KPrefs::setCurrentGroup("Locale"); | 51 | KPrefs::setCurrentGroup("Locale"); |
49 | addItemInt("PreferredLanguage",&mPreferredLanguage,0); | 52 | addItemInt("PreferredLanguage",&mPreferredLanguage,0); |
50 | addItemInt("PreferredTime",&mPreferredTime,0); | 53 | addItemInt("PreferredTime",&mPreferredTime,0); |
@@ -104,9 +107,68 @@ KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) | |||
104 | 107 | ||
105 | } | 108 | } |
106 | 109 | ||
107 | |||
108 | void KPimGlobalPrefs::setGlobalConfig() | 110 | void KPimGlobalPrefs::setGlobalConfig() |
109 | { | 111 | { |
112 | if ( mLocaleDict == 0 ) { | ||
113 | QString fileName ; | ||
114 | QString name = KGlobal::getAppName() +"/"; | ||
115 | #ifndef DESKTOP_VERSION | ||
116 | fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/"+name | ||
117 | #else | ||
118 | fileName = qApp->applicationDirPath () + "/kdepim/"+ name; | ||
119 | #endif | ||
120 | mLocaleDict = 0; | ||
121 | if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) { | ||
122 | |||
123 | if ( mPreferredLanguage == 1 ) | ||
124 | fileName = fileName+"germantranslation.txt"; | ||
125 | else if ( mPreferredLanguage == 4 ) | ||
126 | fileName = fileName+"usertranslation.txt"; | ||
127 | else if ( mPreferredLanguage == 2 ) | ||
128 | fileName = fileName+"frenchtranslation.txt"; | ||
129 | else if ( mPreferredLanguage == 3 ) | ||
130 | fileName = fileName+"italiantranslation.txt"; | ||
131 | QFile file( fileName ); | ||
132 | if (file.open( IO_ReadOnly ) ) { | ||
133 | QTextStream ts( &file ); | ||
134 | ts.setEncoding( QTextStream::Latin1 ); | ||
135 | //ts.setCodec( QTextCodec::latin1 ); | ||
136 | QString text = ts.read(); | ||
137 | file.close(); | ||
138 | text.replace( QRegExp("\\\\n"), "\n" ); | ||
139 | QString line; | ||
140 | QString we; | ||
141 | QString wt; | ||
142 | int br = 0; | ||
143 | int nbr; | ||
144 | nbr = text.find ( "},", br ); | ||
145 | line = text.mid( br, nbr - br ); | ||
146 | br = nbr+1; | ||
147 | int se, ee, st, et; | ||
148 | mLocaleDict = new QDict<QString>; | ||
149 | QString end = "{ \"\",\"\" }"; | ||
150 | while ( (line != end) && (br > 1) ) { | ||
151 | //qDebug("%d *%s* ", br, line.latin1()); | ||
152 | se = line.find("\"")+1; | ||
153 | et = line.findRev("\"",-1); | ||
154 | ee = line.find("\",\""); | ||
155 | st = ee+3; | ||
156 | we = line.mid( se, ee-se ); | ||
157 | wt = line.mid( st, et-st ); | ||
158 | //qDebug("*%s* *%s* ", we.latin1(), wt.latin1()); | ||
159 | mLocaleDict->insert( we, new QString (wt) ); | ||
160 | nbr = text.find ( "}", br ); | ||
161 | line = text.mid( br, nbr - br ); | ||
162 | br = nbr+1; | ||
163 | } | ||
164 | //qDebug("end *%s* ", end.latin1()); | ||
165 | |||
166 | setLocaleDict( mLocaleDict ); | ||
167 | } else { | ||
168 | qDebug("KO: Cannot find translation file %s",fileName.latin1() ); | ||
169 | } | ||
170 | } | ||
171 | } | ||
110 | 172 | ||
111 | KGlobal::locale()->setHore24Format( !mPreferredTime ); | 173 | KGlobal::locale()->setHore24Format( !mPreferredTime ); |
112 | KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); | 174 | KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); |
@@ -124,14 +186,20 @@ void KPimGlobalPrefs::setGlobalConfig() | |||
124 | } | 186 | } |
125 | KPimGlobalPrefs::~KPimGlobalPrefs() | 187 | KPimGlobalPrefs::~KPimGlobalPrefs() |
126 | { | 188 | { |
189 | if (sInstance == this) | ||
190 | sInstance = staticDeleterGP.setObject(0); | ||
191 | else | ||
192 | qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?"); | ||
127 | //qDebug("KPimGlobalPrefs::~KPimGlobalPrefs() "); | 193 | //qDebug("KPimGlobalPrefs::~KPimGlobalPrefs() "); |
128 | writeConfig(); | 194 | writeConfig(); |
195 | if ( mLocaleDict ) | ||
196 | delete mLocaleDict; | ||
129 | } | 197 | } |
130 | 198 | ||
131 | KPimGlobalPrefs *KPimGlobalPrefs::instance() | 199 | KPimGlobalPrefs *KPimGlobalPrefs::instance() |
132 | { | 200 | { |
133 | if ( !sInstance ) { | 201 | if ( !sInstance ) { |
134 | sInstance = staticDeleter.setObject( new KPimGlobalPrefs() ); | 202 | sInstance = staticDeleterGP.setObject( new KPimGlobalPrefs() ); |
135 | sInstance->readConfig(); | 203 | sInstance->readConfig(); |
136 | } | 204 | } |
137 | 205 | ||
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$ | |||
32 | #define KPIMGLOBALPREFS_H | 32 | #define KPIMGLOBALPREFS_H |
33 | 33 | ||
34 | #include "kprefs.h" | 34 | #include "kprefs.h" |
35 | #include <qdict.h> | ||
35 | 36 | ||
36 | class KPimGlobalPrefs : public KPrefs | 37 | class KPimGlobalPrefs : public KPrefs |
37 | { | 38 | { |
@@ -83,6 +84,7 @@ class KPimGlobalPrefs : public KPrefs | |||
83 | KPimGlobalPrefs( const QString &name = QString::null ); | 84 | KPimGlobalPrefs( const QString &name = QString::null ); |
84 | 85 | ||
85 | static KPimGlobalPrefs *sInstance; | 86 | static KPimGlobalPrefs *sInstance; |
87 | QDict<QString> *mLocaleDict; | ||
86 | 88 | ||
87 | 89 | ||
88 | public: | 90 | public: |