Make your App Social with BBM, Part II

IMG_00000016This is @leaschnherr again, with the second part, where I describe how to modify your BBM Profile via an app. For that the app need to be registered at BBM. A description of the necessary steps can you find here in the first part of this series. To get access to the profile and change it, it is the same procedure for each parameter. Some parameters can only be read but not be overwritten. The status, personal message and the picture can be changed by an extern app. Therefore I show you the steps in an example, which can be duplicated for all parameters.

Before starting with the C++ code, we create two simple qml files. The first only shows your current Profile parameters. In this sample we only use the displayed name, the status message and the busy flag. Here is some qml code which you can use as pattern:

Important are only the visible property of the ImageView and the text properties of the Name Label and the status Message Label. In these lines you get the current values from the profile. Later it doesn’t matter which source change the values, the properties are updated automatically via  _profile, which comes from the C++ code and is explained later.

Important is also, that the whole page is wrapped by a navigationPane, cause we use an action item to push the second qml file. Therefore don’t forget to attach the other qml file (called update.qml).

The second qml file is used to change the profile datas:

A CheckBox is used to modify the busy flag and a TextField for the status message. It looks very similar to the profile.qml, but additionally a button is used to save the new values. This button uses the onClicked signal to call a method with the properties as input parameters  (This method is declared later). The second line in this signal ensures the jump back to the profile.qml.

After preparing the qml files only a few lines of code are required.  In the Profile.hpp macros are used to automatically change the displayed parameters:

The first value is always the parameter, which is called out of the qml file. The next parameter, after READ, is the associated getFunction to returns the variable  (need to be defined in your class). The last parameter, after NOTIFY, use the signal profileChanged() signal, which must be declared in this header file as public signal. This construction now automatically updates the properties in the qml file when the variable in the c++ code changed.  We only have to use the profileChanged() signal.

In the first part of this series a slot showProfile() was used. This is the point the new profile.qml is inserted:

The class UserProfile is a private variable of our class which includes the current BBM profile. The next lines are very important: Here we call our signal profileChanged() when the parameters we use are updated in the BBM profile, so that our displayed datas are changed. Next the UI is created. Here we give the pointer of our class to the QmlDocument. Now the class is known as  _profile in the qml file, which already is used, as you see.

The save button in the update.qml uses a slot which need to be declared as public slot:

Here the value from the input is compared with old value and, in case, a request to change the value is send. The comparison looks a little complicated, because before the profile actually is changed the user has to accept this in a message box, which appears out from the UserProfile class. To avoid the message box if the user changed nothing, the if-construction checks all possible combinations. The parameters are now changed in both, the BBM Profile and the app.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">