contentstorage/extsrc/casathandler.cpp
author hgs
Fri, 28 May 2010 16:17:03 +0300
changeset 96 5d243a69bdda
parent 85 7feec50967db
child 98 d2f833ab7940
permissions -rw-r--r--
201021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
85
7feec50967db 201003_02
hgs
parents:
diff changeset
     1
/*
7feec50967db 201003_02
hgs
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
7feec50967db 201003_02
hgs
parents:
diff changeset
     3
 * All rights reserved.
7feec50967db 201003_02
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
7feec50967db 201003_02
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
7feec50967db 201003_02
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
7feec50967db 201003_02
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7feec50967db 201003_02
hgs
parents:
diff changeset
     8
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
     9
 * Initial Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
7feec50967db 201003_02
hgs
parents:
diff changeset
    11
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    12
 * Contributors:
7feec50967db 201003_02
hgs
parents:
diff changeset
    13
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    14
 * Description:  Used for receive SIM Application name, icon or visibility information.
7feec50967db 201003_02
hgs
parents:
diff changeset
    15
 *
7feec50967db 201003_02
hgs
parents:
diff changeset
    16
 */
7feec50967db 201003_02
hgs
parents:
diff changeset
    17
7feec50967db 201003_02
hgs
parents:
diff changeset
    18
// INCLUDE FILES
7feec50967db 201003_02
hgs
parents:
diff changeset
    19
7feec50967db 201003_02
hgs
parents:
diff changeset
    20
#include <e32property.h>
7feec50967db 201003_02
hgs
parents:
diff changeset
    21
#include <bitdev.h>
7feec50967db 201003_02
hgs
parents:
diff changeset
    22
7feec50967db 201003_02
hgs
parents:
diff changeset
    23
#include "ca2internalCRkeys.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    24
#include "casathandler.h"
7feec50967db 201003_02
hgs
parents:
diff changeset
    25
7feec50967db 201003_02
hgs
parents:
diff changeset
    26
7feec50967db 201003_02
hgs
parents:
diff changeset
    27
// ============================ MEMBER FUNCTIONS ===============================
7feec50967db 201003_02
hgs
parents:
diff changeset
    28
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    29
// CCaSatHandler::NewL
7feec50967db 201003_02
hgs
parents:
diff changeset
    30
// Two-phased constructor.
7feec50967db 201003_02
hgs
parents:
diff changeset
    31
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    32
//
7feec50967db 201003_02
hgs
parents:
diff changeset
    33
EXPORT_C CCaSatHandler* CCaSatHandler::NewL()
7feec50967db 201003_02
hgs
parents:
diff changeset
    34
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    35
    CCaSatHandler* self = new ( ELeave ) CCaSatHandler();
7feec50967db 201003_02
hgs
parents:
diff changeset
    36
    CleanupStack::PushL( self );
7feec50967db 201003_02
hgs
parents:
diff changeset
    37
    self->ConstructL();
7feec50967db 201003_02
hgs
parents:
diff changeset
    38
    CleanupStack::Pop( self );
7feec50967db 201003_02
hgs
parents:
diff changeset
    39
    return self;
7feec50967db 201003_02
hgs
parents:
diff changeset
    40
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    41
7feec50967db 201003_02
hgs
parents:
diff changeset
    42
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    43
// Destructor
7feec50967db 201003_02
hgs
parents:
diff changeset
    44
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    45
CCaSatHandler::~CCaSatHandler()
7feec50967db 201003_02
hgs
parents:
diff changeset
    46
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    47
    iSatIcon.Close();
7feec50967db 201003_02
hgs
parents:
diff changeset
    48
    iSatSession.Close();
7feec50967db 201003_02
hgs
parents:
diff changeset
    49
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
    50
7feec50967db 201003_02
hgs
parents:
diff changeset
    51
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    52
// Destructor
7feec50967db 201003_02
hgs
parents:
diff changeset
    53
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
    54
EXPORT_C CAknIcon* CCaSatHandler::LoadIconL()
7feec50967db 201003_02
hgs
parents:
diff changeset
    55
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
    56
    TInt iconId( KErrNone );
7feec50967db 201003_02
hgs
parents:
diff changeset
    57
    User::LeaveIfError( RProperty::Get( KCRUidCa, KCaSatUIIconId, iconId ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
    58
    CAknIcon* icon = CAknIcon::NewL();
7feec50967db 201003_02
hgs
parents:
diff changeset
    59
    CleanupStack::PushL( icon );
7feec50967db 201003_02
hgs
parents:
diff changeset
    60
    if( iconId != KErrNone )
7feec50967db 201003_02
hgs
parents:
diff changeset
    61
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
    62
        RIconEf iIconEf;
7feec50967db 201003_02
hgs
parents:
diff changeset
    63
        iSatIcon.GetIconInfoL( TUint8( iconId ), iIconEf );
7feec50967db 201003_02
hgs
parents:
diff changeset
    64
        CleanupClosePushL( iIconEf );
7feec50967db 201003_02
hgs
parents:
diff changeset
    65
        CFbsBitmap* bitmap = GetBitmapL( iIconEf );
7feec50967db 201003_02
hgs
parents:
diff changeset
    66
        if( !bitmap )
7feec50967db 201003_02
hgs
parents:
diff changeset
    67
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
    68
            CFbsBitmap* mask( NULL );
7feec50967db 201003_02
hgs
parents:
diff changeset
    69
            CleanupStack::PushL( mask );
7feec50967db 201003_02
hgs
parents:
diff changeset
    70
7feec50967db 201003_02
hgs
parents:
diff changeset
    71
            icon->SetBitmap( bitmap );
7feec50967db 201003_02
hgs
parents:
diff changeset
    72
            // create and set mask
7feec50967db 201003_02
hgs
parents:
diff changeset
    73
            User::LeaveIfError( mask->Create( bitmap->SizeInPixels(),
7feec50967db 201003_02
hgs
parents:
diff changeset
    74
                    EGray256 ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
    75
7feec50967db 201003_02
hgs
parents:
diff changeset
    76
            CFbsBitmapDevice* maskDevice = CFbsBitmapDevice::NewL( mask );
7feec50967db 201003_02
hgs
parents:
diff changeset
    77
            CleanupStack::PushL( maskDevice );
7feec50967db 201003_02
hgs
parents:
diff changeset
    78
            CFbsBitGc* maskGc;
7feec50967db 201003_02
hgs
parents:
diff changeset
    79
            User::LeaveIfError( maskDevice->CreateContext( maskGc ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
    80
            CleanupStack::PushL( maskGc );
7feec50967db 201003_02
hgs
parents:
diff changeset
    81
            maskGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
7feec50967db 201003_02
hgs
parents:
diff changeset
    82
            maskGc->SetDrawMode( CGraphicsContext::EDrawModePEN );
7feec50967db 201003_02
hgs
parents:
diff changeset
    83
            maskGc->SetBrushColor( KRgbBlack );
7feec50967db 201003_02
hgs
parents:
diff changeset
    84
            maskGc->Clear();
7feec50967db 201003_02
hgs
parents:
diff changeset
    85
            maskGc->SetBrushColor( KRgbWhite );
7feec50967db 201003_02
hgs
parents:
diff changeset
    86
            maskGc->DrawRect( TRect( TPoint(), bitmap->SizeInPixels() ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
    87
            icon->SetMask( mask );
7feec50967db 201003_02
hgs
parents:
diff changeset
    88
7feec50967db 201003_02
hgs
parents:
diff changeset
    89
            CleanupStack::PopAndDestroy( maskGc );
7feec50967db 201003_02
hgs
parents:
diff changeset
    90
            CleanupStack::PopAndDestroy( maskDevice );
7feec50967db 201003_02
hgs
parents:
diff changeset
    91
            CleanupStack::Pop( mask );
7feec50967db 201003_02
hgs
parents:
diff changeset
    92
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
    93
        CleanupStack::PopAndDestroy( &iIconEf ); // iIconEf
7feec50967db 201003_02
hgs
parents:
diff changeset
    94
        CleanupStack::Pop( icon );
7feec50967db 201003_02
hgs
parents:
diff changeset
    95
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
    96
    else
7feec50967db 201003_02
hgs
parents:
diff changeset
    97
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
    98
        CleanupStack::PopAndDestroy( icon );
7feec50967db 201003_02
hgs
parents:
diff changeset
    99
        icon = NULL;
7feec50967db 201003_02
hgs
parents:
diff changeset
   100
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   101
    return icon;
7feec50967db 201003_02
hgs
parents:
diff changeset
   102
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   103
7feec50967db 201003_02
hgs
parents:
diff changeset
   104
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   105
// CCaSatHandler::GetName
7feec50967db 201003_02
hgs
parents:
diff changeset
   106
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   107
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   108
EXPORT_C TInt CCaSatHandler::GetName( TDes& aName )
7feec50967db 201003_02
hgs
parents:
diff changeset
   109
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   110
    return RProperty::Get( KCRUidCa, KCaSatUIName, aName );
7feec50967db 201003_02
hgs
parents:
diff changeset
   111
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   112
7feec50967db 201003_02
hgs
parents:
diff changeset
   113
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   114
// CCaSatHandler::GetVisibility
7feec50967db 201003_02
hgs
parents:
diff changeset
   115
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   116
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   117
EXPORT_C TBool CCaSatHandler::CheckVisibility()
7feec50967db 201003_02
hgs
parents:
diff changeset
   118
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   119
    TInt visibility( KErrNone );
7feec50967db 201003_02
hgs
parents:
diff changeset
   120
    TInt err = RProperty::Get( KCRUidCa, KCaShowSatUI, visibility );
7feec50967db 201003_02
hgs
parents:
diff changeset
   121
    if( err == KErrNone && visibility )
7feec50967db 201003_02
hgs
parents:
diff changeset
   122
        return ETrue;
7feec50967db 201003_02
hgs
parents:
diff changeset
   123
    else
7feec50967db 201003_02
hgs
parents:
diff changeset
   124
        return EFalse;
7feec50967db 201003_02
hgs
parents:
diff changeset
   125
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   126
7feec50967db 201003_02
hgs
parents:
diff changeset
   127
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   128
// CCaSatHandler::CMcsSatHandler
7feec50967db 201003_02
hgs
parents:
diff changeset
   129
// C++ default constructor can NOT contain any code, that
7feec50967db 201003_02
hgs
parents:
diff changeset
   130
// might leave.
7feec50967db 201003_02
hgs
parents:
diff changeset
   131
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   132
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   133
CCaSatHandler::CCaSatHandler()
7feec50967db 201003_02
hgs
parents:
diff changeset
   134
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   135
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   136
7feec50967db 201003_02
hgs
parents:
diff changeset
   137
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   138
// CCaSatHandler::ConstructL
7feec50967db 201003_02
hgs
parents:
diff changeset
   139
// Symbian 2nd phase constructor can leave.
7feec50967db 201003_02
hgs
parents:
diff changeset
   140
// -----------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   141
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   142
void CCaSatHandler::ConstructL()
7feec50967db 201003_02
hgs
parents:
diff changeset
   143
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   144
    iSatSession.ConnectL();
7feec50967db 201003_02
hgs
parents:
diff changeset
   145
    iSatIcon.OpenL( iSatSession );
7feec50967db 201003_02
hgs
parents:
diff changeset
   146
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   147
7feec50967db 201003_02
hgs
parents:
diff changeset
   148
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   149
// CCaSatHandler::GetVisibility
7feec50967db 201003_02
hgs
parents:
diff changeset
   150
// ---------------------------------------------------------------------------
7feec50967db 201003_02
hgs
parents:
diff changeset
   151
//
7feec50967db 201003_02
hgs
parents:
diff changeset
   152
CFbsBitmap* CCaSatHandler::GetBitmapL( const RIconEf& aIconEF )
7feec50967db 201003_02
hgs
parents:
diff changeset
   153
    {
7feec50967db 201003_02
hgs
parents:
diff changeset
   154
    TInt selectedIconIndex( KErrNotFound );
7feec50967db 201003_02
hgs
parents:
diff changeset
   155
    TSize selectedIconSize( 0, 0 );
7feec50967db 201003_02
hgs
parents:
diff changeset
   156
    CFbsBitmap* bitmap( NULL );
7feec50967db 201003_02
hgs
parents:
diff changeset
   157
    for( TInt i = 0; i < aIconEF.Count(); ++i )
7feec50967db 201003_02
hgs
parents:
diff changeset
   158
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   159
        if( ( aIconEF[i].IconSize().iHeight * aIconEF[i].IconSize().iWidth )
7feec50967db 201003_02
hgs
parents:
diff changeset
   160
                >= ( selectedIconSize.iHeight * selectedIconSize.iWidth ) )
7feec50967db 201003_02
hgs
parents:
diff changeset
   161
            if( bitmap )
7feec50967db 201003_02
hgs
parents:
diff changeset
   162
                {
7feec50967db 201003_02
hgs
parents:
diff changeset
   163
                delete bitmap;
7feec50967db 201003_02
hgs
parents:
diff changeset
   164
                bitmap = NULL;
7feec50967db 201003_02
hgs
parents:
diff changeset
   165
                }
7feec50967db 201003_02
hgs
parents:
diff changeset
   166
        // test and select index of iIcon which is not too big
7feec50967db 201003_02
hgs
parents:
diff changeset
   167
        TRAPD( bitmapErr, bitmap = iSatIcon.GetIconL( aIconEF[ i ] ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
   168
        if( !bitmapErr && bitmap ) //!iBitmap if iIcon is too big
7feec50967db 201003_02
hgs
parents:
diff changeset
   169
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
   170
            selectedIconSize = aIconEF[i].IconSize();
7feec50967db 201003_02
hgs
parents:
diff changeset
   171
            selectedIconIndex = i;
7feec50967db 201003_02
hgs
parents:
diff changeset
   172
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
   173
        else if( bitmapErr )
7feec50967db 201003_02
hgs
parents:
diff changeset
   174
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
   175
            User::Leave( bitmapErr );
7feec50967db 201003_02
hgs
parents:
diff changeset
   176
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
   177
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   178
    if( selectedIconIndex != KErrNotFound )
7feec50967db 201003_02
hgs
parents:
diff changeset
   179
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   180
        if( bitmap )
7feec50967db 201003_02
hgs
parents:
diff changeset
   181
            {
7feec50967db 201003_02
hgs
parents:
diff changeset
   182
            delete bitmap;
7feec50967db 201003_02
hgs
parents:
diff changeset
   183
            bitmap = NULL;
7feec50967db 201003_02
hgs
parents:
diff changeset
   184
            }
7feec50967db 201003_02
hgs
parents:
diff changeset
   185
        TRAPD( bitmapErr, bitmap = 
7feec50967db 201003_02
hgs
parents:
diff changeset
   186
                iSatIcon.GetIconL( aIconEF[ selectedIconIndex ] ) );
7feec50967db 201003_02
hgs
parents:
diff changeset
   187
        User::LeaveIfError( bitmapErr );
7feec50967db 201003_02
hgs
parents:
diff changeset
   188
        return bitmap;
7feec50967db 201003_02
hgs
parents:
diff changeset
   189
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   190
    else
7feec50967db 201003_02
hgs
parents:
diff changeset
   191
        {
7feec50967db 201003_02
hgs
parents:
diff changeset
   192
        return NULL;
7feec50967db 201003_02
hgs
parents:
diff changeset
   193
        }
7feec50967db 201003_02
hgs
parents:
diff changeset
   194
    }
7feec50967db 201003_02
hgs
parents:
diff changeset
   195
7feec50967db 201003_02
hgs
parents:
diff changeset
   196
//  End of File