|
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 "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: |
|
15 * CPostcardOperation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // ========== INCLUDE FILES ================================ |
|
22 |
|
23 #include <badesca.h> |
|
24 #include <e32std.h> |
|
25 #include <apmstd.h> // TDataType |
|
26 |
|
27 #include <mmsvattachmentmanager.h> |
|
28 #include <mmsvattachmentmanagersync.h> |
|
29 #include <cmsvattachment.h> |
|
30 #include <cmsvmimeheaders.h> |
|
31 |
|
32 #include <mmsclient.h> |
|
33 |
|
34 #include <MsgMimeTypes.h> |
|
35 |
|
36 #include <Postcard.rsg> |
|
37 #include "PostcardOperation.h" |
|
38 |
|
39 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
40 |
|
41 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
42 |
|
43 // ========== CONSTANTS ==================================== |
|
44 |
|
45 // ========== MACROS ======================================= |
|
46 |
|
47 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
48 |
|
49 // ========== MODULE DATA STRUCTURES ======================= |
|
50 |
|
51 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
52 |
|
53 // ========== LOCAL FUNCTIONS ============================== |
|
54 |
|
55 // ========== MEMBER FUNCTIONS ============================= |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CPostcardOperation::CPostcardOperation |
|
59 // --------------------------------------------------------- |
|
60 CPostcardOperation::CPostcardOperation( |
|
61 MPostcardOperationObserver& aObserver, |
|
62 CPostcardDocument& aDocument, |
|
63 CPostcardAppUi& aAppUi, |
|
64 RFs& aFs ) : |
|
65 CActive( EPriorityStandard ), |
|
66 iObserver( aObserver ), |
|
67 iDocument( aDocument ), |
|
68 iAppUi( aAppUi ), |
|
69 iFs( aFs ), |
|
70 iError( 0 ), |
|
71 iStore( NULL ), |
|
72 iHeaders( NULL ), |
|
73 iImage( 0 ), |
|
74 iText( 0 ), |
|
75 iRecipient( 0 ), |
|
76 iCommit( EFalse ) |
|
77 { |
|
78 CActiveScheduler::Add( this ); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CPostcardOperation::CPostcardOperation |
|
83 // --------------------------------------------------------- |
|
84 CPostcardOperation::~CPostcardOperation( ) |
|
85 { |
|
86 delete iHeaders; |
|
87 if( iStore ) |
|
88 { |
|
89 delete iStore; |
|
90 } |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // InitL |
|
95 // --------------------------------------------------------- |
|
96 void CPostcardOperation::InitL( ) |
|
97 { |
|
98 if( iDocument.MessageType( ) == EPostcardSent ) |
|
99 { |
|
100 iStore = iDocument.Mtm( ).Entry( ).ReadStoreL( ); |
|
101 } |
|
102 else |
|
103 { |
|
104 iStore = iDocument.Mtm( ).Entry( ).EditStoreL( ); |
|
105 } |
|
106 iManager = &( iStore->AttachmentManagerL( ) ); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------- |
|
110 // UnInitL |
|
111 // --------------------------------------------------------- |
|
112 void CPostcardOperation::UnInitL( ) |
|
113 { |
|
114 if( iCommit ) |
|
115 { |
|
116 iStore->CommitL( ); |
|
117 } |
|
118 delete iStore; |
|
119 iStore = NULL; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------- |
|
123 // CheckAttas |
|
124 // --------------------------------------------------------- |
|
125 TInt CPostcardOperation::CheckAttasL( ) |
|
126 { |
|
127 // Goes thru the attas and check how many images, text and recipients there are |
|
128 TInt count = iManager->AttachmentCount( ); |
|
129 CMsvAttachment* atta = NULL; |
|
130 TInt numOfImages(0), numOfTexts(0), numOfRecipients(0), numOfOthers(0); |
|
131 TInt numOfSmils(0); |
|
132 for(TInt a = 0; a<count; a++) |
|
133 { |
|
134 atta = iManager->GetAttachmentInfoL( a ); |
|
135 CleanupStack::PushL( atta ); |
|
136 switch( RecogniseFileType( atta->MimeType( ) ) ) |
|
137 { |
|
138 case EPostcardFileImage: |
|
139 numOfImages++; |
|
140 iImage = atta->Id( ); |
|
141 break; |
|
142 case EPostcardFileText: |
|
143 numOfTexts++; |
|
144 iText = atta->Id( ); |
|
145 break; |
|
146 case EPostcardFileAddress: |
|
147 numOfRecipients++; |
|
148 iRecipient = atta->Id( ); |
|
149 break; |
|
150 case EPostcardFileSmil: |
|
151 numOfSmils++; |
|
152 iSmil = atta->Id( ); |
|
153 break; |
|
154 default: |
|
155 { |
|
156 if( atta->AttachmentName( ).Find( _L("X-Nokia-PhonebookId_") ) != -1 ) |
|
157 { |
|
158 iText = atta->Id( ); |
|
159 numOfTexts++; |
|
160 } |
|
161 else |
|
162 { |
|
163 numOfOthers++; |
|
164 } |
|
165 break; |
|
166 } |
|
167 } |
|
168 CleanupStack::PopAndDestroy( atta ); |
|
169 } |
|
170 if( numOfImages > 1 || numOfTexts > 1 || numOfRecipients > 1 ) |
|
171 { |
|
172 // Do something here as there's invalid number of attachments! |
|
173 SetError( R_POSTCARD_MULTIPLE_FILES ); |
|
174 CompleteSelf( -1 ); |
|
175 return R_POSTCARD_MULTIPLE_FILES; |
|
176 } |
|
177 if( numOfOthers > 0 || numOfSmils > 1 ) |
|
178 { |
|
179 SetError( R_POSTCARD_FORMAT_NOT_SUPPORTED ); |
|
180 CompleteSelf( -1 ); |
|
181 return R_POSTCARD_FORMAT_NOT_SUPPORTED; |
|
182 } |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------- |
|
187 // CompleteSelf |
|
188 // --------------------------------------------------------- |
|
189 void CPostcardOperation::CompleteSelf( TInt aError ) |
|
190 { |
|
191 iStatus = KRequestPending; |
|
192 TRequestStatus* pStatus = &iStatus; |
|
193 SetActive( ); |
|
194 User::RequestComplete( pStatus, aError ); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------- |
|
198 // GetErrors |
|
199 // --------------------------------------------------------- |
|
200 TInt CPostcardOperation::GetError( ) |
|
201 { |
|
202 return iError; |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // SetError |
|
207 // --------------------------------------------------------- |
|
208 void CPostcardOperation::SetError( TInt aError ) |
|
209 { |
|
210 iError = aError; |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------- |
|
214 // ResetErrors |
|
215 // --------------------------------------------------------- |
|
216 void CPostcardOperation::ResetError( ) |
|
217 { |
|
218 iError = 0; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // RecogniseFileType |
|
223 // --------------------------------------------------------- |
|
224 TPostcardFileType CPostcardOperation::RecogniseFileType( const TDataType& aMimeType ) |
|
225 { |
|
226 if ( aMimeType.Des8( ).CompareF( KMsgMimeTextPlain ) == 0 ) |
|
227 { |
|
228 return EPostcardFileText; |
|
229 } |
|
230 else if ( aMimeType.Des8( ).CompareF( KMsgMimeImageJpeg ) == 0 ) |
|
231 { |
|
232 return EPostcardFileImage; |
|
233 } |
|
234 else if ( aMimeType.Des8( ).CompareF( KMsgMimeImagePng ) == 0 ) |
|
235 { |
|
236 return EPostcardFileImage; |
|
237 } |
|
238 else if ( aMimeType.Des8( ).CompareF( KMsgMimeImageGif ) == 0 ) |
|
239 { |
|
240 return EPostcardFileImage; |
|
241 } |
|
242 else if ( aMimeType.Des8( ).CompareF( KMsgMimeVCard ) == 0 ) |
|
243 { |
|
244 return EPostcardFileAddress; |
|
245 } |
|
246 else if ( aMimeType.Des8( ).CompareF( KMsgMimeSmil ) == 0 ) |
|
247 { |
|
248 return EPostcardFileSmil; |
|
249 } |
|
250 else |
|
251 { |
|
252 return EPostcardFileUnknown; |
|
253 } |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------- |
|
257 // CPostcardOperation::TMsvIdToIndex |
|
258 // --------------------------------------------------------- |
|
259 TInt CPostcardOperation::TMsvIdToIndexL( TMsvAttachmentId& aId ) |
|
260 { |
|
261 TInt count = iManager->AttachmentCount( ); |
|
262 CMsvAttachment* atta = NULL; |
|
263 for(TInt a = 0; a<count; a++) |
|
264 { |
|
265 atta = iManager->GetAttachmentInfoL( a ); |
|
266 if( atta->Id( ) == aId ) |
|
267 { |
|
268 delete atta; |
|
269 return a; |
|
270 } |
|
271 delete atta; |
|
272 } |
|
273 return KErrNotFound; |
|
274 } |
|
275 |
|
276 // EOF |