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.
31 #include <KConfigGroup>
32 #include <KStandardDirs>
35 #include "localenum.h"
36 #include "localenum.moc"
38 KLocaleConfigNumber::KLocaleConfigNumber(KLocale
*locale
,
43 QGridLayout
*lay
= new QGridLayout(this );
44 lay
->setMargin( KDialog::marginHint() );
45 lay
->setSpacing( KDialog::spacingHint());
47 m_labDecSym
= new QLabel(this);
48 lay
->addWidget(m_labDecSym
, 0, 0);
49 m_labDecSym
->setObjectName( I18N_NOOP("&Decimal symbol:") );
50 m_labDecSym
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
51 m_edDecSym
= new QLineEdit(this);
52 lay
->addWidget(m_edDecSym
, 0, 1);
53 connect( m_edDecSym
, SIGNAL( textChanged(const QString
&) ),
54 this, SLOT( slotDecSymChanged(const QString
&) ) );
55 m_labDecSym
->setBuddy(m_edDecSym
);
57 m_labThoSep
= new QLabel(this);
58 lay
->addWidget(m_labThoSep
, 1, 0);
59 m_labThoSep
->setObjectName( I18N_NOOP("Tho&usands separator:") );
60 m_labThoSep
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
61 m_edThoSep
= new QLineEdit(this);
62 lay
->addWidget(m_edThoSep
, 1, 1);
63 connect( m_edThoSep
, SIGNAL( textChanged(const QString
&) ),
64 this, SLOT( slotThoSepChanged(const QString
&) ) );
65 m_labThoSep
->setBuddy(m_edThoSep
);
67 m_labMonPosSign
= new QLabel(this);
68 lay
->addWidget(m_labMonPosSign
, 2, 0);
69 m_labMonPosSign
->setObjectName( I18N_NOOP("Positive si&gn:") );
70 m_labMonPosSign
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
71 m_edMonPosSign
= new QLineEdit(this);
72 lay
->addWidget(m_edMonPosSign
, 2, 1);
73 connect( m_edMonPosSign
, SIGNAL( textChanged(const QString
&) ),
74 this, SLOT( slotMonPosSignChanged(const QString
&) ) );
75 m_labMonPosSign
->setBuddy(m_edMonPosSign
);
77 m_labMonNegSign
= new QLabel(this);
78 lay
->addWidget(m_labMonNegSign
, 3, 0);
79 m_labMonNegSign
->setObjectName( I18N_NOOP("&Negative sign:") );
80 m_labMonNegSign
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
81 m_edMonNegSign
= new QLineEdit(this);
82 lay
->addWidget(m_edMonNegSign
, 3, 1);
83 connect( m_edMonNegSign
, SIGNAL( textChanged(const QString
&) ),
84 this, SLOT( slotMonNegSignChanged(const QString
&) ) );
85 m_labMonNegSign
->setBuddy(m_edMonNegSign
);
87 lay
->setColumnStretch(1, 1);
88 lay
->setRowStretch(4, 1);
90 connect(this, SIGNAL(localeChanged()),
91 SLOT(slotLocaleChanged()));
94 KLocaleConfigNumber::~KLocaleConfigNumber()
98 void KLocaleConfigNumber::save()
100 KSharedConfig::Ptr config
= KGlobal::config();
101 KConfigGroup
group(config
, "Locale");
102 KConfig
ent(KStandardDirs::locate("locale",
103 QString::fromLatin1("l10n/%1/entry.desktop")
104 .arg(m_locale
->country())));
105 ent
.setLocale(m_locale
->language());
106 KConfigGroup entGrp
= ent
.group("KCM Locale");
110 str
= entGrp
.readEntry("DecimalSymbol",
111 QString::fromLatin1("."));
112 group
.deleteEntry("DecimalSymbol", KConfig::Persistent
| KConfig::Global
);
113 if (str
!= m_locale
->decimalSymbol())
114 group
.writeEntry("DecimalSymbol",
115 m_locale
->decimalSymbol(), KConfig::Persistent
|KConfig::Global
);
117 str
= entGrp
.readEntry("ThousandsSeparator",
118 QString::fromLatin1(","));
119 group
.deleteEntry("ThousandsSeparator", KConfig::Persistent
| KConfig::Global
);
120 str
.replace(QString::fromLatin1("$0"), QString());
121 if (str
!= m_locale
->thousandsSeparator())
122 group
.writeEntry("ThousandsSeparator",
123 QString::fromLatin1("$0%1$0")
124 .arg(m_locale
->thousandsSeparator()), KConfig::Persistent
|KConfig::Global
);
126 str
= entGrp
.readEntry("PositiveSign");
127 group
.deleteEntry("PositiveSign", KConfig::Persistent
| KConfig::Global
);
128 if (str
!= m_locale
->positiveSign())
129 group
.writeEntry("PositiveSign", m_locale
->positiveSign(), KConfig::Persistent
|KConfig::Global
);
131 str
= entGrp
.readEntry("NegativeSign", QString::fromLatin1("-"));
132 group
.deleteEntry("NegativeSign", KConfig::Persistent
| KConfig::Global
);
133 if (str
!= m_locale
->negativeSign())
134 group
.writeEntry("NegativeSign", m_locale
->negativeSign(), KConfig::Persistent
|KConfig::Global
);
137 void KLocaleConfigNumber::slotLocaleChanged()
139 // #### load all settings here
140 m_edDecSym
->setText( m_locale
->decimalSymbol() );
141 m_edThoSep
->setText( m_locale
->thousandsSeparator() );
142 m_edMonPosSign
->setText( m_locale
->positiveSign() );
143 m_edMonNegSign
->setText( m_locale
->negativeSign() );
146 void KLocaleConfigNumber::slotDecSymChanged(const QString
&t
)
148 m_locale
->setDecimalSymbol(t
);
149 emit
localeChanged();
152 void KLocaleConfigNumber::slotThoSepChanged(const QString
&t
)
154 m_locale
->setThousandsSeparator(t
);
155 emit
localeChanged();
158 void KLocaleConfigNumber::slotMonPosSignChanged(const QString
&t
)
160 m_locale
->setPositiveSign(t
);
161 emit
localeChanged();
164 void KLocaleConfigNumber::slotMonNegSignChanged(const QString
&t
)
166 m_locale
->setNegativeSign(t
);
167 emit
localeChanged();
170 void KLocaleConfigNumber::slotTranslate()
174 str
= ki18n( "<p>Here you can define the decimal separator used "
175 "to display numbers (i.e. a dot or a comma in "
176 "most countries).</p><p>"
177 "Note that the decimal separator used to "
178 "display monetary values has to be set "
179 "separately (see the 'Money' tab).</p>" ).toString( m_locale
);
180 m_labDecSym
->setWhatsThis( str
);
181 m_edDecSym
->setWhatsThis( str
);
183 str
= ki18n( "<p>Here you can define the thousands separator "
184 "used to display numbers.</p><p>"
185 "Note that the thousands separator used to "
186 "display monetary values has to be set "
187 "separately (see the 'Money' tab).</p>" ).toString( m_locale
);
188 m_labThoSep
->setWhatsThis( str
);
189 m_edThoSep
->setWhatsThis( str
);
191 str
= ki18n( "Here you can specify text used to prefix "
192 "positive numbers. Most people leave this "
193 "blank." ).toString( m_locale
);
194 m_labMonPosSign
->setWhatsThis( str
);
195 m_edMonPosSign
->setWhatsThis( str
);
197 str
= ki18n( "Here you can specify text used to prefix "
198 "negative numbers. This should not be empty, so "
199 "you can distinguish positive and negative "
200 "numbers. It is normally set to minus (-)." ).toString( m_locale
);
201 m_labMonNegSign
->setWhatsThis( str
);
202 m_edMonNegSign
->setWhatsThis( str
);