mmappcomponents/audiofetcher/src/audiofetcher.cpp
changeset 0 a2952bb97e68
child 63 91d5ad76f5c6
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 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: provide synchronized access to file system and metadata source
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <aknViewAppUi.h>				// CAknViewAppUi 
       
    20 #include <avkon.rsg>
       
    21 #include <data_caging_path_literals.hrh>// KDC_APP_RESOURCE_DIR			
       
    22 #include <eikapp.h>						// CEikApplication 
       
    23 #include <e32cmn.h> 
       
    24 #include <coemain.h>
       
    25 #include <e32base.h>
       
    26 #include <bautils.h>
       
    27 #include <AknUtils.h>
       
    28 
       
    29 #include "audiofetcher.hrh"            // For implementation id
       
    30 #include "audiofetcher.h"
       
    31 #include "audiofetcherlog.h"
       
    32 #include "audiofetcherdialog.h"
       
    33 #include <audiofetcherdialog.rsg>
       
    34 
       
    35 _LIT(KAudioFetcherDialogResource, "AudioFetcherdialog.rsc" ); // AudioFetcherDialog Resource File
       
    36     
       
    37 // ---------------------------------------------------------------------------
       
    38 // Two-phased constructor.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CAudioFetcher* CAudioFetcher::NewL()
       
    42     {
       
    43     WLOG("CAudioFetcher::NewL");
       
    44     CAudioFetcher* self = new( ELeave ) CAudioFetcher();
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Symbian 2nd phase constructor can leave.
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CAudioFetcher::ConstructL()
       
    56     {
       
    57     WLOG("CAudioFetcher::ConstructL");
       
    58     // No implementation required
       
    59     }
       
    60     
       
    61 // ---------------------------------------------------------------------------
       
    62 // C++ default constructor can NOT contain any code, that might leave.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CAudioFetcher::CAudioFetcher()
       
    66     {
       
    67     WLOG("CAudioFetcher::CAudioFetcher");
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Destructor
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CAudioFetcher::~CAudioFetcher()
       
    75     {
       
    76     WLOG("CAudioFetcher::~CAudioFetcher >");
       
    77 
       
    78 
       
    79     if ( iResourceOffset )
       
    80         {
       
    81         CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
       
    82         }
       
    83 
       
    84     delete iSelectionSoftkey;
       
    85     delete iTitle;
       
    86     
       
    87     WLOG("CAudioFetcher::~CAudioFetcher <");
       
    88     }
       
    89     
       
    90 // ---------------------------------------------------------------------------
       
    91 // SetMultiSelectionL
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CAudioFetcher::SetMultiSelectionL( TBool aMultiSelect )
       
    95     {
       
    96     WLOG("CAudioFetcher::SetMultiSelectionL");
       
    97     iIsMultiSelection = aMultiSelect;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // SetMimeTypesL
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CAudioFetcher::SetMimeTypesL( const MDesCArray& /*aMimeTypes*/ )
       
   105     {
       
   106     WLOG("CAudioFetcher::SetMimeTypesL (not supported)");
       
   107     // No implementation required (not supported)
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // SetSelectionSoftkeyL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CAudioFetcher::SetSelectionSoftkeyL( const TDesC& aSelectionSoftkey )
       
   115     {
       
   116     WLOG("CAudioFetcher::SetSelectionSoftkeyL");
       
   117 	
       
   118 	HBufC* tmp = aSelectionSoftkey.AllocL();
       
   119 	delete iSelectionSoftkey;
       
   120 	iSelectionSoftkey = tmp;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // SetHeadingL
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CAudioFetcher::SetHeadingL( const TDesC& aTitle )
       
   128     {
       
   129     WLOG("CAudioFetcher::SetHeadingL");
       
   130 	
       
   131 	HBufC* tmp = aTitle.AllocL();
       
   132 	delete iTitle;
       
   133 	iTitle = tmp;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // SetVerifierL
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CAudioFetcher::SetVerifierL( MMGFetchVerifier& aVerifier )
       
   141     {
       
   142     WLOG("CAudioFetcher::SetVerifierL");
       
   143 
       
   144 	iVerifier = &aVerifier;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // GetCancelerL
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CAudioFetcher::GetCancelerL( MMGFetchCanceler*& aCanceler )
       
   152     {
       
   153     WLOG("CAudioFetcher::GetCancelerL");
       
   154 	
       
   155 	aCanceler = this;
       
   156     }
       
   157 
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // LaunchL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TBool CAudioFetcher::LaunchL( CDesCArray& aSelectedFiles,
       
   164                                TMediaFileType aMediaType )
       
   165    	{
       
   166    	WLOG("CAudioFetcher::LaunchL >");
       
   167 		
       
   168 	TInt buttonId;
       
   169     TFileName resFile;
       
   170     TParse parse;
       
   171     parse.Set( KAudioFetcherDialogResource, &KDC_APP_RESOURCE_DIR, NULL );
       
   172 
       
   173     resFile.Append(parse.FullName()); 
       
   174     GetResourceFilenameL( resFile );
       
   175     iResourceOffset = CCoeEnv::Static()->AddResourceFileL( resFile );
       
   176 
       
   177 	// Configure heading and filter type
       
   178 	switch ( aMediaType )
       
   179 	    {
       
   180 	    case EAudioFile:
       
   181 	    case EMusicFile:
       
   182 	        {
       
   183             iTitle = TitleForAudioFetcherL();
       
   184             break;
       
   185 	        }
       
   186 	    case EAnyMediaFile:
       
   187 	        {
       
   188             iTitle = TitleForAnyMediaFileFetcherL();
       
   189 	        break;
       
   190 	        }
       
   191 	    default:
       
   192 	        {
       
   193 	        WLOG("CAudioFetcher::LaunchL  - Error: Unsupported media type, Leaving");
       
   194             User::Leave( KErrNotSupported );
       
   195 	        }
       
   196 	    }
       
   197 	
       
   198 	// create the dialog first
       
   199 	CAudioFetcherDialog* dialog =
       
   200 	    CAudioFetcherDialog::NewL( aSelectedFiles, iVerifier, *iTitle, iIsMultiSelection, aMediaType );
       
   201 	
       
   202 	// Returns zero when Fetcher is cancelled by User.
       
   203 	buttonId = dialog->ExecuteLD( R_MODAL_SINGLE_DIALOG );	
       
   204 	
       
   205 	dialog = NULL;
       
   206 	WLOG("CAudioFetcher::LaunchL <");
       
   207     // Return false if the fetcher was canceled by user
       
   208 	return ( 0 != buttonId && aSelectedFiles.Count() != 0 );
       
   209   	}
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // Return nearest resource file
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CAudioFetcher::GetResourceFilenameL( TFileName& aResFile )
       
   216     {
       
   217     RFs fs;
       
   218     User::LeaveIfError( fs.Connect() );
       
   219     CleanupClosePushL( fs );
       
   220     
       
   221     // don't use AknUtils CompleteWithAppPath  
       
   222     aResFile.Insert( 0, TDriveUnit( EDriveC).Name() );
       
   223     // try to locate the localised resource
       
   224     BaflUtils::NearestLanguageFile( fs, aResFile );
       
   225     // if the localised resource is found, the file name is changed to 
       
   226     // the localised name (z:\apps\resources\xxx.r001)
       
   227     if( !BaflUtils::FileExists( fs, aResFile ) )
       
   228         {
       
   229         // not found on c drive, try z
       
   230         aResFile.Replace( 0, KMaxDriveName, TDriveUnit( EDriveZ ).Name() );
       
   231         // try to locate the localised resource again
       
   232         BaflUtils::NearestLanguageFile( fs, aResFile );
       
   233         // if file was not found this time, there is no localised 
       
   234         // resource with the name
       
   235         if (!BaflUtils::FileExists( fs, aResFile ) )
       
   236             {
       
   237             User::Leave( KErrNotFound );
       
   238             }
       
   239         }
       
   240     
       
   241     CleanupStack::PopAndDestroy( &fs );
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // Return Dialog title
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 HBufC* CAudioFetcher::TitleForAudioFetcherL() const
       
   249     {
       
   250     WLOG("CAudioFetcher::TitleForAudioFetcherL()");
       
   251     return TitleL( R_AUDIOFETCHER_DIALOG_TITLE_AUDIO );
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Return Dialog title
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 HBufC* CAudioFetcher::TitleForAnyMediaFileFetcherL() const
       
   259     {
       
   260     WLOG("CAudioFetcher::TitleForAudioFetcherL()");
       
   261     return TitleL( R_AUDIOFETCHER_DIALOG_TITLE_ANY_FILE );
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------------------------
       
   265 // Return Dialog title
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 HBufC* CAudioFetcher::TitleL( TInt aSingleSelectionTitleResourceId ) const
       
   269     {
       
   270     WLOG("CAudioFetcher::TitleL()");
       
   271 
       
   272     if( !iTitle )
       
   273         {
       
   274         TInt resourceId = aSingleSelectionTitleResourceId;
       
   275         return CCoeEnv::Static()->AllocReadResourceL( resourceId );
       
   276         }
       
   277     return iTitle;
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // From MMGFetchCanceler
       
   282 // -----------------------------------------------------------------------------
       
   283 //	
       
   284 void CAudioFetcher::CancelFetcherL()
       
   285     {
       
   286     WLOG("CAudioFetcher::CancelFetcherL");
       
   287     
       
   288     }
       
   289 
       
   290 // End of File
       
   291 
       
   292