summaryrefslogtreecommitdiffstats
path: root/kcontrol/locale/toplevel.cpp
blob: e74330c30fcc6031e3dd7309458060ce0697966c (plain)
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
  toplevel.cpp - A KControl Application

  Copyright 1998 Matthias Hoelzer
  Copyright 1999-2003 Hans Petter Bieker <bieker@kde.org>

  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 <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqobjectlist.h>
#include <tqpushbutton.h>
#include <tqtabwidget.h>
#include <tqvgroupbox.h>

#include <tdeaboutdata.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <kservice.h>

#include "localenum.h"
#include "localemon.h"
#include "localetime.h"
#include "localeother.h"
#include "klocalesample.h"
#include "toplevel.h"
#include "kcmlocale.h"
#include "toplevel.moc"

TDELocaleApplication::TDELocaleApplication(TQWidget *parent, const char* /*name*/, 
                                       const TQStringList &args)
  : TDECModule( TDELocaleFactory::instance(), parent, args)
{
  TDEAboutData* aboutData = new TDEAboutData("kcmlocale",
        I18N_NOOP("KCMLocale"),
        "3.0",
        I18N_NOOP("Regional settings"),
        TDEAboutData::License_GPL,
        "(C) 1998 Matthias Hoelzer, "
        "(C) 1999-2003 Hans Petter Bieker",
        0, 0, "bieker@kde.org");
  setAboutData( aboutData );

  m_nullConfig = new TDEConfig(TQString::null, false, false);
  m_globalConfig = new TDEConfig(TQString::null, false, true);

  m_locale = new TDELocale(TQString::fromLatin1("kcmlocale"), m_nullConfig);
  TQVBoxLayout *l = new TQVBoxLayout(this, 0, KDialog::spacingHint());
  l->setAutoAdd(TRUE);

  m_tab = new TQTabWidget(this);

  m_localemain = new TDELocaleConfig(m_locale, this);
  m_tab->addTab( m_localemain, TQString::null);
  m_localenum = new TDELocaleConfigNumber(m_locale, this);
  m_tab->addTab( m_localenum, TQString::null );
  m_localemon = new TDELocaleConfigMoney(m_locale, this);
  m_tab->addTab( m_localemon, TQString::null );
  m_localetime = new TDELocaleConfigTime(m_locale, this);
  m_tab->addTab( m_localetime, TQString::null );
  m_localeother = new TDELocaleConfigOther(m_locale, this);
  m_tab->addTab( m_localeother, TQString::null );

  // Examples
  m_gbox = new TQVGroupBox(this);
  m_sample = new TDELocaleSample(m_locale, m_gbox);

  // getting signals from childs
  connect(m_localemain, TQT_SIGNAL(localeChanged()),
          this, TQT_SIGNAL(localeChanged()));
  connect(m_localemain, TQT_SIGNAL(languageChanged()),
          this, TQT_SIGNAL(languageChanged()));

  // run the slots on the childs
  connect(this, TQT_SIGNAL(localeChanged()),
          m_localemain, TQT_SLOT(slotLocaleChanged()));
  connect(this, TQT_SIGNAL(localeChanged()),
          m_localenum, TQT_SLOT(slotLocaleChanged()));
  connect(this, TQT_SIGNAL(localeChanged()),
          m_localemon, TQT_SLOT(slotLocaleChanged()));
  connect(this, TQT_SIGNAL(localeChanged()),
          m_localetime, TQT_SLOT(slotLocaleChanged()));
  connect(this, TQT_SIGNAL(localeChanged()),
          m_localeother, TQT_SLOT(slotLocaleChanged()));

  // keep the example up to date
  // NOTE: this will make the sample be updated 6 times the first time
  // because combo boxes++ emits the change signal not only when the user changes
  // it, but also when it's changed by the program.
  connect(m_localenum, TQT_SIGNAL(localeChanged()),
          m_sample, TQT_SLOT(slotLocaleChanged()));
  connect(m_localemon, TQT_SIGNAL(localeChanged()),
          m_sample, TQT_SLOT(slotLocaleChanged()));
  connect(m_localetime, TQT_SIGNAL(localeChanged()),
          m_sample, TQT_SLOT(slotLocaleChanged()));
  // No examples for this yet
  //connect(m_localeother, TQT_SIGNAL(slotLocaleChanged()),
  //m_sample, TQT_SLOT(slotLocaleChanged()));
  connect(this, TQT_SIGNAL(localeChanged()),
          m_sample, TQT_SLOT(slotLocaleChanged()));

  // make sure we always have translated interface
  connect(this, TQT_SIGNAL(languageChanged()),
          this, TQT_SLOT(slotTranslate()));
  connect(this, TQT_SIGNAL(languageChanged()),
          m_localemain, TQT_SLOT(slotTranslate()));
  connect(this, TQT_SIGNAL(languageChanged()),
          m_localenum, TQT_SLOT(slotTranslate()));
  connect(this, TQT_SIGNAL(languageChanged()),
          m_localemon, TQT_SLOT(slotTranslate()));
  connect(this, TQT_SIGNAL(languageChanged()),
          m_localetime, TQT_SLOT(slotTranslate()));
  connect(this, TQT_SIGNAL(languageChanged()),
          m_localeother, TQT_SLOT(slotTranslate()));

  // mark it as changed when we change it.
  connect(m_localemain, TQT_SIGNAL(localeChanged()),
          TQT_SLOT(slotChanged()));
  connect(m_localenum, TQT_SIGNAL(localeChanged()),
          TQT_SLOT(slotChanged()));
  connect(m_localemon, TQT_SIGNAL(localeChanged()),
          TQT_SLOT(slotChanged()));
  connect(m_localetime, TQT_SIGNAL(localeChanged()),
          TQT_SLOT(slotChanged()));
  connect(m_localeother, TQT_SIGNAL(localeChanged()),
          TQT_SLOT(slotChanged()));

  load();
}

TDELocaleApplication::~TDELocaleApplication()
{
  delete m_locale;
  delete m_globalConfig;
  delete m_nullConfig;
}

void TDELocaleApplication::load()
{
	load( false );
}

void TDELocaleApplication::load( bool useDefaults )
{
	m_globalConfig->setReadDefaults( useDefaults );
	m_globalConfig->reparseConfiguration();
	*m_locale = TDELocale(TQString::fromLatin1("kcmlocale"), m_globalConfig);
	
	emit localeChanged();
	emit languageChanged();
	emit changed(useDefaults);
}

void TDELocaleApplication::save()
{
  // temperary use of our locale as the global locale
  TDELocale *lsave = TDEGlobal::_locale;
  TDEGlobal::_locale = m_locale;
  KMessageBox::information(this, m_locale->translate
                           ("Changed language settings apply only to "
                            "newly started applications.\nTo change the "
                            "language of all programs, you will have to "
                            "logout first."),
                           m_locale->translate("Applying Language Settings"),
                           TQString::fromLatin1("LanguageChangesApplyOnlyToNewlyStartedPrograms"));
  // restore the old global locale
  TDEGlobal::_locale = lsave;

  TDEConfig *config = TDEGlobal::config();
  TDEConfigGroupSaver saver(config, "Locale");

  // ##### this doesn't make sense
  bool langChanged = config->readEntry("Language")
    != m_locale->language();

  m_localemain->save();
  m_localenum->save();
  m_localemon->save();
  m_localetime->save();
  m_localeother->save();

  // rebuild the date base if language was changed
  if (langChanged)
  {
    KService::rebuildKSycoca(this);
  }

  emit changed(false);
}

void TDELocaleApplication::defaults()
{
	load( true );
}

TQString TDELocaleApplication::quickHelp() const
{
  return m_locale->translate("<h1>Country/Region & Language</h1>\n"
          "<p>From here you can configure language, numeric, and time \n"
          "settings for your particular region. In most cases it will be \n"
          "sufficient to choose the country you live in. For instance TDE \n"
          "will automatically choose \"German\" as language if you choose \n"
          "\"Germany\" from the list. It will also change the time format \n"
          "to use 24 hours and and use comma as decimal separator.</p>\n");
}

void TDELocaleApplication::slotTranslate()
{
  // The untranslated string for TQLabel are stored in
  // the name() so we use that when retranslating
  TQObject *wc;
  TQObjectList *list = queryList(TQWIDGET_OBJECT_NAME_STRING);
  TQObjectListIt it(*list);
  while ( (wc = it.current()) != 0 )
  {
    ++it;

    // unnamed labels will cause errors and should not be
    // retranslated. E.g. the example box should not be
    // retranslated from here.
    if (wc->name() == 0)
      continue;
    if (::qstrcmp(wc->name(), "") == 0)
      continue;
    if (::qstrcmp(wc->name(), "unnamed") == 0)
      continue;

    if (::qstrcmp(wc->className(), TQLABEL_OBJECT_NAME_STRING) == 0)
      ((TQLabel *)wc)->setText( m_locale->translate( wc->name() ) );
    else if (::qstrcmp(wc->className(), TQGROUPBOX_OBJECT_NAME_STRING) == 0 ||
             ::qstrcmp(wc->className(), TQVGROUPBOX_OBJECT_NAME_STRING) == 0)
      ((TQGroupBox *)wc)->setTitle( m_locale->translate( wc->name() ) );
    else if (::qstrcmp(wc->className(), TQPUSHBUTTON_OBJECT_NAME_STRING) == 0 ||
             ::qstrcmp(wc->className(), "KMenuButton") == 0)
      ((TQPushButton *)wc)->setText( m_locale->translate( wc->name() ) );
    else if (::qstrcmp(wc->className(), TQCHECKBOX_OBJECT_NAME_STRING) == 0)
      ((TQCheckBox *)wc)->setText( m_locale->translate( wc->name() ) );
  }
  delete list;

  // Here we have the pointer
  m_gbox->setCaption(m_locale->translate("Examples"));
  m_tab->changeTab(m_localemain, m_locale->translate("&Locale"));
  m_tab->changeTab(m_localenum, m_locale->translate("&Numbers"));
  m_tab->changeTab(m_localemon, m_locale->translate("&Money"));
  m_tab->changeTab(m_localetime, m_locale->translate("&Time && Dates"));
  m_tab->changeTab(m_localeother, m_locale->translate("&Other"));

  // FIXME: All widgets are done now. However, there are
  // still some problems. Popup menus from the QLabels are
  // not retranslated.
}

void TDELocaleApplication::slotChanged()
{
  emit changed(true);
}