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