uifw/AvKon/tsrc/bc/S60_SDK3.0/bctestcmdlg/src/bctestfileseldlg.cpp
changeset 22 75713bee6484
parent 21 558113899881
child 26 62ef28f7b435
child 28 d33307312dfe
equal deleted inserted replaced
21:558113899881 22:75713bee6484
     1 /*
       
     2 * Copyright (c) 2006 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:  test case
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <w32std.h>
       
    20 #include <coecntrl.h>
       
    21 #include <MAknFileSelectionObserver.h>
       
    22 #include <MaknFileFilter.h>
       
    23 
       
    24 #include "BCTestFileSelDlg.h"
       
    25 #include "BCTestCmDlg.hrh"
       
    26 #include "streamlogger.h"
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Symbian 2nd static Constructor
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CBCTestFileSelDlg* CBCTestFileSelDlg::NewL()
       
    35     {
       
    36     CBCTestFileSelDlg* self = new( ELeave ) CBCTestFileSelDlg();
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42     
       
    43 // ---------------------------------------------------------------------------
       
    44 // C++ default constructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CBCTestFileSelDlg::CBCTestFileSelDlg():iDlg(0)
       
    48     {    
       
    49     }
       
    50     
       
    51 // ---------------------------------------------------------------------------
       
    52 // Destructor
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CBCTestFileSelDlg::~CBCTestFileSelDlg()
       
    56     {  
       
    57 	delete iDlg;
       
    58     }
       
    59     
       
    60 // ---------------------------------------------------------------------------
       
    61 // Symbian 2nd Constructor
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CBCTestFileSelDlg::ConstructL()
       
    65     {    
       
    66     BuildScriptL();    
       
    67     }
       
    68     
       
    69 // ---------------------------------------------------------------------------
       
    70 // CBCTestFileSelDlg::BuildScriptL
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CBCTestFileSelDlg::BuildScriptL()
       
    74     { 
       
    75 	AddTestL( DELAY(1), TEND);
       
    76 
       
    77     // Add script as your need.   
       
    78 	for(int i=0; i<EBCTestCmdFileSelDlgEnd - EBCTestCmdFileSelDlgBegin -1; ++i)
       
    79 		{
       
    80 		AddTestL( LeftCBA, REP(Down, 2), Right, TEND );
       
    81 		for(int j=0; j<i; ++j)
       
    82 			AddTestL( Down, TEND);
       
    83 		AddTestL( LeftCBA, TEND );	
       
    84 		AddCancelL();		//OK may enter a folder and ask user to select more.
       
    85 		}
       
    86     }
       
    87     
       
    88 void CBCTestFileSelDlg::AddOKL()
       
    89 	{
       
    90 	// add dlg response sciprts
       
    91 	for(int i=0; i<1; ++i)
       
    92 		AddTestL( WAIT(5), KeyOK, TEND);
       
    93 	}
       
    94 
       
    95 void CBCTestFileSelDlg::AddCancelL()
       
    96 	{
       
    97 	// add dlg response sciprts
       
    98 	for(int i=0; i<1; ++i)
       
    99 		AddTestL( WAIT(5), RightCBA, TEND);
       
   100 	}
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CBCTestFileSelDlg::RunL
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CBCTestFileSelDlg::RunL( TInt aCmd )
       
   107     {
       
   108 	SetupL();
       
   109 	switch(aCmd){
       
   110 	case EBCTestCmdFileSelDlgCreate:
       
   111 		TestCreateL();
       
   112 		break;
       
   113 	case EBCTestCmdFileSelDlgCreateRes:
       
   114 		TestCreateL(0);		// 0 is default res id
       
   115 		break;
       
   116 	case EBCTestCmdFileSelDlgQuickCreate:
       
   117 		TestQuickCreateL();
       
   118 		break;
       
   119 	case EBCTestCmdFileSelDlgQuickCreateTitle:
       
   120 		TestQuickCreateL(_L("a title"));
       
   121 		break;
       
   122 	case EBCTestCmdFileSelDlgQuickCreateRes:
       
   123 		TestQuickCreateL(0);	// 0 is the default res id
       
   124 		break;
       
   125 	case EBCTestCmdFileSelDlgSettings:
       
   126 		TestSettingsL();
       
   127 		break;
       
   128 	default:
       
   129 		break;
       
   130 	}
       
   131     Teardown();
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CBCTestFileSelDlg::ReleaseCaseL
       
   136 // ---------------------------------------------------------------------------
       
   137 //   
       
   138 void CBCTestFileSelDlg::Teardown()
       
   139     {
       
   140 	delete iDlg;
       
   141 	iDlg = NULL;
       
   142     }
       
   143 
       
   144 void CBCTestFileSelDlg::TestCreateL()
       
   145 	{
       
   146 	_LIT( KRootPath,					"C:\\Data\\" );
       
   147 	TFileName rootFileName( KRootPath );
       
   148 
       
   149 	iDlg = CAknFileSelectionDialog::NewL( ECFDDialogTypeSelect );
       
   150 	AssertNotNullL(iDlg, _L("file sel dialog create"));
       
   151 	TInt returnValue = iDlg->ExecuteL( rootFileName );
       
   152 	TFileName msg;
       
   153 	msg.Format( _L("User hit: %d, selected file: "), returnValue );
       
   154 	msg.Append( rootFileName );
       
   155 	msg.ZeroTerminate();
       
   156 	AssertTrueL(ETrue, msg);
       
   157 	}
       
   158 
       
   159 void CBCTestFileSelDlg::TestCreateL(TInt aResID)
       
   160 	{
       
   161 	_LIT( KRootPath,					"C:\\Data\\" );
       
   162 	TFileName rootFileName( KRootPath );
       
   163 
       
   164 	iDlg = CAknFileSelectionDialog::NewL( ECFDDialogTypeSelect, aResID );
       
   165 	AssertNotNullL(iDlg, _L("file sel dialog create with Res ID"));
       
   166 	TInt returnValue = iDlg->ExecuteL( rootFileName );
       
   167 	TFileName msg;
       
   168 	msg.Format(_L("User hit: %d, selected file: "), returnValue );
       
   169 	msg.Append( rootFileName );
       
   170 	msg.ZeroTerminate();
       
   171 	AssertTrueL(ETrue, msg);
       
   172 	}
       
   173 
       
   174 void CBCTestFileSelDlg::TestQuickCreateL()
       
   175 	{
       
   176 	TFileName filename;
       
   177 	TFileName folder(_L("C:\\Data\\"));
       
   178 	AssertTrueL(!CAknFileSelectionDialog::RunDlgLD(filename, folder), 
       
   179 		_L("Quick create, User hit Cancle"));
       
   180 	}
       
   181 
       
   182 void CBCTestFileSelDlg::TestQuickCreateL(const TDesC &aTitle)
       
   183 	{
       
   184 	TFileName filename;
       
   185 	TFileName folder(_L("C:\\Data\\"));
       
   186 	AssertTrueL(!CAknFileSelectionDialog::RunDlgLD(filename, folder, aTitle), 
       
   187 		_L("Quick create, User hit Cancle"));
       
   188 	}
       
   189 
       
   190 void CBCTestFileSelDlg::TestQuickCreateL(TInt aResID)
       
   191 	{
       
   192 	TFileName filename;
       
   193 	TFileName folder(_L("C:\\Data\\"));
       
   194 	AssertTrueL(!CAknFileSelectionDialog::RunDlgLD(filename, folder, aResID), 
       
   195 		_L("Quick create, User hit Cancle"));
       
   196 	}
       
   197 
       
   198 void CBCTestFileSelDlg::SetupL()
       
   199 	{
       
   200 	}
       
   201 
       
   202 
       
   203 void CBCTestFileSelDlg::TestSettingsL()
       
   204 {
       
   205 	iDlg = CAknFileSelectionDialog::NewL( ECFDDialogTypeSelect );
       
   206 	iDlg->SetDefaultFolderL(_L("C:\\"));
       
   207 	AssertTrueL(ETrue, _L("default folder set"));
       
   208 
       
   209 	iDlg->SetTitleL(_L("a title"));
       
   210 	AssertTrueL(ETrue, _L("title set"));
       
   211 
       
   212 	iDlg->SetLeftSoftkeyFileL(_L("left fkey"));
       
   213 	AssertTrueL(ETrue, _L("left soft key file set"));
       
   214 
       
   215 	iDlg->SetLeftSoftkeyFolderL(_L("left dkey"));
       
   216 	AssertTrueL(ETrue, _L("left soft key folder set"));
       
   217 
       
   218 	iDlg->SetRightSoftkeyRootFolderL(_L("right root"));
       
   219 	AssertTrueL(ETrue, _L("right soft key root set"));
       
   220 
       
   221 	iDlg->SetRightSoftkeySubfolderL(_L("right sdir"));
       
   222 	AssertTrueL(ETrue, _L("right soft key sub folder set"));
       
   223 
       
   224 	//Add fileter and set Observer
       
   225 	struct MonkObserver: public MAknFileSelectionObserver{
       
   226 		TBool OkToExitL( const TDesC& /*aDriveAndPath*/, const TEntry& /*aEntry*/ ){
       
   227 			return ETrue;
       
   228 		}
       
   229 	} monkObserver;
       
   230 	
       
   231 	iDlg->SetObserver(&monkObserver);
       
   232 	AssertTrueL(ETrue, _L("Observer set"));
       
   233 
       
   234 	struct MonkFilter: public MAknFileFilter{
       
   235 		TBool Accept( const TDesC& /*aDriveAndPath*/, const TEntry& /*aEntry*/ ) const{
       
   236 			return ETrue;
       
   237 		}
       
   238 	};
       
   239 
       
   240 	iDlg->AddFilterL(new (ELeave) MonkFilter);	//problems, should be push into stack
       
   241 	AssertTrueL(ETrue, _L("Filter add"));
       
   242 
       
   243 	TFileName filename;
       
   244 	iDlg->ExecuteL(filename);
       
   245 }