|
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: Active object to handle asynchronious. |
|
15 * A base class for AudiomessageLaunchOperation-, |
|
16 * AudiomessageInsertOperation-,AudiomessageSaveOperation- and |
|
17 * AudiomessageSendOperation -classes |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 #include <basched.h> |
|
24 #include <StringLoader.h> |
|
25 |
|
26 #include <mmsvattachmentmanager.h> |
|
27 #include <mmsvattachmentmanagersync.h> |
|
28 #include <mmsclient.h> |
|
29 #include <MsgMimeTypes.h> |
|
30 #include <MsgEditorCommon.h> |
|
31 #include <cmsvmimeheaders.h> |
|
32 #include <audiomessage.rsg> |
|
33 #include "audiomessageoperation.h" |
|
34 |
|
35 const TInt KSecondAsMilliSeconds( 1000 ); |
|
36 _LIT( KSmilFile,"pres.smil"); |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // --------------------------------------------------------- |
|
41 // CAudioMessageOperation::Constructor |
|
42 // --------------------------------------------------------- |
|
43 // |
|
44 CAudioMessageOperation::CAudioMessageOperation( |
|
45 MAmsOperationObserver& aObserver, |
|
46 CAudioMessageDocument& aDocument ) : CActive( EPriorityStandard ), |
|
47 iObserver( aObserver ), |
|
48 iDocument( aDocument ), |
|
49 iError( 0 ) |
|
50 { |
|
51 CActiveScheduler::Add( this ); |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CAudioMessageOperation::Destructor |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 CAudioMessageOperation::~CAudioMessageOperation() |
|
60 { |
|
61 delete iStore; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------- |
|
65 // CAudioMessageOperation::CompleteSelf |
|
66 // --------------------------------------------------------- |
|
67 // |
|
68 void CAudioMessageOperation::CompleteSelf( TInt aError ) |
|
69 { |
|
70 iStatus = KRequestPending; |
|
71 TRequestStatus* pStatus = &iStatus; |
|
72 SetActive(); |
|
73 User::RequestComplete( pStatus, aError ); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // CAudioMessageOperation::DoEditInitL |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 void CAudioMessageOperation::DoEditInitL( ) |
|
81 { |
|
82 iStore = iDocument.Mtm( ).Entry( ).EditStoreL( ); |
|
83 iManager = &( iStore->AttachmentManagerL( ) ); |
|
84 iManagerSync = &( iStore->AttachmentManagerExtensionsL( ) ); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CAudioMessageOperation::DoReadInitL |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 void CAudioMessageOperation::DoReadInitL( ) |
|
92 { |
|
93 iStore = iDocument.Mtm( ).Entry( ).ReadStoreL( ); |
|
94 iManager = &( iStore->AttachmentManagerL( ) ); |
|
95 iManagerSync = &( iStore->AttachmentManagerExtensionsL( ) ); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CAudioMessageOperation::MakeCommitL |
|
100 // --------------------------------------------------------- |
|
101 // |
|
102 void CAudioMessageOperation::MakeCommitL( ) |
|
103 { |
|
104 iStore->CommitL( ); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CAudioMessageOperation::UnInit |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 void CAudioMessageOperation::UnInit( ) |
|
112 { |
|
113 delete iStore; |
|
114 iStore = NULL; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CAudioMessageOperation::CheckAttasL |
|
119 // Check how many voice and smil attas there are |
|
120 // Save atta id and smil id |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 TInt CAudioMessageOperation::CheckAttasL( ) |
|
124 { |
|
125 TInt count = iManager->AttachmentCount(); |
|
126 CMsvAttachment* atta = NULL; |
|
127 TInt numOfSmils( 0 ); |
|
128 TInt numOfAudios( 0 ); |
|
129 for( TInt a = 0; a < count; a++ ) |
|
130 { |
|
131 atta = iManager->GetAttachmentInfoL( a ); |
|
132 CleanupStack::PushL( atta ); |
|
133 TDataType k = atta->MimeType(); |
|
134 |
|
135 if ( k.Des8().CompareF( KMsgMimeAudioAmr ) == 0 ) |
|
136 { |
|
137 numOfAudios++; |
|
138 iDocument.iAudio = atta->Id( ); |
|
139 } |
|
140 |
|
141 if ( k.Des8().CompareF( KMsgMimeSmil ) == 0 ) |
|
142 { |
|
143 numOfSmils++; |
|
144 iDocument.iSmil = atta->Id( ); |
|
145 } |
|
146 CleanupStack::PopAndDestroy( atta ); |
|
147 } |
|
148 |
|
149 if( numOfAudios > 1 || numOfSmils > 1 ) |
|
150 { |
|
151 // This case seems to be impossible in real life |
|
152 SetError( EAmsMultipleFiles ); |
|
153 CompleteSelf( -1 ); |
|
154 return EAmsMultipleFiles; |
|
155 } |
|
156 |
|
157 return KErrNone; |
|
158 } |
|
159 |
|
160 |
|
161 // --------------------------------------------------------- |
|
162 // CAudioMessageOperation::AddSmilL |
|
163 // --------------------------------------------------------- |
|
164 // |
|
165 void CAudioMessageOperation::AddSmilL() |
|
166 { |
|
167 TFileName file( KSmilFile ); |
|
168 CMsvAttachment* attachment = CMsvAttachment::NewL( CMsvAttachment::EMsvFile ); |
|
169 CleanupStack::PushL( attachment ); |
|
170 |
|
171 if( iDocument.iSmil ) |
|
172 { // Remove the old smil |
|
173 TInt oldSmil = TMsvIdToIndexL( iDocument.iSmil ); |
|
174 if ( oldSmil != KErrNotFound ) |
|
175 { |
|
176 iStore->AttachmentManagerExtensionsL( ).RemoveAttachmentL( oldSmil ); |
|
177 } |
|
178 } |
|
179 |
|
180 RFile *editFile = new ( ELeave ) RFile; |
|
181 iManager->CreateAttachmentL( file, *editFile, attachment, iStatus ); |
|
182 CleanupStack::Pop( attachment ); |
|
183 delete iHeaders; |
|
184 iHeaders = NULL; |
|
185 iHeaders = CMsvMimeHeaders::NewL( ); |
|
186 iHeaders->SetContentLocationL( KSmilFile ); |
|
187 TInt slash = KMsgMimeSmil().Locate( '/' ); |
|
188 iHeaders->SetContentTypeL( KMsgMimeSmil().Left( slash ) ); |
|
189 iHeaders->SetContentSubTypeL( KMsgMimeSmil().Mid( slash + 1 ) ); |
|
190 attachment->SetMimeTypeL( KMsgMimeSmil ); |
|
191 iDocument.iSmil = attachment->Id( ); |
|
192 |
|
193 TInt dur = I64INT( iDocument.GetDuration().Int64() ) / KSecondAsMilliSeconds; |
|
194 |
|
195 CArrayFixFlat<TInt>* array = new ( ELeave ) CArrayFixFlat<TInt>( 3 ); |
|
196 CleanupStack::PushL( array ); |
|
197 array->AppendL( MsgEditorCommons::ScreenWidth() ); |
|
198 array->AppendL( MsgEditorCommons::ScreenHeigth() ); |
|
199 array->AppendL( dur ); |
|
200 TInt resId = R_AUDIOMESSAGE_SMIL; |
|
201 |
|
202 CDesCArrayFlat* arrayForFileName = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
203 CleanupStack::PushL( arrayForFileName ); |
|
204 //дце replaced earlier in iFileName |
|
205 arrayForFileName->AppendL( iContentLocationFileName ); |
|
206 HBufC* smil = StringLoader::LoadLC( resId, *arrayForFileName, *array ); |
|
207 |
|
208 // convert the smil to 8-bit |
|
209 HBufC8* smil8 = HBufC8::NewLC( smil->Des( ).Length( ) ); |
|
210 smil8->Des().Copy( smil->Des( ) ); |
|
211 |
|
212 RFileWriteStream smilStream( *editFile ); |
|
213 smilStream.PushL( ); |
|
214 delete editFile; |
|
215 editFile = NULL; |
|
216 smilStream.WriteL( *smil8 ); |
|
217 smilStream.Close( ); |
|
218 smilStream.Pop( ); |
|
219 CleanupStack::PopAndDestroy( 4, array ); // smil, array, arrayForFileName |
|
220 |
|
221 iHeaders->StoreL( *attachment ); |
|
222 if ( iHeaders ) |
|
223 { |
|
224 delete iHeaders; |
|
225 iHeaders=NULL; |
|
226 } |
|
227 MakeCommitL( ); |
|
228 } |
|
229 |
|
230 |
|
231 // --------------------------------------------------------- |
|
232 // CAudioMessageOperation::TMsvIdToIndexL |
|
233 // --------------------------------------------------------- |
|
234 // |
|
235 TInt CAudioMessageOperation::TMsvIdToIndexL( TMsvAttachmentId& aId ) |
|
236 { |
|
237 TInt count = iManager->AttachmentCount( ); |
|
238 CMsvAttachment* atta = NULL; |
|
239 for(TInt a = 0; a<count; a++) |
|
240 { |
|
241 atta = iManager->GetAttachmentInfoL( a ); |
|
242 if ( atta->Id( ) == aId ) |
|
243 { |
|
244 delete atta; |
|
245 return a; |
|
246 } |
|
247 delete atta; |
|
248 } |
|
249 return KErrNotFound; |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------- |
|
253 // CAudioMessageOperation::RunError |
|
254 // --------------------------------------------------------- |
|
255 // |
|
256 TInt CAudioMessageOperation::RunError( TInt aError ) |
|
257 { |
|
258 if ( aError == KLeaveExit ) |
|
259 { |
|
260 return KLeaveExit; |
|
261 } |
|
262 else |
|
263 { |
|
264 SetError( aError ); |
|
265 CompleteSelf( aError ); |
|
266 return KErrNone; |
|
267 } |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------- |
|
271 // CAudioMessageOperation::GetError |
|
272 // --------------------------------------------------------- |
|
273 // |
|
274 TInt CAudioMessageOperation::GetError( ) |
|
275 { |
|
276 return iError; |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------- |
|
280 // CAudioMessageOperation::SetError |
|
281 // --------------------------------------------------------- |
|
282 // |
|
283 void CAudioMessageOperation::SetError( TInt aError ) |
|
284 { |
|
285 iError = aError; |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------- |
|
289 // CAudioMessageOperation::ResetError |
|
290 // --------------------------------------------------------- |
|
291 // |
|
292 void CAudioMessageOperation::ResetError( ) |
|
293 { |
|
294 iError = 0; |
|
295 } |