summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabprefs.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kabprefs.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabprefs.cpp74
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
@@ -4,132 +4,206 @@
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>
29#include <qfile.h>
30#include <stdlib.h>
31#include <libkdepim/kpimglobalprefs.h>
28 32
29#include <kconfig.h> 33#include <kconfig.h>
30#include <klocale.h> 34#include <klocale.h>
31#include <kstaticdeleter.h> 35#include <kstaticdeleter.h>
32//US#include <kdebug.h> // defines kdDebug() 36//US#include <kdebug.h> // defines kdDebug()
33 37
34#include "kabprefs.h" 38#include "kabprefs.h"
35 39
36KABPrefs *KABPrefs::sInstance = 0; 40KABPrefs *KABPrefs::sInstance = 0;
37static KStaticDeleter<KABPrefs> staticDeleter; 41static KStaticDeleter<KABPrefs> staticDeleter;
38 42
39KABPrefs::KABPrefs() 43KABPrefs::KABPrefs()
40 : KPimPrefs("kaddressbookrc") 44 : KPimPrefs("kaddressbookrc")
41{ 45{
46
47 mLocaleDict = 0;
42 mDetailsFont = QFont("helvetica",12); 48 mDetailsFont = QFont("helvetica",12);
43 KPrefs::setCurrentGroup( "Views" ); 49 KPrefs::setCurrentGroup( "Views" );
44 addItemBool( "HonorSingleClick", &mHonorSingleClick, false ); 50 addItemBool( "HonorSingleClick", &mHonorSingleClick, false );
45 51
46 KPrefs::setCurrentGroup( "General" ); 52 KPrefs::setCurrentGroup( "General" );
47 addItemBool( "AutomaticNameParsing", &mAutomaticNameParsing, true ); 53 addItemBool( "AutomaticNameParsing", &mAutomaticNameParsing, true );
48 addItemInt( "CurrentIncSearchField", &mCurrentIncSearchField, 0 ); 54 addItemInt( "CurrentIncSearchField", &mCurrentIncSearchField, 0 );
49 55
50#ifdef KAB_EMBEDDED 56#ifdef KAB_EMBEDDED
51 addItemBool("AskForQuit",&mAskForQuit,true); 57 addItemBool("AskForQuit",&mAskForQuit,true);
52 addItemBool("ToolBarHor",&mToolBarHor, true ); 58 addItemBool("ToolBarHor",&mToolBarHor, true );
53 addItemBool("ToolBarUp",&mToolBarUp, false ); 59 addItemBool("ToolBarUp",&mToolBarUp, false );
54 addItemBool("SearchWithReturn",&mSearchWithReturn, true ); 60 addItemBool("SearchWithReturn",&mSearchWithReturn, true );
55 addItemFont("DetailsFont",&mDetailsFont); 61 addItemFont("DetailsFont",&mDetailsFont);
56 62
57 63
58#endif //KAB_EMBEDDED 64#endif //KAB_EMBEDDED
59 65
60 KPrefs::setCurrentGroup( "MainWindow" ); 66 KPrefs::setCurrentGroup( "MainWindow" );
61 addItemBool( "JumpButtonBarVisible", &mJumpButtonBarVisible, false ); 67 addItemBool( "JumpButtonBarVisible", &mJumpButtonBarVisible, false );
62 addItemBool( "DetailsPageVisible", &mDetailsPageVisible, true ); 68 addItemBool( "DetailsPageVisible", &mDetailsPageVisible, true );
63 addItemIntList( "ExtensionsSplitter", &mExtensionsSplitter ); 69 addItemIntList( "ExtensionsSplitter", &mExtensionsSplitter );
64 addItemIntList( "DetailsSplitter", &mDetailsSplitter ); 70 addItemIntList( "DetailsSplitter", &mDetailsSplitter );
65 addItemBool( "MultipleViewsAtOnce", &mMultipleViewsAtOnce, true ); 71 addItemBool( "MultipleViewsAtOnce", &mMultipleViewsAtOnce, true );
66 72
67 73
68 KPrefs::setCurrentGroup( "Extensions_General" ); 74 KPrefs::setCurrentGroup( "Extensions_General" );
69 QStringList defaultExtensions; 75 QStringList defaultExtensions;
70 defaultExtensions << "merge"; 76 defaultExtensions << "merge";
71 defaultExtensions << "distribution_list_editor"; 77 defaultExtensions << "distribution_list_editor";
72 addItemInt( "CurrentExtension", &mCurrentExtension, 0 ); 78 addItemInt( "CurrentExtension", &mCurrentExtension, 0 );
73 addItemStringList( "ActiveExtensions", &mActiveExtensions, defaultExtensions ); 79 addItemStringList( "ActiveExtensions", &mActiveExtensions, defaultExtensions );
74 80
75 KPrefs::setCurrentGroup( "Views" ); 81 KPrefs::setCurrentGroup( "Views" );
76 QString defaultView = i18n( "Default Table View" ); 82 QString defaultView = i18n( "Default Table View" );
77 addItemString( "CurrentView", &mCurrentView, defaultView ); 83 addItemString( "CurrentView", &mCurrentView, defaultView );
78 addItemStringList( "ViewNames", &mViewNames, defaultView ); 84 addItemStringList( "ViewNames", &mViewNames, defaultView );
79 85
80 KPrefs::setCurrentGroup( "Filters" ); 86 KPrefs::setCurrentGroup( "Filters" );
81 addItemInt( "CurrentFilter", &mCurrentFilter, 0 ); 87 addItemInt( "CurrentFilter", &mCurrentFilter, 0 );
82 88
83} 89}
84 90
85KABPrefs::~KABPrefs() 91KABPrefs::~KABPrefs()
86{ 92{
87 //qDebug("KABPrefs::~KABPrefs() "); 93 //qDebug("KABPrefs::~KABPrefs() ");
94 setLocaleDict( 0 );
95 if ( mLocaleDict )
96 delete mLocaleDict;
88} 97}
89 98
90KABPrefs *KABPrefs::instance() 99KABPrefs *KABPrefs::instance()
91{ 100{
92 if ( !sInstance ) { 101 if ( !sInstance ) {
93#ifdef KAB_EMBEDDED 102#ifdef KAB_EMBEDDED
94 sInstance = staticDeleter.setObject( new KABPrefs() ); 103 sInstance = staticDeleter.setObject( new KABPrefs() );
95#else //KAB_EMBEDDED 104#else //KAB_EMBEDDED
96 //US the following line has changed ???. Why 105 //US the following line has changed ???. Why
97 staticDeleter.setObject( sInstance, new KABPrefs() ); 106 staticDeleter.setObject( sInstance, new KABPrefs() );
98#endif //KAB_EMBEDDED 107#endif //KAB_EMBEDDED
99 sInstance->readConfig(); 108 sInstance->readConfig();
100 } 109 }
101 110
102 return sInstance; 111 return sInstance;
103} 112}
104 113
105void KABPrefs::setCategoryDefaults() 114void KABPrefs::setCategoryDefaults()
106{ 115{
107 mCustomCategories.clear(); 116 mCustomCategories.clear();
108 117
109 mCustomCategories << i18n( "Business" ) << i18n( "Family" ) << i18n( "School" ) 118 mCustomCategories << i18n( "Business" ) << i18n( "Family" ) << i18n( "School" )
110 << i18n( "Customer" ) << i18n( "Friend" ); 119 << i18n( "Customer" ) << i18n( "Friend" );
111} 120}
112 121
113 // US introduce a nonconst way to return the config object. 122 // US introduce a nonconst way to return the config object.
114KConfig* KABPrefs::getConfig() 123KConfig* KABPrefs::getConfig()
115{ 124{
116 return config(); 125 return config();
117} 126}
127void KABPrefs::usrReadConfig()
128{
129 QString fileName ;
130#ifndef DESKTOP_VERSION
131 fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/";
132#else
133 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/";
134#endif
135 int mPreferredLanguage = KPimGlobalPrefs::instance()->mPreferredLanguage;
136 mLocaleDict = 0;
137 if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) {
138
139 if ( mPreferredLanguage == 1 )
140 fileName = fileName+"germantranslation.txt";
141 else if ( mPreferredLanguage == 4 )
142 fileName = fileName+"usertranslation.txt";
143 else if ( mPreferredLanguage == 2 )
144 fileName = fileName+"frenchtranslation.txt";
145 else if ( mPreferredLanguage == 3 )
146 fileName = fileName+"italiantranslation.txt";
147 QFile file( fileName );
148 if (file.open( IO_ReadOnly ) ) {
149 QTextStream ts( &file );
150 ts.setEncoding( QTextStream::Latin1 );
151 //ts.setCodec( QTextCodec::latin1 );
152 QString text = ts.read();
153 file.close();
154 text.replace( QRegExp("\\\\n"), "\n" );
155 QString line;
156 QString we;
157 QString wt;
158 int br = 0;
159 int nbr;
160 nbr = text.find ( "},", br );
161 line = text.mid( br, nbr - br );
162 br = nbr+1;
163 int se, ee, st, et;
164 mLocaleDict = new QDict<QString>;
165 QString end = "{ \"\",\"\" }";
166 while ( (line != end) && (br > 1) ) {
167 //qDebug("%d *%s* ", br, line.latin1());
168 se = line.find("\"")+1;
169 et = line.findRev("\"",-1);
170 ee = line.find("\",\"");
171 st = ee+3;
172 we = line.mid( se, ee-se );
173 wt = line.mid( st, et-st );
174 //qDebug("*%s* *%s* ", we.latin1(), wt.latin1());
175 mLocaleDict->insert( we, new QString (wt) );
176 nbr = text.find ( "}", br );
177 line = text.mid( br, nbr - br );
178 br = nbr+1;
179 }
180 //qDebug("end *%s* ", end.latin1());
181
182 setLocaleDict( mLocaleDict );
183 } else {
184 qDebug("KO: Cannot find translation file %s",fileName.latin1() );
185 }
186
187
188 }
189 qDebug("KABPrefs::usrReadConfig********************** ");
190 KPimPrefs::usrReadConfig();
191}
118 192
119 193
120/*US 194/*US
121void KABPrefs::usrSetDefaults() 195void KABPrefs::usrSetDefaults()
122{ 196{
123 KPimPrefs::usrSetDefaults(); 197 KPimPrefs::usrSetDefaults();
124} 198}
125 199
126void KABPrefs::usrReadConfig() 200void KABPrefs::usrReadConfig()
127{ 201{
128 KPimPrefs::usrReadConfig(); 202 KPimPrefs::usrReadConfig();
129} 203}
130 204
131void KABPrefs::usrWriteConfig() 205void KABPrefs::usrWriteConfig()
132{ 206{
133 KPimPrefs::usrWriteConfig(); 207 KPimPrefs::usrWriteConfig();
134} 208}
135*/ 209*/