|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Generic File Parser: |
|
15 // - Operator logo, OTA bitmap, parser |
|
16 // - Ringing Tones |
|
17 // Still in a rudimentary shape, pending specifications and design from Symbian. |
|
18 // At the present the parser can only parse an Operator Logo Message containing |
|
19 // an OTA bitmap. |
|
20 // When ParseL is called the message is passed to the base class StoreL method, |
|
21 // which converts the descriptor to 8bit format,ie binary, |
|
22 // and then saves it as an attachment file. |
|
23 // Possibles: May have to implement a ProcessL fn to either save the file in a different directory |
|
24 // or launch an application, after the user presses the accept button in the viewer. |
|
25 // |
|
26 // |
|
27 |
|
28 |
|
29 #include <msventry.h> |
|
30 #include <biodb.h> |
|
31 // |
|
32 #include <gfp.h> |
|
33 |
|
34 |
|
35 // |
|
36 // Constructor |
|
37 // |
|
38 CMsvGenericFileParser::CMsvGenericFileParser(CRegisteredParserDll& aRegisteredParserDll, CMsvEntry& aEntry, RFs& aFs) |
|
39 : CBaseScriptParser2(aRegisteredParserDll, aEntry, aFs), |
|
40 iState(0), iReport(0), iCompleted(0) |
|
41 { |
|
42 } |
|
43 |
|
44 // |
|
45 // Factory methods |
|
46 // |
|
47 EXPORT_C CMsvGenericFileParser* CMsvGenericFileParser::NewL(CRegisteredParserDll& aRegisteredParserDll, CMsvEntry& aEntry, RFs& aFs) |
|
48 { |
|
49 CMsvGenericFileParser* self = new (ELeave) CMsvGenericFileParser(aRegisteredParserDll, aEntry, aFs); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CMsvGenericFileParser::ConstructL() |
|
57 { |
|
58 CActiveScheduler::Add(this); |
|
59 } |
|
60 |
|
61 CMsvGenericFileParser::~CMsvGenericFileParser() |
|
62 { |
|
63 if (iParsedFieldArray != NULL) |
|
64 { |
|
65 iParsedFieldArray->ResetAndDestroy(); |
|
66 delete iParsedFieldArray; |
|
67 } |
|
68 if (iSmsBuf) |
|
69 delete iSmsBuf; |
|
70 } |
|
71 |
|
72 void CMsvGenericFileParser::ParseL(TRequestStatus& aStatus, const TDesC& aSms) |
|
73 { |
|
74 TMsvEntry entry = iEntry.Entry(); // Get the generic stuff |
|
75 iEntryId = entry.Id(); // store the TMsvId |
|
76 iBioType= entry.iBioType; |
|
77 |
|
78 __ASSERT_DEBUG((entry.MtmData3() == 0 || entry.MtmData3() == 1), |
|
79 User::Panic(_L("GXXP-DLL"),KErrGeneral)); |
|
80 |
|
81 // Already parsed.... |
|
82 if(entry.MtmData3() == 1) |
|
83 { |
|
84 iReport = &aStatus; |
|
85 User::RequestComplete(iReport, KErrNone); |
|
86 } |
|
87 // not parsed |
|
88 else if(entry.MtmData3() == 0) |
|
89 { |
|
90 if (iSettings!= NULL) |
|
91 { |
|
92 delete iSettings; |
|
93 iSettings = NULL; |
|
94 } |
|
95 iSettings = aSms.AllocL(); // Allocate new HBufC object |
|
96 ChangeStateL(EParseMessage); //Don't set initial request -just parse it??? |
|
97 aStatus = KRequestPending; |
|
98 iReport = &aStatus; |
|
99 } |
|
100 else |
|
101 { |
|
102 User::Leave(KErrNotSupported); |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 // |
|
108 // ProcessL() -- Currently, the parser doesn't actually use a separate |
|
109 // commit phase to save any information to persistant . |
|
110 // store. This is done as part of the ParseL function. Therefore |
|
111 // this function is superflous, and is only required to satisfy |
|
112 // the base class inheritance requirements. This may change... |
|
113 // .. Complete KErrNotSupported.. |
|
114 // |
|
115 void CMsvGenericFileParser::ProcessL(TRequestStatus& aStatus) |
|
116 { |
|
117 iReport = &aStatus; |
|
118 User::RequestComplete(iReport, KErrNotSupported); |
|
119 } |
|
120 |
|
121 void CMsvGenericFileParser::DoCancel() |
|
122 { |
|
123 User::RequestComplete(iReport,KErrCancel); |
|
124 } |
|
125 |
|
126 void CMsvGenericFileParser::RunL() |
|
127 { |
|
128 iCompleted = iStatus.Int(); |
|
129 if (iCompleted != KErrNone) |
|
130 { |
|
131 User::RequestComplete(iReport,iCompleted); |
|
132 return; |
|
133 } |
|
134 |
|
135 switch (iState) |
|
136 { |
|
137 case EParseMessage: |
|
138 TRAPD(err, ChangeStateL(ECompleteMessage)); |
|
139 if(err != KErrNone) |
|
140 { |
|
141 User::RequestComplete(iReport, err); |
|
142 } |
|
143 break; |
|
144 |
|
145 case ECompleteMessage: |
|
146 User::RequestComplete(iReport, KErrNone); |
|
147 break; |
|
148 |
|
149 default: |
|
150 break; |
|
151 } |
|
152 } |
|
153 |
|
154 void CMsvGenericFileParser::ChangeStateL(TParseSession aState) |
|
155 { |
|
156 iState = aState; |
|
157 switch (iState) |
|
158 { |
|
159 case EParseMessage: |
|
160 ParseMessageL(); |
|
161 break; |
|
162 |
|
163 case ECompleteMessage: |
|
164 CompleteMessageL(); |
|
165 break; |
|
166 |
|
167 default: |
|
168 break; |
|
169 } |
|
170 RequestComplete(iStatus, KErrNone); |
|
171 |
|
172 SetActive(); |
|
173 } |
|
174 |
|
175 void CMsvGenericFileParser::ParseMessageL() |
|
176 { |
|
177 // Header of message has already been stripped away by Socket Observer |
|
178 // The message body is therefore our binary data converted to unicode. |
|
179 // We need to call a function to convert descriptor and create an |
|
180 // eight bit attachment file. Also want to put a message into the body |
|
181 |
|
182 // Store (Ringing Tones or OL/VCD/VCL...) to file |
|
183 |
|
184 TUid uid; |
|
185 TInt count =0; |
|
186 HBufC* fileExt=NULL; |
|
187 |
|
188 CBIODatabase* bioDB = CBIODatabase::NewL(iFs); |
|
189 CleanupStack::PushL(bioDB); |
|
190 |
|
191 count = bioDB->BIOCount(); |
|
192 while (count--) |
|
193 { |
|
194 bioDB->GetBioMsgID(count, uid); |
|
195 if(uid == TUid::Uid(iBioType)) |
|
196 { |
|
197 fileExt=bioDB->GetFileExtL(uid).AllocLC();//get file extension |
|
198 break; |
|
199 } |
|
200 } |
|
201 |
|
202 if(fileExt == NULL || fileExt->Length()<=0) |
|
203 User::Leave(KErrNotFound); |
|
204 |
|
205 TBuf<64> tempBuf; |
|
206 tempBuf.Format(_L("%x"), iEntry.Entry().Id()); |
|
207 tempBuf.Append(fileExt->Des()); |
|
208 StoreL(TFileName(tempBuf)); // pass the filename to base class method - creates a new folder |
|
209 // linked to message entry and stores body as an 8 bit attachment file |
|
210 |
|
211 CleanupStack::PopAndDestroy(2);// fileExt, bioDB |
|
212 } |
|
213 |
|
214 void CMsvGenericFileParser::CompleteMessageL() |
|
215 { |
|
216 // Binary data has been saved in attachment file. |
|
217 |
|
218 iEntry.SetEntryL(iEntryId); |
|
219 |
|
220 // Change the current message details |
|
221 TMsvEntry entry= iEntry.Entry(); |
|
222 |
|
223 entry.SetMtmData3(1); // Indicates that we've parsed it.. |
|
224 |
|
225 iEntry.ChangeL(entry); |
|
226 } |
|
227 |
|
228 void CMsvGenericFileParser::RequestComplete(TRequestStatus& aStatus, TInt aError) |
|
229 { |
|
230 TRequestStatus* p = &aStatus; |
|
231 User::RequestComplete(p, aError); |
|
232 } |