filemanager/View/src/Cfilemanagerfoldernamequerydlg.cpp
branchRCL_3
changeset 39 65326cf895ed
equal deleted inserted replaced
38:491b3ed49290 39:65326cf895ed
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Dialog for asking folder name from user
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StringLoader.h>
       
    22 #include <aknnotewrappers.h> 
       
    23 #include <bautils.h>
       
    24 #include <CFileManagerEngine.h>
       
    25 #include <CFileManagerUtils.h>
       
    26 #include <filemanagerview.rsg>
       
    27 #include "Cfilemanagerfoldernamequerydlg.h"
       
    28 #include "CFileManagerCommonDefinitions.h"
       
    29 #include "FileManagerDlgUtils.h"
       
    30 #include "CFileManagerItemProperties.h"
       
    31 
       
    32 
       
    33 // CONSTANTS
       
    34 // If number is 10 or more 2 digits are needed to display it
       
    35 const TInt KTwoDigitNeeded = 10;
       
    36 _LIT( KFormatStringTwoDigit, "%02d" );
       
    37 _LIT( KFormatString, "%d" );
       
    38 const TInt KFormatBufLen = 16;
       
    39 
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CFileManagerFolderNameQueryDlg::NewL
       
    45 // 
       
    46 // -----------------------------------------------------------------------------
       
    47 // 
       
    48 CFileManagerFolderNameQueryDlg* CFileManagerFolderNameQueryDlg::NewL(
       
    49         TDes& aDataText,
       
    50         CFileManagerEngine& aEngine,
       
    51         TBool aNameGeneration )
       
    52     {
       
    53     CFileManagerFolderNameQueryDlg* self = 
       
    54         new( ELeave ) CFileManagerFolderNameQueryDlg( aDataText, aEngine );
       
    55     
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL( aNameGeneration, aDataText );
       
    58     CleanupStack::Pop( self );
       
    59 
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CFileManagerFolderNameQueryDlg::CFileManagerFolderNameQueryDlg
       
    65 // C++ default constructor can NOT contain any code, that
       
    66 // might leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CFileManagerFolderNameQueryDlg::CFileManagerFolderNameQueryDlg( 
       
    70                                     TDes& aDataText, 
       
    71                                     CFileManagerEngine& aEngine ) :
       
    72     CAknTextQueryDialog( aDataText ),
       
    73     iEngine( aEngine )
       
    74     {
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CFileManagerFolderNameQueryDlg::ConstructL
       
    79 // 
       
    80 // -----------------------------------------------------------------------------
       
    81 // 
       
    82 void CFileManagerFolderNameQueryDlg::ConstructL( TBool aNameGeneration, 
       
    83                                                  TDes& aDataText )
       
    84     {
       
    85     if( aNameGeneration )
       
    86         {
       
    87         TInt i( 1 );
       
    88         HBufC* folderName =
       
    89             StringLoader::LoadLC( R_FILEMANAGER_DEFAULT_FOLDER_NAME );
       
    90         TBuf< KFormatBufLen > numBuf;
       
    91 
       
    92         while( iEngine.IsNameFoundL( *folderName ) )
       
    93             {
       
    94             CleanupStack::PopAndDestroy( folderName );
       
    95             numBuf.Zero();
       
    96             if( i < KTwoDigitNeeded ) 
       
    97                 {
       
    98                 numBuf.Format( KFormatStringTwoDigit, i );
       
    99                 }
       
   100             else
       
   101                 {
       
   102                 numBuf.Format( KFormatString, i );
       
   103                 }
       
   104             AknTextUtils::DisplayTextLanguageSpecificNumberConversion(
       
   105                 numBuf );
       
   106             folderName = StringLoader::LoadLC(
       
   107                 R_FILEMANAGER_DEFAULT_FOLDER_NAME_N, numBuf );
       
   108             ++i;
       
   109             }
       
   110         Text().Copy( *folderName );
       
   111         CleanupStack::PopAndDestroy( folderName );
       
   112         }
       
   113     else
       
   114         {
       
   115         iOldName = aDataText.AllocL();
       
   116         TParsePtrC parse(
       
   117             CFileManagerUtils::StripFinalBackslash( *iOldName ) );
       
   118         if ( parse.PathPresent() )
       
   119             {
       
   120             Text().Copy( parse.NameAndExt() );
       
   121             }
       
   122         else
       
   123             {
       
   124             Text().Copy( *iOldName );
       
   125             }
       
   126             
       
   127         // Strip any directionality markers to get pure name
       
   128         TPtr ptr( iOldName->Des() );
       
   129         AknTextUtils::StripCharacters( ptr, KFmgrDirectionalChars );
       
   130         }
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CFileManagerFolderNameQueryDlg::~CFileManagerFolderNameQueryDlg
       
   135 // Destructor
       
   136 // -----------------------------------------------------------------------------
       
   137 // 
       
   138 CFileManagerFolderNameQueryDlg::~CFileManagerFolderNameQueryDlg()
       
   139     {
       
   140     delete iOldName;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CFileManagerFolderNameQueryDlg::DoOkToExitL
       
   145 // 
       
   146 // -----------------------------------------------------------------------------
       
   147 // 
       
   148 TBool CFileManagerFolderNameQueryDlg::DoOkToExitL( TInt aButtonId )
       
   149     {
       
   150     TBool result( CAknTextQueryDialog::OkToExitL( aButtonId ) );
       
   151 
       
   152     HBufC* userText = Text().AllocLC();
       
   153     TPtr ptrUserText( userText->Des() );
       
   154 
       
   155     // Strip any directionality markers to get pure name
       
   156     AknTextUtils::StripCharacters( ptrUserText, KFmgrDirectionalChars );
       
   157     
       
   158     // Remove white spaces from end, file server also ignores those
       
   159     ptrUserText.TrimRight();
       
   160 
       
   161     // Check folder name
       
   162     TBool isValidName( EFalse );
       
   163     TPtrC empty( KNullDesC );
       
   164     TParsePtrC oldName( CFileManagerUtils::StripFinalBackslash(
       
   165         iOldName ? *iOldName : empty ) );
       
   166     if ( oldName.PathPresent() )
       
   167         {
       
   168         isValidName = iEngine.IsValidName(
       
   169             oldName.DriveAndPath(), *userText, ETrue );
       
   170         }
       
   171     else
       
   172         {
       
   173         isValidName = iEngine.IsValidName( KNullDesC, *userText, ETrue );
       
   174         }
       
   175 
       
   176     if( !isValidName )
       
   177         {
       
   178         if( iEngine.IllegalChars( *userText ) )
       
   179             {
       
   180             FileManagerDlgUtils::ShowInfoNoteL(
       
   181                 R_QTN_FLDR_ILLEGAL_CHARACTERS );
       
   182             }
       
   183         else
       
   184             {
       
   185             FileManagerDlgUtils::ShowInfoNoteL(
       
   186                 R_QTN_FLDR_BAD_FILE_NAME );
       
   187             }
       
   188         CAknQueryControl* queryControl = QueryControl();
       
   189         if ( queryControl )
       
   190             {
       
   191             CEikEdwin* edwin = static_cast< CEikEdwin* >( queryControl->
       
   192                 ControlByLayoutOrNull( EDataLayout ) );
       
   193             if ( edwin )
       
   194                 {
       
   195                 edwin->SetSelectionL( edwin->TextLength(), 0 );
       
   196                 }
       
   197             }
       
   198         CleanupStack::PopAndDestroy( userText );
       
   199         return EFalse;
       
   200         }
       
   201 
       
   202     HBufC* userTextFullPath = HBufC::NewLC( KMaxFileName );
       
   203     TPtr ptrUserTextFullPath( userTextFullPath->Des() );
       
   204     if ( oldName.PathPresent() )
       
   205         {
       
   206         ptrUserTextFullPath.Append( oldName.DriveAndPath() );
       
   207         }
       
   208 
       
   209     ptrUserTextFullPath.Append( *userText );
       
   210 
       
   211     // if entry with same name - not ok except if name same as original
       
   212     if( iEngine.IsNameFoundL( ptrUserTextFullPath ) &&
       
   213         ( !iOldName || ( iOldName &&
       
   214                          iOldName->Des().CompareF( ptrUserTextFullPath ) ) ) )
       
   215         {
       
   216         FileManagerDlgUtils::ShowInfoNoteL(
       
   217                     		 R_QTN_WMLBM_NAME_ALREADY_USED );
       
   218 
       
   219         CAknQueryControl* queryControl = QueryControl();
       
   220         if ( queryControl )
       
   221             {
       
   222             CEikEdwin* edwin = static_cast< CEikEdwin* >
       
   223                 ( queryControl->ControlByLayoutOrNull( EDataLayout ) );
       
   224             if ( edwin )
       
   225                 {
       
   226                 edwin->SetSelectionL( edwin->TextLength(), 0 );
       
   227                 }
       
   228             }
       
   229         result = EFalse;
       
   230         }
       
   231     CleanupStack::PopAndDestroy( userTextFullPath );
       
   232     CleanupStack::PopAndDestroy( userText );
       
   233     return result;
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CFileManagerFileNameQueryDlg::OkToExitL
       
   238 // 
       
   239 // -----------------------------------------------------------------------------
       
   240 // 
       
   241 TBool CFileManagerFolderNameQueryDlg::OkToExitL( TInt aButtonId )
       
   242     {
       
   243     if ( iCallbackDisabled )
       
   244         {
       
   245         return EFalse; // Block unwanted softkey events
       
   246         }
       
   247     TBool ret( EFalse );
       
   248     iCallbackDisabled = ETrue;
       
   249     TRAPD( err, ret = DoOkToExitL( aButtonId ) );
       
   250     iCallbackDisabled = EFalse;
       
   251     User::LeaveIfError( err );
       
   252     return ret;
       
   253     }
       
   254     
       
   255 // -----------------------------------------------------------------------------
       
   256 // CFileManagerFolderNameQueryDlg::OfferKeyEventL
       
   257 // 
       
   258 // -----------------------------------------------------------------------------
       
   259 // 
       
   260 TKeyResponse CFileManagerFolderNameQueryDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) 
       
   261     { 
       
   262     TKeyResponse response = EKeyWasNotConsumed;
       
   263     if ( aType == EEventKey && aKeyEvent.iCode == EKeyEnter ) 
       
   264         { 
       
   265         response = EKeyWasConsumed;
       
   266         } 
       
   267     else
       
   268         {
       
   269         response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent, aType); 
       
   270         }
       
   271     return response;
       
   272     }
       
   273 
       
   274 //  End of File