bluetoothengine/btui/btuidelegate/btdelegatevisibility.cpp
changeset 19 43824b19ee35
child 31 a0ea99b6fa53
equal deleted inserted replaced
17:f05641c183ff 19:43824b19ee35
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Delegate class for setting visibility mode
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "btdelegatevisibility.h"
       
    20 #include "btuimodel.h"
       
    21 #include <bluetoothuitrace.h>
       
    22 #include "btqtconstants.h"
       
    23 #include <btengsettings.h>
       
    24 
       
    25 const int MAX_TEMPORARY_VISIBILITY = 60;  // minutes, this value comes from the UI spec
       
    26 
       
    27 /*!
       
    28     Constructor.
       
    29  */
       
    30 BtDelegateVisibility::BtDelegateVisibility( BtuiModel& model, QObject *parent )
       
    31     : BtAbstractDelegate( model, parent )
       
    32 {
       
    33     TRAP_IGNORE( mBtengSettings = CBTEngSettings::NewL(this) );
       
    34     Q_CHECK_PTR( mBtengSettings );
       
    35     mOperationOngoing = false;
       
    36 }
       
    37 
       
    38 /*!
       
    39     Destructor.
       
    40  */
       
    41 BtDelegateVisibility::~BtDelegateVisibility()
       
    42 {
       
    43     delete mBtengSettings;
       
    44 }
       
    45 /*!
       
    46  * executes visibility delegate functionality, ie. calls CBTEngSettings to set the visibility mode;
       
    47  * when operation completes, emits commandCompleted signal
       
    48  * Parameters:  Qlist<QVariant> where first item is VisibilityMode integer specifying operation;  
       
    49  *              for BtTemporary a 2nd parameter is give which signifies the number of minutes to stay visible.
       
    50  */
       
    51 void BtDelegateVisibility::exec( const QVariant &params )
       
    52 {
       
    53     int minutes, err = 0;
       
    54 
       
    55     if (mOperationOngoing) {
       
    56         // complete command with error
       
    57         emit commandCompleted(KErrInUse);
       
    58         return;
       
    59     } 
       
    60     mOperationOngoing = true;
       
    61     
       
    62     // read 1st parameter
       
    63     BTUI_ASSERT_X(params.toList().at(0).isValid(), "BtDelegateVisibility::exec", "invalid parameter");
       
    64     VisibilityMode btQtMode = (VisibilityMode)params.toList().at(0).toInt();
       
    65     mOperation = BtEngVisibilityMode(btQtMode);
       
    66     
       
    67     // verify that we are setting visibility to a new value, otherwise we won't get a callback
       
    68     TBTVisibilityMode visibilityMode( EBTVisibilityModeNoScans );
       
    69     err = mBtengSettings->GetVisibilityMode( visibilityMode );
       
    70     if (err) {
       
    71         mOperationOngoing = false;
       
    72         emit commandCompleted(err);
       
    73         return;
       
    74     }
       
    75     if (visibilityMode == mOperation) {
       
    76         mOperationOngoing = false;
       
    77         emit commandCompleted(KErrNone);
       
    78         return;
       
    79     }
       
    80     
       
    81     switch (mOperation) {
       
    82     case EBTVisibilityModeGeneral :
       
    83         err = mBtengSettings->SetVisibilityMode(mOperation, 0);
       
    84         break;
       
    85     case EBTVisibilityModeHidden:
       
    86         err = mBtengSettings->SetVisibilityMode(mOperation, 0);
       
    87         break;
       
    88     case EBTVisibilityModeTemporary:
       
    89         BTUI_ASSERT_X(params.toList().at(1).isValid(), "BtDelegateVisibility::exec", "invalid time parameter");
       
    90         minutes = params.toList().at(1).toInt();
       
    91         BTUI_ASSERT_X(((minutes >= 0 ) && (minutes <= MAX_TEMPORARY_VISIBILITY)), 
       
    92                 "BtDelegateVisibility::exec", "invalid time parameter");
       
    93         err = mBtengSettings->SetVisibilityMode(mOperation, minutes);
       
    94         break;
       
    95     default:
       
    96         // error
       
    97         BTUI_ASSERT_X(false, "BtDelegateVisibility::exec", "invalid parameter");
       
    98     }
       
    99     if (err) {
       
   100         // complete command with error
       
   101         mOperationOngoing = false;
       
   102         emit commandCompleted(err);
       
   103     }
       
   104 }
       
   105 
       
   106 void BtDelegateVisibility::PowerStateChanged( TBTPowerStateValue aState )
       
   107 {
       
   108     Q_UNUSED( aState );
       
   109 }
       
   110 
       
   111 /*!
       
   112  * callback from BtEngine
       
   113  *    emits command complete with either: 
       
   114  *    1) KErrUnknown if something went wrong, or
       
   115  *    2) KErrNone if everything ok 
       
   116  */
       
   117 void BtDelegateVisibility::VisibilityModeChanged( TBTVisibilityMode aState )
       
   118 {
       
   119     if (mOperationOngoing) {
       
   120         //Error handling has to be done, if value is not set properly.
       
   121         mOperationOngoing = false;
       
   122         if (mOperation == aState) {
       
   123             emit commandCompleted(KErrNone);
       
   124         }
       
   125         else {
       
   126             emit commandCompleted(KErrUnknown);
       
   127         }
       
   128     }
       
   129 }