Skip to content

Commit

Permalink
Added language setting menu. #312
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulEU committed Apr 12, 2014
1 parent a632f84 commit 2841269
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 3 deletions.
16 changes: 13 additions & 3 deletions KeyhoteeApplication.cpp
Expand Up @@ -314,10 +314,20 @@ int TKeyhoteeApplication::run()
setOrganizationName("Invictus Innovations, Inc");
setApplicationName(APP_NAME);

QString locale = QLocale::system().name();
QSettings settings("Invictus Innovations", "Keyhotee");
QString locale = settings.value("Language", "").toString();

/// If empty set default system locale
if (locale.isEmpty())
{
locale = QLocale::system().name();
settings.setValue("Language", locale);
}

QTranslator translator;
translator.load(QString(":/keyhotee_")+locale);
installTranslator(&translator);
bool loadOk = translator.load(QString(":/keyhotee_") + locale);
if (loadOk)
installTranslator(&translator);

if(_loaded_profile_name.isEmpty())
{
Expand Down
59 changes: 59 additions & 0 deletions KeyhoteeMainWindow.cpp
Expand Up @@ -27,6 +27,7 @@
#include <fc/log/logger.hpp>

/// QT headers:
#include <QAction>
#include <QCompleter>
#include <QLabel>
#include <QLineEdit>
Expand Down Expand Up @@ -69,6 +70,8 @@ KeyhoteeMainWindow::KeyhoteeMainWindow(const TKeyhoteeApplication& mainApp) :
ui = new Ui::KeyhoteeMainWindow;
ui->setupUi(this);

initMenuLanguage();

QString profileName = mainApp.getLoadedProfileName();

QString title = QString("%1 v%2 (%3)").arg(mainApp.getAppName().c_str()).arg(mainApp.getVersionNumberString().c_str()).arg(profileName);
Expand Down Expand Up @@ -147,6 +150,8 @@ KeyhoteeMainWindow::KeyhoteeMainWindow(const TKeyhoteeApplication& mainApp) :
connect(ui->actionShow_Contacts, &QAction::triggered, this, &KeyhoteeMainWindow::showContacts);
connect(ui->actionRequest_authorization, &QAction::triggered, this, &KeyhoteeMainWindow::onRequestAuthorization);
connect(ui->actionShare_contact, &QAction::triggered, this, &KeyhoteeMainWindow::onShareContact);
// Language
connect(ui->menuLanguage, SIGNAL(triggered(QAction*)), this, SLOT(onLanguageChanged(QAction*)));
// Help
connect(ui->actionDiagnostic, &QAction::triggered, this, &KeyhoteeMainWindow::onDiagnostic);
connect(ui->actionAbout, &QAction::triggered, this, &KeyhoteeMainWindow::onAbout);
Expand Down Expand Up @@ -1358,3 +1363,57 @@ void KeyhoteeMainWindow::onShareContact()
assert(contacts.size());
shareContact(contacts);
}


void KeyhoteeMainWindow::initMenuLanguage()
{
_actionsLang.push_back(ui->actionChinese);
ui->actionChinese->setData(QLocale(QLocale::Chinese, QLocale::China).name());

_actionsLang.push_back(ui->actionEnglish);
ui->actionEnglish->setData(QLocale(QLocale::English, QLocale::UnitedStates).name());

_actionsLang.push_back(ui->actionPolish);
ui->actionPolish->setData(QLocale(QLocale::Polish, QLocale::Poland).name());

_actionsLang.push_back(ui->actionPortuguese);
ui->actionPortuguese->setData(QLocale(QLocale::Portuguese, QLocale::Portugal).name());

_actionsLang.push_back(ui->actionSpanish);
ui->actionSpanish->setData(QLocale(QLocale::Spanish, QLocale::AnyCountry).name());

_actionsLang.push_back(ui->actionSpanish_Chile);
ui->actionSpanish_Chile->setData(QLocale(QLocale::Spanish, QLocale::Chile).name());

QSettings settings("Invictus Innovations", "Keyhotee");
QString locale = settings.value("Language", "").toString();
/// Set checked language action
for (const auto& v : _actionsLang)
{
if (locale == v->data().toString())
{
v->setChecked(true);
return;
}
}
/// If not found language set english action
ui->actionEnglish->setChecked(true);
return;
}

void KeyhoteeMainWindow::onLanguageChanged(QAction* langAction)
{
QString localeName = langAction->data().toString();

/// Clear checked state for all languages
for (const auto& v : _actionsLang)
v->setChecked(false);

langAction->setChecked(true);

QSettings settings("Invictus Innovations", "Keyhotee");
settings.setValue("Language", localeName);

QMessageBox::information(this, tr("Change language"),
tr("Please restart application for the changes to take effect") );
}
5 changes: 5 additions & 0 deletions KeyhoteeMainWindow.hpp
Expand Up @@ -34,6 +34,7 @@ class MenuEditControl;
class KeyhoteeMainWindow;
class TKeyhoteeApplication;

class QAction;
class QCompleter;
class QLineEdit;
class QTreeWidgetItem;
Expand Down Expand Up @@ -144,6 +145,8 @@ private slots:
void onSetIcon();
void onRequestAuthorization();
void onShareContact();
// Language
void onLanguageChanged(QAction*);
// Help
void onDiagnostic();
void onAbout();
Expand Down Expand Up @@ -190,6 +193,7 @@ private slots:
void addContact();
void processResponse(const TAuthorizationMessage& msg, const TStoredMailMessage& header);
void loadStoredRequests(bts::bitchat::message_db_ptr request_db);
void initMenuLanguage();

/// Class attributes:

Expand Down Expand Up @@ -224,6 +228,7 @@ private slots:
QList <Mailbox*> _mailboxesList;
/// Set to true when close event processing is in progress (it wasn't yet accepted nor ignored)
bool _isClosing;
QList <QAction*> _actionsLang;
}; //KeyhoteeMainWindow

KeyhoteeMainWindow* getKeyhoteeWindow();
65 changes: 65 additions & 0 deletions KeyhoteeMainWindow.ui
Expand Up @@ -458,11 +458,23 @@
<string>Window</string>
</property>
</widget>
<widget class="QMenu" name="menuLanguage">
<property name="title">
<string>Language</string>
</property>
<addaction name="actionChinese"/>
<addaction name="actionEnglish"/>
<addaction name="actionPolish"/>
<addaction name="actionPortuguese"/>
<addaction name="actionSpanish"/>
<addaction name="actionSpanish_Chile"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuIdentity"/>
<addaction name="menuMail"/>
<addaction name="menuContact"/>
<addaction name="menuLanguage"/>
<addaction name="menuWindow"/>
<addaction name="menuHelp"/>
</widget>
Expand Down Expand Up @@ -700,6 +712,59 @@
<string>Share contact...</string>
</property>
</action>
<action name="actionLanguage">
<property name="text">
<string>Language</string>
</property>
</action>
<action name="actionPolish">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Polish</string>
</property>
</action>
<action name="actionEnglish">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>English</string>
</property>
</action>
<action name="actionPortuguese">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Portuguese</string>
</property>
</action>
<action name="actionChinese">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Chinese</string>
</property>
</action>
<action name="actionSpanish">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Spanish</string>
</property>
</action>
<action name="actionSpanish_Chile">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Spanish (Chile)</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
File renamed without changes.

0 comments on commit 2841269

Please sign in to comment.