2
// C++ Implementation: clanguagesettings
7
// Author: The BibleTime team <info@bibletime.info>, (C) 1999-2008
9
// Copyright: See COPYING file that comes with this distribution
13
#include "clanguagesettings.h"
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2009 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
10
#include "frontend/settingsdialogs/clanguagesettings.h"
14
#include <QHBoxLayout>
16
#include <QVBoxLayout>
18
#include "frontend/settingsdialogs/cfontchooser.h"
15
19
#include "util/cpointers.h"
16
#include "util/ctoolclass.h"
17
20
#include "util/cresmgr.h"
18
#include "util/directoryutil.h"
21
#include <QVBoxLayout>
22
#include <QHBoxLayout>
28
#include "cfontchooser.h"
21
#include "util/tool.h"
22
#include "util/directory.h"
32
25
#include <localemgr.h>
33
26
#include <swlocale.h>
35
29
CLanguageSettingsPage::CLanguageSettingsPage(QWidget* /*parent*/)
39
QVBoxLayout* layout = new QVBoxLayout(this);
43
CToolClass::explanationLabel(
46
tr("Select the language in which the Biblical book names are displayed.")
49
m_swordLocaleCombo = new QComboBox(this);
50
QLabel* label = new QLabel( tr("Language for names of Bible books:"), this);
51
label->setBuddy(m_swordLocaleCombo);
52
m_swordLocaleCombo->setToolTip(tr("The languages which can be used for the biblical booknames"));
55
QHBoxLayout* hBoxLayout = new QHBoxLayout();
56
hBoxLayout->addWidget(label);
57
hBoxLayout->addWidget(m_swordLocaleCombo);
58
hBoxLayout->addStretch();
59
layout->addLayout(hBoxLayout);
61
QStringList languageNames;
62
languageNames.append( languageMgr()->languageForAbbrev("en_US")->translatedName() );
64
std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
65
for (std::list<sword::SWBuf>::const_iterator it = locales.begin(); it != locales.end(); it++)
67
// qWarning("working on %s", (*it).c_str());
68
const CLanguageMgr::Language* const l =
69
CPointers::languageMgr()->languageForAbbrev( sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName() );
73
languageNames.append( l->translatedName() );
78
sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getDescription()
84
m_swordLocaleCombo->addItems( languageNames );
86
const CLanguageMgr::Language* const l =
87
CPointers::languageMgr()->languageForAbbrev( CBTConfig::get(CBTConfig::language) );
89
QString currentLanguageName;
90
if ( l->isValid() && languageNames.contains(l->translatedName()) )
91
{ //tranlated language name is in the box
92
currentLanguageName = l->translatedName();
95
{ //a language like "German Abbrevs" might be the language to set
96
sword::SWLocale* locale =
97
sword::LocaleMgr::getSystemLocaleMgr()->getLocale( CBTConfig::get(CBTConfig::language).toLocal8Bit() );
100
currentLanguageName = QString::fromLatin1(locale->getDescription());
104
if (currentLanguageName.isEmpty())
105
{ // set english as default if nothing was chosen
106
Q_ASSERT(languageMgr()->languageForAbbrev("en_US"));
107
currentLanguageName = languageMgr()->languageForAbbrev("en_US")->translatedName();
110
//now set the item with the right name as current item
111
for (int i = 0; i < m_swordLocaleCombo->count(); ++i)
113
if (currentLanguageName == m_swordLocaleCombo->itemText(i))
115
m_swordLocaleCombo->setCurrentIndex(i);
116
break; //item found, finish the loop
120
layout->addSpacing(20);
125
CToolClass::explanationLabel(
128
tr("You can specify a custom font for each language.")
131
QHBoxLayout* hLayout = new QHBoxLayout();
133
m_usageCombo = new QComboBox(this);
134
m_usageCombo->setToolTip(tr("The font selection below will apply to all texts in this language"));
136
hLayout->addWidget(m_usageCombo);
138
CLanguageMgr::LangMap langMap = languageMgr()->availableLanguages();
140
for (CLanguageMgr::LangMapIterator it = langMap.constBegin() ; it != langMap.constEnd(); ++it )
143
(*it)->translatedName().isEmpty()
145
: (*it)->translatedName();
147
m_fontMap.insert(name, CBTConfig::get(*it) );
150
for( QMap<QString, CBTConfig::FontSettingsPair>::Iterator it = m_fontMap.begin(); it != m_fontMap.end(); ++it )
152
if ( m_fontMap[it.key()].first )
154
m_usageCombo->addItem(util::filesystem::DirectoryUtil::getIcon("fonts.svg"), it.key() );
157
{ //don't show icon for font
158
m_usageCombo->addItem(it.key());
162
m_useOwnFontCheck = new QCheckBox(tr("Use custom font"), this);
163
m_useOwnFontCheck->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
164
connect(m_useOwnFontCheck, SIGNAL(toggled(bool)), SLOT(useOwnFontClicked(bool)) );
165
hLayout->addWidget(m_useOwnFontCheck);
167
layout->addLayout(hLayout);
168
hLayout->setContentsMargins(0,0,0,0);
169
//#warning TODO: remember the last selected font and jump there.
171
m_fontChooser = new CFontChooser(this);
173
//TODO: Eeli's wishlist: why not show something relevant here, like a Bible verse in chosen (not tr()'ed!) language?
175
sampleText.append("1 In the beginning God created the heaven and the earth. ");
31
namespace DU = util::directory;
33
QVBoxLayout* layout = new QVBoxLayout(this);
37
util::tool::explanationLabel(
40
tr("Select the language in which the Biblical book names are displayed.")
43
m_swordLocaleCombo = new QComboBox(this);
44
QLabel* label = new QLabel( tr("Language for names of Bible books:"), this);
45
label->setBuddy(m_swordLocaleCombo);
46
m_swordLocaleCombo->setToolTip(tr("The languages which can be used for the biblical booknames"));
49
QHBoxLayout* hBoxLayout = new QHBoxLayout();
50
hBoxLayout->addWidget(label);
51
hBoxLayout->addWidget(m_swordLocaleCombo);
52
hBoxLayout->addStretch();
53
layout->addLayout(hBoxLayout);
55
QStringList languageNames;
56
languageNames.append( languageMgr()->languageForAbbrev("en_US")->translatedName() );
58
std::list<sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
59
for (std::list<sword::SWBuf>::const_iterator it = locales.begin(); it != locales.end(); it++) {
60
// qWarning("working on %s", (*it).c_str());
61
const CLanguageMgr::Language* const l =
62
CPointers::languageMgr()->languageForAbbrev( sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getName() );
65
languageNames.append( l->translatedName() );
69
sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str())->getDescription()
75
m_swordLocaleCombo->addItems( languageNames );
77
const CLanguageMgr::Language* const l =
78
CPointers::languageMgr()->languageForAbbrev( CBTConfig::get(CBTConfig::language) );
80
QString currentLanguageName;
81
if ( l->isValid() && languageNames.contains(l->translatedName()) ) { //tranlated language name is in the box
82
currentLanguageName = l->translatedName();
84
else { //a language like "German Abbrevs" might be the language to set
85
sword::SWLocale* locale =
86
sword::LocaleMgr::getSystemLocaleMgr()->getLocale( CBTConfig::get(CBTConfig::language).toLocal8Bit() );
88
currentLanguageName = QString::fromLatin1(locale->getDescription());
92
if (currentLanguageName.isEmpty()) { // set english as default if nothing was chosen
93
Q_ASSERT(languageMgr()->languageForAbbrev("en_US"));
94
currentLanguageName = languageMgr()->languageForAbbrev("en_US")->translatedName();
97
//now set the item with the right name as current item
98
for (int i = 0; i < m_swordLocaleCombo->count(); ++i) {
99
if (currentLanguageName == m_swordLocaleCombo->itemText(i)) {
100
m_swordLocaleCombo->setCurrentIndex(i);
101
break; //item found, finish the loop
105
layout->addSpacing(20);
110
util::tool::explanationLabel(
113
tr("You can specify a custom font for each language.")
116
QHBoxLayout* hLayout = new QHBoxLayout();
118
m_usageCombo = new QComboBox(this);
119
m_usageCombo->setToolTip(tr("The font selection below will apply to all texts in this language"));
121
hLayout->addWidget(m_usageCombo);
123
CLanguageMgr::LangMap langMap = languageMgr()->availableLanguages();
125
for (CLanguageMgr::LangMapIterator it = langMap.constBegin() ; it != langMap.constEnd(); ++it ) {
127
(*it)->translatedName().isEmpty()
129
: (*it)->translatedName();
131
m_fontMap.insert(name, CBTConfig::get(*it) );
134
for ( QMap<QString, CBTConfig::FontSettingsPair>::Iterator it = m_fontMap.begin(); it != m_fontMap.end(); ++it ) {
135
if ( m_fontMap[it.key()].first ) { //show font icon
136
m_usageCombo->addItem(DU::getIcon("fonts.svg"), it.key() );
138
else { //don't show icon for font
139
m_usageCombo->addItem(it.key());
143
m_useOwnFontCheck = new QCheckBox(tr("Use custom font"), this);
144
m_useOwnFontCheck->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
145
connect(m_useOwnFontCheck, SIGNAL(toggled(bool)), SLOT(useOwnFontClicked(bool)) );
146
hLayout->addWidget(m_useOwnFontCheck);
148
layout->addLayout(hLayout);
149
hLayout->setContentsMargins(0, 0, 0, 0);
150
/// \todo remember the last selected font and jump there.
152
m_fontChooser = new CFontChooser(this);
154
/// \todo Eeli's wishlist: why not show something relevant here, like a Bible verse in chosen (not tr()'ed!) language?
156
sampleText.append("1 In the beginning God created the heaven and the earth. ");
176
157
sampleText.append("2 And the earth was without form, and void; and darkness was on the face of the deep.");
177
sampleText.append(" And the Spirit of God moved on the face of the waters.");
179
m_fontChooser->setSampleText(sampleText);
180
layout->addWidget(m_fontChooser);
182
connect(m_fontChooser, SIGNAL(fontSelected(const QFont&)), SLOT(newDisplayWindowFontSelected(const QFont&)));
183
connect(m_usageCombo, SIGNAL(activated(const QString&)), SLOT(newDisplayWindowFontAreaSelected(const QString&)));
185
m_fontChooser->setFont( m_fontMap[m_usageCombo->currentText()].second );
186
useOwnFontClicked( m_fontMap[m_usageCombo->currentText()].first );
187
m_useOwnFontCheck->setChecked( m_fontMap[m_usageCombo->currentText()].first );
188
m_fontChooser->setMinimumSize(m_fontChooser->sizeHint());
192
CLanguageSettingsPage::~CLanguageSettingsPage()
196
void CLanguageSettingsPage::save()
198
for(QMap<QString, CBTConfig::FontSettingsPair>::Iterator it = m_fontMap.begin(); it != m_fontMap.end(); ++it )
200
const CLanguageMgr::Language* const lang = languageMgr()->languageForTranslatedName(it.key());
201
if (!lang->isValid())
202
{ //we possibly use a language, for which we have only the abbrev
203
if (!lang->abbrev().isEmpty()) {
204
CLanguageMgr::Language l(it.key(), it.key(), it.key()); //create a temp language
205
CBTConfig::set(&l, it.value());
210
CBTConfig::set(lang, it.value());
215
QString languageAbbrev;
217
const QString currentLanguageName = m_swordLocaleCombo->currentText();
218
const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForTranslatedName( currentLanguageName );
220
if (l && l->isValid())
222
languageAbbrev = l->abbrev();
225
{ //it can be the lang abbrev like de_abbrev or the Sword description
226
std::list <sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
228
for (std::list <sword::SWBuf>::iterator it = locales.begin(); it != locales.end(); it++)
230
sword::SWLocale* locale = sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str());
233
if ( locale && (QString::fromLatin1(locale->getDescription()) == currentLanguageName) )
235
languageAbbrev = QString::fromLatin1(locale->getName()); //we found the abbrevation for the current language
240
if (languageAbbrev.isEmpty())
242
languageAbbrev = currentLanguageName; //probably a non-standard locale name like de_abbrev
246
if (!languageAbbrev.isEmpty())
248
CBTConfig::set(CBTConfig::language, languageAbbrev);
158
sampleText.append(" And the Spirit of God moved on the face of the waters.");
160
m_fontChooser->setSampleText(sampleText);
161
layout->addWidget(m_fontChooser);
163
connect(m_fontChooser, SIGNAL(fontSelected(const QFont&)), SLOT(newDisplayWindowFontSelected(const QFont&)));
164
connect(m_usageCombo, SIGNAL(activated(const QString&)), SLOT(newDisplayWindowFontAreaSelected(const QString&)));
166
m_fontChooser->setFont( m_fontMap[m_usageCombo->currentText()].second );
167
useOwnFontClicked( m_fontMap[m_usageCombo->currentText()].first );
168
m_useOwnFontCheck->setChecked( m_fontMap[m_usageCombo->currentText()].first );
169
m_fontChooser->setMinimumSize(m_fontChooser->sizeHint());
173
CLanguageSettingsPage::~CLanguageSettingsPage() {
176
void CLanguageSettingsPage::save() {
177
for (QMap<QString, CBTConfig::FontSettingsPair>::Iterator it = m_fontMap.begin(); it != m_fontMap.end(); ++it ) {
178
const CLanguageMgr::Language* const lang = languageMgr()->languageForTranslatedName(it.key());
179
if (!lang->isValid()) { //we possibly use a language, for which we have only the abbrev
180
if (!lang->abbrev().isEmpty()) {
181
CLanguageMgr::Language l(it.key(), it.key(), it.key()); //create a temp language
182
CBTConfig::set(&l, it.value());
186
CBTConfig::set(lang, it.value());
191
QString languageAbbrev;
193
const QString currentLanguageName = m_swordLocaleCombo->currentText();
194
const CLanguageMgr::Language* const l = CPointers::languageMgr()->languageForTranslatedName( currentLanguageName );
196
if (l && l->isValid()) {
197
languageAbbrev = l->abbrev();
199
else { //it can be the lang abbrev like de_abbrev or the Sword description
200
std::list <sword::SWBuf> locales = sword::LocaleMgr::getSystemLocaleMgr()->getAvailableLocales();
202
for (std::list <sword::SWBuf>::iterator it = locales.begin(); it != locales.end(); it++) {
203
sword::SWLocale* locale = sword::LocaleMgr::getSystemLocaleMgr()->getLocale((*it).c_str());
206
if ( locale && (QString::fromLatin1(locale->getDescription()) == currentLanguageName) ) {
207
languageAbbrev = QString::fromLatin1(locale->getName()); //we found the abbrevation for the current language
212
if (languageAbbrev.isEmpty()) {
213
languageAbbrev = currentLanguageName; //probably a non-standard locale name like de_abbrev
217
if (!languageAbbrev.isEmpty()) {
218
CBTConfig::set(CBTConfig::language, languageAbbrev);
253
void CLanguageSettingsPage::newDisplayWindowFontSelected(const QFont &newFont)
255
//belongs to the languages/fonts page
256
CBTConfig::FontSettingsPair oldSettings = m_fontMap[ m_usageCombo->currentText() ];
257
m_fontMap.insert( m_usageCombo->currentText(), CBTConfig::FontSettingsPair(oldSettings.first, newFont) );
223
void CLanguageSettingsPage::newDisplayWindowFontSelected(const QFont &newFont) {
224
//belongs to the languages/fonts page
225
CBTConfig::FontSettingsPair oldSettings = m_fontMap[ m_usageCombo->currentText() ];
226
m_fontMap.insert( m_usageCombo->currentText(), CBTConfig::FontSettingsPair(oldSettings.first, newFont) );
260
229
/** Called when the combobox contents is changed */
261
void CLanguageSettingsPage::newDisplayWindowFontAreaSelected(const QString& usage)
263
//belongs to fonts/languages
264
useOwnFontClicked( m_fontMap[usage].first );
265
m_useOwnFontCheck->setChecked( m_fontMap[usage].first );
230
void CLanguageSettingsPage::newDisplayWindowFontAreaSelected(const QString& usage) {
231
//belongs to fonts/languages
232
useOwnFontClicked( m_fontMap[usage].first );
233
m_useOwnFontCheck->setChecked( m_fontMap[usage].first );
267
m_fontChooser->setFont( m_fontMap[usage].second );
235
m_fontChooser->setFont( m_fontMap[usage].second );
271
239
/** This slot is called when the "Use own font for language" bo was clicked. */
272
void CLanguageSettingsPage::useOwnFontClicked( bool isOn )
274
//belongs to fonts/languages
276
m_fontChooser->setEnabled(isOn);
277
m_fontMap[ m_usageCombo->currentText() ].first = isOn;
281
m_usageCombo->setItemIcon(m_usageCombo->currentIndex(), util::filesystem::DirectoryUtil::getIcon("fonts.svg") );
285
m_usageCombo->setItemText(m_usageCombo->currentIndex(), m_usageCombo->currentText() ); //TODO: should this change icon to empty?
290
QString CLanguageSettingsPage::iconName()
292
return CResMgr::settings::fonts::icon;
294
QString CLanguageSettingsPage::label()
296
//: Empty string, don't translate
299
QString CLanguageSettingsPage::header()
301
return tr("Languages");
240
void CLanguageSettingsPage::useOwnFontClicked(bool isOn) {
241
namespace DU = util::directory;
243
//belongs to fonts/languages
245
m_fontChooser->setEnabled(isOn);
246
m_fontMap[ m_usageCombo->currentText() ].first = isOn;
248
if (isOn) { //show font icon
249
m_usageCombo->setItemIcon(m_usageCombo->currentIndex(), DU::getIcon("fonts.svg"));
252
m_usageCombo->setItemText(m_usageCombo->currentIndex(), m_usageCombo->currentText() ); /// \todo should this change icon to empty?
257
QString CLanguageSettingsPage::iconName() {
258
return CResMgr::settings::fonts::icon;
260
QString CLanguageSettingsPage::label() {
261
//: Empty string, don't translate
264
QString CLanguageSettingsPage::header() {
265
return tr("Languages");