lowlevellibsandfws/apputils/src/BaUtilsImp.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 // Declarations for some internal  BAFL functions
       
    17 #include <bautils.h>
       
    18 #include <f32file.h>
       
    19 #include <e32std.h>
       
    20 
       
    21 /**
       
    22 Specifies the maximum length of the numerical part of the suffix.
       
    23 
       
    24 If this is changed the documentation of the following functions 
       
    25 must also be updated:
       
    26 
       
    27 	BaflUtils::NearestLanguageFile()
       
    28 	TNearestLanguageFileFinder::CountDigitsFromEndInValidSuffix()
       
    29 	TNearestLanguageFileFinder::SetFileName()
       
    30 */
       
    31 const TInt KMaxSuffixLength = 5;
       
    32 
       
    33 class RDirectoryScanner
       
    34 /**
       
    35 @internalAll
       
    36 */
       
    37 	{
       
    38 public:
       
    39 	virtual TInt Open(RFs& aFs, const TDesC& aMatchPattern) = 0;
       
    40 	virtual TInt Next(TEntry& aOut) = 0;
       
    41 	virtual void Close() = 0;
       
    42 	virtual ~RDirectoryScanner() {}
       
    43 	};
       
    44 
       
    45 NONSHARABLE_CLASS(RRealDirectoryScanner) : public RDirectoryScanner
       
    46 /**
       
    47 @internalAll
       
    48 */
       
    49 	{
       
    50 public:
       
    51 	virtual TInt Open(RFs& aFs, const TDesC& aMatchPattern);
       
    52 	virtual TInt Next(TEntry& aOut);
       
    53 	virtual void Close();
       
    54 private:
       
    55 	RDir iDir;
       
    56 	};
       
    57 
       
    58 /**
       
    59  * Add a language to the end of the language path, unless it is already
       
    60  * present. On entry, the language path must have an ELangNone entry at its
       
    61  * end. This will be true on exit also.
       
    62  * @internalAll
       
    63  */
       
    64 void AddLanguage(TLanguagePath& aPath, TLanguage aNewLanguage);
       
    65 
       
    66 /**
       
    67  * Create a language path from the current language, ideal language and locale. 
       
    68  * The path may have up to eight entries in it.
       
    69  * @internalAll
       
    70  */
       
    71 
       
    72 void MakeLanguageDowngradePath(TLanguagePath& aPath,
       
    73 	TLanguage aCurrent, TLanguage aIdeal, const TLocale& aLocale);
       
    74 
       
    75 
       
    76 /**
       
    77  * This class contains all the functions for working out the nearest language
       
    78  * file. It can be derived from for test code purposes.
       
    79  * @internalAll
       
    80  */
       
    81 NONSHARABLE_CLASS(TNearestLanguageFileFinder)
       
    82 	{
       
    83 public:
       
    84 	TNearestLanguageFileFinder(const RFs& aFs);
       
    85 	TBool SetFileName(TFileName& aFileName);
       
    86 	TLanguage Language();
       
    87 	// put back the original suffix and drive letter
       
    88 	void RepairFileName();
       
    89 	// add the preset custom resource drive, if any, to iDrives.
       
    90 	TInt AddCustomResourceDrive();
       
    91 	// add all remaining drives to iDrives. iDrives must not have more than one
       
    92 	// drive in it on entry.
       
    93 	void AddAllDrives();
       
    94 	// Tries to append the language code to iFileName. This is 00..09 or just the number.
       
    95 	// If there was not enough space, EFalse is returned.
       
    96 	TBool AppendLanguageCode(TLanguage aLanguage);
       
    97 	// Search the drives in iDrives for the file named iFileName.
       
    98 	// iFileName must have a drive specifier, which will be overwritten.
       
    99 	TBool FindDrive();
       
   100 	// Search for files across all drives in all languages in the path plus the
       
   101 	// language-neutral file.
       
   102 	// On entry, iFileName should be the original name with a drive specifier
       
   103 	// minus the suffix. On return, iFileName will be untouched if EFalse is
       
   104 	// returned, but contain the result if ETrue is returned.
       
   105 	TBool FindLanguageAndDrive();
       
   106 	// Test whether the filename passed in matches the stem given + numbers
       
   107 	// added to the end. Returns the number if it does, or KErrNotFound if not.
       
   108 	// aFileName must not end in a digit.
       
   109 	static TInt LanguageNumberFromFile(const TDesC& aFileName, const TDesC& aStem);
       
   110 	// Find lowest numbered file that matches iFileName, which must be without
       
   111 	// its suffix.
       
   112 	TInt FindFirstLanguageFile(RFs&);
       
   113 	// Try each drive for any language files that match iFileName.
       
   114 	// iFileName must have a directory specifier and be without its suffix.
       
   115 	// returns KErrNotFound, KErrNone or error code.
       
   116 	TInt FindFirstLanguageFileAndDrive();
       
   117 
       
   118 	virtual TInt GetCustomResourceDriveNumber() const;
       
   119 	
       
   120 	virtual TInt FileExists(const TDesC& aFileName) const;
       
   121 	// return our member that is our directory scanning class
       
   122 	virtual RDirectoryScanner& DirectoryScanner();
       
   123 	virtual ~TNearestLanguageFileFinder() {}
       
   124 	
       
   125 private:
       
   126 	TInt CountDigitsFromEnd(const TDesC& aFilename);
       
   127 	TInt CountDigitsFromEndInSuffix (const TDesC& aFilename);
       
   128 
       
   129 public:
       
   130 	const RFs& iFs;
       
   131 	TFileName* iFileName;
       
   132 	TLanguage  iLanguage;
       
   133 	TBuf<26> iDrives;
       
   134 	TLanguagePath iPath;
       
   135 	TBuf<KMaxSuffixLength> iSuffix;
       
   136 	TInt iInitialDriveLetter;
       
   137 	// length minus the removed suffix
       
   138 	TInt iOriginalBaseLength;
       
   139 	// length plus added drive letter minus removed suffix
       
   140 	TInt iBaseLength;
       
   141 	RRealDirectoryScanner iDirScanner;
       
   142 	};
       
   143