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