⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filefetcherappui.cpp

📁 nokia symbian File_Fetching
💻 CPP
字号:
/*
 * ============================================================================
 *  Name     : FileFetcherAppUI.cpp
 *  Part of  : File fetching Example
 *  Created  : 12/9/2003 by Forum Nokia
 *  Implementation notes:
 *
 *     
 *  Version  : 1.0
 *  Copyright: Nokia Corporation
 * ============================================================================
 */

#include <avkon.hrh>
#include <aknnotewrappers.h> 
#include <eikmenup.h>
#include <caknfileselectiondialog.h> 
#include <MGFetch.h>
#include <pathinfo.h>
#include <apgcli.h>
#include <apgtask.h>
#include <apmstd.h>

#include <FileFetcher.rsg>
#include "FileFetcher.pan"
#include "FileFetcherAppUi.h"
#include "FileFetcherAppView.h"
#include "FileFetcher.hrh"


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::ConstructL()
// 
// Second phase construction
// ----------------------------------------------------------------------------
void CFileFetcherAppUi::ConstructL()
{
    BaseConstructL(EAknEnableSkin);

    iAppView = CFileFetcherAppView::NewL(ClientRect());
    AddToStackL(iAppView);
}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::CFileFetcherAppUi()
//
// First phase construction
// ----------------------------------------------------------------------------
CFileFetcherAppUi::CFileFetcherAppUi()
{
}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::~CFileFetcherAppUi()
//
// Destructor
// ----------------------------------------------------------------------------
CFileFetcherAppUi::~CFileFetcherAppUi()
{
	if (iAppView)
		{
		iEikonEnv->RemoveFromStack(iAppView);
		delete iAppView;
		iAppView = NULL;
		}
}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::HandleCommandL()
//
// Handles user commands
// ----------------------------------------------------------------------------
void CFileFetcherAppUi::HandleCommandL(TInt aCommand)
{
	switch(aCommand) {
	case EEikCmdExit:
	case EAknSoftkeyExit:
		Exit();
		break;

	// Menu commands for MGFetch example
	case EMGFetchMenuImages:
		BrowseUsingMGFetchL(EImageFile);
		break;
	case EMGFetchMenuVideo:
		BrowseUsingMGFetchL(EVideoFile);
		break;
	case EMGFetchMenuAudio:
		BrowseUsingMGFetchL(EAudioFile);
		break;
	case EMGFetchMenuGMSFile:
		BrowseUsingMGFetchL(EGMSFile);
		break;

	// Menu commands for CAknSelectionDialog example
	case EAknSelectionMenuImages:
		BrowseUsingAknSelectionDlg(PathInfo::ImagesPath());
		break;
	case EAknSelectionMenuVideo:
		BrowseUsingAknSelectionDlg(PathInfo::VideosPath());
		break;
	case EAknSelectionMenuAudio:
		BrowseUsingAknSelectionDlg(PathInfo::SoundsPath());
		break;
	case EAknSelectionMenuGMSFile:
		BrowseUsingAknSelectionDlg(PathInfo::GmsPicturesPath());
		break;

	default:
		Panic(EFileFetcherUi);
		break;
	}
	}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::BrowseUsingAknSelectionDlg
// 
// Opens a new CAknFileSelectionDialog with given aPath (relative to 
// phone memory root path).
// ----------------------------------------------------------------------------
void CFileFetcherAppUi::BrowseUsingAknSelectionDlg(const TFileName& aPath)
	{
	TFileName filename;

	// Create default filename. (contains only the folder, 
	// e.g. C:\Nokia\Images\) This is used as a starting folder for browsing.
	filename.Append(PathInfo::PhoneMemoryRootPath());
	filename.Append(aPath);

	_LIT(KDialogTitle, "Browse files");
	TBool ret = CAknFileSelectionDialog::RunDlgLD(
		filename,		// on return, contains the selected file's name
		PathInfo::PhoneMemoryRootPath(), // default root path for browsing
		KDialogTitle,	// Dialog's title
		this			// Pointer to class implementing 
						// MAknFileSelectionObserver. OkToExitL is called
						// when user has selected an file.
		);

	// "ret" is true, if user has selected a file
	if( ret )
		{
		// Open the selected file into default application
		_LIT(KQueryStr, "Open file?");
		if( iEikonEnv->QueryWinL(KQueryStr,filename ) )
			{
			ViewFileL(filename);
			}
		}
	}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::OkToExitL
//
// Inherited from MAknFileSelectionObserver.
// Called when user selects a file from CAknFileSelectionDialog.
// ----------------------------------------------------------------------------
TBool CFileFetcherAppUi::OkToExitL (const TDesC& /*aDriveAndPath*/,
									const TEntry& /*aEntry*/)
	{
	// Return ETrue if it is OK to close the CAknFileSelectionDialog.
	return ETrue;
	}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::BrowseUsingMGFetchL
//
// Opens MGFetch dialog with given media type.
// ----------------------------------------------------------------------------
void CFileFetcherAppUi::BrowseUsingMGFetchL(TMediaFileType aMediaType)
	{
	// Create array of descriptors for the selected files
	CDesCArrayFlat* fileArray = new (ELeave) CDesCArrayFlat(5);
	CleanupStack::PushL(fileArray);

	// Open the dialog.
	TBool ret = MGFetch::RunL(
		*fileArray, // When dialog is closed, fileArray contains selected files
		aMediaType, // Displays only media files of type aMediaType
		EFalse,		// Not used in S60 2.0 (single or multiple file selection)
		this		// Pointer to class implementing MMGFetchVerifier;
					// when user has selected file(s), 
					// MMGFetchVerifier::VerifySelectionL is called.
		);

	// "ret" is true, if user has selected file(s)
	if( ret )
		{
		// Open the first selected file into default application
		_LIT(KQueryStr, "Open file?");
		if(iEikonEnv->QueryWinL(KQueryStr, fileArray->MdcaPoint(0)))
			{
			ViewFileL(fileArray->MdcaPoint(0));
			}
		}

	CleanupStack::PopAndDestroy(); // fileArray
	}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::VerifySelectionL
// 
// Inherited from MMGFetchVerifier.
// Called when user selects file(s) from MGFetch dialog.
// ----------------------------------------------------------------------------
TBool CFileFetcherAppUi::VerifySelectionL(const MDesCArray* /*aSelectedFiles*/)
	{
	// Verify the validity of aSelectedFiles if needed.
	// Return ETrue if we accept the selected file(s), otherwise return EFalse
	return ETrue;
	}


// ----------------------------------------------------------------------------
// CFileFetcherAppUi::ViewFileL
//
// Opens aFilename -file into the application that is registered to handle
// the file type.
// ----------------------------------------------------------------------------
void CFileFetcherAppUi::ViewFileL(const TDesC& aFileName) const
	{
    TDataType type;
    RApaLsSession appArcSession;

	// connect to AppArc server
    User::LeaveIfError(appArcSession.Connect());

	// Find the UID of the application that is registered to the MIME type of
	// the file (aFileName).
    TUid aUid;
    appArcSession.AppForDocument(aFileName, aUid, type);
    if (aUid != TUid::Uid(0) )
		{
		// Application found that could handle the file. Now we need to find
		// out from task list if the application is already running.
        TApaTaskList taskList( iEikonEnv->WsSession() );
        TApaTask task = taskList.FindApp( aUid );
        if ( task.Exists() )
			{
			// Application is already running. Requests the task to close its 
			// existing document and open a new one.
			task.BringToForeground();
			task.SwitchOpenFile( aFileName );
			}
			else
			{
			// Application is not running; start it with a new document
            TThreadId id;
            appArcSession.StartDocument( aFileName, type, id );
			}
		} else {
		// Cannot find application that could handle the file.
		_LIT(KCannotOpenFile,
			"Cannot open file. No application found to handle the file.");
		iEikonEnv->InfoWinL(KCannotOpenFile,aFileName);
		}

    appArcSession.Close();
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -