plugin/poi/landmarks/overlay/src/AutoRotation.cpp
changeset 0 c316ab048e9d
equal deleted inserted replaced
-1:000000000000 0:c316ab048e9d
       
     1 /*
       
     2  * Name        : AutoRotation.cpp
       
     3  * Description : Handles device autorotation setting
       
     4  * Project     : This file is part of OpenMAR, an Open Mobile Augmented Reality browser
       
     5  * Website     : http://OpenMAR.org
       
     6  *
       
     7  * Copyright (c) 2010 David Caabeiro
       
     8  *
       
     9  * All rights reserved. This program and the accompanying materials are made available 
       
    10  * under the terms of the Eclipse Public License v1.0 which accompanies this 
       
    11  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
       
    12  *
       
    13  */
       
    14 
       
    15 #include "AutoRotation.h"
       
    16 
       
    17 #include "Logger.h"
       
    18 
       
    19 #include <CentralRepository.h>
       
    20 
       
    21 // Taken from SensorPluginDomainCrKeys.h
       
    22 const TUid KCRUidSensorSettings = { 0x10282DF0 };
       
    23 
       
    24 /*
       
    25  * Bitmask of variated use cases for Turning interaction.
       
    26  *
       
    27  * Possible values:
       
    28  *  0000 0000: No selected use cases, Turning interactions disabled
       
    29  *  0000 0001: Only Silence calls use case enabled
       
    30  *  0000 0010: Only Snooze alarm use case enabled
       
    31  *  0000 0100: Only Display orientation use case enabled
       
    32  *
       
    33  * Bitmask may contain different variations of above selections
       
    34  *
       
    35  * Value is an integer.
       
    36  *
       
    37  * Default value: 7
       
    38  */
       
    39 
       
    40 //const TUint32 KSenSetVariationTurnCtrl = 0x00100003;
       
    41 const TUint32 KSenSettingsTurnCtrl     = 0x00000003;
       
    42 
       
    43 CAutoRotation* CAutoRotation::NewL()
       
    44 {
       
    45     CAutoRotation* self = new(ELeave) CAutoRotation;
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop(self);
       
    49 
       
    50     return self;
       
    51 }
       
    52 
       
    53 CAutoRotation::~CAutoRotation()
       
    54 {
       
    55     Cancel();
       
    56 }
       
    57 
       
    58 CAutoRotation::CAutoRotation()
       
    59     : CActive(CActive::EPriorityStandard)
       
    60 {
       
    61     CActiveScheduler::Add(this);
       
    62 }
       
    63 
       
    64 void CAutoRotation::ConstructL()
       
    65 {
       
    66     LOGTXT("CAutoRotation::ConstructL()");
       
    67 
       
    68     iRepository = CRepository::NewL(KCRUidSensorSettings);
       
    69 
       
    70     RunL();
       
    71 }
       
    72 
       
    73 void CAutoRotation::RunL()
       
    74 {
       
    75     // Store setting value upon any external change
       
    76     User::LeaveIfError(iRepository->Get(KSenSettingsTurnCtrl, iTurnCtrl));
       
    77 
       
    78     Notify();
       
    79 }
       
    80 
       
    81 void CAutoRotation::DoCancel()
       
    82 {
       
    83     iRepository->NotifyCancel(KSenSettingsTurnCtrl);
       
    84 }
       
    85 
       
    86 void CAutoRotation::Notify()
       
    87 {
       
    88     iRepository->NotifyRequest(KSenSettingsTurnCtrl, iStatus);
       
    89     SetActive();
       
    90 }
       
    91 
       
    92 /*
       
    93  * Turn autorotation off
       
    94  */
       
    95 void CAutoRotation::ResetL()
       
    96 {
       
    97     // We don't want to get notification of our own modifications
       
    98     Cancel();
       
    99 
       
   100     TInt turnCtrl = iTurnCtrl & 0xfffffffb;
       
   101     User::LeaveIfError(iRepository->Set(KSenSettingsTurnCtrl, turnCtrl));
       
   102 
       
   103     Notify();
       
   104 }
       
   105 
       
   106 /*
       
   107  * Restore original value
       
   108  */
       
   109 void CAutoRotation::RestoreL()
       
   110 {
       
   111     // We don't want to get notification of our own modifications
       
   112     Cancel();
       
   113 
       
   114     User::LeaveIfError(iRepository->Set(KSenSettingsTurnCtrl, iTurnCtrl));
       
   115 
       
   116     Notify();
       
   117 }