×
Namespaces

Variants
Actions
(Difference between revisions)

QML SMShelper Plugin

From Nokia Developer Wiki
Jump to: navigation, search
jahartik (Talk | contribs)
(Created page with 'Category:Qt MobilityCategory:Qt Quick __NOTOC__ __NOEDITSECTION__ {{CodeSnippet |id=... |platform=... |devices=... |category=... |subcategory=... |creationdate=... |keywo…')
 
kpakarin (Talk | contribs)
Line 19: Line 19:
 
==Overview==
 
==Overview==
  
{{Abstract|An abstract (line or paragraph) describing very briefly what the article delivers - for example "This article defines the standard boilerplate text for a new code example"}}
+
SMSplugin to expose Qt mobility SMS apis to Qml environment
  
''Delete the texts that do not apply.''
+
This snippet can be self-signed.  
  
This snippet can be self-signed.
+
==Preconditions==
  
[or]
+
Qt 4.7.1 or newer and Qt mobility 1.1.0 or newer installed
  
This snippet requires XXX capabilities. Self-signing is not possible because a Developer Certificate is needed.
+
==Pro file==
  
[or]
+
The following capabilities are required:
  
This snippets requires XXX capabilities. Self-signing is not possible because a Developer Certificate, Publisher ID, and device manufacturer approval are required.
+
CAPABILITY: symbian:TARGET.CAPABILITY = NetworkServices
  
 +
<code> code </code>
  
==Preconditions==
+
==Header file==
  
''In complex cases you may need to provide information on the framework needed in order to implement and use the code snippet. For example, a Bluetooth connection must be established in order to use the code snippet "send a file via Bluetooth OBEX". You can refer to an already existing code example.''
+
smshelper.h applying this macro to definitions of member functions to allow them to be invoked via the meta-object system
  
 +
<code>
 +
#ifndef SMSHELPER_H
 +
#define SMSHELPER_H
  
==MMP file (optional)==
+
#include <QObject>
 +
#include <qmessage.h>
 +
#include <qmessageservice.h>
  
The following capabilities and libraries are required:
+
QTM_USE_NAMESPACE
  
CAPABILITY     
 
  
 +
#ifdef Q_OS_SYMBIAN
 +
#  define SENDSMS_ENABLED
 +
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
 +
#  define SENDSMS_ENABLED
 +
#endif
  
LIBRARY         
+
class SMSHelper : public QObject
 +
{
 +
    Q_OBJECT
  
LIBRARY        
+
public:
 +
    explicit SMSHelper(QObject *parent = 0);
 +
    ~SMSHelper();
  
<code> code </code>
+
    Q_INVOKABLE bool sendsms(QString phonenumber, QString message);
  
==Header file==
+
signals:
 +
    void stateMsg(const QString &statemsg);
 +
    void errorMsg(const QString &errormsg);
 +
    void debugMsg(const QString &dbgmsg);
  
''Not the complete file but relevant code blocks.''
+
private slots:
 +
    void messageStateChanged(QMessageService::State s);
 +
#ifndef SENDSMS_ENABLED
 +
    void signalFinishedState() { emit stateMsg("FinishedState");};
 +
#endif
 +
private:
 +
    QMessageService iMessageService;
 +
    QMessageManager iManager;
 +
    QMessageService::State state;
  
<code> code </code>  
+
 
 +
};
 +
 
 +
#endif // SMSHELPER_H
 +
 
 +
</code>  
  
  
 
==Source file==
 
==Source file==
  
''Not the complete file but relevant code blocks.''
+
smshelper source code  
 +
<code>
 +
#include "smshelper.h"
  
''You do not need to provide complete error handling but it should be commented as TODO for developers.''
+
#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));
 +
    }
 +
}
  
<code> code </code>
 
  
 +
</code>
  
 
==Postconditions==  
 
==Postconditions==  

Revision as of 12:43, 29 April 2011


Article Metadata
Tested with
Devices(s): ...
Compatibility
Platform(s): ...
Article
Keywords: ...
Created: (19 Apr 2014)
Last edited: kpakarin (29 Apr 2011)



Delete the guidance text written in italics.

Overview

SMSplugin to expose Qt mobility SMS apis to Qml environment

This snippet can be self-signed.

Preconditions

Qt 4.7.1 or newer and Qt mobility 1.1.0 or newer installed

Pro file

The following capabilities are required:

CAPABILITY: symbian:TARGET.CAPABILITY = NetworkServices

 code

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));
}
}

Postconditions

Explain what the code snippet is expected to do.


Test application and other attachments (optional)

The attachments should be provided with the visible info page (Categories need to be defined, the attached file must be uploaded to Wiki, and internal Wiki links must be used). Every attachment should have its own page (however, a ZIP package can be used for multiple source code files).

86 page views in the last 30 days.