|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 * Utility for common code. |
|
17 * |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 #ifndef __hspsSERVERUTIL_H__ |
|
23 #define __hspsSERVERUTIL_H__ |
|
24 |
|
25 // Includes |
|
26 #include <e32def.h> |
|
27 #include <e32base.h> |
|
28 |
|
29 // Forward declarations. |
|
30 class ChspsODT; |
|
31 class ChspsDomNode; |
|
32 class ChspsResource; |
|
33 |
|
34 // Constants. |
|
35 #define RECURSION_DEPTH_INFINITE (-1) |
|
36 |
|
37 /** |
|
38 * Class hspsAttribUtil. |
|
39 * |
|
40 * Static utility for maintainance and installation handlers. |
|
41 * @ingroup group_hspsserver |
|
42 * @lib hspsThemeServer.exe |
|
43 */ |
|
44 class hspsServerUtil |
|
45 { |
|
46 public: // New methods. |
|
47 /** |
|
48 * Generates attributes for the Configuration element from manifest data |
|
49 * @since S60 5.0 |
|
50 * @param aOdt is an ODT instance to be updated |
|
51 */ |
|
52 static void GenerateConfigurationAttributesL( ChspsODT& aOdt ); |
|
53 |
|
54 /** |
|
55 * Generates attributes for the Object element from manifest data |
|
56 * @since S60 5.0 |
|
57 * @param aOdt is an ODT instance to be updated |
|
58 */ |
|
59 static void GenerateObjectAttributesL( ChspsODT& aOdt ); |
|
60 |
|
61 /** |
|
62 * Retrieves locale independent path which used by HSPS clients to access resources |
|
63 * in their private application folders. |
|
64 * @since S60 5.0 |
|
65 * @param aResourceLanguage is the language of the resource |
|
66 * @param aPath is the path to be unlocalized |
|
67 */ |
|
68 static void GetLocaleIndependentResourcePath( |
|
69 const TLanguage& aResourceLanguage, |
|
70 TFileName& aPath ); |
|
71 |
|
72 /** |
|
73 * Retrieves relative path of a resource under the themes folder. |
|
74 * @since S60 5.0 |
|
75 * @param aSourceFile is the input file |
|
76 * @param aRelativePath is the relative path |
|
77 */ |
|
78 static void GetRelativeResourcePath( |
|
79 const TFileName& aSourceFile, |
|
80 TPath& aRelativePath ); |
|
81 |
|
82 /** |
|
83 * Creates a new attribute for the provided plugin node. |
|
84 * @since S60 5.0 |
|
85 * @param aPluginsNode is the plugins node that should be modified |
|
86 * @param aAttrName is name of the attribute |
|
87 * @param aValue is value of the attribute |
|
88 * @param aFormat is requested value string format |
|
89 * @return KErrNone |
|
90 */ |
|
91 static TInt AddAttributeNumericL( |
|
92 ChspsDomNode& aNode, |
|
93 const TDesC8& aAttrName, |
|
94 const TInt aValue, |
|
95 const TRadix aFormat = EDecimal ); |
|
96 |
|
97 /** |
|
98 * Creates a new attribute for the provided plugin node. |
|
99 * @since S60 5.0 |
|
100 * @param aPluginsNode is the plugins node that should be modified |
|
101 * @param aAttrName is name of the attribute |
|
102 * @param aValue is value of the attribute |
|
103 */ |
|
104 static void AddAttributeDescL( |
|
105 ChspsDomNode& aNode, |
|
106 const TDesC8& aAttrName, |
|
107 const TDesC8& aValue ); |
|
108 |
|
109 /** |
|
110 * Finds a configuration node with the provided id attribute |
|
111 * @since S60 5.0 |
|
112 * @param aOdt is an instance of the ODT class |
|
113 * @param aConfigurationId is an unique identifier of the configuration node |
|
114 * @return plugins node or NULL if the node couldn't be found |
|
115 */ |
|
116 static ChspsDomNode* FindConfigurationNodeL( |
|
117 ChspsODT& aOdt, |
|
118 const TInt aConfigurationId ); |
|
119 |
|
120 /** |
|
121 * Finds a plugin node with the provided id |
|
122 * @since S60 5.0 |
|
123 * @param aOdt is an instance of the ODT class |
|
124 * @param aPluginId is an ID of the plugin instance to be found |
|
125 * @return Pointer to the plugin node or NULL |
|
126 */ |
|
127 static ChspsDomNode* FindPluginNodeL( |
|
128 ChspsODT& aOdt, |
|
129 const TInt aPluginId ); |
|
130 |
|
131 /** |
|
132 * Gets an attribute value of a configuration element. |
|
133 * @since S60 5.0 |
|
134 * @param aOdt is an ODT instance form which the name is fetched |
|
135 * @param aAttr is the attribute to be found |
|
136 * @return value of the name attribute in a configuration node |
|
137 */ |
|
138 static TPtrC8 FindConfigurationAttrL( |
|
139 const ChspsODT& aOdt, |
|
140 const TDesC8& aAttr ); |
|
141 |
|
142 /** |
|
143 * Copies a file to a target path when neccessary. |
|
144 * Target path is created if it's missing. |
|
145 * File is copied if the target's size or date are different or |
|
146 * if the file is missing. |
|
147 * @since S60 5.0 |
|
148 * @param aFs Reference to OPEN file server session handle. |
|
149 * @param aFilemanager Referemce to file manager instance |
|
150 * @param aTargetPath Path where the file should be copied to |
|
151 * @param aFilename Path and name of the file to be copied |
|
152 * @return error code |
|
153 */ |
|
154 static TInt CopyResourceFileL( |
|
155 RFs& aFs, |
|
156 CFileMan& aFilemanager, |
|
157 const TPath& aTargetPath, |
|
158 const TFileName& aSourceFile ); |
|
159 |
|
160 /** |
|
161 * Checks: |
|
162 * - Is there enough space for target file? |
|
163 * - Do source and target files have same timestamp and size |
|
164 * (if target file exists)? |
|
165 * |
|
166 * @param aSource Full path to source file. |
|
167 * @param aTarget Full path to target file. |
|
168 * @param aFs Reference to OPEN file server session handle. |
|
169 * @return TBool ETrue if copy can continue, EFalse if copy not needed. |
|
170 */ |
|
171 static TBool ResourceCopyIsRelevantL( |
|
172 const TDesC& aSource, |
|
173 const TDesC& aTarget, |
|
174 RFs& aFs ); |
|
175 |
|
176 /** |
|
177 * Check configuration states |
|
178 * @since S60 5.0 |
|
179 * @param aOdt ODT instance to be checked |
|
180 * @param aConfState Old state to be replaced |
|
181 * @param aNextConfState New state |
|
182 * @param aOdtUpdated ODT update status |
|
183 */ |
|
184 |
|
185 static void UpdateConfigurationStateL( |
|
186 ChspsODT& aOdt, |
|
187 TDesC8& aConfState, |
|
188 TDesC8& aNextConfState, |
|
189 TBool& aOdtUpdated ); |
|
190 |
|
191 /** |
|
192 * Check state of an application configuration |
|
193 * @since S60 5.0 |
|
194 * @param aOdt ODT instance to be checked |
|
195 * @param aConfState Old state to be replaced |
|
196 * @param aNextConfState New state |
|
197 */ |
|
198 static void UpdateAppConfigurationStateL( |
|
199 ChspsODT& aAppOdt, |
|
200 const TDesC8& aConfState, |
|
201 const TDesC8& aNextConfState ); |
|
202 |
|
203 /** |
|
204 * Finds a defined node with defined attribute value |
|
205 * @since S60 5.0 |
|
206 * @param aOdt is an instance of the ODT class |
|
207 * @param aAttrName is name of the attribute to be found |
|
208 * @param aAttrValue is the value which the attribute should hold |
|
209 */ |
|
210 static ChspsDomNode* FindNodeByAttributeL( |
|
211 ChspsODT& aOdt, |
|
212 const TDesC8& aNodeName, |
|
213 const TDesC8& aAttrName, |
|
214 const TDesC8& aAttrValue ); |
|
215 |
|
216 /** |
|
217 * Retrieves all unique plugin uids from a configuration. |
|
218 * @since S60 5.0 |
|
219 * @param aOdt holds the configuration from which the plugins are searched from |
|
220 * @param aPluginArray is an array of found plugin uids |
|
221 */ |
|
222 static void FindUniquePluginsL( |
|
223 ChspsODT& aOdt, |
|
224 RArray<TInt>& aPluginArray ); |
|
225 |
|
226 |
|
227 /** |
|
228 * Converts a hex value string (0xXXXX) to TUint. |
|
229 * |
|
230 * @param aStr String containing hex value. |
|
231 * @param aTrg Reference to target TUint. Will be modified only |
|
232 * if conversion is successful. |
|
233 * @return KErrNone if successfull. Otherwise related symbian error code. |
|
234 */ |
|
235 static TInt HexString2Uint( |
|
236 const TDesC8& aStr, |
|
237 TUint& aTrg ); |
|
238 |
|
239 /** |
|
240 * Converts a decimal value string to TInt |
|
241 * @param aStr String containing hex value |
|
242 * @return corresponding TInt |
|
243 */ |
|
244 static TInt DecString2Int( |
|
245 const TDesC8& aStr ); |
|
246 |
|
247 /** |
|
248 * Returns a count of plugin instances. |
|
249 * @since S60 5.0 |
|
250 * @param aAppODT is an instance of the the application configuration |
|
251 * @param aPluginUid is an UID of the plugin instances to be found |
|
252 * @param aInstanceCount is the return value |
|
253 */ |
|
254 static void PluginInstanceCountL( |
|
255 const ChspsODT& aAppODT, |
|
256 const TInt aPluginUid, |
|
257 TInt& aInstanceCount ); |
|
258 /** |
|
259 * Converts UID in DesC8 format into TUid format. |
|
260 * @since S60 5.0 |
|
261 * @param aStr is the descriptor value to be converted |
|
262 * @return the converted uid value |
|
263 */ |
|
264 static TUid ConvertDescIntoUid( |
|
265 const TDesC8& aStr ); |
|
266 /** |
|
267 * Finds a child node by tag |
|
268 * @since S60 5.0 |
|
269 * @param aNodeTag is the tag of the child node to be found |
|
270 * @param aParentNode is the node whose child is searched |
|
271 * @param aIndex is index that sets position where to start search |
|
272 * @return pointer to child node |
|
273 */ |
|
274 |
|
275 static ChspsDomNode* FindChildNodeByTagL( |
|
276 const TDesC8& aNodeTag, |
|
277 ChspsDomNode& aParentNode, |
|
278 TInt& aIndex ); |
|
279 |
|
280 /** |
|
281 * Returns fixed name of ODT resources (e.g. clock.o0005 name converts into clock.o0000) |
|
282 * @since S60 5.0 |
|
283 * @param aNameAndExtension is resource name to be fixed |
|
284 * @return fixed resource name |
|
285 */ |
|
286 static TFileName GetFixedOdtName( |
|
287 const TDesC& aNameAndExtension ); |
|
288 |
|
289 /** |
|
290 * Finds files from defined directory and its sub directories from |
|
291 * C: drive, Z: drive or both. If the directory path contains a drive |
|
292 * files are searched from that drive only. |
|
293 * @since S60 5.0 |
|
294 * @param aDirName is directory path where the files are searched |
|
295 * @param aFileName is name of file to be searched |
|
296 * @param aFiles is a list of found files (full path) |
|
297 */ |
|
298 static void FindFilesL( |
|
299 const TDesC& aDirName, |
|
300 const TDesC& aFileName, |
|
301 RArray <TFileName>& aFiles ); |
|
302 |
|
303 /** |
|
304 * Finds files from defined directory from C: drive, Z: drive or both. |
|
305 * If the directory path contains a drive files are searched from that |
|
306 * drive only. |
|
307 * @since S60 5.0 |
|
308 * @param aDirName is directory path where the files are searched |
|
309 * @param aFileName is name of file to be searched |
|
310 * @param aFiles is a list of found files (full path) |
|
311 */ |
|
312 static void FindFilesFromDirL( |
|
313 const TDesC& aDirName, |
|
314 const TDesC& aFileName, |
|
315 RArray <TFileName>& aFiles ); |
|
316 |
|
317 /** |
|
318 * Set node attribute value. Updated node is defined with |
|
319 * node name, attribute name and attribute value |
|
320 * @since S60 5.0 |
|
321 * @param aOdt is an instance of the ODT class |
|
322 * @param aNodeName is name of updated node |
|
323 * @param aAttrName is name of the attribute to be found |
|
324 * @param aAttrValue is the value which the attribute should hold |
|
325 * @param aSetAttrName is name of updated attribute |
|
326 * @param aSetAttrValue is new value of updated attribute |
|
327 */ |
|
328 static void SetAttributeValueL( |
|
329 const ChspsODT& aOdt, |
|
330 const TDesC8& aNodeName, |
|
331 const TDesC8& aAttrName, |
|
332 const TDesC8& aAttrValue, |
|
333 const TDesC8& aSetAttrName, |
|
334 const TDesC8& aSetAttrValue ); |
|
335 |
|
336 /** |
|
337 * Get node attribute value. Node which attribute value is requested |
|
338 * is defined with node name, attribute name and attribute value |
|
339 * @since S60 5.0 |
|
340 * @param aOdt is an instance of the ODT class |
|
341 * @param aNodeName is the name of node which attribute value is requested |
|
342 * @param aAttrName is the name of the attribute which should be contained by the node |
|
343 * @param aAttrValue is the requested value of the attribute |
|
344 * @param aGetAttrName is the name of attribute which value is requested |
|
345 * @param aGetAttrValue is the requested attribute value |
|
346 */ |
|
347 static void GetAttributeValueL( |
|
348 const ChspsODT& aOdt, |
|
349 const TDesC8& aNodeName, |
|
350 const TDesC8& aAttrName, |
|
351 const TDesC8& aAttrValue, |
|
352 const TDesC8& aGetAttrName, |
|
353 TPtrC8& aGetAttrValue ); |
|
354 |
|
355 /** |
|
356 * Checks resource files of defined configuration |
|
357 * Function leaves if all resource files cannot be found |
|
358 * @since S60 5.0 |
|
359 * @param aOdt is an instance of the ODT class |
|
360 * @param aConfUid is configuration UID which resources are checked |
|
361 */ |
|
362 static void CheckResourceFilesL( |
|
363 const ChspsODT& aOdt, |
|
364 const TInt aConfUid ); |
|
365 |
|
366 /** |
|
367 * Returns configuration's version string |
|
368 * Function leaves if configuration cannot be found |
|
369 * @since S60 5.0 |
|
370 * @param aOdt is an instance of the ODT class |
|
371 * @param aConfUid is configuration UID which version is requested |
|
372 * @param aVersion is configuration version string |
|
373 */ |
|
374 static void CheckConfigurationVersionL( |
|
375 ChspsODT& aOdt, |
|
376 const TInt aConfUid, |
|
377 const TDesC& aVersion ); |
|
378 |
|
379 /** |
|
380 * Edit mode for EditNodeActivity method. |
|
381 */ |
|
382 enum TNodeEditMode |
|
383 { |
|
384 EActivateFirst = 0, // Activate first one on specific level only. |
|
385 // Others will be deactivated. |
|
386 |
|
387 EDeactivateAll // Deactivate all. |
|
388 }; |
|
389 |
|
390 /** |
|
391 * Modify node's childs according to given edit mode. |
|
392 * Recursive method. Modifies only nodes that are type plugin. |
|
393 * |
|
394 * @since S60 5.0 |
|
395 * @param aRootNode Root node to start tree recursion. |
|
396 * @param aEditMode Edit mode. Look for TNodeEditMode. |
|
397 * @param aDepth Optional edit depth. e.g. If 1 then |
|
398 * only one level of child nodes is processed. |
|
399 * If not defined (or RECURSION_DEPTH_INFINITE |
|
400 * used) then whole node tree from aRootNode |
|
401 * forward will be processed. |
|
402 */ |
|
403 static void EditPluginNodeActivityL( ChspsDomNode* aRootNode, |
|
404 const TNodeEditMode aEditMode, |
|
405 TInt aDepth = RECURSION_DEPTH_INFINITE ); |
|
406 |
|
407 /** |
|
408 * Get active plugin node. |
|
409 * Not recursive method. Only one level from parent will be checked. |
|
410 * |
|
411 * @since S60 5.0 |
|
412 * @param aParentNode Parent node. |
|
413 * @return ChspsDomNode* Pointer to active plugin node. NULL if none found. |
|
414 */ |
|
415 static ChspsDomNode* GetActivePluginNode( ChspsDomNode* aParentNode ); |
|
416 |
|
417 /** |
|
418 * Get plugin id of a node. |
|
419 * |
|
420 * @since S60 5.0 |
|
421 * @param aNode Node. |
|
422 * @return TInt Plugin id. |
|
423 */ |
|
424 static TInt GetPluginId( ChspsDomNode* aNode ); |
|
425 |
|
426 /** |
|
427 * Get plugin uid of a node. |
|
428 * |
|
429 * @since S60 5.0 |
|
430 * @param aNode Node. |
|
431 * @return TUid Plugin uid. |
|
432 */ |
|
433 static TUid GetPluginUid( ChspsDomNode* aNode ); |
|
434 |
|
435 /** |
|
436 * Gather plugin ids for specific plugin uid from given ODT. |
|
437 * @since S60 5.0 |
|
438 * @param aAppODT ODT to search plugin ids from. |
|
439 * @param aPluginUid Plugin uid to be used as search keyword. |
|
440 * @param aPluginIds Target array for plugin ids. |
|
441 */ |
|
442 static void GetPluginIdsByUidL( |
|
443 const ChspsODT& aAppODT, |
|
444 const TUid aPluginUid, |
|
445 RArray<TInt>& aPluginIds ); |
|
446 |
|
447 /** |
|
448 * Finds a parent node with defined name and attribute |
|
449 * for defined child node |
|
450 * @since S60 5.0 |
|
451 * @param aNode Child node |
|
452 * @param aNodeName Name of parent node |
|
453 * @param aAttrName Name of parent node attribute |
|
454 * @param aAttrValue Value of parent node attribute |
|
455 * @return pointer to parent node or |
|
456 * NULL if defined parent node is not found |
|
457 */ |
|
458 static ChspsDomNode* GetParentNode( |
|
459 const ChspsDomNode& aNode, |
|
460 const TDesC8& aNodeName, |
|
461 const TDesC8& aAttrName, |
|
462 const TDesC8& aAttrValue ); |
|
463 |
|
464 /** |
|
465 * Retrieves a filename from a file declaration. |
|
466 * @since S60 5.1 |
|
467 * @param aFileDeclaration "SKIN():MIF()", "MIF()", "UID()" or "file.ext" string |
|
468 * @param aFilename Referred file name or NULL |
|
469 * @return True if a file was referred from the declaration |
|
470 */ |
|
471 static TBool hspsServerUtil::IsFile( |
|
472 const TDesC& aFileDeclaration, |
|
473 TFileName& aFilename ); |
|
474 |
|
475 /** |
|
476 * Resolve resource files that need to be copied. |
|
477 * |
|
478 * @since S60 5.1 |
|
479 * |
|
480 * @param aODT Configuration. |
|
481 * @param aConfUid Plugin which is to be processed. |
|
482 * @param aActiveLanguage Active language. |
|
483 * @param aWidgetResources Target array. Will receive list |
|
484 * of resources if any applicable. |
|
485 * Ownership of given resources is not transferred! |
|
486 */ |
|
487 static void GetValidResourcesL( |
|
488 ChspsODT& aODT, |
|
489 const TInt aConfUid, |
|
490 const TLanguage aActiveLanguage, |
|
491 RPointerArray<ChspsResource>& aWidgetResources ); |
|
492 |
|
493 /** |
|
494 * Check if there is enough space on given drive for resources included in ODT. |
|
495 * |
|
496 * @since S60 5.1 |
|
497 * |
|
498 * @param aODT Configuration. |
|
499 * @param aActiveLanguage Active language. |
|
500 * @param aFs Reference to open file server handle. |
|
501 * @param aDriveNumber Drive number. Default EDriveC. |
|
502 * @param aAdditionalDiskSpace Additional disk space added to disk (bytes) |
|
503 * space requirement. Default 0. |
|
504 * |
|
505 * @return TInt System wide error code. KErrDiskFull |
|
506 * if not enough space on C drive. |
|
507 */ |
|
508 static TInt EnoughDiskSpaceAvailableL( |
|
509 ChspsODT& aODT, |
|
510 const TLanguage aActiveLanguage, |
|
511 RFs& aFs, |
|
512 const TDriveNumber aDriveNumber = EDriveC, |
|
513 const TInt aAdditionalDiskSpace = 0 ); |
|
514 |
|
515 /** |
|
516 * Finds a node by tag |
|
517 * @since S60 5.0 |
|
518 * @param aNodeTag is the tag of the node to be found |
|
519 * @param aDomNode is the root node where to search specific node |
|
520 * @return pointer to node that is found |
|
521 */ |
|
522 static ChspsDomNode* FindNodeByTagL( |
|
523 const TDesC8& aNodeTag, |
|
524 ChspsDomNode& aDomNode ); |
|
525 |
|
526 private: |
|
527 /** |
|
528 * Internal method. Do not call directly! |
|
529 * |
|
530 * Modify node's childs according to given edit mode. |
|
531 * Recursive method. Modifies only nodes that are type plugin. |
|
532 * |
|
533 * @since S60 5.0 |
|
534 * @param aRootNode Root node to start tree recursion. |
|
535 * @param aEditMode Edit mode. Look for TNodeEditMode. |
|
536 * @param aDepth Edit depth. e.g. If 1 then |
|
537 * only one level of child nodes is processed. |
|
538 * If RECURSION_DEPTH_INFINITE used |
|
539 * then whole node tree from aRootNode |
|
540 * forward will be processed. |
|
541 */ |
|
542 static void _EditPluginNodeActivityL( ChspsDomNode* aRootNode, |
|
543 const TNodeEditMode aEditMode, |
|
544 TInt& aDepth ); |
|
545 |
|
546 /** |
|
547 * Not for instanciation. Only static functionality provided. |
|
548 */ |
|
549 hspsServerUtil(); |
|
550 }; |
|
551 |
|
552 #endif //__hspsSERVERUTIL_H__ |