Browse Source

Make it possible to set user interface language from options dialog

miguelfreitas
Wladimir J. van der Laan 13 years ago
parent
commit
5ac114c756
  1. 39
      src/qt/optionsdialog.cpp
  2. 9
      src/qt/optionsmodel.cpp
  3. 3
      src/qt/optionsmodel.h
  4. 6
      src/qt/qvaluecombobox.cpp
  5. 9
      src/qt/qvaluecombobox.h

39
src/qt/optionsdialog.cpp

@ -19,6 +19,8 @@
#include <QDoubleValidator> #include <QDoubleValidator>
#include <QRegExpValidator> #include <QRegExpValidator>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QDir>
#include <QMessageBox>
class OptionsPage: public QWidget class OptionsPage: public QWidget
{ {
@ -66,8 +68,12 @@ public:
virtual void setMapper(MonitoredDataMapper *mapper); virtual void setMapper(MonitoredDataMapper *mapper);
private: private:
QValueComboBox *lang;
QValueComboBox *unit; QValueComboBox *unit;
QCheckBox *display_addresses; QCheckBox *display_addresses;
bool restart_warning_displayed;
private slots:
void showRestartWarning();
}; };
class NetworkOptionsPage: public OptionsPage class NetworkOptionsPage: public OptionsPage
@ -230,12 +236,33 @@ void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
/* Display options */ /* Display options */
DisplayOptionsPage::DisplayOptionsPage(QWidget *parent): DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
OptionsPage(parent) OptionsPage(parent), restart_warning_displayed(false)
{ {
setWindowTitle(tr("Display")); setWindowTitle(tr("Display"));
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *lang_hbox = new QHBoxLayout();
lang_hbox->addSpacing(18);
QLabel *lang_label = new QLabel(tr("User Interface &Language: "));
lang_hbox->addWidget(lang_label);
lang = new QValueComboBox(this);
// Make list of languages
QDir translations(":translations");
lang->addItem("(default)", QVariant(""));
foreach(const QString &langStr, translations.entryList())
{
lang->addItem(langStr, QVariant(langStr));
}
lang->setToolTip(tr("The user interface language can be set here. This setting will only take effect after restarting Bitcoin."));
connect(lang, SIGNAL(activated(int)), this, SLOT(showRestartWarning()));
lang_label->setBuddy(lang);
lang_hbox->addWidget(lang);
layout->addLayout(lang_hbox);
QHBoxLayout *unit_hbox = new QHBoxLayout(); QHBoxLayout *unit_hbox = new QHBoxLayout();
unit_hbox->addSpacing(18); unit_hbox->addSpacing(18);
QLabel *unit_label = new QLabel(tr("&Unit to show amounts in: ")); QLabel *unit_label = new QLabel(tr("&Unit to show amounts in: "));
@ -259,10 +286,20 @@ DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper) void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
{ {
mapper->addMapping(lang, OptionsModel::Language);
mapper->addMapping(unit, OptionsModel::DisplayUnit); mapper->addMapping(unit, OptionsModel::DisplayUnit);
mapper->addMapping(display_addresses, OptionsModel::DisplayAddresses); mapper->addMapping(display_addresses, OptionsModel::DisplayAddresses);
} }
void DisplayOptionsPage::showRestartWarning()
{
if(!restart_warning_displayed)
{
QMessageBox::warning(this, tr("Warning"), tr("This setting will take effect after restarting Bitcoin."), QMessageBox::Ok);
restart_warning_displayed = true;
}
}
/* Window options */ /* Window options */
WindowOptionsPage::WindowOptionsPage(QWidget *parent): WindowOptionsPage::WindowOptionsPage(QWidget *parent):
OptionsPage(parent) OptionsPage(parent)

9
src/qt/optionsmodel.cpp

@ -21,6 +21,7 @@ void OptionsModel::Init()
fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool(); fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool();
fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool(); fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool();
nTransactionFee = settings.value("nTransactionFee").toLongLong(); nTransactionFee = settings.value("nTransactionFee").toLongLong();
language = settings.value("language", "").toString();
// These are shared with core bitcoin; we want // These are shared with core bitcoin; we want
// command-line options to override the GUI settings: // command-line options to override the GUI settings:
@ -30,6 +31,8 @@ void OptionsModel::Init()
SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString()); SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString());
if (settings.contains("detachDB")) if (settings.contains("detachDB"))
SoftSetBoolArg("-detachdb", settings.value("detachDB").toBool()); SoftSetBoolArg("-detachdb", settings.value("detachDB").toBool());
if (!language.isEmpty())
SoftSetArg("-lang", language.toStdString());
} }
bool OptionsModel::Upgrade() bool OptionsModel::Upgrade()
@ -125,6 +128,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return QVariant(bDisplayAddresses); return QVariant(bDisplayAddresses);
case DetachDatabases: case DetachDatabases:
return QVariant(fDetachDB); return QVariant(fDetachDB);
case Language:
return settings.value("language", "");
default: default:
return QVariant(); return QVariant();
} }
@ -213,6 +218,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
settings.setValue("detachDB", fDetachDB); settings.setValue("detachDB", fDetachDB);
} }
break; break;
case Language: {
settings.setValue("language", value);
}
break;
default: default:
break; break;
} }

3
src/qt/optionsmodel.h

@ -27,6 +27,7 @@ public:
DisplayUnit, // BitcoinUnits::Unit DisplayUnit, // BitcoinUnits::Unit
DisplayAddresses, // bool DisplayAddresses, // bool
DetachDatabases, // bool DetachDatabases, // bool
Language, // QString
OptionIDRowCount, OptionIDRowCount,
}; };
@ -45,11 +46,13 @@ public:
bool getMinimizeOnClose(); bool getMinimizeOnClose();
int getDisplayUnit(); int getDisplayUnit();
bool getDisplayAddresses(); bool getDisplayAddresses();
QString getLanguage() { return language; }
private: private:
int nDisplayUnit; int nDisplayUnit;
bool bDisplayAddresses; bool bDisplayAddresses;
bool fMinimizeToTray; bool fMinimizeToTray;
bool fMinimizeOnClose; bool fMinimizeOnClose;
QString language;
signals: signals:
void displayUnitChanged(int unit); void displayUnitChanged(int unit);

6
src/qt/qvaluecombobox.cpp

@ -6,12 +6,12 @@ QValueComboBox::QValueComboBox(QWidget *parent) :
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int))); connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
} }
int QValueComboBox::value() const QVariant QValueComboBox::value() const
{ {
return itemData(currentIndex(), role).toInt(); return itemData(currentIndex(), role);
} }
void QValueComboBox::setValue(int value) void QValueComboBox::setValue(const QVariant &value)
{ {
setCurrentIndex(findData(value, role)); setCurrentIndex(findData(value, role));
} }

9
src/qt/qvaluecombobox.h

@ -2,19 +2,20 @@
#define QVALUECOMBOBOX_H #define QVALUECOMBOBOX_H
#include <QComboBox> #include <QComboBox>
#include <QVariant>
/* QComboBox that can be used with QDataWidgetMapper to select ordinal values from a model. */ /* QComboBox that can be used with QDataWidgetMapper to select ordinal values from a model. */
class QValueComboBox : public QComboBox class QValueComboBox : public QComboBox
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged USER true)
public: public:
explicit QValueComboBox(QWidget *parent = 0); explicit QValueComboBox(QWidget *parent = 0);
int value() const; QVariant value() const;
void setValue(int value); void setValue(const QVariant &value);
/** Specify model role to use as ordinal value */ /** Specify model role to use as ordinal value (defaults to Qt::UserRole) */
void setRole(int role); void setRole(int role);
signals: signals:

Loading…
Cancel
Save