|
1 /* |
|
2 * Copyright (c) 2002 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 * CMsgConfirmSendQuery implementation file |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <bautils.h> |
|
23 #include <s32mem.h> |
|
24 |
|
25 #include <data_caging_path_literals.hrh> |
|
26 |
|
27 #include <aknmessagequerydialog.h> |
|
28 |
|
29 #include <tmsvpackednotifierrequest.h> |
|
30 |
|
31 // SIS registry |
|
32 #include <swi/sisregistrysession.h> |
|
33 #include <swi/sisregistrypackage.h> |
|
34 |
|
35 #include <mtclreg.h> |
|
36 #include <msvreg.h> |
|
37 |
|
38 #include <StringLoader.h> |
|
39 |
|
40 #include <avkon.rsg> |
|
41 #include <MsgNotifiers.rsg> |
|
42 |
|
43 #include "MsgConfirmSendNotifier.h" |
|
44 #include "MsgConfirmSendQuery.h" |
|
45 |
|
46 // LOCAL CONSTANTS AND MACROS |
|
47 |
|
48 _LIT( KMsgNotifiersResourceFile, "MsgNotifiers.rsc" ); |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CMsgConfirmSendQuery::NewL |
|
52 // |
|
53 // Two-phased constructor. |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CMsgConfirmSendQuery* CMsgConfirmSendQuery::NewL( CMsgConfirmSendNotifier& aNotifier ) |
|
57 { |
|
58 CMsgConfirmSendQuery* self = new ( ELeave ) CMsgConfirmSendQuery( aNotifier ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // CMsgConfirmSendQuery::ConstructL |
|
67 // |
|
68 // Symbian OS default constructor can leave. |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 void CMsgConfirmSendQuery::ConstructL() |
|
72 { |
|
73 iCoe = CEikonEnv::Static(); |
|
74 if ( !iCoe ) |
|
75 { |
|
76 User::Leave( KErrGeneral ); |
|
77 } |
|
78 |
|
79 TFileName resourceFile; |
|
80 TParse parse; |
|
81 parse.Set( KMsgNotifiersResourceFile, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
82 resourceFile = parse.FullName(); |
|
83 |
|
84 BaflUtils::NearestLanguageFile( iCoe->FsSession(), resourceFile ); |
|
85 iResourceFileOffset = iCoe->AddResourceFileL( resourceFile ); |
|
86 |
|
87 CActiveScheduler::Add( this ); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CMsgConfirmSendQuery::CMsgConfirmSendQuery |
|
92 // |
|
93 // C++ constructor can NOT contain any code, that |
|
94 // might leave. |
|
95 // --------------------------------------------------------- |
|
96 // |
|
97 CMsgConfirmSendQuery::CMsgConfirmSendQuery( CMsgConfirmSendNotifier& aNotifier ) |
|
98 : CActive( CActive::EPriorityStandard ), |
|
99 iNotifier( aNotifier ) |
|
100 { |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CMsgConfirmSendQuery::~CMsgConfirmSendQuery |
|
105 // |
|
106 // Destructor |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 CMsgConfirmSendQuery::~CMsgConfirmSendQuery() |
|
110 { |
|
111 Cancel(); |
|
112 if ( iCoe && iResourceFileOffset ) |
|
113 { |
|
114 iCoe->DeleteResourceFile( iResourceFileOffset ); |
|
115 } |
|
116 delete iAppName; |
|
117 delete iMtmName; |
|
118 delete iSelection; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------- |
|
122 // CMsgConfirmSendQuery::RunL |
|
123 // |
|
124 // From active object framework |
|
125 // --------------------------------------------------------- |
|
126 // |
|
127 void CMsgConfirmSendQuery::RunL() |
|
128 { |
|
129 // "Cancel" returns "0" |
|
130 TInt ret( 0 ); |
|
131 |
|
132 HBufC* label = CreateMessageTextLC(); |
|
133 CAknMessageQueryDialog* query = CAknMessageQueryDialog::NewL( *label ); |
|
134 ret = query->ExecuteLD( R_CONFIRM_QUERY ); |
|
135 CleanupStack::PopAndDestroy( label ); |
|
136 |
|
137 iNotifier.HandleActiveEvent( ret ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------- |
|
141 // CMsgConfirmSendQuery::DoCancel |
|
142 // |
|
143 // From active object framework |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 void CMsgConfirmSendQuery::DoCancel() |
|
147 { |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------- |
|
151 // CMsgConfirmSendQuery::Start |
|
152 // |
|
153 // Starts the active object |
|
154 // --------------------------------------------------------- |
|
155 // |
|
156 void CMsgConfirmSendQuery::ShowQueryL( const TDesC8& aBuffer, TBool aSendAs ) |
|
157 { |
|
158 if ( IsActive() ) |
|
159 { |
|
160 Cancel(); |
|
161 } |
|
162 |
|
163 //delete iBuf; |
|
164 //iBuf = NULL; |
|
165 //iBuf = aBuffer.AllocL(); |
|
166 //iClient.ShowQuery( *iBuf, iStatus ); |
|
167 |
|
168 if ( aSendAs ) |
|
169 { |
|
170 ResolveSendAsConfirmDetailsL( aBuffer ); |
|
171 } |
|
172 else |
|
173 { |
|
174 ResolveSendUiConfirmDetailsL( aBuffer ); |
|
175 } |
|
176 |
|
177 // Complete self: |
|
178 iStatus = KRequestPending; |
|
179 TRequestStatus* pStatus = &iStatus; |
|
180 SetActive(); |
|
181 User::RequestComplete( pStatus, KErrNone ); |
|
182 } |
|
183 |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CMsgConfirmSendSession::ResolveSendAsConfirmDetailsL |
|
187 // --------------------------------------------------------- |
|
188 // |
|
189 void CMsgConfirmSendQuery::ResolveSendAsConfirmDetailsL( const TDesC8& aBuffer ) |
|
190 { |
|
191 TSecurityInfo securityInfo; |
|
192 CMsvEntrySelection* selection = new ( ELeave ) CMsvEntrySelection(); |
|
193 CleanupStack::PushL( selection ); |
|
194 TMsvPackedNotifierRequest::UnpackL( aBuffer, *selection, securityInfo ); |
|
195 |
|
196 TInt count = selection->Count(); |
|
197 if ( count == 0 ) |
|
198 { |
|
199 User::Leave( KErrArgument ); |
|
200 } |
|
201 |
|
202 CDummyObserver* dummyObs = new ( ELeave ) CDummyObserver; |
|
203 CleanupStack::PushL( dummyObs ); |
|
204 CMsvSession* session = CMsvSession::OpenSyncL( *dummyObs ); |
|
205 CleanupStack::PushL( session ); |
|
206 |
|
207 TMsvId dummy; |
|
208 TMsvEntry entry; |
|
209 User::LeaveIfError( session->GetEntry( selection->At( 0 ), dummy, entry ) ); |
|
210 |
|
211 iMultipleMessages = ( count > 1 ); |
|
212 iMultipleRecipients = entry.MultipleRecipients(); |
|
213 |
|
214 // Assume all entries have same MTM. |
|
215 NameFromMtmL( session, entry.iMtm ); |
|
216 NameFromSecurityInfoL( securityInfo ); |
|
217 |
|
218 CleanupStack::PopAndDestroy( 3, selection ); // selection, dummyObs, session |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CMsgConfirmSendSession::ResolveSendUiConfirmDetailsL |
|
223 // --------------------------------------------------------- |
|
224 // |
|
225 void CMsgConfirmSendQuery::ResolveSendUiConfirmDetailsL( const TDesC8& aBuffer ) |
|
226 { |
|
227 iMultipleMessages = EFalse; |
|
228 iMultipleRecipients = EFalse; |
|
229 |
|
230 RDesReadStream stream( aBuffer ); |
|
231 delete iMtmName; |
|
232 iMtmName = NULL; |
|
233 TInt length = stream.ReadInt32L(); |
|
234 if ( length ) |
|
235 { |
|
236 iMtmName = HBufC::NewL( stream, length ); |
|
237 } |
|
238 else |
|
239 { |
|
240 iMtmName = StringLoader::LoadL( R_CONFIRM_UNKNOWN_MTM, iCoe ); |
|
241 } |
|
242 TSecurityInfo securityInfo; |
|
243 securityInfo.iSecureId = stream.ReadUint32L(); |
|
244 NameFromSecurityInfoL( securityInfo ); |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------- |
|
248 // CMsgConfirmSendSession::NameFromSecurityInfoL |
|
249 // --------------------------------------------------------- |
|
250 // |
|
251 void CMsgConfirmSendQuery::NameFromSecurityInfoL( TSecurityInfo& securityInfo ) |
|
252 { |
|
253 delete iAppName; |
|
254 iAppName = NULL; |
|
255 Swi::RSisRegistrySession sisSession; |
|
256 if ( sisSession.Connect() == KErrNone ) |
|
257 { |
|
258 Swi::CSisRegistryPackage* sisRegistry = NULL; |
|
259 TRAPD( err, sisRegistry = sisSession.SidToPackageL( securityInfo.iSecureId ) ); |
|
260 if ( !err ) |
|
261 { |
|
262 iAppName = sisRegistry->Name().AllocL(); |
|
263 } |
|
264 delete sisRegistry; |
|
265 sisSession.Close(); |
|
266 } |
|
267 if ( !iAppName || !iAppName->Length() ) |
|
268 { |
|
269 iAppName = StringLoader::LoadL( R_CONFIRM_UNKNOWN_APP, iCoe ); |
|
270 } |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------- |
|
274 // CMsgConfirmSendSession::NameFromMtmL |
|
275 // --------------------------------------------------------- |
|
276 // |
|
277 void CMsgConfirmSendQuery::NameFromMtmL( CMsvSession* aSession, TUid aMtmTypeUid ) |
|
278 { |
|
279 delete iMtmName; |
|
280 iMtmName = NULL; |
|
281 //HBufC* name( NULL ); |
|
282 // Create a client registry |
|
283 CClientMtmRegistry* clientReg = CClientMtmRegistry::NewL( *aSession ); |
|
284 CleanupStack::PushL( clientReg ); |
|
285 |
|
286 // Resolve human readable name for the MTM |
|
287 if ( clientReg->IsPresent( aMtmTypeUid ) ) |
|
288 { |
|
289 iMtmName = clientReg->RegisteredMtmDllInfo( aMtmTypeUid ).HumanReadableName().AllocL(); |
|
290 } |
|
291 if ( !iMtmName || !iMtmName->Length() ) |
|
292 { |
|
293 iMtmName = StringLoader::LoadL( R_CONFIRM_UNKNOWN_MTM, iCoe ); |
|
294 } |
|
295 CleanupStack::PopAndDestroy( clientReg ); |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------- |
|
299 // CMsgConfirmSendQuery::CreateMessageTextLC |
|
300 // --------------------------------------------------------- |
|
301 // |
|
302 HBufC* CMsgConfirmSendQuery::CreateMessageTextLC() |
|
303 { |
|
304 TInt resourceId = R_CONFIRM_SEND_MANY_MSG; |
|
305 if ( !iMultipleMessages ) |
|
306 { |
|
307 resourceId = iMultipleRecipients |
|
308 ? R_CONFIRM_SEND_MANY_RECIP |
|
309 : R_CONFIRM_SEND_ONE; |
|
310 } |
|
311 |
|
312 CPtrCArray* array = new ( ELeave ) CPtrCArray( 2 ); |
|
313 CleanupStack::PushL( array ); |
|
314 |
|
315 array->AppendL( *iAppName ); |
|
316 array->AppendL( *iMtmName ); |
|
317 |
|
318 HBufC* label = StringLoader::LoadL( |
|
319 resourceId, |
|
320 *array, |
|
321 iCoe ); |
|
322 |
|
323 CleanupStack::PopAndDestroy( array ); |
|
324 CleanupStack::PushL( label ); |
|
325 return label; |
|
326 } |
|
327 |
|
328 |
|
329 // End of File |