author | zautrix <zautrix> | 2004-10-23 11:40:59 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-23 11:40:59 (UTC) |
commit | 25b0233d54a6d4bea457fd843073e57183d8bea0 (patch) (unidiff) | |
tree | 4d85c3cec59e8b085738be7111c7e2bb0ee7219e /kaddressbook | |
parent | ba2583db0431059cd7368be23c9653e81af16d29 (diff) | |
download | kdepimpi-25b0233d54a6d4bea457fd843073e57183d8bea0.zip kdepimpi-25b0233d54a6d4bea457fd843073e57183d8bea0.tar.gz kdepimpi-25b0233d54a6d4bea457fd843073e57183d8bea0.tar.bz2 |
global settings bugfixes
-rw-r--r-- | kaddressbook/kabprefs.cpp | 73 | ||||
-rw-r--r-- | kaddressbook/kabprefs.h | 1 |
2 files changed, 5 insertions, 69 deletions
diff --git a/kaddressbook/kabprefs.cpp b/kaddressbook/kabprefs.cpp index 01c935f..3cbcc9a 100644 --- a/kaddressbook/kabprefs.cpp +++ b/kaddressbook/kabprefs.cpp | |||
@@ -1,213 +1,150 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | //US#ifdef KAB_EMBEDDED | 24 | //US#ifdef KAB_EMBEDDED |
25 | //#include <qstring.h> | 25 | //#include <qstring.h> |
26 | //#endif //KAB_EMBEDDED | 26 | //#endif //KAB_EMBEDDED |
27 | 27 | ||
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qregexp.h> | 30 | #include <qregexp.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <libkdepim/kpimglobalprefs.h> | 32 | #include <libkdepim/kpimglobalprefs.h> |
33 | 33 | ||
34 | #include <kconfig.h> | 34 | #include <kconfig.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | #include <kstaticdeleter.h> | 36 | #include <kstaticdeleter.h> |
37 | //US#include <kdebug.h> // defines kdDebug() | 37 | //US#include <kdebug.h> // defines kdDebug() |
38 | 38 | ||
39 | #include "kabprefs.h" | 39 | #include "kabprefs.h" |
40 | 40 | ||
41 | #ifdef DESKTOP_VERSION | 41 | #ifdef DESKTOP_VERSION |
42 | #include <qapplication.h> | 42 | #include <qapplication.h> |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | KABPrefs *KABPrefs::sInstance = 0; | 45 | KABPrefs *KABPrefs::sInstance = 0; |
46 | static KStaticDeleter<KABPrefs> staticDeleter; | 46 | static KStaticDeleter<KABPrefs> staticDeleterAB; |
47 | 47 | ||
48 | KABPrefs::KABPrefs() | 48 | KABPrefs::KABPrefs() |
49 | : KPimPrefs("kaddressbookrc") | 49 | : KPimPrefs("kaddressbookrc") |
50 | { | 50 | { |
51 | |||
52 | mLocaleDict = 0; | ||
53 | mDetailsFont = QFont("helvetica",12); | 51 | mDetailsFont = QFont("helvetica",12); |
54 | KPrefs::setCurrentGroup( "Views" ); | 52 | KPrefs::setCurrentGroup( "Views" ); |
55 | addItemBool( "HonorSingleClick", &mHonorSingleClick, false ); | 53 | addItemBool( "HonorSingleClick", &mHonorSingleClick, false ); |
56 | 54 | ||
57 | KPrefs::setCurrentGroup( "General" ); | 55 | KPrefs::setCurrentGroup( "General" ); |
58 | addItemBool( "AutomaticNameParsing", &mAutomaticNameParsing, true ); | 56 | addItemBool( "AutomaticNameParsing", &mAutomaticNameParsing, true ); |
59 | addItemInt( "CurrentIncSearchField", &mCurrentIncSearchField, 0 ); | 57 | addItemInt( "CurrentIncSearchField", &mCurrentIncSearchField, 0 ); |
60 | 58 | ||
61 | #ifdef KAB_EMBEDDED | 59 | #ifdef KAB_EMBEDDED |
62 | addItemBool("AskForQuit",&mAskForQuit,true); | 60 | addItemBool("AskForQuit",&mAskForQuit,true); |
63 | addItemBool("ToolBarHor",&mToolBarHor, true ); | 61 | addItemBool("ToolBarHor",&mToolBarHor, true ); |
64 | addItemBool("ToolBarUp",&mToolBarUp, false ); | 62 | addItemBool("ToolBarUp",&mToolBarUp, false ); |
65 | addItemBool("SearchWithReturn",&mSearchWithReturn, true ); | 63 | addItemBool("SearchWithReturn",&mSearchWithReturn, true ); |
66 | addItemFont("DetailsFont",&mDetailsFont); | 64 | addItemFont("DetailsFont",&mDetailsFont); |
67 | 65 | ||
68 | 66 | ||
69 | #endif //KAB_EMBEDDED | 67 | #endif //KAB_EMBEDDED |
70 | 68 | ||
71 | KPrefs::setCurrentGroup( "MainWindow" ); | 69 | KPrefs::setCurrentGroup( "MainWindow" ); |
72 | addItemBool( "JumpButtonBarVisible", &mJumpButtonBarVisible, false ); | 70 | addItemBool( "JumpButtonBarVisible", &mJumpButtonBarVisible, false ); |
73 | addItemBool( "DetailsPageVisible", &mDetailsPageVisible, true ); | 71 | addItemBool( "DetailsPageVisible", &mDetailsPageVisible, true ); |
74 | addItemIntList( "ExtensionsSplitter", &mExtensionsSplitter ); | 72 | addItemIntList( "ExtensionsSplitter", &mExtensionsSplitter ); |
75 | addItemIntList( "DetailsSplitter", &mDetailsSplitter ); | 73 | addItemIntList( "DetailsSplitter", &mDetailsSplitter ); |
76 | addItemBool( "MultipleViewsAtOnce", &mMultipleViewsAtOnce, true ); | 74 | addItemBool( "MultipleViewsAtOnce", &mMultipleViewsAtOnce, true ); |
77 | 75 | ||
78 | 76 | ||
79 | KPrefs::setCurrentGroup( "Extensions_General" ); | 77 | KPrefs::setCurrentGroup( "Extensions_General" ); |
80 | QStringList defaultExtensions; | 78 | QStringList defaultExtensions; |
81 | defaultExtensions << "merge"; | 79 | defaultExtensions << "merge"; |
82 | defaultExtensions << "distribution_list_editor"; | 80 | defaultExtensions << "distribution_list_editor"; |
83 | addItemInt( "CurrentExtension", &mCurrentExtension, 0 ); | 81 | addItemInt( "CurrentExtension", &mCurrentExtension, 0 ); |
84 | addItemStringList( "ActiveExtensions", &mActiveExtensions, defaultExtensions ); | 82 | addItemStringList( "ActiveExtensions", &mActiveExtensions, defaultExtensions ); |
85 | 83 | ||
86 | KPrefs::setCurrentGroup( "Views" ); | 84 | KPrefs::setCurrentGroup( "Views" ); |
87 | QString defaultView = i18n( "Default Table View" ); | 85 | QString defaultView = i18n( "Default Table View" ); |
88 | addItemString( "CurrentView", &mCurrentView, defaultView ); | 86 | addItemString( "CurrentView", &mCurrentView, defaultView ); |
89 | addItemStringList( "ViewNames", &mViewNames, defaultView ); | 87 | addItemStringList( "ViewNames", &mViewNames, defaultView ); |
90 | 88 | ||
91 | KPrefs::setCurrentGroup( "Filters" ); | 89 | KPrefs::setCurrentGroup( "Filters" ); |
92 | addItemInt( "CurrentFilter", &mCurrentFilter, 0 ); | 90 | addItemInt( "CurrentFilter", &mCurrentFilter, 0 ); |
93 | 91 | ||
94 | } | 92 | } |
95 | 93 | ||
96 | KABPrefs::~KABPrefs() | 94 | KABPrefs::~KABPrefs() |
97 | { | 95 | { |
98 | //qDebug("KABPrefs::~KABPrefs() "); | 96 | //qDebug("KABPrefs::~KABPrefs() "); |
99 | setLocaleDict( 0 ); | 97 | if (sInstance == this) |
100 | if ( mLocaleDict ) | 98 | sInstance = staticDeleterAB.setObject(0); |
101 | delete mLocaleDict; | ||
102 | } | 99 | } |
103 | 100 | ||
104 | KABPrefs *KABPrefs::instance() | 101 | KABPrefs *KABPrefs::instance() |
105 | { | 102 | { |
106 | if ( !sInstance ) { | 103 | if ( !sInstance ) { |
107 | #ifdef KAB_EMBEDDED | 104 | #ifdef KAB_EMBEDDED |
108 | sInstance = staticDeleter.setObject( new KABPrefs() ); | 105 | sInstance = staticDeleterAB.setObject( new KABPrefs() ); |
109 | #else //KAB_EMBEDDED | 106 | #else //KAB_EMBEDDED |
110 | //US the following line has changed ???. Why | 107 | //US the following line has changed ???. Why |
111 | staticDeleter.setObject( sInstance, new KABPrefs() ); | 108 | staticDeleterAB.setObject( sInstance, new KABPrefs() ); |
112 | #endif //KAB_EMBEDDED | 109 | #endif //KAB_EMBEDDED |
113 | sInstance->readConfig(); | 110 | sInstance->readConfig(); |
114 | } | 111 | } |
115 | 112 | ||
116 | return sInstance; | 113 | return sInstance; |
117 | } | 114 | } |
118 | 115 | ||
119 | void KABPrefs::setCategoryDefaults() | 116 | void KABPrefs::setCategoryDefaults() |
120 | { | 117 | { |
121 | mCustomCategories.clear(); | 118 | mCustomCategories.clear(); |
122 | 119 | ||
123 | mCustomCategories << i18n( "Business" ) << i18n( "Family" ) << i18n( "School" ) | 120 | mCustomCategories << i18n( "Business" ) << i18n( "Family" ) << i18n( "School" ) |
124 | << i18n( "Customer" ) << i18n( "Friend" ); | 121 | << i18n( "Customer" ) << i18n( "Friend" ); |
125 | } | 122 | } |
126 | 123 | ||
127 | // US introduce a nonconst way to return the config object. | 124 | // US introduce a nonconst way to return the config object. |
128 | KConfig* KABPrefs::getConfig() | 125 | KConfig* KABPrefs::getConfig() |
129 | { | 126 | { |
130 | return config(); | 127 | return config(); |
131 | } | 128 | } |
132 | void KABPrefs::usrReadConfig() | 129 | void KABPrefs::usrReadConfig() |
133 | { | 130 | { |
134 | QString fileName ; | ||
135 | #ifndef DESKTOP_VERSION | ||
136 | fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/"; | ||
137 | #else | ||
138 | fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/"; | ||
139 | #endif | ||
140 | int mPreferredLanguage = KPimGlobalPrefs::instance()->mPreferredLanguage; | ||
141 | mLocaleDict = 0; | ||
142 | if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) { | ||
143 | |||
144 | if ( mPreferredLanguage == 1 ) | ||
145 | fileName = fileName+"germantranslation.txt"; | ||
146 | else if ( mPreferredLanguage == 4 ) | ||
147 | fileName = fileName+"usertranslation.txt"; | ||
148 | else if ( mPreferredLanguage == 2 ) | ||
149 | fileName = fileName+"frenchtranslation.txt"; | ||
150 | else if ( mPreferredLanguage == 3 ) | ||
151 | fileName = fileName+"italiantranslation.txt"; | ||
152 | QFile file( fileName ); | ||
153 | if (file.open( IO_ReadOnly ) ) { | ||
154 | QTextStream ts( &file ); | ||
155 | ts.setEncoding( QTextStream::Latin1 ); | ||
156 | //ts.setCodec( QTextCodec::latin1 ); | ||
157 | QString text = ts.read(); | ||
158 | file.close(); | ||
159 | text.replace( QRegExp("\\\\n"), "\n" ); | ||
160 | QString line; | ||
161 | QString we; | ||
162 | QString wt; | ||
163 | int br = 0; | ||
164 | int nbr; | ||
165 | nbr = text.find ( "},", br ); | ||
166 | line = text.mid( br, nbr - br ); | ||
167 | br = nbr+1; | ||
168 | int se, ee, st, et; | ||
169 | mLocaleDict = new QDict<QString>; | ||
170 | QString end = "{ \"\",\"\" }"; | ||
171 | while ( (line != end) && (br > 1) ) { | ||
172 | //qDebug("%d *%s* ", br, line.latin1()); | ||
173 | se = line.find("\"")+1; | ||
174 | et = line.findRev("\"",-1); | ||
175 | ee = line.find("\",\""); | ||
176 | st = ee+3; | ||
177 | we = line.mid( se, ee-se ); | ||
178 | wt = line.mid( st, et-st ); | ||
179 | //qDebug("*%s* *%s* ", we.latin1(), wt.latin1()); | ||
180 | mLocaleDict->insert( we, new QString (wt) ); | ||
181 | nbr = text.find ( "}", br ); | ||
182 | line = text.mid( br, nbr - br ); | ||
183 | br = nbr+1; | ||
184 | } | ||
185 | //qDebug("end *%s* ", end.latin1()); | ||
186 | |||
187 | setLocaleDict( mLocaleDict ); | ||
188 | } else { | ||
189 | qDebug("KO: Cannot find translation file %s",fileName.latin1() ); | ||
190 | } | ||
191 | |||
192 | |||
193 | } | ||
194 | KPimPrefs::usrReadConfig(); | 131 | KPimPrefs::usrReadConfig(); |
195 | } | 132 | } |
196 | 133 | ||
197 | 134 | ||
198 | /*US | 135 | /*US |
199 | void KABPrefs::usrSetDefaults() | 136 | void KABPrefs::usrSetDefaults() |
200 | { | 137 | { |
201 | KPimPrefs::usrSetDefaults(); | 138 | KPimPrefs::usrSetDefaults(); |
202 | } | 139 | } |
203 | 140 | ||
204 | void KABPrefs::usrReadConfig() | 141 | void KABPrefs::usrReadConfig() |
205 | { | 142 | { |
206 | KPimPrefs::usrReadConfig(); | 143 | KPimPrefs::usrReadConfig(); |
207 | } | 144 | } |
208 | 145 | ||
209 | void KABPrefs::usrWriteConfig() | 146 | void KABPrefs::usrWriteConfig() |
210 | { | 147 | { |
211 | KPimPrefs::usrWriteConfig(); | 148 | KPimPrefs::usrWriteConfig(); |
212 | } | 149 | } |
213 | */ | 150 | */ |
diff --git a/kaddressbook/kabprefs.h b/kaddressbook/kabprefs.h index 1098f4c..cc8413e 100644 --- a/kaddressbook/kabprefs.h +++ b/kaddressbook/kabprefs.h | |||
@@ -1,96 +1,95 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifndef KABPREFS_H | 24 | #ifndef KABPREFS_H |
25 | #define KABPREFS_H | 25 | #define KABPREFS_H |
26 | 26 | ||
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qdict.h> | 28 | #include <qdict.h> |
29 | 29 | ||
30 | #include <libkdepim/kpimprefs.h> | 30 | #include <libkdepim/kpimprefs.h> |
31 | 31 | ||
32 | class KConfig; | 32 | class KConfig; |
33 | 33 | ||
34 | class KABPrefs : public KPimPrefs | 34 | class KABPrefs : public KPimPrefs |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | virtual ~KABPrefs(); | 37 | virtual ~KABPrefs(); |
38 | 38 | ||
39 | static KABPrefs *instance(); | 39 | static KABPrefs *instance(); |
40 | 40 | ||
41 | // General | 41 | // General |
42 | bool mHonorSingleClick; | 42 | bool mHonorSingleClick; |
43 | bool mAutomaticNameParsing; | 43 | bool mAutomaticNameParsing; |
44 | int mCurrentIncSearchField; | 44 | int mCurrentIncSearchField; |
45 | 45 | ||
46 | #ifdef KAB_EMBEDDED | 46 | #ifdef KAB_EMBEDDED |
47 | // US introduce a nonconst way to return the config object. | 47 | // US introduce a nonconst way to return the config object. |
48 | KConfig* getConfig(); | 48 | KConfig* getConfig(); |
49 | 49 | ||
50 | bool mToolBarHor; | 50 | bool mToolBarHor; |
51 | bool mToolBarUp; | 51 | bool mToolBarUp; |
52 | bool mAskForQuit; | 52 | bool mAskForQuit; |
53 | 53 | ||
54 | 54 | ||
55 | /** Set preferences to default values */ | 55 | /** Set preferences to default values */ |
56 | // void usrSetDefaults(); | 56 | // void usrSetDefaults(); |
57 | 57 | ||
58 | /** Read preferences from config file */ | 58 | /** Read preferences from config file */ |
59 | // void usrReadConfig(); | 59 | // void usrReadConfig(); |
60 | 60 | ||
61 | /** Write preferences to config file */ | 61 | /** Write preferences to config file */ |
62 | // void usrWriteConfig(); | 62 | // void usrWriteConfig(); |
63 | #endif //KAB_EMBEDDED | 63 | #endif //KAB_EMBEDDED |
64 | void usrReadConfig(); | 64 | void usrReadConfig(); |
65 | 65 | ||
66 | 66 | ||
67 | // GUI | 67 | // GUI |
68 | bool mJumpButtonBarVisible; | 68 | bool mJumpButtonBarVisible; |
69 | bool mDetailsPageVisible; | 69 | bool mDetailsPageVisible; |
70 | bool mMultipleViewsAtOnce; | 70 | bool mMultipleViewsAtOnce; |
71 | bool mSearchWithReturn; | 71 | bool mSearchWithReturn; |
72 | QValueList<int> mExtensionsSplitter; | 72 | QValueList<int> mExtensionsSplitter; |
73 | QValueList<int> mDetailsSplitter; | 73 | QValueList<int> mDetailsSplitter; |
74 | 74 | ||
75 | // Extensions stuff | 75 | // Extensions stuff |
76 | int mCurrentExtension; | 76 | int mCurrentExtension; |
77 | QStringList mActiveExtensions; | 77 | QStringList mActiveExtensions; |
78 | 78 | ||
79 | // Views stuff | 79 | // Views stuff |
80 | QString mCurrentView; | 80 | QString mCurrentView; |
81 | QStringList mViewNames; | 81 | QStringList mViewNames; |
82 | 82 | ||
83 | // Filter | 83 | // Filter |
84 | int mCurrentFilter; | 84 | int mCurrentFilter; |
85 | 85 | ||
86 | void setCategoryDefaults(); | 86 | void setCategoryDefaults(); |
87 | QFont mDetailsFont; | 87 | QFont mDetailsFont; |
88 | 88 | ||
89 | private: | 89 | private: |
90 | KABPrefs(); | 90 | KABPrefs(); |
91 | 91 | ||
92 | QDict<QString> *mLocaleDict; | ||
93 | static KABPrefs *sInstance; | 92 | static KABPrefs *sInstance; |
94 | }; | 93 | }; |
95 | 94 | ||
96 | #endif | 95 | #endif |