applicationui.cpp Example File
xandos/src/applicationui.cpp
#include "applicationui.hpp"
#include "xandos.hpp"
#include "droidlistener.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/LocaleHandler>
using namespace bb::cascades;
ApplicationUI::ApplicationUI(bb::cascades::Application *app)
: QObject(app)
{
m_pTranslator = new QTranslator(this);
m_pLocaleHandler = new LocaleHandler(this);
bool ok = connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this,
SLOT(onSystemLanguageChanged()));
Q_ASSERT(ok);
onSystemLanguageChanged();
xandos *tac = new xandos(app, this);
droidlistener *listener = new droidlistener(this);
ok = connect(listener, SIGNAL(droidSelection(const QString)), tac, SLOT(droidSelection(const QString)));
Q_ASSERT(ok);
ok = connect(tac, SIGNAL(sendSelection(const int)), listener, SLOT(readyWrite(const int)));
Q_ASSERT(ok);
Q_UNUSED(ok);
listener->listen();
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
qml->setContextProperty("_xandos", tac);
app->setScene(root);
}
void ApplicationUI::onSystemLanguageChanged()
{
QCoreApplication::instance()->removeTranslator(m_pTranslator);
QString locale_string = QLocale().name();
QString file_name = QString("tictactoe_%1").arg(locale_string);
if (m_pTranslator->load(file_name, "app/native/qm")) {
QCoreApplication::instance()->installTranslator(m_pTranslator);
}
}