summaryrefslogtreecommitdiffabout
path: root/libkdepim/kpimglobalprefs.cpp
authorzautrix <zautrix>2004-10-23 14:56:10 (UTC)
committer zautrix <zautrix>2004-10-23 14:56:10 (UTC)
commita682b1d39c63cff8d709c67460569c70b661d889 (patch) (unidiff)
treedd5cb4052b07927b63bafa68b2fd6d40bce6a6dc /libkdepim/kpimglobalprefs.cpp
parent73c0cb5307a8276f628765c651ef0284b85d64de (diff)
downloadkdepimpi-a682b1d39c63cff8d709c67460569c70b661d889.zip
kdepimpi-a682b1d39c63cff8d709c67460569c70b661d889.tar.gz
kdepimpi-a682b1d39c63cff8d709c67460569c70b661d889.tar.bz2
fixed several memory leaks
Diffstat (limited to 'libkdepim/kpimglobalprefs.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kpimglobalprefs.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/libkdepim/kpimglobalprefs.cpp b/libkdepim/kpimglobalprefs.cpp
index 3771569..0fdc3e4 100644
--- a/libkdepim/kpimglobalprefs.cpp
+++ b/libkdepim/kpimglobalprefs.cpp
@@ -1,205 +1,204 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
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/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kconfig.h> 32#include <kconfig.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <kdebug.h> 34#include <kdebug.h>
35#include <kstaticdeleter.h> 35#include <kstaticdeleter.h>
36 36
37#include <qregexp.h> 37#include <qregexp.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qapplication.h> 40#include <qapplication.h>
41#include "kpimglobalprefs.h" 41#include "kpimglobalprefs.h"
42 42
43KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0; 43KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0;
44static KStaticDeleter<KPimGlobalPrefs> staticDeleterGP; 44static KStaticDeleter<KPimGlobalPrefs> staticDeleterGP;
45 45
46 46
47KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) 47KPimGlobalPrefs::KPimGlobalPrefs( const QString &name )
48 : KPrefs("microkdeglobalrc") 48 : KPrefs("microkdeglobalrc")
49{ 49{
50 mLocaleDict = 0; 50 mLocaleDict = 0;
51 KPrefs::setCurrentGroup("Locale"); 51 KPrefs::setCurrentGroup("Locale");
52 addItemInt("PreferredLanguage",&mPreferredLanguage,0); 52 addItemInt("PreferredLanguage",&mPreferredLanguage,0);
53 addItemInt("PreferredTime",&mPreferredTime,0); 53 addItemInt("PreferredTime",&mPreferredTime,0);
54 addItemInt("PreferredDate",&mPreferredDate,0); 54 addItemInt("PreferredDate",&mPreferredDate,0);
55 addItemBool("WeekStartsOnSunday",&mWeekStartsOnSunday,false); 55 addItemBool("WeekStartsOnSunday",&mWeekStartsOnSunday,false);
56 addItemString("UserDateFormatLong", &mUserDateFormatLong, "%A %d %b %y"); 56 addItemString("UserDateFormatLong", &mUserDateFormatLong, "%A %d %b %y");
57 addItemString("UserDateFormatShort", &mUserDateFormatShort, "%aK %d.%m.%y"); 57 addItemString("UserDateFormatShort", &mUserDateFormatShort, "%aK %d.%m.%y");
58 58
59 KPrefs::setCurrentGroup("Time & Date"); 59 KPrefs::setCurrentGroup("Time & Date");
60 60
61 addItemString("TimeZoneName",&mTimeZoneId, ("+01:00 Europe/Oslo(CET)") ); 61 addItemString("TimeZoneName",&mTimeZoneId, ("+01:00 Europe/Oslo(CET)") );
62 addItemBool("UseDaylightsaving",&mUseDaylightsaving,true); 62 addItemBool("UseDaylightsaving",&mUseDaylightsaving,true);
63 addItemBool("TimeZoneAdd30min",&mTimeZoneAdd30min,false); 63 addItemBool("TimeZoneAdd30min",&mTimeZoneAdd30min,false);
64 addItemInt("DaylightsavingStart",&mDaylightsavingStart,90); 64 addItemInt("DaylightsavingStart",&mDaylightsavingStart,90);
65 addItemInt("DaylightsavingEnd",&mDaylightsavingEnd,304); 65 addItemInt("DaylightsavingEnd",&mDaylightsavingEnd,304);
66 66
67 KPrefs::setCurrentGroup( "ExternalApplications" ); 67 KPrefs::setCurrentGroup( "ExternalApplications" );
68 68
69 addItemInt( "EmailChannelType", &mEmailClient, OMPI_EMC ); 69 addItemInt( "EmailChannelType", &mEmailClient, OMPI_EMC );
70 addItemString( "EmailChannel", &mEmailOtherChannel, "" ); 70 addItemString( "EmailChannel", &mEmailOtherChannel, "" );
71 addItemString( "EmailChannelMessage", &mEmailOtherMessage, "" ); 71 addItemString( "EmailChannelMessage", &mEmailOtherMessage, "" );
72 addItemString( "EmailChannelParameters", &mEmailOtherMessageParameters, "" ); 72 addItemString( "EmailChannelParameters", &mEmailOtherMessageParameters, "" );
73 addItemString( "EmailChannelMessage2", &mEmailOtherMessage2, "" ); 73 addItemString( "EmailChannelMessage2", &mEmailOtherMessage2, "" );
74 addItemString( "EmailChannelParameters2", &mEmailOtherMessageParameters2, "" ); 74 addItemString( "EmailChannelParameters2", &mEmailOtherMessageParameters2, "" );
75 75
76 addItemInt( "PhoneChannelType", &mPhoneClient, KPPI_PHC ); 76 addItemInt( "PhoneChannelType", &mPhoneClient, KPPI_PHC );
77 addItemString( "PhoneChannel", &mPhoneOtherChannel, "" ); 77 addItemString( "PhoneChannel", &mPhoneOtherChannel, "" );
78 addItemString( "PhoneChannelMessage", &mPhoneOtherMessage, "" ); 78 addItemString( "PhoneChannelMessage", &mPhoneOtherMessage, "" );
79 addItemString( "PhoneChannelParameters", &mPhoneOtherMessageParameters, "" ); 79 addItemString( "PhoneChannelParameters", &mPhoneOtherMessageParameters, "" );
80 80
81 addItemInt( "FaxChannelType", &mFaxClient, NONE_FAC ); 81 addItemInt( "FaxChannelType", &mFaxClient, NONE_FAC );
82 addItemString( "FaxChannel", &mFaxOtherChannel, "" ); 82 addItemString( "FaxChannel", &mFaxOtherChannel, "" );
83 addItemString( "FaxChannelMessage", &mFaxOtherMessage, "" ); 83 addItemString( "FaxChannelMessage", &mFaxOtherMessage, "" );
84 addItemString( "FaxChannelParameters", &mFaxOtherMessageParameters, "" ); 84 addItemString( "FaxChannelParameters", &mFaxOtherMessageParameters, "" );
85 85
86 addItemInt( "SMSChannelType", &mSMSClient, NONE_SMC ); 86 addItemInt( "SMSChannelType", &mSMSClient, NONE_SMC );
87 addItemString( "SMSChannel", &mSMSOtherChannel, "" ); 87 addItemString( "SMSChannel", &mSMSOtherChannel, "" );
88 addItemString( "SMSChannelMessage", &mSMSOtherMessage, "" ); 88 addItemString( "SMSChannelMessage", &mSMSOtherMessage, "" );
89 addItemString( "SMSChannelParameters", &mSMSOtherMessageParameters, "" ); 89 addItemString( "SMSChannelParameters", &mSMSOtherMessageParameters, "" );
90 90
91 addItemInt( "PagerChannelType", &mPagerClient, NONE_PAC ); 91 addItemInt( "PagerChannelType", &mPagerClient, NONE_PAC );
92 addItemString( "PagerChannel", &mPagerOtherChannel, "" ); 92 addItemString( "PagerChannel", &mPagerOtherChannel, "" );
93 addItemString( "PagerChannelMessage", &mPagerOtherMessage, "" ); 93 addItemString( "PagerChannelMessage", &mPagerOtherMessage, "" );
94 addItemString( "PagerChannelParameters", &mPagerOtherMessageParameters, "" ); 94 addItemString( "PagerChannelParameters", &mPagerOtherMessageParameters, "" );
95 95
96 addItemInt( "SIPChannelType", &mSipClient, KPPI_SIC ); 96 addItemInt( "SIPChannelType", &mSipClient, KPPI_SIC );
97 addItemString( "SIPChannel", &mSipOtherChannel, "" ); 97 addItemString( "SIPChannel", &mSipOtherChannel, "" );
98 addItemString( "SIPChannelMessage", &mSipOtherMessage, "" ); 98 addItemString( "SIPChannelMessage", &mSipOtherMessage, "" );
99 addItemString( "SIPChannelParameters", &mSipOtherMessageParameters, "" ); 99 addItemString( "SIPChannelParameters", &mSipOtherMessageParameters, "" );
100 100
101 KPrefs::setCurrentGroup( "PhoneAccess" ); 101 KPrefs::setCurrentGroup( "PhoneAccess" );
102 addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm"); 102 addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm");
103 addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda"); 103 addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda");
104 addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i"); 104 addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i");
105 105
106} 106}
107 107
108void KPimGlobalPrefs::setGlobalConfig() 108void KPimGlobalPrefs::setGlobalConfig()
109{ 109{
110 if ( mLocaleDict == 0 ) { 110 if ( mLocaleDict == 0 ) {
111 QString fileName ; 111 QString fileName ;
112 QString name = KGlobal::getAppName() +"/"; 112 QString name = KGlobal::getAppName() +"/";
113#ifndef DESKTOP_VERSION 113#ifndef DESKTOP_VERSION
114 fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/"+name 114 fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/"+name
115#else 115#else
116 fileName = qApp->applicationDirPath () + "/kdepim/"+ name; 116 fileName = qApp->applicationDirPath () + "/kdepim/"+ name;
117#endif 117#endif
118 mLocaleDict = 0; 118 mLocaleDict = 0;
119 if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) { 119 if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) {
120 120
121 if ( mPreferredLanguage == 1 ) 121 if ( mPreferredLanguage == 1 )
122 fileName = fileName+"germantranslation.txt"; 122 fileName = fileName+"germantranslation.txt";
123 else if ( mPreferredLanguage == 4 ) 123 else if ( mPreferredLanguage == 4 )
124 fileName = fileName+"usertranslation.txt"; 124 fileName = fileName+"usertranslation.txt";
125 else if ( mPreferredLanguage == 2 ) 125 else if ( mPreferredLanguage == 2 )
126 fileName = fileName+"frenchtranslation.txt"; 126 fileName = fileName+"frenchtranslation.txt";
127 else if ( mPreferredLanguage == 3 ) 127 else if ( mPreferredLanguage == 3 )
128 fileName = fileName+"italiantranslation.txt"; 128 fileName = fileName+"italiantranslation.txt";
129 QFile file( fileName ); 129 QFile file( fileName );
130 if (file.open( IO_ReadOnly ) ) { 130 if (file.open( IO_ReadOnly ) ) {
131 QTextStream ts( &file ); 131 QTextStream ts( &file );
132 ts.setEncoding( QTextStream::Latin1 ); 132 ts.setEncoding( QTextStream::Latin1 );
133 //ts.setCodec( QTextCodec::latin1 ); 133 //ts.setCodec( QTextCodec::latin1 );
134 QString text = ts.read(); 134 QString text = ts.read();
135 file.close(); 135 file.close();
136 text.replace( QRegExp("\\\\n"), "\n" ); 136 text.replace( QRegExp("\\\\n"), "\n" );
137 QString line; 137 QString line;
138 QString we; 138 QString we;
139 QString wt; 139 QString wt;
140 int br = 0; 140 int br = 0;
141 int nbr; 141 int nbr;
142 nbr = text.find ( "},", br ); 142 nbr = text.find ( "},", br );
143 line = text.mid( br, nbr - br ); 143 line = text.mid( br, nbr - br );
144 br = nbr+1; 144 br = nbr+1;
145 int se, ee, st, et; 145 int se, ee, st, et;
146 mLocaleDict = new QDict<QString>; 146 mLocaleDict = new QDict<QString>;
147 mLocaleDict->setAutoDelete( true );
147 QString end = "{ \"\",\"\" }"; 148 QString end = "{ \"\",\"\" }";
148 while ( (line != end) && (br > 1) ) { 149 while ( (line != end) && (br > 1) ) {
149 //qDebug("%d *%s* ", br, line.latin1()); 150 //qDebug("%d *%s* ", br, line.latin1());
150 se = line.find("\"")+1; 151 se = line.find("\"")+1;
151 et = line.findRev("\"",-1); 152 et = line.findRev("\"",-1);
152 ee = line.find("\",\""); 153 ee = line.find("\",\"");
153 st = ee+3; 154 st = ee+3;
154 we = line.mid( se, ee-se ); 155 we = line.mid( se, ee-se );
155 wt = line.mid( st, et-st ); 156 wt = line.mid( st, et-st );
156 //qDebug("*%s* *%s* ", we.latin1(), wt.latin1()); 157 //qDebug("*%s* *%s* ", we.latin1(), wt.latin1());
157 mLocaleDict->insert( we, new QString (wt) ); 158 mLocaleDict->insert( we, new QString (wt) );
158 nbr = text.find ( "}", br ); 159 nbr = text.find ( "}", br );
159 line = text.mid( br, nbr - br ); 160 line = text.mid( br, nbr - br );
160 br = nbr+1; 161 br = nbr+1;
161 } 162 }
162 //qDebug("end *%s* ", end.latin1()); 163 //qDebug("end *%s* ", end.latin1());
163 164
164 setLocaleDict( mLocaleDict ); 165 setLocaleDict( mLocaleDict );
165 } else { 166 } else {
166 qDebug("KO: Cannot find translation file %s",fileName.latin1() ); 167 qDebug("KO: Cannot find translation file %s",fileName.latin1() );
167 } 168 }
168 } 169 }
169 } 170 }
170 171
171 KGlobal::locale()->setHore24Format( !mPreferredTime ); 172 KGlobal::locale()->setHore24Format( !mPreferredTime );
172 KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); 173 KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday );
173 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)mPreferredDate ); 174 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)mPreferredDate );
174 KGlobal::locale()->setLanguage( mPreferredLanguage ); 175 KGlobal::locale()->setLanguage( mPreferredLanguage );
175 QString dummy = mUserDateFormatLong; 176 QString dummy = mUserDateFormatLong;
176 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 177 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
177 dummy = mUserDateFormatShort; 178 dummy = mUserDateFormatShort;
178 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 179 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
179 KGlobal::locale()->setDaylightSaving( mUseDaylightsaving, 180 KGlobal::locale()->setDaylightSaving( mUseDaylightsaving,
180 mDaylightsavingStart, 181 mDaylightsavingStart,
181 mDaylightsavingEnd ); 182 mDaylightsavingEnd );
182 KGlobal::locale()->setTimezone( mTimeZoneId, mTimeZoneAdd30min ); 183 KGlobal::locale()->setTimezone( mTimeZoneId, mTimeZoneAdd30min );
183 184
184} 185}
185KPimGlobalPrefs::~KPimGlobalPrefs() 186KPimGlobalPrefs::~KPimGlobalPrefs()
186{ 187{
187 if (sInstance == this) 188 if (sInstance == this)
188 sInstance = staticDeleterGP.setObject(0); 189 sInstance = staticDeleterGP.setObject(0);
189 else 190 else
190 qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?"); 191 qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?");
191 //qDebug("KPimGlobalPrefs::~KPimGlobalPrefs() ");
192 writeConfig();
193 if ( mLocaleDict ) 192 if ( mLocaleDict )
194 delete mLocaleDict; 193 delete mLocaleDict;
195} 194}
196 195
197KPimGlobalPrefs *KPimGlobalPrefs::instance() 196KPimGlobalPrefs *KPimGlobalPrefs::instance()
198{ 197{
199 if ( !sInstance ) { 198 if ( !sInstance ) {
200 sInstance = staticDeleterGP.setObject( new KPimGlobalPrefs() ); 199 sInstance = staticDeleterGP.setObject( new KPimGlobalPrefs() );
201 sInstance->readConfig(); 200 sInstance->readConfig();
202 } 201 }
203 202
204 return sInstance; 203 return sInstance;
205} 204}