RegistrationHandler.cpp Example File
bbmregistration/src/RegistrationHandler.cpp
#include "RegistrationHandler.hpp"
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/system/SystemDialog>
#include <bb/platform/bbm/Context>
#include <bb/platform/bbm/RegistrationState>
using namespace bb::cascades;
using namespace bb::platform::bbm;
using namespace bb::system;
RegistrationHandler::RegistrationHandler(const QUuid &uuid, QObject *parent)
: QObject(parent)
, m_context(uuid)
, m_isAllowed(false)
, m_progress(BbmRegistrationProgress::NotStarted)
, m_temporaryError(false)
, m_statusMessage(tr("Please wait while the application connects to BBM."))
{
QmlDocument* qml = QmlDocument::create("asset:///registration.qml")
.parent(this);
qml->setContextProperty("_registrationHandler", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(root);
bool ok = false;
if (uuid.isNull()) {
SystemDialog *uuidDialog = new SystemDialog("OK");
uuidDialog->setTitle("UUID Error");
uuidDialog->setBody("Invalid/Empty UUID, please set correctly in main.cpp");
ok = connect(uuidDialog, SIGNAL(finished(bb::system::SystemUiResult::Type)), this, SLOT(dialogFinished(bb::system::SystemUiResult::Type)));
Q_ASSERT(ok);
uuidDialog->show();
return;
}
ok = connect(&m_context,
SIGNAL(registrationStateUpdated(
bb::platform::bbm::RegistrationState::Type)),
this,
SLOT(processRegistrationStatus(
bb::platform::bbm::RegistrationState::Type)));
Q_ASSERT(ok);
}
void RegistrationHandler::registerApplication()
{
m_progress = BbmRegistrationProgress::Started;
processRegistrationStatus(m_context.registrationState());
}
void RegistrationHandler::processRegistrationStatus(const RegistrationState::Type state)
{
qDebug() << "Received a BBM Social Platform registration access state="
<< state;
switch(m_progress)
{
case BbmRegistrationProgress::Pending:
if (state != RegistrationState::Pending) {
registrationFinished();
return;
}
break;
case BbmRegistrationProgress::Started:
if (m_context.isAccessAllowed()) {
registrationFinished();
return;
}
if (m_context.registrationState() == RegistrationState::Unknown) {
qDebug() << "BBM Social Platform access state is UNKNOWN; waiting "
"for the initial status";
return;
}
if (m_context.requestRegisterApplication()) {
m_progress = BbmRegistrationProgress::Pending;
qDebug() << "BBM Social Platform registration started";
qDebug() << "Verify you are using a valid UUID";
return;
}
qDebug() << "BBM Social Platform registration could not be started";
registrationFinished();
break;
case BbmRegistrationProgress::Finished:
if (m_context.isAccessAllowed() != m_isAllowed) {
registrationFinished();
}
break;
default:
qDebug() << "Ignoring BBM Social Platform access state=" << state
<< "when progress=" << m_progress;
break;
}
}
void RegistrationHandler::registrationFinished()
{
m_progress = BbmRegistrationProgress::Finished;
switch (m_context.registrationState()) {
case RegistrationState::Allowed:
m_statusMessage = tr("Application connected to BBM. Press Continue.");
m_temporaryError = false;
break;
case RegistrationState::BlockedByRIM:
m_statusMessage = tr("Disconnected by RIM. RIM is preventing this "
"application from connecting to BBM.");
m_temporaryError = false;
break;
case RegistrationState::BlockedByUser:
m_statusMessage = tr("Disconnected. Go to Settings -> Security and "
"Privacy -> Application Permissions and "
"connect this application to BBM.");
m_temporaryError = false;
break;
case RegistrationState::InvalidUuid:
m_statusMessage = tr("Invalid UUID. Report this error to the "
"vendor.");
m_temporaryError = true;
break;
case RegistrationState::MaxAppsReached:
m_statusMessage = tr("Too many applications are connected to BBM. "
"Uninstall one or more applications and try "
"again.");
m_temporaryError = false;
break;
case RegistrationState::Expired:
case RegistrationState::MaxDownloadsReached:
m_statusMessage = tr("Cannot connect to BBM. Download this "
"application from AppWorld to keep using it.");
m_temporaryError = false;
break;
case RegistrationState::NoDataConnection:
m_statusMessage = tr("Check your Internet connection and try again.");
m_temporaryError = true;
break;
case RegistrationState::Pending:
m_statusMessage = tr("Connecting to BBM. Please wait.");
m_temporaryError = false;
break;
case RegistrationState::Unknown:
m_statusMessage = tr("Determining the status. Please wait.");
m_temporaryError = false;
break;
case RegistrationState::Unregistered:
case RegistrationState::UnexpectedError:
case RegistrationState::TemporaryError:
case RegistrationState::CancelledByUser:
default:
m_statusMessage = tr("Would you like to connect the application to "
"BBM?");
m_temporaryError = true;
break;
}
if (m_context.isAccessAllowed()) {
m_isAllowed = true;
} else {
m_isAllowed = false;
}
qDebug() << "Finished BBM Social Platform registration, success="
<< m_isAllowed << "temporaryError=" << m_temporaryError;
emit stateChanged();
}
void RegistrationHandler::dialogFinished(bb::system::SystemUiResult::Type value) {
Application::exit(-1);
}