|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Class that handles message attachment operations: |
|
15 * : insert and delete. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <apmstd.h> |
|
22 #include <cmsvmimeheaders.h> |
|
23 #include <StringLoader.h> |
|
24 #include <mmsvattachmentmanager.h> |
|
25 #include <mmsvattachmentmanagersync.h> |
|
26 #include <MsgEditorCommon.h> |
|
27 #include <MsgMediaInfo.h> |
|
28 #include <MsgMimeTypes.h> |
|
29 #include <audiomessage.rsg> |
|
30 #include "audiomessageinsertoperation.h" |
|
31 #include "audiomessagedocument.h" |
|
32 #include "audiomessagerecorder.h" |
|
33 #include "AudioMessageLogging.h" |
|
34 #include "msgtextutils.h" |
|
35 |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 |
|
40 // --------------------------------------------------------- |
|
41 // CAudioMessageInsertOperation::NewL |
|
42 // --------------------------------------------------------- |
|
43 // |
|
44 CAudioMessageInsertOperation* CAudioMessageInsertOperation::NewL( |
|
45 MAmsOperationObserver& aOperationObserver, |
|
46 CAudioMessageDocument& aDocument, |
|
47 CMsgEditorView& aView ) |
|
48 { |
|
49 CAudioMessageInsertOperation* self = new ( ELeave ) CAudioMessageInsertOperation( |
|
50 aOperationObserver, |
|
51 aDocument, |
|
52 aView ); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CAudioMessageInsertOperation::Constructor |
|
59 // --------------------------------------------------------- |
|
60 // |
|
61 CAudioMessageInsertOperation::CAudioMessageInsertOperation( |
|
62 MAmsOperationObserver& aOperationObserver, |
|
63 CAudioMessageDocument& aDocument, |
|
64 CMsgEditorView& aView ) : CAudioMessageOperation( aOperationObserver, aDocument ), |
|
65 iView( aView ), iState( 0 ), iNew( ETrue ) |
|
66 { |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // CAudioMessageInsertOperation::Destructor |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 CAudioMessageInsertOperation::~CAudioMessageInsertOperation() |
|
75 { |
|
76 Cancel(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CAudioMessageInsertOperation::Insert |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 void CAudioMessageInsertOperation::Insert( CMsgMediaInfo* aInfo, TBool aVal, TBool aNew ) |
|
84 { |
|
85 iRemove = aVal; |
|
86 iNew = aNew; |
|
87 ResetError(); |
|
88 iInfo = aInfo; |
|
89 iState = EAmsInit; |
|
90 CompleteSelf( KErrNone ); |
|
91 } |
|
92 |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CAudioMessageInsertOperation::RunL |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 void CAudioMessageInsertOperation::RunL() |
|
99 { |
|
100 if ( iStatus.Int() != KErrNone ) |
|
101 { |
|
102 SetError( iStatus.Int() ); |
|
103 UnInit(); |
|
104 iObserver.EditorOperationEvent( |
|
105 EAmsOperationInsert, |
|
106 EAmsOperationError ); |
|
107 } |
|
108 else |
|
109 { |
|
110 DoInsertStepL(); |
|
111 } |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------- |
|
116 // CAudioMessageInsertOperation::DoInsertStepL |
|
117 // --------------------------------------------------------- |
|
118 // |
|
119 void CAudioMessageInsertOperation::DoInsertStepL() |
|
120 { |
|
121 switch ( iState ) |
|
122 { |
|
123 case EAmsInit: |
|
124 DoEditInitL(); |
|
125 iState = EAmsCheckAttas; |
|
126 CompleteSelf( KErrNone ); |
|
127 break; |
|
128 case EAmsCheckAttas: |
|
129 CheckAttasL( ); |
|
130 |
|
131 if ( iRemove == EFalse) |
|
132 { |
|
133 iState = EAmsSetAudio; |
|
134 } |
|
135 else |
|
136 { |
|
137 iState = EAmsRemoveAudio; |
|
138 } |
|
139 CompleteSelf( KErrNone ); |
|
140 break; |
|
141 case EAmsRemoveAudio: |
|
142 DoRemoveAudioL(); |
|
143 iState = EAmsRemoveSmil; |
|
144 CompleteSelf( KErrNone ); |
|
145 break; |
|
146 case EAmsRemoveSmil: |
|
147 DoRemoveSmilL(); |
|
148 iState = EAmsCommit; |
|
149 CompleteSelf( KErrNone ); |
|
150 break; |
|
151 case EAmsSetAudio: |
|
152 DoCreateNewAudioAttaL( ); |
|
153 iState = EAmsSetDuration; |
|
154 SetActive(); |
|
155 break; |
|
156 case EAmsSetDuration: |
|
157 DoSetDurationL( ); |
|
158 iState = EAmsInsertSmil; |
|
159 CompleteSelf( KErrNone ); |
|
160 break; |
|
161 case EAmsInsertSmil: |
|
162 AddSmilL(); |
|
163 iState = EAmsCommit; |
|
164 SetActive(); |
|
165 break; |
|
166 case EAmsCommit: |
|
167 MakeCommitL(); |
|
168 UnInit(); |
|
169 iState = EAmsInsertReady; |
|
170 CompleteSelf( KErrNone ); |
|
171 break; |
|
172 case EAmsInsertReady: |
|
173 if ( iRemove == EFalse ) |
|
174 { |
|
175 iObserver.EditorOperationEvent( |
|
176 EAmsOperationInsert, |
|
177 EAmsOperationComplete ); |
|
178 } |
|
179 else |
|
180 { |
|
181 iObserver.EditorOperationEvent( |
|
182 EAmsOperationRemove, |
|
183 EAmsOperationComplete ); |
|
184 } |
|
185 break; |
|
186 default: |
|
187 break; |
|
188 } |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------- |
|
192 // CAudioMessageInsertOperation::DoCreateNewAudioAttaL |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 void CAudioMessageInsertOperation::DoCreateNewAudioAttaL( ) |
|
196 { |
|
197 CMsvAttachment* attachment = CMsvAttachment::NewL( CMsvAttachment::EMsvFile ); |
|
198 CleanupStack::PushL( attachment ); |
|
199 if ( iDocument.iAudio ) |
|
200 { // Remove the old audio |
|
201 TInt oldAudio = TMsvIdToIndexL( iDocument.iAudio ); |
|
202 if ( oldAudio != KErrNotFound ) |
|
203 { |
|
204 iStore->AttachmentManagerExtensionsL( ).RemoveAttachmentL( oldAudio ); |
|
205 } |
|
206 } |
|
207 TParsePtrC parse( iInfo->FullFilePath() ); |
|
208 attachment->SetAttachmentNameL( parse.NameAndExt() ); |
|
209 iManager->AddAttachmentL( iInfo->FullFilePath(), attachment, iStatus ); |
|
210 CleanupStack::Pop( attachment ); |
|
211 iHeaders = CMsvMimeHeaders::NewL( ); |
|
212 TDataType mime = iInfo->MimeType( ); |
|
213 |
|
214 iContentLocationFileName = parse.NameAndExt(); |
|
215 CMsgTextUtils::TrimAndRemoveNonAlphaDigit( iContentLocationFileName ); |
|
216 iHeaders->SetContentLocationL( iContentLocationFileName ); |
|
217 |
|
218 TInt slash = mime.Des8().Locate( '/' ); |
|
219 iHeaders->SetContentTypeL( mime.Des8().Left( slash ) ); |
|
220 iHeaders->SetContentSubTypeL( mime.Des8().Mid( slash + 1 ) ); |
|
221 attachment->SetMimeTypeL( mime.Des8() ); |
|
222 iDocument.iAudio = attachment->Id( ); |
|
223 |
|
224 iHeaders->StoreL( *attachment ); |
|
225 if ( iHeaders ) |
|
226 { |
|
227 delete iHeaders; |
|
228 iHeaders=NULL; |
|
229 } |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // CAudioMessageInsertOperation::DoCancel |
|
234 // --------------------------------------------------------- |
|
235 // |
|
236 void CAudioMessageInsertOperation::DoCancel() |
|
237 { |
|
238 if ( iManager ) |
|
239 { |
|
240 iManager->CancelRequest(); |
|
241 } |
|
242 } |
|
243 |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CAudioMessageInsertOperation::CheckSizeForInsert |
|
247 // --------------------------------------------------------- |
|
248 // |
|
249 TBool CAudioMessageInsertOperation::CheckSizeForInsert() |
|
250 { |
|
251 if( iInfo ) |
|
252 { |
|
253 if ( TUint( iInfo->FileSize() ) > iDocument.MaxMessageSize() ) |
|
254 { |
|
255 SetError( EAmsInsertTooBig ); |
|
256 return EFalse; |
|
257 } |
|
258 else |
|
259 { |
|
260 return ETrue; |
|
261 } |
|
262 } |
|
263 return ETrue; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 // CAudioMessageInsertOperation::DoRemoveAudioL |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 void CAudioMessageInsertOperation::DoRemoveAudioL( ) |
|
271 { |
|
272 if ( iDocument.iAudio ) |
|
273 { // Remove the old audio |
|
274 TInt oldAudio = TMsvIdToIndexL( iDocument.iAudio ); |
|
275 iStore->AttachmentManagerExtensionsL( ).RemoveAttachmentL( oldAudio ); |
|
276 } |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------- |
|
280 // CAudioMessageInsertOperation::DoRemoveSmilL |
|
281 // --------------------------------------------------------- |
|
282 // |
|
283 void CAudioMessageInsertOperation::DoRemoveSmilL( ) |
|
284 { |
|
285 if ( iDocument.iSmil ) |
|
286 { // Remove the old audiosmil |
|
287 TInt oldSmil = TMsvIdToIndexL( iDocument.iSmil ); |
|
288 iStore->AttachmentManagerExtensionsL( ).RemoveAttachmentL( oldSmil ); |
|
289 } |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CAudioMessageInsertOperation::DoSetDurationL |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 void CAudioMessageInsertOperation::DoSetDurationL( ) |
|
297 { |
|
298 if ( iNew ) |
|
299 { |
|
300 ; //Duration already set into document object |
|
301 } |
|
302 else |
|
303 { |
|
304 //We must get the duration for the SMIL |
|
305 RFile attaFile = iManager->GetAttachmentFileL( iDocument.iAudio ); |
|
306 CleanupClosePushL( attaFile ); // RFile must be closed |
|
307 CAudioMessageRecorder *recorder = CAudioMessageRecorder::NewL( attaFile, EFalse ); |
|
308 iDocument.SetDuration( recorder->GetDuration() ); |
|
309 delete recorder; |
|
310 recorder = NULL; |
|
311 CleanupStack::PopAndDestroy( &attaFile ); |
|
312 } |
|
313 |
|
314 } |