From b7e54f8e21143070e5245b930eb692cb3e5690d6 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 28 Jul 2023 00:40:34 +0300 Subject: [PATCH] kdeui: stub KSwitchLanguageDialog to be rewritten. date, time, days, etc. translation and conversion work like a charm tho (when translated and supported by the locale classes ofcourse): https://ibb.co/hcW0dL3 Signed-off-by: Ivailo Monev --- includes/CMakeLists.txt | 1 - includes/KLanguageButton | 1 - kdeui/CMakeLists.txt | 2 - kdeui/dialogs/kswitchlanguagedialog_p.cpp | 369 ++++------------------ kdeui/dialogs/kswitchlanguagedialog_p.h | 91 ++---- kdeui/widgets/klanguagebutton.cpp | 264 ---------------- kdeui/widgets/klanguagebutton.h | 176 ----------- kdewidgets/kde.widgets | 6 - 8 files changed, 90 insertions(+), 820 deletions(-) delete mode 100644 includes/KLanguageButton delete mode 100644 kdeui/widgets/klanguagebutton.cpp delete mode 100644 kdeui/widgets/klanguagebutton.h diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index bf7d5978..02d4c2e0 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -160,7 +160,6 @@ install( KJobTrackerInterface KJobUiDelegate KKeySequenceWidget - KLanguageButton KLed KLineEdit KLinkItemSelectionModel diff --git a/includes/KLanguageButton b/includes/KLanguageButton deleted file mode 100644 index c796fbf6..00000000 --- a/includes/KLanguageButton +++ /dev/null @@ -1 +0,0 @@ -#include "../klanguagebutton.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 59cb84a5..05115a63 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -212,7 +212,6 @@ set(kdeui_LIB_SRCS widgets/khelpmenu.cpp widgets/khistorycombobox.cpp widgets/kkeysequencewidget.cpp - widgets/klanguagebutton.cpp widgets/kled.cpp widgets/klineedit.cpp widgets/kmainwindow.cpp @@ -517,7 +516,6 @@ install( widgets/khelpmenu.h widgets/khistorycombobox.h widgets/kkeysequencewidget.h - widgets/klanguagebutton.h widgets/kled.h widgets/klineedit.h widgets/kmainwindow.h diff --git a/kdeui/dialogs/kswitchlanguagedialog_p.cpp b/kdeui/dialogs/kswitchlanguagedialog_p.cpp index 94ff59f6..e6c30070 100644 --- a/kdeui/dialogs/kswitchlanguagedialog_p.cpp +++ b/kdeui/dialogs/kswitchlanguagedialog_p.cpp @@ -1,221 +1,82 @@ -/* - * This file is part of the KDE Libraries - * Copyright (C) 2007 Krzysztof Lichota (lichota@mimuw.edu.pl) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev -#include "moc_kswitchlanguagedialog_p.cpp" + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. -#include -#include -#include -#include -#include + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kswitchlanguagedialog_p.h" -#include #include #include #include #include -#include +#include +#include -namespace KDEPrivate { - -struct LanguageRowData +static void languageChanged(KSwitchLanguageDialog *dialog) { - LanguageRowData() - { - label = nullptr; - languageButton = nullptr; - removeButton = nullptr; - } - QLabel *label; - KLanguageButton *languageButton; - KPushButton *removeButton; + KMessageBox::information( + dialog, + i18n("The language for this application has been changed. The change will take effect the next time the application is started."), // text + i18n("Application Language Changed"), // caption + "ApplicationLanguageChangedWarning" // dontShowAgainName + ); - void setRowWidgets(QLabel *label, KLanguageButton *languageButton, KPushButton *removeButton) - { - this->label = label; - this->languageButton = languageButton; - this->removeButton = removeButton; - } - -}; - -class KSwitchLanguageDialogPrivate -{ -public: - KSwitchLanguageDialogPrivate(KSwitchLanguageDialog *parent); - - KSwitchLanguageDialog *p; //parent class - - /** - Fills language button with names of languages for which given application has translation. - */ - void fillApplicationLanguages(KLanguageButton *button); - - /** - Adds one button with language to widget. - */ - void addLanguageButton(const QString &languageCode, bool primaryLanguage); - - /** - Returns list of languages chosen for application or default languages is they are not set. - */ - QStringList applicationLanguageList(); - - QMap languageRows; - QList languageButtons; - QGridLayout *languagesLayout; - QWidget *page; -}; - -/*************************** KSwitchLanguageDialog **************************/ + QEvent ev(QEvent::LanguageChange); + QApplication::sendEvent(qApp, &ev); +} KSwitchLanguageDialog::KSwitchLanguageDialog(QWidget *parent) - : KDialog(parent), - d(new KSwitchLanguageDialogPrivate(this)) + : KDialog(parent), + m_dialogwidget(nullptr), + m_dialoglayout(nullptr), + m_languagelabel(nullptr), + m_languageedit(nullptr) { setCaption(i18n("Switch Application Language")); setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Default); setDefaultButton(Ok); + connect(this, SIGNAL(okClicked()), SLOT(slotOk())); connect(this, SIGNAL(defaultClicked()), SLOT(slotDefault())); - d->page = new QWidget(this); - setMainWidget(d->page); - QVBoxLayout *topLayout = new QVBoxLayout(d->page); - topLayout->setMargin( 0 ); - QLabel *label = new QLabel(i18n("Please choose the language which should be used for this application:"), d->page); - topLayout->addWidget(label); - - QHBoxLayout *languageHorizontalLayout = new QHBoxLayout(); - topLayout->addLayout(languageHorizontalLayout); - - d->languagesLayout = new QGridLayout(); - languageHorizontalLayout->addLayout(d->languagesLayout); - languageHorizontalLayout->addStretch(); - - const QStringList defaultLanguages = d->applicationLanguageList(); - - int count = defaultLanguages.count(); - for (int i = 0; i < count; ++i) { - QString language = defaultLanguages[i]; - bool primaryLanguage = (i == 0); - d->addLanguageButton(language, primaryLanguage); - } - - if (!count) { - d->addLanguageButton(KLocale::defaultLanguage(), true); - } - - QHBoxLayout *addButtonHorizontalLayout = new QHBoxLayout(); - topLayout->addLayout(addButtonHorizontalLayout); - - KPushButton *addLangButton = new KPushButton(i18n("Add Fallback Language"), d->page); - addLangButton->setToolTip( - i18n("Adds one more language which will be used if other translations do not contain a proper translation.") - ); - connect(addLangButton, SIGNAL(clicked()), this, SLOT(slotAddLanguageButton())); - addButtonHorizontalLayout->addWidget(addLangButton); - addButtonHorizontalLayout->addStretch(); - - topLayout->addStretch(10); + m_dialogwidget = new QWidget(this); + m_dialoglayout = new QVBoxLayout(m_dialogwidget); + m_languagelabel = new QLabel(m_dialogwidget); + m_languagelabel->setText(i18n("Please choose the language which should be used for this application:")); + m_dialoglayout->addWidget(m_languagelabel); + m_languageedit = new KEditListWidget(m_dialogwidget); + m_dialoglayout->addWidget(m_languageedit); + setMainWidget(m_dialogwidget); } KSwitchLanguageDialog::~KSwitchLanguageDialog() { - delete d; -} - -void KSwitchLanguageDialog::slotAddLanguageButton() -{ - // adding new button with en_US as it should always be present - d->addLanguageButton(KLocale::defaultLanguage(), d->languageButtons.isEmpty()); -} - -void KSwitchLanguageDialog::removeButtonClicked() -{ - KPushButton *removeButton = qobject_cast(sender()); - if (!removeButton) { - kError() << "KSwitchLanguageDialog::removeButtonClicked() called from something else than KPushButton"; - return; - } - - QMap::iterator it = d->languageRows.find(removeButton); - if (it == d->languageRows.end()) { - kError() << "KSwitchLanguageDialog::removeButtonClicked called from unknown KPushButton"; - return; - } - - LanguageRowData languageRowData = it.value(); - - d->languageButtons.removeAll(languageRowData.languageButton); - - languageRowData.label->deleteLater(); - languageRowData.languageButton->deleteLater(); - languageRowData.removeButton->deleteLater(); - d->languageRows.erase(it); -} - -void KSwitchLanguageDialog::languageOnButtonChanged(const QString &languageCode) -{ - Q_UNUSED(languageCode); -#if 0 - for ( int i = 0, count = d->languageButtons.count(); i < count; ++i ) - { - KLanguageButton *languageButton = d->languageButtons[i]; - if (languageButton->current() == languageCode) - { - //update all buttons which have matching id - //might update buttons which were not changed, but well... - languageButton->setText(KGlobal::locale()->languageCodeToName(languageCode)); - } - } -#endif } void KSwitchLanguageDialog::slotOk() { - QStringList languages; + KConfigGroup localegroup(KGlobal::config(), "Locale"); + const QStringList oldtranslations = localegroup.readEntry("Translations", QStringList()); - for ( int i = 0, count = d->languageButtons.count(); i < count; ++i ) { - KLanguageButton *languageButton = d->languageButtons[i]; - languages << languageButton->current(); - } + const QStringList newtranslations = QStringList(); // TODO: + if (oldtranslations != newtranslations) { + localegroup.writeEntry("Translations", newtranslations); + localegroup.sync(); - if (d->applicationLanguageList() != languages) { - QString languageString = languages.join(":"); - //list is different from defaults or saved languages list - KConfigGroup group(KGlobal::config(), "Locale"); - - group.writeEntry("Language", languageString); - group.sync(); - - KMessageBox::information( - this, - i18n("The language for this application has been changed. The change will take effect the next time the application is started."), //text - i18n("Application Language Changed"), //caption - "ApplicationLanguageChangedWarning" //dontShowAgainName - ); - - QEvent ev(QEvent::LanguageChange); - QApplication::sendEvent(qApp, &ev); + languageChanged(this); } accept(); @@ -223,131 +84,17 @@ void KSwitchLanguageDialog::slotOk() void KSwitchLanguageDialog::slotDefault() { - const QStringList defaultLanguages = d->applicationLanguageList(); + KConfigGroup localegroup(KGlobal::config(), "Locale"); + const QStringList oldtranslations = localegroup.readEntry("Translations", QStringList()); + localegroup.revertToDefault("Translations"); + localegroup.sync(); - KConfigGroup group(KGlobal::config(), "Locale"); - - group.revertToDefault("Language"); - group.sync(); - // read back the new default - const QString language = group.readEntry("Language", KLocale::defaultLanguage()); - - if (defaultLanguages != (QStringList() << language)) { - KMessageBox::information( - this, - i18n("The language for this application has been changed. The change will take effect the next time the application is started."), //text - i18n("Application Language Changed"), // caption - "ApplicationLanguageChangedWarning" // dontShowAgainName - ); - - QEvent ev(QEvent::LanguageChange); - QApplication::sendEvent(qApp, &ev); + const QStringList newtranslations = localegroup.readEntry("Translations", QStringList()); + if (oldtranslations != newtranslations) { + languageChanged(this); } accept(); } -/************************ KSwitchLanguageDialogPrivate ***********************/ - -KSwitchLanguageDialogPrivate::KSwitchLanguageDialogPrivate(KSwitchLanguageDialog *parent) - : p(parent) -{ - // NOTE: do NOT use "p" in constructor, it is not fully constructed -} - -void KSwitchLanguageDialogPrivate::fillApplicationLanguages(KLanguageButton *button) -{ - QStringList allLanguages = KLocale::installedLanguages(); - allLanguages.prepend(KLocale::defaultLanguage()); - for (int i = 0, count = allLanguages.count(); i < count; ++i) { - QString languageCode = allLanguages[i]; - if (KLocale::isApplicationTranslatedInto(languageCode)) { - button->insertLanguage(languageCode); - } - } -} - -QStringList KSwitchLanguageDialogPrivate::applicationLanguageList() -{ - KSharedConfigPtr config = KGlobal::config(); - QStringList languagesList; - - if (config->hasGroup("Locale")) { - KConfigGroup group(config, "Locale"); - if (group.hasKey("Language")) { - languagesList = group.readEntry("Language", QString()).split(':'); - } - } - if (languagesList.isEmpty()) { - languagesList = KGlobal::locale()->languageList(); - } - - KLocale *locale = KGlobal::locale(); - for (int i = 0; i < languagesList.count();) { - if (!locale->isApplicationTranslatedInto(languagesList[i])) { - languagesList.removeAt(i); - } else { - ++i; - } - } - - return languagesList; -} - -void KSwitchLanguageDialogPrivate::addLanguageButton(const QString &languageCode, bool primaryLanguage) -{ - QString labelText = primaryLanguage ? i18n("Primary language:") : i18n("Fallback language:"); - - KLanguageButton *languageButton = new KLanguageButton(page); - - fillApplicationLanguages(languageButton); - - languageButton->setCurrentItem(languageCode); - - QObject::connect( - languageButton, - SIGNAL(activated(QString)), - p, - SLOT(languageOnButtonChanged(QString)) - ); - - LanguageRowData languageRowData; - KPushButton *removeButton = nullptr; - - if (!primaryLanguage) { - removeButton = new KPushButton(i18n("Remove"), page); - - QObject::connect( - removeButton, - SIGNAL(clicked()), - p, - SLOT(removeButtonClicked()) - ); - } - - languageButton->setToolTip( - primaryLanguage - ? i18n("This is the main application language which will be used first, before any other languages.") - : i18n("This is the language which will be used if any previous languages do not contain a proper translation.") - ); - - int numRows = languagesLayout->rowCount(); - - QLabel *languageLabel = new QLabel(labelText, page); - languagesLayout->addWidget(languageLabel, numRows + 1, 1, Qt::AlignLeft); - languagesLayout->addWidget(languageButton, numRows + 1, 2, Qt::AlignLeft); - - if (!primaryLanguage) { - languagesLayout->addWidget(removeButton, numRows + 1, 3, Qt::AlignLeft); - languageRowData.setRowWidgets(languageLabel, languageButton, removeButton); - removeButton->show(); - } - - languageRows.insert(removeButton, languageRowData); - - languageButtons.append(languageButton); - languageButton->show(); - languageLabel->show(); -} - -} +#include "moc_kswitchlanguagedialog_p.cpp" diff --git a/kdeui/dialogs/kswitchlanguagedialog_p.h b/kdeui/dialogs/kswitchlanguagedialog_p.h index 864f6e0a..cf4c8ef9 100644 --- a/kdeui/dialogs/kswitchlanguagedialog_p.h +++ b/kdeui/dialogs/kswitchlanguagedialog_p.h @@ -1,32 +1,29 @@ -/* - * This file is part of the KDE Libraries - * Copyright (C) 2007 Krzysztof Lichota (lichota@mimuw.edu.pl) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ -#ifndef _KSWITCHLANGUAGEDIALOG_H_ -#define _KSWITCHLANGUAGEDIALOG_H_ +#ifndef KSWITCHLANGUAGEDIALOG_H +#define KSWITCHLANGUAGEDIALOG_H -#include +#include "kdialog.h" +#include "keditlistwidget.h" -namespace KDEPrivate { - -class KSwitchLanguageDialogPrivate; +#include +#include /** * @short Standard "switch application language" dialog box. @@ -34,48 +31,24 @@ class KSwitchLanguageDialogPrivate; * This class provides "switch application language" dialog box that is used * in KHelpMenu * - * @author Krzysztof Lichota (lichota@mimuw.edu.pl) * @internal */ class KSwitchLanguageDialog : public KDialog { Q_OBJECT public: - /** - * Constructor. Creates a fully featured "Switch application language" dialog box. - * Note that this dialog is made modeless in the KHelpMenu class so - * the users may expect a modeless dialog. - */ KSwitchLanguageDialog(QWidget *parent = nullptr); - virtual ~KSwitchLanguageDialog(); + ~KSwitchLanguageDialog(); -protected Q_SLOTS: - /** - * Activated when the Ok button has been clicked. - */ - virtual void slotOk(); +private Q_SLOTS: + void slotOk(); void slotDefault(); - - /** - *Called when one of language buttons changes state. - */ - virtual void languageOnButtonChanged(const QString &); - - /** - *Called to add one language button to dialog. - */ - virtual void slotAddLanguageButton(); - - /** - Called when "Remove" language button is clicked. - */ - virtual void removeButtonClicked(); - + private: - KSwitchLanguageDialogPrivate *const d; - friend class KSwitchLanguageDialogPrivate; + QWidget* m_dialogwidget; + QVBoxLayout* m_dialoglayout; + QLabel* m_languagelabel; + KEditListWidget* m_languageedit; }; -} - -#endif +#endif // KSWITCHLANGUAGEDIALOG_H diff --git a/kdeui/widgets/klanguagebutton.cpp b/kdeui/widgets/klanguagebutton.cpp deleted file mode 100644 index 28fd5999..00000000 --- a/kdeui/widgets/klanguagebutton.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 1999-2003 Hans Petter Bieker - * (c) 2007 David Jarvie - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "moc_klanguagebutton.cpp" - -#include -#include -#include - -#include -#include -#include -#include - -static void checkInsertPos( QMenu *popup, const QString &str, int &index ) -{ - if ( index != -1 ) - return; - - int a = 0; - const QList actions = popup->actions(); - int b = actions.count(); - - while ( a < b ) - { - int w = ( a + b ) / 2; - QAction *ac = actions[ w ]; - int j = str.localeAwareCompare( ac->text() ); - if ( j > 0 ) - a = w + 1; - else - b = w; - } - - index = a; // it doesn't really matter ... a == b here. - - Q_ASSERT( a == b ); -} - -class KLanguageButtonPrivate -{ -public: - KLanguageButtonPrivate( KLanguageButton *parent); - ~KLanguageButtonPrivate() { delete button; delete popup; } - void setCurrentItem( QAction* ); - void clear(); - QAction *findAction(const QString &data) const; - - QPushButton *button; - QStringList ids; - QMenu *popup; - QString current; - const KLocale *locale; - bool staticText : 1; - bool showCodes : 1; -}; - -KLanguageButton::KLanguageButton( QWidget * parent ) - : QWidget( parent ), - d( new KLanguageButtonPrivate(this) ) -{ -} - -KLanguageButton::KLanguageButton( const QString & text, QWidget * parent ) - : QWidget( parent ), - d( new KLanguageButtonPrivate(this) ) -{ - setText(text); -} - -KLanguageButtonPrivate::KLanguageButtonPrivate( KLanguageButton *parent ) - : button(new QPushButton(parent)), - popup(new QMenu(parent)), - locale(0), - staticText(false), - showCodes(false) -{ - QHBoxLayout *layout = new QHBoxLayout( parent ); - layout->setMargin(0); - layout->addWidget( button ); - - parent->setFocusProxy( button ); - parent->setFocusPolicy( button->focusPolicy() ); - - button->setMenu( popup ); - - QObject::connect( popup, SIGNAL(triggered(QAction*)), parent, SLOT(slotTriggered(QAction*)) ); - QObject::connect( popup, SIGNAL(hovered(QAction*)), parent, SLOT(slotHovered(QAction*)) ); -} - -KLanguageButton::~KLanguageButton() -{ - delete d; -} - -void KLanguageButton::setText(const QString & text) -{ - d->staticText = true; - d->button->setText(text); -} - -void KLanguageButton::setLocale( const KLocale *locale ) -{ - d->locale = locale; -} - -void KLanguageButton::showLanguageCodes( bool show ) -{ - d->showCodes = show; -} - -void KLanguageButton::insertLanguage( const QString &languageCode, const QString &name, int index ) -{ - QString text; - bool showCodes = d->showCodes; - if (name.isEmpty()) - { - text = languageCode; - const KLocale *locale = d->locale ? d->locale : KGlobal::locale(); - if (locale) - text = locale->languageCodeToName(languageCode); - else - showCodes = false; - } - else - text = name; - if (showCodes) - text += QLatin1String( " (" ) + languageCode + QLatin1Char(')'); - - checkInsertPos( d->popup, text, index ); - QAction *a = new QAction(QIcon(), text, this); - a->setData(languageCode); - if ( index >= 0 && index < d->popup->actions().count()-1) - d->popup->insertAction(d->popup->actions()[index], a); - else - d->popup->addAction(a); - d->ids.append(languageCode); -} - -void KLanguageButton::insertSeparator( int index ) -{ - if ( index >= 0 && index < d->popup->actions().count()-1) - d->popup->insertSeparator(d->popup->actions()[index]); - else - d->popup->addSeparator(); -} - -void KLanguageButton::loadAllLanguages() -{ - QStringList langlist = KGlobal::dirs()->findAllResources("locale", - QString::fromLatin1("l10n/*/entry.desktop")); - langlist.sort(); - for (int i = 0, count = langlist.count(); i < count; ++i) - { - QString fpath = langlist[i].left(langlist[i].length() - 14); - QString code = fpath.mid(fpath.lastIndexOf('/') + 1); - KConfig entry(langlist[i], KConfig::SimpleConfig); - KConfigGroup group(&entry, "KCM Locale"); - QString name = group.readEntry("Name", i18n("without name")); - insertLanguage(code, name, i); - } - - const KLocale *locale = d->locale ? d->locale : KGlobal::locale(); - setCurrentItem(locale ? locale->language() : KLocale::defaultLanguage()); -} - -void KLanguageButton::slotTriggered( QAction *a ) -{ - //kDebug() << "slotTriggered" << index; - if (!a) - return; - - d->setCurrentItem( a ); - - // Forward event from popup menu as if it was emitted from this widget: - emit activated( d->current ); -} - -void KLanguageButton::slotHovered( QAction *a ) -{ - //kDebug() << "slotHovered" << index; - - emit highlighted(a->data().toString()); -} - -int KLanguageButton::count() const -{ - return d->ids.count(); -} - -void KLanguageButton::clear() -{ - d->clear(); -} - -void KLanguageButtonPrivate::clear() -{ - ids.clear(); - popup->clear(); - - if ( !staticText ) { - button->setText( QString() ); - } -} - -bool KLanguageButton::contains( const QString &languageCode ) const -{ - return d->ids.contains( languageCode ); -} - -QString KLanguageButton::current() const -{ - return d->current.isEmpty() ? QLatin1String("en") : d->current; -} - -QAction *KLanguageButtonPrivate::findAction(const QString& data) const -{ - foreach(QAction *a, popup->actions()) { - if (!a->data().toString().compare(data)) - return a; - } - return 0; -} - -void KLanguageButton::setCurrentItem( const QString & languageCode ) -{ - if (!d->ids.count()) - return; - QAction *a; - if (d->ids.indexOf(languageCode) < 0) - a = d->findAction(d->ids[0]); - else - a = d->findAction(languageCode); - if (a) - d->setCurrentItem(a); -} - -void KLanguageButtonPrivate::setCurrentItem( QAction *a ) -{ - if (!a->data().isValid()) - return; - current = a->data().toString(); - - if ( !staticText ) { - button->setText( a->text() ); - } -} diff --git a/kdeui/widgets/klanguagebutton.h b/kdeui/widgets/klanguagebutton.h deleted file mode 100644 index 58069b1b..00000000 --- a/kdeui/widgets/klanguagebutton.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * klangbutton.h - Button with language selection drop down menu. - * Derived from the KLangCombo class by Hans Petter Bieker. - * - * Copyright (c) 1999-2003 Hans Petter Bieker - * (c) 2001 Martijn Klingens - * (c) 2007 David Jarvie - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef KLANGUAGEBUTTON_H -#define KLANGUAGEBUTTON_H - -#include -#include - -#include -class KLocale; -class KLanguageButtonPrivate; - -/** - * KLanguageButton is a pushbutton which allows a language to be selected from - * a popup list. - * - * Languages are identified by their ISO 639-1 codes, e.g. en, pt_BR. - * - * \image html klanguagebutton.png "KDE Language Selection Widget" - * - * @author Hans Petter Bieker , Martijn Klingens , - * David Jarvie - */ -class KDEUI_EXPORT KLanguageButton : public QWidget -{ - Q_OBJECT - -public: - /** - * Constructs a button whose text is determined by the current language - * in the popup list. - * - * @param parent the parent of the button - */ - explicit KLanguageButton(QWidget * parent = 0); - - /** - * Constructs a button with static text. - * - * @param text the text of the button - * @param parent the parent of the button - */ - explicit KLanguageButton(const QString & text, QWidget * parent = 0 ); - - /** - * Deconstructor - */ - virtual ~KLanguageButton(); - - /** - * Sets the locale to display language names. By default, KGlobal::locale() is used. - * - * @param locale locale to use - */ - void setLocale( const KLocale *locale ); - - /** - * Sets a static button text. - * - * @param text button text - */ - void setText( const QString &text ); - - /** - * Specifies whether language codes should be shown alongside language names - * in the popup. Calling this method does not affect any previously - * inserted language texts, so it should normally be called before - * populating the list. - * - * @param show true to show codes, false to hide codes - */ - void showLanguageCodes( bool show ); - - /** - * Load all known languages into the popup list. - * The current language in the list is set to the default language for the - * current locale (as modified by setLocale()). - */ - void loadAllLanguages(); - - /** - * Inserts a language into the combo box. - * Normally the display name of the language is obtained automatically, but - * if either the language code does not exist, or there are special display - * requirements, the name of the language can be specified in @p name. - * - * @param languageCode the code for the language - * @param name language name. If empty, the name is obtained automatically. - * @param index the insertion position, or -1 to insert in alphabetical order - */ - void insertLanguage( const QString &languageCode, const QString &name = QString(), int index = -1 ); - - /** - * Inserts a separator item into the combo box. A negative index will append the item. - * - * @param index the insertion position - */ - void insertSeparator( int index = -1 ); - - /** - * Returns the number of items in the combo box. - */ - int count() const; - - /** - * Removes all combobox items. - */ - void clear(); - - /** - * Returns the language code of the combobox's current item. - * - * @return the current item's language code - */ - QString current() const; - - /** - * Checks whether the specified language is in the popup list. - * - * @param languageCode the language's code - * @return true if in the list - */ - bool contains( const QString &languageCode ) const; - - /** - * Sets a given language to be the current item. - * - * @param languageCode the language's code - */ - void setCurrentItem( const QString &languageCode ); - -Q_SIGNALS: - /** - * This signal is emitted when a new item is activated. - * - * @param languageCode code of the activated language - */ - void activated( const QString &languageCode ); - /** - * This signal is emitted when a new item is highlighted. - * - * @param languageCode code of the highlighted language - */ - void highlighted( const QString &languageCode ); - -private Q_SLOTS: - void slotTriggered( QAction* ); - void slotHovered( QAction* ); - -private: - KLanguageButtonPrivate * const d; -}; - -#endif diff --git a/kdewidgets/kde.widgets b/kdewidgets/kde.widgets index 34e6631c..9a75ac44 100644 --- a/kdewidgets/kde.widgets +++ b/kdewidgets/kde.widgets @@ -151,12 +151,6 @@ WhatsThis=A widget to pick a QKeySequence. IncludeFile=kkeysequencewidget.h Group=Buttons (KDE) -[KLanguageButton] -ToolTip=Language Button (KDE) -WhatsThis=KDE's language button. -IncludeFile=klanguagebutton.h -Group=Buttons (KDE) - [KLed] ToolTip=LED Widget (KDE) WhatsThis=A widget showing a light emitter diode