tools/qml/deviceorientation_symbian.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    50 class SymbianOrientation : public DeviceOrientation, public MSensrvDataListener
    50 class SymbianOrientation : public DeviceOrientation, public MSensrvDataListener
    51 {
    51 {
    52     Q_OBJECT
    52     Q_OBJECT
    53 public:
    53 public:
    54     SymbianOrientation()
    54     SymbianOrientation()
    55         : DeviceOrientation(), m_current(UnknownOrientation), m_sensorChannel(0)
    55         : DeviceOrientation(), m_current(UnknownOrientation), m_sensorChannel(0), m_channelOpen(false)
    56     {
    56     {
    57         TRAP_IGNORE(initL());
    57         TRAP_IGNORE(initL());
    58         if (!m_sensorChannel)
    58         if (!m_sensorChannel)
    59             qWarning("No valid sensors found.");
    59             qWarning("No valid sensors found.");
    60     }
    60     }
    82             TRAPD(error, m_sensorChannel = CSensrvChannel::NewL(channelInfoList[i]));
    82             TRAPD(error, m_sensorChannel = CSensrvChannel::NewL(channelInfoList[i]));
    83             if (!error)
    83             if (!error)
    84                 TRAP(error, m_sensorChannel->OpenChannelL());
    84                 TRAP(error, m_sensorChannel->OpenChannelL());
    85             if (!error) {
    85             if (!error) {
    86                 TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
    86                 TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
       
    87                 m_channelOpen = true;
    87                 break;
    88                 break;
    88            }
    89            }
    89             if (error) {
    90             if (error) {
    90                 delete m_sensorChannel;
    91                 delete m_sensorChannel;
    91                 m_sensorChannel = 0;
    92                 m_sensorChannel = 0;
   105    void setOrientation(Orientation) { }
   106    void setOrientation(Orientation) { }
   106 
   107 
   107 private:
   108 private:
   108     DeviceOrientation::Orientation m_current;
   109     DeviceOrientation::Orientation m_current;
   109     CSensrvChannel *m_sensorChannel;
   110     CSensrvChannel *m_sensorChannel;
       
   111     bool m_channelOpen;
       
   112     void pauseListening() {
       
   113         if (m_sensorChannel && m_channelOpen) {
       
   114             m_sensorChannel->StopDataListening();
       
   115             m_sensorChannel->CloseChannel();
       
   116             m_channelOpen = false;
       
   117         }
       
   118     }
       
   119 
       
   120     void resumeListening() {
       
   121         if (m_sensorChannel && !m_channelOpen) {
       
   122             TRAPD(error, m_sensorChannel->OpenChannelL());
       
   123             if (!error) {
       
   124                 TRAP(error, m_sensorChannel->StartDataListeningL(this, 1, 1, 0));
       
   125                 if (!error) {
       
   126                     m_channelOpen = true;
       
   127                 }
       
   128             }
       
   129             if (error) {
       
   130                 delete m_sensorChannel;
       
   131                 m_sensorChannel = 0;
       
   132             }
       
   133         }
       
   134     }
   110 
   135 
   111     void DataReceived(CSensrvChannel &channel, TInt count, TInt dataLost)
   136     void DataReceived(CSensrvChannel &channel, TInt count, TInt dataLost)
   112     {
   137     {
       
   138         Q_UNUSED(dataLost)
   113         if (channel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdOrientationData) {
   139         if (channel.GetChannelInfo().iChannelType == KSensrvChannelTypeIdOrientationData) {
   114             TSensrvOrientationData data;
   140             TSensrvOrientationData data;
   115             for (int i = 0; i < count; ++i) {
   141             for (int i = 0; i < count; ++i) {
   116                 TPckgBuf<TSensrvOrientationData> dataBuf;
   142                 TPckgBuf<TSensrvOrientationData> dataBuf;
   117                 channel.GetData(dataBuf);
   143                 channel.GetData(dataBuf);
   118                 data = dataBuf();
   144                 data = dataBuf();
   119                 Orientation o = UnknownOrientation;
   145                 Orientation orientation = UnknownOrientation;
   120                 switch (data.iDeviceOrientation) {
   146                 switch (data.iDeviceOrientation) {
   121                 case TSensrvOrientationData::EOrientationDisplayUp:
   147                 case TSensrvOrientationData::EOrientationDisplayUp:
   122                     o = Portrait;
   148                     orientation = Portrait;
   123                     break;
   149                     break;
   124                 case TSensrvOrientationData::EOrientationDisplayRightUp:
   150                 case TSensrvOrientationData::EOrientationDisplayRightUp:
   125                     o = Landscape;
   151                     orientation = Landscape;
   126                     break;
   152                     break;
   127                 case TSensrvOrientationData::EOrientationDisplayLeftUp:
   153                 case TSensrvOrientationData::EOrientationDisplayLeftUp:
       
   154                     orientation = LandscapeInverted;
       
   155                     break;
   128                 case TSensrvOrientationData::EOrientationDisplayDown:
   156                 case TSensrvOrientationData::EOrientationDisplayDown:
       
   157                     orientation = PortraitInverted;
       
   158                     break;
   129                 case TSensrvOrientationData::EOrientationUndefined:
   159                 case TSensrvOrientationData::EOrientationUndefined:
   130                 case TSensrvOrientationData::EOrientationDisplayUpwards:
   160                 case TSensrvOrientationData::EOrientationDisplayUpwards:
   131                 case TSensrvOrientationData::EOrientationDisplayDownwards:
   161                 case TSensrvOrientationData::EOrientationDisplayDownwards:
   132                 default:
   162                 default:
   133                     break;
   163                     break;
   134                 }
   164                 }
   135 
   165 
   136                 if (m_current != o && o != UnknownOrientation) {
   166                 if (m_current != orientation && orientation != UnknownOrientation) {
   137                     m_current = o;
   167                     m_current = orientation;
   138                     emit orientationChanged();
   168                     emit orientationChanged();
   139                 }
   169                 }
   140            }
   170            }
   141         }
   171         }
   142     }
   172     }