Profile.cpp Example File
bbmprofile/src/Profile.cpp
#include "Profile.hpp"
#include "ProfileEditor.hpp"
#include "RegistrationHandler.hpp"
#include <bb/ImageData>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/platform/bbm/Context>
using namespace bb::cascades;
Profile::Profile(bb::platform::bbm::Context &context, QObject *parent)
: QObject(parent)
, m_userProfile(0)
, m_context(&context)
, m_profileEditor(0)
{
m_displayPicture = bb::cascades::Image(QUrl("asset:///images/avatarPlaceholder.png"));
}
void Profile::show()
{
m_userProfile = new bb::platform::bbm::UserProfile(m_context, this);
m_profileEditor = new ProfileEditor(m_userProfile, this);
bool ok = connect(m_userProfile, SIGNAL(displayNameUpdated(QString)),
this, SIGNAL(profileChanged()));
Q_ASSERT(ok);
ok = connect(m_userProfile, SIGNAL(personalMessageUpdated(QString)),
this, SIGNAL(profileChanged()));
Q_ASSERT(ok);
ok = connect(m_userProfile, SIGNAL(statusUpdated(bb::platform::bbm::UserStatus::Type, QString)),
this, SIGNAL(profileChanged()));
Q_ASSERT(ok);
ok = connect(m_userProfile, SIGNAL(displayPictureUpdated(bb::platform::bbm::ImageType::Type, QByteArray)),
this, SIGNAL(profileChanged()));
Q_ASSERT(ok);
QmlDocument* qml = QmlDocument::create("asset:///profile.qml").parent(this);
qml->setContextProperty("_profile", this);
AbstractPane* root = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(root);
}
void Profile::requestDisplayPicture()
{
const QByteArray imageData = m_userProfile->displayPicture();
m_displayPicture = bb::cascades::Image(imageData);
emit profileChanged();
}
bool Profile::busy() const
{
return (m_userProfile->status() == bb::platform::bbm::UserStatus::Busy);
}
QString Profile::displayName() const
{
return m_userProfile->displayName();
}
QString Profile::statusMessage() const
{
return m_userProfile->statusMessage();
}
QString Profile::personalMessage() const
{
return m_userProfile->personalMessage();
}
QString Profile::ppid() const
{
return m_userProfile->ppId();
}
QString Profile::appVersion() const
{
return m_userProfile->applicationVersion();
}
QString Profile::handle() const
{
return m_userProfile->handle();
}
QString Profile::platformVersion() const
{
return QString::number(m_userProfile->sdkVersion());
}
QVariant Profile::displayPicture() const
{
return QVariant::fromValue(m_displayPicture);
}
ProfileEditor* Profile::editor() const
{
return m_profileEditor;
}