|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Send commmand handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "glxcommandhandlersend.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <utf.h> // for CnvUtfConverter |
|
26 #include <sendui.h> // for CSendui |
|
27 #include <sendnorm.rsg> // for CSendui resources |
|
28 #include <SendUiConsts.h> // for CSendui plugin type constants |
|
29 #include <CMessageData.h> // for CMessageData |
|
30 #include <coemain.h> // for CCoeEnv |
|
31 #include <StringLoader.h> // for CStringLoader |
|
32 #include <bautils.h> // for BaflUtils |
|
33 #include <data_caging_path_literals.hrh> // for directory and file names |
|
34 |
|
35 // INTERNAL INCLUDES |
|
36 #include <glxcommandhandlers.hrh> // for EGlxCmdUpload |
|
37 #include <mglxmedialistprovider.h> |
|
38 #include <mglxmedialist.h> |
|
39 #include <glxscreenfurniture.h> // for ScreenFurniture toolbar |
|
40 #include <glxuistd.h> // for KGlxUiUtilitiesResource |
|
41 #include <glxuiutility.h> // for HuiUtility |
|
42 #include <glxlog.h> // for debug logging |
|
43 #include <glxattributecontext.h> // for CGlxDefaultAttributeContext |
|
44 #include <glxattributeretriever.h> // for GlxAttributeRetriever |
|
45 #include <glxuiutilities.rsg> // for R_GLX_TOOLTIP_SEND |
|
46 #include <glxfetchcontextremover.h> // for TGlxFetchContextRemover |
|
47 #include <glxresourceutilities.h> // for CGlxResourceUtilities |
|
48 #include <glxicons.mbg> |
|
49 #include <glximageviewermanager.h> // for CGlxImageViewerManager |
|
50 #include <glxgeneraluiutilities.h> |
|
51 |
|
52 // LOCAL FUNCTIONS AND CONSTANTS |
|
53 namespace |
|
54 { |
|
55 const TInt KSendMsgBodySz = 0; |
|
56 const TInt KSendMsgOverallSz = 1024; // KMaxStringLength from SendUi.h |
|
57 // defined locally in the original code... @todo find a definition |
|
58 const TUid KSendAsPostcardUID = { 0x101FF961 }; |
|
59 } |
|
60 |
|
61 |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // Two-phased constructor. |
|
65 // ---------------------------------------------------------------------------- |
|
66 EXPORT_C CGlxCommandHandlerSend* CGlxCommandHandlerSend::NewL( |
|
67 MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem, |
|
68 const TDesC& aFileName) |
|
69 { |
|
70 GLX_FUNC("CGlxCommandHandlerSend::NewL"); |
|
71 CGlxCommandHandlerSend* self = new (ELeave) CGlxCommandHandlerSend( |
|
72 aMediaListProvider, aHasToolbarItem); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(aFileName); |
|
75 CleanupStack::Pop(self); |
|
76 return self; |
|
77 } |
|
78 |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // C++ default constructor |
|
82 // ---------------------------------------------------------------------------- |
|
83 CGlxCommandHandlerSend::CGlxCommandHandlerSend(MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem ) |
|
84 :CGlxMediaListCommandHandler(aMediaListProvider, aHasToolbarItem) |
|
85 { |
|
86 // nothing to do |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // Symbian 2nd phase constructor can leave. |
|
93 // ---------------------------------------------------------------------------- |
|
94 void CGlxCommandHandlerSend::ConstructL(const TDesC& aFileName) |
|
95 { |
|
96 GLX_FUNC("CGlxCommandHandlerSend::ConstructL"); |
|
97 |
|
98 iUiUtility = CGlxUiUtility::UtilityL(); |
|
99 iSendUi = CSendUi::NewL(); |
|
100 |
|
101 LoadRscFileL(aFileName); |
|
102 |
|
103 // add the Send command |
|
104 TCommandInfo info(EGlxCmdSend); |
|
105 info.iMinSelectionLength = 1; |
|
106 info.iMaxSelectionLength = KMaxTInt; |
|
107 AddCommandL(info); |
|
108 } |
|
109 |
|
110 |
|
111 // ---------------------------------------------------------------------------- |
|
112 // Destructor |
|
113 // ---------------------------------------------------------------------------- |
|
114 EXPORT_C CGlxCommandHandlerSend::~CGlxCommandHandlerSend() |
|
115 { |
|
116 GLX_FUNC("CGlxCommandHandlerSend::~CGlxCommandHandlerSend"); |
|
117 if (iResourceOffset) |
|
118 { |
|
119 CCoeEnv::Static()->DeleteResourceFile(iResourceOffset); |
|
120 } |
|
121 |
|
122 if (iUiUtility) |
|
123 { |
|
124 iUiUtility->Close(); |
|
125 } |
|
126 delete iSendUi; |
|
127 } |
|
128 |
|
129 |
|
130 |
|
131 // ---------------------------------------------------------------------------- |
|
132 // ExecuteL |
|
133 // ---------------------------------------------------------------------------- |
|
134 TBool CGlxCommandHandlerSend::DoExecuteL(TInt aCommandId, |
|
135 MGlxMediaList& /*aList*/) |
|
136 { |
|
137 GLX_FUNC("CGlxCommandHandlerSend::DoExecuteL"); |
|
138 |
|
139 if (aCommandId == EGlxCmdSend) |
|
140 { |
|
141 iAvkonAppUi->ProcessCommandL(EGlxCmdDialogLaunched); |
|
142 SendSelectedItemsL(); |
|
143 return ETrue; |
|
144 } |
|
145 return EFalse; |
|
146 } |
|
147 |
|
148 |
|
149 |
|
150 // ---------------------------------------------------------------------------- |
|
151 // DoActivateL |
|
152 // ---------------------------------------------------------------------------- |
|
153 void CGlxCommandHandlerSend::DoActivateL(TInt aViewId) |
|
154 { |
|
155 GLX_FUNC("CGlxCommandHandlerSend::DoActivateL"); |
|
156 |
|
157 iViewId = aViewId; |
|
158 MGlxMediaList& mediaList = MediaList(); |
|
159 |
|
160 // need to check the category attribute for image or video |
|
161 iAttributeContext = CGlxDefaultAttributeContext::NewL(); |
|
162 iAttributeContext->AddAttributeL(TMPXAttribute(KMPXMediaGeneralCategory)); |
|
163 iAttributeContext->AddAttributeL(TMPXAttribute(KMPXMediaGeneralUri)); |
|
164 mediaList.AddContextL( iAttributeContext, KGlxFetchContextPriorityLow ); |
|
165 |
|
166 mediaList.AddMediaListObserverL(this); |
|
167 } |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // Deactivate |
|
174 // ---------------------------------------------------------------------------- |
|
175 void CGlxCommandHandlerSend::Deactivate() |
|
176 { |
|
177 GLX_FUNC("CGlxCommandHandlerSend::Deactivate"); |
|
178 if (iAttributeContext) |
|
179 { |
|
180 MediaList().RemoveContext(iAttributeContext); |
|
181 delete iAttributeContext; |
|
182 iAttributeContext = NULL; |
|
183 } |
|
184 |
|
185 MediaList().RemoveMediaListObserver(this); |
|
186 } |
|
187 |
|
188 |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // OfferKeyEventL |
|
192 // ---------------------------------------------------------------------------- |
|
193 TKeyResponse CGlxCommandHandlerSend::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
194 TEventCode aType) |
|
195 { |
|
196 // Handle the send key |
|
197 if (aKeyEvent.iCode == EKeyYes && aType == EEventKey) |
|
198 { |
|
199 SendSelectedItemsL(); |
|
200 return EKeyWasConsumed; |
|
201 } |
|
202 return EKeyWasNotConsumed; |
|
203 } |
|
204 |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // HandleFocusChangedL |
|
208 // ---------------------------------------------------------------------------- |
|
209 void CGlxCommandHandlerSend::HandleFocusChangedL( |
|
210 NGlxListDefs::TFocusChangeType /*aType*/, |
|
211 TInt aNewIndex, TInt /*aOldIndex*/, MGlxMediaList* aList) |
|
212 { |
|
213 GLX_FUNC("CGlxCommandHandlerSend::HandleFocusChangedL"); |
|
214 if ( aList && aNewIndex >= 0 ) |
|
215 { |
|
216 const CGlxMedia* media = aList->Item(aNewIndex).Properties(); |
|
217 } |
|
218 } |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // SelectedFilesLC |
|
225 // ---------------------------------------------------------------------------- |
|
226 CMessageData* CGlxCommandHandlerSend::SelectedFilesLC() |
|
227 { |
|
228 GLX_FUNC("CGlxCommandHandlerSend::SelectedFilesLC"); |
|
229 |
|
230 // get the focused item from the media list |
|
231 MGlxMediaList& mediaList = MediaList(); |
|
232 |
|
233 CMessageData* messageData = CMessageData::NewLC(); |
|
234 |
|
235 // retrieve the file name and path |
|
236 CGlxDefaultAttributeContext* attributeContext = |
|
237 CGlxDefaultAttributeContext::NewL(); |
|
238 CleanupStack::PushL( attributeContext ); |
|
239 attributeContext->AddAttributeL( TMPXAttribute( KMPXMediaGeneralUri ) ); |
|
240 mediaList.AddContextL( attributeContext, KGlxFetchContextPriorityBlocking ); |
|
241 |
|
242 // TGlxContextRemover will remove the context when it goes out of scope |
|
243 // Used here to avoid a trap and still have safe cleanup |
|
244 TGlxFetchContextRemover contextRemover( attributeContext, mediaList ); |
|
245 CleanupClosePushL( contextRemover ); |
|
246 |
|
247 User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, |
|
248 mediaList, ETrue)); |
|
249 // context off the list |
|
250 CleanupStack::PopAndDestroy( &contextRemover ); |
|
251 |
|
252 // if there are multiple media items, filter the postcard plugin |
|
253 iFilterOutPlugin = (mediaList.SelectionCount() > 1); |
|
254 |
|
255 // extract the filename from selected items in the media list and add it |
|
256 // to the messageData to be returned |
|
257 TGlxSelectionIterator iterator; |
|
258 iterator.SetToFirst( &mediaList ); |
|
259 TInt index = KErrNotFound; |
|
260 |
|
261 while ( (index = iterator++) != KErrNotFound ) |
|
262 { |
|
263 // does not return ownership. |
|
264 const CGlxMedia* media = mediaList.Item( index ).Properties(); |
|
265 if (media) |
|
266 { |
|
267 if ( media->IsSupported( KMPXMediaGeneralUri ) && |
|
268 IsValidTypeL( *media ) ) |
|
269 { |
|
270 CGlxImageViewerManager* viewerInst = |
|
271 CGlxImageViewerManager::InstanceL(); |
|
272 if ( viewerInst && viewerInst->IsPrivate() ) |
|
273 { |
|
274 messageData->AppendAttachmentHandleL( |
|
275 viewerInst->ImageFileHandle() ); |
|
276 } |
|
277 else |
|
278 { |
|
279 messageData->AppendAttachmentL( |
|
280 media->ValueText( KMPXMediaGeneralUri ) ); |
|
281 } |
|
282 viewerInst->DeleteInstance(); |
|
283 } |
|
284 } |
|
285 else |
|
286 { |
|
287 User::Leave( KErrNotReady ); |
|
288 } |
|
289 } |
|
290 |
|
291 CleanupStack::PopAndDestroy( attributeContext ); |
|
292 return messageData; |
|
293 } |
|
294 |
|
295 // ---------------------------------------------------------------------------- |
|
296 // IsValidTypeL |
|
297 // ---------------------------------------------------------------------------- |
|
298 TBool CGlxCommandHandlerSend::IsValidTypeL(const CGlxMedia& aMedia) |
|
299 { |
|
300 GLX_FUNC("CGlxCommandHandlerSend::IsValidTypeL"); |
|
301 // ensure the category attribute is supported by the current media item |
|
302 if (aMedia.IsSupported(KMPXMediaGeneralCategory)) |
|
303 { |
|
304 switch(aMedia.ValueTObject<TInt>(KMPXMediaGeneralCategory)) |
|
305 { |
|
306 case EMPXVideo: |
|
307 { |
|
308 // don't use the postcard plugin to send video |
|
309 iFilterOutPlugin = ETrue; |
|
310 return ETrue; |
|
311 } |
|
312 case EMPXImage: |
|
313 { |
|
314 return ETrue; |
|
315 } |
|
316 default: |
|
317 { |
|
318 return EFalse; |
|
319 } |
|
320 } |
|
321 } |
|
322 return EFalse; |
|
323 } |
|
324 |
|
325 |
|
326 // ---------------------------------------------------------------------------- |
|
327 // SendSelectedItemsL |
|
328 // ---------------------------------------------------------------------------- |
|
329 void CGlxCommandHandlerSend::SendSelectedItemsL() |
|
330 { |
|
331 GLX_FUNC("CGlxCommandHandlerSend::SendSelectedItemsL"); |
|
332 // retrieve the current files name and location |
|
333 CMessageData* msgData = SelectedFilesLC(); |
|
334 HBufC* title = StringLoader::LoadLC(R_QTN_LGAL_POPUP_SEND); |
|
335 |
|
336 // filterOutPlugins is a list of component uids that should NOT be used to |
|
337 // send the media file. if a video file was selected or multiple files |
|
338 // were selected, filter out the option to send as a postcard |
|
339 CArrayFix<TUid>* filterOutPlugins =new (ELeave) CArrayFixFlat<TUid>(1); |
|
340 CleanupStack::PushL(filterOutPlugins); |
|
341 |
|
342 if(iFilterOutPlugin) |
|
343 { |
|
344 filterOutPlugins->AppendL(KSendAsPostcardUID); |
|
345 } |
|
346 |
|
347 // If Device supports text-entry mode only in portrait, |
|
348 // then the orientation has to be forced to EGlxOrientationTextEntry |
|
349 // before launching the Send pop-up. |
|
350 |
|
351 if(iUiUtility->IsPenSupported()) |
|
352 { |
|
353 iUiUtility->SetAppOrientationL( EGlxOrientationDefault ); |
|
354 } |
|
355 // Trap the send call to ensure the orientation is reverted |
|
356 TRAPD(error, iSendUi->ShowQueryAndSendL( msgData, Capabilities(), |
|
357 filterOutPlugins, KNullUid, ETrue, *title )); |
|
358 if (error == KErrNoMemory || error == KErrNotSupported || error |
|
359 == KErrInUse || error == KErrDiskFull || error == KErrTimedOut |
|
360 || error == KErrPermissionDenied) |
|
361 { |
|
362 GlxGeneralUiUtilities::ShowErrorNoteL(error); |
|
363 GLX_LOG_INFO1("error sending the image %d",error); |
|
364 } |
|
365 CleanupStack::PopAndDestroy(filterOutPlugins); |
|
366 CleanupStack::PopAndDestroy(title); |
|
367 CleanupStack::PopAndDestroy(msgData); |
|
368 iAvkonAppUi->ProcessCommandL(EGlxCmdDialogDismissed); |
|
369 } |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 // ---------------------------------------------------------------------------- |
|
375 // LoadRscFileL |
|
376 // ---------------------------------------------------------------------------- |
|
377 void CGlxCommandHandlerSend::LoadRscFileL(const TDesC& aFileName) |
|
378 { |
|
379 GLX_FUNC("CGlxCommandHandlerSend::LoadRscFileL"); |
|
380 CCoeEnv* env = CCoeEnv::Static(); |
|
381 iResourceOffset = env->AddResourceFileL(aFileName); |
|
382 } |
|
383 |
|
384 |
|
385 // ---------------------------------------------------------------------------- |
|
386 // Capabilities |
|
387 // ---------------------------------------------------------------------------- |
|
388 TSendingCapabilities CGlxCommandHandlerSend::Capabilities() |
|
389 { |
|
390 GLX_FUNC("CGlxCommandHandlerSend::Capabilities"); |
|
391 return TSendingCapabilities (KSendMsgBodySz, KSendMsgOverallSz, |
|
392 TSendingCapabilities::ESupportsAttachments); |
|
393 } |
|
394 |
|
395 |
|
396 // ---------------------------------------------------------------------------- |
|
397 // PopulateToolbar |
|
398 // ---------------------------------------------------------------------------- |
|
399 // |
|
400 void CGlxCommandHandlerSend::PopulateToolbarL() |
|
401 { |
|
402 GLX_FUNC("CGlxCommandHandlerSend::PopulateToolbar"); |
|
403 |
|
404 iUiUtility->ScreenFurniture()->SetTooltipL( EGlxCmdSend, CAknButton::EPositionLeft ); |
|
405 } |
|
406 |
|
407 // ---------------------------------------------------------------------------- |
|
408 // DoIsDisabled |
|
409 // ---------------------------------------------------------------------------- |
|
410 // |
|
411 TBool CGlxCommandHandlerSend::DoIsDisabled(TInt aCommandId, |
|
412 MGlxMediaList& aList) const |
|
413 { |
|
414 GLX_FUNC("CGlxCommandHandlerSend::DoIsDisabled"); |
|
415 if (EGlxCmdSend == aCommandId && aList.Count()) |
|
416 { |
|
417 return EFalse; |
|
418 } |
|
419 return ETrue; |
|
420 } |
|
421 |
|
422 // ---------------------------------------------------------------------------- |
|
423 // HandleItemSelectedL |
|
424 // ---------------------------------------------------------------------------- |
|
425 // |
|
426 void CGlxCommandHandlerSend::HandleItemSelectedL(TInt /*aIndex*/, |
|
427 TBool /*aSelected*/, MGlxMediaList* aList) |
|
428 { |
|
429 GLX_FUNC("CGlxCommandHandlerSend::HandleItemSelectedL"); |
|
430 // Check if toolbar is available. |
|
431 CAknToolbar* toolbar = iUiUtility->GetGridToolBar(); |
|
432 if (toolbar) |
|
433 { |
|
434 TBool dimmed = ETrue; |
|
435 if (aList->SelectionCount() > 0) |
|
436 { |
|
437 dimmed = EFalse; |
|
438 } |
|
439 toolbar->SetItemDimmed(EGlxCmdSend, dimmed, ETrue); |
|
440 } |
|
441 } |
|
442 |
|
443 // End of file |