add more spacing
[personal-kdebase.git] / runtime / kcontrol / locale / toplevel.cpp
blobf57b18b50ec480e240e978890fd8a8bce8e80bc5
1 /*
2 toplevel.cpp - A KControl Application
4 Copyright 1998 Matthias Hoelzer
5 Copyright 1999-2003 Hans Petter Bieker <bieker@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <QCheckBox>
24 #include <QGroupBox>
25 #include <QLabel>
26 #include <QLayout>
27 #include <QPushButton>
28 #include <QTabWidget>
30 #include <kaboutdata.h>
31 #include <kbuildsycocaprogressdialog.h>
32 #include <ksharedconfig.h>
33 #include <kdebug.h>
34 #include <kdialog.h>
35 #include <kmessagebox.h>
36 #include <kservice.h>
38 #include "localenum.h"
39 #include "localemon.h"
40 #include "localetime.h"
41 #include "localeother.h"
42 #include "klocalesample.h"
43 #include "toplevel.h"
44 #include "kcmlocale.h"
45 #include "toplevel.moc"
46 #include <kconfiggroup.h>
47 #include <kpluginfactory.h>
48 #include <kpluginloader.h>
49 #include "kcontrollocale.h"
51 K_PLUGIN_FACTORY(KLocaleFactory,
52 KLocale::setMainCatalog("kcmlocale");
53 registerPlugin<KLocaleApplication>();
55 K_EXPORT_PLUGIN(KLocaleFactory("kcmlocale"))
57 KLocaleApplication::KLocaleApplication(QWidget *parent,
58 const QVariantList &args)
59 : KCModule( KLocaleFactory::componentData(), parent, args)
61 KAboutData* aboutData = new KAboutData("kcmlocale", 0,
62 ki18n("KCMLocale"),
63 "3.0",
64 ki18n("Regional settings"),
65 KAboutData::License_GPL,
66 ki18n("(C) 1998 Matthias Hoelzer, "
67 "(C) 1999-2003 Hans Petter Bieker"),
68 KLocalizedString(), 0, "bieker@kde.org");
69 setAboutData( aboutData );
71 m_nullConfig = KSharedConfig::openConfig(QString(), KConfig::NoGlobals );
72 m_globalConfig = KSharedConfig::openConfig(QString(), KConfig::IncludeGlobals );
74 m_locale = new KControlLocale(QLatin1String("kcmlocale"), m_nullConfig);
76 QVBoxLayout *l = new QVBoxLayout(this);
77 l->setMargin(0);
78 l->setSpacing(KDialog::spacingHint());
80 m_tab = new QTabWidget(this);
81 l->addWidget(m_tab);
83 m_localemain = new KLocaleConfig(m_locale, this);
85 m_tab->addTab( m_localemain, QString());
86 m_localenum = new KLocaleConfigNumber(m_locale, this);
87 m_tab->addTab( m_localenum, QString() );
88 m_localemon = new KLocaleConfigMoney(m_locale, this);
89 m_tab->addTab( m_localemon, QString() );
90 m_localetime = new KLocaleConfigTime(m_locale, this);
91 m_tab->addTab( m_localetime, QString() );
92 m_localeother = new KLocaleConfigOther(m_locale, this);
93 m_tab->addTab( m_localeother, QString() );
95 // Examples
96 m_gbox = new QGroupBox(this);
97 l->addWidget(m_gbox);
98 QVBoxLayout *laygroup = new QVBoxLayout(m_gbox);
99 laygroup->setSpacing(KDialog::spacingHint());
100 m_sample = new KLocaleSample(m_locale, m_gbox);
101 laygroup->addWidget( m_sample );
103 // getting signals from children
104 connect(m_localemain, SIGNAL(localeChanged()),
105 this, SIGNAL(localeChanged()));
106 connect(m_localemain, SIGNAL(languageChanged()),
107 this, SIGNAL(languageChanged()));
109 // run the slots on the children
110 connect(this, SIGNAL(localeChanged()),
111 m_localemain, SLOT(slotLocaleChanged()));
112 connect(this, SIGNAL(localeChanged()),
113 m_localenum, SLOT(slotLocaleChanged()));
114 connect(this, SIGNAL(localeChanged()),
115 m_localemon, SLOT(slotLocaleChanged()));
116 connect(this, SIGNAL(localeChanged()),
117 m_localetime, SLOT(slotLocaleChanged()));
118 connect(this, SIGNAL(localeChanged()),
119 m_localeother, SLOT(slotLocaleChanged()));
121 // keep the example up to date
122 // NOTE: this will make the sample be updated 6 times the first time
123 // because combo boxes++ emits the change signal not only when the user changes
124 // it, but also when it's changed by the program.
125 connect(m_localenum, SIGNAL(localeChanged()),
126 m_sample, SLOT(slotLocaleChanged()));
127 connect(m_localemon, SIGNAL(localeChanged()),
128 m_sample, SLOT(slotLocaleChanged()));
129 connect(m_localetime, SIGNAL(localeChanged()),
130 m_sample, SLOT(slotLocaleChanged()));
131 // No examples for this yet
132 //connect(m_localeother, SIGNAL(slotLocaleChanged()),
133 //m_sample, SLOT(slotLocaleChanged()));
134 connect(this, SIGNAL(localeChanged()),
135 m_sample, SLOT(slotLocaleChanged()));
137 // make sure we always have translated interface
138 connect(this, SIGNAL(languageChanged()),
139 this, SLOT(slotTranslate()));
140 connect(this, SIGNAL(languageChanged()),
141 m_localemain, SLOT(slotTranslate()));
142 connect(this, SIGNAL(languageChanged()),
143 m_localenum, SLOT(slotTranslate()));
144 connect(this, SIGNAL(languageChanged()),
145 m_localemon, SLOT(slotTranslate()));
146 connect(this, SIGNAL(languageChanged()),
147 m_localetime, SLOT(slotTranslate()));
148 connect(this, SIGNAL(languageChanged()),
149 m_localeother, SLOT(slotTranslate()));
151 // mark it as changed when we change it.
152 connect(m_localemain, SIGNAL(localeChanged()),
153 SLOT(slotChanged()));
154 connect(m_localenum, SIGNAL(localeChanged()),
155 SLOT(slotChanged()));
156 connect(m_localemon, SIGNAL(localeChanged()),
157 SLOT(slotChanged()));
158 connect(m_localetime, SIGNAL(localeChanged()),
159 SLOT(slotChanged()));
160 connect(m_localeother, SIGNAL(localeChanged()),
161 SLOT(slotChanged()));
165 KLocaleApplication::~KLocaleApplication()
167 delete m_locale;
170 void KLocaleApplication::load()
172 m_globalConfig->reparseConfiguration();
173 *m_locale = KControlLocale(QLatin1String("kcmlocale"), m_globalConfig);
175 emit localeChanged();
176 emit languageChanged();
177 emit changed(false);
180 void KLocaleApplication::save()
182 KMessageBox::information(this, ki18n
183 ("Changed language settings apply only to "
184 "newly started applications.\nTo change the "
185 "language of all programs, you will have to "
186 "logout first.").toString(m_locale),
187 ki18n("Applying Language Settings").toString(m_locale),
188 QLatin1String("LanguageChangesApplyOnlyToNewlyStartedPrograms"));
190 KSharedConfig::Ptr config = KGlobal::config();
191 KConfigGroup group(config, "Locale");
193 // ##### this doesn't make sense
194 bool langChanged = group.readEntry("Language")
195 != m_locale->language();
197 m_localemain->save();
198 m_localenum->save();
199 m_localemon->save();
200 m_localetime->save();
201 m_localeother->save();
203 // rebuild the date base if language was changed
204 if (langChanged)
206 KBuildSycocaProgressDialog::rebuildKSycoca(this);
209 emit changed(false);
212 void KLocaleApplication::defaults()
214 *m_locale = KControlLocale(QLatin1String("kcmlocale"), m_nullConfig);
216 kDebug() << "defaults: " << m_locale->languageList();
218 emit localeChanged();
219 emit languageChanged();
222 QString KLocaleApplication::quickHelp() const
224 return ki18n("<h1>Country/Region & Language</h1>\n"
225 "<p>From here you can configure language, numeric, and time \n"
226 "settings for your particular region. In most cases it will be \n"
227 "sufficient to choose the country you live in. For instance KDE \n"
228 "will automatically choose \"German\" as language if you choose \n"
229 "\"Germany\" from the list. It will also change the time format \n"
230 "to use 24 hours and and use comma as decimal separator.</p>\n").toString(m_locale);
233 void KLocaleApplication::slotTranslate()
235 // The untranslated string for QLabel are stored in
236 // the name() so we use that when retranslating
237 const QList<QWidget*> &list = findChildren<QWidget*>();
238 foreach ( QObject* wc, list )
240 // unnamed labels will cause errors and should not be
241 // retranslated. E.g. the example box should not be
242 // retranslated from here.
243 if (wc->objectName().isEmpty())
244 continue;
245 if (wc->objectName() == "unnamed")
246 continue;
248 if (::qstrcmp(wc->metaObject()->className(), "QLabel") == 0)
249 ((QLabel *)wc)->setText( ki18n( wc->objectName().toLatin1() ).toString( m_locale ) );
250 else if (::qstrcmp(wc->metaObject()->className(), "QGroupBox") == 0 ||
251 ::qstrcmp(wc->metaObject()->className(), "QVGroupBox") == 0)
252 ((QGroupBox *)wc)->setTitle( ki18n( wc->objectName().toLatin1() ).toString( m_locale ) );
253 else if (::qstrcmp(wc->metaObject()->className(), "QPushButton") == 0 ||
254 ::qstrcmp(wc->metaObject()->className(), "KMenuButton") == 0)
255 ((QPushButton *)wc)->setText( ki18n( wc->objectName().toLatin1() ).toString( m_locale ) );
256 else if (::qstrcmp(wc->metaObject()->className(), "QCheckBox") == 0)
257 ((QCheckBox *)wc)->setText( ki18n( wc->objectName().toLatin1() ).toString( m_locale ) );
260 // Here we have the pointer
261 m_gbox->setWindowTitle(ki18n("Examples").toString(m_locale));
262 m_tab->setTabText(m_tab->indexOf(m_localemain), ki18n("&Locale").toString(m_locale));
263 m_tab->setTabText(m_tab->indexOf(m_localenum), ki18n("&Numbers").toString(m_locale));
264 m_tab->setTabText(m_tab->indexOf(m_localemon), ki18n("&Money").toString(m_locale));
265 m_tab->setTabText(m_tab->indexOf(m_localetime), ki18n("&Time && Dates").toString(m_locale));
266 m_tab->setTabText(m_tab->indexOf(m_localeother), ki18n("&Other").toString(m_locale));
267 // FIXME: All widgets are done now. However, there are
268 // still some problems. Popup menus from the QLabels are
269 // not retranslated.
272 void KLocaleApplication::slotChanged()
274 emit changed(true);