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