Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kipr/botui
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcdorman committed Jan 8, 2015
2 parents 9cc9dec + e11652a commit 59f35f1
Show file tree
Hide file tree
Showing 5 changed files with 4,317 additions and 19 deletions.
13 changes: 8 additions & 5 deletions src/LanguageWidget.cpp
Expand Up @@ -12,11 +12,14 @@ LanguageWidget::LanguageWidget(Device *device, QWidget *const parent)
ui->setupUi(this);
performStandardSetup(tr("Language Widget"));

ui->languages->setModel(new LocaleModel(this));
QSettings settings;
QLocale current(settings.value("locale", "en").toString());
LocaleModel *localeModel = new LocaleModel(this);
ui->languages->setModel(localeModel);

const QString currLocale = QSettings().value("locale", "en").toString();
for(int i = 0; i < ui->languages->count(); ++i) {

if(localeModel->locale(localeModel->index(i, 0)).bcp47Name() != currLocale) continue;
ui->languages->setCurrentIndex(i);
break;
}
connect(ui->languages, SIGNAL(currentIndexChanged(int)), SLOT(currentIndexChanged(int)));
}
Expand All @@ -30,7 +33,7 @@ void LanguageWidget::currentIndexChanged(int index)
{
if(index < 0) return;
LocaleModel *model = qobject_cast<LocaleModel *>(ui->languages->model());
const QLocale locale = model->locale(ui->languages->rootModelIndex().child(index, 0));
const QLocale locale = model->locale(ui->languages->model()->index(index, 0));
QSettings settings;
settings.setValue("locale", locale.bcp47Name());
settings.sync();
Expand Down
7 changes: 2 additions & 5 deletions src/LocaleModel.cpp
Expand Up @@ -38,14 +38,11 @@ LocaleModel::LocaleModel(QObject *const parent)
: QStandardItemModel(parent)
{
QDir locales("/etc/botui/locale");

Q_FOREACH(const QFileInfo &localeFile, locales.entryInfoList(QDir::NoDot | QDir::NoDotDot
| QDir::Files)) {
Q_FOREACH(const QFileInfo &localeFile, locales.entryInfoList(QDir::NoDot | QDir::NoDotDot | QDir::Files)) {
const QString name = localeFile.baseName();
const int underline = name.indexOf("_");
if(!underline) continue;
const QString code = name.mid(underline + 1);
appendRow(new LocaleItem(QLocale(code)));
appendRow(new LocaleItem(QLocale(name.mid(underline + 1))));
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/main.cpp
Expand Up @@ -18,18 +18,18 @@
#include <QDir>

#include <QFontDatabase>
#include <QDebug>
#include <QSettings>
#include <QTranslator>

int main(int argc, char* argv[])
{
QSettings settings;
const QString localeString = settings.value("locale", "en").toString();
QLocale locale(localeString);
QLocale::setDefault(locale);

{
QApplication::setStyle(new MechanicalStyle);
QApplication app(argc, argv);

QTranslator translator;
const QString trFile = "link_" + QSettings().value("locale", "en").toString();
if(trFile != "en" && translator.load(trFile, "/etc/botui/locale/"))
app.installTranslator(&translator);

QDir::setCurrent(QApplication::applicationDirPath());
qmlRegisterType<BusyIndicator>("ZapBsComponents", 1, 0, "BusyIndicator");
Expand All @@ -48,7 +48,6 @@ int main(int argc, char* argv[])
#endif
GuiSettingsWidget::updateStyle(&device);
RootController::ref().presentWidget(new HomeWidget(&device));



return app.exec();
}

0 comments on commit 59f35f1

Please sign in to comment.