22 #include "kswitchlanguagedialog.h"
25 #include <tqtooltip.h>
29 #include <klanguagebutton.h>
32 #include <kmessagebox.h>
34 #include <kpushbutton.h>
36 struct LanguageRowData
49 this->languageButton = languageButton;
50 this->removeButton = removeButton;
55 class KSwitchLanguageDialogPrivate
70 void addLanguageButton(
const TQString & languageCode,
bool primaryLanguage);
75 TQStringList applicationLanguageList();
77 TQMap<KPushButton*, LanguageRowData> languageRows;
78 TQPtrList<KLanguageButton> languageButtons;
79 TQGridLayout *languagesLayout;
90 KDialogBase(parent, name, modal, i18n(
"Switch application language"), Ok|Cancel, Ok, true ),
91 d(new KSwitchLanguageDialogPrivate(this))
93 d->page =
new TQWidget(
this );
95 TQVBoxLayout *topLayout =
new TQVBoxLayout( d->page, 0,
spacingHint() );
96 TQLabel *label =
new TQLabel( i18n(
"Please choose language which should be used for this application"), d->page,
"label1" );
97 topLayout->addWidget( label );
99 TQHBoxLayout *languageHorizontalLayout =
new TQHBoxLayout();
100 topLayout->addLayout(languageHorizontalLayout);
102 d->languagesLayout =
new TQGridLayout(0 , 2);
103 languageHorizontalLayout->addLayout(TQT_TQLAYOUT(d->languagesLayout));
104 languageHorizontalLayout->addStretch();
106 TQStringList defaultLanguages = d->applicationLanguageList();
108 for ( TQStringList::ConstIterator it = defaultLanguages.begin(); it != defaultLanguages.end(); ++it )
110 TQString language = *it;
111 bool primaryLanguage = (it == defaultLanguages.begin());
112 d->addLanguageButton(language, primaryLanguage);
115 if (defaultLanguages.count() == 0)
120 TQHBoxLayout *addButtonHorizontalLayout =
new TQHBoxLayout();
121 topLayout->addLayout(addButtonHorizontalLayout);
124 TQToolTip::add(addLangButton, i18n(
"Adds one more language which will be used if other translations do not contain proper translation"));
126 addButtonHorizontalLayout->addWidget(addLangButton);
127 addButtonHorizontalLayout->addStretch();
129 topLayout->addStretch(10);
132 KSwitchLanguageDialog::~KSwitchLanguageDialog()
140 d->addLanguageButton(
"en_US", d->languageButtons.isEmpty() ?
true :
false);
145 TQObject
const *signalSender = TQT_TQOBJECT_CONST(sender());
147 if (signalSender == NULL)
149 kdError() <<
"KSwitchLanguageDialog::removeButtonClicked() called directly, not using signal";
155 if (removeButton == NULL)
157 kdError() <<
"KSwitchLanguageDialog::removeButtonClicked() called from something else than KPushButton";
161 TQMap<KPushButton *, LanguageRowData>::iterator it = d->languageRows.find(removeButton);
163 if (it == d->languageRows.end())
165 kdError() <<
"KSwitchLanguageDialog::removeButtonClicked called from unknown KPushButton";
169 LanguageRowData languageRowData = it.data();
171 d->languageButtons.removeRef(languageRowData.languageButton);
173 languageRowData.label->deleteLater();
174 languageRowData.languageButton->deleteLater();
175 languageRowData.removeButton->deleteLater();
176 d->languageRows.erase(it);
181 for ( TQPtrList<KLanguageButton>::ConstIterator it = d->languageButtons.begin(); it != d->languageButtons.end(); ++it )
184 if (languageButton->
current() == languageCode)
195 TQString languageString;
198 for ( TQPtrList<KLanguageButton>::ConstIterator it = d->languageButtons.begin(); it != d->languageButtons.end(); ++it )
204 languageString +=
':';
206 languageString += languageButton->
current();
212 if (d->applicationLanguageList().join(
":") != languageString)
222 i18n(
"Language for this application has been changed. The change will take effect upon next start of application"),
223 i18n(
"Application language changed"),
224 "ApplicationLanguageChangedWarning"
234 KSwitchLanguageDialogPrivate::KSwitchLanguageDialogPrivate(
242 void KSwitchLanguageDialogPrivate::fillApplicationLanguages(
KLanguageButton *button)
246 for ( TQStringList::ConstIterator it = allLanguages.begin(); it != allLanguages.end(); ++it )
248 TQString languageCode = *it;
259 TQStringList KSwitchLanguageDialogPrivate::applicationLanguageList()
262 TQStringList languagesList;
268 if (config->
hasKey(
"Language"))
273 if (languagesList.empty())
277 return languagesList;
280 void KSwitchLanguageDialogPrivate::addLanguageButton(
const TQString & languageCode,
bool primaryLanguage)
282 TQString labelText = primaryLanguage ? i18n(
"Primary language:") : i18n(
"Fallback language:");
288 fillApplicationLanguages(languageButton);
294 TQT_SIGNAL(activated(
const TQString &)),
296 TQT_SLOT(languageOnButtonChanged(
const TQString &))
299 LanguageRowData languageRowData;
302 if (primaryLanguage ==
false)
304 removeButton =
new KPushButton(i18n(
"Remove"), page);
308 TQT_SIGNAL(clicked()),
310 TQT_SLOT(removeButtonClicked())
316 TQToolTip::add(languageButton, i18n(
"This is main application language which will be used first before any other languages"));
320 TQToolTip::add(languageButton, i18n(
"This is language which will be used if any previous languages does not contain proper translation"));
323 int numRows = languagesLayout->numRows();
325 TQLabel *languageLabel =
new TQLabel(labelText, page);
326 languagesLayout->addWidget( languageLabel, numRows + 1, 1, (TQ_Alignment)TQt::AlignAuto );
327 languagesLayout->addWidget( languageButton, numRows + 1, 2, (TQ_Alignment)TQt::AlignAuto );
329 if (primaryLanguage ==
false)
331 languagesLayout->addWidget( removeButton, numRows + 1, 3, (TQ_Alignment)TQt::AlignAuto );
333 languageRowData.setRowWidgets(
338 removeButton->show();
341 languageRows.insert(removeButton, languageRowData);
343 languageButtons.append(languageButton);
344 languageButton->show();
345 languageLabel->show();
348 #include "kswitchlanguagedialog.moc"