app.cpp Example File
invocation/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))
, m_backButtonVisible(false)
{
connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)), this, SLOT(handleInvoke(const bb::system::InvokeRequest&)));
connect(m_invokeManager, SIGNAL(cardResizeRequested(const bb::system::CardResizeMessage&)), this, SLOT(resized(const bb::system::CardResizeMessage&)));
connect(m_invokeManager, SIGNAL(cardPooled(const bb::system::CardDoneMessage&)), this, SLOT(pooled(const bb::system::CardDoneMessage&)));
switch (m_invokeManager->startupMode()) {
case ApplicationStartupMode::LaunchApplication:
m_startupMode = tr("Launch");
break;
case ApplicationStartupMode::InvokeApplication:
m_startupMode = tr("Invoke");
break;
case ApplicationStartupMode::InvokeViewer:
m_startupMode = tr("Viewer");
break;
case ApplicationStartupMode::InvokeCard:
m_startupMode = tr("Card");
break;
}
m_source = m_target = m_action = m_mimeType = m_uri = m_data = m_status = tr("--");
m_title = tr("InvokeClient");
QmlDocument *qml = QmlDocument::create("asset:///main.qml");
qml->setContextProperty("_app", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(root);
}
void App::cardDone()
{
CardDoneMessage message;
message.setData(tr("Card: I am done. yay!"));
message.setDataType("text/plain");
message.setReason(tr("Success!"));
m_invokeManager->sendCardDone(message);
}
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());
m_backButtonVisible = false;
if (m_target == "com.example.bb10samples.invocation.openimage1") {
m_title = tr("Open Image 1");
} else if (m_target == "com.example.bb10samples.invocation.openimage2") {
m_title = tr("Open Image 2");
} else if (m_target == "com.example.bb10samples.invocation.card.previewer") {
m_title = tr("Previewer");
m_backButtonVisible = true;
} else if (m_target == "com.example.bb10samples.invocation.card.composer") {
m_title = tr("Composer");
} else if (m_target == "com.example.bb10samples.invocation.card.picker") {
m_title = tr("Picker");
}
emit requestChanged();
}
void App::resized(const bb::system::CardResizeMessage&)
{
m_status = tr("Resized");
emit statusChanged();
}
void App::pooled(const bb::system::CardDoneMessage&)
{
m_status = tr("Pooled");
emit statusChanged();
}
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;
}
QString App::title() const
{
return m_title;
}
bool App::backButtonVisible() const
{
return m_backButtonVisible;
}