services/terminalmodeservice/src/upnptmiconmapping.cpp
author hgs
Fri, 03 Sep 2010 09:13:04 +0300
changeset 31 b51a6f4f15ba
parent 24 e9457ebcc4df
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
hgs
parents:
diff changeset
     1
/**
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: CUpnpTmIconMapping class implementation.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
//Include Files  
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include "upnptmiconmapping.h"
hgs
parents:
diff changeset
    21
#include "OstTraceDefinitions.h"
hgs
parents:
diff changeset
    22
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
    23
#include "upnptmiconmappingTraces.h"
hgs
parents:
diff changeset
    24
#endif
hgs
parents:
diff changeset
    25
   
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
_LIT8(KSvgMimeType,     "image/svg+xml");  
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// ================= MEMBER FUNCTIONS ==============================================
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    32
// CUpnpTmIconMapping::NewL
hgs
parents:
diff changeset
    33
// Two-phased constructor.
hgs
parents:
diff changeset
    34
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    35
//
hgs
parents:
diff changeset
    36
CUpnpTmIconMapping* CUpnpTmIconMapping::NewL( )
hgs
parents:
diff changeset
    37
    {
hgs
parents:
diff changeset
    38
    OstTraceFunctionEntry0( CUPNPTMICONMAPPING_NEWL_ENTRY );
hgs
parents:
diff changeset
    39
    CUpnpTmIconMapping* self = new (ELeave) CUpnpTmIconMapping(); 
hgs
parents:
diff changeset
    40
    CleanupStack::PushL(self);
hgs
parents:
diff changeset
    41
    self->ConstructL();
hgs
parents:
diff changeset
    42
    CleanupStack::Pop(self);
hgs
parents:
diff changeset
    43
    OstTraceFunctionExit0( CUPNPTMICONMAPPING_NEWL_EXIT );
hgs
parents:
diff changeset
    44
    return self; 
hgs
parents:
diff changeset
    45
    }
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    49
// CUpnpTmIconMapping::CUpnpTmIconMapping
hgs
parents:
diff changeset
    50
// C++ default constructor can NOT contain any code, that
hgs
parents:
diff changeset
    51
// might leave.
hgs
parents:
diff changeset
    52
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    53
//
hgs
parents:
diff changeset
    54
CUpnpTmIconMapping::CUpnpTmIconMapping( )
hgs
parents:
diff changeset
    55
     {
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
     }
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    60
// CUpnpTmIconMapping::ConstructL
hgs
parents:
diff changeset
    61
// Symbian 2nd phase constructor can leave.
hgs
parents:
diff changeset
    62
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    63
//
hgs
parents:
diff changeset
    64
void CUpnpTmIconMapping::ConstructL()
hgs
parents:
diff changeset
    65
    {
hgs
parents:
diff changeset
    66
    OstTraceFunctionEntry0( CUPNPTMICONMAPPING_CONSTRUCTL_ENTRY );
hgs
parents:
diff changeset
    67
    iFileUrlArray = new ( ELeave ) CDesC8ArrayFlat( KExpectedMaxIconParms  );
hgs
parents:
diff changeset
    68
    iFilePathArray = new ( ELeave ) CDesCArrayFlat( KExpectedMaxIconParms );
hgs
parents:
diff changeset
    69
    OstTraceFunctionExit0( CUPNPTMICONMAPPING_CONSTRUCTL_EXIT );
hgs
parents:
diff changeset
    70
    }
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    73
// CUpnpTmIconMapping::~CUpnpTmIconMapping
hgs
parents:
diff changeset
    74
// Destructor
hgs
parents:
diff changeset
    75
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    76
//
hgs
parents:
diff changeset
    77
CUpnpTmIconMapping::~CUpnpTmIconMapping()
hgs
parents:
diff changeset
    78
    {
hgs
parents:
diff changeset
    79
    OstTraceFunctionEntry0( CUPNPTMICONMAPPING_CUPNPTMICONMAPPING_ENTRY );
hgs
parents:
diff changeset
    80
    if ( iFileUrlArray )
hgs
parents:
diff changeset
    81
        {
hgs
parents:
diff changeset
    82
        iFileUrlArray->Reset();
hgs
parents:
diff changeset
    83
        delete iFileUrlArray;
hgs
parents:
diff changeset
    84
        }
hgs
parents:
diff changeset
    85
    if ( iFilePathArray )
hgs
parents:
diff changeset
    86
        {
hgs
parents:
diff changeset
    87
        iFilePathArray->Reset();
hgs
parents:
diff changeset
    88
        delete iFilePathArray;
hgs
parents:
diff changeset
    89
        }   
hgs
parents:
diff changeset
    90
    iWidthArray.Close();
hgs
parents:
diff changeset
    91
    iHeightArray.Close();
hgs
parents:
diff changeset
    92
    OstTraceFunctionExit0( CUPNPTMICONMAPPING_CUPNPTMICONMAPPING_EXIT );
hgs
parents:
diff changeset
    93
    }
hgs
parents:
diff changeset
    94
hgs
parents:
diff changeset
    95
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    96
// CUpnpTmIconMapping::AddIconFileInfoL
hgs
parents:
diff changeset
    97
// Method is used to store information about each application icon which can be 
hgs
parents:
diff changeset
    98
// used to fetch iconPath for the corresponding iconUrl and to determine whether  
hgs
parents:
diff changeset
    99
// conversion is needed or not.
hgs
parents:
diff changeset
   100
// @param aUrl     Iccon URL.
hgs
parents:
diff changeset
   101
// @param aPath    Icon Path.
hgs
parents:
diff changeset
   102
// @param aWidth   Width of the icon.
hgs
parents:
diff changeset
   103
// @param aHeight  Height of the icon.
hgs
parents:
diff changeset
   104
// -------------------------------------------------------------------------------------
hgs
parents:
diff changeset
   105
//
hgs
parents:
diff changeset
   106
void CUpnpTmIconMapping::AddIconFileInfoL( const TDesC8& aUrl, const TDesC& aPath, 
hgs
parents:
diff changeset
   107
                                                        TInt aWidth, TInt aHeight )
hgs
parents:
diff changeset
   108
    {
hgs
parents:
diff changeset
   109
    OstTraceFunctionEntry0( CUPNPTMICONMAPPING_ADDICONFILEINFOL_ENTRY );
hgs
parents:
diff changeset
   110
    iFileUrlArray->AppendL( aUrl );
hgs
parents:
diff changeset
   111
    iFilePathArray->AppendL( aPath );
hgs
parents:
diff changeset
   112
    iWidthArray.AppendL( aWidth );
hgs
parents:
diff changeset
   113
    iHeightArray.AppendL( aHeight );
hgs
parents:
diff changeset
   114
    OstTraceFunctionExit0( CUPNPTMICONMAPPING_ADDICONFILEINFOL_EXIT );
hgs
parents:
diff changeset
   115
    }
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   118
// CUpnpTmIconMapping::GetSvgIconPath
hgs
parents:
diff changeset
   119
// Method is used to fetch the equivalent icon path for the requested icon url
hgs
parents:
diff changeset
   120
// @param aUrl  iconUrl
hgs
parents:
diff changeset
   121
// @param aSvgFilePath[out]  iconPath
hgs
parents:
diff changeset
   122
// @return   Returns the position of the filepath in the array if found else 
hgs
parents:
diff changeset
   123
//           returns KErrNotFound.
hgs
parents:
diff changeset
   124
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   125
//
hgs
parents:
diff changeset
   126
TInt CUpnpTmIconMapping::GetSvgIconPath( const TDesC8& aUrl,RBuf& aSvgFilePath )
hgs
parents:
diff changeset
   127
    {
hgs
parents:
diff changeset
   128
    OstTraceFunctionEntry0( CUPNPTMICONMAPPING_GETSVGICONPATH_ENTRY );
hgs
parents:
diff changeset
   129
    TInt pos;
hgs
parents:
diff changeset
   130
    if ( iFileUrlArray->Find(aUrl,pos) == KErrNone )
hgs
parents:
diff changeset
   131
        {
hgs
parents:
diff changeset
   132
        aSvgFilePath.Close();
hgs
parents:
diff changeset
   133
        aSvgFilePath.Create((*iFilePathArray)[pos]);
hgs
parents:
diff changeset
   134
        }
hgs
parents:
diff changeset
   135
    else
hgs
parents:
diff changeset
   136
        {
hgs
parents:
diff changeset
   137
        // The requested file is not available
hgs
parents:
diff changeset
   138
        pos = KErrNotFound;
hgs
parents:
diff changeset
   139
        }
hgs
parents:
diff changeset
   140
    OstTraceFunctionExit0( CUPNPTMICONMAPPING_GETSVGICONPATH_EXIT );
hgs
parents:
diff changeset
   141
    return pos;
hgs
parents:
diff changeset
   142
    }
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   145
// CUpnpTmIconMapping::IsConversionNeeded
hgs
parents:
diff changeset
   146
// Method is used to fetch the dimensions of the icon which needs to be served and 
hgs
parents:
diff changeset
   147
// also return the information whether conversion is needed for a particular icon.
hgs
parents:
diff changeset
   148
// @param aIndex   Index of the icon filepath
hgs
parents:
diff changeset
   149
// @param aClientIconPref   Reference to Client Icon Preference object.
hgs
parents:
diff changeset
   150
// @param[out] aIconWidth   Width of the icon which needs to be sent.
hgs
parents:
diff changeset
   151
// @param[out] aIconHeight  Height of the icon which needs to be sent.
hgs
parents:
diff changeset
   152
// @return  Returns the boolean value for conversion is needed(true) or not(false).
hgs
parents:
diff changeset
   153
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   154
//
hgs
parents:
diff changeset
   155
TBool CUpnpTmIconMapping::IsConversionNeeded( TInt aIndex, const CUpnpTmClientIconPref& aClientIconPref,
hgs
parents:
diff changeset
   156
                                                                   TInt& aIconWidth, TInt& aIconHeight )
hgs
parents:
diff changeset
   157
    {
hgs
parents:
diff changeset
   158
    OstTraceFunctionEntry0( CUPNPTMICONMAPPING_ISCONVERSIONNEEDED_ENTRY );
hgs
parents:
diff changeset
   159
    ASSERT( ( aIndex >= 0 ) && ( aIndex < iWidthArray.Count()) );
hgs
parents:
diff changeset
   160
    TBool isConversionNeeded(ETrue);
hgs
parents:
diff changeset
   161
    // Fetch the client's icon preferences
hgs
parents:
diff changeset
   162
    const TDesC8& mimeType = aClientIconPref.MimeType();
hgs
parents:
diff changeset
   163
    TInt iconWidth  = aClientIconPref.Width();
hgs
parents:
diff changeset
   164
    TInt iconHeight = aClientIconPref.Height();
hgs
parents:
diff changeset
   165
    OstTraceExt2( TRACE_NORMAL, DUP1_CUPNPTMICONMAPPING_ISCONVERSIONNEEDED, "CUpnpTmIconMapping::IsConversionNeeded;iconWidth=%d;iconHeight=%d", iconWidth, iconHeight );
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
    if ( mimeType.Compare(KSvgMimeType) == KErrNone )
hgs
parents:
diff changeset
   168
        {
hgs
parents:
diff changeset
   169
        // Client supports "image/svg+xml" mime type icons
hgs
parents:
diff changeset
   170
        if ((( iconWidth == KErrNone ) || ( iconWidth == iWidthArray[aIndex] )) && 
hgs
parents:
diff changeset
   171
            (( iconHeight == KErrNone ) || ( iconHeight == iHeightArray[aIndex] )))
hgs
parents:
diff changeset
   172
            {
hgs
parents:
diff changeset
   173
            /* Either the client has not provided its dimension preferences or 
hgs
parents:
diff changeset
   174
               preferred width and height also matches. So no conversion needed */
hgs
parents:
diff changeset
   175
            isConversionNeeded = EFalse;
hgs
parents:
diff changeset
   176
            }
hgs
parents:
diff changeset
   177
        }
hgs
parents:
diff changeset
   178
    /* 
hgs
parents:
diff changeset
   179
     * If the width and height fields are set properly then only use the client's 
hgs
parents:
diff changeset
   180
     * specified icon dimensions else use the icon's original dimensions.
hgs
parents:
diff changeset
   181
     */
hgs
parents:
diff changeset
   182
    if ( isConversionNeeded && iconWidth && iconHeight )
hgs
parents:
diff changeset
   183
        {
hgs
parents:
diff changeset
   184
        // Use the dimensions specified by the client
hgs
parents:
diff changeset
   185
        aIconWidth  = iconWidth;
hgs
parents:
diff changeset
   186
        aIconHeight = iconHeight;  
hgs
parents:
diff changeset
   187
        }
hgs
parents:
diff changeset
   188
    else
hgs
parents:
diff changeset
   189
        {
hgs
parents:
diff changeset
   190
        // Use original dimensions
hgs
parents:
diff changeset
   191
        aIconWidth  = iWidthArray[aIndex];
hgs
parents:
diff changeset
   192
        aIconHeight = iHeightArray[aIndex]; 
hgs
parents:
diff changeset
   193
        } 
hgs
parents:
diff changeset
   194
    OstTraceExt2( TRACE_NORMAL, CUPNPTMICONMAPPING_ISCONVERSIONNEEDED, "CUpnpTmIconMapping::IsConversionNeeded;aIconWidth=%d;aIconHeight=%d", aIconWidth, aIconHeight );
hgs
parents:
diff changeset
   195
    OstTraceFunctionExit0( CUPNPTMICONMAPPING_ISCONVERSIONNEEDED_EXIT );
hgs
parents:
diff changeset
   196
    return isConversionNeeded;
hgs
parents:
diff changeset
   197
    }