app.cpp Example File
invoketarget/src/app.cpp
#include "app.hpp"
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
using namespace bb::cascades;
using namespace bb::system;
App::App(QObject *parent)
: QObject(parent)
, m_invokeManager(new InvokeManager(this))
{
bool ok = connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)),
this, SLOT(handleInvoke(const bb::system::InvokeRequest&)));
Q_ASSERT(ok);
ok = connect(m_invokeManager,
SIGNAL(cardResizeRequested(const bb::system::CardResizeMessage&)),
this, SLOT(resized(const bb::system::CardResizeMessage&)));
Q_ASSERT(ok);
ok = connect(m_invokeManager,
SIGNAL(cardPooled(const bb::system::CardDoneMessage&)), this,
SLOT(pooled(const bb::system::CardDoneMessage&)));
Q_ASSERT(ok);
m_source = m_target = m_action = m_mimeType = m_uri = m_data = m_status =
tr("--");
switch (m_invokeManager->startupMode()) {
case ApplicationStartupMode::LaunchApplication:
m_startupMode = tr("Launch");
initFullUI();
break;
case ApplicationStartupMode::InvokeApplication:
m_startupMode = tr("Invoke");
break;
case ApplicationStartupMode::InvokeCard:
m_startupMode = tr("Card");
break;
}
}
void App::handleInvoke(const InvokeRequest& request) {
m_source =
QString::fromLatin1("%1 (%2)").arg(request.source().installId()).arg(
request.source().groupId());
m_target = request.target();
m_action = request.action();
m_mimeType = request.mimeType();
m_uri = request.uri().toString();
m_data = QString::fromUtf8(request.data());
if (m_target == "com.example.bb10samples.invocation.sharecomposer") {
initComposerUI();
} else if (m_target
== "com.example.bb10samples.invocation.imagepreviewer") {
initPreviewerUI();
} else if (m_target == "com.example.bb10samples.invocation.eggpicker") {
initPickerUI();
}
emit requestChanged();
}
void App::initFullUI() {
QmlDocument *qml = QmlDocument::create("asset:///main.qml");
qml->setContextProperty("_app", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(root);
}
void App::initComposerUI() {
QmlDocument *qml = QmlDocument::create("asset:///Composer.qml");
qml->setContextProperty("_app", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(root);
}
void App::initPreviewerUI() {
QmlDocument *qml = QmlDocument::create("asset:///Previewer.qml");
qml->setContextProperty("_app", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(root);
}
void App::initPickerUI() {
QmlDocument *qml = QmlDocument::create("asset:///Picker.qml");
qml->setContextProperty("_app", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(root);
}
void App::cardDone(const QString& msg) {
CardDoneMessage message;
message.setData(msg);
message.setDataType("text/plain");
message.setReason(tr("Success!"));
m_invokeManager->sendCardDone(message);
}
void App::resized(const bb::system::CardResizeMessage&) {
m_status = tr("Resized");
emit statusChanged();
}
void App::pooled(const bb::system::CardDoneMessage& doneMessage) {
m_status = tr("Pooled");
m_source = m_target = m_action = m_mimeType = m_uri = m_data = tr("--");
emit statusChanged();
emit requestChanged();
}
QString App::startupMode() const {
return m_startupMode;
}
QString App::source() const {
return m_source;
}
QString App::target() const {
return m_target;
}
QString App::action() const {
return m_action;
}
QString App::mimeType() const {
return m_mimeType;
}
QString App::uri() const {
return m_uri;
}
QString App::data() const {
return m_data;
}
QString App::status() const {
return m_status;
}