1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/*
* localenum.cpp
*
* Copyright (c) 1999-2003 Hans Petter Bieker <[email protected]>
*
* Requires the Qt widget libraries, available at no cost at
* http://www.troll.no/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <qlabel.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qwhatsthis.h>
#include <qregexp.h>
#include <kdialog.h>
#include <ksimpleconfig.h>
#include <kstandarddirs.h>
#include "toplevel.h"
#include "localenum.h"
#include "localenum.moc"
KLocaleConfigNumber::KLocaleConfigNumber(KLocale *locale,
QWidget *parent, const char*name)
: QWidget(parent, name),
m_locale(locale)
{
QGridLayout *lay = new QGridLayout(this, 5, 2,
KDialog::marginHint(),
KDialog::spacingHint());
lay->setAutoAdd(TRUE);
m_labDecSym = new QLabel(this, I18N_NOOP("&Decimal symbol:"));
m_edDecSym = new QLineEdit(this);
connect( m_edDecSym, SIGNAL( textChanged(const QString &) ),
this, SLOT( slotDecSymChanged(const QString &) ) );
m_labDecSym->setBuddy(m_edDecSym);
m_labThoSep = new QLabel(this, I18N_NOOP("Tho&usands separator:"));
m_edThoSep = new QLineEdit(this);
connect( m_edThoSep, SIGNAL( textChanged(const QString &) ),
this, SLOT( slotThoSepChanged(const QString &) ) );
m_labThoSep->setBuddy(m_edThoSep);
m_labMonPosSign = new QLabel(this, I18N_NOOP("Positive si&gn:"));
m_edMonPosSign = new QLineEdit(this);
connect( m_edMonPosSign, SIGNAL( textChanged(const QString &) ),
this, SLOT( slotMonPosSignChanged(const QString &) ) );
m_labMonPosSign->setBuddy(m_edMonPosSign);
m_labMonNegSign = new QLabel(this, I18N_NOOP("&Negative sign:"));
m_edMonNegSign = new QLineEdit(this);
connect( m_edMonNegSign, SIGNAL( textChanged(const QString &) ),
this, SLOT( slotMonNegSignChanged(const QString &) ) );
m_labMonNegSign->setBuddy(m_edMonNegSign);
lay->setColStretch(1, 1);
connect(this, SIGNAL(localeChanged()),
SLOT(slotLocaleChanged()));
}
KLocaleConfigNumber::~KLocaleConfigNumber()
{
}
void KLocaleConfigNumber::save()
{
// temperary use of our locale as the global locale
KLocale *lsave = KGlobal::_locale;
KGlobal::_locale = m_locale;
KConfig *config = KGlobal::config();
KConfigGroupSaver saver(config, "Locale");
KSimpleConfig ent(locate("locale",
QString::fromLatin1("l10n/%1/entry.desktop")
.arg(m_locale->country())), true);
ent.setGroup("KCM Locale");
QString str;
str = ent.readEntry("DecimalSymbol",
QString::fromLatin1("."));
config->deleteEntry("DecimalSymbol", false, true);
if (str != m_locale->decimalSymbol())
config->writeEntry("DecimalSymbol",
m_locale->decimalSymbol(), true, true);
str = ent.readEntry("ThousandsSeparator",
QString::fromLatin1(","));
config->deleteEntry("ThousandsSeparator", false, true);
str.replace(QString::fromLatin1("$0"), QString::null);
if (str != m_locale->thousandsSeparator())
config->writeEntry("ThousandsSeparator",
QString::fromLatin1("$0%1$0")
.arg(m_locale->thousandsSeparator()), true, true);
str = ent.readEntry("PositiveSign");
config->deleteEntry("PositiveSign", false, true);
if (str != m_locale->positiveSign())
config->writeEntry("PositiveSign", m_locale->positiveSign(), true, true);
str = ent.readEntry("NegativeSign", QString::fromLatin1("-"));
config->deleteEntry("NegativeSign", false, true);
if (str != m_locale->negativeSign())
config->writeEntry("NegativeSign", m_locale->negativeSign(), true, true);
// restore the old global locale
KGlobal::_locale = lsave;
}
void KLocaleConfigNumber::slotLocaleChanged()
{
// #### load all settings here
m_edDecSym->setText( m_locale->decimalSymbol() );
m_edThoSep->setText( m_locale->thousandsSeparator() );
m_edMonPosSign->setText( m_locale->positiveSign() );
m_edMonNegSign->setText( m_locale->negativeSign() );
}
void KLocaleConfigNumber::slotDecSymChanged(const QString &t)
{
m_locale->setDecimalSymbol(t);
emit localeChanged();
}
void KLocaleConfigNumber::slotThoSepChanged(const QString &t)
{
m_locale->setThousandsSeparator(t);
emit localeChanged();
}
void KLocaleConfigNumber::slotMonPosSignChanged(const QString &t)
{
m_locale->setPositiveSign(t);
emit localeChanged();
}
void KLocaleConfigNumber::slotMonNegSignChanged(const QString &t)
{
m_locale->setNegativeSign(t);
emit localeChanged();
}
void KLocaleConfigNumber::slotTranslate()
{
QString str;
str = m_locale->translate( "Here you can define the decimal separator used "
"to display numbers (i.e. a dot or a comma in "
"most countries).<p>"
"Note that the decimal separator used to "
"display monetary values has to be set "
"separately (see the 'Money' tab)." );
QWhatsThis::add( m_labDecSym, str );
QWhatsThis::add( m_edDecSym, str );
str = m_locale->translate( "Here you can define the thousands separator "
"used to display numbers.<p>"
"Note that the thousands separator used to "
"display monetary values has to be set "
"separately (see the 'Money' tab)." );
QWhatsThis::add( m_labThoSep, str );
QWhatsThis::add( m_edThoSep, str );
str = m_locale->translate( "Here you can specify text used to prefix "
"positive numbers. Most people leave this "
"blank." );
QWhatsThis::add( m_labMonPosSign, str );
QWhatsThis::add( m_edMonPosSign, str );
str = m_locale->translate( "Here you can specify text used to prefix "
"negative numbers. This should not be empty, so "
"you can distinguish positive and negative "
"numbers. It is normally set to minus (-)." );
QWhatsThis::add( m_labMonNegSign, str );
QWhatsThis::add( m_edMonNegSign, str );
}
|