|
1 /* |
|
2 * Copyright (c) 2005 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 the License "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: Implementation of class CCodConfirm. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <AknUtils.h> |
|
22 #include <AknDef.h> |
|
23 #include <StringLoader.h> |
|
24 #include <CodData.h> |
|
25 #include <CodDefs.h> |
|
26 #include <avkon.rsg> |
|
27 #include <CodUi.rsg> |
|
28 #include "CodConfirm.h" |
|
29 #include "CodLogger.h" |
|
30 #include <Oma2Agent.h> |
|
31 #include <AknLayout.cdl.h> |
|
32 |
|
33 |
|
34 #include <eikmobs.h> |
|
35 #include <aknPopup.h> |
|
36 #include <aknlists.h> |
|
37 #include <StringLoader.h> |
|
38 |
|
39 _LIT( KListBoxSeparator, "\t" ); |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 |
|
43 |
|
44 // ================= TYPES ======================= |
|
45 |
|
46 /** |
|
47 * Mime type to resource id mapping entry. |
|
48 */ |
|
49 struct TMimeAndResId |
|
50 { |
|
51 const TText8* iName; ///< MIME type. |
|
52 TInt iResId; ///< Resource id. |
|
53 }; |
|
54 |
|
55 // ================= CONSTANTS ======================= |
|
56 |
|
57 /// Number of bytes in a kilobyte. |
|
58 LOCAL_D const TInt KCodKbyte = 1024; |
|
59 |
|
60 /** |
|
61 * Null-terminated MIME-to-resId mapping table. |
|
62 * Order of entries is important (from most specific to most generic), as |
|
63 * entries are evaluated linearly. |
|
64 */ |
|
65 LOCAL_D const TMimeAndResId KCodMimeAndResIds[] = |
|
66 { |
|
67 { _S8( "application/vnd.nokia.ringing-tone" ), R_QTN_CD_TYPE_RTONE }, |
|
68 { _S8( "application/x-nokiaGameData" ), R_QTN_CD_TYPE_GAME_LEVEL }, |
|
69 { _S8( "application/vnd.oma.drm" ), R_QTN_CD_TYPE_NOT_CLASSIFIED }, |
|
70 { _S8( "application/" ), R_QTN_CD_TYPE_APPLICATION }, |
|
71 { _S8( "image/vnd.nokia.ota-bitmap" ), R_QTN_CD_TYPE_OPERATOR_LOGO }, |
|
72 { _S8( "image/vnd.nok-oplogo" ), R_QTN_CD_TYPE_OPERATOR_LOGO }, |
|
73 { _S8( "image/vnd.nok-picturemessage" ), R_QTN_CD_TYPE_PICTURE_MESSAGE }, |
|
74 { _S8( "image/" ), R_QTN_CD_TYPE_IMAGE }, |
|
75 { _S8( "audio/" ), R_QTN_CD_TYPE_SOUND }, |
|
76 { _S8( "text/X-vCard" ), R_QTN_CD_TYPE_VCARD }, |
|
77 { _S8( "text/" ), R_QTN_CD_TYPE_DOCUMENT }, |
|
78 { _S8( "" ), R_QTN_CD_TYPE_NOT_CLASSIFIED }, |
|
79 { NULL, 0 } |
|
80 }; |
|
81 |
|
82 // ================= MEMBER FUNCTIONS ======================= |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // CCodConfirm:CCodConfirm() |
|
86 // --------------------------------------------------------- |
|
87 // |
|
88 CCodConfirm::CCodConfirm() |
|
89 { |
|
90 } |
|
91 |
|
92 |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CCodConfirm::~CCodConfirm() |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CCodConfirm::~CCodConfirm() |
|
99 { |
|
100 } |
|
101 |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CCodView::AllocTypeNameL |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 HBufC* CCodConfirm::AllocTypeNameL( const TDesC8& aMimeType ) |
|
108 { |
|
109 const TMimeAndResId* mapping; |
|
110 TInt resId = R_QTN_CD_VALUE_UNDEFINED; |
|
111 for( mapping = &KCodMimeAndResIds[0]; mapping->iName; mapping++ ) |
|
112 { |
|
113 TPtrC8 name( mapping->iName ); |
|
114 // Looking for partial match (leftmost part of aMimeType is compared |
|
115 // to mapping->iName). |
|
116 if( name.Length() <= aMimeType.Length() ) |
|
117 { |
|
118 if( aMimeType.Left( name.Length() ).CompareF( name ) == 0 ) |
|
119 { |
|
120 resId = mapping->iResId; |
|
121 break; |
|
122 } |
|
123 } |
|
124 } |
|
125 return StringLoader::LoadL( resId, iCoeEnv ); |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CCodView::DisplayType |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 TPtrC8 CCodConfirm::DisplayType( const CCodData& aData ) |
|
134 { |
|
135 for ( TInt i = 0; i < (*aData[aData.ActiveDownload()]).Types().MdcaCount(); i++ ) |
|
136 { |
|
137 TPtrC8 type( (*aData[aData.ActiveDownload()]).Types().MdcaPoint( i ) ); |
|
138 if ( |
|
139 type.Compare( KOma1DrmMessageContentType ) && |
|
140 type.Compare( KOma1XmlRoContentType ) && |
|
141 type.Compare( KOma1WbxmlRoContentType ) && |
|
142 type.Compare( KOma2RoContentType ) && |
|
143 type.Compare( KOma2TriggerContentType ) && |
|
144 type.Compare( KOma1DcfContentType ) && |
|
145 type.Compare( KOma2DcfContentType ) && |
|
146 type.Compare( KOmaImportContentType ) |
|
147 ) |
|
148 { |
|
149 return type; // Non-DRM, return it. |
|
150 } |
|
151 } |
|
152 return (*aData[aData.ActiveDownload()]).Type(); // By default returns the first, whatever it is. |
|
153 } |
|
154 |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CCodConfirm::ShowDownloadConfirmationL |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TBool CCodConfirm::ShowDownloadConfirmationL(TInt aCbaResource, |
|
161 const CCodData& aData, |
|
162 TBool aCod ) |
|
163 { |
|
164 HBufC* itemText = NULL; // a buffer holding the text for each list item |
|
165 |
|
166 CEikFormattedCellListBox* listBox = new ( ELeave ) CAknDoublePopupMenuStyleListBox; |
|
167 CleanupStack::PushL( listBox ); |
|
168 |
|
169 // If supported show OK & Cancel buttons, otherwise just CANCEL |
|
170 |
|
171 CAknPopupList* popupList = CAknPopupList::NewL |
|
172 ( listBox, aCbaResource, AknPopupLayouts::EMenuDoubleWindow ); |
|
173 CleanupStack::PushL( popupList ); |
|
174 |
|
175 TInt flags = CEikListBox::EDisableHighlight; |
|
176 listBox->ConstructL( popupList, flags ); |
|
177 listBox->CreateScrollBarFrameL( ETrue ); |
|
178 listBox->ScrollBarFrame()->SetScrollBarVisibilityL |
|
179 ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
180 |
|
181 MDesCArray* itemList = listBox->Model()->ItemTextArray(); |
|
182 CDesCArray* itemArray = (CDesCArray*)itemList; |
|
183 |
|
184 //------------------------------------------- |
|
185 // Header |
|
186 HBufC* header = StringLoader::LoadLC( R_QTN_CD_TITLE ); |
|
187 popupList->SetTitleL( *header ); |
|
188 CleanupStack::PopAndDestroy( header ); // header |
|
189 header = NULL; |
|
190 |
|
191 |
|
192 // make description of buf |
|
193 HBufC* buf; |
|
194 |
|
195 //------------------------------------------- |
|
196 // Name |
|
197 // |
|
198 HBufC* popHeader = StringLoader::LoadLC( R_QTN_CD_DETAIL_NAME ); |
|
199 // If media count more than one, show album name if present |
|
200 itemText = FormatListBoxItemLC( *popHeader, aData.Count() > 1 && aData.Name().Length()? aData.Name() : (*aData[aData.ActiveDownload()]).Name() ); |
|
201 itemArray->AppendL( *itemText ); |
|
202 CleanupStack::PopAndDestroy( 2, popHeader ); // itemText,popHeader |
|
203 itemText = NULL; |
|
204 popHeader = NULL; |
|
205 |
|
206 //------------------------------------------- |
|
207 // Content Size |
|
208 // |
|
209 HBufC* sizeHeader = StringLoader::LoadLC( R_QTN_CD_DETAIL_SIZE ); |
|
210 TInt size = aData.Size(); |
|
211 if( size >= KCodKbyte ) |
|
212 { |
|
213 // Round up. |
|
214 buf = StringLoader::LoadLC |
|
215 ( R_QTN_SIZE_KB, (size - 1) / KCodKbyte + 1, iCoeEnv ); |
|
216 } |
|
217 else |
|
218 { |
|
219 buf = StringLoader::LoadLC( R_QTN_SIZE_B, size, iCoeEnv ); |
|
220 } |
|
221 buf->Des().Trim(); |
|
222 itemText = FormatListBoxItemLC( *sizeHeader, *buf ); |
|
223 itemArray->AppendL( *itemText ); |
|
224 CleanupStack::PopAndDestroy( 3, sizeHeader ); // itemText, sizeHeader |
|
225 itemText = NULL; |
|
226 sizeHeader = NULL; |
|
227 |
|
228 //------------------------------------------- |
|
229 // Type |
|
230 // |
|
231 popHeader = StringLoader::LoadLC( R_QTN_CD_DETAIL_TYPE ); |
|
232 buf = AllocTypeNameL( DisplayType(aData)); |
|
233 CleanupStack::PushL(buf); |
|
234 itemText = FormatListBoxItemLC( *popHeader, *buf ); |
|
235 itemArray->AppendL( *itemText ); |
|
236 CleanupStack::PopAndDestroy( 3, popHeader ); // itemText, nameHeader |
|
237 itemText = NULL; |
|
238 popHeader = NULL; |
|
239 |
|
240 |
|
241 //------------------------------------------- |
|
242 // Price: only if it's aCod |
|
243 // |
|
244 if ( aCod ) |
|
245 { |
|
246 popHeader = StringLoader::LoadLC( R_QTN_CD_DETAIL_PRICE ); |
|
247 itemText = FormatListBoxItemLC( *popHeader, aData.Price() ); |
|
248 itemArray->AppendL( *itemText ); |
|
249 CleanupStack::PopAndDestroy( 2, popHeader ); // itemText, nameHeader |
|
250 itemText = NULL; |
|
251 popHeader = NULL; |
|
252 } |
|
253 |
|
254 //------------------------------------------- |
|
255 // Detail Description |
|
256 // |
|
257 popHeader = StringLoader::LoadLC( R_QTN_CD_DETAIL_DESCRIPT ); |
|
258 HBufC* popValue = StringLoader::LoadLC(R_QTN_CD_VALUE_UNDEFINED ); |
|
259 if (aData.Description().Length()) |
|
260 { |
|
261 itemText = FormatListBoxItemLC( *popHeader, aData.Description() ); |
|
262 } |
|
263 else |
|
264 { |
|
265 itemText = FormatListBoxItemLC( *popHeader, *popValue ); |
|
266 } |
|
267 itemArray->AppendL( *itemText ); |
|
268 CleanupStack::PopAndDestroy( 3, popHeader ); // itemText, popValue |
|
269 itemText = NULL; |
|
270 popHeader = NULL; |
|
271 |
|
272 |
|
273 //------------------------------------------- |
|
274 // Vendor Information |
|
275 // |
|
276 popHeader = StringLoader::LoadLC( R_QTN_CD_DETAIL_VENDOR ); |
|
277 |
|
278 popValue = StringLoader::LoadLC(R_QTN_CD_VALUE_UNDEFINED ); |
|
279 if (aData.Vendor().Length()) |
|
280 itemText = FormatListBoxItemLC( *popHeader, aData.Vendor() ); |
|
281 else |
|
282 itemText = FormatListBoxItemLC( *popHeader, *popValue ); |
|
283 itemArray->AppendL( *itemText ); |
|
284 CleanupStack::PopAndDestroy( 3, popHeader ); // itemText, popValue |
|
285 itemText = NULL; |
|
286 popHeader = NULL; |
|
287 |
|
288 TInt popupOk = popupList->ExecuteLD(); |
|
289 |
|
290 |
|
291 |
|
292 // cleanup |
|
293 CleanupStack::Pop( popupList ); |
|
294 CleanupStack::PopAndDestroy( listBox ); // listBox |
|
295 |
|
296 return popupOk; |
|
297 } |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CCodConfirm::FormatListBoxItemLC |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 HBufC* CCodConfirm::FormatListBoxItemLC |
|
303 ( const TDesC& aFirst, const TDesC& aSecond ) |
|
304 { |
|
305 HBufC* res = HBufC::NewLC( aFirst.Length() + |
|
306 aSecond.Length() + |
|
307 KListBoxSeparator().Length() ); |
|
308 res->Des().Copy( aFirst ); |
|
309 res->Des().Append( KListBoxSeparator ); |
|
310 res->Des().Append( aSecond ); |
|
311 return res; |
|
312 } |