profilesservices/MediaFileList/Inc/mediafiledialog.h
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2007 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:   Header file of mediafiledialog. UI control of mediafilelist
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef MEDIALFILEDIALOG_H
       
    22 #define MEDIALFILEDIALOG_H
       
    23 
       
    24 
       
    25 //  INCLUDES
       
    26 #include "mediafiledialogutils.h"
       
    27 #include "mediafilepreview.h"
       
    28 #include "mediafilehandler.h"
       
    29 #include "mediafiledialogstate.h"
       
    30 #include "mediafilewaitnote.h"
       
    31 
       
    32 
       
    33 #include <e32base.h>
       
    34 #include <aknlists.h>
       
    35 #include <AknDialog.h>
       
    36 #include <AknInfoPopupNoteController.h> // CAknInfoPopupNoteController
       
    37 #include <eikedwin.h>
       
    38 #include <aknsfld.h>
       
    39 #include <peninputsrveventhandler.h>
       
    40 #include <peninputclient.h>
       
    41 
       
    42 
       
    43 // CONSTANTS
       
    44 
       
    45 // CLASS DECLARATION
       
    46 class CMFDialogTest;
       
    47 class CMFProtectionHandler;
       
    48 class CAknInputBlock;
       
    49 class CVideoPreviewDialog;
       
    50 
       
    51 
       
    52 
       
    53 /**
       
    54 * CMFListHandlerObserver
       
    55 * 
       
    56 * CMFListHandler uses CMFListHandlerObserver to get listbox item texts.
       
    57 */
       
    58 NONSHARABLE_CLASS (CMFListHandlerObserver)
       
    59     {
       
    60     public:
       
    61         virtual TPtrC ConstructListboxItem( TInt aListIndex ) = 0;
       
    62         virtual TInt ListboxItemCount() = 0;
       
    63     };
       
    64 
       
    65 
       
    66 /**
       
    67 * CMFListHandler
       
    68 * 
       
    69 * This class is used as listbox model's item array. Listbox uses it to draw 
       
    70 * list items. CMFListHandler gets list item texts from CMediaFileHandler
       
    71 * (metadata query result). This way there is no need to copy all list items
       
    72 * into listbox model.  
       
    73 */
       
    74 NONSHARABLE_CLASS (CMFListHandler) : public MDesCArray
       
    75     {
       
    76     public:
       
    77 	    static CMFListHandler* NewL();
       
    78 	    ~CMFListHandler();
       
    79     private:	
       
    80 	    void ConstructL(void);
       
    81         CMFListHandler();
       
    82 
       
    83     public:  // from MDesCArray
       
    84 	    TInt MdcaCount() const;
       
    85 	    TPtrC16 MdcaPoint(TInt aIndex) const;
       
    86 
       
    87     public:
       
    88   	    void SetObserver( CMFListHandlerObserver* aObserver );
       
    89 	    static void Panic( TInt aReason );
       
    90 	    
       
    91     private:
       
    92 	    CMFListHandlerObserver* iObserver;  // does not own
       
    93     };
       
    94 
       
    95 
       
    96 
       
    97 
       
    98 
       
    99 
       
   100 /**
       
   101 * CMediaFileDialog
       
   102 *
       
   103 * CMediaFileDialog provides UI for selecting/previewing media files.
       
   104 */
       
   105 NONSHARABLE_CLASS (CMediaFileDialog) :  public CAknDialog, 
       
   106                                         public MEikListBoxObserver,
       
   107                                         public MCoeForegroundObserver,
       
   108                                         public CMFListHandlerObserver,
       
   109                                         public MMediaFileHandlerObserver,
       
   110                                         public MMFActiveCallerObserver,
       
   111                                         public MPreviewHandlerObserver,
       
   112                                         public MMediaFileWaitNoteObserver,
       
   113                                         public MAdaptiveSearchTextObserver,  // not used
       
   114                                         public MPenUiActivationHandler
       
   115 
       
   116     {
       
   117     
       
   118 #ifdef _DEBUG     
       
   119     friend class CMFDialogTest;
       
   120 #endif    
       
   121     
       
   122     enum TListOperationType
       
   123         {
       
   124         EAttrSelect,
       
   125         EAttrOpen,
       
   126         EAttrClicked,
       
   127         EAttrDoubleClicked
       
   128         };
       
   129 
       
   130     enum TDelayedOperationType
       
   131         {
       
   132         EAttrPreview,
       
   133         EAttrSearch,
       
   134         EAttrChangeCba
       
   135         };
       
   136 
       
   137 
       
   138     public:// Constructors and destructor
       
   139 
       
   140         /**
       
   141         * Two-phased constructor.
       
   142         */
       
   143 		static CMediaFileDialog* NewL();
       
   144         
       
   145         /**
       
   146         * Destructor.
       
   147         */
       
   148         virtual ~CMediaFileDialog();
       
   149     
       
   150     private:
       
   151 
       
   152         /**
       
   153         * C++ default constructor.
       
   154         */
       
   155         CMediaFileDialog();
       
   156 	
       
   157         /**
       
   158         * By default Symbian OS constructor is private.
       
   159         */
       
   160         void ConstructL();
       
   161 
       
   162 	public:
       
   163 		TBool ShowDialogL( TDes* aFileName, TInt* aNullItem,
       
   164 		                   TInt* aInfo, TDes* aDesInfo );
       
   165 		
       
   166 		void SetAttrL( TInt aAttr, TInt aValue );
       
   167 		void SetAttrL( TInt aAttr, const TDesC& aValue );
       
   168 		void SetAttrL( TInt aAttr, TAny* aValue );
       
   169         void SetNullItemL( const TDesC& aText, const TDesC& aMediaFile,
       
   170 	                       TInt aMediaFileType, TInt aIconId );
       
   171 		
       
   172 	private:
       
   173         /**
       
   174         * From MEikListBoxObserver, called by framework.
       
   175         * @param aListBox.
       
   176         * @param aEventType.
       
   177 		* @return None
       
   178         */
       
   179 		void HandleListBoxEventL( CEikListBox* aListBox, TListBoxEvent aEventType );
       
   180 
       
   181         /**
       
   182         * From the base class.
       
   183 		* Called by framework before the dialog is shown.
       
   184         * @param None
       
   185 		* @return None
       
   186         */
       
   187         void PreLayoutDynInitL();
       
   188 
       
   189         /**
       
   190         * From the base class.
       
   191 		* Called by framework before exiting the dialog.
       
   192         * @param aButtonId Button id.
       
   193 		* @return ETrue to exit\ EFalse to not to exit.
       
   194         */
       
   195         TBool OkToExitL( TInt aButtonId );
       
   196 
       
   197         /**
       
   198         * From the base class.
       
   199 		* Called by framework for key event handling.
       
   200         * @param aKeyEvent.
       
   201 		* @param aType.
       
   202 		* @return Return code.
       
   203         */
       
   204 		TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType );
       
   205 
       
   206         /**
       
   207         * From the base class.
       
   208 		* Called by framework when dialog is activated.
       
   209         * @param None.
       
   210 		* @return None.
       
   211         */
       
   212 		void ActivateL();
       
   213 
       
   214 		/**
       
   215         * From the base class.
       
   216 		* Called by framework before menu is shown.
       
   217         * @param aResourceId Menu resource id.
       
   218 		* @param aMenuPane Pointer to the menu.
       
   219         * @return None.
       
   220         */
       
   221 		void DynInitMenuPaneL( TInt aResourceID, CEikMenuPane* aMenuPane );
       
   222 
       
   223 		/**
       
   224 		* From the base class.
       
   225 		* Handles menu events.
       
   226 		* @param  aCommandId Command id.
       
   227 		* @return None.
       
   228 		*/
       
   229 		void ProcessCommandL( TInt aCommandId );
       
   230 		
       
   231 		/**
       
   232 		* From base class.
       
   233 		* Called when UI layout changes. 
       
   234 		* @param aType.
       
   235     	* @return None.
       
   236 		*/
       
   237         void HandleResourceChange( TInt aType );
       
   238         
       
   239         /** SetSizeAndPosition
       
   240         * From CAknDialog.
       
   241         * Sets dialog's size to whole main pane.
       
   242         * @param aSize ignored
       
   243         */
       
   244         void SetSizeAndPosition( const TSize &aSize );
       
   245         
       
   246         SEikControlInfo CreateCustomControlL( TInt aControlType );
       
   247         
       
   248         virtual CCoeControl* ComponentControl( TInt aIndex ) const;
       
   249         virtual TInt CountComponentControls() const;
       
   250         
       
   251 
       
   252     private:
       
   253 		TBool DoHandleOKL( TInt aAttr );
       
   254 		TBool HandleOKL( TInt aAttr );
       
   255 		TBool DoHandleBackL();
       
   256 		TBool HandleBackL();
       
   257         void SearchL();
       
   258         void DoSearchL();
       
   259         static TInt StartRomScaning( TAny* aInstance );
       
   260         void StartRomScan();
       
   261 
       
   262     private:
       
   263         void ResetDialogL( TInt aError);
       
   264 		void QueryL( TInt aFolderId, TBool aDatabaseChanged = EFalse );
       
   265 		void GetSelectedItemFileName( TInt aListboxIndex, TDes& aFileName );
       
   266 		TInt CurrentItemListIndex();
       
   267 		void SetIconsL();
       
   268 		CAknSearchField* FindBox() const;
       
   269 		void ResetFindBoxL();
       
   270 		void FindBoxCursorMoveL( TInt aType );
       
   271 		void ShowContextMenuL( TInt aResource );
       
   272 		void PreviewL( TInt aMediaType );
       
   273 		void PreviewVideoL( const TDesC& aFileName );
       
   274 		void PreviewNullItemL( TInt aFolderId );
       
   275 		void StartPreviewWithDelay();
       
   276 		void CancelPreview();
       
   277 		void StartSearchWithDelay();
       
   278 		TBool IsVideoFile( TInt aCurrentIndex );
       
   279 		TBool IsValidVideoFileL( TInt aCurrentIndex, TInt aIntention );
       
   280 		TInt MediaTypeIcon( TInt aListboxIndex );
       
   281 		TInt StorageTypeIcon( TInt aListboxIndex );
       
   282 		void GetListItemText( TInt aListboxIndex, TDes& aText );
       
   283 		
       
   284     private:
       
   285 		void CheckListboxIndex();
       
   286 		void HandleMediaFileChanged();
       
   287 		
       
   288     private:
       
   289 		void UpdateListBoxL( TBool aRestFindBox = ETrue );
       
   290 		void DoUpdateListBoxL( TBool aRestFindBox );
       
   291 		void UpdateCbaL( TInt aAttr );
       
   292     	TInt MapAttribute( TInt aFolderId );
       
   293 		
       
   294 		void ShowErrorNoteL( TInt aError );
       
   295     	void ShowPreviewErrorNoteL( TInt aError, TInt aMediaType );
       
   296 		void DeleteMenuItem( CEikMenuPane* aMenuPane, TInt aCommandId );
       
   297 		CGulIcon* IconL(TAknsItemID aId, const TDesC& aFileName, TInt aFileIndex,
       
   298 			TInt aFileMaskIndex);
       
   299 		CGulIcon* IconL(TAknsItemID aId, const TDesC& aFileName, TInt aFileIndex,
       
   300 			TInt aFileMaskIndex, TAknsQsnIconColorsIndex colorIndex);
       
   301 		static TInt CloseDialog( TAny *aObj );
       
   302 		void CloseDialogWithDelayL();
       
   303 		
       
   304     private:
       
   305         void ShowWaitNoteL( TBool aDatabaseChanged );
       
   306 		void ShowPopupNoteL( const TDesC& aText );
       
   307 		void ShowDetailsPopupL();
       
   308 		void GetPopupText( CMediaFileData* aData, TDes& aText );
       
   309 		TBool MatchFound( const TDesC& aAttribute, const TDesC& aText );
       
   310 		
       
   311         /**
       
   312         * Filters the invalid files from media file handler.
       
   313         * @return None.
       
   314         */
       
   315 		void FilterInvalidFiles();
       
   316 
       
   317     private:
       
   318 		static void Panic( TInt aReason );
       
   319 
       
   320     private:  // from CMFListHandlerObserver
       
   321         TPtrC ConstructListboxItem( TInt aListboxIndex );
       
   322         TInt ListboxItemCount();
       
   323         
       
   324     private:   // from MPreviewHandlerObserver
       
   325         void HandlePreviewEventL( TInt aEvent, TInt aError );
       
   326 
       
   327     private:   // from MMediaFileHandlerObserver
       
   328         void HandleMFEventL( TInt aEvent, TInt aError );
       
   329         
       
   330     private:   // from MMFActiveCallerObserver
       
   331         void HandleActiveCallL( TInt aCallId );
       
   332         
       
   333     private:  //from MCoeControlObserver
       
   334         void HandleControlEventL( CCoeControl* aControl, TCoeEvent aEventType );
       
   335         
       
   336     private:  // from MCoeForegroundObserver
       
   337         void HandleGainingForeground();
       
   338         void HandleLosingForeground();
       
   339         
       
   340     private:  // from MAdaptiveSearchTextObserver
       
   341         void AdaptiveSearchTextChanged( CAknSearchField* aSearchField );
       
   342         
       
   343     private:  // from MPenUiActivationHandler
       
   344         void OnPeninputUiDeactivated();
       
   345         void OnPeninputUiActivated();
       
   346         
       
   347     private:  // MMediaFileWaitNoteObserver
       
   348         void HandleWaitNoteL( TInt aButtonId );
       
   349     
       
   350 #ifdef _DEBUG
       
   351     private: // test code
       
   352         CMFDialogTest* iTest;
       
   353 #endif
       
   354    
       
   355     private:
       
   356 		// listbox
       
   357 		CAknSingleGraphicStyleListBox* iListBox;
       
   358 
       
   359 		// for title and icon handling
       
   360 		CStatusPaneHandler* iStatusPaneHandler;
       
   361 
       
   362 		// long buffer for string handling
       
   363 		TBuf<KBufSize256> iBuf;
       
   364 		
       
   365 		// long buffer for string handling
       
   366 		TBuf<KBufSize256> iPopupText;
       
   367 		
       
   368 		// long buffers for listbox items
       
   369 		TBuf<KBufSize128> iListboxItemText1;
       
   370 		TBuf<KBufSize256> iListboxItemText2;
       
   371 		
       
   372 		// text from search field
       
   373 		TBuf<KBufSize128> iSearchText;
       
   374 	
       
   375 		// long buffers for icon file names
       
   376 		TFileName iIconFileName;
       
   377 		
       
   378 		// list box model item array
       
   379 		CMFListHandler* iMFListHandler;
       
   380 		
       
   381 		// dialog state
       
   382 		CMediaFileDialogState* iState;
       
   383 		
       
   384 		// metadata engine wrapper
       
   385 		CMediaFileHandler* iMediaFileHandler;
       
   386 		
       
   387 		// search box
       
   388 		CAknSearchField* iFindCtrl;
       
   389 		
       
   390 		// for generating active object calls
       
   391 		CMFActiveCaller* iCaller;
       
   392 		CMFActiveCaller* iSearchCaller;
       
   393 		
       
   394 		// for previewing video files
       
   395 		CMFVideoPreviewHandler* iVideoPreviewHandler;
       
   396 		
       
   397 		// for previewing audio files
       
   398 		CMFAudioPreviewHandler* iAudioPreviewHandler;
       
   399         
       
   400 		// popup note
       
   401         CAknInfoPopupNoteController* iPopupNote;
       
   402 
       
   403 		// cancel note in case database query takes more than 2 seconds
       
   404 		CMediaFileWaitNote* iWaitNote;
       
   405 	
       
   406 		// needed for finding out whether search field is in pen input mode
       
   407 		RPeninputServer iPeninputServer;
       
   408 		
       
   409 		// for file protection information (drm etc)
       
   410 		CMFProtectionHandler* iProtectionHandler;
       
   411 		
       
   412 		// for closing dialog
       
   413 		CIdle* iIdle;
       
   414 		
       
   415 		TBool ifilevalid;
       
   416         // is dialog in foreground (visible)
       
   417         TBool iForeGround;
       
   418         
       
   419         // dll resource file id
       
   420         TInt iResourceFileId;
       
   421         
       
   422         // is metadata databse open
       
   423         TBool iDatabaseOpen;
       
   424         
       
   425         // is pen input active
       
   426         TBool iPeninputActive;
       
   427 
       
   428         // dialog attribute values
       
   429         HBufC* iNullItemFileNameOne;
       
   430         HBufC* iNullItemFileNameTwo;
       
   431         TInt iNullItemFileTypeOne;
       
   432         TInt iNullItemFileTypeTwo;
       
   433         TBuf<KBufSize128> iDialogTitle;
       
   434         
       
   435         CAknInputBlock* iInputBlock;
       
   436 		
       
   437 		// dialog output parameters
       
   438 		
       
   439 		// selected media file
       
   440 	    TDes* iFileName;
       
   441 	    // selected null item
       
   442 	    TInt*iNullItem;
       
   443 	    // extra parameter for later use
       
   444 	    TInt* iInfo;
       
   445 	    // extra parameter for later use
       
   446 	    TDes* iDesInfo;
       
   447 	    //is double clicked the item of the listbox
       
   448 	    TBool iIsDoubleClicked;
       
   449 	    TBool iFileisvalid;
       
   450 	    // Video preview dialogue, model dialog
       
   451 	    CVideoPreviewDialog* iVideoPreviewDlg;
       
   452     };
       
   453 
       
   454 
       
   455 
       
   456 /**
       
   457 * CFindControl
       
   458 *
       
   459 * Search field functionality (CFindControl) is copied from
       
   460 * AknSelectionLis (s60/mw/classicui/uifw/AvKon/src/AknSelectionList.cpp).
       
   461 * Example code can also be found in 
       
   462 * s60/app/imppapplications/wvuing/wvuiave/AppSrc/CCAContactSelectionDialog.cpp
       
   463 */
       
   464 NONSHARABLE_CLASS (CFindControl) : public CCoeControl 
       
   465     {
       
   466 public:
       
   467     CAknSearchField *iFind;
       
   468     ~CFindControl() { delete iFind; }
       
   469     void Draw(const TRect &) const
       
   470         {
       
   471         // this removes flicker from CEikDialog's Draw().
       
   472         }
       
   473     void SizeChanged()
       
   474         {
       
   475         TRect mainPane;
       
   476         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
   477         
       
   478         TAknLayoutRect listRect;
       
   479     
       
   480         listRect.LayoutRect( mainPane, AknLayout::list_gen_pane(0) );
       
   481 
       
   482         TRect r( listRect.Rect() );
       
   483         iPosition = TPoint( r.iTl );
       
   484         iSize.SetSize( r.Width(), r.Height() );
       
   485         }
       
   486 
       
   487     TSize MinimumSize()
       
   488         {
       
   489         if ( iFind )
       
   490             {
       
   491             if ( iFind->Size() != TSize( 0, 0 ) )
       
   492                 {
       
   493                 return iFind->Size();
       
   494                 }
       
   495             }
       
   496             
       
   497         return iSize;
       
   498         }
       
   499     };
       
   500 
       
   501 
       
   502 
       
   503 
       
   504 #endif      // MEDIALFILEDIALOG_H
       
   505             
       
   506 // End of File