|
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: Upload commmand handler |
|
15 * |
|
16 */ |
|
17 |
|
18 // CLASS HEADER |
|
19 #include "glxcommandhandlerupload.h" |
|
20 |
|
21 // EXTERNAL INCLUDES |
|
22 #include <AiwGenericParam.h> // for passing data between applications |
|
23 #include <aknbutton.h> // for getting the button state |
|
24 #include <akntoolbar.h> // for accessing currently active toolbar |
|
25 #include <centralrepository.h> // for checking the ShareOnline version |
|
26 #include <data_caging_path_literals.hrh> // for directory and file names |
|
27 #include <utf.h> // for CnvUtfConverter |
|
28 |
|
29 |
|
30 // INTERNAL INCLUDES |
|
31 #include <glxattributecontext.h> // for creating medialist context |
|
32 #include <glxattributeretriever.h> // for retrieving the attributes |
|
33 #include <glxcommandhandlers.hrh> // for EGlxCmdUpload |
|
34 #include <glxfetchcontextremover.h> // for TGlxFetchContextRemover |
|
35 #include <glxtracer.h> // for TRACER logs |
|
36 #include <glxuiutilities.rsg> // for Share AIW interest resource |
|
37 #include <mglxmedialist.h> // for accessing the media items |
|
38 |
|
39 // CONSTANTS AND DEFINITIONS |
|
40 namespace |
|
41 { |
|
42 // ShareOnline application UID |
|
43 const TUid KShareOnlineUid = { 0x2000BB53 }; |
|
44 // Shareonline Application version |
|
45 const TUint32 KShareApplicationVersion = 0x01010020; |
|
46 // Buffer to maintain the ShareOnline version number in use |
|
47 const TInt KPhotosShareOnlineVersionBufLen = 12; |
|
48 // Minimum version required for OneClickUpload to work |
|
49 const TVersion KShareOnlineMinimumVersion( 4, 3, 0 ); |
|
50 // OneClickUpload command |
|
51 const TUid KOpenModeOneClick = { 2 }; |
|
52 // Command to request for the tooltip |
|
53 const TUid KCmdGetOneClickToolTip = { 15 }; |
|
54 } |
|
55 |
|
56 // Get the AppUi instance |
|
57 // This class does not have access to a CEikonEnv and hence |
|
58 // pls ignore the code scanner warning - Using CEikonEnv::Static |
|
59 #define GetAppUi() (dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->EikAppUi())) |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // Two-phased constructor. |
|
63 // ---------------------------------------------------------------------------- |
|
64 EXPORT_C CGlxCommandHandlerUpload* CGlxCommandHandlerUpload::NewL( |
|
65 MGlxMediaListProvider* aMediaListProvider, |
|
66 TBool aHasToolbarItem) |
|
67 { |
|
68 TRACER("CGlxCommandHandlerUpload::NewL"); |
|
69 CGlxCommandHandlerUpload* self = |
|
70 new (ELeave) CGlxCommandHandlerUpload(aMediaListProvider,aHasToolbarItem); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // C++ default constructor |
|
79 // ---------------------------------------------------------------------------- |
|
80 CGlxCommandHandlerUpload::CGlxCommandHandlerUpload(MGlxMediaListProvider* |
|
81 aMediaListProvider, |
|
82 TBool aHasToolbarItem) |
|
83 :CGlxMediaListCommandHandler(aMediaListProvider,aHasToolbarItem) |
|
84 { |
|
85 TRACER("CGlxCommandHandlerUpload::CGlxCommandHandlerUpload"); |
|
86 |
|
87 // nothing to do |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // Symbian 2nd phase constructor can leave. |
|
92 // ---------------------------------------------------------------------------- |
|
93 void CGlxCommandHandlerUpload::ConstructL() |
|
94 { |
|
95 TRACER("CGlxCommandHandlerUpload::ConstructL"); |
|
96 iUiUtility = CGlxUiUtility::UtilityL(); |
|
97 |
|
98 // iUploadSupported is zeroed by CBase constructor. |
|
99 // If a leave occurs here, it is left as EFalse. |
|
100 // If InitializeOneClickUploadL() succeeds, it is set to ETrue. |
|
101 TRAP_IGNORE( |
|
102 { |
|
103 CheckVersionL(); |
|
104 InitializeOneClickUploadL(); |
|
105 iUploadSupported = ETrue; |
|
106 } ); |
|
107 |
|
108 |
|
109 // Add the upload command |
|
110 TCommandInfo info(EGlxCmdUpload); |
|
111 AddCommandL(info); |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // Destructor |
|
116 // ---------------------------------------------------------------------------- |
|
117 EXPORT_C CGlxCommandHandlerUpload::~CGlxCommandHandlerUpload() |
|
118 { |
|
119 TRACER("CGlxCommandHandlerUpload::~CGlxCommandHandlerUpload"); |
|
120 |
|
121 if (iUiUtility) |
|
122 { |
|
123 iUiUtility->Close(); |
|
124 } |
|
125 delete iServiceHandler; |
|
126 } |
|
127 |
|
128 // InitializeAIWForShareOnlineL |
|
129 // ---------------------------------------------------------------------------- |
|
130 // |
|
131 void CGlxCommandHandlerUpload::InitializeOneClickUploadL() |
|
132 { |
|
133 TRACER("CGlxCommandHandlerUpload::InitializeOneClickUploadL"); |
|
134 |
|
135 iServiceHandler = CAiwServiceHandler::NewL(); |
|
136 |
|
137 // Attach the AIW Resource defined in uiutilities.rss |
|
138 iServiceHandler->AttachL( R_AIW_SHARE_BASE_INTEREST ); |
|
139 } |
|
140 |
|
141 // Check Share Online version |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CGlxCommandHandlerUpload::CheckVersionL() |
|
145 { |
|
146 TRACER("CGlxCommandHandlerUpload::CheckVersionL"); |
|
147 |
|
148 CRepository* rep = CRepository::NewLC( KShareOnlineUid ); |
|
149 // |
|
150 TBuf<KPhotosShareOnlineVersionBufLen> versionBuf; |
|
151 // Query the ShareOnline version in the build |
|
152 User::LeaveIfError( rep->Get( KShareApplicationVersion, versionBuf ) ); |
|
153 |
|
154 // Initialize version to zero |
|
155 TVersion version( 0, 0, 0 ); |
|
156 TLex lex( versionBuf ); |
|
157 User::LeaveIfError( lex.Val( version.iMajor ) ); |
|
158 if ( lex.Get() != TChar('.') ) |
|
159 { |
|
160 User::Leave( KErrCorrupt ); |
|
161 } |
|
162 User::LeaveIfError( lex.Val( version.iMinor ) ); |
|
163 if ( lex.Get() != TChar('.') ) |
|
164 { |
|
165 User::Leave( KErrCorrupt ); |
|
166 } |
|
167 User::LeaveIfError( lex.Val( version.iBuild ) ); |
|
168 |
|
169 // Compare version number and leave if the detected |
|
170 // version is less than KShareOnlineMinimumVersion. |
|
171 if ( version.iMajor < KShareOnlineMinimumVersion.iMajor ) |
|
172 { |
|
173 User::LeaveIfError( KErrNotSupported ); |
|
174 } |
|
175 else if ( version.iMajor == KShareOnlineMinimumVersion.iMajor ) |
|
176 { |
|
177 if ( version.iMinor < KShareOnlineMinimumVersion.iMinor ) |
|
178 { |
|
179 User::LeaveIfError( KErrNotSupported ); |
|
180 } |
|
181 else if ( version.iMinor == KShareOnlineMinimumVersion.iMinor ) |
|
182 { |
|
183 if ( version.iBuild < KShareOnlineMinimumVersion.iBuild ) |
|
184 { |
|
185 User::LeaveIfError( KErrNotSupported ); |
|
186 } |
|
187 else |
|
188 { |
|
189 // Version is supported, fall through |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 // Version is supported, fall through |
|
195 } |
|
196 } |
|
197 else |
|
198 { |
|
199 // Version is supported, fall through |
|
200 } |
|
201 CleanupStack::PopAndDestroy( rep ); |
|
202 |
|
203 } |
|
204 |
|
205 // ---------------------------------------------------------------------------- |
|
206 // DoExecuteL |
|
207 // ---------------------------------------------------------------------------- |
|
208 TBool CGlxCommandHandlerUpload::DoExecuteL(TInt aCommandId, |
|
209 MGlxMediaList& /*aList*/) |
|
210 { |
|
211 TRACER("CGlxCommandHandlerUpload::DoExecuteL"); |
|
212 |
|
213 TBool handled = EFalse; |
|
214 // handle the upload command |
|
215 if (iUploadSupported && ( EGlxCmdUpload == aCommandId )) |
|
216 { |
|
217 |
|
218 CAiwGenericParamList& inputParams = iServiceHandler->InParamListL(); |
|
219 |
|
220 TAiwVariant variant( KOpenModeOneClick ); //For one click photo upload |
|
221 TAiwGenericParam param( EGenericParamModeActivation, variant ); |
|
222 inputParams.AppendL( param ); |
|
223 |
|
224 // Append all the files that are selected to iServiceHandler->InParamListL() |
|
225 AppendSelectedFilesL(inputParams); |
|
226 |
|
227 // Execute the KAiwCmdUpload command |
|
228 iServiceHandler->ExecuteServiceCmdL( KAiwCmdUpload, |
|
229 inputParams, iServiceHandler->OutParamListL() ); |
|
230 |
|
231 handled = ETrue; |
|
232 } |
|
233 return handled; |
|
234 } |
|
235 |
|
236 // ---------------------------------------------------------------------------- |
|
237 // DoActivateL |
|
238 // ---------------------------------------------------------------------------- |
|
239 void CGlxCommandHandlerUpload::DoActivateL(TInt aViewId) |
|
240 { |
|
241 TRACER("CGlxCommandHandlerUpload::DoActivateL"); |
|
242 iViewId = aViewId; |
|
243 |
|
244 } |
|
245 |
|
246 // ---------------------------------------------------------------------------- |
|
247 // Deactivate |
|
248 // ---------------------------------------------------------------------------- |
|
249 void CGlxCommandHandlerUpload::Deactivate() |
|
250 { |
|
251 TRACER("CGlxCommandHandlerUpload::Deactivate"); |
|
252 |
|
253 } |
|
254 |
|
255 // ---------------------------------------------------------------------------- |
|
256 // AppendSelectedFilesL() |
|
257 // ---------------------------------------------------------------------------- |
|
258 // |
|
259 void CGlxCommandHandlerUpload::AppendSelectedFilesL(CAiwGenericParamList& aInputParams) |
|
260 { |
|
261 TRACER("CGlxCommandHandlerUpload::AppendSelectedFilesL"); |
|
262 |
|
263 HBufC* fileName = HBufC::NewLC(KMaxFileName); |
|
264 |
|
265 // get the media list reference |
|
266 MGlxMediaList& mediaList = MediaList(); |
|
267 |
|
268 //retrieve the file name and path using selection-based fetch contexts |
|
269 CGlxDefaultAttributeContext* attributeContext = |
|
270 CGlxDefaultAttributeContext::NewL(); |
|
271 CleanupStack::PushL(attributeContext); |
|
272 attributeContext->AddAttributeL(KMPXMediaGeneralUri); |
|
273 mediaList.AddContextL(attributeContext, KGlxFetchContextPriorityBlocking); |
|
274 |
|
275 // TGlxContextRemover will remove the context when it goes out of scope |
|
276 // Used here to avoid a trap and still have safe cleanup |
|
277 TGlxFetchContextRemover contextRemover (attributeContext, mediaList); |
|
278 CleanupClosePushL( contextRemover ); |
|
279 |
|
280 // Leaving method returns an err code |
|
281 User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, |
|
282 mediaList, ETrue)); |
|
283 |
|
284 // context off the list |
|
285 CleanupStack::PopAndDestroy( &contextRemover ); |
|
286 |
|
287 // Extract the filename/s from selected item/s in the media list and append |
|
288 // it to AIW InParamList |
|
289 TGlxSelectionIterator iterator; |
|
290 iterator.SetToFirst(&mediaList); |
|
291 TInt index = KErrNotFound; |
|
292 |
|
293 while ( (index = iterator++) != KErrNotFound ) |
|
294 { |
|
295 // does not return ownership. |
|
296 const CGlxMedia* media = mediaList.Item(index).Properties(); |
|
297 if(media) |
|
298 { |
|
299 if(media->IsSupported(KMPXMediaGeneralUri)) |
|
300 { |
|
301 // Retrieve the file URI |
|
302 fileName->Des() = media->ValueText(KMPXMediaGeneralUri); |
|
303 __ASSERT_DEBUG(fileName->Length() <= KMaxFileName, |
|
304 Panic(EGlxPanicRequiredItemNotFound)); |
|
305 TAiwVariant fileVariant( fileName ); |
|
306 TAiwGenericParam fileParam( EGenericParamFile, fileVariant ); |
|
307 aInputParams.AppendL( fileParam ); |
|
308 } |
|
309 } |
|
310 else |
|
311 { |
|
312 User::Leave(KErrNotReady); |
|
313 } |
|
314 } |
|
315 |
|
316 CleanupStack::PopAndDestroy(attributeContext); |
|
317 CleanupStack::PopAndDestroy(fileName); |
|
318 }// contextRemover goes out of scope and removes the context from media list |
|
319 |
|
320 // ---------------------------------------------------------------------------- |
|
321 // PopulateToolbar |
|
322 // ---------------------------------------------------------------------------- |
|
323 // |
|
324 void CGlxCommandHandlerUpload::PopulateToolbarL() |
|
325 { |
|
326 TRACER( "CGlxCommandHandlerUpload::PopulateToolbarL" ); |
|
327 |
|
328 if( iUploadSupported ) |
|
329 { |
|
330 SetToolTipL(); |
|
331 } |
|
332 } |
|
333 |
|
334 // ---------------------------------------------------------------------------- |
|
335 // GetToolTipL |
|
336 // ---------------------------------------------------------------------------- |
|
337 // |
|
338 void CGlxCommandHandlerUpload::GetToolTipL( HBufC*& aToolTipText ) |
|
339 { |
|
340 TRACER("CGlxCommandHandlerUpload::GetToolTipL"); |
|
341 |
|
342 CAiwGenericParamList& inputParams = iServiceHandler->InParamListL(); |
|
343 |
|
344 // Insert Command parameter that tells provider that tooltip is required |
|
345 TAiwVariant variant(KCmdGetOneClickToolTip); |
|
346 TAiwGenericParam param(EGenericParamModeActivation, variant); |
|
347 inputParams.AppendL(param); |
|
348 |
|
349 //Get a reference to output parameter list |
|
350 CAiwGenericParamList& outputParams = iServiceHandler->OutParamListL(); |
|
351 iServiceHandler->ExecuteServiceCmdL(KAiwCmdUpload, inputParams, outputParams); |
|
352 |
|
353 //Tooltip is returned as a parameter in output list |
|
354 for( TInt i = 0 ; i < outputParams.Count(); i++ ) |
|
355 { |
|
356 const TAiwGenericParam& param = outputParams[i]; |
|
357 if(EGenericParamNoteItem == param.SemanticId()) |
|
358 { |
|
359 TAiwVariant value = param.Value(); |
|
360 TPtrC toolTipToBeReturned = value.AsDes(); |
|
361 aToolTipText = toolTipToBeReturned.AllocLC(); |
|
362 } |
|
363 } |
|
364 } |
|
365 |
|
366 // ---------------------------------------------------------------------------- |
|
367 // SetToolTipL |
|
368 // ---------------------------------------------------------------------------- |
|
369 // |
|
370 void CGlxCommandHandlerUpload::SetToolTipL() |
|
371 { |
|
372 TRACER("CGlxCommandHandlerUpload::SetToolTipL"); |
|
373 |
|
374 CAknToolbar* toolbar = GetAppUi()->CurrentFixedToolbar(); |
|
375 |
|
376 if(toolbar) |
|
377 { |
|
378 CAknButton* uploadButton = static_cast<CAknButton*> |
|
379 (toolbar->ControlOrNull( EGlxCmdUpload )); |
|
380 |
|
381 if(uploadButton && iUploadSupported) |
|
382 { |
|
383 // Get the tooltip text from AIW ShareOnline application |
|
384 HBufC* toolTipText = NULL; |
|
385 |
|
386 // GetToolTipL might allocate memory. Hence toolTipText should |
|
387 // be popped and destroyed if present. |
|
388 GetToolTipL(toolTipText); |
|
389 |
|
390 if( toolTipText ) |
|
391 { |
|
392 // Get current button state and set the help text(tool tip) |
|
393 CAknButtonState* currentState = uploadButton->State(); |
|
394 |
|
395 TBool dimmed = uploadButton->IsDimmed(); |
|
396 if(dimmed) |
|
397 { |
|
398 uploadButton->SetDimmed(EFalse); |
|
399 currentState->SetHelpTextL( toolTipText->Des()); |
|
400 uploadButton->SetDimmed(ETrue); |
|
401 } |
|
402 else |
|
403 { |
|
404 currentState->SetHelpTextL( toolTipText->Des()); |
|
405 } |
|
406 CleanupStack::PopAndDestroy(toolTipText); |
|
407 } |
|
408 else |
|
409 { |
|
410 User::Leave(KErrArgument); |
|
411 } |
|
412 } |
|
413 } |
|
414 } |
|
415 |
|
416 // End of file |
|
417 |