|
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 #include <eikapp.h> |
|
17 #include <s32file.h> // class CDictionaryFileStore |
|
18 #include <coemain.h> |
|
19 #include <eikenv.h> |
|
20 #include <bautils.h> |
|
21 #include <coeutils.h> |
|
22 #include <apgicnfl.h> |
|
23 #include "apfdef.h" |
|
24 #include <apgcli.h> |
|
25 #include <barsc2.h> |
|
26 #include <barsread2.h> |
|
27 |
|
28 _LIT(KAppResourcePath,"\\Resource\\Apps\\"); |
|
29 |
|
30 /** Default constructor. |
|
31 |
|
32 The default constructor is empty, and there are no NewL() or NewLC() functions |
|
33 as Uikon applications are created automatically by the application DLL framework |
|
34 when applications are started. */ |
|
35 EXPORT_C CEikApplication::CEikApplication() : iCoeEnv (CCoeEnv::Static()) |
|
36 { |
|
37 } |
|
38 |
|
39 /** Destructor. |
|
40 |
|
41 Deletes any resources acquired by this CEikApplication during its construction |
|
42 phases. */ |
|
43 EXPORT_C CEikApplication::~CEikApplication() |
|
44 { |
|
45 iCoeEnv->DeleteResourceFile(iResourceFileOffset); |
|
46 delete iCapabilityBuf; |
|
47 iProcess = NULL; // Not owned |
|
48 } |
|
49 |
|
50 /** |
|
51 Initiates the aParser object with the name of the application and the |
|
52 aPath and aExt specified. |
|
53 |
|
54 @internalTechnology |
|
55 */ |
|
56 void CEikApplication::InitAppNameParserWithPathAndExt(TParse& aParser, const TDesC& aPath, const TDesC& aExt) const |
|
57 { |
|
58 const TFileName libPath = AppFullName(); |
|
59 const TParsePtrC parsePtr(libPath); |
|
60 const TDriveName driveName = parsePtr.Drive(); |
|
61 const TPtrC appName = parsePtr.Name(); |
|
62 |
|
63 TParse parse; |
|
64 parse.Set(appName,&aExt, NULL); |
|
65 aParser.Set(parse.FullName(),&driveName,&aPath); |
|
66 } |
|
67 |
|
68 /** Gets the localized name of the resource file used by this application. |
|
69 |
|
70 By default, this file has an extension of .rsc and uses the same name |
|
71 as the application file located in the same directory. Language variants |
|
72 are supported through BaflUtils::NearestLanguageFile(). |
|
73 |
|
74 @return The name of the resource file. Used by PreDocConstructL(). */ |
|
75 EXPORT_C TFileName CEikApplication::ResourceFileName() const |
|
76 { // !! needs to cope with multi-lingual apps |
|
77 TParse parse; |
|
78 _LIT(KResFileDefaultExt,".rsc"); |
|
79 InitAppNameParserWithPathAndExt(parse, KAppResourcePath, KResFileDefaultExt); |
|
80 |
|
81 TFileName name = parse.FullName(); |
|
82 BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name); |
|
83 return name; |
|
84 } |
|
85 |
|
86 /** Gets the localized name of the bitmap file used by this application. |
|
87 |
|
88 By default, this file has an extension of .mbm and uses the same name |
|
89 as the application file in the same directory. Language variants |
|
90 are supported using BaflUtils::NearestLanguageFile(). |
|
91 |
|
92 @return The name of the bitmap store for this application. */ |
|
93 EXPORT_C TFileName CEikApplication::BitmapStoreName() const |
|
94 { // !! needs to cope with multi-lingual apps |
|
95 TParse parse; |
|
96 _LIT(KBmpFileDefaultExt,".mbm"); |
|
97 InitAppNameParserWithPathAndExt(parse, KAppResourcePath, KBmpFileDefaultExt); |
|
98 |
|
99 TFileName name = parse.FullName(); |
|
100 BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(),name); |
|
101 return name; |
|
102 } |
|
103 |
|
104 /** Creates a new document. |
|
105 |
|
106 This function is called by the application DLL framework during application startup |
|
107 to create a new instance of the document associated with this application. |
|
108 This implementation of the function makes a record of the CApaProcess argument, |
|
109 and returns a document created by the un-parameterised, private, overload. */ |
|
110 EXPORT_C CApaDocument* CEikApplication::CreateDocumentL(CApaProcess* aProcess) |
|
111 { |
|
112 ASSERT(!iProcess); |
|
113 iProcess = aProcess; |
|
114 return CreateDocumentL(); // pure virtual implemented by each application |
|
115 } |
|
116 |
|
117 /** Prepares for document creation. |
|
118 |
|
119 This function is called by the application DLL framework to complete construction and |
|
120 initialise the new application object. After this function has been called, the |
|
121 CEikApplication can create document objects. If there is a default resource file for |
|
122 this app, then it is added to the control environment. |
|
123 |
|
124 If this function leaves, this should be treated as if construction had failed, |
|
125 and the object should be destroyed by the caller. */ |
|
126 EXPORT_C void CEikApplication::PreDocConstructL() |
|
127 { |
|
128 // Import the application's default resource file, if any |
|
129 TFileName* fileName=new(ELeave) TFileName; |
|
130 CleanupStack::PushL(fileName); |
|
131 *fileName=ResourceFileName(); |
|
132 if (fileName->Length() && ConeUtils::FileExists(*fileName)) |
|
133 iResourceFileOffset=iCoeEnv->AddResourceFileL(*fileName); |
|
134 RApaLsSession ls; |
|
135 CleanupClosePushL(ls); |
|
136 if(ls.Connect() == KErrNone) |
|
137 { |
|
138 // Try to get the localized application caption from AppArc. |
|
139 // Fall back to the old way if we can't get a localized caption. |
|
140 if ((iAppFlags&EFlagCaptionCorrectlyLocalised)==0) |
|
141 { |
|
142 TApaAppInfo info; |
|
143 User::LeaveIfError(ls.GetAppInfo(info, AppDllUid())); |
|
144 if (info.iCaption.Length()>0) |
|
145 { |
|
146 iCaption=info.iCaption; |
|
147 iAppFlags|=EFlagCaptionCorrectlyLocalised; |
|
148 } |
|
149 } |
|
150 delete iCapabilityBuf; |
|
151 iCapabilityBuf=NULL; |
|
152 iCapabilityBuf=new(ELeave) TApaAppCapabilityBuf(); |
|
153 User::LeaveIfError(ls.GetAppCapability(*iCapabilityBuf, AppDllUid())); |
|
154 } |
|
155 CleanupStack::PopAndDestroy(&ls); |
|
156 if ((iAppFlags&EFlagCaptionCorrectlyLocalised)==0) |
|
157 { |
|
158 *fileName=AppFullName(); |
|
159 TParsePtrC parse(*fileName); |
|
160 iCaption=parse.Name(); |
|
161 } |
|
162 CleanupStack::PopAndDestroy(fileName); |
|
163 } |
|
164 |
|
165 |
|
166 /** Gets the default document name for this application. |
|
167 |
|
168 @param aDocumentName On return, contains the default document file name. */ |
|
169 EXPORT_C void CEikApplication::GetDefaultDocumentFileName(TFileName& aDocumentName) const |
|
170 { |
|
171 TApaAppCaption candidate; |
|
172 |
|
173 // Try to get the application's default document file name from the application's |
|
174 // resource file. By convension, the default document file name TBUF is always located |
|
175 // at the beginning of the applicaton's resource file, after the RSS_SIGNATURE and |
|
176 // before the EIK_APP_INFO (i.e. with an offset of EDefaultNameResourceOffset). |
|
177 if (iResourceFileOffset) |
|
178 { |
|
179 iCoeEnv->ReadResource(candidate, EDefaultNameResourceOffset+iResourceFileOffset); |
|
180 if (!candidate.Length()) |
|
181 { |
|
182 aDocumentName.Zero(); |
|
183 return; |
|
184 } |
|
185 } |
|
186 //If this application has no resource file, use the same behavior as above. |
|
187 else |
|
188 { |
|
189 aDocumentName.Zero(); |
|
190 return; |
|
191 } |
|
192 |
|
193 // Make sure we got the full document name including drive and path |
|
194 TParse parse; |
|
195 parse.Set(candidate, &aDocumentName, NULL); |
|
196 aDocumentName = parse.FullName(); |
|
197 } |
|
198 |
|
199 EXPORT_C CDictionaryStore* CEikApplication::OpenIniFileLC(RFs& aFs) const |
|
200 /** Opens the application's .ini file, if one exists. |
|
201 |
|
202 If a .ini file does not exist for this application, or if it is corrupt, |
|
203 this function creates one and opens that. .ini files are located on system drive, |
|
204 in the same directory as the application EXE. |
|
205 |
|
206 @param aFs File server session to use. |
|
207 @return Pointer to the dictionary store for the .ini file. */ |
|
208 { |
|
209 // get the path of the ini file |
|
210 TParse parser; |
|
211 SetToIniFileNameL(parser); |
|
212 // ensure that all directories in the path exist |
|
213 aFs.MkDirAll(parser.FullName()); // ignore the error // |
|
214 // open the ini file if it exists, otherwise create a new one |
|
215 CDictionaryStore* inifile=NULL; |
|
216 // if first attempt to open ini fails because of corrupt file, delete it and try again. |
|
217 TRAPD(err,inifile=CDictionaryFileStore::OpenL(aFs,parser.FullName(),AppDllUid())); |
|
218 if (err==KErrNone) |
|
219 CleanupStack::PushL(inifile); |
|
220 else if (err==KErrEof || err==KErrCorrupt) |
|
221 { |
|
222 User::LeaveIfError(aFs.Delete(parser.FullName())); |
|
223 inifile=CDictionaryFileStore::OpenLC(aFs,parser.FullName(),AppDllUid()); |
|
224 err=KErrNone; |
|
225 } |
|
226 User::LeaveIfError(err); |
|
227 return inifile; |
|
228 } |
|
229 |
|
230 EXPORT_C void CEikApplication::SetToIniFileNameL(TParse& aParser) const |
|
231 /** Sets a supplied file name parser to contain the path of this application's |
|
232 .ini file. |
|
233 |
|
234 @param aParser A file name parser. On return, this contains the path of |
|
235 the application's ini file. */ |
|
236 { |
|
237 TChar sysDrive = RFs::GetSystemDriveChar(); |
|
238 RBuf defaultDrive; |
|
239 _LIT(KColon,":"); |
|
240 TInt maxSizeOfFileName = KColon().Length() + 1; |
|
241 defaultDrive.CreateL(maxSizeOfFileName); |
|
242 defaultDrive.Append(sysDrive); |
|
243 defaultDrive.Append(KColon()); |
|
244 defaultDrive.CleanupClosePushL(); |
|
245 RFs& fs = iEikonEnv->FsSession(); |
|
246 TFileName fullName; |
|
247 User::LeaveIfError(fs.PrivatePath(fullName)); |
|
248 |
|
249 TParsePtrC ptr(AppFullName()); |
|
250 fullName.Append(ptr.Name()); |
|
251 |
|
252 User::LeaveIfError(aParser.SetNoWild(KIniFileExtension,&defaultDrive,&fullName)); |
|
253 CleanupStack::PopAndDestroy(&defaultDrive); |
|
254 } |
|
255 |
|
256 EXPORT_C void CEikApplication::Capability(TDes8& aInfo) const |
|
257 /** Gets the application's capabilities. |
|
258 |
|
259 Application developers should not need to override this function. */ |
|
260 { |
|
261 TApaAppCapability::CopyCapability(aInfo, *iCapabilityBuf); |
|
262 } |
|
263 |
|
264 EXPORT_C void CEikApplication::NewAppServerL(CApaAppServer*& /*aAppServer*/) |
|
265 /** Virtual function called by the framework when the application |
|
266 has been launched as a server application. |
|
267 Applications that wish to be used as server applications must |
|
268 override this function to return their implementation of the server. |
|
269 |
|
270 Base class implementation of this function leaves with KErrNotSupported, |
|
271 to prevent non-server applications from being launched as server applications. |
|
272 |
|
273 @param aAppServer The server pointer to be set. */ |
|
274 { |
|
275 User::Leave(KErrNotSupported); |
|
276 } |
|
277 |
|
278 EXPORT_C void CEikApplication::CEikApplication_Reserved1() |
|
279 { |
|
280 } |
|
281 |
|
282 EXPORT_C void CEikApplication::CEikApplication_Reserved2() |
|
283 { |
|
284 } |
|
285 |
|
286 /** Calling this method will ensure that the application Caption has been localized. |
|
287 This is called at the start of applications override of CEikApplication's |
|
288 CreateDocumentL, when application needs to started in Critical |
|
289 phase of Start-Up. |
|
290 |
|
291 @param aLocalisableResourceFile Location of the localized resource file |
|
292 */ |
|
293 EXPORT_C void CEikApplication::EnsureCaptionIsLocalisedL(const TDesC& aLocalisableResourceFile) |
|
294 { |
|
295 if (!(iAppFlags&EFlagCaptionCorrectlyLocalised)) |
|
296 { |
|
297 TFileName name(aLocalisableResourceFile); |
|
298 BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name); |
|
299 RResourceReader resourceReader; |
|
300 CResourceFile *resourceFile = CResourceFile::NewLC(iEikonEnv->FsSession(),aLocalisableResourceFile,0,0); |
|
301 resourceReader.OpenLC(resourceFile, 1); |
|
302 |
|
303 resourceReader.ReadUint32L(); |
|
304 resourceReader.ReadUint32L(); |
|
305 |
|
306 TPtrC captionShort = resourceReader.ReadTPtrCL(); |
|
307 |
|
308 resourceReader.ReadUint32L(); |
|
309 resourceReader.ReadUint32L(); |
|
310 |
|
311 // read caption |
|
312 TPtrC caption = resourceReader.ReadTPtrCL(); |
|
313 iCaption = caption; |
|
314 iAppFlags|=EFlagCaptionCorrectlyLocalised; |
|
315 CleanupStack::PopAndDestroy(2, resourceFile); |
|
316 } |
|
317 } |
|
318 |
|
319 |