|
1 /* |
|
2 * Copyright (c) 2004 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 CCodDocument. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <AiwGenericParam.h> |
|
22 #include <CodEng.h> |
|
23 #include <DdEng.h> |
|
24 #include <CodUtil.h> |
|
25 #include "CodDocument.h" |
|
26 #include "CodAppUi.h" |
|
27 #include "RequestCompleteCallback.h" |
|
28 #include "CodLogger.h" |
|
29 |
|
30 // ================= MEMBER FUNCTIONS ======================= |
|
31 |
|
32 // --------------------------------------------------------- |
|
33 // CCodDocument::CodAppUi() |
|
34 // --------------------------------------------------------- |
|
35 // |
|
36 CCodAppUi* CCodDocument::CodAppUi() |
|
37 { |
|
38 // Inline method must be defined before it is used. |
|
39 return STATIC_CAST( CCodAppUi*, iAppUi ); |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CCodDocument::NewL() |
|
44 // --------------------------------------------------------- |
|
45 // |
|
46 CCodDocument* CCodDocument::NewL( CEikApplication& aApp, TBool aCod ) |
|
47 { |
|
48 CCodDocument* doc = new (ELeave) CCodDocument( aApp, aCod ); |
|
49 CleanupStack::PushL( doc ); |
|
50 doc->ConstructL(); |
|
51 CleanupStack::Pop( doc ); |
|
52 return doc; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CCodDocument::~CCodDocument() |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 CCodDocument::~CCodDocument() |
|
60 { |
|
61 delete iModel; // Delete (==Cancel) the model... |
|
62 delete iCallback; // ...before deleting (==Cancelling) the callback. |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // CCodDocument::Model() |
|
67 // --------------------------------------------------------- |
|
68 // |
|
69 CCodEngBase& CCodDocument::Model() |
|
70 { |
|
71 return *iModel; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------- |
|
75 // CCodDocument::CreateAppUiL() |
|
76 // --------------------------------------------------------- |
|
77 // |
|
78 CEikAppUi* CCodDocument::CreateAppUiL() |
|
79 { |
|
80 return new (ELeave) CCodAppUi( iCod ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------- |
|
84 // CCodDocument::OpenFileL() |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 CFileStore* CCodDocument::OpenFileL |
|
88 ( TBool aDoOpen, const TDesC& aFilename, RFs& aFs ) |
|
89 { |
|
90 CLOG(( 2, _L("-> CCodDocument::OpenFileL aDoOpen(0x%x) aFname<%S>"), \ |
|
91 aDoOpen, &aFilename )); |
|
92 CFileStore* store( NULL ); |
|
93 if ( aDoOpen ) |
|
94 { |
|
95 RFile file; |
|
96 TInt err = file.Open( aFs, aFilename, |
|
97 EFileShareReadersOnly | EFileStream | EFileRead ); |
|
98 if ( err == KErrInUse ) |
|
99 { |
|
100 err = file.Open( aFs, aFilename, |
|
101 EFileShareAny | EFileStream | EFileRead ); |
|
102 } |
|
103 User::LeaveIfError( err ); |
|
104 CleanupClosePushL<RFile>( file ); |
|
105 store = OpenFileL( aFs, file ); |
|
106 CleanupStack::PopAndDestroy(); // close file |
|
107 } |
|
108 CLOG(( 2, _L("<- CCodDocument::OpenFileL") )); |
|
109 return store; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CCodDocument::OpenFileL() |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 CFileStore* CCodDocument::OpenFileL( RFs& /*aFs*/, RFile& aFile ) |
|
117 { |
|
118 CLOG(( 2, _L("-> CCodDocument::OpenFileL (RFs+RFile)") )); |
|
119 CFileStore* store( NULL ); |
|
120 OpenFileL( store, aFile ); |
|
121 CLOG(( 2, _L("<- CCodDocument::OpenFileL (RFs+RFile)") )); |
|
122 return store; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------- |
|
126 // CCodDocument::OpenFileL() |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 void CCodDocument::OpenFileL( CFileStore*& aFileStore, RFile& aFile ) |
|
130 { |
|
131 CLOG(( 2, _L("-> CCodDocument::OpenFileL (RFile)") )); |
|
132 if( iModel->IsActive() ) |
|
133 { |
|
134 // Busy with something else. |
|
135 // Maybe we should Cancel the ongoing operation? I don't think so. |
|
136 CLOG(( 2, _L(" leave with KErrNotReady") )); |
|
137 User::Leave( KErrNotReady ); |
|
138 } |
|
139 |
|
140 // Get params, extract the UI related ones. |
|
141 const CAiwGenericParamList* params = GetInputParameters(); |
|
142 if ( params ) |
|
143 { |
|
144 TBool silent( EFalse ); |
|
145 TBool suppressNextUrl( EFalse ); |
|
146 TBool suppressLaunch( EFalse ); |
|
147 CodUtil::GetBoolParam( silent, EGenericParamSilentDownload, *params ); |
|
148 CodUtil::GetBoolParam |
|
149 ( suppressNextUrl, EGenericParamSuppressNextUrl, *params ); |
|
150 CodUtil::GetBoolParam |
|
151 ( suppressLaunch, EGenericParamSuppressLaunch, *params ); |
|
152 CodAppUi()->SetServiceFlow( silent, suppressNextUrl, suppressLaunch ); |
|
153 } |
|
154 |
|
155 // Read descriptor data from file. |
|
156 TInt fSize; |
|
157 User::LeaveIfError( aFile.Size( fSize ) ); |
|
158 HBufC8* buf = HBufC8::NewLC( fSize ); |
|
159 TPtr8 bufP( buf->Des() ); |
|
160 User::LeaveIfError( aFile.Read( bufP ) ); |
|
161 |
|
162 iModel->SetL( bufP, &iCallback->iStatus, params, NULL ); |
|
163 iCallback->CallbackOnCompletion |
|
164 ( TCallBack( StaticOpenFileDone, this ) ); |
|
165 CleanupStack::PopAndDestroy( buf ); |
|
166 aFileStore = NULL; |
|
167 CLOG(( 2, _L("<- CCodDocument::OpenFileL (RFile)") )); |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // CCodDocument::CCodDocument() |
|
172 // --------------------------------------------------------- |
|
173 // |
|
174 CCodDocument::CCodDocument( CEikApplication& aApp, TBool aCod ) |
|
175 : CAiwGenericParamConsumer( aApp ), iCod( aCod ) |
|
176 { |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // CCodDocument::ConstructL() |
|
181 // --------------------------------------------------------- |
|
182 // |
|
183 void CCodDocument::ConstructL() |
|
184 { |
|
185 if ( iCod ) |
|
186 { |
|
187 iModel = CCodEng::NewL( iEikProcess, NULL ); |
|
188 } |
|
189 else |
|
190 { |
|
191 iModel = CDdEng::NewL( iEikProcess, NULL ); |
|
192 } |
|
193 |
|
194 iCallback = new ( ELeave ) CRequestCompleteCallback(); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------- |
|
198 // CCodDocument::OpenFileDone() |
|
199 // --------------------------------------------------------- |
|
200 // |
|
201 void CCodDocument::OpenFileDone() |
|
202 { |
|
203 CLOG(( 2, _L("-> CCodDocument::OpenFileDone") )); |
|
204 // Note that it is possible that we don't have iAppUi here. There is |
|
205 // blank screen with "Back" softkey while parsing the COD. |
|
206 // During that, "Back" command may be issued and |
|
207 // processed by AppUi during the wait. |
|
208 if ( iAppUi ) |
|
209 { |
|
210 CodAppUi()->OpenFileDone( iCallback->iStatus.Int() ); |
|
211 } |
|
212 CLOG(( 2, _L("<- CCodDocument::OpenFileDone") )); |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------- |
|
216 // CCodDocument::StaticOpenFileDone() |
|
217 // --------------------------------------------------------- |
|
218 // |
|
219 TInt CCodDocument::StaticOpenFileDone( TAny* aPtr ) |
|
220 { |
|
221 STATIC_CAST( CCodDocument*, aPtr )->OpenFileDone(); |
|
222 return EFalse; // TCallback should return EFalse as TInt. |
|
223 } |