|
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 "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: Launches Sendui Editor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "CaUiMessageSender.h" |
|
23 |
|
24 #include <coemain.h> // CCoeEnv |
|
25 #include <CallUI.rsg> // Resources. |
|
26 |
|
27 #include <msvids.h> // KUidMsvLocalServiceMtmValue |
|
28 |
|
29 #include <sendui.h> // CSendAppUi, CSendUi |
|
30 #include <CMessageData.h> // Message data for CSendUi |
|
31 #include <featmgr.h> // Feature manager |
|
32 #include "CaUiLogger.h" // Call Ui Logger |
|
33 |
|
34 // CONSTANTS |
|
35 // The reconnect query options granularity. |
|
36 #ifdef RD_UNIFIED_EDITOR |
|
37 const TInt KCaUiReConQueryOptionsArrayGranularity = 3; |
|
38 #else // RD_UNIFIED_EDITOR |
|
39 const TInt KCaUiReConQueryOptionsArrayGranularity = 4; |
|
40 #endif // RD_UNIFIED_EDITOR |
|
41 |
|
42 const TInt KMtmPop3Uid = 0x10001029; |
|
43 const TInt KMtmImap4Uid = 0x1000102a; |
|
44 const TInt KUidEmail = 0x10001028; |
|
45 const TInt KUidPostCard = 0x10207245; |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CCaUiMessageSender::CCaUiMessageSender |
|
49 // |
|
50 // C++ constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CCaUiMessageSender::CCaUiMessageSender() |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CCaUiMessageSender::~CCaUiMessageSender |
|
61 // |
|
62 // Destructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CCaUiMessageSender::~CCaUiMessageSender() |
|
66 { |
|
67 |
|
68 CAUILOGSTRING("CALLUI: >>> CCaUiMessageSender::~CCaUiMessageSender()"); |
|
69 |
|
70 if ( iMsgTypes ) |
|
71 { |
|
72 iMsgTypes->Reset(); |
|
73 delete iMsgTypes; |
|
74 } |
|
75 |
|
76 if( iSession ) |
|
77 { |
|
78 iSession->Cancel(); |
|
79 } |
|
80 delete iSession; |
|
81 |
|
82 if( iSendUi ) |
|
83 { |
|
84 delete iSendUi; |
|
85 } |
|
86 |
|
87 CAUILOGSTRING("CALLUI: <<< CCaUiMessageSender::~CCaUiMessageSender()"); |
|
88 } |
|
89 |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CCaUiMessageSender::NewL |
|
93 // |
|
94 // Two-phased constructor. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CCaUiMessageSender* CCaUiMessageSender::NewL() |
|
98 { |
|
99 |
|
100 CAUILOGSTRING("CALLUI: >>> CCaUiMessageSender::NewL()"); |
|
101 |
|
102 CCaUiMessageSender* self = new( ELeave ) CCaUiMessageSender (); |
|
103 |
|
104 CAUILOGSTRING("CALLUI: <<< CCaUiMessageSender::NewL()"); |
|
105 |
|
106 return self; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------- |
|
110 // CCaUiMessageSender::CreateNewMessageL |
|
111 // Create a new message of the given type, in the given location |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CCaUiMessageSender::CreateNewMessageL( |
|
115 TInt aMessageType, |
|
116 MDesC16Array* aRealAddress, |
|
117 MDesC16Array* aAliases, |
|
118 CRichText* aRichText ) |
|
119 { |
|
120 |
|
121 CAUILOGSTRING("CALLUI: >>> CCaUiMessageSender::CreateNewMessageL()"); |
|
122 |
|
123 TRAPD( err, CreateSendUiL()); |
|
124 if ( err != KErrNone ) |
|
125 User::Leave( KErrGeneral ); |
|
126 |
|
127 //Launch message editor standalone |
|
128 TUid mtmUid = { aMessageType }; |
|
129 |
|
130 CMessageData* messageData = CMessageData::NewL(); |
|
131 CleanupStack::PushL( messageData ); |
|
132 if ( aRichText ) |
|
133 { |
|
134 messageData->SetBodyTextL( aRichText ); |
|
135 } |
|
136 |
|
137 // Set real address and check if aliases exist |
|
138 if ( aRealAddress ) |
|
139 { |
|
140 TBool aAliasesExist = EFalse; |
|
141 if ( aAliases && |
|
142 aAliases->MdcaCount() == aRealAddress->MdcaCount() ) |
|
143 { |
|
144 aAliasesExist = ETrue; |
|
145 } |
|
146 for ( TInt i=0; i < aRealAddress->MdcaCount(); i++ ) |
|
147 { |
|
148 if ( aAliasesExist ) |
|
149 { |
|
150 messageData->AppendToAddressL( |
|
151 aRealAddress->MdcaPoint( i ), |
|
152 aAliases->MdcaPoint( i ) ); |
|
153 } |
|
154 else |
|
155 { |
|
156 messageData->AppendToAddressL( |
|
157 aRealAddress->MdcaPoint( i ) ); |
|
158 } |
|
159 } |
|
160 } |
|
161 |
|
162 iSendUi->CreateAndSendMessageL( mtmUid, messageData, KNullUid, EFalse ); |
|
163 CleanupStack::PopAndDestroy(); // messageData |
|
164 |
|
165 CAUILOGSTRING("CALLUI: <<< CCaUiMessageSender::CreateNewMessageL()"); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CCaUiMessageSender::CreateSendUiL |
|
170 // --------------------------------------------------------- |
|
171 // |
|
172 void CCaUiMessageSender::CreateSendUiL() |
|
173 { |
|
174 CAUILOGSTRING("CALLUI: >>> CCaUiMessageSender::CreateSendUiL()"); |
|
175 |
|
176 // Create instance of send ui. |
|
177 if( !iSendUi ) |
|
178 { |
|
179 iSendUi = CSendUi::NewL(); |
|
180 } |
|
181 |
|
182 CAUILOGSTRING("CALLUI: <<< CCaUiMessageSender::CreateSendUiL()"); |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CCaUiMessageSender::MessageTypesArray |
|
187 // --------------------------------------------------------- |
|
188 const CUidNameArray& CCaUiMessageSender:: |
|
189 MessageTypesArrayL() |
|
190 { |
|
191 |
|
192 CAUILOGSTRING("CALLUI: >>> CCaUiMessageSender::MessageTypesArrayL()"); |
|
193 |
|
194 delete iMsgTypes; |
|
195 iMsgTypes = NULL; |
|
196 |
|
197 CUidNameArray* msgTypes = new ( ELeave ) |
|
198 CUidNameArray( KCaUiReConQueryOptionsArrayGranularity ); |
|
199 CleanupStack::PushL( msgTypes ); |
|
200 UpdateMessageTypesArrayL( msgTypes ); |
|
201 CleanupStack::Pop(); |
|
202 iMsgTypes = msgTypes; |
|
203 |
|
204 CAUILOGSTRING("CALLUI: <<< CCaUiMessageSender::MessageTypesArrayL()"); |
|
205 |
|
206 return *iMsgTypes; |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CCaUiMessageSender::UpdateMessageTypesArrayL |
|
211 // Updates the array of UIDs which defines the MTM types for which the user |
|
212 // can create new messages. |
|
213 // --------------------------------------------------------- |
|
214 void CCaUiMessageSender::UpdateMessageTypesArrayL( |
|
215 CUidNameArray* aMsgTypes ) |
|
216 { |
|
217 |
|
218 CAUILOGSTRING("CALLUI:>>> CCaUiMessageSender::UpdateMessageTypesArrayL()"); |
|
219 |
|
220 aMsgTypes->Reset(); |
|
221 |
|
222 FeatureManager::InitializeLibL(); |
|
223 //Read MTM types from resource file |
|
224 TResourceReader resReader; |
|
225 CCoeEnv::Static()->CreateResourceReaderLC( resReader, |
|
226 NEW_MESSAGE_TYPES_ARRAY ); |
|
227 |
|
228 TInt count = resReader.ReadInt16(); |
|
229 |
|
230 for ( TInt i = 0; i < count; i++ ) |
|
231 { |
|
232 TInt32 id = resReader.ReadInt32(); |
|
233 HBufC* name = resReader.ReadHBufCL(); |
|
234 CleanupStack::PushL( name ); |
|
235 |
|
236 switch( id ) |
|
237 { |
|
238 case KUidEmail: |
|
239 { |
|
240 if ( IsMailboxDefinedL() ) |
|
241 { |
|
242 aMsgTypes->AppendL( TUidNameInfo( TUid::Uid( id ), *name ) ); |
|
243 } |
|
244 break; |
|
245 } |
|
246 case KUidPostCard: |
|
247 { |
|
248 if ( FeatureManager::FeatureSupported( KFeatureIdMmsPostcard ) ) |
|
249 { |
|
250 aMsgTypes->AppendL( TUidNameInfo( TUid::Uid( id ), *name ) ); |
|
251 } |
|
252 break; |
|
253 } |
|
254 default: |
|
255 { |
|
256 aMsgTypes->AppendL( TUidNameInfo( TUid::Uid( id ), *name ) ); |
|
257 break; |
|
258 } |
|
259 } |
|
260 |
|
261 CleanupStack::PopAndDestroy( name ); |
|
262 } |
|
263 |
|
264 CleanupStack::PopAndDestroy();//resReader |
|
265 FeatureManager::UnInitializeLib(); |
|
266 |
|
267 CAUILOGSTRING("CALLUI:<<< CCaUiMessageSender::UpdateMessageTypesArrayL() end"); |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------- |
|
271 // CCaUiMessageSender::CreateMessageServiceConnectionL |
|
272 // --------------------------------------------------------- |
|
273 // |
|
274 void CCaUiMessageSender::CreateMessageServiceConnectionL() |
|
275 { |
|
276 CAUILOGSTRING("CALLUI:>>> CCaUiMessageSender::CreateMessageServiceConnectionL()"); |
|
277 |
|
278 if ( !iSession ) |
|
279 { |
|
280 iSession = CMsvSession::OpenSyncL( *this ); |
|
281 } |
|
282 CAUILOGSTRING("CALLUI:<<< CCaUiMessageSender::CreateMessageServiceConnectionL()"); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------- |
|
286 // CCaUiMessageSender::IsMailboxDefinedL |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 TBool CCaUiMessageSender::IsMailboxDefinedL() |
|
290 { |
|
291 CAUILOGSTRING("CALLUI:>>> CCaUiMessageSender::IsMailboxDefinedL()"); |
|
292 |
|
293 CreateMessageServiceConnectionL(); |
|
294 |
|
295 TBool isDefined = EFalse; |
|
296 CMsvEntry* root = iSession->GetEntryL( KMsvRootIndexEntryId ); |
|
297 |
|
298 TInt count = root->Count(); |
|
299 for ( TInt i = 0; i < count; i++ ) |
|
300 { |
|
301 const TMsvEntry& tentry = (*root)[i]; |
|
302 if ( tentry.iMtm.iUid == KMtmPop3Uid || |
|
303 tentry.iMtm.iUid == KMtmImap4Uid ) |
|
304 { |
|
305 isDefined = ETrue; |
|
306 break; |
|
307 } |
|
308 } |
|
309 delete root; |
|
310 |
|
311 CAUILOGSTRING("CALLUI:<<< CCaUiMessageSender::IsMailboxDefinedL()"); |
|
312 return isDefined; |
|
313 } |
|
314 |
|
315 |
|
316 // --------------------------------------------------------- |
|
317 // CCaUiMessageSender::HandleSessionEventL |
|
318 // --------------------------------------------------------- |
|
319 void CCaUiMessageSender::HandleSessionEventL(TMsvSessionEvent aEvent, |
|
320 TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
321 { |
|
322 CAUILOGSTRING("CALLUI:>>> CCaUiMessageSender::HandleSessionEventL()"); |
|
323 |
|
324 CreateMessageServiceConnectionL(); |
|
325 |
|
326 switch ( aEvent ) |
|
327 { |
|
328 case EMsvCloseSession: |
|
329 //Server close. |
|
330 delete iSession; |
|
331 iSession = NULL; |
|
332 CAUILOGSTRING("CALLUI:<<< CCaUiMessageSender::HandleSessionEventL(): case: EMsvCloseSession"); |
|
333 break; |
|
334 default: |
|
335 CAUILOGSTRING("CALLUI:<<< CCaUiMessageSender::HandleSessionEventL(): case: default"); |
|
336 break; |
|
337 } |
|
338 |
|
339 } |
|
340 |
|
341 |
|
342 // End of File |