smshelper.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /********************************************************************************************
  2. ** Copyright © 2011 Nokia Corporation. All rights reserved.
  3. ** Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
  4. ** Java and all Java-based marks are trademarks or registered trademarks of
  5. ** Sun Microsystems, Inc. Other product and company names mentioned herein may be
  6. ** trademarks or trade names of their respective owners.
  7. **
  8. ** Subject to the conditions below, you may, without charge:
  9. **
  10. ** · Use, copy, modify and/or merge copies of this software and
  11. ** associated content and documentation files (the “Software”)
  12. **
  13. ** · Publish, distribute, sub-licence and/or sell new software
  14. ** derived from or incorporating the Software.
  15. **
  16. ** Some of the documentation, content and/or software maybe licensed under open source
  17. ** software or other licenses. To the extent such documentation, content and/or
  18. ** software are included, licenses and/or other terms and conditions shall apply
  19. ** in addition and/or instead of this notice. The exact terms of the licenses, disclaimers,
  20. ** acknowledgements and notices are reproduced in the materials provided.
  21. **
  22. ** This file, unmodified, shall be included with all copies or substantial portions
  23. ** of the Software that are distributed in source code form.
  24. **
  25. ** The Software cannot constitute the primary value of any new software derived
  26. ** from or incorporating the Software.
  27. **
  28. ** Any person dealing with the Software shall not misrepresent the source of the Software.
  29. **
  30. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  31. ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  32. ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  33. ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  34. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  35. ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. ********************************************************************************************/
  37. #include "smshelper.h"
  38. #ifndef SENDSMS_ENABLED
  39. #include <QTimer>
  40. #endif
  41. SMSHelper::SMSHelper(QObject *parent) :
  42. QObject(parent)
  43. {
  44. state = QMessageService::InactiveState;
  45. connect(&iMessageService, SIGNAL(stateChanged(QMessageService::State)), this, SLOT(messageStateChanged(QMessageService::State)));
  46. }
  47. SMSHelper::~SMSHelper()
  48. {
  49. }
  50. bool SMSHelper::sendsms(QString phonenumber, QString message)
  51. {
  52. #ifdef SENDSMS_ENABLED
  53. if (!QMessageAccount::defaultAccount(QMessage::Sms).isValid())
  54. {
  55. emit errorMsg("No messageaccount for sms sending.");
  56. return false;
  57. }
  58. if (state == QMessageService::InactiveState || state == QMessageService::FinishedState)
  59. {
  60. QMessage sms;
  61. sms.setType(QMessage::Sms);
  62. sms.setParentAccountId(QMessageAccount::defaultAccount(QMessage::Sms));
  63. sms.setTo(QMessageAddress(QMessageAddress::Phone, phonenumber));
  64. sms.setBody(message);
  65. return iMessageService.send(sms);
  66. }
  67. else
  68. {
  69. return false;
  70. }
  71. #else
  72. QTimer::singleShot(1000,this,SLOT(signalFinishedState()));
  73. return true;
  74. #endif
  75. }
  76. void SMSHelper::messageStateChanged(QMessageService::State s)
  77. {
  78. state = s;
  79. if (s == QMessageService::InactiveState)
  80. {
  81. emit stateMsg("InactiveState");
  82. }
  83. else if (s == QMessageService::ActiveState)
  84. {
  85. emit stateMsg("ActiveState");
  86. }
  87. else if (s == QMessageService::CanceledState)
  88. {
  89. emit stateMsg("CanceledState");
  90. }
  91. else if (s == QMessageService::FinishedState)
  92. {
  93. emit stateMsg("FinishedState");
  94. }
  95. else
  96. {
  97. emit stateMsg(QString("QMessageService::%1").arg(s));
  98. }
  99. }