qvibra_p.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "qvibra_p.h"
  2. #include "qvibra.h"
  3. QVibraPrivate::QVibraPrivate(QVibra *aPublicAPI) :
  4. iPublicQVibra(aPublicAPI),
  5. iStatus(QVibra::StatusOff)
  6. {
  7. QObject::connect(&iTimer, SIGNAL(timeout()), iPublicQVibra, SLOT(stop()));
  8. }
  9. QVibraPrivate::~QVibraPrivate()
  10. {
  11. delete iVibra;
  12. }
  13. QVibraPrivate* QVibraPrivate::NewL(QVibra *aPublicAPI)
  14. {
  15. QVibraPrivate* self = new (ELeave) QVibraPrivate(aPublicAPI);
  16. CleanupStack::PushL(self);
  17. self->ConstructL();
  18. CleanupStack::Pop(self);
  19. return self;
  20. }
  21. void QVibraPrivate::ConstructL()
  22. {
  23. TRAP(iError, this->iVibra = CHWRMVibra::NewL();)
  24. }
  25. void QVibraPrivate::VibraModeChanged(CHWRMVibra::TVibraModeState aStatus)
  26. {
  27. /*
  28. EVibraModeUnknown Not initialized yet or there is an error condion.
  29. EVibraModeON Vibration setting in the user profile is on.
  30. EVibraModeOFF Vibration setting in the user profile is off.
  31. */
  32. }
  33. void QVibraPrivate::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus)
  34. {
  35. /*
  36. EVibraStatusUnknown Vibra is not initialized yet or status is uncertain because of an error condition.
  37. EVibraStatusNotAllowed Vibra is set off in the user profile or some application is specifically blocking vibra.
  38. EVibraStatusStopped Vibra is stopped.
  39. EVibraStatusOn Vibra is on.
  40. */
  41. if (aStatus == CHWRMVibra::EVibraStatusUnknown ||
  42. aStatus == CHWRMVibra::EVibraStatusNotAllowed) {
  43. iStatus = QVibra::StatusNotAllowed;
  44. emit this->iPublicQVibra->statusChanged(iStatus);
  45. }
  46. if (iDuration == QVibra::InfiniteDuration) {
  47. if (iStatus != QVibra::StatusOff) {
  48. iStatus = QVibra::StatusOff;
  49. emit this->iPublicQVibra->statusChanged(iStatus);
  50. }
  51. }
  52. }
  53. bool QVibraPrivate::start(int duration, int intensity)
  54. {
  55. //if( this->iVibra ) this->iVibra->StartVibraL(duration, intensity);
  56. if( this->iVibra ) {
  57. iDuration = duration;
  58. TRAP(iError,
  59. if (intensity == QVibra::DefaultIntensity) {
  60. iVibra->StartVibraL(QVibra::InfiniteDuration);
  61. } else {
  62. iVibra->StopVibraL();
  63. iVibra->StartVibraL(QVibra::InfiniteDuration, intensity);
  64. }
  65. if (duration != QVibra::InfiniteDuration) {
  66. iTimer.start(duration);
  67. } else {
  68. iTimer.stop();
  69. }
  70. if (iStatus != QVibra::StatusOn) {
  71. iStatus = QVibra::StatusOn;
  72. emit this->iPublicQVibra->statusChanged(iStatus);
  73. }
  74. )
  75. return (iError == KErrNone);
  76. }
  77. }
  78. bool QVibraPrivate::stop()
  79. {
  80. if( this->iVibra ) this->iVibra->StopVibraL();
  81. }
  82. void QVibraPrivate::reserve()
  83. {
  84. if( this->iVibra ) this->iVibra->ReserveVibraL();
  85. }
  86. void QVibraPrivate::release()
  87. {
  88. if( this->iVibra ) this->iVibra->ReleaseVibra();
  89. }
  90. QVibra::Status QVibraPrivate::currentStatus() const
  91. {
  92. if( iVibra->VibraStatus() == CHWRMVibra::EVibraStatusUnknown ||
  93. iVibra->VibraStatus() == CHWRMVibra::EVibraStatusNotAllowed) {
  94. return QVibra::StatusNotAllowed;
  95. }
  96. return iStatus;
  97. }
  98. QVibra::Error QVibraPrivate::error() const
  99. {
  100. switch (iError) {
  101. case KErrNone:
  102. return QVibra::NoError;
  103. case KErrNoMemory:
  104. return QVibra::OutOfMemoryError;
  105. case KErrArgument:
  106. return QVibra::ArgumentError;
  107. case KErrInUse:
  108. return QVibra::VibraInUseError;
  109. case KErrGeneral:
  110. return QVibra::HardwareError;
  111. case KErrTimedOut:
  112. return QVibra::TimeOutError;
  113. case KErrLocked:
  114. return QVibra::VibraLockedError;
  115. case KErrAccessDenied:
  116. return QVibra::AccessDeniedError;
  117. default:
  118. return QVibra::UnknownError;
  119. }
  120. }