--- /dev/null
+#include <QtDebug>
+#include "sendsmssession.h"
+
+SendSMSSession::SendSMSSession( bool sync, QObject *parent ) :
+ QObject(parent)
+{
+ syncSend = sync;
+ isReady = false;
+ tps = NULL;
+}
+
+void SendSMSSession::initTpSession()
+{
+ qDebug() << __PRETTY_FUNCTION__ ;
+
+ if( tps == NULL )
+ {
+ tps = new TpSession( "ring", syncSend );
+
+ if( !isReady && !syncSend )
+ {
+ connect(tps,SIGNAL(accountReady(TpSessionAccount *)),SLOT(onAccountReady(TpSessionAccount *)));
+ }else
+ {
+ SendSMS();
+ }
+
+ connect(tps,SIGNAL(messageSent(const Tp::Message &,TpSessionAccount *)),
+ SLOT(onSMSSent(const Tp::Message &,TpSessionAccount *)));
+
+ connect(tps,SIGNAL(messageReceived(const Tp::ReceivedMessage &,TpSessionAccount *)),
+ SLOT(onMessageReceived(const Tp::ReceivedMessage &,TpSessionAccount *)));
+ }else
+ {
+ if( !isReady && !syncSend )
+ {
+ connect(tps,SIGNAL(accountReady(TpSessionAccount *)),SLOT(onAccountReady(TpSessionAccount *)));
+ }else
+ {
+ SendSMS();
+ }
+ }
+}
+
+void SendSMSSession::setSMSToSend(QString addr, QString msg)
+{
+ qDebug() << __PRETTY_FUNCTION__ ;
+ addresses.append( addr );
+ messages.append( msg );
+
+ initTpSession();
+}
+
+void SendSMSSession::setSMSToSend( QStringList addrs, QStringList msgs )
+{
+ qDebug() << __PRETTY_FUNCTION__ ;
+ addresses = addrs ;
+ messages = msgs ;
+
+ initTpSession();
+}
+
+void SendSMSSession::SendSMS()
+{
+ qDebug() << __PRETTY_FUNCTION__ ;
+ for( int i = 0; i < addresses.size(); i++ )
+ {
+ tps->sendMessageToAddress( "ring", addresses.at(i), messages.at(i) );
+ }
+ addresses.clear();
+ messages.clear();
+}
+
+void SendSMSSession::onAccountReady(TpSessionAccount *tpsa)
+{
+ qDebug() << __PRETTY_FUNCTION__ ;
+
+ isReady = true;
+ for( int i = 0; i < addresses.size(); i++ )
+ {
+ tpsa->sendMessageToAddress( addresses.at(i), messages.at(i) );
+ }
+ addresses.clear();
+ messages.clear();
+}
+
+void SendSMSSession::onSMSSent( const Tp::Message &msg, TpSessionAccount *acc )
+{
+ qDebug() << "SendSMSSession::onSMSSent :" << msg.text();
+ Q_EMIT smsSent( msg.text() );
+}
+
+void SendSMSSession::onMessageReceived(const Tp::ReceivedMessage &msg,TpSessionAccount *acc)
+{
+ qDebug() << "SendSMSSession::onMessageReceived " << msg.text() << "from " << msg.sender()->id();
+}
+
+