QML SMShelper Plugin
somnathbanik
(Talk | contribs) |
|||
| Line 6: | Line 6: | ||
|platform=Symbian 3 | |platform=Symbian 3 | ||
|devices=N8, E7, C7 | |devices=N8, E7, C7 | ||
| − | |category= | + | |category= Qt |
| − | |subcategory= | + | |subcategory= Messaging |
|creationdate=29.04.2011 | |creationdate=29.04.2011 | ||
|keywords=QML, SMS, Messaging | |keywords=QML, SMS, Messaging | ||
| Line 16: | Line 16: | ||
==Overview== | ==Overview== | ||
| − | SMSplugin to expose Qt mobility SMS apis to Qml environment | + | {{Abstract|SMSplugin to expose Qt mobility SMS apis to Qml environment}} |
This snippet can be self-signed. | This snippet can be self-signed. | ||
| Line 22: | Line 22: | ||
==Preconditions== | ==Preconditions== | ||
| − | Qt 4.7.1 or newer and Qt mobility 1.1.0 or newer installed | + | [http://qt.nokia.com/downloads Qt SDK]4.7.1 or newer and [http://qt.nokia.com/products/qt-addons/mobility Qt mobility] 1.1.0 or newer installed |
==Pro file== | ==Pro file== | ||
| Line 28: | Line 28: | ||
The following capabilities and libraries are required: | The following capabilities and libraries are required: | ||
| + | <code cpp> | ||
CAPABILITY | CAPABILITY | ||
| − | |||
symbian:TARGET.CAPABILITY = NetworkServices | symbian:TARGET.CAPABILITY = NetworkServices | ||
| − | |||
CONFIG += mobility | CONFIG += mobility | ||
| − | |||
MOBILITY = messaging | MOBILITY = messaging | ||
| − | + | </code> | |
==Header file== | ==Header file== | ||
| − | smshelper.h applying this macro to definitions of member functions to allow them to be invoked via the meta-object system | + | '''smshelper.h''' applying this macro to definitions of member functions to allow them to be invoked via the''' meta-object system''' |
| − | <code> | + | <code cpp> |
#ifndef SMSHELPER_H | #ifndef SMSHELPER_H | ||
#define SMSHELPER_H | #define SMSHELPER_H | ||
| Line 93: | Line 91: | ||
smshelper source code | smshelper source code | ||
| − | <code> | + | <code cpp> |
#include "smshelper.h" | #include "smshelper.h" | ||
| Line 180: | Line 178: | ||
To register the C++ type in the QML system with the name SMSHelper include following code in your main.cpp file | To register the C++ type in the QML system with the name SMSHelper include following code in your main.cpp file | ||
| − | <code> | + | <code cpp> |
qmlRegisterType<SMSHelper>("SMSHelper",1,0,"SMSHelper"); | qmlRegisterType<SMSHelper>("SMSHelper",1,0,"SMSHelper"); | ||
</code> | </code> | ||
Import sms plugin in QML | Import sms plugin in QML | ||
| − | <code> | + | <code cpp> |
import SMSHelper 1.0 | import SMSHelper 1.0 | ||
</code> | </code> | ||
Example use QML | Example use QML | ||
| − | <code> | + | <code cpp> |
SMSHelper | SMSHelper | ||
{ | { | ||
Revision as of 13:29, 29 April 2011
Article Metadata
Tested with
Devices(s): N8, E7, C7
Compatibility
Platform(s): Symbian 3
Article
Keywords: QML, SMS, Messaging
Created: (29 Apr 2011)
Last edited: somnathbanik
(29 Apr 2011)
Overview
SMSplugin to expose Qt mobility SMS apis to Qml environment
This snippet can be self-signed.
Preconditions
Qt SDK4.7.1 or newer and Qt mobility 1.1.0 or newer installed
Pro file
The following capabilities and libraries are required:
CAPABILITY
symbian:TARGET.CAPABILITY = NetworkServices
CONFIG += mobility
MOBILITY = messaging
Header file
smshelper.h applying this macro to definitions of member functions to allow them to be invoked via the meta-object system
#ifndef SMSHELPER_H
#define SMSHELPER_H
#include <QObject>
#include <qmessage.h>
#include <qmessageservice.h>
QTM_USE_NAMESPACE
#ifdef Q_OS_SYMBIAN
# define SENDSMS_ENABLED
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
# define SENDSMS_ENABLED
#endif
class SMSHelper : public QObject
{
Q_OBJECT
public:
explicit SMSHelper(QObject *parent = 0);
~SMSHelper();
Q_INVOKABLE bool sendsms(QString phonenumber, QString message);
signals:
void stateMsg(const QString &statemsg);
void errorMsg(const QString &errormsg);
void debugMsg(const QString &dbgmsg);
private slots:
void messageStateChanged(QMessageService::State s);
#ifndef SENDSMS_ENABLED
void signalFinishedState() { emit stateMsg("FinishedState");};
#endif
private:
QMessageService iMessageService;
QMessageManager iManager;
QMessageService::State state;
};
#endif // SMSHELPER_H
Source file
smshelper source code
#include "smshelper.h"
#ifndef SENDSMS_ENABLED
#include <QTimer>
#endif
SMSHelper::SMSHelper(QObject *parent) :
QObject(parent)
{
state = QMessageService::InactiveState;
connect(&iMessageService, SIGNAL(stateChanged(QMessageService::State)), this, SLOT(messageStateChanged(QMessageService::State)));
}
SMSHelper::~SMSHelper()
{
}
bool SMSHelper::sendsms(QString phonenumber, QString message)
{
#ifdef SENDSMS_ENABLED
if (!QMessageAccount::defaultAccount(QMessage::Sms).isValid())
{
emit errorMsg("No messageaccount for sms sending.");
return false;
}
if (state == QMessageService::InactiveState || state == QMessageService::FinishedState)
{
QMessage sms;
sms.setType(QMessage::Sms);
sms.setParentAccountId(QMessageAccount::defaultAccount(QMessage::Sms));
sms.setTo(QMessageAddress(QMessageAddress::Phone, phonenumber));
sms.setBody(message);
return iMessageService.send(sms);
}
else
{
return false;
}
#else
QTimer::singleShot(1000,this,SLOT(signalFinishedState()));
return true;
#endif
}
void SMSHelper::messageStateChanged(QMessageService::State s)
{
state = s;
if (s == QMessageService::InactiveState)
{
emit stateMsg("InactiveState");
}
else if (s == QMessageService::ActiveState)
{
emit stateMsg("ActiveState");
}
else if (s == QMessageService::CanceledState)
{
emit stateMsg("CanceledState");
}
else if (s == QMessageService::FinishedState)
{
emit stateMsg("FinishedState");
}
else
{
emit stateMsg(QString("QMessageService::%1").arg(s));
}
}
To register the C++ type in the QML system with the name SMSHelper include following code in your main.cpp file
qmlRegisterType<SMSHelper>("SMSHelper",1,0,"SMSHelper");
Import sms plugin in QML
import SMSHelper 1.0Example use QML
SMSHelper
{
id: smshelper
----
smshelper.sendsms(phone, message)

