4 * Copyright (c) 1999-2003 Hans Petter Bieker <bieker@kde.org>
6 * Requires the Qt widget libraries, available at no cost at
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
36 #include <KConfigGroup>
37 #include <KStandardDirs>
40 #include "localemon.h"
41 #include "localemon.moc"
43 KLocaleConfigMoney::KLocaleConfigMoney(KLocale
*locale
,
51 m_labMonCurSym
->setObjectName( I18N_NOOP("Currency symbol:") );
52 m_labMonDecSym
->setObjectName( I18N_NOOP("Decimal symbol:") );
53 m_labMonThoSep
->setObjectName( I18N_NOOP("Thousands separator:") );
54 m_labMonFraDig
->setObjectName( I18N_NOOP("Fract digits:") );
55 m_positiveGB
->setObjectName( I18N_NOOP("Positive") );
56 m_chMonPosPreCurSym
->setObjectName(I18N_NOOP("Prefix currency symbol"));
57 m_labMonPosMonSignPos
->setObjectName( I18N_NOOP("Sign position:") );
58 m_negativeGB
->setObjectName( I18N_NOOP("Negative") );
59 m_chMonNegPreCurSym
->setObjectName(I18N_NOOP("Prefix currency symbol"));
60 m_labMonNegMonSignPos
->setObjectName( I18N_NOOP("Sign position:") );
62 connect( m_edMonCurSym
, SIGNAL( textChanged(const QString
&) ),
63 SLOT( slotMonCurSymChanged(const QString
&) ) );
65 connect( m_edMonDecSym
, SIGNAL( textChanged(const QString
&) ),
66 SLOT( slotMonDecSymChanged(const QString
&) ) );
68 connect( m_edMonThoSep
, SIGNAL( textChanged(const QString
&) ),
69 SLOT( slotMonThoSepChanged(const QString
&) ) );
71 connect( m_inMonFraDig
, SIGNAL( valueChanged(int) ),
72 SLOT( slotMonFraDigChanged(int) ) );
74 connect( m_chMonPosPreCurSym
, SIGNAL( clicked() ),
75 SLOT( slotMonPosPreCurSymChanged() ) );
77 connect( m_cmbMonPosMonSignPos
, SIGNAL( activated(int) ),
78 SLOT( slotMonPosMonSignPosChanged(int) ) );
80 connect( m_chMonNegPreCurSym
, SIGNAL( clicked() ),
81 SLOT( slotMonNegPreCurSymChanged() ) );
83 connect( m_cmbMonNegMonSignPos
, SIGNAL( activated(int) ),
84 SLOT( slotMonNegMonSignPosChanged(int) ) );
86 m_inMonFraDig
->setRange(0, 10, 1);
87 m_inMonFraDig
->setSliderEnabled(false);
90 KLocaleConfigMoney::~KLocaleConfigMoney()
94 void KLocaleConfigMoney::save()
96 KSharedConfig::Ptr config
= KGlobal::config();
97 KConfigGroup
group(config
, "Locale");
98 KConfig
ent(KStandardDirs::locate("locale",
99 QString::fromLatin1("l10n/%1/entry.desktop")
100 .arg(m_locale
->country())));
101 KConfigGroup entGrp
= ent
.group("KCM Locale");
107 str
= entGrp
.readEntry("CurrencySymbol", QString::fromLatin1("$"));
108 group
.deleteEntry("CurrencySymbol", KConfig::Persistent
| KConfig::Global
);
109 if (str
!= m_locale
->currencySymbol())
110 group
.writeEntry("CurrencySymbol",
111 m_locale
->currencySymbol(), KConfig::Persistent
|KConfig::Global
);
113 str
= entGrp
.readEntry("MonetaryDecimalSymbol", QString::fromLatin1("."));
114 group
.deleteEntry("MonetaryDecimalSymbol", KConfig::Persistent
| KConfig::Global
);
115 if (str
!= m_locale
->monetaryDecimalSymbol())
116 group
.writeEntry("MonetaryDecimalSymbol",
117 m_locale
->monetaryDecimalSymbol(), KConfig::Persistent
|KConfig::Global
);
119 str
= entGrp
.readEntry("MonetaryThousandsSeparator", QString::fromLatin1(","));
120 str
.replace(QString::fromLatin1("$0"), QString());
121 group
.deleteEntry("MonetaryThousandsSeparator", KConfig::Persistent
| KConfig::Global
);
122 if (str
!= m_locale
->monetaryThousandsSeparator())
123 group
.writeEntry("MonetaryThousandsSeparator",
124 QString::fromLatin1("$0%1$0")
125 .arg(m_locale
->monetaryThousandsSeparator()),
126 KConfig::Persistent
|KConfig::Global
);
128 i
= entGrp
.readEntry("FracDigits", 2);
129 group
.deleteEntry("FracDigits", KConfig::Persistent
| KConfig::Global
);
130 if (i
!= m_locale
->fracDigits())
131 group
.writeEntry("FracDigits", m_locale
->fracDigits(), KConfig::Persistent
|KConfig::Global
);
133 b
= entGrp
.readEntry("PositivePrefixCurrencySymbol", true);
134 group
.deleteEntry("PositivePrefixCurrencySymbol", KConfig::Persistent
| KConfig::Global
);
135 if (b
!= m_locale
->positivePrefixCurrencySymbol())
136 group
.writeEntry("PositivePrefixCurrencySymbol",
137 m_locale
->positivePrefixCurrencySymbol(), KConfig::Persistent
|KConfig::Global
);
139 b
= entGrp
.readEntry("NegativePrefixCurrencySymbol", true);
140 group
.deleteEntry("NegativePrefixCurrencySymbol", KConfig::Persistent
| KConfig::Global
);
141 if (b
!= m_locale
->negativePrefixCurrencySymbol())
142 group
.writeEntry("NegativePrefixCurrencySymbol",
143 m_locale
->negativePrefixCurrencySymbol(), KConfig::Persistent
|KConfig::Global
);
145 i
= entGrp
.readEntry("PositiveMonetarySignPosition",
146 (int)KLocale::BeforeQuantityMoney
);
147 group
.deleteEntry("PositiveMonetarySignPosition", KConfig::Persistent
| KConfig::Global
);
148 if (i
!= m_locale
->positiveMonetarySignPosition())
149 group
.writeEntry("PositiveMonetarySignPosition",
150 (int)m_locale
->positiveMonetarySignPosition(),
151 KConfig::Persistent
|KConfig::Global
);
153 i
= entGrp
.readEntry("NegativeMonetarySignPosition",
154 (int)KLocale::ParensAround
);
155 group
.deleteEntry("NegativeMonetarySignPosition", KConfig::Persistent
| KConfig::Global
);
156 if (i
!= m_locale
->negativeMonetarySignPosition())
157 group
.writeEntry("NegativeMonetarySignPosition",
158 (int)m_locale
->negativeMonetarySignPosition(),
159 KConfig::Persistent
|KConfig::Global
);
164 void KLocaleConfigMoney::slotLocaleChanged()
166 m_edMonCurSym
->setText( m_locale
->currencySymbol() );
167 m_edMonDecSym
->setText( m_locale
->monetaryDecimalSymbol() );
168 m_edMonThoSep
->setText( m_locale
->monetaryThousandsSeparator() );
169 m_inMonFraDig
->setValue( m_locale
->fracDigits() );
171 m_chMonPosPreCurSym
->setChecked( m_locale
->positivePrefixCurrencySymbol() );
172 m_chMonNegPreCurSym
->setChecked( m_locale
->negativePrefixCurrencySymbol() );
173 m_cmbMonPosMonSignPos
->setCurrentIndex( m_locale
->positiveMonetarySignPosition() );
174 m_cmbMonNegMonSignPos
->setCurrentIndex( m_locale
->negativeMonetarySignPosition() );
177 void KLocaleConfigMoney::slotMonCurSymChanged(const QString
&t
)
179 m_locale
->setCurrencySymbol(t
);
180 emit
localeChanged();
183 void KLocaleConfigMoney::slotMonDecSymChanged(const QString
&t
)
185 m_locale
->setMonetaryDecimalSymbol(t
);
186 emit
localeChanged();
189 void KLocaleConfigMoney::slotMonThoSepChanged(const QString
&t
)
191 m_locale
->setMonetaryThousandsSeparator(t
);
192 emit
localeChanged();
195 void KLocaleConfigMoney::slotMonFraDigChanged(int value
)
197 m_locale
->setFracDigits(value
);
198 emit
localeChanged();
201 void KLocaleConfigMoney::slotMonPosPreCurSymChanged()
203 m_locale
->setPositivePrefixCurrencySymbol(m_chMonPosPreCurSym
->isChecked());
204 emit
localeChanged();
207 void KLocaleConfigMoney::slotMonNegPreCurSymChanged()
209 m_locale
->setNegativePrefixCurrencySymbol(m_chMonNegPreCurSym
->isChecked());
210 emit
localeChanged();
213 void KLocaleConfigMoney::slotMonPosMonSignPosChanged(int i
)
215 m_locale
->setPositiveMonetarySignPosition((KLocale::SignPosition
)i
);
216 emit
localeChanged();
219 void KLocaleConfigMoney::slotMonNegMonSignPosChanged(int i
)
221 m_locale
->setNegativeMonetarySignPosition((KLocale::SignPosition
)i
);
222 emit
localeChanged();
225 void KLocaleConfigMoney::slotTranslate()
227 QList
<QComboBox
*> list
;
228 list
.append(m_cmbMonPosMonSignPos
);
229 list
.append(m_cmbMonNegMonSignPos
);
231 foreach (QComboBox
* wc
, list
)
233 wc
->setItemText(0, ki18n("Parentheses Around").toString(m_locale
));
234 wc
->setItemText(1, ki18n("Before Quantity Money").toString(m_locale
));
235 wc
->setItemText(2, ki18n("After Quantity Money").toString(m_locale
));
236 wc
->setItemText(3, ki18n("Before Money").toString(m_locale
));
237 wc
->setItemText(4, ki18n("After Money").toString(m_locale
));
242 str
= ki18n( "Here you can enter your usual currency "
243 "symbol, e.g. $ or €." ).toString( m_locale
);
244 m_labMonCurSym
->setWhatsThis( str
);
245 m_edMonCurSym
->setWhatsThis( str
);
246 str
= ki18n( "<p>Here you can define the decimal separator used "
247 "to display monetary values.</p>"
248 "<p>Note that the decimal separator used to "
249 "display other numbers has to be defined "
250 "separately (see the 'Numbers' tab).</p>" ).toString( m_locale
);
251 m_labMonDecSym
->setWhatsThis( str
);
252 m_edMonDecSym
->setWhatsThis( str
);
254 str
= ki18n( "<p>Here you can define the thousands separator "
255 "used to display monetary values.</p>"
256 "<p>Note that the thousands separator used to "
257 "display other numbers has to be defined "
258 "separately (see the 'Numbers' tab).</p>" ).toString( m_locale
);
259 m_labMonThoSep
->setWhatsThis( str
);
260 m_edMonThoSep
->setWhatsThis( str
);
262 str
= ki18n( "This determines the number of fract digits for "
263 "monetary values, i.e. the number of digits you "
264 "find <em>behind</em> the decimal separator. "
265 "Correct value is 2 for almost all people." ).toString( m_locale
);
266 m_labMonFraDig
->setWhatsThis( str
);
267 m_inMonFraDig
->setWhatsThis( str
);
269 str
= ki18n( "If this option is checked, the currency sign "
270 "will be prefixed (i.e. to the left of the "
271 "value) for all positive monetary values. If "
272 "not, it will be postfixed (i.e. to the right)." ).toString( m_locale
);
273 m_chMonPosPreCurSym
->setWhatsThis( str
);
275 str
= ki18n( "If this option is checked, the currency sign "
276 "will be prefixed (i.e. to the left of the "
277 "value) for all negative monetary values. If "
278 "not, it will be postfixed (i.e. to the right)." ).toString( m_locale
);
279 m_chMonNegPreCurSym
->setWhatsThis( str
);
281 str
= ki18n( "Here you can select how a positive sign will be "
282 "positioned. This only affects monetary values." ).toString( m_locale
);
283 m_labMonPosMonSignPos
->setWhatsThis( str
);
284 m_cmbMonPosMonSignPos
->setWhatsThis( str
);
286 str
= ki18n( "Here you can select how a negative sign will "
287 "be positioned. This only affects monetary "
288 "values." ).toString( m_locale
);
289 m_labMonNegMonSignPos
->setWhatsThis( str
);
290 m_cmbMonNegMonSignPos
->setWhatsThis( str
);