17 |
17 |
18 |
18 |
19 |
19 |
20 #include "glxattributeretriever.h" |
20 #include "glxattributeretriever.h" |
21 |
21 |
22 #include <aknWaitDialog.h> |
22 #include <eikenv.h> |
23 #include <avkon.rsg> |
23 #include <AknUtils.h> |
24 #include <EIKENV.H> |
|
25 #include <aknutils.h> |
|
26 #include <bautils.h> |
24 #include <bautils.h> |
27 #include <data_caging_path_literals.hrh> |
25 #include <data_caging_path_literals.hrh> |
28 #include <stringloader.h> |
26 |
29 |
27 |
30 #include <mpxattributespecs.h> |
28 #include <mpxattributespecs.h> |
31 #include <mpxcollectionpath.h> |
29 #include <mpxcollectionpath.h> |
32 |
30 |
33 #include <glxlog.h> |
31 #include <glxlog.h> |
34 #include <glxmedialist.h> |
32 #include <glxmedialist.h> |
35 #include <glxpanic.h> |
33 #include <glxpanic.h> |
36 #include <glxuistd.h> |
|
37 #include <glxuiutilities.rsg> |
|
38 #include <mglxfetchcontext.h> |
34 #include <mglxfetchcontext.h> |
39 #include <mglxmedialistobserver.h> |
35 #include <mglxmedialistobserver.h> |
40 #include <glxresourceutilities.h> |
|
41 |
36 |
42 |
37 |
43 |
38 |
44 /** |
39 /** |
45 * Observer that should be implemented by users of the |
40 * Observer that should be implemented by users of the |
150 virtual TInt RetrieveL(const MGlxFetchContext* aContext, MGlxMediaList* aList) = 0; |
145 virtual TInt RetrieveL(const MGlxFetchContext* aContext, MGlxMediaList* aList) = 0; |
151 virtual ~MGlxBlockingAttributeRetriever() {}; |
146 virtual ~MGlxBlockingAttributeRetriever() {}; |
152 }; |
147 }; |
153 |
148 |
154 /** |
149 /** |
155 * This class displays a wait dialog and blocks until all requested metadata has been retrieved. |
|
156 */ |
|
157 class CGlxWaitDialogAttributeRetriever : public CBase, |
|
158 public MProgressDialogCallback, |
|
159 public MGlxBlockingAttributeRetriever, |
|
160 public MGlxAttributeRetrieverObserver |
|
161 { |
|
162 public: |
|
163 static CGlxWaitDialogAttributeRetriever* NewLC(); |
|
164 |
|
165 public: // from MGlxBlockingAttributeRetriever |
|
166 /** |
|
167 * See @ref MGlxBlockingAttributeRetriever::RetrieveL |
|
168 */ |
|
169 TInt RetrieveL(const MGlxFetchContext* aContext, MGlxMediaList* aList); |
|
170 |
|
171 private: // from MGlxAttributeRetrieverObserver |
|
172 /** |
|
173 * See @ref MGlxAttributeRetrieverObserver::AttributeRetrievalCompleteL |
|
174 */ |
|
175 void AttributeRetrievalCompleteL(TInt aError); |
|
176 |
|
177 public: // From MProgressDialogCallback |
|
178 void DialogDismissedL(TInt aButtonId); |
|
179 |
|
180 private: |
|
181 /** |
|
182 * Constructor |
|
183 */ |
|
184 CGlxWaitDialogAttributeRetriever(); |
|
185 |
|
186 /** |
|
187 * Destructor |
|
188 */ |
|
189 ~CGlxWaitDialogAttributeRetriever(); |
|
190 |
|
191 /** |
|
192 * Second stage constructor |
|
193 */ |
|
194 void ConstructL(); |
|
195 |
|
196 private: |
|
197 /** |
|
198 * Loads the resource file for this dll |
|
199 */ |
|
200 void AddResourceFileL(); |
|
201 |
|
202 /** |
|
203 * Unloads the resource file for this dll |
|
204 */ |
|
205 void RemoveResourceFile(); |
|
206 |
|
207 private: |
|
208 /// App environment used for accessing resource file (not owned) |
|
209 CCoeEnv* iCoeEnv; |
|
210 |
|
211 /// Wait dialog |
|
212 CAknWaitDialog* iWaitDialog; |
|
213 |
|
214 /// Resource file offset |
|
215 TInt iResourceOffset; |
|
216 |
|
217 /** |
|
218 * Attribute retriever (owned) |
|
219 */ |
|
220 CGlxAttributeRetriever* iAttributeRetriever; |
|
221 |
|
222 /** |
|
223 * Attribute retrieval error |
|
224 */ |
|
225 TInt iError; |
|
226 }; |
|
227 |
|
228 /** |
|
229 * This class blocks until all requested metadata has been retrieved |
150 * This class blocks until all requested metadata has been retrieved |
230 */ |
151 */ |
231 class CGlxSynchronousAttributeRetriever : public CBase, |
152 class CGlxSynchronousAttributeRetriever : public CBase, |
232 public MGlxBlockingAttributeRetriever, |
153 public MGlxBlockingAttributeRetriever, |
233 public MGlxAttributeRetrieverObserver |
154 public MGlxAttributeRetrieverObserver |
282 // ----------------------------------------------------------------------------- |
203 // ----------------------------------------------------------------------------- |
283 // RetrieveL |
204 // RetrieveL |
284 // ----------------------------------------------------------------------------- |
205 // ----------------------------------------------------------------------------- |
285 // |
206 // |
286 EXPORT_C TInt GlxAttributeRetriever::RetrieveL(const MGlxFetchContext& aContext, |
207 EXPORT_C TInt GlxAttributeRetriever::RetrieveL(const MGlxFetchContext& aContext, |
287 MGlxMediaList& aList, TBool aShowDialog) |
208 MGlxMediaList& aList, TBool /*aShowDialog*/) |
288 { |
209 { |
289 MGlxBlockingAttributeRetriever* retriever = NULL; |
210 CGlxSynchronousAttributeRetriever* retriever = NULL; |
290 if (aShowDialog) |
211 retriever = CGlxSynchronousAttributeRetriever::NewLC(); |
291 { |
|
292 retriever = CGlxWaitDialogAttributeRetriever::NewLC(); |
|
293 } |
|
294 else |
|
295 { |
|
296 retriever = CGlxSynchronousAttributeRetriever::NewLC(); |
|
297 } |
|
298 TInt err = retriever->RetrieveL(&aContext, &aList); |
212 TInt err = retriever->RetrieveL(&aContext, &aList); |
299 /** |
213 CleanupStack::PopAndDestroy(retriever); |
300 * This will cause a code scanner warning, but it is not possible to do |
|
301 * CleanupStack::PopAndDestroy(retriever) because the pointer pushed |
|
302 * onto the cleanup stack was either of class CGlxWaitDialogAttributeRetriever |
|
303 * or a CGlxSynchronousAttributeRetriever and the object 'retriever' is of |
|
304 * class MGlxBlockingAttributeRetriever |
|
305 */ |
|
306 CleanupStack::PopAndDestroy(); |
|
307 return err; |
214 return err; |
308 } |
215 } |
309 |
216 |
310 // ----------------------------------------------------------------------------- |
217 // ----------------------------------------------------------------------------- |
311 // Constructor |
218 // Constructor |
505 // therefore the call to NotifyObserversIfCompleteL below is necessary. |
412 // therefore the call to NotifyObserversIfCompleteL below is necessary. |
506 NotifyObserverIfCompleteL(); |
413 NotifyObserverIfCompleteL(); |
507 } |
414 } |
508 |
415 |
509 // ----------------------------------------------------------------------------- |
416 // ----------------------------------------------------------------------------- |
510 // CGlxWaitDialogAttributeRetriever |
|
511 // ----------------------------------------------------------------------------- |
|
512 // |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // CGlxWaitDialogAttributeRetriever::NewLC |
|
516 // ----------------------------------------------------------------------------- |
|
517 // |
|
518 CGlxWaitDialogAttributeRetriever* CGlxWaitDialogAttributeRetriever::NewLC() |
|
519 { |
|
520 CGlxWaitDialogAttributeRetriever* self = new (ELeave) CGlxWaitDialogAttributeRetriever(); |
|
521 CleanupStack::PushL(self); |
|
522 self->ConstructL(); |
|
523 return self; |
|
524 } |
|
525 |
|
526 // ----------------------------------------------------------------------------- |
|
527 // CGlxWaitDialogAttributeRetriever::RetrieveL |
|
528 // ----------------------------------------------------------------------------- |
|
529 // |
|
530 TInt CGlxWaitDialogAttributeRetriever::RetrieveL(const MGlxFetchContext* aContext, MGlxMediaList* aList) |
|
531 { |
|
532 // Load the resource file for this dll containing the wait dialog |
|
533 AddResourceFileL(); |
|
534 |
|
535 // prepare the wait dialog |
|
536 iWaitDialog = new( ELeave ) CAknWaitDialog(reinterpret_cast<CEikDialog**>(&iWaitDialog)); |
|
537 iWaitDialog->PrepareLC(R_GLX_WAIT_NOTE_BLOCKING); // Pushes a point to a CEikDialog onto the CleanupStack. RunLD Pops it. |
|
538 |
|
539 iWaitDialog->SetCallback(this); |
|
540 |
|
541 // Load string for dialog |
|
542 HBufC* title = StringLoader::LoadLC( R_GLX_PROGRESS_GENERAL ); |
|
543 iWaitDialog->SetTextL(*title); |
|
544 CleanupStack::PopAndDestroy(title); |
|
545 |
|
546 // The cancel key is specified in the resource |
|
547 CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current(); |
|
548 cba->AddCommandSetToStackL(R_AVKON_SOFTKEYS_CANCEL); |
|
549 |
|
550 iAttributeRetriever->RetrieveL(aContext, aList); |
|
551 iWaitDialog->RunLD(); // starts another active scheduler and blocks |
|
552 return iError; |
|
553 } |
|
554 |
|
555 // ----------------------------------------------------------------------------- |
|
556 // CGlxWaitDialogAttributeRetriever::AttributeRetrievalComplete |
|
557 // ----------------------------------------------------------------------------- |
|
558 // |
|
559 void CGlxWaitDialogAttributeRetriever::AttributeRetrievalCompleteL(TInt aError) |
|
560 { |
|
561 iError = aError; |
|
562 iWaitDialog->ProcessFinishedL(); |
|
563 } |
|
564 |
|
565 // ----------------------------------------------------------------------------- |
|
566 // CGlxWaitDialogAttributeRetriever::DialogDismissedL |
|
567 // ----------------------------------------------------------------------------- |
|
568 // |
|
569 void CGlxWaitDialogAttributeRetriever::DialogDismissedL(TInt aButtonId) |
|
570 { |
|
571 if (aButtonId == EEikBidCancel) |
|
572 { |
|
573 iAttributeRetriever->CancelRetrieve(); |
|
574 iError = KErrCancel; |
|
575 } |
|
576 } |
|
577 |
|
578 // ----------------------------------------------------------------------------- |
|
579 // Constructor |
|
580 // ----------------------------------------------------------------------------- |
|
581 // |
|
582 CGlxWaitDialogAttributeRetriever::CGlxWaitDialogAttributeRetriever() |
|
583 { |
|
584 iCoeEnv = CCoeEnv::Static(); |
|
585 } |
|
586 |
|
587 // ----------------------------------------------------------------------------- |
|
588 // Destructor |
|
589 // ----------------------------------------------------------------------------- |
|
590 // |
|
591 CGlxWaitDialogAttributeRetriever::~CGlxWaitDialogAttributeRetriever() |
|
592 { |
|
593 RemoveResourceFile(); |
|
594 delete iAttributeRetriever; |
|
595 } |
|
596 |
|
597 // ----------------------------------------------------------------------------- |
|
598 // CGlxWaitDialogAttributeRetriever::ConstructL |
|
599 // ----------------------------------------------------------------------------- |
|
600 // |
|
601 void CGlxWaitDialogAttributeRetriever::ConstructL() |
|
602 { |
|
603 iAttributeRetriever = new (ELeave) CGlxAttributeRetriever(*this); |
|
604 } |
|
605 |
|
606 // ----------------------------------------------------------------------------- |
|
607 // AddResourceFileL |
|
608 // ----------------------------------------------------------------------------- |
|
609 // |
|
610 void CGlxWaitDialogAttributeRetriever::AddResourceFileL() |
|
611 { |
|
612 if (!iResourceOffset) // Lazy construction - ensure that this is only run once |
|
613 { |
|
614 GLX_LOG_INFO("Adding attribute retriever resource file"); |
|
615 TParse parse; |
|
616 parse.Set(KGlxUiUtilitiesResource, &KDC_APP_RESOURCE_DIR, NULL); |
|
617 TFileName resourceFile; |
|
618 resourceFile.Append(parse.FullName()); |
|
619 CGlxResourceUtilities::GetResourceFilenameL(resourceFile); |
|
620 iResourceOffset = iCoeEnv->AddResourceFileL(resourceFile); |
|
621 } |
|
622 } |
|
623 |
|
624 // ----------------------------------------------------------------------------- |
|
625 // RemoveResourceFile |
|
626 // ----------------------------------------------------------------------------- |
|
627 // |
|
628 void CGlxWaitDialogAttributeRetriever::RemoveResourceFile() |
|
629 { |
|
630 if (iResourceOffset) // Check that the resource has been loaded |
|
631 { |
|
632 GLX_LOG_INFO("Removing attribute retriever resource file"); |
|
633 iCoeEnv->DeleteResourceFile( iResourceOffset ); |
|
634 iResourceOffset = 0; |
|
635 } |
|
636 } |
|
637 |
|
638 // ----------------------------------------------------------------------------- |
|
639 // CGlxSynchronousAttributeRetriever |
417 // CGlxSynchronousAttributeRetriever |
640 // ----------------------------------------------------------------------------- |
418 // ----------------------------------------------------------------------------- |
641 // |
419 // |
642 |
420 |
643 // ----------------------------------------------------------------------------- |
421 // ----------------------------------------------------------------------------- |